ZoriaRPG

Callback Chests Alpha 3

Aug 6th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.75 KB | None | 0 0
  1. //Chests Using Callbacks, Alpha 3
  2.  
  3. float CallBacks[1024];  //0 is NULL, and the current callback index; the rest are array pointers.
  4.  
  5. item script Pickup_Chest_Callback{
  6.     void run(int message){
  7.         SetScreenDBit(Game->GetCurScreen(), CHEST_REGISTER, bit, true);
  8.        
  9.        
  10.         int ptr = GetCurrentCallBack();
  11.        
  12.         //Callback messages.
  13.         int item_id = ptr[0];
  14.         int bit = ptr[1];
  15.         int key_type = ptr[2];
  16.         //int sound = ptr[2];
  17.         int holdtype = ptr[3];
  18.         int combo_pos = ptr[4];
  19.         int layer = ptr[5];
  20.         int chest_type = ptr[6];
  21.        
  22.         void ChestOpened(bit, true); //Mark the chest opened.
  23.        
  24.         if ( key_type == 1 ) Game->DCounter[CR_KEYS] -= 1; //Regular key
  25.         if ( key_type == 2 ) Game->LKeys[Game->GetCurLevel()] -= 1; //Boss Key
  26.        
  27.        
  28.         if ( sound > 0 ) { Game->PlaySound(sound); }
  29.         if ( message > 0 ) { Screen->Message(sound); }
  30.        
  31.         if ( holdtype ) {
  32.             Link->Action = LA_HOLD1LAND + holdtype - 1;
  33.             Link->HeldItem = item_id;
  34.         }
  35.        
  36.         //Update the chest combos based on the positions and chest types on the given layer.
  37.         if ( chest_type == CHEST_TYPE_SMALL ) {
  38.             SetLayerComboD(layer, combo_pos, (GetLayerComboD(layer, combo_pos)+1);
  39.         }
  40.        
  41.         if ( chest_type == CHEST_TYPE_BIG ) {
  42.             SetLayerComboD(layer, combo_pos, (GetLayerComboD(layer, combo_pos)+1);
  43.             SetLayerComboD(layer, combo_pos+1, (GetLayerComboD(layer, combo_pos)+1);
  44.         }
  45.        
  46.         if ( chest_type == CHEST_TYPE_GRAND ) {
  47.             SetLayerComboD(layer, combo_pos, (GetLayerComboD(layer, combo_pos)+1);
  48.             SetLayerComboD(layer, combo_pos+1, (GetLayerComboD(layer, combo_pos)+1);
  49.             SetLayerComboD(layer, combo_pos-15, (GetLayerComboD(layer, combo_pos)+1);
  50.             SetLayerComboD(layer, combo_pos-16, (GetLayerComboD(layer, combo_pos)+1);
  51.         }
  52.        
  53.         ClearCallBack(ptr);
  54.         ClearCurrentCallBack();
  55.     }
  56. }
  57.  
  58. //void SetCallBackStart(int index) {
  59.    
  60. //}
  61.  
  62. void ClearCallBacks() {
  63.     int sz = SizeOfArray(CallBacks);
  64.     for ( int q = 0; q < zs; q++ ) {
  65.         CallBacks[q] = -1;
  66.     }
  67. }
  68.  
  69. int GetFreeCallback() {
  70.     for ( int q = 0; q < zs; q++ ) {
  71.         if ( CallBacks[q] == -1 ) return q;
  72.     }
  73.     return 0; //Null Callback ID
  74. }
  75.  
  76. int SetCurrentCallBack(){
  77.     int cb = GetFreeCallback();
  78.     if (cb) { CallBacks[0] = cb; return cb; }
  79.     return 0;
  80. }
  81.  
  82. int GetCurrentCallBack(){
  83.     return CallBacks[0];
  84. }
  85.  
  86. int StoreCallBack(int ptr){
  87.     int cb = GetCurrentCallBack();
  88.     if (cb) { CallBacks[cb] = ptr; return 1; }
  89.     return 0;
  90. }
  91.  
  92. void ClearCallBack(int value){
  93.      CallBacks[value] = -1;
  94. }
  95.  
  96. bool ClearCurrentCallBack(){
  97.     int cb = CallBacks[0];
  98.     CallBacks[cb] = -1;
  99. }
  100.  
  101. //Screen->D[reg] to use for chest open flagss.
  102. const int CHEST_REGISTER = 5;
  103.  
  104. const int CHEST_ONE     = 00000001b;
  105. const int CHEST_TWO     = 00000010b;
  106. const int CHEST_THREE   = 00000100b;
  107. const int CHEST_FOUR    = 00001000b;
  108. const int CHEST_FIVE    = 00010000b;
  109. const int CHEST_SIX     = 00100000b;
  110. const int CHEST_SEVEN   = 01000000b;
  111. const int CHEST_EIGHT   = 10000000b;
  112.  
  113. bool ChestOpenedSpecific(int flag){
  114.     return ( (Screen->D[CHEST_REGISTER]&flag) != 0 );
  115. bool ChestOpened(int index){
  116.     return ((Screen->D[CHEST_REGISTER] & (01b << index) ) != 0);
  117. }
  118. void ChestOpened(int index, bool state){
  119.     if ( state ) { (Screen->D[CHEST_REGISTER] |= (01b << index) ); }
  120.     else { (Screen->D[CHEST_REGISTER] &= (~(01b << index)) ); }
  121. }
  122.  
  123. void ChestOpenedSpecific(int flag, bool state){
  124.     if ( state ) { (Screen->D[CHEST_REGISTER] |= flag ); }
  125.     else { Screen->D[CHEST_REGISTER] &= ~flag; }
  126. }
  127.  
  128. //Combos
  129. const int CMB_CHEST_SMALL = 0;
  130. const int CMB_CHEST_SMALL_LOCKED = 0;
  131. const int CMB_CHEST_SMALL_BOSSLOCKED = 0;
  132.  
  133. //Big chests,  1x2 left combo of each
  134. const int CMB_CHEST_BIG = 0;
  135. const int CMB_CHEST_BIG_LOCKED = 0;
  136. const int CMB_CHEST_BIG_BOSSLOCKED = 0;
  137.  
  138. //Big chests, 4x4 combo saize, bottom-left combo.
  139. const int CMB_CHEST_LARGE = 0;
  140. const int CMB_CHEST_LARGE_LOCKED = 0;
  141. const int CMB_CHEST_LARGE_BOSSLOCKED = 0;
  142.  
  143. //const int CHEST_LAYER = 1; //Layer on which chests are placed.
  144.  
  145. //Check for chests on these layers. 0 = No, 1= yes.
  146. const int CHEST_LAYER_0 = 1; //Check for chests on layer 0
  147. const int CHEST_LAYER_1 = 1; //Check for chests on layer 1
  148. const int CHEST_LAYER_2 = 1; //Check for chests on layer 2
  149.  
  150. const int CHEST_HOLDUP_TYPE = 1; //0 = none, 1 = one hand, 2 = two hands.
  151.  
  152. //Type definitions, DO NOT CHANGE.
  153. const int CHEST_TYPE_SMALL = 1;
  154. const int CHEST_TYPE_SMALL_LOCKED = 2;
  155. const int CHEST_TYPE_SMALL_BOSSLOCKED = 3;
  156. const int CHEST_TYPE_BIG = 4;
  157. const int CHEST_TYPE_BIG_LOCKED = 5;
  158. const int CHEST_TYPE_BIG_BOSSLOCKED = 6;
  159. const int CHEST_TYPE_GRAND = 7;
  160. const int CHEST_TYPE_GRAND_LOCKED = 8;
  161. const int CHEST_TYPE_GRAND_BOSSLOCKED = 9;
  162.  
  163. const int SFX_CHEST_UNLOCK = 0;
  164.  
  165. const int CHEST_ITEM_SPAWN_DISTANCE = 48;
  166. const int SFX_CHEST_ITEM_ANIM = 0;
  167. const int CHEST_ITEM_ANIM_DUR = 100;
  168. const float CHEST_ITEM_ANIM_MOVE_SPEED = 0.334;
  169.  
  170. const int CHEST_BUTTON_A = 1;
  171. const int CHEST_BUTTON_B = 0;
  172.  
  173. bool PressChestButton(){
  174.     if ( CHEST_BUTTON_A && Link->PressA ) return true;
  175.     if ( CHEST_BUTTON_B && Link->PressB ) return true;
  176.     return false;
  177. }
  178.  
  179. bool IsChest(int cmb){
  180.     int chests[]={CMB_CHEST_LARGE_BOSSLOCKED, CMB_CHEST_LARGE_LOCKED, CMB_CHEST_LARGE, CMB_CHEST_BIG_BOSSLOCKED,
  181.             CMB_CHEST_BIG_LOCKED,CMB_CHEST_BIG, CMB_CHEST_SMALL_BOSSLOCKED,
  182.             CMB_CHEST_SMALL_LOCKED, CMB_CHEST_SMALL};
  183.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  184.         if ( cmb == chests[q] ) return true;
  185.     }
  186.     return false;
  187. }
  188.  
  189. bool IsSmallChest(int cmb){
  190.     int chests[]={CMB_CHEST_SMALL_BOSSLOCKED,
  191.             CMB_CHEST_SMALL_LOCKED, CMB_CHEST_SMALL};
  192.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  193.         if ( cmb == chests[q] ) return true;
  194.     }
  195.     return false;
  196. }
  197.  
  198. bool IsBigChest(int cmb){
  199.     int chests[]={CMB_CHEST_BIG_BOSSLOCKED,
  200.             CMB_CHEST_BIG_LOCKED,CMB_CHEST_BIG};
  201.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  202.         if ( cmb == chests[q] ) return true;
  203.     }
  204.     return false;
  205. }
  206.  
  207. bool IsGrandChest(int cmb){
  208.     int chests[]={CMB_CHEST_LARGE_BOSSLOCKED, CMB_CHEST_LARGE_LOCKED, CMB_CHEST_LARGE};
  209.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  210.         if ( cmb == chests[q] ) return true;
  211.     }
  212.     return false;
  213. }
  214.  
  215. bool IsUnlockedChest(int cmb){
  216.     int chests[]={CMB_CHEST_LARGE, CMB_CHEST_BIG, CMB_CHEST_SMALL};
  217.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  218.         if ( cmb == chests[q] ) return true;
  219.     }
  220.     return false;
  221. }
  222.  
  223. bool IsLockedChest(int cmb){
  224.     int chests[]={CMB_CHEST_LARGE_LOCKED, CMB_CHEST_BIG_LOCKED, CMB_CHEST_SMALL_LOCKED};
  225.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  226.         if ( cmb == chests[q] ) return true;
  227.     }
  228.     return false;
  229. }
  230.  
  231. bool IsBossLockedChest(int cmb){
  232.     int chests[]={CMB_CHEST_LARGE_BOSSLOCKED, CMB_CHEST_BIG_BOSSLOCKED, CMB_CHEST_SMALL_BOSSLOCKED};
  233.     for ( int q = SizeOfArray(chests); q >= 0; q-- ) {
  234.         if ( cmb == chests[q] ) return true;
  235.     }
  236.     return false;
  237. }
  238.  
  239. ffc script Chest{
  240.     //void run(int contents, int enemy, int open_from_side, int e, int f, int g, int h){
  241.    
  242.    
  243.     void run(int contents_enemy_1, int contents_enemy_2, int contents_enemy_3, int contents_enemy_4,
  244.             int contents_enemy_5, int contents_enemy_6, int contents_enemy_7, int contents_enemy_8){
  245.         int q[256];
  246.         /*
  247.         //  [0] Loop Q
  248.         //  [1] Loop W
  249.         //  [2] Loop E
  250.         //  [3] Temp Chest Contents for Item creation anim and hold-up
  251.             [4] Temp that holds the array index for the 8 sized arrays
  252.             [5] Temp that holds the combo ID for check loops
  253.             [6] Temp combo for adjacentcombo
  254.             [7] [7] Temp for combo position above Link.
  255.             [8] Temp for chest ids when opening chests
  256.             [9] UNUSED
  257.             [10] to [19] UNUSED
  258.             [20] = chest unlocked (ID)
  259.             [21-29] Unused
  260.             [30] pre-animation loop, and then animation timer
  261.             [31-49] Unused
  262.             [50], [51] Callbacks.
  263.            
  264.         */
  265.         int chest_exists[8];
  266.         int chest_pos[8];
  267.         int chest_type[8];
  268.         int chest_layer[8];
  269.         int is_chest[176]; //flag for every combo position. values are 1, 2, and 3, for chests on layers 0, 1, and 2.
  270.            
  271.         int chest_pos_id[176]; //the main combo of each chest group, 0 to 7.
  272.         for ( q[0] = 0; q[0] < 8; q[0]++ ) chest_pos_id[q[0]] = -1; //wipe
  273.        
  274.         for ( q[0] = 0; q[0] < 8; q[0]++ ) chest_layer[q[0]] = -1; //Wipe the array
  275.            
  276.         int pickup_script_args[8]; //fed to the callback
  277.             // [0] None
  278.             // [1] Small, Unlocked
  279.             // [2] Small, Locked
  280.             // [3] Small, Bosslocked
  281.             // [4] Large, Unlocked
  282.             // [5] Large, Locked
  283.             // [6] Large, Bosslocked
  284.         int chest_contents[8]; //negative values are npcs.
  285.        
  286.         //int contents[16];
  287.         //int enemy[16];
  288.         item i; itemdata id;
  289.         //Check which chests EXIST and flag them   
  290.        
  291.            
  292.         //Sotore the positions --combo locations-- of each chest
  293.        
  294.         q[4] = 0; //temp for chest IDs
  295.         for ( q[0] = 0; q[0] < 176; q[0]++ ){
  296.             //Check by layer based on global flags
  297.             if ( CHEST_LAYER_0 ) {
  298.                 q[5] = Screen->ComboD[q[0]]
  299.                 //if it is any type of chest...
  300.                 if ( IsChest(q[5]){
  301.                     chest_exists[ q[4] ] = 1; //Mark that there is a chest
  302.                     chest_pos[ q[4] ] = q[0]; //store the position
  303.                     chest_contents[ q[4] ] = this->InitD[ q[4] ];
  304.                     chest_layer[q[4]] = 0;
  305.                     is_chest[q[0]] = 1;
  306.                     chest_pos_id[q[0]] = q[4];
  307.                     //if it is a small chest
  308.                     if ( IsSmallChest(q[5]){
  309.                         if ( IsUnlockedChest(q[5]){
  310.                             chest_type[q[4]] = 1; //Flag it small unlocked.
  311.                             q[4]++; //increment the temp index.
  312.                             if ( q[4] > 7 ) break;
  313.                             continue;
  314.                         }
  315.                         if ( IsLockedChest(q[5]) ){
  316.                             chest_type[q[4]] = 2; //Flag it small locked.
  317.                             q[4]++; //increment the temp index.
  318.                             if ( q[4] > 7 ) break;
  319.                             continue;
  320.                         }
  321.                         if ( IsBossLockedChest(q[5]) ){
  322.                             chest_type[q[4]] = 3; //Flag it small locked.
  323.                             q[4]++; //increment the temp index.
  324.                             if ( q[4] > 7 ) break;
  325.                             continue;
  326.                         }
  327.                     }
  328.                     if ( IsBigChest(q[5]){
  329.                         if ( IsUnlockedChest(q[5]){
  330.                             chest_type[q[4]] = 4; //Flag it big unlocked.
  331.                             is_chest[q[0]+1] = 1;
  332.                             q[4]++; //increment the temp index.
  333.                            
  334.                             if ( q[4] > 7 ) break;
  335.                             continue;
  336.                         }
  337.                         if ( IsLockedChest(q[5]) ){
  338.                             chest_type[q[4]] = 5; //Flag it big locked.
  339.                             is_chest[q[0]+1] = 1;
  340.                             q[4]++; //increment the temp index.
  341.                            
  342.                             if ( q[4] > 7 ) break;
  343.                             continue;
  344.                         }
  345.                         if ( IsBossLockedChest(q[5]) ){
  346.                             chest_type[q[4]] = 6; //Flag it big locked.
  347.                             is_chest[q[0]+1] = 1;
  348.                             q[4]++; //increment the temp index.
  349.                            
  350.                             if ( q[4] > 7 ) break;
  351.                             continue;
  352.                         }
  353.                     }
  354.                     if ( IsGrandChest(q[5]){
  355.                         if ( IsUnlockedChest(q[5]){
  356.                             chest_type[q[4]] = 7; //Flag it small unlocked.
  357.                             is_chest[q[0]+1] = 1;
  358.                             is_chest[q[0]-15] = 1;
  359.                             is_chest[q[0]-16] = 1;
  360.                             q[4]++; //increment the temp index.
  361.                             if ( q[4] > 7 ) break;
  362.                             continue;
  363.                         }
  364.                         if ( IsLockedChest(q[5]) ){
  365.                             chest_type[q[4]] = 8; //Flag it small locked.
  366.                             is_chest[q[0]+1] = 1;
  367.                             is_chest[q[0]-15] = 1;
  368.                             is_chest[q[0]-16] = 1;
  369.                             q[4]++; //increment the temp index.
  370.                             if ( q[4] > 7 ) break;
  371.                             continue;
  372.                         }
  373.                         if ( IsBossLockedChest(q[5]) ){
  374.                             chest_type[q[4]] = 9; //Flag it small locked.
  375.                             is_chest[q[0]+1] = 1;
  376.                             is_chest[q[0]-15] = 1;
  377.                             is_chest[q[0]-16] = 1;
  378.                             q[4]++; //increment the temp index.
  379.                             if ( q[4] > 7 ) break;
  380.                            
  381.                             continue;
  382.                         }
  383.                     }
  384.                    
  385.                 }
  386.             }
  387.             //layer 1
  388.             if ( CHEST_LAYER_1 ) {
  389.                 q[5] = GetLayerComboD(1,q[0]);
  390.                 //if it is any type of chest...
  391.                 //ignore this pass if this index is already a chest on a lower layer.
  392.                 if ( chest_layer[q[4]] >= 0 ) { continue; }
  393.                
  394.                 if ( IsChest(){
  395.                     chest_exists[ q[4] ] = 1; //mark that there is a chest
  396.                     chest_pos[ q[4] ] = q[0]; //store the position
  397.                     chest_layer[q[4]] = 1;
  398.                     is_chest[q[0]] = 2;
  399.                     //if it is a small chest
  400.                     if ( IsSmallChest(q[5]){
  401.                         if ( IsUnlockedChest(q[5]){
  402.                             chest_type[q[4]] = 1; //Flag it small unlocked.
  403.                             q[4]++; //increment the temp index.
  404.                             if ( q[4] > 7 ) break;
  405.                             continue;
  406.                         }
  407.                         if ( IsLockedChest(q[5]) ){
  408.                             chest_type[q[4]] = 2; //Flag it small locked.
  409.                             q[4]++; //increment the temp index.
  410.                             if ( q[4] > 7 ) break;
  411.                             continue;
  412.                         }
  413.                         if ( IsBossLockedChest(q[5]) ){
  414.                             chest_type[q[4]] = 3; //Flag it small locked.
  415.                             q[4]++; //increment the temp index.
  416.                             if ( q[4] > 7 ) break;
  417.                             continue;
  418.                         }
  419.                     }
  420.                     if ( IsBigChest(q[5]){
  421.                         if ( IsUnlockedChest(q[5]){
  422.                             chest_type[q[4]] = 4; //Flag it big unlocked.
  423.                             is_chest[q[0]+1] = 2;
  424.                             q[4]++; //increment the temp index.
  425.                             if ( q[4] > 7 ) break;
  426.                             continue;
  427.                         }
  428.                         if ( IsLockedChest(q[5]) ){
  429.                             chest_type[q[4]] = 5; //Flag it big locked.
  430.                             is_chest[q[0]+1] = 2;
  431.                             q[4]++; //increment the temp index.
  432.                             if ( q[4] > 7 ) break;
  433.                             continue;
  434.                         }
  435.                         if ( IsBossLockedChest(q[5]) ){
  436.                             chest_type[q[4]] = 6; //Flag it big locked.
  437.                             is_chest[q[0]+1] = 2;
  438.                             q[4]++; //increment the temp index.
  439.                             if ( q[4] > 7 ) break;
  440.                             continue;
  441.                         }
  442.                     }
  443.                     if ( IsGrandChest(q[5]){
  444.                         if ( IsUnlockedChest(q[5]){
  445.                             chest_type[q[4]] = 7; //Flag it small unlocked.
  446.                             is_chest[q[0]+1] = 2;
  447.                             is_chest[q[0]-15] = 2;
  448.                             is_chest[q[0]-16] = 2;
  449.                             q[4]++; //increment the temp index.
  450.                             if ( q[4] > 7 ) break;
  451.                             continue;
  452.                         }
  453.                         if ( IsLockedChest(q[5]) ){
  454.                             chest_type[q[4]] = 8; //Flag it small locked.
  455.                             is_chest[q[0]+1] = 2;
  456.                             is_chest[q[0]-15] = 2;
  457.                             is_chest[q[0]-16] = 2;
  458.                             q[4]++; //increment the temp index.
  459.                             if ( q[4] > 7 ) break;
  460.                             continue;
  461.                         }
  462.                         if ( IsBossLockedChest(q[5]) ){
  463.                             chest_type[q[4]] = 9; //Flag it small locked.
  464.                             is_chest[q[0]+1] = 2;
  465.                             is_chest[q[0]-15] = 2;
  466.                             is_chest[q[0]-16] = 2;
  467.                             q[4]++; //increment the temp index.
  468.                             if ( q[4] > 7 ) break;
  469.                             continue;
  470.                         }
  471.                     }
  472.                    
  473.                 }
  474.             }
  475.             //lsyer 2
  476.             if ( CHEST_LAYER_2 ) {
  477.                 q[5] = GetLayerComboD(2,q[0]);
  478.                 //if it is any type of chest...
  479.                 if ( chest_layer[q[4]] >= 0 ) { continue; } //ignore chests at this position on lower layers.
  480.                 if ( IsChest(){
  481.                     chest_exists[ q[4] ] = 1; //mark that there is a chest
  482.                     chest_pos[ q[4] ] = q[0]; //store the position
  483.                     chest_layer[q[4]] = 2; //store the layer
  484.                     is_chest[q[0]] = 3;
  485.                     //if it is a small chest
  486.                     if ( IsSmallChest(q[5]){
  487.                         if ( IsUnlockedChest(q[5]){
  488.                             chest_type[q[4]] = 1; //Flag it small unlocked.
  489.                             q[4]++; //increment the temp index.
  490.                             if ( q[4] > 7 ) break;
  491.                             continue;
  492.                         }
  493.                         if ( IsLockedChest(q[5]) ){
  494.                             chest_type[q[4]] = 2; //Flag it small locked.
  495.                             q[4]++; //increment the temp index.
  496.                             if ( q[4] > 7 ) break;
  497.                             continue;
  498.                         }
  499.                         if ( IsBossLockedChest(q[5]) ){
  500.                             chest_type[q[4]] = 3; //Flag it small locked.
  501.                             q[4]++; //increment the temp index.
  502.                             if ( q[4] > 7 ) break;
  503.                             continue;
  504.                         }
  505.                     }
  506.                     if ( IsBigChest(q[5]){
  507.                         if ( IsUnlockedChest(q[5]){
  508.                             chest_type[q[4]] = 4; //Flag it big unlocked.
  509.                             is_chest[q[0]+1] = 3;
  510.                             q[4]++; //increment the temp index.
  511.                             if ( q[4] > 7 ) break;
  512.                             continue;
  513.                         }
  514.                         if ( IsLockedChest(q[5]) ){
  515.                             chest_type[q[4]] = 5; //Flag it big locked.
  516.                             is_chest[q[0]+1] = 3;
  517.                             q[4]++; //increment the temp index.
  518.                             if ( q[4] > 7 ) break;
  519.                             continue;
  520.                         }
  521.                         if ( IsBossLockedChest(q[5]) ){
  522.                             chest_type[q[4]] = 6; //Flag it big locked.
  523.                             is_chest[q[0]+1] = 3;
  524.                             q[4]++; //increment the temp index.
  525.                             if ( q[4] > 7 ) break;
  526.                             continue;
  527.                         }
  528.                     }
  529.                     if ( IsGrandChest(q[5]){
  530.                         if ( IsUnlockedChest(q[5]){
  531.                             chest_type[q[4]] = 7; //Flag it small unlocked.
  532.                             is_chest[q[0]+1] = 3;
  533.                             is_chest[q[0]-15] = 3;
  534.                             is_chest[q[0]-16] = 3;
  535.                             q[4]++; //increment the temp index.
  536.                             if ( q[4] > 7 ) break;
  537.                             continue;
  538.                         }
  539.                         if ( IsLockedChest(q[5]) ){
  540.                             chest_type[q[4]] = 8; //Flag it small locked.
  541.                             is_chest[q[0]+1] = 3;
  542.                             is_chest[q[0]-15] = 3;
  543.                             is_chest[q[0]-16] = 3;
  544.                             q[4]++; //increment the temp index.
  545.                             if ( q[4] > 7 ) break;
  546.                             continue;
  547.                         }
  548.                         if ( IsBossLockedChest(q[5]) ){
  549.                             chest_type[q[4]] = 9; //Flag it small locked.
  550.                             is_chest[q[0]+1] = 3;
  551.                             is_chest[q[0]-15] = 3;
  552.                             is_chest[q[0]-16] = 3;
  553.                             q[4]++; //increment the temp index.
  554.                             if ( q[4] > 7 ) break;
  555.                             continue;
  556.                         }
  557.                     }
  558.                    
  559.                 }
  560.             }
  561.         } //End set-up for loop on all layers
  562.                
  563.        
  564.  
  565.        
  566.         //Check which have been opened by reading the bits, and advance their combos on screen init.
  567.         /*
  568.        
  569.         NOW
  570.        
  571.         We know what chests exist, their contents, type, and location.
  572.        
  573.         int chest_exists[8];
  574.         int chest_pos[8];
  575.         int chest_type[8];
  576.             int pickup_script_args[8]; //fed to the callback
  577.             // [0] None
  578.             // [1] Small, Unlocked
  579.             // [2] Small, Locked
  580.             // [3] Small, Bosslocked
  581.             // [4] Large, Unlocked
  582.             // [5] Large, Locked
  583.             // [6] Large, Bosslocked
  584.         int chest_contents[8]; //negative values are npcs.
  585.         chest_layer[8];
  586.         /*
  587.        
  588.         Check which have been opened, and change them on screen init.
  589.        
  590.         */
  591.        
  592.         for ( q[0] = 0; q[0] < 8; q[0]++ ) {
  593.             if ( ChestOpened(q[0] ) {
  594.                 if ( chest_type[q[0]] < CHEST_TYPE_BIG ) {
  595.                     //it is a small chest
  596.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]], (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  597.                     //Update its combo.
  598.                 }
  599.                 if ( chest_type[q[0]] > CHEST_TYPE_SMALL_BOSSLOCKED && chest_type[q[0]] < CHEST_TYPE_GRAND ){
  600.                     //it is a big chest, 1x2\
  601.                     //update the chest and the combo to its right
  602.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]], (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  603.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]]+1, (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  604.                 }
  605.                 if ( chest_type[q[0]] > CHEST_TYPE_BIG_BOSSLOCKED ) {
  606.                     //it is a grand, 4x4 chest.
  607.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]], (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  608.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]]+1, (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  609.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]]-15, (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  610.                     SetLayerComboD( chest_layer[q[0]], chest_pos[q[0]]-16, (GetLayerComboD(chest_layer[q[0]], chest_pos[q[0]])+1) );
  611.                
  612.                     //Update its combo, all four positions
  613.                 }
  614.             }
  615.         } // END Screen Load Set-Up
  616.                
  617.            
  618.         //Now we run the code.
  619.         while(true){
  620.             if ( Link->Dir == DIR_UP ) {
  621.                
  622.                 /*
  623.                 int chest_exists[8];
  624.                 int chest_pos[8];
  625.                 int chest_type[8];
  626.                 int chest_layer[8];
  627.                 int is_chest[176]; //flag for every combo position. values are 1, 2, and 3, for chests on layers 0, 1, and 2.
  628.                    
  629.                 int chest_pos_id[176]; //the main combo of each chest group, 0 to 7.
  630.                 */
  631.                
  632.                 q[7] = ___AdjacentCombo(ComboAt(Link->X+8, Link->Y+8),Link->Dir) ]; //the screen position above Link.
  633.                
  634.                 q[6] = is_chest[ q[7] ]; //the chest type, if any. The layer is q[6]-1
  635.                
  636.                 if ( !q[6] ) { continue; } //if the combo is not a chest, go again.
  637.                
  638.                 q[8] = chest_pos_id[q[7]]; //the ID of the Chest, 0 to 7
  639.                
  640.                 //q[9] = chest_type[ q[8] ]; //the specific chest type.
  641.                 //q[10] = chest_layer[ q[8] ]; //the layer for this chest.
  642.                
  643.                
  644.        
  645.                 //chest_pos_id[combo_loc] holds the ID of chest_pos[n] (0 to 7)
  646.                 //if it is on layer 0
  647.                
  648.                 //align the combo index and the Nth index of the multiple size 8 arrays.
  649.                
  650.                 //q[6] is the combo position 0-176
  651.                 //chest_pos_id[] holds the relative IDs
  652.                
  653.                 //! No, this is not fetching the correct value. is_chest[] holds the chest type per combo location?
  654.                
  655.                 //we need the combo ID and the chest ID pair
  656.                
  657.                
  658.                
  659.                 if ( PressChestCutton() ) {
  660.                     //check to see if it is locked
  661.                     if ( IsLockedChest(q[8]) }{
  662.                         if ( Game->LKeys[Game->GetCurLevel()] > 0 ) {
  663.                         //Game->DCounter[CR_LKEYS] = -1;
  664.                             if ( SFX_CHEST_UNLOCK > 0 ) Game->PlaySound(SFX_CHEST_UNLOCK);
  665.                            
  666.                             //! Send message to pickup script to remove a level key.
  667.                            
  668.                             //open the chest.
  669.                             if ( chest_contents[q[8]] < 0 ) {
  670.                                 //it is an enemy, so
  671.                                 do_open_enemy_chest(q[8], chest_layer[ q[8] ], chest_type[ q[8] ], ( chest_contents[ q[8] ] * -1), false, true, false);
  672.                
  673.                             }
  674.                             else do_chest_open( q[7], chest_layer[ q[8] ], chest_type[ q[8] ], chest_contents[ q[8] ],
  675.                                 false, true, false, q, q[8], CHEST_HOLDUP_TYPE);
  676.                                
  677.                            
  678.                         }
  679.                         else if ( Game->Counter[CR_KEYS] > 0 ) {
  680.                             //Game->DCounter[CR_KEYS] = -1;
  681.                             if ( SFX_CHEST_UNLOCK > 0 ) Game->PlaySound(SFX_CHEST_UNLOCK);
  682.                             //!! Can LINK WASTE A KEY by saving here?
  683.                            
  684.                             //! Send a message to the pickup script to remove a key.
  685.                             //open the chest.
  686.                             if ( chest_contents[q[8]] < 0 ) {
  687.                                 //it is an enemy, so
  688.                                 do_open_enemy_chest(q[8], chest_layer[ q[8] ], chest_type[ q[8] ], ( chest_contents[ q[8] ] * -1), true, false, false);
  689.                
  690.                             }
  691.                             else do_chest_open( q[7], chest_layer[ q[8] ], chest_type[ q[8] ], chest_contents[ q[8] ],
  692.                                 true, false, false, q, q[8], CHEST_HOLDUP_TYPE);
  693.                         }
  694.                     }
  695.                     if ( IsBossLockedChest(q[8]) {
  696.                         if ( HasBossKey(Game->GetCurLevel()) ) {
  697.                             if ( chest_contents[q[8]] < 0 ) {
  698.                                 //it is an enemy, so
  699.                                 do_open_enemy_chest(q[8], chest_layer[ q[8] ], chest_type[ q[8] ], ( chest_contents[ q[8] ] * -1), false, false, true);
  700.                
  701.                             }
  702.                             else do_chest_open( q[7], chest_layer[ q[8] ], chest_type[ q[8] ], chest_contents[ q[8] ],
  703.                                 false, false, true, q, q[8], CHEST_HOLDUP_TYPE);
  704.                         }
  705.                     }
  706.                     else {
  707.                         if ( chest_contents[q[8]] < 0 ) {
  708.                             //it is an enemy, so
  709.                             do_open_enemy_chest(q[8], chest_layer[ q[8] ], chest_type[ q[8] ], ( chest_contents[ q[8] ] * -1), false, false, false);
  710.                
  711.                         }
  712.                         else do_chest_open( q[7], chest_layer[ q[8] ], chest_type[ q[8] ], chest_contents[ q[8] ],
  713.                                 false, false, false, q, q[8], CHEST_HOLDUP_TYPE);
  714.                     }
  715.                    
  716.                 }
  717.                    
  718.             }
  719.             Waitframe();
  720.         } //end while loop
  721.        
  722.     } //end run()
  723.     void do_open_chest(int combo_pos, int layer, int chest_type, int contents, bool key, bool level_key, bool boss_key, int q, int chest_bit, int holdup_type){
  724.        
  725.         int key_type;
  726.         if ( key ) key_type = 1;
  727.         if ( level_key ) key_type = 2;
  728.         if ( boss_key ) key_type = 3;
  729.         //Suspend GhostZH
  730.        
  731.        
  732.        
  733.         //Stun all npcs for the duration of the item animation
  734.         for ( q[30] = Screen->NumNPCs(); q[30] > 0; q[30]++ ) {
  735.             npc n = Screen->LoadNPC(q[30]);
  736.             n->Stun = CHEST_ITEM_ANIM_DUR;
  737.         }
  738.        
  739.         //Play the sound
  740.         if ( SFX_CHEST_ITEM_ANIM > 0 ) Game->PlaySound(SFX_CHEST_ITEM_ANIM);
  741.         //do the item animation.
  742.        
  743.         //!! Send all the item script messages
  744.         q[50] = SetCurrentCallBack()
  745.         q[51] = ( StoreCallBack(ptr[]) != 0 );
  746.        
  747.         int messages[7]={contents, chest_bit, key_type, holdup_type, combo_pos, layer, chest_type};
  748.        
  749.         //Make the item
  750.         item i = Screen->CreateItem(contents);
  751.         i->X = Link->X;
  752.         i->Y = Link->Y = CHEST_ITEM_SPAWN_DISTANCE;
  753.        
  754.         //animation
  755.        
  756.         q[30] = CHEST_ITEM_ANIM_DUR;
  757.        
  758.         //Animation.
  759.         while( q[30]-- || i->Y < Link->Y ) {
  760.             i->Y -= CHEST_ITEM_ANIM_MOVE_SPEED;
  761.             WaitNoAction();
  762.         }
  763.        
  764.         //The item collides with Link, and its pick-up script runs.
  765.         //The script reduces key counts, awards the item, and marks the screen flags as needed
  766.         //using a basic messaging system.
  767.        
  768.     }
  769.     void do_open_enemy_chest(int pos, int layer, int type, int enemy, bool key, bool level_key, bool boss_key){
  770.        
  771.         //use the appropriate key.
  772.         //do the delay?
  773.         //spawn the enemy.
  774.     }
  775.        
  776. } //end script
Add Comment
Please, Sign In to add comment