diff --git a/OpenRA.Mods.RA/Player/MissionObjectives.cs b/OpenRA.Mods.RA/Player/MissionObjectives.cs index bdaf011718..73433077e8 100644 --- a/OpenRA.Mods.RA/Player/MissionObjectives.cs +++ b/OpenRA.Mods.RA/Player/MissionObjectives.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA public void MarkFailed(Player player, int objectiveID) { - if (objectiveID >= objectives.Count || objectives[objectiveID].State == ObjectiveState.Failed) + if (objectiveID >= objectives.Count || objectives[objectiveID].State != ObjectiveState.Incomplete) return; var inous = player.PlayerActor.TraitsImplementing(); diff --git a/OpenRA.Mods.RA/Scripting/Properties/MissionObjectiveProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/MissionObjectiveProperties.cs index 7259ba81c6..56c1e344ed 100644 --- a/OpenRA.Mods.RA/Scripting/Properties/MissionObjectiveProperties.cs +++ b/OpenRA.Mods.RA/Scripting/Properties/MissionObjectiveProperties.cs @@ -9,6 +9,7 @@ #endregion using System; +using Eluant; using OpenRA.Traits; using OpenRA.Scripting; using OpenRA.Mods.RA; @@ -48,6 +49,9 @@ namespace OpenRA.Mods.RA.Scripting "objectives, (s)he has won the game.")] public void MarkCompletedObjective(int id) { + if (id < 0 || id >= mo.Objectives.Count) + throw new LuaException("Objective ID is out of range."); + mo.MarkCompleted(player, id); } @@ -57,9 +61,42 @@ namespace OpenRA.Mods.RA.Scripting "influence whatsoever on the outcome of the game.")] public void MarkFailedObjective(int id) { + if (id < 0 || id >= mo.Objectives.Count) + throw new LuaException("Objective ID is out of range."); + mo.MarkFailed(player, id); } + [ScriptActorPropertyActivity] + [Desc("Returns true if the objective has been successfully completed, false otherwise.")] + public bool IsObjectiveCompleted(int id) + { + if (id < 0 || id >= mo.Objectives.Count) + throw new LuaException("Objective ID is out of range."); + + return mo.Objectives[id].State == ObjectiveState.Completed; + } + + [ScriptActorPropertyActivity] + [Desc("Returns true if the objective has been failed, false otherwise.")] + public bool IsObjectiveFailed(int id) + { + if (id < 0 || id >= mo.Objectives.Count) + throw new LuaException("Objective ID is out of range."); + + return mo.Objectives[id].State == ObjectiveState.Failed; + } + + [ScriptActorPropertyActivity] + [Desc("Returns the description of an objective.")] + public string GetObjectiveDescription(int id) + { + if (id < 0 || id >= mo.Objectives.Count) + throw new LuaException("Objective ID is out of range."); + + return mo.Objectives[id].Description; + } + [ScriptActorPropertyActivity] [Desc("Returns true if this player has lost all units/actors that have the MustBeDestroyed trait.")] public bool HasNoRequiredUnits() diff --git a/mods/cnc/maps/gdi01/gdi01.lua b/mods/cnc/maps/gdi01/gdi01.lua index 3c08f00494..1cee01a00e 100644 --- a/mods/cnc/maps/gdi01/gdi01.lua +++ b/mods/cnc/maps/gdi01/gdi01.lua @@ -48,8 +48,12 @@ WorldLoaded = function() gdiObjective1 = player.AddPrimaryObjective("Eliminate all Nod forces in the area") gdiObjective2 = player.AddSecondaryObjective("Establish a beachhead") - Trigger.OnObjectiveCompleted(player, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(player, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.OnPlayerWon(player, function() Media.PlaySpeechNotification(player, "Win") diff --git a/mods/cnc/maps/gdi02/gdi02.lua b/mods/cnc/maps/gdi02/gdi02.lua index 0b38ab31ee..0dce41c867 100644 --- a/mods/cnc/maps/gdi02/gdi02.lua +++ b/mods/cnc/maps/gdi02/gdi02.lua @@ -37,8 +37,12 @@ WorldLoaded = function() gdiObjective1 = player.AddPrimaryObjective("Eliminate all Nod forces in the area") gdiObjective2 = player.AddSecondaryObjective("Capture the Tiberium Refinery") - Trigger.OnObjectiveCompleted(player, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(player, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.OnPlayerWon(player, function() Media.PlaySpeechNotification(player, "Win") diff --git a/mods/cnc/maps/gdi04c/gdi04c.lua b/mods/cnc/maps/gdi04c/gdi04c.lua index ba50ae858a..0497bec674 100644 --- a/mods/cnc/maps/gdi04c/gdi04c.lua +++ b/mods/cnc/maps/gdi04c/gdi04c.lua @@ -82,8 +82,12 @@ WorldLoaded = function() gdiObjective1 = player.AddPrimaryObjective("Defend the town of BiaƂystok") gdiObjective2 = player.AddPrimaryObjective("Eliminate all Nod forces in the area") - Trigger.OnObjectiveCompleted(player, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(player, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.OnAllKilled(LoseTriggerHouses, function() player.MarkFailedObjective(gdiObjective1) diff --git a/mods/cnc/maps/nod01/nod01.lua b/mods/cnc/maps/nod01/nod01.lua index b2e3fd1a4d..c0b80ed880 100644 --- a/mods/cnc/maps/nod01/nod01.lua +++ b/mods/cnc/maps/nod01/nod01.lua @@ -26,8 +26,12 @@ WorldLoaded = function() NodObjective3 = nod.AddSecondaryObjective("Destroy all GDI troops in the area") GDIObjective1 = gdi.AddPrimaryObjective("Eliminate all Nod forces") - Trigger.OnObjectiveCompleted(nod, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(nod, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(nod, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(nod, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.OnPlayerWon(nod, function() Media.PlaySpeechNotification(nod, "Win") diff --git a/mods/cnc/maps/nod03a/nod03a.lua b/mods/cnc/maps/nod03a/nod03a.lua index 2f003423dd..ac0ecdbbe9 100644 --- a/mods/cnc/maps/nod03a/nod03a.lua +++ b/mods/cnc/maps/nod03a/nod03a.lua @@ -28,8 +28,12 @@ WorldLoaded = function() Trigger.AfterDelay(Utils.Seconds(50), function() SendAttackWave(SecondThirdAttackWave, AttackWaveSpawnB.Location) end) Trigger.AfterDelay(Utils.Seconds(100), function() SendAttackWave(SecondThirdAttackWave, AttackWaveSpawnC.Location) end) - Trigger.OnObjectiveCompleted(player, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(player, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.OnCapture(TechCenter, function() Trigger.AfterDelay(Utils.Seconds(2), function() diff --git a/mods/cnc/maps/nod03b/nod03b.lua b/mods/cnc/maps/nod03b/nod03b.lua index d13545a980..08a626a56a 100644 --- a/mods/cnc/maps/nod03b/nod03b.lua +++ b/mods/cnc/maps/nod03b/nod03b.lua @@ -40,8 +40,12 @@ WorldLoaded = function() nodObjective2 = player.AddSecondaryObjective("Destroy all GDI forces") InsertNodUnits() - Trigger.OnObjectiveCompleted(player, function() Media.DisplayMessage("Objective completed") end) - Trigger.OnObjectiveFailed(player, function() Media.DisplayMessage("Objective failed") end) + Trigger.OnObjectiveCompleted(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed") + end) + Trigger.OnObjectiveFailed(player, function(p, id) + Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed") + end) Trigger.AfterDelay(Utils.Seconds(40), function() SendAttackWave(FirstAttackWaveUnits, FirstAttackWave) end) Trigger.AfterDelay(Utils.Seconds(80), function() SendAttackWave(SecondAttackWaveUnits, SecondAttackWave) end)