1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include "goal.h"
#include "scripting/ade_args.h"
#include "scripting/ade.h"
#include "scripting/api/objs/team.h"
#include "mission/missiongoals.h"
namespace scripting::api
{
//**********HANDLE: mission goal
ADE_OBJ(l_Goal, int, "mission_goal", "Mission goal handle");
ADE_VIRTVAR(Name, l_Goal, nullptr, "The name of the goal", "string", "The goal name")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", Mission_goals[current].name.c_str());
}
ADE_VIRTVAR(Message, l_Goal, nullptr, "The message of the goal", "string", "The goal message")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", Mission_goals[current].message.c_str());
}
ADE_VIRTVAR(Type, l_Goal, nullptr, "The goal type", "string", "primary, secondary, bonus, or none")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
SCP_string type;
int bit = Mission_goals[current].type & GOAL_TYPE_MASK;
switch (bit) {
case PRIMARY_GOAL:
type = "primary";
break;
case SECONDARY_GOAL:
type = "secondary";
break;
case BONUS_GOAL:
type = "bonus";
break;
default:
type = "none";
break;
}
return ade_set_args(L, "s", type);
}
ADE_VIRTVAR(Team, l_Goal, nullptr, "The goal team", "team", "The goal team")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "o", l_Team.Set(Mission_goals[current].team));
}
ADE_VIRTVAR(isGoalSatisfied, l_Goal, nullptr, "The status of the goal", "number", "0 if failed, 1 if complete, 2 if incomplete")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "i", Mission_goals[current].satisfied);
}
ADE_VIRTVAR(Score, l_Goal, nullptr, "The score of the goal", "number", "the score")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "i", Mission_goals[current].score);
}
ADE_VIRTVAR(isGoalValid, l_Goal, nullptr, "The goal validity", "boolean", "true if valid, false otherwise")
{
int current;
if (!ade_get_args(L, "o", l_Goal.Get(¤t))) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "b", !(Mission_goals[current].type & INVALID_GOAL));
}
ADE_FUNC(isValid, l_Goal, nullptr, "Detect if the handle is valid", "boolean", "true if valid, false otherwise")
{
int current = -1;
if (!ade_get_args(L, "o", l_Goal.Get(¤t)))
return ADE_RETURN_FALSE;
return ade_set_args(L, "b", (current >= 0) && (current < (int)Mission_goals.size()));
}
}
|