Python Snippets

Too bad the link is broken. Can you reupload it?

Your right, my bad, I don't know what I was thinking. I might have an upgraded version on one of my storage computers, buried deep in the zip files. Give me a couple days to do my rounds on the hard drive searching and I'll see what I can come up with. :)
 
I'm still working on this stuff, but I have to use a proxy to access CFC on my main computer, and it's a pain (I'm using a local WiFi rather than the dial up).
 
That would only be realistic for ships, armors, siege weapons and air units ('material' units). I think it's a bit odd to sell 'troop'-units. That way you sell people. Know what I mean?

Basically, yes -- material units (which would instantly lose any previous combat experience as a result of the sale).
 
I have an inquiry:

Would it be possible in the python to a) rig a system to change city graphics based on what civics are selected and/or b) make civics mutually exclusive?
 
Would it be possible in the python to . . . make civics mutually exclusive?

After a few minutes of searching, I found these two civics-related functions in CvGameUtils.py:

Code:
def canDoCivic(self,argsList):
	ePlayer = argsList[0]
	[B]eCivic = argsList[1][/B]
	return False

def cannotDoCivic(self,argsList):
	ePlayer = argsList[0]
	[B]eCivic = argsList[1][/B]
	return False

Note the bolded lines. They are saying that a single civic is passed into the function. This would allow you to stop someone from switching to civic X if they were already running civic Y, but it won't allow you to block them from switching to both X and Y at the same time.

Since the Civics screen is in Python, you should be able to block them from making the mutually exclusive selection there. It would not stop an AI from switching to them, however. I think for that you'd need to do SDK work, but maybe Zebra9 knows a way.
 
What do you mean by mutually exclusive"?

From Google:

mutually exclusive: contradictory: unable to be both true at the same time​

The two civics cannot be used together. For example, in each category (Legal, Government, Religion, etc) all of the choices are mutually exclusive because you have to choose one of the five. You cannot use Organized Religion and Pacifism.

I believe neutral_leader wants to make it so that, e.g. you cannot run Pacifism and Slavery together, even though they are in different categories.
 
Yes, I still have to use the proxy. The only problem it causes is that I can can't upload to CFC, but I recently bought 10 gig of server space and I can upload there; ;)
 
EDIT: Nevermind, I figured it out. Thanks anyway for the great python snippets

I've been having trouble getting the civic specific unit's code to work

Code:
	def cannotTrain(self,argsList):
		pCity = argsList[0]
		eUnit = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
		bIgnoreUpgrades = argsList[5]

        	## If The Civ Doesn't Have The Correct Civic Tell the SDK Not To Allow The Player To Train This Unit
        	if eUnit == gc.getInfoTypeForString('UNIT_CARAVAN' ):
            	        if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString('CIVIC_BARTER' )):
                		return True

		return False

Is causing my interface to vanish so I know it must be a whitespace, formatting problem. I'm using BTS 3.17, does this code still work for this? Or if someone sees my error, any help would be appreciated. thanks:)
 
Well try going trough and line by line remove the indentation and then re-add it. That's what I do when I get an indentation error. :thumbsup:
 
It would help a lot if you posted the error you're getting. Enable the logging system and look in Logs/PythonErr.log.

However, just looking at it I can see that you are mixing tabs and spaces -- always a source of trouble with Python. The line

Code:
if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString('CIVIC_BARTER' )):

has a tab mixed in with the spaces in the indentation. The others may have problems too, but that was the first and only one I examined (sixth sense :)). Pick one and stick with it.

I recommend going with tabs since most of the Civ4 code uses them.
 
Are your python snippet for Civic Specific Unit compatible for BTS? Because the code you said was in unmodded game was different in my original BTS Python files and when I used the snippet the civilopedia didn't worked and when I played a game I couldn't see menus or anything except for the main map.

This is my Python Code:

Code:
def cannotTrain(self,argsList):
		pCity = argsList[0]
		eUnit = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
		bIgnoreUpgrades = argsList[5]
		civic = "CIVIC_SLAVERY"        ## The Civic
        unit = "UNIT_SLAVE"        ## The Unit

        ## If The Civ Doesn't Have The Correct Civic Tell the SDK Not To Allow The Player To Train This Unit
        if eUnit == gc.getInfoTypeForString(unit):
            if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString(civic)):
                return True
		return False



Gurra09
 
Well, it should work with BtS. I think I have spotted an error though. Your indentation is incorrect. This should work:
Code:
	def cannotTrain(self,argsList):
		pCity = argsList[0]
		eUnit = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
		bIgnoreUpgrades = argsList[5]
		civic = "CIVIC_SLAVERY"        ## The Civic
		unit = "UNIT_SLAVE"        ## The Unit

		## If The Civ Doesn't Have The Correct Civic Tell the SDK Not To Allow The Player To Train This Unit
		if eUnit == gc.getInfoTypeForString(unit):
			if not gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString(civic)):
                		return True
		return False
You used spaces on some of the lines (I might have used spaces in the snippet, I'll have to check).
 
Now the civilopedia and screens works but I can construct my unit even if I don't have the civic I have wroted in the Python (Slavery).

I can build it with Caste System, Tribalism and every civic. Why?


Gurra09
 
Try this:

In PythonCallbackDefines.xml change

Code:
<Define>
	<DefineName>USE_CANNOT_TRAIN_CALLBACK</DefineName>
	<iDefineIntVal>0</iDefineIntVal>
</Define>

to

Code:
<Define>
	<DefineName>USE_CANNOT_TRAIN_CALLBACK</DefineName>
	<iDefineIntVal>1</iDefineIntVal>
</Define>

Not sure of it works but you could give it a try.
 
Top Bottom