浏览代码

It is now possible to define multiple town themes

Ivan Savenko 1 年之前
父节点
当前提交
358008fca9

+ 12 - 1
client/media/CMusicHandler.cpp

@@ -16,6 +16,7 @@
 #include "../renderSDL/SDLRWwrapper.h"
 
 #include "../../lib/CRandomGenerator.h"
+#include "../../lib/CTownHandler.h"
 #include "../../lib/TerrainHandler.h"
 #include "../../lib/filesystem/Filesystem.h"
 
@@ -64,7 +65,17 @@ void CMusicHandler::loadTerrainMusicThemes()
 {
 	for(const auto & terrain : CGI->terrainTypeHandler->objects)
 	{
-		addEntryToSet("terrain_" + terrain->getJsonKey(), terrain->musicFilename);
+		for(const auto & filename : terrain->musicFilename)
+			addEntryToSet("terrain_" + terrain->getJsonKey(), filename);
+	}
+
+	for(const auto & faction : CGI->townh->objects)
+	{
+		if (!faction || !faction->hasTown())
+			continue;
+
+		for(const auto & filename : faction->town->clientInfo.musicTheme)
+			addEntryToSet("faction_" + faction->getJsonKey(), filename);
 	}
 }
 

+ 1 - 1
client/windows/CCastleInterface.cpp

@@ -1283,7 +1283,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
 	recreateIcons();
 	if (!from)
 		adventureInt->onAudioPaused();
-	CCS->musich->playMusic(town->town->clientInfo.musicTheme, true, false);
+	CCS->musich->playMusicFromSet("faction", town->town->faction->getJsonKey(), true, false);
 }
 
 CCastleInterface::~CCastleInterface()

+ 1 - 1
config/factions/castle.json

@@ -119,7 +119,7 @@
 				"dwellingUpLvl7": { "animation" : "TBCSUP_6.def", "x" : 303, "y" : 0,   "z" : -1, "border" : "TOCSANG2.bmp", "area" : "TZCSANG2.bmp" }
 			},
 
-			"musicTheme" : "music/CstleTown",
+			"musicTheme" : [ "music/CstleTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/conflux.json

@@ -123,7 +123,7 @@
 				"dwellingUpLvl7": { "animation" : "TBELUP_6.def", "x" : 43,  "y" : 0,   "z" : -2, "border" : "TOELUP_6.bmp", "area" : "TZELUP_6.bmp" }
 			},
 
-			"musicTheme" : "music/ElemTown",
+			"musicTheme" : [ "music/ElemTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/dungeon.json

@@ -119,7 +119,7 @@
 				"dwellingUpLvl7": { "animation" : "TBDNUP_6.def", "x" : 550, "y" : 0,   "z" : -1, "border" : "TODDRA2A.bmp", "area" : "TZDDRA2A.bmp" }
 			},
 
-			"musicTheme" : "music/Dungeon",
+			"musicTheme" : [ "music/Dungeon" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/fortress.json

@@ -119,7 +119,7 @@
 				"dwellingUpLvl7": { "animation" : "TBFRUP_6.def", "x" : 587, "y" : 263, "z" : 5,  "border" : "TOFHYD2A.bmp", "area" : "TZFHYD2A.bmp" }
 			},
 
-			"musicTheme" : "music/FortressTown",
+			"musicTheme" : [ "music/FortressTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/inferno.json

@@ -120,7 +120,7 @@
 				"dwellingUpLvl7": { "animation" : "TBINUP_6.def", "x" : 420, "y" : 105, "z" : -1, "border" : "TOIDVL2.bmp",  "area" : "TZIDVL2.bmp" }
 			},
 
-			"musicTheme" : "music/InfernoTown",
+			"musicTheme" : [ "music/InfernoTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/necropolis.json

@@ -124,7 +124,7 @@
 				"dwellingUpLvl7": { "animation" : "TBNCUP_6.def", "x" : 662, "y" : 23,  "border" : "TONBON2.bmp",  "area" : "TZNBON2.bmp" }
 			},
 
