Quantitative Resources

Exactly right. The beauty of this system is that everything works the same way ultimately in the code, and the only details left are which ones fall into which categories. For luxuries and food, the stockpile is basically irrelevant, because that will never get called. That is, you'd never define any buildings/units that require Z amount in XML. (You could, however, still check for the presence of those resources--like the grocer does in determining to give a health bonus for various food types, for instance.) The only difference comes in what the player sees. I suppose we could add a graphical tag in XML which dictates if the stockpile supply shows up on the resource screen in-game, so we don't have to sort through 40 counters. The per turn value will always show up.

The only tricky part comes in trade. We have to define the three categories in code because we want QR to be traded in lump sums, while luxuries and food get traded per turn. But once again, the basics are there already with the gold mechanism.

Technically, all the resources would be "quantified" under this system. It just wouldn't seem that way--which is good. Setting the per-turn production to 1 makes them appear as binaries; setting it to Y per-turn mimics the slot system in Genetic Era; doing this and making use of the stockpile counter equals the traditional quantified system.

What remains now is how to get the city issue solved. Personally, I think that the "1 luxury supplies X cities" rule might be the best way to go, but I see the same old problems: if you have more cities than supplies, which ones get it? Dom suggested linking it to location so that the nearest 5 cities get it, for example, and more distant ones don't. I really like this idea, but it has one MAJOR drawback--on huge maps, where you routinely have 16,000+ plots, this would significantly slow down the game, especially in later eras. Even if only 10% of those tiles have resources, that's still 1,600 calculations per turn, which involve not only the resource location, but also those of all the cities. Another issue: what do you do for building-produced luxuries, like Hit Movies? They'd take their city plot as the location, I guess.

Bottom line: I think it might slow down the game too much, but it definitely is the ideal method. Perhaps a quicker route would be to distribute the resources among the most populous, unhealthy or unhappy cities first (probably just as realistic), or short of that, just do it by the city list, which lists them in order of date founded.
 
When you have more cities than resources, allocating the limited resources becomes the challenge. I agree that doing it by location might get messy, and hard to code.

Here's how I would do it:

  • Let's say you have 4 happiness resources, each providing 5 happiness each. That's a total of 20 happiness.
  • Now, let's say you have 3 cities. One of those has 13 people, another has 11, and the smallest has 7. That's 31 people to make happy.
  • 31 - 20 is a deficit of 11. That's 11 people who will go without luxuries.
  • The deficit will be split evenly between the three cities. 11 / 3 = 3 remainder 2.
  • Here's the result:
    • Largest city with 13 people gets 10 luxuries.
    • Second largest with 11 people gets 8 luxuries.
    • Third largest with 7 gets 4 luxuries.
  • That's still 22 luxuries divided among three cities. We only have 20! That's why we compute the remainder. The bottom remainder = 2 cities will get one less luxury.
    • Largest city with 13 people gets 10 luxuries.
    • Second largest with 11 people gets 7 luxuries.
    • Third largest with 7 gets 3 luxuries.

In code form:

Code:
(Total Defecit) = (Total Population) - (Number of Luxuries)
(City Defecit) = (Total Defecit) / (Number of Cities) 
(Number of Losers) = Remainder of ((Total Defecit) / (Number of Cities))

for each city
  Luxuries of this city = Population of this city - (City Defecit)

for X smallest cities, where X = (Number of Loser Cities)
  Luxuries of this city --

To summarize: divide the deficit between the cities evenly. And if you can't do it evenly, do it as evenly as possible, with the smallest cities getting the short end of the stick.

The reason why you do it this way is because it would be stupid and annoying to have some cities being totally content, while other cities are running a 4 or 5 luxury deficit. Moreover, if you divide the deficit as evenly as possible, it's easier for the player to fix. If all your cities are just one luxury away from contentment, you just need to grab Notre Dame. You just need to run Hereditary Rule with one garrisoned unit in each city. You just need to adopt a state religion to get that one last happiness.

It's better to have it that way then to have 4 cities doing badly, while 5 cities are doing just fine.
 
There’s one thing you said that I particularly liked, so let me quote it for emphasis:

…divide the deficit between the cities evenly. And if you can't do it evenly, do it as evenly as possible, with the smallest cities getting the short end of the stick.

This should be our guiding principle. Outside of any external mitigating factors, and all other things being equal, the resources and their bonuses should be divided among cities as fairly and equally as possible. Within reason, of course.

The “small cities get less priority” rule also appeals to me. Suppose the U.S. suddenly suffered, I don’t know, a silk shortage. In real life, major cities like New York and Los Angeles would get proportionally more, because the market is bigger there. Small cities in places like Wyoming or Montana would get significantly less. In the game, this wouldn’t really be a problem, since smaller cities are less likely to have happiness/health issues. The only time it would be a problem is when you have a major empire and lots of big cities, with few or no resources… but then, that’s kind of the point of this mod, isn’t it? ;)

