Changing Leader Mid-Game

DarkAlzara

Chieftain
Joined
Jul 1, 2020
Messages
39
Hey all,

Just a question. Does anybody know if it is possible to code a leader change mid-game. Like, say a civilization fulfills a certain criteria and their leader changes to somebody different?

Thanks all! :)

Al
 
changing the DB mid game has no effect.

As for the reason there is no method to do that in game, how could we know ? Simple answer is "they do not need it"

Maybe there is 3D engine issue with swapping leader head, code issue with applying LUA, etc, etc...

You can try: PlayerConfigurations:SetLeaderTypeName(LeaderType), but I suppose it's working for setup only (it's in UI context, ie not meant for gameplay changes), and won't do anything in game (or crash).
 
so there is no way to update the database mid-game? Link to a new leader? I was hoping for a more specific response than “no, go ask firaxis”...

As a one-line rule, my understanding is that the database cannot be updated once a game has been loaded. I have not delved into Lua-based modding, which I understand is the way to make the most 'dynamic' changes mid-game, but I think these functions are still limited to reading from the existing database.

Now, I'm definitely not an expert when it comes to the boundaries of what is possible, but in this scenario - and it's not something I've considered, until composing this reply - I would expect the limitation is imposed because the leader (actually, the Player) is written to a database that contains the game's configuration at the point a game is started. The moment this happens, the game commits some information to the database - which Player is in slot 1, which Player is in slot 2, etc.

Because there is a database-written action that homes a Player to a slot - and, presumably, there is logic that means the foundation of what makes up a 'Player' comprises a single Leader (which inherits their unique 'things', the civilization they lead and that civilization's unique 'things') - I think that means we arrive at a point where changing the leader, based on some condition being triggered, is not possible.

Hypothetically, if it was possible for one Player to consist of multiple leaders, then additional database entries that describe the various conditions that 'select' the active leader at a given time may be achievable - but I daresay this would involve substantial re-work of the
 
Ok excellent replies thank you! I may look into this in more detail eventually. It’s something that would be very useful for what Im Trying to achieve.
 
As a one-line rule, my understanding is that the database cannot be updated once a game has been loaded. I have not delved into Lua-based modding, which I understand is the way to make the most 'dynamic' changes mid-game, but I think these functions are still limited to reading from the existing database.

Now, I'm definitely not an expert when it comes to the boundaries of what is possible, but in this scenario - and it's not something I've considered, until composing this reply - I would expect the limitation is imposed because the leader (actually, the Player) is written to a database that contains the game's configuration at the point a game is started. The moment this happens, the game commits some information to the database - which Player is in slot 1, which Player is in slot 2, etc.

Because there is a database-written action that homes a Player to a slot - and, presumably, there is logic that means the foundation of what makes up a 'Player' comprises a single Leader (which inherits their unique 'things', the civilization they lead and that civilization's unique 'things') - I think that means we arrive at a point where changing the leader, based on some condition being triggered, is not possible.

Hypothetically, if it was possible for one Player to consist of multiple leaders, then additional database entries that describe the various conditions that 'select' the active leader at a given time may be achievable - but I daresay this would involve substantial re-work of the

and just an immediate thought I’ve had regarding this: there are already instances of civilizations with multiple leaders: like Elanore. Also I know that Anno domini has a wealth of leaders for some civs. Maybe this is a good place for me to start my investigation...
 
and just an immediate thought I’ve had regarding this: there are already instances of civilizations with multiple leaders: like Elanore. Also I know that Anno domini has a wealth of leaders for some civs. Maybe this is a good place for me to start my investigation...

It's correct that there's both civilizations with multiple choices of leader and also leaders that can lead multiple civilizations - but I think the point is that each combination of one-leader-and-one-civilization represents one entry into the Players list at the point the game is configured. I think that's the limiting factor - I don't think the ability to overlap leaders with civilizations changes that, unfortunately. No matter how many leaders are available and no matter which civilizations they can lead, a Player slot still consists of one leader in charge of one civilization.

I'd recommend starting with exploring the Lua command Gedemon mentioned earlier - my replies are just observations and logic based on a level of assumption; no cold, hard facts, as it were. But well-intentioned to try and save you a wild goose chase.
 
Last edited:
It's correct that there's both civilizations with multiple choices of leader and also leaders that can lead multiple civilizations - but I think the point is that each combination of one-leader-and-one-civilization represents one entry into the Players list at the point the game is configured. I think that's the limiting factor - I don't think the ability to overlap leaders with civilizations changes that, unfortunately. No matter how many leaders are available and no matter which civilizations they can lead, a Player slot still consists of one leader in charge of one civilization.

I'd recommend starting with exploring the Lua command Gedemon mentioned earlier - my replies are just observations and logic based on a level of assumption; no cold, hard facts, as it were. But well-intentioned to try and save you a wild goose chase.

Still, it points me in the right direction and gives me food for thought! Thanks for all the help! I’ll start looking into it!
 
if it is possible to code a leader change mid-game. Like, say a civilization fulfills a certain criteria and their leader changes to somebody different?
[...]
So, do we know if this is remotely possible?
[...]
so there is no way to update the database mid-game? Link to a new leader? I was hoping for a more specific response than “no, go ask firaxis”...

As written 'changing the DB mid game' does not work. At least not directly. This issue has been mentioned already:
Lua cannot alter anything in the Database. So you cannot use lua to alter data in any of the game-tables.
I'd like to add that in some rare exotic cases, in which you want a very slowly (say twice in a whole game or every 36 turns) changing parameter in the Database, you can work around that limitation by stopping the game, manually editing Database-defining .xml/.sql files & reloading the game.
Yes but that's not altering the database by lua code. That's directly editing the contents of the database by using database methods in SQL or XML files.
All LeeS has written is correct & true. I don't want to take issue at all with that - I just want to add my thought on a "remotely possible" solution to the given task "say a civilization fulfills a certain criteria and their leader changes to somebody different?" ...
- No, the leader changes not at all, because he may not from the standpoint of the game - formally you have only one
- Yes, if you have different sets of files with different attributes as abilities or pictures, you can swap them while the game is not running - same vessel, but different content. It has the effect of a changing leader.

You can use a Lua script notifying the player to save and stop civ6 when "a civilization fulfills a certain criteria" & writing a short unique keyword to Lua.log
A shell-script/batch-file (OS level) can then analyze the correlating Lua.log file and rename the right files of leader definitions (ie. "changing leader") WITHOUT the player even knowing what was done when he reloads the game and continues play. He just runs a tiny tool between two civ6 sessions ...

.
 
As written 'changing the DB mid game' does not work. At least not directly. This issue has been mentioned already:



All LeeS has written is correct & true. I don't want to take issue at all with that - I just want to add my thought on a "remotely possible" solution to the given task "say a civilization fulfills a certain criteria and their leader changes to somebody different?" ...
- No, the leader changes not at all, because he may not from the standpoint of the game - formally you have only one
- Yes, if you have different sets of files with different attributes as abilities or pictures, you can swap them while the game is not running - same vessel, but different content. It has the effect of a changing leader.

You can use a Lua script notifying the player to save and stop civ6 when "a civilization fulfills a certain criteria" & writing a short unique keyword to Lua.log
A shell-script/batch-file (OS level) can then analyze the correlating Lua.log file and rename the right files of leader definitions (ie. "changing leader") WITHOUT the player even knowing what was done when he reloads the game and continues play. He just runs a tiny tool between two civ6 sessions ...

.

Clever! Now all I need is a force-save and force-quit prompt! :)
 
I'd like to add that in some rare exotic cases, in which you want a very slowly (say twice in a whole game or every 36 turns) changing parameter in the Database, you can work around that limitation by stopping the game, manually editing Database-defining .xml/.sql files & reloading the game.
I'm curious to know if the modifiers are correctly removed and re-applied for Leaders Unique Attributes.

If that the case, then simply using PlayerConfigurations:SetLeaderTypeName(LeaderType) then saving/reloading *may* work without the need to quit the game and could be fully automated.
 
I'm curious to know if the modifiers are correctly removed and re-applied for Leaders Unique Attributes.
Well, That IS the question. What happens, when you create entirely new modifiers, which in worst case contradict modifier setups already applied to existing game objects?
Has to be tested individually, in general I'd rather avoid such potential conflicts. I mean, Leader Attributes (if not just used as index into array) are not only simple content, they may be part of the vessel. Graphical stuff like icons, pictures, animations are probably simple content as numerical values.

I don't expect a game started e.g. with <Row Name="CITY_AMENITIES_FOR_FREE" Value="1" /> to show problems when it is later continued additionally with UPDATE GlobalParameters SET Value = 0 WHERE Name ='CITY_AMENITIES_FOR_FREE';
Likewise THRESHOLD_SHIFT_PER_PAST_GOLDEN_AGE, BARBARIAN_CAMP_MINIMUM_DISTANCE_CITY ...Unit Maintenance, CombatStrength, Healing, GainingEXP ... I see a lot of interesting parameters which could use some change during a game (for the human player).

.
 
If the leader choices are custom leaders and not the existing ones, you can use RequirementSets to only activate certain abilities under certain conditions. When a RequirementSet is used, the Modifiers are still loaded by the database,just not actually "turned on" unless the requirement conditions are met.

This wouldn't solve the issue of graphics.
 
Top Bottom