Skip to content

Commit

Permalink
Merge pull request scp-fs2open#6446 from Goober5000/docked_warpIn
Browse files Browse the repository at this point in the history
fix ship:warpIn() behavior for docked ships
  • Loading branch information
Goober5000 authored Dec 16, 2024
2 parents 1c90664 + 6bdd80b commit b7c6761
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions code/object/objectdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,15 @@ void object_remove_arriving_stage2_ndl_flag_helper(object *objp, dock_function_i
Ships[objp->instance].flags.remove(Ship::Ship_Flags::Arriving_stage_2_dock_follower);
}

void dock_find_dock_leader_helper(object *objp, dock_function_info *infop)
{
if (Ships[objp->instance].flags[Ship::Ship_Flags::Dock_leader])
{
infop->maintained_variables.objp_value = objp;
infop->early_return_condition = true;
}
}

void dock_calc_total_moi_helper(object* objp, dock_function_info* infop)
{
matrix local_moi, unorient, temp, world_moi;
Expand Down
3 changes: 3 additions & 0 deletions code/object/objectdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,7 @@ void object_remove_arriving_stage1_ndl_flag_helper(object *objp, dock_function_i
void object_set_arriving_stage2_ndl_flag_helper(object *objp, dock_function_info * /*infop*/ );
void object_remove_arriving_stage2_ndl_flag_helper(object *objp, dock_function_info * /*infop*/ );

// find any ship in this group that is the dock leader
void dock_find_dock_leader_helper(object *objp, dock_function_info *infop);

#endif // _OBJECT_DOCK_H
11 changes: 11 additions & 0 deletions code/scripting/api/objs/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,17 @@ ADE_FUNC(warpIn, l_Ship, NULL, "Warps ship in", "boolean", "True if successful,
if(!objh->isValid())
return ADE_RETURN_NIL;

if (object_is_docked(objh->objp()))
{
// Ships that are docked need a designated dock leader to bring the entire group in. The dock leader is, de facto, the arriving ship;
// so by scripting a certain ship to warp in, the script author has designated it as the leader. That being said, if the script
// calls warpIn() multiple times on the same docked group, only set the flag on the first ship.
dock_function_info dfi;
dock_evaluate_all_docked_objects(objh->objp(), &dfi, dock_find_dock_leader_helper);
if (!dfi.maintained_variables.objp_value)
Ships[objh->objp()->instance].flags.set(Ship::Ship_Flags::Dock_leader);
}

shipfx_warpin_start(objh->objp());

return ADE_RETURN_TRUE;
Expand Down
4 changes: 2 additions & 2 deletions code/ship/shipfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,11 @@ void shipfx_actually_warpin(ship *shipp, object *objp)

// dock leader needs to handle dockees
if (object_is_docked(objp)) {
Assertion(shipp->flags[Ship::Ship_Flags::Dock_leader], "The docked ship warping in (%s) should only be the dock leader at this point!\n", shipp->ship_name);
Assertion(shipp->flags[Ship::Ship_Flags::Dock_leader], "The docked ship warping in (%s) should be the dock leader at this point!\n", shipp->ship_name);
dock_function_info dfi;
dock_evaluate_all_docked_objects(objp, &dfi, object_remove_arriving_stage1_ndl_flag_helper);
dock_evaluate_all_docked_objects(objp, &dfi, object_remove_arriving_stage2_ndl_flag_helper);
shipp->flags.remove(Ship::Ship_Flags::Dock_leader); // the dock leader flag is only used for arrival and could interfere with future scripted warpIn() calls
}

// let physics in on it too.
Expand Down Expand Up @@ -527,7 +528,6 @@ void shipfx_warpin_start( object *objp )
if (shipp->is_arriving())
{
mprintf(( "Ship '%s' is already arriving!\n", shipp->ship_name ));
Int3();
return;
}

Expand Down

0 comments on commit b7c6761

Please sign in to comment.