City Resource Stockpiling mod

TheLopez

Deity
Joined
Jan 16, 2006
Messages
2,525
Location
Oregon
So as I am winding through the code I wanted to create a thread to discuss the progress of the mod comp and the features in the mod comp. Here are the current version information notes:
Spoiler :

-----v0.4BtS------

- Fixed a bug in the civilization founding city stockpiling code... I had
wrongly assumed that city IDs started at 0. They do not.

- Added first pass at the automated city resource bleed code. Each turn cities
will bleed out a max of 10% of their stockpiled resources divided between any
cities within a 10 tile radius. Cities that have the same number of a
particular resource as the target city won't bleed the resource to them.

- Added the city resource export screen. This screen is accessed by clicking on
the appropriate resource in the main city screen.

- Added export order infrastructure that will delay delivery of exported city
stockpiled resources till the next turn. It might be good to add a delivery
delay timer to the ExportOrder structure. This way modders could change the
code so exported city stockpiled resources could take n number of turns to
reach the target city where n is the number of tiles between the cities.

- Modified the city resource bleed code so it uses the export order code. This
will enable modders to change the python so the automated export orders can
be cancelled. This is done by just removing the code that disables the cancel
export order button.
Spoiler :

-----v0.3.5BtS------

- Added <bCarriesCityStockpile> and <iCityStockpilePercent> tags allowing
modders to indicate if a unit should take some of the stockpile from a city
and carry it. If the unit happens to be a settler unit then the units
stockpile will be deposited into the city that the unit founds.

- Added mouse over information for units so stockpiled resources are displayed
correctly

- Added the <FoundingCityBonusStockpiles> tag structure allowing modders to
specify one or more bonus stockpiles to the founding city of a civilization.

-----v0.3BtS------

- Added bonus decay rate code infrastructure to CvCity in preparation for decay
rate modifier tags in the building and tech info structures.

- Added bonus decay rate code infrastructure to CvPlayer in preparation for
decay rate modifier tags in the building and tech info structures. Also
updated code that founds cities so bonus decay modifier is updated to include
the players values if available.

- Added the <BonusDecayRateModifiers> tags structure to the building info
structure that provides modders the ability to specify that a building changes
the decay rate for one or more bonuses. The value is defined in terms of
percentages. A negative percentage value will reduce the decay rate. A
positive percentage will increase the decay rate. If one or more decay rate
modifiers end up changing the decay rate to a negative number then the system
will automatically change the decay rate to 0 since negative decay rates do
not make sense.

- Added the <BonusDecayRateModifiers> tags structure to the tech info structure
that provides modders the ability to specify that a tech changes the decay
rate for one or more bonuses. The value is defined in terms of percentages. A
negative percentage value will reduce the decay rate. A positive percentage
will increase the decay rate. If one or more decay rate modifiers end up
changing the decay rate to a negative number then the system will
automatically change the decay rate to 0 since negative decay rates do not
make sense.

- Added a forth pass read for the Civ4TechInfo.xml file to enable the
<BonusDecayRateModifiers> tag.

- Added the <RequiredStockpiledResources> tag structure for the unit info
structure. This allows modders to require one or more stockpiled resources
for units to be trained.

- Added the <RequiredStockpiledResources> tag structure for the building info
structure. This allows modders to require one or more stockpiled resources
for builgings to be constructed.

- Added the <RequiredStockpiledResources> tag structure for the project info
structure. This allows modders to require one or more stockpiled resources
for projects to be constructed.

-----v0.2BtS------

- Added feature to count the number of appropriately improved plots. Updated
the SDK code to award an extra resource stockpile for each tile that is
appropriately improved. Appropriately improved is defined as an improvement
that makes the bonus valid... fishing boats on fish, whaling boats on
whales, etc.

- Added the <BonusMaintenanceCosts> tag set to the building info struture that
allows modders to specify a maintenance cost in stockpiled bonus amount. If
there isn't enough stockpile of a particular type of resource available then
the building will become effectively disabled - it will not provide its
benefits until a stockpile of the required resource becomes available.