The Big Problem
There is one major flaw in the argument you presented, however. When we talk about resource benefits being distributed in the game, what we’re really talking about are the resources themselves, not happiness or health. It’s a subtle difference.

Here’s what I mean. Okay, say you have 5 spices but only 3 silk. In the system you described, you’ve lumped all the luxuries into one category, so they get blurred together. There isn’t any advantage to having spices AND silk. 3 spice and 3 silk = 2 spice and 4 silk = 0 spice and 6 silk.

Where does this difference come into play most obviously? In buildings. The market, for example, gives +1 happiness from Fur, Ivory, Silk, and Whale. That is in addition to the +1 happiness from silk already IIRC. (If I’m wrong about this…well, the point still holds, as I’ll show.) We want to preserve this system if at all possible, and I believe it is possible. But there is no way to preserve it using the system you suggested.

To reiterate: when we’re talking about effects being distributed among cities, we’re really talking about the resources themselves. So instead of thinking about how to distribute happiness, we need to concentrate on the resource distribution.

Example:
Suppose we have it so that +1 silk per turn provides happiness to 2 cities, and you’re lucky enough to have +5 silk per turn in your empire (which has 12 cities). Normally, the game would say, “okay, we have silk, so it is present in every city.” That can’t work now.

Now what it needs to do is think, “only 10 cities can be supplied; which two must be left out?” The answer, as you said, would be the 2 smallest cities (or if you prefer, the ones with most unhappiness/unhealthiness). This won’t affect game strategy much because high commerce/high science cities are usually bigger ones.

Taking our example of +5 silk per turn, each supplying 2 cities, in pseudo-code:

Code:
iNumCitiesSupplied = iNetPerTurn * iCityPerResource

if iNumPlayerCities > iNumCitiesSupplied:
	Get iPlayerCityListbyPop # Note: we need a function here that returns an array of the player’s cities, sorted by population, with the highest pop first

	for iLoopCity == 1 to iNumCitiesSupplied
		set iLoopCity.hasresource = True
	end

	for iLoopCity == iNumCitiesSupplied + 1 to iNumPlayerCities
		set iLoopCity.hasresource = False  # Need this to prevent accidental foul-ups with smaller cities still getting the resource
	end

end

Forgive my very bad syntax, but I’m used to a different system than C++ and Python. It’s still taking some getting used to.

Basically, the idea is that when there is a shortage, it loops though all the cities in the player’s empire (arranged by population) and adds the resource to those cities’ resource boxes. The smaller ones, beyond the number of cities supported, don’t get it.

This solves the “market gives +1 happiness” issue, because it doesn’t mess with the happiness itself (which is an abstract issue anyway) but deals in the very concrete terms of whether the city actually has the resource or not. This might be very important later on when we’re dealing with production chains. I still say buildings involved in production need to be able to be turned off, in addition to having multiple production possibilities, but it would be redundant to do this for every building that uses resources, like the market. Plus, the market is only dealing with the presence of a resource, not how many, so that doesn’t affect your stockpiles. But we’re jumping ahead now… ;)
 
Okay, guys, this thread has some extremely useful code in it. It even has part of Duke176's oil counter, which ww2commander mentioned.

I think we've got the theoretical parts ironed out, and we now need to move on to the actual coding.
 
I havn't read through all of this, but I think the best way to do this would be to create new yieldtypes, and make buildings and units require x amounts of them.

In my Interstellar Colonization mod for example, I have created a new yield type and a new commerce type which I call PopCap and Power, they are required by buildings and they basically just have a negative value of that yield or commerce. And if a building would make you go negative in those yields or commerce types, you can't build it.

For example, a factory might require 2 power and you are producing 3 power per turn (I reset this value every turn, but it can accumulate if its a commerce type), so if you build it, you will end up producing 1 power per turn.
 
Interesting idea, but what happens if your resource gets pillaged?

For example, suppose you have an oil resource that makes 5 oil per turn, and a refinery which takes 1 oil to make 4 petroleum. If your oil well gets bombed, what happens to the refinery? What happens to the petroleum being produced?
 
You would have to code in a shutdown mode for buildings that work that way. The simplest way is to remove the building from the city temporarily. Or code it in a smarter way so that it just doesn't work without it's oil.
 
Okay, that makes sense, but here's another scenario: ;)

Suppose you have two oil supplies, each making +5 oil per turn; you also have 10 refineries, each consuming 1 oil. One of your oil wells suddenly gets bombed. Now only half of your refineries will function (once the stockpile gets depleted to zero), but which half?

This gets even more complex when you have multiple building types assigned to use one resource, e.g. a factory that requires coal to make steel, as well as a coal plant that generates power. How do you tell it which production to kill automatically?

This is why I think we also need a "kill switch" on certain buildings, which enables you to temporarily shut off production. Then the user can select which ones to turn off.
 
An issue with the system is that a yield type would only be available in the city that is working the tile, while the commerce types would be available to the entire empire.

A yield can be converted to a commerce, like the Yield Commerce is converted to research, gold and culture. Or the way hammers can be converted to the same commerce types.

The problems with the system are like the one you are giving an example of. But how does the game handle negative gold? Your units eventually go to strike, and some gets disbanded, randomly it seems.
 
Well, we certainly wouldn't want the game to go about randomly disbanding factories, particularly if they can be set to more than one production. :mischief:

If we had a kill switch for buildings, what I envision is that in the event of a resource shortage, the game halts production on certain buildings until the net flow of that resource goes back up to zero. The kill switch comes in because the user might want to deactivate different buildings, so he can go back in and change things around in the city screen, then check the resources screen to make sure the net flow is not negative.

For example, if he's in the middle of a war he might not care about steel production--let's assume he already has a big supply--so that coal going toward steel production in a factory can be put to other uses. If there's a deficit, and the game automatically kills his coal plant instead, he could go back in and turn the factory off and the coal plant back on, and the end result is that there is no deficit.
 
That's a really good point, Gaius, about the various luxury bonuses from markets. I hadn't thought of that. Without that, all luxuries are equal. With that, though, some resources count "double".

My goal wasn't so much to divide the resources equally (if that were the case, then a small city and equal city would both get the same resources). My goal was to divide the *deficit* evenly, so that all cities would be "equally" unhappy. If cities are equally unhappy, then it's easier to resolve your happiness issues.

That suggests to me that we look at dividing the happiness deficit evenly, not the raw luxury deficit. That is, some luxuries are "doubled" by markets and such. Even if one city gets only 3 resources and another city gets 6, it only matters that both of them are content (or equally discontent). I'm worried this will eat up more processing time, though, trying to figure out which resources would count for double.
 
Yep... I just did a test in the game and it turns out you DO get a double benefit with certain buildings, e.g. the silk-market issue.

The only way I can see to resolve this would be to give the resources to the largest, unhealthiest or unhappiest cities. It might not work out evenly, but I just don't see any viable alternative given the way buildings work. At any rate, I look at this as more of a feature than a problem--the point of quantifying luxuries is, after all, so that one source can't supply every city in the empire, giving you an incentive to get more. However, if it turned out to be too much of a hassle you could always make them like Food: non-quantitative, non-stockpiled.

Oh, I should point out that this also gives you a reason to trade for resources you already have. If you make your own wine, but not enough to keep all your citizens happy, getting more from France would fix everything. :)
 
I thought about that... if you can have fractional health, why not fractional happiness? The only problem is it still doesn't solve the building issue. 3/4 of a silk can't work with a market.
 
Yeah, fractional happiness creates more problems than solutions. Whatever system we have to allocating resources, it makes sense that it should be a feature of the system -- rather than something that requires you to deal with all kinds of micromanagement issues. Efficiency is important too. Ideally, you should be able to do this without looping multiple times through the city list.
 
Hey, sorry to interrupt your discussion, but can I get an ETA for this thing? IT SOUNDS REALLY COOL!!!:goodjob:
 
I havn't read through all of this, but I think the best way to do this would be to create new yieldtypes, and make buildings and units require x amounts of them.

Well, this would work if Oil is really the only resource that seems to be in need of quantification... however, I doubt that will satisfy people. It would satisfy me, but that's just me :) But if one wanted to make all of the resources in the game into yields, this would get to be a bit much I think. We could convert the major strategic resources, but I think it would be very odd to have three yields that are very abstract like Food, Production and Commerce and then numerous very specific yields like Oil, Iron, Copper, Coal, etc.

For example, a factory might require 2 power and you are producing 3 power per turn (I reset this value every turn, but it can accumulate if its a commerce type), so if you build it, you will end up producing 1 power per turn.

It's possible to code the game to store yields nationally.. I've already got a preliminary system for this.
 
Forgive me if this is a really stupid question, but if we end up going with new yieldtypes, I assume we'd just link it to the bonuses, e.g. for the iron resource you'd set <iYieldChange>Z</iYieldChange> for some number Z. This is a really easy way to do it, but how would this affect the trade system? (What I mean is, if you give the AI 1 iron per turn, would this amount to +Z yield per turn?)
 
Forgive me if this is a really stupid question, but if we end up going with new yieldtypes, I assume we'd just link it to the bonuses, e.g. for the iron resource you'd set <iYieldChange>Z</iYieldChange> for some number Z. This is a really easy way to do it, but how would this affect the trade system? (What I mean is, if you give the AI 1 iron per turn, would this amount to +Z yield per turn?)


Yes, basically. However, the best solution is to have yields traded between players like gold already is. I'm going to add this into the game anyway so that Food can be traded between civs early in the game, and I had been planning on an abstract solution to Oil simply called Fuel that would a new yield and tradeable once fossil fuels start to be used.

I mean, using yields would be simple for me since I intend to revamp the yield system anyway... but it too is full of its own problems.
 
It is interesting that you thought of this approach... Jeckel has been trying to do almost the same thing for the Colonization mod, only he is linking it to units. I don't know how far he's gotten with it, though.
 
Back
Top Bottom