mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 08:15:59 -10:00
* Automatically generate the isValid() Lua API function for handle types If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically. An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own. The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one. Co-Authored-By: Claude Fable 5.1 <[email protected]> * Add ADE_OBJ_VALIDATOR for index-based Lua handles Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ. The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles. The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid(). Add a validator to HudGauge while we're at it. Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
147 lines
3.6 KiB
C++
147 lines
3.6 KiB
C++
|
|
#include "event.h"
|
|
#include "scripting/ade_args.h"
|
|
#include "scripting/ade.h"
|
|
#include "mission/missiongoals.h"
|
|
|
|
namespace scripting::api
|
|
{
|
|
//**********HANDLE: mission event
|
|
ADE_OBJ(l_Event, int, "mission_event", "Mission event handle");
|
|
ADE_OBJ_VALIDATOR(l_Event, idx, Mission_events.in_bounds(idx));
|
|
|
|
ADE_VIRTVAR(Name, l_Event, "string", "Mission event name", "string", nullptr)
|
|
{
|
|
int idx;
|
|
const char* s = nullptr;
|
|
if (!ade_get_args(L, "o|s", l_Event.Get(&idx), &s))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "s", "");
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR && s != nullptr) {
|
|
mep->name = s;
|
|
}
|
|
|
|
return ade_set_args(L, "s", mep->name.c_str());
|
|
}
|
|
|
|
ADE_VIRTVAR(DirectiveText, l_Event, "string", "Directive text", "string", nullptr)
|
|
{
|
|
int idx;
|
|
const char* s = nullptr;
|
|
if (!ade_get_args(L, "o|s", l_Event.Get(&idx), &s))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "s", "");
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR && s != nullptr) {
|
|
mep->objective_text = s;
|
|
}
|
|
|
|
return ade_set_args(L, "s", mep->objective_text.c_str());
|
|
}
|
|
|
|
ADE_VIRTVAR(DirectiveKeypressText, l_Event, "string", "Raw directive keypress text, as seen in FRED.", "string", nullptr)
|
|
{
|
|
int idx;
|
|
const char* s = nullptr;
|
|
if (!ade_get_args(L, "o|s", l_Event.Get(&idx), &s))
|
|
return ade_set_error(L, "s", "");
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "s", "");
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR && s != nullptr) {
|
|
mep->objective_key_text = s;
|
|
}
|
|
|
|
return ade_set_args(L, "s", mep->objective_key_text.c_str());
|
|
}
|
|
|
|
ADE_VIRTVAR(Interval, l_Event, "number", "Time for event to repeat (in seconds)", "number", "Repeat time, or 0 if invalid handle")
|
|
{
|
|
int idx;
|
|
int newinterval = 0;
|
|
if (!ade_get_args(L, "o|i", l_Event.Get(&idx), &newinterval))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
mep->interval = newinterval;
|
|
}
|
|
|
|
return ade_set_args(L, "i", mep->interval);
|
|
}
|
|
|
|
ADE_VIRTVAR(ObjectCount, l_Event, "number", "Number of objects left for event", "number", "Repeat count, or 0 if invalid handle")
|
|
{
|
|
int idx;
|
|
int newobject = 0;
|
|
if (!ade_get_args(L, "o|i", l_Event.Get(&idx), &newobject))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
mep->count = newobject;
|
|
}
|
|
|
|
return ade_set_args(L, "i", mep->count);
|
|
}
|
|
|
|
ADE_VIRTVAR(RepeatCount, l_Event, "number", "Event repeat count", "number", "Repeat count, or 0 if invalid handle")
|
|
{
|
|
int idx;
|
|
int newrepeat = 0;
|
|
if (!ade_get_args(L, "o|i", l_Event.Get(&idx), &newrepeat))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
mep->repeat_count = newrepeat;
|
|
}
|
|
|
|
return ade_set_args(L, "i", mep->repeat_count);
|
|
}
|
|
|
|
ADE_VIRTVAR(Score, l_Event, "number", "Event score", "number", "Event score, or 0 if invalid handle")
|
|
{
|
|
int idx;
|
|
int newscore = 0;
|
|
if (!ade_get_args(L, "o|i", l_Event.Get(&idx), &newscore))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (idx < 0 || idx >= (int)Mission_events.size())
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
mission_event *mep = &Mission_events[idx];
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
mep->score = newscore;
|
|
}
|
|
|
|
return ade_set_args(L, "i", mep->score);
|
|
}
|
|
|
|
}
|