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:
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.
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.