Spring's "economy", GET/SET MAX_SPEED - Page 3

Spring's "economy", GET/SET MAX_SPEED

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Argh wrote:...

Code: Select all

bool CUnit::UseEnergy(float energy)
{
                if(energy<0){
		AddEnergy(-energy);
		return true;
	}
	gs->Team(team)->energyPull += energy;
	bool canUse=gs->Team(team)->UseEnergy(energy);
	if(canUse)
		energyUseI += energy;
	return canUse;
}
...
Took me a while to realise. That isn't cheating, you are misunderstanding the code. What it means is that if the unit is trying to spend a negative amount of energy, it is actually adding energy. An example: the solar panels, which have a EnergyUse of -20. Trying to use -20 E, is the same as adding 20 E. That misunderstanding probably comes from the fact that you didn't noticed that:

Code: Select all

                if(energy<0){
Is refering to the amount of energy sent to the function CUnit::UseEnergy() and not to the amount of E you have.
AF wrote:How come Argh has 994 metal in the bank despite a huge deficit in his expenditure in both screenshots? He should have gone into stall immediatly as soon as those demons where spawned, he shouldnt even be able to terraform the land to build an archer.
...
He has 994 metal because each demon spends 2500 M and, since there isn't 2500 M available, it isn't spending anything more. If you look at the demons, you will notice that they don't say "-2500 M" anymore. The problem is probably not economic, it is the fact that units will still operate when they can't use up the intended amounts of M/E.
Argh wrote:...
As that last screenshot clearly shows, even when you should have a negative economy, incapable of doing anything- you can still build, at FULL SPEED. There is no slowdown. It doesn't stop. The costs aren't being calculated properly- you can spend on new stuff all you want.
...
Portugal is in regression right now. It is spending more than it is gaining. Acorging to what you are saying and to what AF said, suposedly, Portugal would completely and uterly stall. Meaning that, even though it is still producing enough to suport health care (independently of spending more than that in other areas), that money could not be spent in critical areas of the country like health care...

You can still produce because you are still making resources and, since the demon only spends resources whenever there is 2500 in the bank, and the lord is still creating chunks of 200 and spending smaller chunks than 2500.

Try this, start with 1K res. Now build a SpireRook. It takes around 14 secs with the combined 1K in the bank + the lord's 200 income. Since the SpireRook spends 300 M/E, it's spending is much noticeable, it doesn't needs to wait for 2500 M/E to be in the bank before it spends. Now build Another SpireRook and notice how much longer it is taking because the older SpireRook is actually taking frequent bites at your pool of M/E.

The problem is probably not in the economy, is in the fact that units still operate when they can't drain res. A good start, would be to fix the fact that mobile units can't have succesfully EnergyUse (probably the reason why you are using negative EnergyMake). Then, make the units not be able to operate when they can't suck enough res.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Actually, upon further investigation, demons will spend as soon as they can find 1/2 of it's upkeep in the bank. That is a thing i knew but had forgoten, units can work at half/ratio (like metal makers).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I can see things go visibly slower in XTA or AA if I'm stalling, perhaps its the huge build speed and small build time involved in nanoblobz which mean you're taking less chunks but each chunk is larger.

Thus the fix would mean a demon should take as much energy as it can up to 2500 and only work when the full 2500 is available, rather than working anyway and only taking when half or more of 2500 is available.
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

If you are setting it back to zero every time you query a unit then it is cheating. You are avoiding a pitfall with creative economic numbers, something we call voodoo economics in the states. A tally should be done globally, since resources are tallied globally, and only reset to zero when all of the units have been queried. Argh is right, the only way to avoid a huge rewrite is to go negative numbers. Otherwise you get a soft economy that never truly stalls.

If a check for the status of the economy is done prior to adding in or subtracting resources, this whole problem is avoided to begin with. You don't have the granularity of control as a cumulative check on the economy, but its an improvement over the current system.

Can someone explain again why an energyuse unit gets its use reverse when the economy is in stall? It should be reset to zero use, not a reverse of its use. That is an error in logic.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

mad rat, we already explained that and figured it all out. It isn't being set to zero, its the actual management of the energy use itself to do with how energy use is handled.

And it isn't reversing ti at all, instead if a negative energy usage is found it's turned into a positive energy gain, because thats what it actually is, and if you didn't do the check it'd have the same result but the statistics at the top would be borked, and you'd have stuff like unit A is generating minus minus 20 energy, or usign minus 20, which isn't good.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

AF wrote:...
Thus the fix would mean a demon should take as much energy as it can up to 2500 and only work when the full 2500 is available, rather than working anyway and only taking when half or more of 2500 is available.
How would that work? If it can, it takes 500 out of the intended 2500? Then what? It can still function 100% with sucking only 1/5 of res? Not function at all while spending resource? Function at 1/5 of .. intended speed, and firing rate and turn rates?

That would be extremely hard to implement. Even the fact that, now, units can suck up half would have to be removed for easy implementation of units not functioning when not able to suck up Res.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

Spring adds res (resources) at a different rate / time than it takes it away.

OTA either did one of these two things:
1. Calculate, from res made and res being used, how much to add/take away as necessary:
6 res being made, 8 res being used (Per tick here) -> -2 res -> resource handler (which would deduct 2 res every tick until this changes)

2. Add and take away at the same time in a tick:
6 res being made, 8 res being used (Per tick) -> +6 and -8 -> resource handler (which would add 6 and then take away 8 every tick until these rates change)

For once, the OTA method works better here (I'd go with method 1, is cleaner)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Actually, I think it's going to be easier than that. If fixed expenses are taken away before you can build/cloak/fire, then we will no longer have problems.
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

Argh wrote:Actually, I think it's going to be easier than that. If fixed expenses are taken away before you can build/cloak/fire, then we will no longer have problems.
And move... :)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

That will have to be done through scripting. But yes, if modders want then they can add that feature.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Argh wrote:... If fixed expenses are taken away before you can build/cloak/fire, ...
Cloack should be considered a fixed expense.

And i'm not seeing how that would fix anything but change how the gameplay flows.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

cloak should be in-between. If a unit takes up 20 energy by simply existing that should come before an optional drain such as cloak which gets turned off when there isn't the energy.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Basically, I'm going to make it go like this, switching the priorities:

1. Get E/M per half-SlowUpdate.

2. Subtract all fixed costs.

3. Subtract costs for building. If no E/M is available, then you cannot build.

4. Subtract costs for cloaking.

5. Subtract costs for firing weapons.


So, that should cure it. If I have a Demon and a Lord, then I will never be able to build, cloak or shoot weapons. The value of my economy will stay a steady -4300/sec., and my scripts making use of Activate() to make units quit moving will work.
esteroth12
Posts: 501
Joined: 18 May 2006, 21:19

Post by esteroth12 »

IMO, cloaking is more important than building... do i want to continue building, or lose my spy?
User avatar
Felix the Cat
Posts: 2383
Joined: 15 Jun 2005, 17:30

Post by Felix the Cat »

Argh,

I know you basically told me to GTFO your thread, but since we've moved beyond coding details and into generalities, I feel justified in entering my unwanted opinion on your proposed changes.

I feel like the order of precedence is basically reversed, and that building should come at the front of the list, followed by fixed costs, firing weapons, and finally cloaking. Why? It just makes sense to me. There's really no objective reason to prefer one method over another, IMO, just your vision of how the world should work.

So I'd add in two things.

1) Allow modders to define the order in which resources are spent, perhaps with a new TDF tag like "UseOrder = UNIT_FIXED BUILDING_FIXED CLOAK BUILD FIRE" or something to that effect.

