View Full Version : Finding a Civ's Unique Building Id


Denniz
Mar 18, 2007, 07:56 AM
I am trying to fix the Modified Special Domestic Advisor mod's Buildings tabs in Warlords. I fixed the building list except for other Civ's Unique Buildings showing up. Anyone know a function that tells you the id of a Civ's unique building?

(PyHelper.PyCity.canConstruct function in CheckVisibility was the problem. I replaced it a call to the API version instead.)

Impaler[WrG]
Mar 18, 2007, 08:30 AM
A civ can have an unlimited number of Unique things (units or buildings) so their is no one function that just magically tell you this, you need to loop over every Building or Unit class calling getCivilizationBuilding or getCivilizationUnit arguing the ClassIndex for which you will get the Type index that civ builds. If that Type is not the default for the Class then its a "Unique".

Denniz
Mar 18, 2007, 08:52 AM
;5216431']A civ can have an unlimited number of Unique things (units or buildings) so their is no one function that just magically tell you this, you need to loop over every Building or Unit class calling getCivilizationBuilding or getCivilizationUnit arguing the ClassIndex for which you will get the Type index that civ builds. If that Type is not the default for the Class then its a "Unique".:hmm: I guess I can compare the current building's CvBuildingClassInfo.getDefaultBuildingIndex with the CvCivilizationInfo.getCivilizationBuilding then. If they are not the same then they can't build it. Thanks.

Edit: It's ugly as hell but it works:
if gc.getCivilizationInfo(iPlayer.getID()).getCiviliz ationBuildings(gc.getBuildingInfo(iBuilding).getBu ildingClassType()) == iBuilding:

Impaler[WrG]
Mar 18, 2007, 09:27 AM
No your passing the player ID as the Civ ID, thats not the same things.

if gc.getCivilizationInfo(iPlayer.getID())

This should be

gc.getCivilizationInfo(iPlayer.getCivilization())

Also your identifying a Player player pointer with 'i' Player which is misleading, use pPlayer to indicate its a pointer

I think your making some higher level design flaws though, tell me if I'm on the right track here.

Are you using the BuildingTypes as the columns of the Advisor? If so don't, instead create a column for every BuildingClass and call getCivilizationBuilding to populate it with the button of the Building Type that the civ builds (seeing columns for the UniqueBuildings of other civs is complete waste of space). Then you can simply use the column index as argument in getCivilizatonBuilding to get the type and then that type index as argument to the various 'city has building' and 'city can build' checks.

Denniz
Mar 18, 2007, 09:53 AM
;5216571']No your passing the player ID as the Civ ID, thats not the same things.

if gc.getCivilizationInfo(iPlayer.getID())

This should be

gc.getCivilizationInfo(iPlayer.getCivilization())

Also your identifying a Player player pointer with 'i' Player which is misleading, use pPlayer to indicate its a pointer

I think your making some higher level design flaws though, tell me if I'm on the right track here.

Are you using the BuildingTypes as the columns of the Advisor? If so don't, instead create a column for every BuildingClass and call getCivilizationBuilding to populate it with the button of the Building Type that the civ builds (seeing columns for the UniqueBuildings of other civs is complete waste of space). Then you can simply use the column index as argument in getCivilizatonBuilding to get the type and then that type index as argument to the various 'city has building' and 'city can build' checks.I missed that. Fixed it now. Thanks. :goodjob:

Your design points are valid. If I were writing this mod from scratch (God forbid!), I would do things differently. But since I am merely fixing a bug, I am trying to keep changes to a minimum. ;)