Have a look at this thread. The function is cannotTrain in CvGameUtils.py but requires to use a Python Callback (explained in the thread).
It doesn't take unit upkeep cost in consideration though.
Exactly what I was looking for, thanks! I think I'm gonna tweak the suggested function to allow 2 free units per city and then one more unit for each population point. One question, though: Does the function
Code:
pPlayer.getNumMilitaryUnits()
EDIT:
Ok, the code is fairly simple. Looks like the callback for cannotTrain is already activated in AOE, right? Anyway, for my first attempt, I did it like this:
Code:
iNumMilitaryUnits = pPlayer.getNumMilitaryUnits()
iNumCitizens = pPlayer.getTotalPopulation()
iNumTotalAllowed = (iNumCities * 2) + iNumCitizens
if iNumMilitaryUnits >= iNumTotalAllowed:
return True
I'll have a look tonight if it works as intended. If it does, I'm gonna tweak it some more, giving additional free units for certain civics like conquest and maybe one per great general.
I'm thinking that maybe this would make summons particularly powerful, since they are extra units that need not be trained. We'll see.