*Display correct building damage state/team on map in wintergrasp.

*Rebuild buidlings after fortress is taken over.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-06-01 12:48:12 -05:00
parent 9ff8f1ab5e
commit b5a098643f
11 changed files with 155 additions and 23 deletions
+1 -1
View File
@@ -519,7 +519,7 @@ struct AreaGroupEntry
struct AreaPOIEntry
{
uint32 id; //0
//uint32 icon[11]; //1-11
uint32 icon[11]; //1-11
float x; //12
float y; //13
float z; //14
+1 -1
View File
@@ -25,7 +25,7 @@ const char Achievementfmt[]="niixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiixixxxxxxxxx
const char AchievementCriteriafmt[]="niiiiiiiixxxxxxxxxxxxxxxxxiixix";
const char AreaTableEntryfmt[]="iiinixxxxxissssssssssssssssxixxxxxxx";
const char AreaGroupEntryfmt[]="niiiiiii";
const char AreaPOIEntryfmt[]="nxxxxxxxxxxxfffixixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxix";
const char AreaPOIEntryfmt[]="niiiiiiiiiiifffixixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxix";
const char AreaTriggerEntryfmt[]="niffffffff";
const char AuctionHouseEntryfmt[]="niiixxxxxxxxxxxxxxxxx";
const char BankBagSlotPricesEntryfmt[]="ni";
+8
View File
@@ -1442,6 +1442,7 @@ void GameObject::TakenDamage(uint32 damage)
SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_DESTROYED);
SetUInt32Value(GAMEOBJECT_DISPLAYID, m_goInfo->destructibleBuilding.destroyedDisplayId);
m_goValue->destructibleBuilding.health = 0;
EventInform(m_goInfo->destructibleBuilding.destroyedEventId);
}
else // from undamaged to damaged
{
@@ -1455,6 +1456,7 @@ void GameObject::TakenDamage(uint32 damage)
}
else
m_goValue->destructibleBuilding.health = 0;
EventInform(m_goInfo->destructibleBuilding.damagedEventId);
}
}
@@ -1465,6 +1467,12 @@ void GameObject::Rebuild()
m_goValue->destructibleBuilding.health = m_goInfo->destructibleBuilding.damagedHealth;
}
void GameObject::EventInform(uint32 eventId)
{
if(eventId && m_zoneScript)
m_zoneScript->ProcessEvent(this, eventId);
}
// overwrite WorldObject function for proper name localization
const char* GameObject::GetNameForLocaleIdx(int32 loc_idx) const
{
+4 -2
View File
@@ -353,13 +353,13 @@ struct GameObjectInfo
uint32 damagedHealth; //0
uint32 dmgPctState2; //1
uint32 state1Name; //2
uint32 state2Name; //3
uint32 damagedEventId; //3
uint32 damagedDisplayId; //4
uint32 destroyedHealth; //5
uint32 unk6;
uint32 unk7;
uint32 unk8;
uint32 unk9;
uint32 destroyedEventId; //9
uint32 destroyedDisplayId; //10
} destructibleBuilding;
//34 GAMEOBJECT_TYPE_GUILDBANK - empty
@@ -648,6 +648,8 @@ class TRINITY_DLL_SPEC GameObject : public WorldObject
bool IsInRange(float x, float y, float z, float radius) const;
void TakenDamage(uint32 damage);
void Rebuild();
void EventInform(uint32 eventId);
protected:
uint32 m_charges; // Spell charges for GAMEOBJECT_TYPE_SPELLCASTER (22)
uint32 m_spellId;
+8
View File
@@ -497,6 +497,14 @@ bool OutdoorPvP::HandleAreaTrigger(Player *plr, uint32 trigger)
return false;
}
void OutdoorPvP::BroadcastPacket(WorldPacket &data)
{
// This is faster than sWorld.SendZoneMessage
for(uint32 team = 0; team < 2; ++team)
for(PlayerSet::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
(*itr)->GetSession()->SendPacket(&data);
}
void OutdoorPvP::RegisterZone(uint32 zoneId)
{
sOutdoorPvPMgr.AddZone(zoneId, this);
+2
View File
@@ -210,6 +210,8 @@ protected:
// world state stuff
virtual void SendRemoveWorldStates(Player * plr) {}
void BroadcastPacket(WorldPacket & data);
virtual void HandlePlayerEnterZone(Player * plr, uint32 zone);
virtual void HandlePlayerLeaveZone(Player * plr, uint32 zone);
+1
View File
@@ -21,6 +21,7 @@
#include "SharedDefines.h"
#include "OutdoorPvP.h"
#include "Player.h"
#include "WorldPacket.h"
#define OTHER_TEAM(a) (a == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE)
+1 -2
View File
@@ -2967,8 +2967,7 @@ void Spell::SendLoot(uint64 guid, LootType loottype)
{
sLog.outDebug("Goober ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->goober.eventId,gameObjTarget->GetDBTableGUIDLow());
sWorld.ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->goober.eventId, player, gameObjTarget);
if(gameObjTarget->GetZoneScript())
gameObjTarget->GetZoneScript()->ProcessEvent(gameObjTarget, gameObjTarget->GetGOInfo()->goober.eventId);
gameObjTarget->EventInform(gameObjTarget->GetGOInfo()->goober.eventId);
}
// cast goober spell
+106 -8
View File
@@ -49,19 +49,75 @@ void LoadTeamPair(TeamPairMap &pairMap, const TeamPair *pair)
}
}
typedef std::list<const AreaPOIEntry *> AreaPOIList;
bool OPvPWintergrasp::SetupOutdoorPvP()
{
RegisterZone(ZONE_WINTERGRASP);
m_defender = TeamId(rand()%2);
//m_defender = TEAM_ALLIANCE;
// Load buildings
AreaPOIList areaPOIs;
float minX = 9999, minY = 9999, maxX = -9999, maxY = -9999;
for(uint32 i = 0; i < sAreaPOIStore.GetNumRows(); ++i)
{
const AreaPOIEntry * poiInfo = sAreaPOIStore.LookupEntry(i);
if(poiInfo && poiInfo->zoneId == ZONE_WINTERGRASP)
{
areaPOIs.push_back(poiInfo);
if(minX > poiInfo->x) minX = poiInfo->x;
if(minY > poiInfo->y) minY = poiInfo->y;
if(maxX < poiInfo->x) maxX = poiInfo->x;
if(maxY < poiInfo->y) maxY = poiInfo->y;
}
}
minX -= 20; minY -= 20; maxX += 20; maxY += 20;
QueryResult *result = WorldDatabase.PQuery("SELECT `guid`,`position_x`,`position_y` FROM `gameobject`,`gameobject_template` WHERE `gameobject`.`map`=571"
" AND `gameobject`.`position_x`>%f AND `gameobject`.`position_y`>%f"
" AND `gameobject`.`position_x`<%f AND `gameobject`.`position_y`<%f"
" AND `gameobject_template`.`type`=33 AND `gameobject`.`id`=`gameobject_template`.`entry`", minX, minY, maxX, maxY);
if(!result)
return false;
do
{
Field *fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float minDist = 100;
AreaPOIList::iterator poi = areaPOIs.end();
for(AreaPOIList::iterator itr = areaPOIs.begin(); itr != areaPOIs.end(); ++itr)
{
if(!(*itr)->icon[1]) // note: may for other use
continue;
float dist = (abs((*itr)->x - x) + abs((*itr)->y - y));
if(minDist > dist)
{
minDist = dist;
poi = itr;
}
}
if(poi != areaPOIs.end())
{
m_buildingStates[guid] = new BuildingState((*poi)->worldState
, x > POS_X_CENTER ? m_defender : OTHER_TEAM(m_defender)
, m_defender != TEAM_ALLIANCE);
areaPOIs.erase(poi);
}
}while(result->NextRow());
delete result;
//for(AreaPOIList::iterator itr = areaPOIs.begin(); itr != areaPOIs.end(); ++itr)
// sLog.outError("not assigned %u %f %f", (*itr)->id, (*itr)->x, (*itr)->y);
m_defender = TeamId(rand()%2);
//m_defender = TEAM_ALLIANCE;
//gameeventmgr.StartInternalEvent(GameEventWintergraspDefender[m_defender]);
//Titan Relic eventid = 19982
@@ -73,10 +129,24 @@ bool OPvPWintergrasp::SetupOutdoorPvP()
return true;
}
void OPvPWintergrasp::ProcessEvent(WorldObject *obj, uint32 eventId)
void OPvPWintergrasp::ProcessEvent(GameObject *obj, uint32 eventId)
{
if(eventId == 19982)
ChangeDefender();
else if(obj->GetGoType() == GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING)
{
BuildingStateMap::const_iterator itr = m_buildingStates.find(obj->GetDBTableGUIDLow());
if(itr != m_buildingStates.end())
{
if(obj->HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_DAMAGED))
itr->second->damageState = DAMAGE_DAMAGED;
else
itr->second->damageState = DAMAGE_DESTROYED;
for(uint32 team = 0; team < 2; ++team)
for(PlayerSet::iterator p_itr = m_players[team].begin(); p_itr != m_players[team].end(); ++p_itr)
itr->second->SendUpdate(*p_itr);
}
}
}
void OPvPWintergrasp::ChangeDefender()
@@ -118,6 +188,13 @@ void OPvPWintergrasp::OnGameObjectCreate(GameObject *go, bool add)
if(add) m_gobjects.insert(go);
else m_gobjects.erase(go);
}
//do we need to store building?
else if(go->GetGoType() == GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING)
{
BuildingStateMap::const_iterator itr = m_buildingStates.find(go->GetDBTableGUIDLow());
if(itr != m_buildingStates.end())
itr->second->building = add ? go : NULL;
}
}
void OPvPWintergrasp::UpdateAllWorldObject()
@@ -126,6 +203,31 @@ void OPvPWintergrasp::UpdateAllWorldObject()
UpdateGameObjectInfo(*itr);
for(CreatureSet::iterator itr = m_creatures.begin(); itr != m_creatures.end(); ++itr)
UpdateCreatureInfo(*itr);
for(BuildingStateMap::iterator itr = m_buildingStates.begin(); itr != m_buildingStates.end(); ++itr)
{
if(itr->second->building)
itr->second->building->Rebuild();
itr->second->damageState = DAMAGE_INTACT;
itr->second->team = m_defender == TEAM_ALLIANCE ? OTHER_TEAM(itr->second->defaultTeam) : itr->second->defaultTeam;
}
//if(GameObject *obj = ObjectAccessor::GetObjectInWorld(
SendInitWorldStatesTo();
}
void OPvPWintergrasp::SendInitWorldStatesTo(Player *player)
{
WorldPacket data(SMSG_INIT_WORLD_STATES, (4+4+4+2+(m_buildingStates.size()*8)));
data << uint32(571);
data << uint32(ZONE_WINTERGRASP);
data << uint32(0);
data << uint16(m_buildingStates.size());
for(BuildingStateMap::iterator itr = m_buildingStates.begin(); itr != m_buildingStates.end(); ++itr)
itr->second->FillData(data);
if(player)
player->GetSession()->SendPacket(&data);
else
BroadcastPacket(data);
}
bool OPvPWintergrasp::UpdateCreatureInfo(Creature *creature)
@@ -173,11 +275,7 @@ void OPvPWintergrasp::HandlePlayerEnterZone(Player * plr, uint32 zone)
&& !plr->HasAura(SPELL_LIEUTENANT))
plr->CastSpell(plr, SPELL_RECRUIT, true);
for(AreaPOIList::iterator itr = areaPOIs.begin(); itr != areaPOIs.end(); ++itr)
{
TeamId team = ((*itr)->x > POS_X_CENTER ? m_defender : OTHER_TEAM(m_defender));
plr->SendUpdateWorldState((*itr)->worldState, AreaPOIIconId[team][DAMAGE_INTACT]);
}
SendInitWorldStatesTo(plr);
OutdoorPvP::HandlePlayerEnterZone(plr, zone);
UpdateTenacityStack();
+22 -7
View File
@@ -46,13 +46,26 @@ const uint32 AreaPOIIconId[3][3] = {{7,8,9},{4,5,6},{1,2,3}};
struct BuildingState
{
explicit BuildingState(uint32 _worldState, uint32 _health)
: worldState(_worldState), health(_health), team(TEAM_NEUTRAL), damageState(DAMAGE_INTACT)
explicit BuildingState(uint32 _worldState, TeamId _team, bool asDefault)
: worldState(_worldState), health(0)
, defaultTeam(asDefault ? _team : OTHER_TEAM(_team)), team(_team), damageState(DAMAGE_INTACT)
, building(NULL)
{}
uint32 worldState;
uint32 health;
TeamId team;
TeamId team, defaultTeam;
DamageState damageState;
GameObject *building;
void SendUpdate(Player *player)
{
player->SendUpdateWorldState(worldState, AreaPOIIconId[team][damageState]);
}
void FillData(WorldPacket &data)
{
data << worldState << AreaPOIIconId[team][damageState];
}
};
typedef std::map<uint32, uint32> TeamPairMap;
@@ -60,7 +73,6 @@ typedef std::map<uint32, uint32> TeamPairMap;
class OPvPWintergrasp : public OutdoorPvP
{
protected:
typedef std::list<const AreaPOIEntry *> AreaPOIList;
typedef std::map<uint32, BuildingState *> BuildingStateMap;
typedef std::set<Creature*> CreatureSet;
typedef std::set<GameObject*> GameObjectSet;
@@ -74,16 +86,19 @@ class OPvPWintergrasp : public OutdoorPvP
void OnCreatureCreate(Creature *creature, bool add);
void OnGameObjectCreate(GameObject *go, bool add);
void ProcessEvent(WorldObject *obj, uint32 eventId);
void ProcessEvent(GameObject *obj, uint32 eventId);
void HandlePlayerEnterZone(Player *plr, uint32 zone);
void HandlePlayerLeaveZone(Player *plr, uint32 zone);
void HandleKill(Player *killer, Unit *victim);
void SendInitWorldStatesTo(Player *player = NULL);
protected:
TeamId m_defender;
int32 m_tenacityStack;
AreaPOIList areaPOIs;
BuildingStateMap buildingStates;
BuildingStateMap m_buildingStates;
CreatureSet m_creatures;
GameObjectSet m_gobjects;
+1 -2
View File
@@ -21,7 +21,6 @@
#include "Common.h"
class WorldObject;
class Creature;
class GameObject;
@@ -44,7 +43,7 @@ class TRINITY_DLL_SPEC ZoneScript
virtual uint32 GetData(uint32 /*DataId*/) { return 0; }
virtual void SetData(uint32 /*DataId*/, uint32 /*Value*/) {}
virtual void ProcessEvent(WorldObject *obj, uint32 eventId) {}
virtual void ProcessEvent(GameObject *obj, uint32 eventId) {}
};
#endif