Files
Mike NelsonandAsteroth 070a8e18fa Adds Props as a new object type (#6836)
* First draft of prop object type

* Add prop editor dialog in FRED

* prop sexps

* lua table prop support

* lab support

* lua mission access to props

* prop collision support

* use std::optional so the object->instance id is always valid

* allow props to block suns

* minor cleanup and remove arbitrary limit. Still limited to 500 objects.

* Sort props by category

* cleanup

* implement collision hooks

* parse prop flags and further ensure props are inited and closed correctly

* Add Cyborg's multi suggestions

* fix missing header

* add props to empty slots if available

* add multi signature

* fix rebase issues and match collisions to the new multithread style

* appease Clang the Conquerer

* save/parse mission prop classes by name

* Clean up comments and finish TODOs

* fix string errors

* clang wants this to be static now

* address feedback

* address feedback

* Use model num from prop info instead

* merge prop and ship collision group sexps together

* fix rebase bug

* address feedback

* fix name shadowing

* ship heavy submodel

* clang

---------

Co-authored-by: Asteroth <[email protected]>
2026-02-16 14:41:34 +01:00

98 lines
2.4 KiB
C++

//
//
#include "globalincs/utility.h"
#include "modelinstance.h"
#include "object.h"
#include "prop.h"
#include "propclass.h"
#include "prop/prop.h"
namespace scripting::api {
//**********HANDLE: Prop
ADE_OBJ_DERIV(l_Prop, object_h, "prop", "Prop handle", l_Object);
ADE_VIRTVAR(Name,
l_Prop,
"string",
"Prop name. This is the actual name of the prop.",
"string",
"Prop name, or empty string if handle is invalid")
{
object_h* objh;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Prop.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if (!objh->isValid())
return ade_set_error(L, "s", "");
prop* propp = prop_id_lookup(objh->objp()->instance);
if (ADE_SETTING_VAR && s != nullptr) {
auto len = sizeof(propp->prop_name);
strncpy(propp->prop_name, s, len);
propp->prop_name[len - 1] = 0;
}
return ade_set_args(L, "s", propp->prop_name);
}
ADE_VIRTVAR(Class,
l_Prop,
"propclass",
"Prop class",
"propclass",
"Prop class, or invalid propclass handle if prop handle is invalid")
{
object_h* objh;
int idx = -1;
if (!ade_get_args(L, "o|o", l_Prop.GetPtr(&objh), l_Propclass.Get(&idx)))
return ade_set_error(L, "o", l_Propclass.Set(-1));
if (!objh->isValid())
return ade_set_error(L, "o", l_Propclass.Set(-1));
prop* propp = prop_id_lookup(objh->objp()->instance);
if (ADE_SETTING_VAR && SCP_vector_inbounds(Prop_info, idx)) {
change_prop_type(objh->objp()->instance, idx);
}
if (propp->prop_info_index < 0)
return ade_set_error(L, "o", l_Propclass.Set(-1));
return ade_set_args(L, "o", l_Propclass.Set(propp->prop_info_index));
}
ADE_VIRTVAR(Textures,
l_Prop,
"modelinstancetextures",
"Gets prop textures",
"modelinstancetextures",
"Prop textures, or invalid proptextures handle if prop handle is invalid")
{
object_h* sh = nullptr;
object_h* dh;
if (!ade_get_args(L, "o|o", l_Prop.GetPtr(&dh), l_Prop.GetPtr(&sh)))
return ade_set_error(L, "o", l_ModelInstanceTextures.Set(modelinstance_h()));
if (!dh->isValid())
return ade_set_error(L, "o", l_ModelInstanceTextures.Set(modelinstance_h()));
prop* propp = prop_id_lookup(dh->objp()->instance);
polymodel_instance* dest = model_get_instance(propp->model_instance_num);
if (ADE_SETTING_VAR && sh && sh->isValid()) {
dest->texture_replace = model_get_instance(propp->model_instance_num)->texture_replace;
}
return ade_set_args(L, "o", l_ModelInstanceTextures.Set(modelinstance_h(dest)));
}
} // namespace scripting::api