Repository navigation
Fix method passing for On Depart hook - #7911
wookieejedi wants to merge 2 commits into
Conversation
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.
dustinspace217
left a comment
There was a problem hiding this comment.
Looks good. Every caller passes a single method that ship_cleanup already handles, so the only visible change is the hook's Method string. A few small things: the bool_value assignment in ship_actually_depart is dead now and can go. Since warp and bay now report SHIP_DEPARTED_WARP and SHIP_DEPARTED_BAY, nothing emits plain SHIP_DEPARTED anymore. No script in my installed mods reads Method (loose files and packed .vp archives), but a line in the description would help, and the doc could mark 'SHIP_DEPARTED' as kept for compatibility, no longer emitted. Optional: its type there says "ship" where it's a string. A short Testing note would also help.
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.
|
I pushed one small commit with the cleanup from my review: the unused |
| 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); | ||
|
|
There was a problem hiding this comment.
This assertion isn't needed because nothing in this function depends on it, and ship_cleanup already asserts
| {"Ship", "ship", "The ship departing the mission"}, | ||
| {"JumpNode", "string", "The name of the jump node the ship was in when it departed. Can be nil."}, | ||
| {"Method", "ship", "The name of the method the ship used to depart. One of: 'SHIP_DEPARTED', 'SHIP_DEPARTED_WARP', 'SHIP_DEPARTED_BAY', 'SHIP_VANISHED', 'SHIP_DEPARTED_REDALERT'."}, | ||
| {"Method", "string", "The name of the method the ship used to depart. One of: 'SHIP_DEPARTED_WARP', 'SHIP_DEPARTED_BAY', 'SHIP_VANISHED', 'SHIP_DEPARTED_REDALERT'. Older builds sent 'SHIP_DEPARTED' for warp and bay departures; it is no longer sent."}, |
There was a problem hiding this comment.
SHIP_DEPARTED should not be deleted from the list. It was a possible value before, and it may be a possible value in the future. Script authors should still be aware of the value.
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.