Replacement Supply System for Civ V

sman1975

Emperor
Joined
Aug 27, 2016
Messages
1,370
Location
Dallas, TX
Hello,

I'm thinking about designing a new supply system for Civ V. The current one of reducing global production seems too coarse of a resolution for such a fine game.

Given my limited LUA abilities, I'm trying to keep the system abilities fairly simple, but more tailored to what supplying military units in combat really means. Here are my initial thoughts on what the system would look like:

1. The game's current supply system would still be used to reduce global production - only at a much lower rate, and maxing out at something like 20% (vice 70% in the game). The supply formula might need adjustments to raise the number of units in supply.

2. Reduce default unit healing numbers to "0".

3. Create a "Reinforcement" function that adds back HP's to units based on where they are:
- If at peace, units in friendly territory and neutral territory heal at standard game rates.
- If at war, units in friendly territory not adjacent to enemy units heal at normal rate. Units in neutral territory not adjacent to enemy units heal at half the neutral heal rate.
- Also, if at war, units in enemy territory not adjacent to enemy units can only heal if within a certain distance from friendly cities. Those distances are based on era, and certain military buildings in that city.
- Units adjacent to enemy units don't heal at all.

4. The Reinforcements distance limit for eras: As civs progress through the eras, their ability to project power and therefore supply would also increase. For example, in the Ancient era, they may be able to Reinforce units in enemy territory up to 10 hexes from a friendly city. In the Industrial era, they may Reinforce units 20 hexes away. If they had an Arsenal in that nearest city, maybe that limit raises to 22 hexes.

5. Certain buildings in the nearest city would add length to supply lines: Armory (+1? hexes), Aresenal (+2? hexes), Military Base (+3? hexes), Airport (+1? hexes). World Wonders like Alhambra, Himeji Castle, Red Fort, Kremlin, Pentagon; as well as National Wonders such as Heroic Epic and Palaces - should all contribute distance to supply lines, but at a pretty small rate so they don't become too OP (e.g. +2 each for World Wonders, and +1 each for National Wonder - only if these buildings are in the nearest city). May also want to limit buildings so that only the highest contributing building is counted - helps remove the problem of building obsolescence. If going this approach, Wonders numbers would probably be adjusted much higher.

6. Using the game's current supply system, if a civ didn't have too many units, all units in enemy territory not adjacent to an enemy unit and within the Reinforcement distance from the nearest city would heal (albeit at a fairly low rate). They would also be able to attack normally. If the civ had too many units/units out of supply, the excess number would introduce a random chance the unit in enemy territory would not heal or would not be able to attack. This chance of no healing/attacks would grow based on how many excess units the civ had.

7. Give all combat units the ability to heal from pillage. Or a healing from killing enemies. This would mitigate some of the crushing impact of Reinforcements (as described here) on long-distance invasions - and feels fairly historically accurate, at least until the late 20th century.

As with all mods that adjust the game's normal components - compatibility with other mods is always problematic. It is also possible to thoroughly screw up game balance due to interaction with other mods. The key workaround for this is to ensure this mod loads last, then hope for the best...

I'm not sure how to handle sea/coast hexes in calculating Reinforcement line limits. Also, I'm not sure if units in friendly territory when the civ has too many units - should they also be subject to a smaller random chance they may not be able to attack.

OK - those are my initial thoughts on a revamped supply system. What's good? What's bad? What should be added/dropped? And if you have any thoughts on what some of the "numbers" should be, i.e. number of units in supply formula, global production penalty, Reinforcement distances per era, buildings to help increase Reinforcement distances and by how much, etc. - please pass those along as well.

Thanks!

Sman
 
Last edited:
With regard to the reinforcement distance limit, I was thinking it could perhaps be calculated with movement points, and would therefore vary depending on the terrain and the presence of roads and railways. For sea/coastal hexes, I realize this sounds drastic, but perhaps supplies shouldn't be allowed to cross neutral bodies of water (although they could cross into opposing territory if the coastal waters of opposing cities touched, to allow short-range amphibious offensives such as Operation Overlord). This would make transoceanic amphibious assaults between roughly equivalent civs next-to-impossible, which would be an improvement in my view. Regarding when units in friendly territory when their side has too many units, I don't think a random chance for lacking the ability to attack needs to be added, not initially at least, perhaps it could be introduced later if a very extreme imbalance resulted. The numbers for the supply formula, production penalty and so on you propose sound reasonable to me.
 
Thanks for the feedback - good points all. Here's what I think:
- I'll have to check, but I'm pretty sure WHoward69 has solved the path calculation problem. If not, I can experiment with the GeneratePath and GetPathEndTurnPlot functions to see if they can give me some useful information. I like the idea about tying it to actual movement capability instead of just a number of hexes - for example two enemy cities are 10 hexes from the nearest friendly city. If there's a road all the way to the first city, and the other has no road and only hills exist between those two cities, it seems obvious the first enemy city would be much easier to sustain an attack against. I think this can be done without much trouble, but I'll need to research the best method.

