Generate unit on city growth/Choose where the pop goes

Gurra09

Emperor
Joined
Jan 1, 2008
Messages
1,302
Location
Sweden
Hi!

I'm working out a concept for a new civ with a somewhat nomadic UA in mind which would need LUA coding and I'm not very familiar with it so hence this thread.

The basic idea is that when a city of said civ grows, instead of adding a pop a unit is born in that city.

How would I do something like that?

The unit would be a specific unit, I'm planning to base the civ's UA on whoward's Units - Population mod (which adds a Population unit that spawns when cities are razed and have the opportunity to either join a city as a pop or settle a new city). With this civ, they would gain one of those when a city grows and the player gets to choose whether to add it to the city or use it to build a new one.

I guess the way this would go about is that when the city grows, the game detects the growth, spawn a Population unit in said city, and decreases the city's population back one step. But as I said I'm not very familiar with LUA.
 
The city growth code I believe is all in C++ (CvCity.cpp and CvCity.h). I'm actually working on a similar change for my mod, except the cultural border growth gives you a unit instead of growing.

Hopefully somebody here knows.
 
You can detect when a city changes population by using the event:

Code:
Events.SerialEventCityPopulationChanged(hexX, hexY, population, citySize)

While most Events (rather than GameEvents) are not recommended for use, this one actually works back when I tested it years ago. It fires for ai cities and cities the human can't see.

However, if most of the time people are just going to be plopping that population back into the city it would probably be less busy work for them (and less likely to mess up the AI) if instead of giving them a unit each time a city grew you made a unique unit that subtracts a population when built.
 
Back
Top Bottom