2
\$\begingroup\$

In my GPS based game, there are certain structures the players can build that store units. For example, airbase structures store aircraft objects. Currently, the way I have this organized is the airbases and aircraft each have their own ID number. The aircraft also have a "homebase id" that stores the ID of the airbase they currently belong to. When the aircraft returns to base and "lands," the aircraft ceases being in a "flying" state, stops moving, and becomes invisible, on the location of the airbase. This works okay, but it's also kind of janky and I'm not sure it'll work in the future when I add aircraft carriers that store aircraft, troop transport planes and ships that store infantry units, etc.

I'm not very experienced in game design and I'm wondering if there is a better way I could do this.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I'm not familiar with Java, but if I read this correctly, then the airplanes are all stored in the airbase, which means that if the airbase gets destroyed/removed, the airplanes will be deleted as well?

I think it works if destroying the airbase is the key objective, but if it's not intended, then I would make a global list and store the airplanes in there. They will still relate with the homebase thanks to the ID, but they're not forced to only persist if the airbase does.

Same also goes for the other sub-units to make a global list to keep them detached. Perhaps the units could also have a "parent garrison id" or "garrison type" (made up terms) so it can be decided by which unit type (an airbase or an aircraft carrier ect.) and which ID of that unit (in the case of multiple airbases or aircrafts) they're currently "landed" at.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .