diff --git a/tgstation.dme b/tgstation.dme
index 8db7849486c..aa85deb28d5 100644
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -6703,6 +6703,7 @@
#include "voidcrew\_DEFINES\human_npcs.dm"
#include "voidcrew\_DEFINES\job_categories.dm"
#include "voidcrew\_DEFINES\keybindings.dm"
+#include "voidcrew\_DEFINES\landing_view.dm"
#include "voidcrew\_DEFINES\lich.dm"
#include "voidcrew\_DEFINES\lighting.dm"
#include "voidcrew\_DEFINES\loot.dm"
@@ -7383,6 +7384,14 @@
#include "voidcrew\modules\intents\intent_component.dm"
#include "voidcrew\modules\intents\keybindings.dm"
#include "voidcrew\modules\intents\preferences.dm"
+#include "voidcrew\modules\landing_animation\landing_animation.dm"
+#include "voidcrew\modules\landing_animation\landing_view.dm"
+#include "voidcrew\modules\landing_animation\landing_view_ascent.dm"
+#include "voidcrew\modules\landing_animation\landing_view_descent.dm"
+#include "voidcrew\modules\landing_animation\landing_view_ground.dm"
+#include "voidcrew\modules\landing_animation\landing_view_hover.dm"
+#include "voidcrew\modules\landing_animation\landing_view_planes.dm"
+#include "voidcrew\modules\landing_animation\landing_view_sky.dm"
#include "voidcrew\modules\lich\lich_abilities.dm"
#include "voidcrew\modules\lich\lich_loot.dm"
#include "voidcrew\modules\lich\lich_mob.dm"
diff --git a/voidcrew/_DEFINES/landing_view.dm b/voidcrew/_DEFINES/landing_view.dm
new file mode 100644
index 00000000000..1dfd1dbfabd
--- /dev/null
+++ b/voidcrew/_DEFINES/landing_view.dm
@@ -0,0 +1,61 @@
+// Planet landing view (voidcrew/modules/landing_animation): what a crew sees around their hull while it lands
+// on a planet or leaves one.
+
+/// The plane the view draws on: over space and its parallax, under the whole world. Cut to
+/// LANDING_VIEW_MASK_PLANE, so it only shows on tiles the viewer can really see.
+#define LANDING_VIEW_PLANE -19
+/// Draws nothing itself. Whatever is on it becomes the mask LANDING_VIEW_PLANE is cut to.
+#define LANDING_VIEW_MASK_PLANE -44
+#define LANDING_VIEW_MASK_RENDER_TARGET "*LANDING_VIEW_MASK"
+/// A white tile on every turf of transit space around a landing hull, and none on the hull: what the ground's light is cut to
+#define LANDING_VIEW_OUTSIDE_PLANE -43
+#define LANDING_VIEW_OUTSIDE_RENDER_TARGET "*LANDING_VIEW_OUTSIDE"
+/// The light on the ground in the landing view, laid over the lighting of the transit space around the hull
+#define LANDING_VIEW_LIGHT_PLANE 18
+
+/// The sky's textures, and their size in pixels
+#define LANDING_VIEW_ICON 'voidcrew/icons/effects/landing_view.dmi'
+#define LANDING_VIEW_ICON_SIZE 480
+
+// Layers on LANDING_VIEW_PLANE, back to front. Pictures locked to the world are images; BYOND draws those
+// under every screen object on the same plane, whatever their layers.
+/// The real ground, far below
+#define LANDING_VIEW_LAYER_GROUND 10
+/// The hull's shadow on that ground
+#define LANDING_VIEW_LAYER_SHADOW 11
+/// Deep space, covering the starfield
+#define LANDING_VIEW_LAYER_SPACE 20
+/// The planet seen whole
+#define LANDING_VIEW_LAYER_PLANET 22
+/// Its glow of air
+#define LANDING_VIEW_LAYER_AIR 23
+/// The sky inside its air: one colour, over the planet and under the ground's haze
+#define LANDING_VIEW_LAYER_SKY 24
+/// Haze between the ship and the ground
+#define LANDING_VIEW_LAYER_HAZE 30
+/// Cloud deck and the clouds rushing past
+#define LANDING_VIEW_LAYER_CLOUD 32
+/// Heat of entry over everything
+#define LANDING_VIEW_LAYER_HEAT 40
+
+// How a landing view track gets from one key to the next
+#define LANDING_CURVE_LINEAR 0
+/// Fast, then settling
+#define LANDING_CURVE_OUT 1
+/// Slow, then rushing
+#define LANDING_CURVE_IN 2
+/// Slow at both ends
+#define LANDING_CURVE_BOTH 3
+
+/// The sizes of the whole planet between which its closer-up texture takes over (see chain_detail())
+#define LANDING_PLANET_DETAIL list(list(1.7, 3.3))
+/// The size of the planet under a ship that is flying over it, and the size it comes up from and falls away to
+#define LANDING_HOVER_SIZE 1.5
+#define LANDING_HOVER_FAR 0.08
+
+// Which part of the ground around a berth a call to bake_ground() draws
+#define LANDING_GROUND_ALL 0
+/// Everything but the chunks the hull's own box touches
+#define LANDING_GROUND_AROUND 1
+/// Only those
+#define LANDING_GROUND_UNDER 2
diff --git a/voidcrew/icons/effects/landing_view.dmi b/voidcrew/icons/effects/landing_view.dmi
new file mode 100644
index 00000000000..a83549fd925
Binary files /dev/null and b/voidcrew/icons/effects/landing_view.dmi differ
diff --git a/voidcrew/icons/effects/landing_view_glow.dmi b/voidcrew/icons/effects/landing_view_glow.dmi
new file mode 100644
index 00000000000..42bdcae0bdc
Binary files /dev/null and b/voidcrew/icons/effects/landing_view_glow.dmi differ
diff --git a/voidcrew/modules/landing_animation/landing_animation.dm b/voidcrew/modules/landing_animation/landing_animation.dm
new file mode 100644
index 00000000000..11e582bafca
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_animation.dm
@@ -0,0 +1,979 @@
+/**
+ * # Planet landing and takeoff visuals
+ *
+ * Seen from the ground, a ship docking on a planet used to pop onto its berth. Now a soft shadow of the hull
+ * spreads over the berth during the dock warmup, then the ship itself drops out of the sky and the real hull
+ * replaces it the moment it lands. On takeoff it moves off level, forward and up, and flies away
+ * toward its bow.
+ *
+ * The falling ship is a proxy: one object carrying a picture of the hull, taken from its transit turfs when it
+ * comes into sight, so it is the ship as it really looks, crew and all. Nothing here changes docking: the
+ * warmup, the move and its crush are untouched.
+ *
+ * Visual only. Proxies and shadows are mouse-transparent, not dense, and every path that ends a dock
+ * (arrival, refusal, cancellation, a deleted ship or site) removes them.
+ */
+
+/// The descending ship comes into sight this long before the expected touchdown (deciseconds)
+#define LANDING_PROXY_LEAD (3 SECONDS)
+/// The shadow starts fading in this long before the expected touchdown
+#define LANDING_SHADOW_LEAD (6 SECONDS)
+/// Height the descending ship starts at, in pixels: well out of sight of anyone near the berth, so it flies
+/// in and out of view rather than popping in
+#define LANDING_PROXY_START_HEIGHT 1100
+/// Height of the ship one second before touchdown
+#define LANDING_PROXY_FINAL_HEIGHT 64
+/// Takeoff: forward and up together, slowly at first, then off toward the bow
+#define LAUNCH_LIFT_TIME (1 SECONDS)
+#define LAUNCH_TILT_TIME (1 SECONDS)
+#define LAUNCH_GO_TIME (1.5 SECONDS)
+#define LAUNCH_TILT_HEIGHT 44
+#define LAUNCH_GO_HEIGHT 140
+/// How far the ship creeps toward its bow before it is properly under way
+#define LAUNCH_TILT_CREEP 24
+/// Tiles past the hull's own length it flies before it is removed: off the screen of anyone near the berth
+#define LAUNCH_GO_TILES 30
+/// How far the shadow slides after it, in tiles
+#define LAUNCH_SHADOW_SLIDE_TILES 10
+/// Thruster wash: most puffs per wave (three waves), the chance an engine-end tile throws one, how far they blow
+#define LAUNCH_WASH_PER_WAVE 9
+#define LAUNCH_WASH_CHANCE 100
+#define LAUNCH_WASH_PUSH 1.8
+/// Width of the shadow at its widest, relative to the hull
+#define LANDING_SHADOW_WIDE 1.35
+/// Width of the shadow just before touchdown
+#define LANDING_SHADOW_NEAR 1.15
+/// The shadow's darkness (alpha) when the ship is high up and when it is about to land
+#define LANDING_SHADOW_FAINT 56
+#define LANDING_SHADOW_DARK 100
+/// The layer the proxy draws its ship turfs at. Everything standing on the hull sorts above it.
+#define LANDING_PROXY_TURF_LAYER 2.05
+/// Above everything on a hull tile: the tile's light, multiplied over it in the picture
+#define LANDING_PROXY_LIGHT_LAYER 100
+/// Just above bullet holes and floor clutter, below every object and mob
+#define LANDING_SHADOW_LAYER 2.07
+/// Height the descending ship waits at until the move starts
+#define LANDING_PROXY_HOVER 10
+/// How long the picture takes to give way to the real hull
+#define LANDING_PICTURE_FADE (0.8 SECONDS)
+/// How long the picture covers a landed hull while its lighting is rebuilt
+#define LANDING_LIGHTING_SETTLE (2 SECONDS)
+/// Chance an edge tile kicks up a puff of dust, and the most puffs one landing makes
+#define LANDING_DUST_CHANCE 20
+#define LANDING_DUST_MAX 12
+/// Thruster wash before touchdown: most puffs per wave (three waves), the chance an edge tile throws one, how far they blow
+#define LANDING_WASH_PUFFS 7
+#define LANDING_WASH_CHANCE 35
+#define LANDING_WASH_PUSH 1.5
+/// How hard the screen shakes for those who feel a landing or a takeoff (tiles)
+#define LANDING_SHAKE 0.4
+/// How far from the hull people on the ground feel and hear it land or leave
+#define LANDING_HEAR_RANGE 12
+/// How far from the hull a landing or launch sound stays at full volume, in tiles
+#define LANDING_SOUND_FULL 4
+/// For whole_site sounds: how far they stay at full volume, and how far they fade out to (a whole site and more)
+#define LANDING_SITE_FULL 20
+#define LANDING_SITE_REACH 160
+/// whole_site: everyone at the site, those aboard included; or only those who are not aboard
+#define LANDING_SITE_ALL 1
+#define LANDING_SITE_OUTSIDE 2
+
+/// Running descent for this ship, if any
+/obj/structure/overmap/ship/var/datum/landing_animation/landing_animation
+
+/// Whether docking at this overmap object plays the planet landing. Terrain planets only; outposts,
+/// empty space and flat encounters keep their plain dock.
+/proc/landing_animation_wanted(obj/structure/overmap/site)
+ var/obj/structure/overmap/planet/planet = astype(site, /obj/structure/overmap/planet)
+ return !!planet?.is_terrain_planet()
+
+/**
+ * Starts the descent for a warmup that is about to run. Called by dock() and on_planet_loaded() as they
+ * start their warmup timer.
+ * * site - the overmap object being docked at
+ * * dock_to_use - the berth the hull will land on
+ * * warmup - the warmup length; touchdown is expected one SSshuttle second after it
+ */
+/obj/structure/overmap/ship/proc/start_landing_animation(obj/structure/overmap/site, obj/docking_port/stationary/dock_to_use, warmup)
+ QDEL_NULL(landing_animation)
+ QDEL_NULL(launch_view)
+ if(!shuttle || !dock_to_use || !landing_animation_wanted(site))
+ return
+ landing_animation = new(src, site, dock_to_use, landing_expected_move(warmup + 1 SECONDS) - world.time)
+
+/**
+ * world.time a hull whose move timer runs out in [delay] will actually move. SSshuttle only looks at its ports
+ * once a second, on a fixed beat, so the move comes at the first beat after the timer.
+ */
+/proc/landing_expected_move(delay)
+ // the port counts whole deciseconds left, rounding half a one down to none
+ var/earliest = world.time + delay - 0.5
+ var/beat = SSshuttle.next_fire
+ if(!beat || !SSshuttle.wait)
+ return earliest
+ while(beat < earliest)
+ beat += SSshuttle.wait
+ return beat
+
+/**
+ * Brings the lighting up to date now, not over the next few ticks. A hull that has just moved has every light
+ * and every tile aboard queued for an update, and SSlighting works through that queue a slice at a time, in
+ * ticks the move has already overrun: for a third of a second or more the whole hull draws black.
+ */
+/proc/landing_settle_lighting()
+ // the same three passes as SSlighting.fire(), without its tick limit
+ var/list/queue = SSlighting.current_sources + SSlighting.sources_queue
+ SSlighting.current_sources = list()
+ SSlighting.sources_queue = list()
+ for(var/datum/light_source/source as anything in queue)
+ source.update_corners()
+ if(!QDELETED(source))
+ source.needs_update = LIGHTING_NO_UPDATE
+ queue = SSlighting.corners_queue
+ SSlighting.corners_queue = list()
+ for(var/datum/lighting_corner/corner as anything in queue)
+ corner.needs_update = FALSE
+ corner.update_objects()
+ queue = SSlighting.objects_queue
+ SSlighting.objects_queue = list()
+ for(var/datum/lighting_object/lit as anything in queue)
+ if(QDELETED(lit))
+ continue
+ lit.update()
+ lit.needs_update = FALSE
+
+/**
+ * A takeoff from a planet is about to run its warmup: the engines wind up for the last of it, heard and felt
+ * aboard and around the berth. Called by undock() as it starts its warmup timer.
+ */
+/obj/structure/overmap/ship/proc/start_launch_animation(warmup)
+ if(!shuttle || !landing_animation_wanted(docked))
+ return
+ addtimer(CALLBACK(src, PROC_REF(launch_spool)), max(0, warmup - 2.2 SECONDS))
+
+/obj/structure/overmap/ship/proc/launch_spool()
+ if(state != OVERMAP_SHIP_UNDOCKING || QDELETED(shuttle))
+ return
+ var/obj/docking_port/stationary/berth = shuttle.get_docked()
+ if(!berth || istype(berth, /obj/docking_port/stationary/transit))
+ return
+ var/list/hull_turfs = landing_hull_pairs(shuttle, berth)[1]
+ landing_jolt(hull_turfs, 'voidcrew/sound/effects/landing/spool.ogg', 50, whole_site = LANDING_SITE_ALL)
+ landing_jolt(hull_turfs, null, 0, reach = LANDING_HEAR_RANGE, shake_time = 3 SECONDS, shake_strength = 0.04)
+ // and what the people aboard will see as they climb is made ready
+ QDEL_NULL(launch_view)
+ launch_view = new(shuttle, null, hull_turfs, 0, docked, landing_bow_dir(shuttle, hull_turfs), src)
+
+/// Ends the descent, removing every proxy and the shadow.
+/obj/structure/overmap/ship/proc/end_landing_animation()
+ QDEL_NULL(landing_animation)
+
+/obj/structure/overmap/ship/Destroy()
+ QDEL_NULL(landing_animation)
+ QDEL_NULL(launch_view)
+ QDEL_NULL(hover_view)
+ return ..()
+
+/**
+ * The hull starts to move. This is the touchdown everyone sees: a descent's picture settles on the ground and
+ * covers the real hull until its lighting is rebuilt, and a launch takes its picture of the hull before the
+ * move touches it.
+ */
+/obj/docking_port/mobile/voidcrew/initiate_docking(obj/docking_port/stationary/new_dock, movement_direction, force = FALSE)
+ var/obj/structure/overmap/ship/ship = current_ship
+ if(!ship || !new_dock || move_in_flight())
+ return ..()
+ var/obj/docking_port/stationary/old_dock = get_docked()
+ var/datum/landing_animation/descent
+ var/datum/launch_animation/launch
+ if(ship.state == OVERMAP_SHIP_DOCKING && istype(old_dock, /obj/docking_port/stationary/transit) && !istype(new_dock, /obj/docking_port/stationary/transit) && landing_animation_wanted(ship.docked))
+ var/list/pairs = landing_hull_pairs(src, new_dock)
+ descent = ship.landing_animation
+ descent?.freeze()
+ landing_touchdown(pairs[2], pairs[1], descent)
+ // the crew aboard feel it too, though they are still in transit for the moment
+ landing_jolt(pairs[1], 'voidcrew/sound/effects/landing/touchdown.ogg', 70, shake_strength = LANDING_SHAKE)
+ else if(ship.state == OVERMAP_SHIP_UNDOCKING && old_dock && !istype(old_dock, /obj/docking_port/stationary/transit) && istype(new_dock, /obj/docking_port/stationary/transit) && landing_animation_wanted(ship.undock_origin?.resolve()))
+ launch = new(landing_hull_pairs(src, new_dock)[1], src)
+ // for takeoff(), which is where the hull really moves; the rest of this proc can take several ticks more
+ landing_now = descent
+ launching_now = launch
+ . = ..()
+ if((descent || launch) && . == DOCKING_SUCCESS)
+ landing_settle_lighting()
+ if(launching_now) // the move never happened
+ launching_now = null
+ qdel(launch)
+ landing_now = null
+ if(descent && !QDELETED(descent) && !descent.landed && . == DOCKING_SUCCESS)
+ descent.landed()
+
+/obj/docking_port/mobile/voidcrew
+ /// The descent the move now under way ends, and the launch it starts
+ var/datum/landing_animation/landing_now
+ var/datum/launch_animation/launching_now
+
+/**
+ * The hull moves, all at once, in here. Whatever the people aboard are shown has to change over in this same
+ * call: what follows it in initiate_docking() is spread over several ticks.
+ */
+/obj/docking_port/mobile/voidcrew/takeoff(list/old_turfs, list/new_turfs, list/moved_atoms, rotation, movement_direction, old_dock, area/fallback_area)
+ var/datum/landing_animation/descent = landing_now
+ var/datum/launch_animation/launch = launching_now
+ landing_now = null
+ launching_now = null
+ var/list/planet_turfs
+ var/list/transit_turfs
+ if(launch)
+ // pair the hull's tiles up before they move: afterwards its areas are no longer on the turfs it left
+ planet_turfs = list()
+ transit_turfs = list()
+ for(var/i in 1 to min(length(old_turfs), length(new_turfs)))
+ var/turf/from_turf = old_turfs[i]
+ var/turf/to_turf = new_turfs[i]
+ if(!from_turf || !to_turf)
+ continue
+ if(!istype(from_turf.loc, area_type) || istype(from_turf.loc, /area/shuttle/transit))
+ continue
+ planet_turfs += from_turf
+ transit_turfs += to_turf
+ . = ..()
+ if(descent)
+ // the ripples that warned the ground a hull was coming are under it now. Left for the end of the docking,
+ // several ticks away, they show on top of its decks until then
+ remove_ripples()
+ var/list/light_twins
+ if(launch)
+ // in transit the stars light the hull's edge, where the ground beside it did a moment ago: for now the
+ // space around it casts the ground's light, and the view of the climb lets it go slowly
+ // (see /datum/landing_view/proc/fade_light)
+ light_twins = landing_view_light_twins(transit_turfs, planet_turfs, SIMPLIFY_DEGREES(-rotation))
+ landing_view_blend_light(light_twins, 1)
+ if(launch || descent)
+ // the hull's lights have moved with it: lit again before anyone sees it dark
+ landing_settle_lighting()
+ if(launch)
+ // the same climb for the people aboard, over the ground they just stood on
+ var/obj/structure/overmap/ship/ship = current_ship
+ var/datum/landing_view/ascent/view = ship?.launch_view
+ if(ship && (QDELETED(view) || view.liftoff))
+ QDEL_NULL(ship.launch_view)
+ view = new(src, null, planet_turfs, 0, ship.undock_origin?.resolve(), launch.bow_dir, ship)
+ ship.launch_view = view
+ // this move turns the hull [rotation] degrees from its berth; the view wants the way back
+ view?.lift_off(transit_turfs, planet_turfs, SIMPLIFY_DEGREES(-rotation))
+ if(QDELETED(view) || view.ended)
+ // nobody to bring the stars back slowly: they come back at once
+ landing_view_restore_light(light_twins)
+ else
+ view.light_twins = light_twins
+ launch.lift_off(transit_turfs, planet_turfs, view)
+ if(descent && !QDELETED(descent))
+ descent.landed()
+
+/**
+ * Hull on the ground: dust off the edges, and a jolt for everyone nearby.
+ * * transit_turfs, descent - the hull's turfs in transit in the same order, and its descent, if the people aboard
+ * should see the same dust beside the hull while it is still there
+ */
+/proc/landing_touchdown(list/hull_turfs, list/transit_turfs, datum/landing_animation/descent)
+ landing_dust(hull_turfs, transit_turfs, descent)
+ landing_jolt(hull_turfs, 'voidcrew/sound/effects/landing/touchdown.ogg', 70, whole_site = LANDING_SITE_OUTSIDE)
+ landing_jolt(hull_turfs, null, 0, reach = LANDING_HEAR_RANGE, shake_strength = LANDING_SHAKE)
+
+/**
+ * Shakes the camera of, and plays [sound_file] to, every player on [hull_turfs] and, with [reach], everyone within
+ * that many tiles of the hull on the same level.
+ */
+/proc/landing_jolt(list/hull_turfs, sound_file, volume, reach = 0, shake_time = 3, shake_strength = 0, whole_site = FALSE)
+ if(!length(hull_turfs))
+ return
+ var/list/hull_set = list()
+ var/min_x = INFINITY
+ var/max_x = -INFINITY
+ var/min_y = INFINITY
+ var/max_y = -INFINITY
+ for(var/turf/hull_turf as anything in hull_turfs)
+ hull_set[hull_turf] = TRUE
+ min_x = min(min_x, hull_turf.x)
+ max_x = max(max_x, hull_turf.x)
+ min_y = min(min_y, hull_turf.y)
+ max_y = max(max_y, hull_turf.y)
+ var/turf/first = hull_turfs[1]
+ var/turf/middle = locate(round((min_x + max_x) / 2), round((min_y + max_y) / 2), first.z)
+ // a packed level holds other sites a few tiles away; they neither hear nor feel it
+ var/datum/own_region = map_region_for_turf(first)
+ // ghosts too, as with explosions (SSmobs.clients_by_zlevel only holds living mobs)
+ for(var/mob/listener as anything in GLOB.player_list)
+ var/turf/where = get_turf(listener)
+ if(!where || where.z != first.z)
+ continue
+ if(!hull_set[where])
+ if(map_region_excludes_turf(own_region, where))
+ continue
+ // an engine roar reaches everyone at the site; a jolt only those near enough to feel it
+ if(!whole_site && (!reach || where.x < min_x - reach || where.x > max_x + reach || where.y < min_y - reach || where.y > max_y + reach))
+ continue
+ else if(whole_site == LANDING_SITE_OUTSIDE)
+ continue
+ if(shake_strength)
+ shake_camera(listener, shake_time, shake_strength)
+ if(sound_file)
+ // heard from the nearest part of the hull, not its middle: the falloff is steep, and from the middle of a
+ // big hull someone standing right against it would be a dozen tiles away and hear next to nothing
+ var/turf/source = hull_set[where] ? where : locate(clamp(where.x, min_x, max_x), clamp(where.y, min_y, max_y), first.z)
+ var/full = whole_site ? LANDING_SITE_FULL : LANDING_SOUND_FULL
+ listener.playsound_local(source || middle, sound_file, volume, TRUE, pressure_affected = FALSE, max_distance = whole_site ? LANDING_SITE_REACH : max(reach, 1) + full, falloff_distance = full)
+
+/// A few light puffs of dust kicked out from the hull's edges, with twins in transit for a [descent]'s crew
+/proc/landing_dust(list/hull_turfs, list/transit_turfs, datum/landing_animation/descent)
+ var/list/hull_set = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ hull_set[hull_turf] = TRUE
+ var/list/order = list()
+ for(var/i in 1 to length(hull_turfs))
+ order += i
+ var/puffs = 0
+ for(var/i in shuffle(order))
+ if(puffs >= LANDING_DUST_MAX)
+ break
+ var/turf/hull_turf = hull_turfs[i]
+ for(var/edge_dir in GLOB.cardinals)
+ var/turf/outside = get_step(hull_turf, edge_dir)
+ if(!outside || hull_set[outside] || isclosedturf(outside))
+ continue
+ if(!prob(LANDING_DUST_CHANCE))
+ break
+ var/list/shape = landing_dust_shape()
+ new /obj/effect/temp_visual/landing_dust(outside, edge_dir, 1, shape)
+ descent?.twin_dust(transit_turfs?[i], edge_dir, 1, shape)
+ puffs++
+ break
+
+/// Pairs each hull tile's current turf with the turf it covers on [dock], the same pairing the move uses.
+/// Returns list(current turfs, destination turfs).
+/proc/landing_hull_pairs(obj/docking_port/mobile/shuttle, obj/docking_port/stationary/dock)
+ var/list/from_turfs = shuttle.return_ordered_turfs(shuttle.x, shuttle.y, shuttle.z, shuttle.dir)
+ var/list/to_turfs = shuttle.return_ordered_turfs(dock.x, dock.y, dock.z, dock.dir)
+ var/list/hull_from = list()
+ var/list/hull_to = list()
+ for(var/i in 1 to min(length(from_turfs), length(to_turfs)))
+ var/turf/from_turf = from_turfs[i]
+ var/turf/to_turf = to_turfs[i]
+ if(!from_turf || !to_turf)
+ continue
+ if(!istype(from_turf.loc, shuttle.area_type) || istype(from_turf.loc, /area/shuttle/transit))
+ continue
+ hull_from += from_turf
+ hull_to += to_turf
+ return list(hull_from, hull_to)
+
+/// The rotation, in degrees clockwise, a move from [shuttle]'s heading onto [dock] applies to the hull.
+/proc/landing_rotation(obj/docking_port/mobile/shuttle, obj/docking_port/stationary/dock)
+ if(dock.dir == shuttle.dir)
+ return 0
+ var/rotation = dir2angle(dock.dir) - dir2angle(shuttle.dir)
+ if(rotation % 90)
+ rotation += rotation % 90
+ return SIMPLIFY_DEGREES(rotation)
+
+/**
+ * # Ship proxy
+ *
+ * A still picture of a whole hull, drawn somewhere else: every visible thing on each hull tile, copied as an
+ * overlay at that tile's spot. It is one object, so the whole picture moves as one (separate tiles tweened
+ * separately round to different pixels and open seams between the rows), and it is a picture rather than a
+ * live view, because a hull's lighting is torn down and rebuilt row by row around every move.
+ */
+/obj/effect/abstract/landing_proxy
+ name = ""
+ anchored = TRUE
+ density = FALSE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ // Above the game world and its lighting: the ship is in the air, over everyone, ripples included. On any
+ // lit plane the ground's light at the spot it passes over (lava glow, a dark patch) shows on the hull and
+ // it reads as see-through. It carries its own light instead; see picture().
+ plane = ABOVE_LIGHTING_PLANE
+ layer = LANDING_PROXY_TURF_LAYER
+ // one picture, so each tile's light multiplies only the tile under it
+ appearance_flags = KEEP_TOGETHER | PIXEL_SCALE
+ vis_flags = NONE
+
+/// A launch's picture stands on the hull it shows: it stays on the ground when the hull leaves
+/obj/effect/abstract/landing_proxy/onShuttleMove(turf/newT, turf/oldT, list/movement_force, move_dir, obj/docking_port/stationary/old_dock, obj/docking_port/mobile/moving_dock)
+ return
+
+/**
+ * Draws the hull standing on [sources] as it will stand on [places] (same order, all on one z), turned
+ * [rotation] degrees clockwise. Returns FALSE with nothing to draw.
+ */
+/obj/effect/abstract/landing_proxy/proc/picture(list/sources, list/places, rotation = 0)
+ if(!length(places))
+ return FALSE
+ var/min_x = INFINITY
+ var/max_x = -INFINITY
+ var/min_y = INFINITY
+ var/max_y = -INFINITY
+ for(var/turf/place as anything in places)
+ min_x = min(min_x, place.x)
+ max_x = max(max_x, place.x)
+ min_y = min(min_y, place.y)
+ max_y = max(max_y, place.y)
+ // stand in the middle, so anyone who can see much of the hull can see the picture
+ var/turf/anchor = locate(round((min_x + max_x) / 2), round((min_y + max_y) / 2), places[1].z)
+ if(!anchor)
+ return FALSE
+ abstract_move(anchor)
+ SET_PLANE_IMPLICIT(src, ABOVE_LIGHTING_PLANE)
+ var/matrix/turn = rotation ? matrix().Turn(rotation) : null
+ // One group per world plane, floor first. In the world each plane draws whole over the one below, whatever
+ // the layers; in one picture everything would sort by layer alone, and floor things (cables, catwalks,
+ // blood, all on TOPDOWN_LAYER) would paint over every machine on the game plane.
+ var/list/plane_parts = new /list(ABOVE_GAME_PLANE - FLOOR_PLANE + 1)
+ for(var/rank in 1 to length(plane_parts))
+ plane_parts[rank] = list()
+ var/list/parts = list()
+ for(var/i in 1 to length(places))
+ var/turf/source = sources[i]
+ var/turf/place = places[i]
+ var/offset_w = (place.x - anchor.x) * ICON_SIZE_X
+ var/offset_z = (place.y - anchor.y) * ICON_SIZE_Y
+ var/turf_plane = clamp(PLANE_TO_TRUE(source.plane), FLOOR_PLANE, ABOVE_GAME_PLANE)
+ var/mutable_appearance/floor = new(source)
+ floor.underlays = list() // its lighting; drawn below as a multiply over the whole tile
+ floor.plane = FLOAT_PLANE
+ floor.pixel_w += offset_w
+ floor.pixel_z += offset_z
+ if(turn)
+ floor.transform = turn
+ plane_parts[turf_plane - FLOOR_PLANE + 1] += floor
+ for(var/atom/movable/thing as anything in source)
+ if(thing.invisibility > SEE_INVISIBLE_LIVING || !thing.icon)
+ continue
+ // only what is drawn on the world itself; light glows and other effect planes would paint as images
+ var/true_plane = PLANE_TO_TRUE(thing.plane)
+ if(true_plane < FLOOR_PLANE || true_plane > ABOVE_GAME_PLANE)
+ continue
+ var/mutable_appearance/part = new(thing)
+ part.plane = FLOAT_PLANE
+ part.pixel_w += offset_w
+ part.pixel_z += offset_z
+ if(turn)
+ part.transform = turn
+ plane_parts[true_plane - FLOOR_PLANE + 1] += part
+ for(var/rank in 1 to length(plane_parts))
+ if(!length(plane_parts[rank]))
+ continue
+ var/mutable_appearance/plane_group = new()
+ plane_group.plane = FLOAT_PLANE
+ plane_group.layer = rank
+ plane_group.appearance_flags = KEEP_TOGETHER | PIXEL_SCALE
+ plane_group.overlays = plane_parts[rank]
+ parts += plane_group
+ for(var/i in 1 to length(places))
+ var/turf/source = sources[i]
+ var/turf/place = places[i]
+ var/offset_w = (place.x - anchor.x) * ICON_SIZE_X
+ var/offset_z = (place.y - anchor.y) * ICON_SIZE_Y
+ // the tile's own light as the hull has it now, laid over the tile the way the lighting plane would
+ // (rooms lit by their area as a whole, or not lit at all, have no darkness of their own to carry)
+ var/area/source_area = source.loc
+ var/mutable_appearance/light = source.lighting_object?.current_underlay
+ if(light && source_area.static_lighting && !source_area.base_lighting_alpha)
+ var/mutable_appearance/tile_light = new(light)
+ tile_light.plane = FLOAT_PLANE
+ tile_light.layer = LANDING_PROXY_LIGHT_LAYER
+ tile_light.blend_mode = BLEND_MULTIPLY
+ tile_light.pixel_w += offset_w
+ tile_light.pixel_z += offset_z
+ if(turn)
+ tile_light.transform = turn
+ parts += tile_light
+ overlays = parts
+ return TRUE
+
+/**
+ * # Ship shadow
+ *
+ * The hull's outline in soft black on the ground. One object: a black square overlay per hull tile, kept
+ * together and blurred, so scaling it spreads the whole outline about the hull's middle.
+ */
+/obj/effect/abstract/landing_shadow
+ name = ""
+ anchored = TRUE
+ density = FALSE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ // Game plane, under everything standing there. The floor plane would add it to the light mask and
+ // light up ground that is meant to stay dark.
+ plane = GAME_PLANE
+ layer = LANDING_SHADOW_LAYER
+ appearance_flags = KEEP_TOGETHER | PIXEL_SCALE
+ alpha = 0
+ vis_flags = NONE
+
+/// Builds the outline from [hull_turfs] (the turfs the hull covers, all on one z). Returns FALSE with nothing to draw.
+/obj/effect/abstract/landing_shadow/proc/outline(list/hull_turfs)
+ if(!length(hull_turfs))
+ return FALSE
+ var/min_x = INFINITY
+ var/max_x = -INFINITY
+ var/min_y = INFINITY
+ var/max_y = -INFINITY
+ for(var/turf/hull_turf as anything in hull_turfs)
+ min_x = min(min_x, hull_turf.x)
+ max_x = max(max_x, hull_turf.x)
+ min_y = min(min_y, hull_turf.y)
+ max_y = max(max_y, hull_turf.y)
+ // The middle of the bounding box, in tiles, which the shadow spreads and shrinks about
+ var/mid_x = (min_x + max_x) / 2
+ var/mid_y = (min_y + max_y) / 2
+ var/anchor_x = round(mid_x)
+ var/anchor_y = round(mid_y)
+ var/turf/anchor = locate(anchor_x, anchor_y, hull_turfs[1].z)
+ if(!anchor)
+ return FALSE
+ abstract_move(anchor)
+ SET_PLANE_IMPLICIT(src, GAME_PLANE)
+ // Pivot on the box's middle: transforms scale about our own tile's centre, so shift that onto it
+ pixel_w = (mid_x - anchor_x) * ICON_SIZE_X
+ pixel_z = (mid_y - anchor_y) * ICON_SIZE_Y
+ var/list/squares = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ var/mutable_appearance/square = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR)
+ square.color = COLOR_BLACK
+ square.pixel_w = (hull_turf.x - mid_x) * ICON_SIZE_X
+ square.pixel_z = (hull_turf.y - mid_y) * ICON_SIZE_Y
+ squares += square
+ overlays = squares
+ add_filter("landing_shadow_blur", 1, gauss_blur_filter(size = 8))
+ return TRUE
+
+/// A puff of dust thrown off a hull's edge as it lands or lifts off, drifting away from the hull
+/obj/effect/temp_visual/landing_dust
+ name = ""
+ icon = 'icons/effects/96x96.dmi'
+ icon_state = "smoke"
+ color = "#c9b79c"
+ // over a climbing ship as well
+ plane = ABOVE_LIGHTING_PLANE
+ layer = LANDING_PROXY_LIGHT_LAYER + 1
+ pixel_w = -32
+ pixel_z = -32
+ alpha = 0
+ duration = 2.4 SECONDS
+
+/// Rolls the numbers one puff is drawn with, so its twin in transit space can be drawn exactly alike
+/proc/landing_dust_shape(push = 1)
+ return list(round(rand(14, 28) * push), rand(-6, 6), rand(-6, 6), push > 1 ? rand(110, 150) : rand(80, 120))
+
+/**
+ * * push - scales how far it is blown: thruster wash drifts further than a settling hull's dust
+ * * shape - the numbers from landing_dust_shape() to draw it with; rolled here if not given
+ */
+/obj/effect/temp_visual/landing_dust/Initialize(mapload, push_dir = NORTH, push = 1, list/shape)
+ . = ..()
+ SET_PLANE_IMPLICIT(src, ABOVE_LIGHTING_PLANE)
+ shape ||= landing_dust_shape(push)
+ var/drift = shape[1]
+ if(push > 1) // thruster wash: as much air as dust, paler so it shows on sand too
+ color = "#e4ded2"
+ var/drift_w = (push_dir & EAST) ? drift : ((push_dir & WEST) ? -drift : shape[2])
+ var/drift_z = (push_dir & NORTH) ? drift : ((push_dir & SOUTH) ? -drift : shape[3])
+ transform = matrix().Scale(0.45)
+ animate(src, alpha = shape[4], transform = matrix().Scale(0.7), time = 0.3 SECONDS, easing = SINE_EASING | EASE_OUT)
+ animate(alpha = 0, transform = matrix().Scale(1.1), pixel_w = pixel_w + drift_w, pixel_z = pixel_z + drift_z, time = duration - 0.3 SECONDS, easing = SINE_EASING | EASE_OUT)
+
+/**
+ * # Descent
+ *
+ * Owned by the ship for the length of one planet dock warmup. Removed by the hull's move (takeoff()), or by
+ * its own watch the moment the ship stops docking at this site.
+ */
+/datum/landing_animation
+ /// The ship coming down
+ var/obj/structure/overmap/ship/ship
+ /// Where it is docking
+ var/datum/weakref/site_ref
+ /// The hull's turfs in transit, in the same order as [berth_turfs]
+ var/list/hull_turfs
+ /// The berth turfs each hull tile lands on
+ var/list/berth_turfs
+ /// Clockwise degrees the landing turns the hull
+ var/rotation = 0
+ /// world.time the hull is expected to touch down
+ var/touchdown_time
+ /// world.time after which the descent gives up waiting for the hull
+ var/give_up_time
+ var/obj/effect/abstract/landing_shadow/shadow
+ /// The falling hull
+ var/obj/effect/abstract/landing_proxy/proxy
+ /// client -> the images that hide the picture and the shadow from them: the crew aboard, who would otherwise
+ /// see a still copy of their ship, themselves included, and its shadow over the real one for a moment after landing
+ var/list/hidden_from = list()
+ /// TRUE once the move has started and the picture is on the ground
+ var/frozen = FALSE
+ /// TRUE once the hull is down and the picture only covers it while its lighting catches up
+ var/landed = FALSE
+
+/datum/landing_animation/New(obj/structure/overmap/ship/ship, obj/structure/overmap/site, obj/docking_port/stationary/dock, until_touchdown)
+ . = ..()
+ src.ship = ship
+ site_ref = WEAKREF(site)
+ var/list/pairs = landing_hull_pairs(ship.shuttle, dock)
+ hull_turfs = pairs[1]
+ berth_turfs = pairs[2]
+ rotation = landing_rotation(ship.shuttle, dock)
+ touchdown_time = world.time + until_touchdown
+ give_up_time = touchdown_time + 60 SECONDS
+ // the planet may already be under the ship: the descent starts from there
+ inside_view = new(ship.shuttle, hull_turfs, berth_turfs, rotation, site, touchdown_time, ship.take_hover())
+ addtimer(CALLBACK(src, PROC_REF(show_shadow)), max(0, until_touchdown - LANDING_SHADOW_LEAD), TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(show_proxies)), max(0, until_touchdown - LANDING_PROXY_LEAD), TIMER_DELETE_ME)
+ for(var/lead in list(1.4 SECONDS, 0.9 SECONDS, 0.4 SECONDS))
+ addtimer(CALLBACK(src, PROC_REF(thruster_wash)), max(0, until_touchdown - lead), TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(watch)), 0.5 SECONDS, TIMER_DELETE_ME | TIMER_LOOP)
+
+/datum/landing_animation/Destroy(force)
+ QDEL_NULL(shadow)
+ QDEL_NULL(inside_view)
+ for(var/client/crew_client as anything in hidden_from)
+ crew_client?.images -= hidden_from[crew_client]
+ hidden_from = null
+ QDEL_NULL(proxy)
+ hull_turfs = null
+ berth_turfs = null
+ if(ship?.landing_animation == src)
+ ship.landing_animation = null
+ ship = null
+ return ..()
+
+/// Ends the descent when the dock it belongs to is no longer happening
+/datum/landing_animation/proc/watch()
+ if(landed)
+ return
+ var/obj/structure/overmap/site = site_ref?.resolve()
+ if(QDELETED(ship) || QDELETED(ship.shuttle) || !site || ship.state != OVERMAP_SHIP_DOCKING || ship.docked != site || world.time > give_up_time)
+ // the people aboard see the planet fade back into space rather than vanish
+ inside_view?.fade_away()
+ inside_view = null
+ if(!QDELETED(ship))
+ // and if the ship is still over it, it comes back up under them
+ addtimer(CALLBACK(ship, TYPE_PROC_REF(/obj/structure/overmap/ship, update_hover_view)), 1.3 SECONDS)
+ qdel(src)
+
+/// The hull has started to move onto the berth: the picture is on the ground now, and stays put.
+/datum/landing_animation/proc/freeze()
+ if(frozen)
+ return
+ frozen = TRUE
+ inside_view?.touchdown()
+ var/list/aboard = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ aboard[hull_turf] = TRUE
+ // every player aboard, ghosts included (they are not in SSmobs.clients_by_zlevel)
+ var/list/client/crew_clients = list()
+ for(var/mob/crew as anything in GLOB.player_list)
+ if(crew.client && aboard[get_turf(crew)])
+ crew_clients += crew.client
+ // what the people on the ground are shown lies on the berth, and the hull is about to stand on it: the
+ // people aboard would see it laid over their own decks
+ var/list/atom/movable/cover = list()
+ if(shadow) // under the hull now; let its blurred rim go gently
+ animate(shadow, alpha = 0, time = 0.4 SECONDS)
+ QDEL_IN(shadow, 0.4 SECONDS)
+ cover += shadow
+ shadow = null
+ if(proxy)
+ animate(proxy, pixel_z = 0, time = 0.2 SECONDS, easing = QUAD_EASING | EASE_IN)
+ cover += proxy
+ for(var/atom/movable/covering as anything in cover)
+ for(var/client/crew_client as anything in crew_clients)
+ var/image/hide = image(loc = covering)
+ hide.override = TRUE
+ crew_client.images += hide
+ LAZYADD(hidden_from[crew_client], hide)
+
+/// The hull is down. The picture covers it a moment longer while its lighting is rebuilt, then goes.
+/datum/landing_animation/proc/landed()
+ if(ship?.landing_animation == src)
+ ship.landing_animation = null
+ landed = TRUE
+ inside_view?.landed()
+ addtimer(CALLBACK(src, PROC_REF(fade_out)), LANDING_LIGHTING_SETTLE, TIMER_DELETE_ME)
+
+/// The real hull is lit again: the picture gives way to it
+/datum/landing_animation/proc/fade_out()
+ if(proxy)
+ animate(proxy, alpha = 0, time = LANDING_PICTURE_FADE)
+ // a hard reference: QDEL_IN keeps only a weakref past a second, and nothing else holds this datum by now
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel), src), LANDING_PICTURE_FADE)
+
+/datum/landing_animation/proc/show_shadow()
+ if(!length(berth_turfs) || frozen || shadow)
+ return
+ shadow = new(berth_turfs[1])
+ if(!shadow.outline(berth_turfs))
+ QDEL_NULL(shadow)
+ return
+ // engines heard on the ground before the ship is in sight; the crew aboard hear nothing new
+ landing_jolt(berth_turfs, 'voidcrew/sound/effects/landing/approach.ogg', 50, whole_site = LANDING_SITE_OUTSIDE)
+ var/time_left = max(1, touchdown_time - world.time)
+ var/fade_in = min(1.5 SECONDS, time_left / 4)
+ var/spread_end = max(0, time_left - LANDING_PROXY_LEAD - fade_in)
+ shadow.transform = matrix().Scale(LANDING_SHADOW_WIDE)
+ animate(shadow, alpha = LANDING_SHADOW_FAINT, time = fade_in)
+ animate(time = max(1, spread_end))
+ animate(transform = matrix().Scale(LANDING_SHADOW_NEAR), alpha = 80, time = min(LANDING_PROXY_LEAD, time_left) * 2 / 3, easing = SINE_EASING)
+ animate(transform = matrix(), alpha = LANDING_SHADOW_DARK, time = min(LANDING_PROXY_LEAD, time_left) / 3, easing = SINE_EASING | EASE_OUT)
+
+/**
+ * The thrusters reach the ground in the last moments: dust blown out from under the hull's edges. Every puff on
+ * the berth has a twin in transit space beside the hull, drawn alike, so the people aboard see the same dust
+ * before the hull moves as after.
+ */
+/datum/landing_animation/proc/thruster_wash()
+ if(frozen || !length(berth_turfs))
+ return
+ var/list/berth_set = list()
+ for(var/turf/berth_turf as anything in berth_turfs)
+ berth_set[berth_turf] = TRUE
+ var/list/order = list()
+ for(var/i in 1 to length(berth_turfs))
+ order += i
+ var/puffs = 0
+ for(var/i in shuffle(order))
+ if(puffs >= LANDING_WASH_PUFFS)
+ break
+ var/turf/berth_turf = berth_turfs[i]
+ for(var/edge_dir in shuffle(GLOB.cardinals.Copy()))
+ var/turf/outside = get_step(berth_turf, edge_dir)
+ if(!outside || berth_set[outside] || isclosedturf(outside))
+ continue
+ if(!prob(LANDING_WASH_CHANCE))
+ break
+ var/list/shape = landing_dust_shape(LANDING_WASH_PUSH)
+ new /obj/effect/temp_visual/landing_dust(outside, edge_dir, LANDING_WASH_PUSH, shape)
+ twin_dust(hull_turfs[i], edge_dir, LANDING_WASH_PUSH, shape)
+ puffs++
+ break
+
+/// The twin, beside the hull in transit, of a puff of dust thrown from the [edge_dir] side of a berth tile
+/datum/landing_animation/proc/twin_dust(turf/hull_turf, edge_dir, push, list/shape)
+ inside_view?.twin_dust(hull_turf, edge_dir, push, shape)
+
+/datum/landing_animation/proc/show_proxies()
+ if(!length(hull_turfs) || frozen || proxy)
+ return
+ proxy = new(berth_turfs[1])
+ if(!proxy.picture(hull_turfs, berth_turfs, rotation))
+ QDEL_NULL(proxy)
+ return
+ var/time_left = max(1, touchdown_time - world.time)
+ var/high_part = time_left * 2 / 3
+ proxy.pixel_z = LANDING_PROXY_START_HEIGHT
+ animate(proxy, pixel_z = LANDING_PROXY_FINAL_HEIGHT, time = high_part, easing = QUAD_EASING | EASE_OUT)
+ // it hovers just off the ground until the move actually starts, which is when it touches down
+ animate(pixel_z = LANDING_PROXY_HOVER, time = time_left - high_part, easing = SINE_EASING | EASE_OUT)
+
+/**
+ * # Takeoff
+ *
+ * The hull has just left the berth for transit. A picture of it moves off level, forward and up, blowing dust
+ * out from under its engine end, and flies off toward its bow, solid all the way, until it
+ * is off the screen. Its shadow stays on the berth, then slides after it and pales. Then everything deletes
+ * itself.
+ */
+/datum/launch_animation
+ var/obj/effect/abstract/landing_shadow/shadow
+ /// The leaving hull
+ var/obj/effect/abstract/landing_proxy/proxy
+ /// The berth turfs the hull is leaving
+ var/list/berth_turfs
+ /// The way the ship's bow points (a cardinal): away from its engines
+ var/bow_dir = NORTH
+
+/// Built just before [shuttle] leaves [hull_turfs]: a picture of it, standing on it
+/datum/launch_animation/New(list/hull_turfs, obj/docking_port/mobile/shuttle)
+ . = ..()
+ berth_turfs = hull_turfs
+ if(!length(hull_turfs))
+ return
+ bow_dir = landing_bow_dir(shuttle, hull_turfs)
+ proxy = new(hull_turfs[1])
+ if(!proxy.picture(hull_turfs, hull_turfs))
+ QDEL_NULL(proxy)
+
+/// The hull is gone (it now stands on [hull_turfs], in transit): the picture flies off and its shadow follows
+/**
+ * * hull_turfs, planet_turfs - where the hull stands now, in transit, and the berth turfs it left, in the same order
+ * * view - what the people aboard see, for the dust they should see too
+ */
+/datum/launch_animation/proc/lift_off(list/hull_turfs, list/planet_turfs, datum/landing_view/view)
+ // felt aboard whatever happens on the ground; the view plays the engines for them
+ landing_jolt(hull_turfs, null, 0, shake_strength = LANDING_SHAKE)
+ if(!proxy)
+ qdel(src)
+ return
+ var/bow_x = (bow_dir & EAST) ? 1 : ((bow_dir & WEST) ? -1 : 0)
+ var/bow_y = (bow_dir & NORTH) ? 1 : ((bow_dir & SOUTH) ? -1 : 0)
+ // the hull's length along its bow, for how far it has to fly
+ var/min_along = INFINITY
+ var/max_along = -INFINITY
+ for(var/turf/berth_turf as anything in berth_turfs)
+ var/along = berth_turf.x * bow_x + berth_turf.y * bow_y
+ min_along = min(min_along, along)
+ max_along = max(max_along, along)
+ var/length_tiles = max_along - min_along + 1
+ // Level the whole way: forward and up together, gathering speed toward the bow. No turning or shrinking: some things
+ // aboard (railings among them) are drawn apart from the hull's picture and would stay square while it turned.
+ var/head_x = bow_x
+ var/head_y = bow_y || (bow_x ? 0 : 1)
+ var/fly = (length_tiles + LAUNCH_GO_TILES) * ICON_SIZE_X
+ // 1. forward and up together, slowly at first
+ animate(proxy, pixel_w = round(head_x * LAUNCH_TILT_CREEP), pixel_z = LAUNCH_TILT_HEIGHT + round(head_y * LAUNCH_TILT_CREEP), time = LAUNCH_LIFT_TIME + LAUNCH_TILT_TIME, easing = SINE_EASING | EASE_IN)
+ // 2. off toward the bow, still climbing; solid until it is gone from view
+ animate(pixel_w = round(head_x * fly), pixel_z = LAUNCH_GO_HEIGHT + round(head_y * fly), time = LAUNCH_GO_TIME, easing = QUAD_EASING | EASE_IN)
+ landing_wash(planet_turfs, bow_dir, hull_turfs, view)
+ landing_jolt(berth_turfs, 'voidcrew/sound/effects/landing/liftoff_outside.ogg', 80, whole_site = LANDING_SITE_OUTSIDE)
+ landing_jolt(berth_turfs, null, 0, reach = LANDING_HEAR_RANGE, shake_strength = LANDING_SHAKE)
+ shadow = new(berth_turfs[1])
+ if(shadow.outline(berth_turfs))
+ var/slide = LAUNCH_SHADOW_SLIDE_TILES * ICON_SIZE_X
+ shadow.alpha = LANDING_SHADOW_DARK
+ // slides after the ship as it moves off, and pales
+ animate(shadow, pixel_w = round(head_x * LAUNCH_TILT_CREEP), pixel_z = round(head_y * LAUNCH_TILT_CREEP), time = LAUNCH_LIFT_TIME + LAUNCH_TILT_TIME, easing = SINE_EASING | EASE_IN)
+ animate(pixel_w = round(head_x * slide), pixel_z = round(head_y * slide), time = LAUNCH_GO_TIME, easing = QUAD_EASING | EASE_IN)
+ // pales on its own curve, from the moment it starts to move off, so it is gone before the ship is
+ animate(shadow, time = LAUNCH_LIFT_TIME, flags = ANIMATION_PARALLEL)
+ animate(alpha = 0, time = LAUNCH_TILT_TIME + LAUNCH_GO_TIME * 0.6, easing = SINE_EASING)
+ else
+ QDEL_NULL(shadow)
+ // a hard reference: QDEL_IN keeps only a weakref past a second, and nothing else holds this datum, so it
+ // would be garbage collected without Destroy() and leave its picture and shadow on the map
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel), src), LAUNCH_LIFT_TIME + LAUNCH_TILT_TIME + LAUNCH_GO_TIME + 0.2 SECONDS)
+
+/**
+ * The way a hull's bow points: away from the middle of its engines, as a cardinal. A hull with no engines, or
+ * engines dead in its middle, leaves straight up the screen.
+ */
+/proc/landing_bow_dir(obj/docking_port/mobile/shuttle, list/hull_turfs)
+ if(!shuttle || !length(shuttle.engine_list) || !length(hull_turfs))
+ return NORTH
+ var/hull_x = 0
+ var/hull_y = 0
+ for(var/turf/hull_turf as anything in hull_turfs)
+ hull_x += hull_turf.x
+ hull_y += hull_turf.y
+ hull_x /= length(hull_turfs)
+ hull_y /= length(hull_turfs)
+ var/engine_x = 0
+ var/engine_y = 0
+ var/engines = 0
+ for(var/obj/machinery/power/shuttle_engine/engine as anything in shuttle.engine_list)
+ var/turf/engine_turf = get_turf(engine)
+ if(!engine_turf || engine_turf.z != hull_turfs[1].z)
+ continue
+ engine_x += engine_turf.x
+ engine_y += engine_turf.y
+ engines++
+ if(!engines)
+ return NORTH
+ var/away_x = hull_x - engine_x / engines
+ var/away_y = hull_y - engine_y / engines
+ if(abs(away_x) < 0.5 && abs(away_y) < 0.5)
+ return NORTH
+ if(abs(away_x) > abs(away_y))
+ return away_x > 0 ? EAST : WEST
+ return away_y > 0 ? NORTH : SOUTH
+
+/// Thruster wash: a few waves of dust blown out from under a lifting hull, most of it at its engine end
+/**
+ * * transit_turfs, view - the hull's turfs in transit, in the same order as hull_turfs, and what the people aboard
+ * see: every puff then has a twin beside the hull in transit
+ */
+/proc/landing_wash(list/hull_turfs, bow_dir, list/transit_turfs, datum/landing_view/view)
+ landing_wash_wave(hull_turfs, bow_dir, transit_turfs, view)
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(landing_wash_wave), hull_turfs.Copy(), bow_dir, transit_turfs?.Copy(), view), 0.35 SECONDS)
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(landing_wash_wave), hull_turfs.Copy(), bow_dir, transit_turfs?.Copy(), view), 0.7 SECONDS)
+
+/proc/landing_wash_wave(list/hull_turfs, bow_dir, list/transit_turfs, datum/landing_view/view)
+ var/bow_x = (bow_dir & EAST) ? 1 : ((bow_dir & WEST) ? -1 : 0)
+ var/bow_y = (bow_dir & NORTH) ? 1 : ((bow_dir & SOUTH) ? -1 : 0)
+ var/list/hull_set = list()
+ var/min_along = INFINITY
+ var/max_along = -INFINITY
+ var/list/order = list()
+ for(var/i in 1 to length(hull_turfs))
+ var/turf/hull_turf = hull_turfs[i]
+ order += i
+ hull_set[hull_turf] = TRUE
+ var/along = hull_turf.x * bow_x + hull_turf.y * bow_y
+ min_along = min(min_along, along)
+ max_along = max(max_along, along)
+ var/span = max(1, max_along - min_along)
+ var/puffs = 0
+ if(QDELETED(view))
+ view = null
+ for(var/i in shuffle(order))
+ if(puffs >= LAUNCH_WASH_PER_WAVE)
+ break
+ var/turf/hull_turf = hull_turfs[i]
+ // 0 at the bow, 1 at the engines
+ var/engine_end = (max_along - (hull_turf.x * bow_x + hull_turf.y * bow_y)) / span
+ if(!prob(LAUNCH_WASH_CHANCE * engine_end * engine_end))
+ continue
+ for(var/edge_dir in shuffle(GLOB.cardinals.Copy()))
+ if(edge_dir == bow_dir)
+ continue
+ var/turf/outside = get_step(hull_turf, edge_dir)
+ if(!outside || hull_set[outside] || isclosedturf(outside))
+ continue
+ var/list/shape = landing_dust_shape(LAUNCH_WASH_PUSH)
+ new /obj/effect/temp_visual/landing_dust(outside, edge_dir, LAUNCH_WASH_PUSH, shape)
+ view?.twin_dust(transit_turfs?[i], edge_dir, LAUNCH_WASH_PUSH, shape)
+ puffs++
+ break
+
+/datum/launch_animation/Destroy(force)
+ QDEL_NULL(shadow)
+ QDEL_NULL(proxy)
+ berth_turfs = null
+ return ..()
+
+#undef LANDING_PROXY_LEAD
+#undef LANDING_SHADOW_LEAD
+#undef LANDING_PROXY_START_HEIGHT
+#undef LANDING_PROXY_FINAL_HEIGHT
+#undef LAUNCH_LIFT_TIME
+#undef LAUNCH_TILT_TIME
+#undef LAUNCH_GO_TIME
+#undef LAUNCH_TILT_HEIGHT
+#undef LAUNCH_GO_HEIGHT
+#undef LAUNCH_TILT_CREEP
+#undef LAUNCH_GO_TILES
+#undef LAUNCH_SHADOW_SLIDE_TILES
+#undef LAUNCH_WASH_PER_WAVE
+#undef LAUNCH_WASH_CHANCE
+#undef LAUNCH_WASH_PUSH
+#undef LANDING_SHADOW_WIDE
+#undef LANDING_SHADOW_NEAR
+#undef LANDING_SHADOW_FAINT
+#undef LANDING_SHADOW_DARK
+#undef LANDING_PROXY_TURF_LAYER
+#undef LANDING_PROXY_LIGHT_LAYER
+#undef LANDING_SHADOW_LAYER
+#undef LANDING_LIGHTING_SETTLE
+#undef LANDING_PROXY_HOVER
+#undef LANDING_PICTURE_FADE
+#undef LANDING_DUST_CHANCE
+#undef LANDING_DUST_MAX
+#undef LANDING_SHAKE
+#undef LANDING_WASH_PUFFS
+#undef LANDING_WASH_CHANCE
+#undef LANDING_WASH_PUSH
+#undef LANDING_HEAR_RANGE
+#undef LANDING_SOUND_FULL
+#undef LANDING_SITE_FULL
+#undef LANDING_SITE_REACH
+#undef LANDING_SITE_ALL
+#undef LANDING_SITE_OUTSIDE
diff --git a/voidcrew/modules/landing_animation/landing_view.dm b/voidcrew/modules/landing_animation/landing_view.dm
new file mode 100644
index 00000000000..0c82f54341e
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view.dm
@@ -0,0 +1,895 @@
+/**
+ * # Landing view
+ *
+ * What the people aboard see around their hull while it lands on a planet or leaves one. The hull spends the
+ * whole manoeuvre in transit space, so without this they watch hyperspace until the ground appears under them.
+ *
+ * Two kinds of thing are drawn, both on LANDING_VIEW_PLANE (see landing_view_planes.dm for how it is cut to
+ * what a viewer can see):
+ *
+ * - The sky: the planet seen whole, its air, clouds. Far away, so it does not move when a viewer walks about.
+ * Screen objects, shared by every viewer, held by one home object in each viewer's screen.
+ * - World pictures: the real terrain around the berth, lit as it is lit, scaled about the middle of the hull,
+ * and the hull's shadow on it. They have to stay put against the hull as viewers walk, and anything standing
+ * on a turf is only drawn for people who can see that turf, so each viewer gets them as images standing on
+ * the turf under their own eye, shifted back to the hull's middle and moved along when they move.
+ *
+ * Motion is described once, as tracks over world.time, and sampled into short straight animation steps for
+ * whoever is watching. Someone who starts watching halfway through gets the rest of the same motion.
+ *
+ * Visual only. Nothing here can be clicked, nothing blocks, and every way a landing or a takeoff can end
+ * removes it.
+ */
+
+/// Length of one straight step of a sampled track
+#define LANDING_VIEW_STEP (0.2 SECONDS)
+/// How often the list of viewers is brought up to date
+#define LANDING_VIEW_SYNC (0.5 SECONDS)
+/// How long the view takes to fade away when its manoeuvre is called off
+#define LANDING_VIEW_FADE (1.2 SECONDS)
+/// How many steps the light on the hull's edge is changed in
+#define LANDING_VIEW_LIGHT_STEPS 8
+/// How many chunks of a picture that cannot be seen yet a viewer is handed in one tick
+#define LANDING_VIEW_HANDOVER 12
+/// How far ahead a viewer's chunks are picked for
+#define LANDING_VIEW_AHEAD (1.5 SECONDS)
+/// Tiles past the edge of a viewer's screen their chunks cover: a shaking camera, a step half made
+#define LANDING_VIEW_MARGIN 1.5
+/// And how much further off than that a chunk has to be before it is taken back
+#define LANDING_VIEW_KEEP 3
+
+/**
+ * One value over time: keys of (world.time, value), each reached along a curve from the key before.
+ */
+/datum/landing_track
+ var/list/times = list()
+ var/list/values = list()
+ var/list/curves = list()
+
+/datum/landing_track/proc/mark(time, value, curve = LANDING_CURVE_LINEAR)
+ times += time
+ values += value
+ curves += curve
+ return src
+
+/// The value at [time]; held at the first key before it and at the last key after it
+/datum/landing_track/proc/at(time)
+ var/count = length(times)
+ if(!count)
+ return 0
+ if(time <= times[1])
+ return values[1]
+ if(time >= times[count])
+ return values[count]
+ for(var/i in 2 to count)
+ if(time > times[i])
+ continue
+ var/span = times[i] - times[i - 1]
+ if(span <= 0)
+ return values[i]
+ var/along = (time - times[i - 1]) / span
+ switch(curves[i])
+ if(LANDING_CURVE_OUT)
+ along = 1 - (1 - along) ** 2
+ if(LANDING_CURVE_IN)
+ along = along ** 2
+ if(LANDING_CURVE_BOTH)
+ along = along * along * (3 - 2 * along)
+ return values[i - 1] + (values[i] - values[i - 1]) * along
+ return values[count]
+
+/datum/landing_track/proc/end_time()
+ return length(times) ? times[length(times)] : 0
+
+/**
+ * One thing the view shows, and how it moves: its size, its opacity and how far it has slid, each a track.
+ *
+ * Either a piece of sky (one screen object everyone watching shares) or a world picture (the ground, the
+ * hull's shadow on it: an image per viewer, see /datum/landing_view).
+ */
+/datum/landing_view_piece
+ /// Size, 1 = as drawn
+ var/datum/landing_track/scale = new
+ /// 0-255
+ var/datum/landing_track/alpha = new
+ /// How far it has slid away: tiles of the picture for a world picture, pixels for a piece of sky
+ var/datum/landing_track/slide_x = new
+ var/datum/landing_track/slide_y = new
+ /// Another piece's size track this one's size is multiplied by: a shadow lying on ground that is itself scaled
+ var/datum/landing_track/scale_with
+ /// And a plain number it is multiplied by: a closer-up texture of the same thing is drawn that much smaller
+ var/scale_factor = 1
+ /// Clockwise degrees it is turned, for a hull that lands turned
+ var/turn = 0
+ /// Sky: the screen object
+ var/atom/movable/screen/landing_view_sky/sky
+ /**
+ * World picture: its parts, each a list(look, offset w, offset z, opacity 0-1, reach): what it shows, where
+ * its middle lies from the hull's middle in pixels, and how far it reaches from that middle in tiles (0: no
+ * telling, everyone holds it). An overlay's offset is not scaled with its parent, so a big picture cannot be
+ * one scaled appearance; every part is scaled and moved on its own to the same effect. Null until it is ready.
+ */
+ var/list/parts
+ /// World picture: TRUE while viewers hold it
+ var/shown = FALSE
+ /// World picture: TRUE once its taking back is booked, and once its handing over is
+ var/dropping = FALSE
+ var/give_booked = FALSE
+ /**
+ * World picture: the smallest size it is ever seen at, if its parts are only handed to the viewers whose
+ * screen they are on. A picture of real tiles costs a client its frame rate by the tile, seen or not.
+ * 0: every viewer holds every part.
+ */
+ var/cull_from = 0
+ /// World picture: TRUE while it is handed out ahead of its motion being known: clear, and still
+ var/held_back = FALSE
+ /// World picture: world.time before which it is not handed to viewers, and after which it is taken back.
+ /// A picture nobody can see yet still costs every viewer its drawing.
+ var/give_at = 0
+ var/drop_at = INFINITY
+
+/datum/landing_view_piece/Destroy(force)
+ QDEL_NULL(sky)
+ parts = null
+ return ..()
+
+/datum/landing_view_piece/proc/end_time()
+ return max(scale.end_time(), alpha.end_time(), slide_x.end_time(), slide_y.end_time(), scale_with ? scale_with.end_time() : 0)
+
+/// list(size, alpha, slide x, slide y) at [time]
+/datum/landing_view_piece/proc/state_at(time)
+ var/size = (length(scale.times) ? scale.at(time) : 1) * scale_factor
+ if(scale_with)
+ size *= scale_with.at(time)
+ return list(size, length(alpha.times) ? alpha.at(time) : 255, slide_x.at(time), slide_y.at(time))
+
+/// The transform for a part whose middle lies [off_w], [off_z] pixels from the middle of the whole
+/datum/landing_view_piece/proc/matrix_of(list/state, off_w = 0, off_z = 0)
+ var/size = state[1]
+ var/matrix/placed = matrix()
+ if(turn)
+ placed.Turn(turn)
+ placed.Scale(size)
+ // it slides away, so it is drawn moved the other way; the ground at the size it is drawn
+ var/unit = sky ? 1 : ICON_SIZE_X * size
+ var/shift_w = off_w * size - state[3] * unit
+ var/shift_z = off_z * size - state[4] * unit
+ if(shift_w || shift_z)
+ if(turn)
+ var/turned_w = shift_w * cos(turn) + shift_z * sin(turn)
+ shift_z = -shift_w * sin(turn) + shift_z * cos(turn)
+ shift_w = turned_w
+ placed.Translate(shift_w, shift_z)
+ return placed
+
+/// Every moment the motion has to pass through from [now] on: a steady beat, and each key of each track
+/datum/landing_view_piece/proc/sample_times(now)
+ var/end = end_time()
+ var/list/moments = list()
+ for(var/beat = now + LANDING_VIEW_STEP, beat < end, beat += LANDING_VIEW_STEP)
+ moments += beat
+ for(var/datum/landing_track/track as anything in list(scale, alpha, slide_x, slide_y, scale_with))
+ for(var/key_time in track?.times)
+ if(key_time > now && key_time <= end)
+ moments |= key_time
+ if(end > now)
+ moments |= end
+ return sort_list(moments, GLOBAL_PROC_REF(cmp_numeric_asc))
+
+/**
+ * Puts [target] (the sky object, or a viewer's image of one part) where the piece is now and queues the rest of
+ * its motion.
+ * * off_w, off_z, opacity - the part's place and opacity, from the piece's parts list
+ */
+/datum/landing_view_piece/proc/play_on(target, off_w = 0, off_z = 0, opacity = 1)
+ var/now = world.time
+ var/list/state = state_at(now)
+ var/atom/movable/moving = target // an image animates the same way
+ moving.transform = matrix_of(state, off_w, off_z)
+ moving.alpha = state[2] * opacity
+ animate(moving, transform = matrix_of(state, off_w, off_z), alpha = state[2] * opacity, time = 0, flags = ANIMATION_LINEAR_TRANSFORM)
+ var/last = now
+ var/held = 0
+ for(var/moment in sample_times(now))
+ var/list/next_state = state_at(moment)
+ if(next_state[1] == state[1] && next_state[2] == state[2] && next_state[3] == state[3] && next_state[4] == state[4])
+ held += moment - last
+ last = moment
+ continue
+ if(held)
+ animate(time = held)
+ held = 0
+ animate(transform = matrix_of(next_state, off_w, off_z), alpha = next_state[2] * opacity, time = moment - last, flags = ANIMATION_LINEAR_TRANSFORM)
+ state = next_state
+ last = moment
+
+/// One person watching: the images of the world pictures made for them, standing on the turf under their eye
+/datum/landing_view_viewer
+ var/client/client
+ /// The mob whose moves we follow
+ var/mob/followed
+ /// The turf the images stand on
+ var/turf/anchor
+ /// Tiles they see each way from it, with a margin
+ var/half_w = 11
+ var/half_h = 9
+ /// world picture -> the images of its parts they hold, by the part's number in the picture as text
+ var/list/images = list()
+
+/**
+ * Holds the sky for one viewer's screen. One object for everyone watching.
+ *
+ * Anchored seven tiles down and left of the middle, as the parallax is: the sky's textures are fifteen tiles
+ * across, and a screen object whose icon reaches past the edge of the view makes the client widen the view to
+ * fit it, which pushes everything else off centre.
+ */
+/atom/movable/screen/landing_view_home
+ name = ""
+ icon = null
+ screen_loc = "CENTER-7,CENTER-7"
+ plane = LANDING_VIEW_PLANE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+
+/// A piece of sky, drawn by the home it is in
+/atom/movable/screen/landing_view_sky
+ name = ""
+ icon = 'icons/effects/alphacolors.dmi'
+ icon_state = "white"
+ plane = LANDING_VIEW_PLANE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ appearance_flags = RESET_COLOR | RESET_TRANSFORM | NO_CLIENT_COLOR
+ alpha = 0
+
+/datum/landing_view
+ /// The hull
+ var/obj/docking_port/mobile/shuttle
+ /// The hull's turfs in transit and the berth turfs they pair with, in the same order
+ var/list/hull_turfs
+ var/list/berth_turfs
+ /// transit turf -> TRUE
+ var/list/hull_set = list()
+ /// Clockwise degrees the landing turns the hull
+ var/rotation = 0
+ /// The box of transit space the view covers: the hull's box and its border
+ var/transit_z
+ var/low_x
+ var/low_y
+ var/high_x
+ var/high_y
+ /// The middle of the hull's box in transit, in tiles (may end in .5)
+ var/pivot_x
+ var/pivot_y
+ /// The middle of the berth's box on the planet, the same point once landed
+ var/ground_x
+ var/ground_y
+ var/ground_z
+ /// Half the hull's size as it stands on the planet, in tiles
+ var/ground_half_w
+ var/ground_half_h
+ /// Areas carrying the mask overlay
+ var/list/area/masked = list()
+ /// client -> /datum/landing_view_viewer
+ var/list/viewers = list()
+ /// Everything shown: sky and world pictures
+ var/list/datum/landing_view_piece/pieces = list()
+ /// The planet's colours
+ var/datum/landing_view_palette/palette
+ /// The ground around the berth from afar, the same ground close up, the light on it, and the hull's shadow on it
+ var/datum/landing_view_piece/ground
+ var/datum/landing_view_piece/close
+ var/datum/landing_view_piece/light
+ var/datum/landing_view_piece/shadow
+ /// Areas carrying the overlay that marks transit space outside the hull
+ var/list/area/marked_outside = list()
+ var/atom/movable/screen/landing_view_home/home
+ /// Things standing in transit space for the view (heat on the hull's edge, dust): deleted with it
+ var/list/props = list()
+ /// The timer that keeps the viewers up to date
+ var/sync_timer
+ /// The transit turfs around the hull whose light this has changed, and their planet twins (see fade_light())
+ var/list/light_twins
+ /// TRUE once nothing more should be shown
+ var/ended = FALSE
+
+/**
+ * * hull_turfs - the hull's turfs in transit; null to attach() it later, once it is there
+ * * berth_turfs - the berth turfs they pair with, in the same order
+ * * rotation - clockwise degrees from the hull's heading in transit to its heading on the berth
+ */
+/datum/landing_view/New(obj/docking_port/mobile/shuttle, list/hull_turfs, list/berth_turfs, rotation)
+ . = ..()
+ src.shuttle = shuttle
+ home = new
+ if(berth_turfs && !set_ground(berth_turfs))
+ ended = TRUE
+ else if(hull_turfs)
+ if(!attach(hull_turfs, rotation))
+ ended = TRUE
+ else if(berth_turfs)
+ stand_on_berth()
+ else
+ ended = TRUE
+
+/// The berth the hull will stand on, or stood on. FALSE if there is none.
+/datum/landing_view/proc/set_ground(list/berth_turfs)
+ if(!length(berth_turfs))
+ return FALSE
+ src.berth_turfs = berth_turfs
+ var/min_x = INFINITY
+ var/max_x = -INFINITY
+ var/min_y = INFINITY
+ var/max_y = -INFINITY
+ for(var/turf/berth_turf as anything in berth_turfs)
+ min_x = min(min_x, berth_turf.x)
+ max_x = max(max_x, berth_turf.x)
+ min_y = min(min_y, berth_turf.y)
+ max_y = max(max_y, berth_turf.y)
+ ground_z = berth_turfs[1].z
+ ground_x = (min_x + max_x) / 2
+ ground_y = (min_y + max_y) / 2
+ ground_half_w = (max_x - min_x + 1) / 2
+ ground_half_h = (max_y - min_y + 1) / 2
+ return TRUE
+
+/**
+ * The hull is still on its berth: the people aboard are found there, so they can be handed what they will need
+ * before it lifts. Nothing can be seen until attach().
+ */
+/datum/landing_view/proc/stand_on_berth()
+ transit_z = ground_z
+ pivot_x = ground_x
+ pivot_y = ground_y
+ low_x = ground_x - ground_half_w + 0.5
+ low_y = ground_y - ground_half_h + 0.5
+ high_x = ground_x + ground_half_w - 0.5
+ high_y = ground_y + ground_half_h - 0.5
+ start_sync()
+
+/datum/landing_view/proc/start_sync()
+ if(!sync_timer)
+ sync_timer = addtimer(CALLBACK(src, PROC_REF(sync_viewers)), LANDING_VIEW_SYNC, TIMER_DELETE_ME | TIMER_LOOP | TIMER_STOPPABLE)
+
+/**
+ * The hull in transit, which everything is drawn around: from here on there are viewers. FALSE if [hull_turfs]
+ * do not pair with the berth's.
+ */
+/datum/landing_view/proc/attach(list/hull_turfs, rotation)
+ if(!length(hull_turfs) || (berth_turfs && length(hull_turfs) != length(berth_turfs)))
+ return FALSE
+ src.hull_turfs = hull_turfs
+ src.rotation = rotation
+ var/min_x = INFINITY
+ var/max_x = -INFINITY
+ var/min_y = INFINITY
+ var/max_y = -INFINITY
+ hull_set = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ hull_set[hull_turf] = TRUE
+ min_x = min(min_x, hull_turf.x)
+ max_x = max(max_x, hull_turf.x)
+ min_y = min(min_y, hull_turf.y)
+ max_y = max(max_y, hull_turf.y)
+ transit_z = hull_turfs[1].z
+ pivot_x = (min_x + max_x) / 2
+ pivot_y = (min_y + max_y) / 2
+ low_x = max(1, min_x - SHUTTLE_TRANSIT_BORDER)
+ low_y = max(1, min_y - SHUTTLE_TRANSIT_BORDER)
+ high_x = min(world.maxx, max_x + SHUTTLE_TRANSIT_BORDER)
+ high_y = min(world.maxy, max_y + SHUTTLE_TRANSIT_BORDER)
+ // the ground reaches the hull the way round it lies when the hull is on its berth
+ for(var/datum/landing_view_piece/piece as anything in pieces)
+ if(!piece.sky)
+ piece.turn = -rotation
+ mask_areas()
+ start_sync()
+ return TRUE
+
+/datum/landing_view/Destroy(force)
+ ended = TRUE
+ for(var/client/watcher as anything in viewers)
+ drop_viewer(watcher)
+ viewers = null
+ unmask_areas()
+ if(light_twins)
+ // left as they were found
+ landing_view_restore_light(light_twins)
+ light_twins = null
+ QDEL_LIST(props)
+ QDEL_LIST(pieces)
+ ground = null
+ close = null
+ light = null
+ shadow = null
+ palette = null
+ QDEL_NULL(home)
+ shuttle = null
+ hull_turfs = null
+ berth_turfs = null
+ hull_set = null
+ return ..()
+
+/**
+ * The manoeuvre was called off: everything fades away, back to plain space, and then the view deletes itself.
+ * Whoever held it should let go of it now.
+ */
+/datum/landing_view/proc/fade_away()
+ if(ended)
+ return
+ ended = TRUE
+ for(var/datum/landing_view_piece/piece as anything in pieces)
+ if(piece.sky)
+ animate(piece.sky, alpha = 0, time = LANDING_VIEW_FADE)
+ for(var/client/watcher as anything in viewers)
+ var/datum/landing_view_viewer/viewer = viewers[watcher]
+ for(var/piece in viewer?.images)
+ var/list/held = viewer.images[piece]
+ for(var/slot in held)
+ animate(held[slot], alpha = 0, time = LANDING_VIEW_FADE)
+ for(var/atom/movable/prop as anything in props)
+ if(!QDELETED(prop))
+ animate(prop, alpha = 0, time = LANDING_VIEW_FADE)
+ // a hard reference: by now nothing else holds us
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel), src), LANDING_VIEW_FADE)
+
+/**
+ * In transit the stars light the hull's outer edge; on the ground, the ground beside it does (warm daylight off
+ * grass, blue off water). Left alone the hull changes colour the instant it lands or lifts. So for the last of
+ * a descent the space around the hull casts, tile for tile, the light the ground around the berth will, and
+ * after a takeoff it goes on casting it and lets it go slowly.
+ * * start, finish - how far from the stars' light to the ground's, 0-1
+ */
+/datum/landing_view/proc/fade_light(start, finish, time, stage = 0)
+ if(QDELETED(src) || ended || !hull_turfs || !berth_turfs)
+ return
+ light_twins ||= landing_view_light_twins(hull_turfs, berth_turfs, rotation)
+ landing_view_blend_light(light_twins, start + (finish - start) * stage / LANDING_VIEW_LIGHT_STEPS)
+ if(stage < LANDING_VIEW_LIGHT_STEPS)
+ addtimer(CALLBACK(src, PROC_REF(fade_light), start, finish, time, stage + 1), time / LANDING_VIEW_LIGHT_STEPS, TIMER_DELETE_ME)
+
+/**
+ * The transit turfs around a hull, each with the planet turf that lies in its place beside the berth:
+ * transit turf -> list(planet turf, TRUE if the stars light the hull from there).
+ * * rotation - clockwise degrees from the hull's heading in transit to its heading on the berth
+ */
+/proc/landing_view_light_twins(list/hull_turfs, list/berth_turfs, rotation)
+ . = list()
+ var/list/hull_set = list()
+ var/list/berth_set = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ hull_set[hull_turf] = TRUE
+ for(var/turf/berth_turf as anything in berth_turfs)
+ berth_set[berth_turf] = TRUE
+ var/turned_cos = round(cos(rotation), 1)
+ var/turned_sin = round(sin(rotation), 1)
+ for(var/i in 1 to min(length(hull_turfs), length(berth_turfs)))
+ var/turf/hull_turf = hull_turfs[i]
+ var/turf/berth_turf = berth_turfs[i]
+ for(var/off_x in -2 to 2)
+ for(var/off_y in -2 to 2)
+ var/turf/planet_side = locate(berth_turf.x + off_x, berth_turf.y + off_y, berth_turf.z)
+ if(!planet_side || berth_set[planet_side])
+ continue
+ // the same step from the same hull tile, turned as the hull lies in transit
+ var/turf/transit_side = locate(hull_turf.x + off_x * turned_cos - off_y * turned_sin, hull_turf.y + off_x * turned_sin + off_y * turned_cos, hull_turf.z)
+ if(!transit_side || hull_set[transit_side] || !isspaceturf(transit_side))
+ continue
+ var/beside = abs(off_x) <= 1 && abs(off_y) <= 1
+ var/list/twin = .[transit_side]
+ if(!twin)
+ .[transit_side] = list(planet_side, beside)
+ else if(beside)
+ twin[2] = TRUE
+
+/// Sets the light each transit turf of [twins] casts: [share] of the way from the stars' to its planet twin's
+/proc/landing_view_blend_light(list/twins, share)
+ var/star_range = GLOB.starlight_range
+ var/star_power = GLOB.starlight_power
+ var/star_color = GLOB.starlight_color
+ for(var/turf/transit_side as anything in twins)
+ if(!isspaceturf(transit_side))
+ continue
+ var/list/twin = twins[transit_side]
+ var/stars = twin[2] ? star_power : 0
+ var/list/ground = landing_view_ground_light(twin[1], twin[2])
+ if(!stars && !ground)
+ continue
+ var/from_reach = stars ? star_range : ground[1]
+ var/to_reach = ground ? ground[1] : star_range
+ var/to_power = ground ? ground[2] : 0
+ var/tone = star_color
+ if(ground && (!stars || share >= 1))
+ tone = ground[3] || COLOR_WHITE
+ else if(ground && share > 0)
+ // never asked for the far end itself: the gradient loops, and gives the near end back for it
+ tone = BlendRGB(star_color, ground[3] || COLOR_WHITE, share)
+ // kept on even at no power: a turf whose light is off has the stars' put back by its neighbours
+ transit_side.set_light(l_range = from_reach + (to_reach - from_reach) * share, l_power = max(stars + (to_power - stars) * share, 0), l_color = tone, l_on = TRUE)
+
+/**
+ * The light [planet_side] casts on a hull standing beside it, as list(range, power, colour), or null for none.
+ * Daylit ground only lights what stands against it while something does (see voidcrew/edits/lighting.dm), so
+ * for ground with nothing on it yet this is the light it will cast, not the light it has.
+ * * beside - TRUE if the hull stands right against it
+ */
+/proc/landing_view_ground_light(turf/planet_side, beside)
+ // ground that lights itself: lava, glowing water
+ if(planet_side.light_range && planet_side.light_range != AMBIENT_BLEED_RANGE)
+ if(!planet_side.light_on || planet_side.light_power <= 0)
+ return null
+ return list(planet_side.light_range, planet_side.light_power, planet_side.light_color)
+ if(!beside)
+ return null
+ var/area/daylit = planet_side.ambient_bleed_area()
+ if(!daylit)
+ return null
+ return list(AMBIENT_BLEED_RANGE, (daylit.base_lighting_alpha / 255) / AMBIENT_BLEED_OVERLAP_FACTOR, daylit.base_lighting_color == COLOR_STARLIGHT ? GLOB.starlight_color : daylit.base_lighting_color)
+
+/// Gives the transit turfs of [twins] back the light they have by rights: the stars', beside a hull, or none
+/proc/landing_view_restore_light(list/twins)
+ for(var/turf/open/space/transit_side in twins)
+ GLOB.starlight -= transit_side
+ transit_side.set_light(l_on = FALSE)
+ transit_side.update_starlight()
+
+/// The mask tile every turf of a landing ship carries, through its area
+/proc/landing_view_mask_tile()
+ var/static/mutable_appearance/tile
+ if(!tile)
+ tile = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM)
+ tile.plane = LANDING_VIEW_MASK_PLANE
+ return tile
+
+/// The tile every turf of transit space around a landing ship carries, through its area: where the ground's light may fall
+/proc/landing_view_outside_tile()
+ var/static/mutable_appearance/tile
+ if(!tile)
+ tile = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM)
+ tile.plane = LANDING_VIEW_OUTSIDE_PLANE
+ return tile
+
+/datum/landing_view/proc/mask_areas()
+ var/list/area/wanted = list()
+ var/list/area/outside_areas = list()
+ if(shuttle.assigned_transit?.assigned_area)
+ wanted += shuttle.assigned_transit.assigned_area
+ outside_areas += shuttle.assigned_transit.assigned_area
+ for(var/area/hull_area as anything in shuttle.shuttle_areas)
+ wanted |= hull_area
+ for(var/turf/hull_turf as anything in hull_turfs)
+ wanted |= hull_turf.loc
+ // the transit space around the hull, whoever's area it is
+ var/turf/outside = locate(low_x, low_y, transit_z)
+ if(outside)
+ wanted |= outside.loc
+ outside_areas |= outside.loc
+ for(var/area/to_mask as anything in wanted)
+ to_mask.add_overlay(landing_view_mask_tile())
+ masked += to_mask
+ for(var/area/to_mark as anything in outside_areas)
+ to_mark.add_overlay(landing_view_outside_tile())
+ marked_outside += to_mark
+
+/datum/landing_view/proc/unmask_areas()
+ for(var/area/was_masked as anything in masked)
+ if(!QDELETED(was_masked))
+ was_masked.cut_overlay(landing_view_mask_tile())
+ masked = list()
+ for(var/area/was_marked as anything in marked_outside)
+ if(!QDELETED(was_marked))
+ was_marked.cut_overlay(landing_view_outside_tile())
+ marked_outside = list()
+
+/**
+ * A new piece of sky in the shared home, its middle on the middle of the screen. With no icon it is a flat
+ * fill of [fill] over the whole screen.
+ * * size - the icon's size in pixels
+ */
+/datum/landing_view/proc/add_sky(sky_layer, icon_file, state, size = ICON_SIZE_X, fill)
+ var/datum/landing_view_piece/piece = new
+ var/atom/movable/screen/landing_view_sky/sky = new
+ piece.sky = sky
+ sky.layer = sky_layer
+ if(icon_file)
+ sky.icon = icon_file
+ sky.icon_state = state
+ // its middle on the middle of the home's fifteen tiles
+ sky.pixel_w = (LANDING_VIEW_ICON_SIZE - size) / 2
+ sky.pixel_z = (LANDING_VIEW_ICON_SIZE - size) / 2
+ else
+ // one white tile in the middle, drawn big enough for any screen
+ sky.color = fill
+ sky.pixel_w = (LANDING_VIEW_ICON_SIZE - ICON_SIZE_X) / 2
+ sky.pixel_z = (LANDING_VIEW_ICON_SIZE - ICON_SIZE_Y) / 2
+ var/mutable_appearance/sheet = mutable_appearance('icons/effects/alphacolors.dmi', "white")
+ sheet.transform = matrix().Scale(64)
+ sky.icon_state = "transparent"
+ sky.overlays = list(sheet)
+ home.vis_contents += sky
+ pieces += piece
+ return piece
+
+/**
+ * A sheet of full light over the ground's own light (see bake_light()), as opaque as [alpha] says: for the white
+ * of a cloud, which is lit by the open sky whatever the ground under it is. Without it a cave turns the cloud
+ * black and warm daylight turns it tan, a moment before either is seen.
+ */
+/datum/landing_view/proc/add_daylight(datum/landing_track/alpha)
+ var/datum/landing_view_piece/daylight = add_sky(5, fill = COLOR_WHITE)
+ daylight.sky.plane = LANDING_VIEW_LIGHT_PLANE
+ daylight.alpha = alpha
+ show(daylight)
+ return daylight
+
+/// A new world picture. Set its parts, then show() it.
+/datum/landing_view/proc/add_picture()
+ var/datum/landing_view_piece/piece = new
+ // the ground reaches the hull the way round it will lie once the hull has turned onto its berth
+ piece.turn = -rotation
+ pieces += piece
+ return piece
+
+/**
+ * [piece]'s motion is set, or has changed: (re)start it for everyone watching. A world picture is handed over at
+ * its give_at and taken back at its drop_at.
+ * * replay - FALSE if only new parts were added to a world picture: what is already showing is left alone
+ */
+/datum/landing_view/proc/show(datum/landing_view_piece/piece, replay = TRUE)
+ if(ended)
+ return
+ if(piece.sky)
+ piece.play_on(piece.sky)
+ return
+ if(!length(piece.parts) || world.time >= piece.drop_at)
+ return
+ if(world.time < piece.give_at)
+ // booked once for each picture. Not as a unique timer: two pictures due at the same moment count as one, and the first is never shown
+ if(piece.give_at < INFINITY && !piece.give_booked)
+ piece.give_booked = TRUE
+ addtimer(CALLBACK(src, PROC_REF(show), piece, replay), piece.give_at - world.time, TIMER_DELETE_ME)
+ return
+ if(!piece.dropping && piece.drop_at < INFINITY)
+ piece.dropping = TRUE
+ addtimer(CALLBACK(src, PROC_REF(take_back), piece), piece.drop_at - world.time, TIMER_DELETE_ME)
+ piece.shown = TRUE
+ for(var/client/watcher as anything in viewers)
+ var/datum/landing_view_viewer/viewer = viewers[watcher]
+ if(!viewer || !watcher)
+ continue
+ give_picture(viewer, piece, replay)
+
+/// A picture handed out ahead of time (see held_back) starts to move, for everyone who holds it
+/datum/landing_view/proc/reveal(datum/landing_view_piece/piece)
+ if(ended || !piece.held_back)
+ return
+ piece.held_back = FALSE
+ show(piece)
+
+/// [piece] is out of sight for good: nobody holds its images any more
+/datum/landing_view/proc/take_back(datum/landing_view_piece/piece)
+ if(ended || !piece.shown)
+ return
+ piece.shown = FALSE
+ for(var/client/watcher as anything in viewers)
+ var/datum/landing_view_viewer/viewer = viewers[watcher]
+ var/list/held = viewer?.images[piece]
+ if(!held)
+ continue
+ for(var/slot in held)
+ watcher?.images -= held[slot]
+ viewer.images -= piece
+
+/**
+ * Brings what [viewer] holds of [piece] up to date: the parts their screen can show, or all of them for a
+ * picture that is not picked over. Parts gone out of their sight are taken back.
+ * * replay - FALSE to leave alone what they already hold
+ */
+/datum/landing_view/proc/give_picture(datum/landing_view_viewer/viewer, datum/landing_view_piece/piece, replay = TRUE)
+ var/client/watcher = viewer.client
+ if(!watcher)
+ return
+ var/list/shown = viewer.images[piece]
+ if(!shown)
+ shown = list()
+ viewer.images[piece] = shown
+ var/list/sight = piece.cull_from ? sight_of(viewer, piece) : null
+ // a picture already in sight has to be whole at once; one that is still clear can come a few parts a tick
+ var/budget = (sight && (piece.held_back || piece.state_at(world.time)[2] <= 0)) ? LANDING_VIEW_HANDOVER : INFINITY
+ var/more = FALSE
+ var/list/image/added = list()
+ for(var/i in 1 to length(piece.parts))
+ var/list/part = piece.parts[i]
+ var/slot = "[i]"
+ var/image/part_image = shown[slot]
+ // how far out of their sight it lies, in tiles
+ var/out = 0
+ if(sight && length(part) > 4 && part[5])
+ out = max(abs(part[2] - sight[1]) - sight[3], abs(part[3] - sight[2]) - sight[4]) / ICON_SIZE_X - part[5]
+ if(part_image)
+ if(out > LANDING_VIEW_KEEP)
+ watcher.images -= part_image
+ shown -= slot
+ else if(replay)
+ play_part(piece, part_image, part)
+ continue
+ if(out > 0)
+ continue
+ if(budget <= 0)
+ more = TRUE
+ continue
+ budget--
+ part_image = image(loc = viewer.anchor)
+ part_image.appearance = part[1]
+ part_image.loc = viewer.anchor
+ place_image(part_image, viewer.anchor)
+ play_part(piece, part_image, part)
+ shown[slot] = part_image
+ added += part_image
+ watcher.images += added
+ if(more)
+ addtimer(CALLBACK(src, PROC_REF(give_more), viewer, piece), world.tick_lag, TIMER_DELETE_ME)
+
+/// The rest of a picture that is being handed over a few parts a tick
+/datum/landing_view/proc/give_more(datum/landing_view_viewer/viewer, datum/landing_view_piece/piece)
+ if(ended || QDELETED(piece) || !piece.shown || !viewer.client || viewers[viewer.client] != viewer)
+ return
+ give_picture(viewer, piece, FALSE)
+
+/datum/landing_view/proc/play_part(datum/landing_view_piece/piece, image/part_image, list/part)
+ if(piece.held_back)
+ animate(part_image, alpha = 0, time = 0)
+ part_image.alpha = 0
+ return
+ piece.play_on(part_image, part[2], part[3], part[4])
+
+/**
+ * The part of [piece] that [viewer]'s screen shows from now until a little later, in the picture's own pixels
+ * from its middle: list(middle w, middle z, half width, half height).
+ */
+/datum/landing_view/proc/sight_of(datum/landing_view_viewer/viewer, datum/landing_view_piece/piece)
+ var/now = world.time
+ // their eye from the hull's middle, turned into the picture's frame
+ var/eye_w = (viewer.anchor.x - pivot_x) * ICON_SIZE_X
+ var/eye_z = (viewer.anchor.y - pivot_y) * ICON_SIZE_Y
+ var/turned = piece.turn
+ var/in_w = eye_w * cos(turned) - eye_z * sin(turned)
+ var/in_z = eye_w * sin(turned) + eye_z * cos(turned)
+ var/sideways = abs(round(turned / 90)) % 2
+ var/half_w = (sideways ? viewer.half_h : viewer.half_w) * ICON_SIZE_X
+ var/half_z = (sideways ? viewer.half_w : viewer.half_h) * ICON_SIZE_Y
+ var/low_w = INFINITY
+ var/low_z = INFINITY
+ var/high_w = -INFINITY
+ var/high_z = -INFINITY
+ for(var/when in list(now, now + LANDING_VIEW_AHEAD))
+ var/list/state = piece.state_at(when)
+ var/size = piece.held_back ? piece.cull_from : max(piece.cull_from, state[1])
+ // it is drawn slid and then scaled, so a point of the screen is that far into it
+ var/mid_w = in_w / size + state[3] * ICON_SIZE_X
+ var/mid_z = in_z / size + state[4] * ICON_SIZE_Y
+ low_w = min(low_w, mid_w - half_w / size)
+ high_w = max(high_w, mid_w + half_w / size)
+ low_z = min(low_z, mid_z - half_z / size)
+ high_z = max(high_z, mid_z + half_z / size)
+ return list((low_w + high_w) / 2, (low_z + high_z) / 2, (high_w - low_w) / 2, (high_z - low_z) / 2)
+
+/// Shifts an image standing on [anchor] so its middle is the hull's middle
+/datum/landing_view/proc/place_image(image/shown, turf/anchor)
+ shown.pixel_w = (pivot_x - anchor.x) * ICON_SIZE_X
+ shown.pixel_z = (pivot_y - anchor.y) * ICON_SIZE_Y
+
+/// Whether [watcher] is looking at this hull's patch of transit space, and from which turf
+/datum/landing_view/proc/eye_turf_of(client/watcher)
+ var/turf/eye_turf = get_turf(watcher.eye)
+ if(!eye_turf || eye_turf.z != transit_z)
+ return null
+ if(eye_turf.x < low_x || eye_turf.x > high_x || eye_turf.y < low_y || eye_turf.y > high_y)
+ return null
+ return eye_turf
+
+/// Brings the viewers up to date: everyone whose eye is on or around the hull, living or not
+/datum/landing_view/proc/sync_viewers()
+ if(ended || !transit_z)
+ return
+ for(var/client/watcher as anything in viewers)
+ if(!watcher || !eye_turf_of(watcher))
+ drop_viewer(watcher)
+ for(var/mob/player as anything in GLOB.player_list)
+ var/client/watcher = player.client
+ if(!watcher)
+ continue
+ var/turf/eye_turf = eye_turf_of(watcher)
+ if(!eye_turf)
+ continue
+ var/datum/landing_view_viewer/viewer = viewers[watcher]
+ if(!viewer)
+ add_viewer(watcher, eye_turf)
+ continue
+ if(viewer.followed != watcher.mob)
+ follow(viewer, watcher.mob)
+ // a new mob (ghosting, being put in a body) or a HUD toggle rebuilds the screen from scratch, and the sky
+ // with it, while the images held for the client stay
+ if(!(home in watcher.screen))
+ watcher.screen += home
+ size_up(viewer)
+ if(viewer.anchor != eye_turf)
+ move_viewer(viewer, eye_turf)
+ else
+ for(var/datum/landing_view_piece/piece as anything in pieces)
+ if(piece.shown && piece.cull_from)
+ give_picture(viewer, piece, FALSE)
+
+/// How much [viewer] sees each way
+/datum/landing_view/proc/size_up(datum/landing_view_viewer/viewer)
+ var/list/view_size = getviewsize(viewer.client?.view)
+ viewer.half_w = view_size[1] / 2 + LANDING_VIEW_MARGIN
+ viewer.half_h = view_size[2] / 2 + LANDING_VIEW_MARGIN
+
+/datum/landing_view/proc/add_viewer(client/watcher, turf/eye_turf)
+ var/datum/landing_view_viewer/viewer = new
+ viewer.client = watcher
+ viewer.anchor = eye_turf
+ viewers[watcher] = viewer
+ follow(viewer, watcher.mob)
+ size_up(viewer)
+ watcher.screen += home
+ for(var/datum/landing_view_piece/piece as anything in pieces)
+ if(piece.shown)
+ give_picture(viewer, piece)
+ on_viewer_added(watcher)
+
+/// For the manoeuvre to greet a new viewer with its sounds
+/datum/landing_view/proc/on_viewer_added(client/watcher)
+ return
+
+/datum/landing_view/proc/drop_viewer(client/watcher)
+ var/datum/landing_view_viewer/viewer = viewers[watcher]
+ viewers -= watcher
+ if(!viewer)
+ return
+ follow(viewer, null)
+ if(watcher)
+ watcher.screen -= home
+ for(var/piece in viewer.images)
+ var/list/held = viewer.images[piece]
+ for(var/slot in held)
+ watcher.images -= held[slot]
+ viewer.images = null
+ viewer.client = null
+
+/datum/landing_view/proc/follow(datum/landing_view_viewer/viewer, mob/to_follow)
+ if(viewer.followed)
+ UnregisterSignal(viewer.followed, COMSIG_MOVABLE_MOVED)
+ viewer.followed = to_follow
+ if(to_follow)
+ RegisterSignal(to_follow, COMSIG_MOVABLE_MOVED, PROC_REF(on_viewer_moved), override = TRUE)
+
+/datum/landing_view/proc/on_viewer_moved(mob/source)
+ SIGNAL_HANDLER
+ var/client/watcher = source.client
+ var/datum/landing_view_viewer/viewer = watcher ? viewers[watcher] : null
+ if(!viewer)
+ return
+ var/turf/eye_turf = eye_turf_of(watcher)
+ if(eye_turf && eye_turf != viewer.anchor)
+ move_viewer(viewer, eye_turf)
+
+/// The viewer's eye is over a new turf: their images go with it, and stay where they were on the world
+/datum/landing_view/proc/move_viewer(datum/landing_view_viewer/viewer, turf/eye_turf)
+ viewer.anchor = eye_turf
+ for(var/datum/landing_view_piece/piece as anything in viewer.images)
+ var/list/held = viewer.images[piece]
+ for(var/slot in held)
+ var/image/shown = held[slot]
+ shown.loc = eye_turf
+ place_image(shown, eye_turf)
+ if(piece.shown && piece.cull_from)
+ give_picture(viewer, piece, FALSE)
+
+#undef LANDING_VIEW_STEP
+#undef LANDING_VIEW_SYNC
+#undef LANDING_VIEW_FADE
+#undef LANDING_VIEW_HANDOVER
+#undef LANDING_VIEW_LIGHT_STEPS
+#undef LANDING_VIEW_AHEAD
+#undef LANDING_VIEW_MARGIN
+#undef LANDING_VIEW_KEEP
diff --git a/voidcrew/modules/landing_animation/landing_view_ascent.dm b/voidcrew/modules/landing_animation/landing_view_ascent.dm
new file mode 100644
index 00000000000..5e87f8f1ad7
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_ascent.dm
@@ -0,0 +1,250 @@
+/**
+ * # The climb, seen from aboard
+ *
+ * Starts the moment the hull leaves its berth for transit (L), over a picture of the ground it just stood on,
+ * so nothing outside changes as it goes. Then, in step with what the people on the ground see of the ship
+ * (a level lift, then off toward the bow):
+ *
+ * | from | what |
+ * |---------|---------------------------------------------------------------------------------------|
+ * | L | the ground falls away and starts to slide astern, dust blowing out from under the hull |
+ * | L+1s | the ground slides off sternward faster as the ship gathers way, haze thickening |
+ * | L+3.3s | into the cloud: everything white |
+ * | L+4.1s | out of its top: the white thins into the sky's colour, and the sky darkens |
+ * | L+4.8s | the planet, whole, falling away under the ship until it is the size it has from orbit |
+ *
+ * Made while the engines wind up, so the country around the berth is already drawn when the hull lifts; only
+ * the ground the hull itself stood on has to wait for it to be gone. When it is done the view of the planet
+ * from above takes over (see /datum/landing_view/hover), or it fades out if the ship is already somewhere else.
+ */
+
+#define ASCENT_LENGTH (9 SECONDS)
+/// How long a view made ready for a takeoff waits for the hull to lift before it gives up
+#define ASCENT_WAIT (40 SECONDS)
+
+/// The view from aboard of this ship's climb out: made ready as its engines wind up, gone when the climb is over
+/obj/structure/overmap/ship/var/datum/landing_view/ascent/launch_view
+
+/datum/landing_view/ascent
+ /// The ship climbing out, which holds us
+ var/obj/structure/overmap/ship/ship
+ /// world.time the hull left the ground; null while it is still on it
+ var/liftoff
+ /// The way the bow points, as a step on the ground picture and on the screen
+ var/bow_dir = NORTH
+ var/bow_x = 0
+ var/bow_y = 0
+ var/screen_bow_x = 0
+ var/screen_bow_y = 0
+
+/**
+ * * hull_turfs - null while the hull is still on its berth; lift_off() is called when it leaves
+ * * berth_turfs - the turfs it stands on, or stood on
+ * * bow_dir - the way its bow points on the berth
+ */
+/datum/landing_view/ascent/New(obj/docking_port/mobile/shuttle, list/hull_turfs, list/berth_turfs, rotation, obj/structure/overmap/site, bow_dir = NORTH, obj/structure/overmap/ship/ship)
+ . = ..()
+ if(ended)
+ return
+ src.ship = ship
+ src.bow_dir = bow_dir
+ palette = landing_view_palette_for(site)
+ bow_x = (bow_dir & EAST) ? 1 : ((bow_dir & WEST) ? -1 : 0)
+ bow_y = (bow_dir & NORTH) ? 1 : ((bow_dir & SOUTH) ? -1 : 0)
+ ground = add_picture()
+ close = add_picture()
+ light = add_picture()
+ shadow = add_picture()
+ hold_ground(ground, close, light)
+ // all the country around the berth; the ground under the hull is drawn once the hull is off it
+ bake_far(ground, CALLBACK(src, PROC_REF(country_drawn)))
+ bake_light(light, CALLBACK(src, PROC_REF(country_drawn)))
+ bake_near(close, detail_reach(), CALLBACK(src, PROC_REF(country_drawn)), LANDING_GROUND_AROUND)
+ if(hull_turfs)
+ lift_off(hull_turfs, berth_turfs, rotation)
+ else
+ addtimer(CALLBACK(src, PROC_REF(give_up)), ASCENT_WAIT, TIMER_DELETE_ME)
+
+/datum/landing_view/ascent/Destroy(force)
+ if(ship?.launch_view == src)
+ ship.launch_view = null
+ ship = null
+ return ..()
+
+/// The takeoff this was made ready for never came
+/datum/landing_view/ascent/proc/give_up()
+ if(!liftoff)
+ qdel(src)
+
+/// The country around the berth is drawn: the people aboard get it now, to hold until the hull lifts if it has not
+/datum/landing_view/ascent/proc/country_drawn()
+ show(ground, FALSE)
+ show(close, FALSE)
+ show(light, FALSE)
+
+/**
+ * The hull has just left its berth for transit.
+ * * hull_turfs - where it stands now
+ * * planet_turfs - the berth turfs it left, in the same order
+ * * rotation - clockwise degrees from its heading in transit to its heading on the berth
+ */
+/datum/landing_view/ascent/proc/lift_off(list/hull_turfs, list/planet_turfs, rotation)
+ if(ended || liftoff)
+ return
+ if(!set_ground(planet_turfs) || !attach(hull_turfs, rotation))
+ qdel(src)
+ return
+ liftoff = world.time
+ // the people aboard went with the hull: what they hold goes with them
+ sync_viewers()
+ ground.held_back = FALSE
+ close.held_back = FALSE
+ light.held_back = FALSE
+ // the ground's light is still on the hull's edge (see takeoff()): it gives way to the stars' as it climbs
+ fade_light(1, 0, 2.6 SECONDS)
+ var/screen_bow = rotation ? turn(bow_dir, rotation) : bow_dir
+ screen_bow_x = (screen_bow & EAST) ? 1 : ((screen_bow & WEST) ? -1 : 0)
+ screen_bow_y = (screen_bow & NORTH) ? 1 : ((screen_bow & SOUTH) ? -1 : 0)
+ // the ground the hull stood on, bare now it has gone: drawn in this same tick, or the tiles beside the hull
+ // show as their painted selves for a moment
+ bake_near(close, detail_reach(), null, LANDING_GROUND_UNDER, TRUE)
+ add_ground()
+ add_clouds()
+ add_planet()
+ sync_viewers()
+ cue('voidcrew/sound/effects/landing/launch.ogg', 60, 3 SECONDS, 0.06)
+ addtimer(CALLBACK(src, PROC_REF(finish)), ASCENT_LENGTH)
+
+/// The climb is over. The planet is left where it is, under a ship still over it, for the view from orbit to take up.
+/datum/landing_view/ascent/proc/finish()
+ if(ended)
+ return
+ var/obj/structure/overmap/ship/our_ship = ship
+ if(our_ship?.launch_view == src)
+ our_ship.launch_view = null
+ if(our_ship.hover_site())
+ qdel(src)
+ our_ship.update_hover_view(FALSE)
+ return
+ fade_away()
+
+/// The ground it stood on, falling away and sliding off astern, and its shadow left behind on it
+/datum/landing_view/ascent/proc/add_ground()
+ // height gained under steady thrust, and way gathered once it starts to move off: sampled, so the motion is smooth
+ for(var/step in 0 to 21)
+ var/seconds = step * 0.2
+ var/when = liftoff + seconds * 10
+ ground.scale.mark(when, 1 / (1 + (seconds / 2.4) ** 2))
+ // moving off from the first moment, slowly at first
+ var/slid = 1.2 * seconds ** 2.2
+ ground.slide_x.mark(when, bow_x * slid)
+ ground.slide_y.mark(when, bow_y * slid)
+ // the shadow stays on the ground, and falls further off to one side the higher the hull is
+ var/lean = min(seconds * 2.6, 9)
+ shadow.slide_x.mark(when, bow_x * slid - lean)
+ shadow.slide_y.mark(when, bow_y * slid + lean)
+ // gone once the sky has closed over it
+ ground.alpha.mark(liftoff + 3.7 SECONDS, 255)
+ ground.alpha.mark(liftoff + 3.8 SECONDS, 0)
+ ground.drop_at = liftoff + 3.9 SECONDS
+ chain_ground(ground, close)
+ show(ground)
+ show(close)
+ // past the reach of those pictures there is only cloud, closing in as the ground falls away
+ var/datum/landing_track/veil_alpha = veil_fade(ground.scale)
+ for(var/for_light in list(FALSE, TRUE))
+ var/datum/landing_view_piece/veil = add_picture()
+ veil.parts = cloud_veil(for_light)
+ veil.scale = ground.scale
+ veil.alpha = veil_alpha
+ veil.slide_x = ground.slide_x
+ veil.slide_y = ground.slide_y
+ veil.drop_at = liftoff + 3.9 SECONDS
+ show(veil)
+ // the light on it goes with it, and lets go as the haze closes over it
+ light.scale = ground.scale
+ light.slide_x = ground.slide_x
+ light.slide_y = ground.slide_y
+ light.alpha.mark(liftoff, 255)
+ light.alpha.mark(liftoff + 3.7 SECONDS, 255)
+ light.alpha.mark(liftoff + 3.8 SECONDS, 0)
+ light.drop_at = liftoff + 3.9 SECONDS
+ show(light)
+ // and the open sky's light closes over it with the haze and the cloud
+ var/datum/landing_track/cloud_light = new
+ cloud_light.mark(liftoff + 2.2 SECONDS, 0)
+ cloud_light.mark(liftoff + 3.5 SECONDS, 255, LANDING_CURVE_IN)
+ add_daylight(cloud_light)
+
+ shadow.parts = list(list(landing_view_shadow_look(berth_turfs, ground_x, ground_y), 0, 0, 1))
+ shadow.scale.mark(liftoff, 1)
+ shadow.scale.mark(liftoff + 1.2 SECONDS, 1.2, LANDING_CURVE_BOTH)
+ shadow.scale_with = ground.scale
+ shadow.alpha.mark(liftoff, 0)
+ shadow.alpha.mark(liftoff + 0.3 SECONDS, 140)
+ shadow.alpha.mark(liftoff + 1.4 SECONDS, 110)
+ shadow.alpha.mark(liftoff + 2.8 SECONDS, 0)
+ show(shadow)
+
+ var/datum/landing_view_piece/haze = add_sky(LANDING_VIEW_LAYER_HAZE, fill = palette.sky)
+ haze.alpha.mark(liftoff + 0.8 SECONDS, 0)
+ haze.alpha.mark(liftoff + 2.4 SECONDS, 110)
+ haze.alpha.mark(liftoff + 3.4 SECONDS, 235)
+ haze.alpha.mark(liftoff + 3.8 SECONDS, 235)
+ haze.alpha.mark(liftoff + 3.9 SECONDS, 0)
+ show(haze)
+
+/// Through the cloud and out of its top
+/datum/landing_view/ascent/proc/add_clouds()
+ var/datum/landing_view_piece/sky = add_sky(LANDING_VIEW_LAYER_SKY, fill = palette.sky)
+ sky.alpha.mark(liftoff + 2.8 SECONDS, 0)
+ sky.alpha.mark(liftoff + 3.6 SECONDS, 255, LANDING_CURVE_BOTH)
+ // thinning as soon as the white has gone: a flat sky is a dead moment
+ sky.alpha.mark(liftoff + 4.7 SECONDS, 255)
+ sky.alpha.mark(liftoff + 6.4 SECONDS, 0, LANDING_CURVE_BOTH)
+ show(sky)
+
+ var/datum/landing_view_piece/inside = add_sky(LANDING_VIEW_LAYER_CLOUD + 1, fill = palette.cloud)
+ inside.alpha.mark(liftoff + 3.3 SECONDS, 0)
+ inside.alpha.mark(liftoff + 3.8 SECONDS, 250, LANDING_CURVE_IN)
+ inside.alpha.mark(liftoff + 4.1 SECONDS, 250)
+ inside.alpha.mark(liftoff + 4.8 SECONDS, 0, LANDING_CURVE_OUT)
+ show(inside)
+
+ // mist streaming past while the ship is inside it, so the white is never still
+ var/datum/landing_view_piece/mist = add_sky(LANDING_VIEW_LAYER_CLOUD + 1.5, LANDING_VIEW_ICON, "wisps", LANDING_VIEW_ICON_SIZE)
+ mist.sky.color = palette.sky
+ mist.turn = 73
+ mist.scale.mark(liftoff + 3.2 SECONDS, 6.5)
+ mist.scale.mark(liftoff + 4.8 SECONDS, 2.2)
+ mist.alpha.mark(liftoff + 3.2 SECONDS, 0)
+ mist.alpha.mark(liftoff + 3.7 SECONDS, 120)
+ mist.alpha.mark(liftoff + 4.2 SECONDS, 120)
+ mist.alpha.mark(liftoff + 4.8 SECONDS, 0)
+ show(mist)
+
+/// The planet whole, falling away under the ship until it is as big as it is from orbit
+/datum/landing_view/ascent/proc/add_planet()
+ var/list/planet = new_planet()
+ var/list/grains = planet[1]
+ var/datum/landing_view_piece/whole = grains[1][1]
+ var/datum/landing_track/size = whole.scale
+ // not as close as a descent leaves it: this near, its texture shows its grain, and here there is no cloud over it
+ size.mark(liftoff + 4.6 SECONDS, 4.2)
+ size.mark(liftoff + 8.6 SECONDS, LANDING_HOVER_SIZE, LANDING_CURVE_BOTH)
+ // there, solid, under the sky before the sky thins: a planet that fades in lets the stars show through it
+ var/datum/landing_track/opacity = new
+ opacity.mark(liftoff + 4.6 SECONDS, 0)
+ opacity.mark(liftoff + 4.7 SECONDS, 255)
+ chain_detail(grains, size, opacity, LANDING_PLANET_DETAIL)
+ var/datum/landing_view_piece/shade = planet[2]
+ shade.alpha = opacity
+ show(shade)
+
+ var/datum/landing_view_piece/air = new_air(whole)
+ air.alpha.mark(liftoff + 4.6 SECONDS, 0)
+ air.alpha.mark(liftoff + 4.7 SECONDS, 235)
+ show(air)
+
+#undef ASCENT_LENGTH
+#undef ASCENT_WAIT
diff --git a/voidcrew/modules/landing_animation/landing_view_descent.dm b/voidcrew/modules/landing_animation/landing_view_descent.dm
new file mode 100644
index 00000000000..5f40498c2ff
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_descent.dm
@@ -0,0 +1,216 @@
+/**
+ * # The descent, seen from aboard
+ *
+ * Laid out against the moment the hull is expected to touch down (T), in the order a falling ship meets things:
+ *
+ * | from | what |
+ * |----------|-----------------------------------------------------------------------------------------|
+ * | start | the planet under the ship, swelling until its rim has left the screen |
+ * | T-9.2s | heat: the hull's edge glows and sheds sparks, streaks fly out past it |
+ * | T-8.4s | the planet thins into the colour of its own sky |
+ * | T-6.2s | into the planet's cloud: everything white, mist streaming past |
+ * | T-5.2s | out of the cloud's underside over the real ground, small and hazy, rushing up |
+ * | T-4.6s | as the cloud thins the ground's own light takes over from the open sky's: a cave is dark |
+ * | T-2.7s | the light on the hull's edge turns from the stars' to the ground's |
+ * | T-1.4s | the thrusters reach the ground: dust blows out from under the hull |
+ * | T-0.3s | the ground is at full size; the ship hangs on its thrusters until the hull really moves |
+ *
+ * The ground is the real terrain around the berth, so when the hull moves onto it nothing outside changes.
+ */
+
+/// Size of the ground when it comes out of the cloud
+#define DESCENT_GROUND_START 0.3
+
+/// The view from aboard, for the length of this descent
+/datum/landing_animation/var/datum/landing_view/descent/inside_view
+
+/datum/landing_view/descent
+ /// world.time the hull is expected to move
+ var/touchdown
+
+/**
+ * * touchdown - world.time the hull is expected to move
+ * * planet_size - the size the planet already has under the ship (see /datum/landing_view/hover); null if it
+ * is not there yet and has to come up from afar
+ */
+/datum/landing_view/descent/New(obj/docking_port/mobile/shuttle, list/hull_turfs, list/berth_turfs, rotation, obj/structure/overmap/site, touchdown, planet_size)
+ . = ..()
+ if(ended)
+ return
+ src.touchdown = touchdown
+ palette = landing_view_palette_for(site)
+ add_planet(planet_size)
+ add_heat()
+ add_clouds()
+ add_ground()
+ sync_viewers()
+ addtimer(CALLBACK(src, PROC_REF(fade_light), 0, 1, 2.2 SECONDS), max(0, touchdown - 2.7 SECONDS - world.time), TIMER_DELETE_ME)
+ cue_at(touchdown - 9.2 SECONDS, 'voidcrew/sound/effects/landing/entry.ogg', 65, 4.5 SECONDS, 0.12)
+ cue_at(touchdown - 6.6 SECONDS, 'voidcrew/sound/effects/landing/clouds.ogg', 45, 1.4 SECONDS, 0.05)
+ cue_at(touchdown - 4.6 SECONDS, 'voidcrew/sound/effects/landing/thrusters.ogg', 50)
+
+/// The planet whole, growing under the ship, then thinning into its own sky
+/datum/landing_view/descent/proc/add_planet(planet_size)
+ var/now = world.time
+ var/list/planet = new_planet()
+ var/list/grains = planet[1]
+ var/datum/landing_view_piece/whole = grains[1][1]
+ var/datum/landing_track/size = whole.scale
+ size.mark(now, planet_size || LANDING_HOVER_FAR)
+ size.mark(touchdown - 6.2 SECONDS, 6.4, LANDING_CURVE_IN)
+ var/datum/landing_track/opacity = new
+ if(planet_size)
+ opacity.mark(now, 255)
+ else
+ opacity.mark(now, 0)
+ opacity.mark(now + 0.6 SECONDS, 255)
+ // solid until the sky has closed over it: a planet that fades lets the stars show through it
+ opacity.mark(touchdown - 6.2 SECONDS, 255)
+ opacity.mark(touchdown - 6.1 SECONDS, 0)
+ chain_detail(grains, size, opacity, LANDING_PLANET_DETAIL)
+ var/datum/landing_view_piece/shade = planet[2]
+ shade.alpha = opacity
+ show(shade)
+
+ var/datum/landing_view_piece/air = new_air(whole)
+ if(planet_size)
+ air.alpha.mark(now, 235)
+ else
+ air.alpha.mark(now, 0)
+ air.alpha.mark(now + 0.6 SECONDS, 235)
+ air.alpha.mark(touchdown - 6.2 SECONDS, 235)
+ air.alpha.mark(touchdown - 6.1 SECONDS, 0)
+ show(air)
+
+ // inside its air: the sky's own colour over everything, until the ground shows under it
+ var/datum/landing_view_piece/sky = add_sky(LANDING_VIEW_LAYER_SKY, fill = palette.sky)
+ sky.alpha.mark(touchdown - 8.4 SECONDS, 0)
+ sky.alpha.mark(touchdown - 6.2 SECONDS, 255, LANDING_CURVE_BOTH)
+ sky.alpha.mark(touchdown - 5.2 SECONDS, 255)
+ sky.alpha.mark(touchdown - 4.4 SECONDS, 0)
+ show(sky)
+
+/// Heat of entry: streaks flying out past the hull, and the hull's edge glowing
+/datum/landing_view/descent/proc/add_heat()
+ for(var/turned in list(0, 137))
+ var/datum/landing_view_piece/streaks = add_sky(LANDING_VIEW_LAYER_HEAT + 1, LANDING_VIEW_ICON, "streaks", LANDING_VIEW_ICON_SIZE)
+ streaks.sky.color = palette.heat
+ streaks.turn = turned
+ // they fly outward: each sheet grows, and the second follows the first so there is always one coming
+ var/lead = turned ? 0.9 SECONDS : 0
+ streaks.scale.mark(touchdown - 9.2 SECONDS + lead, 1.5)
+ streaks.scale.mark(touchdown - 5.6 SECONDS + lead, 3.4)
+ streaks.alpha.mark(touchdown - 9.2 SECONDS + lead, 0)
+ streaks.alpha.mark(touchdown - 8.4 SECONDS + lead, 255)
+ streaks.alpha.mark(touchdown - 6.6 SECONDS, 255)
+ streaks.alpha.mark(touchdown - 5.6 SECONDS, 0)
+ show(streaks)
+ // and the glow of it over everything outside, flaring and sinking
+ // laid over, not added: added to a bright sky it does not show at all
+ var/datum/landing_view_piece/burn = add_sky(LANDING_VIEW_LAYER_HEAT, fill = palette.heat)
+ burn.alpha.mark(touchdown - 9.2 SECONDS, 0)
+ var/flare = TRUE
+ for(var/moment = touchdown - 8.6 SECONDS, moment <= touchdown - 6.4 SECONDS, moment += 0.4 SECONDS)
+ burn.alpha.mark(moment, flare ? 115 : 65, LANDING_CURVE_BOTH)
+ flare = !flare
+ burn.alpha.mark(touchdown - 5.6 SECONDS, 0)
+ show(burn)
+ heat_hull(touchdown - 9.2 SECONDS, touchdown - 5.6 SECONDS)
+
+/// The one layer of cloud: the planet's own, seen from afar on the planet itself, and from inside as white
+/datum/landing_view/descent/proc/add_clouds()
+ var/datum/landing_view_piece/inside = add_sky(LANDING_VIEW_LAYER_CLOUD + 1, fill = palette.cloud)
+ inside.alpha.mark(touchdown - 6.2 SECONDS, 0)
+ inside.alpha.mark(touchdown - 5 SECONDS, 250, LANDING_CURVE_IN)
+ inside.alpha.mark(touchdown - 4.6 SECONDS, 250)
+ inside.alpha.mark(touchdown - 3.8 SECONDS, 0, LANDING_CURVE_OUT)
+ show(inside)
+
+ // mist streaming past while the ship is inside it, so the white is never still
+ var/datum/landing_view_piece/mist = add_sky(LANDING_VIEW_LAYER_CLOUD + 1.5, LANDING_VIEW_ICON, "wisps", LANDING_VIEW_ICON_SIZE)
+ mist.sky.color = palette.sky
+ mist.turn = 73
+ mist.scale.mark(touchdown - 6 SECONDS, 2.2)
+ mist.scale.mark(touchdown - 4 SECONDS, 6.5)
+ mist.alpha.mark(touchdown - 6 SECONDS, 0)
+ mist.alpha.mark(touchdown - 5 SECONDS, 120)
+ mist.alpha.mark(touchdown - 4.5 SECONDS, 120)
+ mist.alpha.mark(touchdown - 4 SECONDS, 0)
+ show(mist)
+
+ // haze between the ship and the ground, clearing as it comes down
+ var/datum/landing_view_piece/haze = add_sky(LANDING_VIEW_LAYER_HAZE, fill = palette.sky)
+ haze.alpha.mark(touchdown - 5.2 SECONDS, 0)
+ haze.alpha.mark(touchdown - 5 SECONDS, 170)
+ haze.alpha.mark(touchdown - 1.2 SECONDS, 0)
+ show(haze)
+
+/// The real ground, rushing up to full size, and the hull's shadow tightening on it
+/datum/landing_view/descent/proc/add_ground()
+ ground = add_picture()
+ ground.scale.mark(touchdown - 5.2 SECONDS, DESCENT_GROUND_START)
+ ground.scale.mark(touchdown - 0.3 SECONDS, 1, LANDING_CURVE_OUT)
+ // handed over as soon as it is made, clear and still, so that whatever a client has to fetch for it has
+ // come long before it is needed; seen once the sky has covered everything
+ ground.held_back = TRUE
+ bake_far(ground, CALLBACK(src, PROC_REF(show), ground))
+ addtimer(CALLBACK(src, PROC_REF(reveal), ground), max(0, touchdown - 5.4 SECONDS - world.time), TIMER_DELETE_ME)
+ // and the same ground close up, once it is near enough to tell the difference
+ close = add_picture()
+ chain_ground(ground, close)
+ // drawn as late as will do: weather comes and goes, and what it shows should be how the ground is as the hull lands
+ addtimer(CALLBACK(src, PROC_REF(bake_near), close, detail_reach(), CALLBACK(src, PROC_REF(show), close)), max(0, touchdown - 5.4 SECONDS - world.time), TIMER_DELETE_ME)
+
+ // past the reach of those pictures there is only cloud: the ground is seen through an opening in it
+ var/datum/landing_track/veil_alpha = veil_fade(ground.scale)
+ for(var/for_light in list(FALSE, TRUE))
+ var/datum/landing_view_piece/veil = add_picture()
+ veil.parts = cloud_veil(for_light)
+ veil.scale = ground.scale
+ veil.alpha = veil_alpha
+ veil.give_at = touchdown - 5.4 SECONDS
+ show(veil)
+ // and the light on it: the white of the cloud gives way to the ground as it is lit, dark if it is dark
+ light = add_picture()
+ light.scale = ground.scale
+ light.held_back = TRUE
+ // under the cloud's own light until the cloud thins: the white stays white, and the ground comes out of it lit as it is lit
+ var/datum/landing_track/cloud_light = new
+ cloud_light.mark(touchdown - 4.6 SECONDS, 255)
+ cloud_light.mark(touchdown - 3.8 SECONDS, 0, LANDING_CURVE_OUT)
+ add_daylight(cloud_light)
+ addtimer(CALLBACK(src, PROC_REF(bake_light), light, CALLBACK(src, PROC_REF(show), light)), max(0, touchdown - 6.6 SECONDS - world.time), TIMER_DELETE_ME)
+ addtimer(CALLBACK(src, PROC_REF(reveal), light), max(0, touchdown - 5 SECONDS - world.time), TIMER_DELETE_ME)
+
+ // the same shadow the people on the ground see spreading over the berth (see /datum/landing_animation)
+ shadow = add_picture()
+ shadow.parts = list(list(landing_view_shadow_look(berth_turfs, ground_x, ground_y), 0, 0, 1))
+ shadow.scale.mark(touchdown - 3 SECONDS, 1.35)
+ shadow.scale.mark(touchdown - 1 SECONDS, 1.15, LANDING_CURVE_BOTH)
+ shadow.scale.mark(touchdown, 1, LANDING_CURVE_OUT)
+ shadow.scale_with = ground.scale
+ // the sun is not straight overhead: from high up the shadow lies well off to one side, and it comes in
+ // under the hull as the hull comes down
+ shadow.slide_x.mark(touchdown - 5 SECONDS, -9)
+ shadow.slide_x.mark(touchdown - 0.4 SECONDS, 0, LANDING_CURVE_OUT)
+ shadow.slide_y.mark(touchdown - 5 SECONDS, 9)
+ shadow.slide_y.mark(touchdown - 0.4 SECONDS, 0, LANDING_CURVE_OUT)
+ shadow.alpha.mark(touchdown - 5 SECONDS, 0)
+ shadow.alpha.mark(touchdown - 4.4 SECONDS, 100)
+ shadow.alpha.mark(touchdown - 3 SECONDS, 110)
+ shadow.alpha.mark(touchdown - 1.2 SECONDS, 140, LANDING_CURVE_BOTH)
+ // and it is under the hull by the time the hull is down: a landed ship has no rim of shadow round it,
+ // and one that went out as it landed would show
+ shadow.alpha.mark(touchdown - 0.5 SECONDS, 110)
+ shadow.alpha.mark(touchdown - 0.1 SECONDS, 0, LANDING_CURVE_IN)
+ show(shadow)
+
+/// The hull has started to move onto the berth
+/datum/landing_view/descent/proc/touchdown()
+ return
+
+/// The hull is down: the people aboard are looking at the real ground now
+/datum/landing_view/descent/proc/landed()
+ qdel(src)
+
+#undef DESCENT_GROUND_START
diff --git a/voidcrew/modules/landing_animation/landing_view_ground.dm b/voidcrew/modules/landing_animation/landing_view_ground.dm
new file mode 100644
index 00000000000..320b44bfac5
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_ground.dm
@@ -0,0 +1,912 @@
+/**
+ * The ground around a berth, as pictures for the landing view (see landing_view.dm).
+ *
+ * Three pictures of the same ground, drawn about the same middle, each finer and reaching less far:
+ *
+ * - From afar: two images of the country around the berth in its own colours: a couple of pixels to the tile
+ * for the whole of it, and half full size for the part that is ever seen clearly (see cloud_veil()). Single
+ * sprites, so the whole planet can be on the screen at once for nothing.
+ * - Close up: the real tiles near the berth and everything standing on them, copied, in small chunks. Exact, so
+ * the hull can move onto it without anything changing, and costly to draw, so it is only shown once the
+ * ground is near, and each viewer only holds the chunks their own screen can show
+ * (see /datum/landing_view/proc/give_picture).
+ *
+ * The first fades into the second as the ground comes up (see chain_ground()).
+ *
+ * None of them carries any light. The view is lit like the rest of the game, by the lighting plate, which over
+ * transit space is full light. So the light on the ground is a picture too (see bake_light()): two small images
+ * of it, drawn on a plane of their own over the lighting of the transit space around the hull. The game's own
+ * lighting then does the rest, for every kind of eye: a cave is as dark to its crew, and as dim to a ghost, in
+ * the picture as it will be when the hull is down in it.
+ */
+
+/// Tiles per side of one chunk of the close-up picture
+#define LANDING_VIEW_CHUNK 8
+/// How far from the hull's box the cordon strip at the edge of a site is still drawn in the close-up picture
+#define LANDING_VIEW_CORDON_REACH 14
+/// The two pictures from afar: how far each reaches from the berth's middle, in tiles, and its pixels to the tile
+#define LANDING_AERIAL_FAR_REACH 64
+#define LANDING_AERIAL_FAR_GRAIN 2
+#define LANDING_AERIAL_NEAR_GRAIN 16
+/// How long a picture from afar may be used again for the same berth
+#define LANDING_AERIAL_KEEP (10 MINUTES)
+/// The two pictures of the light: how far each reaches from the berth's middle, in tiles, and its pixels to the tile
+#define LANDING_LIGHT_FAR_REACH 64
+#define LANDING_LIGHT_FAR_GRAIN 2
+#define LANDING_LIGHT_NEAR_REACH 36
+#define LANDING_LIGHT_NEAR_GRAIN 4
+/// The ground's size between which the close-up picture fades in over the ones from afar
+#define LANDING_DETAIL_FROM 0.75
+#define LANDING_DETAIL_FULL 0.9
+/// The most tiles a viewer sees each way; with LANDING_DETAIL_FROM it sets how far the close-up picture has to reach
+#define LANDING_DETAIL_SIGHT 14
+/// And the most it will reach past the hull's box, however big the hull
+#define LANDING_DETAIL_MOST 30
+
+/// How far past the hull's box the close-up picture reaches
+/datum/landing_view/proc/detail_reach()
+ var/half = max(ground_half_w, ground_half_h)
+ return min(LANDING_DETAIL_MOST, CEILING((half + LANDING_DETAIL_SIGHT) / LANDING_DETAIL_FROM - half, 1))
+
+/**
+ * Sets [close]'s opacity and the moments it is handed to viewers and taken back, from the size of the ground
+ * over time: the close-up picture is there while the ground is big enough to tell it from the picture from afar.
+ * * far - the picture from afar, whose size track both share
+ */
+/datum/landing_view/proc/chain_ground(datum/landing_view_piece/far, datum/landing_view_piece/close)
+ close.scale = far.scale
+ close.slide_x = far.slide_x
+ close.slide_y = far.slide_y
+ close.alpha = new
+ close.cull_from = LANDING_DETAIL_FROM
+ var/datum/landing_track/size = far.scale
+ var/start = size.times[1]
+ var/finish = size.end_time()
+ var/first_seen
+ var/last_seen
+ var/last_share
+ var/last_when
+ for(var/moment = start, moment < finish + 1, moment += 1)
+ var/when = min(moment, finish)
+ var/share = clamp((size.at(when) - LANDING_DETAIL_FROM) / (LANDING_DETAIL_FULL - LANDING_DETAIL_FROM), 0, 1)
+ if(isnull(last_share))
+ close.alpha.mark(when, share * 255)
+ else if(share != last_share)
+ // leaving a level stretch: pin where it ended. Arriving on one: pin where it begins.
+ if(last_share <= 0 || last_share >= 1)
+ close.alpha.mark(last_when, last_share * 255)
+ if(share <= 0 || share >= 1)
+ close.alpha.mark(when, share * 255)
+ last_share = share
+ last_when = when
+ if(share > 0)
+ first_seen ||= when
+ last_seen = when
+ close.alpha.mark(finish, last_share * 255)
+ if(isnull(first_seen))
+ close.give_at = INFINITY
+ return
+ // held from the start if it starts in sight, to the end if it ends in sight. Handed over a little early,
+ // still clear, a few chunks a tick
+ close.give_at = first_seen > start ? first_seen - 0.8 SECONDS : 0
+ close.drop_at = last_seen < finish ? last_seen + 2 : INFINITY
+
+/**
+ * Before the ground's motion is known (a hull still on its berth), its pictures can be handed out, clear and
+ * still, so the people aboard already hold them when it lifts.
+ */
+/datum/landing_view/proc/hold_ground(datum/landing_view_piece/far, datum/landing_view_piece/close, datum/landing_view_piece/light)
+ far.held_back = TRUE
+ close.held_back = TRUE
+ close.cull_from = LANDING_DETAIL_FROM
+ light.held_back = TRUE
+
+/**
+ * Builds the pictures of the ground from afar and hands them to [piece]. Takes a few ticks; [then] is called
+ * when it is done.
+ */
+/datum/landing_view/proc/bake_far(datum/landing_view_piece/piece, datum/callback/then)
+ set waitfor = FALSE
+ var/tone = ground_tone() || palette?.sky || "#808080"
+ var/list/berth_set = list()
+ for(var/turf/berth_turf as anything in berth_turfs)
+ berth_set[berth_turf] = TRUE
+ var/middle_x = round(ground_x)
+ var/middle_y = round(ground_y)
+ // under them and beyond their edges: more of the same, out of focus
+ var/mutable_appearance/sheet = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR)
+ sheet.color = tone
+ sheet.transform = matrix().Scale(400)
+ var/mutable_appearance/beyond = landing_view_world_look(new /mutable_appearance, LANDING_VIEW_LAYER_GROUND)
+ beyond.overlays = list(sheet)
+ var/list/parts = list(list(beyond, 0, 0, 1, 0))
+ // the finer one as far as the ground is ever seen clearly, and no further: it is the costly one to make and to fetch
+ var/list/grains = list(list(LANDING_AERIAL_FAR_REACH, LANDING_AERIAL_FAR_GRAIN), list(veil_hole(), LANDING_AERIAL_NEAR_GRAIN))
+ for(var/rank in 1 to length(grains))
+ var/list/grain = grains[rank]
+ var/icon/aerial = landing_view_aerial(middle_x, middle_y, ground_z, berth_set, tone, grain[1], grain[2])
+ if(QDELETED(src) || ended)
+ return
+ if(!aerial)
+ continue
+ var/size = aerial.Width()
+ var/mutable_appearance/country = mutable_appearance(aerial)
+ // its own middle on the image's, and drawn at a tile's worth of pixels to the tile
+ country.pixel_w = -(size - ICON_SIZE_X) / 2
+ country.pixel_z = -(size - ICON_SIZE_Y) / 2
+ country.transform = matrix().Scale(ICON_SIZE_X / grain[2])
+ var/mutable_appearance/far = landing_view_world_look(new /mutable_appearance, LANDING_VIEW_LAYER_GROUND + 0.02 * rank)
+ far.overlays = list(country)
+ // the picture's middle is the corner between four tiles; ours is the middle of the hull's box
+ parts += list(list(far, (middle_x - 0.5 - ground_x) * ICON_SIZE_X, (middle_y - 0.5 - ground_y) * ICON_SIZE_Y, 1, 0))
+ piece.parts = parts
+ then?.Invoke()
+
+/**
+ * A small picture of the ground for [reach] tiles each way from [mid_x], [mid_y], [grain] pixels to the tile:
+ * every tile and what stands on it, shrunk, in its own colours with no light on it (see bake_light()). Kept a
+ * while and used again for the same spot. Takes a few ticks. Null if it could not be made.
+ * * under_hull - the berth's turfs: where a hull stands on them, the ground it stands on is drawn instead
+ * * fill_tone - the colour of everything that is not this site's ground
+ */
+/proc/landing_view_aerial(mid_x, mid_y, z, list/under_hull, fill_tone, reach, grain)
+ var/static/list/kept = list()
+ var/key = "[mid_x],[mid_y],[z],[reach],[grain]"
+ var/list/had = kept[key]
+ if(had && had[2] > world.time)
+ return had[1]
+ var/turf/middle = locate(mid_x, mid_y, z)
+ if(!middle)
+ return null
+ var/datum/own_region = map_region_for_turf(middle)
+ var/static/list/unlit = list(1, 1, 1)
+ var/side = reach * 2 * grain
+ // every pixel, top row first
+ var/list/cells = new /list(side * side)
+ var/low_x = mid_x - reach
+ var/low_y = mid_y - reach
+ // tiles with something standing on them, north to south, so what stands nearer is drawn over what is behind
+ var/list/turf/occupied = list()
+ // tiles whose own icon reaches past them (grass and its fringe) -> list(its tones, cells it is drawn right, cells up)
+ var/list/fringed = list()
+ for(var/tile_y = mid_y + reach - 1, tile_y >= low_y, tile_y--)
+ var/cell_y = (tile_y - low_y) * grain
+ for(var/tile_x in low_x to mid_x + reach - 1)
+ var/turf/ground = locate(tile_x, tile_y, z)
+ var/list/tones
+ // how far the icon is drawn from the tile's corner, in pixels
+ var/off_x = 0
+ var/off_y = 0
+ if(ground && !istype(ground, /turf/cordon) && !(own_region && map_region_excludes_turf(own_region, ground)))
+ var/turf/bare = under_hull[ground] ? landing_view_ground_under(ground) : null
+ if(bare)
+ tones = landing_view_tones(initial(bare.icon), initial(bare.icon_state), SOUTH, null, unlit, grain)
+ off_x = initial(bare.pixel_x)
+ off_y = initial(bare.pixel_y)
+ else if(!under_hull[ground] || !istype(ground.loc, /area/shuttle))
+ tones = landing_view_tones(ground.icon, ground.icon_state, ground.dir, ground.color, unlit, grain)
+ off_x = ground.pixel_x + ground.pixel_w
+ off_y = ground.pixel_y + ground.pixel_z
+ if(!under_hull[ground] && length(ground.contents))
+ occupied += ground
+ var/cell_x = (tile_x - low_x) * grain
+ var/tone_rows = length(tones)
+ var/shift_x = round(off_x * grain / ICON_SIZE_X, 1)
+ var/shift_y = round(off_y * grain / ICON_SIZE_Y, 1)
+ if(tone_rows && (shift_x || shift_y || tone_rows > grain || length(tones[1]) > grain))
+ fringed[ground] = list(tones, shift_x, shift_y)
+ for(var/row in 1 to grain)
+ var/from_row = row - shift_y
+ var/list/line = (from_row >= 1 && from_row <= tone_rows) ? tones[from_row] : null
+ var/line_length = length(line)
+ var/base = (side - cell_y - row) * side + cell_x
+ for(var/col in 1 to grain)
+ var/from_col = col - shift_x
+ cells[base + col] = (from_col >= 1 && from_col <= line_length && line[from_col]) || fill_tone
+ if(TICK_CHECK)
+ stoplag()
+ // the fringes, over the tiles beside them
+ for(var/turf/ground as anything in fringed)
+ var/list/fringe = fringed[ground]
+ landing_view_stamp(cells, side, fringe[1], (ground.x - low_x) * grain + fringe[2], (ground.y - low_y) * grain + fringe[3])
+ if(TICK_CHECK)
+ stoplag()
+ for(var/turf/ground as anything in occupied)
+ var/list/standing
+ for(var/atom/movable/thing as anything in ground)
+ // nothing that moves about, and nothing too small to tell from up here
+ if(ismob(thing) || isitem(thing) || thing.invisibility > SEE_INVISIBLE_LIVING || !thing.icon || thing.alpha < 128)
+ continue
+ if(istype(thing, /obj/effect/abstract) || istype(thing, /obj/effect/temp_visual) || istype(thing, /obj/docking_port))
+ continue
+ var/true_plane = PLANE_TO_TRUE(thing.plane)
+ if(true_plane < FLOOR_PLANE || true_plane > ABOVE_GAME_PLANE)
+ continue
+ // lowest first
+ var/place = 1
+ for(var/atom/movable/other as anything in standing)
+ if(other.layer > thing.layer)
+ break
+ place++
+ LAZYINITLIST(standing)
+ standing.Insert(place, thing)
+ if(!standing)
+ continue
+ for(var/atom/movable/thing as anything in standing)
+ var/list/tones = landing_view_tones(thing.icon, thing.icon_state, thing.dir, thing.color, unlit, grain)
+ var/shift_x = (ground.x - low_x) * grain + round((thing.pixel_x + thing.pixel_w) * grain / ICON_SIZE_X, 1)
+ var/shift_y = (ground.y - low_y) * grain + round((thing.pixel_y + thing.pixel_z) * grain / ICON_SIZE_Y, 1)
+ landing_view_stamp(cells, side, tones, shift_x, shift_y)
+ if(TICK_CHECK)
+ stoplag()
+ var/path = "data/landing_view/[z]_[mid_x]_[mid_y]_[grain].png"
+ if(!fexists("data/landing_view/made"))
+ text2file("", "data/landing_view/made") // makes the folder
+ var/failed = rustg_dmi_create_png(path, "[side]", "[side]", cells.Join(""))
+ if(failed)
+ stack_trace("No picture of the ground for a landing view: [failed]")
+ return null
+ var/icon/aerial = new(path)
+ // gone over once by the engine, which then keeps it as a picture of its own making: the few colours it has
+ // make that a far smaller file for a client to fetch than the one written above
+ aerial.Blend("#ffffff", ICON_MULTIPLY)
+ kept[key] = list(aerial, world.time + LANDING_AERIAL_KEEP)
+ landing_view_sheet(forget = TRUE)
+ return aerial
+
+/// Draws [tones] (see landing_view_tones()) into a picture's [cells], its lower left corner [shift_x] cells in and [shift_y] up
+/proc/landing_view_stamp(list/cells, side, list/tones, shift_x, shift_y)
+ for(var/row in 1 to length(tones))
+ var/at_y = shift_y + row - 1
+ if(at_y < 0 || at_y >= side)
+ continue
+ var/list/line = tones[row]
+ var/base = (side - 1 - at_y) * side + shift_x
+ for(var/col in 1 to length(line))
+ var/tone = line[col]
+ if(!tone || shift_x + col < 1 || shift_x + col > side)
+ continue
+ cells[base + col] = tone
+
+/// The kind of ground a hull standing on [ground] landed on, if one stands there
+/proc/landing_view_ground_under(turf/ground)
+ var/list/under = ground.baseturfs
+ if(!islist(under))
+ return null
+ var/marker = under.Find(/turf/baseturf_skipover/shuttle)
+ return marker > 1 ? under[marker - 1] : null
+
+/**
+ * An icon state shrunk to [grain] pixels to the tile, as it looks under [light] (see landing_view_light_factor())
+ * and tinted [tint]: its rows, bottom row first, each a list of colours with null where nothing is drawn.
+ * Worked out once for each look.
+ */
+/proc/landing_view_tones(icon_file, state, dir, tint, list/light, grain)
+ var/static/list/known = list()
+ // a sixteenth of full light is as fine as anyone can tell
+ var/red = round(light[1] * 16)
+ var/green = round(light[2] * 16)
+ var/blue = round(light[3] * 16)
+ if(!istext(tint))
+ tint = null
+ var/key = "[icon_file]|[state]|[dir]|[grain]|[tint]|[red],[green],[blue]"
+ var/list/tones = known[key]
+ if(tones)
+ return tones
+ var/list/tint_parts = tint ? rgb2num(tint) : null
+ var/red_share = red / 16 * (tint_parts ? tint_parts[1] / 255 : 1)
+ var/green_share = green / 16 * (tint_parts ? tint_parts[2] / 255 : 1)
+ var/blue_share = blue / 16 * (tint_parts ? tint_parts[3] / 255 : 1)
+ tones = list()
+ for(var/list/line as anything in landing_view_icon_grid(icon_file, state, dir, grain))
+ var/list/lit = new /list(length(line))
+ for(var/col in 1 to length(line))
+ var/list/cell = line[col]
+ if(cell)
+ // sixteen levels of each: few enough colours that the picture is a small file for a client to fetch
+ lit[col] = rgb(round(cell[1] * red_share, 17), round(cell[2] * green_share, 17), round(cell[3] * blue_share, 17))
+ tones += list(lit)
+ known[key] = tones
+ return tones
+
+/**
+ * An icon state shrunk to [grain] pixels to the tile: its rows, bottom row first, each a list of
+ * list(red, green, blue) with null where it is clear. Not kept: landing_view_tones() keeps what it makes of it.
+ */
+/proc/landing_view_icon_grid(icon_file, state, dir, grain)
+ // some things keep a bitmask in their dir (pipes), and asking an icon for a pixel facing a way that is no
+ // way at all never comes back
+ var/static/list/real_dirs = list(NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST)
+ if(!(dir in real_dirs))
+ dir = SOUTH
+ var/list/grid = list()
+ if(!icon_file)
+ return grid
+ var/icon/sample = landing_view_sheet(icon_file)
+ var/width = sample.Width()
+ var/height = sample.Height()
+ var/stride = ICON_SIZE_X / grain
+ var/near = 1 + round(stride * 0.3)
+ var/far = 1 + round(stride * 0.7)
+ for(var/row in 1 to CEILING(height / stride, 1))
+ var/list/line = new /list(CEILING(width / stride, 1))
+ var/from_y = (row - 1) * stride
+ for(var/col in 1 to length(line))
+ var/from_x = (col - 1) * stride
+ // two pixels on the cell's diagonal
+ var/list/total
+ var/found = 0
+ for(var/reach in list(near, far))
+ var/pixel = sample.GetPixel(min(width, from_x + reach), min(height, from_y + reach), state, dir, 1)
+ if(!pixel)
+ continue
+ var/list/parts = rgb2num(pixel)
+ if(length(parts) > 3 && parts[4] < 128)
+ continue
+ if(total)
+ total[1] += parts[1]
+ total[2] += parts[2]
+ total[3] += parts[3]
+ else
+ total = list(parts[1], parts[2], parts[3])
+ found++
+ if(found > 1)
+ total[1] /= found
+ total[2] /= found
+ total[3] /= found
+ line[col] = total
+ grid += list(line)
+ return grid
+
+/**
+ * One icon for a whole icon file, read a state at a time: cutting each state out into an icon of its own is slow.
+ * Held only while a picture is being made.
+ * * forget - let go of every icon held
+ */
+/proc/landing_view_sheet(icon_file, forget = FALSE)
+ var/static/list/sheets = list()
+ if(forget)
+ sheets = list()
+ return null
+ var/icon/sheet = sheets["[icon_file]"]
+ if(!sheet)
+ sheet = icon(icon_file)
+ sheets["[icon_file]"] = sheet
+ return sheet
+
+/// How much of each of red, green and blue reaches [ground], each 0-1
+/proc/landing_view_light_factor(turf/ground)
+ var/static/list/full = list(1, 1, 1)
+ var/static/list/none = list(0, 0, 0)
+ var/area/ground_area = ground.loc
+ var/list/day
+ if(ground_area.base_lighting_alpha)
+ var/list/parts = rgb2num(ground_area.base_lighting_color == COLOR_STARLIGHT ? GLOB.starlight_color : ground_area.base_lighting_color)
+ var/strength = ground_area.base_lighting_alpha / 255 / 255
+ day = list(parts[1] * strength, parts[2] * strength, parts[3] * strength)
+ if(!ground.lighting_object)
+ if(day)
+ return day
+ return (ground_area.static_lighting && !isspaceturf(ground)) ? none : full
+ var/own = ground.get_lumcount()
+ if(!day)
+ return list(own, own, own)
+ return list(min(1, day[1] + own), min(1, day[2] + own), min(1, day[3] + own))
+
+/**
+ * The tone of the ground around the berth: the colour of a few tiles of it, some way out all round, as they are
+ * lit. Null if there is none to be found.
+ */
+/datum/landing_view/proc/ground_tone()
+ var/datum/own_region = map_region_for_turf(berth_turfs[1])
+ var/list/total = list(0, 0, 0)
+ var/found = 0
+ for(var/bearing in 0 to 315 step 45)
+ for(var/far in list(10, 22, 34))
+ var/turf/ground = locate(round(ground_x + sin(bearing) * (ground_half_w + far)), round(ground_y + cos(bearing) * (ground_half_h + far)), ground_z)
+ if(!ground || isclosedturf(ground) || istype(ground, /turf/cordon) || (own_region && map_region_excludes_turf(own_region, ground)))
+ continue
+ for(var/list/line as anything in landing_view_tones(ground.icon, ground.icon_state, ground.dir, ground.color, landing_view_light_factor(ground), LANDING_AERIAL_FAR_GRAIN))
+ for(var/tone in line)
+ if(!tone)
+ continue
+ var/list/parts = rgb2num(tone)
+ total[1] += parts[1]
+ total[2] += parts[2]
+ total[3] += parts[3]
+ found++
+ if(!found)
+ return null
+ return rgb(total[1] / found, total[2] / found, total[3] / found)
+
+/**
+ * Builds the close-up picture of the ground around the berth and adds it to [piece]'s parts. Takes a few ticks;
+ * [then] is called when it is done.
+ * * reach - how many tiles past the hull's box the picture goes
+ * * which - LANDING_GROUND_ALL, or one of the two halves a takeoff draws it in: the ground around the hull
+ * before it lifts, and the ground under it once it has
+ * * in_one_go - build it all now, however long it takes, instead of over a few ticks
+ */
+/datum/landing_view/proc/bake_near(datum/landing_view_piece/piece, reach, datum/callback/then, which = LANDING_GROUND_ALL, in_one_go = FALSE)
+ set waitfor = FALSE
+ var/reach_x = CEILING(ground_half_w + reach, LANDING_VIEW_CHUNK)
+ var/reach_y = CEILING(ground_half_h + reach, LANDING_VIEW_CHUNK)
+ // the edge of a site's ground is a strip of cordon. Near the berth it is drawn, as it will be seen once the
+ // hull is down; further off it is left out, so the ground does not end in a painted line seen from above
+ var/list/cordon_box = list(ground_x - ground_half_w - LANDING_VIEW_CORDON_REACH, ground_y - ground_half_h - LANDING_VIEW_CORDON_REACH, ground_x + ground_half_w + LANDING_VIEW_CORDON_REACH, ground_y + ground_half_h + LANDING_VIEW_CORDON_REACH)
+ var/list/parts = list()
+ // the chunks the hull's own box touches
+ var/under_x = CEILING(ground_half_w + 1, LANDING_VIEW_CHUNK)
+ var/under_y = CEILING(ground_half_h + 1, LANDING_VIEW_CHUNK)
+ var/datum/own_region = map_region_for_turf(berth_turfs[1])
+ // area -> the weather over it, found once
+ var/list/weather_by_area = list()
+ // a hull coming down crushes whatever is rooted on its berth (see /turf/proc/toShuttleMove): a tree there
+ // would stand out past the hull in the picture, and be gone the moment it landed
+ var/list/crushed
+ if(which == LANDING_GROUND_ALL)
+ crushed = list()
+ for(var/turf/berth_turf as anything in berth_turfs)
+ crushed[berth_turf] = TRUE
+ var/middle_x = round(ground_x)
+ var/middle_y = round(ground_y)
+ for(var/chunk_x = middle_x - reach_x, chunk_x < middle_x + reach_x, chunk_x += LANDING_VIEW_CHUNK)
+ for(var/chunk_y = middle_y - reach_y, chunk_y < middle_y + reach_y, chunk_y += LANDING_VIEW_CHUNK)
+ if(which != LANDING_GROUND_ALL)
+ var/under_hull = chunk_x >= middle_x - under_x && chunk_x < middle_x + under_x && chunk_y >= middle_y - under_y && chunk_y < middle_y + under_y
+ if(under_hull != (which == LANDING_GROUND_UNDER))
+ continue
+ var/list/chunk = landing_view_chunk(chunk_x, chunk_y, ground_z, own_region, weather_by_area, cordon_box, crushed)
+ if(chunk)
+ var/centre_off_x = chunk_x + LANDING_VIEW_CHUNK / 2 - ground_x
+ var/centre_off_y = chunk_y + LANDING_VIEW_CHUNK / 2 - ground_y
+ // one part for each world plane it has anything on, floors lowest: every chunk's floor under
+ // whatever stands on any chunk
+ var/list/looks = chunk[1]
+ for(var/rank in 1 to length(looks))
+ if(!looks[rank])
+ continue
+ // the last number: how far it reaches from its middle, in tiles, whatever stands on it included
+ parts += list(list(landing_view_world_look(looks[rank], LANDING_VIEW_LAYER_GROUND + 0.1 + rank * 0.01), centre_off_x * ICON_SIZE_X, centre_off_y * ICON_SIZE_Y, 1, chunk[2]))
+ if(!in_one_go && TICK_CHECK)
+ stoplag()
+ if(QDELETED(src) || ended)
+ return
+ piece.parts = (piece.parts || list()) + parts
+ then?.Invoke()
+
+/// How far past the hull's box the ground is seen at most, in tiles: past that it is lost in the planet's haze
+#define LANDING_VEIL_PAST 17
+/// One billow of the cloud's edge, in tiles across, and how far apart they stand along it
+#define LANDING_VEIL_PUFF 16
+#define LANDING_VEIL_STEP 5
+/// How much further in the thinner row of billows stands
+#define LANDING_VEIL_SOFT 5
+/// The ground's size between which the cloud around it is there in full and gone
+#define LANDING_VEIL_FULL 0.8
+#define LANDING_VEIL_GONE 0.97
+
+/// The furthest from the berth's middle the ground is seen, in tiles
+/datum/landing_view/proc/veil_hole()
+ return round(max(ground_half_w, ground_half_h)) + LANDING_VEIL_PAST
+
+/**
+ * How far this site's own ground reaches from the berth's middle, in tiles, each way: list(east, west, north,
+ * south), none more than veil_hole(). A berth can stand right by the edge of its site, and past that edge
+ * there is nothing to show.
+ */
+/datum/landing_view/proc/ground_extent()
+ var/hole = veil_hole()
+ var/datum/own_region = map_region_for_turf(berth_turfs[1])
+ var/middle_x = round(ground_x)
+ var/middle_y = round(ground_y)
+ var/list/extent = list()
+ for(var/list/way as anything in list(list(1, 0), list(-1, 0), list(0, 1), list(0, -1)))
+ var/reach = hole
+ // along the middle of the hull's box and along both its sides
+ var/half_across = way[1] ? ground_half_h : ground_half_w
+ for(var/out in 1 to hole)
+ var/ended = FALSE
+ for(var/across in list(0, -round(half_across), round(half_across)))
+ var/turf/ground = locate(middle_x + way[1] * out + (way[2] ? across : 0), middle_y + way[2] * out + (way[1] ? across : 0), ground_z)
+ if(!ground || istype(ground, /turf/cordon) || isspaceturf(ground) || (own_region && map_region_excludes_turf(own_region, ground)))
+ ended = TRUE
+ break
+ if(ended)
+ reach = out - 1
+ break
+ extent += reach
+ return extent
+
+/**
+ * What the country around a landing site is lost in, seen from above: the planet's own mist, dust or smoke
+ * (see /datum/landing_view_palette/var/veil) over everything past the site's own ground, or past
+ * veil_hole() tiles from the berth's middle if the site goes on further. Billows along its edge, and a
+ * thinner row of them further in, so the ground fades into it. The pictures of the ground only reach so far,
+ * get coarser as they go, and end where the site ends; this lies over all of that, so no edge of any of them
+ * is ever seen. The opening widens as the ground comes up and closes in as it falls away.
+ * Returns the parts of a world picture.
+ * * for_light - the same shapes for the light plane, in the light of the country around the site (see country_light())
+ */
+/datum/landing_view/proc/cloud_veil(for_light = FALSE)
+ var/list/parts = list()
+ // lit as the country around the site is lit: bright mist over a pitch-dark site would glow
+ var/tone = for_light ? country_light() : (palette?.veil || COLOR_WHITE)
+ var/part_layer = for_light ? 3 : LANDING_VIEW_LAYER_GROUND + 0.6
+ var/list/extent = ground_extent()
+ // where the cloud's sheets begin each way: their billows reach half a billow further in, to just short of the site's edge
+ var/east = extent[1] + LANDING_VEIL_PUFF / 2 - 3
+ var/west = extent[2] + LANDING_VEIL_PUFF / 2 - 3
+ var/north = extent[3] + LANDING_VEIL_PUFF / 2 - 3
+ var/south = extent[4] + LANDING_VEIL_PUFF / 2 - 3
+ // four sheets around the opening: list(middle x, middle y, tiles wide, tiles high)
+ for(var/list/sheet_at as anything in list(list(east + 100, 0, 200, 600), list(-west - 100, 0, 200, 600), list(0, north + 100, 600, 200), list(0, -south - 100, 600, 200)))
+ var/mutable_appearance/sheet = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR)
+ sheet.color = tone
+ sheet.transform = matrix().Scale(sheet_at[3], sheet_at[4])
+ var/mutable_appearance/look = landing_view_world_look(new /mutable_appearance, part_layer)
+ if(for_light)
+ look.plane = LANDING_VIEW_LIGHT_PLANE
+ look.overlays = list(sheet)
+ parts += list(list(look, sheet_at[1] * ICON_SIZE_X, sheet_at[2] * ICON_SIZE_Y, 1, 0))
+ // billows all along its edge, each list(x, y, how big, how opaque), and a thinner, bigger row of them further in
+ var/list/spots = list()
+ for(var/along = -west, along <= east, along += LANDING_VEIL_STEP)
+ spots += list(list(along, north, 1, 1), list(along, -south, 1, 1))
+ spots += list(list(along + 2, north - LANDING_VEIL_SOFT, 1.3, 0.45), list(along + 2, -south + LANDING_VEIL_SOFT, 1.3, 0.45))
+ for(var/along = -south, along <= north, along += LANDING_VEIL_STEP)
+ spots += list(list(east, along, 1, 1), list(-west, along, 1, 1))
+ spots += list(list(east - LANDING_VEIL_SOFT, along + 2, 1.3, 0.45), list(-west + LANDING_VEIL_SOFT, along + 2, 1.3, 0.45))
+ var/turned = 0
+ for(var/list/spot as anything in spots)
+ var/mutable_appearance/puff = mutable_appearance(LANDING_VIEW_ICON, "puff", appearance_flags = RESET_COLOR)
+ puff.color = tone
+ puff.pixel_w = -(LANDING_VIEW_ICON_SIZE - ICON_SIZE_X) / 2
+ puff.pixel_z = -(LANDING_VIEW_ICON_SIZE - ICON_SIZE_Y) / 2
+ // no two alike: each turned and sized a little differently
+ turned += 67
+ var/matrix/billow = matrix()
+ billow.Scale(LANDING_VEIL_PUFF * ICON_SIZE_X / 361 * (0.85 + (turned % 40) / 100) * spot[3])
+ billow.Turn(turned)
+ puff.transform = billow
+ var/mutable_appearance/look = landing_view_world_look(new /mutable_appearance, part_layer + 0.01)
+ if(for_light)
+ look.plane = LANDING_VIEW_LIGHT_PLANE
+ look.overlays = list(puff)
+ parts += list(list(look, spot[1] * ICON_SIZE_X, spot[2] * ICON_SIZE_Y, spot[4], 0))
+ return parts
+
+/// The light the country around the berth lies in, as one colour: the light on a few tiles of it, some way out all round
+/datum/landing_view/proc/country_light()
+ var/datum/own_region = map_region_for_turf(berth_turfs[1])
+ var/list/total = list(0, 0, 0)
+ var/found = 0
+ for(var/bearing in 0 to 315 step 45)
+ for(var/far in list(6, 14, 22))
+ var/turf/ground = locate(round(ground_x + sin(bearing) * (ground_half_w + far)), round(ground_y + cos(bearing) * (ground_half_h + far)), ground_z)
+ if(!ground || istype(ground, /turf/cordon) || isspaceturf(ground) || (own_region && map_region_excludes_turf(own_region, ground)))
+ continue
+ var/list/light = landing_view_light_factor(ground)
+ total[1] += light[1]
+ total[2] += light[2]
+ total[3] += light[3]
+ found++
+ if(!found)
+ return COLOR_WHITE
+ return rgb(min(total[1] / found, 1) * 255, min(total[2] / found, 1) * 255, min(total[3] / found, 1) * 255)
+
+/**
+ * How opaque the cloud around the ground is over time, from the ground's [size]: whole while the ground is small,
+ * gone by the time it is full size, when what lies past the site's edge is whatever the game itself shows there.
+ */
+/datum/landing_view/proc/veil_fade(datum/landing_track/size)
+ var/datum/landing_track/fade = new
+ var/start = size.times[1]
+ var/finish = size.end_time()
+ for(var/moment = start, moment < finish + 2, moment += 2)
+ var/when = min(moment, finish)
+ fade.mark(when, clamp((LANDING_VEIL_GONE - size.at(when)) / (LANDING_VEIL_GONE - LANDING_VEIL_FULL), 0, 1) * 255)
+ return fade
+
+/// Readies [look] to be one part of a world picture
+/proc/landing_view_world_look(mutable_appearance/look, part_layer)
+ look.plane = LANDING_VIEW_PLANE
+ look.layer = part_layer
+ look.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ return look
+
+/**
+ * One chunk of the close-up picture: the planet tiles from [low_x], [low_y] up, one row and column past
+ * LANDING_VIEW_CHUNK so neighbouring chunks overlap and no seam opens between them when they are scaled.
+ * Drawn about its own middle, with everything standing on it, and no light on any of it (see bake_light()).
+ * Returns list(its looks, how far it reaches from its middle in tiles), or null if there is no ground there.
+ *
+ * Its looks are one for each world plane, floor first, and one more for the weather over it, null where it has
+ * nothing: chunks are drawn in no order, so a chunk drawn whole would paint its floor over the tree that leans
+ * in from the chunk beside it. The reach counts what stands on it: a tree's picture can be six tiles across,
+ * and a viewer who can see any of it has to be given the chunk it grows on.
+ * * own_region - the site the berth is in; ground belonging to another site is left out
+ * * weather_by_area - area -> landing_view_weather() of it, filled in as areas are met
+ * * cordon_box - list(low x, low y, high x, high y): cordon turfs outside it are left out
+ * * crushed - turfs whose contents are left out: the berth, under a hull that has yet to land on it
+ */
+/proc/landing_view_chunk(low_x, low_y, z, datum/own_region, list/weather_by_area, list/cordon_box, list/crushed)
+ var/centre_x = low_x + LANDING_VIEW_CHUNK / 2
+ var/centre_y = low_y + LANDING_VIEW_CHUNK / 2
+ // one group per world plane, floor first, as the world draws them (see /obj/effect/abstract/landing_proxy)
+ var/list/plane_parts = new /list(ABOVE_GAME_PLANE - FLOOR_PLANE + 1)
+ for(var/rank in 1 to length(plane_parts))
+ plane_parts[rank] = list()
+ var/found = FALSE
+ var/list/storm_parts = list()
+ // how far anything here reaches from the middle of the chunk, in pixels: its own tiles to begin with
+ var/reach = (LANDING_VIEW_CHUNK / 2 + 1) * ICON_SIZE_X
+ for(var/tile_x in low_x to low_x + LANDING_VIEW_CHUNK)
+ for(var/tile_y in low_y to low_y + LANDING_VIEW_CHUNK)
+ var/turf/ground = locate(tile_x, tile_y, z)
+ if(!ground || (own_region && map_region_excludes_turf(own_region, ground)))
+ continue
+ if(istype(ground, /turf/cordon) && (tile_x < cordon_box[1] || tile_y < cordon_box[2] || tile_x > cordon_box[3] || tile_y > cordon_box[4]))
+ continue
+ found = TRUE
+ var/offset_w = (tile_x - centre_x) * ICON_SIZE_X
+ var/offset_z = (tile_y - centre_y) * ICON_SIZE_Y
+ var/turf_plane = clamp(PLANE_TO_TRUE(ground.plane), FLOOR_PLANE, ABOVE_GAME_PLANE)
+ plane_parts[turf_plane - FLOOR_PLANE + 1] += landing_view_part(ground, offset_w, offset_z, TRUE)
+ for(var/atom/movable/thing as anything in (crushed?[ground] ? null : ground))
+ if(thing.invisibility > SEE_INVISIBLE_LIVING || !thing.icon || thing.alpha < 20)
+ continue
+ if(istype(thing, /obj/effect/abstract) || istype(thing, /obj/effect/temp_visual) || istype(thing, /obj/docking_port))
+ continue
+ var/true_plane = PLANE_TO_TRUE(thing.plane)
+ if(true_plane < FLOOR_PLANE || true_plane > ABOVE_GAME_PLANE)
+ continue
+ plane_parts[true_plane - FLOOR_PLANE + 1] += landing_view_part(thing, offset_w, offset_z, FALSE)
+ var/list/size = landing_view_icon_size(thing.icon)
+ if(size[1] > ICON_SIZE_X || size[2] > ICON_SIZE_Y || thing.pixel_x || thing.pixel_y || thing.pixel_w || thing.pixel_z)
+ // its picture's edges, from the middle of the chunk's middle tile
+ var/left = offset_w + thing.pixel_x + thing.pixel_w - ICON_SIZE_X / 2
+ var/bottom = offset_z + thing.pixel_y + thing.pixel_z - ICON_SIZE_Y / 2
+ reach = max(reach, -left, left + size[1], -bottom, bottom + size[2])
+ var/list/storm = weather_by_area[ground.loc]
+ if(isnull(storm))
+ storm = landing_view_weather(ground.loc)
+ weather_by_area[ground.loc] = storm
+ for(var/mutable_appearance/falling as anything in storm)
+ var/mutable_appearance/over_tile = new(falling)
+ over_tile.pixel_w = offset_w
+ over_tile.pixel_z = offset_z
+ storm_parts += over_tile
+ if(!found)
+ return null
+ // over everything standing there, as the world draws weather
+ plane_parts += list(storm_parts)
+ var/list/looks = new /list(length(plane_parts))
+ for(var/rank in 1 to length(plane_parts))
+ if(!length(plane_parts[rank]))
+ continue
+ var/mutable_appearance/plane_group = new()
+ plane_group.plane = FLOAT_PLANE
+ plane_group.appearance_flags = KEEP_TOGETHER
+ plane_group.overlays = plane_parts[rank]
+ looks[rank] = plane_group
+ return list(looks, reach / ICON_SIZE_X)
+
+/// The size of the pictures in an icon file, as list(width, height) in pixels. Looked up once for each file.
+/proc/landing_view_icon_size(icon_file)
+ var/static/list/known = list()
+ var/static/list/plain = list(ICON_SIZE_X, ICON_SIZE_Y)
+ if(!icon_file)
+ return plain
+ var/list/size = known["[icon_file]"]
+ if(!size)
+ var/icon/sheet = icon(icon_file)
+ size = list(sheet.Width(), sheet.Height())
+ known["[icon_file]"] = size
+ return size
+
+/// The weather falling on every tile of [ground_area] right now, as looks for a ground picture (none: an empty list)
+/proc/landing_view_weather(area/ground_area)
+ . = list()
+ for(var/mutable_appearance/over as anything in ground_area.overlays)
+ if(over.plane != WEATHER_PLANE)
+ continue
+ var/mutable_appearance/falling = new(over)
+ falling.plane = FLOAT_PLANE
+ falling.appearance_flags = NONE
+ . += falling
+
+/**
+ * A copy of [thing]'s look for a ground picture, shifted by [offset_w], [offset_z]: only what the world planes
+ * would draw of it, without its light or anything that glows on a plane of its own.
+ */
+/proc/landing_view_part(atom/thing, offset_w, offset_z, is_turf)
+ var/mutable_appearance/part = new(thing)
+ part.plane = FLOAT_PLANE
+ part.pixel_w += offset_w
+ part.pixel_z += offset_z
+ part.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ if(is_turf && length(part.underlays))
+ var/list/kept = list()
+ for(var/mutable_appearance/under as anything in part.underlays)
+ if(PLANE_TO_TRUE(under.plane) != LIGHTING_PLANE)
+ kept += under
+ part.underlays = kept
+ if(length(part.overlays))
+ var/list/kept
+ for(var/mutable_appearance/over as anything in part.overlays)
+ var/keep = !(over.appearance_flags & KEEP_APART)
+ if(keep && over.plane != FLOAT_PLANE)
+ var/true_plane = PLANE_TO_TRUE(over.plane)
+ keep = (true_plane >= FLOOR_PLANE && true_plane <= ABOVE_GAME_PLANE)
+ if(keep)
+ continue
+ kept ||= part.overlays.Copy()
+ kept -= over
+ if(kept)
+ part.overlays = kept
+ return part
+
+/**
+ * Builds the pictures of the light on the ground and hands them to [piece], whose parts go on the light plane.
+ * Takes a few ticks; [then] is called when it is done.
+ *
+ * What a landed hull's own lamps throw on dark ground beside it is not in them: on a dark site that light comes
+ * on as the hull touches down.
+ */
+/datum/landing_view/proc/bake_light(datum/landing_view_piece/piece, datum/callback/then)
+ set waitfor = FALSE
+ var/middle_x = round(ground_x)
+ var/middle_y = round(ground_y)
+ var/list/berth_set = list()
+ for(var/turf/berth_turf as anything in berth_turfs)
+ berth_set[berth_turf] = TRUE
+ var/list/parts = list()
+ var/list/grains = list(list(LANDING_LIGHT_FAR_REACH, LANDING_LIGHT_FAR_GRAIN), list(LANDING_LIGHT_NEAR_REACH, LANDING_LIGHT_NEAR_GRAIN))
+ for(var/rank in 1 to length(grains))
+ var/list/grain = grains[rank]
+ var/icon/light_map = light_map(middle_x, middle_y, grain[1], grain[2], berth_set)
+ if(QDELETED(src) || ended)
+ return
+ if(!light_map)
+ continue
+ var/size = light_map.Width()
+ var/mutable_appearance/sheet = mutable_appearance(light_map)
+ sheet.pixel_w = -(size - ICON_SIZE_X) / 2
+ sheet.pixel_z = -(size - ICON_SIZE_Y) / 2
+ sheet.transform = matrix().Scale(ICON_SIZE_X / grain[2])
+ var/mutable_appearance/look = landing_view_world_look(new /mutable_appearance, rank)
+ look.plane = LANDING_VIEW_LIGHT_PLANE
+ look.overlays = list(sheet)
+ parts += list(list(look, (middle_x - 0.5 - ground_x) * ICON_SIZE_X, (middle_y - 0.5 - ground_y) * ICON_SIZE_Y, 1, 0))
+ piece.parts = parts
+ then?.Invoke()
+
+/**
+ * A picture of the light on the ground for [reach] tiles each way from [mid_x], [mid_y], [grain] pixels to the
+ * tile: for every tile, what the lighting plane holds over it. Daylight where the area gives it, the tile's own
+ * four lit corners blended across it where it has them, both where it has both, and full light over ground that
+ * glows (lava: the game cuts it out of the lighting altogether) and over everything that is not this site's
+ * ground, which the pictures of the ground draw in a tone that is already lit.
+ * Takes a few ticks. Null if it could not be made.
+ * * berth_set - the berth's turfs: where a hull stands on them they take the light of the ground around the berth
+ */
+/datum/landing_view/proc/light_map(mid_x, mid_y, reach, grain, list/berth_set)
+ var/turf/middle = locate(mid_x, mid_y, ground_z)
+ if(!middle)
+ return null
+ var/datum/own_region = map_region_for_turf(middle)
+ var/side = reach * 2 * grain
+ var/list/cells = new /list(side * side)
+ var/low_x = mid_x - reach
+ var/low_y = mid_y - reach
+ // area -> its daylight as list(red, green, blue), each 0-1, or FALSE for none
+ var/list/daylight = list()
+ // the light a hull on the berth hides: that of the ground around it
+ var/list/around = list(0, 0, 0)
+ var/around_count = 0
+ for(var/turf/berth_turf as anything in berth_set)
+ for(var/turf/beside as anything in RANGE_TURFS(1, berth_turf))
+ if(berth_set[beside])
+ continue
+ var/list/there = landing_view_light_factor(beside)
+ around[1] += there[1]
+ around[2] += there[2]
+ around[3] += there[3]
+ around_count++
+ var/under_hull = around_count ? rgb(round(around[1] / around_count * 255, 4), round(around[2] / around_count * 255, 4), round(around[3] / around_count * 255, 4)) : "#ffffff"
+ for(var/tile_y = mid_y + reach - 1, tile_y >= low_y, tile_y--)
+ var/cell_y = (tile_y - low_y) * grain
+ for(var/tile_x in low_x to mid_x + reach - 1)
+ var/turf/ground = locate(tile_x, tile_y, ground_z)
+ var/cell_x = (tile_x - low_x) * grain
+ var/flat = "#ffffff"
+ var/list/corners
+ if(ground && !istype(ground, /turf/cordon) && !(own_region && map_region_excludes_turf(own_region, ground)))
+ if(berth_set[ground] && istype(ground.loc, /area/shuttle))
+ flat = under_hull
+ else if(landing_view_glows(ground))
+ flat = "#ffffff"
+ else
+ var/area/place = ground.loc
+ var/list/day = daylight[place]
+ if(isnull(day))
+ day = FALSE
+ if(place.base_lighting_alpha)
+ var/list/tint = rgb2num(place.base_lighting_color == COLOR_STARLIGHT ? GLOB.starlight_color : place.base_lighting_color)
+ var/strength = place.base_lighting_alpha / 255 / 255
+ day = list(tint[1] * strength, tint[2] * strength, tint[3] * strength)
+ daylight[place] = day
+ if(ground.lighting_object)
+ // its own corners, with the daylight on top where there is any
+ corners = list()
+ for(var/datum/lighting_corner/corner as anything in list(ground.lighting_corner_SW, ground.lighting_corner_SE, ground.lighting_corner_NW, ground.lighting_corner_NE))
+ if(corner)
+ corners += list(list(corner.cache_r + (day ? day[1] : 0), corner.cache_g + (day ? day[2] : 0), corner.cache_b + (day ? day[3] : 0)))
+ else
+ corners += list(day || list(0, 0, 0))
+ else if(day)
+ flat = rgb(round(day[1] * 255, 4), round(day[2] * 255, 4), round(day[3] * 255, 4))
+ else if(place.static_lighting && !isspaceturf(ground))
+ // no light of any kind reaches it
+ flat = "#000000"
+ for(var/row in 1 to grain)
+ var/base = (side - cell_y - row) * side + cell_x
+ if(!corners)
+ for(var/col in 1 to grain)
+ cells[base + col] = flat
+ continue
+ var/up = (row - 0.5) / grain
+ for(var/col in 1 to grain)
+ var/right = (col - 0.5) / grain
+ var/list/low_left = corners[1]
+ var/list/low_right = corners[2]
+ var/list/up_left = corners[3]
+ var/list/up_right = corners[4]
+ var/red = (low_left[1] * (1 - right) + low_right[1] * right) * (1 - up) + (up_left[1] * (1 - right) + up_right[1] * right) * up
+ var/green = (low_left[2] * (1 - right) + low_right[2] * right) * (1 - up) + (up_left[2] * (1 - right) + up_right[2] * right) * up
+ var/blue = (low_left[3] * (1 - right) + low_right[3] * right) * (1 - up) + (up_left[3] * (1 - right) + up_right[3] * right) * up
+ cells[base + col] = rgb(round(min(red, 1) * 255, 4), round(min(green, 1) * 255, 4), round(min(blue, 1) * 255, 4))
+ if(TICK_CHECK)
+ stoplag()
+ var/path = "data/landing_view/light_[ground_z]_[mid_x]_[mid_y]_[grain].png"
+ if(!fexists("data/landing_view/made"))
+ text2file("", "data/landing_view/made") // makes the folder
+ var/failed = rustg_dmi_create_png(path, "[side]", "[side]", cells.Join(""))
+ if(failed)
+ stack_trace("No picture of the light for a landing view: [failed]")
+ return null
+ var/icon/light_map = new(path)
+ // gone over once by the engine, as the pictures of the ground are: a far smaller file for a client to fetch
+ light_map.Blend("#ffffff", ICON_MULTIPLY)
+ return light_map
+
+/// Whether [ground] glows of itself: the game draws such ground at full brightness whatever light falls on it
+/proc/landing_view_glows(turf/ground)
+ if(islava(ground))
+ return TRUE
+ for(var/mutable_appearance/over as anything in ground.overlays)
+ if(PLANE_TO_TRUE(over.plane) == EMISSIVE_PLANE && over.color ~= GLOB.emissive_color)
+ return TRUE
+ return FALSE
+
+#undef LANDING_VEIL_PAST
+#undef LANDING_VEIL_PUFF
+#undef LANDING_VEIL_STEP
+#undef LANDING_VEIL_SOFT
+#undef LANDING_VEIL_FULL
+#undef LANDING_VEIL_GONE
+#undef LANDING_LIGHT_FAR_REACH
+#undef LANDING_LIGHT_FAR_GRAIN
+#undef LANDING_LIGHT_NEAR_REACH
+#undef LANDING_LIGHT_NEAR_GRAIN
+#undef LANDING_VIEW_CHUNK
+#undef LANDING_VIEW_CORDON_REACH
+#undef LANDING_AERIAL_FAR_REACH
+#undef LANDING_AERIAL_FAR_GRAIN
+#undef LANDING_AERIAL_NEAR_GRAIN
+#undef LANDING_AERIAL_KEEP
+#undef LANDING_DETAIL_FROM
+#undef LANDING_DETAIL_FULL
+#undef LANDING_DETAIL_SIGHT
+#undef LANDING_DETAIL_MOST
diff --git a/voidcrew/modules/landing_animation/landing_view_hover.dm b/voidcrew/modules/landing_animation/landing_view_hover.dm
new file mode 100644
index 00000000000..805d37e2a56
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_hover.dm
@@ -0,0 +1,196 @@
+/**
+ * # The planet below
+ *
+ * A ship flying over a planet has it under the hull for as long as it stays there: the people aboard see it
+ * come up as the ship arrives over it and fall away as it leaves. A landing starts from this picture and a
+ * takeoff ends on it, so from open space to the ground and back there is always something outside.
+ *
+ * Made of the same planet as the landing view, held at one size. A handful of screen objects for everyone
+ * aboard: it costs nothing to keep.
+ */
+
+/// How long the planet takes to come up under a ship that arrives over it, and to fall away when it leaves
+#define HOVER_ARRIVE (2.4 SECONDS)
+#define HOVER_LEAVE (2 SECONDS)
+/// How often the view checks that the ship and its hull are still where it thinks they are
+#define HOVER_CHECK (2 SECONDS)
+
+/// The view of the planet this ship is flying over, if it is over one
+/obj/structure/overmap/ship/var/datum/landing_view/hover/hover_view
+
+/datum/landing_view/hover
+ var/obj/structure/overmap/ship/ship
+ /// The planet below
+ var/obj/structure/overmap/planet/site
+ /// The planet's size and opacity
+ var/datum/landing_track/size
+ var/datum/landing_track/opacity
+ /// Its pieces: see /datum/landing_view/proc/new_planet()
+ var/list/grains
+ var/datum/landing_view_piece/shade
+ var/datum/landing_view_piece/air
+ /// TRUE once the ship has left and the planet is falling away
+ var/leaving = FALSE
+ /// Where the hull's port stood when this was made: a hull that has moved needs a new view
+ var/turf/port_turf
+ var/next_check = 0
+
+/**
+ * * hull_turfs - the hull's turfs in transit
+ * * arriving - FALSE to have the planet there at once, at full size: the end of a climb out
+ */
+/datum/landing_view/hover/New(obj/docking_port/mobile/shuttle, list/hull_turfs, obj/structure/overmap/planet/site, obj/structure/overmap/ship/ship, arriving = TRUE)
+ ..(shuttle, hull_turfs, null, 0)
+ if(ended)
+ return
+ src.ship = ship
+ src.site = site
+ port_turf = get_turf(shuttle)
+ palette = landing_view_palette_for(site)
+ var/list/planet = new_planet()
+ grains = planet[1]
+ shade = planet[2]
+ var/datum/landing_view_piece/whole = grains[1][1]
+ size = whole.scale
+ air = new_air(whole)
+ if(arriving)
+ play(LANDING_HOVER_FAR, LANDING_HOVER_SIZE, 0, 255, HOVER_ARRIVE, LANDING_CURVE_OUT)
+ else
+ play(LANDING_HOVER_SIZE, LANDING_HOVER_SIZE, 255, 255, 0)
+ next_check = world.time + HOVER_CHECK
+ sync_viewers()
+
+/datum/landing_view/hover/Destroy(force)
+ if(ship?.hover_view == src)
+ ship.hover_view = null
+ ship = null
+ site = null
+ grains = null
+ shade = null
+ air = null
+ port_turf = null
+ return ..()
+
+/// Moves the planet from one size and opacity to another over [time]
+/datum/landing_view/hover/proc/play(from_size, to_size, from_opacity, to_opacity, time, curve = LANDING_CURVE_LINEAR)
+ var/now = world.time
+ size.times = list()
+ size.values = list()
+ size.curves = list()
+ size.mark(now, from_size)
+ opacity = new
+ opacity.mark(now, from_opacity)
+ air.alpha = new
+ air.alpha.mark(now, from_opacity * 0.92)
+ if(time)
+ size.mark(now + time, to_size, curve)
+ // solid all the way but for an instant at its smallest: a planet that fades lets the stars show through it
+ if(to_opacity > from_opacity)
+ opacity.mark(now + 0.2 SECONDS, to_opacity)
+ air.alpha.mark(now + 0.2 SECONDS, to_opacity * 0.92)
+ else
+ opacity.mark(now + time - 0.2 SECONDS, from_opacity)
+ air.alpha.mark(now + time - 0.2 SECONDS, from_opacity * 0.92)
+ opacity.mark(now + time, to_opacity)
+ air.alpha.mark(now + time, to_opacity * 0.92)
+ for(var/list/grain as anything in grains)
+ for(var/datum/landing_view_piece/sheet as anything in grain)
+ sheet.alpha = new
+ chain_detail(grains, size, opacity, LANDING_PLANET_DETAIL)
+ shade.alpha = opacity
+ show(shade)
+ show(air)
+
+/// The ship has left the planet behind: it falls away, and then the view deletes itself
+/datum/landing_view/hover/proc/leave()
+ if(leaving || ended)
+ return
+ leaving = TRUE
+ play(size.at(world.time), LANDING_HOVER_FAR, opacity.at(world.time), 0, HOVER_LEAVE, LANDING_CURVE_IN)
+ // a hard reference: the ship may let go of us before then
+ addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel), src), HOVER_LEAVE)
+
+/datum/landing_view/hover/sync_viewers()
+ . = ..()
+ if(ended || leaving || world.time < next_check)
+ return
+ next_check = world.time + HOVER_CHECK
+ var/obj/structure/overmap/ship/our_ship = ship
+ if(QDELETED(our_ship) || QDELETED(shuttle))
+ qdel(src)
+ else if(get_turf(shuttle) != port_turf)
+ // the hull stands somewhere else now: the same planet, around where it is
+ qdel(src)
+ our_ship.update_hover_view(FALSE)
+ else
+ our_ship.update_hover_view()
+
+/// The turfs of [shuttle]'s hull where it stands now
+/proc/landing_hull_turfs(obj/docking_port/mobile/shuttle)
+ . = list()
+ for(var/turf/hull_turf as anything in shuttle.return_turfs())
+ if(istype(hull_turf.loc, shuttle.area_type) && !istype(hull_turf.loc, /area/shuttle/transit))
+ . += hull_turf
+
+/// The planet this ship is flying over and should see under it: none while it is landed, landing or climbing out
+/obj/structure/overmap/ship/proc/hover_site()
+ if(QDELETED(shuttle) || landing_animation || launch_view)
+ return null
+ // waiting above a planet for its ground to be made ready
+ if(state == OVERMAP_SHIP_DOCKING && docked && landing_animation_wanted(docked))
+ return docked
+ // a ship that has let go of its dock is flying, whatever its state says while the undock finishes
+ if(docked || (state != OVERMAP_SHIP_FLYING && state != OVERMAP_SHIP_ACTING && state != OVERMAP_SHIP_UNDOCKING))
+ return null
+ var/turf/tile = loc
+ if(!istype(tile))
+ return null
+ for(var/obj/structure/overmap/planet/planet in tile)
+ if(landing_animation_wanted(planet))
+ return planet
+ return null
+
+/**
+ * Brings the view of the planet below up to date with where the ship is: made when it comes over a planet,
+ * sent away when it leaves.
+ * * arriving - FALSE if a new view should be there at once and not come up from afar
+ */
+/obj/structure/overmap/ship/proc/update_hover_view(arriving = TRUE)
+ var/obj/structure/overmap/planet/over = hover_site()
+ if(!QDELETED(hover_view))
+ if(!hover_view.leaving && hover_view.site == over)
+ return
+ if(!over)
+ hover_view.leave()
+ return
+ // straight on to another: the old one goes at once, so the two never share the hull
+ QDEL_NULL(hover_view)
+ hover_view = null
+ if(!over || !istype(shuttle.get_docked(), /obj/docking_port/stationary/transit))
+ return
+ var/list/hull = landing_hull_turfs(shuttle)
+ if(!length(hull))
+ return
+ hover_view = new(shuttle, hull, over, src, arriving)
+ if(hover_view.ended)
+ QDEL_NULL(hover_view)
+
+/**
+ * A descent is starting: the view of the planet below is over, and the descent carries on from the size the
+ * planet had in it. Null if there was none.
+ */
+/obj/structure/overmap/ship/proc/take_hover()
+ if(QDELETED(hover_view))
+ hover_view = null
+ return null
+ if(!hover_view.leaving)
+ . = hover_view.size.at(world.time)
+ QDEL_NULL(hover_view)
+
+/obj/structure/overmap/ship/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
+ . = ..()
+ update_hover_view()
+
+#undef HOVER_ARRIVE
+#undef HOVER_LEAVE
+#undef HOVER_CHECK
diff --git a/voidcrew/modules/landing_animation/landing_view_planes.dm b/voidcrew/modules/landing_animation/landing_view_planes.dm
new file mode 100644
index 00000000000..cc6b4bc91d2
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_planes.dm
@@ -0,0 +1,71 @@
+/**
+ * The two planes the landing view draws with (see landing_view.dm).
+ *
+ * The view is big pictures: a planet, a cloud deck, the real ground scaled down. They have to show
+ * everywhere a viewer can see space past the hull and nowhere else: not over the hull, and not in the black of
+ * rooms and tiles out of their sight. The mask plane does that. Every area of a landing ship (its own rooms and
+ * the transit space around it) carries a white overlay on the mask plane, so the mask is exactly the tiles of
+ * that ship the viewer can see. The view plane is cut to it, and sits under the floor plane, so the hull covers
+ * the rest.
+ */
+/atom/movable/screen/plane_master/landing_view_mask
+ name = "Landing view mask"
+ documentation = "Holds a white tile for every turf of a landing ship (hull and the transit space around it) the viewer can see.\
+
Never drawn itself: it is the alpha mask of the landing view plane, so that plane's big pictures stop at the edge of sight."
+ plane = LANDING_VIEW_MASK_PLANE
+ appearance_flags = PLANE_MASTER|NO_CLIENT_COLOR
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ render_target = LANDING_VIEW_MASK_RENDER_TARGET
+ render_relay_planes = list()
+ // one view at a time, always on the viewer's own level
+ offsetting_flags = BLOCKS_PLANE_OFFSETTING
+ multiz_scaled = FALSE
+
+/atom/movable/screen/plane_master/landing_view
+ name = "Landing view"
+ documentation = "What a crew sees around their hull as it lands on a planet or leaves one: the planet, its sky and clouds, the real ground below.\
+
Drawn over space and parallax and under the world, and cut to the landing view mask."
+ plane = LANDING_VIEW_PLANE
+ appearance_flags = PLANE_MASTER|NO_CLIENT_COLOR
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ render_relay_planes = list(RENDER_PLANE_UNLIT_GAME)
+ offsetting_flags = BLOCKS_PLANE_OFFSETTING
+ multiz_scaled = FALSE
+
+/atom/movable/screen/plane_master/landing_view/Initialize(mapload, datum/hud/hud_owner, datum/plane_master_group/home, offset)
+ . = ..()
+ add_filter("landing_view_mask", 1, alpha_mask_filter(render_source = OFFSET_RENDER_TARGET(LANDING_VIEW_MASK_RENDER_TARGET, offset)))
+
+/atom/movable/screen/plane_master/landing_view_outside
+ name = "Landing view outside mask"
+ documentation = "Holds a white tile for every turf of transit space around a landing ship the viewer can see, and none for its hull.\
+
Never drawn itself: it is the alpha mask of the landing view light plane, so the ground's light never falls on the ship."
+ plane = LANDING_VIEW_OUTSIDE_PLANE
+ appearance_flags = PLANE_MASTER|NO_CLIENT_COLOR
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ render_target = LANDING_VIEW_OUTSIDE_RENDER_TARGET
+ render_relay_planes = list()
+ offsetting_flags = BLOCKS_PLANE_OFFSETTING
+ multiz_scaled = FALSE
+
+/atom/movable/screen/plane_master/landing_view_outside/Initialize(mapload, datum/hud/hud_owner, datum/plane_master_group/home, offset)
+ . = ..()
+ // space draws itself as something that glows, which cuts it out of the lighting altogether: no light of
+ // ours could darken it. Around a landing hull it is ground that is seen there, so there it is blocked
+ add_relay_to(GET_NEW_PLANE(RENDER_PLANE_EMISSIVE, offset), relay_layer = EMISSIVE_SPACE_LAYER + 0.5, relay_color = GLOB.em_block_color)
+
+/atom/movable/screen/plane_master/landing_view_light
+ name = "Landing view light"
+ documentation = "The light on the ground a landing ship's crew see under them: a picture of it, drawn over the lighting of the transit space around the hull.\
+
The landing view is lit like everything else, by the lighting plate; in transit that is full light everywhere. This puts the ground's own light there instead,\
+ so the ground shows as the game's lighting will show it once the hull is down, to every kind of eye."
+ plane = LANDING_VIEW_LIGHT_PLANE
+ appearance_flags = PLANE_MASTER|NO_CLIENT_COLOR
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ render_relay_planes = list(RENDER_PLANE_LIGHTING)
+ offsetting_flags = BLOCKS_PLANE_OFFSETTING
+ multiz_scaled = FALSE
+
+/atom/movable/screen/plane_master/landing_view_light/Initialize(mapload, datum/hud/hud_owner, datum/plane_master_group/home, offset)
+ . = ..()
+ add_filter("landing_view_outside", 1, alpha_mask_filter(render_source = OFFSET_RENDER_TARGET(LANDING_VIEW_OUTSIDE_RENDER_TARGET, offset)))
diff --git a/voidcrew/modules/landing_animation/landing_view_sky.dm b/voidcrew/modules/landing_animation/landing_view_sky.dm
new file mode 100644
index 00000000000..5ebc7fb7653
--- /dev/null
+++ b/voidcrew/modules/landing_animation/landing_view_sky.dm
@@ -0,0 +1,338 @@
+/**
+ * What the landing view is made of, for a descent and a climb alike: a planet's colours, the planet itself,
+ * its clouds, the hull's shadow, and the heat on the hull's edge.
+ */
+
+/**
+ * The colours of a planet seen from above. The planet texture holds three kinds of surface; each gets a colour.
+ */
+/datum/landing_view_palette
+ /// The two kinds of land
+ var/surface_a = "#b0a48c"
+ var/surface_b = "#8c8474"
+ /// What lies between: sea, lava, ice
+ var/surface_c = "#5a6a7a"
+ var/cloud = "#f2f2f2"
+ /// The glow of air around the planet's rim
+ var/air = "#b8d4f0"
+ /// The sky from inside it, and the haze over the ground
+ var/sky = "#9db4cc"
+ /// What the country around a landing site is lost in, seen from above: mist, dust, smoke
+ var/veil = "#c4ccd4"
+ /// The hull's glow on the way in
+ var/heat = "#ffa64d"
+
+/datum/landing_view_palette/beach
+ surface_a = "#d9c48a"
+ surface_b = "#5f9a4c"
+ surface_c = "#1f6fb0"
+ cloud = "#ffffff"
+ air = "#8fc8ff"
+ sky = "#7fb4e6"
+ // sea mist
+ veil = "#b9d9f2"
+
+/datum/landing_view_palette/jungle
+ surface_a = "#2f6b2c"
+ surface_b = "#6da043"
+ surface_c = "#1d4a3a"
+ cloud = "#f4fbf0"
+ air = "#a5e0c0"
+ sky = "#86c7b0"
+ // the green steam off the canopy
+ veil = "#a9d8c2"
+
+/datum/landing_view_palette/ice
+ surface_a = "#eef4fa"
+ surface_b = "#b9d3e8"
+ surface_c = "#5b88b5"
+ cloud = "#ffffff"
+ air = "#cfe6ff"
+ sky = "#bcd6ee"
+ // blowing snow
+ veil = "#e6f0f8"
+
+/datum/landing_view_palette/lava
+ surface_a = "#3a2c2a"
+ surface_b = "#5d4a44"
+ surface_c = "#ff6a1a"
+ cloud = "#6b5b57"
+ air = "#ff9a5a"
+ sky = "#7a4a3c"
+ heat = "#ff8a3c"
+ // smoke and ash
+ veil = "#5e443e"
+
+/datum/landing_view_palette/wasteland
+ surface_a = "#b59a6a"
+ surface_b = "#7a6a4e"
+ surface_c = "#5d7a3a"
+ cloud = "#d9c9a0"
+ air = "#e0c890"
+ sky = "#c9b98a"
+ // dust
+ veil = "#cdb98c"
+
+/// The palette for [site], by the kind of planet it is
+/proc/landing_view_palette_for(obj/structure/overmap/planet/site)
+ var/static/list/by_planet = list(
+ /datum/overmap/planet/beach = /datum/landing_view_palette/beach,
+ /datum/overmap/planet/jungle = /datum/landing_view_palette/jungle,
+ /datum/overmap/planet/ice = /datum/landing_view_palette/ice,
+ /datum/overmap/planet/lava = /datum/landing_view_palette/lava,
+ /datum/overmap/planet/wasteland = /datum/landing_view_palette/wasteland,
+ )
+ var/palette_type = (istype(site) && site.planet) ? by_planet[site.planet] : null
+ palette_type ||= /datum/landing_view_palette
+ return new palette_type
+
+/// The colour matrix that paints the planet texture's three surfaces in our colours
+/datum/landing_view_palette/proc/surface_matrix()
+ var/list/first = rgb2num(surface_a)
+ var/list/second = rgb2num(surface_b)
+ var/list/third = rgb2num(surface_c)
+ return list(
+ first[1] / 255, first[2] / 255, first[3] / 255, 0,
+ second[1] / 255, second[2] / 255, second[3] / 255, 0,
+ third[1] / 255, third[2] / 255, third[3] / 255, 0,
+ 0, 0, 0, 1,
+ 0, 0, 0, 0,
+ )
+
+/**
+ * The planet seen whole. Returns list(grains, shade):
+ * - grains: two lists of pieces, each a surface and its clouds, showing the same ball: the whole of it, and its
+ * middle at twice the grain for when it fills the screen. Give them to chain_detail() with the size track of
+ * the very first piece.
+ * - shade: the shading of the lit ball, multiplied over both. Give it the same opacity as the whole.
+ *
+ * Separate sheets, each scaled on its own, and not one ball kept together: the client scales a kept-together
+ * group without smoothing it, and this is drawn many times its size.
+ */
+/datum/landing_view/proc/new_planet()
+ var/list/grains = list()
+ var/datum/landing_view_piece/first
+ for(var/grain in list("planet", "planet_near"))
+ var/datum/landing_view_piece/surface = add_sky(LANDING_VIEW_LAYER_PLANET + length(grains) * 0.02, LANDING_VIEW_ICON, grain, LANDING_VIEW_ICON_SIZE)
+ surface.sky.color = palette.surface_matrix()
+ var/datum/landing_view_piece/cloud = add_sky(LANDING_VIEW_LAYER_PLANET + length(grains) * 0.02 + 0.01, LANDING_VIEW_ICON, "[grain]_clouds", LANDING_VIEW_ICON_SIZE)
+ cloud.sky.color = palette.cloud
+ first ||= surface
+ for(var/datum/landing_view_piece/sheet as anything in list(surface, cloud))
+ sheet.scale = first.scale
+ sheet.slide_x = first.slide_x
+ sheet.slide_y = first.slide_y
+ sheet.scale_factor = 0.5 ** length(grains)
+ grains += list(list(surface, cloud))
+ var/datum/landing_view_piece/shade = add_sky(LANDING_VIEW_LAYER_PLANET + 0.09, LANDING_VIEW_ICON, "planet_shade", LANDING_VIEW_ICON_SIZE)
+ shade.sky.blend_mode = BLEND_MULTIPLY
+ shade.scale = first.scale
+ shade.slide_x = first.slide_x
+ shade.slide_y = first.slide_y
+ return list(grains, shade)
+
+/**
+ * Sets the opacity of [pieces], which show one thing at finer and finer grain, so that as it grows each closer-up
+ * texture fades in over the one before, which is then dropped; and the other way about as it shrinks. A texture
+ * is never stretched far, and the picture never thins in the changeover, because the one underneath stays whole
+ * until the one on top has covered it. Each entry of [pieces] is one grain: a piece, or a list of them.
+ * * size - the size track of the first piece
+ * * opacity - how opaque the whole thing is over time (0-255)
+ * * switches - one list(from, to) per changeover: the sizes of the first piece between which the next takes over
+ */
+/datum/landing_view/proc/chain_detail(list/pieces, datum/landing_track/size, datum/landing_track/opacity, list/switches)
+ var/start = min(size.times[1], opacity.times[1])
+ var/finish = max(size.end_time(), opacity.end_time())
+ for(var/moment = start, moment < finish + 2, moment += 2)
+ var/when = min(moment, finish)
+ var/now_size = size.at(when)
+ var/now_opacity = opacity.at(when)
+ for(var/i in 1 to length(pieces))
+ var/share = 1
+ if(i > 1)
+ var/list/rising = switches[i - 1]
+ share = clamp((now_size - rising[1]) / (rising[2] - rising[1]), 0, 1)
+ if(i < length(pieces))
+ var/list/falling = switches[i]
+ if(now_size >= falling[2])
+ share = 0
+ for(var/datum/landing_view_piece/piece as anything in (islist(pieces[i]) ? pieces[i] : list(pieces[i])))
+ piece.alpha.mark(when, now_opacity * share)
+ for(var/grain in pieces)
+ for(var/datum/landing_view_piece/piece as anything in (islist(grain) ? grain : list(grain)))
+ show(piece)
+
+/// The glow of air around [planet]'s rim, growing and shrinking with it
+/datum/landing_view/proc/new_air(datum/landing_view_piece/planet)
+ var/datum/landing_view_piece/air = add_sky(LANDING_VIEW_LAYER_AIR, LANDING_VIEW_ICON, "planet_air", LANDING_VIEW_ICON_SIZE)
+ air.sky.color = palette.air
+ air.scale = planet.scale
+ air.slide_x = planet.slide_x
+ air.slide_y = planet.slide_y
+ return air
+
+/// The hull's outline in soft black, as one part of a world picture drawn about [mid_x], [mid_y]
+/proc/landing_view_shadow_look(list/hull_turfs, mid_x, mid_y)
+ var/list/squares = list()
+ for(var/turf/hull_turf as anything in hull_turfs)
+ var/mutable_appearance/square = mutable_appearance('icons/effects/alphacolors.dmi', "white", appearance_flags = RESET_COLOR)
+ square.color = COLOR_BLACK
+ square.pixel_w = (hull_turf.x - mid_x) * ICON_SIZE_X
+ square.pixel_z = (hull_turf.y - mid_y) * ICON_SIZE_Y
+ squares += square
+ var/mutable_appearance/look = landing_view_world_look(new /mutable_appearance, LANDING_VIEW_LAYER_SHADOW)
+ look.appearance_flags = KEEP_TOGETHER
+ look.overlays = squares
+ look.filters = gauss_blur_filter(size = 12)
+ return look
+
+/**
+ * The hull's edge glows from [start] to [end] (world.time): a tile of glow, shedding sparks, on every tile of
+ * transit space that touches the hull.
+ */
+/datum/landing_view/proc/heat_hull(start, end)
+ if(ended)
+ return
+ if(world.time < start)
+ addtimer(CALLBACK(src, PROC_REF(heat_hull), start, end), start - world.time, TIMER_DELETE_ME)
+ return
+ var/burn = end - world.time
+ if(burn < 1 SECONDS)
+ return
+ for(var/x in low_x to high_x)
+ for(var/y in low_y to high_y)
+ var/turf/spot = locate(x, y, transit_z)
+ if(!spot || hull_set[spot])
+ continue
+ var/list/sides = list()
+ var/hull_dirs = NONE
+ for(var/side in GLOB.cardinals)
+ if(hull_set[get_step(spot, side)])
+ hull_dirs |= side
+ sides += mutable_appearance('voidcrew/icons/effects/landing_view_glow.dmi', "glow_[landing_view_side_name(side)]")
+ for(var/corner in GLOB.diagonals)
+ // a corner only where the hull is not already alongside
+ if((hull_dirs & corner) || !hull_set[get_step(spot, corner)])
+ continue
+ sides += mutable_appearance('voidcrew/icons/effects/landing_view_glow.dmi', "glow_[landing_view_side_name(corner)]")
+ if(!length(sides))
+ continue
+ var/obj/effect/abstract/landing_heat/glow = new(spot)
+ glow.color = palette.heat
+ glow.overlays = sides
+ if(hull_dirs)
+ glow.throw_sparks(hull_dirs)
+ props += glow
+ var/peak = rand(200, 255)
+ animate(glow, alpha = peak, time = 0.8 SECONDS, easing = SINE_EASING)
+ for(var/i in 1 to round((burn - 1.8 SECONDS) / 3))
+ animate(alpha = peak * rand(55, 100) / 100, time = rand(1, 2))
+ animate(alpha = peak, time = rand(1, 2))
+ animate(alpha = 0, time = 1 SECONDS, easing = SINE_EASING)
+ QDEL_IN(glow, burn + 0.5 SECONDS)
+
+/proc/landing_view_side_name(side)
+ switch(side)
+ if(NORTH)
+ return "n"
+ if(SOUTH)
+ return "s"
+ if(EAST)
+ return "e"
+ if(WEST)
+ return "w"
+ if(NORTHEAST)
+ return "ne"
+ if(NORTHWEST)
+ return "nw"
+ if(SOUTHEAST)
+ return "se"
+ if(SOUTHWEST)
+ return "sw"
+
+/// One tile of the hull's glow on the way down, standing in transit space against the hull
+/obj/effect/abstract/landing_heat
+ name = ""
+ icon = 'voidcrew/icons/effects/landing_view_glow.dmi'
+ icon_state = ""
+ anchored = TRUE
+ density = FALSE
+ mouse_opacity = MOUSE_OPACITY_TRANSPARENT
+ // the floor plane, under anything adrift there; transit space is lit throughout
+ plane = FLOOR_PLANE
+ layer = TOPDOWN_LAYER + 0.5
+ alpha = 0
+ vis_flags = NONE
+
+/obj/effect/abstract/landing_heat/Initialize(mapload)
+ . = ..()
+ SET_PLANE_IMPLICIT(src, FLOOR_PLANE)
+
+/// Sparks torn off the hull's edge, flying out away from the hull (which lies to our [hull_dirs])
+/obj/effect/abstract/landing_heat/proc/throw_sparks(hull_dirs)
+ var/static/list/sparks_by_dir = list()
+ var/away = REVERSE_DIR(hull_dirs & (NORTH | SOUTH)) | REVERSE_DIR(hull_dirs & (EAST | WEST))
+ // hull on both sides of an axis: nowhere to fly on that axis
+ if((hull_dirs & (NORTH | SOUTH)) == (NORTH | SOUTH))
+ away &= ~(NORTH | SOUTH)
+ if((hull_dirs & (EAST | WEST)) == (EAST | WEST))
+ away &= ~(EAST | WEST)
+ if(!away)
+ return
+ var/particles/landing_sparks/sparks = sparks_by_dir["[away]"]
+ if(!sparks)
+ sparks = new
+ var/fly_x = (away & EAST) ? 1 : ((away & WEST) ? -1 : 0)
+ var/fly_y = (away & NORTH) ? 1 : ((away & SOUTH) ? -1 : 0)
+ sparks.velocity = generator(GEN_BOX, list(fly_x * 8 - 2, fly_y * 8 - 2, 0), list(fly_x * 16 + 2, fly_y * 16 + 2, 0), UNIFORM_RAND)
+ // born along the edge that touches the hull
+ sparks.position = generator(GEN_BOX, list(fly_x ? -fly_x * 14 : -16, fly_y ? -fly_y * 14 : -16, 0), list(fly_x ? -fly_x * 10 : 16, fly_y ? -fly_y * 10 : 16, 0), UNIFORM_RAND)
+ sparks_by_dir["[away]"] = sparks
+ particles = sparks
+
+/particles/landing_sparks
+ icon = 'icons/effects/particles/generic.dmi'
+ icon_state = list("dot" = 5, "cross" = 1)
+ width = 224
+ height = 224
+ count = 30
+ spawning = 5
+ lifespan = 0.9 SECONDS
+ fade = 0.5 SECONDS
+ fadein = 1
+ color = 0
+ color_change = 0.12
+ gradient = list("#fff3c4", "#ffb347", "#ff5a1c")
+ scale = generator(GEN_VECTOR, list(1, 1), list(2.2, 2.2), NORMAL_RAND)
+ spin = generator(GEN_NUM, -20, 20)
+
+/// Plays [sound_file] to, and shakes the camera of, everyone watching, at [time]
+/datum/landing_view/proc/cue_at(time, sound_file, volume, shake_time = 0, shake_strength = 0)
+ if(time < world.time - 1 SECONDS)
+ return
+ addtimer(CALLBACK(src, PROC_REF(cue), sound_file, volume, shake_time, shake_strength), max(0, time - world.time), TIMER_DELETE_ME)
+
+/datum/landing_view/proc/cue(sound_file, volume, shake_time, shake_strength)
+ if(ended)
+ return
+ for(var/client/watcher as anything in viewers)
+ var/mob/listener = watcher?.mob
+ if(!listener)
+ continue
+ if(sound_file)
+ listener.playsound_local(get_turf(listener), sound_file, volume, FALSE, pressure_affected = FALSE, use_reverb = FALSE)
+ if(shake_time)
+ shake_camera(listener, shake_time, shake_strength)
+
+/**
+ * The twin, beside the hull in transit, of a puff of dust thrown on the planet from the [edge_dir] side of the
+ * berth tile that pairs with [hull_turf].
+ */
+/datum/landing_view/proc/twin_dust(turf/hull_turf, edge_dir, push, list/shape)
+ if(ended || !hull_turf)
+ return
+ // the same side of the same hull tile, as the hull lies in transit
+ var/transit_dir = rotation ? turn(edge_dir, rotation) : edge_dir
+ var/turf/transit_outside = get_step(hull_turf, transit_dir)
+ if(transit_outside && !hull_set[transit_outside])
+ props += new /obj/effect/temp_visual/landing_dust(transit_outside, transit_dir, push, shape)
diff --git a/voidcrew/modules/overmap/code/modules/overmap/ship.dm b/voidcrew/modules/overmap/code/modules/overmap/ship.dm
index 76bc3dd86c7..c953354ee66 100644
--- a/voidcrew/modules/overmap/code/modules/overmap/ship.dm
+++ b/voidcrew/modules/overmap/code/modules/overmap/ship.dm
@@ -2352,6 +2352,7 @@
// broadcast and once plain from the echo. Only refusals get a return value now.
ship_notify("Initiating docking sequence. Docking in [DOCK_WARMUP_TIME / 10] seconds.", "DOCKING", SHIP_NOTIFY_NOTICE, 'voidcrew/sound/notify.ogg', 50)
dock_warmup_timer = addtimer(CALLBACK(src, PROC_REF(complete_dock_warmup), dock_to_use, WEAKREF(to_dock)), DOCK_WARMUP_TIME, TIMER_STOPPABLE)
+ start_landing_animation(to_dock, dock_to_use, DOCK_WARMUP_TIME) // voidcrew/modules/landing_animation
return null
/**
@@ -2407,6 +2408,7 @@
// Start dock warmup
ship_notify("Destination loaded. Docking in [DOCK_WARMUP_TIME / 10] seconds.", "DOCKING", SHIP_NOTIFY_NOTICE, 'voidcrew/sound/notify.ogg', 50)
dock_warmup_timer = addtimer(CALLBACK(src, PROC_REF(complete_dock_warmup), dock_to_use, WEAKREF(source)), DOCK_WARMUP_TIME, TIMER_STOPPABLE)
+ start_landing_animation(source, dock_to_use, DOCK_WARMUP_TIME) // voidcrew/modules/landing_animation
/**
* Requests generation of an ungenerated site's interior WITHOUT holding the helm:
@@ -2609,6 +2611,7 @@
state = OVERMAP_SHIP_UNDOCKING
ship_notify("Initiating undocking sequence. Undocking in [UNDOCK_WARMUP_TIME / 10] seconds.", "UNDOCKING", SHIP_NOTIFY_NOTICE, 'voidcrew/sound/notify.ogg', 50)
undock_warmup_timer = addtimer(CALLBACK(src, PROC_REF(complete_undock_warmup)), UNDOCK_WARMUP_TIME, TIMER_STOPPABLE)
+ start_launch_animation(UNDOCK_WARMUP_TIME) // voidcrew/modules/landing_animation
return null
/**
@@ -2821,6 +2824,7 @@
state = OVERMAP_SHIP_FLYING
undock_origin = null
SEND_SIGNAL(src, COMSIG_VOIDCREW_SHIP_UNDOCKED)
+ update_hover_view() // voidcrew/modules/landing_animation: the planet under a ship that undocked over one
// Force refresh close_overmap_objects for all ships on this turf
var/turf/our_turf = get_turf(src)
if(our_turf)
@@ -3344,6 +3348,9 @@
for(var/obj/structure/overmap/object in tile)
if(object == src || !object.parallax_theme)
continue
+ // flying over a terrain planet, the crew see the planet itself under the hull (voidcrew/modules/landing_animation)
+ if(landing_animation_wanted(object))
+ continue
return object
return null
diff --git a/voidcrew/modules/unit_tests/_unit_tests.dm b/voidcrew/modules/unit_tests/_unit_tests.dm
index 1dc35663ab1..2e1ae7a6642 100644
--- a/voidcrew/modules/unit_tests/_unit_tests.dm
+++ b/voidcrew/modules/unit_tests/_unit_tests.dm
@@ -155,6 +155,7 @@
#include "voidcrew_hyperviolence_hitlines.dm"
#include "voidcrew_hyperviolence_overlays_exec.dm"
#include "voidcrew_hyperviolence_visuals.dm"
+#include "voidcrew_landing_animation.dm"
#include "voidcrew_launch_access.dm"
#include "voidcrew_launch_cargo.dm"
#include "voidcrew_launch_fabrication.dm"
diff --git a/voidcrew/modules/unit_tests/voidcrew_landing_animation.dm b/voidcrew/modules/unit_tests/voidcrew_landing_animation.dm
new file mode 100644
index 00000000000..e509acc3de0
--- /dev/null
+++ b/voidcrew/modules/unit_tests/voidcrew_landing_animation.dm
@@ -0,0 +1,206 @@
+/**
+ * # Planet landing visuals clean up after themselves
+ *
+ * A planet dock warmup puts a shadow and a picture of the ship over the berth, and shows the people aboard
+ * the planet coming up around their hull (voidcrew/modules/landing_animation). All of it must be gone once the
+ * hull has landed, once the dock is called off, and a few seconds after the hull lifts off again.
+ */
+/datum/unit_test/voidcrew_landing_animation
+ var/datum/map_zone/zone
+ var/datum/map_footprint/footprint
+ var/obj/docking_port/stationary/primary
+ var/obj/docking_port/stationary/secondary
+ var/obj/structure/overmap/planet/wasteland/site
+ var/obj/structure/overmap/ship/ship
+
+/datum/unit_test/voidcrew_landing_animation/Destroy()
+ if(ship)
+ qdel(ship) // takes its hull with it
+ if(site)
+ site.mapzone = null
+ site.footprint = null
+ site.reserve_dock = null
+ site.reserve_dock_secondary = null
+ if(zone && footprint)
+ zone.clear_to_uninitialized_space(footprint)
+ zone.release_slot(footprint)
+ qdel(primary, force = TRUE)
+ qdel(secondary, force = TRUE)
+ return ..()
+
+/// Every landing picture or shadow standing anywhere in the box around [turfs]
+/datum/unit_test/voidcrew_landing_animation/proc/effects_on(list/turfs)
+ var/list/found = list()
+ var/turf/first = turfs[1]
+ var/min_x = first.x
+ var/max_x = first.x
+ var/min_y = first.y
+ var/max_y = first.y
+ for(var/turf/place as anything in turfs)
+ min_x = min(min_x, place.x)
+ max_x = max(max_x, place.x)
+ min_y = min(min_y, place.y)
+ max_y = max(max_y, place.y)
+ for(var/turf/place as anything in block(min_x, min_y, first.z, max_x, max_y, first.z))
+ for(var/obj/effect/abstract/effect in place)
+ if(istype(effect, /obj/effect/abstract/landing_proxy) || istype(effect, /obj/effect/abstract/landing_shadow))
+ found += effect
+ return found
+
+/// Everything a view from aboard leaves standing around the hull in transit, and on its areas
+/datum/unit_test/voidcrew_landing_animation/proc/view_leftovers(list/hull_turfs, list/area/areas)
+ var/list/found = list()
+ var/turf/first = hull_turfs[1]
+ for(var/turf/place as anything in RANGE_TURFS(SHUTTLE_TRANSIT_BORDER + 20, first))
+ for(var/obj/effect/effect in place)
+ if(istype(effect, /obj/effect/abstract/landing_heat) || istype(effect, /obj/effect/temp_visual/landing_dust))
+ found += effect
+ for(var/area/was_masked as anything in areas)
+ if(!QDELETED(was_masked) && (landing_view_mask_tile() in was_masked.overlays))
+ found += was_masked
+ return found
+
+/datum/unit_test/voidcrew_landing_animation/proc/start_descent(label)
+ ship.forceMove(get_turf(site))
+ ship.state = "flying" // OVERMAP_SHIP_FLYING
+ ship.docked = null
+ // Flying over the planet with nothing under way, the people aboard see it below
+ ship.update_hover_view()
+ TEST_ASSERT_NOTNULL(ship.hover_view, "A ship flying over a planet does not show it under the hull ([label])")
+ site.adjust_dock_to_shuttle(primary, ship.shuttle)
+ ship.dock(site, primary)
+ var/datum/landing_animation/descent = ship.landing_animation
+ TEST_ASSERT_NOTNULL(descent, "A planet dock warmup did not start the descent ([label])")
+ TEST_ASSERT_NULL(ship.hover_view, "The view of the planet from above carried on under a descent ([label])")
+ // Skip the wait for the shadow and the ship; the timers would fire the same procs a few seconds in
+ descent.show_shadow()
+ descent.show_proxies()
+ return descent
+
+/datum/unit_test/voidcrew_landing_animation/Run()
+ var/list/values = SSovermap.spawn_dynamic_encounter(/datum/overmap/planet/empty, FALSE)
+ if(length(values) < 4 || !values[1] || !values[2] || !values[3] || !values[4])
+ TEST_FAIL("spawn_dynamic_encounter() did not build a site with a berth")
+ return
+ zone = values[1]
+ primary = values[2]
+ secondary = values[3]
+ footprint = values[4]
+ // Planet type decides whether the landing plays; the berth itself can be any ground
+ site = allocate(/obj/structure/overmap/planet/wasteland)
+ site.mapzone = zone
+ site.footprint = footprint
+ site.reserve_dock = primary
+ site.reserve_dock_secondary = secondary
+ TEST_ASSERT(landing_animation_wanted(site), "A terrain planet does not play the landing")
+ TEST_ASSERT(!landing_animation_wanted(allocate(/obj/structure/overmap/planet/empty)), "Empty space plays the planet landing")
+
+ ship = SSshuttle.create_ship(/datum/map_template/shuttle/voidcrew/box)
+ TEST_ASSERT_NOTNULL(ship, "No test ship")
+ var/obj/docking_port/stationary/transit/transit = ship.shuttle.get_docked()
+ TEST_ASSERT(istype(transit), "The test ship did not start in transit")
+
+ // Warmup: a picture with every hull tile in it, plus the shadow
+ var/datum/landing_animation/descent = start_descent("first approach")
+ var/list/hull_turfs = descent.hull_turfs.Copy()
+ var/list/berth_turfs = descent.berth_turfs.Copy()
+ TEST_ASSERT(length(hull_turfs) > 0, "The descent found no hull tiles")
+ var/obj/effect/abstract/landing_proxy/picture = descent.proxy
+ TEST_ASSERT_NOTNULL(picture, "The descent has no ship")
+ TEST_ASSERT(length(picture.overlays) >= length(hull_turfs), "The ship's picture is missing hull tiles")
+ TEST_ASSERT_EQUAL(picture.mouse_opacity, MOUSE_OPACITY_TRANSPARENT, "The picture catches the mouse")
+ TEST_ASSERT(!picture.density, "The picture is dense")
+ TEST_ASSERT_NOTNULL(descent.shadow, "The descent has no shadow")
+ // And for the people aboard: the planet, its clouds, the ground, on the masked planes around the hull
+ var/datum/landing_view/descent/view = descent.inside_view
+ TEST_ASSERT_NOTNULL(view, "The descent shows the people aboard nothing")
+ TEST_ASSERT(!view.ended, "The view from aboard gave up at once")
+ TEST_ASSERT(length(view.pieces) >= 8, "The view from aboard is missing pieces: it has [length(view.pieces)]")
+ var/list/area/masked = view.masked.Copy()
+ TEST_ASSERT(length(masked) >= 2, "The view is not masked to the hull's areas and its transit space")
+ for(var/area/is_masked as anything in masked)
+ TEST_ASSERT(landing_view_mask_tile() in is_masked.overlays, "[is_masked] does not carry the view's mask")
+ for(var/datum/landing_view_piece/piece as anything in view.pieces)
+ if(piece.sky)
+ TEST_ASSERT_EQUAL(piece.sky.mouse_opacity, MOUSE_OPACITY_TRANSPARENT, "A piece of the sky catches the mouse")
+ TEST_ASSERT(piece.sky.plane == -19 || piece.sky.plane == 18, "A piece of the sky is off the view's planes") // LANDING_VIEW_PLANE, LANDING_VIEW_LIGHT_PLANE
+ UNTIL((length(view.ground.parts) && length(view.close.parts)) || QDELETED(view))
+ TEST_ASSERT(length(view.ground.parts) > 1, "The picture of the ground from afar has nothing in it")
+ TEST_ASSERT(length(view.close.parts) > 1, "The close-up picture of the ground has nothing in it")
+ for(var/list/part as anything in (view.ground.parts + view.close.parts))
+ var/mutable_appearance/look = part[1]
+ TEST_ASSERT_EQUAL(look.plane, -19, "Part of the ground picture is off the view's plane") // LANDING_VIEW_PLANE
+ TEST_ASSERT_EQUAL(look.mouse_opacity, MOUSE_OPACITY_TRANSPARENT, "Part of the ground picture catches the mouse")
+ view.heat_hull(world.time, world.time + 3 SECONDS)
+ TEST_ASSERT(length(view.props) > 0, "The hull's edge does not glow on the way in")
+
+ // Called off mid-warmup: everything goes at the next check
+ deltimer(ship.dock_warmup_timer)
+ ship.dock_warmup_timer = null
+ ship.state = "flying" // OVERMAP_SHIP_FLYING
+ ship.docked = null
+ descent.watch()
+ TEST_ASSERT(QDELETED(descent), "A cancelled dock kept its descent")
+ TEST_ASSERT_NULL(ship.landing_animation, "A cancelled dock left the ship pointing at its descent")
+ TEST_ASSERT_EQUAL(length(effects_on(berth_turfs)), 0, "A cancelled dock left the ship's picture or shadow on the berth")
+ TEST_ASSERT(view.ended, "A cancelled dock kept showing the planet to the people aboard")
+ sleep(2 SECONDS)
+ TEST_ASSERT(QDELETED(view), "A cancelled dock kept its view from aboard")
+ TEST_ASSERT_NOTNULL(ship.hover_view, "The planet did not come back under a ship whose landing was called off")
+ QDEL_NULL(ship.hover_view)
+ TEST_ASSERT_EQUAL(length(view_leftovers(hull_turfs, masked)), 0, "A cancelled dock left the view's glow, dust or mask behind")
+
+ // Landing: the hull's move removes everything in the same tick
+ descent = start_descent("second approach")
+ view = descent.inside_view
+ masked = view.masked.Copy()
+ hull_turfs = descent.hull_turfs.Copy()
+ descent.thruster_wash()
+ deltimer(ship.dock_warmup_timer)
+ ship.dock_warmup_timer = null
+ TEST_ASSERT_EQUAL(ship.shuttle.initiate_docking(primary), DOCKING_SUCCESS, "The test ship could not land")
+ TEST_ASSERT_NULL(ship.landing_animation, "The landed ship still points at its descent")
+ TEST_ASSERT(QDELETED(view), "The landed ship still shows its people the view from aboard")
+ TEST_ASSERT_EQUAL(length(view_leftovers(hull_turfs, masked)), 0, "Touchdown left the view's glow, dust or mask behind in transit")
+ // For a moment the picture covers the landed hull while its lighting is rebuilt
+ picture = descent.proxy
+ TEST_ASSERT_NOTNULL(picture, "The picture went before the landed hull's lighting was rebuilt")
+ TEST_ASSERT_EQUAL(picture.pixel_z, 0, "At touchdown the picture is still in the air")
+ sleep(4 SECONDS)
+ TEST_ASSERT(QDELETED(descent), "Touchdown kept the descent")
+ TEST_ASSERT_EQUAL(length(effects_on(berth_turfs)), 0, "Touchdown left the picture or the shadow on the berth")
+
+ // Takeoff: a climbing proxy is left behind, and it is gone a few seconds later
+ ship.docked = null
+ ship.state = "undocking" // OVERMAP_SHIP_UNDOCKING
+ ship.undock_origin = WEAKREF(site)
+ var/obj/docking_port/stationary/transit/departure = ship.shuttle.assigned_transit || SSshuttle.generate_transit_dock(ship.shuttle)
+ TEST_ASSERT_NOTNULL(departure, "No transit dock to leave into")
+ TEST_ASSERT_EQUAL(ship.shuttle.initiate_docking(departure), DOCKING_SUCCESS, "The test ship could not take off")
+ TEST_ASSERT(length(effects_on(berth_turfs)) > 0, "Takeoff left no climbing picture")
+ var/datum/landing_view/ascent/climb = ship.launch_view
+ TEST_ASSERT_NOTNULL(climb, "Takeoff shows the people aboard nothing")
+ // The ground it stood on is drawn over the next few ticks: the hull itself still hides it
+ var/drawn_by = world.time + 3 SECONDS
+ UNTIL(length(climb.close.parts) || QDELETED(climb) || world.time > drawn_by)
+ TEST_ASSERT(length(climb.close.parts) > 0, "The ground is not there under the hull soon after it lifts")
+ masked = climb.masked.Copy()
+ hull_turfs = climb.hull_turfs.Copy()
+ ship.state = "flying" // OVERMAP_SHIP_FLYING
+ sleep(6 SECONDS)
+ TEST_ASSERT_EQUAL(length(effects_on(berth_turfs)), 0, "The takeoff picture or shadow stayed behind")
+ sleep(5 SECONDS)
+ TEST_ASSERT(QDELETED(climb), "The climb's view from aboard never ended")
+ TEST_ASSERT_NULL(ship.launch_view, "The ship still points at its finished climb")
+ // The climb ends on the planet as it looks from above, and that stays under the ship
+ var/datum/landing_view/hover/below = ship.hover_view
+ TEST_ASSERT_NOTNULL(below, "The climb did not leave the planet under the ship")
+ TEST_ASSERT(length(below.pieces) >= 4, "The planet under the ship is missing pieces")
+ // Until the ship flies on: then it falls away
+ ship.forceMove(get_step(get_turf(site), EAST) || get_step(get_turf(site), WEST))
+ TEST_ASSERT(below.leaving, "The planet stayed under a ship that had flown on")
+ sleep(3 SECONDS)
+ TEST_ASSERT(QDELETED(below), "The planet a ship left behind never went")
+ TEST_ASSERT_NULL(ship.hover_view, "The ship still points at the planet it left behind")
+ TEST_ASSERT_EQUAL(length(view_leftovers(hull_turfs, masked)), 0, "The climb left its dust or mask behind in transit")
+ ship.state = "flying" // OVERMAP_SHIP_FLYING
diff --git a/voidcrew/sound/effects/landing/approach.ogg b/voidcrew/sound/effects/landing/approach.ogg
new file mode 100644
index 00000000000..b2a15d576b4
Binary files /dev/null and b/voidcrew/sound/effects/landing/approach.ogg differ
diff --git a/voidcrew/sound/effects/landing/clouds.ogg b/voidcrew/sound/effects/landing/clouds.ogg
new file mode 100644
index 00000000000..19482beea10
Binary files /dev/null and b/voidcrew/sound/effects/landing/clouds.ogg differ
diff --git a/voidcrew/sound/effects/landing/entry.ogg b/voidcrew/sound/effects/landing/entry.ogg
new file mode 100644
index 00000000000..a4b31ed8407
Binary files /dev/null and b/voidcrew/sound/effects/landing/entry.ogg differ
diff --git a/voidcrew/sound/effects/landing/launch.ogg b/voidcrew/sound/effects/landing/launch.ogg
new file mode 100644
index 00000000000..9863178097a
Binary files /dev/null and b/voidcrew/sound/effects/landing/launch.ogg differ
diff --git a/voidcrew/sound/effects/landing/liftoff_outside.ogg b/voidcrew/sound/effects/landing/liftoff_outside.ogg
new file mode 100644
index 00000000000..bb7e522830d
Binary files /dev/null and b/voidcrew/sound/effects/landing/liftoff_outside.ogg differ
diff --git a/voidcrew/sound/effects/landing/spool.ogg b/voidcrew/sound/effects/landing/spool.ogg
new file mode 100644
index 00000000000..8fcdf8e50bf
Binary files /dev/null and b/voidcrew/sound/effects/landing/spool.ogg differ
diff --git a/voidcrew/sound/effects/landing/thrusters.ogg b/voidcrew/sound/effects/landing/thrusters.ogg
new file mode 100644
index 00000000000..350ea8b472a
Binary files /dev/null and b/voidcrew/sound/effects/landing/thrusters.ogg differ
diff --git a/voidcrew/sound/effects/landing/touchdown.ogg b/voidcrew/sound/effects/landing/touchdown.ogg
new file mode 100644
index 00000000000..3ab5c92abd8
Binary files /dev/null and b/voidcrew/sound/effects/landing/touchdown.ogg differ