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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
//
//
#include "intelentry.h"
#include "menuui/techmenu.h"
namespace scripting {
namespace api {
//**********HANDLE: Intelentry
ADE_OBJ(l_Intelentry, int, "intel_entry", "Intel entry handle");
ADE_FUNC(__tostring, l_Intelentry, nullptr, "Intel entry name", "string", "Intel entry name, or an empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
return ade_set_args(L, "s", Intel_info[idx].name);
}
ADE_FUNC(__eq, l_Intelentry, "intel_entry, intel_entry", "Checks if the two entries are equal", "boolean", "true if equal, false otherwise")
{
int idx1,idx2;
if(!ade_get_args(L, "oo", l_Intelentry.Get(&idx1), l_Intelentry.Get(&idx2)))
return ade_set_error(L, "b", false);
if(idx1 < 0 || idx1 >= intel_info_size())
return ade_set_error(L, "b", false);
if(idx2 < 0 || idx2 >= intel_info_size())
return ade_set_error(L, "b", false);
return ade_set_args(L, "b", idx1 == idx2);
}
ADE_VIRTVAR(Name, l_Intelentry, "string", "Intel entry name", "string", "Intel entry name, or an empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR && s != nullptr) {
auto len = sizeof(Intel_info[idx].name);
strncpy(Intel_info[idx].name, s, len);
Intel_info[idx].name[len - 1] = 0;
}
return ade_set_args(L, "s", Intel_info[idx].name);
}
ADE_VIRTVAR(Description, l_Intelentry, "string", "Intel entry description", "string", "Description, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
if(s != nullptr) {
Intel_info[idx].desc = s;
} else {
Intel_info[idx].desc = "";
}
}
return ade_set_args(L, "s", Intel_info[idx].desc);
}
ADE_VIRTVAR(AnimFilename, l_Intelentry, "string", "Intel entry animation filename", "string", "Filename, or empty string if handle is invalid")
{
int idx;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if(idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
if(ADE_SETTING_VAR) {
if(s != nullptr) {
auto len = sizeof(Intel_info[idx].anim_filename);
strncpy(Intel_info[idx].anim_filename, s, len);
Intel_info[idx].anim_filename[len - 1] = 0;
} else {
strcpy_s(Intel_info[idx].anim_filename, "");
}
}
return ade_set_args(L, "s", Intel_info[idx].anim_filename);
}
ADE_VIRTVAR(InTechDatabase, l_Intelentry, "boolean", "Gets or sets whether this intel entry is visible in the tech room", "boolean", "True or false")
{
int idx;
bool new_value;
if (!ade_get_args(L, "o|b", l_Intelentry.Get(&idx), &new_value))
return ade_set_error(L, "b", false);
if (idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "b", false);
if (ADE_SETTING_VAR) {
if (new_value) {
Intel_info[idx].flags |= IIF_IN_TECH_DATABASE;
} else {
Intel_info[idx].flags &= ~IIF_IN_TECH_DATABASE;
}
}
return ade_set_args(L, "b", (Intel_info[idx].flags & IIF_IN_TECH_DATABASE) != 0);
}
ADE_VIRTVAR(CustomData,
l_Intelentry,
nullptr,
"Gets the custom data table for this entry",
"table",
"The entry's custom data table")
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
auto table = luacpp::LuaTable::create(L);
for (const auto& pair : Intel_info[idx].custom_data) {
table.addValue(pair.first, pair.second);
}
return ade_set_args(L, "t", &table);
}
ADE_FUNC(hasCustomData,
l_Intelentry,
nullptr,
"Detects whether the entry has any custom data",
"boolean",
"true if the entry's custom_data is not empty, false otherwise")
{
int idx;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Intelentry.Get(&idx), &s))
return ade_set_error(L, "s", "");
if (idx < 0 || idx >= intel_info_size())
return ade_set_error(L, "s", "");
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
bool result = !Intel_info[idx].custom_data.empty();
return ade_set_args(L, "b", result);
}
ADE_FUNC(isValid, l_Intelentry, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
int idx;
if(!ade_get_args(L, "o", l_Intelentry.Get(&idx)))
return ADE_RETURN_NIL;
if(idx < 0 || idx >= intel_info_size())
return ADE_RETURN_FALSE;
return ADE_RETURN_TRUE;
}
ADE_FUNC(getIntelEntryIndex, l_Intelentry, nullptr, "Gets the index value of the intel entry", "number", "index value of the intel entry")
{
int idx;
if(!ade_get_args(L, "o", l_Intelentry.Get(&idx)))
return ade_set_args(L, "i", -1);
if(idx < 0 || idx >= intel_info_size())
return ade_set_args(L, "i", -1);
return ade_set_args(L, "i", idx + 1); // Lua is 1-based
}
}
}
|