Here are three gadgets to handle tech levels, ranging from simplest to more complicated.

Choose one, download, stick into the \LuaRules\Gadgets\ of your mod, and edit the lines at the top to suit your mod.


1) Simple version: One single "research lab", unlock a batch of units, a soon as it's completed, and as long as you have it.


2) Intermediate version: A whole range of tech level, from 0 to as high as you want. You can have different units enabling the same tech level. When a tech level is reached, every unit of that level and of below levels are unlocked. It's the act of building and completing the specified structures (or mobile units, if you fancy) that grants the tech level: There's no research button, you just build the research lab the way you'd build any other building.

You can tie not only units builbuttons, but also any commands, to a tech level. Like, D-Gun locked out until you build a tech 3 research center. Though there's likely a bug with enqueued orders staying after you lose the tech level.

Losing research lab of course make you lose the associated tech level, unless you have other labs. When you lose a tech, units already under construction can be finished, but enqueued units won't get built. 

Skipping tech level is possible, if you build a tech 10 lab right away you'll jump straight from tech 0 to tech 10. And having tech 10 automatically enable all the lower tech 1,2,3,4,5,6,7,8,9.

It's limited to a mono-dimensional ladder, cannot do branching trees.


3) Advanced version: The tech are not labelled by a simple number, but can bear any name. It is no more one dimensionnal, you can have all the branching out you like, even self-sustaining tech or tech pathes looping back on themselves. The gadget does not need to be changed to suit a mod. The technology name, the units that grant or require a tech, are defined in FBI. More precisely, by a RequireTech=..; and a ProvideTech=..; tag in the [CustomParams] section of [UnitInfo] in a FBI. A single unit can provide multiple tech (comma separated), or require multiple tech (comma separated). Advanced user can use lua hook to slave any command to a tech from a different gadget. Though it has the same bug as previous gadget with already queued commands not deleted when tech is lost. And as for the two others gadgets, read the comment at top of the .lua file for details.


Yeah, I know many other mods have research already, and some done more prettily. So there's nothing new or grounbreaking here. But I was asked to code some simple research system, then got carried away and felt a sudden urge to write up three research gadgets showing the progression from a quick one up to a full fledged one. But since I don't feel like building three whole mods just to showcase them, I decided to just post here. Hopefully, one or two modders looking for a tech system will find them useful.