Snaitf's Upgradable Buildings Demo

I just got Civ 4, and started reading up on how to mod stuff. Then I saw this thread. I really like the idea of upgrading buildings, and decided to hunt down exactly how to fix the problem of being able to build older versions when the newer building is already built.

Here's what I came up with:

You have to either create a copy of the CvGameUtils.py file, or create a class that inherits from the original. See the tutorial mod to see how that's done. Since I'm putting all the mods I like into my customassets folder, I simply copied CvGameUtils.py.

Whichever way you do it, you need to replace or override the cannotConstruct function of CvGameUtils. Replace it with this:

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

	if (gc.getBuildingInfo(eBuilding).getType() == "BUILDING_BARRACKS"):
		for i in range(gc.getNumBuildingInfos()):
			if (gc.getBuildingInfo(i).getType() == "BUILDING_BARRACKS_II"):
				if (pCity.hasBuilding(i)):
					return True
			elif (gc.getBuildingInfo(i).getType() == "BUILDING_BARRACKS_III"):
				if (pCity.hasBuilding(i)):
					return True
	elif (gc.getBuildingInfo(eBuilding).getType() == "BUILDING_BARRACKS_II"):
		for i in range(gc.getNumBuildingInfos()):
			if (gc.getBuildingInfo(i).getType() == "BUILDING_BARRACKS_III"):
				if (pCity.hasBuilding(i)):
					return True
	return False

You'd have to change it for every building you want, it would be annoying, and much simpler to not remove the earlier building versions, but this properly upgrades buildings without fail.

If you wanted to add a new upgradeable building you have to make sure that you add the building to be deleted in Snaitf's code section and add the deleted buildings to this code section and change all the names accordingly.
 
I've noticed that buildings like units have two identifiers, a "Building Class" and a "Type". Unlike Units their is no real use of the Type attribute because every building has a different building Class and this will differentiate them. Two bildings can have the same class with no noticable effect both of them build and both of them can be present

I am wondering if a check based on Building Type can be used as the basis of a ConConstruct function and possibly even a delete old version function that would limit a city to have only 1 building of each class. So for example Barracks I, II and III would all be member of the single Barracks class and the once one such building is in a city none of the others can be built. If this were possible then the mod maker could set up the upgrade path of a building entirely in XML without needing to modify any Python other then pluging in a standardized function or two.
 
I don't think so, but it is on my todo list...
 
Impaler[WrG] said:
I've noticed that buildings like units have two identifiers, a "Building Class" and a "Type". Unlike Units their is no real use of the Type attribute because every building has a different building Class and this will differentiate them. Two bildings can have the same class with no noticable effect both of them build and both of them can be present

I am wondering if a check based on Building Type can be used as the basis of a ConConstruct function and possibly even a delete old version function that would limit a city to have only 1 building of each class. So for example Barracks I, II and III would all be member of the single Barracks class and the once one such building is in a city none of the others can be built. If this were possible then the mod maker could set up the upgrade path of a building entirely in XML without needing to modify any Python other then pluging in a standardized function or two.

I tried, the problem is that each Civ can only use ONE building of each building type, like each civ can build only the unique unit of the type, not the default unit of that type.
 
Crighton said:
personally I thought this would be great idea, you merely anticipated me by about 3 or 4 months and actually knew how to make it work.

bravo.

unfortunately it doesn't quite work yet, but if you could make it work, I'd be your fan ;)
 
Back
Top Bottom