瀏覽代碼

Initial version of AI object value config

Dydzio 7 年之前
父節點
當前提交
b37ba8e046

+ 3 - 0
config/schemas/object.json

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

+ 3 - 0
config/schemas/objectType.json

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

+ 20 - 0
lib/mapObjects/CObjectClassesHandler.cpp

@@ -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

+ 15 - 1
lib/mapObjects/CObjectClassesHandler.h

@@ -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)
 	{

+ 1 - 1
lib/serializer/CSerializer.h

@@ -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";