- On the sea resupply, I was thinking the exact same thing earlier. Just "assume" the units have enough supply with them to initiate operations in hostile territory when they land (they'll probably be at 100% HP). Repairing damage on hostile territory will require Pillage (scavenging on enemy lands - a time-honored tradition among expeditionary forces. Recovers 25HP IIRC). May even add the HPHealedFromDestroyedEnemy promotion to all units, with a low amount of healing (maybe 10-20? The mystic blade Recruitment promotion awards 50HP). This at least gives the invaders a possibility to heal while deployed.

- The Reinforcing function begs the question - if we make intercontinental invasions sooooo difficult, the AI probably will never invade with enough combat power to survive, let alone win. I don't think it will work very well, as it hands the human player a huge advantage. Perhaps I should write it so the AI heals like they would in a normal game, and let this new Reinforcement system only apply to the human player? Would actually increase the challenge I think.
 
Last edited:
Healing from destroyed enemy units in addition to pillaging is a good idea, perhaps the amount gained could increase with policies and/or certain wonders. I agree that the AI will have big problems adjusting to the new system. Maybe players could be given a checkbox option to disable it for the AI, so that they could choose which they liked best (I personally agree that it would be a fun challenge). As an alternative, perhaps it could be given graded healing bonuses depending on the difficulty level.
 
Great suggestions. I've seen posts on programming a front-end at game setup time, and could probably handle it with a little effort - but I'll probably push that to V2 and focus on the actual Reinforcement process and make sure it "works" (i.e is actually fun to play) before handling the ascetics.

V1 will probably have a "globals.lua" file and I'll set it up to default to "all player civs" use the next system, with the ability to comment out 1 line of code to make the system only apply to the human player. Will make it easier to upgrade when it's time to add the front end in V2.

I'll look into this further in the next few days. I'm wrapping up the current mod I'm working on today to give to some playtesters to work on. Should free up a week or so to work on this. Goal is to have a defined process finalized by the end of the week. Within the process will be all the values (healing rates by difficulty level, Reinforcement route limits, building contributions, etc. ) fully set, and only using functions required to implement the process that are within my ability to code... :crazyeye:

As part of that effort, I'll probably post a MS Word document with some empty tables that I could use your help on filling in. I'll also start working on prototype functions tomorrow - to see if some of the intended approaches work and don't make the game less stable.

Thanks!
 
First rough draft of defining the Reinforcement process. I think it captures most of what we've looked at so far. Areas that need a decision are in red.

Please take a look and let me know what you think the numbers should be; and also if I've left anything out that should be here.

BTW: document is in PDF format, as the website was giving me some warnings about Word documents being unsafe to share. Didn't want to scare anyone off. Will take any comments from the forum here and update the document, then republish as the mod develops.

Thanks.
 

Attachments

  • CiVilized Supply - Reinforcements.pdf
    487.5 KB · Views: 180
The numbers proposed in the document seem fine to me, I think it's somewhat hard to make judgments about them until testing. I can't believe I didn't think of this earlier, but scouts should of course be exempted from these rules, otherwise they will get destroyed through attrition almost immediately. A chance for reinforcements when adjacent to enemy units is an interesting idea, I would guess the chance should be closer to 10% than to 25% to maintain balance (of course this is subject to whatever results are revealed by testing). Likewise, the 5%-50% chance against out of supply units sounds good. For supply line length, if it is going to increase by era entered, I think the increase from buildings should only count the highest, but if not, it should be cumulative. For the Expeditionary promotion, perhaps it should apply to melee units but not ranged ones (just an idea)?
 
Thanks, Ferris - this is quality feedback. Some considerations:

- Completely agree that these are all "starting" numbers, subject to extensive changes after testing.
- Scout healing? Duh.... May want to think if there are other units like this, e.g. settlers, GG's, religious units, air units, ships, etc. Even if the Reinforcements process doesn't apply to them, they still will have to be manually healed. Great catch.
- The chance of Reinforcement when adjacent to enemy units was only intended for friendly territory, to demonstrate the defender's advantage of fighting on home ground. However, lower numbers make good sense here.
- Supply line length: the more I think about it (length growing by era or cumulative range increase) - it's really 2 methods of accomplishing the same task: power projection capability grows over time... Since we're really talking about 2 sides of the same coin, I'd prefer to go with the cumulative approach and no era increase. It's more straightforward to code, and less computationally intensive.
- I had to think it through a bit, but I've come to agree with you on excluding ranged units (e.g. archer, siege, helicopter, air units) from healing from kills. Just doesn't seem to represent the "scavenging" aspect of the promotion. Units at distance shouldn't be able to benefit from that. So, if we go that way (and probably should) the only units getting this promotion would be Recon, Mounted, Melee, Gun, and Armor.
- Something to think about: do we touch the Medic 1 & 2 and Survivalism 1 & 2 promotions, or let them work as originally designed?
- The Reinforcement function has to be robust enough to accommodate other potential mods loaded at the same time. To maximized compatibility with other mods, it may be smarter to not touch the healing on friendly territory. Definitely a primary goal of testing should be to look at non-land-based units to make sure we don't break them. It may be better to still keep in automatic healing at a very low rate, and use the Reinforcement function as a means to increase those healing numbers under certain circumstances. No need to go there yet, though, unless testing shows unfixable problems with the current design.

Am experimenting with Supply Lines today. There are many methods/functions described in the modiki with absolutely no documentation/examples. Will have to perform my own tests to get a better understanding of how they work. Some of them may definitely simplify the coding, IF they work the way I think (hope) they should.

Will update the PDF later today and post when it's done. Thanks again for the very helpful suggestions and catching the bugs in the design.
 
Last edited:
OK. Ugh. After a day or so of testing the "Supply Line" concept, I'm sorry to say none of the existing LUA methods/functions support calculating movement points between two plots (i.e. our unit and the nearest friendly city). I've spent half a day working with WHoward's pathfinding code but have still not been able to get it to work properly. It might take me "a while" to beat it into submission. In the interim, so as to not slow down the rest of the project, I'd like to propose an interim solution - described below. The rest of the solution will be constructed in such a way so that when I get the pathfinder code working, upgrading to a movement-points based Supply Line will be fairly painless.

Interim Solution for Supply Line length would look something like this:
- Supply Lines will consist of a set number of hexes, with no account taken for movement points.
- Buildings will cumulatively increase these lines, demonstrating improved supply capabilities over time (as it takes time/tech to add these buildings to a city - effectively simulates supply projection growth through the Eras)
- Certain technologies increase Supply Line length, such as the Wheel, Horseback Riding, Guilds, Railroad, Combustion, Radar - to simulate mobility improvements in lieu of roads & railroads (I'm OK with this level of abstraction, especially when we're talking about 40 year game turns... )

So, for example - the Supply Line length would be determined in this manner (numbers entirely arbitrary and should probably be scaled down):
1. Normal Supply Line: 5 hexes
2. Buildings increase length: Palace (5), Arsenal (1), etc.
3. Techs increase length: Wheel (3), Horseback (2), Railroads (5), etc.

A capital city with an Arsenal and has discovered the Wheel: Supple Line length = 14 (5+5+1+3)

A fringe city on the edge of your empire might only reach out 8 (5 normal length + 3 for the Wheel).

Again - this is only "phase 1" - to get something working while the rest of the mod can be developed/tested. If the rest of the design proves workable, desirable, I can go back to the pathfinding code and attempt to get it working.

How does this sound?
 
I'm also starting to worry more about compatibility with other mods as I start to work out ways to actually implement the rules described above.

I would be much safer to not fiddle with the "healing" system at all - as the current design requires a complete substitution framework be used. Any other mod that also adjusts healing rates, etc., will probably be broken by this approach.

Some suggestions that would greatly improve stability/compatibility:
1. Instead of preventing healing, how about a damaging function similar to the "Enemy Blade" type promotion (used in the Kris Swordsman's Mystic Blade)? In this method, units in enemy territory would be damaged a certain number of HP each turn - assessed at start of turn. They'd still heal at end of turn if they are eligible - call it the defender's advantage. Supply impacts would kick in when they try to take the offensive and attack next turn.
2. Can make the amount of damage variable and/or random, based on distance from supply base (nearest friendly city - e.g. a unit using 50% of its supply line length has less impact than one using 100%) and/or total units out of supply, etc.
3. Units in enemy territory can still heal by pillage and killing enemy units. Maybe Ranged units would also lose HP even though that can't heal by killing enemies - can still heal by pillage though (can't prevent that).
4. Can also attrit (non-scout) units on neutral territory if during war time - to simulate less effective reinforcing functions.
5. Can also attrit units on friendly territory if they're next to an enemy unit (like the citadel works, and even make it larger impact based on more enemy units nearby) but I'm not sure I like this too much. Would rather use something like #6 & 7 (but at a much lower probability)
6. Can still prevent units from attacking on semi-random basis if they are out of supply.
7. Could also prevent units from moving if out of supply, if desired
8. Maybe give all Great Generals a healing bump, like the Great Khan? Would probably help the AI conduct invasions better.

So, basically, the approach consists of taking HP away from units based on location instead of changing the way they are healed - and possibly impacting their ability to move/attack. I think this is much safer than the original design. I believe we can come up with a modified design that accomplishes most of the original design but in a much safer way.

Thoughts?
 
Last edited:
The interim solution is fine with me. Take what time you need to get the pathfinding code to work. With regard to the solutions for compatibility with other mods, I have no issue here either. I agree that they accomplish the goals of the original design. For The Medic and the Survivalism promotions, and the Great General healing bonus, I'm sorry, I just can't imagine clearly enough how they'd work in practice to make a judgment about them. I would advise having them in at first, and if they are found to not go well with the supply system, they can be removed or modified.
 
Version 2 - based on discussions the past couple of days. Key change is the Attrition Table on p.3. Please take a look and let me know what changes are needed, or if the process needs to be simplified/condensed (i.e. remove difficulty-based damage, etc.).

Sorry if it's confusing - too much of this was written BC (before coffee... )
 

Attachments

  • CiVilized Supply - Reinforcements - v2.pdf
    505.5 KB · Views: 179
Also - concerning Attrition - one of the effects if to stop movement. It's certainly allow some movement, but not the whole allowance - i.e. cut infantry moves from 2 to 1.

Also - it's not mentioned, but will be next edition, if a unit is outside of any Supply Line, they'd enjoy the maximum chance of attrition (70%)?
 
Last edited:
function testing going ok - slow but steady progress. Question: System is set to "attrit" only "Combat Units" in enemy territory - which leaves out primarily Recon, Archers, Siege and Helicopter units. Should those also be subject to Attrition?

IOW - attrit any land unit with a combat strength > 0 (which excludes civilians)?
 
I like it. At a glance, the possibility strikes me that there might be somewhat excessive damage to units in neutral/enemy territory which are in supply, but I do not think this should be changed. The figures laid out should be the basis for testing. Agree that attrition should slow movement and units detached from supply lines should suffer the maximum chance for attrition. All this makes me think that perhaps, in later versions, there could be special, suitably hard-to-obtain promotions mitigating some of the penalties resulting from the new system. This would be something for the far future obviously. I'm glad to hear that function testing is progressing. For the four categories in question, I don't think Reconnaissance units should be subject to attrition because their inherent combat strength is so low. Helicopter units in my view should be. For the ranged units, perhaps instead of having them undergo attrition, have them be unable to fire that turn to simulate ammunition shortages? As before, all of this could be changed as needed.
 
Good feedback - all of which sounds very good to me. From what I read from your post, it sounds like ALL land units with combat strength should have to deal with Attrition. The way the concept is evolving this actually sounds like the right way to go.

I especially like the idea of mitigating some of the Attrition effects for experienced units. Creating the promotion to do this is simple. However, as it is completely implemented using LUA (vs. database) there is no way the AI will understand what it does and how to use it, so therefore won't choose it properly. What do you think about tying this mitigation aspect to unit level? Basically, every time a unit gets promoted, it gains a unit level. Usually these peak out at about level 10-15. Perhaps we could use a rule that says L1-5 units experience 100% of the effects of Attrition. L6-10 units experience 75%, and L11+ experience 50%? It's another way of saying very experienced units just do things better, like supply, than newer units.

This approach is easy to code, and quite passive - so it doesn't matter if the AI understands it or not - it will still get all the benefits. That is, IF the AI is using Attrition and we don't limit it to the human player.
 
Last edited:
OK - about to wrap up testing for today. Here's what's working right now:
1. Mod correctly calculates the maximum Supply Line length for each city, adjusting for game difficulty, certain buildings in that city, and certain techs discovered by that civ
2. Mod cycles through all a player's units to determine what Attrition effects to apply, if any (steps 3-8 are applied for each Domain = Land unit with combat strength > 0)
3. Mod will determine which friendly city provides the most efficient Supply Line to a unit (efficiency measured by how many hexes separate unit & city vs. the maximum length of Supply Line the city can provide)
4. Mod will determine what the percentage chance of Attrition for a unit is, based on its location (friendly, neutral, or enemy hex) and if the civ is at war with anyone
5. Mod will test for Attrition impact to movement. For example, if the Attrition chance for the unit is 40%, a random number between 1 and 100 is generated. If the number is lower than 40, 1 movement point is removed from that unit that turn. If the random number is lower than 20, then 2 movement points are removed
6. Mod will test for Attrition impact to ability to attack. It will generate a different random number (1 to 100) - if that is less than the Attrition chance (40% in the previous example) - the unit will not be able to attack. It might be able to still move, though
7. Mod will test for Attrition damage to units at war and/or if there are excess units exceeding supply capacity. It will apply damage based on the values in the Attrition Table (p3 of the guide).
8. Mod will display a notification on the right side of the screen for each unit impacted by Attrition
9. Global production limit and normal healing rates have been adjusted downward.
10. Mod is designed so a single line of code in the CPPSGlobals.lua file can be changed which will make the mod only apply to the human or all major players, depending on the value

Had to add #3, as testing was showing the capital was usually a far better supplier than fringe cities. In other words, the capital may have been more hexes away from the unit, but the Supply Line efficiency was much better. Had to adjust a lot of the logic so the mod would compare all possible cities and pick the one that had the lowest quotient.

What's not working (yet):
1. The increase in chance of Attrition based on number of adjacent enemy units is not working predictably. Both increasing the chance of Attrition and increasing damage based on the number of adjacent enemies isn't working for all units in all situations. Seems kind of random for some reason. Still checking that. Mod does adjust both chance and damage for adjacent enemy cities, though
2. Haven't added any adjustment for Attrition chance based on unit level yet - that's a fairly easy fix, just haven't gotten to it yet
3. There are some unit combat types I'll need to make some adjustments for (i.e. Archers and Siege units have a chance of not being able to attack, but they are also subject to losing HP's on enemy territory - need to adjust for that).
4. Need to add the "Expeditionary Forces" promotion - a fairly quick fix
5. The code is a bit messy at the moment, as several large changes to design occurred today. Need to organize and clean it up before release
6. Also, some small adjustments need to be made to the numbers in the guide - some minor variations exist in the code, so the manual needs to be brought up to date

In its current state, the numbers in red/green in the guide being what they are, the mod generates lots of Attrition impacts each turn. One of the test games I'm running has about 10 friendly units in the Ancient era. If there are no "excess units" - units without "supply" in normal game turns, I might see 1-3 notifications pop up each turn. If I add 4 units (now 14 total), the game shows 3 excess units and I'll see 7-8 notifications each turn. It really looks like it's working as intended. Of course, this may mean the numbers need to be softened a bit, and I'm quite OK with that. The most painful Attrition effect is the not being able to attack. May need to tweak that chance downward. Or not...

There really isn't a lot of work needed to get the mod in a ready to test state. I need about 4-8 more hours to do this. Unfortunately, I'm not sure how much time I'll get to work on it tomorrow, but believe I should be able to post it sometime in the afternoon or Monday at the latest.
 
I'm excited to see the mod approaching testing so soon, as before take the time you need. I think it's logical that the capital would often be a better supplier than smaller cities, even though they are close to the units in question. For mitigating attrition, perhaps have the AI receive the automatic improvements suggested, but the human player has to get the same improvements through separate promotions?
 
OK - mod is "finished..." But I haven't put it through a few 500+ Live Tuner runs to test stability. I haven't seen any CTD's duing development, so I'm thinking the mod is pretty stable.

One thing that's bothering me a bit - the current set up will see Attrition just about every turn. About 25% of the units will experience an Attrition effect when there are no excess units. When there are excess units the number is closer to 100%

EDIT: Scratch the previous paragraph. Need more testing to see if this is really a true statement. I'm not seeing too much Attrition on recent testing.


The reason is there are 3 potential impacts (movement, attack ability, and HP loss). Each of these get a separate test, but this still allows 3 attempts to impact a unit, even if there are no excess units and the unit is in friendly territory. Granted, the odds are slimmer there, but still no nil.

If this is OK, then the mod is ready for testing. If not, then how do you feel about limiting the Attrition impacts to only one actual effect per turn - something like this?
- Test against movement first - if that succeeds, then don't do any other effects.
- If that fails, test against attack ability. If that succeeds, then don't do any other effects.
- If that fails, test against HP loss...)

Let me know. Thanks.
 
Last edited:
Mod is posted!

https://forums.civfanatics.com/resources/combat-power-projection-system.26252/

A couple of known issues:
- Unit flag isn't ghosted when a unit loses all its movement points
- The unit supply formula the basic game uses to determine how many units a civ can support is a one size fits all at the moment. I haven't made changes to each of the difficulty levels in the handicapinfos file - just not sure how generous to make the new supply system yet.

There's probably a million things I've missed, so no pride of authorship. Please pass along all observations, suggestions, etc. Can only make it better.
 
Last edited:
Top Bottom