[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Formulas.h
blob9250d86be867d2efda58df4e9fbb52943084b8ad
1 /*
2 * Copyright (C) 2005-2009 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 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 uint32 nBaseExp;
82 switch(content)
84 case CONTENT_1_60: nBaseExp = 45; break;
85 case CONTENT_61_70: nBaseExp = 235; break;
86 case CONTENT_71_80: nBaseExp = 580; break;
87 default:
88 sLog.outError("BaseGain: Unsupported content level %u",content);
89 nBaseExp = 45; break;
92 if( mob_level >= pl_level )
94 uint32 nLevelDiff = mob_level - pl_level;
95 if (nLevelDiff > 4)
96 nLevelDiff = 4;
97 return ((pl_level*5 + nBaseExp) * (20 + nLevelDiff)/10 + 1)/2;
99 else
101 uint32 gray_level = GetGrayLevel(pl_level);
102 if( mob_level > gray_level )
104 uint32 ZD = GetZeroDifference(pl_level);
105 return (pl_level*5 + nBaseExp) * (ZD + mob_level - pl_level)/ZD;
107 return 0;
111 inline uint32 Gain(Player *pl, Unit *u)
113 if(u->GetTypeId()==TYPEID_UNIT && (
114 ((Creature*)u)->isTotem() || ((Creature*)u)->isPet() ||
115 (((Creature*)u)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL) ))
116 return 0;
118 uint32 xp_gain= BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(pl->GetMapId(),pl->GetZoneId()));
119 if( xp_gain == 0 )
120 return 0;
122 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isElite())
123 xp_gain *= 2;
125 return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL));
128 inline float xp_in_group_rate(uint32 count, bool isRaid)
130 if(isRaid)
132 // FIX ME: must apply decrease modifiers dependent from raid size
133 return 1.0f;
135 else
137 switch(count)
139 case 0:
140 case 1:
141 case 2:
142 return 1.0f;
143 case 3:
144 return 1.166f;
145 case 4:
146 return 1.3f;
147 case 5:
148 default:
149 return 1.4f;
155 #endif