diff --git a/code/__HELPERS/mobs.dm b/code/__HELPERS/mobs.dm
index 252ed732ca4..06f5da9acea 100644
--- a/code/__HELPERS/mobs.dm
+++ b/code/__HELPERS/mobs.dm
@@ -246,10 +246,18 @@ GLOBAL_LIST_INIT(skin_tone_names, list(
var/endtime = world.time + delay
var/starttime = world.time
+ var/dilation_tick = world.time // VOIDCREW EDIT ADDITION - cyberware time dilation
. = TRUE
while (world.time < endtime)
stoplag(1)
+ // VOIDCREW EDIT ADDITION START - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): a slowed body works slower, a frozen one not at all
+ var/dilation_lost = cyberware_time_lost(user, world.time - dilation_tick)
+ dilation_tick = world.time
+ endtime += dilation_lost
+ starttime += dilation_lost
+ // VOIDCREW EDIT ADDITION END
+
if(!QDELETED(progbar))
progbar.update(world.time - starttime)
diff --git a/code/datums/components/ranged_attacks.dm b/code/datums/components/ranged_attacks.dm
index b998362cfc6..787c3b0b527 100644
--- a/code/datums/components/ranged_attacks.dm
+++ b/code/datums/components/ranged_attacks.dm
@@ -66,8 +66,12 @@
INVOKE_ASYNC(src, PROC_REF(async_fire_ranged_attack), firer, target, modifiers)
if(isnull(burst_shots))
return
+ // VOIDCREW EDIT CHANGE START - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): each burst shot waits for the mob's own clock, so a slowed mob's burst slows down too
+ cyberware_burst_start = cyberware_burst_clock(firer)
for(var/i in 1 to (burst_shots - 1))
- addtimer(CALLBACK(src, PROC_REF(async_fire_ranged_attack), firer, target, modifiers), i * burst_intervals)
+ addtimer(CALLBACK(src, PROC_REF(cyberware_burst_shot), firer, target, modifiers, i), i * burst_intervals)
+ // ORIGINAL: addtimer(CALLBACK(src, PROC_REF(async_fire_ranged_attack), firer, target, modifiers), i * burst_intervals)
+ // VOIDCREW EDIT CHANGE END
/// Actually fire the damn thing
/datum/component/ranged_attacks/proc/async_fire_ranged_attack(mob/living/basic/firer, atom/target, modifiers)
diff --git a/code/game/objects/items/grenades/_grenade.dm b/code/game/objects/items/grenades/_grenade.dm
index 262a493cc75..dc7317e696c 100644
--- a/code/game/objects/items/grenades/_grenade.dm
+++ b/code/game/objects/items/grenades/_grenade.dm
@@ -166,7 +166,7 @@
active = TRUE
icon_state = (base_icon_state || initial(icon_state)) + "_active"
SEND_SIGNAL(src, COMSIG_GRENADE_ARMED, det_time, delayoverride)
- addtimer(CALLBACK(src, PROC_REF(detonate)), isnull(delayoverride)? det_time : delayoverride)
+ addtimer(CALLBACK(src, PROC_REF(cyberware_fuse_done)), isnull(delayoverride)? det_time : delayoverride) // VOIDCREW EDIT CHANGE - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): the fuse burns slow in a slowed field. ORIGINAL: addtimer(CALLBACK(src, PROC_REF(detonate)), isnull(delayoverride)? det_time : delayoverride)
/**
* detonate (formerly prime) refers to when the grenade actually delivers its payload (whether or not a boom/bang/detonation is involved)
diff --git a/code/game/sound/sound.dm b/code/game/sound/sound.dm
index 60452addb21..459ddcf5ec3 100644
--- a/code/game/sound/sound.dm
+++ b/code/game/sound/sound.dm
@@ -31,6 +31,12 @@
var/turf/turf_source = get_turf(source)
if (!turf_source)
return
+ // VOIDCREW EDIT ADDITION START - cyberware: a Sandevistan slow-mo keeps its sounds for its replay, and a replay's start sound goes to its viewers from their views (voidcrew/modules/cyberware/ware_sandy_replay.dm)
+ if(length(GLOB.sandy_replays))
+ var/list/sandy_heard = sandy_replay_hear(turf_source, soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference)
+ if(sandy_heard)
+ return sandy_heard
+ // VOIDCREW EDIT ADDITION END
//allocate a channel if necessary now so its the same for everyone
channel = channel || SSsounds.random_available_channel()
@@ -200,6 +206,14 @@
if(HAS_TRAIT(src, TRAIT_SOUND_DEBUGGED))
to_chat(src, span_admin("Max Range-[max_distance] Distance-[distance] Vol-[round(sound_to_use.volume, 0.01)] Sound-[sound_to_use.file]"))
+ // VOIDCREW EDIT CHANGE START - cyberware: a Sandevistan user hears the slowed world slowed (voidcrew/modules/cyberware/ware_sandy_senses.dm)
+ if(length(GLOB.cyberware_time_fields))
+ var/sandy_frequency = sound_to_use.frequency
+ cyberware_dilate_heard(src, turf_source, sound_to_use, usr)
+ SEND_SOUND(src, sound_to_use)
+ sound_to_use.frequency = sandy_frequency // the datum can be shared with the next listener
+ return
+ // VOIDCREW EDIT CHANGE END
SEND_SOUND(src, sound_to_use)
/proc/sound_to_playing_players(soundin, volume = 100, vary = FALSE, frequency = 0, channel = 0, pressure_affected = FALSE, sound/S)
diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm
index 78941bbe241..741c7164b05 100644
--- a/code/modules/projectiles/gun.dm
+++ b/code/modules/projectiles/gun.dm
@@ -380,7 +380,7 @@
// VOIDCREW EDIT ADDITION START: a point-blank head shot at someone helpless is an execution (voidcrew/modules/hyperviolence/overlays_exec/executions.dm)
if(flag && hv_try_head_execution(user, target, params))
- return
+ return TRUE // handled: without this the click fell through to a gun-bash on the body once the execution was over
// VOIDCREW EDIT ADDITION END
if(!can_shoot()) //Just because you can pull the trigger doesn't mean it can shoot.
@@ -448,6 +448,12 @@
if(!user || !firing_burst)
firing_burst = FALSE
return FALSE
+ // VOIDCREW EDIT ADDITION START - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): each burst shot waits for the shooter's own clock, so a burst slows or stops with them
+ var/dilation_wait = cyberware_burst_wait(user, cyberware_burst_start, cyberware_burst_gap, iteration - 1)
+ if(dilation_wait > 0)
+ addtimer(CALLBACK(src, PROC_REF(process_burst), user, target, message, params, zone_override, random_spread, burst_spread_mult, iteration), dilation_wait)
+ return TRUE
+ // VOIDCREW EDIT ADDITION END
if(!issilicon(user))
if(iteration > 1 && !(user.is_holding(src))) //for burst firing
firing_burst = FALSE
@@ -517,6 +523,11 @@
if(user && HAS_TRAIT(user, TRAIT_DOUBLE_TAP))
modified_burst_delay = ROUND_UP(burst_delay * 0.5)
modified_fire_delay = ROUND_UP(fire_delay * 0.5)
+ // VOIDCREW EDIT ADDITION START - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): a slowed shooter's gun cycles slowly too
+ cyberware_burst_start = cyberware_burst_clock(user)
+ cyberware_burst_gap = modified_burst_delay
+ modified_fire_delay = cyberware_dilated_time(user, modified_fire_delay)
+ // VOIDCREW EDIT ADDITION END
if(burst_size > 1)
firing_burst = TRUE
diff --git a/code/modules/vehicles/mecha/_mecha.dm b/code/modules/vehicles/mecha/_mecha.dm
index 4c9cc36adb4..b2e64b15edf 100644
--- a/code/modules/vehicles/mecha/_mecha.dm
+++ b/code/modules/vehicles/mecha/_mecha.dm
@@ -708,7 +708,7 @@
SEND_SIGNAL(user, COMSIG_MOB_USED_CLICK_MECH_MELEE, src)
if(target.mech_melee_attack(src, user))
- TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MELEE_ATTACK, melee_cooldown)
+ TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MELEE_ATTACK, cyberware_dilated_time(src, melee_cooldown)) // VOIDCREW EDIT CHANGE - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm). ORIGINAL: TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MELEE_ATTACK, melee_cooldown)
/// Driver alt clicks anything while in mech
/obj/vehicle/sealed/mecha/proc/on_click_alt(mob/user, atom/target, params)
diff --git a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
index c03240b4a66..223f5d09c50 100644
--- a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
+++ b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
@@ -114,7 +114,7 @@
return TRUE
/obj/item/mecha_parts/mecha_equipment/proc/action(mob/source, atom/target, list/modifiers)
- TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT(type), equip_cooldown)//Cooldown is on the MECH so people dont bypass it by switching equipment
+ TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT(type), cyberware_dilated_time(chassis, equip_cooldown)) // VOIDCREW EDIT CHANGE - cyberware time dilation (voidcrew/modules/cyberware/ware_sandy_timestop.dm): a slowed mech's weapons cycle slowly. ORIGINAL: TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT(type), equip_cooldown)//Cooldown is on the MECH so people dont bypass it by switching equipment
SEND_SIGNAL(source, COMSIG_MOB_USED_MECH_EQUIPMENT, chassis)
chassis.use_energy(energy_drain)
return TRUE
diff --git a/tgstation.dme b/tgstation.dme
index edc62458eea..d7632a15eee 100644
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -6750,6 +6750,7 @@
#include "voidcrew\_DEFINES\subsystems.dm"
#include "voidcrew\_DEFINES\techweb_nodes.dm"
#include "voidcrew\_DEFINES\trade.dm"
+#include "voidcrew\_DEFINES\tutorials.dm"
#include "voidcrew\_HELPERS\data_huds.dm"
#include "voidcrew\_HELPERS\debug_atmos.dm"
#include "voidcrew\_HELPERS\docking.dm"
@@ -7236,6 +7237,12 @@
#include "voidcrew\modules\cyberware\ware_pro_combat.dm"
#include "voidcrew\modules\cyberware\ware_pro_utility.dm"
#include "voidcrew\modules\cyberware\ware_registry.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_replay.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_senses.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_sound.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_timestop.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_timestop_cover.dm"
+#include "voidcrew\modules\cyberware\ware_sandy_timestop_shared.dm"
#include "voidcrew\modules\cyberware\ware_second_wind.dm"
#include "voidcrew\modules\cyberware\ware_street.dm"
#include "voidcrew\modules\cyberware\ware_street_passives.dm"
@@ -7337,6 +7344,7 @@
#include "voidcrew\modules\hyperviolence\visuals\_motion_core.dm"
#include "voidcrew\modules\hyperviolence\visuals\blood_motion.dm"
#include "voidcrew\modules\hyperviolence\visuals\death_falls.dm"
+#include "voidcrew\modules\hyperviolence\visuals\execution_aim.dm"
#include "voidcrew\modules\hyperviolence\visuals\execution_motion.dm"
#include "voidcrew\modules\hyperviolence\visuals\finisher_motion.dm"
#include "voidcrew\modules\hyperviolence\visuals\flying_gore.dm"
@@ -7578,7 +7586,6 @@
#include "voidcrew\modules\npc_ships\code\subtrees\combat_subtree.dm"
#include "voidcrew\modules\npc_ships\code\subtrees\movement_subtree.dm"
#include "voidcrew\modules\onboarding\first_time_notice.dm"
-#include "voidcrew\modules\onboarding\orientation.dm"
#include "voidcrew\modules\onboarding\zone_advisory.dm"
#include "voidcrew\modules\outfits\corporate.dm"
#include "voidcrew\modules\outfits\misc.dm"
@@ -7907,6 +7914,27 @@
#include "voidcrew\modules\trade\favor_uniques\outfitter.dm"
#include "voidcrew\modules\trade\favor_uniques\pike.dm"
#include "voidcrew\modules\trade\favor_uniques\vex.dm"
+#include "voidcrew\modules\tutorials\hooks_chrome_finisher.dm"
+#include "voidcrew\modules\tutorials\hooks_contract.dm"
+#include "voidcrew\modules\tutorials\hooks_medical.dm"
+#include "voidcrew\modules\tutorials\hooks_pirates.dm"
+#include "voidcrew\modules\tutorials\hooks_power.dm"
+#include "voidcrew\modules\tutorials\hooks_repair_drones.dm"
+#include "voidcrew\modules\tutorials\hooks_research.dm"
+#include "voidcrew\modules\tutorials\hooks_ship.dm"
+#include "voidcrew\modules\tutorials\hooks_ship_combat.dm"
+#include "voidcrew\modules\tutorials\hooks_ship_save.dm"
+#include "voidcrew\modules\tutorials\hooks_storage.dm"
+#include "voidcrew\modules\tutorials\hooks_trade.dm"
+#include "voidcrew\modules\tutorials\hooks_vestige.dm"
+#include "voidcrew\modules\tutorials\hooks_world.dm"
+#include "voidcrew\modules\tutorials\hooks_zones.dm"
+#include "voidcrew\modules\tutorials\preferences.dm"
+#include "voidcrew\modules\tutorials\tutorial_catalog.dm"
+#include "voidcrew\modules\tutorials\tutorial_highlights.dm"
+#include "voidcrew\modules\tutorials\tutorial_panel.dm"
+#include "voidcrew\modules\tutorials\tutorial_progress.dm"
+#include "voidcrew\modules\tutorials\tutorial_ship_hud.dm"
#include "voidcrew\modules\transporter\_transporter.dm"
#include "voidcrew\modules\transporter\transporter_console.dm"
#include "voidcrew\modules\transporter\transporter_designs.dm"
diff --git a/tgui/packages/tgui/interfaces/Autolathe.tsx b/tgui/packages/tgui/interfaces/Autolathe.tsx
index a9e2f1720e5..2139b90d1cb 100644
--- a/tgui/packages/tgui/interfaces/Autolathe.tsx
+++ b/tgui/packages/tgui/interfaces/Autolathe.tsx
@@ -12,6 +12,7 @@ import {
import { type BooleanLike, classes } from 'tgui-core/react';
import { capitalize } from 'tgui-core/string';
+import { TutorialFocus } from '../../voidcrew_tgui/components/TutorialFocus'; // VOIDCREW EDIT ADDITION
import { useBackend } from '../backend';
import { Window } from '../layouts';
import { DesignBrowser } from './Fabrication/DesignBrowser';
@@ -221,7 +222,8 @@ const AutolatheRecipe = (props: AutolatheRecipeProps) => {
maxmult = Math.min(Math.floor(maxmult), 50);
const canPrint = maxmult > 0;
- return (
+ // VOIDCREW EDIT CHANGE: was `return (`, wrapped below
+ const recipe = (
);
+
+ // VOIDCREW EDIT ADDITION: the tutorial checklist outlines the design it points at.
+ return {recipe} ;
};
diff --git a/tgui/packages/tgui/interfaces/Fabrication/DesignBrowser.tsx b/tgui/packages/tgui/interfaces/Fabrication/DesignBrowser.tsx
index ace3da2d709..b8076931f9b 100644
--- a/tgui/packages/tgui/interfaces/Fabrication/DesignBrowser.tsx
+++ b/tgui/packages/tgui/interfaces/Fabrication/DesignBrowser.tsx
@@ -9,7 +9,8 @@ import {
} from 'tgui-core/components';
import { classes } from 'tgui-core/react';
-import { useSharedState } from '../../backend';
+import { useBackend, useSharedState } from '../../backend'; // VOIDCREW EDIT CHANGE: useBackend
+import { TutorialFocus } from '../../../voidcrew_tgui/components/TutorialFocus'; // VOIDCREW EDIT ADDITION
import { SearchBar } from '../common/SearchBar';
import type { Design, MaterialMap } from './Types';
@@ -355,7 +356,22 @@ const DesignBrowserTab = (
depth ??= 0;
maxDepth ??= 3;
- return (
+ // VOIDCREW EDIT ADDITION START - the tutorial checklist pulses the top-level tab holding
+ // the circuit imprinter or autolathe design it points at (imprinter_,
+ // autolathe_).
+ const tutorialFocus =
+ useBackend<{ tutorial_focus?: string | null }>().data?.tutorial_focus || '';
+ const focusDesign =
+ /^(imprinter|autolathe)_(.+)$/.exec(tutorialFocus)?.[2] ?? '';
+ const tabFocused =
+ depth === 0 &&
+ !!focusDesign &&
+ selectedCategory !== category.title &&
+ !!category.descendants[focusDesign];
+ // VOIDCREW EDIT ADDITION END
+
+ // VOIDCREW EDIT CHANGE: was `return (`, wrapped below
+ const tab = (
(
)}
);
+ // VOIDCREW EDIT ADDITION START - the tutorial checklist pulses this tab
+ return (
+ {tab}
+ );
+ // VOIDCREW EDIT ADDITION END
};
type CategoryViewProps = {
diff --git a/tgui/packages/tgui/interfaces/Fabricator.tsx b/tgui/packages/tgui/interfaces/Fabricator.tsx
index 5f611e61fe0..e35120b5959 100644
--- a/tgui/packages/tgui/interfaces/Fabricator.tsx
+++ b/tgui/packages/tgui/interfaces/Fabricator.tsx
@@ -9,6 +9,7 @@ import {
} from 'tgui-core/components';
import { classes } from 'tgui-core/react';
+import { TutorialFocus } from '../../voidcrew_tgui/components/TutorialFocus'; // VOIDCREW EDIT ADDITION
import { useBackend } from '../backend';
import { Window } from '../layouts';
import { DesignBrowser } from './Fabrication/DesignBrowser';
@@ -161,7 +162,8 @@ const Recipe = (props: RecipeProps) => {
!available[material] || amount > (available[material] ?? 0),
);
- return (
+ // VOIDCREW EDIT CHANGE: was `return (`, wrapped below
+ const recipe = (
{
);
+ // VOIDCREW EDIT ADDITION START - the tutorial checklist outlines the design it points at
+ return (
+ {recipe}
+ );
+ // VOIDCREW EDIT ADDITION END
};
diff --git a/tgui/packages/tgui/interfaces/SurgeryInitiator.tsx b/tgui/packages/tgui/interfaces/SurgeryInitiator.tsx
index 73acf3e3798..7cde3233647 100644
--- a/tgui/packages/tgui/interfaces/SurgeryInitiator.tsx
+++ b/tgui/packages/tgui/interfaces/SurgeryInitiator.tsx
@@ -4,6 +4,7 @@ import { Button, KeyListener, Stack } from 'tgui-core/components';
import { KEY_DOWN, KEY_ENTER, KEY_UP } from 'tgui-core/keycodes';
import type { BooleanLike } from 'tgui-core/react';
+import { TutorialFocus } from '../../voidcrew_tgui/components/TutorialFocus'; // VOIDCREW EDIT ADDITION: tutorial checklist
import { useBackend } from '../backend';
import { Window } from '../layouts';
import { type BodyZone, BodyZoneSelector } from './common/BodyZoneSelector';
@@ -11,6 +12,7 @@ import { type BodyZone, BodyZoneSelector } from './common/BodyZoneSelector';
type Surgery = {
name: string;
blocked?: BooleanLike;
+ tutorial_id?: string; // VOIDCREW EDIT ADDITION: tutorial checklist
};
type SurgeryInitiatorData = {
@@ -77,33 +79,43 @@ class SurgeryInitiatorInner extends Component<
-
- act('change_zone', { new_zone: zone })}
- selectedZone={selected_zone}
- />
-
+ {/* VOIDCREW EDIT CHANGE START: tutorial checklist focus (voidcrew/modules/tutorials) */}
+
+
+ act('change_zone', { new_zone: zone })}
+ selectedZone={selected_zone}
+ />
+
+
+ {/* VOIDCREW EDIT CHANGE END */}
+ {/* VOIDCREW EDIT CHANGE START: tutorial checklist focus */}
{surgeries.map((surgery, index) => (
- {
- act('start_surgery', {
- surgery_name: surgery.name,
- });
- }}
- disabled={surgery.blocked}
- selected={index === this.state.selectedSurgeryIndex}
- tooltip={
- surgery.blocked ? 'Their body is covered!' : undefined
- }
+
- {surgery.name}
-
+ {
+ act('start_surgery', {
+ surgery_name: surgery.name,
+ });
+ }}
+ disabled={surgery.blocked}
+ selected={index === this.state.selectedSurgeryIndex}
+ tooltip={
+ surgery.blocked ? 'Their body is covered!' : undefined
+ }
+ fluid
+ >
+ {surgery.name}
+
+
))}
+ {/* VOIDCREW EDIT CHANGE END */}
diff --git a/tgui/packages/voidcrew_tgui/components/TutorialFocus.tsx b/tgui/packages/voidcrew_tgui/components/TutorialFocus.tsx
new file mode 100644
index 00000000000..8c77a8072a2
--- /dev/null
+++ b/tgui/packages/voidcrew_tgui/components/TutorialFocus.tsx
@@ -0,0 +1,42 @@
+/**
+ * Pulses a gold outline around one element while the tutorial checklist points at it.
+ *
+ * The window's ui_data sends `tutorial_focus` from `tutorial_ui_focus(user, "")`
+ * (voidcrew/modules/tutorials/tutorial_highlights.dm). Wrap each element a step can point
+ * at, giving it the focus key from that step's `ui_focus`:
+ *
+ * Dock
+ *
+ * It adds the `TutorialFocus` class to its one child and renders nothing of its own, so
+ * layout never changes. The child must pass `className` through to its DOM element: plain
+ * elements, tgui Button, Tabs.Tab, Table.Row and Box all do; a custom component needs a
+ * `className` prop. The outline is drawn inside the element, so a clipping parent can't
+ * hide it.
+ */
+import { Children, cloneElement, isValidElement, type ReactNode } from 'react';
+
+import { useBackend } from '../backend';
+
+type FocusData = { tutorial_focus?: string | null };
+
+type Props = {
+ /** The focus key (or keys) this element answers to, e.g. "helm_dock". */
+ id: string | string[];
+ /** Overrides the window's `tutorial_focus`, for windows that send it under another name. */
+ focus?: string | null;
+ children: ReactNode;
+};
+
+export const TutorialFocus = (props: Props) => {
+ const { id, children } = props;
+ const { data } = useBackend();
+ const focus = props.focus === undefined ? data?.tutorial_focus : props.focus;
+ const matches = Array.isArray(id) ? id.includes(focus || '') : focus === id;
+ if (!focus || !matches) return <>{children}>;
+ const child = Children.only(children);
+ if (!isValidElement<{ className?: string }>(child)) return <>{children}>;
+ const existing = child.props.className;
+ return cloneElement(child, {
+ className: existing ? `${existing} TutorialFocus` : 'TutorialFocus',
+ });
+};
diff --git a/tgui/packages/voidcrew_tgui/interfaces/ChromeCradle.tsx b/tgui/packages/voidcrew_tgui/interfaces/ChromeCradle.tsx
index cf51c16a304..5c8130b9d23 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/ChromeCradle.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/ChromeCradle.tsx
@@ -6,6 +6,7 @@ import { type BooleanLike, classes } from 'tgui-core/react';
import { resolveAsset } from '../../tgui/assets';
import { useBackend } from '../backend';
+import { TutorialFocus } from '../components/TutorialFocus';
import { Window } from '../layouts';
import {
BROWNOUT_COLOR,
@@ -131,6 +132,7 @@ type Data = {
ink: Ink | null;
groups: Group[];
tray_count: number;
+ tutorial_focus?: string | null;
};
const TIER_NAMES: Record = {
@@ -309,7 +311,9 @@ const LoadRail = () => {
className="Cradle__loadCell"
style={{
width: `${(segment.load / scale) * 100}%`,
- backgroundColor: brownout ? BROWNOUT_COLOR : segmentColor(segment),
+ backgroundColor: brownout
+ ? BROWNOUT_COLOR
+ : segmentColor(segment),
}}
/>
@@ -369,9 +373,7 @@ const Rack = () => {
const { groups, has_occupant } = data;
if (!has_occupant) {
- return (
-
The rack is dark.
- );
+ return
The rack is dark.
;
}
return (
@@ -425,6 +427,13 @@ const Tile = (props: { ware: Ware }) => {
const { act, data } = useBackend
();
const picked = data.selected === ware.ref;
const fault = faultLabel(ware);
+ // The tutorial points at the first part that fits until one is picked. Set on the button by hand:
+ // the Tooltip clones its child, so a TutorialFocus wrapper there would swallow its hover props.
+ const tutorialPulse =
+ data.tutorial_focus === 'cradle_install' &&
+ !!data.occupant_is_user &&
+ !data.selected &&
+ firstFittingRef(data.groups) === ware.ref;
return (
} position="right">
@@ -435,6 +444,7 @@ const Tile = (props: { ware: Ware }) => {
!!ware.installed && 'Cradle__tile--installed',
picked && 'Cradle__tile--picked',
!ware.installed && !ware.fits && 'Cradle__tile--nofit',
+ tutorialPulse && 'TutorialFocus',
])}
style={{ borderColor: tierColor(ware.tier) }}
onClick={() => act('select', { ref: ware.ref })}
@@ -455,6 +465,16 @@ const Tile = (props: { ware: Ware }) => {
);
};
+/** The first part not yet installed that fits, in rack order, or null. */
+function firstFittingRef(groups: Group[]): string | null {
+ for (const group of groups) {
+ for (const ware of group.ware) {
+ if (!ware.installed && ware.fits) return ware.ref;
+ }
+ }
+ return null;
+}
+
/**
* What a tile says on hover: the whole card without having to commit a click.
* Clicking is what puts the piece on the body, so hovering has to be enough to
@@ -516,9 +536,7 @@ const Detail = () => {
.find((entry) => entry.ref === selected);
if (!ware) {
- return (
- Nothing selected.
- );
+ return Nothing selected.
;
}
// Only the occupant, conscious and unrestrained, may order work on their own
@@ -613,14 +631,16 @@ const Detail = () => {
EXTRACT
) : (
- act('install', { ref: ware.ref })}
- >
- INSTALL
-
+
+ act('install', { ref: ware.ref })}
+ >
+ INSTALL
+
+
)}
@@ -708,9 +728,10 @@ const ActionButton = (props: {
disabled?: boolean;
hint?: string;
onClick: () => void;
+ className?: string;
children;
}) => {
- const { tone, disabled, hint, onClick, children } = props;
+ const { tone, disabled, hint, onClick, className, children } = props;
return (
!disabled && onClick()}
>
diff --git a/tgui/packages/voidcrew_tgui/interfaces/HelmComputer.tsx b/tgui/packages/voidcrew_tgui/interfaces/HelmComputer.tsx
index b03a169a74a..c02a15afba8 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/HelmComputer.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/HelmComputer.tsx
@@ -33,6 +33,7 @@ import type { BooleanLike } from 'tgui-core/react';
import { resolveAsset } from '../../tgui/assets';
import { useBackend } from '../backend';
+import { TutorialFocus } from '../components/TutorialFocus';
import { Window } from '../layouts';
import {
type CourseSegment,
@@ -240,6 +241,8 @@ type DockFeeQuote = {
};
type Data = {
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
isViewer: BooleanLike;
isNotCrew: BooleanLike;
isAbandoned: BooleanLike;
@@ -530,6 +533,8 @@ const contactKey = (contact: Pick) =>
* button already does the job.
*/
const DOCKABLE_KINDS: ContactKind[] = ['planet', 'ruin', 'outpost'];
+/** OUTPOST_DOCK_VARIANT_BAY: a crew outpost's ship bay berth. */
+const DOCK_VARIANT_BAY = 'ship_bay';
const canTravelDock = (contact: Contact) =>
DOCKABLE_KINDS.includes(contact.kind) && contact.dist > 0 && !!contact.target;
@@ -3301,6 +3306,8 @@ const ContactMenu = (props: {
hint?: string;
disabled?: boolean;
onClick: () => void;
+ /** TutorialFocus key for this entry. */
+ focus?: string;
}[] = [];
if (unknown) {
@@ -3336,6 +3343,8 @@ const ContactMenu = (props: {
disabled: locked || state !== 'flying',
onClick: () =>
act('dock', { target: option.ref, variant: option.variant }),
+ focus:
+ option.variant === DOCK_VARIANT_BAY ? 'helm_dock_bay' : undefined,
});
}
}
@@ -3419,19 +3428,20 @@ const ContactMenu = (props: {
No actions available
) : (
items.map((item) => (
- {
- item.onClick();
- onClose();
- }}
- >
- {item.label}
- {!!item.hint && {item.hint} }
-
+
+ {
+ item.onClick();
+ onClose();
+ }}
+ >
+ {item.label}
+ {!!item.hint && {item.hint} }
+
+
))
)}
@@ -3468,20 +3478,24 @@ const DockPickerMenu = (props: {
Nothing to dock with
) : (
options.map((option) => (
- {
- act('dock', option.ref ? { target: option.ref, variant: option.variant } : {});
- onClose();
- }}
+ id={option.variant === DOCK_VARIANT_BAY ? 'helm_dock_bay' : ''}
>
- {option.name}
- {!!feeHint(option.fee) && (
- {feeHint(option.fee)}
- )}
-
+ {
+ act('dock', option.ref ? { target: option.ref, variant: option.variant } : {});
+ onClose();
+ }}
+ >
+ {option.name}
+ {!!feeHint(option.fee) && (
+ {feeHint(option.fee)}
+ )}
+
+
))
)}
@@ -4152,20 +4166,24 @@ const DockVariantButtons = (props: { target?: string | null }) => {
return (data.dockOptions ?? [])
.filter((option) => option.ref === props.target && option.variant)
.map((option) => (
- {
- event.stopPropagation();
- act('dock', { target: option.ref, variant: option.variant });
- }}
+ id={option.variant === DOCK_VARIANT_BAY ? 'helm_dock_bay' : ''}
>
- {option.label ?? option.name}
- {Number(option.fee) > 0 ? ` · ${Number(option.fee)} cr` : ''}
-
+ {
+ event.stopPropagation();
+ act('dock', { target: option.ref, variant: option.variant });
+ }}
+ >
+ {option.label ?? option.name}
+ {Number(option.fee) > 0 ? ` · ${Number(option.fee)} cr` : ''}
+
+
));
};
@@ -4483,45 +4501,47 @@ const HelmRose = () => {
return (
-
- {ROSE_CELLS.map(([name, direction, rotation]) => {
- const isStop = direction === BURN_STOP;
- const lit = isStop
- ? burnDirection === BURN_STOP
- : commandedCourse === direction;
- return (
-
- isStop ? act('stop') : act('change_heading', { dir: direction })
- }
- >
- {isStop ? (
-
-
-
- ) : (
-
- )}
-
- );
- })}
-
+
+
+ {ROSE_CELLS.map(([name, direction, rotation]) => {
+ const isStop = direction === BURN_STOP;
+ const lit = isStop
+ ? burnDirection === BURN_STOP
+ : commandedCourse === direction;
+ return (
+
+ isStop ? act('stop') : act('change_heading', { dir: direction })
+ }
+ >
+ {isStop ? (
+
+
+
+ ) : (
+
+ )}
+
+ );
+ })}
+
+
);
};
@@ -4604,10 +4624,12 @@ const OpsButton = (props: {
state?: 'armed' | 'active' | 'distress';
title: string;
onClick: (event: React.MouseEvent) => void;
+ /** Extra classes, e.g. from TutorialFocus. */
+ className?: string;
}) => (
{
return (
- act('undock')}
- />
-
- multipleDockOptions ? openDockPicker(event) : runDock(primaryDockOption)
- }
- />
+
+ act('undock')}
+ />
+
+ {/* With several berths, Dock opens the list that holds the ship bay. */}
+
+
+ multipleDockOptions ? openDockPicker(event) : runDock(primaryDockOption)
+ }
+ />
+
{
: 'No command authorization is registered to this ship. Claiming it makes you its commanding officer.'}
- act('claim_abandoned')}
- disabled={!!data.isRetired}
- >
- Claim this ship
-
+
+ act('claim_abandoned')}
+ disabled={!!data.isRetired}
+ >
+ Claim this ship
+
+
diff --git a/tgui/packages/voidcrew_tgui/interfaces/MissionBoard.tsx b/tgui/packages/voidcrew_tgui/interfaces/MissionBoard.tsx
index 8335a59a283..ce44fc7b23a 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/MissionBoard.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/MissionBoard.tsx
@@ -19,6 +19,7 @@ import type { BooleanLike } from 'tgui-core/react';
import { useBackend } from '../../tgui/backend';
import { Window } from '../../tgui/layouts';
+import { TutorialFocus } from '../components/TutorialFocus';
type RewardItem = {
name: string;
@@ -120,6 +121,8 @@ type Data = {
wanted?: WantedEntry[];
// Static data: record id -> base64 mugshot, never sent in the live data
wanted_mugshots?: Record;
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
};
/** One wanted criminal on the board: a public bounty or this ship's private offer. */
@@ -407,12 +410,22 @@ const MissionBoardContent = () => {
>
Available ({offered.length})
- setCurrentTab('active')}
+
- Active ({activeCount})
-
+ setCurrentTab('active')}
+ >
+ Active ({activeCount})
+
+
@@ -539,6 +552,7 @@ const MissionCard = (props: MissionCardProps) => {
const { active_count, max_missions } = data;
const canAccept = !isActive && active_count < max_missions;
+ const canTurnIn = !!mission.can_complete || padContents.length > 0;
// Format time remaining
const formatTime = (deciseconds: number) => {
@@ -589,38 +603,44 @@ const MissionCard = (props: MissionCardProps) => {
{mission.requires_item ? (
- act('turn_in', { ref: mission.ref })}
- >
- Turn In
-
+
+ act('turn_in', { ref: mission.ref })}
+ >
+ Turn In
+
+
) : (
- act('turn_in', { ref: mission.ref })}
- >
- Complete
-
+
+ act('turn_in', { ref: mission.ref })}
+ >
+ Complete
+
+
)}
>
)}
{!isActive && (
- act('accept', { ref: mission.ref })}
- >
- Accept Mission
-
+
+ act('accept', { ref: mission.ref })}
+ >
+ Accept Mission
+
+
)}
);
@@ -742,16 +762,18 @@ const BountyCard = (props: BountyCardProps) => {
{bounty.is_hunting ? (
- act('turn_in_bounty', { ref: bounty.ref })}
- >
- Turn In Key
-
+
+ act('turn_in_bounty', { ref: bounty.ref })}
+ >
+ Turn In Key
+
+
{!bounty.has_tracking && (
@@ -775,16 +797,18 @@ const BountyCard = (props: BountyCardProps) => {
) : (
- act('accept_bounty', { ref: bounty.ref })}
- >
- {bounty.was_abandoned ? 'Abandoned' : 'Accept Bounty'}
-
+
+ act('accept_bounty', { ref: bounty.ref })}
+ >
+ {bounty.was_abandoned ? 'Abandoned' : 'Accept Bounty'}
+
+
)}
diff --git a/tgui/packages/voidcrew_tgui/interfaces/OrientationBriefing.tsx b/tgui/packages/voidcrew_tgui/interfaces/OrientationBriefing.tsx
deleted file mode 100644
index ed8c1761516..00000000000
--- a/tgui/packages/voidcrew_tgui/interfaces/OrientationBriefing.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-import { useState } from 'react';
-import {
- Box,
- Button,
- Icon,
- NoticeBox,
- Section,
- Stack,
- Tabs,
-} from 'tgui-core/components';
-import type { BooleanLike } from 'tgui-core/react';
-
-import { useBackend } from '../backend';
-import { Window } from '../layouts';
-
-type Zone = {
- name: string;
- color: string;
- summary: string;
- rules: string[];
-};
-
-type ResearchNode = {
- name: string;
- desc: string;
-};
-
-type Data = {
- ship_name: string | null;
- combat_researched: BooleanLike;
- zones: Zone[];
- research_path: ResearchNode[];
-};
-
-type TabName = 'welcome' | 'zones' | 'combat';
-
-const TABS: { id: TabName; label: string; icon: string }[] = [
- { id: 'welcome', label: 'Welcome', icon: 'hand-spock' },
- { id: 'zones', label: 'Zones', icon: 'circle-half-stroke' },
- { id: 'combat', label: 'Ship Combat', icon: 'crosshairs' },
-];
-
-export const OrientationBriefing = () => {
- const [tab, setTab] = useState('welcome');
-
- return (
-
-
-
-
-
- {TABS.map((entry) => (
- setTab(entry.id)}
- icon={entry.icon}
- >
- {entry.label}
-
- ))}
-
-
-
- {tab === 'welcome' && }
- {tab === 'zones' && }
- {tab === 'combat' && }
-
-
-
-
- );
-};
-
-/** The reason this window exists at all: the server is being tested on you. */
-const WelcomeTab = () => {
- const { act } = useBackend();
-
- return (
-
-
- Things will break. Expect bugs, half-finished features and rounds that
- end badly through no fault of your own.
-
-
- Report anything broken to jackrip on the Discord, what you were
- doing and roughly when is usually enough to find it in the logs. The
- wiki covers ships, the overmap, missions and everything else Voidcrew
- adds, in far more detail than this window.
-
-
-
- act('open_discord')}>
- Open the Discord
-
-
-
- act('open_wiki')}>
- Open the Wiki
-
-
-
-
- You crew a ship on an overmap. Take contracts, mine, trade and explore;
- fly further out for better pay and worse odds. The other two tabs cover
- where you are allowed to go and how to arm the ship.
-
-
- );
-};
-
-/** What the three overmap bands permit, straight off the defines that enforce it. */
-const ZonesTab = () => {
- const { data } = useBackend();
- const { zones } = data;
-
- return (
-
-
- Your helm console always shows which ring you are in. Crossing a border
- takes ten seconds and can be cancelled until it completes.
-
- {zones.map((zone) => (
-
-
-
- {zone.name}
-
- {zone.summary}
-
- {zone.rules.map((rule) => (
-
- • {rule}
-
- ))}
-
-
- ))}
-
- Farther out, be ready for meteors, radiation storms on planets, hostile
- crews and worse.
-
-
- );
-};
-
-/** Why a new crew should not simply fly outward, and what fixes that. */
-const CombatTab = () => {
- const { data } = useBackend();
- const { research_path, combat_researched, ship_name } = data;
-
- return (
-
-
- Shields, turrets, missiles and interdictors are researched on your own
- ship, not bought. Use an R&D console wired to your ship's
- research server; each node unlocks a board you print and build in.
-
- {research_path.map((node) => (
-
- {node.name}
- {node.desc}
-
- ))}
- {combat_researched ? (
-
- {ship_name ?? 'Your ship'} has Shuttle Warfare Systems researched. You
- can build shields and weapons whenever you are ready.
-
- ) : (
-
- {ship_name ?? 'Your ship'} has no Shuttle Warfare Systems research yet:
- no shields, nothing to shoot back with. Take contracts in the middle
- ring, earn research points, and stay out of the outer ring until you
- are equipped.
-
- )}
-
- );
-};
diff --git a/tgui/packages/voidcrew_tgui/interfaces/OutpostElevator.tsx b/tgui/packages/voidcrew_tgui/interfaces/OutpostElevator.tsx
index eaf0f3cb5df..8d88649911e 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/OutpostElevator.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/OutpostElevator.tsx
@@ -10,6 +10,7 @@ import type { BooleanLike } from 'tgui-core/react';
import { useBackend } from '../../tgui/backend';
import { Window } from '../../tgui/layouts';
+import { TutorialFocus } from '../components/TutorialFocus';
type Floor = {
id: number;
@@ -24,6 +25,8 @@ type Data = {
moving: BooleanLike;
linked: BooleanLike;
floors: Floor[];
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
};
export const OutpostElevator = (props) => {
@@ -49,39 +52,47 @@ export const OutpostElevator = (props) => {
{floors.map((floor) => (
- act('goto', { id: floor.id })}
>
- {`${floor.name}${floor.your_ship ? ' (your ship)' : ''}`}
-
+ act('goto', { id: floor.id })}
+ >
+ {`${floor.name}${floor.your_ship ? ' (your ship)' : ''}`}
+
+
))}
diff --git a/tgui/packages/voidcrew_tgui/interfaces/OutpostMissionBoard.tsx b/tgui/packages/voidcrew_tgui/interfaces/OutpostMissionBoard.tsx
index 1a4e708e03c..cc4226be9d4 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/OutpostMissionBoard.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/OutpostMissionBoard.tsx
@@ -15,6 +15,7 @@ import type { BooleanLike } from 'tgui-core/react';
import { useBackend } from '../../tgui/backend';
import { Window } from '../../tgui/layouts';
+import { TutorialFocus } from '../components/TutorialFocus';
type RewardItem = {
name: string;
@@ -64,6 +65,8 @@ type Data = {
crew_ships: { ref: string; name: string }[];
crew_ship_ref: string | null;
reputation?: Reputation | null;
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
};
const ARCHETYPE_ICONS = {
@@ -202,20 +205,22 @@ const OfferCard = (props: { offer: Offer; canAccept: boolean }) => {
- act('accept', { ref: offer.ref })}
- >
- Accept
-
+
+ act('accept', { ref: offer.ref })}
+ >
+ Accept
+
+
@@ -269,7 +274,9 @@ const ShipMissionRow = (props: { mission: ShipMission }) => {
{!canTurnIn && mission.turn_in_hint ? (
{turnInButton}
) : (
- turnInButton
+
+ {turnInButton}
+
)}
diff --git a/tgui/packages/voidcrew_tgui/interfaces/ShipCombatConsole.tsx b/tgui/packages/voidcrew_tgui/interfaces/ShipCombatConsole.tsx
index dc4ce68e113..3687ce8688f 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/ShipCombatConsole.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/ShipCombatConsole.tsx
@@ -20,6 +20,7 @@ import { type BooleanLike } from 'tgui-core/react';
import { resolveAsset } from '../../tgui/assets';
import { useBackend } from '../backend';
+import { TutorialFocus } from '../components/TutorialFocus';
import { Window } from '../layouts';
// ---------------------------------------------------------------- geometry
@@ -230,6 +231,8 @@ type Data = {
cloak_active: BooleanLike;
attack_mode: BooleanLike;
is_in_attack_mode: BooleanLike;
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
target_name: string | null;
target_ref: string | null;
// Targeting lock-in-progress data
@@ -1621,6 +1624,11 @@ const ApproachCluster = () => {
const TABS = ['Contacts', 'Exploits', 'Defense', 'Systems'] as const;
type Tab = (typeof TABS)[number];
+/** Tutorial focus key each drawer tab answers to. */
+const TAB_FOCUS: Partial> = {
+ Contacts: 'wpn_contact',
+ Exploits: 'wpn_hack',
+};
const Drawer = () => {
const { data } = useBackend();
@@ -1637,23 +1645,27 @@ const Drawer = () => {
{TABS.map((name) => (
- setTab(name)}
+ id={tab === name ? '' : (TAB_FOCUS[name] ?? '')}
>
- {name}
- {name === 'Contacts' && contacts > 0 && (
- {contacts}
- )}
- {name === 'Exploits' && readyChips > 0 && (
- {readyChips}
- )}
- {name === 'Defense' && threats > 0 && (
- {threats}
- )}
-
+ setTab(name)}
+ >
+ {name}
+ {name === 'Contacts' && contacts > 0 && (
+ {contacts}
+ )}
+ {name === 'Exploits' && readyChips > 0 && (
+ {readyChips}
+ )}
+ {name === 'Defense' && threats > 0 && (
+ {threats}
+ )}
+
+
))}
@@ -1797,46 +1809,50 @@ const ContactsTab = () => {
others.map((ship) => {
const targetable = !!ship.same_zone;
return (
-
{
- if (targetable) act('select_target', { ref: ship.ref });
- }}
+ id={targetable ? 'wpn_contact' : ''}
>
-
-
-
-
-
-
{ship.name}
-
- {ship.distance} {bearingOf(ship.dx, ship.dy)}
-
-
- {ship.identified ? (
- <>
- shd {Math.round(ship.shields)}/{ship.shields_max} · hull{' '}
- {Math.round(ship.integrity)}%
- >
- ) : (
- 'no signature'
- )}
- {!targetable && (
- [{ship.zone_name}]
- )}
-
-
+
{
+ if (targetable) act('select_target', { ref: ship.ref });
+ }}
+ >
+
+
+
+
+
+
{ship.name}
+
+ {ship.distance} {bearingOf(ship.dx, ship.dy)}
+
+
+ {ship.identified ? (
+ <>
+ shd {Math.round(ship.shields)}/{ship.shields_max} · hull{' '}
+ {Math.round(ship.integrity)}%
+ >
+ ) : (
+ 'no signature'
+ )}
+ {!targetable && (
+ [{ship.zone_name}]
+ )}
+
+
+
);
})
)}
@@ -1988,6 +2004,9 @@ const ExploitsTab = () => {
);
};
+/** Tutorial focus keys a runnable cartridge's run buttons answer to. */
+const EXEC_FOCUS = ['wpn_hack', 'wpn_execute'];
+
const EwChipRow = (props: { chip: EwChip }) => {
const { chip } = props;
const { act, data } = useBackend
();
@@ -2058,27 +2077,30 @@ const EwChipRow = (props: { chip: EwChip }) => {
{chip.modes && chip.modes.length > 0 ? (
chip.modes.map((mode) => (
+
+ act('ew_execute', { chip_ref: chip.ref, mode })}
+ >
+ {formatModeLabel(mode)}
+
+
+ ))
+ ) : (
+
act('ew_execute', { chip_ref: chip.ref, mode })}
+ onClick={() => act('ew_execute', { chip_ref: chip.ref })}
>
- {formatModeLabel(mode)}
+ {spent ? 'Spent' : 'Execute'}
- ))
- ) : (
- act('ew_execute', { chip_ref: chip.ref })}
- >
- {spent ? 'Spent' : 'Execute'}
-
+
)}
@@ -2533,24 +2555,28 @@ const TubesPanel = () => {
- act('fire_missile')}
- >
- Fire
-
- act('fire_all')}
- >
- Salvo
-
+
+ act('fire_missile')}
+ >
+ Fire
+
+
+
+ act('fire_all')}
+ >
+ Salvo
+
+
{pod_tubes.length > 0 && (
{
Draw
{interdictor_power_draw || 0}W
- act('start_interdict')}
- >
- Engage field
-
+
+ act('start_interdict')}
+ >
+ Engage field
+
+
{!!reason && {reason}
}
);
@@ -2815,10 +2843,15 @@ const OpsButton = (props: {
state?: 'armed' | 'active';
title: string;
onClick: () => void;
+ className?: string;
}) => (
{
return (
-
act(is_in_attack_mode ? 'deactivate' : 'activate')}
- />
+
+ act(is_in_attack_mode ? 'deactivate' : 'activate')}
+ />
+
{
Tools
{!isOutpost && (
- setActiveTab('repair')}
+
- Repair Drones
-
+ setActiveTab('repair')}
+ >
+ Repair Drones
+
+
)}
{!isOutpost && (
{
- act('repair_toggle')}
- >
- {repairEnabled ? 'Pause swarm' : 'Deploy swarm'}
-
+
+ act('repair_toggle')}
+ >
+ {repairEnabled ? 'Pause swarm' : 'Deploy swarm'}
+
+
{
const currentThemeColors = theme ? getThemeColors(theme) : undefined;
+ // Tutorial checklist: lead to the Research tab (print) or the Surveying tab (start).
+ const tutorialFocus = data.tutorial_focus || '';
+ const researchTabFocus =
+ tab !== 9 &&
+ (tutorialFocus === 'survey_research_tab' ||
+ (tutorialFocus === 'survey_print' && data.bankedPoints > 0))
+ ? tutorialFocus
+ : '';
+ const surveyTabFocus =
+ tab !== 1 && tutorialFocus === 'survey_start' ? tutorialFocus : '';
+ const menuFocus = researchTabFocus || surveyTabFocus;
+
if (data.archiveMode) {
return ;
}
@@ -176,179 +190,183 @@ export const SurveyComputer = () => {
-
-
-
-
- {' '}
-
- {
- setTab(1);
- }}
- >
- Surveying
-
- {
- setTab(9);
- }}
- >
- Research
-
- {
- setTab(10);
- }}
- >
- Settings
-
-
-
-
-
-
- {
- setTab(2);
- }}
- >
- Planets
-
- {
- setTab(3);
- }}
- >
- Nebulas
-
- {
- setTab(4);
- }}
- >
- Electric Storms
-
- {
- setTab(5);
- }}
- >
- EMP Storms
-
- {
- setTab(6);
- }}
- >
- Asteroids
-
- {
- setTab(7);
- }}
- >
- Stars
-
-
-
-
-
+
@@ -548,31 +566,39 @@ const Surveying = () => {
{selectedTarget?.status === 'unsurveyed' ? (
Research: {selectedTarget.points}
) : null}
- {
- if (!currentOption.action) {
- return;
- }
- if (currentOption.action === 'survey') {
- act('survey', { target_ref: selectedTarget?.ref });
- } else {
- act(currentOption.action);
- }
- }}
>
- {currentOption.content}
-
+ {
+ if (!currentOption.action) {
+ return;
+ }
+ if (currentOption.action === 'survey') {
+ act('survey', { target_ref: selectedTarget?.ref });
+ } else {
+ act(currentOption.action);
+ }
+ }}
+ >
+ {currentOption.content}
+
+
);
@@ -1313,26 +1339,28 @@ const Research = () => {
return (
- {
- act('printResearch');
- }}
- >
- {' '}
- Print
-
+ 0 ? 'survey_print' : ''}>
+ {
+ act('printResearch');
+ }}
+ >
+ {' '}
+ Print
+
+
{
);
}
+ // Tutorial checklist (rd_node_): list the node it points at first, and pulse the
+ // Available tab while that node is available but another tab is open.
+ const tutorialFocus = data.tutorial_focus || '';
+ const focusNodeId = tutorialFocus.startsWith('rd_node_')
+ ? tutorialFocus.slice('rd_node_'.length)
+ : '';
+ const focusNode = focusNodeId
+ ? displayedNodes.find((x) => x.id === focusNodeId)
+ : undefined;
+ if (focusNode) {
+ displayedNodes = [
+ focusNode,
+ ...displayedNodes.filter((x) => x !== focusNode),
+ ];
+ }
+ const focusAvailable =
+ !!focusNodeId &&
+ (searching || tabIndex !== 1) &&
+ nodes.some((x) => x.id === focusNodeId && x.tier === 1);
+
const switchTab = (tab) => {
setTabIndex(tab);
setSearchText(null);
@@ -281,12 +302,14 @@ const TechwebOverview = (props) => {
>
Researched
- switchTab(1)}
- >
- Available
-
+
+ switchTab(1)}
+ >
+ Available
+
+
switchTab(2)}
@@ -578,7 +601,12 @@ const TechNode = (props) => {
return (
).
+ data.tutorial_focus === `rd_node_${id}`
+ ? 'Techweb__NodeContainer TutorialFocus'
+ : 'Techweb__NodeContainer'
+ }
title={name}
buttons={
!nocontrols && (
diff --git a/tgui/packages/voidcrew_tgui/interfaces/TraderShop.tsx b/tgui/packages/voidcrew_tgui/interfaces/TraderShop.tsx
index 73f84f403a7..68aa1831f9f 100644
--- a/tgui/packages/voidcrew_tgui/interfaces/TraderShop.tsx
+++ b/tgui/packages/voidcrew_tgui/interfaces/TraderShop.tsx
@@ -15,6 +15,7 @@ import type { BooleanLike } from 'tgui-core/react';
import { useBackend } from '../../tgui/backend';
import { Window } from '../../tgui/layouts';
+import { TutorialFocus } from '../components/TutorialFocus';
type CatalogSku = {
ref: string;
@@ -83,6 +84,8 @@ type Data = {
crew_ships: { ref: string; name: string }[];
crew_ship_ref: string | null;
reputation?: Reputation | null;
+ /** The tutorial checklist's focus key for this window (TutorialFocus), or null. */
+ tutorial_focus?: string | null;
};
const SHELF_TAGS = {
@@ -261,13 +264,26 @@ const SkuRow = (props: {
{live?.denial && !live.can_buy && !barred && (isFavor || !soldOut) ? (
{buyButton}
) : (
- buyButton
+
+ {buyButton}
+
)}
);
};
+/** The shop category the Buy chrome tutorial step points at. */
+const CHROME_CATEGORY = 'Street Chrome';
+
const BuyView = (props: { barred: BooleanLike }) => {
const { data } = useBackend();
const { barred } = props;
@@ -303,13 +319,21 @@ const BuyView = (props: { barred: BooleanLike }) => {
All ({catalog.length})
{withItems.map((cat) => (
- setCategory(cat)}
+ id={
+ cat === CHROME_CATEGORY && category !== cat
+ ? 'trader_chrome_tab'
+ : ''
+ }
>
- {cat} ({catalog.filter((sku) => sku.category === cat).length})
-
+ setCategory(cat)}
+ >
+ {cat} ({catalog.filter((sku) => sku.category === cat).length})
+
+
))}
@@ -342,13 +366,15 @@ const LedgerRow = (props: {
const sellButtons = (
<>
- act('sell', { ref: entry.ref })}
- >
- {done ? 'Not buying' : 'Sell'}
-
+ 0 ? 'trader_sell' : ''}>
+ act('sell', { ref: entry.ref })}
+ >
+ {done ? 'Not buying' : 'Sell'}
+
+
{!done && carrying > 1 && (
{
- setTab('buy')}
+
- {trader_name}'s Stock
-
- {!!hasBuybacks && (
setTab('sell')}
+ selected={tab === 'buy'}
+ onClick={() => setTab('buy')}
>
- {trader_name} Buys
+ {trader_name}'s Stock
+
+ {!!hasBuybacks && (
+
+ setTab('sell')}
+ >
+ {trader_name} Buys
+
+
)}
diff --git a/tgui/packages/voidcrew_tgui/interfaces/TutorialChecklist.tsx b/tgui/packages/voidcrew_tgui/interfaces/TutorialChecklist.tsx
new file mode 100644
index 00000000000..915caaeee17
--- /dev/null
+++ b/tgui/packages/voidcrew_tgui/interfaces/TutorialChecklist.tsx
@@ -0,0 +1,452 @@
+// Tutorial checklist: category groups on the left, the open lesson on the right.
+import { useEffect, useState } from 'react';
+import { Box, Button, Icon, Section, Stack, Tabs } from 'tgui-core/components';
+import type { BooleanLike } from 'tgui-core/react';
+
+import { useBackend } from '../backend';
+import { Window } from '../layouts';
+
+type Step = {
+ key: string;
+ name: string;
+ text: string;
+ optional: BooleanLike;
+ /** Steps sharing a route form one way to finish the item. */
+ route: string | null;
+ route_name: string | null;
+};
+
+type Item = {
+ id: string;
+ name: string;
+ intro: string;
+ steps: Step[];
+};
+
+type Category = {
+ id: string;
+ name: string;
+ items: string[];
+};
+
+type Data = {
+ categories: Category[];
+ items: Item[];
+ done: string[];
+ notes: Record;
+ /** Live state lines for the open item's undone steps. */
+ live: Record;
+ /** The step the outlines and in-window focus follow, or null. */
+ guide: string | null;
+ excused: string[];
+ suggested: string | null;
+ selected: string | null;
+ spawn_open: BooleanLike;
+ highlights: BooleanLike;
+};
+
+type Progress = {
+ finished: number;
+ total: number;
+ complete: boolean;
+};
+
+type Lookup = { done: Set; excused: Set };
+
+const routeIds = (steps: Step[]) => {
+ const ids: string[] = [];
+ for (const step of steps) {
+ if (step.route && !ids.includes(step.route)) ids.push(step.route);
+ }
+ return ids;
+};
+
+/** Shared steps plus the route closest to done. Excused and optional steps don't count. */
+const itemProgress = (item: Item, look: Lookup): Progress => {
+ const live = item.steps.filter(
+ (step) => !step.optional && !look.excused.has(step.key),
+ );
+ const counted = live.filter((step) => !step.route);
+ let best: Step[] | undefined;
+ let bestShare = -1;
+ for (const route of routeIds(live)) {
+ const steps = live.filter((step) => step.route === route);
+ const share =
+ steps.filter((step) => look.done.has(step.key)).length / steps.length;
+ if (share > bestShare) {
+ best = steps;
+ bestShare = share;
+ }
+ }
+ if (best) counted.push(...best);
+ const finished = counted.filter((step) => look.done.has(step.key)).length;
+ return {
+ finished,
+ total: counted.length,
+ complete: look.done.has(item.id) || finished >= counted.length,
+ };
+};
+
+const ProgressMark = (props: { progress?: Progress }) => {
+ const { progress } = props;
+ if (!progress) return null;
+ return progress.complete ? (
+
+ ) : (
+
+ {progress.finished}/{progress.total}
+
+ );
+};
+
+export const TutorialChecklist = () => {
+ const { act, data } = useBackend();
+ const items = data.items || [];
+ const categories = data.categories || [];
+ const notes = data.notes || {};
+ const live = data.live || {};
+ const guide = data.guide || null;
+ const suggested = data.suggested || null;
+ const look: Lookup = {
+ done: new Set(data.done || []),
+ excused: new Set(data.excused || []),
+ };
+ const byId: Record = {};
+ const progress: Record = {};
+ for (const item of items) {
+ byId[item.id] = item;
+ progress[item.id] = itemProgress(item, look);
+ }
+
+ const startId =
+ (data.selected && byId[data.selected] ? data.selected : null) ||
+ suggested ||
+ items[0]?.id;
+ const [selectedId, setSelectedId] = useState(startId);
+ const selected = byId[selectedId || ''] || items[0];
+ const homeCategory = categories.find((cat) =>
+ cat.items.includes(startId || ''),
+ );
+ const [open, setOpen] = useState>(
+ homeCategory ? { [homeCategory.id]: true } : {},
+ );
+
+ // The server keeps the open item for the in-game highlight.
+ useEffect(() => {
+ if (startId && data.selected !== startId) act('select', { id: startId });
+ }, []);
+
+ const select = (id: string) => {
+ setSelectedId(id);
+ act('select', { id });
+ };
+
+ return (
+
+
+
+
+
+
+
+ {categories.map((cat) => {
+ const finished = cat.items.filter(
+ (id) => progress[id]?.complete,
+ ).length;
+ const isOpen = !!open[cat.id];
+ const holdsSuggested =
+ !!suggested && cat.items.includes(suggested);
+ return (
+
+
+ setOpen({ ...open, [cat.id]: !isOpen })
+ }
+ >
+
+
+
+
+
+ {cat.name}
+ {!isOpen && holdsSuggested ? (
+
+ ) : null}
+
+
+ {finished}/{cat.items.length}
+
+
+
+ {isOpen ? (
+
+ {cat.items.map((id) => {
+ const item = byId[id];
+ if (!item) return null;
+ return (
+ select(id)}
+ pl={2}
+ >
+
+
+ {item.name}
+ {id === suggested ? (
+
+ ) : null}
+
+
+
+
+
+
+ );
+ })}
+
+ ) : null}
+
+ );
+ })}
+
+
+
+
+
+ Next up
+
+ ) : (
+
+
+
+ )
+ }
+ >
+ {selected ? (
+ <>
+ {selected.intro ? (
+
+ {selected.intro}
+
+ ) : null}
+
+ >
+ ) : null}
+
+
+
+
+
+
+
+ act('toggle_spawn_open')}
+ >
+ Don't open on spawn
+
+
+
+ act('toggle_highlights')}
+ >
+ Highlight objects
+
+
+
+
+
+
+
+ );
+};
+
+type Group = { route: string | null; routeName: string; steps: Step[] };
+
+const groupSteps = (steps: Step[]) => {
+ const groups: Group[] = [];
+ for (const step of steps) {
+ const last = groups[groups.length - 1];
+ if (last && step.route && last.route === step.route) {
+ last.steps.push(step);
+ } else {
+ groups.push({
+ route: step.route,
+ routeName: step.route_name || '',
+ steps: [step],
+ });
+ }
+ }
+ return groups;
+};
+
+type StepListProps = {
+ item: Item;
+ look: Lookup;
+ notes: Record;
+ live: Record;
+ guide: string | null;
+};
+
+/** Steps in order. Routes get a box with "OR" between them and go quiet once another route is done. */
+const StepList = (props: StepListProps) => {
+ const { item, look, notes, live, guide } = props;
+ const groups = groupSteps(item.steps);
+ const routeDone = (route: string) =>
+ item.steps
+ .filter((step) => step.route === route && !step.optional)
+ .every((step) => look.done.has(step.key));
+ const finishedRoute = routeIds(item.steps).find(routeDone);
+ return (
+
+ {groups.map((group, index) => {
+ if (!group.route) {
+ return group.steps.map((step) => (
+
+ ));
+ }
+ const previous = groups[index - 1];
+ const isDone = finishedRoute === group.route;
+ const quiet = !!finishedRoute && !isDone;
+ return (
+
+ {previous?.route ? (
+
+ OR
+
+ ) : null}
+
+
+
+ {group.routeName}
+ {quiet ? (
+
+ not needed
+
+ ) : null}
+
+ {group.steps.map((step) => (
+
+ ))}
+
+
+ );
+ })}
+
+ );
+};
+
+type StepRowProps = {
+ step: Step;
+ done: boolean;
+ quiet?: boolean;
+ note?: string;
+ /** Live state, shown while the step is undone. */
+ live?: string;
+ /** The outlines and in-window focus point at this step. */
+ guided?: boolean;
+};
+
+const StepRow = (props: StepRowProps) => {
+ const { step, done, quiet, note, live, guided } = props;
+ return (
+
+
+
+
+
+
+ {step.name}
+ {guided && !done ? (
+
+ ) : null}
+ {step.optional ? (
+
+ (optional)
+
+ ) : null}
+
+ {step.text}
+ {!done && !!note ? (
+
+ {note}
+
+ ) : null}
+ {!done && !!live ? (
+
+ {live}
+
+ ) : null}
+
+
+ );
+};
diff --git a/tgui/packages/voidcrew_tgui/preferences/features/index.ts b/tgui/packages/voidcrew_tgui/preferences/features/index.ts
index eafe325f6e9..90d65e12583 100644
--- a/tgui/packages/voidcrew_tgui/preferences/features/index.ts
+++ b/tgui/packages/voidcrew_tgui/preferences/features/index.ts
@@ -4,3 +4,4 @@
export * from './autotranslate';
export * from './bark_voice';
export * from './intents';
+export * from './tutorials';
diff --git a/tgui/packages/voidcrew_tgui/preferences/features/tutorials.tsx b/tgui/packages/voidcrew_tgui/preferences/features/tutorials.tsx
new file mode 100644
index 00000000000..8ea027110e7
--- /dev/null
+++ b/tgui/packages/voidcrew_tgui/preferences/features/tutorials.tsx
@@ -0,0 +1,18 @@
+import {
+ CheckboxInput,
+ type FeatureToggle,
+} from 'tgui/interfaces/PreferencesMenu/preferences/features/base';
+
+export const tutorial_checklist: FeatureToggle = {
+ name: 'Open tutorial checklist on spawn',
+ category: 'GAMEPLAY',
+ description: 'Open the tutorial checklist each time you spawn.',
+ component: CheckboxInput,
+};
+
+export const tutorial_highlights: FeatureToggle = {
+ name: 'Highlight tutorial objects',
+ category: 'GAMEPLAY',
+ description: 'Outline the objects the open tutorial points at.',
+ component: CheckboxInput,
+};
diff --git a/tgui/packages/voidcrew_tgui/styles/components/TutorialFocus.scss b/tgui/packages/voidcrew_tgui/styles/components/TutorialFocus.scss
new file mode 100644
index 00000000000..c6d02ae9197
--- /dev/null
+++ b/tgui/packages/voidcrew_tgui/styles/components/TutorialFocus.scss
@@ -0,0 +1,21 @@
+// The tutorial checklist's in-window pointer (components/TutorialFocus.tsx). Outline and
+// inset glow only, both drawn inside the element's box, so nothing moves and a clipping
+// parent can't hide it. #FFC83C matches the in-game outlines.
+@keyframes TutorialFocus__pulse {
+ 0%,
+ 100% {
+ outline-color: rgba(255, 200, 60, 1);
+ box-shadow: inset 0 0 6px 1px rgba(255, 200, 60, 0.55);
+ }
+
+ 50% {
+ outline-color: rgba(255, 200, 60, 0.35);
+ box-shadow: inset 0 0 2px 0 rgba(255, 200, 60, 0.15);
+ }
+}
+
+.TutorialFocus {
+ outline: 2px solid rgba(255, 200, 60, 1) !important;
+ outline-offset: -2px !important;
+ animation: TutorialFocus__pulse 1.6s ease-in-out infinite;
+}
diff --git a/tgui/packages/voidcrew_tgui/styles/main.scss b/tgui/packages/voidcrew_tgui/styles/main.scss
index 071aacc578c..eb318f1f8b4 100644
--- a/tgui/packages/voidcrew_tgui/styles/main.scss
+++ b/tgui/packages/voidcrew_tgui/styles/main.scss
@@ -7,3 +7,4 @@
@include meta.load-css('./interfaces/OutpostManagement.scss');
@include meta.load-css('./interfaces/OutpostPrison.scss');
@include meta.load-css('./interfaces/ShipCombatConsole.scss');
+@include meta.load-css('./components/TutorialFocus.scss');
diff --git a/voidcrew/_DEFINES/cyberware.dm b/voidcrew/_DEFINES/cyberware.dm
index cf6eb52c4f0..b027bdceed7 100644
--- a/voidcrew/_DEFINES/cyberware.dm
+++ b/voidcrew/_DEFINES/cyberware.dm
@@ -254,3 +254,29 @@
/// frame (ware_military_body.dm) and the Strut frame (ware_models_b.dm); the
/// gate itself is in ware_military_body.dm.
#define TRAIT_CYBERWARE_UNBREAKABLE_BONES "cyberware_unbreakable_bones"
+
+/// A Mantis Blade cutting: a sound effect key, one of its files picked each time (ware_military_arms.dm).
+#define CYBERWARE_MANTIS_SLASH_SOUND "cyberware_mantis_slash"
+
+// A Sandevistan's own sounds (ware_sandy_sound.dm). The user's play to him alone and are never slowed or recorded; the
+// external one is what everyone else near hears.
+/// The user's surge coming on.
+#define SANDEVISTAN_ACTIVATION_SOUND 'voidcrew/sound/cyberware/sandevistan_activation.ogg'
+/// Loops to the user for as long as his slow-mo runs.
+#define SANDEVISTAN_LOOP_SOUND 'voidcrew/sound/cyberware/sandevistan_loop.ogg'
+/// The user's slow-mo ending.
+#define SANDEVISTAN_DEACTIVATE_SOUND 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg'
+/// The loop climbs in pitch as the slow-mo runs out: this frequency multiplier at its end, 1 at its start,
+/// most of the climb in the last third (1 + (END - 1) * progress squared).
+#define SANDEVISTAN_PITCH_END 1.4
+/// How often the playing loop's pitch is updated.
+#define SANDEVISTAN_PITCH_UPDATE (0.5 SECONDS)
+/// What everyone else near hears, from the surger's tile, as he surges and bursts off, and the replay's viewers: a sound
+/// effect key, one of its files picked each time (/datum/sound_effect/sandevistan_external).
+#define SANDEVISTAN_EXTERNAL_SOUND "sandevistan_external"
+/// The external cue's volume, live and in the replay.
+#define SANDEVISTAN_EXTERNAL_VOLUME 75
+/// Its pitch spread, in hundredths either way.
+#define SANDEVISTAN_EXTERNAL_SPREAD 6
+/// While a surger keeps moving, his burst cues come at most this often (live, and on the replay's clock).
+#define SANDEVISTAN_BURST_GAP (0.4 SECONDS)
diff --git a/voidcrew/_DEFINES/gorilla_gore.dm b/voidcrew/_DEFINES/gorilla_gore.dm
index 31e6ec17bff..5daec6ec281 100644
--- a/voidcrew/_DEFINES/gorilla_gore.dm
+++ b/voidcrew/_DEFINES/gorilla_gore.dm
@@ -323,23 +323,47 @@
#define GORILLA_RIP_FALL_TIME (0.25 SECONDS)
/// How long the let-go body takes to slide back to where tg lays it (tg's own offset slide).
#define GORILLA_RIP_LET_GO (0.2 SECONDS)
-/// How long nothing moves at the start of the plant, while the puppets' pictures reach the client. The plant's own
-/// 0.3 s still ends inside its stage.
+/// How long nothing moves at the start of the plant, while the puppets' pictures reach the client. The grab
+/// (GORILLA_RIP_GRAB_TIME) still ends inside the plant's stage.
#define GORILLA_RIP_START_HOLD (0.15 SECONDS)
-/// Seen from behind, how long the torn arm takes to come down with his fist and hang beside him.
-#define GORILLA_RIP_HANG_TIME (0.25 SECONDS)
/// The limb rip's blood: how many drops burst from the socket as the arm comes away, and the furthest (pixels) the pool
/// under the shoulder is laid from the middle of the body's tile.
#define GORILLA_RIP_BURST_DROPS 12
#define GORILLA_RIP_POOL_REACH 10
-/// The limb rip's blow with the torn arm: up over his head, then down on theirs. The hit lands as it comes down.
-#define GORILLA_CLUB_RAISE (0.2 SECONDS)
-#define GORILLA_CLUB_STRIKE (0.1 SECONDS)
-/// How long before the arm is all the way down the blow lands (recorded 0 to 0.12 s late without it).
-#define GORILLA_CLUB_HIT_LEAD (0.05 SECONDS)
-/// How far his arms push out on that blow, and the most the torn arm in his fists stretches to reach, as shares of their length.
-#define GORILLA_CLUB_REACH 1.6
-#define GORILLA_CLUB_MAX_STRETCH 1.5
+/// Pixels out past the torn shoulder, away from the body, the pool under it is laid, so it shows from the tear.
+#define GORILLA_RIP_POOL_OUT 6
+/// The limb rip's pace: how long his fists take to close on the wrist, how long the one haul takes from the grab to the
+/// full lean (a shade longer than its 0.4 s stage, so it is still closing when the arm gives, not held still), and how
+/// long the arm shakes in its socket at the end of it before it gives.
+#define GORILLA_RIP_GRAB_TIME (0.25 SECONDS)
+#define GORILLA_RIP_HAUL_TIME (0.45 SECONDS)
+#define GORILLA_RIP_STRAIN_TIME (0.2 SECONDS)
+/// Seen from the front or the back, pixels aside of his middle the arm is hauled to, so it shows beside his body.
+#define GORILLA_RIP_HAUL_ASIDE 12
+/// The same facing away: his arms reach past his back and head, so the arm goes out past his shoulder.
+#define GORILLA_RIP_HAUL_ASIDE_AWAY 20
+/// Seen from the front or the back the body lies across his way. Pixels from where it lay to the middle of his tile
+/// that his step in leaves open (his soles 15 below his middle, half a lying body 8, tg's lying drop 6 and a pixel
+/// to spare), so his boots stop at its edge; and the pixels he steps back off it as he hauls.
+#define GORILLA_RIP_STEP_GAP 18
+#define GORILLA_RIP_STEP_BACK 3
+/// The share of the grab his fists take to reach the hand where it lies, before the arm comes up with them.
+#define GORILLA_RIP_REACH_SHARE 0.55
+/// Facing away, pixels under his tile the finisher's bar is drawn: over his head it would sit on the body and the
+/// arm he hauls up off it.
+#define GORILLA_RIP_BAR_LOW -14
+/// Tiles the torn arm is flung, the degrees his arms swing on as it goes (back seen from the side, out wide from the
+/// front or back), and the pixels of piston they push out with.
+#define GORILLA_RIP_THROW_TILES 2
+#define GORILLA_RIP_THROW_SWING 40
+#define GORILLA_RIP_THROW_REACH 2
+/// The throw: how long the arm is in the air, the animation steps it flies in (each turn a short one), the whole turns
+/// it spins, the pixels it rises at the top of its arc, and the pixels short of the middle of its tile it comes down.
+#define GORILLA_RIP_THROW_TIME (0.3 SECONDS)
+#define GORILLA_RIP_THROW_STEPS 8
+#define GORILLA_RIP_THROW_SPINS 2
+#define GORILLA_RIP_THROW_ARC 10
+#define GORILLA_RIP_THROW_SHORT 0
/// Pixels toward the viewer a backbroken body lies on the bearer's tile, so he doesn't hide it, and the offset's source.
#define GORILLA_BACK_IN_FRONT 10
#define GORILLA_LAID_IN_FRONT_OFFSET "gorilla_laid_in_front"
diff --git a/voidcrew/_DEFINES/mantis_gore.dm b/voidcrew/_DEFINES/mantis_gore.dm
index de955bfb4a8..efc41de9540 100644
--- a/voidcrew/_DEFINES/mantis_gore.dm
+++ b/voidcrew/_DEFINES/mantis_gore.dm
@@ -123,6 +123,10 @@
#define MANTIS_IMPALE_DROP_BEAT (0.3 SECONDS)
/// From the pull-back to the blades coming out and the body dropping.
#define MANTIS_IMPALE_PULL_BEAT (0.3 SECONDS)
+/// The shortest time someone on the floor takes to be swung up onto the blades (longer when the lunging body
+/// glides in for longer), and the steps it is drawn in.
+#define MANTIS_IMPALE_HOIST (0.35 SECONDS)
+#define MANTIS_IMPALE_HOIST_STEPS 4
/// Pixels under a body's middle that it is tipped about: its feet (mantis_tip_matrix()).
#define MANTIS_TIP_FEET (ICON_SIZE_Y / 2 - 4)
@@ -164,10 +168,11 @@
/// Brute to the neck when the head won't come off.
#define MANTIS_SCISSOR_FALLBACK_DAMAGE 25
/// Where a head cut off by the scissor is drawn on its tile: pixels out from the middle toward the side the
-/// head lay, where the neck was, then where it comes to rest, and how far below the middle.
+/// head lay, where the neck was, then where it comes to rest, and how far below the middle. It rolls out and down
+/// off the neck and stays clear of the tile's edge.
#define MANTIS_HEAD_ROLL_FROM 7
-#define MANTIS_HEAD_ROLL_TO 11
-#define MANTIS_HEAD_ROLL_DROP 5
+#define MANTIS_HEAD_ROLL_TO 8
+#define MANTIS_HEAD_ROLL_DROP 7
// ---- Blood on the blades ----
/// How long a drenched blade drips.
diff --git a/voidcrew/_DEFINES/tutorials.dm b/voidcrew/_DEFINES/tutorials.dm
new file mode 100644
index 00000000000..b3fd90d72f0
--- /dev/null
+++ b/voidcrew/_DEFINES/tutorials.dm
@@ -0,0 +1,141 @@
+// Tutorial checklist keys (voidcrew/modules/tutorials).
+// Stored in the tg `tutorial_completions` table. Every key starts with "vc/" so it can
+// never collide with tg's own tutorial keys, and must stay at most 64 characters.
+// Never rename a key that has shipped: players' saved progress is stored under it.
+
+// Panel categories, in the order the panel lists them (GLOB.tutorial_categories holds the names).
+#define TUTORIAL_CATEGORY_START "start"
+#define TUTORIAL_CATEGORY_EXPLORE "explore"
+#define TUTORIAL_CATEGORY_BODY "body"
+#define TUTORIAL_CATEGORY_FIGHT "fight"
+#define TUTORIAL_CATEGORY_KEEP "keep"
+
+// Checklist items. An item key is written once every counted step of the item is done,
+// so later step additions don't reopen a finished item.
+#define TUTORIAL_ITEM_SHIP "vc/ship"
+#define TUTORIAL_ITEM_CONTRACT "vc/contract"
+#define TUTORIAL_ITEM_RESEARCH "vc/research"
+#define TUTORIAL_ITEM_SURVEYS "vc/surveys"
+#define TUTORIAL_ITEM_RUIN "vc/ruin"
+#define TUTORIAL_ITEM_TRADE "vc/trade"
+#define TUTORIAL_ITEM_POWER "vc/power"
+#define TUTORIAL_ITEM_CHROME "vc/chrome"
+#define TUTORIAL_ITEM_SURGERY "vc/surgery"
+#define TUTORIAL_ITEM_ZONES "vc/zones"
+#define TUTORIAL_ITEM_STORAGE "vc/storage"
+#define TUTORIAL_ITEM_REPAIR_DRONES "vc/repair_drones"
+#define TUTORIAL_ITEM_SHIP_SAVE "vc/ship_save"
+#define TUTORIAL_ITEM_VESTIGE "vc/vestige"
+#define TUTORIAL_ITEM_WEAPONS "vc/weapons"
+#define TUTORIAL_ITEM_COMBAT "vc/combat"
+#define TUTORIAL_ITEM_PIRATES "vc/pirates"
+
+// Your ship
+#define TUTORIAL_STEP_SHIP_MANAGE "vc/ship/manage"
+#define TUTORIAL_STEP_SHIP_SEARCH "vc/ship/search"
+#define TUTORIAL_STEP_SHIP_COURSE "vc/ship/course"
+#define TUTORIAL_STEP_SHIP_DOCK "vc/ship/dock"
+#define TUTORIAL_STEP_SHIP_UNDOCK "vc/ship/undock"
+#define TUTORIAL_STEP_SHIP_BUILD "vc/ship/build"
+
+// First contract
+#define TUTORIAL_STEP_CONTRACT_TAKE "vc/contract/take"
+#define TUTORIAL_STEP_CONTRACT_WORK "vc/contract/work"
+#define TUTORIAL_STEP_CONTRACT_TURN_IN "vc/contract/turn_in"
+
+// R&D setup
+#define TUTORIAL_STEP_RESEARCH_KIT "vc/research/kit"
+#define TUTORIAL_STEP_RESEARCH_SERVER "vc/research/server"
+#define TUTORIAL_STEP_RESEARCH_DISK "vc/research/disk"
+#define TUTORIAL_STEP_RESEARCH_CONSOLE "vc/research/console"
+#define TUTORIAL_STEP_RESEARCH_PROTOLATHE "vc/research/protolathe"
+#define TUTORIAL_STEP_RESEARCH_MULTITOOL "vc/research/multitool"
+#define TUTORIAL_STEP_RESEARCH_LINK "vc/research/link"
+
+// Surveys
+#define TUTORIAL_STEP_SURVEYS_NODE "vc/surveys/node"
+#define TUTORIAL_STEP_SURVEYS_BUILD "vc/surveys/build"
+#define TUTORIAL_STEP_SURVEYS_SURVEY "vc/surveys/survey"
+#define TUTORIAL_STEP_SURVEYS_NOTES "vc/surveys/notes"
+
+// Planet ruin
+#define TUTORIAL_STEP_RUIN_LAND "vc/ruin/land"
+#define TUTORIAL_STEP_RUIN_FIND "vc/ruin/find"
+#define TUTORIAL_STEP_RUIN_CACHE "vc/ruin/cache"
+
+// Outpost trade
+#define TUTORIAL_STEP_TRADE_TRAVEL "vc/trade/travel"
+#define TUTORIAL_STEP_TRADE_ELEVATOR "vc/trade/elevator"
+#define TUTORIAL_STEP_TRADE_BUY "vc/trade/buy"
+#define TUTORIAL_STEP_TRADE_SELL "vc/trade/sell"
+
+// Ship power
+#define TUTORIAL_STEP_POWER_SMES "vc/power/smes"
+#define TUTORIAL_STEP_POWER_GENERATOR "vc/power/generator"
+#define TUTORIAL_STEP_POWER_APC "vc/power/apc"
+
+// Cyberware
+#define TUTORIAL_STEP_CHROME_BUY "vc/chrome/buy"
+#define TUTORIAL_STEP_CHROME_INSTALL "vc/chrome/install"
+#define TUTORIAL_STEP_CHROME_EXECUTE "vc/chrome/execute"
+
+// First surgery
+#define TUTORIAL_STEP_SURGERY_START "vc/surgery/start"
+#define TUTORIAL_STEP_SURGERY_FINISH "vc/surgery/finish"
+#define TUTORIAL_STEP_SURGERY_DISSECT "vc/surgery/dissect"
+
+// Zones
+#define TUTORIAL_STEP_ZONES_YELLOW "vc/zones/yellow"
+#define TUTORIAL_STEP_ZONES_WARFARE "vc/zones/warfare"
+#define TUTORIAL_STEP_ZONES_RED "vc/zones/red"
+
+// Storage
+#define TUTORIAL_STEP_STORAGE_SHELF "vc/storage/shelf"
+#define TUTORIAL_STEP_STORAGE_CRATE "vc/storage/crate"
+#define TUTORIAL_STEP_STORAGE_LOCKER "vc/storage/locker"
+#define TUTORIAL_STEP_STORAGE_STORE "vc/storage/store"
+
+// Repair drones
+#define TUTORIAL_STEP_REPAIR_DRONES_RESEARCH "vc/repair_drones/research"
+#define TUTORIAL_STEP_REPAIR_DRONES_ASSEMBLE "vc/repair_drones/assemble"
+#define TUTORIAL_STEP_REPAIR_DRONES_LINK "vc/repair_drones/link"
+#define TUTORIAL_STEP_REPAIR_DRONES_REPAIR "vc/repair_drones/repair"
+
+// Save your ship
+#define TUTORIAL_STEP_SHIP_SAVE_DOCK "vc/ship_save/dock"
+#define TUTORIAL_STEP_SHIP_SAVE_SAVE "vc/ship_save/save"
+#define TUTORIAL_STEP_SHIP_SAVE_LOAD "vc/ship_save/load"
+
+// Vestige pact
+#define TUTORIAL_STEP_VESTIGE_FIND "vc/vestige/find"
+#define TUTORIAL_STEP_VESTIGE_PACT "vc/vestige/pact"
+#define TUTORIAL_STEP_VESTIGE_TRIAL "vc/vestige/trial"
+#define TUTORIAL_STEP_VESTIGE_CLAIM "vc/vestige/claim"
+
+// Ship weapons
+#define TUTORIAL_STEP_WEAPONS_CONSOLE "vc/weapons/console"
+#define TUTORIAL_STEP_WEAPONS_LAUNCHER "vc/weapons/launcher"
+#define TUTORIAL_STEP_WEAPONS_MISSILE "vc/weapons/missile"
+#define TUTORIAL_STEP_WEAPONS_LASER "vc/weapons/laser"
+#define TUTORIAL_STEP_WEAPONS_SHIELD "vc/weapons/shield"
+#define TUTORIAL_STEP_WEAPONS_INTERDICTOR "vc/weapons/interdictor"
+#define TUTORIAL_STEP_WEAPONS_EW "vc/weapons/ew"
+
+// Ship combat
+#define TUTORIAL_STEP_COMBAT_INTERDICT "vc/combat/interdict"
+#define TUTORIAL_STEP_COMBAT_MISSILE "vc/combat/missile"
+#define TUTORIAL_STEP_COMBAT_SHIELDS "vc/combat/shields"
+#define TUTORIAL_STEP_COMBAT_HACK "vc/combat/hack"
+#define TUTORIAL_STEP_COMBAT_FORCE_DOCK "vc/combat/force_dock"
+
+// Hunting pirates
+#define TUTORIAL_STEP_PIRATES_HAIL "vc/pirates/hail"
+#define TUTORIAL_STEP_PIRATES_BOARDERS "vc/pirates/boarders"
+#define TUTORIAL_STEP_PIRATES_COMMANDER "vc/pirates/commander"
+#define TUTORIAL_STEP_PIRATES_BOARD "vc/pirates/board"
+#define TUTORIAL_STEP_PIRATES_SHOOT "vc/pirates/shoot"
+#define TUTORIAL_STEP_PIRATES_BOUNTY "vc/pirates/bounty"
+#define TUTORIAL_STEP_PIRATES_CLAIM "vc/pirates/claim"
+
+/// Prefix shared by every Voidcrew tutorial key in `tutorial_completions`.
+#define TUTORIAL_KEY_PREFIX "vc/"
diff --git a/voidcrew/edits/mobs/new_player.dm b/voidcrew/edits/mobs/new_player.dm
index 01599264307..53f1870a009 100644
--- a/voidcrew/edits/mobs/new_player.dm
+++ b/voidcrew/edits/mobs/new_player.dm
@@ -365,9 +365,8 @@
if(joined_ship.memo && humanc)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(show_ship_memo_to_player), humanc, joined_ship), 3 SECONDS)
- // First spawn of the round gets the orientation briefing, a beat after the
- // memo (voidcrew/modules/onboarding/orientation.dm)
- try_show_orientation_briefing(character)
+ // Tutorial checklist, a beat after the memo (voidcrew/modules/tutorials)
+ try_show_tutorial_checklist(character)
return TRUE
diff --git a/voidcrew/icons/hud/tutorial_arrow.dmi b/voidcrew/icons/hud/tutorial_arrow.dmi
new file mode 100644
index 00000000000..8251e02bc78
Binary files /dev/null and b/voidcrew/icons/hud/tutorial_arrow.dmi differ
diff --git a/voidcrew/modules/bounties/bounty_ai.dm b/voidcrew/modules/bounties/bounty_ai.dm
index a6f4a76f3b5..fae4bba47fb 100644
--- a/voidcrew/modules/bounties/bounty_ai.dm
+++ b/voidcrew/modules/bounties/bounty_ai.dm
@@ -229,7 +229,8 @@
* player's is. Returns that delay.
*/
/proc/bounty_ai_note_step(mob/living/mover, direction)
- var/delay = max(mover.cached_multiplicative_slowdown, world.tick_lag)
+ // Its own clock's delay: a slow-mo pushes BB_BOUNTY_NEXT_STEP_AT back, so the slow-mo's drag on the walk isn't counted twice
+ var/delay = max(cyberware_undilated_slowdown(mover), world.tick_lag)
if(ISDIAGONALDIR(direction))
delay *= sqrt(2)
var/datum/ai_controller/controller = mover.ai_controller
diff --git a/voidcrew/modules/bounties/bounty_boss.dm b/voidcrew/modules/bounties/bounty_boss.dm
index 5ada259688a..1f7a7616e66 100644
--- a/voidcrew/modules/bounties/bounty_boss.dm
+++ b/voidcrew/modules/bounties/bounty_boss.dm
@@ -319,7 +319,7 @@ GLOBAL_LIST_EMPTY(bounty_boss_barricades)
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, BOUNTY_BOSS_BUSY_TRAIT)
ai_controller?.CancelActions()
if(duration)
- boss_busy_timer = addtimer(CALLBACK(src, PROC_REF(boss_clear_busy), boss_busy_serial), duration, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ boss_busy_timer = addtimer(CALLBACK(src, PROC_REF(boss_clear_busy), boss_busy_serial), cyberware_dilated_time(src, duration), TIMER_STOPPABLE | TIMER_DELETE_ME)
return boss_busy_serial
/// Free again, unless `serial` is stale
@@ -1351,7 +1351,7 @@ GLOBAL_LIST_EMPTY(bounty_boss_barricades)
playsound(src, 'sound/machines/piston/piston_raise.ogg', 60, TRUE)
add_filter(BOUNTY_BOSS_SMASH_FILTER, 2, outline_filter(1, BOUNTY_BOSS_SMASH_COLOR))
boss_smash_mark = WEAKREF(new /obj/effect/temp_visual/bounty_boss_mark(get_turf(barrier), smash_time, BOUNTY_BOSS_SMASH_COLOR))
- addtimer(CALLBACK(src, PROC_REF(boss_smash_blow), serial), BOUNTY_BOSS_SMASH_WINDUP, TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(boss_smash_blow), serial), cyberware_dilated_time(src, BOUNTY_BOSS_SMASH_WINDUP), TIMER_DELETE_ME)
return TRUE
/**
@@ -1387,7 +1387,7 @@ GLOBAL_LIST_EMPTY(bounty_boss_barricades)
if(QDELETED(barrier) || !barrier.density || boss_smash_blows >= BOUNTY_BOSS_SMASH_MOST_BLOWS)
boss_end_smash(serial)
return threw
- addtimer(CALLBACK(src, PROC_REF(boss_smash_blow), serial), boss_smash_wait(), TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(boss_smash_blow), serial), cyberware_dilated_time(src, boss_smash_wait()), TIMER_DELETE_ME)
return threw
/// How long until it can throw its next smash punch: its body's click and the soonest arm's own cooldown, at least a tick
@@ -1603,7 +1603,7 @@ GLOBAL_LIST_EMPTY(bounty_boss_barricades)
boss.face_atom(target)
boss.boss_bark("ability")
telegraph(target)
- addtimer(CALLBACK(src, PROC_REF(finish_windup), serial), windup, TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(finish_windup), serial), cyberware_dilated_time(boss, windup), TIMER_DELETE_ME) // slower in a slow-mo
return TRUE
/**
@@ -2212,3 +2212,14 @@ GLOBAL_LIST_EMPTY(bounty_boss_barricades)
#undef BOUNTY_BOSS_BUSY_TRAIT
#undef BOUNTY_BOSS_BUSY_SMASH
#undef BOUNTY_BOSS_SMASH_FILTER
+
+// A slow-mo field pushes its own clocks back with the rest of its deadlines (ware_sandy_timestop.dm, push_deadlines())
+/mob/living/carbon/human/npc/bounty_criminal/boss/cyberware_push_clocks(push)
+ . = ..()
+ var/now = world.time
+ if(boss_next_ability_at > now)
+ boss_next_ability_at += push
+ if(boss_fallback_until > now)
+ boss_fallback_until += push
+ if(boss_cover_rethink_at > now)
+ boss_cover_rethink_at += push
diff --git a/voidcrew/modules/bounties/bounty_chrome.dm b/voidcrew/modules/bounties/bounty_chrome.dm
index faf8dc603f3..429cf42721a 100644
--- a/voidcrew/modules/bounties/bounty_chrome.dm
+++ b/voidcrew/modules/bounties/bounty_chrome.dm
@@ -1084,7 +1084,7 @@ GLOBAL_LIST_EMPTY(bounty_chrome_organ_facts)
if(target)
npc.face_atom(target)
move.tell(target)
- tell_timer = addtimer(CALLBACK(src, PROC_REF(finish_tell), tell_serial), max(move.tell_time, BOUNTY_CHROME_TELL_MIN), TIMER_STOPPABLE | TIMER_DELETE_ME)
+ tell_timer = addtimer(CALLBACK(src, PROC_REF(finish_tell), tell_serial), cyberware_dilated_time(parent, max(move.tell_time, BOUNTY_CHROME_TELL_MIN)), TIMER_STOPPABLE | TIMER_DELETE_ME)
return TRUE
/// The tell under `serial` is over: the move fires, if its owner can still act
@@ -1448,3 +1448,33 @@ GLOBAL_LIST_EMPTY(bounty_chrome_organ_facts)
if(isturf(npc.loc) && !npc.buckled && npc.body_position == STANDING_UP)
npc.face_atom(reader)
npc.say(pick("Who said you could scan me?", "Stop reading me, creep.", "Quit scanning me.", "Eyes off my chrome."), forced = "bounty chrome read")
+
+// ===== IN A SLOW-MO =====
+
+/// A slow-mo field took `push` deciseconds from the bearer (ware_sandy_timestop.dm, push_deadlines()): the moves'
+/// own clocks that haven't run out yet move back by as much.
+/datum/component/bounty_chrome/proc/cyberware_push_clocks(push)
+ if(next_move_at > world.time)
+ next_move_at += push
+ for(var/datum/bounty_chrome_move/move as anything in moves)
+ move.cyberware_push_clocks(push)
+
+/// This move's own clocks, pushed back `push` deciseconds by a slow-mo. Most moves have none.
+/datum/bounty_chrome_move/proc/cyberware_push_clocks(push)
+ return
+
+/datum/bounty_chrome_move/gorilla_punch/cyberware_push_clocks(push)
+ if(opens_at > world.time)
+ opens_at += push
+
+/datum/bounty_chrome_move/gorilla_grab/cyberware_push_clocks(push)
+ if(grab_ready_at > world.time)
+ grab_ready_at += push
+
+/datum/bounty_chrome_move/mantis_lunge/cyberware_push_clocks(push)
+ if(opens_at > world.time)
+ opens_at += push
+
+/datum/bounty_chrome_move/cascade/cyberware_push_clocks(push)
+ if(next_strafe_at > world.time)
+ next_strafe_at += push
diff --git a/voidcrew/modules/bounties/bounty_kingpin.dm b/voidcrew/modules/bounties/bounty_kingpin.dm
index 21d3a97b198..f26d06a9935 100644
--- a/voidcrew/modules/bounties/bounty_kingpin.dm
+++ b/voidcrew/modules/bounties/bounty_kingpin.dm
@@ -638,10 +638,11 @@ GLOBAL_LIST_EMPTY(bounty_kingpin_marks)
kingpin_aim_target = WEAKREF(target)
var/atom/aim_at = kingpin_crew?.shot_target(target) || target
face_atom(aim_at)
- kingpin_aim_beam = Beam(aim_at, icon_state = "infrared", time = BOUNTY_KINGPIN_REVOLVER_AIM, beam_color = COLOR_RED)
+ var/aim_time = cyberware_dilated_time(src, BOUNTY_KINGPIN_REVOLVER_AIM) // slower in a slow-mo
+ kingpin_aim_beam = Beam(aim_at, icon_state = "infrared", time = aim_time, beam_color = COLOR_RED)
visible_message(span_danger("[src] thumbs the hammer back and aims at [target]!"), vision_distance = BOUNTY_KINGPIN_SIGHT)
playsound(src, 'sound/items/weapons/gun/general/ballistic_click.ogg', 60, TRUE)
- kingpin_aim_timer = addtimer(CALLBACK(src, PROC_REF(kingpin_fire)), BOUNTY_KINGPIN_REVOLVER_AIM, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ kingpin_aim_timer = addtimer(CALLBACK(src, PROC_REF(kingpin_fire)), aim_time, TIMER_STOPPABLE | TIMER_DELETE_ME)
return TRUE
/**
@@ -2211,7 +2212,8 @@ GLOBAL_LIST_EMPTY(bounty_kingpin_marks)
return FALSE
if(next.z != crew_seat.z || get_dist(next, crew_seat) > BOUNTY_GOON_LEASH)
return FALSE
- goon.goon_next_move_at = world.time + max(BOUNTY_GOON_STEP, goon.cached_multiplicative_slowdown)
+ // Its own clock's step: a slow-mo pushes this deadline back (cyberware_push_clocks()), so it doesn't count the slow-mo's drag on the walk as well
+ goon.goon_next_move_at = world.time + max(BOUNTY_GOON_STEP, cyberware_undilated_slowdown(goon))
return goon.Move(next, get_dir(goon, next))
/// A sidestep for a clear line on `target`: an open tile next to `goon`, no further from them, from which nobody he isn't fighting is in the way
@@ -2253,12 +2255,12 @@ GLOBAL_LIST_EMPTY(bounty_kingpin_marks)
goon.goon_next_fire_at = world.time + BOUNTY_GOON_SMG_COOLDOWN
playsound(goon, 'sound/items/weapons/gun/smg/smgrack.ogg', 50, TRUE)
goon.visible_message(span_warning("[goon] brings [goon.p_their()] SMG up level."), vision_distance = COMBAT_MESSAGE_RANGE)
- goon.goon_windup_timer = addtimer(CALLBACK(src, PROC_REF(goon_finish_windup), WEAKREF(goon), WEAKREF(target)), BOUNTY_GOON_SMG_WINDUP, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ goon.goon_windup_timer = addtimer(CALLBACK(src, PROC_REF(goon_finish_windup), WEAKREF(goon), WEAKREF(target)), cyberware_dilated_time(goon, BOUNTY_GOON_SMG_WINDUP), TIMER_STOPPABLE | TIMER_DELETE_ME)
if(BOUNTY_GOON_WEAPON_SHOTGUN)
goon.goon_next_fire_at = world.time + BOUNTY_GOON_SHOTGUN_COOLDOWN
playsound(goon, 'sound/items/weapons/gun/shotgun/rack.ogg', 50, TRUE)
goon.visible_message(span_warning("[goon] pumps [goon.p_their()] shotgun."), vision_distance = COMBAT_MESSAGE_RANGE)
- goon.goon_windup_timer = addtimer(CALLBACK(src, PROC_REF(goon_finish_windup), WEAKREF(goon), WEAKREF(target)), BOUNTY_GOON_SHOTGUN_WINDUP, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ goon.goon_windup_timer = addtimer(CALLBACK(src, PROC_REF(goon_finish_windup), WEAKREF(goon), WEAKREF(target)), cyberware_dilated_time(goon, BOUNTY_GOON_SHOTGUN_WINDUP), TIMER_STOPPABLE | TIMER_DELETE_ME)
else
// Single shots off the Stechkin's own selector, in strings with a pause between them; an empty magazine reloads instead
var/obj/item/gun/ballistic/pistol = human_npc_loaded_gun(goon)
@@ -2285,7 +2287,7 @@ GLOBAL_LIST_EMPTY(bounty_kingpin_marks)
if(!goon_fire(goon, target))
return
for(var/pull in 2 to BOUNTY_GOON_SMG_BURST)
- addtimer(CALLBACK(src, PROC_REF(goon_burst_shot), goon_ref, target_ref), (pull - 1) * BOUNTY_GOON_SMG_BURST_GAP, TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(goon_burst_shot), goon_ref, target_ref), cyberware_dilated_time(goon, (pull - 1) * BOUNTY_GOON_SMG_BURST_GAP), TIMER_DELETE_ME)
/// The rest of an SMG burst, a trigger pull at a time
/datum/bounty_kingpin_crew/proc/goon_burst_shot(datum/weakref/goon_ref, datum/weakref/target_ref)
@@ -3201,3 +3203,22 @@ SUBSYSTEM_DEF(bounty_kingpin)
/// His lounge faction stays neutral; his explicit boss encounter is still profiled.
/mob/living/carbon/human/npc/bounty_criminal/kingpin/is_npc_zone_exempt()
return npc_zone_exempt || npc_spawn_context?.exempt || client || mind
+
+// ===== IN A SLOW-MO =====
+
+// The crew paces its people on clocks of its own, not their AI's: a slow-mo field pushes them back with the rest
+// of the body's deadlines (ware_sandy_timestop.dm, push_deadlines()).
+/mob/living/carbon/human/npc/bounty_kingpin_goon/cyberware_push_clocks(push)
+ . = ..()
+ var/now = world.time
+ if(goon_next_fire_at > now)
+ goon_next_fire_at += push
+ if(goon_fumbled_until > now)
+ goon_fumbled_until += push
+ if(goon_next_move_at > now)
+ goon_next_move_at += push
+
+/mob/living/carbon/human/npc/bounty_criminal/kingpin/cyberware_push_clocks(push)
+ . = ..()
+ if(kingpin_next_aim_at > world.time)
+ kingpin_next_aim_at += push
diff --git a/voidcrew/modules/bounties/bounty_lair_mafia.dm b/voidcrew/modules/bounties/bounty_lair_mafia.dm
index 4b45b10147b..bf667178cc7 100644
--- a/voidcrew/modules/bounties/bounty_lair_mafia.dm
+++ b/voidcrew/modules/bounties/bounty_lair_mafia.dm
@@ -2500,3 +2500,19 @@ GLOBAL_LIST_EMPTY(bounty_mafia_rooms)
return SUBTREE_RETURN_FINISH_PLANNING
#undef BOUNTY_MAFIA_BUSY_TRAIT
+
+// A slow-mo field pushes their own clocks back with the rest of their deadlines (ware_sandy_timestop.dm, push_deadlines())
+/mob/living/carbon/human/npc/bounty_mafia/cyberware_push_clocks(push)
+ . = ..()
+ var/now = world.time
+ if(mafia_ready_at > now)
+ mafia_ready_at += push
+ if(mafia_aim_until > now)
+ mafia_aim_until += push
+ if(mafia_next_pull_at > now)
+ mafia_next_pull_at += push
+
+/mob/living/carbon/human/npc/bounty_mafia/don/cyberware_push_clocks(push)
+ . = ..()
+ if(don_dazed_until > world.time)
+ don_dazed_until += push
diff --git a/voidcrew/modules/bounties/chrome/bounty_chrome_cascade.dm b/voidcrew/modules/bounties/chrome/bounty_chrome_cascade.dm
index b4fbd38602a..862a53012c9 100644
--- a/voidcrew/modules/bounties/chrome/bounty_chrome_cascade.dm
+++ b/voidcrew/modules/bounties/chrome/bounty_chrome_cascade.dm
@@ -60,6 +60,14 @@
return FALSE
return ..()
+/datum/bounty_chrome_move/cascade/tell(atom/target)
+ cyberware_time_untint(owner) // its glow shows through a Sandevistan's slowed world (ware_sandy_timestop.dm)
+ return ..()
+
+/datum/bounty_chrome_move/cascade/clear_tell()
+ . = ..()
+ cyberware_time_retint(owner)
+
/datum/bounty_chrome_move/cascade/tell_text(atom/target)
return "[owner]'s spine lights up with a rising whine."
diff --git a/voidcrew/modules/cyberware/chrome_cradle.dm b/voidcrew/modules/cyberware/chrome_cradle.dm
index 495bcccf1ad..e827a46f21f 100644
--- a/voidcrew/modules/cyberware/chrome_cradle.dm
+++ b/voidcrew/modules/cyberware/chrome_cradle.dm
@@ -752,6 +752,8 @@
data["projection"] = build_projection(patient, selected_ware ? available[selected_ware] : null)
data["ink"] = build_ink_data(patient)
data["tray_count"] = length(tray)
+ // Tutorial checklist: the Get it installed step pulses the part to pick, then Install.
+ data["tutorial_focus"] = tutorial_ui_focus(user, "cradle")
return data
/obj/machinery/chrome_cradle/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
diff --git a/voidcrew/modules/cyberware/cyberware_anim.dm b/voidcrew/modules/cyberware/cyberware_anim.dm
index 0284e0a0c88..5d9ba5e7c15 100644
--- a/voidcrew/modules/cyberware/cyberware_anim.dm
+++ b/voidcrew/modules/cyberware/cyberware_anim.dm
@@ -106,6 +106,9 @@
holder.RegisterSignal(bearer, COMSIG_QDELETING, TYPE_PROC_REF(/obj/effect/abstract/cyberware_anim, on_bearer_deleted))
bearer.vis_contents += holder
QDEL_IN(holder, lifetime)
+ // A Sandevistan replay plays it again (ware_sandy_replay.dm). A tick on, once the caller has placed and turned it.
+ if(length(GLOB.sandy_replays))
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(sandy_replay_made), holder), world.tick_lag)
return holder
// =========================================================================
@@ -641,16 +644,20 @@
var/ring_alpha = 235
/// How long the ring takes to roll out and fade.
var/ring_time = 0.65 SECONDS
+ /// How far the ring rolls out when it stops time (ware_sandy_timestop.dm).
+ var/stop_ring_scale = 7.5
/obj/item/organ/cyberimp/cyberware/cascade/milspec
ring_scale = 2.7
ring_alpha = 190
ring_time = 0.55 SECONDS
+ stop_ring_scale = 6.5
/obj/item/organ/cyberimp/cyberware/cascade/street
ring_scale = 2.2
ring_alpha = 140
ring_time = 0.45 SECONDS
+ stop_ring_scale = 5.5
/obj/item/organ/cyberimp/cyberware/cascade/cyberware_worn_key()
return "[..()]-[node_look]"
@@ -735,8 +742,20 @@
/obj/item/organ/cyberimp/cyberware/cascade/proc/roll_ring()
ring_timer = null
var/turf/here = get_turf(owner)
- if(here)
- new /obj/effect/temp_visual/cyberware_time_ring(here, ring_scale, ring_alpha, ring_time)
+ if(!here)
+ return
+ new /obj/effect/temp_visual/cyberware_time_ring(here, ring_scale, ring_alpha, ring_time)
+
+/// The world slows as the window opens: the green ring rolls out past the edge of the screen at once, with the
+/// tint behind its front, instead of waiting for the last spine node.
+/obj/item/organ/cyberimp/cyberware/cascade/proc/roll_stop_ring()
+ if(ring_timer)
+ deltimer(ring_timer)
+ ring_timer = null
+ var/turf/here = get_turf(owner)
+ if(!here)
+ return
+ new /obj/effect/temp_visual/cyberware_time_ring(here, stop_ring_scale, ring_alpha, ring_time, TRUE)
/// The crash: nodes die hips to neck and stay dark.
/obj/item/organ/cyberimp/cyberware/cascade/proc/play_crash()
@@ -784,9 +803,11 @@
randomdir = FALSE
duration = 0.65 SECONDS
-/obj/effect/temp_visual/cyberware_time_ring/Initialize(mapload, max_scale = 3.3, peak_alpha = 235, ring_time = 0.65 SECONDS)
+/obj/effect/temp_visual/cyberware_time_ring/Initialize(mapload, max_scale = 3.3, peak_alpha = 235, ring_time = 0.65 SECONDS, green = FALSE)
duration = ring_time
. = ..()
+ if(green)
+ color = cyberware_time_stop_green()
add_overlay(emissive_appearance(icon, icon_state, src))
transform = matrix().Scale(0.2)
alpha = peak_alpha
diff --git a/voidcrew/modules/cyberware/cyberware_anim2.dm b/voidcrew/modules/cyberware/cyberware_anim2.dm
index 7a799de2ca7..8c8f3588f84 100644
--- a/voidcrew/modules/cyberware/cyberware_anim2.dm
+++ b/voidcrew/modules/cyberware/cyberware_anim2.dm
@@ -74,10 +74,12 @@
particles.spawning = 0
/// Grey dust kicked up by a landing or a take-off.
-/proc/cyberware_grey_dust(turf/where)
+/proc/cyberware_grey_dust(turf/where, shift_w = 0, shift_z = 0)
if(isnull(where))
return null
var/obj/effect/temp_visual/mook_dust/dust = new(where)
+ dust.pixel_w += shift_w
+ dust.pixel_z += shift_z
dust.color = list(0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.2, 0.2, 0.2, 0.33, 0.33, 0.35)
return dust
@@ -708,9 +710,13 @@
duration = 0.4 SECONDS
layer = BELOW_MOB_LAYER
-/obj/effect/temp_visual/circle_wave/cyberware_slam/Initialize(mapload, reach = 2)
+/// `shift_w`, `shift_z`: pixels from the middle of its tile (a blow on a body drawn off its tile).
+/obj/effect/temp_visual/circle_wave/cyberware_slam/Initialize(mapload, reach = 2, shift_w = 0, shift_z = 0)
amount_to_scale = reach + 0.5
- return ..()
+ pixel_w += shift_w
+ pixel_z += shift_z
+ . = ..()
+ sandy_replay_made(src) // a Sandevistan replay plays the ring again (ware_sandy_replay.dm)
/// The same ring drawn on the floor, under everyone and everything standing in its way, whichever side of the
/// landing they are on. The Piledriver's own; the plain one is also what a Gorilla fist throws.
@@ -727,7 +733,9 @@
randomdir = FALSE
duration = 8 SECONDS
-/obj/effect/temp_visual/cyberware_impact_cracks/Initialize(mapload, state = "damaged1", peak_alpha = 255)
+/obj/effect/temp_visual/cyberware_impact_cracks/Initialize(mapload, state = "damaged1", peak_alpha = 255, shift_w = 0, shift_z = 0)
+ pixel_w += shift_w
+ pixel_z += shift_z
. = ..()
var/turf/here = loc
// Nothing to crack in space, open air or a chasm.
@@ -735,6 +743,7 @@
return INITIALIZE_HINT_QDEL
icon_state = state
alpha = peak_alpha
+ sandy_replay_made(src) // a Sandevistan replay plays the cracks again, from this look (ware_sandy_replay.dm)
animate(src, alpha = peak_alpha, time = duration - 2 SECONDS)
animate(alpha = 0, time = 2 SECONDS)
diff --git a/voidcrew/modules/cyberware/icons/sandy_weather.dmi b/voidcrew/modules/cyberware/icons/sandy_weather.dmi
new file mode 100644
index 00000000000..4d3f4fae89a
Binary files /dev/null and b/voidcrew/modules/cyberware/icons/sandy_weather.dmi differ
diff --git a/voidcrew/modules/cyberware/ware_legend.dm b/voidcrew/modules/cyberware/ware_legend.dm
index 58e909208b7..1e3d70afddb 100644
--- a/voidcrew/modules/cyberware/ware_legend.dm
+++ b/voidcrew/modules/cyberware/ware_legend.dm
@@ -26,12 +26,27 @@
#define CYBERWARE_CASCADE_CRIT_BONUS 18
/// Stamina dumped by the crash.
#define CYBERWARE_CASCADE_CRASH_STAMINA 80
-/// Degrees the afterimage hue moves per step of the trail.
-#define CYBERWARE_CASCADE_HUE_STEP 25
/// Melee-cooldown multiplier during the window (lower is faster).
#define CYBERWARE_CASCADE_MELEE_MULT 0.5
-/// Starting opacity of a trail afterimage.
-#define CYBERWARE_CASCADE_AFTERIMAGE_ALPHA 200
+// The trail. Not undefined at the end of this file: the replay draws the same trail (ware_sandy_replay.dm).
+/// Starting opacity of a trail afterimage (the newest); each older one is fainter, down to nothing at the tail.
+#define CYBERWARE_CASCADE_AFTERIMAGE_ALPHA 230
+/// Afterimages on screen at once behind a Cascade bearer who keeps moving.
+#define CYBERWARE_CASCADE_TRAIL_LENGTH 20
+/// Afterimages the Cascade leaves per tile walked: one on the tile left, the rest spread along the step.
+#define CYBERWARE_CASCADE_TRAIL_PER_TILE 2
+/// The longest one step counts for in a trail's life (the first step, or one after a pause).
+#define CYBERWARE_CASCADE_TRAIL_STEP_MAX (0.4 SECONDS)
+// The trail's colours by an afterimage's age, newest to oldest: each one starts on the first and runs through them to the
+// last as it fades, so a whole trail reads first to last from the bearer's heels (cyberware_cascade_trail_tints()).
+/// The newest afterimage: the Sandevistan's own green.
+#define CYBERWARE_CASCADE_TRAIL_COLOR_NEWEST "#5AFF96"
+/// A third of the way through its life.
+#define CYBERWARE_CASCADE_TRAIL_COLOR_YOUNG "#3C8CFF"
+/// Two thirds of the way.
+#define CYBERWARE_CASCADE_TRAIL_COLOR_OLD "#A050FF"
+/// The oldest, just before it is gone.
+#define CYBERWARE_CASCADE_TRAIL_COLOR_OLDEST "#FF5AC8"
/**
* # Cascade Lattice (T4, chest, OS slot, load 12)
@@ -82,14 +97,30 @@
var/window_melee_mult = CYBERWARE_CASCADE_MELEE_MULT
/// The bearer's screen tint during the window.
var/datum/client_colour/window_colour = /datum/client_colour/cyberware_cascade
- /// A trail afterimage is left on every Nth step.
- var/afterimage_interval = 1
+ /// Afterimages on screen at once behind a bearer who keeps moving.
+ var/trail_length = CYBERWARE_CASCADE_TRAIL_LENGTH
+ /// Afterimages left per tile walked.
+ var/trail_per_tile = CYBERWARE_CASCADE_TRAIL_PER_TILE
/// Starting opacity of a trail afterimage.
var/afterimage_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA
/// The status alert shown while the window runs.
var/window_alert = /atom/movable/screen/alert/status_effect/cyberware_cascade
/// What the bearer reads on activation.
var/online_message = "CASCADE ONLINE."
+ /// The bearer's balloons as the window opens and as the crash lands, and what they call the part in chat.
+ var/online_balloon = "cascade online"
+ var/crash_balloon = "cascade crash!"
+ var/part_word = "lattice"
+ /// What the bearer's balloons call the part ("cascade online", "rig still cycling!"). Read through sandy_part_balloon_word().
+ var/balloon_word = "cascade"
+ /// How long the window lasts when it slows the world (no other player near, ware_sandy_timestop.dm). A plain
+ /// surge, or one that a player cuts short, lasts window_duration.
+ var/slowmo_duration = 13 SECONDS
+ /// How fast the world runs through the window when no other player is near (ware_sandy_timestop.dm).
+ var/dilation_scale = 0.1
+ /// How much faster than normal the bearer runs in the window. A surging mob in someone else's field runs at its
+ /// multiplier over theirs.
+ var/time_multiplier = 10
/obj/item/organ/cyberimp/cyberware/cascade/on_mob_remove(mob/living/carbon/organ_owner, special = FALSE, movement_flags)
. = ..()
@@ -112,11 +143,17 @@
var/datum/status_effect/cyberware_cascade_window/window = owner.has_status_effect(/datum/status_effect/cyberware_cascade_window)
if(!window)
return
- to_chat(owner, span_userdanger("The pulse rips through the lattice mid-cascade, everything slams back to real time!"))
+ to_chat(owner, span_userdanger("The pulse rips through the [part_word] mid-surge, everything slams back to real time!"))
owner.remove_status_effect(/datum/status_effect/cyberware_cascade_window) // on_remove applies the crash
for(var/datum/action/cooldown/cyberware/cascade_surge/surge in actions)
surge.StartCooldown()
+/// What `user`'s balloons call their reflex part: "cascade" on the top model, "lattice" on the service model, "rig" on the street model.
+/proc/sandy_part_balloon_word(mob/living/user)
+ var/mob/living/carbon/carbon_user = user
+ var/obj/item/organ/cyberimp/cyberware/cascade/part = iscarbon(carbon_user) ? (locate(/obj/item/organ/cyberimp/cyberware/cascade) in carbon_user.organs) : null
+ return part?.balloon_word || "cascade"
+
/datum/action/cooldown/cyberware/cascade_surge
name = "Cascade Surge"
desc = "Eight seconds of overwhelming speed: melee cooldowns halved, hits land harder, and a 60% chance to dodge blows, or ranged fire on the move. Then six seconds of crash."
@@ -125,12 +162,41 @@
cooldown_time = 60 SECONDS
click_to_activate = FALSE
+/// Whether a press now would end a running window: a player's own press only. An NPC's AI never turns its surge off.
+/datum/action/cooldown/cyberware/cascade_surge/proc/can_cut_short()
+ if(!isliving(owner))
+ return FALSE
+ var/mob/living/surger = owner
+ return !!surger.ckey && !!surger.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/// The cooldown starts as the window opens, so pressing again to end the window early looks past it.
+/datum/action/cooldown/cyberware/cascade_surge/IsAvailable(feedback = FALSE)
+ // Not while a replay holds him: a surge fired under it would run through it
+ if(isliving(owner) && (HAS_TRAIT_FROM(owner, TRAIT_INCAPACITATED, "sandy_replay") || sandy_replay_showing(owner)))
+ return FALSE
+ if(!can_cut_short())
+ return ..()
+ var/cooldown_end = next_use_time
+ next_use_time = 0
+ . = ..()
+ next_use_time = cooldown_end
+
/datum/action/cooldown/cyberware/cascade_surge/Activate(atom/target)
if(!isliving(owner))
return FALSE
var/mob/living/surger = owner
- if(surger.has_status_effect(/datum/status_effect/cyberware_cascade_window) || surger.has_status_effect(/datum/status_effect/cyberware_cascade_crash))
- surger.balloon_alert(surger, "lattice still cycling!")
+ if(HAS_TRAIT_FROM(surger, TRAIT_INCAPACITATED, "sandy_replay") || sandy_replay_showing(surger))
+ return FALSE
+ if(can_cut_short()) // the second press: back to real time, and the crash
+ var/datum/status_effect/cyberware_cascade_window/window = surger.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ if(window.time_stop)
+ window.slowmo_time_up() // a slow-mo waits for an execution in progress (ware_sandy_timestop.dm)
+ else
+ qdel(window)
+ return TRUE
+ // A member of a shared slow-mo whose time is out waits for its crash too (ware_sandy_timestop_shared.dm).
+ if(surger.has_status_effect(/datum/status_effect/cyberware_cascade_window) || surger.has_status_effect(/datum/status_effect/cyberware_cascade_crash) || GLOB.sandy_session_of[surger])
+ surger.balloon_alert(surger, "[sandy_part_balloon_word(surger)] still cycling!")
return FALSE
StartCooldown()
// The lattice hands the window its numbers (an organ-less call falls back to the T4 defaults).
@@ -147,8 +213,6 @@
duration = CYBERWARE_CASCADE_WINDOW
tick_interval = STATUS_EFFECT_NO_TICK
alert_type = /atom/movable/screen/alert/status_effect/cyberware_cascade
- /// Hue of the next afterimage, in degrees. Starts random so no two surges match.
- var/trail_hue = 0
// The numbers below default to the T4 lattice and are overwritten from the
// organ that opened the window (see on_creation). Copied, never referenced.
/// Dodge chance while the window lives: ranged fire while moving, blows any time.
@@ -161,17 +225,26 @@
var/melee_mult = CYBERWARE_CASCADE_MELEE_MULT
/// The bearer's screen tint.
var/datum/client_colour/colour_type = /datum/client_colour/cyberware_cascade
- /// A trail afterimage is left on every Nth step.
- var/afterimage_interval = 1
+ /// Afterimages on screen at once behind a bearer who keeps moving, and how many a tile walked leaves.
+ var/trail_length = CYBERWARE_CASCADE_TRAIL_LENGTH
+ var/trail_per_tile = CYBERWARE_CASCADE_TRAIL_PER_TILE
+ /// The tile his last step left, for the afterimages spread back along that step (on_move()).
+ var/turf/trail_prev
/// Starting opacity of a trail afterimage.
var/afterimage_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA
+ /// world.time of the bearer's last step, to time the next one: the trail's life is counted in steps.
+ var/last_step_at = 0
/// What the bearer reads on activation.
var/online_message = "CASCADE ONLINE."
+ var/online_balloon = "cascade online"
/// The crash this window rolls into.
var/crash_duration = CYBERWARE_CASCADE_CRASH
var/crash_stamina = CYBERWARE_CASCADE_CRASH_STAMINA
- /// Steps taken so far, for the afterimage cadence.
- var/steps_taken = 0
+ /// Whether the surge's own speed, quicker blows, crit and dodge are on now (refresh_perks()).
+ var/perks_on = FALSE
+ /// Quicker blows stay on while a slow-mo carries the surger, apart from the other perks (decisions 22, 2026-11-12):
+ /// melee, unarmed and chrome strikes come at the window's own rate. Gun fire delay is not a click cooldown.
+ var/slowmo_quick_blows = TRUE
/// Optional second argument: the lattice whose numbers this window runs on.
/datum/status_effect/cyberware_cascade_window/on_creation(mob/living/new_owner, obj/item/organ/cyberimp/cyberware/cascade/lattice)
@@ -183,80 +256,160 @@
speed_type = lattice.window_speed
melee_mult = lattice.window_melee_mult
colour_type = lattice.window_colour
- afterimage_interval = lattice.afterimage_interval
+ trail_length = lattice.trail_length
+ trail_per_tile = lattice.trail_per_tile
afterimage_alpha = lattice.afterimage_alpha
online_message = lattice.online_message
+ online_balloon = lattice.online_balloon
crash_duration = lattice.crash_duration
crash_stamina = lattice.crash_stamina
+ dilation_scale = lattice.dilation_scale
+ time_multiplier = lattice.time_multiplier
+ slowmo_duration = lattice.slowmo_duration
return ..()
/datum/status_effect/cyberware_cascade_window/on_apply()
- trail_hue = rand(0, 359)
- owner.add_movespeed_modifier(speed_type)
owner.add_movespeed_mod_immunities(id, /datum/movespeed_modifier/reagent)
cyberware_register_dodge_source(owner, id, CALLBACK(src, PROC_REF(get_dodge_chance)), melee = TRUE)
- owner.hv_crit_set_attacker_bonus(id, crit_bonus)
RegisterSignal(owner, COMSIG_MOVABLE_MOVED, PROC_REF(on_move))
+ RegisterSignal(owner, COMSIG_LIVING_DEATH, PROC_REF(on_death))
owner.add_client_colour(colour_type, id)
- playsound(owner, 'sound/effects/magic/timeparadox2.ogg', 70, TRUE)
+ sandy_surge_sounds() // ware_sandy_sound.dm
owner.visible_message(
span_boldwarning("[owner] fractures into afterimages. Something under [owner.p_their()] skin is running far too fast!"),
span_boldnotice(online_message),
)
- owner.balloon_alert(owner, "cascade online")
+ owner.balloon_alert(owner, online_balloon)
cyberware_cascade_window_fx(owner)
+ try_time_stop() // ware_sandy_timestop.dm
+ refresh_perks()
return TRUE
/datum/status_effect/cyberware_cascade_window/on_remove()
- owner.remove_movespeed_modifier(speed_type)
+ end_time_stop()
+ sandy_sound_sync(off = TRUE, quiet = QDELETED(owner) || owner.stat == DEAD) // ware_sandy_sound.dm
+ set_perks(FALSE)
owner.remove_movespeed_mod_immunities(id, /datum/movespeed_modifier/reagent)
cyberware_unregister_dodge_source(owner, id)
- owner.hv_crit_set_attacker_bonus(id, null)
- UnregisterSignal(owner, COMSIG_MOVABLE_MOVED)
+ UnregisterSignal(owner, list(COMSIG_MOVABLE_MOVED, COMSIG_LIVING_DEATH))
owner.remove_client_colour(id)
- if(!QDELETED(owner) && owner.stat != DEAD)
+ // A slow-mo that ran to its end replays first, and the crash lands when the replay is over (ware_sandy_replay.dm).
+ if(!QDELETED(owner) && owner.stat != DEAD && !sandy_replay_defer_crash(owner, crash_duration, crash_stamina))
owner.apply_status_effect(/datum/status_effect/cyberware_cascade_crash, crash_duration, crash_stamina)
if(!QDELETED(owner))
cyberware_cascade_window_end_fx(owner)
return ..()
+/// Signal proc for [COMSIG_LIVING_DEATH]: the bearer's slow-mo ends with them (its replay still plays).
+/datum/status_effect/cyberware_cascade_window/proc/on_death(mob/living/source, gibbed)
+ SIGNAL_HANDLER
+ end_time_stop() // ware_sandy_timestop.dm
+
/// Melee cooldowns scaled for the window (changeNext_move multiplies these in).
/datum/status_effect/cyberware_cascade_window/nextmove_modifier()
- return melee_mult
+ return (perks_on || slowmo_quick_blows) ? melee_mult : 1
+
+/**
+ * The surge's own edge (speed, crit, dodge) is off while a slow-mo carries the surger: its own
+ * (ware_sandy_timestop.dm), or someone else's that runs it at its relative rate. There it moves at normal speed
+ * and only the world around it is slowed; its quicker blows stay (slowmo_quick_blows). Call whenever either changes.
+ */
+/datum/status_effect/cyberware_cascade_window/proc/refresh_perks()
+ set_perks(!time_stop && !cyberware_surge_in_field(owner))
+
+/datum/status_effect/cyberware_cascade_window/proc/set_perks(on)
+ if(on == perks_on)
+ return
+ perks_on = on
+ if(on)
+ owner.add_movespeed_modifier(speed_type)
+ owner.hv_crit_set_attacker_bonus(id, crit_bonus)
+ else
+ owner.remove_movespeed_modifier(speed_type)
+ owner.hv_crit_set_attacker_bonus(id, null)
/// Dodge-source callback for the shared arbiter: flat chance while the window
/// lives (the arbiter itself enforces the moving-only and point-blank rules
/// for shots, and the pinned rules for blows).
/datum/status_effect/cyberware_cascade_window/proc/get_dodge_chance()
- return dodge_chance
+ return perks_on ? dodge_chance : 0
-/// Signal proc for [COMSIG_MOVABLE_MOVED]: one afterimage per step, the
-/// telegraph everyone in the fight can read. Each step shifts the hue, so the
-/// trail reads as one rolling colour gradient.
+/**
+ * Signal proc for [COMSIG_MOVABLE_MOVED]: the trail, the telegraph everyone in the fight can read. Each step lays
+ * trail_per_tile afterimages along the way it came (the tile left, then evenly toward the tile reached), and each fades
+ * out over the time the bearer takes to walk trail_length of them, measured on his last step. So a bearer who keeps
+ * moving drags trail_length afterimages, newest strongest, at any speed; when he stops, the trail fades out behind him
+ * in that time. Each one's colour goes by its age (green newest, pink oldest), so the trail reads as one gradient, in
+ * his own slow-mo too.
+ */
/datum/status_effect/cyberware_cascade_window/proc/on_move(atom/movable/source, atom/old_loc, dir, forced)
SIGNAL_HANDLER
- if(!isturf(old_loc))
- return
- steps_taken++
- if(steps_taken % afterimage_interval) // cheaper chrome leaves a sparser trail
+ if(!isturf(old_loc) || owner.stat == DEAD) // a body knocked across the floor is not surging
return
- new /obj/effect/temp_visual/decoy/fading/cascade(old_loc, owner, trail_hue, afterimage_alpha)
- trail_hue = (trail_hue + CYBERWARE_CASCADE_HUE_STEP) % 360
-
-/// One afterimage in the Cascade trail, washed in a single hue.
-/obj/effect/temp_visual/decoy/fading/cascade
- duration = 8
-
-/obj/effect/temp_visual/decoy/fading/cascade/Initialize(mapload, atom/mimiced_atom, hue = 0, start_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA)
- . = ..()
- alpha = start_alpha
- color = cascade_tint_matrix(hue)
- animate(src, alpha = 0, time = duration) // restart the parent's fade from the new alpha
-
-/// Colour matrix that flattens the copy to luminance and paints it one hue,
+ var/turf/here = get_turf(owner)
+ var/step_time = world.time - last_step_at
+ last_step_at = world.time
+ sandy_step_sounds(step_time, forced) // ware_sandy_sound.dm
+ var/paused = step_time > CYBERWARE_CASCADE_TRAIL_STEP_MAX
+ if(paused) // the first step, or one after a pause: as long as a step takes him now
+ step_time = owner.cached_multiplicative_slowdown
+ step_time = clamp(step_time, world.tick_lag, CYBERWARE_CASCADE_TRAIL_STEP_MAX)
+ var/per_tile = max(1, trail_per_tile)
+ // One step longer than trail_length of them take to walk: each is laid a step behind him, on ground already crossed
+ var/life = step_time * (max(1, trail_length) / per_tile + 1)
+ var/cap = life
+ if(time_stop) // the slow-mo's trail is gone when it is: the replay draws its own
+ cap = max(duration - world.time, world.tick_lag)
+ // One on the tile he leaves, and the rest spread back along the step he took before this one. Never along the step
+ // he is taking now: he is still gliding off the tile, and they stood ahead of him. A jump, a z change or the first
+ // step after a pause leaves the one.
+ var/along = here && here.z == old_loc.z && get_dist(here, old_loc) == 1
+ var/turf/before = (along && !paused && trail_prev && trail_prev.z == old_loc.z && get_dist(trail_prev, old_loc) == 1) ? trail_prev : null
+ trail_prev = along ? old_loc : null
+ var/count = before ? per_tile : 1
+ for(var/i in 0 to count - 1)
+ var/fraction = i / per_tile
+ var/left = life - (1 + fraction) * step_time // it was passed this long ago
+ if(left <= 0)
+ continue
+ var/start_alpha = afterimage_alpha * left / life
+ var/shift_x = before ? round((before.x - old_loc.x) * fraction * ICON_SIZE_X) : 0
+ var/shift_y = before ? round((before.y - old_loc.y) * fraction * ICON_SIZE_Y) : 0
+ var/age = 1 - left / life
+ // The slow-mo's own kind keeps its colours while the world is tinted (ware_sandy_timestop.dm)
+ var/kind = time_stop ? /obj/effect/temp_visual/decoy/fading/cascade/stopped : /obj/effect/temp_visual/decoy/fading/cascade
+ new kind(old_loc, owner, age, start_alpha, min(left, cap), shift_x, shift_y, left)
+
+/// The trail's colour matrices by age, newest first (the CYBERWARE_CASCADE_TRAIL_COLOR_* defines). Shared: never edit them.
+/proc/cyberware_cascade_trail_tints()
+ var/static/list/tints
+ if(!tints)
+ tints = list()
+ for(var/colour in list(CYBERWARE_CASCADE_TRAIL_COLOR_NEWEST, CYBERWARE_CASCADE_TRAIL_COLOR_YOUNG, CYBERWARE_CASCADE_TRAIL_COLOR_OLD, CYBERWARE_CASCADE_TRAIL_COLOR_OLDEST))
+ tints += list(cyberware_cascade_tint(colour))
+ return tints
+
+/// The trail's colour matrix for an afterimage `age` (0 newest, 1 oldest) of the way through its life: between two of
+/// the trail's colours, as the client tweens it.
+/proc/cyberware_cascade_tint_at(age)
+ var/list/tints = cyberware_cascade_trail_tints()
+ var/spans = length(tints) - 1
+ var/at = clamp(age, 0, 1) * spans
+ var/index = min(round(at), spans - 1)
+ var/list/from = tints[index + 1]
+ var/list/to_tint = tints[index + 2]
+ var/blend = at - index
+ if(blend <= 0)
+ return from
+ var/list/mixed = new(length(from))
+ for(var/i in 1 to length(from))
+ mixed[i] = from[i] + (to_tint[i] - from[i]) * blend
+ return mixed
+
+/// Colour matrix that flattens a sprite to luminance and paints it `colour`,
/// with a lift so dark clothes still glow instead of going black.
-/obj/effect/temp_visual/decoy/fading/cascade/proc/cascade_tint_matrix(hue)
- var/list/tint = rgb2num(rgb(hue, 100, 100, space = COLORSPACE_HSV))
+/proc/cyberware_cascade_tint(colour)
+ var/list/tint = rgb2num(colour)
var/red = tint[1] / 255
var/green = tint[2] / 255
var/blue = tint[3] / 255
@@ -269,6 +422,66 @@
lift * red, lift * green, lift * blue,
)
+/**
+ * One afterimage in the Cascade trail, washed in one colour by its age: `age` (0 to 1) of the way through its life
+ * when laid, and `age_time` until it is oldest (its natural life left; defaults to `life`). Fades from `start_alpha`
+ * over `life`, shifted `shift_x`, `shift_y` pixels. Drawn on the floor, under everyone standing: a trail lies behind its
+ * bearer, never over him (on the game plane one a row nearer the camera would sort over him).
+ */
+/obj/effect/temp_visual/decoy/fading/cascade
+ duration = 8
+ /// The colour matrices it was given and aged through, laid colour first (for tests: the client's tween isn't readable).
+ var/list/aged_through
+
+/obj/effect/temp_visual/decoy/fading/cascade/Initialize(mapload, atom/mimiced_atom, age = 0, start_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA, life, shift_x = 0, shift_y = 0, age_time)
+ if(life)
+ duration = life // before the parent's timer and fade read it
+ . = ..()
+ // The whole look goes on in one assignment, then the fade starts on it (as the replay's afterimage does): a var set
+ // under a running fade is not drawn until the fade ends.
+ var/mutable_appearance/copy = new(src)
+ copy.pixel_w += shift_x // along the step, toward the tile reached
+ copy.pixel_z += shift_y
+ copy.alpha = start_alpha
+ copy.color = cyberware_cascade_tint_at(age)
+ copy.filters = null // the bearer's outline and tints are his, not the trail's
+ copy.appearance_flags |= KEEP_TOGETHER // the colour must reach every overlay
+ SET_PLANE_EXPLICIT(copy, FLOOR_PLANE, src)
+ copy.layer = CLEANABLE_FLOOR_OBJECT_LAYER
+ animate(src)
+ appearance = copy.appearance
+ animate(src, alpha = 0, time = duration)
+ age_colours(age, age_time || duration)
+
+/**
+ * Runs the copy's colour from the one for `age` through the trail's later colours to the oldest, reached in `age_time`,
+ * beside its fade (one parallel animate chain). Call it after the fade starts, on a look already given
+ * cyberware_cascade_tint_at(age).
+ */
+/obj/effect/temp_visual/decoy/fading/cascade/proc/age_colours(age, age_time)
+ var/list/tints = cyberware_cascade_trail_tints()
+ var/spans = length(tints) - 1
+ age = clamp(age, 0, 1)
+ aged_through = list(cyberware_cascade_tint_at(age))
+ if(age >= 1 || age_time <= 0)
+ return
+ var/per_age = age_time / (1 - age) // time per whole life
+ var/at = age
+ var/first = TRUE
+ for(var/stop in 1 to spans)
+ var/stop_age = stop / spans
+ if(stop_age <= at)
+ continue
+ var/list/tint = tints[stop + 1]
+ var/step_time = max((stop_age - at) * per_age, world.tick_lag / 10)
+ if(first)
+ animate(src, color = tint, time = step_time, flags = ANIMATION_PARALLEL)
+ first = FALSE
+ else
+ animate(color = tint, time = step_time)
+ aged_through += list(tint)
+ at = stop_age
+
/atom/movable/screen/alert/status_effect/cyberware_cascade
name = "Cascade Window"
desc = "The lattice has the world in slow motion. Make it count."
@@ -299,19 +512,19 @@
/datum/status_effect/cyberware_cascade_crash/on_apply()
owner.add_movespeed_modifier(/datum/movespeed_modifier/cyberware_cascade_crash)
owner.adjustStaminaLoss(crash_stamina)
- owner.add_client_colour(/datum/client_colour/cyberware_cascade_crash, id)
- playsound(owner, 'sound/machines/warning-buzzer.ogg', 50, TRUE)
+ var/mob/living/carbon/carbon_owner = owner
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = iscarbon(owner) ? (locate(/obj/item/organ/cyberimp/cyberware/cascade) in carbon_owner.organs) : null
+ playsound(owner, 'sound/machines/defib/defib_failed.ogg', 50, FALSE)
owner.visible_message(
span_warning("[owner] staggers, every movement suddenly leaden."),
- span_userdanger("The lattice dumps its heat. Your whole body seizes up and everything slows to a crawl."),
+ span_userdanger("The [lattice?.part_word || "lattice"] dumps its heat. Your whole body seizes up and everything slows to a crawl."),
)
- owner.balloon_alert(owner, "cascade crash!")
+ owner.balloon_alert(owner, lattice?.crash_balloon || "cascade crash!")
cyberware_cascade_crash_fx(owner)
return TRUE
/datum/status_effect/cyberware_cascade_crash/on_remove()
owner.remove_movespeed_modifier(/datum/movespeed_modifier/cyberware_cascade_crash)
- owner.remove_client_colour(id)
if(!QDELETED(owner) && owner.stat != DEAD)
owner.balloon_alert(owner, "systems restabilized")
if(!QDELETED(owner))
@@ -331,13 +544,6 @@
fade_in = 3
fade_out = 3
-/// The crash's screen: drained and gray-brown.
-/datum/client_colour/cyberware_cascade_crash
- priority = CLIENT_COLOR_ORGAN_PRIORITY
- color = list(0.55, 0.3, 0.25, 0.35, 0.55, 0.25, 0.25, 0.25, 0.5)
- fade_in = 3
- fade_out = 5
-
// =========================================================================
// REDLINE CORE
// =========================================================================
@@ -777,7 +983,6 @@
/datum/status_effect/cyberware_redline_crash/on_apply()
owner.add_movespeed_modifier(/datum/movespeed_modifier/cyberware_redline_crash)
owner.adjustStaminaLoss(stamina_dump)
- owner.add_client_colour(/datum/client_colour/cyberware_redline_crash, id)
owner.visible_message(
span_warning("[owner] sags as the red drains out of [owner.p_their()] eyes."),
span_userdanger("The core slams shut and your legs go out from under you."),
@@ -789,7 +994,6 @@
/datum/status_effect/cyberware_redline_crash/on_remove()
owner.remove_movespeed_modifier(/datum/movespeed_modifier/cyberware_redline_crash)
- owner.remove_client_colour(id)
if(!QDELETED(owner) && owner.stat != DEAD)
owner.balloon_alert(owner, "core recovered")
if(!QDELETED(owner))
@@ -806,13 +1010,6 @@
fade_in = 2
fade_out = 10
-/// The crash's screen: burnt out, brown-gray.
-/datum/client_colour/cyberware_redline_crash
- priority = CLIENT_COLOR_ORGAN_PRIORITY
- color = list(0.6, 0.35, 0.3, 0.3, 0.5, 0.25, 0.25, 0.25, 0.45)
- fade_in = 3
- fade_out = 5
-
// =========================================================================
// GOVERNOR DELETE
// =========================================================================
@@ -1111,7 +1308,10 @@
#undef CYBERWARE_CASCADE_CRASH
#undef CYBERWARE_CASCADE_DODGE_CHANCE
#undef CYBERWARE_CASCADE_CRASH_STAMINA
-#undef CYBERWARE_CASCADE_HUE_STEP
+#undef CYBERWARE_CASCADE_TRAIL_COLOR_NEWEST
+#undef CYBERWARE_CASCADE_TRAIL_COLOR_YOUNG
+#undef CYBERWARE_CASCADE_TRAIL_COLOR_OLD
+#undef CYBERWARE_CASCADE_TRAIL_COLOR_OLDEST
#undef CYBERWARE_REDLINE_WINDOW
#undef CYBERWARE_REDLINE_DAMAGE_MULT
#undef CYBERWARE_REDLINE_MELEE_BONUS
diff --git a/voidcrew/modules/cyberware/ware_line_sandy.dm b/voidcrew/modules/cyberware/ware_line_sandy.dm
index 303ff54f346..8ee243712a9 100644
--- a/voidcrew/modules/cyberware/ware_line_sandy.dm
+++ b/voidcrew/modules/cyberware/ware_line_sandy.dm
@@ -28,6 +28,15 @@
* behind the advanced step.
*/
+// The trails (ware_legend.dm has the Cascade's): afterimages on screen at once behind a bearer who keeps moving,
+// afterimages per tile walked, and the newest one's opacity.
+#define CYBERWARE_STREET_TRAIL_LENGTH 6
+#define CYBERWARE_STREET_TRAIL_PER_TILE 1
+#define CYBERWARE_STREET_AFTERIMAGE_ALPHA 140
+#define CYBERWARE_SERVICE_TRAIL_LENGTH 12
+#define CYBERWARE_SERVICE_TRAIL_PER_TILE 2
+#define CYBERWARE_SERVICE_AFTERIMAGE_ALPHA 180
+
// =========================================================================
// STREET MODEL (T2)
// =========================================================================
@@ -48,10 +57,18 @@
window_speed = /datum/movespeed_modifier/cyberware_cascade/street
window_melee_mult = 0.75
window_colour = /datum/client_colour/cyberware_cascade/street
- afterimage_interval = 3
- afterimage_alpha = 120
+ trail_length = CYBERWARE_STREET_TRAIL_LENGTH
+ trail_per_tile = CYBERWARE_STREET_TRAIL_PER_TILE
+ afterimage_alpha = CYBERWARE_STREET_AFTERIMAGE_ALPHA
window_alert = /atom/movable/screen/alert/status_effect/cyberware_cascade/aftermarket
online_message = "REFLEX RIG ONLINE."
+ online_balloon = "rig online"
+ crash_balloon = "rig burnout!"
+ part_word = "rig"
+ balloon_word = "rig"
+ slowmo_duration = 11 SECONDS
+ dilation_scale = 0.4
+ time_multiplier = 2.5
/datum/action/cooldown/cyberware/cascade_surge/street
name = "Reflex Surge"
@@ -85,10 +102,17 @@
window_speed = /datum/movespeed_modifier/cyberware_cascade/milspec
window_melee_mult = 0.6
window_colour = /datum/client_colour/cyberware_cascade/milspec
- afterimage_interval = 2
- afterimage_alpha = 160
+ trail_length = CYBERWARE_SERVICE_TRAIL_LENGTH
+ trail_per_tile = CYBERWARE_SERVICE_TRAIL_PER_TILE
+ afterimage_alpha = CYBERWARE_SERVICE_AFTERIMAGE_ALPHA
window_alert = /atom/movable/screen/alert/status_effect/cyberware_cascade/aftermarket
online_message = "LATTICE ONLINE."
+ online_balloon = "lattice online"
+ crash_balloon = "lattice crash!"
+ balloon_word = "lattice"
+ slowmo_duration = 12 SECONDS
+ dilation_scale = 0.25
+ time_multiplier = 4
/datum/action/cooldown/cyberware/cascade_surge/milspec
name = "Reflex Surge"
@@ -130,3 +154,10 @@
pay_credits = 1800
demand_min = 1
demand_max = 2
+
+#undef CYBERWARE_STREET_TRAIL_LENGTH
+#undef CYBERWARE_STREET_TRAIL_PER_TILE
+#undef CYBERWARE_STREET_AFTERIMAGE_ALPHA
+#undef CYBERWARE_SERVICE_TRAIL_LENGTH
+#undef CYBERWARE_SERVICE_TRAIL_PER_TILE
+#undef CYBERWARE_SERVICE_AFTERIMAGE_ALPHA
diff --git a/voidcrew/modules/cyberware/ware_military_arms.dm b/voidcrew/modules/cyberware/ware_military_arms.dm
index eef698851ac..d65c02aadd4 100644
--- a/voidcrew/modules/cyberware/ware_military_arms.dm
+++ b/voidcrew/modules/cyberware/ware_military_arms.dm
@@ -361,8 +361,17 @@
* guard while nothing else is going on. update_icon_state() only consults it
* when sword_color_icon is set, which it never is here.
*/
+/datum/sound_effect/cyberware_mantis_slash
+ key = CYBERWARE_MANTIS_SLASH_SOUND
+ file_paths = list(
+ 'voidcrew/sound/cyberware/mantis_slash_1.ogg',
+ 'voidcrew/sound/cyberware/mantis_slash_2.ogg',
+ 'voidcrew/sound/cyberware/mantis_slash_3.ogg',
+ )
+
/obj/item/melee/energy/blade/hardlight/cyberware_mantis
name = "mantis blade"
+ hitsound = CYBERWARE_MANTIS_SLASH_SOUND
desc = "A forearm's length of hardlight ground to a monomolecular edge. It comes out of the housing already swinging."
icon = 'voidcrew/modules/cyberware/icons/cyberware_weapons.dmi'
icon_state = "mantis"
@@ -423,10 +432,9 @@
// The worn housing sprite carries the folded blade, so it hides while the blade is out.
hide_worn_while_deployed = TRUE
items_to_create = list(/obj/item/melee/energy/blade/hardlight/cyberware_mantis)
- // A blade sliding out of a forearm housing and snapping back into it, the
- // cursed katana's pair (mining_loot/cursed_katana.dm), not a baton's ratchet.
- extend_sound = 'sound/items/unsheath.ogg'
- retract_sound = 'sound/items/sheath.ogg'
+ // The housing opening and the blade sliding out, and the blade locking back into it.
+ extend_sound = 'voidcrew/sound/cyberware/mantis_draw.ogg'
+ retract_sound = 'voidcrew/sound/cyberware/mantis_sheathe.ogg'
actions_types = list(
/datum/action/item_action/organ_action/toggle/toolkit,
/datum/action/cooldown/cyberware/mantis_lunge,
@@ -730,7 +738,7 @@
span_userdanger("[lunger] flickers across the gap. The blade is already in you, and the floor comes up fast!"),
)
log_combat(lunger, victim, charged ? "mantis-leapt" : "mantis-lunged", "mantis blades ([blades] landed)")
- playsound(victim, 'sound/items/weapons/bladeslice.ogg', 70, TRUE)
+ playsound(victim, CYBERWARE_MANTIS_SLASH_SOUND, 70, TRUE)
// =========================================================================
// WIDOWLINE MONOWIRE
diff --git a/voidcrew/modules/cyberware/ware_pro_combat.dm b/voidcrew/modules/cyberware/ware_pro_combat.dm
index 9a7e77c66a0..9301652c748 100644
--- a/voidcrew/modules/cyberware/ware_pro_combat.dm
+++ b/voidcrew/modules/cyberware/ware_pro_combat.dm
@@ -117,6 +117,8 @@
return 0
if(world.time - last_move_time > CYBERWARE_DODGE_MOVE_WINDOW)
return 0
+ if(cyberware_time_stopping(source)) // the slowed world is the dodge (ware_sandy_timestop.dm)
+ return 0
if(source.stat != CONSCIOUS || source.body_position == LYING_DOWN || source.buckled)
return 0
// Point-blank shots always land: an adjacent shooter is inside the
@@ -182,7 +184,7 @@
/// Signal proc for [COMSIG_LIVING_CHECK_BLOCK]: the melee dodge roll, from tg's own check_block().
/datum/component/cyberware_dodge/proc/on_check_block(mob/living/source, atom/hit_by, damage, attack_text, attack_type, armour_penetration, damage_type)
SIGNAL_HANDLER
- if(!length(melee_sources) || !cyberware_can_dodge_blow(source, hit_by, damage, attack_text, attack_type))
+ if(!length(melee_sources) || cyberware_time_stopping(source) || !cyberware_can_dodge_blow(source, hit_by, damage, attack_text, attack_type))
return FAILED_BLOCK
var/best_chance = best_chance(melee_sources)
if(best_chance <= 0 || !prob(best_chance))
diff --git a/voidcrew/modules/cyberware/ware_sandy_replay.dm b/voidcrew/modules/cyberware/ware_sandy_replay.dm
new file mode 100644
index 00000000000..7e37b21ad2a
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_replay.dm
@@ -0,0 +1,3394 @@
+/**
+ * # The Sandevistan replay
+ *
+ * A slow-mo (ware_sandy_timestop.dm) records how everything in its field looked and where it stood. When the
+ * slow-mo runs out, or the user ends it, the world shows it all again from the start at normal speed: a Cascade's
+ * 8 s at 20% plays back in 1.6 s. A slow-mo that another player cut short doesn't replay.
+ *
+ * Nothing is moved and nothing happens twice. Every real thing stays on the tile it really ended on. For each
+ * frame it is given the look it had then and is drawn at the spot it stood on with a pixel offset (a "puppet").
+ * Only things that are really gone (a spent shot, a gibbed body), or that ended up inside something, get a
+ * stand-in effect. When the replay ends every puppet gets its real look back.
+ *
+ * Recording: one sample per tick of the slowed world (world.tick_lag / time_scale of real time), so each sample is
+ * one tick of the replay. A sample is the thing's appearance, turf and dir, kept only when it changed. The field
+ * hands over everything it sees (freeze_atom() is the one place everything on, entering or made on a field turf
+ * goes through). The field's tint and the user's edge glow are taken out of the recorded looks.
+ *
+ * The real look under a puppet. Game code keeps changing the real things while they are drawn as something else
+ * (Life() runs on, so a body can bleed, fall, die or drop its gun mid-replay). The procs every such change goes
+ * through are wrapped at the bottom of this file: they put the real look back first, let the change land on it, and
+ * the puppet goes back on after. A change that writes vars directly is caught on the next frame by comparing the
+ * puppet with what was drawn, and the changed vars are carried over to the real look (fold()).
+ *
+ * For the length of the replay AIs are paused and the user and their crewmates can't act. Life() keeps running:
+ * this is a lock on decisions and input only, no stun and no damage. A player who isn't crew coming near ends the
+ * replay at once, a watchdog timer ends it whatever happens, and finish() can be called any number of times.
+ * A slow-mo never ends while its user is in the middle of an execution or finisher: it holds until the move is over
+ * (cyberware_cascade_window/proc/slowmo_time_up(), ware_sandy_timestop.dm), so the whole move is in the recording and
+ * the replay's hold never cuts it short. Another body still mid-move when it ends (an NPC's execution) is waited out:
+ * the world goes back to normal speed, nobody is held, and the recording runs on until the move is over
+ * (moves_running()). A move still going after SANDY_REPLAY_WAIT_MAX gets no replay at all.
+ * While any recorded body is mid-move a frame is one real tick, not one tick of the slowed world: the walk-up replays
+ * compressed, the move itself at the speed it really had, so its poses (a tick or two each) can be shown.
+ * The surge's crash starts when the replay ends. A user who went down in the slow-mo still watches it: their crit,
+ * oxygen, damage and knocked-out screens are off their view while it plays and back as it ends (clear_view()).
+ *
+ * It looks and sounds like a surge: the surge-on sound plays at the start, the sounds made in the field play again
+ * at normal pitch (playsound() hands them over), and every surger in it (the user, or a mob on its own surge) leaves
+ * the surge's afterimage trail, coloured by age. A turn of a body (a fall) is tweened, as tg's lying turn is.
+ *
+ * A finisher rig hides a body and draws it as posed pictures (chrome_puppet_rig.dm, mantis_rig.dm). Those pictures are
+ * recorded like anything else, and the animate() chains that pose them are journaled (sandy_replay_animate(), routed
+ * there by a macro in the rig and finisher files) and played again on their stand-ins: the replay shows the move.
+ *
+ * Not replayed (they show as they really are): lights other than flashes lit on the floor (note_light()), fire, smoke and particles, turf changes, attack lunges,
+ * flick()s, tweens on bodies other than steps and turns (flinches, a gun execution's lean, the spin and arc of flying
+ * gore, blood drying and spreading), anything in vis_contents, runechat, camera shakes, and looping sounds.
+ */
+
+/// Trait source of the replay's AI pause and input lock.
+#define SANDY_REPLAY_TRAIT "sandy_replay"
+/// The user's edge glow in a slow-mo (SANDY_STOP_OUTLINE in ware_sandy_timestop.dm, which is included after this file).
+#define SANDY_REPLAY_OUTLINE "sandy_time_stop_outline"
+/// The slow-mo's tint filter on bodies and items (SANDY_STOP_TINT in ware_sandy_timestop.dm).
+#define SANDY_REPLAY_TINT "sandy_time_stop_tint"
+/// The filter that hides what turned up after the recording, for the length of the replay.
+#define SANDY_REPLAY_UNBORN "sandy_replay_unborn"
+/// Filter name hiding what the recording saw change, in the tick between the slow-mo's end and the replay's start.
+#define SANDY_REPLAY_PENDING_HIDE "sandy_replay_pending_hide"
+/// Fullscreen category of the slow-mo's release flash (SANDY_STOP_FLASH in ware_sandy_timestop.dm).
+#define SANDY_REPLAY_RELEASE_FLASH "sandy_time_stop_flash"
+
+#define SANDY_REPLAY_RECORDING 1
+#define SANDY_REPLAY_PENDING 2
+#define SANDY_REPLAY_PLAYING 3
+#define SANDY_REPLAY_DONE 4
+
+#define SANDY_TRACK_PUPPET 1
+#define SANDY_TRACK_STANDIN 2
+
+/// The furthest from its real tile a puppet is drawn, in tiles. Past it the thing is hidden for that frame.
+#define SANDY_REPLAY_REACH 24
+/// The longest move between two frames that is tweened, in pixels. Longer ones are jumps.
+#define SANDY_REPLAY_GLIDE_MAX 96
+/// The same for a surger. One frame is half a second of a Cascade's slow-mo: at a run he crosses three or four tiles in
+/// it, and a lunge on top of that is more. Counted as a jump, he blinked across the room in the replay with no trail.
+#define SANDY_REPLAY_SURGE_GLIDE_MAX 256
+/// The most steps kept for a surger between two frames. More than that and the trail is laid in a straight line.
+#define SANDY_REPLAY_PATH_MAX 16
+/// Extra time the watchdog gives the replay before it ends it.
+#define SANDY_REPLAY_WATCHDOG (1 SECONDS)
+/// How long a recorded turn of a body (a fall, getting up) takes in the replay: tg's own lying turn.
+#define SANDY_REPLAY_TURN_TIME 2
+/// The most times a replay plays a surger's external cue as he bursts off (surger_frame()).
+#define SANDY_REPLAY_BURST_CUES_MAX 6
+/// Everyone and everything within this many tiles of the user holds still for the replay (the slow-mo's witness range:
+/// any other player this close is crew, or there would be no replay).
+#define SANDY_REPLAY_HOLD_RANGE 11
+/// How far from a surger a recording takes what calls sandy_replay_made(): a slowed room reaches 16 tiles from him
+/// (SANDY_COVER_ROOM_REACH), and a blow throws blood five tiles on.
+#define SANDY_REPLAY_MADE_REACH 21
+/// The longest the replay stays on its last frame while gore from a kill in its last moments lands (land()).
+#define SANDY_REPLAY_LANDING_MAX (1.5 SECONDS)
+/// The longest of that it waits for its own animations of that gore to play out, before the real gore flies on.
+#define SANDY_REPLAY_LANDING_TWEENS (0.5 SECONDS)
+/// A kill this close to the recording's end, in its frames, has its gore landed for it.
+#define SANDY_REPLAY_LANDING_FRAMES 10
+/// How long a slash over someone hit stays in the replay once shown: through its strike frames. Its whole length
+/// (0.4 s) left it hanging on the body well after the replayed attacker had gone, and read as a slash from nowhere.
+#define SANDY_REPLAY_PICTURE_TIME (0.2 SECONDS)
+/// The most sounds one recording keeps of the world around the user (footsteps, casings, NPCs' guns).
+#define SANDY_REPLAY_MAX_SOUNDS 200
+/// The most it keeps in all: past SANDY_REPLAY_MAX_SOUNDS only the user's and its crewmates' own sounds go in (their
+/// blows, shots and steps, and anything on the user's own or next tile), so a busy room can't crowd out the fight.
+#define SANDY_REPLAY_MAX_OWN_SOUNDS 500
+/// Recorded sounds play this loud in the replay: under the surge's own sound, which leads it.
+#define SANDY_REPLAY_SOUND_VOLUME 0.6
+/// One sound file starting again this soon in the replay is skipped: thirteen seconds of fight squeezed into one
+/// would otherwise pile the same shot or step on itself.
+#define SANDY_REPLAY_SOUND_GAP (2 * world.tick_lag)
+/// The longest the replay waits, after the slow-mo, for an execution or finisher in it to end. A move still going
+/// then gets no replay rather than being cut short by the replay's hold.
+#define SANDY_REPLAY_WAIT_MAX (8 SECONDS)
+/// How long past its due time a corpse's slide is still waited for (sandy_replay_falling()).
+#define SANDY_REPLAY_FALL_SLACK (1 SECONDS)
+/// The most replay ticks a corpse's own glide is played over (track.glides).
+#define SANDY_REPLAY_CORPSE_GLIDE_MAX 12
+/// The filters the finisher rigs hide a body under while its posed pictures stand in for it (CHROME_RIG_HIDE_FILTER in
+/// chrome_puppet_rig.dm, MANTIS_RIG_HIDE_FILTER in mantis_rig.dm). A body wearing one is in the middle of a move.
+#define SANDY_REPLAY_RIG_HIDES list("chrome_rig_hide", "mantis_rig_hide")
+
+/// The most shots in the air one recording follows at once. A room's worth of rounds is far fewer; past it a new shot is
+/// left out of the replay and the recording says so (shots_capped, and once in the game log).
+#define SANDY_REPLAY_MAX_SHOTS 64
+
+/// The shortest a one-shot effect's animation plays in the replay: two frames. Compressed ten times a muzzle flash or an
+/// impact ring would be over between two frames and never drawn. Longer and it hangs behind the action it belongs to.
+#define SANDY_REPLAY_ONESHOT_MIN (world.tick_lag * 2)
+/// The fewest frames a one-shot effect that only plays its icon's own frames (a muzzle flash) is drawn for.
+#define SANDY_REPLAY_ONESHOT_FRAMES 2
+
+// A track's frames are a flat list, this many entries a frame.
+#define SANDY_FRAME_SIZE 6
+#define SANDY_FRAME_INDEX 1
+#define SANDY_FRAME_LOOK 2
+#define SANDY_FRAME_X 3
+#define SANDY_FRAME_Y 4
+#define SANDY_FRAME_Z 5
+#define SANDY_FRAME_DIR 6
+
+/// Every replay being recorded or played, by its user.
+GLOBAL_LIST_EMPTY(sandy_replays)
+/// Every thing drawn as a puppet right now, to its track.
+GLOBAL_LIST_EMPTY(sandy_replay_masked)
+/// length(GLOB.sandy_replay_masked), as a real global: the wrappers at the bottom of this file read it on every overlay change.
+GLOBAL_REAL_VAR(sandy_replay_masks)
+/// Numbers from the last replay that finished, for tests and recordings.
+GLOBAL_LIST_EMPTY(sandy_replay_last)
+/// A replay is playing a recorded sound: nobody records it again.
+GLOBAL_VAR_INIT(sandy_replay_echoing, FALSE)
+/// A replay starting: a playsound() in its begin() goes to its viewers, from their views (sandy_replay_hear()).
+GLOBAL_DATUM(sandy_replay_routing, /datum/sandy_replay)
+/// The world.time that was set, so a start that failed partway can't route later sounds.
+GLOBAL_VAR_INIT(sandy_replay_routing_time, -1)
+#ifdef UNIT_TESTS
+/// For tests: every sound the replay played to someone, as list(listener, /sound).
+GLOBAL_LIST_EMPTY(sandy_replay_heard)
+#endif
+
+/// One recorded thing.
+/datum/sandy_replay_track
+ var/datum/sandy_replay/owner
+ /// The real thing. Null once it is deleted.
+ var/atom/movable/thing
+ /// The frame it was first seen at. Above 0 for something made, or walking in, mid-window.
+ var/first = 0
+ /// The frame it was deleted at.
+ var/last = INFINITY
+ /// Flat list of frames: index, look, x, y, z (0 when not on a turf), dir.
+ var/list/frames = list()
+ /// Recorder: the thing's raw appearance at the last sample.
+ var/last_raw
+ /// It was on a surge during the window: the user, or a mob on its own surge in the field.
+ var/surger = FALSE
+ /// Surger: the frames its own surge ran between. A crewmate walks in before he surges, and goes on slowed after his
+ /// own time is out while the shared slow-mo runs: those steps leave no trail (surger_frame()).
+ var/surge_from = 0
+ var/surge_until = INFINITY
+ /// Surger: its surge's trail (ware_legend.dm): afterimages behind it while it moves, per tile, and the newest one's alpha.
+ var/trail_length = CYBERWARE_CASCADE_TRAIL_LENGTH
+ var/trail_per_tile = CYBERWARE_CASCADE_TRAIL_PER_TILE
+ var/trail_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA
+ /// Surger: whether the trail's numbers were read from its window yet.
+ var/trail_read = FALSE
+ /// Surger: how many frames its last step took, for a step after a pause.
+ var/trail_step_frames = 0
+ /// Surger: the tile its last replayed step left, for the afterimages spread back along that step (surger_frame()).
+ var/turf/trail_prev
+ /// Recorder, surger: the tiles it stepped onto since its last frame, as flat x, y pairs (on_surger_stepped()).
+ var/list/path
+ /// Surger: the steps it took to reach a frame where it took more than one, by that frame's index as text. A corner
+ /// turned between two samples is two frames a diagonal apart: the trail goes round it as he did (surger_frame()).
+ var/list/ways
+ /// A dead body's steps: the frame it is drawn moved in, to the replay ticks the game's own glide took (sample_track()).
+ var/list/glides
+ /// Recorder, surger: the recording's clock (frame_exact()) at its last step.
+ var/stepped_at = 0
+ /// Surger: the clock at the last step it took to reach a frame, by that frame's index as text. Steps are paced by
+ /// when they were really taken: two fall in one frame and three in the next at one steady run (surger_frame()).
+ var/list/step_clock
+ /// Playback, surger: the clock of the last step replayed.
+ var/trail_stepped_at = 0
+ /// Surger: how long a step takes it (its movement delay, in deciseconds), as of its last recorded step. The live
+ /// trail gives the first step after a pause that long (cyberware_cascade_window/on_move()), and so does the replay's.
+ var/stride = 0
+ /// Playback, surger: world.time its last external cue played.
+ var/burst_cue_at = 0
+ /// Playback: a turn (transform change) being tweened: from, to, how long it takes and when it ends.
+ var/turn_from
+ var/turn_to
+ var/turn_time = 0
+ var/turn_until = 0
+ /// Playback: offset in `frames` of the frame shown before the current one.
+ var/came_from = -SANDY_FRAME_SIZE
+ /// Playback: SANDY_TRACK_PUPPET or SANDY_TRACK_STANDIN.
+ var/mode
+ /// Playback: offset in `frames` of the frame showing now. Below 0 before the first.
+ var/cursor = -SANDY_FRAME_SIZE
+ /// Playback: the tween from the last spot, in pixels still to cover at its start, and when it ends.
+ var/glide_x = 0
+ var/glide_y = 0
+ var/glide_time = 0
+ var/glide_until = 0
+ /// Playback, surger: the tween's way when it isn't a straight line (a corner turned between two frames): flat x, y
+ /// pixel offsets from where it ends, the first where it starts and the last 0, 0, each leg taking the same time.
+ var/list/glide_way
+ /// Puppet: the thing's real look, dir, opacity and luminosity.
+ var/saved_look
+ var/saved_dir
+ var/saved_opacity
+ var/saved_luminosity
+ /// Puppet: its own animate_movement, while it is set to jump because the game moved it under the replay
+ /// (on_puppet_moved()). Null when untouched.
+ var/saved_movement
+ /// Puppet: the appearance it was last drawn with, to notice changes made by anything else.
+ var/expect
+ /// Puppet: wearing its real look right now, while a wrapped proc changes it.
+ var/unmasked = FALSE
+ /// Stand-in: the effect.
+ var/obj/effect/abstract/sandy_replay_standin/standin
+ /// Animations played on the thing while it was recorded (sandy_replay_journal()), each list(frame, look before it,
+ /// time scale, list(step arguments...)).
+ var/list/events
+ /// Playback: the next animation to play, and when the ones playing end.
+ var/event_at = 1
+ var/anim_until = 0
+ /// Puppet: the chain playing on it (its animate() argument lists), when it started and the pixel shift it was
+ /// played with: a redraw mid-chain (a new frame's look) plays the rest of it again (resume_chain()).
+ var/list/chain
+ var/chain_start = 0
+ var/list/chain_shift
+ /// Playback: the look the stand-in was last given.
+ var/drawn_look
+ /// A shot (a projectile): it flies in a line between its frames, a frame at a time (fly()).
+ var/flier = FALSE
+ /// A one-shot effect (a temp visual: a muzzle flash, an impact ring, cracks): its animations play for at least
+ /// SANDY_REPLAY_ONESHOT_MIN, so a compressed one is drawn at all, and its stand-in stays until they are done.
+ var/oneshot = FALSE
+ /// Gore handed back early, flying on for real under the replay's last frame (land()): the replay leaves it be.
+ var/landing = FALSE
+ /// A one-shot whose animation is its icon's own frames (a slash over someone hit): how long its stand-in stays once
+ /// shown, so the frames play through at their own pace instead of ending with the one replay frame it lasted.
+ var/plays_out = 0
+ /// Playback: the glide playing now is a step to another tile, not a pose's own shift on the spot.
+ var/glide_step = FALSE
+ /// Each shot it fired: list(the frame it is first drawn in, x, y of the real tile it was fired from), where its
+ /// muzzle flash and bullet are recorded. A step glides onto that tile by then, or they are drawn ahead of the gun
+ /// (shooting_at()).
+ var/list/shot_frames
+
+/// Carries the recorded look of something that is gone, or isn't on a turf any more.
+/obj/effect/abstract/sandy_replay_standin
+ name = ""
+ anchored = TRUE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ animate_movement = NO_STEPS
+ resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
+
+/// What the user's view follows during the replay.
+/obj/effect/abstract/sandy_replay_eye
+ name = ""
+ anchored = TRUE
+ invisibility = INVISIBILITY_ABSTRACT
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ animate_movement = NO_STEPS
+ resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
+
+/datum/sandy_replay
+ /// Whose slow-mo this is.
+ var/mob/living/user
+ /// The field being recorded. Null once it is over.
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field
+ var/state = SANDY_REPLAY_RECORDING
+ /// world.time the recording began.
+ var/started = 0
+ /// Real time between samples.
+ var/interval = 1
+ var/sample_timer
+ var/begin_timer
+ /// Things being recorded, to their tracks.
+ var/list/tracks = list()
+ /// Tracks of things deleted while recording.
+ var/list/gone = list()
+ /// The last frame's index.
+ var/total = 0
+ /// The field is moving onto new turfs: what it finds there was standing there since frame 0.
+ var/covering = FALSE
+ /// world.time playback began.
+ var/play_started = 0
+ var/play_timer
+ var/watchdog
+ /// Tracks drawn on their real things.
+ var/list/puppets = list()
+ /// Tracks drawn on stand-ins.
+ var/list/standins = list()
+ /// Mobs with their AI paused or input locked, to their simple-animal AI status (or TRUE).
+ var/list/locked = list()
+ /// Held mobs with an AI controller, to list(the status it had, the status tg would have given it) as the hold began.
+ var/list/ai_before = list()
+ /// Things that turned up after the recording ended (gore still landing from the last blow), hidden until the end.
+ var/list/unborn = list()
+ /// Live rig pictures hidden for the replay (by invisibility, see hide_rig_picture()), to their own invisibility.
+ var/list/rig_hidden = list()
+ /// Things hidden in the tick between the slow-mo's end and the replay's start (hide_pending()).
+ var/list/pending_hidden = list()
+ /// Progress bars hidden for the replay (hide_progress_bars()), shown again at the end if still there.
+ var/list/hidden_bars = list()
+ /// Mechs switched off, to what completely_disabled was.
+ var/list/mechs = list()
+ /// Turrets and lit grenades whose clocks the hold has stopped (hold_machines()), to TRUE.
+ var/list/held_machines = list()
+ /// The user's own track, for the camera.
+ var/datum/sandy_replay_track/user_track
+ /// What the user's view follows.
+ var/obj/effect/abstract/sandy_replay_eye/eye
+ /// Sound files played in the replay, to the world.time each last started (play_sounds()).
+ var/list/sound_started = list()
+ /// The user's client pixel offsets before the replay.
+ var/eye_pixel_x = 0
+ var/eye_pixel_y = 0
+ /// The user's crit and knocked-out screens were taken off their view for the replay (clear_view()).
+ var/view_cleared = FALSE
+ /// The same for the other members of a shared slow-mo watching this replay, to TRUE.
+ var/list/members_cleared = list()
+ /// The crash waiting for the replay to end: list(length, stamina).
+ var/list/crash
+ var/finished = FALSE
+ /// Changes to a puppet that no wrapped proc made (fold()), and what they were.
+ var/unhooked = 0
+ var/list/folded = list()
+ /// Times a wrapped proc changed a puppet.
+ var/unmasks = 0
+ /// Sounds made in the field, each list(frame, turf, the rest of playsound()'s arguments).
+ var/list/sounds = list()
+ /// Playback: the next sound to play.
+ var/sound_at = 1
+ /// Afterimages the replay's surgers left.
+ var/afterimages = 0
+ /// How many replayed steps laid their trail along the way the surger really went (surger_way()).
+ var/ways_followed = 0
+ /// External cues played as its surgers burst off (SANDY_REPLAY_BURST_CUES_MAX).
+ var/burst_cues = 0
+ /// The slow-mo is over but a move in it is still going (moves_running()): recording goes on, on the same clock, from
+ /// this world.time, until it ends.
+ var/wait_started = 0
+ /// The recording's clock: frames are counted from `clock_frame` at world.time `clock_time`, `clock_rate` frames a
+ /// decisecond. A frame is one tick of the slowed world, all the way through: the replay (a frame a tick) plays
+ /// everything, an execution in it included, as many times faster as the user was faster than the world (owner,
+ /// 2026-11-12: "based on facts"). 10x for the Cascade, 4x for the service model, 2.5x for the street model.
+ var/clock_frame = 0
+ var/clock_time = 0
+ var/clock_rate = 1
+ /// The clock's rate through the recording: list(the frame it began at, the rate), in order. A shared slow-mo changes
+ /// pace as its members' time runs out (sandy_rebase()), and what the replay scales by the rate (a trail's step, a
+ /// body's turn) takes the rate its frame was recorded at (rate_at()).
+ var/list/clock_rates
+ /// The last frame the sample timer took.
+ var/last_sampled = -1
+ /// Recording: the animation being journaled now (sandy_replay_journal()), to add its next steps to.
+ var/list/open_event
+ /// Animations journaled, for tests and recordings.
+ var/journaled = 0
+ /// How long the last wait was, for tests and recordings.
+ var/waited = 0
+ /// Playback: journaled animations played, and chains played again after a redraw, for tests and recordings.
+ var/events_played = 0
+ var/chains_resumed = 0
+ /// Playback: what each journaled animation was played on and when, for tests and recordings.
+ var/list/event_log = list()
+ /// Every body that was mid-move during the wait: what turns up around them is recorded.
+ var/list/wait_bodies = list()
+ /// Shots being recorded that are still in the air.
+ var/shots_live = 0
+ /// Shots left out because SANDY_REPLAY_MAX_SHOTS were already in the air.
+ var/shots_capped = 0
+ /// Flashes of light made on the field's floor (an execution's shot): list(first frame, frame it went out at (INFINITY
+ /// while lit), x, y, z, range, power, colour) each, in the order they were lit (note_light()).
+ var/list/lights = list()
+ /// Recording: each light still lit, to its entry in `lights`.
+ var/list/lit = list()
+ /// Playback: the next light to light, and the lights the replay lit (weak references), put out at its end.
+ var/light_at = 1
+ var/list/shown_lights = list()
+ /// Shots still flying when the recording ended, held where they are until the replay is over (hold_shots()).
+ var/list/held_shots = list()
+ /// Gore in flight held for the replay (hold_gore()): move loops, tumbles to the time left to their next step, and
+ /// throws to list(world.time they were held at, the delay they had counted).
+ var/list/held_gore = list()
+ /// The recording has run out and the replay is staying on its last frame while gore lands (land()): 2 once the real
+ /// gore flies on. world.time it began, and the gore flying on.
+ var/landing_stage = 0
+ var/landing_started = 0
+ var/list/landing = list()
+ /// The afterimages the replay has left behind its surgers: gone with it, however long it stayed on its last frame.
+ var/list/trail_copies = list()
+ /// world.time the last of it to land has left its last drops by: the replay stays that long.
+ var/landing_settle = 0
+ /// Where and when a finisher's posed pictures were first drawn (sandy_rig_picture()): list(frame, x, y) each. A
+ /// surger gliding onto that tile is there by then (advance()).
+ var/list/rig_frames = list()
+ /// world.time the recording ended at. What was mid-tween then (a spray painting in) carries on from there when it is
+ /// handed back, as if the replay took no time.
+ var/ended_at = 0
+ /// world.time the sprays still painting in when the recording ended are done by, once land() lets them carry on.
+ var/paint_until = 0
+ /// The longest one frame's sample of everything recorded took, in milliseconds, for tests and recordings.
+ var/sample_cost = 0
+
+/datum/sandy_replay/New(datum/proximity_monitor/advanced/timestop/sandevistan/_field, mob/living/_user)
+ field = _field
+ user = _user
+ started = world.time
+ interval = world.tick_lag / field.time_scale
+ clock_time = started
+ clock_rate = 1 / interval
+ clock_rates = list(list(0, clock_rate))
+ var/datum/sandy_replay/old = GLOB.sandy_replays[user]
+ if(old)
+ qdel(old) // a replay still showing ends here
+ GLOB.sandy_replays[user] = src
+ sample_timer = addtimer(CALLBACK(src, PROC_REF(sample)), world.tick_lag, TIMER_LOOP | TIMER_STOPPABLE | TIMER_DELETE_ME)
+ notice(user)
+ last_sampled = 0
+
+/datum/sandy_replay/Destroy()
+ finish()
+ deltimer(sample_timer)
+ deltimer(begin_timer)
+ for(var/atom/movable/thing as anything in tracks)
+ UnregisterSignal(thing, COMSIG_QDELETING)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ track.thing = null
+ track.owner = null
+ tracks.Cut()
+ gone.Cut()
+ wait_bodies.Cut()
+ puppets.Cut()
+ standins.Cut()
+ user_track = null
+ if(user && GLOB.sandy_replays[user] == src)
+ GLOB.sandy_replays -= user
+ if(field?.replay == src)
+ field.replay = null
+ field = null
+ user = null
+ return ..()
+
+// =========================================================================
+// RECORDING
+// =========================================================================
+
+/// The frame the recording is at now.
+/datum/sandy_replay/proc/frame_now()
+ if(state != SANDY_REPLAY_RECORDING)
+ return total
+ return clock_frame + round((world.time - clock_time) * clock_rate + 0.001)
+
+/// The frame the recording is at now, with the part of it gone by.
+/datum/sandy_replay/proc/frame_exact()
+ if(state != SANDY_REPLAY_RECORDING)
+ return total
+ return clock_frame + (world.time - clock_time) * clock_rate
+
+/**
+ * The frame a change made right now is drawn from. Everything recorded is sampled once a frame, in one pass: once this
+ * frame's pass has run, what else changes in this tick (the rig hiding the body its pictures stand in for, or showing
+ * it again) is only seen in the next frame's pass. So a picture made, or a pose started, after the pass belongs to the
+ * next frame too, or the replay shows it a frame before the body's matching change: the user drawn twice as a move
+ * starts, and fading with its pictures as it ends.
+ */
+/datum/sandy_replay/proc/frame_due()
+ return max(frame_exact(), last_sampled + 1)
+
+/// Whether `thing` is recorded at all.
+/datum/sandy_replay/proc/recordable(atom/movable/thing)
+ var/static/list/skipped = typecacheof(list(
+ /obj/effect/abstract,
+ /obj/effect/timestop,
+ /obj/effect/temp_visual/decoy/fading/cascade, // the surge's trail
+ /obj/effect/temp_visual/cyberware_time_ring,
+ /obj/effect/hotspot,
+ /obj/effect/particle_effect,
+ /obj/effect/dummy/lighting_obj, // a flash of light (a gunshot's): its light is an underlay, drawn whole on a stand-in. It is lit again as a light (note_light())
+ /obj/effect/landmark,
+ /atom/movable/screen,
+ ))
+ if(!ismovable(thing) || QDELETED(thing) || thing.invisibility >= INVISIBILITY_ABSTRACT)
+ return FALSE
+ if(ismob(thing) && !isliving(thing)) // ghosts and camera eyes
+ return FALSE
+ if(sandy_rig_picture(thing)) // a finisher rig's posed piece of a body: the move is replayed with it
+ return TRUE
+ if(sandy_bearer_picture(thing)) // a swing or a slash a chrome weapon plays on a body
+ return TRUE
+ if(isprojectile(thing))
+ var/obj/projectile/shot = thing
+ if(shot.hitscan) // crosses the room in a tick: its tracer, muzzle and impact effects are what is seen, and recorded
+ return FALSE
+ return !skipped[thing.type]
+
+/// The field saw `thing`: start recording it.
+/datum/sandy_replay/proc/notice(atom/movable/thing)
+ if(state != SANDY_REPLAY_RECORDING || tracks[thing])
+ return
+ if(istype(thing, /obj/effect/dummy/lighting_obj))
+ note_light(thing)
+ return
+ if(!recordable(thing))
+ return
+ if(isprojectile(thing) && !shot_room())
+ return
+ var/datum/sandy_replay_track/track = new
+ track.owner = src
+ track.thing = thing
+ track.flier = isprojectile(thing)
+ track.first = (covering && !sandy_rig_picture(thing)) ? 0 : round(frame_due()) // a rig picture is made by the move: it was never there before it
+ tracks[thing] = track
+ RegisterSignal(thing, COMSIG_QDELETING, PROC_REF(on_thing_deleted))
+ if(track.flier && !shot_fired(thing))
+ // Seen as it is put on the floor, before fire() turns it the way it flies: its first frame is taken once it is
+ // fired (on_shot_fired()), or the replay draws it upright on the shooter for a frame.
+ RegisterSignal(thing, COMSIG_PROJECTILE_FIRE, PROC_REF(on_shot_fired))
+ sample_track(track, track.first)
+ if(istype(thing, /obj/effect/temp_visual))
+ track.oneshot = TRUE
+ intro(track)
+ if(ismovable(thing.loc) && shown_on(thing)) // a muzzle flash, drawn on the shooter's tile
+ shot_from(thing.loc, track.first)
+ else if(sandy_bearer_picture(thing))
+ track.oneshot = TRUE
+ // On someone hit it plays through where they are. On the surger it would be left behind as he moves on: it
+ // lasts its own replay frame there.
+ var/obj/effect/abstract/cyberware_anim/picture = thing
+ if(picture.bearer != user && !sandy_session_member(src, picture.bearer))
+ track.plays_out = SANDY_REPLAY_PICTURE_TIME
+ else if(track.flier && shot_fired(thing))
+ var/obj/projectile/shot = thing
+ shot_from(shot.firer, track.first)
+ if(sandy_rig_picture(thing) && length(rig_frames) < SANDY_REPLAY_MAX_SHOTS * 4)
+ var/turf/posed_on = shown_on(thing)
+ if(posed_on)
+ rig_frames += list(list(track.first, posed_on.x, posed_on.y))
+ if(sandy_rig_picture(thing) || track.oneshot || track.flier)
+ var/matrix/turned = thing.transform
+ event_log += "notice [thing.type] f[frame_exact()] first=[track.first] on=[shown_on(thing) ? "map" : "off"] dir=[thing.dir] T=[turned.a],[turned.b],[turned.d],[turned.e]"
+
+/**
+ * A flash of light lit on the floor in the field (an execution's shot lights the room around the gun). It isn't drawn
+ * (recordable()): the replay lights its own at the same spot, as bright, from the frame it was lit until the frame it
+ * went out (play_lights()). A light carried by a mob isn't on the floor, and isn't taken.
+ */
+/datum/sandy_replay/proc/note_light(obj/effect/dummy/lighting_obj/glow)
+ if(lit[glow] || QDELETED(glow) || !isturf(glow.loc) || glow.light_range <= 0 || glow.light_power <= 0)
+ return
+ if(length(lights) >= SANDY_REPLAY_MAX_SHOTS)
+ return
+ var/turf/spot = glow.loc
+ var/list/light = list(round(frame_due()), INFINITY, spot.x, spot.y, spot.z, glow.light_range, glow.light_power, glow.light_color)
+ lights += list(light)
+ lit[glow] = light
+ RegisterSignal(glow, COMSIG_QDELETING, PROC_REF(on_light_gone))
+
+/// Signal proc for [COMSIG_QDELETING] on a light the recording took: it went out.
+/datum/sandy_replay/proc/on_light_gone(obj/effect/dummy/lighting_obj/glow)
+ SIGNAL_HANDLER
+ var/list/light = lit[glow]
+ lit -= glow
+ if(light && state == SANDY_REPLAY_RECORDING)
+ light[2] = max(round(frame_due()), light[1] + 1)
+
+/// Stops following the lights still lit: the recording is over, and whatever is still lit stays lit to its end.
+/datum/sandy_replay/proc/forget_lights()
+ for(var/obj/effect/dummy/lighting_obj/glow as anything in lit)
+ UnregisterSignal(glow, COMSIG_QDELETING)
+ lit.Cut()
+
+/// Lights the replay's flashes of light due by `frame`, each for as many frames as it was lit, and never for less than a
+/// one-shot effect is drawn (SANDY_REPLAY_ONESHOT_MIN): compressed ten times, a short flash would be out before it is seen.
+/datum/sandy_replay/proc/play_lights(frame)
+ while(light_at <= length(lights))
+ var/list/light = lights[light_at]
+ if(light[1] > frame)
+ return
+ light_at++
+ var/turf/spot = locate(light[3], light[4], light[5])
+ if(!spot)
+ continue
+ var/span = max((min(light[2], total + 1) - light[1]) * world.tick_lag, SANDY_REPLAY_ONESHOT_MIN)
+ shown_lights += WEAKREF(new /obj/effect/dummy/lighting_obj(spot, light[6], light[7], light[8], span)) // it puts itself out
+
+/**
+ * A temp visual that animates itself in its own Initialize() (tg's ring) is first seen with its vars already at the
+ * tween's end (grown, faded out): it would replay as nothing. Its sandy_replay_intro() gives the look it starts with and
+ * the animations it plays, and those go in its track as if journaled.
+ */
+/datum/sandy_replay/proc/intro(datum/sandy_replay_track/track)
+ var/obj/effect/temp_visual/effect = track.thing
+ var/list/intro = effect.sandy_replay_intro()
+ if(!length(intro))
+ return
+ // The look it starts with goes on as an animation of no length before the rest: a later sample of it (the field's
+ // tint coming on in the same frame) can't take its place.
+ var/list/start = intro[1]
+ start["time"] = 0
+ LAZYADD(track.events, list(list(track.first, null, world.tick_lag * clock_rate, list(start))))
+ for(var/list/steps as anything in intro[2])
+ LAZYADD(track.events, list(list(track.first, null, world.tick_lag * clock_rate, steps)))
+ journaled++
+ event_log += "intro [effect.type] f[track.first] chains=[length(intro[2])]"
+
+/// The field just changed how `thing` looks (its tint): take the sample again.
+/datum/sandy_replay/proc/resample(atom/movable/thing)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(track && state == SANDY_REPLAY_RECORDING)
+ track.last_raw = null
+ sample_track(track, covering ? track.first : round(frame_due()))
+
+/// The sample timer, every tick: one frame of everything recorded, when the clock is on a new one.
+/datum/sandy_replay/proc/sample()
+ if(state != SANDY_REPLAY_RECORDING)
+ return
+ for(var/atom/movable/thing as anything in tracks)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(track.surger && !track.trail_read)
+ read_trail(track)
+ var/list/moving = moves_running()
+ var/frame = frame_now()
+ if(frame <= last_sampled)
+ return
+ last_sampled = frame
+ if(wait_started)
+ // No field hands things over now: what the move leaves around the bodies doing it (a torn-off limb, a head,
+ // blood, gibs) is picked up here, and drawn from the frame it turns up in. The bodies are kept to the end, so
+ // what the move's last blow makes, in the tick it ends, is picked up too.
+ wait_bodies |= moving
+ for(var/mob/living/body as anything in wait_bodies)
+ if(QDELETED(body) || !isturf(body.loc))
+ continue
+ for(var/atom/movable/thing in range(3, body))
+ notice(thing)
+ var/cost_from = TICK_USAGE
+ for(var/atom/movable/thing as anything in tracks)
+ sample_track(tracks[thing], frame)
+ sample_cost = max(sample_cost, TICK_USAGE_TO_MS(cost_from))
+ if(wait_started && (!length(moving) || world.time - wait_started >= SANDY_REPLAY_WAIT_MAX))
+ end_wait(!length(moving))
+
+/// Adds a frame to `track` if the thing changed since its last one.
+/datum/sandy_replay/proc/sample_track(datum/sandy_replay_track/track, frame)
+ var/atom/movable/thing = track.thing
+ if(track.flier && !shot_fired(thing))
+ return // not turned the way it flies yet (notice())
+ var/turf/here = shown_on(thing)
+ var/x = 0
+ var/y = 0
+ var/z = 0
+ if(isturf(here))
+ x = here.x
+ y = here.y
+ z = here.z
+ // The Cascade's spine nodes light one by one over the first frame's span (cyberware_anim.dm): frame 0 opens with
+ // them lit, as the rest of the surge has them, without touching the live boot.
+ var/mob/living/carbon/carbon_bearer = iscarbon(thing) ? thing : null
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = carbon_bearer ? cyberware_bearer_lattice(carbon_bearer) : null
+ var/old = (lattice && findtext(lattice.node_look, "boot") == 1) ? lattice.node_look : null
+ if(old)
+ lattice.node_look = "lit"
+ carbon_bearer.update_body_parts()
+ var/raw = thing.appearance
+ var/facing = thing.dir
+ var/obj/effect/abstract/cyberware_anim/picture = sandy_bearer_picture(thing) ? thing : null
+ if(picture?.bearer)
+ facing = picture.bearer.dir // drawn the way its bearer faces (VIS_INHERIT_DIR)
+ var/list/frames = track.frames
+ var/at = length(frames) - SANDY_FRAME_SIZE
+ // Wet blood dries and spreads on the client (animate()): its vars already hold the end, so it is looked at every sample.
+ var/obj/effect/decal/cleanable/blood/wet = istype(thing, /obj/effect/decal/cleanable/blood) ? thing : null
+ if(wet && !wet.sandy_replay_wet())
+ wet = null
+ if(track.path && at >= 0 && frames[at + SANDY_FRAME_X] == x && frames[at + SANDY_FRAME_Y] == y && frames[at + SANDY_FRAME_Z] == z)
+ track.path = null // back where its last frame has it: nothing to go round
+ if(!wet && at >= 0 && raw == track.last_raw && frames[at + SANDY_FRAME_X] == x && frames[at + SANDY_FRAME_Y] == y && frames[at + SANDY_FRAME_Z] == z && frames[at + SANDY_FRAME_DIR] == facing)
+ if(old)
+ lattice.node_look = old
+ carbon_bearer.update_body_parts()
+ return
+ track.last_raw = raw
+ if(!track.surger && (thing == user || field?.surging[thing]))
+ become_surger(track)
+ else if(track.surger && !track.trail_read)
+ read_trail(track)
+ var/look = clean_look(thing)
+ if(carbon_bearer)
+ look = unfolded_look(carbon_bearer, look)
+ if(old)
+ lattice.node_look = old
+ carbon_bearer.update_body_parts()
+ if(wet)
+ look = wet_look(wet, look)
+ if(track.flier)
+ look = shot_look(thing, look)
+ if(picture)
+ look = picture_look(picture, look)
+ // A corpse the game slides or throws is glided as slowly as the game glided it (a heavy killing blow slides it a
+ // tile over most of half a second), where the living glide until their next step.
+ if(at >= 0 && isliving(thing) && (frames[at + SANDY_FRAME_X] != x || frames[at + SANDY_FRAME_Y] != y))
+ var/mob/living/body = thing
+ if(body.stat == DEAD && body.glide_size > 0)
+ LAZYSET(track.glides, "[frame]", clamp(round(ICON_SIZE_X / body.glide_size * clock_rate * world.tick_lag), 1, SANDY_REPLAY_CORPSE_GLIDE_MAX))
+ if(at >= 0)
+ if(frames[at + SANDY_FRAME_LOOK] == look && frames[at + SANDY_FRAME_X] == x && frames[at + SANDY_FRAME_Y] == y && frames[at + SANDY_FRAME_Z] == z && frames[at + SANDY_FRAME_DIR] == facing)
+ return
+ if(frames[at + SANDY_FRAME_INDEX] >= frame) // sampled twice in one frame: the later look stands
+ if(track.path) // it stepped on since the first take: those steps follow the ones that led to it
+ var/key = "[frames[at + SANDY_FRAME_INDEX]]"
+ var/list/way = (LAZYACCESS(track.ways, key) || list(frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y])) + track.path
+ if(length(way) <= SANDY_REPLAY_PATH_MAX * 2)
+ LAZYSET(track.ways, key, way)
+ else
+ LAZYREMOVE(track.ways, key)
+ track.path = null
+ if(track.stepped_at)
+ LAZYSET(track.step_clock, "[frames[at + SANDY_FRAME_INDEX]]", track.stepped_at)
+ frames[at + SANDY_FRAME_LOOK] = look
+ frames[at + SANDY_FRAME_X] = x
+ frames[at + SANDY_FRAME_Y] = y
+ frames[at + SANDY_FRAME_Z] = z
+ frames[at + SANDY_FRAME_DIR] = facing
+ return
+ if(length(track.path) > 2) // more than one step since its last frame
+ LAZYSET(track.ways, "[frame]", track.path)
+ track.path = null
+ if(track.stepped_at)
+ LAZYSET(track.step_clock, "[frame]", track.stepped_at)
+ frames += list(frame, look, x, y, z, facing)
+
+/**
+ * The turf `thing` is drawn on: its loc, or, for an effect shown in the vis_contents of what it was made in (tg's muzzle
+ * flash, made inside the shooter), the turf that holder stands on. Null when it isn't drawn on the map.
+ */
+/datum/sandy_replay/proc/shown_on(atom/movable/thing)
+ var/atom/here = thing.loc
+ if(isturf(here))
+ return here
+ if(sandy_bearer_picture(thing)) // in nothing: only in the vis_contents of the body it plays on
+ var/obj/effect/abstract/cyberware_anim/picture = thing
+ var/atom/movable/worn_by = picture.bearer
+ return (worn_by && isturf(worn_by.loc) && (thing in worn_by.vis_contents)) ? worn_by.loc : null
+ if(!istype(thing, /obj/effect/temp_visual) || !ismovable(here) || !isturf(here.loc))
+ return null
+ var/atom/movable/holder = here
+ return (thing in holder.vis_contents) ? holder.loc : null
+
+/**
+ * `look` (a picture a chrome weapon plays on a body) as a stand-in on the floor can draw it. On the body it takes the
+ * body's plane and sorts among the body's overlays by a float layer, and the far arm's is cut around what the near hand
+ * holds by a mask of that item: a stand-in has none of those, so it goes on the body's plane just over mobs, uncut.
+ */
+/datum/sandy_replay/proc/picture_look(obj/effect/abstract/cyberware_anim/picture, look)
+ var/mutable_appearance/copy = new(look)
+ var/atom/movable/worn_by = picture.bearer
+ if(worn_by) // on the body it is drawn wherever the body is drawn: held in a grab, lying off its tile
+ copy.pixel_x += worn_by.pixel_x
+ copy.pixel_y += worn_by.pixel_y
+ copy.pixel_w += worn_by.pixel_w
+ copy.pixel_z += worn_by.pixel_z
+ copy.plane = worn_by ? worn_by.plane : GAME_PLANE
+ copy.layer = ABOVE_MOB_LAYER
+ copy.filters = null
+ return copy.appearance
+
+/// `thing`'s appearance without the slow-mo's own look: the field's tint and the user's edge glow.
+/datum/sandy_replay/proc/clean_look(atom/movable/thing)
+ // In a shared slow-mo another member's field may tint it, and every member wears the edge glow (ware_sandy_timestop_shared.dm).
+ var/tinted = field?.tinted[thing] || sandy_session_tints(src, thing)
+ var/outlined = (thing == user || sandy_session_member(src, thing)) && thing.filter_data?[SANDY_REPLAY_OUTLINE]
+ if(!tinted && !outlined)
+ return thing.appearance
+ var/mutable_appearance/copy = new(thing)
+ // Bodies and items wear the tint as a filter (cyberware_time_tints_by_filter()), the rest in `color`.
+ var/filtered = tinted && cyberware_time_tints_by_filter(thing)
+ if(tinted && !filtered)
+ if(istype(thing, /obj/effect/decal/cleanable/blood)) // blood's colour is its own, worked out as it dries
+ var/obj/effect/decal/cleanable/blood/blood = thing
+ copy.color = blood.sandy_replay_colour()
+ if(istype(blood, /obj/effect/decal/cleanable/blood/gibs)) // its meat overlay carries the tint too
+ var/obj/effect/decal/cleanable/blood/gibs/gibs = blood
+ gibs.sandy_untinted_overlays(copy)
+ else
+ copy.color = untinted_colour(thing)
+ copy.appearance_flags |= KEEP_TOGETHER // update_atom_colour() leaves this on once anything was ever coloured
+ if(outlined || filtered)
+ copy.filters = null
+ for(var/name in thing.filter_data)
+ if(name == SANDY_REPLAY_OUTLINE || name == SANDY_REPLAY_TINT)
+ continue
+ var/list/data = thing.filter_data[name]
+ var/list/arguments = data.Copy()
+ arguments -= "priority"
+ copy.filters += filter(arglist(arguments))
+ return copy.appearance
+
+/**
+ * `look` (`body`'s) with its arm blades drawn in its hands while they swing out of their housings. The swing is a picture
+ * in the body's vis_contents, which no look carries, and the held blade isn't drawn under it
+ * (/obj/item/melee/energy/blade/hardlight/cyberware_mantis/build_worn_icon()): recorded as it is, the replay would open on
+ * bare arms for the frames the swing plays. The swing ends on the held blade, so that is what is drawn.
+ */
+/datum/sandy_replay/proc/unfolded_look(mob/living/carbon/body, look)
+ var/unfolding = FALSE
+ for(var/obj/item/organ/cyberimp/arm/toolkit/cyberware/housing in body.organs)
+ var/obj/effect/abstract/cyberware_anim/swing = housing.blade_anim()
+ if(swing && swing.icon_state == housing.blade_anim_state("unfold"))
+ unfolding = TRUE
+ break
+ if(!unfolding)
+ return look
+ var/hidden = FALSE
+ for(var/obj/item/melee/energy/blade/hardlight/cyberware_mantis/blade in body.held_items)
+ if(world.time < blade.inhand_hidden_until)
+ hidden = TRUE
+ break
+ var/list/hands = body.overlays_standing[HANDS_LAYER]
+ if(hands && !islist(hands))
+ hands = list(hands)
+ if(!hidden || !length(hands))
+ return look
+ var/mutable_appearance/copy = new(look)
+ for(var/mutable_appearance/held as anything in hands)
+ if(held.alpha)
+ continue
+ copy.overlays -= held
+ var/mutable_appearance/shown = new(held)
+ shown.alpha = 255
+ copy.overlays += shown
+ return copy.appearance
+
+/// The colour [/atom/proc/update_atom_colour] would give `thing` without the field's tint.
+/datum/sandy_replay/proc/untinted_colour(atom/thing)
+ if(!length(thing.atom_colours))
+ return thing.color
+ for(var/priority in 1 to length(thing.atom_colours))
+ if(priority == TEMPORARY_COLOUR_PRIORITY)
+ continue
+ var/list/entry = thing.atom_colours[priority]
+ if(!entry)
+ continue
+ if(entry[ATOM_COLOR_TYPE_INDEX] == ATOM_COLOR_TYPE_FILTER)
+ return null
+ if(length(entry[ATOM_COLOR_VALUE_INDEX]))
+ return entry[ATOM_COLOR_VALUE_INDEX]
+ return null
+
+/// How many frames a decisecond the recording's clock ran at `frame`.
+/datum/sandy_replay/proc/rate_at(frame)
+ . = clock_rate
+ for(var/list/stretch as anything in clock_rates)
+ if(stretch[1] > frame)
+ break
+ . = stretch[2]
+
+/// `track`'s thing is on a surge: the replay gives it its surge's trail.
+/datum/sandy_replay/proc/become_surger(datum/sandy_replay_track/track)
+ track.surger = TRUE
+ track.surge_from = frame_now()
+ read_trail(track)
+ if(state == SANDY_REPLAY_RECORDING && track.thing)
+ RegisterSignal(track.thing, COMSIG_MOVABLE_MOVED, PROC_REF(on_surger_stepped))
+
+/// Signal proc for [COMSIG_MOVABLE_MOVED] on a surger while it is recorded: the tile it stepped onto is kept, so the
+/// replay's trail follows the way it really went between two frames.
+/datum/sandy_replay/proc/on_surger_stepped(atom/movable/source, atom/old_loc, dir, forced)
+ SIGNAL_HANDLER
+ var/datum/sandy_replay_track/track = tracks[source]
+ if(!track || state != SANDY_REPLAY_RECORDING)
+ return
+ track.stepped_at = frame_exact()
+ if(isliving(source))
+ var/mob/living/walker = source
+ track.stride = walker.cached_multiplicative_slowdown
+ if(length(track.path) >= SANDY_REPLAY_PATH_MAX * 2)
+ return
+ var/turf/here = source.loc
+ LAZYADD(track.path, isturf(here) ? here.x : 0)
+ track.path += isturf(here) ? here.y : 0
+
+/// The recording is over: the surgers' steps aren't followed any more (their puppets take the signal from here, mask()).
+/datum/sandy_replay/proc/stop_paths()
+ for(var/atom/movable/thing as anything in tracks)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(track.surger)
+ UnregisterSignal(thing, COMSIG_MOVABLE_MOVED)
+
+/// `body`'s own surge is over while the recording goes on (a shared slow-mo's member out of time): no trail from here.
+/datum/sandy_replay/proc/surge_over(mob/living/body)
+ var/datum/sandy_replay_track/track = tracks[body]
+ if(track?.surger && track.surge_until == INFINITY && state == SANDY_REPLAY_RECORDING)
+ track.surge_until = frame_now()
+
+/// Takes the trail's cadence and strength from the surger's window. The user's own window isn't listed on them yet
+/// while it opens the slow-mo, so this is tried again on later samples.
+/datum/sandy_replay/proc/read_trail(datum/sandy_replay_track/track)
+ if(!isliving(track.thing))
+ return
+ var/mob/living/body = track.thing
+ var/datum/status_effect/cyberware_cascade_window/window = body.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ if(window)
+ track.trail_length = max(1, window.trail_length)
+ track.trail_per_tile = max(1, window.trail_per_tile)
+ track.trail_alpha = window.afterimage_alpha
+ track.trail_read = TRUE
+
+/// `look` (wet `blood`'s appearance) as the blood is drawn on screen right now, not where its tweens end.
+/datum/sandy_replay/proc/wet_look(obj/effect/decal/cleanable/blood/blood, look)
+ var/colour = blood.sandy_replay_colour()
+ var/list/paint = blood.sandy_replay_paint_now()
+ if(!colour && !paint)
+ return look
+ var/mutable_appearance/copy = new(look)
+ if(colour)
+ copy.color = colour
+ if(paint)
+ copy.transform = paint[1]
+ copy.alpha = paint[2]
+ return copy.appearance
+
+/// A sound was played on `source`, in the field: kept, to play again in the replay. `arguments` are the rest of
+/// playsound()'s, from soundin on, without the channel.
+/datum/sandy_replay/proc/hear(turf/source, list/arguments, mob/actor)
+ if(state != SANDY_REPLAY_RECORDING || (!field && !wait_started) || length(sounds) >= SANDY_REPLAY_MAX_OWN_SOUNDS)
+ return
+ // Waiting out a move after the slow-mo: the sounds around the user, as the hold's reach.
+ var/turf/centre = get_turf(field ? field.host : user)
+ if(!centre || centre.z != source.z || get_dist(centre, source) > (field ? field.current_range : SANDY_REPLAY_HOLD_RANGE))
+ if(!sandy_session_hears(src, source)) // or in a crewmate's field of a shared slow-mo (ware_sandy_timestop_shared.dm)
+ return
+ if(length(sounds) >= SANDY_REPLAY_MAX_SOUNDS && !own_sound(source, actor))
+ return
+ var/now = frame_exact()
+ // The same sound on the same tile in the same frame (a burst's echoes, a crowd's steps) is kept once.
+ for(var/index in length(sounds) to 1 step -1)
+ var/list/kept = sounds[index]
+ if(floor(kept[1]) != floor(now))
+ break
+ if(kept[2] == source && kept[3] == arguments[1])
+ return
+ sounds += list(list(now, source) + arguments)
+
+/// Whether a sound set off by `actor` on `source` is the user's or a crewmate's own: kept past the cap on the world's.
+/datum/sandy_replay/proc/own_sound(turf/source, mob/actor)
+ if(actor && (actor == user || (actor in sandy_session_others(src, FALSE))))
+ return TRUE
+ var/turf/here = get_turf(user)
+ return here && here.z == source.z && get_dist(here, source) <= 1
+
+/// Signal proc for [COMSIG_QDELETING] on anything recorded.
+/datum/sandy_replay/proc/on_thing_deleted(atom/movable/thing)
+ SIGNAL_HANDLER
+ if(thing == user)
+ qdel(src)
+ return
+ var/datum/sandy_replay_track/track = tracks[thing]
+ tracks -= thing
+ pending_hidden -= thing
+ held_shots -= thing
+ unborn -= thing
+ rig_hidden -= thing
+ if(!track)
+ return
+ if(GLOB.sandy_replay_masked[thing] == track)
+ GLOB.sandy_replay_masked -= thing
+ sandy_replay_masks = length(GLOB.sandy_replay_masked)
+ var/ended = (track.flier || istype(thing, /obj/effect/projectile)) ? shot_gone(track) : 0
+ track.thing = null
+ if(state == SANDY_REPLAY_RECORDING || state == SANDY_REPLAY_PENDING)
+ // Drawn up to the frame the recording next sampled without it: a rig picture goes in the frame its body's
+ // own look comes back, not one before (the body would be gone for a frame).
+ track.last = max(last_sampled + 1, track.first + ((track.oneshot && !track.flier) ? SANDY_REPLAY_ONESHOT_FRAMES : 1), ended)
+ gone += track
+ return
+ puppets -= track
+ if(track.flier && state == SANDY_REPLAY_PLAYING)
+ shot_to_standin(track)
+
+/// A player cut the slow-mo short: nothing replays.
+/datum/sandy_replay/proc/cancel()
+ if(state == SANDY_REPLAY_RECORDING)
+ qdel(src)
+
+/// The field is over (it ran out, or the user ended it): playback starts next tick, once the slow-mo's own looks
+/// are off everything.
+/datum/sandy_replay/proc/field_over()
+ if(state != SANDY_REPLAY_RECORDING || wait_started)
+ return
+ field = null
+ // A surger killed in it is a body from here on: its fall and anything that knocks it about leave no trail.
+ for(var/atom/movable/thing as anything in tracks)
+ var/mob/living/body = thing
+ if(isliving(body) && body.stat == DEAD)
+ surge_over(body)
+ if(!length(moves_running()))
+ end_wait(TRUE)
+ return
+ // An execution or finisher in the field is still going. The replay's hold would cut it short (its checks fail on a
+ // held body), so the world goes on at normal speed and the recording with it, a frame a tick, until it's done. A body
+ // killed as the slow-mo ended (its user, shot dead) is waited for the same way until it has slid where it lies.
+ // The clock goes to the world's normal pace first: left at the slow-mo's, the wait would be a frame every half
+ // second and replay ten times too fast.
+ sandy_rebase(1)
+ wait_started = world.time
+
+/**
+ * The recording is over: playback starts next tick, once the slow-mo's own looks are off everything. Without
+ * [replays] (a move still going when the wait ran out) nothing replays.
+ */
+/datum/sandy_replay/proc/end_wait(replays)
+ if(state != SANDY_REPLAY_RECORDING)
+ return
+ total = max(frame_now(), 1)
+ waited = wait_started ? world.time - wait_started : 0
+ stop_paths()
+ forget_lights()
+ ended_at = world.time
+ state = SANDY_REPLAY_PENDING
+ if(replays)
+ hide_progress_bars()
+ hide_pending()
+ hold_shots()
+ hold_gore()
+ deltimer(sample_timer)
+ sample_timer = null
+ if(!replays)
+ finish()
+ return
+ if(watched())
+ // The cut into the replay is one frame: the slow-mo's last frame, then the replay's first, in this same tick,
+ // so no frame of the world as it really is now (the dead where they fell, the gore at its landing spots) goes
+ // out between them. What ends the slow-mo after this (the outline coming off, the release flash) lands on the
+ // real looks under the puppets. With nobody looking on nobody sees the cut: the replay starts next tick.
+ begin()
+ return
+ begin_timer = addtimer(CALLBACK(src, PROC_REF(begin)), world.tick_lag, TIMER_STOPPABLE | TIMER_DELETE_ME)
+
+/// Whether anyone sees the replay start: its user, a crewmate of a shared slow-mo (ware_sandy_timestop_shared.dm), or
+/// any other client looking on from near one of them (a ghost, a crewmate whose own time is out).
+/datum/sandy_replay/proc/watched()
+ if(user?.client || sandy_session_watched(src))
+ return TRUE
+ var/list/here = centres()
+ if(!length(here))
+ return FALSE
+ for(var/client/viewer as anything in GLOB.clients)
+ var/turf/eye_at = get_turf(viewer?.eye)
+ if(!eye_at)
+ continue
+ for(var/turf/centre as anything in here)
+ if(eye_at.z == centre.z && get_dist(eye_at, centre) <= SANDY_REPLAY_REACH)
+ return TRUE
+ return FALSE
+
+/// The bodies in the recording in the middle of an execution or finisher, either side of it, or still falling from a
+/// death (sandy_replay_falling()).
+/datum/sandy_replay/proc/moves_running()
+ . = list()
+ for(var/atom/movable/thing as anything in tracks)
+ if(isliving(thing) && (sandy_replay_mid_move(thing) || sandy_replay_falling(thing)))
+ . += thing
+
+// =========================================================================
+// THE ANIMATION JOURNAL
+// =========================================================================
+// A finisher rig poses its pictures with animate() chains. The server only holds where each chain ends, so a sample
+// can't see the poses on the way. The rig and finisher files send their animate() calls through
+// sandy_replay_animate() (a file-local macro, SANDY_REPLAY_JOURNAL_ON in those files), which plays them as usual and,
+// while a replay records their target, journals them to play again on its stand-in.
+
+/// An animate() call on `target` (null: a further step of the last one) with these named arguments.
+/datum/sandy_replay/proc/journal(target, list/step, atom/movable/started_on)
+ if(state != SANDY_REPLAY_RECORDING)
+ return
+ if(isnull(target))
+ if(open_event)
+ var/list/steps = open_event[4]
+ steps += list(step)
+ return
+ open_event = null
+ var/datum/sandy_replay_track/track = ismovable(target) ? tracks[target] : null
+ if(!track && (sandy_rig_picture(target) || istype(target, /obj/effect/temp_visual)) && near_centre(target))
+ notice(target) // made this tick (a shot's muzzle flash, a drop of blood): its first pose is this call
+ track = tracks[target]
+ // Gore a move puts on the floor and then moves itself: a burst head's gib, the Gorilla's thrown arm and the blood
+ // drops that show as it lands (gorilla_finisher.dm)
+ var/thrown_gib = istype(target, /obj/effect/decal/cleanable/blood) || istype(target, /obj/item/bodypart) || istype(target, /obj/item/organ)
+ if(!track || !(sandy_rig_picture(target) || isliving(target) || track.oneshot || thrown_gib))
+ return
+ if(thrown_gib)
+ // A burst head's gib (flying_gore.dm): tg has already stepped it off the head's tile, and its arc starts back at
+ // the head from there. Its first frame is taken again where it is now, so the arc is drawn from the head to its
+ // landing in the replay too, not as a gib lying on the floor from the blow on. The thrown arm starts where the
+ // hauled one was, and a drop that shows later starts unseen, the same way.
+ var/list/frames = track.frames
+ if(length(frames) && frames[length(frames) - SANDY_FRAME_SIZE + SANDY_FRAME_INDEX] >= frame_now())
+ track.last_raw = null
+ sample_track(track, frames[length(frames) - SANDY_FRAME_SIZE + SANDY_FRAME_INDEX])
+ // The look it had before this call: what it was drawn as when the chain began, direct writes included.
+ open_event = list(frame_due(), started_on ? clean_look(started_on) : null, world.tick_lag * clock_rate, list(step))
+ LAZYADD(track.events, list(open_event))
+ journaled++
+ event_log += "journal [track.thing.type] f[open_event[1]] tag=[step["tag"]] t=[step["time"]] pw=[step["pixel_w"]]"
+
+/// Plays `track`'s journaled animations due by `frame` on its stand-in, or on its puppet (a body's lean or flinch:
+/// shifted to where the puppet is drawn).
+/datum/sandy_replay/proc/play_events(datum/sandy_replay_track/track, frame)
+ var/atom/movable/standin = track.mode == SANDY_TRACK_STANDIN ? track.standin : track.thing
+ var/shift_x = 0
+ var/shift_y = 0
+ if(track.mode == SANDY_TRACK_PUPPET && standin && track.cursor >= 0 && isturf(standin.loc))
+ var/turf/here = standin.loc
+ shift_x = (track.frames[track.cursor + SANDY_FRAME_X] - here.x) * ICON_SIZE_X
+ shift_y = (track.frames[track.cursor + SANDY_FRAME_Y] - here.y) * ICON_SIZE_Y
+ while(track.event_at <= length(track.events))
+ var/list/event = track.events[track.event_at]
+ if(event[1] >= frame + 1)
+ return
+ // Still gliding to the tile it starts on: it starts when the glide is done. A glide on the spot is the frame's own
+ // shift, the pose this chain moves it to (the lift of a body put on the blades): it doesn't hold the chain.
+ if(track.mode == SANDY_TRACK_PUPPET && track.glide_step && track.glide_until > world.time + max(event[1] - frame, 0) * world.tick_lag && standin?.loc && !track.unmasked)
+ return
+ track.event_at++
+ if(!standin?.loc || (track.mode == SANDY_TRACK_PUPPET && (track.unmasked || (standin.alpha == 0 && !track.oneshot)))) // a one-shot's alpha is its own animation's
+ event_log += "skip [track.thing?.type] f[event[1]] at [frame] a=[standin?.alpha] u=[track.unmasked]"
+ continue
+ events_played++
+ var/list/steps = event[4]
+ var/list/first = steps[1]
+ var/parallel = first["flags"] & ANIMATION_PARALLEL
+ var/relative = first["flags"] & ANIMATION_RELATIVE
+ var/look = event[2]
+ if(track.mode == SANDY_TRACK_STANDIN && look && look != track.drawn_look && !parallel)
+ animate(standin, time = 0, flags = ANIMATION_END_NOW)
+ standin.appearance = look
+ standin.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ track.drawn_look = look
+ var/scale = event[3]
+ var/length = 0
+ var/list/chain = list()
+ for(var/i in 1 to length(steps))
+ var/list/arguments = list()
+ if(i == 1)
+ arguments += standin
+ var/list/step = steps[i]
+ for(var/name in step)
+ var/value = step[name]
+ if(name == "time" || name == "delay")
+ value *= scale
+ else if(!relative && name == "pixel_w")
+ value += shift_x
+ else if(!relative && name == "pixel_z")
+ value += shift_y
+ arguments[name] = value
+ if(i == 1 && event[1] > frame) // when in this tick it started
+ arguments["delay"] = (arguments["delay"] || 0) + (event[1] - frame) * world.tick_lag
+ chain += list(arguments)
+ var/loops = first["loop"]
+ // Started late (it waited out a glide): it plays from where it would have got to by now, so it ends on time.
+ var/late = (frame - event[1]) * world.tick_lag
+ if(late > 0 && !relative && (!loops || loops == 1))
+ chain = trim_chain(chain, late, standin)
+ if(track.mode == SANDY_TRACK_PUPPET && !relative)
+ keep_flip(chain, standin.transform)
+ if(track.oneshot && (!loops || loops == 1))
+ stretch_oneshot(chain)
+ for(var/list/arguments as anything in chain)
+ length += (arguments["time"] || 0) + (arguments["delay"] || 0)
+ animate(arglist(arguments))
+ if(loops && loops < 0)
+ length = INFINITY
+ else if(loops > 1)
+ length *= loops
+ track.anim_until = parallel ? max(track.anim_until, world.time + length) : world.time + length
+ event_log += "play [track.thing?.type] f[event[1]] at [frame] len=[length] steps=[length(chain)] pw=[chain[1]["pixel_w"]] t=[chain[1]["time"]] tag=[chain[1]["tag"]] shift=[shift_x],[shift_y]"
+ if(track.mode == SANDY_TRACK_PUPPET)
+ track.expect = standin.appearance // the chain's end values are ours, not game code's: nothing to fold
+ if(!parallel && !relative)
+ track.chain = chain
+ track.chain_start = world.time
+ track.chain_shift = list(shift_x, shift_y)
+
+/**
+ * `chain` (animate() argument lists, changed in place) is a one-shot effect's animation, compressed: one shorter than
+ * SANDY_REPLAY_ONESHOT_MIN is stretched to it, or it would be over before a frame is drawn. One that only fades out (a
+ * muzzle flash) is shown whole for a frame first and fades in the next.
+ */
+/datum/sandy_replay/proc/stretch_oneshot(list/chain)
+ var/span = 0
+ for(var/list/arguments as anything in chain)
+ span += arguments["time"] || 0
+ if(span <= 0 || span >= SANDY_REPLAY_ONESHOT_MIN)
+ return
+ var/list/first = chain[1]
+ var/fades = length(chain) == 1 && first["alpha"] == 0
+ var/factor = (fades ? world.tick_lag : SANDY_REPLAY_ONESHOT_MIN) / span
+ for(var/i in 1 to length(chain))
+ var/list/arguments = chain[i]
+ if(arguments["time"])
+ arguments["time"] *= factor
+ if(i > 1 && arguments["delay"])
+ arguments["delay"] *= factor
+ if(!fades)
+ return
+ // Held whole for a frame by a step that changes nothing, then faded. Not by a `delay` on the fade: through a delay the
+ // client draws where the chain ends (faded out), so an execution's flash showed a frame after its head burst.
+ var/atom/movable/target = first[1]
+ if(!ismovable(target))
+ return
+ var/list/hold = list(target)
+ hold["alpha"] = target.alpha
+ hold["time"] = world.tick_lag
+ for(var/name in list("tag", "flags", "delay", "loop"))
+ if(!isnull(first[name]))
+ hold[name] = first[name]
+ first -= name
+ first.Cut(1, 2)
+ chain.Insert(1, list(hold))
+
+/// `chain` (animate() argument lists, the first naming `thing`) with its first `late` deciseconds already gone by: the
+/// steps that were over are dropped, the one under way is shortened. A chain wholly over jumps to its last step's pose.
+/datum/sandy_replay/proc/trim_chain(list/chain, late, atom/movable/thing)
+ var/list/rest = list()
+ var/at = 0
+ for(var/list/step as anything in chain)
+ var/delay = step["delay"] || 0
+ var/span = (step["time"] || 0) + delay
+ if(!length(rest) && at + span <= late)
+ at += span
+ continue
+ var/list/arguments = step.Copy()
+ if(!length(rest))
+ if(arguments[1] != thing)
+ arguments.Insert(1, thing)
+ for(var/name in list("tag", "flags"))
+ if(isnull(arguments[name]) && !isnull(chain[1][name]))
+ arguments[name] = chain[1][name]
+ var/into = late - at
+ if(into < delay)
+ arguments["delay"] = delay - into
+ else
+ arguments -= "delay"
+ arguments["time"] = max((arguments["time"] || 0) - (into - delay), 0)
+ else if(arguments[1] == thing)
+ arguments.Cut(1, 2)
+ rest += list(arguments)
+ at += span
+ if(length(rest))
+ return rest
+ var/list/last = chain[length(chain)].Copy()
+ if(last[1] != thing)
+ last.Insert(1, thing)
+ for(var/name in list("tag", "flags"))
+ if(isnull(last[name]) && !isnull(chain[1][name]))
+ last[name] = chain[1][name]
+ last -= "delay"
+ last["time"] = 0
+ return list(last)
+
+/**
+ * A pose chain (a lift, a lean) holds the body's turn as it was when the chain started. A rig that flips a lying body
+ * the other way in that same tick leaves the chain on the old turn and the recorded frame on the new one, and a tween
+ * between the two halves passes through a matrix of no size: the body vanishes for it. Such a turn in `chain` (animate()
+ * argument lists, changed in place) is set to `now`, the turn the recorded frame shows.
+ */
+/datum/sandy_replay/proc/keep_flip(list/chain, matrix/now)
+ if(!istype(now))
+ return
+ var/size = abs(now.a * now.e - now.b * now.d)
+ // A chain that ends on the frame's own turn is drawing that turn (a body hauled round end for end, step by step:
+ // mantis_turn_head_toward()), not holding an old one: it plays as it was recorded.
+ var/matrix/last_turn
+ for(var/list/arguments as anything in chain)
+ if(istype(arguments["transform"], /matrix))
+ last_turn = arguments["transform"]
+ if(last_turn)
+ var/matrix/ending = matrix(now).Interpolate(last_turn, 0.5)
+ if(abs(ending.a * ending.e - ending.b * ending.d) >= size * 0.9)
+ return
+ for(var/list/arguments as anything in chain)
+ var/matrix/target = arguments["transform"]
+ if(!istype(target))
+ continue
+ var/matrix/halfway = matrix(now).Interpolate(target, 0.5)
+ if(abs(halfway.a * halfway.e - halfway.b * halfway.d) < size * 0.25)
+ arguments["transform"] = matrix(now)
+ event_log += "keep_flip [now.a],[now.b],[now.d],[now.e] over [target.a],[target.b],[target.d],[target.e]"
+
+/**
+ * A puppet was given a new frame's look while a journaled chain was playing on it, which ends the chain: plays the
+ * rest of it again from where it had got to. `shift_x`, `shift_y`: the pixel shift the puppet is drawn with now.
+ */
+/datum/sandy_replay/proc/resume_chain(datum/sandy_replay_track/track, shift_x, shift_y)
+ var/list/chain = track.chain
+ if(!length(chain) || track.anim_until <= world.time || !track.chain_shift)
+ return
+ var/atom/movable/thing = track.thing
+ var/list/first = chain[1]
+ var/cycle = 0
+ for(var/list/step as anything in chain)
+ cycle += (step["time"] || 0) + (step["delay"] || 0)
+ if(cycle <= 0)
+ return
+ var/elapsed = world.time - track.chain_start
+ var/loops = first["loop"] || 1
+ var/done_loops = round(elapsed / cycle)
+ if(loops > 0 && done_loops >= loops)
+ return
+ elapsed -= done_loops * cycle
+ var/move_x = shift_x - track.chain_shift[1]
+ var/move_y = shift_y - track.chain_shift[2]
+ var/list/rest = list()
+ var/at = 0
+ for(var/list/step as anything in chain)
+ var/span = (step["time"] || 0) + (step["delay"] || 0)
+ if(at + span <= elapsed && !length(rest))
+ at += span
+ continue
+ var/list/arguments = step.Copy()
+ if(!length(rest))
+ if(arguments[1] != thing)
+ arguments.Insert(1, thing)
+ var/into = elapsed - at
+ var/delay = arguments["delay"] || 0
+ if(into < delay)
+ arguments["delay"] = delay - into
+ else
+ arguments -= "delay"
+ arguments["time"] = max((arguments["time"] || 0) - (into - delay), 0)
+ arguments["loop"] = loops > 0 ? loops - done_loops : loops
+ arguments["flags"] = (arguments["flags"] || 0) | ANIMATION_END_NOW
+ else if(arguments[1] == thing)
+ arguments.Cut(1, 2)
+ if(!isnull(arguments["pixel_w"]))
+ arguments["pixel_w"] += move_x
+ if(!isnull(arguments["pixel_z"]))
+ arguments["pixel_z"] += move_y
+ rest += list(arguments)
+ at += span
+ keep_flip(rest, thing.transform)
+ for(var/list/arguments as anything in rest)
+ animate(arglist(arguments))
+ track.expect = thing.appearance
+ chains_resumed++
+
+// =========================================================================
+// SHOTS
+// =========================================================================
+// A shot's own loop moves it a few pixels a tick and keeps its spot in the tile in pixel_x and pixel_y, so a frame's
+// sample (its turf and look) is where it was, to the pixel. On top of that a shot needs: the spot it stopped at when it
+// hits (it is deleted between two samples), a straight line from frame to frame, and the shots still flying when the
+// recording ends held where they are for the replay, so the one real shot is never drawn twice or jumping ahead.
+
+/// Whether `thing` (a shot) has been fired: turned the way it flies and on its way.
+/datum/sandy_replay/proc/shot_fired(atom/movable/thing)
+ var/obj/projectile/shot = thing
+ return shot.fired
+
+/// Signal proc for [COMSIG_PROJECTILE_FIRE] on a shot seen before it was fired: its first frame, in the frame it was
+/// seen in, now that it is turned the way it flies.
+/datum/sandy_replay/proc/on_shot_fired(obj/projectile/shot)
+ SIGNAL_HANDLER
+ UnregisterSignal(shot, COMSIG_PROJECTILE_FIRE)
+ var/datum/sandy_replay_track/track = tracks[shot]
+ if(!track || state != SANDY_REPLAY_RECORDING)
+ return
+ track.last_raw = null
+ var/frame = max(track.first, frame_now())
+ sample_track(track, frame)
+ shot_from(shot.firer, frame)
+
+/// `shooter` fired a shot first drawn in `frame`, on the tile it stands on for real (shooting_at()).
+/datum/sandy_replay/proc/shot_from(atom/movable/shooter, frame)
+ var/datum/sandy_replay_track/track = shooter && tracks[shooter]
+ var/turf/spot = track && get_turf(shooter)
+ if(spot)
+ LAZYADD(track.shot_frames, list(list(frame, spot.x, spot.y)))
+
+/// The first frame from `from` on that `track`'s thing has a shot of its own drawn in on tile `x`, `y`, or 0. A shot
+/// fired from the tile it stepped off in the same frame isn't one: it is drawn there, where the step starts.
+/datum/sandy_replay/proc/shooting_at(datum/sandy_replay_track/track, from, x, y)
+ var/next = 0
+ for(var/list/shot as anything in track.shot_frames)
+ if(shot[1] >= from && shot[2] == x && shot[3] == y && (!next || shot[1] < next))
+ next = shot[1]
+ return next
+
+/// The first frame from `from` on that a finisher's posed pictures are drawn on tile `x`, `y`, or 0. One frame before
+/// counts too: a picture made as he lands is drawn from the frame it was made in, and his step is sampled in the next.
+/datum/sandy_replay/proc/posed_at(from, x, y)
+ var/next = 0
+ for(var/list/posed as anything in rig_frames)
+ if(posed[1] >= from - 1 && posed[2] == x && posed[3] == y && (!next || posed[1] < next))
+ next = posed[1]
+ return next
+
+/// Whether one more shot in the air can be recorded. Logs it, once a recording, when one can't.
+/datum/sandy_replay/proc/shot_room()
+ if(shots_live < SANDY_REPLAY_MAX_SHOTS)
+ shots_live++
+ return TRUE
+ if(!shots_capped)
+ log_game("Sandevistan replay of [key_name(user)]: more than [SANDY_REPLAY_MAX_SHOTS] shots in the air at once, the rest are not replayed.")
+ shots_capped++
+ return FALSE
+
+/// `look` (`shot`'s) as it is on screen. A shot that has hit fades out on the client as it reaches the spot
+/// (process_movement()), and its vars already hold the end of that: it is drawn reaching the spot.
+/datum/sandy_replay/proc/shot_look(obj/projectile/shot, look)
+ if(!shot.deletion_queued || shot.alpha == initial(shot.alpha))
+ return look
+ var/mutable_appearance/copy = new(look)
+ copy.alpha = initial(shot.alpha)
+ return copy.appearance
+
+/// `track`'s shot, or a beam's tracer, muzzle or impact effect, is being deleted: the spot and look it ends with are
+/// recorded. Returns the first frame it is gone in (0 when it isn't being recorded).
+/datum/sandy_replay/proc/shot_gone(datum/sandy_replay_track/track)
+ if(state != SANDY_REPLAY_RECORDING)
+ return 0
+ var/list/frames = track.frames
+ var/at = length(frames) ? frames[length(frames) - SANDY_FRAME_SIZE + SANDY_FRAME_INDEX] : track.first
+ var/end
+ if(track.flier)
+ shots_live--
+ if(!shot_fired(track.thing))
+ return 0 // spent before it flew (a shot at point blank lands inside fire()): never drawn, as it never is live
+ end = max(last_sampled + 1, at + 1) // its last frame is where it was a frame ago; this one is where it stopped
+ else
+ end = max(round(frame_due()), at) // an effect made and gone between two samples: one frame, with its finished look
+ track.last_raw = null
+ sample_track(track, end)
+ return end + 1
+
+/// A shot flies in a straight line from the spot it was drawn at to this frame's, over the `frames` frames between them
+/// (one, unless the replay's timer skipped one: it can come every other tick), as it did between the samples.
+/datum/sandy_replay/proc/fly(datum/sandy_replay_track/track, move_x, move_y, frames)
+ if((!move_x && !move_y) || abs(move_x) > SANDY_REPLAY_REACH * ICON_SIZE_X || abs(move_y) > SANDY_REPLAY_REACH * ICON_SIZE_Y)
+ return TRUE
+ track.glide_x = move_x
+ track.glide_y = move_y
+ track.glide_time = clamp(frames, 1, 4) * world.tick_lag
+ track.glide_until = world.time + track.glide_time
+ return TRUE
+
+/**
+ * The recording is over: the shots still flying stop where they are until the replay is over, as everyone near the
+ * user holds still for it. The replay draws them flying up to that spot and they fly on from it after, so a shot is
+ * never drawn twice (the replay's and the real one) or jumping on by however far it got while the replay played.
+ */
+/datum/sandy_replay/proc/hold_shots()
+ for(var/atom/movable/thing as anything in tracks)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(!track.flier)
+ continue
+ var/obj/projectile/shot = thing
+ if(shot.paused || shot.deletion_queued || !shot.fired)
+ continue
+ shot.paused = TRUE
+ held_shots += shot
+
+/// The replay is over: the shots it held fly on.
+/datum/sandy_replay/proc/release_shots()
+ for(var/obj/projectile/shot as anything in held_shots)
+ if(!QDELETED(shot))
+ shot.paused = FALSE
+ held_shots.Cut()
+ release_gore()
+
+/**
+ * Gore still flying when the recording ends (a gib sliding off on tg's streak, a torn-off part or organ on its
+ * tumble) holds where it is until the replay is over, as the shots do. Left to fly on, it lands while the replay plays
+ * and pops to its landing spot, with the blood it left on the way, the moment the replay hands back. A body or a thing
+ * knocked flying in the recording's last moments (tg's throw) holds in the air the same way: left to fly on under the
+ * replay, a corpse or a dropped gun is drawn where the recording last saw it and jumps to where it landed at the cut.
+ */
+/datum/sandy_replay/proc/hold_gore()
+ for(var/atom/movable/thing as anything in tracks)
+ if(QDELETED(thing) || track_is_shot(thing))
+ continue
+ var/datum/thrownthing/flight = thing.throwing
+ if(flight && !flight.paused)
+ flight.paused = TRUE
+ held_gore[flight] = list(world.time, flight.delayed_time)
+ if(isliving(thing))
+ continue
+ var/datum/move_loop/loop = thing.move_packet?.running_loop
+ if(loop && (loop.status & MOVELOOP_STATUS_RUNNING) && !(loop.status & MOVELOOP_STATUS_PAUSED))
+ loop.pause_loop()
+ held_gore += loop
+ var/datum/component/hv_tumble/tumble = thing.GetComponent(/datum/component/hv_tumble)
+ if(tumble?.step_timer)
+ held_gore[tumble] = max(timeleft(tumble.step_timer), world.tick_lag)
+ deltimer(tumble.step_timer)
+ tumble.step_timer = null
+
+/**
+ * The recording has run out. A kill in its last moments leaves its gore in the air: the replay would stop on the burst's
+ * first frames, and the real gore, held since the slow-mo ended, would jump to wherever it had got to and then finish
+ * its flight in the present, the same burst a second time. So the replay stays on its last frame while the gore lands:
+ * its own animations of it play out (a gib's arc) while the held gore is handed back and flies on for real under the
+ * replay, and only then does the replay hand everything back, with the gore at rest. Never longer than
+ * SANDY_REPLAY_LANDING_MAX. Returns whether it is still landing.
+ */
+/datum/sandy_replay/proc/land()
+ if(!landing_stage)
+ var/list/painting = paints_left()
+ if(!length(held_gore) && !gore_playing() && !oneshots_playing() && !length(painting))
+ return FALSE
+ landing_stage = 2
+ landing_started = world.time
+ deltimer(watchdog)
+ watchdog = addtimer(CALLBACK(src, PROC_REF(finish)), SANDY_REPLAY_LANDING_MAX + SANDY_REPLAY_WATCHDOG, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ for(var/datum/held as anything in held_gore)
+ var/atom/movable/thing
+ if(istype(held, /datum/move_loop))
+ var/datum/move_loop/loop = held
+ thing = loop.moving
+ else if(istype(held, /datum/component))
+ var/datum/component/tumble = held
+ thing = tumble.parent
+ // The time it had left to its next step was counted in the slow-mo, many times too long for now
+ held_gore[held] = world.tick_lag
+ else if(istype(held, /datum/thrownthing))
+ var/datum/thrownthing/flight = held
+ thing = flight.thrownthing
+ if(QDELETED(thing))
+ continue
+ landing |= thing // waited for whether this recording draws it or not
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(!track || track.landing || !(track in puppets))
+ continue
+ unmask(track)
+ track.landing = TRUE
+ thing.sandy_replay_resume(world.time - ended_at)
+ release_gore()
+ // A spray laid in the slow-mo's last moments was still painting in, slowed, when the recording ended, and the
+ // last frame has it half there. Its real paint ran on under the replay: handed back at the end as it is, it
+ // jumped to full at the cut. It carries on here from where the last frame has it, and the replay waits for it.
+ for(var/datum/sandy_replay_track/track as anything in painting)
+ paint_until = max(paint_until, painting[track])
+ unmask(track)
+ track.landing = TRUE
+ track.thing.sandy_replay_resume(world.time - ended_at)
+ // The surger's own last shot, held in the air at his gun, would hang there too: it flies on. Anyone else's
+ // stays held until everyone can move again.
+ for(var/obj/projectile/shot as anything in held_shots)
+ if(QDELETED(shot) || !(shot.firer == user || sandy_session_member(src, shot.firer)))
+ continue
+ var/datum/sandy_replay_track/shot_track = tracks[shot]
+ if(shot_track && !shot_track.landing && (shot_track in puppets))
+ unmask(shot_track)
+ shot_track.landing = TRUE
+ shot.paused = FALSE
+ held_shots -= shot
+ // A flash still lit when the recording ended (the slow-mo stretched it) would hang there for as long as this
+ // takes: it goes out
+ for(var/datum/sandy_replay_track/track as anything in puppets + standins)
+ if(!track.oneshot || track.landing || track.anim_until > world.time || track.last <= total + 1)
+ continue
+ var/atom/movable/drawn = track.mode == SANDY_TRACK_STANDIN ? track.standin : track.thing
+ if(QDELETED(drawn))
+ continue
+ track.landing = TRUE
+ animate(drawn, alpha = 0, time = 0.1 SECONDS)
+ if(world.time - landing_started >= SANDY_REPLAY_LANDING_MAX)
+ return FALSE
+ for(var/atom/movable/thing as anything in landing)
+ if(QDELETED(thing))
+ landing -= thing
+ continue
+ var/datum/move_loop/loop = thing.move_packet?.running_loop
+ var/datum/component/hv_tumble/tumble = thing.GetComponent(/datum/component/hv_tumble)
+ if(!(loop && (loop.status & MOVELOOP_STATUS_RUNNING)) && !tumble?.step_timer && !thing.throwing)
+ landing -= thing
+ landing_settle = world.time + 0.15 SECONDS
+ return length(landing) > 0 || world.time < landing_settle || world.time < paint_until || (world.time - landing_started < SANDY_REPLAY_LANDING_TWEENS && (gore_playing() || oneshots_playing()))
+
+/// The sprays the replay draws that were still painting in when the recording ended (hv_vis_paint(), slowed like the
+/// rest): each track with the world.time its paint is done by once it carries on from where the last frame has it.
+/// Not a smear running down a wall or a pool creeping wider: those take seconds, and nobody waits for them.
+/datum/sandy_replay/proc/paints_left()
+ . = list()
+ if(!ended_at)
+ return
+ var/held_for = world.time - ended_at
+ for(var/datum/sandy_replay_track/track as anything in puppets)
+ var/obj/effect/decal/cleanable/blood/hv_spray/spray = track.thing
+ if(track.landing || track.unmasked || QDELETED(spray) || !istype(spray) || istype(spray, /obj/effect/decal/cleanable/blood/hv_spray/wall))
+ continue
+ var/left = spray.sandy_replay_paint_carry(held_for, FALSE)
+ if(left > 0)
+ .[track] = world.time + left
+
+/// Whether the replay is still playing its own animation of gore thrown in the recording's last moments (a gib's arc
+/// from a head that burst as the slow-mo ended).
+/datum/sandy_replay/proc/gore_playing()
+ for(var/datum/sandy_replay_track/track as anything in puppets)
+ if(track.anim_until <= world.time || !length(track.events))
+ continue
+ var/atom/movable/thing = track.thing
+ // Not a pool: one creeps wider for seconds, and nobody waits for that
+ if(QDELETED(thing) || !(istype(thing, /obj/effect/decal/cleanable/blood/gibs) || istype(thing, /obj/item/bodypart) || istype(thing, /obj/item/organ)))
+ continue
+ var/list/last_event = track.events[length(track.events)]
+ if(last_event[1] >= total - SANDY_REPLAY_LANDING_FRAMES)
+ return TRUE
+ return FALSE
+
+/// Whether a one-shot effect is still playing out in the replay (the splash of a hit in the recording's last moments).
+/datum/sandy_replay/proc/oneshots_playing()
+ for(var/datum/sandy_replay_track/track as anything in standins)
+ if(track.oneshot && track.standin && track.anim_until > world.time)
+ return TRUE
+ return FALSE
+
+/// Whether `thing` is a shot (held by hold_shots()).
+/datum/sandy_replay/proc/track_is_shot(atom/movable/thing)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ return track?.flier
+
+/// The replay is over: the gore hold_gore() held flies on from where it was.
+/datum/sandy_replay/proc/release_gore()
+ for(var/datum/held as anything in held_gore)
+ if(QDELETED(held))
+ continue
+ if(istype(held, /datum/move_loop))
+ var/datum/move_loop/loop = held
+ loop.resume_loop()
+ else if(istype(held, /datum/component/hv_tumble))
+ var/datum/component/hv_tumble/tumble = held
+ if(!tumble.step_timer)
+ tumble.step_timer = addtimer(CALLBACK(tumble, TYPE_PROC_REF(/datum/component/hv_tumble, take_step)), held_gore[held], TIMER_STOPPABLE|TIMER_DELETE_ME)
+ else if(istype(held, /datum/thrownthing))
+ // It flies on from where it hung: its clock starts again as if the hold never was
+ var/datum/thrownthing/flight = held
+ var/list/hung = held_gore[held]
+ flight.start_time += world.time - hung[1]
+ flight.delayed_time = hung[2]
+ flight.paused = FALSE
+ held_gore.Cut()
+
+/// A shot drawn on itself was deleted mid-replay (it hit something in the recording's last tick): a stand-in flies
+/// the rest of its path.
+/datum/sandy_replay/proc/shot_to_standin(datum/sandy_replay_track/track)
+ track.mode = SANDY_TRACK_STANDIN
+ track.last = total + 1
+ standins += track
+ show(track)
+
+// =========================================================================
+// PLAYBACK
+// =========================================================================
+
+/// No progress bar shows during a replay (owner, 2026-11-12): tg's do_after bars (client images on the body's own
+/// screen) of the user and every body the replay holds, and the execution bars (finisher_bar.dm, objects on the
+/// executioner's tile, seen by all) within the replay's reach. Bars made while it plays are hidden as they are made
+/// (sandy_replay_hides_bars_at()). Whatever is still running at the end is shown again.
+/datum/sandy_replay/proc/hide_progress_bars()
+ hide_body_bars(user)
+ for(var/obj/effect/abstract/hv_exec_bar/bar as anything in GLOB.hv_exec_bars)
+ if(bar.invisibility < INVISIBILITY_ABSTRACT && bar_reach(get_turf(bar)))
+ bar.invisibility = INVISIBILITY_ABSTRACT
+ hidden_bars += bar
+
+/// Hides `body`'s own do_after bars from its client.
+/datum/sandy_replay/proc/hide_body_bars(mob/living/body)
+ for(var/target in body?.progressbars)
+ for(var/datum/progressbar/progress as anything in body.progressbars[target])
+ if(progress.user_client && (progress.bar in progress.user_client.images))
+ progress.user_client.images -= progress.bar
+ hidden_bars += progress
+
+/// Playback, every frame: what turned up near the user after the recording ended (a gib or blood still landing
+/// from the last blow, anything made since) isn't in the past being shown: it is hidden, by a filter (looks only),
+/// until the replay ends.
+/datum/sandy_replay/proc/hide_unborn()
+ for(var/turf/here as anything in centres())
+ for(var/atom/movable/thing in range(SANDY_REPLAY_HOLD_RANGE, here))
+ if(tracks[thing] || unborn[thing] || rig_hidden[thing] || thing == user || !recordable(thing))
+ continue
+ if(sandy_rig_picture(thing))
+ hide_rig_picture(thing)
+ continue
+ unborn[thing] = TRUE
+ thing.add_filter(SANDY_REPLAY_UNBORN, 1, color_matrix_filter(list(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
+
+/**
+ * Hides a live rig picture (a pose a finisher left on a body, held past the slow-mo) for the replay, which draws it on
+ * a stand-in. Not by a filter: the backbreaker's broken back carried a hiding filter all through its replay and was still
+ * drawn, the live pose on the floor while the replayed body was lifted (its pictures had a colour filter animated on them
+ * by the hit flash). Invisible, it isn't sent to anyone; shown again as the replay ends, it is drawn as it is by then.
+ */
+/datum/sandy_replay/proc/hide_rig_picture(atom/movable/thing)
+ if(!isnull(rig_hidden[thing]))
+ return
+ rig_hidden[thing] = thing.invisibility
+ thing.invisibility = INVISIBILITY_ABSTRACT
+
+/// Where the replay is watched from: the user, and in a shared slow-mo every other member (ware_sandy_timestop_shared.dm).
+/datum/sandy_replay/proc/centres()
+ . = list()
+ var/turf/here = get_turf(user)
+ if(here)
+ . += here
+ for(var/mob/living/member as anything in sandy_session_others(src, FALSE))
+ var/turf/there = get_turf(member)
+ if(there)
+ . |= there
+
+/// Whether `target` is within `reach` (SANDY_REPLAY_HOLD_RANGE unless given) of the user or another member of its
+/// shared slow-mo.
+/datum/sandy_replay/proc/near_centre(atom/target, reach = SANDY_REPLAY_HOLD_RANGE)
+ var/turf/spot = get_turf(target)
+ if(!spot)
+ return FALSE
+ for(var/turf/here as anything in centres())
+ if(spot.z == here.z && get_dist(spot, here) <= reach)
+ return TRUE
+ return FALSE
+
+/**
+ * The slow-mo is over and the replay starts next tick. For that tick the world would show as it really is, in its own
+ * colours: the last blow's gore at its landing spots, the dead where they fell, a moment before the replay jumps back.
+ * What the recording saw change or turn up is hidden for it (the user stays, so the view has someone in it).
+ */
+/datum/sandy_replay/proc/hide_pending()
+ for(var/atom/movable/thing as anything in tracks)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ if(thing == user || QDELETED(thing) || (length(track.frames) == SANDY_FRAME_SIZE && track.first == 0))
+ continue
+ pending_hidden += thing
+ thing.add_filter(SANDY_REPLAY_PENDING_HIDE, 1, color_matrix_filter(list(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
+
+/// The replay is starting (or isn't coming): what hide_pending() hid is drawn again, before the replay takes its looks.
+/datum/sandy_replay/proc/show_pending()
+ for(var/atom/movable/thing as anything in pending_hidden)
+ if(!QDELETED(thing))
+ thing.remove_filter(SANDY_REPLAY_PENDING_HIDE)
+ pending_hidden.Cut()
+
+/// Whether `spot` is close enough to the user for the replay to hide a bar on it.
+/datum/sandy_replay/proc/bar_reach(turf/spot)
+ return spot && near_centre(spot)
+
+/// Shows again the bars the replay hid that still exist.
+/datum/sandy_replay/proc/show_progress_bars()
+ for(var/datum/thing as anything in hidden_bars)
+ if(QDELETED(thing))
+ continue
+ if(istype(thing, /obj/effect/abstract/hv_exec_bar))
+ var/obj/effect/abstract/hv_exec_bar/bar = thing
+ bar.invisibility = initial(bar.invisibility)
+ else if(istype(thing, /datum/progressbar))
+ var/datum/progressbar/progress = thing
+ if(progress.user_client && progress.bar)
+ progress.user_client.images |= progress.bar
+ hidden_bars.Cut()
+
+/// Starts the replay: the last sample is everything's real final state, then everything goes back to frame 0.
+/datum/sandy_replay/proc/begin()
+ begin_timer = null
+ if(state != SANDY_REPLAY_PENDING)
+ return
+ if(QDELETED(user) || cyberware_time_stop_witnessed(user))
+ finish()
+ return
+ state = SANDY_REPLAY_PLAYING
+ show_pending()
+ hide_progress_bars()
+ watchdog = addtimer(CALLBACK(src, PROC_REF(finish)), (total + 2) * world.tick_lag + SANDY_REPLAY_WATCHDOG, TIMER_STOPPABLE | TIMER_DELETE_ME)
+ try
+ setup_playback()
+ catch(var/exception/error)
+ finish()
+ stack_trace("Sandevistan replay failed to start: [error] ([error.file]:[error.line])")
+ return
+ if(finished)
+ return
+ // The cut to the replay is the change of scene: the slow-mo's pale release flash would only wash out its first frames.
+ // It is already fading on its own (out of user.screens), so it is taken off the client's screen directly.
+ for(var/mob/living/viewer as anything in list(user) + sandy_session_others(src)) // every member of a shared slow-mo
+ viewer.clear_fullscreen(SANDY_REPLAY_RELEASE_FLASH, FALSE)
+ for(var/atom/movable/screen/fullscreen/flash/sandy_release/flash in viewer.client?.screen)
+ viewer.client.screen -= flash
+ play_started = world.time
+ // The surge sound below goes to the replay's viewers from where each watches, not from their real bodies.
+ GLOB.sandy_replay_routing = src
+ GLOB.sandy_replay_routing_time = world.time
+ sandy_member_views() // each member of a shared slow-mo watches its own replayed self (ware_sandy_timestop_shared.dm)
+ // The surge coming on, as anyone near heard the replay's user at its first frame (ware_sandy_sound.dm).
+ var/turf/first = user_track ? locate(user_track.frames[SANDY_FRAME_X], user_track.frames[SANDY_FRAME_Y], user_track.frames[SANDY_FRAME_Z]) : null
+ play_to_viewers(first || get_turf(user), SANDEVISTAN_EXTERNAL_SOUND, 100, TRUE, 0, SOUND_FALLOFF_EXPONENT, rand(100 - SANDEVISTAN_EXTERNAL_SPREAD, 100 + SANDEVISTAN_EXTERNAL_SPREAD) / 100, TRUE, TRUE, SOUND_DEFAULT_FALLOFF_DISTANCE, TRUE)
+ play_timer = addtimer(CALLBACK(src, PROC_REF(play_frame)), world.tick_lag, TIMER_LOOP | TIMER_STOPPABLE | TIMER_DELETE_ME)
+ play_frame()
+ GLOB.sandy_replay_routing = null
+
+/datum/sandy_replay/proc/setup_playback()
+ lock(user)
+ for(var/atom/movable/thing as anything in tracks)
+ var/datum/sandy_replay_track/track = tracks[thing]
+ track.last_raw = null
+ sample_track(track, total)
+ if(isliving(thing))
+ lock(thing)
+ else if(ismecha(thing))
+ hold_mech(thing)
+ if(length(track.frames) == SANDY_FRAME_SIZE && track.first == 0)
+ continue // it never changed: nothing to show
+ if(sandy_rig_picture(thing))
+ // A rig picture still showing (fading out as the move hands the body back, or holding the body in a pose
+ // past the slow-mo): drawn on a stand-in, and the real one is hidden for the replay (hide_rig_picture()).
+ // finish() shows it again as it really is by then.
+ hide_rig_picture(thing)
+ track.mode = SANDY_TRACK_STANDIN
+ standins += track
+ else if(isturf(thing.loc))
+ track.mode = SANDY_TRACK_PUPPET
+ puppets += track
+ mask(track)
+ else
+ track.mode = SANDY_TRACK_STANDIN
+ standins += track
+ for(var/datum/sandy_replay_track/track as anything in gone)
+ track.mode = SANDY_TRACK_STANDIN
+ standins += track
+ gone.Cut()
+ user_track = tracks[user]
+ // What is left of the trail the surge itself drew stands where the slow-mo ended: the replay draws its own
+ for(var/turf/here as anything in centres())
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/left_over in range(SANDY_REPLAY_HOLD_RANGE, here))
+ if(!istype(left_over, /obj/effect/temp_visual/decoy/fading/cascade/replay))
+ qdel(left_over)
+ // A surge's ring still spreading is the slow-mo's own look too
+ for(var/obj/effect/temp_visual/cyberware_time_ring/ring in range(SANDY_REPLAY_HOLD_RANGE, here))
+ qdel(ring)
+ hold_nearby()
+ RegisterSignal(user, COMSIG_MOVABLE_Z_CHANGED, PROC_REF(on_user_z_changed))
+ if(user.client && user.stat != DEAD && isturf(user.loc) && user_track?.mode == SANDY_TRACK_PUPPET)
+ eye = new(user.loc)
+ eye_pixel_x = user.client.pixel_x
+ eye_pixel_y = user.client.pixel_y
+ user.reset_perspective(eye)
+ clear_view()
+
+/// Fullscreens that follow the user's real health (update_damage_hud()): crit, crit vision, oxygen and the brute and
+/// burn vignette. With the blindness of being knocked out (only when nothing else blinds them) they'd paint the
+/// user's present state over a replay of the moments before it.
+#define SANDY_REPLAY_CRIT_SCREENS list("crit", "critvision", "oxy", "brute")
+
+/**
+ * A user who went down in the slow-mo watches their replay like anyone else: their health and knocked-out screens
+ * come off their client's view (not off the mob, so tg keeps updating them) and go back in finish(). Called at the
+ * start and every frame, as Life() can put one back. In a shared slow-mo every other member with a client too.
+ */
+/datum/sandy_replay/proc/clear_view()
+ if(eye && sandy_replay_clear_view_of(user))
+ view_cleared = TRUE
+ for(var/mob/living/member as anything in sandy_session_others(src))
+ if(sandy_replay_clear_view_of(member))
+ members_cleared[member] = TRUE
+
+/// Takes `body`'s health and knocked-out screens off its client's view. TRUE if any came off.
+/proc/sandy_replay_clear_view_of(mob/living/body)
+ var/client/viewer = body?.client
+ if(!viewer)
+ return FALSE
+ for(var/category in SANDY_REPLAY_CRIT_SCREENS)
+ var/atom/movable/screen/fullscreen/screen = body.screens[category]
+ if(screen && (screen in viewer.screen))
+ viewer.screen -= screen
+ . = TRUE
+ var/datum/status_effect/grouped/blindness/blind = body.has_status_effect(/datum/status_effect/grouped/blindness)
+ if(!blind || length(blind.sources) != 1 || !(UNCONSCIOUS_TRAIT in blind.sources))
+ return
+ var/atom/movable/screen/fullscreen/dark = body.screens[blind.id]
+ if(dark && (dark in viewer.screen))
+ viewer.screen -= dark
+ . = TRUE
+ if(body.remove_client_colour(REF(blind)))
+ . = TRUE
+
+/// Puts back what clear_view() took off, as each viewer's real state now has it.
+/datum/sandy_replay/proc/restore_view()
+ for(var/mob/living/member as anything in members_cleared)
+ sandy_replay_restore_view_of(member)
+ members_cleared.Cut()
+ if(!view_cleared)
+ return
+ view_cleared = FALSE
+ sandy_replay_restore_view_of(user)
+
+/proc/sandy_replay_restore_view_of(mob/living/body)
+ if(QDELETED(body))
+ return
+ // Worked out again from the body's state now (Life() ran on through the replay), then shown.
+ body.update_damage_hud()
+ var/datum/status_effect/grouped/blindness/blind = body.has_status_effect(/datum/status_effect/grouped/blindness)
+ blind?.update_blindness()
+ body.reload_fullscreen()
+
+#undef SANDY_REPLAY_CRIT_SCREENS
+
+/// Holds every mob and mech near the user, in the bubble or not: a crewmate or an NPC just outside it can't act on
+/// the held ones (or on the user) while the replay plays. Called at the start and every frame, for arrivals.
+/datum/sandy_replay/proc/hold_nearby()
+ var/turf/here = get_turf(user)
+ if(!here)
+ return
+ for(var/atom/movable/found as anything in SSspatial_grid.orthogonal_range_search(here, SPATIAL_GRID_CONTENTS_TYPE_HEARING, SANDY_REPLAY_HOLD_RANGE))
+ if(isliving(found))
+ lock(found)
+ var/obj/vehicle/sealed/mecha/mech = get_atom_on_turf(found, /obj/vehicle/sealed/mecha)
+ if(istype(mech)) // a pilot, or something hearing inside one
+ hold_mech(mech)
+ sandy_hold_members() // and around every member of a shared slow-mo (ware_sandy_timestop_shared.dm)
+ hold_machines()
+
+/// Stops the clocks of the turrets and lit grenades the slow-mo slows (cyberware_push_machine_deadlines()) near the
+/// user and every member: a turret doesn't track or fire (see tryToShootAt() below) and a fuse doesn't burn while the
+/// replay holds everyone. A turret someone is steering by hand is theirs and is left alone.
+/datum/sandy_replay/proc/hold_machines()
+ for(var/turf/here as anything in centres())
+ for(var/obj/thing in range(SANDY_REPLAY_HOLD_RANGE, here))
+ if(held_machines[thing] || QDELETED(thing))
+ continue
+ if(istype(thing, /obj/machinery/porta_turret))
+ var/obj/machinery/porta_turret/turret = thing
+ if(turret.manual_control)
+ continue
+ else if(!cyberware_lit_grenade(thing))
+ continue
+ held_machines[thing] = TRUE
+ sandy_replay_clock_stop(thing)
+
+/// A turret a replay holds doesn't pick a target. Every automatic turret's scan ends here (cyberware_stealth.dm);
+/// manual control goes through target() and isn't touched.
+/obj/machinery/porta_turret/tryToShootAt(list/atom/movable/targets)
+ if(GLOB.sandy_replay_stopped_clocks[src])
+ return FALSE
+ return ..()
+
+/// Switches `mech` off for the replay.
+/datum/sandy_replay/proc/hold_mech(obj/vehicle/sealed/mecha/mech)
+ if(!isnull(mechs[mech]) || QDELETED(mech))
+ return
+ mechs[mech] = mech.completely_disabled
+ mech.completely_disabled = TRUE
+ sandy_replay_clock_stop(mech)
+
+/// Things whose clocks a replay's hold has stopped, to list(world.time they were last pushed to, holds on it now).
+GLOBAL_LIST_EMPTY(sandy_replay_stopped_clocks)
+
+/**
+ * The replay's hold is a pause for an NPC or a machine: every clock the slow-mo slows (cyberware_push_deadlines(),
+ * cyberware_push_machine_deadlines()) is pushed back every frame of the hold by the time that passed, so it picks up
+ * where it was when the hold ends instead of finding every cooldown run out at once. Two replays holding the same thing
+ * at once push it once. Players' clocks are left alone.
+ */
+/proc/sandy_replay_clock_stop(atom/movable/thing)
+ if(ismob(thing))
+ var/mob/body = thing
+ if(body.ckey)
+ return
+ var/list/stop = GLOB.sandy_replay_stopped_clocks[thing]
+ if(stop)
+ stop[2] += 1
+ else
+ GLOB.sandy_replay_stopped_clocks[thing] = list(world.time, 1)
+
+/// Pushes `thing`'s stopped clocks back by the time since they were last pushed.
+/proc/sandy_replay_clock_catch_up(atom/movable/thing)
+ var/list/stop = GLOB.sandy_replay_stopped_clocks[thing]
+ if(!stop)
+ return
+ var/since = stop[1]
+ var/held = world.time - since
+ if(held <= 0)
+ return
+ stop[1] = world.time
+ if(QDELETED(thing))
+ return
+ if(isliving(thing))
+ cyberware_push_deadlines(thing, held, since)
+ else
+ cyberware_push_machine_deadlines(thing, held, since)
+
+/// Every replay frame: everything held stays where its clocks were.
+/proc/sandy_replay_clocks_tick()
+ for(var/atom/movable/thing as anything in GLOB.sandy_replay_stopped_clocks)
+ sandy_replay_clock_catch_up(thing)
+
+/// A replay let `thing` go: its clocks catch up, and run again once no other replay holds it.
+/proc/sandy_replay_clock_start(atom/movable/thing)
+ var/list/stop = GLOB.sandy_replay_stopped_clocks[thing]
+ if(!stop)
+ return
+ sandy_replay_clock_catch_up(thing)
+ stop[2] -= 1
+ if(stop[2] <= 0)
+ GLOB.sandy_replay_stopped_clocks -= thing
+
+/// Pauses `body`'s AI and locks its player's input. No stun: decisions and input only.
+/datum/sandy_replay/proc/lock(mob/living/body)
+ if(locked[body] || QDELETED(body))
+ return
+ locked[body] = TRUE
+ sandy_replay_clock_stop(body)
+ hide_body_bars(body)
+ if(body.ckey && body.stat != DEAD)
+ body.add_traits(list(TRAIT_IMMOBILIZED, TRAIT_INCAPACITATED), SANDY_REPLAY_TRAIT)
+ if(body.ai_controller)
+ // Taken before the pause: lifting it makes tg work the status out afresh (update_able_to_run())
+ ai_before[body] = list(body.ai_controller.ai_status, body.ai_controller.get_expected_ai_status())
+ ADD_TRAIT(body, TRAIT_AI_PAUSED, SANDY_REPLAY_TRAIT)
+ if(isanimal(body))
+ var/mob/living/simple_animal/animal = body
+ locked[body] = animal.AIStatus
+ animal.toggle_ai(AI_OFF)
+
+/datum/sandy_replay/proc/unlock(mob/living/body)
+ var/was = locked[body]
+ sandy_replay_clock_start(body) // its clocks pick up where they were
+ if(QDELETED(body))
+ return
+ body.remove_traits(list(TRAIT_IMMOBILIZED, TRAIT_INCAPACITATED, TRAIT_AI_PAUSED), SANDY_REPLAY_TRAIT)
+ // The hold is a pause: an AI goes on as it was. Lifting the pause has tg set the status it expects, which undoes a
+ // status something set on purpose (a captive's AI switched off, one switched on by hand). With nothing else changed
+ // since the hold began (tg expects what it expected then), the AI gets back the status it was taken with.
+ var/list/before = ai_before[body]
+ var/datum/ai_controller/brain = body.ai_controller
+ if(before && brain?.able_to_run && before[1] != before[2] && brain.ai_status != before[1] && brain.get_expected_ai_status() == before[2])
+ brain.set_ai_status(before[1])
+ // A knockdown or crit that ended mid-replay tried to stand them up then (get_up()'s do_after), and the lock's
+ // TRAIT_INCAPACITATED failed it: nothing would try again, so they'd lie there. tg's own end-of-floored step.
+ if(body.stat != DEAD && body.body_position == LYING_DOWN && !HAS_TRAIT(body, TRAIT_FLOORED))
+ body.on_floored_end()
+ if(isanimal(body) && isnum(was))
+ var/mob/living/simple_animal/animal = body
+ if(animal.AIStatus == AI_OFF)
+ animal.toggle_ai(was)
+
+/// Puts the puppet on `track`'s thing: its real look is kept, and it is drawn as its current frame.
+/datum/sandy_replay/proc/mask(datum/sandy_replay_track/track)
+ var/atom/movable/thing = track.thing
+ keep_real(track)
+ GLOB.sandy_replay_masked[thing] = track
+ sandy_replay_masks = length(GLOB.sandy_replay_masked)
+ RegisterSignal(thing, COMSIG_MOVABLE_MOVED, PROC_REF(on_puppet_moved))
+ RegisterSignal(thing, COMSIG_ATOM_DIR_CHANGE, PROC_REF(on_puppet_turned))
+ show(track)
+
+/// Takes `track`'s thing as it is now for its real look.
+/datum/sandy_replay/proc/keep_real(datum/sandy_replay_track/track)
+ var/atom/movable/thing = track.thing
+ track.saved_look = thing.appearance
+ track.saved_dir = thing.dir
+ track.saved_opacity = thing.opacity
+ track.saved_luminosity = thing.luminosity
+
+/// Gives `track`'s thing its real look back. Assigning an appearance never touches density, and opacity and
+/// luminosity are pinned while it is a puppet, so nothing the game reads changes.
+/datum/sandy_replay/proc/wear_real(datum/sandy_replay_track/track)
+ var/atom/movable/thing = track.thing
+ if(thing.appearance != track.expect)
+ fold(track)
+ animate(thing, time = 0, flags = ANIMATION_END_NOW)
+ thing.appearance = track.saved_look
+ thing.dir = track.saved_dir
+ pin(track)
+
+/**
+ * The replay is over: `track`'s thing gets its real look back. With `turns`, a body that really got up or went down
+ * while the replay played (a knockdown running out under the hold) turns from the way it was last drawn to the way it
+ * really lies, as tg turns a body, instead of snapping upright at the cut.
+ */
+/datum/sandy_replay/proc/hand_back(datum/sandy_replay_track/track, turns)
+ var/atom/movable/thing = track.thing
+ var/matrix/drawn = (turns && isliving(thing) && track.cursor >= 0 && thing.alpha) ? matrix(thing.transform) : null
+ wear_real(track)
+ // A body's pose the replay was still playing (a corpse slid or slumped and held so, a twitch) carries on from where
+ // the last frame has it, on its real tile: wearing its real look ended its own copy of it, and it would snap back.
+ if(turns && isliving(thing) && chain_ends_real(track))
+ resume_chain(track, 0, 0)
+ return
+ if(!drawn || (drawn ~= thing.transform))
+ return
+ var/matrix/real = matrix(thing.transform)
+ var/matrix/halfway = drawn.Interpolate(real, 0.5)
+ if(abs(halfway.a * halfway.e - halfway.b * halfway.d) < 0.25) // a half turn blends through nothing: it flips at once
+ return
+ thing.transform = drawn
+ animate(thing, transform = real, time = SANDY_REPLAY_TURN_TIME, easing = SINE_EASING)
+
+/**
+ * Whether the chain playing on `track`'s puppet is still going and ends where the real look is: its last pixel_w,
+ * pixel_z and transform, less the shift it was played with, are the thing's own now. A chain that ends anywhere else (the
+ * body stood up or was turned for real under the replay) would carry an old pose over the real one, and isn't resumed.
+ */
+/datum/sandy_replay/proc/chain_ends_real(datum/sandy_replay_track/track)
+ var/list/chain = track.chain
+ if(!length(chain) || track.anim_until <= world.time || !track.chain_shift)
+ return FALSE
+ var/atom/movable/thing = track.thing
+ var/list/last = chain[length(chain)]
+ if(!isnull(last["pixel_w"]) && last["pixel_w"] - track.chain_shift[1] != thing.pixel_w)
+ return FALSE
+ if(!isnull(last["pixel_z"]) && last["pixel_z"] - track.chain_shift[2] != thing.pixel_z)
+ return FALSE
+ var/matrix/turned = last["transform"]
+ if(istype(turned) && !(turned ~= thing.transform))
+ return FALSE
+ return TRUE
+
+/// Appearance assignment copies opacity and luminosity: keep the real ones.
+/datum/sandy_replay/proc/pin(datum/sandy_replay_track/track)
+ var/atom/movable/thing = track.thing
+ if(thing.opacity != track.saved_opacity)
+ thing.opacity = track.saved_opacity
+ if(thing.luminosity != track.saved_luminosity)
+ thing.luminosity = track.saved_luminosity
+
+/// A wrapped proc is about to change `track`'s thing: it gets its real look for that.
+/datum/sandy_replay/proc/unmask(datum/sandy_replay_track/track)
+ wear_real(track)
+ track.unmasked = TRUE
+ unmasks++
+
+/// The change is done: what the thing looks like now is its real look, and the puppet goes back on.
+/datum/sandy_replay/proc/remask(datum/sandy_replay_track/track)
+ if(!track.unmasked || QDELETED(track.thing))
+ return
+ track.unmasked = FALSE
+ keep_real(track)
+ show(track)
+
+/**
+ * Something changed a puppet without going through a wrapped proc (a direct var write, an animate()). Carries the
+ * vars that differ from what was drawn over to the real look. Best effort: a var set to the very value the puppet
+ * was showing can't be seen.
+ */
+/datum/sandy_replay/proc/fold(datum/sandy_replay_track/track)
+ var/mutable_appearance/now = new(track.thing)
+ var/mutable_appearance/drawn = new(track.expect)
+ var/mutable_appearance/real = new(track.saved_look)
+ var/list/changed = list()
+ // pixel_x and pixel_y are taken as plain writes (tg sets them far more often than it shifts them). pixel_w and
+ // pixel_z carry the puppet's own shift, so only what was added to them is carried over.
+ for(var/name in list("icon", "icon_state", "alpha", "layer", "plane", "invisibility", "name", "blend_mode", "pixel_x", "pixel_y"))
+ if(now.vars[name] != drawn.vars[name])
+ real.vars[name] = now.vars[name]
+ changed += name
+ if(!(now.color ~= drawn.color))
+ real.color = now.color
+ changed += "color"
+ if(!(now.transform ~= drawn.transform))
+ real.transform = now.transform
+ changed += "transform"
+ for(var/name in list("pixel_w", "pixel_z"))
+ if(now.vars[name] != drawn.vars[name])
+ real.vars[name] += now.vars[name] - drawn.vars[name]
+ changed += name
+ if(!length(changed))
+ return
+ track.saved_look = real.appearance
+ unhooked++
+ folded += "[track.thing.type]: [changed.Join(",")]"
+
+/// Moves `track` on to the newest frame at or before `frame`. Returns TRUE if that is a new one.
+/datum/sandy_replay/proc/advance(datum/sandy_replay_track/track, frame)
+ var/list/frames = track.frames
+ var/old = track.cursor
+ var/at = old
+ var/end = length(frames)
+ while(at + SANDY_FRAME_SIZE < end && frames[at + SANDY_FRAME_SIZE + SANDY_FRAME_INDEX] <= frame)
+ at += SANDY_FRAME_SIZE
+ if(at == old)
+ return FALSE
+ track.came_from = old
+ track.cursor = at
+ var/left = track.glide_until - world.time
+ var/carry_x = 0
+ var/carry_y = 0
+ if(left > 0 && track.glide_time > 0)
+ var/list/still = glide_at(track, left)
+ carry_x = still[1]
+ carry_y = still[2]
+ track.glide_until = 0
+ track.glide_way = null
+ if(old < 0 || !frames[old + SANDY_FRAME_Z] || frames[old + SANDY_FRAME_Z] != frames[at + SANDY_FRAME_Z])
+ track.turn_until = 0
+ return TRUE
+ var/mutable_appearance/was = frames[old + SANDY_FRAME_LOOK]
+ var/mutable_appearance/now = frames[at + SANDY_FRAME_LOOK]
+ // A turn (a fall, getting up) is a tween on the client: the recording only saw where it ended.
+ if(!(was.transform ~= now.transform))
+ var/matrix/start = matrix(was.transform)
+ var/turn_left = track.turn_until - world.time
+ if(turn_left > 0 && track.turn_time > 0)
+ var/matrix/turning = track.turn_from
+ start = turning.Interpolate(track.turn_to, 1 - turn_left / track.turn_time)
+ track.turn_from = start
+ track.turn_to = matrix(now.transform)
+ // On the replay's clock, as everything else: compressed ten times a fall is a fifth of a frame. A rig's own
+ // snap (a body brought upright onto the blades) is then upright the frame it was, not turning through the move.
+ track.turn_time = SANDY_REPLAY_TURN_TIME * world.tick_lag * rate_at(frames[at + SANDY_FRAME_INDEX])
+ track.turn_until = world.time + track.turn_time
+ // A half turn (a body flipped from lying one way to the other, as a rig move leaves it) blends through a
+ // matrix of no size halfway: the body would vanish for the tween. It flips at once instead.
+ var/matrix/halfway = start.Interpolate(track.turn_to, 0.5)
+ if(abs(halfway.a * halfway.e - halfway.b * halfway.d) < 0.25)
+ track.turn_until = 0
+ // Tween from where it was drawn to where it is now.
+ var/stepped = frames[old + SANDY_FRAME_X] != frames[at + SANDY_FRAME_X] || frames[old + SANDY_FRAME_Y] != frames[at + SANDY_FRAME_Y]
+ var/move_x = (frames[old + SANDY_FRAME_X] - frames[at + SANDY_FRAME_X]) * ICON_SIZE_X + (was.pixel_x + was.pixel_w) - (now.pixel_x + now.pixel_w) + carry_x
+ var/move_y = (frames[old + SANDY_FRAME_Y] - frames[at + SANDY_FRAME_Y]) * ICON_SIZE_Y + (was.pixel_y + was.pixel_z) - (now.pixel_y + now.pixel_z) + carry_y
+ if(track.flier)
+ return fly(track, move_x, move_y, frames[at + SANDY_FRAME_INDEX] - frames[old + SANDY_FRAME_INDEX])
+ var/glide_max = track.surger ? SANDY_REPLAY_SURGE_GLIDE_MAX : SANDY_REPLAY_GLIDE_MAX
+ if((!move_x && !move_y) || abs(move_x) > glide_max || abs(move_y) > glide_max)
+ return TRUE
+ var/time = world.tick_lag
+ if(stepped)
+ // A step glides until the next one, like a walk does.
+ // The last step of a walk glides two ticks, or less if the thing's next frame (a move starting on that tile)
+ // comes sooner: it is on its tile by then.
+ var/ticks = at + SANDY_FRAME_SIZE < end ? min(2, frames[at + SANDY_FRAME_SIZE + SANDY_FRAME_INDEX] - frames[at + SANDY_FRAME_INDEX]) : 2
+ for(var/next = at + SANDY_FRAME_SIZE, next < end, next += SANDY_FRAME_SIZE)
+ if(frames[next + SANDY_FRAME_X] != frames[at + SANDY_FRAME_X] || frames[next + SANDY_FRAME_Y] != frames[at + SANDY_FRAME_Y] || frames[next + SANDY_FRAME_Z] != frames[at + SANDY_FRAME_Z])
+ ticks = frames[next + SANDY_FRAME_INDEX] - frames[at + SANDY_FRAME_INDEX]
+ break
+ time = clamp(ticks, 1, 5) * world.tick_lag
+ var/own_glide = LAZYACCESS(track.glides, "[frames[at + SANDY_FRAME_INDEX]]")
+ if(own_glide) // a corpse sliding: as long as the game took over it
+ time = own_glide * world.tick_lag
+ // A move's first pose due sooner (an execution started as the step landed): the glide is done by then. Not a
+ // corpse's slide: its fall plays over the slide, as it did.
+ if(!own_glide && track.events && track.event_at <= length(track.events))
+ var/list/next_event = track.events[track.event_at]
+ var/due = (next_event[1] - frame) * world.tick_lag
+ if(due >= 0 && due < time)
+ time = max(due, world.tick_lag / 2)
+ // It shoots sooner (it stepped and stopped to fire): it is on the tile by the frame its muzzle flash and bullet are
+ // drawn on it, or they are drawn ahead of the gun while it is still gliding there.
+ var/shot_frame = shooting_at(track, frames[at + SANDY_FRAME_INDEX], frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y])
+ if(shot_frame && !own_glide)
+ time = min(time, max((shot_frame - frame) * world.tick_lag, 0))
+ // A surger who starts a finisher as he lands (a dash straight into an execution): the move's pictures, his blades
+ // and the slashes are drawn on that tile from their first frame, and he was still gliding in under them.
+ if(track.surger && !own_glide)
+ var/posed_frame = posed_at(frames[at + SANDY_FRAME_INDEX], frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y])
+ if(posed_frame)
+ time = min(time, max((posed_frame - frame) * world.tick_lag, world.tick_lag / 2))
+ else if(left > 0)
+ time = left
+ track.glide_x = move_x
+ track.glide_y = move_y
+ track.glide_step = stepped || (left > 0 && track.glide_step) // what is left of a step glides on with this one
+ track.glide_time = time
+ track.glide_until = world.time + time
+ if(track.surger && stepped)
+ track.glide_way = glide_corners(track, old, at, move_x, move_y)
+ return TRUE
+
+/**
+ * The way a surger glides from frame `old` to frame `at` when it turned a corner between them (kept_way()): flat x, y
+ * pixel offsets from where it ends, from `move_x`, `move_y` (where it starts) through each tile it stepped on to 0, 0.
+ * Null for a straight run, which glides as everything else does. Gliding straight across a corner, the puppet was
+ * never on the tiles its trail is laid on.
+ */
+/datum/sandy_replay/proc/glide_corners(datum/sandy_replay_track/track, old, at, move_x, move_y)
+ var/list/frames = track.frames
+ var/turf/left = locate(frames[old + SANDY_FRAME_X], frames[old + SANDY_FRAME_Y], frames[old + SANDY_FRAME_Z])
+ var/turf/reached = locate(frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y], frames[at + SANDY_FRAME_Z])
+ if(!left || !reached)
+ return null
+ var/list/way = kept_way(track, left, reached)
+ if(!way || way_is_straight(way, left, reached))
+ return null
+ . = list(move_x, move_y)
+ for(var/i in 2 to length(way) - 1)
+ var/turf/corner = way[i]
+ . += (corner.x - reached.x) * ICON_SIZE_X
+ . += (corner.y - reached.y) * ICON_SIZE_Y
+ . += 0
+ . += 0
+
+/// Whether `way` (tiles from `left` to `reached`) is the straight line between them.
+/datum/sandy_replay/proc/way_is_straight(list/way, turf/left, turf/reached)
+ var/list/straight = get_line(left, reached)
+ if(length(way) != length(straight))
+ return FALSE
+ for(var/i in 1 to length(way))
+ if(way[i] != straight[i])
+ return FALSE
+ return TRUE
+
+/// Where a track's tween is with `left` of its time to go: list(x, y) pixels from where it ends.
+/datum/sandy_replay/proc/glide_at(datum/sandy_replay_track/track, left)
+ var/list/way = track.glide_way
+ if(!way)
+ return list(track.glide_x * left / track.glide_time, track.glide_y * left / track.glide_time)
+ var/legs = length(way) / 2 - 1
+ var/along = clamp(1 - left / track.glide_time, 0, 1) * legs
+ var/leg = min(round(along), legs - 1) // the leg it is on, from 0
+ var/part = along - leg
+ return list(way[leg * 2 + 1] + (way[leg * 2 + 3] - way[leg * 2 + 1]) * part, way[leg * 2 + 2] + (way[leg * 2 + 4] - way[leg * 2 + 2]) * part)
+
+/**
+ * The legs a track's tween has still to cover with `left` of its time to go, for an animate() chain: a list of
+ * list(x, y, time), each the pixels from where it ends that a leg stops at and how long the leg takes. One leg for a
+ * straight tween.
+ */
+/datum/sandy_replay/proc/glide_legs(datum/sandy_replay_track/track, left)
+ var/list/way = track.glide_way
+ if(!way)
+ return list(list(0, 0, left))
+ . = list()
+ var/legs = length(way) / 2 - 1
+ var/leg_time = track.glide_time / legs
+ var/along = clamp(1 - left / track.glide_time, 0, 1) * legs
+ var/leg = min(round(along), legs - 1)
+ for(var/i in leg to legs - 1)
+ . += list(list(way[i * 2 + 3], way[i * 2 + 4], i == leg ? (1 - (along - leg)) * leg_time : leg_time))
+
+/// Draws `track`'s current frame on its thing or its stand-in.
+/datum/sandy_replay/proc/show(datum/sandy_replay_track/track)
+ var/list/frames = track.frames
+ var/at = track.cursor
+ var/visible = at >= 0 && frames[at + SANDY_FRAME_Z]
+ if(track.mode == SANDY_TRACK_STANDIN)
+ var/turf/spot = visible ? locate(frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y], frames[at + SANDY_FRAME_Z]) : null
+ if(!spot)
+ if(track.standin)
+ track.standin.loc = null
+ return
+ if(!track.standin)
+ track.standin = new(spot)
+ else
+ track.standin.loc = spot // ours, abstract and on no grid: nothing to tell
+ var/obj/effect/abstract/sandy_replay_standin/standin = track.standin
+ if(track.anim_until > world.time)
+ return // a journaled animation is playing on it: it ends where this frame's look is
+ standin.appearance = frames[at + SANDY_FRAME_LOOK]
+ track.drawn_look = frames[at + SANDY_FRAME_LOOK]
+ standin.dir = frames[at + SANDY_FRAME_DIR]
+ standin.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ standin.opacity = FALSE
+ standin.luminosity = 0
+ settle(track, standin, 0, 0)
+ if(track.plays_out)
+ track.anim_until = world.time + track.plays_out
+ track.plays_out = 0
+ return
+ var/atom/movable/thing = track.thing
+ if(QDELETED(thing) || track.unmasked)
+ return
+ var/turf/here = thing.loc
+ var/off_x = 0
+ var/off_y = 0
+ if(!isturf(here))
+ visible = FALSE
+ if(visible)
+ off_x = frames[at + SANDY_FRAME_X] - here.x
+ off_y = frames[at + SANDY_FRAME_Y] - here.y
+ if(frames[at + SANDY_FRAME_Z] != here.z || abs(off_x) > SANDY_REPLAY_REACH || abs(off_y) > SANDY_REPLAY_REACH)
+ visible = FALSE
+ if(!visible) // not there yet at this frame, or not anywhere it can be drawn
+ animate(thing, time = 0, flags = ANIMATION_END_NOW)
+ thing.appearance = track.saved_look
+ thing.dir = track.saved_dir
+ pin(track)
+ thing.alpha = 0
+ // Game code writing its alpha or colour straight on (blood a later spray lands on) would show it until the next
+ // frame's fold(): a filter that draws nothing keeps it hidden through that. Its next look replaces the filters.
+ thing.filters += filter(type = "color", color = list(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
+ thing.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ track.expect = thing.appearance
+ return
+ thing.appearance = frames[at + SANDY_FRAME_LOOK]
+ thing.dir = frames[at + SANDY_FRAME_DIR]
+ pin(track)
+ thing.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ settle(track, thing, off_x * ICON_SIZE_X, off_y * ICON_SIZE_Y)
+ track.expect = thing.appearance
+ resume_chain(track, off_x * ICON_SIZE_X, off_y * ICON_SIZE_Y)
+
+/// Shifts `body` (just given a frame's look) by `off_x`, `off_y` pixels, and plays what is left of its tween.
+/datum/sandy_replay/proc/settle(datum/sandy_replay_track/track, atom/movable/body, off_x, off_y)
+ var/to_w = body.pixel_w + off_x
+ var/to_z = body.pixel_z + off_y
+ var/turn_left = track.turn_until - world.time
+ var/turning = turn_left > 0 && track.turn_time > 0 && track.turn_from && (body.transform ~= track.turn_to)
+ if(turning)
+ var/matrix/from = track.turn_from
+ body.transform = from.Interpolate(track.turn_to, 1 - turn_left / track.turn_time)
+ var/left = track.glide_until - world.time
+ if(left > 0 && track.glide_time > 0)
+ var/list/still = glide_at(track, left)
+ body.pixel_w = to_w + still[1]
+ body.pixel_z = to_z + still[2]
+ var/first = TRUE
+ for(var/list/leg as anything in glide_legs(track, left))
+ if(first)
+ animate(body, pixel_w = to_w + leg[1], pixel_z = to_z + leg[2], time = leg[3], flags = ANIMATION_END_NOW)
+ first = FALSE
+ else
+ animate(pixel_w = to_w + leg[1], pixel_z = to_z + leg[2], time = leg[3])
+ else
+ animate(body, pixel_w = to_w, pixel_z = to_z, time = 0, flags = ANIMATION_END_NOW)
+ if(turning)
+ animate(body, transform = track.turn_to, time = turn_left, easing = SINE_EASING, flags = ANIMATION_PARALLEL)
+
+/// The user's view follows their puppet.
+/datum/sandy_replay/proc/follow()
+ var/client/viewer = user?.client
+ if(!eye || !viewer || !user_track || user_track.cursor < 0)
+ return
+ var/list/frames = user_track.frames
+ var/at = user_track.cursor
+ var/turf/spot = frames[at + SANDY_FRAME_Z] ? locate(frames[at + SANDY_FRAME_X], frames[at + SANDY_FRAME_Y], frames[at + SANDY_FRAME_Z]) : null
+ if(!spot)
+ return
+ eye.loc = spot
+ var/left = user_track.glide_until - world.time
+ if(left > 0 && user_track.glide_time > 0)
+ var/list/still = glide_at(user_track, left)
+ viewer.pixel_x = eye_pixel_x + still[1]
+ viewer.pixel_y = eye_pixel_y + still[2]
+ var/first = TRUE
+ for(var/list/leg as anything in glide_legs(user_track, left))
+ if(first)
+ animate(viewer, pixel_x = eye_pixel_x + leg[1], pixel_y = eye_pixel_y + leg[2], time = leg[3], flags = ANIMATION_END_NOW)
+ first = FALSE
+ else
+ animate(pixel_x = eye_pixel_x + leg[1], pixel_y = eye_pixel_y + leg[2], time = leg[3])
+ else
+ animate(viewer, pixel_x = eye_pixel_x, pixel_y = eye_pixel_y, time = 0, flags = ANIMATION_END_NOW)
+
+/**
+ * A surger's puppet (the user's, or a surging NPC's) just moved on to a new frame. The place where the surge's
+ * own look and sound join the replay: `track.came_from` and `track.cursor` are the frames it went from and to
+ * (offsets in `track.frames`; came_from is below 0 on its first), so a step is the two frames standing on
+ * different turfs. Each step leaves the surge's own afterimage on the tile it left, as a surge does
+ * outside a slow-mo (cyberware_cascade_window/on_move()).
+ */
+/datum/sandy_replay/proc/surger_frame(datum/sandy_replay_track/track)
+ var/list/frames = track.frames
+ var/from = track.came_from
+ var/dest = track.cursor
+ if(from < 0 || !frames[from + SANDY_FRAME_Z] || frames[from + SANDY_FRAME_Z] != frames[dest + SANDY_FRAME_Z])
+ return
+ if(frames[from + SANDY_FRAME_X] == frames[dest + SANDY_FRAME_X] && frames[from + SANDY_FRAME_Y] == frames[dest + SANDY_FRAME_Y])
+ return
+ if(frames[dest + SANDY_FRAME_INDEX] < track.surge_from || frames[dest + SANDY_FRAME_INDEX] > track.surge_until)
+ return // a step taken before its surge came on, or after it ran out
+ var/turf/left = locate(frames[from + SANDY_FRAME_X], frames[from + SANDY_FRAME_Y], frames[from + SANDY_FRAME_Z])
+ var/turf/reached = locate(frames[dest + SANDY_FRAME_X], frames[dest + SANDY_FRAME_Y], frames[dest + SANDY_FRAME_Z])
+ if(!left || !reached || get_dist(left, reached) > SANDY_REPLAY_SURGE_GLIDE_MAX / ICON_SIZE_X)
+ return // a jump, not steps
+ // Several steps can fall between two samples: each tile it crossed gets its afterimages, as each step would. The
+ // way it really went where that was kept (a corner), a straight line where it wasn't.
+ var/list/crossed = surger_way(track, left, reached) || get_line(left, reached)
+ var/steps = length(crossed) - 1
+ // The trail is laid as the live one is (cyberware_cascade_window/on_move()), on the replay's clock: a step takes as
+ // many frames as it took in the recording, and an afterimage lives trail_length / trail_per_tile steps, so a walk at
+ // any speed drags the trail's length behind it. It is gone a frame after the replay is.
+ // The steps were taken between the last one replayed and the last one of this frame, where that was kept: counted
+ // by the frame, a steady run's pace wobbles with how many of its steps each frame happens to hold, and a leg laid
+ // in a fuller frame faded before an older one.
+ var/span = frames[dest + SANDY_FRAME_INDEX] - frames[from + SANDY_FRAME_INDEX]
+ var/stepped = LAZYACCESS(track.step_clock, "[frames[dest + SANDY_FRAME_INDEX]]")
+ if(stepped && track.trail_stepped_at && stepped > track.trail_stepped_at)
+ span = stepped - track.trail_stepped_at
+ track.trail_stepped_at = stepped || frames[dest + SANDY_FRAME_INDEX]
+ var/step_frames = span / steps
+ var/step_max = CYBERWARE_CASCADE_TRAIL_STEP_MAX * rate_at(frames[dest + SANDY_FRAME_INDEX])
+ if(step_frames > step_max) // the first step, or one after a pause: as long as a step takes him, as the live trail has it
+ var/stride_frames = track.stride * rate_at(frames[dest + SANDY_FRAME_INDEX])
+ step_frames = stride_frames > 0 ? min(stride_frames, step_max) : (track.trail_step_frames || step_max)
+ // Within SANDEVISTAN_BURST_GAP of the surge itself, the opening cue just played (ware_sandy_sound.dm).
+ if((stepped || frames[dest + SANDY_FRAME_INDEX]) - track.surge_from >= SANDEVISTAN_BURST_GAP * rate_at(frames[dest + SANDY_FRAME_INDEX]))
+ sandy_burst_cue(track, left)
+ track.trail_step_frames = step_frames
+ var/per_tile = max(1, track.trail_per_tile)
+ var/life_frames = step_frames * (max(1, track.trail_length) / per_tile + 1)
+ var/frames_left = max(total + 2 - frames[dest + SANDY_FRAME_INDEX], 1)
+ for(var/k in 1 to steps)
+ var/turf/step_from = crossed[k]
+ // As the live trail: one on the tile left, the rest back along the step before, never ahead of the puppet
+ var/turf/before = k > 1 ? crossed[k - 1] : track.trail_prev
+ if(before && (before.z != step_from.z || get_dist(before, step_from) != 1))
+ before = null
+ // Several tiles between two frames: the puppet is still gliding over them, and a copy laid before the tick after he
+ // leaves its tile stands ahead of him. It waits to that tick, and starts at the age and life it has left by then.
+ var/wait = track.glide_until > world.time ? (track.glide_until - world.time) * (k - 1) / steps : 0
+ var/ticks = wait > 0 ? max(ROUND_UP(wait / world.tick_lag - 0.001), 1) : 0
+ var/delay = ticks * world.tick_lag
+ // Each copy faces the way he was going as he left its tile: only the last step's facing is in the frame
+ var/facing = steps > 1 ? get_dir(step_from, crossed[k + 1]) : frames[dest + SANDY_FRAME_DIR]
+ for(var/i in 0 to (before ? per_tile - 1 : 0))
+ var/fraction = i / per_tile
+ var/left_frames = life_frames - (steps - k + 1 + fraction) * step_frames - ticks // left when it is laid
+ if(left_frames <= 0)
+ continue
+ var/life = clamp(left_frames + ticks, 1, frames_left) * world.tick_lag
+ var/shift_x = before ? round((before.x - step_from.x) * fraction * ICON_SIZE_X) : 0
+ var/shift_y = before ? round((before.y - step_from.y) * fraction * ICON_SIZE_Y) : 0
+ var/age_time = left_frames * world.tick_lag
+ if(delay)
+ addtimer(CALLBACK(src, PROC_REF(lay_copy), step_from, frames[dest + SANDY_FRAME_LOOK], facing, 1 - left_frames / life_frames, track.trail_alpha * left_frames / life_frames, life > delay ? life - delay : world.tick_lag, shift_x, shift_y, age_time), delay, TIMER_DELETE_ME)
+ else
+ lay_copy(step_from, frames[dest + SANDY_FRAME_LOOK], facing, 1 - left_frames / life_frames, track.trail_alpha * left_frames / life_frames, life, shift_x, shift_y, age_time)
+ afterimages++
+ track.trail_prev = crossed[steps]
+
+/// One afterimage of a surger's replayed trail on `spot` (surger_frame()). Every copy is laid the one way: one that
+/// waited inside its own animation for the puppet to pass came out translucent and fading where the rest stay solid
+/// and change colour, and a trail's newer leg read as fading before its older one.
+/datum/sandy_replay/proc/lay_copy(turf/spot, look, facing, age, start_alpha, life, shift_x, shift_y, age_time)
+ if(finished || QDELETED(spot))
+ return
+ trail_copies += new /obj/effect/temp_visual/decoy/fading/cascade/replay(spot, look, facing, age, start_alpha, life, shift_x, shift_y, age_time)
+
+/// The tiles a surger crossed from `left` to `reached` (both included) as it stepped them in the recording, or null
+/// when they weren't kept or don't join the two up a step at a time (it was moved by something other than walking).
+/datum/sandy_replay/proc/kept_way(datum/sandy_replay_track/track, turf/left, turf/reached)
+ var/list/kept = LAZYACCESS(track.ways, "[track.frames[track.cursor + SANDY_FRAME_INDEX]]")
+ if(!kept)
+ return null
+ var/list/way = list(left)
+ var/turf/last = left
+ for(var/i in 1 to length(kept) step 2)
+ var/turf/next = locate(kept[i], kept[i + 1], left.z)
+ if(!next || get_dist(last, next) != 1)
+ return null
+ way += next
+ last = next
+ return last == reached ? way : null
+
+/// kept_way() for the trail, counted (ways_followed).
+/datum/sandy_replay/proc/surger_way(datum/sandy_replay_track/track, turf/left, turf/reached)
+ . = kept_way(track, left, reached)
+ if(.)
+ ways_followed++
+
+/// A surger's replayed self bursts off from `from` after a pause: its viewers hear the snap anyone near heard
+/// (ware_sandy_sound.dm), at most every SANDEVISTAN_BURST_GAP as the replay plays (the outside view's time) and a few
+/// times a replay.
+/datum/sandy_replay/proc/sandy_burst_cue(datum/sandy_replay_track/track, turf/from)
+ if(burst_cues >= SANDY_REPLAY_BURST_CUES_MAX || (track.burst_cue_at && world.time - track.burst_cue_at < SANDEVISTAN_BURST_GAP))
+ return
+ burst_cues++
+ track.burst_cue_at = world.time
+ var/frequency = rand(100 - SANDEVISTAN_EXTERNAL_SPREAD, 100 + SANDEVISTAN_EXTERNAL_SPREAD) / 100
+ play_to_viewers(from, SANDEVISTAN_EXTERNAL_SOUND, SANDEVISTAN_EXTERNAL_VOLUME, TRUE, 0, SOUND_FALLOFF_EXPONENT, frequency, TRUE, TRUE, SOUND_DEFAULT_FALLOFF_DISTANCE, TRUE)
+
+/// Plays the recorded sounds due by `frame`.
+/datum/sandy_replay/proc/play_sounds(frame)
+ while(sound_at <= length(sounds))
+ var/list/heard = sounds[sound_at]
+ if(heard[1] > frame)
+ return
+ sound_at++
+ var/turf/source = heard[2]
+ if(QDELETED(source))
+ continue
+ var/key = "[heard[3]]"
+ if(world.time - (sound_started[key] || -INFINITY) < SANDY_REPLAY_SOUND_GAP)
+ continue // the same sound just started: one is heard
+ sound_started[key] = world.time
+ var/volume = heard[4] * SANDY_REPLAY_SOUND_VOLUME
+ if(volume < SOUND_AUDIBLE_VOLUME_MIN)
+ continue
+ play_to_viewers(source, heard[3], volume, heard[5], heard[6], heard[7], heard[8], heard[9], heard[10], heard[11], heard[12], heard[13])
+
+/**
+ * Who hears the replay, to the turf each hears it from: the user from where their view is (the replayed self it
+ * follows, not the real body standing where the fight ended), every other member of a shared slow-mo from its own
+ * view, and everyone else the replay holds from where they stand (their view is their own). Nobody else hears it.
+ */
+/datum/sandy_replay/proc/sound_viewers()
+ . = list()
+ var/turf/user_view = get_turf(eye || user)
+ if(eye && user_track && user_track.cursor < 0) // the view hasn't been taken to the first frame yet: it's going there
+ user_view = locate(user_track.frames[SANDY_FRAME_X], user_track.frames[SANDY_FRAME_Y], user_track.frames[SANDY_FRAME_Z]) || user_view
+ if(user_view)
+ .[user] = user_view
+ var/datum/sandy_session/session = sandy_session_of_replay(src)
+ for(var/mob/living/member as anything in sandy_session_others(src, FALSE))
+ var/datum/sandy_session_view/view = session?.views[member]
+ var/turf/member_view = get_turf(view?.eye || member)
+ if(member_view)
+ .[member] = member_view
+ for(var/mob/living/body as anything in locked)
+ if(.[body] || QDELETED(body))
+ continue
+ var/turf/there = get_turf(body)
+ if(there)
+ .[body] = there
+
+/// Plays a sound on `source` to each of sound_viewers(), placed and faded as from where that viewer is watching.
+/// The arguments from `soundin` on are playsound()'s. Returns who it went to.
+/datum/sandy_replay/proc/play_to_viewers(turf/source, soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference)
+ . = list()
+ if(vary && !frequency)
+ frequency = get_rand_frequency() // the same pitch for everyone, as playsound() does
+ var/list/viewers = sound_viewers()
+ for(var/mob/listener as anything in viewers)
+ var/sound/heard = sandy_replay_sound_for(listener, viewers[listener], source, soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference)
+ if(!heard)
+ continue
+#ifdef UNIT_TESTS
+ GLOB.sandy_replay_heard += list(list(listener, heard))
+#endif
+ if(listener.client && listener.can_hear())
+ SEND_SOUND(listener, heard)
+ . += listener
+
+/**
+ * The sound `listener` hears of `soundin` on `source` when listening from `hear_from`, or null if it doesn't reach
+ * them: playsound()'s reach and playsound_local()'s fade, pan, air and room, measured from `hear_from` in place of the
+ * body. Never slowed: the slow-mo is over.
+ */
+/proc/sandy_replay_sound_for(mob/listener, turf/hear_from, turf/source, soundin, vol, vary, extrarange, falloff_exponent = SOUND_FALLOFF_EXPONENT, frequency, pressure_affected = TRUE, ignore_walls = TRUE, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, use_reverb = TRUE, volume_preference)
+ if(!hear_from || !source || hear_from.z != source.z || vol < SOUND_AUDIBLE_VOLUME_MIN)
+ return null
+ var/max_distance = SOUND_RANGE + extrarange
+ var/distance = get_dist(hear_from, source)
+ if(distance > CALCULATE_MAX_SOUND_AUDIBLE_DISTANCE(vol, max_distance, falloff_distance, falloff_exponent))
+ return null
+ if(!ignore_walls && !(hear_from in view(distance, source)))
+ return null
+ var/sound/heard = sound(get_sfx(soundin))
+ heard.wait = 0
+ heard.channel = SSsounds.random_available_channel()
+ heard.volume = vol
+ if(vary)
+ heard.frequency = frequency || get_rand_frequency()
+ heard.volume -= CALCULATE_SOUND_VOLUME(vol, distance, max_distance, falloff_distance, falloff_exponent)
+ if(pressure_affected)
+ var/pressure_factor = 0
+ var/datum/gas_mixture/hearer_env = hear_from.return_air_readonly()
+ var/datum/gas_mixture/source_env = source.return_air_readonly()
+ if(hearer_env && source_env)
+ var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure())
+ pressure_factor = pressure < ONE_ATMOSPHERE ? max((pressure - SOUND_MINIMUM_PRESSURE) / (ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0) : 1
+ if(distance <= 1)
+ pressure_factor = max(pressure_factor, 0.15)
+ heard.volume *= pressure_factor
+ if(heard.volume < SOUND_AUDIBLE_VOLUME_MIN)
+ return null
+ heard.x = source.x - hear_from.x
+ heard.z = source.y - hear_from.y
+ heard.y = 0
+ heard.falloff = max_distance || 1
+ if(listener.sound_environment_override != SOUND_ENVIRONMENT_NONE)
+ heard.environment = listener.sound_environment_override
+ else
+ var/area/room = get_area(hear_from)
+ heard.environment = room.sound_environment
+ if(!use_reverb || heard.environment == SOUND_ENVIRONMENT_NONE)
+ heard.echo ||= new /list(18)
+ heard.echo[3] = -10000
+ heard.echo[4] = -10000
+ if(ispath(volume_preference) && listener.client?.prefs)
+ heard.volume *= listener.client.prefs.read_preference(volume_preference) / 100
+ if(heard.volume < SOUND_AUDIBLE_VOLUME_MIN)
+ return null
+ return heard
+
+/// One afterimage of a surger's trail in the replay: a recorded look, coloured by age like the live trail.
+/obj/effect/temp_visual/decoy/fading/cascade/replay
+
+/obj/effect/temp_visual/decoy/fading/cascade/replay/Initialize(mapload, look, facing, age = 0, start_alpha = CYBERWARE_CASCADE_AFTERIMAGE_ALPHA, life, shift_x = 0, shift_y = 0, age_time)
+ if(life)
+ duration = life // before the parent's timer and fade read it
+ . = ..(mapload, null, age, start_alpha)
+ // The whole look goes on in one assignment, then the fade starts on it. Set piece by piece under the parent's fade,
+ // the client tweened the hue in from full colour: the first afterimage read as a copy of the user beside them.
+ var/mutable_appearance/copy = new(look || src)
+ copy.name = ""
+ copy.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ copy.alpha = start_alpha
+ copy.color = cyberware_cascade_tint_at(age)
+ copy.pixel_w += shift_x // along the step, toward the tile reached
+ copy.pixel_z += shift_y
+ copy.appearance_flags |= KEEP_TOGETHER // a recorded look need not draw as one piece; the colour must reach all of it
+ // Drawn on the floor, under everyone standing: a trail lies behind its surger, never over them (on the game plane a
+ // copy a row nearer the camera would sort over the surger).
+ SET_PLANE_EXPLICIT(copy, FLOOR_PLANE, src)
+ copy.layer = CLEANABLE_FLOOR_OBJECT_LAYER
+ animate(src)
+ appearance = copy.appearance
+ dir = facing
+ opacity = FALSE
+ animate(src, alpha = 0, time = duration)
+ age_colours(age, age_time || duration)
+
+/// The playback timer: one frame a tick.
+/datum/sandy_replay/proc/play_frame()
+ if(finished || state != SANDY_REPLAY_PLAYING)
+ return
+ try
+ if(QDELETED(user) || cyberware_time_stop_witnessed(user))
+ finish()
+ return
+ var/frame = round((world.time - play_started) / world.tick_lag)
+ if(frame > total + 1 && !land()) // the last frame's tween has played out, and nothing is left in the air
+ finish()
+ return
+ frame = min(frame, total)
+ hold_nearby()
+ sandy_replay_clocks_tick() // the held stay paused
+ if(landing_stage < 2) // what gore flying on for real leaves behind it is seen as it is left
+ hide_unborn()
+ clear_view()
+ play_sounds(frame)
+ play_lights(frame)
+ for(var/datum/sandy_replay_track/track as anything in puppets)
+ var/atom/movable/thing = track.thing
+ if(QDELETED(thing))
+ continue
+ var/redraw = FALSE
+ if(track.landing)
+ continue
+ if(track.unmasked) // a wrapped proc never came back
+ track.unmasked = FALSE
+ keep_real(track)
+ redraw = TRUE
+ else if(thing.appearance != track.expect)
+ fold(track)
+ redraw = TRUE
+ var/moved_on = advance(track, frame)
+ if(moved_on || redraw)
+ show(track)
+ if(track == user_track)
+ follow()
+ if(moved_on && track.surger)
+ surger_frame(track)
+ if(track.events)
+ play_events(track, frame)
+ for(var/datum/sandy_replay_track/track as anything in standins.Copy())
+ // A one-shot plays out its animation. While gore lands, what was only drawn to the last frame goes.
+ if((frame >= track.last || (landing_stage && track.last <= total + 1)) && !(track.oneshot && track.anim_until > world.time))
+ QDEL_NULL(track.standin)
+ standins -= track
+ continue
+ if(advance(track, frame))
+ show(track)
+ if(track.events)
+ play_events(track, frame)
+ sandy_member_follow() // ware_sandy_timestop_shared.dm
+ catch(var/exception/error)
+ GLOB.sandy_replay_echoing = FALSE
+ finish()
+ stack_trace("Sandevistan replay frame failed: [error] ([error.file]:[error.line])")
+
+/// Signal proc for [COMSIG_MOVABLE_MOVED] on a puppet: its real tile changed, so its offset does too.
+/datum/sandy_replay/proc/on_puppet_moved(atom/movable/thing, atom/old_loc)
+ SIGNAL_HANDLER
+ if(finished)
+ return
+ if(thing == user && isturf(old_loc) && get_dist(old_loc, thing) > 2) // a shuttle, a teleport: the recorded tiles mean nothing now
+ finish()
+ return
+ var/datum/sandy_replay_track/track = GLOB.sandy_replay_masked[thing]
+ if(!track || track.unmasked)
+ return
+ show(track)
+ // show() moved its offset to the new tile at once, while a client glides a one-tile move from the old tile: the
+ // puppet would slide a tile off its recorded spot and back. It jumps instead, so it stays where its frame has it.
+ if(isnull(track.saved_movement))
+ track.saved_movement = thing.animate_movement
+ thing.animate_movement = NO_STEPS
+
+/// Signal proc for [COMSIG_ATOM_DIR_CHANGE] on a puppet: the game turned it for real.
+/datum/sandy_replay/proc/on_puppet_turned(atom/movable/thing, old_dir, new_dir)
+ SIGNAL_HANDLER
+ var/datum/sandy_replay_track/track = GLOB.sandy_replay_masked[thing]
+ if(track)
+ track.saved_dir = new_dir
+
+/// Signal proc for [COMSIG_MOVABLE_Z_CHANGED] on the user.
+/datum/sandy_replay/proc/on_user_z_changed(datum/source)
+ SIGNAL_HANDLER
+ finish()
+
+/**
+ * Ends the replay: every puppet gets its real look back, stand-ins go, AIs and players are let go, the view goes
+ * home and the crash lands. Safe to call at any point and any number of times; one bad thing can't stop the rest.
+ */
+/datum/sandy_replay/proc/finish()
+ if(finished)
+ return
+ finished = TRUE
+ var/was_playing = state == SANDY_REPLAY_PLAYING
+ if(state == SANDY_REPLAY_RECORDING)
+ stop_paths()
+ state = SANDY_REPLAY_DONE
+ deltimer(play_timer)
+ deltimer(watchdog)
+ deltimer(sample_timer)
+ deltimer(begin_timer)
+ play_timer = null
+ watchdog = null
+ var/list/problems
+ for(var/datum/sandy_replay_track/track as anything in puppets)
+ try
+ var/atom/movable/thing = track.thing
+ if(thing)
+ if(GLOB.sandy_replay_masked[thing] == track)
+ GLOB.sandy_replay_masked -= thing
+ UnregisterSignal(thing, list(COMSIG_MOVABLE_MOVED, COMSIG_ATOM_DIR_CHANGE))
+ if(!QDELETED(thing) && !track.unmasked)
+ hand_back(track, was_playing)
+ thing.sandy_replay_resume((was_playing && ended_at) ? world.time - ended_at : 0)
+ if(!QDELETED(thing) && !isnull(track.saved_movement))
+ thing.animate_movement = track.saved_movement // it glides its own moves again
+ track.saved_movement = null
+ track.unmasked = FALSE
+ catch(var/exception/error)
+ LAZYADD(problems, "[error] ([error.file]:[error.line])")
+ sandy_replay_masks = length(GLOB.sandy_replay_masked)
+ for(var/datum/sandy_replay_track/track as anything in standins)
+ QDEL_NULL(track.standin)
+ QDEL_LIST(trail_copies)
+ forget_lights()
+ for(var/datum/weakref/glow_ref as anything in shown_lights)
+ qdel(glow_ref.resolve()) // a light still lit goes out with the replay
+ shown_lights.Cut()
+ release_shots()
+ show_progress_bars()
+ show_pending()
+ for(var/atom/movable/thing as anything in unborn)
+ if(!QDELETED(thing))
+ thing.remove_filter(SANDY_REPLAY_UNBORN)
+ unborn.Cut()
+ for(var/atom/movable/thing as anything in rig_hidden)
+ if(!QDELETED(thing))
+ thing.invisibility = rig_hidden[thing]
+ rig_hidden.Cut()
+ for(var/mob/living/body as anything in locked)
+ try
+ unlock(body)
+ catch(var/exception/error)
+ LAZYADD(problems, "[error] ([error.file]:[error.line])")
+ locked.Cut()
+ ai_before.Cut()
+ for(var/obj/vehicle/sealed/mecha/mech as anything in mechs)
+ sandy_replay_clock_start(mech)
+ if(!QDELETED(mech))
+ mech.completely_disabled = mechs[mech]
+ mechs.Cut()
+ for(var/obj/thing as anything in held_machines)
+ sandy_replay_clock_start(thing)
+ held_machines.Cut()
+ if(!QDELETED(user))
+ UnregisterSignal(user, COMSIG_MOVABLE_Z_CHANGED)
+ if(eye)
+ var/client/viewer = user.client
+ if(viewer)
+ animate(viewer, pixel_x = eye_pixel_x, pixel_y = eye_pixel_y, time = 0, flags = ANIMATION_END_NOW)
+ if(viewer.eye == eye)
+ user.reset_perspective()
+ try
+ restore_view()
+ catch(var/exception/error)
+ LAZYADD(problems, "[error] ([error.file]:[error.line])")
+ QDEL_NULL(eye)
+ GLOB.sandy_replay_last = list("played" = was_playing, "frames" = total, "puppets" = length(puppets), "standins" = length(standins), "unhooked" = unhooked, "folded" = folded.Copy(), "unmasks" = unmasks, "afterimages" = afterimages, "ways_followed" = ways_followed, "sounds" = length(sounds), "sounds_played" = sound_at - 1, "events_played" = events_played, "chains_resumed" = chains_resumed, "event_log" = event_log.Copy())
+ if(crash && !QDELETED(user) && user.stat != DEAD && cyberware_bearer_lattice(user))
+ user.apply_status_effect(/datum/status_effect/cyberware_cascade_crash, crash[1], crash[2])
+ crash = null
+ sandy_session_replay_over(src) // a shared slow-mo's other crashes and views (ware_sandy_timestop_shared.dm)
+ if(!QDELING(src))
+ qdel(src)
+ if(problems)
+ stack_trace("Sandevistan replay restore problems: [problems.Join("; ")]")
+
+/**
+ * `src` just got its real look back after the replay. A look's vars hold where its animate()s end, so anything that
+ * was mid-tween when it became a puppet starts its tween again here from where it has got to by now. `held_for` is how
+ * long ago the recording ended: what the replay's last frame shows partway through is that much behind by now.
+ */
+/atom/movable/proc/sandy_replay_resume(held_for = 0)
+ return
+
+/// Whether the decal is in the middle of drying or spreading, which happen on the client.
+/obj/effect/decal/cleanable/blood/proc/sandy_replay_wet()
+ return (!dried && can_dry && total_dry_time && drying_time > 0) || length(hv_vis_painting) >= 2
+
+/// The colour update_blood_color() gives it right now without the slow-mo's tint: dried, or partway there while it
+/// dries (it animates from this to the dried colour). Null when that isn't a plain colour.
+/obj/effect/decal/cleanable/blood/proc/sandy_replay_colour()
+ var/base
+ for(var/priority in 1 to length(atom_colours)) // the slow-mo's tint is a filter at TEMPORARY_COLOUR_PRIORITY
+ if(priority == TEMPORARY_COLOUR_PRIORITY)
+ continue
+ var/list/entry = atom_colours[priority]
+ if(!entry)
+ continue
+ if(entry[ATOM_COLOR_TYPE_INDEX] == ATOM_COLOR_TYPE_FILTER || !istext(entry[ATOM_COLOR_VALUE_INDEX]))
+ return null
+ base = entry[ATOM_COLOR_VALUE_INDEX]
+ break
+ if(!base)
+ var/list/blood_DNA = GET_ATOM_BLOOD_DECALS(src)
+ if(!length(blood_DNA))
+ blood_DNA = GET_ATOM_BLOOD_DNA(src)
+ base = length(blood_DNA) ? get_color_from_blood_list(blood_DNA) : BLOOD_COLOR_RED
+ if(!istext(base))
+ return null
+ if(dried || drying_time <= 0)
+ return get_dried_color(base)
+ if(!total_dry_time)
+ return base
+ return BlendRGB(base, get_dried_color(base), round(1 - drying_time / total_dry_time, 0.01))
+
+/// Where its hyperviolence paint (hv_vis_paint()) has got to right now: list(transform, alpha), or null.
+/obj/effect/decal/cleanable/blood/proc/sandy_replay_paint_now()
+ var/list/keys = hv_vis_painting
+ if(length(keys) < 2)
+ return null
+ var/now = world.time
+ for(var/i in 2 to length(keys))
+ var/list/ahead = keys[i]
+ if(now >= ahead[3])
+ continue
+ var/list/behind = keys[i - 1]
+ if(now <= behind[3])
+ return list(behind[1], behind[2])
+ var/span = ahead[3] - behind[3]
+ var/progress = span > 0 ? hv_vis_eased(clamp((now - behind[3]) / span, 0, 1), ahead[4]) : 1
+ var/matrix/from = behind[1]
+ return list(from.Interpolate(ahead[1], progress), behind[2] + (ahead[2] - behind[2]) * progress)
+ return null
+
+/// Wet blood dries (and spreads) by animate(): without this it jumps to its dried look as the replay ends.
+/// update_blood_color() works out how far it has got and plays the rest (hv_vis_paint_on() for the spread).
+/// A paint still going when the recording ended (a spray growing in, a pool creeping wider) ran on unseen under the
+/// replay, whose last frame has it where it was then: it carries on from what was last shown instead of jumping ahead.
+/obj/effect/decal/cleanable/blood/sandy_replay_resume(held_for = 0)
+ if(held_for > 0)
+ sandy_replay_paint_carry(held_for)
+ if(!dried || length(hv_vis_painting))
+ update_atom_colour()
+
+/**
+ * Moves the paint's keyframes (hv_vis_painting) so it carries on now from where it was `held_for` ago, and returns how
+ * long it has left. What is left takes its own time, not the slow-mo's stretch of it: the keyframes were timed when the
+ * blood landed, for a slow-mo meant to run on, and one that a held finisher kept open ends sooner than that. Without
+ * [apply] nothing is moved.
+ */
+/obj/effect/decal/cleanable/blood/proc/sandy_replay_paint_carry(held_for, apply = TRUE)
+ var/list/keys = hv_vis_painting
+ var/count = length(keys)
+ if(count < 2)
+ return 0
+ var/then = world.time - held_for
+ var/heading = 0
+ var/list/times = list()
+ for(var/i in 1 to count)
+ var/list/key = keys[i]
+ times += key[3]
+ if(!heading && i >= 2 && then < key[3])
+ heading = i
+ if(!heading)
+ return 0
+ var/list/ahead = keys[heading]
+ var/span = times[heading] - times[heading - 1]
+ var/done = span > 0 ? clamp((then - times[heading - 1]) / span, 0, 1) : 1
+ var/own = length(ahead) >= 5 ? ahead[5] : span
+ var/reached = world.time + (1 - done) * own
+ var/back = world.time - done * own - times[heading - 1]
+ if(apply)
+ for(var/i in 1 to heading - 1)
+ var/list/key = keys[i]
+ key[3] = times[i] + back
+ ahead[3] = reached
+ for(var/i in heading + 1 to count)
+ var/list/key = keys[i]
+ reached += length(key) >= 5 ? key[5] : times[i] - times[i - 1]
+ if(apply)
+ key[3] = reached
+ return reached - world.time
+
+/// The surge window is closing on `user`: if their replay is about to play or playing, the crash waits for it.
+/// Returns TRUE if it took the crash.
+/proc/sandy_replay_defer_crash(mob/living/user, length, stamina)
+ if(sandy_session_defer_crash(user, length, stamina)) // a shared slow-mo's crashes wait for its one replay (ware_sandy_timestop_shared.dm)
+ return TRUE
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ if(!replay || replay.finished)
+ return FALSE
+ if(replay.state != SANDY_REPLAY_PENDING && replay.state != SANDY_REPLAY_PLAYING && !(replay.state == SANDY_REPLAY_RECORDING && replay.wait_started))
+ return FALSE
+ replay.crash = list(length, stamina)
+ return TRUE
+
+/**
+ * Whether `body` is in the middle of an execution or a finisher, either side of it: a #509 finisher (the Gorilla
+ * moves, the scissor, the garrote, the bosses'), a gun's execution wind-up, or a rig move (the impale, the slam, the
+ * haymaker) with the body hidden under its posed pictures.
+ */
+/proc/sandy_replay_mid_move(mob/living/body)
+ if(QDELETED(body))
+ return FALSE
+ if(body.has_status_effect(/datum/status_effect/hv_finishing) || body.has_status_effect(/datum/status_effect/hv_finisher_hold))
+ return TRUE
+ if(DOING_INTERACTION(body, DOAFTER_SOURCE_HV_EXECUTION))
+ return TRUE
+ if(body.GetComponent(/datum/component/gorilla_fold))
+ return FALSE // a broken back left drawn bent (gorilla_finisher.dm): a pose that lasts, not a move
+ return sandy_rig_hidden(body)
+
+/**
+ * Whether `body` died and its fall isn't over: a heavy blow slides a corpse a whole tile a moment after the death
+ * (hv_vis_death_hit(), hyperviolence/visuals/death_falls.dm). A death that ends the slow-mo (its user's own) comes before
+ * that slide, so the recording goes on until the body has slid, or the replay draws it where it fell and the cut moves it.
+ * A slide that never came by SANDY_REPLAY_FALL_SLACK after it was due isn't waited for.
+ */
+/proc/sandy_replay_falling(mob/living/body)
+ if(!iscarbon(body) || QDELETED(body) || body.stat != DEAD)
+ return FALSE
+ var/mob/living/carbon/corpse = body
+ if(corpse.hv_vis_slide_ends > world.time)
+ return TRUE // sliding now: waited for until it lies still
+ return corpse.hv_vis_slide_due && world.time <= corpse.hv_vis_slide_due + SANDY_REPLAY_FALL_SLACK
+
+/// Whether a finisher rig hides `body` behind its puppets.
+/proc/sandy_rig_hidden(atom/body)
+ for(var/name in SANDY_REPLAY_RIG_HIDES)
+ if(body.filter_data?[name])
+ return TRUE
+ return FALSE
+
+/// Whether an execution bar at `spot` falls inside a replay showing now (owner: no progress bar in a replay).
+/proc/sandy_replay_hides_bars_at(turf/spot)
+ for(var/user in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ if(replay.state == SANDY_REPLAY_PLAYING && !replay.finished && replay.bar_reach(spot))
+ return TRUE
+ return FALSE
+
+/**
+ * Called from playsound(): a sound played in a slow-mo is recorded for its replay. A /sound datum is a looping
+ * sound's next segment (machines, weather), which plays on live and isn't recorded. A sound played while a replay
+ * starts (its surge sound in begin()) goes to that replay's viewers from where each is watching: the list of who
+ * heard it is returned, and playsound() plays it to nobody else.
+ */
+/proc/sandy_replay_hear(turf/source, soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference)
+ if(GLOB.sandy_replay_echoing || isdatum(soundin))
+ return null
+ for(var/user in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ replay.hear(source, list(soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference), usr)
+ var/datum/sandy_replay/starting = GLOB.sandy_replay_routing
+ if(!starting || GLOB.sandy_replay_routing_time != world.time || starting.state != SANDY_REPLAY_PLAYING || starting.finished)
+ return null
+ return starting.play_to_viewers(source, soundin, vol, vary, extrarange, falloff_exponent, frequency, pressure_affected, ignore_walls, falloff_distance, use_reverb, volume_preference)
+
+#define SANDY_ANIM_UNSET "\[sandy_replay_unset]"
+/**
+ * animate(), journaled for the Sandevistan replay. The rig and finisher files call this in place of animate() through
+ * a file-local macro (`#define animate(arguments...) sandy_replay_animate(arguments)`). It takes every named argument
+ * those files use; one it doesn't know is a runtime error, so add it here before using it there.
+ */
+/proc/sandy_replay_animate(Object = SANDY_ANIM_UNSET, time = SANDY_ANIM_UNSET, loop = SANDY_ANIM_UNSET, easing = SANDY_ANIM_UNSET, flags = SANDY_ANIM_UNSET, delay = SANDY_ANIM_UNSET, tag = SANDY_ANIM_UNSET, transform = SANDY_ANIM_UNSET, pixel_x = SANDY_ANIM_UNSET, pixel_y = SANDY_ANIM_UNSET, pixel_w = SANDY_ANIM_UNSET, pixel_z = SANDY_ANIM_UNSET, alpha = SANDY_ANIM_UNSET, color = SANDY_ANIM_UNSET, layer = SANDY_ANIM_UNSET, dir = SANDY_ANIM_UNSET, icon_state = SANDY_ANIM_UNSET, x = SANDY_ANIM_UNSET, y = SANDY_ANIM_UNSET, size = SANDY_ANIM_UNSET, offset = SANDY_ANIM_UNSET, radius = SANDY_ANIM_UNSET)
+ var/static/list/names = list("time", "loop", "easing", "flags", "delay", "tag", "transform", "pixel_x", "pixel_y", "pixel_w", "pixel_z", "alpha", "color", "layer", "dir", "icon_state", "x", "y", "size", "offset", "radius")
+ var/list/values = list(time, loop, easing, flags, delay, tag, transform, pixel_x, pixel_y, pixel_w, pixel_z, alpha, color, layer, dir, icon_state, x, y, size, offset, radius)
+ var/list/step = list()
+ for(var/i in 1 to length(names))
+ var/value = values[i]
+ if(value == SANDY_ANIM_UNSET)
+ continue
+ var/name = names[i]
+ if(isnull(value))
+ // arglist() drops a named null; animate() reads these as their plain values
+ switch(name)
+ if("transform")
+ value = matrix()
+ if("color")
+ value = COLOR_WHITE
+ else
+ continue
+ step[name] = value
+ var/given = Object != SANDY_ANIM_UNSET
+ if(length(GLOB.sandy_replays))
+ for(var/user in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ replay.journal(given ? Object : null, step, (given && ismovable(Object)) ? Object : null)
+ var/list/arguments = given ? list(Object) : list()
+ for(var/name in step)
+ arguments[name] = step[name]
+ animate(arglist(arguments))
+#undef SANDY_ANIM_UNSET
+
+/// Whether `thing` is a finisher rig's posed piece of a body, or a loose picture of the move's (a blood spray, an
+/// execution's muzzle flash).
+/proc/sandy_rig_picture(atom/thing)
+ return istype(thing, /obj/effect/abstract/chrome_puppet) || istype(thing, /obj/effect/abstract/mantis_puppet) || istype(thing, /obj/effect/abstract/mantis_rig_fx) || istype(thing, /obj/effect/temp_visual/hv_muzzle_flash)
+
+/// A short picture a chrome weapon plays on a body (a Mantis swing on its bearer, a slash over someone hit): it is in
+/// nothing, only in that body's vis_contents, so no field ever sees it (cyberware_anim.dm).
+/proc/sandy_bearer_picture(atom/thing)
+ return istype(thing, /obj/effect/abstract/cyberware_anim)
+
+/// A one-shot effect was just made: every recording near it takes it now, from this frame. Called by effects whose
+/// animation isn't journaled (it is in their Initialize()), and by those a move makes after its slow-mo has ended, when no
+/// field hands new things over.
+/proc/sandy_replay_made(atom/movable/thing)
+ if(!length(GLOB.sandy_replays))
+ return
+ var/turf/where = get_turf(thing)
+ if(!where && sandy_bearer_picture(thing))
+ var/obj/effect/abstract/cyberware_anim/picture = thing
+ where = get_turf(picture.bearer)
+ if(!where)
+ return
+ for(var/user in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ if(replay.state == SANDY_REPLAY_RECORDING && replay.user && replay.near_centre(where, SANDY_REPLAY_MADE_REACH))
+ replay.notice(thing)
+
+/// tg's muzzle flash is made inside the shooter and shown in their vis_contents, where no field sees it: every
+/// recording near it takes it here, so a replayed shot has its flash (shown_on() draws it on the shooter's tile).
+/obj/effect/temp_visual/dir_setting/firing_effect/Initialize(mapload, set_dir)
+ . = ..()
+ sandy_replay_made(src)
+
+/// Blood is laid wherever a blow throws it, and a slowed room is wider than the field that hands new things to the
+/// recording (a shared slow-mo slows a whole hall): the recording takes it here as it is made. Missed, it lay on the
+/// floor from the replay's first frame, before the replay had reached the blow that spilled it.
+/obj/effect/decal/cleanable/blood/Initialize(mapload, list/datum/disease/diseases, list/blood_or_dna = get_default_blood_type())
+ . = ..()
+ if(!mapload && . != INITIALIZE_HINT_QDEL && length(GLOB.sandy_replays) && isturf(loc))
+ sandy_replay_made(src)
+
+/// tg's blood splash is put on the floor, where the field hands it over at once, and only then (Initialize()) turns the
+/// way the blow went, takes its colour and flies off fading. The recording took it bare: it is looked at again here,
+/// with its flight, or a replayed hit has no splash.
+/obj/effect/temp_visual/dir_setting/bloodsplatter/Initialize(mapload, set_dir, set_color = BLOOD_COLOR_RED)
+ . = ..()
+ if(!length(GLOB.sandy_replays))
+ return
+ for(var/user in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ replay.retake(src)
+
+/obj/effect/temp_visual/dir_setting/bloodsplatter/sandy_replay_intro()
+ if(alpha) // not flying yet: once it is, its vars hold where the flight ends
+ return null
+ return list(list("pixel_x" = 0, "pixel_y" = 0, "alpha" = initial(alpha)), list(
+ list(list("pixel_x" = pixel_x, "pixel_y" = pixel_y, "alpha" = 0, "time" = duration, "easing" = CUBIC_EASING | EASE_OUT)),
+ ))
+
+/// A one-shot the recording took as it was put down has since been set up (turned, coloured, set flying): its first
+/// frame is taken again, and its own animation goes in its track.
+/datum/sandy_replay/proc/retake(obj/effect/temp_visual/effect)
+ var/datum/sandy_replay_track/track = tracks[effect]
+ if(!track || state != SANDY_REPLAY_RECORDING)
+ return
+ track.last_raw = null
+ sample_track(track, track.first)
+ track.events = null
+ intro(track)
+
+/**
+ * What a temp visual that animates itself in Initialize() looks like before its animation, and the animation: list(the
+ * vars it starts with, as animate() arguments; list(chains: each a list of animate() argument lists, the first without
+ * the object)). Null when it has none.
+ */
+/obj/effect/temp_visual/proc/sandy_replay_intro()
+ return null
+
+/obj/effect/temp_visual/circle_wave/sandy_replay_intro()
+ return list(list("transform" = matrix().Scale(0.1), "alpha" = initial(alpha)), list(
+ list(list("transform" = matrix().Scale(amount_to_scale), "time" = duration, "flags" = ANIMATION_PARALLEL)),
+ list(list("alpha" = max_alpha, "time" = duration * 0.6, "flags" = ANIMATION_PARALLEL), list("alpha" = 0, "time" = duration * 0.4)),
+ ))
+
+/obj/effect/temp_visual/cyberware_impact_cracks
+ /// The alpha it was made with, before its fade (sandy_replay_intro()). Null if no replay took it.
+ var/sandy_peak_alpha
+
+/// Called before its fade starts: the alpha it has now is the one it starts with.
+/obj/effect/temp_visual/cyberware_impact_cracks/sandy_replay_intro()
+ sandy_peak_alpha = alpha
+ return list(list("alpha" = alpha), list(list(list("alpha" = alpha, "time" = duration - 2 SECONDS), list("alpha" = 0, "time" = 2 SECONDS))))
+
+/// Its alpha var already holds the end of its fade (0): handed back as it was, the cracks would vanish as the replay
+/// ends. They are drawn as the real ones are by now instead, and fade out on their own clock.
+/obj/effect/temp_visual/cyberware_impact_cracks/sandy_replay_resume(held_for = 0)
+ var/left = timerid ? timeleft(timerid) : 0
+ if(isnull(sandy_peak_alpha) || !left)
+ return
+ if(left > 2 SECONDS)
+ alpha = sandy_peak_alpha
+ animate(src, alpha = sandy_peak_alpha, time = left - 2 SECONDS)
+ animate(alpha = 0, time = 2 SECONDS)
+ else
+ alpha = round(sandy_peak_alpha * left / (2 SECONDS))
+ animate(src, alpha = 0, time = left)
+
+/// The slow-mo's release flash isn't put on the screen of a user whose replay is starting: the cut to the replay is the
+/// change of scene (begin()).
+/atom/movable/screen/fullscreen/flash/sandy_release/should_show_to(mob/mymob)
+ if(isliving(mymob) && sandy_replay_showing(mymob))
+ return FALSE
+ return ..()
+
+/// Whether a replay is showing on (or about to show for) `user`.
+/proc/sandy_replay_showing(mob/living/user)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user] || sandy_session_replay_of(user) // or a shared slow-mo's (ware_sandy_timestop_shared.dm)
+ return !!replay && !replay.finished && (replay.state == SANDY_REPLAY_PENDING || replay.state == SANDY_REPLAY_PLAYING)
+
+// =========================================================================
+// CHANGES TO A PUPPET
+// =========================================================================
+// Overlays, update_appearance(), atom colours, filters, lying turns and deaths all change a thing's look step by
+// step from what it is now. On a puppet that would land on the recorded look and be lost, so each goes through a
+// wrapper: real look on, the change, puppet back on. With no replay running each costs one number check.
+
+/// `thing` is about to be changed: if it is a puppet it wears its real look until sandy_replay_remask(). Returns
+/// its track if this call took the puppet off.
+/proc/sandy_replay_unmask(atom/thing)
+ var/datum/sandy_replay_track/track = GLOB.sandy_replay_masked[thing]
+ if(!track || track.unmasked || !track.owner)
+ return null
+ track.owner.unmask(track)
+ return track
+
+/proc/sandy_replay_remask(datum/sandy_replay_track/track)
+ track.owner?.remask(track)
+
+/atom/add_overlay(list/add_overlays)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/atom/cut_overlay(list/remove_overlays)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/atom/cut_overlays()
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/atom/update_appearance(updates = ALL)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/atom/update_atom_colour()
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/atom/update_filters()
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/mob/living/update_transform(resize = RESIZE_DEFAULT_SIZE)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/mob/living/set_body_position(new_value)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+// tg's offsets (grabs, lying, a finisher's lean) write all four pixel offsets outright. On a puppet that would
+// overwrite the shift that draws it on its recorded tile, and fold() would carry the difference over to the real
+// body as an offset: the body left drawn tiles away from where it stands after the replay.
+/mob/living/update_offsets(animate = FALSE)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/mob/living/death(gibbed)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+/mob/living/revive(full_heal_flags = NONE, excess_healing = 0, force_grab_ghost = FALSE)
+ if(!sandy_replay_masks)
+ return ..()
+ var/datum/sandy_replay_track/track = sandy_replay_unmask(src)
+ . = ..()
+ if(track)
+ sandy_replay_remask(track)
+
+#undef SANDY_REPLAY_TRAIT
+#undef SANDY_REPLAY_OUTLINE
+#undef SANDY_REPLAY_TINT
+#undef SANDY_REPLAY_UNBORN
+#undef SANDY_REPLAY_PENDING_HIDE
+#undef SANDY_REPLAY_RECORDING
+#undef SANDY_REPLAY_PENDING
+#undef SANDY_REPLAY_PLAYING
+#undef SANDY_REPLAY_DONE
+#undef SANDY_TRACK_PUPPET
+#undef SANDY_TRACK_STANDIN
+#undef SANDY_REPLAY_REACH
+#undef SANDY_REPLAY_MAX_SHOTS
+#undef SANDY_REPLAY_ONESHOT_MIN
+#undef SANDY_REPLAY_GLIDE_MAX
+#undef SANDY_REPLAY_SURGE_GLIDE_MAX
+#undef SANDY_REPLAY_WATCHDOG
+#undef SANDY_REPLAY_TURN_TIME
+#undef SANDY_REPLAY_BURST_CUES_MAX
+#undef SANDY_REPLAY_MAX_SOUNDS
+#undef SANDY_REPLAY_MAX_OWN_SOUNDS
+#undef SANDY_REPLAY_SOUND_VOLUME
+#undef SANDY_REPLAY_SOUND_GAP
+#undef SANDY_REPLAY_HOLD_RANGE
+#undef SANDY_REPLAY_MADE_REACH
+#undef SANDY_REPLAY_LANDING_MAX
+#undef SANDY_REPLAY_LANDING_TWEENS
+#undef SANDY_REPLAY_LANDING_FRAMES
+#undef SANDY_REPLAY_ONESHOT_FRAMES
+#undef SANDY_REPLAY_PICTURE_TIME
+#undef SANDY_REPLAY_WAIT_MAX
+#undef SANDY_REPLAY_FALL_SLACK
+#undef SANDY_REPLAY_CORPSE_GLIDE_MAX
+#undef SANDY_REPLAY_RIG_HIDES
+#undef SANDY_FRAME_SIZE
+#undef SANDY_FRAME_INDEX
+#undef SANDY_FRAME_LOOK
+#undef SANDY_FRAME_X
+#undef SANDY_FRAME_Y
+#undef SANDY_FRAME_Z
+#undef SANDY_FRAME_DIR
diff --git a/voidcrew/modules/cyberware/ware_sandy_senses.dm b/voidcrew/modules/cyberware/ware_sandy_senses.dm
new file mode 100644
index 00000000000..0c2cc49b8f8
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_senses.dm
@@ -0,0 +1,299 @@
+/**
+ * # What the Sandevistan user sees and hears of the slowed world
+ *
+ * Only the user's own client changes; nobody else's view or speakers do.
+ *
+ * Sound: a sound from a tile inside the field reaches the user pitched down and slowed by the field's scale
+ * (the `frequency` of the sound datum, set in playsound_local). The user's own sounds stay normal: anything
+ * from their own tile, and anything their own action set off (`usr` is the user: their gun, their swings,
+ * their callbacks). The weather and ship-hum loops already playing on the user's channels are slowed in place with SOUND_UPDATE, and the loop's next segments go out
+ * slowed too.
+ *
+ * Weather: area overlays are shared by everyone on a planet, so they are left alone. Each weathered area in
+ * the user's view gets one override image, shown to the user's client only: a copy of the area's appearance
+ * with every weather overlay swapped for a pre-baked slowed copy from
+ * sandy_weather.dmi. There is no particle weather to slow.
+ */
+
+#define SANDY_WEATHER_ICON 'voidcrew/modules/cyberware/icons/sandy_weather.dmi'
+/// Tiles past the edge of the user's view that still get slowed weather, so a step never shows a fast edge.
+#define SANDY_WEATHER_VIEW_MARGIN 1
+
+/// The field `listener` is the user of, if any.
+/proc/cyberware_field_of_user(mob/listener)
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.host == listener)
+ return field
+
+/**
+ * How fast `listener` hears a sound from `source`: 1 normally, the field's pace for a sound from inside the
+ * user's field. `actor` is whoever set the sound off (`usr`).
+ */
+/proc/cyberware_heard_speed(mob/listener, turf/source, mob/actor)
+ if(!isturf(source) || actor == listener)
+ return 1
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_field_of_user(listener)
+ if(!field)
+ return 1
+ var/turf/here = get_turf(listener)
+ if(!here || source == here || source.z != here.z || get_dist(source, here) > field.current_range)
+ return 1
+ return field.time_scale
+
+/// Slows `heard` for `listener` if it comes from the slowed world. Called from playsound_local.
+/proc/cyberware_dilate_heard(mob/listener, turf/source, sound/heard, mob/actor)
+ var/speed = cyberware_heard_speed(listener, source, actor)
+ if(speed == 1)
+ return
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_field_of_user(listener)
+ field?.senses?.note_one_shot(heard)
+ heard.frequency = cyberware_scaled_frequency(heard.frequency, speed)
+
+/// `frequency` (0 for as-is, a multiplier within -100..100, or a rate in Hz) played `speed` times as fast.
+/proc/cyberware_scaled_frequency(frequency, speed)
+ if(!frequency)
+ frequency = 1
+ return frequency * speed
+
+// ----- looping sounds sent straight to a mob (weather) -----
+
+/datum/looping_sound
+ /// The last file this loop sent straight to its mob, to slow it in place.
+ var/sandy_last_file
+ /// The volume it went at.
+ var/sandy_last_volume
+ /// The channel it went on (ash storm loops take a random one).
+ var/sandy_last_channel
+
+/// The direct branch of the base play(), done here so the channel a loop took is known and the sound can
+/// go out slowed to a dilation user.
+/datum/looping_sound/play(soundfile, volume_override)
+ if(!direct)
+ return ..()
+ var/sound/sound_to_play = sound(soundfile)
+ sound_to_play.channel = sound_channel || SSsounds.random_available_channel()
+ sound_to_play.volume = volume_override || volume //Use volume as fallback if theres no override
+ sandy_last_file = soundfile
+ sandy_last_volume = sound_to_play.volume
+ sandy_last_channel = sound_to_play.channel
+ if(length(GLOB.cyberware_time_fields) && ismob(parent))
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_field_of_user(parent)
+ if(field?.senses)
+ sound_to_play.frequency = field.senses.loop_speed
+ SEND_SOUND(parent, sound_to_play)
+
+// =========================================================================
+// THE USER'S SENSES
+// =========================================================================
+
+/// Lives with a dilation field and keeps its user's weather and sound loops in step with the field's pace.
+/datum/sandy_senses
+ /// The field whose pace this follows.
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field
+ /// The user.
+ var/mob/living/user
+ /// The client the images are shown to.
+ var/client/viewer
+ /// Weathered areas in view, to the override image shown for each.
+ var/list/area_images = list()
+ /// Areas, to what their image was built from, to rebuild it only when that changes.
+ var/list/area_keys = list()
+ /// How fast the user's loops play now.
+ var/loop_speed = 1
+ /// Channels of world sounds sent slowed and maybe still playing, to an unslowed copy of each, to retune them.
+ var/list/one_shots = list()
+ /// The same channels, to when each went out.
+ var/list/one_shot_times = list()
+
+/datum/sandy_senses/New(datum/proximity_monitor/advanced/timestop/sandevistan/field)
+ src.field = field
+ user = field.host
+ RegisterSignal(user, COMSIG_MOB_LOGOUT, PROC_REF(on_logout))
+ update()
+
+/datum/sandy_senses/Destroy()
+ if(user)
+ UnregisterSignal(user, COMSIG_MOB_LOGOUT)
+ set_loops(1)
+ clear_images()
+ field = null
+ user = null
+ return ..()
+
+/// The field started: bring the loops and the weather in line with its pace.
+/datum/sandy_senses/proc/update()
+ set_loops(field.time_scale)
+ refresh_weather()
+
+/// Signal proc for [COMSIG_MOB_LOGOUT]: the client keeps its images when it leaves, so take them back.
+/datum/sandy_senses/proc/on_logout(datum/source)
+ SIGNAL_HANDLER
+ clear_images()
+
+// ----- sound loops -----
+
+/// Plays the user's weather and ship-hum loops at `speed` times normal, in place.
+/datum/sandy_senses/proc/set_loops(speed)
+ if(loop_speed == speed)
+ return
+ loop_speed = speed
+ if(!user.client)
+ return
+ retune_one_shots(speed)
+ for(var/datum/component/area_sound_manager/manager as anything in user.GetComponents(/datum/component/area_sound_manager))
+ var/datum/looping_sound/loop = manager.our_loop
+ if(!loop?.direct || !loop.sandy_last_channel || !loop.sandy_last_file)
+ continue
+ update_channel(loop.sandy_last_file, loop.sandy_last_channel, loop.sandy_last_volume, speed)
+ var/buzz = user.client.current_ambient_sound
+ var/area/here = get_area(user)
+ if(buzz && here?.ambient_buzz == buzz)
+ var/buzz_pref = user.client.prefs.read_preference(/datum/preference/numeric/volume/sound_ship_ambience_volume)
+ update_channel(buzz, CHANNEL_BUZZ, here.ambient_buzz_vol * (buzz_pref / 100), speed, TRUE)
+
+/// Notes a world sound about to go out slowed (`heard` still unslowed), to speed it back up later.
+/datum/sandy_senses/proc/note_one_shot(sound/heard)
+ if(!heard.channel || heard.repeat)
+ return
+ var/sound/copy = sound(heard.file, 0, 0, heard.channel, heard.volume)
+ copy.frequency = heard.frequency
+ copy.x = heard.x
+ copy.y = heard.y
+ copy.z = heard.z
+ copy.falloff = heard.falloff
+ copy.environment = heard.environment
+ copy.echo = heard.echo
+ one_shots["[heard.channel]"] = copy
+ one_shot_times["[heard.channel]"] = world.time
+
+/// World sounds still playing from earlier in the effect take the new pace: full speed when it ends.
+/datum/sandy_senses/proc/retune_one_shots(speed)
+ for(var/channel in one_shots.Copy())
+ if(world.time - one_shot_times[channel] > 15 SECONDS) // long finished
+ one_shots -= channel
+ one_shot_times -= channel
+ continue
+ var/sound/copy = one_shots[channel]
+ var/sound/update = sound(copy.file, 0, 0, copy.channel, copy.volume)
+ update.frequency = cyberware_scaled_frequency(copy.frequency, speed) // never 0: an update with 0 keeps the old pace
+ update.x = copy.x
+ update.y = copy.y
+ update.z = copy.z
+ update.falloff = copy.falloff
+ update.environment = copy.environment
+ update.echo = copy.echo
+ update.status = SOUND_UPDATE
+ SEND_SOUND(user, update)
+ if(speed == 1)
+ one_shots.Cut()
+ one_shot_times.Cut()
+
+/// Changes the pace and volume of what is playing on `channel` for the user, without restarting it.
+/datum/sandy_senses/proc/update_channel(file, channel, volume, speed, repeat = FALSE)
+ var/sound/update = sound(file, repeat, 0, channel, volume)
+ update.frequency = speed
+ update.status = SOUND_UPDATE
+ SEND_SOUND(user, update)
+
+// ----- weather -----
+
+/// Shows slowed weather over every weathered area in the user's view, and drops images for the rest.
+/datum/sandy_senses/proc/refresh_weather(force = FALSE)
+ var/client/now_viewer = user.client
+ if(viewer && viewer != now_viewer)
+ clear_images()
+ viewer = now_viewer
+ if(!viewer && !force)
+ return
+ var/tag = cyberware_weather_tag(field.time_scale)
+ var/list/wanted = list()
+ var/turf/centre = get_turf(user)
+ if(centre)
+ var/list/weathers = list()
+ for(var/datum/weather/weather as anything in SSweather.processing)
+ if(weather.stage != END_STAGE && length(weather.overlay_cache) && (centre.z in weather.impacted_z_levels))
+ weathers += weather
+ if(length(weathers))
+ var/list/size = getviewsize(viewer?.view || world.view)
+ var/reach_x = round(size[1] / 2) + SANDY_WEATHER_VIEW_MARGIN
+ var/reach_y = round(size[2] / 2) + SANDY_WEATHER_VIEW_MARGIN
+ var/list/seen = list()
+ for(var/turf/spot as anything in block(max(centre.x - reach_x, 1), max(centre.y - reach_y, 1), centre.z, min(centre.x + reach_x, world.maxx), min(centre.y + reach_y, world.maxy), centre.z))
+ seen[spot.loc] = TRUE
+ for(var/area/place as anything in seen)
+ var/list/caches = list()
+ for(var/datum/weather/weather as anything in weathers)
+ if(weather.impacted_areas_lookup[place])
+ caches += list(weather.overlay_cache)
+ if(length(caches))
+ wanted[place] = caches
+ for(var/area/place as anything in area_images.Copy())
+ if(!wanted[place])
+ drop_image(place)
+ for(var/area/place as anything in wanted)
+ var/list/caches = wanted[place]
+ var/key = "[tag]|[length(place.overlays)]"
+ for(var/list/cache as anything in caches)
+ key += "|[REF(cache)]"
+ if(area_keys[place] == key)
+ continue
+ drop_image(place)
+ var/image/slowed = cyberware_slowed_weather_image(place, tag)
+ area_images[place] = slowed
+ area_keys[place] = key
+ viewer?.images += slowed
+
+/// Takes `place`'s image off the user's screen.
+/datum/sandy_senses/proc/drop_image(area/place)
+ var/image/slowed = area_images[place]
+ if(slowed)
+ viewer?.images -= slowed
+ area_images -= place
+ area_keys -= place
+
+/// Takes every image off the user's screen: the real weather shows again.
+/datum/sandy_senses/proc/clear_images()
+ if(viewer)
+ for(var/area/place as anything in area_images)
+ viewer.images -= area_images[place]
+ area_images.Cut()
+ area_keys.Cut()
+ viewer = null
+
+/// The sandy_weather.dmi suffix for a field running at `scale`: the nearest baked pace.
+/proc/cyberware_weather_tag(scale)
+ if(scale <= 0.27)
+ return "s20"
+ if(scale <= 0.42)
+ return "s35"
+ return "s50"
+
+/// An override image of `place` as it looks now, with its weather overlays swapped for slowed (`tag`) copies.
+/proc/cyberware_slowed_weather_image(area/place, tag)
+ var/static/list/baked
+ if(!baked)
+ baked = list()
+ for(var/state in icon_states(SANDY_WEATHER_ICON))
+ baked[state] = TRUE
+ var/image/slowed = image(loc = place)
+ slowed.appearance = place.appearance
+ slowed.override = TRUE
+ var/list/swapped = list()
+ for(var/overlay in slowed.overlays)
+ var/state
+ if(overlay:icon == 'icons/effects/weather_effects.dmi')
+ state = "[overlay:icon_state]_[tag]"
+ else if(overlay:icon == 'icons/effects/glow_weather.dmi')
+ state = "glow_[overlay:icon_state]_[tag]"
+ if(!state || !baked[state])
+ swapped += overlay
+ continue
+ var/mutable_appearance/copy = new(overlay)
+ copy.icon = SANDY_WEATHER_ICON
+ copy.icon_state = state
+ swapped += copy
+ slowed.overlays = swapped
+ return slowed
+
+#undef SANDY_WEATHER_ICON
+#undef SANDY_WEATHER_VIEW_MARGIN
diff --git a/voidcrew/modules/cyberware/ware_sandy_sound.dm b/voidcrew/modules/cyberware/ware_sandy_sound.dm
new file mode 100644
index 00000000000..b3014ba0d4f
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_sound.dm
@@ -0,0 +1,201 @@
+/**
+ * # What a Sandevistan sounds like
+ *
+ * The user hears his own surge come on, a loop for as long as his slow-mo runs, and the slow-mo ending. The
+ * loop climbs in pitch as the slow-mo runs toward its end (sandy_slowmo_progress()).
+ * Those go to him alone, straight to his client: never slowed by his own
+ * slow-mo (ware_sandy_senses.dm slows sounds in playsound_local) and never recorded for its replay (ware_sandy_replay.dm
+ * records playsound()), which is the outside view. An NPC surger has no client and gets none of them.
+ *
+ * Everyone else near hears a short snap from the surger's tile as he surges and as he bursts off. A crewmate slowed in
+ * his slow-mo is someone else too; in a shared slow-mo each member hears the other's snap and never his own. The
+ * replay plays the same snap to its viewers when the replayed surger bursts off after a pause
+ * (sandy_replay/proc/surger_frame()).
+ */
+
+/// The user's own cues.
+#define SANDY_SOUND_ACTIVATION_VOLUME 70
+#define SANDY_SOUND_LOOP_VOLUME 50
+#define SANDY_SOUND_DEACTIVATE_VOLUME 60
+
+#ifdef UNIT_TESTS
+/// Every Sandevistan cue sent, as list(mob, /sound), whether or not the mob has a client.
+GLOBAL_LIST_EMPTY(sandy_cues_sent)
+#endif
+
+/datum/status_effect/cyberware_cascade_window
+ /// The user's slow-mo sounds are on: the loop plays (sandy_sound_sync()).
+ var/slowmo_sounding = FALSE
+ /// The channel the loop plays on, reserved while it does.
+ var/loop_channel
+ /// The ckey whose client the loop went to, to stop it wherever that client is now.
+ var/loop_ckey
+ /// world.time of the last external cue.
+ var/last_burst_cue = 0
+ /// How far the slow-mo has run toward its end, 0 to 1, as last read (sandy_slowmo_progress()).
+ var/pitch_progress = 0
+ /// world.time pitch_progress was last read.
+ var/pitch_progress_at = 0
+ /// The timer that updates the playing loop's pitch.
+ var/pitch_timer
+
+/datum/sound_effect/sandevistan_external
+ key = SANDEVISTAN_EXTERNAL_SOUND
+ file_paths = list(
+ 'voidcrew/sound/cyberware/sandevistan_external_1.ogg',
+ 'voidcrew/sound/cyberware/sandevistan_external_2.ogg',
+ 'voidcrew/sound/cyberware/sandevistan_external_3.ogg',
+ )
+
+/// A cue as it goes out: `file` at `volume`, its pitch moved by up to `spread` hundredths.
+/proc/sandy_cue(file, volume, spread = 0, channel = 0)
+ var/sound/cue = sound(file)
+ cue.volume = volume
+ cue.channel = channel
+ cue.wait = 0
+ if(spread)
+ cue.frequency = rand(100 - spread, 100 + spread) / 100
+ return cue
+
+/// The frequency multiplier for a slow-mo `progress` (0 to 1) of the way to its end.
+/proc/sandy_pitch_for(progress)
+ progress = clamp(progress, 0, 1)
+ return 1 + (SANDEVISTAN_PITCH_END - 1) * progress * progress
+
+/// Sends `cue` to `listener` alone.
+/proc/sandy_cue_send(mob/listener, sound/cue)
+#ifdef UNIT_TESTS
+ GLOB.sandy_cues_sent += list(list(listener, cue))
+#endif
+ if(listener?.client)
+ SEND_SOUND(listener, cue)
+
+/**
+ * The snap, from `surger`'s tile, to everyone who would hear a sound there but him, placed and faded as playsound()
+ * does (sandy_replay_sound_for()). Not recorded for a replay: the replay plays its own.
+ */
+/proc/sandy_external_cue(mob/living/surger)
+ var/turf/source = get_turf(surger)
+ if(!source)
+ return
+ var/frequency = rand(100 - SANDEVISTAN_EXTERNAL_SPREAD, 100 + SANDEVISTAN_EXTERNAL_SPREAD) / 100
+ var/list/listeners = get_hearers_in_range(SOUND_RANGE, source, RECURSIVE_CONTENTS_CLIENT_MOBS)
+#ifdef UNIT_TESTS
+ listeners |= get_hearers_in_range(SOUND_RANGE, source) // test bodies have no clients
+#endif
+ var/datum/region = map_region_for_turf(source)
+ for(var/mob/listener in listeners)
+ if(listener == surger)
+ continue
+ var/turf/there = get_turf(listener)
+ if(!there || (region && there.z == source.z && map_region_excludes_turf(region, there)))
+ continue
+ var/sound/heard = sandy_replay_sound_for(listener, there, source, SANDEVISTAN_EXTERNAL_SOUND, SANDEVISTAN_EXTERNAL_VOLUME, TRUE, 0, SOUND_FALLOFF_EXPONENT, frequency, TRUE, TRUE, SOUND_DEFAULT_FALLOFF_DISTANCE, TRUE)
+ if(heard && (!listener.client || listener.can_hear()))
+ sandy_cue_send(listener, heard)
+
+/// The surge comes on: the user hears it start, everyone else the snap.
+/datum/status_effect/cyberware_cascade_window/proc/sandy_surge_sounds()
+ last_burst_cue = world.time
+ if(owner.ckey)
+ sandy_cue_send(owner, sandy_cue(SANDEVISTAN_ACTIVATION_SOUND, SANDY_SOUND_ACTIVATION_VOLUME))
+ sandy_external_cue(owner)
+
+/**
+ * A step, `step_time` after the last one. A forced move (thrown, pulled, carried) is never a burst. Everyone else
+ * hears the snap on the first step after standing still, and then every SANDEVISTAN_BURST_GAP while he keeps moving.
+ */
+/datum/status_effect/cyberware_cascade_window/proc/sandy_step_sounds(step_time, forced)
+ if(forced)
+ return
+ if(world.time - last_burst_cue < SANDEVISTAN_BURST_GAP)
+ return
+ last_burst_cue = world.time
+ sandy_external_cue(owner)
+
+/**
+ * Starts the user's slow-mo sounds when his slow-mo has started, and ends them when it has ended. Call wherever
+ * `time_stop` is set or cleared. `off` ends them whatever, and `quiet` without the closing cue (logout, death).
+ */
+/datum/status_effect/cyberware_cascade_window/proc/sandy_sound_sync(off = FALSE, quiet = FALSE)
+ var/on = !off && time_stop && !QDELETED(owner) && owner.ckey && owner.stat != DEAD
+ if(on && !slowmo_sounding)
+ slowmo_sounding = TRUE
+ loop_ckey = owner.ckey
+ pitch_progress = 0
+ pitch_progress_at = world.time
+ RegisterSignal(owner, COMSIG_MOB_LOGOUT, PROC_REF(sandy_sound_logout))
+ loop_channel = SSsounds.reserve_sound_channel(src)
+ if(!loop_channel)
+ return // no channel to stop it on: no loop
+ var/sound/loop = sandy_cue(SANDEVISTAN_LOOP_SOUND, SANDY_SOUND_LOOP_VOLUME, channel = loop_channel)
+ loop.repeat = TRUE
+ loop.frequency = sandy_pitch_for(sandy_slowmo_progress())
+ sandy_cue_send(owner, loop)
+ pitch_timer = addtimer(CALLBACK(src, PROC_REF(sandy_pitch_update)), SANDEVISTAN_PITCH_UPDATE, TIMER_LOOP | TIMER_STOPPABLE | TIMER_DELETE_ME)
+ return
+ if(on || !slowmo_sounding)
+ return
+ slowmo_sounding = FALSE
+ deltimer(pitch_timer)
+ pitch_timer = null
+ if(!QDELETED(owner))
+ UnregisterSignal(owner, COMSIG_MOB_LOGOUT)
+ var/mob/listener = sandy_loop_listener()
+ if(loop_channel)
+ var/sound/stop = sound(null)
+ stop.channel = loop_channel
+ sandy_cue_send(listener, stop)
+ SSsounds.free_sound_channel(loop_channel)
+ loop_channel = null
+ loop_ckey = null
+ if(!quiet && !QDELETED(owner) && listener == owner && owner.stat != DEAD)
+ sandy_cue_send(owner, sandy_cue(SANDEVISTAN_DEACTIVATE_SOUND, SANDY_SOUND_DEACTIVATE_VOLUME))
+
+/// Whoever has the client the loop went to, wherever it is now.
+/datum/status_effect/cyberware_cascade_window/proc/sandy_loop_listener()
+ var/client/heard_by = GLOB.directory[loop_ckey]
+ . = heard_by?.mob
+#ifdef UNIT_TESTS
+ . ||= owner // test bodies have keys but no clients
+#endif
+
+/**
+ * How far the slow-mo has run toward its end, 0 at its start and 1 at its end, read against its end as it stands now
+ * (the field's ends_at: a hold or a shared slow-mo can move it later). It never goes down: when the end moves, what is
+ * left climbs from where it stood to 1 at the new end.
+ */
+/datum/status_effect/cyberware_cascade_window/proc/sandy_slowmo_progress()
+ var/ends = natural_end
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = time_stop?.chronofield
+ if(field && field.ends_at != INFINITY)
+ ends = field.ends_at
+ var/now = world.time
+ if(now <= pitch_progress_at)
+ return pitch_progress
+ if(ends <= now)
+ pitch_progress = 1
+ else
+ pitch_progress = min(1, pitch_progress + (1 - pitch_progress) * (now - pitch_progress_at) / (ends - pitch_progress_at))
+ pitch_progress_at = now
+ return pitch_progress
+
+/// Every SANDEVISTAN_PITCH_UPDATE while the loop plays: its pitch follows the slow-mo toward its end, without restarting.
+/datum/status_effect/cyberware_cascade_window/proc/sandy_pitch_update()
+ if(!slowmo_sounding || !loop_channel)
+ deltimer(pitch_timer)
+ pitch_timer = null
+ return
+ var/sound/update = sound(SANDEVISTAN_LOOP_SOUND, TRUE, 0, loop_channel, SANDY_SOUND_LOOP_VOLUME)
+ update.frequency = sandy_pitch_for(sandy_slowmo_progress())
+ update.status = SOUND_UPDATE
+ sandy_cue_send(sandy_loop_listener(), update)
+
+/// Signal proc for [COMSIG_MOB_LOGOUT]: the loop stops with him, wherever his client goes.
+/datum/status_effect/cyberware_cascade_window/proc/sandy_sound_logout(datum/source)
+ SIGNAL_HANDLER
+ sandy_sound_sync(off = TRUE, quiet = TRUE)
+
+#undef SANDY_SOUND_ACTIVATION_VOLUME
+#undef SANDY_SOUND_LOOP_VOLUME
+#undef SANDY_SOUND_DEACTIVATE_VOLUME
diff --git a/voidcrew/modules/cyberware/ware_sandy_timestop.dm b/voidcrew/modules/cyberware/ware_sandy_timestop.dm
new file mode 100644
index 00000000000..e9fac613bcf
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_timestop.dm
@@ -0,0 +1,1878 @@
+/**
+ * # The Cascade line's time dilation
+ *
+ * When a Cascade-line surge (ware_legend.dm, ware_line_sandy.dm) opens and no other player is within
+ * SANDY_STOP_WITNESS_RANGE tiles, the world around the user runs in slow motion for the whole window:
+ *
+ * model window world runs at
+ * street 6 s 50%
+ * service 7 s 35%
+ * Cascade T4 8 s 20%
+ *
+ * Pressing the surge again ends the window early, slow-mo and all, and the crash follows as usual. With another
+ * player near (the user's own crewmates don't count: they slow like an NPC), the surge is the plain one; if one comes in range mid-surge, the slow-mo ends there and the surge
+ * carries on without it. Only a player's surge does this (the user needs a ckey): an NPC criminal's lattice never does.
+ *
+ * Built on tg's time stop field (code/datums/proximity_monitor/fields/timestop.dm), hosted on the user so
+ * it follows them. Anything it touches stays slowed until the effect ends, even once the user walks off. The
+ * field re-checks for players every tick and ends at once if one comes in.
+ *
+ * No shortcuts on people. A slowed mob moves under a movespeed modifier, and every tick the field pushes its
+ * timing deadlines back by the time it lost (next_move, ability cooldowns, AI behaviour cooldowns and the
+ * blackboard deadlines listed in dilated_blackboard_keys(), ranged cooldowns). Slowed bodies take damage,
+ * wounds and bleeding through tg as normal.
+ *
+ * Everything else in the field runs on the same slowed clock, through a few helpers below:
+ * - cyberware_dilated_time() and cyberware_dilated_steps() turn a length of local time into real time, exact
+ * through the slow-mo and its end. Hyperviolence gore uses them (flinches, death throes, blood paint, flying
+ * gibs), and so do a mech's weapon and melee cooldowns and a gun's fire delay.
+ * - cyberware_time_lost() stretches do_after for a slowed body (VOIDCREW EDIT in do_after).
+ * - Burst shots wait on a burst clock the field pushes back (cyberware_burst_wait()), so a burst queued before
+ * the slow-mo slows with it: guns (gun.dm) and basic mob ranged attacks (ranged_attacks.dm).
+ * - The field pushes back mech move cooldowns, turret fire cooldowns and lit grenade fuses (_grenade.dm).
+ * Things in hand stay held until the effect ends; gore and blood that merely stand in the field are slowed
+ * while they are within its range. The user and anything the user carries are never slowed.
+ * Nothing is ever frozen: the field never sends tg's time stop signals, so a supermatter keeps running.
+ *
+ * Bosses (a finisher user, or a boss-rank human NPC) are slowed for SANDY_STOP_BOSS_HOLD at most.
+ *
+ * Each surge model speeds its bearer up by a time multiplier (the lattice's time_multiplier): street 2x, service
+ * about 2.86x, Cascade 5x. A mob on its own surge (a bounty NPC's lattice) runs at its multiplier over the user's,
+ * at most SANDY_STOP_MAX_RELATIVE, for as long as both windows are open: a street NPC in a Cascade's field at 40%,
+ * an equal tier at 100% (left alone), a Cascade NPC in a street user's field at 200% (2.5x, capped). Faster than
+ * the user runs the same machinery the other way (its deadlines, cooldowns, walk and gore come sooner). A surging
+ * mob is never tinted, at any rate. If it surges while already held, the field lets it go at once, drops every
+ * slow it was carrying (surge_free()) and takes it back at its relative rate. When its window closes the field
+ * takes it at the field's own pace, unless it is dead: a corpse freed by a surge is left as it fell.
+ *
+ * The user's reflex dodge (ware_pro_combat.dm) is off while the world is slowed: the speed gap already does that
+ * job. It comes back if the slow-mo ends before the window does.
+ *
+ * Look: affected things get a grey-green tint instead of tg's inversion, and so does blood (decals, sprays,
+ * splatters), spent casings and shooter effects; a tinted decal's drying colour waits for the tint to come off. Floor
+ * items and the user keep their colour, and so do the shots, flashes and casings of the user and any surging mob.
+ * Every bullet and every throw in the field flies at the field's pace, whoever started it, and gets its speed back
+ * when let go; a body on its own time (the user, a surging mob) that is itself thrown flies at its own speed.
+ */
+
+/// Another player within this many tiles of the user means no dilation.
+#define SANDY_STOP_WITNESS_RANGE 11
+/// Radius of the field around the user (a 19x15 widescreen view is 9 tiles to each side and 7 up and down). It also
+/// takes the rest of the user's room (ware_sandy_timestop_cover.dm).
+#define SANDY_STOP_FIELD_RANGE 11
+/// How long a boss stays slowed before it shrugs the field off.
+#define SANDY_STOP_BOSS_HOLD (1 SECONDS)
+/// The fastest a surging mob runs in someone else's field, relative to normal speed.
+#define SANDY_STOP_MAX_RELATIVE 2
+/// Relative rates this close to 1 count as the same speed: the mob is left alone.
+#define SANDY_STOP_SAME_RATE 0.01
+/// How long the tint's front takes per tile past the ring's own size, out to the field's edge and the room beyond.
+#define SANDY_STOP_RING_TAIL 0.4
+/// Filter name of the user's edge glow.
+#define SANDY_STOP_OUTLINE "sandy_time_stop_outline"
+/// Fullscreen category of the release flash.
+#define SANDY_STOP_FLASH "sandy_time_stop_flash"
+/// Filter name (and KEEP_TOGETHER source) of the slow-mo's tint on bodies and items. Same as SANDY_REPLAY_TINT.
+#define SANDY_STOP_TINT "sandy_time_stop_tint"
+/// The longest a slow-mo is held past its end for its user's execution or finisher to finish inside it.
+#define SANDY_STOP_HOLD_MAX (6 SECONDS)
+/// How long the slow-mo still holds once that move is over: its last blow (a shot's flash, the flinch, the gore) lands
+/// inside the slow-mo, not in the first tick after it. SANDY_REPLAY_MOVE_TAIL in ware_sandy_replay.dm is as long.
+#define SANDY_STOP_HOLD_TAIL 5
+
+/// Every atom the dilation has hold of, to its field.
+GLOBAL_LIST_EMPTY(cyberware_time_dilated)
+
+/// How fast time runs for `thing`: 1 normally, below 1 in slow-mo, above 1 for a faster surger.
+/proc/cyberware_time_scale(atom/thing)
+ if(isnull(thing))
+ return 1
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[thing]
+ return field ? field.scale_for(thing) : 1
+
+/// Every dilation field running now.
+GLOBAL_LIST_EMPTY(cyberware_time_fields)
+/// world.time and nesting depth while an untinted shooter spawns turf effects that carry no firer ref of their own.
+GLOBAL_VAR_INIT(cyberware_untinted_fx_at, -1)
+GLOBAL_VAR_INIT(cyberware_untinted_fx_depth, 0)
+
+/// Whether an untinted shooter is spawning turf effects right now on this tick.
+/proc/cyberware_untinted_fx_active()
+ if(GLOB.cyberware_untinted_fx_at != world.time)
+ GLOB.cyberware_untinted_fx_depth = 0
+ return FALSE
+ return GLOB.cyberware_untinted_fx_depth > 0
+
+/// Unwraps a held, chambered or mounted item to whatever carries it.
+/proc/cyberware_actor_root(atom/actor)
+ while(isitem(actor) && ismovable(actor.loc))
+ actor = actor.loc
+ return actor
+
+/// Whether `actor` keeps its own colours in a running slow-mo (the user, their ride, a surging mob, a freed boss).
+/proc/cyberware_untinted_actor(atom/actor)
+ actor = cyberware_actor_root(actor)
+ if(isnull(actor) || !length(GLOB.cyberware_time_fields))
+ return FALSE
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[actor]
+ if(istype(holder))
+ return !!(holder.surging[actor] || holder.immune[actor] || holder.released[actor] || holder.own_ride(actor))
+ if(cyberware_own_surge(actor))
+ return TRUE
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.immune[actor] || field.surging[actor] || field.released[actor] || field.own_ride(actor))
+ return TRUE
+ if(ismob(actor))
+ var/mob/person = actor
+ if(person.can_block_magic(field.antimagic_flags))
+ return TRUE
+ return FALSE
+
+/// The field that tints small effects or casings made by `maker` at `where`, or null when `maker` keeps its colours.
+/proc/cyberware_maker_field(atom/maker, atom/where)
+ maker = cyberware_actor_root(maker)
+ if(!length(GLOB.cyberware_time_fields))
+ return null
+ if(maker)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[maker]
+ if(istype(holder))
+ if(holder.surging[maker] || holder.immune[maker] || holder.released[maker] || holder.own_ride(maker))
+ return null
+ return holder
+ if(cyberware_untinted_actor(maker))
+ return null
+ var/turf/spot = get_turf(where || maker)
+ if(!spot)
+ return null
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(maker && (sandy_session_shares(field, maker) || field.cover_outsider(maker)))
+ continue
+ if(field.tinted[spot])
+ return field
+ var/turf/centre = get_turf(field.host)
+ if(centre && centre.z == spot.z && get_dist(centre, spot) <= field.current_range)
+ return field
+ return null
+
+/// The field that slows a throw of `thing` starting or flying here, if any. A body on its own time (own_time()) flies
+/// at its own speed.
+/proc/cyberware_throw_field(atom/movable/thing)
+ if(isnull(thing) || !length(GLOB.cyberware_time_fields))
+ return null
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/held = GLOB.cyberware_time_dilated[thing]
+ if(istype(held))
+ return held.own_time(thing) ? null : held
+ var/turf/spot = get_turf(thing)
+ if(!spot)
+ return null
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.cover_outsider(thing) || field.own_time(thing))
+ continue
+ if(field.tinted[spot])
+ return field
+ var/turf/centre = get_turf(field.host)
+ if(centre && centre.z == spot.z && get_dist(centre, spot) <= field.current_range)
+ return field
+ return null
+
+/**
+ * The field `thing` runs slow in: the one holding it, or one it stands inside (blood, gibs, a grenade on the
+ * floor). Never for the user, anything the user carries, or a living thing the field didn't take.
+ */
+/proc/cyberware_time_field(atom/thing)
+ if(isnull(thing) || !length(GLOB.cyberware_time_fields))
+ return null
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[thing]
+ if(field)
+ return field
+ if(isliving(thing))
+ return null
+ var/turf/here = get_turf(thing)
+ if(!here)
+ return null
+ var/atom/on_turf = ismovable(thing) ? get_atom_on_turf(thing) : thing
+ for(field as anything in GLOB.cyberware_time_fields)
+ if(field.immune[thing] || field.immune[on_turf] || field.released[on_turf] || field.surging[on_turf])
+ continue
+ var/turf/centre = get_turf(field.host)
+ if(centre && centre.z == here.z && get_dist(centre, here) <= field.current_range)
+ return field
+ return null
+
+/// Whether `bearer` is slowing the world around them right now.
+/proc/cyberware_time_stopping(mob/living/bearer)
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.host == bearer)
+ return TRUE
+ return FALSE
+
+/// Whether `thing` is a mob with its own Cascade surge window open. Such a mob runs at its own speed in any field.
+/proc/cyberware_own_surge(atom/thing)
+ if(!isliving(thing))
+ return FALSE
+ var/mob/living/body = thing
+ return !!body.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/// `surger` just opened its own surge window at `multiplier`: every field lets it go and runs it at its relative
+/// rate until the window closes.
+/proc/cyberware_surge_frees(mob/living/surger, multiplier)
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.host != surger)
+ field.surge_free(surger, multiplier)
+
+/// Whether some other user's field is running `surger` at its relative rate.
+/proc/cyberware_surge_in_field(mob/living/surger)
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.surging[surger])
+ return TRUE
+ return FALSE
+
+/// A field just took or let go of `surger`: its surge's own edge goes off or back on (ware_legend.dm).
+/proc/cyberware_surge_refresh_perks(mob/living/surger)
+ if(QDELETED(surger))
+ return
+ var/datum/status_effect/cyberware_cascade_window/window = surger.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ window?.refresh_perks()
+
+/// The time multiplier of `body`'s open surge window, or 1 with none.
+/proc/cyberware_surge_multiplier(mob/living/body)
+ if(!isliving(body))
+ return 1
+ var/datum/status_effect/cyberware_cascade_window/window = body.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ return window ? window.time_multiplier : 1
+
+/// A surge's tell is about to play on `body`: let its own colours show through the field's tint while it winds up.
+/proc/cyberware_time_untint(mob/living/body)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[body]
+ field?.escape_the_negative_zone(body)
+
+/// The tell on `body` is over: if the field still holds it at its own pace, tint it again.
+/proc/cyberware_time_retint(mob/living/body)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[body]
+ if(field && !field.surging[body])
+ field.into_the_negative_zone(body)
+
+/// How long, in real time, `time` deciseconds of `thing`'s own time take from now. Exact through the slow-mo
+/// and the end of the effect, as the field stands now.
+/proc/cyberware_dilated_time(atom/thing, time)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_time_field(thing)
+ if(!field)
+ return time
+ return field.real_time_for(thing, time)
+
+/**
+ * Real-time lengths for a chain of animation steps `times` on `thing`: list(step 1, step 2, ...), or null when it
+ * isn't slowed. A looping chain just plays at the field's pace. `tag` names the animation, so a held mob that
+ * breaks free (surge_free()) can drop it.
+ */
+/proc/cyberware_dilated_steps(atom/thing, list/times, loop = 1, tag)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_time_field(thing)
+ if(!field)
+ return null
+ if(tag && field.held_mobs[thing])
+ LAZYOR(field.slowed_tags[thing], tag)
+ var/list/real = list()
+ if(loop != 1)
+ var/scale = field.scale_for(thing)
+ for(var/time in times)
+ real += time / scale
+ return real
+ var/local = 0
+ var/reached = 0
+ for(var/time in times)
+ local += time
+ var/at = field.real_time_for(thing, local)
+ real += max(at - reached, 0)
+ reached = at
+ return real
+
+/// Time `thing` lost in the last `elapsed` deciseconds: none of it outside a field. Negative for a surger running
+/// faster than normal: it gained time.
+/proc/cyberware_time_lost(atom/thing, elapsed)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[thing]
+ if(!field || elapsed <= 0)
+ return 0
+ return elapsed * (1 - field.scale_for(thing))
+
+/// Time a held `thing` has lost since the field last pushed its deadlines back.
+/proc/cyberware_time_lag(atom/thing)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[thing]
+ if(!field)
+ return 0
+ return (world.time - field.last_tick) * (1 - field.scale_for(thing))
+
+/// A burst clock's start for a burst beginning now. The field pushes it back with the shooter's deadlines.
+/proc/cyberware_burst_clock(atom/shooter)
+ return world.time - cyberware_time_lag(shooter)
+
+/// How much longer shot `index` (0 for the first) of a burst begun at `start`, `gap` apart, has to wait.
+/proc/cyberware_burst_wait(atom/shooter, start, gap, index)
+ if(!GLOB.cyberware_time_dilated[shooter])
+ return max(start + gap * index - world.time, 0)
+ var/due = start + cyberware_time_lag(shooter) + gap * index
+ return due - world.time >= world.tick_lag ? due - world.time : 0
+
+/// Whether a player other than `user` is within `range` tiles: any living body with a ckey, connected or not. The user's
+/// own crewmates don't count: they are slowed with the rest of the world, like an NPC.
+/proc/cyberware_time_stop_witnessed(mob/living/user, range = SANDY_STOP_WITNESS_RANGE)
+ var/turf/here = get_turf(user)
+ if(!here)
+ return TRUE
+ var/datum/team/user_crew = cyberware_crew_team(user) // ware_pro_combat.dm
+ for(var/atom/movable/found as anything in SSspatial_grid.orthogonal_range_search(here, SPATIAL_GRID_CONTENTS_TYPE_HEARING, range))
+ if(found == user)
+ continue
+ if(isliving(found))
+ var/mob/living/body = found
+ if(body.ckey && (!user_crew || cyberware_crew_team(body) != user_crew))
+ return TRUE
+ continue
+ if(ismob(found)) // ghosts and camera eyes don't count
+ continue
+ // a locker or a mech with a player in it, or a small player picked up and carried as an item
+ for(var/mob/living/inside in found.get_all_contents())
+ if(inside != user && inside.ckey && (!user_crew || cyberware_crew_team(inside) != user_crew))
+ return TRUE
+ return FALSE
+
+/// Whether `victim` is a boss: anything with a finisher, or a boss-rank human NPC.
+/proc/cyberware_time_stop_boss(mob/living/victim)
+ if(victim.GetComponent(/datum/component/hv_finisher_user))
+ return TRUE
+ if(istype(victim, /mob/living/carbon/human/npc))
+ var/mob/living/carbon/human/npc/person = victim
+ return person.npc_rank >= HUMAN_NPC_RANK_BOSS
+ return FALSE
+
+/// The grey-green wash on dilated things.
+/proc/cyberware_time_stop_tint()
+ var/static/list/tint = list(0.26,0.28,0.27, 0.52,0.56,0.54, 0.10,0.11,0.105, 0.02,0.05,0.04)
+ return tint
+
+/// The wash over something drawn in `colour` (a sprite coloured white-to-`colour` by its `color`): the tint's rows
+/// scaled by that colour, so it reads as that colour seen through the wash.
+/proc/cyberware_time_tint_of(colour)
+ var/list/mixed = cyberware_time_stop_tint().Copy()
+ var/list/rgb = istext(colour) ? rgb2num(colour) : null
+ if(length(rgb) < 3)
+ return mixed
+ for(var/row in 0 to 2)
+ for(var/column in 1 to 3)
+ mixed[row * 3 + column] *= rgb[row + 1] / 255
+ return mixed
+
+/// Whether `thing` wears the slow-mo's tint as a colour filter. Bodies and items carry their blood as RESET_COLOR
+/// overlays (wounds, gore, bloody clothes, stains on a severed limb), which a tint in `color` never reaches; a filter
+/// covers the whole drawn atom, overlays included. It also leaves `atom_colours` alone, so a body's own temporary
+/// colour (a chem, a perk) is still there when the tint comes off.
+/proc/cyberware_time_tints_by_filter(atom/thing)
+ return isliving(thing) || isitem(thing) || sandy_rig_picture(thing) // a rig picture animates its own colour (a flash)
+
+/// Puts the slow-mo's tint on `thing`.
+/proc/cyberware_time_tint_on(atom/thing)
+ if(cyberware_time_tints_by_filter(thing))
+ // While another colour filter was animated on a tinted body (hyperviolence's hit flash), the client drew
+ // it in full colour: the flash runs through this filter instead (cyberware_time_flash()).
+ thing.remove_filter("hv_vis_flash") // a hit flash already running would show the body in full colour
+ thing.add_filter(SANDY_STOP_TINT, 20, color_matrix_filter(cyberware_time_stop_tint()))
+ ADD_KEEP_TOGETHER(thing, SANDY_STOP_TINT)
+ return
+ // A blood splash, bead, strand or hitscan beam carries its colour in `color` alone, which the tint replaces: kept as
+ // its own colour, so it gets that colour back (not white) when the tint comes off.
+ if((istype(thing, /obj/effect/temp_visual) || istype(thing, /obj/effect/ebeam) || istype(thing, /obj/effect/projectile)) && istext(thing.color) && !LAZYACCESS(thing.atom_colours, FIXED_COLOUR_PRIORITY))
+ thing.add_atom_colour(thing.color, FIXED_COLOUR_PRIORITY)
+ thing.add_atom_colour(cyberware_time_tint_for(thing), TEMPORARY_COLOUR_PRIORITY)
+ if(istype(thing, /obj/effect/decal/cleanable/blood/gibs)) // its meat is a RESET_COLOR overlay: see its update_overlays()
+ thing.update_appearance(UPDATE_OVERLAYS)
+
+/**
+ * The tint `thing` wears in `color`. The tint replaces its colour, so a sprite drawn white and coloured by its `color` (a
+ * blood splash, a bead, a gut strand, a hitscan beam: greyscale art) would show its white art through the wash, near white.
+ * A temp visual, beam or hitscan piece whose own colour is kept at FIXED_COLOUR_PRIORITY (cyberware_time_tint_on()) wears
+ * the wash over that colour instead. A blood decal works its own out in update_blood_color().
+ */
+/proc/cyberware_time_tint_for(atom/thing)
+ if(!istype(thing, /obj/effect/temp_visual) && !istype(thing, /obj/effect/ebeam) && !istype(thing, /obj/effect/projectile))
+ return cyberware_time_stop_tint()
+ var/list/own = LAZYACCESS(thing.atom_colours, FIXED_COLOUR_PRIORITY)
+ if(!own || own[ATOM_COLOR_TYPE_INDEX] == ATOM_COLOR_TYPE_FILTER || !istext(own[ATOM_COLOR_VALUE_INDEX]))
+ return cyberware_time_stop_tint()
+ return cyberware_time_tint_of(own[ATOM_COLOR_VALUE_INDEX])
+
+/// tg gave `thing` (tinted in `color`) a colour of its own over the tint: kept as its own colour, and the tint put back over it.
+/proc/cyberware_time_recolour_tinted(atom/thing)
+ if(istext(thing.color))
+ thing.add_atom_colour(thing.color, FIXED_COLOUR_PRIORITY)
+ thing.add_atom_colour(cyberware_time_tint_for(thing), TEMPORARY_COLOUR_PRIORITY)
+
+/// `first` then the slow-mo's tint, as one colour matrix (both 12-number RGB matrices).
+/proc/cyberware_time_tint_after(list/first)
+ var/list/tint = cyberware_time_stop_tint()
+ var/list/out = list()
+ for(var/row in 0 to 3)
+ for(var/column in 1 to 3)
+ var/sum = row == 3 ? tint[9 + column] : 0
+ for(var/k in 0 to 2)
+ sum += first[row * 3 + k + 1] * tint[k * 3 + column]
+ out += sum
+ return out
+
+/**
+ * A hit flash (`flash`, a colour matrix held for `times`: in, hold, out) on a `body` the slow-mo tints. The client
+ * drew a tinted body in full colour while a second colour filter was animated on it, so the flash plays through the
+ * tint filter itself: tint over the flash, held, then back to the plain tint. FALSE if the body isn't tinted.
+ */
+/proc/cyberware_time_flash(atom/body, list/flash, list/times)
+ var/tint_filter = body.filter_data?[SANDY_STOP_TINT] && body.get_filter(SANDY_STOP_TINT)
+ if(!tint_filter)
+ return FALSE
+ var/list/flashed = cyberware_time_tint_after(flash)
+ // Beside the body's own animations: with a killing blow's death slump started the same tick, the client played the
+ // flash seconds late and near white, a corpse glowing in the middle of the slow-mo.
+ animate(tint_filter, color = flashed, time = times[1], easing = LINEAR_EASING, flags = ANIMATION_PARALLEL)
+ animate(color = flashed, time = times[2], easing = LINEAR_EASING)
+ animate(color = cyberware_time_stop_tint(), time = times[3], easing = LINEAR_EASING)
+ return TRUE
+
+/// Takes the slow-mo's tint off `thing`.
+/proc/cyberware_time_tint_off(atom/thing)
+ if(cyberware_time_tints_by_filter(thing))
+ thing.remove_filter(SANDY_STOP_TINT)
+ REMOVE_KEEP_TOGETHER(thing, SANDY_STOP_TINT)
+ return
+ thing.remove_atom_colour(TEMPORARY_COLOUR_PRIORITY)
+ if(istype(thing, /obj/effect/decal/cleanable/blood/gibs))
+ thing.update_appearance(UPDATE_OVERLAYS)
+
+/// Whether `thing` is drawn with the slow-mo's tint right now.
+/proc/cyberware_time_has_tint(atom/thing)
+ if(cyberware_time_tints_by_filter(thing))
+ return !!thing.filter_data?[SANDY_STOP_TINT]
+ var/list/entry = LAZYACCESS(thing.atom_colours, TEMPORARY_COLOUR_PRIORITY)
+ if(!entry || !islist(entry[ATOM_COLOR_VALUE_INDEX]))
+ return FALSE
+ var/list/worn = entry[ATOM_COLOR_VALUE_INDEX]
+ return compare_list(worn, cyberware_time_stop_tint()) || compare_list(worn, cyberware_time_tint_for(thing))
+
+/// Blood and loose gore the field tints like the world around it (it is only looked at, never held): nothing about
+/// gore is in colour in the slow-mo. Severed parts and spilled intestines are items, which otherwise keep their colour
+/// on the floor.
+/proc/cyberware_time_tinted_blood(atom/thing)
+ var/static/list/blood = typecacheof(list(
+ /obj/effect/decal/cleanable/blood,
+ /obj/effect/temp_visual/dir_setting/bloodsplatter,
+ /obj/effect/temp_visual/hv_blood_bead,
+ /obj/effect/temp_visual/wire_blood_drop,
+ /obj/item/hv_intestines,
+ /obj/effect/ebeam/hv_gut,
+ /obj/item/bodypart,
+ /obj/item/organ,
+ ))
+ if(!blood[thing.type])
+ return FALSE
+ return isturf(thing.loc) // a part or organ still in a body, a hand or a bag is not loose gore
+
+/obj/item/ammo_casing
+ /// Weakref to the untinted actor who fired or ejected this casing while a slow-mo ran, so it keeps its colour.
+ var/datum/weakref/sandy_untinted_by
+
+/// Whether `casing` was dropped or fired by someone who acts in their own colours in the current slow-mo.
+/proc/cyberware_casing_keeps_colour(obj/item/ammo_casing/casing)
+ var/atom/actor = casing.sandy_untinted_by?.resolve()
+ return actor && cyberware_untinted_actor(actor)
+
+/// Whether `shot` belongs to a shooter whose shots and hit effects stay in colour.
+/proc/cyberware_shot_untinted(obj/projectile/shot)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[shot]
+ if(istype(holder) && holder.user_shots[shot])
+ return TRUE
+ return shot.firer && cyberware_untinted_actor(shot.firer)
+
+/// Spent casings and turf shot effects the field tints like the floor, unless an untinted shooter made them.
+/proc/cyberware_time_tinted_shot_trash(atom/thing)
+ if(!isturf(thing.loc))
+ return FALSE
+ if(istype(thing, /obj/item/ammo_casing))
+ return !cyberware_casing_keeps_colour(thing)
+ if(istype(thing, /obj/effect/projectile) || istype(thing, /obj/effect/temp_visual/dir_setting/firing_effect) || istype(thing, /obj/effect/temp_visual/impact_effect))
+ return !cyberware_untinted_fx_active()
+ return FALSE
+
+/// tg works a blood decal's drying colour out of its `color` (blending it toward the dried colour), and its sprite is
+/// white, coloured by that `color`. With the slow-mo's tint matrix in `color` it would be drawn white and its drying
+/// colour lost, so while tinted it wears the tint mixed with its own colour, held where it was. It works its colour
+/// out again when the tint comes off (update_atom_colour() calls this). A colour filter didn't draw on decals.
+/// Blood made in the slow-mo wears it from its first picture: tg starts its drying animation (from its own colour, a
+/// text colour) as it is made, before the field tints it, and the client drew that blood white, its art with no colour,
+/// until the decal's next animation ended.
+/obj/effect/decal/cleanable/blood/update_blood_color()
+ if(!sandy_time_tinted() && !sandy_time_tint_due())
+ return ..()
+ animate(src)
+ var/own = sandy_replay_colour() // ware_sandy_replay.dm
+ if(!istext(own))
+ return TRUE
+ color = cyberware_time_tint_of(own)
+ return TRUE
+
+/// Whether the slow-mo's tint is on this blood right now.
+/obj/effect/decal/cleanable/blood/proc/sandy_time_tinted()
+ return islist(color) && LAZYACCESS(atom_colours, TEMPORARY_COLOUR_PRIORITY) && GLOB.cyberware_time_dilated[src]
+
+/// Whether this blood is being made on a slow-mo's ground that the field will tint it on this tick (once it is made).
+/obj/effect/decal/cleanable/blood/proc/sandy_time_tint_due()
+ if(!length(GLOB.cyberware_time_fields) || GLOB.cyberware_time_dilated[src] || !isturf(loc))
+ return FALSE
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_time_field(src)
+ return istype(field) && field.ring_wait(src) <= 0
+
+/// tg's create_splatter() sets the splash's colour after making it, over the slow-mo's tint: the tint goes back on.
+/mob/living/create_splatter(splatter_dir = pick(GLOB.cardinals))
+ . = ..()
+ for(var/obj/effect/temp_visual/dir_setting/bloodsplatter/splatter in get_turf(src))
+ if(GLOB.cyberware_time_dilated[splatter] && cyberware_time_has_tint(splatter))
+ cyberware_time_recolour_tinted(splatter)
+
+/// tg's Draw() gives a beam's last, cut-short segment the beam's colour right after making it, over the tint the
+/// field put on it as it was made (a gut strand's end showed raw in the slow-mo): the tint goes back on, and a
+/// strand drawn in the slow-mo has its picture in vis_contents tinted at once rather than on the next field tick.
+/datum/beam/Draw()
+ . = ..()
+ for(var/obj/effect/ebeam/segment as anything in elements)
+ if(QDELETED(segment) || !cyberware_time_has_tint(segment))
+ continue
+ if(istext(segment.color) && !LAZYACCESS(segment.atom_colours, FIXED_COLOUR_PRIORITY))
+ segment.add_atom_colour(segment.color, FIXED_COLOUR_PRIORITY) // its own colour again once the tint comes off
+ segment.add_atom_colour(cyberware_time_tint_for(segment), TEMPORARY_COLOUR_PRIORITY) // the wash over that colour
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = GLOB.cyberware_time_dilated[segment]
+ if(istype(field))
+ field.tint_blood_bits(segment)
+
+/obj/effect/decal/cleanable/blood/gibs
+ /// Set while sandy_untinted_overlays() builds the overlays as they are without the slow-mo's tint.
+ var/sandy_skip_tint = FALSE
+
+/obj/effect/decal/cleanable/blood
+ /// The pace tg sends it across the floor at (the delay of its move loop), kept while a field stretches it.
+ var/sandy_flight_delay
+
+/**
+ * tg sends a gib across the floor (streak()), and the blood knocked out of a body by a hit (the hitsplatter's
+ * fly_towards()), on move loops of their own, a tile every couple of deciseconds. Nothing slowed those: in a field a gib
+ * shot off at full speed while its tumble (hyperviolence/visuals/flying_gore.dm) crawled, a hit's blood crossed three
+ * tiles before the bullet that drew it had crossed one, and the replay showed both as many times too fast. Each step
+ * takes the field's time, worked out a step at a time, so one still on its way when the slow-mo ends goes on at its own
+ * pace. Call it once the loop is running.
+ */
+/obj/effect/decal/cleanable/blood/proc/sandy_slow_flight()
+ if(QDELETED(src) || !length(GLOB.cyberware_time_fields))
+ return
+ var/datum/move_loop/loop = move_packet?.running_loop
+ if(QDELETED(loop))
+ return
+ sandy_flight_delay = loop.delay
+ RegisterSignal(src, COMSIG_MOVABLE_MOVED_FROM_LOOP, PROC_REF(sandy_flight_stepped), override = TRUE)
+ if(sandy_flight_pace(loop))
+ loop.pause_for(loop.delay) // its first step was due at tg's pace
+
+/// Signal proc for [COMSIG_MOVABLE_MOVED_FROM_LOOP]: the step after this one takes what the field it is in now makes of it.
+/obj/effect/decal/cleanable/blood/proc/sandy_flight_stepped(atom/movable/source, datum/move_loop/loop)
+ SIGNAL_HANDLER
+ if(!QDELETED(loop))
+ sandy_flight_pace(loop)
+
+/// Sets `loop` (the flight's) to the field's pace, keeping the steps it has left. Returns TRUE if that changed it.
+/obj/effect/decal/cleanable/blood/proc/sandy_flight_pace(datum/move_loop/loop)
+ var/pace = max(cyberware_dilated_time(src, sandy_flight_delay), world.tick_lag)
+ if(pace == loop.delay)
+ return FALSE
+ loop.lifetime *= pace / loop.delay // counted down by the delay a step: the same steps left
+ loop.set_delay(pace)
+ return TRUE
+
+/**
+ * Short effects made inside a shooter (tg's firing_effect, gun_feel's muzzle flash) are drawn in their vis_contents,
+ * where no field turf ever sees them. On a glowing user they are drawn apart so the user's edge glow doesn't wrap the
+ * flash; on a slowed shooter the field tints them from their first frame, also drawn apart so the shooter's tint filter
+ * doesn't wash over them a second time.
+ */
+/obj/effect/temp_visual/Initialize(mapload)
+ . = ..()
+ if(mapload || . == INITIALIZE_HINT_QDEL || !length(GLOB.cyberware_time_fields) || !ismovable(loc))
+ return
+ var/atom/movable/shooter = loc
+ if(shooter.get_filter(SANDY_STOP_OUTLINE))
+ appearance_flags |= KEEP_APART
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_maker_field(shooter, shooter)
+ if(field)
+ appearance_flags |= KEEP_APART
+ field.take_looks(src)
+
+/// Marks casings ejected by an untinted shooter before they hit the ground, and hands a slowed shooter's casing to
+/// their field even in the outer reaches of a covered room.
+/obj/item/gun/ballistic/handle_chamber(empty_chamber = TRUE, from_firing = TRUE, chamber_next_round = TRUE)
+ var/obj/item/ammo_casing/casing = chambered
+ var/atom/holder = cyberware_actor_root(src)
+ if(istype(casing) && length(GLOB.cyberware_time_fields))
+ casing.sandy_untinted_by = cyberware_untinted_actor(holder) ? WEAKREF(holder) : null
+ . = ..()
+ if(istype(casing) && !QDELETED(casing) && length(GLOB.cyberware_time_fields) && isturf(casing.loc) && !GLOB.cyberware_time_dilated[casing] && !cyberware_casing_keeps_colour(casing))
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_maker_field(holder, casing)
+ field?.freeze_atom(casing)
+
+/// Keeps casings and turf flashes fired without a ballistic gun (basic mobs' ranged_attacks, turrets) in step with
+/// whoever fired them.
+/obj/item/ammo_casing/throw_proj(atom/target, turf/targloc, mob/living/user, params, spread, atom/fired_from)
+ if(!length(GLOB.cyberware_time_fields))
+ return ..()
+ var/atom/actor = cyberware_actor_root(user || fired_from)
+ var/untinted = cyberware_untinted_actor(actor)
+ sandy_untinted_by = untinted ? WEAKREF(actor) : null
+ if(untinted)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[src]
+ if(istype(holder) && !throwing)
+ holder.unfreeze_atom(src)
+ GLOB.cyberware_untinted_fx_at = world.time
+ GLOB.cyberware_untinted_fx_depth++
+ . = ..()
+ if(untinted)
+ GLOB.cyberware_untinted_fx_depth = max(GLOB.cyberware_untinted_fx_depth - 1, 0)
+ return
+ if(!QDELETED(src) && isturf(loc) && !GLOB.cyberware_time_dilated[src])
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_maker_field(actor, src)
+ field?.freeze_atom(src)
+ if(!user && firing_effect_type)
+ var/turf/flash_spot = get_turf(src)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = flash_spot ? cyberware_maker_field(actor, flash_spot) : null
+ if(field)
+ for(var/obj/effect/temp_visual/fx in flash_spot)
+ if(istype(fx, firing_effect_type) && !GLOB.cyberware_time_dilated[fx])
+ field.freeze_atom(fx)
+
+/// Casings tipped out of a cylinder, box or hand take or skip the tint by whoever dropped them; picked up off the
+/// floor, they drop the field's tint.
+/obj/item/ammo_casing/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
+ . = ..()
+ var/on_floor = isturf(loc)
+ if(on_floor == isturf(old_loc))
+ return
+ if(!on_floor)
+ sandy_untinted_by = null
+ if(!throwing)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[src]
+ holder?.unfreeze_atom(src)
+ return
+ if(!length(GLOB.cyberware_time_fields) || !old_loc)
+ return
+ var/atom/actor = cyberware_actor_root(old_loc)
+ if(cyberware_untinted_actor(actor))
+ sandy_untinted_by = WEAKREF(actor)
+ if(!throwing)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[src]
+ holder?.unfreeze_atom(src)
+ else if(!cyberware_casing_keeps_colour(src) && !GLOB.cyberware_time_dilated[src])
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_maker_field(actor, src)
+ field?.freeze_atom(src)
+
+/// Impact puffs stay untinted for an untinted shooter's round and take the tint for a slowed one's.
+/obj/projectile/on_hit(atom/target, blocked = 0, pierce_hit)
+ if(!length(GLOB.cyberware_time_fields))
+ return ..()
+ if(cyberware_shot_untinted(src))
+ GLOB.cyberware_untinted_fx_at = world.time
+ GLOB.cyberware_untinted_fx_depth++
+ . = ..()
+ GLOB.cyberware_untinted_fx_depth = max(GLOB.cyberware_untinted_fx_depth - 1, 0)
+ return
+ . = ..()
+ if(impact_effect_type && !hitscan)
+ var/turf/spot = get_turf(target)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = spot ? cyberware_maker_field(firer || fired_from, spot) : null
+ if(field)
+ for(var/obj/effect/temp_visual/fx in spot)
+ if(istype(fx, impact_effect_type) && !GLOB.cyberware_time_dilated[fx])
+ field.freeze_atom(fx)
+
+/// tg's hitscan sets its muzzle, tracer and impact colours after making them, over any tint the turf put on them:
+/// put the wash back over a slowed shooter's beam, and leave an untinted shooter's beam in its own colour.
+/obj/projectile/generate_hitscan_tracers(impact_point = TRUE, impact_visual = TRUE)
+ if(!length(GLOB.cyberware_time_fields))
+ return ..()
+ if(cyberware_shot_untinted(src))
+ GLOB.cyberware_untinted_fx_at = world.time
+ GLOB.cyberware_untinted_fx_depth++
+ . = ..()
+ GLOB.cyberware_untinted_fx_depth = max(GLOB.cyberware_untinted_fx_depth - 1, 0)
+ return
+ . = ..()
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/maker_field = cyberware_maker_field(firer || fired_from, src)
+ var/list/spots = list()
+ if(isturf(loc))
+ spots[loc] = TRUE
+ if(last_point)
+ var/turf/end_turf = last_point.return_turf()
+ if(end_turf)
+ spots[end_turf] = TRUE
+ for(var/datum/point/pt as anything in beam_points)
+ var/turf/pt_turf = pt.return_turf()
+ if(pt_turf)
+ spots[pt_turf] = TRUE
+ var/datum/point/next_pt = beam_points[pt]
+ var/turf/next_turf = next_pt?.return_turf()
+ if(pt_turf && next_turf)
+ for(var/turf/line_turf as anything in get_line(pt_turf, next_turf))
+ spots[line_turf] = TRUE
+ for(var/turf/spot as anything in spots)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = maker_field || cyberware_maker_field(null, spot)
+ for(var/obj/effect/projectile/beam_fx in spot)
+ if(!GLOB.cyberware_time_dilated[beam_fx] && field)
+ field.freeze_atom(beam_fx)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[beam_fx]
+ if(istype(holder) && holder.tinted[beam_fx] && istext(beam_fx.color))
+ cyberware_time_recolour_tinted(beam_fx)
+ holder.replay?.resample(beam_fx)
+
+/// Every throw started inside a dilation field skips tg's immediate full-speed first step and flies at the field's pace,
+/// even for bodies already held in `held_mobs` or items already lying on the floor.
+/atom/movable/throw_at(atom/target, range, speed, mob/thrower, spin = TRUE, diagonals_first = FALSE, datum/callback/callback, force = MOVE_FORCE_STRONG, gentle = FALSE, quickstart = TRUE, throw_datum_typepath = /datum/thrownthing)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = length(GLOB.cyberware_time_fields) ? cyberware_throw_field(src) : null
+ if(field)
+ quickstart = FALSE
+ var/datum/thrownthing/previous = throwing
+ . = ..()
+ if(!. || !throwing || throwing == previous)
+ return
+ if(previous)
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/holder as anything in GLOB.cyberware_time_fields)
+ if(holder.held_throws[src])
+ holder.held_throws -= src
+ field = field || (length(GLOB.cyberware_time_fields) ? cyberware_throw_field(src) : null)
+ field?.take_throw(src)
+
+/// Restores a slowed throw's real speed as it lands, before `finalize()` works out impact damage and zero-g drift.
+/datum/thrownthing/finalize(hit = FALSE, target = null)
+ set waitfor = FALSE
+ if(thrownthing && length(GLOB.cyberware_time_fields))
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.held_throws[thrownthing])
+ field.finish_throw(thrownthing, src)
+ break
+ return ..()
+
+/obj/effect/decal/cleanable/blood/gibs/streak(list/directions, mapload = FALSE)
+ . = ..()
+ if(!mapload)
+ sandy_slow_flight()
+
+/obj/effect/decal/cleanable/blood/hitsplatter/fly_towards(turf/target_turf, range)
+ . = ..()
+ sandy_slow_flight()
+
+/// A gib's meat and bone are a KEEP_APART, RESET_COLOR overlay that the tint in `color` skips: tinted, it wears the
+/// wash over its own colour too, and gets its colour back when the tint comes off (cyberware_time_tint_off()).
+/obj/effect/decal/cleanable/blood/gibs/update_overlays()
+ . = ..()
+ if(sandy_skip_tint || !sandy_time_tinted())
+ return
+ for(var/mutable_appearance/bit in .)
+ if(bit.appearance_flags & RESET_COLOR)
+ bit.color = cyberware_time_tint_of(istext(bit.color) ? bit.color : COLOR_WHITE)
+
+/// Swaps the tinted meat overlay in `look` (a copy of this gib's appearance) for the untinted one, so the replay
+/// shows the meat in its own colour (ware_sandy_replay.dm, clean_look()).
+/obj/effect/decal/cleanable/blood/gibs/proc/sandy_untinted_overlays(mutable_appearance/look)
+ if(managed_overlays)
+ look.overlays -= managed_overlays
+ sandy_skip_tint = TRUE
+ var/list/plain = update_overlays()
+ sandy_skip_tint = FALSE
+ for(var/overlay in plain)
+ if(overlay)
+ look.overlays += overlay
+
+/// Flattens a sprite to luminance and paints it the dilation's green (#5AFF96).
+/proc/cyberware_time_stop_green()
+ var/static/list/green
+ if(!green)
+ var/red = 90 / 255
+ var/grn = 1
+ var/blue = 150 / 255
+ // gain + lift = 1, so white maps to the green itself and black to a dim green
+ var/gain = 0.65
+ var/lift = 0.35
+ green = list(
+ 0.3 * gain * red, 0.3 * gain * grn, 0.3 * gain * blue,
+ 0.59 * gain * red, 0.59 * gain * grn, 0.59 * gain * blue,
+ 0.11 * gain * red, 0.11 * gain * grn, 0.11 * gain * blue,
+ lift * red, lift * grn, lift * blue,
+ )
+ return green
+
+/// Blackboard keys holding world.time deadlines that slow down with their owner.
+/proc/dilated_blackboard_keys()
+ var/static/list/keys = list(
+ BB_HUMAN_NPC_NEXT_SHOT,
+ BB_HUMAN_NPC_RELOAD_UNTIL,
+ BB_HUMAN_NPC_ARMING_RETRY_AT,
+ BB_HUMAN_NPC_NEXT_TREAT,
+ BB_HUMAN_NPC_FLEE_UNTIL,
+ BB_BOUNTY_NEXT_STEP_AT,
+ BB_BOUNTY_BACKSTEP_AT,
+ BB_BOUNTY_BOSS_HUNT_AT,
+ BB_BOUNTY_BOSS_RELOAD_UNTIL,
+ BB_BASIC_MOB_REINFORCEMENTS_COOLDOWN,
+ // defined and undefined inside their own modules
+ "convict_hit_until",
+ "convict_lost_since",
+ "pirate_windup_until",
+ "pirate_breach_started",
+ "pirate_no_path_at",
+ "pirate_breach_progress_at",
+ "pirate_next_execution", // BB_PIRATE_NEXT_EXECUTION
+ "BB_outpost_horror_hunt_at", // BB_OUTPOST_HORROR_HUNT_AT
+ )
+ return keys
+
+/datum/movespeed_modifier/cyberware_dilation
+ variable = TRUE
+
+// =========================================================================
+// THE EFFECT
+// =========================================================================
+
+/// Lives as long as the dilation, holds the field on the user, and ends it when deleted.
+/obj/effect/timestop/sandevistan
+ name = "stopped moment"
+ desc = null
+ hidden = TRUE
+ alpha = 0
+ freezerange = SANDY_STOP_FIELD_RANGE
+ /// Whose dilation this is. The field is hosted on them.
+ var/mob/living/user
+ /// How fast the world runs.
+ var/slow_scale = 1
+ /// The user's own time multiplier (their surge model's), for surging mobs' relative rates.
+ var/user_multiplier = 1
+ /// The timer that ends the slow-mo when its time is up.
+ var/end_timer
+
+/// `immune_atoms` must be list(user). `time` is the whole effect, all of it at `scale`. `multiplier` is the user's
+/// surge model's time multiplier.
+/obj/effect/timestop/sandevistan/Initialize(mapload, radius, time, list/immune_atoms, start = TRUE, silent = TRUE, scale = 1, multiplier = 1)
+ if(length(immune_atoms))
+ user = immune_atoms[1]
+ slow_scale = scale
+ user_multiplier = multiplier
+ return ..(mapload, radius, time, immune_atoms, start, TRUE)
+
+/obj/effect/timestop/sandevistan/Destroy()
+ deltimer(end_timer)
+ end_timer = null
+ user = null
+ return ..()
+
+/// The slow-mo's time is up. Its user's surge window decides when it really ends; without one it ends now.
+/obj/effect/timestop/sandevistan/proc/time_up()
+ end_timer = null
+ var/datum/status_effect/cyberware_cascade_window/window = user?.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ if(window?.time_stop == src)
+ window.slowmo_time_up()
+ return
+ qdel(src)
+
+/obj/effect/timestop/sandevistan/timestop()
+ target = get_turf(src)
+ // A tick before the window would close, so the window hears it first: an execution in progress holds the slow-mo
+ // (cyberware_cascade_window/proc/slowmo_time_up()).
+ end_timer = addtimer(CALLBACK(src, PROC_REF(time_up)), max(duration - world.tick_lag, world.tick_lag), TIMER_STOPPABLE | TIMER_DELETE_ME)
+ if(QDELETED(user))
+ return
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = new(user, freezerange, FALSE, immune, antimagic_flags, FALSE, slow_scale, user_multiplier) // a user inside a mech still slows the world
+ field.stopper = src
+ field.ends_at = world.time + duration
+ chronofield = field
+
+// =========================================================================
+// THE FIELD
+// =========================================================================
+
+/datum/proximity_monitor/advanced/timestop/sandevistan
+ /// The effect that owns this field. Deleting it ends the dilation.
+ var/obj/effect/timestop/sandevistan/stopper
+ /// How fast time runs in here, below 1.
+ var/time_scale = 1
+ /// world.time of the last tick, for how much time each tick dilated.
+ var/last_tick = 0
+ /// The field's own clock. A timer, not SSfastprocess, which sleeps outside RUNLEVEL_GAME.
+ var/tick_timer
+ /// Mobs in hand.
+ var/list/held_mobs = list()
+ /// Projectiles in hand, to their own speed.
+ var/list/held_shots = list()
+ /// Thrown things in hand, to their own speed.
+ var/list/held_throws = list()
+ /// The user's own shots: never tinted. A surging mob's held shots aren't tinted either.
+ var/list/user_shots = list()
+ /// Bosses in hand, to the world.time they shrug the field off.
+ var/list/boss_holds = list()
+ /// Bosses that already shrugged it off. The field leaves them be.
+ var/list/released = list()
+ /// world.time the effect ends, when time runs normally again.
+ var/ends_at = INFINITY
+ /// Mechs held. Their move cooldown runs slow.
+ var/list/held_mechs = list()
+ /// Turrets held. Their fire cooldown runs slow.
+ var/list/held_turrets = list()
+ /// Armed grenades held. Their fuse runs slow.
+ var/list/held_grenades = list()
+ /// Mobs in range running their own surge. The field leaves them and their shots be until their window closes.
+ var/list/surging = list()
+ /// Held mobs, to the tags of their slowed hv_vis_play() animations, to drop if they break free.
+ var/list/slowed_tags = list()
+ /// The user's slowed weather and sound (ware_sandy_senses.dm).
+ var/datum/sandy_senses/senses
+ /// The user's time multiplier. A surging mob runs at its own over this.
+ var/user_multiplier = 1
+ /// Surging mobs held at their relative rate, to that rate. Never 0, never tinted. Their shots fly at the field's pace.
+ var/list/own_scales = list()
+ /// Things that should wear the tint, to TRUE.
+ var/list/tinted = list()
+ /// Tinted things the ring hasn't reached yet, to the timer that tints them when it does.
+ var/list/tint_timers = list()
+ /// Where the green ring rolls out from, while it is rolling.
+ var/turf/ring_center
+ /// world.time the ring started rolling.
+ var/ring_start = 0
+ /// How long the ring takes to reach its full size.
+ var/ring_time = 0
+ /// The ring's full size, in tiles of radius.
+ var/ring_reach = 0
+ /// The recording of this slow-mo, played back when it ends (ware_sandy_replay.dm). Only a player's field has one.
+ var/datum/sandy_replay/replay
+ /// Tinted blood decals and gut strands, checked each tick for drips, trail pieces or strand pictures new in their vis_contents.
+ var/list/blood_holders = list()
+ /// The user's finisher rig pictures, to the glow drawn under each (glow_rig_picture()).
+ var/list/rig_glows = list()
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/New(atom/_host, range, _ignore_if_not_on_turf = TRUE, list/immune, antimagic_flags, channelled, _time_scale = 1, _user_multiplier = 1)
+ time_scale = _time_scale > 0 ? _time_scale : 1
+ user_multiplier = _user_multiplier > 0 ? _user_multiplier : 1
+ last_tick = world.time
+ GLOB.cyberware_time_fields += src
+ if(isliving(_host))
+ var/mob/living/recorded = _host
+ if(recorded.ckey)
+ replay = new(src, recorded) // before the field takes its first turf, so it sees everything
+ cover_preset_ring(_host) // ware_sandy_timestop_cover.dm
+ . = ..()
+ cover_start() // ware_sandy_timestop_cover.dm
+ STOP_PROCESSING(SSfastprocess, src) // tick() runs on tick_timer instead
+ tick_timer = addtimer(CALLBACK(src, PROC_REF(tick)), 0.2 SECONDS, TIMER_LOOP | TIMER_STOPPABLE | TIMER_DELETE_ME)
+ RegisterSignal(host, COMSIG_PROJECTILE_FIRER_BEFORE_FIRE, PROC_REF(on_user_fire))
+ if(ismob(host))
+ senses = new(src)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/Destroy()
+ QDEL_NULL(senses)
+ cover_end() // ware_sandy_timestop_cover.dm
+ deltimer(tick_timer)
+ tick_timer = null
+ if(host)
+ UnregisterSignal(host, COMSIG_PROJECTILE_FIRER_BEFORE_FIRE)
+ stopper = null
+ GLOB.cyberware_time_fields -= src
+ var/list/were_surging = surging.Copy()
+ for(var/mob/living/surger as anything in surging)
+ UnregisterSignal(surger, COMSIG_QDELETING)
+ surging.Cut()
+ . = ..() // unfreeze_all() lets everything go
+ for(var/mob/living/surger as anything in were_surging)
+ cyberware_surge_refresh_perks(surger) // a surge still open gets its own edge back
+ own_scales.Cut()
+ released.Cut()
+ var/datum/sandy_replay/recording = replay
+ replay = null
+ recording?.field_over() // it plays back from here; a player cutting the slow-mo short cancelled it in tick()
+
+/// How long, in real time from now, `local` deciseconds of `thing`'s own time take: its rate in the field until
+/// the effect (or a boss's hold) ends, then real time.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/real_time_for(atom/thing, local)
+ var/now = world.time
+ var/ends = ends_at
+ if(boss_holds[thing])
+ ends = min(ends, boss_holds[thing])
+ var/rate = scale_for(thing)
+ if(ends <= now || rate == 1)
+ return local
+ var/span = (ends - now) * rate
+ if(local <= span)
+ return local / rate
+ return ends - now + local - span
+
+/// How fast time runs for `thing` in this field: a surger's own relative rate, 1 for a surger left alone, else the field's pace.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/scale_for(atom/thing)
+ var/own = own_scales[thing]
+ if(own)
+ return own
+ if(surging[thing])
+ return 1
+ return time_scale
+
+/// The rate, against normal speed, of a mob surging at `multiplier` in this field. Capped at SANDY_STOP_MAX_RELATIVE.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/relative_rate(multiplier)
+ if(!multiplier || multiplier <= 0)
+ multiplier = 1
+ return min(multiplier / user_multiplier, SANDY_STOP_MAX_RELATIVE)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/freeze_atom(atom/movable/A)
+ replay?.notice(A) // everything on, entering or made on a field turf comes through here
+ if(sandy_session_shares(src, A)) // another member of a shared slow-mo runs in its own field (ware_sandy_timestop_shared.dm)
+ return FALSE
+ if(!istype(A) || global_frozen_atoms[A])
+ return FALSE
+ if(GLOB.cyberware_time_dilated[A] || released[A] || immune[A] || surging[A])
+ if(A.throwing)
+ take_throw(A) // a body already held, thrown across the field
+ return FALSE
+ if(cyberware_own_surge(A))
+ take_surger(A, cyberware_surge_multiplier(A))
+ return FALSE
+ if(own_ride(A)) // the user's mech or vehicle is part of them: full speed
+ return FALSE
+ if(ismob(A))
+ var/mob/M = A
+ if(M.can_block_magic(antimagic_flags))
+ immune[A] = TRUE
+ return FALSE
+ var/tint = TRUE
+ if(isliving(A))
+ hold_mob(A)
+ else if(isprojectile(A))
+ var/obj/projectile/shot = A
+ if(shot.firer && immune[shot.firer])
+ user_shots[shot] = TRUE
+ tint = FALSE
+ escape_the_negative_zone(shot) // in case it was tinted before it had a firer
+ else if(shot.firer && (surging[shot.firer] || cyberware_own_surge(shot.firer))) // at the field's pace, like every bullet, but in colour
+ tint = FALSE
+ hold_shot(shot)
+ else if(ismecha(A))
+ hold_mech(A)
+ else if(istype(A, /obj/machinery/porta_turret))
+ frozen_structures += A
+ held_turrets[A] = TRUE
+ else if((ismachinery(A) && !istype(A, /obj/machinery/light)) || isstructure(A) || cyberware_time_tinted_blood(A) || cyberware_time_tinted_shot_trash(A))
+ frozen_structures += A // looks only
+ else if(cyberware_lit_grenade(A))
+ held_grenades[A] = TRUE
+ tint = !!A.throwing // floor items keep their colour
+ else if(!A.throwing)
+ return FALSE
+ else if(istype(A, /obj/item/ammo_casing) && cyberware_casing_keeps_colour(A))
+ tint = FALSE
+ if(A.throwing)
+ hold_throw(A)
+ GLOB.cyberware_time_dilated[A] = src
+ frozen_things[A] = TRUE
+ RegisterSignal(A, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+ if(tint)
+ into_the_negative_zone(A)
+ if(istype(A, /obj/effect/decal/cleanable/blood) || istype(A, /obj/effect/ebeam))
+ tint_blood_bits(A)
+ return TRUE
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/setup_field_turf(turf/target)
+ if(!replay)
+ return ..()
+ replay.covering = TRUE // what stands on a turf the field moves onto was there all along
+ . = ..()
+ replay?.covering = FALSE
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/unfreeze_all()
+ for(var/obj/effect/picture as anything in rig_glows)
+ drop_rig_glow(picture)
+ for(var/atom/movable/flier as anything in held_throws.Copy())
+ let_go_throw(flier)
+ if(!frozen_things[flier] && !surging[flier])
+ UnregisterSignal(flier, COMSIG_QDELETING)
+ for(var/atom/movable/thing as anything in frozen_things)
+ unfreeze_atom(thing)
+ for(var/turf/ground as anything in frozen_turfs)
+ unfreeze_turf(ground)
+ frozen_turfs.Cut()
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/unfreeze_atom(atom/movable/A)
+ if(held_mobs[A])
+ let_go_mob(A)
+ if(held_shots[A])
+ let_go_shot(A)
+ if(held_throws[A])
+ let_go_throw(A)
+ held_mechs -= A
+ held_turrets -= A
+ held_grenades -= A
+ frozen_structures -= A
+ blood_holders -= A
+ user_shots -= A
+ slowed_tags -= A
+ own_scales -= A
+ UnregisterSignal(A, COMSIG_QDELETING)
+ escape_the_negative_zone(A)
+ frozen_things -= A
+ GLOB.cyberware_time_dilated -= A
+
+// ----- mobs -----
+
+/// Takes hold of a mob: slowed (or sped up, for a faster surger), whichever its rate is.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/hold_mob(mob/living/victim)
+ held_mobs[victim] = TRUE
+ slow_mob(victim)
+ if(scale_for(victim) < 1 && cyberware_time_stop_boss(victim))
+ boss_holds[victim] = world.time + SANDY_STOP_BOSS_HOLD
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/let_go_mob(mob/living/victim)
+ unslow_mob(victim)
+ held_mobs -= victim
+ boss_holds -= victim
+
+/// Paces a mob's walk to its rate in the field: slower, or faster for a faster surger. Its timers move with it every tick().
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/slow_mob(mob/living/victim)
+ var/rate = scale_for(victim)
+ victim.remove_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation)
+ // A slowed walk gets at least a decisecond's delay to stretch; a faster one divides what it really has.
+ var/base_delay = rate < 1 ? max(victim.cached_multiplicative_slowdown, 1) : max(victim.cached_multiplicative_slowdown, 0)
+ victim.add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation, multiplicative_slowdown = base_delay * (1 / rate - 1))
+ if(istype(victim, /mob/living/simple_animal/hostile))
+ var/mob/living/simple_animal/hostile/animal_victim = victim
+ animal_victim.move_to_delay = initial(animal_victim.move_to_delay) / rate
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/unslow_mob(mob/living/victim)
+ victim.remove_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation)
+ if(istype(victim, /mob/living/simple_animal/hostile))
+ var/mob/living/simple_animal/hostile/animal_victim = victim
+ animal_victim.move_to_delay = initial(animal_victim.move_to_delay)
+
+/// Pushes every timing deadline `victim` has that hasn't passed yet back by `push` deciseconds (forward, if negative).
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/push_deadlines(mob/living/victim, push)
+ cyberware_push_deadlines(victim, push)
+
+/**
+ * Pushes every timing deadline `victim` has that was still to come at `since` (default now) back by `push` deciseconds
+ * (forward, if negative). The one list of a mob's clocks: the slow-mo field slows them with it, and the replay's hold
+ * (ware_sandy_replay.dm) stops them with it, so a clock added here is covered by both.
+ */
+/proc/cyberware_push_deadlines(mob/living/victim, push, since = world.time)
+ var/now = since
+ if(victim.next_move > now)
+ victim.next_move += push
+ for(var/datum/action/cooldown/ability in victim.actions)
+ if(ability.next_use_time > now)
+ ability.next_use_time += push
+ var/datum/ai_controller/controller = victim.ai_controller
+ if(controller)
+ for(var/behavior in controller.behavior_cooldowns)
+ if(controller.behavior_cooldowns[behavior] > now)
+ controller.behavior_cooldowns[behavior] += push
+ for(var/key in dilated_blackboard_keys())
+ var/deadline = controller.blackboard[key]
+ if(isnum(deadline) && deadline > now)
+ controller.blackboard[key] = deadline + push
+ var/datum/component/ranged_attacks/ranged = victim.GetComponent(/datum/component/ranged_attacks)
+ if(ranged && ranged.fire_cooldown > now)
+ ranged.fire_cooldown += push
+ if(istype(victim, /mob/living/simple_animal/hostile))
+ var/mob/living/simple_animal/hostile/animal_victim = victim
+ if(animal_victim.ranged_cooldown > now)
+ animal_victim.ranged_cooldown += push
+
+ for(var/obj/item/gun/gun in victim.held_items)
+ gun.cyberware_burst_start += push
+ if(ranged)
+ ranged.cyberware_burst_start += push
+ victim.cyberware_push_clocks(push) // its own clocks (ware_sandy_timestop_cover.dm)
+
+// ----- mobs on their own surge -----
+
+/**
+ * `surger` runs its own surge at `multiplier`: at the same rate as the user it is left alone; otherwise the field
+ * holds it at its relative rate, slower or faster, untinted.
+ */
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/take_surger(mob/living/surger, multiplier)
+ surging[surger] = TRUE
+ RegisterSignal(surger, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+ cyberware_surge_refresh_perks(surger) // the field paces it now, not its own edge
+ var/rate = relative_rate(multiplier)
+ if(abs(rate - 1) < SANDY_STOP_SAME_RATE)
+ return
+ own_scales[surger] = rate
+ hold_mob(surger)
+ GLOB.cyberware_time_dilated[surger] = src
+ frozen_things[surger] = TRUE
+
+/**
+ * `surger` opened its own surge at `multiplier`: if the field holds it, let it go now and drop every slow it
+ * carried (its walk, its pauses, its last bit of lost time, its slowed animations and the shots it fired), then
+ * take it back at its relative rate. Its shots go back in at the field's pace, untinted.
+ */
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/surge_free(mob/living/surger, multiplier)
+ if(surging[surger] || sandy_session_shares(src, surger))
+ return
+ var/list/its_shots = list()
+ if(GLOB.cyberware_time_dilated[surger] == src)
+ var/lag = cyberware_time_lag(surger)
+ if(lag > 0)
+ push_deadlines(surger, lag) // the time it really lost since the last tick
+ var/list/tags = slowed_tags[surger]
+ unfreeze_atom(surger)
+ for(var/tag in tags)
+ surger.hv_vis_release(tag, 1) // back to its real pose at once, not at the slowed pace
+ for(var/obj/projectile/shot as anything in held_shots.Copy())
+ if(shot.firer == surger)
+ unfreeze_atom(shot)
+ its_shots += shot
+ else
+ var/turf/centre = get_turf(host)
+ var/turf/here = get_turf(surger)
+ if(!centre || !here || here.z != centre.z || get_dist(centre, here) > current_range)
+ return // out of reach: if it walks in still surging, freeze_atom() takes it at its rate
+ take_surger(surger, multiplier)
+ for(var/obj/projectile/shot as anything in its_shots)
+ if(!QDELETED(shot))
+ freeze_atom(shot)
+
+/// Every tick: surgers whose window has closed go back to the field's pace, if they are still in range. A surger
+/// that died is let go for good: its corpse is never taken back and tinted.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/check_surgers()
+ var/turf/centre = get_turf(host)
+ for(var/mob/living/surger as anything in surging.Copy())
+ if(surger.stat != DEAD && cyberware_own_surge(surger))
+ continue
+ if(GLOB.cyberware_time_dilated[surger] == src)
+ var/lag = cyberware_time_lag(surger)
+ if(lag)
+ push_deadlines(surger, lag)
+ unfreeze_atom(surger)
+ surging -= surger
+ UnregisterSignal(surger, COMSIG_QDELETING)
+ cyberware_surge_refresh_perks(surger)
+ if(surger.stat == DEAD)
+ released[surger] = TRUE
+ continue
+ var/turf/here = get_turf(surger)
+ if(centre && here && here.z == centre.z && get_dist(centre, here) <= current_range)
+ freeze_atom(surger)
+
+// ----- mechs, turrets, grenades -----
+
+/// Takes hold of a mech and whoever is driving it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/hold_mech(obj/vehicle/sealed/mecha/mech)
+ frozen_structures += mech
+ held_mechs[mech] = TRUE
+ for(var/mob/living/pilot in mech.occupants)
+ freeze_atom(pilot)
+
+/// Pushes back the clocks of held machines and grenades by `push` deciseconds.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/push_machine_deadlines(push)
+ for(var/obj/vehicle/sealed/mecha/mech as anything in held_mechs)
+ cyberware_push_machine_deadlines(mech, push)
+ for(var/obj/machinery/porta_turret/turret as anything in held_turrets)
+ cyberware_push_machine_deadlines(turret, push)
+ for(var/obj/item/grenade/bomb as anything in held_grenades)
+ cyberware_push_machine_deadlines(bomb, push)
+
+/// Pushes the clock of a held machine or grenade `thing` back by `push` deciseconds, if it was still to come at `since`
+/// (default now). Shared by the field and the replay's hold (ware_sandy_replay.dm), like cyberware_push_deadlines().
+/proc/cyberware_push_machine_deadlines(atom/thing, push, since = world.time)
+ var/now = since
+ if(ismecha(thing))
+ var/obj/vehicle/sealed/mecha/mech = thing
+ if(mech.cooldown_vehicle_move > now)
+ mech.cooldown_vehicle_move += push
+ else if(istype(thing, /obj/machinery/porta_turret))
+ var/obj/machinery/porta_turret/turret = thing
+ if(turret.last_fired + turret.shot_delay > now)
+ turret.last_fired += push
+ else if(istype(thing, /obj/item/grenade))
+ var/obj/item/grenade/bomb = thing
+ if(bomb.cyberware_fuse_at > now)
+ bomb.cyberware_fuse_at += push
+
+// ----- projectiles -----
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/hold_shot(obj/projectile/shot)
+ held_shots[shot] = shot.speed
+ shot.speed = held_shots[shot] * scale_for(shot)
+ if(!user_shots[shot]) // a shot is made, and taken, before it has a firer
+ RegisterSignal(shot, COMSIG_PROJECTILE_FIRE, PROC_REF(held_shot_fired), override = TRUE)
+
+/// Signal proc for [COMSIG_PROJECTILE_FIRE] on a held shot: now it has a firer, a surging mob's shot loses the tint.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/held_shot_fired(obj/projectile/shot)
+ SIGNAL_HANDLER
+ UnregisterSignal(shot, COMSIG_PROJECTILE_FIRE)
+ if(shot.firer && (surging[shot.firer] || cyberware_own_surge(shot.firer)))
+ escape_the_negative_zone(shot)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/let_go_shot(obj/projectile/shot)
+ shot.speed = held_shots[shot]
+ held_shots -= shot
+ UnregisterSignal(shot, COMSIG_PROJECTILE_FIRE)
+
+/// Signal proc for [COMSIG_PROJECTILE_FIRER_BEFORE_FIRE] on the user: watch the shot leave the barrel.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/on_user_fire(datum/source, obj/projectile/shot, atom/fired_from, atom/original)
+ SIGNAL_HANDLER
+ RegisterSignal(shot, COMSIG_PROJECTILE_FIRE, PROC_REF(take_user_shot), override = TRUE)
+
+/// Signal proc for [COMSIG_PROJECTILE_FIRE]: the user's shot keeps its colour but crawls at the field's pace like
+/// every bullet in it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/take_user_shot(obj/projectile/shot)
+ SIGNAL_HANDLER
+ UnregisterSignal(shot, COMSIG_PROJECTILE_FIRE)
+ if(QDELETED(shot) || shot.deletion_queued)
+ return
+ user_shots[shot] = TRUE
+ escape_the_negative_zone(shot) // in case it was tinted before it had a firer
+ if(held_shots[shot])
+ return
+ // Another field (a crewmate's, in a shared slow-mo) took it as it was made: it lets go first, or both would slow
+ // it, and whichever let go last would leave it flying at the slowed pace after the slow-mo.
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[shot]
+ if(istype(holder) && holder != src)
+ holder.unfreeze_atom(shot)
+ hold_shot(shot)
+ GLOB.cyberware_time_dilated[shot] = src
+ frozen_things[shot] = TRUE
+ RegisterSignal(shot, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+
+// ----- throws -----
+
+/// Whether `thing` is a body on its own time here: the user, their ride, a surging mob, a freed boss, a crewmate in the
+/// shared slow-mo, anyone the field can't touch. Thrown, it flies at its own speed.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/own_time(atom/movable/thing)
+ return !!(thing == host || immune[thing] || surging[thing] || released[thing] || own_ride(thing) || sandy_session_shares(src, thing))
+
+/// Takes a throw started or arriving in the field: held bodies and floor items alike fly at the field's pace.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/take_throw(atom/movable/thing)
+ if(QDELETED(thing) || !thing.throwing || cover_outsider(thing) || own_time(thing))
+ return
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/holder as anything in GLOB.cyberware_time_fields)
+ if(holder.held_throws[thing])
+ return
+ if(!GLOB.cyberware_time_dilated[thing] && freeze_atom(thing))
+ return
+ replay?.notice(thing)
+ hold_throw(thing)
+ if(held_grenades[thing] && !tinted[thing])
+ into_the_negative_zone(thing)
+ else if(!frozen_things[thing] && !surging[thing])
+ RegisterSignal(thing, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+
+/// Records `thing`'s own throw speed and slows its flight to the field's pace.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/hold_throw(atom/movable/thing)
+ var/datum/thrownthing/flight = thing.throwing
+ if(!flight)
+ return
+ if(!held_throws[thing])
+ held_throws[thing] = flight.speed
+ pace_throw(thing, held_throws[thing] * time_scale, flight)
+
+/// Sets `thing`'s `flight` to `new_speed`, keeping its progress along the current tile.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/pace_throw(atom/movable/thing, new_speed, datum/thrownthing/flight = thing.throwing)
+ if(!flight || new_speed <= 0 || flight.speed == new_speed)
+ return
+ var/elapsed = max(world.time - flight.start_time + flight.delayed_time, 0)
+ flight.start_time = world.time + flight.delayed_time - elapsed * (flight.speed / new_speed)
+ flight.speed = new_speed
+
+/// Restores `thing`'s throw to its own speed from where it has got to.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/let_go_throw(atom/movable/thing)
+ var/orig_speed = held_throws[thing]
+ held_throws -= thing
+ if(orig_speed && thing.throwing)
+ pace_throw(thing, orig_speed)
+
+/// `thing`'s throw is landing inside the slow-mo: put its real speed back for impact, and let a plain floor item go.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/finish_throw(atom/movable/thing, datum/thrownthing/flight)
+ var/orig_speed = held_throws[thing]
+ if(!orig_speed)
+ return
+ held_throws -= thing
+ if(flight)
+ pace_throw(thing, orig_speed, flight)
+ if(!frozen_things[thing])
+ if(!surging[thing])
+ UnregisterSignal(thing, COMSIG_QDELETING)
+ return
+ if(held_grenades[thing])
+ escape_the_negative_zone(thing)
+ return
+ if(!held_mobs[thing] && !held_shots[thing] && !held_mechs[thing] && !held_turrets[thing] && !(thing in frozen_structures))
+ unfreeze_atom(thing)
+
+/// Forgets a held thing that got deleted.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/held_gone(atom/movable/thing)
+ SIGNAL_HANDLER
+ held_shots -= thing
+ user_shots -= thing
+ held_mobs -= thing
+ held_throws -= thing
+ held_mechs -= thing
+ held_turrets -= thing
+ held_grenades -= thing
+ boss_holds -= thing
+ surging -= thing
+ slowed_tags -= thing
+ tinted -= thing
+ if(tint_timers[thing])
+ deltimer(tint_timers[thing])
+ tint_timers -= thing
+ own_scales -= thing
+ frozen_structures -= thing
+ blood_holders -= thing
+ frozen_things -= thing
+ GLOB.cyberware_time_dilated -= thing
+
+// ----- the clock -----
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/process()
+ return PROCESS_KILL
+
+/// Every 0.2 s: end if a player came in, push back the timers of everything held, let bosses go.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/tick()
+ if(QDELETED(host) || cyberware_time_stop_witnessed(host))
+ if(sandy_session_field_cut(src)) // a shared slow-mo ends for everyone in it (ware_sandy_timestop_shared.dm)
+ return
+ replay?.cancel() // cut short: nothing replays
+ if(!QDELETED(stopper))
+ qdel(stopper) // takes this field with it
+ return
+ sandy_session_check_touch(src) // a crewmate's slow-mo touching this one joins it (ware_sandy_timestop_shared.dm)
+ if(QDELETED(src))
+ return
+ var/elapsed = world.time - last_tick
+ last_tick = world.time
+ for(var/mob/living/victim as anything in held_mobs)
+ var/lost = elapsed * (1 - scale_for(victim)) // a faster surger's is negative: its deadlines come sooner
+ if(lost)
+ push_deadlines(victim, lost)
+ var/push = elapsed * (1 - time_scale)
+ if(push > 0)
+ push_machine_deadlines(push)
+ check_surgers()
+ let_go_own_ride()
+ for(var/mob/living/boss as anything in boss_holds.Copy())
+ if(world.time < boss_holds[boss])
+ continue
+ unfreeze_atom(boss)
+ released[boss] = TRUE
+ for(var/obj/effect/holder as anything in blood_holders)
+ tint_blood_bits(holder)
+ senses?.refresh_weather()
+ cover_tick() // ware_sandy_timestop_cover.dm
+
+/// Whether `thing` is what the user is riding or piloting: a vehicle with them aboard, or anything they're buckled to.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/own_ride(atom/movable/thing)
+ if(!ismob(host) || !istype(thing))
+ return FALSE
+ var/mob/living/user = host
+ if(istype(thing, /obj/vehicle))
+ var/obj/vehicle/ride = thing
+ if(ride.is_occupant(user))
+ return TRUE
+ return isliving(user) && user.buckled == thing
+
+/// The user climbed into a mech or onto a vehicle the field already holds: it runs at full speed from now on.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/let_go_own_ride()
+ if(!isliving(host))
+ return
+ var/mob/living/user = host
+ for(var/atom/movable/ride in list(user.loc, user.buckled))
+ if(frozen_things[ride] && own_ride(ride))
+ unfreeze_atom(ride)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/into_the_negative_zone(atom/A)
+ tinted[A] = TRUE
+ replay?.resample(A) // recorded without the tint from here on
+ var/wait = ring_wait(A)
+ if(wait > 0)
+ if(!tint_timers[A])
+ tint_timers[A] = addtimer(CALLBACK(src, PROC_REF(ring_reached), A), wait, TIMER_STOPPABLE)
+ return
+ cyberware_time_tint_on(A)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/escape_the_negative_zone(atom/A)
+ if(tint_timers[A])
+ deltimer(tint_timers[A])
+ tint_timers -= A
+ if(!tinted[A])
+ return
+ tinted -= A
+ cyberware_time_tint_off(A)
+
+/// Drips and trail pieces are blood drawn in a blood decal's vis_contents with RESET_COLOR, and a gut strand (a beam)
+/// draws its picture from one shared object in each segment's vis_contents: the holder's tint never reaches them. Each
+/// is tinted on its own like the holder, and let go with the field. Blood that drips onto a tinted decal later is
+/// picked up by tick().
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/tint_blood_bits(obj/effect/holder)
+ blood_holders[holder] = TRUE // a new drip or trail has no bits yet: they come as more blood lands on it
+ if(!length(holder.vis_contents))
+ return
+ for(var/obj/effect/bit in holder.vis_contents)
+ if(!istype(bit, /obj/effect/decal/cleanable/blood) && !istype(bit, /obj/effect/ebeam))
+ continue
+ if(frozen_things[bit] || QDELETED(bit))
+ continue
+ GLOB.cyberware_time_dilated[bit] = src
+ frozen_things[bit] = TRUE
+ frozen_structures += bit
+ RegisterSignal(bit, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+ tinted[bit] = TRUE // not recorded: the replay draws the decal, not what is in its vis_contents
+ var/wait = ring_wait(bit)
+ if(wait > 0)
+ tint_timers[bit] = addtimer(CALLBACK(src, PROC_REF(ring_reached), bit), wait, TIMER_STOPPABLE)
+ else
+ cyberware_time_tint_on(bit)
+
+/// The ring starts rolling out from `center` to `reach` tiles over `time`: everything it hasn't reached yet loses
+/// its tint until the ring's front passes it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sweep_ring(turf/center, reach, time)
+ ring_center = center
+ ring_start = world.time
+ ring_time = time
+ ring_reach = reach
+ for(var/atom/movable/thing as anything in tinted)
+ if(tint_timers[thing])
+ continue
+ var/wait = ring_wait(thing)
+ if(wait <= 0)
+ continue
+ cyberware_time_tint_off(thing)
+ tint_timers[thing] = addtimer(CALLBACK(src, PROC_REF(ring_reached), thing), wait, TIMER_STOPPABLE)
+
+/// How long until the rolling ring's front reaches `thing`, or 0 if it already has. The ring grows with a sine
+/// ease-out (cyberware_time_ring).
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/ring_wait(atom/thing)
+ if(!ring_center)
+ return 0
+ var/turf/spot = get_turf(thing)
+ if(!spot || spot.z != ring_center.z)
+ return 0
+ var/dist = sqrt((spot.x - ring_center.x) ** 2 + (spot.y - ring_center.y) ** 2)
+ if(dist > ring_reach) // past the ring's own size the front keeps rolling out at SANDY_STOP_RING_TAIL a tile, not all at once
+ return max(ring_start + ring_time + (dist - ring_reach) * SANDY_STOP_RING_TAIL - world.time, 0)
+ if(world.time >= ring_start + ring_time)
+ return 0
+ var/reached = clamp((dist - 0.2) / max(ring_reach - 0.2, 0.1), 0, 1)
+ return ring_start + ring_time * arcsin(reached) / 90 - world.time
+
+/// The ring's front got to `thing`: on with its tint, if it still wants it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/ring_reached(atom/movable/thing)
+ tint_timers -= thing
+ if(QDELETED(thing) || !tinted[thing])
+ return
+ cyberware_time_tint_on(thing)
+
+// ----- finisher rigs -----
+
+/// The user's edge glow is on their body, which a finisher rig hides while posed pictures of it stand in its place
+/// (chrome_puppet_rig.dm, mantis_rig.dm). Each picture of the user gets a solid copy in the glow's colour, a pixel
+/// bigger, drawn under all of the user's pictures: together they show as one rim round the whole posed body.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/glow_rig_picture(obj/effect/picture)
+ var/obj/effect/abstract/sandy_rig_glow/glow = rig_glows[picture]
+ if(glow)
+ glow.copy_overlays_of(picture) // redrawn (the blade rig's body piece takes the bearer's look again)
+ return
+ glow = new(null)
+ glow.copy_overlays_of(picture)
+ if(istype(picture, /obj/effect/abstract/mantis_puppet))
+ // The blade rig's pieces stand on other rows (pixel_y, SIDE_MAP): a copy with a layer of its own would sort on
+ // the tile's row, over the piece. Each is drawn under its own piece instead.
+ glow.vis_flags |= VIS_UNDERLAY
+ else
+ glow.layer = picture.layer - 0.05
+ picture.vis_contents += glow
+ rig_glows[picture] = glow
+ RegisterSignal(picture, COMSIG_QDELETING, PROC_REF(rig_picture_gone))
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/drop_rig_glow(obj/effect/picture)
+ var/obj/effect/abstract/sandy_rig_glow/glow = rig_glows[picture]
+ rig_glows -= picture
+ UnregisterSignal(picture, COMSIG_QDELETING)
+ if(glow)
+ picture.vis_contents -= glow
+ qdel(glow)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/rig_picture_gone(obj/effect/picture)
+ SIGNAL_HANDLER
+ drop_rig_glow(picture)
+
+/// Tints `thing` (a rig picture, a muzzle flash in vis_contents) as looks-only, let go when the field ends.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/take_looks(atom/movable/thing)
+ if(frozen_things[thing] || QDELETED(thing))
+ return
+ GLOB.cyberware_time_dilated[thing] = src
+ frozen_things[thing] = TRUE
+ frozen_structures += thing // looks only
+ RegisterSignal(thing, COMSIG_QDELETING, PROC_REF(held_gone), override = TRUE)
+ into_the_negative_zone(thing)
+
+/// A rig picture of a body the field tints: tinted like it, and let go with the field.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/take_rig_picture(obj/effect/picture)
+ take_looks(picture)
+
+/// The solid copy under one of the user's rig pictures. It takes the picture's icon, facing and turn.
+/obj/effect/abstract/sandy_rig_glow
+ name = ""
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ appearance_flags = RESET_COLOR | PIXEL_SCALE
+ vis_flags = VIS_INHERIT_ICON | VIS_INHERIT_ICON_STATE | VIS_INHERIT_DIR | VIS_INHERIT_PLANE
+ color = list(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.82, 0.353, 1, 0.588, 0)
+
+/obj/effect/abstract/sandy_rig_glow/Initialize(mapload)
+ . = ..()
+ add_filter("sandy_rig_glow", 1, outline_filter(1, "#5AFF96D2"))
+
+/// A picture drawn from overlays (the blade rig's body piece is a copy of the bearer's whole look) has little or no
+/// icon of its own to inherit: the copy takes its overlays too, so it is the whole figure's shape.
+/obj/effect/abstract/sandy_rig_glow/proc/copy_overlays_of(obj/effect/picture)
+ overlays = picture.overlays.Copy()
+ underlays = picture.underlays.Copy()
+
+/**
+ * A finisher rig stood up `picture`, a posed piece of `body` (or a loose picture of the move's, like the victim's
+ * blood spraying). In a Sandevistan slow-mo it looks like the body it stands for: the user's carry the user's edge
+ * glow, a held body's are tinted with the world.
+ */
+/proc/cyberware_time_rig_picture(obj/effect/picture, mob/living/body)
+ if(!length(GLOB.cyberware_time_fields) || QDELETED(picture) || isnull(body))
+ return
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field.host == body)
+ field.glow_rig_picture(picture)
+ return
+ if(field.tinted[body])
+ field.take_rig_picture(picture)
+ return
+
+// =========================================================================
+// THE WINDOW'S SIDE
+// =========================================================================
+
+/datum/status_effect/cyberware_cascade_window
+ /// How fast the world runs in slow-mo, if nobody else is near when the window opens. Copied from the lattice.
+ var/dilation_scale = 0.1
+ /// How much faster than normal the bearer runs: sets surging mobs' relative rates in each other's fields.
+ var/time_multiplier = 10
+ /// How long the window runs when it slows the world. Copied from the lattice; 0 keeps the plain length.
+ var/slowmo_duration = 0
+ /// world.time a plain surge from the same start would have ended: a slow-mo a player cuts short carries on as a
+ /// plain surge no longer than this.
+ var/plain_end = 0
+ /// The running dilation, if any.
+ var/obj/effect/timestop/sandevistan/time_stop
+ /// world.time the window closes on its own, before any hold.
+ var/natural_end = 0
+ /// The slow-mo is held for an execution in progress until this world.time at most (slowmo_time_up()). 0 when not holding.
+ var/hold_until = 0
+ /// This surge's one hold is used.
+ var/hold_spent = FALSE
+ var/hold_timer
+ /// The held move is over: the slow-mo ends at this world.time (SANDY_STOP_HOLD_TAIL). 0 while it runs.
+ var/tail_until = 0
+
+/// Slows the world for the whole window if the bearer is a player and nobody else is near. Called as the window
+/// opens, while `duration` is still its length.
+/datum/status_effect/cyberware_cascade_window/proc/try_time_stop()
+ cyberware_surge_frees(owner, time_multiplier) // anyone's surge runs at its own rate in someone else's field
+ if(dilation_scale <= 0 || dilation_scale >= 1 || duration <= 0 || !owner.ckey || time_stop)
+ return FALSE
+ if(cyberware_time_stop_witnessed(owner))
+ return FALSE
+ if(sandy_session_bars(owner)) // under a replay, or beside a crewmate's slow-mo too far gone to join (ware_sandy_timestop_shared.dm)
+ return FALSE
+ var/turf/here = get_turf(owner)
+ if(!here)
+ return FALSE
+ plain_end = world.time + duration
+ duration = max(duration, slowmo_duration) // the slow-mo runs longer than the plain surge
+ natural_end = world.time + duration
+ time_stop = new(here, SANDY_STOP_FIELD_RANGE, duration, list(owner), TRUE, TRUE, dilation_scale, time_multiplier)
+ if(QDELETED(time_stop))
+ time_stop = null
+ duration = plain_end - world.time // no slow-mo: a plain surge's length
+ natural_end = plain_end
+ return FALSE
+ RegisterSignal(time_stop, COMSIG_QDELETING, PROC_REF(time_stop_over))
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = cyberware_bearer_lattice(owner)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = time_stop.chronofield
+ if(lattice)
+ lattice.roll_stop_ring()
+ field?.sweep_ring(here, lattice.stop_ring_scale, lattice.ring_time)
+ owner.remove_client_colour(id) // the user sees the slowed world as it is
+ owner.add_filter(SANDY_STOP_OUTLINE, 2, outline_filter(1, "#5AFF96D2"))
+ if(field)
+ sandy_session_check_touch(field, src) // a crewmate's slow-mo this touches becomes one with it (ware_sandy_timestop_shared.dm)
+ sandy_sound_sync() // ware_sandy_sound.dm
+ return TRUE
+
+/**
+ * The slow-mo's time is up, or the user pressed the surge again. If the user is in the middle of an execution or a
+ * finisher, the slow-mo holds until the move is over (once a surge, at most SANDY_STOP_HOLD_MAX past now), so the
+ * move plays out inside it and its replay shows it. Otherwise the window closes now, and the slow-mo with it.
+ */
+/datum/status_effect/cyberware_cascade_window/proc/slowmo_time_up()
+ if(hold_until)
+ return // already holding: it ends when the move does
+ if(time_stop && !hold_spent && sandy_session_mid_move(src)) // or a crewmate's, at a shared slow-mo's end (ware_sandy_timestop_shared.dm)
+ hold_spent = TRUE
+ hold_until = world.time + SANDY_STOP_HOLD_MAX
+ duration = max(duration, hold_until + world.tick_lag) // the window outlasts the hold; hold_check() closes it
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = time_stop.chronofield
+ if(field)
+ field.ends_at = hold_until
+ var/datum/sandy_session/session = GLOB.sandy_session_of[owner]
+ session?.repace() // every member's field holds with it
+ session?.hold_for_moves() // and a member out of time who is the one mid-move finishes it at its own speed
+ hold_timer = addtimer(CALLBACK(src, PROC_REF(hold_check)), world.tick_lag, TIMER_LOOP | TIMER_STOPPABLE | TIMER_DELETE_ME)
+ return
+ qdel(src)
+
+/// Every tick of a hold: the move is over, so the window (and the slow-mo) closes. At the cap the move is still
+/// going: the slow-mo ends without a replay, rather than the replay's hold cutting the move short.
+/datum/status_effect/cyberware_cascade_window/proc/hold_check()
+ if(QDELETED(owner) || !time_stop)
+ qdel(src)
+ return
+ if(sandy_session_mid_move(src))
+ tail_until = 0
+ if(world.time < hold_until)
+ return
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = time_stop.chronofield
+ if(!sandy_session_others_active(owner)) // a shared slow-mo goes on, and its replay with it
+ field?.replay?.cancel()
+ qdel(src)
+ return
+ if(!tail_until)
+ tail_until = world.time + SANDY_STOP_HOLD_TAIL
+ duration = max(duration, tail_until + world.tick_lag)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = time_stop.chronofield
+ if(field)
+ field.ends_at = max(field.ends_at, tail_until)
+ if(world.time < tail_until)
+ return
+ qdel(src)
+
+/// Signal proc for [COMSIG_QDELETING] on the dilation when the window didn't end it (a player came near): time runs
+/// normally and the rest of the window carries on as an ordinary surge, in its own colour.
+/datum/status_effect/cyberware_cascade_window/proc/time_stop_over(datum/source)
+ SIGNAL_HANDLER
+ time_stop = null
+ sandy_sound_sync() // ware_sandy_sound.dm
+ if(QDELETED(owner))
+ return
+ stop_hold()
+ owner.remove_filter(SANDY_STOP_OUTLINE)
+ sandy_release_flash(owner)
+ var/ends = min(natural_end, plain_end) // a plain surge's length: the slow-mo's extra time goes with the slow-mo
+ if(world.time >= ends)
+ QDEL_IN(src, 0) // past where a plain surge would have ended (or the window's own end, during a hold)
+ return
+ duration = ends
+ owner.add_client_colour(colour_type, id)
+ refresh_perks() // the rest of the window is an ordinary surge
+
+/datum/status_effect/cyberware_cascade_window/proc/stop_hold()
+ deltimer(hold_timer)
+ hold_timer = null
+ hold_until = 0
+ tail_until = 0
+
+/// Ends the dilation early (the window is closing).
+/datum/status_effect/cyberware_cascade_window/proc/end_time_stop()
+ if(sandy_session_window_ends(src)) // a shared slow-mo decides (ware_sandy_timestop_shared.dm)
+ return
+ stop_hold()
+ if(!time_stop)
+ return
+ UnregisterSignal(time_stop, COMSIG_QDELETING)
+ QDEL_NULL(time_stop)
+ sandy_sound_sync() // ware_sandy_sound.dm
+ if(!QDELETED(owner))
+ owner.remove_filter(SANDY_STOP_OUTLINE)
+ sandy_release_flash(owner)
+
+/// A pale green flash on the user's screen as the world speeds back up.
+/proc/sandy_release_flash(mob/living/user)
+ user.overlay_fullscreen(SANDY_STOP_FLASH, /atom/movable/screen/fullscreen/flash/sandy_release)
+ user.clear_fullscreen(SANDY_STOP_FLASH, 0.22 SECONDS)
+
+/atom/movable/screen/fullscreen/flash/sandy_release
+ color = "#E1FFEB"
+ alpha = 140
+
+/// The afterimage left while time is dilated, laid and coloured like the rest of the trail (cyberware_cascade_window/on_move()).
+/// Its colour matrix keeps it out of the world's tint.
+/obj/effect/temp_visual/decoy/fading/cascade/stopped
+
+// =========================================================================
+// CLOCKS THAT RUN SLOW
+// =========================================================================
+
+/obj/item/gun
+ /// world.time the current burst began, pushed back while the shooter is slowed (cyberware time dilation).
+ var/cyberware_burst_start = 0
+ /// The gap between the current burst's shots, in the shooter's own time.
+ var/cyberware_burst_gap = 0
+
+/datum/component/ranged_attacks
+ /// world.time the current burst began, pushed back while the mob is slowed (cyberware time dilation).
+ var/cyberware_burst_start = 0
+
+/// One shot of a burst (`index` 1 is the second shot), fired when the mob's own clock gets there.
+/datum/component/ranged_attacks/proc/cyberware_burst_shot(mob/living/basic/firer, atom/target, modifiers, index)
+ if(QDELETED(firer))
+ return
+ var/wait = cyberware_burst_wait(firer, cyberware_burst_start, burst_intervals, index)
+ if(wait > 0)
+ addtimer(CALLBACK(src, PROC_REF(cyberware_burst_shot), firer, target, modifiers, index), wait, TIMER_DELETE_ME)
+ return
+ async_fire_ranged_attack(firer, target, modifiers)
+
+/obj/item/grenade
+ /// world.time the fuse runs out, pushed back while the grenade sits in a dilation field. 0 when not lit.
+ var/cyberware_fuse_at = 0
+
+/// Whether `thing` is a grenade with its fuse burning.
+/proc/cyberware_lit_grenade(atom/thing)
+ if(!istype(thing, /obj/item/grenade))
+ return FALSE
+ var/obj/item/grenade/bomb = thing
+ return bomb.active && bomb.cyberware_fuse_at
+
+/obj/item/grenade/arm_grenade(mob/user, delayoverride, msg = TRUE, volume = 60)
+ cyberware_fuse_at = world.time + (isnull(delayoverride) ? det_time : delayoverride)
+ . = ..()
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = cyberware_time_field(src)
+ field?.freeze_atom(src)
+
+/// The fuse timer ran out: go off, unless the grenade's own clock is still behind.
+/obj/item/grenade/proc/cyberware_fuse_done()
+ if(!cyberware_fuse_at)
+ return
+ var/wait = cyberware_fuse_at + cyberware_time_lag(src) - world.time
+ if(wait >= world.tick_lag)
+ addtimer(CALLBACK(src, PROC_REF(cyberware_fuse_done)), max(wait, world.tick_lag), TIMER_DELETE_ME)
+ return
+ cyberware_fuse_at = 0
+ detonate()
+
+#undef SANDY_STOP_WITNESS_RANGE
+#undef SANDY_STOP_FIELD_RANGE
+#undef SANDY_STOP_RING_TAIL
+#undef SANDY_STOP_BOSS_HOLD
+#undef SANDY_STOP_MAX_RELATIVE
+#undef SANDY_STOP_SAME_RATE
+#undef SANDY_STOP_OUTLINE
+#undef SANDY_STOP_FLASH
+#undef SANDY_STOP_TINT
+#undef SANDY_STOP_HOLD_MAX
+#undef SANDY_STOP_HOLD_TAIL
diff --git a/voidcrew/modules/cyberware/ware_sandy_timestop_cover.dm b/voidcrew/modules/cyberware/ware_sandy_timestop_cover.dm
new file mode 100644
index 00000000000..b4fa6745a64
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_timestop_cover.dm
@@ -0,0 +1,184 @@
+/**
+ * # How much of the world the Cascade slow-mo covers
+ *
+ * Additions to the slow-mo field in ware_sandy_timestop.dm (this file is included after it, so its procs chain onto
+ * that file's):
+ *
+ * - Its light. The tint sits on bodies, items, turfs and decals, but a room's coloured light is drawn on the lighting
+ * plane, which multiplies over all of them: a purple club room stayed purple under the wash. While the slow-mo runs,
+ * the user's own lighting plane (and that of any crewmate the field holds) is drawn in grey, so the slowed world
+ * reads the same under any light. This is a filter on that player's own plane masters: nobody else's screen changes.
+ * Anyone else looking on (a ghost, a player beyond the witness range) sees the per-atom tint under the room's own
+ * light, as before.
+ * - Its reach. The field is SANDY_STOP_FIELD_RANGE (11) tiles round the user: a 19x15 view with two columns and four
+ * rows to spare. It also takes the rest of the room the user stands in, out to SANDY_COVER_ROOM_REACH tiles (indoor
+ * areas only: an open planet is one huge area), when the slow-mo starts and whenever the user walks into another
+ * room. A wide room is slowed and tinted whole, not cut off at a moving edge.
+ * - Its edge. Ground the field moves onto after the ring has rolled out fades into the tint over SANDY_COVER_FADE
+ * instead of switching, so the front of a moving field doesn't flicker.
+ * - Never another player. A player outside the user's crew is never held, even in a room the field takes past the
+ * witness range (a player within it ends the slow-mo, ware_sandy_timestop.dm).
+ * - Clocks of the mob's own. A mob that keeps its attack and move deadlines in its own vars (the kingpin's crew,
+ * bounty_kingpin.dm) pushes them back in cyberware_push_clocks(), which the field calls with every push.
+ */
+
+/// How far the field takes the room its user stands in, in tiles.
+#define SANDY_COVER_ROOM_REACH 16
+/// How long ground the field moves onto takes to fade into the tint.
+#define SANDY_COVER_FADE (0.4 SECONDS)
+/// Filter name of the slow-mo's grey light on a player's lighting plane.
+#define SANDY_COVER_LIGHT "sandy_slowmo_light"
+/// The field's ground turfs taken per tick when it takes a room, so a big room doesn't land in one tick.
+#define SANDY_COVER_ROOM_BATCH 120
+
+/// The slow-mo's light: every light drawn as grey of the same strength, its colour gone.
+/proc/sandy_slowmo_light_matrix()
+ var/static/list/grey = list(0.4,0.4,0.4,0, 0.4,0.4,0.4,0, 0.4,0.4,0.4,0, 0,0,0,1, 0,0,0,0)
+ return grey
+
+/// Draws `viewer`'s light in grey (`on`) or in its own colours again. Only `viewer`'s own screen changes.
+/proc/sandy_slowmo_light(mob/viewer, on)
+ var/datum/hud/hud = viewer?.hud_used
+ if(!hud)
+ return
+ for(var/atom/movable/screen/plane_master/plate as anything in hud.get_true_plane_masters(RENDER_PLANE_LIGHTING))
+ if(!on)
+ plate.remove_filter(SANDY_COVER_LIGHT)
+ else if(!plate.get_filter(SANDY_COVER_LIGHT))
+ plate.add_filter(SANDY_COVER_LIGHT, 5, color_matrix_filter(sandy_slowmo_light_matrix())) // after the light cutoffs (3, 4)
+
+/// How far `body` walks per step without the slow-mo's own drag on it: its move delay as its own clock counts it.
+/proc/cyberware_undilated_slowdown(mob/living/body)
+ var/datum/movespeed_modifier/dilation = LAZYACCESS(body.movespeed_modification, "[/datum/movespeed_modifier/cyberware_dilation]")
+ return body.cached_multiplicative_slowdown - (dilation ? dilation.multiplicative_slowdown : 0)
+
+/// A slow-mo field took `push` deciseconds from this mob: deadlines it keeps in its own vars move back by as much.
+/// Only those that haven't passed yet. Negative `push` (a faster surger) brings them forward.
+/mob/living/proc/cyberware_push_clocks(push)
+ var/datum/component/bounty_chrome/chrome = GetComponent(/datum/component/bounty_chrome) // a chrome bounty's moves (bounty_chrome.dm)
+ chrome?.cyberware_push_clocks(push)
+
+/datum/proximity_monitor/advanced/timestop/sandevistan
+ /// Set once the field has taken its first ground: what it moves onto after that fades in.
+ var/cover_ready = FALSE
+ /// The room the field last took, so it is taken once per visit.
+ var/area/covered_room
+ /// Ground of the room still to take, a batch per tick.
+ var/list/room_queue = list()
+ /// Players whose light this field draws grey, to TRUE.
+ var/list/lit_viewers = list()
+
+/// Whether `thing` is a player body the field must never hold: a ckey outside the user's crew.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_outsider(atom/movable/thing)
+ if(!isliving(thing) || thing == host)
+ return FALSE
+ var/mob/living/body = thing
+ if(!body.ckey)
+ return FALSE
+ var/datum/team/user_crew = isliving(host) ? cyberware_crew_team(host) : null
+ return !user_crew || cyberware_crew_team(body) != user_crew
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/freeze_atom(atom/movable/A)
+ if(cover_outsider(A))
+ return FALSE
+ return ..()
+
+/datum/proximity_monitor/advanced/timestop/sandevistan/freeze_turf(turf/T)
+ var/fade = cover_ready && !tinted[T] && (!ring_center || world.time >= ring_start + ring_time)
+ var/old_colour = T.color
+ . = ..()
+ if(fade && tinted[T] && T.color != old_colour)
+ var/tinted_colour = T.color
+ T.color = old_colour
+ animate(T, color = tinted_colour, time = SANDY_COVER_FADE)
+
+/// Before the field takes its first ground: the user's lattice is about to roll its ring out from here (try_time_stop()),
+/// so what the field takes now waits for the ring's front at once, instead of being tinted, untinted by sweep_ring() and
+/// tinted again a moment later.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_preset_ring(atom/user) // `host` isn't set yet
+ if(!isliving(user))
+ return
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = cyberware_bearer_lattice(user)
+ var/turf/here = get_turf(user)
+ if(!lattice || !here)
+ return
+ ring_center = here
+ ring_start = world.time
+ ring_time = lattice.ring_time
+ ring_reach = lattice.stop_ring_scale
+
+/// The field has its ground: the user's light goes grey, and from here on new ground fades in.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_start()
+ cover_ready = TRUE
+ if(ismob(host))
+ cover_light(host, TRUE)
+
+/// Every tick: the room the user is in, a batch of its ground, and who sees the grey light.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_tick()
+ cover_room()
+ var/taken = 0
+ while(length(room_queue) && taken < SANDY_COVER_ROOM_BATCH)
+ var/turf/ground = room_queue[length(room_queue)]
+ room_queue.len--
+ taken++
+ if(QDELETED(ground) || tinted[ground])
+ continue
+ setup_field_turf(ground)
+ if(QDELETED(src))
+ return
+ for(var/mob/viewer as anything in lit_viewers.Copy())
+ if(QDELETED(viewer) || (viewer != host && !held_mobs[viewer]))
+ cover_light(viewer, FALSE)
+ else if(viewer.client)
+ sandy_slowmo_light(viewer, TRUE) // a reconnect or a new body builds new plane masters
+ for(var/mob/living/held as anything in held_mobs.Copy())
+ if(cover_outsider(held)) // a held body a player from another crew took over: let go
+ unfreeze_atom(held)
+ else if(held.client && !lit_viewers[held])
+ cover_light(held, TRUE)
+
+/// Queues the ground of the room the user stands in, if it is a new one.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_room()
+ var/turf/centre = get_turf(host)
+ var/area/room = centre?.loc
+ if(!room || room == covered_room)
+ return
+ covered_room = room
+ if(room.outdoors || istype(room, /area/space))
+ return
+ var/list/rings = new /list(SANDY_COVER_ROOM_REACH + 1)
+ for(var/turf/ground as anything in RANGE_TURFS(SANDY_COVER_ROOM_REACH, centre))
+ if(ground.loc != room || tinted[ground])
+ continue
+ var/ring = get_dist(ground, centre) + 1
+ if(!rings[ring])
+ rings[ring] = list()
+ rings[ring] += ground
+ // farthest first in the list, nearest last: the queue is taken from its end
+ room_queue.Cut()
+ for(var/ring in length(rings) to 1 step -1)
+ if(rings[ring])
+ room_queue += rings[ring]
+
+/// Draws `viewer`'s light grey (or not) on this field's behalf; another field still drawing it keeps it grey.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_light(mob/viewer, on)
+ if(on)
+ lit_viewers[viewer] = TRUE
+ sandy_slowmo_light(viewer, TRUE)
+ return
+ lit_viewers -= viewer
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/field as anything in GLOB.cyberware_time_fields)
+ if(field != src && field.lit_viewers[viewer])
+ return
+ sandy_slowmo_light(viewer, FALSE)
+
+/// The field is ending: everyone's light gets its colour back.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/cover_end()
+ room_queue.Cut()
+ for(var/mob/viewer as anything in lit_viewers.Copy())
+ cover_light(viewer, FALSE)
+
+#undef SANDY_COVER_ROOM_REACH
+#undef SANDY_COVER_FADE
+#undef SANDY_COVER_LIGHT
+#undef SANDY_COVER_ROOM_BATCH
diff --git a/voidcrew/modules/cyberware/ware_sandy_timestop_shared.dm b/voidcrew/modules/cyberware/ware_sandy_timestop_shared.dm
new file mode 100644
index 00000000000..92997c9a660
--- /dev/null
+++ b/voidcrew/modules/cyberware/ware_sandy_timestop_shared.dm
@@ -0,0 +1,806 @@
+/**
+ * # One slow-mo for a crew
+ *
+ * Crewmates' slow-mos (ware_sandy_timestop.dm) that touch become one: a /datum/sandy_session. A solo slow-mo is a
+ * session of one, and the solo code is that session as it stands; the datum is made the moment a second crewmate's
+ * field touches the first (fields within SANDY_SHARED_TOUCH tiles of each other), on the press or later as they move.
+ *
+ * - Every member keeps its own field, hosted on it: the shared bubble is the union of them, each following its member.
+ * - The world runs at the deepest slow among the members whose own time is left (the "active" ones). An active member
+ * runs at its own multiplier over the world's (relative_rate()): two Cascades at normal speed, a street surger beside
+ * a Cascade at a quarter of it until the Cascade is out.
+ * - A member whose own time is out (or who pressed the surge again) is slowed at the world's pace by its own field
+ * until the last one ends: tinted, no edge glow, still able to act. Its crash waits.
+ * - When the last active member's time is out every field ends at once, and the one recording (the oldest field's)
+ * plays back once. Each member's view follows its own replayed self. Every crash lands after it.
+ * - A player from another crew near any member's field ends it for everyone, with no replay.
+ * - It lasts at most SANDY_SHARED_MAX_LENGTH from the first press: then it ends as if the last member's time ran out.
+ * - The release flash only shows to a member when no replay follows (the cut to the replay is the change of scene).
+ * - When the last active member's time is up while any member is mid-move, the slow-mo holds for it as a solo one does
+ * (sandy_session_mid_move()), so the replay never waits with the world running. A hold may run past
+ * SANDY_SHARED_MAX_LENGTH by its own cap; nobody joins while it holds. A member whose own time was out and who is
+ * the one mid-move runs at its own speed again for the hold, with its edge glow (hold_for_moves()).
+ *
+ * Each member is paced by its own field only: the other members' fields leave it alone (sandy_session_shares()).
+ */
+
+/// Two fields this close (their hosts' distance, in tiles) touch: two SANDY_STOP_FIELD_RANGE (11) radii and the tile between.
+#define SANDY_SHARED_TOUCH 23
+/// Relative rates this close to 1 count as the same speed (SANDY_STOP_SAME_RATE in ware_sandy_timestop.dm).
+#define SANDY_SHARED_SAME_RATE 0.01
+/// A shared slow-mo ends this long after its first member's press, however many crewmates join and extend it.
+#define SANDY_SHARED_MAX_LENGTH (30 SECONDS)
+/// Copies of ware_sandy_replay.dm's and ware_sandy_timestop.dm's defines, which those files undefine at their end.
+#define SANDY_SHARED_RECORDING 1
+#define SANDY_SHARED_PUPPET 1
+#define SANDY_SHARED_HOLD_RANGE 11
+#define SANDY_SHARED_OUTLINE "sandy_time_stop_outline"
+#define SANDY_SHARED_FRAME_X 3
+#define SANDY_SHARED_FRAME_Y 4
+#define SANDY_SHARED_FRAME_Z 5
+
+/// Every shared slow-mo, by member.
+GLOBAL_LIST_EMPTY(sandy_session_of)
+
+/datum/sandy_session
+ /// Every member, to its field's effect.
+ var/list/members = list()
+ /// Members with their own time left, to their window.
+ var/list/active = list()
+ /// Each member's time multiplier and slow-mo depth, from its window.
+ var/list/mults = list()
+ var/list/scales = list()
+ /// Crashes waiting for the replay to end, by member: list(length, stamina).
+ var/list/crashes = list()
+ /// The one recording.
+ var/datum/sandy_replay/replay
+ /// Members' replay views (the recording's own user has the replay's camera), by member.
+ var/list/views = list()
+ /// The fields have ended; the replay plays or is about to.
+ var/ending = FALSE
+ /// The world's pace now, and the multiplier that sets it.
+ var/world_scale = 1
+ var/world_mult = 1
+ /// For tests and recordings: what happened when.
+ var/list/log = list()
+ /// world.time of the first member's press, and how long after it the slow-mo ends at the latest.
+ var/started = 0
+ var/max_length = SANDY_SHARED_MAX_LENGTH
+ /// The cap is ending every member's time at once: no "spent" cue for each.
+ var/capping = FALSE
+
+/datum/sandy_session/Destroy()
+ disband()
+ return ..()
+
+/datum/sandy_session/proc/note(text)
+ log += "[world.time] [text]"
+
+/// The window of `body`'s surge, if any.
+/proc/sandy_session_window(mob/living/body)
+ return body?.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/// The field `effect` runs.
+/proc/sandy_session_field(obj/effect/timestop/sandevistan/effect)
+ return QDELETED(effect) ? null : effect.chronofield
+
+/// Whether `field` (one of a session member's) must leave `thing` alone: it is another member of the same session.
+/proc/sandy_session_shares(datum/proximity_monitor/advanced/timestop/sandevistan/field, atom/thing)
+ if(!length(GLOB.sandy_session_of) || thing == field.host)
+ return FALSE
+ var/datum/sandy_session/session = GLOB.sandy_session_of[thing]
+ return !!session && session == GLOB.sandy_session_of[field.host]
+
+/// Whether the other members of `body`'s session still have time of their own.
+/proc/sandy_session_others_active(mob/living/body)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[body]
+ if(!session)
+ return FALSE
+ for(var/mob/living/member as anything in session.active)
+ if(member != body)
+ return TRUE
+ return FALSE
+
+// =========================================================================
+// JOINING
+// =========================================================================
+
+/// Whether `field` is a player's running slow-mo that a crewmate's can join: its host's window is still slowing the
+/// world (or the host is in a session not yet over), and its recording is still going.
+/proc/sandy_session_joinable(datum/proximity_monitor/advanced/timestop/sandevistan/field, datum/status_effect/cyberware_cascade_window/hint)
+ if(QDELETED(field) || QDELETED(field.stopper) || !isliving(field.host))
+ return FALSE
+ var/mob/living/host = field.host
+ if(!host.ckey)
+ return FALSE
+ var/datum/sandy_session/session = GLOB.sandy_session_of[host]
+ if(session)
+ return !session.ending && !session.holding() && !!session.replay && session.replay.state == SANDY_SHARED_RECORDING && !session.replay.wait_started
+ var/datum/status_effect/cyberware_cascade_window/window = (hint?.owner == host) ? hint : sandy_session_window(host)
+ if(!window || window.time_stop != field.stopper || window.hold_until)
+ return FALSE
+ return !!field.replay && field.replay.state == SANDY_SHARED_RECORDING && !field.replay.wait_started
+
+/**
+ * Whether `body` may not open a slow-mo of its own right now: a replay holds it or is showing on it, or a crewmate's
+ * slow-mo that it could not join reaches it (one in its last hold, or whose replay is about to play or playing). A
+ * second field there would run on through that replay, with its ring, its tint and its user's edge glow in it.
+ */
+/proc/sandy_session_bars(mob/living/body)
+ if(HAS_TRAIT_FROM(body, TRAIT_INCAPACITATED, "sandy_replay") || sandy_replay_showing(body))
+ return TRUE
+ var/turf/here = get_turf(body)
+ var/datum/team/crew = cyberware_crew_team(body)
+ if(!here || !crew)
+ return FALSE
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/other as anything in GLOB.cyberware_time_fields)
+ var/mob/living/host = other.host
+ if(!isliving(host) || host == body || !host.ckey || cyberware_crew_team(host) != crew || sandy_session_joinable(other))
+ continue
+ var/turf/there = get_turf(host)
+ if(there && there.z == here.z && get_dist(here, there) <= SANDY_SHARED_TOUCH)
+ return TRUE
+ for(var/mob/living/other_user as anything in GLOB.sandy_replays)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[other_user]
+ if(!replay || replay.finished || other_user == body || cyberware_crew_team(other_user) != crew)
+ continue
+ if(replay.state == SANDY_SHARED_RECORDING && !replay.wait_started)
+ continue // still recording: joinable, or far enough to be its own
+ var/turf/there = get_turf(other_user)
+ if(there && there.z == here.z && get_dist(here, there) <= SANDY_SHARED_TOUCH)
+ return TRUE
+ return FALSE
+
+/// `field` and `other` are two crewmates' slow-mos that touch.
+/proc/sandy_session_touching(datum/proximity_monitor/advanced/timestop/sandevistan/field, datum/proximity_monitor/advanced/timestop/sandevistan/other)
+ var/turf/here = get_turf(field.host)
+ var/turf/there = get_turf(other.host)
+ if(!here || !there || here.z != there.z || get_dist(here, there) > SANDY_SHARED_TOUCH)
+ return FALSE
+ var/datum/team/crew = cyberware_crew_team(field.host) // ware_pro_combat.dm
+ return !!crew && crew == cyberware_crew_team(other.host)
+
+/**
+ * Called every field tick and when a slow-mo starts: if `field` touches a crewmate's running slow-mo that isn't
+ * already the same session, the two become one. The younger one joins the older one, whose recording is kept.
+ */
+/proc/sandy_session_check_touch(datum/proximity_monitor/advanced/timestop/sandevistan/field, datum/status_effect/cyberware_cascade_window/hint)
+ if(QDELETED(field))
+ return
+ var/datum/sandy_session/capped = GLOB.sandy_session_of[field.host]
+ if(capped && !capped.ending && !capped.holding() && world.time >= capped.started + capped.max_length)
+ capped.cap()
+ return
+ if(length(GLOB.cyberware_time_fields) < 2 || !sandy_session_joinable(field, hint))
+ return
+ var/datum/sandy_session/mine = GLOB.sandy_session_of[field.host]
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/other as anything in GLOB.cyberware_time_fields)
+ if(other == field || !sandy_session_joinable(other))
+ continue
+ var/datum/sandy_session/theirs = GLOB.sandy_session_of[other.host]
+ if(mine && mine == theirs)
+ continue
+ if(!sandy_session_touching(field, other))
+ continue
+ var/datum/sandy_session/older = theirs || sandy_session_of_one(other)
+ var/datum/sandy_session/younger = mine || sandy_session_of_one(field, hint)
+ if(!older || !younger)
+ return
+ if(older.replay.started > younger.replay.started)
+ var/datum/sandy_session/swap = older
+ older = younger
+ younger = swap
+ older.absorb(younger)
+ return // one join a tick
+
+/// A session for a solo slow-mo that's about to be joined.
+/proc/sandy_session_of_one(datum/proximity_monitor/advanced/timestop/sandevistan/field, datum/status_effect/cyberware_cascade_window/hint)
+ var/mob/living/host = field.host
+ var/datum/status_effect/cyberware_cascade_window/window = (hint?.owner == host) ? hint : sandy_session_window(host)
+ if(!window || !field.replay)
+ return null
+ var/datum/sandy_session/session = new
+ session.replay = field.replay
+ session.started = field.replay.started
+ session.add_member(host, window)
+ session.world_scale = field.time_scale
+ session.world_mult = field.user_multiplier
+ session.note("solo [host] becomes a session")
+ return session
+
+/// Takes `host`'s field and window into the session.
+/datum/sandy_session/proc/add_member(mob/living/host, datum/status_effect/cyberware_cascade_window/window)
+ members[host] = window.time_stop
+ active[host] = window
+ mults[host] = window.time_multiplier
+ scales[host] = window.dilation_scale
+ GLOB.sandy_session_of[host] = src
+
+/**
+ * `other`'s members, fields and crashes join this session. Its recording is dropped: what this one hasn't seen in
+ * the new fields is noticed now (standing there from the start if `other` only just began), and the newcomers are
+ * the replay's surgers.
+ */
+/datum/sandy_session/proc/absorb(datum/sandy_session/other)
+ var/fresh = other.replay ? world.time - other.replay.started <= world.tick_lag : FALSE
+ started = min(started, other.started)
+ if(other.replay && other.replay != replay)
+ var/datum/sandy_replay/dropped = other.replay
+ // What the dropped recording had seen and this one hasn't (the gore of the newcomer's kills before they joined)
+ if(replay?.state == SANDY_SHARED_RECORDING)
+ for(var/atom/movable/thing as anything in dropped.tracks)
+ var/datum/sandy_replay_track/seen = dropped.tracks[thing]
+ if(QDELETED(thing) || replay.tracks[thing])
+ continue
+ replay.covering = fresh && !seen.first
+ replay.notice(thing)
+ replay.covering = FALSE
+ other.replay = null
+ dropped.field = null
+ dropped.cancel()
+ for(var/mob/living/member as anything in other.members)
+ members[member] = other.members[member]
+ if(other.active[member])
+ active[member] = other.active[member]
+ mults[member] = other.mults[member]
+ scales[member] = other.scales[member]
+ if(other.crashes[member])
+ crashes[member] = other.crashes[member]
+ GLOB.sandy_session_of[member] = src
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(members[member])
+ if(!field)
+ continue
+ field.replay = replay
+ replay?.sandy_take_field(field, fresh)
+ note("[member] joins ([fresh ? "on the press" : "fields met"])")
+ other.members.Cut()
+ other.active.Cut()
+ other.crashes.Cut()
+ qdel(other)
+ // What another member's field already tints stays tinted: the newcomer's ring only rolls over what is new to the
+ // slow-mo (its ring took the tint off everything it hadn't reached yet, the floor under the first bubble included).
+ for(var/mob/living/member as anything in members)
+ sandy_session_field(members[member])?.sandy_keep_shared_tint(src)
+ // Members only ever run in their own field.
+ for(var/mob/living/member as anything in members)
+ for(var/mob/living/each as anything in members)
+ if(each != member)
+ sandy_session_field(members[each])?.sandy_let_go(member)
+ repace()
+
+/// The world's pace is the deepest slow among the active members: every field runs at it, the active members at
+/// their own rate over it, and the recording's frames follow it.
+/datum/sandy_session/proc/repace()
+ var/deepest = 1
+ var/fastest = 1
+ for(var/mob/living/member as anything in active)
+ if(scales[member] < deepest)
+ deepest = scales[member]
+ fastest = mults[member]
+ if(!length(active))
+ return
+ var/changed = deepest != world_scale
+ world_scale = deepest
+ world_mult = fastest
+ var/ends = world.time
+ for(var/mob/living/member as anything in active)
+ var/datum/status_effect/cyberware_cascade_window/window = active[member]
+ ends = max(ends, window.hold_until || min(window.natural_end, started + max_length))
+ for(var/mob/living/member as anything in members)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(members[member])
+ if(!field)
+ continue
+ field.ends_at = ends
+ field.sandy_set_world_rate(world_scale, world_mult)
+ if(active[member])
+ field.sandy_pace_host(mults[member])
+ if(changed)
+ replay?.sandy_rebase(world_scale)
+ note("world at [world_scale]")
+
+// =========================================================================
+// A MEMBER'S TIME RUNS OUT, AND THE END
+// =========================================================================
+
+/**
+ * Called from the window's end_time_stop(): `window`'s own time is over (it ran out, the bearer pressed the surge
+ * again, or died). TRUE when the session took care of it: the slow-mo goes on for the others, or it was the last one
+ * and everything ends now. FALSE for a solo slow-mo: the window ends it as it always has.
+ */
+/proc/sandy_session_window_ends(datum/status_effect/cyberware_cascade_window/window)
+ var/mob/living/owner = window.owner
+ var/datum/sandy_session/session = owner && GLOB.sandy_session_of[owner]
+ if(!session || session.active[owner] != window)
+ return FALSE
+ session.active -= owner
+ if(length(session.active))
+ session.time_out(owner, window)
+ else
+ session.finish_all(window)
+ return TRUE
+
+/// `member`'s own time is out while others still have theirs: it becomes part of the slowed world.
+/datum/sandy_session/proc/time_out(mob/living/member, datum/status_effect/cyberware_cascade_window/window)
+ window.stop_hold()
+ var/obj/effect/timestop/sandevistan/effect = window.time_stop
+ if(effect)
+ window.UnregisterSignal(effect, COMSIG_QDELETING)
+ deltimer(effect.end_timer) // the session ends it now
+ effect.end_timer = null
+ window.time_stop = null
+ window.sandy_sound_sync() // his slow-mo is over for him (ware_sandy_sound.dm)
+ member.remove_filter(SANDY_SHARED_OUTLINE)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(effect)
+ if(member.stat != DEAD)
+ if(!capping)
+ member.balloon_alert(member, "[sandy_part_balloon_word(member)] spent")
+ field?.sandy_host_joins_world()
+ replay?.surge_over(member) // the replay leaves no trail behind him from here (ware_sandy_replay.dm)
+ note("[member] out of time")
+ repace()
+
+/// Whether a member's window is holding the slow-mo for a move in progress (slowmo_time_up()).
+/datum/sandy_session/proc/holding()
+ for(var/mob/living/member as anything in active)
+ var/datum/status_effect/cyberware_cascade_window/window = active[member]
+ if(window.hold_until)
+ return TRUE
+ return FALSE
+
+/**
+ * Whether `window`'s slow-mo must hold for a move in progress: its owner's, or, when it is the last window of a shared
+ * slow-mo with time left, any member's. Ending then would leave the replay waiting for that move with the world
+ * running at full speed (sandy_replay/proc/field_over()).
+ */
+/proc/sandy_session_mid_move(datum/status_effect/cyberware_cascade_window/window)
+ var/mob/living/owner = window.owner
+ if(sandy_replay_mid_move(owner))
+ return TRUE
+ var/datum/sandy_session/session = GLOB.sandy_session_of[owner]
+ if(!session || session.ending || session.active[owner] != window || length(session.active) > 1)
+ return FALSE
+ for(var/mob/living/member as anything in session.members)
+ if(member != owner && sandy_replay_mid_move(member))
+ return TRUE
+ return FALSE
+
+/**
+ * The slow-mo holds for a move in progress (slowmo_time_up()). A member whose own time was out and who is in the middle
+ * of that move runs at its own speed for the hold, with its edge glow, as the member holding does: held for at the
+ * world's pace, it crawled through the move in a tinted room where nothing else happened, for up to the hold's cap.
+ */
+/datum/sandy_session/proc/hold_for_moves()
+ for(var/mob/living/member as anything in members)
+ if(active[member] || QDELETED(member) || member.stat == DEAD || !sandy_replay_mid_move(member))
+ continue
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(members[member])
+ if(!field)
+ continue
+ field.sandy_host_leaves_world()
+ member.add_filter(SANDY_SHARED_OUTLINE, 2, outline_filter(1, "#5AFF96D2")) // the edge glow try_time_stop() gives
+ note("[member] finishes its move")
+
+/// The last active member's time is out: every field ends now and the recording plays once.
+/datum/sandy_session/proc/finish_all(datum/status_effect/cyberware_cascade_window/last)
+ ending = TRUE
+ last.stop_hold()
+ if(last.time_stop)
+ last.UnregisterSignal(last.time_stop, COMSIG_QDELETING)
+ last.time_stop = null
+ last.sandy_sound_sync() // ware_sandy_sound.dm
+ note("ends; replay [replay ? "plays" : "none"]")
+ var/list/everyone = members.Copy()
+ end_fields(FALSE)
+ if(replay)
+ replay.field_over() // with nothing still moving, the replay is cut to in this same tick
+ // The release flash only where no replay is showing: the cut to it is the change of scene (sandy_replay_showing()).
+ for(var/mob/living/member as anything in everyone)
+ if(!QDELETED(member) && member.stat != DEAD && !sandy_replay_showing(member))
+ sandy_release_flash(member)
+ note("flash [member]")
+ if(!replay && !QDELETED(src))
+ disband()
+
+/// The slow-mo has run SANDY_SHARED_MAX_LENGTH: every member still on its own time is out now, and it ends as when the
+/// last one's time runs out (the one replay, then the crashes).
+/datum/sandy_session/proc/cap()
+ note("capped")
+ capping = TRUE
+ var/list/windows = list()
+ for(var/mob/living/member as anything in active)
+ windows += active[member]
+ var/datum/status_effect/cyberware_cascade_window/last = length(windows) ? windows[length(windows)] : null
+ for(var/datum/status_effect/cyberware_cascade_window/window as anything in windows)
+ if(window != last && !QDELETED(window))
+ qdel(window) // on_remove() -> end_time_stop() -> sandy_session_window_ends(): time_out()
+ // The last one ends it all, or holds first for a member's move in progress, as its time running out would.
+ if(!QDELETED(last))
+ if(last.time_stop)
+ last.slowmo_time_up()
+ else
+ qdel(last)
+ capping = FALSE
+
+/// Ends every member's field. With `flash` each member's screen gets the release flash as the world speeds up.
+/datum/sandy_session/proc/end_fields(flash)
+ for(var/mob/living/member as anything in members)
+ var/obj/effect/timestop/sandevistan/effect = members[member]
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(effect)
+ if(field)
+ field.replay = null // the session hands the recording over once, below
+ var/datum/status_effect/cyberware_cascade_window/window = active[member]
+ if(window && window.time_stop == effect)
+ continue // still running its own time: the window hears its field go (time_stop_over())
+ if(!QDELETED(effect))
+ qdel(effect)
+ if(!QDELETED(member))
+ member.remove_filter(SANDY_SHARED_OUTLINE)
+ if(flash && member.stat != DEAD)
+ sandy_release_flash(member)
+ note("flash [member]")
+ for(var/mob/living/member as anything in active)
+ var/datum/status_effect/cyberware_cascade_window/window = active[member]
+ if(!QDELETED(window.time_stop))
+ qdel(window.time_stop)
+
+/**
+ * A player from another crew came near one of the fields (or a member's body is gone): it all ends now, with no
+ * replay. The members still on their own time carry on as plain surges; the others crash now.
+ */
+/datum/sandy_session/proc/cut_short()
+ note("cut short")
+ ending = TRUE
+ var/datum/sandy_replay/recording = replay
+ replay = null
+ recording?.cancel()
+ end_fields(TRUE) // no replay follows: the members already out of time see the world speed up too
+ disband()
+
+/// Called from a field's tick() when it would end itself (a player came near, or its host is gone). TRUE when the
+/// session took care of it.
+/proc/sandy_session_field_cut(datum/proximity_monitor/advanced/timestop/sandevistan/field)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[field.host]
+ if(!session || session.ending)
+ return FALSE
+ session.cut_short()
+ return TRUE
+
+/// Lets everyone go: crashes that waited land now, views go back, and the session is over.
+/datum/sandy_session/proc/disband()
+ for(var/mob/living/member as anything in views)
+ var/datum/sandy_session_view/view = views[member]
+ view.stop()
+ views.Cut()
+ for(var/mob/living/member as anything in crashes)
+ var/list/crash = crashes[member]
+ if(!QDELETED(member) && member.stat != DEAD && cyberware_bearer_lattice(member) && !sandy_session_window(member))
+ member.apply_status_effect(/datum/status_effect/cyberware_cascade_crash, crash[1], crash[2])
+ crashes.Cut()
+ for(var/mob/living/member as anything in members)
+ if(GLOB.sandy_session_of[member] == src)
+ GLOB.sandy_session_of -= member
+ members.Cut()
+ active.Cut()
+ if(replay)
+ replay = null
+ if(!QDELING(src))
+ qdel(src)
+
+/// Called from sandy_replay_defer_crash(): a member's crash waits for the session's replay. TRUE if it waits.
+/proc/sandy_session_defer_crash(mob/living/user, length, stamina)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[user]
+ if(!session)
+ return FALSE
+ session.crashes[user] = list(length, stamina)
+ return TRUE
+
+/// Called from the replay's finish(): it is over, so the session is too.
+/proc/sandy_session_replay_over(datum/sandy_replay/replay)
+ for(var/mob/living/member as anything in GLOB.sandy_session_of)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[member]
+ if(session.replay != replay)
+ continue
+ if(session.ending)
+ session.note("replay over")
+ session.disband()
+ else
+ session.replay = null // a hold ran past its cap: the slow-mo goes on with nothing to replay
+ return
+
+// =========================================================================
+// THE FIELDS
+// =========================================================================
+
+/// Leaves `member` (another member of the session) alone from now on: its own field paces it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_let_go(mob/living/member)
+ if(GLOB.cyberware_time_dilated[member] == src)
+ var/lag = cyberware_time_lag(member)
+ if(lag > 0)
+ push_deadlines(member, lag)
+ var/list/tags = slowed_tags[member]
+ unfreeze_atom(member)
+ for(var/tag in tags)
+ member.hv_vis_release(tag, 1)
+ if(surging[member])
+ surging -= member
+ UnregisterSignal(member, COMSIG_QDELETING)
+ cyberware_surge_refresh_perks(member)
+
+/// Puts the tint straight back on whatever this field's rolling ring took it off that another field of `session`
+/// already tints.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_keep_shared_tint(datum/sandy_session/session)
+ if(!length(tint_timers))
+ return
+ for(var/atom/thing as anything in tint_timers.Copy())
+ for(var/mob/living/member as anything in session.members)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/other = sandy_session_field(session.members[member])
+ if(!other || other == src || !other.tinted[thing] || other.tint_timers[thing])
+ continue
+ deltimer(tint_timers[thing])
+ tint_timers -= thing
+ if(!QDELETED(thing) && tinted[thing])
+ cyberware_time_tint_on(thing)
+ break
+
+/// Runs this field at the world's new pace: everything it holds, every surger in it at its rate over it.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_set_world_rate(scale, multiplier)
+ if(scale == time_scale && multiplier == user_multiplier)
+ return
+ time_scale = scale
+ user_multiplier = multiplier
+ for(var/mob/living/surger as anything in surging)
+ var/rate = relative_rate(cyberware_surge_multiplier(surger))
+ var/held = GLOB.cyberware_time_dilated[surger] == src
+ if(abs(rate - 1) < SANDY_SHARED_SAME_RATE)
+ if(held)
+ var/lag = cyberware_time_lag(surger)
+ if(lag > 0)
+ push_deadlines(surger, lag)
+ var/list/tags = slowed_tags[surger]
+ unfreeze_atom(surger)
+ for(var/tag in tags)
+ surger.hv_vis_release(tag, 1)
+ else if(held)
+ own_scales[surger] = rate
+ slow_mob(surger)
+ else
+ take_surger(surger, cyberware_surge_multiplier(surger))
+ for(var/mob/living/victim as anything in held_mobs)
+ if(!own_scales[victim])
+ slow_mob(victim)
+ for(var/obj/projectile/shot as anything in held_shots)
+ shot.speed = held_shots[shot] * scale_for(shot)
+ for(var/atom/movable/flier as anything in held_throws)
+ pace_throw(flier, held_throws[flier] * time_scale)
+ senses?.update()
+
+/// The field's own host, still on its own time, at its multiplier over the world's: left alone at the same rate,
+/// held slower (a street surger beside a Cascade) otherwise.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_pace_host(multiplier)
+ var/mob/living/body = host
+ if(!istype(body) || surging[body])
+ return // sandy_set_world_rate() keeps it at its rate
+ if(abs(relative_rate(multiplier) - 1) < SANDY_SHARED_SAME_RATE)
+ return
+ immune -= body
+ stopper?.immune -= body
+ take_surger(body, multiplier)
+
+/// The host's own time is out: from now on it's part of the slowed world, held at the field's pace and tinted, and
+/// its shots are the world's.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_host_joins_world()
+ var/mob/living/body = host
+ if(!istype(body))
+ return
+ if(surging[body])
+ if(GLOB.cyberware_time_dilated[body] == src)
+ unfreeze_atom(body)
+ surging -= body
+ UnregisterSignal(body, COMSIG_QDELETING)
+ immune -= body
+ stopper?.immune -= body
+ UnregisterSignal(body, COMSIG_PROJECTILE_FIRER_BEFORE_FIRE)
+ freeze_atom(body)
+
+/// The host's own time was out and the slow-mo now holds for its move (sandy_session/proc/hold_for_moves()): until the
+/// fields end it runs at its own speed again, out of the tint, and its shots are its own.
+/datum/proximity_monitor/advanced/timestop/sandevistan/proc/sandy_host_leaves_world()
+ var/mob/living/body = host
+ if(!istype(body) || immune[body])
+ return
+ if(GLOB.cyberware_time_dilated[body] == src)
+ var/lag = cyberware_time_lag(body)
+ if(lag > 0)
+ push_deadlines(body, lag)
+ var/list/tags = slowed_tags[body]
+ unfreeze_atom(body)
+ for(var/tag in tags)
+ body.hv_vis_release(tag, 1)
+ immune[body] = TRUE
+ if(stopper)
+ stopper.immune[body] = TRUE
+ RegisterSignal(body, COMSIG_PROJECTILE_FIRER_BEFORE_FIRE, PROC_REF(on_user_fire), override = TRUE)
+
+// =========================================================================
+// THE RECORDING
+// =========================================================================
+
+/// `field` feeds this recording from now on: what stands in it is noticed. With `from_start` (the field only just
+/// began) it was standing there from frame 0. The host is a surger in the replay.
+/datum/sandy_replay/proc/sandy_take_field(datum/proximity_monitor/advanced/timestop/sandevistan/field, from_start)
+ if(state != SANDY_SHARED_RECORDING)
+ return
+ covering = from_start
+ for(var/turf/ground as anything in field.frozen_turfs)
+ for(var/atom/movable/thing as anything in ground)
+ notice(thing)
+ covering = FALSE
+ notice(field.host)
+ var/datum/sandy_replay_track/track = tracks[field.host]
+ if(track && !track.surger)
+ become_surger(track)
+
+/// The world's pace changed: frames go on from here at one a tick of the world as it runs now, so the replay
+/// compresses each stretch by the pace it had.
+/datum/sandy_replay/proc/sandy_rebase(scale)
+ if(state != SANDY_SHARED_RECORDING || wait_started || scale <= 0)
+ return
+ var/exact = frame_exact()
+ clock_frame = round(exact)
+ clock_rate = scale / world.tick_lag
+ clock_rates += list(list(clock_frame, clock_rate))
+ clock_time = world.time - (exact - clock_frame) / clock_rate
+ interval = world.tick_lag / scale
+
+/// The session `replay` is the one recording of, if any.
+/proc/sandy_session_of_replay(datum/sandy_replay/replay)
+ var/datum/sandy_session/session = replay?.user && GLOB.sandy_session_of[replay.user]
+ return session?.replay == replay ? session : null
+
+/// The shared slow-mo's replay `body` watches, if it is a member of one.
+/proc/sandy_session_replay_of(mob/living/body)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[body]
+ return session?.replay
+
+/// The members of `replay`'s shared slow-mo other than its own user, still here; with `watching` only those with a
+/// client (they watch it too).
+/proc/sandy_session_others(datum/sandy_replay/replay, watching = TRUE)
+ . = list()
+ var/datum/sandy_session/session = sandy_session_of_replay(replay)
+ if(!session)
+ return
+ for(var/mob/living/member as anything in session.members)
+ if(member != replay.user && !QDELETED(member) && (!watching || member.client))
+ . += member
+
+/// Whether a member of `replay`'s shared slow-mo other than its user has a client watching.
+/proc/sandy_session_watched(datum/sandy_replay/replay)
+ return length(sandy_session_others(replay)) > 0
+
+/// Called from clean_look(): whether a field of `replay`'s shared slow-mo tints `thing`.
+/proc/sandy_session_tints(datum/sandy_replay/replay, atom/thing)
+ var/datum/sandy_session/session = sandy_session_of_replay(replay)
+ if(!session)
+ return FALSE
+ for(var/mob/living/member as anything in session.members)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(session.members[member])
+ if(field?.tinted[thing])
+ return TRUE
+ return FALSE
+
+/// Called from clean_look(): whether `thing` is a member of `replay`'s shared slow-mo.
+/proc/sandy_session_member(datum/sandy_replay/replay, atom/thing)
+ var/datum/sandy_session/session = sandy_session_of_replay(replay)
+ return !!session && ismob(thing) && (thing in session.members)
+
+/// Called from hear(): a sound outside the recording's own field may be inside another member's.
+/proc/sandy_session_hears(datum/sandy_replay/replay, turf/source)
+ var/datum/sandy_session/session = GLOB.sandy_session_of[replay.user]
+ if(!session || session.replay != replay)
+ return FALSE
+ for(var/mob/living/member as anything in session.members)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = sandy_session_field(session.members[member])
+ var/turf/centre = get_turf(member)
+ if(field && centre && centre.z == source.z && get_dist(centre, source) <= field.current_range)
+ return TRUE
+ return FALSE
+
+/// Called from hold_nearby(): everyone near every member holds still too.
+/datum/sandy_replay/proc/sandy_hold_members()
+ var/datum/sandy_session/session = GLOB.sandy_session_of[user]
+ if(!session || session.replay != src)
+ return
+ for(var/mob/living/member as anything in session.members)
+ if(member == user || QDELETED(member))
+ continue
+ lock(member)
+ var/turf/here = get_turf(member)
+ if(!here)
+ continue
+ for(var/atom/movable/found as anything in SSspatial_grid.orthogonal_range_search(here, SPATIAL_GRID_CONTENTS_TYPE_HEARING, SANDY_SHARED_HOLD_RANGE))
+ if(isliving(found))
+ lock(found)
+ var/obj/vehicle/sealed/mecha/mech = get_atom_on_turf(found, /obj/vehicle/sealed/mecha)
+ if(istype(mech))
+ hold_mech(mech)
+
+/// Called from begin(): every other member watches its own replayed self.
+/datum/sandy_replay/proc/sandy_member_views()
+ var/datum/sandy_session/session = GLOB.sandy_session_of[user]
+ if(!session || session.replay != src)
+ return
+ for(var/mob/living/member as anything in session.members)
+ if(member == user || session.views[member])
+ continue
+ var/datum/sandy_replay_track/track = tracks[member]
+ if(!member.client || member.stat == DEAD || !isturf(member.loc) || track?.mode != SANDY_SHARED_PUPPET)
+ continue
+ var/datum/sandy_session_view/view = new(member, track)
+ session.views[member] = view
+ view.follow()
+
+/// Called from play_frame(): the members' views follow their replayed selves.
+/datum/sandy_replay/proc/sandy_member_follow()
+ var/datum/sandy_session/session = GLOB.sandy_session_of[user]
+ if(!session || session.replay != src)
+ return
+ for(var/mob/living/member as anything in session.views)
+ var/datum/sandy_session_view/view = session.views[member]
+ view.follow()
+
+/// One member's camera for the replay: as the replay's own (sandy_replay/proc/follow()), for someone else.
+/datum/sandy_session_view
+ var/mob/living/viewer
+ var/datum/sandy_replay_track/track
+ var/obj/effect/abstract/sandy_replay_eye/eye
+ var/pixel_x = 0
+ var/pixel_y = 0
+ var/last_cursor = -2
+
+/datum/sandy_session_view/New(mob/living/member, datum/sandy_replay_track/member_track)
+ viewer = member
+ track = member_track
+ eye = new(member.loc)
+ pixel_x = member.client.pixel_x
+ pixel_y = member.client.pixel_y
+ member.reset_perspective(eye)
+
+/datum/sandy_session_view/proc/follow()
+ var/client/screen = viewer?.client
+ if(!eye || !screen || !track || track.cursor < 0 || track.cursor == last_cursor)
+ return
+ last_cursor = track.cursor
+ var/list/frames = track.frames
+ var/at = track.cursor
+ var/turf/spot = frames[at + SANDY_SHARED_FRAME_Z] ? locate(frames[at + SANDY_SHARED_FRAME_X], frames[at + SANDY_SHARED_FRAME_Y], frames[at + SANDY_SHARED_FRAME_Z]) : null
+ if(!spot)
+ return
+ eye.loc = spot
+ var/left = track.glide_until - world.time
+ if(left > 0 && track.glide_time > 0)
+ screen.pixel_x = pixel_x + track.glide_x * left / track.glide_time
+ screen.pixel_y = pixel_y + track.glide_y * left / track.glide_time
+ animate(screen, pixel_x = pixel_x, pixel_y = pixel_y, time = left, flags = ANIMATION_END_NOW)
+ else
+ animate(screen, pixel_x = pixel_x, pixel_y = pixel_y, time = 0, flags = ANIMATION_END_NOW)
+
+/datum/sandy_session_view/proc/stop()
+ var/client/screen = viewer?.client
+ if(screen)
+ animate(screen, pixel_x = pixel_x, pixel_y = pixel_y, time = 0, flags = ANIMATION_END_NOW)
+ if(screen.eye == eye)
+ viewer.reset_perspective()
+ QDEL_NULL(eye)
+ viewer = null
+ track = null
+
+#undef SANDY_SHARED_TOUCH
+#undef SANDY_SHARED_SAME_RATE
+#undef SANDY_SHARED_MAX_LENGTH
+#undef SANDY_SHARED_RECORDING
+#undef SANDY_SHARED_PUPPET
+#undef SANDY_SHARED_HOLD_RANGE
+#undef SANDY_SHARED_OUTLINE
+#undef SANDY_SHARED_FRAME_X
+#undef SANDY_SHARED_FRAME_Y
+#undef SANDY_SHARED_FRAME_Z
diff --git a/voidcrew/modules/gun_feel/gun_feel.dm b/voidcrew/modules/gun_feel/gun_feel.dm
index c11c9ecc74c..811b64ee569 100644
--- a/voidcrew/modules/gun_feel/gun_feel.dm
+++ b/voidcrew/modules/gun_feel/gun_feel.dm
@@ -103,7 +103,9 @@
gun_feel_resolve()
var/angle = gun_feel_fire_angle(user, target)
gun_feel_kick(user, angle)
- if(gun_feel_wants_flash())
+ // An execution's flash is at the barrel, on the head, and while its shooter is drawn aiming the gun isn't at the
+ // hip where this one goes (hyperviolence/visuals/execution_motion.dm, execution_aim.dm)
+ if(gun_feel_wants_flash() && !hv_firing_execution && !hv_aim)
gun_feel_muzzle_flash(user, angle)
/// Direction of the shot in degrees clockwise from north.
diff --git a/voidcrew/modules/gun_feel/muzzle_flash.dm b/voidcrew/modules/gun_feel/muzzle_flash.dm
index cbf101e632b..07025f0e01c 100644
--- a/voidcrew/modules/gun_feel/muzzle_flash.dm
+++ b/voidcrew/modules/gun_feel/muzzle_flash.dm
@@ -118,3 +118,6 @@
if(ismovable(loc))
var/atom/movable/shooter = loc
shooter.vis_contents += src
+ // Made inside the shooter, where a Sandevistan's field sees nothing: its recording takes the turned plume here,
+ // once it is whole, so a replayed shot keeps it (ware_sandy_replay.dm).
+ sandy_replay_made(src)
diff --git a/voidcrew/modules/hyperviolence/_core.dm b/voidcrew/modules/hyperviolence/_core.dm
index 2aafc284d62..02245a4fddf 100644
--- a/voidcrew/modules/hyperviolence/_core.dm
+++ b/voidcrew/modules/hyperviolence/_core.dm
@@ -37,17 +37,24 @@
var/matrix/fallen = matrix(transform)
var/matrix/upright = matrix(transform)
upright.Turn(-angle)
+ // In a Sandevistan field (cyberware/ware_sandy_timestop.dm) it runs slow.
+ var/list/real = cyberware_dilated_steps(src, list(HV_DEATH_THROES_TIME, UPDATE_TRANSFORM_ANIMATION_TIME)) || list(HV_DEATH_THROES_TIME, UPDATE_TRANSFORM_ANIMATION_TIME)
animate(src, transform = upright, time = 0)
- animate(transform = upright, time = HV_DEATH_THROES_TIME)
- animate(transform = fallen, time = UPDATE_TRANSFORM_ANIMATION_TIME, easing = EASE_IN|EASE_OUT)
+ animate(transform = upright, time = real[1])
+ animate(transform = fallen, time = real[2], easing = EASE_IN|EASE_OUT)
// The shudder: sideways offsets that die down, each step relative to the last, ending where it began.
var/static/list/shudder = list(3, -3, 2, -2, 2, -1, 1, 0)
var/step_time = HV_DEATH_THROES_TIME / length(shudder)
+ var/list/shudder_times = list()
+ for(var/i in 1 to length(shudder))
+ shudder_times += step_time
+ var/list/shudder_real = cyberware_dilated_steps(src, shudder_times)
var/offset = 0
for(var/i in 1 to length(shudder))
var/shift = shudder[i] - offset
offset = shudder[i]
+ var/time = shudder_real ? shudder_real[i] : step_time
if(i == 1)
- animate(src, pixel_w = shift, time = step_time, flags = ANIMATION_RELATIVE|ANIMATION_PARALLEL)
+ animate(src, pixel_w = shift, time = time, flags = ANIMATION_RELATIVE|ANIMATION_PARALLEL)
else
- animate(pixel_w = shift, time = step_time, flags = ANIMATION_RELATIVE)
+ animate(pixel_w = shift, time = time, flags = ANIMATION_RELATIVE)
diff --git a/voidcrew/modules/hyperviolence/finishers/finisher.dm b/voidcrew/modules/hyperviolence/finishers/finisher.dm
index bacc17c2aca..f2f6f1e12c3 100644
--- a/voidcrew/modules/hyperviolence/finishers/finisher.dm
+++ b/voidcrew/modules/hyperviolence/finishers/finisher.dm
@@ -387,7 +387,10 @@
user.set_combat_mode(TRUE)
var/old_wound_bonus = weapon.wound_bonus
weapon.wound_bonus += extra_wound_bonus
+ victim.hv_struck_where_aimed = TRUE
weapon.melee_attack_chain(user, victim)
+ if(!QDELETED(victim))
+ victim.hv_struck_where_aimed = FALSE
if(!QDELETED(weapon))
weapon.wound_bonus = old_wound_bonus
if(!QDELETED(user))
@@ -446,6 +449,18 @@
return FALSE
return TRUE
+/mob/living/carbon
+ /// TRUE while a finisher's real blow (real_blow()) is being struck at this body: the blow lands on the part it
+ /// is aimed at instead of going through tg's zone roll for a melee hit (attacked_by() in item_attack.dm).
+ var/hv_struck_where_aimed = FALSE
+
+/mob/living/carbon/get_random_valid_zone(base_zone, base_probability = 80, list/blacklisted_parts, even_weights, bypass_warning)
+ if(hv_struck_where_aimed && base_zone && !even_weights)
+ var/aimed = check_zone(base_zone)
+ if(!(aimed in blacklisted_parts) && get_bodypart(aimed))
+ return aimed
+ return ..()
+
/// The melee weapon a person attacker swings in a finisher: the heaviest one in its hands, or null
/proc/hv_finisher_weapon(mob/living/user)
var/obj/item/best
diff --git a/voidcrew/modules/hyperviolence/finishers/finisher_bar.dm b/voidcrew/modules/hyperviolence/finishers/finisher_bar.dm
index 245fea9f2c5..1f498284fe6 100644
--- a/voidcrew/modules/hyperviolence/finishers/finisher_bar.dm
+++ b/voidcrew/modules/hyperviolence/finishers/finisher_bar.dm
@@ -15,6 +15,9 @@
/// Matches tg's PROGRESSBAR_ANIMATION_TIME: the fade in and out
#define HV_EXEC_BAR_FADE 5
+/// Every execution bar in the world (the Sandevistan replay hides them while it plays).
+GLOBAL_LIST_EMPTY(hv_exec_bars)
+
/obj/effect/abstract/hv_exec_bar
name = "progress"
icon = 'icons/effects/progressbar.dmi'
@@ -46,16 +49,25 @@
// Centred over the top of their sprite, however big it is (a 64px boss is drawn up from its tile, shifted left by half the extra width)
var/list/icon_size = executioner.icon ? get_icon_dimensions(executioner.icon) : list("width" = ICON_SIZE_X, "height" = ICON_SIZE_Y)
pixel_w = executioner.base_pixel_x + (icon_size["width"] - ICON_SIZE_X) / 2
+ // Over the body, where a move is drawing it off its tile (hv_exec_bar_lean())
+ if(executioner.hv_exec_lean)
+ pixel_x = executioner.hv_exec_lean[1]
+ pixel_y = executioner.hv_exec_lean[2]
// Above any do_after bars the executioner already has over themselves
var/list/own_bars = LAZYACCESS(executioner.progressbars, executioner)
rest_z = executioner.base_pixel_y + icon_size["height"] + HV_EXEC_BAR_HEIGHT * length(own_bars)
+ pixel_z = rest_z
alpha = 0
- animate(src, pixel_z = rest_z, alpha = 255, time = HV_EXEC_BAR_FADE, easing = SINE_EASING)
+ animate(src, alpha = 255, time = HV_EXEC_BAR_FADE, easing = SINE_EASING)
RegisterSignal(owner, COMSIG_QDELETING, PROC_REF(on_owner_deleted))
RegisterSignal(owner, COMSIG_MOVABLE_MOVED, PROC_REF(on_owner_moved))
tick()
+ GLOB.hv_exec_bars += src
+ if(sandy_replay_hides_bars_at(get_turf(src))) // cyberware/ware_sandy_replay.dm: no bar shows in a replay
+ invisibility = INVISIBILITY_ABSTRACT
/obj/effect/abstract/hv_exec_bar/Destroy()
+ GLOB.hv_exec_bars -= src
if(update_timer)
deltimer(update_timer)
update_timer = null
@@ -99,6 +111,24 @@
else
finish(FALSE)
+/mob/living
+ /// How far a move's pose draws this body off its tile right now, list(x, y) in pixels: its execution bars stand
+ /// over the body, not over the tile it has leaned off (hv_exec_bar_lean()).
+ var/list/hv_exec_lean
+
+/**
+ * A move draws [executioner]'s body [x], [y] pixels off their tile from here on (a lean over a victim, a lunge): their
+ * execution bars go there with it over [time], and one started while it holds starts there. Without it a bar stood
+ * beside a body bent half a tile over its victim. 0, 0 puts them back over the tile.
+ */
+/proc/hv_exec_bar_lean(mob/living/executioner, x = 0, y = 0, time = 0, easing = SINE_EASING)
+ if(QDELETED(executioner))
+ return
+ executioner.hv_exec_lean = (x || y) ? list(x, y) : null
+ for(var/obj/effect/abstract/hv_exec_bar/bar as anything in GLOB.hv_exec_bars)
+ if(bar.owner == executioner && !bar.ending)
+ animate(bar, pixel_x = x, pixel_y = y, time = time, easing = easing, flags = ANIMATION_PARALLEL)
+
/**
* Puts a bar over [executioner] that fills over [total] deciseconds, seen by everyone who can see them.
* Returns it, for the caller to finish(); null if there is nowhere to put it.
diff --git a/voidcrew/modules/hyperviolence/overlays_exec/executions.dm b/voidcrew/modules/hyperviolence/overlays_exec/executions.dm
index 5547afef33b..3779c8aaadc 100644
--- a/voidcrew/modules/hyperviolence/overlays_exec/executions.dm
+++ b/voidcrew/modules/hyperviolence/overlays_exec/executions.dm
@@ -26,6 +26,9 @@
/obj/item/gun
/// While an execution round is being fired: the damage it has dealt to the victim's head
var/hv_execution_head_damage = 0
+ /// TRUE while an execution round is being fired: the barrel is on the head, so the shot's flash is drawn there
+ /// (visuals/execution_motion.dm) and not at the hip
+ var/hv_firing_execution = FALSE
/obj/item/gun/handle_suicide(mob/living/carbon/human/user, mob/living/carbon/human/target, params, bypass_timer)
if(bypass_timer || !hv_execution_possible(user, target))
@@ -88,7 +91,7 @@
bar.finish(held && !QDELETED(src) && !QDELETED(user) && !QDELETED(target))
if(!held || QDELETED(src) || QDELETED(user) || QDELETED(target))
return
- hv_fire_execution(user, target, params)
+ return hv_fire_execution(user, target, params)
/// do_after check: the shooter still holds the gun to the head of someone who still can't fight back.
/obj/item/gun/proc/hv_execution_holds(mob/living/user, mob/living/target)
@@ -114,11 +117,23 @@
var/burns = chambered.loaded_projectile.damage_type == BURN
hv_execution_head_damage = 0
RegisterSignal(target, COMSIG_MOB_APPLY_DAMAGE, PROC_REF(hv_execution_hit))
+ // The barrel is on the head, so tg's zone roll for the shot can't send the round elsewhere.
+ var/obj/item/ammo_casing/execution_casing = chambered
+ RegisterSignal(execution_casing, COMSIG_CASING_READY_PROJECTILE, PROC_REF(hv_execution_round_ready))
var/normal_multiplier = projectile_damage_multiplier
projectile_damage_multiplier *= HV_EXECUTION_POINT_BLANK_MULT
+ // The flashes tg and gun feel draw for a shot are at the hip, out toward the victim's tile: on the boots of a
+ // body lying with its head at the far end. The execution draws its own, at the barrel.
+ var/hip_flash = execution_casing.firing_effect_type
+ execution_casing.firing_effect_type = null
+ hv_firing_execution = TRUE
// Only the first round of a burst is held to the head; the rest are ordinary shots.
var/fired = process_fire(target, user, TRUE, params, BODY_ZONE_HEAD)
+ hv_firing_execution = FALSE
projectile_damage_multiplier = normal_multiplier
+ if(!QDELETED(execution_casing))
+ execution_casing.firing_effect_type = hip_flash
+ UnregisterSignal(execution_casing, COMSIG_CASING_READY_PROJECTILE)
if(!QDELETED(target))
UnregisterSignal(target, COMSIG_MOB_APPLY_DAMAGE)
if(!fired)
@@ -129,6 +144,17 @@
hv_execution_witnesses(user, target)
return TRUE
+/// Each round (or pellet) the execution casing readies loses its accuracy falloff, so tg's zone roll on
+/// impact (projectile.dm, the one TRAIT_DESIGNATED_TARGET also skips) keeps it on the aimed head. Its
+/// damage, armour and everything after are tg's as usual. It is never drawn: fired with the barrel on the
+/// head it lands the tick it is made, and a Sandevistan replay, which draws every round it saw, showed it as
+/// a tracer lying across the shooter (cyberware/ware_sandy_replay.dm records nothing it can't see).
+/obj/item/gun/proc/hv_execution_round_ready(obj/item/ammo_casing/source, atom/target, mob/living/user, quiet, zone_override, atom/fired_from)
+ SIGNAL_HANDLER
+ if(fired_from == src && source.loaded_projectile)
+ source.loaded_projectile.accuracy_falloff = 0
+ source.loaded_projectile.invisibility = INVISIBILITY_ABSTRACT
+
/// Adds up what this gun's rounds do to the victim's head while an execution round is fired.
/obj/item/gun/proc/hv_execution_hit(mob/living/source, damage, damagetype, def_zone, blocked, wound_bonus, exposed_wound_bonus, sharpness, attack_direction, atom/attacking_item)
SIGNAL_HANDLER
diff --git a/voidcrew/modules/hyperviolence/visuals/_defines.dm b/voidcrew/modules/hyperviolence/visuals/_defines.dm
index a2add2fc026..77c2a4a88be 100644
--- a/voidcrew/modules/hyperviolence/visuals/_defines.dm
+++ b/voidcrew/modules/hyperviolence/visuals/_defines.dm
@@ -143,7 +143,7 @@
// ---- Executions and finishers ----
/// How far the shooter leans in over the victim while the barrel is pressed to the head.
-#define HV_VIS_PRESS_LEAN 4
+#define HV_VIS_PRESS_LEAN 9
/// The still moment at the end of the press, after the trembling stops.
#define HV_VIS_PRESS_PAUSE (0.3 SECONDS)
/// How far off the middle of its tile tg's muzzle flash art sits, toward the way it faces, in pixels.
diff --git a/voidcrew/modules/hyperviolence/visuals/_motion_core.dm b/voidcrew/modules/hyperviolence/visuals/_motion_core.dm
index 9b45e989263..6d994f7415d 100644
--- a/voidcrew/modules/hyperviolence/visuals/_motion_core.dm
+++ b/voidcrew/modules/hyperviolence/visuals/_motion_core.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// Hyperviolence visuals: the animation pass over the gore. Bodies flinch, snap, lurch and limp when
// hit, fall away from the killing blow and twitch after, severed parts and brains tumble through
// the air, blood paints in, drips, spreads and floats, guts slither, and executions and
@@ -202,12 +205,20 @@
/atom/proc/hv_vis_play(tag, list/steps, loop = 1)
if(!length(steps))
return
+ // In a Sandevistan field (cyberware/ware_sandy_timestop.dm) it plays at the field's pace.
+ var/list/times = list()
+ for(var/list/step as anything in steps)
+ times += step[4]
+ var/list/real = cyberware_dilated_steps(src, times, loop, tag)
+ var/started = FALSE
for(var/i in 1 to length(steps))
var/list/step = steps[i]
- if(i == 1)
- animate(src, pixel_w = step[1], pixel_z = step[2], transform = step[3], time = step[4], easing = step[5], loop = loop, tag = tag)
+ var/time = real ? real[i] : step[4]
+ if(!started)
+ animate(src, pixel_w = step[1], pixel_z = step[2], transform = step[3], time = time, easing = step[5], loop = loop, tag = tag)
+ started = TRUE
else
- animate(pixel_w = step[1], pixel_z = step[2], transform = step[3], time = step[4], easing = step[5])
+ animate(pixel_w = step[1], pixel_z = step[2], transform = step[3], time = time, easing = step[5])
/**
* Plays steps that take over this atom's whole animation: each step is list(pixel_y, transform, time,
@@ -218,15 +229,24 @@
/atom/proc/hv_vis_play_over(list/steps)
if(!length(steps))
return
+ // Slowed like hv_vis_play() in a Sandevistan field.
+ var/list/times = list()
+ for(var/list/step as anything in steps)
+ times += step[3]
+ var/list/real = cyberware_dilated_steps(src, times)
+ var/started = FALSE
for(var/i in 1 to length(steps))
var/list/step = steps[i]
- if(i == 1)
- animate(src, pixel_y = step[1], transform = step[2], time = step[3], easing = step[4])
+ var/time = real ? real[i] : step[3]
+ if(!started)
+ animate(src, pixel_y = step[1], transform = step[2], time = time, easing = step[4])
+ started = TRUE
else
- animate(pixel_y = step[1], transform = step[2], time = step[3], easing = step[4])
+ animate(pixel_y = step[1], transform = step[2], time = time, easing = step[4])
/// Eases a named sequence back to where the atom really is over `time`, from wherever it has got to.
/atom/proc/hv_vis_release(tag, time = 2)
+ time = cyberware_dilated_time(src, time)
animate(src, pixel_w = pixel_w, pixel_z = pixel_z, transform = transform, time = time, easing = SINE_EASING, tag = tag)
/// Stops named sequences at once.
@@ -283,16 +303,31 @@
/// A pale flash over the body for the frames of a hit-stop. A colour filter, gone again half a second later.
/mob/living/proc/hv_vis_flash()
+ // A body a finisher rig hides has nothing to flash: its puppets flash (chrome_rig/flash()). A colour animated on the
+ // hidden body was drawn by the client through its hide filter, a near-white corpse until the rig let it go.
+ if(sandy_rig_hidden(src))
+ return
+ var/list/times = hv_vis_flash_times()
+ if(cyberware_time_flash(src, list(0.6,0,0, 0,0.6,0, 0,0,0.6, 0.4,0.4,0.4), times))
+ return // in a Sandevistan slow-mo the flash plays through the slow-mo's tint filter (ware_sandy_timestop.dm)
if(!get_filter(HV_VIS_FLASH_FILTER))
add_filter(HV_VIS_FLASH_FILTER, 10, color_matrix_filter(list(1,0,0, 0,1,0, 0,0,1, 0,0,0)))
var/flash = get_filter(HV_VIS_FLASH_FILTER)
if(!flash)
return
- animate(flash, color = list(0.6,0,0, 0,0.6,0, 0,0,0.6, 0.4,0.4,0.4), time = 0.5, easing = LINEAR_EASING)
- animate(color = list(0.6,0,0, 0,0.6,0, 0,0,0.6, 0.4,0.4,0.4), time = HV_VIS_HITSTOP_TIME, easing = LINEAR_EASING)
- animate(color = list(1,0,0, 0,1,0, 0,0,1, 0,0,0), time = 1, easing = LINEAR_EASING)
+ animate(flash, color = list(0.6,0,0, 0,0.6,0, 0,0,0.6, 0.4,0.4,0.4), time = times[1], easing = LINEAR_EASING)
+ animate(color = list(0.6,0,0, 0,0.6,0, 0,0,0.6, 0.4,0.4,0.4), time = times[2], easing = LINEAR_EASING)
+ animate(color = list(1,0,0, 0,1,0, 0,0,1, 0,0,0), time = times[3], easing = LINEAR_EASING)
addtimer(CALLBACK(src, TYPE_PROC_REF(/datum, remove_filter), HV_VIS_FLASH_FILTER), 0.5 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_DELETE_ME)
+/**
+ * The hit flash's steps (in, hold, out). Never slowed by a Sandevistan slow-mo: the flash is a screen effect, like the
+ * user's afterimages, not part of the slowed world. Stretched by the slow-mo, a flash on a body in it lasted seconds and
+ * read as a glowing corpse.
+ */
+/mob/living/proc/hv_vis_flash_times()
+ return list(0.5, HV_VIS_HITSTOP_TIME, 1)
+
/// The attacker's side of a hit-stop: the blow sticks for a few frames. A melee attacker stays leaned
/// into the victim; a shooter stays rocked back, even with the barrel against them (`shot`).
/mob/living/proc/hv_vis_hold_blow(atom/victim, shot = FALSE)
@@ -385,3 +420,5 @@
/// Holds this mob's named sequences until one of `end_flags` happens or `duration` passes.
/mob/living/proc/hv_vis_hold(list/tags, end_flags, duration)
AddComponent(/datum/component/hv_motion_hold, tags, end_flags, duration)
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence/visuals/blood_motion.dm b/voidcrew/modules/hyperviolence/visuals/blood_motion.dm
index 7133927011e..b5c40fb343a 100644
--- a/voidcrew/modules/hyperviolence/visuals/blood_motion.dm
+++ b/voidcrew/modules/hyperviolence/visuals/blood_motion.dm
@@ -17,7 +17,8 @@ GLOBAL_VAR(hv_vis_spray_origin)
/obj/effect/decal/cleanable/blood
/// Hyperviolence visuals: the paint-in, drip or creep this decal is in the middle of. Keyframes, each
- /// list(transform, alpha, the world.time it is reached, easing); the first is where it starts.
+ /// list(transform, alpha, the world.time it is reached, easing, how long the step takes at normal speed); the
+ /// first is where it starts.
var/list/hv_vis_painting
/**
@@ -28,9 +29,15 @@ GLOBAL_VAR(hv_vis_spray_origin)
/obj/effect/decal/cleanable/blood/proc/hv_vis_paint(list/keys)
var/reached = world.time
var/list/timed = list()
+ // In a Sandevistan field (cyberware/ware_sandy_timestop.dm) the paint runs slow.
+ var/list/times = list()
for(var/list/key as anything in keys)
- reached += key[3]
- timed += list(list(key[1], key[2], reached, key[4]))
+ times += key[3]
+ var/list/real = cyberware_dilated_steps(src, times)
+ for(var/i in 1 to length(keys))
+ var/list/key = keys[i]
+ reached += real ? real[i] : key[3]
+ timed += list(list(key[1], key[2], reached, key[4], key[3]))
hv_vis_painting = timed
hv_vis_paint_on()
@@ -58,6 +65,9 @@ GLOBAL_VAR(hv_vis_spray_origin)
var/matrix/from = behind[1]
var/matrix/current = from.Interpolate(ahead[1], progress)
animate(src, transform = current, alpha = behind[2] + (ahead[2] - behind[2]) * progress, time = 0, tag = HV_VIS_TAG_PAINT)
+ if(now < behind[3]) // held by a frozen moment before it starts
+ animate(transform = current, alpha = behind[2], time = behind[3] - now)
+ now = behind[3]
animate(transform = ahead[1], alpha = ahead[2], time = ahead[3] - now, easing = ahead[4])
for(var/i in heading + 1 to length(keys))
var/list/key = keys[i]
@@ -77,11 +87,15 @@ GLOBAL_VAR(hv_vis_spray_origin)
return (1 - cos(progress * 180)) / 2
return progress
-/// tg has just stopped every animation on the decal: carry on with its paint.
+/// tg has just stopped every animation on the decal: carry on with its paint. A decal a Sandevistan replay is drawing
+/// as it was (cyberware/ware_sandy_replay.dm) takes the colour and the paint on its real look, not on the recorded one.
/obj/effect/decal/cleanable/blood/update_blood_color()
+ var/datum/sandy_replay_track/replayed = sandy_replay_masks ? sandy_replay_unmask(src) : null
. = ..()
if(hv_vis_painting)
hv_vis_paint_on()
+ if(replayed)
+ sandy_replay_remask(replayed)
/mob/living/hv_blood_throw(spray_dir, strength = 3)
var/turf/previous_origin = GLOB.hv_vis_spray_origin
diff --git a/voidcrew/modules/hyperviolence/visuals/death_falls.dm b/voidcrew/modules/hyperviolence/visuals/death_falls.dm
index 667d976d1fd..d7eef13250e 100644
--- a/voidcrew/modules/hyperviolence/visuals/death_falls.dm
+++ b/voidcrew/modules/hyperviolence/visuals/death_falls.dm
@@ -9,6 +9,13 @@
// Every pose is held by the animation itself and let go by /datum/component/hv_motion_hold the moment
// the body is moved, stands up or is revived.
+/mob/living/carbon
+ /// world.time the corpse's slide across a whole tile is due at (hv_vis_death_hit()), 0 when none is waiting. A
+ /// Sandevistan replay keeps recording until it has slid (ware_sandy_replay.dm).
+ var/hv_vis_slide_due = 0
+ /// world.time the corpse's slide across a tile is over at (hv_vis_slide_tile()), 0 when it never slid.
+ var/hv_vis_slide_ends = 0
+
/// Falls point away from the hit that dropped the body, when one just landed from the side.
/mob/living/carbon/set_lying_angle(new_lying)
var/falling = !lying_angle && new_lying
@@ -125,7 +132,9 @@
hv_vis_play_over(hv_vis_hold_then_fall_steps(HV_VIS_HITSTOP_TIME, 2))
if(hv_vis_hit_damage >= HV_VIS_FULL_SLIDE_DAMAGE && hv_vis_can_slide_tile(hit_dir))
// Next tick: the blow that killed it may still be resolving (a shotgun's other pellets).
- addtimer(CALLBACK(src, PROC_REF(hv_vis_slide_tile), hit_dir), 1, TIMER_DELETE_ME)
+ var/slide_in = cyberware_dilated_time(src, 1) // slower in a Sandevistan field
+ hv_vis_slide_due = world.time + slide_in
+ addtimer(CALLBACK(src, PROC_REF(hv_vis_slide_tile), hit_dir), slide_in, TIMER_DELETE_ME)
return
hv_vis_slide_in_tile(hit_dir, hv_vis_hit_damage, big ? HV_VIS_HITSTOP_TIME : 0)
hv_vis_twitches(rand(3, 5), big ? 6 : 4)
@@ -174,9 +183,11 @@
/// Slides the corpse a whole tile along the killing blow, a real move with a slow glide.
/mob/living/carbon/proc/hv_vis_slide_tile(slide_dir)
+ hv_vis_slide_due = 0
if(QDELETED(src) || stat != DEAD)
return
- if(hv_vis_can_slide_tile(slide_dir) && Move(get_step(loc, slide_dir), slide_dir, DELAY_TO_GLIDE_SIZE(HV_VIS_SLIDE_TIME)))
+ if(hv_vis_can_slide_tile(slide_dir) && Move(get_step(loc, slide_dir), slide_dir, DELAY_TO_GLIDE_SIZE(cyberware_dilated_time(src, HV_VIS_SLIDE_TIME))))
+ hv_vis_slide_ends = world.time + cyberware_dilated_time(src, HV_VIS_SLIDE_TIME)
// Thrown back as it falls: a little lift over the slide.
var/matrix/base = matrix(transform)
hv_vis_play(HV_VIS_TAG_FALL, list(
diff --git a/voidcrew/modules/hyperviolence/visuals/execution_aim.dm b/voidcrew/modules/hyperviolence/visuals/execution_aim.dm
new file mode 100644
index 00000000000..0cccd4b7352
--- /dev/null
+++ b/voidcrew/modules/hyperviolence/visuals/execution_aim.dm
@@ -0,0 +1,487 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
+/**
+ * # A gun execution's aim
+ *
+ * tg draws a held gun low at the hip and a body has no poses, so a shooter holding the barrel to a head stood in the
+ * middle of his own tile with the gun at his side. For the length of the hold he is drawn by the puppet rig
+ * (hyperviolence_gorilla/chrome_puppet_rig.dm) instead: his body without the gun arm, the gun arm, and the gun, three
+ * pictures posed so the barrel's end is on the victim's head where that head is drawn, whichever way the victim lies
+ * and whichever side the shooter stands on.
+ *
+ * - Everything is measured in pixels from the middle of the shooter as he is drawn, x to the right and y up, and each
+ * picture is moved by its transform alone.
+ * - He faces along the longer side of the way to the head. Seen side-on he bends forward from the feet. He leans
+ * toward the victim as far as it takes for his arm and the gun to span the rest: a little for a head at his feet,
+ * half a tile for one at the far end of the victim's tile.
+ * - The barrel's line runs through the middle of the head and stops HV_AIM_GAP short of it. The hand is where that puts
+ * the grip, and the arm turns and stretches from the shoulder to the hand.
+ * - The gun at his hip is left out of the picture the rig takes of him, and only out of that picture: the real body,
+ * hidden under the rig, keeps it.
+ * - Purely a drawing. It goes when the execution does: fired (after the recoil), called off, the shooter moved or
+ * knocked down, the gun out of his hand, either of them deleted.
+ *
+ * A shooter the rig can't draw (not human, lying down, cloaked, shrunk or grown, already in a finisher's rig, a picture
+ * that isn't one tile) leans in as before (hv_vis_press_in()).
+ */
+
+/// How far short of the middle of the head the barrel's end stops: on the skull, the head being some four pixels in radius.
+#define HV_AIM_GAP 4
+/// How big the gun is drawn, of its item icon.
+#define HV_AIM_GUN_SCALE 0.6
+/// How high over his feet the shooter's head is, in pixels: how far a bend from the feet carries it forward.
+#define HV_AIM_HEAD_HEIGHT 26
+/// The least and the most the shooter leans toward the victim, in pixels.
+#define HV_AIM_LEAN_MIN 6
+#define HV_AIM_LEAN_MAX 17
+/// The bend of the body seen side-on, in degrees: for a head at his feet, and what a head a tile further adds.
+#define HV_AIM_BEND 12
+#define HV_AIM_BEND_FAR 6
+/// How long the lift from the hip to the head takes, the kick of the shot, how long the kick is held, and the way back down.
+#define HV_AIM_RAISE (0.3 SECONDS)
+#define HV_AIM_KICK (0.05 SECONDS)
+#define HV_AIM_KICK_HOLD (0.25 SECONDS)
+#define HV_AIM_LOWER (0.3 SECONDS)
+/// The way back down of a hold that was called off.
+#define HV_AIM_CALLED_OFF (0.15 SECONDS)
+/// How far the shot throws the gun back along the barrel, in pixels, and how far it tips the barrel up, in degrees.
+#define HV_AIM_KICK_BACK 2
+#define HV_AIM_KICK_CLIMB 20
+
+/obj/item/gun
+ /// The aimed pose of the execution this gun is being held to a head for
+ var/datum/hv_exec_aim/hv_aim
+ /// TRUE while the rig takes its picture of the shooter: the gun in his hand is left out of it
+ var/hv_aim_out_of_hand = FALSE
+
+// The gun is in the hand all along; only its drawing at the hip is left out of the rig's picture.
+/obj/item/gun/build_worn_icon(default_layer = 0, default_icon_file = null, isinhands = FALSE, female_uniform = NO_FEMALE_UNIFORM, override_state = null, override_file = null)
+ . = ..()
+ if(isinhands && hv_aim_out_of_hand && .)
+ var/mutable_appearance/standing = .
+ standing.alpha = 0
+
+/datum/hv_exec_aim
+ /// The gun
+ var/obj/item/gun/gun
+ /// Who holds it
+ var/mob/living/carbon/human/shooter
+ /// Whose head it is on
+ var/mob/living/target
+ /// The rig drawing the shooter
+ var/datum/chrome_rig/rig
+ /// The way the shooter is drawn facing
+ var/facing
+ /// The arm the gun is in: "l" or "r"
+ var/side
+ /// The grip and the barrel's end on the gun's picture: list(grip x, grip y, muzzle x, muzzle y)
+ var/list/shape
+ /// The middle of the victim's drawn head
+ var/head_x = 0
+ var/head_y = 0
+ /// The way the barrel points, a unit vector
+ var/aim_x = 0
+ var/aim_y = 0
+ /// -1 for a gun pointing left: its picture is mirrored so it isn't held upside down
+ var/flip = 1
+ /// The barrel's turn, in degrees clockwise from pointing east
+ var/barrel_turn = 0
+ /// The barrel's end in the aimed pose
+ var/list/muzzle
+ /// The aimed pose (see pose_for())
+ var/list/aimed
+ /// The pose the pictures were last sent to
+ var/list/held
+ /// The timer that takes the rig down once he is back upright
+ var/down_timer
+
+/datum/hv_exec_aim/New(obj/item/gun/gun, mob/living/shooter, mob/living/target)
+ . = ..()
+ src.gun = gun
+ src.shooter = shooter
+ src.target = target
+
+/datum/hv_exec_aim/Destroy()
+ hv_exec_bar_lean(shooter)
+ if(down_timer)
+ deltimer(down_timer)
+ down_timer = null
+ if(gun)
+ UnregisterSignal(gun, list(COMSIG_ITEM_DROPPED, COMSIG_QDELETING))
+ if(gun.hv_aim == src)
+ gun.hv_aim = null
+ if(shooter)
+ UnregisterSignal(shooter, COMSIG_QDELETING)
+ if(target)
+ UnregisterSignal(target, COMSIG_LIVING_POST_UPDATE_TRANSFORM)
+ QDEL_NULL(rig)
+ take_from_hand(FALSE)
+ gun = null
+ shooter = null
+ target = null
+ return ..()
+
+/// Leaves the gun at the hip out of the shooter's look (`out`), or puts it back.
+/datum/hv_exec_aim/proc/take_from_hand(out)
+ if(QDELETED(gun) || gun.hv_aim_out_of_hand == out)
+ return
+ gun.hv_aim_out_of_hand = out
+ if(!QDELETED(shooter))
+ shooter.update_held_items()
+
+/// Whether the rig is up and the barrel is on the head.
+/datum/hv_exec_aim/proc/is_up()
+ return !QDELETED(src) && !isnull(rig) && !isnull(aimed)
+
+/**
+ * Stands the rig up and lifts the gun onto the head. Returns FALSE if the shooter can't be drawn that way, with
+ * nothing left behind.
+ */
+/datum/hv_exec_aim/proc/raise()
+ if(!stand_up())
+ return FALSE
+ // The gun out of his hand, or either of them gone: the drawing comes down at once. A victim laid down, got up or
+ // turned over: the gun goes to where the head is now.
+ RegisterSignals(gun, list(COMSIG_ITEM_DROPPED, COMSIG_QDELETING), PROC_REF(on_lost))
+ RegisterSignal(shooter, COMSIG_QDELETING, PROC_REF(on_lost))
+ RegisterSignal(target, COMSIG_LIVING_POST_UPDATE_TRANSFORM, PROC_REF(on_target_turned))
+ return TRUE
+
+/// Builds the rig for where the head is drawn now and plays the lift from the hip. Returns FALSE, with no rig, if it can't.
+/datum/hv_exec_aim/proc/stand_up()
+ if(!ishuman(shooter) || QDELETED(target) || QDELETED(gun) || !isturf(shooter.loc) || !isturf(target.loc))
+ return FALSE
+ if(shooter.body_position == LYING_DOWN || shooter.alpha < 255 || shooter.invisibility || sandy_rig_hidden(shooter))
+ return FALSE
+ if(shooter.current_size != RESIZE_DEFAULT_SIZE) // the rig's pictures are of a body its usual size
+ return FALSE
+ var/held_index = shooter.get_held_index_of_item(gun)
+ if(!held_index)
+ return FALSE
+ side = IS_LEFT_INDEX(held_index) ? "l" : "r"
+ var/icon/gun_picture = getFlatIcon(gun, SOUTH, no_anim = TRUE)
+ if(!gun_picture)
+ return FALSE
+ if(gun_picture.Width() != ICON_SIZE_X || gun_picture.Height() != ICON_SIZE_Y)
+ gun_picture.Scale(ICON_SIZE_X, ICON_SIZE_Y)
+ shape = hv_gun_shape(gun, gun_picture)
+ var/list/head = head_now()
+ head_x = head[1]
+ head_y = head[2]
+ facing = abs(head_x) >= abs(head_y) ? (head_x >= 0 ? EAST : WEST) : (head_y >= 0 ? NORTH : SOUTH)
+ if(shooter.dir != facing)
+ shooter.setDir(facing)
+
+ rig = new(shooter, facing)
+ take_from_hand(TRUE)
+ if(!rig.snapshot())
+ take_from_hand(FALSE)
+ QDEL_NULL(rig)
+ return FALSE
+ // What is drawn over what. On one row the gun arm and the gun are over both bodies; seen from behind they are
+ // under his own. A far arm, in a side view, is under his body with its gun.
+ var/turf/shooter_turf = shooter.loc
+ var/turf/target_turf = target.loc
+ var/far_arm = rig.behind_body(side)
+ // A body lying a row nearer the viewer is drawn over everything on his row: the arm and the gun stand on its row.
+ var/on_their_row = target.body_position == LYING_DOWN && target_turf.y < shooter_turf.y
+ var/top = max(shooter.layer, target.layer)
+ var/arm_layer = top + 0.02
+ var/gun_layer = top + 0.01
+ if(facing == NORTH)
+ arm_layer = shooter.layer - 0.01
+ gun_layer = shooter.layer - 0.02
+ else if(far_arm && !on_their_row)
+ arm_layer = shooter.layer - 0.02
+ gun_layer = shooter.layer - 0.01
+ rig.add_puppet("body", rig.cut_without_arms(side))
+ var/obj/effect/abstract/chrome_puppet/gun_puppet = rig.add_puppet("gun", gun_picture, FALSE, gun_layer)
+ var/obj/effect/abstract/chrome_puppet/arm_puppet = rig.add_puppet("arm_[side]", rig.arm_picture(side), FALSE, arm_layer)
+ if(on_their_row)
+ for(var/obj/effect/abstract/chrome_puppet/puppet as anything in list(gun_puppet, arm_puppet))
+ puppet.pixel_y -= ICON_SIZE_Y
+ puppet.pixel_z += ICON_SIZE_Y
+ rig.conceal()
+ take_from_hand(FALSE)
+ // Moved or knocked down: the drawing comes down at once
+ rig.watch_body(CALLBACK(src, PROC_REF(drop)))
+
+ solve()
+ var/list/rest = rest_pose()
+ set_pose(rest)
+ play(through(rest, aimed, 3), HV_AIM_RAISE)
+ return TRUE
+
+/// Where the middle of the victim's head is drawn now, from where the shooter is drawn: list(x, y).
+/datum/hv_exec_aim/proc/head_now()
+ var/turf/shooter_turf = get_turf(shooter)
+ var/turf/target_turf = get_turf(target)
+ var/list/head_at = target.hv_vis_head_offset()
+ return list(
+ (target_turf.x - shooter_turf.x) * ICON_SIZE_X + head_at[1] - (shooter.pixel_x + shooter.pixel_w),
+ (target_turf.y - shooter_turf.y) * ICON_SIZE_Y + head_at[2] - (shooter.pixel_y + shooter.pixel_z),
+ )
+
+/datum/hv_exec_aim/proc/on_target_turned(datum/source)
+ SIGNAL_HANDLER
+ // Once tg has finished laying the body down or standing it up
+ addtimer(CALLBACK(src, PROC_REF(follow_head)), world.tick_lag, TIMER_UNIQUE|TIMER_DELETE_ME)
+
+/// The victim's head is somewhere else (laid down, got up, turned over): the pose is taken again, on the head.
+/datum/hv_exec_aim/proc/follow_head()
+ if(!is_up() || down_timer || QDELETED(target) || QDELETED(shooter) || !isturf(target.loc) || !isturf(shooter.loc))
+ return
+ var/list/head = head_now()
+ if(abs(head[1] - head_x) < 1 && abs(head[2] - head_y) < 1)
+ return
+ QDEL_NULL(rig)
+ aimed = null
+ if(!stand_up())
+ drop()
+
+/datum/hv_exec_aim/proc/on_lost(datum/source)
+ SIGNAL_HANDLER
+ drop()
+
+/// Takes the drawing down at once.
+/datum/hv_exec_aim/proc/drop()
+ if(!QDELETED(src))
+ qdel(src)
+
+/// Works out the aimed pose: how far he bends and leans, and from that the arm and the gun.
+/datum/hv_exec_aim/proc/solve()
+ var/side_view = facing == EAST || facing == WEST
+ var/bend = side_view ? HV_AIM_BEND + HV_AIM_BEND_FAR * clamp((abs(head_x) - 20) / 21, 0, 1) : 0
+ var/matrix/bent = body_matrix(bend, 0, 0)
+ var/list/pivot = rig.shoulder(side)
+ var/list/shoulder = chrome_rig_apply(bent, pivot[1], pivot[2])
+ var/to_x = head_x - shoulder[1]
+ var/to_y = head_y - shoulder[2]
+ // He leans the way he faces; sideways as well only for a head a tile off that line (a diagonal)
+ var/way_x = (side_view || abs(to_x) >= ICON_SIZE_X / 2) ? to_x : 0
+ var/way_y = (!side_view || abs(to_y) >= ICON_SIZE_Y / 2) ? to_y : 0
+ var/way_length = sqrt(way_x * way_x + way_y * way_y) || 1
+ way_x /= way_length
+ way_y /= way_length
+ // What his arm and the gun span when the arm is easy: the lean covers the rest
+ var/list/hand = rig.hand_offset(side)
+ var/arm_ease = side_view ? 1 : (facing == SOUTH ? 1.1 : 0.7)
+ var/span = HV_AIM_GAP + (shape[3] - shape[1]) * HV_AIM_GUN_SCALE + sqrt(hand[1] * hand[1] + hand[2] * hand[2]) * arm_ease
+ var/along = to_x * way_x + to_y * way_y
+ var/aside = to_x * to_x + to_y * to_y - along * along
+ var/lean = clamp(along - sqrt(max(0, span * span - aside)), HV_AIM_LEAN_MIN, HV_AIM_LEAN_MAX)
+ aimed = pose_for(bend, round(way_x * lean), round(way_y * lean))
+ muzzle = barrel_end(aimed)
+
+/**
+ * The pose with the body bent `bend` degrees and moved `lean_x`, `lean_y`, the barrel on the head and thrown `kick`
+ * pixels back from it: list(bend, lean x, lean y, arm turn, arm length, gun turn). The first full pose (no kick) sets
+ * the way the barrel points for the rest.
+ */
+/datum/hv_exec_aim/proc/pose_for(bend, lean_x, lean_y, kick = 0)
+ var/matrix/body = body_matrix(bend, lean_x, lean_y)
+ var/list/pivot = rig.shoulder(side)
+ var/list/shoulder = chrome_rig_apply(body, pivot[1], pivot[2])
+ if(!kick)
+ var/to_x = head_x - shoulder[1]
+ var/to_y = head_y - shoulder[2]
+ var/distance = sqrt(to_x * to_x + to_y * to_y) || 1
+ aim_x = to_x / distance
+ aim_y = to_y / distance
+ flip = aim_x < 0 ? -1 : 1
+ barrel_turn = -arctan(aim_x, aim_y)
+ // From the grip to the barrel's end as the gun is drawn, then back from where the barrel ends to where the hand is
+ var/matrix/drawn = matrix()
+ drawn.Scale(HV_AIM_GUN_SCALE, HV_AIM_GUN_SCALE * flip)
+ drawn.Turn(barrel_turn)
+ var/list/barrel = chrome_rig_apply(drawn, shape[3] - shape[1], shape[4] - shape[2])
+ var/hand_x = head_x - aim_x * (HV_AIM_GAP + kick) - barrel[1]
+ var/hand_y = head_y - aim_y * (HV_AIM_GAP + kick) - barrel[2]
+ var/list/arm = rig.pose_reaching(side, hand_x, hand_y, 0, body)
+ var/longest = (facing == EAST || facing == WEST) ? 1.7 : (facing == SOUTH ? 1.4 : 1.2)
+ return list(bend, lean_x, lean_y, arm[1], min(arm[2], longest), barrel_turn - (kick ? HV_AIM_KICK_CLIMB * flip : 0))
+
+/// The pose he starts from and ends in: upright on his tile, the arm hanging, the gun low and pointing down ahead of him.
+/datum/hv_exec_aim/proc/rest_pose()
+ var/low = 90
+ switch(facing)
+ if(EAST)
+ low = 70
+ if(WEST)
+ low = 110
+ if(NORTH) // behind his own body: it only comes up
+ low = barrel_turn
+ // The short way round from where it points on the head
+ while(low - barrel_turn > 180)
+ low -= 360
+ while(low - barrel_turn < -180)
+ low += 360
+ return list(0, 0, 0, 0, 1, low)
+
+/// The body's matrix bent `bend` degrees from the feet (side views only) and moved `lean_x`, `lean_y`.
+/datum/hv_exec_aim/proc/body_matrix(bend, lean_x, lean_y)
+ var/matrix/body = rig.bend_matrix(bend) || matrix()
+ body.Translate(lean_x, lean_y)
+ return body
+
+/// The matrices that draw `pose`: list(body, arm, gun).
+/datum/hv_exec_aim/proc/matrices_of(list/pose)
+ var/matrix/body = body_matrix(pose[1], pose[2], pose[3])
+ var/list/hand = rig.hand_at(side, list(pose[4], pose[5], body))
+ var/matrix/gun_matrix = matrix()
+ gun_matrix.Translate(-shape[1], -shape[2])
+ gun_matrix.Scale(HV_AIM_GUN_SCALE, HV_AIM_GUN_SCALE * flip)
+ gun_matrix.Turn(pose[6])
+ gun_matrix.Translate(hand[1], hand[2])
+ return list(body, rig.arm_matrix(side, pose[4], pose[5], body), gun_matrix)
+
+/// Where the barrel's end is drawn in `pose`: list(x, y).
+/datum/hv_exec_aim/proc/barrel_end(list/pose)
+ var/list/matrices = matrices_of(pose)
+ return chrome_rig_apply(matrices[3], shape[3], shape[4])
+
+/// The poses from `first` to `last` in `steps` short straight steps, eased in and out, so the arm stays on its
+/// shoulder and the gun in the hand on the way.
+/datum/hv_exec_aim/proc/through(list/first, list/last, steps)
+ . = list()
+ for(var/i in 1 to steps)
+ var/progress = (1 - cos(180 * i / steps)) / 2
+ var/list/pose = list()
+ for(var/part in 1 to length(last))
+ pose += first[part] + (last[part] - first[part]) * progress
+ . += list(pose)
+
+/// Puts the pictures in `pose` at once.
+/datum/hv_exec_aim/proc/set_pose(list/pose)
+ var/list/matrices = matrices_of(pose)
+ var/list/pictures = pictures()
+ for(var/i in 1 to length(pictures))
+ var/obj/effect/abstract/chrome_puppet/picture = pictures[i]
+ if(picture)
+ picture.transform = matrices[i]
+ held = pose
+
+/// The rig's pictures in the order matrices_of() gives their matrices: the body, the arm, the gun.
+/datum/hv_exec_aim/proc/pictures()
+ return list(rig.puppet("body"), rig.puppet("arm_[side]"), rig.puppet("gun"))
+
+/**
+ * Sends the pictures through `poses`, each step taking `times` (one number: the whole run, shared evenly; or a list, one
+ * per pose), at the shooter's own pace in a Sandevistan slow-mo. Returns how long it takes in real time.
+ */
+/datum/hv_exec_aim/proc/play(list/poses, times, easing = LINEAR_EASING)
+ var/list/each = times
+ if(!islist(each))
+ each = list()
+ for(var/i in 1 to length(poses))
+ each += times / length(poses)
+ var/list/real = cyberware_dilated_steps(shooter, each) || each
+ var/list/pictures = pictures()
+ var/list/steps = list()
+ for(var/list/pose as anything in poses)
+ steps += list(matrices_of(pose))
+ for(var/i in 1 to length(pictures))
+ var/obj/effect/abstract/chrome_puppet/picture = pictures[i]
+ if(!picture)
+ continue
+ for(var/step in 1 to length(steps))
+ if(step == 1)
+ animate(picture, transform = steps[step][i], time = real[step], easing = easing)
+ else
+ animate(transform = steps[step][i], time = real[step], easing = easing)
+ held = poses[length(poses)]
+ . = 0
+ for(var/time in real)
+ . += time
+ // His bar goes where his head goes: the lean, and what the bend from the feet adds to it
+ var/forward = facing == EAST ? 1 : (facing == WEST ? -1 : 0)
+ hv_exec_bar_lean(shooter, round(held[2] + forward * HV_AIM_HEAD_HEIGHT * sin(held[1])), round(held[3]), .)
+
+/// The shot: the gun kicks back and up, he rocks back with it and holds there through the flash, then lowers the gun
+/// and straightens up, and the rig comes down.
+/datum/hv_exec_aim/proc/recoil()
+ if(!is_up() || QDELETED(shooter) || !isturf(shooter.loc))
+ drop()
+ return
+ // The shot can bloody him: his pictures are taken again, where they stand
+ take_from_hand(TRUE)
+ if(rig.snapshot())
+ rig.repaint("body", rig.cut_without_arms(side))
+ rig.repaint("arm_[side]", rig.arm_picture(side))
+ take_from_hand(FALSE)
+ var/list/kicked = pose_for(max(aimed[1] - 3, 0), aimed[2] - round(aim_x * HV_AIM_KICK_BACK), aimed[3] - round(aim_y * HV_AIM_KICK_BACK), HV_AIM_KICK_BACK)
+ var/list/poses = list(kicked, kicked) + through(kicked, rest_pose(), 3)
+ var/length = play(poses, list(HV_AIM_KICK, HV_AIM_KICK_HOLD, HV_AIM_LOWER / 3, HV_AIM_LOWER / 3, HV_AIM_LOWER / 3))
+ comes_down_in(length)
+
+/// Called off: the gun comes down, and the rig with it.
+/datum/hv_exec_aim/proc/lower()
+ if(!is_up() || QDELETED(shooter) || !isturf(shooter.loc))
+ drop()
+ return
+ comes_down_in(play(through(held, rest_pose(), 2), HV_AIM_CALLED_OFF))
+
+/datum/hv_exec_aim/proc/comes_down_in(time)
+ if(down_timer)
+ deltimer(down_timer)
+ down_timer = addtimer(CALLBACK(src, PROC_REF(drop)), time, TIMER_STOPPABLE|TIMER_DELETE_ME)
+
+/// Where the barrel's end is in pixels from the middle of `spot`: list(x, y).
+/datum/hv_exec_aim/proc/muzzle_from(turf/spot)
+ var/turf/shooter_turf = get_turf(shooter)
+ var/x = muzzle[1] + shooter.pixel_x + shooter.pixel_w
+ var/y = muzzle[2] + shooter.pixel_y + shooter.pixel_z
+ return list(x + (shooter_turf.x - spot.x) * ICON_SIZE_X, y + (shooter_turf.y - spot.y) * ICON_SIZE_Y)
+
+/**
+ * Where the grip and the barrel's end are on a gun's picture, in pixels from its middle: list(grip x, grip y, muzzle
+ * x, muzzle y). tg's gun icons point east: the barrel ends at the right edge, the grip hangs under the back of it.
+ */
+/proc/hv_gun_shape(obj/item/gun/gun, icon/picture)
+ var/static/list/shapes = list()
+ var/key = "[gun.type]-[gun.icon_state]"
+ if(shapes[key])
+ return shapes[key]
+ var/left = 0
+ var/right = 0
+ var/bottom = 0
+ var/top = 0
+ var/list/filled = list()
+ for(var/x in 1 to ICON_SIZE_X)
+ var/list/column = list()
+ for(var/y in 1 to ICON_SIZE_Y)
+ if(isnull(picture.GetPixel(x, y)))
+ continue
+ column += y
+ left ||= x
+ right = x
+ bottom = bottom ? min(bottom, y) : y
+ top = max(top, y)
+ filled += list(column)
+ if(!right)
+ return shapes[key] = list(-7, -3, 10, 2)
+ // The barrel's height: the middle of what is drawn two pixels in from its end
+ var/list/barrel = filled[max(right - 2, left)]
+ var/barrel_y = 0
+ for(var/y in barrel)
+ barrel_y += y
+ barrel_y = length(barrel) ? barrel_y / length(barrel) : (top + bottom) / 2
+ return shapes[key] = list(min(left + 3, right) - 0.5 - ICON_SIZE_X / 2, bottom + (top - bottom) * 0.4 - 0.5 - ICON_SIZE_Y / 2, right - ICON_SIZE_X / 2, barrel_y - 0.5 - ICON_SIZE_Y / 2)
+
+#undef HV_AIM_GAP
+#undef HV_AIM_GUN_SCALE
+#undef HV_AIM_HEAD_HEIGHT
+#undef HV_AIM_LEAN_MIN
+#undef HV_AIM_LEAN_MAX
+#undef HV_AIM_BEND
+#undef HV_AIM_BEND_FAR
+#undef HV_AIM_RAISE
+#undef HV_AIM_KICK
+#undef HV_AIM_KICK_HOLD
+#undef HV_AIM_LOWER
+#undef HV_AIM_CALLED_OFF
+#undef HV_AIM_KICK_BACK
+#undef HV_AIM_KICK_CLIMB
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence/visuals/execution_motion.dm b/voidcrew/modules/hyperviolence/visuals/execution_motion.dm
index 35aa47d1605..65fb32aaad5 100644
--- a/voidcrew/modules/hyperviolence/visuals/execution_motion.dm
+++ b/voidcrew/modules/hyperviolence/visuals/execution_motion.dm
@@ -1,23 +1,43 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// Hyperviolence visuals: gun executions (overlays_exec/executions.dm).
-// 17. The press: the shooter leans in over the victim, the victim trembles, and both go still for a
-// short, deliberate moment before the shot. The shot: a big muzzle flash at the head the barrel is
-// pressed to, a hit-stop on both (the shooter rocks back from it), and a burst head throws its gibs
-// in arcs (flying_gore.dm). The body holds for a beat, then slumps forward along the shot
-// (death_falls.dm).
+// 17. The press: the shooter leans in over the victim with the barrel on the head (execution_aim.dm), the
+// victim trembles, and both go still for a short, deliberate moment before the shot. The shot: a big
+// muzzle flash at the barrel's end, the gun kicks and the shooter rocks back from it, a hit-stop on the
+// victim, and a burst head throws its gibs in arcs (flying_gore.dm). The body holds for a beat, then
+// slumps forward along the shot (death_falls.dm). Then the shooter lowers the gun and straightens up.
// The press is only drawn over the wind-up the execution already has; nothing here changes its timing.
/obj/item/gun/hv_start_execution(mob/living/user, mob/living/target, params)
// The same checks that stop the wind-up before it starts.
var/pressing = !fire_cd && !firing_burst && !HAS_TRAIT(user, TRAIT_PACIFISM) && isturf(user.loc) && isturf(target.loc)
+ var/datum/hv_exec_aim/aim
if(pressing)
- user.hv_vis_press_in(target, HV_EXECUTION_WINDUP)
+ user.face_atom(target)
+ // He is drawn with the gun on the head (execution_aim.dm); one who can't be only leans in.
+ QDEL_NULL(hv_aim)
+ aim = new(src, user, target)
+ if(aim.raise())
+ hv_aim = aim
+ else
+ QDEL_NULL(aim)
+ user.hv_vis_press_in(target, HV_EXECUTION_WINDUP)
target.hv_vis_tremble(HV_EXECUTION_WINDUP - HV_VIS_PRESS_PAUSE, 1)
. = ..()
if(!pressing)
return
- // Shot or called off, the shooter straightens up.
- if(!QDELETED(user))
- user.hv_vis_release(HV_VIS_TAG_PRESS, 1.5)
+ // Called off, the shooter straightens up at once. Having fired he holds the lean through the flash and the burst:
+ // straightening on the shot's own tick, he stood idle while the head went off beside him.
+ if(aim)
+ // The shot's recoil ends in the gun coming down (hv_fire_execution()); anything else lowers it now
+ if(!QDELETED(aim) && !aim.down_timer)
+ aim.lower()
+ else if(!QDELETED(user))
+ if(.)
+ addtimer(CALLBACK(user, TYPE_PROC_REF(/atom, hv_vis_release), HV_VIS_TAG_PRESS, 1.5), 0.4 SECONDS)
+ else
+ user.hv_vis_release(HV_VIS_TAG_PRESS, 1.5)
if(!QDELETED(target) && target.stat != DEAD)
target.hv_vis_release(HV_VIS_TAG_TREMBLE, 1)
@@ -36,7 +56,10 @@
. = ..()
if(!. || QDELETED(user))
return
- hv_vis_muzzle_flash(user, head_turf || target, head_at, behind_head)
+ // With the gun drawn on the head the flash is at its barrel's end, and the gun kicks
+ var/datum/hv_exec_aim/aim = hv_aim?.is_up() ? hv_aim : null
+ hv_vis_muzzle_flash(user, head_turf || target, head_at, behind_head, aim)
+ aim?.recoil()
if(!QDELETED(target))
target.hv_vis_big_hit(get_dir(user, target), user)
@@ -68,23 +91,40 @@
var/loops = max(1, round(duration / 2))
var/base_w = pixel_w
var/base_z = pixel_z
- animate(src, pixel_w = base_w + strength, pixel_z = base_z, transform = base, time = 0.5, loop = loops, tag = HV_VIS_TAG_TREMBLE)
- animate(pixel_w = base_w - strength, pixel_z = base_z, transform = base, time = 1)
- animate(pixel_w = base_w, pixel_z = base_z, transform = base, time = 0.5)
+ // Slower in a Sandevistan field (cyberware/ware_sandy_timestop.dm).
+ var/list/real = cyberware_dilated_steps(src, list(0.5, 1, 0.5), loops) || list(0.5, 1, 0.5)
+ animate(src, pixel_w = base_w + strength, pixel_z = base_z, transform = base, time = real[1], loop = loops, tag = HV_VIS_TAG_TREMBLE)
+ animate(pixel_w = base_w - strength, pixel_z = base_z, transform = base, time = real[2])
+ animate(pixel_w = base_w, pixel_z = base_z, transform = base, time = real[3])
/**
- * A muzzle flash much bigger than a normal shot's, with a flash of light. It is where the barrel's end
- * is: just short of the head it is pressed to, `head_at` pixels from the middle of the target's tile
- * (list(x, y)). It stands on the target's tile, so it sorts with the target: a shooter standing nearer
- * the camera than the victim is drawn over it, as their body is between us and the gun. `behind_target`
- * draws it under the target too: the barrel is on the far side of their head.
+ * A muzzle flash bigger than a normal shot's, with a flash of light. It is where the barrel's end is: where
+ * `aim` draws it (execution_aim.dm), turned the way the barrel points; without one, just short of the head it
+ * is pressed to, `head_at` pixels from the middle of the target's tile (list(x, y)). It stands on the target's
+ * tile, so it sorts with the target: a shooter standing nearer the camera than the victim is drawn over it, as
+ * their body is between us and the gun. `behind_target` draws it under the target too: the barrel is on the far
+ * side of their head.
*/
-/proc/hv_vis_muzzle_flash(mob/living/shooter, atom/target, list/head_at, behind_target = FALSE)
+/proc/hv_vis_muzzle_flash(mob/living/shooter, atom/target, list/head_at, behind_target = FALSE, datum/hv_exec_aim/aim)
var/turf/shooter_turf = get_turf(shooter)
var/turf/spot = get_turf(target) || shooter_turf
if(!shooter_turf || !spot)
return
- new /obj/effect/temp_visual/hv_muzzle_flash(spot, get_dir(shooter_turf, spot) || shooter.dir, head_at, behind_target)
+ var/shot_dir = get_dir(shooter_turf, spot) || shooter.dir
+ var/list/barrel_end
+ var/turn = 0
+ if(aim)
+ barrel_end = aim.muzzle_from(spot)
+ shot_dir = abs(aim.aim_x) >= abs(aim.aim_y) ? (aim.aim_x >= 0 ? EAST : WEST) : (aim.aim_y >= 0 ? NORTH : SOUTH)
+ // The flash's picture points along its facing; the rest of the way to the barrel's line it is turned
+ turn = aim.barrel_turn + 90 - dir2angle(shot_dir)
+ while(turn > 180)
+ turn -= 360
+ while(turn < -180)
+ turn += 360
+ else
+ barrel_end = list((head_at ? head_at[1] : 0) - HV_VIS_DX(shot_dir) * HV_VIS_FLASH_SHORT, (head_at ? head_at[2] : 0) - HV_VIS_DY(shot_dir) * HV_VIS_FLASH_SHORT)
+ new /obj/effect/temp_visual/hv_muzzle_flash(spot, shot_dir, barrel_end, behind_target, turn)
shooter_turf.flash_lighting_fx(3, 2, LIGHT_COLOR_ORANGE, 2)
/// The flash is one still picture, tg's muzzle flash at its brightest, grown and faded here. tg's own
@@ -99,26 +139,30 @@
randomdir = FALSE
duration = 4
-/obj/effect/temp_visual/hv_muzzle_flash/Initialize(mapload, shot_dir, list/head_at, behind_target = FALSE)
+/// `barrel_end` is where the barrel ends, in pixels from the middle of this tile (list(x, y)); `turn` the degrees
+/// clockwise the barrel's line is off the flash's facing.
+/obj/effect/temp_visual/hv_muzzle_flash/Initialize(mapload, shot_dir, list/barrel_end, behind_target = FALSE, turn = 0)
. = ..()
if(behind_target)
layer = BELOW_MOB_LAYER
setDir(shot_dir || SOUTH)
- var/dx = HV_VIS_DX(dir)
- var/dy = HV_VIS_DY(dir)
- // tg's flash art sits off the middle of its tile, toward the way it faces. It grows about that
+ // tg's flash art sits off the middle of its tile, toward the way it faces. It grows and turns about that
// point, and that point goes at the end of the barrel.
- var/core_w = dx * HV_VIS_FLASH_CORE
- var/core_z = dy * HV_VIS_FLASH_CORE
- pixel_w = (head_at ? head_at[1] : 0) - dx * HV_VIS_FLASH_SHORT - core_w
- pixel_z = (head_at ? head_at[2] : 0) - dy * HV_VIS_FLASH_SHORT - core_z
- transform = hv_vis_scaled_about(2.2, core_w, core_z)
- animate(src, transform = hv_vis_scaled_about(2.8, core_w, core_z), alpha = 0, time = duration, easing = QUAD_EASING|EASE_OUT)
+ var/core_w = HV_VIS_DX(dir) * HV_VIS_FLASH_CORE
+ var/core_z = HV_VIS_DY(dir) * HV_VIS_FLASH_CORE
+ pixel_w = round((barrel_end ? barrel_end[1] : 0) - core_w)
+ pixel_z = round((barrel_end ? barrel_end[2] : 0) - core_z)
+ transform = hv_vis_scaled_about(1.7, core_w, core_z, turn)
+ animate(src, transform = hv_vis_scaled_about(2.3, core_w, core_z, turn), alpha = 0, time = duration, easing = QUAD_EASING|EASE_OUT)
-/// A matrix that scales by `scale` about the point (x, y) pixels from the middle of the icon.
-/proc/hv_vis_scaled_about(scale, x, y)
+/// A matrix that scales by `scale` and turns `turn` degrees clockwise about the point (x, y) pixels from the middle of the icon.
+/proc/hv_vis_scaled_about(scale, x, y, turn = 0)
var/matrix/scaled = matrix()
scaled.Translate(-x, -y)
scaled.Scale(scale)
+ if(turn)
+ scaled.Turn(turn)
scaled.Translate(x, y)
return scaled
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence/visuals/flying_gore.dm b/voidcrew/modules/hyperviolence/visuals/flying_gore.dm
index 60c87030104..2d5a2a1c8cf 100644
--- a/voidcrew/modules/hyperviolence/visuals/flying_gore.dm
+++ b/voidcrew/modules/hyperviolence/visuals/flying_gore.dm
@@ -87,6 +87,7 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
pixel_y = base_pixel_y + HV_VIS_DY(fling_dir) * 7 + rand(-3, 3)
var/datum/component/hv_tumble/tumble = AddComponent(/datum/component/hv_tumble, style, blood_dna, fling_dir, path, on_landed, from, starts_over, starts_turned)
tumble.launch()
+ sandy_replay_made(src) // a Sandevistan's recording takes it wherever in the slowed room it comes off (ware_sandy_replay.dm)
return TRUE
/// The tiles a part flung from `start` along `fling_dir` crosses, nearest first, up to `distance` of them.
@@ -184,7 +185,7 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
else if(!grounded)
step_time *= 3
rest_layer = part.layer
- addtimer(CALLBACK(src, PROC_REF(give_up)), 5 SECONDS, TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(give_up)), cyberware_dilated_time(part, 5 SECONDS), TIMER_DELETE_ME)
/datum/component/hv_tumble/RegisterWithParent()
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
@@ -230,7 +231,8 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
/// where it is once it has dropped.
/datum/component/hv_tumble/proc/launch()
start_flight()
- step_timer = addtimer(CALLBACK(src, PROC_REF(take_step)), length(path) ? world.tick_lag : flight_time(), TIMER_STOPPABLE|TIMER_DELETE_ME)
+ // In a Sandevistan field (cyberware/ware_sandy_timestop.dm) it flies slow.
+ step_timer = addtimer(CALLBACK(src, PROC_REF(take_step)), cyberware_dilated_time(parent, length(path) ? world.tick_lag : flight_time()), TIMER_STOPPABLE|TIMER_DELETE_ME)
/datum/component/hv_tumble/proc/start_flight()
var/obj/item/part = parent
@@ -305,12 +307,13 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
steps_taken++
path.Cut(1, 2)
stepping = TRUE
- part.set_glide_size(DELAY_TO_GLIDE_SIZE(step_time))
+ var/real_step = cyberware_dilated_time(part, step_time)
+ part.set_glide_size(DELAY_TO_GLIDE_SIZE(real_step))
part.forceMove(next)
stepping = FALSE
if(QDELETED(src))
return
- step_timer = addtimer(CALLBACK(src, PROC_REF(take_step)), step_time, TIMER_STOPPABLE|TIMER_DELETE_ME)
+ step_timer = addtimer(CALLBACK(src, PROC_REF(take_step)), real_step, TIMER_STOPPABLE|TIMER_DELETE_ME)
/// Blood on each tile it crosses. Anything else moving it (a hand, a conveyor) ends the flight.
/datum/component/hv_tumble/proc/on_moved(obj/item/source, atom/old_loc, movement_dir, forced, list/old_locs)
@@ -324,6 +327,12 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
if(!isturf(crossed) || isgroundlessturf(crossed) || crossed.has_gravity() <= 0)
return
streaks++
+ // Over wet spray already there it leaves nothing new: its few drops would thin the gout out (the spray is one decal
+ // a tile, and takes the last look it is given).
+ for(var/obj/effect/decal/cleanable/blood/hv_spray/there in crossed)
+ if(!istype(there, /obj/effect/decal/cleanable/blood/hv_spray/wall) && !there.dried && !QDELETED(there))
+ there.add_blood_DNA(blood_dna)
+ return
// A few drops under it as it passes, not a line.
var/obj/effect/decal/cleanable/blood/hv_spray/streak/trail = hv_blood_lay_spray(crossed, /obj/effect/decal/cleanable/blood/hv_spray/streak/drops, fling_dir, blood_dna)
if(istype(trail))
@@ -430,10 +439,12 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
var/list/pivot = part.hv_vis_spin_pivot()
var/start_x = part.pixel_x
var/start_y = part.pixel_y
- animate(part, pixel_x = start_x, pixel_y = start_y, transform = base, time = 2.5, tag = HV_VIS_TAG_SPIN)
- animate(pixel_x = start_x + (end_x - start_x) / 3, pixel_y = start_y + (end_y - start_y) / 3, transform = hv_vis_turned(base, spin * 120, pivot[2], pivot[1]), time = 1.5, easing = LINEAR_EASING)
- animate(pixel_x = start_x + (end_x - start_x) * 2 / 3, pixel_y = start_y + (end_y - start_y) * 2 / 3, transform = hv_vis_turned(base, spin * 240, pivot[2], pivot[1]), time = 2, easing = LINEAR_EASING)
- animate(pixel_x = end_x, pixel_y = end_y, transform = base, time = 3, easing = QUAD_EASING|EASE_OUT)
+ // Slower in a Sandevistan field (cyberware/ware_sandy_timestop.dm).
+ var/list/real = cyberware_dilated_steps(part, list(2.5, 1.5, 2, 3)) || list(2.5, 1.5, 2, 3)
+ animate(part, pixel_x = start_x, pixel_y = start_y, transform = base, time = real[1], tag = HV_VIS_TAG_SPIN)
+ animate(pixel_x = start_x + (end_x - start_x) / 3, pixel_y = start_y + (end_y - start_y) / 3, transform = hv_vis_turned(base, spin * 120, pivot[2], pivot[1]), time = real[2], easing = LINEAR_EASING)
+ animate(pixel_x = start_x + (end_x - start_x) * 2 / 3, pixel_y = start_y + (end_y - start_y) * 2 / 3, transform = hv_vis_turned(base, spin * 240, pivot[2], pivot[1]), time = real[3], easing = LINEAR_EASING)
+ animate(pixel_x = end_x, pixel_y = end_y, transform = base, time = real[4], easing = QUAD_EASING|EASE_OUT)
// ---- Limbs and heads coming off ----
@@ -499,6 +510,8 @@ GLOBAL_LIST(hv_vis_arcing_gibs)
. = list(-y, x)
else
. = list(x, y)
+ // Where tg has moved the body off the middle of its tile: lying down, or held in a grab
+ .[1] += pixel_x - base_pixel_x
.[2] += pixel_y - base_pixel_y
/// How far this body is drawn turned from upright as it lies now, in degrees clockwise, the short way round
diff --git a/voidcrew/modules/hyperviolence/wire/wire_garrote.dm b/voidcrew/modules/hyperviolence/wire/wire_garrote.dm
index 41ec6366450..775eeb6429c 100644
--- a/voidcrew/modules/hyperviolence/wire/wire_garrote.dm
+++ b/voidcrew/modules/hyperviolence/wire/wire_garrote.dm
@@ -303,7 +303,10 @@
wire.wound_bonus += extra_wound_bonus
wire.garrote_blow = TRUE
wire.garrote_no_cleave = TRUE
+ victim.hv_struck_where_aimed = TRUE
wire.melee_attack_chain(user, victim)
+ if(!QDELETED(victim))
+ victim.hv_struck_where_aimed = FALSE
if(!QDELETED(wire))
wire.garrote_blow = FALSE
wire.garrote_no_cleave = FALSE
diff --git a/voidcrew/modules/hyperviolence_gorilla/chrome_puppet_rig.dm b/voidcrew/modules/hyperviolence_gorilla/chrome_puppet_rig.dm
index eb9372465b9..61e30c9eb84 100644
--- a/voidcrew/modules/hyperviolence_gorilla/chrome_puppet_rig.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/chrome_puppet_rig.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # The puppet rig ("arm rig")
*
@@ -408,6 +411,7 @@ GLOBAL_LIST_INIT(chrome_rig_fill_shift, list(
if(copy_transform)
puppet.transform = body.transform
puppets[key] = puppet
+ cyberware_time_rig_picture(puppet, body) // in a Sandevistan slow-mo it looks like the body it stands for
// Stood up after the rig was packed, in the same tick: into the same file
if(sheet?.made_at == world.time)
sheet.redraw()
@@ -793,6 +797,10 @@ GLOBAL_LIST_INIT(chrome_rig_fill_shift, list(
/// Every puppet flashes white and fades back.
/datum/chrome_rig/proc/flash()
for(var/key in puppets)
+ // In a Sandevistan slow-mo the flash plays through the puppet's tint filter: a second colour filter animated over
+ // the tint was drawn stuck at its flash by the client, a near-white body until the rig let go (ware_sandy_timestop.dm)
+ if(cyberware_time_flash(puppets[key], list(0.4,0,0, 0,0.4,0, 0,0,0.4, 0.6,0.6,0.62), list(0, 0, 0.2 SECONDS)))
+ continue
cyberware_flash_fx(puppets[key], 0.2 SECONDS)
#undef CHROME_RIG_HIDE_FILTER
@@ -801,3 +809,5 @@ GLOBAL_LIST_INIT(chrome_rig_fill_shift, list(
#undef CHROME_RIG_SWING_STEP
#undef CHROME_RIG_SWAP
#undef CHROME_RIG_MIN_ARM_LENGTH
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_finisher.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_finisher.dm
index cb85f71c3c4..a75a6342a33 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_finisher.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_finisher.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Gorilla finishers (owner D39)
*
@@ -7,7 +10,7 @@
* the head and it bursts (#509's burst; the brain is thrown out whole, so revival works). A helmet or
* plating crumples instead and the skull caves in. Needs gravity, or the brain would drift off.
* - Arm (the aimed one, else the other): the limb rip. A boot on the body, both fists on the arm, it tears
- * off at the shoulder with the spray running back over the bearer, and one blow to the head with it.
+ * off at the shoulder with the spray running back over the bearer, and he flings it away behind him.
* Armour on the arm wrenches the shoulder out instead.
* - Chest: the backbreaker. Pressed overhead, brought down across a knee, the back breaks and the body
* is shoved off it, still bent, onto the tile he faces (at his feet if that tile is blocked). Armour on
@@ -139,6 +142,9 @@
/// Takes every puppet down and shows both bodies.
/datum/hv_finisher/chrome/gorilla/proc/cleanup_rigs()
+ // Hidden behind his stand-ins he may have been turned (a click, a blocked step): he comes back facing the way they did
+ if(bearer_rig && facing && !QDELETED(user))
+ user.setDir(facing)
QDEL_NULL(bearer_rig)
QDEL_NULL(victim_rig)
@@ -213,13 +219,27 @@
if(sparks)
sparks.pixel_z += spark_z
sparks.pixel_w += spark_w
- var/turf/spot = get_turf(where)
+ // Where the blow is drawn, which is not the tile the body stands on when it is held off it (over his knee)
+ var/list/at = gorilla_drawn_spot(where, spark_w, spark_z)
+ var/turf/spot = at?[1]
if(spot)
// On the floor: on the game plane the ring was drawn over bodies standing further up the screen
- new /obj/effect/temp_visual/circle_wave/cyberware_slam/floor(spot, heavy ? 1 : 0.6)
+ new /obj/effect/temp_visual/circle_wave/cyberware_slam/floor(spot, heavy ? 1 : 0.6, at[2], at[3])
for(var/mob/living/viewer in range(4, spot))
if(viewer.client)
shake_camera(viewer, heavy ? 3 : 2, heavy ? 2 : 1)
+ return at
+
+/// The tile [where] is drawn on, [off_w], [off_z] pixels from its own middle, and how far from that tile's middle:
+/// list(turf, pixels across, pixels up), or null when it is nowhere.
+/proc/gorilla_drawn_spot(atom/movable/where, off_w = 0, off_z = 0)
+ var/turf/from = get_turf(where)
+ if(isnull(from))
+ return null
+ var/total_w = where.pixel_x + where.pixel_w + off_w
+ var/total_z = where.pixel_y + where.pixel_z + off_z
+ var/turf/spot = locate(clamp(from.x + round(total_w / ICON_SIZE_X, 1), 1, world.maxx), clamp(from.y + round(total_z / ICON_SIZE_Y, 1), 1, world.maxy), from.z) || from
+ return list(spot, round(total_w - (spot.x - from.x) * ICON_SIZE_X), round(total_z - (spot.y - from.y) * ICON_SIZE_Y))
// ---- The stages: each one hands its key to the finisher ----
@@ -771,11 +791,8 @@
/datum/hv_finisher_stage/hold/gorilla/rip_plant,
/datum/hv_finisher_stage/hold/gorilla/rip_strain,
/datum/hv_finisher_stage/kill/gorilla/rip,
- /datum/hv_finisher_stage/recover/gorilla/rip_club,
/datum/hv_finisher_stage/recover/gorilla/rip,
)
- /// The torn-off arm, held until it is dropped on the victim's tile
- var/obj/item/bodypart/held_limb
/// "l" or "r": the side of the victim's body the arm is on
var/side
/// The bearer's arm whose fist takes the wrist first ("l" or "r"); the other fist joins it
@@ -792,43 +809,26 @@
var/grip_stretch = 1
/// Where the fists hold the wrist: pixels from the middle of the bearer's tile
var/list/grip
- /// The torn arm's hand and shoulder in its own picture, list(hand_x, hand_y, shoulder_x, shoulder_y): the bearer
- /// holds it by the hand and swings the shoulder end
- var/list/club_ends
+// One grab, one haul, the tear and the throw on its follow-through, and he straightens up: 1.4 s. The stages run on the
+// finisher's 0.2 s tick, so each lasts a whole number of ticks.
/datum/hv_finisher_stage/hold/gorilla/rip_plant
key = "plant"
- duration = 0.5 SECONDS
+ duration = 0.4 SECONDS
enter_sound = 'sound/effects/gravhit.ogg'
enter_volume = 40
/datum/hv_finisher_stage/hold/gorilla/rip_strain
key = "strain"
- duration = 1.35 SECONDS
+ duration = 0.4 SECONDS
/datum/hv_finisher_stage/kill/gorilla/rip
key = "tear"
- duration = 0.8 SECONDS
-
-/datum/hv_finisher_stage/recover/gorilla/rip_club
- key = "club"
- duration = 0.45 SECONDS
- // Still held through the blow, so the body doesn't slide back off the grab under it. The hit is timed with the
- // swing (swing_club()), not this stage's beat, which only fires on the finisher's next tick.
- pins = TRUE
+ duration = 0.2 SECONDS
/datum/hv_finisher_stage/recover/gorilla/rip
key = "recover"
-
-/datum/hv_finisher/chrome/gorilla/rip/Destroy()
- drop_held_limb()
- return ..()
-
-/datum/hv_finisher/chrome/gorilla/rip/stop(reason)
- if(!running)
- return
- . = ..()
- drop_held_limb()
+ duration = 0.4 SECONDS
/// The aimed arm, else the other one.
/datum/hv_finisher/chrome/gorilla/rip/pick_zone()
@@ -865,7 +865,12 @@
for(var/arm_side in list("l", "r"))
var/obj/effect/abstract/chrome_puppet/own_arm = bearer_rig.puppet("arm_[arm_side]")
own_arm?.layer = user.layer - 0.01
- lean_out = list(-round(toward[1] / ICON_SIZE_X * GORILLA_RIP_LEAN), -round(toward[2] / ICON_SIZE_Y * GORILLA_RIP_LEAN))
+ if(facing == NORTH && !QDELETED(exec_bar))
+ // Facing away, the bar over his head would sit on the body and the arm he hauls up off it: under his feet
+ exec_bar.rest_z = GORILLA_RIP_BAR_LOW
+ exec_bar.pixel_z = GORILLA_RIP_BAR_LOW
+ animate(exec_bar, pixel_z = GORILLA_RIP_BAR_LOW, alpha = 255, time = 0.5 SECONDS, easing = SINE_EASING)
+ lean_out =list(-round(toward[1] / ICON_SIZE_X * GORILLA_RIP_LEAN), -round(toward[2] / ICON_SIZE_Y * GORILLA_RIP_LEAN))
lean = lean_out.Copy()
victim_rig = new(victim, victim.dir)
if(bearer_rig && victim_rig.snapshot())
@@ -892,16 +897,24 @@
// in by the arm as he hauls
body_shift = grab_pull_back()
lean = list(lean_out[1] + body_shift[1], lean_out[2] + body_shift[2])
+ if(!side_view())
+ // From the front or the back the body lies across his way: he steps in only until his boots meet it,
+ // as far whichever way he faces (it lies a few pixels low on its tile), and hauls back off it. The
+ // body stays where it lay (haul() doesn't drag it in), so the blood is under its stump at the tear
+ var/list/lay = lying_offsets || list(0, 0)
+ var/room = max(0, abs(body_origin()[2] - lay[2]) - GORILLA_RIP_STEP_GAP)
+ lean[2] = clamp(lean[2], -room, room)
+ lean_out = list(lean[1], lean[2] + (toward[2] > 0 ? GORILLA_RIP_STEP_BACK : -GORILLA_RIP_STEP_BACK))
for(var/key_name in victim_rig.puppets)
var/obj/effect/abstract/chrome_puppet/part = victim_rig.puppets[key_name]
part.pixel_x += body_shift[1]
part.pixel_y += body_shift[2]
// What stands in for it until its puppets can be drawn stands where they do
victim_rig.conceal(body_shift[1], body_shift[2])
- take_wrist(0.3 SECONDS, GORILLA_RIP_START_HOLD)
+ take_wrist(GORILLA_RIP_GRAB_TIME, GORILLA_RIP_START_HOLD)
else
QDEL_NULL(victim_rig)
- arms_to(side_view() ? 45 : 30, 0.3 SECONDS, 3)
+ arms_to(side_view() ? 45 : 30, GORILLA_RIP_GRAB_TIME, 3)
// A boot on the body: the bearer leans over them, arms and all (after the swings, which would cut
// the lean short on the arms). Nothing moves through the hold, while the puppets' pictures reach the
// client: they come on as the bodies stood, and then he steps in.
@@ -909,33 +922,26 @@
var/obj/effect/abstract/chrome_puppet/part = bearer_rig.puppets[key_name]
if(victim_rig)
animate(part, pixel_x = part.pixel_x, time = GORILLA_RIP_START_HOLD, flags = ANIMATION_PARALLEL)
- animate(pixel_x = part.pixel_x + lean[1], pixel_y = part.pixel_y + lean[2], time = 0.3 SECONDS, easing = SINE_EASING | EASE_OUT)
+ animate(pixel_x = part.pixel_x + lean[1], pixel_y = part.pixel_y + lean[2], time = GORILLA_RIP_GRAB_TIME, easing = SINE_EASING | EASE_OUT)
else
- animate(part, pixel_x = part.pixel_x + lean[1], pixel_y = part.pixel_y + lean[2], time = 0.3 SECONDS, easing = SINE_EASING | EASE_OUT, flags = ANIMATION_PARALLEL)
+ animate(part, pixel_x = part.pixel_x + lean[1], pixel_y = part.pixel_y + lean[2], time = GORILLA_RIP_GRAB_TIME, easing = SINE_EASING | EASE_OUT, flags = ANIMATION_PARALLEL)
+ // His bar goes with him: left over his tile, it hung half a tile behind the man leaning in on the body
+ if(bearer_rig && !QDELETED(exec_bar) && !exec_bar.ending)
+ if(victim_rig)
+ animate(exec_bar, pixel_x = 0, pixel_y = 0, time = GORILLA_RIP_START_HOLD, flags = ANIMATION_PARALLEL)
+ animate(pixel_x = lean[1], pixel_y = lean[2], time = GORILLA_RIP_GRAB_TIME, easing = SINE_EASING | EASE_OUT)
+ else
+ animate(exec_bar, pixel_x = lean[1], pixel_y = lean[2], time = GORILLA_RIP_GRAB_TIME, easing = SINE_EASING | EASE_OUT, flags = ANIMATION_PARALLEL)
if("strain")
if(victim_rig && grip)
- haul(1.3 SECONDS)
+ haul(GORILLA_RIP_HAUL_TIME)
else
- arms_to(side_view() ? 25 : 15, 1.3 SECONDS, 1)
- bearer_rig?.tremble(1.3 SECONDS)
- if("tear")
- // The arm gives: he yanks it back and comes upright
- bearer_rig?.bend_and_swing(0, side_view() ? -20 : 0, 0.1 SECONDS)
- if("club")
- if(held_limb)
- // Up over his head, then down on theirs, the hit landing as it comes down
- swing_club(GORILLA_CLUB_RAISE, GORILLA_CLUB_STRIKE)
- // A shade before the arm is all the way down: the server's timer runs a tick or two behind the client's swing
- addtimer(CALLBACK(src, PROC_REF(club_hit)), GORILLA_CLUB_RAISE + GORILLA_CLUB_STRIKE - GORILLA_CLUB_HIT_LEAD, TIMER_DELETE_ME)
- else
- arms_to(0, 0.4 SECONDS)
+ arms_to(side_view() ? 25 : 15, GORILLA_RIP_HAUL_TIME, 1)
+ addtimer(CALLBACK(bearer_rig, TYPE_PROC_REF(/datum/chrome_rig, tremble), GORILLA_RIP_STRAIN_TIME), GORILLA_RIP_HAUL_TIME - GORILLA_RIP_STRAIN_TIME, TIMER_DELETE_ME)
if("recover")
- bearer_rig?.drop_puppet("club")
- // The arm goes down with the body as he lets it go
- drop_held_limb()
// Down the way they point: not back up over his head the way they came
bearer_rig?.unwind_arms()
- arms_to(0, 0.5 SECONDS)
+ arms_to(0, 0.3 SECONDS)
// Let go, the body slides back to where tg lays it; its stand-ins go with it, and the real one shows there
if(victim_rig && !QDELETED(victim))
for(var/key_name in victim_rig.puppets)
@@ -945,7 +951,7 @@
// Straightens up off the body, so the real one shows where he stands (after the swing, as the lean was)
for(var/key_name in bearer_rig?.puppets)
var/obj/effect/abstract/chrome_puppet/part = bearer_rig.puppets[key_name]
- animate(part, pixel_x = user.pixel_x, pixel_y = user.pixel_y, time = 0.4 SECONDS, easing = SINE_EASING, flags = ANIMATION_PARALLEL)
+ animate(part, pixel_x = user.pixel_x, pixel_y = user.pixel_y, time = 0.3 SECONDS, easing = SINE_EASING, flags = ANIMATION_PARALLEL)
/// The middle of the bearer's puppets as drawn: pixels from the middle of his tile.
/datum/hv_finisher/chrome/gorilla/rip/proc/bearer_origin()
@@ -964,7 +970,12 @@
var/list/shoulder_at = body_shoulder_at()
var/list/left = bearer_shoulder_at("l", bearer_base)
var/list/right = bearer_shoulder_at("r", bearer_base)
- var/angle = arctan((left[1] + right[1]) / 2 - shoulder_at[1], (left[2] + right[2]) / 2 - shoulder_at[2])
+ var/to_x = (left[1] + right[1]) / 2
+ if(!side_view())
+ // From the front or the back, aside of his middle on the arm's own side: straight at him, his body hides it
+ // Facing away, his arms reach past his back and head, which hide them: further out, past his shoulder
+ to_x += (shoulder_at[1] < to_x ? -1 : 1) * (facing == NORTH ? GORILLA_RIP_HAUL_ASIDE_AWAY : GORILLA_RIP_HAUL_ASIDE)
+ var/angle = arctan(to_x - shoulder_at[1], (left[2] + right[2]) / 2 - shoulder_at[2])
if(side_view())
// Up toward the top of the screen, never past it
var/to_up = 90 - angle
@@ -1078,16 +1089,43 @@
still[key_name] = list(was[1], was[2], null)
all_poses += list(still)
step_times += hold
- for(var/i in 1 to steps)
- var/progress = (1 - cos(180 * i / steps)) / 2
- var/matrix/bent_now = bearer_rig.bend_matrix(bend * progress)
- var/list/poses = list()
- for(var/key_name in there)
- var/list/pose = there[key_name]
- var/list/was = start[key_name]
- poses[key_name] = list(was[1] + (pose[1] - was[1]) * progress, was[2] + (pose[2] - was[2]) * progress, key_name == "body" ? null : bent_now)
- all_poses += list(poses)
- step_times += time / steps
+ // His fists go down to the hand where it lies first (no further out than they take it), and only then does the arm
+ // come up with them: an arm rising on its own before he has it would look lifted by nothing
+ var/list/hand = victim_rig.hand_point(side)
+ var/list/body_at = body_origin()
+ var/list/hand_at = list(body_at[1] + hand[1], body_at[2] + hand[2])
+ var/list/reach_to = hand_at
+ var/list/fist_from = bearer_shoulder_at(grip_side, bent)
+ var/to_hand = sqrt((reach_to[1] - fist_from[1]) ** 2 + (reach_to[2] - fist_from[2]) ** 2)
+ var/to_grip = sqrt((grip[1] - fist_from[1]) ** 2 + (grip[2] - fist_from[2]) ** 2)
+ if(to_hand > to_grip && to_hand)
+ reach_to = list(fist_from[1] + (reach_to[1] - fist_from[1]) * to_grip / to_hand, fist_from[2] + (reach_to[2] - fist_from[2]) * to_grip / to_hand)
+ var/list/on_hand = poses_on(reach_to, now, bent)
+ on_hand["body"] = start["body"]
+ var/body_turn = now["body"]
+ var/list/phases = list(list(start, on_hand, time * GORILLA_RIP_REACH_SHARE), list(on_hand, there, time * (1 - GORILLA_RIP_REACH_SHARE)))
+ for(var/list/phase as anything in phases)
+ var/list/from_poses = phase[1]
+ var/list/to_poses = phase[2]
+ var/lifting = (to_poses == there)
+ for(var/i in 1 to steps)
+ var/progress = (1 - cos(180 * i / steps)) / 2
+ var/matrix/bent_now = bearer_rig.bend_matrix(bend * progress)
+ var/list/poses = list()
+ for(var/key_name in there)
+ if(lifting && key_name == "body")
+ var/keep = 1 - progress
+ var/wrist_x = keep * keep * hand_at[1] + 2 * keep * progress * reach_to[1] + progress * progress * grip[1]
+ var/wrist_y = keep * keep * hand_at[2] + 2 * keep * progress * reach_to[2] + progress * progress * grip[2]
+ var/list/body_pose = victim_rig.pose_reaching(side, wrist_x - body_at[1], wrist_y - body_at[2], body_turn)
+ body_turn = body_pose[1]
+ poses[key_name] = list(body_pose[1], body_pose[2], null)
+ continue
+ var/list/pose = to_poses[key_name]
+ var/list/was = from_poses[key_name]
+ poses[key_name] = list(was[1] + (pose[1] - was[1]) * progress, was[2] + (pose[2] - was[2]) * progress, key_name == "body" ? null : bent_now)
+ all_poses += list(poses)
+ step_times += phase[3] / steps
pose_through(all_poses, step_times)
/**
@@ -1114,7 +1152,9 @@
// Sine in and out, the same for every part
var/progress = (1 - cos(180 * i / GORILLA_RIP_HAUL_STEPS)) / 2
lean = list(round(lean_from[1] + (lean_out[1] - lean_from[1]) * progress, 1), round(lean_from[2] + (lean_out[2] - lean_from[2]) * progress, 1))
- body_shift = list(round(shift_from[1] * (1 - progress), 1), round(shift_from[2] * (1 - progress), 1))
+ // Seen from the side it is dragged in by the arm; from the front or back it stays where it lay
+ if(side_view())
+ body_shift = list(round(shift_from[1] * (1 - progress), 1), round(shift_from[2] * (1 - progress), 1))
victim_rig.base_transform = chrome_rig_turn_about_feet(flat, raised * progress)
leans += list(lean)
shifts += list(body_shift)
@@ -1140,10 +1180,35 @@
bearer_rig.base_transform = bearer_rig.bend_matrix(lean_back)
// After the swings and turns, which would cut these short: he steps back and the body comes with him
gorilla_offsets_through(bearer_rig.puppets, leans, user.pixel_x, user.pixel_y, step_time)
+ if(!QDELETED(exec_bar) && !exec_bar.ending) // and his bar steps back with him
+ for(var/i in 1 to length(leans))
+ var/list/point = leans[i]
+ if(i == 1)
+ animate(exec_bar, pixel_x = point[1], pixel_y = point[2], time = step_time, flags = ANIMATION_PARALLEL)
+ else
+ animate(pixel_x = point[1], pixel_y = point[2], time = step_time)
gorilla_offsets_through(victim_rig.puppets, shifts, victim.pixel_x, victim.pixel_y, step_time)
- // Both bodies shake together, so the fists stay on the wrist
- bearer_rig.tremble(time)
- victim_rig.tremble(time)
+ // One pull, no shaking until the end of it, where the arm holds in its socket a moment before it gives
+ addtimer(CALLBACK(src, PROC_REF(strain_shake)), max(0, time - GORILLA_RIP_STRAIN_TIME), TIMER_DELETE_ME)
+
+/// The end of the haul: both bodies shake together, so the fists stay on the wrist.
+/datum/hv_finisher/chrome/gorilla/rip/proc/strain_shake()
+ if(!running)
+ return
+ // Until the arm gives, if the tear comes a tick late. Every puppet of both bodies takes the same steps, so the fists
+ // stay on the wrist; each step is relative and they add up to nothing, so nothing is left off its place
+ var/static/list/shakes = list(2, -4, 4, -4, 4, -2)
+ var/step_time = GORILLA_RIP_STRAIN_TIME * 2 / length(shakes)
+ var/list/parts = list()
+ for(var/datum/chrome_rig/rig as anything in list(bearer_rig, victim_rig))
+ for(var/key_name in rig?.puppets)
+ parts += rig.puppets[key_name]
+ for(var/obj/effect/abstract/chrome_puppet/part as anything in parts)
+ for(var/i in 1 to length(shakes))
+ if(i == 1)
+ animate(part, pixel_w = shakes[i], time = step_time, flags = ANIMATION_RELATIVE | ANIMATION_PARALLEL)
+ else
+ animate(pixel_w = shakes[i], time = step_time, flags = ANIMATION_RELATIVE)
/**
* Degrees (clockwise) to turn the body lying as [flat] turns it about its feet as the arm is hauled toward [point] (pixels
@@ -1205,13 +1270,46 @@
* stump and all; else the arm is still its own piece.
*/
/datum/hv_finisher/chrome/gorilla/rip/proc/redraw_bodies(torn)
- bearer_rig?.redraw_arms()
+ if(torn)
+ redraw_bearer()
if(QDELETED(victim) || !victim_rig?.snapshot())
return
victim_rig.repaint("body", torn ? victim_rig.flat : victim_rig.cut_without_arms(side))
if(!torn)
victim_rig.repaint("arm_[side]", victim_rig.arm_picture(side))
+/// The bearer's stand-ins take on how he looks now, without any passing hit flash or turn made while hidden.
+/datum/hv_finisher/chrome/gorilla/rip/proc/redraw_bearer()
+ if(!running || QDELETED(user) || !bearer_rig)
+ return
+ user.remove_filter(HV_VIS_FLASH_FILTER)
+ var/real_dir = user.dir
+ var/saved_color = user.color
+ var/had_temp_color = !isnull(LAZYACCESS(user.atom_colours, TEMPORARY_COLOUR_PRIORITY))
+ if(had_temp_color)
+ var/resting_color
+ for(var/priority in 1 to length(user.atom_colours))
+ if(priority == TEMPORARY_COLOUR_PRIORITY)
+ continue
+ var/list/entry = user.atom_colours[priority]
+ if(!entry)
+ continue
+ if(entry[ATOM_COLOR_TYPE_INDEX] == ATOM_COLOR_TYPE_FILTER)
+ break
+ if(length(entry[ATOM_COLOR_VALUE_INDEX]))
+ resting_color = entry[ATOM_COLOR_VALUE_INDEX]
+ break
+ user.color = resting_color
+ if(facing)
+ user.dir = facing
+ var/redrawn = bearer_rig.redraw_arms()
+ user.dir = real_dir
+ if(had_temp_color)
+ user.color = saved_color
+ if(redrawn)
+ for(var/key_name in bearer_rig.puppets)
+ cyberware_time_rig_picture(bearer_rig.puppets[key_name], user)
+
/// Blood bursts every way from the socket the arm just left, where the shoulder is drawn at that moment.
/datum/hv_finisher/chrome/gorilla/rip/proc/shoulder_burst()
var/turf/spot = get_turf(victim)
@@ -1239,7 +1337,18 @@
// Off a body still on its feet it lands at them
if(victim.body_position != LYING_DOWN)
joint[2] = CHROME_RIG_FEET_Y + victim.pixel_y + victim.pixel_z
+ else
+ // Out past the stump, where the body lying over it doesn't hide it as it runs
+ var/out_x = joint[1] - (victim.pixel_x + victim.pixel_w)
+ var/out_y = joint[2] - (victim.pixel_y + victim.pixel_z)
+ var/out = sqrt(out_x * out_x + out_y * out_y)
+ if(out)
+ joint[1] += out_x / out * GORILLA_RIP_POOL_OUT
+ joint[2] += out_y / out * GORILLA_RIP_POOL_OUT
var/list/back = grab_pull_back()
+ if(!side_view())
+ // Seen from the front or back the body was never dragged in: the pool goes where the stump is, all along
+ return list(clamp(round(joint[1] + back[1]), -GORILLA_RIP_POOL_REACH, GORILLA_RIP_POOL_REACH), clamp(round(joint[2] + back[2]), -GORILLA_RIP_POOL_REACH, GORILLA_RIP_POOL_REACH))
return list(clamp(round(joint[1] + back[1] / 2), -GORILLA_RIP_POOL_REACH, GORILLA_RIP_POOL_REACH), clamp(round(joint[2] + back[2] / 2), -GORILLA_RIP_POOL_REACH, GORILLA_RIP_POOL_REACH))
/**
@@ -1266,10 +1375,14 @@
for(var/i in 1 to count)
var/angle = start + i * (360 / count) + rand(-14, 14)
var/distance = pick(reach) + rand(-2, 2)
+ var/rim = min(4, max(0, distance - 1))
+ var/start_x = from_x + round(sin(angle) * rim)
+ var/start_y = from_y + round(cos(angle) * rim)
var/land_x = from_x + round(sin(angle) * distance)
var/land_y = from_y + round(cos(angle) * distance)
- // list(start x, start y, land x, land y, arc height, flight time, wait): the monowire's drop, which lands as a drip
- new /obj/effect/temp_visual/wire_blood_drop(origin, list(from_x, from_y, land_x, land_y, 3 + rand(0, 5), round(1.5 + distance / 14, 0.5), 0), blood_color, blood_dna, viruses)
+ // list(start x, start y, land x, land y, arc height, flight time, wait, behind): leaves an elevated shoulder in front
+ // of the body, never under it, and lands as a floor drip
+ new /obj/effect/temp_visual/wire_blood_drop(origin, list(start_x, start_y, land_x, land_y, 3 + rand(0, 5), round(1.5 + distance / 14, 0.5), 0, FALSE), blood_color, blood_dna, viruses)
/**
* Moves [pool] (blood just laid on the floor) so its middle is [x], [y] pixels from the middle of its tile, and keeps it
@@ -1362,259 +1475,144 @@
else
hit_stop(victim)
var/outcome = gorilla_limb_rip(victim, target_zone, user, fist(), pool_spot())
+ // The blow's pale flash is on the real body, hidden behind its stand-ins, which flash on their own: redrawn
+ // from it now, they would stay pale until he lets go
+ victim.remove_filter(HV_VIS_FLASH_FILTER)
// Both bodies are hidden behind their stand-ins, and so is what this just did to them (the stump, the blood
- // that ran back over him): the stand-ins take it on now, or it would only show when they come down
+ // that ran back over him): the stand-ins take it on now, before his swing starts, or it would only show later
redraw_bodies(outcome == "torn")
+ // The arm gives: he comes upright and both arms swing on with it, flinging it away: back past him seen
+ // from the side, out wide from the front or back
+ bearer_rig?.bend_and_swing(0, side_view() ? -GORILLA_RIP_THROW_SWING : GORILLA_RIP_THROW_SWING, 0.15 SECONDS, GORILLA_RIP_THROW_REACH)
if(outcome == "torn")
- held_limb = gorilla_last_torn_limb(victim, target_zone)
- if(held_limb?.can_bleed())
+ var/obj/item/bodypart/torn = gorilla_last_torn_limb(victim, target_zone)
+ if(torn?.can_bleed())
shoulder_burst()
- // The arm goes with the bearer's fists; the body drops back to the floor
- var/obj/effect/abstract/chrome_puppet/arm = victim_rig?.puppet("arm_[side]")
- if(arm && bearer_rig)
- var/list/arm_shoulder = victim_rig.shoulder(side)
- var/list/arm_hand = victim_rig.hand_offset(side)
- club_ends = list(arm_shoulder[1] + arm_hand[1], arm_shoulder[2] + arm_hand[2], arm_shoulder[1], arm_shoulder[2])
- victim_rig.puppets -= "arm_[side]"
- bearer_rig.puppets["club"] = arm
- // Drawn where it was, from the bearer's tile
- var/list/toward = to_bearer()
- arm.pixel_x -= toward[1]
- arm.pixel_y -= toward[2]
- arm.forceMove(get_turf(user))
- // In his fists, over them. Seen from behind he holds it on his far side, so his body hides it
- arm.layer = facing == NORTH ? user.layer - 0.005 : user.layer + 0.03
- if(grip && facing == NORTH)
- // Yanked back lying as it was hauled, it would cross the back of his legs and reach past his feet.
- // It comes down in his fist, back to its own length, and hangs from it beside him
- var/list/origin = bearer_origin()
- hang_club(arm, list(grip[1] - origin[1], grip[2] - origin[2]), bearer_rig.hand_point(grip_side))
- else if(grip)
- // ...and yanked back with the fist that held it
- var/list/fist_at = bearer_rig.hand_point(grip_side)
- var/list/origin = bearer_origin()
- animate(arm, pixel_x = arm.pixel_x + round(origin[1] + fist_at[1] - grip[1]), pixel_y = arm.pixel_y + round(origin[2] + fist_at[2] - grip[2]), time = 0.1 SECONDS, easing = SINE_EASING)
- else
- arm.pixel_x = 0
- arm.pixel_y = 0
- arm.pixel_z = 6
- arm.transform = matrix().Turn(100)
+ // It comes away in his fists and goes on over his shoulder with the follow-through
+ throw_torn_arm(torn)
+ // Snapped back off the body, and the step back is taken up again
+ var/list/toward = to_bearer()
+ var/back_x = SIGN(toward[1]) * 2
+ var/back_y = SIGN(toward[2]) * 2
for(var/key_name in bearer_rig?.puppets)
var/obj/effect/abstract/chrome_puppet/part = bearer_rig.puppets[key_name]
- animate(part, pixel_w = -2, time = 0.1 SECONDS, flags = ANIMATION_RELATIVE | ANIMATION_PARALLEL)
- animate(pixel_w = 2, time = 0.3 SECONDS, flags = ANIMATION_RELATIVE)
+ animate(part, pixel_w = back_x, pixel_z = back_y, time = 0.1 SECONDS, flags = ANIMATION_RELATIVE | ANIMATION_PARALLEL)
+ animate(pixel_w = -back_x, pixel_z = -back_y, time = 0.2 SECONDS, flags = ANIMATION_RELATIVE)
// It drops back to the floor as the arm gives
fall_back()
/**
- * The torn arm ([club]) goes with the fist that holds its hand, from [from_fist] to [fist_at] (pixels from the middle of
- * his puppets), swinging about it in short steps to hang straight down. The fist is at his side, and the arm back at
- * its own length, by half way.
+ * The torn arm leaves his fists and flies GORILLA_RIP_THROW_TILES out to his side, spinning, and lies where it lands. It
+ * is the real arm from the first frame: put on the tile it lands on at once, and drawn from where the hauled one was,
+ * so where its flight ends is where it lies. Out to the side it was hauled to if that way is open, else the other side,
+ * else behind him; with nowhere open it drops at his feet. A way that takes it across him is a tile shorter, so it flies
+ * about as far from his fists whichever way it goes.
*/
-/datum/hv_finisher/chrome/gorilla/rip/proc/hang_club(obj/effect/abstract/chrome_puppet/club, list/from_fist, list/fist_at)
- var/held_length = club_length()
- if(!held_length)
+/datum/hv_finisher/chrome/gorilla/rip/proc/throw_torn_arm(obj/item/bodypart/torn)
+ if(QDELETED(torn))
return
- var/matrix/drawn = club.transform
- var/list/hand_now = chrome_rig_apply(drawn, club_ends[1], club_ends[2])
- var/list/stump_now = chrome_rig_apply(drawn, club_ends[3], club_ends[4])
- var/angle_now = arctan(stump_now[1] - hand_now[1], stump_now[2] - hand_now[2])
- var/stretch_now = sqrt((stump_now[1] - hand_now[1]) ** 2 + (stump_now[2] - hand_now[2]) ** 2) / held_length
- var/turn = -90 - angle_now
- while(turn > 180)
- turn -= 360
- while(turn <= -180)
- turn += 360
- var/steps = max(4, bearer_rig.swing_steps(0, turn))
- var/obj/effect/abstract/chrome_puppet/own_arm = bearer_rig.puppet("arm_[grip_side]")
+ var/turf/start = get_turf(user) || get_turf(victim)
+ if(!start)
+ return
+ // Where the hauled arm is drawn now (pixels from the middle of his tile), and which way it points, hand to shoulder
+ var/list/from
+ var/along = 90
+ var/obj/effect/abstract/chrome_puppet/hauled = victim_rig?.puppet("arm_[side]")
+ if(hauled)
+ var/list/pivot = victim_rig.shoulder(side)
+ var/list/hand = victim_rig.hand_offset(side)
+ var/list/hand_at = chrome_rig_apply(hauled.transform, pivot[1] + hand[1], pivot[2] + hand[2])
+ var/list/stump_at = chrome_rig_apply(hauled.transform, pivot[1], pivot[2])
+ var/off_x = (hauled.x - start.x) * ICON_SIZE_X + hauled.pixel_x + hauled.pixel_w
+ var/off_y = (hauled.y - start.y) * ICON_SIZE_Y + hauled.pixel_y + hauled.pixel_z
+ from = list(round(off_x + (hand_at[1] + stump_at[1]) / 2), round(off_y + (hand_at[2] + stump_at[2]) / 2))
+ along = arctan(stump_at[1] - hand_at[1], stump_at[2] - hand_at[2])
+ // The real arm takes its place
+ victim_rig.drop_puppet("arm_[side]")
+ else
+ var/list/shoulder_at = gorilla_shoulder_at(victim, side)
+ from = list(round((victim.x - start.x) * ICON_SIZE_X + shoulder_at[1]), round((victim.y - start.y) * ICON_SIZE_Y + shoulder_at[2]))
+ // Out to his side, clear of both bodies: the furthest open way of these, the first of them on a tie. The side the
+ // arm is already on comes first; thrown the other way it would cross him and fly a tile further than it reads.
+ var/toward = get_dir(user, victim) || user.dir
+ var/list/ways = list(turn(toward, 90), turn(toward, -90), REVERSE_DIR(toward))
+ if(gorilla_throw_same_side(from, ways[2]) && !gorilla_throw_same_side(from, ways[1]))
+ ways.Swap(1, 2)
+ var/turf/land = start
+ var/best = 0
+ for(var/heading in ways)
+ var/same_side = gorilla_throw_same_side(from, heading)
+ var/list/turf/path = hv_vis_fling_path(start, heading, same_side ? GORILLA_RIP_THROW_TILES : max(1, GORILLA_RIP_THROW_TILES - 1))
+ var/reach = length(path) + ((!same_side && length(path)) ? 1 : 0) // it started a tile's worth on the far side
+ if(reach > best)
+ best = reach
+ land = path[length(path)]
+ var/list/blood_dna = torn.can_bleed() ? torn.blood_dna_info : null
+ var/dx = (land.x - start.x) * ICON_SIZE_X
+ var/dy = (land.y - start.y) * ICON_SIZE_Y
+ // It comes down a little short of the middle of its tile, on the side it came from
+ var/rest_x = -SIGN(dx) * GORILLA_RIP_THROW_SHORT
+ var/rest_y = -SIGN(dy) * GORILLA_RIP_THROW_SHORT
+ // Spun about its own picture, from the way it was hauled (the dropped arm hangs hand down: straight up is no turn)
+ // round to lying as it lands, whole turns the way it was thrown
+ var/list/spin_about = torn.hv_vis_spin_pivot()
+ var/start_turn = 90 - along
+ var/spin_sign = (dx || dy) ? ((dx > 0 || (!dx && dy < 0)) ? 1 : -1) : 1
+ var/end_turn = round((start_turn + spin_sign * GORILLA_RIP_THROW_SPINS * 360) / 360) * 360
+ var/matrix/base = matrix(torn.transform)
+ // Drawn where the hauled arm was before it is put on its tile, so its first frame is there; over him, but for seen
+ // from behind, where his body hid the arm in his fists
+ var/matrix/start_spun = hv_vis_turned(base, start_turn, spin_about[2], spin_about[1])
+ torn.pixel_x = from[1] - dx
+ torn.pixel_y = from[2] - dy
+ torn.pixel_w = 0
+ torn.pixel_z = 0
+ torn.transform = start_spun
+ torn.layer = facing == NORTH ? user.layer - 0.01 : user.layer + 0.03
+ torn.forceMove(land)
+ animate(torn, pixel_x = from[1] - dx, pixel_y = from[2] - dy, pixel_z = 0, transform = start_spun, time = 0)
+ var/steps = GORILLA_RIP_THROW_STEPS
for(var/i in 1 to steps)
var/progress = i / steps
- var/yanked = min(1, progress * 2)
- var/matrix/hung = club_matrix(from_fist[1] + (fist_at[1] - from_fist[1]) * yanked, from_fist[2] + (fist_at[2] - from_fist[2]) * yanked, angle_now + turn * progress, stretch_now + (1 - stretch_now) * yanked)
- if(i == 1)
- // From here on its transform alone puts it in his fist, from where his own arm stands
- animate(club, transform = hung, pixel_x = own_arm?.pixel_x || 0, pixel_y = own_arm?.pixel_y || 0, pixel_z = own_arm?.pixel_z || 0, time = GORILLA_RIP_HANG_TIME / steps)
- else
- animate(transform = hung, time = GORILLA_RIP_HANG_TIME / steps)
-
-/// The middle of the victim's head as drawn, lying or not: pixels from the middle of the bearer's tile.
-/datum/hv_finisher/chrome/gorilla/rip/proc/victim_head_at()
- var/list/head = chrome_rig_apply(victim.transform, 0, CHROME_RIG_NECK_PIVOT_Y + 3.5)
- return list((victim.x - user.x) * ICON_SIZE_X + victim.pixel_x + victim.pixel_w + head[1], (victim.y - user.y) * ICON_SIZE_Y + victim.pixel_y + victim.pixel_z + head[2])
-
-/// The torn arm's length in its own picture, hand to shoulder.
-/datum/hv_finisher/chrome/gorilla/rip/proc/club_length()
- return sqrt((club_ends[3] - club_ends[1]) ** 2 + (club_ends[4] - club_ends[2]) ** 2)
-
-/**
- * The torn arm held by its hand at [fist_x], [fist_y] (pixels from the middle of the bearer's puppets), its shoulder
- * end pointing [angle] degrees round from the right (anticlockwise), [stretch] times its length.
- */
-/datum/hv_finisher/chrome/gorilla/rip/proc/club_matrix(fist_x, fist_y, angle, stretch = 1)
- var/along = arctan(club_ends[3] - club_ends[1], club_ends[4] - club_ends[2])
- return chrome_rig_turn(along - angle, club_ends[1], club_ends[2], fist_x - club_ends[1], fist_y - club_ends[2], 1, stretch)
-
-/// The degrees from [from_angle] to [to_angle], turning the way [arm_turned] went (anticlockwise positive) when they are far apart.
-/proc/gorilla_turn_with(from_angle, to_angle, arm_turned)
- var/turned = to_angle - from_angle
- while(turned > 180)
- turned -= 360
- while(turned <= -180)
- turned += 360
- if(abs(arm_turned) > 90 && turned * arm_turned < 0)
- turned += arm_turned > 0 ? 360 : -360
- return turned
-
-/**
- * The blow with the torn arm: both fists swing it up over his head in [raise], then bring it down on the victim's
- * head in [strike], so it lands as the arms come down. The arm in his fists goes through the same short steps as
- * his arms, held by its hand in the fist that tore it off.
- */
-/datum/hv_finisher/chrome/gorilla/rip/proc/swing_club(raise, strike)
- if(!bearer_rig)
- return
- var/obj/effect/abstract/chrome_puppet/club = club_ends ? bearer_rig.puppet("club") : null
- var/holding = grip_side || bearer_rig.near_side()
- var/list/origin = bearer_origin()
- // The blow comes down from his shoulders onto the head; the fists go out as far along it as the arm in them doesn't
- var/list/head = victim_head_at()
- var/list/left = bearer_rig.shoulder("l")
- var/list/right = bearer_rig.shoulder("r")
- var/from_x = (left[1] + right[1]) / 2
- var/from_y = (left[2] + right[2]) / 2
- var/to_x = head[1] - origin[1] - from_x
- var/to_y = head[2] - origin[2] - from_y
- var/apart = sqrt(to_x * to_x + to_y * to_y)
- var/blow_angle = arctan(to_x, to_y)
- var/held_length = club ? club_length() : 0
- var/fist_along = clamp(apart - held_length, 0, GORILLA_CLUB_REACH * bearer_rig.arm_reach(holding))
- var/blow_stretch = held_length ? clamp((apart - fist_along) / held_length, 1, GORILLA_CLUB_MAX_STRETCH) : 1
- var/fist_x = from_x + fist_along * cos(blow_angle)
- var/fist_y = from_y + fist_along * sin(blow_angle)
- // Overhead: seen from the side up and back, the arm hanging back over his head; from the front or from behind
- // straight up, where both his arms and the arm in them show over his head
- var/club_up
- var/list/poses_now = list()
- var/list/poses_up = list()
- var/list/poses_down = list()
- for(var/arm_side in list("l", "r"))
- poses_now[arm_side] = bearer_rig.arm_poses[arm_side] || list(0, 1)
- var/list/up
- if(side_view())
- up = list(200 * bearer_rig.raise_sign(arm_side), 1.2)
- club_up = facing == EAST ? 145 : 35
- else
- up = list(170 * bearer_rig.raise_sign(arm_side), 1.1)
- club_up = 90
- poses_up[arm_side] = up
- var/list/down = bearer_rig.pose_reaching(arm_side, fist_x, fist_y, up[1])
- down[2] = min(down[2], GORILLA_CLUB_REACH)
- poses_down[arm_side] = down
- // Every arm goes through the same steps: sine up, then faster and faster down
- var/up_steps = 1
- var/down_steps = 1
- for(var/arm_side in list("l", "r"))
- var/list/now = poses_now[arm_side]
- var/list/up = poses_up[arm_side]
- var/list/down = poses_down[arm_side]
- up_steps = max(up_steps, bearer_rig.swing_steps(now[1], up[1]))
- down_steps = max(down_steps, bearer_rig.swing_steps(up[1], down[1]))
- var/list/progress = list()
- var/list/step_times = list()
- for(var/i in 1 to up_steps)
- progress += (1 - cos(180 * i / up_steps)) / 2
- step_times += raise / up_steps
- for(var/i in 1 to down_steps)
- progress += 1 - cos(90 * i / down_steps)
- step_times += strike / down_steps
- var/list/arm_steps = list("l" = list(), "r" = list())
- for(var/i in 1 to length(progress))
- var/rising = i <= up_steps
- for(var/arm_side in list("l", "r"))
- var/list/was = rising ? poses_now[arm_side] : poses_up[arm_side]
- var/list/will = rising ? poses_up[arm_side] : poses_down[arm_side]
- arm_steps[arm_side] += list(list(was[1] + (will[1] - was[1]) * progress[i], was[2] + (will[2] - was[2]) * progress[i]))
- for(var/arm_side in arm_steps)
- bearer_rig.pose_arm_through(arm_side, arm_steps[arm_side], step_times)
- if(!club)
+ // Whole turns: it lands lying exactly as it will lie
+ var/matrix/spun = i == steps ? matrix(base) : hv_vis_turned(base, start_turn + (end_turn - start_turn) * progress, spin_about[2], spin_about[1])
+ var/height = round(GORILLA_RIP_THROW_ARC * 4 * progress * (1 - progress))
+ var/to_x = round(from[1] - dx + (rest_x - from[1] + dx) * progress)
+ var/to_y = round(from[2] - dy + (rest_y - from[2] + dy) * progress)
+ animate(pixel_x = to_x, pixel_y = to_y, pixel_z = height, transform = spun, time = GORILLA_RIP_THROW_TIME / steps)
+ if(length(blood_dna))
+ // A drop half way and one beside it where it lands (under it, the arm hid the drop), each as it gets there
+ var/turf/half_way = get_dist(start, land) > 1 ? get_step(start, get_dir(start, land)) : null
+ if(half_way)
+ gorilla_drop_in_time(half_way, blood_dna, round((from[1] - dx + rest_x) / 2 + (start.x - half_way.x) * ICON_SIZE_X + dx), round((from[2] - dy + rest_y) / 2 + (start.y - half_way.y) * ICON_SIZE_Y + dy), GORILLA_RIP_THROW_TIME / 2)
+ gorilla_drop_in_time(land, blood_dna, rest_x + (dx < 0 ? -6 : 6), rest_y - 3, GORILLA_RIP_THROW_TIME)
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(gorilla_torn_arm_landed), torn, land, initial(torn.layer)), GORILLA_RIP_THROW_TIME, TIMER_DELETE_ME)
+
+/// Whether a throw heading [heading] goes off on the side the arm is already drawn on ([from]: pixels from the thrower).
+/proc/gorilla_throw_same_side(list/from, heading)
+ var/across = ((heading & EAST) ? 1 : 0) - ((heading & WEST) ? 1 : 0)
+ var/up = ((heading & NORTH) ? 1 : 0) - ((heading & SOUTH) ? 1 : 0)
+ return from[1] * across + from[2] * up >= 0
+
+/// A drop of blood laid on [spot] at [x], [y] pixels from its middle, [delay] from now. It is made when it lands: made
+/// at once and hidden until then, it pooled with any drop already on the tile and was gone.
+/proc/gorilla_drop_in_time(turf/spot, list/blood_dna, x, y, delay)
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(gorilla_lay_drop), spot, blood_dna, x, y), delay, TIMER_DELETE_ME)
+
+/proc/gorilla_lay_drop(turf/spot, list/blood_dna, x, y)
+ if(!isturf(spot) || isgroundlessturf(spot) || !spot.has_gravity())
return
- // The torn arm turns the way the arm holding it does, from where it hangs in the fist now
- var/matrix/drawn = club.transform
- var/list/hand_now = chrome_rig_apply(drawn, club_ends[1], club_ends[2])
- var/list/stump_now = chrome_rig_apply(drawn, club_ends[3], club_ends[4])
- var/club_now = arctan(stump_now[1] - hand_now[1], stump_now[2] - hand_now[2])
- var/stretch_now = held_length ? sqrt((stump_now[1] - hand_now[1]) ** 2 + (stump_now[2] - hand_now[2]) ** 2) / held_length : 1
- var/list/hold_now = poses_now[holding]
- var/list/hold_up = poses_up[holding]
- var/list/hold_down = poses_down[holding]
- // Arm turns are clockwise, the arm's angles anticlockwise
- var/turn_up = gorilla_turn_with(club_now, club_up, hold_now[1] - hold_up[1])
- var/turn_down = gorilla_turn_with(club_now + turn_up, blow_angle, hold_up[1] - hold_down[1])
- var/obj/effect/abstract/chrome_puppet/holding_arm = bearer_rig.puppet("arm_[holding]")
- var/list/held_steps = arm_steps[holding]
- for(var/i in 1 to length(held_steps))
- var/rising = i <= up_steps
- var/list/fist = bearer_rig.hand_at(holding, held_steps[i])
- var/angle = rising ? club_now + turn_up * progress[i] : club_now + turn_up + turn_down * progress[i]
- var/stretch = rising ? stretch_now + (1 - stretch_now) * progress[i] : 1 + (blow_stretch - 1) * progress[i]
- var/matrix/held = club_matrix(fist[1], fist[2], angle, stretch)
- if(i == 1)
- animate(club, transform = held, pixel_x = holding_arm?.pixel_x || 0, pixel_y = holding_arm?.pixel_y || 0, pixel_w = 0, pixel_z = holding_arm?.pixel_z || 0, time = step_times[i])
- else
- animate(transform = held, time = step_times[i])
-
-/// The torn arm lands on the victim's head.
-/datum/hv_finisher/chrome/gorilla/rip/proc/club_hit()
- if(!running || QDELETED(victim) || !held_limb)
+ var/obj/effect/decal/cleanable/blood/drip/wire_flick/drop = new(spot, null, blood_dna)
+ if(QDELETED(drop))
return
- var/obj/item/bodypart/head = victim.get_bodypart(BODY_ZONE_HEAD)
- victim.hv_hold_attack_message("[user] beats [victim] with [victim.p_their()] own arm!", "[user] beats you with your own arm!", "You beat [victim] with [victim.p_their()] own arm!", user, vision_range = DEFAULT_MESSAGE_RANGE)
- // None of #509's heavy-hit spray for this blow: its fan lands a tile out past the body, nowhere near the head
- gorilla_hold_spray(victim)
- victim.apply_damage(15, BRUTE, head || BODY_ZONE_CHEST, victim.run_armor_check(head, MELEE), wound_bonus = CANT_WOUND, attack_direction = get_dir(user, victim), attacking_item = fist())
- victim.hv_flush_hit()
- playsound(victim, 'sound/effects/wounds/splatter.ogg', 60, TRUE)
- // The blow's wound is drawn on the hidden body: its stand-in takes it on, and takes the hit
- var/obj/effect/abstract/chrome_puppet/body_puppet = victim_rig?.puppet("body")
- if(body_puppet && victim_rig.snapshot())
- victim_rig.repaint("body", victim_rig.puppet("arm_[side]") ? victim_rig.cut_without_arms(side) : victim_rig.flat)
- var/obj/effect/abstract/cyberware_anim/impact = gorilla_play_impact(user, body_puppet || victim, "impact_gorilla")
- if(impact && body_puppet)
- // On the head, where the arm lands. On a puppet it keeps the puppet's place but not its turn: the head as it lies
- var/list/head_at = chrome_rig_apply(victim.transform, 0, CHROME_RIG_NECK_PIVOT_Y + 3.5)
- impact.pixel_w += round(head_at[1])
- impact.pixel_z += round(head_at[2])
- else if(impact)
- // It rides on the body, so its offset turns with a lying one: up is the head
- impact.pixel_y += round(CHROME_RIG_NECK_PIVOT_Y + 3.5)
- // Not tg's Shake(): its first step takes pixel_y from pixel_x, which throws a body pulled in by a grab a third of a
- // tile aside for a frame
- if(body_puppet)
- for(var/key_name in victim_rig.puppets)
- gorilla_shudder(victim_rig.puppets[key_name], 2, 1, 0.2 SECONDS)
- else
- gorilla_shudder(victim, 2, 1, 0.2 SECONDS)
- if(held_limb.can_bleed())
- victim.add_splatter_floor(get_turf(victim), small_drip = TRUE)
+ drop.wire_place(x, y)
-/// Puts the torn arm down on the victim's tile, wherever the finisher stopped.
-/datum/hv_finisher/chrome/gorilla/rip/proc/drop_held_limb()
- if(isnull(held_limb))
+/// The thrown arm has come down on [land]: a wet slap, and it lies with everything else on the floor.
+/proc/gorilla_torn_arm_landed(obj/item/bodypart/torn, turf/land, rest_layer)
+ if(QDELETED(torn) || torn.loc != land)
return
- var/obj/item/bodypart/limb = held_limb
- held_limb = null
- if(QDELETED(limb))
- return
- var/turf/spot = get_turf(victim) || get_turf(user)
- if(spot)
- limb.forceMove(spot)
- // What still runs out of it as it lands: a drip, into the pool from the tear where there is one. Not a fresh
- // splash on the body's tile a second after the wound
- if(limb.can_bleed())
- if(!QDELETED(victim) && get_turf(victim) == spot)
- victim.add_splatter_floor(spot, TRUE)
- else
- new /obj/effect/decal/cleanable/blood/drip(spot, null, limb.blood_dna_info)
+ torn.layer = rest_layer
+ playsound(torn, 'sound/misc/moist_impact.ogg', 40, TRUE)
/// The arm just torn from [victim] at [zone], waiting in nullspace, or null.
/proc/gorilla_last_torn_limb(mob/living/carbon/victim, zone)
@@ -1652,7 +1650,7 @@
if(hv_crit_apply_wound(limb, /datum/wound/blunt/bone/moderate, toward_bearer, fist))
victim.hv_add_hit_line("[victim]'s shoulder wrenches out of its socket!", HV_LINE_BOLD, "Your shoulder wrenches out of its socket!")
victim.hv_flush_hit()
- do_sparks(2, TRUE, victim)
+ // No do_sparks() here: the wrench has its own spark at the shoulder, and tg's sparks wander off across the floor
log_combat(user, victim, "dislocated the arm of", "gorilla arms")
return "dislocated"
// The spray runs back at the bearer: the last hit on the body came from them.
@@ -1661,6 +1659,8 @@
// One straight line back at the bearer, who takes it; no fan past him
if(limb.can_bleed())
gorilla_short_spray(victim, toward_bearer, 2)
+ if(!QDELETED(user) && victim.can_bleed(BLOOD_COVER_TURFS) == BLEED_SPLATTER)
+ user.hv_blood_drench(victim.get_blood_dna_list(), victim.get_static_viruses())
var/obj/item/bodypart/torn = gorilla_tear_limb(victim, limb, toward_bearer, TRUE, blood_at)
victim.hv_flush_hit()
if(isnull(torn))
@@ -1691,21 +1691,29 @@
LAZYSET(victim.body_zone_dismembered_by, limb.body_zone, WOUND_BLUNT)
var/bleeds = limb.can_bleed()
var/turf/spot = get_turf(victim)
- var/list/old_blood = list()
- if(blood_at && isturf(spot))
+ // tg lays the blood on the middle of the tile, which a body held in a grab is drawn well off. The splatter the tear
+ // bleeds into is put under the stump before the bleed turns it into a pool: moved after, with the pool's spread
+ // already animating, it was drawn on the middle of the tile until the spread was done.
+ var/obj/effect/decal/cleanable/blood/under_stump
+ var/laid_here = FALSE
+ if(bleeds && blood_at && isturf(spot) && !isgroundlessturf(spot) && spot.has_gravity() && victim.can_bleed(BLOOD_COVER_TURFS) == BLEED_SPLATTER)
for(var/obj/effect/decal/cleanable/blood/there in spot)
- old_blood += there
+ if(there.type == /obj/effect/decal/cleanable/blood && !there.dried && !QDELETED(there))
+ under_stump = there
+ break
+ if(!under_stump)
+ under_stump = new(spot, null, victim.get_blood_dna_list())
+ laid_here = !QDELETED(under_stump)
+ if(QDELETED(under_stump))
+ under_stump = null
+ else if(!under_stump.hv_pool_tier) // a pool already spread there stays where it is
+ gorilla_place_blood(under_stump, blood_at[1], blood_at[2])
if(bleeds)
victim.bleed(rand(20, 40))
limb.drop_limb(FALSE, TRUE)
victim.update_equipment_speed_mods()
- if(bleeds && isturf(spot))
+ if(bleeds && isturf(spot) && !laid_here) // the splatter laid here stands in for this one
victim.add_splatter_floor(spot)
- if(blood_at)
- // tg lays it on the middle of the tile, which a body held in a grab is drawn well off
- for(var/obj/effect/decal/cleanable/blood/pool in spot)
- if(pool.type == /obj/effect/decal/cleanable/blood && !(pool in old_blood) && !QDELETED(pool))
- gorilla_place_blood(pool, blood_at[1], blood_at[2])
if(QDELETED(limb))
return null
if(keep_out)
@@ -1948,13 +1956,15 @@
/datum/hv_finisher/chrome/gorilla/backbreaker/beat(key)
if(key != "slam" || QDELETED(victim))
return
- hit_stop(victim_rig?.puppet("upper") || victim, TRUE)
+ // The ring, the cracks and the dust go where the back is drawn breaking: on the body's waist, over his knee
+ var/obj/effect/abstract/chrome_puppet/held_half = victim_rig?.puppet("upper")
+ var/list/break_at = held_half ? list(0, BACK_WAIST_PIVOT_Y) : gorilla_zone_point(victim, BODY_ZONE_CHEST)
+ var/list/at = hit_stop(held_half || victim, TRUE, round(break_at[2]), round(break_at[1]))
gorilla_backbreaker_sound(victim)
playsound(victim, 'sound/effects/meteorimpact.ogg', 50, TRUE)
- var/turf/knee = get_turf(user)
- if(knee)
- new /obj/effect/temp_visual/cyberware_impact_cracks(knee, "damaged1", 255)
- cyberware_grey_dust(knee)
+ if(at)
+ new /obj/effect/temp_visual/cyberware_impact_cracks(at[1], "damaged1", 255, at[2], at[3])
+ cyberware_grey_dust(at[1], at[2], at[3])
var/outcome = gorilla_backbreak(victim, user, fist())
broke = outcome == "broken"
// What the blow did to the body (the snapped bone, tg's wounds) is drawn on the hidden one: the halves take it on
@@ -2126,3 +2136,5 @@
qdel(src)
#undef BACK_WAIST_PIVOT_Y
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_looks.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_looks.dm
index af865681fbe..9190122ff2c 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_looks.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_looks.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Gorilla Arms looks
*
@@ -171,3 +174,5 @@ GLOBAL_LIST_INIT(gorilla_hand_points, list(
. = ..()
if(iscarbon(was_on) && !QDELETED(was_on))
was_on.gorilla_update_snap_overlays()
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_pound.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_pound.dm
index be2e7cfe0c4..cb506433b39 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_pound.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_pound.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Ground pound
*
@@ -243,3 +246,5 @@
carrier.remove_item_action(old)
else
qdel(old)
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_pry.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_pry.dm
index 024f6f0ce23..9ea9ab803e5 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_pry.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_pry.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Gorilla door pry
*
@@ -171,3 +174,5 @@
*/
/proc/gorilla_door_seam_stepped(obj/machinery/door/airlock/door)
return !!findtext("[door.icon]", "/airlocks/station/")
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_slam.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_slam.dm
index 6abe224fd6d..dfd61d2834a 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_slam.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_slam.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # The grab-slam
*
@@ -1052,3 +1055,5 @@
#undef SLAM_EASE_IN
#undef SLAM_EASE_SINE
#undef SLAM_WAIST_Y
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_swing.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_swing.dm
index 3473f7dcffe..dd101687ad9 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_swing.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_swing.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Arm swings
*
@@ -249,3 +252,5 @@
#undef SWING_FRAME_BASE
#undef SWING_FRAME_ARMS
#undef SWING_FRAME_LAYERS
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_throw.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_throw.dm
index d2b4a5d58a9..d116eecbe09 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_throw.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_throw.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # Gorilla throws and wall impacts
*
@@ -511,3 +514,5 @@
name = "blood smear"
icon_state = "impact_edge"
alpha = 220
+
+#undef animate
diff --git a/voidcrew/modules/hyperviolence_gorilla/gorilla_thrust.dm b/voidcrew/modules/hyperviolence_gorilla/gorilla_thrust.dm
index 567afa6aae9..1c3d72b0906 100644
--- a/voidcrew/modules/hyperviolence_gorilla/gorilla_thrust.dm
+++ b/voidcrew/modules/hyperviolence_gorilla/gorilla_thrust.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # The piston punch's arm
*
@@ -304,3 +307,5 @@
return TRUE
#undef GORILLA_THRUST_FILTER
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_housing.dm b/voidcrew/modules/mantis_gore/mantis_housing.dm
index 2d682512cd6..7f1a037aa83 100644
--- a/voidcrew/modules/mantis_gore/mantis_housing.dm
+++ b/voidcrew/modules/mantis_gore/mantis_housing.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// The housing side of the Mantis line's gore: the combat stance while a blade is out (the guard pose,
// the fists raised, a glint now and then), the flick of blood on the way back in, and the stain the
// housing keeps until it is washed. See mantis_core.dm for the overview.
@@ -234,3 +237,5 @@
. += stain
#undef MANTIS_FLICK_FLIGHT
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_impale.dm b/voidcrew/modules/mantis_gore/mantis_impale.dm
index de703e5538e..ca7a704f0ca 100644
--- a/voidcrew/modules/mantis_gore/mantis_impale.dm
+++ b/voidcrew/modules/mantis_gore/mantis_impale.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// The impaling lunge. A lunge that arrives with both blades on someone already hurt or down skewers them:
// held up on the blades for a beat (pinned to the wall for longer, if one is right behind them), then the
// blades rip out with a spray and they drop. The bearer is rooted with full hands the whole time, and
@@ -131,8 +134,10 @@
// reach them as it lands (begin_rig()).
prior_dir = victim.dir
victim.setDir(mantis_face_dir(victim, bearer))
- hoist()
- place_victim(0, 0)
+ // Swung up as the lunging body comes in, and on as the points go in, rather than stood up in one frame.
+ var/hoist_time = max(glide_time, MANTIS_IMPALE_HOIST)
+ hoist(hoist_time)
+ place_victim(0, 0, hoist_time)
mantis_pose_blades(housings, MANTIS_POSE_LUNGE)
put_up_rig()
if(rig)
@@ -364,15 +369,28 @@
* picture turns: tg still has them lying down, with everything that goes with it. Skipped for a resized
* body, whose lying turn carries a shift that wouldn't come back out cleanly.
*/
-/datum/mantis_impale/proc/hoist()
+/datum/mantis_impale/proc/hoist(time = 0)
if(hoist_angle || victim.body_position != LYING_DOWN || !victim.rotate_on_lying || !victim.lying_angle)
return
if(victim.current_size != RESIZE_DEFAULT_SIZE)
return
hoist_angle = victim.lying_angle
- var/matrix/upright = matrix(victim.transform)
+ var/matrix/lying = matrix(victim.transform)
+ var/matrix/upright = matrix(lying)
upright.Turn(-hoist_angle)
- victim.transform = upright
+ if(!time)
+ victim.transform = upright
+ return
+ // Swung up off the floor on the blades, in a few steps so the body keeps its size on the way (one straight
+ // tween of a quarter turn shrinks it). It starts from how tg drew them, so the replay plays it from there too.
+ var/swing = hoist_angle > 180 ? hoist_angle - 360 : hoist_angle
+ animate(victim, transform = lying, time = 0, flags = ANIMATION_PARALLEL)
+ for(var/i in 1 to MANTIS_IMPALE_HOIST_STEPS)
+ var/matrix/step = matrix(lying)
+ step.Turn(-swing * sin(90 * i / MANTIS_IMPALE_HOIST_STEPS))
+ if(i == MANTIS_IMPALE_HOIST_STEPS)
+ step = upright
+ animate(transform = step, time = time / MANTIS_IMPALE_HOIST_STEPS)
/// Gives back tg's lying turn. [fall] drops them into it instead of snapping.
/datum/mantis_impale/proc/unhoist(fall = FALSE)
@@ -600,3 +618,5 @@
blade.show_inhand()
if(!QDELETED(src))
qdel(src)
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_lunge_fx.dm b/voidcrew/modules/mantis_gore/mantis_lunge_fx.dm
index 72f1f089403..70871f57fc0 100644
--- a/voidcrew/modules/mantis_gore/mantis_lunge_fx.dm
+++ b/voidcrew/modules/mantis_gore/mantis_lunge_fx.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// Pictures for the Mantis line's gore. Nothing here changes who gets hit, when or how hard: the
// mechanics call in after they have happened. One-shot holders and temp visuals only; every animate()
// on a mob here is relative and parallel and ends where it began, so tg's offsets, lying turn and #509's
@@ -507,3 +510,5 @@
#undef MANTIS_LEAP_GLIDE
#undef MANTIS_SPURT_WAIT
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_rig.dm b/voidcrew/modules/mantis_gore/mantis_rig.dm
index ce74f3981f6..34d856f515a 100644
--- a/voidcrew/modules/mantis_gore/mantis_rig.dm
+++ b/voidcrew/modules/mantis_gore/mantis_rig.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
/**
* # The blade rig: the impale and the scissor, drawn around the victim
*
@@ -253,6 +256,7 @@
/datum/mantis_rig/Destroy()
reveal()
+ hv_exec_bar_lean(bearer)
for(var/key in puppets)
qdel(puppets[key])
puppets = null
@@ -320,6 +324,7 @@
body.pixel_y = body_row
body.pixel_w = base_w + lean_w + body.shift_w
body.pixel_z = base_z + lean_z + body.shift_z
+ cyberware_time_rig_picture(body, bearer) // a Sandevistan user's edge glow takes the new look (ware_sandy_timestop.dm)
/**
* The bearer's pixel_x and pixel_y under the rig's own lean: without a #509 finisher's lean (pose_user()), which
@@ -359,6 +364,8 @@
picture.pixel_w = base_w + lean_w + picture.shift_w
picture.pixel_z = base_z + lean_z + picture.shift_z
puppets[key] = picture
+ // In a Sandevistan slow-mo it looks like whose it is: the victim's blood, or a piece of the bearer
+ cyberware_time_rig_picture(picture, (key in list("wound", "drip")) ? victim : bearer)
return picture
/**
@@ -438,6 +445,7 @@
dress()
lean_w = spec[MANTIS_RIG_BEARER_W] + extra_w
lean_z = spec[MANTIS_RIG_BEARER_Z] + extra_z
+ hv_exec_bar_lean(bearer, lean_w, lean_z, time) // the bar over them goes with the lunge (hyperviolence/finishers/finisher_bar.dm)
for(var/key in puppets)
var/obj/effect/abstract/mantis_puppet/picture = puppets[key]
var/to_w = base_w + lean_w + picture.shift_w
@@ -517,6 +525,8 @@
spray.pixel_w = base_w + lean_w - ICON_SIZE_X
spray.pixel_z = base_z + lean_z - ICON_SIZE_Y + own_y() - spray.pixel_y
QDEL_IN(spray, lifetime)
+ if(blood)
+ cyberware_time_rig_picture(spray, victim) // tinted with the world in a Sandevistan slow-mo, like all blood
return spray
/**
@@ -566,3 +576,5 @@
#undef MANTIS_RIG_HIDE_FILTER
#undef MANTIS_RIG_LAYER_STEP
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_scissor.dm b/voidcrew/modules/mantis_gore/mantis_scissor.dm
index 0972323df06..63bc94b1c2a 100644
--- a/voidcrew/modules/mantis_gore/mantis_scissor.dm
+++ b/voidcrew/modules/mantis_gore/mantis_scissor.dm
@@ -1,3 +1,6 @@
+// The Sandevistan replay plays a move again: animate() here is journaled for it (cyberware/ware_sandy_replay.dm).
+#define animate(arguments...) sandy_replay_animate(arguments)
+
// The scissor: both blades out, head aimed, a swing at someone adjacent who is dying. The blades rise,
// catch the light, then come down and close on the neck, one blade behind it and one in front, and #509's
// decapitation takes the head. The bearer is drawn by the blade rig (mantis_rig.dm) from the raise to the
@@ -127,15 +130,49 @@
// ---- The wind-up -----------------------------------------------------------
-/// Someone on the floor is turned so their head lies toward [bearer], the way tg turns someone dragged.
-/// Straight above or below them, the head goes to the left, where the blades are drawn to close on it.
+/// How long the bearer takes to haul a body round end for end, and in how many steps it is drawn.
+#define MANTIS_SCISSOR_HAUL_TIME (0.45 SECONDS)
+#define MANTIS_SCISSOR_HAUL_STEPS 6
+
+/**
+ * Someone on the floor is turned so their head lies toward [bearer], the way tg turns someone dragged.
+ * Straight above or below them, the head goes to the left, where the blades are drawn to close on it.
+ * Already lying that way, they stay as they are. Lying the other way, they are hauled round end for end:
+ * tg's own turn for that is a flip in one frame, so the picture swings them round about their middle instead,
+ * the head passing on the bearer's side (below, unless the bearer stands above them). tg's lying angle is set
+ * at once, so the body is really lying the new way the whole time; only the drawing takes the time.
+ */
/proc/mantis_turn_head_toward(mob/living/victim, mob/living/bearer)
if(victim.body_position != LYING_DOWN || !victim.rotate_on_lying || !victim.lying_angle)
return
- if(bearer.x == victim.x)
- victim.set_lying_angle(LYING_ANGLE_WEST)
+ var/new_angle = LYING_ANGLE_WEST
+ if(bearer.x != victim.x)
+ new_angle = bearer.x > victim.x ? LYING_ANGLE_EAST : LYING_ANGLE_WEST
+ var/old_angle = victim.lying_angle
+ if(new_angle == old_angle)
+ return
+ var/matrix/was = matrix(victim.transform)
+ victim.set_lying_angle(new_angle)
+ if(victim.lying_angle != new_angle || REVERSE_ANGLE(new_angle) != old_angle)
return
- victim.set_lying_angle(bearer.x > victim.x ? LYING_ANGLE_EAST : LYING_ANGLE_WEST)
+ // Head east (90) to head west (270) through head down (180) is clockwise; through head up it is the other way.
+ var/through_top = bearer.y > victim.y
+ var/turn = (old_angle == LYING_ANGLE_EAST) ? 180 : -180
+ if(through_top)
+ turn = -turn
+ // tg's turn, read before the steps below: each animate() leaves the var at its own end.
+ var/matrix/lying = matrix(victim.transform)
+ // The picture as tg had it, at once (tg's own turn already jumped), then round in even steps that ease in and out.
+ animate(victim, transform = was, time = 0)
+ for(var/i in 1 to MANTIS_SCISSOR_HAUL_STEPS)
+ var/matrix/step = matrix(was)
+ step.Turn(turn * (1 - cos(180 * i / MANTIS_SCISSOR_HAUL_STEPS)) / 2)
+ if(i == MANTIS_SCISSOR_HAUL_STEPS)
+ step = lying
+ animate(transform = step, time = MANTIS_SCISSOR_HAUL_TIME / MANTIS_SCISSOR_HAUL_STEPS)
+
+#undef MANTIS_SCISSOR_HAUL_TIME
+#undef MANTIS_SCISSOR_HAUL_STEPS
/// Both blades rise. A glint runs along them, and the victim shudders.
/datum/hv_finisher_stage/windup/mantis
@@ -346,3 +383,5 @@
/// The bearer straightens up out of the cut.
/datum/hv_finisher_stage/recover/mantis
duration = 0.5 SECONDS
+
+#undef animate
diff --git a/voidcrew/modules/mantis_gore/mantis_swing.dm b/voidcrew/modules/mantis_gore/mantis_swing.dm
index 86f02e9f38b..4e87bfc47c0 100644
--- a/voidcrew/modules/mantis_gore/mantis_swing.dm
+++ b/voidcrew/modules/mantis_gore/mantis_swing.dm
@@ -294,6 +294,7 @@
RegisterSignal(bearer, COMSIG_QDELETING, PROC_REF(on_bearer_deleted))
bearer.vis_contents += src
QDEL_IN(src, MANTIS_SWING_LIFETIME)
+ sandy_replay_made(src) // a Sandevistan replay plays it again (ware_sandy_replay.dm)
#undef MANTIS_SWING_ICON
#undef MANTIS_SWING_TIME
diff --git a/voidcrew/modules/missions/mission_board.dm b/voidcrew/modules/missions/mission_board.dm
index 1d2fb12f785..dd17ac6e851 100644
--- a/voidcrew/modules/missions/mission_board.dm
+++ b/voidcrew/modules/missions/mission_board.dm
@@ -129,6 +129,8 @@
/obj/machinery/computer/mission_board/ui_data(mob/user)
var/list/data = list()
+ // Tutorial checklist pointer (voidcrew/modules/tutorials)
+ data["tutorial_focus"] = tutorial_ui_focus(user, "board")
var/obj/structure/overmap/ship/ship = get_ship()
data["has_ship"] = !!ship
diff --git a/voidcrew/modules/onboarding/first_time_notice.dm b/voidcrew/modules/onboarding/first_time_notice.dm
index 70c15616958..b3b43ea1f21 100644
--- a/voidcrew/modules/onboarding/first_time_notice.dm
+++ b/voidcrew/modules/onboarding/first_time_notice.dm
@@ -18,8 +18,8 @@
* player's preferences savefile. Closing the window without answering (or
* disconnecting mid-prompt, which is exactly what the six-second player did)
* leaves the flag unset, so their next visit asks again. This is distinct from
- * the orientation briefing in orientation.dm, which is per-round and only
- * fires after a spawn - a player who bounces off the lobby never reaches it.
+ * the tutorial checklist (voidcrew/modules/tutorials), which only opens after a
+ * spawn - a player who bounces off the lobby never reaches it.
*/
/// Preferences-savefile key marking that this player has answered the notice.
diff --git a/voidcrew/modules/onboarding/orientation.dm b/voidcrew/modules/onboarding/orientation.dm
deleted file mode 100644
index 22ecee9d339..00000000000
--- a/voidcrew/modules/onboarding/orientation.dm
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * # Orientation Briefing
- *
- * The screen a player gets the first time they spawn into a round. It covers the
- * three things a new crew has no other way to find out: that the server is in an
- * early testing phase and where bugs go, what the overmap's three zone bands
- * actually permit, and that the gear which makes the deep bands survivable is
- * researched rather than bought.
- *
- * One tab each, and every tab kept short. This opens four seconds after spawn, on
- * top of a player who is still working out which way their ship faces, anything
- * longer than a screen gets closed unread.
- *
- * Shown once per client per round - a respawn twenty minutes later does not
- * re-open it - and available afterwards from the OOC tab, since the one time it
- * opens automatically is also the busiest moment of a player's round.
- *
- * The zone rows are built here rather than written into the TSX so that a change
- * to what a band permits is a change to one file, next to the defines that
- * enforce it. The advisory this screen sets up is enforced in the field by
- * zone_advisory.dm.
- */
-
-/// Where bug reports go during the testing phase.
-#define VOIDCREW_DISCORD_URL "https://discord.gg/6z9wQTYJmK"
-
-/// The player wiki. Kept in step with WIKIURL in config/voidcrew/voidcrew_config.txt,
-/// which is what the standard tg wiki verb reads.
-#define VOIDCREW_WIKI_URL "https://wiki.voidcrew-lrp.com"
-
-/// Gap between spawning and the briefing opening. Long enough that it lands
-/// after the client has finished loading into its body rather than on top of the
-/// spawn, short enough that it is still the first thing they read.
-#define ORIENTATION_BRIEFING_DELAY (4 SECONDS)
-
-/// Ckeys already shown the briefing this round.
-GLOBAL_LIST_EMPTY(orientation_briefing_seen)
-
-/// One datum for the whole server: it holds no per-player state, and TGUI keys
-/// its windows on (user, datum) so any number of players can have it open.
-GLOBAL_DATUM_INIT(orientation_briefing, /datum/orientation_briefing, new)
-
-/datum/orientation_briefing
-
-/datum/orientation_briefing/ui_state(mob/user)
- return GLOB.always_state
-
-/datum/orientation_briefing/ui_interact(mob/user, datum/tgui/ui)
- ui = SStgui.try_update_ui(user, src, ui)
- if(!ui)
- ui = new(user, src, "OrientationBriefing")
- ui.open()
-
-/datum/orientation_briefing/ui_data(mob/user)
- var/list/data = list()
- var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
- data["ship_name"] = ship?.name
- // Hard boolean rather than ship?.: a null here would read as "not
- // researched" in the UI anyway, and saying so plainly is what a ghost or
- // someone standing on a ruin should see.
- data["combat_researched"] = ship ? ship.has_ship_combat_research() : FALSE
- return data
-
-/datum/orientation_briefing/ui_static_data(mob/user)
- var/list/data = list()
-
- data["zones"] = list(
- list(
- "name" = ZONE_NAME_GREEN,
- "color" = ZONE_COLOR_GREEN,
- "summary" = "The inner ring, where every ship starts. Weapons will not fire and nobody can board you.",
- "rules" = list(
- "No ship weapons, no boarding, no interdiction",
- "Nothing out here damages your ship or attacks your crew",
- "Lowest ore yields and contract pay",
- ),
- ),
- list(
- "name" = ZONE_NAME_YELLOW,
- "color" = ZONE_COLOR_YELLOW,
- "summary" = "The middle ring. Weapons still will not fire, but a crew can raid you.",
- "rules" = list(
- "No ship weapons",
- "Boarding and interdiction are allowed",
- "Player vs player requires escalation. Robbery is accepted, and combat is acceptable if they resist",
- "About 50% more ore, about 70% more contract pay",
- ),
- ),
- list(
- "name" = ZONE_NAME_RED,
- "color" = ZONE_COLOR_RED,
- "summary" = "The outer ring. Nothing is off limits. Your hull can be shot at, and the ships out here are equipped for it.",
- "rules" = list(
- "Ship weapons are live: you can be shot",
- "PLAYERS CAN KILL YOU FOR NOTHING",
- "Boarding and interdiction are allowed",
- "Double ore, about 160% more pay plus a trade voucher",
- ),
- ),
- )
-
- // Pulled off the live nodes so a rename in ship_combat/research.dm follows.
- var/list/research_path = list()
- for(var/node_id in list(TECHWEB_NODE_SHIP_COMBAT, TECHWEB_NODE_SHIP_COMBAT_SHIELDS, TECHWEB_NODE_SHIP_COMBAT_LASERS, TECHWEB_NODE_SHIP_COMBAT_MISSILES, TECHWEB_NODE_SHIP_COMBAT_INTERDICTOR))
- var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id)
- if(!node)
- continue
- research_path += list(list(
- "name" = node.display_name,
- "desc" = node.description,
- ))
- data["research_path"] = research_path
-
- return data
-
-/datum/orientation_briefing/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
- . = ..()
- if(.)
- return
- switch(action)
- if("open_discord")
- // Hands the link to the player's own browser; TGUI itself has no way
- // out to an external site.
- DIRECT_OUTPUT(ui.user, link(VOIDCREW_DISCORD_URL))
- return TRUE
- if("open_wiki")
- DIRECT_OUTPUT(ui.user, link(VOIDCREW_WIKI_URL))
- return TRUE
-
-/**
- * Opens the briefing for a player who has not seen it yet this round.
- *
- * Called from the spawn path. The seen-list is marked immediately rather than
- * when the window opens, so a player who spawns, dies and respawns inside the
- * delay still only queues one.
- */
-/proc/try_show_orientation_briefing(mob/user)
- if(!user?.client || !user.ckey)
- return
- if(user.ckey in GLOB.orientation_briefing_seen)
- return
- GLOB.orientation_briefing_seen += user.ckey
- addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(show_orientation_briefing), user), ORIENTATION_BRIEFING_DELAY)
-
-/// Timer landing point for try_show_orientation_briefing().
-/proc/show_orientation_briefing(mob/user)
- if(!user?.client)
- return
- GLOB.orientation_briefing.ui_interact(user)
-
-/client/verb/orientation_briefing()
- set name = "Orientation Briefing"
- set category = "OOC"
- set desc = "Re-open the new player briefing: testing phase, zones, and ship combat gear."
- if(!mob)
- return
- GLOB.orientation_briefing.ui_interact(mob)
-
-#undef ORIENTATION_BRIEFING_DELAY
-#undef VOIDCREW_DISCORD_URL
-#undef VOIDCREW_WIKI_URL
diff --git a/voidcrew/modules/player_outposts/outpost_residents.dm b/voidcrew/modules/player_outposts/outpost_residents.dm
index a349b7b49f9..48bda2789f0 100644
--- a/voidcrew/modules/player_outposts/outpost_residents.dm
+++ b/voidcrew/modules/player_outposts/outpost_residents.dm
@@ -179,7 +179,7 @@
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_CREWMEMBER_JOINED, character, job.title)
log_shuttle("[character.ckey] arrived as a resident of [home.name]")
to_chat(character, span_boldnotice("You are a resident of [home.name]."))
- try_show_orientation_briefing(character)
+ try_show_tutorial_checklist(character)
return TRUE
/// Called before create_character transfers the lobby mind, after appearance prompts.
diff --git a/voidcrew/modules/shuttle/construction/construction_console.dm b/voidcrew/modules/shuttle/construction/construction_console.dm
index b4834593448..5a6e947d6a0 100644
--- a/voidcrew/modules/shuttle/construction/construction_console.dm
+++ b/voidcrew/modules/shuttle/construction/construction_console.dm
@@ -2146,6 +2146,9 @@ GLOBAL_LIST_INIT(ship_rcd_hull_designs, list(
data["theme"] = theme
data += construction_controls_data(user)
data += repair_controls_data()
+ // Tutorial checklist focus (voidcrew/modules/tutorials), only on the viewer's own ship's console.
+ var/tutorial_focus = tutorial_ui_focus(user, "construction")
+ data["tutorial_focus"] = (tutorial_focus && tutorial_repair_is_crew_console(user, src)) ? tutorial_focus : null
return data
diff --git a/voidcrew/modules/shuttle/helm/_helm.dm b/voidcrew/modules/shuttle/helm/_helm.dm
index d94a1e0f89c..70201f04c4e 100644
--- a/voidcrew/modules/shuttle/helm/_helm.dm
+++ b/voidcrew/modules/shuttle/helm/_helm.dm
@@ -351,6 +351,8 @@
data["isNotCrew"] = !is_crew_member(user)
data["isAbandoned"] = current_ship.abandoned
data["isRetired"] = current_ship.retired_by_checkpoint || current_ship.checkpoint_rebuilding
+ // The tutorial checklist's pulsing button, if any (tutorials/tutorial_highlights.dm).
+ data["tutorial_focus"] = tutorial_ui_focus(user, "helm")
data["integrity"] = current_ship.get_integrity_percent()
data["overhealth"] = current_ship.get_overhealth_percent()
diff --git a/voidcrew/modules/trade/outpost_elevator.dm b/voidcrew/modules/trade/outpost_elevator.dm
index cec5101aeee..7abf9351c78 100644
--- a/voidcrew/modules/trade/outpost_elevator.dm
+++ b/voidcrew/modules/trade/outpost_elevator.dm
@@ -101,6 +101,8 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/outpost_elevator, 32)
/obj/machinery/outpost_elevator/ui_data(mob/user)
var/list/data = list()
+ // Tutorial checklist pointer (voidcrew/modules/tutorials)
+ data["tutorial_focus"] = tutorial_ui_focus(user, "elevator")
data["current_floor"] = get_current_floor()
data["moving"] = moving
data["linked"] = !!(outpost && get_current_floor() != -1)
diff --git a/voidcrew/modules/trade/trader_npc.dm b/voidcrew/modules/trade/trader_npc.dm
index 041d4522b73..9fb837e4484 100644
--- a/voidcrew/modules/trade/trader_npc.dm
+++ b/voidcrew/modules/trade/trader_npc.dm
@@ -441,6 +441,8 @@ GLOBAL_DATUM_INIT(trader_counter_state, /datum/ui_state/trader_counter, new)
/datum/outpost_trader_ui/shop/ui_data(mob/user)
var/list/data = list()
+ // Tutorial checklist pointer (voidcrew/modules/tutorials)
+ data["tutorial_focus"] = tutorial_ui_focus(user, "trader")
var/datum/outpost_shop/shop = npc.shop
data["barred"] = npc.outpost ? npc.outpost.is_user_barred(user) : FALSE
@@ -594,6 +596,8 @@ GLOBAL_DATUM_INIT(trader_counter_state, /datum/ui_state/trader_counter, new)
/datum/outpost_trader_ui/contracts/ui_data(mob/user)
var/list/data = list()
+ // Tutorial checklist pointer (voidcrew/modules/tutorials)
+ data["tutorial_focus"] = tutorial_ui_focus(user, "board")
var/obj/structure/overmap/trader_outpost/outpost = npc.outpost
var/datum/outpost_shop/shop = outpost?.shop
diff --git a/voidcrew/modules/tutorials/hooks_chrome_finisher.dm b/voidcrew/modules/tutorials/hooks_chrome_finisher.dm
new file mode 100644
index 00000000000..5ae93e3ef65
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_chrome_finisher.dm
@@ -0,0 +1,97 @@
+// Tutorial checklist hook: a finished chrome execution (Cyberware item).
+// The three cyberware finishers are separate engine types: the Gorilla Arms moves (/datum/hv_finisher/chrome),
+// the Mantis Blades scissor and the Widowline garrote. Boss finishers and gun executions don't count.
+// Hooked on the shared stop() so each line is covered; returns the parent's value unchanged.
+
+/// The finishers that count as a cyberware execution.
+GLOBAL_LIST_INIT(tutorial_chrome_finisher_types, typecacheof(list(
+ /datum/hv_finisher/chrome,
+ /datum/hv_finisher/garrote,
+ /datum/hv_finisher/mantis_scissor,
+)))
+
+/datum/hv_finisher/stop(reason)
+ // Captured first: the end callback can delete the finisher inside the parent.
+ var/was_running = running
+ var/mob/living/doer = user
+ var/killed = completed
+ . = ..()
+ if(!was_running || !(killed || reason == HV_FINISHER_DONE))
+ return
+ if(!doer?.ckey || !GLOB.tutorial_chrome_finisher_types[type])
+ return
+ tutorial_credit(doer, TUTORIAL_STEP_CHROME_EXECUTE)
+
+// ---- chrome-surgery: helpers for the Cyberware item's pointers and live lines ----
+
+/// Whether a bought item path is chrome for the Buy chrome step: implants, cyberware eyes and the
+/// cased sets. Not the empty autosurgeon: it can't fit chrome.
+/proc/tutorial_is_chrome_path(path)
+ return ispath(path, /obj/item/organ/cyberimp) || ispath(path, /obj/item/organ/eyes/robotic/cyberware) \
+ || ispath(path, /obj/item/cyberware_pair_case) || ispath(path, /obj/item/storage/case/cyberware)
+
+/// Whether a trader's shelf holds any chrome. Cached per shop type: shelves are fixed lists.
+/proc/tutorial_shop_sells_chrome(datum/outpost_shop/shop)
+ if(!shop)
+ return FALSE
+ var/static/list/sells_by_type = list()
+ if(isnull(sells_by_type[shop.type]))
+ var/sells = FALSE
+ for(var/datum/shop_sku/sku_type as anything in shop.sku_types)
+ if(ispath(sku_type, /datum/shop_sku) && tutorial_is_chrome_path(initial(sku_type.item_path)))
+ sells = TRUE
+ break
+ sells_by_type[shop.type] = sells
+ return sells_by_type[shop.type]
+
+/// The first loose piece of chrome [user] carries (hands, pockets, bags, cases), or null.
+/proc/tutorial_carried_chrome(mob/living/carbon/user)
+ if(!iscarbon(user))
+ return null
+ for(var/obj/item/organ/ware in user.get_all_contents())
+ if(ware.owner || !ware.GetComponent(/datum/component/cyberware))
+ continue
+ return ware
+ return null
+
+/**
+ * What finisher [user]'s fitted chrome gives them, for the Do an execution step.
+ * Returns list(line, can_finish): a short how-to line or null, and TRUE when they own a working one.
+ */
+/proc/tutorial_chrome_finisher_state(mob/living/carbon/user)
+ if(!iscarbon(user))
+ return list(null, FALSE)
+ if(gorilla_synced(user))
+ return list("Gorilla Arms: hands empty, aim at the head, an arm or the chest.", TRUE)
+ if(brawler_synced(user))
+ return list("Brawler Myomers: hands empty, aim at an arm.", TRUE)
+ var/wire = FALSE
+ var/scissor_housings = 0
+ var/shiv_housings = 0
+ var/gorilla_arms = 0
+ for(var/obj/item/organ/organ in user.organs)
+ if(organ.owner != user)
+ continue
+ if(istype(organ, /obj/item/organ/cyberimp/arm/toolkit/cyberware/monowire))
+ wire = TRUE
+ else if(istype(organ, /obj/item/organ/cyberimp/arm/toolkit/cyberware/mantis))
+ var/obj/item/organ/cyberimp/arm/toolkit/cyberware/mantis/housing = organ
+ var/scissors = FALSE
+ for(var/obj/item/melee/energy/blade/hardlight/cyberware_mantis/blade_type as anything in housing.items_to_create)
+ if(ispath(blade_type, /obj/item/melee/energy/blade/hardlight/cyberware_mantis) && (initial(blade_type.gore_moves) & MANTIS_MOVE_SCISSOR))
+ scissors = TRUE
+ if(scissors)
+ scissor_housings++
+ else
+ shiv_housings++
+ else if(istype(organ, /obj/item/organ/cyberimp/cyberware/gorilla_arms))
+ gorilla_arms++
+ if(scissor_housings >= 2)
+ return list("Mantis Blades: both blades out, aim at the head.", TRUE)
+ if(wire)
+ return list("Widowline: wire out, aim at the head.", TRUE)
+ if(scissor_housings || gorilla_arms)
+ return list("Only one arm of the pair is working.", FALSE)
+ if(shiv_housings)
+ return list("Shiv Blades can't finish anyone.", FALSE)
+ return list("Nothing fitted can finish someone yet.", FALSE)
diff --git a/voidcrew/modules/tutorials/hooks_contract.dm b/voidcrew/modules/tutorials/hooks_contract.dm
new file mode 100644
index 00000000000..5d9aafd0e4e
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_contract.dm
@@ -0,0 +1,96 @@
+// Tutorial checklist hooks. Part B: contract accept, work and turn-in hooks.
+// Every override calls the parent with its exact argument list and returns its value.
+
+/// Covers the mission board, trader contracts and the kingpin. Returns TRUE or an error string.
+/obj/structure/overmap/ship/accept_mission(datum/mission/mission)
+ . = ..()
+ if(. == TRUE && ismob(usr))
+ tutorial_credit(usr, TUTORIAL_STEP_CONTRACT_TAKE)
+
+/// Crew who join after the contract was taken still get the step from the board.
+/obj/machinery/computer/mission_board/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ var/obj/structure/overmap/ship/ship = get_ship()
+ if(length(ship?.active_missions) && user?.mind && (user.mind in ship.ship_team?.members))
+ tutorial_credit(user, TUTORIAL_STEP_CONTRACT_TAKE)
+
+/datum/mission/on_objective_completed(datum/mission_objective/objective)
+ var/obj/structure/overmap/ship/ship = (active && !failed && !completed) ? servant : null
+ . = ..()
+ if(ship && !QDELETED(ship))
+ tutorial_credit_crew(ship, TUTORIAL_STEP_CONTRACT_WORK)
+
+/// The mission qdels itself during the parent, so the ship is saved first.
+/datum/mission/finish_mission(atom/reward_anchor)
+ var/obj/structure/overmap/ship/ship = (active && !failed && !completed) ? servant : null
+ . = ..()
+ if(!ship || QDELETED(ship) || !completed)
+ return
+ // Deliveries complete at hand-in, so the work step is credited here too.
+ tutorial_credit_crew(ship, TUTORIAL_STEP_CONTRACT_WORK)
+ tutorial_credit_crew(ship, TUTORIAL_STEP_CONTRACT_TURN_IN)
+
+// ---------------------------------------------------------------------------
+// Step pointers and live lines (contract-trade)
+// ---------------------------------------------------------------------------
+
+/// The viewer's crew ship's first live contract, or null.
+/proc/tutorial_first_contract(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ for(var/datum/mission/mission as anything in ship?.active_missions)
+ if(!QDELETED(mission))
+ return mission
+ return null
+
+/// "Name: progress." for the viewer's first live contract, or null.
+/proc/tutorial_contract_line(mob/user)
+ var/datum/mission/mission = tutorial_first_contract(user)
+ if(!mission)
+ return null
+ var/progress = mission.get_progress_string()
+ return progress ? "[mission.name]: [progress]." : "[mission.name]."
+
+/// The main trader also posts contracts; stalls and guards don't.
+/datum/vc_tutorial_step/contract_take/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /mob/living/basic/outpost_trader))
+ var/mob/living/basic/outpost_trader/trader = candidate
+ return !isnull(trader.outpost) && trader.outpost.trader == trader
+ return TRUE
+
+/// While berthed at an outpost, its main trader (a fixed spot behind a counter).
+/datum/vc_tutorial_step/contract_take/extra_targets(mob/user)
+ var/obj/structure/overmap/trader_outpost/outpost = get_crew_ship(user)?.docked
+ if(!istype(outpost) || QDELETED(outpost.trader))
+ return list()
+ return list(outpost.trader)
+
+/datum/vc_tutorial_step/contract_work/live_line(mob/user)
+ var/line = tutorial_contract_line(user)
+ if(!line)
+ return null
+ if(tutorial_first_contract(user).get_waypoint_info())
+ line += " Marked on the helm."
+ return line
+
+/// The contract's tracked objective, when it lies loose on the ground. Anything carried is
+/// skipped, so a holder's position is never shown.
+/datum/vc_tutorial_step/contract_work/extra_targets(mob/user)
+ var/datum/mission/mission = tutorial_first_contract(user)
+ var/atom/movable/objective = mission?.quest_atom
+ if(QDELETED(objective) || !isturf(objective.loc))
+ return list()
+ if(ismob(objective))
+ var/mob/objective_mob = objective
+ if(objective_mob.ckey)
+ return list()
+ return list(objective)
+
+/datum/vc_tutorial_step/contract_turn_in/live_line(mob/user)
+ return tutorial_contract_line(user)
+
+/// Only a pad a board reads: an unlinked pad is never checked at Turn In.
+/datum/vc_tutorial_step/contract_turn_in/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/machinery/mission_pad))
+ var/obj/machinery/mission_pad/pad = candidate
+ return !isnull(pad.linked_console)
+ return TRUE
diff --git a/voidcrew/modules/tutorials/hooks_medical.dm b/voidcrew/modules/tutorials/hooks_medical.dm
new file mode 100644
index 00000000000..5436a9e20a3
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_medical.dm
@@ -0,0 +1,105 @@
+// Tutorial checklist hooks. Part C: cyberware install and surgery hooks.
+// Overrides chain with any others of the same proc; each returns the parent's value unchanged.
+
+/// Chrome credits the body that receives it; a surgeon gets credit under Surgery instead.
+/obj/item/organ/cyberimp/on_mob_insert(mob/living/carbon/organ_owner, special = FALSE, movement_flags)
+ . = ..()
+ if(!special && organ_owner?.ckey)
+ tutorial_credit(organ_owner, TUTORIAL_STEP_CHROME_INSTALL)
+
+/obj/item/organ/eyes/robotic/cyberware/on_mob_insert(mob/living/carbon/organ_owner, special = FALSE, movement_flags)
+ . = ..()
+ if(!special && organ_owner?.ckey)
+ tutorial_credit(organ_owner, TUTORIAL_STEP_CHROME_INSTALL)
+
+/datum/surgery_step/initiate(mob/living/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, try_to_fail = FALSE)
+ tutorial_credit(user, TUTORIAL_STEP_SURGERY_START)
+ return ..()
+
+/// Credited before the parent, which qdels the surgery. Not COMSIG_MOB_SURGERY_FINISHED:
+/// that fires from Destroy(), including for cancelled operations.
+/datum/surgery/complete(mob/surgeon)
+ tutorial_credit(surgeon, TUTORIAL_STEP_SURGERY_FINISH)
+ return ..()
+
+/// Every dissection tier inherits this step. The body's dissection_points_paid grows by
+/// exactly what the notes are worth, so a rise means research was actually earned.
+/datum/surgery_step/experimental_dissection/success(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, default_display_results = FALSE)
+ var/paid_before = target?.dissection_points_paid
+ . = ..()
+ if(target && target.dissection_points_paid > paid_before)
+ tutorial_credit(user, TUTORIAL_STEP_SURGERY_DISSECT)
+
+// ---- chrome-surgery: First surgery pointers, live lines and the surgery window's focus ----
+
+/**
+ * What [user] still needs on them for Tend Wounds: a scalpel, a hemostat, a cautery and a sheet
+ * (anything that starts surgery: a bedsheet, drapes or a cloak). Memoised for the current tick,
+ * because the step's filter asks once per candidate; fresh skips the memo.
+ */
+/proc/tutorial_surgery_missing(mob/living/user, fresh = FALSE)
+ var/static/memo_time = -1
+ var/static/list/memo = list()
+ if(memo_time != world.time || fresh)
+ memo_time = world.time
+ memo.Cut()
+ var/user_ref = REF(user)
+ if(memo[user_ref])
+ return memo[user_ref]
+ var/scalpel = FALSE
+ var/hemostat = FALSE
+ var/cautery = FALSE
+ var/sheet = FALSE
+ if(istype(user))
+ for(var/obj/item/thing in user.get_all_contents())
+ switch(thing.tool_behaviour)
+ if(TOOL_SCALPEL)
+ scalpel = TRUE
+ if(TOOL_HEMOSTAT)
+ hemostat = TRUE
+ if(TOOL_CAUTERY)
+ cautery = TRUE
+ if(!sheet && thing.GetComponent(/datum/component/surgery_initiator))
+ sheet = TRUE
+ var/list/missing = list()
+ if(!scalpel)
+ missing += "a scalpel"
+ if(!hemostat)
+ missing += "a hemostat"
+ if(!cautery)
+ missing += "a cautery"
+ if(!sheet)
+ missing += "a sheet"
+ memo[user_ref] = missing
+ return missing
+
+/// An operation in progress that [user] is working on: on themselves or someone beside them,
+/// at the body part they are aiming at. Null when there is none.
+/proc/tutorial_surgery_in_reach(mob/living/user)
+ if(!istype(user) || !isturf(user.loc))
+ return null
+ var/list/patients = list(user)
+ for(var/mob/living/patient in orange(1, user))
+ patients += patient
+ for(var/mob/living/patient as anything in patients)
+ for(var/datum/surgery/operation as anything in patient.surgeries)
+ if(operation.location == user.zone_selected && operation.status <= length(operation.steps))
+ return operation
+ return null
+
+/// The surgery window (SurgeryInitiator.tsx) pulses the surgery a First surgery step names, or the
+/// body picker first while the surgeon isn't aiming at the chest. Both those surgeries are chest-only.
+/datum/component/surgery_initiator/ui_data(mob/user)
+ . = ..()
+ var/focus = tutorial_ui_focus(user, "surgery")
+ if(!focus)
+ return
+ if(user.zone_selected != BODY_ZONE_CHEST)
+ focus = "surgery_chest"
+ .["tutorial_focus"] = focus
+ for(var/list/entry as anything in .["surgeries"])
+ var/surgery_name = entry["name"]
+ if(findtext(surgery_name, "Tend Wounds") == 1)
+ entry["tutorial_id"] = "surgery_tend_wounds"
+ else if(findtext(surgery_name, "Dissection"))
+ entry["tutorial_id"] = "surgery_dissection"
diff --git a/voidcrew/modules/tutorials/hooks_pirates.dm b/voidcrew/modules/tutorials/hooks_pirates.dm
new file mode 100644
index 00000000000..4f7107a297c
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_pirates.dm
@@ -0,0 +1,126 @@
+// Tutorial checklist hooks: the Hunting pirates item (voidcrew/modules/npc_ships).
+// Overrides chain with any others of the same proc and keep the parent's return value.
+// Boarding a pirate ship is credited from tutorial_on_docked() in tutorial_progress.dm and
+// from the interdictor force-dock in hooks_ship_combat.dm.
+
+/// TRUE for a hostile NPC ship that no crew has claimed.
+/proc/tutorial_is_pirate_ship(obj/structure/overmap/ship/ship)
+ var/obj/structure/overmap/ship/npc/npc_ship = ship
+ return istype(npc_ship) && !QDELETED(npc_ship) && npc_ship.hostile && !npc_ship.player_controlled
+
+/// The wave-complete signal is only sent once a boarding wave is cleared.
+/datum/ai_controller/npc_ship/start_boarding_phase()
+ . = ..()
+ if(.)
+ RegisterSignal(src, COMSIG_BOARDING_WAVE_COMPLETE, PROC_REF(tutorial_on_wave_complete), override = TRUE)
+
+/datum/ai_controller/npc_ship/proc/tutorial_on_wave_complete(datum/source, wave)
+ SIGNAL_HANDLER
+ var/obj/structure/overmap/ship/target = get_target()
+ if(!QDELETED(target) && !istype(target, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(target, TUTORIAL_STEP_PIRATES_BOARDERS, aboard_only = TRUE)
+
+/// Runs when the boss dies, or a human boss is downed or cuffed. Disabling the ship ends it.
+/datum/ai_controller/npc_ship/handle_boss_killed()
+ var/state_before = get_combat_state()
+ var/obj/structure/overmap/ship/target = get_target()
+ . = ..()
+ if(state_before == NPC_COMBAT_DISABLED || get_combat_state() != NPC_COMBAT_DISABLED)
+ return
+ if(!QDELETED(target) && !istype(target, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(target, TUTORIAL_STEP_PIRATES_COMMANDER, aboard_only = TRUE)
+
+/// Hull failure. Credits the crew the pirate was fighting.
+/obj/structure/overmap/ship/npc/on_ship_destroyed()
+ var/already_crashed = has_crash_landed
+ var/was_pirate = tutorial_is_pirate_ship(src)
+ var/datum/ai_controller/npc_ship/controller = ai_controller
+ var/obj/structure/overmap/ship/target = istype(controller) ? controller.get_target() : null
+ . = ..()
+ if(already_crashed || !was_pirate || !has_crash_landed)
+ return
+ if(!QDELETED(target) && !istype(target, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(target, TUTORIAL_STEP_PIRATES_SHOOT, aboard_only = TRUE)
+
+/obj/machinery/computer/helm/claim_npc_ship(obj/structure/overmap/ship/npc/npc_ship, mob/living/claimer, form_new = null)
+ . = ..()
+ if(. && claimer)
+ tutorial_credit(claimer, TUTORIAL_STEP_PIRATES_CLAIM)
+
+/// The hull was abandoned (crew wiped) and claimed with the helm's Claim button, no key.
+/obj/structure/overmap/ship/npc/claim_abandoned_ship(mob/living/claimer, form_new = null)
+ var/was_pirate = tutorial_is_pirate_ship(src)
+ . = ..()
+ if(. && was_pirate && claimer)
+ tutorial_credit(claimer, TUTORIAL_STEP_PIRATES_CLAIM)
+
+/// Credits whoever picked up a pirate's hail.
+/obj/machinery/holopad/answer_hail(obj/structure/overmap/ship/npc/pirate/pirate, mob/user)
+ . = ..()
+ if(. && user)
+ tutorial_credit(user, TUTORIAL_STEP_PIRATES_HAIL)
+
+/// A pirate bounty paid out to a crew (the mission board turn-in).
+/datum/pirate_bounty/complete(obj/structure/overmap/ship/winner, obj/machinery/mission_pad/pad)
+ var/was_settled = completed || failed
+ . = ..()
+ if(!was_settled && completed && !QDELETED(winner) && !istype(winner, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(winner, TUTORIAL_STEP_PIRATES_BOUNTY)
+
+// ---------------------------------------------------------------------------
+// Live state for the Hunting pirates steps.
+// ---------------------------------------------------------------------------
+
+/// Tiles on the overmap a boardable pirate can be from the crew's ship.
+#define TUTORIAL_BOARD_RANGE 2
+/// Matches TUTORIAL_HIGHLIGHT_VIEW_RANGE in tutorial_highlights.dm.
+#define TUTORIAL_KEY_CARRIER_RANGE 9
+
+/// The controller of the pirate currently engaging this ship, or null.
+/proc/tutorial_engaging_pirate_controller(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ var/obj/structure/overmap/ship/npc/pirate = ship.engaging_pirate_ref?.resolve()
+ if(QDELETED(pirate))
+ return null
+ var/datum/ai_controller/npc_ship/controller = pirate.ai_controller
+ return istype(controller) ? controller : null
+
+/// The ZONE_* type of the space a ship is in, or null when unknown.
+/proc/tutorial_ship_zone_type(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ var/turf/ship_turf = get_turf(ship)
+ return ship_turf ? SSovermap_zones.get_zone_type(ship_turf) : null
+
+/// A pirate ship near this one that a helm Dock would board: one our interdictor holds, or
+/// a disabled one. Null if none.
+/proc/tutorial_boardable_pirate(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ var/obj/structure/overmap/ship/npc/held = tutorial_interdicted_ship(ship)
+ if(tutorial_is_pirate_ship(held))
+ return held
+ var/turf/ship_turf = get_turf(ship)
+ if(!ship_turf)
+ return null
+ for(var/obj/structure/overmap/ship/npc/pirate in range(TUTORIAL_BOARD_RANGE, ship_turf))
+ if(pirate.is_disabled && tutorial_is_pirate_ship(pirate))
+ return pirate
+ return null
+
+/// Downed or cuffed NPCs in view of the viewer with a ship key in a pocket.
+/proc/tutorial_key_carriers(mob/user)
+ . = list()
+ if(!user)
+ return
+ for(var/mob/living/holder in view(TUTORIAL_KEY_CARRIER_RANGE, user))
+ if(holder == user || holder.ckey)
+ continue
+ if(holder.stat == CONSCIOUS && !HAS_TRAIT(holder, TRAIT_RESTRAINED))
+ continue
+ if(locate(/obj/item/ship_key) in holder.contents)
+ . += holder
+
+#undef TUTORIAL_BOARD_RANGE
+#undef TUTORIAL_KEY_CARRIER_RANGE
diff --git a/voidcrew/modules/tutorials/hooks_power.dm b/voidcrew/modules/tutorials/hooks_power.dm
new file mode 100644
index 00000000000..d34aab30392
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_power.dm
@@ -0,0 +1,26 @@
+// Tutorial checklist hooks. Part C: SMES, generator and APC hooks.
+// Overrides chain with any others of the same proc; each returns the parent's value unchanged.
+
+/obj/machinery/power/smes/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ if(user?.ckey && !SSvc_tutorials.progress[user.ckey]?[TUTORIAL_STEP_POWER_SMES] && get_ship_from_atom(src))
+ tutorial_credit(user, TUTORIAL_STEP_POWER_SMES)
+
+/obj/machinery/power/port_gen/pacman/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
+ var/was_active = active
+ . = ..()
+ if(action == "toggle_power" && active && !was_active)
+ tutorial_credit(ui?.user || usr, TUTORIAL_STEP_POWER_GENERATOR)
+
+/// Opening an unlocked panel counts. A locked one shows nothing the player can switch.
+/obj/machinery/power/apc/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ if((!locked || issilicon(user)) && user?.ckey && !SSvc_tutorials.progress[user.ckey]?[TUTORIAL_STEP_POWER_APC] && get_ship_from_atom(src))
+ tutorial_credit(user, TUTORIAL_STEP_POWER_APC)
+
+/// Unlocking a panel aboard counts too (right-click or an ID swipe).
+/obj/machinery/power/apc/togglelock(mob/living/user)
+ var/was_locked = locked
+ . = ..()
+ if(was_locked && !locked && user?.ckey && get_ship_from_atom(src))
+ tutorial_credit(user, TUTORIAL_STEP_POWER_APC)
diff --git a/voidcrew/modules/tutorials/hooks_repair_drones.dm b/voidcrew/modules/tutorials/hooks_repair_drones.dm
new file mode 100644
index 00000000000..6d471f9ccb6
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_repair_drones.dm
@@ -0,0 +1,139 @@
+// Tutorial checklist hooks: the Repair drones item (voidcrew/modules/shuttle/construction).
+// Overrides chain with any others of the same proc.
+
+/datum/techweb/research_node(datum/techweb_node/node, force = FALSE, auto_adjust_cost = TRUE, get_that_dosh = TRUE, atom/research_source)
+ . = ..()
+ if(!. || !istype(node) || node.id != TECHWEB_NODE_SHIP_REPAIR_SWARM)
+ return
+ var/obj/structure/overmap/ship/ship = metric_techweb_ship(src)
+ if(ship)
+ tutorial_credit_crew(ship, TUTORIAL_STEP_REPAIR_DRONES_RESEARCH)
+
+/// The final step spawns the drone and deletes the chassis this component sits on.
+/datum/component/construction/ship_repair_drone/check_step(obj/item/item, mob/living/user)
+ var/atom/chassis = parent
+ . = ..()
+ if(. && QDELETED(chassis) && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_REPAIR_DRONES_ASSEMBLE)
+
+/obj/structure/ship_repair_drone/multitool_act(mob/living/user, obj/item/multitool/tool)
+ var/was_linked = !!console
+ . = ..()
+ if(!was_linked && console && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_REPAIR_DRONES_LINK)
+
+/// Drones call this when a repair finishes. Credits the crew aboard the console's ship.
+/obj/machinery/computer/camera_advanced/base_construction/ship/perform_record_repair(datum/ship_repair_record/record)
+ . = ..()
+ if(. && current_ship)
+ tutorial_credit_crew(current_ship, TUTORIAL_STEP_REPAIR_DRONES_REPAIR, aboard_only = TRUE)
+
+// ---------------------------------------------------------------------------
+// Panel helpers for the Repair drones steps (tutorial_catalog.dm). Cheap: they run in ui_data.
+// ---------------------------------------------------------------------------
+
+/// How long the ship's construction console lookup is kept.
+#define TUTORIAL_REPAIR_CONSOLE_CACHE (10 SECONDS)
+
+/// Ship REF -> list(world.time, weakref to its construction console or null).
+GLOBAL_LIST_EMPTY(tutorial_repair_console_cache)
+
+/**
+ * The ship's own construction console: the one running its repairs, else one aboard, preferring
+ * one with the repair disk. The aboard scan is cached briefly because it walks every ship area.
+ */
+/proc/tutorial_repair_console(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ var/obj/machinery/computer/camera_advanced/base_construction/ship/console = ship.shuttle?.ship_repair_controller?.resolve()
+ if(!QDELETED(console))
+ return console
+ var/ship_ref = REF(ship)
+ var/list/cached = GLOB.tutorial_repair_console_cache[ship_ref]
+ if(cached && world.time < cached[1] + TUTORIAL_REPAIR_CONSOLE_CACHE)
+ var/datum/weakref/cached_ref = cached[2]
+ console = cached_ref?.resolve()
+ if(!QDELETED(console))
+ return console
+ console = null
+ for(var/obj/machinery/computer/camera_advanced/base_construction/ship/candidate as anything in ship.get_ship_machines(/obj/machinery/computer/camera_advanced/base_construction/ship))
+ if(istype(candidate, /obj/machinery/computer/camera_advanced/base_construction/ship/bay))
+ continue
+ if(!console || (candidate.console_upgrades & SHIP_CONSTRUCTION_UPGRADE_REPAIR))
+ console = candidate
+ GLOB.tutorial_repair_console_cache[ship_ref] = list(world.time, console ? WEAKREF(console) : null)
+ return console
+
+/// Whether this is a construction console of the viewer's own ship, not an outpost bay's.
+/proc/tutorial_repair_is_crew_console(mob/user, atom/candidate)
+ var/obj/machinery/computer/camera_advanced/base_construction/ship/console = candidate
+ if(!istype(console) || istype(console, /obj/machinery/computer/camera_advanced/base_construction/ship/bay))
+ return FALSE
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && get_ship_from_atom(console) == ship
+
+/**
+ * What stands between this web and the node: the next node to research on the way, missing
+ * reputation, or points. Null once researched or with no web.
+ */
+/proc/tutorial_repair_research_line(datum/techweb/web, node_id)
+ if(!web || web.researched_nodes[node_id])
+ return null
+ var/datum/techweb_node/next = tutorial_repair_next_node(web, node_id, list())
+ if(!next)
+ return null
+ if(next.id != node_id)
+ return "Research [next.display_name] first."
+ if(!web.have_zone_permission_for_node(next))
+ return "Needs more crew reputation."
+ if(!web.can_afford(next.get_price(web)))
+ return "Short on research points."
+ return null
+
+/// The first unresearched node on the way to node_id whose prerequisites are all researched.
+/proc/tutorial_repair_next_node(datum/techweb/web, node_id, list/visited)
+ if(visited[node_id] || web.researched_nodes[node_id])
+ return null
+ visited[node_id] = TRUE
+ var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id)
+ if(!node)
+ return null
+ for(var/prereq_id in node.prereq_ids)
+ var/datum/techweb_node/blocker = tutorial_repair_next_node(web, prereq_id, visited)
+ if(blocker)
+ return blocker
+ return node
+
+/// The next assembly step of the nearest unfinished drone chassis beside the viewer.
+/proc/tutorial_repair_chassis_line(mob/user)
+ var/turf/center = get_turf(user)
+ if(!center)
+ return null
+ for(var/obj/item/ship_repair_drone_part/chassis/chassis in range(2, center))
+ var/datum/component/construction/ship_repair_drone/assembly = chassis.GetComponent(/datum/component/construction/ship_repair_drone)
+ if(!assembly || assembly.index > length(assembly.steps))
+ continue
+ var/list/next_step = assembly.steps[assembly.index]
+ var/step_desc = next_step["desc"]
+ if(step_desc)
+ return STRIP_HTML_FULL(step_desc, 160)
+ return null
+
+/// The swarm's state as its console shows it.
+/proc/tutorial_repair_swarm_line(obj/machinery/computer/camera_advanced/base_construction/ship/console)
+ if(QDELETED(console))
+ return null
+ if(!(console.console_upgrades & SHIP_CONSTRUCTION_UPGRADE_REPAIR))
+ return "No repair disk in the construction console."
+ if(!length(console.repair_drones))
+ return "No drones linked."
+ if(!console.repair_enabled)
+ return "Swarm paused."
+ if(!console.repair_tracking)
+ return "Damage monitoring is off."
+ var/waiting = length(console.repair_records)
+ if(!waiting)
+ return "Swarm out. No hull damage logged."
+ return "[waiting] damaged spot\s waiting for repair."
+
+#undef TUTORIAL_REPAIR_CONSOLE_CACHE
diff --git a/voidcrew/modules/tutorials/hooks_research.dm b/voidcrew/modules/tutorials/hooks_research.dm
new file mode 100644
index 00000000000..50bbc6129dc
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_research.dm
@@ -0,0 +1,254 @@
+// Tutorial checklist hooks. Part C: R&D setup (kit, ship server, disk, console, protolathe, multitool
+// links) and surveys (research node, survey console, notes).
+// Overrides chain with any others of the same proc; each returns the parent's value unchanged.
+
+// ---------------------------------------------------------------------------
+// R&D setup
+// ---------------------------------------------------------------------------
+
+/// The autolathe builds on a timer with no user, so the kit counts once a player picks it up or opens it.
+/obj/item/storage/box/rndboards/all/pickup(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_KIT)
+
+/datum/storage/box/rndkit/open_storage(mob/living/to_show)
+ . = ..()
+ if(.)
+ tutorial_credit(to_show, TUTORIAL_STEP_RESEARCH_KIT)
+
+/// on_construction() runs for flatpack deploys and frame builds, never for mapped machines.
+/obj/machinery/rnd/server/ship/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_SERVER)
+
+/obj/machinery/computer/rdconsole/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_CONSOLE)
+
+/obj/machinery/rnd/production/protolathe/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_PROTOLATHE)
+
+/// The ship server takes its source disk in attacked_by (voidcrew/modules/research/server.dm).
+/obj/machinery/rnd/server/ship/attacked_by(obj/item/attacking_item, mob/living/user, list/modifiers, list/attack_modifiers)
+ var/had_disk = !!source_code_hdd
+ . = ..()
+ if(!had_disk && source_code_hdd && source_code_hdd == attacking_item)
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_DISK)
+
+/// The ship server's multitool_act stores its disk's techweb in the multitool buffer.
+/obj/machinery/rnd/server/ship/multitool_act(mob/living/user, obj/item/multitool/tool)
+ . = ..()
+ if(. && source_code_hdd?.stored_research && tool.buffer == source_code_hdd.stored_research)
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_MULTITOOL)
+
+/obj/machinery/computer/rdconsole/multitool_act(mob/living/user, obj/item/multitool/tool)
+ . = ..()
+ if(. && stored_research && stored_research == tool.buffer && tutorial_ship_rnd_linked(get_ship_from_atom(src), stored_research))
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_LINK)
+
+/obj/machinery/rnd/production/protolathe/multitool_act(mob/living/user, obj/item/multitool/tool)
+ . = ..()
+ if(. && stored_research && stored_research == tool.buffer && tutorial_ship_rnd_linked(get_ship_from_atom(src), stored_research))
+ tutorial_credit(user, TUTORIAL_STEP_RESEARCH_LINK)
+
+/**
+ * TRUE when the ship has an R&D console and a protolathe both on a techweb served by a ship
+ * R&D server. With no web given, the ship's own research web is used.
+ * Walks the hull's machines, so only call it on a player action or a panel open.
+ */
+/proc/tutorial_ship_rnd_linked(obj/structure/overmap/ship/ship, datum/techweb/web)
+ if(QDELETED(ship))
+ return FALSE
+ if(!web)
+ web = ship.get_research_web()
+ if(!web || !(locate(/obj/machinery/rnd/server/ship) in web.techweb_servers))
+ return FALSE
+ var/console_linked = FALSE
+ for(var/obj/machinery/computer/rdconsole/console as anything in ship.get_ship_machines(/obj/machinery/computer/rdconsole))
+ if(console.stored_research == web)
+ console_linked = TRUE
+ break
+ if(!console_linked)
+ return FALSE
+ for(var/obj/machinery/rnd/production/protolathe/lathe as anything in ship.get_ship_machines(/obj/machinery/rnd/production/protolathe))
+ if(lathe.stored_research == web)
+ return TRUE
+ return FALSE
+
+// ---------------------------------------------------------------------------
+// Surveys
+// ---------------------------------------------------------------------------
+
+/// Research notes are redeemed (and deleted) by the Voidcrew override in research/edits/_rd_consoles.dm.
+/// Notes of any origin count, because merged notes change origin.
+/obj/machinery/computer/rdconsole/attackby(obj/item/attacking_item, mob/user, list/modifiers, list/attack_modifiers)
+ var/is_notes = istype(attacking_item, /obj/item/research_notes)
+ . = ..()
+ if(is_notes && QDELETED(attacking_item))
+ tutorial_credit(user, TUTORIAL_STEP_SURVEYS_NOTES)
+
+/datum/techweb/research_node(datum/techweb_node/node, force = FALSE, auto_adjust_cost = TRUE, get_that_dosh = TRUE, atom/research_source)
+ . = ..()
+ if(!. || !istype(node) || node.id != TECHWEB_NODE_SURVEY_CONSOLE)
+ return
+ var/obj/structure/overmap/ship/ship = metric_techweb_ship(src)
+ if(ship)
+ tutorial_credit_crew(ship, TUTORIAL_STEP_SURVEYS_NODE)
+
+/// Only the crew's own ship console counts. Outpost archive consoles open the same window.
+/obj/machinery/computer/camera_advanced/shuttle_docker/survey/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ var/obj/structure/overmap/ship/ship = bound_ship?.resolve()
+ if(attached_to_ship && ship && get_crew_ship(user, ship))
+ tutorial_credit(user, TUTORIAL_STEP_SURVEYS_BUILD)
+
+/// When the ship's movement last stopped a running survey, for the Surveys checklist line.
+/obj/machinery/computer/camera_advanced/shuttle_docker/survey/var/tutorial_moved_at = 0
+
+/obj/machinery/computer/camera_advanced/shuttle_docker/survey/cancel_survey(datum/source)
+ SIGNAL_HANDLER
+ var/was_running = survey_in_progress
+ . = ..()
+ if(was_running && source && !survey_in_progress)
+ tutorial_moved_at = world.time
+
+// ---------------------------------------------------------------------------
+// In-window focus (TutorialFocus in the tsx). Window ids: "rdconsole", "imprinter", "survey", "autolathe".
+// ---------------------------------------------------------------------------
+
+/obj/machinery/computer/rdconsole/ui_data(mob/user)
+ . = ..()
+ if(islist(.))
+ .["tutorial_focus"] = tutorial_ui_focus(user, "rdconsole")
+
+/obj/machinery/rnd/production/circuit_imprinter/ui_data(mob/user)
+ . = ..()
+ if(islist(.))
+ .["tutorial_focus"] = tutorial_ui_focus(user, "imprinter")
+
+/obj/machinery/autolathe/ui_data(mob/user)
+ . = ..()
+ if(islist(.))
+ .["tutorial_focus"] = tutorial_ui_focus(user, "autolathe")
+
+/obj/machinery/computer/camera_advanced/shuttle_docker/survey/ui_data(mob/user)
+ . = ..()
+ if(islist(.))
+ .["tutorial_focus"] = tutorial_ui_focus(user, "survey")
+
+// ---------------------------------------------------------------------------
+// Step helpers (tutorial_catalog.dm R&D setup and Surveys)
+// ---------------------------------------------------------------------------
+
+/// TRUE when the candidate is a flatpack that deploys into one of these machine types.
+/proc/tutorial_flatpack_builds(atom/candidate, list/machine_types)
+ var/obj/item/flatpack/pack = candidate
+ if(!istype(pack) || !pack.board)
+ return FALSE
+ for(var/machine_type in machine_types)
+ if(ispath(pack.board.build_path, machine_type))
+ return TRUE
+ return FALSE
+
+/// TRUE when the mob carries an item that works as this tool (TOOL_* define).
+/proc/tutorial_has_tool(mob/user, tool_behaviour)
+ if(!user)
+ return FALSE
+ for(var/obj/item/thing in user.get_all_contents())
+ if(thing.tool_behaviour == tool_behaviour)
+ return TRUE
+ return FALSE
+
+/// "No multitool on you." while the mob carries no such tool, else null.
+/proc/tutorial_tool_line(mob/user, tool_behaviour)
+ if(!user || tutorial_has_tool(user, tool_behaviour))
+ return null
+ return "No [tool_behaviour] on you."
+
+/// TRUE for a computer frame that is empty or holds this board type.
+/proc/tutorial_frame_for(atom/candidate, board_type)
+ var/obj/structure/frame/computer/frame = candidate
+ if(!istype(frame))
+ return FALSE
+ return !frame.circuit || istype(frame.circuit, board_type)
+
+/// The step's nearest highlight candidate that is a computer frame for this board, or null.
+/// With board_required, empty frames don't count.
+/proc/tutorial_nearest_frame(mob/user, datum/vc_tutorial_step/step, board_type, board_required = FALSE)
+ var/turf/center = get_turf(user)
+ if(!center)
+ return null
+ var/obj/structure/frame/computer/nearest
+ var/nearest_dist = INFINITY
+ for(var/obj/structure/frame/computer/frame in tutorial_step_candidates(user, step))
+ if(frame.circuit ? !istype(frame.circuit, board_type) : board_required)
+ continue
+ var/dist = get_dist(center, frame)
+ if(dist < nearest_dist)
+ nearest = frame
+ nearest_dist = dist
+ return nearest
+
+/// What a computer frame needs next, and whether the mob lacks the tool for it.
+/proc/tutorial_frame_line(mob/user, obj/structure/frame/computer/frame)
+ if(QDELETED(frame))
+ return null
+ var/line
+ var/tool
+ if(!frame.anchored)
+ line = "The frame needs a wrench."
+ tool = TOOL_WRENCH
+ else
+ switch(frame.state)
+ if(FRAME_COMPUTER_STATE_EMPTY)
+ line = "The frame needs its board."
+ if(FRAME_COMPUTER_STATE_BOARD_INSTALLED)
+ line = "The board needs a screwdriver."
+ tool = TOOL_SCREWDRIVER
+ if(FRAME_COMPUTER_STATE_BOARD_SECURED)
+ line = "The frame needs 5 cable."
+ if(FRAME_COMPUTER_STATE_WIRED)
+ line = "The frame needs 2 glass."
+ if(FRAME_COMPUTER_STATE_GLASSED)
+ line = "The frame needs a screwdriver."
+ tool = TOOL_SCREWDRIVER
+ if(tool && !tutorial_has_tool(user, tool))
+ line += " You have none."
+ return line
+
+/// TRUE when an R&D console or lathe runs off this techweb.
+/proc/tutorial_rnd_device_linked(atom/candidate, datum/techweb/web)
+ if(!web)
+ return FALSE
+ if(istype(candidate, /obj/machinery/computer/rdconsole))
+ var/obj/machinery/computer/rdconsole/console = candidate
+ return console.stored_research == web
+ if(istype(candidate, /obj/machinery/rnd))
+ var/obj/machinery/rnd/machine = candidate
+ return machine.stored_research == web
+ return FALSE
+
+/// The plain name the R&D setup steps use for a linkable device, or null.
+/proc/tutorial_rnd_device_label(atom/machine)
+ if(istype(machine, /obj/machinery/computer/rdconsole))
+ return "R&D console"
+ if(istype(machine, /obj/machinery/rnd/production/protolathe))
+ return "protolathe"
+ if(istype(machine, /obj/machinery/rnd/production/circuit_imprinter))
+ return "circuit imprinter"
+ return null
+
+/// "Research points: 12 of 40." for a node not yet researched, or null.
+/proc/tutorial_node_points_line(datum/techweb/web, node_id)
+ if(!web || web.researched_nodes[node_id])
+ return null
+ var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id)
+ if(!node)
+ return null
+ var/list/price = node.get_price(web)
+ var/cost = price?[TECHWEB_POINT_TYPE_GENERIC]
+ if(!cost)
+ return null
+ var/have = round(web.research_points[TECHWEB_POINT_TYPE_GENERIC] || 0)
+ return "Research points: [have] of [cost]."
diff --git a/voidcrew/modules/tutorials/hooks_ship.dm b/voidcrew/modules/tutorials/hooks_ship.dm
new file mode 100644
index 00000000000..fae5a74e0ea
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_ship.dm
@@ -0,0 +1,51 @@
+// Tutorial checklist hooks. Part B: captain management, helm and construction console hooks.
+// Every override calls the parent with its exact argument list and returns its value.
+// Overrides of the same proc in other files (Part C's ruin cache closet hook) chain.
+
+/datum/captain_management_ui/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_SHIP_MANAGE)
+
+/// Lockers and crates aboard a ship. Hot path: one ckey lookup once the step is done.
+/obj/structure/closet/open(mob/living/user, force = FALSE, special_effects = TRUE)
+ . = ..()
+ if(. != TRUE || !ismob(user))
+ return
+ var/user_ckey = user.ckey
+ if(!user_ckey || SSvc_tutorials.has_key(user_ckey, TUTORIAL_STEP_SHIP_SEARCH))
+ return
+ if(get_ship_from_atom(src))
+ tutorial_credit(user, TUTORIAL_STEP_SHIP_SEARCH)
+
+/// Alt-click tile search aboard a ship.
+/datum/lootpanel/open(turf/tile)
+ . = ..()
+ var/mob/viewer = owner?.mob
+ if(viewer && get_ship_from_atom(tile))
+ tutorial_credit(viewer, TUTORIAL_STEP_SHIP_SEARCH)
+
+/// Only a course this click actually changed counts, so refused clicks (viewer helms,
+/// non-crew, a busy ship) never credit a course someone else set.
+/obj/machinery/computer/helm/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
+ var/obj/structure/overmap/ship/ship_before = current_ship
+ var/course_before = current_ship?.commanded_course
+ var/autopilot_before = current_ship?.autopilot_engaged
+ . = ..()
+ if(!current_ship || current_ship != ship_before)
+ return
+ var/plotted = FALSE
+ switch(action)
+ if("change_heading", "set_course")
+ plotted = current_ship.commanded_course != BURN_NONE && current_ship.commanded_course != course_before
+ if("autopilot")
+ plotted = current_ship.autopilot_engaged && !autopilot_before
+ if(!plotted)
+ return
+ var/mob/pilot = ui?.user || usr
+ if(ismob(pilot))
+ tutorial_credit(pilot, TUTORIAL_STEP_SHIP_COURSE)
+
+/obj/machinery/computer/camera_advanced/base_construction/ship/ui_interact(mob/user, datum/tgui/ui)
+ . = ..()
+ if(current_ship)
+ tutorial_credit(user, TUTORIAL_STEP_SHIP_BUILD)
diff --git a/voidcrew/modules/tutorials/hooks_ship_combat.dm b/voidcrew/modules/tutorials/hooks_ship_combat.dm
new file mode 100644
index 00000000000..139ab385931
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_ship_combat.dm
@@ -0,0 +1,183 @@
+// Tutorial checklist hooks: the Ship weapons and Ship combat items (voidcrew/modules/ship_combat).
+// Overrides chain with any others of the same proc and keep the parent's return value.
+
+// ---------------------------------------------------------------------------
+// Ship weapons: building them. on_construction() runs for frame builds and flatpack
+// deploys, never for mapped machines.
+// ---------------------------------------------------------------------------
+
+/obj/machinery/computer/camera_advanced/ship_combat/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_CONSOLE)
+
+/obj/machinery/ship_combat/missile_launcher/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_LAUNCHER)
+
+/obj/machinery/ship_combat/laser_turret/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_LASER)
+
+/obj/machinery/ship_combat/shield_generator/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_SHIELD)
+
+/obj/machinery/ship_combat/interdictor/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_INTERDICTOR)
+
+/obj/machinery/ship_combat/ew_suite/on_construction(mob/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_EW)
+
+/// The screwdriver seal moves a missile from PAYLOAD to ARMED inside the parent (after a do_after).
+/// A missile bought armed (the /armed subtypes) can be unsealed and resealed; that doesn't count.
+/obj/structure/ship_missile/attackby(obj/item/W, mob/user, list/modifiers)
+ var/state_before = construction_state
+ . = ..()
+ if(initial(construction_state) == MISSILE_STATE_ARMED)
+ return
+ if(state_before == MISSILE_STATE_PAYLOAD && construction_state == MISSILE_STATE_ARMED && !QDELETED(src))
+ tutorial_credit(user, TUTORIAL_STEP_WEAPONS_MISSILE)
+
+// ---------------------------------------------------------------------------
+// Ship combat: using them.
+// ---------------------------------------------------------------------------
+
+/// The lock lands here. Credits the interdicting crew aboard.
+/obj/machinery/ship_combat/interdictor/complete_warmup()
+ . = ..()
+ if(!interdiction_active)
+ return
+ var/obj/structure/overmap/ship/our_ship = linked_ship_ref?.resolve()
+ if(our_ship && !istype(our_ship, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(our_ship, TUTORIAL_STEP_COMBAT_INTERDICT, aboard_only = TRUE)
+
+/// Player fire passes the user; NPC fire passes null.
+/obj/machinery/ship_combat/missile_launcher/fire(turf/target, obj/structure/overmap/target_ship, obj/structure/overmap/ship/source_ship, mob/user, spawn_offset_x = 0, spawn_offset_y = 0, approach_dir = null)
+ . = ..()
+ if(. && user && istype(target_ship, /obj/structure/overmap/ship))
+ tutorial_credit(user, TUTORIAL_STEP_COMBAT_MISSILE)
+
+/// Credits the attacking crew when a hit takes a ship's shields from up to broken.
+/proc/tutorial_check_shields_broken(obj/structure/overmap/ship/attacker, obj/structure/overmap/ship/target, shields_were_up)
+ if(!shields_were_up || QDELETED(attacker) || QDELETED(target) || attacker == target)
+ return
+ if(!target.shields_broken || istype(attacker, /obj/structure/overmap/ship/npc))
+ return
+ tutorial_credit_crew(attacker, TUTORIAL_STEP_COMBAT_SHIELDS)
+
+/// The beam can delete itself mid-proc, so its ships are read first.
+/obj/effect/ship_laser_beam/fire_laser()
+ var/obj/structure/overmap/ship/attacker = source_ship
+ var/obj/structure/overmap/ship/target = target_ship
+ var/shields_were_up = target?.shields_active
+ . = ..()
+ tutorial_check_shields_broken(attacker, target, shields_were_up)
+
+/// Missiles break shields by bumping into a wall. The wall's ship is the target.
+/obj/structure/ship_shield_wall/Bumped(atom/movable/AM)
+ var/obj/effect/ship_missile/missile = AM
+ var/obj/structure/overmap/ship/attacker = istype(missile) ? missile.source_ship : null
+ var/obj/machinery/ship_combat/shield_generator/gen = generator_ref?.resolve()
+ var/obj/structure/overmap/ship/target = gen?.linked_ship_ref?.resolve()
+ var/shields_were_up = target?.shields_active
+ . = ..()
+ if(attacker)
+ tutorial_check_shields_broken(attacker, target, shields_were_up)
+
+/// A payload that launched is added to launched_payloads. A new weakref means one went out.
+/obj/machinery/ship_combat/ew_suite/on_warmup_complete()
+ var/datum/weakref/last_before = length(launched_payloads) ? launched_payloads[length(launched_payloads)] : null
+ . = ..()
+ var/datum/weakref/last_after = length(launched_payloads) ? launched_payloads[length(launched_payloads)] : null
+ if(!last_after || last_after == last_before)
+ return
+ var/obj/structure/overmap/ship/owner = get_owner_ship()
+ if(owner && !istype(owner, /obj/structure/overmap/ship/npc))
+ tutorial_credit_crew(owner, TUTORIAL_STEP_COMBAT_HACK, aboard_only = TRUE)
+
+/// Force-docking credits the user, and counts as boarding a pirate ship for the crew aboard.
+/obj/machinery/ship_combat/interdictor/force_dock_target(mob/user)
+ var/obj/structure/overmap/ship/target = interdicted_ship_ref?.resolve()
+ . = ..()
+ if(!.)
+ return
+ if(user)
+ tutorial_credit(user, TUTORIAL_STEP_COMBAT_FORCE_DOCK)
+ var/obj/structure/overmap/ship/our_ship = linked_ship_ref?.resolve()
+ if(our_ship && tutorial_is_pirate_ship(target))
+ tutorial_credit_crew(our_ship, TUTORIAL_STEP_PIRATES_BOARD, aboard_only = TRUE)
+
+// ---------------------------------------------------------------------------
+// Ship combat: the weapons console window ("weapons") and live state for the steps.
+// ---------------------------------------------------------------------------
+
+/// How long a ship's combat machine list is reused by the live lines.
+#define TUTORIAL_COMBAT_MACHINE_CACHE (10 SECONDS)
+
+/// Chained after console_ui.dm and ew_console.dm (this file is included after both).
+/obj/machinery/computer/camera_advanced/ship_combat/ui_data(mob/user)
+ var/list/data = ..()
+ data["tutorial_focus"] = tutorial_weapons_focus(tutorial_ui_focus(user, "weapons"))
+ return data
+
+/// Walks a step's focus key back to the control this console needs first: a lock, then
+/// the targeting camera before the fire keys.
+/obj/machinery/computer/camera_advanced/ship_combat/proc/tutorial_weapons_focus(focus)
+ if(!focus)
+ return null
+ if(!target_ship && (focus in list("wpn_engage", "wpn_fire", "wpn_interdict", "wpn_hack", "wpn_execute")))
+ return "wpn_contact"
+ if(focus == "wpn_fire" && !attack_mode)
+ return "wpn_engage"
+ return focus
+
+/// Machines of a type aboard a ship, cached for a few seconds because the lookup walks every
+/// ship area. Live state is read off the machines by the caller.
+/proc/tutorial_combat_machines(obj/structure/overmap/ship/ship, machine_type)
+ . = list()
+ if(QDELETED(ship))
+ return
+ var/cache_key = "combat|[REF(ship)]|[machine_type]"
+ var/list/cached = SSvc_tutorials.machine_cache[cache_key]
+ var/list/refs
+ if(cached && world.time < cached[1] + TUTORIAL_COMBAT_MACHINE_CACHE)
+ refs = cached[2]
+ else
+ refs = list()
+ for(var/obj/machinery/machine as anything in ship.get_ship_machines(machine_type))
+ refs += WEAKREF(machine)
+ SSvc_tutorials.machine_cache[cache_key] = list(world.time, refs)
+ for(var/datum/weakref/ref as anything in refs)
+ var/obj/machinery/machine = ref.resolve()
+ if(!QDELETED(machine))
+ . += machine
+
+/// "Weapons are locked" while the ship sits where ship weapons can't fire, else null.
+/proc/tutorial_weapons_zone_note(obj/structure/overmap/ship/ship)
+ if(ship && !SSovermap_zones.weapons_allowed_at(ship))
+ return "Weapons are locked outside red space."
+ return null
+
+/// The ship a weapons console aboard has locked, or null.
+/proc/tutorial_weapons_target(obj/structure/overmap/ship/ship)
+ for(var/obj/machinery/computer/camera_advanced/ship_combat/console as anything in tutorial_combat_machines(ship, /obj/machinery/computer/camera_advanced/ship_combat))
+ var/obj/structure/overmap/ship/target = console.target_ship
+ if(istype(target) && !QDELETED(target))
+ return target
+ return null
+
+/// The ship one of this ship's interdictors is holding, or null.
+/proc/tutorial_interdicted_ship(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ for(var/obj/machinery/ship_combat/interdictor/interdictor in ship.linked_interdictors)
+ if(!interdictor.interdiction_active)
+ continue
+ var/obj/structure/overmap/ship/held = interdictor.interdicted_ship_ref?.resolve()
+ if(!QDELETED(held))
+ return held
+ return null
+
+#undef TUTORIAL_COMBAT_MACHINE_CACHE
diff --git a/voidcrew/modules/tutorials/hooks_ship_save.dm b/voidcrew/modules/tutorials/hooks_ship_save.dm
new file mode 100644
index 00000000000..4e6f758bde1
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_ship_save.dm
@@ -0,0 +1,68 @@
+// Tutorial checklist hooks: the Save your ship item (voidcrew/modules/ship_saves and the
+// player outpost ship bays). Overrides chain with any others of the same proc.
+
+/// The bay's own arrival handler. Same guard as the parent: the hull must be in this bay's dock.
+/datum/outpost_berth/ship_bay/on_ship_docked(datum/source)
+ SIGNAL_HANDLER
+ . = ..()
+ if(QDELETED(ship) || dock?.get_docked() != ship.shuttle)
+ return
+ tutorial_credit_crew(ship, TUTORIAL_STEP_SHIP_SAVE_DOCK, aboard_only = TRUE)
+
+/datum/ship_checkpoint_ui/save_ship(mob/living/user, datum/outpost_berth/ship_bay/bay, slot, funds_parts = 0)
+ . = ..()
+ if(. && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_SHIP_SAVE_SAVE)
+
+/// A save is spent once its hull exists or starts building, from the lobby or a shipyard console.
+/datum/ship_saves/spend(ckey, slot)
+ . = ..()
+ var/player_ckey = ckey(ckey)
+ if(player_ckey && !SSvc_tutorials.has_key(player_ckey, TUTORIAL_STEP_SHIP_SAVE_LOAD))
+ SSvc_tutorials.credit_ckey(player_ckey, TUTORIAL_STEP_SHIP_SAVE_LOAD, get_mob_by_ckey(player_ckey))
+
+// ---------------------------------------------------------------------------
+// Panel helpers for the Save your ship steps (tutorial_catalog.dm). Cheap: they run in ui_data.
+// ---------------------------------------------------------------------------
+
+/// How long the list of outposts with ship bays is kept. There are only a few outposts.
+#define TUTORIAL_SAVE_BAY_CACHE (30 SECONDS)
+
+/// Names of the outposts a ship can dock in a bay at right now, and when they were read.
+GLOBAL_LIST_EMPTY(tutorial_save_bay_names)
+GLOBAL_VAR_INIT(tutorial_save_bay_read_at, -INFINITY)
+
+/// Outposts whose helm entry offers "Dock at ship bay", the same test the helm uses.
+/proc/tutorial_save_bay_outposts()
+ if(world.time < GLOB.tutorial_save_bay_read_at + TUTORIAL_SAVE_BAY_CACHE)
+ return GLOB.tutorial_save_bay_names
+ var/list/names = list()
+ for(var/obj/structure/overmap/dynamic/player_outpost/home as anything in GLOB.player_outposts)
+ if(!QDELETED(home) && home.ship_bay_installed && home.has_hangar_elevator())
+ names += home.name
+ GLOB.tutorial_save_bay_names = names
+ GLOB.tutorial_save_bay_read_at = world.time
+ return names
+
+/// The ship bay this ship is docked in, or null.
+/proc/tutorial_save_bay_of(obj/structure/overmap/ship/ship)
+ if(QDELETED(ship))
+ return null
+ var/obj/structure/overmap/dynamic/player_outpost/home = ship.docked
+ if(!istype(home))
+ return null
+ for(var/datum/outpost_berth/ship_bay/bay as anything in home.bay_berths)
+ if(bay.ship == ship && bay.is_ship_present())
+ return bay
+ return null
+
+/// The shipyard consoles inside one bay.
+/proc/tutorial_save_bay_consoles(datum/outpost_berth/ship_bay/bay)
+ . = list()
+ if(QDELETED(bay))
+ return
+ for(var/obj/machinery/computer/ship_checkpoint/console as anything in SSmachines.get_machines_by_type_and_subtypes(/obj/machinery/computer/ship_checkpoint))
+ if(bay.contains_turf(get_turf(console)))
+ . += console
+
+#undef TUTORIAL_SAVE_BAY_CACHE
diff --git a/voidcrew/modules/tutorials/hooks_storage.dm b/voidcrew/modules/tutorials/hooks_storage.dm
new file mode 100644
index 00000000000..29baaa5e733
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_storage.dm
@@ -0,0 +1,32 @@
+// Tutorial checklist hooks: the Storage item (cargo shelves and smart lockers,
+// voidcrew/modules/storage). Overrides chain with any others of the same proc.
+
+/// Only a player assembling parts counts. Mapped and spawned shelves never pass through here.
+/// The parts delete themselves only once the shelf is up.
+/obj/item/rack_parts/cargo_shelf/attack_self(mob/user)
+ . = ..()
+ if(QDELETED(src) && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_STORAGE_SHELF)
+
+/obj/structure/cargo_shelf/load_crate(obj/structure/closet/crate/crate, mob/living/user)
+ . = ..()
+ if(. && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_STORAGE_CRATE)
+
+/// Called only when a machine frame is finished, never for mapped or spawned lockers.
+/obj/machinery/smartfridge/storage/on_construction(mob/user)
+ . = ..()
+ if(ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_STORAGE_LOCKER)
+
+/// One item by hand.
+/obj/machinery/smartfridge/storage/load(obj/item/weapon, mob/user)
+ . = ..()
+ if(. && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_STORAGE_STORE)
+
+/// A bag emptied into the locker. Returns how many items went in.
+/obj/machinery/smartfridge/storage/load_storage(datum/storage/storage, mob/user)
+ . = ..()
+ if(. > 0 && ismob(user))
+ tutorial_credit(user, TUTORIAL_STEP_STORAGE_STORE)
diff --git a/voidcrew/modules/tutorials/hooks_trade.dm b/voidcrew/modules/tutorials/hooks_trade.dm
new file mode 100644
index 00000000000..5e0262b94b5
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_trade.dm
@@ -0,0 +1,157 @@
+// Tutorial checklist hooks. Part B: outpost elevator, shop purchase and buyback hooks.
+// Every override calls the parent with its exact argument list and returns its value.
+// The barter, chart and rumor SKUs replace try_purchase without calling the base, so
+// each is covered on its own.
+
+/obj/machinery/outpost_elevator/complete_ride(floor_id, datum/weakref/rider_ref)
+ var/list/riders
+ var/list/turf/own_alcove = get_own_alcove()
+ for(var/turf/alcove_turf as anything in own_alcove)
+ for(var/mob/living/rider in alcove_turf)
+ if(rider.ckey)
+ LAZYSET(riders, rider, alcove_turf)
+ . = ..()
+ // Riding a trader outpost's elevator also means the ship got there: crew who joined
+ // after it berthed never saw the dock.
+ var/at_trader = istype(outpost, /obj/structure/overmap/trader_outpost)
+ for(var/mob/living/rider as anything in riders)
+ if(!QDELETED(rider) && get_turf(rider) != riders[rider])
+ tutorial_credit(rider, TUTORIAL_STEP_TRADE_ELEVATOR)
+ if(at_trader)
+ tutorial_credit(rider, TUTORIAL_STEP_TRADE_TRAVEL)
+
+/// Credits a finished purchase: every buy counts for trade, chrome also for cyberware.
+/proc/tutorial_credit_purchase(mob/living/user, datum/shop_sku/sku)
+ if(!user || !sku)
+ return
+ tutorial_credit(user, TUTORIAL_STEP_TRADE_BUY)
+ var/bought = sku.item_path
+ if(tutorial_is_chrome_path(bought))
+ tutorial_credit(user, TUTORIAL_STEP_CHROME_BUY)
+
+/datum/shop_sku/try_purchase(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit_purchase(user, src)
+
+/datum/shop_sku/barter/try_purchase(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit_purchase(user, src)
+
+/datum/shop_sku/anomaly_chart/try_purchase(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit_purchase(user, src)
+
+/datum/shop_sku/ruin_chart/try_purchase(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit_purchase(user, src)
+
+/datum/shop_sku/rumor/try_purchase(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit_purchase(user, src)
+
+/datum/shop_buyback/try_sell(mob/living/user, mob/living/basic/outpost_trader/vendor, quiet = FALSE)
+ . = ..()
+ if(. == TRUE)
+ tutorial_credit(user, TUTORIAL_STEP_TRADE_SELL)
+
+/datum/shop_buyback/try_sell_bulk(mob/living/user, mob/living/basic/outpost_trader/vendor)
+ . = ..()
+ if(. > 0)
+ tutorial_credit(user, TUTORIAL_STEP_TRADE_SELL)
+
+// ---------------------------------------------------------------------------
+// Step pointers and live lines (contract-trade)
+// ---------------------------------------------------------------------------
+
+/// The trader outpost the viewer's crew ship is berthed at, or null.
+/proc/tutorial_docked_outpost(mob/user)
+ var/obj/structure/overmap/trader_outpost/outpost = get_crew_ship(user)?.docked
+ return istype(outpost) && !QDELETED(outpost) ? outpost : null
+
+/// A trader who runs a shop. Checkpoint guards are traders by type but sell nothing.
+/proc/tutorial_is_shopkeeper(atom/candidate)
+ if(!istype(candidate, /mob/living/basic/outpost_trader) || istype(candidate, /mob/living/basic/outpost_trader/checkpoint_guard))
+ return FALSE
+ var/mob/living/basic/outpost_trader/trader = candidate
+ return !isnull(trader.shop)
+
+/datum/vc_tutorial_step/trade_travel/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/list/here = ship?.get_relative_overmap_coords()
+ if(!here)
+ return null
+ var/obj/structure/overmap/trader_outpost/nearest
+ var/best_dist
+ var/best_dx
+ var/best_dy
+ for(var/obj/structure/overmap/trader_outpost/outpost as anything in GLOB.trader_outposts)
+ if(QDELETED(outpost))
+ continue
+ var/list/there = outpost.get_relative_overmap_coords()
+ if(!there)
+ continue
+ var/dx = there[1] - here[1]
+ var/dy = there[2] - here[2]
+ var/dist = max(abs(dx), abs(dy))
+ if(!nearest || dist < best_dist)
+ nearest = outpost
+ best_dist = dist
+ best_dx = dx
+ best_dy = dy
+ if(!nearest)
+ return null
+ if(!best_dist)
+ return ship.is_still() ? "[nearest.name] is here." : "[nearest.name] is here. Slow down to dock."
+ return "Nearest outpost: [nearest.name], [best_dist] tiles [overmap_delta_to_compass(best_dx, best_dy)]."
+
+/// The elevator panel in this crew's berth (a fixed wall panel, off the ship).
+/datum/vc_tutorial_step/trade_elevator/extra_targets(mob/user)
+ var/obj/structure/overmap/trader_outpost/outpost = tutorial_docked_outpost(user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!outpost || !ship)
+ return list()
+ for(var/datum/outpost_berth/berth as anything in outpost.berths)
+ if(berth?.ship == ship && !QDELETED(berth.panel))
+ return list(berth.panel)
+ return list()
+
+/// Only this crew's berth panel or the concourse panels: other berths are crew only.
+/datum/vc_tutorial_step/trade_elevator/highlight_filter(mob/user, atom/candidate)
+ if(!istype(candidate, /obj/machinery/outpost_elevator))
+ return TRUE
+ var/obj/machinery/outpost_elevator/panel = candidate
+ if(panel.is_lobby || !panel.berth)
+ return FALSE
+ return panel.berth.ship == get_crew_ship(user)
+
+/datum/vc_tutorial_step/trade_buy/highlight_filter(mob/user, atom/candidate)
+ return !istype(candidate, /mob/living/basic/outpost_trader) || tutorial_is_shopkeeper(candidate)
+
+/// A whole credit amount with thousands commas: 12500 -> "12,500".
+/proc/tutorial_credits_text(amount)
+ var/digits = num2text(abs(round(amount)), 12)
+ var/out = ""
+ while(length(digits) > 3)
+ out = ",[copytext(digits, -3)][out]"
+ digits = copytext(digits, 1, -3)
+ return "[round(amount) < 0 ? "-" : ""][digits][out]"
+
+/datum/vc_tutorial_step/trade_buy/live_line(mob/user)
+ var/datum/bank_account/account = get_crew_ship(user)?.ship_account
+ if(!account)
+ return null
+ return "Ship account: [tutorial_credits_text(account.account_balance)] cr."
+
+/// Only traders with a wanted list buy anything.
+/datum/vc_tutorial_step/trade_sell/highlight_filter(mob/user, atom/candidate)
+ if(!istype(candidate, /mob/living/basic/outpost_trader))
+ return TRUE
+ if(!tutorial_is_shopkeeper(candidate))
+ return FALSE
+ var/mob/living/basic/outpost_trader/trader = candidate
+ return length(trader.shop.buybacks) > 0
diff --git a/voidcrew/modules/tutorials/hooks_vestige.dm b/voidcrew/modules/tutorials/hooks_vestige.dm
new file mode 100644
index 00000000000..64f7b0249c7
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_vestige.dm
@@ -0,0 +1,70 @@
+// Tutorial checklist hooks: the Vestige pact item (entering a vestige, the pact,
+// the trial and the boon). Overrides chain with any others of the same proc; each
+// returns the parent's value unchanged.
+
+/// Chains with the /area/ruin/Entered hook in hooks_world.dm.
+/area/ruin/space/has_grav/vestige/Entered(atom/movable/arrived, area/old_area)
+ . = ..()
+ if(!ismob(arrived))
+ return
+ var/mob/visitor = arrived
+ if(!visitor.ckey || SSvc_tutorials.progress[visitor.ckey]?[TUTORIAL_STEP_VESTIGE_FIND])
+ return
+ tutorial_credit(visitor, TUTORIAL_STEP_VESTIGE_FIND)
+
+/datum/vestige_trial/begin(mob/living/user)
+ . = ..()
+ tutorial_credit(user, TUTORIAL_STEP_VESTIGE_PACT)
+
+/// The trial qdels itself in the parent, so the owner and body are saved first.
+/// `fulfilled` is set only when the completion really took.
+/datum/vestige_trial/complete()
+ var/was_fulfilled = fulfilled
+ var/datum/mind/keeper = owner
+ var/mob/body = owner?.current
+ . = ..()
+ if(was_fulfilled || !fulfilled || !keeper)
+ return
+ tutorial_credit(body || keeper.current, TUTORIAL_STEP_VESTIGE_TRIAL)
+
+/// The parent qdels the action and may replace the claiming body (shapeshift upgrades).
+/datum/action/vestige_reward/claim(mob/living/user, datum/mind/mind, datum/vestige_boon/choice_type)
+ var/was_paid = paid
+ . = ..()
+ if(was_paid || !paid)
+ return
+ tutorial_credit(QDELETED(user) ? mind?.current : user, TUTORIAL_STEP_VESTIGE_CLAIM)
+
+// ---------------------------------------------------------------------------
+// Patron pointers for Make a pact (ruin-vestige). Patrons are godmode NPCs that
+// never leave their altar, so pointing at one through a wall gives nothing away.
+// ---------------------------------------------------------------------------
+
+/// How far from the viewer a patron is still pointed at.
+#define TUTORIAL_PATRON_RANGE 40
+
+/// Every vestige patron in the world (one per loaded vestige).
+GLOBAL_LIST_EMPTY(tutorial_vestige_patrons)
+
+/mob/living/basic/vestige_patron/Initialize(mapload)
+ . = ..()
+ GLOB.tutorial_vestige_patrons += src
+
+/mob/living/basic/vestige_patron/Destroy()
+ GLOB.tutorial_vestige_patrons -= src
+ return ..()
+
+/// Patrons in the vestige the viewer stands in.
+/proc/tutorial_nearby_patrons(mob/user)
+ . = list()
+ var/turf/here = get_turf(user)
+ if(!here)
+ return
+ for(var/mob/living/basic/vestige_patron/patron as anything in GLOB.tutorial_vestige_patrons)
+ var/turf/there = get_turf(patron)
+ if(!there || there.z != here.z || get_dist(here, there) > TUTORIAL_PATRON_RANGE)
+ continue
+ if(tutorial_same_tenant(here, there))
+ . += patron
+
+#undef TUTORIAL_PATRON_RANGE
diff --git a/voidcrew/modules/tutorials/hooks_world.dm b/voidcrew/modules/tutorials/hooks_world.dm
new file mode 100644
index 00000000000..4debfccb476
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_world.dm
@@ -0,0 +1,164 @@
+// Tutorial checklist hooks. Part C: closet, loot panel and ruin area hooks.
+// Overrides chain with any others of the same proc; each returns the parent's value unchanged.
+
+/// Opening an abandoned cache off-ship. Purchased caches are delivered aboard, so they don't count.
+/obj/structure/closet/crate/zone_loot/open(mob/living/user, force = FALSE, special_effects = TRUE)
+ . = ..()
+ if(.)
+ tutorial_credit_ruin_cache(src, user)
+
+/obj/structure/closet/crate/secure/loot/open(mob/living/user, force = FALSE, special_effects = TRUE)
+ . = ..()
+ if(.)
+ tutorial_credit_ruin_cache(src, user)
+
+/proc/tutorial_credit_ruin_cache(obj/structure/closet/cache, mob/living/user)
+ if(!ismob(user) || !user.ckey)
+ return
+ if(SSvc_tutorials.progress[user.ckey]?[TUTORIAL_STEP_RUIN_CACHE])
+ return
+ if(!tutorial_countable_cache(cache))
+ return
+ // A cache that counts sits in a ruin, open-air ones included (they have no /area/ruin).
+ tutorial_credit(user, TUTORIAL_STEP_RUIN_FIND)
+ tutorial_credit(user, TUTORIAL_STEP_RUIN_CACHE)
+
+/// TRUE for a cache found in the world: not a bought black-market one, and not aboard a ship.
+/proc/tutorial_countable_cache(obj/structure/closet/cache)
+ if(QDELETED(cache) || istype(cache, /obj/structure/closet/crate/zone_loot/syndicate/trader))
+ return FALSE
+ return !get_ship_from_atom(cache)
+
+// ---------------------------------------------------------------------------
+// Ruin pointers for the Planet ruin item (ruin-vestige). Read only from the step
+// procs in tutorial_catalog.dm, which run on a highlight rebuild or the panel's
+// 5 s refresh, never per tick.
+// ---------------------------------------------------------------------------
+
+/// Furthest ruin the Find a ruin pointers will name. A planet is 128 tiles across.
+#define TUTORIAL_RUIN_RANGE 100
+/// How far from the viewer a cache is still pointed at.
+#define TUTORIAL_CACHE_RANGE 40
+
+/// Every abandoned cache in the world, so the pointers never scan turfs.
+GLOBAL_LIST_EMPTY(tutorial_ruin_caches)
+
+/obj/structure/closet/crate/zone_loot/Initialize(mapload)
+ . = ..()
+ GLOB.tutorial_ruin_caches += src
+
+/obj/structure/closet/crate/zone_loot/Destroy()
+ GLOB.tutorial_ruin_caches -= src
+ return ..()
+
+/obj/structure/closet/crate/secure/loot/Initialize(mapload)
+ . = ..()
+ GLOB.tutorial_ruin_caches += src
+
+/obj/structure/closet/crate/secure/loot/Destroy()
+ GLOB.tutorial_ruin_caches -= src
+ return ..()
+
+/// The planet the viewer stands on or is berthed at, or null.
+/proc/tutorial_planet_under(mob/user)
+ var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
+ if(ship)
+ var/obj/structure/overmap/berth = ship.docked
+ if(istype(berth, /obj/structure/overmap/planet) && !istype(berth, /obj/structure/overmap/planet/empty))
+ return berth
+ return null
+ var/turf/here = get_turf(user)
+ if(!here)
+ return null
+ var/obj/structure/overmap/planet/planet = SSovermap_zones.get_overmap_object_for_turf(here)
+ if(istype(planet) && !istype(planet, /obj/structure/overmap/planet/empty))
+ return planet
+ return null
+
+/// TRUE if a landmark and a turf share a map tenant (a planet on a shared level).
+/proc/tutorial_same_tenant(turf/here, turf/there)
+ if(!here || !there || here.z != there.z)
+ return FALSE
+ var/datum/map_footprint/tenant = map_footprint_containing_turf(here)
+ return !tenant || tenant.contains_turf(there)
+
+/// The ruin landmark nearest the viewer on their planet, or null.
+/proc/tutorial_nearest_ruin_landmark(mob/user)
+ var/turf/here = get_turf(user)
+ if(!here)
+ return null
+ var/datum/map_footprint/tenant = map_footprint_containing_turf(here)
+ var/obj/effect/landmark/ruin/nearest
+ var/nearest_dist
+ for(var/obj/effect/landmark/ruin/mark as anything in GLOB.ruin_landmarks)
+ if(QDELETED(mark) || mark.z != here.z || !mark.ruin_template)
+ continue
+ var/turf/spot = get_turf(mark)
+ if(!spot || (tenant && !tenant.contains_turf(spot)))
+ continue
+ var/dist = get_dist(here, spot)
+ if(dist > TUTORIAL_RUIN_RANGE)
+ continue
+ if(!nearest || dist < nearest_dist)
+ nearest = mark
+ nearest_dist = dist
+ return nearest
+
+/// TRUE if a turf lies inside the area a ruin template was loaded over (centred on its landmark).
+/proc/tutorial_in_ruin_footprint(turf/spot, obj/effect/landmark/ruin/mark)
+ var/datum/map_template/ruin/template = mark?.ruin_template
+ var/turf/center = get_turf(mark)
+ if(!spot || !template || !center || spot.z != center.z)
+ return FALSE
+ return abs(spot.x - center.x) <= CEILING(template.width / 2, 1) && abs(spot.y - center.y) <= CEILING(template.height / 2, 1)
+
+/**
+ * TRUE if the viewer stands inside a ruin's footprint on their planet. With credit, also
+ * credits Find a ruin (on the next tick: this runs inside a highlight rebuild, and a
+ * credit starts another one).
+ */
+/proc/tutorial_ruin_footprint_check(mob/user, credit = FALSE)
+ var/turf/here = get_turf(user)
+ if(!here || get_ship_from_atom(user))
+ return FALSE
+ var/inside = FALSE
+ for(var/obj/effect/landmark/ruin/mark as anything in GLOB.ruin_landmarks)
+ if(QDELETED(mark) || mark.z != here.z)
+ continue
+ if(tutorial_in_ruin_footprint(here, mark))
+ inside = TRUE
+ break
+ if(inside && credit && user.ckey)
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(tutorial_credit_ruin_footprint), WEAKREF(user)), 0)
+ return inside
+
+/proc/tutorial_credit_ruin_footprint(datum/weakref/user_ref)
+ var/mob/user = user_ref?.resolve()
+ if(user && tutorial_ruin_footprint_check(user))
+ tutorial_credit(user, TUTORIAL_STEP_RUIN_FIND)
+
+/// Closed, countable caches near the viewer on their planet.
+/proc/tutorial_nearby_ruin_caches(mob/user)
+ . = list()
+ var/turf/here = get_turf(user)
+ if(!here)
+ return
+ for(var/obj/structure/closet/cache as anything in GLOB.tutorial_ruin_caches)
+ if(cache.opened || cache.z != here.z || get_dist(here, cache) > TUTORIAL_CACHE_RANGE)
+ continue
+ if(!tutorial_same_tenant(here, get_turf(cache)) || !tutorial_countable_cache(cache))
+ continue
+ . += cache
+
+#undef TUTORIAL_RUIN_RANGE
+#undef TUTORIAL_CACHE_RANGE
+
+/// Walking into a ruin. No ship maps /area/ruin.
+/area/ruin/Entered(atom/movable/arrived, area/old_area)
+ . = ..()
+ if(!ismob(arrived))
+ return
+ var/mob/visitor = arrived
+ if(!visitor.ckey || SSvc_tutorials.progress[visitor.ckey]?[TUTORIAL_STEP_RUIN_FIND])
+ return
+ tutorial_credit(visitor, TUTORIAL_STEP_RUIN_FIND)
diff --git a/voidcrew/modules/tutorials/hooks_zones.dm b/voidcrew/modules/tutorials/hooks_zones.dm
new file mode 100644
index 00000000000..17d350d1b80
--- /dev/null
+++ b/voidcrew/modules/tutorials/hooks_zones.dm
@@ -0,0 +1,21 @@
+// Tutorial checklist hooks. Part A: the Zones item (entering yellow and red space,
+// researching Shuttle Warfare Systems). Overrides chain with any others of the same proc.
+
+/// The crossing timer lands here once the ship is actually over the line.
+/obj/structure/overmap/ship/complete_zone_transition()
+ . = ..()
+ if(QDELETED(src) || istype(src, /obj/structure/overmap/ship/npc) || !SSovermap_zones?.initialized)
+ return
+ var/zone_type = SSovermap_zones.get_zone_type(get_turf(src))
+ if(zone_type == ZONE_YELLOW || zone_type == ZONE_RED)
+ tutorial_credit_crew(src, TUTORIAL_STEP_ZONES_YELLOW, aboard_only = TRUE)
+ if(zone_type == ZONE_RED)
+ tutorial_credit_crew(src, TUTORIAL_STEP_ZONES_RED, aboard_only = TRUE)
+
+/datum/techweb/research_node(datum/techweb_node/node, force = FALSE, auto_adjust_cost = TRUE, get_that_dosh = TRUE, atom/research_source)
+ . = ..()
+ if(!. || !istype(node) || node.id != TECHWEB_NODE_SHIP_COMBAT)
+ return
+ var/obj/structure/overmap/ship/ship = metric_techweb_ship(src)
+ if(ship)
+ tutorial_credit_crew(ship, TUTORIAL_STEP_ZONES_WARFARE)
diff --git a/voidcrew/modules/tutorials/preferences.dm b/voidcrew/modules/tutorials/preferences.dm
new file mode 100644
index 00000000000..05f7b99418a
--- /dev/null
+++ b/voidcrew/modules/tutorials/preferences.dm
@@ -0,0 +1,14 @@
+/// Opens the tutorial checklist by itself after every spawn. Progress is tracked
+/// either way; this only controls the automatic window (tutorial_panel.dm).
+/datum/preference/toggle/tutorial_checklist
+ category = PREFERENCE_CATEGORY_GAME_PREFERENCES
+ savefile_key = "tutorial_checklist"
+ savefile_identifier = PREFERENCE_PLAYER
+ default_value = TRUE
+
+/// Outlines the objects the open tutorial item points at (tutorial_highlights.dm).
+/datum/preference/toggle/tutorial_highlights
+ category = PREFERENCE_CATEGORY_GAME_PREFERENCES
+ savefile_key = "tutorial_highlights"
+ savefile_identifier = PREFERENCE_PLAYER
+ default_value = TRUE
diff --git a/voidcrew/modules/tutorials/tutorial_catalog.dm b/voidcrew/modules/tutorials/tutorial_catalog.dm
new file mode 100644
index 00000000000..f6530936fed
--- /dev/null
+++ b/voidcrew/modules/tutorials/tutorial_catalog.dm
@@ -0,0 +1,1979 @@
+/**
+ * # Tutorial checklist catalog
+ *
+ * One /datum/vc_tutorial per checklist item and one /datum/vc_tutorial_step per step,
+ * each a singleton owned by SSvc_tutorials. Steps are credited passively by hooks
+ * (hooks_*.dm) calling tutorial_credit() or tutorial_credit_crew() with a step key
+ * from voidcrew/_DEFINES/tutorials.dm. Nothing here acts on the world.
+ *
+ * The panel is the one place how-to text is allowed in player UI (kit rule exception
+ * for the checklist). Keep the intro to 1-3 plain sentences and each step to one line.
+ *
+ * Adding an item: give it an id, a category (TUTORIAL_CATEGORY_*), an order within that
+ * category, an intro and its steps. A step with a route is one way to finish the item:
+ * give every step of one way the same route id and route_name, and the item needs at
+ * least two routes. Once every counted step of one route is done, the other routes'
+ * steps are excused.
+ */
+
+/// Panel categories, in panel order: category id -> name.
+GLOBAL_LIST_INIT(tutorial_categories, list(
+ TUTORIAL_CATEGORY_START = "Getting started",
+ TUTORIAL_CATEGORY_EXPLORE = "Exploring",
+ TUTORIAL_CATEGORY_BODY = "Your body",
+ TUTORIAL_CATEGORY_FIGHT = "Fighting",
+ TUTORIAL_CATEGORY_KEEP = "Keeping your ship",
+))
+
+/datum/vc_tutorial
+ /// Item key, a TUTORIAL_ITEM_* define. Written to the DB when the item completes.
+ var/id
+ /// Shown in the panel's item list.
+ var/name
+ /// The panel category it is listed under, a TUTORIAL_CATEGORY_* define.
+ var/category
+ /// Position within its category, lowest first.
+ var/order = 0
+ /// 1-3 plain sentences on how the system works, shown above the steps.
+ var/intro
+ /// Step typepaths, in the order they are shown.
+ var/list/steps = list()
+
+/datum/vc_tutorial_step
+ /// Step key, a TUTORIAL_STEP_* define. At most 64 characters.
+ var/key
+ /// Short imperative title.
+ var/name
+ /// One plain line of how-to text.
+ var/text
+ /// Optional steps are shown but never counted toward the item.
+ var/optional = FALSE
+ /// Route id. Steps sharing one form one way to finish the item; null for shared steps.
+ var/route
+ /// The route's heading in the panel.
+ var/route_name
+ /// Atom types (objects, mobs or turfs) the in-game highlight outlines while this step is the
+ /// guide step. Empty when no fixed type fits; see extra_targets() and highlight_filter().
+ var/list/highlight_types
+ /// Window id -> focus key. While this is the viewer's guide step, a window whose ui_data sends
+ /// tutorial_ui_focus(user, window id) pulses the element wrapped in .
+ /// Example: list("helm" = "helm_dock").
+ var/list/ui_focus
+
+/**
+ * A short note shown under the step for this viewer, or null.
+ * Machine scans are cached per ship by SSvc_tutorials.
+ * A note also tells suggested_item() the step can't be done yet; use live_line() for state.
+ */
+/datum/vc_tutorial_step/proc/availability(mob/user)
+ return null
+
+/**
+ * A short line of live state shown under the step while it is undone, or null.
+ * Example: "Batteries at 12%". It is state, never rules. Plain text: React renders it as text,
+ * so don't html_encode it. Called only for the viewer's open item, about every 5 s while the
+ * panel is open. It never affects suggested_item().
+ */
+/datum/vc_tutorial_step/proc/live_line(mob/user)
+ return null
+
+/**
+ * TRUE to keep a highlight candidate (a highlight_types match or an extra_targets() entry).
+ * Example: only the unlinked machine, only the armed missile.
+ */
+/datum/vc_tutorial_step/proc/highlight_filter(mob/user, atom/candidate)
+ return TRUE
+
+/**
+ * Atoms to highlight besides highlight_types matches: specific mobs, turfs or objects.
+ * Only atoms on the viewer's z-level are used. Default empty.
+ */
+/datum/vc_tutorial_step/proc/extra_targets(mob/user)
+ return list()
+
+/**
+ * What the off-screen arrow points at, or null for no arrow. The arrow hides while the target
+ * is on the viewer's screen. The default is the nearest highlight candidate on the viewer's
+ * z-level within TUTORIAL_ARROW_RANGE tiles, and no arrow at all while any candidate is on
+ * screen. Override it for things that aren't highlight candidates (the nearest ruin).
+ */
+/datum/vc_tutorial_step/proc/arrow_target(mob/user)
+ return tutorial_default_arrow_target(user, tutorial_step_candidates(user, src))
+
+/**
+ * TRUE when this step should not count toward its item for this viewer, for example
+ * a captain-only step seen by a crewmate, or a route step once another route is done.
+ * Overrides must keep the parent's result.
+ */
+/datum/vc_tutorial_step/proc/excused(mob/user)
+ return route_excused(tutorial_viewer_ckey(user))
+
+/**
+ * TRUE when this is a route step and every counted step of a different route in the same
+ * item is done for this ckey. Reads SSvc_tutorials.progress only, so it never recurses.
+ */
+/datum/vc_tutorial_step/proc/route_excused(ckey)
+ if(!route || !ckey)
+ return FALSE
+ var/list/done = SSvc_tutorials.progress[ckey]
+ var/datum/vc_tutorial/item = SSvc_tutorials.item_by_step?[key]
+ if(!done || !item)
+ return FALSE
+ // route id -> TRUE while every counted step of it is done so far
+ var/list/finished = list()
+ for(var/datum/vc_tutorial_step/other as anything in item.steps)
+ if(!other.route || other.route == route || other.optional)
+ continue
+ if(isnull(finished[other.route]))
+ finished[other.route] = TRUE
+ if(!done[other.key])
+ finished[other.route] = FALSE
+ for(var/other_route in finished)
+ if(finished[other_route])
+ return TRUE
+ return FALSE
+
+/**
+ * State check run when the panel opens. TRUE credits the step to the viewer.
+ * Use it for things a player may have finished before the hook could see them.
+ */
+/datum/vc_tutorial_step/proc/state_satisfied(mob/user)
+ return FALSE
+
+// ---------------------------------------------------------------------------
+// Your ship
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/ship
+ id = TUTORIAL_ITEM_SHIP
+ name = "Your ship"
+ category = TUTORIAL_CATEGORY_START
+ order = 1
+ intro = "The helm flies the ship and docks it at planets, outposts and ruins. The captain runs the crew and ship settings from Ship Management. Your ship's lockers hold most of what you need to start."
+ steps = list(
+ /datum/vc_tutorial_step/ship_manage,
+ /datum/vc_tutorial_step/ship_search,
+ /datum/vc_tutorial_step/ship_course,
+ /datum/vc_tutorial_step/ship_dock,
+ /datum/vc_tutorial_step/ship_undock,
+ /datum/vc_tutorial_step/ship_build,
+ )
+
+/datum/vc_tutorial_step/ship_manage
+ key = TUTORIAL_STEP_SHIP_MANAGE
+ name = "Open Ship Management"
+ text = "Use the Ship Management button at the top left to see your crew, invites and ship settings."
+
+/datum/vc_tutorial_step/ship_manage/availability(mob/user)
+ if(excused(user))
+ return "Captain only."
+ return null
+
+/datum/vc_tutorial_step/ship_manage/excused(mob/user)
+ if(..())
+ return TRUE
+ return !(locate(/datum/action/innate/captain_management) in user?.actions)
+
+/datum/vc_tutorial_step/ship_search
+ key = TUTORIAL_STEP_SHIP_SEARCH
+ name = "Search the lockers"
+ text = "Open your ship's lockers and crates, or Alt-click a tile to see everything on it."
+ highlight_types = list(/obj/structure/closet)
+
+/// Skip lockers someone already opened or emptied. A closet that was never opened may not
+/// have made its contents yet, so it still counts.
+/datum/vc_tutorial_step/ship_search/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/closet/closet = candidate
+ if(!istype(closet))
+ return TRUE
+ if(closet.opened)
+ return FALSE
+ return !closet.contents_initialized || length(closet.contents)
+
+/// Shared by the helm steps: a hull with no helm can't do them.
+/datum/vc_tutorial_step/proc/no_helm_note(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(ship && !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/computer/helm))
+ return "No helm aboard."
+ return null
+
+/datum/vc_tutorial_step/ship_course
+ key = TUTORIAL_STEP_SHIP_COURSE
+ name = "Set a course"
+ text = "At the helm, pick a heading, or right-click the chart to fly there on autopilot."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_course")
+
+/datum/vc_tutorial_step/ship_course/availability(mob/user)
+ return no_helm_note(user)
+
+/datum/vc_tutorial_step/ship_course/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship?.shuttle || !isturf(ship.loc))
+ return null
+ if(!ship.can_thrust())
+ return "The engines have no power."
+ return null
+
+/datum/vc_tutorial_step/ship_dock
+ key = TUTORIAL_STEP_SHIP_DOCK
+ name = "Dock"
+ text = "Fly onto a planet, outpost or ruin and press Dock at the helm."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_dock")
+
+/datum/vc_tutorial_step/ship_dock/availability(mob/user)
+ return no_helm_note(user)
+
+/datum/vc_tutorial_step/ship_dock/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ if(ship.dock_warmup_timer || ship.state == OVERMAP_SHIP_DOCKING)
+ return "Docking..."
+ if(!isturf(ship.loc))
+ return "Docked. Undock to fly somewhere new."
+ if(!ship.is_still() && MAGNITUDE(ship.speed[1], ship.speed[2]) > ship.max_speed * DOCK_ASSIST_SPEED_FRACTION)
+ return "Too fast to dock."
+ return null
+
+/datum/vc_tutorial_step/ship_undock
+ key = TUTORIAL_STEP_SHIP_UNDOCK
+ name = "Undock"
+ text = "Press Undock at the helm to leave."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_undock")
+
+/datum/vc_tutorial_step/ship_undock/availability(mob/user)
+ return no_helm_note(user)
+
+/// The same blocks the helm's Undock button shows, in the order it checks them.
+/datum/vc_tutorial_step/ship_undock/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship || isturf(ship.loc))
+ return null
+ if(ship.undock_warmup_timer || ship.state == OVERMAP_SHIP_UNDOCKING)
+ return "Undocking..."
+ if(!COOLDOWN_FINISHED(ship, integrity_undock_lockout))
+ return "The hull is too damaged to leave yet."
+ if(!COOLDOWN_FINISHED(ship, interdiction_undock_lockout))
+ return "Held by an interdiction."
+ if(!COOLDOWN_FINISHED(ship, undock_cooldown))
+ return "The docking clamps are still cycling."
+ var/datum/voidcrew_cargo_shuttle/cargo_shuttle = ship.get_cargo_shuttle()
+ if(cargo_shuttle && cargo_shuttle.state != CARGO_SHUTTLE_AWAY)
+ return "The cargo shuttle is aboard."
+ return null
+
+/datum/vc_tutorial_step/ship_build
+ key = TUTORIAL_STEP_SHIP_BUILD
+ name = "See the construction console"
+ text = "Research Shuttle Construction, build the console, and use its drone to change your hull."
+ optional = TRUE
+ highlight_types = list(/obj/machinery/computer/camera_advanced/base_construction/ship)
+
+/datum/vc_tutorial_step/ship_build/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship || SSvc_tutorials.ship_has_machine(ship, /obj/machinery/computer/camera_advanced/base_construction/ship))
+ return null
+ var/datum/techweb/web = ship.get_research_web()
+ if(!web)
+ return null
+ if(web.researched_nodes[TECHWEB_NODE_SHIP_CONSTRUCTION])
+ return "Researched. Print its board at the circuit imprinter."
+ return "Shuttle Construction isn't researched yet."
+
+// ---------------------------------------------------------------------------
+// First contract
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/contract
+ id = TUTORIAL_ITEM_CONTRACT
+ name = "First contract"
+ category = TUTORIAL_CATEGORY_START
+ order = 5
+ intro = "Contracts are paid jobs from the board on your ship or from outpost traders. Do the job, bring back what they asked for and turn it in at the pad."
+ steps = list(
+ /datum/vc_tutorial_step/contract_take,
+ /datum/vc_tutorial_step/contract_work,
+ /datum/vc_tutorial_step/contract_turn_in,
+ )
+
+/datum/vc_tutorial_step/contract_take
+ key = TUTORIAL_STEP_CONTRACT_TAKE
+ name = "Take a contract"
+ text = "Open the contract board and press Accept Mission on a contract. At an outpost, the main trader has Contracts."
+ highlight_types = list(/obj/machinery/computer/mission_board, /mob/living/basic/outpost_trader)
+ ui_focus = list("board" = "board_accept")
+
+/datum/vc_tutorial_step/contract_take/availability(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(ship && !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/computer/mission_board))
+ return "No board aboard. Traders offer contracts, or research Mission Logistics."
+ return null
+
+/datum/vc_tutorial_step/contract_work
+ key = TUTORIAL_STEP_CONTRACT_WORK
+ name = "Do the job"
+ text = "Do what the contract asks. Jobs at a site are marked on the helm."
+ ui_focus = list("board" = "board_active_tab")
+
+/datum/vc_tutorial_step/contract_turn_in
+ key = TUTORIAL_STEP_CONTRACT_TURN_IN
+ name = "Get paid"
+ text = "Put the goods on the pad and press Turn In under Active, or Complete if there's nothing to hand over. Traders take goods from your hands."
+ highlight_types = list(/obj/machinery/mission_pad, /obj/machinery/computer/mission_board)
+ ui_focus = list("board" = "board_turn_in")
+
+// ---------------------------------------------------------------------------
+// R&D setup
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/research
+ id = TUTORIAL_ITEM_RESEARCH
+ name = "R&D setup"
+ category = TUTORIAL_CATEGORY_START
+ order = 3
+ intro = "Research unlocks new gear and machines for your ship. You need a server, a console and a protolathe, all linked together. The autolathe prints a kit with everything to start."
+ steps = list(
+ /datum/vc_tutorial_step/research_kit,
+ /datum/vc_tutorial_step/research_server,
+ /datum/vc_tutorial_step/research_disk,
+ /datum/vc_tutorial_step/research_console,
+ /datum/vc_tutorial_step/research_protolathe,
+ /datum/vc_tutorial_step/research_multitool,
+ /datum/vc_tutorial_step/research_link,
+ )
+
+/datum/vc_tutorial_step/research_kit
+ key = TUTORIAL_STEP_RESEARCH_KIT
+ name = "Get the R&D kit"
+ text = "Print the Research & Development Kit at the autolathe and pick it up."
+ highlight_types = list(/obj/machinery/autolathe, /obj/item/storage/box/rndboards/all)
+ ui_focus = list("autolathe" = "autolathe_rndkit")
+
+/// A hull that already has a ship server is past needing the kit.
+/datum/vc_tutorial_step/research_kit/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/rnd/server/ship)
+
+/datum/vc_tutorial_step/research_server
+ key = TUTORIAL_STEP_RESEARCH_SERVER
+ name = "Build the R&D server"
+ text = "Set the server flatpack on the floor and use a multitool on it."
+ highlight_types = list(/obj/item/flatpack)
+
+/datum/vc_tutorial_step/research_server/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/rnd/server/ship)
+
+/// Only the server's flatpack, not the other three from the kit.
+/datum/vc_tutorial_step/research_server/highlight_filter(mob/user, atom/candidate)
+ return tutorial_flatpack_builds(candidate, list(/obj/machinery/rnd/server/ship))
+
+/datum/vc_tutorial_step/research_server/live_line(mob/user)
+ return tutorial_tool_line(user, TOOL_MULTITOOL)
+
+/datum/vc_tutorial_step/research_disk
+ key = TUTORIAL_STEP_RESEARCH_DISK
+ name = "Add the ship disk"
+ text = "Put the R&D server source code disk from the kit into the server."
+ highlight_types = list(/obj/machinery/rnd/server/ship, /obj/item/computer_disk/ship_disk)
+
+/datum/vc_tutorial_step/research_disk/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return !!ship?.get_research_web()
+
+/datum/vc_tutorial_step/research_console
+ key = TUTORIAL_STEP_RESEARCH_CONSOLE
+ name = "Set up the R&D console"
+ text = "Use the kit's iron in hand to make a computer frame. Wrench it, add the console board, screwdriver it, add 5 cable and 2 glass, then screwdriver it again."
+ highlight_types = list(/obj/structure/frame/computer)
+
+/datum/vc_tutorial_step/research_console/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/computer/rdconsole)
+
+/// Empty frames and frames holding the R&D console board.
+/datum/vc_tutorial_step/research_console/highlight_filter(mob/user, atom/candidate)
+ return tutorial_frame_for(candidate, /obj/item/circuitboard/computer/rdconsole)
+
+/datum/vc_tutorial_step/research_console/live_line(mob/user)
+ var/obj/structure/frame/computer/frame = tutorial_nearest_frame(user, src, /obj/item/circuitboard/computer/rdconsole)
+ if(!frame)
+ return "No computer frame yet."
+ return tutorial_frame_line(user, frame)
+
+/datum/vc_tutorial_step/research_protolathe
+ key = TUTORIAL_STEP_RESEARCH_PROTOLATHE
+ name = "Set up the protolathe"
+ text = "Set the protolathe flatpack on the floor and use a multitool on it. Do the same with the circuit imprinter."
+ highlight_types = list(/obj/item/flatpack)
+
+/datum/vc_tutorial_step/research_protolathe/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/rnd/production/protolathe)
+
+/datum/vc_tutorial_step/research_protolathe/highlight_filter(mob/user, atom/candidate)
+ return tutorial_flatpack_builds(candidate, list(/obj/machinery/rnd/production/protolathe, /obj/machinery/rnd/production/circuit_imprinter))
+
+/datum/vc_tutorial_step/research_protolathe/live_line(mob/user)
+ return tutorial_tool_line(user, TOOL_MULTITOOL)
+
+/datum/vc_tutorial_step/research_multitool
+ key = TUTORIAL_STEP_RESEARCH_MULTITOOL
+ name = "Multitool the server"
+ text = "Hold a multitool and use it on the server to copy its link."
+ highlight_types = list(/obj/machinery/rnd/server/ship)
+
+/// A hull whose console and protolathe already run off its server got here some other way.
+/datum/vc_tutorial_step/research_multitool/state_satisfied(mob/user)
+ return tutorial_ship_rnd_linked(get_crew_ship(user))
+
+/datum/vc_tutorial_step/research_multitool/live_line(mob/user)
+ return tutorial_tool_line(user, TOOL_MULTITOOL)
+
+/datum/vc_tutorial_step/research_link
+ key = TUTORIAL_STEP_RESEARCH_LINK
+ name = "Link all the devices"
+ text = "Use that multitool on the R&D console, the protolathe and the circuit imprinter."
+ highlight_types = list(/obj/machinery/computer/rdconsole, /obj/machinery/rnd/production/protolathe, /obj/machinery/rnd/production/circuit_imprinter)
+
+/datum/vc_tutorial_step/research_link/state_satisfied(mob/user)
+ return tutorial_ship_rnd_linked(get_crew_ship(user))
+
+/// Only the machines that aren't on the ship's research web yet.
+/datum/vc_tutorial_step/research_link/highlight_filter(mob/user, atom/candidate)
+ return !tutorial_rnd_device_linked(candidate, get_crew_ship(user)?.get_research_web())
+
+/datum/vc_tutorial_step/research_link/live_line(mob/user)
+ var/datum/techweb/web = get_crew_ship(user)?.get_research_web()
+ if(!web)
+ return null
+ var/unlinked_tool = FALSE
+ for(var/obj/item/multitool/tool in user.get_all_contents())
+ if(tool.buffer == web)
+ unlinked_tool = FALSE
+ break
+ unlinked_tool = TRUE
+ if(unlinked_tool)
+ return "Your multitool has no server link."
+ var/list/unlinked = list()
+ for(var/atom/machine as anything in tutorial_step_candidates(user, src))
+ var/label = tutorial_rnd_device_label(machine)
+ if(label)
+ unlinked |= label
+ if(!length(unlinked))
+ return null
+ return "Not linked: [unlinked.Join(", ")]."
+
+// ---------------------------------------------------------------------------
+// Surveys
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/surveys
+ id = TUTORIAL_ITEM_SURVEYS
+ name = "Surveys"
+ category = TUTORIAL_CATEGORY_EXPLORE
+ order = 1
+ intro = "A survey console scans a planet from orbit and prints research notes. The R&D console turns the notes into research points."
+ steps = list(
+ /datum/vc_tutorial_step/surveys_node,
+ /datum/vc_tutorial_step/surveys_build,
+ /datum/vc_tutorial_step/surveys_survey,
+ /datum/vc_tutorial_step/surveys_notes,
+ )
+
+/datum/vc_tutorial_step/surveys_node
+ key = TUTORIAL_STEP_SURVEYS_NODE
+ name = "Research the survey console"
+ text = "At the R&D console, research Orbital survey console. It's on the Available tab."
+ highlight_types = list(/obj/machinery/computer/rdconsole)
+ ui_focus = list("rdconsole" = "rd_node_" + TECHWEB_NODE_SURVEY_CONSOLE)
+
+/datum/vc_tutorial_step/surveys_node/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/techweb/web = ship?.get_research_web()
+ return !!web?.researched_nodes[TECHWEB_NODE_SURVEY_CONSOLE]
+
+/datum/vc_tutorial_step/surveys_node/live_line(mob/user)
+ return tutorial_node_points_line(get_crew_ship(user)?.get_research_web(), TECHWEB_NODE_SURVEY_CONSOLE)
+
+/datum/vc_tutorial_step/surveys_build
+ key = TUTORIAL_STEP_SURVEYS_BUILD
+ name = "Build a survey console"
+ text = "Print the Orbital survey console board at the circuit imprinter. Build it in a computer frame like the R&D console."
+ highlight_types = list(
+ /obj/machinery/rnd/production/circuit_imprinter,
+ /obj/item/flatpack,
+ /obj/structure/frame/computer,
+ /obj/item/circuitboard/computer/survey_shuttle_docker,
+ )
+ ui_focus = list("imprinter" = "imprinter_survey_console_board")
+
+/datum/vc_tutorial_step/surveys_build/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/computer/camera_advanced/shuttle_docker/survey)
+
+/// The imprinter's flatpack while no imprinter is aboard, and frames empty or holding the survey board.
+/datum/vc_tutorial_step/surveys_build/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/item/flatpack))
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(ship && SSvc_tutorials.ship_has_machine(ship, /obj/machinery/rnd/production/circuit_imprinter))
+ return FALSE
+ return tutorial_flatpack_builds(candidate, list(/obj/machinery/rnd/production/circuit_imprinter))
+ if(istype(candidate, /obj/structure/frame/computer))
+ return tutorial_frame_for(candidate, /obj/item/circuitboard/computer/survey_shuttle_docker)
+ return TRUE
+
+/datum/vc_tutorial_step/surveys_build/live_line(mob/user)
+ var/datum/techweb/web = get_crew_ship(user)?.get_research_web()
+ if(!web)
+ return null
+ var/obj/structure/frame/computer/frame = tutorial_nearest_frame(user, src, /obj/item/circuitboard/computer/survey_shuttle_docker, TRUE)
+ if(frame)
+ return tutorial_frame_line(user, frame)
+ var/has_imprinter = FALSE
+ for(var/obj/machinery/rnd/production/circuit_imprinter/imprinter in tutorial_step_candidates(user, src))
+ has_imprinter = TRUE
+ if(imprinter.stored_research == web)
+ return null
+ if(has_imprinter)
+ return "The circuit imprinter isn't linked to the server."
+ return "No circuit imprinter set up."
+
+/datum/vc_tutorial_step/surveys_survey
+ key = TUTORIAL_STEP_SURVEYS_SURVEY
+ name = "Survey a planet"
+ text = "Park the ship on a planet's tile and start a survey at the console. Keep the ship still until it ends."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/shuttle_docker/survey)
+ ui_focus = list("survey" = "survey_start")
+
+/datum/vc_tutorial_step/surveys_survey/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/obj/machinery/computer/camera_advanced/shuttle_docker/survey/console = ship.survey_console?.resolve()
+ if(!console)
+ return "No survey console aboard."
+ if(console.survey_in_progress)
+ return "Surveying. Keep the ship still."
+ if(console.tutorial_moved_at && world.time < console.tutorial_moved_at + 2 MINUTES)
+ return "The last survey stopped when the ship moved."
+ if(!ship.is_still())
+ return "The ship is moving."
+ var/list/blacklisted_types = console.get_blacklisted_overmap_types()
+ for(var/obj/structure/overmap/object in ship.close_overmap_objects)
+ if(!is_type_in_list(object, blacklisted_types))
+ return "Over [object.name]."
+ return "Nothing to survey on this tile."
+
+/datum/vc_tutorial_step/surveys_notes
+ key = TUTORIAL_STEP_SURVEYS_NOTES
+ name = "Turn in the notes"
+ text = "Print the notes on the survey console's Research tab and use them on the R&D console."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/shuttle_docker/survey, /obj/item/research_notes, /obj/machinery/computer/rdconsole)
+ ui_focus = list("survey" = "survey_print")
+
+/// The survey console only while it has research waiting to print.
+/datum/vc_tutorial_step/surveys_notes/highlight_filter(mob/user, atom/candidate)
+ var/obj/machinery/computer/camera_advanced/shuttle_docker/survey/console = candidate
+ if(istype(console))
+ return console.banked_points > 0
+ return TRUE
+
+/datum/vc_tutorial_step/surveys_notes/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/obj/machinery/computer/camera_advanced/shuttle_docker/survey/console = ship?.survey_console?.resolve()
+ if(console?.banked_points > 0)
+ return "[console.banked_points] research waiting to print."
+ return null
+
+// ---------------------------------------------------------------------------
+// Planet ruin
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/ruin
+ id = TUTORIAL_ITEM_RUIN
+ name = "Planet ruin"
+ category = TUTORIAL_CATEGORY_EXPLORE
+ order = 2
+ intro = "Planets are dotted with ruins people left behind. Most hold loot, often an abandoned cache, and usually something guarding it."
+ steps = list(
+ /datum/vc_tutorial_step/ruin_land,
+ /datum/vc_tutorial_step/ruin_find,
+ /datum/vc_tutorial_step/ruin_cache,
+ )
+
+/datum/vc_tutorial_step/ruin_land
+ key = TUTORIAL_STEP_RUIN_LAND
+ name = "Land on a planet"
+ text = "Fly onto a planet and press Dock at the helm."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_dock")
+
+/// Already berthed on a planet, or standing on one: a late joiner walks straight out.
+/datum/vc_tutorial_step/ruin_land/state_satisfied(mob/user)
+ return !!tutorial_planet_under(user)
+
+/datum/vc_tutorial_step/ruin_land/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
+ var/obj/structure/overmap/berth = ship?.docked
+ if(!berth || tutorial_planet_under(user))
+ return null
+ return "Docked at [berth]."
+
+/datum/vc_tutorial_step/ruin_find
+ key = TUTORIAL_STEP_RUIN_FIND
+ name = "Find a ruin"
+ text = "Walk out and explore until you find a place someone left behind."
+
+/// Open-air ruins have no ruin area to walk into, so standing inside one's footprint counts.
+/datum/vc_tutorial_step/ruin_find/state_satisfied(mob/user)
+ return tutorial_ruin_footprint_check(user, credit = FALSE)
+
+/datum/vc_tutorial_step/ruin_find/arrow_target(mob/user)
+ if(tutorial_ruin_footprint_check(user, credit = TRUE))
+ return null
+ var/obj/effect/landmark/ruin/mark = tutorial_nearest_ruin_landmark(user)
+ return mark ? get_turf(mark) : null
+
+/datum/vc_tutorial_step/ruin_find/live_line(mob/user)
+ var/obj/effect/landmark/ruin/mark = tutorial_nearest_ruin_landmark(user)
+ var/turf/here = get_turf(user)
+ var/turf/there = get_turf(mark)
+ if(!here || !there || tutorial_in_ruin_footprint(here, mark))
+ return null
+ var/distance = max(10, round(get_dist(here, there), 10))
+ return "A ruin lies about [distance] tiles [dir2text(get_dir(here, there))]."
+
+/datum/vc_tutorial_step/ruin_cache
+ key = TUTORIAL_STEP_RUIN_CACHE
+ name = "Open the cache"
+ text = "Find the abandoned cache and open it. A locked one needs a code; a multitool on it rates your last try."
+ highlight_types = list(/obj/structure/closet/crate/zone_loot, /obj/structure/closet/crate/secure/loot)
+
+/// Unopened caches in the ruin the viewer is in or near, so the arrow finds one behind walls.
+/datum/vc_tutorial_step/ruin_cache/extra_targets(mob/user)
+ return tutorial_nearby_ruin_caches(user)
+
+/// Closed, found caches only: never a bought one, never one aboard a ship.
+/datum/vc_tutorial_step/ruin_cache/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/closet/cache = candidate
+ return istype(cache) && !cache.opened && tutorial_countable_cache(cache)
+
+/datum/vc_tutorial_step/ruin_cache/live_line(mob/user)
+ var/obj/effect/landmark/ruin/mark = tutorial_nearest_ruin_landmark(user)
+ if(!mark || !tutorial_in_ruin_footprint(get_turf(user), mark))
+ return null
+ for(var/obj/structure/closet/cache as anything in GLOB.tutorial_ruin_caches)
+ if(!cache.opened && tutorial_countable_cache(cache) && tutorial_in_ruin_footprint(get_turf(cache), mark))
+ return null
+ return "No closed cache left in this ruin."
+
+// ---------------------------------------------------------------------------
+// Outpost trade
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/trade
+ id = TUTORIAL_ITEM_TRADE
+ name = "Outpost trade"
+ category = TUTORIAL_CATEGORY_EXPLORE
+ order = 3
+ intro = "Outposts are where you buy gear and sell what you found. Each trader has their own stock and a list of things they want."
+ steps = list(
+ /datum/vc_tutorial_step/trade_travel,
+ /datum/vc_tutorial_step/trade_elevator,
+ /datum/vc_tutorial_step/trade_buy,
+ /datum/vc_tutorial_step/trade_sell,
+ )
+
+/datum/vc_tutorial_step/trade_travel
+ key = TUTORIAL_STEP_TRADE_TRAVEL
+ name = "Travel to an outpost and dock"
+ text = "Fly to a trading outpost and press Dock at the helm."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_dock")
+
+/datum/vc_tutorial_step/trade_elevator
+ key = TUTORIAL_STEP_TRADE_ELEVATOR
+ name = "Ride the elevator"
+ text = "Stand in the elevator by your berth's panel and pick the concourse."
+ highlight_types = list(/obj/machinery/outpost_elevator)
+ ui_focus = list("elevator" = "elevator_concourse")
+
+/datum/vc_tutorial_step/trade_buy
+ key = TUTORIAL_STEP_TRADE_BUY
+ name = "Buy something"
+ text = "Click a trader, pick Trade and buy from their stock."
+ highlight_types = list(/mob/living/basic/outpost_trader)
+ ui_focus = list("trader" = "trader_buy")
+
+/datum/vc_tutorial_step/trade_sell
+ key = TUTORIAL_STEP_TRADE_SELL
+ name = "Sell something"
+ text = "Open a trader's Buys tab and sell what they want while carrying it. They won't buy back shop goods."
+ highlight_types = list(/mob/living/basic/outpost_trader)
+ ui_focus = list("trader" = "trader_sell")
+
+// ---------------------------------------------------------------------------
+// Ship power
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/power
+ id = TUTORIAL_ITEM_POWER
+ name = "Ship power"
+ category = TUTORIAL_CATEGORY_START
+ order = 2
+ intro = "Most ships store their power in SMES batteries in engineering. A fuel generator recharges them while it runs. Each room has an APC that switches its lights, machines and air on or off."
+ steps = list(
+ /datum/vc_tutorial_step/power_smes,
+ /datum/vc_tutorial_step/power_generator,
+ /datum/vc_tutorial_step/power_apc,
+ )
+
+/datum/vc_tutorial_step/power_smes
+ key = TUTORIAL_STEP_POWER_SMES
+ name = "Check the batteries"
+ text = "Find the SMES in engineering. It powers the ship."
+ highlight_types = list(/obj/machinery/power/smes)
+
+/datum/vc_tutorial_step/power_smes/availability(mob/user)
+ if(excused(user))
+ return "No batteries aboard."
+ return null
+
+/// Some small hulls run straight off a generator with no SMES at all.
+/datum/vc_tutorial_step/power_smes/excused(mob/user)
+ if(..())
+ return TRUE
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/power/smes)
+
+/datum/vc_tutorial_step/power_smes/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship || !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/power/smes))
+ return null
+ var/stored = 0
+ var/capacity = 0
+ var/output_off = FALSE
+ for(var/obj/machinery/power/smes/battery as anything in ship.get_ship_machines(/obj/machinery/power/smes))
+ if(!battery.output_attempt)
+ output_off = TRUE
+ for(var/obj/item/stock_parts/power_store/cell in battery.component_parts)
+ stored += cell.charge()
+ capacity += cell.max_charge()
+ if(output_off)
+ return "A battery's output is switched off."
+ if(capacity <= 0)
+ return null
+ return "Batteries at [round(stored / capacity * 100)]%."
+
+/datum/vc_tutorial_step/power_generator
+ key = TUTORIAL_STEP_POWER_GENERATOR
+ name = "Start the generator"
+ text = "Bolt the generator down, load its fuel sheets and turn it on."
+ highlight_types = list(/obj/machinery/power/port_gen)
+
+/datum/vc_tutorial_step/power_generator/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship || !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/power/port_gen))
+ return null
+ var/obj/machinery/power/port_gen/generator = tutorial_power_nearest(user, ship.get_ship_machines(/obj/machinery/power/port_gen))
+ if(!generator)
+ return null
+ if(generator.active)
+ return "Running."
+ if(!generator.anchored)
+ return "Not bolted down. Wrench it to the floor."
+ var/obj/machinery/power/port_gen/pacman/pacman = generator
+ if(istype(pacman) && !pacman.HasFuel())
+ var/obj/item/fuel = pacman.sheet_path
+ return "No [initial(fuel.name)] loaded."
+ return "Ready. Turn it on."
+
+/datum/vc_tutorial_step/power_generator/availability(mob/user)
+ if(excused(user))
+ return "No generator aboard. The general store sells one."
+ return null
+
+/datum/vc_tutorial_step/power_generator/excused(mob/user)
+ if(..())
+ return TRUE
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/power/port_gen)
+
+/datum/vc_tutorial_step/power_apc
+ key = TUTORIAL_STEP_POWER_APC
+ name = "Use an APC"
+ text = "Each room has a power panel on the wall. Right-click it to unlock it, then switch things off or back on."
+ highlight_types = list(/obj/machinery/power/apc)
+
+/// The panel for the room the viewer stands in, when it has one; otherwise any.
+/datum/vc_tutorial_step/power_apc/highlight_filter(mob/user, atom/candidate)
+ var/obj/machinery/power/apc/room_apc = tutorial_room_apc(user)
+ return !room_apc || candidate == room_apc
+
+/datum/vc_tutorial_step/power_apc/live_line(mob/user)
+ var/obj/machinery/power/apc/room_apc = tutorial_room_apc(user)
+ if(!room_apc)
+ return null
+ return room_apc.locked ? "This room's panel is locked." : "This room's panel is unlocked."
+
+/// The APC of the ship room the viewer stands in, or null.
+/proc/tutorial_room_apc(mob/user)
+ var/area/room = get_area(user)
+ var/obj/machinery/power/apc/room_apc = room?.apc
+ if(QDELETED(room_apc) || !get_ship_from_atom(room_apc))
+ return null
+ return room_apc
+
+/// The atom in a list nearest the viewer on their z-level, or null.
+/proc/tutorial_power_nearest(mob/user, list/things)
+ var/turf/here = get_turf(user)
+ if(!here)
+ return null
+ var/atom/best
+ var/best_dist = INFINITY
+ for(var/atom/thing as anything in things)
+ var/turf/spot = get_turf(thing)
+ if(spot?.z != here.z)
+ continue
+ var/dist = get_dist(here, spot)
+ if(dist < best_dist)
+ best = thing
+ best_dist = dist
+ return best
+
+// ---------------------------------------------------------------------------
+// Cyberware
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/chrome
+ id = TUTORIAL_ITEM_CHROME
+ name = "Cyberware"
+ category = TUTORIAL_CATEGORY_BODY
+ order = 1
+ intro = "Chrome is cybernetic parts fitted into your body. Some of it lets you finish off a downed enemy in one move."
+ steps = list(
+ /datum/vc_tutorial_step/chrome_buy,
+ /datum/vc_tutorial_step/chrome_install,
+ /datum/vc_tutorial_step/chrome_execute,
+ )
+
+/datum/vc_tutorial_step/chrome_buy
+ key = TUTORIAL_STEP_CHROME_BUY
+ name = "Buy chrome"
+ text = "Halcyon's general store sells a little street chrome. The Back Bay at Quartermain Depot sells more, and the Chop Shop in the red zone sells the rest."
+ highlight_types = list(/mob/living/basic/outpost_trader)
+ ui_focus = list("trader" = "trader_chrome_tab")
+
+/// Only traders whose shelf holds chrome.
+/datum/vc_tutorial_step/chrome_buy/highlight_filter(mob/user, atom/candidate)
+ var/mob/living/basic/outpost_trader/trader = candidate
+ if(!istype(trader))
+ return FALSE
+ return tutorial_shop_sells_chrome(trader.shop)
+
+/// Chrome found in the field and fitted counts: nobody has to buy what they already wear.
+/datum/vc_tutorial_step/chrome_buy/excused(mob/user)
+ . = ..()
+ if(!.)
+ . = SSvc_tutorials.has_key(tutorial_viewer_ckey(user), TUTORIAL_STEP_CHROME_INSTALL)
+
+/datum/vc_tutorial_step/chrome_install
+ key = TUTORIAL_STEP_CHROME_INSTALL
+ name = "Get it installed"
+ text = "Lie in a Chrome Cradle at the Back Bay or the Chop Shop, pick the part and press Install. Surgery can fit it too."
+ highlight_types = list(/obj/machinery/chrome_cradle)
+ ui_focus = list("cradle" = "cradle_install")
+
+/// Cradles are outpost machines, never in a ship scan: any on the viewer's z-level, so the
+/// arrow can lead to one.
+/datum/vc_tutorial_step/chrome_install/extra_targets(mob/user)
+ . = list()
+ var/turf/here = get_turf(user)
+ if(!here)
+ return
+ for(var/obj/machinery/chrome_cradle/cradle as anything in SSmachines.get_machines_by_type(/obj/machinery/chrome_cradle))
+ if(cradle.z == here.z)
+ . += cradle
+
+/datum/vc_tutorial_step/chrome_install/live_line(mob/user)
+ var/obj/item/organ/ware = tutorial_carried_chrome(user)
+ if(!ware)
+ return null
+ var/where = parse_zone(deprecise_zone(ware.zone))
+ if(!cyberware_insert_check(ware, user, silent = TRUE))
+ return "[format_text(ware.name)] ([where]) won't fit."
+ return "[format_text(ware.name)] goes in your [where]."
+
+/// Chrome already in the body counts, whoever fitted it and whenever.
+/datum/vc_tutorial_step/chrome_install/state_satisfied(mob/user)
+ return length(get_installed_cyberware(user)) > 0
+
+/datum/vc_tutorial_step/chrome_execute
+ key = TUTORIAL_STEP_CHROME_EXECUTE
+ name = "Do an execution"
+ text = "Get someone down, stand square on, then finish them with Brawler Myomers, Gorilla Arms, Mantis Blades or a Widowline."
+
+/datum/vc_tutorial_step/chrome_execute/live_line(mob/user)
+ var/list/state = tutorial_chrome_finisher_state(user)
+ return state[1]
+
+/// Someone the viewer could finish right now, if they carry a finisher. Only bodies already
+/// down within a few tiles, in plain sight.
+/datum/vc_tutorial_step/chrome_execute/extra_targets(mob/user)
+ . = list()
+ var/list/state = tutorial_chrome_finisher_state(user)
+ if(!state[2])
+ return
+ for(var/mob/living/carbon/victim in oview(3, user))
+ if(chrome_finisher_valid_victim(user, victim))
+ . += victim
+
+// ---------------------------------------------------------------------------
+// First surgery
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/surgery
+ id = TUTORIAL_ITEM_SURGERY
+ name = "First surgery"
+ category = TUTORIAL_CATEGORY_BODY
+ order = 2
+ intro = "Surgery heals wounds and works on organs. The patient lies down under a sheet or drapes, and each step needs the right tool. Dissecting a body adds to your ship's research."
+ steps = list(
+ /datum/vc_tutorial_step/surgery_start,
+ /datum/vc_tutorial_step/surgery_finish,
+ /datum/vc_tutorial_step/surgery_dissect,
+ )
+
+/datum/vc_tutorial_step/surgery_start
+ key = TUTORIAL_STEP_SURGERY_START
+ name = "Start an operation"
+ text = "Lay a crewmate or yourself on a table or bed, cover them with a bedsheet or surgical drapes, aim at the chest and pick Tend Wounds. The autolathe prints the tools."
+ highlight_types = list(/obj/structure/table, /obj/structure/bed, /obj/item/bedsheet)
+ ui_focus = list("surgery" = "surgery_tend_wounds")
+
+/// Missing tools: the autolathe. Then a sheet. Then somewhere to lie down.
+/datum/vc_tutorial_step/surgery_start/extra_targets(mob/user)
+ . = list()
+ var/list/missing = tutorial_surgery_missing(user)
+ if(!length(missing) || (length(missing) == 1 && missing[1] == "a sheet"))
+ return
+ var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
+ if(!ship)
+ return
+ for(var/obj/machinery/autolathe/lathe as anything in SSmachines.get_machines_by_type_and_subtypes(/obj/machinery/autolathe))
+ if(lathe.z == user.z && get_ship_from_atom(lathe) == ship)
+ . += lathe
+
+/datum/vc_tutorial_step/surgery_start/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/machinery/autolathe))
+ return TRUE
+ var/list/missing = tutorial_surgery_missing(user)
+ if(istype(candidate, /obj/item/bedsheet))
+ return length(missing) == 1 && missing[1] == "a sheet"
+ return !length(missing)
+
+/datum/vc_tutorial_step/surgery_start/live_line(mob/user)
+ var/list/missing = tutorial_surgery_missing(user)
+ if(!length(missing))
+ return null
+ return "Missing: [english_list(missing)]."
+
+/datum/vc_tutorial_step/surgery_finish
+ key = TUTORIAL_STEP_SURGERY_FINISH
+ name = "Finish it"
+ text = "Use the tool each step names, in your active hand, until you mend the incision."
+
+/datum/vc_tutorial_step/surgery_finish/live_line(mob/user)
+ var/datum/surgery/operation = tutorial_surgery_in_reach(user)
+ var/datum/surgery_step/next = operation && GLOB.surgery_steps[operation.steps[operation.status]]
+ if(!next)
+ return null
+ return "Next: [next.name]."
+
+/// The patient of an operation the viewer is working on (never the viewer themselves).
+/datum/vc_tutorial_step/surgery_finish/extra_targets(mob/user)
+ . = list()
+ var/datum/surgery/operation = tutorial_surgery_in_reach(user)
+ var/mob/living/patient = operation?.target
+ if(patient && patient != user)
+ . += patient
+
+/datum/vc_tutorial_step/surgery_dissect
+ key = TUTORIAL_STEP_SURGERY_DISSECT
+ name = "Dissect a body"
+ text = "Lay a corpse or dead creature on a table, cover it, aim at the chest and pick Dissection. Take the notes it gives you to an R&D console."
+ highlight_types = list(/obj/structure/table/optable)
+ ui_focus = list("surgery" = "surgery_dissection")
+
+/// Dead bodies in sight that still have something to teach.
+/datum/vc_tutorial_step/surgery_dissect/extra_targets(mob/user)
+ . = list()
+ var/static/datum/surgery_step/experimental_dissection/pricer
+ if(!pricer)
+ pricer = new
+ for(var/mob/living/body in oview(9, user))
+ if(body.stat != DEAD || HAS_TRAIT(body, TRAIT_DISSECTED) || !isturf(body.loc))
+ continue
+ if(pricer.check_value(body) > body.dissection_points_paid)
+ . += body
+
+// ---------------------------------------------------------------------------
+// Zones (replaces the old orientation briefing)
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/zones
+ id = TUTORIAL_ITEM_ZONES
+ name = "Zones"
+ category = TUTORIAL_CATEGORY_FIGHT
+ order = 1
+ intro = "Space is split into green, yellow and red zones. Green is safe from other crews. In yellow crews can board each other, and in red anything goes."
+ // Warfare research comes first so the checklist agrees with the zone advisory, which warns a
+ // crew crossing into yellow without it.
+ steps = list(
+ /datum/vc_tutorial_step/zones_warfare,
+ /datum/vc_tutorial_step/zones_yellow,
+ /datum/vc_tutorial_step/zones_red,
+ )
+
+/// The viewer's crew ship if the viewer is aboard it, else null.
+/proc/tutorial_aboard_crew_ship(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(ship && get_ship_from_atom(user) == ship)
+ return ship
+ return null
+
+/// TRUE when the viewer is aboard their crew ship and it sits in one of the given zone types.
+/proc/tutorial_aboard_in_zone(mob/user, list/zone_types)
+ var/obj/structure/overmap/ship/ship = tutorial_aboard_crew_ship(user)
+ if(!ship || !SSovermap_zones?.initialized)
+ return FALSE
+ return (SSovermap_zones.get_zone_type_anywhere(get_turf(ship)) in zone_types)
+
+/**
+ * Live line for a zone step: the crossing in progress, or roughly how far the crew ship is from
+ * the ring it has to cross. Zones are static rings around the overmap centre
+ * (SSovermap.get_zone_band_for_turf()); ring_ratio is ZONE_INNER_RING_RATIO for yellow and
+ * ZONE_MIDDLE_RING_RATIO for red.
+ */
+/proc/tutorial_zone_distance_line(mob/user, ring_ratio, zone_name)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ if(ship.zone_transitioning)
+ return "Crossing the line. Don't press stop."
+ if(ship.docked)
+ return "Docked. Undock to fly out."
+ var/turf/here = get_turf(ship)
+ var/turf/centre = SSovermap.overmap_centre
+ if(!istype(here, /turf/open/overmap) || !centre || here.z != centre.z)
+ return null
+ var/max_radius = (OVERMAP_SIZE - 1) / 2
+ var/distance = sqrt((here.x - centre.x) ** 2 + (here.y - centre.y) ** 2)
+ var/tiles = CEILING(ring_ratio * max_radius - distance, 1)
+ if(tiles <= 0)
+ return null
+ return "About [tiles] tile\s to the [zone_name]."
+
+/datum/vc_tutorial_step/zones_warfare
+ key = TUTORIAL_STEP_ZONES_WARFARE
+ name = "Research Shuttle Warfare Systems"
+ text = "At the R&D console, after Basic Shuttle Research. It unlocks the weapons console; each ship weapon has its own research after it."
+ highlight_types = list(/obj/machinery/computer/rdconsole)
+ ui_focus = list("rdconsole" = "rd_node_ship_combat")
+
+/datum/vc_tutorial_step/zones_warfare/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && ship.has_ship_combat_research()
+
+/datum/vc_tutorial_step/zones_warfare/live_line(mob/user)
+ return tutorial_research_line(user, TECHWEB_NODE_SHIP_COMBAT, skip_self = TRUE)
+
+/datum/vc_tutorial_step/zones_yellow
+ key = TUTORIAL_STEP_ZONES_YELLOW
+ name = "Enter the yellow zone"
+ text = "Fly away from the sun. At the line the ship stops for a few seconds to cross; don't press stop. In yellow, other crews can board and rob you."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_course")
+
+/// Covers a player who joins a crew already out in yellow or red.
+/datum/vc_tutorial_step/zones_yellow/state_satisfied(mob/user)
+ return tutorial_aboard_in_zone(user, list(ZONE_YELLOW, ZONE_RED))
+
+/datum/vc_tutorial_step/zones_yellow/live_line(mob/user)
+ return tutorial_zone_distance_line(user, ZONE_INNER_RING_RATIO, ZONE_NAME_YELLOW)
+
+/datum/vc_tutorial_step/zones_red
+ key = TUTORIAL_STEP_ZONES_RED
+ name = "Enter the red zone"
+ text = "Keep flying out past yellow. Anything goes in red. Ships fire on each other and players can kill you for nothing."
+ optional = TRUE
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_course")
+
+/datum/vc_tutorial_step/zones_red/state_satisfied(mob/user)
+ return tutorial_aboard_in_zone(user, list(ZONE_RED))
+
+/datum/vc_tutorial_step/zones_red/live_line(mob/user)
+ return tutorial_zone_distance_line(user, ZONE_MIDDLE_RING_RATIO, ZONE_NAME_RED)
+
+// ---------------------------------------------------------------------------
+// Ship weapons
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/weapons
+ id = TUTORIAL_ITEM_WEAPONS
+ name = "Ship weapons"
+ category = TUTORIAL_CATEGORY_FIGHT
+ order = 2
+ intro = "Shuttle Warfare Systems unlocks the weapons console, and each weapon has its own research after it. Ship weapons only fire in red space. Shields, the interdictor and electronic warfare also need crew reputation to research."
+ steps = list(
+ /datum/vc_tutorial_step/weapon_build/console,
+ /datum/vc_tutorial_step/weapon_build/launcher,
+ /datum/vc_tutorial_step/weapon_build/missile,
+ /datum/vc_tutorial_step/weapon_build/laser,
+ /datum/vc_tutorial_step/weapon_build/shield,
+ /datum/vc_tutorial_step/weapon_build/interdictor,
+ /datum/vc_tutorial_step/weapon_build/ew,
+ )
+
+/// A note while the viewer's crew is below the reputation that ZONE_PERMISSION_ADVANCED
+/// research needs. Reads the crew record without creating one.
+/datum/vc_tutorial_step/proc/crew_reputation_note(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/voidcrew_crew_record/record = ship?.ship_team?.crew_record
+ if(QDELETED(record) || record.get_zone_permission() < ZONE_PERMISSION_ADVANCED)
+ return "Needs more crew reputation."
+ return null
+
+/**
+ * The node to research next on the way to node_id: node_id itself once its prerequisites are in,
+ * else the first missing prerequisite (walked back). Null once node_id is researched.
+ */
+/proc/tutorial_next_research_node(datum/techweb/web, node_id, depth = 0)
+ if(!web || !node_id || web.researched_nodes[node_id] || depth > 8)
+ return null
+ var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id)
+ if(!node)
+ return null
+ for(var/prereq_id in node.prereq_ids)
+ var/datum/techweb_node/missing = tutorial_next_research_node(web, prereq_id, depth + 1)
+ if(missing)
+ return missing
+ return node
+
+/**
+ * "Research X first." for the next node on the way to node_id on the viewer's ship web, or null
+ * once it (or design_id, from a disk) is in. skip_self: say nothing while node_id itself is next,
+ * for a step that already names it. A node held back only by crew reputation says nothing here;
+ * the step's availability() note covers that.
+ */
+/proc/tutorial_research_line(mob/user, node_id, design_id, skip_self = FALSE)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/datum/techweb/web = ship.get_research_web()
+ if(!web)
+ return "No research server running aboard."
+ if(design_id && web.researched_designs[design_id])
+ return null
+ var/datum/techweb_node/next = tutorial_next_research_node(web, node_id)
+ if(!next || (skip_self && next.id == node_id) || !web.have_zone_permission_for_node(next))
+ return null
+ return "Research [next.display_name] first."
+
+/// TRUE when the viewer carries an item of this type anywhere on them.
+/proc/tutorial_carries(mob/user, item_type)
+ if(!user || !item_type)
+ return FALSE
+ return !!(locate(item_type) in user.get_all_contents())
+
+/**
+ * A ship weapon built from a printed board. The guide moves with the build: the R&D console until
+ * the board's research is in, then the printer, then a frame holding that board (or any empty frame
+ * while the viewer carries the board). Credit is on_construction() in hooks_ship_combat.dm.
+ */
+/datum/vc_tutorial_step/weapon_build
+ highlight_types = list(/obj/machinery/computer/rdconsole, /obj/machinery/rnd/production/circuit_imprinter, /obj/structure/frame/machine)
+ /// Techweb node that unlocks the board.
+ var/node_id
+ /// Design id of the board.
+ var/design_id
+ /// The board item, an /obj/item/circuitboard path.
+ var/board_type
+ /// The frame the board goes in.
+ var/frame_type = /obj/structure/frame/machine
+
+/// TRUE once the ship web has the board's design, or when there is no web to ask.
+/datum/vc_tutorial_step/weapon_build/proc/board_unlocked(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/techweb/web = ship?.get_research_web()
+ if(!web)
+ return TRUE
+ return web.researched_designs[design_id] || web.researched_nodes[node_id]
+
+/datum/vc_tutorial_step/weapon_build/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/structure/frame))
+ var/obj/structure/frame/frame = candidate
+ if(frame.circuit)
+ return istype(frame.circuit, board_type)
+ return tutorial_carries(user, board_type)
+ if(tutorial_carries(user, board_type))
+ return FALSE
+ var/unlocked = board_unlocked(user)
+ if(istype(candidate, /obj/machinery/computer/rdconsole))
+ return !unlocked
+ return unlocked
+
+/datum/vc_tutorial_step/weapon_build/live_line(mob/user)
+ if(!tutorial_carries(user, board_type))
+ var/research = tutorial_research_line(user, node_id, design_id)
+ if(research)
+ return research
+ return frame_line(user)
+
+/// What the nearest frame in view that holds this board (or, while the viewer carries the board,
+/// an empty one) still needs.
+/datum/vc_tutorial_step/weapon_build/proc/frame_line(mob/user)
+ var/carrying = tutorial_carries(user, board_type)
+ var/obj/structure/frame/best
+ var/best_dist = INFINITY
+ for(var/obj/structure/frame/frame in view(7, user))
+ if(!istype(frame, frame_type))
+ continue
+ if(frame.circuit ? !istype(frame.circuit, board_type) : !carrying)
+ continue
+ var/dist = get_dist(user, frame)
+ // A frame already holding the board beats an empty one.
+ if(frame.circuit)
+ dist -= 100
+ if(dist < best_dist)
+ best = frame
+ best_dist = dist
+ if(!best)
+ return null
+ if(istype(best, /obj/structure/frame/computer))
+ return tutorial_computer_frame_line(best)
+ return tutorial_machine_frame_line(best)
+
+/// One line on what a machine frame still needs.
+/proc/tutorial_machine_frame_line(obj/structure/frame/machine/frame)
+ switch(frame.state)
+ if(FRAME_STATE_EMPTY)
+ return "The frame needs 5 cables."
+ if(FRAME_STATE_WIRED)
+ return frame.anchored ? "The frame is ready for the board." : "Wrench the frame down, then add the board."
+ var/list/needs = list()
+ for(var/component in frame.req_components)
+ var/amount = frame.req_components[component]
+ if(amount)
+ needs += "[amount] [frame.req_component_names[component]]\s"
+ if(!length(needs))
+ return "The frame is ready. Screwdriver it shut."
+ return "The frame needs [english_list(needs)]."
+
+/// One line on what a computer frame still needs.
+/proc/tutorial_computer_frame_line(obj/structure/frame/computer/frame)
+ switch(frame.state)
+ if(FRAME_COMPUTER_STATE_EMPTY)
+ return frame.anchored ? "The frame is ready for the board." : "Wrench the frame down, then add the board."
+ if(FRAME_COMPUTER_STATE_BOARD_INSTALLED)
+ return "Screwdriver the board in."
+ if(FRAME_COMPUTER_STATE_BOARD_SECURED)
+ return "The frame needs 5 cables."
+ if(FRAME_COMPUTER_STATE_WIRED)
+ return "The frame needs 2 glass sheets."
+ if(FRAME_COMPUTER_STATE_GLASSED)
+ return "The frame is ready. Screwdriver it shut."
+ return null
+
+/datum/vc_tutorial_step/weapon_build/console
+ key = TUTORIAL_STEP_WEAPONS_CONSOLE
+ name = "Build a weapons console"
+ text = "Print the Weapons System board at the circuit imprinter and build it in a computer frame."
+ highlight_types = list(/obj/machinery/computer/rdconsole, /obj/machinery/rnd/production/circuit_imprinter, /obj/structure/frame/computer)
+ ui_focus = list("rdconsole" = "rd_node_ship_combat", "imprinter" = "imprinter_ship_combat_console")
+ node_id = TECHWEB_NODE_SHIP_COMBAT
+ design_id = "ship_combat_console"
+ board_type = /obj/item/circuitboard/computer/ship_combat_console
+ frame_type = /obj/structure/frame/computer
+
+/datum/vc_tutorial_step/weapon_build/launcher
+ key = TUTORIAL_STEP_WEAPONS_LAUNCHER
+ name = "Build a missile launcher"
+ text = "Print the launcher board and build it in a machine frame. Wrench it loose, then drag it onto an outer wall."
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_missiles", "imprinter" = "imprinter_ship_missile_launcher")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_MISSILES
+ design_id = "ship_missile_launcher"
+ board_type = /obj/item/circuitboard/machine/ship_combat/missile_launcher
+
+/datum/vc_tutorial_step/weapon_build/laser
+ key = TUTORIAL_STEP_WEAPONS_LASER
+ name = "Build a laser turret"
+ text = "Print the turret board and build it in a machine frame with a power cell. Wrench it loose, then drag it onto an outer wall."
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_lasers", "imprinter" = "imprinter_ship_laser_turret")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_LASERS
+ design_id = "ship_laser_turret"
+ board_type = /obj/item/circuitboard/machine/ship_combat/laser_turret
+
+/// Shields, the interdictor and EW: the reputation note, unless the crew already has the board's design.
+/datum/vc_tutorial_step/weapon_build/proc/gated_note(mob/user)
+ if(tutorial_carries(user, board_type))
+ return null
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/techweb/web = ship?.get_research_web()
+ if(web && (web.researched_designs[design_id] || web.researched_nodes[node_id]))
+ return null
+ return crew_reputation_note(user)
+
+/datum/vc_tutorial_step/weapon_build/shield
+ key = TUTORIAL_STEP_WEAPONS_SHIELD
+ name = "Build a shield generator"
+ text = "Print the shield generator board and build it in a machine frame."
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_shields", "imprinter" = "imprinter_ship_shield_generator")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_SHIELDS
+ design_id = "ship_shield_generator"
+ board_type = /obj/item/circuitboard/machine/ship_combat/shield_generator
+
+/datum/vc_tutorial_step/weapon_build/shield/availability(mob/user)
+ return gated_note(user)
+
+/datum/vc_tutorial_step/weapon_build/interdictor
+ key = TUTORIAL_STEP_WEAPONS_INTERDICTOR
+ name = "Build an interdictor"
+ text = "Print the interdictor board and build it in a machine frame."
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_interdictor", "imprinter" = "imprinter_ship_interdictor")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_INTERDICTOR
+ design_id = "ship_interdictor"
+ board_type = /obj/item/circuitboard/machine/ship_combat/interdictor
+
+/datum/vc_tutorial_step/weapon_build/interdictor/availability(mob/user)
+ return gated_note(user)
+
+/datum/vc_tutorial_step/weapon_build/ew
+ key = TUTORIAL_STEP_WEAPONS_EW
+ name = "Build an EW suite"
+ text = "Print the EW suite board and build it in a machine frame. To use it, link it to the weapons console with a multitool and load a cartridge."
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_ew", "imprinter" = "imprinter_ew_suite")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_EW
+ design_id = "ew_suite"
+ board_type = /obj/item/circuitboard/machine/ship_combat/ew_suite
+
+/datum/vc_tutorial_step/weapon_build/ew/availability(mob/user)
+ return gated_note(user)
+
+/// The missile is printed whole at the protolathe, so this step points at the protolathe and the
+/// unarmed missile frames instead of a board and a machine frame.
+/datum/vc_tutorial_step/weapon_build/missile
+ key = TUTORIAL_STEP_WEAPONS_MISSILE
+ name = "Arm a missile"
+ text = "Print a missile frame, a tracking circuit and a warhead at the protolathe. Wire the frame, add the circuit and the warhead, then screwdriver it shut."
+ highlight_types = list(/obj/machinery/computer/rdconsole, /obj/machinery/rnd/production/protolathe, /obj/structure/ship_missile)
+ ui_focus = list("rdconsole" = "rd_node_ship_combat_missiles")
+ node_id = TECHWEB_NODE_SHIP_COMBAT_MISSILES
+ design_id = "ship_missile_frame"
+
+/datum/vc_tutorial_step/weapon_build/missile/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/structure/ship_missile))
+ var/obj/structure/ship_missile/missile = candidate
+ return missile.construction_state < MISSILE_STATE_ARMED
+ var/unlocked = board_unlocked(user)
+ if(istype(candidate, /obj/machinery/computer/rdconsole))
+ return !unlocked
+ return unlocked
+
+/datum/vc_tutorial_step/weapon_build/missile/live_line(mob/user)
+ var/research = tutorial_research_line(user, node_id, design_id)
+ if(research)
+ return research
+ var/obj/structure/ship_missile/best
+ for(var/obj/structure/ship_missile/missile in view(7, user))
+ if(missile.construction_state >= MISSILE_STATE_ARMED)
+ continue
+ if(!best || get_dist(user, missile) < get_dist(user, best))
+ best = missile
+ if(!best)
+ return null
+ switch(best.construction_state)
+ if(MISSILE_STATE_UNWIRED)
+ return "The missile needs 5 cables."
+ if(MISSILE_STATE_WIRED)
+ return "The missile needs a tracking circuit."
+ if(MISSILE_STATE_TRACKING)
+ return "The missile needs a warhead."
+ if(MISSILE_STATE_PAYLOAD)
+ return "Screwdriver the missile shut."
+ return null
+
+// ---------------------------------------------------------------------------
+// Ship combat
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/combat
+ id = TUTORIAL_ITEM_COMBAT
+ name = "Ship combat"
+ category = TUTORIAL_CATEGORY_FIGHT
+ order = 3
+ intro = "Ship weapons and hacking only work in red space. The interdictor also works in yellow space and holds a ship so you can hit it or board it. All of it is run from the weapons console."
+ steps = list(
+ /datum/vc_tutorial_step/combat_missile,
+ /datum/vc_tutorial_step/combat_shields,
+ /datum/vc_tutorial_step/combat_interdict,
+ /datum/vc_tutorial_step/combat_hack,
+ /datum/vc_tutorial_step/combat_force_dock,
+ )
+
+/datum/vc_tutorial_step/combat_missile
+ key = TUTORIAL_STEP_COMBAT_MISSILE
+ name = "Launch a missile"
+ text = "Drag an armed missile onto the launcher. At the weapons console, lock onto a ship, press Engage, then Fire."
+ highlight_types = list(
+ /obj/machinery/computer/camera_advanced/ship_combat,
+ /obj/structure/ship_missile,
+ /obj/machinery/ship_combat/missile_launcher,
+ )
+ ui_focus = list("weapons" = "wpn_fire")
+
+/// Only armed missiles and empty launchers: the ones the drag still has to join.
+/datum/vc_tutorial_step/combat_missile/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/structure/ship_missile))
+ var/obj/structure/ship_missile/missile = candidate
+ return missile.construction_state == MISSILE_STATE_ARMED
+ if(istype(candidate, /obj/machinery/ship_combat/missile_launcher))
+ var/obj/machinery/ship_combat/missile_launcher/launcher = candidate
+ return !launcher.loaded_missile
+ return TRUE
+
+/datum/vc_tutorial_step/combat_missile/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/note = tutorial_weapons_zone_note(ship)
+ if(note)
+ return note
+ var/list/launchers = tutorial_combat_machines(ship, /obj/machinery/ship_combat/missile_launcher)
+ if(!length(launchers))
+ return "No missile launcher aboard."
+ for(var/obj/machinery/ship_combat/missile_launcher/launcher as anything in launchers)
+ if(launcher.loaded_missile)
+ return null
+ return "No missile loaded."
+
+/datum/vc_tutorial_step/combat_shields
+ key = TUTORIAL_STEP_COMBAT_SHIELDS
+ name = "Bring down their shields"
+ text = "Keep hitting a shielded ship with missiles or lasers until its shield fails."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/ship_combat)
+ ui_focus = list("weapons" = "wpn_fire")
+
+/datum/vc_tutorial_step/combat_shields/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/note = tutorial_weapons_zone_note(ship)
+ if(note)
+ return note
+ var/obj/structure/overmap/ship/target = tutorial_weapons_target(ship)
+ if(!target)
+ return null
+ return target.shields_active ? "Their shield is up." : "Their shield is down."
+
+/datum/vc_tutorial_step/combat_interdict
+ key = TUTORIAL_STEP_COMBAT_INTERDICT
+ name = "Interdict a ship"
+ text = "At the weapons console, lock onto a ship within two tiles and press Engage field. It slows them and stops them docking."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/ship_combat)
+ ui_focus = list("weapons" = "wpn_interdict")
+
+/datum/vc_tutorial_step/combat_interdict/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ if(!SSvc_tutorials.ship_has_machine(ship, /obj/machinery/ship_combat/interdictor))
+ return "No interdictor aboard."
+ if(!SSovermap_zones.interdiction_allowed_at(ship))
+ return "Interdiction is blocked in green space."
+ return null
+
+/datum/vc_tutorial_step/combat_hack
+ key = TUTORIAL_STEP_COMBAT_HACK
+ name = "Hack a ship"
+ text = "Lock onto a ship at the weapons console, open Exploits and run a cartridge."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/ship_combat)
+ ui_focus = list("weapons" = "wpn_hack")
+
+/datum/vc_tutorial_step/combat_hack/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/note = tutorial_weapons_zone_note(ship)
+ if(note)
+ return note
+ if(!length(tutorial_combat_machines(ship, /obj/machinery/ship_combat/ew_suite)))
+ return "No EW suite aboard."
+ var/linked = FALSE
+ for(var/obj/machinery/computer/camera_advanced/ship_combat/console as anything in tutorial_combat_machines(ship, /obj/machinery/computer/camera_advanced/ship_combat))
+ var/obj/machinery/ship_combat/ew_suite/suite = console.linked_ew_ref?.resolve()
+ if(!suite)
+ continue
+ linked = TRUE
+ if(length(suite.loaded_chips))
+ return null
+ return linked ? "No cartridges loaded." : "The EW suite isn't linked to a console."
+
+/datum/vc_tutorial_step/combat_force_dock
+ key = TUTORIAL_STEP_COMBAT_FORCE_DOCK
+ name = "Force-dock a ship"
+ text = "Fly onto the ship you're holding, stop, and press Dock at the helm."
+ optional = TRUE
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_dock")
+
+/datum/vc_tutorial_step/combat_force_dock/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship)
+ return null
+ var/obj/structure/overmap/ship/held = tutorial_interdicted_ship(ship)
+ if(!held)
+ return "Not holding a ship."
+ if(get_turf(held) != get_turf(ship))
+ return "Get onto their tile."
+ if(!ship.is_still())
+ return "Stop your ship."
+ if(!held.is_still())
+ return "They're still moving."
+ return null
+
+// ---------------------------------------------------------------------------
+// Hunting pirates
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/pirates
+ id = TUTORIAL_ITEM_PIRATES
+ name = "Hunting pirates"
+ category = TUTORIAL_CATEGORY_FIGHT
+ order = 4
+ intro = "Pirate ships hunt crews in red space. You can let them board and then take the fight to their ship, or shoot their ship down from yours. In yellow space they only board a crew that's broke."
+ steps = list(
+ /datum/vc_tutorial_step/pirates_hail,
+ /datum/vc_tutorial_step/pirates_boarders,
+ /datum/vc_tutorial_step/pirates_commander,
+ /datum/vc_tutorial_step/pirates_board,
+ /datum/vc_tutorial_step/pirates_shoot,
+ /datum/vc_tutorial_step/pirates_bounty,
+ /datum/vc_tutorial_step/pirates_claim,
+ )
+
+/datum/vc_tutorial_step/pirates_hail
+ key = TUTORIAL_STEP_PIRATES_HAIL
+ name = "Answer a hail"
+ text = "A pirate hail rings your holopads. Answer it to pay them off. Refuse or ignore it and they board."
+ optional = TRUE
+ highlight_types = list(/obj/machinery/holopad)
+
+/// Only pads that are ringing.
+/datum/vc_tutorial_step/pirates_hail/highlight_filter(mob/user, atom/candidate)
+ var/obj/machinery/holopad/pad = candidate
+ return !istype(pad) || pad.incoming_hail
+
+/datum/vc_tutorial_step/pirates_boarders
+ key = TUTORIAL_STEP_PIRATES_BOARDERS
+ name = "Hold off the boarders"
+ text = "They board in one wave sized to your crew. Kill or cuff every one of them."
+ route = "board"
+ route_name = "Let them board"
+
+/datum/vc_tutorial_step/pirates_boarders/live_line(mob/user)
+ var/datum/ai_controller/npc_ship/controller = tutorial_engaging_pirate_controller(get_crew_ship(user))
+ if(controller?.get_combat_state() == NPC_COMBAT_BOARDING)
+ return "Boarders aboard."
+ return null
+
+/datum/vc_tutorial_step/pirates_commander
+ key = TUTORIAL_STEP_PIRATES_COMMANDER
+ name = "Beat their commander"
+ text = "In red space their commander pods in after the wave. Kill them, put them down or cuff them."
+ route = "board"
+ route_name = "Let them board"
+
+/datum/vc_tutorial_step/pirates_commander/live_line(mob/user)
+ var/zone_type = tutorial_ship_zone_type(get_crew_ship(user))
+ if(zone_type && zone_type != ZONE_RED)
+ return "You're not in red space."
+ return null
+
+/datum/vc_tutorial_step/pirates_board
+ key = TUTORIAL_STEP_PIRATES_BOARD
+ name = "Board their ship"
+ text = "Once their commander is down, or while you're holding their ship, fly onto it, stop, and press Dock at the helm."
+ route = "board"
+ route_name = "Let them board"
+ highlight_types = list(/obj/machinery/computer/helm)
+
+/// The helm only once a pirate ship nearby will take the dock.
+/datum/vc_tutorial_step/pirates_board/highlight_filter(mob/user, atom/candidate)
+ return !!tutorial_boardable_pirate(get_crew_ship(user))
+
+/datum/vc_tutorial_step/pirates_board/live_line(mob/user)
+ var/obj/structure/overmap/ship/npc/pirate = tutorial_boardable_pirate(get_crew_ship(user))
+ if(pirate?.is_disabled)
+ return "Their ship is disabled."
+ return null
+
+/datum/vc_tutorial_step/pirates_shoot
+ key = TUTORIAL_STEP_PIRATES_SHOOT
+ name = "Shoot them down"
+ text = "Hit their hull with missiles and lasers until it fails."
+ route = "shoot"
+ route_name = "Fight ship to ship"
+ highlight_types = list(/obj/machinery/computer/camera_advanced/ship_combat)
+ ui_focus = list("weapons" = "wpn_fire")
+
+/// A wreck can't be turned in, so a crew on a bounty sees whose key it's after.
+/datum/vc_tutorial_step/pirates_shoot/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship || !SSbounty)
+ return null
+ for(var/datum/pirate_bounty/bounty as anything in SSbounty.get_bounties_for_claimant(ship))
+ return "Hunting [bounty.name]'s key."
+ return null
+
+/datum/vc_tutorial_step/pirates_bounty
+ key = TUTORIAL_STEP_PIRATES_BOUNTY
+ name = "Turn in a bounty"
+ text = "Take a pirate bounty at the mission board. Bring back their captain's key, put it on the mission pad and turn it in."
+ optional = TRUE
+ highlight_types = list(
+ /obj/item/ship_key,
+ /obj/machinery/computer/mission_board,
+ /obj/machinery/mission_pad,
+ )
+ ui_focus = list("board" = "board_bounty")
+
+/// Keys anywhere; the board and pad only while the crew is hunting a bounty.
+/datum/vc_tutorial_step/pirates_bounty/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/item/ship_key))
+ return TRUE
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && SSbounty?.ship_has_active_bounty(ship)
+
+/datum/vc_tutorial_step/pirates_claim
+ key = TUTORIAL_STEP_PIRATES_CLAIM
+ name = "Claim the hull"
+ text = "Take their captain's key and use it on their helm. A downed or cuffed captain keeps it in a pocket."
+ optional = TRUE
+ highlight_types = list(/obj/item/ship_key, /obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_claim")
+
+/// Keys anywhere, but only the helms of pirate ships.
+/datum/vc_tutorial_step/pirates_claim/highlight_filter(mob/user, atom/candidate)
+ if(istype(candidate, /obj/machinery/computer/helm))
+ var/obj/structure/overmap/ship/npc/npc_ship = get_ship_from_atom(candidate)
+ return istype(npc_ship) && (!npc_ship.player_controlled || npc_ship.abandoned)
+ return TRUE
+
+/// A downed or cuffed NPC in view with a key in a pocket.
+/datum/vc_tutorial_step/pirates_claim/extra_targets(mob/user)
+ return tutorial_key_carriers(user)
+
+// ---------------------------------------------------------------------------
+// Storage
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/storage
+ id = TUTORIAL_ITEM_STORAGE
+ name = "Storage"
+ category = TUTORIAL_CATEGORY_START
+ order = 4
+ intro = "Loose items get lost fast on a ship. Cargo shelves stack crates out of the way, and smart lockers keep items sorted for the whole crew."
+ steps = list(
+ /datum/vc_tutorial_step/storage_shelf,
+ /datum/vc_tutorial_step/storage_crate,
+ /datum/vc_tutorial_step/storage_locker,
+ /datum/vc_tutorial_step/storage_store,
+ )
+
+/datum/vc_tutorial_step/storage_shelf
+ key = TUTORIAL_STEP_STORAGE_SHELF
+ name = "Build a cargo shelf"
+ text = "Use four iron sheets in hand and make cargo shelf parts. Stand on a clear tile and use the parts to build it there."
+ highlight_types = list(/obj/item/stack/sheet/iron, /obj/item/rack_parts/cargo_shelf)
+
+/// Loose shelf parts, or an iron stack big enough for them (the recipe takes four sheets).
+/datum/vc_tutorial_step/storage_shelf/highlight_filter(mob/user, atom/candidate)
+ var/obj/item/stack/sheet/iron/sheets = candidate
+ return !istype(sheets) || sheets.amount >= 4
+
+/datum/vc_tutorial_step/storage_crate
+ key = TUTORIAL_STEP_STORAGE_CRATE
+ name = "Shelve a crate"
+ text = "Push a crate next to a cargo shelf, then drag the crate onto the shelf."
+ highlight_types = list(/obj/structure/cargo_shelf, /obj/structure/closet/crate)
+
+/// Shelves with room left, and crates loose on the floor.
+/datum/vc_tutorial_step/storage_crate/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/cargo_shelf/shelf = candidate
+ if(istype(shelf))
+ return !!shelf.shelf_contents?.Find(null)
+ var/obj/structure/closet/crate/crate = candidate
+ return istype(crate) && !crate.anchored && isturf(crate.loc)
+
+/datum/vc_tutorial_step/storage_locker
+ key = TUTORIAL_STEP_STORAGE_LOCKER
+ name = "Build a smart locker"
+ text = "Research Food Processing, then print a Smart Locker board at the circuit imprinter. Build it in a machine frame with a matter bin and five cable."
+ highlight_types = list(/obj/machinery/rnd/production/circuit_imprinter, /obj/structure/frame/machine)
+ ui_focus = list("rdconsole" = "rd_node_food_proc", "imprinter" = "imprinter_smartlocker")
+
+/// Only frames that hold a smart locker board.
+/datum/vc_tutorial_step/storage_locker/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/frame/machine/frame = candidate
+ return !istype(frame) || istype(frame.circuit, /obj/item/circuitboard/machine/smartfridge/storage)
+
+/datum/vc_tutorial_step/storage_locker/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/techweb/web = ship?.get_research_web()
+ if(web && !web.researched_designs["smartlocker"])
+ return "Research Food Processing first."
+ if(ship && !SSvc_tutorials.ship_has_machine(ship, /obj/machinery/rnd/production/circuit_imprinter))
+ return "No circuit imprinter aboard."
+ return null
+
+/datum/vc_tutorial_step/storage_store
+ key = TUTORIAL_STEP_STORAGE_STORE
+ name = "Fill a smart locker"
+ text = "Put an item in a smart locker, or drag a bag onto it to empty the bag."
+ highlight_types = list(/obj/machinery/smartfridge/storage)
+
+// ---------------------------------------------------------------------------
+// Repair drones
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/repair_drones
+ id = TUTORIAL_ITEM_REPAIR_DRONES
+ name = "Repair drones"
+ category = TUTORIAL_CATEGORY_KEEP
+ order = 1
+ intro = "Repair drones fix hull damage while you fly. They rebuild it with ore from your ship's silo."
+ steps = list(
+ /datum/vc_tutorial_step/repair_drones_research,
+ /datum/vc_tutorial_step/repair_drones_assemble,
+ /datum/vc_tutorial_step/repair_drones_link,
+ /datum/vc_tutorial_step/repair_drones_repair,
+ )
+
+/datum/vc_tutorial_step/repair_drones_research
+ key = TUTORIAL_STEP_REPAIR_DRONES_RESEARCH
+ name = "Research Shuttle Repair Swarm"
+ text = "At the R&D console, after Shuttle Construction Automation. It needs some crew reputation."
+ highlight_types = list(/obj/machinery/computer/rdconsole)
+ ui_focus = list("rdconsole" = "rd_node_ship_repair_swarm")
+
+/datum/vc_tutorial_step/repair_drones_research/state_satisfied(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ var/datum/techweb/web = ship?.get_research_web()
+ return web && (TECHWEB_NODE_SHIP_REPAIR_SWARM in web.researched_nodes)
+
+/datum/vc_tutorial_step/repair_drones_research/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return tutorial_repair_research_line(ship?.get_research_web(), TECHWEB_NODE_SHIP_REPAIR_SWARM)
+
+/datum/vc_tutorial_step/repair_drones_assemble
+ key = TUTORIAL_STEP_REPAIR_DRONES_ASSEMBLE
+ name = "Assemble a drone"
+ text = "Print the chassis and its three parts at an exosuit fabricator. Fit the parts to the chassis with a wrench, five cable and a screwdriver."
+ highlight_types = list(/obj/machinery/mecha_part_fabricator, /obj/item/ship_repair_drone_part/chassis)
+
+/// The next assembly step of the nearest chassis in reach.
+/datum/vc_tutorial_step/repair_drones_assemble/live_line(mob/user)
+ return tutorial_repair_chassis_line(user)
+
+/datum/vc_tutorial_step/repair_drones_link
+ key = TUTORIAL_STEP_REPAIR_DRONES_LINK
+ name = "Link the drone"
+ text = "Print the Repair Swarm upgrade disk at a protolathe and use it on the construction console. Then use a multitool on the console, then on the drone aboard."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/base_construction/ship, /obj/structure/ship_repair_drone)
+
+/// The crew's own console, and drones nobody has linked yet.
+/datum/vc_tutorial_step/repair_drones_link/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/ship_repair_drone/drone = candidate
+ if(istype(drone))
+ return !drone.console
+ return tutorial_repair_is_crew_console(user, candidate)
+
+/datum/vc_tutorial_step/repair_drones_link/live_line(mob/user)
+ var/obj/machinery/computer/camera_advanced/base_construction/ship/console = tutorial_repair_console(get_crew_ship(user))
+ if(console && !(console.console_upgrades & SHIP_CONSTRUCTION_UPGRADE_REPAIR))
+ return "No repair disk in the construction console."
+ return null
+
+/datum/vc_tutorial_step/repair_drones_repair
+ key = TUTORIAL_STEP_REPAIR_DRONES_REPAIR
+ name = "Watch it repair"
+ text = "In the construction console's Repair Drones tab, press Deploy swarm. Then take hull damage while flying."
+ highlight_types = list(/obj/machinery/computer/camera_advanced/base_construction/ship, /obj/structure/ship_repair_drone)
+ ui_focus = list("construction" = "construct_deploy_swarm")
+
+/// The console while the swarm is paused, the crew's linked drones once it is out.
+/datum/vc_tutorial_step/repair_drones_repair/highlight_filter(mob/user, atom/candidate)
+ var/obj/structure/ship_repair_drone/drone = candidate
+ if(istype(drone))
+ return drone.console && drone.console.repair_enabled && drone.console.current_ship == get_crew_ship(user)
+ if(!tutorial_repair_is_crew_console(user, candidate))
+ return FALSE
+ var/obj/machinery/computer/camera_advanced/base_construction/ship/console = candidate
+ return !console.repair_enabled
+
+/datum/vc_tutorial_step/repair_drones_repair/live_line(mob/user)
+ return tutorial_repair_swarm_line(tutorial_repair_console(get_crew_ship(user)))
+
+// ---------------------------------------------------------------------------
+// Save your ship
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/ship_save
+ id = TUTORIAL_ITEM_SHIP_SAVE
+ name = "Save your ship"
+ category = TUTORIAL_CATEGORY_KEEP
+ order = 2
+ intro = "A saved ship can be loaded again in a later round. Saving happens at a crew outpost with ship bays."
+ steps = list(
+ /datum/vc_tutorial_step/ship_save_dock,
+ /datum/vc_tutorial_step/ship_save_save,
+ /datum/vc_tutorial_step/ship_save_load,
+ )
+
+/datum/vc_tutorial_step/ship_save_dock
+ key = TUTORIAL_STEP_SHIP_SAVE_DOCK
+ name = "Dock in a ship bay"
+ text = "Fly to a crew outpost with ship bays. On the helm, pick Dock at ship bay, not the plain outpost entry."
+ highlight_types = list(/obj/machinery/computer/helm)
+ ui_focus = list("helm" = "helm_dock_bay")
+
+/datum/vc_tutorial_step/ship_save_dock/live_line(mob/user)
+ var/list/names = tutorial_save_bay_outposts()
+ if(!length(names))
+ return "No outpost has ship bays right now."
+ return "Ship bays: [jointext(names, ", ")]."
+
+/// Only the captain can save or load a ship.
+/datum/vc_tutorial_step/proc/captain_only_note(mob/user)
+ if(excused(user))
+ return "Captain only."
+ return null
+
+/datum/vc_tutorial_step/ship_save_save
+ key = TUTORIAL_STEP_SHIP_SAVE_SAVE
+ name = "Save the ship"
+ text = "Take the bay elevator to the shipyard console and save your ship to a slot."
+ highlight_types = list(/obj/machinery/computer/ship_checkpoint)
+
+/datum/vc_tutorial_step/ship_save_save/availability(mob/user)
+ return captain_only_note(user)
+
+/datum/vc_tutorial_step/ship_save_save/excused(mob/user)
+ if(..())
+ return TRUE
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ return ship && !ship.is_ship_captain(user)
+
+/datum/vc_tutorial_step/ship_save_save/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_crew_ship(user)
+ if(!ship?.is_ship_captain(user))
+ return null
+ if(!tutorial_save_bay_of(ship))
+ return "Your ship isn't in a ship bay."
+ if(!length(ship.shuttle?.spawn_points))
+ return "This hull has no cryopods."
+ return null
+
+/// The shipyard console in the bay the crew's ship sits in, so the arrow can lead the captain there.
+/datum/vc_tutorial_step/ship_save_save/extra_targets(mob/user)
+ return tutorial_save_bay_consoles(tutorial_save_bay_of(get_crew_ship(user)))
+
+/datum/vc_tutorial_step/ship_save_load
+ key = TUTORIAL_STEP_SHIP_SAVE_LOAD
+ name = "Load a saved ship"
+ text = "Pick a saved ship when you join, or build it at a shipyard console once the old hull is gone."
+ optional = TRUE
+ highlight_types = list(/obj/machinery/computer/ship_checkpoint)
+
+// ---------------------------------------------------------------------------
+// Vestige pact
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial/vestige
+ id = TUTORIAL_ITEM_VESTIGE
+ name = "Vestige pact"
+ category = TUTORIAL_CATEGORY_FIGHT
+ order = 10
+ intro = "Vestiges are strange places that show up during the round. The patron inside sets you one trial, and finishing it earns a boon."
+ steps = list(
+ /datum/vc_tutorial_step/vestige_find,
+ /datum/vc_tutorial_step/vestige_pact,
+ /datum/vc_tutorial_step/vestige_trial,
+ /datum/vc_tutorial_step/vestige_claim,
+ )
+
+/datum/vc_tutorial_step/vestige_find
+ key = TUTORIAL_STEP_VESTIGE_FIND
+ name = "Find a vestige"
+ text = "Vestiges surface during the round. The helm lists each one under its patron's name. Fly to one and go inside."
+
+/datum/vc_tutorial_step/vestige_find/live_line(mob/user)
+ var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
+ var/surfaced = FALSE
+ for(var/obj/structure/overmap/space_ruin/vestige/signal in GLOB.space_ruin_signals)
+ if(QDELETED(signal))
+ continue
+ surfaced = TRUE
+ if(ship?.discovered_contacts?[REF(signal)])
+ return "Your helm has charted [signal]."
+ if(!surfaced)
+ return "None have surfaced yet."
+ return ship ? "One has surfaced. Your helm hasn't found it yet." : "One has surfaced."
+
+/datum/vc_tutorial_step/vestige_pact
+ key = TUTORIAL_STEP_VESTIGE_PACT
+ name = "Make a pact"
+ text = "Click the patron inside with an empty hand and choose Pact. It sets you one trial."
+ highlight_types = list(/mob/living/basic/vestige_patron)
+
+/// Patrons in the vestige the viewer is in, so the arrow finds one behind walls. They never move.
+/datum/vc_tutorial_step/vestige_pact/extra_targets(mob/user)
+ return tutorial_nearby_patrons(user)
+
+/datum/vc_tutorial_step/vestige_pact/live_line(mob/user)
+ var/datum/mind/mind = user.mind
+ var/datum/action/vestige_reward/pending = mind?.vestige_pending_reward
+ if(pending)
+ return "A patron still owes you a boon."
+ var/datum/vestige_trial/active = mind?.active_vestige_trial
+ if(active)
+ return "You already have a pact with [active.patron_name]."
+ return null
+
+/datum/vc_tutorial_step/vestige_trial
+ key = TUTORIAL_STEP_VESTIGE_TRIAL
+ name = "Complete the trial"
+ text = "Do what the patron asked. Click the pact button on your screen to read the terms again."
+
+/datum/vc_tutorial_step/vestige_trial/live_line(mob/user)
+ var/datum/vestige_trial/active = user.mind?.active_vestige_trial
+ if(!active)
+ return null
+ return "[active.name]: [active.get_progress_text()]"
+
+/datum/vc_tutorial_step/vestige_claim
+ key = TUTORIAL_STEP_VESTIGE_CLAIM
+ name = "Claim your boon"
+ text = "Use the Claim Your Boon button and pick one."
+
+/datum/vc_tutorial_step/vestige_claim/live_line(mob/user)
+ var/datum/vestige_record/record = get_vestige_record(user.mind)
+ if(!user.mind?.vestige_pending_reward)
+ return null
+ return record?.pending_patron_name ? "[record.pending_patron_name] owes you a boon." : "A boon is waiting for you."
diff --git a/voidcrew/modules/tutorials/tutorial_highlights.dm b/voidcrew/modules/tutorials/tutorial_highlights.dm
new file mode 100644
index 00000000000..5f2ad8e0101
--- /dev/null
+++ b/voidcrew/modules/tutorials/tutorial_highlights.dm
@@ -0,0 +1,659 @@
+/**
+ * # Tutorial highlights
+ *
+ * Points one viewer at what their open tutorial item needs next: gold outlines on things
+ * nearby, an arrow at the screen edge toward a target off screen, and a pulsing outline on
+ * the right button in windows that opt in (tutorial_ui_focus()).
+ *
+ * ## Which step is pointed at (the guide step)
+ * The open item is the one selected in the panel (SSvc_tutorials.selected), else the
+ * panel's suggested item. Its guide step is the first step, in panel order, that is
+ * undone, not excused, and has something to point at for this viewer:
+ * 1. a highlight candidate (highlight_types match or extra_targets() entry, kept by
+ * highlight_filter()) on their z-level, or
+ * 2. a ui_focus entry, or
+ * 3. a non-null arrow_target().
+ * If no step has any of these, the guide step is the first undone, non-excused step.
+ * Outlines, the arrow and window focus all follow the guide step, never a different one.
+ *
+ * ## Rendering
+ * Outlines: one client /image per outlined atom, attached to the atom (loc = target). Objects
+ * and mobs get a copy of their appearance with an outline and glow filter, a hair BELOW the
+ * target's layer on its own plane, so the real sprite covers the copy and only the gold ring
+ * shows. Turfs get a gold square frame just above the floor. Images go only into the
+ * viewer's client.images, so nobody else sees them. They are hidden by walls like the target.
+ *
+ * Arrow: one /atom/movable/screen/tutorial_arrow per viewer in their client.screen, placed one
+ * tile in from the edge of their view (client.view, so widescreen works) on the line toward
+ * the target and turned to face it. Hidden while the target is on screen or there is none.
+ *
+ * ## Cost
+ * Nothing runs per tick. A rebuild (step choice, scans, arrow target) happens on a refresh
+ * trigger (panel open/close/select, a credit, a pref toggle, the panel's 5 s live refresh) or
+ * when the viewer walks a few tiles or changes z-level, at most once per
+ * TUTORIAL_HIGHLIGHT_MOVE_COOLDOWN. Between rebuilds each step the viewer takes only moves the
+ * arrow (math, no scan). Ship-wide scans are cached per ship and step.
+ */
+
+/// Most atoms outlined at once.
+#define TUTORIAL_HIGHLIGHT_CAP 3
+/// Radius of the in-view search.
+#define TUTORIAL_HIGHLIGHT_VIEW_RANGE 9
+/// How far a candidate may be and still be outlined.
+#define TUTORIAL_HIGHLIGHT_SHIP_RANGE 24
+/// How far the default off-screen arrow will point.
+#define TUTORIAL_ARROW_RANGE 60
+/// Shortest gap between two movement-driven rebuilds.
+#define TUTORIAL_HIGHLIGHT_MOVE_COOLDOWN (2 SECONDS)
+/// Tiles walked before a movement-driven rebuild is considered.
+#define TUTORIAL_HIGHLIGHT_MOVE_TILES 3
+/// How long a ship-wide scan for one step stays cached.
+#define TUTORIAL_HIGHLIGHT_SHIP_CACHE (10 SECONDS)
+/// The outline colour the owner approved.
+#define TUTORIAL_HIGHLIGHT_COLOR "#FFC83C"
+/// The dim end of the outline pulse.
+#define TUTORIAL_HIGHLIGHT_COLOR_DIM "#8A5A10"
+
+/// ckey -> /datum/tutorial_highlight for every viewer that currently has one.
+GLOBAL_LIST_EMPTY(tutorial_highlighters)
+
+/**
+ * Rebuilds the viewer's tutorial highlights and arrow. Called when the panel opens or closes,
+ * when the viewer selects an item, when the highlight preference changes, and when a step is
+ * credited to them. Cheap and safe for any mob, including ghosts and mobs with no client.
+ */
+/proc/tutorial_refresh_highlights(mob/user)
+ if(!user)
+ return
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey)
+ return
+ var/datum/tutorial_highlight/highlight = GLOB.tutorial_highlighters[ckey]
+ if(!highlight)
+ // Only a real client gets one here; unit tests make theirs directly.
+ if(!user.client || !tutorial_highlights_wanted(user))
+ return
+ highlight = new(user)
+ highlight.rebuild(user)
+
+/**
+ * Forces a full refresh for one viewer: outlines, arrow, window focus and the open panel.
+ * Call it after a state change that a live_line() or highlight_filter() reads, when no
+ * credit follows to do it for you.
+ */
+/proc/tutorial_refresh(mob/user)
+ if(!user)
+ return
+ tutorial_refresh_highlights(user)
+ SStgui.try_update_ui(user, GLOB.tutorial_checklist)
+
+/// TRUE when this viewer wants outlines: alive and in a body, the preference on, and the
+/// checklist not put away (closed this round, or its spawn window turned off) unless it's open.
+/proc/tutorial_highlights_wanted(mob/user)
+ var/datum/preferences/prefs = user?.client?.prefs
+ if(!prefs || isobserver(user) || user.stat == DEAD)
+ return FALSE
+ if(!prefs.read_preference(/datum/preference/toggle/tutorial_highlights))
+ return FALSE
+ if(SStgui.get_open_ui(user, GLOB.tutorial_checklist))
+ return TRUE
+ if(tutorial_viewer_ckey(user) in GLOB.tutorial_checklist_hidden)
+ return FALSE
+ return !!prefs.read_preference(/datum/preference/toggle/tutorial_checklist)
+
+/// The viewer's open item: the one selected in the panel, else the suggested one. Null if none.
+/proc/tutorial_open_item(mob/user)
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey)
+ return null
+ SSvc_tutorials.build_catalog()
+ var/item_id = SSvc_tutorials.selected[ckey] || SSvc_tutorials.suggested_item(ckey, user)
+ if(!item_id)
+ return null
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ if(item.id == item_id)
+ return item
+ return null
+
+/// The viewer's guide step (see the file header), or null.
+/proc/tutorial_highlight_step(mob/user)
+ return tutorial_pick_guide_step(user, tutorial_open_item(user))
+
+/// The guide step of one item for this viewer (see the file header), or null.
+/proc/tutorial_pick_guide_step(mob/user, datum/vc_tutorial/item)
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey || !item)
+ return null
+ var/list/done = SSvc_tutorials.progress[ckey]
+ var/datum/vc_tutorial_step/first
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ if(done?[step.key] || step.excused(user))
+ continue
+ first ||= step
+ if(length(tutorial_step_candidates(user, step)) || length(step.ui_focus) || step.arrow_target(user))
+ return step
+ return first
+
+/**
+ * The focus key for one window, or null. A window sends it from ui_data as "tutorial_focus"
+ * and wraps its buttons in . It reads the viewer's last guide step, so
+ * it is a few list lookups and safe in ui_data. Null unless the viewer has the checklist on
+ * and the highlight preference on (only then do they have a highlighter).
+ */
+/proc/tutorial_ui_focus(mob/user, window_id)
+ if(!user || !window_id)
+ return null
+ var/datum/tutorial_highlight/highlight = GLOB.tutorial_highlighters[tutorial_viewer_ckey(user)]
+ if(!highlight || highlight.viewer != user || !highlight.step_key)
+ return null
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key?[highlight.step_key]
+ return step?.ui_focus?[window_id]
+
+/**
+ * Every highlight candidate for one step and viewer, unsorted: highlight_types matches in
+ * view, object and turf matches aboard their ship, plus extra_targets(), all on the viewer's
+ * z-level and kept by highlight_filter(). Held items and anything inside something else are
+ * skipped. The viewer is never a candidate. Memoised per step while a rebuild runs.
+ */
+/proc/tutorial_step_candidates(mob/user, datum/vc_tutorial_step/step)
+ var/turf/center = get_turf(user)
+ if(!center || !step)
+ return list()
+ var/datum/tutorial_highlight/highlight = GLOB.tutorial_highlighters[tutorial_viewer_ckey(user)]
+ if(highlight?.viewer != user)
+ highlight = null
+ var/list/memo = highlight?.candidate_memo
+ if(memo && memo[step.key])
+ return memo[step.key]
+ var/list/found = list()
+ var/list/types = step.highlight_types
+ if(length(types))
+ var/wants_turfs = FALSE
+ for(var/type in types)
+ if(ispath(type, /turf))
+ wants_turfs = TRUE
+ break
+ var/list/seen = memo ? highlight.view_memo : null
+ if(!seen)
+ seen = view(TUTORIAL_HIGHLIGHT_VIEW_RANGE, user)
+ if(memo)
+ highlight.view_memo = seen
+ for(var/atom/thing in seen)
+ if(thing == user || isarea(thing))
+ continue
+ if(isturf(thing))
+ if(!wants_turfs)
+ continue
+ else if(!isturf(thing.loc))
+ continue
+ if(is_type_in_list(thing, types))
+ found[thing] = TRUE
+ var/obj/structure/overmap/ship/ship = get_ship_from_atom(user)
+ if(ship)
+ for(var/atom/thing as anything in tutorial_ship_candidates(ship, step, highlight, wants_turfs))
+ if(thing != user && thing.z == center.z)
+ found[thing] = TRUE
+ for(var/atom/extra as anything in step.extra_targets(user))
+ if(QDELETED(extra) || extra == user)
+ continue
+ var/turf/extra_turf = get_turf(extra)
+ if(extra_turf?.z == center.z)
+ found[extra] = TRUE
+ var/list/result = list()
+ for(var/atom/thing as anything in found)
+ if(step.highlight_filter(user, thing))
+ result += thing
+ if(memo)
+ memo[step.key] = result
+ return result
+
+/// highlight_types object and turf matches aboard a ship (mobs come only from view(), so
+/// nobody is tracked through walls). Cached on the highlighter (if given) per ship and step,
+/// because it walks every ship area.
+/proc/tutorial_ship_candidates(obj/structure/overmap/ship/ship, datum/vc_tutorial_step/step, datum/tutorial_highlight/highlight, wants_turfs)
+ var/list/result = list()
+ if(highlight)
+ var/ship_ref = REF(ship)
+ if(highlight.ship_cache_ship != ship_ref)
+ highlight.ship_cache = list()
+ highlight.ship_cache_ship = ship_ref
+ var/list/cached = highlight.ship_cache[step.key]
+ if(cached && world.time < cached[1] + TUTORIAL_HIGHLIGHT_SHIP_CACHE)
+ for(var/datum/weakref/ref as anything in cached[2])
+ var/atom/thing = ref.resolve()
+ if(thing && (isturf(thing) || isturf(thing.loc)))
+ result += thing
+ return result
+ if(!ship.shuttle?.shuttle_areas)
+ return result
+ var/list/types = step.highlight_types
+ var/list/refs = list()
+ for(var/area/ship_area as anything in ship.shuttle.shuttle_areas)
+ // Objects only: a ship-wide mob match would track people through walls.
+ for(var/obj/thing in ship_area)
+ if(isturf(thing.loc) && is_type_in_list(thing, types))
+ result += thing
+ refs += WEAKREF(thing)
+ if(!wants_turfs)
+ continue
+ for(var/turf/floor in ship_area)
+ if(is_type_in_list(floor, types))
+ result += floor
+ refs += WEAKREF(floor)
+ if(highlight)
+ highlight.ship_cache[step.key] = list(world.time, refs)
+ return result
+
+/**
+ * The default arrow target: null while any candidate is on the viewer's screen, else the
+ * nearest candidate on their z-level within TUTORIAL_ARROW_RANGE tiles.
+ */
+/proc/tutorial_default_arrow_target(mob/user, list/candidates)
+ var/turf/center = tutorial_screen_center(user)
+ if(!center || !length(candidates))
+ return null
+ var/list/view_size = getviewsize(user.client ? user.client.view : world.view)
+ var/atom/nearest
+ var/nearest_dist
+ for(var/atom/thing as anything in candidates)
+ var/turf/spot = get_turf(thing)
+ if(!spot || spot.z != center.z)
+ continue
+ if(tutorial_on_screen(center, spot, view_size))
+ return null
+ var/dist = get_dist(center, spot)
+ if(dist > TUTORIAL_ARROW_RANGE)
+ continue
+ if(!nearest || dist < nearest_dist)
+ nearest = thing
+ nearest_dist = dist
+ return nearest
+
+/// The turf the viewer's screen is centred on.
+/proc/tutorial_screen_center(mob/user)
+ return get_turf(user?.client?.eye || user)
+
+/// TRUE when spot is inside the screen centred on center, for a getviewsize() list.
+/proc/tutorial_on_screen(turf/center, turf/spot, list/view_size)
+ if(!center || !spot || center.z != spot.z)
+ return FALSE
+ return abs(spot.x - center.x) <= (view_size[1] - 1) / 2 && abs(spot.y - center.y) <= (view_size[2] - 1) / 2
+
+/**
+ * One viewer's outlines and arrow. Lives in GLOB.tutorial_highlighters under the viewer's
+ * ckey until logout, death, ghosting, or the viewer no longer wanting outlines.
+ */
+/datum/tutorial_highlight
+ /// The ckey this belongs to.
+ var/ckey
+ /// The body we're watching. Cleared when it logs out, dies, ghosts or is deleted.
+ var/mob/viewer
+ /// The client the images and arrow were pushed to, kept so they can be taken back off it.
+ var/client/shown_client
+ /// target atom -> its /image
+ var/list/images = list()
+ /// When non-null, used instead of tutorial_highlights_wanted(). Unit tests set it.
+ var/wanted_override
+ /// world.time of the last movement-driven rebuild.
+ var/last_move_rebuild = 0
+ /// Turf of the last rebuild, for the "walked a few tiles" check.
+ var/turf/last_turf
+ /// Key of the current guide step, or null. tutorial_ui_focus() reads it.
+ var/step_key
+ /// REF() of the ship the cache below is for.
+ var/ship_cache_ship
+ /// step key -> list(world.time, list of weakrefs) of ship-wide scan results.
+ var/list/ship_cache = list()
+ /// step key -> candidate list, only while a rebuild runs (so no hard refs outlive it).
+ var/list/candidate_memo
+ /// The viewer's view() list, only while a rebuild runs.
+ var/list/view_memo
+ /// The off-screen arrow, made on first use.
+ var/atom/movable/screen/tutorial_arrow/arrow
+ /// What the arrow points at.
+ var/datum/weakref/arrow_target_ref
+
+/datum/tutorial_highlight/New(mob/user)
+ . = ..()
+ ckey = tutorial_viewer_ckey(user)
+ GLOB.tutorial_highlighters[ckey] = src
+ watch(user)
+
+/datum/tutorial_highlight/Destroy()
+ clear_images()
+ hide_arrow()
+ QDEL_NULL(arrow)
+ arrow_target_ref = null
+ unwatch()
+ shown_client = null
+ last_turf = null
+ candidate_memo = null
+ view_memo = null
+ if(GLOB.tutorial_highlighters[ckey] == src)
+ GLOB.tutorial_highlighters -= ckey
+ ship_cache = null
+ return ..()
+
+/// Starts listening to a body for the events that move or end the outlines.
+/datum/tutorial_highlight/proc/watch(mob/user)
+ if(viewer == user)
+ return
+ unwatch()
+ viewer = user
+ RegisterSignals(user, list(COMSIG_MOB_LOGOUT, COMSIG_QDELETING, COMSIG_LIVING_DEATH, COMSIG_MOB_GHOSTIZED), PROC_REF(on_viewer_gone))
+
+/datum/tutorial_highlight/proc/unwatch()
+ if(!viewer)
+ return
+ UnregisterSignal(viewer, list(COMSIG_MOB_LOGOUT, COMSIG_QDELETING, COMSIG_LIVING_DEATH, COMSIG_MOB_GHOSTIZED, COMSIG_MOVABLE_MOVED, COMSIG_MOVABLE_Z_CHANGED))
+ viewer = null
+
+/// Recomputes the guide step, outlines and arrow target.
+/datum/tutorial_highlight/proc/rebuild(mob/user)
+ if(QDELETED(src))
+ return
+ user ||= viewer
+ if(!user || QDELETED(user))
+ qdel(src)
+ return
+ var/wanted = isnull(wanted_override) ? tutorial_highlights_wanted(user) : wanted_override
+ if(!wanted && isnull(wanted_override))
+ qdel(src)
+ return
+ watch(user)
+ last_turf = get_turf(user)
+ candidate_memo = list()
+ var/datum/vc_tutorial_step/step = wanted ? tutorial_highlight_step(user) : null
+ step_key = step?.key
+ if(!step)
+ candidate_memo = null
+ view_memo = null
+ set_targets(list())
+ set_arrow_target(null)
+ stop_tracking_movement()
+ return
+ set_targets(pick_outlined(user, tutorial_step_candidates(user, step)))
+ set_arrow_target(step.arrow_target(user))
+ candidate_memo = null
+ view_memo = null
+ start_tracking_movement()
+
+/// The nearest candidates within TUTORIAL_HIGHLIGHT_SHIP_RANGE, at most TUTORIAL_HIGHLIGHT_CAP.
+/datum/tutorial_highlight/proc/pick_outlined(mob/user, list/candidates)
+ var/turf/center = get_turf(user)
+ var/list/by_distance = list()
+ if(!center)
+ return by_distance
+ for(var/atom/thing as anything in candidates)
+ var/turf/spot = get_turf(thing)
+ if(!spot || spot.z != center.z || get_dist(center, spot) > TUTORIAL_HIGHLIGHT_SHIP_RANGE)
+ continue
+ by_distance[thing] = get_dist_euclidean(center, spot)
+ sortTim(by_distance, GLOBAL_PROC_REF(cmp_numeric_asc), associative = TRUE)
+ var/list/result = list()
+ for(var/atom/thing as anything in by_distance)
+ result += thing
+ if(length(result) >= TUTORIAL_HIGHLIGHT_CAP)
+ break
+ return result
+
+/// Makes the outlined set exactly new_targets, reusing images for targets that stay.
+/datum/tutorial_highlight/proc/set_targets(list/new_targets)
+ for(var/atom/old_target as anything in images.Copy())
+ if(!(old_target in new_targets))
+ remove_target(old_target)
+ for(var/atom/target as anything in new_targets)
+ var/image/current = images[target]
+ if(!current)
+ add_target(target)
+ // Some code sets dir directly, without setDir() or its signal.
+ else if(!isturf(target) && current.dir != target.dir)
+ images[target] = make_image(target)
+ shown_client?.images -= current
+ shown_client?.images |= images[target]
+ sync_client()
+
+/datum/tutorial_highlight/proc/add_target(atom/target)
+ images[target] = make_image(target)
+ RegisterSignal(target, COMSIG_QDELETING, PROC_REF(on_target_deleted))
+ RegisterSignals(target, list(COMSIG_ATOM_UPDATED_ICON, COMSIG_ATOM_POST_DIR_CHANGE), PROC_REF(on_target_look_changed))
+
+/datum/tutorial_highlight/proc/remove_target(atom/target)
+ var/image/old_image = images[target]
+ images -= target
+ UnregisterSignal(target, list(COMSIG_QDELETING, COMSIG_ATOM_UPDATED_ICON, COMSIG_ATOM_POST_DIR_CHANGE))
+ if(old_image)
+ shown_client?.images -= old_image
+
+/// The outline image for one target.
+/datum/tutorial_highlight/proc/make_image(atom/target)
+ if(isturf(target))
+ return make_turf_image(target)
+ var/image/outline = new
+ outline.appearance = target.appearance
+ // The copied appearance doesn't carry the facing over to the image (it reads SOUTH), so
+ // the outline would trace the south-facing sprite of anything turned another way.
+ outline.dir = target.dir
+ outline.loc = target
+ // An attached image already draws at the target, so the copied offsets and transform
+ // would be applied twice.
+ outline.pixel_x = 0
+ outline.pixel_y = 0
+ outline.pixel_w = 0
+ outline.pixel_z = 0
+ outline.transform = null
+ outline.layer = target.layer - 0.001
+ outline.plane = target.plane
+ // KEEP_APART: a KEEP_TOGETHER target (humans) would otherwise tint and filter the outline with itself.
+ outline.appearance_flags |= KEEP_TOGETHER | RESET_COLOR | KEEP_APART
+ outline.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ outline.alpha = 255
+ // A tinted target (atom colour or a colour matrix) would tint the gold outline too.
+ outline.color = null
+ outline.filters = list(
+ filter(type = "outline", size = 1, color = TUTORIAL_HIGHLIGHT_COLOR),
+ filter(type = "drop_shadow", x = 0, y = 0, size = 2, offset = 1, color = "[TUTORIAL_HIGHLIGHT_COLOR]90"),
+ )
+ pulse(outline)
+ pulse_filters(outline.filters[1], outline.filters[2])
+ return outline
+
+/// A gold square frame on a turf, just above the floor and under anything standing on it.
+/// (A copy of the turf would sit under its neighbours, which would hide the ring.)
+/datum/tutorial_highlight/proc/make_turf_image(turf/target)
+ var/image/frame = image('icons/hud/screen_gen.dmi', target, "selector")
+ frame.plane = target.plane
+ frame.layer = isopenturf(target) ? ABOVE_OPEN_TURF_LAYER : target.layer + 0.001
+ frame.color = TUTORIAL_HIGHLIGHT_COLOR
+ frame.appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM | KEEP_APART
+ frame.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ frame.filters = filter(type = "drop_shadow", x = 0, y = 0, size = 2, offset = 0, color = "[TUTORIAL_HIGHLIGHT_COLOR]90")
+ pulse(frame)
+ pulse_filters(null, frame.filters[1])
+ return frame
+
+/// The shared slow alpha pulse.
+/datum/tutorial_highlight/proc/pulse(image/target_image)
+ animate(target_image, alpha = 110, time = 0.8 SECONDS, loop = -1, easing = SINE_EASING)
+ animate(alpha = 255, time = 0.8 SECONDS, easing = SINE_EASING)
+
+/// Breathes the outline between bright and dark gold and the glow in and out, in step with pulse().
+/datum/tutorial_highlight/proc/pulse_filters(outline_filter, glow_filter)
+ if(outline_filter)
+ animate(outline_filter, color = TUTORIAL_HIGHLIGHT_COLOR_DIM, time = 0.8 SECONDS, loop = -1, easing = SINE_EASING)
+ animate(color = TUTORIAL_HIGHLIGHT_COLOR, time = 0.8 SECONDS, easing = SINE_EASING)
+ if(glow_filter)
+ animate(glow_filter, size = 0, time = 0.8 SECONDS, loop = -1, easing = SINE_EASING)
+ animate(size = 4, time = 0.8 SECONDS, easing = SINE_EASING)
+
+/// Puts the current images on the viewer's client and takes images and arrow off any old client.
+/datum/tutorial_highlight/proc/sync_client()
+ var/client/current = viewer?.client
+ if(shown_client && shown_client != current)
+ for(var/atom/target as anything in images)
+ shown_client.images -= images[target]
+ if(arrow)
+ shown_client.screen -= arrow
+ shown_client = current
+ if(!shown_client)
+ return
+ for(var/atom/target as anything in images)
+ shown_client.images |= images[target]
+
+/// Removes every image and forgets every target.
+/datum/tutorial_highlight/proc/clear_images()
+ for(var/atom/target as anything in images.Copy())
+ remove_target(target)
+ images.Cut()
+
+/datum/tutorial_highlight/proc/set_arrow_target(atom/target)
+ arrow_target_ref = target ? WEAKREF(target) : null
+ update_arrow()
+
+/**
+ * Places the arrow toward its target, one tile in from the edge of the viewer's screen, or
+ * hides it when the target is gone, on another z-level, or on screen. Math only, no scan:
+ * it runs on every step the viewer takes.
+ */
+/datum/tutorial_highlight/proc/update_arrow()
+ var/atom/target = arrow_target_ref?.resolve()
+ var/client/current = viewer?.client
+ var/turf/center = tutorial_screen_center(viewer)
+ var/turf/spot = get_turf(target)
+ if(!target || !current || !center || !spot || spot.z != center.z)
+ hide_arrow()
+ return
+ var/list/view_size = getviewsize(current.view)
+ if(tutorial_on_screen(center, spot, view_size))
+ hide_arrow()
+ return
+ if(!arrow)
+ arrow = new
+ arrow.point(spot.x - center.x, spot.y - center.y, view_size)
+ if(shown_client != current)
+ sync_client()
+ current.screen |= arrow
+
+/// TRUE while the arrow is on the viewer's screen. For unit tests and debugging.
+/datum/tutorial_highlight/proc/arrow_shown()
+ return !!(arrow && viewer?.client && (arrow in viewer.client.screen))
+
+/datum/tutorial_highlight/proc/hide_arrow()
+ if(!arrow)
+ return
+ shown_client?.screen -= arrow
+ viewer?.client?.screen -= arrow
+
+/datum/tutorial_highlight/proc/start_tracking_movement()
+ if(!viewer)
+ return
+ RegisterSignal(viewer, COMSIG_MOVABLE_MOVED, PROC_REF(on_viewer_moved), override = TRUE)
+ RegisterSignal(viewer, COMSIG_MOVABLE_Z_CHANGED, PROC_REF(on_viewer_z_changed), override = TRUE)
+
+/datum/tutorial_highlight/proc/stop_tracking_movement()
+ if(!viewer)
+ return
+ UnregisterSignal(viewer, list(COMSIG_MOVABLE_MOVED, COMSIG_MOVABLE_Z_CHANGED))
+
+/datum/tutorial_highlight/proc/on_viewer_moved(mob/source)
+ SIGNAL_HANDLER
+ update_arrow()
+ if(world.time < last_move_rebuild + TUTORIAL_HIGHLIGHT_MOVE_COOLDOWN)
+ return
+ var/turf/here = get_turf(source)
+ if(last_turf && here && here.z == last_turf.z && get_dist(here, last_turf) < TUTORIAL_HIGHLIGHT_MOVE_TILES)
+ return
+ last_move_rebuild = world.time
+ INVOKE_ASYNC(src, PROC_REF(rebuild), source)
+
+/datum/tutorial_highlight/proc/on_viewer_z_changed(mob/source)
+ SIGNAL_HANDLER
+ last_move_rebuild = world.time
+ INVOKE_ASYNC(src, PROC_REF(rebuild), source)
+
+/datum/tutorial_highlight/proc/on_target_deleted(atom/source)
+ SIGNAL_HANDLER
+ remove_target(source)
+
+/// The target changed its look; rebuild its copy so the outline still hugs it.
+/datum/tutorial_highlight/proc/on_target_look_changed(atom/source)
+ SIGNAL_HANDLER
+ var/image/old_image = images[source]
+ if(!old_image)
+ return
+ shown_client?.images -= old_image
+ images[source] = make_image(source)
+ shown_client?.images |= images[source]
+
+/// Logout, death, ghosting or deletion: drop the outlines and arrow. A later refresh (the
+/// panel, a credit) brings them back if the viewer still wants them.
+/datum/tutorial_highlight/proc/on_viewer_gone(mob/source)
+ SIGNAL_HANDLER
+ qdel(src)
+
+/**
+ * The tutorial's off-screen arrow. One per viewer, owned by their /datum/tutorial_highlight;
+ * it only ever sits in that viewer's client.screen.
+ */
+/atom/movable/screen/tutorial_arrow
+ name = ""
+ icon = 'voidcrew/icons/hud/tutorial_arrow.dmi'
+ icon_state = "arrow"
+ color = TUTORIAL_HIGHLIGHT_COLOR
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ animate_movement = NO_STEPS
+ screen_loc = "CENTER,CENTER"
+
+/atom/movable/screen/tutorial_arrow/Initialize(mapload, datum/hud/hud_owner)
+ . = ..()
+ add_filter("tutorial_arrow_glow", 1, drop_shadow_filter(x = 0, y = 0, size = 3, offset = 0, color = "[TUTORIAL_HIGHLIGHT_COLOR]90"))
+ animate(src, alpha = 150, time = 0.8 SECONDS, loop = -1, easing = SINE_EASING)
+ animate(alpha = 255, time = 0.8 SECONDS, easing = SINE_EASING)
+
+/**
+ * Places the arrow on the line from the screen centre toward a target dx, dy tiles away,
+ * one tile in from the screen edge, and turns it to face the target.
+ *
+ * The facing snaps to the nearest of eight directions. Cardinals use the straight sprite and
+ * diagonals a hand-drawn 45 degree one, each only ever turned by whole right angles, so the
+ * pixel art is never resampled (a free rotation renders jagged).
+ */
+/atom/movable/screen/tutorial_arrow/proc/point(dx, dy, list/view_size)
+ var/edge_x = max((view_size[1] - 1) / 2 - 1, 0)
+ var/edge_y = max((view_size[2] - 1) / 2 - 1, 0)
+ // The bottom row of the screen holds the HUD buttons, so a downward arrow stays one tile higher.
+ if(dy < 0)
+ edge_y = max(edge_y - 1, 0)
+ var/scale = 0
+ if(dx && dy)
+ scale = min(edge_x / abs(dx), edge_y / abs(dy))
+ else if(dx)
+ scale = edge_x / abs(dx)
+ else if(dy)
+ scale = edge_y / abs(dy)
+ var/offset_x = round(dx * scale * ICON_SIZE_X)
+ var/offset_y = round(dy * scale * ICON_SIZE_Y)
+ screen_loc = "CENTER[screen_offset_text(offset_x, ICON_SIZE_X)],CENTER[screen_offset_text(offset_y, ICON_SIZE_Y)]"
+ // delta_to_angle() is clockwise from north. "arrow" points south (180), "arrow_diagonal"
+ // south-east (135).
+ var/sector = round(delta_to_angle(dx, dy) / 45, 1) % 8
+ icon_state = ISODD(sector) ? "arrow_diagonal" : "arrow"
+ var/matrix/turned = matrix()
+ turned.Turn(sector * 45 - (ISODD(sector) ? 135 : 180))
+ transform = turned
+
+/// "+tiles:pixels" or "-tiles:pixels" for a pixel offset from a screen anchor, pixels 0 to tile_size - 1.
+/atom/movable/screen/tutorial_arrow/proc/screen_offset_text(pixels, tile_size)
+ var/tiles = round(pixels / tile_size)
+ var/remainder = pixels - tiles * tile_size
+ return "[tiles >= 0 ? "+" : ""][tiles]:[remainder]"
+
+#undef TUTORIAL_HIGHLIGHT_CAP
+#undef TUTORIAL_HIGHLIGHT_VIEW_RANGE
+#undef TUTORIAL_HIGHLIGHT_SHIP_RANGE
+#undef TUTORIAL_ARROW_RANGE
+#undef TUTORIAL_HIGHLIGHT_MOVE_COOLDOWN
+#undef TUTORIAL_HIGHLIGHT_MOVE_TILES
+#undef TUTORIAL_HIGHLIGHT_SHIP_CACHE
+#undef TUTORIAL_HIGHLIGHT_COLOR
+#undef TUTORIAL_HIGHLIGHT_COLOR_DIM
diff --git a/voidcrew/modules/tutorials/tutorial_panel.dm b/voidcrew/modules/tutorials/tutorial_panel.dm
new file mode 100644
index 00000000000..16dd1620acf
--- /dev/null
+++ b/voidcrew/modules/tutorials/tutorial_panel.dm
@@ -0,0 +1,251 @@
+/**
+ * # Tutorial checklist panel
+ *
+ * One tgui window per viewer (TutorialChecklist). It opens by itself 4 s after every
+ * spawn unless the player turned that off, closed it this round, or has every item
+ * done. The "Tutorials" OOC verb opens it any time, ghosts included.
+ *
+ * Its actions are the two footer preferences and "select", which records the item the
+ * viewer has open (SSvc_tutorials.selected) for the in-game highlight. It takes no refs
+ * and never acts on the world.
+ *
+ * Autoupdate is off. Credits push updates themselves, and while the window is open a loop
+ * timer refreshes it and the viewer's highlights every TUTORIAL_LIVE_REFRESH, so live lines
+ * (step live_line(), computed only for the open item) and the arrow stay current.
+ */
+
+/// Gap between spawning and the checklist opening, so it lands after the client has
+/// loaded into its body.
+#define TUTORIAL_CHECKLIST_DELAY (4 SECONDS)
+/// Gap between two live refreshes of an open checklist.
+#define TUTORIAL_LIVE_REFRESH (5 SECONDS)
+
+/// Ckeys who closed the checklist this round. It stays shut for them until next round.
+GLOBAL_LIST_EMPTY(tutorial_checklist_hidden)
+
+/// One datum for the whole server; tgui keys windows on (user, datum).
+GLOBAL_DATUM_INIT(tutorial_checklist, /datum/tutorial_checklist, new)
+
+/// ckey -> the loop timer refreshing that viewer's open checklist.
+GLOBAL_LIST_EMPTY(tutorial_live_timers)
+
+/datum/tutorial_checklist
+
+/datum/tutorial_checklist/ui_state(mob/user)
+ return GLOB.always_state
+
+/datum/tutorial_checklist/ui_interact(mob/user, datum/tgui/ui)
+ ui = SStgui.try_update_ui(user, src, ui)
+ if(!ui)
+ run_state_checks(user)
+ ui = new(user, src, "TutorialChecklist")
+ // Credits push updates themselves (SStgui.try_update_ui), and live lines
+ // refresh on their own slower loop, so the window doesn't rebuild every tick.
+ ui.set_autoupdate(FALSE)
+ ui.open()
+ start_live_refresh(user)
+ tutorial_refresh_highlights(user)
+ // The guide step is only known once the highlighter has run.
+ ui.send_update()
+
+/// Starts (or restarts) the viewer's live refresh loop.
+/datum/tutorial_checklist/proc/start_live_refresh(mob/user)
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey)
+ return
+ stop_live_refresh(ckey)
+ GLOB.tutorial_live_timers[ckey] = addtimer(CALLBACK(src, PROC_REF(live_refresh), ckey, WEAKREF(user)), TUTORIAL_LIVE_REFRESH, TIMER_STOPPABLE | TIMER_LOOP | TIMER_DELETE_ME)
+
+/datum/tutorial_checklist/proc/stop_live_refresh(ckey)
+ var/timer = GLOB.tutorial_live_timers[ckey]
+ GLOB.tutorial_live_timers -= ckey
+ if(timer)
+ deltimer(timer)
+
+/// Loop timer landing point: refreshes the open window and the viewer's highlights, or
+/// stops once the window is gone.
+/datum/tutorial_checklist/proc/live_refresh(ckey, datum/weakref/user_ref)
+ var/mob/user = user_ref?.resolve()
+ var/datum/tgui/ui = user ? SStgui.get_open_ui(user, src) : null
+ if(!ui)
+ stop_live_refresh(ckey)
+ return
+ ui.send_update()
+ tutorial_refresh_highlights(user)
+
+/// Credits steps the viewer has already done but no hook saw.
+/datum/tutorial_checklist/proc/run_state_checks(mob/user)
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey)
+ return
+ SSvc_tutorials.build_catalog()
+ for(var/key in SSvc_tutorials.steps_by_key)
+ if(SSvc_tutorials.has_key(ckey, key))
+ continue
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key[key]
+ if(step.state_satisfied(user))
+ tutorial_credit(user, key)
+
+/datum/tutorial_checklist/ui_static_data(mob/user)
+ SSvc_tutorials.build_catalog()
+ var/list/items = list()
+ var/list/category_items = list()
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ var/list/steps = list()
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ steps += list(list(
+ "key" = step.key,
+ "name" = step.name,
+ "text" = step.text,
+ "optional" = step.optional,
+ "route" = step.route,
+ "route_name" = step.route_name,
+ ))
+ items += list(list(
+ "id" = item.id,
+ "name" = item.name,
+ "intro" = item.intro,
+ "steps" = steps,
+ ))
+ if(!category_items[item.category])
+ category_items[item.category] = list()
+ category_items[item.category] += item.id
+ var/list/categories = list()
+ for(var/category_id in GLOB.tutorial_categories)
+ if(!length(category_items[category_id]))
+ continue
+ categories += list(list(
+ "id" = category_id,
+ "name" = GLOB.tutorial_categories[category_id],
+ "items" = category_items[category_id],
+ ))
+ return list("categories" = categories, "items" = items)
+
+/datum/tutorial_checklist/ui_data(mob/user)
+ var/list/data = list()
+ var/ckey = tutorial_viewer_ckey(user)
+ var/list/done_keys = list()
+ var/list/notes = list()
+ var/list/excused = list()
+ var/list/progress = ckey ? SSvc_tutorials.progress[ckey] : null
+ for(var/key in progress)
+ done_keys += key
+ for(var/key in SSvc_tutorials.steps_by_key)
+ if(progress?[key])
+ continue
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key[key]
+ var/note = step.availability(user)
+ if(note)
+ notes[key] = note
+ if(step.excused(user))
+ excused += key
+ data["done"] = done_keys
+ data["notes"] = notes
+ data["excused"] = excused
+ var/suggested = ckey ? SSvc_tutorials.suggested_item(ckey, user) : null
+ data["suggested"] = suggested
+ data["selected"] = ckey ? SSvc_tutorials.selected[ckey] : null
+ // Live lines, for the open item's undone steps only.
+ var/list/live = list()
+ var/open_id = data["selected"] || suggested
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ if(item.id != open_id)
+ continue
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ if(progress?[step.key])
+ continue
+ var/line = step.live_line(user)
+ if(line)
+ // The panel wraps it to two lines; this only stops a runaway string.
+ live[step.key] = copytext_char("[line]", 1, 161)
+ break
+ data["live"] = live
+ // The step the outlines, arrow and window focus follow, if the viewer has highlights.
+ var/datum/tutorial_highlight/highlight = ckey ? GLOB.tutorial_highlighters[ckey] : null
+ data["guide"] = highlight?.viewer == user ? highlight.step_key : null
+ data["spawn_open"] = user.client?.prefs ? !!user.client.prefs.read_preference(/datum/preference/toggle/tutorial_checklist) : TRUE
+ data["highlights"] = user.client?.prefs ? !!user.client.prefs.read_preference(/datum/preference/toggle/tutorial_highlights) : TRUE
+ return data
+
+/datum/tutorial_checklist/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
+ . = ..()
+ if(.)
+ return
+ switch(action)
+ if("toggle_spawn_open")
+ var/datum/preferences/prefs = ui.user.client?.prefs
+ if(!prefs)
+ return FALSE
+ var/datum/preference/toggle/tutorial_checklist/pref = GLOB.preference_entries[/datum/preference/toggle/tutorial_checklist]
+ prefs.write_preference(pref, !prefs.read_preference(/datum/preference/toggle/tutorial_checklist))
+ return TRUE
+ if("toggle_highlights")
+ var/datum/preferences/prefs = ui.user.client?.prefs
+ if(!prefs)
+ return FALSE
+ var/datum/preference/toggle/tutorial_highlights/pref = GLOB.preference_entries[/datum/preference/toggle/tutorial_highlights]
+ prefs.write_preference(pref, !prefs.read_preference(/datum/preference/toggle/tutorial_highlights))
+ tutorial_refresh_highlights(ui.user)
+ return TRUE
+ if("select")
+ var/ckey = tutorial_viewer_ckey(ui.user)
+ var/item_id = params["id"]
+ if(!ckey || !istext(item_id))
+ return FALSE
+ var/known = FALSE
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ if(item.id == item_id)
+ known = TRUE
+ break
+ if(!known)
+ return FALSE
+ SSvc_tutorials.selected[ckey] = item_id
+ tutorial_refresh_highlights(ui.user)
+ return TRUE
+
+/datum/tutorial_checklist/ui_close(mob/user)
+ . = ..()
+ var/ckey = tutorial_viewer_ckey(user)
+ if(ckey)
+ GLOB.tutorial_checklist_hidden |= ckey
+ stop_live_refresh(ckey)
+ tutorial_refresh_highlights(user)
+
+/// The ckey whose progress a viewer sees.
+/proc/tutorial_viewer_ckey(mob/user)
+ return user?.ckey || ckey(user?.mind?.key)
+
+/**
+ * Opens the checklist 4 s after a spawn, if the player wants it and still has
+ * something left to do. Called from the spawn paths.
+ */
+/proc/try_show_tutorial_checklist(mob/user)
+ if(!user?.client)
+ return
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey || (ckey in GLOB.tutorial_checklist_hidden))
+ return
+ if(!user.client.prefs?.read_preference(/datum/preference/toggle/tutorial_checklist))
+ return
+ if(SSvc_tutorials.all_complete(ckey, user))
+ return
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(show_tutorial_checklist), user), TUTORIAL_CHECKLIST_DELAY)
+
+/// Timer landing point for try_show_tutorial_checklist().
+/proc/show_tutorial_checklist(mob/user)
+ if(!user?.client)
+ return
+ if(tutorial_viewer_ckey(user) in GLOB.tutorial_checklist_hidden)
+ return
+ GLOB.tutorial_checklist.ui_interact(user)
+
+/client/verb/tutorial_checklist()
+ set name = "Tutorials"
+ set category = "OOC"
+ set desc = "Open the tutorial checklist."
+ if(!mob)
+ return
+ GLOB.tutorial_checklist.ui_interact(mob)
+
+#undef TUTORIAL_CHECKLIST_DELAY
+#undef TUTORIAL_LIVE_REFRESH
diff --git a/voidcrew/modules/tutorials/tutorial_progress.dm b/voidcrew/modules/tutorials/tutorial_progress.dm
new file mode 100644
index 00000000000..6a0220ae0b7
--- /dev/null
+++ b/voidcrew/modules/tutorials/tutorial_progress.dm
@@ -0,0 +1,286 @@
+/**
+ * # Tutorial checklist progress
+ *
+ * Holds which tutorial steps each ckey has done and saves them to tg's existing
+ * `tutorial_completions` table under "vc/" keys (no schema change). tg's own
+ * SStutorials ignores keys it doesn't know, so the two never collide.
+ *
+ * Progress belongs to the ckey, not the body: death, ghosting and cryo lose nothing.
+ * With no database it lives in memory for the round.
+ *
+ * The credit API every hook calls:
+ * - tutorial_credit(mob/user, step_key)
+ * - tutorial_credit_crew(obj/structure/overmap/ship/ship, step_key, aboard_only = FALSE)
+ */
+
+/// How long a ship's "is this machine aboard" scan stays cached.
+#define TUTORIAL_MACHINE_CACHE_TIME (60 SECONDS)
+
+SUBSYSTEM_DEF(vc_tutorials)
+ name = "Tutorial Checklist"
+ flags = SS_NO_FIRE
+
+ /// ckey -> list(key -> TRUE). Step and item keys both live here.
+ var/list/progress = list()
+ /// Every checklist item singleton, sorted by category (GLOB.tutorial_categories order), then order.
+ var/list/datum/vc_tutorial/items
+ /// step key -> step singleton
+ var/list/datum/vc_tutorial_step/steps_by_key
+ /// step key -> the item singleton that owns it
+ var/list/datum/vc_tutorial/item_by_step
+ /// Ckeys whose saved progress has been loaded (or asked for) this round.
+ var/list/loaded_ckeys = list()
+ /// "[REF(ship)]|[type]" -> list(world.time, result). Keyed by ref string so no hard ref is held.
+ var/list/machine_cache = list()
+ /// ckey -> the item id the viewer has open in the panel. The in-game highlight reads it.
+ var/list/selected = list()
+
+/datum/controller/subsystem/vc_tutorials/Initialize()
+ build_catalog()
+ RegisterSignal(SSdcs, COMSIG_GLOB_CLIENT_CONNECT, PROC_REF(on_client_connect))
+ for(var/client/client as anything in GLOB.clients)
+ if(client?.ckey)
+ INVOKE_ASYNC(src, PROC_REF(load_progress), client.ckey)
+ return SS_INIT_SUCCESS
+
+/// Builds the item and step singletons. Safe to call more than once; callers that can run
+/// before Initialize call it first.
+/datum/controller/subsystem/vc_tutorials/proc/build_catalog()
+ if(items)
+ return
+ items = list()
+ steps_by_key = list()
+ item_by_step = list()
+ for(var/item_type in subtypesof(/datum/vc_tutorial))
+ var/datum/vc_tutorial/item = new item_type
+ if(!item.id)
+ continue
+ var/list/step_instances = list()
+ for(var/step_type in item.steps)
+ var/datum/vc_tutorial_step/step = new step_type
+ step_instances += step
+ steps_by_key[step.key] = step
+ item_by_step[step.key] = item
+ item.steps = step_instances
+ items += item
+ sortTim(items, GLOBAL_PROC_REF(cmp_vc_tutorial_order))
+
+/// Sort helper for the checklist items: category order first, then order within it.
+/proc/cmp_vc_tutorial_order(datum/vc_tutorial/a, datum/vc_tutorial/b)
+ var/category_a = GLOB.tutorial_categories.Find(a.category)
+ var/category_b = GLOB.tutorial_categories.Find(b.category)
+ if(category_a != category_b)
+ return category_a - category_b
+ return a.order - b.order
+
+/datum/controller/subsystem/vc_tutorials/proc/on_client_connect(datum/source, client/client)
+ SIGNAL_HANDLER
+ if(client?.ckey)
+ INVOKE_ASYNC(src, PROC_REF(load_progress), client.ckey)
+
+/// Loads a ckey's saved "vc/" keys and merges them into anything credited this round.
+/datum/controller/subsystem/vc_tutorials/proc/load_progress(ckey)
+ if(!ckey || loaded_ckeys[ckey])
+ return
+ if(!SSdbcore.IsConnected())
+ return
+ loaded_ckeys[ckey] = TRUE
+ var/datum/db_query/query = SSdbcore.NewQuery(
+ "SELECT tutorial_key FROM [format_table_name("tutorial_completions")] WHERE ckey = :ckey AND tutorial_key LIKE :prefix",
+ list("ckey" = ckey, "prefix" = "[TUTORIAL_KEY_PREFIX]%")
+ )
+ if(!query.Execute())
+ qdel(query)
+ loaded_ckeys -= ckey
+ return
+ var/list/done = progress[ckey]
+ if(!done)
+ done = list()
+ progress[ckey] = done
+ while(query.NextRow())
+ var/key = query.item[1]
+ if(key)
+ done[key] = TRUE
+ qdel(query)
+ var/mob/viewer = get_mob_by_ckey(ckey)
+ if(viewer)
+ SStgui.try_update_ui(viewer, GLOB.tutorial_checklist)
+
+/// Writes keys for a ckey. Duplicates are ignored by the table's unique index.
+/datum/controller/subsystem/vc_tutorials/proc/save_keys(ckey, list/keys)
+ if(!SSdbcore.IsConnected())
+ return
+ for(var/key in keys)
+ var/datum/db_query/query = SSdbcore.NewQuery(
+ "INSERT INTO [format_table_name("tutorial_completions")] (ckey, tutorial_key) VALUES (:ckey, :tutorial_key) ON DUPLICATE KEY UPDATE tutorial_key = tutorial_key",
+ list("ckey" = ckey, "tutorial_key" = key)
+ )
+ query.warn_execute()
+ qdel(query)
+
+/// TRUE if the ckey has this key (step or item).
+/datum/controller/subsystem/vc_tutorials/proc/has_key(ckey, key)
+ var/list/done = progress[ckey]
+ return !!done?[key]
+
+/// TRUE if the item is complete for this viewer: its item key is saved, or every
+/// counted step (not optional, not excused for them) is done.
+/datum/controller/subsystem/vc_tutorials/proc/item_complete(datum/vc_tutorial/item, ckey, mob/user)
+ var/list/done = progress[ckey]
+ if(!done)
+ return FALSE
+ if(done[item.id])
+ return TRUE
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ if(step.optional || done[step.key])
+ continue
+ if(step.route_excused(ckey))
+ continue
+ if(user && step.excused(user))
+ continue
+ return FALSE
+ return TRUE
+
+/**
+ * The item the panel suggests next for this viewer: the first incomplete item, in panel
+ * order, with a counted step left that is neither excused nor marked unavailable for them.
+ * Returns the item id, or null.
+ */
+/datum/controller/subsystem/vc_tutorials/proc/suggested_item(ckey, mob/user)
+ build_catalog()
+ var/list/done = progress[ckey]
+ for(var/datum/vc_tutorial/item as anything in items)
+ if(item_complete(item, ckey, user))
+ continue
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ if(step.optional || done?[step.key] || step.route_excused(ckey))
+ continue
+ if(user && (step.excused(user) || step.availability(user)))
+ continue
+ return item.id
+ return null
+
+/// TRUE if every item is complete for this viewer.
+/datum/controller/subsystem/vc_tutorials/proc/all_complete(ckey, mob/user)
+ build_catalog()
+ for(var/datum/vc_tutorial/item as anything in items)
+ if(!item_complete(item, ckey, user))
+ return FALSE
+ return TRUE
+
+/// Marks a step for a ckey. Returns TRUE if it was newly marked.
+/datum/controller/subsystem/vc_tutorials/proc/credit_ckey(ckey, step_key, mob/user)
+ build_catalog()
+ var/list/done = progress[ckey]
+ if(!done)
+ done = list()
+ progress[ckey] = done
+ if(done[step_key])
+ return FALSE
+ done[step_key] = TRUE
+ var/list/to_save = list(step_key)
+ var/datum/vc_tutorial/item = item_by_step[step_key]
+ if(item && !done[item.id] && item_complete(item, ckey, user))
+ done[item.id] = TRUE
+ to_save += item.id
+ if(SSdbcore.IsConnected())
+ INVOKE_ASYNC(src, PROC_REF(save_keys), ckey, to_save)
+ var/mob/viewer = user?.client ? user : get_mob_by_ckey(ckey)
+ if(viewer)
+ SStgui.try_update_ui(viewer, GLOB.tutorial_checklist)
+ tutorial_refresh_highlights(viewer)
+ return TRUE
+
+/// Whether a machine of this type is aboard the ship, cached for TUTORIAL_MACHINE_CACHE_TIME
+/// because get_ship_machines() walks every area's contents.
+/datum/controller/subsystem/vc_tutorials/proc/ship_has_machine(obj/structure/overmap/ship/ship, machine_type)
+ if(QDELETED(ship))
+ return FALSE
+ var/cache_key = "[REF(ship)]|[machine_type]"
+ var/list/cached = machine_cache[cache_key]
+ if(cached && world.time < cached[1] + TUTORIAL_MACHINE_CACHE_TIME)
+ return cached[2]
+ var/result = length(ship.get_ship_machines(machine_type)) > 0
+ machine_cache[cache_key] = list(world.time, result)
+ return result
+
+/**
+ * Credits a tutorial step to a player. Returns TRUE if it was newly credited.
+ * Cheap when the step is already done: one assoc lookup.
+ */
+/proc/tutorial_credit(mob/user, step_key)
+ if(!user || !step_key)
+ return FALSE
+ var/ckey = user.ckey || ckey(user.mind?.key)
+ if(!ckey)
+ return FALSE
+ var/list/done = SSvc_tutorials.progress[ckey]
+ if(done?[step_key])
+ return FALSE
+ return SSvc_tutorials.credit_ckey(ckey, step_key, user)
+
+/**
+ * Credits a step to every member of a ship's crew, through their current bodies.
+ * With aboard_only, only members whose body is aboard that ship.
+ */
+/proc/tutorial_credit_crew(obj/structure/overmap/ship/ship, step_key, aboard_only = FALSE)
+ if(!ship?.ship_team || !step_key)
+ return
+ for(var/datum/mind/member as anything in ship.ship_team.members)
+ var/mob/body = member?.current
+ if(!body)
+ continue
+ if(aboard_only && get_ship_from_atom(body) != ship)
+ continue
+ tutorial_credit(body, step_key)
+
+// ---------------------------------------------------------------------------
+// Ship signals: dock, undock, land, survey
+// ---------------------------------------------------------------------------
+
+/obj/structure/overmap/ship/Initialize(mapload, datum/map_template/shuttle/voidcrew/template)
+ . = ..()
+ if(. == INITIALIZE_HINT_QDEL || istype(src, /obj/structure/overmap/ship/npc))
+ return
+ RegisterSignal(src, COMSIG_VOIDCREW_SHIP_DOCKED, PROC_REF(tutorial_on_docked))
+ RegisterSignal(src, COMSIG_VOIDCREW_SHIP_UNDOCKED, PROC_REF(tutorial_on_undocked))
+ RegisterSignal(src, COMSIG_VOIDCREW_SURVEY_COMPLETED, PROC_REF(tutorial_on_survey))
+
+/obj/structure/overmap/ship/proc/tutorial_on_docked(datum/source)
+ SIGNAL_HANDLER
+ // A checkpoint rebuild also sends DOCKED; only a real berth counts.
+ if(!docked)
+ return
+ tutorial_credit_crew(src, TUTORIAL_STEP_SHIP_DOCK, aboard_only = TRUE)
+ if(istype(docked, /obj/structure/overmap/planet) && !istype(docked, /obj/structure/overmap/planet/empty))
+ tutorial_credit_crew(src, TUTORIAL_STEP_RUIN_LAND, aboard_only = TRUE)
+ // Trader outposts only: the trade steps after this one (elevator, shops) are theirs.
+ else if(istype(docked, /obj/structure/overmap/trader_outpost))
+ tutorial_credit_crew(src, TUTORIAL_STEP_TRADE_TRAVEL, aboard_only = TRUE)
+ if(tutorial_docked_with_pirate())
+ tutorial_credit_crew(src, TUTORIAL_STEP_PIRATES_BOARD, aboard_only = TRUE)
+
+/// TRUE if this ship is docked to a pirate ship, or to the empty space a pirate ship is docked at.
+/// Both ships of a ship-to-ship dock have `docked` set from dock(), before either arrives.
+/obj/structure/overmap/ship/proc/tutorial_docked_with_pirate()
+ if(istype(docked, /obj/structure/overmap/ship))
+ return tutorial_is_pirate_ship(docked)
+ if(!istype(docked, /obj/structure/overmap/planet/empty))
+ return FALSE
+ for(var/obj/structure/overmap/ship/npc/other in SSovermap.simulated_ships)
+ if(other != src && other.docked == docked && tutorial_is_pirate_ship(other))
+ return TRUE
+ return FALSE
+
+/obj/structure/overmap/ship/proc/tutorial_on_undocked(datum/source)
+ SIGNAL_HANDLER
+ // Also sent while a derelict hull is being deleted; nobody flew that.
+ if(QDELETED(src))
+ return
+ tutorial_credit_crew(src, TUTORIAL_STEP_SHIP_UNDOCK, aboard_only = TRUE)
+
+/obj/structure/overmap/ship/proc/tutorial_on_survey(datum/source, celestial_type)
+ SIGNAL_HANDLER
+ tutorial_credit_crew(src, TUTORIAL_STEP_SURVEYS_SURVEY)
+
+#undef TUTORIAL_MACHINE_CACHE_TIME
diff --git a/voidcrew/modules/tutorials/tutorial_ship_hud.dm b/voidcrew/modules/tutorials/tutorial_ship_hud.dm
new file mode 100644
index 00000000000..885b7c425d9
--- /dev/null
+++ b/voidcrew/modules/tutorials/tutorial_ship_hud.dm
@@ -0,0 +1,65 @@
+// Tutorial checklist: the HUD outline for "Open Ship Management".
+// The Ship Management action button is a per-HUD screen object, so a filter on it is seen only
+// by its owner (and anyone observing that HUD). Must be included after tutorial_highlights.dm:
+// an override placed before the proc it chains onto never runs.
+
+#define TUTORIAL_HUD_FILTER "tutorial_hud_outline"
+
+/datum/tutorial_highlight
+ /// Weakrefs to the HUD screen objects we outlined.
+ var/list/hud_outlined = list()
+
+/datum/tutorial_highlight/rebuild(mob/user)
+ . = ..()
+ if(QDELETED(src))
+ return
+ set_hud_outline(tutorial_ship_manage_buttons(viewer))
+
+/datum/tutorial_highlight/Destroy()
+ set_hud_outline(list())
+ return ..()
+
+/// Outlines exactly these screen objects, taking the outline off any others.
+/datum/tutorial_highlight/proc/set_hud_outline(list/new_targets)
+ for(var/datum/weakref/old_ref as anything in hud_outlined)
+ var/atom/movable/screen/old_target = old_ref.resolve()
+ if(old_target && !(old_target in new_targets))
+ old_target.remove_filter(TUTORIAL_HUD_FILTER)
+ hud_outlined = list()
+ for(var/atom/movable/screen/target as anything in new_targets)
+ if(!target.get_filter(TUTORIAL_HUD_FILTER))
+ target.add_filter(TUTORIAL_HUD_FILTER, 10, outline_filter(1, "#FFC83C"))
+ // Pulses in step with the world outlines.
+ var/hud_filter = target.get_filter(TUTORIAL_HUD_FILTER)
+ animate(hud_filter, color = "#8A5A10", time = 0.8 SECONDS, loop = -1, easing = SINE_EASING)
+ animate(color = "#FFC83C", time = 0.8 SECONDS, easing = SINE_EASING)
+ hud_outlined += WEAKREF(target)
+
+/**
+ * The viewer's Ship Management button (and the palette toggle when the button sits in the
+ * collapsed palette) while "Open Ship Management" is the undone step of their open item.
+ */
+/proc/tutorial_ship_manage_buttons(mob/user)
+ var/datum/hud/hud = user?.hud_used
+ if(!hud)
+ return list()
+ var/ckey = tutorial_viewer_ckey(user)
+ if(!ckey || SSvc_tutorials.has_key(ckey, TUTORIAL_STEP_SHIP_MANAGE))
+ return list()
+ var/datum/vc_tutorial/item = tutorial_open_item(user)
+ if(item?.id != TUTORIAL_ITEM_SHIP)
+ return list()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key?[TUTORIAL_STEP_SHIP_MANAGE]
+ if(!step || step.excused(user))
+ return list()
+ var/list/buttons = list()
+ for(var/datum/action/innate/captain_management/action in user.actions)
+ var/atom/movable/screen/movable/action_button/button = action.viewers[hud]
+ if(!button)
+ continue
+ buttons += button
+ if(button.location == SCRN_OBJ_IN_PALETTE && hud.toggle_palette)
+ buttons |= hud.toggle_palette
+ return buttons
+
+#undef TUTORIAL_HUD_FILTER
diff --git a/voidcrew/modules/unit_tests/_unit_tests.dm b/voidcrew/modules/unit_tests/_unit_tests.dm
index 609aaa01250..30752e53add 100644
--- a/voidcrew/modules/unit_tests/_unit_tests.dm
+++ b/voidcrew/modules/unit_tests/_unit_tests.dm
@@ -104,8 +104,14 @@
#include "voidcrew_cyberware_models_b.dm"
#include "voidcrew_cyberware_npcs.dm"
#include "voidcrew_cyberware_passives.dm"
+#include "voidcrew_cyberware_replay.dm"
+#include "voidcrew_cyberware_replay_end.dm"
+#include "voidcrew_cyberware_sandy_sound.dm"
#include "voidcrew_cyberware_soak.dm"
#include "voidcrew_cyberware_text.dm"
+#include "voidcrew_cyberware_timestop.dm"
+#include "voidcrew_cyberware_timestop_cover.dm"
+#include "voidcrew_cyberware_timestop_shared.dm"
#include "voidcrew_cyberware_widowline.dm"
#include "voidcrew_cyberware_zoom.dm"
#include "voidcrew_derelict_helpers.dm"
@@ -144,6 +150,7 @@
#include "voidcrew_hyperviolence_blood.dm"
#include "voidcrew_hyperviolence_braingut.dm"
#include "voidcrew_hyperviolence_crits.dm"
+#include "voidcrew_hyperviolence_exec_aim.dm"
#include "voidcrew_hyperviolence_hitlines.dm"
#include "voidcrew_hyperviolence_overlays_exec.dm"
#include "voidcrew_hyperviolence_visuals.dm"
@@ -299,6 +306,7 @@
#include "voidcrew_trader_jukebox.dm"
#include "voidcrew_trader_rental_locker.dm"
#include "voidcrew_trader_shipyard_berths.dm"
+#include "voidcrew_tutorials.dm"
#include "voidcrew_vestige.dm"
#include "voidcrew_vestige_abductor.dm"
#include "voidcrew_vestige_ascension.dm"
diff --git a/voidcrew/modules/unit_tests/voidcrew_bounty_chrome_cascade.dm b/voidcrew/modules/unit_tests/voidcrew_bounty_chrome_cascade.dm
index 6bf48a69880..16a8d1d1967 100644
--- a/voidcrew/modules/unit_tests/voidcrew_bounty_chrome_cascade.dm
+++ b/voidcrew/modules/unit_tests/voidcrew_bounty_chrome_cascade.dm
@@ -193,7 +193,13 @@
var/mob/living/carbon/human/npc/bounty_companion/buddy = buddies[1]
buddy.ai_controller?.set_ai_status(AI_STATUS_OFF)
buddy.forceMove(spot(1, 2))
- TEST_ASSERT("cascade" in bounty_chrome_install_now(buddy, list("cascade")), "The companion's lattice didn't go in")
+ // A companion can spawn with chrome of its own, and some of it leaves no room for a lattice
+ var/list/came_with = list()
+ for(var/obj/item/organ/organ in buddy.organs)
+ if(organ.GetComponent(/datum/component/cyberware))
+ came_with += organ.type
+ qdel(organ)
+ TEST_ASSERT("cascade" in bounty_chrome_install_now(buddy, list("cascade")), "The companion's lattice didn't go in (it spawned with [english_list(came_with, "no chrome")])")
var/datum/component/bounty_chrome/buddy_chrome = buddy.GetComponent(/datum/component/bounty_chrome)
var/datum/bounty_chrome_move/cascade/buddy_move = buddy_chrome?.move_of(/datum/bounty_chrome_move/cascade)
TEST_ASSERT_NOTNULL(buddy_move, "The companion's lattice has no move")
@@ -280,10 +286,9 @@
fcopy(getFlatIcon(brawler, facing), "data/bounty_chrome_renders/cascade_brawler_[dir2text(facing)].png")
fcopy(getFlatIcon(gunman, facing), "data/bounty_chrome_renders/cascade_gunman_[dir2text(facing)].png")
// The afterimage a step leaves, tinted as the lattice's trail is (a flat icon drops an atom's colour, so the tint goes on by hand)
- var/obj/effect/temp_visual/decoy/fading/cascade/afterimage = new(spot(2, 3), gunman, 0)
- for(var/hue in list(0, 120, 280))
+ var/list/tints = cyberware_cascade_trail_tints()
+ for(var/age in 1 to length(tints))
var/icon/trail = getFlatIcon(gunman, EAST)
- trail.MapColors(arglist(afterimage.cascade_tint_matrix(hue)))
- fcopy(trail, "data/bounty_chrome_renders/cascade_afterimage_[hue].png")
- qdel(afterimage)
+ trail.MapColors(arglist(tints[age]))
+ fcopy(trail, "data/bounty_chrome_renders/cascade_afterimage_[age].png")
#endif
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_replay.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_replay.dm
new file mode 100644
index 00000000000..82460ba0317
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_replay.dm
@@ -0,0 +1,1477 @@
+/**
+ * # The replay after a Sandevistan slow-mo
+ *
+ * voidcrew/modules/cyberware/ware_sandy_replay.dm. A slow-mo that runs out, or that its user ends, is shown again
+ * from frame 0 on the real things, drawn at their recorded spots without being moved, and every one of them ends
+ * exactly as it really was. A slow-mo another player cut short doesn't replay.
+ *
+ * Unit-test files compile before voidcrew/_DEFINES/, so literals stand in for the module's defines: the replay's
+ * states are 1 recording, 2 about to play, 3 playing, and its trait source is "sandy_replay".
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay
+ abstract_type = /datum/unit_test/voidcrew_cyberware_timestop/replay
+
+/// Opens `user`'s slow-mo and returns its recording
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/start_recording(mob/living/carbon/human/user)
+ surge(user)
+ sleep(0.1 SECONDS) // the field starts async
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ TEST_ASSERT_NOTNULL(replay, "The slow-mo isn't being recorded")
+ TEST_ASSERT_EQUAL(replay.state, 1, "The recording didn't start in its recording state")
+ return replay
+
+/// Ends `user`'s slow-mo the way a second press of the surge does
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/press_again(mob/living/carbon/human/user)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/// Waits up to `limit` for `user`'s replay to be over
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/wait_over(mob/living/carbon/human/user, limit = 5 SECONDS)
+ var/until = world.time + limit
+ while(GLOB.sandy_replays[user] && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay never ended")
+
+/// Whether the replay holds `body` (AI pause or input lock)
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/held(mob/living/body)
+ return HAS_TRAIT_FROM(body, TRAIT_AI_PAUSED, "sandy_replay") || HAS_TRAIT_FROM(body, TRAIT_IMMOBILIZED, "sandy_replay") || HAS_TRAIT_FROM(body, TRAIT_INCAPACITATED, "sandy_replay")
+
+/// `thing`'s own look while its replay waits to start: without the replay's hide (sandy_replay_pending_hide), which is
+/// the replay's, not the thing's
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/real_look(atom/movable/thing)
+ if(!thing.filter_data?["sandy_replay_pending_hide"])
+ return thing.appearance
+ var/mutable_appearance/look = new(thing)
+ look.filters = null
+ for(var/name in thing.filter_data)
+ if(name == "sandy_replay_pending_hide")
+ continue
+ var/list/arguments = thing.filter_data[name]
+ arguments = arguments.Copy()
+ arguments -= "priority"
+ look.filters += filter(arglist(arguments))
+ return look.appearance
+
+/// Names what differs between `thing`'s look now and the appearance `was`
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/look_difference(atom/movable/thing, was)
+ var/mutable_appearance/now = new(thing)
+ var/mutable_appearance/before = new(was)
+ var/list/found = list()
+ for(var/name in list("icon", "icon_state", "pixel_x", "pixel_y", "pixel_w", "pixel_z", "alpha", "layer", "plane", "invisibility", "mouse_opacity", "appearance_flags", "blend_mode", "name"))
+ if(now.vars[name] != before.vars[name])
+ found += "[name] [before.vars[name]] -> [now.vars[name]]"
+ if(!(now.color ~= before.color))
+ found += "color"
+ if(!(now.transform ~= before.transform))
+ found += "transform"
+ if(length(now.overlays) != length(before.overlays))
+ found += "overlays [length(before.overlays)] -> [length(now.overlays)]"
+ if(length(now.underlays) != length(before.underlays))
+ found += "underlays [length(before.underlays)] -> [length(now.underlays)]"
+ if(length(now.filters) != length(before.filters))
+ var/list/had = list()
+ for(var/dm_filter/filter as anything in before.filters)
+ had += "[filter.type]"
+ var/list/has = list()
+ for(var/dm_filter/filter as anything in now.filters)
+ has += "[filter.type]"
+ found += "filters [length(before.filters)] ([had.Join("/")]) -> [length(now.filters)] ([has.Join("/")]), filter names now: [jointext(assoc_to_keys(thing.filter_data), "/")]"
+ return length(found) ? found.Join(", ") : "nothing in the vars compared"
+
+/// A slow-mo the user ends replays from frame 0 on the real things, without moving them, and every one of them
+/// ends exactly as it really was. Changes made to them mid-replay land on their real look.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/plays_and_restores
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/plays_and_restores/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayuser")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/mob/living/carbon/human/npc/bleeder = allocate(/mob/living/carbon/human/npc, spot(4, 0))
+ var/mob/living/carbon/human/npc/victim = allocate(/mob/living/carbon/human/npc, spot(4, 2))
+ var/obj/item/wrench/wrench = allocate(/obj/item/wrench, spot(1, 1))
+ var/obj/item/crowbar/still = allocate(/obj/item/crowbar, spot(1, 2))
+ var/obj/structure/table/table = allocate(/obj/structure/table, spot(3, 2))
+ var/datum/sandy_replay/replay = start_recording(user)
+ TEST_ASSERT(replay.tracks[raider] && replay.tracks[wrench] && replay.tracks[table] && replay.tracks[user], "The recording missed things in the field")
+
+ // The window: the user steps, an NPC is moved, one bleeds, one loses its head and dies, a thing is made, one is made and deleted.
+ sleep(0.6 SECONDS)
+ user.Move(spot(0, 1), NORTH)
+ raider.forceMove(spot(3, 0))
+ wrench.forceMove(spot(2, 2))
+ bleeder.cause_wound_of_type_and_severity(WOUND_SLASH, bleeder.get_bodypart(BODY_ZONE_CHEST), WOUND_SEVERITY_SEVERE)
+ var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD)
+ head.dismember()
+ victim.death()
+ var/obj/item/screwdriver/made = allocate(/obj/item/screwdriver, spot(3, 1))
+ var/obj/item/pen/spent = new(spot(1, 0))
+ playsound(spot(2, 1), 'sound/items/weapons/genhit1.ogg', 50, FALSE)
+ sleep(0.6 SECONDS)
+ qdel(spent)
+ sleep(0.3 SECONDS)
+ TEST_ASSERT(replay.tracks[made], "Something made mid-window wasn't recorded")
+
+ // The second press: the slow-mo's looks come off, and that is everything's real final state.
+ press_again(user)
+ TEST_ASSERT_EQUAL(replay.state, 2, "Ending the slow-mo didn't queue the replay")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't wait for the replay")
+ var/list/things = list(user, raider, bleeder, victim, wrench, still, table, made)
+ // A head still flying (a throw, or hyperviolence's tumble) really lands during the replay, and its roll on landing
+ // moves its pixel_x 6 px (hv_vis_roll() in hyperviolence/visuals/flying_gore.dm): a real change, not the replay's.
+ var/head_in_flight = !QDELETED(head) && (!!head.throwing || !!head.GetComponent(/datum/component/hv_tumble))
+ var/head_x = QDELETED(head) ? null : head.pixel_x
+ if(!QDELETED(head) && !head_in_flight)
+ things += head
+ log_test("replay/plays_and_restores: severed head [QDELETED(head) ? "gone" : (head_in_flight ? "still in flight at the release, left out of the exact check" : "at rest, checked")]")
+ var/list/real = list()
+ var/list/real_spot = list()
+ var/list/real_dir = list()
+ for(var/atom/movable/thing as anything in things)
+ real[thing] = real_look(thing)
+ real_spot[thing] = thing.loc
+ real_dir[thing] = thing.dir
+ var/raider_overlays = length(raider.overlays)
+ // Not in the slow-mo, but near the user: it holds still for the replay too.
+ var/mob/living/carbon/human/npc/outsider = allocate(/mob/living/carbon/human/npc, spot(5, 1))
+
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ // Frame 0: drawn back where they started, standing on the tiles they ended on.
+ for(var/atom/movable/thing as anything in things)
+ TEST_ASSERT_EQUAL(thing.loc, real_spot[thing], "The replay moved [thing] for real")
+ TEST_ASSERT(GLOB.sandy_replay_masked[user] && GLOB.sandy_replay_masked[raider] && GLOB.sandy_replay_masked[wrench] && GLOB.sandy_replay_masked[victim], "Things that changed aren't replayed")
+ TEST_ASSERT(!GLOB.sandy_replay_masked[still] && !GLOB.sandy_replay_masked[table], "Things that never changed are replayed (the slow-mo's tint wasn't taken out of the recording cleanly)")
+ TEST_ASSERT_EQUAL(user.pixel_z, -32, "The user isn't drawn back on their first tile")
+ TEST_ASSERT_EQUAL(raider.pixel_w, -32, "The NPC isn't drawn back on its first tile")
+ TEST_ASSERT_EQUAL(wrench.pixel_w - initial(wrench.pixel_w), -32, "The item isn't drawn back on its first tile")
+ TEST_ASSERT_EQUAL(made.alpha, 0, "Something made mid-window shows at frame 0")
+ var/datum/sandy_replay_track/victim_track = replay.tracks[victim]
+ TEST_ASSERT(victim.appearance != real[victim], "The corpse's first frame is its last")
+ TEST_ASSERT(length(victim_track.frames) > 6, "The corpse has one frame")
+ TEST_ASSERT(length(replay.standins) >= 1, "Something deleted mid-window has no stand-in")
+ TEST_ASSERT(HAS_TRAIT_FROM(user, TRAIT_IMMOBILIZED, "sandy_replay") && HAS_TRAIT_FROM(user, TRAIT_INCAPACITATED, "sandy_replay"), "The user can act during the replay")
+ TEST_ASSERT(HAS_TRAIT_FROM(raider, TRAIT_AI_PAUSED, "sandy_replay"), "The NPC's AI runs during the replay")
+ TEST_ASSERT(HAS_TRAIT_FROM(outsider, TRAIT_AI_PAUSED, "sandy_replay"), "An NPC near the user but outside the slow-mo acts during the replay")
+ TEST_ASSERT(!raider.IsStun() && !user.IsStun(), "The replay stunned someone")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash started during the replay")
+
+ // Mid-replay: the game changes puppets. Through wrapped procs (an overlay, a lying turn) and by a plain var write.
+ sleep(0.1 SECONDS)
+ var/mutable_appearance/mark = mutable_appearance('icons/effects/effects.dmi', "shield-old")
+ raider.add_overlay(mark)
+ raider.set_lying_angle(90)
+ wrench.alpha = 128
+ TEST_ASSERT(GLOB.sandy_replay_masked[raider], "A change to a puppet ended its replay")
+
+ wait_over(user)
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The replay didn't play")
+ TEST_ASSERT_EQUAL(length(GLOB.sandy_replay_masked), 0, "Puppets are left after the replay")
+ for(var/atom/movable/thing as anything in things)
+ TEST_ASSERT_EQUAL(thing.loc, real_spot[thing], "[thing] isn't where it really ended")
+ TEST_ASSERT_EQUAL(thing.dir, real_dir[thing], "[thing] isn't facing the way it really ended")
+ if(thing == raider || thing == wrench || thing == user) // changed mid-replay below; the user wears the crash now
+ continue
+ TEST_ASSERT(thing.appearance == real[thing], "[thing] doesn't look exactly as it really ended: [look_difference(thing, real[thing])]")
+ // The changes made mid-replay are on the real looks, and nothing else is.
+ TEST_ASSERT_EQUAL(length(raider.overlays), raider_overlays + 1, "An overlay added mid-replay was lost, or others were")
+ TEST_ASSERT_EQUAL(raider.lying_angle, 90, "The lying turn didn't hold")
+ var/mutable_appearance/raider_was = new(real[raider])
+ var/matrix/upright = matrix(raider_was.transform)
+ TEST_ASSERT(!(raider.transform ~= upright), "A lying turn made mid-replay isn't on the real body")
+ TEST_ASSERT_EQUAL(raider.pixel_w, raider_was.pixel_w, "The NPC is left drawn off its tile")
+ TEST_ASSERT(user.pixel_w == 0 && user.pixel_z == 0 && user.alpha == 255, "The user is left drawn off their tile or hidden")
+ TEST_ASSERT(user.transform ~= matrix(), "The user is left turned or scaled")
+ TEST_ASSERT_EQUAL(user.mouse_opacity, initial(user.mouse_opacity), "The user can't be clicked after the replay")
+ TEST_ASSERT_EQUAL(wrench.alpha, 128, "A var written mid-replay was lost")
+ TEST_ASSERT_EQUAL(wrench.pixel_w, initial(wrench.pixel_w), "The item is left drawn off its tile")
+ TEST_ASSERT_EQUAL(wrench.mouse_opacity, initial(wrench.mouse_opacity), "The item can't be clicked after the replay")
+ // The wrench's alpha is one change no wrapper sees. A head still tumbling at the release lands mid-replay, and its
+ // bounce and roll (hv_vis_roll(), flying_gore.dm) write its pixel offsets directly: that may be another. Nothing
+ // else may be.
+ var/list/folded = GLOB.sandy_replay_last["folded"]
+ log_test("replay/plays_and_restores: head pixel_x [head_x] at the release, [QDELETED(head) ? "gone" : head.pixel_x] after; changes no wrapper saw: [folded.Join("; ")]")
+ var/wrench_changes = 0
+ for(var/change in folded)
+ if(findtext(change, "[/obj/item/wrench]:") == 1)
+ wrench_changes++
+ else
+ TEST_ASSERT(head_in_flight && findtext(change, "[/obj/item/bodypart/head]") == 1, "A puppet read as changed when nothing changed it: [change]")
+ TEST_ASSERT_EQUAL(wrench_changes, 1, "The var written on the wrench mid-replay wasn't seen once")
+ TEST_ASSERT(!held(user) && !held(raider) && !held(bleeder) && !held(outsider), "Someone is still held after the replay")
+ TEST_ASSERT(!(locate(/obj/effect/abstract/sandy_replay_standin) in range(9, user)), "A stand-in outlived the replay")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land when the replay ended")
+ // It looks and sounds like a surge: the user's step left an afterimage, and the sound made in the field played again.
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= 1, "The user's step in the replay left no afterimage")
+ TEST_ASSERT(GLOB.sandy_replay_last["sounds"] >= 1, "A sound made in the field wasn't recorded")
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["sounds_played"], GLOB.sandy_replay_last["sounds"], "The recorded sounds didn't all play in the replay")
+
+/// A slow-mo that runs out replays by itself, and the watchdog ends a replay whose frames stopped coming
+/datum/unit_test/voidcrew_cyberware_timestop/replay/watchdog
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/watchdog/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaywatch")
+ set_window(user, 1 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.4 SECONDS)
+ raider.forceMove(spot(3, 0))
+ var/until = world.time + 3 SECONDS
+ while(replay.state != 3 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "A slow-mo that ran out didn't replay")
+ TEST_ASSERT(GLOB.sandy_replay_masked[raider], "The NPC that moved isn't replayed")
+ var/datum/sandy_replay_track/raider_track = replay.tracks[raider]
+ var/mutable_appearance/real = new(raider_track.saved_look)
+ deltimer(replay.play_timer) // the frames stop coming
+ replay.play_timer = null
+ var/stalled_at = world.time
+ wait_over(user)
+ TEST_ASSERT(world.time - stalled_at >= 1 SECONDS, "The stalled replay ended before the watchdog could have ended it")
+ TEST_ASSERT(!held(user) && !held(raider), "Someone is still held after the watchdog ended the replay")
+ TEST_ASSERT_EQUAL(raider.pixel_w, real.pixel_w, "The NPC is left drawn off its tile")
+ TEST_ASSERT_EQUAL(length(GLOB.sandy_replay_masked), 0, "Puppets are left after the watchdog ended the replay")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land when the watchdog ended the replay")
+
+/// A player who isn't crew coming near ends the replay at once
+/datum/unit_test/voidcrew_cyberware_timestop/replay/player_arrives
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/player_arrives/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayalone")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(1 SECONDS)
+ raider.forceMove(spot(3, 0))
+ sleep(0.5 SECONDS)
+ press_again(user)
+ var/real = real_look(raider)
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT_EQUAL(raider.pixel_w, -32, "The NPC isn't replayed")
+ var/mob/living/carbon/human/stranger = allocate(/mob/living/carbon/human/consistent, spot(1, 2))
+ stranger.key = "sandyreplaystranger"
+ replay.play_frame()
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay went on with another player near")
+ TEST_ASSERT(raider.appearance == real, "The NPC didn't snap back to its real look: [look_difference(raider, real)]")
+ TEST_ASSERT(!held(user) && !held(raider), "Someone is still held after a player ended the replay")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land when a player ended the replay")
+
+/// A slow-mo another player cut short doesn't replay
+/datum/unit_test/voidcrew_cyberware_timestop/replay/not_when_cut_short
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/not_when_cut_short/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaycut")
+ set_window(user, 1.5 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ start_recording(user)
+ raider.forceMove(spot(3, 0))
+ var/mob/living/carbon/human/stranger = allocate(/mob/living/carbon/human/consistent, spot(1, 2))
+ stranger.key = "sandyreplaycutter"
+ sleep(0.5 SECONDS) // the field's next tick sees them
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "A slow-mo cut short by a player kept its recording")
+ sleep(1.5 SECONDS) // past the end of the window
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_window), "Test fixture: the window should be over")
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "A slow-mo cut short by a player replayed")
+ TEST_ASSERT_EQUAL(length(GLOB.sandy_replay_masked), 0, "A slow-mo cut short by a player made puppets")
+ TEST_ASSERT(!held(user) && !held(raider), "Someone is held with no replay")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land at the end of the window")
+
+/// The user dying in the window is replayed too: their body isn't locked, and no crash follows
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_dies
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_dies/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaydead")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.5 SECONDS)
+ user.Move(spot(0, 1), NORTH)
+ sleep(0.5 SECONDS)
+ user.death() // ends the slow-mo there and then; the replay starts a tick later
+ TEST_ASSERT_EQUAL(replay.state, 2, "The slow-mo of a user who died didn't end at death with its replay queued")
+ deltimer(replay.begin_timer)
+ var/real = user.appearance
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay of a user who died didn't start")
+ TEST_ASSERT(GLOB.sandy_replay_masked[user], "The dead user's body isn't replayed")
+ TEST_ASSERT_EQUAL(user.pixel_z, -32, "The dead user isn't drawn back on their first tile")
+ TEST_ASSERT(user.appearance != real, "The dead user isn't drawn alive at frame 0")
+ TEST_ASSERT(!held(user), "A dead user was input-locked")
+ wait_over(user)
+ TEST_ASSERT(user.appearance == real, "The dead user's body doesn't look as it really ended")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A dead user crashed")
+
+/// A user who goes into crit in the window is replayed upright from their first tile and goes down at the frame they
+/// went down, and after the replay is exactly as they really are: still down, still in crit, not held
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_crit
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_crit/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaycrit")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.5 SECONDS)
+ user.Move(spot(0, 1), NORTH)
+ sleep(0.5 SECONDS)
+ user.apply_damage(user.health - user.crit_threshold + 10, BRUTE, BODY_ZONE_CHEST)
+ TEST_ASSERT_EQUAL(user.stat, SOFT_CRIT, "Test fixture: the user should be in soft crit")
+ TEST_ASSERT_EQUAL(user.body_position, LYING_DOWN, "Test fixture: a user in crit should be lying down")
+ sleep(0.3 SECONDS)
+ TEST_ASSERT_EQUAL(replay.state, 1, "Crit ended the slow-mo")
+ press_again(user)
+ deltimer(replay.begin_timer)
+ var/real = user.appearance
+ var/real_angle = user.lying_angle
+ var/matrix/real_turn = matrix(user.transform)
+ TEST_ASSERT(!(real_turn ~= matrix()), "Test fixture: a user lying in crit should be turned")
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay of a user in crit didn't start")
+ TEST_ASSERT(GLOB.sandy_replay_masked[user], "The user in crit isn't replayed")
+ TEST_ASSERT_EQUAL(user.pixel_z, -32, "The user in crit isn't drawn back on their first tile")
+ TEST_ASSERT(user.transform ~= matrix(), "The user in crit isn't drawn upright at frame 0")
+ var/down_at = 0
+ var/until = world.time + 5 SECONDS
+ while(GLOB.sandy_replays[user] && world.time < until)
+ if(!down_at && !(user.transform ~= matrix()))
+ down_at = world.time
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay never ended")
+ TEST_ASSERT(down_at > replay.play_started, "The user in crit never goes down in their replay, or is down from its first frame")
+ // the crash lands when the replay ends and plays its node looks, so the whole appearance can't match; compare the
+ // parts the replay drew over
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "Test fixture: the crash should land on a user in crit")
+ var/difference = look_difference(user, real)
+ TEST_ASSERT(difference == "nothing in the vars compared", "The user in crit doesn't look as they really are after the replay: [difference]")
+ TEST_ASSERT(user.transform ~= real_turn, "The user in crit isn't turned as they really lie after the replay")
+ TEST_ASSERT_EQUAL(user.stat, SOFT_CRIT, "The replay changed the user's stat")
+ TEST_ASSERT_EQUAL(user.body_position, LYING_DOWN, "The user in crit stood up after the replay")
+ TEST_ASSERT_EQUAL(user.lying_angle, real_angle, "The user in crit's lying angle changed over the replay")
+ TEST_ASSERT(!held(user), "The user in crit is still held after the replay")
+
+/// A user knocked down in the window whose knockdown wears off during the replay gets up once it ends: the replay's
+/// input lock fails tg's get-up while it plays
+/datum/unit_test/voidcrew_cyberware_timestop/replay/gets_up_after
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/gets_up_after/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayknock")
+ set_window(user, 3 SECONDS)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ lattice.crash_stamina = 0 // the crash's stamina dump would floor them again
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.5 SECONDS)
+ user.Paralyze(20 SECONDS)
+ TEST_ASSERT_EQUAL(user.body_position, LYING_DOWN, "Test fixture: a paralyzed user should be lying down")
+ sleep(0.3 SECONDS)
+ press_again(user)
+ deltimer(replay.begin_timer)
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ user.SetParalyzed(0) // wears off mid-replay
+ TEST_ASSERT_EQUAL(user.body_position, LYING_DOWN, "Test fixture: the replay's lock should keep the user from getting up while it plays")
+ wait_over(user)
+ var/until = world.time + 3 SECONDS
+ while(user.body_position == LYING_DOWN && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(user.body_position, STANDING_UP, "A user whose knockdown wore off during the replay never got up after it")
+ TEST_ASSERT_EQUAL(user.lying_angle, 0, "The user got up but is still turned")
+
+/// A crit body for an execution to be done on, `dx`, `dy` from the room's corner
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/make_victim(dx, dy)
+ var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent, spot(dx, dy))
+ victim.adjustOxyLoss(120)
+ TEST_ASSERT(victim.hv_is_helpless(), "Test fixture: the victim isn't down")
+ return victim
+
+/// The user's own look on a replay frame: never hidden. A finisher rig's hide only while a stand-in of one of the
+/// rig's pictures is drawn in their place.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/check_seen(mob/living/user, datum/sandy_replay/replay)
+ var/datum/sandy_replay_track/track = replay.tracks[user]
+ if(!track || track.cursor < 0 || !GLOB.sandy_replay_masked[user])
+ return
+ TEST_ASSERT(user.alpha > 0 && user.invisibility < INVISIBILITY_ABSTRACT, "The user is drawn hidden on replay frame [track.frames[track.cursor + 1]]")
+ if(!user.filter_data?["chrome_rig_hide"] && !user.filter_data?["mantis_rig_hide"])
+ return
+ var/pictures = 0
+ for(var/datum/sandy_replay_track/standin_track as anything in replay.standins)
+ if(standin_track.standin?.loc && length(standin_track.events))
+ pictures++
+ TEST_ASSERT(pictures, "The user's puppet wears a rig's hide with no rig picture drawn for it on replay frame [track.frames[track.cursor + 1]]")
+
+/// No progress bar is drawn while a replay plays (owner, 2026-11-12): no execution bar near the user, and no do_after
+/// bar image on the user's screen.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/check_no_bars(mob/living/user)
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ if(!replay || replay.state != 3)
+ return
+ for(var/obj/effect/abstract/hv_exec_bar/bar as anything in GLOB.hv_exec_bars)
+ TEST_ASSERT(bar.invisibility >= INVISIBILITY_ABSTRACT || get_dist(bar, user) > 11, "An execution bar shows during the replay")
+ for(var/target in user.progressbars)
+ for(var/datum/progressbar/progress as anything in user.progressbars[target])
+ TEST_ASSERT(!progress.user_client || !(progress.bar in progress.user_client.images), "A progress bar shows on the user's screen during the replay")
+
+/// Whether `user` sees the surge's own screen colour
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/surge_tinted(mob/living/user)
+ return !!user.get_client_colour("cyberware_cascade_window")
+
+/// `user`'s surge window
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/window_of(mob/living/user)
+ return user.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/**
+ * A gun execution in its wind-up when the slow-mo is asked to end (its time is up, or a second press; playtest bug
+ * 2026-11-12): the slow-mo holds, with the user's edge glow on, until the shot goes off for real, then ends and
+ * replays. Nobody is held while it holds. The user is never hidden in the replay, sees no surge colour during or
+ * after it, and is left exactly where and as they really are; the crash lands after.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/execution_running_at_end
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/execution_running_at_end/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 1), "sandyreplayexec")
+ set_window(user, 4 SECONDS)
+ var/mob/living/carbon/human/victim = make_victim(1, 0)
+ // An execution round goes through tg's hit-zone roll (projectile.dm, ran_zone at 93% a tile away): about one in
+ // fifteen lands on another limb and does nothing to the head. That is the execution's own problem, not the slow-mo's.
+ ADD_TRAIT(victim, TRAIT_DESIGNATED_TARGET, "sandy_replay_test")
+ var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ TEST_ASSERT(user.put_in_active_hand(pistol), "Test fixture: the pistol wouldn't go in the user's hand")
+ user.zone_selected = BODY_ZONE_HEAD
+ var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD)
+ var/head_brute = head.brute_dam
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ sleep(0.6 SECONDS)
+ user.Move(spot(0, 0), SOUTH) // off the tile the replay starts on: its puppet is drawn a tile up
+ sleep(0.3 SECONDS)
+ user.face_atom(victim)
+ INVOKE_ASYNC(pistol, TYPE_PROC_REF(/obj/item/gun, hv_start_execution), user, victim, null)
+ sleep(0.4 SECONDS)
+ TEST_ASSERT(sandy_replay_mid_move(user), "The wind-up isn't seen as a move in progress")
+
+ var/asked = world.time
+ window.slowmo_time_up() // what its time running out and a second press both do
+ sleep(world.tick_lag)
+ TEST_ASSERT_NOTNULL(window.time_stop, "The slow-mo ended in the middle of the user's execution")
+ TEST_ASSERT(window.hold_until, "The slow-mo isn't holding for the execution")
+ TEST_ASSERT(user.filter_data?["sandy_time_stop_outline"], "The user's edge glow went off while the slow-mo holds")
+ TEST_ASSERT_EQUAL(replay.state, 1, "The recording stopped while the slow-mo holds")
+ TEST_ASSERT(!held(user), "The user is held while their execution plays out")
+ TEST_ASSERT(!surge_tinted(user), "The surge's colour is on the user's screen in the slow-mo")
+ var/until = world.time + 7 SECONDS
+ while(replay.state == 1 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(!QDELETED(replay) && replay.state >= 2, "The slow-mo never ended after the execution, or nothing replayed")
+ TEST_ASSERT(world.time - asked <= 6.5 SECONDS, "The hold ran past its cap")
+ TEST_ASSERT(!sandy_replay_mid_move(user), "The slow-mo ended before the execution did")
+ head = victim.get_bodypart(BODY_ZONE_HEAD)
+ TEST_ASSERT(!head || head.brute_dam > head_brute, "The execution didn't go off")
+ TEST_ASSERT(!window_of(user), "The surge window outlived the slow-mo it held")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't wait for the replay")
+ while(replay.state != 3 && GLOB.sandy_replays[user] && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay never played after the execution")
+ // Frame 0 has the user a tile up, never hidden. Then every frame to the end, with no surge colour.
+ TEST_ASSERT_EQUAL(user.pixel_z, 32, "The user isn't drawn back on their first tile")
+ while(GLOB.sandy_replays[user] && world.time < until + 8 SECONDS)
+ check_seen(user, replay)
+ TEST_ASSERT(!surge_tinted(user), "The surge's colour is on the user's screen during the replay")
+ check_no_bars(user)
+ sleep(world.tick_lag)
+ wait_over(user)
+ TEST_ASSERT(!surge_tinted(user), "The surge's colour is on the user's screen after the replay")
+ TEST_ASSERT(user.pixel_w == user.base_pixel_w && user.pixel_z == user.base_pixel_z, "The user is left drawn off their tile: [user.pixel_w],[user.pixel_z]")
+ TEST_ASSERT(user.pixel_x == user.base_pixel_x && user.pixel_y == user.base_pixel_y, "The user is left shifted: [user.pixel_x],[user.pixel_y]")
+ TEST_ASSERT(user.alpha == 255 && user.invisibility == initial(user.invisibility), "The user is left hidden")
+ TEST_ASSERT(user.transform ~= matrix(), "The user is left turned or scaled")
+ TEST_ASSERT(!held(user), "The user is still held after the replay")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land when the replay ended")
+
+/**
+ * A move still going when the hold's cap runs out: the slow-mo ends without a replay (the replay's hold would cut the
+ * move short), the move isn't touched, and the crash lands. Asking again while it holds changes nothing.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_capped
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_capped/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaycap")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ // A rig's hide is what marks a move in progress that has no status of its own (the impale, the slam)
+ user.add_filter("chrome_rig_hide", 1, color_matrix_filter(list(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
+ TEST_ASSERT(sandy_replay_mid_move(user), "Test fixture: the user isn't mid-move")
+ var/asked = world.time
+ window.slowmo_time_up()
+ TEST_ASSERT(window.hold_until, "The slow-mo isn't holding for the move")
+ TEST_ASSERT(window.hold_until - asked <= 6 SECONDS, "The hold's cap is [window.hold_until - asked] ds")
+ window.slowmo_time_up() // asked again (a second press) while holding: still holding
+ TEST_ASSERT_NOTNULL(window.time_stop, "A second ask ended a holding slow-mo")
+ var/until = world.time + 8 SECONDS
+ while(window_of(user) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(!window_of(user), "The hold never ended")
+ TEST_ASSERT(world.time - asked >= 6 SECONDS - world.tick_lag, "The hold ended before its cap with the move still going")
+ TEST_ASSERT(world.time - asked <= 6.5 SECONDS, "The hold ran past its cap")
+ TEST_ASSERT(QDELETED(replay) && !GLOB.sandy_replays[user], "A slow-mo that ended on its cap replayed")
+ TEST_ASSERT(user.filter_data?["chrome_rig_hide"], "Ending the slow-mo touched the move")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't land")
+ TEST_ASSERT(!surge_tinted(user), "The surge's colour stayed on the user's screen")
+ user.remove_filter("chrome_rig_hide")
+
+/**
+ * A rig move done inside the slow-mo is replayed: its posed pictures are recorded and drawn as stand-ins, with the
+ * animations that posed them played again, and the user's puppet wears the rig's hide only while they are. In the
+ * slow-mo the user's pictures carry the edge glow. And tg's offsets set on a puppet mid-replay (a finisher letting
+ * go, a grab) land on the real body, not on the puppet's shift: nothing is left drawn off its tile.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/rig_move_inside
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/rig_move_inside/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 1), "sandyreplayrig")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ sleep(0.6 SECONDS)
+ user.Move(spot(0, 0), SOUTH)
+ var/datum/chrome_rig/rig = new(user, EAST)
+ TEST_ASSERT(rig.snapshot(), "Test fixture: the rig couldn't picture the user")
+ rig.rig_arms()
+ rig.conceal()
+ TEST_ASSERT(user.filter_data?["chrome_rig_hide"], "Test fixture: the rig didn't hide the user")
+ TEST_ASSERT(sandy_replay_mid_move(user), "A rigged body isn't seen as mid-move")
+ var/side = rig.near_side()
+ var/obj/effect/abstract/chrome_puppet/arm = rig.puppet("arm_[side]") // the rig keys its arms "arm_l" and "arm_r" (rig_arms())
+ TEST_ASSERT_NOTNULL(arm, "Test fixture: the rig has no arm")
+ TEST_ASSERT(replay.tracks[arm], "The rig's picture isn't recorded")
+ TEST_ASSERT(locate(/obj/effect/abstract/sandy_rig_glow) in arm.vis_contents, "The user's rig picture has no edge glow in the slow-mo")
+ var/journaled = replay.journaled
+ rig.swing_arm(side, 90, 0.4 SECONDS)
+ TEST_ASSERT(replay.journaled > journaled, "The rig's swing wasn't journaled for the replay")
+ sleep(0.5 SECONDS)
+ qdel(rig)
+ sleep(0.3 SECONDS)
+ window.slowmo_time_up()
+ TEST_ASSERT_EQUAL(replay.state, 2, "A finished move held the slow-mo")
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT_EQUAL(user.pixel_z, 32, "The user isn't drawn back on their first tile")
+ // tg's offsets on the puppet (a finisher's lean, then letting go), as a cut-short move would
+ user.add_offsets("sandy_replay_test", null, 6, 4)
+ sleep(world.tick_lag)
+ user.remove_offsets("sandy_replay_test")
+ var/saw_swing = FALSE
+ var/until = world.time + 5 SECONDS
+ while(GLOB.sandy_replays[user] && world.time < until)
+ check_seen(user, replay)
+ for(var/datum/sandy_replay_track/track as anything in replay.standins)
+ if(track.standin?.loc && track.event_at > 1)
+ saw_swing = TRUE
+ sleep(world.tick_lag)
+ wait_over(user)
+ TEST_ASSERT(saw_swing, "The rig's pictures and their swing weren't played in the replay")
+ TEST_ASSERT(user.pixel_w == user.base_pixel_w && user.pixel_z == user.base_pixel_z, "Offsets set mid-replay left the user drawn off their tile: [user.pixel_w],[user.pixel_z]")
+ TEST_ASSERT(user.pixel_x == user.base_pixel_x && user.pixel_y == user.base_pixel_y, "Offsets set mid-replay left the user shifted: [user.pixel_x],[user.pixel_y]")
+ TEST_ASSERT(!user.filter_data?["chrome_rig_hide"] && user.alpha == 255, "The user is left hidden")
+
+/**
+ * An execution early in the slow-mo, then more happens in it (owner, 2026-11-12: "if an execution isn't the same
+ * speed, we won't get the whole replay if something happens after"). The slow-mo doesn't hold for a move that's over,
+ * the recording runs on at the slow-mo's own rate after the move, the replay shows what came after the move after
+ * the move's frames, ends on its own well before its watchdog, holds the user for exactly its length, and leaves
+ * everything as it really is.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/after_execution
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/after_execution/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayafter")
+ set_window(user, 5 SECONDS)
+ var/mob/living/carbon/human/victim = make_victim(1, 0)
+ var/mob/living/carbon/human/bystander = allocate(/mob/living/carbon/human/consistent, spot(3, 0))
+ var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ TEST_ASSERT(user.put_in_active_hand(pistol), "Test fixture: the pistol wouldn't go in the user's hand")
+ user.zone_selected = BODY_ZONE_HEAD
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ user.face_atom(victim)
+ INVOKE_ASYNC(pistol, TYPE_PROC_REF(/obj/item/gun, hv_start_execution), user, victim, null)
+ sleep(world.tick_lag)
+ TEST_ASSERT(sandy_replay_mid_move(user), "The wind-up isn't seen as a move in progress")
+ var/until = world.time + 4 SECONDS
+ while(sandy_replay_mid_move(user) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(!sandy_replay_mid_move(user), "The execution never ended")
+ TEST_ASSERT_EQUAL(replay.state, 1, "The recording stopped when the execution ended")
+ TEST_ASSERT(window_of(user) && !window.hold_until, "The slow-mo ended, or held, for an execution that was already over")
+ var/move_over = replay.frame_now()
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(bystander.Move(spot(3, 1), NORTH), "Test fixture: the bystander couldn't step")
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(replay.frame_now() - move_over <= round(1 SECONDS / replay.interval) + 2, "The recording didn't go back to the slow-mo's rate after the execution")
+ until = world.time + 6 SECONDS
+ while(replay.state == 1 && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(replay.state >= 2, "The slow-mo never ended")
+ TEST_ASSERT(!window.hold_until, "The slow-mo held at its end with no move going")
+ // The bystander's step is in the recording, after the execution's frames.
+ var/datum/sandy_replay_track/track = replay.tracks[bystander]
+ TEST_ASSERT_NOTNULL(track, "The bystander wasn't recorded")
+ var/stepped_at = -1
+ var/turf/stepped_to = spot(3, 1)
+ for(var/i in 1 to length(track.frames) step 6)
+ if(track.frames[i + 2] == stepped_to.x && track.frames[i + 3] == stepped_to.y)
+ stepped_at = track.frames[i]
+ break
+ TEST_ASSERT(stepped_at > move_over, "The step after the execution isn't in the recording after it (frame [stepped_at], move over at [move_over])")
+ while(replay.state != 3 && GLOB.sandy_replays[user] && world.time < until + 1 SECONDS)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay never played")
+ var/play_started = world.time
+ var/total = replay.total
+ TEST_ASSERT(held(user), "The user isn't held for the replay")
+ while(GLOB.sandy_replays[user] && world.time < play_started + 15 SECONDS)
+ if(world.time - play_started < (total - 1) * world.tick_lag)
+ TEST_ASSERT(held(user), "The user was let go before the replay was over")
+ check_no_bars(user)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay never ended")
+ TEST_ASSERT(world.time - play_started <= (total + 2) * world.tick_lag + 0.2 SECONDS, "The replay was ended by its watchdog, not by playing out ([world.time - play_started] for [total] frames)")
+ TEST_ASSERT(GLOB.sandy_replay_last["played"], "Nothing replayed")
+ TEST_ASSERT(!held(user), "The user is still held after the replay")
+ TEST_ASSERT_EQUAL(get_turf(bystander), stepped_to, "The bystander isn't where they really are")
+ TEST_ASSERT(bystander.pixel_w == bystander.base_pixel_w && bystander.pixel_z == bystander.base_pixel_z, "The bystander is left drawn off their tile")
+ TEST_ASSERT(bystander.alpha == 255, "The bystander is left hidden")
+ TEST_ASSERT(user.pixel_w == user.base_pixel_w && user.pixel_z == user.base_pixel_z && user.alpha == 255, "The user is left drawn off their tile or hidden")
+
+/// Fires a harmless bullet from `from` at `target`, by `firer`
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/fire_shot(turf/from, mob/living/firer, atom/target)
+ var/obj/projectile/bullet/shot = new(from)
+ shot.damage = 0
+ shot.stamina = 0
+ shot.firer = firer
+ shot.fired_from = firer
+ shot.aim_projectile(target, from)
+ shot.fire()
+ return shot
+
+/// Whether a replay stand-in is anywhere near `user`
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/standin_near(mob/living/user)
+ for(var/obj/effect/abstract/sandy_replay_standin/standin in range(8, user))
+ return TRUE
+ return FALSE
+
+/// The user's shot, fired and spent inside the slow-mo, is in the replay from the muzzle to the spot it hit, along its
+/// path, and gone after it: nothing is left behind.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_spent_inside
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_spent_inside/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayshot")
+ set_window(user, 4 SECONDS)
+ var/mob/living/carbon/human/npc/target = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/projectile/shot = fire_shot(spot(0, 0), user, target)
+ var/datum/sandy_replay_track/track = replay.tracks[shot]
+ TEST_ASSERT_NOTNULL(track, "The shot wasn't recorded")
+ TEST_ASSERT(track.flier, "The shot wasn't recorded as a shot")
+ var/until = world.time + 3.5 SECONDS
+ while(!QDELETED(shot) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(QDELETED(shot), "The shot never hit in the slow-mo")
+ TEST_ASSERT(track in replay.gone, "The spent shot isn't kept to be drawn")
+ var/list/frames = track.frames
+ var/count = length(frames) / 6
+ TEST_ASSERT(count >= 3, "The shot's flight has [count] frames")
+ TEST_ASSERT(track.last > frames[length(frames) - 5], "The spot the shot hit is never shown (last [track.last])")
+ var/prev = -INFINITY
+ for(var/i = 1, i <= length(frames), i += 6)
+ var/mutable_appearance/look = new(frames[i + 1])
+ var/at = frames[i + 2] * 32 + look.pixel_x
+ TEST_ASSERT(at >= prev, "The shot goes back on itself at frame [frames[i]]: [prev] -> [at]")
+ TEST_ASSERT(look.alpha > 0, "The shot is drawn invisible at frame [frames[i]]")
+ prev = at
+ TEST_ASSERT_EQUAL(frames[length(frames) - 3], target.x, "The shot's last frame isn't on the tile it hit")
+ press_again(user)
+ until = world.time + 2 SECONDS
+ while(replay.state != 3 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ var/drawn = 0
+ var/drawn_after = 0
+ while(!QDELETED(replay) && replay.state == 3)
+ var/frame = round((world.time - replay.play_started) / world.tick_lag)
+ if(track.standin?.loc)
+ drawn++
+ if(frame > track.last)
+ drawn_after++
+ sleep(world.tick_lag)
+ log_test("replay/shot_spent_inside: [count] frames, first [track.first], last [track.last], drawn [drawn] ticks")
+ TEST_ASSERT(drawn >= count - 1, "The shot was drawn for [drawn] ticks of its [count] frames")
+ TEST_ASSERT_EQUAL(drawn_after, 0, "The shot was drawn after the frame it hit in")
+ wait_over(user)
+ TEST_ASSERT(!standin_near(user), "A stand-in is left after the replay")
+ TEST_ASSERT_EQUAL(length(GLOB.sandy_replay_masked), 0, "Puppets are left after the replay")
+
+/// A shot still flying when the slow-mo ends is drawn by itself (one shot, never two), held where the recording left
+/// it while the replay plays, and flies on from there after, with its own look back.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_flying_at_end
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_flying_at_end/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayflying")
+ set_window(user, 4 SECONDS)
+ var/mob/living/carbon/human/npc/gunman = allocate(/mob/living/carbon/human/npc, spot(1, 2))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/projectile/shot = fire_shot(spot(1, 2), gunman, spot(6, 2))
+ var/turf/fired_at = get_turf(shot)
+ sleep(0.8 SECONDS)
+ TEST_ASSERT(!QDELETED(shot), "The shot was gone before the slow-mo ended")
+ TEST_ASSERT(replay.tracks[shot], "The shot wasn't recorded")
+ press_again(user)
+ var/until = world.time + 2 SECONDS
+ while(replay.state != 3 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT(!QDELETED(shot), "The shot was gone before the replay")
+ var/datum/sandy_replay_track/track = replay.tracks[shot]
+ var/list/frames = track.frames
+ var/turf/held_at = get_turf(shot)
+ var/mutable_appearance/real_look = new(track.saved_look) // the shot is drawn from the recording now: its real look is kept aside
+ var/real_x = real_look.pixel_x
+ TEST_ASSERT(shot.paused && (shot in replay.held_shots), "The shot flies on while the replay plays")
+ TEST_ASSERT(GLOB.sandy_replay_masked[shot], "The shot isn't drawn from the recording")
+ TEST_ASSERT(held_at != fired_at, "The shot never moved in the slow-mo")
+ TEST_ASSERT(frames[length(frames) - 3] == held_at.x && frames[length(frames) - 2] == held_at.y, "The recording's last frame isn't where the shot is held")
+ var/standins = 0
+ while(!QDELETED(replay) && replay.state == 3)
+ TEST_ASSERT_EQUAL(get_turf(shot), held_at, "The shot moved during the replay")
+ if(standin_near(user))
+ standins++
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(standins, 0, "A second shot was drawn beside the real one")
+ wait_over(user)
+ TEST_ASSERT(!QDELETED(shot), "The shot was gone after the replay")
+ TEST_ASSERT(!shot.paused, "The shot is still held after the replay")
+ TEST_ASSERT(!GLOB.sandy_replay_masked[shot], "The shot is still drawn from the recording")
+ // Back on its real spot when the replay let it go; it may have flown on east since (it is not held any more), but
+ // never sits behind where it was held (a recorded frame left on it).
+ var/real_spot = held_at.x * ICON_SIZE_X + real_x
+ var/now_spot = shot.x * ICON_SIZE_X + shot.pixel_x
+ TEST_ASSERT(now_spot >= real_spot, "The shot isn't back on its real spot ([now_spot - real_spot] px)")
+ TEST_ASSERT(shot.pixel_w == 0 && shot.pixel_z == 0 && shot.alpha > 0, "The shot is left drawn off its spot, or hidden")
+ sleep(0.3 SECONDS)
+ TEST_ASSERT(QDELETED(shot) || get_turf(shot) != held_at, "The shot didn't fly on after the replay")
+ if(!QDELETED(shot))
+ qdel(shot)
+
+/**
+ * A finisher leaves a pose on a body past the slow-mo (the backbreaker's broken back) and cracks in the floor. While
+ * the replay plays, the pose left on the floor isn't drawn (the replay draws the move from its start), and as it ends
+ * the pose and the cracks are there again as they really are: the cracks still at their full strength.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/pose_left_and_cracks
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/pose_left_and_cracks/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaypose")
+ var/mob/living/carbon/human/victim = make_victim(1, 0)
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ sleep(0.4 SECONDS)
+ var/datum/chrome_rig/rig = new(victim, SOUTH)
+ TEST_ASSERT(rig.snapshot(), "Test fixture: the rig couldn't picture the victim")
+ var/obj/effect/abstract/chrome_puppet/pose = rig.add_puppet("pose", rig.cut_without_arms())
+ rig.conceal()
+ TEST_ASSERT(replay.tracks[pose], "The rig's picture isn't recorded")
+ // Handed over as the backbreaker does: a pose that lasts, not a move the slow-mo waits for
+ victim.AddComponent(/datum/component/gorilla_fold, rig, 1)
+ var/turf/open/floor/cracked = spot(1, 1)
+ TEST_ASSERT(isfloorturf(cracked), "Test fixture: no floor to crack")
+ var/obj/effect/temp_visual/cyberware_impact_cracks/cracks = new(cracked, "damaged1", 255)
+ TEST_ASSERT(!QDELETED(cracks) && replay.tracks[cracks], "The cracks aren't recorded")
+ sleep(0.3 SECONDS)
+ window.slowmo_time_up()
+ TEST_ASSERT_EQUAL(replay.state, 2, "A pose left on a body held the slow-mo")
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT(pose.invisibility >= INVISIBILITY_ABSTRACT, "The pose left on the body is drawn while the replay plays the move again")
+ wait_over(user)
+ TEST_ASSERT(!QDELETED(pose) && pose.invisibility == 0, "The pose left on the body isn't drawn again after the replay")
+ TEST_ASSERT(!QDELETED(cracks), "Test fixture: the cracks ran out before the replay ended")
+ // Their alpha var holds the end of the fade they are playing (0), so what can be checked is that the replay took the
+ // strength they were made with, which is what they are drawn at again when it ends
+ TEST_ASSERT_EQUAL(cracks.sandy_peak_alpha, 255, "The replay didn't take the strength the cracks were made with")
+ qdel(victim.GetComponent(/datum/component/gorilla_fold))
+
+/// A gun's muzzle flash (tg's, made inside the shooter and shown in their vis_contents) is recorded on the shooter's
+/// tile from the frame it was made in, so a replayed shot has its flash with it.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/muzzle_flash_recorded
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/muzzle_flash_recorded/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayflash")
+ set_window(user, 4 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/effect/temp_visual/dir_setting/firing_effect/flash = new(user, EAST)
+ var/datum/sandy_replay_track/track = replay.tracks[flash]
+ TEST_ASSERT_NOTNULL(track, "The muzzle flash wasn't recorded")
+ TEST_ASSERT(track.oneshot, "The muzzle flash wasn't recorded as a one-shot effect")
+ var/list/frames = track.frames
+ TEST_ASSERT(length(frames) >= 6, "The muzzle flash has no frame")
+ TEST_ASSERT_EQUAL(frames[1], track.first, "The muzzle flash's first frame isn't the frame it was made in")
+ TEST_ASSERT_EQUAL(frames[3], user.x, "The muzzle flash isn't drawn on the shooter's tile (x)")
+ TEST_ASSERT_EQUAL(frames[4], user.y, "The muzzle flash isn't drawn on the shooter's tile (y)")
+ TEST_ASSERT_EQUAL(frames[6], EAST, "The muzzle flash lost the way the shot went")
+ press_again(user)
+ wait_over(user)
+
+/// The plume a powder gun throws along the shot (made inside the shooter, turned to the shot's own angle) is recorded
+/// too, turned as it was: a replayed diagonal shot keeps it.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/muzzle_plume_recorded
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/muzzle_plume_recorded/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayplume")
+ set_window(user, 4 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/effect/temp_visual/gun_feel_muzzle_flash/plume = new(user, 135)
+ var/datum/sandy_replay_track/track = replay.tracks[plume]
+ TEST_ASSERT_NOTNULL(track, "The plume of a shot wasn't recorded")
+ var/list/frames = track.frames
+ TEST_ASSERT(length(frames) >= 6, "The plume has no frame")
+ TEST_ASSERT_EQUAL(frames[3], user.x, "The plume isn't drawn on the shooter's tile (x)")
+ TEST_ASSERT_EQUAL(frames[4], user.y, "The plume isn't drawn on the shooter's tile (y)")
+ var/mutable_appearance/look = new(frames[2])
+ var/matrix/turned = matrix()
+ turned.Turn(135)
+ TEST_ASSERT(gun_feel_same_matrix(look.transform, turned), "The recorded plume isn't turned along a south-east shot")
+ press_again(user)
+ wait_over(user)
+
+/// The slash a chrome weapon draws over someone hit lives only in that body's vis_contents: it is recorded on the
+/// body's tile, as a stand-in on the floor can draw it, and stays long enough in the replay to play through.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hit_picture_recorded
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hit_picture_recorded/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayslash")
+ var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent, spot(1, 0))
+ set_window(user, 4 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/effect/abstract/cyberware_anim/slash = cyberware_play_impact(user, victim, "impact_mantis")
+ TEST_ASSERT_NOTNULL(slash, "Test fixture: no slash was drawn over the victim")
+ sleep(0.2 SECONDS)
+ var/datum/sandy_replay_track/track = replay.tracks[slash] || replay.gone[slash]
+ TEST_ASSERT_NOTNULL(track, "The slash over someone hit wasn't recorded")
+ TEST_ASSERT(track.oneshot, "The slash wasn't recorded as a one-shot effect")
+ TEST_ASSERT(track.plays_out > 0, "The slash over someone hit isn't left to play through")
+ var/list/frames = track.frames
+ TEST_ASSERT(length(frames) >= 6, "The slash has no frame")
+ TEST_ASSERT_EQUAL(frames[length(frames) - 3], victim.x, "The slash isn't drawn on the tile of the one hit (x)")
+ TEST_ASSERT_EQUAL(frames[length(frames) - 2], victim.y, "The slash isn't drawn on the tile of the one hit (y)")
+ var/mutable_appearance/look = new(frames[length(frames) - 4])
+ TEST_ASSERT_EQUAL(look.plane, victim.plane, "The recorded slash isn't on the plane of the one hit")
+ TEST_ASSERT_EQUAL(look.layer, ABOVE_MOB_LAYER, "The recorded slash would sort under the body")
+ press_again(user)
+ wait_over(user)
+
+/// tg's blood splash is handed to the recording as it is put down, before it has turned the way the blow went and set
+/// off: it is taken again once it has, turned and with its flight, so a replayed hit has its splash.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/blood_splash_recorded
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/blood_splash_recorded/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaysplash")
+ set_window(user, 4 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/effect/temp_visual/dir_setting/bloodsplatter/splash = new(spot(1, 0), EAST)
+ var/datum/sandy_replay_track/track = replay.tracks[splash]
+ TEST_ASSERT_NOTNULL(track, "Test fixture: the field didn't hand the blood splash to the recording")
+ var/list/frames = track.frames
+ TEST_ASSERT_EQUAL(frames[6], EAST, "The recorded splash isn't turned the way the blow went")
+ TEST_ASSERT(length(track.events) >= 2, "The recorded splash has no flight: it would replay as nothing")
+ var/list/flight = track.events[2]
+ var/list/steps = flight[4]
+ var/list/step = steps[1]
+ TEST_ASSERT_EQUAL(step["pixel_x"], 16, "The recorded splash doesn't fly the way the blow went")
+ TEST_ASSERT_EQUAL(step["alpha"], 0, "The recorded splash doesn't fade as it flies")
+ press_again(user)
+ wait_over(user)
+
+/// A one-shot effect that only fades (a muzzle flash), compressed past two frames, is held whole for a frame by a step
+/// that changes nothing and then faded: never by a `delay`, through which the client draws it already faded out.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/oneshot_fade_held
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/oneshot_fade_held/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayfade")
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/obj/effect/abstract/sandy_replay_standin/standin = allocate(/obj/effect/abstract/sandy_replay_standin, spot(1, 0))
+ standin.alpha = 255
+ var/list/fade = list(standin)
+ fade["alpha"] = 0
+ fade["time"] = world.tick_lag / 2
+ var/list/chain = list(fade)
+ replay.stretch_oneshot(chain)
+ TEST_ASSERT_EQUAL(length(chain), 2, "The fade wasn't given a frame held whole first")
+ var/list/hold = chain[1]
+ var/list/rest = chain[2]
+ TEST_ASSERT_EQUAL(hold[1], standin, "The held step isn't on the stand-in")
+ TEST_ASSERT_EQUAL(hold["alpha"], 255, "The held step changes the flash")
+ TEST_ASSERT_EQUAL(hold["time"], world.tick_lag, "The flash isn't held for a frame")
+ TEST_ASSERT_NULL(hold["delay"], "The flash is held by a delay")
+ TEST_ASSERT_NULL(rest["delay"], "The fade waits on a delay")
+ TEST_ASSERT_EQUAL(rest["alpha"], 0, "The flash doesn't fade after its held frame")
+ TEST_ASSERT(rest[1] != standin, "The fade starts a new animation instead of following the held frame")
+ press_again(user)
+ wait_over(user)
+
+/// A shot is put on the floor before fire() turns it the way it flies: its first frame is taken once it is fired, so the
+/// replay never draws it unturned on the shooter. One spent before it flew (point blank) isn't drawn at all.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_first_frame_turned
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/shot_first_frame_turned/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayturn")
+ set_window(user, 4 SECONDS)
+ var/mob/living/carbon/human/npc/target = allocate(/mob/living/carbon/human/npc, spot(3, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/obj/projectile/bullet/shot = new(spot(0, 0))
+ shot.damage = 0
+ shot.stamina = 0
+ shot.firer = user
+ shot.fired_from = user
+ var/datum/sandy_replay_track/track = replay.tracks[shot]
+ TEST_ASSERT_NOTNULL(track, "The shot wasn't recorded")
+ TEST_ASSERT_EQUAL(length(track.frames), 0, "The shot has a frame before it was fired")
+ shot.aim_projectile(target, spot(0, 0))
+ shot.fire()
+ TEST_ASSERT(length(track.frames) >= 6, "The shot has no frame once fired")
+ var/mutable_appearance/look = new(track.frames[2])
+ TEST_ASSERT_EQUAL(track.frames[1], track.first, "The shot's first frame isn't the frame it was seen in")
+ TEST_ASSERT(!(look.transform ~= matrix()), "The shot's first frame isn't turned the way it flies")
+ var/obj/projectile/bullet/blank = new(spot(0, 0))
+ var/datum/sandy_replay_track/blank_track = replay.tracks[blank]
+ TEST_ASSERT_NOTNULL(blank_track, "The point-blank shot wasn't recorded")
+ qdel(blank)
+ TEST_ASSERT_EQUAL(length(blank_track.frames), 0, "A shot spent before it flew is drawn")
+ press_again(user)
+ wait_over(user)
+
+/// A shooter's muzzle flash and bullet are recorded on the tile it stands on for real: a replayed step onto that tile is
+/// over by the frame its shot is drawn in, so the flash is drawn at the gun, not ahead of a body still gliding there.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/step_lands_before_shot
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/step_lands_before_shot/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaystepshot")
+ set_window(user, 4 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.2 SECONDS)
+ var/datum/sandy_replay_track/user_track = replay.tracks[user]
+ TEST_ASSERT_NOTNULL(user_track, "The user isn't recorded")
+ var/obj/effect/temp_visual/dir_setting/firing_effect/flash = new(user, EAST)
+ var/datum/sandy_replay_track/flash_track = replay.tracks[flash]
+ TEST_ASSERT_NOTNULL(flash_track, "The muzzle flash wasn't recorded")
+ TEST_ASSERT_EQUAL(length(user_track.shot_frames), 1, "The muzzle flash isn't recorded as the user's shot")
+ var/list/shot = user_track.shot_frames[1]
+ TEST_ASSERT_EQUAL(shot[1], flash_track.first, "The user's shot isn't at the frame its flash is drawn in")
+ TEST_ASSERT_EQUAL(shot[2], user.x, "The user's shot isn't on the tile it was fired from (x)")
+ TEST_ASSERT_EQUAL(shot[3], user.y, "The user's shot isn't on the tile it was fired from (y)")
+ // Played back: two tiles east in frame 10, a shot from there in frame 11, the next step not until frame 20.
+ var/look = user.appearance
+ var/datum/sandy_replay_track/walker = new
+ walker.frames = list(0, look, user.x - 2, user.y, user.z, EAST, 10, look, user.x, user.y, user.z, EAST, 20, look, user.x - 2, user.y, user.z, WEST)
+ walker.cursor = 0
+ TEST_ASSERT(replay.advance(walker, 10), "The step wasn't played")
+ TEST_ASSERT(walker.glide_time > world.tick_lag, "Without a shot the step doesn't glide on toward the next, as a walk does")
+ walker.shot_frames = list(list(11, user.x, user.y))
+ walker.cursor = 0
+ walker.glide_until = 0
+ TEST_ASSERT(replay.advance(walker, 10), "The step wasn't played")
+ TEST_ASSERT(walker.glide_until - world.time <= world.tick_lag, "The step is still gliding when the shot fired from its tile is drawn")
+ // A shot fired from the tile it stepped off, in the frame of the step, doesn't hurry the step.
+ walker.shot_frames = list(list(10, user.x - 2, user.y))
+ walker.cursor = 0
+ walker.glide_until = 0
+ TEST_ASSERT(replay.advance(walker, 10), "The step wasn't played")
+ TEST_ASSERT(walker.glide_time > world.tick_lag, "A shot fired before the step cuts the step's glide short")
+ press_again(user)
+ wait_over(user)
+
+/// The replay's hold is a pause: an NPC's clocks (its next click, a blackboard deadline) and a held mech's have as long
+/// left when the replay ends as when it began, instead of running out during it, even one due a tick into the hold.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_pauses_clocks
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_pauses_clocks/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayclocks")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/gunner = allocate(/mob/living/carbon/human/npc, spot(5, 0))
+ var/obj/vehicle/sealed/mecha/ripley/mech = allocate(/obj/vehicle/sealed/mecha/ripley, spot(2, 3))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.6 SECONDS)
+ gunner.forceMove(spot(5, 1))
+ sleep(0.6 SECONDS)
+ press_again(user)
+ TEST_ASSERT_EQUAL(replay.state, 2, "Ending the slow-mo didn't queue the replay")
+ TEST_ASSERT_NOTNULL(gunner.ai_controller, "The NPC has no AI")
+ gunner.next_move = world.time + 1 // due before the hold is over
+ gunner.ai_controller.set_blackboard_key("human_npc_next_shot", world.time + 12) // BB_HUMAN_NPC_NEXT_SHOT
+ mech.cooldown_vehicle_move = world.time + 10
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ replay.hold_mech(mech)
+ var/began = world.time
+ wait_over(user)
+ var/held_for = world.time - began
+ TEST_ASSERT(held_for >= 3 * world.tick_lag, "The replay was over too fast to test anything ([held_for] ds)")
+ // At most one tick has run since the replay let go (wait_over()'s poll).
+ var/move_left = gunner.next_move - world.time
+ var/shot_left = gunner.ai_controller.blackboard["human_npc_next_shot"] - world.time
+ var/mech_left = mech.cooldown_vehicle_move - world.time
+ log_test("replay/hold_pauses_clocks: held [held_for] ds; left after: next_move [move_left], next shot [shot_left], mech move [mech_left]")
+ TEST_ASSERT(move_left <= 1 && move_left >= 1 - world.tick_lag - 0.01, "The NPC's next click had 1 ds left when the replay began and [move_left] when it ended")
+ TEST_ASSERT(shot_left <= 12 && shot_left >= 12 - world.tick_lag - 0.01, "The NPC's next shot had 12 ds left when the replay began and [shot_left] when it ended")
+ TEST_ASSERT(mech_left <= 10 && mech_left >= 10 - world.tick_lag - 0.01, "The mech's move cooldown had 10 ds left when the replay began and [mech_left] when it ended")
+ TEST_ASSERT(!GLOB.sandy_replay_stopped_clocks[gunner] && !GLOB.sandy_replay_stopped_clocks[mech], "The replay left a stopped clock behind")
+
+/// A turret that counts every target it is handed and shoots none, switched off so only the test drives it
+/obj/machinery/porta_turret/sandy_replay_test_probe
+ var/aimed = 0
+
+/obj/machinery/porta_turret/sandy_replay_test_probe/target(atom/movable/target)
+ aimed++
+ return FALSE
+
+/// The hold pauses the machines the slow-mo slows: a turret near the user takes no aim during it and has as long to
+/// its next shot after it, and a lit grenade's fuse has as long left, instead of going off while everyone is held.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_pauses_turrets
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_pauses_turrets/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayturret")
+ set_window(user, 3 SECONDS)
+ var/obj/machinery/porta_turret/sandy_replay_test_probe/turret = allocate(/obj/machinery/porta_turret/sandy_replay_test_probe, spot(3, 0))
+ turret.on = FALSE
+ turret.check_should_process()
+ turret.raised = TRUE
+ var/obj/item/grenade/bomb = allocate(/obj/item/grenade, spot(2, 2))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(1.2 SECONDS)
+ press_again(user)
+ TEST_ASSERT_EQUAL(replay.state, 2, "Ending the slow-mo didn't queue the replay")
+ turret.last_fired = world.time + 1 - turret.shot_delay // next shot due before the hold is over
+ bomb.arm_grenade(null, 1, msg = FALSE) // due before the hold is over
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT(replay.held_machines[turret], "The replay didn't hold a turret in reach")
+ TEST_ASSERT(replay.held_machines[bomb], "The replay didn't hold a lit grenade in reach")
+ var/began = world.time
+ var/until = world.time + 5 SECONDS
+ while(GLOB.sandy_replays[user] && world.time < until)
+ turret.tryToShootAt(list(user))
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay never ended")
+ var/held_for = world.time - began
+ TEST_ASSERT(held_for >= 3 * world.tick_lag, "The replay was over too fast to test anything ([held_for] ds)")
+ TEST_ASSERT_EQUAL(turret.aimed, 0, "A held turret took aim during the replay")
+ var/shot_left = turret.last_fired + turret.shot_delay - world.time
+ var/fuse_left = bomb.cyberware_fuse_at - world.time
+ log_test("replay/hold_pauses_turrets: held [held_for] ds; left after: turret shot [shot_left], fuse [fuse_left]")
+ TEST_ASSERT(!(bomb.dud_flags & GRENADE_USED), "A held grenade went off during the replay")
+ TEST_ASSERT(shot_left <= 1 && shot_left >= 1 - world.tick_lag - 0.01, "The turret's next shot had 1 ds left when the replay began and [shot_left] when it ended")
+ TEST_ASSERT(fuse_left <= 1 && fuse_left >= 1 - world.tick_lag - 0.01, "The grenade's fuse had 1 ds left when the replay began and [fuse_left] when it ended")
+ TEST_ASSERT(!GLOB.sandy_replay_stopped_clocks[turret] && !GLOB.sandy_replay_stopped_clocks[bomb], "The replay left a stopped clock behind")
+ bomb.cyberware_fuse_at = 0 // don't let it go off after the test
+ turret.tryToShootAt(list(user))
+ TEST_ASSERT_EQUAL(turret.aimed, 1, "The turret still won't take aim after the replay")
+
+/// Two replays holding one NPC at once push its clocks once, so it has the same time left when the last lets go, and
+/// a player's clocks are never stopped.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/overlapping_holds_push_once
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/overlapping_holds_push_once/Run()
+ var/mob/living/carbon/human/npc/npc = allocate(/mob/living/carbon/human/npc, spot(0, 0))
+ var/mob/living/carbon/human/player = allocate(/mob/living/carbon/human/consistent, spot(2, 0))
+ player.key = "sandyreplayplayerclock"
+ ADD_TRAIT(npc, TRAIT_AI_PAUSED, TRAIT_SOURCE_UNIT_TESTS) // it would go for the player
+ var/began = world.time
+ npc.next_move = began + 20
+ player.next_move = began + 20
+ sandy_replay_clock_stop(npc)
+ sandy_replay_clock_stop(player)
+ sleep(0.3 SECONDS)
+ sandy_replay_clock_stop(npc) // a second replay takes it
+ sleep(0.3 SECONDS)
+ sandy_replay_clock_start(npc) // the first lets go: the second still holds it
+ TEST_ASSERT_EQUAL(npc.next_move - world.time, 20, "An NPC's clock ran while another replay still held it")
+ sleep(0.3 SECONDS)
+ sandy_replay_clock_start(npc)
+ sandy_replay_clock_start(player)
+ TEST_ASSERT_EQUAL(npc.next_move - world.time, 20, "An NPC held by two replays at once didn't get exactly its held time back")
+ TEST_ASSERT_EQUAL(player.next_move, began + 20, "A player's clock was pushed by the replay's hold")
+ TEST_ASSERT(!GLOB.sandy_replay_stopped_clocks[npc] && !GLOB.sandy_replay_stopped_clocks[player], "A stopped clock was left behind")
+
+/// The sounds the replay played to `listener` of `file`, as /sound datums
+/datum/unit_test/voidcrew_cyberware_timestop/replay/proc/heard_by(mob/listener, file)
+ . = list()
+ for(var/list/entry as anything in GLOB.sandy_replay_heard)
+ var/sound/heard = entry[2]
+ if(entry[1] == listener && heard.file == file)
+ . += heard
+
+/// A user who ends the slow-mo away from where a sound was made hears it in the replay from where their view is (their
+/// replayed self), not from where their body stands
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_from_view
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_from_view/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaysoundview")
+ set_window(user, 2 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ GLOB.sandy_replay_heard.Cut()
+ playsound(spot(0, 1), 'sound/items/weapons/genhit1.ogg', 80, FALSE)
+ sleep(0.3 SECONDS)
+ user.forceMove(spot(2, 0))
+ user.forceMove(spot(4, 0))
+ user.forceMove(spot(5, 0))
+ sleep(0.3 SECONDS)
+ press_again(user)
+ TEST_ASSERT_EQUAL(replay.state, 2, "The replay isn't about to play")
+ // What follow() does for a user with a client: the view stands on the replayed self, here still where it started.
+ replay.eye = new /obj/effect/abstract/sandy_replay_eye(spot(0, 0))
+ wait_over(user)
+ var/list/heard = heard_by(user, 'sound/items/weapons/genhit1.ogg')
+ TEST_ASSERT_EQUAL(length(heard), 1, "The user wasn't played the recorded sound once")
+ var/sound/sound = heard[1]
+ TEST_ASSERT(sound.x == 0 && sound.z == 1, "The sound was placed from the real body ([sound.x], [sound.z]), not from the view (0, 1)")
+ TEST_ASSERT(abs(sound.volume - 48) < 0.5, "The sound played at [sound.volume], not at its recorded volume under the surge (48)")
+
+/// A busy room filling the recording doesn't crowd out the user's own sounds
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_cap_keeps_own
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_cap_keeps_own/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaysoundcap")
+ set_window(user, 2 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ for(var/i in 1 to 200)
+ replay.sounds += list(list(0, spot(4, 4), 'sound/items/weapons/genhit.ogg', 50, FALSE, 0, 6, 0, TRUE, TRUE, 1, TRUE, null))
+ playsound(spot(4, 3), 'sound/items/weapons/genhit1.ogg', 50, FALSE)
+ TEST_ASSERT_EQUAL(length(replay.sounds), 200, "The world's sounds went past their cap")
+ playsound(spot(1, 0), 'sound/items/weapons/genhit2.ogg', 50, FALSE)
+ TEST_ASSERT_EQUAL(length(replay.sounds), 201, "A blow on the user's next tile wasn't kept past the world's cap")
+ replay.hear(spot(4, 2), list('sound/items/weapons/genhit3.ogg', 50, FALSE, 0, 6, 0, TRUE, TRUE, 1, TRUE, null), user)
+ TEST_ASSERT_EQUAL(length(replay.sounds), 202, "A sound the user set off wasn't kept past the world's cap")
+ replay.sounds.Cut()
+ press_again(user)
+ wait_over(user)
+
+/// The same sound starting many times at once in the replay is heard once; a different one still plays
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_pileup_thinned
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sound_pileup_thinned/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaysoundpile")
+ set_window(user, 2 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ GLOB.sandy_replay_heard.Cut()
+ for(var/dx in 1 to 4)
+ playsound(spot(dx, 1), 'sound/items/weapons/genhit1.ogg', 50, FALSE)
+ playsound(spot(0, 0), 'sound/items/weapons/genhit2.ogg', 50, FALSE)
+ TEST_ASSERT_EQUAL(length(replay.sounds), 5, "The sounds weren't all recorded")
+ sleep(0.3 SECONDS)
+ press_again(user)
+ wait_over(user)
+ TEST_ASSERT_EQUAL(length(heard_by(user, 'sound/items/weapons/genhit1.ogg')), 1, "Four starts of one sound in the same moment weren't heard as one")
+ TEST_ASSERT_EQUAL(length(heard_by(user, 'sound/items/weapons/genhit2.ogg')), 1, "A different sound in the same moment was thinned out")
+
+/// The replay drags the user's trail behind his walk at the replay's speed, and none of it outlives the replay
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaytrail")
+ set_window(user, 6 SECONDS)
+ start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ var/length = window.trail_length
+ window.last_step_at = world.time // already walking: no first step's guessed pace
+ // A step or two a recorded frame (one frame is 0.5 s of the slow-mo): the replay sees each step, not a back and
+ // forth folded into one.
+ walk_trail(user, 16, 0.3 SECONDS)
+ var/peak = 0
+ var/list/off = list()
+ var/until = world.time + 8 SECONDS
+ while(world.time < until && (GLOB.sandy_replays[user] || window_of(user)))
+ peak = max(peak, count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade/replay))
+ off += off_colour_trail(user, /obj/effect/temp_visual/decoy/fading/cascade/replay)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay never ended")
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The replay didn't play")
+ log_test("replay/trail: [GLOB.sandy_replay_last["afterimages"]] afterimages laid, at most [peak] at once (trail [length])")
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= length, "The replay laid [GLOB.sandy_replay_last["afterimages"]] afterimages for a 16-tile walk")
+ TEST_ASSERT(!length(off), "Replayed afterimages not coloured by age: [jointext(off.Copy(1, min(length(off), 4) + 1), "; ")]")
+ TEST_ASSERT(peak >= length / 2, "At most [peak] afterimages at once behind the replayed walk, not about [length]")
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade), 0, "An afterimage outlived the replay")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A surger who crosses more tiles between two recorded moments than a walk does (a sprint into a lunge) has not
+/// teleported: the replay lays his trail over them
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail_dash
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail_dash/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaydash")
+ set_window(user, 3 SECONDS)
+ start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ window.last_step_at = world.time
+ sleep(0.6 SECONDS) // a recorded moment standing still
+ for(var/i in 1 to 4) // four tiles inside one recorded moment (half a second of the slow-mo)
+ TEST_ASSERT(user.Move(get_step(user, EAST), EAST), "Test fixture: the surger couldn't step")
+ sleep(0.6 SECONDS)
+ press_again(user)
+ wait_over(user)
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The replay didn't play")
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= 4, "The replay laid [GLOB.sandy_replay_last["afterimages"]] afterimages for a four-tile dash")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A corner turned inside one recorded moment is replayed round the corner: the trail is laid on the tile he turned
+/// on, not along the diagonal between the two samples.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail_corner
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/trail_corner/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaycorner")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ window.last_step_at = world.time
+ sleep(0.6 SECONDS) // a recorded moment standing still
+ var/turf/corner = spot(1, 0)
+ TEST_ASSERT(user.Move(corner, EAST), "Test fixture: the surger couldn't step east")
+ TEST_ASSERT(user.Move(get_step(corner, NORTH), NORTH), "Test fixture: the surger couldn't step north")
+ sleep(0.6 SECONDS)
+ var/datum/sandy_replay_track/track = replay.tracks[user]
+ TEST_ASSERT_NOTNULL(track, "Test fixture: the surger isn't recorded")
+ TEST_ASSERT_EQUAL(length(track.ways), 1, "The two steps taken inside one recorded moment weren't kept")
+ var/list/kept = track.ways[track.ways[1]]
+ TEST_ASSERT_EQUAL(length(kept), 4, "The steps kept for the corner aren't two tiles")
+ TEST_ASSERT(kept[1] == corner.x && kept[2] == corner.y, "The corner tile isn't the first step kept")
+ press_again(user)
+ wait_over(user)
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The replay didn't play")
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["ways_followed"], 1, "The replay didn't lay the trail round the corner the surger turned")
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= 2, "The replay laid [GLOB.sandy_replay_last["afterimages"]] afterimages for two steps round a corner")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Blood still painting in when the recording ended carries on, when the replay hands it back, from where the replay's
+/// last frame had it: its keyframes move on by the time the replay took.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/paint_carries_on
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/paint_carries_on/Run()
+ var/obj/effect/decal/cleanable/blood/hv_spray/spray = allocate(/obj/effect/decal/cleanable/blood/hv_spray, spot(1, 1))
+ var/matrix/full = matrix(spray.transform)
+ spray.hv_vis_paint(list(list(matrix(full), 0, 0, LINEAR_EASING), list(full, 255, 2 SECONDS, LINEAR_EASING)))
+ TEST_ASSERT_EQUAL(length(spray.hv_vis_painting), 2, "Test fixture: the spray isn't painting in")
+ var/list/last = spray.hv_vis_painting[2]
+ var/done_at = last[3]
+ sleep(0.5 SECONDS) // the replay plays: the paint runs on unseen
+ var/list/ahead = spray.sandy_replay_paint_now()
+ TEST_ASSERT(ahead && ahead[2] > 40, "Test fixture: the paint didn't run on (alpha [ahead ? ahead[2] : "none"])")
+ spray.sandy_replay_resume(0.5 SECONDS)
+ last = spray.hv_vis_painting[2]
+ TEST_ASSERT_EQUAL(last[3], done_at + 0.5 SECONDS, "The paint's keyframes didn't move on by the time the replay took")
+ var/list/shown = spray.sandy_replay_paint_now()
+ TEST_ASSERT(shown && shown[2] < 10, "The paint didn't carry on from where the recording ended (alpha [shown ? shown[2] : "none"])")
+ spray.sandy_replay_resume()
+ last = spray.hv_vis_painting[2]
+ TEST_ASSERT_EQUAL(last[3], done_at + 0.5 SECONDS, "A hand-back with no replay behind it moved the paint")
+ // Timed for a slow-mo that then ended sooner: what is left takes its own time, not ten times it
+ var/list/first = spray.hv_vis_painting[1]
+ last[3] = first[3] + 20 SECONDS
+ var/left = spray.sandy_replay_paint_carry(0.1 SECONDS)
+ TEST_ASSERT(left > 1.5 SECONDS && left <= 2 SECONDS, "A paint stretched by the slow-mo has [left] ds left once it is over, not what is left of its own 2 seconds")
+ last = spray.hv_vis_painting[2]
+ TEST_ASSERT(abs(last[3] - (world.time + left)) < 0.01, "The stretched paint's last keyframe isn't where it now ends")
+
+/// The replay's hold hands an AI back as it took it: one that was running by hand where tg would have it off (or the
+/// other way round) isn't left in the status tg works out afresh when the pause lifts.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_keeps_ai_status
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/hold_keeps_ai_status/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayaistatus")
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(3, 0))
+ var/datum/ai_controller/brain = raider.ai_controller
+ TEST_ASSERT_NOTNULL(brain, "Test fixture: the NPC has no AI controller")
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(brain.get_expected_ai_status() != AI_STATUS_ON, "Test fixture: tg already expects this AI on")
+ brain.set_ai_status(AI_STATUS_ON) // by hand: nobody is on the level, so tg itself would keep it off
+ press_again(user)
+ sleep(0.2 SECONDS)
+ TEST_ASSERT(held(raider), "Test fixture: the replay doesn't hold the NPC")
+ var/list/before = replay.ai_before[raider]
+ TEST_ASSERT_EQUAL(before?[1], AI_STATUS_ON, "Test fixture: the AI wasn't on any more when the hold began")
+ wait_over(user)
+ TEST_ASSERT(!held(raider), "The NPC is still held after the replay")
+ TEST_ASSERT_EQUAL(brain.ai_status, AI_STATUS_ON, "An AI that was running when the replay's hold began was left switched off after it")
+ brain.set_ai_status(AI_STATUS_OFF)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A body knocked flying as the slow-mo ends hangs in the air for the replay and flies on after it: it is never drawn
+/// where the recording last saw it while it really lands somewhere else.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/thrown_body_held
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/thrown_body_held/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaythrown")
+ var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent, spot(1, 2))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(1 SECONDS)
+ TEST_ASSERT_NOTNULL(replay.tracks[victim], "Test fixture: the body isn't recorded")
+ victim.throw_at(spot(5, 2), 4, 1)
+ sleep(world.tick_lag)
+ var/datum/thrownthing/flight = victim.throwing
+ TEST_ASSERT_NOTNULL(flight, "Test fixture: the body isn't in flight")
+ press_again(user)
+ TEST_ASSERT(flight.paused, "A body in flight as the slow-mo ended wasn't held for the replay")
+ var/turf/hung = get_turf(victim)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(get_turf(victim), hung, "A body in flight flew on under the replay")
+ wait_over(user)
+ var/until = world.time + 3 SECONDS
+ while(victim.throwing && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(victim.throwing, "The body never landed after the replay")
+ TEST_ASSERT(get_turf(victim) != hung, "The body didn't fly on once the replay let it go")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// What happens inside the first frame's half-second span (steps, a drawn weapon, a wound, spilled blood) isn't
+/// folded into frame 0: the replay opens where the user stood when the slow-mo began, with the Cascade's spine already
+/// lit, and replays those first steps with their trail.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/first
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/first/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayfirst")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/victim = allocate(/mob/living/carbon/human/npc, spot(2, 1))
+ var/obj/item/crowbar/still = allocate(/obj/item/crowbar, spot(0, 2))
+ var/obj/item/wrench/wrench = allocate(/obj/item/wrench, spot(3, 3))
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ var/datum/sandy_replay_track/user_track = replay.tracks[user]
+ TEST_ASSERT_NOTNULL(user_track, "Test fixture: the user isn't recorded")
+ TEST_ASSERT(findtext(lattice.node_look, "boot") == 1, "Test fixture: the Cascade's spine isn't still booting ([lattice.node_look])")
+ TEST_ASSERT(user_track.frames[2] != replay.clean_look(user), "Frame 0 kept the Cascade's half-lit boot spine")
+ var/old = lattice.node_look
+ lattice.node_look = "lit"
+ user.update_body_parts()
+ TEST_ASSERT_EQUAL(user_track.frames[2], replay.clean_look(user), "Frame 0 didn't open with the Cascade's lit spine")
+ lattice.node_look = old
+ user.update_body_parts()
+
+ // Still inside frame 0's span: step round a corner, take a weapon in hand, wound a body and spill blood.
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ window.last_step_at = world.time
+ TEST_ASSERT(user.Move(spot(1, 0), EAST), "Test fixture: the surger couldn't step east")
+ TEST_ASSERT(user.Move(spot(1, 1), NORTH), "Test fixture: the surger couldn't step north")
+ TEST_ASSERT(user.put_in_active_hand(wrench), "Test fixture: the weapon wouldn't go in the user's hand")
+ victim.cause_wound_of_type_and_severity(WOUND_SLASH, victim.get_bodypart(BODY_ZONE_CHEST), WOUND_SEVERITY_SEVERE)
+ var/obj/effect/decal/cleanable/blood/blood = allocate(/obj/effect/decal/cleanable/blood, spot(2, 0))
+ TEST_ASSERT_EQUAL(replay.frame_now(), 0, "Test fixture: the first frame's span was already over")
+
+ sleep(0.6 SECONDS)
+ var/datum/sandy_replay_track/track = replay.tracks[blood]
+ TEST_ASSERT_NOTNULL(track, "Blood spilled in the first half second wasn't recorded")
+ TEST_ASSERT(track.first >= 1, "Blood spilled in the first half second was given frame 0 ([track.first])")
+ TEST_ASSERT(user_track.frames[3] == spot(0, 0).x && user_track.frames[4] == spot(0, 0).y, "Frame 0 moved off the tile the slow-mo began on")
+ TEST_ASSERT_EQUAL(length(user_track.ways), 1, "The corner turned in the first half second wasn't kept")
+
+ press_again(user)
+ deltimer(replay.begin_timer)
+ var/real = real_look(user)
+ var/was = real_look(victim)
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT(!GLOB.sandy_replay_masked[still], "An untouched prop was replayed")
+ TEST_ASSERT(user.pixel_w == -32 && user.pixel_z == -32, "Frame 0 doesn't draw the user back on the tile the slow-mo began on ([user.pixel_w],[user.pixel_z])")
+ var/mutable_appearance/now = new(user)
+ var/mutable_appearance/before = new(real)
+ TEST_ASSERT(length(now.overlays) < length(before.overlays), "Frame 0 already shows what the user put in their hand in the first half second")
+ TEST_ASSERT(victim.appearance != was, "A body hurt in the first half second opens the replay already hurt")
+ TEST_ASSERT_EQUAL(blood.alpha, 0, "Blood spilled in the first half second shows at frame 0")
+
+ wait_over(user)
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The replay didn't play")
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["ways_followed"], 1, "The replay didn't follow the corner turned in the first half second")
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= 2, "The first half second's steps left [GLOB.sandy_replay_last["afterimages"]] afterimages")
+ TEST_ASSERT(victim.appearance == was, "The hurt body didn't end the replay as it really was")
+ TEST_ASSERT_EQUAL(blood.alpha, 255, "Blood spilled in the first half second stayed hidden after the replay")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// No trail afterimage is ever laid on a tile the replayed user has not left yet, on a straight dash or round a corner,
+/// and waiting for the tick he leaves it keeps each copy's colour age and life ending when they would have.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/ahead
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/ahead/Run()
+ var/turf/start = spot(0, 0)
+ var/mob/living/carbon/human/user = make_user(start, "sandyreplayahead")
+ set_window(user, 5 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = window_of(user)
+ window.last_step_at = world.time
+ sleep(0.5 SECONDS) // a three-tile straight dash inside one recorded frame (the test room is five tiles wide)
+ for(var/i in 1 to 3)
+ TEST_ASSERT(user.Move(get_step(user, EAST), EAST), "Test fixture: the surger couldn't dash east")
+ sleep(0.5 SECONDS) // next frame: a corner turn inside one frame
+ var/turf/corner = spot(4, 0)
+ TEST_ASSERT(user.Move(corner, EAST), "Test fixture: the surger couldn't step onto the corner")
+ TEST_ASSERT(user.Move(get_step(corner, NORTH), NORTH), "Test fixture: the surger couldn't turn north")
+ sleep(0.5 SECONDS) // next frame: another step north, so the corner glides over a single tick
+ TEST_ASSERT(user.Move(spot(4, 2), NORTH), "Test fixture: the surger couldn't step north again")
+ sleep(1.5 SECONDS) // room for the dash's copies to finish their own life inside the replay
+
+ press_again(user)
+ var/until = world.time + 2 SECONDS
+ while(replay.state != 3 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ var/datum/sandy_replay_track/user_track = replay.tracks[user]
+ var/list/frames = user_track.frames
+ var/drawn = 0
+ var/began = 0
+ var/done_at = 0
+ var/stalled_at = 0
+ var/peak = 0
+ var/list/ahead = list()
+ var/list/off = list()
+ until = world.time + 5 SECONDS
+ while(!QDELETED(replay) && replay.state == 3 && world.time < until)
+ for(var/waited in 1 to 2)
+ if(QDELETED(replay) || replay.state != 3)
+ break
+ var/at = user_track.cursor
+ if(at >= 0)
+ var/left = user_track.glide_until - world.time
+ var/list/still = (left > 0 && user_track.glide_time > 0) ? replay.glide_at(user_track, left) : list(0, 0)
+ var/now_spot = (frames[at + 3] - start.x) * 32 + still[1] + (frames[at + 4] - start.y) * 32 + still[2]
+ if(left > 0 && user_track.glide_way)
+ var/list/steps = replay.glide_legs(user_track, left)
+ if(left == user_track.glide_time && length(steps) != 2)
+ ahead += "corner glide had [length(steps)] legs"
+ drawn++
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/replay/image as anything in replay.trail_copies)
+ if(QDELETED(image) || !isturf(image.loc))
+ continue
+ var/real_spot = (image.x - start.x) * 32 + (image.y - start.y) * 32
+ if(real_spot > now_spot + 0.01)
+ ahead += "tile ([image.x - start.x],[image.y - start.y]) at [real_spot] px while puppet is at [now_spot] px"
+ if(!began && image.x == start.x && image.y == start.y && !image.pixel_w && !image.pixel_z)
+ began = world.time
+ done_at = world.time + image.duration
+ if(!stalled_at && image.x == start.x + 1 && image.y == start.y && !image.pixel_w && !image.pixel_z)
+ stalled_at = world.time
+ peak = world.time + image.duration
+ off += off_colour_trail(user, /obj/effect/temp_visual/decoy/fading/cascade/replay)
+ if(waited == 1)
+ sleep(0)
+ sleep(world.tick_lag)
+ wait_over(user)
+ TEST_ASSERT(!length(ahead), "Afterimages showed ahead of the puppet: [jointext(ahead.Copy(1, min(length(ahead), 4) + 1), "; ")]")
+ TEST_ASSERT(drawn >= 1, "The corner's glide never played")
+ TEST_ASSERT(began > 0 && stalled_at >= began + world.tick_lag, "The dash's second tile didn't wait for the next tick ([began] -> [stalled_at])")
+ TEST_ASSERT(peak > done_at && peak - done_at < world.tick_lag, "Waiting a tick shifted when the delayed copy's life ends ([done_at] -> [peak])")
+ TEST_ASSERT(!length(off), "Delayed afterimages not coloured by age: [jointext(off.Copy(1, min(length(off), 4) + 1), "; ")]")
+ TEST_ASSERT(GLOB.sandy_replay_last["ways_followed"] >= 1, "The replay didn't follow the way the surger went (the dash and the corner are each one)")
+ TEST_ASSERT(GLOB.sandy_replay_last["afterimages"] >= 6, "The replay laid [GLOB.sandy_replay_last["afterimages"]] afterimages across the dash and corner")
+ sleep(world.tick_lag)
+ TEST_ASSERT_EQUAL(count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade), 0, "An afterimage outlived the replay")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_replay_end.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_replay_end.dm
new file mode 100644
index 00000000000..6517b89c0bd
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_replay_end.dm
@@ -0,0 +1,134 @@
+/**
+ * # How a Sandevistan replay's recording ends, and how the replay hands back
+ *
+ * voidcrew/modules/cyberware/ware_sandy_replay.dm. A death that ends the slow-mo is recorded to the end of its fall, a
+ * thing the game moves under the replay stays drawn where its frame has it, a body's held pose carries on after the
+ * replay, and a flash of light in the field is lit again in the replay and put out after it.
+ *
+ * Unit-test files compile before voidcrew/_DEFINES/, so literals stand in for the module's defines: the replay's states
+ * are 1 recording, 2 about to play, 3 playing; a frame is 6 entries of a track's frames list (index, look, x, y, z, dir).
+ */
+
+/// The user is shot dead in the slow-mo with a blow heavy enough to slide the corpse a tile. The recording goes on until
+/// it has slid, so the replay's last frame has it where it lies, and the slide leaves no trail.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_slides_dead
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/user_slides_dead/Run()
+ var/mob/living/carbon/human/user = make_user(spot(1, 1), "sandyreplayslide")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.6 SECONDS)
+ // The killing blow, as hyperviolence notes a hit in the tick it lands: heavy, from the west.
+ user.hv_vis_hit_time = world.time
+ user.hv_vis_hit_dir = EAST
+ user.hv_vis_hit_damage = 60
+ var/frames_before = replay.frame_now()
+ var/died_at = world.time
+ user.death() // ends the slow-mo there and then
+ TEST_ASSERT(user.hv_vis_slide_due, "Test fixture: the death queued no slide across a tile")
+ TEST_ASSERT_EQUAL(replay.state, 1, "The recording stopped before the dead user's body slid")
+ TEST_ASSERT(replay.wait_started, "The recording isn't waiting for the dead user's body to slide")
+ var/until = world.time + 3 SECONDS
+ while(replay.state == 1 && !QDELETED(replay) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(!QDELETED(replay) && replay.state >= 2, "The recording never ended after the body slid, or nothing replays")
+ TEST_ASSERT_EQUAL(user.loc, spot(2, 1), "Test fixture: the body didn't slide a tile east")
+ // The world ran at its normal pace while the body slid: a frame a tick, or the slide replays too fast
+ var/waited_ticks = (replay.ended_at - died_at) / world.tick_lag
+ TEST_ASSERT(waited_ticks >= 2, "Test fixture: the recording waited [waited_ticks] ticks for the slide")
+ TEST_ASSERT(replay.total - frames_before >= waited_ticks - 2, "The wait for the slide recorded [replay.total - frames_before] frames over [waited_ticks] ticks")
+ var/datum/sandy_replay_track/track = replay.tracks[user]
+ var/list/frames = track.frames
+ var/at = length(frames) - 6
+ TEST_ASSERT(frames[at + 3] == user.x && frames[at + 4] == user.y, "The replay's last frame doesn't have the body where it slid to")
+ TEST_ASSERT(frames[at + 1] > track.surge_until, "The body's slide counts as a surging step and leaves a trail")
+ // The slide is replayed as slowly as it went (HV_VIS_SLIDE_TIME, 0.4 s: eight ticks), not snapped in a tick or two
+ var/slide_ticks = length(track.glides) ? track.glides[track.glides[1]] : 0
+ TEST_ASSERT(slide_ticks >= 6, "The corpse's slide replays over [slide_ticks] ticks")
+ TEST_ASSERT(replay.ended_at >= died_at + 0.4 SECONDS, "The recording ended [replay.ended_at - died_at] ds after the death, before the slide was over")
+ wait_over(user)
+ TEST_ASSERT_EQUAL(GLOB.sandy_replay_last["played"], TRUE, "The death didn't replay")
+ TEST_ASSERT_EQUAL(user.loc, spot(2, 1), "The body isn't where it slid to after the replay")
+ TEST_ASSERT(user.pixel_w == user.base_pixel_w && user.pixel_z == user.base_pixel_z, "The body is left drawn off its tile: [user.pixel_w],[user.pixel_z]")
+
+/// A puppet the game moves a tile under the replay jumps there instead of gliding, so it stays drawn on its frame's tile,
+/// and glides its own moves again after the replay.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/puppet_moved_jumps
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/puppet_moved_jumps/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplayjump")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.6 SECONDS)
+ raider.forceMove(spot(3, 0))
+ sleep(0.6 SECONDS)
+ press_again(user)
+ deltimer(replay.begin_timer)
+ var/movement = raider.animate_movement
+ replay.begin()
+ TEST_ASSERT_EQUAL(replay.state, 3, "The replay didn't start")
+ TEST_ASSERT(GLOB.sandy_replay_masked[raider], "The NPC that moved isn't replayed")
+ TEST_ASSERT_EQUAL(raider.pixel_w, -32, "The NPC isn't drawn back on its first tile")
+ raider.forceMove(spot(3, 1)) // the game moves it under the replay
+ TEST_ASSERT_EQUAL(raider.animate_movement, NO_STEPS, "A puppet moved under the replay glides, drawn a tile off its frame's tile as it goes")
+ TEST_ASSERT_EQUAL(raider.pixel_z, -32, "The moved puppet isn't drawn on its frame's tile")
+ wait_over(user)
+ TEST_ASSERT_EQUAL(raider.animate_movement, movement, "The NPC doesn't glide its own moves after the replay")
+ TEST_ASSERT_EQUAL(raider.loc, spot(3, 1), "The NPC isn't where it was really moved to")
+
+/// A corpse's pose held in the slow-mo (slid within its tile) is played on its puppet, and carries on from there on the
+/// real body when the replay hands it back, instead of being ended with the puppet.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/held_pose_carries_on
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/held_pose_carries_on/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaypose")
+ set_window(user, 3 SECONDS)
+ var/mob/living/carbon/human/npc/victim = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.6 SECONDS)
+ victim.death()
+ victim.hv_vis_slide_in_tile(EAST, 20)
+ sleep(0.6 SECONDS)
+ press_again(user)
+ deltimer(replay.begin_timer)
+ var/real_w = victim.pixel_w
+ replay.begin()
+ TEST_ASSERT(GLOB.sandy_replay_masked[victim], "The corpse isn't replayed")
+ var/datum/sandy_replay_track/track = replay.tracks[victim]
+ var/until = world.time + 3 SECONDS
+ while(!length(track.chain) && GLOB.sandy_replays[user] && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(length(track.chain), "The corpse's slide wasn't played on its puppet")
+ var/resumed = replay.chains_resumed
+ replay.finish()
+ TEST_ASSERT(GLOB.sandy_replay_last["chains_resumed"] > resumed, "The corpse's held pose ended at the hand-back")
+ TEST_ASSERT_EQUAL(victim.pixel_w, real_w, "The corpse's real offset changed")
+
+/// A flash of light lit on the floor in the field is lit again in the replay, as bright, and is out after it.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/flash_light_replayed
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/flash_light_replayed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyreplaylight")
+ set_window(user, 3 SECONDS)
+ var/datum/sandy_replay/replay = start_recording(user)
+ sleep(0.6 SECONDS)
+ var/turf/flash_at = spot(2, 1)
+ flash_at.flash_lighting_fx(3, 2, LIGHT_COLOR_ORANGE, 2) // an execution's shot
+ TEST_ASSERT_EQUAL(length(replay.lights), 1, "A flash of light in the field wasn't recorded")
+ sleep(0.6 SECONDS)
+ var/list/light = replay.lights[1]
+ TEST_ASSERT(light[2] != INFINITY && light[2] > light[1], "The recording didn't see the flash go out")
+ press_again(user)
+ deltimer(replay.begin_timer)
+ replay.begin()
+ var/found_lit = FALSE
+ var/until = world.time + 3 SECONDS
+ while(!found_lit && GLOB.sandy_replays[user] && world.time < until)
+ for(var/obj/effect/dummy/lighting_obj/glow in flash_at)
+ found_lit = glow.light_range == 3 && glow.light_power == 2 && glow.light_color == LIGHT_COLOR_ORANGE
+ if(!found_lit)
+ sleep(world.tick_lag)
+ TEST_ASSERT(found_lit, "The replay didn't light the flash as the live one was lit")
+ wait_over(user)
+ TEST_ASSERT(!(locate(/obj/effect/dummy/lighting_obj) in flash_at), "A light the replay lit is still on after it")
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_sandy_sound.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_sandy_sound.dm
new file mode 100644
index 00000000000..be4c140af70
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_sandy_sound.dm
@@ -0,0 +1,257 @@
+/**
+ * # What a Sandevistan sounds like
+ *
+ * voidcrew/modules/cyberware/ware_sandy_sound.dm. The user hears his surge come on, a loop for as long as his slow-mo
+ * runs and its ending, all to him alone and none of it recorded for the
+ * replay. Everyone else near hears a short snap from his tile as he surges and bursts off, and the replay's viewers
+ * hear it as the replay starts and as his replayed self bursts off after a pause.
+ *
+ * Unit-test files compile before voidcrew/_DEFINES/, so the sound files are written out. "external" stands for any of
+ * the snap's files.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound
+ abstract_type = /datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound
+
+/// Whether `heard` is `file`, or any of the snap's files for "external"
+/datum/unit_test/voidcrew_cyberware_timestop/proc/is_file(sound/heard, file)
+ if(file == "external")
+ return heard.file in list('voidcrew/sound/cyberware/sandevistan_external_1.ogg', 'voidcrew/sound/cyberware/sandevistan_external_2.ogg', 'voidcrew/sound/cyberware/sandevistan_external_3.ogg')
+ return heard.file == file
+
+/// The cues of `file` sent to `listener`, as /sound datums
+/datum/unit_test/voidcrew_cyberware_timestop/proc/cues(mob/listener, file)
+ . = list()
+ for(var/list/entry as anything in GLOB.sandy_cues_sent)
+ var/sound/cue = entry[2]
+ if(entry[1] == listener && cue.file && !(cue.status & SOUND_UPDATE) && is_file(cue, file))
+ . += cue
+
+/// The pitch updates sent to `listener` for what plays on `channel`, as /sound datums
+/datum/unit_test/voidcrew_cyberware_timestop/proc/updates(mob/listener, channel)
+ . = list()
+ for(var/list/entry as anything in GLOB.sandy_cues_sent)
+ var/sound/cue = entry[2]
+ if(entry[1] == listener && (cue.status & SOUND_UPDATE) && cue.channel == channel)
+ . += cue
+
+/// The stops sent to `listener` on `channel`
+/datum/unit_test/voidcrew_cyberware_timestop/proc/stops(mob/listener, channel)
+ . = 0
+ for(var/list/entry as anything in GLOB.sandy_cues_sent)
+ var/sound/cue = entry[2]
+ if(entry[1] == listener && !cue.file && cue.channel == channel)
+ .++
+
+/// The channel the loop went out on to `user` (asserts it went out once, looping)
+/datum/unit_test/voidcrew_cyberware_timestop/proc/loop_channel(mob/user)
+ var/list/loops = cues(user, 'voidcrew/sound/cyberware/sandevistan_loop.ogg')
+ TEST_ASSERT_EQUAL(length(loops), 1, "The slow-mo's loop didn't go out once to its user")
+ var/sound/loop = loops[1]
+ TEST_ASSERT(loop.repeat && loop.channel, "The loop isn't repeating on a channel of its own")
+ return loop.channel
+
+/// On a surge the user hears it come on and the slow-mo's loop, a bystander the snap; neither hears the other's, and
+/// none of it is recorded. A second press stops the loop and he hears the slow-mo end.
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/surge
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/surge/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundsurge")
+ var/mob/living/carbon/human/bystander = allocate(/mob/living/carbon/human/consistent, spot(3, 0))
+ set_window(user, 2 SECONDS)
+ GLOB.sandy_cues_sent.Cut()
+ var/datum/sandy_replay/replay = start_recording(user)
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_activation.ogg')), 1, "The user didn't hear his surge come on")
+ TEST_ASSERT_EQUAL(length(cues(user, "external")), 0, "The user heard his own snap")
+ TEST_ASSERT_EQUAL(length(cues(bystander, "external")), 1, "A bystander didn't hear the snap")
+ TEST_ASSERT_EQUAL(length(cues(bystander, 'voidcrew/sound/cyberware/sandevistan_activation.ogg')), 0, "A bystander heard the user's own surge")
+ TEST_ASSERT_EQUAL(length(cues(bystander, 'voidcrew/sound/cyberware/sandevistan_loop.ogg')), 0, "A bystander heard the user's loop")
+ var/sound/snap = cues(bystander, "external")[1]
+ TEST_ASSERT(snap.x == -3 && snap.z == 0, "The snap wasn't placed at the surger's tile ([snap.x], [snap.z])")
+ TEST_ASSERT(snap.frequency >= 0.94 && snap.frequency <= 1.06, "The snap's pitch ([snap.frequency]) went past its spread")
+ var/channel = loop_channel(user)
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(user.Move(spot(1, 0), EAST), "Test fixture: the user couldn't step")
+ for(var/list/heard as anything in replay.sounds)
+ TEST_ASSERT(!findtext("[heard[3]]", "sandevistan"), "A Sandevistan cue ([heard[3]]) was recorded for the replay")
+ press_again(user)
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop wasn't stopped when the slow-mo ended")
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg')), 1, "The user didn't hear his slow-mo end")
+ TEST_ASSERT_EQUAL(length(cues(bystander, 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg')), 0, "A bystander heard the user's slow-mo end")
+ wait_over(user)
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop was stopped twice")
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg')), 1, "The user heard his slow-mo end twice")
+
+/// As the user moves in his slow-mo, others hear the snap at most every 0.4 s, and never for a forced move
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/steps
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/steps/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundsteps")
+ var/mob/living/carbon/human/bystander = allocate(/mob/living/carbon/human/consistent, spot(0, 3))
+ set_window(user, 4 SECONDS)
+ start_recording(user)
+ GLOB.sandy_cues_sent.Cut()
+ sleep(0.4 SECONDS)
+ for(var/dx in 1 to 3)
+ TEST_ASSERT(user.Move(spot(dx, 0), EAST), "Test fixture: the user couldn't step")
+ TEST_ASSERT_EQUAL(length(cues(bystander, "external")), 1, "Bursting off from standing didn't cue the snap once")
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(user.Move(spot(4, 0), EAST), "Test fixture: the user couldn't step")
+ TEST_ASSERT_EQUAL(length(cues(bystander, "external")), 2, "A burst off past 0.4 s didn't cue the snap again")
+ sleep(1.1 SECONDS)
+ user.forceMove(spot(5, 0))
+ TEST_ASSERT_EQUAL(length(cues(bystander, "external")), 2, "A forced move cued the snap")
+ press_again(user)
+ wait_over(user)
+
+/// The loop stops when the user dies, and nothing stops it a second time
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/loop_stops_on_death
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/loop_stops_on_death/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundloopdie")
+ set_window(user, 2 SECONDS)
+ GLOB.sandy_cues_sent.Cut()
+ start_recording(user)
+ var/channel = loop_channel(user)
+ user.death()
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop wasn't stopped when the user died")
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg')), 0, "A dead user heard his slow-mo end")
+ wait_over(user)
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop was stopped twice")
+
+/// The loop stops when the user logs out, and the slow-mo's end doesn't stop it again
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/loop_stops_on_logout
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/loop_stops_on_logout/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundlooplogout")
+ set_window(user, 2 SECONDS)
+ GLOB.sandy_cues_sent.Cut()
+ start_recording(user)
+ var/channel = loop_channel(user)
+ SEND_SIGNAL(user, COMSIG_MOB_LOGOUT)
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop wasn't stopped when the user logged out")
+ press_again(user)
+ wait_over(user)
+ TEST_ASSERT_EQUAL(stops(user, channel), 1, "The loop was stopped twice")
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_deactivate.ogg')), 0, "A user who logged out was sent his slow-mo's end")
+
+/// The replay plays the snap to its viewers as it starts, where the user began, and where the replayed user bursts off
+/// after a pause, placed from their view and not from his real body, and not again for every step after it
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/replay_snap
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/replay_snap/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundreplay")
+ set_window(user, 3 SECONDS)
+ start_recording(user)
+ TEST_ASSERT(user.Move(spot(1, 0), EAST), "Test fixture: the user couldn't step")
+ sleep(0.6 SECONDS)
+ for(var/dx in 2 to 4)
+ TEST_ASSERT(user.Move(spot(dx, 0), EAST), "Test fixture: the user couldn't step")
+ sleep(0.3 SECONDS)
+ GLOB.sandy_replay_heard.Cut()
+ var/datum/sandy_replay/replay = GLOB.sandy_replays[user]
+ press_again(user)
+ // A view off to one side; a client's would follow the replayed self.
+ replay.eye = new /obj/effect/abstract/sandy_replay_eye(spot(0, 1))
+ wait_over(user)
+ var/list/heard = list()
+ for(var/list/entry as anything in GLOB.sandy_replay_heard)
+ if(entry[1] == user && is_file(entry[2], "external"))
+ heard += entry[2]
+ TEST_ASSERT_EQUAL(length(heard), 2, "The replay's viewer didn't hear the snap at its start and once at the burst after the pause")
+ var/sound/start = heard[1]
+ var/sound/burst = heard[2]
+ // The start plays as the replay opens, while the view stands on where the user began (not on his body, at (4, 0)).
+ TEST_ASSERT(start.x == 0 && start.z == 0, "The replay's start snap was placed at ([start.x], [start.z]), not where the user began (0, 0)")
+ TEST_ASSERT(burst.x == 1 && burst.z == -1, "The burst snap was placed at ([burst.x], [burst.z]), not where the replayed user burst off from the view (1, -1)")
+ TEST_ASSERT(burst.volume > 60, "The burst snap played at [burst.volume], not at full volume")
+
+/// In a shared slow-mo each member hears the other's snap, never his own, and his own loop ends when his time is out
+/datum/unit_test/voidcrew_cyberware_timestop/shared/sandy_sound
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/sandy_sound/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandysoundone")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandysoundtwo")
+ make_crew(list(first, second))
+ set_window(first, 3 SECONDS)
+ set_window(second, 3 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ GLOB.sandy_cues_sent.Cut()
+ surge(second)
+ sleep(0.3 SECONDS)
+ TEST_ASSERT_NOTNULL(session_of(first), "Test fixture: the two slow-mos didn't join")
+ TEST_ASSERT_EQUAL(length(cues(first, "external")), 1, "A member didn't hear his crewmate surge")
+ TEST_ASSERT_EQUAL(length(cues(second, "external")), 0, "A member heard his own snap")
+ TEST_ASSERT_EQUAL(length(cues(first, 'voidcrew/sound/cyberware/sandevistan_activation.ogg')), 0, "A member heard his crewmate's own surge")
+ var/channel = loop_channel(second)
+ sleep(0.2 SECONDS)
+ TEST_ASSERT(second.Move(spot(4, 0), EAST), "Test fixture: the member couldn't step")
+ TEST_ASSERT_EQUAL(length(cues(first, "external")), 2, "A member didn't hear his crewmate burst off")
+ TEST_ASSERT_EQUAL(length(cues(second, "external")), 0, "A member heard his own snap as he burst off")
+ var/datum/action/cooldown/cyberware/cascade_surge/button = surge_button(second)
+ TEST_ASSERT(button.Trigger(), "The second press did nothing")
+ TEST_ASSERT_NOTNULL(one.time_stop, "Test fixture: one member dropping out ended the shared slow-mo")
+ TEST_ASSERT_EQUAL(stops(second, channel), 1, "The loop of a member whose time is out didn't stop")
+ qdel(one)
+ sleep(0.1 SECONDS)
+ wait_replay(first)
+ TEST_ASSERT_EQUAL(stops(second, channel), 1, "The loop was stopped twice")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// The loop climbs in pitch as the slow-mo runs toward its end, to about 1.4 near it, and nothing reaches the user on
+/// the loop's channel after it
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/pitch_climbs
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/pitch_climbs/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundpitch")
+ var/mob/living/carbon/human/bystander = allocate(/mob/living/carbon/human/consistent, spot(0, 3))
+ set_window(user, 3 SECONDS)
+ GLOB.sandy_cues_sent.Cut()
+ start_recording(user)
+ var/channel = loop_channel(user)
+ sleep(2.6 SECONDS)
+ var/list/climb = updates(user, channel)
+ TEST_ASSERT(length(climb) >= 4, "The loop's pitch was updated [length(climb)] times in 2.7 s")
+ var/last = 0
+ for(var/sound/update as anything in climb)
+ TEST_ASSERT(update.file == 'voidcrew/sound/cyberware/sandevistan_loop.ogg', "A pitch update went out for another sound")
+ TEST_ASSERT(update.frequency >= last, "The loop's pitch went down ([last] to [update.frequency])")
+ last = update.frequency
+ TEST_ASSERT(last >= 1.25 && last <= 1.4, "The loop's pitch near the end was [last], not about 1.4")
+ TEST_ASSERT_EQUAL(length(cues(user, 'voidcrew/sound/cyberware/sandevistan_loop.ogg')), 1, "The loop was restarted to change its pitch")
+ TEST_ASSERT_EQUAL(length(updates(bystander, channel)), 0, "A bystander was sent the loop's pitch")
+ press_again(user)
+ var/sent = length(GLOB.sandy_cues_sent)
+ sleep(1.2 SECONDS)
+ for(var/i in sent + 1 to length(GLOB.sandy_cues_sent))
+ var/list/entry = GLOB.sandy_cues_sent[i]
+ var/sound/cue = entry[2]
+ TEST_ASSERT(!(entry[1] == user && cue.channel == channel), "The loop's channel was sent [cue.file] after the slow-mo ended")
+ wait_over(user)
+
+/// When the slow-mo's end moves later (a hold, a shared slow-mo), the pitch never drops and never passes the top
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/pitch_end_moves
+
+/datum/unit_test/voidcrew_cyberware_timestop/replay/sandy_sound/pitch_end_moves/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandysoundpitchmove")
+ set_window(user, 3 SECONDS)
+ start_recording(user)
+ var/datum/status_effect/cyberware_cascade_window/window = user.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop?.chronofield
+ TEST_ASSERT_NOTNULL(field, "Test fixture: no slow-mo field")
+ sleep(2 SECONDS)
+ var/before = window.sandy_slowmo_progress()
+ TEST_ASSERT(before > 0.5 && before < 1, "Test fixture: the slow-mo was [before] of the way through at 2 s of 3")
+ field.ends_at += 10 SECONDS
+ var/after = window.sandy_slowmo_progress()
+ TEST_ASSERT(after >= before, "The slow-mo's progress went from [before] to [after] when its end moved later")
+ sleep(0.5 SECONDS)
+ var/later = window.sandy_slowmo_progress()
+ TEST_ASSERT(later >= after && later < 1, "The progress ([later]) didn't keep climbing slowly toward the later end")
+ field.ends_at = world.time - 1
+ TEST_ASSERT(window.sandy_slowmo_progress() <= 1, "The progress went past the end")
+ TEST_ASSERT(sandy_pitch_for(window.sandy_slowmo_progress()) <= 1.4, "The pitch went past the top")
+ TEST_ASSERT(sandy_pitch_for(2) <= 1.4, "The pitch went past the top")
+ press_again(user)
+ wait_over(user)
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop.dm
new file mode 100644
index 00000000000..ca9b6570071
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop.dm
@@ -0,0 +1,1092 @@
+/**
+ * # The Cascade line's time dilation
+ *
+ * voidcrew/modules/cyberware/ware_sandy_timestop.dm. A player's surge with no other player near slows the
+ * world for the whole window: street 6 s at 50%, service 7 s at 35%, Cascade 8 s at 20%. Nothing is ever
+ * frozen: a human NPC walks under a movespeed modifier and its timers run slow, and it never gets tg's
+ * immobilise, hand-block or AI-pause traits. The user can act the whole time, and pressing the surge again ends
+ * the window early, slow-mo and all. Another player near means no dilation at all.
+ *
+ * Unit-test files compile before voidcrew/_DEFINES/, so literals stand in for module defines.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop
+ abstract_type = /datum/unit_test/voidcrew_cyberware_timestop
+
+/// A player body (a key, no client) at `where` with a Cascade lattice (or `lattice_type`) in it
+/datum/unit_test/voidcrew_cyberware_timestop/proc/make_user(turf/where, key, lattice_type = /obj/item/organ/cyberimp/cyberware/cascade)
+ var/mob/living/carbon/human/user = allocate(/mob/living/carbon/human/consistent, where)
+ user.key = key
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = allocate(lattice_type)
+ TEST_ASSERT(lattice.Insert(user, special = TRUE), "Test fixture: the lattice wouldn't go in")
+ return user
+
+/// Opens the lattice's window the way its surge button does
+/datum/unit_test/voidcrew_cyberware_timestop/proc/surge(mob/living/carbon/human/user)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ return user.apply_status_effect(/datum/status_effect/cyberware_cascade_window, lattice)
+
+/// A turf `dx`, `dy` from the bottom left of the test room
+/datum/unit_test/voidcrew_cyberware_timestop/proc/spot(dx, dy)
+ return locate(run_loc_floor_bottom_left.x + dx, run_loc_floor_bottom_left.y + dy, run_loc_floor_bottom_left.z)
+
+/datum/unit_test/voidcrew_cyberware_timestop/Destroy()
+ for(var/mob/living/body in allocated)
+ body.key = null
+ return ..()
+
+/// Whether `body` carries any of the traits tg's own time stop freezes with
+/datum/unit_test/voidcrew_cyberware_timestop/proc/frozen(mob/living/body)
+ return HAS_TRAIT(body, TRAIT_IMMOBILIZED) || HAS_TRAIT(body, TRAIT_HANDS_BLOCKED) || HAS_TRAIT(body, TRAIT_AI_PAUSED) || HAS_TRAIT(body, TRAIT_MUTE) || HAS_TRAIT(body, TRAIT_EMOTEMUTE)
+
+/// Sets the length of `user`'s next window, to keep a test short
+/datum/unit_test/voidcrew_cyberware_timestop/proc/set_window(mob/living/carbon/human/user, length)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ lattice.window_duration = length
+ lattice.slowmo_duration = length // the tests that set a length mean the slow-mo too
+
+/// `user`'s surge button
+/datum/unit_test/voidcrew_cyberware_timestop/proc/surge_button(mob/living/carbon/human/user)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ return locate(/datum/action/cooldown/cyberware/cascade_surge) in lattice.actions
+
+/// Waits for the replay that follows `user`'s slow-mo to be over (ware_sandy_replay.dm): AIs are paused and the crash waits until then
+/datum/unit_test/voidcrew_cyberware_timestop/proc/wait_replay(mob/living/carbon/human/user)
+ var/until = world.time + 5 SECONDS
+ while(GLOB.sandy_replays[user] && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(GLOB.sandy_replays[user], "The replay after the slow-mo never ended")
+
+/// Nobody else near: the world runs slow from the first moment to the end of the window, nothing is ever frozen,
+/// and the user can act throughout
+/datum/unit_test/voidcrew_cyberware_timestop/alone
+
+/datum/unit_test/voidcrew_cyberware_timestop/alone/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ set_window(user, 2 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/next_move_was = world.time + 5 SECONDS
+ raider.next_move = next_move_was
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ sleep(0.1 SECONDS) // the field starts async
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(istype(field), "The dilation has no field")
+
+ // Slow-mo from the start: a walk under a movespeed modifier, no freeze and no Stun.
+ TEST_ASSERT(abs(field.time_scale - 0.1) < 0.001, "The Cascade's world doesn't run at 10% from the start ([field.time_scale])")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC isn't slowed as the window opens")
+ TEST_ASSERT(!frozen(raider), "The NPC was frozen")
+ TEST_ASSERT(!raider.IsStun(), "The dilation stunned the NPC")
+ TEST_ASSERT(!frozen(user), "The user froze in their own dilation")
+ var/turf/start = get_turf(user)
+ user.Move(spot(0, 1), NORTH)
+ TEST_ASSERT(get_turf(user) != start, "The user couldn't move in their own slow-mo")
+
+ // Slowed bodies still get hurt through tg.
+ var/brute_before = raider.getBruteLoss()
+ raider.apply_damage(10, BRUTE, BODY_ZONE_CHEST)
+ TEST_ASSERT(raider.getBruteLoss() > brute_before, "A slowed NPC didn't take damage")
+
+ // Through the whole window: slowed, never frozen.
+ for(var/i in 1 to 4)
+ sleep(0.4 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "The slow-mo ended [i * 0.4] s into a 2 s window")
+ TEST_ASSERT(!frozen(raider), "The NPC was frozen [i * 0.4] s in")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC wasn't slowed [i * 0.4] s in")
+ TEST_ASSERT(raider.next_move > next_move_was + 1 SECONDS, "The NPC's timers ran on at full speed")
+ TEST_ASSERT(!length(field.frozen_mobs), "The field kept a list of frozen mobs")
+
+ sleep(0.7 SECONDS) // past the window
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_window), "Test fixture: the window outlived its 2 s")
+ TEST_ASSERT_NULL(window.time_stop, "The slow-mo outlived the window")
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC stayed slow after the window")
+ wait_replay(user)
+ TEST_ASSERT(!frozen(raider), "The NPC was frozen after the window and its replay")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// The slow-mo lasts each model's whole window at that model's pace
+/datum/unit_test/voidcrew_cyberware_timestop/full_window
+
+/datum/unit_test/voidcrew_cyberware_timestop/full_window/Run()
+ var/list/models = list(
+ /obj/item/organ/cyberimp/cyberware/cascade/street = list(11 SECONDS, 0.4),
+ /obj/item/organ/cyberimp/cyberware/cascade/milspec = list(12 SECONDS, 0.25),
+ /obj/item/organ/cyberimp/cyberware/cascade = list(13 SECONDS, 0.1),
+ )
+ for(var/model in models)
+ var/list/expected = models[model]
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser", model)
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "[model]: the window didn't open")
+ TEST_ASSERT_EQUAL(window.duration - world.time, expected[1], "[model]: the window isn't [expected[1] / 10] s")
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "[model]: time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(abs(field.time_scale - expected[2]) < 0.001, "[model]: the world runs at [field.time_scale], not [expected[2]]")
+ TEST_ASSERT(abs(field.ends_at - window.duration) <= 1, "[model]: the slow-mo ends at [field.ends_at], the window at [window.duration]")
+ end_surge(user)
+ TEST_ASSERT_NULL(window.time_stop, "[model]: the slow-mo outlived the window")
+ user.key = null
+ qdel(user)
+
+/// Pressing the surge again ends the window early, slow-mo and all, and the crash starts. It never opens a fresh
+/// window, and an NPC's lattice never turns itself off.
+/datum/unit_test/voidcrew_cyberware_timestop/toggle_off
+
+/datum/unit_test/voidcrew_cyberware_timestop/toggle_off/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/action/cooldown/cyberware/cascade_surge/button = surge_button(user)
+ TEST_ASSERT_NOTNULL(button, "Test fixture: the lattice has no surge button")
+ TEST_ASSERT(button.Trigger(), "The first press didn't surge")
+ var/datum/status_effect/cyberware_cascade_window/window = user.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+ TEST_ASSERT_NOTNULL(window, "The first press didn't open the window")
+ var/cooldown_end = button.next_use_time
+ TEST_ASSERT(cooldown_end > world.time, "Test fixture: the press didn't start the cooldown")
+ sleep(0.5 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "Test fixture: the NPC isn't slowed")
+
+ TEST_ASSERT(button.IsAvailable(), "The surge can't be pressed while its window runs")
+ TEST_ASSERT(button.Trigger(), "The second press did nothing")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_window), "The second press didn't end the window")
+ TEST_ASSERT_NULL(window.time_stop, "The slow-mo outlived the window")
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC stayed slow after the window was cut short")
+ TEST_ASSERT_EQUAL(button.next_use_time, cooldown_end, "Cutting the window short changed the cooldown")
+
+ // The crash lands once the replay of the shortened slow-mo is over, and the surge can't be pressed in between.
+ TEST_ASSERT(!button.Trigger(), "A press went through during the replay")
+ wait_replay(user)
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "Ending the window early skipped the crash")
+
+ // In the crash, and after it, the button is back on its cooldown.
+ TEST_ASSERT(!button.IsAvailable(), "The surge could be pressed in the crash")
+ TEST_ASSERT(!button.Trigger(), "A third press went through")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ TEST_ASSERT(!button.Trigger(), "A press after the crash went through on cooldown")
+ TEST_ASSERT(!user.has_status_effect(/datum/status_effect/cyberware_cascade_window), "A press opened a fresh window on cooldown")
+
+ // An NPC pressing its own surge again doesn't end it.
+ var/mob/living/carbon/human/npc/surger = make_surger(spot(3, 0))
+ var/datum/action/cooldown/cyberware/cascade_surge/npc_button = surge_button(surger)
+ TEST_ASSERT(npc_button.Trigger(), "The NPC's press didn't surge")
+ TEST_ASSERT(!npc_button.IsAvailable(), "An NPC's surge reads as pressable in its window")
+ npc_button.Trigger()
+ TEST_ASSERT(surger.has_status_effect(/datum/status_effect/cyberware_cascade_window), "An NPC's second press ended its window")
+ end_surge(surger)
+
+/// A player coming in range mid-surge ends the slow-mo; the surge carries on as a plain one, with the plain trail
+/datum/unit_test/voidcrew_cyberware_timestop/player_walks_in
+
+/datum/unit_test/voidcrew_cyberware_timestop/player_walks_in/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/other = allocate(/mob/living/carbon/human/consistent, spot(3, 3))
+ var/opened = world.time
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ TEST_ASSERT_EQUAL(window.duration - opened, 13 SECONDS, "The slow-mo doesn't run its own, longer length")
+ other.key = "sandytimestopother"
+ sleep(0.5 SECONDS) // a couple of field ticks
+ TEST_ASSERT_NULL(window.time_stop, "The slow-mo carried on with a player in range")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_window), "The surge ended with the slow-mo")
+ TEST_ASSERT_EQUAL(window.duration - opened, 8 SECONDS, "The surge carries on past a plain surge's length once a player is near")
+ var/turf/start = get_turf(user)
+ user.Move(spot(0, 1), NORTH)
+ TEST_ASSERT(get_turf(user) != start, "Test fixture: the user couldn't step")
+ TEST_ASSERT_NULL(locate(/obj/effect/temp_visual/decoy/fading/cascade/stopped) in spot(0, 0), "The slow-mo trail outlived the slow-mo")
+ end_surge(user)
+
+/// Another player near: the plain surge, no dilation
+/datum/unit_test/voidcrew_cyberware_timestop/witnessed
+
+/datum/unit_test/voidcrew_cyberware_timestop/witnessed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/other = allocate(/mob/living/carbon/human/consistent, spot(3, 3))
+ other.key = "sandytimestopother" // a player body, client or not
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NULL(window.time_stop, "Time slowed with another player in sight")
+ TEST_ASSERT(window.duration - world.time <= 8 SECONDS, "A plain surge got the slow-mo's longer length")
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC was slowed without a dilation")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// The user's own mech runs at full speed in their slow-mo, whether they were in it at the surge or climbed in after
+/datum/unit_test/voidcrew_cyberware_timestop/own_mech_free
+
+/datum/unit_test/voidcrew_cyberware_timestop/own_mech_free/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/obj/vehicle/sealed/mecha/ripley/mech = allocate(/obj/vehicle/sealed/mecha/ripley, spot(0, 0))
+ var/obj/vehicle/sealed/mecha/ripley/other_mech = allocate(/obj/vehicle/sealed/mecha/ripley, spot(2, 2))
+ user.forceMove(mech) // moved_inside() wants a client
+ if(!mech.is_occupant(user))
+ mech.add_occupant(user)
+ TEST_ASSERT(mech.is_occupant(user), "Test fixture: the user isn't in the mech")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(!field.held_mechs[mech], "The user's own mech was slowed")
+ TEST_ASSERT(!tinted(mech), "The user's own mech was tinted")
+ TEST_ASSERT(field.held_mechs[other_mech], "An empty mech in the field wasn't slowed")
+
+ // Out of the first mech and into the slowed one: it's let go on the next tick.
+ mech.mob_exit(user, silent = TRUE)
+ user.forceMove(other_mech) // moved_inside() wants a client
+ if(!other_mech.is_occupant(user))
+ other_mech.add_occupant(user)
+ // Two of the field's own ticks after the climb (its clock is a looping timer, which can run late under load).
+ var/climbed = world.time
+ var/until = world.time + 2 SECONDS
+ var/ticks_seen = 0
+ var/last_seen = field.last_tick
+ while(ticks_seen < 2 && world.time < until && !QDELETED(field))
+ sleep(world.tick_lag)
+ if(field.last_tick != last_seen && field.last_tick > climbed)
+ ticks_seen++
+ last_seen = field.last_tick
+ TEST_ASSERT(ticks_seen >= 2, "Test fixture: the field stopped ticking")
+ TEST_ASSERT(!field.held_mechs[other_mech], "A mech the user climbed into stayed slowed")
+ TEST_ASSERT(!tinted(other_mech), "A mech the user climbed into stayed tinted")
+ other_mech.mob_exit(user, silent = TRUE)
+ end_surge(user)
+
+/// A player hidden in a locker, or picked up and carried as an item, still counts as someone near
+/datum/unit_test/voidcrew_cyberware_timestop/witnessed_hidden
+
+/datum/unit_test/voidcrew_cyberware_timestop/witnessed_hidden/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/obj/structure/closet/locker = allocate(/obj/structure/closet, spot(3, 0))
+ var/mob/living/carbon/human/hider = allocate(/mob/living/carbon/human/consistent, spot(3, 0))
+ hider.key = "sandytimestophider"
+ hider.forceMove(locker)
+ TEST_ASSERT(cyberware_time_stop_witnessed(user), "A player in a locker didn't count as someone near")
+ hider.key = null
+ var/mob/living/basic/mouse/pet = allocate(/mob/living/basic/mouse, spot(2, 2))
+ pet.key = "sandytimestoppet"
+ var/obj/item/mob_holder/holder = allocate(/obj/item/mob_holder, spot(2, 2), pet)
+ TEST_ASSERT(pet.loc == holder, "The mouse wasn't picked up")
+ TEST_ASSERT(cyberware_time_stop_witnessed(user), "A player carried as an item didn't count as someone near")
+ pet.key = null
+ TEST_ASSERT(!cyberware_time_stop_witnessed(user), "Nobody's near, but the user counted as watched")
+
+/// An NPC's surge never slows the world, whoever is near
+/datum/unit_test/voidcrew_cyberware_timestop/npc_surge
+
+/datum/unit_test/voidcrew_cyberware_timestop/npc_surge/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), null)
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NULL(window.time_stop, "A surge with no player behind it slowed the world")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A gib thrown across the floor in the slow-mo crosses it at the field's pace, and as many tiles as it would have.
+/datum/unit_test/voidcrew_cyberware_timestop/gibs_fly_slowed
+
+/datum/unit_test/voidcrew_cyberware_timestop/gibs_fly_slowed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopgibs")
+ set_window(user, 3 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ var/scale = field.time_scale
+ var/obj/effect/decal/cleanable/blood/gibs/chunk = allocate(/obj/effect/decal/cleanable/blood/gibs, spot(1, 2))
+ TEST_ASSERT_NOTNULL(cyberware_time_field(chunk), "Test fixture: the gib isn't in the field")
+ var/datum/move_loop/loop = GLOB.move_manager.move_to(chunk, spot(5, 2), delay = 2, timeout = 6)
+ TEST_ASSERT_NOTNULL(loop, "Test fixture: the gib has no move loop")
+ chunk.sandy_flight_delay = loop.delay
+ TEST_ASSERT(chunk.sandy_flight_pace(loop), "A gib's flight across the floor wasn't slowed in the field")
+ TEST_ASSERT(abs(loop.delay - 2 / scale) < 0.5, "A slowed gib takes [loop.delay] a tile at [scale * 100]%, not [2 / scale]")
+ TEST_ASSERT(abs(loop.lifetime / loop.delay - 3) < 0.01, "A slowed gib has [loop.lifetime / loop.delay] steps left of the 3 it was thrown")
+ qdel(loop)
+ // The blood a hit knocks out of a body flies the same way
+ var/obj/effect/decal/cleanable/blood/hitsplatter/splash = allocate(/obj/effect/decal/cleanable/blood/hitsplatter, spot(1, 3))
+ splash.fly_towards(spot(4, 3), 3)
+ var/datum/move_loop/flight = splash.move_packet?.running_loop
+ TEST_ASSERT_NOTNULL(flight, "Test fixture: the hit's blood has no move loop")
+ TEST_ASSERT(abs(flight.delay - splash.sandy_flight_delay / scale) < 0.5, "A hit's blood crosses a tile in [flight.delay] at [scale * 100]%, not [splash.sandy_flight_delay / scale]")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Everything in the field runs on its own slowed clock: gore timing, do_after, bursts, mechs, turrets, fuses
+/datum/unit_test/voidcrew_cyberware_timestop/slow_everything
+
+/datum/unit_test/voidcrew_cyberware_timestop/slow_everything/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ set_window(user, 2 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/obj/item/gun/ballistic/automatic/pistol/raider_gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ raider.put_in_hands(raider_gun)
+ var/obj/item/gun/ballistic/automatic/pistol/user_gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ user.put_in_hands(user_gun)
+ var/mob/living/basic/mouse/rat = allocate(/mob/living/basic/mouse, spot(1, 2))
+ rat.AddComponent(/datum/component/ranged_attacks, projectile_type = /obj/projectile/beam, burst_shots = 3)
+ var/obj/vehicle/sealed/mecha/ripley/mech = allocate(/obj/vehicle/sealed/mecha/ripley, spot(3, 2))
+ var/obj/machinery/porta_turret/turret = allocate(/obj/machinery/porta_turret, spot(3, 1))
+ var/obj/effect/decal/cleanable/blood/pool = allocate(/obj/effect/decal/cleanable/blood, spot(2, 1))
+ // Drips drawn in another drip's vis_contents with RESET_COLOR, as tg's make_blood_splatter() adds them
+ var/obj/effect/decal/cleanable/blood/drip/drips = allocate(/obj/effect/decal/cleanable/blood/drip, spot(1, 3))
+ var/obj/effect/decal/cleanable/blood/drip/drop = allocate(/obj/effect/decal/cleanable/blood/drip, drips)
+ drop.appearance_flags |= RESET_COLOR
+ drips.vis_contents += drop
+ var/obj/effect/decal/cleanable/blood/gibs/gibs = allocate(/obj/effect/decal/cleanable/blood/gibs, spot(2, 3))
+ var/obj/item/grenade/bomb = allocate(/obj/item/grenade, spot(1, 1))
+ bomb.arm_grenade(null, 3 SECONDS, msg = FALSE)
+
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+
+ // The NPC's clock runs at the model's pace from the start; the user's doesn't slow.
+ var/scale = field.time_scale
+ TEST_ASSERT(scale > 0 && scale < 1, "Test fixture: the field's pace is [scale]")
+ var/lost = cyberware_time_lost(raider, 10)
+ TEST_ASSERT(abs(lost - 10 * (1 - scale)) < 0.1, "A slowed NPC's clock didn't run at [scale * 100]% (lost [lost] of 10)")
+ TEST_ASSERT_EQUAL(cyberware_time_lost(user, 10), 0, "The user's clock slowed")
+ TEST_ASSERT_EQUAL(cyberware_dilated_time(user, 10), 10, "The user's animations would be slowed")
+ TEST_ASSERT_NULL(cyberware_time_field(user_gun), "Something the user holds would be slowed")
+ var/gore = cyberware_dilated_time(raider, 1)
+ TEST_ASSERT(abs(gore - 1 / scale) < 0.1, "A slowed NPC's gore doesn't play at [scale * 100]% ([gore] for 1)")
+ TEST_ASSERT_NOTNULL(cyberware_time_field(pool), "Blood on the floor in the field isn't slowed")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/pool_field = GLOB.cyberware_time_dilated[pool]
+ TEST_ASSERT(pool_field?.tinted[pool], "Blood in the field isn't tinted with the world")
+ var/list/steps = cyberware_dilated_steps(raider, list(1, 1))
+ var/both = cyberware_dilated_time(raider, 2) // the second step may run past the window's end, back at full speed
+ TEST_ASSERT(length(steps) == 2 && abs(steps[1] - 1 / scale) < 0.1 && abs(steps[1] + steps[2] - both) < 0.1, "A slowed NPC's flinch doesn't play at [scale * 100]% from its first step ([jointext(steps, ",")], [both] in all)")
+
+ // Bursts queued in the slow-mo wait longer.
+ raider_gun.cyberware_burst_start = cyberware_burst_clock(raider)
+ raider_gun.cyberware_burst_gap = 1
+ var/datum/component/ranged_attacks/rat_gun = rat.GetComponent(/datum/component/ranged_attacks)
+ rat_gun.cyberware_burst_start = cyberware_burst_clock(rat)
+ var/gun_start = raider_gun.cyberware_burst_start
+ var/rat_start = rat_gun.cyberware_burst_start
+
+ // Machines and fuses: nothing is shut down, every clock runs slow.
+ TEST_ASSERT(!mech.completely_disabled, "The dilation shut a mech down")
+ TEST_ASSERT(field.held_mechs[mech], "A mech in the field wasn't taken")
+ TEST_ASSERT(field.held_turrets[turret], "A turret in the field wasn't taken")
+ TEST_ASSERT(field.held_grenades[bomb], "A lit grenade in the field wasn't taken")
+ turret.last_fired = world.time
+ var/fired_at = turret.last_fired
+ mech.cooldown_vehicle_move = world.time + 5
+ var/move_at = mech.cooldown_vehicle_move
+ // A gut strand drawn in the slow-mo: one tile across and one up is 45 px, so its last segment is cut short and
+ // drawn with its own icon, which tg's Draw() colours after the field has tinted it
+ var/datum/beam/strand = raider.Beam(turret, "gut_beam", 'voidcrew/modules/hyperviolence/braingut/icons/gore_guts.dmi', INFINITY, 10, /obj/effect/ebeam/hv_gut, emissive = FALSE)
+
+ sleep(0.5 SECONDS)
+ // Blood and gore take the world's tint, including what a `color` tint can't reach (RESET_COLOR overlays and vis_contents)
+ TEST_ASSERT(tinted(raider), "A slowed NPC wasn't tinted")
+ TEST_ASSERT(raider.filter_data?["sandy_time_stop_tint"], "A slowed NPC's tint doesn't cover its wound and blood overlays")
+ TEST_ASSERT(tinted(drop), "A drip drawn in another drip's vis_contents kept its colour in the slow-mo")
+ TEST_ASSERT(islist(drop.color), "A drip in the slow-mo isn't drawn with the tint")
+ TEST_ASSERT(gib_bits_tinted(gibs), "A gib's meat overlay kept its colour in the slow-mo")
+ TEST_ASSERT(length(strand.elements) == 2, "Test fixture: the strand isn't two segments ([length(strand.elements)])")
+ for(var/obj/effect/ebeam/segment as anything in strand.elements)
+ TEST_ASSERT(islist(segment.color), "A gut strand segment drawn in the slow-mo kept its colour ([segment.color], own icon: [isicon(segment.icon)])")
+ // A blood splash's art is white, coloured by its `color`: the tint goes over its blood colour, never in place of it
+ var/obj/effect/temp_visual/dir_setting/bloodsplatter/splash = new(spot(2, 2), EAST, BLOOD_COLOR_RED)
+ var/list/worn = LAZYACCESS(splash.atom_colours, TEMPORARY_COLOUR_PRIORITY) // `color` itself reads back as a 20-number matrix
+ TEST_ASSERT(islist(splash.color) && worn && compare_list(worn[ATOM_COLOR_VALUE_INDEX], cyberware_time_tint_of(BLOOD_COLOR_RED)), "A blood splash made in the slow-mo is drawn pale, its white art under the bare tint ([json_encode(splash.atom_colours)])")
+ TEST_ASSERT(tinted(splash), "A blood splash made in the slow-mo isn't counted as tinted")
+ // 0.5 s at 20% or less is at most 1 decisecond of the NPC's own time: a 2 decisecond gap is still waiting, at full speed it's long gone
+ TEST_ASSERT(cyberware_burst_wait(raider, raider_gun.cyberware_burst_start, 2, 1) > 0, "A queued burst shot fired at full speed")
+ TEST_ASSERT(raider_gun.cyberware_burst_start > gun_start, "The NPC's burst clock wasn't pushed back")
+ TEST_ASSERT(rat_gun.cyberware_burst_start > rat_start, "A basic mob's burst clock wasn't pushed back")
+ TEST_ASSERT(turret.last_fired > fired_at, "A slowed turret's fire cooldown wasn't pushed back")
+ TEST_ASSERT(mech.cooldown_vehicle_move > move_at, "A slowed mech's move cooldown wasn't pushed back")
+ TEST_ASSERT(!mech.completely_disabled, "The dilation shut a mech down")
+ TEST_ASSERT(!(bomb.dud_flags & GRENADE_USED), "A grenade's fuse burned through at full speed")
+
+ // Just past the window: the replay of a 2 s slow-mo is over in a few tenths at the deeper slow-mos, so look as it starts
+ var/window_until = world.time + 2 SECONDS
+ while(!QDELETED(window) && window.time_stop && world.time < window_until)
+ sleep(world.tick_lag)
+ TEST_ASSERT_NULL(window.time_stop, "The slow-mo outlived the window")
+ TEST_ASSERT_EQUAL(cyberware_time_lost(raider, 10), 0, "The NPC's clock stayed slow after the dilation")
+ TEST_ASSERT_NULL(cyberware_time_field(pool), "Blood stayed slowed after the dilation")
+ TEST_ASSERT(istext(pool.color), "Blood kept the slow-mo's tint, or lost its own colour, after the dilation")
+ TEST_ASSERT(!tinted(raider), "An NPC kept the slow-mo's tint after the dilation")
+ TEST_ASSERT(!tinted(drop) && istext(drop.color), "A drip kept the slow-mo's tint, or lost its own colour, after the dilation")
+ // The replay is playing now: the gib shows its recorded look, which must be untinted too
+ TEST_ASSERT(GLOB.sandy_replays[user], "Test fixture: no replay after the slow-mo")
+ TEST_ASSERT(!gib_bits_tinted(gibs), "A gib's meat overlay kept the slow-mo's tint in the replay ([gib_diag(gibs)])")
+ for(var/obj/effect/ebeam/segment as anything in strand.elements)
+ TEST_ASSERT(!islist(segment.color), "A gut strand segment kept the slow-mo's tint after the dilation")
+ wait_replay(user)
+ TEST_ASSERT(!gib_bits_tinted(gibs), "A gib's meat overlay kept the slow-mo's tint after the replay ([gib_diag(gibs)])")
+ qdel(strand)
+ TEST_ASSERT(!(bomb.dud_flags & GRENADE_USED), "A grenade's fuse didn't lose its slowed time")
+ TEST_ASSERT(bomb.cyberware_fuse_at > world.time, "A grenade's fuse has nothing left after losing time")
+ bomb.cyberware_fuse_at = 0 // don't let it go off after the test
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Whether `thing` wears the dilation's tint
+/datum/unit_test/voidcrew_cyberware_timestop/proc/tinted(atom/thing)
+ return cyberware_time_has_tint(thing)
+
+/// Whether `gibs`' meat and bone overlay is drawn with a colour matrix
+/datum/unit_test/voidcrew_cyberware_timestop/proc/gib_bits_tinted(obj/effect/decal/cleanable/blood/gibs/gibs)
+ for(var/mutable_appearance/bit as anything in gibs.overlays)
+ if(bit.icon_state == "[gibs.icon_state]-overlay" && islist(bit.color))
+ return TRUE
+ return FALSE
+
+/// What `gibs` is drawn with, for a failure message
+/datum/unit_test/voidcrew_cyberware_timestop/proc/gib_diag(obj/effect/decal/cleanable/blood/gibs/gibs)
+ var/list/meat = list()
+ for(var/mutable_appearance/bit as anything in gibs.overlays)
+ if(bit.icon_state == "[gibs.icon_state]-overlay")
+ meat += json_encode(bit.color)
+ return "meat [meat.Join(" ")], color [json_encode(gibs.color)], atom_colours [json_encode(gibs.atom_colours)], dilated [!!GLOB.cyberware_time_dilated[gibs]], puppet [!!GLOB.sandy_replay_masked[gibs]]"
+
+/// A raider NPC at `where` with its own Cascade lattice (or `lattice_type`)
+/datum/unit_test/voidcrew_cyberware_timestop/proc/make_surger(turf/where, lattice_type = /obj/item/organ/cyberimp/cyberware/cascade)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, where)
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = allocate(lattice_type)
+ TEST_ASSERT(lattice.Insert(raider, special = TRUE), "Test fixture: the lattice wouldn't go in the NPC")
+ return raider
+
+/// No reflex dodge, speed or crit edge while the user's own world is slowed, but the quicker blows stay (decisions 22);
+/// all of it is there as before if the slow-mo ends before the window does
+/datum/unit_test/voidcrew_cyberware_timestop/no_dodge_while_slowed
+
+/datum/unit_test/voidcrew_cyberware_timestop/no_dodge_while_slowed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/obj/item/knife/kitchen/knife = allocate(/obj/item/knife/kitchen, spot(1, 0))
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ TEST_ASSERT_NOTNULL(window, "The lattice's window didn't open")
+ window.dodge_chance = 100
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/component/cyberware_dodge/arbiter = user.GetComponent(/datum/component/cyberware_dodge)
+ TEST_ASSERT_NOTNULL(arbiter, "The window has no dodge")
+ TEST_ASSERT(cyberware_time_stopping(user), "The user isn't marked as slowing time")
+ TEST_ASSERT_EQUAL(arbiter.on_check_block(user, knife, 10, "the knife", MELEE_ATTACK), FAILED_BLOCK, "The user dodged a blow in slow-mo")
+ TEST_ASSERT(!user.has_movespeed_modifier(window.speed_type), "The user kept the surge's speed in slow-mo")
+ TEST_ASSERT(!LAZYACCESS(user.hv_crit_attacker_bonuses, window.id), "The user kept the surge's crit edge in slow-mo")
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ TEST_ASSERT_NOTNULL(lattice, "Test fixture: the user has no lattice")
+ TEST_ASSERT(lattice.window_melee_mult < 1, "Test fixture: the lattice gives no quicker blows")
+ TEST_ASSERT_EQUAL(window.nextmove_modifier(), lattice.window_melee_mult, "The user lost the surge's quicker blows in slow-mo")
+ user.changeNext_move(CLICK_CD_MELEE)
+ TEST_ASSERT(abs(user.next_move - world.time - CLICK_CD_MELEE * lattice.window_melee_mult) < 0.01, "A blow in slow-mo didn't come at the surge's rate ([user.next_move - world.time] for [CLICK_CD_MELEE])")
+ user.next_move = world.time
+ sleep(1.2 SECONDS)
+ TEST_ASSERT_EQUAL(arbiter.on_check_block(user, knife, 10, "the knife", MELEE_ATTACK), FAILED_BLOCK, "The user dodged a blow later in slow-mo")
+ qdel(window.time_stop) // as when a player comes in range
+ TEST_ASSERT_NULL(window.time_stop, "Test fixture: the dilation didn't end")
+ TEST_ASSERT(!cyberware_time_stopping(user), "The user still counts as slowing time")
+ TEST_ASSERT_EQUAL(arbiter.on_check_block(user, knife, 10, "the knife", MELEE_ATTACK), SUCCESSFUL_BLOCK, "The dodge didn't come back after the slow-mo ended")
+ TEST_ASSERT(user.has_movespeed_modifier(window.speed_type), "The surge's speed didn't come back after the slow-mo ended")
+ TEST_ASSERT_EQUAL(LAZYACCESS(user.hv_crit_attacker_bonuses, window.id), window.crit_bonus, "The surge's crit edge didn't come back after the slow-mo ended")
+ TEST_ASSERT_EQUAL(window.nextmove_modifier(), lattice.window_melee_mult, "The surge's quicker blows changed after the slow-mo ended")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// An NPC already surging when the user slows the world runs at its own speed, and so do its shots
+/datum/unit_test/voidcrew_cyberware_timestop/surging_npc_immune
+
+/datum/unit_test/voidcrew_cyberware_timestop/surging_npc_immune/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(2, 0))
+ var/obj/projectile/bullet/shot = allocate(/obj/projectile/bullet, spot(1, 1))
+ shot.firer = raider
+ var/shot_speed = shot.speed
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(field.surging[raider], "The field didn't notice the NPC's surge")
+ TEST_ASSERT(!frozen(raider), "A surging NPC was frozen")
+ TEST_ASSERT(!tinted(raider), "A surging NPC was tinted")
+ TEST_ASSERT_EQUAL(cyberware_time_lost(raider, 10), 0, "A surging NPC's clock slowed")
+ TEST_ASSERT_NULL(cyberware_time_field(raider), "A surging NPC's gore would be slowed")
+ TEST_ASSERT(field.held_shots[shot] && shot.speed == shot_speed * field.time_scale, "A surging NPC's shot doesn't fly at the field's pace like every bullet")
+ sleep(0.5 SECONDS) // a couple of field ticks
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "A surging NPC was slowed")
+
+ // Its window closes: the field takes it like anyone else.
+ raider.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ sleep(0.3 SECONDS)
+ TEST_ASSERT(!field.surging[raider], "The field kept leaving the NPC be after its window closed")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The NPC wasn't slowed once its window closed")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ raider.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// An NPC held in slow-mo that surges breaks free at once and drops every slow it carried
+/datum/unit_test/voidcrew_cyberware_timestop/late_surge_breaks_free
+
+/datum/unit_test/voidcrew_cyberware_timestop/late_surge_breaks_free/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(2, 0))
+ var/obj/projectile/bullet/shot = allocate(/obj/projectile/bullet, spot(1, 1))
+ shot.firer = raider
+ var/shot_speed = shot.speed
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ sleep(0.3 SECONDS)
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "Test fixture: the NPC isn't slowed")
+ TEST_ASSERT(field.held_shots[shot], "Test fixture: the NPC's shot isn't held")
+ raider.hv_vis_play("sandy_test_flinch", list(list(2, 0, matrix(), 2, LINEAR_EASING), list(0, 0, matrix(), 2, LINEAR_EASING)))
+ TEST_ASSERT("sandy_test_flinch" in field.slowed_tags[raider], "A held NPC's slowed animation wasn't noted")
+
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ TEST_ASSERT(field.surging[raider], "The field didn't let the surging NPC go")
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The surging NPC stayed slowed")
+ TEST_ASSERT(!frozen(raider), "The surging NPC was frozen")
+ TEST_ASSERT(!tinted(raider), "The surging NPC stayed tinted")
+ TEST_ASSERT_NULL(GLOB.cyberware_time_dilated[raider], "The surging NPC is still in the field's hands")
+ TEST_ASSERT_EQUAL(cyberware_time_lost(raider, 10), 0, "The surging NPC's clock stayed slow")
+ TEST_ASSERT_NULL(field.slowed_tags[raider], "The surging NPC's slowed animations weren't dropped")
+ TEST_ASSERT(field.held_shots[shot] && shot.speed == shot_speed * field.time_scale, "The surging NPC's shot left the field's pace")
+ sleep(0.5 SECONDS) // a few field ticks
+ TEST_ASSERT(!raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The field took the surging NPC back")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ raider.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ raider.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Ends `body`'s window and crash, for the end of a test
+/datum/unit_test/voidcrew_cyberware_timestop/proc/end_surge(mob/living/body)
+ body.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ body.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A surging mob runs at its own multiplier over the user's, at most twice normal speed
+/datum/unit_test/voidcrew_cyberware_timestop/relative_rates
+
+/datum/unit_test/voidcrew_cyberware_timestop/relative_rates/Run()
+ var/obj/item/organ/cyberimp/cyberware/cascade/street/street = allocate(/obj/item/organ/cyberimp/cyberware/cascade/street)
+ var/obj/item/organ/cyberimp/cyberware/cascade/milspec/service = allocate(/obj/item/organ/cyberimp/cyberware/cascade/milspec)
+ var/obj/item/organ/cyberimp/cyberware/cascade/cascade = allocate(/obj/item/organ/cyberimp/cyberware/cascade)
+ TEST_ASSERT_EQUAL(street.time_multiplier, 2.5, "The street rig isn't 2.5x")
+ TEST_ASSERT_EQUAL(service.time_multiplier, 4, "The service lattice isn't 4x")
+ TEST_ASSERT_EQUAL(cascade.time_multiplier, 10, "The Cascade isn't 10x")
+
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT_EQUAL(field.user_multiplier, 10, "A Cascade user's field doesn't know they run at 10x")
+ TEST_ASSERT(abs(field.relative_rate(2.5) - 0.25) < 0.001, "A street surger in a Cascade's field isn't at 25%")
+ TEST_ASSERT_EQUAL(field.relative_rate(10), 1, "An equal surger isn't at full speed")
+ field.user_multiplier = 2.5 // as a street user's field
+ TEST_ASSERT_EQUAL(field.relative_rate(10), 2, "A Cascade surger in a street user's field isn't capped at 200%")
+ TEST_ASSERT(abs(field.relative_rate(4) - 1.6) < 0.001, "A service surger in a street user's field isn't at 160%")
+ field.user_multiplier = 10
+ end_surge(user)
+
+/// A slower surger in the user's field is held at its relative rate for the whole window, never frozen or tinted
+/datum/unit_test/voidcrew_cyberware_timestop/slower_surger
+
+/datum/unit_test/voidcrew_cyberware_timestop/slower_surger/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(2, 0), /obj/item/organ/cyberimp/cyberware/cascade/street)
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(field.surging[raider], "The field didn't notice the NPC's surge")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.25) < 0.001, "A street surger in a Cascade's field isn't at 25% ([cyberware_time_scale(raider)])")
+ TEST_ASSERT(!frozen(raider), "A surging NPC was frozen")
+ TEST_ASSERT(!tinted(raider), "A surging NPC was tinted")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "A slower surger isn't slowed")
+ var/lost = cyberware_time_lost(raider, 10)
+ TEST_ASSERT(lost > 7.4 && lost < 7.6, "A slower surger's clock didn't run at 25% (lost [lost] of 10)")
+ sleep(1.2 SECONDS) // later in the window: the surger keeps its own rate
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.25) < 0.001, "A surger's rate changed mid-window ([cyberware_time_scale(raider)])")
+ TEST_ASSERT(raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "A slower surger stopped being slowed mid-window")
+ end_surge(user)
+ end_surge(raider)
+
+/// A faster surger runs faster than normal: deadlines sooner, a quicker walk, quicker shots and gore
+/datum/unit_test/voidcrew_cyberware_timestop/faster_surger
+
+/datum/unit_test/voidcrew_cyberware_timestop/faster_surger/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser", /obj/item/organ/cyberimp/cyberware/cascade/street)
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(2, 0))
+ var/obj/projectile/bullet/shot = allocate(/obj/projectile/bullet, spot(1, 1))
+ shot.firer = raider
+ var/shot_speed = shot.speed
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT_EQUAL(field.user_multiplier, 2.5, "A street user's field doesn't know they run at 2.5x")
+ TEST_ASSERT(field.held_shots[shot], "Test fixture: the NPC's shot isn't held before it surges")
+
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ TEST_ASSERT_EQUAL(cyberware_time_scale(raider), 2, "A Cascade surger in a street user's field isn't capped at 200%")
+ TEST_ASSERT(!tinted(raider), "A faster surger was tinted")
+ TEST_ASSERT_EQUAL(cyberware_time_lost(raider, 10), -10, "A faster surger's clock doesn't run at double speed")
+ TEST_ASSERT_EQUAL(cyberware_dilated_time(raider, 10), 5, "A faster surger's gore doesn't play at double speed")
+ var/datum/movespeed_modifier/pace = raider.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation)
+ TEST_ASSERT(pace && pace.multiplicative_slowdown <= 0, "A faster surger doesn't walk faster")
+ TEST_ASSERT(field.held_shots[shot] && shot.speed == shot_speed * field.time_scale, "A faster surger's shot doesn't fly at the field's pace")
+ TEST_ASSERT(!tinted(shot), "A surger's shot was tinted")
+
+ var/next_move_was = world.time + 5 SECONDS
+ raider.next_move = next_move_was
+ sleep(0.5 SECONDS) // a couple of field ticks
+ TEST_ASSERT(raider.next_move < next_move_was - 0.3 SECONDS, "A faster surger's deadlines didn't come sooner")
+ end_surge(user)
+ end_surge(raider)
+
+/// Every bullet in the field flies at the field's pace, whoever fired it: the user's and a surging NPC's alike, untinted
+/datum/unit_test/voidcrew_cyberware_timestop/shots_at_field_pace
+
+/datum/unit_test/voidcrew_cyberware_timestop/shots_at_field_pace/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(3, 0))
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ TEST_ASSERT(field.time_scale > 0 && field.time_scale < 1, "Test fixture: not in the slow-mo")
+
+ var/obj/projectile/bullet/user_shot = allocate(/obj/projectile/bullet, spot(1, 0))
+ user_shot.firer = user
+ field.take_user_shot(user_shot)
+ var/user_speed = field.held_shots[user_shot] // its own speed: the field may have taken it as it appeared
+ TEST_ASSERT(field.held_shots[user_shot] && !user_shot.paused, "The user's slow-mo shot wasn't held, or hung")
+ TEST_ASSERT_EQUAL(user_shot.speed, user_speed * field.time_scale, "The user's slow-mo shot doesn't crawl at the field's pace")
+ TEST_ASSERT(!tinted(user_shot), "The user's slow-mo shot was tinted")
+
+ var/obj/projectile/bullet/npc_shot = allocate(/obj/projectile/bullet, spot(2, 0))
+ npc_shot.firer = raider
+ field.freeze_atom(npc_shot)
+ SEND_SIGNAL(npc_shot, COMSIG_PROJECTILE_FIRE) // made, then fired
+ var/npc_speed = field.held_shots[npc_shot]
+ TEST_ASSERT(field.held_shots[npc_shot] && !npc_shot.paused, "A surging NPC's shot wasn't held, or hung")
+ TEST_ASSERT_EQUAL(npc_shot.speed, npc_speed * field.time_scale, "A surging NPC's shot doesn't fly at the field's pace")
+ TEST_ASSERT(!tinted(npc_shot), "A surging NPC's shot was tinted")
+
+ end_surge(user)
+ TEST_ASSERT_NULL(window.time_stop, "The slow-mo outlived the window")
+ TEST_ASSERT_EQUAL(user_shot.speed, user_speed, "The user's shot didn't get its speed back")
+ TEST_ASSERT_EQUAL(npc_shot.speed, npc_speed, "The NPC's shot didn't get its speed back")
+ end_surge(raider)
+
+/// A surging NPC that dies is let go for good: its corpse isn't taken back and tinted
+/datum/unit_test/voidcrew_cyberware_timestop/no_corpse_retake
+
+/datum/unit_test/voidcrew_cyberware_timestop/no_corpse_retake/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = make_surger(spot(2, 0), /obj/item/organ/cyberimp/cyberware/cascade/street)
+ TEST_ASSERT_NOTNULL(surge(raider), "The NPC's window didn't open")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT(field.surging[raider], "Test fixture: the field didn't notice the NPC's surge")
+ raider.death()
+ sleep(0.5 SECONDS) // a couple of field ticks
+ TEST_ASSERT(!field.surging[raider], "The field kept a dead surger as surging")
+ TEST_ASSERT_NULL(GLOB.cyberware_time_dilated[raider], "The field took a dead surger back")
+ TEST_ASSERT(!tinted(raider), "A dead surger's corpse was tinted")
+ TEST_ASSERT(field.released[raider], "A dead surger wasn't let go for good")
+ end_surge(user)
+ end_surge(raider)
+
+/// The user hears the slowed world slowed (ware_sandy_senses.dm): world sounds in the field take its pace at full
+/// volume; their own sounds, sounds from outside the field and other listeners don't.
+/datum/unit_test/voidcrew_cyberware_timestop/heard_slowed
+
+/datum/unit_test/voidcrew_cyberware_timestop/heard_slowed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(3, 0))
+ var/turf/far = locate(user.x + 40, user.y, user.z) || locate(1, user.y, user.z)
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, get_turf(raider), raider), 1, "A sound was slowed with no dilation running")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ TEST_ASSERT_NOTNULL(field.senses, "The field has no senses for its user")
+
+ // From the start: the world at the field's pace, as loud as ever.
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, get_turf(raider), raider), field.time_scale, "A world sound didn't take the slow-mo pace")
+ var/sound/shot = sound('sound/items/weapons/gun/pistol/shot.ogg')
+ shot.volume = 100
+ cyberware_dilate_heard(user, get_turf(raider), shot, raider)
+ TEST_ASSERT(shot.frequency == field.time_scale, "A world sound went out at frequency [shot.frequency]")
+ TEST_ASSERT_EQUAL(shot.volume, 100, "A slowed world sound was made quieter")
+ TEST_ASSERT_EQUAL(field.senses.loop_speed, field.time_scale, "The user's loops didn't take the slow-mo pace")
+
+ // The user's own sounds, other listeners and far sounds stay as they are.
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, get_turf(user), raider), 1, "A sound on the user's own tile was slowed")
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, get_turf(raider), user), 1, "A sound the user set off was slowed")
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(raider, get_turf(raider), null), 1, "Someone other than the user heard it slowed")
+ if(far && get_dist(far, user) > field.current_range)
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, far, null), 1, "A sound from outside the field was slowed")
+ TEST_ASSERT_EQUAL(cyberware_scaled_frequency(44100, 0.5), 22050, "A rate in Hz didn't scale")
+ TEST_ASSERT_EQUAL(cyberware_scaled_frequency(0, 0.2), 0.2, "An as-is sound didn't scale")
+
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ TEST_ASSERT_NULL(window.time_stop, "Test fixture: the dilation outlived its window")
+ TEST_ASSERT_EQUAL(cyberware_heard_speed(user, get_turf(raider), raider), 1, "Sounds stayed slowed after the dilation")
+
+/// The user sees the weather slowed through a private override image per area; the area itself never changes,
+/// and the images go when the dilation ends.
+/datum/unit_test/voidcrew_cyberware_timestop/weather_slowed
+
+/datum/unit_test/voidcrew_cyberware_timestop/weather_slowed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(1, 1), "sandytimestopuser")
+ var/area/place = get_area(user)
+ var/datum/weather/rain_storm/rain = new(list(user.z), list("areas" = list(place), "weather_flags" = WEATHER_INDOORS))
+ TEST_ASSERT(rain.impacted_areas_lookup[place], "Test fixture: the rain didn't take the test room")
+ rain.stage = MAIN_STAGE
+ rain.update_areas()
+ SSweather.processing |= rain
+ var/list/area_overlays = place.overlays.Copy()
+
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ field.senses.refresh_weather(force = TRUE) // no client in a unit test
+ var/image/slowed = field.senses.area_images[place]
+ TEST_ASSERT_NOTNULL(slowed, "The rained-on area got no image")
+ TEST_ASSERT(slowed.override, "The weather image doesn't replace the area's look")
+ TEST_ASSERT(weather_states(slowed).Find("rain_high_s20"), "The slow-mo didn't show slowed rain: [jointext(weather_states(slowed), ",")]")
+ TEST_ASSERT(!weather_states(slowed).Find("rain_high"), "The fast rain is still in the slowed image")
+ TEST_ASSERT_EQUAL(length(place.overlays), length(area_overlays), "The area's own overlays changed")
+
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ TEST_ASSERT_NULL(window.time_stop, "Test fixture: the dilation outlived its window")
+ TEST_ASSERT_NULL(field.senses, "The senses outlived the dilation")
+ TEST_ASSERT_EQUAL(length(place.overlays), length(area_overlays), "The area's own overlays changed after the dilation")
+
+ SSweather.processing -= rain
+ rain.stage = END_STAGE
+ rain.update_areas()
+ qdel(rain)
+
+/// The icon states of `slowed`'s overlays.
+/datum/unit_test/voidcrew_cyberware_timestop/weather_slowed/proc/weather_states(image/slowed)
+ . = list()
+ for(var/overlay in slowed.overlays)
+ if(overlay:icon == 'icons/effects/glow_weather.dmi')
+ continue // rain has no glow state: that overlay draws nothing either way
+ . += overlay:icon_state
+
+/// A slow-mo cut short by a player arriving after a plain surge's length has passed ends the surge at once: the
+/// slow-mo's extra seconds never carry on as a plain surge in front of another player.
+/datum/unit_test/voidcrew_cyberware_timestop/late_witness_clamped
+
+/datum/unit_test/voidcrew_cyberware_timestop/late_witness_clamped/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytimestopuser")
+ var/obj/item/organ/cyberimp/cyberware/cascade/lattice = locate() in user.organs
+ lattice.window_duration = 1 SECONDS
+ lattice.slowmo_duration = 4 SECONDS
+ var/mob/living/carbon/human/other = allocate(/mob/living/carbon/human/consistent, spot(3, 3))
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Time didn't slow with nobody else near")
+ sleep(1.5 SECONDS) // past the plain length, inside the slow-mo's
+ TEST_ASSERT(window_of_user(user), "The slow-mo ended at the plain surge's length")
+ other.key = "sandytimestopother"
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(!window_of_user(user), "The surge carried on after the slow-mo with a plain surge's time already spent")
+ TEST_ASSERT(user.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The crash didn't follow")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/datum/unit_test/voidcrew_cyberware_timestop/proc/window_of_user(mob/living/user)
+ return user.has_status_effect(/datum/status_effect/cyberware_cascade_window)
+
+/// A hit flash on a body in the slow-mo plays at its real length: a flash stretched with the body lasted seconds,
+/// a glowing corpse in the middle of the slow-mo
+/datum/unit_test/voidcrew_cyberware_timestop/hit_flash_not_slowed
+
+/datum/unit_test/voidcrew_cyberware_timestop/hit_flash_not_slowed/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandyflashuser")
+ set_window(user, 2 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(2, 0))
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS) // the field starts async
+ TEST_ASSERT_NOTNULL(window?.time_stop, "Test fixture: time didn't slow")
+ var/list/slowed = cyberware_dilated_steps(raider, list(0.5, 1.5, 1))
+ TEST_ASSERT(length(slowed) == 3 && slowed[1] > 0.5, "Test fixture: the NPC's animations aren't slowed")
+ var/list/times = raider.hv_vis_flash_times()
+ TEST_ASSERT(length(times) == 3 && times[1] == 0.5 && times[2] == 1.5 && times[3] == 1, "A hit flash in the slow-mo is slowed ([jointext(times, ",")])")
+ // The tint rolls out behind the ring: wait for it to reach the NPC
+ for(var/waited in 1 to 20)
+ if(tinted(raider))
+ break
+ sleep(0.1 SECONDS)
+ TEST_ASSERT(tinted(raider), "Test fixture: the slow-mo's tint never reached the NPC")
+ raider.hv_vis_flash()
+ TEST_ASSERT_NULL(raider.get_filter("hv_vis_flash"), "A tinted body's flash didn't play through its tint")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ wait_replay(user)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Walks `user` `steps` tiles back and forth along the bottom row, `pace` a step, as a surger who keeps moving
+/datum/unit_test/voidcrew_cyberware_timestop/proc/walk_trail(mob/living/user, steps, pace = 0.1 SECONDS)
+ var/west_end = run_loc_floor_bottom_left.x
+ var/east_end = min(west_end + 4, run_loc_floor_top_right.x)
+ var/heading = EAST
+ for(var/i in 1 to steps)
+ var/turf/next = get_step(user, heading)
+ if(next.x > east_end || next.x < west_end)
+ heading = REVERSE_DIR(heading)
+ next = get_step(user, heading)
+ TEST_ASSERT(user.Move(next, heading), "Test fixture: the surger couldn't step")
+ sleep(pace)
+
+/// The live afterimages of `type` around `user`
+/datum/unit_test/voidcrew_cyberware_timestop/proc/count_trail(mob/living/user, type)
+ . = 0
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/image in range(7, user))
+ if(istype(image, type))
+ .++
+
+/// The afterimages of `type` around `user` that don't age to the trail's oldest colour, or don't start on the colour
+/// for their age: a description of each, empty if none
+/datum/unit_test/voidcrew_cyberware_timestop/proc/off_colour_trail(mob/living/user, type)
+ . = list()
+ var/oldest = json_encode(cyberware_cascade_trail_tints()[4])
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/image in range(7, user))
+ if(!istype(image, type))
+ continue
+ var/list/through = image.aged_through
+ if(!length(through) || !islist(image.color) || json_encode(through[length(through)]) != oldest)
+ . += "[image.type] aged through [json_encode(through)]"
+
+/// A fresh afterimage is laid in the trail's newest colour (green) and aged through blue and purple to the oldest (pink)
+/datum/unit_test/voidcrew_cyberware_timestop/trail_colours
+
+/datum/unit_test/voidcrew_cyberware_timestop/trail_colours/Run()
+ var/mob/living/carbon/human/user = allocate(/mob/living/carbon/human/consistent, spot(0, 0))
+ var/list/tints = cyberware_cascade_trail_tints()
+ TEST_ASSERT_EQUAL(length(tints), 4, "The trail doesn't have four colours")
+ var/obj/effect/temp_visual/decoy/fading/cascade/fresh = new(spot(1, 0), user, 0, 230, 2 SECONDS)
+ TEST_ASSERT_EQUAL(json_encode(fresh.aged_through), json_encode(tints), "A fresh afterimage wasn't laid green and aged through blue and purple to pink")
+ TEST_ASSERT(islist(fresh.color), "A fresh afterimage has no colour matrix")
+ TEST_ASSERT_EQUAL(PLANE_TO_TRUE(fresh.plane), FLOOR_PLANE, "A fresh afterimage is drawn over bodies")
+ // Half way through its life: laid between blue and purple, aged on to purple and pink
+ var/obj/effect/temp_visual/decoy/fading/cascade/stopped/aged = new(spot(2, 0), user, 0.5, 115, 1 SECONDS)
+ TEST_ASSERT_EQUAL(length(aged.aged_through), 3, "A half-aged afterimage didn't age through purple to pink: [json_encode(aged.aged_through)]")
+ TEST_ASSERT_EQUAL(json_encode(aged.aged_through[1]), json_encode(cyberware_cascade_tint_at(0.5)), "A half-aged afterimage wasn't laid in its age's colour")
+ TEST_ASSERT_EQUAL(json_encode(aged.aged_through[3]), json_encode(tints[4]), "A half-aged afterimage didn't age to pink")
+ var/list/half = cyberware_cascade_tint_at(0.5)
+ var/list/blue = tints[2]
+ var/list/purple = tints[3]
+ TEST_ASSERT(half[10] > min(blue[10], purple[10]) && half[10] < max(blue[10], purple[10]), "Half way isn't between blue and purple")
+ qdel(fresh)
+ qdel(aged)
+
+/// A plain surge: a surger who keeps moving drags the trail's length of afterimages, all under bodies, and they are
+/// gone a trail's life after he stops
+/datum/unit_test/voidcrew_cyberware_timestop/trail_plain
+
+/datum/unit_test/voidcrew_cyberware_timestop/trail_plain/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytrailuser")
+ var/mob/living/carbon/human/other = allocate(/mob/living/carbon/human/consistent, spot(3, 3))
+ other.key = "sandytrailother" // a player near: a plain surge, no slow-mo
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NULL(window.time_stop, "Test fixture: time slowed with another player near")
+ window.last_step_at = world.time // already walking: no first step's guessed pace
+ walk_trail(user, 16)
+ var/live = count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade)
+ TEST_ASSERT(abs(live - window.trail_length) <= 2, "[live] afterimages behind a surger who keeps moving, not about [window.trail_length]")
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/image in range(7, user))
+ TEST_ASSERT(PLANE_TO_TRUE(image.plane) == FLOOR_PLANE, "An afterimage is drawn over bodies (plane [image.plane])")
+ var/list/off = off_colour_trail(user, /obj/effect/temp_visual/decoy/fading/cascade)
+ TEST_ASSERT(!length(off), "Afterimages not coloured by age: [off.Join("; ")]")
+ sleep(0.1 SECONDS * window.trail_length / window.trail_per_tile + 0.2 SECONDS)
+ TEST_ASSERT_EQUAL(count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade), 0, "The trail lingered after the surger stopped")
+ // A body knocked across the floor is not surging: no afterimages behind a corpse
+ user.death()
+ user.forceMove(get_step(user, EAST))
+ user.forceMove(get_step(user, EAST))
+ TEST_ASSERT_EQUAL(count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade), 0, "A dead surger's body left afterimages as it was moved")
+ end_surge(user)
+
+/// The slow-mo: the same trail, coloured by age as a plain surge's, behind a user walking at normal speed
+/datum/unit_test/voidcrew_cyberware_timestop/trail_slowmo
+
+/datum/unit_test/voidcrew_cyberware_timestop/trail_slowmo/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 0), "sandytrailuser")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Test fixture: time didn't slow with nobody else near")
+ window.last_step_at = world.time // already walking: no first step's guessed pace
+ walk_trail(user, 16)
+ var/live = count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade/stopped)
+ TEST_ASSERT(abs(live - window.trail_length) <= 2, "[live] afterimages behind a user walking in the slow-mo, not about [window.trail_length]")
+ var/list/off = off_colour_trail(user, /obj/effect/temp_visual/decoy/fading/cascade/stopped)
+ TEST_ASSERT(!length(off), "Slow-mo afterimages not coloured by age: [off.Join("; ")]")
+ var/green = json_encode(cyberware_time_stop_green())
+ for(var/obj/effect/temp_visual/decoy/fading/cascade/stopped/image in range(7, user))
+ TEST_ASSERT(json_encode(image.aged_through[1]) != green, "A slow-mo afterimage is the plain green kind")
+ sleep(0.1 SECONDS * window.trail_length / window.trail_per_tile + 0.2 SECONDS)
+ TEST_ASSERT_EQUAL(count_trail(user, /obj/effect/temp_visual/decoy/fading/cascade), 0, "The slow-mo's trail lingered after the user stopped")
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ wait_replay(user)
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A slowed gunman's muzzle flashes and spent casings take the grey-green tint from their first frame, while the
+/// user's and a surging NPC's keep their colours without the user's edge glow wrapping their flash.
+/datum/unit_test/voidcrew_cyberware_timestop/muzzle_and_casings_tinted
+
+/datum/unit_test/voidcrew_cyberware_timestop/muzzle_and_casings_tinted/Run()
+ var/mob/living/carbon/human/user = make_user(spot(1, 2), "sandymuzzleuser")
+ var/mob/living/carbon/human/npc/gunman = allocate(/mob/living/carbon/human/npc, spot(1, 0))
+ var/mob/living/carbon/human/npc/surger = make_surger(spot(1, 4))
+ TEST_ASSERT_NOTNULL(surge(surger), "Test fixture: the surging NPC's window didn't open")
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Test fixture: time didn't slow with nobody else near")
+ for(var/waited in 1 to 20)
+ if(tinted(gunman))
+ break
+ sleep(0.1 SECONDS)
+ TEST_ASSERT(tinted(gunman), "Test fixture: the slow-mo's tint never reached the gunman")
+ TEST_ASSERT(!tinted(user), "Test fixture: the user was tinted")
+ TEST_ASSERT(!tinted(surger), "Test fixture: the surging NPC was tinted")
+
+ var/obj/item/gun/ballistic/automatic/pistol/gunman_gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ gunman.put_in_hands(gunman_gun)
+ var/obj/item/ammo_casing/gunman_casing = gunman_gun.chambered
+ TEST_ASSERT_NOTNULL(gunman_casing, "Test fixture: the gunman's pistol isn't chambered")
+ TEST_ASSERT(gunman_gun.try_fire_gun(spot(4, 0), gunman), "Test fixture: the slowed gunman didn't fire")
+ var/obj/effect/temp_visual/dir_setting/firing_effect/gunman_flash = locate() in gunman
+ var/obj/effect/temp_visual/gun_feel_muzzle_flash/gunman_plume = locate() in gunman
+ TEST_ASSERT(gunman_flash && (gunman_flash in gunman.vis_contents), "Test fixture: the gunman got no firing_effect")
+ TEST_ASSERT(gunman_plume && (gunman_plume in gunman.vis_contents), "Test fixture: the gunman got no muzzle plume")
+ TEST_ASSERT(tinted(gunman_flash), "A slowed gunman's firing_effect wasn't tinted on its first frame")
+ TEST_ASSERT(gunman_flash.appearance_flags & KEEP_APART, "A slowed gunman's firing_effect wasn't kept apart from its filter")
+ TEST_ASSERT(tinted(gunman_plume), "A slowed gunman's muzzle plume wasn't tinted on its first frame")
+ TEST_ASSERT(gunman_plume.appearance_flags & KEEP_APART, "A slowed gunman's muzzle plume wasn't kept apart from its filter")
+ TEST_ASSERT(isturf(gunman_casing.loc), "Test fixture: the gunman's spent casing wasn't ejected onto the floor")
+ TEST_ASSERT(tinted(gunman_casing), "A slowed gunman's spent casing wasn't tinted on its first frame")
+
+ var/obj/item/gun/ballistic/automatic/pistol/user_gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ user.put_in_hands(user_gun)
+ var/obj/item/ammo_casing/user_casing = user_gun.chambered
+ TEST_ASSERT(user_gun.try_fire_gun(spot(4, 2), user), "Test fixture: the user didn't fire")
+ var/obj/effect/temp_visual/dir_setting/firing_effect/user_flash = locate() in user
+ var/obj/effect/temp_visual/gun_feel_muzzle_flash/user_plume = locate() in user
+ TEST_ASSERT(user_flash && user_plume, "Test fixture: the user got no muzzle flashes")
+ TEST_ASSERT(!tinted(user_flash), "The user's own firing_effect was tinted")
+ TEST_ASSERT(!tinted(user_plume), "The user's own muzzle plume was tinted")
+ TEST_ASSERT((user_flash.appearance_flags & KEEP_APART) && (user_plume.appearance_flags & KEEP_APART), "The user's muzzle flash wasn't kept apart from their edge glow")
+ TEST_ASSERT(isturf(user_casing.loc) && !tinted(user_casing), "The user's own spent casing was tinted")
+
+ var/obj/item/gun/ballistic/automatic/pistol/surger_gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ surger.put_in_hands(surger_gun)
+ var/obj/item/ammo_casing/surger_casing = surger_gun.chambered
+ TEST_ASSERT(surger_gun.try_fire_gun(spot(4, 4), surger), "Test fixture: the surging NPC didn't fire")
+ var/obj/effect/temp_visual/dir_setting/firing_effect/surger_flash = locate() in surger
+ var/obj/effect/temp_visual/gun_feel_muzzle_flash/surger_plume = locate() in surger
+ TEST_ASSERT(surger_flash && surger_plume, "Test fixture: the surging NPC got no muzzle flashes")
+ TEST_ASSERT(!tinted(surger_flash) && !tinted(surger_plume), "A surging NPC's muzzle flash was tinted")
+ TEST_ASSERT(isturf(surger_casing.loc) && !tinted(surger_casing), "A surging NPC's spent casing was tinted")
+
+ sleep(0.3 SECONDS)
+ TEST_ASSERT(tinted(gunman_casing), "A slowed gunman's spent casing lost its tint while the slow-mo ran")
+ TEST_ASSERT(!tinted(user_casing) && !tinted(surger_casing), "An untinted shooter's casing picked up the slow-mo's tint")
+
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ TEST_ASSERT(!tinted(gunman_casing), "A spent casing kept the slow-mo's tint after the slow-mo ended")
+ wait_replay(user)
+ end_surge(user)
+ end_surge(surger)
+
+/// Throws started inside a slow-mo — whether of a body already in held_mobs or an item already on the floor, and whoever
+/// started them — fly at the field's pace, pause for the replay, and carry on at normal speed when let go.
+/datum/unit_test/voidcrew_cyberware_timestop/throws_at_field_pace
+
+/datum/unit_test/voidcrew_cyberware_timestop/throws_at_field_pace/Run()
+ var/mob/living/carbon/human/user = make_user(spot(0, 4), "sandythrowuser")
+ var/mob/living/carbon/human/plain_body = allocate(/mob/living/carbon/human/consistent, spot(0, 0))
+ var/obj/item/wrench/plain_item = allocate(/obj/item/wrench, spot(0, 1))
+ TEST_ASSERT(plain_body.throw_at(spot(4, 0), 4, 1, user), "Test fixture: plain body throw didn't start")
+ TEST_ASSERT(plain_item.throw_at(spot(4, 1), 4, 1, user), "Test fixture: plain item throw didn't start")
+ var/plain_from = world.time
+ while((plain_body.throwing || plain_item.throwing) && world.time < plain_from + 2 SECONDS)
+ sleep(world.tick_lag)
+ var/plain_time = max(world.time - plain_from, 0.5 SECONDS) // how long a plain four-tile throw takes here
+ var/plain_body_dist = plain_body.x - spot(0, 0).x
+ var/plain_item_dist = plain_item.x - spot(0, 1).x
+ TEST_ASSERT_EQUAL(plain_body_dist, 4, "Test fixture: an un-slowed body didn't cross 4 tiles in 2 s ([plain_body_dist])")
+ TEST_ASSERT_EQUAL(plain_item_dist, 4, "Test fixture: an un-slowed item didn't cross 4 tiles in 2 s ([plain_item_dist])")
+ qdel(plain_body)
+ qdel(plain_item)
+
+ var/mob/living/carbon/human/slow_body = allocate(/mob/living/carbon/human/consistent, spot(0, 2))
+ var/obj/item/wrench/slow_item = allocate(/obj/item/wrench, spot(0, 3))
+ var/mob/living/carbon/human/short_body = allocate(/mob/living/carbon/human/consistent, spot(2, 0))
+ var/obj/item/wrench/short_item = allocate(/obj/item/wrench, spot(2, 1))
+
+ var/datum/status_effect/cyberware_cascade_window/window = surge(user)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(window.time_stop, "Test fixture: time didn't slow with nobody else near")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field = window.time_stop.chronofield
+ for(var/waited in 1 to 20)
+ if(tinted(short_body))
+ break
+ sleep(0.1 SECONDS)
+ TEST_ASSERT(field.held_mobs[slow_body] && tinted(slow_body), "Test fixture: the body isn't held and tinted before the throw")
+ TEST_ASSERT(!GLOB.cyberware_time_dilated[slow_item] && !tinted(slow_item), "Test fixture: a floor item is held or tinted before being thrown")
+
+ TEST_ASSERT(slow_body.throw_at(spot(4, 2), 4, 1, user), "The held body wouldn't throw inside the slow-mo")
+ TEST_ASSERT(slow_item.throw_at(spot(4, 3), 4, 1, user), "The floor item wouldn't throw inside the slow-mo")
+ TEST_ASSERT(short_body.throw_at(spot(3, 0), 1, 4), "The short body throw didn't start")
+ TEST_ASSERT(short_item.throw_at(spot(3, 1), 1, 4), "The short item throw didn't start")
+
+ TEST_ASSERT_EQUAL(slow_body.x, spot(0, 2).x, "A throw in slow-mo took an immediate full-speed quickstart step")
+ TEST_ASSERT_EQUAL(field.held_throws[slow_body], 1, "A held body thrown in slow-mo didn't enter held_throws")
+ TEST_ASSERT_EQUAL(field.held_throws[slow_item], 1, "A floor item thrown in slow-mo didn't enter held_throws")
+ TEST_ASSERT(abs(slow_body.throwing.speed - field.time_scale) < 0.001, "A thrown held body's speed is [slow_body.throwing.speed], not [field.time_scale]")
+ TEST_ASSERT(abs(slow_item.throwing.speed - field.time_scale) < 0.001, "A thrown floor item's speed is [slow_item.throwing.speed], not [field.time_scale]")
+ TEST_ASSERT(tinted(slow_item), "A floor item thrown in slow-mo wasn't tinted while flying")
+
+ sleep(plain_time) // as long as the plain throws took to land
+ var/slow_body_dist = slow_body.x - spot(0, 2).x
+ var/slow_item_dist = slow_item.x - spot(0, 3).x
+ TEST_ASSERT(slow_body_dist < plain_body_dist && !isnull(slow_body.throwing), "A held body flew [slow_body_dist] tiles in the time [plain_body_dist] take outside slow-mo")
+ TEST_ASSERT(slow_item_dist < plain_item_dist && !isnull(slow_item.throwing), "A floor item flew [slow_item_dist] tiles in the time [plain_item_dist] take outside slow-mo")
+ TEST_ASSERT(isnull(short_body.throwing) && short_body.x == spot(3, 0).x, "Test fixture: the 1-tile body throw didn't land inside the slow-mo")
+ TEST_ASSERT(field.held_mobs[short_body] && tinted(short_body), "A held body whose throw landed inside the slow-mo was let go")
+ TEST_ASSERT(isnull(short_item.throwing) && short_item.x == spot(3, 1).x, "Test fixture: the 1-tile item throw didn't land inside the slow-mo")
+ TEST_ASSERT(!tinted(short_item) && !GLOB.cyberware_time_dilated[short_item], "A floor item stayed tinted or held after landing inside the slow-mo")
+
+ // the user is on their own time: thrown, their own body takes tg's immediate first step and is never paced
+ TEST_ASSERT(user.throw_at(spot(1, 4), 1, 1), "The user wouldn't throw inside their own slow-mo")
+ TEST_ASSERT_EQUAL(user.x, spot(1, 4).x, "The user's own body didn't fly at its own speed when thrown in their slow-mo")
+ TEST_ASSERT(!field.held_throws[user], "The user's own thrown body was taken by their field")
+
+ user.remove_status_effect(/datum/status_effect/cyberware_cascade_window)
+ TEST_ASSERT_EQUAL(slow_body.throwing.speed, 1, "A thrown body didn't get its normal speed back when the slow-mo ended")
+ TEST_ASSERT_EQUAL(slow_item.throwing.speed, 1, "A thrown item didn't get its normal speed back when the slow-mo ended")
+ TEST_ASSERT(slow_body.throwing.paused && slow_item.throwing.paused, "The replay didn't hold the flying throws when the slow-mo ended")
+ wait_replay(user)
+ var/land_until = world.time + 0.5 SECONDS
+ while((slow_body.throwing || slow_item.throwing) && world.time < land_until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(isnull(slow_body.throwing) && slow_body.x == spot(4, 2).x, "A thrown body didn't finish its flight at normal speed after the slow-mo ([slow_body.x] vs [spot(4, 2).x])")
+ TEST_ASSERT(isnull(slow_item.throwing) && slow_item.x == spot(4, 3).x, "A thrown item didn't finish its flight at normal speed after the slow-mo ([slow_item.x] vs [spot(4, 3).x])")
+ TEST_ASSERT(!tinted(slow_body) && !tinted(slow_item), "A thrown body or item kept the slow-mo's tint after landing")
+ end_surge(user)
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_cover.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_cover.dm
new file mode 100644
index 00000000000..e01a0e42a14
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_cover.dm
@@ -0,0 +1,118 @@
+/**
+ * How much the Cascade slow-mo covers (voidcrew/modules/cyberware/ware_sandy_timestop_cover.dm): its reach, never
+ * another crew's player, and mobs that pace themselves on their own clocks (the kingpin's crew).
+ *
+ * Unit-test files compile before voidcrew/_DEFINES/, so literals stand in for module defines.
+ */
+
+/// The field takes what is 11 tiles out, leaves what is 20 out alone, and never holds a player from another crew.
+/datum/unit_test/voidcrew_cyberware_timestop/cover_reach
+
+/datum/unit_test/voidcrew_cyberware_timestop/cover_reach/Run()
+ var/turf/here = spot(0, 0)
+ var/turf/near_spot = locate(here.x + 11, here.y, here.z) || locate(here.x - 11, here.y, here.z)
+ var/turf/far_spot = locate(here.x + 20, here.y, here.z) || locate(here.x - 20, here.y, here.z)
+ TEST_ASSERT(near_spot && far_spot, "Test fixture: no turfs 11 and 20 tiles from the test room")
+ var/mob/living/carbon/human/user = make_user(here, "sandycover[type]")
+ set_window(user, 2 SECONDS)
+ var/mob/living/carbon/human/near = allocate(/mob/living/carbon/human/consistent, near_spot)
+ var/mob/living/carbon/human/far = allocate(/mob/living/carbon/human/consistent, far_spot)
+ surge(user)
+ TEST_ASSERT(cyberware_time_stopping(user), "The slow-mo didn't start")
+ sleep(0.6 SECONDS) // a few field ticks: the room is taken a batch at a time
+ TEST_ASSERT(GLOB.cyberware_time_dilated[near], "A body 11 tiles out isn't slowed")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field
+ for(var/datum/proximity_monitor/advanced/timestop/sandevistan/each as anything in GLOB.cyberware_time_fields)
+ if(each.host == user)
+ field = each
+ TEST_ASSERT_NOTNULL(field, "The slow-mo has no field")
+ TEST_ASSERT(field.tinted[near_spot], "The ground 11 tiles out isn't taken")
+ TEST_ASSERT(!field.tinted[far_spot], "The ground 20 tiles out is taken")
+ TEST_ASSERT(!GLOB.cyberware_time_dilated[far], "A body 20 tiles out is slowed")
+ TEST_ASSERT(!cyberware_time_has_tint(far_spot), "The ground 20 tiles out is tinted")
+ // A player from another crew the field reaches (its room can run past the witness range) is never held. Made after
+ // the slow-mo started and handed to the field directly: anywhere near, they would end it as a witness.
+ var/turf/away = locate(here.x + 40, here.y, here.z) || locate(1, here.y, here.z)
+ var/mob/living/carbon/human/outsider = allocate(/mob/living/carbon/human/consistent, away)
+ outsider.key = "sandycoveroutsider[type]" // a player before the field ever sees them
+ outsider.forceMove(spot(1, 1))
+ TEST_ASSERT(!field.freeze_atom(outsider), "The field took a player from another crew")
+ TEST_ASSERT(!GLOB.cyberware_time_dilated[outsider], "A player from another crew is slowed")
+ outsider.key = null
+
+/**
+ * A kingpin's crew paces its goons on its own clocks. In a slow-mo they shoot and step at the field's pace, not their
+ * own: shots and steps over two seconds before and inside the slow-mo, driven a tick at a time as the crew does.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/kingpin_crew
+
+/datum/unit_test/voidcrew_cyberware_timestop/kingpin_crew/Run()
+ var/turf/seat = spot(2, 0)
+ var/obj/structure/chair/sofa/corp/sofa = allocate(/obj/structure/chair/sofa/corp, seat)
+ sofa.setDir(NORTH)
+ var/list/posts = list(list(spot(4, 0), "pistol"), list(spot(0, 4), "shotgun")) // BOUNTY_GOON_WEAPON_*
+ var/mob/living/carbon/human/npc/bounty_criminal/kingpin/kingpin = bounty_kingpin_setup(seat, posts, bounty_kingpin_make_record(), TRUE)
+ TEST_ASSERT_NOTNULL(kingpin, "Test fixture: no kingpin")
+ var/datum/bounty_kingpin_crew/crew = kingpin.kingpin_crew
+ var/list/goons = crew.goons()
+ TEST_ASSERT_EQUAL(length(goons), 2, "Test fixture: the lounge doesn't have its two goons")
+ var/mob/living/carbon/human/npc/bounty_kingpin_goon/shooter = goons[1]
+ var/mob/living/carbon/human/npc/bounty_kingpin_goon/walker = goons[2]
+ var/mob/living/carbon/human/user = make_user(spot(2, 3), "sandykingpin[type]")
+ ADD_TRAIT(user, TRAIT_GODMODE, TRAIT_SOURCE_UNIT_TESTS)
+ set_window(user, 6 SECONDS)
+ TEST_ASSERT(crew.start_shootout(user, TRUE), "Test fixture: the shootout didn't start")
+ crew.crew_draw_ends_at = world.time
+ crew.process(0.2)
+ STOP_PROCESSING(SSfastprocess, crew) // the test drives the goons a tick at a time
+ for(var/mob/living/carbon/human/npc/goon as anything in goons + kingpin)
+ goon.ai_controller?.set_ai_status(AI_STATUS_OFF)
+
+ var/list/normal = kingpin_rates(crew, shooter, walker, user)
+ surge(user)
+ TEST_ASSERT(cyberware_time_stopping(user), "The slow-mo didn't start")
+ TEST_ASSERT(GLOB.cyberware_time_dilated[shooter] && GLOB.cyberware_time_dilated[walker], "The field didn't take the goons")
+ var/scale = cyberware_time_scale(shooter)
+ var/list/slowed = kingpin_rates(crew, shooter, walker, user)
+ TEST_NOTICE(src, "kingpin goons over 2 s: normal [normal[1]] shots, [normal[2]] steps; in the slow-mo at [scale]: [slowed[1]] shots, [slowed[2]] steps")
+ log_world("SANDY COVER kingpin goons over 2 s: normal [normal[1]] shots, [normal[2]] steps; in the slow-mo at [scale]: [slowed[1]] shots, [slowed[2]] steps")
+ TEST_ASSERT(normal[1] >= 3 && normal[2] >= 3, "Test fixture: the goons barely shot or stepped at full speed ([normal[1]] shots, [normal[2]] steps)")
+ TEST_ASSERT(slowed[1] <= max(1, normal[1] / 2), "A goon in the slow-mo still shoots near full rate ([slowed[1]] against [normal[1]])")
+ TEST_ASSERT(slowed[2] <= max(1, normal[2] / 2), "A goon in the slow-mo still steps near full rate ([slowed[2]] against [normal[2]])")
+ // the pushed clock itself
+ shooter.goon_next_fire_at = world.time + 10
+ var/was = shooter.goon_next_fire_at
+ sleep(0.6 SECONDS)
+ TEST_ASSERT(shooter.goon_next_fire_at > was, "The field didn't push the goon's trigger clock")
+
+ for(var/datum/bounty_kingpin_crew/each as anything in GLOB.bounty_kingpin_crews.Copy())
+ for(var/mob/living/carbon/human/npc/bounty_kingpin_goon/goon as anything in each.goons())
+ qdel(goon)
+ var/mob/living/carbon/human/npc/bounty_criminal/kingpin/boss = each.kingpin()
+ if(boss)
+ qdel(boss)
+ else
+ qdel(each)
+
+/// Two seconds of the crew's turns for `shooter` (a pistol at `target`) and `walker` (back and forth on its row):
+/// list(shots, steps).
+/datum/unit_test/voidcrew_cyberware_timestop/kingpin_crew/proc/kingpin_rates(datum/bounty_kingpin_crew/crew, mob/living/carbon/human/npc/bounty_kingpin_goon/shooter, mob/living/carbon/human/npc/bounty_kingpin_goon/walker, mob/living/target)
+ var/shots = 0
+ var/steps = 0
+ var/list/ends = list(spot(0, 4), spot(1, 4))
+ var/until = world.time + 2 SECONDS
+ while(world.time < until)
+ var/obj/item/gun/ballistic/pistol = human_npc_held_gun(shooter)
+ if(istype(pistol) && pistol.magazine)
+ pistol.magazine.top_off()
+ if(!pistol.chambered)
+ pistol.chamber_round()
+ shooter.next_click = 0
+ shooter.next_move = 0
+ if(crew.goon_try_attack(shooter, target))
+ shots++
+ var/turf/goal = get_turf(walker) == ends[1] ? ends[2] : ends[1]
+ if(crew.goon_step_toward(walker, goal))
+ steps++
+ sleep(world.tick_lag)
+ return list(shots, steps)
diff --git a/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_shared.dm b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_shared.dm
new file mode 100644
index 00000000000..c7084eaf617
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_cyberware_timestop_shared.dm
@@ -0,0 +1,375 @@
+/**
+ * # One slow-mo for a crew
+ *
+ * voidcrew/modules/cyberware/ware_sandy_timestop_shared.dm. Crewmates' slow-mos that touch become one: it lasts until
+ * the last member's own time is out, a member out of time is slowed with the world, one replay plays at the end and
+ * every crash lands after it. Another crew's player ends it for everyone with no replay.
+ */
+/datum/unit_test/voidcrew_cyberware_timestop/shared
+ abstract_type = /datum/unit_test/voidcrew_cyberware_timestop/shared
+ var/list/ships = list()
+ var/list/teams = list()
+
+/// Ships of earlier shared tests: test datums are only destroyed after the whole run.
+GLOBAL_LIST_EMPTY(sandy_shared_test_ships)
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/Destroy()
+ for(var/obj/structure/overmap/ship/ship as anything in ships)
+ SSovermap.simulated_ships -= ship
+ ship.ship_team = null
+ ships.Cut()
+ for(var/datum/team/team as anything in teams)
+ qdel(team)
+ teams.Cut()
+ return ..()
+
+/// Puts every body in `bodies` on one ship's crew (cyberware_crew_team()).
+/datum/unit_test/voidcrew_cyberware_timestop/shared/proc/make_crew(list/bodies)
+ for(var/obj/structure/overmap/ship/old as anything in GLOB.sandy_shared_test_ships)
+ SSovermap.simulated_ships -= old
+ old.ship_team = null
+ GLOB.sandy_shared_test_ships.Cut()
+ var/obj/structure/overmap/ship/ship = new
+ GLOB.sandy_shared_test_ships += ship
+ var/datum/team/voidcrew/team = new
+ team.name = "Test crew"
+ team.ship = ship
+ ship.ship_team = team
+ SSovermap.simulated_ships |= ship
+ ships += ship
+ teams += team
+ for(var/mob/living/body as anything in bodies)
+ if(!body.mind)
+ body.mind_initialize()
+ team.add_member(body.mind)
+ TEST_ASSERT_EQUAL(cyberware_crew_team(body), team, "Test fixture: [body] isn't on the crew")
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/proc/session_of(mob/living/body)
+ return GLOB.sandy_session_of[body]
+
+/// Two Cascades, the second pressed a second after the first: one slow-mo until the second's time is out, the first
+/// slowed with the world (still able to act) for the rest of it, one replay, both crashes after it.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/join
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/join/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 2 SECONDS)
+ set_window(second, 2 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(1, 2))
+ TEST_ASSERT(!cyberware_time_stop_witnessed(first), "Test fixture: a crewmate counts as a witness")
+
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(1 SECONDS)
+ TEST_ASSERT_NOTNULL(one.time_stop, "Test fixture: the first slow-mo didn't start")
+ var/datum/sandy_replay/recording = GLOB.sandy_replays[first]
+ TEST_ASSERT_NOTNULL(recording, "Test fixture: the first slow-mo isn't recording")
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(two.time_stop, "The crewmate's surge in the slow-mo didn't slow the world")
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "The two slow-mos didn't join")
+ TEST_ASSERT_EQUAL(session_of(second), session, "The second surger is in another session")
+ TEST_ASSERT_EQUAL(session.replay, recording, "The shared slow-mo isn't recorded by the first one's recording")
+ TEST_ASSERT_NULL(GLOB.sandy_replays[second], "The second surger kept a recording of its own")
+ TEST_ASSERT(abs(cyberware_time_scale(first) - 1) < 0.01, "The first Cascade isn't at normal speed beside the second ([cyberware_time_scale(first)])")
+ TEST_ASSERT(abs(cyberware_time_scale(second) - 1) < 0.01, "The second Cascade isn't at normal speed beside the first ([cyberware_time_scale(second)])")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.1) < 0.01, "The NPC isn't at the world's 10% ([cyberware_time_scale(raider)])")
+
+ sleep(1.1 SECONDS) // the first one's own time is out
+ TEST_ASSERT(!first.has_status_effect(/datum/status_effect/cyberware_cascade_window), "Test fixture: the first window outlived its 2 s")
+ TEST_ASSERT(!first.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The first surger crashed before the replay")
+ TEST_ASSERT_EQUAL(recording.state, 1, "The recording stopped while the second surger still had time")
+ TEST_ASSERT_NOTNULL(two.time_stop, "The shared slow-mo ended with the first one's time")
+ TEST_ASSERT(abs(cyberware_time_scale(first) - 0.1) < 0.01, "The first surger, out of time, isn't slowed with the world ([cyberware_time_scale(first)])")
+ TEST_ASSERT(first.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The first surger's walk isn't slowed")
+ TEST_ASSERT(!frozen(first), "The first surger was frozen")
+ TEST_ASSERT(!first.get_filter("sandy_time_stop_outline"), "The first surger kept the edge glow")
+ TEST_ASSERT(second.get_filter("sandy_time_stop_outline"), "The second surger lost the edge glow")
+ var/turf/was = get_turf(first)
+ first.Move(spot(0, 1), NORTH)
+ TEST_ASSERT(get_turf(first) != was, "The slowed first surger couldn't move")
+
+ sleep(1 SECONDS) // the second one's time is out: it all ends
+ TEST_ASSERT(!second.has_status_effect(/datum/status_effect/cyberware_cascade_window), "Test fixture: the second window outlived its 2 s")
+ TEST_ASSERT(!length(GLOB.cyberware_time_fields), "A field outlived the shared slow-mo")
+ TEST_ASSERT(!first.has_status_effect(/datum/status_effect/cyberware_cascade_crash) && !second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A crash landed before the replay")
+ TEST_ASSERT(!QDELETED(recording) && recording.state >= 2, "The one replay didn't start at the end")
+ wait_replay(first)
+ TEST_ASSERT(GLOB.sandy_replay_last["played"], "The shared replay didn't play")
+ TEST_ASSERT(first.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The first surger never crashed")
+ TEST_ASSERT(second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The second surger never crashed")
+ TEST_ASSERT_NULL(session_of(first), "The session outlived its replay")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A member pressing the surge again drops out (slowed with the world) and the slow-mo goes on for the other.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/drop_out
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/drop_out/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 3 SECONDS)
+ set_window(second, 3 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ surge(second)
+ sleep(0.3 SECONDS)
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "Test fixture: the two slow-mos didn't join")
+ var/datum/action/cooldown/cyberware/cascade_surge/button = surge_button(second)
+ TEST_ASSERT(button.Trigger(), "The second press did nothing")
+ TEST_ASSERT(!second.has_status_effect(/datum/status_effect/cyberware_cascade_window), "The second press didn't end that member's window")
+ TEST_ASSERT_NOTNULL(one.time_stop, "One member dropping out ended the shared slow-mo")
+ TEST_ASSERT(abs(cyberware_time_scale(second) - 0.1) < 0.01, "The member who dropped out isn't slowed with the world")
+ TEST_ASSERT(!second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The member who dropped out crashed before the replay")
+ TEST_ASSERT_EQUAL(session.replay?.state, 1, "The recording stopped when one member dropped out")
+ qdel(one) // the other ends it
+ sleep(0.1 SECONDS)
+ wait_replay(first)
+ TEST_ASSERT(second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "The member who dropped out never crashed")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A player from another crew coming near ends the shared slow-mo for everyone, with no replay.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/other_crew
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/other_crew/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 4 SECONDS)
+ set_window(second, 4 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.2 SECONDS)
+ TEST_ASSERT_NOTNULL(session_of(first), "Test fixture: the two slow-mos didn't join")
+ var/mob/living/carbon/human/stranger = allocate(/mob/living/carbon/human/consistent, spot(5, 0))
+ stranger.key = "sandysharedstranger"
+ sleep(0.5 SECONDS)
+ TEST_ASSERT_NULL(one.time_stop, "Another crew's player didn't end the first member's slow-mo")
+ TEST_ASSERT_NULL(two.time_stop, "Another crew's player didn't end the second member's slow-mo")
+ TEST_ASSERT(!length(GLOB.cyberware_time_fields), "A field outlived another crew's player coming near")
+ TEST_ASSERT_NULL(GLOB.sandy_replays[first], "The shared slow-mo cut short kept its recording")
+ TEST_ASSERT_NULL(session_of(first), "The session outlived being cut short")
+ stranger.key = null
+ qdel(one)
+ qdel(two)
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// Crewmates' slow-mos that don't touch stay apart, each with its own recording.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/apart
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/apart/Run()
+ var/turf/far = locate(run_loc_floor_bottom_left.x + 24, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)
+ if(!far)
+ far = locate(run_loc_floor_bottom_left.x - 24, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)
+ TEST_ASSERT_NOTNULL(far, "Test fixture: no turf 24 tiles from the test room")
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(far, "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 1 SECONDS)
+ set_window(second, 1 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.3 SECONDS)
+ TEST_ASSERT_NOTNULL(one.time_stop, "Test fixture: the first slow-mo didn't start")
+ TEST_ASSERT_NOTNULL(two.time_stop, "Test fixture: the second slow-mo didn't start")
+ TEST_ASSERT_NULL(session_of(first), "Slow-mos 24 tiles apart joined")
+ TEST_ASSERT(GLOB.sandy_replays[first] && GLOB.sandy_replays[second] && GLOB.sandy_replays[first] != GLOB.sandy_replays[second], "Slow-mos apart don't each have their own recording")
+ sleep(1 SECONDS)
+ wait_replay(first)
+ wait_replay(second)
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A Cascade and a street model: the world runs at the Cascade's 10% (the street surger at its 2.5x over it), then at
+/// the street model's 40% once the Cascade is out of time.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/mixed
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/mixed/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]", /obj/item/organ/cyberimp/cyberware/cascade/street)
+ make_crew(list(first, second))
+ set_window(first, 1 SECONDS)
+ set_window(second, 3 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(1, 2))
+ surge(first)
+ sleep(0.1 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.2 SECONDS)
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "Test fixture: the two slow-mos didn't join")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.1) < 0.01, "The world isn't at the Cascade's 10% ([cyberware_time_scale(raider)])")
+ TEST_ASSERT(abs(cyberware_time_scale(second) - 0.25) < 0.01, "The street surger doesn't run at 2.5x the Cascade's world ([cyberware_time_scale(second)])")
+ var/datum/sandy_replay/recording = session.replay
+ var/rate_before = recording.clock_rate
+ sleep(1 SECONDS) // the Cascade is out of time
+ TEST_ASSERT_NOTNULL(two.time_stop, "The shared slow-mo ended with the Cascade's time")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.4) < 0.01, "The world didn't speed up to the street model's 40% ([cyberware_time_scale(raider)])")
+ TEST_ASSERT(abs(cyberware_time_scale(second) - 1) < 0.01, "The street surger isn't at normal speed in its own pace ([cyberware_time_scale(second)])")
+ TEST_ASSERT(abs(cyberware_time_scale(first) - 0.4) < 0.01, "The Cascade, out of time, isn't slowed with the world ([cyberware_time_scale(first)])")
+ TEST_ASSERT(recording.clock_rate > rate_before * 3, "The recording's frames didn't follow the world's new pace")
+ // What the replay scales by the pace (a trail's step, a body's turn) takes the pace each frame was recorded at
+ TEST_ASSERT_EQUAL(recording.rate_at(0), rate_before, "The recording forgot the pace its first frames were taken at")
+ TEST_ASSERT_EQUAL(recording.rate_at(recording.frame_now()), recording.clock_rate, "The recording's newest frames aren't at the world's new pace")
+ qdel(two)
+ sleep(0.1 SECONDS)
+ wait_replay(first)
+ TEST_ASSERT(first.has_status_effect(/datum/status_effect/cyberware_cascade_crash) && second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A crash didn't land after the replay")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A shared slow-mo ends at its cap however much time its members have left: the one replay, then every crash. A
+/// crewmate pressing after it is over gets a slow-mo of their own.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/capped
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/capped/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ var/mob/living/carbon/human/third = make_user(spot(5, 0), "sandythree[type]")
+ make_crew(list(first, second, third))
+ set_window(first, 10 SECONDS)
+ set_window(second, 10 SECONDS)
+ set_window(third, 1 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.1 SECONDS)
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "Test fixture: the two slow-mos didn't join")
+ TEST_ASSERT_EQUAL(session.max_length, 30 SECONDS, "A shared slow-mo isn't capped at 30 seconds")
+ var/datum/sandy_replay/recording = session.replay
+ session.max_length = world.time - session.started + 0.5 SECONDS // the cap, brought within the test's reach
+ var/until = world.time + 2 SECONDS
+ while(!QDELETED(one) && world.time < until) // checked the tick it ends: the replay of so short a slow-mo is short too
+ sleep(world.tick_lag)
+ TEST_ASSERT(QDELETED(one) && QDELETED(two), "A member's window outlived the cap")
+ TEST_ASSERT(!length(GLOB.cyberware_time_fields), "A field outlived the cap")
+ TEST_ASSERT(!QDELETED(recording) && recording.state >= 2, "The replay didn't start at the cap")
+ TEST_ASSERT(!first.has_status_effect(/datum/status_effect/cyberware_cascade_crash) && !second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A crash landed before the replay")
+ wait_replay(first)
+ TEST_ASSERT(GLOB.sandy_replay_last["played"], "The capped slow-mo's replay didn't play")
+ TEST_ASSERT(first.has_status_effect(/datum/status_effect/cyberware_cascade_crash) && second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A crash didn't land after the replay")
+ TEST_ASSERT_NULL(session_of(first), "The session outlived its replay")
+
+ var/datum/status_effect/cyberware_cascade_window/three = surge(third)
+ sleep(0.1 SECONDS)
+ TEST_ASSERT_NOTNULL(three.time_stop, "A crewmate's press after the cap didn't slow the world")
+ TEST_ASSERT_NULL(session_of(third), "A press after the cap joined the old session")
+ TEST_ASSERT_NOTNULL(GLOB.sandy_replays[third], "A press after the cap isn't recording a replay of its own")
+ sleep(1 SECONDS)
+ wait_replay(third)
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ third.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// A member's own shot taken first by a crewmate's field (made where both reach) is paced by the shooter's field only,
+/// and flies at its own speed again once the shared slow-mo is over. The shared replay draws a member without the edge
+/// glow every member wears.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/shots_full_speed_after
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/shots_full_speed_after/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 2 SECONDS)
+ set_window(second, 2 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ var/datum/status_effect/cyberware_cascade_window/two = surge(second)
+ sleep(0.1 SECONDS)
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "Test fixture: the two slow-mos didn't join")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field_one = one.time_stop?.chronofield
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/field_two = two.time_stop?.chronofield
+ TEST_ASSERT(field_one && field_two, "Test fixture: a member has no field")
+
+ TEST_ASSERT(second.get_filter("sandy_time_stop_outline"), "Test fixture: the second member has no edge glow")
+ var/mutable_appearance/recorded = new(session.replay.clean_look(second))
+ TEST_ASSERT(length(recorded.filters) < length(second.filters), "The shared replay records a member with the slow-mo's edge glow")
+
+ var/obj/projectile/bullet/shot = allocate(/obj/projectile/bullet, spot(3, 1))
+ var/shot_speed = initial(shot.speed)
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/holder = GLOB.cyberware_time_dilated[shot]
+ TEST_ASSERT(holder == field_one || holder == field_two, "Test fixture: no member's field took the shot")
+ var/datum/proximity_monitor/advanced/timestop/sandevistan/shooter = holder == field_one ? field_two : field_one
+ shot.firer = shooter.host
+ shooter.take_user_shot(shot) // its own field watches it leave the barrel
+ TEST_ASSERT_EQUAL(GLOB.cyberware_time_dilated[shot], shooter, "The shooter's field doesn't pace its own shot")
+ TEST_ASSERT_NULL(holder.held_shots[shot], "Two members' fields hold one shot")
+ TEST_ASSERT(abs(shot.speed - shot_speed * shooter.scale_for(shot)) < 0.001, "The member's shot isn't at its field's pace ([shot.speed] vs [shot_speed * shooter.scale_for(shot)])")
+
+ qdel(one)
+ qdel(two)
+ sleep(0.1 SECONDS)
+ wait_replay(first)
+ TEST_ASSERT(!QDELETED(shot), "Test fixture: the unfired shot is gone")
+ TEST_ASSERT_EQUAL(shot.speed, shot_speed, "A member's shot is still slowed after the shared slow-mo")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+
+/// The last member's time runs out while a member who already dropped out is mid-move: the shared slow-mo holds, as a
+/// solo one does, until the move is over, and that member finishes the move at its own speed with its edge glow on.
+/// The world never runs live between the slow-mo and its replay: the fields end
+/// and the replay starts without waiting, and nobody gets the release flash.
+/datum/unit_test/voidcrew_cyberware_timestop/shared/holds_for_member_move
+
+/datum/unit_test/voidcrew_cyberware_timestop/shared/holds_for_member_move/Run()
+ var/mob/living/carbon/human/first = make_user(spot(0, 0), "sandyone[type]")
+ var/mob/living/carbon/human/second = make_user(spot(3, 0), "sandytwo[type]")
+ make_crew(list(first, second))
+ set_window(first, 2 SECONDS)
+ set_window(second, 3 SECONDS)
+ var/mob/living/carbon/human/npc/raider = allocate(/mob/living/carbon/human/npc, spot(1, 2))
+ var/datum/status_effect/cyberware_cascade_window/one = surge(first)
+ sleep(0.2 SECONDS)
+ surge(second)
+ sleep(0.3 SECONDS)
+ var/datum/sandy_session/session = session_of(first)
+ TEST_ASSERT_NOTNULL(session, "Test fixture: the two slow-mos didn't join")
+ var/datum/sandy_replay/recording = session.replay
+ var/datum/action/cooldown/cyberware/cascade_surge/button = surge_button(second)
+ TEST_ASSERT(button.Trigger(), "Test fixture: the second press did nothing")
+ TEST_ASSERT(!second.has_status_effect(/datum/status_effect/cyberware_cascade_window), "Test fixture: the second member is still on its own time")
+ // A rig's hide marks a move in progress that has no status of its own (the impale, the slam)
+ second.add_filter("chrome_rig_hide", 1, color_matrix_filter(list(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
+ TEST_ASSERT(sandy_replay_mid_move(second), "Test fixture: the second member isn't mid-move")
+
+ sleep(2 SECONDS) // the first one's own time is up
+ TEST_ASSERT(!QDELETED(one) && one.hold_until, "The shared slow-mo didn't hold for the other member's move")
+ TEST_ASSERT_EQUAL(length(GLOB.cyberware_time_fields), 2, "A field ended while the slow-mo holds")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 0.1) < 0.01, "The world isn't slowed while the slow-mo holds ([cyberware_time_scale(raider)])")
+ TEST_ASSERT(abs(cyberware_time_scale(second) - 1) < 0.01, "The member the slow-mo holds for isn't at its own speed ([cyberware_time_scale(second)])")
+ TEST_ASSERT(!second.has_movespeed_modifier(/datum/movespeed_modifier/cyberware_dilation), "The member the slow-mo holds for still walks slowed")
+ TEST_ASSERT(second.get_filter("sandy_time_stop_outline"), "The member the slow-mo holds for has no edge glow")
+ TEST_ASSERT(!tinted(second), "The member the slow-mo holds for is still tinted")
+ TEST_ASSERT_EQUAL(recording.state, 1, "The recording stopped while the slow-mo holds")
+ TEST_ASSERT(!recording.wait_started, "The replay is waiting with the world running")
+ TEST_ASSERT(!sandy_session_joinable(sandy_session_field(one.time_stop)), "A crewmate could join a holding slow-mo")
+ sleep(1 SECONDS)
+ TEST_ASSERT(!QDELETED(one) && one.time_stop, "The hold ended with the move still going")
+
+ second.remove_filter("chrome_rig_hide") // the move is over
+ var/until = world.time + 2 SECONDS
+ while(length(GLOB.cyberware_time_fields) && world.time < until)
+ sleep(world.tick_lag)
+ TEST_ASSERT(!length(GLOB.cyberware_time_fields), "The slow-mo never ended after the move")
+ TEST_ASSERT(!second.get_filter("sandy_time_stop_outline"), "The edge glow outlived the slow-mo")
+ TEST_ASSERT(QDELETED(one), "The window outlived the slow-mo it held")
+ // The tick the fields end: the recording is over without a wait. (With a member's client watching, begin() runs in
+ // this same tick; with none, end_wait() starts it next tick.)
+ TEST_ASSERT(!QDELETED(recording) && recording.state >= 2, "The replay didn't follow the slow-mo at once")
+ TEST_ASSERT(!recording.wait_started, "The replay waited for a move with the world running")
+ TEST_ASSERT(abs(cyberware_time_scale(raider) - 1) < 0.01, "The world is still slowed after the slow-mo")
+ for(var/entry in session.log)
+ TEST_ASSERT(!findtext(entry, "flash"), "A member got the release flash with a replay following: [entry]")
+ wait_replay(first)
+ TEST_ASSERT(GLOB.sandy_replay_last["played"], "The shared replay didn't play")
+ TEST_ASSERT(first.has_status_effect(/datum/status_effect/cyberware_cascade_crash) && second.has_status_effect(/datum/status_effect/cyberware_cascade_crash), "A crash didn't land after the replay")
+ first.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
+ second.remove_status_effect(/datum/status_effect/cyberware_cascade_crash)
diff --git a/voidcrew/modules/unit_tests/voidcrew_gorilla_gore.dm b/voidcrew/modules/unit_tests/voidcrew_gorilla_gore.dm
index ca6bd9819d0..acf635f4fce 100644
--- a/voidcrew/modules/unit_tests/voidcrew_gorilla_gore.dm
+++ b/voidcrew/modules/unit_tests/voidcrew_gorilla_gore.dm
@@ -915,7 +915,7 @@
TEST_ASSERT_NOTNULL(framed.get_bodypart(BODY_ZONE_HEAD), "The Atlas frame's head burst")
qdel(frame_finisher)
-/// The limb rip tears the aimed arm off and leaves it on the victim's tile.
+/// The limb rip tears the aimed arm off and throws it away behind the bearer, quickly, with no blow after.
/datum/unit_test/voidcrew_gorilla_gore/finisher_rip
/datum/unit_test/voidcrew_gorilla_gore/finisher_rip/Run()
@@ -927,11 +927,19 @@
TEST_ASSERT(gorilla_try_finisher(bearer, victim), "The limb rip didn't start")
var/datum/hv_finisher/chrome/gorilla/rip/finisher = bearer.chrome_finisher
TEST_ASSERT(istype(finisher), "An arm aim didn't pick the limb rip")
+ TEST_ASSERT(finisher.total_duration() <= 1.6 SECONDS, "The limb rip runs [finisher.total_duration() / 10] s, longer than its one pull and throw")
+ var/head_brute = victim.get_bodypart(BODY_ZONE_HEAD).brute_dam
run_to_end(finisher)
TEST_ASSERT_NULL(victim.get_bodypart(BODY_ZONE_L_ARM), "The aimed arm wasn't torn off")
TEST_ASSERT_NOTNULL(victim.get_bodypart(BODY_ZONE_R_ARM), "The wrong arm was torn off")
- var/obj/item/bodypart/arm/left/torn = locate() in get_turf(victim)
- TEST_ASSERT_NOTNULL(torn, "The torn arm wasn't left on the victim's tile")
+ TEST_ASSERT_EQUAL(victim.get_bodypart(BODY_ZONE_HEAD).brute_dam, head_brute, "The torn arm was used to beat the victim's head")
+ // Thrown away behind the bearer: on its way, never on the victim's tile
+ var/obj/item/bodypart/arm/left/torn
+ for(var/obj/item/bodypart/arm/left/found in range(2, bearer))
+ torn = found
+ TEST_ASSERT_NOTNULL(torn, "The torn arm wasn't thrown out into the room")
+ TEST_ASSERT(get_turf(torn) != get_turf(victim), "The torn arm was dropped on the victim instead of thrown")
+ TEST_ASSERT(get_dist(torn, victim) >= get_dist(bearer, victim), "The torn arm was thrown toward the victim")
TEST_ASSERT_EQUAL(puppets_left(), 0, "The limb rip left puppets behind")
// The blood is the tear's, laid under the shoulder as the arm came off: nothing fresh when the arm is dropped
var/obj/effect/decal/cleanable/blood/pool
@@ -955,6 +963,55 @@
TEST_ASSERT_NOTNULL(armoured.get_bodypart(BODY_ZONE_R_ARM).get_wound_type(/datum/wound/blunt/bone/moderate), "An armoured arm didn't dislocate")
qdel(armoured_rip)
+/// However the body lies when the grab turns it (head either way, facing any way) and whichever arm is aimed, the arm
+/// hauled up, the fists that take it and the blood all come from the shoulder at the head end of the body, on the
+/// side of the bearer's middle that shoulder is on.
+/datum/unit_test/voidcrew_gorilla_gore/finisher_rip_shoulders
+
+/datum/unit_test/voidcrew_gorilla_gore/finisher_rip_shoulders/Run()
+ var/list/bearer_offsets = list("[NORTH]" = list(0, -1), "[SOUTH]" = list(0, 1), "[EAST]" = list(-1, 0), "[WEST]" = list(1, 0))
+ for(var/bearer_facing in bearer_offsets)
+ var/list/offset = bearer_offsets[bearer_facing]
+ for(var/angle in list(LYING_ANGLE_EAST, LYING_ANGLE_WEST))
+ for(var/zone in list(BODY_ZONE_L_ARM, BODY_ZONE_R_ARM))
+ var/combo = "bearer facing [dir2text(text2num(bearer_facing))], body lying at [angle], [zone]"
+ clear_mess(spot(3, 3))
+ var/mob/living/carbon/human/consistent/victim = downed(spot(3, 3))
+ victim.set_lying_angle(angle)
+ var/mob/living/carbon/human/bearer = gorilla(spot(3 + offset[1], 3 + offset[2]))
+ bearer.zone_selected = zone
+ TEST_ASSERT(gorilla_try_finisher(bearer, victim), "The limb rip didn't start: [combo]")
+ var/datum/hv_finisher/chrome/gorilla/rip/finisher = bearer.chrome_finisher
+ TEST_ASSERT(istype(finisher), "An arm aim didn't pick the limb rip: [combo]")
+ TEST_ASSERT_EQUAL(finisher.target_zone, zone, "The rip took the other arm: [combo]")
+ TEST_ASSERT_NOTNULL(finisher.victim_rig, "The rip drew no stand-in for the body: [combo]")
+ var/datum/chrome_rig/rig = finisher.victim_rig
+ // The way the head lies, as the body is drawn now
+ var/list/mid = chrome_rig_apply(rig.base_transform, 0, 0)
+ var/list/neck = chrome_rig_apply(rig.base_transform, 0, 10)
+ var/head_x = neck[1] - mid[1]
+ var/head_y = neck[2] - mid[2]
+ var/list/shoulder = rig.shoulder_point(finisher.side)
+ TEST_ASSERT((shoulder[1] - mid[1]) * head_x + (shoulder[2] - mid[2]) * head_y > 0, "The hauled arm's shoulder is at the feet end: [combo]")
+ // The blood pools under that shoulder: the head end of the body, past its middle
+ var/list/pool = finisher.pool_spot()
+ var/list/back = finisher.grab_pull_back()
+ // (from the middle of the body as it lies when the pool is laid: where it lay, seen from the front or back)
+ var/share = finisher.side_view() ? 0.5 : 1
+ var/pool_x = pool[1] - (victim.pixel_x + victim.pixel_w + back[1] * share)
+ var/pool_y = pool[2] - (victim.pixel_y + victim.pixel_z + back[2] * share)
+ TEST_ASSERT(pool_x * head_x + pool_y * head_y > 0, "The torn shoulder bleeds at the feet end: [combo]")
+ // Seen from the front or the back, his fists take the wrist on the shoulder's side of his middle
+ if(!finisher.side_view())
+ var/list/from = finisher.body_shoulder_at()
+ var/list/origin = finisher.bearer_origin()
+ if(abs(from[1] - origin[1]) > 1)
+ TEST_ASSERT((finisher.grip[1] - origin[1]) * (from[1] - origin[1]) > 0, "His fists took the wrist on the far side of him from its shoulder: [combo]")
+ finisher.stop(HV_FINISHER_TIMED_OUT)
+ qdel(bearer)
+ qdel(victim)
+ TEST_ASSERT_EQUAL(puppets_left(), 0, "The limb rips left puppets behind")
+
/// The backbreaker breaks the back (they can't stand) and shoves the body onto the tile the bearer faces, or drops it
/// at his feet if that tile is blocked; the fold comes off when the body is moved.
/datum/unit_test/voidcrew_gorilla_gore/finisher_backbreaker
@@ -1326,3 +1383,117 @@
TEST_ASSERT(refused & COMPONENT_CANCEL_ATTACK_CHAIN, "The Brawler pry didn't take the outpost door click")
sleep(0.5 SECONDS)
TEST_ASSERT(outpost_door.density, "The Brawler pair pried an outpost airlock")
+
+/// The limb rip's north-facing bar starts low, the bearer's puppets take on blood at the tear without baking in a hit
+/// flash, and side views keep floor blood under the body while every airborne shoulder drop flies above it.
+/datum/unit_test/voidcrew_gorilla_gore/finisher_rip_visuals
+
+/datum/unit_test/voidcrew_gorilla_gore/finisher_rip_visuals/Run()
+ // Facing north: the bar starts under the bearer's feet instead of sliding down across him
+ var/mob/living/carbon/human/north_bearer = gorilla(spot(1, 0))
+ north_bearer.zone_selected = BODY_ZONE_L_ARM
+ var/mob/living/carbon/human/consistent/north_victim = downed(spot(1, 1))
+ TEST_ASSERT(gorilla_try_finisher(north_bearer, north_victim), "The north-facing limb rip didn't start")
+ var/datum/hv_finisher/chrome/gorilla/rip/north_rip = north_bearer.chrome_finisher
+ TEST_ASSERT(istype(north_rip) && north_rip.facing == NORTH, "The north-facing rip didn't face north")
+ TEST_ASSERT_NOTNULL(north_rip.exec_bar, "The north-facing rip put up no bar")
+ TEST_ASSERT_EQUAL(north_rip.exec_bar.rest_z, -14, "The north-facing rip's bar doesn't rest under his feet") // GORILLA_RIP_BAR_LOW
+ TEST_ASSERT_EQUAL(north_rip.exec_bar.pixel_z, -14, "The north-facing rip's bar didn't start at its low rest height") // GORILLA_RIP_BAR_LOW
+ north_rip.stop(2) // HV_FINISHER_TIMED_OUT
+ qdel(north_bearer)
+ qdel(north_victim)
+
+ // At the tear, the bearer's puppets take on the blood on his clothes at once, without baking in a hit flash or turn
+ clear_mess(spot(1, 2))
+ clear_mess(spot(1, 3))
+ var/mob/living/carbon/human/bearer = gorilla(spot(1, 3))
+ if(!bearer.w_uniform)
+ bearer.equip_to_slot_or_del(new /obj/item/clothing/under/color/grey(bearer), ITEM_SLOT_ICLOTHING)
+ bearer.zone_selected = BODY_ZONE_L_ARM
+ var/mob/living/carbon/human/consistent/victim = downed(spot(1, 2))
+ TEST_ASSERT(gorilla_try_finisher(bearer, victim), "The south-facing limb rip didn't start")
+ var/datum/hv_finisher/chrome/gorilla/rip/finisher = bearer.chrome_finisher
+ TEST_ASSERT_NOTNULL(finisher.bearer_rig, "The south-facing rip built no bearer rig")
+ var/icon/flat_before = icon(finisher.bearer_rig.flat)
+ var/head_x = 0
+ var/head_y = 0
+ var/head_before
+ for(var/check_y in 24 to 28) // above CHROME_RIG_NECK_Y (23): bare head skin
+ for(var/check_x in 14 to 18)
+ var/px = flat_before.GetPixel(check_x, check_y)
+ if(px)
+ head_x = check_x
+ head_y = check_y
+ head_before = px
+ break
+ if(head_before)
+ break
+ TEST_ASSERT_NOTNULL(head_before, "Test fixture: found no opaque pixel on the bearer's bare head")
+ finisher.advance() // strain
+ var/list/drawn_before = list()
+ for(var/part_key in list("body", "arm_l", "arm_r"))
+ var/obj/effect/abstract/chrome_puppet/part = finisher.bearer_rig.puppet(part_key)
+ drawn_before[part_key] = part ? part.overlays.Copy() : list()
+ bearer.add_atom_colour("#ff0000", TEMPORARY_COLOUR_PRIORITY)
+ bearer.add_filter("hv_vis_flash", 10, color_matrix_filter(list(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, 0.4, 0.4, 0.4))) // HV_VIS_FLASH_FILTER
+ bearer.dir = EAST
+ finisher.advance() // tear
+ TEST_ASSERT(finisher.running, "Test fixture: the rip ended on the tear beat")
+ for(var/part_key in list("body", "arm_l", "arm_r"))
+ var/obj/effect/abstract/chrome_puppet/puppet = finisher.bearer_rig.puppet(part_key)
+ TEST_ASSERT_NOTNULL(puppet, "Missing bearer puppet [part_key] at the tear")
+ var/list/drawn_now = puppet.overlays.Copy()
+ TEST_ASSERT(length(drawn_now) >= 1 && !(drawn_now ~= drawn_before[part_key]), "Bearer puppet [part_key] didn't take on its bloodied picture at the tear")
+ var/icon/flat_after = finisher.bearer_rig.flat
+ TEST_ASSERT_NULL(flat_after.GetPixel(1, 1), "The redrawn bearer picture painted transparent corners solid")
+ TEST_ASSERT_EQUAL(flat_after.GetPixel(head_x, head_y), head_before, "A hit flash or turn tainted the bearer's bare head in the tear snapshot")
+ var/bloodied_pixels = 0
+ for(var/check_y in 1 to 22) // below CHROME_RIG_NECK_Y (23): clothed torso, arms and legs
+ for(var/check_x in 1 to 32)
+ if(flat_after.GetPixel(check_x, check_y) != flat_before.GetPixel(check_x, check_y))
+ bloodied_pixels++
+ TEST_ASSERT(bloodied_pixels > 0, "The tear snapshot drew no blood onto the bearer's clothed body")
+ TEST_ASSERT_EQUAL(LOWER_TEXT(bearer.color), "#ff0000", "The bearer's temporary colour wasn't restored after the snapshot")
+ bearer.remove_atom_colour(TEMPORARY_COLOUR_PRIORITY)
+ run_to_end(finisher)
+ qdel(bearer)
+ qdel(victim)
+
+ // Side views (east and west): floor blood stays under bodies, and every airborne drop flies above them from the socket rim
+ var/list/side_offsets = list("[EAST]" = list(-1, 0), "[WEST]" = list(1, 0))
+ for(var/way_text in side_offsets)
+ var/list/off = side_offsets[way_text]
+ clear_mess(spot(1, 2))
+ clear_mess(spot(2, 2))
+ clear_mess(spot(3, 2))
+ for(var/obj/effect/temp_visual/wire_blood_drop/earlier in spot(2, 2)) // the other side's drops, still in the air
+ qdel(earlier)
+ var/mob/living/carbon/human/consistent/side_victim = downed(spot(2, 2))
+ var/mob/living/carbon/human/side_bearer = gorilla(spot(2 + off[1], 2 + off[2]))
+ side_bearer.zone_selected = BODY_ZONE_L_ARM
+ TEST_ASSERT(gorilla_try_finisher(side_bearer, side_victim), "The [dir2text(text2num(way_text))] rip didn't start")
+ var/datum/hv_finisher/chrome/gorilla/rip/side_rip = side_bearer.chrome_finisher
+ var/list/expected_pool = side_rip.pool_spot()
+ side_rip.advance() // strain
+ side_rip.advance() // tear
+ var/obj/effect/decal/cleanable/blood/floor_pool
+ for(var/obj/effect/decal/cleanable/blood/decal in get_turf(side_victim))
+ if(decal.type == /obj/effect/decal/cleanable/blood)
+ floor_pool = decal
+ TEST_ASSERT_NOTNULL(floor_pool, "The [dir2text(text2num(way_text))] tear laid no floor blood on the tear tick")
+ // On the floor's own plane (tg's floor decals, layered from TOPDOWN_LAYER up) or under the mobs on theirs
+ TEST_ASSERT(PLANE_TO_TRUE(floor_pool.plane) < GAME_PLANE || floor_pool.layer < MOB_LAYER, "Floor blood in [dir2text(text2num(way_text))] was drawn over the bodies (plane [floor_pool.plane], layer [floor_pool.layer])")
+ TEST_ASSERT(floor_pool.base_pixel_x == expected_pool[1] && floor_pool.base_pixel_y == expected_pool[2], "Floor blood in [dir2text(text2num(way_text))] missed pool_spot()")
+ var/drop_count = 0
+ var/list/start_points = list()
+ for(var/obj/effect/temp_visual/wire_blood_drop/drop in get_turf(side_victim))
+ drop_count++
+ TEST_ASSERT_EQUAL(drop.layer, ABOVE_MOB_LAYER, "An airborne shoulder drop in [dir2text(text2num(way_text))] was hidden under the bodies ([drop.layer])")
+ TEST_ASSERT_EQUAL(drop.alpha, 255, "An airborne shoulder drop in [dir2text(text2num(way_text))] started invisible")
+ start_points["[drop.pixel_x],[drop.pixel_y]"] = TRUE
+ TEST_ASSERT_EQUAL(drop_count, 12, "The [dir2text(text2num(way_text))] tear threw [drop_count] drops instead of 12") // GORILLA_RIP_BURST_DROPS
+ TEST_ASSERT(length(start_points) > 1, "All airborne drops in [dir2text(text2num(way_text))] started stacked on one pixel")
+ run_to_end(side_rip)
+ qdel(side_bearer)
+ qdel(side_victim)
+ TEST_ASSERT_EQUAL(puppets_left(), 0, "The visual rip tests left puppets behind")
diff --git a/voidcrew/modules/unit_tests/voidcrew_hv_finishers.dm b/voidcrew/modules/unit_tests/voidcrew_hv_finishers.dm
index 09fb18b6baf..796b1d223e8 100644
--- a/voidcrew/modules/unit_tests/voidcrew_hv_finishers.dm
+++ b/voidcrew/modules/unit_tests/voidcrew_hv_finishers.dm
@@ -280,6 +280,8 @@
TEST_ASSERT_NOTNULL(bar, "the finisher put up no bar")
TEST_ASSERT_EQUAL(bar.loc, get_turf(matriarch), "the bar isn't over the matriarch")
TEST_ASSERT_EQUAL(bar.owner, matriarch, "the bar follows the wrong mob")
+ TEST_ASSERT(bar.rest_z > 0, "the bar has no rest height over the matriarch ([bar.rest_z])")
+ TEST_ASSERT_EQUAL(bar.pixel_z, bar.rest_z, "the bar started below its rest height and would climb across the body ([bar.pixel_z] vs [bar.rest_z])")
// A map object, not a client image: whoever has the tile in view sees it
TEST_ASSERT(bar.invisibility <= bystander.see_invisible, "a bystander can't see the bar")
TEST_ASSERT(can_see(bystander, bar, world.view), "the bar is out of the bystander's sight")
@@ -299,3 +301,28 @@
again.interrupt(3) // HV_FINISHER_DAMAGED
TEST_ASSERT(second_bar.ending, "the bar outlived the interrupt")
TEST_ASSERT(findtext(second_bar.icon_state, "_fail"), "an interrupted bar doesn't look failed")
+
+/// A bar stands over a body a move has leaned off its tile, goes with the lean, and comes back when the lean ends.
+/datum/unit_test/voidcrew_hv_finisher/bar_follows_lean
+
+/datum/unit_test/voidcrew_hv_finisher/bar_follows_lean/Run()
+ var/mob/living/carbon/human/killer = allocate(/mob/living/carbon/human/consistent, spot(0, 0))
+ var/obj/effect/abstract/hv_exec_bar/bar = hv_exec_bar_start(killer, 2 SECONDS)
+ TEST_ASSERT_NOTNULL(bar, "Test fixture: no bar")
+ TEST_ASSERT(bar.rest_z > 0 && bar.pixel_z == bar.rest_z, "A bar over a standing body didn't start at its rest height ([bar.pixel_z] vs [bar.rest_z])")
+ hv_exec_bar_lean(killer, 12, -3)
+ TEST_ASSERT(bar.pixel_x == 12 && bar.pixel_y == -3, "A bar didn't go with its body's lean ([bar.pixel_x], [bar.pixel_y])")
+ TEST_ASSERT_EQUAL(bar.pixel_z, bar.rest_z, "A sideways lean moved the bar's height ([bar.pixel_z] vs [bar.rest_z])")
+ var/list/existing = list()
+ existing[killer] = list(bar)
+ killer.progressbars = existing
+ var/obj/effect/abstract/hv_exec_bar/second = hv_exec_bar_start(killer, 2 SECONDS)
+ killer.progressbars = null
+ TEST_ASSERT(second.pixel_x == 12 && second.pixel_y == -3, "A bar started over a leaning body stands over the tile ([second.pixel_x], [second.pixel_y])")
+ TEST_ASSERT_EQUAL(second.rest_z, bar.rest_z + 6, "A stacked bar didn't sit one bar higher ([second.rest_z] vs [bar.rest_z])") // HV_EXEC_BAR_HEIGHT
+ TEST_ASSERT_EQUAL(second.pixel_z, second.rest_z, "A stacked bar didn't start at its stacked height ([second.pixel_z] vs [second.rest_z])")
+ hv_exec_bar_lean(killer)
+ TEST_ASSERT(bar.pixel_x == 0 && bar.pixel_y == 0, "A bar stayed off the tile after the lean ended")
+ TEST_ASSERT_NULL(killer.hv_exec_lean, "The lean was kept on the body after it ended")
+ qdel(bar)
+ qdel(second)
diff --git a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_exec_aim.dm b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_exec_aim.dm
new file mode 100644
index 00000000000..fcb71366f19
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_exec_aim.dm
@@ -0,0 +1,235 @@
+/**
+ * A gun execution's aimed pose (voidcrew/modules/hyperviolence/visuals/execution_aim.dm).
+ *
+ * A headless world draws nothing, so these check what the server keeps: where the pose puts the barrel's end against
+ * where the victim's head is drawn, from every side and for both ways a body lies, and that nothing of the pose is
+ * left on the shooter or the floor however the execution ends.
+ */
+
+/// Shared helpers; not a test itself
+/datum/unit_test/voidcrew_hv_exec_aim
+ abstract_type = /datum/unit_test/voidcrew_hv_exec_aim
+
+/// The floor `dx`, `dy` tiles from the test room's bottom-left corner
+/datum/unit_test/voidcrew_hv_exec_aim/proc/spot(dx, dy)
+ return locate(run_loc_floor_bottom_left.x + dx, run_loc_floor_bottom_left.y + dy, run_loc_floor_bottom_left.z)
+
+/// A shooter in the middle of the room with a pistol in hand, aiming at the head
+/datum/unit_test/voidcrew_hv_exec_aim/proc/make_shooter()
+ var/mob/living/carbon/human/consistent/shooter = allocate(/mob/living/carbon/human/consistent, spot(2, 2))
+ var/obj/item/gun/ballistic/automatic/pistol/gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ gun.can_misfire = FALSE
+ shooter.put_in_active_hand(gun, forced = TRUE)
+ shooter.zone_selected = BODY_ZONE_HEAD
+ return shooter
+
+/// A body on the floor `way` of the middle of the room, lying at `angle` (90: head to the east, 270: to the west)
+/datum/unit_test/voidcrew_hv_exec_aim/proc/make_victim(way, angle)
+ var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, get_step(spot(2, 2), way))
+ ADD_TRAIT(victim, TRAIT_PIERCEIMMUNE, INNATE_TRAIT) // no stray shrapnel
+ ADD_TRAIT(victim, TRAIT_DESIGNATED_TARGET, TRAIT_SOURCE_UNIT_TESTS) // tg's zone roll never sends the round off the head
+ victim.Knockdown(60 SECONDS)
+ victim.set_lying_angle(angle)
+ TEST_ASSERT_EQUAL(victim.body_position, LYING_DOWN, "Test fixture: the victim isn't on the floor")
+ return victim
+
+/// The rig's pictures standing anywhere near the middle of the room
+/datum/unit_test/voidcrew_hv_exec_aim/proc/pictures_up()
+ . = 0
+ for(var/obj/effect/abstract/chrome_puppet/picture in range(2, spot(2, 2)))
+ . += !QDELETED(picture)
+
+/// Fails if anything of the pose is left on `shooter`, their `gun` or the floor
+/datum/unit_test/voidcrew_hv_exec_aim/proc/check_nothing_left(mob/living/carbon/human/shooter, obj/item/gun/gun, how)
+ TEST_ASSERT_EQUAL(pictures_up(), 0, "Pictures of the aimed pose are still standing after the execution [how]")
+ if(!QDELETED(gun))
+ TEST_ASSERT_NULL(gun.hv_aim, "The gun still has its aimed pose after the execution [how]")
+ TEST_ASSERT(!gun.hv_aim_out_of_hand, "The gun is still left out of its holder's hand after the execution [how]")
+ if(QDELETED(shooter))
+ return
+ TEST_ASSERT(!shooter.filter_data?["chrome_rig_hide"], "The shooter is still hidden after the execution [how]")
+ TEST_ASSERT_EQUAL(shooter.mouse_opacity, initial(shooter.mouse_opacity), "The shooter's click area was not put back after the execution [how]")
+ TEST_ASSERT_EQUAL(shooter.pixel_w, 0, "The shooter is left [shooter.pixel_w] pixels aside after the execution [how]")
+ TEST_ASSERT_EQUAL(shooter.pixel_z, 0, "The shooter is left [shooter.pixel_z] pixels up after the execution [how]")
+ if(shooter.body_position == STANDING_UP) // on the floor tg has turned him itself
+ var/matrix/turned = shooter.transform
+ TEST_ASSERT(abs(turned.a - 1) < 0.001 && abs(turned.b) < 0.001 && abs(turned.c) < 0.001 && abs(turned.f) < 0.001, "The shooter is left turned or moved after the execution [how]")
+ if(QDELETED(gun) || !shooter.is_holding(gun))
+ return
+ var/list/hands = shooter.overlays_standing[HANDS_LAYER]
+ if(hands && !islist(hands))
+ hands = list(hands)
+ TEST_ASSERT(length(hands), "The shooter's held gun isn't drawn after the execution [how]")
+ for(var/mutable_appearance/held as anything in hands)
+ TEST_ASSERT(held.alpha, "The gun in the shooter's hand is still drawn as nothing after the execution [how]")
+
+/**
+ * From each side, and for a body lying each way, the aimed pose ends the barrel on the head as it is drawn, pointing at
+ * it: never at the other end of the body. The gun's picture really is posed there, and the shooter's own look keeps
+ * its gun.
+ */
+/datum/unit_test/voidcrew_hv_exec_aim/on_the_head
+
+/datum/unit_test/voidcrew_hv_exec_aim/on_the_head/Run()
+ var/mob/living/carbon/human/shooter = make_shooter()
+ var/obj/item/gun/gun = shooter.get_active_held_item()
+ for(var/way in GLOB.cardinals)
+ for(var/angle in list(90, 270))
+ var/mob/living/carbon/human/victim = make_victim(way, angle)
+ var/what = "from the [dir2text(REVERSE_DIR(way))] of a body lying [angle == 90 ? "head-east" : "head-west"]"
+ shooter.face_atom(victim)
+ var/datum/hv_exec_aim/aim = new(gun, shooter, victim)
+ TEST_ASSERT(aim.raise(), "The shooter couldn't be drawn aiming [what]")
+ // Where the head is drawn, from the middle of the shooter's tile
+ var/list/head_at = victim.hv_vis_head_offset()
+ var/head_x = (victim.x - shooter.x) * ICON_SIZE_X + head_at[1]
+ var/head_y = (victim.y - shooter.y) * ICON_SIZE_Y + head_at[2]
+ TEST_ASSERT_EQUAL(head_at[1], angle == 90 ? 9 : -9, "Test fixture: the head isn't drawn at the end the body lies toward")
+ var/off_x = head_x - aim.muzzle[1]
+ var/off_y = head_y - aim.muzzle[2]
+ var/off = sqrt(off_x * off_x + off_y * off_y)
+ // On the skull: HV_AIM_GAP (4) short of its middle, a little more where the arm is at its longest
+ TEST_ASSERT(off >= 2.5 && off <= 6.5, "The barrel ends [off] pixels from the middle of the head [what]: [aim.muzzle[1]],[aim.muzzle[2]] against [head_x],[head_y]")
+ // The other end of the body: its boots
+ var/boots_x = (victim.x - shooter.x) * ICON_SIZE_X - head_at[1] * 1.5
+ TEST_ASSERT(abs(aim.muzzle[1] - boots_x) > 12, "The barrel ends at the boots [what]")
+ TEST_ASSERT((off_x * aim.aim_x + off_y * aim.aim_y) / off > 0.95, "The barrel doesn't point at the head [what]")
+ // The gun's picture is posed with its barrel's end there
+ var/obj/effect/abstract/chrome_puppet/gun_picture = aim.rig.puppet("gun")
+ TEST_ASSERT_NOTNULL(gun_picture, "No picture of the gun stands [what]")
+ var/list/drawn_end = chrome_rig_apply(gun_picture.transform, aim.shape[3], aim.shape[4])
+ TEST_ASSERT(abs(drawn_end[1] - aim.muzzle[1]) < 0.5 && abs(drawn_end[2] - aim.muzzle[2]) < 0.5, "The gun's picture ends at [drawn_end[1]],[drawn_end[2]], not on the head, [what]")
+ // He leans toward the victim, never away
+ var/obj/effect/abstract/chrome_puppet/body_picture = aim.rig.puppet("body")
+ var/matrix/leaned = body_picture.transform
+ var/list/middle = chrome_rig_apply(leaned, 0, 0)
+ TEST_ASSERT(middle[1] * (victim.x - shooter.x) + middle[2] * (victim.y - shooter.y) > 0, "The shooter doesn't lean toward the victim [what]")
+ TEST_ASSERT(shooter.filter_data?["chrome_rig_hide"], "The real body shows under its aimed pose [what]")
+ TEST_ASSERT(!gun.hv_aim_out_of_hand, "The gun stays out of the shooter's own look during the hold [what]")
+ qdel(aim)
+ check_nothing_left(shooter, gun, "was dropped [what]")
+ qdel(victim)
+
+/// However an execution ends, nothing of the aimed pose is left: fired, called off, the shooter moved or knocked down,
+/// the gun dropped, the victim or the shooter deleted.
+/datum/unit_test/voidcrew_hv_exec_aim/nothing_left
+
+/datum/unit_test/voidcrew_hv_exec_aim/nothing_left/Run()
+ for(var/ending in list("fired", "called off", "the shooter moved", "the shooter fell", "the gun dropped", "the victim deleted", "the shooter deleted"))
+ var/mob/living/carbon/human/shooter = make_shooter()
+ var/obj/item/gun/gun = shooter.get_active_held_item()
+ // Head-east, the shooter to the west: the head is at the far end
+ var/mob/living/carbon/human/victim = make_victim(EAST, 90)
+ INVOKE_ASYNC(gun, TYPE_PROC_REF(/obj/item/gun, hv_start_execution), shooter, victim, null)
+ sleep(0.5 SECONDS)
+ TEST_ASSERT(gun.hv_aim?.is_up(), "No aimed pose during the hold (ending: [ending])")
+ TEST_ASSERT(pictures_up() >= 3, "The aimed pose has [pictures_up()] pictures up, not its three (ending: [ending])")
+ switch(ending)
+ if("fired")
+ sleep(1.1 SECONDS) // the 1.5 s hold is over: the shot
+ TEST_ASSERT_NULL(victim.get_bodypart(BODY_ZONE_HEAD), "Test fixture: the execution didn't burst the head")
+ TEST_ASSERT(gun.hv_aim?.is_up(), "The aimed pose went on the shot's own tick, before its recoil")
+ sleep(1 SECONDS)
+ if("called off")
+ shooter.zone_selected = BODY_ZONE_CHEST
+ sleep(0.6 SECONDS)
+ if("the shooter moved")
+ shooter.forceMove(spot(2, 3))
+ sleep(world.tick_lag * 2)
+ if("the shooter fell")
+ shooter.Knockdown(5 SECONDS)
+ sleep(world.tick_lag * 2)
+ if("the gun dropped")
+ shooter.dropItemToGround(gun, force = TRUE)
+ sleep(world.tick_lag * 2)
+ if("the victim deleted")
+ qdel(victim)
+ sleep(0.6 SECONDS)
+ if("the shooter deleted")
+ qdel(shooter)
+ sleep(world.tick_lag * 2)
+ check_nothing_left(shooter, gun, "ended with [ending]")
+ // Past the wind-up, whatever it was: nothing comes back
+ sleep(1.2 SECONDS)
+ check_nothing_left(shooter, gun, "ended with [ending], a moment later")
+ if(!QDELETED(victim))
+ qdel(victim)
+ if(!QDELETED(gun))
+ qdel(gun)
+ if(!QDELETED(shooter))
+ qdel(shooter)
+
+/**
+ * The shot's flash is at the end of the barrel as the aimed pose draws it, from every side, and the flashes tg and gun
+ * feel draw at the hip are not made for it. The next shot has its own again.
+ */
+/datum/unit_test/voidcrew_hv_exec_aim/flash_at_the_barrel
+
+/datum/unit_test/voidcrew_hv_exec_aim/flash_at_the_barrel/Run()
+ for(var/way in GLOB.cardinals)
+ var/mob/living/carbon/human/shooter = make_shooter()
+ var/obj/item/gun/gun = shooter.get_active_held_item()
+ var/mob/living/carbon/human/victim = make_victim(way, 90)
+ var/turf/victim_turf = get_turf(victim)
+ var/what = "from the [dir2text(REVERSE_DIR(way))]"
+ INVOKE_ASYNC(gun, TYPE_PROC_REF(/obj/item/gun, hv_start_execution), shooter, victim, null)
+ sleep(1.4 SECONDS)
+ var/datum/hv_exec_aim/aim = gun.hv_aim
+ TEST_ASSERT(aim?.is_up(), "No aimed pose at the end of the hold [what]")
+ var/list/barrel_end = aim.muzzle_from(victim_turf)
+ var/list/head_at = victim.hv_vis_head_offset()
+ // The 1.5 s hold ends: the shot. Its flash lasts 0.4 s.
+ var/obj/effect/temp_visual/hv_muzzle_flash/flash
+ var/until = world.time + 0.5 SECONDS
+ while(!flash && world.time < until)
+ sleep(world.tick_lag)
+ flash = locate() in victim_turf
+ TEST_ASSERT_NOTNULL(flash, "The execution made no flash [what]")
+ // The flash art's bright end is HV_VIS_FLASH_CORE (9) pixels off its middle, the way it faces
+ var/core_x = flash.pixel_w + ((flash.dir & EAST) ? 9 : ((flash.dir & WEST) ? -9 : 0))
+ var/core_y = flash.pixel_z + ((flash.dir & NORTH) ? 9 : ((flash.dir & SOUTH) ? -9 : 0))
+ TEST_ASSERT(abs(core_x - barrel_end[1]) <= 1 && abs(core_y - barrel_end[2]) <= 1, "The flash is at [core_x],[core_y], the barrel's end at [barrel_end[1]],[barrel_end[2]], [what]")
+ var/to_head = sqrt((core_x - head_at[1]) ** 2 + (core_y - head_at[2]) ** 2)
+ TEST_ASSERT(to_head <= 7.5, "The flash is [to_head] pixels from the head [what]")
+ TEST_ASSERT_NULL(locate(/obj/effect/temp_visual/gun_feel_muzzle_flash) in shooter, "The execution made gun feel's flash at the hip [what]")
+ TEST_ASSERT_NULL(locate(/obj/effect/temp_visual/dir_setting/firing_effect) in shooter, "The execution made tg's flash at the hip [what]")
+ TEST_ASSERT(!gun.hv_firing_execution, "The gun still counts as firing an execution round [what]")
+ sleep(1 SECONDS)
+ check_nothing_left(shooter, gun, "fired [what]")
+ // A plain shot after it has its flash at the hip as ever
+ var/obj/item/ammo_casing/next_round = gun.chambered
+ TEST_ASSERT_NOTNULL(next_round, "Test fixture: no round chambered after the execution")
+ TEST_ASSERT_EQUAL(next_round.firing_effect_type, initial(next_round.firing_effect_type), "The next round lost its flash [what]")
+ qdel(victim)
+ qdel(gun)
+ qdel(shooter)
+
+/// A cuffed victim on his feet, held off the middle of his tile as a grab holds him: the barrel is on the head where it
+/// is drawn. He lies down during the hold: the barrel follows the head to the floor.
+/datum/unit_test/voidcrew_hv_exec_aim/follows_the_head
+
+/datum/unit_test/voidcrew_hv_exec_aim/follows_the_head/Run()
+ var/mob/living/carbon/human/shooter = make_shooter()
+ var/obj/item/gun/gun = shooter.get_active_held_item()
+ var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, get_step(spot(2, 2), EAST))
+ ADD_TRAIT(victim, TRAIT_RESTRAINED, TRAIT_SOURCE_UNIT_TESTS)
+ victim.add_offsets(TRAIT_SOURCE_UNIT_TESTS, x_add = -12, animate = FALSE) // an aggressive grab's
+ var/datum/hv_exec_aim/aim = new(gun, shooter, victim)
+ TEST_ASSERT(aim.raise(), "The shooter couldn't be drawn aiming at a victim on his feet")
+ gun.hv_aim = aim
+ var/list/head_at = victim.hv_vis_head_offset()
+ TEST_ASSERT_EQUAL(head_at[1], -12, "A head held off the middle of its tile isn't found where it is drawn")
+ var/off = sqrt((ICON_SIZE_X + head_at[1] - aim.muzzle[1]) ** 2 + (head_at[2] - aim.muzzle[2]) ** 2)
+ TEST_ASSERT(off <= 6.5, "The barrel ends [off] pixels from the head of a victim on his feet")
+ victim.remove_offsets(TRAIT_SOURCE_UNIT_TESTS, animate = FALSE)
+ victim.Knockdown(60 SECONDS)
+ victim.set_lying_angle(90)
+ sleep(world.tick_lag * 4)
+ TEST_ASSERT(aim.is_up(), "The aimed pose went when the victim lay down")
+ head_at = victim.hv_vis_head_offset()
+ TEST_ASSERT_EQUAL(head_at[1], 9, "Test fixture: the victim's head isn't at the far end")
+ off = sqrt((ICON_SIZE_X + head_at[1] - aim.muzzle[1]) ** 2 + (head_at[2] - aim.muzzle[2]) ** 2)
+ TEST_ASSERT(off <= 6.5, "The barrel stayed [off] pixels from the head after the victim lay down")
+ TEST_ASSERT_EQUAL(pictures_up(), 3, "The aimed pose has [pictures_up()] pictures up after following the head, not three")
+ qdel(aim)
+ check_nothing_left(shooter, gun, "followed the head down")
diff --git a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm
index a52ae18d4b9..ac69bbdb0bf 100644
--- a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm
+++ b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm
@@ -211,3 +211,55 @@
TEST_ASSERT_EQUAL(body.pixel_w, pixel_before, "The death throes left the body [body.pixel_w - pixel_before] pixels aside")
var/matrix/after = body.transform
TEST_ASSERT(abs(after.a - lying.a) < 0.01 && abs(after.b - lying.b) < 0.01 && abs(after.d - lying.d) < 0.01 && abs(after.e - lying.e) < 0.01, "The death throes left the body turned differently from how tg laid it down")
+
+/// How many fresh victims the aimed-part tests below strike. At tg's odds a miss turns up in nearly every run.
+#define HV_AIMED_PART_TRIES 60
+
+/// An execution round from a tile away strikes the head every time: tg's zone roll for the shot never
+/// sends it to another part. No TRAIT_DESIGNATED_TARGET here, unlike the tests above (which shoot from
+/// the victim's own tile, where tg never rolls a miss).
+/datum/unit_test/hv_gun_execution_hits_head
+
+/datum/unit_test/hv_gun_execution_hits_head/Run()
+ var/mob/living/carbon/human/consistent/gunner = allocate(/mob/living/carbon/human/consistent)
+ gunner.zone_selected = BODY_ZONE_HEAD
+ var/turf/beside = get_step(run_loc_floor_bottom_left, EAST)
+ var/misses = 0
+ for(var/i in 1 to HV_AIMED_PART_TRIES)
+ var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, beside)
+ ADD_TRAIT(victim, TRAIT_PIERCEIMMUNE, INNATE_TRAIT) // no stray shrapnel
+ victim.Knockdown(30 SECONDS)
+ var/obj/item/gun/ballistic/automatic/pistol/gun = allocate(/obj/item/gun/ballistic/automatic/pistol)
+ gun.can_misfire = FALSE
+ gunner.put_in_active_hand(gun, forced = TRUE)
+ gun.chambered.loaded_projectile.damage = 10 // doubled at the muzzle: 20, nowhere near the burst line
+ var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD)
+ TEST_ASSERT(gun.hv_fire_execution(gunner, victim, null), "The execution shot did not fire")
+ if(head.brute_dam <= 0)
+ misses++
+ qdel(gun)
+ qdel(victim)
+ TEST_ASSERT_EQUAL(misses, 0, "[misses] of [HV_AIMED_PART_TRIES] execution rounds struck another part than the head")
+
+/// A finisher's real blow lands on the part it is aimed at every time, past tg's zone roll for a melee hit.
+/datum/unit_test/hv_finisher_blow_hits_aimed_part
+
+/datum/unit_test/hv_finisher_blow_hits_aimed_part/Run()
+ var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent)
+ var/obj/item/storage/toolbox/toolbox = allocate(/obj/item/storage/toolbox)
+ attacker.put_in_active_hand(toolbox, forced = TRUE)
+ var/turf/beside = get_step(run_loc_floor_bottom_left, EAST)
+ var/misses = 0
+ for(var/i in 1 to HV_AIMED_PART_TRIES)
+ var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, beside)
+ victim.Knockdown(30 SECONDS)
+ var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD)
+ var/datum/hv_finisher/finisher = new(attacker, victim)
+ TEST_ASSERT(finisher.real_blow(BODY_ZONE_HEAD), "The finisher's blow didn't swing")
+ if(head.brute_dam <= 0)
+ misses++
+ qdel(finisher)
+ qdel(victim)
+ TEST_ASSERT_EQUAL(misses, 0, "[misses] of [HV_AIMED_PART_TRIES] finisher blows struck another part than the head")
+
+#undef HV_AIMED_PART_TRIES
diff --git a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_visuals.dm b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_visuals.dm
index 64388853905..32057002534 100644
--- a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_visuals.dm
+++ b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_visuals.dm
@@ -461,3 +461,13 @@
TEST_ASSERT(length(victim._active_timers), "Nothing will take the flash off")
sleep(1 SECONDS)
TEST_ASSERT_NULL(victim.get_filter("hv_vis_flash"), "The flash stayed on")
+
+/// A body a finisher rig hides behind its puppets doesn't flash: the puppets do
+/datum/unit_test/voidcrew_hv_visuals/no_flash_when_hidden
+
+/datum/unit_test/voidcrew_hv_visuals/no_flash_when_hidden/Run()
+ var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, spot(1, 1))
+ victim.add_filter("chrome_rig_hide", 1, color_matrix_filter(list(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,0, 0,0,0,0)))
+ victim.hv_vis_flash()
+ TEST_ASSERT_NULL(victim.get_filter("hv_vis_flash"), "A body hidden by a rig flashed")
+ victim.remove_filter("chrome_rig_hide")
diff --git a/voidcrew/modules/unit_tests/voidcrew_tutorials.dm b/voidcrew/modules/unit_tests/voidcrew_tutorials.dm
new file mode 100644
index 00000000000..4cb6e58fe8f
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_tutorials.dm
@@ -0,0 +1,1546 @@
+// Tutorial checklist (voidcrew/modules/tutorials). Each test drives the real hooked proc and
+// reads SSvc_tutorials.progress. Fork defines are included after the test harness, so step
+// keys are literals here; the catalog test checks every TUTORIAL_STEP_* a hook uses against
+// voidcrew/_DEFINES/tutorials.dm and the live catalog.
+// Credits INSERT into tutorial_completions only when a database is connected; the fake ckey
+// makes those rows harmless and the unique index keeps them to one per key.
+
+#define TUTORIAL_TEST_CKEY "tutorialtest"
+
+/// Ship interiors come from the zone teleport fixture (area + registered docking port).
+/datum/unit_test/voidcrew_tutorials
+ parent_type = /datum/unit_test/voidcrew_zone_teleport
+ abstract_type = /datum/unit_test/voidcrew_tutorials
+ var/list/crew_records = list()
+ var/list/keyed_players = list()
+
+/datum/unit_test/voidcrew_tutorials/New()
+ . = ..()
+ // The fixture's Destroy restores this; it never set it itself.
+ zones_were_active = SSovermap_zones.zones_active
+ SSvc_tutorials.progress -= TUTORIAL_TEST_CKEY
+
+/datum/unit_test/voidcrew_tutorials/Destroy()
+ SSvc_tutorials.progress -= TUTORIAL_TEST_CKEY
+ GLOB.tutorial_checklist_hidden -= TUTORIAL_TEST_CKEY
+ // A deleted mob that still holds a key with no client is reported as a stuck player.
+ for(var/mob/player as anything in keyed_players)
+ player.key = null
+ QDEL_LIST(crew_records)
+ return ..()
+
+/// A keyed player body. The hot-path hooks bail on mobs without a ckey.
+/datum/unit_test/voidcrew_tutorials/proc/make_player(turf/location = run_loc_floor_bottom_left)
+ var/mob/living/carbon/human/consistent/player = allocate(/mob/living/carbon/human/consistent, location)
+ player.mind_initialize()
+ allocated += player.mind
+ player.mind.key = TUTORIAL_TEST_CKEY
+ player.key = TUTORIAL_TEST_CKEY
+ keyed_players += player
+ return player
+
+/// A ship whose interior is ship_turf, crewed by the given player.
+/datum/unit_test/voidcrew_tutorials/proc/make_crewed_ship(turf/ship_turf, mob/living/player)
+ var/obj/structure/overmap/ship/ship = make_ship(ship_turf, run_loc_floor_top_right)
+ var/datum/team/voidcrew/team = allocate(/datum/team/voidcrew)
+ team.ship = ship
+ ship.ship_team = team
+ if(player)
+ team.join_member(player.mind)
+ crew_records |= ship.get_crew_record()
+ return ship
+
+/datum/unit_test/voidcrew_tutorials/proc/done(key)
+ return SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, key)
+
+/datum/unit_test/voidcrew_tutorials/proc/reset_progress()
+ SSvc_tutorials.progress -= TUTORIAL_TEST_CKEY
+
+/// Swaps one turf into a fresh area; the fixture restores it.
+/datum/unit_test/voidcrew_tutorials/proc/make_area(turf/location, area_type)
+ var/area/new_area = new area_type
+ ship_areas += new_area
+ original_areas[location] = get_area(location)
+ location.change_area(get_area(location), new_area)
+ return new_area
+
+/// Keys unique and short, under "vc/", each item has a category, an intro and a counted step,
+/// route steps come in two or more routes, and every key a hook credits is a step in the catalog.
+/datum/unit_test/voidcrew_tutorials/catalog/Run()
+ SSvc_tutorials.build_catalog()
+ TEST_ASSERT_EQUAL(length(SSvc_tutorials.items), 17, "The checklist does not have its seventeen items")
+ var/list/seen = list()
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ check_key(item.id, seen)
+ TEST_ASSERT(item.name, "[item.id] has no name")
+ TEST_ASSERT(item.category && GLOB.tutorial_categories[item.category], "[item.id] has no panel category")
+ TEST_ASSERT(istext(item.intro) && length(trimtext(item.intro)), "[item.id] has no intro")
+ var/counted = 0
+ var/list/routes = list()
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ check_key(step.key, seen)
+ TEST_ASSERT(findtext(step.key, "[item.id]/") == 1, "[step.key] is not under its item [item.id]")
+ TEST_ASSERT(step.name && step.text, "[step.key] has no name or text")
+ if(step.route)
+ TEST_ASSERT(step.route_name, "[step.key] has a route with no name")
+ routes |= step.route
+ if(!step.optional)
+ counted++
+ TEST_ASSERT(counted, "[item.id] has no step that counts")
+ TEST_ASSERT(!length(routes) || length(routes) >= 2, "[item.id] has route steps but only one route")
+
+ var/list/define_values = list()
+ var/defines = file2text("voidcrew/_DEFINES/tutorials.dm")
+ var/regex/define_regex = regex("#define (TUTORIAL_STEP_\[A-Z_\]+) \"(\[^\"\]+)\"", "g")
+ while(define_regex.Find(defines))
+ define_values[define_regex.group[1]] = define_regex.group[2]
+ TEST_ASSERT(length(define_values) >= 30, "Could not read the step defines")
+ var/regex/use_regex = regex("TUTORIAL_STEP_\[A-Z_\]+", "g")
+ var/files_read = 0
+ for(var/file_name in flist("voidcrew/modules/tutorials/"))
+ if(!findtext(file_name, ".dm", -3))
+ continue
+ files_read++
+ var/source = file2text("voidcrew/modules/tutorials/[file_name]")
+ while(use_regex.Find(source))
+ var/define_name = use_regex.match
+ var/key = define_values[define_name]
+ TEST_ASSERT(key, "[file_name] uses [define_name], which is not defined")
+ TEST_ASSERT(SSvc_tutorials.steps_by_key[key], "[file_name] credits [key], which no checklist step owns")
+ TEST_ASSERT(files_read >= 10, "Could not read the tutorial hook files")
+
+/datum/unit_test/voidcrew_tutorials/catalog/proc/check_key(key, list/seen)
+ TEST_ASSERT(istext(key) && length(key), "A checklist key is empty")
+ TEST_ASSERT(length(key) <= 64, "[key] is longer than the 64 characters the table holds")
+ TEST_ASSERT(findtext(key, "vc/") == 1, "[key] does not start with vc/")
+ TEST_ASSERT(!seen[key], "[key] is used twice")
+ seen[key] = TRUE
+
+/// A two-route item built outside the catalog (no id, so build_catalog skips the type).
+/datum/vc_tutorial/route_test
+ name = "Route test"
+ steps = list(
+ /datum/vc_tutorial_step/route_test_shared,
+ /datum/vc_tutorial_step/route_test_a1,
+ /datum/vc_tutorial_step/route_test_a2,
+ /datum/vc_tutorial_step/route_test_b1,
+ )
+
+/datum/vc_tutorial_step/route_test_shared
+ key = "vc/route_test/shared"
+ name = "Shared"
+ text = "Shared step."
+
+/datum/vc_tutorial_step/route_test_a1
+ key = "vc/route_test/a1"
+ name = "A1"
+ text = "Route A, first step."
+ route = "a"
+ route_name = "Route A"
+
+/datum/vc_tutorial_step/route_test_a2
+ key = "vc/route_test/a2"
+ name = "A2"
+ text = "Route A, second step."
+ route = "a"
+ route_name = "Route A"
+
+/datum/vc_tutorial_step/route_test_b1
+ key = "vc/route_test/b1"
+ name = "B1"
+ text = "Route B."
+ route = "b"
+ route_name = "Route B"
+
+/// Finishing every step of route A excuses route B and completes the item.
+/datum/unit_test/voidcrew_tutorials/routes
+ var/datum/vc_tutorial/route_test/test_item
+
+/datum/unit_test/voidcrew_tutorials/routes/Destroy()
+ if(test_item)
+ for(var/datum/vc_tutorial_step/step as anything in test_item.steps)
+ SSvc_tutorials.steps_by_key -= step.key
+ SSvc_tutorials.item_by_step -= step.key
+ QDEL_LIST(test_item.steps)
+ QDEL_NULL(test_item)
+ return ..()
+
+/datum/unit_test/voidcrew_tutorials/routes/Run()
+ SSvc_tutorials.build_catalog()
+ test_item = new
+ test_item.id = "vc/route_test"
+ var/list/step_instances = list()
+ for(var/step_type in test_item.steps)
+ var/datum/vc_tutorial_step/step = new step_type
+ step_instances += step
+ SSvc_tutorials.steps_by_key[step.key] = step
+ SSvc_tutorials.item_by_step[step.key] = test_item
+ test_item.steps = step_instances
+ var/datum/vc_tutorial_step/a1 = step_instances[2]
+ var/datum/vc_tutorial_step/b1 = step_instances[4]
+ var/mob/living/carbon/human/player = make_player()
+
+ tutorial_credit(player, "vc/route_test/shared")
+ tutorial_credit(player, "vc/route_test/a1")
+ TEST_ASSERT(!b1.excused(player), "Route B was excused with route A half done")
+ TEST_ASSERT(!SSvc_tutorials.item_complete(test_item, TUTORIAL_TEST_CKEY, player), "The item completed with route A half done")
+ tutorial_credit(player, "vc/route_test/a2")
+ TEST_ASSERT(b1.excused(player), "Finishing route A did not excuse route B")
+ TEST_ASSERT(b1.route_excused(TUTORIAL_TEST_CKEY), "Finishing route A did not excuse route B by ckey")
+ TEST_ASSERT(!a1.excused(player), "The finished route excused itself")
+ TEST_ASSERT(SSvc_tutorials.item_complete(test_item, TUTORIAL_TEST_CKEY, null), "Finishing route A did not complete the item")
+ TEST_ASSERT(done("vc/route_test"), "Finishing route A did not save the item key")
+ TEST_ASSERT(!done("vc/route_test/b1"), "Route B's step was marked done")
+
+/// The suggested item is the first incomplete one in panel order with a step the viewer
+/// can do now: steps marked unavailable or excused don't count.
+/datum/unit_test/voidcrew_tutorials/suggested/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ make_crewed_ship(deck, player)
+ SSvc_tutorials.build_catalog()
+ tutorial_credit(player, "vc/ship/manage")
+ TEST_ASSERT_EQUAL(SSvc_tutorials.suggested_item(TUTORIAL_TEST_CKEY, player), "vc/ship", "A new player was not pointed at Your ship")
+ // What's left of Your ship needs a helm, and this hull has none.
+ tutorial_credit(player, "vc/ship/search")
+ TEST_ASSERT_EQUAL(SSvc_tutorials.suggested_item(TUTORIAL_TEST_CKEY, player), "vc/power", "Steps marked unavailable still held the suggestion")
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ SSvc_tutorials.progress[TUTORIAL_TEST_CKEY][item.id] = TRUE
+ TEST_ASSERT_NULL(SSvc_tutorials.suggested_item(TUTORIAL_TEST_CKEY, player), "Something was suggested with every item done")
+
+/// Opening a locker aboard counts; one off the ship doesn't.
+/datum/unit_test/voidcrew_tutorials/ship_search/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/turf/outside = get_step(deck, EAST)
+ var/mob/living/carbon/human/player = make_player(outside)
+ make_crewed_ship(deck, player)
+ var/obj/structure/closet/off_ship = allocate(/obj/structure/closet, outside)
+ TEST_ASSERT(off_ship.open(player), "The off-ship locker would not open")
+ TEST_ASSERT(!done("vc/ship/search"), "A locker off the ship counted as searching the ship")
+ player.forceMove(deck)
+ var/obj/structure/closet/aboard = allocate(/obj/structure/closet, deck)
+ TEST_ASSERT(aboard.open(player), "The locker aboard would not open")
+ TEST_ASSERT(done("vc/ship/search"), "Opening a locker aboard was not credited")
+
+/// An abandoned cache opened off-ship counts.
+/datum/unit_test/voidcrew_tutorials/ruin_cache/Run()
+ var/mob/living/carbon/human/player = make_player()
+ // A crate won't open with someone standing on it.
+ var/obj/structure/closet/crate/zone_loot/cache = allocate(/obj/structure/closet/crate/zone_loot, get_step(run_loc_floor_bottom_left, EAST))
+ TEST_ASSERT(cache.open(player), "The cache would not open")
+ TEST_ASSERT(done("vc/ruin/cache"), "Opening an abandoned cache was not credited")
+
+/// Walking into a ruin, and into a vestige (which is also a ruin).
+/datum/unit_test/voidcrew_tutorials/ruin_entry/Run()
+ var/turf/start = run_loc_floor_bottom_left
+ var/turf/ruin_turf = get_step(start, EAST)
+ var/turf/vestige_turf = get_step(ruin_turf, EAST)
+ make_area(ruin_turf, /area/ruin)
+ make_area(vestige_turf, /area/ruin/space/has_grav/vestige)
+ var/mob/living/carbon/human/player = make_player(start)
+ player.forceMove(ruin_turf)
+ TEST_ASSERT(done("vc/ruin/find"), "Entering a ruin was not credited")
+ TEST_ASSERT(!done("vc/vestige/find"), "A plain ruin counted as a vestige")
+ reset_progress()
+ player.forceMove(vestige_turf)
+ TEST_ASSERT(done("vc/vestige/find"), "Entering a vestige was not credited")
+ TEST_ASSERT(done("vc/ruin/find"), "A vestige did not count as a ruin")
+
+/datum/unit_test/voidcrew_tutorials/surgery/Run()
+ var/mob/living/carbon/human/surgeon = make_player()
+ var/mob/living/carbon/human/patient = allocate(/mob/living/carbon/human/consistent)
+ var/datum/surgery/operation = new /datum/surgery(patient, BODY_ZONE_CHEST, patient.get_bodypart(BODY_ZONE_CHEST))
+ operation.complete(surgeon)
+ TEST_ASSERT(QDELETED(operation), "The finished operation was not cleaned up")
+ TEST_ASSERT(done("vc/surgery/finish"), "Finishing an operation was not credited")
+
+/// A dissection that pays research counts; reopening a spent body doesn't.
+/datum/unit_test/voidcrew_tutorials/dissection/Run()
+ var/mob/living/carbon/human/surgeon = make_player()
+ var/mob/living/carbon/human/corpse = allocate(/mob/living/carbon/human/consistent, get_step(run_loc_floor_bottom_left, EAST))
+ corpse.death()
+ var/datum/surgery_step/experimental_dissection/dissect = allocate(/datum/surgery_step/experimental_dissection)
+ dissect.success(surgeon, corpse, BODY_ZONE_CHEST, null, null)
+ TEST_ASSERT(corpse.dissection_points_paid > 0, "The dissection paid nothing")
+ TEST_ASSERT(done("vc/surgery/dissect"), "A paying dissection was not credited")
+ reset_progress()
+ dissect.success(surgeon, corpse, BODY_ZONE_CHEST, null, null)
+ TEST_ASSERT(!done("vc/surgery/dissect"), "Re-dissecting a spent body was credited")
+ for(var/obj/item/research_notes/notes in surgeon.loc)
+ qdel(notes)
+ for(var/obj/item/research_notes/notes in surgeon.held_items)
+ qdel(notes)
+
+/// Survey console and Shuttle Warfare Systems credit the crew of the ship holding the server.
+/datum/unit_test/voidcrew_tutorials/research_nodes/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(get_step(deck, EAST))
+ make_crewed_ship(deck, player)
+ var/datum/techweb/web = allocate(/datum/techweb)
+ var/obj/machinery/rnd/server/server = allocate(/obj/machinery/rnd/server, deck)
+ web.techweb_servers |= server
+ // TECHWEB_NODE_SURVEY_CONSOLE and TECHWEB_NODE_SHIP_COMBAT
+ TEST_ASSERT(web.research_node(SSresearch.techweb_node_by_id("survey_console"), TRUE, FALSE, FALSE), "The survey console node could not be researched")
+ TEST_ASSERT(done("vc/surveys/node"), "Researching the survey console was not credited to the crew")
+ TEST_ASSERT(!done("vc/zones/warfare"), "The survey node counted as warfare research")
+ TEST_ASSERT(web.research_node(SSresearch.techweb_node_by_id("ship_combat"), TRUE, FALSE, FALSE), "The warfare node could not be researched")
+ TEST_ASSERT(done("vc/zones/warfare"), "Researching Shuttle Warfare Systems was not credited to the crew")
+ web.techweb_servers -= server
+
+/// Buying chrome at a trader counts for trade and for cyberware.
+/datum/unit_test/voidcrew_tutorials/purchase/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/structure/overmap/ship/ship = make_crewed_ship(get_step(run_loc_floor_bottom_left, EAST), player)
+ var/datum/bank_account/account = allocate(/datum/bank_account, "Tutorial test", null, 1, FALSE)
+ account.account_balance = 1000
+ ship.ship_account = account
+ var/datum/shop_sku/sku = allocate(/datum/shop_sku)
+ sku.item_path = /obj/item/organ/cyberimp/cyberware/shock_coils
+ sku.price_credits = 500
+ sku.stock = 1
+ TEST_ASSERT(sku.try_purchase(player, null), "The stocked general SKU would not sell")
+ TEST_ASSERT_EQUAL(account.account_balance, 500, "The purchase charged the wrong amount")
+ TEST_ASSERT(done("vc/trade/buy"), "Buying from a trader was not credited")
+ TEST_ASSERT(done("vc/chrome/buy"), "Buying chrome was not credited")
+ ship.ship_account = null
+ for(var/obj/item/organ/cyberimp/bought in player.held_items)
+ qdel(bought)
+ for(var/obj/item/organ/cyberimp/bought in player.loc)
+ qdel(bought)
+
+/// A real install counts for the body that gets it; a special (spawn/clone) insert doesn't.
+/datum/unit_test/voidcrew_tutorials/chrome_install/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/item/organ/cyberimp/chest/nutriment/silent = allocate(/obj/item/organ/cyberimp/chest/nutriment)
+ silent.Insert(player, TRUE)
+ TEST_ASSERT(silent.owner == player, "The special insert failed")
+ TEST_ASSERT(!done("vc/chrome/install"), "A special insert was credited")
+ silent.Remove(player, TRUE)
+ var/obj/item/organ/cyberimp/chest/nutriment/implant = allocate(/obj/item/organ/cyberimp/chest/nutriment)
+ implant.Insert(player)
+ TEST_ASSERT(implant.owner == player, "The install failed")
+ TEST_ASSERT(done("vc/chrome/install"), "Installing an implant was not credited")
+
+/// A chrome finisher that lands counts; one called off, or a boss-style finisher, doesn't.
+/datum/unit_test/voidcrew_tutorials/chrome_execute/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent, get_step(run_loc_floor_bottom_left, EAST))
+
+ var/datum/hv_finisher/chrome/called_off = new(player, victim)
+ called_off.running = TRUE
+ called_off.stop(HV_FINISHER_LOST_GRIP)
+ TEST_ASSERT(!done("vc/chrome/execute"), "A called-off chrome finisher was credited")
+
+ var/datum/hv_finisher/boss_style = new(player, victim)
+ boss_style.running = TRUE
+ boss_style.completed = TRUE
+ boss_style.stop(HV_FINISHER_DONE)
+ qdel(boss_style)
+ TEST_ASSERT(!done("vc/chrome/execute"), "A non-chrome finisher was credited")
+
+ var/datum/hv_finisher/chrome/finished = new(player, victim)
+ finished.running = TRUE
+ finished.completed = TRUE
+ finished.stop(HV_FINISHER_DONE)
+ TEST_ASSERT(done("vc/chrome/execute"), "A finished chrome execution was not credited")
+
+ reset_progress()
+ var/datum/hv_finisher/mantis_scissor/scissor = new(player, victim)
+ scissor.running = TRUE
+ scissor.completed = TRUE
+ scissor.stop(HV_FINISHER_DONE)
+ qdel(scissor)
+ TEST_ASSERT(done("vc/chrome/execute"), "A finished Mantis scissor was not credited")
+
+/// Redeeming research notes at an R&D console.
+/datum/unit_test/voidcrew_tutorials/research_notes/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/computer/rdconsole/console = allocate(/obj/machinery/computer/rdconsole, get_step(run_loc_floor_bottom_left, EAST))
+ var/datum/techweb/web = allocate(/datum/techweb)
+ console.stored_research = web
+ var/obj/item/research_notes/notes = allocate(/obj/item/research_notes, run_loc_floor_bottom_left)
+ notes.value = 10
+ console.attackby(notes, player)
+ TEST_ASSERT(QDELETED(notes), "The console did not take the notes")
+ TEST_ASSERT(done("vc/surveys/notes"), "Turning in research notes was not credited")
+ console.stored_research = null
+
+/// R&D setup: kit, built ship server, disk, multitool, built console and protolathe, then links.
+/// The link step waits until both the console and the protolathe are on the server's web.
+/datum/unit_test/voidcrew_tutorials/rnd_setup/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/structure/overmap/ship/ship = make_crewed_ship(deck, player)
+
+ var/obj/item/storage/box/rndboards/all/kit = allocate(/obj/item/storage/box/rndboards/all, deck)
+ kit.pickup(player)
+ TEST_ASSERT(done("vc/research/kit"), "Picking up the R&D kit was not credited")
+
+ var/obj/machinery/rnd/server/ship/server = allocate(/obj/machinery/rnd/server/ship, deck)
+ TEST_ASSERT(!done("vc/research/server"), "A spawned server counted as building one")
+ server.on_construction(player)
+ TEST_ASSERT(done("vc/research/server"), "Building the ship server was not credited")
+
+ var/obj/item/computer_disk/ship_disk/disk = allocate(/obj/item/computer_disk/ship_disk, deck)
+ server.attacked_by(disk, player)
+ TEST_ASSERT_EQUAL(server.source_code_hdd, disk, "The server did not take the disk")
+ TEST_ASSERT(done("vc/research/disk"), "Adding the ship disk was not credited")
+
+ var/obj/item/multitool/tool = allocate(/obj/item/multitool, deck)
+ server.multitool_act(player, tool)
+ TEST_ASSERT_EQUAL(tool.buffer, disk.stored_research, "The multitool did not store the server's techweb")
+ TEST_ASSERT(done("vc/research/multitool"), "Multitooling the server was not credited")
+
+ var/obj/machinery/computer/rdconsole/console = allocate(/obj/machinery/computer/rdconsole, deck)
+ console.on_construction(player)
+ TEST_ASSERT(done("vc/research/console"), "Building the R&D console was not credited")
+ var/obj/machinery/rnd/production/protolathe/lathe = allocate(/obj/machinery/rnd/production/protolathe, deck)
+ lathe.on_construction(player)
+ TEST_ASSERT(done("vc/research/protolathe"), "Building the protolathe was not credited")
+ console.unsync_research_servers()
+ lathe.unsync_research_servers()
+
+ console.multitool_act(player, tool)
+ TEST_ASSERT_EQUAL(console.stored_research, disk.stored_research, "The console did not link to the server")
+ TEST_ASSERT(!done("vc/research/link"), "Linking only the console counted as linking everything")
+ TEST_ASSERT(!tutorial_ship_rnd_linked(ship), "The ship counted as linked with the protolathe unlinked")
+ lathe.multitool_act(player, tool)
+ TEST_ASSERT_EQUAL(lathe.stored_research, disk.stored_research, "The protolathe did not link to the server")
+ TEST_ASSERT(done("vc/research/link"), "Linking the console and protolathe was not credited")
+ TEST_ASSERT(done("vc/research"), "Finishing every R&D step did not complete the item")
+ console.unsync_research_servers()
+ lathe.unsync_research_servers()
+
+/// Starting a PACMAN counts; stopping one doesn't.
+/datum/unit_test/voidcrew_tutorials/generator/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/power/port_gen/pacman/generator = allocate(/obj/machinery/power/port_gen/pacman, get_step(run_loc_floor_bottom_left, EAST))
+ generator.sheets = 50
+ var/datum/tgui/generator_ui = allocate(/datum/tgui, player, generator, "PortableGenerator")
+ generator.ui_act("toggle_power", list(), generator_ui, generator_ui.state)
+ TEST_ASSERT(generator.active, "The generator did not start")
+ TEST_ASSERT(done("vc/power/generator"), "Starting the generator was not credited")
+ reset_progress()
+ generator.ui_act("toggle_power", list(), generator_ui, generator_ui.state)
+ TEST_ASSERT(!generator.active, "The generator did not stop")
+ TEST_ASSERT(!done("vc/power/generator"), "Stopping the generator was credited")
+
+/// Dock and undock credit crew aboard; a ship with no berth doesn't count as docked.
+/datum/unit_test/voidcrew_tutorials/dock_undock/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/structure/overmap/ship/ship = make_crewed_ship(deck, player)
+ SEND_SIGNAL(ship, "voidcrew_ship_docked") // COMSIG_VOIDCREW_SHIP_DOCKED
+ TEST_ASSERT(!done("vc/ship/dock"), "A rebuild with no berth counted as docking")
+ var/obj/structure/overmap/ship/berth = allocate(/obj/structure/overmap/ship, get_step(run_loc_floor_top_right, WEST))
+ ship.docked = berth
+ SEND_SIGNAL(ship, "voidcrew_ship_docked") // COMSIG_VOIDCREW_SHIP_DOCKED
+ ship.docked = null
+ TEST_ASSERT(done("vc/ship/dock"), "Docking was not credited to the crew aboard")
+ TEST_ASSERT(!done("vc/ruin/land"), "Docking at a ship counted as landing on a planet")
+ SEND_SIGNAL(ship, "voidcrew_ship_undocked") // COMSIG_VOIDCREW_SHIP_UNDOCKED
+ TEST_ASSERT(done("vc/ship/undock"), "Undocking was not credited to the crew aboard")
+ TEST_ASSERT(!done("vc/trade/travel"), "Docking at a ship counted as reaching an outpost")
+ var/obj/structure/overmap/trader_outpost/outpost = allocate(/obj/structure/overmap/trader_outpost, get_step(run_loc_floor_top_right, WEST))
+ ship.docked = outpost
+ SEND_SIGNAL(ship, "voidcrew_ship_docked") // COMSIG_VOIDCREW_SHIP_DOCKED
+ ship.docked = null
+ TEST_ASSERT(done("vc/trade/travel"), "Docking at a trader outpost was not credited to the crew aboard")
+
+/// Pact, completed trial and claimed boon.
+/datum/unit_test/voidcrew_tutorials/vestige/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/mind/keeper = player.mind
+ var/datum/vestige_trial/trial = allocate(/datum/vestige_trial, keeper, "Test patron", list())
+ keeper.active_vestige_trial = trial
+ trial.begin(player)
+ TEST_ASSERT(done("vc/vestige/pact"), "Making a pact was not credited")
+ trial.complete()
+ TEST_ASSERT(QDELETED(trial), "The completed trial was not cleaned up")
+ TEST_ASSERT(done("vc/vestige/trial"), "Completing a trial was not credited")
+ reset_progress()
+ trial.complete()
+ TEST_ASSERT(!done("vc/vestige/trial"), "A stale completion was credited")
+
+ var/datum/vestige_record/record = get_vestige_record(keeper, create = TRUE)
+ var/list/candidates = list(/datum/vestige_boon/unit_test_a)
+ record.pending_candidates = candidates.Copy()
+ var/datum/action/vestige_reward/reward = allocate(/datum/action/vestige_reward, keeper, candidates, "Test patron")
+ reward.Grant(player)
+ reward.claim(player, keeper, /datum/vestige_boon/unit_test_a)
+ TEST_ASSERT(/datum/vestige_boon/unit_test_a in keeper.vestige_boons, "The boon was not paid")
+ TEST_ASSERT(done("vc/vestige/claim"), "Claiming a boon was not credited")
+ GLOB.vestige_records -= ckey(keeper.key)
+ qdel(record)
+
+/// A smart locker counts once a player finishes building one and once they put something in it.
+/// Shelf assembly and crate loading wait in do_after, so they are not driven here.
+/datum/unit_test/voidcrew_tutorials/smart_locker/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/smartfridge/storage/locker = allocate(/obj/machinery/smartfridge/storage, get_step(run_loc_floor_bottom_left, EAST))
+ TEST_ASSERT(!done("vc/storage/locker"), "A spawned smart locker counted as building one")
+ locker.on_construction(player)
+ TEST_ASSERT(done("vc/storage/locker"), "Building a smart locker was not credited")
+ var/obj/item/wrench/stored = allocate(/obj/item/wrench)
+ TEST_ASSERT(player.put_in_hands(stored), "The player could not hold the item")
+ TEST_ASSERT(locker.load(stored, player), "The smart locker refused the item")
+ TEST_ASSERT_EQUAL(stored.loc, locker, "The item did not go into the smart locker")
+ TEST_ASSERT(done("vc/storage/store"), "Storing an item in a smart locker was not credited")
+
+/// Researching Shuttle Repair Swarm credits the crew whose techweb did it.
+/datum/unit_test/voidcrew_tutorials/repair_swarm_research/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(get_step(deck, EAST))
+ make_crewed_ship(deck, player)
+ var/datum/techweb/web = allocate(/datum/techweb)
+ var/obj/machinery/rnd/server/server = allocate(/obj/machinery/rnd/server, deck)
+ web.techweb_servers |= server
+ // TECHWEB_NODE_SHIP_REPAIR_SWARM
+ TEST_ASSERT(web.research_node(SSresearch.techweb_node_by_id("ship_repair_swarm"), TRUE, FALSE, FALSE), "The repair swarm node could not be researched")
+ TEST_ASSERT(done("vc/repair_drones/research"), "Researching Shuttle Repair Swarm was not credited to the crew")
+ web.techweb_servers -= server
+
+/// A save being used, from the lobby or a shipyard console, credits whoever saved it.
+/datum/unit_test/voidcrew_tutorials/ship_save_load/Run()
+ var/datum/ship_save_store/old_store = GLOB.ship_save_store
+ var/datum/ship_saves/old_saves = GLOB.ship_saves
+ var/datum/ship_economy_db/old_economy = GLOB.ship_economy_db
+ var/datum/ship_save_store/fake/store = new
+ store.saved["[TUTORIAL_TEST_CKEY]|1"] = list("meta" = list(), "payload" = null)
+ GLOB.ship_save_store = store
+ GLOB.ship_saves = new /datum/ship_saves
+ GLOB.ship_economy_db = new /datum/ship_economy_db/fake
+ GLOB.ship_saves.spend(TUTORIAL_TEST_CKEY, 1)
+ var/credited = done("vc/ship_save/load")
+ var/removed = !store.saved["[TUTORIAL_TEST_CKEY]|1"]
+ qdel(GLOB.ship_saves)
+ qdel(GLOB.ship_economy_db)
+ qdel(store)
+ GLOB.ship_save_store = old_store
+ GLOB.ship_saves = old_saves
+ GLOB.ship_economy_db = old_economy
+ TEST_ASSERT(removed, "The spent save was not removed")
+ TEST_ASSERT(credited, "Using a saved ship was not credited")
+
+/// The outline follows the open item's first unfinished step, honours the preference, and
+/// cleans up when its target is deleted or the viewer logs out.
+/datum/unit_test/voidcrew_tutorials/highlights
+ var/datum/tutorial_highlight/highlight
+
+/datum/unit_test/voidcrew_tutorials/highlights/Destroy()
+ QDEL_NULL(highlight)
+ SSvc_tutorials.selected -= TUTORIAL_TEST_CKEY
+ return ..()
+
+/datum/unit_test/voidcrew_tutorials/highlights/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ make_crewed_ship(deck, player)
+ SSvc_tutorials.build_catalog()
+ SSvc_tutorials.selected[TUTORIAL_TEST_CKEY] = "vc/ship"
+ var/obj/structure/closet/locker = allocate(/obj/structure/closet, deck)
+ var/obj/machinery/computer/helm/helm = allocate(/obj/machinery/computer/helm, deck)
+
+ // A clientless body never gets one by itself.
+ tutorial_refresh_highlights(player)
+ TEST_ASSERT_NULL(GLOB.tutorial_highlighters[TUTORIAL_TEST_CKEY], "A body with no client got highlights")
+
+ highlight = new(player)
+ highlight.wanted_override = TRUE
+ highlight.rebuild(player)
+ // Ship management is captain-only, so a crewmate's first step is searching the lockers.
+ var/image/locker_image = highlight.images[locker]
+ TEST_ASSERT(locker_image, "The locker by the player was not outlined for the search step")
+ TEST_ASSERT(!highlight.images[helm], "The helm was outlined before its step")
+ TEST_ASSERT(length(highlight.images) <= 3, "More than three objects were outlined")
+ TEST_ASSERT_EQUAL(locker_image.loc, locker, "The outline is not attached to the locker")
+ TEST_ASSERT_EQUAL(length(locker_image.filters), 2, "The outline is missing its outline or glow filter")
+
+ // Finishing the step moves the outline on through the real credit path.
+ tutorial_credit(player, "vc/ship/search")
+ TEST_ASSERT(highlight.images[helm], "The helm was not outlined once searching was done")
+ TEST_ASSERT(!highlight.images[locker], "The locker stayed outlined after its step was done")
+
+ highlight.wanted_override = FALSE
+ highlight.rebuild(player)
+ TEST_ASSERT_EQUAL(length(highlight.images), 0, "Outlines showed with the preference off")
+ highlight.wanted_override = TRUE
+ highlight.rebuild(player)
+ TEST_ASSERT(highlight.images[helm], "The helm was not outlined again with the preference back on")
+
+ qdel(helm)
+ TEST_ASSERT(!(helm in highlight.images), "A deleted helm kept its outline")
+
+ var/obj/machinery/computer/helm/second_helm = allocate(/obj/machinery/computer/helm, deck)
+ highlight.rebuild(player)
+ TEST_ASSERT(highlight.images[second_helm], "A new helm was not outlined")
+ SEND_SIGNAL(player, COMSIG_MOB_LOGOUT)
+ TEST_ASSERT(QDELETED(highlight), "Logging out did not end the highlights")
+ TEST_ASSERT_EQUAL(length(highlight.images), 0, "Logging out left outline images behind")
+ TEST_ASSERT_NULL(GLOB.tutorial_highlighters[TUTORIAL_TEST_CKEY], "Logging out left the viewer registered")
+ highlight = null
+
+/// Taking a contract credits whoever accepted it; work and turn-in credit the crew.
+/datum/unit_test/voidcrew_tutorials_contract
+ parent_type = /datum/unit_test/voidcrew_zone_missions
+
+/datum/unit_test/voidcrew_tutorials_contract
+ var/mob/keyed_member
+
+/datum/unit_test/voidcrew_tutorials_contract/Destroy()
+ SSvc_tutorials.progress -= TUTORIAL_TEST_CKEY
+ keyed_member?.key = null
+ return ..()
+
+/datum/unit_test/voidcrew_tutorials_contract/Run()
+ SSvc_tutorials.progress -= TUTORIAL_TEST_CKEY
+ var/obj/structure/overmap/ship/ship = make_ship(0, FALSE)
+ // The fixture's bare account has no job, so it can't unregister itself on delete.
+ var/datum/bank_account/fixture_account = ship.ship_account
+ SSeconomy.bank_accounts_by_id -= "[fixture_account.account_id]"
+ fixture_account.add_to_accounts = FALSE
+ var/mob/living/carbon/human/member = allocate(/mob/living/carbon/human/consistent)
+ member.mind_initialize()
+ allocated += member.mind
+ member.mind.key = TUTORIAL_TEST_CKEY
+ member.key = TUTORIAL_TEST_CKEY
+ keyed_member = member
+ ship.enlist_crewmember(member)
+ var/datum/mission/mission = allocate(/datum/mission/zone_missions_test, null, 1)
+ ship.available_missions += mission
+ usr = member
+ TEST_ASSERT_EQUAL(ship.accept_mission(mission), TRUE, "The contract was refused")
+ usr = null
+ TEST_ASSERT(SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, "vc/contract/take"), "Taking a contract was not credited")
+ TEST_ASSERT(!SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, "vc/contract/turn_in"), "Taking a contract counted as turning it in")
+ TEST_ASSERT(mission.turn_in(run_loc_floor_bottom_left, null), "The contract did not settle")
+ TEST_ASSERT(SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, "vc/contract/work"), "Doing the contract was not credited to the crew")
+ TEST_ASSERT(SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, "vc/contract/turn_in"), "Turning in the contract was not credited to the crew")
+ TEST_ASSERT(SSvc_tutorials.has_key(TUTORIAL_TEST_CKEY, "vc/contract"), "Finishing every contract step did not complete the item")
+
+/// A hostile NPC hull with no AI and no spawner record. The overrides keep a hull failure
+/// from crash-landing a ship that has no interior.
+/obj/structure/overmap/ship/npc/tutorial_test
+ name = "tutorial test pirate"
+ spawner_resolved = TRUE
+
+/obj/structure/overmap/ship/npc/tutorial_test/crash_land()
+ return
+
+/obj/structure/overmap/ship/npc/tutorial_test/get_random_ship_turf()
+ return null
+
+/obj/structure/overmap/ship/npc/tutorial_test/start_critical_alert()
+ return
+
+/obj/structure/overmap/ship/npc/tutorial_test/stop_critical_alert()
+ return
+
+/// A player hull whose ship-to-ship dock always succeeds without moving anything.
+/obj/structure/overmap/ship/tutorial_dock_test
+
+/obj/structure/overmap/ship/tutorial_dock_test/dock_ships_directly(obj/structure/overmap/ship/other_ship, mob/user, instant = FALSE)
+ return null
+
+/// Stands in for a missile in flight; gone a moment after the launcher's delayed spawn.
+/obj/effect/temp_visual/tutorial_test_missile
+ duration = 1
+
+/// A launcher that can always fire, with a harmless missile loaded.
+/obj/machinery/ship_combat/missile_launcher/tutorial_test
+
+/obj/machinery/ship_combat/missile_launcher/tutorial_test/can_fire()
+ return TRUE
+
+/obj/machinery/ship_combat/missile_launcher/tutorial_test/get_missile_spawn_turf(turf/target, obj/structure/overmap/tgt_ship, approach_dir = null)
+ return target
+
+/// Like make_crewed_ship(), but with a chosen hull type.
+/datum/unit_test/voidcrew_tutorials/proc/make_crewed_ship_of_type(turf/ship_turf, mob/living/player, ship_type)
+ var/area/shuttle/voidcrew/ship_area = new
+ ship_areas += ship_area
+ original_areas[ship_turf] = get_area(ship_turf)
+ ship_turf.change_area(get_area(ship_turf), ship_area)
+ var/obj/docking_port/mobile/voidcrew/port = new(ship_turf)
+ port.shuttle_areas[ship_area] = TRUE
+ port.register()
+ ship_area.shuttle_port = port
+ var/obj/structure/overmap/ship/ship = allocate(ship_type, run_loc_floor_top_right)
+ ship.shuttle = port
+ port.current_ship = ship
+ ships += ship
+ var/datum/team/voidcrew/team = allocate(/datum/team/voidcrew)
+ team.ship = ship
+ ship.ship_team = team
+ team.join_member(player.mind)
+ crew_records |= ship.get_crew_record()
+ return ship
+
+/// Building a ship weapon from a frame credits the builder; a mapped one doesn't.
+/datum/unit_test/voidcrew_tutorials/weapon_build/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/ship_combat/interdictor/interdictor = allocate(/obj/machinery/ship_combat/interdictor, get_step(run_loc_floor_bottom_left, EAST))
+ TEST_ASSERT(!done("vc/weapons/interdictor"), "A spawned interdictor counted as building one")
+ interdictor.on_construction(player)
+ TEST_ASSERT(done("vc/weapons/interdictor"), "Building an interdictor was not credited")
+ TEST_ASSERT(!done("vc/weapons/shield"), "Building an interdictor counted as a shield generator")
+
+/// Sealing a loaded missile credits whoever armed it; unsealing it doesn't.
+/datum/unit_test/voidcrew_tutorials/missile_arm/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/structure/ship_missile/missile = allocate(/obj/structure/ship_missile, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/item/screwdriver/tool = allocate(/obj/item/screwdriver)
+ TEST_ASSERT(player.put_in_active_hand(tool), "The player could not hold the screwdriver")
+ missile.construction_state = 3 // MISSILE_STATE_PAYLOAD
+ missile.attackby(tool, player)
+ TEST_ASSERT_EQUAL(missile.construction_state, 4, "The screwdriver did not arm the missile") // MISSILE_STATE_ARMED
+ TEST_ASSERT(done("vc/weapons/missile"), "Arming a missile was not credited")
+ reset_progress()
+ missile.attackby(tool, player)
+ TEST_ASSERT_EQUAL(missile.construction_state, 3, "The screwdriver did not unseal the missile") // MISSILE_STATE_PAYLOAD
+ TEST_ASSERT(!done("vc/weapons/missile"), "Unsealing a missile was credited")
+
+/// A launch at a ship credits the player who fired; an NPC launch has no player to credit.
+/datum/unit_test/voidcrew_tutorials/missile_fire/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/ship_combat/missile_launcher/tutorial_test/launcher = allocate(/obj/machinery/ship_combat/missile_launcher/tutorial_test, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/structure/overmap/ship/target_ship = allocate(/obj/structure/overmap/ship, get_step(run_loc_floor_top_right, WEST))
+ var/turf/target_turf = get_step(run_loc_floor_top_right, SOUTH)
+ launcher.loaded_missile = list("effect_type" = /obj/effect/temp_visual/tutorial_test_missile)
+ TEST_ASSERT(launcher.fire(target_turf, target_ship, null, null), "The NPC launch failed")
+ TEST_ASSERT(!done("vc/combat/missile"), "A launch with no player was credited")
+ launcher.loaded_missile = list("effect_type" = /obj/effect/temp_visual/tutorial_test_missile)
+ TEST_ASSERT(launcher.fire(target_turf, target_ship, null, player), "The launch failed")
+ TEST_ASSERT(done("vc/combat/missile"), "Launching a missile at a ship was not credited")
+ // Let the delayed missile spawns land and clear inside the test.
+ sleep(2 SECONDS)
+
+/// Force-docking a held pirate credits the user, and boarding it to the crew aboard.
+/datum/unit_test/voidcrew_tutorials/force_dock/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/structure/overmap/ship/our_ship = make_crewed_ship_of_type(deck, player, /obj/structure/overmap/ship/tutorial_dock_test)
+ var/obj/structure/overmap/ship/npc/tutorial_test/pirate = allocate(/obj/structure/overmap/ship/npc/tutorial_test, get_turf(our_ship))
+ pirate.state = "flying" // OVERMAP_SHIP_FLYING
+ var/obj/machinery/ship_combat/interdictor/interdictor = allocate(/obj/machinery/ship_combat/interdictor, get_step(run_loc_floor_top_right, SOUTH))
+ interdictor.linked_ship_ref = WEAKREF(our_ship)
+ TEST_ASSERT(!interdictor.force_dock_target(player), "Force-docking with no lock succeeded")
+ TEST_ASSERT(!done("vc/combat/force_dock"), "A failed force-dock was credited")
+ interdictor.interdicted_ship_ref = WEAKREF(pirate)
+ interdictor.interdiction_active = TRUE
+ TEST_ASSERT(interdictor.force_dock_target(player), "The force-dock failed")
+ TEST_ASSERT(done("vc/combat/force_dock"), "Force-docking was not credited")
+ TEST_ASSERT(done("vc/pirates/board"), "Force-docking a pirate was not credited as boarding it")
+
+/// Hunting pirates: finishing "Let them board" excuses "Fight ship to ship" and completes the
+/// item. The boss and the dock go through their real procs; the wave handler is called directly.
+/datum/unit_test/voidcrew_tutorials/pirate_routes/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/structure/overmap/ship/our_ship = make_crewed_ship(deck, player)
+ var/obj/structure/overmap/ship/npc/tutorial_test/pirate = allocate(/obj/structure/overmap/ship/npc/tutorial_test, get_turf(our_ship))
+ var/datum/ai_controller/npc_ship/controller = new(pirate)
+ pirate.ai_controller = controller
+ // The ship controller has no movement type, and the base Destroy() it calls into reads one.
+ controller.change_ai_movement_type(/datum/ai_movement/dumb)
+ controller.set_blackboard_key("npc_target", our_ship) // BB_NPC_TARGET
+
+ controller.tutorial_on_wave_complete(controller, 1)
+ TEST_ASSERT(done("vc/pirates/boarders"), "Clearing the boarding wave was not credited")
+ controller.handle_boss_killed()
+ TEST_ASSERT(pirate.is_disabled, "Beating the commander did not disable the pirate ship")
+ TEST_ASSERT(done("vc/pirates/commander"), "Beating the commander was not credited")
+ reset_progress()
+ controller.handle_boss_killed()
+ TEST_ASSERT(!done("vc/pirates/commander"), "A second boss call on a disabled ship was credited")
+ tutorial_credit(player, "vc/pirates/boarders")
+ tutorial_credit(player, "vc/pirates/commander")
+
+ var/datum/vc_tutorial_step/shoot = SSvc_tutorials.steps_by_key["vc/pirates/shoot"]
+ var/datum/vc_tutorial/item = SSvc_tutorials.item_by_step["vc/pirates/shoot"]
+ TEST_ASSERT(!shoot.excused(player), "Fight ship to ship was excused with Let them board unfinished")
+ var/obj/structure/overmap/planet/empty/space = allocate(/obj/structure/overmap/planet/empty, get_step(run_loc_floor_top_right, WEST))
+ var/list/saved_ships = SSovermap.simulated_ships
+ SSovermap.simulated_ships = list(our_ship, pirate)
+ pirate.docked = space
+ our_ship.docked = space
+ SEND_SIGNAL(our_ship, "voidcrew_ship_docked") // COMSIG_VOIDCREW_SHIP_DOCKED
+ our_ship.docked = null
+ pirate.docked = null
+ SSovermap.simulated_ships = saved_ships
+ TEST_ASSERT(done("vc/pirates/board"), "Docking beside a pirate ship was not credited as boarding it")
+ TEST_ASSERT(shoot.excused(player), "Finishing Let them board did not excuse Fight ship to ship")
+ TEST_ASSERT(SSvc_tutorials.item_complete(item, TUTORIAL_TEST_CKEY, player), "Finishing Let them board did not complete Hunting pirates")
+ TEST_ASSERT(done("vc/pirates"), "Finishing Let them board did not save the item key")
+ TEST_ASSERT(!done("vc/pirates/shoot"), "Fight ship to ship was marked done")
+
+/// A pirate hull failing credits the crew it was fighting, once.
+/datum/unit_test/voidcrew_tutorials/pirate_shot_down/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/structure/overmap/ship/our_ship = make_crewed_ship(deck, player)
+ var/obj/structure/overmap/ship/npc/tutorial_test/pirate = allocate(/obj/structure/overmap/ship/npc/tutorial_test, get_step(run_loc_floor_top_right, WEST))
+ var/datum/ai_controller/npc_ship/controller = new(pirate)
+ pirate.ai_controller = controller
+ // The ship controller has no movement type, and the base Destroy() it calls into reads one.
+ controller.change_ai_movement_type(/datum/ai_movement/dumb)
+ controller.set_blackboard_key("npc_target", our_ship) // BB_NPC_TARGET
+ pirate.on_ship_destroyed()
+ TEST_ASSERT(pirate.has_crash_landed, "The pirate hull did not fail")
+ TEST_ASSERT(done("vc/pirates/shoot"), "Shooting down a pirate was not credited to its target's crew")
+ reset_progress()
+ pirate.on_ship_destroyed()
+ TEST_ASSERT(!done("vc/pirates/shoot"), "A hull that had already failed was credited again")
+
+// ---------------------------------------------------------------------------
+// Guide step, candidates, window focus, arrow and live lines (tutorial_highlights.dm).
+// The steps below are test-only: they belong to no catalog item, so they never show in game.
+// ---------------------------------------------------------------------------
+
+/datum/vc_tutorial_step/unit_test_plain
+ key = "vc/test/plain"
+ name = "Nothing to point at"
+
+/datum/vc_tutorial_step/unit_test_closet
+ key = "vc/test/closet"
+ name = "Lockers"
+ highlight_types = list(/obj/structure/closet)
+ /// When set, only these candidates survive highlight_filter(), so map lockers don't count.
+ var/list/allowed
+ /// Returned by extra_targets().
+ var/list/extras = list()
+
+/datum/vc_tutorial_step/unit_test_closet/highlight_filter(mob/user, atom/candidate)
+ return !allowed || (candidate in allowed)
+
+/datum/vc_tutorial_step/unit_test_closet/extra_targets(mob/user)
+ return extras
+
+/datum/vc_tutorial_step/unit_test_focus
+ key = "vc/test/focus"
+ name = "Window only"
+ ui_focus = list("test_window" = "test_button")
+
+/datum/vc_tutorial_step/unit_test_mob
+ key = "vc/test/mob"
+ name = "People"
+ highlight_types = list(/mob/living/carbon/human)
+
+/datum/vc_tutorial_step/unit_test_live
+ key = "vc/test/live"
+ name = "Live"
+
+/datum/vc_tutorial_step/unit_test_live/live_line(mob/user)
+ return "Batteries at 12%"
+
+/// The guide step is the first undone step with something to point at, else the first undone
+/// step; mobs and turfs can be candidates; filters and extra targets apply; the viewer is never
+/// a candidate.
+/datum/unit_test/voidcrew_tutorials/guide_step/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/datum/vc_tutorial/item = new
+ item.id = "vc/test"
+ var/datum/vc_tutorial_step/unit_test_plain/plain = new
+ var/datum/vc_tutorial_step/unit_test_closet/closet_step = new
+ var/datum/vc_tutorial_step/unit_test_focus/focus_step = new
+
+ // Nothing to point at anywhere: the first undone step.
+ item.steps = list(plain)
+ TEST_ASSERT_EQUAL(tutorial_pick_guide_step(player, item), plain, "With nothing to point at, the first undone step was not the guide")
+ // A later step with a window focus beats an earlier one with nothing.
+ item.steps = list(plain, focus_step)
+ TEST_ASSERT_EQUAL(tutorial_pick_guide_step(player, item), focus_step, "A step with a window focus was skipped")
+ // A step with no lockers in reach is skipped; with one beside the player it is the guide.
+ item.steps = list(plain, closet_step, focus_step)
+ closet_step.allowed = list()
+ TEST_ASSERT_EQUAL(tutorial_pick_guide_step(player, item), focus_step, "A step with no lockers in reach was chosen")
+ var/obj/structure/closet/locker = allocate(/obj/structure/closet, deck)
+ closet_step.allowed = list(locker)
+ TEST_ASSERT_EQUAL(tutorial_pick_guide_step(player, item), closet_step, "The step with a locker beside the player was not the guide")
+ // Done steps are skipped.
+ SSvc_tutorials.progress[TUTORIAL_TEST_CKEY] = list("vc/test/closet" = TRUE)
+ TEST_ASSERT_EQUAL(tutorial_pick_guide_step(player, item), focus_step, "A done step stayed the guide")
+ reset_progress()
+
+ // Filter and extra targets.
+ var/obj/structure/closet/other_locker = allocate(/obj/structure/closet, run_loc_floor_top_right)
+ closet_step.allowed = null
+ var/list/candidates = tutorial_step_candidates(player, closet_step)
+ TEST_ASSERT((locker in candidates) && (other_locker in candidates), "Both lockers in view were not candidates")
+ closet_step.allowed = list(other_locker)
+ candidates = tutorial_step_candidates(player, closet_step)
+ TEST_ASSERT(!(locker in candidates) && (other_locker in candidates), "highlight_filter() did not drop the other locker")
+ closet_step.allowed = list(run_loc_floor_top_right)
+ closet_step.extras = list(run_loc_floor_top_right)
+ candidates = tutorial_step_candidates(player, closet_step)
+ TEST_ASSERT(run_loc_floor_top_right in candidates, "An extra_targets() turf was not a candidate")
+ closet_step.extras = list()
+
+ // Mobs: another person is a candidate, the viewer never is.
+ var/datum/vc_tutorial_step/unit_test_mob/mob_step = new
+ var/mob/living/carbon/human/consistent/patient = allocate(/mob/living/carbon/human/consistent, run_loc_floor_top_right)
+ candidates = tutorial_step_candidates(player, mob_step)
+ TEST_ASSERT(patient in candidates, "A person in view was not a candidate")
+ TEST_ASSERT(!(player in candidates), "The viewer was a candidate for their own step")
+
+ // Turfs by type, and their outline is a frame on the turf.
+ var/datum/vc_tutorial_step/unit_test_plain/turf_step = new
+ turf_step.highlight_types = list(run_loc_floor_top_right.type)
+ candidates = tutorial_step_candidates(player, turf_step)
+ TEST_ASSERT(run_loc_floor_top_right in candidates, "A floor of the step's type was not a candidate")
+ var/datum/tutorial_highlight/highlight = new(player)
+ highlight.wanted_override = TRUE
+ var/image/frame = highlight.make_image(run_loc_floor_top_right)
+ TEST_ASSERT_EQUAL(frame.loc, run_loc_floor_top_right, "The turf frame is not on the turf")
+ TEST_ASSERT_EQUAL(frame.icon_state, "selector", "The turf outline is not the frame")
+ qdel(highlight)
+
+/// The default arrow target, the screen check, and where the arrow sits for a 21x15 view.
+/datum/unit_test/voidcrew_tutorials/arrow/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/list/view_size = getviewsize(world.view)
+ var/far_x = min(deck.x + 30, world.maxx)
+ var/turf/far = locate(far_x, deck.y, deck.z)
+ TEST_ASSERT(far_x - deck.x > (view_size[1] - 1) / 2, "The test map is too narrow for an off-screen target")
+ TEST_ASSERT(!tutorial_on_screen(deck, far, view_size), "A turf thirty tiles away counted as on screen")
+ TEST_ASSERT(tutorial_on_screen(deck, run_loc_floor_top_right, view_size), "A turf beside the player counted as off screen")
+ TEST_ASSERT_EQUAL(tutorial_default_arrow_target(player, list(far)), far, "The arrow did not point at an off-screen target")
+ TEST_ASSERT_NULL(tutorial_default_arrow_target(player, list(far, run_loc_floor_top_right)), "The arrow showed while a target was on screen")
+
+ var/atom/movable/screen/tutorial_arrow/arrow = allocate(/atom/movable/screen/tutorial_arrow)
+ arrow.point(10, 0, list(21, 15))
+ TEST_ASSERT_EQUAL(arrow.screen_loc, "CENTER+9:0,CENTER+0:0", "The arrow is not one tile in from the east edge")
+ arrow.point(-10, 0, list(21, 15))
+ TEST_ASSERT_EQUAL(arrow.screen_loc, "CENTER-9:0,CENTER+0:0", "The arrow is not one tile in from the west edge")
+ arrow.point(0, -20, list(21, 15))
+ TEST_ASSERT_EQUAL(arrow.screen_loc, "CENTER+0:0,CENTER-5:0", "The arrow is not two tiles in from the south edge, above the HUD buttons")
+
+/// tutorial_ui_focus() follows the viewer's guide step and is null with highlights off.
+/datum/unit_test/voidcrew_tutorials/ui_focus
+ var/datum/tutorial_highlight/highlight
+
+/datum/unit_test/voidcrew_tutorials/ui_focus/Destroy()
+ QDEL_NULL(highlight)
+ SSvc_tutorials.selected -= TUTORIAL_TEST_CKEY
+ return ..()
+
+/datum/unit_test/voidcrew_tutorials/ui_focus/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ make_crewed_ship(deck, player)
+ SSvc_tutorials.build_catalog()
+ SSvc_tutorials.selected[TUTORIAL_TEST_CKEY] = "vc/ship"
+ allocate(/obj/structure/closet, deck)
+ allocate(/obj/machinery/computer/helm, deck)
+
+ TEST_ASSERT_NULL(tutorial_ui_focus(player, "helm"), "A viewer with no highlights got a window focus")
+ highlight = new(player)
+ highlight.wanted_override = TRUE
+ highlight.rebuild(player)
+ TEST_ASSERT_NULL(tutorial_ui_focus(player, "helm"), "The helm was focused while the search step was the guide")
+ tutorial_credit(player, "vc/ship/search")
+ TEST_ASSERT_EQUAL(tutorial_ui_focus(player, "helm"), "helm_course", "The helm did not focus its heading pad for the course step")
+ TEST_ASSERT_NULL(tutorial_ui_focus(player, "weapons"), "A window the step has no focus for got one")
+ highlight.wanted_override = FALSE
+ highlight.rebuild(player)
+ TEST_ASSERT_NULL(tutorial_ui_focus(player, "helm"), "The window focus stayed with highlights off")
+
+/// The panel sends live lines for the open item's undone steps only.
+/datum/unit_test/voidcrew_tutorials/live_lines
+ var/datum/vc_tutorial/test_item
+
+/datum/unit_test/voidcrew_tutorials/live_lines/Destroy()
+ SSvc_tutorials.items -= test_item
+ SSvc_tutorials.selected -= TUTORIAL_TEST_CKEY
+ test_item = null
+ return ..()
+
+/datum/unit_test/voidcrew_tutorials/live_lines/Run()
+ var/mob/living/carbon/human/player = make_player(run_loc_floor_bottom_left)
+ SSvc_tutorials.build_catalog()
+ test_item = new
+ test_item.id = "vc/test"
+ test_item.steps = list(new /datum/vc_tutorial_step/unit_test_live)
+ SSvc_tutorials.items += test_item
+ SSvc_tutorials.selected[TUTORIAL_TEST_CKEY] = "vc/test"
+
+ var/list/data = GLOB.tutorial_checklist.ui_data(player)
+ var/list/live = data["live"]
+ TEST_ASSERT_EQUAL(live["vc/test/live"], "Batteries at 12%", "The open item's live line was not sent")
+ SSvc_tutorials.progress[TUTORIAL_TEST_CKEY] = list("vc/test/live" = TRUE)
+ data = GLOB.tutorial_checklist.ui_data(player)
+ live = data["live"]
+ TEST_ASSERT(!live["vc/test/live"], "A done step's live line was still sent")
+ SSvc_tutorials.selected[TUTORIAL_TEST_CKEY] = "vc/ship"
+ SSvc_tutorials.progress[TUTORIAL_TEST_CKEY] = list()
+ data = GLOB.tutorial_checklist.ui_data(player)
+ live = data["live"]
+ TEST_ASSERT(!live["vc/test/live"], "A live line was sent for an item that is not open")
+
+// ---------------------------------------------------------------------------
+// ship-power
+// ---------------------------------------------------------------------------
+
+/// Lockers already opened, or opened and emptied, are not pointed at.
+/datum/unit_test/voidcrew_tutorials/ship_power_lockers/Run()
+ SSvc_tutorials.build_catalog()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/ship/search"]
+ var/obj/structure/closet/locker = allocate(/obj/structure/closet, get_step(run_loc_floor_bottom_left, EAST))
+ TEST_ASSERT(step.highlight_filter(player, locker), "A closed, unsearched locker was not pointed at")
+ TEST_ASSERT(locker.open(player), "The locker would not open")
+ TEST_ASSERT(!step.highlight_filter(player, locker), "An open locker was still pointed at")
+ TEST_ASSERT(locker.close(player), "The locker would not close")
+ TEST_ASSERT(!step.highlight_filter(player, locker), "An emptied locker was still pointed at")
+
+/// The generator line follows the generator: unbolted, no fuel, ready, running.
+/datum/unit_test/voidcrew_tutorials/ship_power_generator_line/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/obj/machinery/power/port_gen/pacman/generator = allocate(/obj/machinery/power/port_gen/pacman, deck)
+ make_crewed_ship(deck, player)
+ SSvc_tutorials.build_catalog()
+ SSvc_tutorials.machine_cache.Cut()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/power/generator"]
+ generator.set_anchored(FALSE)
+ TEST_ASSERT_EQUAL(step.live_line(player), "Not bolted down. Wrench it to the floor.", "An unbolted generator was not reported")
+ generator.set_anchored(TRUE)
+ generator.sheets = 0
+ TEST_ASSERT_EQUAL(step.live_line(player), "No solid plasma loaded.", "An empty generator did not name its fuel")
+ generator.sheets = 10
+ TEST_ASSERT_EQUAL(step.live_line(player), "Ready. Turn it on.", "A fuelled, bolted generator was not ready")
+ generator.active = TRUE
+ TEST_ASSERT_EQUAL(step.live_line(player), "Running.", "A running generator was not reported")
+ generator.active = FALSE
+ SSvc_tutorials.machine_cache.Cut()
+
+/// A hull with no SMES excuses the battery step; one with a switched-off SMES says so.
+/datum/unit_test/voidcrew_tutorials/ship_power_smes/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ make_crewed_ship(deck, player)
+ SSvc_tutorials.build_catalog()
+ SSvc_tutorials.machine_cache.Cut()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/power/smes"]
+ TEST_ASSERT(step.excused(player), "The battery step was not excused on a hull with no SMES")
+ var/obj/machinery/power/smes/battery = allocate(/obj/machinery/power/smes, deck)
+ SSvc_tutorials.machine_cache.Cut()
+ TEST_ASSERT(!step.excused(player), "The battery step was excused with an SMES aboard")
+ battery.output_attempt = FALSE
+ TEST_ASSERT_EQUAL(step.live_line(player), "A battery's output is switched off.", "A switched-off SMES was not reported")
+ SSvc_tutorials.machine_cache.Cut()
+
+/// The Ship Management button is never outlined for someone without it, or once the step is done.
+/datum/unit_test/voidcrew_tutorials/ship_power_hud/Run()
+ var/mob/living/carbon/human/player = make_player()
+ SSvc_tutorials.build_catalog()
+ TEST_ASSERT(!length(tutorial_ship_manage_buttons(player)), "A player with no Ship Management button got an outline")
+ tutorial_credit(player, "vc/ship/manage")
+ TEST_ASSERT(!length(tutorial_ship_manage_buttons(player)), "A done Ship Management step still outlined the button")
+
+// ---------------------------------------------------------------------------
+// contract-trade
+// ---------------------------------------------------------------------------
+
+/// Riding a trader outpost's elevator credits the ride and the arrival (crew who joined after
+/// the dock); riding one anywhere else credits only the ride.
+/datum/unit_test/voidcrew_tutorials/trade_elevator_travel/Run()
+ var/turf/berth_spot = run_loc_floor_bottom_left
+ var/turf/concourse_spot = get_step(run_loc_floor_bottom_left, EAST)
+ var/mob/living/carbon/human/player = make_player(berth_spot)
+ var/obj/structure/overmap/trader_outpost/outpost = allocate(/obj/structure/overmap/trader_outpost, get_step(run_loc_floor_top_right, WEST))
+ var/datum/outpost_berth/berth = allocate(/datum/outpost_berth, outpost, 1, null)
+ berth.alcove_turfs = list(berth_spot)
+ outpost.lobby_alcove_turfs = list(concourse_spot)
+ var/obj/machinery/outpost_elevator/panel = allocate(/obj/machinery/outpost_elevator, get_step(berth_spot, NORTH))
+ panel.outpost = outpost
+ panel.berth = berth
+ panel.complete_ride(0, WEAKREF(player))
+ TEST_ASSERT_EQUAL(get_turf(player), concourse_spot, "The elevator did not move the rider")
+ TEST_ASSERT(done("vc/trade/elevator"), "Riding the elevator was not credited")
+ TEST_ASSERT(done("vc/trade/travel"), "Riding a trader outpost's elevator did not credit reaching it")
+ panel.berth = null
+ panel.outpost = null
+ outpost.lobby_alcove_turfs = list()
+
+ reset_progress()
+ player.forceMove(berth_spot)
+ var/obj/structure/overmap/ship/host = allocate(/obj/structure/overmap/ship, get_step(run_loc_floor_top_right, SOUTH))
+ var/datum/outpost_berth/host_berth = allocate(/datum/outpost_berth, host, 1, null)
+ host_berth.alcove_turfs = list(berth_spot)
+ host.lobby_alcove_turfs = list(concourse_spot)
+ panel.outpost = host
+ panel.berth = host_berth
+ panel.complete_ride(0, WEAKREF(player))
+ TEST_ASSERT(done("vc/trade/elevator"), "Riding another host's elevator was not credited as a ride")
+ TEST_ASSERT(!done("vc/trade/travel"), "Riding an elevator away from a trader outpost counted as reaching one")
+ panel.berth = null
+ panel.outpost = null
+ host.lobby_alcove_turfs = list()
+
+/// Turn In only reads a board's linked pad, so an unlinked pad is never outlined.
+/datum/unit_test/voidcrew_tutorials/contract_pad_filter/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/machinery/mission_pad/linked = allocate(/obj/machinery/mission_pad, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/machinery/computer/mission_board/board = allocate(/obj/machinery/computer/mission_board, get_step(run_loc_floor_bottom_left, NORTH))
+ var/obj/machinery/mission_pad/spare = allocate(/obj/machinery/mission_pad, get_step(get_step(run_loc_floor_bottom_left, EAST), EAST))
+ TEST_ASSERT_EQUAL(board.linked_pad, linked, "The board did not link the nearby pad")
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/contract/turn_in"]
+ TEST_ASSERT(step, "The turn-in step is missing")
+ TEST_ASSERT(step.highlight_filter(player, linked), "The linked pad was filtered out")
+ TEST_ASSERT(!step.highlight_filter(player, spare), "An unlinked pad was kept")
+ TEST_ASSERT(step.highlight_filter(player, board), "The board was filtered out")
+
+/// Guards and shopless traders are never pointed at for buying, selling or contracts.
+/datum/unit_test/voidcrew_tutorials/trader_filters/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/mob/living/basic/outpost_trader/checkpoint_guard/guard = allocate(/mob/living/basic/outpost_trader/checkpoint_guard, get_step(run_loc_floor_bottom_left, EAST))
+ var/mob/living/basic/outpost_trader/stall = allocate(/mob/living/basic/outpost_trader, get_step(run_loc_floor_bottom_left, NORTH))
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial_step/buy = SSvc_tutorials.steps_by_key["vc/trade/buy"]
+ var/datum/vc_tutorial_step/take = SSvc_tutorials.steps_by_key["vc/contract/take"]
+ TEST_ASSERT(buy && take, "A trade or contract step is missing")
+ TEST_ASSERT(!buy.highlight_filter(player, guard), "A checkpoint guard was kept as a shop")
+ TEST_ASSERT(!buy.highlight_filter(player, stall), "A trader with no shop was kept")
+ TEST_ASSERT(!take.highlight_filter(player, stall), "A trader with no outpost was kept for contracts")
+
+/// The ship balance line reads like a price tag.
+/datum/unit_test/voidcrew_tutorials/credits_text/Run()
+ TEST_ASSERT_EQUAL(tutorial_credits_text(0), "0", "Zero was formatted wrong")
+ TEST_ASSERT_EQUAL(tutorial_credits_text(999), "999", "Three digits were formatted wrong")
+ TEST_ASSERT_EQUAL(tutorial_credits_text(1000), "1,000", "Four digits were formatted wrong")
+ TEST_ASSERT_EQUAL(tutorial_credits_text(1234567), "1,234,567", "Seven digits were formatted wrong")
+ TEST_ASSERT_EQUAL(tutorial_credits_text(-1500), "-1,500", "A debt was formatted wrong")
+
+// ---------------------------------------------------------------------------
+// research-surveys: R&D setup and Surveys step filters and live lines
+// ---------------------------------------------------------------------------
+
+/// Flatpack steps outline only their own machine's pack; the link step only unlinked machines;
+/// the frame line names the next part and a missing tool.
+/datum/unit_test/voidcrew_tutorials/research_surveys_steps/Run()
+ var/turf/deck = run_loc_floor_bottom_left
+ var/mob/living/carbon/human/player = make_player(deck)
+ var/datum/vc_tutorial_step/server_step = SSvc_tutorials.steps_by_key["vc/research/server"]
+ var/datum/vc_tutorial_step/lathe_step = SSvc_tutorials.steps_by_key["vc/research/protolathe"]
+ var/datum/vc_tutorial_step/console_step = SSvc_tutorials.steps_by_key["vc/research/console"]
+
+ var/obj/item/flatpack/server_pack = allocate(/obj/item/flatpack, deck, new /obj/item/circuitboard/machine/rdserver/ship())
+ var/obj/item/flatpack/lathe_pack = allocate(/obj/item/flatpack, deck, new /obj/item/circuitboard/machine/protolathe())
+ var/obj/item/flatpack/imprinter_pack = allocate(/obj/item/flatpack, deck, new /obj/item/circuitboard/machine/circuit_imprinter())
+ TEST_ASSERT(server_step.highlight_filter(player, server_pack), "The server step dropped the server flatpack")
+ TEST_ASSERT(!server_step.highlight_filter(player, lathe_pack), "The server step kept the protolathe flatpack")
+ TEST_ASSERT(lathe_step.highlight_filter(player, lathe_pack), "The protolathe step dropped the protolathe flatpack")
+ TEST_ASSERT(lathe_step.highlight_filter(player, imprinter_pack), "The protolathe step dropped the imprinter flatpack")
+ TEST_ASSERT(!lathe_step.highlight_filter(player, server_pack), "The protolathe step kept the server flatpack")
+
+ TEST_ASSERT_EQUAL(tutorial_tool_line(player, TOOL_MULTITOOL), "No multitool on you.", "A player without a multitool got no line")
+ var/obj/item/multitool/tool = allocate(/obj/item/multitool, deck)
+ player.put_in_hands(tool)
+ TEST_ASSERT_NULL(tutorial_tool_line(player, TOOL_MULTITOOL), "A player holding a multitool was told they had none")
+
+ var/obj/structure/frame/computer/frame = allocate(/obj/structure/frame/computer, get_step(deck, EAST))
+ TEST_ASSERT(console_step.highlight_filter(player, frame), "The console step dropped an empty computer frame")
+ TEST_ASSERT(!console_step.highlight_filter(player, tool), "The console step kept something that isn't a frame")
+ frame.set_anchored(FALSE)
+ TEST_ASSERT_EQUAL(tutorial_frame_line(player, frame), "The frame needs a wrench. You have none.", "Wrong line for a loose frame")
+ frame.set_anchored(TRUE)
+ TEST_ASSERT_EQUAL(tutorial_frame_line(player, frame), "The frame needs its board.", "Wrong line for an empty frame")
+ frame.state = FRAME_COMPUTER_STATE_GLASSED
+ TEST_ASSERT_EQUAL(tutorial_frame_line(player, frame), "The frame needs a screwdriver. You have none.", "Wrong line for a glassed frame")
+ var/obj/item/screwdriver/driver = allocate(/obj/item/screwdriver, deck)
+ player.put_in_hands(driver)
+ TEST_ASSERT_EQUAL(tutorial_frame_line(player, frame), "The frame needs a screwdriver.", "A player holding a screwdriver was told they had none")
+ frame.state = FRAME_COMPUTER_STATE_EMPTY
+
+ var/datum/techweb/web = allocate(/datum/techweb)
+ var/obj/machinery/rnd/production/protolathe/lathe = allocate(/obj/machinery/rnd/production/protolathe, get_step(deck, NORTH))
+ TEST_ASSERT(!tutorial_rnd_device_linked(lathe, web), "An unlinked protolathe counted as linked")
+ lathe.stored_research = web
+ TEST_ASSERT(tutorial_rnd_device_linked(lathe, web), "A linked protolathe counted as unlinked")
+ TEST_ASSERT(!tutorial_rnd_device_linked(lathe, null), "A protolathe counted as linked to no web")
+ lathe.stored_research = null
+
+ var/datum/techweb_node/node = SSresearch.techweb_node_by_id("survey_console")
+ TEST_ASSERT_NOTNULL(node, "No survey console node")
+ web.researched_nodes -= "survey_console"
+ web.research_points[TECHWEB_POINT_TYPE_GENERIC] = 12
+ var/cost = node.get_price(web)[TECHWEB_POINT_TYPE_GENERIC]
+ TEST_ASSERT_EQUAL(tutorial_node_points_line(web, "survey_console"), "Research points: 12 of [cost].", "Wrong research points line")
+ web.researched_nodes["survey_console"] = TRUE
+ TEST_ASSERT_NULL(tutorial_node_points_line(web, "survey_console"), "A researched node still showed a points line")
+
+// ---------------------------------------------------------------------------
+// ruin-vestige: Planet ruin and Vestige pact credits and live lines
+// ---------------------------------------------------------------------------
+
+/// A found cache also counts as finding the ruin; a bought black-market cache counts for neither.
+/datum/unit_test/voidcrew_tutorials/ruin_cache_sources/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/turf/beside = get_step(run_loc_floor_bottom_left, EAST)
+ var/obj/structure/closet/crate/zone_loot/syndicate/trader/bought = allocate(/obj/structure/closet/crate/zone_loot/syndicate/trader, beside)
+ TEST_ASSERT(bought.open(player), "The bought cache would not open")
+ TEST_ASSERT(!done("vc/ruin/cache"), "Opening a bought cache was credited")
+ TEST_ASSERT(!done("vc/ruin/find"), "Opening a bought cache counted as finding a ruin")
+ qdel(bought)
+ var/obj/structure/closet/crate/zone_loot/cache = allocate(/obj/structure/closet/crate/zone_loot, beside)
+ TEST_ASSERT(cache in GLOB.tutorial_ruin_caches, "A cache was not registered for the pointers")
+ TEST_ASSERT(cache in tutorial_nearby_ruin_caches(player), "A closed cache nearby was not offered to the arrow")
+ TEST_ASSERT(cache.open(player), "The cache would not open")
+ TEST_ASSERT(done("vc/ruin/cache"), "Opening a found cache was not credited")
+ TEST_ASSERT(done("vc/ruin/find"), "Opening a found cache did not count as finding its ruin")
+ TEST_ASSERT(!(cache in tutorial_nearby_ruin_caches(player)), "An opened cache was still offered to the arrow")
+
+/// Open-air ruins have no ruin area: standing in a ruin's footprint counts as finding it.
+/datum/unit_test/voidcrew_tutorials/ruin_footprint/Run()
+ var/turf/center = locate(run_loc_floor_bottom_left.x + 2, run_loc_floor_bottom_left.y + 2, run_loc_floor_bottom_left.z)
+ var/datum/map_template/template = allocate(/datum/map_template)
+ // Half of 1, rounded up: the footprint reaches one tile out from the landmark.
+ template.width = 1
+ template.height = 1
+ var/obj/effect/landmark/ruin/mark = allocate(/obj/effect/landmark/ruin, center)
+ mark.ruin_template = template
+ var/mob/living/carbon/human/player = make_player(center)
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial_step/find = SSvc_tutorials.steps_by_key["vc/ruin/find"]
+ TEST_ASSERT(tutorial_in_ruin_footprint(get_step(center, NORTHEAST), mark), "A tile inside the footprint was not counted")
+ TEST_ASSERT(!tutorial_in_ruin_footprint(locate(center.x + 3, center.y, center.z), mark), "A tile outside the footprint was counted")
+ TEST_ASSERT(find.state_satisfied(player), "Standing in a ruin footprint did not satisfy Find a ruin")
+ TEST_ASSERT_EQUAL(tutorial_nearest_ruin_landmark(player), mark, "The nearest ruin landmark was not found")
+ TEST_ASSERT_NULL(find.live_line(player), "Find a ruin pointed elsewhere while standing in a ruin")
+ player.forceMove(run_loc_floor_bottom_left)
+ TEST_ASSERT(!find.state_satisfied(player), "Standing outside a ruin footprint satisfied Find a ruin")
+ TEST_ASSERT(find.live_line(player), "Find a ruin had no live line near a ruin")
+ mark.ruin_template = null
+
+/// The vestige steps read the player's pact as state.
+/datum/unit_test/voidcrew_tutorials/vestige_live_lines/Run()
+ var/mob/living/carbon/human/player = make_player()
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial_step/pact = SSvc_tutorials.steps_by_key["vc/vestige/pact"]
+ var/datum/vc_tutorial_step/trial_step = SSvc_tutorials.steps_by_key["vc/vestige/trial"]
+ TEST_ASSERT_NULL(pact.live_line(player), "A free player was told they were busy")
+ TEST_ASSERT_NULL(trial_step.live_line(player), "A trial line showed with no pact")
+ var/datum/vestige_trial/trial = allocate(/datum/vestige_trial, player.mind, "Test patron", list())
+ player.mind.active_vestige_trial = trial
+ TEST_ASSERT(findtext(pact.live_line(player), "Test patron"), "The busy line did not name the patron")
+ TEST_ASSERT(findtext(trial_step.live_line(player), trial.get_progress_text()), "The trial line did not show progress")
+ player.mind.active_vestige_trial = null
+
+// ---- chrome-surgery ----
+
+/// Cased chrome sets credit Buy chrome; the empty autosurgeon, which can't fit chrome, doesn't.
+/datum/unit_test/voidcrew_tutorials/chrome_buy_paths/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/shop_sku/sku = allocate(/datum/shop_sku)
+ sku.item_path = /obj/item/autosurgeon
+ tutorial_credit_purchase(player, sku)
+ TEST_ASSERT(done("vc/trade/buy"), "A purchase was not credited")
+ TEST_ASSERT(!done("vc/chrome/buy"), "An empty autosurgeon counted as chrome")
+ sku.item_path = /obj/item/cyberware_pair_case/gorilla_arms/street
+ tutorial_credit_purchase(player, sku)
+ TEST_ASSERT(done("vc/chrome/buy"), "A cased chrome pair was not credited")
+ TEST_ASSERT(tutorial_is_chrome_path(/obj/item/storage/case/cyberware/scrapper), "The scrapper case is not chrome")
+ TEST_ASSERT(tutorial_is_chrome_path(/obj/item/organ/eyes/robotic/cyberware/lookout), "Cyberware eyes are not chrome")
+
+/// Carried chrome names where it goes; fitted chrome satisfies Install and excuses Buy.
+/datum/unit_test/voidcrew_tutorials/chrome_install_state/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/chrome_install/install = allocate(/datum/vc_tutorial_step/chrome_install)
+ var/datum/vc_tutorial_step/chrome_buy/buy = allocate(/datum/vc_tutorial_step/chrome_buy)
+ TEST_ASSERT_NULL(install.live_line(player), "An empty-handed player got a chrome line")
+ TEST_ASSERT(!install.state_satisfied(player), "A body with no chrome satisfied Install")
+ var/obj/item/organ/cyberimp/cyberware/second_wind/ware = allocate(/obj/item/organ/cyberimp/cyberware/second_wind)
+ player.put_in_hands(ware)
+ var/line = install.live_line(player)
+ TEST_ASSERT(line && findtext(line, "chest"), "The carried chrome line did not name the chest: [line]")
+ ware.Insert(player, TRUE)
+ TEST_ASSERT(ware.owner == player, "The special insert failed")
+ TEST_ASSERT(install.state_satisfied(player), "Fitted chrome did not satisfy Install")
+ TEST_ASSERT(!buy.excused(player), "Buy was excused before Install was done")
+ SSvc_tutorials.progress[TUTORIAL_TEST_CKEY] = list("vc/chrome/install" = TRUE)
+ TEST_ASSERT(buy.excused(player), "Buy was not excused once chrome was fitted")
+
+/// The execution line reads the fitted chrome: none, then Shiv Blades, which can't finish anyone.
+/datum/unit_test/voidcrew_tutorials/chrome_execute_line/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/chrome_execute/execute = allocate(/datum/vc_tutorial_step/chrome_execute)
+ TEST_ASSERT_EQUAL(execute.live_line(player), "Nothing fitted can finish someone yet.", "Wrong line with no chrome")
+ var/obj/item/organ/right = allocate(/obj/item/organ/cyberimp/arm/toolkit/cyberware/mantis/street)
+ var/obj/item/organ/left = allocate(/obj/item/organ/cyberimp/arm/toolkit/cyberware/mantis/street/left)
+ right.Insert(player, TRUE)
+ left.Insert(player, TRUE)
+ TEST_ASSERT_EQUAL(execute.live_line(player), "Shiv Blades can't finish anyone.", "Shiv Blades were not called out")
+ TEST_ASSERT(!length(execute.extra_targets(player)), "A player who can't finish anyone got finisher targets")
+
+/// Tend Wounds tools: all four missing on a bare body, none once carried.
+/datum/unit_test/voidcrew_tutorials/surgery_tools/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/surgery_start/start = allocate(/datum/vc_tutorial_step/surgery_start)
+ TEST_ASSERT_EQUAL(length(tutorial_surgery_missing(player, fresh = TRUE)), 4, "A bare body was not missing all four")
+ TEST_ASSERT(findtext(start.live_line(player), "Missing: "), "No missing-tools line")
+ for(var/tool_type in list(/obj/item/scalpel, /obj/item/hemostat, /obj/item/cautery, /obj/item/bedsheet))
+ var/obj/item/tool = allocate(tool_type)
+ tool.forceMove(player)
+ TEST_ASSERT(!length(tutorial_surgery_missing(player, fresh = TRUE)), "Carried tools were not seen")
+
+/// The finish line names the next step of an operation the player is working on.
+/datum/unit_test/voidcrew_tutorials/surgery_next_step/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/surgery_finish/finish = allocate(/datum/vc_tutorial_step/surgery_finish)
+ TEST_ASSERT_NULL(finish.live_line(player), "A line with no operation running")
+ player.zone_selected = BODY_ZONE_CHEST
+ var/datum/surgery/operation = new /datum/surgery/healing/brute/basic(player, BODY_ZONE_CHEST, player.get_bodypart(BODY_ZONE_CHEST))
+ var/line = finish.live_line(player)
+ TEST_ASSERT(line && findtext(line, "Next: ") == 1, "No next-step line: [line]")
+ qdel(operation)
+
+// ---------------------------------------------------------------------------
+// zones-weapons
+// ---------------------------------------------------------------------------
+
+/// Warfare research is the first Zones step, so the checklist agrees with the zone advisory.
+/datum/unit_test/voidcrew_tutorials/zw_zone_order/Run()
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial/zones = SSvc_tutorials.item_by_step["vc/zones/yellow"]
+ TEST_ASSERT(zones, "The Zones item is missing")
+ var/datum/vc_tutorial_step/first = zones.steps[1]
+ TEST_ASSERT_EQUAL(first.key, "vc/zones/warfare", "Zones does not start with warfare research")
+
+/// A missile bought armed can be unsealed and resealed without counting as arming one.
+/datum/unit_test/voidcrew_tutorials/zw_bought_missile/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/structure/ship_missile/missile = allocate(/obj/structure/ship_missile/armed, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/item/screwdriver/tool = allocate(/obj/item/screwdriver)
+ TEST_ASSERT(player.put_in_active_hand(tool), "The player could not hold the screwdriver")
+ missile.attackby(tool, player)
+ TEST_ASSERT_EQUAL(missile.construction_state, 3, "The screwdriver did not unseal the missile") // MISSILE_STATE_PAYLOAD
+ missile.attackby(tool, player)
+ TEST_ASSERT_EQUAL(missile.construction_state, 4, "The screwdriver did not reseal the missile") // MISSILE_STATE_ARMED
+ TEST_ASSERT(!done("vc/weapons/missile"), "Resealing a bought missile counted as arming one")
+
+/// The research line walks back to the first missing prerequisite and goes quiet once researched.
+/datum/unit_test/voidcrew_tutorials/zw_next_research/Run()
+ var/datum/techweb/web = allocate(/datum/techweb)
+ var/datum/techweb_node/next = tutorial_next_research_node(web, "ship_combat")
+ TEST_ASSERT(next, "A fresh web had nothing to research toward Shuttle Warfare Systems")
+ TEST_ASSERT_NOTEQUAL(next.id, "ship_combat", "Shuttle Warfare Systems was next before Basic Shuttle Research")
+ web.research_node(SSresearch.techweb_node_by_id("ship_combat"), TRUE, FALSE, FALSE)
+ next = tutorial_next_research_node(web, "ship_combat_missiles")
+ TEST_ASSERT_EQUAL(next?.id, "ship_combat_missiles", "Missile Ordnance was not next after Shuttle Warfare Systems")
+ web.research_node(SSresearch.techweb_node_by_id("ship_combat_missiles"), TRUE, FALSE, FALSE)
+ TEST_ASSERT_NULL(tutorial_next_research_node(web, "ship_combat_missiles"), "A researched node still had a next node")
+
+/// Launcher outlines: an empty frame only while the viewer carries the board, and no printer then.
+/datum/unit_test/voidcrew_tutorials/zw_build_filter/Run()
+ var/mob/living/carbon/human/player = make_player()
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial_step/weapon_build/step = SSvc_tutorials.steps_by_key["vc/weapons/launcher"]
+ TEST_ASSERT(istype(step), "The launcher step is not a weapon build step")
+ var/obj/structure/frame/machine/frame = allocate(/obj/structure/frame/machine, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/machinery/rnd/production/circuit_imprinter/printer = allocate(/obj/machinery/rnd/production/circuit_imprinter, get_step(run_loc_floor_bottom_left, NORTH))
+ TEST_ASSERT(!step.highlight_filter(player, frame), "An empty frame was outlined before the board was printed")
+ TEST_ASSERT(step.highlight_filter(player, printer), "The imprinter was not outlined before the board was printed")
+ TEST_ASSERT_EQUAL(tutorial_machine_frame_line(frame), "The frame needs 5 cables.", "The empty frame line is wrong")
+ var/obj/item/circuitboard/machine/ship_combat/missile_launcher/board = allocate(/obj/item/circuitboard/machine/ship_combat/missile_launcher)
+ TEST_ASSERT(player.put_in_active_hand(board), "The player could not hold the board")
+ TEST_ASSERT(step.highlight_filter(player, frame), "An empty frame was not outlined with the board in hand")
+ TEST_ASSERT(!step.highlight_filter(player, printer), "The imprinter was still outlined with the board in hand")
+
+// ---------------------------------------------------------------------------
+// combat-pirates: Ship combat and Hunting pirates content.
+// ---------------------------------------------------------------------------
+
+/// The weapons console walks a step's focus back to the lock, then to Engage.
+/datum/unit_test/voidcrew_tutorials/cp_weapons_focus/Run()
+ var/obj/machinery/computer/camera_advanced/ship_combat/console = allocate(/obj/machinery/computer/camera_advanced/ship_combat, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/structure/overmap/ship/target = allocate(/obj/structure/overmap/ship, get_step(run_loc_floor_top_right, WEST))
+ TEST_ASSERT_NULL(console.tutorial_weapons_focus(null), "No step focus still focused something")
+ console.target_ship = null
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_fire"), "wpn_contact", "Fire was focused with no lock")
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_interdict"), "wpn_contact", "Interdict was focused with no lock")
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_hack"), "wpn_contact", "Exploits were focused with no lock")
+ console.target_ship = target
+ console.attack_mode = FALSE
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_fire"), "wpn_engage", "Fire was focused outside attack mode")
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_interdict"), "wpn_interdict", "Interdict lost its focus with a lock")
+ console.attack_mode = TRUE
+ TEST_ASSERT_EQUAL(console.tutorial_weapons_focus("wpn_fire"), "wpn_fire", "Fire was not focused in attack mode")
+ console.attack_mode = FALSE
+ console.target_ship = null
+
+/// Missile outlines skip unarmed missiles and loaded launchers; hail outlines only ringing pads.
+/datum/unit_test/voidcrew_tutorials/cp_filters/Run()
+ SSvc_tutorials.build_catalog()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/missile_step = SSvc_tutorials.steps_by_key["vc/combat/missile"]
+ var/datum/vc_tutorial_step/hail_step = SSvc_tutorials.steps_by_key["vc/pirates/hail"]
+ var/datum/vc_tutorial_step/claim_step = SSvc_tutorials.steps_by_key["vc/pirates/claim"]
+ TEST_ASSERT(missile_step && hail_step && claim_step, "A combat or pirate step is missing from the catalog")
+
+ var/obj/structure/ship_missile/missile = allocate(/obj/structure/ship_missile, get_step(run_loc_floor_bottom_left, EAST))
+ missile.construction_state = 3 // MISSILE_STATE_PAYLOAD
+ TEST_ASSERT(!missile_step.highlight_filter(player, missile), "An unarmed missile was outlined")
+ missile.construction_state = 4 // MISSILE_STATE_ARMED
+ TEST_ASSERT(missile_step.highlight_filter(player, missile), "An armed missile was not outlined")
+ var/obj/machinery/ship_combat/missile_launcher/launcher = allocate(/obj/machinery/ship_combat/missile_launcher, get_step(run_loc_floor_bottom_left, NORTH))
+ launcher.loaded_missile = null
+ TEST_ASSERT(missile_step.highlight_filter(player, launcher), "An empty launcher was not outlined")
+ launcher.loaded_missile = list("name" = "test")
+ TEST_ASSERT(!missile_step.highlight_filter(player, launcher), "A loaded launcher was outlined")
+ launcher.loaded_missile = null
+
+ var/obj/machinery/holopad/pad = allocate(/obj/machinery/holopad, get_step(run_loc_floor_bottom_left, NORTHEAST))
+ pad.incoming_hail = FALSE
+ TEST_ASSERT(!hail_step.highlight_filter(player, pad), "A quiet holopad was outlined")
+ pad.incoming_hail = TRUE
+ TEST_ASSERT(hail_step.highlight_filter(player, pad), "A ringing holopad was not outlined")
+ pad.incoming_hail = FALSE
+
+ var/obj/machinery/computer/helm/helm = allocate(/obj/machinery/computer/helm, get_step(run_loc_floor_top_right, SOUTH))
+ TEST_ASSERT(!claim_step.highlight_filter(player, helm), "A helm on no pirate ship was outlined for claiming")
+
+/// Claiming an abandoned pirate hull at its helm counts as claiming it; a player hull doesn't.
+/datum/unit_test/voidcrew_tutorials/cp_abandoned_claim/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/obj/structure/overmap/ship/plain = allocate(/obj/structure/overmap/ship, get_step(run_loc_floor_top_right, WEST))
+ plain.abandoned = TRUE
+ TEST_ASSERT(plain.claim_abandoned_ship(player, TRUE), "The abandoned player hull could not be claimed")
+ crew_records |= plain.get_crew_record()
+ TEST_ASSERT(!done("vc/pirates/claim"), "Claiming a player hull counted as claiming a pirate")
+ var/obj/structure/overmap/ship/npc/tutorial_test/pirate = allocate(/obj/structure/overmap/ship/npc/tutorial_test, get_step(run_loc_floor_top_right, SOUTHWEST))
+ pirate.abandoned = TRUE
+ TEST_ASSERT(pirate.claim_abandoned_ship(player, TRUE), "The abandoned pirate hull could not be claimed")
+ crew_records |= pirate.get_crew_record()
+ TEST_ASSERT(done("vc/pirates/claim"), "Claiming an abandoned pirate hull was not credited")
+
+/// Missiles come first in Ship combat; the hail and bounty steps are optional.
+/datum/unit_test/voidcrew_tutorials/cp_catalog/Run()
+ SSvc_tutorials.build_catalog()
+ var/datum/vc_tutorial/combat = SSvc_tutorials.item_by_step["vc/combat/missile"]
+ TEST_ASSERT(combat, "Ship combat is missing")
+ var/datum/vc_tutorial_step/first = combat.steps[1]
+ TEST_ASSERT_EQUAL(first.key, "vc/combat/missile", "Ship combat does not start with the missile step")
+ for(var/key in list("vc/pirates/hail", "vc/pirates/bounty"))
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key[key]
+ TEST_ASSERT(step, "[key] is missing")
+ TEST_ASSERT(step.optional, "[key] counts toward Hunting pirates")
+ TEST_ASSERT(!step.route, "[key] belongs to a route")
+
+// ---------------------------------------------------------------------------
+// storage-drones-saves: Storage, Repair drones and Save your ship panel lines and outlines.
+// ---------------------------------------------------------------------------
+
+/// The repair swarm research line names the next node on the way, then reputation.
+/datum/unit_test/voidcrew_tutorials/sds_research_line/Run()
+ var/datum/techweb/web = allocate(/datum/techweb)
+ web.researched_nodes = list()
+ // TECHWEB_NODE_SHIP_AUTOMATION and TECHWEB_NODE_SHIP_REPAIR_SWARM
+ var/datum/techweb_node/automation = SSresearch.techweb_node_by_id("ship_automation")
+ var/datum/techweb_node/swarm = SSresearch.techweb_node_by_id("ship_repair_swarm")
+ TEST_ASSERT(automation && swarm, "The repair swarm nodes are missing")
+ for(var/prereq_id in swarm.prereq_ids)
+ if(prereq_id != automation.id)
+ mark_researched(web, prereq_id)
+ for(var/prereq_id in automation.prereq_ids)
+ mark_researched(web, prereq_id)
+ TEST_ASSERT_EQUAL(tutorial_repair_research_line(web, swarm.id), "Research [automation.display_name] first.", "The missing prerequisite was not named")
+ web.researched_nodes[automation.id] = TRUE
+ // A web with no ship server has public standing only; the swarm needs yellow.
+ TEST_ASSERT_EQUAL(tutorial_repair_research_line(web, swarm.id), "Needs more crew reputation.", "The reputation gate was not named")
+ web.researched_nodes[swarm.id] = TRUE
+ TEST_ASSERT_NULL(tutorial_repair_research_line(web, swarm.id), "A researched node still had a line")
+
+/// Marks a node and everything before it researched, for the line helpers only.
+/datum/unit_test/voidcrew_tutorials/sds_research_line/proc/mark_researched(datum/techweb/web, node_id)
+ if(web.researched_nodes[node_id])
+ return
+ web.researched_nodes[node_id] = TRUE
+ var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id)
+ for(var/prereq_id in node?.prereq_ids)
+ mark_researched(web, prereq_id)
+
+/// The Watch it repair line follows the console: disk, drones, paused swarm, monitoring, backlog.
+/datum/unit_test/voidcrew_tutorials/sds_swarm_line/Run()
+ var/obj/machinery/computer/camera_advanced/base_construction/ship/console = allocate(/obj/machinery/computer/camera_advanced/base_construction/ship)
+ console.console_upgrades = NONE
+ TEST_ASSERT_EQUAL(tutorial_repair_swarm_line(console), "No repair disk in the construction console.", "A console with no disk was not reported")
+ // SHIP_CONSTRUCTION_UPGRADE_REPAIR
+ console.console_upgrades = (1<<10)
+ TEST_ASSERT_EQUAL(tutorial_repair_swarm_line(console), "No drones linked.", "A console with no drones was not reported")
+ var/obj/structure/ship_repair_drone/drone = allocate(/obj/structure/ship_repair_drone, run_loc_floor_bottom_left)
+ console.repair_drones += drone
+ console.repair_enabled = FALSE
+ TEST_ASSERT_EQUAL(tutorial_repair_swarm_line(console), "Swarm paused.", "A paused swarm was not reported")
+ console.repair_enabled = TRUE
+ console.repair_tracking = FALSE
+ TEST_ASSERT_EQUAL(tutorial_repair_swarm_line(console), "Damage monitoring is off.", "Monitoring being off was not reported")
+ console.repair_tracking = TRUE
+ TEST_ASSERT_EQUAL(tutorial_repair_swarm_line(console), "Swarm out. No hull damage logged.", "An idle deployed swarm was not reported")
+ console.repair_drones -= drone
+ console.repair_enabled = FALSE
+ console.repair_tracking = FALSE
+
+/// Shelve a crate outlines loose crates and shelves with room, nothing else.
+/datum/unit_test/voidcrew_tutorials/sds_crate_filter/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/storage/crate"]
+ TEST_ASSERT(step, "The Shelve a crate step is missing")
+ var/obj/structure/cargo_shelf/shelf = allocate(/obj/structure/cargo_shelf, get_step(run_loc_floor_bottom_left, EAST))
+ var/obj/structure/closet/crate/crate = allocate(/obj/structure/closet/crate, get_step(run_loc_floor_bottom_left, NORTH))
+ TEST_ASSERT(step.highlight_filter(player, shelf), "An empty shelf was not outlined")
+ TEST_ASSERT(step.highlight_filter(player, crate), "A loose crate was not outlined")
+ crate.set_anchored(TRUE)
+ TEST_ASSERT(!step.highlight_filter(player, crate), "A bolted crate was outlined")
+ crate.set_anchored(FALSE)
+ for(var/level in 1 to length(shelf.shelf_contents))
+ TEST_ASSERT(shelf.insert_crate(allocate(/obj/structure/closet/crate, run_loc_floor_bottom_left)), "The shelf refused a crate")
+ TEST_ASSERT(!step.highlight_filter(player, shelf), "A full shelf was outlined")
+
+/// The shelf step outlines iron only in stacks big enough for the parts.
+/datum/unit_test/voidcrew_tutorials/sds_shelf_filter/Run()
+ var/mob/living/carbon/human/player = make_player()
+ var/datum/vc_tutorial_step/step = SSvc_tutorials.steps_by_key["vc/storage/shelf"]
+ TEST_ASSERT(step, "The Build a cargo shelf step is missing")
+ var/obj/item/stack/sheet/iron/few = allocate(/obj/item/stack/sheet/iron, run_loc_floor_bottom_left, 3)
+ var/obj/item/stack/sheet/iron/enough = allocate(/obj/item/stack/sheet/iron, get_step(run_loc_floor_bottom_left, EAST), 4)
+ TEST_ASSERT(!step.highlight_filter(player, few), "Three sheets were outlined")
+ TEST_ASSERT(step.highlight_filter(player, enough), "Four sheets were not outlined")
+
+// ---------------------------------------------------------------------------
+// integration: every step's window focus names a window that sends tutorial_focus, and
+// node/design keys name real techweb nodes and designs.
+// ---------------------------------------------------------------------------
+
+/datum/unit_test/voidcrew_tutorials/ui_focus_keys/Run()
+ // Windows whose ui_data sends tutorial_focus (tutorial_ui_focus(user, "")).
+ var/list/windows = list("helm", "board", "trader", "elevator", "rdconsole", "imprinter", "survey", "autolathe", "cradle", "surgery", "weapons", "construction")
+ SSvc_tutorials.build_catalog()
+ for(var/datum/vc_tutorial/item as anything in SSvc_tutorials.items)
+ for(var/datum/vc_tutorial_step/step as anything in item.steps)
+ for(var/window in step.ui_focus)
+ var/focus_key = step.ui_focus[window]
+ TEST_ASSERT(window in windows, "[step.key] focuses unknown window [window]")
+ TEST_ASSERT(istext(focus_key) && length(focus_key), "[step.key] has an empty focus key for [window]")
+ if(window == "rdconsole")
+ TEST_ASSERT(findtext(focus_key, "rd_node_") == 1, "[step.key] sends [focus_key] to the R&D console")
+ TEST_ASSERT(SSresearch.techweb_nodes[copytext(focus_key, 9)], "[step.key] points at missing node [focus_key]")
+ if(window == "imprinter" || window == "autolathe")
+ TEST_ASSERT(findtext(focus_key, "[window]_") == 1, "[step.key] sends [focus_key] to the [window]")
+ TEST_ASSERT(SSresearch.techweb_designs[copytext(focus_key, length(window) + 2)], "[step.key] points at missing design [focus_key]")
+
+/// The off-screen arrow snaps to eight facings: straight sprite for cardinals, the 45 degree one for diagonals.
+/datum/unit_test/voidcrew_tutorials/arrow_facing/Run()
+ var/atom/movable/screen/tutorial_arrow/arrow = allocate(/atom/movable/screen/tutorial_arrow)
+ var/list/view_size = list(21, 15)
+ arrow.point(4, 4, view_size)
+ TEST_ASSERT_EQUAL(arrow.icon_state, "arrow_diagonal", "A north-east target did not use the diagonal arrow")
+ arrow.point(10, 1, view_size)
+ TEST_ASSERT_EQUAL(arrow.icon_state, "arrow", "A nearly east target did not snap to the straight arrow")
+ arrow.point(-3, -4, view_size)
+ TEST_ASSERT_EQUAL(arrow.icon_state, "arrow_diagonal", "A south-west target did not use the diagonal arrow")
+
+#undef TUTORIAL_TEST_CKEY
diff --git a/voidcrew/sound/cyberware/mantis_draw.ogg b/voidcrew/sound/cyberware/mantis_draw.ogg
new file mode 100644
index 00000000000..e70b2857be5
Binary files /dev/null and b/voidcrew/sound/cyberware/mantis_draw.ogg differ
diff --git a/voidcrew/sound/cyberware/mantis_sheathe.ogg b/voidcrew/sound/cyberware/mantis_sheathe.ogg
new file mode 100644
index 00000000000..59078cff7d9
Binary files /dev/null and b/voidcrew/sound/cyberware/mantis_sheathe.ogg differ
diff --git a/voidcrew/sound/cyberware/mantis_slash_1.ogg b/voidcrew/sound/cyberware/mantis_slash_1.ogg
new file mode 100644
index 00000000000..a3f2cec3904
Binary files /dev/null and b/voidcrew/sound/cyberware/mantis_slash_1.ogg differ
diff --git a/voidcrew/sound/cyberware/mantis_slash_2.ogg b/voidcrew/sound/cyberware/mantis_slash_2.ogg
new file mode 100644
index 00000000000..d18aa2d63e5
Binary files /dev/null and b/voidcrew/sound/cyberware/mantis_slash_2.ogg differ
diff --git a/voidcrew/sound/cyberware/mantis_slash_3.ogg b/voidcrew/sound/cyberware/mantis_slash_3.ogg
new file mode 100644
index 00000000000..e29bc7af664
Binary files /dev/null and b/voidcrew/sound/cyberware/mantis_slash_3.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_activation.ogg b/voidcrew/sound/cyberware/sandevistan_activation.ogg
new file mode 100644
index 00000000000..a8889dd633d
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_activation.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_deactivate.ogg b/voidcrew/sound/cyberware/sandevistan_deactivate.ogg
new file mode 100644
index 00000000000..bb443e3f050
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_deactivate.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_external_1.ogg b/voidcrew/sound/cyberware/sandevistan_external_1.ogg
new file mode 100644
index 00000000000..015b249ee38
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_external_1.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_external_2.ogg b/voidcrew/sound/cyberware/sandevistan_external_2.ogg
new file mode 100644
index 00000000000..0ae02bb8254
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_external_2.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_external_3.ogg b/voidcrew/sound/cyberware/sandevistan_external_3.ogg
new file mode 100644
index 00000000000..0903b746f3c
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_external_3.ogg differ
diff --git a/voidcrew/sound/cyberware/sandevistan_loop.ogg b/voidcrew/sound/cyberware/sandevistan_loop.ogg
new file mode 100644
index 00000000000..36a515b8582
Binary files /dev/null and b/voidcrew/sound/cyberware/sandevistan_loop.ogg differ