/// <summary>
/// Finishes the given mission with the given vessel.
/// Rewards the space program with the missions reward.
/// </summary>
/// <param name="m">mission</param>
/// <param name="vessel">vessel</param>
public void finishMission(Mission m, Vessel vessel, GameEvent events)
{
if (!isMissionAlreadyFinished(m, vessel) && m.isDone(vessel, events))
{
MissionStatus status = new MissionStatus(m.name, vessel.id.ToString());
status.repeatable = m.repeatable;
status.repeatableSameVessel = m.repeatableSameVessel;
if (m.passiveMission)
{
status.endOfLife = Planetarium.GetUniversalTime() + m.lifetime;
status.passiveReward = m.passiveReward;
status.lastPassiveRewardTime = Planetarium.GetUniversalTime();
}
if (m.clientControlled)
{
status.endOfLife = Planetarium.GetUniversalTime() + m.lifetime;
}
status.clientControlled = m.clientControlled;
currentProgram.add(status);
reward(m.reward);
// finish unfinished goals
foreach (MissionGoal goal in m.goals)
{
finishMissionGoal(goal, vessel, events);
}
// If this mission is randomized, we will discard the mission
if (m.randomized)
{
discardRandomMission(m);
m = reloadMission(m, vessel);
}
}
}