Add more functions for objectives management to Lua API

This commit is contained in:
Oliver Brakmann
2014-09-18 18:12:29 +02:00
parent 97ce246a27
commit 6f538e0180

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System; using System;
using Eluant;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Scripting; using OpenRA.Scripting;
using OpenRA.Mods.RA; using OpenRA.Mods.RA;
@@ -48,6 +49,9 @@ namespace OpenRA.Mods.RA.Scripting
"objectives, (s)he has won the game.")] "objectives, (s)he has won the game.")]
public void MarkCompletedObjective(int id) 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); mo.MarkCompleted(player, id);
} }
@@ -57,9 +61,42 @@ namespace OpenRA.Mods.RA.Scripting
"influence whatsoever on the outcome of the game.")] "influence whatsoever on the outcome of the game.")]
public void MarkFailedObjective(int id) 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); 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] [ScriptActorPropertyActivity]
[Desc("Returns true if this player has lost all units/actors that have the MustBeDestroyed trait.")] [Desc("Returns true if this player has lost all units/actors that have the MustBeDestroyed trait.")]
public bool HasNoRequiredUnits() public bool HasNoRequiredUnits()