Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Please let me override the Economy engine!  (Read 2299 times)

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Please let me override the Economy engine!
« on: December 19, 2015, 07:08:59 PM »

I am... very disappointed with the economy engine, no matter how much I try to use workarounds on my mod to make the economy work better, it just don't work...

One of the biggest problems is the pricing system, and how markets buy and sell from each other, it create some bizarre bottlenecks in the economy (when markets need to move massive amount of goods, the price calculator breaks, if my calculations are correct, trying to sell millions of ore can make the price drop to 1, this is leading to a situation on my mod where refineries don't have enough ore to work, yet ore exists in massive quantities and is cheap, non-refinery markets are abusing the ore low price and stocking up, while refineries need to make massive purchases that break the price to them, and end not buying anything, thus they are stuck without ore).

I found no way to work around it, the only solution I can think is just override the Economy class.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Please let me override the Economy engine!
« Reply #1 on: December 19, 2015, 07:41:16 PM »

You can already do this. Just set these values:

"economyIntervalnGameDays":30,
"economyMinFramesPerSecond":30,

To something high (around a million) and the base economy should just run one iteration in the first day or so of pre-game-start-time and not run again. And then you should be able to manipulate whatever values you want directly through your own economy implementation made using a script.

And you'd need to override whatever else does direct manipulation so that it plays nice with your implementation (i.e. submarket plugins responding to player purchase/sales, trade disruption events, etc).

no matter how much I try to use workarounds on my mod to make the economy work better, it just don't work...

Yeah, it's probably better to just try to write your own than it is to have to figure out how this one works, which you'd really need to understand pretty well before being able to change it effectively. Kind of impossible, really, since there's no good way to see exactly how it's put together.
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Please let me override the Economy engine!
« Reply #2 on: December 20, 2015, 03:32:43 AM »

Yep, I already read a good part of it, many things I understood, some I didn't, specially when there are multiple indirections in obfuscated code (some functions call 3 or 4 obfuscated layers in a row).

Still, part of the reason I got so interested in this is that reading your code is very educational =D You are a very good Java programmer (of course I say that as a C++ programmer... so maybe your code is *** and I don't noticed :P)

Also... thanks for the idea! I considered a way of disabling the engine and overriding with my own code (I already figured how to do parts of that... I already have a enterframe script doing some stuff, and I already manipulate the market stock on transaction on the fuction that updates the cargo), but I didn't had any idea how, by making it run only once I already know what I would need to do :)


I will just have another question then: How I make something run on the economy setup phase of sector generation? And how much the economy updates in sector generation? (I assume it updates in the same speed as in-game, thus in vanilla during "Stabilization" it updates 33 times).
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Please let me override the Economy engine!
« Reply #3 on: December 20, 2015, 10:07:46 AM »

I will just have another question then: How I make something run on the economy setup phase of sector generation?

Hmm. Set the initialStepsToRun to 0 in your economy.json, and then you can update stuff in
ModPlugin.onNewGameAfterEconomyLoad
But the economy would still run through one cycle during the new-game-time-pass (before waiting for a million days, or whatever large value you'd set economyIntervalnGameDays to). So if you did that, you'd have to snapshot and restore the state of your economy.

Personally, I'd just run it all in, like, the 3rd or 4th day of the new-game-time-pass. After the base economy is done updating for good - which it will be quickly, if you set economyMinFramesPerSecond to something... ehh, wait, I've been thinking about this backwards. economyMinFramesPerSecond needs to be set super-low for the base economy to advance in a low number of frames.

If you set it to 1 / (economyIntervalnGameDays * 10) then that should ensure the base economy runs a full interval in one frame and then doesn't run anymore until economyIntervalnGameDays is over (which, if that's set to a million or so, will not happen in any reasonable timeframe.) Note: this one frame would take a long time, so the you'd see the progress bar stick for a while on the first day of sector generation, and then zip through the rest.

Hope this makes sense.

... made a note to add a flag to turn the economy off :)


And how much the economy updates in sector generation? (I assume it updates in the same speed as in-game, thus in vanilla during "Stabilization" it updates 33 times).

It updates 2 month's worth, whatever that means based on the configured values. By default, that's roughly two full passes over every market. Not sure where the 33 comes from?
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile
Re: Please let me override the Economy engine!
« Reply #4 on: December 20, 2015, 10:38:06 AM »

It updates 2 month's worth, whatever that means based on the configured values. By default, that's roughly two full passes over every market. Not sure where the 33 comes from?

The game when it loads do two things:

Economy Stabilization Pass.
Simulate sector for a while (I forgot the name the UI shows).

The first takes a number configured in economy.json
The second is seemly always 2 months (I found no way to change that).

I am very sure that the current vanilla economy.json has the first number set to 1000 days.

Since the economy updates every 30 days, this means it updates 33 times (33*30 = 990).

On my mod I currently set the economy to update daily, and changed the number of days to stabilize to 365, and it indeed takes roughly 10 times longer to do the stabilization pass. (I once set it to 5000 with 1 days update... serious mistake :P)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24128
    • View Profile
Re: Please let me override the Economy engine!
« Reply #5 on: December 20, 2015, 10:56:29 AM »

Ah, gotcha. (Yeah, the 2 months are currently hardcoded.)
Logged