#5 LibGDX Jam


Do not code when you're tired! A little story of bad design decisions. But let's start with the good part:


A space station cannot contain an unlimited amount of resources, so there has to be some kind of storage. This storage is basically just a map: Resource -> Amount
The two most important methods are int get(Quantity resource, int amount) and int add(Quantity resource).
A Quantity is a simple tuple of a Resource and an amount. The add method will try to add as much items from the quantity as possible. The return value is the number of added items.
Let's look at an example:
We have an empty storage with a limit of 100 resources and we want to add a Quantity(Oxygen, 110).
There is not enough space for all of it, but at least a portion of it. So after the add call, the storage is filled with 100 "units" of oxygen and the method returns the value 100, because that's the amount of added units. The quantity itself is also modified. It now has a leftover of 10 units.
The get method is similar, but it has an additional parameter amount. This additional parameter says how many units we want to move from the storage to the given quantity. The return value is again the number of moved units. Let's continue with the above example. We now want to move 50 units of oxygen back to our quantity, which only contains 10 units at the moment.
After this call: get(quantity, 50)
Our quantity now contains 60 units, the storage has 50 units and the method itself returns the value 50.

And now the bad part...

Consume and Produce

I implemented a system to consume and produce resources. The basic idea is that a ProducerConsumer consumes an array of quantities to produce another array of quantities. For example: A Water assembler will consume one H₂, one O and a bit energy to produce one H₂O. So far so good, but where does a room get its resources from? From the global storage? From its own input buffer?
Late at night I came to the conclusion that I want both. Gases and Liquids will be taken from the station itself, by iterating over all storage units and removing the needed items. Solids will be removed from the local input storage. So every room has now an array of storage units marked as input, output or global. A storage unit marked as input will be only used by the surrounding room. Output will be filled by the surrounding room and every other room can use it's content. Global storage can be used for anything.
Really strange and ugly design, but that's how it goes when it's late and you're tired...

So I'm not sure how to go on. Should I fix this trash or should I keep it and hope for the best? I mean, it works, but maybe I will regret this design decision. But fixing this will cost time and time is a rare resource at the moment.