Browse Source

defining own regions

Laserlicht 1 year ago
parent
commit
23438590c5

+ 21 - 6
lib/campaign/CampaignState.cpp

@@ -46,6 +46,8 @@ CampaignRegions CampaignRegions::fromJson(const JsonNode & node)
 	CampaignRegions cr;
 	CampaignRegions cr;
 	cr.campPrefix = node["prefix"].String();
 	cr.campPrefix = node["prefix"].String();
 	cr.colorSuffixLength = static_cast<int>(node["color_suffix_length"].Float());
 	cr.colorSuffixLength = static_cast<int>(node["color_suffix_length"].Float());
+	cr.campSuffix = node["suffix"].isNull() ? std::vector<std::string>() : std::vector<std::string>{node["suffix"].Vector()[0].String(), node["suffix"].Vector()[1].String(), node["suffix"].Vector()[2].String()};
+	cr.campBackground = node["background"].isNull() ? "" : node["background"].String();
 
 
 	for(const JsonNode & desc : node["desc"].Vector())
 	for(const JsonNode & desc : node["desc"].Vector())
 		cr.regions.push_back(CampaignRegions::RegionDescription::fromJson(desc));
 		cr.regions.push_back(CampaignRegions::RegionDescription::fromJson(desc));
@@ -68,7 +70,10 @@ CampaignRegions CampaignRegions::getLegacy(int campId)
 
 
 ImagePath CampaignRegions::getBackgroundName() const
 ImagePath CampaignRegions::getBackgroundName() const
 {
 {
-	return ImagePath::builtin(campPrefix + "_BG.BMP");
+	if(campBackground.empty())
+		return ImagePath::builtin(campPrefix + "_BG.BMP");
+	else
+		return ImagePath::builtin(campBackground);
 }
 }
 
 
 Point CampaignRegions::getPosition(CampaignScenarioID which) const
 Point CampaignRegions::getPosition(CampaignScenarioID which) const
@@ -81,30 +86,40 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex,
 {
 {
 	auto const & region = regions[which.getNum()];
 	auto const & region = regions[which.getNum()];
 
 
-	static const std::string colors[2][8] =
+	static const std::string colors[3][8] =
 	{
 	{
+		{"", "", "", "", "", "", "", ""},
 		{"R", "B", "N", "G", "O", "V", "T", "P"},
 		{"R", "B", "N", "G", "O", "V", "T", "P"},
 		{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}
 		{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}
 	};
 	};
 
 
-	std::string color = colors[colorSuffixLength - 1][colorIndex];
+	std::string color = colors[colorSuffixLength][colorIndex];
 
 
 	return ImagePath::builtin(campPrefix + region.infix + "_" + type + color + ".BMP");
 	return ImagePath::builtin(campPrefix + region.infix + "_" + type + color + ".BMP");
 }
 }
 
 
 ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const
 ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const
 {
 {
-	return getNameFor(which, color, "En");
+	if(campSuffix.size() == 0)
+		return getNameFor(which, color, "En");
+	else
+		return getNameFor(which, color, campSuffix[0]);
 }
 }
 
 
 ImagePath CampaignRegions::getSelectedName(CampaignScenarioID which, int color) const
 ImagePath CampaignRegions::getSelectedName(CampaignScenarioID which, int color) const
 {
 {
-	return getNameFor(which, color, "Se");
+	if(campSuffix.size() == 0)
+		return getNameFor(which, color, "Se");
+	else
+		return getNameFor(which, color, campSuffix[1]);
 }
 }
 
 
 ImagePath CampaignRegions::getConqueredName(CampaignScenarioID which, int color) const
 ImagePath CampaignRegions::getConqueredName(CampaignScenarioID which, int color) const
 {
 {
-	return getNameFor(which, color, "Co");
+	if(campSuffix.size() == 0)
+		return getNameFor(which, color, "Co");
+	else
+		return getNameFor(which, color, campSuffix[2]);
 }
 }
 
 
 
 

+ 7 - 0
lib/campaign/CampaignState.h

@@ -33,6 +33,8 @@ class IGameCallback;
 class DLL_LINKAGE CampaignRegions
 class DLL_LINKAGE CampaignRegions
 {
 {
 	std::string campPrefix;
 	std::string campPrefix;
+	std::vector<std::string> campSuffix = {};
+	std::string campBackground = "";
 	int colorSuffixLength;
 	int colorSuffixLength;
 
 
 	struct DLL_LINKAGE RegionDescription
 	struct DLL_LINKAGE RegionDescription
@@ -67,6 +69,11 @@ public:
 		h & campPrefix;
 		h & campPrefix;
 		h & colorSuffixLength;
 		h & colorSuffixLength;
 		h & regions;
 		h & regions;
+		if (h.version >= Handler::Version::CAMPAIGN_REGIONS)
+		{
+			h & campSuffix;
+			h & campBackground;
+		}
 	}
 	}
 
 
 	static CampaignRegions fromJson(const JsonNode & node);
 	static CampaignRegions fromJson(const JsonNode & node);

+ 2 - 1
lib/serializer/ESerializationVersion.h

@@ -58,7 +58,8 @@ enum class ESerializationVersion : int32_t
 	MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
 	MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
 	REMOVE_LIB_RNG, // 849 - removed random number generators from library classes
 	REMOVE_LIB_RNG, // 849 - removed random number generators from library classes
 	HIGHSCORE_PARAMETERS, // 850 - saves parameter for campaign
 	HIGHSCORE_PARAMETERS, // 850 - saves parameter for campaign
-  PLAYER_HANDICAP, // 851 - player handicap selection at game start
+	PLAYER_HANDICAP, // 851 - player handicap selection at game start
+	CAMPAIGN_REGIONS, // 852 - configurable campaign regions
 
 
 	CURRENT = PLAYER_HANDICAP
 	CURRENT = PLAYER_HANDICAP
 };
 };