My Random Ideas

Your exampole is a little flawed, in that you are thinking about the scales in reverse, MASSIVE Power Source, tiny bicycle (building).

In FTTW there would be a maximum capacity for electricity, long before you reach a maximum capacity of the buildings to use the electricity.

Also, if you turned off 1 factory over another, the owner of that factory is not going to be happy as he loses money, the employees are not going to be happy because they are not getting paid and therefore cannot eat.

Simply turning off a building doesn't make the underlying problems disappear.

The final goal would be like the standard 'specialisation' concept of bts, where you don't have the time to build everything everywhere, so you need to prioritise, labs or factories, farms or mines, etc.

Obviously in an ideal world we would have perfect customised systems for every idea, but like you said, who is going to code it.

The system I proposed makes use of mechanics we already have to simulate the concept of very limited supplies, and the need to 'manage' your expansion and usage carefully.

All that the current system needs is something to help the AI not kill itself because it is working from the assumption that all bonus resources are good.

We were able to save the pop. usage system with a few lines of code.

What I am thinking now is can we implement an AI 'safe guard' for this concept, again with only a few lines.

Something that tells it to check the bonus a building makes before or after it builds something, if that bonus has a bNegative = True, check it's Negative Fix list and prioritise acquiring those resources unitl it reaches a 0 or positive balance.

So that it doesn't just keep building negative bonuses constantly and crashes it's economy.
 
Ok, So I have started implementing a new idea.

Homelessness:

So I have added a new specialist type to replace the current citizen type, Homeless. I also added a new Resident specialist which is now the Citizen.

So now that we will be having lots more specialists and specialist slots (I also just added Cooks) I have decided to (eventually) move most of a buildings effects over to their specialist slots (Though I will still make full use of the unique building tags as well) so basically a building is only going to be highly effective when you have people employed in them, along with having bonus resources for them.

Now if you fail to have enough Job oppurtunities for all your little people, you will get Homeless people and they will make your town sick and unhappy! Uh oH!!

(Making use of the 'Avoid Growth' Button may become a very important tactic in the future so that your citizens are not overrun by a Homeless Apocalypse! CHAAAAAAANGE!!
 
Looking at the code, the correct place to make the AI figure out which building to build would be
PHP:
int CvCityAI::AI_buildingValueThreshold(BuildingTypes eBuilding, int iFocusFlags, int iThreshold)
Here it calculates a value for a building. Returning 0 will ensure that the building will not be build and if more than one building returns higher than 0, the one with the highest value will be build.

This mean it should return 0 if electricity consumption is higher than 0 and that new+current electricity consumption is higher than the current electricity production. That should prevent the AI from being extremely stupid regarding electricity management.

Next is electricity production. The value should be modified to encourage producing enough powerplants to have surplus electricity to allow building electricity consumers.

Looking at CvBuildingInfo, I can't locate where electricity should be. It tells if the building supplies power, but that's a civ concept of powerplants, which is either the city is powered or not. Free bonuses is not good either because it stores bonus type and number. You can't have more than one bonus for a single building :(

If we should allow more than one type of bonus to be supplied by a single building, the best approach would be to use an InfoArray. I plan on adding it to the code, but I'm not done making it portable and it still contains M:C specific code, which will not compile in any BTS mod.

If we stick to a single bonus per building approach, then the code, which is interesting is this: (still from CvCityAI::AI_buildingValueThreshold)
PHP:
if (kBuilding.getFreeBonus() != NO_BONUS)
{
	iValue += (kOwner.AI_bonusVal((BonusTypes)(kBuilding.getFreeBonus()), 1) *
        	         ((kOwner.getNumTradeableBonuses((BonusTypes)(kBuilding.getFreeBonus())) == 0) ? 2 : 1) *
        	         (iNumCities + kBuilding.getNumFreeBonuses()));
}
The problem with this approach is that it asks the player for the value of the bonus. From what I can read from your idea, it should be based on each city. That makes me wonder if electricity should be bonus or yield. Bonuses are designed to be shared between cities (plotgroups and such) while yields are like food and production and sticks to a single city.

Now if you fail to have enough Job oppurtunities for all your little people, you will get Homeless people and they will make your town sick and unhappy! Uh oH!!

(Making use of the 'Avoid Growth' Button may become a very important tactic in the future so that your citizens are not overrun by a Homeless Apocalypse! CHAAAAAAANGE!!
In that case you better teach the AI that bigger is not always better and that avoid growth is an important setting once in a while.
 
The concepts you put forward seem like they will do the job nicely.

With the first one we would need some way to have generic code/math rather than inputting a specific bonus.

So some code snippet that looks if a building produces a bonus, then look at that bonus to see if it is negative, if yes then look at the bonustypefix tag and fixweight for that bonus, then count the number of bonuses of the fix tag, then negativefix - negativebonus = or greater than 0 proceed with the build.

That could be done right? It would be a 'relatively' small addition wouldn't it?



With the second part, I think that will be fine too, I do not envisage having a building produce 2 kinds of bonus.

IF I do hit that though, I can just 'cheat' and make an 'expansion' building that has the 'other half' of the building as a prereq.

Then we can sneak around the 1 produced bonus type limit. (It also adds to the feel of the wasteland, where you have to both build and 'furnish' a large building or site. "Yeah it is meant to be like that it's... :shifty: immersive...")

The sharing between cities is not a problem either, because bonus resources are only shared when they are connected by a route, so we can assume in the case of Electricity, that Routes come with power lines, and in the case of water pipelines, etc. (That is why trails are SO expensive... "Yeah it is meant to be like that it's... :shifty: immersive...")

So in essence when you connect a city it becomes part of your national grid, and all demands and production become shared across it.

So connecting your empire has both the positive and negative of sharing the load amongst all, with all of the problems and benefits that brings!



With the Avoid Growth situation, I wonder if there is anywhere in the code that stores the total number of specialist slots that are currently available in a city.

Or actually thinking about it all it needs to be is if SPECIALIST_CITIZEN count is greater than (let's say) 2 activate avoid growth button.

Then hopefully the existing AI will always put 'homeless' citizens into any other available slot because they are all better than the homeless output. So it will automatically reduce the number of homeless below 2 if it can and so will then continue growing. (or perhaps it needs to be homeless pop divided by total pop equals greater or equal to whatever number. As a larger city might be able to support more homeless and maybe gain higher tier units by letting itself grow 'a little' out of control..)

That again should be a fairly easy fix right? It just would need a few lines in the right place..

It could even be made a bit better by adding a second snippet that says if homeless is greater than 2 build a unit, that way it will reduce the population and increase it's military power.

Perhaps it would be something like adding an extra bit of math to the existing unit building AI code that was added, that increases the desire to build a unit instead of a building or process, so that the computer won't auto bankrupt itself by bypassing code that checks if it can afford to support any new units.
 
With the second part, I think that will be fine too, I do not envisage having a building produce 2 kinds of bonus.

IF I do hit that though, I can just 'cheat' and make an 'expansion' building that has the 'other half' of the building as a prereq.
Not a bad idea. However I wonder about getFreeBuildingClass. It's part of building info, meaning at least in theory, you can build one building, which then adds another and each of those adds a bonus resource. Either way lets stick to one bonus for each building.

The sharing between cities is not a problem either, because bonus resources are only shared when they are connected by a route, so we can assume in the case of Electricity, that Routes come with power lines, and in the case of water pipelines, etc. (That is why trails are SO expensive... "Yeah it is meant to be like that it's... :shifty: immersive...")
I think I have come up with something better. Say we expand the bonus enum by adding NUM_CITY_BONUS_RESOURCES. Any bonus written before this line will stay in the city and not be shared in a plotgroup. Anything after this line will be shared.

This gives the DLL quick access to tell if a bonus should be shared as well as a hardcoded ID, which allows special code for each. On top of producing a faster DLL than when it relies on XML data, it will produce easier to read code, which is also faster and easier to write.

One really neat thing about this approach is that this is a DLL hardcoding/XML friendly hybrid.
This is because the hardcoding is "open ended". For XML, it means that the hardcoded bonuses should appear in the same order as in the DLL, like with other hardcoded XML files. However since the length of the XML isn't hardcoded, more bonuses can be added without changing the DLL. They will just use the current code, which relies only on XML data. In other words, since the DLL will not have anything after NUM_CITY_BONUS_RESOURCES, any bonus spread by plotgroups will be 100% XML based just like they are now.

I think this would be the best approach. It reuses as much code as possible, meaning it should be fairly quick to set up a system like this. It's easy to add special city based resources like thirst and electricity and it leaves the current bonus system intact.

Maybe the system can later be expanded by making a unit, which can set up a link between cities, which then transfers a single bonus from one city to the other. Naturally I'm thinking of water caravans, but by simply setting up the code to handle bonuses, that feature can be used for transporting other bonuses later without changing the DLL.
 
to be honest, I like the idea of the bonuses sharing, like i said it gives you the effect of a potential national grid, where you could have a nuclear power station in one town providing electricity to several smaller towns.

This means we can also introduce wonders like the Hoover Dam which would give lots of power and can be attached to several towns.

Until it gets to the point of actually having a full on 'caravan' system of some sort, the routes are what represent caravans.

So provided you have a full route you have uninterupted caravans of water (or whatever else).

If you pillage someones route, that knocks out the caravans as well as it is no longer safe to take that journey.

I prefer this system, as it allows the player to connect their fledgling towns together and move from isolated townships to an intergrated nation (Like the NCR).

The important bit is having something that allows the AI to not destroy itself by accident.
 
to be honest, I like the idea of the bonuses sharing, like i said it gives you the effect of a potential national grid, where you could have a nuclear power station in one town providing electricity to several smaller towns.
Me too, but I can't realistically see how the AI can handle something that complex. Say a plotgroup has 12 surplus electricity and the player invents some factory. It checks that there is enough power and since it only use 10, there is and it start building because it's by far the best available building. That goes for all 8 cities. Suddenly electricity consumption increase by 80 and ends up with -68, which appears to be really bad. To overcome this issue, the AI should have some sort of awareness of what other cities are building and prediction regarding electricity consumption and production, which seriously leave the simple to implement concept.

Coding an AI, which can figure out new concepts is actually a rather hard thing to do. Many modders end up implementing features for humans only, but I would prefer to reduce feature complexity to allow the AI to cope with the feature. Reducing the "world" of electricity to a single city appears to be the simplification needed to allow the AI to catch up and play by the same rules as the human players.
 
hmmm... so it cannot see it's bonuses globally...

So with something like the 'choose what to build' code it does it simultaneously rather than 1 city at a time.

As in it doesn't see it has 10 elec. to spend, goes first city, spends it, goes next city, no more to spend build something else..

So it wouldn't see it has spent it until after 1 of the buildings has finished building, by which point it is too late...

I wonder if we could come up with some kind of bit of math or something that would 'slow' the AI building bnegative producers 'en mass'..

Like you say it would need some kind of awareness of what it is already building for the math to be 'reactive' and know that it is building more than one anyway..

That sucks.. I don't know if it is worth bothering with then.. I mean it would limit the player in how many advanced buildings they can build in a city, but it completely removes it from the real 'empire designing' system that I wanted it to be, where one city can support another and so on...

hmmm... wait it can see how many cities are in a plotgroup right?
No that would just make it not build any until it has enough free resource for all of the cities in a plotgroup which is no good either...

Grr.. there must be some kind of equation we could add that makes the AI not smart, just not suicidally stupid...

Something that stops it making like you say a universal build decision, where it splurges and gets one for every city it has all in one go... something like everytime it makes the deicision to build that decision becomes less attractive or something...

But if it makes it's building decisions all in the same thought, simultaneously, then it can't be done, or if it makes the decisions one city at a time, but has no memory of it's other build decisions same problem...
 
Not thinking about the AI for a second, wouldn't this an extremely annoying feature in game for the player, requiring far more micromanagement than necessary. It seems like it would be easier to just not build things that require electricity since there seems to be a malice for doing so, rather than the building simply not being optimal without electricity.
 
The math is fairly simple. Just loop all cities in a plotgroup, get the current production (is the AI using a queue?) and then get info for that building to get the bonus type and number. However the AI would end up in nested loops. This mean the number of buildings to check each turn would be: num cities*num buildings*num cities. (not sure if num buildings would be available buildings or building classes in XML). That would make the game rather slow. In fact it would be so slow that it certainly isn't the way to go.

This mean if electricity should spread in a plotgroup, the AI should get the information without actually collecting the information :crazyeye:
The only way I can think of, which I think could work, would be to add a new bonus array to the plotgroup class. This new array should store the bonuses provided by the buildings currently being build. This number should then be updated when a city changes/finishes production.

However I still think the first few bonuses should be hardcoded. The coding/performance considerations for "city bonuses" still applies to this.
 
@clanky

No because the eventual design would be that you would need these advanced buildings to be able to build the most advanced units, etc.

It wouldn't really be micromanagement, it would be about empire design. Where is your best production, where is your best science, where would it benefit you most to apply your precious and limited resources.

The various quantities etc. would be balanced out appropriately, so that advancing your empire is always better, just not 'thoughtless'.

@Night

hmms... ok.. (sits pondering)
 
Not thinking about the AI for a second, wouldn't this an extremely annoying feature in game for the player, requiring far more micromanagement than necessary. It seems like it would be easier to just not build things that require electricity since there seems to be a malice for doing so, rather than the building simply not being optimal without electricity.
I kind of agree with this. While I like the basic idea behind this, I somewhat suspect that the formula is wrong and it ends up as a good thing to build powerplants in all cities, but only production facilities in specialized production cities. As a result, a few cities (or a single one) will overflow with electricity bonus production because nearly nothing is consumed.

If a powerplant delivers 10 electricity and all factories are fully supplied already, those 10 would mean +300 production to each factory in each city. If you have 11 cities and 10 factories, adding such a powerplant would add +3000 production/turn in total. That is a totally awesome building.

If this were to be somewhat realistic, at turn start, the plotgroup copies the amount of electricity to a counter. During doTurn, cities eat up electricity from the plotgroup and when the plotgroup runs out, stuff happens to the remaining electricity demanding buildings... or more likely, nothing goes on. This could be expanded to handle priority rather than just first served (which would be the order the cities were founded in, with the oldest being first). It's also possible to add that a city will only consume (request*production)/(total request), naturally capped at request. That way if you produce 10 and have 3 cities requiring 10 each, they will get 3, 3 and 4 since they are forced to share.

I'm still not entirely sure it is a good idea to give a penalty for overloading the power grid. The idea sounds nice, but it can easily turn into a micro management hell.

Water on the other hand is consumed by population, possibly like 1 unit/pop each turn. Failure to supply water would upset people, making them angry and causing poor health. That could likely be managed.

I really think this whole thing would need some thinking before any implementation. It has the potential to both be great and ruin the game.
 
Well, avoiding the situation you describe Night is just a matter of balance.

The original example I gave was not a final game example, just a description of concept.

We can limit where powerplants are available by a number of factors, we can make it so that a big power plant means bad things for a city, so building the massive coal or nuclear powerplants everywhere may not be the smart move, and nicer power plants may produce less, so even if every city had one, it would only fully supply a single factory. (Or whatever)

We can use the 'cathedral system' so you have to have say 4 of one building before you can build a mega powerplant (or any kind of powerplant) same for the factories and such so that the AI can't blow itself up too hard.

We can use the prereqvicinitybonus tag, so certain power plants can only be built next to uranium or coal or whatever or by terrain or feature or improvement. We can limit it by culture level so only the most developed cities can have them.

The point is if we can make it so that the AI doesn't just kill itself by blind stupidity, the rest is just tweaking the xml until the balance is just right that it presents the player with a challenge and a question "What do I give priority to?".

As a player you will be able to see what your electric production/consumption is in each city and plotgroup when ever you are in the city screen. So you will always be able to make the decision, is this the best place to make/use electricity.

Same with any other bonus.

Do I use water here in this city to improve the output of my farms, or do I use it over here to produce electricity from a Hydro Fuel Cell Facility?

The only real stumbling block right now is the fact that (possibly) the Ai won't tell the difference between good and bad bonus resources and will over spend wothout any thought to what is happening. If we can just introduce something that will help it not over spend, whether it knows it or not, then it should be able to at least not kill itself.

I know in my gut it can work (if the AI doesn't commit suicide by stupidity) everything after that is just refining the numbers and concepts to as near as perfection as humanly possible.
 
The more I think about it, the more I think your proposal is flawed :(

The main issue is that it relies on the existing bonus code. Say we build a powerplant, which gives +5 electricity. That is +5 in each city in the plotgroup, not 5 in total. Since you want to add a bonus for excess electricity production, then the bonus is multiplied by the number of cities. This isn't something, which can be balanced out with XML as it is a fundamental flaw in the design.

The same goes for water. If you build a well, which adds 2 water, it adds those two in all cities,. Say each unit of water can boost one farm. That would then become two farms for each city.

I suspect this is doomed to fail or maybe not even get coded if this issue isn't solved.
 
Well you are not thinking the whole thing through, because the negative bonus works the same.

So 1 electricity spreads across the whole plotgroup, but so does 1 consumption so balance is achieved.

If you over consume the whole grid suffers. If you over produce the whole grid can flourish.

Generally speaking buildings that will be boosted by electricity bonus, will also produce consumption and be equally negatively effected by consumption, reducing the overall boost that electricity gives.

The abstract multiplication of bonuses across plotgroups is negated and balanced by the fact that both the negative and positive bonuses are abstractly multiplied by the same amount and in the same way, so it cancels itself out.

It is using the number concept in a slightly abstract way, to represent a non infinite amount.

You are right that 1 unnegated electricity can be used equally across as many cities as you have, but for every building you introduce that can benefit from it, it will add consumption and thus reduce the overall effectiveness of electricity across the grid, and many of those cities that have the 'free' electricity won't be able to benefit from it, because they won't have any buildings that use electricity. (There may be a few that do, we shall see as the system progresses)

I originally thought of just adding the positive electricity, but then like you say it would be exponentially increased by the number of cities in a plotgroup and so a powerplant would some how magically provide more power the more cities draw upon it. Which is Impressive!

Adding the balancing negative bonus allows for the system to be finite, add too many electiricity or water consuming buildings than you can produce for, and suddenly your whole grid begins to suffer the effects of blackouts or droughts.
 
Well you are not thinking the whole thing through, because the negative bonus works the same.
I am thinking it though and the fact that both are spread across the plotgroup will not really save the design.

If a factory gain +30 for positive and -20 for negative, it still nets at +10 for each electricity, even if supply and demand is equal. This mean if you have 10 independent cities, each with production = consumption, they will still be greatly boosted by being connected into a plotgroup. It makes no sense that a factory increase production just because it becomes connected to a powerplant, which is already running at 100% capacity. Where is the energy coming from?
 
But if the positive and negative are equal, you will only gain a net benefit
Yeah, but isn't that overpowered as well?

The issue is say we build a powerplant and a factory in each city. It produce and consume 10 electricity. With +10 production each, it ends up as +100/turn. Join 20 cities in a plotgorup and it becomes +2000 in each city without actually producing more power or building more factories.

What should be done to make this somewhat realistic, is what I wrote before. Production and consumption is in the plotgroup. Each city then use those two numbers to figure out consumption vs production and figures out how many electricity units it can pull from the plotgroup.

A factory then has something like:
+10 for each electricity consumed
+0.5 angry people for each (5-consumed) -- (that is for each delivered electricity under 5)

That will give a realistic production bonus and if more than half the electricity is missing, people get angry. I just made up the numbers, but it shows the basic idea. It will not multiply the power production and hence bonuses with the number of cities and the core idea of the need to fulfill requirements is there. However there is a buffer as a strict system would likely be too tricky to manage, not to mention really annoying.

To be honest I'm not sure I like the idea of a bad effect. It would just be paying the upkeep for the factory without getting any production. The workers would still get paid.
 
Back
Top Bottom