Advertisement
ZoriaRPG

Callback Chests

May 30th, 2017
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.16 KB | None | 0 0
  1. float CallBacks[1024];  //0 is NULL, and the current callback index; the rest are array pointers.
  2.  
  3. item script Pickup_Chest_Callback{
  4.     void run(int message){
  5.         SetScreenDBit(Game->GetCurScreen(), CHEST_REGISTER, bit, true);
  6.        
  7.        
  8.         int ptr = GetCurrentCallBack();
  9.        
  10.         //Callback messages.
  11.         int item_id = ptr[0];
  12.         int bit = ptr[1];
  13.         int sound = ptr[2];
  14.         int holdtype = ptr[3];
  15.        
  16.         if ( sound > 0 ) { Game->PlaySound(sound); }
  17.         if ( message > 0 ) { Screen->Message(sound); }
  18.        
  19.         if ( holdtype ) {
  20.             Link->Action = LA_HOLD1LAND + holdtype - 1;
  21.             Link->HeldItem = item_id;
  22.         }
  23.        
  24.         ClearCallBack(ptr);
  25.         ClearCurrentCallBack();
  26.     }
  27. }
  28.  
  29. //void SetCallBackStart(int index) {
  30.    
  31. //}
  32.  
  33. void ClearCallBacks() {
  34.     int sz = SizeOfArray(CallBacks);
  35.     for ( int q = 0; q < zs; q++ ) {
  36.         CallBacks[q] = -1;
  37.     }
  38. }
  39.  
  40. int GetFreeCallback() {
  41.     for ( int q = 0; q < zs; q++ ) {
  42.         if ( CallBacks[q] == -1 ) return q;
  43.     }
  44.     return 0; //Null Callback ID
  45. }
  46.  
  47. bool SetCurrentCallBack(){
  48.     int cb = GetFreeCallback();
  49.     if (cb) { CallBacks[0] = cb; return true; }
  50.     return false;
  51. }
  52.  
  53. int GetCurrentCallBack(){
  54.     return CallBacks[0];
  55. }
  56.  
  57. bool StoreCallBack(float value){
  58.     int cb = GetFreeCallback();
  59.     if (cb) { CallBacks[cb] = value; return true; }
  60.     return false;
  61. }
  62.  
  63. void ClearCallBack(int value){
  64.      CallBacks[value] = -1;
  65. }
  66.  
  67. bool ClearCurrentCallBack(){
  68.     int cb = CallBacks[0];
  69.     CallBacks[cb] = -1;
  70. }
  71.  
  72. //Screen->D[reg] to use for chest open flagss.
  73. const int CHEST_REGISTER = 5;
  74.  
  75. const int CHEST_ONE     = 00000001b;
  76. const int CHEST_TWO     = 00000010b;
  77. const int CHEST_THREE   = 00000100b;
  78. const int CHEST_FOUR    = 00001000b;
  79. const int CHEST_FIVE    = 00010000b;
  80. const int CHEST_SIX     = 00100000b;
  81. const int CHEST_SEVEN   = 01000000b;
  82. const int CHEST_EIGHT   = 10000000b;
  83.  
  84. //Combos
  85. const int CMB_CHEST_SMALL = 0;
  86. const int CMB_CHEST_SMALL_LOCKED = 0;
  87. const int CMB_CHEST_SMALL_BOSSLOCKED = 0;
  88.  
  89. //Big chests,  1x2 left combo of each
  90. const int CMB_CHEST_BIG = 0;
  91. const int CMB_CHEST_BIG_LOCKED = 0;
  92. const int CMB_CHEST_BIG_BOSSLOCKED = 0;
  93.  
  94. //Big chests, 4x4 combo saize, bottom-left combo.
  95. const int CMB_CHEST_LARGE = 0;
  96. const int CMB_CHEST_LARGE_LOCKED = 0;
  97. const int CMB_CHEST_LARGE_BOSSLOCKED = 0;
  98.  
  99. //const int CHEST_LAYER = 1; //Layer on which chests are placed.
  100.  
  101. //Check for chests on these layers. 0 = No, 1= yes.
  102. const int CHEST_LAYER_ZERO = 1; //Check for chests on layer 0
  103. const int CHEST_LAYER_ONE = 1; //Check for chests on layer 1
  104. const int CHEST_LAYER_TWO = 1; //Check for chests on layer 2
  105.  
  106. const int CHEST_HOLDUP_TYPE = 1; //0 = none, 1 = one hand, 2 = two hands.
  107.  
  108.  
  109.  
  110. ffc script Chest{
  111.     //void run(int contents, int enemy, int open_from_side, int e, int f, int g, int h){
  112.    
  113.    
  114.     void run(int contents_enemy_1, int contents_enemy_2, int contents_enemy_3, int contents_enemy_4,
  115.             int contents_enemy_5, int contents_enemy_6, int contents_enemy_7, int contents_enemy_8){
  116.             int q[256];
  117.             //  [0[ Loop Q
  118.             //  [1] Loop W
  119.             //  [2] Loop E
  120.             //  [3] Temp Chest Contents for Item creation anim and hold-up
  121.             int chest_exists[8];
  122.             int chest_pos[8];
  123.             int chest_type[8];
  124.                 int pickup_script_args[8]; //fed to the callback
  125.                 // [0] None
  126.                 // [1] Small, Unlocked
  127.                 // [2] Small, Locked
  128.                 // [3] Small, Bosslocked
  129.                 // [4] Large, Unlocked
  130.                 // [5] Large, Locked
  131.                 // [6] Large, Bosslocked
  132.             int chest_contents[8]; //negative values are npcs.
  133.            
  134.             int contents[16];
  135.             int enemy[16];
  136.             item i; itemdata id;
  137.             //Check which chests EXIST and flag them   
  138.             for
  139.                
  140.             //Sotore the positions --combo locations-- of each chest
  141.                
  142.             //Check which have been opened by reading the bits, and advance their combos on screen init.
  143.            
  144.             //Then ...
  145.                 //Store the contents into an array.
  146.             for ( q[0] = 0; q[0] < 16; q[0]++ ) {
  147.                 if ( q < 8 ) {
  148.                     if ( contents[q[0]] > 0 ) { contents[q[0]] = GetHighFloat(this->InitD[q[0]]); }
  149.                     if ( contents[q[0]] < 0 ) { enemy[q[0]] = GetHighFloat(this-InitD[q[0]]); }
  150.                 }
  151.                 else {
  152.                     if ( contents[q[0]] > 0 ) { contents[q[0]] = GetHighFloat(this->InitD[q[0]-8]); }
  153.                     if ( contents[q[0]] < 0 ) { enemy[q[0]] = GetHighFloat(this-InitD[q[0]-8]); }
  154.                 }
  155.             }
  156.                
  157.         int flags;
  158.         //Can we use tilewidth and tileheight to set the chest sise, without making this tedious
  159.         ///for the user?
  160.        
  161.        
  162.         //! We can avoid using chest ID and read from top left to bottom right for combos on the screen.
  163.         //! if a combo is a big chest CMB_ then we open those next to it using adjacent combo, to
  164.         //! determine which others are part of it.
  165.        
  166.        
  167.        
  168.        
  169.         if ( draw_over ) //Big Chest
  170.        
  171.         if ( translucent ) ///Can Open from Side
  172.            
  173.         if ( ethereal ) //
  174.            
  175.         if ( stationary ) {
  176.            
  177.         //A.Speed is a specific chest ID on the screen, at this->X and this->Y.
  178.            
  179.         //If we can;t use tile width and height, we can use x speed to set the chest size.
  180.            
  181.        
  182.        
  183.         while(true){
  184.            
  185.            
  186.            
  187.             //Check Link Proximity to Chest Combos
  188.            
  189.            
  190.             //If Link is within range, and presses a button
  191.            
  192.            
  193.                 //If the chest is larger than 1x1, open all related combos.
  194.            
  195.            
  196.                 ///If the chest has an enemy, Spawn it
  197.            
  198.            
  199.                 //If the chest has contents, give them.
  200.            
  201.                 //Make the item
  202.            
  203.                 i = Screen->CreateItem item_id
  204.            
  205.             //Find a free callback ID
  206.            
  207.             //If we find one, store it
  208.            
  209.             //Set the callback value with the pointer for 'pickup_script_args'
  210.            
  211.                 id = Game->LoadItemData item_id
  212.                 id->InitD =
  213.            
  214.                 // We could do it this way, as a callback is safer.
  215.            
  216.                 //Set the itemdata for the chest bit int he pickup script
  217.                 //This tells the pickup script which bit to set on the screen, as D1
  218.                
  219.                 //Otherwise, we just make the igtem and award it.
  220.                 //As long as it does not have IP_PICKUP it should be safe.
  221.            
  222.                 //Freeze Link and move the item down toward him in an animation.
  223.            
  224.                 //If Collision with Link, flag the screen D
  225.            
  226.            
  227.                 //FLag Screen D that this chest was opened.
  228.                
  229.                 //Do a holdup animation.
  230.            
  231.            
  232.                 if CHEST_HOLDUP_TYPE
  233.                     Link->Action = LA_HOLD1LAND + CHEST_HOLDUP_TYPE - 1;
  234.                 Link->HeldItem = q[3];
  235.            
  236.             Waitframe();
  237.            
  238.            
  239.         }
  240.     }
  241.    
  242.    
  243.    
  244.    
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement