Assorted notes on the production model / economy / stations

The place to discuss scripting and game modifications for X²: The Threat.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Post Reply
User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Assorted notes on the production model / economy / stations

Post by Burianek » Sun, 20. Jun 04, 08:04

Assorted notes on the production model / economy and creating factories with scripts
This is formatted extremely poorly. Forgive me, but I don't think there are too many people out there that want to do this stuff, so for the two or three of you that will read this, you'll forgive the sloppiness.

Creating factories with scripts
Setting up Products / Resources
When you create a station with a script, (as far as I know) it makes abosultely no difference what station type you choose to create. The only thing that will be different from station type to station type is the name that the station will have. The station will initially be set up with no products or primary / secondary resources. These must be manually added with the relevant script editor commands. Multiple products are not allowed. They will be added, but the station at best will only use one of them, and at worst will not function correctly at all.

Starting/Stopping the Factory Running
The station will not begin production or using any resources until it has been initialized with the script editor command 'set station production on = [true]' or whatever it's called. When this command is run, the code will scan the product type and set the cycle time based on product and any resources currently set up as described below. The command will not function correctly if the factory has had more than one product set up. Occasionally, it will use the last product added and just ignore the superfluous one/ones. Occasionally, the script command to initialize production will fail.
Factories can be set to run with no resources added. They will just produce products and require nothing.
Factories can be stopped from running by the corresponding 'set station production on = [false]'
Removing a product with the script editor without first stopping the station from running with the above command will break the station.
You can, if you wanted for some reason, stop the station from running, remove the product, add a different product, and restart the station running. The cycle time will change accordingly to reflect the new product and the resources will adjust their usage for the new cycle time to maintain the default rate of usage.
You can also stop a station from producing and change primary and secondary resources and when you start it again everything will adjust.
Note that any time you stop a station, you also need to wait until the current production run is complete before changing anything.

On the subject of multiple resources
First of all, secondary resources do not affect production. For NPC factories, they are resource sinks. Any wares present will slowly disappear with no other effect to the production model. They exist just so that the player has a place to dump goods. For player factories, they do not disappear. They'll just sit forever.
As many or as few primary resources can be added to a factory. Every primary resource has a default rate of comsumption. This is the exact same as its rate of production. (in all cases except energy)
A few examples:
Energy is consumed at 15 / min
Wheat - 10 / min
Beef - 3 / min
BoGas - 1 / 1.2 min
APAC - 1 / 8 min

and so on...

when you add a primary resource to a factory without first stopping the factory, and reinitializing afterwards, its cycle time has already been set by the product. The cycle time is multiplied by the consumption rate to get the units consumed per cycle. In the case of non-integer numbers, the computer rounds up. For example,
we've set up a 1 MW shield factory with only the product added,
we start it running.
the cycle time is set to 3 minutes
without stopping production and waiting for the current run to finish, we add Rastar Oil as a primary resource.
cycle time remains unchanged at 3 min.
the consumption rate of rastar oil is 2 per every 4/3 minutes, (or 1.5 per minute)
cycle time of 3 min times 1.5 per minute equals 4.5 oil consumed every 3 minutes
this is rounded up and the player will observe 5 oil consumed every 3 minute cycle.

If we had stopped production
waited for the run to finish
added rastar oil as a primary resource
and then reinitialized the factory with the 'set station production on = [true]' command,
cycle time would change to 6 minutes to reflect the least common multiple of the 1MW shield production rate and the Rastar oil consumption rate
now, 2 1MW shields are produced every 6 minutes, using 9 rastar oil.

Any time you set up multiple resources, when you issue the set factory production on command, the least common multiple is found and cycle time is set up.
(production / consumption rate or cycle time or whatever you want to call it is a function of ware price and is hardcoded in case you were interested. more expensive items are consumed less rapidly / take longer to produce)

Multiple Resources of the same Class
There are nine 'classes' of wares that can be used as resources and products.
These correspond to individual types files and are:
TWareB - basic food (wheat)
TWareE - energy
TWareF - advanced food (cloth rime)
TWareM - mineral (ore, silicon, nividium)
TWareN - mission items (artefacts, spacefly eggs)
TWareT - tech items (satellites, crystals, lasertowers, computer chips)
TLaser - Weapons
TShields - Shields
TRockets - Missiles

As you are setting up your factory, every primary resource that is added that represents a new types file is required for production to start.
Primary resources that are both from the same types file are standby items for eachother, and production will run as long as one or the other is present. Both are not required.

For example, I create a Bliss Place, and add spaceweed as my product.
I then add BoGas and Argnu Beef as my only two primary resources.
I initialize the factory and start it running.
As long as one or the other, but not necessarily both resources, are in stock, production will commence and the resource thatr is available will be consumed.
If both are in stock, the computer will randomly select one or the other (but not both) to be consumed at the beginning of each production cycle.

I could set up a factory with BoFu, Meatsteaks, Rastar Oil, and Soja Husk as the four primary resources, and as long as one was present the production cycle would commence.
Now, as soon as I add energy as a resource, a new types file is represented, and now my factory will require both energy and one of the above four foods to run a production cycle.
I think that's enough examples.




Changing ware prices with mods
This is what happens if you try to change avg price of a ware to alter factory performance.
Let me do a very specific example, assuming that you wanted to make a bliss place more profitable by doubling the price
of spaceweed:

Old bliss place:

In a cycle time of 4 minutes:
consumes 60 ecells @ 16 apiece = 960 value consumed / 4 min, or 240/min
consumes 8 swamp plants @ 156 apiece = 1248 value consumed / 4 min, or 312 / min
produces 1 spaceweed @ 2912 apiece = 2912 value / 4 min, or 728 / min.
Profit margin = 728 / (240 + 312) = 1.319
Profit / min = 728 - (240 + 312) = 176 / min

If you double the price of spaceweed this happens:

In a cycle time of 8 min (doubles with price):
consumes 120 ecells @ 16 apiece (doubles with price) = 1920 value consumed / 8 min, or 240/min
consumes 16 swamp plants @ 156 apiece (doubles with price) = 2496 value consumed / 8 min, or 312/min
produces 1 spaceweed @ 5824 (price changed) = 5824 value / 8 min, or 728 / min.
Profit margin and profit / min unchanged since every line has been effectively equalized on a per minute basis.
Stock limits for spaceweed are halved due to the higher price. (a station can hold x number of minutes worth of value of any good)

The code dynamically adjusts factory inputs required and cycle times to keep everything nice and equal.

Similarly, if the good that you are adjusting is used as an input somewhere else, the number of goods consumed per minute
will be halved to keep the value of those goods consumed / min constant.

There's also an issue with strange cycle times and such that Mad Hatter discovered. Let's say that you mutliply the price of
meatsteak cahoonas by 1.5 (from 72 to 108)
# Inputs and cycle time have this same factor applied to them:
Cycle time increases from 1 min, to 1.5 min (1 min 30 sec)
Energy required increases from 15 to 22.5
Argnu Beef required increases from 3 to 4.5
But you can't display these non integer numbers for inputs required, right?
So the code finds the least common multiple of all of the input and output units to keep integer values:
(in this case doubling them):
Cycle time now 3 min
Cahoonas produced now 20
Energy required now 45
Argnu Beef required now 9

You can imagine that if you pick a new avg price that is a strange multiple of the original, when the code scales up the inputs
required, it will yield a pretty tough number to make an integer out of. In this case, you can run into situations where the
code has to multiply through by extremely large factors to get integers for inputs/outputs. In some circumstances, this can make
the units produced per cycle larger than the stock limit for the factory! In this case the factory will never start production!




On the Flow of 'stuff' through the universe
Solar Power Plants
SPPs are the only factory that produces goods in greater quantity than is consumed. I'm hoping this makes sense to you, as I don't really feel like going into a long explanation. Basically,
3 beef takes 15 energy to produce.
10 meatsteaks take 15 energy and 3 beef to produce, or 15 energy plus 15 energy (for the beef), total of 30 energy.
1 silicon takes 24 energy to produce.
8 crystals take 120 energy, 80 meatsteaks, and 5 silicon to produce. or 120 energy plus 240 energy (for the meatsteaks) plus 120 energy (for the silicon), total of 480 energy.
Each crystal therefore takes 60 energy to produce.
In a SPP, each crystal produces 138 energy (more than double)
This is the only factory that does this, and SPPs are how 'stuff', 'wealth', or whatever you want to call it is added to the universe.

Resource Sinks
Resources are removed every so often from trading stations and secondary resource slots on NPC factories. This is how 'stuff' or 'wealth' or whatever is removed from the universe. Combined with SPPs, this system of resource adds and sinks keeps a constant flow through the universe and tries to manage that there is never an overabundance or shortage of products. Seen at the extreme cases, if every sector had multiple trading stations / docks / etc. that bought every product as soon as it was produced and then consumed it, there would be a global shortfall of 'stuff'. If every sector had 10 SPPs in it. Every factory would have limitless access to energy. The energy would flow from factory to factory, creating basic food, than adv food, up through high tech weapons, and as no factory would have to compete for the energy, there would be plenty of goods to go around. More than could be consumed in fact, and eventually all factories would cease production as they maxed storage, and the only time anything would be produced is as it trickled out of one of the sinks. It's late, I can't explain it any better than this. If you're modifiying the galaxy however, or changing the economy in any way, you have to respect the balance. Add too many sinks, and watch the galaxy bleed dry. Add too many sources (SPPs) and watch the overabundance of goods propagate. The X-Universe original map is painstakingly balanced. Trust me, it took them quite a great deal of effort to get it that way.

It feels like I'm forgetting a lot, and there are certainly a lot of topics I haven't covered. If anyone has specific questions or is experimenting and wonders why something is behaving the way it is, feel free to post. I may or may not know the answer, but at the very least, I'll try to work through it with you so we can both figure it out.
"Nature's first green is gold" . . . stay golden.

marklaverty
Posts: 270
Joined: Mon, 23. Feb 04, 15:03
x2

Post by marklaverty » Mon, 21. Jun 04, 14:05

:thumb_up: :thumb_up: :thumb_up: :thumb_up: :D
For everything you ever wanted to know about X2,
and more......

[ external image ]

User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Post by Burianek » Wed, 7. Jul 04, 17:01

Some further discussion of economy ideas is available here.
"Nature's first green is gold" . . . stay golden.

Post Reply

Return to “X²: The Threat - Scripts and Modding”