How to add leaders?

apenpaap

Tsar of all the Internets
Joined
Apr 7, 2008
Messages
1,468
Location
Amsterdam
I want to add Boudica as an early Eanglish leader, Brennus as an early French leader, Hatshepsut as an early Egyptian leader, and Shaka (renamed Za Haqala) as an early Ethiopian leader. I know how to add their leaderheads and do their personality and stuff, but I have no idea how to make RFC have these civs start with those leaders and how to switch them to more modern leaders later on. Can anyone offer some help there?
 
I want to add Boudica as an early Eanglish leader, Brennus as an early French leader, Hatshepsut as an early Egyptian leader, and Shaka (renamed Za Haqala) as an early Ethiopian leader. I know how to add their leaderheads and do their personality and stuff, but I have no idea how to make RFC have these civs start with those leaders and how to switch them to more modern leaders later on. Can anyone offer some help there?

Here's a guide that I think ought to work. This assumes that you have already added the art and XML files that control the leader characteristics. In particular, I assume that you have added the XML code for the new leaders to the bottom of the appropriate lists in the same order throughout.

Consts.py
1. In the #leaders list, add a line to the bottom for each extra leader. This creates a variable that Python can use later. Ensure that the number you assign to each variable matches the position of the corresponding leader in XML. e.g. iHirohito = 53.
2. In tLeaders, add each new variable name to the appropriate, time-ordered list of leaders. e.g. (iTokugawa, iHirohito), .
3. In tEarlyLeaders, if you want a new leader to be the first leader for this civ when played by the AI, change the appropriate variable name. e.g. replace (iElizabeth), with (iBoudica), .
4. In tLateLeaders, in the appropriate line containing a list of leaders and spawning times, add a list of four entries comprising:
(a) the new variable name
(b) the earliest time for the new leaderhead to replace its predecessor
(c) a number I don't understand
(d) a number I don't understand.
You should just copy (c) and (d) from some other leader. e.g. (iHirohito, i1800AD, 5, 5), . If the civ had only one leader before you modified it, you can delete the details for its original leader in this line.
5. If your new leader is for Rome, make the appropriate changes to the special lines for Rome above the tLateLeaders function.

RiseAndFall.py
6. If you now have a civ with more than 3 leaders, the leader switching code can't handle it yet. You need to replace the first part of checkPlayerTurn with the following code that handles 4 leaders. If you have 5 or more leaders, figure it out yourself.

Spoiler :

Replace
Code:
                if (len(tLeaders[iPlayer]) > 1):
                        if (len(tLateLeaders[iPlayer]) > 5):
                                if (iGameTurn >= tLateLeaders[iPlayer][5]):
                                        self.switchLateLeaders(iPlayer, 4)
                                elif (iGameTurn >= tLateLeaders[iPlayer][1]):
                                        self.switchLateLeaders(iPlayer, 0)
                        else:
                                if (iGameTurn >= tLateLeaders[iPlayer][1]):
                                        self.switchLateLeaders(iPlayer, 0)
with
Code:
                if (len(tLeaders[iPlayer]) > 1):
                        if (len(tLateLeaders[iPlayer]) > 9):
                                if (iGameTurn >= tLateLeaders[iPlayer][9]):
                                        self.switchLateLeaders(iPlayer, 8)
                                elif (iGameTurn >= tLateLeaders[iPlayer][5]):
                                        self.switchLateLeaders(iPlayer, 4)
                                elif (iGameTurn >= tLateLeaders[iPlayer][1]):
                                        self.switchLateLeaders(iPlayer, 0)
                        elif (len(tLateLeaders[iPlayer]) > 5):
                                if (iGameTurn >= tLateLeaders[iPlayer][5]):
                                        self.switchLateLeaders(iPlayer, 4)
                                elif (iGameTurn >= tLateLeaders[iPlayer][1]):
                                        self.switchLateLeaders(iPlayer, 0)
                        else:
                                if (iGameTurn >= tLateLeaders[iPlayer][1]):
                                        self.switchLateLeaders(iPlayer, 0)
 
I'm changing it now, but it looks like the bit in riseandfall.py looks exactly like the bit I'm supposed to replace it with. Did you make a mistake, or is there a small change I didn't see?
 
@Panopticon

The two additional numbers that are in tLateLeaders for each leader have to do with the chance of switching each turn. The first number is the base chance out of 100 each turn that the leader will switch. The second denotes an certain era. If the civ in question is currently in or past that era, the chance per turn in doubled. (I think it starts with ancient=0, but it could be 1)

For example, (iGandhi, i1700AD, 5, 4) means that after 1700, there is a base chance of 5% each turn that the leader will switch to Gandhi, which is doubled if India is at least in the industrial era.
 
First: thanks for this tutorial, Panopticon :)

But is it still up to date? I tried to do exactly what you said, but it doesn't work. For example, I've added Jimmu and Meiji as Japanese leaders. The consts.py file now looks as follows:

Spoiler :
Code:
[...]
iZara_Yaqob = 52
iJimmu = 53
iMeiji = 54
iAkbar = 55
iHiram = 56
iHaile_Selassie = 57
iGustav = 58
iAbu_Bakr = 59
iMongkut = 60
iElishat = 61
iPhilip = 62
iBarbarossa = 63
iCharles = 64
iFrancis = 65
iYaroslav = 66
iAfonso = 67




tLeaders = (
(iRamesses, iHatshepsut),
(iAsoka, iAkbar, iGandhi),
(iQin_Shi_Huang, iMing_Tai_Zu, iMao),
(iHammurabi, iGilgamesh),
(iPericles, iAlexander,),
(iCyrus, iDarius),
(iElishat, iHannibal,),
(iAugustus, iJulius_Caesar, iJustinian),
(iJimmu, iTokugawa, iMeiji),
(iZara_Yaqob, iHaile_Selassie),
(iPacal,),
(iRagnar,),
(iAbu_Bakr, iSaladin,),
(iSuryavarman,),
(iIsabella, iPhilip),
(iLouis_Xiv, iNapoleon, iDe_Gaulle),
(iVictoria, iElizabeth, iChurchill),
(iBismarck, iOttoI, iFrederick),
(iStalin, iPeter, iCatherine),
(iWillem_Van_Oranje,),
(iMansa_Musa,),
(iAfonso, iJoao,),
(iHuayna_Capac,),
(iGenghis_Khan, iKublai_Khan),
(iMontezuma,),
(iMehmed, iSuleiman),
(iFranklin_Roosevelt, iWashington, iLincoln))

tEarlyLeaders = (
(iRamesses), 
(iAsoka),
(iQin_Shi_Huang),
(iGilgamesh),
(iPericles),
(iCyrus),
(iElishat),
(iJulius_Caesar),
(iJimmu),
(iZara_Yaqob),
(iPacal),
(iRagnar),
(iAbu_Bakr),
(iSuryavarman),
(iIsabella),
(iLouis_Xiv),
(iElizabeth),
(iOttoI),
(iPeter),
(iWillem_Van_Oranje),
(iMansa_Musa),
(iAfonso),
(iHuayna_Capac),
(iGenghis_Khan),
(iMontezuma),
(iMehmed),
(iWashington))


if (gc.getPlayer(0).isPlayable()): #late start condition
        tRomanLateLeaders = (iAugustus, i50AD, 5, 2, iJustinian, i1000AD, 10, 3)
else: 
        tRomanLateLeaders = (iAugustus, i50AD, 5, 2)


tLateLeaders = ( #all up to 300 turns earlier because the switch is triggered after a few years
(iHatshepsut, i400BC, 5, 1), 
(iAkbar, i1400AD, 5, 3, iGandhi, i1700AD, 5, 4),
(iMing_Tai_Zu, i1400AD, 10, 3, iMao, i1800AD, 10, 5),
(iHammurabi, i1600BC, 10, 1),
(iAlexander, i10BC, 5, 2),
(iDarius, i10BC, 5, 2),
(iHannibal, i400BC, 10, 1),
tRomanLateLeaders,
(iTokugawa, i1200AD, 10, 3, iMeiji, i1760AD, 10, 4),
(iHaile_Selassie, i1800AD, 10, 4),
(iPacal,),
(iRagnar,),
(iSaladin, i1000AD, 10, 2),
(iSuryavarman,),
(iPhilip, i1400AD, 10, 3),
(iNapoleon, i1700AD, 10, 4, iDe_Gaulle, i1940AD, 10, 5),
(iVictoria, i1600AD, 15, 3, iChurchill, i1930AD, 10, 5),
(iFrederick, i1500AD, 10, 3, iBismarck, i1760AD, 10, 4),
(iCatherine, i1600AD, 15, 4, iStalin, i1800AD, 15, 5),
(iWillem_Van_Oranje,),
(iMansa_Musa,),
(iJoao, i1400AD, 10, 2),
(iHuayna_Capac,),
(iKublai_Khan, i1500AD, 10, 3),
(iMontezuma,),
(iSuleiman, i1500AD, 10, 3),
(iLincoln, i1800AD, 15, 5, iFranklin_Roosevelt, i1900AD, 15, 5))
The problem is, Japan still starts with Tokugawa, both when played by the AI or the HI. I didn't test the other implemented switches, but I'd be surprised if they worked.
I haven't changed anything in RiseAndFall.py yet, though - but this shouldn't be necessary as long as every civ has only three leaders, right?

PS: sorry for the necromancy ;)
 
Are leaders indexed correctly in Civ4LeaderHeadInfos.xml? For instance, is the Jimmu XML immediately after Zara Yaqob? Try putting Tokugawa first in the tLeaders list for Japan; standard practice is to put the leader who appears on the opening screen first on that list, and if something is going wrong here you can at least work out that this is where the problem is. You should test the other switches; if it takes too long, temporarily move the dates closer to 600AD and use the late start. You understand that this isn't a lot of information for me to work with, so these are just guesses as to what is going wrong.
 
Of course. Lack of information is exactly my problem, for I've really no idea what might have gone wrong.

The iJimmu etc. variables are initialized exactly as they appear after Zara in the XML file, so that isn't the problem. I've restored Tokugawa back to the begin of Japan's tLeaders array and am currently testing what happens.

Thanks :)
 
That did it! Seems you're not supposed to change the leader for the civ selection screen (though I never understood why, say, Britain had to start with Victoria when controlled by the human).

Edit: I also implemented your switch algorithm for 4 leaderheads and thus was able to add medieval leaderheads for most European civs. I just started a Dutch game and was immediately greeted by Alfred the Great, Charlemagne, Charles V and Yaroslav the Wise. Awesome!
 
How do you install the art for a new leader? I have the files and I placed it into Assets/Art/leaderheads, but I can't figure out where to edit in the ArtDefines XML stuff for the leaderhead.
 
Hey Leoreth or Panopticon!
So the main rules, just to be sure:

Leaders are in the exact same order as in the LeaderheadInfos.xml
The tLeaders have to contain all leaders for the civs, and the first one has to be the "primary" leader for that civ in each line. This is just for the human player (start screen) if I get it right
The tEarlyLeader is the leader which the civ will start with. This doesn't have to be the primary leader of the civ, right?
The TLateLeader is all the other leaders with (name, date, percentage, era). All leaders for the same civs should go in the same line here too.

Also, how do I know which one is supposed to be the primary leader of the civ? Where can I check it?
(note this is for RFCE, so all the base RFC leaders were changed)
 
You're right in all your guesses.

The so called "primary" leader is the one to which the civ is set in the worldbuilder file. As you already said, the primary leader has no effect other than what LH the player sees when selecting his civ.
 
Thanks for the quick answer, I will try it out soon :goodjob:

That did it! Seems you're not supposed to change the leader for the civ selection screen (though I never understood why, say, Britain had to start with Victoria when controlled by the human).

So this post isn't relevant anymore?
If the primary leaders are set only in the worldbuilder file, you don't really have to start for Britain with Victoria, you can go with any leader you want by simply changing it in the wb file, altough I may be mistaken here.
My point is you don't necessary have to adjust the leaders in the python to the wb file, you can also do that the other way around (without messing up anything in the background)?
 
Yeah, I just wasn't aware of that fact back then :)
 
Hm, I was testing this tonight, and the mod doesn't start a game right now. After civ selection it crashes on the loading screen
I only added the last 4 leaders for now, and if I revert the python changes everything works and seems fine in the civilopedia, so there are no xml bugs...
This is the Consts.py with my changes:

Spoiler :
Code:
...
iGustavus=32
iSuleiman=33
iDandolo=34
iThe_Pope=35
iHarald_Hardrada=36
iIvan_Iv=37
iGeorge_Iii=38
iMaria_Ii=39
iAndrea_Dandolo=40
iHaakon_Iv=41

