Mission Objectives

Started by
1 comment, last by CirdanValen 12 years, 9 months ago
For the past few days, I've been contemplating how to implement mission objectives in my shmup. It's going to be a fairly simple system, only one objective is active at a time and objectives will only consist of killing x number of baddies, stay alive for x amount of minutes, and other similar objectives.

Staying alive for x amount of minutes is a simple objective to create because it's a timer. However, objectives that need to keep track of how many baddies were killed or how many items were collected by the player I just can't nail down.

Basically, my idea was when the foe factory generates an enemy that is the goal of the objective, it would assign an event listener to that foe object. When that foe was "killed" it would send a message to the listener saying that it was killed, and the objective counter would increase. The only problem with this is I need to figure out if there is a way to design the factory to differentiate between the different enemy objects so it knows which ones to keep track of. I was hoping to figure out an elegant solution, but I think I might have to resort to assigning a string in the foe objects stating which kind enemy it is, which will allow me to check it against the objective. Is there a better way to do this?

The way my game is setup currently is I have a "Ship" class, and the enemies inherit from this class allowing me to add special functionality. I'm writing this in C++
Advertisement
[source lang="cpp"]class Objective
{
// Constructors etc. omitted

public:
template<typename T>
bool WantsToKill(const T&) const
{
return false;
}

template<>
bool WantsToKill(const SpecificShip&) const
{
return WantsToKillSpecificShip;
}

public:
void IncreaseKillCounter()
{
++KillCounter;

if(KillCounter >= TargetKillCount)
GameObjectives.CompleteObjective(*this);
}

private:
unsigned KillCounter;
unsigned TargetKillCount;

bool WantsToKillSpecificShip;
};



class Ship
{
public:
virtual void CheckObjectiveWhenKilled(Objective&) const { }
};

class SpecificShip
{
public:
virtual void CheckObjectiveWhenKilled(Objective& objective) const
{
if(objective.WantsToKill(*this))
objective.IncreaseKillCounter();
}
};[/source]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Ooh, I like that solution. Thanks!

This topic is closed to new replies.

Advertisement