Advertisement
ZoriaRPG

ZC Item Rental v0.3.2 (Link Between Worlds)

Nov 19th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.47 KB | None | 0 0
  1. //Item Rental v0.3.2
  2. //Extension to RPG_Itms.zlib for RPG.zh v0.97.3
  3. //This *CAN* be used as a stand-alone header.
  4.  
  5. float TimedItems[512]; //Arbitrary value, at least 256. The standard ZC items are 0 to 255, but it
  6.             //is *technically possible* to exceed that with tricks, so you may use a larger array if needed.
  7.             //The array index saize must be **TWICE** the number of items in a game. The latter half
  8.             //of the array is used to store if a timer is running.
  9.            
  10. const int MAX_INVENTORY_ITEMS = 255; //This is based on an array, so the value is 0 to 255, for the standard 256 items.
  11. const int T_INVENTORY_RUNNING = 256; //The value for a running timer is offset by this many index positions.
  12.  
  13. const int STR_RENTED_ITEM = 0; //The default message to show when renting an item.
  14. const int SFX_RENTED_ITEM = 63; //The default sound to play when renting an item.
  15. const int RENTAL_TIME = 1800; //5 minutes = 5 * 60 (seconds) * 60 (frames)
  16. const int STR_RENTAL_EXPIRED = 1; //The default message to show when a rental expires.
  17. const int SFX_RENTAL_EXPIRED = 64; //The default sound to play when a rental expires.
  18.  
  19. const int DO_NOT_RENT = 2; //If the index of TimedItems[256+it] == 2, do not remove it from inventory, as it's fully owned.
  20. //No, this isn't needed, as if the player fully buys the item, we  need only set TimedItems[it] to 0.
  21.  
  22. //Running the timers...
  23.  
  24. //Call every frame before Waitdraw()
  25. void RunItemTimers(){
  26.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  27.         if ( TimedItems[q+T_INVENTORY_RUNNING] == 1 ) {
  28.             TimedItems[q]--;
  29.         }
  30.     }
  31. }
  32.  
  33. //Pause item timers, until resumed. This is an **IMPORTANT** courtesy function. You want to call this in
  34. //scripts that create lengthy dialogue.
  35. void SuspendItemTimers(){
  36.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  37.         if ( TimedItems[q+T_INVENTORY_RUNNING] == 1 ) {
  38.             TimedItems[q+T_INVENTORY_RUNNING] = 0;
  39.         }
  40.     }
  41. }
  42.  
  43. //This resumes item timers that are suspended.
  44. void ResumeItemTimers(){
  45.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  46.         if ( TimedItems[q+T_INVENTORY_RUNNING] <= 0 ) {
  47.             TimedItems[q+T_INVENTORY_RUNNING] = 1;
  48.         }
  49.     }
  50. }
  51.  
  52. //Removes all rented items if the player dies, and nullifies their timers. Call every frame, after Waitdraw(),
  53. //and **after** any functions that refill HP (e.g. extra lives)
  54. void RemoveItemsOnDeath(){
  55.     if ( Link->HP <= 0 ) {
  56.         for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  57.             if ( TimedItems[q] && Link->Item[q] ) {
  58.                 TimedItems[q] = 0;
  59.                 TimedItems[q+T_INVENTORY_RUNNING] = 0;
  60.                 Link->Item[q] = false;
  61.             }
  62.             //If we want to remove items on death, without a STRICT timer (timer set to -1)
  63.             if ( TimedItems[q] == -1 ) && Link->Item[q] ) {
  64.                 TimedItems[q] = 0;
  65.                 TimedItems[q+T_INVENTORY_RUNNING] = 0;
  66.                 Link->Item[q] = false;
  67.                
  68.             ]
  69.         }
  70.     }
  71. }
  72.  
  73. //Call to arbitrarily remove all rented items at any time, and nullify their timers.
  74. void RemoveRentedItems(){
  75.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  76.         if ( TimedItems[q] && Link->Item[q] ) {
  77.             TimedItems[q] = 0;
  78.             TimedItems[q+T_INVENTORY_RUNNING] = 0;
  79.             Link->Item[q] = false;
  80.         }
  81.     }
  82. }
  83.  
  84. //Rent without a timer, but take away when player dies.
  85. void RentUntilDeath(int itm){
  86.     TimedItems[itm] = -1;
  87.     if ( ! Link->Item[itm] ) {
  88.         Link->Item[itm] = true;
  89.     }
  90. }
  91.  
  92. //Call to arbitrarily remove a specific rented item at any time, and nullify its timer.
  93. void RemoveRentedItem(int it){
  94.     if ( TimedItems[it] && Link->Item[it] ) {
  95.         TimedItems[it] = 0;
  96.         TimedItems[it+T_INVENTORY_RUNNING] = 0;
  97.         Link->Item[it] = false;
  98.     }
  99. }
  100.  
  101.  
  102. //Function to disable items, and handle alerting the player ( RentalTimerExpired().
  103. //Run every frame after RunItemTimers() and before Waitdraw().
  104. //use only one of the two variations of this, not both.
  105.  
  106. //Use this version if you do not want to display a message when a timer expires.
  107. //It will play a sound by default, set by constant SFX_RENTAL_EXPIRED.
  108. //The message, and sound will play only once per frame, even if the player loses more than one item at
  109. //precisely the same moment.
  110. void RentalTimeExpired(){
  111.     bool playedSound = false;
  112.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  113.         if ( TimedItems[q+T_INVENTORY_RUNNING] > 0 && TimedItems[q] < 1 ) {
  114.             if ( Link->Item[q] ){
  115.                 if ( ! playSound ) {
  116.                     playedSound = true;
  117.                     Game->PlaySound(SFX_RENTAL_EXPIRED);
  118.                 }
  119.                 Link->Item[q] = false;
  120.             }
  121.             TimedItems[q] = 0;
  122.             TimedItems[q+T_INVENTORY_RUNNING] = 0;
  123.         }
  124.     }
  125.    
  126. }
  127.  
  128.  
  129. //Use this version if you **DO** want to display a message when a timer expires.
  130. //If you wish to use a default message, set by constant STR_RENTAL_EXPIRED, set arg msg to '0'
  131. //Otherwise, specify a string manually. It will play a sound by default, set by constant SFX_RENTAL_EXPIRED.
  132. //The message, and sound will play only once per frame, even if the player loses more than one item at
  133. //precisely the same moment.
  134. void RentalTimeExpired(int msg){
  135.     bool playedSound = false;
  136.     for ( int q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  137.         if ( TimedItems[q+T_INVENTORY_RUNNING] > 0 && TimedItems[q] < 1 ) {
  138.             if ( Link->Item[q] ){
  139.                 if ( ! playSound ) {
  140.                     playedSound = true;
  141.                     Game->PlaySound(SFX_RENTAL_EXPIRED);
  142.                 }
  143.                 if ( msg ) {
  144.                     Screen->Message(msg); //Play a string with a value greater than 0.
  145.                 }
  146.                 if ( ! msg ) {
  147.                     Screen->Message(STR_RENTAL_EXPIRED); //if you feel lazy, use a constant.
  148.                 }
  149.                 Link->Item[q] = false;
  150.             }
  151.             TimedItems[q] = 0;
  152.             TimedItems[q+T_INVENTORY_RUNNING] = 0;
  153.         }
  154.     }
  155.    
  156. }
  157.  
  158. //Functions to set rental timers.
  159.  
  160.  
  161. //Sets a timer for one item specified by arg it, to the amount of the constant RENTAL_TIME (defaults as 5 mins)
  162.     //and starts timer.
  163. void SetTimedItemTimer(int it){
  164.     TimedItems[it] = RENTAL_TIME;
  165.     TimedItems[it+T_INVENTORY_RUNNING] = 1;
  166. }
  167.  
  168.  
  169. //Timer settings allowing an imput.
  170. //Choose the format for time that you wish to use, enable that function, and disable the others of this type.
  171.  
  172. //Sets a timer for one item specified by arg it for duration specified by arg rentalTime; and starts timer.
  173. //Uses an integer as full minutes for arg rentalTime, so a value of 00010.0000 is ten minutes, *NOT* tem frames.
  174. //This is the default version. A version below allows seconds, and a third uses an absolute value in frames.
  175. //DISABLE THIS if you wish to use seconds, or absolute frames for the rentalTime arg.
  176. void SetTimedItemTimer(int it, int rentalTime){
  177.     if ( rentalTime != -1 ) {
  178.         TimedItems[it] = RentalTime(rentalTime);
  179.     }
  180.     else if ( rentalTime == -1 ) {
  181.         TimedItems[it] = -1;
  182.     }
  183.     if ( rentalTime != -1 ) {
  184.         TimedItems[it+T_INVENTORY_RUNNING] = 1;
  185.     }
  186. }
  187.  
  188.  
  189. //Sets a timer for one item specified by arg it for duration specified by arg rentalTime; and starts timer.
  190. //Uses time as a float, where the ones place (and higher) is minutes, and the THOUSANDTHS place is SECONDS.
  191. //e.g. 00005.0010 is 5 minues 1 (ONE) second. ; 00005.0001 is five minutes, and 1/10 seconds.
  192. //Enable this if you wish to pass rentalTime in this format.
  193. //void SetTimedItemTimer(int it, float rentalTime){
  194. //  if ( rentalTime != -1 ) {
  195. //      TimedItems[it] = RentalTime(rentalTime);
  196. //  }
  197. //  else if ( rentalTime == -1 ) {
  198. //      TimedItems[it] = -1;
  199. //  }
  200. //  if ( rentalTime != -1 ) {
  201. //      TimedItems[it+T_INVENTORY_RUNNING] = 1;
  202. //  }
  203. //}
  204.  
  205. //Sets a timer for one item specified by arg it for duration specified by arg rentalTime; and starts timer.
  206. //Uses time in absolute frames.
  207. //Enable this if you wish to pass rentalTime in this format.
  208. //void SetTimedItemTimer(int it, int rentalTime){
  209. //  TimedItems[it] = rentalTime;
  210. //  if ( rentalTime != -1 ) {
  211. //      TimedItems[it+T_INVENTORY_RUNNING] = 1;
  212. //  }
  213. //}
  214.  
  215.  
  216. //Constants for Gauges
  217. const int RENTAL_GAUGE_A_POS_X = 0;
  218. const int RENTAL_GAUGE_A_POS_Y = 0;
  219. const int RENTAL_GAUGE_B_POS_X = 12;
  220. const int RENTAL_GAUGE_B_POS_Y = 0;
  221. const int RENTAL_GAUGE_WIDTH = 8;
  222. const int GAUGE_A_BUTTON_LENGTH_X = 50;
  223. const int GAUGE_A_BUTTON_LENGTH_Y = 50;
  224. const int GAUGE_A_BUTTON_OFFSET_X = 0;
  225. const int GAUGE_A_BUTTON_OFFSET_Y = 0;
  226. const int GAUGE_B_BUTTON_LENGTH_X = 50;
  227. const int GAUGE_B_BUTTON_LENGTH_Y = 50;
  228. const int GAUGE_B_BUTTON_OFFSET_X = 12;
  229. const int GAUGE_B_BUTTON_OFFSET_Y = 12;
  230. const int RENTAL_GAUGE_LAYER = 7; //Display gauge on layer 7.
  231. const int RENTAL_GAUGE_COLOUR = 10; //Set to colour for gauges.
  232. const int RENTAL_GAUGE_OPACITY = 60;
  233.  
  234.  
  235. ///// ! We need rental gauges that draw in the reverse directions ! Add an arg for right->left & up->Down anor left->right & down->up
  236.  
  237. //Draws rental gauge for item in slot A, if it's rented.
  238. void DrawRentalGaugeA(int posX, int posY, int width, int colour, bool horizontal, bool rlud, bool transparent, int opacity){
  239.     int itemOnA = GetEquipmentA();
  240.     //bool rlud is right to left, up to down
  241.     int remTime = TimedItems[it];
  242.     int barLengthX;
  243.     int barLengthY;
  244.     if ( horizontal ) {
  245.         barLengthX = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  246.         barLengthY = width;
  247.     }
  248.     if ( ! horizontal ) {
  249.         barLengthX = width;
  250.         barLengthY = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  251.     }
  252.     if ( IsRented( itemOnA ) {
  253.         Screen->Rectangle(RENTAL_GAUGE_LAYER, posX, posY, posX+barLengthX, posY+barLengthY, RENTAL_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  254.     }
  255.    
  256. }
  257.  
  258.  
  259. //Draws rental gauge for item in slot B, if it's rented.
  260. void DrawRentalGaugeB(int posX, int posY, int length, int width, int colour, bool horizontal, bool transparent, int opacity){
  261.     int itemOnB = GetEquipmentB();
  262.     int remTime = TimedItems[it];
  263.     int barLengthX;
  264.     int barLengthY;
  265.     if ( horizontal ) {
  266.         barLengthX = ( GAUGE_B_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  267.         barLengthY = width;
  268.     }
  269.     if ( ! horizontal ) {
  270.         barLengthX = width;
  271.         barLengthY = ( GAUGE_B_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  272.     }
  273.     if ( IsRented( itemOnB ) {
  274.         Screen->Rectangle(RENTAL_GAUGE_LAYER, posX, posY, posX+barLengthX, posY+barLengthY, RENTAL_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  275.     }
  276.    
  277. }
  278.  
  279. //Returns the value of an item if it is rented.
  280. int IsRented(int it){
  281.     int itm;
  282.     for ( q = 0; q <= ( SizeOfArray(TimedItems) * 0.5 ) q++ ){
  283.         itm = TimedItems[q];
  284.         if ( it == itm ) return itm;
  285.     }
  286.     return -1;
  287. }
  288.  
  289.  
  290.  
  291. //Returns seconds from decimal portion of float argument. Fineness to 1/10 second.
  292. int RentalSeconds(float seconds){
  293.         int timer_seconds = (seconds - (seconds >> 0)) * 10000;
  294.         return timer_seconds * 6;
  295. }
  296.  
  297. //Returns minutes from integer part of float arg.
  298. int RentalMinutes(float mins){
  299.         int rental_minutes = ( mins >> 0 ) ;
  300.         return rental_minutes * 360;
  301. }
  302.  
  303. //Returns total time in frames, so that ZC understands it.
  304. int RentalTime(float val){
  305.     int mins = RentalMinutes(val);
  306.     int seconds = RentalSeconds(val);
  307.     return mins+seconds;
  308. }
  309.        
  310. // Pick-Up Script for Rented Items with a TIMER
  311. // Arguments:
  312. // D0: The item number of the item given.
  313. // D1: The amount of time that the player should keep the item.
  314.     //If '0', the constant RENTAL_TIME is used as a default.
  315. // D2: A message to display. Must be a string greater than '0'.
  316. // D3: A sound to play.
  317. // D4: Set to a value of '1' to hold the item up with one hand. Set to a value of '2' to hold up with BOTH hands.
  318. item script PickupRentalItem{
  319.     void run(int it, int time, int message, int sound, int holdup){
  320.         if ( message ) {
  321.             Screen->Message(message);
  322.         }
  323.         if ( !message ) {
  324.             Screen->Message(STR_RENTED_ITEM);
  325.         }
  326.         if ( sound ) {
  327.             Game->PlaySound(sound);
  328.         }
  329.         if ( !sound ) {
  330.             Game->PlaySound(SFX_RENTED_ITEM);
  331.         }
  332.         if ( time ) {
  333.             SetTimedItemTimer(it, time);
  334.         }
  335.         if ( !time ) {
  336.             SetTimedItemTimer(it);
  337.         }
  338.         if ( holdup == 1 ) {
  339.             Link->Action = LA_HOLD1LAND;
  340.             Link->HeldItem = it;
  341.         }
  342.         if ( holdup == 2 ) {
  343.             Link->Action = LA_HOLD2LAND;
  344.             Link->HeldItem = it;
  345.         }
  346.     }
  347. }
  348.  
  349.  
  350.  
  351. // Pick-Up Script for Rented Items **WITHOUT** a timer.
  352. // Arguments:
  353. // D0: The item number of the item given.
  354. // D1: A message to display. Must be a string greater than '0'.
  355. // D2: A sound to play.
  356. // D3: Set to a value of '1' to hold the item up with one hand. Set to a value of '2' to hold up with BOTH hands.
  357. item script RentItemUntilDeath{
  358.     void run(int it, int message, int sound, int holdup){
  359.         SetTimedItemTimer(it, -1);
  360.         if ( message ) {
  361.             Screen->Message(message);
  362.         }
  363.         if ( !message ) {
  364.             Screen->Message(STR_RENTED_ITEM);
  365.         }
  366.         if ( sound ) {
  367.             Game->PlaySound(sound);
  368.         }
  369.         if ( !sound ) {
  370.             Game->PlaySound(SFX_RENTED_ITEM);
  371.         }
  372.         if ( holdup == 1 ) {
  373.             Link->Action = LA_HOLD1LAND;
  374.             Link->HeldItem = it;
  375.         }
  376.         if ( holdup == 2 ) {
  377.             Link->Action = LA_HOLD2LAND;
  378.             Link->HeldItem = it;
  379.         }
  380.     }
  381. }
  382.  
  383.  
  384.  
  385. //Attach item script FullyBuyItem (below) to items that you want to allow the player to fully own, ...
  386.     //or call FullyOwnItem() in an item script, or any FFC script to make ownership permanent.
  387.  
  388.  
  389. //Function to own an item specified by arg it: Used if the player *IS* already renting the item.
  390. void FullyOwnItem(int it){
  391.     TimedItems[it] = 0;
  392.     TimedItems[it+T_INVENTORY_RUNNING] = 0;
  393. }
  394.  
  395. //Function to own an item specified by arg it: Used if the player is *NOT* already renting the item.
  396. void FullyOwnItem(int it, bool give){
  397.     TimedItems[it] = 0;
  398.     TimedItems[it+T_INVENTORY_RUNNING] = 0;
  399.     if ( give && !Link->Item[it] ) {
  400.         Link->Item[it] = true;
  401.     }
  402. }
  403.  
  404. //Pick-Up script to own an item specified by arg D0.
  405. item script FullyBuyItem {
  406.     void run(int it){
  407.         FullyOwnItem(it);
  408.     }
  409. }
  410.  
  411. //An example global active script for rented items.
  412. global script activeExample {
  413.     void run(){
  414.         while(true){
  415.             RunItemTimers();
  416.             RentalTimeExpired();
  417.             DrawRentalGaugeA(RENTAL_GAUGE_A_POS_X, RENTALY_GAUGE_A_POS_X, RENTAL_GAUGE_WIDTH, RENTAL_GAUGE_COLOUR, false, true, RENTAL_GAUGE_OPACITY);
  418.             DrawRentalGaugeB(RENTAL_GAUGE_B_POS_X, RENTALY_GAUGE_B_POS_X, RENTAL_GAUGE_WIDTH, RENTAL_GAUGE_COLOUR, false, true, RENTAL_GAUGE_OPACITY);
  419.             Waitdraw();
  420.             RemoveItemsOnDeath();
  421.             Waitframe();
  422.            
  423.         }
  424.     }
  425. }
  426.  
  427.  
  428.  
  429. //Charged Items
  430. //This replicates the Link Between Worlds method of item ammunition (charge gauge).
  431.  
  432.  
  433. //Base constants.
  434. const int CHARGE_GAUGE = 0; //Index position of array index to store value of charge gauge.
  435. const int MAX_CHARGE_AMOUNT = 60; //The total fill of the gauge (its length, in pixels)
  436. const int CHARGE_REFILL_RATE = 1; //pixels per second.
  437.  
  438. //Constants for charge gauges.
  439. const int CHARGE_GAUGE_X = 0;
  440. const int CHARGE_GAUGE_Y = 8;
  441. const int CHARGE_GAUGE_WIDTH = 8;
  442. const int CHARGE_GAUGE_HEIGHT = 8;
  443. const int CHARGE_GAUGE_COLOUR = 16;
  444. const int CHARGE_GAUGE_OPACITY = 50;
  445. const int CHARGE_GAUGE_LAYER = 7;
  446.  
  447. //Reduce charge gauge by an arbitrary amount.
  448. void ReduceChargeGauge(int amount){
  449.     ChargeItems[CHARGE_GAUGE] -= amount;
  450. }
  451.  
  452. //Refills the charge gauge. Call this every frame.
  453. void RefillChargeGauge(){
  454.     if ( ChargeItems[CHARGE_GAUGE] != MAX_CHARGE_AMOUNT ) {
  455.         ChargeItems[CHARGE_GAUGE] += ( CHARGE_REFILL_RATE / 60 );
  456.     }
  457. }
  458.  
  459. //Array to store charged item values.
  460. //This is a float, so that we may refill it (decimal places) every frame.
  461. float ChargeItems[]={  0,   I_BOMB,     CR_BOMBS,
  462.                 I_ARROW1,   CR_ARROWS,
  463.                 I_ARROW2,   CR_ARROWS,
  464.                 I_ARROW3,   CR_ARROWS,
  465.                 I_SBOMB,    CR_SBOMBS,
  466.                 I_ROCSFEATHER,  CR_SCRIPT25 };
  467.     //Format: Duration of gauge (index 0), Item constant (1) , item counter constant (2), item 2 constant (3), item counter 2 constant (4), .
  468.    
  469.  
  470.    
  471. //Replenishes ammo for items when gauge is full:
  472. //Accepts an array inout as list[]
  473. void ChargeGauge(int list){
  474.     for ( int q = 1; q <= SizeOfArray(list); q += 2 ) {
  475.         if ( list[CHARGE_GAUGE] > 0 ) {
  476.             if ( list[q] && list[q+1] ) { //If the value stored in the index is not zero...
  477.                 if ( Link->Item[q] ) {
  478.                     if ( Game->MCounter[q+1] != 100 ) {
  479.                         Game->MCounter[q+1] = 100;
  480.                     }
  481.                     if ( Game->Counter[q+1] != 100 ) {
  482.                         Game->Counter[q+1] = 100;
  483.                     }
  484.                 }
  485.             }
  486.         }
  487.     }
  488. }
  489.  
  490. global script active_charges{
  491.     void run(){
  492.         while(true){
  493.             DisplayChargeGauge(CHARGE_GAUGE_X, CHARGE_GAUGE_Y, CHARGE_GAUGE_WIDTH, CHARGE_GAUGE_COLOUR, true, true, 65);
  494.             Waitdraw();
  495.             Waitframe();
  496.         }
  497.     }
  498. }
  499.  
  500.  
  501.  
  502. //Returns the remaining amount in the charge gauge this frame. (Updates the drawing of gauges). Do not call directly in active script.
  503.     //This is called by the functions that draw the gauges.
  504. int RemCharge(){
  505.     return ChargeGauge[CHARGE_GAUGE];
  506. }
  507.  
  508. //A function to reduce the charge gauge at any time, by an arbitrary amount.
  509. void ReduceCharges(float amount){
  510.     ChargeItems[CHARGE_GAUGE] -= amount;
  511. }
  512.  
  513. //Display the charge gauge on the screen. Call every frame before Waitdraw().
  514. void DisplayChargeGauge(int posX, int posY, int width, int colour, bool horizontal, bool transparent, int opacity){
  515.     int remTime = RemCharge();
  516.     int barLengthX;
  517.     int barLengthY;
  518.     if ( horizontal ) {
  519.         barLengthX = ( MAX_CHARGE_AMOUNT / 100 ) * ( remTime / 360 );
  520.         barLengthY = width;
  521.     }
  522.     if ( ! horizontal ) {
  523.         barLengthX = width;
  524.         barLengthY = ( MAX_CHARGE_AMOUNT / 100 ) * ( remTime / 360 );
  525.     }
  526.     Screen->Rectangle(RENTAL_GAUGE_LAYER, posX, posY, posX+barLengthX, posY+barLengthY, RENTAL_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  527.    
  528. }
  529.  
  530.  
  531. //Item script to add to any item, to reduce the charge gauge. Normally used instead of ammunition.
  532. //This lowers the charge gauge every time a player uses an item.
  533. //Allows fractional amounts.
  534. item script ReduceCharges{
  535.     void run(float chargeCost){
  536.         ReduceCharges(chargeCost);
  537.     }
  538. }
  539.  
  540. //Item to refill charge gauge. Set D0 to the amount that the item should replenish, or set to '0' if 100%.
  541. item script ChargeGaugeRefill{
  542.     void run(int amount) {
  543.         if ( amount ) {
  544.             ChargeItems[CHARGE_GAUGE] += amount;
  545.         }
  546.         else {
  547.             ChargeItems[CHARGE_GAUGE] = MAX_CHARGE_AMOUNT;
  548.         }
  549.     }
  550. }
  551.  
  552.  
  553. //Deprecated Functions
  554.  
  555. //Display the charge gauge on the screen. Call every frame before Waitdraw().
  556. void _DisplayChargeGauge(int posX, int posY, int length, int width, int colour, bool horizontal, bool transparent, int opacity){
  557.     Screen->Rectangle(CHARGE_GAUGE_LAYER, posX, posY, posX+length, posY+width, CHARGE_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  558. }
  559.  
  560. //The following two functions likely have no useful purpose, unless this header is expanded to give two
  561. //separate charge values for A and B slots, although doing that would only invite cheating. .
  562.  
  563. //Draws item charge gauge for item in slot A.
  564. void DrawItemGaugeA(int posX, int posY, int length, int width, int colour, bool horizontal, bool transparent, int opacity){
  565.     int itemOnA = GetEquipmentA();
  566.     int remTime = RemCharge();
  567.     int barLengthX;
  568.     int barLengthY;
  569.     if ( horizontal ) {
  570.         barLengthX = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  571.         barLengthY = width;
  572.     }
  573.     if ( ! horizontal ) {
  574.         barLengthX = width;
  575.         barLengthY = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  576.     }
  577.     Screen->Rectangle(RENTAL_GAUGE_LAYER, posX, posY, posX+barLengthX, posY+barLengthY, RENTAL_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  578.    
  579. }
  580.  
  581. //Draws item charge gauge for item in slot B.
  582. void DrawItemGaugeB(int posX, int posY, int length, int width, int colour, bool horizontal, bool transparent, int opacity){
  583.     int itemOnB = GetEquipmentB();
  584.     int remTime = RemCharge();
  585.     int barLengthX;
  586.     int barLengthY;
  587.     if ( horizontal ) {
  588.         barLengthX = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  589.         barLengthY = width;
  590.     }
  591.     if ( ! horizontal ) {
  592.         barLengthX = width;
  593.         barLengthY = ( GAUGE_A_BUTTON_LENGTH_X / 100 ) * ( remTime / 360 );
  594.     }
  595.     Screen->Rectangle(RENTAL_GAUGE_LAYER, posX, posY, posX+barLengthX, posY+barLengthY, RENTAL_GAUGE_COLOUR, 1, 0, 0, 0, transparent, opacity);
  596.    
  597. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement