Skip to content

Commit

Permalink
Merge pull request #5611 from MjnMixael/force_rearm_sexp
Browse files Browse the repository at this point in the history
Force rearm sexp
  • Loading branch information
JohnAFernandez committed Nov 1, 2023
2 parents db02a82 + f2d0bfd commit 3764146
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
9 changes: 7 additions & 2 deletions code/ai/aicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12780,9 +12780,14 @@ void ai_do_repair_frame(object *objp, ai_info *aip, float frametime)
repaired = ship_do_rearm_frame( objp, frametime ); // hook to do missile rearming

// See if fully repaired. If so, cause process to stop.
if ( repaired && (repair_aip->submode == AIS_DOCK_4)) {
if ( repaired ) {

repair_aip->submode = AIS_UNDOCK_0;
// We can repair ships without being docked, so only do this if we are docked
if (repair_aip->submode == AIS_DOCK_4) {
repair_aip->submode = AIS_UNDOCK_0;
} else { // Undocking ends the repair, but since we don't need to do that in this case, end it here
ai_do_objects_repairing_stuff(objp, &Objects[support_objnum], REPAIR_INFO_END);
}
repair_aip->submode_start_time = Missiontime;

// if repairing player object -- tell him done with repair
Expand Down
77 changes: 77 additions & 0 deletions code/parse/sexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ SCP_vector<sexp_oper> Operators = {
{ "reset-time-compression", OP_CUTSCENES_RESET_TIME_COMPRESSION, 0, 0, SEXP_ACTION_OPERATOR, },
{ "call-ssm-strike", OP_CALL_SSM_STRIKE, 3, INT_MAX, SEXP_ACTION_OPERATOR, }, // X3N0-Life-Form
{ "set-gravity-accel", OP_SET_GRAVITY_ACCEL, 1, 1, SEXP_ACTION_OPERATOR, }, // Asteroth
{ "force-rearm", OP_FORCE_REARM, 1, INT_MAX, SEXP_ACTION_OPERATOR, }, // MjnMixael
{ "abort-rearm", OP_ABORT_REARM, 1, INT_MAX, SEXP_ACTION_OPERATOR, }, // MjnMixael

//Variable Category
{ "modify-variable", OP_MODIFY_VARIABLE, 2, 2, SEXP_ACTION_OPERATOR, },
Expand Down Expand Up @@ -14114,6 +14116,51 @@ void multi_sexp_set_gravity_accel()
}
}

void sexp_force_rearm(int node)
{
// This is kiiiiinda hacky. All the related repair methods expect a docker and a dockee, but
// nothing really special happens between them. It checks that they are same team and tells the docker
// to undock when repair is completed. So with minimal changes we can skip the dock stuff and just tell
// the code that the repairer is the repairee and all works as expected. Basically we simply created a
// way for a ship to 'repair itself'.

for (int n = node; n >= 0; n = CDR(n)) {

auto ship = eval_ship(n);
if (!ship || !ship->shipp)
return;

// Set flags
ai_info* aip = &Ai_info[Ships[ship->objp->instance].ai_index];
aip->support_ship_signature = ship->objp->signature;
aip->support_ship_objnum = OBJ_INDEX(ship->objp);
aip->submode_start_time = Missiontime;

// Start the HUD stuff
if (aip == Player_ai) {
hud_support_view_start();
}

// Begin the repair
ai_do_objects_repairing_stuff(ship->objp, ship->objp, REPAIR_INFO_BEGIN);
}
}

void sexp_abort_rearm(int node)
{
for (int n = node; n >= 0; n = CDR(n)) {

auto ship = eval_ship(n);
if (!ship || !ship->shipp)
return;

ai_info* aip = &Ai_info[Ships[ship->objp->instance].ai_index];

// Begin the repair
ai_do_objects_repairing_stuff(ship->objp, &Objects[aip->support_ship_objnum], REPAIR_INFO_ABORT);
}
}

// this function get called by send-message or send-message random with the name of the message, sender,
// and priority.
void sexp_send_one_message( const char *name, const char *who_from, const char *priority, int group, int delay, int event_num = -1 )
Expand Down Expand Up @@ -28873,6 +28920,16 @@ int eval_sexp(int cur_node, int referenced_node)
sexp_val = SEXP_TRUE;
break;

case OP_FORCE_REARM:
sexp_force_rearm(node);
sexp_val = SEXP_TRUE;
break;

case OP_ABORT_REARM:
sexp_abort_rearm(node);
sexp_val = SEXP_TRUE;
break;

default:{
// Check if we have a dynamic SEXP with this operator and if there is, execute that
auto dynamicSEXP = sexp::get_dynamic_sexp(op_num);
Expand Down Expand Up @@ -30123,6 +30180,8 @@ int query_operator_return_type(int op)
case OP_COPY_CONTAINER:
case OP_APPLY_CONTAINER_FILTER:
case OP_SET_GRAVITY_ACCEL:
case OP_FORCE_REARM:
case OP_ABORT_REARM:
return OPR_NULL;

case OP_AI_CHASE:
Expand Down Expand Up @@ -30424,6 +30483,8 @@ int query_operator_argument_type(int op, int argnum)
case OP_IS_FRIENDLY_STEALTH_VISIBLE:
case OP_GET_DAMAGE_CAUSED:
case OP_GET_THROTTLE_SPEED:
case OP_FORCE_REARM:
case OP_ABORT_REARM:
return OPF_SHIP;

case OP_ALTER_SHIP_FLAG:
Expand Down Expand Up @@ -35085,6 +35146,8 @@ int get_category(int op_id)
case OP_HUD_FORCE_SENSOR_STATIC:
case OP_HUD_FORCE_EMP_EFFECT:
case OP_SET_GRAVITY_ACCEL:
case OP_FORCE_REARM:
case OP_ABORT_REARM:
case OP_SET_ORDER_ALLOWED_TARGET:
case OP_ENABLE_GENERAL_ORDERS:
case OP_VALIDATE_GENERAL_ORDERS:
Expand Down Expand Up @@ -35554,6 +35617,8 @@ int get_subcategory(int op_id)
case OP_CUTSCENES_RESET_TIME_COMPRESSION:
case OP_CALL_SSM_STRIKE:
case OP_SET_GRAVITY_ACCEL:
case OP_FORCE_REARM:
case OP_ABORT_REARM:
return CHANGE_SUBCATEGORY_SPECIAL_EFFECTS;

case OP_MODIFY_VARIABLE:
Expand Down Expand Up @@ -39459,6 +39524,18 @@ SCP_vector<sexp_help_struct> Sexp_help = {
"\t1: Acceleration rate"
},

{ OP_FORCE_REARM, "force-rearm\r\n"
"\tForces a ship to instantly begin a rearm sequence as if docked to a support ship\r\n"
"\tTakes 1 or more arguments\r\n"
"\tALL: The ship to rearm\r\n"
},

{ OP_ABORT_REARM, "abort-rearm\r\n"
"\tForces a ship to instantly abort a rearm sequence\r\n"
"\tTakes 1 or more arguments\r\n"
"\tALL: The ship to abort rearm\r\n"
},

{ OP_SET_POST_EFFECT, "set-post-effect\r\n"
"\tConfigures a post-processing effect. Takes 2 arguments...\r\n"
"\t1: Effect type\r\n"
Expand Down
2 changes: 2 additions & 0 deletions code/parse/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ enum : int {
OP_HUD_FORCE_SENSOR_STATIC, // MjnMixael
OP_HUD_FORCE_EMP_EFFECT, // MjnMixael
OP_SET_GRAVITY_ACCEL, // Asteroth
OP_FORCE_REARM, // MjnMixael
OP_ABORT_REARM, // MjnMixael
OP_SET_ORDER_ALLOWED_TARGET, // MjnMixael
OP_ENABLE_GENERAL_ORDERS, // MjnMixael
OP_VALIDATE_GENERAL_ORDERS, // MjnMixael
Expand Down

0 comments on commit 3764146

Please sign in to comment.