Initial Comit: First commit.
[SauerEngine.git] / src / rpggame / stats.h
blob53646dfe4ac4b4822baad034279584ec5013bc53
2 // all of these stats are the total "points" an object has
3 // points are converted into efficiency = log(points/pointscale+1)*percentscale+100
4 // efficiency is by default 100% and rises logarithmically from that, according to the two scale vars, which are set in script
5 // efficiency is used with a base value, i.e. a sword that does 10 damage used by a player with 150% melee efficiency does 15 damage
7 // with this define, we can uses these names to define vars, strings, functions etc
9 // see rpg.html for detailed explanation as to their meaning
11 #define RPGSTATNAMES \
12 N(melee) \
13 N(ranged) \
14 N(magic) \
16 N(hpregen) \
17 N(manaregen) \
19 N(maxhp) \
20 N(maxmana) \
22 N(attackspeed) \
23 N(movespeed) \
24 N(jumpheight) \
25 N(tradeskill) \
26 N(feared) \
27 N(stealth) \
28 N(hostility) \
30 N(stata) \
31 N(statb) \
32 N(statc) \
35 #define RPGATTRNAMES \
36 N(ai) \
37 N(hp) \
38 N(mana) \
39 N(gold) \
40 N(worth) \
41 N(useamount) \
42 N(usetype) \
43 N(damage) \
44 N(maxrange) \
45 N(maxangle) \
46 N(attackrate) \
47 N(manacost) \
48 N(effect) \
50 N(attra) \
51 N(attrb) \
52 N(attrc) \
54 N(usesound)
57 #define RPGNAMES RPGSTATNAMES RPGATTRNAMES
59 struct rpgobj;
61 struct stats
63 #define N(n) static int pointscale_##n, percentscale_##n; \
64 static void def_##n(int a, int b) { pointscale_##n = a; percentscale_##n = b; } \
65 int eff_##n() { return int(logf(s_##n/pointscale_##n+1)*percentscale_##n)+100; }
66 RPGSTATNAMES
67 #undef N
68 #define N(n) int s_##n;
69 RPGNAMES
70 #undef N
72 int statupdatetime;
74 stats() : statupdatetime(0)
76 st_reset();
77 #define N(n) s_##n = 0;
78 RPGATTRNAMES
79 #undef N
82 void st_reset()
84 #define N(n) s_##n = 0;
85 RPGSTATNAMES
86 #undef N
89 void st_accumulate(rpgobj &o)
91 #define N(n) s_##n += o.s_##n;
92 RPGSTATNAMES
93 #undef N
96 void st_show(g3d_gui &g)
98 #define N(n) if(s_##n) { s_sprintfd(s)(#n ": %d => %d%%", s_##n, eff_##n()); g.text(s, 0xFFFFFF, "info"); }
99 RPGSTATNAMES
100 #undef N
101 #define N(n) if(s_##n) { s_sprintfd(s)(#n ": %d", s_##n); g.text(s, 0xFFAAAA, "info"); }
102 RPGATTRNAMES
103 #undef N
106 void st_init()
108 s_hp = eff_maxhp();
109 s_mana = eff_maxmana();
112 void st_respawn() // player only
114 s_hp = 10;
117 void st_update(int lastmillis)
119 if(lastmillis-statupdatetime>1000)
121 statupdatetime += 1000;
122 const int base_hp_regen_rate = 2, base_mana_regen_rate = 3; // in script?
123 s_hp += eff_hpregen() *base_hp_regen_rate /100;
124 s_mana += eff_manaregen()*base_mana_regen_rate/100;
125 if(s_hp >eff_maxhp()) s_hp = eff_maxhp();
126 if(s_mana>eff_maxmana()) s_mana = eff_maxmana();