Dancing Hoskuld
Deity
I am trying to get a bonus from a building. I can't use the <FreeBonus> tag because it breaks corporations (and guilds).
In particular I have captured a wild horse (cow, pig, elephant or deer) and now want to settle it as a horse_herd (cow_herd,...) building in a city providing a bonus.
I was told to use
but it does not work! As you can see in the image below I have built all the buildings but don't have any resources.
Bits of code and traces in my mod.
In particular I have captured a wild horse (cow, pig, elephant or deer) and now want to settle it as a horse_herd (cow_herd,...) building in a city providing a bonus.
I was told to use
Code:
pCity.changeFreeBonus (gc.getInfoTypeForString("BONUS_GOLD"), 1)
Bits of code and traces in my mod.
Spoiler :
In the init function I have:-
which produces trace prints
which means it is working as expected.
In the onBuildindBuilt function I have
Which is producing the trace messages
Which means I have built a horse_herd building and should get an horse resource but I am not getting the resource.
Code:
ga_iBuildingBonusRules_InfoTypeNum = []
if (gb_OptionBuildingResourcePossible == True):
as_BuildingBonusRules = [
['BUILDING_ELEPHANT_HERD', 'BONUS_IVORY'],
['BUILDING_HORSE_HERD', 'BONUS_HORSE'],
['BUILDING_DEER_HERD', 'BONUS_DEER'],
['BUILDING_COW_HERD', 'BONUS_COW'],
['BUILDING_PIG_HERD', 'BONUS_PIG']
]
# Convert these into integers for speed when used in game
for i in range(as_BuildingBonusRules.__len__()):
iBuilding = gc.getInfoTypeForString(as_BuildingBonusRules[i][0])
iBonus = gc.getInfoTypeForString(as_BuildingBonusRules[i][1])
BugUtil.debug("Building %s (%d) gives bonus %s (%d).", as_BuildingBonusRules[i][0], iBuilding, as_BuildingBonusRules[i][1], iBonus)
if (iBuilding >= 0 ) and (iBonus >= 0):
ga_iBuildingBonusRules_InfoTypeNum.append([iBuilding, iBonus])
else:
BugUtil.warn("Building %s (%d) gives bonus %s (%d). Contains bad building or bomus.", as_BuildingBonusRules[i][0], iBuilding, as_BuildingBonusRules[i][1], iBonus)
which produces trace prints
Code:
12:41:29 DEBUG: Building BUILDING_ELEPHANT_HERD (570) gives bonus BONUS_IVORY (26).
12:41:29 DEBUG: Building BUILDING_HORSE_HERD (564) gives bonus BONUS_HORSE (4).
12:41:29 DEBUG: Building BUILDING_DEER_HERD (571) gives bonus BONUS_DEER (15).
12:41:29 DEBUG: Building BUILDING_COW_HERD (578) gives bonus BONUS_COW (13).
12:41:29 DEBUG: Building BUILDING_PIG_HERD (579) gives bonus BONUS_PIG (17).
which means it is working as expected.
In the onBuildindBuilt function I have
Code:
def onBuildingBuilt(argsList):
'Building Completed'
pCity, iBuildingType = argsList
game = gc.getGame()
global gb_OptionBuildingResourcePossible, ga_iBuildingBonusRules_InfoTypeNum
BugUtil.debug("SubdueAnimals - onBuildingBuilt - iBuildingType %d.", iBuildingType)
if (gb_OptionBuildingResourcePossible == False):
return
for i in range(ga_iBuildingBonusRules_InfoTypeNum.__len__()):
if (iBuildingType == ga_iBuildingBonusRules_InfoTypeNum[i][0]):
pCity.changeFreeBonus (ga_iSubdueRules_InfoTypeNum[i][1], 1)
BugUtil.debug("SubdueAnimals - onBuildingBuilt - Building %d gives bonus %d.", ga_iBuildingBonusRules_InfoTypeNum[i][0], ga_iBuildingBonusRules_InfoTypeNum[i][1])
break
Which is producing the trace messages
Code:
12:41:49 DEBUG: SubdueAnimals - onBuildingBuilt - iBuildingType 564.
12:41:49 DEBUG: SubdueAnimals - onBuildingBuilt - Building 564 gives bonus 4.
Which means I have built a horse_herd building and should get an horse resource but I am not getting the resource.
. Or in this case not quite enough pasting since I type a variable name once and then copy and paste it into the code because of my dyslexia and typing problem
.
I think its the variable names that were simply too intricate to register in my brain. So I had to shut it down first. 
.
Its actually the exact thing I've been missing all along!
(The textbook I linked to earlier in this thread does also cover the data structures stacks, queues and threes. Dictionaries on the other hand were covered in the basics.)

OMG!
I'm yet to wrap my head around your examples, but this is exactly the sort of thing I like about programming.