1.3 Server
1.3.1 Sequence
1.3.2 Cargos
1.3.3 Grid
1.3.4 Engine
1.3.5 Setup
1.3.6 Agent
1.3.7 Interval
1.3.8 Dispatcher
1.3.9 TCP Server
8.14
1.3.2 Cargos🔗

Source code at cargos.rkt

Cargos are the blocks that bots are carrying. These are stored on the server in a hash table. The key is the bot id, the value is the block entity.
(struct cargos (hash))
(define (make-cargos) (cargos (make-hash)))
We can load cargo for a bot and retrieve cargo for a bot.
(test-case
 "load and retrieve"
 (let ([cargos (make-cargos)]
       [block (entity 102 type-block (location 1 2))])
   (load-cargo cargos 101 block)
   (check-equal? (cargo-for-bot cargos 101) block)))
The functions are basic hash table operations.
(define (cargo-for-bot cargos id) (hash-ref (cargos-hash cargos) id #f))
 
(define (load-cargo cargos id entity)
  (hash-set! (cargos-hash cargos) id entity))
When we unload cargo, the block is removed from the table and returned for later use.
(test-case
 "unload"
 (let ([cargos (make-cargos)]
       [block (entity 102 type-block (location 1 2))])
   (load-cargo cargos 101 block)
   (check-equal? (unload-cargo cargos 101) block)
   (check-false (cargo-for-bot cargos 101))))
Another basic hash table operation.
(define (unload-cargo cargos id)
  (let ([entity (cargo-for-bot cargos id)])
    (when entity
      (hash-remove! (cargos-hash cargos) id))
    entity))