diff options
author | XTZGZoReX <none@none> | 2010-08-06 19:23:43 +0200 |
---|---|---|
committer | XTZGZoReX <none@none> | 2010-08-06 19:23:43 +0200 |
commit | 946adf469c14deeaf202cba5378fb5edfd792bd6 (patch) | |
tree | ce27f0aaa34c6cd06fbdf234ec31ff6abc9ce80c /src/server/game/Maps/Map.cpp | |
parent | 2562a4651f94e2dc40ccce108a2497c2c26bfff6 (diff) |
*** New core <-> script library interface - complete rewrite of the old one.
* Removed the misdesigned on_events script/hooks.
* Lots of related cleanups and assertions.
* The interface is now fully object-oriented.
** Scripts no longer use function pointers.
** Scripts no longer use the general-purpose Script struct for everything.
** Script types are split into separate classes which must be inherited depending on what functionality is desired.
* Several script types have been added to allow extending functionality in a code-only manner (some script types require
assignment in the recently added ScriptName columns in the database, though).
** SpellHandlerScript: Wrapper around spell scripts (returns new SpellScript objects (`spell_script_names`.`ScriptName`)).
** ServerScript: Allows scripting events that occur in the network layer.
** WorldScript: Allows scripting certain world-global events.
** FormulaScript: Allows hooking and interfering with core formulas.
** *MapScript: Allows hooking different map types (including world, instance, and battleground maps (`instance_template`.`ScriptName`)).
** ItemScript: Allows scripting of items (like the old interface (`item_template`.`ScriptName`)).
** CreatureScript: Allows scripting of creatures/AI (like the old interface (`creature_template`.`ScriptName`)).
** GameObjectScript: Allows scripting of gameobjects (like the old interface (`gameobject_template`.`ScriptName`)).
** AreaTriggerScript: Allows scripting triggered area triggers (like the old interface (`areatrigger_scripts`.`ScriptName`)).
** OutdoorPvPScript: Script which should return OutdoorPvP objects for use by OutdoorPvPMgr (`outdoorpvp_template`.`ScriptName`).
** CommandScript: Allows extending the in-core command table.
** WeatherScript: Allows scripting of weather changes (`game_weather`.`ScriptName`).
** AuctionHouseScript: Allows scripting of auction events.
** ConditionScript: Allows scripting of conditions (`conditions`.`ScriptName`).
** DynamicObjectScript: Allows scripting of dynamicobjects.
** TransportScript: Allows scripting of transport events (`transports`.`ScriptName`).
* OutdoorPvP objects are now created through scripts. This effectively means that they'll need to be moved to scripts
before the they're functional again.
* The whole idea with this new interface is to allow expanding core functionality without touching core code. If further
hooks are needed to expand functionality of the core, let us know; we'll add them, if we agree that it is appropriate
to do so.
*** NOTE: The scripts project will _not_ build before it has been adapted to the new interface.
*** Thanks to everyone who helped out with related preparations and suggestions!
--HG--
branch : trunk
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r-- | src/server/game/Maps/Map.cpp | 139 |
1 files changed, 16 insertions, 123 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index eed56efd026..6a4e02a9d1b 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -41,7 +41,7 @@ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "GossipDef.h" - +#include "ScriptMgr.h" #include "MapInstanced.h" #include "InstanceSaveMgr.h" #include "VMapFactory.h" @@ -62,6 +62,9 @@ struct ScriptAction Map::~Map() { + if (!Instanceable()) + sScriptMgr.OnDestroyMap(this); + UnloadAll(); while (!i_worldObjects.empty()) @@ -169,6 +172,8 @@ void Map::LoadMap(int gx,int gy, bool reload) sLog.outDetail("Unloading previously loaded map %u before reloading.",GetId()); delete (GridMaps[gx][gy]); GridMaps[gx][gy]=NULL; + + sScriptMgr.OnUnloadGridMap(this, gx, gy); } // map file name @@ -184,6 +189,8 @@ void Map::LoadMap(int gx,int gy, bool reload) sLog.outError("Error loading map file: \n %s\n", tmp); } delete [] tmp; + + sScriptMgr.OnLoadGridMap(this, gx, gy); } void Map::LoadMapAndVMap(int gx,int gy) @@ -229,6 +236,9 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _par //lets initialize visibility distance for map Map::InitVisibilityDistance(); + + if (!Instanceable()) + sScriptMgr.OnCreateMap(this); } void Map::InitVisibilityDistance() @@ -437,6 +447,7 @@ bool Map::Add(Player *player) player->m_clientGUIDs.clear(); player->UpdateObjectVisibility(true); + sScriptMgr.OnPlayerEnter(this, player); return true; } @@ -480,102 +491,6 @@ Map::Add(T *obj) obj->UpdateObjectVisibility(true); } -/* -void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self) -{ - CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) - { - sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); - return; - } - - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - if (!loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y))) - return; - - Trinity::MessageDeliverer post_man(*player, msg, to_self); - TypeContainerVisitor<Trinity::MessageDeliverer, WorldTypeMapContainer > message(post_man); - CellLock<ReadGuard> cell_lock(cell, p); - cell_lock->Visit(cell_lock, message, *this, *player, GetVisibilityDistance()); -} - -void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg) -{ - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) - { - sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); - return; - } - - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - if (!loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y))) - return; - - //TODO: currently on continents when Visibility.Distance.InFlight > Visibility.Distance.Continents - //we have alot of blinking mobs because monster move packet send is broken... - Trinity::ObjectMessageDeliverer post_man(*obj,msg); - TypeContainerVisitor<Trinity::ObjectMessageDeliverer, WorldTypeMapContainer > message(post_man); - CellLock<ReadGuard> cell_lock(cell, p); - cell_lock->Visit(cell_lock, message, *this, *obj, GetVisibilityDistance()); -} - -void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, bool to_self, bool own_team_only) -{ - CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) - { - sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); - return; - } - - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - 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); - TypeContainerVisitor<Trinity::MessageDistDeliverer , WorldTypeMapContainer > message(post_man); - CellLock<ReadGuard> cell_lock(cell, p); - cell_lock->Visit(cell_lock, message, *this, *player, dist); -} - -void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist) -{ - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - - if (p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) - { - sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); - return; - } - - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - if (!loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y))) - return; - - Trinity::ObjectMessageDistDeliverer post_man(*obj, msg, dist); - TypeContainerVisitor<Trinity::ObjectMessageDistDeliverer, WorldTypeMapContainer > message(post_man); - CellLock<ReadGuard> cell_lock(cell, p); - cell_lock->Visit(cell_lock, message, *this, *obj, dist); -} -*/ - bool Map::loaded(const GridPair &p) const { return (getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord)); @@ -704,6 +619,8 @@ void Map::Update(const uint32 &t_diff) if (!m_mapRefManager.isEmpty() || !m_activeNonPlayers.empty()) ProcessRelocationNotifies(t_diff); + + sScriptMgr.OnMapUpdate(this, t_diff); } struct ResetNotifier @@ -821,6 +738,8 @@ void Map::Remove(Player *player, bool remove) if (remove) DeleteFromWorld(player); + + sScriptMgr.OnPlayerLeave(this, player); } template<class T> @@ -1993,32 +1912,6 @@ void Map::UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpai // send data notifier.SendToSelf(); } -/* -void Map::PlayerRelocationNotify(Player* player, Cell cell, CellPair cellpair) -{ - Trinity::PlayerRelocationNotifier relocationNotifier(*player); - cell.data.Part.reserved = ALL_DISTRICT; - - TypeContainerVisitor<Trinity::PlayerRelocationNotifier, GridTypeMapContainer > p2grid_relocation(relocationNotifier); - TypeContainerVisitor<Trinity::PlayerRelocationNotifier, WorldTypeMapContainer > p2world_relocation(relocationNotifier); - - cell.Visit(cellpair, p2grid_relocation, *this, *player, MAX_CREATURE_ATTACK_RADIUS); - cell.Visit(cellpair, p2world_relocation, *this, *player, MAX_CREATURE_ATTACK_RADIUS); -} - -void Map::CreatureRelocationNotify(Creature *creature, Cell cell, CellPair cellpair) -{ - Trinity::CreatureRelocationNotifier relocationNotifier(*creature); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); // not trigger load unloaded grids at notifier call - - TypeContainerVisitor<Trinity::CreatureRelocationNotifier, WorldTypeMapContainer > c2world_relocation(relocationNotifier); - TypeContainerVisitor<Trinity::CreatureRelocationNotifier, GridTypeMapContainer > c2grid_relocation(relocationNotifier); - - cell.Visit(cellpair, c2world_relocation, *this, *creature, MAX_CREATURE_ATTACK_RADIUS); - cell.Visit(cellpair, c2grid_relocation, *this, *creature, MAX_CREATURE_ATTACK_RADIUS); -} -*/ void Map::SendInitSelf(Player * player) { |