Skip to content

Commit 55230ff

Browse files
authored
Merge pull request LandSandBoat#10368 from LandSandBoat/zone_interface
Core: Add WeatherContainer, clean up Zone interface surface
2 parents f3276a2 + 6892d2d commit 55230ff

27 files changed

Lines changed: 301 additions & 175 deletions

src/map/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ set(MAP_CORE_SOURCES
159159
${CMAKE_CURRENT_SOURCE_DIR}/universal_container.h
160160
${CMAKE_CURRENT_SOURCE_DIR}/weapon_skill.cpp
161161
${CMAKE_CURRENT_SOURCE_DIR}/weapon_skill.h
162+
${CMAKE_CURRENT_SOURCE_DIR}/weather_container.cpp
163+
${CMAKE_CURRENT_SOURCE_DIR}/weather_container.h
162164
${CMAKE_CURRENT_SOURCE_DIR}/ximesh/transformation_matrix.h
163165
${CMAKE_CURRENT_SOURCE_DIR}/ximesh/vector3.h
164166
${CMAKE_CURRENT_SOURCE_DIR}/ximesh/ximesh_structs.h

src/map/ai/controllers/mob_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ auto CMobController::DoRoamTick(timer::time_point tick) -> Task<void>
11781178
{
11791179
PMob->PAI->Despawn();
11801180
// Override respawn timer set by CDespawnState for deaggro (60s instead of default)
1181-
PMob->loc.zone->spawnHandler()->registerForRespawn(PMob, 60s);
1181+
PMob->loc.zone->spawnHandler().registerForRespawn(PMob, 60s);
11821182
co_return;
11831183
}
11841184
}

src/map/ai/states/despawn_state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CDespawnState::CDespawnState(CBaseEntity* _PEntity, bool instantDespawn)
3939

4040
if (auto* PMob = dynamic_cast<CMobEntity*>(_PEntity); PMob && PMob->m_AllowRespawn && PMob->loc.zone != nullptr)
4141
{
42-
PMob->loc.zone->spawnHandler()->registerForRespawn(PMob);
42+
PMob->loc.zone->spawnHandler().registerForRespawn(PMob);
4343
}
4444
}
4545

src/map/campaign_system.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ void LoadState()
6565
zoneutils::ForEachZone(
6666
[&state](CZone* PZone)
6767
{
68-
if (PZone->m_CampaignHandler != nullptr)
68+
if (PZone->campaignHandler() != nullptr)
6969
{
70-
uint8 nation = (uint8)(PZone->m_CampaignHandler->GetZoneControl() + 1) * 2;
70+
auto* handler = PZone->campaignHandler();
71+
72+
uint8 nation = (uint8)(handler->GetZoneControl() + 1) * 2;
7173
switch (nation)
7274
{
7375
case CampaignControl::SandoriaMask:
@@ -86,17 +88,17 @@ void LoadState()
8688
}
8789

8890
CampaignRegion region;
89-
region.campaignId = PZone->m_CampaignHandler->GetCampaignId();
90-
region.status = PZone->m_CampaignHandler->GetBattleStatus();
91-
region.heroism = PZone->m_CampaignHandler->GetHeroism();
92-
region.influenceSandoria = PZone->m_CampaignHandler->GetInfluence(CampaignArmy::Sandoria);
93-
region.influenceBastok = PZone->m_CampaignHandler->GetInfluence(CampaignArmy::Bastok);
94-
region.influenceWindurst = PZone->m_CampaignHandler->GetInfluence(CampaignArmy::Windurst);
95-
region.influenceBeastman = PZone->m_CampaignHandler->GetInfluence(CampaignArmy::Orcish);
96-
region.currentFortifications = PZone->m_CampaignHandler->GetFortification();
97-
region.currentResources = PZone->m_CampaignHandler->GetResource();
98-
region.maxFortifications = PZone->m_CampaignHandler->GetMaxFortification();
99-
region.maxResources = PZone->m_CampaignHandler->GetMaxResource();
91+
region.campaignId = handler->GetCampaignId();
92+
region.status = handler->GetBattleStatus();
93+
region.heroism = handler->GetHeroism();
94+
region.influenceSandoria = handler->GetInfluence(CampaignArmy::Sandoria);
95+
region.influenceBastok = handler->GetInfluence(CampaignArmy::Bastok);
96+
region.influenceWindurst = handler->GetInfluence(CampaignArmy::Windurst);
97+
region.influenceBeastman = handler->GetInfluence(CampaignArmy::Orcish);
98+
region.currentFortifications = handler->GetFortification();
99+
region.currentResources = handler->GetResource();
100+
region.maxFortifications = handler->GetMaxFortification();
101+
region.maxResources = handler->GetMaxResource();
100102
region.nationControl = nation;
101103
state.regions.emplace_back(region);
102104
}

src/map/entities/mob_entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ auto CMobEntity::GetEligibleGeodes() const -> std::vector<uint16>
844844
uint8 element = 0;
845845

846846
// Set element by weather
847-
if (const Weather weather = loc.zone->GetWeather(); weather >= Weather::HotSpell && weather <= Weather::Darkness)
847+
if (const Weather weather = loc.zone->weather().current(); weather >= Weather::HotSpell && weather <= Weather::Darkness)
848848
{
849849
/*
850850
element = zoneutils::GetWeatherElement(weather);

src/map/latent_effect_container.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void CLatentEffectContainer::CheckLatentsWeather()
702702
return;
703703
}
704704

705-
CheckLatentsWeather(PZone->GetWeather());
705+
CheckLatentsWeather(PZone->weather().current());
706706
}
707707

708708
void CLatentEffectContainer::CheckLatentsWeather(Weather weather)

src/map/lua/lua_base_entity.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,7 +2631,7 @@ auto CLuaBaseEntity::getWeather(const sol::object& ignoreScholar) const -> uint8
26312631
}
26322632
else
26332633
{
2634-
weather = zoneutils::GetZone(m_PBaseEntity->getZone())->GetWeather();
2634+
weather = zoneutils::GetZone(m_PBaseEntity->getZone())->weather().current();
26352635
}
26362636

26372637
return static_cast<uint8>(weather);
@@ -12266,7 +12266,7 @@ auto CLuaBaseEntity::registerBattlefield(const sol::object& arg0, const sol::obj
1226612266
return BATTLEFIELD_RETURN_CODE_BATTLEFIELD_FULL;
1226712267
}
1226812268

12269-
if (m_PBaseEntity->loc.zone->m_BattlefieldHandler == nullptr)
12269+
if (m_PBaseEntity->loc.zone->battlefieldHandler() == nullptr)
1227012270
{
1227112271
ShowWarning("m_BattlefieldHandler was null for %s.", m_PBaseEntity->getName());
1227212272
return BATTLEFIELD_RETURN_CODE_BATTLEFIELD_FULL;
@@ -12317,7 +12317,7 @@ auto CLuaBaseEntity::registerBattlefield(const sol::object& arg0, const sol::obj
1231712317
registration.rules |= battlefield.get<bool>("canLoseExp") ? RULES_LOSE_EXP : 0;
1231812318
}
1231912319

12320-
return PZone->m_BattlefieldHandler->RegisterBattlefield(PChar, registration);
12320+
return PZone->battlefieldHandler()->RegisterBattlefield(PChar, registration);
1232112321
}
1232212322

1232312323
auto CLuaBaseEntity::battlefieldAtCapacity(const int battlefieldID) const -> bool
@@ -12328,7 +12328,7 @@ auto CLuaBaseEntity::battlefieldAtCapacity(const int battlefieldID) const -> boo
1232812328
return true;
1232912329
}
1233012330

12331-
if (m_PBaseEntity->loc.zone->m_BattlefieldHandler == nullptr)
12331+
if (m_PBaseEntity->loc.zone->battlefieldHandler() == nullptr)
1233212332
{
1233312333
ShowWarning("m_BattlefieldHandler was null for %s.", m_PBaseEntity->getName());
1233412334
return true;
@@ -12343,14 +12343,14 @@ auto CLuaBaseEntity::battlefieldAtCapacity(const int battlefieldID) const -> boo
1234312343
auto* PChar = static_cast<CCharEntity*>(m_PBaseEntity);
1234412344
auto* PZone = PChar->loc.zone == nullptr ? zoneutils::GetZone(PChar->loc.destination) : PChar->loc.zone;
1234512345

12346-
if (!PZone || PZone->m_BattlefieldHandler == nullptr)
12346+
if (!PZone || PZone->battlefieldHandler() == nullptr)
1234712347
{
1234812348
ShowWarning("CLuaBaseEntity::battlefieldAtCapacity() - Battlefield Handler is null.");
1234912349
return true; // NOTE: We were previously breaking here, so return full in this case.
1235012350
}
1235112351

1235212352
bool full = false;
12353-
if (PZone->m_BattlefieldHandler->ReachedMaxCapacity(battlefieldID))
12353+
if (PZone->battlefieldHandler()->ReachedMaxCapacity(battlefieldID))
1235412354
{
1235512355
full = true;
1235612356
}
@@ -12373,7 +12373,7 @@ auto CLuaBaseEntity::enterBattlefield(const sol::object& area) const -> bool
1237312373
return false;
1237412374
}
1237512375

12376-
if (m_PBaseEntity->objtype != TYPE_PC || m_PBaseEntity->loc.zone->m_BattlefieldHandler == nullptr)
12376+
if (m_PBaseEntity->objtype != TYPE_PC || m_PBaseEntity->loc.zone->battlefieldHandler() == nullptr)
1237712377
{
1237812378
ShowWarning("CLuaBaseEntity::enterBattlefield() - Non-PC calling function, or Battlefield Handler is null.");
1237912379
return false;
@@ -12382,11 +12382,11 @@ auto CLuaBaseEntity::enterBattlefield(const sol::object& area) const -> bool
1238212382
CBattlefield* PBattlefield = nullptr;
1238312383
if (area == sol::lua_nil)
1238412384
{
12385-
PBattlefield = m_PBaseEntity->loc.zone->m_BattlefieldHandler->GetBattlefield(m_PBaseEntity, true);
12385+
PBattlefield = m_PBaseEntity->loc.zone->battlefieldHandler()->GetBattlefield(m_PBaseEntity, true);
1238612386
}
1238712387
else
1238812388
{
12389-
PBattlefield = m_PBaseEntity->loc.zone->m_BattlefieldHandler->GetBattlefieldByArea(area.as<uint8>());
12389+
PBattlefield = m_PBaseEntity->loc.zone->battlefieldHandler()->GetBattlefieldByArea(area.as<uint8>());
1239012390
}
1239112391

1239212392
return PBattlefield ? PBattlefield->InsertEntity(m_PBaseEntity, true) : false;
@@ -12407,13 +12407,13 @@ auto CLuaBaseEntity::leaveBattlefield(const uint8 leavecode) const -> bool
1240712407
return false;
1240812408
}
1240912409

12410-
if (m_PBaseEntity->objtype == TYPE_NPC || m_PBaseEntity->loc.zone->m_BattlefieldHandler == nullptr)
12410+
if (m_PBaseEntity->objtype == TYPE_NPC || m_PBaseEntity->loc.zone->battlefieldHandler() == nullptr)
1241112411
{
1241212412
ShowWarning("CLuaBaseEntity::leaveBattlefield() - NPC calling function, or Battlefield Handler is null.");
1241312413
return false;
1241412414
}
1241512415

12416-
return m_PBaseEntity->loc.zone->m_BattlefieldHandler->RemoveFromBattlefield(m_PBaseEntity, m_PBaseEntity->PBattlefield, leavecode);
12416+
return m_PBaseEntity->loc.zone->battlefieldHandler()->RemoveFromBattlefield(m_PBaseEntity, m_PBaseEntity->PBattlefield, leavecode);
1241712417
}
1241812418

1241912419
/************************************************************************
@@ -18009,7 +18009,7 @@ auto CLuaBaseEntity::getRespawnTime() const -> uint32
1800918009

1801018010
if (auto* PMob = static_cast<CMobEntity*>(m_PBaseEntity); PMob->loc.zone)
1801118011
{
18012-
if (const auto remaining = PMob->loc.zone->spawnHandler()->getRemainingRespawnTime(PMob))
18012+
if (const auto remaining = PMob->loc.zone->spawnHandler().getRemainingRespawnTime(PMob))
1801318013
{
1801418014
return static_cast<uint32>(timer::count_seconds(*remaining));
1801518015
}
@@ -18041,7 +18041,7 @@ void CLuaBaseEntity::setRespawnTime(const uint32 seconds) const
1804118041

1804218042
if (PMob->loc.zone != nullptr)
1804318043
{
18044-
PMob->loc.zone->spawnHandler()->unregister(PMob);
18044+
PMob->loc.zone->spawnHandler().unregister(PMob);
1804518045
}
1804618046

1804718047
return;
@@ -18053,7 +18053,7 @@ void CLuaBaseEntity::setRespawnTime(const uint32 seconds) const
1805318053
// If mob is not currently spawned, update its pending respawn time in SpawnHandler
1805418054
if (!PMob->PAI->IsSpawned() && PMob->loc.zone != nullptr)
1805518055
{
18056-
PMob->loc.zone->spawnHandler()->registerForRespawn(PMob, std::chrono::seconds(seconds));
18056+
PMob->loc.zone->spawnHandler().registerForRespawn(PMob, std::chrono::seconds(seconds));
1805718057
}
1805818058
}
1805918059

src/map/lua/lua_battlefield.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void CLuaBattlefield::addGroups(const sol::table& groups, bool hasMultipleArenas
330330

331331
if (!entityIds.empty())
332332
{
333-
uint32 stride = uint32(entityIds.size()) / m_PLuaBattlefield->GetZone()->m_BattlefieldHandler->MaxBattlefieldAreas();
333+
uint32 stride = uint32(entityIds.size()) / m_PLuaBattlefield->GetZone()->battlefieldHandler()->MaxBattlefieldAreas();
334334

335335
// Look to see if there's an Armoury Crate within the group of monsters
336336
static const std::string ARMOURY_CRATE = "Armoury_Crate";

src/map/lua/lua_zone.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ ZONE_TYPE CLuaZone::getTypeMask()
188188

189189
auto CLuaZone::getBattlefieldByInitiator(uint32 charID) -> CBattlefield*
190190
{
191-
if (m_pLuaZone->m_BattlefieldHandler)
191+
if (m_pLuaZone->battlefieldHandler())
192192
{
193-
return m_pLuaZone->m_BattlefieldHandler->GetBattlefieldByInitiator(charID);
193+
return m_pLuaZone->battlefieldHandler()->GetBattlefieldByInitiator(charID);
194194
}
195195
return nullptr;
196196
}
197197

198198
auto CLuaZone::getWeather() const -> Weather
199199
{
200-
return m_pLuaZone->GetWeather();
200+
return m_pLuaZone->weather().current();
201201
}
202202

203203
uint32 CLuaZone::getUptime()

src/map/lua/luautils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,7 @@ void OnMobDisengage(CBaseEntity* PMob)
35893589
return;
35903590
}
35913591

3592-
auto weather = PMob->loc.zone->GetWeather();
3592+
auto weather = PMob->loc.zone->weather().current();
35933593

35943594
auto result = onMobDisengage(PMob, weather);
35953595
if (!result.valid())

0 commit comments

Comments
 (0)