From 7688e65c6364fe46e8c23435d0f90c5e3ec8fb5d Mon Sep 17 00:00:00 2001 From: wookieejedi Date: Mon, 19 Oct 2026 13:07:58 -0400 Subject: [PATCH 1/2] Fix method passing for On Depart hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ship_actually_depart_helper throws away the departure method — it only forwards a bool: // ship.cpp:8940 dfi.parameter_variables.bool_value = (method == SHIP_VANISHED ? true:false); // ship.cpp:8930 ship_cleanup(objp->instance, infop->parameter_variables.bool_value ? SHIP_VANISHED : SHIP_DEPARTED); So SHIP_DEPARTED_WARP and SHIP_DEPARTED_BAY are flattened to SHIP_DEPARTED before ship_cleanup ever sees them. Consequences: OnShipDepart’s Method param can only ever be SHIP_DEPARTED, SHIP_VANISHED, or SHIP_DEPARTED_REDALERT, even though global_hooks.cpp:356 documents SHIP_DEPARTED_WARP and SHIP_DEPARTED_BAY as possible values — those two are unreachable. Ship_registry[].cleanup_mode loses the distinction too. The fix is to carry method through dock_function_info instead of the bool. --- code/ship/ship.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index 21f148802b5..a52304cae11 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -8927,7 +8927,7 @@ static void ship_actually_depart_helper(object *objp, dock_function_info *infop) // do standard departure stuff first objp->flags.set(Object::Object_Flags::Should_be_dead); if (objp->type == OBJ_SHIP) - ship_cleanup(objp->instance, infop->parameter_variables.bool_value ? SHIP_VANISHED : SHIP_DEPARTED); + ship_cleanup(objp->instance, infop->parameter_variables.int_value); // do the end-mission stuff if it's the player ship if (objp == Player_obj) @@ -8939,8 +8939,13 @@ static void ship_actually_depart_helper(object *objp, dock_function_info *infop) */ void ship_actually_depart(int shipnum, int method) { + Assertion(method & (SHIP_DEPARTED | SHIP_VANISHED | SHIP_DEPARTED_REDALERT), + "Invalid departure method '%i' passed to ship_actually_depart for ship %s!", method, Ships[shipnum].ship_name); + dock_function_info dfi; dfi.parameter_variables.bool_value = (method == SHIP_VANISHED ? true:false); + dfi.parameter_variables.int_value = method; + dock_evaluate_all_docked_objects(&Objects[Ships[shipnum].objnum], &dfi, ship_actually_depart_helper); // in a couple of cases we'll need to send a packet to update clients From 9448a0422be92b0705163874777e932d60b65e5a Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Tue, 17 Nov 2026 19:27:23 -0800 Subject: [PATCH 2/2] Drop the unused departure flag and correct the On Ship Depart docs ship_actually_depart_helper now reads the method from int_value, so the bool_value assignment is unused. The hook's Method parameter is a string, and warp and bay departures now report their own method instead of SHIP_DEPARTED. --- code/scripting/global_hooks.cpp | 2 +- code/ship/ship.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/code/scripting/global_hooks.cpp b/code/scripting/global_hooks.cpp index 2a6ee23bf9f..a796168f1db 100644 --- a/code/scripting/global_hooks.cpp +++ b/code/scripting/global_hooks.cpp @@ -353,7 +353,7 @@ const std::shared_ptr> OnShipDepart = Hook> OnWeaponDelete = Hook::Factory("On Weapon Delete", diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index a52304cae11..733b6bb35ab 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -8943,7 +8943,6 @@ void ship_actually_depart(int shipnum, int method) "Invalid departure method '%i' passed to ship_actually_depart for ship %s!", method, Ships[shipnum].ship_name); dock_function_info dfi; - dfi.parameter_variables.bool_value = (method == SHIP_VANISHED ? true:false); dfi.parameter_variables.int_value = method; dock_evaluate_all_docked_objects(&Objects[Ships[shipnum].objnum], &dfi, ship_actually_depart_helper);