I want to change the civics using events

liwy

Chieftain
Joined
Nov 15, 2009
Messages
63
Location
Brussels
Hello fellow modders! Could you help me to make a (multiple?) civic changer function that will activate during events. The objective is to implement events such as fascist coup/march on the capital (granting maybe a few free units).
In fact through this process I hope to make fascism a series of events more than a "technology", an idea that is questionnable at best (even if I will not remove it from the tech list).

In addition as I reread the xml structure of CIV4EventsTriggerInfos.xml, I realised there was no way for an event to select a city controled by an other that as an certrain amount of the culture's player, the objective here should be the creation of an Irrendentist event for the nationalistic states

My last attempt for a function to change the civic

Code:
def applyDictatorRise(argsList):
	iEvent = argsList[1]
	kTriggeredData = argsList[0]
	trigger = gc.getEventTriggerInfo(kTriggeredData.eTrigger)
	player = gc.getPlayer(kTriggeredData.ePlayer)
	
	iCivicOption = CvUtil.findInfoTypeNum(gc.getCivicOptionInfo,gc.getNumCivicOptionInfos(),'CIVICOPTION_GOVERNMENT')
	iCivic = CvUtil.findInfoTypeNum(gc.getCivicInfo,gc.getNumCivicInfos(),'CIVIC_POLICE_STATE')
	
	for iPlayer:
		gc.getPlayer(iPlayer).setCivics(iCivicOption, iCivic)




The trigger for the irredentism event

Code:
def canTriggerIrredentism(argsList):
	
	pPlayer1 = gc.getPlayer
	pPlayer2 = gc.getPlayer(iOwner)
	iTeam1 = pPlayer1.getTeam()
	iTeam2 = pPlayer2.getTeam()
        owner = gc.getPlayer(iOwner)
        pCity = argsList
	
	if pCity.calculateTeamCulturePercent(iTeam1) > 20:
		return true
	return false
 
Too many obvious errors at quick glance.
For loop is one.
pPlayer1 is another.
pCity as well...
 
I have tried the suggested modification of lfgr (I hope that I pronounced it right.) but it still doesn't work.
 
You are right I should be more detailed.
The civic changing function doesn't change anything even if I rechecked twice the test event I created. It requires to put the name of the function in the python callback tags, am I right? like this: <PythonCallback>applyHostileTakeoverDone1</PythonCallback>
 
Well the error message say: "AttributeError: 'int' object has no attribute 'eTrigger'
I as I only partially know how it works, I have no idea how to deal with this, except by gently asking, and already thanking you for your help...
 
You don't need that line trigger = gc.getEventTriggerInfo(kTriggeredData.eTrigger).

I don't even think that you need iEvent = argsList[1].

Then apply the last line as ifgr said.

I don't know how you test it because the function canTriggerIrredentism is still to be rewritten.
 
I know the second one still need to be reworked, python is puzzling enough to not try to run to new functions at the same time.

Well now the error message say that there are no attributes for "ePlayer"
 
Yes, but your event is depending upon the eventtrigger. If nothing is triggered, you don't have data.
 
There are ways to trigger an event directly with python, bypassing the canXXX requirements.
 
Good to know but with events, it is relatively easy to set them to trigger at first sight!

But you do need data, right?

This code works:

Code:
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	
	gc.getPlayer(kTriggeredData.ePlayer).setCivics(gc.getInfoTypeForString("CIVICOPTION_GOVERNMENT"), gc.getInfoTypeForString("CIVIC_POLICE_STATE"))

ePlayer is defined because I made sure that a dummy eventtrigger worked in the first place (at least, this is how I see it).

I didn't define anything before the setCivics function because I'm a bit superstitious about that: it serves only once, so I don't like to push the memory to its limits...

More importantly: this code makes you switch to CIVIC_POLICE_STATE even if you have not researched the appropriate tech.

Now, I have to figure out what are exactly the conditions you want for this to apply. So far, it picks a random city in your Civ. I think it could be a random city in another Civ as well.
 
This is even better if it force the civic, so communist revolutionaries might join the modern tyranny contest earlier (spoiler, the first and the second wore moustaches). It seems pretty obvious that such major change should be caused by an internal change, especially in the capital but I thought that I would control such parameters using the xml.
 
This code could work for your canTriggerIrredentism:

Code:
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	
	pCity = gc.getPlayer(kTriggeredData.ePlayer).getCity(kTriggeredData.iCityId)
	pPlot = pCity.plot()

	for iPlayerX in xrange(gc.getMAX_CIV_PLAYERS()):
		if iPlayerX == kTriggeredData.ePlayer: continue
		if not gc.getPlayer(iPlayerX).isAlive(): continue
		if pPlot.getCulture(iPlayerX,) > pPlot.getCulture(kTriggeredData.ePlayer,) and pCity.isDisorder():
			return true

	return false

It checks that 1) you don't have the highest culture in your capital 2) it is currently in disorder.

In the CvEventTriggerInfos, I set the tags <bPickCity> to 1, <iAngry> to 1 plus this to check for the capital city:
Code:
			<BuildingsRequired>
				<BuildingClass>BUILDINGCLASS_PALACE</BuildingClass>
			</BuildingsRequired>
			<iNumBuildings>1</iNumBuildings>

Hope it works for you.
 
What are the "," doing in the codes, fail :D
 
But it works like that, I tested it with a message!

What "fails" is that as soon as possible, the civic will switch back to a valid one if fascism is not yet researched.

Edit: it's true that it also works without the two commas!
 
It wont work also when there are forced civics active.
 
A solution could be to grant the required technology like this:

Code:
	iPlayer = kTriggeredData.ePlayer
	gc.getTeam(gc.getPlayer(iPlayer).getTeam()).setHasTech(gc.getInfoTypeForString("TECH_FASCISM"), True, iPlayer, False, False)
	gc.getPlayer(iPlayer).setCivics(gc.getInfoTypeForString("CIVICOPTION_GOVERNMENT"), gc.getInfoTypeForString("CIVIC_POLICE_STATE"))

This pushes you into a different era if you playtest in ancient era like I did!

The forced civic, it's only the UN, isn't it? You could say it's fair enough.
 
Doesnt make any sense to grant a free tech....
Just do not allow the event to trigger if you cannot change to the civics.
 
Back
Top Bottom