On Building Complete perform action (ex add promotion)

carloscodex

Chieftain
Joined
Sep 14, 2012
Messages
66
Location
Pleasanton (San Francisco), Ca
I've poured through the API and read threads and looked at sample code but can't seem to find an answer to this.

I want to register something that triggers when a city first "gets" a building (typically by building it, but there could be other ways).

On that even being fired I'd like to just add promotions to units or perform other actions.

One specific example: I want to give CERTAIN unit classes, built from said city, a specific promotion.


Ideas? Thanks guys!
 
Short of DLL modding there is not an easy way to detect when a building finishes. A very hacky way to do this (without DLL modding) would be as follows:

1) Create a new unit class for every building (ei: unitclass_temple)
2) Have each building spawn a free unit of its unitclass (ei: building_temple spawns a free unit_temple)
3) Detect when a unit is created (I have some lua that does this)
4) When you detect unit_temple spawning, delete the unit and fire a "building created" lua event with the city and building_temple as arguments.
 
Seems a little rough but I like where you're taking this. You gave me an idea.

I wonder if there is a way to set a dirty bit on the city buildings--then I can scan for that on each turn. I am also trying to figure out a way to list buildings in a city. I do see the function:

IsHasBuilding

But I don't want to perform full scans of all buildings.
 
You could save all the buildings in a city each turn and scan each city at the start of each turn to see if there are any new buildings. I am not sure it would be easier to implement and would have some drawbacks. It is possible for buildings to finish in the middle of turns (for example, if a building is rush bought). The unit detection approach would fire exactly when the building completes, rather than a turn later.

That isn't to say the unit spawning method is faultless. There may be a maximum number of unitClasses the game can support, which would make the unit method impossible as a general solution (though it may work in specific cases).
 
Thanks again. That was my first thought - Units Limit. Since I am building the "Prehistoric Mod" I have already added 7 era and many, many units. I need to be careful on limits and I've been researching and gathering info (and running tests).

I love your Race for Religion Mod. I've played it once. I've been looking at your code and it has given me some good ideas. I'll definitely mention you in my mod and I'll first if I borrow code.

I am creating a PRE-BELIEF system. Since this is a prehistoric mod, before beliefs, we have human thought and motivations.

I am creating a three tier system:

Thought -> Belief -> Religion.


Thanks again for the help!
 
Back
Top Bottom