I'm writing a game that involves cargo, and I plan to have a large number of cargo types. Currently I have a Cargo
class, and a ship carrying cargo has an array of the Cargo
s it is holding.
I'd really rather not have each ship with a bunch of objects when all I really want to know is how much of which cargoes each ship has. Especially when these ships will be created and discarded a lot.
I'm sure the thing I'm looking for is so basic I'll look dumb for even asking, but I know there's something similar to an array that holds an object and a related value. I want to use that to reference the Cargo
type from the static array, and hold the quantity.
What's it called? How would I use it (ie what are common functions used for it)? Some code snippets and terminology would be ideal.