ZoriaRPG

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

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×