1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

The Medieval Economy

Discussion in 'Civ4Col - Medieval: Conquests' started by Kailric, Sep 15, 2013.

  1. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    I am converting this first post to detail all the changes about the Economy in M:C


    -sell 25 units per worker, Wily sells 50.
    -connected trade posts increase it by 25
    -Each connected foreign city without a trade post should increase by 5
    -Each connected domestic city should increase by 5.
    -Each connected domestic city with a 'market' building should increase by 10/15/25.




    Current Screen Shots


    Original Post:
    Spoiler :

     
  2. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Here is an idea I had on this. After a city builds a market and starts to be able to sell goods at market we could introduce a new Resource Bar above the current one where the player could place goods for sale at the local market. The local market wouldn't bring as much gold as selling goods along trade routes but it would satisfy a cities desired goods and increase fealty and happiness. This would keep the market system separate from the production system so you would not have to worry about modding it.

    Each time a player unlocks a good he can sell it gets added to the list of Marketable goods.
     
  3. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I'm not sure making a brand new system for domestic sales in cities is the way to go. Sounds like too much work compared to what we gain from it. Our greatest shortcoming is programming time meaning we should plan what to do with the little we do have. Each time we spend an hour on one feature, it's an hour not spend on another one. We should be better at figuring out "what is good enough?" rather than "what is the ideal solution?".

    I plan to go on with the plan to just get units and buildings have a demand and for now not really care what to use it for. Well I plan to hook it into the yield consumption as mentioned earlier. It would be best if the AI could figure out how to use it. In fact we need far less special rules for AI.
     
  4. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Well, once we get a new working model to play with then we can test things to see how we like it, so by all means, continue with your plan:)
     
  5. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    While looking for a good place to hook in demands I read though CvCity::calculateNetYields() and.... :eek::confused:

    For starters when it calculates yields consumed using an odd approach. It's a loop, which goes through all units to figure out which yields their profession consumes. That is ok, but it does it inside a loop, which goes through all units. Yeah, nested loops. It would appear that the outer loop is unneeded. This appears to be a vanilla issue and I suspect it's a relic of some pre-release code, possibly debug code. From what I gather if we set 3 farmers to work in a city and nobody else, then it will check 9 units as each farmer is checked 3 times. As this is n*n checks, it becomes 25 for 5 farmers etc. However it can break the outer loop in certain conditions meaning a 20 pop city might only check 20 times, not 400. I'm not entirely sure about the specifics about this and it should need further investigation.

    There is some code for heavy armor. Why would heavy armor needs special code? Why isn't it using the general code like say weapons do?

    A general lack of comments makes it hard to figure out what goes on as multiple tasks appears to be blended into each other. It might be a good idea to do more than one thing in the loop for performance reasons, but we should make it human readable too.

    I think this function needs some cleaning, but for now it works and I don't feel like touching it.

    How to continue coding
    I came up with the idea to copy the custom house code from RaR. It comes with on/off for each yield and threshold. Implement this and cap sales at domestic demand and we have the user setup we were looking for. The AI might not like this, but with a little modification to how it handles raw materials I think we can get around that issue. It would then only be able to sell raw materials domestically meaning everything it sells should be raw materials. Minor setup issue.

    I also wondered about the issue that money is too hard to earn in the beginning. I came up with the idea that the type of market place shouldn't tell which yields to be sold. Instead all yields are tradeable at any place, but there is a cap on how many you can trade each turn and the marketplace increase this cap. The higher the level the higher the cap. With no marketplace at all the cap should be fairly low, like 2 or something. Not much, but it means a great deal compared to not being able to sell at all. 2/turn for each city accumulates to something, enough to at least keep some workers at work.

    New export price idea
    I had another idea regarding trading. When you buy/sell in "Europe" the game remembers how much you traded and use it to generate new prices. This mean if you export the same over and over the price of that will drop and not raise again even if you stop exporting it for a while (vanilla issue). If we duplicate the counter and have one for total traded amount for statistics and stuff and another for price calculation we can modify the latter as we want. If we do "* X / 100" each turn where X is written in XML, then we can set it to say 95 or something and the traded amount will decrease 5% each turn, meaning Europe will forget you traded a huge quantity after a certain cooldown period and once again be able to raise the price. Likewise if you go into war and buy 1000 weapons and none after that it shouldn't affect prices too much after 100+ turns.
     
  6. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Calculatenetyields is heavily modified for sure. The multi goods produced modified it and I modified that even further. The heavy armor is there because it is a check to see what armor is being produced at your armories. Remember you can change what armor you want your smiths to make so I added code to check for this. It should be rewrote and made modded friendly perhaps so that any building could be modded in the XML to produce different types of yields bases on user selection. Or maybe there is a better solution to this? The AI atm always chooses the best armor to build.

    The other changes you percent all sound great to me.
     
  7. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I think it should be redesigned to have one yield produced for each profession. The armorsmith should then be an expert in multiple professions and the building should house multiple professions. This design change is likely the most modder friendly we can come up with as it gives options for non-armor professions as well.
     
  8. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    Yeah, having multiple professions per building should make that possible easily without needing a special system. That way, you could also make some of the advanced armor professions discoverable via techs if you want (which could come after gaining access to the yields themselves). Early on you'd have to import Plate Armor from abroad to equip Knights, but after advancing could eventually become able to produce it domestically.

    The other changes sound good to me as well. Re the price levels for Europe screens, one thing to keep in mind is that Europe prices trending constantly downward forces you to seek out sources of new unexploited Yields (and gradually build domestic consumption for independence in the case of M:C) But it would be nice to have at least some recovery. One option might be to eventually let Europe screens use the same demand system as cities, raising/lowering prices if their demand is persistently under/over-fulfilled. The vanilla price system seems quite arbitrary and discontinous with big semi-random lurches from time to time, so I'll be glad to be rid of it! :p:king:
     
  9. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I finally finished selling on the domestic market using code from domestic market and custom house from RaR and Androrc's domestic market modcomp mixed together with my own modifications. This turned out to be a lot harder than I expected. It looks fairly simple, but it ended up being fairly complex.

    Still missing:
    demands from units
    restrictions on total sales from a city. Right now it sells 200 if the building demands is high enough.

    I also wonder if it would be a good idea to add the production bonus to demands. This could be yet another reason for producing bells.

    I'm also not really happy with the way local prices are calculated. They seem less random than I wanted and they appear to be fairly static. This part of the code might be completely redesigned at some point.

    I plan on adding a yield group of imported goods. The minimum sale price of those should be 25% higher than the buy price in "Europe", with a minimum of +1.

    I'm wondering if it could be doable to make a list of domestically sellable yields, sort of like a cache for "player can sell these". Right now it lists a whole lot of yields, which will never be sold domestically. It even lists uninvented ones.

    Another thing. I didn't care much for the text strings at this point. They are copy pasted from RaR and as such some of them makes little sense in this context. They should be rewritten once the whole feature is complete.
     
  10. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I added yield demands to units. That was more or less copy paste. The only thing, which prevented this from being a 5 minute job is that I made a cache rather than recalculating the demand each time it's needed. Most of the time I used on this was spent analyzing the code to figure out where to hook in to update the cache. It turned out that to work efficiently the cache needs to be able to add/remove a single unit at a time as well as make complete rebuilds. I think I got it to update correctly, but we will not know for sure until units have demands and we play real games with this. Just to be safe I added an assert check for the cache at the end of doTurn(). This check might be disabled in the future as it is a bit slow, but for now it catches cache bugs if they are present.

    It turns out that the design to split the cache into two caches for buildings and units was a good choice. Now it can clear and rebuild the building cache without touching the unit cache and vice versa. Adding the two caches when using them is not a major slowdown, specially not when considering how much easier it is to manage the cache this way :)

    While this feature still needs some polishing I say it's playable. It can read yield demands from XML, display them in the city screen and sell on next turn event. It also looks into the custom house settings to honor threshold and "won't sell" settings. By default all thresholds are 0 and it will sell anything. The AI will not change this setting and as such it will sell domestically if possible. It will however not move yields between cities to fill demands as none of the AI code looks at the demands (yet?). We should likely consider if it is wise to make demands for tools, food etc as this might cause unwanted AI sideeffects.
     
  11. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    Awesome :goodjob: Having real Demand getting generated will make production and trading lots more interesting, especially when your higher-grade citizens start wanting to consume a variety of imported yields from the unique Trade Screens as well as the Europe screen.:king:

    I agree it's best to avoid having building/unit demands for those yields that are frequently used in construction or for other reasons; I did this in 2071 (using Androrc's DM modcomp) to let some buildings consume Biopolymers then immediately regretted it. Adding something like the Sentiment/Fealty production bonus to demands sounds good too; however it might be even more suitable to instead add a % bonus to demands for cities with high Prosperity.
     
  12. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I added iMarketCap to buildings and NO_MARKED_SALES_CAP to GlobalDefinesALT.xml.
    A city will now no longer sell more yields than NO_MARKED_SALES_CAP + (iMarketCap for each building present).
    I set NO_MARKED_SALES_CAP to 2 for now. Set it to 20000 or something if you don't like having a cap at all.

    I also noticed that the price setting code (which is bad, I know) can set the price of a yield to 0. I added a check to make sure it will only sell if it actually gains a profit from it. Before this fix it would remove the yield, but since the profit was 0, the later trading code assumed no sale and didn't post a message about the sale. The result was that the yields disappeared without the player getting money or message about it. Now that there is a cap on how much you can sell it would be even worse as the code could sell worthless yields instead of high priced ones. It still can, but at least it will not give anything away for free anymore.

    Yields are sold in the order they are indexed (bottom row left to right). It's perfectly happy using all of the cap to sell for 2 gold/yield and having used up the cap when it reaches 15 gold/yield goods. There is no easy way to avoid this in the code, though the custom house settings can be used to prevent selling low cost yields. A fix for this means a complete redesign as the selling code is only aware of one yield at the time and have to assume no other yields will be sold.

    Using prosperity instead of fealty sounds like a better idea. I made a single line in the code where stuff like this should be added. However I haven't figured out how much it should influence demands or how it should be calculated. I guess we will find out eventually.

    I noticed RaR has +50% demand for each level of market. We could have that as well if we like. Well it would be "this building adds X%". Docks might increase demand as well as marketplaces as it simulates natural local trade that docks brings with it.

    Also I wonder about how to add population to the calculation. I wrote earlier that I want to gain a "big city bonus" to give added motivation to increase city population limit. I haven't figured out that should work though.
     
  13. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    This topic appeared in the Colonization 2071 thread and I decided to move it here instead. As you might have noticed, Colonization 2071 adopted M:C's DLL code and anything affecting one affects the other.

    I have been thinking about using plotgroups and at first I didn't like it as the needed data wouldn't be available when needed and it could end up taking a while recalculating it every time. However I came up with a new idea.

    Each player should have a list of plotgroups. Each item in that list should be a list of its own of pointers to the cities in the plotgroup in question (or maybe it's enough if each city has an int to tell which plotgroup it's in). In CvPlayer::doTurn() it should no longer loop cities, it should loop plotgroups. At the start of each plotgroup it calculates a an array of the combined demands for all cities in the plotgroup. This way each city can access demands in other cities in the same plotgroup without spending ages locating the other cities. Some restructuring would be needed as stuff like prices would be moved to plotgroups instead of individual cities. If we use floats when calculating the combined demands for a plotgroup, then we will be able to sell a yield even in the case where 5 cities each demand 0.2. I have already been considering moving to floats due to rounding and multiple units.

    Plotgroups can also be used for AI traderoutes. The best city can be set for each plotgroup mean a plotgroup on an island will not stop producing say tools because a city on another island is better at producing tools. This way it will view each island (plotgroup) as a selfcontained "civ" when moving yields around to supply its industry.

    Moving food wasn't really my plan. My plan was to set threshold to 50% of growth threshold and export for all cities. If a city produce negative food, it sets feeder service on to make other cities fill it up until it reaches 100. When no cities import, then the others will export, but has nowhere to export, which is the same as not exporting. This clears the way for AI mining colonies with minor food around it and it needs to import say 6 food/turn to feed the population.

    Luxury food is currently moved from cities not producing it to cities producing it. It could be beneficial to select one city in each plotgroup to stockpile it instead of spreading it out like that. Raw materials to luxury food is distributed randomly to cities able to produce luxury food. It could benefit from using the best city code to find the best production facility instead of just using a random one. Even worse it might send sheep to one city and cattle to another. The best city code should be able to prevent that from happening.

    What is left is to figure out how to deal with traderoutes to supply construction of buildings and stuff like that.
     
  14. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    That sounds good and should save processing time and AI confusion as well as tons of hassle for human players. No one wants to play a game that becomes focused on coordinating dozens of local routes for LTL freight forwarding. (oh wait, apparently some people do.) Well to each his own :king:

    For buildings and constructed units that require yields for completion; when construction is underway maybe it could use feeder service to import/stockpile that yield to a threshold of the amount required. For Professions that require a yield, the need or demand for that yield won't become apparent until the AI tries to adopt that Profession and fails. To solve this it could also be reasonable to let the AI draw upon yields from its local Plotgroup to equip a profession. (Maybe it could even do this with Units/Buildings at higher difficulty levels; I'm pretty sure that could increase effectiveness of AI gameplay tremendously). Alternately it could be set to always stockpile those yields in all cities up to the required amount, but that likely seems a bit excessive and suboptimal.

    IIRC one other important "safety valve" to allow blocked building/unit construction to proceed is to pay gold to complete it. I had thought this was possible through gameinfo/CIV4HurryInfo.xml but it looks like that relates to rushing Hammers and immigrants.
     
  15. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    That's the plan. However now I came up with another idea. Each player can set if human players should have this feature as well. If enabled a city will automatically import whatever yield is needed for the current building if the city lacks it. This will reduce micromanagement regarding spreading tools and stone to cities needing them just once. I wonder if that can go bad somehow.

    Oh I forgot about that (even though I use it once in a while). I need to look into how it works and it certainly is possible that the AI could use this.

    The current transport code works based on how much a profession will produce when using the yield in question as input. It will not actually have to have anybody working in that profession and as such that approach avoids the problem you just mentioned. On the other hand it doesn't look at how many are actually working in that profession and it doesn't look at how many slots are available for that profession, at least not yet.

    Sounds like a bad idea to me. I don't like the concept of the AI cheating like this (it's an awesome cheat. You can't interrupt their transports). Likewise it spoils a lot if the human players can do something like that.

    That was actually the plan. I just improved on the plan. Right now the game picks the best suited city, which scales really poorly. Imagine producing 50 ore and the best city only takes 18 as input. That scenario demands spreading the ore to several cities to fully exploit the ore.

    The solution is to look at all cities and locate the best building for processing the yield in question. Then all cities with that building will import the yield. However cities with enough in the warehouse are skipped. This way blacksmith building lv 2 will take everything (assuming there is only one). Once the input buffer there is filled, there will no longer be a building lv 2 in the consideration and all level 1 buildings will start importing. Once the level 2 building has used enough ore to start importing, all level 1 will stop importing and the cycle repeats. If no building exist to take it (all input full or none has even been built), then it will consider the ore to be a final product and sell the surplus to Europe.

    I think that will likely be the best approach. It scales well (or at least a lot better than vanilla) to big empires by allowing production in multiple cities while at the same time try to reduce the number of units used to get the production going as the best buildings have a higher priority when getting raw materials.
     
  16. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    Ok, but I wasn't referring to yields consumed by production professions, but the yields that are required in order to equip a profession (ie <YieldEquipedNums>). Most of the vanilla and M:C map professions are like this, and some require more than one yield simultaneously (probably rare to have lying around in AI cities, which must make some complicated M:C military profs hard for it to equip). Unlike Buildings/Units construction requirements where import feeder can be set as soon as construction is underway; the AI won't be able to plan to transport yields in advance of needing to use them as equipment. Some possible ways to address equipment blockage would be A) be able to use surplus yield from the local Plotgroup when equipping professions, B) be able to spend Gold to "hurry" profession equipment that's missing locally, or C) set the AI to always stockpile the equippable minimum (50 units) of all equipment types in all cities as a contingency in case it needs to equip professions locally.
     
  17. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    I was thinking of solution C. However I don't want to hardcode 50 units because then you can't make a super unit using 100. Alternatively the AI stockpiles 100, but that would be overkill if it only needs to store 20. I came up with this:

    Make a cache in each player with an int for each yield and set it to 0 (YieldArray<int> will do that automatically).
    Loop through all professions. For all allowed professions, if yield requirements is higher than already in the array, then set the value in the array to the required number.

    Once this loop is done, we will have a list of minimum requirements in the AI cities. This is even dynamic and will change as the player gain access to more inventions/founding fathers. It wouldn't be a logical solution to stockpile for uninvented professions.

    The drawback is that this could place 15 horses in all cities. I would like a priority list of cities for this, but I haven't figured out how to do that yet. Maybe sort the cities according to population and assume that big cities are more likely to produce those professions.
     
  18. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    I am currently testing out the new Building/Unit Demand feature to see how it plays and how it works. I have one question though, why is the getYieldDemand in CvCity.h divided by 100 as in its code...

    return (getBuildingYieldDemand(eYield) + getUnitYieldDemand(eYield)) / 100;

    I removed the "100" so I don't have to set the values into the hundreds. I tested things out and all seems to be working well in my first assessment.

    Edit: Ah, I see where you stated that the factors are divided by 100, but I am not sure why.

    I plan on testing out the Economy aspects of the game and make adjustments and improvements. I added a new feature to the Manor building in that in increases the output of the center plot by 2. This value can be modded in the XML under the new Building attribute "iCenterPlotBonus".

    In Medieval terms the Center Plot would be considered the "demesne" or private domain of the Lordship. All other plots around would be considered tenants and the workers are paying rent to the Manor Lord in the form up goods harvested/gathered. The tenants or serfs are required to work on the Manor Lord's private property several hours per week and so we can consider that's how those goods are acquired.

    When we start to add in the new Civics screen we may can modify how the relationship between the Manor Lord and his tenants work as there were several ways this operated in medieval times.
     
  19. orlanth

    orlanth Storm God. Yarr!

    Joined:
    Nov 17, 2001
    Messages:
    1,759
    I will look forward to having a Civics screen available! :king::goodjob: Do you think it'll be possible to bring back the Tech Categories of the original modcomp? It would be cool to have categories such as Religious, Military, and Economic techs for which certain FFs could give a discount to research costs in that field.
     
  20. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    I had to download and install the Inventor mod again to check out how Categories work as its been a while since I have played that mod. I see no reason why they can not be added back and I am not sure how much they function already but the discount to research sounds like a cool idea.

    I have come upon an idea I would like to work on first before I do a Civics screen and that is an overhaul of the Fealty/Bell production system. I want Fealty to be an individual aspect of the game and each unit having its own Fealty attribute. As of now Fealty/Rebel Sentiment is the same as vanilla in that it adds up to be a percentage of the total population and when you add a new unit to a city it automatically lowers the Fealty. I never liked that even in vanilla.

    The new system will give a Fealty attribute to each unit as mentioned. Fealty will then be raised or lowered depending on different factors.

    Factors that can Raise Fealty:
    • A unit who is working at his chosen profession
    • Certain Civics and Techs
    • Having access to "Demanded" goods
    • Prosperity of town
    • Extra Food Fed to population(3 food instead of two)
    • Buildings
    • Symmetry of Other units (Master Vintner/Expert Vintager)
    • Founding Fathers

    Factors that Lower Fealty:
    • A unit that is unemployed
    • A unit that is not working at his chosen profession
    • War (some units will not like war)
    • Certain Civics and Techs
    • Starvation
    • Taxes
    • No Access to preferred buildings(Monks with no Monastery)
    • Corruption

    Benefits of High Fealty:
    • Production Bonuses
    • Combat Bonuses

    Fealty of your Units will range from 100% to -100%. At -100% a unit may even leave your Realm for another Realm. Fealty for starting your Conquests will be an average of all your Units Fealty. Certain units could have a starting bonus to Fealty or penalty.


    Corruption is also an idea I have. It was a huge part of Manorial life in that the further away from the Lord's Manor you were the more corruption that took place (much like the concept in the older Civilization games). Corruption could be added as a new Yield that is countered by Fealty production in your Town Centers. Like Fealty has a positive effect, Corruption has a negative effect and it increases over time if there are no units producing Fealty. Certain Civics/Techs/FFs will also raise or lower Corruption. Criminals in your Realm could automatically add to Corruption impressing a need to get them converted or shipped off to prison:suicide:

    I feel like these two systems will add greatly to the strategic depth of the Mod while working well with the new Civics Screen and not adding too much complexity. Any thoughts?
     

Share This Page