Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2] 3 4

Author Topic: Speeders's Common Sense Economy Mod (in dev)  (Read 25156 times)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #15 on: December 08, 2015, 03:24:30 PM »

There are two important factors in this:

First factor, not only the game don't add or remove production facilities, but also they work non-stop, the way a light factory is implemented in vanilla for example means it will keep making "domestic goods" no matter what, including if there are too much of it (and because the way prices are intended to be stable, they will reach a mininum value and never decrease, thus exports from that planet don't actually increase, resulting in a supply spiral), and also if there are not enough raw materials, a planet with light industry has a demand for metals and volatiles, and will buy it, and decrease it from the stockpile if present, but if noone sell those products to that planet, it will keep making domestic goods like there is no tomorrow, resulting not only in a oversupply spiral of domestic goods, but also a spiral of price for the demanded products, that will get higher and higher (until a sort of hardcoded limit).

To clear up some possible misconceptions:

Prices will go to very low levels (i.e. low single-digits per unit), and this absolutely will increase exports from a market, since other markets try to get stuff at the lowest cost.

The "decay" factor ensures stockpiles don't get too high if there isn't enough overall demand. This can be thought of, in part, as simulating a winding down of production.

Light industry will produce less domestic goods if the demand for volatiles and whatever other ingredients isn't met; see: getProductionMult() method call in the relevant market condition.


Re: "stable prices" - the goal isn't to create prices that hit a specific target, but a simulation that settles on a stable equilibrium point, and then use that as a base for events and such to manipulate. If your underlying simulation doesn't aim for something like that, you might as well just assign prices randomly, because that's what you'd be getting anyway.

If you're thinking of simulating all trade via explicit shipping through in-game fleets, I don't think that's going to work at all. The number of fleets would have to be a few orders of magnitude higher than it is for that to be remotely viable. Otherwise, the sample size is just too small. Conceptually, the fleets you see in the game represent a fraction of the actual traffic.


Note this also has another consequence: the economy allow all business to operate at losses. example: the ore refinery currently uses 5000 ore (default price: 10) to make 2500 metal sheets (default price: 30). suppose that someone is attacking all fleets near the mining places, and cause the trade disruption event to jack ore prices to 50 (I've seen it happen many times). Planets with refinery will happily pay 50*5000 (250000) to produce goods in the value of 2500*30 (75000) resulting in a loss of 175000.

Not quite how it works, because scarcity of ore will also drive up the scarcity/prices of metal and anything else on down the chain of production.

(example: food exporting planets frequently export 1 BILLION units of food, there is NOWHERE in the game enough ships to trade that

Are you sure? If so: this sounds like a bug. The highest food stockpile I can see at the moment ~8 million at Tartessus. Coupled with the "ridiculous amounts of volatiles on Mimir" thing that came up a while back, I'm fairly sure there's a bug somewhere. Hmm. Possibly in the trade disruption/food shortage events, which manipulate some economy values directly. The sim itself doesn't seem to produce these kinds of conditions, which would explain why I hadn't spotted it in testing the sim... noted down, will check it out.
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #16 on: December 08, 2015, 06:15:02 PM »

Quote
Re: "stable prices" - the goal isn't to create prices that hit a specific target, but a simulation that settles on a stable equilibrium point, and then use that as a base for events and such to manipulate. If your underlying simulation doesn't aim for something like that, you might as well just assign prices randomly, because that's what you'd be getting anyway.

I don't think I can agree with that. I've played Railroad Tycoon 3 a while back, and recently got back into it. While it is an entirely different game type, it manages a living economy far better than this game's current implementation.
It has a rather detailed and effective economy which properly manages supply and demand, as well as prices. Most notably, you have to haul goods from low price to high price, which the simulation handles very well. The prices will fluctuate based on various factors, but will tend to stabilize over time based on production, demand, and stockpiles.

Factories in that game produce resources, process them, or consume them. The ones that process resources don't work without the raw materials, and that doesn't hurt the game at all.

Raw materials have the lowest base price, and each level of processing increases that, generally by 100 units of cash. Generally is 50 res, 150 res, 250res, for each tier, as an approximation.

Supply locations drop the price slightly, stockpiles drop the price more. Places with demand raise the price significantly. This results in prices that ensure that hauling from supply source to demanding factorio will result in a gross profit in most cases. The only exception is if the destination already has a large stockpile, as that drives the price down.

Starsector doesn't seem to do that. The economy, while it seems kinda functional, really... Doesn't work.

Quote
If you're thinking of simulating all trade via explicit shipping through in-game fleets, I don't think that's going to work at all. The number of fleets would have to be a few orders of magnitude higher than it is for that to be remotely viable. Otherwise, the sample size is just too small. Conceptually, the fleets you see in the game represent a fraction of the actual traffic.
Why have that much throughput then? Why not scale production/consumption down massively? Or, why not haul 1 unit of food on a ship, and at the source and destination, buy/sell 100 units? It would be hidden from the player, but it would still have a physical presence in the world. Killing that fleet would destroy a bunch of goods, allowing a blockade or w.e.


Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #17 on: December 08, 2015, 06:17:02 PM »

Thanks for the info Alex!

As for the food amount absurd trading amount, testing here does seem to suggest it is tied to events, seemly you even added some manual food shortage events on the game start (maybe to make it easier to starting players), this seemly results sometimes in aberrant behaviour.

I created about 5 games in a row (but sadly don't tough of saving them... because of all the testing was creating lots of files I wiped out all saves) and noticed that stuff sometimes randomly went into "broken" territory (ie: bizarre stocks of something, or some good disappearing from the economy completely), but most often stuff just worked as intended...

Since the sim is rather laser guided into stableness, I guess your theory is right (events are breaking stuff).

Also I noticed goods popular with events are the ones that break more often (food, organics), while goods that sometimes you take some hours of play to see for the first time, are rather stable in behaviour (rare metal sheets/ingots for example).

Also good to know unmet demand does result in a production loss, I was going to create some workaround for that, this means less work to me =D (also more code to hunt down and find what it do).

EDIT: (I posted while Ranakastrasz was also posting, I saw his post AFTER making my post).

There is a great reason why Starsector don't try to literally move all goods: performance, specially with the current way it calculate trades (that often result in circular trade routes, with planet A and B buying from each other the same good repeteadly, you can see this in-game when you check the market information and see some goods having the top export and top import locations being the same market) it would need to generate a high number of fleets (not of ships) even with goods taking little space, this would make AI calculations kill your CPU.

Still, I played many games with extensive trading, and it can be done, but the economy would need a complete overhaul for this to work.
« Last Edit: December 08, 2015, 06:21:41 PM by speeder »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #18 on: December 08, 2015, 06:48:22 PM »

Quote
Re: "stable prices" - the goal isn't to create prices that hit a specific target, but a simulation that settles on a stable equilibrium point, and then use that as a base for events and such to manipulate. If your underlying simulation doesn't aim for something like that, you might as well just assign prices randomly, because that's what you'd be getting anyway.

I don't think I can agree with that. I've played Railroad Tycoon 3 a while back, and recently got back into it. While it is an entirely different game type, it manages a living economy far better than this game's current implementation.
It has a rather detailed and effective economy which properly manages supply and demand, as well as prices. Most notably, you have to haul goods from low price to high price, which the simulation handles very well. The prices will fluctuate based on various factors, but will tend to stabilize over time based on production, demand, and stockpiles.

Factories in that game produce resources, process them, or consume them. The ones that process resources don't work without the raw materials, and that doesn't hurt the game at all.

Raw materials have the lowest base price, and each level of processing increases that, generally by 100 units of cash. Generally is 50 res, 150 res, 250res, for each tier, as an approximation.

Supply locations drop the price slightly, stockpiles drop the price more. Places with demand raise the price significantly. This results in prices that ensure that hauling from supply source to demanding factorio will result in a gross profit in most cases. The only exception is if the destination already has a large stockpile, as that drives the price down.

Starsector doesn't seem to do that. The economy, while it seems kinda functional, really... Doesn't work.

I feel like we're maybe talking past each other a bit here; at least, I don't see how what you're describing runs counter to having a system that stabilizes at an equilibrium point. From my perspective, that's just about a requirement to get the kind of stuff you're talking about to work reliably.

On the implementation side of things, I think the issue with Starsector's economy is that it *doesn't stabilize fast enough or well enough*. If it did (and I'll definitely be looking at that), it'd be easier to create just these kinds of opportunities by adjusting market connection weights etc.



Quote
If you're thinking of simulating all trade via explicit shipping through in-game fleets, I don't think that's going to work at all. The number of fleets would have to be a few orders of magnitude higher than it is for that to be remotely viable. Otherwise, the sample size is just too small. Conceptually, the fleets you see in the game represent a fraction of the actual traffic.
Why have that much throughput then? Why not scale production/consumption down massively? Or, why not haul 1 unit of food on a ship, and at the source and destination, buy/sell 100 units? It would be hidden from the player, but it would still have a physical presence in the world. Killing that fleet would destroy a bunch of goods, allowing a blockade or w.e.

It's not a throughput issue, it's a sample size issue. How many trade fleets go from market A to market B during any given month? We've got, what, 30ish markets now, right? Let's say roughly 1000 connections, then. I really doubt most of these get more than one fleet per month at best.

If we're depending on these fleets to *actually drive the economy*, that's incredibly subject to luck. Say one of those fleets gets intercepted by an enemy in another system, far beyond where the player can see. Whether that one fleet makes it or not may as well be completely random. If we're then basing prices on the success of these super random successes and failures, well, I think you can see where this is going.

To have a sample size where "did a significant portion of the shipping from market A to market B get killed off" did not vary essentially randomly, we're, I believe, talking about having several orders of magnitude more trade fleets *and* other fleets that attack them. Well beyond what's feasible, and going up exponentially with more markets to boot.


Also I noticed goods popular with events are the ones that break more often (food, organics), while goods that sometimes you take some hours of play to see for the first time, are rather stable in behaviour (rare metal sheets/ingots for example).

Thanks for the additional confirmation!



Still, I played many games with extensive trading, and it can be done, but the economy would need a complete overhaul for this to work.

Overhaul may be too strong a word; I'd settle for a simulation that stabilizes more quickly :) The current method does it by simulating trades, but the number of trades it can do is limited by performance concerns, so the sizes of the trades are necessarily fairly large, and it overshoots/oscillates a bit, which is why you sometimes see import/export cycles of the same good between a pair of markets.


(Appreciate the discussion here, btw. Good to talk this through and helps crystallize some ideas.)
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #19 on: December 08, 2015, 06:51:04 PM »

Light industry will produce less domestic goods if the demand for volatiles and whatever other ingredients isn't met; see: getProductionMult() method call in the relevant market condition.

I did saw that before, but I noticed it is only used to add a flat modify number to supply.

I assumed that unless you change the supply mods for whatever reason, they will stay the same, and the engine will always use the supply value to make supply.

Since you said that this DOES react to lack of raw materials, I must ask: Do you constant un-apply and reapply market conditions?

Or there is something else I am missing?
Logged

Clockwork Owl

  • Admiral
  • *****
  • Posts: 790
    • View Profile
    • Starsector South Korean Community
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #20 on: December 08, 2015, 06:56:36 PM »

Simulate based on enemy activity near the route I guess. Trade fleets getting intercepted should have *some* effect, not drastic, but noticable.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #21 on: December 08, 2015, 06:59:33 PM »

Since you said that this DOES react to lack of raw materials, I must ask: Do you constant un-apply and reapply market conditions?

Market conditions get reapplied (i.e. unapplied and then applied again) before processing supply/demand and at other appropriate times. It's not what I'd call "constantly", but each market has them reapplied something like twice every 30 days, depending on when the economy sim steps through that market.
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #22 on: December 08, 2015, 07:03:12 PM »

Since you said that this DOES react to lack of raw materials, I must ask: Do you constant un-apply and reapply market conditions?

Market conditions get reapplied (i.e. unapplied and then applied again) before processing supply/demand and at other appropriate times. It's not what I'd call "constantly", but each market has them reapplied something like twice every 30 days, depending on when the economy sim steps through that market.

This applies to all conditions, or only some of them?

If only some of them, how a modder go to make his conditions get updated, or not updated?
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #23 on: December 08, 2015, 07:03:38 PM »

I didn't really say it NEEDS to move all the goods, but it is fully possible to do, without adding 10x as many trade fleets.

If you are going to simulate the economy, I doubt you really NEED to have planets producing a hundred thousand volitiles. Why not go with 5-10k instead? Railroad tycoon essentially produces 2 units (although units are in fractions, presumably 1% units) as it's baseline per factory per year. In this game, 2 is clearly too little, but a baseline of 5k units per month cycle would probably be manageable.

Trade fleets are quite capable of having 5+ atlas, which is 10k cargo capacity by itself.
I haven't really counted trade fleets, but you said they get maybe one per month. You might lose a month of production, but unless pirate activity is huge, then you will lose out on one month of trade on occasion. As long as you set the stockpile threshhold to something like 3 months or so, only repeated interceptions would be able to starve a location.

I see why the trade fleets might have issues due to limits on which locations each one, meaning that some might starve. I suppose I see how that works. It still causes problems however. But, I've seen major trade fleets, and many more small trade fleets, smugglers, and otherwise. Planets seem to get a trader in at least once a week, although more remote ones might have delays like a month, and that kind of delay will occur for major trade fleets.

I suppose you could suppress the teleportation based on the fraction of trade fleets going to/from a specific plant in the last month. If you lose 10% of the cargo capacity of all the ships lost last month, reduce trade volume by 10%. or something. Or you might already do that, I'm not sure. As long as killing trading ships that serve a planet will damage the planet proportionally.

----
Pricing wise

Food has a base price of 30 credits. Drop the price by 5%(diminishing) per 100 units in stock. At 2k, it would drop to ~35%, or ~10 credits. For each 100 demand, increase the price by 5%(linear). If the planet needs 1k food per month, set the price to 60 (for shortages. If you had 1k food already that would cancel it out for price of 30, and if you have 10k, then it would be drowned, cutting the price). Or use another number set, or a different equation, since those examples were rubbish. It needs to be less of a change for larger value differences. Probably need to scale based on economy size somehow. Regardless, a price adjustment based on supply vs demand would be very beneficial, instead of... Whatever it is that you are using. Clearly it isn't supply-vs demand at this time. Ore frequently costs more at neutral or forges than they do at ore mines...
That should only happen if the ore mines are failing due to lack of heavy machinery (which would, ideally, only cut production in half or something, driving the price up) and the forge world has enough ore to last for 3 months or more. In that case, they forge world's demand would be countered by the large stockpile, and so the price would drop to normal or lower.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #24 on: December 08, 2015, 07:23:07 PM »

Alex, I just found this line:

Code
protected float minCargoUpdateInterval = 30; // campaign days

Can you make that a setting, or not do that please :) No wonder I am seeing some bizarre results regarding market cargo with my mod on, and why tweaking some settings that should affect the market made no effect.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #25 on: December 08, 2015, 08:23:56 PM »

@Ranakastrasz:
It does use supply and demand, and it does a good job of it in terms of producing results that make sense *if you can see the whole picture*. It needs to produce results that make sense given what the player can see, though, so that's quite a bit different. Any discrepancies you see are likely to either be the results of trade disruptions, or the results of something happening that's just not obvious. Which is, of course, a problem.

Intercepting trade fleets already does do damage to the planet's economy. All I'm saying is trying to entirely drive the economy using trade fleets wouldn't work.


This applies to all conditions, or only some of them?

All.

Alex, I just found this line:

Code
protected float minCargoUpdateInterval = 30; // campaign days

Can you make that a setting, or not do that please :) No wonder I am seeing some bizarre results regarding market cargo with my mod on, and why tweaking some settings that should affect the market made no effect.

You can provide your own market plugin implementation if you want to change how this works. See: data/campaign/submarkets.csv.

Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #26 on: December 08, 2015, 09:01:26 PM »

You can provide your own market plugin implementation if you want to change how this works. See: data/campaign/submarkets.csv.

Whoa, awesome!

I saw this file before, and saw the "id" thing, but didn't noticed the "script" column, after your post I actually checked again, and whoohooo!

By the way, what are also other economic stuff I can easily override? I found out that I can seemly override events and conditions.

Seemly the economy itself is impossible to override (although there is an API to "GET" the economy and a economy API, you can't "SET" the economy... although seemly you can "SET" the whole campaign O.o)

EDIT:

found computeStockpileAvailableForSale function on BaseSubmarketPlugin.

That function is ever called?
« Last Edit: December 08, 2015, 09:05:46 PM by speeder »
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #27 on: December 09, 2015, 07:07:33 PM »

Features so far:

Tariff calculator based on much stuff (details on first page already)
Open Submarket has custom commodity updater, every time you open it, it grabs some commodities from the hidden stockpile and put it for sale (or if there is too much, it puts back on the hidden stockpile).

The amount for sale formula is based on a hand-designed formula (that took me 7 hours to do!), the result is that "low" hidden stocks, like 500 of something, will result in 50 units available (or something like that), while obscenely high amounts (1 million for example) will result in 80.000 (or something like that) to be available.

Markets with more population have slighly more stuff, and a higher "limit" of goods on display (ie: a 10 population market will show at most 200.000 items at once).

You CAN wipe out the hidden stock, if you keep opening and closign the screen and buying stuff, you can keep buying until the market runs out of hidden stock, just keep in mind that doing so will make the prices rise sharply (and experiment I made trying to wipe out Heavy Machinery stocks in Jangala resulted in me paying for the last item about 600, on average I paid about 450)


Now another feature:

Markets not only react to conditions to produce stuff (this was already made on Alex side, for most part, sometimes it is not fully implemented, but a market lowers production if it has less crew than needed and less raw materials than needed), but react to profits (and losses).

Now a business (example: the single Shipbreakers yard that exists on Vanilla on that independent planet I forgot the name) now calculates how much it will profit using the game engine own calculation system of purchase and sale values, then the more it profits, the more it will attempt to produce (requiring more raw materials and more crew, thus it won't work if there aren't enough stuff to make it work).

It is a log10 function though (ie: the amount of production done has diminishing returns)

This calculation can also handle losses, if the profits are losses instead, the business will reduce its production, up to a mininum (to avoid breaking stuff).


I hope this feature will help Nexerelin and faction mods to be balanced easier (since now the economy will produce more, or stop producing, based on if it makes sense or not, instead of having runaway supply or runaway demand).
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #28 on: December 09, 2015, 07:25:44 PM »

But does it blend? But when will we get to try out this highly experimental and presumably save-game-corrupting mod?
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Speeders's Common Sense Economy Mod (in dev)
« Reply #29 on: December 09, 2015, 08:27:29 PM »

Probably after I finish making the supply and demand values work on vanilla

Currently the whole chain of production is somewhat broken

What I am doing is fixing raw materials business, and then fixing the next ones, and so on.

This mean the business I want to actually fix, will be the last (because they use almost all other commodities) that are the AutoFactory and the Fuel Factory.

I fixed so far the shipbreaker yard, and the ore mines.

The ore mines in particular tend to make a healthy amount of stock (around 150% of their internal demand, sometimes it reaches 600%, but is rare), some profit (a ore mine profit about 5000 per day) and charge decent prices (usually, ignoring tariff, they charge the player from 3 to 7).

Ore refineries that aren't in trouble with pirates and whatnot tend to have their ore demand met (or surpassed even), buying ore at around 12.

I dunno why, but the ore global supply/demand frequently is around 0.8, but yet if I visit lots of planets they all have no stocks problem, I am not sure what is going on there.


Now I need to sleep, tomorrow I want to fix at least the volatiles and organics factories.
Logged
Pages: 1 [2] 3 4