Garrison Training

(Combat Type Value * (1 + 2,5*Era 'StartPercent')

Do NOT use StartPercent, if you can avoid it.

StartPercent is the percentage of the maximum number of turns at which you start the game if the user, in an Advanced Start, selects an era later than Ancient. So if a Standard game is 500 turns, and someone picks an Industrial start (StartPercent=50), then the game will start the game on turn number 250 (1700 AD) instead of in 4000 BC. That's all this value means, nothing more; if you start the game in the Ancient Era, then it'll never use this value for anything.

Why is this bad to key off of? Well, take my own Alpha Centauri mod. Because I upped the maximum number of turns to 1000 on Standard speed, to take advantage of my three new Eras and some altered scaling of research rates, the Industrial era now has StartPercent = 34, I think, so that it'll start on turn 340 (1680 AD with my altered turn numbers). I'm still tweaking the numbers involved, but it'll stay in that range.
The point is that StartPercent is a purely relative value, only useful in the context of the GameSpeed turn number settings, so any mod that changes it (like mine) will do so because it also changed values in other tables to compensate, and you're not accounting for those other changes.
It's better, IMO, to just use the Era ID numbers (0, 1, 2, 3, etc.). So Industrial would always be 4, unless another mod adds a prehistoric era and shifts the existing eras up one notch.
 
Plains and boats can't "garrison" in a city, so they can't get the bonus.
I went with the garrison requirement instead of just being on the city tile because now it means the unit needs to be passive in order to get the XP. So when for example using your city-based artillery, it won't get the bonus either.
 
Hiya Iceco and than ks for the mod :)

I've been altering your mod out of boredom and a desire to learn how to mod Civ 5. I'd like to remove the garrisoned unit requirement but cannot seem to figure out the code. Any chance you'd be will to help?
 
Sure.
The relevant code is:
Code:
pUnit = pCity:GetGarrisonedUnit()
[color=green]-- Checks if a city has a garrisoned unit[/color]
if (pUnit ~= nil) then
The first line takes the data of the unit that is in the city and stores it as pUnit.
The last line checks if you actually stored a value (checks if pUnit is not empty).
If there's a value, you have a garrisoned unit, if it's nil, you don't.
 
Yea I found that. My question is the variable type to put into:

pUnit = pCity:GetGarrisonedUnit()

that will make punit = all units in the city. Including air and naval. I believe the variable names for both of those are "Uitcombat_air" and "unitcombat_naval" for the pcombattypefactor argument. I'll have to play around with the weights of thepcombattypefactor quite a bit, I don't want to be too OP but leaving them completely out of the scope of my mod doesn't make sense to me.

My plan is to take what I learn from this and make a "training unit" that can move from city to city and train all forces in the hex.... Crediting you of course :)
 
Is this working with the most recent patch? Also wondering how I would go about adjusting the xp gain rate, I am terrible at math so I have trouble with your formulas, For example if I read correctly this is the current formula.

(Combat Type Value * (1 + 2,5*Era 'StartPercent') ) / ( Game Speed 'ResearchPercent' * # of Units )

does that "Game Speed 'ResearchPercent' mean that if I have a mod that makes research 50% slower it will also affect training speed?

How would I alter the formula to have 100% chance to get 1xp and 80% chance?
 
Is this working with the most recent patch? Also wondering how I would go about adjusting the xp gain rate, I am terrible at math so I have trouble with your formulas, For example if I read correctly this is the current formula.

(Combat Type Value * (1 + 2,5*Era 'StartPercent') ) / ( Game Speed 'ResearchPercent' * # of Units )

does that "Game Speed 'ResearchPercent' mean that if I have a mod that makes research 50% slower it will also affect training speed?

How would I alter the formula to have 100% chance to get 1xp and 80% chance?
It works with the most recent patch.

I don't know how the slowing research mod works. The one that I know increases the cost of techs at an incremental rate (slower each age) and shouldn't affect this mod. If however the mod you're talking about slows all research throughout the ages with a flat %, it'll probably use the same mechanic and have an effect.
When you mean you want a specific %, I take you don't want it to change with era, game speed or troop count (if you do, you'll have to do some algebra). In that case it suffices to simply take out everything in the pChance formula and replace it with the percentage you want (write "100" or "80"). Or you can do pChance = pCombatTypeFactor and write the percentages in the calculation of the latter.
 
Thank you for the quick answer. and yes I have a mod that adds 50% to the research costs through the ResearchPercent to all game speeds

I have another question. if I wanted to consider the number of cities into the equation how would I go about that. I.E. (Combat Type Value * (1 + 2,5*Era 'StartPercent') ) / ( Game Speed ('ResearchPercent' * ,75) * (# of Units - # of Cities) ) or - # of units Garisoned in all cities,
 
That could work, though I don't know if doing "#units - #cities" makes much sense, I think something like #units/#cities would make more sense.
#garrisons is also possible. Something like
Code:
local garrisons = 0
for pCity in pPlayer:Cities() do 
  if pCity:GetGarrisonedUnit() ~= nil then
    garrisons = garrisons + 1
  end
end
(Haven't tested this bit of code, but I imagine that's how it would work.
 
I like this mod! It never made sense that a unit should be penalised for actually hanging around to defend a city, or that you should go seeking war just to get units that can fight better on certain terrain.

My only comment though is why is this tied to a new building? Surely it'd be simpler just have the garrison training an effect of the Barracks, and Military Academy upgrades (I forget the third one)? This way they're still justifying their maintenance cost even if you're not actively building units, and it'd be possible to speed the rate of XP gain.
 
Just saw this mod for the first time.
I like the idea. 1 thought I had, that I may play around with, if I ever get around to modding CiV, is tie the effect to an improvement instead of a building, specifically the fort (or a new improvement).
This is what I was thinking; make it an effect of Barracks, Arsenal and Military Academy (and any civ specific ones). This way you justify the maintenance cost of these upgrades.

It might be nice also to have it affect an area so units near a city can earn exp too, so long as they haven't taken an action that turn?
 
I haven't been keeping up with Civ anymore, so it's really a great coincidence I'm reading this,
but I don't think this mod wouldn't be compatible with the expansion pack, unless there has been a major change in how mods are handled or they did something that would conflict with this mod. Both of which I think are unlikely. It's simply code, not much that can break, really.

I suggest you just try it out.
 

Garrison Training (v. 4)
---- by Iceco


Units garrisoned in a city with a Sparring Grounds (new building) built in it have a chance of gaining experience.
The chance depends on:
  • Unit's Combat Type: Melee units have the highest chance, then mounts, archers and eventually siege engines.
    * Naval and aerial combat units can not garrison in a city.
    * Unknown Combat Types, as those modded-in by others, are defaulted to use the same chance as that of mounted units.
  • Player's Era: The chance increases as you reach a new eras.
  • Game Speed: The slower the game speed, the lower the chance. (I.e. on Marathon you have less chance than on Standard.)
  • Player's Unit Count: The more units (including workers etc.) you have, the less chance for experience gain.
    * The influence of this factor is diminished for AI players, as the AI favours (and needs) a higher quantity of troops to measure up to human adversaries.


Rationale

This mod is created to give passive civs a fighting chance against those geared towards conquest, who gain massive amounts of XP through battle and generally have a tech and quantity advantage as well.
Explanation of factors in calculation:
  • The less a unit otherwise would benefit from being garrisoned or otherwise stationed in the city, the more it is rewarded for this passive behaviour.
  • In later eras, the game generally picks up speed, there's less time left to benefit from it, the Armory and Military Academy are introduced and the Unit Count (point 4) goes up.
  • With slower pace, production and tech advance slows down too and there are more turn to benefit from it.
  • The more units a player has, the more military oriented he is and the less he needs compensation against (other) militarily strong players.

I first brought up this idea here.


Version history
Spoiler :
v. 4 (21 Mar 2011)
  • Multiplayer is now supported
  • Fixed +1XP per turn replaced by % chance, based on several factors
    * Effect no longer limited to melee units
    * Cap of 60XP removed
  • Mutual exclusivity with Armory removed
  • Changes to Flavor of Sparring Grounds
v. 3 (17 Mar 2011)
  • Bugfix: correctly set dependency on Sparring Grounds (was -still- on Barracks)
v. 2 (17 Mar 2011)
  • Addition of the Sparring Grounds building (mutually exclusive with Armory)
  • Can't gain XP when a unit already has 60XP or more
v. 1 (14 Mar 2011)
  • First complete version

Credits

Alpaca and Gedemon for their documentation on and examples of Lua coding, the Lua tutorial on the Civ 5 wiki and the code of his City States UU mod respectively.
MouseyPounds and SamBC for helping me during development, solving the things I had problems with here.
Again SamBC and now Spatzimaus for their feedback here.

If you want to incorporate this mod in yours, please let me know and give credit.
Hello Iceco

This is a great mod
1 of few things missing from Civ5

1. How do i make this work on multiplayer?

2. If not possible, i / we have been doing this


But for that to work, i need simple xml code to modify existing game config.
I doubt something as complex as this mod can be dumbed down to single xml file

Therefore, all i really need to know is the xml code for: granting exp per turn.
And how to apply that to a building

Then, I may just apply that code to Monument, which everyone builds.
Question then remains, where must unit be placed (which tiles) to gain exp per turn...
 
Top Bottom