Finding Colony Leader Generation Code

Lemon Merchant

Not Quite Sonic
Retired Moderator
Joined
Jun 27, 2008
Messages
8,773
Location
Red Sector A
A user of my mod (Better BAT AI) was playing as Cyrus when a colony was created - with Cyrus as a leader.

Obviously, this is a bug, and I'm trying to stomp it, but I can't seem to find the code in the SDK that handles the assignment of a colony leader. Or is it in Python?

Any attempts to point me in the right direction would be greatly appreciated. :)
 
If I get this right, what you say is that one LeaderHead ended up for more than one player.

I would assume that if the game is to assign a random or semi random LeaderHead, it will loop all candidates. I then searched for GC.getNumLeaderHeadInfos(), which luckily is not used very often.

CvPlayer::getSplitEmpireLeaders(): This function does indeed loop all players and discard all leaders who are set to rule any player, dead or alive. Looks ok to me.

Two more functions, which only applies for !isBarbarian() && !isMinorCiv(). Doesn't look like what you search for either (assuming colony is minor civ)

CvPlayer::changePersonalityType( )
This one leaves out !isMinorCiv() and only checks !isBarbarian(). It loops all LHs and assigns a random value to each in the interval 0 to < 10000. It will then pick the LH with the highest value. It does check to see if the leader is already used, but only in living players. It ignores dead ones (which could be argued to be ok). If the LH is in use, the value is cut in half, not set to 0.

From what I read from this, say by chance the highest number is 8000 and the second highest is 3000, then it would go for the 8000 LH. If that LH is already in use, the number would drop to 4000, but it would still be the highest number and two players could end up with the same leader. It's unlikely, but possible. Also it requires GAMEOPTION_RANDOM_PERSONALITIES to be active.

Looks to me like this could very well be a vanilla bug. Or is it a design issue, since they are aware that they are setting the same LH to two players? Could be some early code to allow testing with just a few LHs and then it was so unlikely that their test phase never encountered this bug.
 
Thanks for the information, Nightinggale. I thought that it might be a vanilla bug, as nothing in BBATAI touches the colony logic. I'll take a look at the code you referenced and make sure that I can follow along with your explanation.

I should have mentioned that the user was playing with the Unrestricted Leaders option on.

Again, many thanks for your help. :)
 
Back
Top Bottom