Civic Linked Leaders: Effort

Tholish

Emperor
Joined
Jul 5, 2002
Messages
1,344
Location
Japan
I'm going to try to make a modcomp that makes civic linked leaders. Here's the idea.
Each civ has multiple leaders, one of whom (the earliest era one) is the default. The others are not available until you get a certain civic. Whenever you change to the civic associated with one of these leaders, your civ automatically changes to that leader and remains led by that leader until a civic change switches you to another leader.

So, for example, you have Britain which starts with Boudica as default leader. Upon switching to Monarchy you get Elizabeth. On switching to Free Market you get Victoria and Nationalism gets you Churchill.

I'm thinking of using this as the changed XML in CivilizationInfos

Code:
<Leaders>
	<Leader>
	             <LeaderName>LEADER_BOUDICA</LeaderName>
		<bLeaderAvailability>1</bLeaderAvailability>
		<CivicAvailability>CIVIC_TRIBALISM</CivicAvailability>
	</Leader>
	<Leader>
	             <LeaderName>LEADER_ELIZABETH</LeaderName>
		<bLeaderAvailability>0</bLeaderAvailability>
		<CivicAvailability>CIVIC_HEREDITARY_RULE</CivicAvailability>
	</Leader>
	<Leader>
	             <LeaderName>LEADER_VICTORIA</LeaderName>
		<bLeaderAvailability>0</bLeaderAvailability>
		<CivicAvailability>CIVIC_FREE_MARKET</CivicAvailability>
	</Leader>
	<Leader>
	             <LeaderName>LEADER_CHURCHILL</LeaderName>
		<bLeaderAvailability>0</bLeaderAvailability>
		<CivicAvailability>CIVIC_NATIONALISM</CivicAvailability>
	</Leader>
</Leaders>
I will have to write a function into the dll that returns CivicAvailability but I think the rest can be done with Python. There is code in RevDCM for changing a leader, which I can probably adapt to do this.

I'm thinking of making Anarchy be the trigger. Any time a civ is in anarchy, a check is made to see if the CivicAvailability of any of the civs leaders matches a current civic and then if so just add the leader and switch the civ to it.

If I can get this to work, the next step is to change the civ name to match the leader, so that Boudica leads the British Tribes, Elizabeth leads the Kingdom of England, Victoria leads the British Empire, and Churchill leads Great Britain.
 
Pretty interesting idea. For changing a leader you only need this function in CvPlayer.cpp:

Code:
//Androrc Change Leader
void CvPlayer::setLeaderType(LeaderHeadTypes eLeader)
{
	for (int iI = 0; iI < GC.getNumTraitInfos(); iI++)
		{
			if (GC.getLeaderHeadInfo(getLeaderType()).hasTrait(iI))
			{
				processTrait((TraitTypes) iI, -1);
			}
		}
	GC.getInitCore().setLeader(getID(), eLeader);
	GC.getInitCore().setLeaderName(getID(), GC.getLeaderHeadInfo(getLeaderType()).getDescription());
	for (int iI = 0; iI < GC.getNumTraitInfos(); iI++)
		{
			if (GC.getLeaderHeadInfo(getLeaderType()).hasTrait(iI))
			{
				processTrait((TraitTypes) iI, 1);
			}
		}
}
//Androrc End

And this in CvPlayer.h:
Code:
	void setLeaderType(LeaderHeadTypes eLeader);

For getting it to work with Civics, you could add this code to CvPlayer::setCivic, so that it changes the leader according to civic (but with this code you would need to put the civic required in the LeaderHeadInfos.xml file):

Code:
	for (int iI = 0; iI < GC.getNumLeaderHeadInfos(); iI++)
	{
		if (GC.getLeaderHeadInfo((LeaderHeadTypes) iI).getCivic() == eNewValue && GC.getCivilizationInfo(getCivilizationType()).isLeaders(iI))
		{
			LeaderHeadTypes eLeader = (LeaderHeadTypes) iI;
			setLeaderType(eLeader);
		}
	}

Then you would have to get the Civic in the LeaderHeadInfos.xml, and have a getCivic function in Infos.cpp for CvLeaderHeadInfo.
 
I was planning to do it another way, but there you are, I'll just try this. In fact, there's already a tag for Favorite Civic and probably all the other stuff needed if I just use that.

