aboutsummaryrefslogtreecommitdiff
path: root/src/game/Map.cpp
diff options
context:
space:
mode:
authorgvcoman <none@none>2008-11-05 20:51:05 -0600
committergvcoman <none@none>2008-11-05 20:51:05 -0600
commit44bdb135f4ed5bb834795cfb928ccbb0504cf834 (patch)
tree7995df4957fb2e0e6cde895fbe3e85b7efde5fa7 /src/game/Map.cpp
parent8d331f2b10cff29ee0571f7056ad353df6a3eabd (diff)
[svn] Implemented player on player and player on creature possession:
* Implemented packet and vision forwarding through possessed units * Added new OnPossess script call alerting scripts on when possession is applied/removed * Moved fall damage and fall under map calculations into the Player class * Added new PossessedAI that is applied only while possession on creature is active * Implemented summon possessed spell effect * Fixed Eyes of the Beast --HG-- branch : trunk
Diffstat (limited to 'src/game/Map.cpp')
-rw-r--r--src/game/Map.cpp53
1 files changed, 43 insertions, 10 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index c47d5dd3a64..0d251ee5912 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -255,7 +255,7 @@ template<>
void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell)
{
// add to world object registry in grid
- if(obj->isPet())
+ if(obj->isPet() || obj->isPossessedByPlayer())
{
(*grid)(cell.CellX(), cell.CellY()).AddWorldObject<Creature>(obj, obj->GetGUID());
obj->SetCurrentCell(cell);
@@ -299,7 +299,7 @@ template<>
void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell)
{
// remove from world object registry in grid
- if(obj->isPet())
+ if(obj->isPet() || obj->isPossessedByPlayer())
{
(*grid)(cell.CellX(), cell.CellY()).RemoveWorldObject<Creature>(obj, obj->GetGUID());
}
@@ -311,6 +311,27 @@ void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell)
}
template<class T>
+void Map::SwitchGridContainers(T* obj, bool active)
+{
+ CellPair pair = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
+ Cell cell(pair);
+ NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
+
+ if (active)
+ {
+ (*grid)(cell.CellX(), cell.CellY()).RemoveGridObject<T>(obj, obj->GetGUID());
+ (*grid)(cell.CellX(), cell.CellY()).AddWorldObject<T>(obj, obj->GetGUID());
+ } else
+ {
+ (*grid)(cell.CellX(), cell.CellY()).RemoveWorldObject<T>(obj, obj->GetGUID());
+ (*grid)(cell.CellX(), cell.CellY()).AddGridObject<T>(obj, obj->GetGUID());
+ }
+}
+
+template void Map::SwitchGridContainers(Creature *, bool);
+template void Map::SwitchGridContainers(Corpse *, bool);
+
+template<class T>
void Map::DeleteFromWorld(T* obj)
{
// Note: In case resurrectable corpse and pet its removed from gloabal lists in own destructors
@@ -467,7 +488,7 @@ Map::Add(T *obj)
AddNotifier(obj,cell,p);
}
-void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self)
+void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self, bool to_possessor)
{
CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
@@ -483,13 +504,13 @@ void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self)
if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
return;
- Trinity::MessageDeliverer post_man(*player, msg, to_self);
+ Trinity::MessageDeliverer post_man(*player, msg, to_possessor, to_self);
TypeContainerVisitor<Trinity::MessageDeliverer, WorldTypeMapContainer > message(post_man);
CellLock<ReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, message, *this);
}
-void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg)
+void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg, bool to_possessor)
{
CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
@@ -506,13 +527,13 @@ void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg)
if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
return;
- Trinity::ObjectMessageDeliverer post_man(msg);
+ Trinity::ObjectMessageDeliverer post_man(*obj, msg, to_possessor);
TypeContainerVisitor<Trinity::ObjectMessageDeliverer, WorldTypeMapContainer > message(post_man);
CellLock<ReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, message, *this);
}
-void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, bool to_self, bool own_team_only)
+void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, bool to_self, bool own_team_only, bool to_possessor)
{
CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
@@ -528,13 +549,13 @@ void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, boo
if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
return;
- Trinity::MessageDistDeliverer post_man(*player, msg, dist, to_self, own_team_only);
+ Trinity::MessageDistDeliverer post_man(*player, msg, to_possessor, dist, to_self, own_team_only);
TypeContainerVisitor<Trinity::MessageDistDeliverer , WorldTypeMapContainer > message(post_man);
CellLock<ReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, message, *this);
}
-void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist)
+void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist, bool to_possessor)
{
CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
@@ -551,7 +572,7 @@ void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist)
if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
return;
- Trinity::ObjectMessageDistDeliverer post_man(*obj, msg,dist);
+ Trinity::ObjectMessageDistDeliverer post_man(*obj, msg, to_possessor, dist);
TypeContainerVisitor<Trinity::ObjectMessageDistDeliverer, WorldTypeMapContainer > message(post_man);
CellLock<ReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, message, *this);
@@ -649,6 +670,7 @@ Map::Remove(T *obj, bool remove)
assert( grid != NULL );
obj->RemoveFromWorld();
+
RemoveFromGrid(obj,grid,cell);
UpdateObjectVisibility(obj,cell,p);
@@ -697,6 +719,11 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
// if move then update what player see and who seen
UpdatePlayerVisibility(player,new_cell,new_val);
UpdateObjectsVisibilityFor(player,new_cell,new_val);
+
+ // also update what possessing player sees
+ if(player->isPossessedByPlayer())
+ UpdateObjectsVisibilityFor((Player*)player->GetCharmer(), new_cell, new_val);
+
PlayerRelocationNotify(player,new_cell,new_val);
NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY());
if( !same_cell && newGrid->GetGridState()!= GRID_STATE_ACTIVE )
@@ -725,10 +752,16 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
#endif
AddCreatureToMoveList(creature,x,y,z,ang);
// in diffcell/diffgrid case notifiers called at finishing move creature in Map::MoveAllCreaturesInMoveList
+ if(creature->isPossessedByPlayer())
+ EnsureGridLoadedForPlayer(new_cell, (Player*)creature->GetCharmer(), false);
}
else
{
creature->Relocate(x, y, z, ang);
+ // Update visibility back to player who is controlling the creature
+ if(creature->isPossessedByPlayer())
+ UpdateObjectsVisibilityFor((Player*)creature->GetCharmer(), new_cell, new_val);
+
CreatureRelocationNotify(creature,new_cell,new_val);
}
assert(CheckGridIntegrity(creature,true));