Refactor Allies 03 objectives code

This commit is contained in:
ScottNZ
2013-06-06 01:51:15 +12:00
parent aecc3624ba
commit cdb74fd547

View File

@@ -28,29 +28,23 @@ 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[] { evacuateUnits, destroyAirbases, evacuateMgg }; } }
Dictionary<int, Objective> objectives = new Dictionary<int, Objective> Objective evacuateUnits = new Objective(ObjectiveType.Primary, EvacuateUnitsText, ObjectiveStatus.InProgress);
{ Objective destroyAirbases = new Objective(ObjectiveType.Secondary, DestroyAirbasesText, ObjectiveStatus.InProgress);
{ EvacuateID, new Objective(ObjectiveType.Primary, Evacuate, ObjectiveStatus.InProgress) }, Objective evacuateMgg = new Objective(ObjectiveType.Secondary, EvacuateMggText, ObjectiveStatus.InProgress);
{ AirbaseID, new Objective(ObjectiveType.Secondary, Airbase, ObjectiveStatus.InProgress) },
{ GapGeneratorID, new Objective(ObjectiveType.Secondary, GapGenerator , ObjectiveStatus.InProgress) }
};
const int EvacuateID = 0; const string EvacuateUnitsText = "Following the rescue of Einstein, the Allies are now being flanked from both sides."
const int AirbaseID = 1;
const int GapGeneratorID = 2;
const string Evacuate = "Following the rescue of Einstein, the Allies are now being flanked from both sides."
+ " Evacuate {0} units before the remaining Allied forces in the area are wiped out."; + " Evacuate {0} units before the remaining Allied forces in the area are wiped out.";
const string Airbase = "Destroy the nearby Soviet airbases."; const string DestroyAirbasesText = "Destroy the nearby Soviet airbases.";
const string GapGenerator = "Einstein has recently developed a technology which allows us to obscure units from the enemy." const string EvacuateMggText = "Einstein has recently developed a technology which allows us to obscure units from the enemy."
+ " Evacuate at least one prototype mobile gap generator intact."; + " Evacuate at least one prototype mobile gap generator intact.";
const string ShortEvacuateTemplate = "{0}/{1} units evacuated";
int unitsEvacuatedThreshold; int unitsEvacuatedThreshold;
int unitsEvacuated; int unitsEvacuated;
InfoWidget evacuateWidget; InfoWidget evacuateWidget;
const string ShortEvacuateTemplate = "{0}/{1} units evacuated";
World world; World world;
Player allies1; Player allies1;
@@ -185,7 +179,7 @@ namespace OpenRA.Mods.RA.Missions
if (world.FrameNumber % 25 == 0) if (world.FrameNumber % 25 == 0)
ManageSovietUnits(); ManageSovietUnits();
if (objectives[AirbaseID].Status != ObjectiveStatus.Completed) if (destroyAirbases.Status != ObjectiveStatus.Completed)
{ {
if (world.FrameNumber % 25 == 0) if (world.FrameNumber % 25 == 0)
BuildSovietAircraft(); BuildSovietAircraft();
@@ -196,12 +190,12 @@ namespace OpenRA.Mods.RA.Missions
EvacuateAlliedUnits(exit1TopLeft.CenterLocation, exit1BottomRight.CenterLocation, exit1ExitPoint.Location); EvacuateAlliedUnits(exit1TopLeft.CenterLocation, exit1BottomRight.CenterLocation, exit1ExitPoint.Location);
EvacuateAlliedUnits(exit2TopLeft.CenterLocation, exit2BottomRight.CenterLocation, exit2ExitPoint.Location); EvacuateAlliedUnits(exit2TopLeft.CenterLocation, exit2BottomRight.CenterLocation, exit2ExitPoint.Location);
CheckSovietAirbase(); CheckSovietAirbases();
if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && a.IsInWorld && !a.IsDead() if (!world.Actors.Any(a => (a.Owner == allies1 || a.Owner == allies2) && a.IsInWorld && !a.IsDead()
&& ((a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>()))) && ((a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>())))
{ {
objectives[EvacuateID].Status = ObjectiveStatus.Failed; evacuateUnits.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.");
} }
@@ -266,11 +260,11 @@ namespace OpenRA.Mods.RA.Missions
return world.Actors.Where(a => a.HasTrait<AttackPlane>() && a.Owner == soviets && a.IsInWorld && !a.IsDead()); return world.Actors.Where(a => a.HasTrait<AttackPlane>() && a.Owner == soviets && a.IsInWorld && !a.IsDead());
} }
void CheckSovietAirbase() void CheckSovietAirbases()
{ {
if (objectives[AirbaseID].Status != ObjectiveStatus.Completed && sovietAirfields.All(a => a.IsDead() || a.Owner != soviets)) if (destroyAirbases.Status != ObjectiveStatus.Completed && sovietAirfields.All(a => a.IsDead() || a.Owner != soviets))
{ {
objectives[AirbaseID].Status = ObjectiveStatus.Completed; destroyAirbases.Status = ObjectiveStatus.Completed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
} }
} }
@@ -349,9 +343,9 @@ namespace OpenRA.Mods.RA.Missions
void UpdateUnitsEvacuated() void UpdateUnitsEvacuated()
{ {
evacuateWidget.Text = ShortEvacuateTemplate.F(unitsEvacuated, unitsEvacuatedThreshold); evacuateWidget.Text = ShortEvacuateTemplate.F(unitsEvacuated, unitsEvacuatedThreshold);
if (objectives[EvacuateID].Status == ObjectiveStatus.InProgress && unitsEvacuated >= unitsEvacuatedThreshold) if (evacuateUnits.Status == ObjectiveStatus.InProgress && unitsEvacuated >= unitsEvacuatedThreshold)
{ {
objectives[EvacuateID].Status = ObjectiveStatus.Completed; evacuateUnits.Status = ObjectiveStatus.Completed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
MissionAccomplished("The remaining Allied forces in the area have evacuated."); MissionAccomplished("The remaining Allied forces in the area have evacuated.");
} }
@@ -369,9 +363,9 @@ namespace OpenRA.Mods.RA.Missions
unitsEvacuated++; unitsEvacuated++;
var createsShroud = unit.TraitOrDefault<CreatesShroud>(); var createsShroud = unit.TraitOrDefault<CreatesShroud>();
if (createsShroud != null && objectives[GapGeneratorID].Status == ObjectiveStatus.InProgress) if (createsShroud != null && evacuateMgg.Status == ObjectiveStatus.InProgress)
{ {
objectives[GapGeneratorID].Status = ObjectiveStatus.Completed; evacuateMgg.Status = ObjectiveStatus.Completed;
OnObjectivesUpdated(true); OnObjectivesUpdated(true);
} }
@@ -416,7 +410,7 @@ namespace OpenRA.Mods.RA.Missions
sovietParadropTicks = difficulty == "Hard" ? 1500 * 17 : 1500 * 20; sovietParadropTicks = difficulty == "Hard" ? 1500 * 17 : 1500 * 20;
sovietUnits2Ticks = difficulty == "Hard" ? 1500 * 12 : 1500 * 15; sovietUnits2Ticks = difficulty == "Hard" ? 1500 * 12 : 1500 * 15;
objectives[EvacuateID].Text = objectives[EvacuateID].Text.F(unitsEvacuatedThreshold); evacuateUnits.Text = evacuateUnits.Text.F(unitsEvacuatedThreshold);
allies = w.Players.Single(p => p.InternalName == "Allies"); allies = w.Players.Single(p => p.InternalName == "Allies");
soviets = w.Players.Single(p => p.InternalName == "Soviets"); soviets = w.Players.Single(p => p.InternalName == "Soviets");