From 97ce246a27dcf15a287290dd683fd0b860784e3c Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 18 Sep 2014 18:06:30 +0200 Subject: [PATCH 1/3] Prevent already failed objectives from being marked as completed The same change was not and must not be done in the reverse case. It should be and is possible to mark an already completed objective as failed. Consider a case where a player is supposed to capture, but not destroy, a building. He captures it, the objective is complete. However, later in the game that building gets destroyed. In this case, the objective should be changed to failed. --- OpenRA.Mods.RA/Player/MissionObjectives.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 6f538e01801eec6953a19e455edd5473d4cb411f Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 18 Sep 2014 18:12:29 +0200 Subject: [PATCH 2/3] Add more functions for objectives management to Lua API --- .../Properties/MissionObjectiveProperties.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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() From 1db6388bd4f396b9621be0d41a7b0e02fa6b16f2 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 18 Sep 2014 18:29:28 +0200 Subject: [PATCH 3/3] Update existing maps --- mods/cnc/maps/gdi01/gdi01.lua | 8 ++++++-- mods/cnc/maps/gdi02/gdi02.lua | 8 ++++++-- mods/cnc/maps/gdi04c/gdi04c.lua | 8 ++++++-- mods/cnc/maps/nod01/nod01.lua | 8 ++++++-- mods/cnc/maps/nod03a/nod03a.lua | 8 ++++++-- mods/cnc/maps/nod03b/nod03b.lua | 8 ++++++-- 6 files changed, 36 insertions(+), 12 deletions(-) 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)