Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Flocking
- {
- public class Mission
- {
- public string missionName;
- private List<SubMission> subMissions; // submissions that must be completed one after the other
- private List<Goal.State> status; // status of each submission
- private int activeIndex = 0; // index of the active sub-mission
- public Mission()
- {
- subMissions = new List<SubMission>();
- status = new List<Goal.State>();
- }
- /// <summary>
- /// Adds a sub mission to this mission.
- /// </summary>
- public void AddSubMission(SubMission s)
- {
- subMissions.Add(s);
- status.Add(Goal.State.InProgress);
- }
- public void Update(float dt)
- {
- if( GetState() != Goal.State.Accomplished )
- {
- // update the active sub-mission
- var activeSubMission = subMissions[activeIndex];
- activeSubMission.Update(dt);
- // if the active sub-mission was completed, move on to the next
- if( activeSubMission.GetState() == Goal.State.Accomplished )
- {
- status[activeIndex] = Goal.State.Accomplished;
- ++activeIndex;
- }
- else if( activeSubMission.GetState() == Goal.State.Failed )
- {
- status[activeIndex] = Goal.State.Failed;
- ++activeIndex;
- }
- }
- }
- public Goal.State GetState()
- {
- // first, check the list of accomplished/failed missions. If one of those has Failed, return Failed
- for(int i = 0; i < activeIndex; ++i)
- if( status[i] == Goal.State.Failed )
- return Goal.State.Failed;
- // to determine if the mission is still in progress, check the last's sub-missions status
- // if it's In-Progress, the whole mission is in progress
- if( status[status.Count - 1] == Goal.State.InProgress )
- return Goal.State.InProgress;
- // if we reached this point, the mission was successful
- return Goal.State.Accomplished;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement