1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/entities/faction/CFaction.cpp
Ivan Savenko 3dd4fa2528 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
2024-10-10 12:28:08 +00:00

131 lines
2.4 KiB
C++

/*
* CFaction.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CFaction.h"
#include "CTown.h"
#include "../../VCMI_Lib.h"
#include "../../texts/CGeneralTextHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
CFaction::~CFaction()
{
if (town)
{
delete town;
town = nullptr;
}
}
int32_t CFaction::getIndex() const
{
return index.getNum();
}
int32_t CFaction::getIconIndex() const
{
return index.getNum(); //???
}
std::string CFaction::getJsonKey() const
{
return modScope + ':' + identifier;
}
std::string CFaction::getModScope() const
{
return modScope;
}
void CFaction::registerIcons(const IconRegistar & cb) const
{
if(town)
{
auto & info = town->clientInfo;
cb(info.icons[0][0], 0, "ITPT", info.iconLarge[0][0]);
cb(info.icons[0][1], 0, "ITPT", info.iconLarge[0][1]);
cb(info.icons[1][0], 0, "ITPT", info.iconLarge[1][0]);
cb(info.icons[1][1], 0, "ITPT", info.iconLarge[1][1]);
cb(info.icons[0][0] + 2, 0, "ITPA", info.iconSmall[0][0]);
cb(info.icons[0][1] + 2, 0, "ITPA", info.iconSmall[0][1]);
cb(info.icons[1][0] + 2, 0, "ITPA", info.iconSmall[1][0]);
cb(info.icons[1][1] + 2, 0, "ITPA", info.iconSmall[1][1]);
cb(index.getNum(), 1, "CPRSMALL", info.towerIconSmall);
cb(index.getNum(), 1, "TWCRPORT", info.towerIconLarge);
}
}
std::string CFaction::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());
}
std::string CFaction::getNameTextID() const
{
return TextIdentifier("faction", modScope, identifier, "name").get();
}
std::string CFaction::getDescriptionTranslated() const
{
return VLC->generaltexth->translate(getDescriptionTextID());
}
std::string CFaction::getDescriptionTextID() const
{
return TextIdentifier("faction", modScope, identifier, "description").get();
}
FactionID CFaction::getId() const
{
return FactionID(index);
}
FactionID CFaction::getFactionID() const
{
return FactionID(index);
}
bool CFaction::hasTown() const
{
return town != nullptr;
}
EAlignment CFaction::getAlignment() const
{
return alignment;
}
BoatId CFaction::getBoatType() const
{
return boatType;
}
TerrainId CFaction::getNativeTerrain() const
{
return nativeTerrain;
}
void CFaction::updateFrom(const JsonNode & data)
{
}
void CFaction::serializeJson(JsonSerializeFormat & handler)
{
}
VCMI_LIB_NAMESPACE_END