Advertisement
ZoriaRPG

Digging Game for JudasRising v0.8.1

Apr 12th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.92 KB | None | 0 0
  1. //////////////////////////////////
  2. /// Digging Game for ZC 2.50.2 ///
  3. /// for JudasRising            ///
  4. /// By: ZoriaRPG               ///
  5. /// v0.8.1                     ///
  6. /// 12th April, 2018           ///
  7. //////////////////////////////////
  8.  
  9. //Known issues: Shovel is not taken away if the player presses F6 during the game.
  10. //      A new global array index is needed to fix this.
  11. //     
  12. //      The menu does not display an error message if the player does not have enough money.
  13. // 
  14. //      The menu dialogue does not fit into the box.
  15. //
  16. //      The string displays improperly (being eaten by the dialogue size. Needs a bigger style or a different font).
  17. //
  18. //      The invisible combo for Tango seems to be incorrect?!
  19. //
  20. //      Need to store the pre-dug state of the room, and restore it when the game ends.
  21. // 
  22. const int I_SHOVEL          = 145; //Item ID of shovel item.
  23.  
  24. const int MISC_GAMES            = 5; //Link->Misc[]
  25. const int GT_SHOVEL             = 1; //bit for Link->Misc[MISC_GAMES]
  26.  
  27. const int SHOVELGAME_D = 6;  // Screen->D[] Register
  28. const int SHOVELGAME_BIT = 1; // Bit used by D[] register.
  29.  
  30.  
  31. const int SHOVEL_GAME_RUNNING       = 0; //index for shovelgame[]
  32. const int SHOVEL_GAME_TIMER         = 1; //index for shovelgame[]
  33. const int SHOVEL_GAME_ACTIVE        = 2; //index for shovelgame[]
  34. const int SHOVEL_GAME_HAS_SHOVEL    = 3; //index for shovelgame[]
  35. const int SHOVEL_GAME_PREV_B_ITEM   = 4; //index for shovelgame[]
  36. const int SHOVEL_GAME_ENDED     = 5; //index for shovelgame[]
  37.  
  38.  
  39. const int SHOVEL_GAME_LINE_Y        = 144; //Y position of invisible line.
  40.  
  41. const int SHOVEL_GAME_TIMER_X       = 200; //Timer X diaplsy position.
  42. const int SHOVEL_GAME_TIMER_Y       = 2; //Timer Y display position.
  43. const int SHOVEL_GAME_TIMER_SIZE_X  = 32; //Timer text character width. Warning: This was BROKEN in 2.50.2 and earlier!
  44. const int SHOVEL_GAME_TIMER_SIZE_Y  = 32; //Timer text character height. Warning: This was BROKEN in 2.50.2 and earlier!
  45. const int SHOVEL_GAME_TIMER_FONT    = 1; //Z3
  46. const int SHOVEL_GAME_TIMER_LAYER   = 6;
  47. const int SHOVEL_GAME_TIMER_COLOUR  = 0x01; //white
  48. const int SHOVEL_GAME_TIMER_VALUE   = 15; //DEFAULT
  49.  
  50. const int SHOVEL_GAME_MESSAGE_GAMEOVER  = 8; //The message to display when the game ends.
  51.  
  52. const int SHOVEL_GAME_GUY_DISTX     = 14; //Max disance from guy ffc.
  53. const int SHOVEL_GAME_GUY_DISTY     = 14; //Max disance from guy ffc.
  54. const int SHOVEL_GAME_COST      = 60;   //Default cost.
  55.  
  56. //Which buttons to allow to press to activate the menu.
  57. //1 to allow, 0 to disallow.
  58. const int SHOVEL_GAME_BUTTON_A      = 1;
  59. const int SHOVEL_GAME_BUTTON_B      = 1;
  60. const int SHOVEL_GAME_BUTTON_L      = 1;
  61. const int SHOVEL_GAME_BUTTON_R      = 1;
  62. const int SHOVEL_GAME_BUTTON_EX1    = 1;
  63. const int SHOVEL_GAME_BUTTON_EX2    = 1;
  64. const int SHOVEL_GAME_BUTTON_EX3    = 1;
  65. const int SHOVEL_GAME_BUTTON_EX4    = 1;
  66.  
  67. //const int SHOVEL_GAME_
  68. //const int SHOVEL_GAME_
  69. //const int SHOVEL_GAME_
  70. //const int SHOVEL_GAME_
  71.  
  72.  
  73. //Place this ffc on the screen, and give it the data of am NPC. Place over a solid combo.
  74. ffc script ShovelGame
  75. {
  76.     //D0: Game duration timer (in seconds!). Defaults to 15.
  77.     //D1: Cost to play in Rupees
  78.     void run(int time, int cost)
  79.     {
  80.        
  81.         int shovelgame[256];
  82.         //0 == timer
  83.         //1 == running
  84.         //2 == active
  85.         //3 == has the shovel in inventory
  86.         shovelgame[SHOVEL_GAME_ACTIVE] = 1;
  87.         shovelgame[SHOVEL_GAME_HAS_SHOVEL] = Cond(Link->Item[I_SHOVEL], 1, 0);
  88.         cost = Cond(cost > 0, cost, SHOVEL_GAME_COST);
  89.         int s_ver[]="Version 0.8"; TraceS(s_ver);
  90.         while(shovelgame[SHOVEL_GAME_ACTIVE])
  91.         {
  92.             if ( !shovelgame[SHOVEL_GAME_RUNNING] )
  93.             {
  94.                 //The NPC here is set by the FFC data:
  95.                 //If below or to the right of him
  96.                 if ( _DG_Below(this) || _DG_RightOf(this) )
  97.                 {
  98.                     //if Link is facing the guy
  99.                     if ( _DG_Facing(this, DIR_DOWN) || _DG_Facing(this, DIR_RIGHT) )
  100.                     {
  101.                         //and within a set distance
  102.                         if ( _DG_DistX(this, SHOVEL_GAME_GUY_DISTX) )
  103.                         {
  104.                             if ( _DG_DistY(this, SHOVEL_GAME_GUY_DISTX) )
  105.                             {
  106.                                 //and presses the correct button
  107.                                 if ( PressShovelGameButton() )
  108.                                 {
  109.                                     //create yes/no tango menu
  110.                                     //if menu returns (1) then the game is running
  111.                                     shovelgame[SHOVEL_GAME_RUNNING] = ShovelGameMenu(cost);
  112.                                     TraceB(IsShovelGame());
  113.                                 }
  114.                             }
  115.                         }
  116.                     }
  117.                 }
  118.             }
  119.            
  120.             //while runnning
  121.             while(shovelgame[SHOVEL_GAME_RUNNING])
  122.             {
  123.                 //if Link doesnt have the shovel, give it to him here:
  124.                
  125.                 if ( !shovelgame[SHOVEL_GAME_HAS_SHOVEL] )
  126.                 {
  127.                     if ( !Link->Item[I_SHOVEL] ) Link->Item[I_SHOVEL] = true;
  128.                     //Set the shovel as the active B item.
  129.                     if ( GetEquipmentB() != I_SHOVEL )
  130.                     {
  131.                         if ( GetEquipmentA() != I_SHOVEL )
  132.                         {
  133.                             shovelgame[SHOVEL_GAME_PREV_B_ITEM] = GetEquipmentB();
  134.                             SetShovelToB(); //Set the shovel to B every frame if not already on A!
  135.                         }
  136.                     }
  137.                 }
  138.                 //wait for Link to cross the invisible line
  139.                 do
  140.                 {
  141.                     Waitframe();
  142.                     continue;
  143.                 } while(Link->Y > SHOVEL_GAME_LINE_Y );
  144.                
  145.                 //once he does...
  146.                
  147.                 shovelgame[SHOVEL_GAME_TIMER] = Cond(time > 0, time, SHOVEL_GAME_TIMER_VALUE); //set the timer
  148.                 shovelgame[SHOVEL_GAME_TIMER] *= 60; //make it frames.
  149.                
  150.                 //Begin the game
  151.                 IsShovelGame(true); //set game running
  152.                 while(shovelgame[SHOVEL_GAME_TIMER]-- > -1 ) //This check is in frames; the display is in seconds.
  153.                 {
  154.                     //while the timer is above -1
  155.                
  156.                     //display the game time.
  157.                    
  158.                
  159.                     Screen->DrawInteger
  160.                         (SHOVEL_GAME_TIMER_LAYER, SHOVEL_GAME_TIMER_X, SHOVEL_GAME_TIMER_Y,                
  161.                             SHOVEL_GAME_TIMER_FONT, SHOVEL_GAME_TIMER_COLOUR, 0,
  162.                             SHOVEL_GAME_TIMER_SIZE_X, SHOVEL_GAME_TIMER_SIZE_Y,
  163.                             ((shovelgame[SHOVEL_GAME_TIMER]/60) << 0), 0, 128);
  164.                
  165.                    
  166.                     Waitframe(); continue;
  167.                     //if the timer expires, end the game.
  168.                 }
  169.            
  170.                 shovelgame[SHOVEL_GAME_RUNNING] = 0;
  171.                 shovelgame[SHOVEL_GAME_ENDED] = 1;
  172.                 Waitframe(); continue;
  173.             }
  174.        
  175.             //Game is over.
  176.             if ( shovelgame[SHOVEL_GAME_ENDED] )
  177.             {
  178.                 //Show a message
  179.                 Screen->Message(SHOVEL_GAME_MESSAGE_GAMEOVER);
  180.                 //set game off
  181.                 IsShovelGame(false);
  182.                
  183.                 //take the shovel away if Link does not own one.
  184.                
  185.                 if ( !shovelgame[SHOVEL_GAME_HAS_SHOVEL] )
  186.                 {
  187.                     if ( Link->Item[I_SHOVEL] ) Link->Item[I_SHOVEL] = false;
  188.                     //Set the shovel as the active B item.
  189.                 }
  190.                 shovelgame[SHOVEL_GAME_ENDED] = 0;
  191.             }
  192.            
  193.             Waitframe(); continue;
  194.         }
  195.        
  196.         //if you want the guy to say something else, or if you want to offer a new game,
  197.         //then, you could do that.
  198.        
  199.     }  
  200.  
  201.  
  202.    //ffc functions
  203.  
  204.  
  205.      bool _DG_DistY(ffc a, int distance)
  206.      {
  207.          int dist;
  208.          if ( a->Y > Link->Y ) dist = a->Y - Link->Y;
  209.           else dist = Link->Y - a->Y;
  210.          return ( dist <= distance );
  211.      }
  212.  
  213.      bool _DG_Below(ffc n){ return Link->Y > n->Y; }
  214.      bool _DG_RightOf(ffc n){ return Link->X > n->X; }
  215.  
  216.      bool _DG_Facing (ffc f, int ffc_dir)
  217.      {
  218.            if ( ffc_dir == DIR_UP && Link->Dir == DIR_DOWN ) return true;
  219.            if ( ffc_dir == DIR_DOWN && Link->Dir == DIR_UP ) return true;
  220.            if ( ffc_dir == DIR_RIGHT && Link->Dir == DIR_LEFT ) return true;
  221.            if ( ffc_dir == DIR_LEFT && Link->Dir == DIR_RIGHT ) return true;
  222.            return false;
  223.      }
  224.  
  225.  
  226.      bool _DG_DistX(ffc a, int distance)
  227.      {
  228.          int dist;
  229.          if ( a->X > Link->X ) dist = a->X - Link->X;
  230.                else dist = Link->X - a->X;
  231.          return ( dist <= distance );
  232.       }
  233.  
  234.       bool PressShovelGameButton()
  235.       {
  236.              if ( SHOVEL_GAME_BUTTON_A && Link->PressA )
  237.              {
  238.                  Link->PressA = false; Link->InputA = false; return true;
  239.              }
  240.              if ( SHOVEL_GAME_BUTTON_B && Link->PressB )
  241.              {
  242.                  Link->PressB = false; Link->InputB = false; return true;
  243.              }
  244.              if ( SHOVEL_GAME_BUTTON_L && Link->PressL )
  245.              {
  246.                  Link->PressL = false; Link->InputL = false; return true;
  247.              }
  248.              if ( SHOVEL_GAME_BUTTON_R && Link->PressR )
  249.              {
  250.                  Link->PressR = false; Link->InputR = false; return true;
  251.              }
  252.              if ( SHOVEL_GAME_BUTTON_EX1 && Link->PressEx1 )
  253.              {
  254.                  Link->PressEx1 = false; Link->InputEx1 = false; return true;
  255.           }
  256.              if ( SHOVEL_GAME_BUTTON_EX2 && Link->PressEx2 )
  257.              {
  258.                  Link->PressEx2 = false; Link->InputEx2 = false; return true;
  259.              }
  260.              if ( SHOVEL_GAME_BUTTON_EX3 && Link->PressEx3 )
  261.              {
  262.                  Link->PressEx3 = false; Link->InputEx3 = false; return true;
  263.              }
  264.              if ( SHOVEL_GAME_BUTTON_EX4 && Link->PressEx4 )
  265.              {
  266.                  Link->PressEx4 = false; Link->InputEx4 = false; return true;
  267.              }
  268.              return false;
  269.          }
  270.        
  271.     }
  272.  
  273.     void SetShovelToB()
  274.     {
  275.        
  276.         int ___end = GetEquipmentB();
  277.         do Link->SelectBWeapon(DIR_RIGHT);
  278.         while(GetEquipmentB() != I_SHOVEL && GetEquipmentB() != ___end );
  279.     }
  280.     //The 'yes/no' menu called by the ffc.
  281.     int ShovelGameMenu(int cost)
  282.     {
  283.         Tango_D[0] = cost; //We store a game variable in the Tango_D array, so that we can reference it inside the menu.
  284.    
  285.         int lineBreak[]="@26";
  286.         int line1[]="@choice(1)Play the shovel game for @tab(8)@number(@d0) rupees?@26";
  287.         int line2[]="@choice(2)Not interested.@domenu(1)@suspend()";
  288.        
  289.         SetUpWindow(WINDOW_SLOT_1, WINDOW_STYLE_3, 32, 32, SIZE_LARGE);
  290.         Tango_LoadString(WINDOW_SLOT_1, line1);
  291.         Tango_AppendString(WINDOW_SLOT_1, line2);
  292.         Tango_ActivateSlot(WINDOW_SLOT_1);
  293.  
  294.        
  295.         while(!Tango_MenuIsActive())
  296.         {
  297.        
  298.             Waitframe();
  299.         }
  300.        
  301.         // Save the state again...
  302.         int slotState[278];
  303.         int menuState[960];
  304.         int cursorPos;
  305.         Tango_SaveSlotState(WINDOW_SLOT_1, slotState);
  306.         Tango_SaveMenuState(menuState);
  307.        
  308.         int done = 0;
  309.         int choice;
  310.         int ret;
  311.         while(!done){
  312.        
  313.             while( Tango_MenuIsActive() )
  314.             {
  315.                 cursorPos=Tango_GetMenuCursorPosition();
  316.                 Waitframe();
  317.             }
  318.        
  319.             choice = Tango_GetLastMenuChoice();
  320.             if ( choice == 1 ) // play the game
  321.             {
  322.                 if ( Game->Counter[CR_RUPEES] < cost )
  323.                 {
  324.                     ret = 0;
  325.                     done = 1;
  326.                 }
  327.                 else
  328.                 {
  329.                     Game->DCounter[CR_RUPEES] -= cost;
  330.                     ret = 1;
  331.                     done = 1;
  332.                 }
  333.             }
  334.             else if ( choice == 2 ) //not interested.
  335.             {
  336.                 ret = 0;
  337.                 menuArg = choice;
  338.                 done = 1;
  339.             }
  340.        
  341.            
  342.             else done = 1;
  343.  
  344.             if ( done )
  345.             {
  346.                 break;
  347.             }
  348.             else
  349.             {
  350.                 Tango_RestoreSlotState(WINDOW_SLOT_1, slotState);
  351.                 Tango_RestoreMenuState(menuState);
  352.                 Tango_SetMenuCursorPosition(cursorPos);
  353.             }
  354.         }
  355.        
  356.         Tango_ClearSlot(WINDOW_SLOT_1);
  357.         return ret;
  358.     }
  359. //}
  360.  
  361. //Huzzah, this script now uses a way more practical injection model for usage! ~Lunaria
  362.  
  363. //The combo type for generic digging on overworld.
  364. const int Shovel_ComboType = 143;   //Script 2 (143) is default for this.
  365.  
  366.  
  367. //The flag to dig on to trigger secrets. (Does not need to be on a digable combo type!)
  368. const int Shovel_SecretFlag = 99;   //General Purpose 2  (99) is default for this.
  369.  
  370.  
  371. //Digging on proper combos will change the combo to this one:
  372. const int Shovel_DugCombo = 969;        //Change to 0 to use the screens undercombo instead.
  373.  
  374.  
  375. //Start of 8 combos in a row for the dig animation. (Up 1, Down 1, Left 1, Right 1, Up 2, Down 2, Left 2, Right 2)
  376. const int Shovel_Anima_Start = 3780;
  377. //Start of 4 combos for the dirt clut
  378. const int Shovel_FlyingDirt = 3788;
  379.  
  380.  
  381.  
  382. //FFC slot for the shovel script. This now uses an FFC slot because fancier animation, woo!
  383. const int Shovel_FFC_Script = 172;
  384.  
  385.  
  386. // This is the sound to be played when you successfully dig.
  387. const int Shovel_Sound = 74;
  388. // The sound to be played when you attempt to dig an undiggable combo.
  389. const int Shovel_Fail = 101;
  390. // The secret sound to be played when you dig a secret.
  391. const int Shovel_SecretSFX = 27;
  392.  
  393. item script Shovel{
  394.     void run(){
  395.         int s_dig[]="Shovel_Diggy";
  396.         int s_dig_game[]="Shovel_Diggy_Game";
  397.         int useScript = Game->GetFFCScript(Cond(IsShovelGame(), s_dig_game, s_dig));
  398.         if(Link->Z > 0) return;
  399.         //int args[] = {103,0,0,0,0,0,0,0};
  400.         RunFFCScript(useScript, NULL);
  401.        
  402.        
  403.     }
  404. }
  405.  
  406.  
  407. ffc script Shovel_Diggy_Game{
  408.   void run(){
  409.     int chance;
  410.     int itemdrop;
  411.     int itemlocx;
  412.     int itemlocy;
  413.     // Link->Action=LA_ATTACKING;
  414.    
  415.     item ShovelLoot;
  416.    
  417.     bool DigSuccess = false;
  418.    
  419.     int DigComboX;
  420.     int DigComboY;
  421.     if(Link->Dir == 0){
  422.         DigComboX = Link->X + 8;
  423.         DigComboY = Link->Y - 2;
  424.     }
  425.     else if(Link->Dir == 1){
  426.         DigComboX = Link->X + 8;
  427.         DigComboY = Link->Y + 18;
  428.     }
  429.     else if(Link->Dir == 2){
  430.         DigComboX = Link->X - 2;
  431.         DigComboY = Link->Y + 8;
  432.     }
  433.     else if(Link->Dir == 3){
  434.         DigComboX = Link->X + 18;
  435.         DigComboY = Link->Y + 8;
  436.     }
  437.    
  438.     int DigComboX2 = ComboAt(DigComboX,DigComboY) % 16;
  439.     DigComboX2 = DigComboX2 * 16;
  440.     int DigComboY2 = ComboAt(DigComboX,DigComboY) / 16;
  441.     DigComboY2 = Floor(DigComboY2);
  442.     DigComboY2 = DigComboY2 * 16;
  443.    
  444.    
  445.     for(int i; i != 10; i ++){
  446.         Link->Invisible = true;
  447.        
  448.         Screen->FastCombo(2, Link->X, Link->Y, Shovel_Anima_Start + Link->Dir, 6, OP_OPAQUE);
  449.         NoAction();
  450.        
  451.         Waitframe();
  452.         Link->Invisible = false;
  453.     }
  454.  
  455.    
  456.     if(Screen->ComboT[ComboAt(DigComboX,DigComboY)] != Shovel_ComboType
  457.     && Screen->ComboI[ComboAt(DigComboX,DigComboY)] != Shovel_SecretFlag
  458.     && Screen->ComboF[ComboAt(DigComboX,DigComboY)] != Shovel_SecretFlag){
  459.        Game->PlaySound(Shovel_Fail);
  460.     }
  461.     else{
  462.        
  463.        Game->PlaySound(Shovel_Sound);
  464.        DigSuccess = true;
  465.        
  466.        chance=Rand(100)+1;
  467.        
  468.        if(Screen->ComboT[ComboAt(DigComboX,DigComboY)] == Shovel_ComboType && Screen->ComboI[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag){
  469.            
  470.            Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Screen->UnderCombo;
  471.            chance = 101;
  472.            
  473.        }
  474.        else if(Screen->ComboF[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag || Screen->ComboI[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag){
  475.            Game->PlaySound(Shovel_SecretSFX);
  476.            Screen->TriggerSecrets();
  477.            Screen->State[ST_SECRET] = true;
  478.            chance = 101;
  479.        }
  480.        else{
  481.            Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Screen->UnderCombo;
  482.            
  483.            if(Shovel_DugCombo > 0){
  484.                Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Shovel_DugCombo;
  485.            }
  486.        }
  487.    
  488.     //The drops for the special shovel game are defined in the function ShovelDigItem();
  489.        itemdrop = ShovelDigItem();
  490.  
  491.        if(Link->Dir==0){    //Spawn location
  492.            itemlocx=Link->X;
  493.            itemlocy=Link->Y-16;
  494.        }
  495.        if(Link->Dir==1){
  496.            itemlocx=Link->X;
  497.            itemlocy=Link->Y+16;
  498.        }
  499.        if(Link->Dir==2){
  500.            itemlocx=Link->X-16;
  501.            itemlocy=Link->Y;
  502.        }
  503.        if(Link->Dir==3){
  504.            itemlocx=Link->X+16;
  505.            itemlocy=Link->Y;
  506.        }
  507.  
  508.        if(itemdrop != -999){
  509.            ShovelLoot=Screen->CreateItem(itemdrop);
  510.            ShovelLoot->X=itemlocx;
  511.            ShovelLoot->Y=itemlocy;
  512.            ShovelLoot->Z=2;
  513.            ShovelLoot->Jump = 2;
  514.            ShovelLoot->Pickup=IP_TIMEOUT;
  515.        }
  516.     }
  517.    
  518.     int shovel_item_dir = Link->Dir;
  519.     int DirtClutX = DigComboX2;
  520.     int DirtClutY = DigComboY2;
  521.    
  522.    
  523.     for(int i; i != 10; i ++){
  524.         Link->Invisible = true;
  525.        
  526.         Screen->FastCombo(2, Link->X, Link->Y, Shovel_Anima_Start + 4 + Link->Dir, 6, OP_OPAQUE);
  527.         NoAction();
  528.        
  529.         if(i < 5){
  530.            
  531.             if(shovel_item_dir == 0)DirtClutY --;
  532.             if(shovel_item_dir == 1 && i % 2 == 0)DirtClutY ++;
  533.            
  534.             //sideways
  535.             if(shovel_item_dir > 1)DirtClutY --;
  536.             if(shovel_item_dir == 3)DirtClutX = DigComboX + (i / 2);
  537.             if(shovel_item_dir == 2)DirtClutX = DigComboX - (i / 2);
  538.            
  539.         }
  540.         else{
  541.            
  542.             if(shovel_item_dir == 0 && i % 2 == 0)DirtClutY --;
  543.             if(shovel_item_dir == 1)DirtClutY ++;
  544.            
  545.             //sideways
  546.             if(shovel_item_dir > 1)DirtClutY ++;
  547.             if(shovel_item_dir == 3)DirtClutX = DigComboX + (i / 2);
  548.             if(shovel_item_dir == 2)DirtClutX = DigComboX - (i / 2);
  549.            
  550.         }
  551.         if(DigSuccess)Screen->FastCombo(2, DirtClutX, DirtClutY, Shovel_FlyingDirt + shovel_item_dir, 6, OP_OPAQUE);
  552.        
  553.        
  554.         if(Screen->ComboS[ComboAt(ShovelLoot->X + 8, ShovelLoot->Y + 8)] == 0){
  555.            
  556.             if(shovel_item_dir == 0)ShovelLoot->Y --;
  557.             else if(shovel_item_dir == 1)ShovelLoot->Y ++;
  558.             else if(shovel_item_dir == 2)ShovelLoot->X --;
  559.             else if(shovel_item_dir == 3)ShovelLoot->X ++;
  560.            
  561.         }
  562.        
  563.        
  564.         Waitframe();
  565.         Link->Invisible = false;
  566.     }
  567.    
  568.     while(ShovelLoot->Z > 0){
  569.        
  570.         if(Screen->ComboS[ComboAt(ShovelLoot->X + 8, ShovelLoot->Y + 8)] == 0){
  571.            
  572.             if(shovel_item_dir == 0)ShovelLoot->Y --;
  573.             else if(shovel_item_dir == 1)ShovelLoot->Y ++;
  574.             else if(shovel_item_dir == 2)ShovelLoot->X --;
  575.             else if(shovel_item_dir == 3)ShovelLoot->X ++;
  576.            
  577.         }
  578.        
  579.         Waitframe();
  580.        
  581.     }
  582.    
  583.   }
  584.  
  585.   //These tables define the prizes to award during the DIGGING GAME! -Z
  586.   int ShovelDigItem()
  587.     {
  588.         int prizeChances[100]=
  589.         {
  590.             //Define shovel game prizes, here.
  591.             0,0,0,0,0,0,0,0,0,0,
  592.             2,2,2,2,2,2,2,2,2,2,
  593.             34,34,34,
  594.             1,1,1,1,1,
  595.             87,-999, //29
  596.             //30
  597.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  598.             //40
  599.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  600.             //50
  601.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  602.             //60
  603.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  604.             //70
  605.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  606.             //80
  607.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  608.             //90
  609.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999
  610.         };
  611.         int specialPrizeChances[100]=
  612.         {
  613.             //Define special prizes here.
  614.             0,0,0,0,0,0,0,0,0,0,
  615.             2,2,2,2,2,2,2,2,2,2,
  616.             34,34,34,
  617.             1,1,1,1,1,
  618.             87,-999, //29
  619.             //30
  620.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  621.             //40
  622.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  623.             //50
  624.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  625.             //60
  626.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  627.             //70
  628.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  629.             //80
  630.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999,
  631.             //90
  632.             -999,-999,-999,-999,-999,-999,-999,-999,-999,-999
  633.         };
  634.         if ( !GetScreenDBit(SHOVELGAME_D, SHOVELGAME_BIT) )
  635.             return specialPrizeChances[Rand(0,99)];
  636.         else return prizeChances[Rand(0,99)];
  637.     }
  638. }
  639.  
  640. //Normal, non-digging-game, script. (Unchanged) -Z
  641. ffc script Shovel_Diggy{
  642.   void run(){
  643.     int chance;
  644.     int itemdrop;
  645.     int itemlocx;
  646.     int itemlocy;
  647.     // Link->Action=LA_ATTACKING;
  648.    
  649.     item ShovelLoot;
  650.    
  651.     bool DigSuccess = false;
  652.    
  653.     int DigComboX;
  654.     int DigComboY;
  655.     if(Link->Dir == 0){
  656.         DigComboX = Link->X + 8;
  657.         DigComboY = Link->Y - 2;
  658.     }
  659.     else if(Link->Dir == 1){
  660.         DigComboX = Link->X + 8;
  661.         DigComboY = Link->Y + 18;
  662.     }
  663.     else if(Link->Dir == 2){
  664.         DigComboX = Link->X - 2;
  665.         DigComboY = Link->Y + 8;
  666.     }
  667.     else if(Link->Dir == 3){
  668.         DigComboX = Link->X + 18;
  669.         DigComboY = Link->Y + 8;
  670.     }
  671.    
  672.     int DigComboX2 = ComboAt(DigComboX,DigComboY) % 16;
  673.     DigComboX2 = DigComboX2 * 16;
  674.     int DigComboY2 = ComboAt(DigComboX,DigComboY) / 16;
  675.     DigComboY2 = Floor(DigComboY2);
  676.     DigComboY2 = DigComboY2 * 16;
  677.    
  678.    
  679.     for(int i; i != 10; i ++){
  680.         Link->Invisible = true;
  681.        
  682.         Screen->FastCombo(2, Link->X, Link->Y, Shovel_Anima_Start + Link->Dir, 6, OP_OPAQUE);
  683.         NoAction();
  684.        
  685.         Waitframe();
  686.         Link->Invisible = false;
  687.     }
  688.  
  689.    
  690.     if(Screen->ComboT[ComboAt(DigComboX,DigComboY)] != Shovel_ComboType
  691.     && Screen->ComboI[ComboAt(DigComboX,DigComboY)] != Shovel_SecretFlag
  692.     && Screen->ComboF[ComboAt(DigComboX,DigComboY)] != Shovel_SecretFlag){
  693.        Game->PlaySound(Shovel_Fail);
  694.     }
  695.     else{
  696.        
  697.        Game->PlaySound(Shovel_Sound);
  698.        DigSuccess = true;
  699.        
  700.        chance=Rand(100)+1;
  701.        
  702.        if(Screen->ComboT[ComboAt(DigComboX,DigComboY)] == Shovel_ComboType && Screen->ComboI[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag){
  703.            
  704.            Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Screen->UnderCombo;
  705.            chance = 101;
  706.            
  707.        }
  708.        else if(Screen->ComboF[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag || Screen->ComboI[ComboAt(DigComboX,DigComboY)] == Shovel_SecretFlag){
  709.            Game->PlaySound(Shovel_SecretSFX);
  710.            Screen->TriggerSecrets();
  711.            Screen->State[ST_SECRET] = true;
  712.            chance = 101;
  713.        }
  714.        else{
  715.            Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Screen->UnderCombo;
  716.            
  717.            if(Shovel_DugCombo > 0){
  718.                Screen->ComboD[ComboAt(DigComboX,DigComboY)] = Shovel_DugCombo;
  719.            }
  720.        }
  721.        
  722.         //Drop ratio is the current number minus the last one.
  723.        if(chance<=10){      //10%
  724.            itemdrop = 0;    //1 rupee
  725.        }
  726.        else if(chance<=20){ //10%
  727.            itemdrop = 2;    //Recovery heart
  728.        }
  729.        else if(chance<=23){ //3%
  730.            itemdrop = 34;   //Fairy
  731.        }
  732.        else if(chance<=27){ //4%
  733.            itemdrop = 1;    //5 Rupee
  734.        }
  735.        else if(chance<=28){ //1%
  736.            itemdrop = 87;   //100 Rupee
  737.        }
  738.        else{
  739.            itemdrop = - 999;    //No item drop
  740.        }
  741.  
  742.        if(Link->Dir==0){    //Spawn location
  743.            itemlocx=Link->X;
  744.            itemlocy=Link->Y-16;
  745.        }
  746.        if(Link->Dir==1){
  747.            itemlocx=Link->X;
  748.            itemlocy=Link->Y+16;
  749.        }
  750.        if(Link->Dir==2){
  751.            itemlocx=Link->X-16;
  752.            itemlocy=Link->Y;
  753.        }
  754.        if(Link->Dir==3){
  755.            itemlocx=Link->X+16;
  756.            itemlocy=Link->Y;
  757.        }
  758.  
  759.        if(itemdrop != -999){
  760.            ShovelLoot=Screen->CreateItem(itemdrop);
  761.            ShovelLoot->X=itemlocx;
  762.            ShovelLoot->Y=itemlocy;
  763.            ShovelLoot->Z=2;
  764.            ShovelLoot->Jump = 2;
  765.            ShovelLoot->Pickup=IP_TIMEOUT;
  766.        }
  767.     }
  768.    
  769.     int shovel_item_dir = Link->Dir;
  770.     int DirtClutX = DigComboX2;
  771.     int DirtClutY = DigComboY2;
  772.    
  773.    
  774.     for(int i; i != 10; i ++){
  775.         Link->Invisible = true;
  776.        
  777.         Screen->FastCombo(2, Link->X, Link->Y, Shovel_Anima_Start + 4 + Link->Dir, 6, OP_OPAQUE);
  778.         NoAction();
  779.        
  780.         if(i < 5){
  781.            
  782.             if(shovel_item_dir == 0)DirtClutY --;
  783.             if(shovel_item_dir == 1 && i % 2 == 0)DirtClutY ++;
  784.            
  785.             //sideways
  786.             if(shovel_item_dir > 1)DirtClutY --;
  787.             if(shovel_item_dir == 3)DirtClutX = DigComboX + (i / 2);
  788.             if(shovel_item_dir == 2)DirtClutX = DigComboX - (i / 2);
  789.            
  790.         }
  791.         else{
  792.            
  793.             if(shovel_item_dir == 0 && i % 2 == 0)DirtClutY --;
  794.             if(shovel_item_dir == 1)DirtClutY ++;
  795.            
  796.             //sideways
  797.             if(shovel_item_dir > 1)DirtClutY ++;
  798.             if(shovel_item_dir == 3)DirtClutX = DigComboX + (i / 2);
  799.             if(shovel_item_dir == 2)DirtClutX = DigComboX - (i / 2);
  800.            
  801.         }
  802.         if(DigSuccess)Screen->FastCombo(2, DirtClutX, DirtClutY, Shovel_FlyingDirt + shovel_item_dir, 6, OP_OPAQUE);
  803.        
  804.        
  805.         if(Screen->ComboS[ComboAt(ShovelLoot->X + 8, ShovelLoot->Y + 8)] == 0){
  806.            
  807.             if(shovel_item_dir == 0)ShovelLoot->Y --;
  808.             else if(shovel_item_dir == 1)ShovelLoot->Y ++;
  809.             else if(shovel_item_dir == 2)ShovelLoot->X --;
  810.             else if(shovel_item_dir == 3)ShovelLoot->X ++;
  811.            
  812.         }
  813.        
  814.        
  815.         Waitframe();
  816.         Link->Invisible = false;
  817.     }
  818.    
  819.     while(ShovelLoot->Z > 0){
  820.        
  821.         if(Screen->ComboS[ComboAt(ShovelLoot->X + 8, ShovelLoot->Y + 8)] == 0){
  822.            
  823.             if(shovel_item_dir == 0)ShovelLoot->Y --;
  824.             else if(shovel_item_dir == 1)ShovelLoot->Y ++;
  825.             else if(shovel_item_dir == 2)ShovelLoot->X --;
  826.             else if(shovel_item_dir == 3)ShovelLoot->X ++;
  827.            
  828.         }
  829.        
  830.         Waitframe();
  831.        
  832.     }
  833.    
  834.   }
  835. }
  836.  
  837. ffc script Shovel_SP_DigPoint{
  838.     void run(int Replace_Combo, int Replace_CSet, int Secret_Item){
  839.        
  840.         //  just script a FFC as "dig point" that changes it's combo to something specific when dug
  841.         //  probably the best solution
  842.         //  since you could define on the fly what you'd want it to be
  843.        
  844.        
  845.         if(Screen->State[ST_SECRET] == false){
  846.            
  847.            
  848.         }
  849.         else{
  850.            
  851.            
  852.            
  853.         }
  854.        
  855.     }
  856. }
  857.  
  858. //Returns if the digging game is active. Used to communicate with other scripts.
  859. bool IsShovelGame()
  860. {
  861.     return (Link->Misc[MISC_GAMES]&GT_SHOVEL);
  862. }
  863.  
  864. //Sets a global condition via Link->Misc.
  865. void IsShovelGame(bool s)
  866. {
  867.     if ( s )
  868.     {
  869.         Link->Misc[MISC_GAMES] |= GT_SHOVEL;
  870.     }
  871.     else    Link->Misc[MISC_GAMES] |= ~GT_SHOVEL;
  872. }
  873.  
  874. //Clears all games from Link->Misc. Call after run() in the active script.
  875. void ClearLinkMiscGames()
  876. {
  877.     Link->Misc[MISC_GAMES] = 0;
  878. }
  879.  
  880. //global script active
  881. //  void run()
  882. //  {
  883. //      ClearLinkMiscGames(); //Put it here!
  884. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement