You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add several API features to improve scripting support for subsystems.
1. A `CanonicalName` virtvar to provide a clear way to get subsystem names for indexing and referencing
2. `Submodel` and `SubmodelInstance` virtvars to get the submodel information associated with the subsystem, if it exists
3. A `getSubsystemList()` function to provide a subsystem iterator
ADE_FUNC(__eq, l_Model, "model, model", "Checks if two model handles refer to the same model", "boolean", "True if models are equal")
67
+
{
68
+
model_h* mdl1;
69
+
model_h* mdl2;
70
+
71
+
if (!ade_get_args(L, "oo", l_Model.GetPtr(&mdl1), l_Model.GetPtr(&mdl2)))
72
+
returnADE_RETURN_NIL;
73
+
74
+
if (mdl1->GetID() == mdl2->GetID())
75
+
returnADE_RETURN_TRUE;
76
+
77
+
returnADE_RETURN_FALSE;
78
+
}
79
+
80
+
ADE_FUNC(__eq, l_Submodel, "submodel, submodel", "Checks if two submodel handles refer to the same submodel", "boolean", "True if submodels are equal")
81
+
{
82
+
submodel_h* smh1;
83
+
submodel_h* smh2;
84
+
85
+
if (!ade_get_args(L, "oo", l_Submodel.GetPtr(&smh1), l_Submodel.GetPtr(&smh2)))
86
+
returnADE_RETURN_NIL;
87
+
88
+
if (smh1->GetModelID() == smh2->GetModelID() && smh1->GetSubmodelIndex() == smh2->GetSubmodelIndex())
89
+
returnADE_RETURN_TRUE;
90
+
91
+
returnADE_RETURN_FALSE;
92
+
}
93
+
66
94
ADE_VIRTVAR(Submodels, l_Model, nullptr, "Model submodels", "submodels", "Model submodels, or an invalid submodels handle if the model handle is invalid")
//Since the first element of a list is the next element from the head, and we start this function with the captured "ss" object being the head, this GET_NEXT will return the first element on first call of this lambda.
116
+
//Similarly, an empty list is defined by the head's next element being itself, hence an empty list will immediately return nil just fine
117
+
ss = GET_NEXT(ss);
118
+
119
+
if (ss == END_OF_LIST(&shipp->subsys_list) || ss == nullptr) {
ADE_FUNC(setFlag, l_Ship, "boolean set_it, string flag_name", "Sets or clears one or more flags - this function can accept an arbitrary number of flag arguments. The flag names can be any string that the alter-ship-flag SEXP operator supports.", nullptr, "Returns nothing")
ADE_VIRTVAR(Submodel, l_Subsystem, "submodel", "The submodel corresponding to this subsystem, if one exists", "submodel", "Submodel handle, or invalid submodel handle if this subsystem does not have a submodel, or if the subsystem handle is invalid")
127
+
{
128
+
ship_subsys_h *sso;
129
+
if (!ade_get_args(L, "o", l_Subsystem.GetPtr(&sso)))
ADE_VIRTVAR(SubmodelInstance, l_Subsystem, "submodel_instance", "The submodel instance corresponding to this subsystem, if one exists", "submodel_instance", "Submodel instance handle, or invalid submodel instance handle if this subsystem does not have a submodel instance, or if the subsystem handle is invalid")
142
+
{
143
+
ship_subsys_h *sso;
144
+
if (!ade_get_args(L, "o", l_Subsystem.GetPtr(&sso)))
ADE_VIRTVAR(Orientation, l_Subsystem, "orientation", "Orientation of subobject or turret base", "orientation", "Subsystem orientation, or identity orientation if handle is invalid")
125
159
{
126
160
ship_subsys_h *sso;
@@ -345,6 +379,22 @@ ADE_VIRTVAR(NameOnHUD, l_Subsystem, "string", "Subsystem name as it would be dis
ADE_VIRTVAR(CanonicalName, l_Subsystem, "string", "Canonical subsystem name that can be used to reference this subsystem in a SEXP or script", "string", "Canonical subsystem name, or an empty string if handle is invalid")
383
+
{
384
+
ship_subsys_h *sso;
385
+
386
+
if (!ade_get_args(L, "o", l_Subsystem.GetPtr(&sso)))
387
+
returnade_set_error(L, "s", "");
388
+
389
+
if (!sso->isValid())
390
+
returnade_set_error(L, "s", "");
391
+
392
+
if (ADE_SETTING_VAR)
393
+
LuaError(L, "Setting the CanonicalName is not allowed!");
ADE_VIRTVAR(NumFirePoints, l_Subsystem, "number", "Number of firepoints", "number", "Number of fire points, or 0 if handle is invalid")
349
399
{
350
400
ship_subsys_h* sso;
@@ -384,7 +434,7 @@ ADE_VIRTVAR(FireRateMultiplier, l_Subsystem, "number", "Factor by which turret's
384
434
returnade_set_args(L, "f", sso->ss->rof_scaler);
385
435
}
386
436
387
-
ADE_FUNC(getModelName, l_Subsystem, NULL, "Returns the original name of the subsystem in the model file", "string", "name or empty string on error")
437
+
ADE_FUNC(getModelName, l_Subsystem, nullptr, "Returns the original name of the subsystem as defined in the ship class, which could possibly correspond to a submodel in the model file. This is the same as CanonicalName.", "string", "name or empty string on error")
ADE_VIRTVAR(PrimaryBanks, l_Subsystem, "weaponbanktype", "Array of primary weapon banks", "weaponbanktype", "Primary banks, or invalid weaponbanktype handle if subsystem handle is invalid")
0 commit comments