Advertisement
ZoriaRPG

RPG_XP_New.zlib

Jul 26th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.92 KB | None | 0 0
  1. //RPG Macros
  2.  
  3.  
  4. const int LM_XP = 31; //Index of Link->Misc to use for drawing xP
  5. // Xp arard.timer
  6.  
  7. const float XP_DRAW_TIME =  0.10; //frames
  8. const int XP_DRAW_COLOUR_FG = 0x02;
  9. const int XP_DRAW_COLOUR_BG = 0x0F; //shadow
  10. const int XP_DRAW_XOFS = 18;  //from Link
  11. const int XP_DRAW_YOFS = -8; const int XP_DRAW_XOFS = 18;  //from Link
  12. const int XP_DRAW_SHADOW_XOFS = -1;
  13. const int XP_DRAW_SHADOW_YOFS = -1;
  14. const int XP_DRAW_FONT = 0;
  15.  
  16. const int XP_LEVEL_NEXT = 5002; //holds value of next needed XP
  17.  
  18. const int G_XP_DRAW_TIMER = 5001;
  19. const int G_XP_DLAST_AWARD = 5000;
  20.  
  21. const float RPG_LEVEL_01 = 0.0050;
  22. const float RPG_LEVEL_02 = 0.0100;
  23. const float RPG_LEVEL_03 = 0.0200;
  24. const float RPG_LEVEL_04 = 0.0500;
  25. const float RPG_LEVEL_05 = 0.1000;
  26. const float RPG_LEVEL_06 = 0.2000;
  27. const float RPG_LEVEL_07 = 0.5000;
  28. const float RPG_LEVEL_08 = 1.0000;
  29. const float RPG_LEVEL_09 = 2.0000;
  30. const float RPG_LEVEL_10 = 5.0000;
  31. const float RPG_LEVEL_11 = 10.0000;
  32. const float RPG_LEVEL_12 = 20.0000;
  33. const float RPG_LEVEL_13 = 50.0000;
  34. const float RPG_LEVEL_14 = 100.0000;
  35. const float RPG_LEVEL_15 = 500.0000;
  36. const float RPG_LEVEL_16 = 1000.0000;
  37. const float RPG_LEVEL_17 = 5000.0000;
  38. const float RPG_LEVEL_18 = 10000.0000;
  39. const float RPG_LEVEL_19 = 50000.0000;
  40. const float RPG_LEVEL_20 = 100000.0000;
  41. const float RPG_LEVEL_LAST = 21; //end of array
  42.  
  43. const int RPG_CUR_PLAYER_LEVEL = 5004;
  44.  
  45. const int NPCA_XP = 29; //NPC Attribute for XP Award Value
  46. const int NPCA_XP_MAX_PLAYER_LEVEL = 30; //NPC Attribute for Max Player Level to get award. (A zero value in this field will always award XP)
  47. const int NPCA_CR = 31; //NPC Attribute for enemy Challenge Rating
  48.  
  49. ffc script rpg
  50. {
  51.     void run(){}
  52.    
  53. void XP(int xp)
  54. {
  55.     if ( !xp ) return; //ignore and break on 0 value
  56.     GRAM[XP] += xp / 10000; //XP is awarded as 1/10000 per point for MAX LONG purposes
  57.     GRAM[G_XP_LAST_AWARD] = xp;
  58.     GRAM[G_XP_DRAW_TIMER] = XP_DRAW_TIME;
  59.     //Link->Misc[LM_XP] = xp+XP_DRAW_TIME; //too slow
  60.     if ( level_up )
  61.     {
  62.         do_levelup();
  63.     }
  64. }
  65.  
  66. void do_levelup()
  67. {
  68.     ++GRAM[RPG_CUR_PLAYER_LEVEL];
  69.     set_next_xp();
  70.     //message display and fanfare
  71.     //stats
  72.     //spells
  73.     //abilities
  74.     //bonuses
  75. }
  76.  
  77. float xp()
  78. {
  79.     return GRAM[XP];
  80. }
  81.  
  82. //call when starting the game
  83. void xp_init()
  84. {
  85.     GRAM[XP_LEVEL_NEXT] = RPG_LEVEL_01;
  86. }
  87.  
  88. void set_next_xp()
  89. {
  90.     int xp_table[RPG_LEVEL_LAST]=
  91.     {
  92.         RPG_LEVEL_01, RPG_LEVEL_02, RPG_LEVEL_03, RPG_LEVEL_04, RPG_LEVEL_05,
  93.         RPG_LEVEL_06, RPG_LEVEL_07, RPG_LEVEL_08, RPG_LEVEL_09, RPG_LEVEL_10,
  94.         RPG_LEVEL_11, RPG_LEVEL_12, RPG_LEVEL_13, RPG_LEVEL_14, RPG_LEVEL_15,
  95.         RPG_LEVEL_16, RPG_LEVEL_17, RPG_LEVEL_18, RPG_LEVEL_19, RPG_LEVEL_20
  96.     };
  97.     GRAM[XP_LEVEL_NEXT] = xp_table[current_level()];
  98. }
  99. int current_level()
  100. {
  101.     return GRAM[RPG_CUR_PLAYER_LEVEL];
  102. }
  103. float need_xp()
  104. {
  105.     return GRAM[GRAM[XP_LEVEL_NEXT]];
  106. }
  107.  
  108. //returns true if the character should level up
  109. bool levelup
  110. {
  111.     if ( xp() >= need_xp() ) return true;
  112. }
  113.  
  114. void draw_xp_award()
  115. {
  116.     /*too slow
  117.     int amt = Link->Misc[LM_XP]
  118.     int time = ( amt - ( amt << 0 ) ) * 10000;
  119.     amt = amt << 0;
  120.     */
  121.     if ( !GRAM[G_XP_DRAW_TIMER] ) return; //Don't draw if timer has elapsed.
  122.     if ( !GRAM[G_XP_LAST_AWARD] ) return; //Don't draw 0 XP
  123.     int xpstr[8];
  124.    
  125.     itoa(GRAM[G_XP_LAST_AWARD], xpstr); //as these reversed?
  126.     //draw two strings using XP values in Link->Misc
  127.     --GRAM[G_XP_DRAW_TIMER];
  128.    
  129. }
  130.  
  131. const int RPG_HUD_XP_X = 180;
  132. const int RPG_HUD_XP_Y = -20;
  133. const int RPG_HUD_XP_FONT = 0;
  134. const int RPG_HUD_XP_COLOUR = 0x02;
  135. //onst int RPG_HUD_
  136.  
  137. void draw_xp_hud(int x, int y, int font, int colour)
  138. {
  139.     int str[13]; //including sign, dot, and term
  140.     int buf[11]; //no sign or dot
  141.     ftoa(GRAM[XP], str);
  142.     int pos;
  143.     for ( int q = 0; q < 13; ++q; )
  144.     {
  145.         if ( string_h.isnumber(str[q] ) //revised string headers
  146.         {
  147.             buf[pos] = str[q];
  148.             ++pos;
  149.         }
  150.     }
  151.     //drawstring
  152.    
  153. }
  154.  
  155.  
  156.  
  157. int get_xp(int id)
  158. {
  159.     npcdata nd = Game->LoadNPCData(id);
  160.     return nd->Attributes[NPCA_XP];
  161.    
  162. }
  163. int get_xp(npc n)
  164. {
  165.     return n->Attributes[NPCA_XP];
  166. }
  167. int get_xp(npcdata nd)
  168. {
  169.     return nd->Attributes[NPCA_XP];
  170. }
  171.  
  172.  
  173. //Determines if the player is entitled to a reward, and awards that amount.
  174. //should this merely do XP(getxp()) ?
  175. //No, we need a monster check that does:
  176. // XP(get_canaward_xp(id))
  177. int get_canaward_xp(int id)
  178. {
  179.     npcdata nd = Game->LoadNPCData(id);
  180.     if ( nd->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] )
  181.     {
  182.         if ( current_level <= nd->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] ) return get_xp(id);
  183.         return 0;
  184.     }
  185.     return get_xp(id);
  186.    
  187. }
  188. int get_canaward_xp(npc n)
  189. {
  190.     if ( n->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] )
  191.     {
  192.         if ( current_level <= nd->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] ) return get_xp(n);
  193.         return 0;
  194.     }
  195.     return get_xp(n);
  196. }
  197. int get_canaward_xp(npcdata nd)
  198. {
  199.     if ( nd->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] )
  200.     {
  201.         if ( current_level <= nd->Attributes[NPCA_XP_MAX_PLAYER_LEVEL] ) return get_xp(id);
  202.         return 0;
  203.     }
  204.     return get_xp(id);
  205. }
  206.  
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement