My game includes a series of 10 missions, each with 3 objectives to complete during gameplay (very similar to achievements). Once the 3 objectives are completed in any order, the mission is completed and the player is given the next mission objectives.
I'm struggling with how to structure this. I've created a 10-length array of mission classes, with each class containing a 3-length array of classes for each of the objective details (name, goal value, completionState, etc.) This is a good start, and allows me to easily see if an achieved objective event is part of the current mission or if it should be ignored as it's currently not active.
var missionControl : MissionClass[];
class MissionClass
{
var mission = new ObjectiveInfo[3];
}
class ObjectiveInfo
{
var name : String;
var goalValue : int;
var completionState : boolean;
var total : int;
}
However, the way I'm intending to send achieved objective events is to send a string reference, rather than pointing to a location in the array (in case I shuffle the order later), but how can I use a string to locate an item in an array and then check if that item's parent Mission Class is the currently active mission?
function ObjectiveCheck ( objectiveName : String )
{
// Find the objective by name
// Find out if the objective we've been passed is part of the currently active mission
// If it is, check if we've met the goalValue, if so set objective to completed
}
// Edit: New Code using a string comparison. missionStatus
is an array where item 0
equals the current mission number (1/10), and items 1
, 2
, 3
hold the current status of each mission objective (0 = incomplete, 1 = previously complete, 2 = newly complete).
function ObjectiveCheck ( objectiveName : String, num : int )
{
// Find out if the objective we've been passed is part of the currently active mission and see if it's met the goal value
var currentMission = missionControl[ missionStatus[0] ];
for ( var i=0; i < 3; i++ )
if ( missionStatus[i+1] == 0 && currentMission[i].name == objectiveName && num >= currentMission[i].goalValue )
{
missionStatus[i+1] = 2;
// Play mission complete sound
}
}