Advertisement
ZoriaRPG

Simple Somaria v0.4

Jul 5th, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.59 KB | None | 0 0
  1. // Simple Somaria
  2. // ZoriaRPG
  3. // v0.4 for ZC 2.50+
  4.  
  5. const int CMB_SOMARIA       = 0;
  6. const int SPR_SOMARIA_POOF  = 0;
  7. const int SFX_SOMARIA_POOF  = 0;
  8. const int CMB_INVIS     = 0;
  9.  
  10. ffc script SimpleSomariaBlock
  11. {
  12.     void run()
  13.     {
  14.         int pos; int x; int y; int blocks;
  15.         while(1)
  16.         {
  17.             if ( Link->Dir == DIR_UP ) { pos = ComboAt(Link->X+8, Link->Y+8));}
  18.             if ( Link->Dir == DIR_DOWN ) { pos = ComboAt(Link->X+7, Link->Y+8));}
  19.             if ( Link->Dir ==DIR_LEFT ) { pos = ComboAt(Link->X+8, Link->Y+7));}
  20.             if ( Link->Dir ==DIR_RIGHT ) { pos = ComboAt(Link->X+8, Link->Y+8));}
  21.                
  22.            
  23.             pos = adjacentCombo(pos, Link->Dir); //update
  24.             x = ComboX(pos);
  25.             y = ComboY(pos);
  26.            
  27.             if ( !Screen->ComboS[pos] ) //not walkable
  28.             {
  29.                 //error out
  30.                 this->Data = 0; Quit();
  31.             }
  32.             if ( pos % 16 == 0 ) //if on the leftmost column
  33.             {
  34.                 //error out
  35.                 this->Data = 0; Quit();
  36.             }
  37.             if ( (pos & 15) == 1 ) //rightmost column
  38.             {
  39.                 //error out
  40.                 this->Data = 0; Quit();
  41.             }
  42.             if ( pos < 0x10 ) //if it's the top row
  43.             {
  44.                 //error out
  45.                 this->Data = 0; Quit();
  46.             }      
  47.             if ( cmb > 0x9F ) //if it's on the bottom rowif ( pos < 0x10 ) combooffsets[11] = 1; //if it's the top row
  48.             {
  49.                 //error out
  50.                 this->Data = 0; Quit();
  51.             }
  52.            
  53.             else
  54.             {
  55.                 if ( blocks )
  56.                 {
  57.                     //find and destroy old block
  58.                     //we obviously need to mark them in some way when they move!!
  59.                     //no, just a unique combo ID.
  60.                     for ( int q = 0; q < 176; ++q )
  61.                     {
  62.                         if ( Screen->ComboD[q] == CMB_SOMARIA )
  63.                         {
  64.                             //poof anim
  65.                             lweapon poof = Screen->CreateLWeapon(LW_SPARKLE);
  66.                             poof->X = x;
  67.                             poof->Y = y;
  68.                             poof->UseSprite(SPR_SOMARIA_POOF);
  69.                             //sound
  70.                             Game->PlaySound(SFX_SOMARIA_POOF);
  71.                             //remove block
  72.                             Screen->ComboD[pos] = Screen->Undercombo;
  73.                             --blocks;
  74.                             while(poof->isValid()) Waitframe();
  75.                             break;
  76.                         }
  77.                     }
  78.                            
  79.                    
  80.                     //create new block
  81.                 }
  82.                
  83.                 //Creaqte the block.
  84.                
  85.                 //set combo type to a 4-way block
  86.                
  87.                 //poof anim
  88.                 lweapon poof = Screen->CreateLWeapon(LW_SPARKLE);
  89.                 poof->X = x;
  90.                 poof->Y = y;
  91.                 poof->UseSprite(SPR_SOMARIA_POOF);
  92.                 //sound
  93.                 Game->PlaySound(SFX_SOMARIA_POOF);
  94.                 ComboD[pos] = CMB_SOMARIA; //must be a 4-way push type, and only used by this script.
  95.                 ++blocks;
  96.                    
  97.                
  98.             }
  99.             Waitframe();
  100.         }
  101.     }
  102.         //Constants for AdjacentCombo()
  103.     //This now uses DIR_* constants, so you can do AdjacentCombo(cmb,Link->Dir)
  104.     //Returns the Nth combo index of a combo based on a central point, and a direction.
  105.     //For example, combo 22 + COMBO_UPRIGHT returns '7',
  106.     //as combo 7 is to the upper-right of combo 22.
  107.     int adjacentCombo(int cmb, int dir)
  108.     {
  109.         int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  110.         if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  111.         if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  112.         if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  113.         if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  114.         if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN ) ) return 0; //if the left columb
  115.         if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return 0; //if the right column
  116.         if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP ) ) return 0; //if the top row
  117.         if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return 0; //if the bottom row
  118.         else if ( cmb >= 0 && cmb <= 176 ) return cmb + combooffsets[dir];
  119.         else return -1;
  120.     }  
  121.    
  122.     void execute(int id)
  123.     {
  124.         // Invalid script
  125.         if ( id < 0 ) return;
  126.         if ( id > 511 ) return;
  127.        
  128.         ffc f;
  129.        
  130.         for(int q =1 ; q < 33; ++q)
  131.         {
  132.         f = Screen->LoadFFC(q);
  133.        
  134.         if (!q->Script ) continue;
  135.         if ( !f->Data ) continue;
  136.         if ( f->Data != CMB_INVIS ) continue;
  137.         if ( f->Flags[FFCF_CHANGER] ) continue;
  138.        
  139.         f->Data = CMB_INVIS;
  140.        
  141.         }
  142.  
  143.     }
  144. }
  145.            
  146.  
  147. item script SimpleSomariaCane
  148. {
  149.     void run()
  150.     {
  151.         Link->Action = LA_ATTACKING;
  152.         //if the ffc script isn't running, run it.
  153.         int s[]="SimpleSomariaBlock";
  154.         int a = Game->GetFFCScript(s);
  155.         if ( !countRunning(a) );
  156.         {
  157.             SimpleSomariaBlock.execute(a);
  158.         }
  159.     }
  160.     int countRunning(int id)
  161.     {
  162.         // Invalid script
  163.         if id < 0 ) return -1;
  164.         if ( id > 511 ) return -1;
  165.    
  166.         ffc f;
  167.         int count;
  168.    
  169.         for ( int q = 1; q < 33; ++q )
  170.         {
  171.             f = Screen->LoadFFC(q);
  172.             if ( f->Script == id )
  173.             {
  174.                 ++count;
  175.             }
  176.         }
  177.    
  178.         return count;
  179.     }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement