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

Question about resource consumption by buildings

Discussion in 'Civ5 - Creation & Customization' started by irnf, Jan 17, 2021.

  1. irnf

    irnf Chieftain

    Joined:
    May 30, 2020
    Messages:
    11
    It is possible for buildings to require a resource in order to be built, the classic example being the hydro plant.

    However, losing your last aluminum or your only source of aluminum (mine is pillaged, city with mine is lost etc) does not have any negative effect on the hydro plant. So in regular unmodded civ 5, it is possible for buildings to require resources for construction but they never require them for operation or maintenance. This is different than the way units are treated - where losing the strategic resource makes them fight less effectively.

    So my question, as an inexperienced modder, is to what extent would it be possible to impose some kind of penalty on a building that "required" a resource that the player no longer has access to or enough of. In other words I want buildings to respond to resource shortages the same way units do. This could potentially include just nullifying all effects of the building.

    Specialists?

    A particularly big issue that I can imagine is, that even if with scripting you could nullify a building's yields, resource output, or whatever else, I'm sure it would be very hard to remove any specialist slots it has. Specialist slots seem like they would be another big problem.

    Just Destroy the Building During Shortage?

    A simple solution may be to use a script to destroy buildings that require a resource when the number of copies of the resource available fall below the amount required by the empire. The problem with this is that you need to discriminate between all the individual buildings in the empire and destroy only some of them (if you have 4 factories producing Y from X, but only 3 X, the script needs to be able to destroy only 1 factory, and somehow pick which one should be destroyed). A second, more simple problem with just destroying the buildings is that it seems like an unfair and severe way of handling the situation when you can often get a lot of resources back quickly depending on the situation (like repairing an improvement in 2 turns).

    Case Study

    As an example: There's a good mod from steam user Clay Matthew T that makes an "energy" resource which is created from and required by different buildings. But it doesn't do anything about the issue of the game not handling shortages realistically. If you lose the coal necessary for your city's coal plant, the plant still produces energy, buildings that require energy, in turn, continue to function just fine.

    Conclusion

    Solving this issue could lead to some amazing economic mods because you could have buildings with complex input/output relationships and a world economy of traded resources that emergently responds in a realistic way when a random improvement somewhere on the map is pillaged.
     
  2. irnf

    irnf Chieftain

    Joined:
    May 30, 2020
    Messages:
    11
    No one has replied yet but that's fine. I am no programmer and don't plan to do this myself anytime soon. This whole thread is just meant as an intellectual exercise to see what's possible. I have two more thoughts:

    1) Destroying buildings that lack resources could work, I think, if the same script that destroys them keeps track of what was previously in the city and adds them back automatically when more resources are available. It would get really complicated because you would need to keep track of all the resource buildings that have ever existed in every city. But there's a way to make that simpler:

    The script could destroy buildings that lack resources, and for each building thus destroyed, add a new building representing the "closed" version. This is great because it gives the player a visual indicator of what has been closed and will become available again with more resources. Once the resource shortage is fixed, the script could then use these closed buildings as a guide for adding back the "functional" version of the building. I think this would actually help a lot because the script wouldn't need to keep track of every city's building history abstractly - instead all the information it needs will be manifest in which "closed" buildings the city has.

    So, the script mainly just needs to store associations between functional buildings, closed buildings, and resources, and calculate each player's resource counts each turn. It will then run through every city every turn, and for every building that is in excess of the associated resource count, remove it and add the associated closed building to the same city. Simultaneously, the script will check every city for closed buildings, and for each type of closed building check whether the associated resource count is positive, zero, or negative. If positive, remove the closed building and add the associated functional building.
     
  3. irnf

    irnf Chieftain

    Joined:
    May 30, 2020
    Messages:
    11
    2) Another idea I had was that if you want an emergently complex economic mod with sophisticated input/output relationships, you don't actually need to use civ 5's resource system per se. You can just add a dozen new yields to the game and simply represent your new resources as yields. For economic simulation, this is actually even better than using the game's built-in resource system because the yields can come primarily from specialists instead of buildings, immediately opening the door to a lot more realism and emergent complexity.

    Here's how it could work. You have buildings with three specialists each (which I believe is the limit for a single building), representing different industries or factories. Each specialist produces some of your new fancy yields depending on their job, while also subtracting from other new fancy yields. You can use building prerequisite relationships to have "tiers" of these factories so you are not limited to just 3 specialists of each type, and building additional tiers would therefore represent investing into that industry.

    Unfortunately this "yield as resource" system will still run into the same problem of how to make negative/zero of the yield in your "balance" meaningful. Without a way to penalize the player for going into the negative the input/output relationships are not truly stringent. In other words the "resource requirements" or "inputs" of specialists will not actually be meaningful.

    I found another thread where people were talking about the same idea, of representing a resource as a yield: https://forums.civfanatics.com/thre...rce-requiring-buildings.489841/#post-12282455

    Apparently ww2 commander did something like this and it was really complicated. I'm not a coder and don't think I can comprehend his code unfortunately. I would appreciate it if someone more knowledgeable could read what he wrote and write an interpretation here.
     

Share This Page