From e4cd7220cce04f22d84b892841233caaafdb11b9 Mon Sep 17 00:00:00 2001 From: ScottNZ Date: Thu, 6 Jun 2013 01:54:40 +1200 Subject: [PATCH] Refactor Allies 04 objectives code --- OpenRA.Mods.RA/Missions/Allies04Script.cs | 36 ++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/OpenRA.Mods.RA/Missions/Allies04Script.cs b/OpenRA.Mods.RA/Missions/Allies04Script.cs index 23377b66f3..5ae1eb53d8 100644 --- a/OpenRA.Mods.RA/Missions/Allies04Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies04Script.cs @@ -29,19 +29,15 @@ namespace OpenRA.Mods.RA.Missions { public event Action OnObjectivesUpdated = notify => { }; - public IEnumerable Objectives { get { return objectives.Values; } } + public IEnumerable Objectives { get { return new[] { infiltrateLab, destroyBase }; } } - Dictionary objectives = new Dictionary - { - { InfiltrateID, new Objective(ObjectiveType.Primary, "", ObjectiveStatus.InProgress) }, - { DestroyID, new Objective(ObjectiveType.Primary, Destroy, ObjectiveStatus.Inactive) } - }; + Objective infiltrateLab = new Objective(ObjectiveType.Primary, "", ObjectiveStatus.InProgress); + Objective destroyBase = new Objective(ObjectiveType.Primary, DestroyBaseText, ObjectiveStatus.Inactive); - const int InfiltrateID = 0; - const int DestroyID = 1; - 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." - + " Get our {0} into the laboratory undetected."; + const string InfiltrateLabTemplate = "The Soviets are currently developing a new defensive system named the \"Iron Curtain\" at their main research laboratory." + + " Get our {0} into the laboratory undetected."; + + const string DestroyBaseText = "Secure the laboratory and destroy the rest of the Soviet base. Ensure that the laboratory is not destroyed."; Actor hijackTruck; Actor baseGuard; @@ -175,7 +171,7 @@ namespace OpenRA.Mods.RA.Missions if (allies1Spy.IsDead() || (allies2Spy != null && allies2Spy.IsDead())) { - objectives[InfiltrateID].Status = ObjectiveStatus.Failed; + infiltrateLab.Status = ObjectiveStatus.Failed; OnObjectivesUpdated(true); 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() && (a.HasTrait() && !a.HasTrait()) || a.HasTrait())) { - objectives[DestroyID].Status = ObjectiveStatus.Failed; + destroyBase.Status = ObjectiveStatus.Failed; OnObjectivesUpdated(true); 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); MissionAccomplished("The Soviet research laboratory has been secured successfully."); } @@ -214,8 +210,8 @@ namespace OpenRA.Mods.RA.Missions void OnDestroyBaseTimerExpired(CountdownTimer t) { - if (SovietBaseDestroyed() && objectives[InfiltrateID].Status == ObjectiveStatus.Completed) return; - objectives[DestroyID].Status = ObjectiveStatus.Failed; + if (SovietBaseDestroyed() && infiltrateLab.Status == ObjectiveStatus.Completed) return; + destroyBase.Status = ObjectiveStatus.Failed; OnObjectivesUpdated(true); MissionFailed("The Soviet research laboratory was not secured in time."); } @@ -240,8 +236,8 @@ namespace OpenRA.Mods.RA.Missions if (allies1SpyInfiltratedLab && (allies2SpyInfiltratedLab || allies2Spy == null)) { - objectives[InfiltrateID].Status = ObjectiveStatus.Completed; - objectives[DestroyID].Status = ObjectiveStatus.InProgress; + infiltrateLab.Status = ObjectiveStatus.Completed; + destroyBase.Status = ObjectiveStatus.InProgress; OnObjectivesUpdated(true); frameInfiltrated = world.FrameNumber; @@ -362,7 +358,7 @@ namespace OpenRA.Mods.RA.Missions soviets = w.Players.Single(p => p.InternalName == "Soviets"); 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;