mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Basic version of object templates mapping
This commit is contained in:
parent
b3ca6c8cee
commit
952708e865
@ -109,39 +109,33 @@
|
||||
"lastReservedIndex" : 2,
|
||||
"base" : {
|
||||
"aiValue" : 0,
|
||||
"layer" : "sail",
|
||||
"onboardAssaultAllowed" : true,
|
||||
"onboardVisitAllowed" : true,
|
||||
"base" : {
|
||||
"visitableFrom" : [ "+++", "+-+", "+++" ],
|
||||
"mask" : [ "VVV", "VAV" ]
|
||||
}
|
||||
},
|
||||
"types" : {
|
||||
"evil" :
|
||||
"evil" : // Necropolis
|
||||
{
|
||||
"index" : 0,
|
||||
"layer" : "sail",
|
||||
"index" : 0,
|
||||
"actualAnimation" : "AB01_.def",
|
||||
"overlayAnimation" : "ABM01_.def",
|
||||
"onboardAssaultAllowed" : true,
|
||||
"onboardVisitAllowed" : true,
|
||||
"flagAnimations" : ["ABF01L", "ABF01G", "ABF01R", "ABF01D", "ABF01B", "ABF01P", "ABF01W", "ABF01K"]
|
||||
},
|
||||
"good" :
|
||||
"good" : // Castle
|
||||
{
|
||||
"index" : 1,
|
||||
"layer" : "sail",
|
||||
"actualAnimation" : "AB02_.def",
|
||||
"overlayAnimation" : "ABM02_.def",
|
||||
"onboardAssaultAllowed" : true,
|
||||
"onboardVisitAllowed" : true,
|
||||
"flagAnimations" : ["ABF02L", "ABF02G", "ABF02R", "ABF02D", "ABF02B", "ABF02P", "ABF02W", "ABF02K"]
|
||||
},
|
||||
"neutral" : {
|
||||
"neutral" : { // Fortress
|
||||
"index" : 2,
|
||||
"layer" : "sail",
|
||||
"actualAnimation" : "AB03_.def",
|
||||
"overlayAnimation" : "ABM03_.def",
|
||||
"onboardAssaultAllowed" : true,
|
||||
"onboardVisitAllowed" : true,
|
||||
"flagAnimations" : ["ABF03L", "ABF03G", "ABF03R", "ABF03D", "ABF03B", "ABF03P", "ABF03W", "ABF03K"]
|
||||
},
|
||||
}
|
||||
|
@ -922,9 +922,12 @@ void CMapLoaderH3M::readObjectTemplates()
|
||||
// Read custom defs
|
||||
for(int defID = 0; defID < defAmount; ++defID)
|
||||
{
|
||||
auto * tmpl = new ObjectTemplate;
|
||||
auto tmpl = std::make_shared<ObjectTemplate>();
|
||||
tmpl->readMap(reader->getInternalReader());
|
||||
templates.push_back(std::shared_ptr<const ObjectTemplate>(tmpl));
|
||||
templates.push_back(tmpl);
|
||||
|
||||
if (!CResourceHandler::get()->existsResource(ResourceID( "SPRITES/" + tmpl->animationFile, EResType::ANIMATION)))
|
||||
logMod->warn("Template animation %s of type (%d %d) is missing!", tmpl->animationFile, tmpl->id, tmpl->subid );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "../VCMI_Lib.h"
|
||||
#include "../CModHandler.h"
|
||||
#include "../CTownHandler.h"
|
||||
#include "../mapObjects/CObjectClassesHandler.h"
|
||||
#include "../filesystem/Filesystem.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -50,6 +52,42 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
|
||||
}
|
||||
}
|
||||
|
||||
for (auto entryTemplate : mapping["templates"].Struct())
|
||||
{
|
||||
std::string h3mName = entryTemplate.second.String();
|
||||
std::string vcmiName = entryTemplate.first;
|
||||
|
||||
if (!CResourceHandler::get()->existsResource(ResourceID( "SPRITES/" + vcmiName, EResType::ANIMATION)))
|
||||
logMod->warn("Template animation file %s was not found!", vcmiName);
|
||||
|
||||
mappingObjectTemplate[h3mName] = vcmiName;
|
||||
}
|
||||
|
||||
for (auto entryOuter : mapping["objects"].Struct())
|
||||
{
|
||||
if (entryOuter.second.isStruct())
|
||||
{
|
||||
for (auto entryInner : entryOuter.second.Struct())
|
||||
{
|
||||
auto handler = VLC->objtypeh->getHandlerFor( VLC->modh->scopeGame(), entryOuter.first, entryInner.first);
|
||||
|
||||
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
|
||||
{
|
||||
auto handler = VLC->objtypeh->getHandlerFor( VLC->modh->scopeGame(), entryOuter.first, entryOuter.first);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
mappingBuilding = loadMapping<BuildingID>(mapping["buildingsCommon"], "building.core:random");
|
||||
mappingFaction = loadMapping<FactionID>(mapping["factions"], "faction");
|
||||
mappingCreature = loadMapping<CreatureID>(mapping["creatures"], "creature");
|
||||
@ -60,6 +98,23 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
|
||||
mappingSecondarySkill = loadMapping<SecondarySkill>(mapping["skills"], "skill");
|
||||
}
|
||||
|
||||
void MapIdentifiersH3M::remapTemplate(ObjectTemplate & objectTemplate)
|
||||
{
|
||||
std::string name = boost::to_lower_copy(objectTemplate.animationFile);
|
||||
|
||||
if (mappingObjectTemplate.count(name))
|
||||
objectTemplate.animationFile = mappingObjectTemplate.at(name);
|
||||
|
||||
ObjectTypeIdentifier objectType{ objectTemplate.id, objectTemplate.subid};
|
||||
|
||||
if (mappingObjectIndex.count(objectType))
|
||||
{
|
||||
auto mappedType = mappingObjectIndex.at(objectType);
|
||||
objectTemplate.id = mappedType.ID;
|
||||
objectTemplate.subid = mappedType.subID;
|
||||
}
|
||||
}
|
||||
|
||||
BuildingID MapIdentifiersH3M::remapBuilding(std::optional<FactionID> owner, BuildingID input) const
|
||||
{
|
||||
if (owner.has_value() && mappingFactionBuilding.count(*owner))
|
||||
|
@ -15,6 +15,20 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class JsonNode;
|
||||
class ObjectTemplate;
|
||||
|
||||
struct ObjectTypeIdentifier
|
||||
{
|
||||
Obj ID;
|
||||
int32_t subID;
|
||||
|
||||
bool operator < (const ObjectTypeIdentifier & other) const
|
||||
{
|
||||
if (ID != other.ID)
|
||||
return ID < other.ID;
|
||||
return subID < other.subID;
|
||||
}
|
||||
};
|
||||
|
||||
class MapIdentifiersH3M
|
||||
{
|
||||
@ -28,11 +42,16 @@ class MapIdentifiersH3M
|
||||
std::map<ArtifactID, ArtifactID> mappingArtifact;
|
||||
std::map<SecondarySkill, SecondarySkill> mappingSecondarySkill;
|
||||
|
||||
std::map<std::string, std::string> mappingObjectTemplate;
|
||||
std::map<ObjectTypeIdentifier, ObjectTypeIdentifier> mappingObjectIndex;
|
||||
|
||||
template<typename IdentifierID>
|
||||
std::map<IdentifierID, IdentifierID> loadMapping(const JsonNode & mapping, const std::string & identifierName);
|
||||
public:
|
||||
void loadMapping(const JsonNode & mapping);
|
||||
|
||||
void remapTemplate(ObjectTemplate & objectTemplate);
|
||||
|
||||
BuildingID remapBuilding(std::optional<FactionID> owner, BuildingID input) const;
|
||||
FactionID remap(FactionID input) const;
|
||||
CreatureID remap(CreatureID input) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user