[BTS] How to make truly random war theme play for at-war civs?

SuperXANA

Chieftain
Joined
Aug 19, 2009
Messages
30
Hello everyone,

I noticed in Civ IV that it's possible to have random unit sounds play when selecting units, just by having one sound file defined in AudioDefines.xml and numbering the files with the defined name and a number. That way, you do not have the same sound playing all the time when selecting units and breaking immersion in-game.

I was wondering if it's possible to do the same thing with "You're at war with this civ!" themes - that is, have one war theme defined in the XML (those files being MP3s not WAVs) and have the game randomly choose from one of the war themes.

Right now, you have to go into Civ4LeaderHeadInfos.xml / AudioDefines.xml and choose a theme to play for them in each era (both peace and war themes). It would not have the same effect as allowing a random war theme to play, since you have to choose it in the aforementioned file(s) and it will always be the same no matter what.

Is what I'm looking for even possible? I haven't found a mod that's tried this particular idea yet.

Thanks for your help! I really appreciate it quite a lot! :)
 
It looks possible, though it's obviously a DLL only change. The relevant code:
PHP:
int CvPlayer::getIntroMusicScriptId(PlayerTypes eForPlayer) const
{
   CvPlayer& kForPlayer = GET_PLAYER(eForPlayer);
   EraTypes eEra = kForPlayer.getCurrentEra();
   CvLeaderHeadInfo& kLeader = GC.getLeaderHeadInfo(getLeaderType());
   if (GET_TEAM(kForPlayer.getTeam()).isAtWar(getTeam()))
   {
       return kLeader.getDiploWarIntroMusicScriptIds(eEra);
   }
   else
   {
       return kLeader.getDiploPeaceIntroMusicScriptIds(eEra);
   }
}
PHP:
int CvLeaderHeadInfo::getDiploWarIntroMusicScriptIds(int i) const
{
   FAssertMsg(i < GC.getNumEraInfos(), "Index out of bounds");
   FAssertMsg(i > -1, "Index out of bounds");
   return m_piDiploWarIntroMusicScriptIds ? m_piDiploWarIntroMusicScriptIds[i] : -1;
}
It's stored as a list with one ID for each era. If you change it to store a list of length era and each element is a list of a non-fixed length of IDs, then when picking one era, it will be possible to make the code pick a random one from the inner list. Remember to use unsynced random as the synced one will cause multiplayer desyncs.

There are other functions to play music, but the approach seems to be the same for all of them.
 
Hello!

Well, this is kind of beyond me now. :(

I haven't tried making my own DLL yet, and I use the BULL Mod in my game so it has it's own packaged DLL.
Plus, I hardly understood what most of that meant, not to say that the explanation was bad - I'm just inexperienced with CIV IV modding. ;)

As far as I can tell, the BULL mod only provides the DLL for download and not the relevant changes they made to it.

I was hoping this change would work like the Unit Sounds randomizer mechanism, but sadly you informed me it doesn't.

I was poking around the BULL Game DLL with a hex editor earlier and the code in there doesn't match what's on display here. It must be obfuscated or something, which makes it difficult to change without breaking anything. Perhaps this isn't possible when already using a DLL mod?

Thanks for your help!
 
Last edited:
I was poking around the BULL Game DLL with a hex editor earlier and the code in there doesn't match what's on display here. It must be obfuscated or something, which makes it difficult to change without breaking anything. Perhaps this isn't possible when already using a DLL mod?
1: don't use a hex editor on the DLL files. Get hold of the source code. Most if not all mods use open source and there is source code for the vanilla DLL as well.
2: there is max one DLL for each mod. If there is a DLL already in the mod where you want to use this feature, you need to modify that DLL, not make a new one.
 
Hello Nightinggale, thanks for responding!

Vis-a-vis point #2 in your post: The character mod I am modifying doesn't come with a DLL installed. Instead, I added the BULL DLL myself to get the extra features that it offers (after doing some Python merging for BUG).

I looked for the aforementioned DLL online, and I just now discovered that the mod does provide the source code.

I figured out how to build the DLL for BULL, making the build environment on my computer all that, making the source files available where they need to be, etc.

EDIT @ 12/14/2017: I decided the strange build error I was receiving with my custom build wasn't worth agonizing over and I've moved over to K-mod's DLL instead. (I will tryout a custom build of K-mod with the random music patch later.)

Thanks for your help! :)
 
Last edited:
Top Bottom