[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / BattleGroundAB.cpp
blob7f19148ef1d0e1b8a543a8d9acca38781967a13f
1 /*
2 * Copyright (C) 2005-2010 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 #include "Object.h"
20 #include "Player.h"
21 #include "BattleGround.h"
22 #include "BattleGroundAB.h"
23 #include "Creature.h"
24 #include "GameObject.h"
25 #include "BattleGroundMgr.h"
26 #include "Language.h"
27 #include "Util.h"
28 #include "WorldPacket.h"
29 #include "MapManager.h"
31 BattleGroundAB::BattleGroundAB()
33 m_BuffChange = true;
34 m_BgObjects.resize(BG_AB_OBJECT_MAX);
36 m_StartMessageIds[BG_STARTING_EVENT_FIRST] = 0;
37 m_StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_AB_START_ONE_MINUTE;
38 m_StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_AB_START_HALF_MINUTE;
39 m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_AB_HAS_BEGUN;
42 BattleGroundAB::~BattleGroundAB()
46 void BattleGroundAB::Update(uint32 diff)
48 BattleGround::Update(diff);
50 if (GetStatus() == STATUS_IN_PROGRESS)
52 int team_points[BG_TEAMS_COUNT] = { 0, 0 };
54 for (int node = 0; node < BG_AB_NODES_MAX; ++node)
56 // 3 sec delay to spawn new banner instead previous despawned one
57 if (m_BannerTimers[node].timer)
59 if (m_BannerTimers[node].timer > diff)
60 m_BannerTimers[node].timer -= diff;
61 else
63 m_BannerTimers[node].timer = 0;
64 _CreateBanner(node, m_BannerTimers[node].type, m_BannerTimers[node].teamIndex, false);
68 // 1-minute to occupy a node from contested state
69 if (m_NodeTimers[node])
71 if (m_NodeTimers[node] > diff)
72 m_NodeTimers[node] -= diff;
73 else
75 m_NodeTimers[node] = 0;
76 // Change from contested to occupied !
77 uint8 teamIndex = m_Nodes[node]-1;
78 m_prevNodes[node] = m_Nodes[node];
79 m_Nodes[node] += 2;
80 // create new occupied banner
81 _CreateBanner(node, BG_AB_NODE_TYPE_OCCUPIED, teamIndex, true);
82 _SendNodeUpdate(node);
83 _NodeOccupied(node,(teamIndex == 0) ? ALLIANCE:HORDE);
84 // Message to chatlog
86 if (teamIndex == 0)
88 SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_ALLIANCE,NULL,LANG_BG_ALLY,_GetNodeNameId(node));
89 PlaySoundToAll(BG_AB_SOUND_NODE_CAPTURED_ALLIANCE);
91 else
93 SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_HORDE,NULL,LANG_BG_HORDE,_GetNodeNameId(node));
94 PlaySoundToAll(BG_AB_SOUND_NODE_CAPTURED_HORDE);
99 for (int team = 0; team < BG_TEAMS_COUNT; ++team)
100 if (m_Nodes[node] == team + BG_AB_NODE_TYPE_OCCUPIED)
101 ++team_points[team];
104 // Accumulate points
105 for (int team = 0; team < BG_TEAMS_COUNT; ++team)
107 int points = team_points[team];
108 if (!points)
109 continue;
110 m_lastTick[team] += diff;
111 if (m_lastTick[team] > BG_AB_TickIntervals[points])
113 m_lastTick[team] -= BG_AB_TickIntervals[points];
114 m_TeamScores[team] += BG_AB_TickPoints[points];
115 m_HonorScoreTics[team] += BG_AB_TickPoints[points];
116 m_ReputationScoreTics[team] += BG_AB_TickPoints[points];
117 if (m_ReputationScoreTics[team] >= m_ReputationTics)
119 (team == BG_TEAM_ALLIANCE) ? RewardReputationToTeam(509, 10, ALLIANCE) : RewardReputationToTeam(510, 10, HORDE);
120 m_ReputationScoreTics[team] -= m_ReputationTics;
122 if (m_HonorScoreTics[team] >= m_HonorTics)
124 RewardHonorToTeam(GetBonusHonorFromKill(1), (team == BG_TEAM_ALLIANCE) ? ALLIANCE : HORDE);
125 m_HonorScoreTics[team] -= m_HonorTics;
127 if (!m_IsInformedNearVictory && m_TeamScores[team] > BG_AB_WARNING_NEAR_VICTORY_SCORE)
129 if (team == BG_TEAM_ALLIANCE)
130 SendMessageToAll(LANG_BG_AB_A_NEAR_VICTORY, CHAT_MSG_BG_SYSTEM_NEUTRAL);
131 else
132 SendMessageToAll(LANG_BG_AB_H_NEAR_VICTORY, CHAT_MSG_BG_SYSTEM_NEUTRAL);
133 PlaySoundToAll(BG_AB_SOUND_NEAR_VICTORY);
134 m_IsInformedNearVictory = true;
137 if (m_TeamScores[team] > BG_AB_MAX_TEAM_SCORE)
138 m_TeamScores[team] = BG_AB_MAX_TEAM_SCORE;
139 if (team == BG_TEAM_ALLIANCE)
140 UpdateWorldState(BG_AB_OP_RESOURCES_ALLY, m_TeamScores[team]);
141 if (team == BG_TEAM_HORDE)
142 UpdateWorldState(BG_AB_OP_RESOURCES_HORDE, m_TeamScores[team]);
144 // update achievement flags
145 // we increased m_TeamScores[team] so we just need to check if it is 500 more than other teams resources
146 // horde will be a bit disadvantaged, but we can assume that points aren't updated for both team in same Update() call
147 uint8 otherTeam = (team + 1) % BG_TEAMS_COUNT;
148 if (m_TeamScores[team] > m_TeamScores[otherTeam] + 500)
149 m_TeamScores500Disadvantage[otherTeam] = true;
153 // Test win condition
154 if (m_TeamScores[BG_TEAM_ALLIANCE] >= BG_AB_MAX_TEAM_SCORE)
155 EndBattleGround(ALLIANCE);
156 if (m_TeamScores[BG_TEAM_HORDE] >= BG_AB_MAX_TEAM_SCORE)
157 EndBattleGround(HORDE);
161 void BattleGroundAB::StartingEventCloseDoors()
163 // despawn buffs
164 for (int i = 0; i < BG_AB_NODES_MAX * 3; ++i)
165 SpawnBGObject(m_BgObjects[BG_AB_OBJECT_SPEEDBUFF_STABLES + i], RESPAWN_ONE_DAY);
168 void BattleGroundAB::StartingEventOpenDoors()
170 for (int i = 0; i < BG_AB_NODES_MAX; ++i)
172 //randomly select buff to spawn
173 uint8 buff = urand(0, 2);
174 SpawnBGObject(m_BgObjects[BG_AB_OBJECT_SPEEDBUFF_STABLES + buff + i * 3], RESPAWN_IMMEDIATELY);
176 OpenDoorEvent(BG_EVENT_DOOR);
179 void BattleGroundAB::AddPlayer(Player *plr)
181 BattleGround::AddPlayer(plr);
182 //create score and add it to map, default values are set in the constructor
183 BattleGroundABScore* sc = new BattleGroundABScore;
185 m_PlayerScores[plr->GetGUID()] = sc;
188 void BattleGroundAB::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
193 void BattleGroundAB::HandleAreaTrigger(Player *Source, uint32 Trigger)
195 switch(Trigger)
197 case 3948: // Arathi Basin Alliance Exit.
198 if (Source->GetTeam() != ALLIANCE)
199 Source->GetSession()->SendNotification(LANG_BATTLEGROUND_ONLY_ALLIANCE_USE);
200 else
201 Source->LeaveBattleground();
202 break;
203 case 3949: // Arathi Basin Horde Exit.
204 if (Source->GetTeam() != HORDE)
205 Source->GetSession()->SendNotification(LANG_BATTLEGROUND_ONLY_HORDE_USE);
206 else
207 Source->LeaveBattleground();
208 break;
209 case 3866: // Stables
210 case 3869: // Gold Mine
211 case 3867: // Farm
212 case 3868: // Lumber Mill
213 case 3870: // Black Smith
214 case 4020: // Unk1
215 case 4021: // Unk2
216 //break;
217 default:
218 //sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
219 //Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
220 break;
224 /* type: 0-neutral, 1-contested, 3-occupied
225 teamIndex: 0-ally, 1-horde */
226 void BattleGroundAB::_CreateBanner(uint8 node, uint8 type, uint8 teamIndex, bool delay)
228 // Just put it into the queue
229 if (delay)
231 m_BannerTimers[node].timer = 2000;
232 m_BannerTimers[node].type = type;
233 m_BannerTimers[node].teamIndex = teamIndex;
234 return;
237 // cause the node-type is in the generic form
238 // please see in the headerfile for the ids
239 if (type != BG_AB_NODE_TYPE_NEUTRAL)
240 type += teamIndex;
242 SpawnEvent(node, type, true); // will automaticly despawn other events
245 int32 BattleGroundAB::_GetNodeNameId(uint8 node)
247 switch (node)
249 case BG_AB_NODE_STABLES: return LANG_BG_AB_NODE_STABLES;
250 case BG_AB_NODE_BLACKSMITH: return LANG_BG_AB_NODE_BLACKSMITH;
251 case BG_AB_NODE_FARM: return LANG_BG_AB_NODE_FARM;
252 case BG_AB_NODE_LUMBER_MILL:return LANG_BG_AB_NODE_LUMBER_MILL;
253 case BG_AB_NODE_GOLD_MINE: return LANG_BG_AB_NODE_GOLD_MINE;
254 default:
255 ASSERT(0);
257 return 0;
260 void BattleGroundAB::FillInitialWorldStates(WorldPacket& data)
262 const uint8 plusArray[] = {0, 2, 3, 0, 1};
264 // Node icons
265 for (uint8 node = 0; node < BG_AB_NODES_MAX; ++node)
266 data << uint32(BG_AB_OP_NODEICONS[node]) << uint32((m_Nodes[node]==0)?1:0);
268 // Node occupied states
269 for (uint8 node = 0; node < BG_AB_NODES_MAX; ++node)
270 for (uint8 i = 1; i < BG_AB_NODES_MAX; ++i)
271 data << uint32(BG_AB_OP_NODESTATES[node] + plusArray[i]) << uint32((m_Nodes[node]==i)?1:0);
273 // How many bases each team owns
274 uint8 ally = 0, horde = 0;
275 for (uint8 node = 0; node < BG_AB_NODES_MAX; ++node)
276 if (m_Nodes[node] == BG_AB_NODE_STATUS_ALLY_OCCUPIED)
277 ++ally;
278 else if (m_Nodes[node] == BG_AB_NODE_STATUS_HORDE_OCCUPIED)
279 ++horde;
281 data << uint32(BG_AB_OP_OCCUPIED_BASES_ALLY) << uint32(ally);
282 data << uint32(BG_AB_OP_OCCUPIED_BASES_HORDE) << uint32(horde);
284 // Team scores
285 data << uint32(BG_AB_OP_RESOURCES_MAX) << uint32(BG_AB_MAX_TEAM_SCORE);
286 data << uint32(BG_AB_OP_RESOURCES_WARNING) << uint32(BG_AB_WARNING_NEAR_VICTORY_SCORE);
287 data << uint32(BG_AB_OP_RESOURCES_ALLY) << uint32(m_TeamScores[BG_TEAM_ALLIANCE]);
288 data << uint32(BG_AB_OP_RESOURCES_HORDE) << uint32(m_TeamScores[BG_TEAM_HORDE]);
290 // other unknown
291 data << uint32(0x745) << uint32(0x2); // 37 1861 unk
294 void BattleGroundAB::_SendNodeUpdate(uint8 node)
296 // Send node owner state update to refresh map icons on client
297 const uint8 plusArray[] = {0, 2, 3, 0, 1};
299 if (m_prevNodes[node])
300 UpdateWorldState(BG_AB_OP_NODESTATES[node] + plusArray[m_prevNodes[node]], 0);
301 else
302 UpdateWorldState(BG_AB_OP_NODEICONS[node], 0);
304 UpdateWorldState(BG_AB_OP_NODESTATES[node] + plusArray[m_Nodes[node]], 1);
306 // How many bases each team owns
307 uint8 ally = 0, horde = 0;
308 for (uint8 i = 0; i < BG_AB_NODES_MAX; ++i)
309 if (m_Nodes[i] == BG_AB_NODE_STATUS_ALLY_OCCUPIED)
310 ++ally;
311 else if (m_Nodes[i] == BG_AB_NODE_STATUS_HORDE_OCCUPIED)
312 ++horde;
314 UpdateWorldState(BG_AB_OP_OCCUPIED_BASES_ALLY, ally);
315 UpdateWorldState(BG_AB_OP_OCCUPIED_BASES_HORDE, horde);
318 void BattleGroundAB::_NodeOccupied(uint8 node,Team team)
320 uint8 capturedNodes = 0;
321 for (uint8 i = 0; i < BG_AB_NODES_MAX; ++i)
323 if (m_Nodes[node] == GetTeamIndexByTeamId(team) + BG_AB_NODE_TYPE_OCCUPIED && !m_NodeTimers[i])
324 ++capturedNodes;
326 if (capturedNodes >= 5)
327 CastSpellOnTeam(SPELL_AB_QUEST_REWARD_5_BASES, team);
328 if (capturedNodes >= 4)
329 CastSpellOnTeam(SPELL_AB_QUEST_REWARD_4_BASES, team);
332 /* Invoked if a player used a banner as a gameobject */
333 void BattleGroundAB::EventPlayerClickedOnFlag(Player *source, GameObject* target_obj)
335 if (GetStatus() != STATUS_IN_PROGRESS)
336 return;
338 uint8 event = (sBattleGroundMgr.GetGameObjectEventIndex(target_obj->GetDBTableGUIDLow())).event1;
339 if (event >= BG_AB_NODES_MAX) // not a node
340 return;
341 BG_AB_Nodes node = BG_AB_Nodes(event);
343 BattleGroundTeamId teamIndex = GetTeamIndexByTeamId(source->GetTeam());
345 // Check if player really could use this banner, not cheated
346 if (!(m_Nodes[node] == 0 || teamIndex == m_Nodes[node] % 2))
347 return;
349 source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
350 uint32 sound = 0;
352 // TODO in the following code we should restructure a bit to avoid
353 // duplication (or maybe write functions?)
354 // If node is neutral, change to contested
355 if (m_Nodes[node] == BG_AB_NODE_TYPE_NEUTRAL)
357 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
358 m_prevNodes[node] = m_Nodes[node];
359 m_Nodes[node] = teamIndex + 1;
360 // create new contested banner
361 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
362 _SendNodeUpdate(node);
363 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
365 if (teamIndex == 0)
366 SendMessage2ToAll(LANG_BG_AB_NODE_CLAIMED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node), LANG_BG_ALLY);
367 else
368 SendMessage2ToAll(LANG_BG_AB_NODE_CLAIMED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node), LANG_BG_HORDE);
370 sound = BG_AB_SOUND_NODE_CLAIMED;
372 // If node is contested
373 else if ((m_Nodes[node] == BG_AB_NODE_STATUS_ALLY_CONTESTED) || (m_Nodes[node] == BG_AB_NODE_STATUS_HORDE_CONTESTED))
375 // If last state is NOT occupied, change node to enemy-contested
376 if (m_prevNodes[node] < BG_AB_NODE_TYPE_OCCUPIED)
378 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
379 m_prevNodes[node] = m_Nodes[node];
380 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED;
381 // create new contested banner
382 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
383 _SendNodeUpdate(node);
384 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
386 if (teamIndex == BG_TEAM_ALLIANCE)
387 SendMessage2ToAll(LANG_BG_AB_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
388 else
389 SendMessage2ToAll(LANG_BG_AB_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
391 // If contested, change back to occupied
392 else
394 UpdatePlayerScore(source, SCORE_BASES_DEFENDED, 1);
395 m_prevNodes[node] = m_Nodes[node];
396 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_OCCUPIED;
397 // create new occupied banner
398 _CreateBanner(node, BG_AB_NODE_TYPE_OCCUPIED, teamIndex, true);
399 _SendNodeUpdate(node);
400 m_NodeTimers[node] = 0;
401 _NodeOccupied(node,(teamIndex == BG_TEAM_ALLIANCE) ? ALLIANCE:HORDE);
403 if (teamIndex == BG_TEAM_ALLIANCE)
404 SendMessage2ToAll(LANG_BG_AB_NODE_DEFENDED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
405 else
406 SendMessage2ToAll(LANG_BG_AB_NODE_DEFENDED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
408 sound = (teamIndex == BG_TEAM_ALLIANCE) ? BG_AB_SOUND_NODE_ASSAULTED_ALLIANCE : BG_AB_SOUND_NODE_ASSAULTED_HORDE;
410 // If node is occupied, change to enemy-contested
411 else
413 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
414 m_prevNodes[node] = m_Nodes[node];
415 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED;
416 // create new contested banner
417 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
418 _SendNodeUpdate(node);
419 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
421 if (teamIndex == BG_TEAM_ALLIANCE)
422 SendMessage2ToAll(LANG_BG_AB_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_ALLIANCE, source, _GetNodeNameId(node));
423 else
424 SendMessage2ToAll(LANG_BG_AB_NODE_ASSAULTED,CHAT_MSG_BG_SYSTEM_HORDE, source, _GetNodeNameId(node));
426 sound = (teamIndex == BG_TEAM_ALLIANCE) ? BG_AB_SOUND_NODE_ASSAULTED_ALLIANCE : BG_AB_SOUND_NODE_ASSAULTED_HORDE;
429 // If node is occupied again, send "X has taken the Y" msg.
430 if (m_Nodes[node] >= BG_AB_NODE_TYPE_OCCUPIED)
432 if (teamIndex == BG_TEAM_ALLIANCE)
433 SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_ALLIANCE, NULL, LANG_BG_ALLY, _GetNodeNameId(node));
434 else
435 SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN,CHAT_MSG_BG_SYSTEM_HORDE, NULL, LANG_BG_HORDE, _GetNodeNameId(node));
437 PlaySoundToAll(sound);
440 bool BattleGroundAB::SetupBattleGround()
442 //buffs
443 for (int i = 0; i < BG_AB_NODES_MAX; ++i)
445 if (!AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i, Buff_Entries[0], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
446 || !AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i + 1, Buff_Entries[1], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
447 || !AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i + 2, Buff_Entries[2], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
449 sLog.outErrorDb("BatteGroundAB: Failed to spawn buff object!");
452 return true;
455 void BattleGroundAB::Reset()
457 //call parent's class reset
458 BattleGround::Reset();
460 for (uint8 i = 0; i < BG_TEAMS_COUNT; ++i)
462 m_TeamScores[i] = 0;
463 m_lastTick[i] = 0;
464 m_HonorScoreTics[i] = 0;
465 m_ReputationScoreTics[i] = 0;
466 m_TeamScores500Disadvantage[i] = false;
469 m_IsInformedNearVictory = false;
470 bool isBGWeekend = BattleGroundMgr::IsBGWeekend(GetTypeID());
471 m_HonorTics = (isBGWeekend) ? BG_AB_ABBGWeekendHonorTicks : BG_AB_NotABBGWeekendHonorTicks;
472 m_ReputationTics = (isBGWeekend) ? BG_AB_ABBGWeekendReputationTicks : BG_AB_NotABBGWeekendReputationTicks;
474 for (uint8 i = 0; i < BG_AB_NODES_MAX; ++i)
476 m_Nodes[i] = 0;
477 m_prevNodes[i] = 0;
478 m_NodeTimers[i] = 0;
479 m_BannerTimers[i].timer = 0;
481 // all nodes owned by neutral team at beginning
482 m_ActiveEvents[i] = BG_AB_NODE_TYPE_NEUTRAL;
487 void BattleGroundAB::EndBattleGround(uint32 winner)
489 //win reward
490 if (winner == ALLIANCE)
491 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
492 if (winner == HORDE)
493 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
494 //complete map_end rewards (even if no team wins)
495 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
496 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
498 BattleGround::EndBattleGround(winner);
501 WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(Player* player)
503 BattleGroundTeamId teamIndex = GetTeamIndexByTeamId(player->GetTeam());
505 // Is there any occupied node for this team?
506 std::vector<uint8> nodes;
507 for (uint8 i = 0; i < BG_AB_NODES_MAX; ++i)
508 if (m_Nodes[i] == teamIndex + 3)
509 nodes.push_back(i);
511 WorldSafeLocsEntry const* good_entry = NULL;
512 // If so, select the closest node to place ghost on
513 if (!nodes.empty())
515 float plr_x = player->GetPositionX();
516 float plr_y = player->GetPositionY();
518 float mindist = 999999.0f;
519 for (uint8 i = 0; i < nodes.size(); ++i)
521 WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[nodes[i]] );
522 if (!entry)
523 continue;
524 float dist = (entry->x - plr_x)*(entry->x - plr_x)+(entry->y - plr_y)*(entry->y - plr_y);
525 if (mindist > dist)
527 mindist = dist;
528 good_entry = entry;
531 nodes.clear();
533 // If not, place ghost on starting location
534 if (!good_entry)
535 good_entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[teamIndex+5] );
537 return good_entry;
540 void BattleGroundAB::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
542 BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
543 if( itr == m_PlayerScores.end() ) // player not found...
544 return;
546 switch(type)
548 case SCORE_BASES_ASSAULTED:
549 ((BattleGroundABScore*)itr->second)->BasesAssaulted += value;
550 break;
551 case SCORE_BASES_DEFENDED:
552 ((BattleGroundABScore*)itr->second)->BasesDefended += value;
553 break;
554 default:
555 BattleGround::UpdatePlayerScore(Source,type,value);
556 break;
560 bool BattleGroundAB::IsAllNodesConrolledByTeam(uint32 team) const
562 uint32 count = 0;
563 for (int i = 0; i < BG_AB_NODES_MAX; ++i)
564 if ((team == ALLIANCE && m_Nodes[i] == BG_AB_NODE_STATUS_ALLY_OCCUPIED) ||
565 (team == HORDE && m_Nodes[i] == BG_AB_NODE_STATUS_HORDE_OCCUPIED))
566 ++count;
568 return count == BG_AB_NODES_MAX;