Production Line

Production Line

Not enough ratings
How Slot stockpiles work (version 1.53)
By cliffski
A low level technical explanation of the code that controls the stockpiles built into production line slots. (not supply stockpiles or component production export stockpiles)
   
Award
Favorite
Favorited
Unfavorite
The code that runs every frame
The stockpiles attached to each slot get processed every frame. This calls

SIM_StockpileBase::Process()

At regular intervals (every 60 frames, or probably one second), they call this code:

RequestReplacements();

That code checks the stockpile still has a link to an import bay, or at least a manufacturing bay or supply stockpile. If it does not, it recalculates a route to the nearest bay. If none is found, it pops up the error notice to tell the player there is no link to the resource network.

The code then calls

ProcessShoppingList()

In this code, the stockpile goes through its list of 'CurrentResources' which are the list of resources required to carry out the current task on the current car. If there are any resources that are not available, or not already 'on order' from somewhere, requests for those resources are added to the network.

If there is still empty space in the stockpile at this point, the code will loop through the current resources list adding more of each needed item to its requests, so it hopefully has enough of everything for the *current* car to work on multiple identical models.
Code than runs when a task is complete (or started.. if predictive stock control)
When a task is completed (or earlier if we have predictive stock control enabled), the resources used for the task get consumed. This carries out the following code:

SpendResources() is called, which firstly calls

BuildCurrentResourceList()
This is a big chunk of code that does the following:
1) goes through each resource requirement for the current task and adds these items tom a list
2) goes through upgrades enabled at this slot and for this vehicle and then adds/removes resource items from that list
3) goes through any car-body overrides that add or remove resources based on the body style (for example 2 door cars use less doors)
4) goes through any power-train specific requirements, such as swapping fuel tank for battery in electric power train vehicles.

We now have a list of resources we will need to build the current car, and this list gets copied to 'CurrentResources'

We then run some code called ProcessPurge()
This code goes through every object currently in the stockpile and checks its resource type against the last 16 resource typoes that this stockpile actually used. If none of these resource types match the current one, we then check if our slot has multiple subtasks, and check to see if any other tasks in that list would require the resource. if the answer is still no, it gets 'purged' in other words, removed and refunded to free up space.


and then the stockpile goes through each entry in 'CurrentResources' and does the following:
1) Updates the consumption history of that resources for showing stats to the player
2) Updates a list of whether the resources just used was locally made or not, to provide local slot stats to the player
3) Removes the resource item from the stockpile
4) Makes a note that this resource item was the most recent in the 'LastObjects' list of the 16 most recently used resource objects.



1 Comments
Hephaistos 9 Jul, 2018 @ 11:35am 
So I start with 16 doors.

I build a car but get no resource alert for the car alarm it uses. One door gets replaced with an emergency ordered car alarm.

Then 4 doors are used and I am left with 11 doors in my stock.

The remaining 11 doors will not get purged because they are always in the lastObjects list. But then the loop goes and orders 5 new doors to replenish the stockpile. It should get 4 doors and one alarm.