Free units on discovering tech and research unit ability


Sep 6, 2007
I am currently working on a new mod, which is going great, except I haven't been able to figure out two things yet.

When certain techs are researched (i.e. communism) you receive a free unit (i.e. a great spy). But only if you are the first to discover said tech.

What I would like to do is (without screwing up the original techs and losing the ability to grant "first only" units) is have a technology grant units regardless of when it is discovered (so basically the moment you get it, or the turn afterwards).

I am currently working through events, but that really isn't working very well (often it takes many turns before the event takes place, which makes sense, but isn't what I want).

The other problem is that I would like to create a unit that grants a small amount of research upon performing the "research" action, much like a great person does, only instead of granting a large amount once, being able to grant a small amount each turn (I'll worry about automation at a later time).

Does anyone have any hints as to how I could accomplish it, or perhaps know of a mod where something like this was done so I can look at their example to figure out what I have to do?

Thank you all so much for your time looking into this for me!
The free unit can be done in python. FFH has tons of python code in it, so maybe look at that one. My snippets are out of RFRE.

Skipping some details.. it could look something like this:

     def onTechAcquired(self, argsList):      
          iTechType, iTeam, iPlayer, bAnnounce = argsList
          self.techName =     str( gc.getTechInfo( iTechType ).getDescription() 
          if (self.techName == 'Dictator'):
newUnit = playerX.initUnit(gc.getInfoTypeForString(enslaveUnit), iX, iY, enslaveAI)

More code is needed to pick the x,y location (the capital maybe?).

The enslaveUnit looks something like:

The decleration of the onTechAcquired hook goes in

For the beaker part, I'd guess the tech leak mod component shows how to do this.
Thank you very much for your help. I have the units appearing just as they should now (although it took a little bit of experimenting ^_^)

I'm still working on the research from unit ability bit. I am currently trying to work with the Discovery ability Great People have, although it is not working exactly how I want it just yet.

The tech leak mod shows how I can add research to a tech, which should work now, but I haven't been able to get it as a unit ability yet. Perhaps it will require some SDK modding... Not sure yet. Any idea's on this would be more then welcome!
There is probably a better way to do it.. but one way that could be done in python is to use unit promotions. When 1 of these special promotions are taken away it gives some beakers. That can be done in xml + python. That python would be housed in onEndGameTurn so that it is processed each turn. If in xml you only allow 1 of this unit type, and then once the final promo is taken away the unit is killed ( pLoopUnit.kill(False, iPlayerID) ), this does have the effect that you want.

There are bad parts to anything involving the SDK:
* the .dll is almost 4 megs (zipped it's only 1 meg though)
* it only works on Windows
* when the game is patched the custom dll needs to be recompiled
I have been able to solve both these issues in Python now. I managed to use the onEndTurn part of the CustomEventManager script to check for the appropriate units and do stuff automatically (this is actually preferable to a unit ability as it turns out). Some issues I am still working on (but for which I know how to get it right) are:

- showing the unit ability as an icon (will do this with a unique promotion, which will also become the qualifier for the generated research instead of the unit type as it currently is - for other modders that wish to use my stuff)
- force the player to choose a tech to develop (in rare cases you could have no tech active and then the unit does nothing but it should force the player to choose a tech. I will do this by summoning the choose a tech popup dialogue normally called after discovering a tech)

Anyway, just wanted to let you all know I got it working and that I'll be mentioning primordial stew in my mod credits ^_^ Thank you all!
Top Bottom