Python At War

Riker13

King
Joined
Nov 9, 2001
Messages
859
Location
UK
Dear All,

I am trying to teach myself Python and would like to add some code in to my own personal mod which would only allow a certain CIVIC to be available if you are at WAR.

How would I do this?

Any help would be great.

All the best.

Riker13 :crazyeye:
 
This has been done in FFH2 - the crusade civic available to the Bannor civilisation when they have 1) researched a certain tech and 2) are at war.

I don't know the code itself but you could probably copy and modify what has already been done.
 
Ok Bad Player thanks for that I will have a look.

But please if anybody else has a code snippet of what I am after that would be good.
 
Interesting, I had the same idea for one of my scenarios, but I didn't know if it would work. My question was, would this cause any trouble if a civ is already running that civic and then makes peace - in other words, if it's running a civic that it now cannot run? Does the civ continue to run the civic, but once it switches, it can't switch back?
 
This perhaps?

Code:
def cannotDoCivic(argsList):
	ePlayer = argsList[0]
	eCivic = argsList[1]
	pPlayer = gc.getPlayer(ePlayer)

	if eCivic == gc.getInfoTypeForString('CIVIC_CRUSADE'):
		eTeam = gc.getTeam(pPlayer.getTeam())
		bAtWar = False
		for iPlayer2 in range(gc.getMAX_PLAYERS()):
			pPlayer2 = gc.getPlayer(iPlayer2)
			if (pPlayer2.isAlive() and iPlayer2 != gc.getBARBARIAN_PLAYER()):
				iTeam2 = pPlayer2.getTeam()
				if eTeam.isAtWar(iTeam2):
					bAtWar = True
		if bAtWar == False:
			return True

	return False
 
Interesting, I had the same idea for one of my scenarios, but I didn't know if it would work. My question was, would this cause any trouble if a civ is already running that civic and then makes peace - in other words, if it's running a civic that it now cannot run?

Perhaps the civic will automatically switch to the default one?
 
Gaius, I had this reply via PM from Keal.


I just added an attribute to civics that I called bRequireWar, then I intercepted the candoCivic function to require the player to be atWar before it can be selected. If your familiar with SDK changes its pretty simple.

In my case I also blocked the player from diplomacy with civs he is at war with when that civic is selected, so he can never make peace (unless he changes the civic first). Which worked well for my Crusade civic, I dont know if it will apply to you or not.
 
Maniac,

I tried the code but affriad it did not work :cry:

Not sure why, the code looked good as far as I could tell.

It is very annoying all I need is this and I can play my own little mod :mad:

Someone please come to the rescue.

Riker13 :crazyeye:
 
Oh wait, I got it.

In PythonCallbackDefines.xml, you need to set USE_CANNOT_DO_CIVIC_CALLBACK to 1.
 
Sorry Maniac that didnt do it either, below is the code used in CvGameUtils as you suggested.


cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
pPlayer = gc.getPlayer(ePlayer)
if eCivic == gc.getInfoTypeForString('CIVIC_TOTAL_WAR'):
eTeam = gc.getTeam(pPlayer.getTeam())
bAtWar = False
for iPlayer2 in range(gc.getMAX_PLAYERS()):
pPlayer2 = gc.getPlayer(iPlayer2)
if (pPlayer2.isAlive() and iPlayer2 != gc.getBARBARIAN_PLAYER()):
iTeam2 = pPlayer2.getTeam()
if eTeam.isAtWar(iTeam2):
bAtWar = True
if bAtWar == False:
return True

What is the BARBARIAN_PLAYER part for?


Regards

Riker13:crazyeye:
 
You're always at war with the barbarians, so they have to be excluded from the check whether you're at peace or not.

Anyway, that code is copied straight from FfH version 20, where it worked, so I wouldn't know why it doesn't work for you.
 
As I said the code did look good, but whether I am at war or not I can still pick the CIVIC "Total War", never the less thank you MANIAC for your assistance, I will keep trying and will let you know what the problem is.

Of course if anybody else could help that would be great ;)

Regards

Riker13 :crazyeye:
 
Post what you have so far and I'll try to take a look. :)

Gaius,

I am afraid this is all I have on the "cant choose a civic without being at war code"

cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
pPlayer = gc.getPlayer(ePlayer)
if eCivic == gc.getInfoTypeForString('CIVIC_TOTAL_WAR'):
eTeam = gc.getTeam(pPlayer.getTeam())
bAtWar = False
for iPlayer2 in range(gc.getMAX_PLAYERS()):
pPlayer2 = gc.getPlayer(iPlayer2)
if (pPlayer2.isAlive() and iPlayer2 != gc.getBARBARIAN_PLAYER()):
iTeam2 = pPlayer2.getTeam()
if eTeam.isAtWar(iTeam2):
bAtWar = True
if bAtWar == False:
return True

What I am after is that you cannot choose "Total War" unless you are at war, but even with this code I can pick it at peace ;(

Can you help.

Many Regards

Riker13 :crazyeye:
 
With the help of Zebra9 who found a couple of errors with the code has come back with this unfortunatly it still does not work, any more clues from anybody else?

def cannotDoCivic(self,argsList):
ePlayer = argsList[0]
eCivic = argsList[1]
pPlayer = gc.getPlayer(ePlayer)
if eCivic == gc.getInfoTypeForString('CIVIC_TOTAL_WAR'):
eTeam = gc.getTeam(pPlayer.getTeam())
bAtWar = False
for iPlayer2 in range(gc.getMAX_PLAYERS()):
pPlayer2 = gc.getPlayer(iPlayer2)
if pPlayer2.isAlive() and iPlayer2 != gc.getBARBARIAN_PLAYER():
iTeam2 = pPlayer2.getTeam()
if not eTeam.isAtWar(iTeam2):
bAtWar = True
break
if not bAtWar:
return True

return False
 
Back
Top Bottom