2) (something I've been wanting to suggest for a while but keep forgetting to make a thread about) Add a way for players to prioritize resource expenditures on-the-fly; no complex system is needed, just a simple button that says 'Prioritize' that pushes the unit in question to the front of the queue for doling out resources. Those who have played Hearts of Iron 2 know what I'm talking about.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Felix, imagine a small tiny situation.

You have gigantic uber builder that runs off of energy, you also have a nuclear power plant. The plant generates 200 and the builder consumes 200 by simply existing or it will shut off. To build something the builder consumes an extra 200 making it a total of -400

Construction under your system:

Building comes first so lets take away the 200 building cost, that leaves us with nothing, zilch, natta, kaput. Oh wait, what about the existance cost that the builder always consumes? Without that it'll just shut off, and we've already ran out of energy, and we've already built too! nm We'll just wait till the next cycle, oh here it comes ok 200 energy for building and 200 energy again for, oh no we've ran out again, lets wait untill nxt cycle...................... some time later ......... 200 for building, ooo its finished, ok 200 for consumption, oh there it is finally.

Construction under our system:

Ok Unit existence costs are 200 so lets take those away, now to build, ah we cant build we havent got the resources to keep the builder turned on and build at the same time. Oh well.

As you can see the player hasnt earned double the cost of the building in our system whereas the player has gotten away with not paying the 200 existence costs in your system, and infact there should have been no construction at all if those existence costs couldnt be paid because the units should turn off untill they're available.

As for your prioritization thing, go stick it in the feature request forum. Its very far removed from what we're talking about and would require a lot more code than you think. If you'd read this thread you'd realize that the prioritization would require things be managed in a totally different way with regards to power, and you'd realize that these unit existence costs that are always there are integral parts of gameplay not just random tidbits, and they're much more important. It's like saying I dont care about supplying power to my factory, that can wait untill after its started building stuff, well duh it needs power to build stuff to begin with.
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

It may be safe to allow a slight debt equal to the fixed intake rate, just so you don't have false stalls.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Aha... at least AF has gotten why I'm so annoyed about this. The execution order as to what gets taken out first isn't minor, folks- the fixed costs must come first, so that modders can properly game-balance their economies. Everything else after that is arguable. I can see arguments about cloaking, being able to fire weapons, and building things all being equally valid. However, OTA prioritized building first, so I think I will keep things that way.

As for debt... the code should either allow nearly-infinite debt, or should set everything back to zero and do the math again every half-tick. Either way is arguable. Personally, I am in favor of allowing debt to reset to zero. This is cheating, really, but minor cheating- so long as fixed costs remain above income + reserves, players will not have any resources for anything else.

Mods that don't like the idea of fixed costs have it veeeeeery simple: just don't use them! If you just want Energy to be "ammunition" or whatever, then assign no negative EnergyUse/Make to any units, and you're fine. There isn't anything forcing people to make use of this concept, under this plan, whereas under the current code, modders are being forced to use hack-arounds to compensate for the fact that the order of execution is wrong.
Yeha
Posts: 96
Joined: 13 Aug 2004, 19:12

Post by Yeha »

The spring economy doesn't work like a powergrid, it works with a stockpile of resources, this is by design and not a bug. If a unit cant drain its requested amount it won't do so and leave the resource pool untouched and the action will fail. This is true for units with energyuse too, which isn't a true upkeep but instead the unit is expected to have a sideeffect, like making metal which will be shut off in the case of low resources.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

The problem is that if we don't have true upkeep, then a lot of conditions aren't possible. Like, for example, coding things to stop moving if you lack Energy.

Moreover, it removes a valuable game design tool- giving players powerful weapons in exchange for partially or totally crippling their economy. And it doesn't give anything back in return- it's not like there are positives to the way it's coded. Right now, it's cheating players who are running at the edge of their resources but staying positive, and rewarding those who are overspending on fixed-expense items, because if those costs are a large enough amount, then they're almost never getting applied :P

For example, Targeting Centers used to be major costs, in OTA. This came along with a very large benefit, so it was worth it. But if your opponent blew up enough of your Energy production, you needed to shut it down asap to avoid stalling your entire economy.

In NanoBlobs, the Demon was originally intended to be a gamble. Summoning one would cripple a player's economy, but they would have a very powerful playing piece on the table. However, it just won't work, because the code is making the drain fail, unless I have >4500 M/E income/bank.

That's like going to a fancy restaurant, when you can only afford fast food... ordering everything on the menu, including all of the fine wines... then saying to the waiter, "oops, I don't have any money"... and having the restaurant be OK with that :P It doesn't work that way IRL, and it shouldn't work that way in Spring, either.

In short... doing it that way was a mistake. If available E/M can't get set to 0 or lower, then it's impossible to make use of gambling play, or force players to be serious about managing their economy while they are blowing things up.
Post Reply

Return to “Engine”