Event onChangeWar

TheLopez

Deity
Joined
Jan 16, 2006
Messages
2,525
Location
Oregon
Does anyone know when the onChangeWar event gets called? I assumed incorrectly that it was called when someone declared war on someone else.

My current onChangeWar method in the original CvEventManager.py file looks like:
Code:
	def onChangeWar(self, argsList):
		'War Status Changes'
		bIsWar = argsList[0]
		iPlayer = argsList[1]
		iRivalTeam = argsList[2]
		[B]CyInterface().addImmediateMessage(gc.getPlayer(iPlayer).getCivilizationName(),"")[/B]
		if (not self.__LOG_WARPEACE):
			return
		if (bIsWar):
			strStatus = "declared war"
		else:
			strStatus = "declared peace"
		CvUtil.pyPrint('Player %d Civilization %s has %s on Team %d'
			%(iPlayer, gc.getPlayer(iPlayer).getCivilizationName(), strStatus, eRivalTeam))

The changed line is in bold. The civilization name is never displayed. Even when I force a war with someone else.

Weird.
 
I would have guessed it would trigger when there is a change in war state (either way)... as you have. I can't think of anything else it would do. Maybe a bug?
 
The Great Apple said:
I would have guessed it would trigger when there is a change in war state (either way)... as you have. I can't think of anything else it would do.
I thought it was triggered by a change in war state too... oh well.

The Great Apple said:
Maybe a bug?
A bug? No, that can't be, I thought games like these were bug free?

Anyways, the reason why I ask is because when player A declares war on player B I wanted all of player B's contracted out units hired by player A to immediately abandon player A. The only workaround that I could think of is to check at the end of each player's turn, but that is just an ugly hack that I don't like.
 
As far as I can tell its never called.
 
TheLopez said:
The only workaround that I could think of is to check at the end of each player's turn, but that is just an ugly hack that I don't like.

There isn't any event that runs at the end of a players turn. onPlayerEndTurn runs after the players upkeep each turn (city production, research, paying for units, culture, etc...) which means it kicks before you move any of your units or do any of that sort of stuff. Its not very well named.

And I agree that would be an ugly hack (and process intensive), it would be nice if we could get your original design to work.
 
I agree, it would be nice if I could get it to work, but it might not be possible without the SDK...

Another ugly workaround would be to check either onBeginGameTurn or onEndGameTurn... this could be a bit more realistic since it could simulate the delayed reaction of "Oh you declared war on my King/Emperor/President/etc. well then I'll see you later"
 
Well, you'd want to do some testing, which I don't have time to do atm, but here are a few ideas...

Put a short test in onUpdate or OnUnitMoved/OnCombatResult 8) that calls an event you make up in your Event Manager wrapper class to do onDeclareWar for you.

Alternatively, test out the dialog for "declare war?", and see if you can't trigger your event from there. That will probably only work for the human players, but you might get lucky. Oddly enough, doing something similar worked like a charm when I made OnCivicsChanged 8).

Having thought about it for a second, I think puting the test in onMove & onCombatResult (+ on BeginPlayerTurn) is probably good enough.
 
Belizan said:
Alternatively, test out the dialog for "declare war?", and see if you can't trigger your event from there. That will probably only work for the human players, but you might get lucky. Oddly enough, doing something similar worked like a charm when I made OnCivicsChanged 8).
Hmmm. Did it work for AIs though?
 
Back
Top Bottom