[4366] Applied MaNGOS coding style to src/game.
[mangos-git.git] / src / game / Formulas.h
bloba55b491328a05af58d5c0afd25a08549a7438153
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_FORMULAS_H
20 #define MANGOS_FORMULAS_H
22 #include "World.h"
23 #include "Database/DatabaseEnv.h"
25 namespace MaNGOS
27 namespace XP
29 typedef enum XPColorChar { RED, ORANGE, YELLOW, GREEN, GRAY };
31 inline uint32 GetGrayLevel(uint32 pl_level)
33 if( pl_level <= 5 )
34 return 0;
35 else if( pl_level <= 39 )
36 return pl_level - 5 - pl_level/10;
37 else if( pl_level <= 59 )
38 return pl_level - 1 - pl_level/5;
39 else
40 return pl_level - 9;
43 inline XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
45 if( mob_level >= pl_level + 5 )
46 return RED;
47 else if( mob_level >= pl_level + 3 )
48 return ORANGE;
49 else if( mob_level >= pl_level - 2 )
50 return YELLOW;
51 else if( mob_level > GetGrayLevel(pl_level) )
52 return GREEN;
53 else
54 return GRAY;
57 inline uint32 GetZeroDifference(uint32 pl_level)
59 if( pl_level < 8 ) return 5;
60 if( pl_level < 10 ) return 6;
61 if( pl_level < 12 ) return 7;
62 if( pl_level < 16 ) return 8;
63 if( pl_level < 20 ) return 9;
64 if( pl_level < 30 ) return 11;
65 if( pl_level < 40 ) return 12;
66 if( pl_level < 45 ) return 13;
67 if( pl_level < 50 ) return 14;
68 if( pl_level < 55 ) return 15;
69 if( pl_level < 60 ) return 16;
70 return 17;
73 inline uint32 BaseGain(uint32 pl_level, uint32 mob_level)
75 if( mob_level >= pl_level )
76 return ((pl_level*5 + 45) * (20 + mob_level - pl_level)/10 + 1)/2;
77 else
79 uint32 gray_level = GetGrayLevel(pl_level);
80 if( mob_level > gray_level )
82 uint32 ZD = GetZeroDifference(pl_level);
83 return (pl_level*5 + 45) * (ZD + mob_level - pl_level)/ZD;
85 return 0;
89 inline uint32 Gain(Player *pl, Unit *u)
91 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isTotem() || ((Creature*)u)->isPet())
92 return 0;
94 uint32 xp_gain= BaseGain(pl->getLevel(), u->getLevel());
95 if( xp_gain == 0 )
96 return 0;
98 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isElite())
99 xp_gain *= 2;
101 return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL));
104 inline uint32 xp_Diff(uint32 lvl)
106 if( lvl < 29 )
107 return 0;
108 if( lvl == 29 )
109 return 1;
110 if( lvl == 30 )
111 return 3;
112 if( lvl == 32 )
113 return 6;
114 else
115 return (5*(lvl-30));
118 inline uint32 mxp(uint32 lvl)
120 if (lvl < 60)
122 return (45 + (5*lvl));
124 else
126 return (235 + (5*lvl));
130 inline uint32 xp_to_level(uint32 lvl)
132 uint32 xp = 0;
133 if (lvl < 60)
135 xp = (8*lvl + xp_Diff(lvl)) * mxp(lvl);
137 else if (lvl == 60)
139 xp = (155 + mxp(lvl) * (1344 - 69 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
141 else
143 xp = (155 + mxp(lvl) * (1344 - ((69-lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
145 // The XP to Level is always rounded to the nearest 100 points (50 rounded to low).
146 return ((xp + 49) / 100) * 100; // use additional () for prevent free association operations in C++
149 inline uint32 xp_to_money(uint32 rewXP, uint32 qlevel)
151 // for max_level
152 uint32 money = 0;
153 if (qlevel >= 15)
154 money = rewXP / 10;
155 else if (qlevel == 14)
156 money = rewXP / 8;
157 else if (qlevel == 13)
158 money = rewXP / 6;
159 else if (qlevel == 12)
160 money = rewXP / 4;
161 else if (qlevel == 11)
162 money = rewXP / 2;
163 else if (qlevel > 0 && qlevel <= 10)
164 money = rewXP;
166 return money;
170 #endif