Advertisement
ZoriaRPG

ZC Xtal Switches / Dungeon Barriers / Crystal Switches

Nov 19th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.66 KB | None | 0 0
  1. /// Xtal Switches
  2. /// By: ZoriaRPG
  3.  
  4. //Settings
  5. const int LINK_WALK_BLOCKS = 1; //Link can walk on a barrier block if he was standing on that type when they changed.
  6.  
  7. //Crystal Switch Combo IDs:
  8.  
  9. const int CMB_XTAL_RED_UP       = 0; //Red switch, up state combo.
  10. const int CMB_XTAL_RED_DOWN     = 0; //Red switch, down state combo.
  11. const int CMB_XTAL_BLUE_UP      = 0; //Blue switch, up state combo.
  12. const int CMB_XTAL_BLUE_DOWN        = 0; //Blue switch, down state combo.
  13. const int CMB_XTAL_SWITCH_TRIG      = 0; //Combo ID of the trigger.
  14.  
  15. const int CMB_XTAL_BLUE_UP_WALKABLE = 0; //Blue switch, WALKABLE up state combo.
  16. const int CMB_XTAL_RED_UP_WALKABLE  = 0; //Red switch, WALKABLE up state combo.
  17.  
  18. //Switch States
  19. const int XTAL_BLUE_UP          = 1;
  20. const int XTAL_RED_UP           = 0;
  21.  
  22. //DMAP Constants
  23. const int MAX_XTAL_DMAPS        = 463;  //Set to number of DMAPs in use.
  24.                         //Only Dmaps 0 through 462 are usable for this.
  25. const int XTAL_SHARED           = 1;
  26. const int XTAL_NOT_SHARED       = 0;
  27.  
  28. //Sounds
  29. const int SFX_XTAL_SWITCH       = 0; //Sound ID for hitting a Crystal Switch Trigger.
  30.  
  31. //Arrays
  32.  
  33. float XtalSwitches[464]; //Set index size, to number of DMAPs in use + 1.
  34. float XTalSwitchesList[214369]; //Set index size, to number of DMAPs in use, SQUARED.
  35. //512 DMAps is too many though, as the maximum number of indices is 214747.
  36. //463 is the maximum.
  37.  
  38. const int LINK_ON_BLOCK  = 464; //Set to the last index of XtalSwitches[]
  39.  
  40. float XtalSwitchTriggerLWeapons[]={0};
  41. float XtalSwitchTriggerEWeapons[]={0};
  42.  
  43. void XtalSwitchTrig(int cmb, bool limitLW){
  44.     int c;
  45.     int curDMAP = Game->GetCurDMap();
  46.     for ( int q = 0; q < 176; q ++ ) {
  47.         c = Screen->ComboD[q];
  48.         if ( c == cmb ) {
  49.             for ( int w = 1; w < Screen->NumLWeapons(); w++ ){
  50.                 lweapon l = Screen->LoadLWeapon(w);
  51.                
  52.                 if ( limitLW ) {
  53.                 if ( l->Type != LW_SWORD || l->Type != LW_BRANG ||
  54.                     l->Type != LW_HOOKSHOT || l=>Type != LW_MAGIC || l->Type != LW_HAMMER ) continue;
  55.                 if ( Collision(c,l) SetXtalSwitch(curDMAP);
  56.             }
  57.         }
  58.     }
  59. }
  60.  
  61. //Use list of LWeapons to trigger switches.
  62. void XtalSwitchTrig(int cmb, int listLW){
  63.     int c;
  64.     int curDMAP = Game->GetCurDMap();
  65.     bool match;
  66.     for ( int q = 0; q < 176; q ++ ) {
  67.         c = Screen->ComboD[q];
  68.         if ( c == cmb ) {
  69.             for ( int w = 1; w < Screen->NumLweapons(); w++ ){
  70.                 lweapon l = Screen->LoadLWeapon(w);
  71.                
  72.                 for ( int e = 0; e < SizeOfArray(listLW) e++ ) {
  73.                     if ( l->Type == listLW[e] ) {
  74.                         match = true;
  75.                     }
  76.                 }
  77.                 if ( match && Collision(c,l) ) SetXtalSwitch(curDMAP);
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. //Use list of LWeapons to trigger switches.
  84. void XtalSwitchTrig(int cmb, int weapList, bool eWeapons){
  85.     int c;
  86.     int curDMAP = Game->GetCurDMap();
  87.     bool match;
  88.     for ( int q = 0; q < 176; q ++ ) {
  89.         c = Screen->ComboD[q];
  90.         if ( c == cmb ) {
  91.             if ( !eWeapons ) {
  92.                 for ( int w = 1; w < Screen->NumLWeapons(); w++ ){
  93.                     lweapon l = Screen->LoadLWeapon(w);
  94.                     for ( int e = 0; e < SizeOfArray(weapList) e++ ) {
  95.                         if ( l->Type == weapList[e] ) match = true;
  96.                     }
  97.                 }
  98.                 if ( match && Collision(c,l) ) SetXtalSwitch(curDMAP);
  99.             }
  100.             if ( eWeapons ) {
  101.                 for ( int w = 1; w < Screen->NumEWeapons(); w++ ){
  102.                     eweapon l = Screen->LoadEWeapon(w);
  103.                     for ( int e = 0; e < SizeOfArray(weapList) e++ ) {
  104.                         if ( l->Type == weapList[e] ) match = true;
  105.                     }
  106.                 }
  107.                 if ( match && Collision(c,l) ) SetXtalSwitch(curDMAP);
  108.             }
  109.         }
  110.     }
  111. }
  112.  
  113. //Use list of LWeapons, to trigger switches, plus list of eweapons.
  114. void XtalSwitchTrig(int cmb, int listLW, int listEW){
  115.     int c;
  116.     int curDMAP = Game->GetCurDMap();
  117.     bool match;
  118.     for ( int q = 0; q < 176; q ++ ) {
  119.         c = Screen->ComboD[q];
  120.         if ( c == cmb ) {
  121.             for ( int w = 1; w < Screen->NumLWeapons(); w++ ){
  122.                 lweapon l = Screen->LoadLWeapon(w);
  123.                
  124.                 for ( int e = 0; e < SizeOfArray(listLW); e++ ) {
  125.                     if ( l->Type == listLW[e] ) {
  126.                         match = true;
  127.                     }
  128.                 }
  129.                 for ( int r = 0; r < SizeOfArray(listEW); r++ ) {
  130.                     if ( l->Type == listEW[r] ) {
  131.                         match = true;
  132.                     }
  133.                 }
  134.                 if ( match && Collision(c,l) ) SetXtalSwitch(curDMAP);
  135.             }
  136.         }
  137.     }
  138. }
  139.  
  140. void SetXtalSwitch(int dmap){
  141.     Game->PlaySound(SFX_XTAL_SWITCH);
  142.     if ( XtalSwitches[dmap] ) XtalSwitches[dmap] = XTAL_RED_UP;
  143.     else XtalSwitches[dmap] = XTAL_BLUE_UP;
  144.     XtalSwitches_SetDMAPs(dmap);
  145. }
  146.  
  147.  
  148.  
  149. global script activeExample{
  150.     void run(){
  151.         while(true){
  152.             Xtals();
  153.             Waitdraw();
  154.             Waitframe();
  155.         }
  156.     }
  157. }
  158.  
  159.  
  160.  
  161. //Run before Waitdraw().
  162. void Xtals(){
  163.     int dmap = Game->GetCurDMap();
  164.     int cmb;
  165.  
  166.     if ( XtalSwitches[dmap] ) { //Blue is up
  167.         for ( int q = 1; q < 176; q++ ){
  168.             cmb = Screen->ComboD[q];
  169.             if ( cmb == CMB_XTAL_BLUE_DOWN ) Screen->ComboD[q] = CMB_XTAL_BLUE_UP;
  170.             if ( cmb == CMB_XTAL_RED_UP ) Screen->ComboD[q] = CMB_XTAL_RED_DOWN;
  171.             if ( LinkComboD == CMB_XTAL_BLUE_UP && LINK_WALK_BLOCKS ) Screen->ComboD[q] = CMB_XTAL_BLUE_UP_WALKABLE;
  172.            
  173.         }
  174.     }
  175.     else {
  176.         for ( int q = 1; q < 176; q++ ){
  177.             cmb = Screen->ComboD[q];
  178.             if ( cmb == CMB_XTAL_BLUE_UP ) Screen->ComboD[q] = CMB_XTAL_BLUE_DOWN;
  179.             if ( cmb == CMB_XTAL_RED_DOWN ) Screen->ComboD[q] = CMB_XTAL_RED_UP;
  180.             if ( LinkComboD == CMB_XTAL_RED_UP && LINK_WALK_BLOCKS ) Screen->ComboD[q] = CMB_XTAL_RED_UP_WALKABLE;
  181.         }
  182.     }
  183. }
  184.  
  185. //Sets switch positions for each DMAP, based on a list.
  186. void XtalSwitches_SetDMAPs(){
  187.     int curDMAP = Game->GetCurDMap();
  188.     for ( int q = 0; q <= MAX_XTAL_DMAPS; q++ ){
  189.         if ( XTalSwitchesList[ (curDMAP * MAX_XTAL_DMAPS) + q] ) {
  190.             if ( XtalSwitches[q] != XtalSwitches[curDMAP] )
  191.             XtalSwitches[q] = XtalSwitches[curDMAP];
  192.         }
  193.     }
  194. }
  195.  
  196. //Sets switch positions for each DMAP, based on a list.
  197. void XtalSwitches_SetDMAPs(int curDMAP){
  198.     for ( int q = 0; q <= MAX_XTAL_DMAPS; q++ ){
  199.         if ( XTalSwitchesList[ (curDMAP * MAX_XTAL_DMAPS) + q] ) {
  200.             if ( XtalSwitches[q] != XtalSwitches[curDMAP] )
  201.             XtalSwitches[q] = XtalSwitches[curDMAP];
  202.         }
  203.     }
  204. }
  205.    
  206.  
  207. //Run before Waitdraw().
  208. //void XtalSwitches(){
  209.     //XtalSwitches_SetDMAPs();
  210. //  Xtals();
  211. //}
  212.  
  213. //void XtalSwitchesFlip(int dmap){
  214.    
  215.  
  216.    
  217. //! These functions allow you to add shared DMAPs to the list.
  218.  
  219. // SetXtalSwitches(16,3,true)
  220. // This sets DMAP 3 to share the state of DMAP 16
  221.  
  222. //Add another DMAP to the switches affected by triggering them from a single DMAP.
  223. //Row is the base DMAP. Column is the DMAP to share its state.
  224. void SetXtalSwitches(int row, int column, int shared){
  225.     XTalSwitchesList[ (row * MAX_XTAL_DMAPS ) + column] = shared;
  226. }
  227.  
  228. //Add another DMAP to the switches affected by triggering them from a single DMAP.
  229. //Row is the base DMAP. Column is the DMAP to share its state.
  230. void SetXtalSwitches(int row, int column, bool shared){
  231.     int share;
  232.     if ( shared ) share = 1;
  233.     XTalSwitchesList[ (row * MAX_XTAL_DMAPS ) + column] = share;
  234. }
  235.  
  236. //float XTalSwitchesList[100] = {
  237. //          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  238. //  ;
  239.    
  240.  
  241.  
  242.  
  243. global script onExit{
  244.     void run(){
  245.         ClearXtalSwitches();
  246.     }
  247. }
  248.    
  249.  
  250. void ClearXtalSwitches(){
  251.     for ( int q = 0; q <= 512; q++ ){
  252.         XtalSwitches[q] = 0;
  253.     }
  254. }
  255.  
  256. // Return ComboD for combo Link is over.
  257. int LinkComboD() {
  258.  return Screen->ComboD[ComboAt(Link->X+8, Link->Y+13)];
  259. }
  260.  
  261. // Return ComboI for combo Link is over.
  262. int LinkComboI() {
  263.  return Screen->ComboI[ComboAt(Link->X+8, Link->Y+13)];
  264. }
  265.  
  266. // Return ComboF for combo Link is over.
  267. int LinkComboF() {
  268.  return Screen->ComboF[ComboAt(Link->X+8, Link->Y+13)];
  269. }
  270.  
  271. // Return ComboS for combo Link is over.
  272. int LinkComboS() {
  273.  return Screen->ComboS[ComboAt(Link->X+8, Link->Y+13)];
  274. }
  275.  
  276. // Return ComboC for combo Link is over.
  277. int LinkComboC() {
  278.  return Screen->ComboC[ComboAt(Link->X+8, Link->Y+13)];
  279. }
  280.  
  281. // Return ComboT for combo Link is over.
  282. int LinkComboT() {
  283.  return Screen->ComboT[ComboAt(Link->X+8, Link->Y+13)];
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement