mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Reduce usage of pointers to VLC entities
Final goal (of multiple PR's) is to remove all remaining pointers from serializeable game state, and replace them with either identifiers or with shared/unique pointers. CGTownInstance::town and CGHeroInstance::type members have been removed. Now this data is computed dynamically using subID member. VLC entity of a town can now be accessed via following methods: - getFactionID() returns ID of a faction - getFaction() returns pointer to a faction - getTown() returns pointer to a town VLC entity of a hero can now be accessed via following methods: - getHeroTypeID() returns ID of a hero - getHeroClassID() returns ID of a hero class - getHeroType() returns pointer to a hero - getHeroClass() returns pointer to a hero class
This commit is contained in:
@@ -95,10 +95,10 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town)
|
||||
// 1. Building exists in town (don't attempt to build Lvl 5 guild in Fortress
|
||||
// 2. Building was not built yet
|
||||
// othervice, silently ignore / skip it
|
||||
if (town->town->buildings.count(i) && !town->hasBuilt(i))
|
||||
if (town->getTown()->buildings.count(i) && !town->hasBuilt(i))
|
||||
{
|
||||
gameHandler->buildStructure(town->id, i, true);
|
||||
iw.components.emplace_back(ComponentType::BUILDING, BuildingTypeUniqueID(town->getFaction(), i));
|
||||
iw.components.emplace_back(ComponentType::BUILDING, BuildingTypeUniqueID(town->getFactionID(), i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ SetAvailableCreatures NewTurnProcessor::generateTownGrowth(const CGTownInstance
|
||||
sac.tid = t->id;
|
||||
sac.creatures = t->creatures;
|
||||
|
||||
for (int k=0; k < t->town->creatures.size(); k++)
|
||||
for (int k=0; k < t->getTown()->creatures.size(); k++)
|
||||
{
|
||||
if (t->creatures.at(k).second.empty())
|
||||
continue;
|
||||
@@ -345,7 +345,7 @@ void NewTurnProcessor::updateNeutralTownGarrison(const CGTownInstance * t, int c
|
||||
{
|
||||
const auto * creature = slot.second->type;
|
||||
|
||||
if (creature->getFaction() != t->getFaction())
|
||||
if (creature->getFactionID() != t->getFactionID())
|
||||
continue;
|
||||
|
||||
if (creature->getLevel() != tierToGrow)
|
||||
@@ -518,7 +518,7 @@ std::tuple<EWeekType, CreatureID> NewTurnProcessor::pickWeekType(bool newMonth)
|
||||
{
|
||||
newMonster.second = VLC->creh->pickRandomMonster(gameHandler->getRandomGenerator());
|
||||
} while (VLC->creh->objects[newMonster.second] &&
|
||||
(*VLC->townh)[VLC->creatures()->getById(newMonster.second)->getFaction()]->town == nullptr); // find first non neutral creature
|
||||
(*VLC->townh)[VLC->creatures()->getById(newMonster.second)->getFactionID()]->town == nullptr); // find first non neutral creature
|
||||
|
||||
return { EWeekType::BONUS_GROWTH, newMonster.second};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user