Refactor Allies 04 objectives code

This commit is contained in:
ScottNZ
2013-06-06 01:54:40 +12:00
parent cdb74fd547
commit e4cd7220cc

View File

@@ -29,19 +29,15 @@ namespace OpenRA.Mods.RA.Missions
{ {
public event Action<bool> OnObjectivesUpdated = notify => { }; public event Action<bool> OnObjectivesUpdated = notify => { };
public IEnumerable<Objective> Objectives { get { return objectives.Values; } } public IEnumerable<Objective> Objectives { get { return new[] { infiltrateLab, destroyBase }; } }
Dictionary<int, Objective> objectives = new Dictionary<int, Objective> Objective infiltrateLab = new Objective(ObjectiveType.Primary, "", ObjectiveStatus.InProgress);
{ Objective destroyBase = new Objective(ObjectiveType.Primary, DestroyBaseText, ObjectiveStatus.Inactive);
{ InfiltrateID, new Objective(ObjectiveType.Primary, "", ObjectiveStatus.InProgress) },
{ DestroyID, new Objective(ObjectiveType.Primary, Destroy, ObjectiveStatus.Inactive) }
};
const int InfiltrateID = 0; const string InfiltrateLabTemplate = "The Soviets are currently developing a new defensive system named the \"Iron Curtain\" at their main research laboratory."
const int DestroyID = 1; + " Get our {0} into the laboratory undetected.";
const string Destroy = "Secure the laboratory and destroy the rest of the Soviet base. Ensure that the laboratory is not destroyed.";
const string Infiltrate = "The Soviets are currently developing a new defensive system named the \"Iron Curtain\" at their main research laboratory." const string DestroyBaseText = "Secure the laboratory and destroy the rest of the Soviet base. Ensure that the laboratory is not destroyed.";
+ " Get our {0} into the laboratory undetected.";
Actor hijackTruck; Actor hijackTruck;
Actor baseGuard; Actor baseGuard;
@@ -175,7 +171,7 @@ namespace OpenRA.Mods.RA.Missions
if (allies1Spy.IsDead() || (allies2Spy != null && allies2Spy.IsDead())) if (allies1Spy.IsDead() || (allies2Spy != null && allies2Spy.IsDead()))
{ {
objectives[InfiltrateID].Status = ObjectiveStatus.Failed; infiltrateLab.Status = ObjectiveStatus.Failed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
MissionFailed("{0} spy was killed.".F(allies1 != allies2 ? "A" : "The")); MissionFailed("{0} spy was killed.".F(allies1 != allies2 ? "A" : "The"));
} }
@@ -184,13 +180,13 @@ namespace OpenRA.Mods.RA.Missions
else if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead() else if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && !a.IsDead()
&& (a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>())) && (a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>()))
{ {
objectives[DestroyID].Status = ObjectiveStatus.Failed; destroyBase.Status = ObjectiveStatus.Failed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
MissionFailed("The remaining Allied forces in the area have been wiped out."); MissionFailed("The remaining Allied forces in the area have been wiped out.");
} }
else if (SovietBaseDestroyed() && objectives[InfiltrateID].Status == ObjectiveStatus.Completed) else if (SovietBaseDestroyed() && infiltrateLab.Status == ObjectiveStatus.Completed)
{ {
objectives[DestroyID].Status = ObjectiveStatus.Completed; destroyBase.Status = ObjectiveStatus.Completed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
MissionAccomplished("The Soviet research laboratory has been secured successfully."); MissionAccomplished("The Soviet research laboratory has been secured successfully.");
} }
@@ -214,8 +210,8 @@ namespace OpenRA.Mods.RA.Missions
void OnDestroyBaseTimerExpired(CountdownTimer t) void OnDestroyBaseTimerExpired(CountdownTimer t)
{ {
if (SovietBaseDestroyed() && objectives[InfiltrateID].Status == ObjectiveStatus.Completed) return; if (SovietBaseDestroyed() && infiltrateLab.Status == ObjectiveStatus.Completed) return;
objectives[DestroyID].Status = ObjectiveStatus.Failed; destroyBase.Status = ObjectiveStatus.Failed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
MissionFailed("The Soviet research laboratory was not secured in time."); MissionFailed("The Soviet research laboratory was not secured in time.");
} }
@@ -240,8 +236,8 @@ namespace OpenRA.Mods.RA.Missions
if (allies1SpyInfiltratedLab && (allies2SpyInfiltratedLab || allies2Spy == null)) if (allies1SpyInfiltratedLab && (allies2SpyInfiltratedLab || allies2Spy == null))
{ {
objectives[InfiltrateID].Status = ObjectiveStatus.Completed; infiltrateLab.Status = ObjectiveStatus.Completed;
objectives[DestroyID].Status = ObjectiveStatus.InProgress; destroyBase.Status = ObjectiveStatus.InProgress;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
frameInfiltrated = world.FrameNumber; frameInfiltrated = world.FrameNumber;
@@ -362,7 +358,7 @@ namespace OpenRA.Mods.RA.Missions
soviets = w.Players.Single(p => p.InternalName == "Soviets"); soviets = w.Players.Single(p => p.InternalName == "Soviets");
creeps = w.Players.Single(p => p.InternalName == "Creeps"); creeps = w.Players.Single(p => p.InternalName == "Creeps");
objectives[InfiltrateID].Text = Infiltrate.F(allies1 != allies2 ? "spies" : "spy"); infiltrateLab.Text = InfiltrateLabTemplate.F(allies1 != allies2 ? "spies" : "spy");
destroyBaseTicks = difficulty == "Hard" ? 1500 * 25 : difficulty == "Normal" ? 1500 * 28 : 1500 * 31; destroyBaseTicks = difficulty == "Hard" ? 1500 * 25 : difficulty == "Normal" ? 1500 * 28 : 1500 * 31;