|
36 | 36 | #include "parse/sexp/LuaAISEXP.h" |
37 | 37 | #include "parse/sexp/sexp_lookup.h" |
38 | 38 | #include "playerman/player.h" |
| 39 | +#include "prop/prop.h" |
39 | 40 | #include "scripting/api/LuaPromise.h" |
40 | 41 | #include "scripting/api/objs/LuaEnum.h" |
41 | 42 | #include "scripting/api/objs/LuaSEXP.h" |
|
57 | 58 | #include "scripting/api/objs/object.h" |
58 | 59 | #include "scripting/api/objs/parse_object.h" |
59 | 60 | #include "scripting/api/objs/promise.h" |
| 61 | +#include "scripting/api/objs/prop.h" |
| 62 | +#include "scripting/api/objs/propclass.h" |
60 | 63 | #include "scripting/api/objs/sexpvar.h" |
61 | 64 | #include "scripting/api/objs/ship_registry_entry.h" |
62 | 65 | #include "scripting/api/objs/ship.h" |
@@ -549,6 +552,43 @@ ADE_FUNC(__len, l_Mission_ParsedShips, NULL, |
549 | 552 | return ade_set_args(L, "i", static_cast<int>(Parse_objects.size())); |
550 | 553 | } |
551 | 554 |
|
| 555 | +//****SUBLIBRARY: Mission/Props |
| 556 | +ADE_LIB_DERIV(l_Mission_Props, "Props", nullptr, "Props in the mission", l_Mission); |
| 557 | + |
| 558 | +ADE_INDEXER(l_Mission_Props, "number/string IndexOrName", "Gets prop", "prop", "Prop handle, or invalid prop handle if index was invalid") |
| 559 | +{ |
| 560 | + const char* name; |
| 561 | + if(!ade_get_args(L, "*s", &name)) |
| 562 | + return ade_set_error(L, "o", l_Prop.Set(object_h())); |
| 563 | + |
| 564 | + int idx = ship_name_lookup(name); |
| 565 | + |
| 566 | + if (idx >= 0) |
| 567 | + { |
| 568 | + return ade_set_args(L, "o", l_Prop.Set(object_h(&Objects[Props[idx].objnum]))); |
| 569 | + } |
| 570 | + else |
| 571 | + { |
| 572 | + idx = atoi(name); |
| 573 | + |
| 574 | + int objnum = -1; |
| 575 | + if (idx > 0) |
| 576 | + objnum = object_subclass_at_index(Props, MAX_PROPS, idx); |
| 577 | + |
| 578 | + return ade_set_args(L, "o", l_Prop.Set(object_h(objnum))); |
| 579 | + } |
| 580 | +} |
| 581 | + |
| 582 | +ADE_FUNC(__len, l_Mission_Props, NULL, |
| 583 | + "Number of props in the mission. " |
| 584 | + "This function is somewhat slow, and should be set to a variable for use in looping situations. " |
| 585 | + "Note that props can be vanished, and so this value cannot be relied on for more than one frame.", |
| 586 | + "number", |
| 587 | + "Number of props in the mission, or 0 if props haven't been initialized yet") |
| 588 | +{ |
| 589 | + return ade_set_args(L, "i", object_subclass_count(Props, MAX_PROPS)); |
| 590 | +} |
| 591 | + |
552 | 592 | //****SUBLIBRARY: Mission/Waypoints |
553 | 593 | ADE_LIB_DERIV(l_Mission_Waypoints, "Waypoints", NULL, NULL, l_Mission); |
554 | 594 |
|
@@ -1340,6 +1380,47 @@ ADE_FUNC(createShip, |
1340 | 1380 | return ade_set_error(L, "o", l_Ship.Set(object_h())); |
1341 | 1381 | } |
1342 | 1382 |
|
| 1383 | +ADE_FUNC(createProp, |
| 1384 | + l_Mission, |
| 1385 | + "[string Name, propclass Class /* First prop class by default */, orientation Orientation=null, vector Position /* null vector by default */]", |
| 1386 | + "Creates a prop and returns a handle to it using the specified name, class, world orientation, and world position.", |
| 1387 | + "prop", |
| 1388 | + "Prop handle, or invalid prop handle if prop couldn't be created") |
| 1389 | +{ |
| 1390 | + const char* name = nullptr; |
| 1391 | + int pclass = -1; |
| 1392 | + matrix_h* orient = nullptr; |
| 1393 | + vec3d pos = vmd_zero_vector; |
| 1394 | + ade_get_args(L, "|sooo", &name, l_Propclass.Get(&pclass), l_Matrix.GetPtr(&orient), l_Vector.Get(&pos)); |
| 1395 | + |
| 1396 | + if (Prop_info.size() == 0) { |
| 1397 | + return ade_set_error(L, "o", l_Prop.Set(object_h())); |
| 1398 | + } |
| 1399 | + |
| 1400 | + matrix *real_orient = &vmd_identity_matrix; |
| 1401 | + if(orient != NULL) |
| 1402 | + { |
| 1403 | + real_orient = orient->GetMatrix(); |
| 1404 | + } |
| 1405 | + |
| 1406 | + if (pclass == -1) { |
| 1407 | + return ade_set_error(L, "o", l_Prop.Set(object_h())); |
| 1408 | + } |
| 1409 | + |
| 1410 | + int obj_idx = prop_create(real_orient, &pos, pclass, name); |
| 1411 | + |
| 1412 | + if(obj_idx >= 0) { |
| 1413 | + auto propp = &Props[Objects[obj_idx].instance]; |
| 1414 | + |
| 1415 | + prop_info* pip = &Prop_info[pclass]; |
| 1416 | + |
| 1417 | + model_page_in_textures(pip->model_num, pclass); |
| 1418 | + |
| 1419 | + return ade_set_args(L, "o", l_Prop.Set(object_h(&Objects[obj_idx]))); |
| 1420 | + } else |
| 1421 | + return ade_set_error(L, "o", l_Prop.Set(object_h())); |
| 1422 | +} |
| 1423 | + |
1343 | 1424 | ADE_FUNC(createDebris, |
1344 | 1425 | l_Mission, |
1345 | 1426 | "[ship | shipclass | model | submodel | nil source, string | nil submodel_index_or_name, vector position, orientation, enumeration create_flags, " |
|
0 commit comments