Advertisement
ZoriaRPG

ZC Heart Jar and Magic Jar (Useless Drop Collection)

Nov 15th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.20 KB | None | 0 0
  1. /// Heart and Magic Storage Jars
  2. /// Collects 'useless' Drops for later use.
  3. /// By: ZoriaRPG for IotM No.2
  4. /// v0.3
  5. /// 10th February, 2016
  6. ///
  7.  
  8. /// Global Arrays
  9. float ReserveCounters[256]={0,0,0,MAX_HEART_JAR_HEARTS_STORED, MAX_MAGIC_JAR_MAGIC_STORED}; //Holds values of dropped items that can't be used when the player picks them up.
  10. int OwnsItems[512];  //Stores what items the player actually owns.
  11.  
  12. //Array indices.
  13. const int RESERVE_HEARTS        = 1;
  14. const int RESERVE_MAGIC         = 2;
  15. const int HEART_JAR_MAX_HEARTS  = 3;
  16. const int MAGIC_JAR_MAX_MAGIC   = 4;
  17.  
  18. //item constants.
  19. const int I_HEARTJAR = 100; //The item ID for the Heart Jar.
  20. const int I_MAGICJAR = 101; //The item ID for the Magic Jar
  21.  
  22. //Initial caps. These can be changed as constants, or set with functions at any time (to allow upgrades).
  23. const int MAX_HEART_JAR_HEARTS_STORED = 32;
  24. const int MAX_MAGIC_JAR_MAGIC_STORED = 1024;
  25.  
  26. //Debug values
  27. const int DEBUG_ON_HEART_MAGIC_JARS             = 1; //Is debug enabled in general?
  28. const int DEBUG_TRACE_HEART_JAR_HEARTS          = 1; //indidual debug types.
  29. const int DEBUG_TRACE_HEART_JAR_HEARTS_CAP      = 1;
  30. const int DEBUG_TRACE_MAGIC_JAR_MAGIC           = 1;
  31. const int DEBUG_TRACE_MAGIC_JAR_MAGIC_CAP       = 1;
  32. const int DEBUG_TRACE_OWNERSHIP_HEART_JAR       = 1;
  33. const int DEBUG_TRACE_OWNERSHIP_MAGIC_JAR       = 1;
  34. const int DEBUG_TRACE_HEART_PICKUP_JAR_VALUE    = 1;
  35. const int DEBUG_TRACE_MAGICPICKUP_JAR_VALUE     = 1;
  36.  
  37. //use with if ( Link->PressEx3 && DEBUG_VALUE ) Trace().this
  38.  
  39. Debugjarvalues(){
  40.     int str[]="Present Heart jar Value is: "
  41.     int str2[]="Present Magic jar value is: "
  42.     TraceNL();  TraceS(str);    Trace(ReserveCounters[RESERVE_HEARTS]);
  43.     TraceNL();  TraceS(str);    Trace(ReserveCounters[RESERVE_MAGIC]);
  44. }
  45.  
  46. global script debug{
  47.     void run(){
  48.         while(true){
  49.             if ( Link->PressEx3 ) Debugjarvalues();
  50.             Waitdraw();
  51.             Waitframe();
  52.         }
  53.     }
  54. }
  55.  
  56.  
  57. //Assign as the pick-up script on all heart items.
  58. //D0: Number of hearts to give when Link picks it up.
  59. //D1 Divisor, for how many hearts it will store in the heart jar.
  60. item script heartdrop{
  61.     void run(int numhearts, int divisor){
  62.         if ( Link->HP == Link->MaxHP && OwnsItems[I_HEARTJAR] ) {
  63.             if ( ( ReserveCounters[RESERVE_HEARTS] + ( numhearts / divisor ) ) < ReserveCounters[HEART_JAR_MAX_HEARTS] )
  64.                 {
  65.                     ReserveCounters[RESERVE_HEARTS] += numhearts / divisor;
  66.                     if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  67.                         int str[]="On heart pickup, the amount of hearts added to the heart jar was: ";
  68.                         TraceNL();  TraceS(str); Trace(numhearts/divisor);
  69.                     }
  70.                 }
  71.             if ( (ReserveCounters[RESERVE_HEARTS] < ReserveCounters[HEART_JAR_MAX_HEARTS] ) && ( ReserveCounters[RESERVE_HEARTS] + (numhearts / divisor) > ReserveCounters[HEART_JAR_MAX_HEARTS] ) )
  72.                 ReserveCounters[RESERVE_HEARTS]  = ReserveCounters[HEART_JAR_MAX_HEARTS];
  73.         }
  74.     }
  75. }
  76.  
  77.  
  78. //Assign as the pick-up script on all magic drop items.
  79. //D0: Amount of magic to give when Link picks it up.
  80. //D1 Divisor, for how many magic points it will store in the magic jar.
  81. item script magicdrop{
  82.     void run(int num_mp, int divisor){
  83.     if ( Link->MP == Link->MaxMp && OwnsItems[I_MAGICJAR] ) {
  84.             if ( ( ReserveCounters[RESERVE_MAGIC] + ( num_mp / divisor ) ) < ReserveCounters[MAGIC_JAR_MAX_MAGIC] )
  85.                 {
  86.                     ReserveCounters[RESERVE_MAGIC] += num_mp / divisor;
  87.                     if ( if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  88.                         int str[]="On magic pickup, the amount of magic added to the heart jar was: ";
  89.                         TraceNL();  TraceS(str); Trace(num_mp/divisor);
  90.                     }
  91.                 }
  92.             if ( (ReserveCounters[RESERVE_MAGIC] < ReserveCounters[MAGIC_JAR_MAX_MAGIC] ) && ( ReserveCounters[RESERVE_MAGIC] + (num_mp / divisor) > ReserveCounters[MAGIC_JAR_MAX_MAGIC] ) )
  93.                 ReserveCounters[RESERVE_MAGIC]  = ReserveCounters[MAGIC_JAR_MAX_MAGIC];
  94.         }
  95.     }
  96. }
  97.    
  98.  
  99. //Assign as pickup script for heart jar item.
  100. item script HeartJarPickup{
  101.     void run(int msg, int sfx, imt errsfx, int cap){
  102.         if ( msg ) Screen->message(msg);
  103.         OwnsItems[I_HEARTJAR] = 1;
  104.         if ( cap ) SetHeartJarCap(cap);
  105.     }
  106. }
  107.  
  108.  
  109. //Assign as pickup script for magic jar item.
  110. item script MagicJarPickup{
  111.     void run(int msg, int sfx, imt errsfx, int cap){
  112.         if ( msg ) Screen->message(msg);
  113.         OwnsItems[I_MAGICJAR] = 1;
  114.         if ( cap ) SetMagicJarCap(cap);
  115.     }
  116. }
  117.  
  118.  
  119. //Assign as running script for Heart Jar.
  120. item script heartjar{
  121.     void run(int msg, int sfx, imt errsfx){
  122.         if ( Link->HP < Link->MaxHP ) {
  123.             if ( ReserveCounters[RESERVE_HEARTS] > ( Ceiling((Link->MaxHP - Link->HP) / 16) ) ) {
  124.                 if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  125.                         int str[]="The value of 'Ceiling((Link->MaxHP - Link->HP) / 16)' is: ";
  126.                         TraceNL();  TraceS(str); Trace( Ceiling((Link->MaxHP - Link->HP) / 16) );
  127.                 }
  128.                 ReserveCounters[RESERVE_HEARTS] -= ( Ceiling((Link->MaxHP - Link->HP) / 16) );
  129.                 Link->HP = Link->MaxHP;
  130.                 Game->PlaySound(sfx);
  131.             }
  132.             if ( ReserveCounters[RESERVE_HEARTS] < ( Ceiling((Link->MaxHP - Link->HP) / 16) ) && ReserveCounters[RESERVE_HEARTS] ){
  133.                
  134.                 if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  135.                     int str[]="Used the heart jar when Link's HP was lower than the number of hearts in the jar.";
  136.                     int str2[]="The amount of health restored, was: ";
  137.                     TraceNL();  TraceS(str); TraceNL(); TraceS(str2); Trace( ReserveCounters[RESERVE_HEARTS] * 16 );
  138.                 }
  139.                 Link->HP += ReserveCounters[RESERVE_HEARTS] * 16;
  140.                 ReserveCounters[RESERVE_HEARTS] = 0; //Clear the reserve.
  141.                 Game->PlaySound(sfx);
  142.             }
  143.             if ( !(ReserveCounters[RESERVE_HEARTS]) ) Game->PlaySound(errsrfx);
  144.         }
  145.         else game->PlaySound(errsfx);
  146.     }
  147. }
  148.            
  149.                
  150.  
  151. //Assign as running script for Magic Jar.
  152. item script magicjar{
  153.     void run(int msg, int sfx, imt errsfx){
  154.         if ( Link->MP < Link->MaxMP ) {
  155.             if ( ReserveCounters[RESERVE_MAGIC] > ( Ceiling((Link->MaxMP - Link->MP) / 32) ) ) {
  156.                 if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  157.                         int str[]="The value of 'Ceiling((Link->MaxMP - Link->MP) / 32)' is: ";
  158.                         TraceNL();  TraceS(str); Trace( Ceiling((Link->MaxMP - Link->MP) / 32) );
  159.                 }
  160.                 ReserveCounters[RESERVE_MAGIC] -= ( Ceiling((Link->MaxMP - Link->MP) / 32) );
  161.                 Link->MP = Link->MaxMP;
  162.                 Game->PlaySound(sfx);
  163.             }
  164.             if ( ReserveCounters[RESERVE_MAGIC] < ( Ceiling((Link->MaxMP - Link->MP) / 32) ) && ReserveCounters[RESERVE_MAGIC] ){
  165.                 if ( DEBUG_ON_HEART_MAGIC_JARS ) {
  166.                     int str[]="Used the magic jar when Link's MP was lower than the number of magic in the jar.";
  167.                     int str2[]="The amount of magic restored, was: ";
  168.                     TraceNL();  TraceS(str); TraceNL(); TraceS(str2); Trace( ReserveCounters[RESERVE_MAGIC] * 32 );
  169.                 }
  170.                
  171.                 Link->MP += ReserveCounters[RESERVE_MAGIC] * 32;
  172.                 ReserveCounters[RESERVE_MAGIC] = 0;
  173.                 Game->PlaySound(sfx);
  174.             }
  175.             if ( !(ReserveCounters[RESERVE_MAGIC]) ) Game->PlaySound(errsrfx);
  176.         }
  177.         else game->PlaySound(errsfx);
  178.     }
  179. }
  180.            
  181.  
  182. //Global Accessor Functions
  183. void SetHeartJarCap(int cap){
  184.     ReserveCounters[HEART_JAR_MAX_HEARTS] = cap;
  185. }
  186.  
  187. void SetMagicJarCap(int cap){
  188.     ReserveCounters[MAGIC_JAR_MAX_MAGIC] = cap;
  189. }
  190.  
  191.  
  192. //! Deprecated (already!?)
  193. //These are pointless. Just call the setters above for inits.
  194. void InitMagicJarCap(int cap){
  195.     ReserveCounters[MAGIC_JAR_MAX_MAGIC] = cap;
  196. }
  197.  
  198. void InitHeartJarCap(int cap) {
  199.     ReserveCounters[HEART_JAR_MAX_HEARTS] = cap;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement