Skip to content

Commit 8fb7a05

Browse files
authored
grant lua ability to force a ship to call for support (scp-fs2open#7250)
1 parent 6120f7e commit 8fb7a05

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

code/scripting/api/objs/ship.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "wing.h"
2424

2525
#include "ai/aigoals.h"
26+
#include "ai/ai.h"
2627
#include "globalincs/utility.h"
2728
#include "hud/hudets.h"
2829
#include "hud/hudshield.h"
@@ -1610,6 +1611,48 @@ ADE_FUNC(fireSecondary, l_Ship, NULL, "Fires ship secondary bank(s)", "number",
16101611
return ade_set_args(L, "i", ship_fire_secondary(objh->objp(), 0));
16111612
}
16121613

1614+
ADE_FUNC(callSupport,
1615+
l_Ship,
1616+
nullptr,
1617+
"Forces this ship to request support rearm/repair if it's a valid ship type, not docked, and support is allowed.",
1618+
"boolean",
1619+
"True if a support request was issued, false otherwise")
1620+
{
1621+
object_h* objh;
1622+
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
1623+
return ade_set_error(L, "b", false);
1624+
}
1625+
1626+
if (!objh->isValid()) {
1627+
return ade_set_error(L, "b", false);
1628+
}
1629+
1630+
auto objp = objh->objp();
1631+
auto shipp = &Ships[objp->instance];
1632+
auto aip = &Ai_info[shipp->ai_index];
1633+
auto sip = &Ship_info[shipp->ship_info_index];
1634+
1635+
if (!sip->is_fighter_bomber()) {
1636+
return ADE_RETURN_FALSE;
1637+
}
1638+
1639+
if (aip->ai_flags[AI::AI_Flags::Being_repaired, AI::AI_Flags::Awaiting_repair]) {
1640+
return ADE_RETURN_FALSE;
1641+
}
1642+
1643+
if (object_is_docked(objp)) {
1644+
return ADE_RETURN_FALSE;
1645+
}
1646+
1647+
if (!is_support_allowed(objp)) {
1648+
return ADE_RETURN_FALSE;
1649+
}
1650+
1651+
ai_issue_rearm_request(objp);
1652+
1653+
return ADE_RETURN_TRUE;
1654+
}
1655+
16131656
ADE_FUNC_DEPRECATED(getAnimationDoneTime, l_Ship, "number Type, number Subtype", "Gets time that animation will be done", "number", "Time (seconds), or 0 if ship handle is invalid",
16141657
gameversion::version(22, 0, 0, 0),
16151658
"To account for the new animation tables, please use getSubmodelAnimationTime()")

0 commit comments

Comments
 (0)