2023-05-23 14:07:44 +02:00
|
|
|
/*
|
|
|
|
* MapIdentifiersH3M.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 "MapIdentifiersH3M.h"
|
|
|
|
|
|
|
|
#include "../VCMI_Lib.h"
|
2023-06-20 14:09:42 +02:00
|
|
|
#include "../CHeroHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../entities/faction/CFaction.h"
|
|
|
|
#include "../entities/faction/CTownHandler.h"
|
2023-05-24 21:02:27 +02:00
|
|
|
#include "../filesystem/Filesystem.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
|
|
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
|
|
|
#include "../mapObjects/ObjectTemplate.h"
|
2023-07-30 19:12:25 +02:00
|
|
|
#include "../modding/IdentifierStorage.h"
|
2023-05-23 14:07:44 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-05-23 22:55:18 +02:00
|
|
|
template<typename IdentifierID>
|
2023-05-25 23:38:00 +02:00
|
|
|
void MapIdentifiersH3M::loadMapping(std::map<IdentifierID, IdentifierID> & result, const JsonNode & mapping, const std::string & identifierName)
|
2023-05-23 14:07:44 +02:00
|
|
|
{
|
2023-05-23 22:55:18 +02:00
|
|
|
for (auto entry : mapping.Struct())
|
2023-05-23 14:07:44 +02:00
|
|
|
{
|
2023-05-23 22:55:18 +02:00
|
|
|
IdentifierID sourceID (entry.second.Integer());
|
2024-02-13 14:34:16 +02:00
|
|
|
IdentifierID targetID (*VLC->identifiers()->getIdentifier(entry.second.getModScope(), identifierName, entry.first));
|
2023-05-23 14:07:44 +02:00
|
|
|
|
2023-05-23 22:55:18 +02:00
|
|
|
result[sourceID] = targetID;
|
2023-05-23 14:07:44 +02:00
|
|
|
}
|
2023-05-23 22:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
|
|
|
|
{
|
2023-11-17 16:19:07 +02:00
|
|
|
if (!mapping["supported"].Bool())
|
|
|
|
throw std::runtime_error("Unsupported map format!");
|
|
|
|
|
2023-05-23 14:07:44 +02:00
|
|
|
for (auto entryFaction : mapping["buildings"].Struct())
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
FactionID factionID (*VLC->identifiers()->getIdentifier(entryFaction.second.getModScope(), "faction", entryFaction.first));
|
2023-05-23 14:07:44 +02:00
|
|
|
auto buildingMap = entryFaction.second;
|
|
|
|
|
|
|
|
for (auto entryBuilding : buildingMap.Struct())
|
|
|
|
{
|
|
|
|
BuildingID sourceID (entryBuilding.second.Integer());
|
2024-02-13 14:34:16 +02:00
|
|
|
BuildingID targetID (*VLC->identifiers()->getIdentifier(entryBuilding.second.getModScope(), "building." + VLC->factions()->getById(factionID)->getJsonKey(), entryBuilding.first));
|
2023-05-23 14:07:44 +02:00
|
|
|
|
|
|
|
mappingFactionBuilding[factionID][sourceID] = targetID;
|
|
|
|
}
|
|
|
|
}
|
2023-05-23 22:55:18 +02:00
|
|
|
|
2023-05-24 21:02:27 +02:00
|
|
|
for (auto entryTemplate : mapping["templates"].Struct())
|
|
|
|
{
|
2023-09-20 20:59:16 +02:00
|
|
|
AnimationPath h3mName = AnimationPath::builtinTODO(entryTemplate.second.String());
|
|
|
|
AnimationPath vcmiName = AnimationPath::builtinTODO(entryTemplate.first);
|
2023-05-24 21:02:27 +02:00
|
|
|
|
2023-09-20 20:59:16 +02:00
|
|
|
if (!CResourceHandler::get()->existsResource(vcmiName.addPrefix("SPRITES/")))
|
|
|
|
logMod->warn("Template animation file %s was not found!", vcmiName.getOriginalName());
|
2023-05-24 21:02:27 +02:00
|
|
|
|
|
|
|
mappingObjectTemplate[h3mName] = vcmiName;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto entryOuter : mapping["objects"].Struct())
|
|
|
|
{
|
|
|
|
if (entryOuter.second.isStruct())
|
|
|
|
{
|
|
|
|
for (auto entryInner : entryOuter.second.Struct())
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
auto handler = VLC->objtypeh->getHandlerFor( entryInner.second.getModScope(), entryOuter.first, entryInner.first);
|
2023-05-24 21:02:27 +02:00
|
|
|
|
|
|
|
auto entryValues = entryInner.second.Vector();
|
|
|
|
ObjectTypeIdentifier h3mID{Obj(entryValues[0].Integer()), int32_t(entryValues[1].Integer())};
|
|
|
|
ObjectTypeIdentifier vcmiID{Obj(handler->getIndex()), handler->getSubIndex()};
|
|
|
|
mappingObjectIndex[h3mID] = vcmiID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
auto handler = VLC->objtypeh->getHandlerFor( entryOuter.second.getModScope(), entryOuter.first, entryOuter.first);
|
2023-05-24 21:02:27 +02:00
|
|
|
|
|
|
|
auto entryValues = entryOuter.second.Vector();
|
|
|
|
ObjectTypeIdentifier h3mID{Obj(entryValues[0].Integer()), int32_t(entryValues[1].Integer())};
|
|
|
|
ObjectTypeIdentifier vcmiID{Obj(handler->getIndex()), handler->getSubIndex()};
|
|
|
|
mappingObjectIndex[h3mID] = vcmiID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
loadMapping(mappingHeroPortrait, mapping["portraits"], "hero");
|
2023-05-25 23:38:00 +02:00
|
|
|
loadMapping(mappingBuilding, mapping["buildingsCommon"], "building.core:random");
|
|
|
|
loadMapping(mappingFaction, mapping["factions"], "faction");
|
|
|
|
loadMapping(mappingCreature, mapping["creatures"], "creature");
|
|
|
|
loadMapping(mappingHeroType, mapping["heroes"], "hero");
|
|
|
|
loadMapping(mappingHeroClass, mapping["heroClasses"], "heroClass");
|
|
|
|
loadMapping(mappingTerrain, mapping["terrains"], "terrain");
|
|
|
|
loadMapping(mappingArtifact, mapping["artifacts"], "artifact");
|
|
|
|
loadMapping(mappingSecondarySkill, mapping["skills"], "skill");
|
2023-05-23 14:07:44 +02:00
|
|
|
}
|
|
|
|
|
2023-05-24 21:02:27 +02:00
|
|
|
void MapIdentifiersH3M::remapTemplate(ObjectTemplate & objectTemplate)
|
|
|
|
{
|
2023-09-20 20:59:16 +02:00
|
|
|
auto name = objectTemplate.animationFile;
|
2023-05-24 21:02:27 +02:00
|
|
|
|
|
|
|
if (mappingObjectTemplate.count(name))
|
2023-09-20 20:59:16 +02:00
|
|
|
objectTemplate.animationFile = mappingObjectTemplate.at(name);
|
2023-05-24 21:02:27 +02:00
|
|
|
|
|
|
|
ObjectTypeIdentifier objectType{ objectTemplate.id, objectTemplate.subid};
|
|
|
|
|
|
|
|
if (mappingObjectIndex.count(objectType))
|
|
|
|
{
|
|
|
|
auto mappedType = mappingObjectIndex.at(objectType);
|
|
|
|
objectTemplate.id = mappedType.ID;
|
|
|
|
objectTemplate.subid = mappedType.subID;
|
|
|
|
}
|
2023-06-16 18:11:37 +02:00
|
|
|
|
|
|
|
if (objectTemplate.id == Obj::TOWN || objectTemplate.id == Obj::RANDOM_DWELLING_FACTION)
|
|
|
|
objectTemplate.subid = remap(FactionID(objectTemplate.subid));
|
|
|
|
|
|
|
|
if (objectTemplate.id == Obj::MONSTER)
|
|
|
|
objectTemplate.subid = remap(CreatureID(objectTemplate.subid));
|
|
|
|
|
|
|
|
if (objectTemplate.id == Obj::ARTIFACT)
|
|
|
|
objectTemplate.subid = remap(ArtifactID(objectTemplate.subid));
|
2023-05-24 21:02:27 +02:00
|
|
|
}
|
|
|
|
|
2023-05-23 15:13:09 +02:00
|
|
|
BuildingID MapIdentifiersH3M::remapBuilding(std::optional<FactionID> owner, BuildingID input) const
|
2023-05-23 14:07:44 +02:00
|
|
|
{
|
2023-05-23 15:13:09 +02:00
|
|
|
if (owner.has_value() && mappingFactionBuilding.count(*owner))
|
2023-05-23 14:07:44 +02:00
|
|
|
{
|
2023-05-23 15:13:09 +02:00
|
|
|
auto submap = mappingFactionBuilding.at(*owner);
|
2023-05-23 14:07:44 +02:00
|
|
|
|
|
|
|
if (submap.count(input))
|
|
|
|
return submap.at(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mappingBuilding.count(input))
|
|
|
|
return mappingBuilding.at(input);
|
2023-05-23 15:13:09 +02:00
|
|
|
return BuildingID::NONE;
|
2023-05-23 14:07:44 +02:00
|
|
|
}
|
|
|
|
|
2023-05-23 22:55:18 +02:00
|
|
|
FactionID MapIdentifiersH3M::remap(FactionID input) const
|
|
|
|
{
|
|
|
|
if (mappingFaction.count(input))
|
|
|
|
return mappingFaction.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreatureID MapIdentifiersH3M::remap(CreatureID input) const
|
|
|
|
{
|
|
|
|
if (mappingCreature.count(input))
|
|
|
|
return mappingCreature.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeroTypeID MapIdentifiersH3M::remap(HeroTypeID input) const
|
|
|
|
{
|
|
|
|
if (mappingHeroType.count(input))
|
|
|
|
return mappingHeroType.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID MapIdentifiersH3M::remapPortrait(HeroTypeID input) const
|
2023-06-20 14:09:42 +02:00
|
|
|
{
|
|
|
|
if (mappingHeroPortrait.count(input))
|
|
|
|
return mappingHeroPortrait.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2023-05-23 22:55:18 +02:00
|
|
|
HeroClassID MapIdentifiersH3M::remap(HeroClassID input) const
|
|
|
|
{
|
|
|
|
if (mappingHeroClass.count(input))
|
|
|
|
return mappingHeroClass.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
TerrainId MapIdentifiersH3M::remap(TerrainId input) const
|
|
|
|
{
|
|
|
|
if (mappingTerrain.count(input))
|
|
|
|
return mappingTerrain.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArtifactID MapIdentifiersH3M::remap(ArtifactID input) const
|
|
|
|
{
|
|
|
|
if (mappingArtifact.count(input))
|
|
|
|
return mappingArtifact.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
SecondarySkill MapIdentifiersH3M::remap(SecondarySkill input) const
|
|
|
|
{
|
|
|
|
if (mappingSecondarySkill.count(input))
|
|
|
|
return mappingSecondarySkill.at(input);
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:07:44 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|