Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Station Economies #5474

Merged
merged 17 commits into from
Jan 26, 2023
Merged

Conversation

Web-eWorks
Copy link
Member

...Feature freeze can't catch me if I type fast enough!

In all seriousness, this is a down-to-the-wire PR delayed by a round of sickness and a PC rebuild, but one that may prove to be one of the bigger features of the patch. This PR completely rebalances the economic system of Pioneer, providing a (perhaps too generous) 40-50% profit margin for savvy pilots who can sniff out the perfect pair of systems and stations to trade between - but punishes traders who get too complacent with seriously diminishing returns for running the same route too often.

The headlining feature of this PR is of course the "dynamic" economy for stations - we now have a proper supply-and-demand economic system where each station has its own set of commodities produced and consumed (and associated quantities for each), though the system is not quite as well-rounded as I'd like due to the paucity of good input data - I've shoehorned this all in to the existing three major economic archetypes, when I'd really like to split our commodities between 6-8 economic subtypes with more sane production and consumption rates... something for another PR.

Of note: the economic simulation is not "dynamic" in that prices change over time naturally. The existing behavior of station stocking is preserved in that stations will restock / increase demand back to an "equilibrium" value but once reaching that will remain in steady-state until the player takes an action. This is also a subject for another PR.

A secondary feature is an improved trade calculator tool (still WIP as of this writing) that provides extremely "cheaty" information on exactly which system/station has the best trade prices for a commodity (available for developers via alt-click) as well as providing more reasonable information about a station's economic flow for all commodities, similar to the existing system trade tool.

2023-01-16.01-59-43.mp4

The commodity market (the video shows an outdated version) now displays the station's local import/export disposition of a commodity, and if the player has a trade computer mounted additionally displays the interstellar import/export nature of a commodity.

I've also included a slightly-opinionated change to increase the easy/medium start's amount of available credits - as in-system missions don't pay much more than fuel cost and immediately running to an interstellar mission to make money isn't the greatest new-player introduction. On a meta level, this also balances removing the Sinonatrix from the easy start with a bit of extra cash instead 😄

TESTING REQUIRED

This branch was written hurriedly and not thoroughly tested, so I'd really appreciate everyone reading this PR description downloading a build from the Checks section and testing the economic behavior specifically - you can cheat in money with the Ctrl+I menu (as well as give yourself a better ship for bulk trading) and get setup for trading that way.

I've prepared a short list of scenarios that should be tested (independently) while I'm working on finishing the UI elements:

  • In-system trading (in a single system) for at least 2 weeks game-time
  • Interstellar trading for at least 24 weeks game-time
  • Triggering at least one NewsEventCommodity event
  • Triggering at least one SoldOut event

@Web-eWorks
Copy link
Member Author

image

The price-list widget will remain hidden for developer-only purposes this patch, but I've added an economy sidebar mode to the System Map to allow inspecting station economies (following similar rules as the system-level economy sidebar, including providing extra data with a trade computer).

image

With that, I believe there are no major changes needed for this PR to be accepted into the upcoming release. I'll rebase tomorrow, and would appreciate as many testers as I can possibly get on this short notice!

@impaktor
Copy link
Member

What's the read icon? That market is saturated/depleted?

For future: I can imagine we want the player to start "isolated/trapped" in a system, start interplanetary trading and missions, buy a Trade computer MkI, that only gives in-system info, then buys hyperdrive, then buys Trade Computer Mk II, that gives both in-system and inter-stellar trade info.

@Yyffii
Copy link

Yyffii commented Jan 20, 2023

Out of stock / demand work properly, disallowing you from purchase or sell: note - out of demand has no notification similar to out of stock recommend adding one for that as well
certain commodities (Hydrogen, Radioactive, Rubbish) seem to have floating point stock / demand amounts - not sure if that will cause issues, but is visually messy imo.
fuel / commodity prices are relatively balanced that - for doing local delivery missions or local while not making lots of money you do make some, if you do it efficiently you can stack 5 or 6 deliverys + some commodities and make a decent enough amount to begin your interstellar travels

@impaktor
Copy link
Member

out of demand has no notification similar to out of stock recommend adding one for that as well

I haven't tried this branch yet, but shouldn't "out of demand" simply be reflected in the price? E.g. Radioactives are really out of demand, so have negative price. Only reason I can see for station out right refusing to buy, is out of space for the commodity.

@Bodasey
Copy link

Bodasey commented Jan 20, 2023

The commodity market is broken:

  • Purchase lowers stock and leaves demand unchanged
  • Sale leaves stock unchanged and decreases demand

resulting in low stocks on game load, especially hydrogen may run out.

Buy/Sell has no effect on stock and demand in fuel stations. They also have got low stock.

The money is calculated correctly.

fresh compiled c949363 Version

@Web-eWorks
Copy link
Member Author

The commodity market is broken:

  • Purchase lowers stock and leaves demand unchanged
  • Sale leaves stock unchanged and decreases demand

This is intentional - when you sell a commodity it is not immediately available in the market again, and takes up to a week to circulate through the station's economy. Similarly, buying a commodity does not increase demand, as you're buying from the 'surplus stock' of commodities that are too expensive for the local market.

I'm slightly concerned about your finding of running out of hydrogen, as all stations should start with several thousand tons at the very minimum, and restock over time if you spend a bit of time jumping to other systems.

Buy/Sell has no effect on stock and demand in fuel stations. They also have got low stock.

I'm not sure what you mean here.

What's the read icon? That market is saturated/depleted?

If you mean the 'red' icon, that indicates an unprofitable trade between the docked station and the target station (or in general, a profitable trade if you were to fly a return journey).

certain commodities (Hydrogen, Radioactive, Rubbish) seem to have floating point stock / demand amounts - not sure if that will cause issues, but is visually messy imo.

Good catch, thank you!

I've realized there's one final piece of the puzzle missing - I need to adjust the difference between buy and sell prices for a commodity, as there's an exploit right now for high-value commodities where you can make money by buying commodities from the market and immediately reselling them.

@impaktor
Copy link
Member

This is intentional - when you sell a commodity it is not immediately available in the market again, and takes up to a week to circulate through the station's economy.

I wonder if the player will think this is a bug? Not sure I see why it needs to lag? I've seen other games where price instantly updates up/down for each unit you buy/sell. I'm sure there's something I'm not getting here.

@Web-eWorks
Copy link
Member Author

I wonder if the player will think this is a bug? Not sure I see why it needs to lag? I've seen other games where price instantly updates up/down for each unit you buy/sell. I'm sure there's something I'm not getting here.

The price updates instantly. However, the commodity item itself is not immediately available to re-buy after you've sold it to the market, and vice-versa. This prevents another exploit, where buying most of a station's stock of a commodity massively increases its sell price (by increasing demand) and you can infinitely resell the commodities you just bought for a 1-3% profit.

@Web-eWorks
Copy link
Member Author

Alright, now this should be ready to go. I've added trade price fees so that selling commodities back to the station you bought them at is always a net loss (and increased profits slightly to balance the fees), fixed a major determinism issue that resulted in different stock numbers between game starts, and added a lot more variance to commodity affinity at different stations. In-system trading should be more interesting, but also more difficult as you'll have to trade a number of different commodities rather than the same 2-4 every time.

I also fixed a bug in the station economy comparison tool which resulted in displaying incorrect trade data, so it should now be safe to trust the trade computer!

@Bodasey
Copy link

Bodasey commented Jan 21, 2023

Buy/Sell has no effect on stock and demand in fuel stations. They also have got low stock.

I'm not sure what you mean here.

This one:

Fuelstation

...and here are the same prices shown as in the commodity market, not the half as promised and indeed accounted when trading. Maybe we cannot use the same layout as in the commodity market because these marketplaces now work differently, independent from each other?


adapt texts:


NoDataAvailable

weak, but not urgent to have


Observed behaviour: for hydrogen, High security prison serenity is a major exporter, OPLI Contemplation is not an exporter.

Expected behaviour: OPLI Contemplation with a gas giant nearby where it can be scooped is a major exporter, while a distant space station or a ground station on a rocky planet should be an importer.

Introducing fuel cells as a commodity would be a key for an interesting economy model:

  • Cold worlds demand hydrogen, oxygen and fuel cells to produce energy and the by-product water with high offer rate.
  • Hot worlds use water and fuel cells (and radiation) to produce oxygen and hydrogen in a controlled process.
  • The offer rates of water, hydrogen and oxygen depend on the local availability, e.g. gas giants or ice moons. Keep demand high anyway for that scooped hydrogen can be brought in.
    (Actual real rockets also need liquid oxygen)

...but are fighters interested in the search for cheap fuel or even scooping it?

@Web-eWorks
Copy link
Member Author

Observed behaviour: for hydrogen, High security prison serenity is a major exporter, OPLI Contemplation is not an exporter.

This is well beyond out of scope for this PR. I will not be making any efforts to produce more "realistic" commodity stock numbers until several other prerequisite changes are made.

I'll take a quick look at the fuel foundation market, but I'm not entirely sure what the best way to handle that will be. Depends on what the existing code is trying to do.

The other graphical issues with the trade tool will be getting deferred to next update.

@Bodasey
Copy link

Bodasey commented Jan 21, 2023

I'm not sure if this is related to this PR, but happened when testing it.

Info: Game::LoadGame('_autosave5')
Info: savefile version: 88
Info: Creating new galaxy generator 'legacy' version 1
Info: Clearing and re-using previous Galaxy object
Info: StarSystemCache: misses: 0, slave hits: 0, master hits: 0
Info: SectorCache: misses: 0, slave hits: 0, master hits: 0
Info: Stars picked from galaxy: 125000
Info: Generating 0 random stars
Info: Final stars number: 125000
Info: WARNING: ship varada discarded, because there are no hyperspace routes available for it
Info: WARNING: lowering ships flow by 0.78 for performance reasons
Info: Stars picked from galaxy: 125000
Info: Generating 0 random stars
Info: Final stars number: 125000
Info: Color Fractal name: GGNeptune
Info: Color Fractal name: GGUranus
Info: Color Fractal name: GGSaturn
Info: Color Fractal name: GGJupiter
Info: TT-4247 (storeria) out of fuel
Info: VO-1169 (natrix) out of fuel

Thread 1 "pioneer" received signal SIGSEGV, Segmentation fault.
ImGui::TableSetupColumn (label=label@entry=0x15cc738 "Amount", flags=flags@entry=0, init_width_or_weight=init_width_or_weight@entry=0, user_id=0) at /home/romaschw/pioneer-station-economy/contrib/imgui/imgui_tables.cpp:1409
1409 if (table->DeclColumnsCount >= table->ColumnsCount)

Crash to terminal (gdb)

@impaktor impaktor force-pushed the master branch 2 times, most recently from 90e4530 to 6a3a044 Compare January 26, 2023 21:29
- Expose system body's star system and agricultural scalar to Lua
- Adjust ratio of specific input commodities to output commodities to avoid creating galactic 'dependence' on the commodity
- Now systems can export computers instead of constantly being starved of them!
- Separate all economic simulation code out into its own Lua module
- Give each station its own balance of economy types based on a limited set of parameters
- Commodity stock and demand are now tracked separately, based on 'flow' and 'affinity' controlling parameters driven by the station's economic type
- Commodity prices are determined on a per-station basis and dynamically update as the player buys and sells from the station
- This ties into the restocking mechanic to further increase the impact of making multiple round-trips between the same stations
- In-system trading is also now possible, with interstellar trading providing a higher profit margin for canny pilots
- Now all persistent commodities are fully handed inside of economy
- Haulaway commodities and hydrogen are treated separately, with a blind-random-walk update method
- Display list of nearby system prices for selected commodity
- Display list of prices for current system's stations for selected commodity
- Available via alt-click of existing button for development purposes
- Display local import/export status of a trade good
- Limit in-market display of a good's interstellar import/export status to trade computer only
- Additional column for commodity demand
- Limit sale of goods to only that station's available demand
- Move drawing the sidebar title into the main SystemOverviewWidget class
- Compares two station markets to each other, similar to comparing two system economies
- Displays import/export prices relative to the system's economic data
- Use sidebar for system overview and economy widgets
- Move current system name to center of map view
- Remove old system overview implementation
- Adds a 2% trade fee applied to both sides of a commodity transaction relative to the commodity price
- Update trade tool to take trade fees into account
- Increase commodity stock-based price variance to retain economic balance
- Use system view's system instead of current system when displaying overview title
- Add "no available data" string for inspecting economy in other systems
- Change debug commodity finder's "load data" mechanism
- General tweaks and cleanups
- Fix determinism issue due to iterating economy types by transient sort order
- Add random variance to commodity affinity on a per-station basis (reduces incidence of all stations in a system having the same import/export distribution)
- Adjust commodity flow based on affinity; "minimal trade" in a commodity results in lower supply and demand
@Web-eWorks Web-eWorks merged commit 49bd7e2 into pioneerspacesim:master Jan 26, 2023
@Web-eWorks Web-eWorks deleted the station-economy branch January 30, 2023 21:13
@antonspace
Copy link

Been messing around with the new economy today, just have a couple of questions to get a better understanding of what might be issues, and what might be features, don't wish to open an issue if it is really just my ignorance.

Screenshot_2023-02-03_20-31-47

On the left, metal alloys is shown to be a minor export, on the right it says intersteller trade: major import, major import where exactly? no other system is selected as a destination.

It is not clear why buying one item of metal alloys is going to cost more than the listed price, is there an unstated sales tax or profit margin here? Feels a bit like I am being ripped off, I can understand the price increasing after buying the item due to reduced supply, surely the price stated should be the price charged?

While playing around with the new economy today, thought it would be a good idea to buy some precious metals after finding them at a good price, problem was as I traveled around various systems running missions, demand was relatively low, so when a good price was encountered, I could only offload a few tonnes here and there, and ended up having to carry them around for months taking up valuable space. Not clear why demand is a limiting factor here, offloading a large supply of precious metals at any one station should be enough to discourage over exploiting that station as the relatively large increase in supply should have a relatively large reduction in the price?

@bszlrd
Copy link
Contributor

bszlrd commented Feb 3, 2023

I was a bit puzzled too at first, so maybe a tooltip would be useful for the icons on the list.
Those show whether the commodity is an export or import on the station you are at (shown on the system map too). Which can be different from the Interstellar Trade entry, which shows it for the system (what you would see on the sector map).
The price on the list is the price you'd buy/sell that commodity on that station. No taxes or whatever should be on the price.

@Web-eWorks
Copy link
Member Author

On the left, metal alloys is shown to be a minor export, on the right it says intersteller trade: major import, major import where exactly? no other system is selected as a destination.

In the left hand columns, the import/export is shown relative to the local market. On the description pane on the right, the "interstellar trade" indicates the profitability of this commodity relative to the interstellar average price of the commodity. It does not function relative to a target system, or it would display the target system's name and export/import status.

It is not clear why buying one item of metal alloys is going to cost more than the listed price, is there an unstated sales tax or profit margin here? Feels a bit like I am being ripped off, I can understand the price increasing after buying the item due to reduced supply, surely the price stated should be the price charged?

Both buying and selling are subject to a small (~2%) fee both directions, to avoid being able to immediately resell the commodity to the station for a 2-5% profit. Unfortunately, there was no room to split the "price" column into separate buy/sell prices, and I did not make any mention of the fee in any other text due to lack of time. The price column is the average price of the item at the station.

Not clear why demand is a limiting factor here, offloading a large supply of precious metals at any one station should be enough to discourage over exploiting that station as the relatively large increase in supply should have a relatively large reduction in the price?

Supply and demand are intended to be symmetric to each other relative to import/export - a station that primarily exports precious metals is not going to have a large demand to sell them to the local market (the market is already saturated with low-cost goods purchased directly from the factories / mines for a cheaper price than the player can get going through the export market), and a station that exports a very small amount and has little need for precious metals will not have a high demand no matter what you price your goods at. Thus, you should look for stations that need precious metals as a Major Import, as they will have high enough demand to handle the volume of goods you're trying to trade.

Outside of the economy simulation, this is entirely on purpose - precious metals are intended to be very low-volume trade items (10-20t max) to allow other goods to retain a level of relative profitability. For example, in a Pumpkinseed with 10t of cargo (at best...) you'll make the most total cash trading Precious metals, but if you buy a Mola Mola, you'll make more cash on a full hold with a 500-800cr good, rather than fully buying out a station's stock of precious metals and leaving the rest of the hold empty. Once you get to a Storeria, you'll be able to fully fill a hold with only 50-60cr goods, but will make more total cash from a run than if you bought out a station's entire stock of robots or precious metals.

This still isn't quite perfect, as the curve for how much money you make per run doesn't follow the curve for fuel costs, but you can load multiple commodities into your hold and sell them at different stations to maximize your profits if you don't mind paying extra for fuel. This is the intended game loop for bulk trading, where making more money requires more planning from the player and isn't as simple as "buy bigger ship, trade same commodities".

@Web-eWorks
Copy link
Member Author

And additionally - selling goods to a market does not instantaneously increase the supply available at that market. This is intentional to avoid economic exploits (buy a bunch, lowering supply to increase sell price, sell back for a profit), and also approximates real life - you're selling via a broker to a real entity, which means when you sell goods you only consume market demand. Pioneer's markets do not model speculative arbitrage, where a broker would take commodities off your hands for a much lower price and store them in hopes of being able to sell them later to other travellers for a higher price. This is something that would be implemented for later work, if ever, and most likely only be viable at certain high-traffic stations used as trade hubs.

@antonspace
Copy link

Had my doubts about limiting sales based on the demand, now it makes a lot more sense, It keeps all the commodities relevant throughout the game rather than the gradual drift towards high end products as is so often the case in gameplay.

I think the commodity market would benefit from having a separate buy price and sell price column, with the price displayed being the explicit price you pay or receive, narrowing the right side panel.

2 very trivial observations, buy 1 unit for, rather than buy 1 units for, and the precious metals description, should that be silver rather than silicon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants