diff --git a/tgstation.dme b/tgstation.dme index 34c6bdf341f..2c90f4bcefe 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -6750,6 +6750,8 @@ #include "voidcrew\_DEFINES\subsystems.dm" #include "voidcrew\_DEFINES\techweb_nodes.dm" #include "voidcrew\_DEFINES\trade.dm" +#include "voidcrew\_DEFINES\tutorials.dm" +#include "voidcrew\_DEFINES\xenoarch.dm" #include "voidcrew\_HELPERS\data_huds.dm" #include "voidcrew\_HELPERS\debug_atmos.dm" #include "voidcrew\_HELPERS\docking.dm" @@ -7571,7 +7573,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" @@ -7897,6 +7898,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" @@ -7919,6 +7941,76 @@ #include "voidcrew\modules\voice_barks\voice_screen.dm" #include "voidcrew\modules\weapons_bench\ammunition.dm" #include "voidcrew\modules\worldgen_logging\worldgen.dm" +#include "voidcrew\modules\xenoarch\core\artifact.dm" +#include "voidcrew\modules\xenoarch\core\artifact_appearance.dm" +#include "voidcrew\modules\xenoarch\core\artifact_effect.dm" +#include "voidcrew\modules\xenoarch\core\artifact_energy_kinds.dm" +#include "voidcrew\modules\xenoarch\core\artifact_helpers.dm" +#include "voidcrew\modules\xenoarch\core\artifact_label.dm" +#include "voidcrew\modules\xenoarch\core\artifact_pricing.dm" +#include "voidcrew\modules\xenoarch\dig\ambush.dm" +#include "voidcrew\modules\xenoarch\dig\boulder.dm" +#include "voidcrew\modules\xenoarch\dig\curios.dm" +#include "voidcrew\modules\xenoarch\dig\designs.dm" +#include "voidcrew\modules\xenoarch\dig\dig_reserve.dm" +#include "voidcrew\modules\xenoarch\dig\dig_sites.dm" +#include "voidcrew\modules\xenoarch\dig\finds.dm" +#include "voidcrew\modules\xenoarch\dig\site_walls.dm" +#include "voidcrew\modules\xenoarch\dig\spectrometer.dm" +#include "voidcrew\modules\xenoarch\dig\stabiliser.dm" +#include "voidcrew\modules\xenoarch\dig\strange_rock.dm" +#include "voidcrew\modules\xenoarch\dig\tools.dm" +#include "voidcrew\modules\xenoarch\effects\blood.dm" +#include "voidcrew\modules\xenoarch\effects\bodyhorror.dm" +#include "voidcrew\modules\xenoarch\effects\cell.dm" +#include "voidcrew\modules\xenoarch\effects\disgust.dm" +#include "voidcrew\modules\xenoarch\effects\emp.dm" +#include "voidcrew\modules\xenoarch\effects\feelings.dm" +#include "voidcrew\modules\xenoarch\effects\gas.dm" +#include "voidcrew\modules\xenoarch\effects\gravity.dm" +#include "voidcrew\modules\xenoarch\effects\hallucination.dm" +#include "voidcrew\modules\xenoarch\effects\health.dm" +#include "voidcrew\modules\xenoarch\effects\light.dm" +#include "voidcrew\modules\xenoarch\effects\noise.dm" +#include "voidcrew\modules\xenoarch\effects\radiation.dm" +#include "voidcrew\modules\xenoarch\effects\sleepy.dm" +#include "voidcrew\modules\xenoarch\effects\stun.dm" +#include "voidcrew\modules\xenoarch\effects\teleport.dm" +#include "voidcrew\modules\xenoarch\effects\temperature.dm" +#include "voidcrew\modules\xenoarch\effects\tesla.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\animate.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\berserk.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\disarm.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\electric_field.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\extinguisher.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\faraday.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\feysight.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\forcefield.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\fortify.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\gaia.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\gravity_wave.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\life_drain.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\life_steal.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\plasma_vent.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\poltergeist.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\resurrect.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\sleeping_gas.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\spines.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\sprint.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\status_effects.dm" +#include "voidcrew\modules\xenoarch\effects_polaris\sweat.dm" +#include "voidcrew\modules\xenoarch\study\analyser.dm" +#include "voidcrew\modules\xenoarch\study\labeler.dm" +#include "voidcrew\modules\xenoarch\study\research.dm" +#include "voidcrew\modules\xenoarch\study\scanpad.dm" +#include "voidcrew\modules\xenoarch\study\techweb.dm" +#include "voidcrew\modules\xenoarch\trade\buyers.dm" +#include "voidcrew\modules\xenoarch\trade\checkpoint.dm" +#include "voidcrew\modules\xenoarch\trade\metrics.dm" +#include "voidcrew\modules\xenoarch\trade\specimen_crate.dm" +#include "voidcrew\modules\xenoarch\use\battery.dm" +#include "voidcrew\modules\xenoarch\use\harvester.dm" +#include "voidcrew\modules\xenoarch\use\utilizer.dm" #include "voidcrew\objects\items\blueprints.dm" #include "voidcrew\objects\items\cards_ids.dm" #include "voidcrew\objects\items\trash.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..f8c6d121177 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 + return ( + {tab} + ); }; type CategoryViewProps = { diff --git a/tgui/packages/tgui/interfaces/Fabricator.tsx b/tgui/packages/tgui/interfaces/Fabricator.tsx index 5f611e61fe0..3cf05e2eced 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: the tutorial checklist outlines the design it points at. + return ( + {recipe} + ); }; 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) => ( - + + ))} + {/* 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`: + * + * + * + * 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/AnomalyUtilizer.tsx b/tgui/packages/voidcrew_tgui/interfaces/AnomalyUtilizer.tsx new file mode 100644 index 00000000000..628f049a942 --- /dev/null +++ b/tgui/packages/voidcrew_tgui/interfaces/AnomalyUtilizer.tsx @@ -0,0 +1,112 @@ +/** + * Exotic utilizer: one power button ringed by the battery's charge, glowing in the colour of the + * energy it holds. DM side: voidcrew/modules/xenoarch/use/utilizer.dm. + */ +import { Box, Button, Stack } from 'tgui-core/components'; + +import { useBackend } from '../../tgui/backend'; +import { Window } from '../../tgui/layouts'; + +type Cell = { + fill: number; + color: string | null; + serial: string | null; + mode: string | null; +}; + +type Data = { + emitting: number; + cell: Cell | null; +}; + +const RING_R = 52; +const RING_C = 2 * Math.PI * RING_R; + +export const AnomalyUtilizer = (props) => { + const { act, data } = useBackend(); + const { emitting, cell } = data; + const on = !!emitting; + const color = cell?.color || '#4b5563'; + const fill = cell ? Math.max(0, Math.min(1, cell.fill)) : 0; + return ( + + + + + + + {on ? ( + + ) : null} + + act('power')} + /> + + {on ? 'EMIT' : 'OFF'} + + + + + + {cell?.serial ? cell.serial.toUpperCase() : 'NO CELL'} + {cell?.mode ? ` · ${cell.mode.toUpperCase()}` : ''} + + + + + + + + ); +}; diff --git a/tgui/packages/voidcrew_tgui/interfaces/ArtifactHarvester.tsx b/tgui/packages/voidcrew_tgui/interfaces/ArtifactHarvester.tsx new file mode 100644 index 00000000000..39c43f0dccd --- /dev/null +++ b/tgui/packages/voidcrew_tgui/interfaces/ArtifactHarvester.tsx @@ -0,0 +1,266 @@ +/** + * Exotic particle harvester: a phosphor scope traces the signal of the find beside the machine, + * in its energy's colour, and a glass tube fills with the battery's colour as it draws. + * DM side: voidcrew/modules/xenoarch/use/harvester.dm. + */ +import { Box, Button, Stack } from 'tgui-core/components'; + +import { useBackend } from '../../tgui/backend'; +import { Window } from '../../tgui/layouts'; + +type Source = { + serial: string; + state: string; + color: string | null; +}; + +type Cell = { + fill: number; + color: string | null; + kind: string | null; + serial: string | null; +}; + +type Data = { + powered: number; + drawing: number; + source: Source | null; + cell: Cell | null; +}; + +const WORDS: Record = { + ready: 'SIGNAL', + drawing: 'DRAWING', + quiet: 'NO SIGNAL', + tangled: 'CROSSED', + unfit: 'WILL NOT HOLD', + spent: 'SPENT', + busy: 'ENGAGED', + mismatch: 'CELL MISMATCH', +}; + +const SCREEN_W = 240; +const SCREEN_H = 90; +const PHOSPHOR = '#59d48a'; +/** One period of the base wave in pixels; animated traces only use whole harmonics of it. */ +const PERIOD = 2 * Math.PI * 20; + +/** The trace for a state, twice the screen wide so it can scroll seamlessly. */ +function tracePath(state: string): string { + const points: string[] = []; + for (let x = 0; x <= SCREEN_W * 2; x += 3) { + const t = x / 20; + let y: number; + switch (state) { + case 'ready': + case 'drawing': + y = Math.sin(t) * 22; + break; + case 'tangled': + y = Math.sin(t) * 15 + Math.sin(t * 3 + 1) * 13; + break; + case 'unfit': + y = Math.sin(t * 3) * 26 * Math.exp(-((x % 60) / 16)); + break; + case 'mismatch': + y = Math.sin(t) * 12 + Math.sin(t * 5) * 6; + break; + case 'busy': + y = Math.sign(Math.sin(t * 0.8)) * 14; + break; + default: + y = Math.sin(t * 7) * 1.2; + } + points.push(`${x},${(SCREEN_H / 2 - y).toFixed(1)}`); + } + return `M ${points.join(' L ')}`; +} + +const MOVING = ['ready', 'drawing', 'tangled']; + +function Scope(props: { state: string; color: string; lit: boolean }) { + const { state, color, lit } = props; + return ( + + + {[...Array(9)].map((_, i) => ( + + ))} + {[...Array(3)].map((_, i) => ( + + ))} + {lit ? ( + + {MOVING.includes(state) ? ( + + ) : null} + + ) : null} + + ); +} + +function Tube(props: { fill: number; color: string | null; live: boolean }) { + const { fill, color, live } = props; + const height = 104; + const level = Math.round(height * Math.max(0, Math.min(1, fill))); + return ( + + + + + ); +} + +const etched = { + fontFamily: 'monospace', + fontSize: '10px', + letterSpacing: '2px', + color: '#8f98a6', +}; + +export const ArtifactHarvester = (props) => { + const { act, data } = useBackend(); + const { powered, drawing, source, cell } = data; + const state = source ? source.state : 'none'; + const lit = !!powered; + const traceColor = + (state === 'drawing' || state === 'ready') && source?.color + ? source.color + : PHOSPHOR; + const canDraw = + lit && !drawing && !!cell && cell.fill < 1 && state === 'ready'; + return ( + + + + + + + + + + {source ? source.serial.toUpperCase() : 'NO SOURCE'} + + + {source ? WORDS[state] || '' : ''} + + + + + + + CELL + + + + + + {drawing ? ( + + ) : ( + + )} + + + + + + + + + + + ); +}; 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 ( + + + )) )} @@ -3468,20 +3478,24 @@ const DockPickerMenu = (props: {
Nothing to dock with
) : ( options.map((option) => ( - + + )) )} @@ -4152,20 +4166,24 @@ const DockVariantButtons = (props: { target?: string | null }) => { return (data.dockOptions ?? []) .filter((option) => option.ref === props.target && option.variant) .map((option) => ( - + + )); }; @@ -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 ( - - ); - })} -
+ +
+ {ROSE_CELLS.map(([name, direction, rotation]) => { + const isStop = direction === BURN_STOP; + const lit = isStop + ? burnDirection === BURN_STOP + : commandedCourse === direction; + return ( + + ); + })} +
+
); }; @@ -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; }) => ( + + + 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 ? ( - + + + ) : ( - + + + )} )} {!isActive && ( - + + + )} ); @@ -742,16 +762,18 @@ const BountyCard = (props: BountyCardProps) => { {bounty.is_hunting ? ( - + + + {!bounty.has_tracking && ( @@ -775,16 +797,18 @@ const BountyCard = (props: BountyCardProps) => { ) : ( - + + + )} 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. - - - - - - - - - - - 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) => ( - + + ))} 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 }) => { - + + + @@ -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) => ( - + + ))}
@@ -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) => ( + + + + )) + ) : ( + - )) - ) : ( - + )}
@@ -2533,24 +2555,28 @@ const TubesPanel = () => {
- - + + + + + + {pod_tubes.length > 0 && (
- + + + {!!reason &&
{reason}
} ); @@ -2815,10 +2843,15 @@ const OpsButton = (props: { state?: 'armed' | 'active'; title: string; onClick: () => void; + className?: string; }) => ( + + + + + ); @@ -1313,26 +1339,28 @@ const Research = () => { return ( - + 0 ? 'survey_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 = ( <> - + 0 ? 'trader_sell' : ''}> + + {!done && carrying > 1 && ( + ); +}; + +export const XenoarchAnalyser = () => { + const { act, data } = useBackend(); + const { powered, pad, scanning, specimen, reading, tape, kind_colors } = data; + const channels = reading?.current ? reading.channels : []; + const read = !!powered && !!reading?.current; + const canScan = !!powered && pad === 'ready' && !!specimen && !scanning; + return ( + + + + + + + + + + + + + + + + act('scan')} + /> + + + act('halt')} + /> + + + + + + + + + + + + + + + + + + + + + + + + + act('tear')} + /> + + + + + + + + + ); +}; diff --git a/tgui/packages/voidcrew_tgui/interfaces/XenoarchLabeler.tsx b/tgui/packages/voidcrew_tgui/interfaces/XenoarchLabeler.tsx new file mode 100644 index 00000000000..f84071aebed --- /dev/null +++ b/tgui/packages/voidcrew_tgui/interfaces/XenoarchLabeler.tsx @@ -0,0 +1,206 @@ +/** + * The specimen labeler: the tag it will print, stamped in purple ink on manila + * card, over the words it knows for each line. Click a line on the tag or a + * tab to choose which line to set, then click a word. + */ +import { useState } from 'react'; +import { Box, Button, Stack } from 'tgui-core/components'; + +import { useBackend } from '../../tgui/backend'; +import { Window } from '../../tgui/layouts'; + +type Field = 'effect' | 'trigger' | 'second'; + +type Data = { + effect: string | null; + trigger: string | null; + second: string | null; + effects: string[]; + triggers: string[]; + none: string; +}; + +const FIELDS: { key: Field; title: string }[] = [ + { key: 'effect', title: 'Effect' }, + { key: 'trigger', title: 'Trigger' }, + { key: 'second', title: 'Second' }, +]; + +const INK = '#5b2a86'; + +/** A manila tag on a string, its three lines stamped in purple. */ +const Tag = (props: { + data: Data; + field: Field; + onField: (field: Field) => void; +}) => { + const { data, field, onField } = props; + return ( +
+
+ {FIELDS.map((line) => { + const word = data[line.key]; + return ( +
onField(line.key)} + style={{ + cursor: 'pointer', + display: 'flex', + alignItems: 'baseline', + padding: '2px 4px', + borderBottom: '1px solid #a88a54', + background: field === line.key ? '#ffffff38' : undefined, + }} + > + + {line.title}: + + + {word ?? '...'} + +
+ ); + })} +
+ ); +}; + +export const XenoarchLabeler = () => { + const { act, data } = useBackend(); + const [field, setField] = useState('effect'); + let words = data.effects; + if (field === 'trigger') { + words = data.triggers; + } else if (field === 'second') { + words = [data.none, ...data.effects]; + } + const chosen = data[field]; + const anySet = !!data.effect || !!data.trigger || !!data.second; + const pick = (word: string) => { + act('set', { field, word }); + // Move on to the next blank line, as a hand would. + const next = FIELDS.find((line) => line.key !== field && !data[line.key]); + if (next) { + setField(next.key); + } + }; + return ( + + + + + + + + + {FIELDS.map((tab) => ( + + + + ))} + + + + + {words.map((word) => ( + pick(word)} + style={{ + display: 'inline-block', + cursor: 'pointer', + margin: '3px', + padding: '3px 8px', + borderRadius: '2px', + fontFamily: 'monospace', + fontSize: '12px', + background: word === chosen ? INK : '#e9e1cd', + color: word === chosen ? '#fff' : '#3a3631', + boxShadow: '0 1px 0 #0006', + }} + > + {word} + + ))} + + + + + + + + + + + + + ); +}; 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/tools/gear_catalog/categories.py b/tools/gear_catalog/categories.py index 7e804a834c1..bcc45b02c0a 100644 --- a/tools/gear_catalog/categories.py +++ b/tools/gear_catalog/categories.py @@ -192,8 +192,10 @@ ('/obj/item/access_key', 'tools', ITEM), ('/obj/item/airlock_painter', 'tools', ITEM), ('/obj/item/analyzer', 'tools', ITEM), + ('/obj/item/anomaly_battery', 'relics', ITEM), ('/obj/item/anomaly_neutralizer', 'tools', ITEM), ('/obj/item/anomaly_releaser', 'tools', ITEM), + ('/obj/item/anomaly_utilizer', 'relics', ITEM), ('/obj/item/beacon', 'tools', ITEM), ('/obj/item/binoculars', 'tools', ITEM), ('/obj/item/boxcutter', 'tools', ITEM), @@ -209,6 +211,7 @@ ('/obj/item/dragons_blood', 'relics', ITEM), ('/obj/item/emergency_bed', 'tools', ITEM), ('/obj/item/experi_scanner', 'tools', ITEM), + ('/obj/item/excavation', 'tools', ITEM), ('/obj/item/extendohand', 'tools', ITEM), ('/obj/item/extinguisher', 'tools', ITEM), ('/obj/item/extraction_pack', 'tools', ITEM), diff --git a/tools/gear_catalog/ratings/belts.json b/tools/gear_catalog/ratings/belts.json index 527417b7636..e0827fa2280 100644 --- a/tools/gear_catalog/ratings/belts.json +++ b/tools/gear_catalog/ratings/belts.json @@ -37,6 +37,24 @@ "reason": "A trophy belt that holds one luchador mask.", "tier": "none" }, + "/obj/item/storage/belt/excavation": { + "confidence": "high", + "group": "mining belts", + "hash": "", + "name": "excavation webbing", + "rank": 3, + "reason": "Eight small slots for dig tools, scanners, a GPS and rock samples. Holds nothing a fight needs.", + "tier": "none" + }, + "/obj/item/storage/belt/excavation/full": { + "confidence": "high", + "group": "mining belts", + "hash": "", + "name": "excavation webbing", + "rank": 3, + "reason": "The excavation kit: webbing with a rock hammer, brush, depth scanner, core sampler and find satchel. Prints at round start.", + "tier": "none" + }, "/obj/item/storage/belt/fannypack": { "confidence": "high", "group": "fashion belts", diff --git a/tools/gear_catalog/ratings/relics.json b/tools/gear_catalog/ratings/relics.json index 66247cc16a8..18a8ec53488 100644 --- a/tools/gear_catalog/ratings/relics.json +++ b/tools/gear_catalog/ratings/relics.json @@ -9,6 +9,24 @@ "harmless" ], "items": { + "/obj/item/anomaly_battery": { + "confidence": "high", + "group": "parts and upgrades", + "hash": "", + "name": "exotic battery", + "rank": 2, + "reason": "Holds one effect drawn off an artifact for the exotic utilizer and does nothing alone. Rated as what it powers.", + "tier": "yellow" + }, + "/obj/item/anomaly_utilizer": { + "confidence": "medium", + "group": "parts and upgrades", + "hash": "", + "name": "exotic utilizer", + "rank": 2, + "reason": "Runs one harvested artifact effect from an exotic battery: a field or bursts for about 6.5 minutes, or 10 contact uses. Power is the artifact's own; the worst cases are stun or teleport bursts every 10 to 50 s over 2 to 8 tiles, which hit the holder too unless bio-suited. Healing shares the per-person artifact cap. Needs a dug artifact and a harvester to fill.", + "tier": "yellow" + }, "/obj/item/book_of_babel": { "confidence": "high", "group": "harmless", @@ -349,6 +367,7 @@ "/obj/item/hot_potato/harmless": "no route", "/obj/item/hot_potato/harmless/toy": "toy", "/obj/item/hot_potato/syndicate": "no route", + "/obj/item/relic/excavated": "no route", "/obj/item/shadowcloak/weaker": "no route", "/obj/item/soulstone": "no route", "/obj/item/soulstone/anybody/chaplain/sparring": "no route", diff --git a/tools/gear_catalog/ratings/storage.json b/tools/gear_catalog/ratings/storage.json index 9c01b42d1ad..9988aa6d494 100644 --- a/tools/gear_catalog/ratings/storage.json +++ b/tools/gear_catalog/ratings/storage.json @@ -53,6 +53,15 @@ "reason": "A bag for one kind of work item. Helps with the job, not with a fight.", "tier": "none" }, + "/obj/item/storage/bag/excavation": { + "confidence": "high", + "group": "work bags", + "hash": "", + "name": "find satchel", + "rank": 3, + "reason": "A bag for one kind of work item. Helps with the job, not with a fight.", + "tier": "none" + }, "/obj/item/storage/bag/fishing": { "confidence": "high", "group": "work bags", diff --git a/tools/gear_catalog/ratings/tools.json b/tools/gear_catalog/ratings/tools.json index 53f65496042..3e74dc5cb5e 100644 --- a/tools/gear_catalog/ratings/tools.json +++ b/tools/gear_catalog/ratings/tools.json @@ -749,6 +749,69 @@ "reason": "Wheels a patient along. Faster than dragging.", "tier": "none" }, + "/obj/item/excavation/brush": { + "confidence": "high", + "group": "Mining tools", + "hash": "", + "name": "excavation brush", + "rank": 24, + "reason": "Brushes the last grit off a dig find. Work tool only.", + "tier": "none" + }, + "/obj/item/excavation/brush/quick": { + "confidence": "high", + "group": "Mining tools", + "hash": "", + "name": "quick brush", + "rank": 25, + "reason": "Excavation brush that works in a third of the time. Saves minutes at a dig, nothing else.", + "tier": "none" + }, + "/obj/item/excavation/core_sampler": { + "confidence": "high", + "group": "Mining tools", + "hash": "", + "name": "core sampler", + "rank": 28, + "reason": "Draws a rock core from a dig find for the spectrometer. Work tool only.", + "tier": "none" + }, + "/obj/item/excavation/depth_scanner": { + "confidence": "high", + "group": "Mining tools", + "hash": "", + "name": "depth scanner", + "rank": 26, + "reason": "Reads roughly how deep a dig find sits and how much has been cut. Prints at round start.", + "tier": "none" + }, + "/obj/item/excavation/depth_scanner/advanced": { + "confidence": "medium", + "group": "Mining tools", + "hash": "", + "name": "advanced depth scanner", + "rank": 27, + "reason": "Reads a dig find exactly, and the field it needs, so a crew skips the trip back to the spectrometer. Speeds artifact digging; no use in a fight.", + "tier": "green" + }, + "/obj/item/excavation/hammer": { + "confidence": "high", + "group": "Mining tools", + "hash": "", + "name": "rock hammer", + "rank": 23, + "reason": "Rock hammer with swappable heads for cutting dig finds down. Hits for 6. Prints at round start.", + "tier": "none" + }, + "/obj/item/excavation/stabiliser": { + "confidence": "medium", + "group": "Mining tools", + "hash": "", + "name": "field stabiliser", + "rank": 29, + "reason": "Lays the field that keeps a large dig find whole as it comes out. Needed to get full value from artifacts; harmless otherwise.", + "tier": "green" + }, "/obj/item/experi_scanner": { "confidence": "high", "group": "Scanners and trackers", @@ -3002,6 +3065,7 @@ "/obj/item/door_remote/head_of_security": "no route", "/obj/item/door_remote/omni": "no route", "/obj/item/emergency_bed/silicon": "no route", + "/obj/item/excavation": "abstract", "/obj/item/extendohand/acme": "no route", "/obj/item/extinguisher/anti": "no route", "/obj/item/extinguisher/mini/nozzle": "uncreatable", 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/_DEFINES/xenoarch.dm b/voidcrew/_DEFINES/xenoarch.dm new file mode 100644 index 00000000000..75262a30333 --- /dev/null +++ b/voidcrew/_DEFINES/xenoarch.dm @@ -0,0 +1,265 @@ +// Xenoarchaeology: shared defines for every part of voidcrew/modules/xenoarch/. +// Each section names the part that owns its numbers. Parts may add part-local defines at +// the top of their own files; anything two parts read belongs here. +// +// Unit tests compile before this file and cannot see these defines (see the test files for +// the literal values they mirror). + +// ===== Bands (shared) ===== +// A find's band is the ZONE_* it was dug in (voidcrew/_DEFINES/overmap_zones.dm), stamped on +// the find. Price and research read the stamp, never where the find is now. A null stamp +// means "not dug": buyers refuse it. + +/// Positional lists below are indexed by ZONE_GREEN (1), ZONE_YELLOW (2), ZONE_RED (3). +#define XENOARCH_BAND_INDEX(band) clamp(band || ZONE_GREEN, ZONE_GREEN, ZONE_RED) + +// ===== Effect tiers (core) ===== +// Numeric so they index the positional lists below. Never use them as assoc keys. +#define ARTIFACT_TIER_COMMON 1 +#define ARTIFACT_TIER_UNCOMMON 2 +#define ARTIFACT_TIER_RARE 3 +#define ARTIFACT_TIER_EXTREME 4 + +/// Main-effect tier odds for a large artifact, per band: common, uncommon, rare, extreme. +#define ARTIFACT_TIER_ODDS_GREEN list(62, 28, 9, 1) +#define ARTIFACT_TIER_ODDS_YELLOW list(45, 33, 18, 4) +#define ARTIFACT_TIER_ODDS_RED list(30, 34, 27, 9) + +/// Chance a large artifact also carries a minor second effect. +#define ARTIFACT_SECOND_EFFECT_CHANCE 50 + +// ===== Effect strength (core) ===== +#define ARTIFACT_STRENGTH_SMALL "small" +#define ARTIFACT_STRENGTH_MEDIUM "medium" +#define ARTIFACT_STRENGTH_LARGE "large" +/// Strength weights per band (small, medium, large): green leans small, red leans large. +#define ARTIFACT_STRENGTH_ODDS_GREEN list(60, 30, 10) +#define ARTIFACT_STRENGTH_ODDS_YELLOW list(35, 45, 20) +#define ARTIFACT_STRENGTH_ODDS_RED list(15, 45, 40) + +// ===== Release modes (core) ===== +// What the analyser reports as "contact", "field" or "bursts". +#define ARTIFACT_RELEASE_TOUCH "touch" +#define ARTIFACT_RELEASE_AURA "aura" +#define ARTIFACT_RELEASE_PULSE "pulse" +#define ARTIFACT_ALL_RELEASE_METHODS list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_AURA, ARTIFACT_RELEASE_PULSE) + +// ===== Charge (core) ===== +// Per second. Auras spend three times what the artifact refills, so a bolted aura runs about +// a third of the time. A pulse fires when the store is full and empties it. +#define ARTIFACT_RECHARGE_PER_SECOND 0.5 +#define ARTIFACT_AURA_COST_PER_SECOND 1.5 +#define ARTIFACT_TOUCH_COST 3 + +// ===== Triggers (core) ===== +// Bitflags so an effect can hold one and a check can test several. Oxygen and nitrogen +// triggers from Nova are deliberately gone: ship air would keep those artifacts always on. +#define ARTIFACT_TRIGGER_TOUCH (1<<0) +#define ARTIFACT_TRIGGER_WATER (1<<1) +#define ARTIFACT_TRIGGER_ACID (1<<2) +#define ARTIFACT_TRIGGER_VOLATILE (1<<3) +#define ARTIFACT_TRIGGER_TOXIN (1<<4) +#define ARTIFACT_TRIGGER_IMPACT (1<<5) +#define ARTIFACT_TRIGGER_ENERGY (1<<6) +#define ARTIFACT_TRIGGER_HEAT (1<<7) +#define ARTIFACT_TRIGGER_COLD (1<<8) +#define ARTIFACT_TRIGGER_PLASMA (1<<9) +#define ARTIFACT_TRIGGER_CO2 (1<<10) +#define ARTIFACT_TRIGGER_PROXIMITY (1<<11) + +/// Triggers read from the air on the artifact's tile every process. +#define ARTIFACT_TRIGGERS_AIR (ARTIFACT_TRIGGER_HEAT | ARTIFACT_TRIGGER_COLD | ARTIFACT_TRIGGER_PLASMA | ARTIFACT_TRIGGER_CO2) +/// Triggers held for as long as a condition lasts, rather than woken by a stimulus. +#define ARTIFACT_TRIGGERS_LEVEL (ARTIFACT_TRIGGERS_AIR | ARTIFACT_TRIGGER_PROXIMITY) + +/// Every trigger an effect may roll. Weights are in artifact_trigger_weight(). +#define ARTIFACT_ALL_TRIGGERS list(\ + ARTIFACT_TRIGGER_TOUCH,\ + ARTIFACT_TRIGGER_WATER,\ + ARTIFACT_TRIGGER_ACID,\ + ARTIFACT_TRIGGER_VOLATILE,\ + ARTIFACT_TRIGGER_TOXIN,\ + ARTIFACT_TRIGGER_IMPACT,\ + ARTIFACT_TRIGGER_ENERGY,\ + ARTIFACT_TRIGGER_HEAT,\ + ARTIFACT_TRIGGER_COLD,\ + ARTIFACT_TRIGGER_PLASMA,\ + ARTIFACT_TRIGGER_CO2,\ + ARTIFACT_TRIGGER_PROXIMITY,\ +) + +// Trigger thresholds (Nova's values). +#define ARTIFACT_HEAT_AIR_KELVIN 375 +#define ARTIFACT_HEAT_TOOL_KELVIN 700 +#define ARTIFACT_COLD_AIR_KELVIN 225 +#define ARTIFACT_GAS_TRIGGER_MOLES 10 +#define ARTIFACT_PROXIMITY_RANGE 3 +#define ARTIFACT_IMPACT_THROWFORCE 10 + +// Trigger families, as the analyser reports them. +#define ARTIFACT_FAMILY_CONTACT "contact" +#define ARTIFACT_FAMILY_ENERGY "energy" +#define ARTIFACT_FAMILY_AIR "air" + +// ===== Waking (core) ===== +/// How long a contact stimulus keeps an effect awake. Each artifact rolls once in this range; +/// another stimulus while awake starts the count again. +#define ARTIFACT_WAKE_MIN (45 SECONDS) +#define ARTIFACT_WAKE_MAX (90 SECONDS) +/// How long a level trigger keeps an effect awake after its condition ends. +#define ARTIFACT_LEVEL_LINGER (6 SECONDS) +/// Hauling, bumping and repeated pats count as one touch per this long. +#define ARTIFACT_TOUCH_COOLDOWN (3 SECONDS) + +// ===== Energy kinds (core) ===== +// Nova's seven type_name values. Several effects share each kind, so the analyser narrows +// an artifact down without naming its effect. Keys index GLOB.artifact_energy_kinds. +#define ARTIFACT_ENERGY_CONCENTRATED "concentrated" +#define ARTIFACT_ENERGY_PSIONIC "psionic" +#define ARTIFACT_ENERGY_ELECTROMAGNETIC "electromagnetic" +#define ARTIFACT_ENERGY_PARTICLE "particle" +#define ARTIFACT_ENERGY_ORGANIC "organic" +#define ARTIFACT_ENERGY_BLUESPACE "bluespace" +#define ARTIFACT_ENERGY_SYNTHESIS "synthesis" + +// ===== Labels (core vocabulary; the labeler is P3) ===== +/// The second-effect field when the labeller thinks there is none. A correct "None" counts. +#define ARTIFACT_LABEL_NONE "None" + +// ===== Scan and harvest lock (core API; analyser P3, harvester P4) ===== +/// A lock nobody released frees itself after this long. +#define ARTIFACT_LOCK_TIMEOUT (2 MINUTES) + +// ===== Harvesting (P4 owns the machines) ===== +#define ARTIFACT_MAX_HARVESTS 3 +/// Charge an exotic battery holds. One harvest fills one battery. +#define ARTIFACT_BATTERY_CAPACITY 200 +/// Charge per second a harvester draws on tier-1 capacitors: a full battery in 80 seconds. +#define ARTIFACT_HARVEST_DRAW_RATE 2.5 +/// Charge per second a utilizer spends running a field or bursts: a full battery lasts 400 seconds. +#define ARTIFACT_UTILIZER_DRAIN 0.5 +/// Charge per second a utilizer feeds a burst effect's store, twice what an artifact refills. +#define ARTIFACT_UTILIZER_PULSE_FEED 1 +/// Charge one contact use costs: ten from a full battery. +#define ARTIFACT_UTILIZER_TOUCH_COST 20 + +// ===== Pricing (core function; buyers are P5) ===== +/// Base price of a large artifact by stamped band (green, yellow, red). +#define ARTIFACT_PRICE_BASE list(250, 450, 700) +/// Main-effect tier multiplier (common, uncommon, rare, extreme). +#define ARTIFACT_PRICE_TIER_MULT list(1, 1.5, 2.5, 4) +/// Label accuracy shares. A label pays its share at or above the floor, else the unlabelled rate. +#define ARTIFACT_LABEL_SHARE_EFFECT 0.5 +#define ARTIFACT_LABEL_SHARE_TRIGGER 0.3 +#define ARTIFACT_LABEL_SHARE_SECOND 0.2 +#define ARTIFACT_LABEL_ACCURACY_FLOOR 0.5 +#define ARTIFACT_UNLABELLED_SHARE 0.2 +#define ARTIFACT_DAMAGED_MULT 0.5 +#define ARTIFACT_HARVEST_MULT 0.8 +/// Receipts round to this many credits. +#define ARTIFACT_PRICE_ROUNDING 5 + +// ===== Research (core function; payout is P3) ===== +/// First full analysis of a large artifact, by stamped band (green, yellow, red). +#define ARTIFACT_RESEARCH_POINTS list(100, 150, 250) +/// Multiplier for a rare or extreme main effect. +#define ARTIFACT_RESEARCH_RARE_MULT 1.5 + +// ===== Dig sites (P2) ===== +#define XENOARCH_SITES_PER_PLANET 3 +/// Large and small finds per site, by band (green, yellow, red). +#define XENOARCH_LARGE_PER_SITE list(1, 1, 2) +#define XENOARCH_SMALL_PER_SITE list(3, 3, 2) +/// Small-find tier odds per band: tier 1, 2, 3. +#define XENOARCH_SMALL_TIER_ODDS_GREEN list(60, 32, 8) +#define XENOARCH_SMALL_TIER_ODDS_YELLOW list(50, 37, 13) +#define XENOARCH_SMALL_TIER_ODDS_RED list(40, 40, 20) +/// Chance that uncovering a large find wakes local fauna, by band. +#define XENOARCH_AMBUSH_CHANCE list(0, 25, 45) +/// Minimum tiles between two dig sites. +#define XENOARCH_SITE_SPACING 20 + +/// do_after key for every dig tool, so one person works one thing at a time. +#define DOAFTER_SOURCE_XENOARCH "doafter_xenoarch" + +/// What a site wall gives up when it is mined. +#define XENOARCH_FIND_LARGE 1 +#define XENOARCH_FIND_SMALL 2 + +/// Dig site kinds (Bay's), which set the small finds a site holds. +#define XENOARCH_SITE_GARDEN "garden" +#define XENOARCH_SITE_ANIMAL "animal" +#define XENOARCH_SITE_HOUSE "house" +#define XENOARCH_SITE_TECHNICAL "technical" +#define XENOARCH_SITE_TEMPLE "temple" +#define XENOARCH_SITE_WAR "war" + +/// Large find shares, in percent, out of what a boulder holds. The rest is an alien artifact. +#define XENOARCH_FIND_SHARE_FORMATION 6 +#define XENOARCH_FIND_SHARE_CRYSTAL 4 +#define XENOARCH_FIND_SHARE_CASE 2 +/// Combat exosuit wrecks: red sites only, taken out of the artifact share. About one a round. +#define XENOARCH_FIND_SHARE_EXOSUIT_RED 1 + +/// A boulder's find sits this deep, in cm. +#define XENOARCH_BOULDER_DEPTH_MIN 25 +#define XENOARCH_BOULDER_DEPTH_MAX 200 +/// The plain depth scanner reads a boulder to within this many cm (a strange rock to a third of it). +#define XENOARCH_SCAN_ERROR 15 +/// Hammering costs this long per cm the head takes off. +#define XENOARCH_HAMMER_TIME_PER_CM (0.5 SECONDS) +/// One pass of the brush. +#define XENOARCH_BRUSH_TIME (3 SECONDS) +#define XENOARCH_BRUSH_TIME_QUICK (1 SECONDS) +/// A pick or drill takes this much off a boulder per swing, roughly. +#define XENOARCH_PICK_CUT_MIN 18 +#define XENOARCH_PICK_CUT_MAX 30 +/// Chance an unstabilised large find comes apart as it is freed. The rest come out damaged. +#define XENOARCH_UNSTABLE_CRUMBLE_CHANCE 50 + +/// Strange rocks: the find sits 6 to 14 cm deep, plus this much per tier. +#define XENOARCH_ROCK_DEPTH_PER_TIER 8 + +/// Curio classes, as buyers price them (design: shell 40, fossil 50, pottery 80, +/// statuette or instrument 150, strange object 200 cr). +#define XENOARCH_CURIO_SHELL "shell" +#define XENOARCH_CURIO_FOSSIL "fossil" +#define XENOARCH_CURIO_POTTERY "pottery" +#define XENOARCH_CURIO_STATUETTE "statuette" +#define XENOARCH_CURIO_INSTRUMENT "instrument" +#define XENOARCH_CURIO_STRANGE_OBJECT "strange object" + +/// Charged crystal: what it puts on the wire and for how long in all before it goes dull. +#define XENOARCH_CRYSTAL_POWER (15 KILO WATTS) +#define XENOARCH_CRYSTAL_LIFETIME (90 MINUTES) + +// ===== Signals ===== +// All sent on the artifact (/obj/machinery/artifact) unless noted. + +/// An effect woke: (datum/artifact_effect/effect) +#define COMSIG_ARTIFACT_EFFECT_ACTIVATED "artifact_effect_activated" +/// An effect went dormant: (datum/artifact_effect/effect) +#define COMSIG_ARTIFACT_EFFECT_DEACTIVATED "artifact_effect_deactivated" +/// A stimulus reached the artifact, whether or not anything woke: (trigger, mob/living/user, woke) +#define COMSIG_ARTIFACT_STIMULATED "artifact_stimulated" +/// A label was stuck on or scraped off: (datum/artifact_label/label_or_null, mob/user) +#define COMSIG_ARTIFACT_LABEL_CHANGED "artifact_label_changed" +/// The artifact was stamped as dug: (band) +#define COMSIG_ARTIFACT_STAMPED "artifact_stamped" +/// One harvest was taken from it (P4 sends): (datum/artifact_effect/effect, mob/user) +#define COMSIG_ARTIFACT_HARVESTED "artifact_harvested" +/// It was sold (P5 sends, on the artifact before it is deleted): (credits, vouchers, mob/seller) +#define COMSIG_ARTIFACT_SOLD "artifact_sold" + +// ===== Metrics (record_metric events) ===== +// Category in brackets. Event names must never equal a record_metric() parameter name. +/// [METRIC_RESEARCH] a find came out of the ground. subject = find type, zone = band. +#define XENOARCH_METRIC_DUG "artifact_dug" +/// [METRIC_RESEARCH] a find crumbled or came out unstabilised. +#define XENOARCH_METRIC_LOST "artifact_lost" +/// [METRIC_RESEARCH] first full analysis paid. points = research points. +#define XENOARCH_METRIC_ANALYSED "artifact_analysed" +/// [METRIC_RESEARCH] an effect was drained into a battery. +#define XENOARCH_METRIC_HARVESTED "artifact_harvested" +/// [METRIC_TRADE] sold at an outpost. credits, vouchers; details: accuracy, tier, band, harvests, damaged. +#define XENOARCH_METRIC_SOLD "artifact_sold" 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/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/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_checkpoint_snapshot.dm b/voidcrew/modules/player_outposts/outpost_checkpoint_snapshot.dm index 84f9ef147fd..0043d64dc0e 100644 --- a/voidcrew/modules/player_outposts/outpost_checkpoint_snapshot.dm +++ b/voidcrew/modules/player_outposts/outpost_checkpoint_snapshot.dm @@ -48,6 +48,10 @@ GLOBAL_LIST_INIT(outpost_checkpoint_excluded, typecacheof(list( /obj/structure/headpike, // Outpost property that works a ship bay's side rooms, never a ship's fitting. /obj/structure/outpost_yard_droid, + // Dug finds live for the round only: rebuilding one would reroll its effects and refill its + // harvests (voidcrew/modules/xenoarch/). + /obj/machinery/artifact, + /obj/machinery/power/charged_crystal, ))) /** 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 499ec70cafb..8731c0c0118 100644 --- a/voidcrew/modules/unit_tests/_unit_tests.dm +++ b/voidcrew/modules/unit_tests/_unit_tests.dm @@ -295,6 +295,7 @@ #include "voidcrew_trader_checkpoint.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" @@ -315,6 +316,12 @@ #include "voidcrew_weapon_ladder.dm" #include "voidcrew_weather_sites.dm" #include "voidcrew_windoor_survey.dm" +#include "voidcrew_xenoarch_core.dm" +#include "voidcrew_xenoarch_dig.dm" +#include "voidcrew_xenoarch_effects_polaris.dm" +#include "voidcrew_xenoarch_study.dm" +#include "voidcrew_xenoarch_trade.dm" +#include "voidcrew_xenoarch_use.dm" #include "voidcrew_zone_identity.dm" #include "voidcrew_zone_logging.dm" #include "voidcrew_zone_missions.dm" diff --git a/voidcrew/modules/unit_tests/voidcrew_tutorials.dm b/voidcrew/modules/unit_tests/voidcrew_tutorials.dm new file mode 100644 index 00000000000..5d6840de917 --- /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-6:0", "The arrow is not one tile in from the south edge") + +/// 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/modules/unit_tests/voidcrew_xenoarch_core.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_core.dm new file mode 100644 index 00000000000..f8168ec71b3 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_core.dm @@ -0,0 +1,216 @@ +// Xenoarchaeology tests: core. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm: +// bands (ZONE_*): green 1, yellow 2, red 3 +// tiers: common 1, uncommon 2, rare 3, extreme 4 +// triggers: touch 1, water 2, acid 4, volatile 8, toxin 16, impact 32, energy 64, +// heat 128, cold 256, plasma 512, co2 1024, proximity 2048 +// release methods: "touch", "aura", "pulse" + +/// Sale price: the design's worked examples, the label floor, condition and rounding. +/datum/unit_test/voidcrew_xenoarch_price/Run() + TEST_ASSERT_EQUAL(xenoarch_price_for(1, 1, 1), 250, "green common, perfect label") + TEST_ASSERT_EQUAL(xenoarch_price_for(2, 3, 1), 1125, "yellow rare, perfect label") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 3, 1), 1750, "red rare, perfect label") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 4, 1), 2800, "red extreme, perfect label") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 1, 0), 140, "red common, unlabelled") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 1, 0.3), 140, "a label under half right pays the unlabelled rate") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 1, 0.5), 350, "a half-right label pays half") + TEST_ASSERT_EQUAL(xenoarch_price_for(3, 1, 0.5 + 0.3 + 0.2), 700, "a perfect label summed in floating point pays in full") + TEST_ASSERT_EQUAL(xenoarch_price_for(2, 1, 1, TRUE), 225, "damaged halves the price") + TEST_ASSERT_EQUAL(xenoarch_price_for(1, 1, 1, FALSE, 3), 130, "three harvests take 0.8 cubed, rounded to 5") + TEST_ASSERT_EQUAL(xenoarch_price_for(null, 1, 1), 250, "an unknown band prices as green") + TEST_ASSERT_EQUAL(xenoarch_research_points(1, 1), 100, "green research") + TEST_ASSERT_EQUAL(xenoarch_research_points(3, 3), 375, "red rare research") + + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/heal, null, 2) + TEST_ASSERT_EQUAL(artifact_sale_value(find), 0, "a find never dug sold for credits") + TEST_ASSERT_EQUAL(artifact_research_value(find), 0, "a find never dug paid research") + find.stamp_origin(2) + TEST_ASSERT_EQUAL(artifact_research_value(find), 150, "a dug yellow uncommon find pays the wrong research") + TEST_ASSERT(!find.stamp_origin(3), "a second stamp replaced the first") + TEST_ASSERT_EQUAL(artifact_sale_value(find), 135, "an unlabelled yellow uncommon find") + var/trigger_word = artifact_trigger_name(find.main_effect.trigger) + find.apply_label(new /datum/artifact_label("Heals", trigger_word, "None")) + TEST_ASSERT_EQUAL(find.label_accuracy(), 1, "a perfect label did not read as perfect") + TEST_ASSERT_EQUAL(artifact_sale_value(find), 675, "a perfectly labelled yellow uncommon find") + find.apply_label(new /datum/artifact_label("Heals", trigger_word, "Light")) + TEST_ASSERT_EQUAL(artifact_sale_value(find), 540, "a wrong second effect costs a fifth") + find.damaged = TRUE + find.harvests_left = 2 + TEST_ASSERT_EQUAL(artifact_sale_value(find), 215, "damaged and harvested once") + find.research_paid = TRUE + TEST_ASSERT_EQUAL(artifact_research_value(find), 0, "research paid twice for one artifact") + +/// Every rollable effect is complete, every tier can roll, and the free-power fix holds. +/datum/unit_test/voidcrew_xenoarch_catalogue/Run() + var/list/tiers_seen = list() + for(var/datum/artifact_effect/effect_type as anything in artifact_effect_types()) + var/datum/artifact_effect/effect = new effect_type(null, 1) + TEST_ASSERT(effect.tier >= 1 && effect.tier <= 4, "[effect_type] has tier [effect.tier]") + TEST_ASSERT(!effect.minor || effect.tier <= 2, "[effect_type] is minor above uncommon") + TEST_ASSERT(length(effect.allowed_release_methods), "[effect_type] can't release at all") + TEST_ASSERT(effect.release_method in list("touch", "aura", "pulse"), "[effect_type] rolled release [effect.release_method]") + TEST_ASSERT(GLOB.artifact_energy_kinds[effect.energy_kind], "[effect_type] rolled unknown energy kind [effect.energy_kind]") + TEST_ASSERT(effect.trigger in list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048), "[effect_type] rolled trigger [effect.trigger]") + TEST_ASSERT(effect.label_name in artifact_effect_label_names(), "[effect_type]'s label is missing from the labeler words") + TEST_ASSERT(!(effect.helpful && effect.harmful), "[effect_type] is both helpful and harmful") + tiers_seen |= effect.tier + qdel(effect) + for(var/tier in 1 to 4) + TEST_ASSERT(tier in tiers_seen, "no effect can roll at tier [tier]") + TEST_ASSERT(xenoarch_pick_effect_type(tier, 1), "picking a tier [tier] effect found nothing") + TEST_ASSERT(xenoarch_pick_effect_type(null, 3, minor_only = TRUE), "no minor second effect can roll") + var/datum/artifact_effect/tesla/tesla = new(null, 3) + TEST_ASSERT(!(tesla.zap_flags & ZAP_GENERATES_POWER), "the tesla effect powers tesla coils") + qdel(tesla) + + // Deeper bands roll stronger effects (2000 rolls each; the means are about 1.5 and 2.15). + var/green_total = 0 + var/red_total = 0 + for(var/i in 1 to 2000) + green_total += xenoarch_roll_tier(1) + red_total += xenoarch_roll_tier(3) + TEST_ASSERT(red_total > green_total * 1.2, "red tier rolls ([red_total]) are not clearly above green ([green_total])") + +/// Triggers: only the matching stimulus wakes an effect, wakes lapse, and a crated find never stirs. +/datum/unit_test/voidcrew_xenoarch_triggers/Run() + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/water), 2, "water is not a water trigger") + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/hydrogen), 2, "hydrogen is not a water trigger") + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/toxin/acid), 4, "acid is not an acid trigger") + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/toxin/plasma), 8, "liquid plasma is not volatile") + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/toxin), 16, "toxin is not a toxin trigger") + TEST_ASSERT_EQUAL(artifact_reagent_trigger(/datum/reagent/consumable/sugar), 0, "sugar set something off") + TEST_ASSERT_EQUAL(artifact_reagent_triggers(list(/datum/reagent/water, /datum/reagent/toxin/acid)), 6, "a mixture should count as both") + + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/temperature/heat, /datum/artifact_effect/light, 1) + find.main_effect.trigger = 2 + find.second_effect.trigger = 32 + TEST_ASSERT(!find.stimulate(1), "touch matched a water trigger") + TEST_ASSERT(!find.is_active(), "a wrong stimulus woke it") + TEST_ASSERT(find.stimulate(2), "water did not match a water trigger") + TEST_ASSERT(find.main_effect.activated, "water did not wake the main effect") + TEST_ASSERT(!find.second_effect.activated, "water woke the impact-triggered second effect") + TEST_ASSERT(find.shown_awake, "the artifact does not look awake") + TEST_ASSERT_EQUAL(find.icon_state, "[find.shape]_active", "the artifact did not switch to its active sprite") + find.main_effect.awake_until = world.time - 1 + find.process(2) + TEST_ASSERT(!find.main_effect.activated, "an expired wake did not lapse") + TEST_ASSERT_EQUAL(find.icon_state, find.shape, "the artifact kept its active sprite asleep") + + // The glove rule. + var/mob/living/carbon/human/consistent/tester = allocate(/mob/living/carbon/human/consistent) + TEST_ASSERT(artifact_touch_counts(tester), "a bare hand did not count as touch") + var/obj/item/clothing/gloves/latex/latex = allocate(/obj/item/clothing/gloves/latex) + tester.equip_to_slot_if_possible(latex, ITEM_SLOT_GLOVES) + TEST_ASSERT(!artifact_touch_counts(tester), "latex gloves counted as touch") + qdel(latex) + var/obj/item/clothing/gloves/color/yellow/insulated = allocate(/obj/item/clothing/gloves/color/yellow) + tester.equip_to_slot_if_possible(insulated, ITEM_SLOT_GLOVES) + TEST_ASSERT(artifact_touch_counts(tester), "ordinary gloves did not count as touch") + find.main_effect.trigger = 1 + find.touched_by(tester) + TEST_ASSERT(find.main_effect.activated, "a gloved hand did not wake a touch trigger") + + // Proximity is held while someone stands near, and only then. + find.main_effect.deactivate(quiet = TRUE) + find.main_effect.trigger = 2048 + tester.moveToNullspace() + find.process(2) + TEST_ASSERT(!find.main_effect.activated, "proximity woke with nobody near") + tester.forceMove(get_step(find, EAST)) + find.process(2) + TEST_ASSERT(find.main_effect.activated, "proximity did not wake with someone beside it") + + // Crated, it goes still and ignores everything. + var/obj/structure/closet/crate/specimen/crate = allocate(/obj/structure/closet/crate/specimen, get_step(find, NORTH)) + find.forceMove(crate) + TEST_ASSERT(!find.is_active(), "a crated find stayed awake") + TEST_ASSERT(!find.stimulate(2048), "a crated find took a stimulus") + find.process(2) + TEST_ASSERT(!find.is_active(), "a crated find woke from proximity") + +/// The analyser and harvester lock frees itself on release, on its holder's deletion and on timeout. +/datum/unit_test/voidcrew_xenoarch_lock/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + var/datum/analyser = allocate(/datum) + var/datum/harvester = allocate(/datum) + TEST_ASSERT(find.try_lock(analyser), "a free artifact refused a lock") + TEST_ASSERT(find.is_being_used(), "a locked artifact reads as free") + TEST_ASSERT(!find.try_lock(harvester), "a second machine took a held lock") + TEST_ASSERT(!find.release_lock(harvester), "a machine released someone else's lock") + TEST_ASSERT(find.release_lock(analyser), "a halted scan could not release its lock") + TEST_ASSERT(!find.is_being_used(), "releasing left the artifact locked") + TEST_ASSERT(find.try_lock(harvester), "a released artifact refused a new lock") + qdel(harvester) + TEST_ASSERT(!find.is_being_used(), "a deleted machine kept its lock") + TEST_ASSERT(find.try_lock(analyser, 0), "could not take a lock") + TEST_ASSERT(!find.is_being_used(), "a lock outlived its timeout") + +/// Finds never ride along in a ship checkpoint or save. +/datum/unit_test/voidcrew_xenoarch_checkpoints/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + TEST_ASSERT(!outpost_checkpoint_saves(find), "a checkpoint would save a loose artifact") + find.set_anchored(TRUE) + TEST_ASSERT(!outpost_checkpoint_saves(find), "a checkpoint would save a bolted artifact") + TEST_ASSERT_NULL(find.checkpoint_type(), "an artifact has a checkpoint rebuild type") + var/obj/machinery/power/charged_crystal/crystal = allocate(/obj/machinery/power/charged_crystal) + TEST_ASSERT(!outpost_checkpoint_saves(crystal), "a checkpoint would save a charged crystal") + +/// Artifact healing shares one cap per person, whatever does the healing. +/datum/unit_test/voidcrew_xenoarch_heal_cap/Run() + var/mob/living/carbon/human/consistent/patient = allocate(/mob/living/carbon/human/consistent) + patient.take_overall_damage(60, 60) + var/healed = 0 + for(var/i in 1 to 6) + healed += artifact_capped_heal(patient, 12) + TEST_ASSERT(healed <= 30.5, "artifact healing went past the cap ([healed])") + TEST_ASSERT(healed >= 29.5, "artifact healing stopped short of the cap ([healed])") + TEST_ASSERT_EQUAL(artifact_capped_heal(patient, 50), 0, "a fresh call slipped past the cap") + + // A wound of one kind takes the whole heal, not half of it. + var/mob/living/carbon/human/consistent/bruised = allocate(/mob/living/carbon/human/consistent) + bruised.take_overall_damage(40, 0) + var/mended = artifact_capped_heal(bruised, 12) + TEST_ASSERT(mended >= 11.5 && mended <= 12.5, "a brute-only wound healed [mended] of 12") + TEST_ASSERT_EQUAL(artifact_capped_heal(allocate(/mob/living/carbon/human/consistent), 12), 0, "an unhurt body used up heal") + +/// Deleting an artifact deletes its effects and leaves them no holder. +/datum/unit_test/voidcrew_xenoarch_cleanup/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/heal, /datum/artifact_effect/light, 1) + var/datum/artifact_effect/main = find.main_effect + var/datum/artifact_effect/second = find.second_effect + main.wake(1 MINUTES) + second.wake(1 MINUTES) + qdel(find) + TEST_ASSERT(QDELETED(main), "the main effect outlived its artifact") + TEST_ASSERT(QDELETED(second), "the second effect outlived its artifact") + TEST_ASSERT_NULL(main.holder, "the main effect kept its artifact") + +/** + * An artifact idling, or running heat and gas, on a planet never gives a planet turf private air. + * Uses the shared planet air room from voidcrew_planet_shared_air.dm. + */ +/datum/unit_test/voidcrew_planet_shared_air/xenoarch_idle_artifact/Run() + if(!planetary_atmos_shared_mix_enabled()) + return + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, center) + find.replace_effects(/datum/artifact_effect/temperature/heat, /datum/artifact_effect/gas, 3) + // Air triggers read the air every process. + find.main_effect.trigger = 128 + find.second_effect.trigger = 1024 + TEST_ASSERT(room_is_pristine(), "placing an artifact gave the planet private air") + for(var/i in 1 to 3) + find.process(2) + TEST_ASSERT(room_is_pristine(), "an idle artifact gave the planet private air") + find.main_effect.release_method = "aura" + find.second_effect.release_method = "aura" + find.main_effect.wake(1 MINUTES) + find.second_effect.wake(1 MINUTES) + for(var/i in 1 to 3) + find.process(2) + TEST_ASSERT(room_is_pristine(), "heat or gas running on a planet gave it private air") diff --git a/voidcrew/modules/unit_tests/voidcrew_xenoarch_dig.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_dig.dm new file mode 100644 index 00000000000..99b71429a33 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_dig.dm @@ -0,0 +1,260 @@ +// Xenoarchaeology tests: dig. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm: +// bands (ZONE_*): green 1, yellow 2, red 3 +// finds per site (large, small): green 1 + 3, yellow 1 + 3, red 2 + 2; 3 sites a planet +// XENOARCH_FIND_LARGE 1, XENOARCH_FIND_SMALL 2 +// XENOARCH_CRYSTAL_LIFETIME 90 minutes = 54000 deciseconds +// curio values: shell 40, fossil 50, pottery 80, statuette and instrument 150, strange object 200 + +/// The reserve holds a fixed supply: seeding happens once, finds come out one at a time, and a +/// boulder cut loose stays counted until it is opened or lost. +/datum/unit_test/voidcrew_xenoarch_dig_reserve/Run() + var/datum/planet_dig_reserve/red = allocate(/datum/planet_dig_reserve, 3) + TEST_ASSERT(red.seed(/datum/planet/lava), "the first build did not seed the reserve") + TEST_ASSERT(!red.seed(/datum/planet/lava), "a rebuild seeded the reserve again") + TEST_ASSERT_EQUAL(length(red.sites), 3, "a planet should hold three sites") + TEST_ASSERT_EQUAL(red.finds_left(), 12, "a red planet should hold twelve finds") + var/datum/dig_site_record/site = red.sites[1] + TEST_ASSERT_EQUAL(site.large_left, 2, "a red site should hold two large finds") + TEST_ASSERT_EQUAL(site.small_left, 2, "a red site should hold two small finds") + TEST_ASSERT_EQUAL(site.band, 3, "a red site was not stamped red") + + var/datum/planet_dig_reserve/green = allocate(/datum/planet_dig_reserve, 1) + green.seed(/datum/planet/beach) + var/datum/dig_site_record/green_site = green.sites[1] + TEST_ASSERT_EQUAL(green_site.large_left, 1, "a green site should hold one large find") + TEST_ASSERT_EQUAL(green_site.small_left, 3, "a green site should hold three small finds") + + TEST_ASSERT(site.take_find(1), "a large find could not be taken") + TEST_ASSERT(site.take_find(1), "the second large find could not be taken") + TEST_ASSERT(!site.take_find(1), "a third large find came out of a two-find site") + var/datum/dig_boulder_record/boulder = site.cut_boulder() + TEST_ASSERT_EQUAL(site.finds_left(), 3, "a boulder cut loose was not counted as still to come") + TEST_ASSERT_EQUAL(boulder.band, 3, "a red boulder was not stamped red") + TEST_ASSERT(boulder.target_depth >= 25 && boulder.target_depth <= 200, "boulder depth [boulder.target_depth] out of range") + TEST_ASSERT(boulder.field in GLOB.xenoarch_stabilising_fields, "boulder rolled unknown field [boulder.field]") + TEST_ASSERT(boulder.serial, "boulder has no catalogue number") + site.settle_boulder(boulder) + TEST_ASSERT_EQUAL(site.finds_left(), 2, "an opened boulder still counted") + qdel(boulder) + TEST_ASSERT_EQUAL(length(red.sites_with_finds()), 3, "a site with finds left was skipped") + site.small_left = 0 + TEST_ASSERT_EQUAL(length(red.sites_with_finds()), 2, "an emptied site would be rebuilt") + +/// Mining a site wall frees its find and debits the record; an unopened boulder survives its own +/// deletion (a planet teardown) and comes back as it was. +/datum/unit_test/voidcrew_xenoarch_site_wall + /// Turfs this test turned to rock -> their original type, put back even if an assertion fails + var/list/changed_turfs = list() + +/datum/unit_test/voidcrew_xenoarch_site_wall/Destroy() + for(var/turf/changed as anything in changed_turfs) + changed.ChangeTurf(changed_turfs[changed]) + changed_turfs = null + return ..() + +/datum/unit_test/voidcrew_xenoarch_site_wall/Run() + var/datum/dig_site_record/site = allocate(/datum/dig_site_record, 2, "house") + site.large_left = 1 + site.small_left = 1 + var/turf/large_spot = run_loc_floor_bottom_left + var/turf/small_spot = get_step(run_loc_floor_bottom_left, EAST) + changed_turfs[large_spot] = large_spot.type + changed_turfs[small_spot] = small_spot.type + + var/turf/closed/mineral/large_wall = large_spot.ChangeTurf(/turf/closed/mineral) + large_wall.make_dig_site_wall(site, 1) + TEST_ASSERT_EQUAL(large_wall.mineralType, null, "a site wall kept ore") + TEST_ASSERT_EQUAL(large_wall.scan_state, "xenoarch_site", "a site wall has no scanner mark") + TEST_ASSERT(!ambient_ore_wall_ok(large_wall), "NPC miners would dig a site wall") + large_wall.gets_drilled() + var/obj/structure/xenoarch_boulder/boulder = locate() in large_spot + TEST_ASSERT_NOTNULL(boulder, "mining a large-find wall left no boulder") + TEST_ASSERT_EQUAL(site.large_left, 0, "the large find was not taken from the record") + TEST_ASSERT_EQUAL(length(site.loose), 1, "the cut boulder was not kept in the record") + var/datum/dig_boulder_record/kept = site.loose[1] + TEST_ASSERT_EQUAL(boulder.record, kept, "the boulder does not draw its record") + kept.dug = 40 + var/serial = kept.serial + qdel(boulder) + TEST_ASSERT(!QDELETED(kept), "a torn-down boulder deleted its record") + TEST_ASSERT_EQUAL(length(site.loose), 1, "a torn-down boulder left its site") + var/obj/structure/xenoarch_boulder/rebuilt = new(large_spot, kept, site) + TEST_ASSERT_EQUAL(rebuilt.record.serial, serial, "the rebuilt boulder has a new catalogue number") + TEST_ASSERT_EQUAL(rebuilt.record.dug, 40, "the rebuilt boulder lost its cut depth") + TEST_ASSERT_EQUAL(rebuilt.cut_stage(), 1, "40 cm cut should show the second stage") + qdel(rebuilt) + + var/turf/closed/mineral/small_wall = small_spot.ChangeTurf(/turf/closed/mineral) + small_wall.make_dig_site_wall(site, 2) + small_wall.gets_drilled() + var/obj/item/strange_rock/rock = locate() in small_spot + TEST_ASSERT_NOTNULL(rock, "mining a small-find wall left no strange rock") + TEST_ASSERT_EQUAL(rock?.band, 2, "the strange rock was not stamped with its site's band") + TEST_ASSERT_EQUAL(site.small_left, 0, "the small find was not taken from the record") + + // A flagged wall whose record ran dry gives nothing. + var/turf/closed/mineral/spent_wall = small_spot.ChangeTurf(/turf/closed/mineral) + spent_wall.make_dig_site_wall(site, 2) + spent_wall.gets_drilled() + var/count = 0 + for(var/obj/item/strange_rock/extra in small_spot) + count++ + TEST_ASSERT_EQUAL(count, 1, "an emptied site gave another rock") + +/// Brushed at the right depth with the right field, the find comes out whole, stamped and with the +/// boulder's number; cut past it, nothing comes out at all. +/datum/unit_test/voidcrew_xenoarch_boulder/Run() + var/obj/structure/xenoarch_boulder/boulder = allocate(/obj/structure/xenoarch_boulder) + var/datum/dig_boulder_record/record = boulder.record + // Green: no ambush can wake in a test. + record.band = 1 + record.find_type = /obj/machinery/artifact + record.target_depth = 30 + record.dug = 30 + record.stabilised = TRUE + var/obj/machinery/artifact/find = boulder.free_find(null) + TEST_ASSERT(istype(find), "a stabilised boulder at depth gave no artifact") + TEST_ASSERT(QDELETED(boulder), "the boulder outlived its find") + TEST_ASSERT_EQUAL(find?.origin_band, 1, "the find was not stamped with the boulder's band") + TEST_ASSERT_EQUAL(find?.serial, record.serial, "the find did not keep the boulder's catalogue number") + TEST_ASSERT(!find?.damaged, "a stabilised find came out damaged") + qdel(find) + + var/obj/structure/xenoarch_boulder/overcut = allocate(/obj/structure/xenoarch_boulder) + overcut.record.band = 1 + overcut.record.find_type = /obj/machinery/artifact + overcut.record.target_depth = 30 + overcut.record.dug = 28 + overcut.cut(5, null) + TEST_ASSERT(QDELETED(overcut), "a boulder cut past its find survived") + TEST_ASSERT_NULL(locate(/obj/machinery/artifact) in run_loc_floor_bottom_left, "a boulder cut past its find still gave an artifact") + + // Without the right field it either comes apart or comes out damaged, never whole. + for(var/i in 1 to 6) + var/obj/structure/xenoarch_boulder/loose = allocate(/obj/structure/xenoarch_boulder) + loose.record.band = 1 + loose.record.find_type = /obj/machinery/artifact + loose.record.target_depth = 25 + loose.record.dug = 25 + loose.record.stabilised = FALSE + var/obj/machinery/artifact/unheld = loose.free_find(null) + TEST_ASSERT(QDELETED(loose), "an unstabilised boulder survived being freed") + if(unheld) + TEST_ASSERT(unheld.damaged, "an unstabilised find came out whole") + qdel(unheld) + + // It shrinks by depth cut, never by depth left. + var/obj/structure/xenoarch_boulder/shrinking = allocate(/obj/structure/xenoarch_boulder) + shrinking.record.dug = 25 + TEST_ASSERT_EQUAL(shrinking.cut_stage(), 0, "25 cm cut should still show the first stage") + shrinking.record.dug = 150 + TEST_ASSERT_EQUAL(shrinking.cut_stage(), 3, "150 cm cut should show the last stage") + + // A find dug in another band keeps that band wherever it is freed. + var/obj/machinery/artifact/yellow = xenoarch_spawn_large_find(/obj/machinery/artifact, run_loc_floor_bottom_left, 2, TRUE, "Tau-1001") + TEST_ASSERT_EQUAL(yellow?.origin_band, 2, "a yellow find was not stamped yellow") + TEST_ASSERT_EQUAL(yellow?.serial, "Tau-1001", "a find did not take the catalogue number it was given") + TEST_ASSERT(yellow?.damaged, "a find freed damaged came out whole") + qdel(yellow) + +/// A strange rock frees a stamped, marked curio at depth and nothing past it. +/datum/unit_test/voidcrew_xenoarch_strange_rock/Run() + var/obj/item/strange_rock/rock = allocate(/obj/item/strange_rock, run_loc_floor_bottom_left, 2, "house") + TEST_ASSERT_EQUAL(rock.band, 2, "a yellow rock was not stamped yellow") + TEST_ASSERT(rock.tier >= 1 && rock.tier <= 3, "rock tier [rock.tier] out of range") + rock.find_type = /obj/item/xenoarch_curio/bowl + rock.target_depth = 10 + rock.dug = 10 + var/obj/item/xenoarch_curio/bowl = rock.free_find(null) + TEST_ASSERT(istype(bowl), "a rock at depth gave no curio") + TEST_ASSERT_EQUAL(bowl?.origin_band, 2, "the curio was not stamped with its rock's band") + TEST_ASSERT_EQUAL(xenoarch_curio_value(bowl), 80, "a bowl was not marked at the pottery price") + TEST_ASSERT_EQUAL(xenoarch_find_band(bowl), 2, "xenoarch_find_band() can't read a curio") + qdel(bowl) + + var/obj/item/xenoarch_curio/spawned = allocate(/obj/item/xenoarch_curio/shell) + TEST_ASSERT_NULL(xenoarch_find_band(spawned), "a curio that never came out of the ground reads as dug") + + var/obj/item/strange_rock/overcut = allocate(/obj/item/strange_rock, run_loc_floor_bottom_left, 1, "garden") + overcut.find_type = /obj/item/xenoarch_curio/shell + overcut.target_depth = 10 + overcut.dug = 11 + overcut.lose_find(null) + TEST_ASSERT(QDELETED(overcut), "a rock cut past its find survived") + var/count = 0 + for(var/obj/item/xenoarch_curio/shell/shell in run_loc_floor_bottom_left) + if(shell != spawned) + count++ + TEST_ASSERT_EQUAL(count, 0, "a rock cut past its find still gave a curio") + + // Every site kind and tier gives something real. + for(var/kind in list("garden", "animal", "house", "technical", "temple", "war")) + for(var/tier in 1 to 3) + var/find_type = xenoarch_small_find(kind, tier) + TEST_ASSERT(ispath(find_type, /atom/movable) || find_type == /datum/xenoarch_research_draw, "[kind] tier [tier] gives [find_type]") + +/// Large finds other than artifacts: shares by band, stamps, and what each one comes out as. +/datum/unit_test/voidcrew_xenoarch_large_finds/Run() + for(var/i in 1 to 400) + var/find_type = xenoarch_roll_large_find(1) + TEST_ASSERT(!ispath(find_type, /obj/vehicle/sealed/mecha), "a green site rolled an exosuit") + TEST_ASSERT(ispath(find_type, /atom/movable), "a green site rolled [find_type]") + + var/turf/spot = run_loc_floor_bottom_left + var/obj/machinery/power/charged_crystal/crystal = xenoarch_spawn_large_find(/obj/machinery/power/charged_crystal, spot, 3, TRUE) + TEST_ASSERT(istype(crystal), "no charged crystal came out") + TEST_ASSERT_EQUAL(crystal?.origin_band, 3, "the crystal was not stamped") + TEST_ASSERT_EQUAL(crystal?.charge_left, 27000, "a damaged crystal should hold half its charge") + TEST_ASSERT(!crystal?.can_run(), "an unwired, loose crystal would run") + crystal.wired = TRUE + crystal.set_anchored(TRUE) + TEST_ASSERT(!crystal.can_run(), "a crystal with no cable under it would run") + crystal.charge_left = 0 + TEST_ASSERT(crystal.is_dull(), "a spent crystal is not dull") + qdel(crystal) + + var/obj/machinery/artifact/bluespace_formation/formation = xenoarch_spawn_large_find(/obj/machinery/artifact/bluespace_formation, spot, 2, FALSE, "Sigma-1234") + TEST_ASSERT(istype(formation), "no formation came out") + TEST_ASSERT_EQUAL(formation?.origin_band, 2, "the formation was not stamped") + TEST_ASSERT_NULL(formation?.main_effect, "a formation rolled an artifact effect") + qdel(formation) + + var/obj/structure/closet/crate/zone_loot/research/case = xenoarch_spawn_large_find(/obj/structure/closet/crate/zone_loot/research, spot, 3) + TEST_ASSERT_EQUAL(case?.loot_zone, 3, "a sealed case was not tiered by where it was dug") + qdel(case) + + var/obj/vehicle/sealed/mecha/gygax/wreck = xenoarch_spawn_large_find(/obj/vehicle/sealed/mecha/gygax, spot, 3) + TEST_ASSERT(istype(wreck), "no exosuit came out") + TEST_ASSERT(wreck.get_integrity() <= wreck.max_integrity * 0.4, "the exosuit came out undamaged") + TEST_ASSERT(!wreck.cell || wreck.cell.charge <= wreck.cell.maxcharge * 0.2, "the exosuit came out with a full cell") + qdel(wreck) + +/// Every sprite state the dig code can ask for exists. +/datum/unit_test/voidcrew_xenoarch_dig_icons/Run() + var/site_icon = 'voidcrew/modules/xenoarch/icons/dig_site.dmi' + for(var/variant in 1 to 4) + for(var/stage in 0 to 3) + TEST_ASSERT(icon_exists(site_icon, "boulder[variant]_[stage]"), "missing boulder[variant]_[stage]") + TEST_ASSERT(icon_exists(site_icon, "boulder[variant]_[stage]_vein"), "missing boulder[variant]_[stage]_vein") + for(var/state in list("vein1", "vein2", "vein3", "stake_orange", "stake_red", "spoil1", "spoil2", "field", "holotag", "survey_pin")) + TEST_ASSERT(icon_exists(site_icon, state), "missing dig site state [state]") + var/tool_icon = 'voidcrew/modules/xenoarch/icons/dig_tools.dmi' + for(var/head in list(1, 2, 4, 6, 10)) + TEST_ASSERT(icon_exists(tool_icon, "hammer_[head]"), "missing hammer_[head]") + for(var/state in list("brush", "brush_quick", "depth_scanner", "depth_scanner_adv", "sampler", "sampler_full", "stabiliser", "stabiliser_lamp", "find_bag")) + TEST_ASSERT(icon_exists(tool_icon, state), "missing tool state [state]") + for(var/state in list("charged_crystal", "charged_crystal_active", "charged_crystal_dull", "charged_crystal_wires")) + TEST_ASSERT(icon_exists('voidcrew/modules/xenoarch/icons/dig_finds.dmi', state), "missing crystal state [state]") + for(var/state in list("spectrometer", "spectrometer_processing", "spectrometer_open")) + TEST_ASSERT(icon_exists('voidcrew/modules/xenoarch/icons/dig_machines.dmi', state), "missing spectrometer state [state]") + TEST_ASSERT(icon_exists('voidcrew/modules/xenoarch/icons/dig_scan.dmi', "xenoarch_site"), "missing scanner mark") + for(var/stage in 0 to 2) + TEST_ASSERT(icon_exists('voidcrew/modules/xenoarch/icons/curios.dmi', "strange_rock_[stage]"), "missing strange_rock_[stage]") + for(var/obj/item/xenoarch_curio/curio_type as anything in subtypesof(/obj/item/xenoarch_curio)) + var/obj/item/xenoarch_curio/curio = new curio_type(run_loc_floor_bottom_left) + for(var/state in curio.variants) + TEST_ASSERT(icon_exists(curio.icon, state), "[curio_type] has no sprite state [state]") + qdel(curio) diff --git a/voidcrew/modules/unit_tests/voidcrew_xenoarch_effects_polaris.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_effects_polaris.dm new file mode 100644 index 00000000000..0fd9b18a73f --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_effects_polaris.dm @@ -0,0 +1,373 @@ +// Xenoarchaeology tests: effects_polaris. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm: +// bands (ZONE_*): green 1, yellow 2, red 3 +// tiers: common 1, uncommon 2, rare 3, extreme 4 +// triggers: plasma 512 (the only one a test names) +// release methods: "touch", "aura", "pulse" + +/// The Polaris and VOREStation effects: type -> list(tier, minor, harvestable), from the design catalogue. +/proc/voidcrew_xenoarch_polaris_catalogue() + return list( + /datum/artifact_effect/extinguisher = list(1, TRUE, TRUE), + /datum/artifact_effect/animate = list(1, FALSE, FALSE), + /datum/artifact_effect/sweat = list(1, TRUE, TRUE), + /datum/artifact_effect/electric_field = list(2, FALSE, TRUE), + /datum/artifact_effect/bestow/fortify = list(2, FALSE, TRUE), + /datum/artifact_effect/bestow/faraday = list(2, FALSE, TRUE), + /datum/artifact_effect/bestow/sprint = list(2, FALSE, TRUE), + /datum/artifact_effect/bestow/berserk = list(2, FALSE, TRUE), + /datum/artifact_effect/disarm = list(2, FALSE, TRUE), + /datum/artifact_effect/forcefield = list(2, FALSE, FALSE), + /datum/artifact_effect/gaia = list(2, FALSE, TRUE), + /datum/artifact_effect/gas_vent/plasma = list(2, FALSE, FALSE), + /datum/artifact_effect/poltergeist = list(3, FALSE, TRUE), + /datum/artifact_effect/bestow/feysight = list(3, FALSE, TRUE), + /datum/artifact_effect/gas_vent/sleeping = list(3, FALSE, FALSE), + /datum/artifact_effect/life_drain = list(3, FALSE, TRUE), + /datum/artifact_effect/gravity_wave = list(4, FALSE, FALSE), + /datum/artifact_effect/spines = list(4, FALSE, FALSE), + /datum/artifact_effect/life_steal = list(4, FALSE, TRUE), + /datum/artifact_effect/resurrect = list(4, FALSE, FALSE), + ) + +/// Every Polaris effect is rollable with the catalogue's tier, minor and harvest flags, and rolls sane traits. +/datum/unit_test/voidcrew_xenoarch_polaris_catalogue/Run() + var/list/catalogue = voidcrew_xenoarch_polaris_catalogue() + var/list/rollable = artifact_effect_types() + TEST_ASSERT(!(/datum/artifact_effect/bestow in rollable), "the shared status-giving parent can roll") + TEST_ASSERT(!(/datum/artifact_effect/gas_vent in rollable), "the shared gas vent parent can roll") + for(var/effect_type in catalogue) + var/list/row = catalogue[effect_type] + TEST_ASSERT(effect_type in rollable, "[effect_type] can't roll") + var/label_count = 0 + var/datum/artifact_effect/probe = effect_type + for(var/datum/artifact_effect/other as anything in rollable) + if(initial(other.label_name) == initial(probe.label_name)) + label_count++ + TEST_ASSERT_EQUAL(label_count, 1, "[effect_type]'s label word is shared with another effect") + for(var/band in 1 to 3) + for(var/roll in 1 to 10) + var/datum/artifact_effect/effect = new effect_type(null, band) + TEST_ASSERT_EQUAL(effect.tier, row[1], "[effect_type] has the wrong tier") + TEST_ASSERT_EQUAL(effect.minor, row[2], "[effect_type] has the wrong minor flag") + TEST_ASSERT_EQUAL(effect.harvestable, row[3], "[effect_type] has the wrong harvest flag") + TEST_ASSERT(effect.release_method in effect.allowed_release_methods, "[effect_type] rolled a release it doesn't allow") + TEST_ASSERT(effect.energy_kind in effect.possible_kinds, "[effect_type] rolled a kind it doesn't allow") + TEST_ASSERT(effect.range >= 1 && effect.range <= 8, "[effect_type] rolled range [effect.range]") + TEST_ASSERT(effect.touch_cost <= effect.maximum_charges, "[effect_type] can never be touched off") + qdel(effect) + // Plasma air never wakes the plasma vent, or it would feed itself. + for(var/roll in 1 to 100) + var/datum/artifact_effect/gas_vent/plasma/vent = new(null, 3) + TEST_ASSERT(vent.trigger != 512, "the plasma vent rolled a plasma-air trigger") + qdel(vent) + var/datum/artifact_effect/spines/spines = new(null, 1) + TEST_ASSERT_EQUAL(spines.green_weight, 0.5, "spines are not halved in green") + qdel(spines) + +/// Every Polaris effect wakes, touches, runs a field and bursts on a real artifact without errors, +/// and leaves no force walls standing once it is gone. +/datum/unit_test/voidcrew_xenoarch_polaris_effects_run/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + var/turf/home = get_turf(find) + var/mob/living/carbon/human/consistent/tester = allocate(/mob/living/carbon/human/consistent, get_step(home, EAST)) + tester.mind_initialize() + allocate(/obj/item/crowbar, get_step(get_step(home, NORTH), NORTH)) + for(var/effect_type in voidcrew_xenoarch_polaris_catalogue()) + find.forceMove(home) + tester.forceMove(get_step(home, EAST)) + find.replace_effects(effect_type, null, 3) + var/datum/artifact_effect/effect = find.main_effect + TEST_ASSERT(effect, "[effect_type] did not attach to the artifact") + if(istype(effect, /datum/artifact_effect/gas_vent)) + var/datum/artifact_effect/gas_vent/vent = effect + vent.reserve = 0 // Venting is tested on its own, with the air put back afterwards. + effect.wake(1 MINUTES) + TEST_ASSERT(effect.activated, "[effect_type] did not wake") + effect.do_effect_touch(tester) + effect.do_effect_aura(2) + effect.do_effect_pulse(effect.maximum_charges) + effect.deactivate(quiet = TRUE) + tester.fully_heal(HEAL_ALL) + find.replace_effects(null, null) + for(var/obj/effect/forcefield/artifact/wall in range(4, home)) + TEST_ASSERT(!wall.density, "a force wall still stands after its effect is gone") + for(var/obj/effect/decal/cleanable/artifact_ooze/puddle in range(4, home)) + TEST_ASSERT(puddle.reagents?.total_volume <= 30, "an ooze puddle grew past a cupful") + +/** + * Harvested copies run from a battery item, usually in someone's hand (the utilizer). Every Polaris + * effect runs from such a holder through the public API (wake, touch, tick) and the raw hooks + * without errors, and the harmful ones work on whoever carries the battery too. A folder stands + * in for the battery: these tests must not depend on another part's types. + */ +/datum/unit_test/voidcrew_xenoarch_polaris_battery_holder/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + var/turf/home = get_turf(find) + var/turf/carrier_spot = locate(home.x + 2, home.y, home.z) + var/turf/target_spot = locate(home.x + 3, home.y, home.z) + var/mob/living/carbon/human/consistent/carrier = allocate(/mob/living/carbon/human/consistent, carrier_spot) + var/mob/living/carbon/human/consistent/target = allocate(/mob/living/carbon/human/consistent, target_spot) + carrier.mind_initialize() + target.mind_initialize() + var/obj/item/folder/battery = allocate(/obj/item/folder) + carrier.put_in_active_hand(battery) + TEST_ASSERT_EQUAL(artifact_effect_visible_source(battery), carrier, "a carried battery is not seen as coming from its carrier") + for(var/effect_type in voidcrew_xenoarch_polaris_catalogue()) + find.replace_effects(effect_type, null, 3) + var/datum/artifact_effect/copy = find.main_effect.make_harvest_copy(battery) + TEST_ASSERT_EQUAL(copy.holder, battery, "[effect_type]'s harvest copy is not held by the battery") + if(istype(copy, /datum/artifact_effect/gas_vent)) + var/datum/artifact_effect/gas_vent/vent = copy + vent.reserve = 0 + copy.wake(1 MINUTES) + copy.current_charge = copy.maximum_charges + copy.touch(target) + copy.current_charge = copy.maximum_charges + copy.tick(2) + copy.do_effect_touch(target) + copy.do_effect_aura(2) + copy.do_effect_pulse(copy.maximum_charges) + copy.deactivate(quiet = TRUE) + qdel(copy) + carrier.fully_heal(HEAL_ALL) + target.fully_heal(HEAL_ALL) + carrier.forceMove(carrier_spot) + target.forceMove(target_spot) + if(!carrier.is_holding(battery)) + carrier.put_in_active_hand(battery) + + // The harmful ones hit their carrier too. + find.replace_effects(/datum/artifact_effect/electric_field, /datum/artifact_effect/disarm, 3) + var/datum/artifact_effect/electric_field/field = find.main_effect.make_harvest_copy(battery) + var/datum/artifact_effect/disarm/pry = find.second_effect.make_harvest_copy(battery) + var/obj/item/crowbar/bar = allocate(/obj/item/crowbar) + carrier.put_in_inactive_hand(bar) + TEST_ASSERT(field.arc_to(carrier, 10, FALSE), "an electric field in a battery spared its own carrier") + carrier.fully_heal(HEAL_ALL) + carrier.swap_hand() + TEST_ASSERT(pry.pry(carrier), "a disarm battery spared its own carrier's hand") + TEST_ASSERT(!carrier.is_holding(bar), "the disarm battery did not make its carrier drop the crowbar") + qdel(field) + qdel(pry) + +/// Resurrect: three lives, then spent; refuses the long dead, minds that moved on, and the absent. +/datum/unit_test/voidcrew_xenoarch_resurrect/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/resurrect, null, 3) + var/datum/artifact_effect/resurrect/rite = find.main_effect + var/mob/living/carbon/human/consistent/patient = allocate(/mob/living/carbon/human/consistent, get_step(find, EAST)) + patient.mind_initialize() + for(var/life in 1 to 3) + patient.adjustBruteLoss(40) + patient.death() + TEST_ASSERT_EQUAL(patient.stat, DEAD, "the patient did not die (life [life])") + TEST_ASSERT_EQUAL(rite.raise_refusal(patient), "gone", "a body with no player to come back was offered a revival") + TEST_ASSERT(rite.raise(patient), "a fresh body was not raised (life [life])") + TEST_ASSERT(patient.stat != DEAD, "the patient is still dead after being raised (life [life])") + TEST_ASSERT_EQUAL(rite.uses_left, 3 - life, "a revival did not spend a use") + patient.death() + TEST_ASSERT_EQUAL(rite.raise_refusal(patient), "spent", "a spent artifact offered a fourth life") + TEST_ASSERT(!rite.raise(patient), "a spent artifact raised the dead") + TEST_ASSERT_EQUAL(patient.stat, DEAD, "a spent artifact brought the patient back") + + // A fresh artifact for the remaining rules. + find.replace_effects(/datum/artifact_effect/resurrect, null, 3) + rite = find.main_effect + patient.timeofdeath = world.time - 6 MINUTES + TEST_ASSERT_EQUAL(rite.raise_refusal(patient), "too late", "a body dead six minutes was offered a revival") + patient.timeofdeath = world.time + var/mob/living/carbon/human/consistent/clone = allocate(/mob/living/carbon/human/consistent, get_step(find, WEST)) + patient.mind.transfer_to(clone) + TEST_ASSERT_EQUAL(rite.raise_refusal(patient), "gone", "a body whose mind moved on was offered a revival") + clone.mind.transfer_to(patient) + ADD_TRAIT(patient, TRAIT_SUICIDED, "unit_test") + TEST_ASSERT_EQUAL(rite.raise_refusal(patient), "ruined", "a suicide was offered a revival") + REMOVE_TRAIT(patient, TRAIT_SUICIDED, "unit_test") + + // Its mending is capped like any artifact healing. + var/mob/living/carbon/human/consistent/wreck = allocate(/mob/living/carbon/human/consistent, get_step(find, NORTH)) + wreck.mind_initialize() + wreck.adjustBruteLoss(170) + wreck.death() + rite.raise(wreck) + TEST_ASSERT(wreck.getBruteLoss() >= 139.5, "resurrect mended past the artifact healing cap ([wreck.getBruteLoss()] brute left)") + +/// Life steal: never heals past the shared cap, and takes exactly what it gives. +/datum/unit_test/voidcrew_xenoarch_life_steal/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/life_steal, null, 3) + var/datum/artifact_effect/life_steal/thief = find.main_effect + thief.range = 3 + var/mob/living/carbon/human/consistent/user = allocate(/mob/living/carbon/human/consistent, get_step(find, EAST)) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent, get_step(find, WEST)) + TEST_ASSERT_EQUAL(thief.steal_for(user, 10), 0, "life steal healed an unhurt person") + TEST_ASSERT_EQUAL(victim.getBruteLoss() + victim.getFireLoss(), 0, "life steal hurt someone without healing anyone") + user.take_overall_damage(60, 0) + var/healed = 0 + for(var/i in 1 to 6) + healed += thief.steal_for(user, 10) + TEST_ASSERT(healed <= 30.5, "life steal healed past the artifact cap ([healed])") + TEST_ASSERT(healed >= 29.5, "life steal stopped short of the cap ([healed])") + var/lost = victim.getBruteLoss() + victim.getFireLoss() + TEST_ASSERT(abs(lost - healed) < 1, "life steal took [lost] but gave [healed]") + +/// The status effects do what they say while they last and leave nothing behind. +/datum/unit_test/voidcrew_xenoarch_polaris_status_effects/Run() + var/mob/living/carbon/human/consistent/tester = allocate(/mob/living/carbon/human/consistent) + + tester.apply_status_effect(/datum/status_effect/artifact/fortify, 30 SECONDS) + tester.apply_damage(20, BRUTE, BODY_ZONE_CHEST) + var/fortified_loss = tester.getBruteLoss() + TEST_ASSERT(fortified_loss > 15 && fortified_loss < 19, "fortified skin took [fortified_loss] from a 20 brute hit") + tester.remove_status_effect(/datum/status_effect/artifact/fortify) + tester.apply_damage(20, BRUTE, BODY_ZONE_CHEST) + TEST_ASSERT(tester.getBruteLoss() - fortified_loss > 19.5, "fortify outlived its status effect") + tester.fully_heal(HEAL_ALL) + + // Doses never stack past one dose, nor past the cap. + var/datum/status_effect/artifact/fortify/dose = tester.apply_status_effect(/datum/status_effect/artifact/fortify, 10 SECONDS) + tester.apply_status_effect(/datum/status_effect/artifact/fortify, 10 SECONDS) + TEST_ASSERT(dose.duration <= world.time + 10 SECONDS, "two fortify doses stacked") + tester.apply_status_effect(/datum/status_effect/artifact/fortify, 10 MINUTES) + TEST_ASSERT(dose.duration <= world.time + 90 SECONDS, "a fortify dose ran past its cap") + tester.remove_status_effect(/datum/status_effect/artifact/fortify) + + tester.apply_status_effect(/datum/status_effect/artifact/sprint, 30 SECONDS) + TEST_ASSERT(tester.has_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_sprint), "sprint did not speed anyone up") + tester.remove_status_effect(/datum/status_effect/artifact/sprint) + TEST_ASSERT(!tester.has_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_sprint), "sprint outlived its status effect") + + tester.apply_status_effect(/datum/status_effect/artifact/faraday, 30 SECONDS) + TEST_ASSERT(tester.emp_act(EMP_HEAVY) & EMP_PROTECT_SELF, "faraday did not stop an EMP") + tester.remove_status_effect(/datum/status_effect/artifact/faraday) + TEST_ASSERT(!(tester.emp_act(EMP_HEAVY) & EMP_PROTECT_SELF), "faraday outlived its status effect") + + tester.apply_status_effect(/datum/status_effect/artifact/feysight, 30 SECONDS) + TEST_ASSERT(HAS_TRAIT(tester, TRAIT_THERMAL_VISION), "feysight gave no sight through walls") + tester.remove_status_effect(/datum/status_effect/artifact/feysight) + TEST_ASSERT(!HAS_TRAIT(tester, TRAIT_THERMAL_VISION), "feysight outlived its status effect") + + tester.apply_status_effect(/datum/status_effect/artifact/berserk, 30 SECONDS) + TEST_ASSERT(HAS_TRAIT(tester, TRAIT_PERFECT_ATTACKER), "berserk did not take") + tester.remove_status_effect(/datum/status_effect/artifact/berserk) + TEST_ASSERT(!HAS_TRAIT(tester, TRAIT_PERFECT_ATTACKER), "berserk outlived its status effect") + TEST_ASSERT(tester.has_status_effect(/datum/status_effect/artifact/exhausted), "berserk ended without the crash") + tester.apply_status_effect(/datum/status_effect/artifact/berserk, 30 SECONDS) + TEST_ASSERT(!tester.has_status_effect(/datum/status_effect/artifact/berserk), "an exhausted person was enraged again") + tester.remove_status_effect(/datum/status_effect/artifact/exhausted) + TEST_ASSERT(!tester.has_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_exhausted), "exhaustion outlived its status effect") + +/// Gas vents: indoors they vent from a finite reserve, then run dry for good. +/datum/unit_test/voidcrew_xenoarch_gas_vent_reserve/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + var/turf/open/here = get_turf(find) + var/datum/gas_mixture/original = here.return_air().copy() + find.replace_effects(/datum/artifact_effect/gas_vent/plasma, null, 3) + var/datum/artifact_effect/gas_vent/plasma/vent = find.main_effect + vent.reserve = 10 + vent.max_pressure = 1000 + TEST_ASSERT_EQUAL(vent.vent(6), 6, "the plasma vent did not vent indoors") + TEST_ASSERT_EQUAL(vent.vent(6), 4, "the plasma vent vented past its reserve") + TEST_ASSERT_EQUAL(vent.vent(6), 0, "a dry plasma vent kept venting") + var/list/plasma = here.return_air().gases[/datum/gas/plasma] + TEST_ASSERT(plasma && plasma[MOLES] >= 9.5, "the vented plasma is not on the tile") + TEST_ASSERT(vent.is_spent(), "a dry plasma vent is not spent") + here.return_air().copy_from(original) + here.air_update_turf(FALSE, FALSE) + + // The plain gas vent holds a reserve too, under one gas contract (600 mol), and a harvest copy + // takes half of what is left rather than a fresh one. + find.replace_effects(/datum/artifact_effect/gas, null, 3) + var/datum/artifact_effect/gas/plain = find.main_effect + TEST_ASSERT(plain.reserve > 0 && plain.reserve < 600, "a gas vent rolled a reserve of [plain.reserve] mol") + plain.reserve = 100 + var/obj/item/anomaly_battery/battery = allocate(/obj/item/anomaly_battery) + var/datum/artifact_effect/gas/copy = plain.make_harvest_copy(battery) + TEST_ASSERT_EQUAL(copy.reserve + plain.reserve, 100, "a harvest copy made more gas than the vent held") + TEST_ASSERT_EQUAL(copy.gas_type, plain.gas_type, "a harvest copy vents a different gas") + qdel(copy) + plain.reserve = 5 + plain.max_pressure = 1000 + TEST_ASSERT(plain.vent(8), "the gas vent did not vent indoors") + TEST_ASSERT(!plain.vent(8), "a dry gas vent kept venting") + TEST_ASSERT(plain.is_spent(), "a dry gas vent is not spent") + here.return_air().copy_from(original) + here.air_update_turf(FALSE, FALSE) + +/// Animate never walks while bolted down, and follows someone when loose. +/datum/unit_test/voidcrew_xenoarch_animate/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/animate, null, 1) + var/datum/artifact_effect/animate/walker = find.main_effect + walker.range = 5 + var/turf/start = get_turf(find) + var/mob/living/carbon/human/consistent/quarry = allocate(/mob/living/carbon/human/consistent, locate(start.x + 3, start.y, start.z)) + quarry.mind_initialize() + find.set_anchored(TRUE) + walker.stalk() + TEST_ASSERT_EQUAL(get_turf(find), start, "a bolted artifact walked") + find.set_anchored(FALSE) + TEST_ASSERT(walker.stalk(), "a loose artifact did not follow someone in reach") + TEST_ASSERT(get_dist(find, quarry) < 3, "the artifact did not close in on its quarry") + +/// The gravity wave knocks people down but never throws them into space (or lava, or a chasm). +/datum/unit_test/voidcrew_xenoarch_gravity_wave_ledge/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/gravity_wave, null, 3) + var/datum/artifact_effect/gravity_wave/wave = find.main_effect + var/turf/start = get_turf(find) + var/mob/living/carbon/human/consistent/bystander = allocate(/mob/living/carbon/human/consistent, locate(start.x + 1, start.y, start.z)) + var/turf/ledge = locate(start.x + 3, start.y, start.z) + var/old_type = ledge.type + ledge.ChangeTurf(/turf/open/space/basic, flags = CHANGETURF_IGNORE_AIR) + TEST_ASSERT_EQUAL(wave.safe_distance(bystander, EAST, 5), 1, "the wave would throw someone into space") + TEST_ASSERT_EQUAL(wave.safe_distance(bystander, WEST, 1), 1, "the wave refused a safe throw") + ledge = locate(start.x + 3, start.y, start.z) + ledge.ChangeTurf(old_type, flags = CHANGETURF_IGNORE_AIR) + +/// The electric field only arcs to machines and to people holding something metal. +/datum/unit_test/voidcrew_xenoarch_electric_field/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/electric_field, null, 3) + var/datum/artifact_effect/electric_field/field = find.main_effect + var/mob/living/carbon/human/consistent/bystander = allocate(/mob/living/carbon/human/consistent, get_step(find, EAST)) + TEST_ASSERT(!field.arc_to(bystander, 10, FALSE), "the field arced to someone with empty hands") + TEST_ASSERT_EQUAL(bystander.getFireLoss(), 0, "an empty-handed bystander was burned") + var/obj/item/crowbar/bar = allocate(/obj/item/crowbar) + bystander.put_in_active_hand(bar) + TEST_ASSERT(field.arc_to(bystander, 10, FALSE), "the field did not arc to someone holding a crowbar") + TEST_ASSERT(bystander.getFireLoss() > 0, "the arc did not burn") + +/** + * Polaris effects on planet ground never give a planet turf private air: the gas vents, the + * extinguisher and the force walls. (A real flame writes the air itself, so none is lit here.) + * Uses the shared planet air room from voidcrew_planet_shared_air.dm. + */ +/datum/unit_test/voidcrew_planet_shared_air/xenoarch_polaris_effects/Run() + if(!planetary_atmos_shared_mix_enabled()) + return + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, center) + find.replace_effects(/datum/artifact_effect/gas_vent/plasma, /datum/artifact_effect/gas_vent/sleeping, 3) + TEST_ASSERT(room_is_pristine(), "placing an artifact gave the planet private air") + for(var/datum/artifact_effect/gas_vent/vent as anything in find.effects()) + vent.release_method = "aura" + vent.wake(1 MINUTES) + TEST_ASSERT_EQUAL(vent.vent(10), 0, "a gas vent vented into planet air") + vent.do_effect_touch(null) + vent.do_effect_pulse(50) + for(var/i in 1 to 3) + find.process(2) + TEST_ASSERT(room_is_pristine(), "a gas vent running on a planet gave it private air") + find.replace_effects(/datum/artifact_effect/extinguisher, /datum/artifact_effect/forcefield, 3) + var/datum/artifact_effect/extinguisher/snuffer = find.main_effect + snuffer.range = 2 + snuffer.do_effect_pulse(50) + snuffer.do_effect_aura(2) + var/datum/artifact_effect/forcefield/field = find.second_effect + field.ring_radius = 2 + field.raise_ring(10 SECONDS) + TEST_ASSERT(room_is_pristine(), "the extinguisher or force walls gave the planet private air") + field.drop_ring() diff --git a/voidcrew/modules/unit_tests/voidcrew_xenoarch_study.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_study.dm new file mode 100644 index 00000000000..8bb305fae4a --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_study.dm @@ -0,0 +1,235 @@ +// Xenoarchaeology tests: study. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm (see also the header of voidcrew_xenoarch_core.dm): +// bands (ZONE_*): green 1, yellow 2, red 3 +// tiers: common 1, uncommon 2, rare 3, extreme 4 +// triggers: touch 1, water 2, acid 4 +// research for a first analysis: 100 / 150 / 250 by band, x1.5 for rare or extreme + +/// A scan pad with an analyser beside it, ready for a find. +/datum/unit_test/voidcrew_xenoarch_study + abstract_type = /datum/unit_test/voidcrew_xenoarch_study + var/obj/machinery/artifact_scanpad/pad + var/obj/machinery/artifact_analyser/analyser + +/datum/unit_test/voidcrew_xenoarch_study/proc/build_bench() + pad = allocate(/obj/machinery/artifact_scanpad, run_loc_floor_bottom_left) + analyser = allocate(/obj/machinery/artifact_analyser, get_step(run_loc_floor_bottom_left, EAST)) + analyser.print_delay = 0 + analyser.find_pad() + +/// A yellow-band find with one known effect, standing on the pad. +/datum/unit_test/voidcrew_xenoarch_study/proc/place_find(band = 2) + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, pad.loc, band) + find.replace_effects(/datum/artifact_effect/heal, null, band) + return find + +/// Counts things of a type on a turf. +/datum/unit_test/voidcrew_xenoarch_study/proc/count_on(turf/where, path) + . = 0 + for(var/atom/movable/thing in where) + if(istype(thing, path)) + .++ + +/// The first full analysis of a dug find prints a report and pays research once, ever. +/datum/unit_test/voidcrew_xenoarch_study/research_once/Run() + build_bench() + TEST_ASSERT_EQUAL(analyser.pad, pad, "the analyser didn't find the pad beside it") + TEST_ASSERT_EQUAL(analyser.scan_time, 10 SECONDS, "stock parts should make a ten-second scan") + var/obj/machinery/artifact/find = place_find() + TEST_ASSERT_EQUAL(analyser.watched, find, "the analyser isn't watching the find on its pad") + var/turf/out = analyser.drop_location() + + TEST_ASSERT(analyser.start_scan(), "a scan didn't start") + TEST_ASSERT(find.is_being_used(), "the scan didn't lock the find") + analyser.finish_scan() + TEST_ASSERT(find.research_paid, "the first analysis didn't mark research paid") + TEST_ASSERT_NULL(find.locked_by, "finishing the scan didn't release the lock") + TEST_ASSERT_EQUAL(count_on(out, /obj/item/research_notes), 1, "the first analysis didn't print notes") + var/obj/item/research_notes/notes = locate() in out + TEST_ASSERT_EQUAL(notes.value, 150, "a yellow uncommon find pays 150") + + var/obj/item/paper/artifact_report/report = locate() in out + TEST_ASSERT_NOTNULL(report, "no report was printed") + var/text = report.get_raw_text() + TEST_ASSERT(findtext(text, find.serial), "the report doesn't name the serial") + TEST_ASSERT(findtext(text, find.main_effect.report_line()), "the report doesn't carry the report line") + TEST_ASSERT(findtext(report.name, find.serial), "the report isn't named for its find") + TEST_ASSERT_NOTNULL(analyser.reading, "the screen kept no reading") + + TEST_ASSERT(analyser.start_scan(), "a second scan didn't start") + analyser.finish_scan() + TEST_ASSERT_EQUAL(count_on(out, /obj/item/research_notes), 1, "a second analysis paid research again") + TEST_ASSERT_EQUAL(count_on(out, /obj/item/paper/artifact_report), 2, "a second analysis printed no report") + +/// A find that never came out of a dig site pays nothing, but still reads. +/datum/unit_test/voidcrew_xenoarch_study/undug_pays_nothing/Run() + build_bench() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, pad.loc) + find.replace_effects(/datum/artifact_effect/heal, null, null) + TEST_ASSERT(!find.is_dug(), "a find made without a band was stamped") + TEST_ASSERT(analyser.start_scan(), "a scan didn't start") + analyser.finish_scan() + TEST_ASSERT(!find.research_paid, "an undug find was marked paid") + TEST_ASSERT_EQUAL(count_on(analyser.drop_location(), /obj/item/research_notes), 0, "an undug find paid research") + TEST_ASSERT_EQUAL(count_on(analyser.drop_location(), /obj/item/paper/artifact_report), 1, "an undug find printed no report") + TEST_ASSERT_EQUAL(xenoarch_claim_analysis(find, analyser, null), 0, "claiming an undug find paid") + +/// Halting, losing the find, losing power or deleting the analyser always lets go of the lock. +/datum/unit_test/voidcrew_xenoarch_study/lock_release/Run() + build_bench() + var/obj/machinery/artifact/find = place_find() + + TEST_ASSERT(analyser.start_scan(), "a scan didn't start") + analyser.abort_scan("Scan halted.") + TEST_ASSERT_NULL(find.locked_by, "halting didn't release the lock") + TEST_ASSERT(!pad.beam_on, "halting left the beam on") + + TEST_ASSERT(analyser.start_scan(), "a scan didn't restart after a halt") + find.forceMove(get_step(pad.loc, NORTH)) + TEST_ASSERT_NULL(analyser.scan_target, "moving the find off the pad didn't stop the scan") + TEST_ASSERT_NULL(find.locked_by, "moving the find off the pad didn't release the lock") + TEST_ASSERT_NULL(analyser.watched, "the analyser kept watching a find that left the pad") + TEST_ASSERT(!find.research_paid, "an aborted scan paid research") + + find.forceMove(pad.loc) + TEST_ASSERT_EQUAL(analyser.watched, find, "the analyser didn't notice the find coming back") + TEST_ASSERT(analyser.start_scan(), "a scan didn't start on the returned find") + analyser.set_is_operational(FALSE) + TEST_ASSERT_NULL(find.locked_by, "losing power didn't release the lock") + analyser.set_is_operational(TRUE) + + TEST_ASSERT(analyser.start_scan(), "a scan didn't start after power came back") + qdel(analyser) + TEST_ASSERT_NULL(find.locked_by, "deleting the analyser mid-scan didn't release the lock") + TEST_ASSERT(!pad.beam_on, "deleting the analyser left the beam on") + +/// A find another machine holds can't be scanned until it lets go. +/datum/unit_test/voidcrew_xenoarch_study/lock_respected/Run() + build_bench() + var/obj/machinery/artifact/find = place_find() + var/obj/machinery/artifact_analyser/other = allocate(/obj/machinery/artifact_analyser, get_step(run_loc_floor_bottom_left, NORTHEAST)) + TEST_ASSERT(find.try_lock(other), "another machine couldn't take the lock") + TEST_ASSERT(!analyser.start_scan(), "a scan started on a find another machine holds") + find.release_lock(other) + TEST_ASSERT(analyser.start_scan(), "a scan didn't start once the other machine let go") + analyser.abort_scan() + +/// Deleting a find mid-scan stops the scan cleanly. +/datum/unit_test/voidcrew_xenoarch_study/find_deleted/Run() + build_bench() + var/obj/machinery/artifact/find = place_find() + TEST_ASSERT(analyser.start_scan(), "a scan didn't start") + qdel(find) + TEST_ASSERT_NULL(analyser.scan_target, "the scan outlived its find") + TEST_ASSERT_NULL(analyser.watched, "the analyser kept a deleted find") + TEST_ASSERT(!pad.beam_on, "the beam outlived the find") + +/// The tape records each stimulus and whether the find answered it. +/datum/unit_test/voidcrew_xenoarch_study/tape/Run() + build_bench() + var/obj/machinery/artifact/find = place_find() + find.main_effect.trigger = 2 // water + find.stimulate(4) // acid + find.stimulate(2) // water + var/list/texts = list() + for(var/list/line as anything in analyser.tape) + texts += line["text"] + TEST_ASSERT("Acid. No response." in texts, "the tape didn't record a stimulus that woke nothing") + TEST_ASSERT("Water. Response." in texts, "the tape didn't record a stimulus that woke the find") + var/before = length(analyser.tape) + find.stimulate(4) + find.stimulate(4) + TEST_ASSERT(length(analyser.tape) <= before + 1, "repeated stimuli each took a new line") + TEST_ASSERT(analyser.tear_tape(null), "the tape couldn't be torn off") + TEST_ASSERT(!length(analyser.tape), "tearing the tape left lines on it") + TEST_ASSERT_EQUAL(count_on(analyser.drop_location(), /obj/item/paper/artifact_tape), 1, "tearing the tape left no slip") + find.main_effect.deactivate(quiet = TRUE) + +/// The labeler takes only words from its lists, and a tag made from the right words reads as right. +/datum/unit_test/voidcrew_xenoarch_study/labeler/Run() + var/obj/item/artifact_labeler/labeler = allocate(/obj/item/artifact_labeler) + TEST_ASSERT_NULL(labeler.make_label(), "a blank labeler made a tag") + TEST_ASSERT(!labeler.set_word("effect", "Turns lead into gold"), "the labeler took a word it doesn't know") + TEST_ASSERT(!labeler.set_word("trigger", "Heals"), "the labeler took an effect word as a trigger") + TEST_ASSERT(!labeler.set_word("colour", "Heals"), "the labeler took a field it doesn't have") + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, run_loc_floor_bottom_left, 1) + find.replace_effects(/datum/artifact_effect/heal, null, 1) + TEST_ASSERT(labeler.set_word("effect", "Heals"), "the labeler refused an effect word") + TEST_ASSERT(labeler.set_word("trigger", artifact_trigger_name(find.main_effect.trigger)), "the labeler refused a trigger word") + TEST_ASSERT_NULL(labeler.make_label(), "a labeler with a blank line made a tag") + TEST_ASSERT(labeler.set_word("second", "None"), "the labeler refused None for the second line") + var/datum/artifact_label/tag = labeler.make_label() + TEST_ASSERT_NOTNULL(tag, "a full labeler made no tag") + find.apply_label(tag) + TEST_ASSERT_EQUAL(find.label_accuracy(), 1, "a tag with every word right didn't read as right") + TEST_ASSERT(labeler.set_word("second", "Light"), "the labeler refused an effect word for the second line") + find.apply_label(labeler.make_label()) + TEST_ASSERT_EQUAL(find.label_accuracy(), 0.8, "a wrong second line should cost a fifth") + +/// The three research nodes sit on the price ladder and unlock every study design. +/datum/unit_test/voidcrew_xenoarch_study_nodes/Run() + var/list/expected = list( + "xenoarchaeology" = list(40, list("xenoarch_analyser", "xenoarch_scanpad", "xenoarch_labeler")), + "xenoarch_excavation" = list(80, list()), + "xenoarch_exotic_particles" = list(120, list()), + ) + for(var/node_id in expected) + var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id) + TEST_ASSERT(node && node.id == node_id, "research node [node_id] is missing") + var/list/costs = node.research_costs + TEST_ASSERT_EQUAL(costs[TECHWEB_POINT_TYPE_GENERIC], expected[node_id][1], "[node_id] is off the price ladder") + for(var/design_id in expected[node_id][2]) + TEST_ASSERT_NOTNULL(SSresearch.techweb_designs[design_id], "design [design_id] is missing") + TEST_ASSERT(design_id in node.design_ids, "[node_id] doesn't unlock [design_id]") + TEST_ASSERT_EQUAL(SSresearch.techweb_node_by_id("xenoarchaeology").zone_permission, 0, "the analyser node needs no standing") + TEST_ASSERT_EQUAL(SSresearch.techweb_node_by_id("xenoarch_exotic_particles").zone_permission, 1, "the harvester node should need yellow standing (ZONE_PERMISSION_YELLOW)") + var/datum/design/board/analyser_board = SSresearch.techweb_designs["xenoarch_analyser"] + TEST_ASSERT_EQUAL(analyser_board.build_path, /obj/item/circuitboard/machine/artifact_analyser, "the analyser design prints the wrong board") + var/list/curio_points = SSresearch.techweb_point_items[/obj/item/relic/excavated] + TEST_ASSERT_EQUAL(curio_points?[TECHWEB_POINT_TYPE_GENERIC], 60, "the strange object pays no research in the destructive analyzer") + TEST_ASSERT_NULL(SSresearch.techweb_point_items[/obj/item/relic], "a strange object from maintenance pays research like a dug one") + // Every curio a dig can give pays something, and nothing pays more than the cheapest node. + for(var/curio_type in subtypesof(/obj/item/xenoarch_curio)) + var/list/points = SSresearch.techweb_point_items[curio_type] + var/value = points?[TECHWEB_POINT_TYPE_GENERIC] + TEST_ASSERT(value >= 20 && value <= 60, "[curio_type] pays [value || 0] research in the destructive analyzer") + +/** + * Every design the xenoarchaeology nodes list exists. The dig, use and trade parts define most of + * them, so this only passes once all the parts are together; a failure names the id to rename. + */ +/datum/unit_test/voidcrew_xenoarch_study_node_designs/Run() + var/list/expected = list( + "xenoarchaeology" = list("xenoarch_analyser", "xenoarch_scanpad", "xenoarch_labeler", "xenoarch_stabiliser", "xenoarch_spectrometer", "xenoarch_specimen_crate"), + "xenoarch_excavation" = list("xenoarch_scanner_advanced", "xenoarch_brush_quick"), + "xenoarch_exotic_particles" = list("xenoarch_harvester", "xenoarch_battery", "xenoarch_utilizer"), + ) + for(var/node_id in expected) + var/datum/techweb_node/node = SSresearch.techweb_node_by_id(node_id) + for(var/design_id in expected[node_id]) + TEST_ASSERT_NOTNULL(SSresearch.techweb_designs[design_id], "[node_id] lists design [design_id], which no part defines") + TEST_ASSERT(design_id in node?.design_ids, "[node_id] lost design [design_id]") + +/** + * Every xenoarchaeology design has exactly one way in: the hand kit from the autolathe at round + * start, or one research node. Nothing is both, and nothing sits in two nodes. + */ +/datum/unit_test/voidcrew_xenoarch_design_routes/Run() + var/list/node_count = list() + for(var/node_id in SSresearch.techweb_nodes) + var/datum/techweb_node/node = SSresearch.techweb_nodes[node_id] + for(var/design_id in node.design_ids) + node_count[design_id] = (node_count[design_id] || 0) + 1 + var/checked = 0 + for(var/design_id in SSresearch.techweb_designs) + if(!findtext(design_id, "xenoarch_", 1, 10)) + continue + var/datum/design/design = SSresearch.techweb_designs[design_id] + var/routes = node_count[design_id] || 0 + if(RND_CATEGORY_INITIAL in design.category) + routes++ + TEST_ASSERT_EQUAL(routes, 1, "design [design_id] has [routes] routes (nodes: [node_count[design_id] || 0])") + checked++ + TEST_ASSERT(checked >= 17, "only [checked] xenoarchaeology designs were found") diff --git a/voidcrew/modules/unit_tests/voidcrew_xenoarch_trade.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_trade.dm new file mode 100644 index 00000000000..1a46768f168 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_trade.dm @@ -0,0 +1,360 @@ +// Xenoarchaeology tests: trade. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm and the part-local defines in xenoarch/trade/: +// bands (ZONE_*): green 1, yellow 2, red 3 +// tiers: common 1, uncommon 2, rare 3, extreme 4 +// COMSIG_ARTIFACT_SOLD "artifact_sold" +// XENOARCH_FIND_DEMAND 3, XENOARCH_CURIO_DEMAND 6 +// buyer line keys "perfect", "close", "wrong", "blank", "live" +// checkpoint refusal for a loose find "xenoarch_loose_find" + +/// Shared helpers for the trade tests; runs nothing itself. +/datum/unit_test/voidcrew_xenoarch_trade + abstract_type = /datum/unit_test/voidcrew_xenoarch_trade + +/// A seller with a bank card in hand, the way the outpost ledger finds an account without a crew. +/datum/unit_test/voidcrew_xenoarch_trade/proc/make_seller(datum/bank_account/account) + var/mob/living/carbon/human/consistent/seller = allocate(/mob/living/carbon/human/consistent) + var/obj/item/card/id/advanced/card = allocate(/obj/item/card/id/advanced) + qdel(card.registered_account) + card.registered_account = account + seller.put_in_hands(card) + return seller + +/// Deletes the receipts and vouchers a sale left in hand or underfoot. +/datum/unit_test/voidcrew_xenoarch_trade/proc/tidy(mob/living/seller) + for(var/obj/item/paper/xenoarch_receipt/receipt in near_seller(seller)) + qdel(receipt) + for(var/obj/item/stack/trade_voucher/chits in near_seller(seller)) + qdel(chits) + +/// Everything the seller holds, plus everything at their feet. +/datum/unit_test/voidcrew_xenoarch_trade/proc/near_seller(mob/living/seller) + var/turf/feet = get_turf(seller) + return seller.get_all_contents() + feet.contents + +/// Barnaby, Boffin and Vex buy finds; Vex takes no curios; nobody else buys either. +/datum/unit_test/voidcrew_xenoarch_trade/buyers/Run() + var/list/expected = list( + /datum/outpost_shop/general = list(TRUE, TRUE), + /datum/outpost_shop/vendor/skunkworks = list(TRUE, TRUE), + /datum/outpost_shop/black_market = list(TRUE, FALSE), + /datum/outpost_shop/outfitter = list(FALSE, FALSE), + /datum/outpost_shop/vendor/dregs_bar = list(FALSE, FALSE), + ) + for(var/shop_type in expected) + var/datum/outpost_shop/shop = allocate(shop_type) + var/list/wants = expected[shop_type] + var/datum/shop_buyback/xenoarch_find/find_row = locate() in shop.buybacks + var/datum/shop_buyback/xenoarch_curio/curio_row = locate() in shop.buybacks + TEST_ASSERT_EQUAL(!!find_row, wants[1], "[shop_type] large-find row") + TEST_ASSERT_EQUAL(!!curio_row, wants[2], "[shop_type] curio row") + if(find_row) + TEST_ASSERT(find_row.buyer == shop.xenoarch_buyer, "[shop_type]'s find row has no buyer") + TEST_ASSERT_EQUAL(find_row.demand, 3, "[shop_type] wants the wrong number of large finds") + TEST_ASSERT_NULL(find_row.item_path, "[shop_type]'s find row has an item path, so Pike's ledger would sell finds remotely") + TEST_ASSERT(find_row.get_ui_icon(), "[shop_type]'s find row has no picture") + if(curio_row) + TEST_ASSERT_EQUAL(curio_row.demand, 6, "[shop_type] wants the wrong number of curios") + TEST_ASSERT(curio_row.get_ui_icon(), "[shop_type]'s curio row has no picture") + // A convoy tops the rows up like any other ledger row + if(find_row) + find_row.demand = 0 + shop.convoy_restock() + TEST_ASSERT(find_row.demand > 0, "[shop_type]'s find demand never comes back") + // Sarge buys nothing but points the way + var/datum/outpost_shop/outfitter/depot = allocate(/datum/outpost_shop/outfitter) + TEST_ASSERT_NOTNULL(depot.xenoarch_buyer, "Sarge has nothing to say about a find") + TEST_ASSERT(depot.xenoarch_buyer.line("notice"), "Sarge has nothing to say about a find") + TEST_ASSERT_EQUAL(xenoarch_credits_text(1125), "1,125 cr", "credit formatting") + TEST_ASSERT_EQUAL(xenoarch_credits_text(250), "250 cr", "credit formatting") + TEST_ASSERT_EQUAL(xenoarch_credits_text(1000000), "1,000,000 cr", "credit formatting") + +/// A sale pays the sale value once, takes the find, prints a receipt and tells the artifact. +/datum/unit_test/voidcrew_xenoarch_trade/sale + /// Arguments of the last COMSIG_ARTIFACT_SOLD seen + var/list/sold_args + +/datum/unit_test/voidcrew_xenoarch_trade/sale/proc/on_sold(datum/source, credits, vouchers, mob/seller) + SIGNAL_HANDLER + sold_args = list(credits, vouchers, seller) + +/datum/unit_test/voidcrew_xenoarch_trade/sale/Run() + var/datum/outpost_shop/general/shop = allocate(/datum/outpost_shop/general) + var/datum/shop_buyback/xenoarch_find/row = locate() in shop.buybacks + var/datum/bank_account/account = allocate(/datum/bank_account, "Xenoarch sale test", null, 1, FALSE) + var/mob/living/carbon/human/seller = make_seller(account) + + // Never dug: refused, nothing moves + var/obj/machinery/artifact/stray = allocate(/obj/machinery/artifact, get_step(seller, EAST)) + stray.replace_effects(/datum/artifact_effect/heal, null, 2) + TEST_ASSERT_EQUAL(row.settle(stray, seller, account, null), 0, "an undug find sold") + TEST_ASSERT(!QDELETED(stray), "an undug find was taken without pay") + TEST_ASSERT_EQUAL(account.account_balance, 0, "an undug find paid out") + TEST_ASSERT_EQUAL(row.demand, 3, "a refused sale used up demand") + qdel(stray) + + // Dug in yellow, labelled right: full price + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, get_step(seller, EAST), 2) + find.replace_effects(/datum/artifact_effect/heal, null, 2) + find.apply_label(new /datum/artifact_label("Heals", artifact_trigger_name(find.main_effect.trigger), "None")) + var/expected = artifact_sale_value(find) + TEST_ASSERT_EQUAL(expected, 675, "a perfectly labelled yellow uncommon find is not worth 675") + TEST_ASSERT(shop.xenoarch_buyer.closing_line(find) in shop.xenoarch_buyer.lines["perfect"], "Barnaby didn't praise a perfect label") + var/serial = find.serial + RegisterSignal(find, "artifact_sold", PROC_REF(on_sold)) + TEST_ASSERT_EQUAL(row.settle(find, seller, account, null), expected, "the sale paid the wrong amount") + TEST_ASSERT_EQUAL(account.account_balance, expected, "the account got the wrong amount") + TEST_ASSERT(QDELETED(find), "the sold find stayed in the world") + TEST_ASSERT_EQUAL(row.demand, 2, "a sale did not use up demand") + TEST_ASSERT_NOTNULL(sold_args, "COMSIG_ARTIFACT_SOLD was not sent") + TEST_ASSERT_EQUAL(sold_args[1], expected, "COMSIG_ARTIFACT_SOLD carried the wrong credits") + TEST_ASSERT_EQUAL(sold_args[2], 0, "Barnaby paid a voucher") + TEST_ASSERT_EQUAL(sold_args[3], seller, "COMSIG_ARTIFACT_SOLD named the wrong seller") + var/obj/item/paper/xenoarch_receipt/receipt = locate() in near_seller(seller) + TEST_ASSERT_NOTNULL(receipt, "no receipt was handed over") + TEST_ASSERT(findtext(receipt.name, serial), "the receipt doesn't name the find") + TEST_ASSERT(!(locate(/obj/item/stack/trade_voucher) in near_seller(seller)), "Barnaby handed over a voucher") + tidy(seller) + + // Selling it again is impossible: it is gone + TEST_ASSERT_EQUAL(row.settle(find, seller, account, null), 0, "a sold find sold twice") + TEST_ASSERT_EQUAL(account.account_balance, expected, "a second sale of one find paid") + + // Out of demand: refused + var/obj/machinery/artifact/late = allocate(/obj/machinery/artifact, get_step(seller, EAST), 1) + row.demand = 0 + TEST_ASSERT_EQUAL(row.settle(late, seller, account, null), 0, "a buyer with no demand left bought a find") + TEST_ASSERT(!QDELETED(late), "a refused find was taken") + + // No account: refused + row.demand = 3 + TEST_ASSERT_EQUAL(row.settle(late, seller, null, null), 0, "a find sold with nowhere to pay") + TEST_ASSERT(!QDELETED(late), "a find was taken with nowhere to pay") + +/// Vex pays one voucher on top for an extreme main effect, and only for that. +/datum/unit_test/voidcrew_xenoarch_trade/vex_voucher/Run() + var/datum/outpost_shop/black_market/shop = allocate(/datum/outpost_shop/black_market) + var/datum/shop_buyback/xenoarch_find/row = locate() in shop.buybacks + var/datum/bank_account/account = allocate(/datum/bank_account, "Xenoarch voucher test", null, 1, FALSE) + var/mob/living/carbon/human/seller = make_seller(account) + + var/obj/machinery/artifact/plain = allocate(/obj/machinery/artifact, get_step(seller, EAST), 3) + plain.replace_effects(/datum/artifact_effect/heal, null, 3) + TEST_ASSERT_EQUAL(shop.xenoarch_buyer.vouchers_for(plain), 0, "Vex pays a voucher for an uncommon find") + TEST_ASSERT(row.settle(plain, seller, account, null) > 0, "Vex refused a dug red find") + TEST_ASSERT(!(locate(/obj/item/stack/trade_voucher) in near_seller(seller)), "Vex handed over a voucher for an uncommon find") + tidy(seller) + + var/obj/machinery/artifact/live = allocate(/obj/machinery/artifact, get_step(seller, EAST), 3) + live.replace_effects(/datum/artifact_effect/tesla, null, 3) + TEST_ASSERT_EQUAL(live.main_effect.tier, 4, "the tesla effect is no longer extreme; pick another extreme effect for this test") + TEST_ASSERT(shop.xenoarch_buyer.closing_line(live) in shop.xenoarch_buyer.lines["live"], "Vex didn't remark on an extreme find") + var/before = account.account_balance + var/expected = artifact_sale_value(live) + TEST_ASSERT_EQUAL(expected, 560, "an unlabelled red extreme find is not worth 560") + TEST_ASSERT_EQUAL(row.settle(live, seller, account, null), expected, "Vex paid the wrong credits for an extreme find") + TEST_ASSERT_EQUAL(account.account_balance - before, expected, "the account got the wrong amount") + var/vouchers = 0 + for(var/obj/item/stack/trade_voucher/chits in near_seller(seller)) + vouchers += chits.amount + TEST_ASSERT_EQUAL(vouchers, 1, "Vex didn't pay exactly one voucher for an extreme find") + tidy(seller) + + // A spent extreme is a curio now: priced as common, and no voucher. + var/obj/machinery/artifact/dull = allocate(/obj/machinery/artifact, get_step(seller, EAST), 3) + dull.replace_effects(/datum/artifact_effect/resurrect, null, 3) + TEST_ASSERT_EQUAL(dull.main_effect.tier, 4, "the resurrect effect is no longer extreme") + TEST_ASSERT_EQUAL(artifact_sale_value(dull), 560, "a fresh unlabelled red resurrect find is not worth 560") + var/datum/artifact_effect/resurrect/lives = dull.main_effect + lives.uses_left = 0 + TEST_ASSERT(lives.is_spent(), "a resurrect with no lives left is not spent") + TEST_ASSERT_EQUAL(artifact_sale_value(dull), 140, "a spent red resurrect find kept its extreme price") + TEST_ASSERT_EQUAL(shop.xenoarch_buyer.vouchers_for(dull), 0, "Vex pays a voucher for a spent extreme find") + TEST_ASSERT(!(shop.xenoarch_buyer.closing_line(dull) in shop.xenoarch_buyer.lines["live"]), "Vex calls a spent find live") + TEST_ASSERT_EQUAL(row.settle(dull, seller, account, null), 140, "Vex paid the wrong credits for a spent find") + TEST_ASSERT(!(locate(/obj/item/stack/trade_voucher) in near_seller(seller)), "Vex handed over a voucher for a spent find") + tidy(seller) + + // The others pay credits only, extreme or not + var/datum/outpost_shop/general/halcyon = allocate(/datum/outpost_shop/general) + var/obj/machinery/artifact/other = allocate(/obj/machinery/artifact, get_step(seller, EAST), 3) + other.replace_effects(/datum/artifact_effect/tesla, null, 3) + TEST_ASSERT_EQUAL(halcyon.xenoarch_buyer.vouchers_for(other), 0, "Barnaby pays vouchers") + +/// Only a find the seller hauls counts: pulled loose, or in a shut crate they pull. +/datum/unit_test/voidcrew_xenoarch_trade/hauling/Run() + var/datum/outpost_shop/vendor/skunkworks/shop = allocate(/datum/outpost_shop/vendor/skunkworks) + var/datum/shop_buyback/xenoarch_find/row = locate() in shop.buybacks + var/datum/bank_account/account = allocate(/datum/bank_account, "Xenoarch hauling test", null, 1, FALSE) + var/mob/living/carbon/human/seller = make_seller(account) + var/turf/beside = get_step(seller, EAST) + + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, beside, 2) + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 0, "a find nobody pulls counted as hauled") + TEST_ASSERT_EQUAL(row.count_carried_units(seller), 0, "a find nobody pulls showed on the ledger") + seller.start_pulling(find) + TEST_ASSERT(seller.pulling == find, "the seller could not pull the find") + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 1, "a pulled find did not count") + seller.stop_pulling() + + var/obj/structure/closet/crate/specimen/crate = allocate(/obj/structure/closet/crate/specimen, beside) + if(!crate.opened) + crate.open() + TEST_ASSERT(crate.load_find(find, seller), "the find would not heave into the open crate") + TEST_ASSERT(find.loc == crate, "the find would not go in the crate") + TEST_ASSERT(!crate.opened, "the lid did not shut on the find") + TEST_ASSERT(findtext(jointext(crate.examine(seller), " "), find.serial), "the crate lid doesn't show the find's tag") + seller.start_pulling(crate) + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 1, "a find in a pulled crate did not count") + TEST_ASSERT_EQUAL(xenoarch_find_holder(find), crate, "a crated find's holder is not its crate") + crate.open() + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 0, "an open crate still counted as holding the find") + seller.stop_pulling() + + // A plain crate a find got into some other way (an exosuit clamp, an admin) counts too + var/obj/structure/closet/crate/plain = allocate(/obj/structure/closet/crate, beside) + if(plain.opened) + plain.close() + find.forceMove(plain) + seller.start_pulling(plain) + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 1, "a find in a pulled plain crate did not count") + seller.stop_pulling() + + // An undug find shows as hauled but never sellable + var/obj/machinery/artifact/stray = allocate(/obj/machinery/artifact, get_step(seller, NORTH)) + seller.start_pulling(stray) + TEST_ASSERT_EQUAL(length(xenoarch_hauled_finds(seller)), 1, "an undug pulled find wasn't hauled") + TEST_ASSERT_EQUAL(length(row.sellable_finds(seller)), 0, "an undug find was sellable") + TEST_ASSERT_NOTNULL(row.get_denial_reason(seller), "an undug find could be sold") + seller.stop_pulling() + + // The find row never matches an inventory item (plunder appraisal, Pike's ledger) + var/obj/item/relic/relic = allocate(/obj/item/relic) + TEST_ASSERT(!row.matches(relic), "the large-find row matched an item") + +/// Curios sell only with the dug mark, at their own price; only Boffin takes strange objects. +/datum/unit_test/voidcrew_xenoarch_trade/curios/Run() + var/datum/outpost_shop/general/halcyon = allocate(/datum/outpost_shop/general) + var/datum/outpost_shop/vendor/skunkworks/skunkworks = allocate(/datum/outpost_shop/vendor/skunkworks) + var/datum/shop_buyback/xenoarch_curio/barnaby_row = locate() in halcyon.buybacks + var/datum/shop_buyback/xenoarch_curio/boffin_row = locate() in skunkworks.buybacks + + var/obj/item/relic/maint_relic = allocate(/obj/item/relic) + TEST_ASSERT(!boffin_row.matches(maint_relic), "an unmarked strange object passed as a find") + var/obj/item/relic/dug_relic = allocate(/obj/item/relic) + TEST_ASSERT(xenoarch_mark_curio(dug_relic, 200), "could not mark a strange object as dug") + TEST_ASSERT(boffin_row.matches(dug_relic), "Boffin refused a dug strange object") + TEST_ASSERT(!barnaby_row.matches(dug_relic), "Barnaby took a strange object") + TEST_ASSERT(!xenoarch_mark_curio(maint_relic, 0), "a curio was marked as worth nothing") + + var/datum/bank_account/account = allocate(/datum/bank_account, "Xenoarch curio test", null, 1, FALSE) + var/mob/living/carbon/human/seller = make_seller(account) + var/obj/item/statuebust/shard = allocate(/obj/item/statuebust) + xenoarch_mark_curio(shard, 50) + seller.put_in_hands(shard) + TEST_ASSERT_EQUAL(barnaby_row.count_carried_units(seller), 1, "a carried curio didn't count") + TEST_ASSERT_NULL(barnaby_row.get_denial_reason(seller), "a carried curio was refused") + TEST_ASSERT(barnaby_row.try_sell(seller, null), "a curio didn't sell") + TEST_ASSERT_EQUAL(account.account_balance, 50, "a curio paid the wrong amount") + TEST_ASSERT(QDELETED(shard), "a sold curio stayed in hand") + TEST_ASSERT_EQUAL(barnaby_row.demand, 5, "a curio sale did not use up demand") + TEST_ASSERT(!barnaby_row.try_sell(seller, null), "a curio sold that wasn't there") + + // The whole join: a curio brushed out of a strange rock is marked, sells at its class price, and + // pays research once in a destructive analyzer. + var/obj/item/strange_rock/rock = allocate(/obj/item/strange_rock, get_turf(seller), 1, "house") + rock.find_type = /obj/item/xenoarch_curio/urn + rock.target_depth = 10 + rock.dug = 10 + var/obj/item/xenoarch_curio/urn = rock.free_find(null) + TEST_ASSERT(istype(urn), "a strange rock at depth gave no curio") + TEST_ASSERT(barnaby_row.matches(urn), "Barnaby refused a curio dug out of a strange rock") + var/list/urn_points = techweb_item_point_check(urn) + TEST_ASSERT_EQUAL(urn_points?[TECHWEB_POINT_TYPE_GENERIC], 30, "a dug urn pays the wrong research") + seller.put_in_hands(urn) + var/before = account.account_balance + TEST_ASSERT(barnaby_row.try_sell(seller, null), "a dug curio didn't sell") + TEST_ASSERT_EQUAL(account.account_balance - before, 80, "a dug urn paid the wrong amount") + + var/obj/item/strange_rock/relic_rock = allocate(/obj/item/strange_rock, get_turf(seller), 2, "technical") + relic_rock.find_type = /obj/item/relic/excavated + relic_rock.target_depth = 10 + relic_rock.dug = 10 + var/obj/item/relic/excavated/oddity = relic_rock.free_find(null) + TEST_ASSERT(istype(oddity), "a strange rock at depth gave no strange object") + TEST_ASSERT(boffin_row.matches(oddity), "Boffin refused a dug strange object") + TEST_ASSERT(!barnaby_row.matches(oddity), "Barnaby took a dug strange object") + qdel(oddity) + +/// A large find gets into a specimen crate the way a crew would: pushed onto the open crate and the +/// lid shut, or heaved in. Never two to a crate, never into a shut one, never into a plain crate. +/datum/unit_test/voidcrew_xenoarch_trade/crating/Run() + var/turf/start = run_loc_floor_bottom_left + var/turf/crate_spot = get_step(start, EAST) + var/turf/plain_spot = get_step(start, NORTH) + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, start, 1) + var/obj/structure/closet/crate/specimen/crate = allocate(/obj/structure/closet/crate/specimen, crate_spot) + if(crate.opened) + crate.close() + TEST_ASSERT(!find.Move(crate_spot, EAST), "a find was pushed onto a shut crate") + TEST_ASSERT_EQUAL(find.loc, start, "a find ended up on a shut crate") + TEST_ASSERT(!crate.load_find(find), "a find was heaved into a shut crate") + + crate.open() + TEST_ASSERT(find.Move(crate_spot, EAST), "a find could not be pushed onto the open specimen crate") + TEST_ASSERT(crate.close(), "the crate would not shut on a find") + TEST_ASSERT_EQUAL(find.loc, crate, "shutting the lid did not take the find in") + TEST_ASSERT(find.suppressed, "a crated find was not held still") + + // Opened again, the find sits in the crate; a second find has no room by either path. + crate.open() + TEST_ASSERT_EQUAL(find.loc, crate_spot, "opening the crate did not leave the find in it") + var/obj/machinery/artifact/other = allocate(/obj/machinery/artifact, start, 1) + TEST_ASSERT(!other.Move(crate_spot, EAST), "two finds were pushed into one crate") + TEST_ASSERT(!crate.load_find(other), "two finds were heaved into one crate") + + // Bolted finds don't go anywhere. + find.forceMove(get_step(crate_spot, EAST)) + other.set_anchored(TRUE) + TEST_ASSERT(!crate.load_find(other), "a bolted find was heaved into a crate") + other.set_anchored(FALSE) + TEST_ASSERT(crate.load_find(other), "a loose find beside the open crate would not heave in") + TEST_ASSERT_EQUAL(other.loc, crate, "a heaved find is not in the crate") + + // A plain crate takes no large find. + var/obj/structure/closet/crate/plain = allocate(/obj/structure/closet/crate, plain_spot) + if(!plain.opened) + plain.open() + var/obj/machinery/artifact/third = allocate(/obj/machinery/artifact, start, 1) + TEST_ASSERT(!third.Move(plain_spot, NORTH), "a find was pushed into an open plain crate") + +/// The checkpoint turns back a loose find, lets a crated one through, and never stops one leaving. +/datum/unit_test/voidcrew_xenoarch_trade/checkpoint/Run() + var/datum/outpost_checkpoint/checkpoint = allocate(/datum/outpost_checkpoint) + var/turf/chamber = run_loc_floor_bottom_left + checkpoint.chamber_turfs = list(chamber) + TEST_ASSERT_EQUAL(length(checkpoint.inspect_chamber()), 0, "an empty chamber refused something") + + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, chamber, 1) + var/list/refused = checkpoint.inspect_chamber() + TEST_ASSERT_EQUAL(refused[find], "xenoarch_loose_find", "a loose find walked through the checkpoint") + TEST_ASSERT(checkpoint.refusing_only_loose_finds(), "a loose find read as something else") + + checkpoint.exit_request = TRUE + var/list/leaving = checkpoint.inspect_chamber() + TEST_ASSERT(!leaving[find], "a find was stopped on its way out") + checkpoint.exit_request = FALSE + + var/obj/structure/closet/crate/specimen/crate = allocate(/obj/structure/closet/crate/specimen, chamber) + if(!crate.opened) + crate.open() + TEST_ASSERT(crate.load_find(find), "the find would not heave into the open crate") + TEST_ASSERT_EQUAL(length(checkpoint.inspect_chamber()), 0, "a crated find was turned back") + + var/datum/outpost_shop/vendor/checkpoint/halcyon/desk = allocate(/datum/outpost_shop/vendor/checkpoint/halcyon) + TEST_ASSERT(desk.get_line("xenoarch_loose_find") in desk.xenoarch_loose_lines, "Hollis has nothing to say about a loose find") + TEST_ASSERT(desk.get_line("checkpoint_pass"), "Hollis lost his ordinary lines") + var/obj/machinery/outpost_checkpoint_sensor/sensor = allocate(/obj/machinery/outpost_checkpoint_sensor) + TEST_ASSERT(sensor.machine_line("xenoarch_loose_find"), "the wall scanner has nothing to say about a loose find") diff --git a/voidcrew/modules/unit_tests/voidcrew_xenoarch_use.dm b/voidcrew/modules/unit_tests/voidcrew_xenoarch_use.dm new file mode 100644 index 00000000000..cf88b2b70ab --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_xenoarch_use.dm @@ -0,0 +1,250 @@ +// Xenoarchaeology tests: use. +// +// Test files compile before voidcrew/_DEFINES, so the values below are literals. They mirror +// voidcrew/_DEFINES/xenoarch.dm and the harvester's readout keys: +// ARTIFACT_MAX_HARVESTS 3, ARTIFACT_BATTERY_CAPACITY 200, ARTIFACT_HARVEST_DRAW_RATE 2.5, +// ARTIFACT_UTILIZER_DRAIN 0.5, ARTIFACT_UTILIZER_PULSE_FEED 1, ARTIFACT_UTILIZER_TOUCH_COST 20, +// ARTIFACT_AURA_COST_PER_SECOND 1.5, COMSIG_ARTIFACT_HARVESTED "artifact_harvested", +// release methods "touch", "aura", "pulse"; bands green 1, yellow 2, red 3. +// readout: "ready", "quiet", "tangled", "unfit", "spent", "busy", "mismatch". + +/// A battery fills only from a harvest, only from one source at a time, and a copy of it is empty. +/datum/unit_test/voidcrew_xenoarch_battery/Run() + var/obj/item/anomaly_battery/battery = allocate(/obj/item/anomaly_battery) + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/heal, /datum/artifact_effect/light, 2) + var/datum/artifact_effect/heal = find.main_effect + var/datum/artifact_effect/light = find.second_effect + + TEST_ASSERT_EQUAL(battery.stored_charge, 0, "a new battery came charged") + TEST_ASSERT_EQUAL(battery.add_charge(50), 0, "a battery holding nothing took charge") + TEST_ASSERT(battery.can_take(heal), "an empty battery refused an effect") + + battery.load_from(heal, find.serial) + TEST_ASSERT(istype(battery.held_effect, /datum/artifact_effect/heal), "the battery does not hold a copy of the effect") + TEST_ASSERT(battery.held_effect != heal, "the battery holds the artifact's own effect, not a copy") + TEST_ASSERT_EQUAL(battery.held_effect.holder, battery, "the copy's holder is not the battery") + TEST_ASSERT_EQUAL(battery.source_serial, find.serial, "the battery was not stamped with the find's serial") + TEST_ASSERT_EQUAL(battery.add_charge(250), 200, "a battery took more than its capacity") + TEST_ASSERT(battery.is_full(), "a battery at capacity is not full") + TEST_ASSERT_EQUAL(battery.charge_level(), 100, "a full battery's gauge") + TEST_ASSERT(!battery.can_take(heal), "a full battery took more") + battery.use_charge(199) + TEST_ASSERT_EQUAL(battery.charge_level(), 25, "any charge at all should show a quarter on the gauge") + TEST_ASSERT(battery.can_take(heal), "a part-charged battery refused a top-up from its own source") + TEST_ASSERT(!battery.can_take(light), "a part-charged battery took a second effect") + battery.use_charge(5) + TEST_ASSERT_EQUAL(battery.stored_charge, 0, "spending more than it held left charge behind") + TEST_ASSERT(battery.can_take(light), "an empty battery refused a new effect") + + battery.add_charge(80) + battery.purge() + TEST_ASSERT_EQUAL(battery.stored_charge, 0, "a purged battery kept charge") + TEST_ASSERT_NULL(battery.held_effect, "a purged battery kept its effect") + TEST_ASSERT_NULL(battery.source_serial, "a purged battery kept its stamp") + + // Machines that copy an item (the experimentor) make a new one from its type: always empty. + battery.load_from(heal, find.serial) + battery.add_charge(200) + var/obj/item/anomaly_battery/copy = allocate(battery.type) + TEST_ASSERT_EQUAL(copy.stored_charge, 0, "a battery built from its type came charged") + TEST_ASSERT_NULL(copy.held_effect, "a battery built from its type came holding an effect") + +/// The harvester: the harvest cap, when a harvest is spent, the lock, refusals and cleanup. +/datum/unit_test/voidcrew_xenoarch_harvest + var/harvest_signals = 0 + +/datum/unit_test/voidcrew_xenoarch_harvest/proc/on_harvested(datum/source, datum/artifact_effect/effect, mob/user) + SIGNAL_HANDLER + harvest_signals++ + +/datum/unit_test/voidcrew_xenoarch_harvest/Run() + var/obj/machinery/artifact_harvester/harvester = allocate(/obj/machinery/artifact_harvester) + harvester.set_machine_stat(NONE) + TEST_ASSERT(harvester.is_operational, "the harvester is not operational in the test room") + var/turf/beside = locate(harvester.x + 1, harvester.y, harvester.z) + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact, beside, 2) + find.replace_effects(/datum/artifact_effect/heal, null, 2) + RegisterSignal(find, "artifact_harvested", PROC_REF(on_harvested)) + var/price_before = artifact_sale_value(find) + + TEST_ASSERT(!harvester.start_draw(), "it drew with no battery") + var/obj/item/anomaly_battery/battery = allocate(/obj/item/anomaly_battery) + battery.forceMove(harvester) + harvester.battery = battery + + TEST_ASSERT_EQUAL(harvester.find_source(), find, "it did not find the artifact beside it") + TEST_ASSERT_EQUAL(harvester.source_state(find), "quiet", "a sleeping find did not read as quiet") + TEST_ASSERT(!harvester.start_draw(), "it drew from a sleeping find") + + find.main_effect.wake(10 MINUTES) + TEST_ASSERT_EQUAL(harvester.source_state(find), "ready", "an awake, harvestable find did not read as ready") + TEST_ASSERT(harvester.start_draw(), "it would not draw from a ready find") + TEST_ASSERT(harvester.drawing, "it is not drawing") + TEST_ASSERT_EQUAL(find.locked_by?.resolve(), harvester, "it did not lock the find") + TEST_ASSERT_EQUAL(find.harvests_left, 3, "a harvest was spent before any charge arrived") + + harvester.process(2) + TEST_ASSERT_EQUAL(battery.stored_charge, 5, "two seconds on tier-1 parts should draw 5 charge") + TEST_ASSERT_EQUAL(find.harvests_left, 2, "the first charge did not spend a harvest") + TEST_ASSERT_EQUAL(harvest_signals, 1, "the harvest signal was not sent once") + harvester.process(2) + TEST_ASSERT_EQUAL(find.harvests_left, 2, "one draw spent two harvests") + for(var/i in 1 to 50) + if(!harvester.drawing) + break + harvester.process(2) + TEST_ASSERT(!harvester.drawing, "it never finished filling the battery") + TEST_ASSERT(battery.is_full(), "it stopped before the battery was full") + TEST_ASSERT(!find.is_being_used(), "it kept the find locked after finishing") + TEST_ASSERT(istype(battery.held_effect, /datum/artifact_effect/heal), "the battery does not hold the drawn effect") + TEST_ASSERT(artifact_sale_value(find) < price_before, "a harvest did not lower the find's price") + TEST_ASSERT_EQUAL(harvest_signals, 1, "one full draw sent more than one harvest signal") + TEST_ASSERT(!harvester.start_draw(), "it drew into a full battery") + + // Stopping before any charge arrives costs nothing; stopping after costs the harvest. + harvester.purge_battery() + TEST_ASSERT_EQUAL(battery.stored_charge, 0, "purging left charge in the battery") + TEST_ASSERT(harvester.start_draw(), "it would not draw into a purged battery") + harvester.stop_draw() + TEST_ASSERT_EQUAL(find.harvests_left, 2, "a draw stopped before any charge spent a harvest") + TEST_ASSERT(!find.is_being_used(), "a stopped draw kept the find locked") + TEST_ASSERT(harvester.start_draw(), "it would not start again") + harvester.process(2) + harvester.stop_draw() + TEST_ASSERT_EQUAL(find.harvests_left, 1, "a draw stopped after charge arrived did not spend its harvest") + TEST_ASSERT_EQUAL(battery.stored_charge, 5, "a stopped draw lost the charge it had drawn") + + // A part-charged battery only tops up from the effect it holds. + find.main_effect.deactivate(quiet = TRUE) + find.replace_effects(/datum/artifact_effect/heal, /datum/artifact_effect/light, 2) + find.second_effect.wake(10 MINUTES) + TEST_ASSERT_EQUAL(harvester.source_state(find), "mismatch", "a battery holding another effect read as ready") + TEST_ASSERT(!harvester.start_draw(), "a part-charged battery took a second effect") + find.main_effect.wake(10 MINUTES) + TEST_ASSERT_EQUAL(harvester.source_state(find), "tangled", "two awake effects did not read as tangled") + TEST_ASSERT(!harvester.start_draw(), "it drew with two effects awake") + find.second_effect.deactivate(quiet = TRUE) + find.main_effect.harvestable = FALSE + TEST_ASSERT_EQUAL(harvester.source_state(find), "unfit", "an unharvestable effect did not read as unfit") + TEST_ASSERT(!harvester.start_draw(), "it drew an unharvestable effect") + find.main_effect.harvestable = TRUE + harvester.purge_battery() + + // Someone else's lock, and a spent find. + var/datum/other_locker = new + TEST_ASSERT(find.try_lock(other_locker), "could not lock the find for the test") + TEST_ASSERT_EQUAL(harvester.source_state(find), "busy", "a find locked by another machine did not read as busy") + TEST_ASSERT(!harvester.start_draw(), "it drew from a find another machine held") + find.release_lock(other_locker) + qdel(other_locker) + find.harvests_left = 0 + TEST_ASSERT_EQUAL(harvester.source_state(find), "spent", "a find with no harvests left did not read as spent") + TEST_ASSERT(!harvester.start_draw(), "it drew past the harvest cap") + find.harvests_left = 1 + + // Hauling the find away mid-draw stops it and lets go. + TEST_ASSERT(harvester.start_draw(), "it would not draw from the last harvest") + find.forceMove(run_loc_floor_top_right) + harvester.process(2) + TEST_ASSERT(!harvester.drawing, "it kept drawing from a find out of reach") + TEST_ASSERT(!find.is_being_used(), "it kept a find out of reach locked") + TEST_ASSERT_EQUAL(find.harvests_left, 1, "a draw that never reached charge spent a harvest") + + // Deleting it mid-draw releases the find; ejecting hands the battery out. + find.forceMove(beside) + TEST_ASSERT(harvester.start_draw(), "it would not draw again") + harvester.process(2) + TEST_ASSERT_EQUAL(find.harvests_left, 0, "the last harvest was not spent") + harvester.stop_draw() + TEST_ASSERT(harvester.eject_battery(), "it would not eject its battery") + TEST_ASSERT_NULL(harvester.battery, "it kept a reference to the ejected battery") + TEST_ASSERT(!(battery in harvester.component_parts), "the battery counts as a part of the machine, so ship saves would keep it") + battery.forceMove(harvester) + harvester.battery = battery + find.harvests_left = 1 + harvester.purge_battery() + TEST_ASSERT(harvester.start_draw(), "it would not draw before deletion") + qdel(harvester) + TEST_ASSERT(!find.is_being_used(), "a deleted harvester kept the find locked") + TEST_ASSERT(QDELETED(battery), "a deleted harvester left its battery in nullspace") + UnregisterSignal(find, "artifact_harvested") + +/// The utilizer: field drain, healing through the shared cap, bursts, contact uses and cleanup. +/datum/unit_test/voidcrew_xenoarch_utilizer/Run() + var/obj/machinery/artifact/find = allocate(/obj/machinery/artifact) + find.replace_effects(/datum/artifact_effect/heal, null, 2) + find.main_effect.release_method = "aura" + find.main_effect.range = 3 + var/obj/item/anomaly_battery/battery = allocate(/obj/item/anomaly_battery) + battery.load_from(find.main_effect, find.serial) + battery.add_charge(200) + find.moveToNullspace() + + var/obj/item/anomaly_utilizer/utilizer = allocate(/obj/item/anomaly_utilizer) + TEST_ASSERT(!utilizer.switch_on(), "it switched on with no battery") + battery.forceMove(utilizer) + utilizer.battery = battery + var/datum/artifact_effect/effect = battery.held_effect + + var/mob/living/carbon/human/consistent/patient = allocate(/mob/living/carbon/human/consistent) + patient.adjustBruteLoss(50) + var/damage_before = patient.getBruteLoss() + patient.getFireLoss() + + TEST_ASSERT(utilizer.switch_on(), "it would not switch on") + TEST_ASSERT(effect.activated, "switching on did not wake the battery's effect") + utilizer.process(2) + TEST_ASSERT_EQUAL(battery.stored_charge, 199, "a field should cost 0.5 charge a second") + for(var/i in 1 to 60) + utilizer.process(2) + var/healed = damage_before - (patient.getBruteLoss() + patient.getFireLoss()) + TEST_ASSERT(healed > 0, "a heal field healed nobody") + TEST_ASSERT(healed <= 30.1, "a heal field healed [healed], past the shared cap") + TEST_ASSERT(effect.activated, "the field lapsed while switched on") + + // Running dry switches it off. + battery.stored_charge = 0.5 + utilizer.process(2) + TEST_ASSERT(!utilizer.emitting, "it kept running on an empty battery") + TEST_ASSERT(!effect.activated, "its effect stayed awake after it went dark") + TEST_ASSERT(!utilizer.switch_on(), "it switched on with an empty battery") + + // Bursts build up at the utilizer's own rate and let go when full. + battery.stored_charge = 200 + effect.release_method = "pulse" + effect.maximum_charges = 6 + effect.current_charge = 0 + TEST_ASSERT(utilizer.switch_on(), "it would not switch on for bursts") + utilizer.process(2) + TEST_ASSERT_EQUAL(effect.current_charge, 2, "bursts should build at 1 charge a second") + utilizer.process(2) + utilizer.process(2) + TEST_ASSERT_EQUAL(effect.current_charge, 0, "a full store did not let go") + utilizer.switch_off() + + // Contact: one use per press, paid from the battery, and nothing while switched off. + var/mob/living/carbon/human/consistent/holder = allocate(/mob/living/carbon/human/consistent) + effect.release_method = "touch" + TEST_ASSERT_EQUAL(utilizer.interact_with_atom(patient, holder), NONE, "a switched-off utilizer acted on contact") + TEST_ASSERT(utilizer.switch_on(holder), "it would not switch on for contact") + var/charge_before = battery.stored_charge + utilizer.process(2) + TEST_ASSERT_EQUAL(battery.stored_charge, charge_before, "a contact effect drained while waiting") + TEST_ASSERT_EQUAL(utilizer.interact_with_atom(patient, holder), ITEM_INTERACT_SUCCESS, "pressing it to someone did nothing") + TEST_ASSERT_EQUAL(battery.stored_charge, charge_before - 20, "a contact use should cost 20 charge") + TEST_ASSERT_EQUAL(effect.get_responsible(), holder, "the person pressing it does not answer for it") + TEST_ASSERT_EQUAL(utilizer.interact_with_atom(find, holder), NONE, "it acted on contact with an object") + + // Ejecting while running switches it off; deleting it takes the battery with it. + TEST_ASSERT(utilizer.eject_battery(holder), "it would not eject its battery") + TEST_ASSERT(!utilizer.emitting, "it kept running with its battery out") + TEST_ASSERT(!effect.activated, "the battery's effect stayed awake out of the utilizer") + TEST_ASSERT_NULL(utilizer.battery, "it kept a reference to the ejected battery") + if(battery.loc == holder) + holder.transferItemToLoc(battery, utilizer, force = TRUE) + else + battery.forceMove(utilizer) + utilizer.battery = battery + TEST_ASSERT(utilizer.switch_on(holder), "it would not switch on again") + qdel(utilizer) + TEST_ASSERT(QDELETED(battery), "a deleted utilizer left its battery behind") diff --git a/voidcrew/modules/unit_tests/voidcrew_zone_research.dm b/voidcrew/modules/unit_tests/voidcrew_zone_research.dm index 70533966073..599cddb5597 100644 --- a/voidcrew/modules/unit_tests/voidcrew_zone_research.dm +++ b/voidcrew/modules/unit_tests/voidcrew_zone_research.dm @@ -123,6 +123,7 @@ /datum/techweb_node/nanite_remotes = 1, /datum/techweb_node/restricted_tech = 2, /datum/techweb_node/desynchronization = 2, + /datum/techweb_node/xenoarch_exotic_particles = 1, ) var/gated = 0 for(var/node_id in SSresearch.techweb_nodes) @@ -131,7 +132,7 @@ if(node.zone_permission) gated++ TEST_ASSERT_EQUAL(gated, length(expected), "The direct-research gate covers the wrong number of nodes") - TEST_ASSERT_EQUAL(gated, 45, "The direct-research gate must cover exactly forty-five nodes") + TEST_ASSERT_EQUAL(gated, 46, "The direct-research gate must cover exactly forty-six nodes") TEST_ASSERT_EQUAL(SSresearch.techweb_node_by_id("nanite_military").type, /datum/techweb_node/nanite_combat, "Military nanites changed id") /// Gated gear left the open nodes it used to share, and only sits on its new node. diff --git a/voidcrew/modules/xenoarch/core/artifact.dm b/voidcrew/modules/xenoarch/core/artifact.dm new file mode 100644 index 00000000000..02b38852dc4 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact.dm @@ -0,0 +1,500 @@ +/** + * # Large alien artifact + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/artifacts/artifact_machine.dm, + * reworked for Voidcrew: + * - Effects roll by the band the find was dug in (tier odds and strength), and the find is + * stamped with that band, a catalogue serial, and later a crew's label. + * - A stimulus wakes a matching effect for a while (ARTIFACT_WAKE_MIN to _MAX); level triggers + * (heat, cold, plasma or CO2 in the air, someone nearby) hold it awake while they last. + * Oxygen and nitrogen triggers are gone. Air is read with return_air_readonly(), so an idle + * artifact never gives a planet turf its own private air. + * - It does nothing off a turf (crated, carried in a mech) or inside a trader outpost. + * - Anyone can bolt it down with a wrench, except inside a trader outpost. + * - Scan and harvest machines lock it through try_lock()/release_lock(); a lock frees itself + * when its holder is deleted or after ARTIFACT_LOCK_TIMEOUT (Nova's halt never unlocked it). + * - Smashing it lets harmful effects off in one last burst, never helpful ones, and an admin + * delete or planet unload does nothing at all. + * + * Looks, sounds and examine text are in artifact_appearance.dm. + */ +/obj/machinery/artifact + name = "alien artifact" + desc = "A large object of no make you recognise." + icon = 'voidcrew/modules/xenoarch/icons/artifacts.dmi' + icon_state = "pylon" + density = TRUE + anchored = FALSE + use_power = NO_POWER_USE + // No UI and no power: a hand on it is a touch, nothing else. + interaction_flags_atom = NONE + interaction_flags_machine = INTERACT_MACHINE_OFFLINE + max_integrity = 1000 + resistance_flags = LAVA_PROOF | FIRE_PROOF | ACID_PROOF + + /// ZONE_* it was dug in, or null if it never came out of the ground. Price and research read this. + var/origin_band + /// Catalogue number, such as "Kappa-4412" + var/serial + /// The label a crew stuck on it, if any + var/datum/artifact_label/label + /// Harvests a harvester may still drain from it + var/harvests_left = ARTIFACT_MAX_HARVESTS + /// Its first full analysis has paid research points. Stays with the artifact whichever crew holds it. + var/research_paid = FALSE + /// Came out of the rock unstabilised. Sells for less. + var/damaged = FALSE + /// The effect it is named and priced for + var/datum/artifact_effect/main_effect + /// A minor second effect, or null + var/datum/artifact_effect/second_effect + /// Rolls its own effects on Initialize. Finds that are not true artifacts turn this off. + var/rolls_effects = TRUE + + /// How long one contact stimulus keeps an effect awake; rolled once per artifact + var/wake_duration = ARTIFACT_WAKE_MIN + /// Whoever last woke, struck, splashed or hauled it. Logged for any harm it does. + var/datum/weakref/last_disturbed_by + /// Last time a touch counted, so hauling and bumping count once per ARTIFACT_TOUCH_COOLDOWN + var/last_touch_time = 0 + /// Effects are held asleep: it is off a turf or inside a trader outpost + var/suppressed = FALSE + + /// The scan or harvest machine using it, if any + var/datum/weakref/locked_by + /// world.time the lock lapses if never released + var/lock_expires = 0 + +/obj/machinery/artifact/Initialize(mapload, band) + . = ..() + serial = xenoarch_new_serial() + wake_duration = rand(ARTIFACT_WAKE_MIN, ARTIFACT_WAKE_MAX) + setup_shape() + if(rolls_effects) + roll_effects(band) + if(!isnull(band)) + stamp_origin(band) + suppressed = is_suppressed() + update_activity_visuals() + +/obj/machinery/artifact/Destroy() + locked_by = null + last_disturbed_by = null + clear_activity_visuals() + QDEL_NULL(main_effect) + QDEL_NULL(second_effect) + QDEL_NULL(label) + return ..() + +/// Both effects, skipping a missing second. +/obj/machinery/artifact/proc/effects() + . = list() + if(main_effect) + . += main_effect + if(second_effect) + . += second_effect + +/// Any effect awake. +/obj/machinery/artifact/proc/is_active() + return main_effect?.activated || second_effect?.activated + +// ===== Rolling ===== + +/// Rolls a main effect from the band's tier odds and, half the time, a minor second effect. +/obj/machinery/artifact/proc/roll_effects(band) + var/main_type = xenoarch_pick_effect_type(xenoarch_roll_tier(band), band) + var/second_type + if(main_type && prob(ARTIFACT_SECOND_EFFECT_CHANCE)) + second_type = xenoarch_pick_effect_type(null, band, minor_only = TRUE, exclude = main_type) + replace_effects(main_type, second_type, band) + +/// Swaps both effects for new ones of the given types (second may be null). For rolling, tests and admins. +/obj/machinery/artifact/proc/replace_effects(main_type, second_type, band) + QDEL_NULL(main_effect) + QDEL_NULL(second_effect) + if(main_type) + main_effect = new main_type(src, band) + if(second_type) + second_effect = new second_type(src, band) + update_activity_visuals(force = TRUE) + +// ===== Seams read by other parts ===== + +/// Whether it came out of a dig site. Buyers refuse anything else. +/obj/machinery/artifact/proc/is_dug() + return !isnull(origin_band) + +/// How many harvests have been drained from it. +/obj/machinery/artifact/proc/harvests_taken() + return clamp(ARTIFACT_MAX_HARVESTS - harvests_left, 0, ARTIFACT_MAX_HARVESTS) + +/// 0 to 1: how right its label is. 0 with no label. +/obj/machinery/artifact/proc/label_accuracy() + if(!label || !main_effect) + return 0 + . = 0 + if(label.effect_name == main_effect.label_name) + . += ARTIFACT_LABEL_SHARE_EFFECT + if(label.trigger_name == artifact_trigger_name(main_effect.trigger)) + . += ARTIFACT_LABEL_SHARE_TRIGGER + var/second_truth = second_effect ? second_effect.label_name : ARTIFACT_LABEL_NONE + if(label.second_name == second_truth) + . += ARTIFACT_LABEL_SHARE_SECOND + +/// Sticks a new label on, replacing any old one. +/obj/machinery/artifact/proc/apply_label(datum/artifact_label/new_label, mob/user) + if(label && label != new_label) + QDEL_NULL(label) + label = new_label + SEND_SIGNAL(src, COMSIG_ARTIFACT_LABEL_CHANGED, new_label, user) + update_appearance() + +/// Scrapes the label off. +/obj/machinery/artifact/proc/remove_label(mob/user) + if(!label) + return FALSE + QDEL_NULL(label) + SEND_SIGNAL(src, COMSIG_ARTIFACT_LABEL_CHANGED, null, user) + update_appearance() + return TRUE + +/// Marks it as dug in `band`. Only the first stamp counts. +/obj/machinery/artifact/proc/stamp_origin(band) + if(!isnull(origin_band)) + return FALSE + origin_band = XENOARCH_BAND_INDEX(band) + SEND_SIGNAL(src, COMSIG_ARTIFACT_STAMPED, origin_band) + return TRUE + +// ===== Scan and harvest lock ===== + +/** + * Claims it for a scan or harvest. Fails while another live machine holds it. The lock frees + * itself when its holder is deleted or after `duration`, so a crashed or halted scan can never + * lock an artifact for good. + */ +/obj/machinery/artifact/proc/try_lock(datum/locker, duration = ARTIFACT_LOCK_TIMEOUT) + if(!locker) + return FALSE + if(is_being_used() && locked_by.resolve() != locker) + return FALSE + locked_by = WEAKREF(locker) + lock_expires = world.time + duration + return TRUE + +/// Frees the lock. With a `locker`, only if that is who holds it. +/obj/machinery/artifact/proc/release_lock(datum/locker) + if(!locked_by) + return FALSE + var/datum/holder = locked_by.resolve() + if(locker && holder && holder != locker) + return FALSE + locked_by = null + lock_expires = 0 + return TRUE + +/// Whether a live machine holds the lock (Nova's being_used). +/obj/machinery/artifact/proc/is_being_used() + if(!locked_by) + return FALSE + var/datum/holder = locked_by.resolve() + if(QDELETED(holder) || world.time >= lock_expires) + locked_by = null + lock_expires = 0 + return FALSE + return TRUE + +// ===== Stimuli ===== + +/// Remembers who set it off, for the combat log. +/obj/machinery/artifact/proc/note_disturbance(mob/user) + if(ismob(user)) + last_disturbed_by = WEAKREF(user) + +/** + * A stimulus reached it. Wakes every effect whose trigger matches. + * Returns TRUE if anything matched. + */ +/obj/machinery/artifact/proc/stimulate(trigger, mob/user) + if(suppressed || QDELETED(src)) + return FALSE + note_disturbance(user) + var/woke = FALSE + for(var/datum/artifact_effect/effect as anything in effects()) + if(effect.trigger == trigger) + effect.wake(wake_duration) + woke = TRUE + SEND_SIGNAL(src, COMSIG_ARTIFACT_STIMULATED, trigger, user, woke) + return woke + +/// Wakes every effect a bitfield of triggers matches. +/obj/machinery/artifact/proc/stimulate_all(triggers, mob/user) + . = FALSE + for(var/trigger in ARTIFACT_ALL_TRIGGERS) + if(triggers & trigger) + . = stimulate(trigger, user) || . + +/** + * Someone laid a hand on it, or brushed it (bumped, hauled). A bare or non-latex hand wakes + * touch effects; any touch lets an awake contact effect act on them. + */ +/obj/machinery/artifact/proc/touched_by(mob/living/user, accidental = FALSE) + if(!isliving(user)) + return + if(accidental && world.time < last_touch_time + ARTIFACT_TOUCH_COOLDOWN) + return + last_touch_time = world.time + if(!accidental) + to_chat(user, span_notice("You run your hand over [src].")) + if(artifact_touch_counts(user)) + stimulate(ARTIFACT_TRIGGER_TOUCH, user) + else + note_disturbance(user) + if(suppressed) + return + for(var/datum/artifact_effect/effect as anything in effects()) + if(accidental && prob(50)) + continue + effect.touch(user) + +/obj/machinery/artifact/attack_hand(mob/living/user, list/modifiers) + . = ..() + if(. || !user.Adjacent(src)) + return + touched_by(user) + return TRUE + +/obj/machinery/artifact/attack_robot(mob/user) + if(!user.Adjacent(src)) + return ..() + touched_by(user) + return TRUE + +/obj/machinery/artifact/attack_paw(mob/living/user, list/modifiers) + if(!user.Adjacent(src)) + return ..() + touched_by(user) + return TRUE + +/obj/machinery/artifact/Bumped(atom/movable/bumped_atom) + . = ..() + if(isliving(bumped_atom)) + touched_by(bumped_atom, accidental = TRUE) + +/obj/machinery/artifact/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE) + . = ..() + refresh_suppression() + // Hauling it counts as touching it (Nova did this through Move() and Bumped()). + if(isliving(pulledby)) + touched_by(pulledby, accidental = TRUE) + +/obj/machinery/artifact/attacked_by(obj/item/attacking_item, mob/living/user, list/modifiers, list/attack_modifiers) + note_disturbance(user) + . = ..() + if(QDELETED(src)) + return + if(attacking_item.force > 0) + stimulate(ARTIFACT_TRIGGER_IMPACT, user) + if(artifact_tool_is_energetic(attacking_item)) + stimulate(ARTIFACT_TRIGGER_ENERGY, user) + if(attacking_item.get_temperature() > ARTIFACT_HEAT_TOOL_KELVIN) + stimulate(ARTIFACT_TRIGGER_HEAT, user) + +/obj/machinery/artifact/hitby(atom/movable/hit_by, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum) + var/mob/thrower = throwingdatum?.get_thrower() + note_disturbance(thrower) + . = ..() + if(QDELETED(src)) + return + var/hard_enough = isliving(hit_by) + if(isobj(hit_by)) + var/obj/thrown_object = hit_by + hard_enough = thrown_object.throwforce >= ARTIFACT_IMPACT_THROWFORCE + if(hard_enough) + stimulate(ARTIFACT_TRIGGER_IMPACT, thrower) + +/obj/machinery/artifact/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit = FALSE) + var/mob/firer = hitting_projectile.firer + note_disturbance(firer) + . = ..() + if(QDELETED(src)) + return + if(hitting_projectile.armor_flag == LASER || hitting_projectile.armor_flag == ENERGY) + stimulate(ARTIFACT_TRIGGER_ENERGY, firer) + else if(hitting_projectile.damage > 0) + stimulate(ARTIFACT_TRIGGER_IMPACT, firer) + +/obj/machinery/artifact/take_damage(damage_amount, damage_type = BRUTE, damage_flag = "", sound_effect = TRUE, attack_dir, armour_penetration = 0) + . = ..() + if(QDELETED(src)) + return + // Hits with a known culprit are handled where they land; these are fires, blasts and arcs. + switch(damage_flag) + if(FIRE) + stimulate(ARTIFACT_TRIGGER_HEAT) + if(ENERGY, LASER) + stimulate(ARTIFACT_TRIGGER_ENERGY) + if(BOMB) + stimulate(ARTIFACT_TRIGGER_IMPACT) + stimulate(ARTIFACT_TRIGGER_HEAT) + +/obj/machinery/artifact/emp_act(severity) + . = ..() + if(!(. & EMP_PROTECT_SELF)) + stimulate(ARTIFACT_TRIGGER_ENERGY) + +/obj/machinery/artifact/fire_act(exposed_temperature, exposed_volume) + . = ..() + if(exposed_temperature > ARTIFACT_HEAT_AIR_KELVIN) + stimulate(ARTIFACT_TRIGGER_HEAT) + +/obj/machinery/artifact/expose_reagents(list/reagents, datum/reagents/source, methods = TOUCH, volume_modifier = 1, show_message = TRUE) + . = ..() + if(. & COMPONENT_NO_EXPOSE_REAGENTS) + return + stimulate_all(artifact_reagent_triggers(reagents)) + +/obj/machinery/artifact/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(is_reagent_container(tool) && tool.is_drainable()) + return splash_with(tool, user) + if(artifact_tool_is_energetic(tool)) + user.visible_message( + span_notice("[user] presses [tool] against [src]."), + span_notice("You press [tool] against [src]."), + ) + playsound(src, 'sound/effects/sparks/sparks1.ogg', 40, TRUE) + stimulate(ARTIFACT_TRIGGER_ENERGY, user) + if(tool.get_temperature() > ARTIFACT_HEAT_TOOL_KELVIN) + stimulate(ARTIFACT_TRIGGER_HEAT, user) + return ITEM_INTERACT_SUCCESS + if(tool.get_temperature() > ARTIFACT_HEAT_TOOL_KELVIN) + return heat_with(tool, user) + return NONE + +/obj/machinery/artifact/welder_act(mob/living/user, obj/item/tool) + if(tool.get_temperature() <= ARTIFACT_HEAT_TOOL_KELVIN) + return NONE + return heat_with(tool, user) + +/// Holds a hot tool to it. +/obj/machinery/artifact/proc/heat_with(obj/item/tool, mob/living/user) + user.visible_message( + span_notice("[user] holds [tool] to [src]."), + span_notice("You hold [tool] to [src] until the surface ticks with heat."), + ) + playsound(src, 'sound/items/tools/welder.ogg', 30, TRUE) + stimulate(ARTIFACT_TRIGGER_HEAT, user) + return ITEM_INTERACT_SUCCESS + +/// Splashes a little of an open container over it. +/obj/machinery/artifact/proc/splash_with(obj/item/container, mob/living/user) + var/datum/reagents/held = container.reagents + if(!held?.total_volume) + balloon_alert(user, "empty!") + return ITEM_INTERACT_BLOCKING + note_disturbance(user) + var/amount = min(held.total_volume, 10) + user.visible_message( + span_notice("[user] splashes [src] with the contents of [container]."), + span_notice("You splash [src] with [container]."), + ) + playsound(src, 'sound/effects/slosh.ogg', 25, TRUE) + held.expose(src, TOUCH, amount / held.total_volume) + held.remove_all(amount) + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact/wrench_act(mob/living/user, obj/item/tool) + if(istype(get_area(src), /area/voidcrew/trader_outpost)) + balloon_alert(user, "the deck won't take bolts!") + return ITEM_INTERACT_BLOCKING + if(default_unfasten_wrench(user, tool, 4 SECONDS) == SUCCESSFUL_UNFASTEN) + playsound(src, 'sound/machines/clockcult/integration_cog_install.ogg', 30, TRUE) + return ITEM_INTERACT_SUCCESS + +/// Whether a tool counts as electrical contact: a live stun baton or a lit energy blade. +/proc/artifact_tool_is_energetic(obj/item/tool) + if(istype(tool, /obj/item/melee/baton/security)) + var/obj/item/melee/baton/security/baton = tool + return baton.active + if(istype(tool, /obj/item/melee/energy)) + return HAS_TRAIT(tool, TRAIT_TRANSFORM_ACTIVE) + return FALSE + +// ===== Processing ===== + +/obj/machinery/artifact/process(seconds_per_tick) + for(var/datum/artifact_effect/effect as anything in effects()) + effect.recharge(seconds_per_tick) + if(refresh_suppression()) + return + check_level_triggers() + for(var/datum/artifact_effect/effect as anything in effects()) + effect.tick(seconds_per_tick) + +/// Off a turf, or inside a trader outpost, it does nothing at all. +/obj/machinery/artifact/proc/is_suppressed() + return !isturf(loc) || is_trader_outpost_protected(src) + +/// Re-reads suppression; puts everything to sleep when it starts. Returns TRUE while suppressed. +/obj/machinery/artifact/proc/refresh_suppression() + var/now_suppressed = is_suppressed() + if(now_suppressed == suppressed) + return suppressed + suppressed = now_suppressed + if(suppressed) + // A crate lid or an outpost's dampers: it goes still without a show. + for(var/datum/artifact_effect/effect as anything in effects()) + effect.deactivate(quiet = !isturf(loc)) + update_activity_visuals() + return suppressed + +/** + * Air and proximity triggers. Reads the tile's air without materializing it: a planet turf + * still on its shared mix stays on it. + */ +/obj/machinery/artifact/proc/check_level_triggers() + var/wanted = NONE + for(var/datum/artifact_effect/effect as anything in effects()) + if(effect.trigger & ARTIFACT_TRIGGERS_LEVEL) + wanted |= effect.trigger + if(!wanted) + return + var/met = NONE + if(wanted & ARTIFACT_TRIGGERS_AIR) + var/turf/here = get_turf(src) + var/datum/gas_mixture/air = here?.return_air_readonly() + if(air) + if(air.temperature > ARTIFACT_HEAT_AIR_KELVIN) + met |= ARTIFACT_TRIGGER_HEAT + if(air.temperature < ARTIFACT_COLD_AIR_KELVIN) + met |= ARTIFACT_TRIGGER_COLD + var/list/gases = air.gases + if(gases[/datum/gas/plasma]?[MOLES] >= ARTIFACT_GAS_TRIGGER_MOLES) + met |= ARTIFACT_TRIGGER_PLASMA + if(gases[/datum/gas/carbon_dioxide]?[MOLES] >= ARTIFACT_GAS_TRIGGER_MOLES) + met |= ARTIFACT_TRIGGER_CO2 + if(wanted & ARTIFACT_TRIGGER_PROXIMITY) + for(var/mob/living/nearby in view(ARTIFACT_PROXIMITY_RANGE, src)) + if(nearby.stat != DEAD) + met |= ARTIFACT_TRIGGER_PROXIMITY + break + if(!met) + return + for(var/datum/artifact_effect/effect as anything in effects()) + if(effect.trigger & met) + effect.wake(ARTIFACT_LEVEL_LINGER) + +// ===== Destruction ===== + +/obj/machinery/artifact/atom_destruction(damage_flag) + var/mob/culprit = last_disturbed_by?.resolve() + visible_message( + span_danger("[src] cracks apart with a sound like a bell breaking!"), + blind_message = span_hear("You hear something ring and shatter."), + ) + playsound(src, 'sound/effects/glass/glassbr3.ogg', 70, TRUE) + if(!suppressed) + log_game("Artifact [serial] ([main_effect?.log_name]) was smashed at [AREACOORD(src)][culprit ? " after [key_name(culprit)] disturbed it" : ""].") + for(var/datum/artifact_effect/effect as anything in effects()) + effect.do_effect_destroy() + return ..() diff --git a/voidcrew/modules/xenoarch/core/artifact_appearance.dm b/voidcrew/modules/xenoarch/core/artifact_appearance.dm new file mode 100644 index 00000000000..347790a2883 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_appearance.dm @@ -0,0 +1,389 @@ +/** + * # Artifact looks, sounds and examine text + * + * Shapes come from icons/artifacts.dmi, assembled from clean sources only (CC BY-SA 3.0): + * NovaSector 5ce2bd2215c0 artifacts.dmi states 7-13 (pylon, terminal, vents, growth, three + * crystals), Polaris 6cd19fe0dec6 xenoarchaeology.dmi ano10/70/80/120/130/140/150 (torus, + * monolith, spire, idol, cradle, effigy, spindle), and Aurora's crystal_madness (shard; its + * active frames were drawn for Voidcrew). No Goon art: Nova artifact_1-6 and Bay/Polaris + * ano00/20/30/40/50 are Goon copies and are not used. + * + * While it sleeps an artifact breathes a faint glow in its energy kind's colour. Awake, it plays + * its shape's active animation, glows brighter, sheds particles, lights the room a little and + * hums. Waking, falling asleep and each burst it releases have their own small moment. + */ + +/// Shape key -> list("name", "descs", "tag" = list(pixel_x, pixel_y) for the label sticker) +GLOBAL_LIST_INIT(artifact_shapes, list( + "pylon" = list( + "name" = "alien pylon", + "descs" = list( + "A grey orb held above a slim stand by nothing you can see.", + "A metal stand topped with a perfectly smooth grey sphere.", + ), + "tag" = list(15, -22), + ), + "terminal" = list( + "name" = "alien terminal", + "descs" = list( + "A dark glass screen in a heavy frame, lettered in a script nobody reads.", + "It looks like a console. The keys are the wrong shape for any hand you know of.", + ), + "tag" = list(22, -22), + ), + "vents" = list( + "name" = "vented casing", + "descs" = list( + "A heavy grey casing, louvred down one side.", + "A squat metal housing with vents along its flank. Nothing comes out of them.", + ), + "tag" = list(23, -22), + ), + "growth" = list( + "name" = "fronded mass", + "descs" = list( + "A tangle of hard green fronds around a single lidded eye.", + "Green fronds, like metal grown as a plant, curl around a closed eye.", + ), + "tag" = list(21, -21), + ), + "crystal_green" = list( + "name" = "large crystal", + "descs" = list( + "A green crystal the size of a dog. It shines faintly as it catches the light.", + "A green crystal with a faint glow somewhere deep inside.", + ), + "tag" = list(17, -21), + ), + "crystal_violet" = list( + "name" = "large crystal", + "descs" = list( + "A violet crystal the size of a dog. Something twinkles deep inside it.", + "A violet crystal, cold and heavy, with a faint inner glow.", + ), + "tag" = list(17, -21), + ), + "crystal_blue" = list( + "name" = "large crystal", + "descs" = list( + "A blue crystal the size of a dog. It shines faintly as it catches the light.", + "A blue crystal, clear near the edges and cloudy at the heart.", + ), + "tag" = list(17, -21), + ), + "torus" = list( + "name" = "black torus", + "descs" = list( + "A ring of black stone, cold and smooth. The hole looks deeper than the ring is thick.", + "A small black ring, far heavier than it has any right to be.", + ), + "tag" = list(15, -14), + ), + "monolith" = list( + "name" = "green monolith", + "descs" = list( + "A leaning slab of green stone, striped with darker veins.", + "A green slab with grooves down its face, too regular to be weathering.", + ), + "tag" = list(20, -23), + ), + "spire" = list( + "name" = "violet spire", + "descs" = list( + "A twisted violet spire, ridged like horn.", + "A curled violet spike. The ridges on it are warm to the touch.", + ), + "tag" = list(22, -23), + ), + "idol" = list( + "name" = "sandstone idol", + "descs" = list( + "A weathered figure with its arms raised. Its face has been worn away.", + "A sandstone figure holding up two empty hands.", + ), + "tag" = list(17, -17), + ), + "cradle" = list( + "name" = "black cradle", + "descs" = list( + "A forked pedestal of black metal, shaped to hold something that isn't there.", + "Two black prongs rising from a heavy base. Whatever they held is gone.", + ), + "tag" = list(14, -22), + ), + "effigy" = list( + "name" = "pale effigy", + "descs" = list( + "A smooth white figure the height of a child. It has no mouth.", + "A pale figure standing very straight. Its eyes are two dark beads.", + ), + "tag" = list(16, -23), + ), + "spindle" = list( + "name" = "red spindle", + "descs" = list( + "A red crystal turning slowly in place, touching nothing.", + "A spindle of red crystal that hangs a hand's width off the ground and turns.", + ), + "tag" = list(14, -19), + ), + "shard" = list( + "name" = "pale shard", + "descs" = list( + "A cluster of pale blue crystal growing out of a dark stone.", + "Pale blue crystals jut from a lump of black rock like broken glass.", + ), + "tag" = list(16, -23), + ), +)) + +/// Close-up details; each artifact keeps two. +GLOBAL_LIST_INIT(artifact_examine_notes, list( + "It is heavier than it looks.", + "There are no seams, bolts or tool marks anywhere on it.", + "It is a few degrees warmer than the air around it.", + "Grit from the dig is still packed into its crevices.", + "Up close, the surface has a fine grain, like fingerprints.", + "It doesn't ring when tapped. It doesn't make any sound at all.", + "Dust doesn't seem to settle on it.", + "It smells faintly of ozone.", +)) + +/// Lines for falling asleep: "[artifact] [line]" +#define ARTIFACT_SLEEP_LINES list("grows dull.", "fades.", "goes very still.", "falls quiet.") + +/// Glow levels, faintest first. +#define ARTIFACT_GLOW_NONE 0 +#define ARTIFACT_GLOW_IDLE 1 +#define ARTIFACT_GLOW_RESTING 2 +#define ARTIFACT_GLOW_AWAKE 3 + +/obj/machinery/artifact + /// GLOB.artifact_shapes key. Set on a subtype or map to fix the shape; random otherwise. + var/shape + /// Two close-up details for examine_more + var/list/examine_notes + /// Glow level and colour now showing, so the filter is only rebuilt when they change + var/glow_level = ARTIFACT_GLOW_NONE + var/glow_color + /// Shared particle type now attached + var/particles_shown + /// Hum while awake + var/datum/looping_sound/hum + /// Shown on the last visual refresh: awake at all + var/shown_awake = FALSE + +/// Picks a shape if none is set and takes its name, description and icon. +/obj/machinery/artifact/proc/setup_shape() + if(!GLOB.artifact_shapes[shape]) + shape = pick(GLOB.artifact_shapes) + var/list/shape_data = GLOB.artifact_shapes[shape] + name = shape_data["name"] + desc = pick(shape_data["descs"]) + var/list/notes = GLOB.artifact_examine_notes.Copy() + examine_notes = list() + for(var/i in 1 to 2) + examine_notes += pick_n_take(notes) + update_appearance() + +/obj/machinery/artifact/update_icon_state() + icon_state = "[shape][shown_awake ? "_active" : ""]" + return ..() + +/obj/machinery/artifact/update_overlays() + . = ..() + if(!label) + return + var/list/tag_offset = GLOB.artifact_shapes[shape]?["tag"] || list(16, -22) + var/mutable_appearance/sticker = mutable_appearance(icon, "label_tag") + sticker.pixel_x = tag_offset[1] + sticker.pixel_y = tag_offset[2] + . += sticker + +/obj/machinery/artifact/examine(mob/user) + . = ..() + if(is_dug()) + . += "A field tag wired to it reads [serial]." + if(label) + . += label.examine_text() + if(damaged) + . += span_warning("Cracks run through it where it came out of the rock badly.") + if(anchored) + . += "It is bolted to the deck." + if(!shown_awake) + return + var/datum/artifact_energy_kind/kind = visual_kind() + if(kind) + . += span_notice(pick(kind.awake_examine)) + if(all_awake_resting()) + . += "Its glow gutters, as if gathering itself." + +/obj/machinery/artifact/examine_more(mob/user) + . = ..() + . += examine_notes + +/// The kind that sets its look: the main effect's, or the second's if it has no main. +/obj/machinery/artifact/proc/visual_kind() + var/datum/artifact_effect/lead = main_effect || second_effect + return lead ? artifact_energy_kind(lead.energy_kind) : null + +/// Every awake effect is an aura resting between runs. +/obj/machinery/artifact/proc/all_awake_resting() + var/any_awake = FALSE + for(var/datum/artifact_effect/effect as anything in effects()) + if(!effect.activated) + continue + any_awake = TRUE + if(!effect.exhausted) + return FALSE + return any_awake + +// ===== Moments ===== + +/// An effect woke. The first one to wake brings the whole artifact to life. +/obj/machinery/artifact/proc/effect_woke(datum/artifact_effect/effect) + SEND_SIGNAL(src, COMSIG_ARTIFACT_EFFECT_ACTIVATED, effect) + if(!shown_awake && !QDELETED(src)) + var/datum/artifact_energy_kind/kind = visual_kind() + if(kind) + visible_message(span_warning(kind.wake_line(src))) + playsound(src, kind.wake_sound, 50, TRUE) + throb(1.12) + update_activity_visuals() + +/// An effect went to sleep. When the last one sleeps, so does the artifact. +/obj/machinery/artifact/proc/effect_slept(datum/artifact_effect/effect, quiet = FALSE) + SEND_SIGNAL(src, COMSIG_ARTIFACT_EFFECT_DEACTIVATED, effect) + if(QDELETED(src)) + return + if(shown_awake && !is_active() && !quiet) + visible_message(span_notice("[src] [pick(ARTIFACT_SLEEP_LINES)]")) + playsound(src, 'sound/effects/stealthoff.ogg', 40, TRUE) + update_activity_visuals() + +/// An effect let off a burst. +/obj/machinery/artifact/proc/effect_pulsed(datum/artifact_effect/effect) + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + playsound(src, kind.pulse_sound, 45, TRUE) + throb(1.18) + var/old_level = glow_level + set_glow(ARTIFACT_GLOW_AWAKE, kind.color, flash = TRUE) + glow_level = old_level + +/// A quick swell and settle. +/obj/machinery/artifact/proc/throb(scale) + var/matrix/swell = matrix() + swell.Scale(scale) + animate(src, transform = swell, time = 0.15 SECONDS, easing = SINE_EASING | EASE_OUT) + animate(transform = matrix(), time = 0.4 SECONDS, easing = SINE_EASING | EASE_IN) + +// ===== Glow, light, particles, hum ===== + +/** + * Brings icon, glow, light, particles and hum in line with what the effects are doing. + * Cheap when nothing changed; `force` rebuilds everything (after effects were replaced). + */ +/obj/machinery/artifact/proc/update_activity_visuals(force = FALSE) + if(QDELETED(src)) + return + var/datum/artifact_energy_kind/kind = visual_kind() + var/awake = is_active() && !suppressed + var/resting = awake && all_awake_resting() + if(awake != shown_awake || force) + shown_awake = awake + update_appearance(UPDATE_ICON_STATE) + + var/wanted_glow = ARTIFACT_GLOW_NONE + if(kind && isturf(loc)) + if(!awake) + wanted_glow = ARTIFACT_GLOW_IDLE + else + wanted_glow = resting ? ARTIFACT_GLOW_RESTING : ARTIFACT_GLOW_AWAKE + set_glow(wanted_glow, kind?.color, force = force) + + var/wanted_particles = (awake && !resting) ? kind?.particle_type : null + if(wanted_particles != particles_shown || force) + if(particles_shown) + remove_shared_particles(particles_shown) + particles_shown = wanted_particles + if(particles_shown) + add_shared_particles(particles_shown) + + update_artifact_light(awake, resting, kind) + + if(awake) + if(force && hum) + QDEL_NULL(hum) + if(!hum && kind?.hum_type) + hum = new kind.hum_type(src) + hum?.start() + else + hum?.stop() + +/// Light: an awake light or darkness effect sets it; otherwise a small glow while awake. +/obj/machinery/artifact/proc/update_artifact_light(awake, resting, datum/artifact_energy_kind/kind) + if(awake) + for(var/datum/artifact_effect/effect as anything in effects()) + if(!effect.activated) + continue + var/list/override = effect.light_override() + if(override) + set_light(override[1], override[2], override[3]) + return + if(awake && kind) + set_light(2, resting ? 0.4 : 0.9, kind.color) + else + set_light(0) + +/// Sets the drop-shadow glow and starts it breathing. `flash` spikes it once, then settles. +/obj/machinery/artifact/proc/set_glow(level, color, force = FALSE, flash = FALSE) + if(!flash && !force && level == glow_level && color == glow_color) + return + glow_level = level + glow_color = color + if(level == ARTIFACT_GLOW_NONE || !color) + remove_filter("artifact_glow") + return + var/low_alpha + var/high_alpha + var/size + var/period + switch(level) + if(ARTIFACT_GLOW_AWAKE) + low_alpha = "70" + high_alpha = "c8" + size = 2.5 + period = 1 SECONDS + if(ARTIFACT_GLOW_RESTING) + low_alpha = "30" + high_alpha = "60" + size = 1.5 + period = 2 SECONDS + else + low_alpha = "18" + high_alpha = "50" + size = 1 + period = 3 SECONDS + if(flash) + add_filter("artifact_glow", 2, drop_shadow_filter(0, 0, 4, 0, "[color]ff")) + else + add_filter("artifact_glow", 2, drop_shadow_filter(0, 0, size, 0, "[color][low_alpha]")) + transition_filter_chain("artifact_glow", -1, \ + FilterChainStep(list("color" = "[color][high_alpha]", "size" = size), period, SINE_EASING), \ + FilterChainStep(list("color" = "[color][low_alpha]", "size" = size), period, SINE_EASING)) + +/// Strips glow, particles, light and hum (deletion). +/obj/machinery/artifact/proc/clear_activity_visuals() + if(particles_shown) + remove_shared_particles(particles_shown) + particles_shown = null + remove_filter("artifact_glow") + glow_level = ARTIFACT_GLOW_NONE + QDEL_NULL(hum) + set_light(0) + +#undef ARTIFACT_SLEEP_LINES +#undef ARTIFACT_GLOW_NONE +#undef ARTIFACT_GLOW_IDLE +#undef ARTIFACT_GLOW_RESTING +#undef ARTIFACT_GLOW_AWAKE diff --git a/voidcrew/modules/xenoarch/core/artifact_effect.dm b/voidcrew/modules/xenoarch/core/artifact_effect.dm new file mode 100644 index 00000000000..bbe595b16a0 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_effect.dm @@ -0,0 +1,434 @@ +/** + * # Artifact effect + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/artifacts/effect.dm, + * reworked for Voidcrew: + * - Tiers, band-weighted rolls, a label name and harvest flag drive the catalogue. + * - Charge is per second. Auras spend faster than the store refills, so they rest about two + * thirds of the time; a pulse fires when the store is full. The store refills while asleep, + * so a freshly woken artifact acts at once. + * - A stimulus wakes an effect for a while instead of toggling it; level triggers (air and + * proximity) hold it awake while their condition lasts. + * - Harmful effects log like a weapon. Helpful effects never burst when smashed. + * + * Whatever holds an effect (an artifact, or a battery once harvested) calls tick() every + * process and touch() when touched. Subtypes implement do_effect_touch/aura/pulse. + * + * A rollable effect is any subtype that sets label_name. Parents that only share code leave it + * null and never roll. Adding an effect is adding a subtype: nothing else to register. + */ +/datum/artifact_effect + /// The plain words a labeler offers for it, such as "Heals". Null on abstract parents. + var/label_name + /// Name for logs and admins + var/log_name = "unknown" + /// ARTIFACT_TIER_* + var/tier = ARTIFACT_TIER_COMMON + /// A harvester can drain it into a battery + var/harvestable = TRUE + /// Can roll as an artifact's second effect (common and uncommon effects only) + var/minor = FALSE + /// Relative weight against other effects of its tier + var/weight = 10 + /// Weight multipliers by stamped band + var/green_weight = 1 + var/yellow_weight = 1 + var/red_weight = 1 + /// Logged as a weapon when it lands on someone + var/harmful = FALSE + /// Never fires a last burst when its artifact is smashed + var/helpful = FALSE + + /// ARTIFACT_ENERGY_* kinds it can present as; one is picked + var/list/possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED) + /// ARTIFACT_ENERGY_*: what the analyser reads off it, and how its artifact looks + var/energy_kind = ARTIFACT_ENERGY_CONCENTRATED + /// ARTIFACT_RELEASE_* it can roll + var/list/allowed_release_methods = list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_AURA, ARTIFACT_RELEASE_PULSE) + /// ARTIFACT_RELEASE_* + var/release_method = ARTIFACT_RELEASE_TOUCH + /// ARTIFACT_TRIGGER_* it can roll; null for any + var/list/allowed_triggers + /// The trigger that wakes it (one ARTIFACT_TRIGGER_* flag) + var/trigger = ARTIFACT_TRIGGER_TOUCH + + /// ARTIFACT_STRENGTH_* + var/strength = ARTIFACT_STRENGTH_SMALL + /// Tiles its aura and pulses reach + var/range = 3 + /// Size of its charge store; a pulse spends all of it + var/maximum_charges = 10 + /// Charge in store + var/current_charge = 0 + /// Charge one touch spends + var/touch_cost = ARTIFACT_TOUCH_COST + + /// Awake and releasing + var/activated = FALSE + /// An aura that ran its store dry and is resting until full + var/exhausted = FALSE + /// world.time it falls asleep unless woken again + var/awake_until = 0 + + /// Whatever holds it: an artifact, or a battery once harvested + var/atom/holder + /// Who answers for it when it hurts someone, if not its artifact's last disturber + var/datum/weakref/responsible_ref + /// REF(victim) -> world.time last logged, so an aura logs each person twice a minute at most + var/list/last_logged + +/datum/artifact_effect/New(atom/location, band) + . = ..() + holder = location + roll_traits(band) + setup() + current_charge = maximum_charges + +/datum/artifact_effect/Destroy(force) + if(activated) + activated = FALSE + on_deactivate() + holder = null + responsible_ref = null + last_logged = null + return ..() + +/// Rolls energy kind, release method, trigger and strength. +/datum/artifact_effect/proc/roll_traits(band) + energy_kind = pick(possible_kinds) + release_method = pick(allowed_release_methods) + trigger = roll_trigger() + roll_strength(band) + +/datum/artifact_effect/proc/roll_trigger() + var/list/candidates = allowed_triggers || ARTIFACT_ALL_TRIGGERS + var/list/weights = list() + for(var/candidate in candidates) + weights += artifact_trigger_weight(candidate) + var/index = xenoarch_pick_weighted_index(weights) + return index ? candidates[index] : ARTIFACT_TRIGGER_TOUCH + +/// Picks small, medium or large by band (green leans small, red leans large). +/datum/artifact_effect/proc/roll_strength(band) + var/list/odds + switch(XENOARCH_BAND_INDEX(band)) + if(ZONE_RED) + odds = ARTIFACT_STRENGTH_ODDS_RED + if(ZONE_YELLOW) + odds = ARTIFACT_STRENGTH_ODDS_YELLOW + else + odds = ARTIFACT_STRENGTH_ODDS_GREEN + switch(xenoarch_pick_weighted_index(odds)) + if(3) + set_strength(ARTIFACT_STRENGTH_LARGE) + if(2) + set_strength(ARTIFACT_STRENGTH_MEDIUM) + else + set_strength(ARTIFACT_STRENGTH_SMALL) + +/// Nova's charge and range bands for each strength, range capped at 8. +/datum/artifact_effect/proc/set_strength(new_strength) + strength = new_strength + switch(strength) + if(ARTIFACT_STRENGTH_LARGE) + maximum_charges = rand(20, 50) + range = rand(6, 8) + if(ARTIFACT_STRENGTH_MEDIUM) + maximum_charges = rand(15, 30) + range = rand(4, 6) + else + maximum_charges = rand(5, 20) + range = rand(2, 4) + current_charge = min(current_charge, maximum_charges) + +/// Subtype setup after the roll: fix a release method, pick a gas, and so on. +/datum/artifact_effect/proc/setup() + return + +// ===== Waking and sleeping ===== + +/// Keeps it awake for at least `duration` more, waking it if it slept. +/datum/artifact_effect/proc/wake(duration) + awake_until = max(awake_until, world.time + duration) + if(!activated) + activate() + +/datum/artifact_effect/proc/activate() + if(activated) + return + activated = TRUE + exhausted = FALSE + on_activate() + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + artifact.effect_woke(src) + +/// Puts it to sleep. `quiet` skips its artifact's sleep moment (used when it is crated or deleted). +/datum/artifact_effect/proc/deactivate(quiet = FALSE) + if(!activated) + return + activated = FALSE + exhausted = FALSE + awake_until = 0 + on_deactivate() + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + artifact.effect_slept(src, quiet) + +/// Hook: it just woke. +/datum/artifact_effect/proc/on_activate() + return + +/// Hook: it just went to sleep. +/datum/artifact_effect/proc/on_deactivate() + return + +/// The light it gives off while awake as list(range, power, colour), or null to leave the +/// artifact's own glow alone. Light and darkness effects override this. +/datum/artifact_effect/proc/light_override() + return null + +// ===== Releasing ===== + +/// Refills the store. Called every process, awake or not. +/datum/artifact_effect/proc/recharge(seconds_per_tick) + current_charge = min(maximum_charges, current_charge + ARTIFACT_RECHARGE_PER_SECOND * seconds_per_tick) + +/// Called by the holder every process: lets an expired wake lapse, then releases an aura or pulse. +/datum/artifact_effect/proc/tick(seconds_per_tick) + if(!activated) + return + if(world.time >= awake_until) + deactivate() + return + switch(release_method) + if(ARTIFACT_RELEASE_AURA) + release_aura(seconds_per_tick) + if(ARTIFACT_RELEASE_PULSE) + release_pulse() + +/datum/artifact_effect/proc/release_aura(seconds_per_tick) + var/cost = ARTIFACT_AURA_COST_PER_SECOND * seconds_per_tick + if(exhausted) + if(current_charge < maximum_charges) + return + set_exhausted(FALSE) + if(current_charge < cost) + set_exhausted(TRUE) + return + current_charge -= cost + do_effect_aura(seconds_per_tick) + +/datum/artifact_effect/proc/release_pulse() + if(current_charge < maximum_charges) + return + current_charge = 0 + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + artifact.effect_pulsed(src) + do_effect_pulse(maximum_charges) + +/datum/artifact_effect/proc/set_exhausted(new_value) + if(exhausted == new_value) + return + exhausted = new_value + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + artifact.update_activity_visuals() + +/// Someone touched its holder. Returns TRUE if it acted on them. +/datum/artifact_effect/proc/touch(mob/living/user) + if(!activated || release_method != ARTIFACT_RELEASE_TOUCH || !isliving(user)) + return FALSE + if(current_charge < touch_cost) + return FALSE + current_charge -= touch_cost + do_effect_touch(user) + return TRUE + +/// Hook: acts on one person touching it. +/datum/artifact_effect/proc/do_effect_touch(mob/living/user) + return + +/// Hook: acts on everything in range, once per process while the aura runs. +/datum/artifact_effect/proc/do_effect_aura(seconds_per_tick) + return + +/// Hook: one burst. `power` is the charge spent, from 5 to 50. +/datum/artifact_effect/proc/do_effect_pulse(power) + return + +/// Hook: its artifact was smashed. Harmful effects let off one last burst; helpful ones nothing. +/datum/artifact_effect/proc/do_effect_destroy() + if(helpful) + return + do_effect_pulse(maximum_charges) + +// ===== Helpers for subtypes ===== + +/// The turf it acts from. +/datum/artifact_effect/proc/source_turf() + return get_turf(holder) + +/// Living mobs within its range (plus `extra_range`). +/datum/artifact_effect/proc/living_in_range(extra_range = 0) + . = list() + var/turf/center = source_turf() + if(!center) + return + for(var/mob/living/target in range(range + extra_range, center)) + . += target + +/// Who answers for harm it does: whoever set it going on a battery, else whoever last woke or +/// moved its artifact. +/datum/artifact_effect/proc/get_responsible() + var/mob/responsible = responsible_ref?.resolve() + if(responsible) + return responsible + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + return artifact.last_disturbed_by?.resolve() + return null + +/datum/artifact_effect/proc/set_responsible(mob/user) + responsible_ref = user ? WEAKREF(user) : null + +/// Logs harm to `victim` like a weapon hit, at most twice a minute per victim. +/datum/artifact_effect/proc/log_harm(mob/living/victim) + if(!harmful || !istype(victim) || QDELETED(holder)) + return + var/key = REF(victim) + if(LAZYACCESS(last_logged, key) > world.time - 30 SECONDS) + return + LAZYSET(last_logged, key, world.time) + var/mob/responsible = get_responsible() + log_combat(responsible || holder, victim, "exposed", holder, "to [log_name]") + +/// Hook: it had a limited number of uses (lives, a gas reserve) and has none left. A spent +/// effect does nothing more and sells as common (pricing_tier()). +/datum/artifact_effect/proc/is_spent() + return FALSE + +/// The tier buyers price it at: its own, or common once it is spent. +/datum/artifact_effect/proc/pricing_tier() + return is_spent() ? ARTIFACT_TIER_COMMON : tier + +/// What the analyser can read off it: list("kind", "release", "family"), in report words. +/datum/artifact_effect/proc/report_parts() + var/datum/artifact_energy_kind/kind = artifact_energy_kind(energy_kind) + var/release_text + switch(release_method) + if(ARTIFACT_RELEASE_AURA) + release_text = "released as a field" + if(ARTIFACT_RELEASE_PULSE) + release_text = "released in bursts" + else + release_text = "released on contact" + var/family_text + switch(artifact_trigger_family(trigger)) + if(ARTIFACT_FAMILY_CONTACT) + family_text = "Reacts to physical contact." + if(ARTIFACT_FAMILY_ENERGY) + family_text = "Reacts to energetic contact." + else + family_text = "Reacts to its surroundings." + return list("kind" = kind.report_name, "release" = release_text, "family" = family_text) + +/// One report line, such as "Electromagnetic energy, released in bursts. Reacts to energetic contact." +/datum/artifact_effect/proc/report_line() + var/list/parts = report_parts() + return "[parts["kind"]], [parts["release"]]. [parts["family"]]" + +/** + * A copy of this effect for a battery (harvesting). Same kind, release, trigger, strength and + * subtype settings, with an empty store. The copy's holder is `new_holder`. + */ +/datum/artifact_effect/proc/make_harvest_copy(atom/new_holder) + var/datum/artifact_effect/copy = new type(new_holder, null) + copy.energy_kind = energy_kind + copy.release_method = release_method + copy.trigger = trigger + copy.strength = strength + copy.range = range + copy.maximum_charges = maximum_charges + copy.touch_cost = touch_cost + copy.current_charge = 0 + copy_settings_to(copy) + return copy + +/// Hook: copy subtype settings (target temperature, gas, and so on) onto a harvest copy. +/datum/artifact_effect/proc/copy_settings_to(datum/artifact_effect/copy) + return + +// ===== Catalogue ===== + +/// Every rollable effect type (has a label_name), built once. +/proc/artifact_effect_types() + var/static/list/types + if(!types) + types = list() + for(var/datum/artifact_effect/effect_type as anything in subtypesof(/datum/artifact_effect)) + if(initial(effect_type.label_name)) + types += effect_type + return types + +/// The labeler's "what it does" words: every rollable effect's label_name, sorted, no repeats. +/proc/artifact_effect_label_names() + var/static/list/names + if(!names) + names = list() + for(var/datum/artifact_effect/effect_type as anything in artifact_effect_types()) + names |= initial(effect_type.label_name) + sortTim(names, GLOBAL_PROC_REF(cmp_text_asc)) + return names.Copy() + +/// Rolls a main-effect tier for a large find from its band. +/proc/xenoarch_roll_tier(band) + var/list/odds + switch(XENOARCH_BAND_INDEX(band)) + if(ZONE_RED) + odds = ARTIFACT_TIER_ODDS_RED + if(ZONE_YELLOW) + odds = ARTIFACT_TIER_ODDS_YELLOW + else + odds = ARTIFACT_TIER_ODDS_GREEN + return max(xenoarch_pick_weighted_index(odds), ARTIFACT_TIER_COMMON) + +/** + * Picks an effect type. + * + * * tier - ARTIFACT_TIER_* to pick from, or null for any tier (minor picks) + * * band - stamped band, for band weights + * * minor_only - only effects that may be a second effect + * * exclude - a type not to pick (the main effect, when picking the second) + * + * Falls back to lower tiers if a tier has nothing to offer. + */ +/proc/xenoarch_pick_effect_type(tier, band, minor_only = FALSE, exclude) + var/band_index = XENOARCH_BAND_INDEX(band) + for(var/try_tier = tier || ARTIFACT_TIER_EXTREME; try_tier >= ARTIFACT_TIER_COMMON; try_tier--) + var/list/candidates = list() + var/list/weights = list() + for(var/datum/artifact_effect/effect_type as anything in artifact_effect_types()) + if(effect_type == exclude) + continue + if(minor_only && !initial(effect_type.minor)) + continue + if(tier && initial(effect_type.tier) != try_tier) + continue + var/band_mult = initial(effect_type.green_weight) + if(band_index == ZONE_YELLOW) + band_mult = initial(effect_type.yellow_weight) + else if(band_index == ZONE_RED) + band_mult = initial(effect_type.red_weight) + var/effect_weight = initial(effect_type.weight) * band_mult + if(effect_weight <= 0) + continue + candidates += effect_type + weights += effect_weight + var/index = xenoarch_pick_weighted_index(weights) + if(index) + return candidates[index] + if(!tier) + break + return null diff --git a/voidcrew/modules/xenoarch/core/artifact_energy_kinds.dm b/voidcrew/modules/xenoarch/core/artifact_energy_kinds.dm new file mode 100644 index 00000000000..276d72df482 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_energy_kinds.dm @@ -0,0 +1,304 @@ +/** + * # Artifact energy kinds + * + * The seven kinds of energy an analyser can read off a find (Nova's type_name values). Each + * kind also sets how an artifact looks and sounds: a faint glow while it sleeps, and a brighter + * glow, drifting particles, a light and a hum while it is awake. Several effects share each + * kind, so learning the look narrows a find down without naming what it does. + * + * Sounds and particles are existing tg assets. + */ + +/// Every energy kind, keyed by ARTIFACT_ENERGY_*. +GLOBAL_LIST_INIT(artifact_energy_kinds, init_artifact_energy_kinds()) + +/proc/init_artifact_energy_kinds() + . = list() + for(var/kind_type in subtypesof(/datum/artifact_energy_kind)) + var/datum/artifact_energy_kind/kind = new kind_type + .[kind.key] = kind + +/// The energy kind datum for a key, falling back to concentrated energy. +/proc/artifact_energy_kind(key) + return GLOB.artifact_energy_kinds[key] || GLOB.artifact_energy_kinds[ARTIFACT_ENERGY_CONCENTRATED] + +/datum/artifact_energy_kind + /// ARTIFACT_ENERGY_* + var/key + /// How the analyser names it + var/report_name + /// Glow, light and particle colour + var/color + /// Particles drifting off it while awake + var/particle_type + /// The hum while awake + var/hum_type + /// Played when it wakes + var/wake_sound + /// Played on each burst it releases + var/pulse_sound = 'sound/effects/magic/repulse.ogg' + /// "[artifact] [line]" when it wakes + var/list/wake_lines + /// Examine line while it is awake + var/list/awake_examine + +/datum/artifact_energy_kind/proc/wake_line(atom/artifact) + return "[artifact] [pick(wake_lines)]" + +/datum/artifact_energy_kind/concentrated + key = ARTIFACT_ENERGY_CONCENTRATED + report_name = "Concentrated energy" + color = "#ffb347" + particle_type = /particles/artifact/concentrated + hum_type = /datum/looping_sound/artifact_hum/concentrated + wake_sound = 'sound/effects/magic/charge.ogg' + wake_lines = list( + "brightens with a rising whine.", + "flares, and warm light rolls off it.", + "starts to hum. You can feel the heat from here.", + ) + awake_examine = list( + "It is giving off a low, warm hum.", + "Heat shimmers off its surface.", + ) + +/datum/artifact_energy_kind/psionic + key = ARTIFACT_ENERGY_PSIONIC + report_name = "Psionic wavefront" + color = "#b86bff" + particle_type = /particles/artifact/psionic + hum_type = /datum/looping_sound/artifact_hum/psionic + wake_sound = 'sound/effects/magic/magic_block_mind.ogg' + pulse_sound = 'sound/effects/hallucinations/far_noise.ogg' + wake_lines = list( + "shudders, and the air around it wavers.", + "goes very quiet, and your ears start to ring.", + "shimmers like a reflection on water.", + ) + awake_examine = list( + "The air around it wavers like heat haze.", + "Looking at it for long makes your teeth ache.", + ) + +/datum/artifact_energy_kind/electromagnetic + key = ARTIFACT_ENERGY_ELECTROMAGNETIC + report_name = "Electromagnetic energy" + color = "#5fd3ff" + particle_type = /particles/artifact/electromagnetic + hum_type = /datum/looping_sound/artifact_hum/electromagnetic + wake_sound = 'sound/effects/supermatter.ogg' + pulse_sound = 'sound/effects/sparks/sparks2.ogg' + wake_lines = list( + "crackles, and static crawls over it.", + "snaps with a blue spark.", + "buzzes, and the hair on your arms stands up.", + ) + awake_examine = list( + "Static crawls across its surface.", + "It buzzes faintly, like a transformer.", + ) + +/datum/artifact_energy_kind/particle + key = ARTIFACT_ENERGY_PARTICLE + report_name = "High-frequency particles" + color = "#e6efff" + particle_type = /particles/artifact/particle + hum_type = /datum/looping_sound/artifact_hum/particle + wake_sound = 'sound/effects/magic/cosmic_energy.ogg' + wake_lines = list( + "brightens, and motes of light lift off it.", + "glitters as if dusted with frost.", + "gives off a thin, high tone.", + ) + awake_examine = list( + "Tiny motes of light drift off its surface.", + "It glitters, though nothing is shining on it.", + ) + +/datum/artifact_energy_kind/organic + key = ARTIFACT_ENERGY_ORGANIC + report_name = "Organically reactive particles" + color = "#ff5f7a" + particle_type = /particles/artifact/organic + hum_type = /datum/looping_sound/artifact_hum/organic + wake_sound = 'sound/effects/magic/enter_blood.ogg' + pulse_sound = 'sound/effects/singlebeat.ogg' + wake_lines = list( + "swells slightly, then settles into a slow pulse.", + "flushes a dull red.", + "twitches.", + ) + awake_examine = list( + "It pulses slowly, like something breathing.", + "Its surface is damp and faintly warm.", + ) + +/datum/artifact_energy_kind/bluespace + key = ARTIFACT_ENERGY_BLUESPACE + report_name = "Bluespace phasing" + color = "#4a6bff" + particle_type = /particles/artifact/bluespace + hum_type = /datum/looping_sound/artifact_hum/bluespace + wake_sound = 'sound/effects/phasein.ogg' + pulse_sound = 'sound/effects/magic/blink.ogg' + wake_lines = list( + "blurs at the edges.", + "flickers, as if it were briefly somewhere else.", + "seems to lean without moving.", + ) + awake_examine = list( + "Its edges won't hold still.", + "It is hard to say exactly how far away it is.", + ) + +/datum/artifact_energy_kind/synthesis + key = ARTIFACT_ENERGY_SYNTHESIS + report_name = "Atomic synthesis" + color = "#7dff6a" + particle_type = /particles/artifact/synthesis + hum_type = /datum/looping_sound/artifact_hum/synthesis + wake_sound = 'sound/effects/bubbles/bubbles.ogg' + pulse_sound = 'sound/effects/spray.ogg' + wake_lines = list( + "fizzes, and a sharp chemical smell rises from it.", + "beads with moisture.", + "hisses softly.", + ) + awake_examine = list( + "It fizzes faintly. The air near it tastes of metal.", + "A sharp, clean smell hangs around it.", + ) + +// ===== Hums ===== + +/datum/looping_sound/artifact_hum + volume = 20 + extra_range = -8 + falloff_distance = 2 + falloff_exponent = 5 + ignore_walls = FALSE + vary = TRUE + +/datum/looping_sound/artifact_hum/concentrated + mid_sounds = list('sound/machines/sm/loops/calm.ogg' = 1) + mid_length = 10 SECONDS + volume = 15 + +/datum/looping_sound/artifact_hum/psionic + mid_sounds = list('sound/ambience/misc/ambimystery.ogg' = 1) + mid_length = 10 SECONDS + volume = 12 + +/datum/looping_sound/artifact_hum/electromagnetic + mid_sounds = list( + 'sound/machines/tcomms/tcomms_mid1.ogg' = 1, + 'sound/machines/tcomms/tcomms_mid2.ogg' = 1, + 'sound/machines/tcomms/tcomms_mid3.ogg' = 1, + 'sound/machines/tcomms/tcomms_mid4.ogg' = 1, + ) + mid_length = 2 SECONDS + +/datum/looping_sound/artifact_hum/particle + mid_sounds = list('sound/machines/hypertorus/loops/hypertorus_nominal.ogg' = 1) + mid_length = 6.6 SECONDS + volume = 12 + +/datum/looping_sound/artifact_hum/organic + mid_sounds = list('sound/effects/singlebeat.ogg' = 1) + mid_length = 1.6 SECONDS + volume = 15 + +/datum/looping_sound/artifact_hum/bluespace + mid_sounds = list( + 'sound/machines/gravgen/grav_gen_mid1.ogg' = 12, + 'sound/machines/gravgen/grav_gen_mid2.ogg' = 1, + ) + mid_length = 2.3 SECONDS + volume = 15 + +/datum/looping_sound/artifact_hum/synthesis + mid_sounds = list( + 'sound/effects/soup_boil/soup_boil1.ogg' = 1, + 'sound/effects/soup_boil/soup_boil2.ogg' = 1, + 'sound/effects/soup_boil/soup_boil3.ogg' = 1, + 'sound/effects/soup_boil/soup_boil4.ogg' = 1, + ) + mid_length = 3 SECONDS + volume = 15 + +// ===== Particles ===== +// Shared holders (add_shared_particles): one emitter per kind serves every artifact of that kind. + +/particles/artifact + icon = 'icons/effects/particles/generic.dmi' + icon_state = "dot" + width = 64 + height = 64 + count = 24 + spawning = 0.6 + lifespan = 1.5 SECONDS + fade = 1 SECONDS + fadein = 0.2 SECONDS + position = generator(GEN_CIRCLE, 6, 13, NORMAL_RAND) + scale = generator(GEN_VECTOR, list(0.4, 0.4), list(0.8, 0.8), NORMAL_RAND) + +/particles/artifact/concentrated + color = "#ffb347" + velocity = list(0, 0.6) + drift = generator(GEN_VECTOR, list(-0.1, 0), list(0.1, 0.05), UNIFORM_RAND) + +/particles/artifact/psionic + icon = 'icons/effects/particles/echo.dmi' + icon_state = list("echo1" = 1, "echo2" = 1, "echo3" = 1) + color = "#b86bff" + spawning = 0.25 + lifespan = 2 SECONDS + scale = generator(GEN_VECTOR, list(0.15, 0.15), list(0.3, 0.3), NORMAL_RAND) + position = generator(GEN_CIRCLE, 0, 12, NORMAL_RAND) + rotation = generator(GEN_NUM, 0, 360, UNIFORM_RAND) + +/particles/artifact/electromagnetic + icon_state = "cross" + color = "#5fd3ff" + spawning = 1.2 + lifespan = 0.4 SECONDS + fade = 0.3 SECONDS + fadein = 0 + position = generator(GEN_CIRCLE, 8, 15, UNIFORM_RAND) + scale = generator(GEN_VECTOR, list(0.3, 0.3), list(0.6, 0.6), NORMAL_RAND) + +/particles/artifact/particle + color = "#e6efff" + spawning = 0.5 + lifespan = 2.5 SECONDS + velocity = list(0, 0.25) + drift = generator(GEN_VECTOR, list(-0.15, 0), list(0.15, 0), UNIFORM_RAND) + scale = generator(GEN_VECTOR, list(0.25, 0.25), list(0.5, 0.5), NORMAL_RAND) + +/particles/artifact/organic + icon_state = "drop" + color = "#ff5f7a" + spawning = 0.3 + lifespan = 1.2 SECONDS + gravity = list(0, -0.3) + position = generator(GEN_CIRCLE, 0, 9, NORMAL_RAND) + +/particles/artifact/bluespace + icon = 'icons/effects/particles/echo.dmi' + icon_state = list("echo1" = 3, "echo2" = 1, "echo3" = 1) + color = "#4a6bff" + spawning = 1 + lifespan = 0.6 SECONDS + fade = 0.5 SECONDS + friction = 0.5 + position = generator(GEN_SPHERE, 4, 12, NORMAL_RAND) + drift = generator(GEN_VECTOR, list(-1, 1), list(1, 2), NORMAL_RAND) + scale = 0.6 + +/particles/artifact/synthesis + icon_state = "curl" + color = "#7dff6a" + spawning = 0.4 + lifespan = 1.8 SECONDS + velocity = list(0, 0.4) + spin = generator(GEN_NUM, -20, 20, NORMAL_RAND) diff --git a/voidcrew/modules/xenoarch/core/artifact_helpers.dm b/voidcrew/modules/xenoarch/core/artifact_helpers.dm new file mode 100644 index 00000000000..6ac141d22c0 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_helpers.dm @@ -0,0 +1,244 @@ +/** + * # Xenoarchaeology helpers + * + * Small shared procs: bands, serials, the trigger vocabulary and weighted picks. + */ + +/// The ZONE_* a turf belongs to, for stamping a find. Falls back to green, the lowest price, +/// so a failed lookup can never inflate a payout. +/proc/xenoarch_band_for_turf(turf/location) + location = get_turf(location) + if(!location) + return ZONE_GREEN + var/zone_type = SSovermap_zones.get_zone_type_anywhere(location) + if(zone_type == ZONE_YELLOW || zone_type == ZONE_RED) + return zone_type + return ZONE_GREEN + +/// "green", "yellow" or "red", for metrics and logs. +/proc/xenoarch_band_name(band) + switch(band) + if(ZONE_YELLOW) + return "yellow" + if(ZONE_RED) + return "red" + return "green" + +/// Every serial handed out this round, so no two finds share one. +GLOBAL_LIST_EMPTY(artifact_serials_used) + +/// A catalogue number such as "Kappa-4412". Unique for the round. +/proc/xenoarch_new_serial() + var/static/list/letters = list( + "Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", + "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", + "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega", + ) + for(var/attempt in 1 to 50) + var/serial = "[pick(letters)]-[rand(1000, 9999)]" + if(!GLOB.artifact_serials_used[serial]) + GLOB.artifact_serials_used[serial] = TRUE + return serial + // 24 letters x 9000 numbers; fifty misses means the round has dug an absurd amount. + var/fallback = "Omega-[length(GLOB.artifact_serials_used) + 10000]" + GLOB.artifact_serials_used[fallback] = TRUE + return fallback + +/// The plain word for a trigger, as the labeler lists it and a label records it. +/proc/artifact_trigger_name(trigger) + switch(trigger) + if(ARTIFACT_TRIGGER_TOUCH) + return "Touch" + if(ARTIFACT_TRIGGER_WATER) + return "Water" + if(ARTIFACT_TRIGGER_ACID) + return "Acid" + if(ARTIFACT_TRIGGER_VOLATILE) + return "Volatile chemicals" + if(ARTIFACT_TRIGGER_TOXIN) + return "Toxins" + if(ARTIFACT_TRIGGER_IMPACT) + return "Impact" + if(ARTIFACT_TRIGGER_ENERGY) + return "Electricity" + if(ARTIFACT_TRIGGER_HEAT) + return "Heat" + if(ARTIFACT_TRIGGER_COLD) + return "Cold" + if(ARTIFACT_TRIGGER_PLASMA) + return "Plasma" + if(ARTIFACT_TRIGGER_CO2) + return "Carbon dioxide" + if(ARTIFACT_TRIGGER_PROXIMITY) + return "Proximity" + return "Unknown" + +/// Every trigger word, in the labeler's order. +/proc/artifact_trigger_label_names() + var/static/list/names + if(!names) + names = list() + for(var/trigger in ARTIFACT_ALL_TRIGGERS) + names += artifact_trigger_name(trigger) + return names.Copy() + +/// Which family the analyser reports a trigger under. +/proc/artifact_trigger_family(trigger) + if(trigger & (ARTIFACT_TRIGGER_TOUCH | ARTIFACT_TRIGGER_WATER | ARTIFACT_TRIGGER_ACID | ARTIFACT_TRIGGER_VOLATILE | ARTIFACT_TRIGGER_TOXIN)) + return ARTIFACT_FAMILY_CONTACT + if(trigger & (ARTIFACT_TRIGGER_IMPACT | ARTIFACT_TRIGGER_ENERGY | ARTIFACT_TRIGGER_HEAT | ARTIFACT_TRIGGER_COLD)) + return ARTIFACT_FAMILY_ENERGY + return ARTIFACT_FAMILY_AIR + +/// How often an effect rolls this trigger, relative to the others. +/proc/artifact_trigger_weight(trigger) + switch(trigger) + if(ARTIFACT_TRIGGER_PROXIMITY) + return 4 + if(ARTIFACT_TRIGGER_PLASMA, ARTIFACT_TRIGGER_CO2) + return 8 + return 10 + +/// Picks an index from a positional list of weights. Returns 0 if every weight is 0. +/proc/xenoarch_pick_weighted_index(list/weights) + var/total = 0 + for(var/weight in weights) + total += max(weight, 0) + if(total <= 0) + return 0 + var/roll = rand() * total + for(var/index in 1 to length(weights)) + roll -= max(weights[index], 0) + if(roll < 0) + return index + return length(weights) + +/** + * How exposed a mob is to an artifact, from 0 (fully protected) to 1 (bare). + * Biosuits do most of it; latex gloves and science goggles help a little. Ported from Nova's + * get_anomaly_protection(), reading bio armor with getarmor() instead of Nova's helper. + */ +/proc/artifact_exposure(mob/living/target) + if(!ishuman(target)) + return 1 + var/mob/living/carbon/human/person = target + var/protection = 0 + if(person.getarmor(BODY_ZONE_CHEST, BIO) >= 85) + protection += 0.5 + if(person.getarmor(BODY_ZONE_HEAD, BIO) >= 85) + protection += 0.3 + if(istype(person.gloves, /obj/item/clothing/gloves/latex)) + protection += 0.1 + if(istype(person.glasses, /obj/item/clothing/glasses/science)) + protection += 0.1 + return clamp(1 - protection, 0, 1) + +/// Whether a mob's touch counts as touching the artifact's surface: a bare hand, or any gloves +/// that are not latex. Things without hands always count. +/proc/artifact_touch_counts(mob/living/toucher) + if(!iscarbon(toucher)) + return TRUE + var/mob/living/carbon/carbon_toucher = toucher + var/obj/item/clothing/gloves/worn = carbon_toucher.get_item_by_slot(ITEM_SLOT_GLOVES) + return !istype(worn, /obj/item/clothing/gloves/latex) + +// ===== Healing cap ===== +// Heal and robo-heal effects share one budget per person across every artifact and utilizer: +// ARTIFACT_HEAL_CAP brute plus burn per ARTIFACT_HEAL_WINDOW. + +#define ARTIFACT_HEAL_CAP 30 +#define ARTIFACT_HEAL_WINDOW (5 MINUTES) + +/// REF(mob) -> list(window ends at, amount healed in the window). Holds no hard references. +GLOBAL_LIST_EMPTY(artifact_heal_ledger) + +/// How much artifact healing this mob may still take in its current window. +/proc/artifact_heal_allowance(mob/living/target) + var/list/entry = GLOB.artifact_heal_ledger[REF(target)] + if(!entry || world.time >= entry[1]) + return ARTIFACT_HEAL_CAP + return max(ARTIFACT_HEAL_CAP - entry[2], 0) + +/// Records artifact healing against this mob's window. +/proc/artifact_record_heal(mob/living/target, amount) + if(amount <= 0) + return + var/key = REF(target) + var/list/entry = GLOB.artifact_heal_ledger[key] + if(!entry || world.time >= entry[1]) + entry = list(world.time + ARTIFACT_HEAL_WINDOW, 0) + GLOB.artifact_heal_ledger[key] = entry + // Lazy sweep of stale windows so the ledger never grows past the people healed recently. + if(length(GLOB.artifact_heal_ledger) > 50) + for(var/old_key in GLOB.artifact_heal_ledger) + var/list/old = GLOB.artifact_heal_ledger[old_key] + if(world.time >= old[1]) + GLOB.artifact_heal_ledger -= old_key + entry[2] += amount + +/** + * Heals brute and burn on `target`, never past what the shared cap allows. The heal is split in + * proportion to the brute and burn they have, so a one-sided wound gets the whole amount. + * Returns the amount actually healed. + * + * * required_bodytype - limit to robotic or organic limbs on carbons (heal_overall_damage's arg) + */ +/proc/artifact_capped_heal(mob/living/target, amount, required_bodytype) + var/allowed = min(amount, artifact_heal_allowance(target)) + if(allowed <= 0) + return 0 + var/before = target.getBruteLoss() + target.getFireLoss() + if(before <= 0) + return 0 + var/brute_share = allowed * target.getBruteLoss() / before + target.heal_overall_damage(brute_share, allowed - brute_share, required_bodytype = required_bodytype) + var/healed = max(before - (target.getBruteLoss() + target.getFireLoss()), 0) + artifact_record_heal(target, healed) + return healed + +#undef ARTIFACT_HEAL_CAP +#undef ARTIFACT_HEAL_WINDOW + +// ===== Reagent triggers ===== + +/// Reagents that count as volatile (Nova's GLOB.volatile_reagents). +GLOBAL_LIST_INIT(artifact_volatile_reagents, typecacheof(list( + /datum/reagent/thermite, + /datum/reagent/toxin/plasma, + /datum/reagent/nitroglycerin, + /datum/reagent/clf3, + /datum/reagent/sorium, + /datum/reagent/liquid_dark_matter, + /datum/reagent/gunpowder, + /datum/reagent/rdx, + /datum/reagent/tatp, + /datum/reagent/flash_powder, + /datum/reagent/phlogiston, + /datum/reagent/napalm, + /datum/reagent/pyrosium, + /datum/reagent/teslium, +))) + +/// The trigger one reagent type counts as, or NONE. +/proc/artifact_reagent_trigger(reagent_type) + if(!ispath(reagent_type, /datum/reagent)) + return NONE + if(ispath(reagent_type, /datum/reagent/water) || ispath(reagent_type, /datum/reagent/hydrogen)) + return ARTIFACT_TRIGGER_WATER + if(ispath(reagent_type, /datum/reagent/toxin/acid)) + return ARTIFACT_TRIGGER_ACID + if(GLOB.artifact_volatile_reagents[reagent_type]) + return ARTIFACT_TRIGGER_VOLATILE + if(ispath(reagent_type, /datum/reagent/toxin) || ispath(reagent_type, /datum/reagent/consumable/ethanol/neurotoxin)) + return ARTIFACT_TRIGGER_TOXIN + return NONE + +/// Every trigger a list of reagents counts as (datums or types), as one bitfield. +/proc/artifact_reagent_triggers(list/reagents) + . = NONE + for(var/reagent in reagents) + var/reagent_type = reagent + if(istype(reagent, /datum/reagent)) + var/datum/reagent/reagent_datum = reagent + reagent_type = reagent_datum.type + . |= artifact_reagent_trigger(reagent_type) diff --git a/voidcrew/modules/xenoarch/core/artifact_label.dm b/voidcrew/modules/xenoarch/core/artifact_label.dm new file mode 100644 index 00000000000..1eb9429109b --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_label.dm @@ -0,0 +1,25 @@ +/** + * # Artifact label + * + * The sticker a crew prints and sticks on a large find: what they think it does, what they + * think wakes it, and its second effect or "None". Words come from the labeler's plain-word + * lists (artifact_effect_label_names(), artifact_trigger_label_names()). Nothing in the game + * says whether a label is right; the sale price is the only feedback. + */ +/datum/artifact_label + /// What it does, as an effect's label_name + var/effect_name + /// What wakes it, as artifact_trigger_name() gives it + var/trigger_name + /// The second effect's label_name, or ARTIFACT_LABEL_NONE + var/second_name = ARTIFACT_LABEL_NONE + +/datum/artifact_label/New(effect_name, trigger_name, second_name = ARTIFACT_LABEL_NONE) + . = ..() + src.effect_name = effect_name + src.trigger_name = trigger_name + src.second_name = second_name || ARTIFACT_LABEL_NONE + +/// The label as it reads when examined. +/datum/artifact_label/proc/examine_text() + return "A printed label reads: Effect: [effect_name || "?"]. Trigger: [trigger_name || "?"]. Second: [second_name || ARTIFACT_LABEL_NONE]." diff --git a/voidcrew/modules/xenoarch/core/artifact_pricing.dm b/voidcrew/modules/xenoarch/core/artifact_pricing.dm new file mode 100644 index 00000000000..d8d4cf6aec1 --- /dev/null +++ b/voidcrew/modules/xenoarch/core/artifact_pricing.dm @@ -0,0 +1,64 @@ +/** + * # Artifact pricing and research value + * + * One place that says what a large find is worth, so buyers, receipts, metrics and tests + * all agree. Price = base by stamped band x main-effect tier x label share x condition. + * Buyers only take finds stamped as dug; anything else is worth nothing to them. + */ + +/// Credits a buyer pays for this artifact as it stands. 0 if it was never dug. +/proc/artifact_sale_value(obj/machinery/artifact/artifact) + if(QDELETED(artifact) || !artifact.is_dug()) + return 0 + var/datum/artifact_effect/main = artifact.main_effect + if(!main) + return 0 + return xenoarch_price_for(artifact.origin_band, main.pricing_tier(), artifact.label_accuracy(), artifact.damaged, artifact.harvests_taken()) + +/// The tier buyers price this artifact at: its main effect's, or common once that effect is spent. +/// Vex's voucher reads this too, so a spent extreme earns none. +/proc/artifact_price_tier(obj/machinery/artifact/artifact) + return artifact?.main_effect?.pricing_tier() || ARTIFACT_TIER_COMMON + +/** + * The pure price function behind artifact_sale_value(). + * + * * band - stamped ZONE_* + * * tier - ARTIFACT_TIER_* of the main effect + * * accuracy - 0 to 1, from label_accuracy(); 0 for no label + * * damaged - came out of the rock damaged + * * harvests_taken - how many harvests were drained from it + */ +/proc/xenoarch_price_for(band, tier, accuracy, damaged = FALSE, harvests_taken = 0) + var/list/base = ARTIFACT_PRICE_BASE + var/list/tier_mult = ARTIFACT_PRICE_TIER_MULT + var/value = base[XENOARCH_BAND_INDEX(band)] * tier_mult[clamp(tier, ARTIFACT_TIER_COMMON, ARTIFACT_TIER_EXTREME)] + value *= xenoarch_label_share(accuracy) + if(damaged) + value *= ARTIFACT_DAMAGED_MULT + if(harvests_taken > 0) + value *= ARTIFACT_HARVEST_MULT ** harvests_taken + return max(round(value, ARTIFACT_PRICE_ROUNDING), 0) + +/// What share of full price a label of this accuracy earns. +/proc/xenoarch_label_share(accuracy) + // A perfect label sums 0.5 + 0.3 + 0.2 in floating point; never let that read as 0.99999. + accuracy = round(accuracy, 0.01) + if(accuracy >= ARTIFACT_LABEL_ACCURACY_FLOOR) + return min(accuracy, 1) + return ARTIFACT_UNLABELLED_SHARE + +/// Research points for the first full analysis of a large find. +/proc/xenoarch_research_points(band, tier) + var/list/points = ARTIFACT_RESEARCH_POINTS + . = points[XENOARCH_BAND_INDEX(band)] + if(tier >= ARTIFACT_TIER_RARE) + . *= ARTIFACT_RESEARCH_RARE_MULT + return round(.) + +/// Research points this artifact pays on its first full analysis, or 0 once paid or if it was never dug. +/// A spent effect still studies at its own tier: it is the same thing, only emptied. +/proc/artifact_research_value(obj/machinery/artifact/artifact) + if(QDELETED(artifact) || !artifact.is_dug() || artifact.research_paid || !artifact.main_effect) + return 0 + return xenoarch_research_points(artifact.origin_band, artifact.main_effect.tier) diff --git a/voidcrew/modules/xenoarch/dig/ambush.dm b/voidcrew/modules/xenoarch/dig/ambush.dm new file mode 100644 index 00000000000..3fa934fda1b --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/ambush.dm @@ -0,0 +1,67 @@ +/** + * # Dig ambush + * + * Freeing a large find in a yellow or red site can wake whatever lives in the rock nearby + * (XENOARCH_AMBUSH_CHANCE). The ground rumbles first, then a pack crawls out a few tiles off, + * never on top of the crew. Reuses the field-expedition wave: a zone mob marker with a 1 to 2 + * count, wildlife or spiders, scaled by the site's own zone. + */ + +/// How long the rumble lasts before something comes out. +#define DIG_AMBUSH_WARNING (3 SECONDS) + +/// Rolls for an ambush at a freed find. Returns TRUE if one is coming. +/proc/xenoarch_dig_ambush(turf/site, band, mob/digger) + if(!isturf(site)) + return FALSE + var/list/chances = XENOARCH_AMBUSH_CHANCE + if(!prob(chances[XENOARCH_BAND_INDEX(band)])) + return FALSE + var/turf/lair = xenoarch_ambush_lair(site) + if(!lair) + return FALSE + playsound(lair, pick( + 'sound/ambience/earth_rumble/earth_rumble_distant1.ogg', + 'sound/ambience/earth_rumble/earth_rumble_distant2.ogg', + 'sound/ambience/earth_rumble/earth_rumble_distant3.ogg', + ), 70, FALSE, 4) + site.visible_message(span_warning("The ground shudders. Something answers the noise from deeper in the rock.")) + new /obj/effect/temp_visual/xenoarch_dust(lair, "#8f8a83", FALSE) + var/theme = pick_weight(list( + /obj/effect/zone_mobs/wildlife = 6, + /obj/effect/zone_mobs/bug = 4, + )) + addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(xenoarch_spring_ambush), lair, theme), DIG_AMBUSH_WARNING) + if(digger) + log_game("[key_name(digger)] woke a dig-site ambush at [AREACOORD(lair)].") + return TRUE + +/// Open ground 4 to 7 tiles from the find, preferably against the rock, for the pack to come from. +/proc/xenoarch_ambush_lair(turf/site) + var/list/by_rock = list() + var/list/open = list() + for(var/turf/open/tile in RANGE_TURFS(7, site)) + if(get_dist(tile, site) < 4 || isgroundlessturf(tile) || tile.is_blocked_turf(exclude_mobs = TRUE)) + continue + if(istype(tile, /turf/open/water) || istype(tile, /turf/open/lava)) + continue + if(!istype(tile.loc, /area/overmap_encounter/planetoid)) + continue + open += tile + for(var/direction in GLOB.cardinals) + if(ismineralturf(get_step(tile, direction))) + by_rock += tile + break + if(length(by_rock)) + return pick(by_rock) + return length(open) ? pick(open) : null + +/// The pack comes out, unless the planet went away in the meantime. +/proc/xenoarch_spring_ambush(turf/lair, theme) + if(!isopenturf(lair) || !istype(lair.loc, /area/overmap_encounter/planetoid)) + return + playsound(lair, 'sound/effects/break_stone.ogg', 60, TRUE) + new /obj/effect/temp_visual/xenoarch_dust(lair, "#8f8a83", FALSE) + new theme(lair, list(1, 2)) + +#undef DIG_AMBUSH_WARNING diff --git a/voidcrew/modules/xenoarch/dig/boulder.dm b/voidcrew/modules/xenoarch/dig/boulder.dm new file mode 100644 index 00000000000..ae092443e5d --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/boulder.dm @@ -0,0 +1,426 @@ +/** + * # Veined boulder + * + * What a large find sits in once its site wall is mined. Ported from NovaSector (5ce2bd2215c0) + * modular_nova/modules/xenoarchartifacts/artifacts/artifact.dm (/obj/structure/boulder), reworked: + * - All state lives in a /datum/dig_boulder_record held by the planet's dig reserve, so a rebuilt + * planet puts the boulder back exactly as the crew left it. + * - One depth scanner sounds and measures it (Nova's scanner plus tape measure); the advanced one + * reads the exact depth and the stabilising field on site, skipping the spectrometer trip. + * - One hammer with a fitted head, a pick or drill for rough work, and the brush to finish: + * brushing never overshoots, it only takes a centimetre at a time until the find shows. + * - Cutting past the find loses it. Freeing it without the right stabilising field loses it half + * the time and damages it otherwise. A lost find leaves nothing behind: no artifact is made and + * no burst fires (Nova spawned and deleted one, setting off its destroy effect). + * - It shrinks visibly by depth cut (never by depth left, which would give the find away), chips + * and dusts on every strike, and the find comes out of a settling cloud of grit. + */ +/obj/structure/xenoarch_boulder + name = "veined boulder" + desc = "A heavy block of veined rock, cut loose from the face. Something harder sits inside it." + icon = 'voidcrew/modules/xenoarch/icons/dig_site.dmi' + icon_state = "boulder1_0" + anchored = TRUE + density = TRUE + max_integrity = 150 + resistance_flags = FIRE_PROOF | LAVA_PROOF + /// Everything about this boulder; kept in its site's record while it is unopened + var/datum/dig_boulder_record/record + /// The dig site it came from (weakref to /datum/dig_site_record), if any + var/datum/weakref/site_ref + /// Next world.time a working tool makes its noise + var/next_work_noise = 0 + +/obj/structure/xenoarch_boulder/Initialize(mapload, datum/dig_boulder_record/new_record, datum/dig_site_record/site) + . = ..() + record = new_record || new /datum/dig_boulder_record(xenoarch_band_for_turf(src)) + if(site) + site_ref = WEAKREF(site) + color = record.rock_color || "#8f8a83" + if(record.tagged) + AddComponent(/datum/component/gps, "[record.serial] dig") + update_appearance() + +/obj/structure/xenoarch_boulder/Destroy() + var/datum/dig_site_record/site = site_ref?.resolve() + if(record && !record.settled && site && (record in site.loose)) + // Torn down with its planet: the record stays in the reserve and the next build puts the + // boulder back as it was. Deleted any other way on a live planet (an admin, a ship setting + // down on it), it is gone for good. + if(!xenoarch_boulder_kept_on_delete(loc)) + settle() + record_metric(METRIC_RESEARCH, XENOARCH_METRIC_LOST, subject = "[record.find_type]", zone = xenoarch_band_name(record.band), details = list("size" = "large", "reason" = "removed"), location = loc) + if(record && (record.settled || !site || !(record in site.loose))) + QDEL_NULL(record) + record = null + site_ref = null + return ..() + +/// Whether a boulder deleted at `place` keeps its record for the next build: its planet is being +/// torn down, or no planet holds it at all (nothing would rebuild it, so nothing is lost either). +/proc/xenoarch_boulder_kept_on_delete(atom/place) + var/turf/here = get_turf(place) + if(!here) + return TRUE + var/obj/structure/overmap/planet/planet = SSovermap_zones?.get_overmap_object_for_turf(here) + return !istype(planet) || planet.unloading + +/// How far it has been cut down, by depth cut: 0 untouched to 3 a stub of rock. +/obj/structure/xenoarch_boulder/proc/cut_stage() + switch(record?.dug) + if(140 to INFINITY) + return 3 + if(80 to 140) + return 2 + if(30 to 80) + return 1 + return 0 + +/obj/structure/xenoarch_boulder/update_icon_state() + icon_state = "boulder[record?.variant || 1]_[cut_stage()]" + return ..() + +/obj/structure/xenoarch_boulder/update_overlays() + . = ..() + if(!record) + return + . += mutable_appearance(icon, "boulder[record.variant]_[cut_stage()]_vein", appearance_flags = RESET_COLOR) + if(record.sounded) + . += mutable_appearance(icon, "survey_pin", appearance_flags = RESET_COLOR) + if(record.tagged) + . += mutable_appearance(icon, "holotag", appearance_flags = RESET_COLOR) + if(record.field_applied) + . += mutable_appearance(icon, "field", appearance_flags = RESET_COLOR) + +/obj/structure/xenoarch_boulder/examine(mob/user) + . = ..() + if(!record) + return + if(record.tagged) + . += "A holotag on it reads [record.serial]." + switch(record.sounded) + if(1) + . += "A survey tag pinned to it reads: find at [max(1, record.rough_depth - XENOARCH_SCAN_ERROR)] to [record.rough_depth + XENOARCH_SCAN_ERROR] cm. Cut [record.dug] cm." + if(2) + . += "A survey tag pinned to it reads: find at [record.target_depth] cm. Cut [record.dug] cm." + if(record.field_applied) + . += span_notice("A faint lattice of light holds it, set to the [lowertext(record.field_applied)].") + +// ===== Tools ===== + +/obj/structure/xenoarch_boulder/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(!record || record.settled) + return NONE + if(istype(tool, /obj/item/mining_scanner) || istype(tool, /obj/item/t_scanner/adv_mining_scanner)) + return tag_with(tool, user) + if(istype(tool, /obj/item/excavation/hammer)) + return hammer_with(tool, user) + if(istype(tool, /obj/item/excavation/brush)) + return brush_with(tool, user) + if(istype(tool, /obj/item/excavation/depth_scanner)) + return sound_with(tool, user) + if(istype(tool, /obj/item/excavation/core_sampler)) + return sample_with(tool, user) + if(istype(tool, /obj/item/excavation/stabiliser)) + return stabilise_with(tool, user) + if(tool.tool_behaviour == TOOL_MINING) + return rough_cut_with(tool, user) + return NONE + +/// The holotag: a GPS signal under its catalogue number, so the crew (and anyone else) can find it again. +/obj/structure/xenoarch_boulder/proc/tag_with(obj/item/scanner, mob/living/user) + if(record.tagged) + balloon_alert(user, "already tagged") + return ITEM_INTERACT_BLOCKING + record.tagged = TRUE + AddComponent(/datum/component/gps, "[record.serial] dig") + playsound(src, 'sound/machines/beep/twobeep.ogg', 40, TRUE) + user.visible_message( + span_notice("[user] fixes a holotag to [src]."), + span_notice("You fix a holotag to [src]. It blinks to life: [record.serial]."), + ) + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/hammer_with(obj/item/excavation/hammer/hammer, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + var/cm = hammer.head + user.visible_message( + span_notice("[user] starts chipping at [src] with [hammer]."), + span_notice("You start chipping at [src] with the [cm] cm head."), + blind_message = span_hear("You hear steady chipping."), + ) + if(!do_after(user, cm * XENOARCH_HAMMER_TIME_PER_CM, src, extra_checks = CALLBACK(src, PROC_REF(work_noise), SFX_ROCK_TAP, 0.6 SECONDS, TRUE), interaction_key = DOAFTER_SOURCE_XENOARCH)) + // Stopping mid-swing is how a careful hand slips. + if(!QDELETED(src) && record && !record.settled && prob(50)) + to_chat(user, span_warning("Your hammer glances off and takes a chip out of [src].")) + cut(rand(1, 2), user) + return ITEM_INTERACT_BLOCKING + cut(cm, user) + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/rough_cut_with(obj/item/tool, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + user.visible_message( + span_notice("[user] starts breaking rock off [src] with [tool]."), + span_notice("You start breaking rock off [src]."), + blind_message = span_hear("You hear rock being broken."), + ) + if(!tool.use_tool(src, user, 2.5 SECONDS, volume = 50, extra_checks = CALLBACK(src, PROC_REF(work_noise), 'sound/effects/pickaxe/picaxe1.ogg', 0.8 SECONDS, TRUE))) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src) || record.settled) + return ITEM_INTERACT_BLOCKING + cut(rand(XENOARCH_PICK_CUT_MIN, XENOARCH_PICK_CUT_MAX), user) + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/brush_with(obj/item/excavation/brush/brush, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(!do_after(user, brush.brush_time, src, extra_checks = CALLBACK(src, PROC_REF(work_noise), SFX_RUSTLE, 0.9 SECONDS, FALSE), interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src) || record.settled) + return ITEM_INTERACT_BLOCKING + if(record.dug > record.target_depth) + lose_find(user, "cut too deep") + return ITEM_INTERACT_SUCCESS + if(record.dug == record.target_depth) + free_find(user) + return ITEM_INTERACT_SUCCESS + record.dug++ + dust_puff(small = TRUE) + if(record.sounded) + balloon_alert(user, "[record.dug] cm") + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/sound_with(obj/item/excavation/depth_scanner/scanner, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + playsound(src, 'sound/effects/industrial_scan/industrial_scan1.ogg', 35, TRUE) + if(!do_after(user, scanner.scan_time, src, interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src) || record.settled) + return ITEM_INTERACT_BLOCKING + record.sounded = max(record.sounded, scanner.exact ? 2 : 1) + playsound(src, 'sound/machines/beep/twobeep.ogg', 30, TRUE) + var/list/reading = list() + if(scanner.exact) + reading += "Find at [record.target_depth] cm." + else + reading += "Find at [max(1, record.rough_depth - XENOARCH_SCAN_ERROR)] to [record.rough_depth + XENOARCH_SCAN_ERROR] cm." + reading += "Cut [record.dug] cm." + if(scanner.reads_field) + reading += "Field: [record.field]." + to_chat(user, span_notice("[scanner] pins a survey tag to [src] and reads: [jointext(reading, " ")]")) + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/sample_with(obj/item/excavation/core_sampler/sampler, mob/living/user) + if(sampler.sample_serial) + balloon_alert(user, "sampler is full") + return ITEM_INTERACT_BLOCKING + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + playsound(src, 'sound/effects/rock/rocktap2.ogg', 40, TRUE) + if(!do_after(user, 2 SECONDS, src, interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src) || record.settled || sampler.sample_serial) + return ITEM_INTERACT_BLOCKING + sampler.take_core(record) + playsound(src, 'sound/machines/click.ogg', 40, TRUE) + user.visible_message( + span_notice("[user] drives [sampler] into [src] and draws out a core of rock."), + span_notice("You drive [sampler] into [src] and draw out a core of rock."), + ) + return ITEM_INTERACT_SUCCESS + +/obj/structure/xenoarch_boulder/proc/stabilise_with(obj/item/excavation/stabiliser/stabiliser, mob/living/user) + if(!stabiliser.selected_field) + balloon_alert(user, "no field set") + return ITEM_INTERACT_BLOCKING + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + user.visible_message( + span_notice("[user] sweeps [stabiliser] slowly over [src]."), + span_notice("You sweep [stabiliser] over [src], laying down the [lowertext(stabiliser.selected_field)]."), + blind_message = span_hear("You hear a low electrical hum."), + ) + playsound(src, 'sound/effects/magic/forcewall.ogg', 25, TRUE) + if(!do_after(user, 5 SECONDS, src, interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src) || record.settled) + return ITEM_INTERACT_BLOCKING + // Correct or not, the field looks the same. Only the spectrometer or a field reading can tell. + record.field_applied = stabiliser.selected_field + record.stabilised = (record.field_applied == record.field) + playsound(src, 'sound/machines/clockcult/steam_whoosh.ogg', 25, TRUE) + to_chat(user, span_notice("A faint lattice of light settles over [src].")) + update_appearance() + return ITEM_INTERACT_SUCCESS + +/// Plays a tool's noise, with a chip of rock and a puff of dust for striking tools, at most every `interval`. Always TRUE (a do_after check). +/obj/structure/xenoarch_boulder/proc/work_noise(noise, interval, striking) + if(world.time < next_work_noise) + return TRUE + next_work_noise = world.time + interval + playsound(src, noise, striking ? 45 : 30, TRUE) + if(striking) + dust_puff(small = TRUE) + Shake(1, 0, 0.15 SECONDS) + return TRUE + +// ===== Cutting down ===== + +/// Takes `cm` off the boulder. Past the find, the find is lost. +/obj/structure/xenoarch_boulder/proc/cut(cm, mob/living/user) + var/old_stage = cut_stage() + record.dug += cm + if(record.dug > record.target_depth) + lose_find(user, "cut too deep") + return + dust_puff(small = FALSE) + if(cut_stage() != old_stage) + // A whole slab comes away: the boulder is visibly smaller. + playsound(src, 'sound/effects/rock/rock_break.ogg', 40, TRUE) + visible_message(span_notice("A slab of rock breaks away from [src].")) + new /obj/effect/temp_visual/xenoarch_dust(get_turf(src), color, FALSE) + if(record.sounded && user) + balloon_alert(user, "[record.dug] cm") + update_appearance() + +/// A puff of dust off the cut face, tinted like the rock. +/obj/structure/xenoarch_boulder/proc/dust_puff(small = TRUE) + new /obj/effect/temp_visual/xenoarch_dust(get_turf(src), color, small) + +/// The settle: brushed clean at the right depth. Without the right field it may come apart anyway. +/obj/structure/xenoarch_boulder/proc/free_find(mob/living/user) + var/turf/spot = get_turf(src) + var/damaged = FALSE + if(!record.stabilised) + if(prob(XENOARCH_UNSTABLE_CRUMBLE_CHANCE)) + lose_find(user, "unstabilised") + return null + damaged = TRUE + var/find_type = record.find_type + var/band = record.band + var/serial = record.serial + settle() + playsound(spot, 'sound/effects/break_stone.ogg', 50, TRUE) + playsound(spot, 'sound/effects/rustle/rustle3.ogg', 40, TRUE) + new /obj/effect/temp_visual/xenoarch_dust(spot, color, FALSE) + new /obj/effect/decal/cleanable/rubble(spot) + var/atom/movable/find = xenoarch_spawn_large_find(find_type, spot, band, damaged, serial) + if(find) + // It comes up out of the grit. + find.alpha = 0 + find.pixel_z = -6 + animate(find, alpha = 255, pixel_z = 0, time = 1.2 SECONDS, easing = SINE_EASING | EASE_OUT) + new /obj/effect/temp_visual/xenoarch_glint(spot) + visible_message(span_notice("The last of the rock sloughs away, and [find] stands clear of the dust.")) + if(damaged) + visible_message(span_warning("Cracks run through [find] where the rock let go of it badly.")) + record_metric(METRIC_RESEARCH, XENOARCH_METRIC_DUG, subject = "[find_type]", zone = xenoarch_band_name(band), details = list("size" = "large", "damaged" = damaged), actor = user, location = spot) + xenoarch_dig_ambush(spot, band, user) + qdel(src) + return find + +/** + * The find is gone: cut into, come apart unheld, smashed or blown up. Nothing is made and + * nothing goes off. `reason` is for the round metrics. + */ +/obj/structure/xenoarch_boulder/proc/lose_find(mob/living/user, reason, delete_self = TRUE) + var/turf/spot = get_turf(src) + var/find_type = record.find_type + var/band = record.band + settle() + switch(reason) + if("cut too deep") + visible_message( + span_warning("Something deep inside [src] gives a dull crunch, and the whole boulder splits along a fault. Whatever was in there is gravel now."), + blind_message = span_hear("You hear rock crunch and split."), + ) + if("unstabilised") + visible_message( + span_warning("As the last grit comes away, [src] shudders and slumps to pieces. Nothing was holding it together."), + blind_message = span_hear("You hear rock slump and slide."), + ) + else + visible_message( + span_warning("[src] bursts apart in a spray of grit."), + blind_message = span_hear("You hear rock burst apart."), + ) + playsound(spot, 'sound/effects/break_stone.ogg', 60, TRUE) + playsound(spot, 'sound/effects/rock/rock_break.ogg', 50, TRUE) + new /obj/effect/temp_visual/xenoarch_dust(spot, color, FALSE) + new /obj/effect/decal/cleanable/rubble(spot) + record_metric(METRIC_RESEARCH, XENOARCH_METRIC_LOST, subject = "[find_type]", zone = xenoarch_band_name(band), details = list("size" = "large", "reason" = reason), actor = user, location = spot) + if(delete_self) + qdel(src) + +/// Done with: out of its site's record for good. +/obj/structure/xenoarch_boulder/proc/settle() + if(record.settled) + return + record.settled = TRUE + var/datum/dig_site_record/site = site_ref?.resolve() + site?.settle_boulder(record) + +/obj/structure/xenoarch_boulder/atom_destruction(damage_flag) + if(record && !record.settled) + lose_find(null, damage_flag == BOMB ? "blast" : "smashed", delete_self = FALSE) + return ..() + +/** + * # Dig dust + * + * A short puff of grit tinted like the rock it came off. Small for each strike, big when a slab + * comes away or the boulder lets go. Reuses the mook leap cloud. + */ +/obj/effect/temp_visual/xenoarch_dust + name = "dust" + icon = 'icons/mob/simple/jungle/mook.dmi' + icon_state = "mook_leap_cloud" + layer = ABOVE_MOB_LAYER + plane = GAME_PLANE + pixel_x = -16 + pixel_y = -16 + base_pixel_x = -16 + base_pixel_y = -16 + duration = 1 SECONDS + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + +/obj/effect/temp_visual/xenoarch_dust/Initialize(mapload, dust_color, small = TRUE) + . = ..() + if(dust_color) + color = dust_color + var/matrix/size = matrix() + if(small) + size.Scale(0.35) + size.Translate(rand(-6, 6), rand(-2, 8)) + alpha = 170 + else + size.Scale(0.8) + transform = size + animate(src, alpha = 0, time = duration, easing = EASE_IN) + +/** + * # Find glint + * + * A warm glitter over a find the moment the last grit comes off it. tg's shield sparkles, tinted. + */ +/obj/effect/temp_visual/xenoarch_glint + name = "glint" + icon = 'icons/effects/effects.dmi' + icon_state = "shieldsparkles" + color = "#ffe6a8" + layer = ABOVE_MOB_LAYER + plane = GAME_PLANE + randomdir = FALSE + duration = 1.2 SECONDS + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + +/obj/effect/temp_visual/xenoarch_glint/Initialize(mapload) + . = ..() + animate(src, alpha = 0, time = duration, easing = EASE_IN) diff --git a/voidcrew/modules/xenoarch/dig/curios.dm b/voidcrew/modules/xenoarch/dig/curios.dm new file mode 100644 index 00000000000..9f5a85c40bf --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/curios.dm @@ -0,0 +1,344 @@ +/** + * # Curios and small finds + * + * What comes out of strange rocks: fossils, pottery, statuettes, instruments, scrap, now and then + * tg's strange object, a page of research notes or a single item from a sealed research case. + * Each dig site has a kind (Bay's: garden, animal, house, technical, temple, war), weighted by + * the planet's climate, which decides its small finds by tier. + * + * Every curio and strange object that comes out of the ground is stamped with the band it was + * dug in (origin_band). Buyers read that and `curio_class`; an unstamped one (admin spawned, + * experimentor copies, maintenance relics) is not a find. + * + * Sprites: Polaris (6cd19fe0dec6) icons/obj/xenoarchaeology.dmi small-find states, CC BY-SA 3.0. + */ + +// ===== Site kinds ===== + +/// Climate favourites: planet type -> site kinds that turn up more often there. +GLOBAL_LIST_INIT(xenoarch_site_kind_climates, list( + /datum/planet/beach = list(XENOARCH_SITE_GARDEN, XENOARCH_SITE_HOUSE), + /datum/planet/jungle = list(XENOARCH_SITE_GARDEN, XENOARCH_SITE_ANIMAL), + /datum/planet/snow = list(XENOARCH_SITE_ANIMAL, XENOARCH_SITE_HOUSE), + /datum/planet/wasteland = list(XENOARCH_SITE_TECHNICAL, XENOARCH_SITE_WAR), + /datum/planet/lava = list(XENOARCH_SITE_TEMPLE, XENOARCH_SITE_WAR), +)) + +/// Picks a site kind, favouring the ones the planet's climate suits. +/proc/xenoarch_pick_site_kind(planet_type) + var/list/weights = list() + for(var/kind in list(XENOARCH_SITE_GARDEN, XENOARCH_SITE_ANIMAL, XENOARCH_SITE_HOUSE, XENOARCH_SITE_TECHNICAL, XENOARCH_SITE_TEMPLE, XENOARCH_SITE_WAR)) + weights[kind] = 10 + var/list/favoured = GLOB.xenoarch_site_kind_climates[planet_type] + for(var/kind in favoured) + weights[kind] = 30 + return pick_weight(weights) + +/// A small find's tier, 1 to 3, by band. +/proc/xenoarch_roll_small_tier(band) + var/list/odds + switch(XENOARCH_BAND_INDEX(band)) + if(ZONE_RED) + odds = XENOARCH_SMALL_TIER_ODDS_RED + if(ZONE_YELLOW) + odds = XENOARCH_SMALL_TIER_ODDS_YELLOW + else + odds = XENOARCH_SMALL_TIER_ODDS_GREEN + return max(xenoarch_pick_weighted_index(odds), 1) + +/// Stands in a small find table for "one item from a sealed research case". +/datum/xenoarch_research_draw + +/// What a strange rock from a site of `site_kind` holds at `tier`: a type path. +/proc/xenoarch_small_find(site_kind, tier) + switch(site_kind) + if(XENOARCH_SITE_GARDEN) + switch(tier) + if(1) + return pick(/obj/item/xenoarch_curio/plant_fossil, /obj/item/xenoarch_curio/shell) + if(2) + return /obj/item/xenoarch_curio/seed_pod + else + return /obj/item/research_notes/excavation/tiny + if(XENOARCH_SITE_ANIMAL) + switch(tier) + if(1) + return pick(/obj/item/xenoarch_curio/bone, /obj/item/xenoarch_curio/skull) + if(2) + return /obj/item/xenoarch_curio/skeleton + else + return /obj/item/research_notes/excavation/tiny + if(XENOARCH_SITE_TECHNICAL) + switch(tier) + if(1) + return /obj/item/xenoarch_curio/scrap + if(2) + return /obj/item/relic/excavated + else + return /datum/xenoarch_research_draw + if(XENOARCH_SITE_TEMPLE) + switch(tier) + if(1) + return pick(/obj/item/xenoarch_curio/urn, /obj/item/xenoarch_curio/statuette) + if(2) + return pick(/obj/item/xenoarch_curio/instrument, /obj/item/xenoarch_curio/idol) + else + return /obj/item/relic/excavated + if(XENOARCH_SITE_WAR) + switch(tier) + if(1) + return /obj/item/xenoarch_curio/sidearm + if(2) + return /obj/item/relic/excavated + else + return /obj/item/research_notes/excavation/small + // House, and anything unknown + switch(tier) + if(1) + return pick(/obj/item/xenoarch_curio/bowl, /obj/item/xenoarch_curio/urn) + if(2) + return pick(/obj/item/xenoarch_curio/statuette, /obj/item/xenoarch_curio/instrument) + return /obj/item/relic/excavated + +/// Makes a small find at `destination` and stamps it with `band`. Returns it. +/proc/xenoarch_spawn_small_find(find_type, atom/destination, band) + if(find_type == /datum/xenoarch_research_draw) + return xenoarch_research_draw(destination, band) + if(!ispath(find_type, /atom/movable)) + return null + var/atom/movable/find = new find_type(destination) + xenoarch_stamp_find(find, band) + return find + +/// One item from the research loot theme, at the band's odds, as a sealed case would give it. +/proc/xenoarch_research_draw(atom/destination, band) + var/datum/loot_theme/theme = GLOB.loot_themes[/datum/loot_theme/research] + if(!theme) + return null + var/list/pools = list( + "[LOOT_TIER_COMMON]" = theme.loot_common?.Copy(), + "[LOOT_TIER_UNCOMMON]" = theme.loot_uncommon?.Copy(), + "[LOOT_TIER_PRIME]" = theme.loot_prime?.Copy(), + "[LOOT_TIER_UNIQUE]" = theme.loot_uniques?.Copy(), + ) + var/list/odds + switch(XENOARCH_BAND_INDEX(band)) + if(ZONE_RED) + odds = ZONE_LOOT_ODDS_RED + if(ZONE_YELLOW) + odds = ZONE_LOOT_ODDS_YELLOW + else + odds = ZONE_LOOT_ODDS_GREEN + var/loot_path = draw_loot_from_tier(pools, pick_weight(odds)) + if(!loot_path) + return null + return spawn_loot_prize(destination, loot_path) + +/// What outpost buyers pay for each curio class (design: credits only). +GLOBAL_LIST_INIT(xenoarch_curio_values, list( + XENOARCH_CURIO_SHELL = 40, + XENOARCH_CURIO_FOSSIL = 50, + XENOARCH_CURIO_POTTERY = 80, + XENOARCH_CURIO_STATUETTE = 150, + XENOARCH_CURIO_INSTRUMENT = 150, + XENOARCH_CURIO_STRANGE_OBJECT = 200, +)) + +/// Stamps a curio or strange object with the band it was dug in and marks it for buyers. +/// First stamp wins. Returns TRUE if `find` is a stampable small find. +/proc/xenoarch_stamp_find(atom/movable/find, band) + band = XENOARCH_BAND_INDEX(band) + if(istype(find, /obj/item/xenoarch_curio)) + var/obj/item/xenoarch_curio/curio = find + if(!isnull(curio.origin_band)) + return TRUE + curio.origin_band = band + xenoarch_dig_mark_find(curio, GLOB.xenoarch_curio_values[curio.curio_class]) + return TRUE + if(istype(find, /obj/item/relic/excavated)) + var/obj/item/relic/excavated/relic = find + if(!isnull(relic.origin_band)) + return TRUE + relic.origin_band = band + xenoarch_dig_mark_find(relic, GLOB.xenoarch_curio_values[XENOARCH_CURIO_STRANGE_OBJECT]) + return TRUE + return FALSE + +/** + * Marks a freshly dug small find as one outpost buyers will take, at `value` credits. Buyers refuse + * anything unmarked on purpose (maintenance relics, experimentor copies, admin spawns). The trade + * module's xenoarch_mark_curio() (trade/buyers.dm) does the marking; this is the only call site. + */ +/proc/xenoarch_dig_mark_find(obj/item/find, value) + if(!istype(find) || !value) + return FALSE + return xenoarch_mark_curio(find, value) + +// ===== Research notes ===== + +/obj/item/research_notes/excavation + origin_type = "xenoarchaeology" + +/obj/item/research_notes/excavation/tiny + value = 100 + +/obj/item/research_notes/excavation/small + value = 250 + +// ===== Strange object ===== + +/// tg's strange object, as dug out of a site. Only these, stamped, count as finds. +/obj/item/relic/excavated + /// ZONE_* it was dug in, or null + var/origin_band + +// ===== Curios ===== + +/obj/item/xenoarch_curio + name = "curio" + desc = "Something old, out of the ground." + icon = 'voidcrew/modules/xenoarch/icons/curios.dmi' + icon_state = "bone" + w_class = WEIGHT_CLASS_SMALL + resistance_flags = FIRE_PROOF + /// XENOARCH_CURIO_*: what a buyer files it under + var/curio_class = XENOARCH_CURIO_FOSSIL + /// ZONE_* it was dug in, or null if it never came out of the ground + var/origin_band + /// Icon states to pick from + var/list/variants + /// Descriptions to pick from + var/list/descs + +/obj/item/xenoarch_curio/Initialize(mapload) + . = ..() + if(length(variants)) + icon_state = pick(variants) + if(length(descs)) + desc = pick(descs) + pixel_x = base_pixel_x + rand(-6, 6) + pixel_y = base_pixel_y + rand(-4, 4) + +/obj/item/xenoarch_curio/examine(mob/user) + . = ..() + if(!isnull(origin_band)) + . += "Grit from the dig is still packed into it." + +/obj/item/xenoarch_curio/plant_fossil + name = "plant fossil" + curio_class = XENOARCH_CURIO_FOSSIL + variants = list("plant1", "plant2", "plant3", "plant4") + descs = list( + "A flake of stone holding the print of a leaf. Nothing that grows now has leaves like it.", + "A slab of rock with a frond pressed into it, every vein still there.", + ) + +/obj/item/xenoarch_curio/shell + name = "fossil shell" + curio_class = XENOARCH_CURIO_SHELL + variants = list("shell") + descs = list( + "A coiled shell turned to stone, from a sea that dried up long ago.", + "A ribbed shell, stone all the way through.", + ) + +/obj/item/xenoarch_curio/seed_pod + name = "seed pod" + curio_class = XENOARCH_CURIO_STATUETTE + variants = list("green_lump") + descs = list( + "A hard green pod the size of a fist. Something rattles inside when you shake it.", + "A seed case, glassy and green, sealed shut for longer than anyone can guess.", + ) + +/obj/item/xenoarch_curio/bone + name = "fossil bone" + curio_class = XENOARCH_CURIO_FOSSIL + variants = list("bone") + descs = list( + "A long bone gone to stone, still bedded in a little rock.", + "A heavy limb bone from something big. It's all rock now.", + ) + +/obj/item/xenoarch_curio/skull + name = "fossil skull" + curio_class = XENOARCH_CURIO_FOSSIL + variants = list("skull", "hskull") + descs = list( + "A skull set in stone. The eye sockets face the wrong way for anything you know.", + "A horned skull, half freed from its rock.", + ) + +/obj/item/xenoarch_curio/skeleton + name = "fossil skeleton" + curio_class = XENOARCH_CURIO_STATUETTE + w_class = WEIGHT_CLASS_BULKY + variants = list("uskel", "skel") + descs = list( + "A whole skeleton of some long-dead creature, wired upright on a block of its own stone.", + "Every bone of a small animal, still lying where it died.", + ) + +/obj/item/xenoarch_curio/bowl + name = "clay bowl" + curio_class = XENOARCH_CURIO_POTTERY + variants = list("bowl") + descs = list( + "A shallow bowl of fired clay, rim chipped, glaze still bright inside.", + "A hand-thrown bowl. Somebody's thumbprint is baked into the base.", + ) + +/obj/item/xenoarch_curio/urn + name = "urn" + curio_class = XENOARCH_CURIO_POTTERY + variants = list("urn", "urn1", "urn2", "urn3") + descs = list( + "A narrow-necked urn, sealed with something that has gone hard as stone.", + "A painted urn. The pattern repeats all the way round and never quite matches up.", + ) + +/obj/item/xenoarch_curio/statuette + name = "statuette" + curio_class = XENOARCH_CURIO_STATUETTE + variants = list("statuette", "statuette1", "statuette2", "statuette3") + descs = list( + "A small carved figure. Too many joints in the arms.", + "A figure worn smooth by handling, long before it was buried.", + ) + +/obj/item/xenoarch_curio/instrument + name = "strange instrument" + curio_class = XENOARCH_CURIO_INSTRUMENT + variants = list("instrument") + descs = list( + "Bells, reeds or both, in a frame of dark metal. It makes no sound when shaken.", + "Something meant to be played, though not by hands like yours.", + ) + +/obj/item/xenoarch_curio/idol + name = "idol" + curio_class = XENOARCH_CURIO_STATUETTE + variants = list("unknown1") + descs = list( + "A banded column of gold-coloured metal, stacked like a spine.", + "A column of metal rings, stacked and worn smooth where hands once held it.", + ) + +/obj/item/xenoarch_curio/scrap + name = "corroded mechanism" + curio_class = XENOARCH_CURIO_POTTERY + variants = list("unknown2", "unknown3", "unknown4", "box", "sliver1", "pen1") + descs = list( + "A lump of machinery fused by age. Whatever it did, it stopped doing it a long time ago.", + "A fitting of some kind, its threads clogged with ancient grit.", + ) + +/obj/item/xenoarch_curio/sidearm + name = "spent sidearm" + curio_class = XENOARCH_CURIO_POTTERY + w_class = WEIGHT_CLASS_NORMAL + variants = list("egun1", "egun3", "egun5", "egun9", "gun1", "gun3", "gunold") + descs = list( + "A sidearm from a war nobody remembers. The works inside have rotted solid.", + "A grip and a barrel, more or less. It will never fire again.", + ) diff --git a/voidcrew/modules/xenoarch/dig/designs.dm b/voidcrew/modules/xenoarch/dig/designs.dm new file mode 100644 index 00000000000..60f00e399ff --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/designs.dm @@ -0,0 +1,135 @@ +/** + * # Excavation designs + * + * The hand kit prints on any autolathe from round start (like the R&D kit). The stabiliser and the + * spectrometer board belong to the "Xenoarchaeology" research node; the advanced depth scanner and + * quick brush to "Advanced Excavation". Those nodes list these ids: + * + * - Xenoarchaeology: "xenoarch_stabiliser", "xenoarch_spectrometer" + * - Advanced Excavation: "xenoarch_scanner_advanced", "xenoarch_brush_quick" + */ + +// ===== Autolathe, from round start ===== + +/datum/design/xenoarch_kit + name = "Excavation Kit" + desc = "Webbing with a rock hammer, brush, depth scanner, core sampler and a find satchel." + id = "xenoarch_kit" + build_type = AUTOLATHE + materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT * 3, /datum/material/glass = SHEET_MATERIAL_AMOUNT, /datum/material/plastic = SHEET_MATERIAL_AMOUNT) + build_path = /obj/item/storage/belt/excavation/full + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_hammer + name = "Rock Hammer" + id = "xenoarch_hammer" + build_type = AUTOLATHE + materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT) + build_path = /obj/item/excavation/hammer + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_brush + name = "Excavation Brush" + id = "xenoarch_brush" + build_type = AUTOLATHE + materials = list(/datum/material/plastic = SMALL_MATERIAL_AMOUNT * 2, /datum/material/iron = SMALL_MATERIAL_AMOUNT) + build_path = /obj/item/excavation/brush + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_depth_scanner + name = "Depth Scanner" + id = "xenoarch_depth_scanner" + build_type = AUTOLATHE + materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 3, /datum/material/glass = SMALL_MATERIAL_AMOUNT * 3) + build_path = /obj/item/excavation/depth_scanner + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_core_sampler + name = "Core Sampler" + id = "xenoarch_core_sampler" + build_type = AUTOLATHE + materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 4) + build_path = /obj/item/excavation/core_sampler + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_find_bag + name = "Find Satchel" + id = "xenoarch_find_bag" + build_type = AUTOLATHE + materials = list(/datum/material/plastic = SHEET_MATERIAL_AMOUNT) + build_path = /obj/item/storage/bag/excavation + category = list( + RND_CATEGORY_INITIAL, + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +// ===== Research: Xenoarchaeology ===== + +/datum/design/xenoarch_stabiliser + name = "Field Stabiliser" + desc = "A handheld projector that holds crumbling rock together while a find is freed." + id = "xenoarch_stabiliser" + build_type = PROTOLATHE | AWAY_LATHE + materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT, /datum/material/glass = HALF_SHEET_MATERIAL_AMOUNT, /datum/material/silver = SMALL_MATERIAL_AMOUNT * 3) + build_path = /obj/item/excavation/stabiliser + category = list( + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/board/xenoarch_spectrometer + name = "Radiocarbon Spectrometer Board" + desc = "The circuit board for a radiocarbon spectrometer." + id = "xenoarch_spectrometer" + build_path = /obj/item/circuitboard/machine/xenoarch_spectrometer + category = list( + RND_CATEGORY_MACHINE + RND_SUBCATEGORY_MACHINE_RESEARCH, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE + +// ===== Research: Advanced Excavation ===== + +/datum/design/xenoarch_scanner_advanced + name = "Advanced Depth Scanner" + desc = "Reads a find's exact depth and the field its rock needs, on site." + id = "xenoarch_scanner_advanced" + build_type = PROTOLATHE | AWAY_LATHE + materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 3, /datum/material/glass = SMALL_MATERIAL_AMOUNT * 3, /datum/material/gold = SMALL_MATERIAL_AMOUNT * 2, /datum/material/uranium = SMALL_MATERIAL_AMOUNT * 2) + build_path = /obj/item/excavation/depth_scanner/advanced + category = list( + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO + +/datum/design/xenoarch_brush_quick + name = "Quick Brush" + desc = "An excavation brush with a vibrating head." + id = "xenoarch_brush_quick" + build_type = PROTOLATHE | AWAY_LATHE + materials = list(/datum/material/plastic = SMALL_MATERIAL_AMOUNT * 2, /datum/material/iron = SMALL_MATERIAL_AMOUNT * 2, /datum/material/gold = SMALL_MATERIAL_AMOUNT * 2) + build_path = /obj/item/excavation/brush/quick + category = list( + RND_CATEGORY_TOOLS + RND_SUBCATEGORY_TOOLS_MINING, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO diff --git a/voidcrew/modules/xenoarch/dig/dig_reserve.dm b/voidcrew/modules/xenoarch/dig/dig_reserve.dm new file mode 100644 index 00000000000..5afea9cf217 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/dig_reserve.dm @@ -0,0 +1,176 @@ +/** + * # Planet dig reserve + * + * What a planet's dig sites still hold for the rest of the round. It lives on the persistent + * overmap planet, never on its disposable surface, because surfaces rebuild five minutes after + * the last visitor leaves: seeding per build would refill every site on every visit. + * + * The first build fills one record per site; rebuilds place only what is left, and mining a + * site wall takes from its record. Same pattern as /datum/planet_ore_reserve. + * + * A boulder already cut out of the rock keeps its whole state here (depth, field, scan, tag) until + * it is opened or lost, so a crew that flies off for a stabiliser finds it as they left it. + */ +/datum/planet_dig_reserve + /// ZONE_* of the planet when the reserve was made; finds are stamped with it + var/band = ZONE_GREEN + /// One record per dig site, in the order they were placed + var/list/datum/dig_site_record/sites = list() + /// Set once the first build has placed every site + var/seeded = FALSE + +/datum/planet_dig_reserve/New(band) + . = ..() + src.band = XENOARCH_BAND_INDEX(band) + +/datum/planet_dig_reserve/Destroy(force) + QDEL_LIST(sites) + return ..() + +/// Makes one record per site, the first time the planet is built. `planet_type` picks the site kinds. +/datum/planet_dig_reserve/proc/seed(planet_type) + if(seeded) + return FALSE + seeded = TRUE + var/list/large = XENOARCH_LARGE_PER_SITE + var/list/small = XENOARCH_SMALL_PER_SITE + var/index = XENOARCH_BAND_INDEX(band) + for(var/i in 1 to XENOARCH_SITES_PER_PLANET) + var/datum/dig_site_record/site = new(band, xenoarch_pick_site_kind(planet_type)) + site.large_left = large[index] + site.small_left = small[index] + sites += site + return TRUE + +/// Sites with anything left in them, in placement order. +/datum/planet_dig_reserve/proc/sites_with_finds() + . = list() + for(var/datum/dig_site_record/site as anything in sites) + if(site.finds_left() > 0) + . += site + +/// Every find still to come out of the planet, boulders already cut loose included. +/datum/planet_dig_reserve/proc/finds_left() + . = 0 + for(var/datum/dig_site_record/site as anything in sites) + . += site.finds_left() + +/// What one dig site still holds. +/datum/dig_site_record + /// Large finds (boulders) left in the site + var/large_left = 0 + /// Small finds (strange rocks) left in the site + var/small_left = 0 + /// Which kind of site it is (XENOARCH_SITE_*) + var/site_kind = XENOARCH_SITE_HOUSE + /// Where the site sat on the last build, from the planet footprint's low corner, so a rebuild + /// tries the same spot first. Terrain is regenerated on a rebuild, so it may not fit again. + var/x + var/y + /// ZONE_* every find from here is stamped with + var/band = ZONE_GREEN + /// Boulders cut out of the rock but not yet opened, kept so a rebuild puts them back as they were + var/list/datum/dig_boulder_record/loose = list() + +/datum/dig_site_record/New(band, site_kind) + . = ..() + src.band = XENOARCH_BAND_INDEX(band) + if(site_kind) + src.site_kind = site_kind + +/datum/dig_site_record/Destroy(force) + QDEL_LIST(loose) + return ..() + +/// Finds still to come out of this site. +/datum/dig_site_record/proc/finds_left() + return large_left + small_left + length(loose) + +/// Takes one find of `kind` (XENOARCH_FIND_*) out of the count. FALSE if none were left. +/datum/dig_site_record/proc/take_find(kind) + switch(kind) + if(XENOARCH_FIND_LARGE) + if(large_left <= 0) + return FALSE + large_left-- + return TRUE + if(XENOARCH_FIND_SMALL) + if(small_left <= 0) + return FALSE + small_left-- + return TRUE + return FALSE + +/// A boulder was cut out of the face: rolls what it holds and keeps it until it is opened or lost. +/datum/dig_site_record/proc/cut_boulder() + var/datum/dig_boulder_record/boulder = new(band) + boulder.site_kind = site_kind + loose += boulder + return boulder + +/// A loose boulder was opened or lost. It is gone from the site for good. +/datum/dig_site_record/proc/settle_boulder(datum/dig_boulder_record/boulder) + loose -= boulder + +/** + * Everything about one boulder: what is inside, how deep, which field holds it, and how far the + * crew has got. The boulder structure only draws it. + */ +/datum/dig_boulder_record + /// ZONE_* the find is stamped with + var/band = ZONE_GREEN + /// The catalogue number on its holotag, which an artifact keeps when it comes out + var/serial + /// What is inside (a type path), rolled by band + var/find_type + /// Depth of the find's surface, in cm + var/target_depth = XENOARCH_BOULDER_DEPTH_MIN + /// What the plain depth scanner reads: the true depth give or take XENOARCH_SCAN_ERROR + var/rough_depth = XENOARCH_BOULDER_DEPTH_MIN + /// The one stabilising field that holds it (one of GLOB.xenoarch_stabilising_fields) + var/field + /// Radiometric age, in years, for the spectrometer report + var/age = 0 + /// cm cut so far + var/dug = 0 + /// 0 not sounded, 1 sounded roughly, 2 sounded exactly + var/sounded = 0 + /// The field the crew projected on it, if any + var/field_applied + /// The projected field matches + var/stabilised = FALSE + /// A holotag (GPS) has been fixed to it + var/tagged = FALSE + /// Sprite variant, 1 to 4 + var/variant = 1 + /// Colour of the rock it was cut from + var/rock_color + /// The kind of site it came from, for the spectrometer report + var/site_kind + /// Opened or lost: nothing more to do with it + var/settled = FALSE + +/datum/dig_boulder_record/New(band) + . = ..() + src.band = XENOARCH_BAND_INDEX(band) + serial = xenoarch_new_serial() + find_type = xenoarch_roll_large_find(src.band) + target_depth = rand(XENOARCH_BOULDER_DEPTH_MIN, XENOARCH_BOULDER_DEPTH_MAX) + rough_depth = max(1, target_depth + rand(-XENOARCH_SCAN_ERROR, XENOARCH_SCAN_ERROR)) + field = pick(GLOB.xenoarch_stabilising_fields) + age = rand(4, 900) * 1000000 + variant = rand(1, 4) + +/obj/structure/overmap/planet + /// What this planet's dig sites still hold; made on first use + var/datum/planet_dig_reserve/dig_reserve + +/obj/structure/overmap/planet/Destroy() + QDEL_NULL(dig_reserve) + return ..() + +/// This planet's dig reserve, made on first use with the planet's band. +/obj/structure/overmap/planet/proc/get_dig_reserve() + if(!dig_reserve) + dig_reserve = new(ore_zone()) + return dig_reserve diff --git a/voidcrew/modules/xenoarch/dig/dig_sites.dm b/voidcrew/modules/xenoarch/dig/dig_sites.dm new file mode 100644 index 00000000000..1b9ee4b94f0 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/dig_sites.dm @@ -0,0 +1,365 @@ +/** + * # Dig sites + * + * A planet-generator pass that runs after the anomalies, once per surface build. Each site is a + * short run of mountain wall facing open ground: the walls get a vein overlay and one find each, + * and two or three survey stakes and a spoil heap go on the ground in front, so a site reads from + * across the map. Copies place_budgeted_anomalies(): random draws, then an exhaustive scan, + * keeping off rivers, the landing strip and ruins, and spacing sites XENOARCH_SITE_SPACING apart. + * + * What a site holds comes from the planet's /datum/planet_dig_reserve, never from the build, so a + * planet rebuilt after everyone left has only what was not yet dug. A planet whose overmap object + * cannot be found gets no sites at all, since nothing could keep count of them. + * + * Hooked by chaining populate_terrain() from this file (included after PlanetGenerator.dm): the + * original runs first, then the dig pass. The cave area's own population call is skipped; its + * walls are reached from the surface ground that faces them. + */ + +/// Random tries for a site's spot before the exhaustive scan. +#define DIG_SITE_RANDOM_ATTEMPTS 250 +/// Tiles of plain planet a site keeps between itself and ruins or the landing strip. +#define DIG_SITE_CLEARANCE 4 +/// How far from its anchor tile a site's walls may run. +#define DIG_SITE_REACH 3 + +/// Wall to build an outcrop from on a planet with no usable cliff, by planet type. +GLOBAL_LIST_INIT(xenoarch_outcrop_walls, list( + /datum/planet/beach = /turf/closed/mineral/random/beach, + /datum/planet/jungle = /turf/closed/mineral/random/jungle, + /datum/planet/lava = /turf/closed/mineral/random/volcanic/voidcrew, + /datum/planet/snow = /turf/closed/mineral/random/snow, + /datum/planet/wasteland = /turf/closed/mineral/random/high_chance/wasteland, +)) + +/datum/map_generator/planet_generator/populate_terrain(list/turfs, area/generate_in, zone_band) + . = ..() + if(istype(generate_in, /area/overmap_encounter/planetoid/cave)) + return + place_dig_sites(turfs, generate_in) + +/** + * Places every site that still holds something. Returns how many were placed. + */ +/datum/map_generator/planet_generator/proc/place_dig_sites(list/turfs, area/overmap_encounter/planetoid/surface) + if(!length(turfs) || !istype(surface)) + return 0 + var/obj/structure/overmap/planet/planet = SSovermap_zones?.get_overmap_object_for_turf(turfs[1]) + if(!istype(planet)) + return 0 + var/datum/planet_dig_reserve/reserve = planet.get_dig_reserve() + reserve.seed(surface.planet_type) + var/list/to_place = reserve.sites_with_finds() + if(!length(to_place)) + return 0 + + var/datum/map_footprint/footprint = planet.footprint + var/list/placed_at = list() + var/placed = 0 + for(var/datum/dig_site_record/site as anything in to_place) + var/list/spot = find_dig_site_spot(turfs, site, placed_at, footprint) + if(!spot) + spot = build_dig_outcrop(turfs, site, placed_at, surface.planet_type) + if(!spot) + continue + var/turf/anchor = spot[1] + build_dig_site(site, anchor, spot[2]) + site.x = anchor.x - (footprint ? footprint.low_x : 0) + site.y = anchor.y - (footprint ? footprint.low_y : 0) + placed_at += anchor + placed++ + if(placed < length(to_place)) + log_world("[name] dig site shortfall: [placed]/[length(to_place)] sites placed.") + return placed + +/** + * Finds an anchor (the open tile a site is worked from) and its walls: the site's last spot if it + * still fits, then random draws, then every tile in turn. Returns list(anchor, walls) or null. + */ +/datum/map_generator/planet_generator/proc/find_dig_site_spot(list/turfs, datum/dig_site_record/site, list/placed_at, datum/map_footprint/footprint) + var/needed = max(site.large_left + site.small_left, 1) + if(!isnull(site.x) && !isnull(site.y) && length(turfs)) + var/turf/first = turfs[1] + var/turf/last_spot = locate((footprint ? footprint.low_x : 0) + site.x, (footprint ? footprint.low_y : 0) + site.y, first.z) + var/list/walls = dig_site_walls_at(last_spot, needed, placed_at) + if(walls) + return list(last_spot, walls) + var/random_attempts = length(turfs) ? DIG_SITE_RANDOM_ATTEMPTS : 0 + for(var/attempt in 1 to random_attempts + length(turfs)) + SSovermap.worldgen_yield(throttled) + var/turf/candidate = attempt <= random_attempts ? pick(turfs) : turfs[attempt - random_attempts] + var/list/walls = dig_site_walls_at(candidate, needed, placed_at) + if(walls) + return list(candidate, walls) + return null + +/// The walls a site anchored on `anchor` would use, or null if the spot is no good. +/datum/map_generator/planet_generator/proc/dig_site_walls_at(turf/anchor, needed, list/placed_at) + if(!dig_site_ground_ok(anchor)) + return null + for(var/turf/taken as anything in placed_at) + if(taken.z == anchor.z && get_dist(anchor, taken) < XENOARCH_SITE_SPACING) + return null + var/list/walls = collect_dig_site_walls(anchor, needed) + if(!walls || !dig_site_clear_of_ruins(anchor)) + return null + return walls + +/// Open ground the generator laid down: not water, lava, a river, a ruin or the landing strip. +/proc/dig_site_ground_ok(turf/ground) + if(!isopenturf(ground) || isgroundlessturf(ground) || ground.planet_river) + return FALSE + if(istype(ground, /turf/open/water) || istype(ground, /turf/open/lava)) + return FALSE + if(ground.turf_flags & NO_RUINS) + return FALSE + var/datum/biome/biome = ground.generating_biome + if(!biome || !(ground.type in biome.open_turf_types)) + return FALSE + if(ground.is_blocked_turf(exclude_mobs = TRUE)) + return FALSE + return TRUE + +/// Plain mountain rock that faces open ground and isn't already part of a site or a special vein. +/proc/dig_site_wall_ok(turf/closed/mineral/wall) + if(!istype(wall) || wall.dig_find) + return FALSE + if(istype(wall, /turf/closed/mineral/gibtonite) || istype(wall, /turf/closed/mineral/strong)) + return FALSE + if(wall.spawned_boulder || (wall.mineralType && !is_ordinary_ore(wall.mineralType))) + return FALSE + if(wall.turf_flags & NO_RUINS) + return FALSE + if(!istype(wall.loc, /area/overmap_encounter/planetoid)) + return FALSE + for(var/direction in GLOB.cardinals) + var/turf/side = get_step(wall, direction) + if(isopenturf(side) && !isgroundlessturf(side) && !side.planet_river && !istype(side, /turf/open/lava)) + return TRUE + return FALSE + +/// A connected run of usable face walls within DIG_SITE_REACH of the anchor, or null if too short. +/proc/collect_dig_site_walls(turf/anchor, needed) + var/list/queue = list() + for(var/direction in GLOB.cardinals) + var/turf/closed/mineral/wall = get_step(anchor, direction) + if(dig_site_wall_ok(wall)) + queue += wall + var/list/walls = list() + var/list/seen = list() + while(length(queue) && length(walls) < needed) + var/turf/closed/mineral/wall = queue[1] + queue.Cut(1, 2) + if(seen[wall]) + continue + seen[wall] = TRUE + walls += wall + for(var/direction in GLOB.alldirs) + var/turf/closed/mineral/next = get_step(wall, direction) + if(!next || seen[next] || get_dist(next, anchor) > DIG_SITE_REACH) + continue + if(dig_site_wall_ok(next)) + queue += next + return length(walls) >= needed ? walls : null + +/// Nothing within DIG_SITE_CLEARANCE belongs to a ruin, the landing strip or the world border. +/proc/dig_site_clear_of_ruins(turf/anchor) + for(var/turf/near as anything in RANGE_TURFS(DIG_SITE_CLEARANCE, anchor)) + if(near.turf_flags & NO_RUINS) + return FALSE + if(!istype(near.loc, /area/overmap_encounter/planetoid)) + return FALSE + return TRUE + +/** + * A planet with no cliff to dig into (a thin beach) gets a short outcrop of its own rock, raised + * on open ground. Returns list(anchor, walls) or null. + */ +/datum/map_generator/planet_generator/proc/build_dig_outcrop(list/turfs, datum/dig_site_record/site, list/placed_at, planet_type) + var/needed = max(site.large_left + site.small_left, 1) + var/wall_type = GLOB.xenoarch_outcrop_walls[planet_type] || /turf/closed/mineral/random + var/width = needed + 2 + for(var/attempt in 1 to DIG_SITE_RANDOM_ATTEMPTS) + SSovermap.worldgen_yield(throttled) + var/turf/anchor = pick(turfs) + if(!dig_site_ground_ok(anchor)) + continue + var/too_close = FALSE + for(var/turf/taken as anything in placed_at) + if(taken.z == anchor.z && get_dist(anchor, taken) < XENOARCH_SITE_SPACING) + too_close = TRUE + break + if(too_close || !dig_site_clear_of_ruins(anchor)) + continue + // A row of rock just north of the anchor, centred on it. + var/list/row = list() + var/start_x = anchor.x - round(width / 2) + for(var/offset in 0 to width - 1) + var/turf/tile = locate(start_x + offset, anchor.y + 1, anchor.z) + if(!dig_site_ground_ok(tile)) + row = null + break + row += tile + if(!row) + continue + for(var/turf/tile as anything in row) + var/turf/raised = tile.ChangeTurf(wall_type, flags = CHANGETURF_IGNORE_AIR) + raised.assemble_baseturfs(initial(raised.baseturfs) || raised.type) + // Rarely a raised wall rolls a special vein and the run comes up short. One outcrop is + // enough rock to leave on a planet: the site waits for the next build rather than another. + var/list/walls = collect_dig_site_walls(anchor, needed) + return walls ? list(anchor, walls) : null + return null + +/** + * Flags the walls, puts back any boulders already cut loose, and dresses the ground in front: + * stakes at the ends of the face and a spoil heap a step back. + */ +/datum/map_generator/planet_generator/proc/build_dig_site(datum/dig_site_record/site, turf/anchor, list/walls) + var/list/kinds = list() + for(var/i in 1 to site.large_left) + kinds += XENOARCH_FIND_LARGE + for(var/i in 1 to site.small_left) + kinds += XENOARCH_FIND_SMALL + shuffle_inplace(kinds) + for(var/i in 1 to min(length(kinds), length(walls))) + var/turf/closed/mineral/wall = walls[i] + wall.make_dig_site_wall(site, kinds[i]) + return dress_dig_site(site, anchor, walls) + +/// Places loose boulders, stakes and the spoil heap around a site. Returns the decorations placed. +/proc/dress_dig_site(datum/dig_site_record/site, turf/anchor, list/walls) + // Ground right against the face, where the work happens, and a ring a step back for the dressing. + var/list/front = list() + var/list/back = list() + for(var/turf/closed/mineral/wall as anything in walls) + for(var/direction in GLOB.cardinals) + var/turf/side = get_step(wall, direction) + if(dig_site_dressing_ok(side)) + front |= side + for(var/turf/near as anything in RANGE_TURFS(2, anchor)) + if(!(near in front) && dig_site_dressing_ok(near)) + back += near + var/rock_color = "#8f8a83" + var/turf/closed/mineral/first_wall = walls[1] + if(istype(first_wall)) + rock_color = first_wall.dig_rock_color() + + . = list() + for(var/datum/dig_boulder_record/boulder as anything in site.loose) + var/turf/spot = length(front) ? pick_n_take(front) : (length(back) ? pick_n_take(back) : null) + if(!spot) + break + if(!boulder.rock_color) + boulder.rock_color = rock_color + . += new /obj/structure/xenoarch_boulder(spot, boulder, site) + + // Stakes go on the two back tiles furthest apart, so the face is bracketed by them. + if(length(back) >= 2) + var/turf/stake_a + var/turf/stake_b + var/best = -1 + for(var/turf/one as anything in back) + for(var/turf/two as anything in back) + var/distance = get_dist(one, two) + if(distance > best) + best = distance + stake_a = one + stake_b = two + back -= stake_a + back -= stake_b + var/tape = pick("orange", "red") + . += new /obj/structure/xenoarch_stake(stake_a, tape) + . += new /obj/structure/xenoarch_stake(stake_b, tape) + if(length(back) && prob(50)) + . += new /obj/structure/xenoarch_stake(pick_n_take(back), tape) + if(length(back)) + . += new /obj/structure/xenoarch_spoil_heap(pick_n_take(back)) + +/// A tile the dressing can stand on: open, walkable, unclaimed ground. Plants on it are cleared. +/proc/dig_site_dressing_ok(turf/tile) + if(!isopenturf(tile) || isgroundlessturf(tile) || tile.planet_river) + return FALSE + if(istype(tile, /turf/open/water) || istype(tile, /turf/open/lava)) + return FALSE + if(locate(/obj/structure/xenoarch_boulder) in tile) + return FALSE + if(locate(/obj/structure/xenoarch_stake) in tile) + return FALSE + if(locate(/obj/structure/xenoarch_spoil_heap) in tile) + return FALSE + for(var/obj/structure/flora/plant in tile) + qdel(plant) + return !tile.is_blocked_turf(exclude_mobs = TRUE) + +/** + * # Survey stake + * + * A wooden stake with flagging tape, left by whoever marked the site out. Pull it up by hand. + */ +/obj/structure/xenoarch_stake + name = "survey stake" + desc = "A wooden stake hammered into the ground, with a strip of flagging tape knotted near the top." + icon = 'voidcrew/modules/xenoarch/icons/dig_site.dmi' + icon_state = "stake_orange" + anchored = TRUE + density = FALSE + layer = BELOW_MOB_LAYER + max_integrity = 30 + resistance_flags = FLAMMABLE + +/obj/structure/xenoarch_stake/Initialize(mapload, tape_color) + . = ..() + if(tape_color) + icon_state = "stake_[tape_color]" + pixel_x = base_pixel_x + rand(-5, 5) + pixel_y = base_pixel_y + rand(-3, 4) + +/obj/structure/xenoarch_stake/attack_hand(mob/living/user, list/modifiers) + . = ..() + if(.) + return + user.visible_message( + span_notice("[user] works [src] loose from the ground."), + span_notice("You start working [src] loose."), + ) + if(!do_after(user, 2 SECONDS, target = src)) + return TRUE + playsound(src, 'sound/effects/shovel_dig.ogg', 30, TRUE) + user.visible_message(span_notice("[user] pulls up [src] and tosses it aside."), span_notice("You pull up [src].")) + qdel(src) + return TRUE + +/** + * # Spoil heap + * + * Earth and broken rock shovelled out of the dig. Scenery; a shovel clears it. + */ +/obj/structure/xenoarch_spoil_heap + name = "spoil heap" + desc = "A heap of earth and broken rock shovelled out of a dig." + icon = 'voidcrew/modules/xenoarch/icons/dig_site.dmi' + icon_state = "spoil1" + anchored = TRUE + density = FALSE + layer = BELOW_OBJ_LAYER + max_integrity = 60 + +/obj/structure/xenoarch_spoil_heap/Initialize(mapload) + . = ..() + icon_state = "spoil[rand(1, 2)]" + pixel_x = base_pixel_x + rand(-4, 4) + pixel_y = base_pixel_y + rand(-2, 3) + +/obj/structure/xenoarch_spoil_heap/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(tool.tool_behaviour != TOOL_SHOVEL) + return NONE + if(!tool.use_tool(src, user, 3 SECONDS, volume = 50)) + return ITEM_INTERACT_BLOCKING + user.visible_message(span_notice("[user] spreads [src] flat."), span_notice("You spread [src] flat.")) + qdel(src) + return ITEM_INTERACT_SUCCESS + +#undef DIG_SITE_RANDOM_ATTEMPTS +#undef DIG_SITE_CLEARANCE +#undef DIG_SITE_REACH diff --git a/voidcrew/modules/xenoarch/dig/finds.dm b/voidcrew/modules/xenoarch/dig/finds.dm new file mode 100644 index 00000000000..11e5052b624 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/finds.dm @@ -0,0 +1,352 @@ +/** + * # Large finds + * + * What a boulder holds, and the finds other than alien artifacts: the bluespace formation, the + * charged crystal, a sealed research case and, in red sites only, a wrecked combat exosuit. + * + * Shares (design): artifact 88%, bluespace formation 6%, charged crystal 4%, sealed case 2%. + * In red the exosuit wreck takes XENOARCH_FIND_SHARE_EXOSUIT_RED out of the artifact share. + */ + +/// Rolls what a boulder in a site of this band holds. Returns a type path. +/proc/xenoarch_roll_large_find(band) + band = XENOARCH_BAND_INDEX(band) + var/roll = rand(1, 100) + var/threshold = XENOARCH_FIND_SHARE_FORMATION + if(roll <= threshold) + return /obj/machinery/artifact/bluespace_formation + threshold += XENOARCH_FIND_SHARE_CRYSTAL + if(roll <= threshold) + return /obj/machinery/power/charged_crystal + threshold += XENOARCH_FIND_SHARE_CASE + if(roll <= threshold) + return /obj/structure/closet/crate/zone_loot/research + if(band == ZONE_RED) + threshold += XENOARCH_FIND_SHARE_EXOSUIT_RED + if(roll <= threshold) + return pick_weight(GLOB.xenoarch_exosuit_wrecks) + return /obj/machinery/artifact + +/// Combat exosuits that turn up wrecked in red dig sites: the two standard frames. +GLOBAL_LIST_INIT(xenoarch_exosuit_wrecks, list( + /obj/vehicle/sealed/mecha/gygax = 3, + /obj/vehicle/sealed/mecha/durand = 2, +)) + +/** + * Makes a freed large find of `find_type` at `spot`, stamped with `band`. `damaged` is a find that + * came out without the right field. An artifact keeps the boulder's catalogue number. + */ +/proc/xenoarch_spawn_large_find(find_type, turf/spot, band, damaged = FALSE, serial) + band = XENOARCH_BAND_INDEX(band) + if(ispath(find_type, /obj/machinery/artifact)) + var/obj/machinery/artifact/artifact = new find_type(spot, band) + if(serial) + artifact.serial = serial + if(damaged) + artifact.damaged = TRUE + return artifact + if(ispath(find_type, /obj/machinery/power/charged_crystal)) + var/obj/machinery/power/charged_crystal/crystal = new find_type(spot, band) + if(damaged) + crystal.crack() + return crystal + if(ispath(find_type, /obj/structure/closet/crate/zone_loot)) + var/obj/structure/closet/crate/zone_loot/case = new find_type(spot) + // Tiered by where it was dug, wherever it is opened. + case.loot_zone = band + return case + if(ispath(find_type, /obj/vehicle/sealed/mecha)) + return xenoarch_wreck_exosuit(find_type, spot, damaged) + if(ispath(find_type, /atom/movable)) + return new find_type(spot) + return null + +/// The band a find was dug in, or null if it never came out of a dig site. +/proc/xenoarch_find_band(atom/find) + if(istype(find, /obj/machinery/artifact)) + var/obj/machinery/artifact/artifact = find + return artifact.origin_band + if(istype(find, /obj/item/xenoarch_curio)) + var/obj/item/xenoarch_curio/curio = find + return curio.origin_band + if(istype(find, /obj/item/relic/excavated)) + var/obj/item/relic/excavated/relic = find + return relic.origin_band + if(istype(find, /obj/machinery/power/charged_crystal)) + var/obj/machinery/power/charged_crystal/crystal = find + return crystal.origin_band + return null + +// ===== Exosuit wreck ===== + +/** + * A combat exosuit that has been in the rock a long time: a third of its armour, a nearly flat + * cell, no weapons, and caked in dust until someone washes it. Crews repair and arm it themselves. + */ +/proc/xenoarch_wreck_exosuit(mech_type, turf/spot, damaged = FALSE) + var/obj/vehicle/sealed/mecha/mech = new mech_type(spot) + mech.update_integrity(round(mech.max_integrity * (damaged ? 0.2 : 0.35))) + if(mech.cell) + mech.cell.charge = round(mech.cell.maxcharge * 0.15) + mech.add_atom_colour("#b8a88e", WASHABLE_COLOUR_PRIORITY) + return mech + +// ===== Bluespace formation ===== + +/** + * # Bluespace formation + * + * A growth of bluespace crystal on dark stone. Not a true artifact: it has no effects to study. + * Each hard knock throws people near it a short way and lets off a small EMP; broken, it leaves + * a few bluespace crystals. Rewrite of NovaSector (5ce2bd2215c0) artifact_bluespace_crystal.dm + * without the anomaly it spawned on destruction. + */ +/obj/machinery/artifact/bluespace_formation + rolls_effects = FALSE + shape = "shard" + max_integrity = 240 + /// Next world.time it can lash out again + var/next_lash = 0 + +/obj/machinery/artifact/bluespace_formation/Initialize(mapload, band) + . = ..() + name = "bluespace formation" + desc = pick( + "Pale blue crystal growing out of dark stone. Looking at it too long makes the edges of things swim.", + "A cluster of blue crystal on a black rock. The light inside it doesn't come from anywhere.", + ) + add_filter("formation_glow", 2, drop_shadow_filter(0, 0, 1.5, 0, "#4fb3ff70")) + add_shared_particles(/particles/artifact/bluespace) + set_light(2, 0.6, "#4fb3ff") + +/obj/machinery/artifact/bluespace_formation/Destroy() + remove_shared_particles(/particles/artifact/bluespace) + remove_filter("formation_glow") + return ..() + +/obj/machinery/artifact/bluespace_formation/take_damage(damage_amount, damage_type = BRUTE, damage_flag = "", sound_effect = TRUE, attack_dir, armour_penetration = 0) + . = ..() + if(. > 0 && !QDELETED(src) && world.time >= next_lash) + lash_out() + +/// Throws everyone close by a few tiles and lets off a small EMP. +/obj/machinery/artifact/bluespace_formation/proc/lash_out() + next_lash = world.time + 3 SECONDS + var/turf/here = get_turf(src) + if(!here) + return + visible_message(span_warning("[src] flares, and the space around it folds.")) + playsound(here, 'sound/effects/magic/teleport_diss.ogg', 50, TRUE) + do_sparks(3, FALSE, src) + empulse(here, 0, 2) + var/mob/culprit = last_disturbed_by?.resolve() + for(var/mob/living/victim in range(3, here)) + if(artifact_exposure(victim) <= 0) + continue + if(victim.buckled) + victim.buckled.unbuckle_mob(victim) + if(do_teleport(victim, get_turf(victim), 4, asoundin = 'sound/effects/phasein.ogg', channel = TELEPORT_CHANNEL_BLUESPACE)) + if(culprit && culprit != victim) + log_combat(culprit, victim, "displaced with a bluespace formation", src) + +/obj/machinery/artifact/bluespace_formation/atom_destruction(damage_flag) + var/turf/here = get_turf(src) + if(here) + new /obj/item/stack/ore/bluespace_crystal(here, rand(2, 4)) + return ..() + +// ===== Charged crystal ===== + +/** + * # Charged crystal + * + * A crystal holding a finite charge. Bolted onto a cable knot and wrapped in wire, it puts about + * one PACMAN's worth on the net (XENOARCH_CRYSTAL_POWER) until it has given XENOARCH_CRYSTAL_LIFETIME + * of it, then goes dull for good. Cut the wire to save what is left. Rewrite of NovaSector + * (5ce2bd2215c0) artifact_power_crystal.dm, which gave free power forever. + * + * Never saved with a ship (GLOB.outpost_checkpoint_excluded): a rebuilt one would be full again. + * Art: the core crystal sprite (Nova artifacts.dmi), recoloured amber, with a drawn wire wrap. + */ +/obj/machinery/power/charged_crystal + name = "charged crystal" + desc = "A heavy amber crystal. The air near it smells like a storm coming." + icon = 'voidcrew/modules/xenoarch/icons/dig_finds.dmi' + icon_state = "charged_crystal" + density = TRUE + anchored = FALSE + use_power = NO_POWER_USE + processing_flags = START_PROCESSING_MANUALLY + max_integrity = 200 + resistance_flags = FIRE_PROOF | ACID_PROOF + /// ZONE_* it was dug in, or null + var/origin_band + /// Wrapped in cable, ready to feed a powernet + var/wired = FALSE + /// Deciseconds of output left before it goes dull + var/charge_left = XENOARCH_CRYSTAL_LIFETIME + /// Came out of the rock badly: half the charge, and a crack to show for it + var/cracked = FALSE + /// Putting power on the net right now + var/running = FALSE + /// The hum while it runs + var/datum/looping_sound/hum + +/obj/machinery/power/charged_crystal/Initialize(mapload, band) + . = ..() + if(!isnull(band)) + origin_band = XENOARCH_BAND_INDEX(band) + update_appearance() + +/obj/machinery/power/charged_crystal/Destroy() + QDEL_NULL(hum) + return ..() + +/// Came out of the rock badly. +/obj/machinery/power/charged_crystal/proc/crack() + if(cracked) + return + cracked = TRUE + charge_left = round(charge_left / 2) + +/// Has any charge left to give. +/obj/machinery/power/charged_crystal/proc/is_dull() + return charge_left <= 0 + +/obj/machinery/power/charged_crystal/proc/can_run() + return wired && anchored && powernet && !is_dull() + +/// Starts or stops feeding the net to match what it can do now. +/obj/machinery/power/charged_crystal/proc/refresh_running() + var/should_run = can_run() + if(should_run == running) + return + running = should_run + if(running) + begin_processing() + if(!hum) + hum = new /datum/looping_sound/artifact_hum/electromagnetic(src) + hum.start() + playsound(src, 'sound/effects/magic/charge.ogg', 40, TRUE) + visible_message(span_notice("[src] catches, and light crawls up through it.")) + else + end_processing() + hum?.stop() + update_appearance() + +/obj/machinery/power/charged_crystal/process(seconds_per_tick) + if(!can_run()) + refresh_running() + return + add_avail(power_to_energy(XENOARCH_CRYSTAL_POWER)) + charge_left -= seconds_per_tick * (1 SECONDS) + if(is_dull()) + go_dull() + return + update_light_level() + +/// Spent: dark through and through, and no use to anyone. +/obj/machinery/power/charged_crystal/proc/go_dull() + charge_left = 0 + visible_message(span_notice("The last of the light drains out of [src], and it goes dark.")) + playsound(src, 'sound/effects/stealthoff.ogg', 40, TRUE) + refresh_running() + +/// Brighter while it has more to give. +/obj/machinery/power/charged_crystal/proc/update_light_level() + if(!running) + set_light(0) + return + var/fraction = clamp(charge_left / XENOARCH_CRYSTAL_LIFETIME, 0, 1) + set_light(2, 0.4 + fraction * 0.6, "#ffb347") + +/obj/machinery/power/charged_crystal/update_icon_state() + if(is_dull()) + icon_state = "charged_crystal_dull" + else if(running) + icon_state = "charged_crystal_active" + else + icon_state = "charged_crystal" + return ..() + +/obj/machinery/power/charged_crystal/update_overlays() + . = ..() + if(wired) + . += mutable_appearance(icon, "charged_crystal_wires") + +/obj/machinery/power/charged_crystal/update_appearance(updates = ALL) + . = ..() + update_light_level() + +/obj/machinery/power/charged_crystal/examine(mob/user) + . = ..() + if(is_dull()) + . += "It is dark all the way through." + else + var/fraction = charge_left / XENOARCH_CRYSTAL_LIFETIME + if(fraction > 0.66) + . += "Light moves deep inside it." + else if(fraction > 0.33) + . += "The light inside it has thinned." + else + . += "Only a faint spark is left in it." + if(cracked) + . += span_warning("A crack runs through it.") + if(wired) + . += "Copper wire is wound around its foot[running ? ", warm to the touch" : ""]." + if(anchored) + . += "It is bolted to the deck." + +/obj/machinery/power/charged_crystal/wrench_act(mob/living/user, obj/item/tool) + if(running) + balloon_alert(user, "cut the wire first") + return ITEM_INTERACT_BLOCKING + if(default_unfasten_wrench(user, tool, 3 SECONDS) != SUCCESSFUL_UNFASTEN) + return ITEM_INTERACT_BLOCKING + if(anchored) + connect_to_network() + else + disconnect_from_network() + refresh_running() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/power/charged_crystal/wirecutter_act(mob/living/user, obj/item/tool) + if(!wired) + return NONE + if(!tool.use_tool(src, user, 2 SECONDS, volume = 50)) + return ITEM_INTERACT_BLOCKING + wired = FALSE + new /obj/item/stack/cable_coil(drop_location(), 2) + user.visible_message(span_notice("[user] cuts the wire off [src]."), span_notice("You cut the wire off [src].")) + refresh_running() + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/power/charged_crystal/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(!istype(tool, /obj/item/stack/cable_coil)) + return NONE + if(wired) + balloon_alert(user, "already wired") + return ITEM_INTERACT_BLOCKING + var/obj/item/stack/cable_coil/coil = tool + if(coil.get_amount() < 2) + balloon_alert(user, "need more cable") + return ITEM_INTERACT_BLOCKING + user.visible_message(span_notice("[user] starts winding cable around [src]."), span_notice("You start winding cable around [src].")) + if(!do_after(user, 2 SECONDS, src) || wired || !coil.use(2)) + return ITEM_INTERACT_BLOCKING + wired = TRUE + playsound(src, 'sound/items/deconstruct.ogg', 40, TRUE) + refresh_running() + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/power/charged_crystal/atom_destruction(damage_flag) + var/turf/here = get_turf(src) + if(here) + visible_message(span_warning("[src] shatters!"), blind_message = span_hear("You hear a crystal shatter.")) + playsound(here, 'sound/effects/glass/glassbr3.ogg', 60, TRUE) + for(var/i in 1 to 2) + new /obj/item/shard(here) + return ..() diff --git a/voidcrew/modules/xenoarch/dig/site_walls.dm b/voidcrew/modules/xenoarch/dig/site_walls.dm new file mode 100644 index 00000000000..d0ecaed8432 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/site_walls.dm @@ -0,0 +1,104 @@ +/** + * # Dig site walls + * + * Ordinary mountain rock flagged as part of a dig site. The wall keeps its own turf type (so it + * smooths, digs and leaves the same ground as its neighbours) and gains a vein overlay, a mining + * scanner mark, and one find. Mining it frees that find: a boulder for a large one, a strange rock + * for a small one, taken out of its site's record in the planet's dig reserve. + * + * Site walls drop no ore, so NPC planet miners (ambient_ore_wall_ok()) leave them alone. They + * never set mineralType to anything but null: upstream gets_drilled() builds whatever that is. + * + * Vein marks are Baystation12 excavation_overlays.dmi overlay_archaeo1-3, recoloured. + */ + +/turf/closed/mineral + /// The dig site this wall belongs to (weakref to /datum/dig_site_record) + var/datum/weakref/dig_site_ref + /// XENOARCH_FIND_* this wall gives up when mined, or null for plain rock + var/dig_find + /// The vein overlay drawn on it, so it can be taken off again + var/mutable_appearance/dig_vein_overlay + +/// Rock tints by wall sprite, so a boulder looks like the face it came out of. +GLOBAL_LIST_INIT(xenoarch_rock_tints, list( + "icons/turf/walls/mountain_wall.dmi" = "#eef2f6", + "icons/turf/walls/icerock_wall.dmi" = "#d5e1ec", + "icons/turf/walls/rock_wall.dmi" = "#9c968e", + "icons/turf/walls/sandstone_wall.dmi" = "#d8bf8e", +)) + +/// Turns this rock into a dig site wall holding one find of `find_kind` for `site`. +/turf/closed/mineral/proc/make_dig_site_wall(datum/dig_site_record/site, find_kind) + dig_site_ref = WEAKREF(site) + dig_find = find_kind + mineralType = null + mineralAmt = 0 + spawned_boulder = null + scan_state = "xenoarch_site" + if(dig_vein_overlay) + cut_overlay(dig_vein_overlay) + // Drawn on the 32x32 tile, not the wall's oversized 40x40 sprite. + dig_vein_overlay = mutable_appearance('voidcrew/modules/xenoarch/icons/dig_site.dmi', "vein[rand(1, 3)]", appearance_flags = RESET_TRANSFORM) + add_overlay(dig_vein_overlay) + +/// Clears the site flag without giving anything up. +/turf/closed/mineral/proc/clear_dig_site_wall() + dig_site_ref = null + dig_find = null + scan_state = "" + if(dig_vein_overlay) + cut_overlay(dig_vein_overlay) + dig_vein_overlay = null + +/// The colour a boulder cut from this face should take. +/turf/closed/mineral/proc/dig_rock_color() + if(color) + return color + return GLOB.xenoarch_rock_tints["[icon]"] || "#8f8a83" + +/turf/closed/mineral/examine(mob/user) + . = ..() + if(dig_find) + . += span_notice("Pale veins run through the rock here, flecked with something that isn't stone.") + +/turf/closed/mineral/gets_drilled(mob/user, exp_multiplier = 0) + if(dig_find) + release_dig_find(user) + return ..() + +/** + * Frees this wall's find onto its own tile, just before the wall is scraped away. + * Returns the boulder or strange rock, or null if the site's record had nothing left. + */ +/turf/closed/mineral/proc/release_dig_find(mob/user) + var/datum/dig_site_record/site = dig_site_ref?.resolve() + var/kind = dig_find + var/rock_color = dig_rock_color() + clear_dig_site_wall() + if(!site || !site.take_find(kind)) + return null + var/atom/movable/freed + switch(kind) + if(XENOARCH_FIND_LARGE) + var/datum/dig_boulder_record/boulder_record = site.cut_boulder() + boulder_record.rock_color = rock_color + freed = new /obj/structure/xenoarch_boulder(src, boulder_record, site) + visible_message( + span_notice("The face splits around something harder, and a veined boulder comes away whole."), + blind_message = span_hear("You hear rock split with a deep crack."), + ) + playsound(src, 'sound/effects/rock/rock_break.ogg', 50, TRUE) + if(XENOARCH_FIND_SMALL) + freed = new /obj/item/strange_rock(src, site.band, site.site_kind) + playsound(src, 'sound/effects/rock/rocktap3.ogg', 50, TRUE) + if(user) + to_chat(user, span_notice("A lump of veined rock drops out of the face.")) + return freed + +/// The mining scanner's pulse marks a site wall with its own sign rather than an ore's. +/obj/effect/temp_visual/mining_overlay/Initialize(mapload) + . = ..() + var/turf/closed/mineral/rock = loc + if(istype(rock) && rock.dig_find) + icon = 'voidcrew/modules/xenoarch/icons/dig_scan.dmi' diff --git a/voidcrew/modules/xenoarch/dig/spectrometer.dm b/voidcrew/modules/xenoarch/dig/spectrometer.dm new file mode 100644 index 00000000000..32ec639e2f9 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/spectrometer.dm @@ -0,0 +1,193 @@ +/** + * # Radiocarbon spectrometer + * + * A bench machine aboard ship. Feed it a core sampler holding a boulder's core and it dates the + * rock, notes what is mixed into it, and names the stabilising field its matrix holds under, on a + * printed report. Then it hands the sampler back empty. + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/machines/ + * geosample_analyzer.dm, reworked: a timer instead of sleep(), the sampler comes back instead of + * being kept (or destroyed on a power cut), and the report reads like lab paperwork. + * Sprites: Nova machinery.dmi spectrometer states, with a drawn open panel. + */ +/obj/item/circuitboard/machine/xenoarch_spectrometer + name = "Radiocarbon Spectrometer" + greyscale_colors = CIRCUIT_COLOR_SCIENCE + build_path = /obj/machinery/xenoarch_spectrometer + req_components = list( + /datum/stock_part/scanning_module = 2, + /obj/item/stack/sheet/glass = 1, + ) + +/obj/machinery/xenoarch_spectrometer + name = "radiocarbon spectrometer" + desc = "A bench spectrometer for rock cores. It dates the rock and reads the field its matrix will hold under." + icon = 'voidcrew/modules/xenoarch/icons/dig_machines.dmi' + icon_state = "spectrometer" + base_icon_state = "spectrometer" + density = TRUE + circuit = /obj/item/circuitboard/machine/xenoarch_spectrometer + use_power = IDLE_POWER_USE + idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION + active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION + /// The sampler being read + var/obj/item/excavation/core_sampler/sampler + /// The reading in progress + var/scan_timer + /// How long a reading takes; better scanning modules shorten it + var/scan_time = 10 SECONDS + +/obj/machinery/xenoarch_spectrometer/Destroy() + if(scan_timer) + deltimer(scan_timer) + scan_timer = null + if(sampler) + sampler.forceMove(drop_location()) + sampler = null + return ..() + +/obj/machinery/xenoarch_spectrometer/RefreshParts() + . = ..() + var/rating = max(total_part_rating(/datum/stock_part/scanning_module), 2) + // Two tier-1 modules read in 10 s; each tier past that takes off a second, down to 4 s. + scan_time = max(4 SECONDS, (12 - rating) SECONDS) + +/obj/machinery/xenoarch_spectrometer/update_icon_state() + if(panel_open) + icon_state = "[base_icon_state]_open" + else if(scan_timer) + icon_state = "[base_icon_state]_processing" + else + icon_state = base_icon_state + return ..() + +/obj/machinery/xenoarch_spectrometer/examine(mob/user) + . = ..() + if(scan_timer) + . += "It is reading a core." + +/obj/machinery/xenoarch_spectrometer/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(!istype(tool, /obj/item/excavation/core_sampler)) + return NONE + var/obj/item/excavation/core_sampler/new_sampler = tool + if(panel_open) + balloon_alert(user, "close the panel") + return ITEM_INTERACT_BLOCKING + if(!is_operational) + balloon_alert(user, "no power") + return ITEM_INTERACT_BLOCKING + if(sampler) + balloon_alert(user, "already reading") + return ITEM_INTERACT_BLOCKING + if(!new_sampler.sample_serial) + balloon_alert(user, "sampler is empty") + return ITEM_INTERACT_BLOCKING + if(!user.transferItemToLoc(new_sampler, src)) + return ITEM_INTERACT_BLOCKING + sampler = new_sampler + user.visible_message( + span_notice("[user] slots [new_sampler] into [src]."), + span_notice("You slot [new_sampler] into [src]."), + ) + begin_reading() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/xenoarch_spectrometer/attack_hand(mob/living/user, list/modifiers) + . = ..() + if(. || !sampler) + return + // Pulls the sampler out, abandoning a reading. + stop_reading() + eject_sampler(user) + return TRUE + +/obj/machinery/xenoarch_spectrometer/proc/begin_reading() + update_use_power(ACTIVE_POWER_USE) + playsound(src, 'sound/effects/industrial_scan/industrial_scan3.ogg', 40, TRUE) + scan_timer = addtimer(CALLBACK(src, PROC_REF(finish_reading)), scan_time, TIMER_STOPPABLE | TIMER_DELETE_ME) + update_appearance() + +/obj/machinery/xenoarch_spectrometer/proc/stop_reading() + if(scan_timer) + deltimer(scan_timer) + scan_timer = null + update_use_power(IDLE_POWER_USE) + update_appearance() + +/obj/machinery/xenoarch_spectrometer/proc/finish_reading() + scan_timer = null + update_use_power(IDLE_POWER_USE) + if(QDELETED(src) || !sampler) + update_appearance() + return + if(!is_operational) + visible_message(span_warning("[src] whines down and pushes the sampler back out.")) + eject_sampler() + update_appearance() + return + print_report(sampler) + sampler.clear_core() + eject_sampler() + update_appearance() + +/// Power lost mid-reading: the sampler comes back with its core still in it. +/obj/machinery/xenoarch_spectrometer/on_set_is_operational(old_value) + . = ..() + if(!is_operational && scan_timer) + stop_reading() + visible_message(span_warning("[src] whines down and pushes the sampler back out.")) + eject_sampler() + +/obj/machinery/xenoarch_spectrometer/proc/eject_sampler(mob/living/user) + if(!sampler) + return + var/obj/item/excavation/core_sampler/out = sampler + sampler = null + out.forceMove(drop_location()) + if(user) + user.put_in_hands(out) + +/obj/machinery/xenoarch_spectrometer/Exited(atom/movable/gone, direction) + . = ..() + if(gone == sampler) + sampler = null + stop_reading() + +/// Prints the lab report for the core in `core_sampler`. +/obj/machinery/xenoarch_spectrometer/proc/print_report(obj/item/excavation/core_sampler/core_sampler) + var/obj/item/paper/report = new(drop_location()) + report.name = "spectrometer report ([core_sampler.sample_serial])" + report.add_raw_text(xenoarch_spectrometer_text(core_sampler.sample_serial, core_sampler.sample_age, core_sampler.sample_field, core_sampler.sample_site_kind)) + var/datum/asset/spritesheet_batched/sheet = get_asset_datum(/datum/asset/spritesheet/simple/paper) + report.add_stamp(sheet.icon_class_name("stamp-ok"), rand(180, 260), rand(330, 380), rand(-15, 15), "stamp-ok") + report.update_appearance() + playsound(src, 'sound/machines/printer.ogg', 40, FALSE) + visible_message(span_notice("[src] chatters and feeds out a report.")) + return report + +/// What a site's rock is mixed with, as the spectrometer reads it. +GLOBAL_LIST_INIT(xenoarch_core_inclusions, list( + XENOARCH_SITE_GARDEN = "carbonised plant matter, pollen", + XENOARCH_SITE_ANIMAL = "mineralised bone, collagen traces", + XENOARCH_SITE_HOUSE = "fired clay, hearth ash", + XENOARCH_SITE_TECHNICAL = "corroded alloy, trace rare earths", + XENOARCH_SITE_TEMPLE = "pigment, worked stone dust", + XENOARCH_SITE_WAR = "slag, spent propellant residue", +)) + +/// The report text: lab paperwork, nothing about how to use it. +/proc/xenoarch_spectrometer_text(serial, age, field, site_kind) + var/age_text + if(age >= 1000000000) + age_text = "[round(age / 1000000000, 0.1)] billion years" + else if(age >= 1000000) + age_text = "[round(age / 1000000)] million years" + else + age_text = "[round(age / 1000)] thousand years" + var/inclusions = GLOB.xenoarch_core_inclusions[site_kind] || "none of note" + . = "
RADIOCARBON SPECTROMETRY
Core sample [serial]

" + . += "Matrix age: about [age_text]
" + . += "Inclusions: [inclusions]
" + . += "Exotic signature: present, unresolved
" + . += "Matrix holds under: [field]
" + . += "
Bench copy. File with the find." diff --git a/voidcrew/modules/xenoarch/dig/stabiliser.dm b/voidcrew/modules/xenoarch/dig/stabiliser.dm new file mode 100644 index 00000000000..e0fa1f118cf --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/stabiliser.dm @@ -0,0 +1,68 @@ +/** + * # Field stabiliser + * + * A handheld projector that lays a stabilising field over a boulder before its find is freed. + * Every boulder's rock needs one of eight fields; only the right one holds the find together as + * the last of the rock comes away. A wrong field looks exactly like a right one. The spectrometer + * (or an advanced depth scanner) says which field a boulder needs. + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/obj/ + * artifact_stabilizer.dm: the field list (Phoron renamed), picked from a radial instead of an + * input box. Sprite: Nova tools.dmi anoscanner_borg. + */ + +/// The eight fields a boulder's rock may need, with the colour the stabiliser shows for each. +GLOBAL_LIST_INIT(xenoarch_stabilising_fields, list( + "Diffracted carbon dioxide laser" = "#ff8f6b", + "Nitrogen tracer field" = "#7fb2ff", + "Potassium refrigerant cloud" = "#b98bff", + "Mercury dispersion wave" = "#c9d3dc", + "Iron wafer conduction field" = "#d08a5c", + "Calcium binary deoxidizer" = "#f2f0d8", + "Chlorine diffusion emissions" = "#b6f06a", + "Plasma saturated field" = "#ff6fd0", +)) + +/obj/item/excavation/stabiliser + name = "field stabiliser" + desc = "An old handheld field projector, built to hold crumbling rock together. Its dial is marked with eight field settings." + icon_state = "stabiliser" + inhand_icon_state = "analyzer" + w_class = WEIGHT_CLASS_NORMAL + custom_materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT, /datum/material/glass = HALF_SHEET_MATERIAL_AMOUNT, /datum/material/silver = SMALL_MATERIAL_AMOUNT * 3) + /// The field it projects, or null before one is dialled in + var/selected_field + +/obj/item/excavation/stabiliser/examine(mob/user) + . = ..() + if(selected_field) + . += "The dial is set to [selected_field]." + else + . += "The dial is at rest." + +/obj/item/excavation/stabiliser/attack_self(mob/user, modifiers) + . = ..() + if(.) + return + var/list/choices = list() + for(var/field in GLOB.xenoarch_stabilising_fields) + var/image/swatch = image('voidcrew/modules/xenoarch/icons/dig_site.dmi', "field") + swatch.color = GLOB.xenoarch_stabilising_fields[field] + choices[field] = swatch + var/picked = show_radial_menu(user, src, choices, require_near = TRUE, tooltips = TRUE) + if(!picked || !user.is_holding(src) || !(picked in GLOB.xenoarch_stabilising_fields)) + return TRUE + selected_field = picked + playsound(src, 'sound/machines/click.ogg', 30, TRUE) + balloon_alert(user, "set to [lowertext(picked)]") + update_appearance() + return TRUE + +/obj/item/excavation/stabiliser/update_overlays() + . = ..() + if(!selected_field) + return + // A small lamp on the dial shows the setting's colour. + var/mutable_appearance/lamp = mutable_appearance(icon, "stabiliser_lamp") + lamp.color = GLOB.xenoarch_stabilising_fields[selected_field] + . += lamp diff --git a/voidcrew/modules/xenoarch/dig/strange_rock.dm b/voidcrew/modules/xenoarch/dig/strange_rock.dm new file mode 100644 index 00000000000..5fa8abbe8d0 --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/strange_rock.dm @@ -0,0 +1,180 @@ +/** + * # Strange rock + * + * A lump of veined rock that drops out of a site wall, holding one small find. Worked by hand + * like a boulder in miniature: sound it, chip it down with the hammer, brush the last of it away. + * Cut too deep and the find goes with the rock. + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarch/code/modules/research/ + * xenoarch/strange_rock.dm, reworked: finds come from the site's kind and band (curios.dm), not + * Nova's loot tables; one scanner sounds and measures; the find is stamped with its band. Sprite + * from Polaris (6cd19fe0dec6) icons/obj/xenoarchaeology.dmi "strange", carved down in two stages. + */ +/obj/item/strange_rock + name = "strange rock" + desc = "A lump of veined rock, heavier than it looks." + icon = 'voidcrew/modules/xenoarch/icons/curios.dmi' + icon_state = "strange_rock_0" + w_class = WEIGHT_CLASS_NORMAL + force = 6 + throwforce = 8 + /// ZONE_* its find is stamped with + var/band = ZONE_GREEN + /// XENOARCH_SITE_* it came out of + var/site_kind + /// 1 to 3 + var/tier = 1 + /// What is inside (a type path) + var/find_type + /// Depth of the find, in cm + var/target_depth = 10 + /// What the plain depth scanner reads + var/rough_depth = 10 + /// cm chipped off so far + var/dug = 0 + /// 0 not sounded, 1 roughly, 2 exactly + var/sounded = 0 + /// Next world.time a working tool makes its noise + var/next_work_noise = 0 + +/obj/item/strange_rock/Initialize(mapload, band, site_kind) + . = ..() + src.band = XENOARCH_BAND_INDEX(isnull(band) ? xenoarch_band_for_turf(src) : band) + src.site_kind = site_kind || pick(XENOARCH_SITE_GARDEN, XENOARCH_SITE_ANIMAL, XENOARCH_SITE_HOUSE, XENOARCH_SITE_TECHNICAL, XENOARCH_SITE_TEMPLE, XENOARCH_SITE_WAR) + tier = xenoarch_roll_small_tier(src.band) + find_type = xenoarch_small_find(src.site_kind, tier) + target_depth = rand(6, 14) + tier * XENOARCH_ROCK_DEPTH_PER_TIER + var/error = round(XENOARCH_SCAN_ERROR / 3) + rough_depth = max(1, target_depth + rand(-error, error)) + pixel_x = base_pixel_x + rand(-6, 6) + pixel_y = base_pixel_y + rand(-4, 4) + +/obj/item/strange_rock/update_icon_state() + switch(dug) + if(20 to INFINITY) + icon_state = "strange_rock_2" + if(10 to 20) + icon_state = "strange_rock_1" + else + icon_state = "strange_rock_0" + return ..() + +/obj/item/strange_rock/examine(mob/user) + . = ..() + var/error = round(XENOARCH_SCAN_ERROR / 3) + switch(sounded) + if(1) + . += "A survey tag on it reads: find at [max(1, rough_depth - error)] to [rough_depth + error] cm. Cut [dug] cm." + if(2) + . += "A survey tag on it reads: find at [target_depth] cm. Cut [dug] cm." + +/obj/item/strange_rock/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(istype(tool, /obj/item/excavation/hammer)) + return hammer_with(tool, user) + if(istype(tool, /obj/item/excavation/brush)) + return brush_with(tool, user) + if(istype(tool, /obj/item/excavation/depth_scanner)) + return sound_with(tool, user) + return NONE + +/obj/item/strange_rock/proc/hammer_with(obj/item/excavation/hammer/hammer, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(!do_after(user, hammer.head * XENOARCH_HAMMER_TIME_PER_CM, src, extra_checks = CALLBACK(src, PROC_REF(work_noise), SFX_ROCK_TAP, 0.6 SECONDS), interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src)) + return ITEM_INTERACT_BLOCKING + dug += hammer.head + if(dug > target_depth) + lose_find(user) + return ITEM_INTERACT_SUCCESS + if(sounded) + balloon_alert(user, "[dug] cm") + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/item/strange_rock/proc/brush_with(obj/item/excavation/brush/brush, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(!do_after(user, brush.brush_time, src, extra_checks = CALLBACK(src, PROC_REF(work_noise), SFX_RUSTLE, 0.9 SECONDS), interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src)) + return ITEM_INTERACT_BLOCKING + if(dug > target_depth) + lose_find(user) + return ITEM_INTERACT_SUCCESS + if(dug == target_depth) + free_find(user) + return ITEM_INTERACT_SUCCESS + dug++ + if(sounded) + balloon_alert(user, "[dug] cm") + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/item/strange_rock/proc/sound_with(obj/item/excavation/depth_scanner/scanner, mob/living/user) + if(DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + playsound(src, 'sound/effects/industrial_scan/industrial_scan2.ogg', 30, TRUE) + if(!do_after(user, scanner.scan_time, src, interaction_key = DOAFTER_SOURCE_XENOARCH)) + return ITEM_INTERACT_BLOCKING + if(QDELETED(src)) + return ITEM_INTERACT_BLOCKING + sounded = max(sounded, scanner.exact ? 2 : 1) + playsound(src, 'sound/machines/beep/twobeep.ogg', 30, TRUE) + var/error = round(XENOARCH_SCAN_ERROR / 3) + var/depth_text = scanner.exact ? "[target_depth] cm" : "[max(1, rough_depth - error)] to [rough_depth + error] cm" + to_chat(user, span_notice("[scanner] pins a survey tag to [src] and reads: Find at [depth_text]. Cut [dug] cm.")) + return ITEM_INTERACT_SUCCESS + +/// A tool's noise at most every `interval`. Always TRUE (a do_after check). +/obj/item/strange_rock/proc/work_noise(noise, interval) + if(world.time < next_work_noise) + return TRUE + next_work_noise = world.time + interval + playsound(src, noise, 35, TRUE) + return TRUE + +/// Brushed clean at the right depth: the find comes loose, into the hand that held the rock if any. +/obj/item/strange_rock/proc/free_find(mob/living/user) + var/atom/drop_spot = drop_location() + var/mob/living/holder = ismob(loc) ? loc : null + var/atom/movable/find = xenoarch_spawn_small_find(find_type, drop_spot, band) + playsound(drop_spot, 'sound/effects/rock/rock_break.ogg', 40, TRUE) + new /obj/effect/temp_visual/xenoarch_dust(get_turf(drop_spot), "#9c8c78", TRUE) + if(find) + new /obj/effect/temp_visual/xenoarch_glint(get_turf(drop_spot)) + var/atom/speaker = holder || src + speaker.visible_message( + span_notice("The last crust of rock falls away from [find]."), + blind_message = span_hear("You hear rock crumble."), + ) + record_metric(METRIC_RESEARCH, XENOARCH_METRIC_DUG, subject = "[find.type]", zone = xenoarch_band_name(band), details = list("size" = "small", "tier" = tier), actor = user, location = drop_spot) + qdel(src) + if(!find) + return null + if(holder && isitem(find) && holder.put_in_hands(find)) + return find + // On the ground it hops out of the grit. + animate(find, pixel_z = 5, time = 0.15 SECONDS, easing = SINE_EASING | EASE_OUT) + animate(pixel_z = 0, time = 0.3 SECONDS, easing = BOUNCE_EASING) + return find + +/// Cut too deep, or smashed: the find goes with the rock. +/obj/item/strange_rock/proc/lose_find(mob/living/user, reason = "cut too deep") + var/atom/drop_spot = drop_location() + var/atom/speaker = ismob(loc) ? loc : src + speaker.visible_message( + span_warning("Something inside [src] crunches, and it falls apart into gravel. Nothing in it survived."), + blind_message = span_hear("You hear rock crunch."), + ) + playsound(drop_spot, 'sound/effects/break_stone.ogg', 40, TRUE) + new /obj/effect/temp_visual/xenoarch_dust(get_turf(drop_spot), "#9c8c78", TRUE) + record_metric(METRIC_RESEARCH, XENOARCH_METRIC_LOST, subject = "[find_type]", zone = xenoarch_band_name(band), details = list("size" = "small", "reason" = reason), actor = user, location = drop_spot) + qdel(src) + +/obj/item/strange_rock/ex_act(severity, target) + if(severity == EXPLODE_LIGHT && prob(50)) + return FALSE + lose_find(null, "blast") + return TRUE diff --git a/voidcrew/modules/xenoarch/dig/tools.dm b/voidcrew/modules/xenoarch/dig/tools.dm new file mode 100644 index 00000000000..45cbff9c3cb --- /dev/null +++ b/voidcrew/modules/xenoarch/dig/tools.dm @@ -0,0 +1,236 @@ +/** + * # Excavation tools + * + * The hand kit for working dig finds: a rock hammer with interchangeable heads, a brush, a depth + * scanner, a core sampler and a bag for strange rocks, sold as a belt kit from the ship autolathe. + * The stabiliser is in stabiliser.dm. + * + * Merged from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarch/.../xenoarch_tool.dm: one + * hammer instead of seven (Nova's adjustable hammer, with a radial), one scanner that also measures + * (Nova's scanner plus tape measure). Sprites from Nova's xenoarch_items.dmi and tools.dmi. + */ +/obj/item/excavation + name = "excavation tool" + icon = 'voidcrew/modules/xenoarch/icons/dig_tools.dmi' + lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi' + righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi' + w_class = WEIGHT_CLASS_SMALL + obj_flags = CONDUCTS_ELECTRICITY + +// ===== Hammer ===== + +/// Hammer heads, in cm taken off per strike. +#define XENOARCH_HAMMER_HEADS list(1, 2, 4, 6, 10) + +/** + * A rock hammer with a set of heads. The head fitted sets how much each strike takes off. + */ +/obj/item/excavation/hammer + name = "rock hammer" + desc = "A short rock hammer with a case of interchangeable heads, from a fine pick to a broad chisel." + icon_state = "hammer_4" + inhand_icon_state = "screwdriver_head" + force = 6 + throwforce = 6 + attack_verb_continuous = list("hammers", "chips", "taps") + attack_verb_simple = list("hammer", "chip", "tap") + hitsound = 'sound/effects/rock/rocktap1.ogg' + custom_materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT) + /// cm each strike takes off + var/head = 4 + +/obj/item/excavation/hammer/examine(mob/user) + . = ..() + . += "The [head] cm head is fitted." + +/obj/item/excavation/hammer/attack_self(mob/user, modifiers) + . = ..() + if(.) + return + var/list/choices = list() + for(var/size in XENOARCH_HAMMER_HEADS) + choices["[size] cm"] = image(icon, "hammer_[size]") + var/picked = show_radial_menu(user, src, choices, require_near = TRUE, tooltips = TRUE) + if(!picked || !user.is_holding(src)) + return TRUE + var/new_head = text2num(picked) + if(!new_head || new_head == head) + return TRUE + head = new_head + icon_state = "hammer_[head]" + playsound(src, 'sound/items/tools/ratchet.ogg', 30, TRUE) + balloon_alert(user, "[head] cm head fitted") + update_appearance() + return TRUE + +#undef XENOARCH_HAMMER_HEADS + +// ===== Brush ===== + +/obj/item/excavation/brush + name = "excavation brush" + desc = "A stiff little brush for sweeping grit off something you don't want to scratch." + icon_state = "brush" + inhand_icon_state = "screwdriver_head" + w_class = WEIGHT_CLASS_TINY + custom_materials = list(/datum/material/plastic = SMALL_MATERIAL_AMOUNT * 2, /datum/material/iron = SMALL_MATERIAL_AMOUNT) + /// One pass of the brush + var/brush_time = XENOARCH_BRUSH_TIME + +/obj/item/excavation/brush/quick + name = "quick brush" + desc = "An excavation brush with a vibrating head. It buzzes against your fingers." + icon_state = "brush_quick" + custom_materials = list(/datum/material/plastic = SMALL_MATERIAL_AMOUNT * 2, /datum/material/iron = SMALL_MATERIAL_AMOUNT * 2, /datum/material/gold = SMALL_MATERIAL_AMOUNT * 2) + brush_time = XENOARCH_BRUSH_TIME_QUICK + +// ===== Depth scanner ===== + +/obj/item/excavation/depth_scanner + name = "depth scanner" + desc = "A handheld sounder that pins a survey tag to a find and reads how deep it sits and how much has been cut." + icon_state = "depth_scanner" + inhand_icon_state = "analyzer" + custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 3, /datum/material/glass = SMALL_MATERIAL_AMOUNT * 3) + /// How long a sounding takes + var/scan_time = 2 SECONDS + /// Reads the true depth, not a range + var/exact = FALSE + /// Also reads which stabilising field holds a boulder + var/reads_field = FALSE + +/obj/item/excavation/depth_scanner/advanced + name = "advanced depth scanner" + desc = "A field sounder that reads a find's exact depth and the field its rock matrix needs, right there at the dig." + icon_state = "depth_scanner_adv" + custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 3, /datum/material/glass = SMALL_MATERIAL_AMOUNT * 3, /datum/material/gold = SMALL_MATERIAL_AMOUNT * 2, /datum/material/uranium = SMALL_MATERIAL_AMOUNT * 2) + scan_time = 1 SECONDS + exact = TRUE + reads_field = TRUE + +// ===== Core sampler ===== + +/** + * Draws a core out of a boulder for the spectrometer. Holds one core at a time; the spectrometer + * empties it, or knock the core out by hand. + */ +/obj/item/excavation/core_sampler + name = "core sampler" + desc = "A hollow steel tube with a hardened bit, for drawing a core of rock out of a find." + icon_state = "sampler" + inhand_icon_state = "screwdriver_head" + custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 4) + /// Catalogue number of the boulder the core came from, or null when empty + var/sample_serial + /// The field that holds that boulder + var/sample_field + /// Radiometric age of the rock + var/sample_age + /// XENOARCH_SITE_* it came from + var/sample_site_kind + +/obj/item/excavation/core_sampler/examine(mob/user) + . = ..() + if(sample_serial) + . += "It holds a core of veined rock, tagged [sample_serial]." + else + . += "It is empty." + +/// Fills it from a boulder's record. +/obj/item/excavation/core_sampler/proc/take_core(datum/dig_boulder_record/record) + sample_serial = record.serial + sample_field = record.field + sample_age = record.age + sample_site_kind = record.site_kind + update_appearance() + +/// Empties it. +/obj/item/excavation/core_sampler/proc/clear_core() + sample_serial = null + sample_field = null + sample_age = null + sample_site_kind = null + update_appearance() + +/obj/item/excavation/core_sampler/update_icon_state() + icon_state = sample_serial ? "sampler_full" : "sampler" + return ..() + +/obj/item/excavation/core_sampler/attack_self(mob/user, modifiers) + . = ..() + if(. || !sample_serial) + return + clear_core() + playsound(src, 'sound/effects/rock/rocktap3.ogg', 30, TRUE) + to_chat(user, span_notice("You knock the core out of [src]. It crumbles.")) + return TRUE + +// ===== Bag and belt ===== + +/// A satchel for strange rocks and small finds. +/obj/item/storage/bag/excavation + name = "find satchel" + desc = "A padded satchel with a pocket for every strange rock." + icon = 'voidcrew/modules/xenoarch/icons/dig_tools.dmi' + icon_state = "find_bag" + inhand_icon_state = "satchel-explorer" + lefthand_file = 'icons/mob/inhands/equipment/backpack_lefthand.dmi' + righthand_file = 'icons/mob/inhands/equipment/backpack_righthand.dmi' + worn_icon_state = "satchel" + slot_flags = ITEM_SLOT_BELT | ITEM_SLOT_POCKETS + w_class = WEIGHT_CLASS_SMALL + resistance_flags = FLAMMABLE + storage_type = /datum/storage/bag/excavation + custom_materials = list(/datum/material/plastic = SHEET_MATERIAL_AMOUNT) + +/datum/storage/bag/excavation + max_slots = 12 + max_specific_storage = WEIGHT_CLASS_NORMAL + max_total_storage = 40 + +/datum/storage/bag/excavation/New(atom/parent, max_slots, max_specific_storage, max_total_storage, rustle_sound, remove_rustle_sound) + . = ..() + set_holdable(list( + /obj/item/strange_rock, + /obj/item/xenoarch_curio, + /obj/item/relic, + )) + +/// A webbing rig with loops for the dig kit. +/obj/item/storage/belt/excavation + name = "excavation webbing" + desc = "A chest rig with loops for hammer heads, brushes and a sampler, and a pocket for the field tags." + icon_state = "explorer2" + inhand_icon_state = "explorer2" + worn_icon_state = "explorer2" + storage_type = /datum/storage/excavation_belt + +/datum/storage/excavation_belt + max_slots = 8 + max_specific_storage = WEIGHT_CLASS_NORMAL + max_total_storage = 21 + +/datum/storage/excavation_belt/New(atom/parent, max_slots, max_specific_storage, max_total_storage, rustle_sound, remove_rustle_sound) + . = ..() + set_holdable(list( + /obj/item/excavation, + /obj/item/storage/bag/excavation, + /obj/item/mining_scanner, + /obj/item/t_scanner/adv_mining_scanner, + /obj/item/gps, + /obj/item/pickaxe/mini, + /obj/item/strange_rock, + /obj/item/flashlight, + /obj/item/paper, + /obj/item/pen, + )) + +/// The kit the autolathe prints: webbing with the hand tools and a satchel. +/obj/item/storage/belt/excavation/full + +/obj/item/storage/belt/excavation/full/PopulateContents() + new /obj/item/excavation/hammer(src) + new /obj/item/excavation/brush(src) + new /obj/item/excavation/depth_scanner(src) + new /obj/item/excavation/core_sampler(src) + new /obj/item/storage/bag/excavation(src) diff --git a/voidcrew/modules/xenoarch/effects/blood.dm b/voidcrew/modules/xenoarch/effects/blood.dm new file mode 100644 index 00000000000..b3d3dec9433 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/blood.dm @@ -0,0 +1,63 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/blood.dm. +// Voidcrew: blood_volume set directly (Nova's adjust_blood_volume() doesn't exist here); regen stops +// at a normal amount; drain never takes anyone below the point where they start to pass out. + +/datum/artifact_effect/blood + tier = ARTIFACT_TIER_RARE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC) + +/// Whether `target` has blood to work on. +/datum/artifact_effect/blood/proc/bleeds(mob/living/target) + return target.stat != DEAD && target.blood_volume > 0 && !HAS_TRAIT(target, TRAIT_NOBLOOD) + +/datum/artifact_effect/blood/regen + label_name = "Restores blood" + log_name = "Blood regeneration" + helpful = TRUE + +/datum/artifact_effect/blood/regen/do_effect_touch(mob/living/user) + if(restore(user, 20)) + to_chat(user, span_notice("Your body feels full, somehow.")) + +/datum/artifact_effect/blood/regen/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(restore(target, 2 * seconds_per_tick) && prob(10)) + to_chat(target, span_notice("Your chest feels warm.")) + +/datum/artifact_effect/blood/regen/do_effect_pulse(power) + for(var/mob/living/target as anything in living_in_range()) + if(restore(target, power * 1.5)) + to_chat(target, span_notice("Warmth floods through your veins.")) + +/datum/artifact_effect/blood/regen/proc/restore(mob/living/target, amount) + if(!bleeds(target) || target.blood_volume >= BLOOD_VOLUME_NORMAL) + return FALSE + target.blood_volume = min(BLOOD_VOLUME_NORMAL, target.blood_volume + amount * artifact_exposure(target)) + return TRUE + +/datum/artifact_effect/blood/drain + label_name = "Drains blood" + log_name = "Blood drain" + harmful = TRUE + +/datum/artifact_effect/blood/drain/do_effect_touch(mob/living/user) + if(bleed(user, 40)) + to_chat(user, span_warning("Blood beads up through the skin of your palm!")) + +/datum/artifact_effect/blood/drain/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(bleed(target, 2 * seconds_per_tick) && prob(10)) + to_chat(target, span_warning("Your nose starts to bleed.")) + +/datum/artifact_effect/blood/drain/do_effect_pulse(power) + for(var/mob/living/target as anything in living_in_range()) + if(bleed(target, power)) + to_chat(target, span_warning("You feel suddenly light-headed.")) + target.add_splatter_floor(get_turf(target), small_drip = TRUE) + +/datum/artifact_effect/blood/drain/proc/bleed(mob/living/target, amount) + if(!bleeds(target) || target.blood_volume <= BLOOD_VOLUME_OKAY) + return FALSE + target.blood_volume = max(BLOOD_VOLUME_OKAY, target.blood_volume - amount * artifact_exposure(target)) + log_harm(target) + return TRUE diff --git a/voidcrew/modules/xenoarch/effects/bodyhorror.dm b/voidcrew/modules/xenoarch/effects/bodyhorror.dm new file mode 100644 index 00000000000..c5dc7911e73 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/bodyhorror.dm @@ -0,0 +1,68 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/bodyhorror.dm. +// Voidcrew: half as likely in green; one victim per burst; not harvestable; logged. + +/datum/artifact_effect/bodyhorror + label_name = "Twists flesh" + log_name = "Body horror" + tier = ARTIFACT_TIER_EXTREME + harvestable = FALSE + harmful = TRUE + green_weight = 0.5 + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC) + allowed_release_methods = list(ARTIFACT_RELEASE_PULSE) + +/datum/artifact_effect/bodyhorror/setup() + range = min(range, 4) + +/datum/artifact_effect/bodyhorror/do_effect_pulse(power) + var/list/victims = list() + for(var/mob/living/carbon/target in living_in_range()) + if(target.stat == DEAD || HAS_TRAIT(target, TRAIT_NODISMEMBER) || artifact_exposure(target) <= 0.5) + continue + victims += target + while(length(victims)) + if(mutate_limb(pick_n_take(victims))) + return + +/// Swaps one arm or leg (or a missing one) for a living flesh limb. Returns TRUE if it did. +/datum/artifact_effect/bodyhorror/proc/mutate_limb(mob/living/carbon/target) + var/list/zones = target.get_missing_limbs() + for(var/obj/item/bodypart/part as anything in target.bodyparts) + if(part.body_zone == BODY_ZONE_HEAD || part.body_zone == BODY_ZONE_CHEST) + continue + if(HAS_TRAIT(part, TRAIT_IGNORED_BY_LIVING_FLESH) || (part.bodypart_flags & BODYPART_UNREMOVABLE)) + continue + zones += part.body_zone + if(!length(zones)) + return FALSE + var/zone = pick(zones) + var/part_type + switch(zone) + if(BODY_ZONE_L_ARM) + part_type = /obj/item/bodypart/arm/left/flesh + if(BODY_ZONE_R_ARM) + part_type = /obj/item/bodypart/arm/right/flesh + if(BODY_ZONE_L_LEG) + part_type = /obj/item/bodypart/leg/left/flesh + if(BODY_ZONE_R_LEG) + part_type = /obj/item/bodypart/leg/right/flesh + if(!part_type) + return FALSE + var/obj/item/bodypart/old_part = target.get_bodypart(zone) + if(old_part) + old_part.dismember() + else + target.emote("scream") + target.visible_message( + span_danger("[target]'s limb swells and splits, and something red and living pushes out of it!"), + span_userdanger("Your limb swells and splits, and something red and living pushes out of it!"), + blind_message = span_hear("You hear tearing flesh and cracking bone."), + ) + // The same steps the living flesh mob uses to take a limb (ruin_defender/flesh.dm). + var/obj/item/bodypart/new_part = new part_type() + var/mob/living/basic/living_limb_flesh/parasite = new + parasite.forceMove(new_part) + new_part.replace_limb(target, TRUE) + parasite.register_to_limb(new_part) + log_harm(target) + return TRUE diff --git a/voidcrew/modules/xenoarch/effects/cell.dm b/voidcrew/modules/xenoarch/effects/cell.dm new file mode 100644 index 00000000000..5121c9fd4e8 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/cell.dm @@ -0,0 +1,104 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/cellcharge.dm and celldrain.dm. +// Voidcrew: no free power. Charging works on at most two ordinary power cells at a time, no +// faster than a tier-1 recharger (the cell's own charge rate, capped at a standard cell's), and +// never on APCs, SMES units, megacells or any machine. Nova gave 125 kW to everything in range +// and a billion joules to every cell when smashed. Draining reaches the same cells. + +/datum/artifact_effect/cell + tier = ARTIFACT_TIER_UNCOMMON + minor = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC) + /// Cells it works on at once + var/cell_limit = 2 + +/// Seconds of recharger-rate charge for this cell, capped at a standard cell's rate. +/datum/artifact_effect/cell/proc/charge_for(obj/item/stock_parts/power_store/cell/cell, seconds) + return min(cell.chargerate, STANDARD_CELL_RATE) * seconds + +/// Ordinary power cells carried by `holder_atom` (itself, or anything inside it). +/datum/artifact_effect/cell/proc/cells_in(atom/holder_atom) + return holder_atom.get_all_contents_type(/obj/item/stock_parts/power_store/cell) + +/// Cells in range, loose or carried, never inside a machine. `want_room` picks cells that are +/// not full; otherwise cells that are not empty. +/datum/artifact_effect/cell/proc/cells_nearby(want_room) + . = list() + var/turf/center = source_turf() + if(!center) + return + for(var/atom/movable/thing in range(range, center)) + if(!isitem(thing) && !isliving(thing)) + continue + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_in(thing)) + if(want_room ? cell.charge < cell.maxcharge : cell.charge > 0) + . += cell + if(length(.) >= cell_limit) + return + +/datum/artifact_effect/cell/proc/after_change(obj/item/stock_parts/power_store/cell/cell) + cell.update_appearance() + if(isatom(cell.loc)) + var/atom/cell_holder = cell.loc + cell_holder.update_appearance() + +/datum/artifact_effect/cell/charge + label_name = "Charges cells" + log_name = "Cell charge" + helpful = TRUE + +/datum/artifact_effect/cell/charge/do_effect_touch(mob/living/user) + var/charged = 0 + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_in(user)) + if(charged >= cell_limit) + break + if(cell.charge >= cell.maxcharge) + continue + cell.give(charge_for(cell, 5)) + after_change(cell) + charged++ + if(charged && issilicon(user)) + to_chat(user, span_notice("Your cell takes a charge.")) + +/datum/artifact_effect/cell/charge/do_effect_aura(seconds_per_tick) + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_nearby(want_room = TRUE)) + cell.give(charge_for(cell, seconds_per_tick)) + after_change(cell) + +/datum/artifact_effect/cell/charge/do_effect_pulse(power) + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_nearby(want_room = TRUE)) + cell.give(charge_for(cell, 10)) + after_change(cell) + +/datum/artifact_effect/cell/drain + label_name = "Drains cells" + log_name = "Cell drain" + harmful = TRUE + +/datum/artifact_effect/cell/drain/do_effect_touch(mob/living/user) + var/drained = 0 + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_in(user)) + if(drained >= cell_limit) + break + if(cell.charge <= 0) + continue + cell.use(charge_for(cell, 30), force = TRUE) + after_change(cell) + drained++ + if(drained) + log_harm(user) + if(issilicon(user)) + to_chat(user, span_warning("Your cell is draining fast!")) + +/datum/artifact_effect/cell/drain/do_effect_aura(seconds_per_tick) + drain_nearby(charge_seconds = seconds_per_tick * 2) + +/datum/artifact_effect/cell/drain/do_effect_pulse(power) + drain_nearby(charge_seconds = 20) + +/datum/artifact_effect/cell/drain/proc/drain_nearby(charge_seconds) + for(var/obj/item/stock_parts/power_store/cell/cell as anything in cells_nearby(want_room = FALSE)) + cell.use(charge_for(cell, charge_seconds), force = TRUE) + after_change(cell) + var/mob/living/carrier = get(cell, /mob/living) + if(carrier) + log_harm(carrier) diff --git a/voidcrew/modules/xenoarch/effects/disgust.dm b/voidcrew/modules/xenoarch/effects/disgust.dm new file mode 100644 index 00000000000..579a6e3575d --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/disgust.dm @@ -0,0 +1,33 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/disgust.dm. +// Voidcrew: nausea that builds, rather than one touch that empties your stomach. + +/datum/artifact_effect/disgust + label_name = "Nausea" + log_name = "Disgust" + tier = ARTIFACT_TIER_UNCOMMON + minor = TRUE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_ORGANIC) + +/datum/artifact_effect/disgust/do_effect_touch(mob/living/user) + sicken(user, 50) + +/datum/artifact_effect/disgust/do_effect_aura(seconds_per_tick) + for(var/mob/living/carbon/target in living_in_range()) + if(SPT_PROB(40, seconds_per_tick)) + sicken(target, 4) + +/datum/artifact_effect/disgust/do_effect_pulse(power) + for(var/mob/living/carbon/target in living_in_range()) + sicken(target, clamp(power * 1.5, 10, 60)) + +/datum/artifact_effect/disgust/proc/sicken(mob/living/target, amount) + if(!iscarbon(target) || target.stat == DEAD) + return + var/exposure = artifact_exposure(target) + if(exposure <= 0) + return + if(prob(30)) + to_chat(target, span_warning(pick("Your stomach turns over.", "You don't feel so good.", "Your mouth floods with spit."))) + target.adjust_disgust(amount * exposure) + log_harm(target) diff --git a/voidcrew/modules/xenoarch/effects/emp.dm b/voidcrew/modules/xenoarch/effects/emp.dm new file mode 100644 index 00000000000..2a1af40041e --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/emp.dm @@ -0,0 +1,19 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/emp.dm. +// Voidcrew: smaller pulses (Nova's light radius reached ten tiles); logged. + +/datum/artifact_effect/emp + label_name = "EMP" + log_name = "EMP" + tier = ARTIFACT_TIER_RARE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC) + allowed_release_methods = list(ARTIFACT_RELEASE_PULSE) + +/datum/artifact_effect/emp/do_effect_pulse(power) + var/turf/here = source_turf() + if(!here) + return + var/light_range = clamp(range - 1, 1, 6) + empulse(here, round(light_range / 3), light_range) + for(var/mob/living/carbon/human/target in living_in_range()) + log_harm(target) diff --git a/voidcrew/modules/xenoarch/effects/feelings.dm b/voidcrew/modules/xenoarch/effects/feelings.dm new file mode 100644 index 00000000000..142fcfb1b2b --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/feelings.dm @@ -0,0 +1,105 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/feelings.dm. +// Voidcrew: trimmed message lists, plain spans instead of font tags, dizziness only from dread. + +/datum/artifact_effect/feelings + tier = ARTIFACT_TIER_COMMON + minor = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC) + /// Strong feelings + var/list/major_messages + /// Passing feelings + var/list/minor_messages + var/major_mood_type + var/minor_mood_type + /// Span proc for messages + var/good = TRUE + +/datum/artifact_effect/feelings/do_effect_touch(mob/living/user) + feel(user, 50, 100) + +/datum/artifact_effect/feelings/do_effect_aura(seconds_per_tick) + for(var/mob/living/carbon/human/target in living_in_range()) + if(SPT_PROB(2.5, seconds_per_tick)) + feel(target, 100, 0) + else if(SPT_PROB(5, seconds_per_tick)) + feel(target, 0, 100) + +/datum/artifact_effect/feelings/do_effect_pulse(power) + for(var/mob/living/carbon/human/target in living_in_range()) + feel(target, 80, 100) + +/// Gives `target` a strong feeling with `major_chance`, else a passing one with `minor_chance`. +/datum/artifact_effect/feelings/proc/feel(mob/living/target, major_chance, minor_chance) + if(!ishuman(target) || prob(100 * (1 - artifact_exposure(target)))) + return + if(prob(major_chance)) + to_chat(target, good ? span_nicegreen("[pick(major_messages)]") : span_boldwarning(pick(major_messages))) + target.add_mood_event("artifact_feeling_major", major_mood_type) + if(!good) + target.adjust_dizzy_up_to(4 SECONDS, 20 SECONDS) + else if(prob(minor_chance)) + to_chat(target, good ? span_nicegreen(pick(minor_messages)) : span_warning(pick(minor_messages))) + target.add_mood_event("artifact_feeling_minor", minor_mood_type) + +/datum/artifact_effect/feelings/good + label_name = "Good mood" + log_name = "Good feeling" + good = TRUE + major_mood_type = /datum/mood_event/artifact_good_major + minor_mood_type = /datum/mood_event/artifact_good_minor + major_messages = list( + "You want to hug everyone you meet!", + "Everything is going so well!", + "You feel giddy.", + "You could dance.", + ) + minor_messages = list( + "You feel good.", + "You've got a good feeling about this.", + "Something smells good.", + "You fight the urge to smile.", + "The colours around you seem a bit brighter.", + "Your worries seem very far away.", + ) + +/datum/artifact_effect/feelings/bad + label_name = "Dread" + log_name = "Bad feeling" + good = FALSE + major_mood_type = /datum/mood_event/artifact_bad_major + minor_mood_type = /datum/mood_event/artifact_bad_minor + major_messages = list( + "You've got to get out of here!", + "Someone's trying to kill you!", + "There's something out there!", + "What's happening to you?", + ) + minor_messages = list( + "You feel worried.", + "Something doesn't feel right.", + "You get a strange feeling in your gut.", + "You've got a bad feeling about this.", + "Your scalp prickles.", + "The shadows seem longer than they were.", + "The walls feel closer.", + ) + +/datum/mood_event/artifact_good_major + description = "Everything's going great and I don't even know why." + mood_change = 6 + timeout = 5 MINUTES + +/datum/mood_event/artifact_good_minor + description = "I feel strangely relaxed." + mood_change = 3 + timeout = 3 MINUTES + +/datum/mood_event/artifact_bad_major + description = "Something is very, very wrong around here." + mood_change = -6 + timeout = 5 MINUTES + +/datum/mood_event/artifact_bad_minor + description = "I feel uneasy and I can't say why." + mood_change = -3 + timeout = 3 MINUTES diff --git a/voidcrew/modules/xenoarch/effects/gas.dm b/voidcrew/modules/xenoarch/effects/gas.dm new file mode 100644 index 00000000000..228415d4d0d --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/gas.dm @@ -0,0 +1,84 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/gas.dm. +// Voidcrew: oxygen, nitrogen or carbon dioxide only (plasma and nitrous oxide are their own +// effects); room-temperature gas; vents indoors only, never into planet air; stops at a modest +// pressure; no destroy burst. Like the Polaris vents (effects_polaris/plasma_vent.dm) it holds a +// finite reserve, less than one gas contract asks for, shared with any battery drawn off it, so it +// is never a free nitrogen well for gas contracts. + +/datum/artifact_effect/gas + label_name = "Vents gas" + log_name = "Gas" + tier = ARTIFACT_TIER_COMMON + possible_kinds = list(ARTIFACT_ENERGY_PARTICLE, ARTIFACT_ENERGY_SYNTHESIS) + /// The gas it vents + var/gas_type = /datum/gas/oxygen + /// It stops venting once its tile reaches this pressure (kPa) + var/max_pressure = ONE_ATMOSPHERE + /// Moles left in it; it runs dry for good when this hits zero + var/reserve = 0 + /// Said it was dry + var/announced_dry = FALSE + +/datum/artifact_effect/gas/setup() + var/static/list/gas_weights = list( + /datum/gas/oxygen = 4, + /datum/gas/nitrogen = 4, + /datum/gas/carbon_dioxide = 2, + ) + gas_type = pick_weight(gas_weights) + max_pressure = rand(105, 150) + reserve = rand(150, 300) + +// Half of what is left goes with a harvest copy, so the reserve is shared, never doubled. +/datum/artifact_effect/gas/copy_settings_to(datum/artifact_effect/gas/copy) + copy.gas_type = gas_type + copy.max_pressure = max_pressure + copy.reserve = round(reserve / 2) + reserve -= copy.reserve + +/datum/artifact_effect/gas/is_spent() + return reserve <= 0 + +/datum/artifact_effect/gas/do_effect_touch(mob/living/user) + if(vent(rand(2, 8))) + to_chat(user, span_warning("Gas hisses out of [holder] around your hand.")) + +/datum/artifact_effect/gas/do_effect_aura(seconds_per_tick) + vent(rand(0, 3) * seconds_per_tick) + +/datum/artifact_effect/gas/do_effect_pulse(power) + if(vent(power / 2)) + playsound(holder, 'sound/effects/spray.ogg', 40, TRUE) + +/datum/artifact_effect/gas/do_effect_destroy() + return + +/// Lets up to `moles` of its gas out onto its tile, from its reserve. Returns TRUE if any came out. +/datum/artifact_effect/gas/proc/vent(moles) + if(moles <= 0) + return FALSE + var/turf/open/here = source_turf() + if(!istype(here) || here.planetary_atmos || isspaceturf(here)) + return FALSE + if(reserve <= 0) + run_dry(here) + return FALSE + var/datum/gas_mixture/air = here.return_air() + if(!air || air.return_pressure() >= max_pressure) + return FALSE + moles = min(moles, reserve) + reserve -= moles + var/datum/gas_mixture/puff = new + puff.assert_gas(gas_type) + puff.gases[gas_type][MOLES] = moles + puff.temperature = T20C + here.assume_air(puff) + return TRUE + +/// Its reserve is spent: one last hiss, then nothing ever again. +/datum/artifact_effect/gas/proc/run_dry(turf/here) + if(announced_dry) + return + announced_dry = TRUE + here.visible_message(span_notice("[holder] gives a thin hiss, and nothing more comes out.")) + playsound(here, 'sound/effects/spray3.ogg', 25, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) diff --git a/voidcrew/modules/xenoarch/effects/gravity.dm b/voidcrew/modules/xenoarch/effects/gravity.dm new file mode 100644 index 00000000000..e864b8e520f --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/gravity.dm @@ -0,0 +1,58 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/gravity.dm. +// Voidcrew: shorter reach (four tiles of pull or push, not eight), anchored and heavy things stay +// put, only loose items, structures and people move; any trigger. Moving people is logged. + +#define ARTIFACT_GRAVITY_PULL 1 +#define ARTIFACT_GRAVITY_PUSH 2 +#define ARTIFACT_GRAVITY_SCATTER 3 + +/datum/artifact_effect/gravity + label_name = "Gravity" + log_name = "Gravity" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_BLUESPACE) + allowed_release_methods = list(ARTIFACT_RELEASE_PULSE) + /// Pull, push or scatter + var/mode = ARTIFACT_GRAVITY_PULL + +/datum/artifact_effect/gravity/setup() + mode = pick(ARTIFACT_GRAVITY_PULL, ARTIFACT_GRAVITY_PUSH, ARTIFACT_GRAVITY_SCATTER) + range = min(range, 6) + +/datum/artifact_effect/gravity/copy_settings_to(datum/artifact_effect/gravity/copy) + copy.mode = mode + +/datum/artifact_effect/gravity/do_effect_pulse(power) + var/turf/center = source_turf() + if(!center) + return + new /obj/effect/temp_visual/circle_wave/gravity(center) + for(var/atom/movable/thing in range(range, center)) + if(thing == holder || !can_shift(thing)) + continue + var/exposure = isliving(thing) ? artifact_exposure(thing) : 1 + if(exposure <= 0) + continue + switch(mode) + if(ARTIFACT_GRAVITY_PULL) + for(var/step in 1 to round(4 * exposure)) + step_towards(thing, center) + if(ARTIFACT_GRAVITY_PUSH) + for(var/step in 1 to round(4 * exposure)) + step_away(thing, center) + if(ARTIFACT_GRAVITY_SCATTER) + var/turf/landing = pick(RANGE_TURFS(range, center)) + thing.throw_at(landing, round(4 * exposure), 2) + if(isliving(thing)) + log_harm(thing) + +/// Loose items, unanchored structures and the living; nothing anchored or immovable. +/datum/artifact_effect/gravity/proc/can_shift(atom/movable/thing) + if(thing.anchored || thing.move_resist > MOVE_FORCE_STRONG) + return FALSE + return isitem(thing) || isstructure(thing) || isliving(thing) + +#undef ARTIFACT_GRAVITY_PULL +#undef ARTIFACT_GRAVITY_PUSH +#undef ARTIFACT_GRAVITY_SCATTER diff --git a/voidcrew/modules/xenoarch/effects/hallucination.dm b/voidcrew/modules/xenoarch/effects/hallucination.dm new file mode 100644 index 00000000000..49357b5df31 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/hallucination.dm @@ -0,0 +1,35 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/drugs.dm. +// Voidcrew: real hallucinations as well as the colours, capped at a minute. + +/datum/artifact_effect/hallucination + label_name = "Hallucinations" + log_name = "Hallucination" + tier = ARTIFACT_TIER_UNCOMMON + minor = TRUE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_ORGANIC) + +/datum/artifact_effect/hallucination/do_effect_touch(mob/living/user) + if(dose(user, 20 SECONDS)) + to_chat(user, span_hypnophrase("The colours go soft at the edges.")) + +/datum/artifact_effect/hallucination/do_effect_aura(seconds_per_tick) + for(var/mob/living/carbon/target in living_in_range()) + if(SPT_PROB(20, seconds_per_tick) && dose(target, 5 SECONDS)) + to_chat(target, span_hypnophrase("Something at the corner of your eye moves.")) + +/datum/artifact_effect/hallucination/do_effect_pulse(power) + for(var/mob/living/carbon/target in living_in_range()) + if(dose(target, power SECONDS)) + to_chat(target, span_hypnophrase("Everything starts to swim.")) + +/datum/artifact_effect/hallucination/proc/dose(mob/living/target, duration) + if(!iscarbon(target) || target.stat == DEAD) + return FALSE + var/exposure = artifact_exposure(target) + if(exposure <= 0) + return FALSE + target.adjust_hallucinations_up_to(duration * exposure, 60 SECONDS) + target.adjust_drugginess_up_to(duration * exposure, 30 SECONDS) + log_harm(target) + return TRUE diff --git a/voidcrew/modules/xenoarch/effects/health.dm b/voidcrew/modules/xenoarch/effects/health.dm new file mode 100644 index 00000000000..0bd78a64401 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/health.dm @@ -0,0 +1,94 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/health.dm. +// Voidcrew: healing shares one cap per person across every artifact (artifact_capped_heal()), +// so a heal artifact bolted in a corridor is a comfort, not a medbay. Robo variants work on +// silicons, robotic mobs and prosthetic limbs. Hurt effects log like weapons. Nova's numbers +// (pulses scaling to 250 healing or 160 damage) are cut to sane ranges. + +/datum/artifact_effect/heal + label_name = "Heals" + log_name = "Heal" + tier = ARTIFACT_TIER_UNCOMMON + minor = TRUE + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC) + /// Which limbs it works on for carbons, and which mobs otherwise + var/robotic = FALSE + +/datum/artifact_effect/heal/do_effect_touch(mob/living/user) + if(mend(user, 12)) + to_chat(user, span_notice((robotic ? "Your damaged parts knit themselves back together." : "A soothing warmth spreads through you."))) + +/datum/artifact_effect/heal/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(mend(target, 0.75 * seconds_per_tick) && prob(10)) + to_chat(target, span_notice((robotic ? "A faint hum steadies your systems." : "You feel a gentle warmth from something nearby."))) + +/datum/artifact_effect/heal/do_effect_pulse(power) + for(var/mob/living/target as anything in living_in_range()) + if(mend(target, clamp(power * 0.6, 4, 20))) + to_chat(target, span_notice((robotic ? "A wave of energy mends your plating." : "A wave of warmth washes through you."))) + +/// Heals one mob within the shared cap. Returns the amount healed. +/datum/artifact_effect/heal/proc/mend(mob/living/target, amount) + if(target.stat == DEAD) + return 0 + amount *= artifact_exposure(target) + if(iscarbon(target)) + return artifact_capped_heal(target, amount, robotic ? BODYTYPE_ROBOTIC : BODYTYPE_ORGANIC) + if(robotic ? !(target.mob_biotypes & MOB_ROBOTIC) : !(target.mob_biotypes & MOB_ORGANIC)) + return 0 + return artifact_capped_heal(target, amount) + +/datum/artifact_effect/heal/robotic + label_name = "Mends machines" + log_name = "Robo-heal" + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC, ARTIFACT_ENERGY_PARTICLE) + robotic = TRUE + +/datum/artifact_effect/hurt + label_name = "Hurts" + log_name = "Hurt" + tier = ARTIFACT_TIER_UNCOMMON + minor = TRUE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_ORGANIC) + var/robotic = FALSE + +/datum/artifact_effect/hurt/do_effect_touch(mob/living/user) + if(wound(user, 8)) + to_chat(user, span_warning((robotic ? "Your systems report sudden damage!" : "A painful discharge of energy strikes you!"))) + +/datum/artifact_effect/hurt/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(wound(target, 0.5 * seconds_per_tick) && prob(10)) + to_chat(target, span_warning((robotic ? "Something nearby is stressing your plating." : "You feel a painful force radiating from something nearby."))) + +/datum/artifact_effect/hurt/do_effect_pulse(power) + for(var/mob/living/target as anything in living_in_range()) + if(wound(target, clamp(power * 0.3, 3, 12))) + to_chat(target, span_warning((robotic ? "A wave of energy buckles your plating!" : "A wave of energy tears at your skin!"))) + +/// Hurts one mob, split between brute and burn. Returns TRUE if it took any. +/datum/artifact_effect/hurt/proc/wound(mob/living/target, amount) + if(target.stat == DEAD) + return FALSE + amount *= artifact_exposure(target) + if(amount <= 0) + return FALSE + if(iscarbon(target)) + var/before = target.getBruteLoss() + target.getFireLoss() + target.take_overall_damage(amount / 2, amount / 2, required_bodytype = robotic ? BODYTYPE_ROBOTIC : BODYTYPE_ORGANIC) + if(target.getBruteLoss() + target.getFireLoss() <= before) + return FALSE + else + if(robotic ? !(target.mob_biotypes & MOB_ROBOTIC) : !(target.mob_biotypes & MOB_ORGANIC)) + return FALSE + target.take_overall_damage(amount / 2, amount / 2) + log_harm(target) + return TRUE + +/datum/artifact_effect/hurt/robotic + label_name = "Damages machines" + log_name = "Robo-hurt" + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC, ARTIFACT_ENERGY_PARTICLE) + robotic = TRUE diff --git a/voidcrew/modules/xenoarch/effects/light.dm b/voidcrew/modules/xenoarch/effects/light.dm new file mode 100644 index 00000000000..a66120473f6 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/light.dm @@ -0,0 +1,41 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/light.dm. +// Voidcrew: shines (or darkens) the whole time it is awake and costs no charge; any trigger; +// brightness kept to an ordinary lamp's range. + +/datum/artifact_effect/light + label_name = "Light" + log_name = "Light" + tier = ARTIFACT_TIER_COMMON + minor = TRUE + possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_PARTICLE) + allowed_release_methods = list(ARTIFACT_RELEASE_AURA) + /// Light colour + var/light_tint = "#fff3d6" + /// Light power sign: 1 for light, -1 for darkness + var/light_sign = 1 + +/datum/artifact_effect/light/release_aura(seconds_per_tick) + return + +/datum/artifact_effect/light/do_effect_destroy() + return + +/datum/artifact_effect/light/light_override() + return list(range, light_sign * clamp(maximum_charges / 12, 0.8, 3), light_tint) + +/datum/artifact_effect/light/on_activate() + // An artifact refreshes its own light; anything else (a battery in a utilizer) is lit here. + if(holder && !istype(holder, /obj/machinery/artifact)) + var/list/glow = light_override() + holder.set_light(glow[1], glow[2], glow[3]) + +/datum/artifact_effect/light/on_deactivate() + if(holder && !istype(holder, /obj/machinery/artifact)) + holder.set_light(0) + +/datum/artifact_effect/light/darkness + label_name = "Darkness" + log_name = "Darkness" + possible_kinds = list(ARTIFACT_ENERGY_PARTICLE, ARTIFACT_ENERGY_BLUESPACE) + light_tint = COLOR_WHITE + light_sign = -1 diff --git a/voidcrew/modules/xenoarch/effects/noise.dm b/voidcrew/modules/xenoarch/effects/noise.dm new file mode 100644 index 00000000000..b0bf2c93d43 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/noise.dm @@ -0,0 +1,34 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/noise.dm. +// Voidcrew: eerie sounds only (Nova's list mixed in bike horns and sitcom laughter); any trigger +// (Nova fixed it to oxygen, which is gone); not harvestable. + +/datum/artifact_effect/noise + label_name = "Noise" + log_name = "Noise" + tier = ARTIFACT_TIER_COMMON + minor = TRUE + harvestable = FALSE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC) + allowed_release_methods = list(ARTIFACT_RELEASE_PULSE) + +/datum/artifact_effect/noise/do_effect_pulse(power) + var/static/list/noises = list( + 'sound/effects/hallucinations/wail.ogg', + 'sound/effects/hallucinations/far_noise.ogg', + 'sound/effects/hallucinations/veryfar_noise.ogg', + 'sound/effects/hallucinations/growl1.ogg', + 'sound/effects/hallucinations/growl2.ogg', + 'sound/effects/hallucinations/growl3.ogg', + 'sound/effects/hallucinations/radio_static.ogg', + 'sound/effects/screech.ogg', + 'sound/effects/gong.ogg', + 'sound/effects/clang.ogg', + 'sound/effects/magic/curse.ogg', + 'sound/ambience/misc/signal.ogg', + 'sound/machines/airlock/airlock_alien_prying.ogg', + 'sound/misc/scary_horn.ogg', + ) + playsound(holder, pick(noises), 60, TRUE, extrarange = 6) + +/datum/artifact_effect/noise/do_effect_destroy() + playsound(holder, 'sound/effects/hallucinations/wail.ogg', 80, TRUE, extrarange = 20, pressure_affected = FALSE) diff --git a/voidcrew/modules/xenoarch/effects/radiation.dm b/voidcrew/modules/xenoarch/effects/radiation.dm new file mode 100644 index 00000000000..5c518663dcf --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/radiation.dm @@ -0,0 +1,42 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/radiate.dm. +// Voidcrew: lower aura chances (Nova reached 100% per tick); exposure logged. + +/datum/artifact_effect/radiation + label_name = "Radiation" + log_name = "Radiation" + tier = ARTIFACT_TIER_RARE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PARTICLE, ARTIFACT_ENERGY_ORGANIC) + /// How hot it runs, 1 to 5 + var/intensity = 1 + +/datum/artifact_effect/radiation/setup() + intensity = rand(1, 5) + +/datum/artifact_effect/radiation/copy_settings_to(datum/artifact_effect/radiation/copy) + copy.intensity = intensity + +/datum/artifact_effect/radiation/do_effect_touch(mob/living/user) + var/turf/here = source_turf() + if(!here) + return + radiation_pulse(here, max_range = 1, threshold = RAD_MEDIUM_INSULATION, chance = 50) + log_harm(user) + +/datum/artifact_effect/radiation/do_effect_aura(seconds_per_tick) + var/turf/here = source_turf() + if(!here) + return + radiation_pulse(here, max_range = range, threshold = RAD_MEDIUM_INSULATION, chance = 4 + intensity * 2) + log_nearby() + +/datum/artifact_effect/radiation/do_effect_pulse(power) + var/turf/here = source_turf() + if(!here) + return + radiation_pulse(here, max_range = range, threshold = RAD_MEDIUM_INSULATION, chance = clamp(power, 10, 50)) + log_nearby() + +/datum/artifact_effect/radiation/proc/log_nearby() + for(var/mob/living/carbon/human/target in living_in_range()) + log_harm(target) diff --git a/voidcrew/modules/xenoarch/effects/sleepy.dm b/voidcrew/modules/xenoarch/effects/sleepy.dm new file mode 100644 index 00000000000..38a2a324fcc --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/sleepy.dm @@ -0,0 +1,35 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/sleepy.dm. +// Voidcrew: drowsiness first, then short sleeps (Nova slept you 25 seconds per touch). + +/datum/artifact_effect/sleepy + label_name = "Puts people to sleep" + log_name = "Sleep" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_ORGANIC) + +/datum/artifact_effect/sleepy/do_effect_touch(mob/living/user) + lull(user, 30 SECONDS, 4 SECONDS) + +/datum/artifact_effect/sleepy/do_effect_aura(seconds_per_tick) + for(var/mob/living/carbon/target in living_in_range()) + if(SPT_PROB(30, seconds_per_tick)) + lull(target, 4 SECONDS) + +/datum/artifact_effect/sleepy/do_effect_pulse(power) + for(var/mob/living/carbon/target in living_in_range()) + lull(target, power * 0.8 SECONDS, power >= 30 ? 3 SECONDS : 0) + +/// Makes `target` drowsy (up to 40 seconds) and maybe nod off. +/datum/artifact_effect/sleepy/proc/lull(mob/living/target, drowsy, nap = 0) + if(!iscarbon(target) || target.stat == DEAD) + return + var/exposure = artifact_exposure(target) + if(exposure <= 0) + return + if(prob(25)) + to_chat(target, span_notice(pick("You feel a yawn coming on.", "Your eyelids are heavy.", "You could do with a nap."))) + target.adjust_drowsiness_up_to(drowsy * exposure, 40 SECONDS) + if(nap) + target.Sleeping(nap * exposure) + log_harm(target) diff --git a/voidcrew/modules/xenoarch/effects/stun.dm b/voidcrew/modules/xenoarch/effects/stun.dm new file mode 100644 index 00000000000..e970bc04431 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/stun.dm @@ -0,0 +1,38 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/stun.dm. +// Voidcrew: Nova's touch put 200 stamina damage into one hand; touch now knocks you down briefly, +// auras sap stamina, bursts can floor a room. Logged like a weapon. + +/datum/artifact_effect/stun + label_name = "Knocks people down" + log_name = "Stun" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_ORGANIC) + +/datum/artifact_effect/stun/do_effect_touch(mob/living/user) + if(sap(user, 45, 2 SECONDS)) + to_chat(user, span_warning("A jolt runs up your arm and your legs give out.")) + +/datum/artifact_effect/stun/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(SPT_PROB(15, seconds_per_tick) && sap(target, 12)) + to_chat(target, span_warning("Your limbs go heavy for a moment.")) + +/datum/artifact_effect/stun/do_effect_pulse(power) + for(var/mob/living/target as anything in living_in_range()) + if(sap(target, clamp(power * 2, 20, 70), power >= 20 ? 1.5 SECONDS : 0)) + to_chat(target, span_warning("A wave of force knocks the wind out of you!")) + +/// Saps stamina and maybe knocks down. Returns TRUE if it took. +/datum/artifact_effect/stun/proc/sap(mob/living/target, stamina, knockdown = 0) + if(target.stat != CONSCIOUS || issilicon(target)) + return FALSE + var/exposure = artifact_exposure(target) + if(exposure <= 0) + return FALSE + target.adjust_confusion_up_to(3 SECONDS * exposure, 10 SECONDS) + target.adjustStaminaLoss(stamina * exposure) + if(knockdown) + target.Knockdown(knockdown * exposure) + log_harm(target) + return TRUE diff --git a/voidcrew/modules/xenoarch/effects/teleport.dm b/voidcrew/modules/xenoarch/effects/teleport.dm new file mode 100644 index 00000000000..5b31e1ed267 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/teleport.dm @@ -0,0 +1,55 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/teleport.dm. +// Voidcrew: short hops onto open floor (never into walls, space or a chasm), through unforced +// do_teleport() so no-teleport areas and the zone guard still apply; no sparks, which light +// plasma; logged. + +/datum/artifact_effect/teleport + label_name = "Teleports" + log_name = "Teleport" + tier = ARTIFACT_TIER_RARE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_BLUESPACE) + +/datum/artifact_effect/teleport/do_effect_touch(mob/living/user) + if(hop(user, 6)) + to_chat(user, span_warning("You're suddenly standing somewhere else!")) + +/datum/artifact_effect/teleport/do_effect_aura(seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + if(SPT_PROB(10, seconds_per_tick) && hop(target, range)) + to_chat(target, span_warning("You are displaced by a strange force!")) + +/datum/artifact_effect/teleport/do_effect_pulse(power) + var/turf/center = source_turf() + if(center) + new /obj/effect/temp_visual/circle_wave/bluespace(center) + for(var/mob/living/target as anything in living_in_range()) + if(hop(target, range + 2)) + to_chat(target, span_warning("You are displaced by a strange force!")) + +/// Hops `target` to a random open floor up to `distance` tiles away. Returns TRUE if it moved. +/datum/artifact_effect/teleport/proc/hop(mob/living/target, distance) + if(target.buckled || target.anchored) + return FALSE + var/exposure = artifact_exposure(target) + distance = round(distance * exposure) + if(distance < 1) + return FALSE + var/turf/origin = get_turf(target) + var/list/landings = list() + for(var/turf/open/spot in RANGE_TURFS(distance, origin)) + if(spot == origin || isspaceturf(spot) || isgroundlessturf(spot) || islava(spot)) + continue + if(spot.is_blocked_turf(exclude_mobs = TRUE)) + continue + landings += spot + if(!length(landings)) + return FALSE + var/turf/landing = pick(landings) + new /obj/effect/temp_visual/bluespace_fissure(origin) + if(!do_teleport(target, landing, precision = 0, no_effects = TRUE, channel = TELEPORT_CHANNEL_BLUESPACE)) + return FALSE + playsound(origin, 'sound/effects/magic/blink.ogg', 40, TRUE) + playsound(landing, 'sound/effects/phasein.ogg', 40, TRUE) + log_harm(target) + return TRUE diff --git a/voidcrew/modules/xenoarch/effects/temperature.dm b/voidcrew/modules/xenoarch/effects/temperature.dm new file mode 100644 index 00000000000..752c88dba9d --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/temperature.dm @@ -0,0 +1,84 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/temperature.dm. +// Voidcrew: gentle targets (a common minor effect makes a room uncomfortable, not lethal); bodies +// never pushed past the damage limits; planet air is never written (bodies only on planet turfs); +// no destroy burst. + +/datum/artifact_effect/temperature + tier = ARTIFACT_TIER_COMMON + minor = TRUE + allowed_release_methods = list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_AURA, ARTIFACT_RELEASE_PULSE) + /// Air near it moves toward this + var/target_temp = T20C + var/target_low = T20C + var/target_high = T20C + /// Bodies never go past this (kept short of the damage limit) + var/body_limit = T20C + /// Kelvin per second the tile's air moves while the aura runs + var/air_rate = 8 + /// Kelvin per second bodies in range move while the aura runs + var/body_rate = 1.5 + /// Shown to a toucher + var/touch_message + +/datum/artifact_effect/temperature/setup() + target_temp = rand(target_low, target_high) + +/datum/artifact_effect/temperature/copy_settings_to(datum/artifact_effect/temperature/copy) + copy.target_temp = target_temp + +/datum/artifact_effect/temperature/do_effect_touch(mob/living/user) + to_chat(user, span_warning(touch_message)) + nudge_body(user, 15) + nudge_air(20) + +/datum/artifact_effect/temperature/do_effect_aura(seconds_per_tick) + nudge_air(air_rate * seconds_per_tick) + for(var/mob/living/target as anything in living_in_range()) + nudge_body(target, body_rate * seconds_per_tick) + +/datum/artifact_effect/temperature/do_effect_pulse(power) + nudge_air(clamp(power * 2, 10, 60)) + for(var/mob/living/target as anything in living_in_range()) + nudge_body(target, clamp(power / 3, 3, 12)) + +/datum/artifact_effect/temperature/do_effect_destroy() + return + +/// Moves the air on its own tile toward the target. Never planet air, never vacuum. +/datum/artifact_effect/temperature/proc/nudge_air(amount) + var/turf/open/here = source_turf() + if(!istype(here) || here.planetary_atmos || isspaceturf(here)) + return + var/datum/gas_mixture/air = here.return_air() + if(!air || air.total_moles() <= 0) + return + var/difference = target_temp - air.temperature + if(abs(difference) < 1) + return + air.temperature += clamp(difference, -amount, amount) + here.air_update_turf(FALSE, FALSE) + +/datum/artifact_effect/temperature/proc/nudge_body(mob/living/target, amount) + var/goal = target_temp > T20C ? min(target_temp, body_limit) : max(target_temp, body_limit) + var/difference = goal - target.bodytemperature + if(abs(difference) < 0.5) + return + target.adjust_bodytemperature(clamp(difference, -amount, amount) * artifact_exposure(target)) + +/datum/artifact_effect/temperature/heat + label_name = "Heat" + log_name = "Heat" + possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_SYNTHESIS) + target_low = 310 + target_high = 345 + body_limit = BODYTEMP_HEAT_DAMAGE_LIMIT - 5 + touch_message = "A wave of heat runs up your arm." + +/datum/artifact_effect/temperature/cold + label_name = "Cold" + log_name = "Cold" + possible_kinds = list(ARTIFACT_ENERGY_SYNTHESIS, ARTIFACT_ENERGY_BLUESPACE) + target_low = 255 + target_high = 280 + body_limit = BODYTEMP_COLD_DAMAGE_LIMIT + 5 + touch_message = "A chill runs up your spine." diff --git a/voidcrew/modules/xenoarch/effects/tesla.dm b/voidcrew/modules/xenoarch/effects/tesla.dm new file mode 100644 index 00000000000..9d88b5f38a0 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects/tesla.dm @@ -0,0 +1,26 @@ +// Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/effects/tesla.dm. +// Voidcrew: ZAP_GENERATES_POWER removed, so tesla coils get nothing from it; weaker arcs (Nova's +// reached 90 burn); not harvestable; logged. + +/datum/artifact_effect/tesla + label_name = "Lightning" + log_name = "Tesla" + tier = ARTIFACT_TIER_EXTREME + harvestable = FALSE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC, ARTIFACT_ENERGY_CONCENTRATED) + allowed_release_methods = list(ARTIFACT_RELEASE_PULSE) + /// Never ZAP_GENERATES_POWER: no running a ship off an artifact. + var/zap_flags = ZAP_OBJ_DAMAGE | ZAP_MOB_DAMAGE | ZAP_MOB_STUN + +/datum/artifact_effect/tesla/setup() + maximum_charges = max(maximum_charges, 15) + +/datum/artifact_effect/tesla/do_effect_pulse(power) + if(QDELETED(holder)) + return + var/reach = 3 + rand(0, 2) + playsound(holder, 'sound/effects/magic/lightningshock.ogg', 60, TRUE, extrarange = 5) + tesla_zap(source = holder, zap_range = reach, power = rand(12, 30) * 1000, cutoff = 1e4, zap_flags = zap_flags) + for(var/mob/living/target in range(reach, source_turf())) + log_harm(target) diff --git a/voidcrew/modules/xenoarch/effects_polaris/animate.dm b/voidcrew/modules/xenoarch/effects_polaris/animate.dm new file mode 100644 index 00000000000..99606713e13 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/animate.dm @@ -0,0 +1,123 @@ +// Artifact effect: animate. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/animate_anomaly.dm, +// also in VOREStation (9335d66b9fdf). Voidcrew: the artifact itself lurches one step at a time +// toward the nearest person (or away from a hand laid on it). It only moves with an ordinary +// Move(), so walls, doors and people stop it, and it never steps into space, open air, lava or a +// chasm. Bolted down, it strains against the bolts instead. Not harvestable: only an artifact +// can walk. No destroy burst. + +/datum/artifact_effect/animate + label_name = "Moves on its own" + log_name = "Animate" + tier = ARTIFACT_TIER_COMMON + harvestable = FALSE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_BLUESPACE) + /// Who it is following + var/datum/weakref/quarry_ref + /// Throttles the lurch and strain messages + COOLDOWN_DECLARE(message_cooldown) + +/datum/artifact_effect/animate/setup() + range = max(range, 3) + +/datum/artifact_effect/animate/Destroy(force) + quarry_ref = null + return ..() + +/datum/artifact_effect/animate/do_effect_touch(mob/living/user) + var/obj/machinery/artifact/artifact = holder + if(!istype(artifact) || !isturf(artifact.loc)) + return + if(lurch(get_step_away(artifact, user))) + artifact.visible_message(span_warning("[artifact] lurches away from [user]!")) + +/datum/artifact_effect/animate/do_effect_aura(seconds_per_tick) + stalk() + +/// A burst is a short run of lurches, a beat apart. +/datum/artifact_effect/animate/do_effect_pulse(power) + if(!stalk()) + return + for(var/step in 1 to clamp(round(power / 12), 1, 3) - 1) + addtimer(CALLBACK(src, PROC_REF(stalk)), step * 0.4 SECONDS, TIMER_DELETE_ME) + +/datum/artifact_effect/animate/do_effect_destroy() + return + +/// One step toward whoever it is following. Returns TRUE if it moved. +/datum/artifact_effect/animate/proc/stalk() + var/obj/machinery/artifact/artifact = holder + if(!istype(artifact) || !isturf(artifact.loc)) + return FALSE + var/mob/living/quarry = find_quarry() + if(!quarry) + return FALSE + artifact.setDir(get_dir(artifact, quarry)) + if(get_dist(artifact, quarry) <= 1) + return FALSE + if(!lurch(get_step_to(artifact, quarry))) + return FALSE + if(COOLDOWN_FINISHED(src, message_cooldown)) + COOLDOWN_START(src, message_cooldown, 8 SECONDS) + artifact.visible_message(span_warning("[artifact] lurches toward [quarry].")) + return TRUE + +/// Steps onto `destination` if it can stand there. Returns TRUE if it moved. +/datum/artifact_effect/animate/proc/lurch(turf/destination) + var/obj/machinery/artifact/artifact = holder + if(!istype(artifact) || !isturf(destination) || destination.z != artifact.z) + return FALSE + if(isspaceturf(destination) || isgroundlessturf(destination) || islava(destination) || ischasm(destination)) + return FALSE + if(artifact.anchored) + strain(artifact) + return FALSE + var/turf/start = artifact.loc + if(!artifact.Move(destination, get_dir(start, destination)) || artifact.loc == start) + return FALSE + playsound(artifact, pick('sound/effects/footstep/heavy1.ogg', 'sound/effects/footstep/heavy2.ogg'), 40, TRUE) + hop(artifact) + return TRUE + +/// Bolted down, it rocks against the bolts. +/datum/artifact_effect/animate/proc/strain(obj/machinery/artifact/artifact) + playsound(artifact, 'sound/effects/creak/creak1.ogg', 35, TRUE) + var/shove = pick(-3, 3) + animate(artifact, pixel_x = artifact.base_pixel_x + shove, time = 0.1 SECONDS, flags = ANIMATION_PARALLEL) + animate(pixel_x = artifact.base_pixel_x, time = 0.2 SECONDS) + if(COOLDOWN_FINISHED(src, message_cooldown)) + COOLDOWN_START(src, message_cooldown, 8 SECONDS) + artifact.visible_message(span_warning("[artifact] strains against its bolts.")) + +/// A heavy little hop. +/datum/artifact_effect/animate/proc/hop(obj/machinery/artifact/artifact) + animate(artifact, pixel_z = 4, time = 0.1 SECONDS, easing = SINE_EASING | EASE_OUT, flags = ANIMATION_PARALLEL) + animate(pixel_z = 0, time = 0.15 SECONDS, easing = SINE_EASING | EASE_IN) + +/** + * The person it follows: the last one while they stay close and awake, else the nearest + * conscious mob in range, preferring people with a mind over animals. + */ +/datum/artifact_effect/animate/proc/find_quarry() + var/turf/center = source_turf() + if(!center) + return null + var/mob/living/quarry = quarry_ref?.resolve() + if(quarry && quarry.stat == CONSCIOUS && quarry.z == center.z && get_dist(center, quarry) <= range) + return quarry + quarry = null + var/quarry_distance = INFINITY + var/quarry_has_mind = FALSE + for(var/mob/living/candidate in living_in_range()) + if(candidate.stat != CONSCIOUS) + continue + var/has_mind = !!candidate.mind + var/distance = get_dist(center, candidate) + if(quarry_has_mind && !has_mind) + continue + if((has_mind && !quarry_has_mind) || distance < quarry_distance) + quarry = candidate + quarry_distance = distance + quarry_has_mind = has_mind + quarry_ref = quarry ? WEAKREF(quarry) : null + return quarry diff --git a/voidcrew/modules/xenoarch/effects_polaris/berserk.dm b/voidcrew/modules/xenoarch/effects_polaris/berserk.dm new file mode 100644 index 00000000000..f7fbe36903d --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/berserk.dm @@ -0,0 +1,35 @@ +// Artifact effect: berserk. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/berserk.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: a status effect instead of Polaris' /datum/modifier. Rage +// makes every punch land, weapons hit a quarter harder and swings come faster; when it ends the +// person is drained and slow for a while, and can't be enraged again until they recover. Polaris' +// brain damage per dose is dropped: the crash afterwards is the price. Works on people only. +// Logged like harm, since the crash is forced on whoever it touches. + +/datum/artifact_effect/bestow/berserk + label_name = "Rage" + log_name = "Berserk" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_ORGANIC) + status_type = /datum/status_effect/artifact/berserk + touch_duration = 30 SECONDS + pulse_duration = 25 SECONDS + aura_duration = 10 SECONDS + aura_chance = 6 + +/datum/artifact_effect/bestow/berserk/can_bestow(mob/living/target) + return ..() && iscarbon(target) && target.stat == CONSCIOUS + +/datum/artifact_effect/bestow/berserk/on_bestowed(mob/living/target) + target.visible_message( + span_warning("[target]'s face twists with sudden fury."), + span_userdanger("Heat floods your face. Your hands want something to break."), + ) + playsound(target, 'sound/effects/magic/demon_attack1.ogg', 15, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/bestow/berserk/on_renewed(mob/living/target) + to_chat(target, span_warning("Your anger flares up again.")) + +/datum/artifact_effect/bestow/berserk/on_refused(mob/living/target) + to_chat(target, span_notice("A flash of anger comes and goes. You're too tired to hold onto it.")) diff --git a/voidcrew/modules/xenoarch/effects_polaris/disarm.dm b/voidcrew/modules/xenoarch/effects_polaris/disarm.dm new file mode 100644 index 00000000000..b454885922a --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/disarm.dm @@ -0,0 +1,50 @@ +// Artifact effect: disarm. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/disarm.dm. Voidcrew: +// pries open the hand people are using, so what they hold drops at their feet (never thrown, so +// nothing lands in a chasm or lava); items that can't be dropped stay put. Run from a carried +// battery, it pries open its carrier's hand too. Logged like a weapon. + +/datum/artifact_effect/disarm + label_name = "Makes people drop things" + log_name = "Disarm" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_BLUESPACE) + +/datum/artifact_effect/disarm/do_effect_touch(mob/living/user) + pry(user) + +/datum/artifact_effect/disarm/do_effect_aura(seconds_per_tick) + for(var/mob/living/target in living_in_range()) + if(SPT_PROB(6, seconds_per_tick)) + pry(target) + +/datum/artifact_effect/disarm/do_effect_pulse(power) + var/turf/center = source_turf() + if(center) + new /obj/effect/temp_visual/circle_wave/artifact_ring/pry(center, max(range * 0.6, 1.5)) + for(var/mob/living/target in living_in_range()) + pry(target) + +/// Makes `target` drop what is in their active hand. Returns TRUE if it fell. +/datum/artifact_effect/disarm/proc/pry(mob/living/target) + if(target.stat != CONSCIOUS) + return FALSE + if(!prob(100 * artifact_exposure(target))) + return FALSE + var/obj/item/held = target.get_active_held_item() + if(!held || !target.dropItemToGround(held)) + return FALSE + target.visible_message( + span_warning("[target]'s hand jerks open and [held] falls to the floor."), + span_warning("Something pries your fingers open. [held] falls out of your grip!"), + ) + playsound(target, 'sound/items/weapons/thudswoosh.ogg', 40, TRUE) + new /obj/effect/temp_visual/telekinesis(get_turf(target)) + log_harm(target) + return TRUE + +/// A faint violet ripple for the burst. +/obj/effect/temp_visual/circle_wave/artifact_ring/pry + color = "#e17ceb" + max_alpha = 110 diff --git a/voidcrew/modules/xenoarch/effects_polaris/electric_field.dm b/voidcrew/modules/xenoarch/effects_polaris/electric_field.dm new file mode 100644 index 00000000000..20de4024364 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/electric_field.dm @@ -0,0 +1,99 @@ +// Artifact effect: electric field. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/electric_field.dm, +// also in VOREStation (9335d66b9fdf). Voidcrew: arcs only find robots, prosthetic-bodied mobs and +// people holding something metal, so it can be read and avoided (empty hands, insulated gloves); +// Polaris shocked everyone in range for up to 40 burn. Field arcs never stun, bursts only knock +// down briefly, and every arc is logged. A hand on it grounds the toucher: the charge leaps to +// everyone else nearby instead, as in Polaris. Lights in range flicker as it charges. Run from a +// carried battery, it arcs to its carrier too. + +/// Lights one charge can flicker, so a room full of lamps costs no more than a few +#define ARTIFACT_FIELD_MAX_FLICKERS 6 + +/datum/artifact_effect/electric_field + label_name = "Shocks" + log_name = "Electric field" + tier = ARTIFACT_TIER_UNCOMMON + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC, ARTIFACT_ENERGY_CONCENTRATED) + +/datum/artifact_effect/electric_field/do_effect_touch(mob/living/user) + flicker_lights() + var/arcs = 0 + for(var/mob/living/target in living_in_range()) + if(target == user) + continue + if(arc_to(target, rand(10, 15), knockdown = FALSE)) + arcs++ + if(arcs) + to_chat(user, span_warning("A charge runs up your arm, through you, and leaps away.")) + playsound(source_turf(), 'sound/effects/magic/lightningshock.ogg', 35, TRUE) + else + to_chat(user, span_notice("The hair on your arm stands up, then settles.")) + +/datum/artifact_effect/electric_field/do_effect_aura(seconds_per_tick) + if(SPT_PROB(15, seconds_per_tick)) + flicker_lights(2) + for(var/mob/living/target in living_in_range()) + if(SPT_PROB(10, seconds_per_tick)) + arc_to(target, rand(3, 6), knockdown = FALSE) + +/datum/artifact_effect/electric_field/do_effect_pulse(power) + var/turf/center = source_turf() + if(!center) + return + flicker_lights() + playsound(center, 'sound/effects/magic/lightningshock.ogg', 50, TRUE) + new /obj/effect/temp_visual/electricity(center) + for(var/mob/living/target in living_in_range()) + arc_to(target, clamp(power * 0.4, 6, 18), knockdown = power >= 25) + +/** + * Arcs to `target` if it is a machine or holds something metal. Returns TRUE if the shock took. + * Insulated gloves and a suit's insulation work as they do against any shock. + */ +/datum/artifact_effect/electric_field/proc/arc_to(mob/living/target, damage, knockdown) + var/atom/source = artifact_effect_visible_source(holder) + if(target.stat == DEAD || !conducts(target)) + return FALSE + damage *= artifact_exposure(target) + if(damage < 1) + return FALSE + var/flags = SHOCK_SUPPRESS_MESSAGE | (knockdown ? SHOCK_KNOCKDOWN : SHOCK_NOSTUN) + // Positional on purpose: only the carbon override has the jitter, stutter and stun arguments. + if(!target.electrocute_act(damage, holder, 1, flags, 4 SECONDS, 2 SECONDS, 1 SECONDS)) + return FALSE + if(source != target) + source?.Beam(target, icon_state = "lightning[rand(1, 12)]", time = 0.5 SECONDS) + if(issilicon(target) || (target.mob_biotypes & MOB_ROBOTIC)) + to_chat(target, span_danger("ERROR: Electrical fault detected!")) + target.adjust_stutter(3 SECONDS) + else if(source == target) + to_chat(target, span_danger("Sparks crawl up your arm!")) + else + to_chat(target, span_danger("A spark leaps from [source] to you!")) + log_harm(target) + return TRUE + +/// Robots and anything with metal in hand make a path for the charge. +/datum/artifact_effect/electric_field/proc/conducts(mob/living/target) + if(issilicon(target) || (target.mob_biotypes & MOB_ROBOTIC)) + return TRUE + for(var/obj/item/held in target.held_items) + if(held.obj_flags & CONDUCTS_ELECTRICITY) + return TRUE + return FALSE + +/// Makes a few lights in range stutter. +/datum/artifact_effect/electric_field/proc/flicker_lights(limit = ARTIFACT_FIELD_MAX_FLICKERS) + var/turf/center = source_turf() + if(!center) + return + var/flickered = 0 + for(var/obj/machinery/light/light in range(range, center)) + if(flickered >= limit) + return + if(light.flicker(rand(3, 6))) + flickered++ + +#undef ARTIFACT_FIELD_MAX_FLICKERS diff --git a/voidcrew/modules/xenoarch/effects_polaris/extinguisher.dm b/voidcrew/modules/xenoarch/effects_polaris/extinguisher.dm new file mode 100644 index 00000000000..2b42ca52bc1 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/extinguisher.dm @@ -0,0 +1,107 @@ +// Artifact effect: extinguisher. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/extinguisher.dm. +// Voidcrew: puts out burning people, burning objects and open flames in its range, and wets +// people a little so they are slow to catch again. Air is only cooled indoors; on planet ground +// it snuffs the flames and never touches the shared planet air. No wet floors (Polaris left +// slippery tiles); no destroy burst. + +/// Hot air on a fire tile is pulled down toward this +#define ARTIFACT_EXTINGUISH_COOL_TO (T20C + 30) +/// At most this many kelvin come off a fire tile's air per douse +#define ARTIFACT_EXTINGUISH_COOL_STEP 120 + +/datum/artifact_effect/extinguisher + label_name = "Puts out fires" + log_name = "Extinguisher" + tier = ARTIFACT_TIER_COMMON + minor = TRUE + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_SYNTHESIS, ARTIFACT_ENERGY_PARTICLE) + +/datum/artifact_effect/extinguisher/do_effect_touch(mob/living/user) + douse(user, 4) + to_chat(user, span_notice("Cold mist beads on your skin.")) + playsound(source_turf(), 'sound/effects/extinguish.ogg', 25, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) + +/datum/artifact_effect/extinguisher/do_effect_aura(seconds_per_tick) + var/turf/center = source_turf() + if(!center) + return + var/quenched = quench_area(center) + for(var/mob/living/target in living_in_range()) + if(target.on_fire) + douse(target, 2) + quenched = TRUE + if(quenched) + playsound(center, 'sound/effects/extinguish.ogg', 30, TRUE) + else if(SPT_PROB(15, seconds_per_tick)) + new /obj/effect/temp_visual/artifact_mist(center) + +/datum/artifact_effect/extinguisher/do_effect_pulse(power) + var/turf/center = source_turf() + if(!center) + return + new /obj/effect/temp_visual/circle_wave/artifact_ring/mist(center, max(range * 0.6, 1.5)) + playsound(center, 'sound/effects/extinguish.ogg', 45, TRUE) + quench_area(center) + for(var/mob/living/target in living_in_range()) + if(!douse(target, 3)) + to_chat(target, span_notice("A cold, damp mist rolls over you.")) + +/datum/artifact_effect/extinguisher/do_effect_destroy() + return + +/// Puts out `target` and leaves them damp. Returns TRUE (and tells them) if it put them out. +/datum/artifact_effect/extinguisher/proc/douse(mob/living/target, wetness) + var/was_burning = target.on_fire + target.extinguish_mob() + target.adjust_wet_stacks(wetness * artifact_exposure(target)) + if(was_burning && !target.on_fire) + to_chat(target, span_notice("A cold mist rolls over you, and the flames on you gutter out.")) + return TRUE + return FALSE + +/// Snuffs open flames and burning objects in range. Returns TRUE if it put anything out. +/datum/artifact_effect/extinguisher/proc/quench_area(turf/center) + . = FALSE + for(var/obj/effect/hotspot/flame in range(range, center)) + var/turf/open/flame_turf = flame.loc + qdel(flame) + cool_air(flame_turf) + new /obj/effect/temp_visual/artifact_mist(flame_turf) + . = TRUE + for(var/obj/burning in range(range, center)) + if(burning.resistance_flags & ON_FIRE) + burning.extinguish() + . = TRUE + +/// Takes the heat out of an indoor fire tile so it doesn't flare straight back. Never planet air. +/datum/artifact_effect/extinguisher/proc/cool_air(turf/open/spot) + if(!istype(spot) || spot.planetary_atmos || isspaceturf(spot)) + return + var/datum/gas_mixture/air = spot.return_air() + if(!air || air.temperature <= ARTIFACT_EXTINGUISH_COOL_TO) + return + air.temperature = max(ARTIFACT_EXTINGUISH_COOL_TO, air.temperature - ARTIFACT_EXTINGUISH_COOL_STEP) + spot.air_update_turf(FALSE, FALSE) + +/// A puff of cold mist. +/obj/effect/temp_visual/artifact_mist + icon_state = "extinguish" + alpha = 200 + duration = 0.8 SECONDS + +/obj/effect/temp_visual/artifact_mist/Initialize(mapload) + . = ..() + pixel_x = rand(-6, 6) + pixel_y = rand(-4, 8) + animate(src, alpha = 0, pixel_y = pixel_y + 6, time = duration) + +/// A ring of mist rolling out from the artifact. +/obj/effect/temp_visual/circle_wave/artifact_ring/mist + color = "#cfe9ff" + max_alpha = 170 + duration = 0.8 SECONDS + +#undef ARTIFACT_EXTINGUISH_COOL_TO +#undef ARTIFACT_EXTINGUISH_COOL_STEP diff --git a/voidcrew/modules/xenoarch/effects_polaris/faraday.dm b/voidcrew/modules/xenoarch/effects_polaris/faraday.dm new file mode 100644 index 00000000000..117dfd06f43 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/faraday.dm @@ -0,0 +1,25 @@ +// Artifact effect: faraday. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/faraday.dm. +// Voidcrew: a status effect that swallows EMPs for the wearer and everything they carry +// (Polaris used a /datum/modifier); doses never stack past two minutes. + +/datum/artifact_effect/bestow/faraday + label_name = "EMP shielding" + log_name = "Faraday" + tier = ARTIFACT_TIER_UNCOMMON + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ELECTROMAGNETIC, ARTIFACT_ENERGY_PARTICLE) + status_type = /datum/status_effect/artifact/faraday + touch_duration = 90 SECONDS + pulse_duration = 30 SECONDS + aura_duration = 10 SECONDS + +/datum/artifact_effect/bestow/faraday/on_bestowed(mob/living/target) + if(issilicon(target)) + to_chat(target, span_notice("Your sensors go quiet. Background interference: none.")) + else + to_chat(target, span_notice("The hair on your arms lies flat, and a cold hush settles over your skin.")) + playsound(target, 'sound/effects/magic/magic_block.ogg', 20, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/bestow/faraday/on_renewed(mob/living/target) + to_chat(target, span_notice("The hush on your skin deepens.")) diff --git a/voidcrew/modules/xenoarch/effects_polaris/feysight.dm b/voidcrew/modules/xenoarch/effects_polaris/feysight.dm new file mode 100644 index 00000000000..60c5fb1ca08 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/feysight.dm @@ -0,0 +1,33 @@ +// Artifact effect: feysight. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/feysight.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: a status effect giving thermal sight (living things show +// through walls) with a faint green tint, instead of Polaris' /datum/modifier. The first dose +// still costs a pounding headache, as in Polaris. Doses never stack past 45 seconds. + +#define ARTIFACT_FEYSIGHT_HEADACHE 10 + +/datum/artifact_effect/bestow/feysight + label_name = "Second sight" + log_name = "Feysight" + tier = ARTIFACT_TIER_RARE + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC) + status_type = /datum/status_effect/artifact/feysight + touch_duration = 30 SECONDS + pulse_duration = 20 SECONDS + aura_duration = 8 SECONDS + aura_chance = 8 + +/datum/artifact_effect/bestow/feysight/can_bestow(mob/living/target) + return iscarbon(target) && target.stat != DEAD + +/datum/artifact_effect/bestow/feysight/on_bestowed(mob/living/target) + to_chat(target, span_hypnophrase("The walls go thin as paper, and through them, warm shapes move.")) + to_chat(target, span_warning("The inside of your head hurts...")) + target.adjustStaminaLoss(ARTIFACT_FEYSIGHT_HEADACHE) + playsound(target, 'sound/effects/magic/magic_block_mind.ogg', 20, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/bestow/feysight/on_renewed(mob/living/target) + to_chat(target, span_hypnophrase("The shapes behind the walls sharpen.")) + +#undef ARTIFACT_FEYSIGHT_HEADACHE diff --git a/voidcrew/modules/xenoarch/effects_polaris/forcefield.dm b/voidcrew/modules/xenoarch/effects_polaris/forcefield.dm new file mode 100644 index 00000000000..7c5e1eac4be --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/forcefield.dm @@ -0,0 +1,129 @@ +// Artifact effect: forcefield. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/forcefield.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: a ring of short-lived force walls two tiles out (three for a +// strong one) instead of Polaris' permanent sixteen-wall box. A burst or a touch raises it for a +// few seconds; a field holds it up only while the field runs and drops it the moment it rests. +// Walls skip tiles already blocked (walls, closed doors, machines) and fade in, so nobody is +// sealed into a wall. Everything it raised goes when it sleeps or is destroyed. Not harvestable. + +/// How long a field keeps its ring after its last run before letting it drop +#define ARTIFACT_FORCEFIELD_AURA_GRACE (3 SECONDS) + +/datum/artifact_effect/forcefield + label_name = "Force walls" + log_name = "Forcefield" + tier = ARTIFACT_TIER_UNCOMMON + harvestable = FALSE + possible_kinds = list(ARTIFACT_ENERGY_PARTICLE, ARTIFACT_ENERGY_BLUESPACE) + /// Tiles from the artifact to the ring + var/ring_radius = 2 + /// How long a burst or touch keeps the ring up + var/ring_time = 10 SECONDS + /// The walls it raised that still stand + var/list/obj/effect/forcefield/artifact/walls = list() + /// world.time a field last held the ring up + var/last_held = 0 + +/datum/artifact_effect/forcefield/setup() + switch(strength) + if(ARTIFACT_STRENGTH_LARGE) + ring_radius = 3 + ring_time = 15 SECONDS + if(ARTIFACT_STRENGTH_MEDIUM) + ring_time = 12 SECONDS + else + ring_time = 8 SECONDS + // A touch needs a good part of the store, so a hand can't keep the ring up for free. + touch_cost = max(touch_cost, round(maximum_charges / 2)) + +/datum/artifact_effect/forcefield/copy_settings_to(datum/artifact_effect/forcefield/copy) + copy.ring_radius = ring_radius + copy.ring_time = ring_time + +/datum/artifact_effect/forcefield/Destroy(force) + drop_ring() + return ..() + +/datum/artifact_effect/forcefield/on_deactivate() + drop_ring() + +/datum/artifact_effect/forcefield/tick(seconds_per_tick) + . = ..() + if(release_method == ARTIFACT_RELEASE_AURA && length(walls) && world.time > last_held + ARTIFACT_FORCEFIELD_AURA_GRACE) + drop_ring() + +/datum/artifact_effect/forcefield/do_effect_touch(mob/living/user) + to_chat(user, span_notice("The air around [holder] goes taut as a drumskin.")) + raise_ring(ring_time) + +/datum/artifact_effect/forcefield/do_effect_aura(seconds_per_tick) + last_held = world.time + if(!length(walls)) + // Long enough to outlast any one run; the field drops it itself when it rests. + raise_ring(2 MINUTES) + +/datum/artifact_effect/forcefield/do_effect_pulse(power) + raise_ring(ring_time) + +/datum/artifact_effect/forcefield/do_effect_destroy() + return + +/// Raises a fresh ring around the artifact. Returns how many walls went up. +/datum/artifact_effect/forcefield/proc/raise_ring(duration) + drop_ring() + var/turf/center = source_turf() + if(!center) + return 0 + var/tint = artifact_energy_kind(energy_kind).color + for(var/turf/open/spot in RANGE_TURFS(ring_radius, center)) + if(max(abs(spot.x - center.x), abs(spot.y - center.y)) != ring_radius) + continue + if(isspaceturf(spot) || isgroundlessturf(spot) || spot.is_blocked_turf(exclude_mobs = TRUE)) + continue + var/obj/effect/forcefield/artifact/wall = new(spot, duration, tint) + walls += wall + RegisterSignal(wall, COMSIG_QDELETING, PROC_REF(wall_gone)) + if(length(walls)) + playsound(center, 'sound/effects/magic/forcewall.ogg', 45, TRUE) + center.visible_message(span_warning("Walls of rippling light spring up around [holder]!")) + return length(walls) + +/// Takes down every wall it raised. +/datum/artifact_effect/forcefield/proc/drop_ring() + if(!length(walls)) + return + for(var/obj/effect/forcefield/artifact/wall in walls) + UnregisterSignal(wall, COMSIG_QDELETING) + wall.fade_out() + walls.Cut() + +/// A wall timed out or was deleted: forget it. +/datum/artifact_effect/forcefield/proc/wall_gone(datum/source) + SIGNAL_HANDLER + walls -= source + +/// One pane of the ring. +/obj/effect/forcefield/artifact + name = "shimmering wall" + desc = "A pane of rippling light, hard as glass." + icon_state = "shield-greyscale" + alpha = 0 + initial_duration = 10 SECONDS + +/obj/effect/forcefield/artifact/Initialize(mapload, duration, tint) + if(isnum(duration)) + initial_duration = duration + . = ..() + if(tint) + color = tint + animate(src, alpha = 190, time = 0.4 SECONDS) + +/// Fades and goes, rather than blinking out. +/obj/effect/forcefield/artifact/proc/fade_out() + if(QDELETED(src)) + return + set_density(FALSE) + animate(src, alpha = 0, time = 0.3 SECONDS) + QDEL_IN(src, 0.3 SECONDS) + +#undef ARTIFACT_FORCEFIELD_AURA_GRACE diff --git a/voidcrew/modules/xenoarch/effects_polaris/fortify.dm b/voidcrew/modules/xenoarch/effects_polaris/fortify.dm new file mode 100644 index 00000000000..c89b845939a --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/fortify.dm @@ -0,0 +1,25 @@ +// Artifact effect: fortify. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/fortify.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: a short status effect taking 15% off brute and burn +// (Polaris used a /datum/modifier); doses never stack past a minute and a half. + +/datum/artifact_effect/bestow/fortify + label_name = "Toughens skin" + log_name = "Fortify" + tier = ARTIFACT_TIER_UNCOMMON + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_ORGANIC) + status_type = /datum/status_effect/artifact/fortify + touch_duration = 60 SECONDS + pulse_duration = 30 SECONDS + aura_duration = 10 SECONDS + +/datum/artifact_effect/bestow/fortify/on_bestowed(mob/living/target) + if(issilicon(target)) + to_chat(target, span_notice("Your plating hums and stiffens.")) + else + to_chat(target, span_notice("Your skin tightens and goes tough as old leather.")) + playsound(target, 'sound/effects/magic/fleshtostone.ogg', 20, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/bestow/fortify/on_renewed(mob/living/target) + to_chat(target, span_notice("Your skin tightens again.")) diff --git a/voidcrew/modules/xenoarch/effects_polaris/gaia.dm b/voidcrew/modules/xenoarch/effects_polaris/gaia.dm new file mode 100644 index 00000000000..9bb2a63eec4 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/gaia.dm @@ -0,0 +1,120 @@ +// Artifact effect: gaia. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/gaia.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: tends living plants in hydroponics trays nearby (water, +// health, weeds, pests and toxins) but never speeds their growth or revives dead ones, so it +// saves a gardener's chores without making more crop. Plant people nearby feel it too, inside the +// shared artifact healing cap. Polaris' glitterflies become a few short-lived butterflies, at +// most three at a time, that fade away on their own. + +/// Butterflies alive at once, per artifact +#define ARTIFACT_GAIA_MAX_BUTTERFLIES 3 + +/datum/artifact_effect/gaia + label_name = "Feeds plants" + log_name = "Gaia" + tier = ARTIFACT_TIER_UNCOMMON + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC, ARTIFACT_ENERGY_SYNTHESIS) + /// Weakrefs to the butterflies it has drawn + var/list/datum/weakref/butterflies = list() + +/datum/artifact_effect/gaia/Destroy(force) + for(var/datum/weakref/butterfly_ref as anything in butterflies) + var/mob/living/basic/butterfly/lavaland/temporary/butterfly = butterfly_ref.resolve() + if(butterfly) + butterfly.fadeout() + butterflies = null + return ..() + +/datum/artifact_effect/gaia/do_effect_touch(mob/living/user) + to_chat(user, span_notice("You feel the presence of something long forgotten, and green.")) + var/tended = tend_all(range + 2, 3, 30) + if(tended) + to_chat(user, span_notice("Somewhere nearby, leaves rustle.")) + +/datum/artifact_effect/gaia/do_effect_aura(seconds_per_tick) + tend_all(range, 0.5 * seconds_per_tick, 2) + for(var/mob/living/carbon/human/sprout in living_in_range()) + if(SPT_PROB(10, seconds_per_tick)) + nourish(sprout, 2) + +/datum/artifact_effect/gaia/do_effect_pulse(power) + var/turf/center = source_turf() + if(!center) + return + new /obj/effect/temp_visual/circle_wave/artifact_ring/gaia(center, max(range * 0.6, 1.5)) + playsound(center, 'sound/effects/rustle/rustle1.ogg', 40, TRUE) + tend_all(range, clamp(power / 5, 2, 8), 10) + if(prob(25)) + draw_butterfly(get_step(center, pick(GLOB.alldirs))) + for(var/mob/living/carbon/human/sprout in living_in_range()) + nourish(sprout, clamp(power / 4, 2, 8)) + +/** + * Tends every planted tray in `reach` by `amount`, with `butterfly_chance` per tray of drawing a + * butterfly. Returns how many it tended. + */ +/datum/artifact_effect/gaia/proc/tend_all(reach, amount, butterfly_chance) + . = 0 + var/turf/center = source_turf() + if(!center) + return + for(var/obj/machinery/hydroponics/tray in range(reach, center)) + if(!tend(tray, amount)) + continue + .++ + if(prob(butterfly_chance)) + draw_butterfly(get_turf(tray)) + +/// Waters, weeds and soothes one tray's living plant. Never ages it. Returns TRUE if it had one. +/datum/artifact_effect/gaia/proc/tend(obj/machinery/hydroponics/tray, amount) + if(!tray.myseed || tray.plant_status == HYDROTRAY_PLANT_DEAD) + return FALSE + tray.adjust_waterlevel(amount * 3) + tray.adjust_plant_health(amount) + tray.adjust_weedlevel(-1) + tray.adjust_pestlevel(-1) + tray.adjust_toxic(-amount) + tray.update_appearance() + if(prob(30)) + new /obj/effect/temp_visual/artifact_gaia_bloom(get_turf(tray)) + return TRUE + +/// Plant people take a little warmth from it, inside the shared healing cap. +/datum/artifact_effect/gaia/proc/nourish(mob/living/carbon/human/sprout, amount) + if(sprout.stat == DEAD || !(sprout.mob_biotypes & MOB_PLANT)) + return + if(artifact_capped_heal(sprout, amount * artifact_exposure(sprout)) > 0 && prob(30)) + to_chat(sprout, span_notice("A warm, green feeling seeps into your leaves.")) + +/// A butterfly comes to the plants for a while. +/datum/artifact_effect/gaia/proc/draw_butterfly(turf/spot) + for(var/datum/weakref/butterfly_ref as anything in butterflies) + if(!butterfly_ref.resolve()) + butterflies -= butterfly_ref + if(length(butterflies) >= ARTIFACT_GAIA_MAX_BUTTERFLIES || !istype(spot) || spot.is_blocked_turf()) + return + var/mob/living/basic/butterfly/lavaland/temporary/butterfly = new(spot) + butterfly.source = artifact_effect_visible_source(holder) + butterfly.max_distance = range + 3 + butterflies += WEAKREF(butterfly) + addtimer(CALLBACK(butterfly, TYPE_PROC_REF(/mob/living/basic/butterfly/lavaland/temporary, fadeout)), rand(60, 120) SECONDS, TIMER_DELETE_ME) + +/// A green shimmer over a tended tray. +/obj/effect/temp_visual/artifact_gaia_bloom + icon = 'icons/obj/service/hydroponics/equipment.dmi' + icon_state = "gaia_blessing" + duration = 1.5 SECONDS + +/obj/effect/temp_visual/artifact_gaia_bloom/Initialize(mapload) + . = ..() + alpha = 0 + animate(src, alpha = 255, time = 0.4 SECONDS) + animate(alpha = 0, time = 1.1 SECONDS) + +/// A soft green ring for the burst. +/obj/effect/temp_visual/circle_wave/artifact_ring/gaia + color = "#8cd448" + max_alpha = 140 + +#undef ARTIFACT_GAIA_MAX_BUTTERFLIES diff --git a/voidcrew/modules/xenoarch/effects_polaris/gravity_wave.dm b/voidcrew/modules/xenoarch/effects_polaris/gravity_wave.dm new file mode 100644 index 00000000000..fc45c550e35 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/gravity_wave.dm @@ -0,0 +1,146 @@ +// Artifact effect: gravity wave. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/gravitational_waves.dm, +// also in VOREStation (9335d66b9fdf). Voidcrew: one huge knockback ring instead of Polaris' +// singularity pull. It draws the air in for a moment first (a shimmer closing on it, a rising +// hum), so anyone watching has time to brace or back off; then everything loose in reach is +// flung outward and people are knocked down, hardest near the middle. Anchored things stay put, +// and nobody is thrown into lava, a chasm, open air or space. +// Smashing it lets the wave go at once. Not harvestable; logged. + +/// How long it gathers before the wave +#define ARTIFACT_WAVE_WINDUP (1.5 SECONDS) +/// Furthest it ever reaches +#define ARTIFACT_WAVE_MAX_RANGE 7 +/// Loose objects one wave can fling (people always feel it), so a junk pile can't lag the server +#define ARTIFACT_WAVE_MAX_OBJECTS 40 + +/datum/artifact_effect/gravity_wave + label_name = "Shockwave" + log_name = "Gravity wave" + tier = ARTIFACT_TIER_EXTREME + harvestable = FALSE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_BLUESPACE, ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_PSIONIC) + allowed_release_methods = list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_PULSE) + /// A wave is gathering + var/gathering = FALSE + +/datum/artifact_effect/gravity_wave/setup() + range = clamp(range, 3, ARTIFACT_WAVE_MAX_RANGE) + // A wave needs a good part of the store; a hand can't set one off every few seconds. + touch_cost = max(touch_cost, round(maximum_charges / 2)) + +/datum/artifact_effect/gravity_wave/do_effect_touch(mob/living/user) + to_chat(user, span_warning("[holder] hums under your hand, louder and louder.")) + gather() + +/datum/artifact_effect/gravity_wave/do_effect_pulse(power) + gather() + +/datum/artifact_effect/gravity_wave/do_effect_destroy() + release_wave() + +/// The warning: the air draws in toward it, then the wave goes. +/datum/artifact_effect/gravity_wave/proc/gather() + var/turf/center = source_turf() + if(gathering || !center) + return FALSE + gathering = TRUE + center.visible_message(span_danger("The air around [holder] bends and draws in toward it.")) + playsound(center, 'sound/effects/magic/cosmic_expansion.ogg', 50, TRUE) + new /obj/effect/temp_visual/artifact_wave_gather(center, range) + addtimer(CALLBACK(src, PROC_REF(release_wave)), ARTIFACT_WAVE_WINDUP, TIMER_DELETE_ME) + return TRUE + +/// Flings everything loose in reach outward. Does nothing if it was crated or put to sleep meanwhile. +/datum/artifact_effect/gravity_wave/proc/release_wave() + gathering = FALSE + var/obj/machinery/artifact/artifact = holder + if(istype(artifact) && artifact.suppressed) + return + var/turf/center = source_turf() + if(!center) + return + new /obj/effect/temp_visual/circle_wave/artifact_ring/gravity_wave(center, range) + playsound(center, 'sound/effects/gravhit.ogg', 70, TRUE, extrarange = 4) + playsound(center, 'sound/effects/magic/repulse.ogg', 60, TRUE) + var/atom/movable/carrier = artifact_effect_visible_source(holder) + var/objects_flung = 0 + for(var/atom/movable/thing in range(range, center)) + if(thing == holder || thing == carrier || !can_fling(thing)) + continue + if(!isliving(thing)) + if(objects_flung >= ARTIFACT_WAVE_MAX_OBJECTS) + continue + objects_flung++ + fling(thing, center) + +/// Loose items, unanchored structures and the living; nothing anchored or immovable. +/datum/artifact_effect/gravity_wave/proc/can_fling(atom/movable/thing) + if(thing.anchored || thing.move_resist > MOVE_FORCE_STRONG || !isturf(thing.loc)) + return FALSE + if(isliving(thing)) + var/mob/living/victim = thing + return !victim.buckled + return isitem(thing) || isstructure(thing) + +/// Throws `thing` directly away from `center`, harder the closer it stood. +/datum/artifact_effect/gravity_wave/proc/fling(atom/movable/thing, turf/center) + var/distance = get_dist(center, thing) + var/exposure = isliving(thing) ? artifact_exposure(thing) : 1 + var/throw_range = round(clamp(range - distance + 2, 2, 6) * exposure) + if(throw_range < 1) + return + var/direction = (distance > 0) ? get_dir(center, thing) : pick(GLOB.alldirs) + if(isliving(thing)) + var/mob/living/victim = thing + throw_range = safe_distance(victim, direction, throw_range) + shake_camera(victim, 3, 2) + victim.Knockdown(2 SECONDS * exposure) + to_chat(victim, span_userdanger("A wall of force hits you and [throw_range ? "lifts you off your feet" : "slams you to the ground"]!")) + log_harm(victim) + if(throw_range < 1) + return + var/turf/landing = get_ranged_target_turf(thing, direction, throw_range) + if(landing) + // Positional: some throw_at() overrides rename their arguments. + thing.throw_at(landing, throw_range, 2) + +/** + * How far `thing` can be thrown toward `direction`, up to `limit`, without crossing lava, a chasm, + * open air or space. A wave knocks people over; it never throws them off a ledge or out an airlock. + */ +/datum/artifact_effect/gravity_wave/proc/safe_distance(atom/movable/thing, direction, limit) + var/turf/spot = get_turf(thing) + for(var/step in 1 to limit) + spot = get_step(spot, direction) + if(!spot || isspaceturf(spot) || isgroundlessturf(spot) || islava(spot) || ischasm(spot)) + return step - 1 + return limit + +/// A shimmer closing in on the artifact before the wave. +/obj/effect/temp_visual/artifact_wave_gather + icon = 'icons/effects/64x64.dmi' + icon_state = "circle_wave" + pixel_x = -16 + pixel_y = -16 + color = "#d8c3ff" + alpha = 0 + duration = ARTIFACT_WAVE_WINDUP + +/obj/effect/temp_visual/artifact_wave_gather/Initialize(mapload, reach = 4) + . = ..() + transform = matrix().Scale(max(reach, 1)) + animate(src, transform = matrix().Scale(0.1), time = duration, easing = SINE_EASING | EASE_IN, flags = ANIMATION_PARALLEL) + animate(src, alpha = 160, time = duration * 0.5, flags = ANIMATION_PARALLEL) + animate(alpha = 220, time = duration * 0.5) + +/// The wave itself. +/obj/effect/temp_visual/circle_wave/artifact_ring/gravity_wave + color = "#d8c3ff" + max_alpha = 230 + duration = 0.6 SECONDS + +#undef ARTIFACT_WAVE_WINDUP +#undef ARTIFACT_WAVE_MAX_RANGE +#undef ARTIFACT_WAVE_MAX_OBJECTS diff --git a/voidcrew/modules/xenoarch/effects_polaris/life_drain.dm b/voidcrew/modules/xenoarch/effects_polaris/life_drain.dm new file mode 100644 index 00000000000..86d8cb5694a --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/life_drain.dm @@ -0,0 +1,112 @@ +// Artifact effect: life drain. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/lifedrain.dm. Voidcrew: +// a sickly beam hooks into someone nearby; if they are still in reach a few seconds later, it +// tears a little life out of them (bruising, breathlessness and a spell of weakness). Stepping out +// of reach snaps the beam, so it can always be escaped. One beam per person at a time, people in +// a good biosuit are ignored (as in Polaris), and every drain is logged. Polaris healed the +// toucher with what it took; that is the extreme Life steal effect, so this only takes. + +/// Seconds between the hook and the drain +#define ARTIFACT_DRAIN_WINDUP (3 SECONDS) + +/datum/artifact_effect/life_drain + label_name = "Drains life" + log_name = "Life drain" + tier = ARTIFACT_TIER_RARE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC, ARTIFACT_ENERGY_CONCENTRATED) + /// REF(victim) -> TRUE while a beam is hooked into them + var/list/hooked = list() + +/datum/artifact_effect/life_drain/Destroy(force) + hooked = null + return ..() + +/datum/artifact_effect/life_drain/do_effect_touch(mob/living/user) + hook(user, 10) + +/datum/artifact_effect/life_drain/do_effect_aura(seconds_per_tick) + for(var/mob/living/target in living_in_range()) + if(SPT_PROB(6, seconds_per_tick)) + hook(target, 5) + +/datum/artifact_effect/life_drain/do_effect_pulse(power) + var/list/victims = living_in_range() + for(var/i in 1 to 2) + if(!length(victims)) + return + hook(pick_n_take(victims), clamp(power * 0.3, 4, 12)) + +/// Smashed, it lashes everyone in reach at once, with no warning. +/datum/artifact_effect/life_drain/do_effect_destroy() + for(var/mob/living/target in living_in_range()) + if(can_hook(target)) + siphon(target, 6) + +/// Whether `target` is somebody it can feed on. +/datum/artifact_effect/life_drain/proc/can_hook(mob/living/target) + if(target.stat == DEAD || hooked?[REF(target)]) + return FALSE + return artifact_exposure(target) >= 0.5 + +/// Hooks a beam into `target`; the drain lands after the windup if they stay. Returns TRUE if it hooked. +/datum/artifact_effect/life_drain/proc/hook(mob/living/target, damage) + if(!can_hook(target)) + return FALSE + var/atom/origin = artifact_effect_visible_source(holder) + if(!isatom(origin)) + return FALSE + var/key = REF(target) + hooked[key] = TRUE + playsound(target, 'sound/effects/magic/enter_blood.ogg', 35, TRUE) + // Carried in a battery, it feeds on whoever holds it: no beam to step out of. + if(origin == target) + target.visible_message( + span_danger("[target] shudders as something in [target.p_their()] grip starts to pull."), + span_userdanger("Something in your grip hooks into you. Something cold starts to pull."), + ) + addtimer(CALLBACK(src, PROC_REF(finish_hook), WEAKREF(target), null, key, damage, TRUE), ARTIFACT_DRAIN_WINDUP, TIMER_DELETE_ME) + return TRUE + var/datum/beam/drain_beam = origin.Beam(target, icon_state = "drain_life", time = ARTIFACT_DRAIN_WINDUP + 0.5 SECONDS, maxdistance = range + 1) + target.visible_message( + span_danger("A sickly beam lashes out from [origin] and hooks into [target]!"), + span_userdanger("A sickly beam lashes out from [origin] and hooks into you. Something cold starts to pull."), + ) + addtimer(CALLBACK(src, PROC_REF(finish_hook), WEAKREF(target), WEAKREF(drain_beam), key, damage), ARTIFACT_DRAIN_WINDUP, TIMER_DELETE_ME) + return TRUE + +/// The windup ended: drains `target` if the beam still holds them. +/datum/artifact_effect/life_drain/proc/finish_hook(datum/weakref/target_ref, datum/weakref/beam_ref, key, damage, held = FALSE) + hooked -= key + var/mob/living/target = target_ref?.resolve() + var/datum/beam/drain_beam = beam_ref?.resolve() + if(!target || target.stat == DEAD) + qdel(drain_beam) + return + if(held) + if(artifact_effect_visible_source(holder) != target) + to_chat(target, span_notice("The cold hook slips out of you.")) + return + else if(QDELETED(drain_beam)) + to_chat(target, span_notice("The cold hook slips out of you.")) + return + qdel(drain_beam) + siphon(target, damage) + +/// Tears `damage` worth of life out of `target`. +/datum/artifact_effect/life_drain/proc/siphon(mob/living/target, damage) + damage *= artifact_exposure(target) + if(damage <= 0) + return + target.take_overall_damage(damage) + target.adjustStaminaLoss(damage * 2) + target.apply_status_effect(/datum/status_effect/artifact/exhausted, 10 SECONDS) + new /obj/effect/temp_visual/heal(get_turf(target), "#7a1d3a") + target.visible_message( + span_danger("Something pale and shining is pulled out of [target]."), + span_userdanger("Something is torn out of you. Your legs go weak."), + ) + playsound(target, 'sound/effects/magic/exit_blood.ogg', 40, TRUE) + log_harm(target) + +#undef ARTIFACT_DRAIN_WINDUP diff --git a/voidcrew/modules/xenoarch/effects_polaris/life_steal.dm b/voidcrew/modules/xenoarch/effects_polaris/life_steal.dm new file mode 100644 index 00000000000..4ea9ab1a036 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/life_steal.dm @@ -0,0 +1,82 @@ +// Artifact effect: life steal. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/lifesteal.dm. +// Voidcrew: heals one person by taking the same amount from everyone else in reach, split between +// them. It only takes what it gives, so nothing happens unless the person it feeds is hurt, and +// what it gives goes through the shared artifact healing cap: it is a slow trickle, never a +// medbay and never a weapon. Who it feeds: the hand on it, the person carrying it, or for a burst +// the nearest hurt person. Every theft is logged. + +/datum/artifact_effect/life_steal + label_name = "Steals life" + log_name = "Life steal" + tier = ARTIFACT_TIER_EXTREME + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC, ARTIFACT_ENERGY_CONCENTRATED) + allowed_release_methods = list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_PULSE) + +/datum/artifact_effect/life_steal/do_effect_touch(mob/living/user) + if(!steal_for(user, 10)) + to_chat(user, span_notice("Something reaches into you, finds nothing it wants, and lets go.")) + +/datum/artifact_effect/life_steal/do_effect_pulse(power) + steal_for(pick_beneficiary(), clamp(power * 0.4, 5, 15)) + +/// Whoever a burst feeds: the person carrying it, else the nearest hurt person in reach. +/datum/artifact_effect/life_steal/proc/pick_beneficiary() + var/atom/carrier = artifact_effect_visible_source(holder) + if(isliving(carrier)) + return carrier + var/turf/center = source_turf() + if(!center) + return null + var/mob/living/best + var/best_distance = INFINITY + for(var/mob/living/candidate in living_in_range()) + if(candidate.stat == DEAD || candidate.getBruteLoss() + candidate.getFireLoss() <= 0) + continue + var/distance = get_dist(center, candidate) + if(distance < best_distance) + best = candidate + best_distance = distance + return best + +/** + * Heals `beneficiary` by up to `amount`, taken from everyone else in reach. + * Returns the amount healed. + */ +/datum/artifact_effect/life_steal/proc/steal_for(mob/living/beneficiary, amount) + if(!beneficiary || beneficiary.stat == DEAD) + return 0 + var/wanted = min(amount, beneficiary.getBruteLoss() + beneficiary.getFireLoss(), artifact_heal_allowance(beneficiary)) + if(wanted <= 0) + return 0 + var/list/victims = list() + for(var/mob/living/victim in living_in_range()) + if(victim == beneficiary || victim.stat == DEAD || artifact_exposure(victim) <= 0) + continue + victims += victim + if(!length(victims)) + return 0 + // What each victim can give: an even share, less for those in protective gear. + var/list/shares = list() + var/offered = 0 + for(var/mob/living/victim as anything in victims) + var/share = wanted / length(victims) * artifact_exposure(victim) + shares[victim] = share + offered += share + if(offered <= 0) + return 0 + var/healed = artifact_capped_heal(beneficiary, offered) + if(healed <= 0) + return 0 + // Everyone gives up exactly their part of what was healed. + var/scale = healed / offered + for(var/mob/living/victim as anything in shares) + victim.take_overall_damage(shares[victim] * scale) + victim.Beam(beneficiary, icon_state = "lichbeam", time = 1.5 SECONDS) + to_chat(victim, span_danger("Warmth bleeds out of you and runs toward [beneficiary].")) + log_harm(victim) + new /obj/effect/temp_visual/heal(get_turf(beneficiary), "#b0306a") + to_chat(beneficiary, span_notice("Stolen warmth floods into you, and your wounds pull shut.")) + playsound(beneficiary, 'sound/effects/magic/exit_blood.ogg', 35, TRUE) + return healed diff --git a/voidcrew/modules/xenoarch/effects_polaris/plasma_vent.dm b/voidcrew/modules/xenoarch/effects_polaris/plasma_vent.dm new file mode 100644 index 00000000000..24073c05e17 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/plasma_vent.dm @@ -0,0 +1,121 @@ +// Artifact effect: plasma vent. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/gasphoron.dm. +// Voidcrew: vents plasma (Polaris' "phoron") indoors only: never into planet air, never into space. +// Each vent stops at a modest pressure on its tile, and holds a finite reserve, less than one gas +// contract asks for, so it can never become a free plasma well. Plasma air never wakes it, or it +// would feed itself. Everyone breathing near it is logged. Not harvestable. +// +// Also the shared parent for gas vents with a reserve (sleeping gas uses it). + +/datum/artifact_effect/gas_vent + harvestable = FALSE + harmful = TRUE + /// The /datum/gas it vents + var/gas_type + /// Gas puff colour + var/puff_color = "#ffffff" + /// Moles left in it; it runs dry for good when this hits zero + var/reserve = 0 + var/reserve_low = 100 + var/reserve_high = 200 + /// It stops venting once its tile reaches this pressure (kPa) + var/max_pressure = ONE_ATMOSPHERE + /// Said it was dry + var/announced_dry = FALSE + +/datum/artifact_effect/gas_vent/setup() + reserve = rand(reserve_low, reserve_high) + max_pressure = rand(110, 140) + +// Half of what is left goes with a copy, so the reserve is shared, never doubled. +/datum/artifact_effect/gas_vent/copy_settings_to(datum/artifact_effect/gas_vent/copy) + copy.reserve = round(reserve / 2) + reserve -= copy.reserve + copy.max_pressure = max_pressure + +/datum/artifact_effect/gas_vent/is_spent() + return reserve <= 0 + +/datum/artifact_effect/gas_vent/do_effect_touch(mob/living/user) + if(vent(rand(3, 8))) + to_chat(user, span_warning("Gas hisses out of [holder] around your hand.")) + +/datum/artifact_effect/gas_vent/do_effect_aura(seconds_per_tick) + if(SPT_PROB(50, seconds_per_tick)) + vent(rand(1, 3)) + +/datum/artifact_effect/gas_vent/do_effect_pulse(power) + vent(clamp(power / 2, 3, 20)) + +/** + * Lets up to `moles` of its gas out onto its tile, from its reserve. Indoors only: never a planet + * turf (whose air is shared), never space. Returns the moles that came out. + */ +/datum/artifact_effect/gas_vent/proc/vent(moles) + if(moles <= 0 || !gas_type) + return 0 + var/turf/open/here = source_turf() + if(!istype(here) || here.planetary_atmos || isspaceturf(here)) + return 0 + if(reserve <= 0) + run_dry(here) + return 0 + var/datum/gas_mixture/air = here.return_air() + if(!air || air.return_pressure() >= max_pressure) + return 0 + moles = min(moles, reserve) + reserve -= moles + var/datum/gas_mixture/puff = new + puff.assert_gas(gas_type) + puff.gases[gas_type][MOLES] = moles + puff.temperature = T20C + here.assume_air(puff) + var/obj/effect/temp_visual/artifact_gas_puff/cloud = new(here) + cloud.color = puff_color + playsound(here, 'sound/effects/spray2.ogg', 20, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) + for(var/mob/living/breather in living_in_range()) + log_harm(breather) + return moles + +/// Its reserve is spent: one last wheeze, then nothing ever again. +/datum/artifact_effect/gas_vent/proc/run_dry(turf/here) + if(announced_dry) + return + announced_dry = TRUE + here.visible_message(span_notice("[holder] wheezes, and nothing more comes out.")) + playsound(here, 'sound/effects/spray3.ogg', 25, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) + +/datum/artifact_effect/gas_vent/plasma + label_name = "Vents plasma" + log_name = "Plasma vent" + tier = ARTIFACT_TIER_UNCOMMON + possible_kinds = list(ARTIFACT_ENERGY_BLUESPACE, ARTIFACT_ENERGY_SYNTHESIS) + // Every trigger but plasma air, which it would make itself. + allowed_triggers = list( + ARTIFACT_TRIGGER_TOUCH, + ARTIFACT_TRIGGER_WATER, + ARTIFACT_TRIGGER_ACID, + ARTIFACT_TRIGGER_VOLATILE, + ARTIFACT_TRIGGER_TOXIN, + ARTIFACT_TRIGGER_IMPACT, + ARTIFACT_TRIGGER_ENERGY, + ARTIFACT_TRIGGER_HEAT, + ARTIFACT_TRIGGER_COLD, + ARTIFACT_TRIGGER_CO2, + ARTIFACT_TRIGGER_PROXIMITY, + ) + gas_type = /datum/gas/plasma + puff_color = "#c95ad8" + reserve_low = 150 + reserve_high = 300 + +/// A small cloud of vented gas. +/obj/effect/temp_visual/artifact_gas_puff + icon_state = "smoke" + alpha = 120 + duration = 1.2 SECONDS + +/obj/effect/temp_visual/artifact_gas_puff/Initialize(mapload) + . = ..() + pixel_x = rand(-4, 4) + animate(src, alpha = 0, pixel_y = 10, time = duration) diff --git a/voidcrew/modules/xenoarch/effects_polaris/poltergeist.dm b/voidcrew/modules/xenoarch/effects_polaris/poltergeist.dm new file mode 100644 index 00000000000..5a527a8351d --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/poltergeist.dm @@ -0,0 +1,106 @@ +// Artifact effect: poltergeist. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/poltergeist.dm, also in +// VOREStation (9335d66b9fdf). Voidcrew: picks a loose object lying near the artifact, lifts it for a +// moment (time to duck) and hurls it at the nearest person. Only small and medium items lying on +// the floor fly; nothing is pulled from hands, bags or tables' contents, and a thrown object only +// hits as hard as its own weight allows. Logged like a weapon. + +/// How long an object hangs in the air before it flies +#define ARTIFACT_POLTERGEIST_WINDUP (0.8 SECONDS) + +/datum/artifact_effect/poltergeist + label_name = "Throws things" + log_name = "Poltergeist" + tier = ARTIFACT_TIER_RARE + harmful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_PSIONIC, ARTIFACT_ENERGY_BLUESPACE) + +/datum/artifact_effect/poltergeist/do_effect_touch(mob/living/user) + lift_and_throw(user) + +/datum/artifact_effect/poltergeist/do_effect_aura(seconds_per_tick) + if(SPT_PROB(15, seconds_per_tick)) + lift_and_throw(nearest_target()) + +/datum/artifact_effect/poltergeist/do_effect_pulse(power) + var/mob/living/target = nearest_target() + if(!target) + return + var/throws = power >= 30 ? 2 : 1 + for(var/i in 1 to throws) + lift_and_throw(target) + +/// Smashed, it flings what is near it at once, with no warning. +/datum/artifact_effect/poltergeist/do_effect_destroy() + var/mob/living/target = nearest_target() + var/obj/item/missile = find_missile(target) + if(target && missile) + hurl(WEAKREF(missile), WEAKREF(target)) + +/// The closest conscious mob in range, preferring people with a mind over animals. +/datum/artifact_effect/poltergeist/proc/nearest_target() + var/turf/center = source_turf() + if(!center) + return null + var/mob/living/best + var/best_distance = INFINITY + var/best_has_mind = FALSE + for(var/mob/living/candidate in living_in_range()) + if(candidate.stat != CONSCIOUS) + continue + var/has_mind = !!candidate.mind + var/distance = get_dist(center, candidate) + if(best_has_mind && !has_mind) + continue + if((has_mind && !best_has_mind) || distance < best_distance) + best = candidate + best_distance = distance + best_has_mind = has_mind + return best + +/// A loose item on the floor within its reach, not right under `target`'s feet. +/datum/artifact_effect/poltergeist/proc/find_missile(mob/living/target) + var/turf/center = source_turf() + if(!center || !target) + return null + var/list/candidates = list() + for(var/obj/item/thing in range(range, center)) + if(!isturf(thing.loc) || thing.anchored || thing.w_class > WEIGHT_CLASS_BULKY) + continue + if((thing.item_flags & ABSTRACT) || HAS_TRAIT(thing, TRAIT_NODROP) || thing.throwforce <= 0) + continue + if(get_dist(thing, target) < 2) + continue + candidates += thing + return length(candidates) ? pick(candidates) : null + +/// Lifts something toward `target`; it flies after a short windup. Returns TRUE if it lifted one. +/datum/artifact_effect/poltergeist/proc/lift_and_throw(mob/living/target) + if(!target || target.stat == DEAD || !prob(100 * artifact_exposure(target))) + return FALSE + var/obj/item/missile = find_missile(target) + if(!missile) + return FALSE + missile.visible_message(span_warning("[missile] lifts off the floor and turns toward [target]!")) + playsound(missile, 'sound/effects/magic/summonitems_generic.ogg', 30, TRUE) + animate(missile, pixel_z = 10, time = ARTIFACT_POLTERGEIST_WINDUP, easing = SINE_EASING | EASE_OUT, flags = ANIMATION_PARALLEL) + var/atom/origin = artifact_effect_visible_source(holder) + origin?.Beam(missile, icon_state = "kinesis", time = ARTIFACT_POLTERGEIST_WINDUP) + addtimer(CALLBACK(src, PROC_REF(hurl), WEAKREF(missile), WEAKREF(target)), ARTIFACT_POLTERGEIST_WINDUP, TIMER_DELETE_ME) + return TRUE + +/// Throws the lifted item, if it is still lying where it was lifted and the target still stands. +/datum/artifact_effect/poltergeist/proc/hurl(datum/weakref/missile_ref, datum/weakref/target_ref) + var/obj/item/missile = missile_ref?.resolve() + var/mob/living/target = target_ref?.resolve() + if(!missile) + return + animate(missile, pixel_z = 0, time = 0.1 SECONDS, flags = ANIMATION_PARALLEL) + if(!isturf(missile.loc) || !target || target.stat == DEAD || missile.z != target.z) + return + playsound(missile, 'sound/effects/magic/repulse.ogg', 30, TRUE) + // Positional: some item overrides of throw_at() rename their arguments. + missile.throw_at(target, range * 2, 3) + log_harm(target) + +#undef ARTIFACT_POLTERGEIST_WINDUP diff --git a/voidcrew/modules/xenoarch/effects_polaris/resurrect.dm b/voidcrew/modules/xenoarch/effects_polaris/resurrect.dm new file mode 100644 index 00000000000..1b815b2fc7e --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/resurrect.dm @@ -0,0 +1,194 @@ +// Artifact effect: resurrect. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/resurrect.dm and the +// VOREStation (9335d66b9fdf) "vitality swap" version. Voidcrew (owner decision 4): brings back one +// person lying beside it who died less than five minutes ago, three times in all, then it cracks +// and goes dull for good. It is never a free revive loop: +// - three lives per artifact, stored on the effect; not harvestable, and artifacts are never +// saved with a ship, so the count can't be copied or reset; +// - only a body whose own player is still there to come back: a ghost that can re-enter, or a +// player still in the body. Do-not-resuscitate, logged-out players, and a mind that already moved +// on (a clone, a new body) are refused; +// - the same checks as a defibrillator: suicides, husks, failing or missing hearts and brains, and +// bodies too broken to hold life; +// - its healing goes through the shared artifact cap (30 brute and burn); it clears the choking +// and some poison, but a body torn apart past that stays dead and costs no use. +// Polaris drained the living nearby to fuel it; that is dropped. The price is the use, and the +// person comes back weak. Every revival is logged. + +/// Lives it can give back before it is spent +#define ARTIFACT_RESURRECT_USES 3 +/// How long after death a body can still be raised +#define ARTIFACT_RESURRECT_WINDOW (5 MINUTES) +/// How long the light works on a body before it wakes +#define ARTIFACT_RESURRECT_RITE (4 SECONDS) +/// Poison it clears from a body +#define ARTIFACT_RESURRECT_TOX_MEND 40 + +/datum/artifact_effect/resurrect + label_name = "Raises the dead" + log_name = "Resurrect" + tier = ARTIFACT_TIER_EXTREME + harvestable = FALSE + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC) + /// Lives it can still give back. At zero it is spent for good. + var/uses_left = ARTIFACT_RESURRECT_USES + /// The body it is working on, if any + var/datum/weakref/working_on + /// REF(body) -> world.time it last showed it could not help them + var/list/refused_at + +/datum/artifact_effect/resurrect/Destroy(force) + working_on = null + refused_at = null + return ..() + +/datum/artifact_effect/resurrect/copy_settings_to(datum/artifact_effect/resurrect/copy) + copy.uses_left = uses_left + +/datum/artifact_effect/resurrect/is_spent() + return uses_left <= 0 + +/datum/artifact_effect/resurrect/do_effect_touch(mob/living/user) + seek() + +/datum/artifact_effect/resurrect/do_effect_aura(seconds_per_tick) + seek() + +/datum/artifact_effect/resurrect/do_effect_pulse(power) + seek() + +/// Spent, it only gives the faintest light when woken. +/datum/artifact_effect/resurrect/light_override() + if(uses_left <= 0) + return list(1, 0.3, "#5a1a1a") + return null + +/// Looks for a body laid beside it and starts on the first one that can come back. +/datum/artifact_effect/resurrect/proc/seek() + if(uses_left <= 0 || working_on?.resolve()) + return + var/turf/center = source_turf() + if(!center) + return + for(var/mob/living/carbon/human/body in range(1, center)) + if(body.stat != DEAD) + continue + var/refusal = raise_refusal(body) + if(refusal) + show_refusal(body, refusal) + continue + begin_rite(body) + return + +/** + * Why `body` can't be raised, as a short reason, or null if it can. + * "spent", "not here", "too late", "gone" (nobody to come back) or "ruined" (the body can't hold life). + */ +/datum/artifact_effect/resurrect/proc/raise_refusal(mob/living/carbon/human/body) + if(uses_left <= 0) + return "spent" + if(!istype(body) || QDELETED(body) || body.stat != DEAD || !isturf(body.loc)) + return "not here" + if(world.time - body.timeofdeath > ARTIFACT_RESURRECT_WINDOW) + return "too late" + if(!body.mind || body.mind.current != body) + return "gone" + if(body.can_defib() != DEFIB_POSSIBLE) + return "ruined" + if(projected_health(body) <= HEALTH_THRESHOLD_DEAD) + return "ruined" + if(!body.client && !body.get_ghost(FALSE, TRUE)) + return "gone" + return null + +/// What `body`'s health would be after the mending it gives. +/datum/artifact_effect/resurrect/proc/projected_health(mob/living/carbon/human/body) + var/mended = min(artifact_heal_allowance(body), body.getBruteLoss() + body.getFireLoss()) + mended += body.getOxyLoss() + min(body.getToxLoss(), ARTIFACT_RESURRECT_TOX_MEND) + return body.health + mended + +/// Shows, now and then, that it reached for a body and could not take hold. +/datum/artifact_effect/resurrect/proc/show_refusal(mob/living/carbon/human/body, refusal) + if(refusal == "spent" || refusal == "not here") + return + var/key = REF(body) + if(LAZYACCESS(refused_at, key) > world.time - 30 SECONDS) + return + LAZYSET(refused_at, key, world.time) + if(refusal == "gone") + body.visible_message(span_notice("A thread of red light reaches from [holder] to [body], finds no one there, and fades.")) + else + body.visible_message(span_notice("A thread of red light touches [body], slides off, and fades.")) + +/// The light goes to work on `body`; it wakes after the rite if nothing has changed. +/datum/artifact_effect/resurrect/proc/begin_rite(mob/living/carbon/human/body) + working_on = WEAKREF(body) + var/atom/origin = artifact_effect_visible_source(holder) + origin?.Beam(body, icon_state = "lichbeam", time = ARTIFACT_RESURRECT_RITE) + body.visible_message(span_warning("Threads of red light reach out of [holder] and sink into [body]. The body twitches.")) + playsound(body, 'sound/effects/magic/enter_blood.ogg', 45, TRUE) + playsound(body, 'sound/effects/singlebeat.ogg', 60, TRUE) + body.do_jitter_animation(100) + body.notify_revival("Something is dragging you back toward your body!", source = holder) + addtimer(CALLBACK(src, PROC_REF(finish_rite), WEAKREF(body)), ARTIFACT_RESURRECT_RITE, TIMER_DELETE_ME) + +/// The rite ends: raises the body if it still can be. +/datum/artifact_effect/resurrect/proc/finish_rite(datum/weakref/body_ref) + working_on = null + var/mob/living/carbon/human/body = body_ref?.resolve() + if(!body) + return + var/obj/machinery/artifact/artifact = holder + if((istype(artifact) && artifact.suppressed) || get_dist(source_turf(), body) > 1 || raise_refusal(body)) + body.visible_message(span_notice("The red light drains out of [body] and is gone.")) + return + raise(body) + +/** + * Brings `body` back to life and spends one use. Returns TRUE if they live. + * Checks nothing about whether they should: raise_refusal() does that. + */ +/datum/artifact_effect/resurrect/proc/raise(mob/living/carbon/human/body) + if(uses_left <= 0 || QDELETED(body) || body.stat != DEAD) + return FALSE + artifact_capped_heal(body, artifact_heal_allowance(body)) + body.adjustOxyLoss(-body.getOxyLoss(), updating_health = FALSE) + body.adjustToxLoss(-min(body.getToxLoss(), ARTIFACT_RESURRECT_TOX_MEND), updating_health = FALSE, forced = TRUE) + body.updatehealth() + body.set_heartattack(FALSE) + if(body.health <= HEALTH_THRESHOLD_DEAD) + return FALSE + body.grab_ghost() + if(!body.revive_from("artifact")) + return FALSE + uses_left-- + body.emote("gasp") + body.set_jitter_if_lower(20 SECONDS) + body.apply_status_effect(/datum/status_effect/artifact/exhausted, 60 SECONDS) + body.visible_message( + span_warning("[body]'s eyes snap open in a flash of red light!"), + span_userdanger("You are dragged back into your body, gasping. Everything aches."), + ) + playsound(body, 'sound/effects/magic/staff_healing.ogg', 50, TRUE) + var/mob/responsible = get_responsible() + log_combat(responsible || holder, body, "revived", holder, "with [log_name] ([uses_left] uses left)") + if(uses_left <= 0) + go_dull() + return TRUE + +/// The last life is given: it cracks and the light inside goes out. +/datum/artifact_effect/resurrect/proc/go_dull() + var/turf/here = source_turf() + if(!here) + return + here.visible_message(span_warning("[holder] cracks with a sound like a knuckle, and the light deep inside it goes out.")) + playsound(here, 'sound/effects/wounds/crack1.ogg', 50, TRUE) + var/obj/machinery/artifact/artifact = holder + if(istype(artifact)) + artifact.update_activity_visuals() + +#undef ARTIFACT_RESURRECT_USES +#undef ARTIFACT_RESURRECT_WINDOW +#undef ARTIFACT_RESURRECT_RITE +#undef ARTIFACT_RESURRECT_TOX_MEND diff --git a/voidcrew/modules/xenoarch/effects_polaris/sleeping_gas.dm b/voidcrew/modules/xenoarch/effects_polaris/sleeping_gas.dm new file mode 100644 index 00000000000..66b00d1fd5b --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/sleeping_gas.dm @@ -0,0 +1,15 @@ +// Artifact effect: sleeping gas. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/gassleeping.dm. +// Voidcrew: vents nitrous oxide indoors only, from a finite reserve, and stops at a modest +// pressure on its tile (see the gas_vent parent in plasma_vent.dm). Everyone breathing near it is +// logged. Not harvestable. + +/datum/artifact_effect/gas_vent/sleeping + label_name = "Vents sleeping gas" + log_name = "Sleeping gas" + tier = ARTIFACT_TIER_RARE + possible_kinds = list(ARTIFACT_ENERGY_BLUESPACE, ARTIFACT_ENERGY_SYNTHESIS) + gas_type = /datum/gas/nitrous_oxide + puff_color = "#f2f2ff" + reserve_low = 100 + reserve_high = 200 diff --git a/voidcrew/modules/xenoarch/effects_polaris/spines.dm b/voidcrew/modules/xenoarch/effects_polaris/spines.dm new file mode 100644 index 00000000000..33eabff7144 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/spines.dm @@ -0,0 +1,99 @@ +// Artifact effect: spines. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/indiscriminate_spines.dm. +// Voidcrew: it bristles for a second (a rattle and a visible shiver, time to duck behind cover), +// then looses a ring of bone spines evenly around itself, eight or twelve by strength. A hand on +// it is spared: no spine flies toward the person touching it, as in Polaris. Half as likely in the +// green zone (design catalogue). Polaris' spore variant is not ported. Not harvestable; logged. + +/// How long it bristles before it fires +#define ARTIFACT_SPINES_WINDUP (1 SECONDS) + +/datum/artifact_effect/spines + label_name = "Fires spines" + log_name = "Spines" + tier = ARTIFACT_TIER_EXTREME + harvestable = FALSE + harmful = TRUE + green_weight = 0.5 + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC) + allowed_release_methods = list(ARTIFACT_RELEASE_TOUCH, ARTIFACT_RELEASE_PULSE) + /// Spines in one volley + var/volley = 8 + /// A volley is being readied + var/bristling = FALSE + +/datum/artifact_effect/spines/setup() + volley = (strength == ARTIFACT_STRENGTH_LARGE) ? 12 : 8 + // A volley needs a good part of the store; a hand can't set one off every few seconds. + touch_cost = max(touch_cost, round(maximum_charges / 2)) + +/datum/artifact_effect/spines/copy_settings_to(datum/artifact_effect/spines/copy) + copy.volley = volley + +/datum/artifact_effect/spines/do_effect_touch(mob/living/user) + bristle(user) + +/datum/artifact_effect/spines/do_effect_pulse(power) + bristle() + +/datum/artifact_effect/spines/do_effect_destroy() + fire_volley() + +/// The warning: it shivers and rattles, then fires. `spared` is the person touching it. +/datum/artifact_effect/spines/proc/bristle(mob/living/spared) + var/turf/center = source_turf() + if(bristling || !center) + return FALSE + bristling = TRUE + center.visible_message(span_danger("[holder] bristles with sharp bone!")) + playsound(center, 'sound/effects/blob/blobattack.ogg', 50, TRUE) + var/atom/movable/shaker = artifact_effect_visible_source(holder) + if(shaker) + shaker.Shake(1, 1, ARTIFACT_SPINES_WINDUP) + addtimer(CALLBACK(src, PROC_REF(fire_volley), spared ? WEAKREF(spared) : null), ARTIFACT_SPINES_WINDUP, TIMER_DELETE_ME) + return TRUE + +/// Looses one ring of spines. Skips the direction of whoever `spared_ref` points to. +/datum/artifact_effect/spines/proc/fire_volley(datum/weakref/spared_ref) + bristling = FALSE + var/obj/machinery/artifact/artifact = holder + if(istype(artifact) && artifact.suppressed) + return 0 + var/turf/center = source_turf() + if(!center) + return 0 + var/mob/living/spared = spared_ref?.resolve() + var/spared_angle = (spared && get_dist(center, spared) <= 1 && spared.loc != center) ? get_angle(center, spared) : null + var/atom/movable/launcher = artifact_effect_visible_source(holder) + var/step = 360 / volley + var/offset = rand(0, step - 1) + var/fired = 0 + for(var/i in 0 to volley - 1) + var/angle = (offset + i * step) % 360 + if(!isnull(spared_angle) && abs(closer_angle_difference(angle, spared_angle)) < step * 0.75) + continue + var/obj/projectile/artifact_spine/spine = new(center) + spine.firer = launcher + spine.fired_from = launcher + spine.range = range + 2 + spine.fire(angle) + fired++ + playsound(center, 'sound/items/weapons/pierce.ogg', 60, TRUE) + for(var/mob/living/target in living_in_range(2)) + if(target != spared) + log_harm(target) + return fired + +/// A bone spine. +/obj/projectile/artifact_spine + name = "bone spine" + icon_state = "magspear" + color = "#efe2c4" + damage = 10 + damage_type = BRUTE + armor_flag = BULLET + sharpness = SHARP_POINTY + hit_prone_targets = TRUE + hitsound = 'sound/items/weapons/pierce.ogg' + +#undef ARTIFACT_SPINES_WINDUP diff --git a/voidcrew/modules/xenoarch/effects_polaris/sprint.dm b/voidcrew/modules/xenoarch/effects_polaris/sprint.dm new file mode 100644 index 00000000000..efac54d7df7 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/sprint.dm @@ -0,0 +1,25 @@ +// Artifact effect: sprint. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/sprinting.dm. +// Voidcrew: uncommon, not common (design catalogue); a short movement-speed status effect with a +// fading afterimage, instead of Polaris' /datum/modifier; doses never stack past a minute. + +/datum/artifact_effect/bestow/sprint + label_name = "Speeds people up" + log_name = "Sprint" + tier = ARTIFACT_TIER_UNCOMMON + helpful = TRUE + possible_kinds = list(ARTIFACT_ENERGY_CONCENTRATED, ARTIFACT_ENERGY_PSIONIC) + status_type = /datum/status_effect/artifact/sprint + touch_duration = 45 SECONDS + pulse_duration = 25 SECONDS + aura_duration = 8 SECONDS + +/datum/artifact_effect/bestow/sprint/on_bestowed(mob/living/target) + if(issilicon(target)) + to_chat(target, span_notice("Your actuators whine up to a higher pitch.")) + else + to_chat(target, span_notice("Your legs fill with a restless spring.")) + playsound(target, 'sound/effects/magic/tail_swing.ogg', 20, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/bestow/sprint/on_renewed(mob/living/target) + to_chat(target, span_notice("Your legs itch to run.")) diff --git a/voidcrew/modules/xenoarch/effects_polaris/status_effects.dm b/voidcrew/modules/xenoarch/effects_polaris/status_effects.dm new file mode 100644 index 00000000000..fd83aec0b84 --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/status_effects.dm @@ -0,0 +1,329 @@ +// Status effects applied by artifact effects. +// +// Rewritten for tg from the Polaris (6cd19fe0dec6) and VOREStation (9335d66b9fdf) /datum/modifier +// types the xenoarchaeology effects used (fortify, faraday, sprinting, berserk and its exhaustion, +// feysight). tg has no modifiers, so each is a status effect here. +// +// None of them stack. A fresh dose only tops the time up to that dose's own length, never past +// max_duration, so standing in an aura keeps a buff going but never banks a long one. +// Also here: the shared parent for effects that hand one of these out. + +/// Artifact status effects: refresh to the longer of what is left and the new dose. +/datum/status_effect/artifact + id = "artifact" + status_type = STATUS_EFFECT_REFRESH + duration = 30 SECONDS + tick_interval = STATUS_EFFECT_NO_TICK + alert_type = null + /// Longest one dose can last, in deciseconds + var/max_duration = 2 MINUTES + +/datum/status_effect/artifact/on_creation(mob/living/new_owner, set_duration) + if(isnum(set_duration)) + duration = clamp(set_duration, 1 SECONDS, max_duration) + return ..() + +/datum/status_effect/artifact/refresh(mob/living/new_owner, set_duration) + var/dose = isnum(set_duration) ? clamp(set_duration, 1 SECONDS, max_duration) : initial(duration) + duration = max(duration, world.time + dose) + +// ===== Fortify ===== + +#define ARTIFACT_FORTIFY_DAMAGE_MULT 0.85 + +/datum/status_effect/artifact/fortify + id = "artifact_fortify" + max_duration = 90 SECONDS + alert_type = /atom/movable/screen/alert/status_effect/artifact_fortify + +/datum/status_effect/artifact/fortify/on_apply() + RegisterSignal(owner, COMSIG_MOB_APPLY_DAMAGE_MODIFIERS, PROC_REF(soften_blow)) + owner.add_filter("artifact_fortify", 2, outline_filter(1, "#a7b89aa8")) + return TRUE + +/datum/status_effect/artifact/fortify/on_remove() + UnregisterSignal(owner, COMSIG_MOB_APPLY_DAMAGE_MODIFIERS) + owner.remove_filter("artifact_fortify") + to_chat(owner, span_notice("Your skin softens and feels like your own again.")) + +/datum/status_effect/artifact/fortify/proc/soften_blow(mob/living/source, list/damage_mods, damage, damagetype) + SIGNAL_HANDLER + if(damagetype == BRUTE || damagetype == BURN) + damage_mods += ARTIFACT_FORTIFY_DAMAGE_MULT + +/atom/movable/screen/alert/status_effect/artifact_fortify + name = "Hardened Skin" + desc = "Your skin is tight and tough, like old leather." + icon_state = "slime_stoneskin" + +#undef ARTIFACT_FORTIFY_DAMAGE_MULT + +// ===== Faraday ===== + +/datum/status_effect/artifact/faraday + id = "artifact_faraday" + max_duration = 2 MINUTES + alert_type = /atom/movable/screen/alert/status_effect/artifact_faraday + /// Throttles the "it went nowhere" message + COOLDOWN_DECLARE(grounded_message) + +/datum/status_effect/artifact/faraday/on_apply() + RegisterSignal(owner, COMSIG_ATOM_PRE_EMP_ACT, PROC_REF(ground_pulse)) + owner.add_filter("artifact_faraday", 2, outline_filter(1, "#5fd3ff60")) + return TRUE + +/datum/status_effect/artifact/faraday/on_remove() + UnregisterSignal(owner, COMSIG_ATOM_PRE_EMP_ACT) + owner.remove_filter("artifact_faraday") + to_chat(owner, span_notice("The hush around you lifts, and the static comes back.")) + +/// Swallows an EMP whole: the mob, everything it carries, and its wiring. +/datum/status_effect/artifact/faraday/proc/ground_pulse(atom/source, severity) + SIGNAL_HANDLER + if(COOLDOWN_FINISHED(src, grounded_message)) + COOLDOWN_START(src, grounded_message, 5 SECONDS) + to_chat(owner, span_notice("A pulse crackles over your skin and goes nowhere.")) + new /obj/effect/temp_visual/emp(get_turf(owner)) + return EMP_PROTECT_SELF | EMP_PROTECT_CONTENTS | EMP_PROTECT_WIRES + +/atom/movable/screen/alert/status_effect/artifact_faraday + name = "Grounded" + desc = "A cold, still hush has settled on your skin." + icon_state = "shock_immune" + +// ===== Sprint ===== + +/datum/movespeed_modifier/status_effect/artifact_sprint + multiplicative_slowdown = -0.25 + blacklisted_movetypes = (FLYING|FLOATING) + +/datum/status_effect/artifact/sprint + id = "artifact_sprint" + max_duration = 60 SECONDS + alert_type = /atom/movable/screen/alert/status_effect/artifact_sprint + +/datum/status_effect/artifact/sprint/on_apply() + owner.add_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_sprint) + RegisterSignal(owner, COMSIG_MOVABLE_MOVED, PROC_REF(leave_afterimage)) + return TRUE + +/datum/status_effect/artifact/sprint/on_remove() + owner.remove_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_sprint) + UnregisterSignal(owner, COMSIG_MOVABLE_MOVED) + to_chat(owner, span_notice("Your legs feel heavy again.")) + +/// A fading copy of them where they just were. +/datum/status_effect/artifact/sprint/proc/leave_afterimage(atom/movable/source, atom/old_loc, movement_dir, forced) + SIGNAL_HANDLER + if(forced || !isturf(old_loc) || !prob(45)) + return + var/obj/effect/temp_visual/decoy/fading/halfsecond/afterimage = new(old_loc, owner) + afterimage.alpha = 110 + animate(afterimage, alpha = 0, time = 0.5 SECONDS) + +/atom/movable/screen/alert/status_effect/artifact_sprint + name = "Light on Your Feet" + desc = "Your legs feel springy and tireless. The floor seems to rush by." + icon_state = "realignment" + +// ===== Berserk and exhaustion ===== + +#define ARTIFACT_BERSERK_FORCE_MULT 1.25 +#define ARTIFACT_BERSERK_SWING_MULT 0.8 +#define ARTIFACT_EXHAUSTED_SWING_MULT 1.25 + +/datum/mood_event/artifact_berserk + description = "Everything makes me so ANGRY." + mood_change = -3 + timeout = 2 MINUTES + +/datum/status_effect/artifact/berserk + id = "artifact_berserk" + max_duration = 45 SECONDS + alert_type = /atom/movable/screen/alert/status_effect/artifact_berserk + +/datum/status_effect/artifact/berserk/on_apply() + // The fury needs something to burn. A spent body can't hold it. + if(owner.stat == DEAD || owner.has_status_effect(/datum/status_effect/artifact/exhausted)) + return FALSE + ADD_TRAIT(owner, TRAIT_PERFECT_ATTACKER, TRAIT_STATUS_EFFECT(id)) + RegisterSignal(owner, COMSIG_MOB_ITEM_ATTACK, PROC_REF(swing_harder)) + owner.add_filter("artifact_berserk", 2, outline_filter(1, "#c0202080")) + owner.add_mood_event("artifact_berserk", /datum/mood_event/artifact_berserk) + return TRUE + +/datum/status_effect/artifact/berserk/on_remove() + REMOVE_TRAIT(owner, TRAIT_PERFECT_ATTACKER, TRAIT_STATUS_EFFECT(id)) + UnregisterSignal(owner, COMSIG_MOB_ITEM_ATTACK) + owner.remove_filter("artifact_berserk") + if(QDELETED(owner) || owner.stat == DEAD) + return + to_chat(owner, span_warning("The anger drains out of you, and takes your strength with it.")) + owner.apply_status_effect(/datum/status_effect/artifact/exhausted, 25 SECONDS) + +/datum/status_effect/artifact/berserk/nextmove_modifier() + return ARTIFACT_BERSERK_SWING_MULT + +/datum/status_effect/artifact/berserk/proc/swing_harder(mob/living/source, mob/living/target, mob/living/user, list/modifiers, list/attack_modifiers) + SIGNAL_HANDLER + MODIFY_ATTACK_FORCE_MULTIPLIER(attack_modifiers, ARTIFACT_BERSERK_FORCE_MULT) + +/atom/movable/screen/alert/status_effect/artifact_berserk + name = "Seeing Red" + desc = "Your blood is up. You want to hit something." + icon_state = "blooddrunk" + +/datum/movespeed_modifier/status_effect/artifact_exhausted + multiplicative_slowdown = 0.6 + blacklisted_movetypes = (FLYING|FLOATING) + +/// Worn out: after a rage, a life drain, or being dragged back from death. +/datum/status_effect/artifact/exhausted + id = "artifact_exhausted" + max_duration = 60 SECONDS + alert_type = /atom/movable/screen/alert/status_effect/artifact_exhausted + +/datum/status_effect/artifact/exhausted/on_apply() + owner.add_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_exhausted) + return TRUE + +/datum/status_effect/artifact/exhausted/on_remove() + owner.remove_movespeed_modifier(/datum/movespeed_modifier/status_effect/artifact_exhausted) + +/datum/status_effect/artifact/exhausted/nextmove_modifier() + return ARTIFACT_EXHAUSTED_SWING_MULT + +/atom/movable/screen/alert/status_effect/artifact_exhausted + name = "Drained" + desc = "You feel wrung out. Every step is an effort." + icon_state = "weaken" + +#undef ARTIFACT_BERSERK_FORCE_MULT +#undef ARTIFACT_BERSERK_SWING_MULT +#undef ARTIFACT_EXHAUSTED_SWING_MULT + +// ===== Feysight ===== + +/datum/client_colour/artifact_feysight + priority = CLIENT_COLOR_TEMPORARY_PRIORITY + color = "#d4ffdc" + fade_in = 1 SECONDS + fade_out = 1 SECONDS + +/datum/status_effect/artifact/feysight + id = "artifact_feysight" + max_duration = 45 SECONDS + alert_type = /atom/movable/screen/alert/status_effect/artifact_feysight + +/datum/status_effect/artifact/feysight/on_apply() + ADD_TRAIT(owner, TRAIT_THERMAL_VISION, TRAIT_STATUS_EFFECT(id)) + RegisterSignal(owner, COMSIG_MOB_UPDATE_SIGHT, PROC_REF(tint_sight)) + owner.update_sight() + owner.add_client_colour(/datum/client_colour/artifact_feysight, REF(src)) + return TRUE + +/datum/status_effect/artifact/feysight/on_remove() + REMOVE_TRAIT(owner, TRAIT_THERMAL_VISION, TRAIT_STATUS_EFFECT(id)) + UnregisterSignal(owner, COMSIG_MOB_UPDATE_SIGHT) + owner.update_sight() + owner.remove_client_colour(REF(src)) + to_chat(owner, span_notice("You blink, and the walls are only walls again.")) + +/// A faint green to the dark while the sight lasts. +/datum/status_effect/artifact/feysight/proc/tint_sight(mob/source) + SIGNAL_HANDLER + source.lighting_color_cutoffs = blend_cutoff_colors(source.lighting_color_cutoffs, list(5, 22, 10)) + +/atom/movable/screen/alert/status_effect/artifact_feysight + name = "Second Sight" + desc = "Living things glow through the walls like coals through paper." + icon_state = "moon_hide" + +// ===== Shared helpers ===== + +/** + * What people see an effect coming from: the artifact itself, or, for an effect harvested into a + * battery, whoever or whatever carries that battery. Safe on a null or deleted holder. + */ +/proc/artifact_effect_visible_source(atom/holder) + if(!ismovable(holder)) + return holder + return get_atom_on_turf(holder) + +// ===== Shared visuals ===== + +/// A ring rolling out from an artifact. Pass the reach in tiles after the location. +/obj/effect/temp_visual/circle_wave/artifact_ring + +/obj/effect/temp_visual/circle_wave/artifact_ring/Initialize(mapload, scale) + if(isnum(scale)) + amount_to_scale = scale + return ..() + +// ===== Effects that hand one out ===== + +/** + * Shared parent for effects that give people near them a status effect: a touch gives the + * longest dose, a burst a medium one to everyone in range, and a field brushes people now and + * then with a short one. Protective gear shortens every dose. Not rollable itself. + */ +/datum/artifact_effect/bestow + /// The /datum/status_effect/artifact it hands out + var/datum/status_effect/artifact/status_type + var/touch_duration = 60 SECONDS + var/pulse_duration = 30 SECONDS + var/aura_duration = 10 SECONDS + /// Chance per second that the field reaches each person in range + var/aura_chance = 10 + +/datum/artifact_effect/bestow/do_effect_touch(mob/living/user) + bestow(user, touch_duration) + +/datum/artifact_effect/bestow/do_effect_aura(seconds_per_tick) + for(var/mob/living/target in living_in_range()) + if(SPT_PROB(aura_chance, seconds_per_tick)) + bestow(target, aura_duration, quiet = TRUE) + +/datum/artifact_effect/bestow/do_effect_pulse(power) + var/dose = pulse_duration * clamp(power / 25, 0.5, 1.5) + for(var/mob/living/target in living_in_range()) + bestow(target, dose) + +/** + * Gives `target` a dose lasting `duration` (deciseconds), shortened by protective gear. + * `quiet` keeps a field's top-ups from repeating the renewal message. + * Returns TRUE if they have it afterwards. + */ +/datum/artifact_effect/bestow/proc/bestow(mob/living/target, duration, quiet = FALSE) + if(!status_type || !can_bestow(target)) + return FALSE + duration *= artifact_exposure(target) + if(duration < 1 SECONDS) + return FALSE + var/had_it = !!target.has_status_effect(status_type) + target.apply_status_effect(status_type, duration) + if(!target.has_status_effect(status_type)) + on_refused(target) + return FALSE + if(!had_it) + on_bestowed(target) + else if(!quiet) + on_renewed(target) + log_harm(target) + return TRUE + +/// Who it works on. A harmful one carried in a battery works on whoever carries it too. +/datum/artifact_effect/bestow/proc/can_bestow(mob/living/target) + return target.stat != DEAD + +/// Hook: `target` just got their first dose. +/datum/artifact_effect/bestow/proc/on_bestowed(mob/living/target) + return + +/// Hook: `target` already had it and got topped up by a touch or burst. +/datum/artifact_effect/bestow/proc/on_renewed(mob/living/target) + return + +/// Hook: `target` could not take it (the status effect refused). +/datum/artifact_effect/bestow/proc/on_refused(mob/living/target) + return diff --git a/voidcrew/modules/xenoarch/effects_polaris/sweat.dm b/voidcrew/modules/xenoarch/effects_polaris/sweat.dm new file mode 100644 index 00000000000..5f4efce409c --- /dev/null +++ b/voidcrew/modules/xenoarch/effects_polaris/sweat.dm @@ -0,0 +1,97 @@ +// Artifact effect: sweat. +// Rewritten from Polaris (6cd19fe0dec6) code/modules/xenoarcheaology/effects/sweating_reagents.dm. +// Voidcrew: Polaris could weep any reagent in the game (and blood); this weeps one mild, +// everyday liquid picked from a short list, so it is never a free source of anything worth +// having. It pools into a small puddle that can be mopped or scooped up, and a puddle stops +// growing once it holds a cupful. + +/// A puddle stops growing once it holds this many units +#define ARTIFACT_SWEAT_PUDDLE_CAP 30 + +/datum/artifact_effect/sweat + label_name = "Weeps fluid" + log_name = "Sweat" + tier = ARTIFACT_TIER_COMMON + minor = TRUE + possible_kinds = list(ARTIFACT_ENERGY_ORGANIC, ARTIFACT_ENERGY_SYNTHESIS) + /// What it weeps + var/datum/reagent/reagent_type = /datum/reagent/water + +/datum/artifact_effect/sweat/setup() + var/static/list/weepings = list( + /datum/reagent/water, + /datum/reagent/water/salt, + /datum/reagent/consumable/sugar, + /datum/reagent/consumable/nutriment/fat/oil, + /datum/reagent/consumable/vinegar, + ) + reagent_type = pick(weepings) + +/datum/artifact_effect/sweat/copy_settings_to(datum/artifact_effect/sweat/copy) + copy.reagent_type = reagent_type + +/datum/artifact_effect/sweat/do_effect_touch(mob/living/user) + var/turf/user_turf = get_turf(user) + if(prob(25) && weep(user_turf, 6)) + var/atom/source = istype(holder, /obj/machinery/artifact) ? holder : null + user.visible_message( + span_warning("[source ? "[source] shudders at [user]'s touch and spits" : "Something spits"] a slick of fluid across [user]'s feet!"), + span_warning("[source ? "[source] shudders at your touch and spits" : "Something spits"] a slick of fluid across your feet!"), + ) + playsound(user_turf, 'sound/effects/splat.ogg', 35, TRUE) + return + weep(source_turf(), 2) + to_chat(user, span_notice("A cold, slick film beads on your skin.")) + +/datum/artifact_effect/sweat/do_effect_aura(seconds_per_tick) + if(SPT_PROB(25, seconds_per_tick) && weep(source_turf(), 2)) + playsound(source_turf(), 'sound/effects/bubbles/bubbles.ogg', 15, TRUE, SILENCED_SOUND_EXTRARANGE) + +/datum/artifact_effect/sweat/do_effect_pulse(power) + var/turf/center = source_turf() + if(!center) + return + var/spilled = weep(center, clamp(power / 4, 2, 10)) + var/list/neighbours = list() + for(var/turf/open/spot in orange(1, center)) + neighbours += spot + for(var/i in 1 to min(3, length(neighbours))) + spilled = weep(pick_n_take(neighbours), clamp(power / 8, 1, 5)) || spilled + if(spilled) + if(istype(holder, /obj/machinery/artifact)) + center.visible_message(span_warning("[holder] shudders and spits fluid across the floor.")) + else + center.visible_message(span_warning("Fluid spatters across the floor.")) + playsound(center, 'sound/effects/splat.ogg', 40, TRUE) + +/// Adds `amount` of its liquid to a puddle on `spot`. Returns TRUE if any went in. +/datum/artifact_effect/sweat/proc/weep(turf/open/spot, amount) + if(!istype(spot) || amount <= 0 || isspaceturf(spot) || isgroundlessturf(spot) || islava(spot)) + return FALSE + var/obj/effect/decal/cleanable/artifact_ooze/puddle = locate() in spot + if(!puddle) + puddle = new(spot) + if(QDELETED(puddle)) + return FALSE + if(!puddle.reagents) + puddle.create_reagents(ARTIFACT_SWEAT_PUDDLE_CAP) + var/room = ARTIFACT_SWEAT_PUDDLE_CAP - puddle.reagents.total_volume + if(room <= 0) + return FALSE + puddle.reagents.add_reagent(reagent_type, min(amount, room)) + // Just the hue: water's own colour is nearly clear and the slick would vanish. + puddle.color = copytext(initial(reagent_type.color), 1, 8) + return TRUE + +/// A puddle of whatever an artifact wept. Scoop it up with a container, or mop it. +/obj/effect/decal/cleanable/artifact_ooze + name = "slick" + desc = "A small, faintly warm puddle of something thin." + icon = 'icons/effects/blood.dmi' + icon_state = "floor1" + random_icon_states = list("floor1", "floor2", "floor3", "floor4", "floor5", "floor6", "floor7") + alpha = 200 + beauty = -25 + mergeable_decal = FALSE + +#undef ARTIFACT_SWEAT_PUDDLE_CAP diff --git a/voidcrew/modules/xenoarch/icons/artifacts.dmi b/voidcrew/modules/xenoarch/icons/artifacts.dmi new file mode 100644 index 00000000000..eb78e3d4591 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/artifacts.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/curios.dmi b/voidcrew/modules/xenoarch/icons/curios.dmi new file mode 100644 index 00000000000..9c0676c242e Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/curios.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/dig_finds.dmi b/voidcrew/modules/xenoarch/icons/dig_finds.dmi new file mode 100644 index 00000000000..9d997f52b08 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/dig_finds.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/dig_machines.dmi b/voidcrew/modules/xenoarch/icons/dig_machines.dmi new file mode 100644 index 00000000000..9831561bd32 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/dig_machines.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/dig_scan.dmi b/voidcrew/modules/xenoarch/icons/dig_scan.dmi new file mode 100644 index 00000000000..236d0c8e74b Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/dig_scan.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/dig_site.dmi b/voidcrew/modules/xenoarch/icons/dig_site.dmi new file mode 100644 index 00000000000..f75c1279768 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/dig_site.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/dig_tools.dmi b/voidcrew/modules/xenoarch/icons/dig_tools.dmi new file mode 100644 index 00000000000..625e047c193 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/dig_tools.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/specimen_crate.dmi b/voidcrew/modules/xenoarch/icons/specimen_crate.dmi new file mode 100644 index 00000000000..8820a1096e6 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/specimen_crate.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/study.dmi b/voidcrew/modules/xenoarch/icons/study.dmi new file mode 100644 index 00000000000..93bb8673886 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/study.dmi differ diff --git a/voidcrew/modules/xenoarch/icons/use.dmi b/voidcrew/modules/xenoarch/icons/use.dmi new file mode 100644 index 00000000000..a49c5e20d60 Binary files /dev/null and b/voidcrew/modules/xenoarch/icons/use.dmi differ diff --git a/voidcrew/modules/xenoarch/study/analyser.dm b/voidcrew/modules/xenoarch/study/analyser.dm new file mode 100644 index 00000000000..ca38994cdb3 --- /dev/null +++ b/voidcrew/modules/xenoarch/study/analyser.dm @@ -0,0 +1,585 @@ +/** + * # Artifact analyser + * + * Ported from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/machines/artifact_analyzer.dm, + * rewritten for Voidcrew. Machine art from Nova's machinery.dmi (by way of TauCetiClassic), + * CC BY-SA 3.0; see icons/study.dmi. + * + * - A tgui instrument instead of Nova's HTML window: a live trace of the find on the pad, the last + * reading, and a paper tape of everything the pad sensed while the crew tested it. + * - A scan claims the find with try_lock() and lets go on finish, halt, power loss, the find + * leaving the pad, and Destroy(). Nova's halt never let go, which jammed the find for good. + * - The report is lab paperwork: serial, condition, and one report_line() per emission. It names + * what the find gives off, never what it does. + * - The first full analysis of a dug find pays research once, as notes (research.dm). + */ + +/// Sent on a scan pad (scanpad.dm) when a large find arrives on it or leaves it, or the pad itself +/// changes: (). Defined here because this file compiles first; the harvester listens for it too. +#define COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED "xenoarch_pad_specimen_changed" + +/// Lines the tape keeps before the oldest scrolls off. +#define ANALYSER_TAPE_LENGTH 12 +/// A repeated tape line within this long adds to the line before instead of printing again. +#define ANALYSER_TAPE_REPEAT_WINDOW (20 SECONDS) + +// Tape line tones, for the screen. +#define TAPE_NOTE "note" +#define TAPE_RESPONSE "response" +#define TAPE_QUIET "quiet" +#define TAPE_FAULT "fault" + +/obj/machinery/artifact_analyser + name = "artifact analyser" + desc = "A bench console with a slow green screen and a narrow printer slot. A cable runs from its back to the floor." + icon = 'voidcrew/modules/xenoarch/icons/study.dmi' + icon_state = "analyser" + base_icon_state = "analyser" + density = TRUE + anchored = TRUE + circuit = /obj/item/circuitboard/machine/artifact_analyser + idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION + active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION + /// The scan pad it reads through + var/obj/machinery/artifact_scanpad/pad + /// The find on that pad whose stirrings go on the tape + var/obj/machinery/artifact/watched + /// The find being scanned, which this analyser holds the lock on + var/obj/machinery/artifact/scan_target + /// Who started the scan, for the research log + var/datum/weakref/scan_operator + /// world.time the scan began + var/scan_started = 0 + /// How long a scan takes; better scanning modules shorten it + var/scan_time = 10 SECONDS + /// Timer that ends the scan + var/scan_timer + /// The last completed reading, as the screen shows it + var/list/reading + /// The find that reading belongs to + var/datum/weakref/reading_of + /// The tape: list(list("time", "text", "tone", "count", "at")) + var/list/tape = list() + /// Reports printed, for the report number + var/reports_printed = 0 + /// Delay between the printer starting and the paper coming out + var/print_delay = 1.5 SECONDS + /// list(name, text, research points) of a report still in the printer + var/list/pending_printout + /// Wakes waiting to go on the tape after whatever stimulus caused them + var/list/pending_lines + COOLDOWN_DECLARE(tear_cooldown) + +/obj/machinery/artifact_analyser/post_machine_initialize() + . = ..() + find_pad() + +/obj/machinery/artifact_analyser/Destroy() + eject_printout() + abort_scan(quiet = TRUE) + set_watched(null, quiet = TRUE) + set_pad(null) + reading = null + reading_of = null + scan_operator = null + pending_lines = null + return ..() + +/obj/machinery/artifact_analyser/RefreshParts() + . = ..() + // Two stock modules make a ten-second scan; the best modules cut it to six. + var/rating = max(total_part_rating(/datum/stock_part/scanning_module), 2) + scan_time = max(6 SECONDS, 10 SECONDS - (rating - 2) * (4 SECONDS / 6)) + +// ===== The pad ===== + +/// Finds a scan pad next to it, preferring the one it faces. +/obj/machinery/artifact_analyser/proc/find_pad() + if(pad && !QDELETED(pad) && get_dist(src, pad) <= 1) + return pad + var/obj/machinery/artifact_scanpad/found = locate() in get_step(src, dir) + if(!found) + for(var/obj/machinery/artifact_scanpad/nearby in orange(1, src)) + found = nearby + break + set_pad(found) + return pad + +/obj/machinery/artifact_analyser/proc/set_pad(obj/machinery/artifact_scanpad/new_pad) + if(new_pad == pad) + return + if(pad) + abort_scan("Pad lost. Scan stopped.") + UnregisterSignal(pad, list(COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED, COMSIG_QDELETING)) + pad = new_pad + if(pad) + RegisterSignal(pad, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED, PROC_REF(on_pad_changed)) + RegisterSignal(pad, COMSIG_QDELETING, PROC_REF(on_pad_deleted)) + refresh_watch() + +/obj/machinery/artifact_analyser/proc/on_pad_deleted(datum/source) + SIGNAL_HANDLER + set_pad(null) + SStgui.update_uis(src) + +/obj/machinery/artifact_analyser/proc/on_pad_changed(datum/source) + SIGNAL_HANDLER + if(pad && get_dist(src, pad) > 1) + set_pad(null) + else + refresh_watch() + SStgui.update_uis(src) + +/obj/machinery/artifact_analyser/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE) + . = ..() + if(pad && get_dist(src, pad) > 1) + set_pad(null) + +/// Ready to read the pad: powered, bolted down, closed up. +/obj/machinery/artifact_analyser/proc/can_operate() + return is_operational && anchored && !panel_open + +// ===== Watching the find on the pad ===== + +/// Follows whatever now stands on the pad, and drops a scan whose find has gone. +/obj/machinery/artifact_analyser/proc/refresh_watch() + var/obj/machinery/artifact/on_pad = (pad && !QDELETED(pad)) ? pad.get_specimen() : null + if(scan_target && (scan_target != on_pad || !pad.can_scan())) + abort_scan(scan_target == on_pad ? "Pad offline. Scan stopped." : "Specimen moved. Scan lost.") + set_watched(on_pad) + +/obj/machinery/artifact_analyser/proc/set_watched(obj/machinery/artifact/find, quiet = FALSE) + if(find == watched) + return + if(watched) + UnregisterSignal(watched, list( + COMSIG_ARTIFACT_STIMULATED, + COMSIG_ARTIFACT_EFFECT_ACTIVATED, + COMSIG_ARTIFACT_EFFECT_DEACTIVATED, + COMSIG_ARTIFACT_LABEL_CHANGED, + COMSIG_QDELETING, + )) + if(!quiet && !find) + add_tape("Pad clear.", TAPE_NOTE) + watched = find + pending_lines = null + if(!watched) + return + RegisterSignal(watched, COMSIG_ARTIFACT_STIMULATED, PROC_REF(on_stimulated)) + RegisterSignal(watched, COMSIG_ARTIFACT_EFFECT_ACTIVATED, PROC_REF(on_effect_woke)) + RegisterSignal(watched, COMSIG_ARTIFACT_EFFECT_DEACTIVATED, PROC_REF(on_effect_slept)) + RegisterSignal(watched, COMSIG_ARTIFACT_LABEL_CHANGED, PROC_REF(on_label_changed)) + RegisterSignal(watched, COMSIG_QDELETING, PROC_REF(on_watched_deleted)) + if(!quiet) + add_tape("[specimen_name(watched)] on the pad.", TAPE_NOTE) + if(watched.is_active()) + add_tape("Active on arrival.", TAPE_RESPONSE) + +/obj/machinery/artifact_analyser/proc/on_watched_deleted(datum/source) + SIGNAL_HANDLER + if(scan_target == source) + abort_scan("Specimen lost. Scan stopped.") + set_watched(null) + SStgui.update_uis(src) + +/// "Kappa-4412", or a plain description for a find nobody tagged. +/obj/machinery/artifact_analyser/proc/specimen_name(obj/machinery/artifact/find) + return find.is_dug() ? find.serial : "Untagged find" + +/// "Primary" or "Secondary": which of the find's emissions an effect is. +/obj/machinery/artifact_analyser/proc/channel_name(datum/artifact_effect/effect) + if(watched && effect == watched.second_effect) + return "Secondary" + return "Primary" + +/// A stimulus reached the find: the tape records it, and whether anything answered. +/obj/machinery/artifact_analyser/proc/on_stimulated(datum/source, trigger, mob/living/user, woke) + SIGNAL_HANDLER + if(!can_operate()) + return + add_tape("[artifact_trigger_name(trigger)]. [woke ? "Response." : "No response."]", woke ? TAPE_RESPONSE : TAPE_QUIET) + if(woke) + flick("[base_icon_state]_alert", src) + playsound(src, 'sound/machines/beep/twobeep.ogg', 25, FALSE) + +/// An emission rose. Held a moment, so the stimulus that caused it prints first. +/obj/machinery/artifact_analyser/proc/on_effect_woke(datum/source, datum/artifact_effect/effect) + SIGNAL_HANDLER + if(!can_operate()) + return + LAZYADD(pending_lines, "[channel_name(effect)] emission rising.") + addtimer(CALLBACK(src, PROC_REF(flush_pending_lines)), 1, TIMER_UNIQUE) + +/obj/machinery/artifact_analyser/proc/on_effect_slept(datum/source, datum/artifact_effect/effect) + SIGNAL_HANDLER + if(!can_operate()) + return + add_tape("[channel_name(effect)] emission fading.", TAPE_QUIET) + SStgui.update_uis(src) + +/obj/machinery/artifact_analyser/proc/flush_pending_lines() + for(var/line in pending_lines) + add_tape(line, TAPE_RESPONSE) + pending_lines = null + SStgui.update_uis(src) + +/obj/machinery/artifact_analyser/proc/on_label_changed(datum/source) + SIGNAL_HANDLER + SStgui.update_uis(src) + +/// Prints a line on the tape, folding a quick repeat into the line before. +/obj/machinery/artifact_analyser/proc/add_tape(text, tone = TAPE_NOTE) + var/list/last = length(tape) ? tape[length(tape)] : null + if(last && last["text"] == text && world.time - last["at"] < ANALYSER_TAPE_REPEAT_WINDOW) + last["count"] += 1 + last["at"] = world.time + last["time"] = station_time_timestamp("hh:mm:ss") + else + tape += list(list( + "time" = station_time_timestamp("hh:mm:ss"), + "text" = text, + "tone" = tone, + "count" = 1, + "at" = world.time, + )) + if(length(tape) > ANALYSER_TAPE_LENGTH) + tape.Cut(1, 2) + SStgui.update_uis(src) + +// ===== Scanning ===== + +/// Starts a scan of the find on the pad. Returns TRUE if one began. +/obj/machinery/artifact_analyser/proc/start_scan(mob/user) + if(scan_target || !can_operate()) + return FALSE + find_pad() + if(!pad) + say("No pad connected.") + playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 30, FALSE) + return FALSE + if(!pad.can_scan()) + say("Pad offline.") + playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 30, FALSE) + return FALSE + var/obj/machinery/artifact/find = pad.get_specimen() + if(!find) + say("Nothing on the pad.") + playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 30, FALSE) + return FALSE + if(!find.try_lock(src)) + say("Too much interference.") + add_tape("Interference. Scan refused.", TAPE_FAULT) + playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 30, FALSE) + return FALSE + set_watched(find) + scan_target = find + scan_operator = user ? WEAKREF(user) : null + scan_started = world.time + scan_timer = addtimer(CALLBACK(src, PROC_REF(finish_scan)), scan_time, TIMER_STOPPABLE | TIMER_DELETE_ME) + pad.set_beam(TRUE) + update_use_power(ACTIVE_POWER_USE) + update_appearance() + playsound(src, 'sound/machines/terminal/terminal_processing.ogg', 30, FALSE) + add_tape("Scan begun.", TAPE_NOTE) + return TRUE + +/// Stops a scan before it finishes and lets go of the find. +/obj/machinery/artifact_analyser/proc/abort_scan(reason, quiet = FALSE) + if(!scan_target) + return + if(scan_timer) + deltimer(scan_timer) + scan_timer = null + var/obj/machinery/artifact/find = scan_target + scan_target = null + scan_operator = null + if(!QDELETED(find)) + find.release_lock(src) + if(pad && !QDELETED(pad)) + pad.set_beam(FALSE) + if(QDELETED(src)) + return + update_use_power(IDLE_POWER_USE) + update_appearance() + if(quiet) + return + if(reason) + add_tape(reason, TAPE_FAULT) + playsound(src, 'sound/machines/scanner/scanbuzz.ogg', 30, FALSE) + SStgui.update_uis(src) + +/// The scan ran its full length: read the find, print the report, pay research once. +/obj/machinery/artifact_analyser/proc/finish_scan() + scan_timer = null + var/obj/machinery/artifact/find = scan_target + if(QDELETED(find) || !pad || QDELETED(pad) || pad.get_specimen() != find || !pad.can_scan() || !can_operate()) + abort_scan("Specimen lost. Scan stopped.") + return + var/mob/operator = scan_operator?.resolve() + reading = build_reading(find) + reading_of = WEAKREF(find) + var/report_text = report_text(find) + var/report_name = "analysis report ([specimen_name(find)])" + // Research is claimed now, while the find is still locked to us, and printed with the report. + var/research_points = xenoarch_claim_analysis(find, src, operator) + scan_target = null + scan_operator = null + find.release_lock(src) + pad.set_beam(FALSE) + update_use_power(IDLE_POWER_USE) + update_appearance() + say("Analysis complete.") + playsound(src, 'sound/machines/ping.ogg', 30, FALSE) + playsound(src, 'sound/machines/printer.ogg', 35, FALSE) + add_tape(research_points ? "Scan complete. Report and data printed." : "Scan complete. Report printed.", TAPE_NOTE) + // Held on the machine until it prints, so a console torn down mid-print still drops it. + eject_printout() + pending_printout = list(report_name, report_text, research_points) + if(print_delay) + addtimer(CALLBACK(src, PROC_REF(eject_printout)), print_delay) + else + eject_printout() + +/// Drops the waiting report, and the research notes if that analysis paid any. +/obj/machinery/artifact_analyser/proc/eject_printout() + if(!pending_printout) + return + var/report_name = pending_printout[1] + var/report_text = pending_printout[2] + var/research_points = pending_printout[3] + pending_printout = null + var/turf/out = drop_location() + if(!out) + return + var/obj/item/paper/artifact_report/report = new(out) + report.name = report_name + report.add_raw_text(report_text, advanced_html = TRUE) + report.update_appearance() + INVOKE_ASYNC(report, TYPE_PROC_REF(/obj/item/paper/artifact_report, stamp_report)) + if(research_points) + xenoarch_print_analysis_notes(out, research_points) + +/// What the screen shows for a finished reading. +/obj/machinery/artifact_analyser/proc/build_reading(obj/machinery/artifact/find) + var/list/channels = list() + if(find.main_effect) + channels += list(effect_reading("Primary", find.main_effect)) + if(find.second_effect) + channels += list(effect_reading("Secondary", find.second_effect)) + return list( + "serial" = specimen_name(find), + "name" = find.name, + "damaged" = find.damaged, + "channels" = channels, + ) + +/obj/machinery/artifact_analyser/proc/effect_reading(channel, datum/artifact_effect/effect) + var/list/parts = effect.report_parts() + return list( + "channel" = channel, + "kind" = parts["kind"], + "kind_key" = effect.energy_kind, + "release" = parts["release"], + "release_key" = effect.release_method, + "family" = parts["family"], + ) + +/// The printed report: lab paperwork with blanks for the analyst. +/obj/machinery/artifact_analyser/proc/report_text(obj/machinery/artifact/find) + reports_printed++ + var/list/lines = list() + lines += "
XENOARCHAEOLOGY
Analysis report no. [reports_printed]
[station_time_timestamp("hh:mm")]
" + lines += "
" + lines += "Specimen: [specimen_name(find)], [find.name]
" + lines += "Condition: [find.damaged ? "Fractured" : "Sound"]
" + lines += "
" + if(!find.main_effect && !find.second_effect) + lines += "No emissions detected.
" + else + lines += "Primary emission: [find.main_effect ? find.main_effect.report_line() : "None detected."]
" + lines += "Secondary emission: [find.second_effect ? find.second_effect.report_line() : "None detected."]
" + lines += "
" + lines += "Observations: \[____________________________________\]
" + lines += "\[____________________________________________________\]
" + lines += "Analyst: \[____________________\]" + return lines.Join("\n") + +/// Tears the tape off as a paper slip. +/obj/machinery/artifact_analyser/proc/tear_tape(mob/user) + if(!length(tape) || !COOLDOWN_FINISHED(src, tear_cooldown)) + return FALSE + COOLDOWN_START(src, tear_cooldown, 2 SECONDS) + var/obj/item/paper/artifact_tape/slip = new(drop_location()) + var/list/lines = list() + for(var/list/entry as anything in tape) + lines += "[entry["time"]] [entry["text"]][entry["count"] > 1 ? " (x[entry["count"]])" : ""]" + slip.add_raw_text("[lines.Join("
\n")]
", advanced_html = TRUE) + slip.update_appearance() + tape.Cut() + playsound(src, 'sound/items/poster/poster_ripped.ogg', 30, TRUE) + if(user) + user.put_in_hands(slip) + return TRUE + +// ===== Power, tools and looks ===== + +/obj/machinery/artifact_analyser/on_set_is_operational(old_value) + . = ..() + if(!is_operational) + abort_scan("Power lost. Scan stopped.") + update_appearance() + +/obj/machinery/artifact_analyser/update_icon_state() + if(panel_open) + icon_state = "[base_icon_state]_open" + else if(!is_operational) + icon_state = "[base_icon_state]_off" + else if(scan_target) + icon_state = "[base_icon_state]_working" + else + icon_state = base_icon_state + return ..() + +/obj/machinery/artifact_analyser/update_overlays() + . = ..() + if(!panel_open && is_operational) + . += emissive_appearance(icon, "[base_icon_state]_screen", src, alpha = 120) + +/obj/machinery/artifact_analyser/screwdriver_act(mob/living/user, obj/item/tool) + if(!default_deconstruction_screwdriver(user, "[base_icon_state]_open", base_icon_state, tool)) + return NONE + if(panel_open) + abort_scan("Panel open. Scan stopped.") + update_appearance() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact_analyser/crowbar_act(mob/living/user, obj/item/tool) + if(default_deconstruction_crowbar(tool)) + return ITEM_INTERACT_SUCCESS + return NONE + +/obj/machinery/artifact_analyser/wrench_act(mob/living/user, obj/item/tool) + if(scan_target) + balloon_alert(user, "it's scanning!") + return ITEM_INTERACT_BLOCKING + if(default_unfasten_wrench(user, tool) == SUCCESSFUL_UNFASTEN) + find_pad() + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact_analyser/examine(mob/user) + . = ..() + if(!pad) + . += "Its pad lamp is dark." + else if(scan_target) + . += span_notice("Its screen is crawling with numbers.") + +// ===== tgui ===== + +/obj/machinery/artifact_analyser/ui_interact(mob/user, datum/tgui/ui) + find_pad() + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "XenoarchAnalyser", name) + ui.open() + +/obj/machinery/artifact_analyser/ui_static_data(mob/user) + var/list/colors = list() + for(var/key in GLOB.artifact_energy_kinds) + var/datum/artifact_energy_kind/kind = GLOB.artifact_energy_kinds[key] + colors[key] = kind.color + return list("kind_colors" = colors) + +/obj/machinery/artifact_analyser/ui_data(mob/user) + var/list/data = list() + data["powered"] = can_operate() + if(!pad || QDELETED(pad)) + data["pad"] = "none" + else + data["pad"] = pad.can_scan() ? "ready" : "offline" + data["scanning"] = !!scan_target + data["progress"] = scan_target ? clamp(round((world.time - scan_started) / scan_time * 100), 0, 100) : 0 + data["specimen"] = null + if(watched && !QDELETED(watched)) + data["specimen"] = list( + "serial" = specimen_name(watched), + "name" = watched.name, + "awake" = !!watched.is_active() && !watched.suppressed, + "resting" = !!watched.all_awake_resting(), + "label" = watched.label ? "[watched.label.effect_name] / [watched.label.trigger_name] / [watched.label.second_name]" : null, + ) + data["reading"] = null + if(reading) + var/obj/machinery/artifact/subject = reading_of?.resolve() + var/current = !!(subject && subject == watched) + var/list/shown = reading.Copy() + shown["current"] = current + // While the read find is on the pad, each emission's trace follows it live. + var/list/channels = list() + for(var/list/channel as anything in reading["channels"]) + var/list/live = channel.Copy() + var/datum/artifact_effect/effect = null + if(current) + effect = channel["channel"] == "Secondary" ? subject.second_effect : subject.main_effect + live["awake"] = !!(effect?.activated && !subject.suppressed) + live["resting"] = !!(effect?.activated && effect.exhausted) + channels += list(live) + shown["channels"] = channels + data["reading"] = shown + var/list/tape_lines = list() + for(var/list/entry as anything in tape) + tape_lines += list(list("time" = entry["time"], "text" = entry["text"], "tone" = entry["tone"], "count" = entry["count"])) + data["tape"] = tape_lines + return data + +/obj/machinery/artifact_analyser/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) + . = ..() + if(.) + return + var/mob/user = ui.user + switch(action) + if("scan") + if(start_scan(user)) + return TRUE + if("halt") + if(scan_target) + say("Scan halted.") + abort_scan("Scan halted.") + return TRUE + if("tear") + return tear_tape(user) + return FALSE + +// ===== Paperwork ===== + +/// The printed analysis report. +/obj/item/paper/artifact_report + name = "analysis report" + +/// The analyser's stamp across the report. +/obj/item/paper/artifact_report/proc/stamp_report() + var/datum/asset/spritesheet_batched/sheet = get_asset_datum(/datum/asset/spritesheet/simple/paper) + if(QDELETED(src) || !sheet) + return + add_stamp(sheet.icon_class_name("stamp-rd"), rand(260, 330), rand(20, 70), rand(-15, 15), "stamp-rd") + update_appearance() + +/// A length of tape torn off the analyser. +/obj/item/paper/artifact_tape + name = "analyser tape" + desc = "A curl of narrow printer tape." + +/obj/item/circuitboard/machine/artifact_analyser + name = "Artifact Analyser" + greyscale_colors = CIRCUIT_COLOR_SCIENCE + build_path = /obj/machinery/artifact_analyser + req_components = list( + /datum/stock_part/scanning_module = 2, + /obj/item/stack/sheet/glass = 1, + ) + +#undef ANALYSER_TAPE_LENGTH +#undef ANALYSER_TAPE_REPEAT_WINDOW +#undef TAPE_NOTE +#undef TAPE_RESPONSE +#undef TAPE_QUIET +#undef TAPE_FAULT diff --git a/voidcrew/modules/xenoarch/study/labeler.dm b/voidcrew/modules/xenoarch/study/labeler.dm new file mode 100644 index 00000000000..878389cd2db --- /dev/null +++ b/voidcrew/modules/xenoarch/study/labeler.dm @@ -0,0 +1,185 @@ +/** + * # Specimen labeler + * + * New code on BeeStation's idea (42b0625, code/modules/xenoarchaeology/tools/xenoarchaeology_labeler.dm). + * Art: BeeStation icons/obj/xenoarchaeology/xenoartifact_tech.dmi "labeler", CC BY-SA 3.0; the + * print animation in icons/study.dmi was drawn from it for Voidcrew. + * + * A handheld tag printer. The crew dials in three words from its fixed lists (what the find does, + * what wakes it, its second effect or "None") and presses a printed tag onto a large find. Nothing + * says whether the tag is right; a buyer's price is the only answer. Right-click peels a tag off. + */ +/obj/item/artifact_labeler + name = "specimen labeler" + desc = "A handheld tag printer with a little green screen. Its word list is burned into memory and can't be changed." + icon = 'voidcrew/modules/xenoarch/icons/study.dmi' + icon_state = "labeler" + inhand_icon_state = "electronic" + lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi' + righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi' + item_flags = NOBLUDGEON + w_class = WEIGHT_CLASS_SMALL + drop_sound = 'sound/items/handling/tape_drop.ogg' + pickup_sound = 'sound/items/handling/tape_pickup.ogg' + custom_materials = list( + /datum/material/iron = SMALL_MATERIAL_AMOUNT * 2, + /datum/material/glass = SMALL_MATERIAL_AMOUNT * 1.5, + ) + /// What the find does, as an effect's label word + var/effect_word + /// What wakes it, as a trigger word + var/trigger_word + /// Its second effect's label word, or ARTIFACT_LABEL_NONE + var/second_word + COOLDOWN_DECLARE(print_cooldown) + +/obj/item/artifact_labeler/examine(mob/user) + . = ..() + if(effect_word || trigger_word || second_word) + . += "Its screen reads: [effect_word || "..."] / [trigger_word || "..."] / [second_word || "..."]" + +/obj/item/artifact_labeler/attack_self(mob/user, modifiers) + . = ..() + if(.) + return + ui_interact(user) + return TRUE + +/// Whether all three words are set. +/obj/item/artifact_labeler/proc/is_complete() + return effect_word && trigger_word && second_word + +/** + * Dials one field to a word from its list. Returns TRUE if it changed. + * `field` is "effect", "trigger" or "second"; a null word clears the field. + */ +/obj/item/artifact_labeler/proc/set_word(field, word) + if(word && !(word in words_for(field))) + return FALSE + switch(field) + if("effect") + if(effect_word == word) + return FALSE + effect_word = word + if("trigger") + if(trigger_word == word) + return FALSE + trigger_word = word + if("second") + if(second_word == word) + return FALSE + second_word = word + else + return FALSE + return TRUE + +/// The words a field may take. +/obj/item/artifact_labeler/proc/words_for(field) + switch(field) + if("effect") + return artifact_effect_label_names() + if("trigger") + return artifact_trigger_label_names() + if("second") + return list(ARTIFACT_LABEL_NONE) + artifact_effect_label_names() + return list() + +/// A label datum for the words now set, or null if any is missing. +/obj/item/artifact_labeler/proc/make_label() + if(!is_complete()) + return null + return new /datum/artifact_label(effect_word, trigger_word, second_word) + +/obj/item/artifact_labeler/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers) + if(!istype(interacting_with, /obj/machinery/artifact)) + return NONE + var/obj/machinery/artifact/find = interacting_with + if(!is_complete()) + balloon_alert(user, "the tag is half blank!") + return ITEM_INTERACT_BLOCKING + if(!COOLDOWN_FINISHED(src, print_cooldown)) + return ITEM_INTERACT_BLOCKING + COOLDOWN_START(src, print_cooldown, 2 SECONDS) + flick("labeler_print", src) + playsound(src, 'sound/items/taperecorder/taperecorder_print.ogg', 35, TRUE) + if(!do_after(user, 1 SECONDS, find)) + return ITEM_INTERACT_BLOCKING + var/datum/artifact_label/new_label = make_label() + if(!new_label) + return ITEM_INTERACT_BLOCKING + var/replaced = !!find.label + find.apply_label(new_label, user) + // A tag sets the sale price, and anyone can reach a find, so leave a trail for admins. + log_game("[key_name(user)] tagged artifact [find.serial] as [effect_word] / [trigger_word] / [second_word] at [AREACOORD(find)].") + playsound(find, 'sound/items/handling/component_pickup.ogg', 30, TRUE) + user.visible_message( + span_notice("[user] presses a printed tag onto [find]."), + span_notice((replaced ? "You peel off the old tag and press the new one onto [find]." : "You press the tag onto [find].")), + ) + return ITEM_INTERACT_SUCCESS + +/obj/item/artifact_labeler/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers) + if(!istype(interacting_with, /obj/machinery/artifact)) + return NONE + var/obj/machinery/artifact/find = interacting_with + if(!find.label) + balloon_alert(user, "no tag on it!") + return ITEM_INTERACT_BLOCKING + if(!do_after(user, 1 SECONDS, find)) + return ITEM_INTERACT_BLOCKING + if(!find.remove_label(user)) + return ITEM_INTERACT_BLOCKING + log_game("[key_name(user)] peeled the tag off artifact [find.serial] at [AREACOORD(find)].") + playsound(find, 'sound/items/poster/poster_ripped.ogg', 20, TRUE) + user.visible_message( + span_notice("[user] peels the tag off [find]."), + span_notice("You peel the tag off [find]."), + ) + return ITEM_INTERACT_SUCCESS + +// ===== tgui ===== + +/obj/item/artifact_labeler/ui_state(mob/user) + return GLOB.hands_state + +/obj/item/artifact_labeler/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "XenoarchLabeler", name) + ui.open() + +/obj/item/artifact_labeler/ui_static_data(mob/user) + return list( + "effects" = artifact_effect_label_names(), + "triggers" = artifact_trigger_label_names(), + "none" = ARTIFACT_LABEL_NONE, + ) + +/obj/item/artifact_labeler/ui_data(mob/user) + return list( + "effect" = effect_word, + "trigger" = trigger_word, + "second" = second_word, + ) + +/obj/item/artifact_labeler/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) + . = ..() + if(.) + return + switch(action) + if("set") + var/field = params["field"] + var/word = params["word"] + if(!istext(field) || (!isnull(word) && !istext(word))) + return FALSE + if(set_word(field, word)) + playsound(src, 'sound/machines/terminal/terminal_button03.ogg', 15, TRUE) + return TRUE + if("clear") + if(effect_word || trigger_word || second_word) + effect_word = null + trigger_word = null + second_word = null + playsound(src, 'sound/machines/terminal/terminal_button07.ogg', 15, TRUE) + return TRUE + return FALSE diff --git a/voidcrew/modules/xenoarch/study/research.dm b/voidcrew/modules/xenoarch/study/research.dm new file mode 100644 index 00000000000..f2056bf7284 --- /dev/null +++ b/voidcrew/modules/xenoarch/study/research.dm @@ -0,0 +1,75 @@ +/** + * # Xenoarchaeology research + * + * Large finds: the first full analysis of a dug find pays research once, whichever crew runs it. + * The flag lives on the find (research_paid), so passing one find between crews pays nothing + * more. The points come out of the analyser as research notes, which any R&D console takes, so + * no machine here needs a techweb link. + * + * Small finds: each curio type pays once per techweb through the destructive analyzer, by tg's + * own techweb_point_items table (subtypes count as their nearest listed type). + */ + +/** + * Claims the research for analysing `find`, once per find. Marks it paid and logs the metric; + * the caller prints the notes. Returns the points, or 0 if it was never dug or already paid. + */ +/proc/xenoarch_claim_analysis(obj/machinery/artifact/find, atom/analyser, mob/user) + if(QDELETED(find) || !find.is_dug()) + return 0 + var/points = artifact_research_value(find) + if(points <= 0) + return 0 + find.research_paid = TRUE + record_metric( + category = METRIC_RESEARCH, + event = XENOARCH_METRIC_ANALYSED, + subject = "[find.main_effect?.type]", + points = points, + zone = xenoarch_band_name(find.origin_band), + details = list("serial" = find.serial, "tier" = find.main_effect?.tier), + actor = user, + location = analyser, + ) + return points + +/// Prints claimed analysis research as notes at `where`. +/proc/xenoarch_print_analysis_notes(atom/where, points) + if(!where || points <= 0) + return null + return new /obj/item/research_notes(where, points, "xenoarchaeology") + +/** + * Research the destructive analyzer pays once per techweb for each kind of small find. + * Points sit between 20 and 60, under the cheapest research node, so a full set of curios is a + * pleasant extra rather than a research route. + */ +GLOBAL_LIST_INIT(xenoarch_curio_research_points, list( + /obj/item/xenoarch_curio/shell = 20, + /obj/item/xenoarch_curio/plant_fossil = 25, + /obj/item/xenoarch_curio/bone = 25, + /obj/item/xenoarch_curio/bowl = 25, + /obj/item/xenoarch_curio/skull = 30, + /obj/item/xenoarch_curio/urn = 30, + /obj/item/xenoarch_curio/scrap = 30, + /obj/item/xenoarch_curio/sidearm = 35, + /obj/item/xenoarch_curio/seed_pod = 40, + /obj/item/xenoarch_curio/statuette = 45, + /obj/item/xenoarch_curio/instrument = 45, + /obj/item/xenoarch_curio/idol = 50, + /obj/item/xenoarch_curio/skeleton = 60, + // The strange object a site gives up is tg's relic. Only a dug one pays: maintenance relics and + // experimentor copies are the plain type. + /obj/item/relic/excavated = 60, +)) + +/// Adds the curio table to tg's destructive-analyzer payouts. +/proc/xenoarch_register_curio_research() + for(var/curio_type in GLOB.xenoarch_curio_research_points) + if(SSresearch.techweb_point_items[curio_type]) + continue + SSresearch.techweb_point_items[curio_type] = list(TECHWEB_POINT_TYPE_GENERIC = GLOB.xenoarch_curio_research_points[curio_type]) + +/datum/controller/subsystem/research/Initialize() + . = ..() + xenoarch_register_curio_research() diff --git a/voidcrew/modules/xenoarch/study/scanpad.dm b/voidcrew/modules/xenoarch/study/scanpad.dm new file mode 100644 index 00000000000..11a50416041 --- /dev/null +++ b/voidcrew/modules/xenoarch/study/scanpad.dm @@ -0,0 +1,180 @@ +/** + * # Scan pad + * + * Machine art: NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/icons/machinery.dmi, + * by way of TauCetiClassic, CC BY-SA 3.0. The unpowered, open and glow states in icons/study.dmi + * were edited from it for Voidcrew. The code is new. + * + * A floor plate under a low arch of sensor rods. A large find stands under the arch for the + * analyser beside it to read (and for the harvester to drain). The pad only knows what stands on + * it: the moment a find arrives or leaves it tells whatever is listening, so a reading can never + * outlive its subject (COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED, defined in analyser.dm, which compiles + * first). Whichever machine holds the find's lock drives the beam with set_beam(). + */ + +/obj/machinery/artifact_scanpad + name = "scan pad" + desc = "A floor plate under a low arch of sensor rods. The rods are tipped with violet glass." + icon = 'voidcrew/modules/xenoarch/icons/study.dmi' + icon_state = "scanpad" + base_icon_state = "scanpad" + // The arch draws over whatever stands under it; the plate is an overlay beneath. + layer = ABOVE_MOB_LAYER + density = FALSE + anchored = TRUE + circuit = /obj/item/circuitboard/machine/artifact_scanpad + idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.5 + active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION + /// The scanning beam is sweeping + var/beam_on = FALSE + /// Hum while the beam sweeps + var/datum/looping_sound/artifact_scanpad/scan_hum + +/obj/machinery/artifact_scanpad/Initialize(mapload) + . = ..() + var/static/list/loc_connections = list( + COMSIG_ATOM_ENTERED = PROC_REF(on_entered), + // A find made right on the pad (an admin, a test) never "enters" it. + COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZED_ON = PROC_REF(on_entered), + COMSIG_ATOM_EXITED = PROC_REF(on_exited), + ) + AddElement(/datum/element/connect_loc, loc_connections) + scan_hum = new(src) + update_appearance() + +/obj/machinery/artifact_scanpad/post_machine_initialize() + . = ..() + // An analyser built before its pad finds it now. + for(var/obj/machinery/artifact_analyser/analyser in orange(1, src)) + analyser.find_pad() + +/obj/machinery/artifact_scanpad/Destroy() + beam_on = FALSE + QDEL_NULL(scan_hum) + return ..() + +/// The large find standing on the pad, if any. +/obj/machinery/artifact_scanpad/proc/get_specimen() + if(!isturf(loc)) + return null + for(var/obj/machinery/artifact/find in loc) + if(!QDELETED(find)) + return find + return null + +/// Ready to read a find: powered, bolted down and closed up. +/obj/machinery/artifact_scanpad/proc/can_scan() + return is_operational && anchored && !panel_open + +/obj/machinery/artifact_scanpad/proc/on_entered(datum/source, atom/movable/arrived, atom/old_loc, list/atom/old_locs) + SIGNAL_HANDLER + if(istype(arrived, /obj/machinery/artifact)) + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + +/obj/machinery/artifact_scanpad/proc/on_exited(datum/source, atom/movable/gone, direction) + SIGNAL_HANDLER + if(istype(gone, /obj/machinery/artifact)) + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + +/obj/machinery/artifact_scanpad/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE) + . = ..() + // connect_loc follows us, but whoever was reading the old tile has to start over. + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + +/// Starts or stops the sweeping beam. +/obj/machinery/artifact_scanpad/proc/set_beam(on) + if(on == beam_on || QDELETED(src)) + return + beam_on = on + if(beam_on) + update_use_power(ACTIVE_POWER_USE) + playsound(src, 'sound/machines/destructive_scanner/TubeUp.ogg', 40, TRUE) + scan_hum?.start() + set_light(2, 0.8, "#a34de0") + else + update_use_power(IDLE_POWER_USE) + scan_hum?.stop() + set_light(0) + update_appearance() + +/obj/machinery/artifact_scanpad/on_set_is_operational(old_value) + . = ..() + if(!is_operational) + set_beam(FALSE) + update_appearance() + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + +/obj/machinery/artifact_scanpad/update_icon_state() + if(panel_open) + icon_state = "[base_icon_state]_open" + else if(!is_operational) + icon_state = "[base_icon_state]_off" + else + icon_state = base_icon_state + return ..() + +/obj/machinery/artifact_scanpad/update_overlays() + . = ..() + // The plate sits below anything standing on it. + . += mutable_appearance(icon, "[base_icon_state]_bottom", LOW_OBJ_LAYER) + if(panel_open || !is_operational) + return + . += emissive_appearance(icon, "[base_icon_state]_lights", src, alpha = 200) + if(beam_on) + . += mutable_appearance(icon, "[base_icon_state]_beam") + . += emissive_appearance(icon, "[base_icon_state]_beam", src) + +/obj/machinery/artifact_scanpad/screwdriver_act(mob/living/user, obj/item/tool) + if(beam_on) + balloon_alert(user, "it's scanning!") + return ITEM_INTERACT_BLOCKING + if(!default_deconstruction_screwdriver(user, "[base_icon_state]_open", base_icon_state, tool)) + return NONE + update_appearance() + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact_scanpad/crowbar_act(mob/living/user, obj/item/tool) + if(default_deconstruction_crowbar(tool)) + return ITEM_INTERACT_SUCCESS + return NONE + +/obj/machinery/artifact_scanpad/wrench_act(mob/living/user, obj/item/tool) + if(beam_on) + balloon_alert(user, "it's scanning!") + return ITEM_INTERACT_BLOCKING + if(default_unfasten_wrench(user, tool) == SUCCESSFUL_UNFASTEN) + SEND_SIGNAL(src, COMSIG_XENOARCH_PAD_SPECIMEN_CHANGED) + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact_scanpad/examine(mob/user) + . = ..() + var/obj/machinery/artifact/find = get_specimen() + if(find) + . += "[find] stands under the arch." + if(beam_on) + . += span_notice("A violet line sweeps slowly up and down under the arch.") + +/// The arch's hum while it sweeps. +/datum/looping_sound/artifact_scanpad + mid_sounds = list( + 'sound/machines/tcomms/tcomms_mid1.ogg' = 1, + 'sound/machines/tcomms/tcomms_mid3.ogg' = 1, + 'sound/machines/tcomms/tcomms_mid5.ogg' = 1, + ) + mid_length = 1.8 SECONDS + volume = 20 + extra_range = -6 + falloff_distance = 2 + falloff_exponent = 5 + ignore_walls = FALSE + +/obj/item/circuitboard/machine/artifact_scanpad + name = "Scan Pad" + greyscale_colors = CIRCUIT_COLOR_SCIENCE + build_path = /obj/machinery/artifact_scanpad + req_components = list( + /datum/stock_part/scanning_module = 2, + /datum/stock_part/micro_laser = 1, + /obj/item/stack/cable_coil = 2, + ) diff --git a/voidcrew/modules/xenoarch/study/techweb.dm b/voidcrew/modules/xenoarch/study/techweb.dm new file mode 100644 index 00000000000..459e1be8a6b --- /dev/null +++ b/voidcrew/modules/xenoarch/study/techweb.dm @@ -0,0 +1,88 @@ +/** + * # Xenoarchaeology research nodes + * + * Three nodes on tg's price ladder. The excavation kit itself comes from the ship autolathe and + * needs no research (dig/designs.dm). + * + * - Xenoarchaeology (tier 1): stabiliser, spectrometer, analyser and scan pad, labeler, specimen crate. + * - Advanced Excavation (tier 2): the advanced scanner and quick brush. + * - Exotic Particles (tier 3, yellow standing): the harvester, exotic battery and utilizer. + * + * Each node lists every design it unlocks, including those printed by the dig, use and trade + * parts of this module (named below by the file that defines them). + */ + +#define TECHWEB_NODE_XENOARCH "xenoarchaeology" +#define TECHWEB_NODE_XENOARCH_EXCAVATION "xenoarch_excavation" +#define TECHWEB_NODE_XENOARCH_EXOTIC "xenoarch_exotic_particles" + +/datum/techweb_node/xenoarchaeology + id = TECHWEB_NODE_XENOARCH + display_name = "Xenoarchaeology" + description = "Field stabilisers and a sample spectrometer for getting large finds out whole, and a bench analyser to read them once they're home." + prereq_ids = list(TECHWEB_NODE_FUNDIMENTAL_SCI) + design_ids = list( + "xenoarch_analyser", + "xenoarch_scanpad", + "xenoarch_labeler", + "xenoarch_stabiliser", // dig/stabiliser.dm + "xenoarch_spectrometer", // dig/spectrometer.dm + "xenoarch_specimen_crate", // trade/specimen_crate.dm + ) + research_costs = list(TECHWEB_POINT_TYPE_GENERIC = TECHWEB_TIER_1_POINTS) + +/datum/techweb_node/xenoarch_excavation + id = TECHWEB_NODE_XENOARCH_EXCAVATION + display_name = "Advanced Excavation" + description = "A depth scanner that reads the stabilising field on the spot, and a quicker brush." + prereq_ids = list(TECHWEB_NODE_XENOARCH) + design_ids = list( + "xenoarch_scanner_advanced", // dig/tools.dm + "xenoarch_brush_quick", // dig/tools.dm + ) + research_costs = list(TECHWEB_POINT_TYPE_GENERIC = TECHWEB_TIER_2_POINTS) + +/datum/techweb_node/xenoarch_exotic_particles + id = TECHWEB_NODE_XENOARCH_EXOTIC + display_name = "Exotic Particles" + description = "A harvester that draws a live emission out of a large find into a battery, and a handheld projector that can let it out again." + prereq_ids = list(TECHWEB_NODE_XENOARCH) + design_ids = list( + "xenoarch_harvester", // use/harvester.dm + "xenoarch_battery", // use/battery.dm + "xenoarch_utilizer", // use/utilizer.dm + ) + research_costs = list(TECHWEB_POINT_TYPE_GENERIC = TECHWEB_TIER_3_POINTS) + // The utilizer and battery are rated yellow (tools/gear_catalog/ratings/relics.json). + zone_permission = ZONE_PERMISSION_YELLOW + +// ===== Designs printed by this part ===== + +/datum/design/board/artifact_analyser + name = "Machine Design (Artifact Analyser Board)" + desc = "The circuit board for a bench artifact analyser." + id = "xenoarch_analyser" + build_path = /obj/item/circuitboard/machine/artifact_analyser + category = list(RND_CATEGORY_MACHINE + RND_SUBCATEGORY_MACHINE_RESEARCH) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE + +/datum/design/board/artifact_scanpad + name = "Machine Design (Scan Pad Board)" + desc = "The circuit board for the scan pad an artifact analyser reads through." + id = "xenoarch_scanpad" + build_path = /obj/item/circuitboard/machine/artifact_scanpad + category = list(RND_CATEGORY_MACHINE + RND_SUBCATEGORY_MACHINE_RESEARCH) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE + +/datum/design/artifact_labeler + name = "Specimen Labeler" + desc = "A handheld printer for the tags that go on large finds." + id = "xenoarch_labeler" + build_type = PROTOLATHE | AWAY_LATHE + materials = list( + /datum/material/iron = SMALL_MATERIAL_AMOUNT * 2, + /datum/material/glass = SMALL_MATERIAL_AMOUNT * 1.5, + ) + build_path = /obj/item/artifact_labeler + category = list(RND_CATEGORY_EQUIPMENT + RND_SUBCATEGORY_EQUIPMENT_SCIENCE) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE diff --git a/voidcrew/modules/xenoarch/trade/buyers.dm b/voidcrew/modules/xenoarch/trade/buyers.dm new file mode 100644 index 00000000000..f86e7bf32c1 --- /dev/null +++ b/voidcrew/modules/xenoarch/trade/buyers.dm @@ -0,0 +1,961 @@ +/** + * # Outpost buyers for dig finds + * + * Barnaby at Halcyon, Boffin at the Quartermain's Skunkworks and Vex at the Undertow buy what + * comes out of the old dig sites. They are the outposts' own traders: this file gives each one a + * buyer's voice (/datum/xenoarch_buyer) and two rows on their wanted ledger, so a find sells from + * the same Sell tab as everything else they buy. + * + * - Large finds are machinery, so the stock ledger (which only takes inventory items) can't hold + * them. /datum/shop_buyback/xenoarch_find takes the find the seller is pulling, loose or in a + * shut crate, once it is at the counter. The trader looks it over while the seller waits, then + * pays artifact_sale_value() into the account every other sale pays (get_shop_buyback_account()), + * prints a receipt and says what they made of it. The sale is final: nothing is quoted, so a + * label can't be tried out on the buyer. + * - Only finds stamped as dug sell. Vex pays a voucher on top for an extreme main effect. + * - Curios (/datum/shop_buyback/xenoarch_curio) are ordinary items marked as dug finds with + * xenoarch_mark_curio(); Barnaby and Boffin take them, and only Boffin takes strange objects. + * - Each buyer takes XENOARCH_FIND_DEMAND large finds and XENOARCH_CURIO_DEMAND curios at a time, + * topped up by the convoy like any other ledger row (shop.dm convoy_restock()). + * - A buyer notices a find being hauled up to the counter and says so, once per find. Sarge, who + * buys none, points the way to Boffin's stall instead. + * - Selling earns no reputation; that comes from jobs (trader_favor.dm). + */ + +/// Large finds each buyer takes before the next convoy +#define XENOARCH_FIND_DEMAND 3 +/// Curios each buyer takes before the next convoy +#define XENOARCH_CURIO_DEMAND 6 +/// How far from the trader a hauled find may be and still count as at the counter +#define XENOARCH_COUNTER_REACH 3 +/// How long the trader looks a find over before paying +#define XENOARCH_INSPECT_TIME (2.5 SECONDS) +/// Least time between the starts of two inspections, so the Sell button can't be used to make the trader spam +#define XENOARCH_INSPECT_COOLDOWN (4 SECONDS) +/// How far away a trader notices a find being hauled in +#define XENOARCH_NOTICE_RANGE 4 +/// Least time between two "what have you got there" remarks +#define XENOARCH_NOTICE_COOLDOWN (30 SECONDS) +/// How many finds a trader remembers having remarked on +#define XENOARCH_NOTICE_MEMORY 20 + +// Line keys for /datum/xenoarch_buyer/var/lines +/// Spoken when a find is hauled up +#define XENOARCH_LINE_NOTICE "notice" +/// Emotes while looking over a loose find; %THING% is the find +#define XENOARCH_LINE_INSPECT "inspect" +/// Emotes while looking into a crate; %THING% is the crate +#define XENOARCH_LINE_INSPECT_CRATED "inspect_crated" +/// Spoken while looking over a find that came out of the rock cracked +#define XENOARCH_LINE_CRACKED "cracked" +/// Spoken while looking over a find that has been drained +#define XENOARCH_LINE_TAPPED "tapped" +/// Spoken on paying for a find labelled right on every line +#define XENOARCH_LINE_PERFECT "perfect" +/// Spoken on paying for a find labelled mostly right +#define XENOARCH_LINE_CLOSE "close" +/// Spoken on paying for a find labelled mostly wrong +#define XENOARCH_LINE_WRONG "wrong" +/// Spoken on paying for a find with no label +#define XENOARCH_LINE_BLANK "blank" +/// Spoken on paying for a find with an extreme main effect +#define XENOARCH_LINE_LIVE "live" +/// Spoken when the seller walks off mid-inspection +#define XENOARCH_LINE_WALKED "walked" + +// ========================================================================= +// HAULING +// ========================================================================= + +/// The large find in `thing`: the artifact itself, or the first artifact in a shut crate. Null otherwise. +/proc/xenoarch_find_in(atom/movable/thing) + if(istype(thing, /obj/machinery/artifact)) + return thing + if(istype(thing, /obj/structure/closet)) + var/obj/structure/closet/box = thing + if(!box.opened) + return locate(/obj/machinery/artifact) in box.contents + return null + +/// Every large find `user` is hauling: the artifact they pull, or those in the shut crate they pull. +/proc/xenoarch_hauled_finds(mob/living/user) + . = list() + var/atom/movable/hauled = user?.pulling + if(istype(hauled, /obj/machinery/artifact)) + . += hauled + else if(istype(hauled, /obj/structure/closet)) + var/obj/structure/closet/box = hauled + if(!box.opened) + for(var/obj/machinery/artifact/find in box.contents) + . += find + +/// What a hauled find rides in: its crate, or the find itself when loose. +/proc/xenoarch_find_holder(obj/machinery/artifact/find) + if(!find) + return null + return isturf(find.loc) ? find : find.loc + +/// "1,125 cr" +/proc/xenoarch_credits_text(amount) + var/digits = num2text(round(abs(amount)), 12) + var/grouped = "" + while(length(digits) > 3) + grouped = ",[copytext(digits, -3)][grouped]" + digits = copytext(digits, 1, -3) + return "[amount < 0 ? "-" : ""][digits][grouped] cr" + +// ========================================================================= +// THE BUYERS +// ========================================================================= + +/** + * # Dig-find buyer + * + * The buying side of one outpost trader: their voice for finds, what they take, and how their + * receipt reads. One per shop, made by the shop (see /datum/outpost_shop/New below). + */ +/datum/xenoarch_buyer + /// The shop this buyer works for + var/datum/outpost_shop/shop + /// Vouchers paid on top of credits for a find whose main effect is extreme + var/extreme_vouchers = 0 + /// Buys large finds at all (a trader who only points the way to the buyer next door doesn't) + var/buys_finds = TRUE + /// Buys curios at all + var/buys_curios = TRUE + /// Takes tg's strange objects among the curios + var/takes_strange_objects = FALSE + /// Large-find ledger row: name, description and picture + var/find_name = "dig pieces" + var/find_desc = "Large finds out of the old dig sites." + var/find_icon = 'voidcrew/modules/xenoarch/icons/artifacts.dmi' + var/find_icon_state = "idol" + /// Curio ledger row: name, description and picture + var/curio_name = "curios" + var/curio_desc = "Small finds out of the old dig sites." + var/curio_icon = 'icons/obj/mining.dmi' + var/curio_icon_state = "skull" + /// Receipt heading, subheading, sign-off, hand, ink and paper stamp + var/receipt_title = "RECEIPT" + var/receipt_subtitle + var/receipt_signoff + var/receipt_font = PEN_FONT + var/receipt_ink = "#202020" + var/receipt_stamp + /// Heard while the buyer looks a find over + var/inspect_sound = 'sound/items/handling/paper_pickup.ogg' + /// Speech and emotes, by XENOARCH_LINE_* key + var/list/lines = list() + /// Extra idle chatter added to the shop's own + var/list/idle_lines = list() + /// Serials already remarked on, oldest first + var/list/noticed = list() + /// The find being looked over right now + var/datum/weakref/inspecting + /// When the buyer may next remark on a hauled find + COOLDOWN_DECLARE(notice_cooldown) + /// When the buyer may next start looking a find over + COOLDOWN_DECLARE(inspect_cooldown) + +/datum/xenoarch_buyer/New(datum/outpost_shop/shop) + . = ..() + src.shop = shop + +/datum/xenoarch_buyer/Destroy() + shop = null + inspecting = null + return ..() + +/// Ledger rows this buyer adds to their shop. +/datum/xenoarch_buyer/proc/ledger_types() + . = list() + if(buys_finds) + . += /datum/shop_buyback/xenoarch_find + if(buys_curios) + . += /datum/shop_buyback/xenoarch_curio + +/// The trader at the counter, if the interior has one. +/datum/xenoarch_buyer/proc/trader() + return shop?.trader_npc + +/// Looking a find over right now (a live find, not one sold or lost meanwhile), or only just done with one. +/datum/xenoarch_buyer/proc/is_busy() + var/obj/machinery/artifact/find = inspecting?.resolve() + if(QDELETED(find)) + inspecting = null + return !COOLDOWN_FINISHED(src, inspect_cooldown) + return TRUE + +/// Vouchers this buyer adds for `find`. A spent extreme is only a curiosity, and earns none. +/datum/xenoarch_buyer/proc/vouchers_for(obj/machinery/artifact/find) + if(extreme_vouchers > 0 && find?.main_effect && artifact_price_tier(find) == ARTIFACT_TIER_EXTREME) + return extreme_vouchers + return 0 + +/// A random line for `key`, or null. +/datum/xenoarch_buyer/proc/line(key) + var/list/options = lines[key] + return length(options) ? pick(options) : null + +/// The trader says `text`, and holds their other chatter back for a moment. +/datum/xenoarch_buyer/proc/speak(mob/living/basic/outpost_trader/vendor, text) + if(QDELETED(vendor) || !text) + return + COOLDOWN_START(vendor, speak_cooldown, 3 SECONDS) + vendor.say(text) + +/// The trader starts looking over `find`, riding in `holder` (the find itself, or its crate). +/datum/xenoarch_buyer/proc/begin_inspection(mob/living/basic/outpost_trader/vendor, obj/machinery/artifact/find, atom/movable/holder) + if(QDELETED(vendor)) + return + var/emote = line(holder == find ? XENOARCH_LINE_INSPECT : XENOARCH_LINE_INSPECT_CRATED) + if(emote) + vendor.manual_emote(replacetext(emote, "%THING%", "\the [holder]")) + if(holder != find) + playsound(holder, 'sound/machines/crate/crate_open.ogg', 20, TRUE) + if(inspect_sound) + playsound(vendor, inspect_sound, 30, TRUE) + // Cracks and a drained feel are plain to anyone looking; said while looking, not as a verdict. + if(find.damaged) + speak(vendor, line(XENOARCH_LINE_CRACKED)) + else if(find.harvests_taken() > 0) + speak(vendor, line(XENOARCH_LINE_TAPPED)) + +/// What the trader says as they pay for `find`. Only said once the find is theirs. +/datum/xenoarch_buyer/proc/closing_line(obj/machinery/artifact/find) + if(find.main_effect && artifact_price_tier(find) == ARTIFACT_TIER_EXTREME) + return line(XENOARCH_LINE_LIVE) + if(!find.label) + return line(XENOARCH_LINE_BLANK) + var/accuracy = round(find.label_accuracy(), 0.01) + if(accuracy >= 1) + return line(XENOARCH_LINE_PERFECT) + if(accuracy >= ARTIFACT_LABEL_ACCURACY_FLOOR) + return line(XENOARCH_LINE_CLOSE) + return line(XENOARCH_LINE_WRONG) + +/** + * Remarks on a find being hauled up to the counter, once per find and not too often. Runs on the + * trader's life tick. Only finds a player is pulling count: that is someone showing it off. + */ +/datum/xenoarch_buyer/proc/look_around(mob/living/basic/outpost_trader/vendor) + if(!COOLDOWN_FINISHED(src, notice_cooldown) || is_busy() || !isturf(vendor.loc)) + return + for(var/atom/movable/thing in range(XENOARCH_NOTICE_RANGE, vendor)) + var/mob/living/hauler = thing.pulledby + if(!hauler?.client) + continue + var/obj/machinery/artifact/find = xenoarch_find_in(thing) + if(!find?.is_dug() || (find.serial in noticed)) + continue + noticed += find.serial + if(length(noticed) > XENOARCH_NOTICE_MEMORY) + noticed.Cut(1, 2) + COOLDOWN_START(src, notice_cooldown, XENOARCH_NOTICE_COOLDOWN) + speak(vendor, line(XENOARCH_LINE_NOTICE)) + return + +/// The receipt's body: the facts of one sale, in this buyer's hand. +/datum/xenoarch_buyer/proc/receipt_text(list/sale) + var/list/parts = list() + parts += "
[receipt_title][receipt_subtitle ? "
[receipt_subtitle]" : ""]

" + parts += "Bought of [sale["seller"]], [sale["time"]].
" + parts += "One [sale["find"]], field tag [sale["serial"]].
" + parts += sale["label"] ? "The tag on it says: [sale["label"]].
" : "No label on it.
" + if(sale["condition"]) + parts += "Condition: [sale["condition"]].
" + parts += "
Paid [sale["price"]] to [sale["account"]].
" + if(sale["vouchers"]) + parts += "Also handed over: [sale["vouchers"]] trade voucher[sale["vouchers"] > 1 ? "s" : ""].
" + if(receipt_signoff) + parts += "
[receipt_signoff]" + return parts.Join() + +/// The facts of a sale, taken before the find is gone. +/datum/xenoarch_buyer/proc/sale_record(obj/machinery/artifact/find, mob/living/seller, price, vouchers, datum/bank_account/account) + var/list/condition = list() + if(find.damaged) + condition += "cracked" + if(find.harvests_taken() > 0) + condition += "drained" + var/label_text + if(find.label) + label_text = "[find.label.effect_name || "?"] / [find.label.trigger_name || "?"] / [find.label.second_name || ARTIFACT_LABEL_NONE]" + return list( + "seller" = seller?.real_name || "a stranger", + "time" = station_time_timestamp("hh:mm"), + "find" = find.name, + "serial" = find.serial, + "label" = label_text, + "label_off" = !!find.label && round(find.label_accuracy(), 0.01) < 1, + "condition" = length(condition) ? condition.Join(", ") : null, + "price" = xenoarch_credits_text(price), + "vouchers" = vouchers, + "account" = account?.account_holder || "the seller", + ) + +// ----- Barnaby: Waystation Halcyon, green ----- + +/datum/xenoarch_buyer/barnaby + find_name = "dig pieces" + find_desc = "Anything big and old out of the cliffs. Barnaby pays fair and keeps the nice ones in the back." + find_icon_state = "idol" + curio_name = "curios" + curio_desc = "Fossils, pots, little figures. The gift shop does well out of them." + curio_icon = 'icons/obj/mining.dmi' + curio_icon_state = "skull" + receipt_title = "WAYSTATION HALCYON" + receipt_subtitle = "General Store" + receipt_signoff = "With thanks, B." + receipt_font = FOUNTAIN_PEN_FONT + receipt_ink = "#24305e" + receipt_stamp = "stamp-qm" + inspect_sound = 'sound/items/handling/book_pickup.ogg' + lines = list( + XENOARCH_LINE_NOTICE = list( + "Goodness, what have you dragged in? Bring it round, dear.", + "Oh, that's come out of the ground, hasn't it. Let's have a look.", + "Mind the floor with that. It's only just been mopped.", + ), + XENOARCH_LINE_INSPECT = list( + "pushes his reading glasses up his nose and leans over %THING%.", + "peers at %THING% over his glasses, humming.", + ), + XENOARCH_LINE_INSPECT_CRATED = list( + "lifts the lid of %THING% and peers inside, glasses on the end of his nose.", + "props open %THING% with one hand and has a good long look.", + ), + XENOARCH_LINE_CRACKED = list( + "Oh dear. Cracked right down the side.", + "Somebody's been rough with this one.", + ), + XENOARCH_LINE_TAPPED = list( + "Feels tired, this one. Somebody's had a go at it.", + "Hm. Not as lively as it ought to be.", + ), + XENOARCH_LINE_PERFECT = list( + "Labelled proper and everything. You've done your homework, dear.", + "Exactly what it says on the tag. Lovely.", + ), + XENOARCH_LINE_CLOSE = list( + "Near enough what it says on the tag. I'll not quibble.", + "Mostly right, that label. Mostly.", + ), + XENOARCH_LINE_WRONG = list( + "I'm not sure this label's been anywhere near this thing, dear.", + "Whoever wrote this tag was guessing. I'll pay for the rock.", + ), + XENOARCH_LINE_BLANK = list( + "No label? Then I'm buying a mystery, and mysteries come cheap.", + "Not a word on it about what it does. I'll take it on faith, at a faith price.", + ), + XENOARCH_LINE_LIVE = list( + "Goodness. This one's very much awake in there. I'll be glad when the courier takes it.", + "Oh my. I'll be keeping this one well away from the biscuit tin.", + ), + XENOARCH_LINE_WALKED = list( + "Oh! Never mind, then.", + "Changed your mind? That's all right, dear.", + ), + ) + idle_lines = list( + "Folk keep digging funny old things out of the cliffs. I'll buy them, if they don't hum too loud.", + "Had a lad bring in a stone that whistled. Paid him for it. It's in the back. It still whistles.", + ) + +// ----- Boffin: the Skunkworks, Quartermain Depot, yellow ----- + +/datum/xenoarch_buyer/boffin + takes_strange_objects = TRUE + find_name = "alien artifacts" + find_desc = "Large finds out of the old dig sites. Boffin likes them catalogued and in one piece." + find_icon_state = "terminal" + curio_name = "curios and oddities" + curio_desc = "Small dig finds, and the strange objects nobody can explain. Especially those." + curio_icon = 'icons/obj/devices/artefacts.dmi' + curio_icon_state = "prototype3" + receipt_title = "THE SKUNKWORKS" + receipt_subtitle = "Specimen intake" + receipt_signoff = "Received for bench testing. Boffin, QA." + receipt_font = PEN_FONT + receipt_ink = "#1d3b6e" + receipt_stamp = "stamp-rd" + inspect_sound = 'sound/machines/scanner/scanner.ogg' + lines = list( + XENOARCH_LINE_NOTICE = list( + "Oh. Oh, that's not from around here. Bring it closer. No, not THAT close.", + "Is that a dig piece? Wheel it over, wheel it over.", + "I can hear that from here. Lovely.", + ), + XENOARCH_LINE_INSPECT = list( + "waves his multitool over %THING%, squinting at the readout.", + "taps %THING% with his multitool and listens.", + ), + XENOARCH_LINE_INSPECT_CRATED = list( + "pries up the lid of %THING% and pokes his multitool inside.", + "leans into %THING% with his multitool held out like a divining rod.", + ), + XENOARCH_LINE_CRACKED = list( + "Cracked straight through. Somebody dug this out with a shovel and a prayer.", + "Fracture lines. I can see them. I can always see them.", + ), + XENOARCH_LINE_TAPPED = list( + "Someone's been siphoning this. It's running on fumes.", + "Drained. Partly. The hum's a semitone flat.", + ), + XENOARCH_LINE_PERFECT = list( + "Label checks out on every line. Somebody on your crew owns a notebook. Keep them.", + "Correct on every count. I'm almost disappointed. Nothing left for me to discover.", + ), + XENOARCH_LINE_CLOSE = list( + "Label's close. I'll fix the rest in pencil.", + "Mostly right. The rest is what we in the trade call a learning opportunity.", + ), + XENOARCH_LINE_WRONG = list( + "Your label and my multitool disagree. My multitool is right.", + "This label is fiction. Good fiction. Still fiction.", + ), + XENOARCH_LINE_BLANK = list( + "No label. I love a blind test, but I don't pay for one.", + "Unlabelled. So I'm paying for a rock and a hunch.", + ), + XENOARCH_LINE_LIVE = list( + "Oh, this is a LIVE one. Nobody touch anything. Especially me.", + "That's the real thing. I'm going to need a bigger bench.", + ), + XENOARCH_LINE_WALKED = list( + "Hey! I was measuring that!", + "Fine. Take your rock. I'll measure the dent it left.", + ), + ) + idle_lines = list( + "Old dig pieces! Alien, ancient, occasionally ticking. My three favourite words.", + "Bring me something out of the deep rock. I promise to only lick it once.", + ) + +// A lab intake sheet, with a pencil note when the label needed fixing. +/datum/xenoarch_buyer/boffin/receipt_text(list/sale) + var/list/parts = list() + parts += "
[receipt_title]
[receipt_subtitle]

" + parts += "Specimen: [sale["serial"]] ([sale["find"]])
" + parts += "From: [sale["seller"]], [sale["time"]]
" + parts += "Label as received: [sale["label"] ? "[sale["label"]][sale["label_off"] ? " (corrected in pencil)" : ""]" : "none"]
" + parts += "Condition: [sale["condition"] || "intact"]
" + parts += "Paid: [sale["price"]] to [sale["account"]]
" + parts += "
[receipt_signoff]" + return parts.Join() + +// ----- Vex: Undertow Exchange, red ----- + +/datum/xenoarch_buyer/vex + extreme_vouchers = 1 + buys_curios = FALSE + find_name = "dig pieces" + find_desc = "Old alien finds. Vex has collectors in the deep ring who pay for the strange ones." + find_icon_state = "spindle" + receipt_title = "UNDERTOW EXCHANGE" + receipt_signoff = "No returns. This never happened." + receipt_font = PRINTER_FONT + receipt_ink = "#111111" + receipt_stamp = "stamp-void" + inspect_sound = null + lines = list( + XENOARCH_LINE_NOTICE = list( + "That's a dig piece. Bring it here. Slowly.", + "Now that's a conversation piece. Over here.", + "Collectors in the deep ring would kill for one of those. Some have.", + ), + XENOARCH_LINE_INSPECT = list( + "slides their sunglasses down and looks %THING% over without a word.", + "walks once around %THING%, slowly.", + ), + XENOARCH_LINE_INSPECT_CRATED = list( + "lifts the lid of %THING% with one gloved finger and looks in.", + "cracks %THING% open an inch and studies the gap.", + ), + XENOARCH_LINE_CRACKED = list( + "Cracked. Collectors hate cracks.", + "Somebody dropped this. More than once.", + ), + XENOARCH_LINE_TAPPED = list( + "Tapped. Somebody's had their fun with this.", + "Half of what it was. I can tell.", + ), + XENOARCH_LINE_PERFECT = list( + "Clean paperwork. My buyer likes clean paperwork.", + "Label's right. That's rarer than the rock.", + ), + XENOARCH_LINE_CLOSE = list( + "Label's close enough for my buyer. Not for me.", + "Mostly right. Mostly gets mostly paid.", + ), + XENOARCH_LINE_WRONG = list( + "Somebody guessed. I don't pay for guesses.", + "Wrong label. My buyer's going to ask questions. I'll answer them, for a fee.", + ), + XENOARCH_LINE_BLANK = list( + "No label. You're selling me a rock with a story you don't know.", + "Blank. Fine. I'll make up a story. Mine sell better.", + ), + XENOARCH_LINE_LIVE = list( + "Now this is worth something to people who don't deal in credits. Take the chit.", + "My buyer's going to want this very badly. Here. A little extra.", + ), + XENOARCH_LINE_WALKED = list( + "Walking away. Smart, or stupid. We'll see.", + "Suit yourself.", + ), + ) + idle_lines = list( + "The deep-ring collectors pay silly money for old dig pieces. The scarier the better.", + "Somebody brought me a crystal that hummed in a key I didn't like. Sold it in an hour.", + ) + +// Vex writes as little as possible down. +/datum/xenoarch_buyer/vex/receipt_text(list/sale) + var/list/parts = list() + parts += "
[receipt_title]

" + parts += "[sale["serial"]]. [sale["price"]] to [sale["account"]].[sale["vouchers"] ? " One chit." : ""]
" + parts += "
[receipt_signoff]" + return parts.Join() + +// ----- Sarge: Quartermain Depot's main counter, who sends finds round to Boffin ----- + +/datum/xenoarch_buyer/sarge + buys_finds = FALSE + buys_curios = FALSE + lines = list( + XENOARCH_LINE_NOTICE = list( + "That's not armor. Boffin buys rocks. Skunkworks, round the back.", + "Dig piece? Not my department. Boffin's stall.", + "Don't park that at my counter. Boffin's the one who wants it.", + ), + ) + +// ========================================================================= +// SHOPS AND TRADERS +// ========================================================================= + +/datum/outpost_shop + /// /datum/xenoarch_buyer type for a shop that buys dig finds, or null + var/xenoarch_buyer_type + /// This shop's dig-find buyer, if it buys them + var/datum/xenoarch_buyer/xenoarch_buyer + +/datum/outpost_shop/general + xenoarch_buyer_type = /datum/xenoarch_buyer/barnaby + +/datum/outpost_shop/vendor/skunkworks + xenoarch_buyer_type = /datum/xenoarch_buyer/boffin + +/datum/outpost_shop/black_market + xenoarch_buyer_type = /datum/xenoarch_buyer/vex + +/datum/outpost_shop/outfitter + xenoarch_buyer_type = /datum/xenoarch_buyer/sarge + +// The buyer's ledger rows go in before the base New() makes the buybacks, so they share the +// shop's demand and convoy restock like any other row. +/datum/outpost_shop/New(obj/structure/overmap/trader_outpost/outpost) + if(xenoarch_buyer_type) + xenoarch_buyer = new xenoarch_buyer_type(src) + buyback_types = buyback_types + xenoarch_buyer.ledger_types() + if(length(xenoarch_buyer.idle_lines)) + var/list/idle = trader_lines[TRADER_LINE_IDLE] + trader_lines[TRADER_LINE_IDLE] = (islist(idle) ? idle : list()) + xenoarch_buyer.idle_lines + . = ..() + if(!xenoarch_buyer) + return + for(var/datum/shop_buyback/buyback as anything in buybacks) + if(istype(buyback, /datum/shop_buyback/xenoarch_find)) + var/datum/shop_buyback/xenoarch_find/find_row = buyback + find_row.attach(xenoarch_buyer) + else if(istype(buyback, /datum/shop_buyback/xenoarch_curio)) + var/datum/shop_buyback/xenoarch_curio/curio_row = buyback + curio_row.attach(xenoarch_buyer) + +/datum/outpost_shop/Destroy() + QDEL_NULL(xenoarch_buyer) + return ..() + +/mob/living/basic/outpost_trader/Life(seconds_per_tick, times_fired) + . = ..() + shop?.xenoarch_buyer?.look_around(src) + +// ========================================================================= +// LARGE FINDS +// ========================================================================= + +/** + * # Large-find ledger row + * + * Buys the find the seller is pulling (loose, or in a shut crate), not anything in their pack. + * item_path stays null on purpose: Pike's remote ledger and the contract pricing skip rows without + * one, so a large find can only be sold by hauling it to an outpost. + */ +/datum/shop_buyback/xenoarch_find + name = "dig pieces" + desc = "Large finds out of the old dig sites." + category = "Dig Finds" + item_path = null + demand_min = XENOARCH_FIND_DEMAND + demand_max = XENOARCH_FIND_DEMAND + /// The buyer whose ledger this is + var/datum/xenoarch_buyer/buyer + +/datum/shop_buyback/xenoarch_find/Destroy() + buyer = null + return ..() + +/// Takes on `new_buyer`'s wording for the ledger. +/datum/shop_buyback/xenoarch_find/proc/attach(datum/xenoarch_buyer/new_buyer) + buyer = new_buyer + name = new_buyer.find_name + desc = new_buyer.find_desc + cached_icon = null + +/datum/shop_buyback/xenoarch_find/get_ui_icon() + if(!cached_icon && buyer) + cached_icon = icon2base64(icon(buyer.find_icon, buyer.find_icon_state, SOUTH, frame = 1)) + return cached_icon + +/datum/shop_buyback/xenoarch_find/get_payment_text() + return "by the piece" + +// Never an inventory item, whoever asks (plunder appraisal, Pike's ledger). +/datum/shop_buyback/xenoarch_find/matches(obj/item/offered) + return FALSE + +/datum/shop_buyback/xenoarch_find/find_refused_variant(mob/living/user) + return null + +/// The finds `user` is hauling that a buyer pays for (dug, and worth something), first to sell at the front. +/datum/shop_buyback/xenoarch_find/proc/sellable_finds(mob/living/user) + . = list() + for(var/obj/machinery/artifact/find as anything in xenoarch_hauled_finds(user)) + if(artifact_sale_value(find) > 0) + . += find + +// The trader takes one piece at a time, so a crate of three still shows one. +/datum/shop_buyback/xenoarch_find/count_carried_units(mob/living/user) + if(!istype(user)) + return 0 + return length(sellable_finds(user)) ? 1 : 0 + +/// Whether `find` is close enough to `vendor` to be looked at. +/datum/shop_buyback/xenoarch_find/proc/at_counter(obj/machinery/artifact/find, mob/living/basic/outpost_trader/vendor) + var/atom/movable/holder = xenoarch_find_holder(find) + return !QDELETED(vendor) && holder && get_dist(holder, vendor) <= XENOARCH_COUNTER_REACH + +/datum/shop_buyback/xenoarch_find/get_denial_reason(mob/living/user) + if(demand <= 0) + return "Not buying any more this shift." + if(buyer?.is_busy()) + return "Already looking one over." + var/list/hauled = xenoarch_hauled_finds(user) + if(!length(hauled)) + return "Nothing at the counter." + var/list/finds = sellable_finds(user) + if(!length(finds)) + for(var/obj/machinery/artifact/find as anything in hauled) + if(!find.is_dug()) + return "No field tag on it." + return "Not buying that." + if(!at_counter(finds[1], buyer?.trader())) + return "Bring it closer." + if(!get_shop_buyback_account(user)) + return "No bank account on your ID." + return null + +// The sale finishes once the trader has looked the find over, so this starts it and reports +// nothing sold yet: the window's own sale sound and line would come too early. The buyer makes +// their own noise when the money changes hands. +/datum/shop_buyback/xenoarch_find/try_sell(mob/living/user, mob/living/basic/outpost_trader/vendor, quiet = FALSE) + if(!buyer || QDELETED(vendor)) + return FALSE + INVOKE_ASYNC(src, PROC_REF(sell_hauled_find), user, vendor) + return FALSE + +/datum/shop_buyback/xenoarch_find/try_sell_bulk(mob/living/user, mob/living/basic/outpost_trader/vendor) + try_sell(user, vendor) + return 0 + +/// Whether the sale of `find` can still go ahead: same seller, same counter, still hauled, still wanted. +/datum/shop_buyback/xenoarch_find/proc/sale_still_on(mob/living/seller, mob/living/basic/outpost_trader/vendor, obj/machinery/artifact/find) + if(QDELETED(src) || QDELETED(find) || QDELETED(vendor) || QDELETED(seller) || !buyer) + return FALSE + if(demand <= 0 || !(find in sellable_finds(seller)) || !at_counter(find, vendor)) + return FALSE + if(!vendor.check_menu(seller) || vendor.outpost?.is_user_barred(seller)) + return FALSE + if(vendor.outpost && !vendor.outpost.contains_site_turf(get_turf(vendor))) + return FALSE + return TRUE + +/** + * The seller waits at the counter while the trader looks over the first find they are hauling. + * Walking off, letting go of it or the trader's demand running out calls it off. Sleeps. + */ +/datum/shop_buyback/xenoarch_find/proc/sell_hauled_find(mob/living/seller, mob/living/basic/outpost_trader/vendor) + var/denial = get_denial_reason(seller) + if(denial) + to_chat(seller, span_warning(denial)) + vendor?.play_denial() + return FALSE + var/obj/machinery/artifact/find = sellable_finds(seller)[1] + if(!sale_still_on(seller, vendor, find)) + vendor?.play_denial() + return FALSE + var/atom/movable/holder = xenoarch_find_holder(find) + buyer.inspecting = WEAKREF(find) + COOLDOWN_START(buyer, inspect_cooldown, XENOARCH_INSPECT_COOLDOWN) + buyer.begin_inspection(vendor, find, holder) + var/looked = do_after(seller, XENOARCH_INSPECT_TIME, holder, timed_action_flags = IGNORE_HELD_ITEM, extra_checks = CALLBACK(src, PROC_REF(sale_still_on), seller, vendor, find), hidden = TRUE) + if(buyer) + buyer.inspecting = null + if(!looked || !sale_still_on(seller, vendor, find)) + if(!QDELETED(find) && buyer) + buyer.speak(vendor, buyer.line(XENOARCH_LINE_WALKED)) + return FALSE + if(settle(find, seller, get_shop_buyback_account(seller), vendor) > 0) + return TRUE + vendor.play_denial() + return FALSE + +/** + * Pays for `find` and takes it: credits into `account`, any voucher and the receipt into the + * seller's hands, the find gone. All checks and the payment happen without a sleep between them. + * Returns the credits paid, or 0 if nothing was sold. + */ +/datum/shop_buyback/xenoarch_find/proc/settle(obj/machinery/artifact/find, mob/living/seller, datum/bank_account/account, mob/living/basic/outpost_trader/vendor) + if(QDELETED(find) || !find.is_dug() || demand <= 0 || !account) + return 0 + var/price = artifact_sale_value(find) + if(price <= 0) + return 0 + var/vouchers = buyer ? buyer.vouchers_for(find) : 0 + var/list/sale = buyer?.sale_record(find, seller, price, vouchers, account) + var/reaction = buyer?.closing_line(find) + var/atom/drop_spot = seller?.drop_location() || vendor?.drop_location() || get_turf(find) + var/serial = find.serial + var/trader_name = buyer?.shop?.trader_name || "The buyer" + + demand-- + SEND_SIGNAL(find, COMSIG_ARTIFACT_SOLD, price, vouchers, seller) + metric_artifact_sold(find, seller, price, vouchers, buyer?.shop) + log_game("XENOARCH: [key_name(seller)] sold [serial] ([find.main_effect?.log_name]) to [trader_name] for [price] cr[vouchers ? " and [vouchers] voucher\s" : ""] at [AREACOORD(drop_spot)].") + if(isturf(find.loc)) + new /obj/effect/temp_visual/xenoarch_sold_find(find.loc, find) + qdel(find) + + account.adjust_money(price, "Trader Outpost: [trader_name] bought [serial]") + if(vouchers > 0) + var/obj/item/stack/trade_voucher/chits = new(drop_spot, vouchers) + seller?.put_in_hands(chits) + if(sale) + var/obj/item/paper/xenoarch_receipt/receipt = new(drop_spot) + receipt.fill_in(buyer, sale) + seller?.put_in_hands(receipt) + if(!QDELETED(vendor)) + playsound(vendor, 'sound/effects/cashregister.ogg', 40, TRUE) + if(sale) + playsound(vendor, 'sound/items/handling/standard_stamp.ogg', 35, TRUE) + buyer?.speak(vendor, reaction) + if(seller) + to_chat(seller, span_notice("[trader_name] pays [xenoarch_credits_text(price)] for [serial][vouchers ? " and slides over a trade voucher" : ""].")) + return price + +/// The sold find, fading off the counter as it is carried into the back. +/obj/effect/temp_visual/xenoarch_sold_find + duration = 0.8 SECONDS + randomdir = FALSE + +/obj/effect/temp_visual/xenoarch_sold_find/Initialize(mapload, atom/movable/find) + . = ..() + if(find) + icon = find.icon + icon_state = find.icon_state + pixel_x = find.pixel_x + pixel_y = find.pixel_y + animate(src, alpha = 0, pixel_z = 6, time = duration, easing = SINE_EASING | EASE_IN) + +// ========================================================================= +// CURIOS +// ========================================================================= + +/** + * # Dug curio + * + * Marks a small find as having come out of a dig site, and what a buyer pays for it. Buyers take + * only marked items, so strange objects from maintenance or the experimentor (never marked) can't + * pass as finds. Copies made of a curio don't carry the mark. + */ +/datum/component/xenoarch_curio + /// Credits a buyer pays for it + var/value = 0 + +/datum/component/xenoarch_curio/Initialize(value) + if(!isitem(parent)) + return COMPONENT_INCOMPATIBLE + src.value = max(round(value), 0) + +/// Marks `find` as a dug curio worth `value` credits to a buyer. Call when a small find comes out of the rock. +/proc/xenoarch_mark_curio(obj/item/find, value) + if(!istype(find) || value <= 0) + return FALSE + find.AddComponent(/datum/component/xenoarch_curio, value) + return TRUE + +/// What a buyer pays for `thing` as a curio: 0 if it never came out of a dig site. +/proc/xenoarch_curio_value(obj/item/thing) + var/datum/component/xenoarch_curio/mark = thing?.GetComponent(/datum/component/xenoarch_curio) + return mark ? mark.value : 0 + +/** + * # Curio ledger row + * + * An ordinary inventory buyback, except that every curio carries its own price. item_path stays + * null so contract pricing and Pike's remote ledger leave it alone. + */ +/datum/shop_buyback/xenoarch_curio + name = "curios" + desc = "Small finds out of the old dig sites." + category = "Dig Finds" + item_path = null + demand_min = XENOARCH_CURIO_DEMAND + demand_max = XENOARCH_CURIO_DEMAND + /// The buyer whose ledger this is + var/datum/xenoarch_buyer/buyer + /// Credits the last single sale paid (bulk sales add these up) + var/last_sale_value = 0 + +/datum/shop_buyback/xenoarch_curio/Destroy() + buyer = null + return ..() + +/// Takes on `new_buyer`'s wording for the ledger. +/datum/shop_buyback/xenoarch_curio/proc/attach(datum/xenoarch_buyer/new_buyer) + buyer = new_buyer + name = new_buyer.curio_name + desc = new_buyer.curio_desc + cached_icon = null + +/datum/shop_buyback/xenoarch_curio/get_ui_icon() + if(!cached_icon && buyer) + cached_icon = icon2base64(icon(buyer.curio_icon, buyer.curio_icon_state, SOUTH, frame = 1)) + return cached_icon + +/datum/shop_buyback/xenoarch_curio/get_payment_text() + return "by the piece" + +/datum/shop_buyback/xenoarch_curio/matches(obj/item/offered) + if(!isitem(offered) || is_trader_good(offered)) + return FALSE + if((offered.item_flags & ABSTRACT) || (offered.flags_1 & HOLOGRAM_1)) + return FALSE + if(istype(offered, /obj/item/relic) && !buyer?.takes_strange_objects) + return FALSE + return xenoarch_curio_value(offered) > 0 + +/datum/shop_buyback/xenoarch_curio/find_refused_variant(mob/living/user) + return null + +/datum/shop_buyback/xenoarch_curio/get_denial_reason(mob/living/user) + if(demand <= 0) + return "Not buying any more this shift." + if(count_carried_units(user) < 1) + return "Carrying none of the goods: [get_wanted_text()]." + if(!get_shop_buyback_account(user)) + return "No bank account on your ID." + return null + +/datum/shop_buyback/xenoarch_curio/try_sell(mob/living/user, mob/living/basic/outpost_trader/vendor, quiet = FALSE) + last_sale_value = 0 + if(demand <= 0) + return FALSE + var/datum/bank_account/account = get_shop_buyback_account(user) + if(!account) + return FALSE + var/list/found = find_offered_items(user) + if(!length(found)) + return FALSE + var/obj/item/curio = found[1] + var/value = xenoarch_curio_value(curio) + if(value <= 0) + return FALSE + var/curio_name = curio.name + var/curio_type = curio.type + qdel(curio) + demand-- + account.adjust_money(value, "Trader Outpost: sold [curio_name]") + last_sale_value = value + if(!quiet) + to_chat(user, span_notice("Sold: [curio_name] ([xenoarch_credits_text(value)]).")) + // The ordinary ledger metric, priced by the piece + if(SSmetrics.accepting) + var/list/details = list("name" = name, "sales" = 1, "curio" = curio_name) + if(vendor?.shop) + details["shop"] = "[vendor.shop.type]" + record_metric(METRIC_TRADE, "shop_buyback", subject = curio_type, credits = value, quantity = 1, details = details, actor = user) + return TRUE + +/datum/shop_buyback/xenoarch_curio/try_sell_bulk(mob/living/user, mob/living/basic/outpost_trader/vendor) + var/sold = 0 + var/total = 0 + var/safety = 50 + while(demand > 0 && safety-- > 0) + if(!try_sell(user, vendor, quiet = TRUE)) + break + sold++ + total += last_sale_value + if(sold > 0) + to_chat(user, span_notice("Sold [sold] [sold > 1 ? "curios" : "curio"] ([xenoarch_credits_text(total)]).")) + return sold + +// ========================================================================= +// THE RECEIPT +// ========================================================================= + +/// What a buyer hands over with the money: a dealer's paper, in their own hand. +/obj/item/paper/xenoarch_receipt + name = "receipt" + desc = "A dealer's receipt for something old and heavy." + /// Paper stamp icon state to press on once the stamp sheet is ready + var/pending_stamp + +/obj/item/paper/xenoarch_receipt/proc/fill_in(datum/xenoarch_buyer/buyer, list/sale) + name = "receipt ([sale["serial"]])" + add_raw_text(buyer.receipt_text(sale), buyer.receipt_font, buyer.receipt_ink) + update_appearance() + if(buyer.receipt_stamp) + pending_stamp = buyer.receipt_stamp + // The stamp's class comes from the paper spritesheet, which may have to be made ready first + INVOKE_ASYNC(src, PROC_REF(stamp_it)) + +/obj/item/paper/xenoarch_receipt/proc/stamp_it() + var/datum/asset/spritesheet_batched/sheet = get_asset_datum(/datum/asset/spritesheet/simple/paper) + if(QDELETED(src) || !sheet || !pending_stamp) + return + add_stamp(sheet.icon_class_name(pending_stamp), rand(180, 260), rand(40, 120), rand(-15, 15), pending_stamp) + pending_stamp = null + update_appearance() + +#undef XENOARCH_FIND_DEMAND +#undef XENOARCH_CURIO_DEMAND +#undef XENOARCH_COUNTER_REACH +#undef XENOARCH_INSPECT_TIME +#undef XENOARCH_INSPECT_COOLDOWN +#undef XENOARCH_NOTICE_RANGE +#undef XENOARCH_NOTICE_COOLDOWN +#undef XENOARCH_NOTICE_MEMORY +#undef XENOARCH_LINE_NOTICE +#undef XENOARCH_LINE_INSPECT +#undef XENOARCH_LINE_INSPECT_CRATED +#undef XENOARCH_LINE_CRACKED +#undef XENOARCH_LINE_TAPPED +#undef XENOARCH_LINE_PERFECT +#undef XENOARCH_LINE_CLOSE +#undef XENOARCH_LINE_WRONG +#undef XENOARCH_LINE_BLANK +#undef XENOARCH_LINE_LIVE +#undef XENOARCH_LINE_WALKED diff --git a/voidcrew/modules/xenoarch/trade/checkpoint.dm b/voidcrew/modules/xenoarch/trade/checkpoint.dm new file mode 100644 index 00000000000..43ec2af87bc --- /dev/null +++ b/voidcrew/modules/xenoarch/trade/checkpoint.dm @@ -0,0 +1,78 @@ +/** + * # Outpost checkpoints turning back loose finds + * + * A large find comes into a trader outpost crated, or not at all. The scan chamber + * (voidcrew/modules/trade/outpost_checkpoint.dm) refuses an artifact standing loose on its floor + * the way it refuses a gun on the floor: the inner door stays shut, the guard (or the wall + * scanner) says so, and the outer door waits until the find has been taken back out. A find in + * any shut crate, or carried in an exosuit, passes. Leaving through an exterior hatch is never + * refused for a find. + * + * Inside, a find does nothing anyway (the outpost holds it still); this keeps one from being + * dragged through the crowd at the door and gives the guards something to say about it. + */ + +/// The refusal category for a loose find: a refused[] value and a line key for guards and scanners +#define XENOARCH_CHECKPOINT_LINE_LOOSE "xenoarch_loose_find" + +/datum/outpost_checkpoint/inspect_chamber() + var/list/refused = ..() + if(exit_request) + return refused + for(var/turf/tile as anything in chamber_turfs) + for(var/obj/machinery/artifact/find in tile) + if(!refused[find]) + refused[find] = XENOARCH_CHECKPOINT_LINE_LOOSE + return refused + +/// Whether everything the chamber refuses right now is a loose find. +/datum/outpost_checkpoint/proc/refusing_only_loose_finds() + var/list/refused = inspect_chamber() + if(!length(refused)) + return FALSE + for(var/atom/movable/thing as anything in refused) + if(refused[thing] != XENOARCH_CHECKPOINT_LINE_LOOSE) + return FALSE + return TRUE + +// A refusal is announced as "armed"; when the only thing refused is a loose find, say that instead. +/datum/outpost_checkpoint/announce(category, urgent = FALSE) + if(category == CHECKPOINT_LINE_ARMED && state == CHECKPOINT_REJECTING && refusing_only_loose_finds()) + category = XENOARCH_CHECKPOINT_LINE_LOOSE + return ..(category, urgent) + +/obj/machinery/outpost_checkpoint_sensor/machine_line(category) + if(category == XENOARCH_CHECKPOINT_LINE_LOOSE) + return "Uncontained specimen." + return ..() + +/datum/outpost_shop/vendor/checkpoint + /// What this guard says to someone pulling a find in loose + var/list/xenoarch_loose_lines = list( + "Crate it first.", + ) + +/datum/outpost_shop/vendor/checkpoint/get_line(category) + if(category == XENOARCH_CHECKPOINT_LINE_LOOSE) + return length(xenoarch_loose_lines) ? pick(xenoarch_loose_lines) : null + return ..() + +/datum/outpost_shop/vendor/checkpoint/halcyon + xenoarch_loose_lines = list( + "Crate it first, please. That doesn't come in loose.", + "Whatever that is, it goes in a crate before it comes past me.", + ) + +/datum/outpost_shop/vendor/checkpoint/quartermain + xenoarch_loose_lines = list( + "Crate it first.", + "Not loose. Box it and come back.", + ) + +/datum/outpost_shop/vendor/checkpoint/undertow + xenoarch_loose_lines = list( + "Crate it.", + "Loose rocks stay outside.", + ) + +#undef XENOARCH_CHECKPOINT_LINE_LOOSE diff --git a/voidcrew/modules/xenoarch/trade/metrics.dm b/voidcrew/modules/xenoarch/trade/metrics.dm new file mode 100644 index 00000000000..a6aa1f7aa2c --- /dev/null +++ b/voidcrew/modules/xenoarch/trade/metrics.dm @@ -0,0 +1,24 @@ +// Round metrics for selling finds. Digging, analysing and harvesting record their own events +// (XENOARCH_METRIC_DUG/LOST/ANALYSED/HARVESTED) where they happen; curios sold over the counter use +// the ordinary "shop_buyback" event. + +/// A large find sold at an outpost. Call before the find is deleted. `zone` is the band it was dug in. +/proc/metric_artifact_sold(obj/machinery/artifact/find, mob/living/seller, credits, vouchers, datum/outpost_shop/shop) + if(!SSmetrics.accepting || QDELETED(find)) + return + var/list/details = list( + "serial" = find.serial, + "accuracy" = round(find.label_accuracy(), 0.01), + "labelled" = !!find.label, + "tier" = find.main_effect ? artifact_price_tier(find) : null, + "effect_tier" = find.main_effect?.tier, + "spent" = !!find.main_effect?.is_spent(), + "band" = xenoarch_band_name(find.origin_band), + "harvests" = find.harvests_taken(), + "damaged" = !!find.damaged, + "crated" = !isturf(find.loc), + ) + if(shop) + details["buyer"] = shop.trader_name + details["shop"] = "[shop.type]" + record_metric(METRIC_TRADE, XENOARCH_METRIC_SOLD, zone = xenoarch_band_name(find.origin_band), subject = find.main_effect?.type || find.type, credits = credits, vouchers = vouchers, quantity = 1, details = details, actor = seller) diff --git a/voidcrew/modules/xenoarch/trade/specimen_crate.dm b/voidcrew/modules/xenoarch/trade/specimen_crate.dm new file mode 100644 index 00000000000..c550d5b6234 --- /dev/null +++ b/voidcrew/modules/xenoarch/trade/specimen_crate.dm @@ -0,0 +1,149 @@ +/** + * # Specimen crate + * + * A heavy crate built to hold one large find. Effects stop while it is shut inside (an + * artifact off a turf never stirs), so a crew can haul a dangerous find without it going off. + * Any shut crate gets a find past an outpost checkpoint and up to a buyer; this one takes only + * the find and small things, never people or other machines, and shows the find's field tag on + * the lid so a hold full of crates can be told apart. + * + * It is also the only crate a large find can be loaded into. Open crates are dense here and the + * usual drag-to-stuff only takes items and people, so a find gets in one of two ways: drag it onto + * the open crate to heave it in (the lid shuts on it), or push it onto the open crate and shut the + * lid like any other crate. + * + * Art: a recolour of tg's plain crate (icons/obj/storage/crates.dmi "crate"/"crateopen"), lead + * grey with padded straps; "manifest" and "welded" are tg's own, copied so crate overlays line up. + */ +/obj/structure/closet/crate/specimen + name = "specimen crate" + desc = "A padded, lead-lined crate big enough for one large find." + icon = 'voidcrew/modules/xenoarch/icons/specimen_crate.dmi' + icon_state = "specimen" + base_icon_state = "specimen" + allow_dense = TRUE + allow_objects = TRUE + storage_capacity = 10 + // Its own sprite sheet holds no other crate's states + paint_jobs = null + +/obj/structure/closet/crate/specimen/insertion_allowed(atom/movable/thing) + // The only dense thing it takes is one artifact. No people, no other machines. + if(istype(thing, /obj/machinery/artifact)) + var/obj/machinery/artifact/find = thing + if(find.anchored || (locate(/obj/machinery/artifact) in contents)) + return FALSE + return TRUE + if(ismob(thing) || (isobj(thing) && thing.density)) + return FALSE + return ..() + +/// How long it takes to heave a large find into the crate. +#define SPECIMEN_CRATE_HEAVE_TIME (3 SECONDS) + +// A find dragged onto the open crate is heaved in. +/obj/structure/closet/crate/specimen/mouse_drop_receive(atom/movable/dropped, mob/living/user, params) + if(!istype(dropped, /obj/machinery/artifact)) + return ..() + heave_in(dropped, user) + +// The open crate lets a find be pushed onto it, so shutting the lid takes it in. +/obj/structure/closet/crate/specimen/CanAllowThrough(atom/movable/mover, border_dir) + . = ..() + if(!. && opened && istype(mover, /obj/machinery/artifact) && has_room_for(mover)) + return TRUE + +/// No other find is already in it or sitting in it, and `find` is loose. +/obj/structure/closet/crate/specimen/proc/has_room_for(obj/machinery/artifact/find) + if(find.anchored || (locate(/obj/machinery/artifact) in contents)) + return FALSE + for(var/obj/machinery/artifact/other in loc) + if(other != find) + return FALSE + return TRUE + +/** + * Whether `find` can be heaved in by `user` right now. Says why not unless `quiet` (the check a + * heave in progress keeps making). + */ +/obj/structure/closet/crate/specimen/proc/can_heave(obj/machinery/artifact/find, mob/living/user, quiet = FALSE) + var/reason + if(QDELETED(src) || QDELETED(find) || !isturf(loc) || !isturf(find.loc)) + reason = "can't get at it!" + else if(!opened) + reason = "the lid's shut!" + else if(find.anchored) + reason = "it's bolted down!" + else if(find.z != z || get_dist(find, src) > 1) + reason = "too far away!" + else if(!has_room_for(find)) + reason = "no room!" + else if(!can_close()) + reason = "something's in the way!" + if(reason && user && !quiet) + balloon_alert(user, reason) + return !reason + +/// Heaves `find` into the open crate and drops the lid on it. Sleeps. Returns TRUE if it went in. +/obj/structure/closet/crate/specimen/proc/heave_in(obj/machinery/artifact/find, mob/living/user) + if(!isliving(user) || DOING_INTERACTION(user, DOAFTER_SOURCE_XENOARCH)) + return FALSE + if(!can_heave(find, user)) + return FALSE + user.visible_message( + span_notice("[user] gets a grip on [find] and starts heaving it into [src]."), + span_notice("You get a grip on [find] and start heaving it into [src]."), + ) + // Getting your arms round it is a touch, like hauling it. + find.touched_by(user, accidental = TRUE) + if(!do_after(user, SPECIMEN_CRATE_HEAVE_TIME, find, extra_checks = CALLBACK(src, PROC_REF(can_heave), find, user, TRUE), interaction_key = DOAFTER_SOURCE_XENOARCH)) + return FALSE + return load_find(find, user) + +/// Sets `find` down in the open crate and shuts the lid on it. Returns TRUE if it ended up inside. +/obj/structure/closet/crate/specimen/proc/load_find(obj/machinery/artifact/find, mob/living/user) + if(!can_heave(find, user)) + return FALSE + if(user?.pulling == find) + user.stop_pulling() + find.forceMove(loc) + // The lid takes whatever sits in the crate, the find included, through the usual closing path. + if(!close(user) || find.loc != src) + return FALSE + playsound(src, 'sound/effects/bang.ogg', 25, TRUE) + if(user) + user.visible_message( + span_notice("[user] heaves [find] into [src] and drops the lid on it."), + span_notice("You heave [find] into [src] and drop the lid on it."), + ) + return TRUE + +#undef SPECIMEN_CRATE_HEAVE_TIME + +/obj/structure/closet/crate/specimen/examine(mob/user) + . = ..() + if(opened) + return + var/obj/machinery/artifact/find = locate() in contents + if(!find) + return + . += "Something heavy is strapped in." + if(find.is_dug()) + . += "A field tag clipped to the lid reads [find.serial]." + +// Printed in the field-gear node ("Xenoarchaeology", study/techweb.dm). It costs more iron than +// it breaks down into. +/datum/design/specimen_crate + name = "Specimen Crate" + desc = "A padded, lead-lined crate big enough for one large find." + id = "xenoarch_specimen_crate" + build_type = PROTOLATHE | AWAY_LATHE + materials = list( + /datum/material/iron = SHEET_MATERIAL_AMOUNT * 5, + /datum/material/plastic = SHEET_MATERIAL_AMOUNT * 2, + ) + build_path = /obj/structure/closet/crate/specimen + category = list( + RND_CATEGORY_EQUIPMENT + RND_SUBCATEGORY_EQUIPMENT_SCIENCE, + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE | DEPARTMENT_BITFLAG_CARGO diff --git a/voidcrew/modules/xenoarch/use/battery.dm b/voidcrew/modules/xenoarch/use/battery.dm new file mode 100644 index 00000000000..c7fe87698c0 --- /dev/null +++ b/voidcrew/modules/xenoarch/use/battery.dm @@ -0,0 +1,203 @@ +/** + * # Exotic battery + * + * Holds what a harvester draws off an alien artifact: a copy of one effect and up to + * ARTIFACT_BATTERY_CAPACITY charge. It does nothing on its own; a utilizer runs it. + * + * Rewritten from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/obj/particle_battery.dm. + * Art: Nova's machinery.dmi particles_battery states (CC BY-SA 3.0, pixel-checked clean against + * Goon), with a core mask drawn for Voidcrew so the battery glows in its energy kind's colour. + * + * Only a harvester draw adds charge, and a new battery is always empty. Batteries are items, so + * ship saves and checkpoints delete them on load (clear_stock() removes every item, wherever it + * sits) and a saved harvester comes back with an empty slot: a charged battery can't be copied. + */ +/obj/item/anomaly_battery + name = "exotic battery" + desc = "A heavy little cell with a window onto its core." + icon = 'voidcrew/modules/xenoarch/icons/use.dmi' + icon_state = "battery0" + base_icon_state = "battery" + inhand_icon_state = "cell" + lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi' + righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi' + w_class = WEIGHT_CLASS_SMALL + custom_materials = list( + /datum/material/iron = SHEET_MATERIAL_AMOUNT, + /datum/material/plasma = SHEET_MATERIAL_AMOUNT, + /datum/material/gold = HALF_SHEET_MATERIAL_AMOUNT, + ) + /// Charge held, 0 to capacity + var/stored_charge = 0 + /// Most charge it can hold + var/capacity = ARTIFACT_BATTERY_CAPACITY + /// A copy of the artifact effect it holds, or null if it was never filled or was purged + var/datum/artifact_effect/held_effect + /// The artifact effect it was drawn from, so a harvester can top it up from the same find + var/datum/weakref/source_ref + /// Catalogue number of the find it was drawn from, stamped on its side + var/source_serial + +/obj/item/anomaly_battery/Destroy(force) + QDEL_NULL(held_effect) + source_ref = null + return ..() + +/// 0 to 1. +/obj/item/anomaly_battery/proc/charge_fraction() + if(capacity <= 0) + return 0 + return clamp(stored_charge / capacity, 0, 1) + +/obj/item/anomaly_battery/proc/is_full() + return stored_charge >= capacity + +/// The gauge on its side: 0, 25, 50, 75 or 100. Any charge at all shows a quarter. +/obj/item/anomaly_battery/proc/charge_level() + if(stored_charge <= 0) + return 0 + return clamp(round(charge_fraction() * 100, 25), 25, 100) + +/// The energy kind its core glows with, or null when it holds nothing. +/obj/item/anomaly_battery/proc/held_kind() + if(!held_effect) + return null + return artifact_energy_kind(held_effect.energy_kind) + +/// The kind to show: null while it holds no charge, so an empty core stays dark. +/obj/item/anomaly_battery/proc/lit_kind() + return stored_charge > 0 ? held_kind() : null + +/// Whether it still holds the effect drawn from `source`. +/obj/item/anomaly_battery/proc/holds_from(datum/artifact_effect/source) + return held_effect && source && source_ref?.resolve() == source + +/// Whether a harvester may pour `source`'s energy in: it is empty, or it already holds that same effect. +/obj/item/anomaly_battery/proc/can_take(datum/artifact_effect/source) + if(!source || is_full()) + return FALSE + return stored_charge <= 0 || holds_from(source) + +/// Readies it to take `source`'s energy, copying the effect unless it already holds it. +/obj/item/anomaly_battery/proc/load_from(datum/artifact_effect/source, serial) + if(holds_from(source)) + return + discard_effect() + held_effect = source.make_harvest_copy(src) + source_ref = WEAKREF(source) + source_serial = serial + stored_charge = 0 + update_appearance() + +/// Adds charge, up to capacity. Returns how much went in. +/obj/item/anomaly_battery/proc/add_charge(amount) + if(!held_effect || amount <= 0) + return 0 + var/added = min(amount, capacity - stored_charge) + if(added <= 0) + return 0 + var/old_level = charge_level() + stored_charge += added + if(charge_level() != old_level) + update_appearance() + return added + +/// Spends charge. Returns how much came out. +/obj/item/anomaly_battery/proc/use_charge(amount) + if(amount <= 0) + return 0 + var/used = min(amount, stored_charge) + var/old_level = charge_level() + stored_charge -= used + if(charge_level() != old_level) + update_appearance() + return used + +/// Empties it and lets go of the effect it held. +/obj/item/anomaly_battery/proc/purge() + discard_effect() + source_serial = null + stored_charge = 0 + update_appearance() + +/obj/item/anomaly_battery/proc/discard_effect() + if(held_effect?.activated) + held_effect.deactivate() + QDEL_NULL(held_effect) + source_ref = null + +/obj/item/anomaly_battery/update_icon_state() + icon_state = "[base_icon_state][charge_level()]" + return ..() + +/obj/item/anomaly_battery/update_overlays() + . = ..() + . += anomaly_core_overlays(src, "battery_core", lit_kind(), charge_fraction()) + +/obj/item/anomaly_battery/examine(mob/user) + . = ..() + if(source_serial) + . += "A strip on its side is stamped [source_serial]." + . += anomaly_core_description(lit_kind(), charge_fraction()) + +// ===== Shared with the utilizer and harvester ===== + +/** + * The glowing core of a battery as overlays: the tinted mask and its emissive, brighter with + * more charge. `state` is the mask's icon state on `owner`'s icon. Empty while the core is dark. + */ +/proc/anomaly_core_overlays(atom/owner, state, datum/artifact_energy_kind/kind, fraction) + . = list() + if(!kind || fraction <= 0) + return + var/core_alpha = round(110 + 145 * clamp(fraction, 0, 1)) + var/mutable_appearance/core = mutable_appearance(owner.icon, state, alpha = core_alpha) + core.color = kind.color + . += core + . += emissive_appearance(owner.icon, state, owner, alpha = round(core_alpha * 0.7)) + +/// "Its core glows a steady amber." or "Its core is dark." +/proc/anomaly_core_description(datum/artifact_energy_kind/kind, fraction) + if(!kind || fraction <= 0) + return "Its core is dark." + var/strength = "bright" + if(fraction < 0.34) + strength = "dim" + else if(fraction < 0.67) + strength = "steady" + return "Its core glows a [strength] [anomaly_glow_word(kind.key)]." + +/// A plain colour word for an energy kind's glow. +/proc/anomaly_glow_word(kind_key) + switch(kind_key) + if(ARTIFACT_ENERGY_CONCENTRATED) + return "amber" + if(ARTIFACT_ENERGY_PSIONIC) + return "violet" + if(ARTIFACT_ENERGY_ELECTROMAGNETIC) + return "pale blue" + if(ARTIFACT_ENERGY_PARTICLE) + return "white" + if(ARTIFACT_ENERGY_ORGANIC) + return "rose red" + if(ARTIFACT_ENERGY_BLUESPACE) + return "deep blue" + if(ARTIFACT_ENERGY_SYNTHESIS) + return "green" + return "strange light" + +/datum/design/anomaly_battery + name = "Exotic Battery" + desc = "A cell built to hold what a harvester draws off an alien find." + id = "xenoarch_battery" + build_type = PROTOLATHE | AWAY_LATHE + materials = list( + /datum/material/iron = SHEET_MATERIAL_AMOUNT, + /datum/material/plasma = SHEET_MATERIAL_AMOUNT, + /datum/material/gold = HALF_SHEET_MATERIAL_AMOUNT, + ) + build_path = /obj/item/anomaly_battery + category = list( + RND_CATEGORY_EQUIPMENT + RND_SUBCATEGORY_EQUIPMENT_SCIENCE + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE diff --git a/voidcrew/modules/xenoarch/use/harvester.dm b/voidcrew/modules/xenoarch/use/harvester.dm new file mode 100644 index 00000000000..8de9efea73c --- /dev/null +++ b/voidcrew/modules/xenoarch/use/harvester.dm @@ -0,0 +1,484 @@ +/** + * # Exotic particle harvester + * + * Draws one awake effect off an alien artifact standing next to it and packs it into an exotic + * battery, which a utilizer can then run. Each artifact gives ARTIFACT_MAX_HARVESTS harvests in + * all, and every harvest taken lowers its sale price (core pricing reads harvests_taken()). + * + * Rewritten from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/machines/artifact_harvester.dm, + * with its HTML window replaced by tgui (ArtifactHarvester.tsx). Voidcrew changes: + * - A harvest is spent the moment the first charge reaches the battery, so stopping early or + * losing power partway never refunds it, and a draw that never started costs nothing. + * Nova copied the effect for free, forever. + * - The find's lock (try_lock()/release_lock()) is held for the whole draw and released on + * finish, on halt and in Destroy(). Nova anchored the find and never let go of it on halt. + * - It reads any find on the eight tiles around it, so it works beside a scan pad or without one. + * - Effects marked unharvestable won't come off; two effects awake at once can't be separated. + * - A battery can be topped up only from the effect it already holds; an empty one takes anything. + * - While it draws, a stream of motes in the energy's colour runs from the find to the dome, the + * find throbs and crackles with its own sound, and the console hums. + * + * Art: Nova's machinery.dmi harvester states (CC BY-SA 3.0, pixel-checked clean against Goon), + * a dome mask drawn for Voidcrew, and tg's drain_life beam made greyscale so it can be tinted. + * + * Ship saves: the harvester is rebuilt from its board with an empty slot (its battery is an item + * and clear_stock() deletes it) and no draw in progress, so a save never copies a charge. + */ + +/// What the readout says about the find beside it. +#define HARVEST_SOURCE_READY "ready" +#define HARVEST_SOURCE_QUIET "quiet" +#define HARVEST_SOURCE_TANGLED "tangled" +#define HARVEST_SOURCE_UNFIT "unfit" +#define HARVEST_SOURCE_SPENT "spent" +#define HARVEST_SOURCE_BUSY "busy" +#define HARVEST_SOURCE_MISMATCH "mismatch" +#define HARVEST_SOURCE_DRAWING "drawing" + +/obj/machinery/artifact_harvester + name = "exotic particle harvester" + desc = "A console wired to a collector dome. It pulls the energy off an alien find and packs it into a battery." + icon = 'voidcrew/modules/xenoarch/icons/use.dmi' + icon_state = "harvester" + base_icon_state = "harvester" + density = TRUE + anchored = TRUE + circuit = /obj/item/circuitboard/machine/artifact_harvester + idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION + active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION * 2 + processing_flags = START_PROCESSING_MANUALLY + // Its window opens unpowered too (dark scope, no draw), so a battery is never stuck inside. + interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON | INTERACT_MACHINE_OFFLINE + /// The battery in its slot + var/obj/item/anomaly_battery/battery + /// Drawing right now + var/drawing = FALSE + /// The find it draws from, while it draws + var/datum/weakref/source_ref + /// The effect it draws, while it draws + var/datum/weakref/drawn_ref + /// Whoever started the draw, for the harvest record + var/datum/weakref/operator_ref + /// This draw has already taken one of the find's harvests + var/draw_counted = FALSE + /// Charge per second, from its capacitors + var/draw_rate = ARTIFACT_HARVEST_DRAW_RATE + /// The stream of motes between the find and the dome + var/datum/beam/draw_beam + /// The hum while it draws + var/datum/looping_sound/artifact_harvester/soundloop + /// world.time of the next crackle off the find + var/next_crackle = 0 + +/obj/machinery/artifact_harvester/Initialize(mapload) + . = ..() + soundloop = new(src) + +/obj/machinery/artifact_harvester/Destroy() + stop_draw() + QDEL_NULL(soundloop) + QDEL_NULL(battery) + return ..() + +/obj/machinery/artifact_harvester/RefreshParts() + . = ..() + var/capacitor_tier = max(total_part_rating(/datum/stock_part/capacitor) / 2, 1) + // Tier-1 capacitors fill a battery in 80 seconds, tier-4 in 40. + draw_rate = ARTIFACT_HARVEST_DRAW_RATE * (1 + (capacitor_tier - 1) / 3) + +/obj/machinery/artifact_harvester/examine(mob/user) + . = ..() + if(battery) + . += "An exotic battery is seated under the dome." + if(drawing) + . += span_notice("Its dome hums, and a thin stream of light runs into it.") + +// ===== Battery slot ===== + +/obj/machinery/artifact_harvester/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(!istype(tool, /obj/item/anomaly_battery)) + return NONE + if(battery) + balloon_alert(user, "slot's taken!") + return ITEM_INTERACT_BLOCKING + if(!user.transferItemToLoc(tool, src)) + return ITEM_INTERACT_BLOCKING + battery = tool + user.visible_message( + span_notice("[user] seats [tool] under the dome of [src]."), + span_notice("You seat [tool] under the dome of [src]."), + ) + playsound(src, 'sound/machines/terminal/terminal_insert_disc.ogg', 40, TRUE) + update_appearance() + SStgui.update_uis(src) + return ITEM_INTERACT_SUCCESS + +/obj/machinery/artifact_harvester/Exited(atom/movable/gone, direction) + . = ..() + if(gone != battery) + return + battery = null + stop_draw() + if(!QDELETED(src)) + update_appearance() + +/// Hands the battery back, or drops it in front of the harvester. +/obj/machinery/artifact_harvester/proc/eject_battery(mob/living/user) + if(!battery) + return FALSE + if(drawing) + balloon_alert(user, "it's drawing!") + return FALSE + var/obj/item/anomaly_battery/ejected = battery + ejected.forceMove(drop_location()) + if(user && Adjacent(user)) + user.put_in_hands(ejected) + playsound(src, 'sound/machines/terminal/terminal_eject.ogg', 40, TRUE) + return TRUE + +/// Vents the battery: its charge and the effect it held are gone, and it can take anything again. +/obj/machinery/artifact_harvester/proc/purge_battery(mob/living/user) + if(!battery || drawing || !battery.held_effect) + return FALSE + var/datum/artifact_energy_kind/kind = battery.lit_kind() + battery.purge() + if(kind) + visible_message(span_notice("[src]'s dome flares [anomaly_glow_word(kind.key)] and goes dark with a hiss.")) + flick_dome(kind.color) + playsound(src, 'sound/machines/steam_hiss.ogg', 40, TRUE) + update_appearance() + return TRUE + +// ===== Reading the find ===== + +/// The find it would draw from: an artifact on a tile around it, preferring one that is awake. +/obj/machinery/artifact_harvester/proc/find_source() + var/obj/machinery/artifact/fallback + for(var/obj/machinery/artifact/candidate in orange(1, src)) + if(QDELETED(candidate) || !isturf(candidate.loc)) + continue + if(candidate.is_active()) + return candidate + fallback ||= candidate + return fallback + +/// Whether a find is still close enough to draw from. +/obj/machinery/artifact_harvester/proc/in_reach(obj/machinery/artifact/source) + return !QDELETED(source) && isturf(source.loc) && source.z == z && get_dist(src, source) <= 1 + +/// The one awake effect a draw would take, or null when none or both are awake. +/obj/machinery/artifact_harvester/proc/awake_effect(obj/machinery/artifact/source) + var/datum/artifact_effect/found + for(var/datum/artifact_effect/effect as anything in source.effects()) + if(!effect.activated) + continue + if(found) + return null + found = effect + return found + +/// What the readout says about `source` right now (a HARVEST_SOURCE_* key). +/obj/machinery/artifact_harvester/proc/source_state(obj/machinery/artifact/source) + if(source.harvests_left <= 0) + return HARVEST_SOURCE_SPENT + if(source.is_being_used() && source.locked_by?.resolve() != src) + return HARVEST_SOURCE_BUSY + if(source.suppressed) + return HARVEST_SOURCE_QUIET + var/awake = 0 + for(var/datum/artifact_effect/effect as anything in source.effects()) + if(effect.activated) + awake++ + if(awake > 1) + return HARVEST_SOURCE_TANGLED + var/datum/artifact_effect/effect = awake_effect(source) + if(!effect) + return HARVEST_SOURCE_QUIET + if(!effect.harvestable) + return HARVEST_SOURCE_UNFIT + if(battery && !battery.can_take(effect) && !battery.is_full()) + return HARVEST_SOURCE_MISMATCH + return HARVEST_SOURCE_READY + +// ===== Drawing ===== + +/// Starts a draw from the find beside it. Returns TRUE if it started. +/obj/machinery/artifact_harvester/proc/start_draw(mob/living/user) + if(drawing) + return FALSE + if(!is_operational) + return refuse(user, "no power!") + if(!battery) + return refuse(user, "no battery!") + if(battery.is_full()) + return refuse(user, "battery's full!") + var/obj/machinery/artifact/source = find_source() + if(!source) + return refuse(user, "nothing to draw from!") + if(source_state(source) != HARVEST_SOURCE_READY) + return refuse(user, "no clean signal!") + var/datum/artifact_effect/effect = awake_effect(source) + if(!effect || !source.try_lock(src)) + return refuse(user, "no clean signal!") + + battery.load_from(effect, source.serial) + drawing = TRUE + draw_counted = FALSE + source_ref = WEAKREF(source) + drawn_ref = WEAKREF(effect) + operator_ref = user ? WEAKREF(user) : null + next_crackle = world.time + 3 SECONDS + + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + QDEL_NULL(draw_beam) + // The motes run from the find into the collector dome on the right of the sprite. + draw_beam = Beam(source, icon_state = "harvest_draw", icon = 'voidcrew/modules/xenoarch/icons/use.dmi', beam_color = kind.color, override_origin_pixel_x = 7, override_origin_pixel_y = 10) + soundloop.start() + playsound(src, 'sound/machines/terminal/terminal_prompt_confirm.ogg', 40, TRUE) + visible_message(span_notice("[src] hums, and a thin stream of [anomaly_glow_word(kind.key)] light reaches out to [source].")) + update_use_power(ACTIVE_POWER_USE) + begin_processing() + update_appearance() + return TRUE + +/// Buzzes and says why it won't start. Always FALSE. +/obj/machinery/artifact_harvester/proc/refuse(mob/living/user, reason) + playsound(src, 'sound/machines/buzz/buzz-two.ogg', 30, TRUE) + if(user) + balloon_alert(user, reason) + return FALSE + +/obj/machinery/artifact_harvester/process(seconds_per_tick) + if(!drawing) + return PROCESS_KILL + var/obj/machinery/artifact/source = source_ref?.resolve() + var/datum/artifact_effect/effect = drawn_ref?.resolve() + if(!is_operational) + stop_draw("[src]'s dome flickers and goes dark.") + return + if(!battery || QDELETED(effect) || !in_reach(source) || !source.try_lock(src)) + stop_draw("[src] whines down as the stream of light snaps.") + return + var/added = battery.add_charge(draw_rate * seconds_per_tick) + if(added > 0 && !draw_counted) + count_harvest(source, effect) + if(world.time >= next_crackle) + next_crackle = world.time + rand(5 SECONDS, 8 SECONDS) + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + playsound(source, kind.pulse_sound, 25, TRUE) + source.throb(1.06) + flick_dome(kind.color) + if(battery.is_full()) + finish_draw() + +/// Takes one of the find's harvests. Runs once per draw, when the first charge arrives. +/obj/machinery/artifact_harvester/proc/count_harvest(obj/machinery/artifact/source, datum/artifact_effect/effect) + draw_counted = TRUE + source.harvests_left = max(source.harvests_left - 1, 0) + var/mob/user = operator_ref?.resolve() + SEND_SIGNAL(source, COMSIG_ARTIFACT_HARVESTED, effect, user) + record_metric( + category = METRIC_RESEARCH, + event = XENOARCH_METRIC_HARVESTED, + zone = xenoarch_band_name(source.origin_band), + subject = "[effect.type]", + details = list( + "serial" = source.serial, + "harvests_taken" = source.harvests_taken(), + "kind" = effect.energy_kind, + "release" = effect.release_method, + "strength" = effect.strength, + ), + actor = user, + location = src, + ) + log_game("[user ? key_name(user) : "Nobody"] drew [effect.log_name] off artifact [source.serial] with [src] at [AREACOORD(src)]; [source.harvests_left] harvests left.") + +/obj/machinery/artifact_harvester/proc/finish_draw() + var/datum/artifact_energy_kind/kind = battery?.held_kind() + stop_draw() + playsound(src, 'sound/machines/chime.ogg', 40, FALSE) + if(kind) + visible_message(span_notice("[src] chimes, and its dome settles to a steady [anomaly_glow_word(kind.key)] glow.")) + else + visible_message(span_notice("[src] chimes.")) + +/** + * Ends a draw: lets go of the find, cuts the stream and the hum. Safe to call when idle and from + * Destroy(). `message` is shown to anyone watching. + */ +/obj/machinery/artifact_harvester/proc/stop_draw(message) + if(!drawing) + return + drawing = FALSE + var/obj/machinery/artifact/source = source_ref?.resolve() + source?.release_lock(src) + source_ref = null + drawn_ref = null + operator_ref = null + draw_counted = FALSE + QDEL_NULL(draw_beam) + soundloop?.stop() + end_processing() + if(QDELETED(src)) + return + update_use_power(IDLE_POWER_USE) + update_appearance() + SStgui.update_uis(src) + if(message) + visible_message(span_warning(message)) + playsound(src, 'sound/machines/terminal/terminal_off.ogg', 40, TRUE) + +// ===== Looks ===== + +/obj/machinery/artifact_harvester/update_icon_state() + if(drawing) + icon_state = "[base_icon_state]_on" + else if(battery) + icon_state = "[base_icon_state]_loaded" + else + icon_state = base_icon_state + return ..() + +/obj/machinery/artifact_harvester/update_overlays() + . = ..() + if(!battery) + return + var/datum/artifact_energy_kind/kind + var/fraction = battery.charge_fraction() + if(drawing) + var/datum/artifact_effect/effect = drawn_ref?.resolve() + kind = effect ? artifact_energy_kind(effect.energy_kind) : battery.held_kind() + // The dome is lit the whole draw, even while the battery is still nearly empty. + fraction = max(fraction, 0.6) + else + kind = battery.lit_kind() + . += anomaly_core_overlays(src, "harvester_dome", kind, fraction) + +/// A brief flare of the dome in `color` that fades back to whatever it shows. +/obj/machinery/artifact_harvester/proc/flick_dome(color) + var/mutable_appearance/flare = mutable_appearance(icon, "harvester_dome") + flare.color = color + var/atom/movable/flare_visual = flick_overlay_view(flare, 0.8 SECONDS) + if(flare_visual) + animate(flare_visual, alpha = 0, time = 0.8 SECONDS, easing = SINE_EASING | EASE_IN) + +// ===== Tools ===== + +/obj/machinery/artifact_harvester/screwdriver_act(mob/living/user, obj/item/tool) + if(drawing) + balloon_alert(user, "it's drawing!") + return ITEM_INTERACT_BLOCKING + if(default_deconstruction_screwdriver(user, icon_state, icon_state, tool)) + update_appearance() + return ITEM_INTERACT_SUCCESS + return NONE + +/obj/machinery/artifact_harvester/crowbar_act(mob/living/user, obj/item/tool) + if(drawing && panel_open) + balloon_alert(user, "it's drawing!") + return ITEM_INTERACT_BLOCKING + if(default_deconstruction_crowbar(tool)) + return ITEM_INTERACT_SUCCESS + return NONE + +// ===== Window ===== + +/obj/machinery/artifact_harvester/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "ArtifactHarvester", name) + ui.open() + +/obj/machinery/artifact_harvester/ui_data(mob/user) + var/list/data = list() + data["powered"] = is_operational + data["drawing"] = drawing + var/obj/machinery/artifact/source = drawing ? source_ref?.resolve() : find_source() + if(source) + var/datum/artifact_effect/effect = drawing ? drawn_ref?.resolve() : awake_effect(source) + var/datum/artifact_energy_kind/kind = effect ? artifact_energy_kind(effect.energy_kind) : null + data["source"] = list( + "serial" = source.serial || "untagged", + "state" = drawing ? HARVEST_SOURCE_DRAWING : source_state(source), + "color" = kind?.color, + ) + else + data["source"] = null + if(battery) + var/datum/artifact_energy_kind/kind = battery.lit_kind() + data["cell"] = list( + "fill" = round(battery.charge_fraction(), 0.01), + "color" = kind?.color, + "kind" = kind?.report_name, + "serial" = battery.source_serial, + ) + else + data["cell"] = null + return data + +/obj/machinery/artifact_harvester/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) + . = ..() + if(.) + return + var/mob/living/user = ui.user + switch(action) + if("draw") + start_draw(user) + return TRUE + if("halt") + if(drawing) + stop_draw("[src] whines down.") + return TRUE + if("eject") + eject_battery(user) + return TRUE + if("purge") + purge_battery(user) + return TRUE + +// ===== Board, design and sound ===== + +/obj/item/circuitboard/machine/artifact_harvester + name = "Exotic Particle Harvester" + greyscale_colors = CIRCUIT_COLOR_SCIENCE + build_path = /obj/machinery/artifact_harvester + req_components = list( + /datum/stock_part/capacitor = 2, + /datum/stock_part/scanning_module = 1, + /datum/stock_part/micro_laser = 1, + ) + +/datum/design/board/artifact_harvester + name = "Exotic Particle Harvester Board" + desc = "The circuit board for an exotic particle harvester." + id = "xenoarch_harvester" + build_path = /obj/item/circuitboard/machine/artifact_harvester + category = list( + RND_CATEGORY_MACHINE + RND_SUBCATEGORY_MACHINE_RESEARCH + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE + +/datum/looping_sound/artifact_harvester + start_sound = 'sound/machines/gravgen/grav_gen_start.ogg' + start_length = 1 SECONDS + mid_sounds = list( + 'sound/machines/gravgen/grav_gen_mid1.ogg' = 12, + 'sound/machines/gravgen/grav_gen_mid2.ogg' = 1, + ) + mid_length = 1.1 SECONDS + end_sound = 'sound/machines/gravgen/grav_gen_end.ogg' + volume = 30 + extra_range = -4 + falloff_distance = 2 + falloff_exponent = 5 + vary = TRUE + +#undef HARVEST_SOURCE_READY +#undef HARVEST_SOURCE_QUIET +#undef HARVEST_SOURCE_TANGLED +#undef HARVEST_SOURCE_UNFIT +#undef HARVEST_SOURCE_SPENT +#undef HARVEST_SOURCE_BUSY +#undef HARVEST_SOURCE_MISMATCH +#undef HARVEST_SOURCE_DRAWING diff --git a/voidcrew/modules/xenoarch/use/utilizer.dm b/voidcrew/modules/xenoarch/use/utilizer.dm new file mode 100644 index 00000000000..27b7ab9f86f --- /dev/null +++ b/voidcrew/modules/xenoarch/use/utilizer.dm @@ -0,0 +1,366 @@ +/** + * # Exotic utilizer + * + * A handheld emitter that runs whatever effect its exotic battery holds. Switched on from its + * own small window (attack_self), never from an action button. + * + * - A field effect runs without a break; a burst effect builds up and lets go on its own rhythm, + * at twice the rate the artifact itself refilled. Either costs ARTIFACT_UTILIZER_DRAIN charge a + * second, so a full battery lasts about six and a half minutes. + * - A contact effect waits until the holder presses the prongs to someone (themselves included), + * at ARTIFACT_UTILIZER_TOUCH_COST a use: ten uses from a full battery. + * - Whoever switched it on answers for the harm it does (set_responsible), and every contact use + * is logged like a weapon hit. Its holder and anyone else in reach are affected alike. + * - It goes dark inside a trader outpost, as artifacts do. + * - Healing, cell charge and air effects run through the effect's own code, so the shared heal + * cap, the cell rules and the planet-air guard all still apply. It makes no charge of its own. + * + * Rewritten from NovaSector (5ce2bd2215c0) modular_nova/modules/xenoarchartifacts/obj/particle_battery.dm + * (/obj/item/xenoarch/xenoarch_utilizer), with its HTML window replaced by tgui (AnomalyUtilizer.tsx) + * and its timer mode dropped. Art: Nova's machinery.dmi utilizer states (CC BY-SA 3.0, pixel-checked + * clean against Goon), with core and prong masks drawn for Voidcrew. Sounds and hums are the + * energy kind's own (core/artifact_energy_kinds.dm). + * + * Ship saves delete it like any item, battery and all, so it can never come back charged. + */ + +/// How long each process keeps the battery's effect awake: well past the next SSobj tick, so it +/// never lapses while on, even when the server lags. Switching off puts it to sleep at once. +#define UTILIZER_WAKE_MARGIN (10 SECONDS) + +/obj/item/anomaly_utilizer + name = "exotic utilizer" + desc = "A pronged emitter on a squat grip, with a slot for an exotic battery." + icon = 'voidcrew/modules/xenoarch/icons/use.dmi' + icon_state = "utilizer" + base_icon_state = "utilizer" + inhand_icon_state = "electronic" + lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi' + righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi' + w_class = WEIGHT_CLASS_SMALL + item_flags = NOBLUDGEON + light_system = OVERLAY_LIGHT + light_range = 2 + light_power = 0.8 + light_on = FALSE + custom_materials = list( + /datum/material/iron = SHEET_MATERIAL_AMOUNT * 2, + /datum/material/glass = SHEET_MATERIAL_AMOUNT, + /datum/material/gold = SHEET_MATERIAL_AMOUNT, + /datum/material/plasma = SHEET_MATERIAL_AMOUNT, + ) + /// The battery in its slot + var/obj/item/anomaly_battery/battery + /// Switched on and giving off its effect + var/emitting = FALSE + /// The energy kind's hum while it runs + var/datum/looping_sound/hum + +/obj/item/anomaly_utilizer/Destroy(force) + switch_off(quiet = TRUE) + QDEL_NULL(battery) + QDEL_NULL(hum) + return ..() + +/// The effect it would run, or null with no battery or an empty one. +/obj/item/anomaly_utilizer/proc/loaded_effect() + return battery?.held_effect + +/// Whether it may run here: never inside a trader outpost. +/obj/item/anomaly_utilizer/proc/is_damped() + return is_trader_outpost_protected(src) + +// ===== Battery slot ===== + +/obj/item/anomaly_utilizer/item_interaction(mob/living/user, obj/item/tool, list/modifiers) + if(!istype(tool, /obj/item/anomaly_battery)) + return NONE + if(battery) + balloon_alert(user, "slot's taken!") + return ITEM_INTERACT_BLOCKING + if(!user.transferItemToLoc(tool, src)) + return ITEM_INTERACT_BLOCKING + battery = tool + to_chat(user, span_notice("You slide [tool] into [src] until it clicks.")) + playsound(src, 'sound/items/weapons/gun/general/magazine_insert_full.ogg', 30, TRUE) + update_appearance() + SStgui.update_uis(src) + return ITEM_INTERACT_SUCCESS + +/obj/item/anomaly_utilizer/Exited(atom/movable/gone, direction) + . = ..() + if(gone != battery) + return + switch_off(quiet = QDELETED(src)) + battery = null + if(!QDELETED(src)) + update_appearance() + SStgui.update_uis(src) + +/obj/item/anomaly_utilizer/proc/eject_battery(mob/living/user) + if(!battery) + return FALSE + var/obj/item/anomaly_battery/ejected = battery + switch_off() + ejected.forceMove(drop_location()) + if(user) + user.put_in_hands(ejected) + playsound(src, 'sound/items/weapons/gun/general/magazine_remove_full.ogg', 30, TRUE) + return TRUE + +// ===== Switching ===== + +/// Switches it on. Returns TRUE if it started. +/obj/item/anomaly_utilizer/proc/switch_on(mob/living/user) + if(emitting) + return FALSE + var/datum/artifact_effect/effect = loaded_effect() + if(!effect || battery.stored_charge <= 0) + playsound(src, 'sound/machines/click.ogg', 30, TRUE) + if(user) + balloon_alert(user, "nothing happens") + return FALSE + if(is_damped()) + playsound(src, 'sound/machines/click.ogg', 30, TRUE) + if(user) + to_chat(user, span_warning("[src] clicks, but its prongs stay dark.")) + return FALSE + emitting = TRUE + effect.set_responsible(user) + effect.wake(UTILIZER_WAKE_MARGIN) + START_PROCESSING(SSobj, src) + + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + playsound(src, 'sound/machines/click.ogg', 30, TRUE) + playsound(src, kind.wake_sound, 40, TRUE) + QDEL_NULL(hum) + if(kind.hum_type) + hum = new kind.hum_type(src) + hum.start() + visible_message(span_notice("[src] hums to life, its prongs glowing [anomaly_glow_word(kind.key)].")) + if(user) + user.log_message("switched on [src] holding [effect.log_name] ([effect.release_method], [effect.strength]).", effect.harmful ? LOG_ATTACK : LOG_GAME) + update_glow() + update_appearance() + SStgui.update_uis(src) + return TRUE + +/// Switches it off. `message` is shown to anyone watching; `quiet` skips sound and updates (deletion). +/obj/item/anomaly_utilizer/proc/switch_off(message, quiet = FALSE) + if(!emitting) + return + emitting = FALSE + STOP_PROCESSING(SSobj, src) + var/datum/artifact_effect/effect = loaded_effect() + effect?.deactivate() + hum?.stop() + if(quiet) + return + if(message) + visible_message(span_notice(message)) + playsound(src, 'sound/effects/stealthoff.ogg', 30, TRUE) + update_glow() + update_appearance() + SStgui.update_uis(src) + +/obj/item/anomaly_utilizer/process(seconds_per_tick) + var/datum/artifact_effect/effect = loaded_effect() + if(!emitting || !effect) + switch_off() + return PROCESS_KILL + if(is_damped()) + switch_off("[src] crackles and goes dark.") + return PROCESS_KILL + var/old_level = battery.charge_level() + switch(effect.release_method) + if(ARTIFACT_RELEASE_AURA) + battery.use_charge(ARTIFACT_UTILIZER_DRAIN * seconds_per_tick) + // The battery pays for a field that never rests. + effect.current_charge = effect.maximum_charges + if(ARTIFACT_RELEASE_PULSE) + battery.use_charge(ARTIFACT_UTILIZER_DRAIN * seconds_per_tick) + effect.current_charge = min(effect.maximum_charges, effect.current_charge + ARTIFACT_UTILIZER_PULSE_FEED * seconds_per_tick) + var/store_before = effect.current_charge + effect.wake(UTILIZER_WAKE_MARGIN) + effect.tick(seconds_per_tick) + if(QDELETED(src)) + return PROCESS_KILL + if(effect.release_method == ARTIFACT_RELEASE_PULSE && effect.current_charge < store_before) + burst_visuals(artifact_energy_kind(effect.energy_kind)) + if(battery.stored_charge <= 0) + switch_off("[src] sputters and goes dark.") + return PROCESS_KILL + if(battery.charge_level() != old_level) + update_appearance() + +// ===== Contact ===== + +/obj/item/anomaly_utilizer/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers) + if(!isliving(interacting_with)) + return NONE + var/datum/artifact_effect/effect = loaded_effect() + if(!emitting || effect?.release_method != ARTIFACT_RELEASE_TOUCH) + return NONE + return touch_with(interacting_with, user) + +/// Presses the prongs to `target`, letting the battery's contact effect act on them. +/obj/item/anomaly_utilizer/proc/touch_with(mob/living/target, mob/living/user) + var/datum/artifact_effect/effect = loaded_effect() + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + user.changeNext_move(CLICK_CD_MELEE) + user.do_attack_animation(target) + effect.set_responsible(user) + effect.current_charge = max(effect.current_charge, effect.touch_cost) + if(target == user) + user.visible_message( + span_warning("[user] presses [src] to [user.p_them()]self. Its prongs flare [anomaly_glow_word(kind.key)]."), + span_warning("You press [src] to yourself. Its prongs flare [anomaly_glow_word(kind.key)]."), + ) + else + user.visible_message( + span_warning("[user] presses [src] against [target]. Its prongs flare [anomaly_glow_word(kind.key)]."), + span_warning("You press [src] against [target]. Its prongs flare [anomaly_glow_word(kind.key)]."), + ignored_mobs = target, + ) + to_chat(target, span_userdanger("[user] presses [src] against you!")) + log_combat(user, target, "touched", src, "([effect.log_name])") + effect.touch(target) + battery?.use_charge(ARTIFACT_UTILIZER_TOUCH_COST) + burst_visuals(kind) + if(!battery || battery.stored_charge <= 0) + switch_off("[src] sputters and goes dark.") + else + update_appearance() + SStgui.update_uis(src) + return ITEM_INTERACT_SUCCESS + +// ===== Looks ===== + +/// The swell and flash of a burst or a contact. +/obj/item/anomaly_utilizer/proc/burst_visuals(datum/artifact_energy_kind/kind) + if(!kind) + return + playsound(src, kind.pulse_sound, 45, TRUE) + var/matrix/swell = matrix() + swell.Scale(1.2) + animate(src, transform = swell, time = 0.12 SECONDS, easing = SINE_EASING | EASE_OUT) + animate(transform = matrix(), time = 0.35 SECONDS, easing = SINE_EASING | EASE_IN) + var/mutable_appearance/flare = mutable_appearance(icon, "utilizer_tips") + flare.color = kind.color + var/atom/movable/flare_visual = flick_overlay_view(flare, 0.6 SECONDS) + if(flare_visual) + flare_visual.add_filter("flare_glow", 1, drop_shadow_filter(0, 0, 3, 0, "[kind.color]cc")) + animate(flare_visual, alpha = 0, time = 0.6 SECONDS, easing = SINE_EASING | EASE_IN) + +/// The breathing glow and light while it runs. +/obj/item/anomaly_utilizer/proc/update_glow() + var/datum/artifact_effect/effect = loaded_effect() + if(!emitting || !effect) + remove_filter("utilizer_glow") + set_light_on(FALSE) + return + var/datum/artifact_energy_kind/kind = artifact_energy_kind(effect.energy_kind) + add_filter("utilizer_glow", 2, drop_shadow_filter(0, 0, 1.5, 0, "[kind.color]40")) + transition_filter_chain("utilizer_glow", -1, \ + FilterChainStep(list("color" = "[kind.color]b0", "size" = 2), 0.8 SECONDS, SINE_EASING), \ + FilterChainStep(list("color" = "[kind.color]40", "size" = 1.5), 0.8 SECONDS, SINE_EASING)) + // A light or darkness effect lights its battery itself; the utilizer stays out of its way. + if(effect.light_override()) + set_light_on(FALSE) + return + set_light_color(kind.color) + set_light_on(TRUE) + +/obj/item/anomaly_utilizer/update_icon_state() + icon_state = battery ? "[base_icon_state][battery.charge_level()]" : base_icon_state + return ..() + +/obj/item/anomaly_utilizer/update_overlays() + . = ..() + if(!battery) + return + var/datum/artifact_energy_kind/kind = battery.lit_kind() + . += anomaly_core_overlays(src, "utilizer_core", kind, battery.charge_fraction()) + if(emitting && kind) + var/mutable_appearance/tips = mutable_appearance(icon, "utilizer_tips") + tips.color = kind.color + . += tips + . += emissive_appearance(icon, "utilizer_tips", src) + +/obj/item/anomaly_utilizer/examine(mob/user) + . = ..() + if(!battery) + . += "Its battery slot is empty." + return + . += "An exotic battery sits in its slot." + . += anomaly_core_description(battery.lit_kind(), battery.charge_fraction()) + if(emitting) + var/datum/artifact_energy_kind/kind = battery.held_kind() + . += span_notice("It hums, its prongs glowing [anomaly_glow_word(kind?.key)].") + +// ===== Window ===== + +/obj/item/anomaly_utilizer/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "AnomalyUtilizer", name) + ui.open() + +/obj/item/anomaly_utilizer/ui_data(mob/user) + var/list/data = list() + data["emitting"] = emitting + if(battery) + var/datum/artifact_effect/effect = loaded_effect() + var/datum/artifact_energy_kind/kind = battery.lit_kind() + var/mode + switch(effect?.release_method) + if(ARTIFACT_RELEASE_AURA) + mode = "field" + if(ARTIFACT_RELEASE_PULSE) + mode = "burst" + if(ARTIFACT_RELEASE_TOUCH) + mode = "contact" + data["cell"] = list( + "fill" = round(battery.charge_fraction(), 0.01), + "color" = kind?.color, + "serial" = battery.source_serial, + "mode" = kind ? mode : null, + ) + else + data["cell"] = null + return data + +/obj/item/anomaly_utilizer/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) + . = ..() + if(.) + return + var/mob/living/user = ui.user + switch(action) + if("power") + if(emitting) + switch_off("[src] winds down.") + else + switch_on(user) + return TRUE + if("eject") + eject_battery(user) + return TRUE + +/datum/design/anomaly_utilizer + name = "Exotic Utilizer" + desc = "A handheld emitter that runs whatever an exotic battery holds." + id = "xenoarch_utilizer" + build_type = PROTOLATHE | AWAY_LATHE + materials = list( + /datum/material/iron = SHEET_MATERIAL_AMOUNT * 2, + /datum/material/glass = SHEET_MATERIAL_AMOUNT, + /datum/material/gold = SHEET_MATERIAL_AMOUNT, + /datum/material/plasma = SHEET_MATERIAL_AMOUNT, + ) + build_path = /obj/item/anomaly_utilizer + category = list( + RND_CATEGORY_EQUIPMENT + RND_SUBCATEGORY_EQUIPMENT_SCIENCE + ) + departmental_flags = DEPARTMENT_BITFLAG_SCIENCE + +#undef UTILIZER_WAKE_MARGIN diff --git a/wiki/content/xenoarchaeology.md b/wiki/content/xenoarchaeology.md new file mode 100644 index 00000000000..5cfbb38c9c4 --- /dev/null +++ b/wiki/content/xenoarchaeology.md @@ -0,0 +1,328 @@ +--- +title: Xenoarchaeology +category: Exploration +order: 3.5 +blurb: Dig old alien finds out of planet cliffs, work out what wakes them, then sell them to Barnaby, Boffin and Vex or bolt them down aboard. +--- + +Some planet cliffs hold old dig sites: veined rock with something that isn't stone inside it. Most of it is small stuff such as fossils and pottery. Now and then a whole boulder comes away with an alien artifact in it. Getting one out in one piece takes care, finding out what it does means poking it, and a correct label is what the buyers pay for. A dug artifact can be sold at a [trader outpost](trader-outposts.md), bolted down aboard for its effect, or drained into batteries for a handheld projector. + +## Where finds come from + +Dig sites are on planet surfaces only. Ruins, asteroid fields and outposts have none. See [Planets](planets.md). + +A site is a run of about four wall tiles in a cliff face, each threaded with pale veins. Two or three survey stakes with orange or red flagging tape and a heap of spoil stand on the ground in front, so a site shows from across the map. Examine a vein wall and it says pale veins run through the rock. A mining scanner marks the walls with a sign of its own, not an ore's. A world with no cliff to dig into gets a short outcrop of its own rock instead. + +Mine a vein wall with a pickaxe or drill. Each wall gives up one find. It is either a boulder with a large find inside, or a strange rock with a small one. NPC miners leave these walls alone. + +Every world holds three sites, and what is in them is fixed for the round. + +| Zone | Large finds per world | Small finds per world | +|---|---|---| +| Green | 3 | 9 | +| Yellow | 3 | 9 | +| Red | 6 | 6 | + +Sites do not refill when a planet unloads and comes back. A boulder you cut free but did not finish is put back as you left it, with its depth, tag and stabiliser field. + +The zone the planet is in decides how good the finds are. Higher zones give rarer and stronger effects, better small finds and bigger payouts. Every effect can turn up in every zone, so a green-only crew can dig, study and sell everything. Freeing a large find in yellow or red can also wake whatever lives in the rock (see below). Only red space can hold a wrecked exosuit. See [The Overmap](overmap.md) for the zones. + +## Tools + +Print the **Excavation Kit** at any autolathe from the start. It costs 3 iron, 1 glass and 1 plastic sheet and comes as a belt of webbing holding a rock hammer, brush, depth scanner, core sampler and find satchel. Each piece prints on its own too. You also need a pickaxe or drill for the walls, and a mining scanner if you want to tag boulders. Everything else comes from [research](research.md). + +| Tool | What it does | Where from | +|---|---|---| +| Rock hammer | Chips rock off a find. Use it in hand to fit a 1, 2, 4, 6 or 10 cm head. | Kit | +| Excavation brush | Takes one centimetre per pass and can never overshoot. | Kit | +| Depth scanner | Pins a survey tag to a find saying how deep it sits. | Kit | +| Core sampler | Draws a core of rock from a boulder. Holds one core. | Kit | +| Find satchel | Holds 12 strange rocks, curios and strange objects. | Kit | +| Field stabiliser | Holds a boulder together while its find is freed. Eight field settings. | Xenoarchaeology, protolathe | +| Radiocarbon spectrometer | Reads a core and prints which field a boulder needs. | Xenoarchaeology, circuit imprinter | +| Artifact analyser and scan pad | Read a find. Build both. | Xenoarchaeology, circuit imprinter | +| Specimen labeler | Prints the tag that goes on a large find. | Xenoarchaeology, protolathe | +| Specimen crate | Holds one large find safely. | Xenoarchaeology | +| Advanced depth scanner | Reads the exact depth and the field, on site. | Advanced Excavation, protolathe | +| Quick brush | Brushes three times as fast. | Advanced Excavation, protolathe | +| Exotic particle harvester | Drains an effect into a battery. | Exotic Particles, circuit imprinter | +| Exotic battery and exotic utilizer | Store a drained effect and let it out again. | Exotic Particles, protolathe | + +**Xenoarchaeology** costs 40 research points and follows Fundamental Science. **Advanced Excavation** costs 80 and follows Xenoarchaeology. **Exotic Particles** costs 120 and also follows Xenoarchaeology, and your crew needs 4 [reputation](zone-reputation.md) before it opens. + +## Digging + +### Strange rocks + +A strange rock is a lump of veined rock you can carry. It holds one small find, much shallower than a boulder's, 14 to 38 cm down. + +1. Optionally sound it with a depth scanner. It reads a ten-centimetre window. +2. Chip it down with the hammer. +3. Finish with the brush. + +No stabiliser is needed. Cut past the find and the find goes with the rock. A blast can destroy one too. When it comes free it drops into the hand that held the rock. + +### Boulders + +A boulder is the large find. It is anchored and heavy, and breaking it loses what is inside, so keep explosives away. Work it in this order. + +1. **Tag it.** Use a mining scanner on the boulder. It gets a holotag with a catalogue number such as Kappa-4412 and shows on GPS units as that number plus "dig". Anyone with a GPS can pick it up, other crews included. +2. **Sound it.** Use a depth scanner. It pins a survey tag saying how deep the find sits as a 30 cm window, and how much has been cut so far. Finds sit between 25 and 200 cm down. The advanced scanner gives the exact depth. +3. **Learn the field.** Every boulder needs one of eight stabilising fields. The advanced depth scanner reads it on site. With the plain scanner, push the core sampler into the boulder (two seconds), take the core to a radiocarbon spectrometer aboard ship (about ten seconds), and read the "Matrix holds under" line on the report it prints. The report carries the boulder's catalogue number, so you can keep several apart. +4. **Stabilise it.** Use the field stabiliser in hand to pick the field, then sweep it over the boulder for five seconds. A wrong field looks exactly like a right one. +5. **Cut down to the find.** Mix tools as you like. +6. **Brush it clean.** Once the cut equals the depth, one more pass frees the find. + +| Cutting tool | Takes off | Time | +|---|---|---| +| Pickaxe or drill | 18 to 30 cm | 2.5 seconds a swing | +| Rock hammer | The fitted head, 1 to 10 cm | Half a second per cm | +| Brush | 1 cm | 3 seconds a pass, 1 second with the quick brush | + +A sounded boulder tells you the running total after every strike. The pick and hammer can overshoot. The brush cannot, so stop short and brush the rest. Walk away from a hammer swing halfway through and it may chip a centimetre or two off the boulder. + +### Losing or cracking a find + +- **Cut past the find** and the boulder splits along a fault. Nothing is left. +- **Free it without the right field** and half the time it slumps to pieces and nothing is left. The other half it comes out cracked. +- A cracked find sells for half. A cracked charged crystal holds half its charge and a cracked exosuit is in worse shape. +- **Smashing or blasting a boulder** loses the find. + +In yellow or red space, freeing a large find can wake the local fauna: roughly one time in four in yellow and nearly one in two in red. The ground shudders, and about three seconds later a pack of animals or spiders crawls out four to seven tiles away. + +## What can come out + +| Find | What it is | +|---|---| +| Alien artifact | The usual large find. Comes in many shapes. One main effect, sometimes a milder second one. See Study and Using artifacts. | +| Bluespace formation | Pale blue crystal on black rock. It has no effect to study and no buyer wants it. Each time it takes a hit it teleports everyone within three tiles a short hop away and sets off a small EMP. Broken, it leaves 2 to 4 bluespace crystals, which traders buy (see [Mining & Salvage](mining.md)). | +| Charged crystal | An amber crystal holding a limited charge. It can run a ship's power for a while. | +| Sealed case | A sealed specimen transfer cache of lab and research gear, better the higher the zone it was dug in. It can hold a weapon. | +| Exosuit wreck | Very rare, red zone only. A Gygax or Durand, badly damaged, nearly flat on charge, caked in dust and carrying no weapons. Wash it, repair it and arm it yourselves. | +| Curios | Shells, plant fossils, bones, skulls, skeletons, bowls, urns, statuettes, instruments, idols, seed pods, corroded mechanisms and spent sidearms. They sell. | +| Research notes | A page worth 100 or 250 research points. | +| Strange object | A device of unknown purpose. Boffin buys them. | + +Small finds come out of strange rocks. Large finds come out of boulders. Every artifact, curio and strange object is stamped with the zone it was dug in, and that stamp is what pricing and research read, wherever you carry it afterwards. + +## Moving finds + +A large find is dense and unbolted, so you pull it. Pulling or bumping an artifact counts as touching it, at most once every three seconds. That wakes a touch-triggered artifact unless you wear latex gloves. + +!!! warning "Hauled artifacts can go off" + Latex gloves stop you waking a touch-triggered artifact. They do not stop one that is already awake from acting on you. + +A large find travels in a **specimen crate**, a padded, lead-lined crate built for one large find. Open the crate, then either drag the find onto it (a few seconds' heave, and the lid shuts on it) or push the find onto the open crate and close the lid. Ordinary crates will not take one, and a bolted-down find will not go in. The specimen crate also holds small things, never people or other machines, and its lid shows the find's catalogue number. While a find is shut in a crate it does nothing at all. + +Every way into a trader outpost runs through a scan chamber. A loose artifact on the chamber floor makes the guard refuse the whole chamber ("Crate it first.") until someone takes it back out. A find in a shut crate passes. Going out is never a problem. Inside an outpost an artifact does nothing and cannot be bolted down. The lift between floors carries unbolted things standing in its alcove, so a crate rides up with you. + +## Study + +Large finds are read at an **artifact analyser** beside a **scan pad**. Both need power, must be bolted down and need their panels closed. Stand the find on the pad and open the analyser. + +### Scanning + +A scan takes about ten seconds. Better scanning modules shorten it. The analyser prints a report with the condition of the find and one line for each emission it has, giving three things: + +- the **energy kind**, which also sets the colour of the glow when the find wakes; +- how it is released: on contact, as a field, or in bursts; +- what it reacts to: physical contact, energetic contact, or its surroundings. + +A find with only one emission prints "None detected" for the secondary one, which tells you whether the second effect on a label should say None. The report never names the effect. The first completed scan of each dug find also prints research notes, once per find however many crews scan it: 100 points for a green find, 150 for yellow and 250 for red, and half as much again for the rarer effects. Take the notes to any R&D console. + +| Report says | Glow | +|---|---| +| Concentrated energy | Amber | +| Psionic wavefront | Violet | +| Electromagnetic energy | Pale blue | +| High-frequency particles | White | +| Organically reactive particles | Rose red | +| Bluespace phasing | Deep blue | +| Atomic synthesis | Green | + +Heat and cold report as energetic contact even though air temperature sets them off. Plasma, carbon dioxide and proximity report as surroundings. + +### Testing + +The report narrows an artifact down. To find the rest, apply stimuli to the find on the pad and watch the analyser's **tape**. Each stimulus prints a line such as "Water. Response." or "Touch. No response.", and each emission prints "emission rising" and "emission fading" as it wakes and sleeps. Air and proximity triggers print no stimulus line, only the rising and fading ones. The tape holds twelve lines. Tear it off for a paper slip. + +Touch the find, splash it, hit it, burn it, shock it, change the air around it. The trigger table below says what each word means. Put on bio gear first (see Hazards). + +A stimulus wakes any effect with that trigger for 45 to 90 seconds, and another stimulus restarts the clock. Air and proximity triggers keep the effect awake for as long as the condition lasts, plus a few seconds. An awake artifact glows, hums and gives off particles. + +### Labelling + +Open the **specimen labeler** in hand and pick three words from its lists: what the find does, what wakes it, and its second effect or None. Use it on the find to stick on the tag, which takes a second. Right-click peels a tag off. A new tag replaces the old one, so you can relabel as often as you like. Examining the find shows the tag as written. + +Nothing in the game tells you whether the tag is right until a buyer pays for it. + +## Using artifacts + +### Bolted down + +Anyone can bolt an artifact down with a wrench, or unbolt it, in four seconds. An artifact runs its effect wherever it stands, and bolting it down keeps it there. Some limits apply: + +- A field uses its charge three times as fast as the artifact refills it, so it runs for about a third of the time and rests the rest. A burst fires when the store is full. +- No one can take more than 30 points of brute and burn healing from artifacts in five minutes, all artifacts and utilizers added together. +- A cell charger effect works on at most two ordinary power cells at once, at about charger speed. Machines and their cells are left alone. +- Gas effects vent only indoors, never onto planet ground or into space. Heat and cold change the air only indoors too, but they still warm or chill people anywhere. +- An artifact does nothing in a crate or inside a trader outpost. + +A ship rebuilt from a [checkpoint](player-outposts.md#ship-bay) comes back without its artifacts, charged crystals, batteries or utilizers. + +### Charged crystals + +Bolt a charged crystal down on a cable and wind two lengths of cable around it, and it puts 15 kW on the wire. It runs until it has given 90 minutes of power in all, then goes dull for good. Cut the wire to stop it and keep what is left. A cracked crystal starts with half. + +### Harvester, battery and utilizer + +The **exotic particle harvester** draws one effect off an artifact into an **exotic battery**. + +1. Seat an empty battery under the dome. +2. Put the artifact on a tile next to the harvester and wake the effect you want. +3. Press Draw. A full battery takes about 80 seconds, down to about 40 with the best capacitors. + +Notes: + +- Each artifact allows three harvests in all. A harvest is spent the moment charge starts to flow, and stopping early refunds nothing. Each one takes a fifth off the find's sale price. +- It will not draw while two effects are awake at once. +- An empty battery takes any effect. After that it tops up only from the effect it already holds. Purge a battery to reuse it. +- These effects cannot be drained: Twists flesh, Noise, Lightning, Moves on its own, Force walls, Shockwave, Vents plasma, Vents sleeping gas, Raises the dead and Fires spines. + +The **exotic utilizer** is a handheld projector with a slot for the battery. Open it in hand to switch it on. + +- A field or burst effect runs until the battery is empty, about six and a half minutes from full. +- A contact effect waits for you to press the prongs against someone, yourself included. A full battery gives ten uses. +- A field or burst reaches everyone in range, including the person holding it. +- It goes dark in a trader outpost. + +### Smashing + +An artifact is tough, but if it breaks, every effect that is not helpful lets off one last burst. + +## Selling + +Three outpost traders buy finds. Large finds sell only by hauling them to the trader. + +| Buyer | Outpost | Takes | +|---|---|---| +| Barnaby | Waystation Halcyon, general store | Large finds, curios | +| Boffin | The Skunkworks, Quartermain Depot | Large finds, curios, strange objects | +| Vex | Undertow Exchange, black market | Large finds. Pays one trade voucher on top for an artifact with one of the rarest main effects. | + +Sarge, at the Quartermain main counter, buys none and sends you round to Boffin. All three buyers pay the same for the same find. Selling earns no reputation. + +### Selling a large find + +1. Pull the find, or the shut crate holding it, to within three tiles of the trader. +2. Open Trade. The wanted ledger has a line for finds: "dig pieces" with Barnaby and Vex, "alien artifacts" with Boffin. Sell it. +3. The trader looks it over for a couple of seconds. Stay put. Walk away and the sale is off. +4. You get no quote and no second chance. The sale is final. Credits land on your ID's account, any voucher lands in your hand, and a paper receipt comes with them. + +Each buyer takes three large finds before the next supply convoy, and Barnaby and Boffin take six curios. A convoy arrives about every 22 minutes and brings demand part of the way back. + +### What it pays + +Four things set the price of a large find: + +- **The zone it was dug in**, not where you sell it. The base price is 250 credits for green, 450 for yellow and 700 for red. +- **Its main effect.** Rarer effects pay more, up to four times the base. +- **Your label.** The effect word is worth half of the price, the trigger word 30% and the second effect 20%. Add up what your label gets right. If it comes to half or more, you are paid that share of the price. Below half, or with no label, you are paid a fifth. +- **Condition.** A cracked find pays half. Each harvest takes off a fifth. + +A perfectly labelled artifact pays between 250 and 1,000 credits from green space, 450 and 1,800 from yellow, and 700 and 2,800 from red, depending on its main effect. The best of those in red also earns a voucher at Vex. Vouchers are covered on [Money & Trade](money-and-trade.md). + +### Curios + +Barnaby and Boffin pay by the piece. Vex buys none. + +| Credits | Items | +|---|---| +| 40 | Fossil shell | +| 50 | Plant fossil, fossil bone, fossil skull | +| 80 | Clay bowl, urn, corroded mechanism, spent sidearm | +| 150 | Statuette, strange instrument, idol, seed pod, fossil skeleton | +| 200 | Strange object (Boffin only) | + +Only finds that came out of a dig site sell. A strange object from maintenance or an experimentor copy is not one. Feeding a dug curio or strange object to the destructive analyzer pays research points, once per kind per research server. Rarer finds pay more. + +## Labels and triggers + +Every artifact has one main effect, and some carry a milder second one. Only the milder effects turn up as a second effect. + +### What wakes it + +| Trigger word | What sets it off | +|---|---| +| Touch | A bare hand, or any glove that isn't latex. | +| Water | A splash of water or hydrogen. | +| Acid | A splash of any acid. | +| Volatile chemicals | A splash of thermite, liquid plasma, nitroglycerin, gunpowder or similar. | +| Toxins | A splash of any other toxin. | +| Impact | A hit from anything with force, a thrown object that hits hard, a thrown creature, a bullet that does damage, or a blast. | +| Electricity | A live stun baton or lit energy blade pressed to it, a laser or energy beam, or an EMP. | +| Heat | Air above 375 K (102 °C), a lit welder or any tool above 700 K, fire, or a blast. | +| Cold | Air below 225 K (-48 °C). | +| Plasma | Ten or more moles of plasma in the air on its tile. | +| Carbon dioxide | Ten or more moles of carbon dioxide on its tile. | +| Proximity | A living thing within three tiles that it can see. | + +### What it does + +A field acts on everything in range while it runs. A burst acts on everything in range when the store fills. A contact effect acts on whoever touches the awake artifact. Any release works unless the table says otherwise. "Logged" means the effect is recorded as an attack (see Hazards). "Drain" means a harvester can take it. + +| Label | What it does | Drain | Logged | +|---|---|---|---| +| Restores blood | Tops up the blood of people nearby, up to normal. | Yes | No | +| Drains blood | Bleeds people nearby, never to the point of passing out. | Yes | Yes | +| Twists flesh | Bursts only. Turns one limb of someone close into a living flesh limb. | No | Yes | +| Charges cells | Charges loose or carried power cells. | Yes | No | +| Drains cells | Drains the same cells. | Yes | Yes | +| Nausea | Makes people nearby sick. | Yes | Yes | +| EMP | Bursts only. Sets off EMPs. | Yes | Yes | +| Good mood | Lifts the mood of people nearby. | Yes | No | +| Dread | Unease, dizziness and a bad mood. | Yes | No | +| Vents gas | Oxygen, nitrogen or carbon dioxide into the room. Stops when the room is a little over pressure. | Yes | No | +| Gravity | Bursts only. Pulls, pushes or scatters loose items, loose structures and people. | Yes | Yes | +| Hallucinations | Hallucinations and a drugged haze. | Yes | Yes | +| Heals | Mends brute and burn on living people nearby. | Yes | No | +| Mends machines | The same for robots and robotic limbs. | Yes | No | +| Hurts | Brute and burn damage to living people nearby. | Yes | Yes | +| Damages machines | The same against robots and robotic limbs. | Yes | Yes | +| Light | Field only. A bright glow. | Yes | No | +| Darkness | Field only. Dims everything nearby. | Yes | No | +| Noise | Bursts only. Wails and groans. | No | No | +| Radiation | Radiation pulses. | Yes | Yes | +| Puts people to sleep | Drowsiness, then sleep. | Yes | Yes | +| Knocks people down | Stamina damage, confusion and falls. | Yes | Yes | +| Teleports | Hops people a few tiles at random. Never into space or lava. | Yes | Yes | +| Heat | Warms people and the room, stopping short of burning anyone. | Yes | No | +| Cold | Chills people and the room, stopping short of freezing anyone. | Yes | No | +| Lightning | Bursts only. Arcs lightning at everything nearby. | No | Yes | +| Moves on its own | Creeps after the nearest person. Held back by its bolts. | No | No | +| Rage | Hits land harder and faster for a while, then exhaustion. | Yes | Yes | +| Makes people drop things | Pries open a hand and drops what is in it. | Yes | Yes | +| Shocks | Zaps robots and anyone holding something metal, and flickers the lights. | Yes | Yes | +| Puts out fires | Douses burning people, flames and burning objects. | Yes | No | +| EMP shielding | Makes you immune to EMPs for a while. | Yes | No | +| Second sight | See living things through walls for a short time. | Yes | No | +| Force walls | A ring of force walls goes up around it for several seconds. | No | No | +| Toughens skin | Takes some of the sting out of brute and burn damage for a short time. | Yes | No | +| Feeds plants | Waters and tends planted trays nearby. Sometimes draws a butterfly. | Yes | No | +| Shockwave | Contact or bursts. After a short wind-up, throws everyone and everything loose outward and knocks people down. | No | Yes | +| Drains life | Hooks a beam into someone, then tears health and stamina away a few seconds later. | Yes | Yes | +| Steals life | Contact or bursts. Heals one person by hurting everyone else nearby. | Yes | Yes | +| Vents plasma | Plasma into the room, from a limited supply. | No | Yes | +| Throws things | Lifts loose objects and throws them at the nearest person. | Yes | Yes | +| Raises the dead | Revives one body beside it that died under five minutes ago, if the person is still there to come back. Three uses, then dull. | No | No | +| Vents sleeping gas | Nitrous oxide into the room, from a limited supply. | No | Yes | +| Fires spines | Contact or bursts. A volley of bone spines in every direction. | No | Yes | +| Speeds people up | Faster on their feet for a short time. | Yes | No | +| Weeps fluid | Puddles of water, salt water, sugar, oil or vinegar. | Yes | No | + +## Hazards and logging + +- **Artifacts act on you.** A field or burst reaches everyone in range, and a contact effect hits whoever touches it. Bio suit and hood together stop most of an effect. Latex gloves and science goggles add the rest. Full protection also blocks the good effects. +- **Harmful effects are logged as attacks.** The person answering for it is whoever last woke, hit, splashed or hauled the artifact. For a utilizer it is whoever switched it on. A field logs each victim at most twice a minute. Nothing stops an artifact hurting another crew, and admins can see who did it. +- **Tagging, labelling, harvesting and selling are logged too,** and so is freeing a find that wakes an ambush. +- **Bolted artifacts act on your ship.** One that vents gas, irradiates or hurts people does it in your corridor.