Updated Copyright year to 2013
[getmangos.git] / src / game / Formulas.h
blobf393bf9744f8d5f5ef64a50f2f7dc06d6133222a
1 /*
2 * Copyright (C) 2005-2013 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 float hk_honor_at_level(uint32 level, uint32 count = 1)
30 return (float)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 case CONTENT_81_85: nBaseExp = 1878; break;
88 default:
89 sLog.outError("BaseGain: Unsupported content level %u", content);
90 nBaseExp = 45; break;
93 if (mob_level >= pl_level)
95 uint32 nLevelDiff = mob_level - pl_level;
96 if (nLevelDiff > 4)
97 nLevelDiff = 4;
98 return ((pl_level * 5 + nBaseExp) * (20 + nLevelDiff) / 10 + 1) / 2;
100 else
102 uint32 gray_level = GetGrayLevel(pl_level);
103 if (mob_level > gray_level)
105 uint32 ZD = GetZeroDifference(pl_level);
106 return (pl_level * 5 + nBaseExp) * (ZD + mob_level - pl_level) / ZD;
108 return 0;
112 inline uint32 Gain(Player* pl, Unit* u)
114 if (u->GetTypeId() == TYPEID_UNIT && (
115 ((Creature*)u)->IsTotem() || ((Creature*)u)->IsPet() ||
116 (((Creature*)u)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL)))
117 return 0;
119 uint32 xp_gain = BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMap(pl->GetMapId()));
120 if (xp_gain == 0)
121 return 0;
123 if (u->GetTypeId() == TYPEID_UNIT && ((Creature*)u)->IsElite())
124 xp_gain *= 2;
126 return (uint32)(xp_gain * sWorld.getConfig(CONFIG_FLOAT_RATE_XP_KILL));
129 inline float xp_in_group_rate(uint32 count, bool isRaid)
131 if (isRaid)
133 // FIX ME: must apply decrease modifiers dependent from raid size
134 return 1.0f;
136 else
138 switch (count)
140 case 0:
141 case 1:
142 case 2:
143 return 1.0f;
144 case 3:
145 return 1.166f;
146 case 4:
147 return 1.3f;
148 case 5:
149 default:
150 return 1.4f;
156 #endif