-			"musicTheme" : "music/NecroTown",
+			"musicTheme" : [ "music/NecroTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/rampart.json

@@ -123,7 +123,7 @@
 				"dwellingUpLvl7": { "animation" : "TBRMUP_6.def", "x" : 502, "y" : 5,   "z" : -5, "border" : "TORDR2AA.bmp", "area" : "TZRDR2AA.bmp" }
 			},
 
-			"musicTheme" : "music/Rampart",
+			"musicTheme" : [ "music/Rampart" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/stronghold.json

@@ -117,7 +117,7 @@
 				"dwellingUpLvl7": { "animation" : "TBSTUP_6.def", "x" : 604, "y" : 0,   "border" : "TOSBEH2A.bmp", "area" : "TZSBEH2A.bmp" }
 			},
 
-			"musicTheme" : "music/Stronghold",
+			"musicTheme" : [ "music/Stronghold" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 1 - 1
config/factions/tower.json

@@ -118,7 +118,7 @@
 				"dwellingUpLvl7": { "animation" : "TBTWUP_6.def", "x" : 75,  "y" : 91,  "z" : -1, "border" : "TOTTIT2.bmp",  "area" : "TZTTIT2.bmp" }
 			},
 
-			"musicTheme" : "music/TowerTown",
+			"musicTheme" : [ "music/TowerTown" ],
 			"defaultTavern" : 5,
 			"tavernVideo" : "TAVERN.BIK",
 			"guildBackground" : "TPMAGE.bmp",

+ 7 - 3
config/schemas/faction.json

@@ -151,9 +151,13 @@
 					"$ref" : "townSiege.json"
 				},
 				"musicTheme" : {
-					"type" : "string",
-					"description" : "Path to town music theme",
-					"format" : "musicFile"
+					"type" : "array",
+					"description" : "Path to town music themes",
+					"minItems" : 1,
+					"items" : { 
+						"type" : "string",
+						"format" : "musicFile"
+					}
 				},
 				"tavernVideo" : {
 					"type" : "string",

+ 4 - 3
docs/modders/Entities_Format/Faction_Format.md

@@ -30,7 +30,7 @@ In order to make functional town you also need:
 
 ### Music
 
--   Town theme music track (1 music file)
+-   Town theme music track (at least 1 music file)
 
 ### Buildings
 
@@ -150,8 +150,9 @@ Each town requires a set of buildings (Around 30-45 buildings)
 			}
 		}
 	},
-	// Path to town music theme, e.g. "music/castleTheme"
-	"musicTheme" : "",
+	// List of town music themes, e.g. [ "music/castleTheme" ]
+	// At least one music file is required
+	"musicTheme" : [ "" ],
 
 	// List of structures which represents visible graphical objects on town screen.
 	// See detailed description below

+ 10 - 1
lib/CTownHandler.cpp

@@ -902,8 +902,17 @@ void CTownHandler::loadClientData(CTown &town, const JsonNode & source) const
 	readIcon(source["icons"]["fort"]["normal"], info.iconSmall[1][0], info.iconLarge[1][0]);
 	readIcon(source["icons"]["fort"]["built"], info.iconSmall[1][1], info.iconLarge[1][1]);
 
+	if (source["musicTheme"].isVector())
+	{
+		for (auto const & entry : source["musicTheme"].Vector())
+			info.musicTheme.push_back(AudioPath::fromJson(entry));
+	}
+	else
+	{
+		info.musicTheme.push_back(AudioPath::fromJson(source["musicTheme"]));
+	}
+
 	info.hallBackground = ImagePath::fromJson(source["hallBackground"]);
-	info.musicTheme = AudioPath::fromJson(source["musicTheme"]);
 	info.townBackground = ImagePath::fromJson(source["townBackground"]);
 	info.guildWindow = ImagePath::fromJson(source["guildWindow"]);
 	info.buildingsIcons = AnimationPath::fromJson(source["buildingsIcons"]);

+ 1 - 1
lib/CTownHandler.h

@@ -253,7 +253,7 @@ public:
 		std::string iconSmall[2][2]; /// icon names used during loading
 		std::string iconLarge[2][2];
 		VideoPath tavernVideo;
-		AudioPath musicTheme;
+		std::vector<AudioPath> musicTheme;
 		ImagePath townBackground;
 		ImagePath guildBackground;
 		ImagePath guildWindow;