From 6f538e01801eec6953a19e455edd5473d4cb411f Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 18 Sep 2014 18:12:29 +0200 Subject: [PATCH] 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()