Refactor Allies 03 objectives code
This commit is contained in:
@@ -28,29 +28,23 @@ namespace OpenRA.Mods.RA.Missions
|
||||
{
|
||||
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>
|
||||
{
|
||||
{ EvacuateID, new Objective(ObjectiveType.Primary, Evacuate, ObjectiveStatus.InProgress) },
|
||||
{ AirbaseID, new Objective(ObjectiveType.Secondary, Airbase, ObjectiveStatus.InProgress) },
|
||||
{ GapGeneratorID, new Objective(ObjectiveType.Secondary, GapGenerator , ObjectiveStatus.InProgress) }
|
||||
};
|
||||
Objective evacuateUnits = new Objective(ObjectiveType.Primary, EvacuateUnitsText, ObjectiveStatus.InProgress);
|
||||
Objective destroyAirbases = new Objective(ObjectiveType.Secondary, DestroyAirbasesText, ObjectiveStatus.InProgress);
|
||||
Objective evacuateMgg = new Objective(ObjectiveType.Secondary, EvacuateMggText, ObjectiveStatus.InProgress);
|
||||
|
||||
const int EvacuateID = 0;
|
||||
const int AirbaseID = 1;
|
||||
const int GapGeneratorID = 2;
|
||||
const string EvacuateUnitsText = "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.";
|
||||
const string DestroyAirbasesText = "Destroy the nearby Soviet airbases.";
|
||||
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.";
|
||||
|
||||
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.";
|
||||
const string Airbase = "Destroy the nearby Soviet airbases.";
|
||||
const string GapGenerator = "Einstein has recently developed a technology which allows us to obscure units from the enemy."
|
||||
+ " Evacuate at least one prototype mobile gap generator intact.";
|
||||
const string ShortEvacuateTemplate = "{0}/{1} units evacuated";
|
||||
|
||||
int unitsEvacuatedThreshold;
|
||||
int unitsEvacuated;
|
||||
InfoWidget evacuateWidget;
|
||||
const string ShortEvacuateTemplate = "{0}/{1} units evacuated";
|
||||
|
||||
World world;
|
||||
Player allies1;
|
||||
@@ -185,7 +179,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
if (world.FrameNumber % 25 == 0)
|
||||
ManageSovietUnits();
|
||||
|
||||
if (objectives[AirbaseID].Status != ObjectiveStatus.Completed)
|
||||
if (destroyAirbases.Status != ObjectiveStatus.Completed)
|
||||
{
|
||||
if (world.FrameNumber % 25 == 0)
|
||||
BuildSovietAircraft();
|
||||
@@ -196,12 +190,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
EvacuateAlliedUnits(exit1TopLeft.CenterLocation, exit1BottomRight.CenterLocation, exit1ExitPoint.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()
|
||||
&& ((a.HasTrait<Building>() && !a.HasTrait<Wall>()) || a.HasTrait<BaseBuilding>())))
|
||||
{
|
||||
objectives[EvacuateID].Status = ObjectiveStatus.Failed;
|
||||
evacuateUnits.Status = ObjectiveStatus.Failed;
|
||||
OnObjectivesUpdated(true);
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -349,9 +343,9 @@ namespace OpenRA.Mods.RA.Missions
|
||||
void UpdateUnitsEvacuated()
|
||||
{
|
||||
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);
|
||||
MissionAccomplished("The remaining Allied forces in the area have evacuated.");
|
||||
}
|
||||
@@ -369,9 +363,9 @@ namespace OpenRA.Mods.RA.Missions
|
||||
unitsEvacuated++;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -416,7 +410,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
sovietParadropTicks = difficulty == "Hard" ? 1500 * 17 : 1500 * 20;
|
||||
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");
|
||||
soviets = w.Players.Single(p => p.InternalName == "Soviets");
|
||||
|
||||
Reference in New Issue
Block a user