I would have a class Mission from which nothing derives. It would contain things like a mission name, description, reward, and a list of goals. A goal is where I would use inheritance to achieve polymorphism. The interface of a goal should allow me to check if the goal is still open, if it has been fulfilled, or if it has failed (e.g., you had to protect some ally and he has been killed). Alternatively, the goal could issue signals when it has been fulfilled and when it has determined it cannot be fulfilled. You probably also want to have a way of checking progress, for goals like "kill 8 enemies of this type", so you can display (3/8) next to the goal.
This is the goal class (the code is in C#)
public abstract class Goal
{
public enum State
{
Accomplished,
Failed,
InProgress
}
public Goal()
{
}
public abstract void Update(float dt);
public abstract State GetState();
}
I have figured out that sometimes I need some goals to happen:
- simultaneously. E.g: Go to location x AND Keep someone alive at the same time
- One after the other. E.g: Go to location x, then to location y, then to z, then kill someone etc
The first thing that came in my mind was this (This is in the Mission class by the way)
List<Goal> serialGoals; // goals that must be accomplished one after the other, in order
List<Goal> parallelGoals; // goals that none of them must fail (Failed state).
However the above design has the limitation that a particular goal cannot be linked with other parallel goals.
For example let's say I have the following serial goals:
Goal A) Go to location(x1, y1, z1)
Goal B) Kill the boss
But while Goal A is InProgress, I would like to have a parallel goal that would be:
The above goal must go away when Goal A is accomplished. With the design above it cannot be done.
So this is what I thought for this:
The goal class would contain a List<Goal> that would be the parallel goals that must hold true while this one is in progress. I think this is much better and will suffice for a lot of uses.
Is this design good? Do I have to consider more things?
Thanks in advance.