EDIT: theres no such thing as processTrait, but I don't think its necessary. In looking for it I saw how often traits are checked against the leader and I think just changing the leader will do it.
 
OK, I compiled it, tested it, and uploaded it. Thanks a lot Androrc. This will prove invaluable!

http://forums.civfanatics.com/downloads.php?do=file&id=14294

EDIT: only issue I can see is that maybe my decision to use FavoriteCivic will mean the AI never switches away. But as I understand it favorite civic is mostly about diplomacy, its a favorite civic in others. We'll see.

ANOTHER EDIT: well, its not absolute, but its a strong tendency. I set up all female leaders to prefer Tribalism, then played a future start against them. Cathy turned into Peter, but the others kept tribalism while changing all other civics (checked by saving in wb and looking at the text file)

Also, ideally I would want to have an extra really bad default civic and one leader whose civic is free at game start so that regardless of leader chosen, as soon as the game starts the civ changes the proper ancient era leader.

So, like you said I need to clone the relevant FavoriteCivic related functions and add a new tag into the schema and XML "TriggerCivic."

YET ANOTHER EDIT: OK, I've done that. In doing it I saw the actual code where favorite civic is preferred. Now it opens up this whole design problem. In LeaderheadInfos I've got Favorite Civic and Trigger Civic right next to each other. Trigger Civic is the one that causes a switch to the leader, Favorite Civic is the one the leader wants to go to. So the thing to do is make sure no leader ever has the same trigger civic and favorite civic. A simple application is to just chain them, so Boudica (the early british leader) has a trigger of Tribalism and a favorite of Vassalage, which is Elizabeths trigger, but her favorite civic is Free Market. So when she takes over she can't switch to her favorite civic right away, but when she can it triggers a switch to Victoria whose trigger civic is free market, but whose favorite civic is emancipation. Emancipation happens to be the trigger civic for Churchill, who has no favorite civic. Or the American Hiawatha (Sitting Bull) triggers at Tribalism and his favorite is Representation, which Triggers Washington whose favorite is Emancipation, which Triggers Lincoln whose favorite is State Property, which is the trigger for Roosevelt.

What these possibilities lead to is the need for more leaders per civ, but for a proof of concept mod I don't want to load up a bunch of leaderheads, so I'll just consolidate existing civs and leaders, maybe throw in a couple from official mods, clone rename and rebackground a few.

In addition to having the civ name switch I'll have to rewrite city lists to reflect modern city names, in an order based on centrality to the area of the civ. Thus my south American civ will have city names based on major modern cities, starting with Lima and expanding outward to cities in the area that are farther away. When they switch to Bolivar the city list won't be a misfit. By the time they get to Vargas, Sao Paolo and Buenos Aires will be in their area. Same with the Hittites/Ottomans/Turks, but their city list and the Greek/Byzantine city list will overlap, as the Roman/Italian list will overlap with the Greeks, and with Gaul/France and Britain/England and even Egypt/Arabia and Babylon/Persia and Phonecia(ruled by a renamed Gilgamesh)/Carthage/Moors(Mansa)/Spain. The latter will go like "Beirut,Tripoli,Madrid".
 
I don't think the code I sent you will change the leader's personality, but in order for it to do so it is just a simple line you have to include:

Code:
//Androrc Change Leader
void CvPlayer::setLeaderType(LeaderHeadTypes eLeader)
{
	for (int iI = 0; iI < GC.getNumTraitInfos(); iI++)
		{
			if (GC.getLeaderHeadInfo(getLeaderType()).hasTrait(iI))
			{
				processTrait((TraitTypes) iI, -1);
			}
		}
	GC.getInitCore().setLeader(getID(), eLeader);
	GC.getInitCore().setLeaderName(getID(), GC.getLeaderHeadInfo(getLeaderType()).getDescription());
[COLOR="Lime"]	setPersonalityType(eLeader);[/COLOR]
	for (int iI = 0; iI < GC.getNumTraitInfos(); iI++)
		{
			if (GC.getLeaderHeadInfo(getLeaderType()).hasTrait(iI))
			{
				processTrait((TraitTypes) iI, 1);
			}
		}
}
//Androrc End
 
Top Bottom