- Added resource consumption code for buildings. When a building does not have
the stockpiled resources to be active then they are made dorment until there
are enough resources stockpiled to make them active again.

- Updated the city screen UI so hovering over buildings shows required
maintenance bonuses if needed.

- After much internal debate the decay rate has been changed to a percentage
instead of an absolute. This way a resource cannot decay into nothing.
Instead resources will decay by the percentage provided. This will allow for
more flexability in the future when building and technology decay rate
modifiers are added. The decay rate is applied to resources after everything
else has had a chance to eat away at the resource. For example if a city has
a decay rate of 25% for fish and that city has a stockpile of 12 fish at the
beginning of the turn, a building that requires 2 fish/turn then there would
be 7.5 fish available after buildings consume their required maintenance and
the decay rate is applied. One will notice after several turns the growth of
the resource will slowly decay realistically modelling the aging and eventual
spoiling of the resource meaning: STOCKPILE GROWTH IS NOT LINEAR!

- Updated the building and bonus pedia screens through the SDK to make sure
they reflect stockpiling information correctly.

-----v0.1BtS------

- Setup City Resource Stockpiles infrastructure

- Added the required infrastructure in the SDK to support having cities
stockpile all resources

- Added support methods in the SDK to check to see if resources are being
worked by a city.

- Updated the UI so hovering over resources in the city screen display the
correct number of stockpiled resources and the number of resources per turn
that get stockpiled.

- Updated the bonus change and hasBonus methods to use the new bonus local to
city code to make sure bonuses are only given to the city owning the tile. A
configuration option to change this will be added so modders can deside if
they want cities to be greedy or not.

- Added the <bStockpileable> tag to the bonus info structure. If the tag is set
then that bonus resource will stockpile in cities, be unavailable in other
cities if configured to do so, etc.

- Added the <fDecayRate> tag to the bonus info structure. If the tag is set
then the resource will decay the point amount set per turn. If the stockpile
runs out in the city then anything in the city using that resource will "turn
off" until enough of that resource is stocked up again.

- Added the <StockpilingPrereqBuilding> tag to the bonus info structure. If the
tag is set then the resource will only stockpile when the city that has
access to the resource has the building built. Updated the UI so the benefits
don't show up if the prereq hasn't been built yet in the city.

- Updated SDK code so when a city with a stockpile of resources but no actual
resources available runs out of the stockpile the code removes the bonus
effects.

- Updated SDK code so when a city with a no stockpile of resources and no
actual resources available has a stockpile added the bonus effects are then
added as if the city had access to the resource.


Design notes:
Spoiler :

7b) Add resource consumption code.
- Corporations should "turn off" if there aren't enough resources for corporations next turn
11) populate in CvCity.cpp:
- processBonusStockpile
- doBonusCnsumpotion
16) Add trade route effects to stockpile resources
23) Add ability in city screen to select and send resources from host city to target city
24) Add switch per city and per player to turn off bleed effect
25) Add a tag to buildings that increases the resource bleed amount
n) Add configurable game options
- All cities having access to resources stockpile the resources.
n+1) Add python infrastructure to set configurable options
n+2) Extract localizable strings

Ideas:

- Code to manually turn buildings on/off
- Code to manually turn corporations on/off

DONE)
1) Add data structure and infrastructure in CvCity.cpp to warehouse resource amount stockpiling information
2) Expose resource stockpiling infrastructure through SDK to python
3) Define a tag for Bonus info structure that indicates if the resource should stack in cities or not
4) Define tag(s) in units and building info structures that indicates if building the unit or building consumes resources (type and amount)
- maybe key off of <BonusType> and <PrereqBonuses> tags... might want to completely change how these tags are implemented
- done for buildings
5) Update main city screen to show number of resources stockpiled plus growth per turn: X (+Y)
where X is the total amount and (+Y) is the growth per turn.
6) Add tags to building structure that define resource consumption per turn...
7a) Add resource consumption code.
- Buildings should "turn off" if there aren't enough resources for buildings next turn
8) Update main city screen with mouse over info for resources showing total information: production amount, consumption amount ( who is consuming per turn )
- Partially done... need to include unit consumption.
- Make sure to add resource bleed to other cities as part of consumption
9) Add tag to resources to specify required building to stockpile.
10) Add tag to resources to specify stockpile decay rate
12) Add slow bleed of resources to other cities if configured to do so.
- Only bleed resources from one city to another city if the target city can stockpile the resource
- Add configurable option to only allow x bleed distance from host city to target cities
- Add resource bleed cache that is only applied at the beginning of the turn...
13) Add decay rate modifiers tag to buildings and add decay rate getting code
to CvCity CvGameTextMgr should use the getDecayRate method from there
instead of straight from the bonus info object
14) Add building required for stockpiling tag
15) Change building required for stockpiling tag to building class instead or look at code to check for building prereq with civ specific building
17) Add tag structure to add game start stockpiles per civilization
18) Update building and bonus pedia screens to reflect new tags
19) Add decay rate modifiers tag to techs
20) Add tags to indicate stockpiled resource requirement for building construction
- Make sure to take awake stockpile amount when building construction starts
- Make sure to give back the stockpile amount if building construction is cancelled.
21) Add tags to indicate stockpiled resource requirement for unit training
- Make sure to take awake stockpile amount when unit training starts
- Make sure to give back the stockpile amount if training the unit is cancelled.
22) Add tags to indicate stockpiled resource requirement for project creation
- Make sure to take awake stockpile amount when project creation starts
- Make sure to give back the stockpile amount if project creation is cancelled.

 

Attachments

  • CityResourceStockpiles-teaser.JPG
    CityResourceStockpiles-teaser.JPG
    174.5 KB · Views: 992
  • CityResourceStockpiles-teaser2.JPG
    CityResourceStockpiles-teaser2.JPG
    74.8 KB · Views: 867
  • CityResourceStockpiles-teaser3.JPG
    CityResourceStockpiles-teaser3.JPG
    49.1 KB · Views: 791
Here's a question for the community... should transfer of resource stockpiles be automatic or should something like a supply wagon unit be needed to transfer resources from city to city? I am going to add a configurable option to allow modders to decide if cities should be greedy or not so that isn't a question. What I mean by greedy is: resources worked by one city won't be accessible to other cities like it is in the game right now. Honestly, having gold available in one end of an empire shouldn't mean that it can automatically go to the other end of the empire automatically.
 
Manually is probably to much micromanagement imho.

True, but some people like that... what do you think of the rest of it? If manually doesn't work, should the resources bleed over to adjoining cities then? Kind of like a slow bleed of resources? The algorithm could be something like this:

Original city generates 3 copper a turn and 100 stockpiled.
Player builds a city so 10% of the original's city copper bleeds over a turn to the new city if the greedy config option is turned on. Honestly, I could make the 10% a config value too. This way resources might eventually bleed out over the entire empire, if they aren't consumed first.
 
I've been thinking about this alot lately, like I mentioned in the DRM thread, I really like the idea of being able to produce resources from other resources. I think that it really opens up alot of options to do things through resource requirement.

My response to your first question is that I think it should be something done automatically, I also think that the stockpiles should only be available locally (without some sort of National Project). You could even make it so that you can't stockpile X resource in a city without Y building there (No BONUS_STOCKPILE_GRAINS for you, yeah you have Corn, Rice and Wheat, but no Granary). If you tied Resource creation to the resources themselves (BONUS_BRONZE_WEAPONS requires BONUS_REFINED_COPPER, BONUS_TIN and BONUS_LUMBER) you could then have Buildings with multiple outputs (a Forge can create BONUS_BRONZE_ARMOR, BONUS_BRONZE_TOOLS, BONUS_BRONZE_WEAPONS, BONUS_IRON_ARMOR, BONUS_IRON_TOOLS, BONUS_IRON_WEAPONS so long as the city it is in has the requisite stockpiled resources) <--This is actually something I've been tweaking from BRC.

Another thought that I had was tying Resource creation to Improvements as well. Take a tiered Improvement setup like what was used in DCD (and some others if I'm not mistaken) and have it so an Opencast Mine on a plot with Copper will add 9 units of BONUS_COPPER_ORE and 1 unit of BONUS_TIN to the working city's Stockpile each turn that it is worked, after being worked for X turns it upgrades to a Drift Mine which adds extra Yield from the tile as well as +50% (round up?) increase to the "harvest per turn" making it 14 units of BONUS_COPPER_ORE and 2 units of BONUS_TIN per turn; after another X turns of being worked it upgrades to a Shaft Mine for yet more Yield and another +50% increase to HPT (using Drift Mine output as the baseline) making it 21 and 3. The "Town" of the Mine tree could be Shaft Mine w/Refinery, give it a 100% increase to 42 and 6 as well as adding 14 units of BONUS_REFINED_COPPER.

Farms could be a similar thing, have a Grange on some Corn? Each turn it's worked you harvest 10 BONUS_HARVESTED_CORN, when the Grange upgrades to a Farm its HPT increases to 15 and at Estate to 30, maybe Estates also give you an opportunity to choose another Farm/Pasture/Plantation BONUS_ (with an HPT of 10) from a list of those available from connected cities controlled by the player (Farm in city A has Corn and upgrades to an Estate, city B has a Pasture with Pigs and a Pasture with Sheep, City C has a Plantation with Sugar and a Plantation with Dye, player gets to choose from Dye, Pigs, Sheep and Sugar to have produced from the Estate).

Just some ideas, sorry if they were not coherent.
 
I've been thinking about this alot lately, like I mentioned in the DRM thread, I really like the idea of being able to produce resources from other resources. I think that it really opens up alot of options to do things through resource requirement.
Did you see that I updated my Building Resource Converter mod so its compatible with BtS? http://forums.civfanatics.com/showthread.php?t=179993

Huh, could you imagine the mod that you could make by combining the city resource stockpiling mod, building resource converter mod and the upgradable buildings mod?

My response to your first question is that I think it should be something done automatically, I also think that the stockpiles should only be available locally (without some sort of National Project). You could even make it so that you can't stockpile X resource in a city without Y building there (No BONUS_STOCKPILE_GRAINS for you, yeah you have Corn, Rice and Wheat, but no Granary).
Noted in my to do list. That is a great idea... no stockpiling unless you have the building...

If you tied Resource creation to the resources themselves (BONUS_BRONZE_WEAPONS requires BONUS_REFINED_COPPER, BONUS_TIN and BONUS_LUMBER) you could then have Buildings with multiple outputs (a Forge can create BONUS_BRONZE_ARMOR, BONUS_BRONZE_TOOLS, BONUS_BRONZE_WEAPONS, BONUS_IRON_ARMOR, BONUS_IRON_TOOLS, BONUS_IRON_WEAPONS so long as the city it is in has the requisite stockpiled resources) <--This is actually something I've been tweaking from BRC.
Not a bad idea but out of scope for this mod.

Another thought that I had was tying Resource creation to Improvements as well. Take a tiered Improvement setup like what was used in DCD (and some others if I'm not mistaken) and have it so an Opencast Mine on a plot with Copper will add 9 units of BONUS_COPPER_ORE and 1 unit of BONUS_TIN to the working city's Stockpile each turn that it is worked, after being worked for X turns it upgrades to a Drift Mine which adds extra Yield from the tile as well as +50% (round up?) increase to the "harvest per turn" making it 14 units of BONUS_COPPER_ORE and 2 units of BONUS_TIN per turn; after another X turns of being worked it upgrades to a Shaft Mine for yet more Yield and another +50% increase to HPT (using Drift Mine output as the baseline) making it 21 and 3. The "Town" of the Mine tree could be Shaft Mine w/Refinery, give it a 100% increase to 42 and 6 as well as adding 14 units of BONUS_REFINED_COPPER.
Another good idea but again out of scope :p

Farms could be a similar thing, have a Grange on some Corn? Each turn it's worked you harvest 10 BONUS_HARVESTED_CORN, when the Grange upgrades to a Farm its HPT increases to 15 and at Estate to 30, maybe Estates also give you an opportunity to choose another Farm/Pasture/Plantation BONUS_ (with an HPT of 10) from a list of those available from connected cities controlled by the player (Farm in city A has Corn and upgrades to an Estate, city B has a Pasture with Pigs and a Pasture with Sheep, City C has a Plantation with Sugar and a Plantation with Dye, player gets to choose from Dye, Pigs, Sheep and Sugar to have produced from the Estate).

Just some ideas, sorry if they were not coherent.
All good ideas, I will put the ideas that are out of scope for this mod and put them in a bin list so they don't get lost.
 
Huh, could you imagine the mod that you could make by combining the city resource stockpiling mod, building resource converter mod and the upgradable buildings mod?

If you couldn't tell from my previous post, ^this is something I've kinda been fixated on for a little

Noted in my to do list. That is a great idea... no stockpiling unless you have the building...

Another thought regarding this is DRM should be included and you could give Buildings/Techs a "Stockpile Decay Modifier" for things that are perishable, though I also think that if DRM were to be included it should only apply to resources that are gained in the typical way or to stockpile resources which represent things like food (decaying grain and seafood but no decaying cut stone or iron ore)
 
If you couldn't tell from my previous post, ^this is something I've kinda been fixated on for a little



Another thought regarding this is DRM should be included and you could give Buildings/Techs a "Stockpile Decay Modifier" for things that are perishable, though I also think that if DRM were to be included it should only apply to resources that are gained in the typical way or to stockpile resources which represent things like food (decaying grain and seafood but no decaying cut stone or iron ore)
Decaying perishable stockpiled resources? I love it... Noting it down on the to do list... actually, I might add this right now since I have the stockpiling code in a working state.

Oh and one of the things I did from the beginning was to make sure all of the stockpile code was done using floats...
 
True, but some people like that... what do you think of the rest of it? If manually doesn't work, should the resources bleed over to adjoining cities then? Kind of like a slow bleed of resources? The algorithm could be something like this:

Original city generates 3 copper a turn and 100 stockpiled.
Player builds a city so 10% of the original's city copper bleeds over a turn to the new city if the greedy config option is turned on. Honestly, I could make the 10% a config value too. This way resources might eventually bleed out over the entire empire, if they aren't consumed first.

Sounds like a good and reasonable idea.
Maybe the trade routes should be involved in here, more for your own cities, if the city has trade routes with them.


But honestly, design is not really my strong site, so that doesn't have to mean anything.
 
Sounds like a good and reasonable idea.
Maybe the trade routes should be involved in here, more for your own cities, if the city has trade routes with them.


But honestly, design is not really my strong site, so that doesn't have to mean anything.

"Even the smallest of ideas can yield the biggest results" - unknown
 
Decaying perishable stockpiled resources? I love it... Noting it down on the to do list... actually, I might add this right now since I have the stockpiling code in a working state.

It could be combined with buildings. So you can have any number of grain without granary but you get 50% decay rate instead of 5%. Still I think that even stone and iron should decay, just at rather low rate (rust, thieves, etc.).
 
It could be combined with buildings. So you can have any number of grain without granary but you get 50% decay rate instead of 5%. Still I think that even stone and iron should decay, just at rather low rate (rust, thieves, etc.).
Huh, rust, thieves? What a great idea... I smell random events:

X number of gold was stolen from your city treasury by thieves
A leak in your storehouse has caused x number of iron to rust away


As for buildings modifying decay rates, that is a great idea... what about techs too? So if you discover refrigeration your decay rate on perishable resources goes down even more.
 
I like the idea of Building/Tech Decay Modifiers, though I still think that certain buildings should be required to stockpile certain resources

Speaking of events...

What about things like piggybacking on preexisting events? Master Blacksmith, can anyone say Masterwork Items?
 
I like the idea of Building/Tech Decay Modifiers, though I still think that certain buildings should be required to stockpile certain resources
I agree. They will :)

Speaking of events...

What about things like piggybacking on preexisting events? Master Blacksmith, can anyone say Masterwork Items?
not a bad idea,
 
True, but some people like that... what do you think of the rest of it? If manually doesn't work, should the resources bleed over to adjoining cities then? Kind of like a slow bleed of resources? The algorithm could be something like this:
Why not a combination of random and targetted bleed? Manual transport with supply units is micromanagy and a bit annoying, having a switch... much less.

Have a random bleed as you suggested, but also add a "transfer" drop-down, where you can choose a city - then, let's say 1/2 of the random bleed is instead going to the targetted city.

This means if you don't care about the whole thing a lot, it's working its way through your empire and you'll get the benefits after some time - you can just let it "do its thing"; if it's urgent (e.g. in a newly founded city), you can speed the process up.

Lot more coding and city screen modification, though.

Cheers, LT.
 
Would the "bleed" go only to cities that were connected? I also don't think it is a good idea to allow the "bleeding" city to give the collecting city more than they have. (i.e. the collecting city shouldn't be able to surpass the bleeding city simply by existing), maybe if there were a direct transfer option you could manually give them more, but IMHO the bleed should be slow and gradual and only to Connected/Trade Route cities that you control.
 
Would the "bleed" go only to cities that were connected? I also don't think it is a good idea to allow the "bleeding" city to give the collecting city more than they have. (i.e. the collecting city shouldn't be able to surpass the bleeding city simply by existing), maybe if there were a direct transfer option you could manually give them more, but IMHO the bleed should be slow and gradual and only to Connected/Trade Route cities that you control.

The bleed effect would only go to cities that are in the trade network, so only connected cities.
 
Presumably resource "bleed" via trade networks never sends resources to other players...

If you are doing the stockpile at all, you need to have this interact with diplomatic resource trades.
How many are traded in a trade agreement?
Is it one time only, or X per turn? (One time only would be unpleasant - you'd have to keep going back to ask for more.)
Where do they come from? The capital's stockpile, the biggest stockpile, some user specified stockpile, whichever city has the most at the time the actual transfer happens?
If a single deal can be for multiple copies, what happens if you are trading 2 per turn with someone but spent a bunch and only have 1 left at the relevant time? (I would assume the entire deal should be canceled, but it could just be suspended for that turn so that on later turns the trade happens if you both have enough to meet your obligations.)
 
Presumably resource "bleed" via trade networks never sends resources to other players...

If you are doing the stockpile at all, you need to have this interact with diplomatic resource trades.
How many are traded in a trade agreement?
Is it one time only, or X per turn? (One time only would be unpleasant - you'd have to keep going back to ask for more.)
Where do they come from? The capital's stockpile, the biggest stockpile, some user specified stockpile, whichever city has the most at the time the actual transfer happens?
If a single deal can be for multiple copies, what happens if you are trading 2 per turn with someone but spent a bunch and only have 1 left at the relevant time? (I would assume the entire deal should be canceled, but it could just be suspended for that turn so that on later turns the trade happens if you both have enough to meet your obligations.)

All very good questions and ones that we are working through... one step at a time. Doing resource stockpiling is changing a huge subsystem of the game...

Speaking of questions... should you only be able to stockpile resources if you are working that tile or stockpile them all the time regardless of if you are working that tile?

I already have it in the code that you stockpile as long as you have an improvement on the tile. But should you have to work that tile to get the stockpile?
 
Top Bottom