[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / Formulas.h
blob43e77d333de10a92c33d91508031f4b6d17441c1
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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"
24 namespace MaNGOS
26 namespace Honor
28 inline uint32 hk_honor_at_level(uint32 level, uint32 count=1)
30 return (uint32)ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f )));
33 namespace XP
35 typedef enum XPColorChar { RED, ORANGE, YELLOW, GREEN, GRAY };
37 inline uint32 GetGrayLevel(uint32 pl_level)
39 if( pl_level <= 5 )
40 return 0;
41 else if( pl_level <= 39 )
42 return pl_level - 5 - pl_level/10;
43 else if( pl_level <= 59 )
44 return pl_level - 1 - pl_level/5;
45 else
46 return pl_level - 9;
49 inline XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
51 if( mob_level >= pl_level + 5 )
52 return RED;
53 else if( mob_level >= pl_level + 3 )
54 return ORANGE;
55 else if( mob_level >= pl_level - 2 )
56 return YELLOW;
57 else if( mob_level > GetGrayLevel(pl_level) )
58 return GREEN;
59 else
60 return GRAY;
63 inline uint32 GetZeroDifference(uint32 pl_level)
65 if( pl_level < 8 ) return 5;
66 if( pl_level < 10 ) return 6;
67 if( pl_level < 12 ) return 7;
68 if( pl_level < 16 ) return 8;
69 if( pl_level < 20 ) return 9;
70 if( pl_level < 30 ) return 11;
71 if( pl_level < 40 ) return 12;
72 if( pl_level < 45 ) return 13;
73 if( pl_level < 50 ) return 14;
74 if( pl_level < 55 ) return 15;
75 if( pl_level < 60 ) return 16;
76 return 17;
79 inline uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content)
81 //TODO: need modifier for CONTENT_71_80 different from CONTENT_61_70?
82 const uint32 nBaseExp = content == CONTENT_1_60 ? 45 : 235;
83 if( mob_level >= pl_level )
85 uint32 nLevelDiff = mob_level - pl_level;
86 if (nLevelDiff > 4)
87 nLevelDiff = 4;
88 return ((pl_level*5 + nBaseExp) * (20 + nLevelDiff)/10 + 1)/2;
90 else
92 uint32 gray_level = GetGrayLevel(pl_level);
93 if( mob_level > gray_level )
95 uint32 ZD = GetZeroDifference(pl_level);
96 return (pl_level*5 + nBaseExp) * (ZD + mob_level - pl_level)/ZD;
98 return 0;
102 inline uint32 Gain(Player *pl, Unit *u)
104 if(u->GetTypeId()==TYPEID_UNIT && (
105 ((Creature*)u)->isTotem() || ((Creature*)u)->isPet() ||
106 (((Creature*)u)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL) ))
107 return 0;
109 uint32 xp_gain= BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(pl->GetMapId(),pl->GetZoneId()));
110 if( xp_gain == 0 )
111 return 0;
113 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isElite())
114 xp_gain *= 2;
116 return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL));
119 inline uint32 xp_Diff(uint32 lvl)
121 if( lvl < 29 )
122 return 0;
123 if( lvl == 29 )
124 return 1;
125 if( lvl == 30 )
126 return 3;
127 if( lvl == 31 )
128 return 6;
129 else
130 return (5*(lvl-30));
133 inline uint32 mxp(uint32 lvl)
135 if (lvl < 60)
137 return (45 + (5*lvl));
139 else
141 return (235 + (5*lvl));
145 inline uint32 xp_to_level(uint32 lvl)
147 uint32 xp = 0;
148 if (lvl < 60)
150 xp = (8*lvl + xp_Diff(lvl)) * mxp(lvl);
152 else if (lvl == 60)
154 xp = (155 + mxp(lvl) * (1344 - 70 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
156 else if (lvl < 70)
158 xp = (155 + mxp(lvl) * (1344 - ((69-lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
159 }else
161 // level higher than 70 is not supported
162 xp = (uint32)(779700 * (pow(sWorld.getRate(RATE_XP_PAST_70), (int32)lvl - 69)));
163 return ((xp < 0x7fffffff) ? xp : 0x7fffffff);
166 // The XP to Level is always rounded to the nearest 100 points (50 rounded to high).
167 xp = ((xp + 50) / 100) * 100; // use additional () for prevent free association operations in C++
169 if ((lvl > 10) && (lvl < 60)) // compute discount added in 2.3.x
171 uint32 discount = (lvl < 28) ? (lvl - 10) : 18;
172 xp = (xp * (100 - discount)) / 100; // apply discount
173 xp = (xp / 100) * 100; // floor to hundreds
176 return xp;
179 inline float xp_in_group_rate(uint32 count, bool isRaid)
181 if(isRaid)
183 // FIX ME: must apply decrease modifiers dependent from raid size
184 return 1.0f;
186 else
188 switch(count)
190 case 0:
191 case 1:
192 case 2:
193 return 1.0f;
194 case 3:
195 return 1.166f;
196 case 4:
197 return 1.3f;
198 case 5:
199 default:
200 return 1.4f;
206 #endif