1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Merge branch 'develop' into creature-numeric-quantities

This commit is contained in:
Dydzio
2023-01-21 12:57:29 +01:00
362 changed files with 10853 additions and 5367 deletions

View File

@@ -16,7 +16,6 @@
#include "CGameState.h"
#include "CTownHandler.h"
#include "CModHandler.h"
#include "Terrain.h"
#include "StringConstants.h"
#include "serializer/JsonDeserializer.h"
#include "serializer/JsonUpdater.h"
@@ -47,14 +46,9 @@ int32_t CCreature::getIconIndex() const
return iconIndex;
}
const std::string & CCreature::getName() const
std::string CCreature::getJsonKey() const
{
return nameSing;//???
}
const std::string & CCreature::getJsonKey() const
{
return identifier;
return modScope + ':' + identifier;
}
void CCreature::registerIcons(const IconRegistar & cb) const
@@ -78,16 +72,6 @@ uint32_t CCreature::getMaxHealth() const
return CBonusSystemNode::MaxHealth();
}
const std::string & CCreature::getPluralName() const
{
return namePl;
}
const std::string & CCreature::getSingularName() const
{
return nameSing;
}
int32_t CCreature::getAdvMapAmountMin() const
{
return ammMin;
@@ -184,6 +168,36 @@ int32_t CCreature::getCost(int32_t resIndex) const
return 0;
}
std::string CCreature::getNameTranslated() const
{
return getNameSingularTranslated();
}
std::string CCreature::getNamePluralTranslated() const
{
return VLC->generaltexth->translate(getNamePluralTextID());
}
std::string CCreature::getNameSingularTranslated() const
{
return VLC->generaltexth->translate(getNameSingularTextID());
}
std::string CCreature::getNameTextID() const
{
return getNameSingularTextID();
}
std::string CCreature::getNamePluralTextID() const
{
return TextIdentifier("creatures", modScope, identifier, "name", "plural" ).get();
}
std::string CCreature::getNameSingularTextID() const
{
return TextIdentifier("creatures", modScope, identifier, "name", "singular" ).get();
}
CCreature::CreatureQuantityId CCreature::getQuantityID(const int & quantity)
{
if (quantity<5)
@@ -306,13 +320,13 @@ bool CCreature::valid() const
std::string CCreature::nodeName() const
{
return "\"" + namePl + "\"";
return "\"" + getNamePluralTextID() + "\"";
}
bool CCreature::isItNativeTerrain(TerrainId terrain) const
{
auto native = getNativeTerrain();
return native == terrain || native == Terrain::ANY_TERRAIN;
return native == terrain || native == ETerrainId::ANY_TERRAIN;
}
TerrainId CCreature::getNativeTerrain() const
@@ -323,7 +337,7 @@ TerrainId CCreature::getNativeTerrain() const
//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
//and in the CGHeroInstance::getNativeTerrain() to setup mevement bonuses or/and penalties.
return hasBonus(selectorNoTerrainPenalty, selectorNoTerrainPenalty)
? TerrainId(Terrain::ANY_TERRAIN)
? TerrainId(ETerrainId::ANY_TERRAIN)
: (*VLC->townh)[faction]->nativeTerrain;
}
@@ -369,12 +383,6 @@ void CCreature::updateFrom(const JsonNode & data)
void CCreature::serializeJson(JsonSerializeFormat & handler)
{
{
auto nameNode = handler.enterStruct("name");
handler.serializeString("singular", nameSing);
handler.serializeString("plural", namePl);
}
handler.serializeInt("fightValue", fightValue);
handler.serializeInt("aiValue", AIValue);
handler.serializeInt("growth", growth);
@@ -609,6 +617,9 @@ std::vector<JsonNode> CCreatureHandler::loadLegacyData(size_t dataSize)
CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index)
{
assert(identifier.find(':') == std::string::npos);
assert(!scope.empty());
auto cre = new CCreature();
if(node["hasDoubleWeek"].Bool())
@@ -618,12 +629,16 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
cre->idNumber = CreatureID(index);
cre->iconIndex = cre->getIndex() + 2;
cre->identifier = identifier;
cre->modScope = scope;
JsonDeserializer handler(nullptr, node);
cre->serializeJson(handler);
cre->cost = Res::ResourceSet(node["cost"]);
VLC->generaltexth->registerString(cre->getNameSingularTextID(), node["name"]["singular"].String());
VLC->generaltexth->registerString(cre->getNamePluralTextID(), node["name"]["plural"].String());
cre->addBonus(node["hitPoints"].Integer(), Bonus::STACK_HEALTH);
cre->addBonus(node["speed"].Integer(), Bonus::STACKS_SPEED);
cre->addBonus(node["attack"].Integer(), Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);