1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Initial version of AI object value config

This commit is contained in:
Dydzio 2018-07-28 00:43:56 +02:00
parent df00ced204
commit b37ba8e046
5 changed files with 42 additions and 2 deletions

View File

@ -13,6 +13,9 @@
"name": {
"type":"string",
},
"defaultAiValue": {
"type":"number",
},
"handler": {
"type":"string",

View File

@ -13,6 +13,9 @@
"name": {
"type":"string",
},
"aiValue": {
"type":"number",
},
"sounds": {
"type":"object",

View File

@ -206,6 +206,11 @@ CObjectClassesHandler::ObjectContainter * CObjectClassesHandler::loadFromJson(co
obj->handlerName = json["handler"].String();
obj->base = json["base"];
obj->id = selectNextID(json["index"], objects, 256);
if(json["defaultAiValue"].isNull())
obj->groupDefaultAiValue = boost::none;
else
obj->groupDefaultAiValue = json["defaultAiValue"].Integer();
for (auto entry : json["types"].Struct())
{
loadObjectEntry(entry.first, entry.second, obj);
@ -387,6 +392,11 @@ std::string CObjectClassesHandler::getObjectHandlerName(si32 type) const
return objects.at(type)->handlerName;
}
boost::optional<si32> CObjectClassesHandler::getObjGroupAiValue(si32 primaryID) const
{
return objects.at(primaryID)->groupDefaultAiValue;
}
AObjectTypeHandler::AObjectTypeHandler():
type(-1), subtype(-1)
{
@ -457,6 +467,11 @@ void AObjectTypeHandler::init(const JsonNode & input, boost::optional<std::strin
for(const JsonNode & node : input["sounds"]["removal"].Vector())
sounds.removal.push_back(node.String());
if(input["aiValue"].isNull())
aiValue = boost::none;
else
aiValue = input["aiValue"].Integer();
initTypeData(input);
}
@ -545,6 +560,11 @@ const RandomMapInfo & AObjectTypeHandler::getRMGInfo()
return rmgInfo;
}
boost::optional<si32> AObjectTypeHandler::getAiValue() const
{
return aiValue;
}
bool AObjectTypeHandler::isStaticObject()
{
return false; // most of classes are not static

View File

@ -146,6 +146,8 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
std::vector<ObjectTemplate> templates;
SObjectSounds sounds;
boost::optional<si32> aiValue;
protected:
void preInitObject(CGObjectInstance * obj) const;
virtual bool objectFilter(const CGObjectInstance *, const ObjectTemplate &) const;
@ -184,6 +186,8 @@ public:
const RandomMapInfo & getRMGInfo();
boost::optional<si32> getAiValue() const;
virtual bool isStaticObject();
virtual void afterLoadFinalization();
@ -215,6 +219,10 @@ public:
{
h & sounds;
}
if(version >= 788)
{
h & aiValue;
}
}
};
@ -237,6 +245,8 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
SObjectSounds sounds;
boost::optional<si32> groupDefaultAiValue;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name;
@ -252,6 +262,10 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
{
h & sounds;
}
if(version >= 788)
{
h & groupDefaultAiValue;
}
}
};
@ -306,7 +320,7 @@ public:
/// Returns handler string describing the handler (for use in client)
std::string getObjectHandlerName(si32 type) const;
boost::optional<si32> getObjGroupAiValue(si32 primaryID) const; //default AI value of objects belonging to particular primaryID
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -12,7 +12,7 @@
#include "../ConstTransitivePtr.h"
#include "../GameConstants.h"
const ui32 SERIALIZATION_VERSION = 787;
const ui32 SERIALIZATION_VERSION = 788;
const ui32 MINIMAL_SERIALIZATION_VERSION = 753;
const std::string SAVEGAME_MAGIC = "VCMISVG";