Advertisement
ZoriaRPG

ZScript: Z3 Style Magic Mirror (v0.3.3, New Solidity Check)

Nov 22nd, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.26 KB | None | 0 0
  1. ///////////////////////
  2. /// Z3 Magic Mirror ///
  3. /// v0.3.3          ///
  4. /// 22-Nov-2016     ///
  5. /// By: ZoriaRPG    ///
  6. ///////////////////////////////////////
  7. /// Partial Rewrite of the Original ///
  8. /// WarpFunctions.zh b1.1 from 2014 ///
  9. /// originally made by request for  ///
  10. /// Obderhode and used in the quest ///
  11. /// 'The Three Whistles'            ///
  12. ///////////////////////////////////////
  13.  
  14. //! To-Do
  15. //! Add in freeze flags and ghost suspension
  16.  
  17.  //! BUG    If Link is warped onto an entrance/exit (cave walk down/u) warp tile, that tile will activate and he will
  18.  //!        seem to walk in and out of a place then error out and return.
  19.  
  20.  //v0.3.3 Modified the solidity tests for a far more fine tuned check.
  21.  
  22. /// Global Array
  23. int Mirror[214747];
  24.  
  25. const int TEST_MIRROR_SPARKLE = 0;
  26. const int MIRROR_SPARKLE_BEFORE_WAITDRAW = 0;
  27.  
  28. //Moon Pearl Goodies
  29. const int I_MIRROR = 160;
  30. const int I_MOONPEARL = 200;
  31. const int I_BUNNYRING = 201; //A wisp ring twith a LTM for Bunny Sprites
  32.  
  33. //Options
  34. const int WARP_RETURNS_ON_INJURY        = 1;
  35. const int REQUIRE_MOON_PEARL            = 1;
  36. const int MIRROR_RETURNS_TO_DUNGEON_ENTRANCE    = 1; //This requires placing a warp return square on dungeon entrance screens.
  37.  
  38. const int MIRROR_POST_WARP_TIMER_NUM_FRAMES = 75; // Number of frames afer warping, before Link may use a warp return sparkle.
  39.  
  40. const int POST_WARP_LINK_IS_INVINCIBLE      = 0;     //If se tto '1', Link->CollDetection will be disabled for a number of
  41.                         //frames equal to:
  42.  
  43. const int WARP_INVULNERABILITY_FRAMES       = 90; //Number of frames that Link is invulnerable after warping.
  44.  
  45. //!! Caution: This may conflict with other items that grant invulnerability!
  46.  
  47.  
  48. ///Constants for Array Indices of Mirror[]
  49.  
  50. const int IS_WARPING        = 0;
  51. const int AFTER_WARP        = 1;
  52. const int RETURN_WARP       = 2;
  53. const int AFTER_RETURN_WARP     = 3;
  54.  
  55. const int WARP_SPARKLE          = 10;
  56. const int WARP_SPARKLE_DMAP         = 11;
  57. const int WARP_SPARKLE_SCREEN       = 12;
  58. const int WARP_SPARKLE_X        = 13;
  59. const int WARP_SPARKLE_Y        = 14;
  60. const int WARP_SPARKLE_RETURN_DMAP  = 15;
  61.  
  62. const int WARP_LINK_X           = 20;
  63. const int WARP_LINK_Y           = 21;
  64. const int WARP_LINK_Z           = 22;
  65. const int WARP_LINK_HP          = 23;
  66. const int WARP_LINK_TEMP_INVULNERABILITY = 24;
  67.  
  68. const int MIRROR_SPARKLE_COMBO_FRAME = 30; //Mirror array index
  69. const int MIRROR_POST_WARP_TIMER = 40;
  70.  
  71.  
  72.  
  73. //Settings
  74.  
  75. //Sounds
  76. const int SFX_WARP_ERROR    = 67;
  77. const int SFX_WARP      = 73;
  78. const int SFX_WARP_DUNGEON  = 16;
  79.  
  80. const int WARP_WAVE_DUR     = 100; //Duration of warp wavy animation (overworld)
  81. const int WARP_WAVE_DUR_DUNGEON = 100; //Duration of warp wavy animation (inside dungeons)
  82.  
  83. const int WARP_DUR      = 60;
  84. const int POST_WARP_DELAY   = 15;
  85.  
  86.  
  87.  
  88. //Mirror Sparkle Settings
  89. const int MIRROR_SPARKLE_COMBO      = 32596; // COmbo of sparkle or other warp return effect.
  90. const int MIRROR_SPARKLE_COMBO_LAYER    = 2;
  91. const int MIRROR_SPARKLE_COMBO_W    = 1;
  92. const int MIRROR_SPARKLE_COMBO_H    = 1;
  93. const int MIRROR_SPARKLE_COMBO_CSET     = 0;
  94. const int MIRROR_SPARKLE_COMBO_XSCALE   = -1;
  95. const int MIRROR_SPARKLE_COMBO_YSCALE   = -1;
  96. const int MIRROR_SPARKLE_COMBO_RX   = 0;
  97. const int MIRROR_SPARKLE_COMBO_RY   = 0;
  98. const int MIRROR_SPARKLE_COMBO_RANGLE   = 0;
  99.  
  100. const int MIRROR_SPARKLE_COMBO_FLIP     = 0;
  101. const int MIRROR_SPARKLE_COMBO_OPACITY  = 64;
  102.  
  103. const int MIRROR_SPARKLE_COMBO_NUM_FRAMES = 4;
  104. const int MIRROR_SPARKLE_COMBO_INIT_FRAME = 1;
  105.  
  106.  
  107.  
  108.  
  109. //Accessors
  110. int IsWarping(){ return Mirror[IS_WARPING]; }
  111. void IsWarping(bool state){ if ( state ) Mirror[IS_WARPING] = 1; else Mirror[IS_WARPING] = 0; }
  112.  
  113. int AfterWarp(){ return Mirror[AFTER_WARP]; }
  114. void AfterWarp(bool state){ if ( state ) Mirror[AFTER_WARP] = 1; else Mirror[AFTER_WARP] = 0; }
  115.  
  116. int IsReturnWarping(){ return Mirror[RETURN_WARP]; }
  117. void IsReturnWarping(bool state){ if ( state ) Mirror[RETURN_WARP] = 1; else Mirror[RETURN_WARP] = 0; }
  118.  
  119. int AfterReturnWarp(){ return Mirror[AFTER_RETURN_WARP]; }
  120. void AfterReturnWarp(bool state){ if ( state ) Mirror[AFTER_RETURN_WARP] = 1; else Mirror[AFTER_RETURN_WARP] = 0; }
  121.  
  122. int WarpSparkle(){ return Mirror[WARP_SPARKLE]; }
  123. void WarpSparkle(bool state){ if ( state ) Mirror[WARP_SPARKLE] = 1; else Mirror[WARP_SPARKLE] = 0; }
  124.  
  125. int WarpSparkleReturn(){ return Mirror[WARP_SPARKLE_RETURN_DMAP]; }
  126. void WarpSparkleReturn(int dmap){ Mirror[WARP_SPARKLE_RETURN_DMAP] = dmap; }
  127.  
  128. int WarpSparkleDMap(){ return Mirror[WARP_SPARKLE_DMAP]; }
  129. void WarpSparkleDMap(int dmap){ Mirror[WARP_SPARKLE_DMAP] = dmap; }
  130.  
  131. int WarpSparkleX(){ return Mirror[WARP_SPARKLE_X]; }
  132. void WarpSparkleX(int x){ Mirror[WARP_SPARKLE_X] = x; }
  133.  
  134. int WarpSparkleY(){ return Mirror[WARP_SPARKLE_Y]; }
  135. void WarpSparkleY(int y){ Mirror[WARP_SPARKLE_Y] = y; }
  136.  
  137. int WarpSparkleScreen(){ return Mirror[WARP_SPARKLE_SCREEN]; }
  138. void WarpSparkleScreen(int screen){ Mirror[WARP_SPARKLE_SCREEN] = screen; }
  139.  
  140. //The following four functions are used to manipulate,a nd check the post-warp timer,
  141. //that prevents Link from being sent back by a sparkle as soon as he finishes warping.
  142.  
  143. int WarpReturnWait(){ return Mirror[MIRROR_POST_WARP_TIMER]; }
  144. void ReducePostWarpTimer(){ if ( Mirror[MIRROR_POST_WARP_TIMER] > 0 ) Mirror[MIRROR_POST_WARP_TIMER]--; }
  145. void SetPostWarpTimer(){ Mirror[MIRROR_POST_WARP_TIMER] = MIRROR_POST_WARP_TIMER_NUM_FRAMES; }
  146. void ClearPostWarpTimer(){ Mirror[MIRROR_POST_WARP_TIMER] = 0; }
  147.  
  148.  
  149. //Functions
  150.  
  151. //Checks the present DMap and returns irts counterpart.
  152. //!! You must set up the arrays inside this function, for it to work.
  153. int GetOtherworldlyDMap(int dmap){
  154.     int q[4];
  155.     int LightWorldDMaps[]={3,-1,-1,-1,-1}; //Populate these two arrays with the IDs of your light and dark world dmaps
  156.     int DarkWorldDMaps[]={8,-1,-1,-1,-1}; //in matched pairs.
  157.     for ( q[0] = 0; q[0] < SizeOfArray(LightWorldDMaps); q[0]++ ) {
  158.         q[1] = LightWorldDMaps[ q[0] ];
  159.         q[2] = DarkWorldDMaps[ q[0] ];
  160.         if ( dmap == q[1] ) return DarkWorldDMaps[ q[0] ];
  161.         if ( dmap == q[2] ) return LightWorldDMaps[ q[0] ];
  162.     }
  163.     return -1;
  164. }
  165.  
  166. //Returns if the present dmap is a dark world dmap
  167. //!! You must set up the arrays inside this function, for it to work.
  168. bool IsDarkWorld(){
  169.     int DarkWorldDMaps[]={8,-1,-1,-1,-1};
  170.     for ( int q = 0; q < SizeOfArray(DarkWorldDMaps); q++ ) {
  171.         if ( Game->GetCurDMap() == DarkWorldDMaps[q] ) return true;
  172.     }
  173.     return false;
  174. }
  175.  
  176. //Generates coordinates for the warp return sparkle.
  177. //this is set when we use the mirror.
  178. void SetWarpReturn(){
  179.     WarpSparkle(true);
  180.     WarpSparkleX(Link->X);
  181.     WarpSparkleY(Link->Y);
  182.     WarpSparkleDMap( GetOtherworldlyDMap( Game->GetCurDMap() ) );
  183.     WarpSparkleScreen(Game->GetCurScreen());
  184.     WarpSparkleReturn(Game->GetCurDMap());
  185. }
  186.  
  187. //Removes the warp sparkle, after using it.
  188. void ClearWarpSparkle(){
  189.     WarpSparkle(false);
  190.     WarpSparkleX(-100);
  191.     WarpSparkleY(-100);
  192.     WarpSparkleDMap(-1);
  193.     WarpSparkleScreen(-1);
  194.     WarpSparkleReturn(-1);
  195. }
  196.  
  197. //Returns if Link is in a dungeon based on the array dungeonDMaps[]
  198. //!! You must set up the array inside this function, for it to work.
  199. bool IsDungeonDMap(){
  200.     int dungeonDMaps[]={20,21,22};//List all dungeon DMaps here
  201.     for ( int q = 0; q < SizeOfArray(dungeonDMaps); q++ ) {
  202.         if ( Game->GetCurDMap() == dungeonDMaps[q] ) return true;
  203.         return false;
  204.     }
  205. }
  206.  
  207. //Returns if the warp destination is solid, prior to warping.
  208. bool WarpDestSolid(int x, int y, int screen, int map){
  209.     return ( Game->GetComboSolid(map, screen, ComboAt(x,y)) );
  210. }
  211.    
  212. //! Main Functions to Call before Waitdraw()
  213.  
  214. //Handles the initial warp routines.
  215. void MirrorWarpLink() {
  216.     if ( IsWarping() ){
  217.         Link->X = Mirror[WARP_LINK_X];
  218.         Link->Y = Mirror[WARP_LINK_Y];
  219.         SetPostWarpTimer();
  220.         NoAction();
  221.         Game->PlaySound(SFX_WARP);
  222.         Screen->Wavy = WARP_WAVE_DUR;
  223.         //Freeze all enemies and ghost scripts
  224.         for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  225.             NoAction();
  226.             Waitframe();
  227.         }
  228.         //resume npcs and ghost scripts
  229.         Link->PitWarp(GetOtherworldlyDMap(Game->GetCurDMap()), Game->GetCurScreen());
  230.         IsWarping(false);
  231.         for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  232.             NoAction();
  233.             Waitframe();
  234.         }
  235.         AfterWarp(true);
  236.     }
  237.    
  238.     if (IsReturnWarping() ){
  239.         Mirror[WARP_LINK_HP] = Link->HP;
  240.  
  241.         Link->X = WarpSparkleX();
  242.         Link->Y = WarpSparkleY();
  243.         NoAction();
  244.         Game->PlaySound(SFX_WARP);
  245.         Screen->Wavy = WARP_WAVE_DUR;
  246.         //Freeze all enemies and ghost scripts
  247.         for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  248.             NoAction();
  249.             Waitframe();
  250.         }
  251.         //resume npcs and ghost scripts
  252.         Link->PitWarp(WarpSparkleReturn(), WarpSparkleScreen());
  253.        
  254.         IsReturnWarping(false);
  255.         for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  256.             NoAction();
  257.             Waitframe();
  258.         }
  259.         AfterReturnWarp(true);
  260.     }
  261. }
  262.  
  263. //Post-warp cleanup, and bounce.
  264. void WarpFinish() {
  265.     if (AfterWarp()){
  266.         if ( Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER ) Link->HitDir = -1;
  267.         //SetWarpReturn();
  268.         //If the destination is solid, send Link back.
  269.         if ( LinkTouchingSolid() ) {
  270.             ClearWarpSparkle();
  271.             Game->PlaySound(SFX_WARP_ERROR);
  272.             WaitNoAction();
  273.             Screen->Wavy = WARP_WAVE_DUR;
  274.             //freeze all enemies and ghost scripts.
  275.             for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY); q > 0; q--){
  276.                 NoAction();
  277.                 Waitframe();
  278.             }
  279.             //resume npcs and ghost scripts
  280.             Link->X = Mirror[WARP_LINK_X];
  281.             Link->Y = Mirror[WARP_LINK_Y];
  282.             Link->PitWarp(GetOtherworldlyDMap(Game->GetCurDMap()), Game->GetCurScreen());
  283.             Screen->Wavy = WARP_WAVE_DUR;
  284.            
  285.             AfterWarp(false);
  286.             for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY); q > 0; q--){
  287.                 NoAction();
  288.                 Waitframe();
  289.             }
  290.         }
  291.         if ( Link->HP < Mirror[WARP_LINK_HP] && WARP_RETURNS_ON_INJURY) { //If Link is injured, send him back.
  292.             Link->HP = Mirror[WARP_LINK_HP];
  293.             Game->PlaySound(SFX_WARP);
  294.             Screen->Wavy = WARP_WAVE_DUR;
  295.             //freeze all enemies and ghost scripts.
  296.             for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  297.                 NoAction();
  298.                 Waitframe();
  299.             }
  300.             //resume npcs and ghost scripts
  301.             Link->X = Mirror[WARP_LINK_X];
  302.             Link->Y = Mirror[WARP_LINK_Y];
  303.             Link->PitWarp(WarpSparkleReturn(), Game->GetCurScreen());
  304.  
  305.             Link->X = Mirror[WARP_LINK_X];
  306.             Link->Y = Mirror[WARP_LINK_Y];
  307.             Link->HP = Mirror[WARP_LINK_HP];
  308.            
  309.             AfterWarp(false);
  310.             for(int q = (WARP_WAVE_DUR + POST_WARP_DELAY) / 2; q > 0; q--){
  311.                 NoAction();
  312.                 Waitframe();
  313.             }
  314.         }
  315.         else {
  316.             Link->X = Mirror[WARP_LINK_X];
  317.             Link->Y = Mirror[WARP_LINK_Y];
  318.             //SetPostWarpTimer();
  319.             //Mirror[WARP_LINK_TEMP_INVULNERABILITY] = WARP_INVULNERABILITY_FRAMES;
  320.             AfterWarp(false);
  321.         }
  322.     }
  323.    
  324.     if (AfterReturnWarp()){
  325.         if ( Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER ) Link->HitDir = -1;
  326.         ClearWarpSparkle();
  327.         Mirror[WARP_LINK_TEMP_INVULNERABILITY] = WARP_INVULNERABILITY_FRAMES;
  328.         AfterReturnWarp(false);
  329.         ClearPostWarpTimer();
  330.            
  331.     }
  332.    
  333.     if ( POST_WARP_LINK_IS_INVINCIBLE ) {
  334.         if ( Mirror[WARP_LINK_TEMP_INVULNERABILITY] ) {
  335.             //If we find a way to Flicker Link, it goes here.
  336.             Link->CollDetection = false;
  337.             Mirror[WARP_LINK_TEMP_INVULNERABILITY]--;
  338.         }
  339.         if ( !Mirror[WARP_LINK_TEMP_INVULNERABILITY] ) Link->CollDetection = true;
  340.     }
  341.    
  342.     //if ( Mirror[MIRROR_POST_WARP_TIMER] > 0 ) Mirror[MIRROR_POST_WARP_TIMER]--;
  343. }
  344.  
  345. //Checks if any of Link's corners ar eon a solid combo.
  346. bool LinkTouchingSolid(){
  347.     if ( Screen->isSolid(Link->X, Link->Y) ||
  348.         Screen->isSolid(Link->X+8, Link->Y+8) ||
  349.         Screen->isSolid(Link->X, Link->Y+8) ||
  350.         Screen->isSolid(Link->X+8, Link->Y) ||
  351.         Screen->isSolid(Link->X+8, Link->Y+16) ||
  352.         Screen->isSolid(Link->X+16, Link->Y+8)  || 
  353.         Screen->isSolid(Link->X+15, Link->Y) ||
  354.         Screen->isSolid(Link->X, Link->Y+15) ||
  355.         Screen->isSolid(Link->X+15, Link->Y+15)) return true;
  356.     return false;
  357. }
  358.  
  359. //Creates the mirror return sparkle.
  360. void MirrorSparkle(){
  361.     if ( Game->GetCurDMap() == WarpSparkleDMap() && Game->GetCurScreen() == WarpSparkleScreen() ) {
  362.         Screen->DrawCombo(  MIRROR_SPARKLE_COMBO_LAYER, WarpSparkleX(), WarpSparkleY(),
  363.             MIRROR_SPARKLE_COMBO, MIRROR_SPARKLE_COMBO_H, MIRROR_SPARKLE_COMBO_W, MIRROR_SPARKLE_COMBO_CSET,
  364.             MIRROR_SPARKLE_COMBO_XSCALE, MIRROR_SPARKLE_COMBO_YSCALE, MIRROR_SPARKLE_COMBO_RX,
  365.             MIRROR_SPARKLE_COMBO_RY, MIRROR_SPARKLE_COMBO_RANGLE, Mirror[MIRROR_SPARKLE_COMBO_FRAME],
  366.             MIRROR_SPARKLE_COMBO_FLIP, true, MIRROR_SPARKLE_COMBO_OPACITY) ; //Mirror sparkle
  367.        
  368.         //Reduce the frames
  369.         if ( Mirror[MIRROR_SPARKLE_COMBO_FRAME] >= MIRROR_SPARKLE_COMBO_NUM_FRAMES ) Mirror[MIRROR_SPARKLE_COMBO_FRAME] = MIRROR_SPARKLE_COMBO_INIT_FRAME;
  370.         else Mirror[MIRROR_SPARKLE_COMBO_FRAME]++;
  371.            
  372.         if ( !WarpReturnWait() && !IsTempInvincible() ){
  373.            
  374.             if ( Abs( Link->X - WarpSparkleX()) < 8 && Abs(Link->Y - WarpSparkleY()) < 8 )
  375.             {
  376.                 //Reurn Link via the portal
  377.                 IsReturnWarping(true);
  378.             }
  379.         }
  380.     }
  381. }
  382.  
  383. bool IsTempInvincible(){
  384.     if ( Mirror[WARP_LINK_TEMP_INVULNERABILITY] && POST_WARP_LINK_IS_INVINCIBLE ) return true;
  385.     if ( !Mirror[WARP_LINK_TEMP_INVULNERABILITY] || !POST_WARP_LINK_IS_INVINCIBLE ) return false;
  386. }
  387.  
  388. void TestSparkle(){
  389.     int x = WarpSparkleX();
  390.     int y = WarpSparkleY();
  391.     if ( x < 0 ) x = 0;
  392.     if ( y < 0 ) y = 0;
  393.     Screen->DrawCombo(  MIRROR_SPARKLE_COMBO_LAYER, x, y,
  394.             MIRROR_SPARKLE_COMBO, MIRROR_SPARKLE_COMBO_H, MIRROR_SPARKLE_COMBO_W, MIRROR_SPARKLE_COMBO_CSET,
  395.             MIRROR_SPARKLE_COMBO_XSCALE, MIRROR_SPARKLE_COMBO_YSCALE, MIRROR_SPARKLE_COMBO_RX,
  396.             MIRROR_SPARKLE_COMBO_RY, MIRROR_SPARKLE_COMBO_RANGLE, Mirror[MIRROR_SPARKLE_COMBO_FRAME],
  397.             MIRROR_SPARKLE_COMBO_FLIP, true, MIRROR_SPARKLE_COMBO_OPACITY) ; //Mirror sparkle
  398.        
  399.         //Reduce the frames
  400.         if ( Mirror[MIRROR_SPARKLE_COMBO_FRAME] >= MIRROR_SPARKLE_COMBO_NUM_FRAMES ) Mirror[MIRROR_SPARKLE_COMBO_FRAME] = MIRROR_SPARKLE_COMBO_INIT_FRAME;
  401.         else Mirror[MIRROR_SPARKLE_COMBO_FRAME]++;
  402. }
  403.  
  404.  
  405. //Runs the moon pearl bunny sprite change, and halts using any item other than the mirror.
  406. void MoonPearl(){
  407.     if ( IsDarkWorld() && !Link->Item[I_MOONPEARL] && !Link->Item[I_BUNNYRING] ) Link->Item[I_BUNNYRING] = true;
  408.     if ( !IsDarkWorld() && Link->Item[I_BUNNYRING] ) Link->Item[I_BUNNYRING] = false;
  409.     if ( IsDarkWorld() && Link->Item[I_MOONPEARL] && Link->Item[I_BUNNYRING] ) Link->Item[I_BUNNYRING] = false;
  410.     if ( Link->Item[I_BUNNYRING] ) {
  411.         if ( Link->PressA && GetEquipmentA() != I_MIRROR ) Link->PressA = false;
  412.         if ( Link->PressB && GetEquipmentB() != I_MIRROR ) Link->PressB = false;
  413.     }
  414. }
  415.  
  416. /// Items
  417.  
  418. item script Mirror{
  419.     void run(){
  420.         if ( IsDungeonDMap() && MIRROR_RETURNS_TO_DUNGEON_ENTRANCE ) {
  421.             //Warp to dungeon entrance.
  422.             Game->PlaySound(SFX_WARP_DUNGEON);
  423.             Screen->Wavy = WARP_WAVE_DUR_DUNGEON;
  424.             Link->Warp(Game->GetCurDMap(), Game->DMapContinue[Game->GetCurDMap()]);
  425.         }
  426.         else {
  427.             if ( IsDarkWorld() ) {
  428.                 SetPostWarpTimer();
  429.                 //Mirror[MIRROR_POST_WARP_TIMER] = MIRROR_POST_WARP_TIMER_NUM_FRAMES;
  430.                 Mirror[WARP_LINK_X] = Link->X;
  431.                 Mirror[WARP_LINK_Y] = Link->Y;
  432.                 Mirror[WARP_LINK_HP] = Link->HP;
  433.                 SetWarpReturn();
  434.                 IsWarping(true);
  435.             }
  436.             //Warp to other world
  437.             if ( !IsDarkWorld() && SFX_WARP_ERROR ) Game->PlaySound(SFX_WARP_ERROR);
  438.         }
  439.     }
  440. }
  441.  
  442. //Global Script Example
  443.  
  444. global script Z3_Mirror{
  445.     void run(){
  446.         while(true){
  447.             if ( REQUIRE_MOON_PEARL ) MoonPearl();
  448.             ReducePostWarpTimer();
  449.             MirrorWarpLink();
  450.            
  451.             //if ( TEST_MIRROR_SPARKLE ) TestSparkle();
  452.             //if ( MIRROR_SPARKLE_BEFORE_WAITDRAW ) MirrorSparkle();
  453.             WarpFinish();
  454.             Waitdraw();
  455.            
  456.             //if ( !MIRROR_SPARKLE_BEFORE_WAITDRAW ) MirrorSparkle();
  457.             if ( WarpSparkle() ) MirrorSparkle(); //Call only if it exists.
  458.             Waitframe();
  459.         }
  460.     }
  461. }
  462.  
  463. //Deprecated
  464.  
  465. const int SOLIDITY_CHECK_DISTANCE = 8;
  466.  
  467. bool TouchingSolid(int x, int y) {
  468.     if ( Screen->isSolid(x,y) ||
  469.         Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y) ||
  470.         Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y+SOLIDITY_CHECK_DISTANCE) ||
  471.         Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y-SOLIDITY_CHECK_DISTANCE) ||
  472.         Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y) ||
  473.         Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y+SOLIDITY_CHECK_DISTANCE) ||
  474.         Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y-SOLIDITY_CHECK_DISTANCE) ) {
  475.         return true;
  476.     }
  477.     return false;
  478. }
  479.  
  480. bool TouchingSolid(){
  481.     if ( Screen->isSolid(Link->X,Link->Y) ||
  482.         Screen->isSolid(Link->X + 15, Link->Y) ||
  483.         Screen->isSolid(Link->X + 15, Link->Y+15) ||
  484.         Screen->isSolid(Link->X + 15, Link->Y-15) ||
  485.         Screen->isSolid(Link->X - 15, Link->Y) ||
  486.         Screen->isSolid(Link->X - 15, Link->Y+15) ||
  487.         Screen->isSolid(Link->X - 15, Link->Y-15) )
  488.     {
  489.         return true;
  490.     }
  491.     return false;
  492. }
  493.  
  494.  
  495.  
  496. //Cape
  497.  
  498. //Cane of Byrna
  499.  
  500. //! I need to include these, along with IsInvisible() and IsInvincible() to ensure that there ar eno comflicts between this and other cape/cane scripts.
  501.  
  502. const int CAPE_ON = 50;
  503. const int BYRNA_ON = 51;
  504.  
  505. item script CapeOfInvisibility{
  506.     void run(){
  507.         if ( Mirror[CAPE_ON] ) { Mirror[CAPE_ON] = 0; }
  508.         else Mirror[CAPE_ON] = 1;
  509.     }
  510. }
  511.  
  512. item script CaneOfByrna{
  513.     void run(){
  514.         if ( Mirror[BYRNA_ON] ) { Mirror[BYRNA_ON] = 0; }
  515.         else Mirror[BYRNA_ON] = 1;
  516.     }
  517. }
  518.  
  519. void CaneOfByrna(){}
  520. void CapeOfInvisibility(){}
  521.  
  522. bool IsInvisible(){
  523.     if ( Mirror[CAPE_ON] ) return true;
  524.     return false;
  525. }
  526.  
  527. bool IsInvincible(){
  528.     if ( Mirror[BYRNA_ON] || Mirror[WARP_LINK_TEMP_INVULNERABILITY] ) return true;
  529.     return false;
  530. }
  531.  
  532. void HandleInvisibilityAndInvincibility(){
  533.     if ( IsInvisible() ) Link->Invisible = true;
  534.     else Link->Invisible = false;
  535.     if ( IsInvincible() ) Link->CollDetection = false;
  536.     else Link->CollDetection = true;
  537. }
  538.  
  539. //! We can tighten this down baed on Link's proximity to the grid.
  540. bool LinkTouchingSolidCombo(){
  541.     int cmb[6];
  542.     cmb[0] = ComboAt(Link->X, Link->Y);
  543.     cmb[1] = ____AdjacentCombo(cmb,3);
  544.     cmb[2] = ____AdjacentCombo(cmb,5);
  545.     cmb[3] = ____AdjacentCombo(cmb,4);
  546.     for ( cmb[4] = 0; cmb[4] <= 2; cmb[4]++ ) {
  547.         for ( cmb[5] = 0; cmb[5] <= 4; cmb[5]++ ) {
  548.             if ( GetLayerComboS(cmb[4], cmb[ cmb[5] ]) > 0 ) return true;
  549.         }
  550.     }
  551. }
  552.  
  553.  
  554. //Constants for AdjacentCombo()
  555.  
  556. //const int CMB_UPLEFT    = 0;
  557. //const int CMB_UP        = 1;
  558. //const int CMB_UPRIGHT   = 2;
  559. //const int CMB_RIGHT     = 3;
  560. //const int CMB_DOWNRIGHT = 4;
  561. //const int CMB_DOWN      = 5;
  562. //const int CMB_DOWNLEFT  = 6;
  563. //const int CMB_LEFT      = 7;
  564. //const int CMB_LEFTUP    = 0; //Not 8, as those are dir + shield
  565.  
  566. //Returns the Nuth combo index of a combo based on a central point, and a direction.
  567. //For example, combo 22 + COMBO_UPRIGHT returns '7',
  568. //as combo 7 is to the upper-right of combo 22.
  569. int ____AdjacentCombo(int cmb, int dir){
  570.     int combooffsets[13]={-0x10,-0x0F,-0x0E,1,0x10,0x0F,0x0E,-1,-0x10};
  571.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  572.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  573.     if ( cmb < 0x10 ) combooffsets[11] = 1;
  574.     if ( cmb < 0xAF ) combooffsets[12] = 1;
  575.     if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return 0;
  576.     if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return 0;
  577.     if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT ) ) return 0;
  578.     if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return 0;
  579.     else if ( cmb > 0 && cmb < 177 ) return cmb + combooffsets[dir];
  580.     else return 0;
  581. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement