I want a way to make a lot of different units without having to program stuff like moveTo and Attack actions more than once
The way I see it, there are 2 ways I can do this.
- A single generic Unit class with flags that specifies what it can/can't do (then create instances in a static array and grab them when needed)
- Abstract unit class with abstract methods for Unit-specific actions like (Attack, Harvest, Patrol), which then all need to be implemented in the subclasses, even if the unit can't actually harvest anything.
the first way of doing this seems the simplest, but i would end up having a lot of code being unused for the majority of the units.
the second way could also work. But if i decide to have two different units that can harvest resources, i'm gonna have the exact same code in two different classes, which doesn't seem like the right way to do it.
Is this even the right approach to this problem?
In a game like AoE, every unit has, what i presume is, some kind of List of Actions/Orders, I would really like to know how to achieve something similar to that, where i can just code each Action/Order once, and then give it to all the units that need said Action.
If i'm unclear (highly plausible) or you need more information on what exactly i'm looking for, just ask me in a comment.