Garrison Training

Iceco

Warlord
Joined
Oct 27, 2010
Messages
188

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.
 

Attachments

  • IconSparring_BetaIcon.png
    IconSparring_BetaIcon.png
    50.9 KB · Views: 223
  • IconSparring_BetaIG.jpg
    IconSparring_BetaIG.jpg
    113.5 KB · Views: 818
  • Garrison Training (v 4).civ5mod
    81.7 KB · Views: 503
  • ReadmeGarrisonTraining.pdf
    104.2 KB · Views: 306
Now to critique the idea ;)

The basic concept is probably good, but 1XP per turn seems possibly excessive. Okay, so it's only the garrison units, but still...

Might be worth using ScriptData (via SaveUtils, of course, though I've not the time/energy to dig up the URL right now) to enact a sort of fractional XP, so they get 1/5 each turn. Oh, and you might then want to consider whether game speed should have an effect on it, though I don't know how to get at the setting.
 
For future reference: SaveUtils.lua thread

A lot of people say 1XP is too much, so I guess they're right, but 1/5 is too few, in my opinion. That's 50 turns to get the first promotion, 150 for the second (when I swap the barracks as the required building). At that point it beats the point of having this mod.
1/2XP might work, but I think other solutions would be better. Like:
  • capping the maximum gainable XP through these means (to either the second or the third promotion --- this is extremely easy),
  • making the building/maintenance cost rise more per amount of cities you have (Thal did this for his national wonders.) or per amount built,
  • require that the barracks or armory (whichever would be best) is NOT built or preferably making that building and the 'sparring grounds' mutually exclusive, if that's possible, making the latter a building only making sense to be used by passive civs. (Would also make it easy to determine the flavors for that building.)
In order of difficulty it's probably: cap, SaveUtils, rising cost, exclusivity (latter two may be the other way around). Of course, nothing prevents me from combining a few.

And about game speed, I found what you mean: Game:GetGameSpeedType(). I don't know what the 'Type' will give. Hopefully it's an int, so it could be used in a formula.
But I don't know if it's needed, as the other means of gaining XP (battle or buildings) aren't weighted either, I believe.

EDIT: I just remembered that the power plant and hydro plant are mutually exclusive. So guess the exclusivity can be added easily as well.
 
Ok, today I worked on the icon for the "sparring grounds". Tell me if I'm going in the right direction with this. If so, I'll clean it up a bit more.
I'm also not sure about that name. Sparring/training grounds/fields? Arena? Something else entirely?

 
I'd say 'training field', just because it matches actual (European) history, as it's now referred to in English. The artwork is pretty nice - can I ask you for some when I get to doing actual proper mod content (I'm working on infrastructure atm)?
 
Was quite a struggle to get the graphics in-game, but managed it.
Here is how it currently looks:
Spoiler :



The icons still stand out a bit too much from the rest of the game, so I might mess around a bit more.

As you can see, I called it "Practice Field", a bit of a dull name, but someone pointed out "Training Field" spoke more of recruitment of some sort. I'm still not sure how I have to call it.
And sure, I can always try to help you with the icons, but don't expect too much of it. This here was created with the help of a stock image.

Making it mutually exclusive with the barracks doesn't seem like an option. It would prevent you from building the heroic epic, and take out the Russia UB.
I guess I'll have to do exclusive with Armory and a cap at 100XP (is that the third promotion?)
 
This seems a valid mod idea, as I had one very similar.

There's a few caveats that bug me about the idea though. Limiting this to the city plot only means this can be a bit of a micromanagement nightmare. "Okay, this unit is done training, let's shuffle in another one." I have a bit of code in my flanking XP mod component that could cover all of the tiles adjacent to a city. So that one can be solved. The other one is that of a barracks. This potentially reduces the value of the barracks and similar buildings. In eliminating the micromanagement aspect, this building would allow almost a whole empire to operate with just one copy of this building.
 
I think it's the cleanness of the edges and colours that makes it stand out so much, but it''s hard to be sure. The main game ones have a certain amount of texturing in all of the colours, as well, rather than solid colour. You might be able to get a similar effect using standard filters in, for example, the GIMP.
 
This seems a valid mod idea, as I had one very similar.

There's a few caveats that bug me about the idea though. Limiting this to the city plot only means this can be a bit of a micromanagement nightmare. "Okay, this unit is done training, let's shuffle in another one." I have a bit of code in my flanking XP mod component that could cover all of the tiles adjacent to a city. So that one can be solved. The other one is that of a barracks. This potentially reduces the value of the barracks and similar buildings. In eliminating the micromanagement aspect, this building would allow almost a whole empire to operate with just one copy of this building.
You're taking time out of the equation. To mimic the effect of the Barracks alone you need 15 turns, at what time the Barracks has created 2 units with 15XP. Next release, at the very least it will be mutually exclusive with the Armory (and thus the Academy too) and I'll try to bring that down to the Barracks even. That means the choice between Barracks and Practice Field isn't a choice at all: if you want to have a decently sized army that's usable anywhere in the next 100-200 turns, go with Barracks and the others, do you just want to keep some troops around as defence should it be needed, go with Practice Field.
For the micromanagement just the same. If you want to, you can rotate your units around every X turns (every 60 turns, I believe, if you want 3 promotions, which is actually very long), but you'd have better luck waging war with those troops.
Increasing the affected area isn't in the spirit of this mod. It's meant to give players with small armies some highly trained units, instead of boosting massive armies even more.
I think it's the cleanness of the edges and colours that makes it stand out so much, but it''s hard to be sure. The main game ones have a certain amount of texturing in all of the colours, as well, rather than solid colour. You might be able to get a similar effect using standard filters in, for example, the GIMP.
I think the biggest problem is the colour use. I used some pretty hard colours instead of the more earthy/softer tones used in-game. That's for the smaller icons. The big icon is just a lot less detailed and varied as the in-game ones, but that one's the lowest priority. You should be playing the game, not reading the Civilopedia.
None of the colours are solid though. All have some sort of gradient or grain already, but it does not really show that much. I'll see what it gives if I add some more.
  • Do you maybe know at what thresholds you gain the levels? In the XML it speaks of a value of 10. It's clearly not 10, 20, 30, 40.... Is it 10, 30, 60, 100, 150, 210,...?
  • Also, I just thought of a way I might be able to make the building mutually exclusive with the Barracks. I could add a clone Heroic Epic which can be built if all cities have Practice Fields and then add a clone Krepost (not tied to the Armory though) for the Russians.
    That would still have various problems though. Firstly, if other mods change the characteristics of the Heroic Epic, my clone would still be like the old one (unless I find a way to make a script that assembles the XML of the clone building based on what is written for the Heroic Epic - then it's a simple load order issue). Secondly, people could build barracks in some cities and practice fields in other, which would mess both the original Heroic Epic as the clone up.
 
Each level costs 10 more in new XP than the last - so it's triangular numbers times 10, or 10, 30, 60, 100...
 
Might be worth using ScriptData (via SaveUtils, of course, though I've not the time/energy to dig up the URL right now) to enact a sort of fractional XP, so they get 1/5 each turn.

No need for ScriptData for that. Even if we're sure the game doesn't store the fractions (and I'm not sold on that), you can just tie it to a random draw; each turn, each unit stationed in a city has a 1 in X chance of gaining +1 XP. You could easily vary this by unit type, then, to where X is larger for archer-type units and MUCH higher for air units. Or more precisely, have X be the same for all, but replace the "1" with a different function. So maybe melee units have a 3 in 10 chance, ranged units have a 2 in 10, and air units have a 1 in 10.

It's not quite as smooth, but 1 XP isn't going to make or break anything, so the randomness will even out in the long term.

(It's the Map.Rand function I'm talking bout. If you want to see how this works in practice, look through AssignStartingPlots. I make heavy use of it in my own mod.)

Oh, and you might then want to consider whether game speed should have an effect on it, though I don't know how to get at the setting.

Easy: pick one of the multipliers (BuildPercent, ResearchPercent, TrainPercent, etc.); they all scale up at pretty much the same rate, so it shouldn't matter which you pick. Just multiply your threshold by that factor. So the 10 mentioned above would move to 7 for Quick, 15 for Epic, or 30 for Marathon.
 
I noticed the Game:Rand, but didn't get it to work. Good to know I have a working example of Map.Rand somewhere. Still, the randomness is not as clean as a real decimal. What do other people think? I also thought of making the amount of XP depend on the range of a unit instead, so artillery would get less XP than archers and fighters/bombers would get the least. (Through GameInfo instead of Unit, so earned promotions don't negatively affect this.)
And I just realised scaling it with game speed does make sense, so I'll add that in in the future.


For a way to make it mutually exclusive with the Barracks, I've found the DB.Query method, but fear it will not be of much help. I originally thought I could make the sum of all Barracks + Practice Fields and when that corresponds to 80 or 100% of the number of cities, change the data of the Heroic Epic to make it buildable.
Documentation: (for future reference) wiki entry for DB.Query, Random related thread, An enlightening example?

My hopes is now on finding out how Thal did his 80% requirement for National Wonders for his Balance mod, but I can't seem to find the relevant bit of code. So far I found
<Building_PrereqBuildingClassesPercentage> tags in TBC\City Development\BCD - National Wonders.xml, and that table is created in CiVUP\Core\New Tables.xml,
but I can't find the code behind it. (I hope that if I find how he made an alternate requirement I'll be able to adapt it for my needs.)


EDIT:
This is shaping up to be a whole lot more than I thought, so I'll try to split it up in several releases, so people don't have to wait for everything to be finished. This is what I'll try to do for v. 2:
Version 2
*Addition of the Practice Field (probably renamed Sparring Ground)
*Mutual exclusivity with Armory and XP cap at 60XP

Then later releases will (hopefully) have:
*Mutually exclusive with Barracks instead
*More refined way of calculating/applying the XP/turn
*Make game speed have an effect on the above too
*Multiplayer support
 
So I did just that^

Version 2 is now up.

Spoiler :
Old: New:
The arms could probably do with a bit more highlight.




EDIT:
Had to make a version 3 to correctly make the Sparring Grounds as the criterium. It still checked for the Barracks as in version 1. Sorry for the inconvenience.
Also of note is that I got rid of the large 8x8 icon grid and tried a 1x1, which works. That made my mod over 60 times smaller, so I think it was worth it.
 
Still, the randomness is not as clean as a real decimal.

No, but that's not always a bad thing. Since the UI doesn't display decimals, you might have strange situations like a unit with 9.8 XP showing 10/10, and the player wonders why he doesn't have a new promotion yet. If the increments are always +1, and you just vary WHEN the +1 will happen, then there's at least not that issue.
And as I said before, randomness in general favors the AI, which overall is probably a good thing as the game is heavily biased towards the player. Sure, you might have streaks where one unit gets +1 on five successive turns while another goes twenty turns without a single increase, but the granularity works in your favor here; how many players would even notice if a unit gets +1 or not? They'd only be watching for that if a unit was very close to leveling.

If you don't want it to be random, there are a few ways around that. For instance, you could simply give +1 on each turn number that's a multiple of N. (I don't have the wiki in front of me; is there a Unit:GetTurnCreated() function to use instead of the game clock?) So a melee unit might get +1 every 3 turns, an archer +1 every 5, a bomber +1 every 10, or whatever.

I also thought of making the amount of XP depend on the range of a unit instead, so artillery would get less XP than archers and fighters/bombers would get the least.

I wouldn't do that. First, you wouldn't be able to make it scale linearly anyway, because of the jump in range from non-air units to air ones (and then from Bombers to Stealths), so you'd need some sort of table lookup anyway. And secondly, because it means that something like a Longbowman gets less XP than its non-UU counterpart, and Artillery gets less than the Cannons it upgraded from (or Stealth Bombers getting less than Bombers and Jet Fighters getting less than Fighters)? Even if you thought that the last one makes sense (and it doesn't), it leads to a bad gameplay result: the player would wait to upgrade until he needed the unit for offense or the city was threatened, to get more XP, while an AI upgrades as soon as it can. This already happens with the Pentagon; if I think I'm going to get it, I'll hold off upgrading for some of my units, to save money. The AI, obviously, does not.

To me, it'd be much better to sort by Unit Combat Class. (That's "melee", "siege", "mounted", etc.) This'd make sure that any UUs or upgraded units get the same as their original versions, and it's an easy table lookup.
While it's easy enough to check, though, it wouldn't be compatible with any outside mods that add new combat classes (so make sure you add an ELSE with some sort of default value). For instance, my own future-era mod adds five new combat classes (Psi, Energy, Multirole, Orbital, and Titan), and you don't want to force other people to make their own slightly altered copies of your mod if you don't have to.

For a way to make it mutually exclusive with the Barracks

You can make buildings be mutually exclusive already, through the new <MutualExclusiveGroup> tag; look at the Solar Plant and Nuclear Plant for examples of this. Building one locks out the other, automatically. This was only implemented in the March 1st patch, and it's not being done in a very robust way, but it works.
 
That about the randomness does make sense, if you look at it like that. I might go with that then.

And I suggested that about the unit range, as I found it quite proportional. The longer the range of a unit, the more it can do offence from the city (or other places) and the less I want to buff it. Having artillery gain less was part of the plan. I did forget about the longbowman and the impact on gameplay escaped me as well. So sure, I'll go with the original plan and stick to differentiation between combat types.

And I knew of the mutual exclusivity support, starting from version 2 this mod already has it between the Sparring Grounds and the Armory. The problem is that the Barracks are a prereq for the Heroic Epic. Blocking out a national wonder would accomplish quite the opposite of what I'm trying to do. I can't make a Heroic Epic 'clone' with prereq Sparring Grounds either as people might want to have a mix of Barracks and Sparring Grounds in their empire. That's why I want to know how Thal made the requirement of 80% of a type of building, hoping it could be of use to me.
And there's the Krepost too.
 
The longer the range of a unit, the more it can do offence from the city (or other places) and the less I want to buff it.

The problem is that a Bomber isn't three times as useful as an artillery, and a Stealth Bomber isn't twice as good as a Bomber (assuming equal strength ratings). Air units have huge ranges partially because their rebasing range is twice their combat range; you could halve the air unit ranges (down to 5-10) and double the rebase multiplier to x4, and it wouldn't drastically affect their utility. (I've actually been tempted to do this.) Sure, you'd need to rebase them a bit more often, but since they stay in cities it wouldn't make them more vulnerable to counterattack or anything.

The jump from range 2 to 3 (cannon -> artillery or using a Battleship instead of a Destroyer) is only really important because cities' defensive fires have a range of 2, but if you play in a mod where cities attack with range 3, or where defensive units are more mobile, then the range doesn't mean nearly as much. Also, because artillery still has the same line-of-sight requirements as a Cannon, you won't consistently get the extra potential target area.

So yeah, stick with combat types. It's just too much of a headache to do this any other way.
 
What do you think of these ratios (at normal game speed):
melee - 9/12 (75%) --- 80 turns for 3 promotions (134 for 4, 200 for 5)
archer - 6/12 (50%) --- 120 turns
siege - 4/12 (33%) --- 180 turns
plains - 2/12 (17%) --- 360 turns
Keep in mind that it will be mutually exclusive with the Barracks (and thus Armory and Military Academy). The sparring grounds definitely need to be better than those, to make up for the troops being tied to the city for a good portion of the game.

Maybe I could make it tie in to the era of the game as well? That would make it more balanced, instead of overpowered early-game compared to a simple Barracks and useless compared to the trio late-game.
A good idea, no?
 
Ok, problem for multiplayer games is fixed.

For the XP gain, I have worked out the code for the factor for game speed and era. Here's a chart of what XPs could look like in a standard game:


Then about the Barracks:
Making it mutually exclusive seems like it won't be a clean cut like I hoped it would be. I better leave it alone as it would only make things worse. I'm saving you the long explanation.
As alternative I thought of adding the presence of a Barracks/Armory/Academy as a (negative) factor to the XP calculation, but that's not intuitive and hard to justify (why should the presence of Barracks influence a unit negatively?),
so now I thought of simply making the amount of units a player has a (again negative) factor in the equation. I think it's a really good factor as it correctly favours those with small empires and low troops counts. The only hiccup is that the AI by nature favours unit spamming to make up for its incompetence, so I might have to differentiate between human and AI.

But what I need to know now is what you think are typical troop counts for small/passive, medium/normal and large/aggressive empires, in what eras that is and how much XP that should mean.
I don't often exceed 15 units, so have no clue.
 
Version 4 is up. Everything you need to know about it is in the first post. This should be the final version, unless I'd need to rebalance stuff.
Also note the nice Readme.html I added.

And xxhe, in version 3, I set it to 1XP (in Lua), but you can change it.
In version 4, there is a formula behind it.
Spoiler :
(Combat Type Value * (1 + 2,5*Era 'StartPercent') ) / ( Game Speed 'ResearchPercent' * # of Units )
This gives a value standing for the % chance that a unit gets 1XP any given turn.

If you open up the Lua file in the mod, you can fiddle with the Combat Type value or with the weight of the other factors.
 
Top Bottom