tLeaders = (
(iCharles_V,),
(iJustinian,),
(iCharlemagne,iJoan,iLouis_Xiv),
(iAbuBakr,iSaladin),
(iSimeon,),
(iAbdarRahman,iAbuYusufYaqub),
(iIsabella,iPhilip_Ii),
(iHarald_Hardrada,iHaakon_Iv,iChristian_Iv),
(iDandolo,iAndrea_Dandolo),
(iYaroslav,),
(iStephen,iMatthias),
(iBarbarossa,iFrederick,),
(iCasimir,iSobieski),
(iIvan_Iv,iPeter,iCatherine),
(iSimone,),
(iWilliam,iElizabeth,iGeorge_Iii),
(iAfonso,iJoao,iMaria_Ii),
(iMaximilian,iMaria_Theresa),
(iMehmed,iSuleiman,),
(iGustavus,),
(iWillem_Van_Oranje,),
(iThe_Pope,)
)

tEarlyLeaders = (
(iCharles_V),
(iJustinian),
(iCharlemagne),
(iAbuBakr),
(iSimeon),
(iAbdarRahman),
(iIsabella),
(iHarald_Hardrada),
(iDandolo),
(iYaroslav),
(iStephen),
(iBarbarossa),
(iCasimir),
(iIvan_Iv),
(iSimone),
(iWilliam),
(iAfonso),
(iMaximilian),
(iMehmed),
(iGustavus),
(iWillem_Van_Oranje),
(iThe_Pope)
)

tLateLeaders = ( #all up to 200 years earlier because the switch is triggered after a few years
(iCharles_V,),
(iJustinian,),
(iJoan,i1160AD,10,3,iLouis_Xiv,i1452AD,25,3),
(iSaladin,i1160AD,25,2),
(iSimeon,),
(iAbuYusufYaqub,i1101AD,10,2),
(iPhilip_Ii,i1520AD,10,3),
(iHaakon_Iv,i1160AD,25,2,iChristian_Iv,i1520AD,5,3),
(iAndrea_Dandolo,i1160AD,10,2),
(iYaroslav,),
(iMatthias,i1419AD,25,3),
(iFrederick,i1520AD,5,3),
(iSobieski,i1570AD,10,3),
(iPeter,i1520,10,3,iCatherine,i1700AD,25,3),
(iSimone,),
(iElizabeth,i1452AD,10,3,iGeorge_Iii,i1700AD,10,3),
(iJoao,i1419AD,10,3,iMaria_Ii,i1700AD,10,3),
(iMaria_Theresa,i1700AD,25,3),
(iSuleiman,i1520AD,15,3),
(iGustavus,),
(iWillem_Van_Oranje,),
(iThe_Pope)
)

I double checked the LHs order in the leaderheadinfos.xml, and everything related to leaders in the worldbuilder file
Do you have any idea what else should be changed?
 
My first guess is this line (fix in red).
Code:
tLateLeaders = ( #all up to 200 years earlier because the switch is triggered after a few years
(iCharles_V,),
(iJustinian,),
(iJoan,i1160AD,10,3,iLouis_Xiv,i1452AD,25,3),
(iSaladin,i1160AD,25,2),
(iSimeon,),
(iAbuYusufYaqub,i1101AD,10,2),
(iPhilip_Ii,i1520AD,10,3),
(iHaakon_Iv,i1160AD,25,2,iChristian_Iv,i1520AD,5,3),
(iAndrea_Dandolo,i1160AD,10,2),
(iYaroslav,),
(iMatthias,i1419AD,25,3),
(iFrederick,i1520AD,5,3),
(iSobieski,i1570AD,10,3),
(iPeter,i1520,10,3,iCatherine,i1700AD,25,3),
(iSimone,),
(iElizabeth,i1452AD,10,3,iGeorge_Iii,i1700AD,10,3),
(iJoao,i1419AD,10,3,iMaria_Ii,i1700AD,10,3),
(iMaria_Theresa,i1700AD,25,3),
(iSuleiman,i1520AD,15,3),
(iGustavus,),
(iWillem_Van_Oranje,),
(iThe_Pope[COLOR="Red"],[/COLOR])
)

The comma has to be there so that the game recognizes it as a tuple and not a singular entry.
 
Thanks, I will try adding commas to civs with no leader cycling

EDIT: I just found out that the bug is probably not on my end
Leaderhead switching doesn't even work for 3 leaders in base RFCE right now!!
I will try messing around with the RiseAndFall.py, there is a good chance something is wrong there...

EDIT2: The comma did not help
 
Odd
If I replace the code with the 4 leader switching version in the RiseAndFall.py, even switching 2 leaders won't work (so not even the original consts.py file in RFCE)
 
Back
Top Bottom