CvGameUtils.py in Bug (RevDCM)

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
The following code looks correct, but fails to prevent "Slave Cage" building from appearing on the production list, when the player has not changed labor civic to slavery. The slave cage appears on the list when it should not.

Spoiler :

Code:
def canConstruct(self,argsList):
	pCity = argsList[0]
	eBuilding = argsList[1]
	bContinue = argsList[2]
	bTestVisible = argsList[3]
	bIgnoreCost = argsList[4]

	pPlayer = gc.getPlayer(pCity.getOwner())		
			
	if eBuilding == gc.getInfoTypeForString("BUILDING_SLAVE_CAGE"):
		if (pPlayer.getCivics(gc.getInfoTypeForString("CIVICOPTION_LABOR")) == gc.getInfoTypeForString("CIVIC_SLAVERY")):
			return True

	return False

and...

Spoiler :

Code:
def cannotConstruct(self,argsList):
	pCity = argsList[0]
	eBuilding = argsList[1]
	bContinue = argsList[2]
	bTestVisible = argsList[3]
	bIgnoreCost = argsList[4]

	pPlayer = gc.getPlayer(pCity.getOwner())		
			
	if eBuilding == gc.getInfoTypeForString("BUILDING_SLAVE_CAGE"):
		if not (pPlayer.getCivics(gc.getInfoTypeForString("CIVICOPTION_LABOR")) == gc.getInfoTypeForString("CIVIC_SLAVERY")):
			return True

	return False


What have I missed?


Orion Veteran :cool:
 
The Return False at the end whipes your code for the Slave Cage. Put the slave cage code after the Return false.
 
Did you enable these callbacks in PythonCallbackDefines.xml? They are all disabled by default.

Code:
<Define>
	<DefineName>USE_CANNOT_CONSTRUCT_CALLBACK</DefineName>
	<iDefineIntVal>[B][COLOR="Orange"]1[/COLOR][/B]</iDefineIntVal>
</Define>
<Define>
	<DefineName>USE_CAN_CONSTRUCT_CALLBACK</DefineName>
	<iDefineIntVal>[B][COLOR="Orange"]1[/COLOR][/B]</iDefineIntVal>
</Define>

This is not specific to BUG; the normal game uses this file to determine which Python callbacks the DLL should use.
 
Really, this isn't an issue?

Code:
	if eBuilding == gc.getInfoTypeForString("BUILDING_SLAVE_CAGE"):
		if not (pPlayer.getCivics(gc.getInfoTypeForString("CIVICOPTION_LABOR")) == gc.getInfoTypeForString("CIVIC_SLAVERY")):
			return True

	return False
Wouldn't that return False at the end override the return true in the if statement above?
 
When a function gets to a return statement, it immediately exits the function and returns the specified value. It does not execute any code from the return to the end of the function.

In this function, each test is checked one-by-one until one succeeds and returns the specified value. Once that happens, no more tests are checked and the function exits with the given value. Only if every if test fails is the final return hit.

Code:
def getAnimalName(nLegs)
    if nLegs == 1000:
        return "millipeed"
    if nLegs == 100:
        return "centipede"
    if nLegs == 4:
        return "cat"
    if nLegs == 2:
        return "human"
    return "dunno"
 
OK thanks, didn't know that.
 
Top Bottom