Inventory

<
>
November 1, 2021

With this change Structures can’t be placed for free anymore.

I introduced an Inventory type which is roughly implemented like this:

pub struct Inventory {
    items: BTreeMap<Item, usize>,
}

impl Inventory {
    pub fn add(&mut self, item: Item, count: usize) {
        ...
    }

    pub fn try_take(&mut self, item: &Item, count: usize) -> Option<usize> {
        ...
    }

    pub fn n_available(&self, item: &Item) -> usize {
        ...
    }

    pub fn starter_inventory() -> Self {
        ...
    }
}

I also updated Planet to have its own Inventory. Only Items available in it can be placed on the Planet and will be removed from that Inventory. When removed from the Planet, they are added back to the Inventory.
To then fill up the Planet’s Inventory, Influences got their own Inventory. They now accept any Structure which is then added to the Influence’s Inventory.
On every tick, the inventories of all Incluences are merged into the Planet’s. This way it’s possible to craft structures with your factory that are then available for placement.

The available counts are now displayed in the Structure overview:

Many Structures were only accepting Material instead of the more generic Item type which made it impossible to transport Structures within the factory. I updated them accordingly.