1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 22:17:45 +00:00

Replacement of old ZoneMgr

This commit is contained in:
Mordred 2018-01-27 23:52:49 +01:00
parent 9607bebb05
commit aabcdf6e74
24 changed files with 723 additions and 530 deletions

View file

@ -5,7 +5,8 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
file(GLOB UTILS_PUBLIC_INCLUDE_FILES file(GLOB UTILS_PUBLIC_INCLUDE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/*.h") "${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/Exd/*.h" )
file(GLOB UTILS_SOURCE_FILES file(GLOB UTILS_SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Config/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Config/*.cpp"

View file

@ -162,29 +162,6 @@ namespace Common {
instance, instance,
}; };
enum TerritoryIntendedUseType : uint8_t //ToDo: Add The Rest of The Territory Types and Have Better Names For Them
{
Town = 0,
OpenWorld = 1,
Inn = 2,
Dungeon = 3,
JailArea = 5,
OpeningArea = 6,
BeforeTrialDung = 7,
AllianceRaid = 8,
OpenWorldInstanceBattle = 9,
Trial = 10,
HousingArea = 13,
HousingPrivateArea = 14,
MSQPrivateArea = 15,
Raids = 16,
RaidFights = 17,
ChocoboTutorial = 21,
Wedding = 22,
BeginnerTutorial = 27,
PalaceOfTheDead = 31,
};
enum CharaLook : uint8_t enum CharaLook : uint8_t
{ {
Race = 0x00, Race = 0x00,

View file

@ -89,6 +89,7 @@ bool Core::Data::ExdData::loadZoneInfo()
auto weatherRateFields = weatherRate.get_row( weather_rate ); auto weatherRateFields = weatherRate.get_row( weather_rate );
int32_t aetheryte_index = getField< int32_t >( fields, 23 ); int32_t aetheryte_index = getField< int32_t >( fields, 23 );
uint8_t zoneType = getField< uint8_t >( fields, 9 );
ZoneInfo info{ 0 }; ZoneInfo info{ 0 };
@ -101,6 +102,8 @@ bool Core::Data::ExdData::loadZoneInfo()
info.map_id = map_id; info.map_id = map_id;
info.weather_rate = weather_rate; // TODO: deal with weather groups info.weather_rate = weather_rate; // TODO: deal with weather groups
info.aetheryte_index = aetheryte_index; info.aetheryte_index = aetheryte_index;
info.zone_type = zoneType;
uint8_t sumPc = 0; uint8_t sumPc = 0;
for( size_t i = 0; i < 16; ) for( size_t i = 0; i < 16; )

View file

@ -37,6 +37,7 @@ namespace Core {
std::map< uint8_t, int32_t> weather_rate_map; std::map< uint8_t, int32_t> weather_rate_map;
int32_t aetheryte_index; int32_t aetheryte_index;
uint8_t zone_type;
}; };
struct ClassJobInfo struct ClassJobInfo

View file

@ -3532,6 +3532,7 @@
placeNameZone = exdData->getField< uint16_t >( row, 4 ); placeNameZone = exdData->getField< uint16_t >( row, 4 );
placeName = exdData->getField< uint16_t >( row, 5 ); placeName = exdData->getField< uint16_t >( row, 5 );
map = exdData->getField< uint16_t >( row, 6 ); map = exdData->getField< uint16_t >( row, 6 );
territoryIntendedUse = exdData->getField< uint8_t >( row, 9 );
weatherRate = exdData->getField< uint8_t >( row, 12 ); weatherRate = exdData->getField< uint8_t >( row, 12 );
aetheryte = exdData->getField< int32_t >( row, 23 ); aetheryte = exdData->getField< int32_t >( row, 23 );
} }

@ -1 +1 @@
Subproject commit e58b804be5672cade4c55cd5f5ec60889d817550 Subproject commit bab17595d24c697c6abea881e7849b388c898647

View file

@ -11,7 +11,7 @@
#include "Player.h" #include "Player.h"
#include "BattleNpc.h" #include "BattleNpc.h"
#include "Zone/ZoneMgr.h" #include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "ServerZone.h" #include "ServerZone.h"
@ -43,7 +43,7 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr; extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::Scripting::ScriptManager g_scriptMgr; extern Core::Scripting::ScriptManager g_scriptMgr;
@ -309,7 +309,7 @@ void Core::Entity::Player::teleport( uint16_t aetheryteId, uint8_t type )
setStateFlag( PlayerStateFlag::BetweenAreas ); setStateFlag( PlayerStateFlag::BetweenAreas );
auto z_pos = g_zoneMgr.getZonePosition( data->levelId ); auto z_pos = g_territoryMgr.getTerritoryPosition( data->levelId );
Common::FFXIVARR_POSITION3 pos; Common::FFXIVARR_POSITION3 pos;
pos.x = 0; pos.x = 0;
@ -367,8 +367,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId )
{ {
auto pPlayer = getAsPlayer(); auto pPlayer = getAsPlayer();
auto pZone = g_zoneMgr.getZone( zoneId ); auto pZone = g_territoryMgr.getZoneByTerriId( zoneId );
if( !pZone /*|| ( ( pZone == m_pCurrentZone ) && m_lastPing )*/ ) if( !pZone /*|| ( ( pZone == m_pCurrentZone ) && m_lastPing )*/ )
{ {
@ -437,7 +436,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId )
} }
ZoneChannelPacket< FFXIVIpcInitZone > initZonePacket( getId() ); ZoneChannelPacket< FFXIVIpcInitZone > initZonePacket( getId() );
initZonePacket.data().zoneId = getCurrentZone()->getLayoutId(); initZonePacket.data().zoneId = getCurrentZone()->getTerritoryId();
initZonePacket.data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() ); initZonePacket.data().weatherId = static_cast< uint8_t >( getCurrentZone()->getCurrentWeather() );
initZonePacket.data().bitmask = 0x1; initZonePacket.data().bitmask = 0x1;
initZonePacket.data().unknown5 = 0x2A; initZonePacket.data().unknown5 = 0x2A;
@ -540,7 +539,7 @@ void Core::Entity::Player::discover( int16_t map_id, int16_t sub_id )
int32_t offset = 4; int32_t offset = 4;
auto info = g_exdData.m_zoneInfoMap[getCurrentZone()->getId()]; auto info = g_exdData.m_zoneInfoMap[getCurrentZone()->getTerritoryId()];
if( info.is_two_byte ) if( info.is_two_byte )
offset = 4 + 2 * info.discovery_index; offset = 4 + 2 * info.discovery_index;
else else
@ -1030,7 +1029,7 @@ void Core::Entity::Player::update( int64_t currTime )
if( m_queuedZoneing && ( currTime - m_queuedZoneing->m_queueTime ) > 800 ) if( m_queuedZoneing && ( currTime - m_queuedZoneing->m_queueTime ) > 800 )
{ {
Common::FFXIVARR_POSITION3 targetPos = m_queuedZoneing->m_targetPosition; Common::FFXIVARR_POSITION3 targetPos = m_queuedZoneing->m_targetPosition;
if( getCurrentZone()->getId() != m_queuedZoneing->m_targetZone ) if( getCurrentZone()->getTerritoryId() != m_queuedZoneing->m_targetZone )
{ {
performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation); performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation);
} }

View file

@ -5,7 +5,6 @@
#include "Player.h" #include "Player.h"
#include "Zone/ZoneMgr.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"

View file

@ -16,7 +16,7 @@
#include "Player.h" #include "Player.h"
#include "Zone/ZoneMgr.h" #include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "ServerZone.h" #include "ServerZone.h"
@ -30,7 +30,7 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr; extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
@ -58,7 +58,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
auto zoneId = res->getUInt( "TerritoryId" ); auto zoneId = res->getUInt( "TerritoryId" );
ZonePtr pCurrZone = g_zoneMgr.getZone( zoneId ); ZonePtr pCurrZone = g_territoryMgr.getZoneByTerriId( zoneId );
m_zoneId = zoneId; m_zoneId = zoneId;
// TODO: logic for instances needs to be added here // TODO: logic for instances needs to be added here
@ -70,7 +70,7 @@ bool Core::Entity::Player::load( uint32_t charId, SessionPtr pSession )
// default to new gridania // default to new gridania
// TODO: should probably just abort and mark character as corrupt // TODO: should probably just abort and mark character as corrupt
pCurrZone = g_zoneMgr.getZone( 132 ); pCurrZone = g_territoryMgr.getZoneByTerriId( 132 );
m_pos.x = 0.0f; m_pos.x = 0.0f;
m_pos.y = 0.0f; m_pos.y = 0.0f;

View file

@ -425,7 +425,7 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost:
if( ( subCommand == "pos" ) ) if( ( subCommand == "pos" ) )
{ {
int16_t map_id = g_exdData.m_zoneInfoMap[player.getCurrentZone()->getId()].map_id; int16_t map_id = g_exdData.m_zoneInfoMap[player.getCurrentZone()->getTerritoryId()].map_id;
player.sendNotice( "Pos:\n" + player.sendNotice( "Pos:\n" +
std::to_string( player.getPos().x ) + "\n" + std::to_string( player.getPos().x ) + "\n" +
@ -433,7 +433,7 @@ void Core::DebugCommandHandler::get( char * data, Entity::Player& player, boost:
std::to_string( player.getPos().z ) + "\n" + std::to_string( player.getPos().z ) + "\n" +
std::to_string( player.getRotation() ) + "\nMapId: " + std::to_string( player.getRotation() ) + "\nMapId: " +
std::to_string( map_id ) + "\nZoneID: " + std::to_string( map_id ) + "\nZoneID: " +
std::to_string( player.getCurrentZone()->getId() ) + "\n" ); std::to_string(player.getCurrentZone()->getTerritoryId() ) + "\n" );
} }
else else
{ {

View file

@ -13,7 +13,6 @@
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "Zone/ZonePosition.h" #include "Zone/ZonePosition.h"
#include "ServerZone.h" #include "ServerZone.h"
#include "Zone/ZoneMgr.h"
#include "Network/PacketWrappers/InitUIPacket.h" #include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PingPacket.h"
@ -37,7 +36,6 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::DebugCommandHandler g_gameCommandMgr;

View file

@ -10,10 +10,10 @@
#include "Network/GameConnection.h" #include "Network/GameConnection.h"
#include "Session.h" #include "Session.h"
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "Zone/ZonePosition.h" #include "Zone/ZonePosition.h"
#include "ServerZone.h" #include "ServerZone.h"
#include "Zone/ZoneMgr.h"
#include "Network/PacketWrappers/InitUIPacket.h" #include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PingPacket.h"
@ -37,7 +37,7 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr; extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::DebugCommandHandler g_gameCommandMgr;
@ -403,16 +403,22 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Teri: case GmCommand::Teri:
{ {
auto zoneInfo = g_zoneMgr.getZone( param1 );
if ( !zoneInfo ) if( !g_territoryMgr.isValidTerritory( param1 ) )
{ {
player.sendUrgent( "Invalid zone " + std::to_string( param1 ) ); player.sendUrgent( "Invalid zone " + std::to_string( param1 ) );
} }
else else
{ {
auto pZone = g_territoryMgr.getZoneByTerriId( param1 );
if( !pZone )
{
player.sendUrgent( "No zone instance found for " + std::to_string( param1 ) );
break;
}
targetPlayer->setPosition( targetPlayer->getPos() ); targetPlayer->setPosition( targetPlayer->getPos() );
targetPlayer->performZoning( param1, targetPlayer->getPos(), 0 ); targetPlayer->performZoning( param1, targetPlayer->getPos(), 0 );
player.sendNotice( targetPlayer->getName() + " was warped to zone " + std::to_string( param1 ) + " (" + zoneInfo->getName( ) + ")" ); player.sendNotice( targetPlayer->getName() + " was warped to zone " + std::to_string( param1 ) + " (" + pZone->getName() + ")" );
} }
break; break;
} }

View file

@ -13,7 +13,6 @@
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "Zone/ZonePosition.h" #include "Zone/ZonePosition.h"
#include "ServerZone.h" #include "ServerZone.h"
#include "Zone/ZoneMgr.h"
#include "Network/PacketWrappers/ServerNoticePacket.h" #include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"
@ -27,7 +26,6 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::DebugCommandHandler g_gameCommandMgr;

View file

@ -12,10 +12,10 @@
#include "Network/GameConnection.h" #include "Network/GameConnection.h"
#include "Session.h" #include "Session.h"
#include "ServerZone.h"
#include "Zone/TerritoryMgr.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
#include "Zone/ZonePosition.h" #include "Zone/ZonePosition.h"
#include "ServerZone.h"
#include "Zone/ZoneMgr.h"
#include "Network/PacketWrappers/InitUIPacket.h" #include "Network/PacketWrappers/InitUIPacket.h"
#include "Network/PacketWrappers/PingPacket.h" #include "Network/PacketWrappers/PingPacket.h"
@ -40,7 +40,7 @@
extern Core::Logger g_log; extern Core::Logger g_log;
extern Core::ServerZone g_serverZone; extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr; extern Core::TerritoryMgr g_territoryMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::DebugCommandHandler g_gameCommandMgr;
@ -297,7 +297,7 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket&
auto pZone = player.getCurrentZone(); auto pZone = player.getCurrentZone();
auto pLine = g_zoneMgr.getZonePosition( zoneLineId ); auto pLine = g_territoryMgr.getTerritoryPosition( zoneLineId );
Common::FFXIVARR_POSITION3 targetPos{}; Common::FFXIVARR_POSITION3 targetPos{};
uint32_t targetZone; uint32_t targetZone;
@ -324,7 +324,7 @@ void Core::Network::GameConnection::zoneLineHandler( const Packets::GamePacket&
targetPos.x = 0; targetPos.x = 0;
targetPos.y = 0; targetPos.y = 0;
targetPos.z = 0; targetPos.z = 0;
targetZone = pZone->getId(); targetZone = pZone->getTerritoryId();
} }
player.performZoning( targetZone, targetPos, rotation); player.performZoning( targetZone, targetPos, rotation);
@ -442,7 +442,7 @@ void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket
int32_t entrysizes = sizeof( listPacket.data().entries ); int32_t entrysizes = sizeof( listPacket.data().entries );
memset( listPacket.data().entries, 0, sizeof( listPacket.data().entries ) ); memset( listPacket.data().entries, 0, sizeof( listPacket.data().entries ) );
listPacket.data().entries[0].bytes[2] = player.getCurrentZone()->getId(); listPacket.data().entries[0].bytes[2] = player.getCurrentZone()->getTerritoryId();
listPacket.data().entries[0].bytes[3] = 0x80; listPacket.data().entries[0].bytes[3] = 0x80;
listPacket.data().entries[0].bytes[4] = 0x02; listPacket.data().entries[0].bytes[4] = 0x02;
listPacket.data().entries[0].bytes[6] = 0x3B; listPacket.data().entries[0].bytes[6] = 0x3B;
@ -450,7 +450,7 @@ void Core::Network::GameConnection::socialListHandler( const Packets::GamePacket
listPacket.data().entries[0].classJob = static_cast< uint8_t >( player.getClass() ); listPacket.data().entries[0].classJob = static_cast< uint8_t >( player.getClass() );
listPacket.data().entries[0].contentId = player.getContentId(); listPacket.data().entries[0].contentId = player.getContentId();
listPacket.data().entries[0].level = player.getLevel(); listPacket.data().entries[0].level = player.getLevel();
listPacket.data().entries[0].zoneId = player.getCurrentZone()->getId(); listPacket.data().entries[0].zoneId = player.getCurrentZone()->getTerritoryId();
listPacket.data().entries[0].zoneId1 = 0x0100; listPacket.data().entries[0].zoneId1 = 0x0100;
// TODO: no idea what this does // TODO: no idea what this does
//listPacket.data().entries[0].one = 1; //listPacket.data().entries[0].one = 1;

View file

@ -332,7 +332,7 @@ bool Core::Scripting::ScriptManager::onStatusTimeOut( Entity::ActorPtr pActor, u
bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone ) bool Core::Scripting::ScriptManager::onZoneInit( ZonePtr pZone )
{ {
auto script = m_nativeScriptManager->getScript< ZoneScript >( pZone->getId() ); auto script = m_nativeScriptManager->getScript< ZoneScript >(pZone->getTerritoryId() );
if( script ) if( script )
{ {
script->onZoneInit(); script->onZoneInit();

View file

@ -12,6 +12,7 @@
#include <common/Network/Hive.h> #include <common/Network/Hive.h>
#include <common/Exd/ExdData.h> #include <common/Exd/ExdData.h>
#include <common/Exd/ExdDataGenerated.h>
#include <common/Network/PacketContainer.h> #include <common/Network/PacketContainer.h>
#include <common/Database/DbLoader.h> #include <common/Database/DbLoader.h>
#include <common/Database/CharaDbConnection.h> #include <common/Database/CharaDbConnection.h>
@ -21,7 +22,7 @@
#include "Network/GameConnection.h" #include "Network/GameConnection.h"
#include "Session.h" #include "Session.h"
#include "Zone/ZoneMgr.h" #include "Zone/TerritoryMgr.h"
#include "DebugCommand/DebugCommandHandler.h" #include "DebugCommand/DebugCommandHandler.h"
@ -33,12 +34,14 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <thread> #include <thread>
#include <common/Util/Util.h>
Core::Logger g_log; Core::Logger g_log;
Core::DebugCommandHandler g_gameCommandMgr; Core::DebugCommandHandler g_gameCommandMgr;
Core::Scripting::ScriptManager g_scriptMgr; Core::Scripting::ScriptManager g_scriptMgr;
Core::Data::ExdData g_exdData; Core::Data::ExdData g_exdData;
Core::ZoneMgr g_zoneMgr; Core::Data::ExdDataGenerated g_exdDataGen;
Core::TerritoryMgr g_territoryMgr;
Core::LinkshellMgr g_linkshellMgr; Core::LinkshellMgr g_linkshellMgr;
Core::Db::DbWorkerPool< Core::Db::CharaDbConnection > g_charaDb; Core::Db::DbWorkerPool< Core::Db::CharaDbConnection > g_charaDb;
@ -168,6 +171,13 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
return false; return false;
} }
g_log.info( "Setting up generated EXD data" );
if( !g_exdDataGen.init( m_pConfig->getValue< std::string >( "Settings.General.DataPath", "" ) ) )
{
g_log.fatal( "Error setting up generated EXD data " );
return false;
}
Core::Db::DbLoader loader; Core::Db::DbLoader loader;
Core::Db::ConnectionInfo info; Core::Db::ConnectionInfo info;
@ -224,8 +234,8 @@ void Core::ServerZone::run( int32_t argc, char* argv[] )
g_scriptMgr.init(); g_scriptMgr.init();
g_log.info( "ZoneMgr: Setting up zones" ); g_log.info( "TerritoryMgr: Setting up zones" );
g_zoneMgr.createZones(); g_territoryMgr.init();
std::vector< std::thread > thread_list; std::vector< std::thread > thread_list;
thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) );
@ -258,12 +268,13 @@ void Core::ServerZone::mainLoop()
{ {
this_thread::sleep_for( chrono::milliseconds( 50 ) ); this_thread::sleep_for( chrono::milliseconds( 50 ) );
g_zoneMgr.updateZones();
auto currTime = static_cast< uint32_t >( Util::getTimeSeconds() );
g_territoryMgr.updateTerritoryInstances( currTime );
g_scriptMgr.update(); g_scriptMgr.update();
auto currTime = static_cast< uint32_t >( time( nullptr ) );
lock_guard< std::mutex > lock( this->m_sessionMutex ); lock_guard< std::mutex > lock( this->m_sessionMutex );
for( auto sessionIt : this->m_sessionMapById ) for( auto sessionIt : this->m_sessionMapById )
{ {

View file

@ -0,0 +1,201 @@
#include "TerritoryMgr.h"
#include <common/Logging/Logger.h>
#include <common/Database/DatabaseDef.h>
#include <common/Exd/ExdDataGenerated.h>
#include "Zone.h"
#include "ZonePosition.h"
extern Core::Logger g_log;
extern Core::Data::ExdData g_exdData;
extern Core::Data::ExdDataGenerated g_exdDataGen;
Core::TerritoryMgr::TerritoryMgr() :
m_lastInstanceId( 10000 )
{
}
void Core::TerritoryMgr::loadTerritoryTypeDetailCache()
{
auto idList = g_exdDataGen.getTerritoryTypeIdList();
for( auto id : idList )
{
auto teri1 = g_exdDataGen.getTerritoryType( id );
if( !teri1->name.empty() )
m_territoryTypeDetailCacheMap[id] = teri1;
}
}
bool Core::TerritoryMgr::isValidTerritory( uint32_t territoryTypeId ) const
{
return !( m_territoryTypeDetailCacheMap.find( territoryTypeId ) == m_territoryTypeDetailCacheMap.end() );
}
bool Core::TerritoryMgr::init()
{
loadTerritoryTypeDetailCache();
loadTerritoryPositionMap();
createDefaultTerritories();
return true;
}
uint32_t Core::TerritoryMgr::getNextInstanceId()
{
return ++m_lastInstanceId;
}
Core::Data::TerritoryTypePtr Core::TerritoryMgr::getTerritoryDetail( uint32_t territoryTypeId ) const
{
auto tIt = m_territoryTypeDetailCacheMap.find( territoryTypeId );
if( tIt == m_territoryTypeDetailCacheMap.end() )
return nullptr;
return tIt->second;
}
bool Core::TerritoryMgr::isInstanceContentTerritory( uint32_t territoryTypeId ) const
{
auto pTeri = getTerritoryDetail( territoryTypeId );
if( !pTeri )
return false;
if ( territoryTypeId == 359 )
{
// return false;
}
return pTeri->territoryIntendedUse == TerritoryIntendedUse::AllianceRaid ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::BeforeTrialDung ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::Trial ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::Dungeon ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::OpenWorldInstanceBattle ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::PalaceOfTheDead ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::RaidFights ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::Raids;
}
bool Core::TerritoryMgr::isPrivateTerritory( uint32_t territoryTypeId ) const
{
auto pTeri = getTerritoryDetail( territoryTypeId );
if( !pTeri )
return false;
return pTeri->territoryIntendedUse == TerritoryIntendedUse::OpeningArea ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::Inn ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::HousingPrivateArea ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::JailArea ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::MSQPrivateArea;
}
bool Core::TerritoryMgr::createDefaultTerritories()
{
// for each entry in territoryTypeExd, check if it is a normal and if so, add the zone object
for( const auto& territory : m_territoryTypeDetailCacheMap )
{
auto territoryId = territory.first;
auto territoryInfo = territory.second;
// if the zone has no name set
if( territoryInfo->name.empty() )
continue;
auto pPlaceName = g_exdDataGen.getPlaceName( territoryInfo->placeName );
if( !pPlaceName || pPlaceName->name.empty() || !isDefaultTerritory( territoryId ) )
continue;
uint32_t guid = getNextInstanceId();
g_log.Log( LoggingSeverity::info, std::to_string( territoryId ) +
"\t" + std::to_string( guid ) +
"\t" + std::to_string( territoryInfo->territoryIntendedUse ) +
"\t" + territoryInfo->name +
"\t" + pPlaceName->name );
ZonePtr pZone( new Zone( territoryId, guid, territoryInfo->name, pPlaceName->name, false ) );
pZone->init();
InstanceIdToZonePtrMap instanceMap;
instanceMap[guid] = pZone;
m_territoryInstanceMap[territoryId] = instanceMap;
}
return true;
}
void Core::TerritoryMgr::loadTerritoryPositionMap()
{
auto pQR = g_charaDb.query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" );
while( pQR->next() )
{
uint32_t id = pQR->getUInt( 1 );
uint32_t targetZoneId = pQR->getUInt( 2 );
Common::FFXIVARR_POSITION3 pos{};
pos.x = pQR->getFloat( 3 );
pos.y = pQR->getFloat( 4 );
pos.z = pQR->getFloat( 5 );
float posO = pQR->getFloat( 6 );
uint32_t radius = pQR->getUInt( 7 );
m_territoryPositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) );
}
}
bool Core::TerritoryMgr::isDefaultTerritory( uint32_t territoryTypeId ) const
{
auto pTeri = getTerritoryDetail( territoryTypeId );
if( !pTeri )
return false;
return pTeri->territoryIntendedUse == TerritoryIntendedUse::Inn ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::Town ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::OpenWorld ||
pTeri->territoryIntendedUse == TerritoryIntendedUse::OpeningArea;
}
Core::ZonePositionPtr Core::TerritoryMgr::getTerritoryPosition( uint32_t territoryPositionId ) const
{
auto it = m_territoryPositionMap.find( territoryPositionId );
if( it != m_territoryPositionMap.end() )
return it->second;
return nullptr;
}
Core::ZonePtr Core::TerritoryMgr::getZoneByTerriId( uint32_t territoryId ) const
{
auto zoneMap = m_territoryInstanceMap.find( territoryId );
if( zoneMap == m_territoryInstanceMap.end() )
return nullptr;
// TODO: actually select the proper one
return zoneMap->second.begin()->second;
return nullptr;
}
void Core::TerritoryMgr::updateTerritoryInstances( uint32_t currentTime )
{
for( auto zoneMap : m_territoryInstanceMap )
{
for( auto zone : zoneMap.second )
zone.second->runZoneLogic( currentTime );
}
}

View file

@ -0,0 +1,133 @@
#ifndef SAPPHIRE_TERRITORYMGR_H
#define SAPPHIRE_TERRITORYMGR_H
#include <common/Exd/ExdData.h>
#include "Forwards.h"
namespace Core
{
namespace Data
{
// TODO: this should actually not be here but should be generated in exdData aswell
struct PlaceName;
struct TerritoryType;
struct InstanceContent;
using PlaceNamePtr = boost::shared_ptr< PlaceName >;
using TerritoryTypePtr = boost::shared_ptr< TerritoryType >;
using InstanceContentPtr = boost::shared_ptr< InstanceContent >;
}
/*!
\class TerritoryMgr_c
\brief A class managing zones
This class manages persistent and temporary instances alike.
*/
class TerritoryMgr
{
public:
enum TerritoryIntendedUse : uint8_t //ToDo: Add The Rest of The Territory Types and Have Better Names For Them
{
Town = 0,
OpenWorld = 1,
Inn = 2,
Dungeon = 3,
JailArea = 5,
OpeningArea = 6,
BeforeTrialDung = 7,
AllianceRaid = 8,
OpenWorldInstanceBattle = 9,
Trial = 10,
HousingArea = 13,
HousingPrivateArea = 14,
MSQPrivateArea = 15,
Raids = 16,
RaidFights = 17,
ChocoboTutorial = 21,
Wedding = 22,
BeginnerTutorial = 27,
PalaceOfTheDead = 31,
};
TerritoryMgr();
/*! initializes the territoryMgr */
bool init();
bool createDefaultTerritories();
/*! caches TerritoryType details into m_territoryTypeMap */
void loadTerritoryTypeDetailCache();
/*! List of positions for zonelines */
void loadTerritoryPositionMap();
/*! returns true if the given territoryTypeId is in fact a valid zone
based on informations in the dats ( checks if an entry in the dats exists trhough cache ) */
bool isValidTerritory( uint32_t territoryTypeId ) const;
/*! returns the next available instanceId */
uint32_t getNextInstanceId();
/*! returns true if the territoryType in question is not a persistant zone */
bool isInstanceContentTerritory( uint32_t territoryTypeId ) const;
/*! returns true if the territoryType in question is not a private zone */
bool isPrivateTerritory( uint32_t territoryTypeId ) const;
/*! returns true if the territyTyoe is a default-non instanced zone */
bool isDefaultTerritory( uint32_t territoryTypeId ) const;
/*! creates a new instance for a given territoryTypeId */
ZonePtr createTerritoryInstance( uint32_t territoryTypeId );
/*! removes instance by instanceId, return true if successful */
bool removeTerritoryInstance( uint32_t territoryTypeId );
/*! returns the cached detail of a territory, nullptr if not found */
Data::TerritoryTypePtr getTerritoryDetail( uint32_t territoryTypeId ) const;
/*! loop for processing territory logic, iterating all existing instances */
void updateTerritoryInstances( uint32_t currentTime );
/*! pushes a new instances onto the handling map */
bool addInstance( ZonePtr pInstance );
/*! returns a ZonePtr to the instance or nullptr if not found */
ZonePtr getInstance( uint32_t instanceId ) const;
/*! returns a ZonePositionPtr if found, else nullptr */
ZonePositionPtr getTerritoryPosition( uint32_t territoryPositionId ) const;
/*! returns a default Zone by territoryId
TODO: Mind multiple instances?! */
ZonePtr getZoneByTerriId( uint32_t territoryId ) const;
private:
using TerritoryTypeDetailCache = std::unordered_map< uint16_t, Data::TerritoryTypePtr >;
using InstanceIdToZonePtrMap = std::unordered_map< uint32_t, ZonePtr >;
using TerritoryIdToInstanceMap = std::unordered_map< uint16_t, InstanceIdToZonePtrMap >;
using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >;
/*! map holding details for territory templates */
TerritoryTypeDetailCache m_territoryTypeDetailCacheMap;
/*! map holding actual instances of territories */
TerritoryIdToInstanceMap m_territoryInstanceMap;
/*! map holding positions for zonelines */
PositionMap m_territoryPositionMap;
/*! internal counter for instanceIds
TODO: it should be ensured that this does not overflow if the server runs for a loooong time
( as if that will ever happen ;) ) */
uint32_t m_lastInstanceId;
};
}
#endif // SAPPHIRE_TERRITORYMGR_H

View file

@ -13,7 +13,7 @@
#include <common/Database/DatabaseDef.h> #include <common/Database/DatabaseDef.h>
#include "Zone.h" #include "Zone.h"
#include "ZoneMgr.h" #include "TerritoryMgr.h"
#include "Session.h" #include "Session.h"
#include "Actor/Actor.h" #include "Actor/Actor.h"
@ -41,8 +41,8 @@ namespace Core {
* \brief * \brief
*/ */
Zone::Zone() Zone::Zone()
: m_zoneId( 0 ) : m_territoryId( 0 )
, m_layoutId( 0 ) , m_guId( 0 )
, m_bPrivate( false ) , m_bPrivate( false )
, m_type( Common::RegionType::normal ) , m_type( Common::RegionType::normal )
, m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) , m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) )
@ -51,15 +51,15 @@ Zone::Zone()
{ {
} }
Zone::Zone( uint16_t zoneId, uint32_t layoutId, std::string name, std::string interName, bool bPrivate = false ) Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName, bool bPrivate = false )
: m_type( Common::RegionType::normal ) : m_type( Common::RegionType::normal )
, m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) , m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) )
{ {
m_layoutId = layoutId; m_guId = guId;
m_zoneId = zoneId; m_territoryId = territoryId;
m_zoneCode = name; m_internalName = internalName;
m_zoneName = interName; m_placeName = placeName;
m_bPrivate = bPrivate; m_bPrivate = bPrivate;
m_lastMobUpdate = 0; m_lastMobUpdate = 0;
@ -150,7 +150,7 @@ void Zone::loadCellCache()
"Look," "Look,"
"Models," "Models,"
"type " "type "
"FROM battlenpc WHERE ZoneId = " + std::to_string( getId() ) + ";" ); "FROM battlenpc WHERE ZoneId = " + std::to_string(getTerritoryId() ) + ";" );
std::vector< Entity::BattleNpcPtr > cache; std::vector< Entity::BattleNpcPtr > cache;
@ -175,10 +175,7 @@ void Zone::loadCellCache()
uint32_t modelId = pQR->getUInt( 17 ); uint32_t modelId = pQR->getUInt( 17 );
uint32_t type = pQR->getUInt( 18 ); uint32_t type = pQR->getUInt( 18 );
Common::FFXIVARR_POSITION3 pos; Common::FFXIVARR_POSITION3 pos{ posX, posY, posZ };
pos.x = posX;
pos.y = posY;
pos.z = posZ;
Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( modelId, nameId, pos, Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( modelId, nameId, pos,
sizeId, type, level, behaviour, mobType ) ); sizeId, type, level, behaviour, mobType ) );
pBNpc->setRotation( static_cast< float >( rotation ) ); pBNpc->setRotation( static_cast< float >( rotation ) );
@ -190,8 +187,8 @@ void Zone::loadCellCache()
for( auto entry : cache ) for( auto entry : cache )
{ {
// get cell position // get cell position
uint32_t cellX = CellHandler< ZoneMgr >::getPosX( entry->getPos().x ); uint32_t cellX = CellHandler< TerritoryMgr >::getPosX( entry->getPos().x );
uint32_t cellY = CellHandler< ZoneMgr >::getPosY( entry->getPos().z ); uint32_t cellY = CellHandler< TerritoryMgr >::getPosY( entry->getPos().z );
// find the right cell, create it if not existing yet // find the right cell, create it if not existing yet
if( m_pCellCache[cellX] == nullptr ) if( m_pCellCache[cellX] == nullptr )
@ -211,9 +208,9 @@ void Zone::loadCellCache()
uint8_t Zone::getNextWeather() uint8_t Zone::getNextWeather()
{ {
auto zoneInfo = g_exdData.m_zoneInfoMap[ getLayoutId() ]; auto zoneInfo = g_exdData.m_zoneInfoMap[getGuId() ];
uint32_t unixTime = static_cast< uint32_t >( time( nullptr ) ); uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() );
// Get Eorzea hour for weather start // Get Eorzea hour for weather start
uint32_t bell = unixTime / 175; uint32_t bell = unixTime / 175;
// Do the magic 'cause for calculations 16:00 is 0, 00:00 is 8 and 08:00 is 16 // Do the magic 'cause for calculations 16:00 is 0, 00:00 is 8 and 08:00 is 16
@ -227,12 +224,12 @@ uint8_t Zone::getNextWeather()
uint32_t step1 = ( calcBase << 0xB ) ^ calcBase; uint32_t step1 = ( calcBase << 0xB ) ^ calcBase;
uint32_t step2 = ( step1 >> 8 ) ^ step1; uint32_t step2 = ( step1 >> 8 ) ^ step1;
uint8_t rate = static_cast< uint8_t >(step2 % 0x64); auto rate = static_cast< uint8_t >( step2 % 0x64 );
for( auto entry : zoneInfo.weather_rate_map ) for( auto entry : zoneInfo.weather_rate_map )
{ {
uint8_t sRate = entry.first; uint8_t sRate = entry.first;
int32_t weatherId = entry.second; auto weatherId = static_cast< uint8_t >( entry.second );
if( rate <= sRate ) if( rate <= sRate )
return weatherId; return weatherId;
@ -280,7 +277,7 @@ void Zone::pushActor( Entity::ActorPtr pActor )
if( pActor->isPlayer() ) if( pActor->isPlayer() )
{ {
g_log.debug( "[Zone:" + m_zoneCode + "] Adding player [" + std::to_string( pActor->getId() ) + "]" ); g_log.debug( "[Zone:" + m_internalName + "] Adding player [" + std::to_string( pActor->getId() ) + "]" );
auto pPlayer = pActor->getAsPlayer(); auto pPlayer = pActor->getAsPlayer();
auto pSession = g_serverZone.getSession( pPlayer->getId() ); auto pSession = g_serverZone.getSession( pPlayer->getId() );
@ -313,7 +310,7 @@ void Zone::removeActor( Entity::ActorPtr pActor )
if( pActor->isPlayer() ) if( pActor->isPlayer() )
{ {
g_log.debug( "[Zone:" + m_zoneCode + "] Removing player [" + std::to_string( pActor->getId() ) + "]" ); g_log.debug( "[Zone:" + m_internalName + "] Removing player [" + std::to_string( pActor->getId() ) + "]" );
// If it's a player and he's inside boundaries - update his nearby cells // If it's a player and he's inside boundaries - update his nearby cells
if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX && if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX &&
pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY ) pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY )
@ -365,9 +362,9 @@ void Zone::queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range,
} }
} }
uint32_t Zone::getId() uint32_t Zone::getTerritoryId()
{ {
return m_zoneId; return m_territoryId;
} }
Common::RegionType Zone::getType() const Common::RegionType Zone::getType() const
@ -375,9 +372,9 @@ Common::RegionType Zone::getType() const
return m_type; return m_type;
} }
uint16_t Zone::getLayoutId() const uint16_t Zone::getGuId() const
{ {
return m_layoutId; return m_guId;
} }
bool Zone::isInstance() const bool Zone::isInstance() const
@ -387,12 +384,12 @@ bool Zone::isInstance() const
const std::string& Zone::getName() const const std::string& Zone::getName() const
{ {
return m_zoneName; return m_placeName;
} }
const std::string& Zone::getInternalName() const const std::string& Zone::getInternalName() const
{ {
return m_zoneCode; return m_internalName;
} }
std::size_t Zone::getPopCount() const std::size_t Zone::getPopCount() const
@ -407,7 +404,7 @@ bool Zone::checkWeather()
if ( m_weatherOverride != m_currentWeather ) if ( m_weatherOverride != m_currentWeather )
{ {
m_currentWeather = m_weatherOverride; m_currentWeather = m_weatherOverride;
g_log.debug( "[Zone:" + m_zoneCode + "] overriding weather to : " + std::to_string( m_weatherOverride ) ); g_log.debug( "[Zone:" + m_internalName + "] overriding weather to : " + std::to_string( m_weatherOverride ) );
return true; return true;
} }
} }
@ -417,7 +414,7 @@ bool Zone::checkWeather()
if ( nextWeather != m_currentWeather ) if ( nextWeather != m_currentWeather )
{ {
m_currentWeather = nextWeather; m_currentWeather = nextWeather;
g_log.debug( "[Zone:" + m_zoneCode + "] changing weather to : " + std::to_string( nextWeather ) ); g_log.debug( "[Zone:" + m_internalName + "] changing weather to : " + std::to_string( nextWeather ) );
return true; return true;
} }
} }
@ -472,7 +469,7 @@ void Zone::updateBnpcs( int64_t tickCount )
} }
} }
bool Zone::runZoneLogic() bool Zone::runZoneLogic( uint32_t currTime )
{ {
int64_t tickCount = Util::getTimeMs(); int64_t tickCount = Util::getTimeMs();
@ -495,7 +492,7 @@ bool Zone::runZoneLogic()
// this session is not linked to this area anymore, remove it from zone session list // this session is not linked to this area anymore, remove it from zone session list
if( ( !pSession->getPlayer()->getCurrentZone() ) || ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) ) if( ( !pSession->getPlayer()->getCurrentZone() ) || ( pSession->getPlayer()->getCurrentZone() != shared_from_this() ) )
{ {
g_log.debug( "[Zone:" + m_zoneCode + "] removing session " + std::to_string( pSession->getId() ) ); g_log.debug( "[Zone:" + m_internalName + "] removing session " + std::to_string( pSession->getId() ) );
if( pSession->getPlayer()->getCell() ) if( pSession->getPlayer()->getCell() )
removeActor( pSession->getPlayer() ); removeActor( pSession->getPlayer() );

View file

@ -15,26 +15,21 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
namespace Core { namespace Core {
namespace Entity
{
class Actor;
class Player;
}
class Session; class Session;
class ZonePosition; class ZonePosition;
typedef std::set< SessionPtr > SessionSet; using SessionSet = std::set< SessionPtr >;
class Zone : public CellHandler< Cell >, public boost::enable_shared_from_this< Zone > class Zone : public CellHandler< Cell >, public boost::enable_shared_from_this< Zone >
{ {
protected: protected:
uint32_t m_zoneId; uint32_t m_territoryId;
uint32_t m_layoutId; uint32_t m_guId;
std::string m_zoneName; std::string m_placeName;
std::string m_zoneCode; std::string m_internalName;
bool m_bPrivate; bool m_bPrivate;
@ -57,7 +52,7 @@ protected:
public: public:
Zone(); Zone();
Zone( uint16_t zoneId, uint32_t layoutId, std::string name, std::string interName, bool bPrivate ); Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName, bool bPrivate );
virtual ~Zone(); virtual ~Zone();
bool init(); bool init();
@ -91,11 +86,11 @@ public:
void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry ); void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry );
virtual uint32_t getId(); virtual uint32_t getTerritoryId();
Common::RegionType getType() const; Common::RegionType getType() const;
uint16_t getLayoutId() const; uint16_t getGuId() const;
bool isInstance() const; bool isInstance() const;
@ -107,7 +102,7 @@ public:
bool checkWeather(); bool checkWeather();
void updateBnpcs( int64_t tickCount ); void updateBnpcs( int64_t tickCount );
bool runZoneLogic(); bool runZoneLogic( uint32_t currTime );
}; };

View file

@ -1,89 +0,0 @@
#include <common/Logging/Logger.h>
#include <common/Exd/ExdData.h>
#include <common/Database/DatabaseDef.h>
#include <boost/lexical_cast.hpp>
#include "ZoneMgr.h"
#include "Zone.h"
#include "ZonePosition.h"
extern Core::Logger g_log;
extern Core::Data::ExdData g_exdData;
namespace Core {
ZoneMgr::ZoneMgr() = default;
ZoneMgr::~ZoneMgr() = default;
void ZoneMgr::loadZonePositionMap()
{
auto pQR = g_charaDb.query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" );
while( pQR->next() )
{
uint32_t id = pQR->getUInt( 1 );
uint32_t targetZoneId = pQR->getUInt( 2 );
Common::FFXIVARR_POSITION3 pos;
pos.x = pQR->getFloat( 3 );
pos.y = pQR->getFloat( 4 );
pos.z = pQR->getFloat( 5 );
float posO = pQR->getFloat( 6 );
uint32_t radius = pQR->getUInt( 7 );
m_zonePositionMap[id] = ZonePositionPtr( new ZonePosition( id, targetZoneId, pos, radius, posO ) );
}
}
ZonePositionPtr ZoneMgr::getZonePosition( uint32_t zonePositionId )
{
auto it = m_zonePositionMap.find( zonePositionId );
if( it != m_zonePositionMap.end() )
return it->second;
return nullptr;
}
bool ZoneMgr::createZones()
{
loadZonePositionMap();
// find zone info from exd
for( auto zone : g_exdData.m_zoneInfoMap )
{
uint32_t zoneId = zone.first;
auto info = zone.second;
g_log.Log( LoggingSeverity::info, std::to_string( info.id ) + "\t" + info.zone_str );
ZonePtr pZone( new Zone( info.id, info.layout_id, info.zone_name, info.zone_str, false ) );
pZone->init();
m_zoneMap[info.id] = pZone;
}
return true;
}
void ZoneMgr::updateZones()
{
for( auto zone : m_zoneMap )
{
zone.second->runZoneLogic();
}
}
ZonePtr ZoneMgr::getZone( uint32_t zoneId )
{
ZoneMap::iterator it;
it = m_zoneMap.find( zoneId );
if( it != m_zoneMap.end() )
return it->second;
return nullptr;
}
}

View file

@ -1,39 +0,0 @@
#ifndef _ZONEMGR_H
#define _ZONEMGR_H
#include <unordered_map>
#include <map>
#include "Forwards.h"
namespace Core {
using ZoneMap = std::unordered_map< uint32_t, ZonePtr >;
class ZoneMgr
{
public:
ZoneMgr();
~ZoneMgr();
bool createZones();
ZonePtr getZone( uint32_t zoneId );
void loadZonePositionMap();
ZonePositionPtr getZonePosition( uint32_t zonePositionId );
void updateZones();
private:
ZoneMap m_zoneMap;
std::unordered_map<int32_t, ZonePositionPtr > m_zonePositionMap;
};
}
#endif

View file

@ -9,7 +9,7 @@
#include <iostream> #include <iostream>
#include <cctype> #include <cctype>
#include <set> #include <set>
#include "ExdDataGenerated.h" #include <common/Exd/ExdDataGenerated.h>
#include <common/Logging/Logger.h> #include <common/Logging/Logger.h>
#include <boost/range/algorithm/remove_if.hpp> #include <boost/range/algorithm/remove_if.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>