One of the classic resources is STORAGE.
FACILITY represents things such as a service counter, a machine, or an operator: it can serve only one entity at a time and according to its capacity (with CAPACITY:3, the FACILITY would serve 3 entities). STORAGE, on the other hand, represents something like a warehouse, a tank, or a network that can be used partially.
What is a STORAGE? A STORAGE is a type of resource that is not seized per entity, but by quantity. It is used when an entity must reserve part of a resource without occupying it entirely. For example, a truck can drop 10 boxes into a warehouse that can hold up to 40.
How does it work? It is defined with a total capacity, for example 40 units.
STORAGE {NAME:warehouse1, X:300, Y:200, capacity:40}
Entities use the ENTER block to occupy a certain amount, and LEAVE to give it back.
ENTER warehouse1,5 LEAVE warehouse1
If an entity tries to occupy more than what is available, it will automatically wait in an internal queue until the STORAGE has enough free capacity. You don’t need to program anything additional to manage that wait.
In the example: a box warehouse (STORAGE) is defined with 40 capacity units. Trucks arrive every 10 time units and deposit between 1 and 16 boxes. After some time, they leave, freeing the occupied space. You will see on-screen text how many boxes are stored at any moment.
In addition to calculating it via additions and subtractions, you can also do it directly by querying the corresponding SNA for STORAGE occupancy:
R$(warehouse1,OCCUPIED) ; Units currently occupied R$(warehouse1,LEFT) ; Units available
Example
/* Warehouses: STORAGE
Capacity management and storage usage.
*/
INITIAL capacity,40 ; defines a savevalue named capacity with value 40
STORAGE {NAME:warehouse1, X:300, Y:200, capacity:X$capacity}
POSITION {NAME:EXIT, X:500, Y:200}
; Text showing current contents
GRAPHIC {NAME:text1, Type:TEXT, X:320, Y:240, Text:"Current boxes: 0"}
START 100
; Trucks arriving every 10 time units
GENERATE 10,0 {NAME:Truck, X:100, Y:200}
ADVANCE 15 {TO:warehouse1}
ENTER warehouse1,(random*15)+1 ; Occupies between 1 and 16 storage units
savevalue usage,X$capacity - R$(warehouse1,LEFT)
MOVE {name:text1,text:"Current boxes X$usage : R$(warehouse1,OCCUPIED)"}
ADVANCE 40,10
LEAVE warehouse1 ; Releases the occupied units
savevalue usage,X$capacity - R$(warehouse1,LEFT)
MOVE {name:text1,text:"Current boxes X$usage : R$(warehouse1,OCCUPIED)"}
ADVANCE 15 {TO:EXIT}
TERMINATE 1