[MOD] How to limit number of units based on number of cities?

Gearbolt38

Chieftain
Joined
Sep 20, 2020
Messages
41
Location
Hatfield(UK)
I am working on my first MOD and I am looking for a way to limit the number of times a single unit can be built based on number of cities. Ex : I want to limit to 20 the number of times this powerful knight can be built for every 5 cities in my empire control, after which I would need 5 more cities to build another 20 of this powerful knight.

Thank you in advance
 
You can add some python into canTrain or cannotTrain in CvGameUtils.py to do this.
cannotTrain is the one I use.

pPlayer.getNumCities will give you the number of cities the player has.
I’m not aware of a fast method to do a count count for a specific unit. You could check if eUnit in the cannotTrain function is one of the ones you want to limit and if it is loop through the players units and count how many of that type they have.
 
Thank you very much, the truth is I am a complete novice when it comes to Python but I understand the concepts you have described...I will come back once I give it a try after learning some basics, than you again
 
I’m not aware of a fast method to do a count count for a specific unit. You could check if eUnit in the cannotTrain function is one of the ones you want to limit and if it is loop through the players units and count how many of that type they have.
Sounds like a job for
Code:
int getUnitClassCount(int /*UnitClassTypes*/ eIndex);
int getUnitClassMaking(int /*UnitClassTypes*/ eIndex);
int getUnitClassCountPlusMaking(int /*UnitClassTypes*/ eIndex);
in CyPlayer. The DLL caches these counts, so those functions are fast.
 
Top Bottom