2026-10-28 15:39:06 +02:00
extends Node
const Economy = preload ( " res://economy.gd " )
const TITLES = [ " Колодки " , " Дыба " , " Колесо " , " Железная дева " , " Музыкальный стул " , " Котёл " ]
const PRICES = Economy . TOOL_PRICES
const FOOTPRINTS = [ Vector2i ( 2 , 2 ) , Vector2i ( 3 , 4 ) , Vector2i ( 4 , 4 ) , Vector2i ( 3 , 3 ) , Vector2i ( 3 , 3 ) , Vector2i ( 4 , 4 ) ]
const ORIGIN = Vector2 ( - 2 , - 4 )
const AREA = Vector2i ( 12 , 9 )
const EXTRA = preload ( " res://new_equipment.gd " )
const QUEUE_CAPACITY = 7
const PLACE_SOUND = preload ( " res://audio/apparatus_place.wav " )
const REMOVE_SOUND = preload ( " res://audio/apparatus_remove.wav " )
const Icon = preload ( " res://talent_icon.gd " )
var g
var sentences
2026-10-29 21:39:15 +02:00
var arcade = preload ( " res://idle_arcade.gd " ) . new ( )
var roaming = preload ( " res://helper_roaming.gd " ) . new ( )
2026-10-28 15:39:06 +02:00
const DIALOGUE_INTERVAL = 30.0
const HERO_INTERVAL = 100.0
var dialogue_clock = 0.0
var dialogue_turn = 0
var stations = [ ]
var expansion_level = 0
var drag = preload ( " res://build_drag.gd " ) . new ( )
var expansion_button : Button
var losses = preload ( " res://workshop_losses.gd " ) . new ( )
var helpers = [ ]
var unlock = 0
var helper_speed = 0
var automation = false
var helper_diligence = 0
var pressure_time = 0.0
var penalty_clock = 0.0
var penalty_gold_lost = 0
var penalty_souls_lost = 0
var pressure_label : Label
var tree_summary : Label
var build_mode = false
var pending = - 1
var pending_turns = 0
var moving = - 1
var selected = - 1
var spawn_clock = 0.0
var darkness = 0.0
var grid : Node3D
var preview : MeshInstance3D
var ghost : Node3D
var ghost_material : StandardMaterial3D
var pointer_position = null
var panel : PanelContainer
var context : PanelContainer
var context_title : Label
var catalogue : PanelContainer
var tree : PanelContainer
var tree_backdrop : ColorRect
var shade : ColorRect
var pressure : Label
var info : Label
var notice : Label
var timer_label : Label
var build_button : Button
var grimoire_button : Button
var buy_labels = [ ]
var buy_icons = [ ]
var help_primary : Label
var help_secondary : Label
var build_player : AudioStreamPlayer
var node_buttons = [ ]
var buy_buttons = [ ]
var bars = [ ]
var notice_time = 0.0
var nav = AStarGrid2D . new ( )
2026-10-29 13:16:22 +02:00
var free_floor_points = PackedVector3Array ( )
2026-10-28 15:39:06 +02:00
var revision = 0
var mesh_walking = preload ( " res://mesh_walking.gd " ) . new ( )
func setup ( game ) :
g = game
mesh_walking . setup ( g )
2026-10-29 21:39:15 +02:00
roaming . setup ( self )
2026-10-28 15:39:06 +02:00
sentences = preload ( " res://judgement.gd " ) . new ( ) ; sentences . setup ( self )
losses . setup ( self )
build_player = AudioStreamPlayer . new ( ) ; g . add_child ( build_player ) ; build_player . max_polyphony = 4
g . development . device . hide ( )
g . development . tree_icon . hide ( )
g . development . xp_label . get_parent ( ) . get_parent ( ) . hide ( )
g . development . action_bar . hide ( )
g . development . action_bar . reparent ( g . ui_compat )
g . development . tree_icon . reparent ( g . ui_compat )
g . zone . hide ( ) ; g . ring . hide ( )
make_grid ( )
make_ui ( )
drag . setup ( self )
make_level_bar ( )
2026-10-29 21:39:15 +02:00
arcade . setup ( self )
2026-10-28 15:39:06 +02:00
rebuild_nav ( )
var saved = g . get_meta ( " workshop_save " , { } )
if saved is Dictionary and not saved . is_empty ( ) :
restore ( saved )
if not stations . is_empty ( ) or g . done > 0 :
var parent = g . menu . main_start . get_parent ( )
var resume = g . button ( " Продолжить " , resume_saved )
parent . add_child ( resume ) ; parent . move_child ( resume , g . menu . main_start . get_index ( ) )
func style ( bg = Color ( " 141018 " ) , edge = Color ( " 776044 " ) ) :
return preload ( " res://infernal_ui.gd " ) . panel ( false , 18 )
func make_panel ( pos , dimensions ) :
var p = PanelContainer . new ( ) ; g . hud . add_child ( p ) ; p . position = pos ; p . size = dimensions
p . add_theme_stylebox_override ( " panel " , style ( ) )
return p
func text ( parent , value , font_size = 18 , color = Color ( " d5c9b5 " ) ) :
var l = g . label ( value , font_size , color ) ; parent . add_child ( l )
l . vertical_alignment = VERTICAL_ALIGNMENT_CENTER
l . size_flags_horizontal = Control . SIZE_EXPAND_FILL
return l
func action ( parent , value , callback ) :
var b = g . button ( value , callback ) ; parent . add_child ( b )
preload ( " res://infernal_ui.gd " ) . apply_button ( b )
b . add_theme_font_size_override ( " font_size " , 17 )
return b
func icon_button ( kind , tooltip , pos , callback ) :
var b = action ( g . hud , " " , callback ) ; b . custom_minimum_size = Vector2 ( 64 , 64 ) ; b . size = Vector2 ( 64 , 64 ) ; b . position = pos
b . tooltip_text = tooltip ; b . toggle_mode = true ; b . focus_mode = Control . FOCUS_NONE
b . z_index = 50
for state in [ " normal " , " hover " , " pressed " , " disabled " ] : b . add_theme_stylebox_override ( state , preload ( " res://infernal_ui.gd " ) . icon ( state ) )
var icon = Icon . new ( ) ; icon . kind = kind ; b . add_child ( icon ) ; icon . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
icon . offset_left = 9 ; icon . offset_top = 9 ; icon . offset_right = - 9 ; icon . offset_bottom = - 9
return b
func make_ui ( ) :
shade = ColorRect . new ( ) ; g . hud . add_child ( shade ) ; shade . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
shade . color = Color ( 0.08 , 0 , 0.025 , 0 ) ; shade . mouse_filter = Control . MOUSE_FILTER_IGNORE ; shade . z_index = - 3
panel = PanelContainer . new ( ) ; g . ui_compat . add_child ( panel )
var hidden = VBoxContainer . new ( ) ; panel . add_child ( hidden )
info = text ( hidden , " " ) ; timer_label = text ( hidden , " " ) ; pressure = text ( hidden , " " )
help_primary = text ( hidden , " " ) ; help_secondary = text ( hidden , " " ) ; notice = text ( hidden , " " )
build_button = icon_button ( " build " , " Строительство [B] " , Vector2 ( 1432 , 812 ) , toggle_build )
build_button . name = " BuildIconButton "
grimoire_button = icon_button ( " book " , " Гримуар [T] " , Vector2 ( 1512 , 812 ) , toggle_tree )
grimoire_button . name = " GrimoireIconButton "
var v : VBoxContainer
var row : HBoxContainer
catalogue = make_panel ( Vector2 ( 1080 , 116 ) , Vector2 ( 496 , 680 ) ) ; catalogue . z_index = 12
v = VBoxContainer . new ( ) ; catalogue . add_child ( v ) ; v . add_theme_constant_override ( " separation " , 10 )
text ( v , " КУЗНЯ ИСТЯЗАНИЙ " , 25 , Color ( " d8d4c4 " ) ) . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
text ( v , " ЛКМ — установить · Колесо — поворот / масштаб \n WASD — камера · СКМ — вращение \n ЛКМ 1 с — перенос · Снизу — удаление " , 16 )
var scroll = ScrollContainer . new ( ) ; v . add_child ( scroll ) ; scroll . custom_minimum_size = Vector2 ( 452 , 335 ) ; scroll . size_flags_vertical = Control . SIZE_EXPAND_FILL
scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED ; preload ( " res://infernal_ui.gd " ) . apply_scroll ( scroll )
var tools = VBoxContainer . new ( ) ; scroll . add_child ( tools ) ; tools . size_flags_horizontal = Control . SIZE_EXPAND_FILL ; tools . add_theme_constant_override ( " separation " , 8 )
for i in range ( TITLES . size ( ) ) :
var b = action ( tools , " " , func ( ) : begin_purchase ( i ) ) ; buy_buttons . append ( b )
var margin = MarginContainer . new ( ) ; b . add_child ( margin ) ; margin . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT ) ; margin . mouse_filter = Control . MOUSE_FILTER_IGNORE
for side in [ " left " , " right " ] : margin . add_theme_constant_override ( " margin_ " + side , 12 )
for side in [ " top " , " bottom " ] : margin . add_theme_constant_override ( " margin_ " + side , 6 )
var entry = HBoxContainer . new ( ) ; margin . add_child ( entry ) ; entry . mouse_filter = Control . MOUSE_FILTER_IGNORE ; entry . add_theme_constant_override ( " separation " , 12 )
var icon = Icon . new ( ) ; icon . kind = Icon . APPARATUS [ i ] ; icon . custom_minimum_size = Vector2 ( 40 , 40 ) ; entry . add_child ( icon )
buy_icons . append ( icon )
var l = text ( entry , " " , 16 ) ; l . mouse_filter = Control . MOUSE_FILTER_IGNORE ; buy_labels . append ( l )
expansion_button = action ( v , " " , purchase_expansion ) ; expansion_button . name = " BuyRoomExpansion "
action ( v , " Завершить строительство [B] " , toggle_build )
catalogue . hide ( )
context = make_panel ( Vector2 . ZERO , Vector2 ( 336 , 52 ) ) ; context . z_index = 10
v = VBoxContainer . new ( ) ; context . add_child ( v ) ; context_title = text ( v , " " , 19 , Color ( " dedacb " ) )
context . hide ( )
make_tree ( )
g . hud . move_child ( build_button , - 1 ) ; g . hud . move_child ( grimoire_button , - 1 )
refresh ( )
func make_tree ( ) :
tree_backdrop = ColorRect . new ( ) ; g . hud . add_child ( tree_backdrop ) ; tree_backdrop . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
tree_backdrop . color = Color ( . 018 , . 022 , . 025 , . 90 ) ; tree_backdrop . z_index = 39 ; tree_backdrop . hide ( )
tree = make_panel ( Vector2 ( 190 , 58 ) , Vector2 ( 1220 , 742 ) ) ; tree . z_index = 40
var root = VBoxContainer . new ( ) ; tree . add_child ( root ) ; root . add_theme_constant_override ( " separation " , 12 )
text ( root , " Г Р И М У А Р Ц Е Х А " , 30 , Color ( " d8d4c4 " ) ) . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
tree_summary = text ( root , " " , 16 ) ; tree_summary . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
var columns = HBoxContainer . new ( ) ; root . add_child ( columns ) ; columns . add_theme_constant_override ( " separation " , 22 )
var tool_nodes = [ ]
for kind in range ( TITLES . size ( ) ) :
if kind > 0 : tool_nodes . append ( [ Icon . APPARATUS [ kind ] , " Чертёж: " + TITLES [ kind ] , " Открывает покупку в кузне " , " unlock %d " %kind ] )
var specs = [
{ " title " : " I ОРУДИЯ " , " subtitle " : " Золото · покупка новых орудий " , " nodes " : tool_nodes } ,
{ " title " : " II СУККУБА " , " subtitle " : " 1 очко за каждый новый уровень " , " nodes " : [ [ " boot " , " Поступь тени " , " +25 % к скорости " , " speed " ] , [ " whip " , " Владычица боли " , " +20 % к своим действиям " , " power " ] , [ " wings " , " Хозяйка цеха " , " +8 % к работе всей команды " , " leadership " ] , [ " lock " , " Крылья госпожи " , " Будущее развитие " , " future " ] ] } ,
2026-10-29 21:39:15 +02:00
{ " title " : " III СВИТА " , " subtitle " : " Души · до 3 помощниц " , " nodes " : [ [ " wings " , " Призвать помощницу " , " Доставка душ к свободным орудиям " , " hire " ] , [ " soul " , " Надсмотрщицы " , " Работа орудия на полной скорости " , " auto " ] , [ " boot " , " Стремительная свита " , " +25 % к скорости движения " , " haste " ] , [ " whip " , " Усердная свита " , " +25 % к скорости работы " , " diligence " ] , [ " lock " , " Легион тьмы " , " Будущее развитие " , " future " ] ] }
2026-10-28 15:39:06 +02:00
]
for spec in specs :
var column = VBoxContainer . new ( ) ; columns . add_child ( column ) ; column . custom_minimum_size = Vector2 ( 376 , 0 )
column . add_theme_constant_override ( " separation " , 0 )
text ( column , spec . title , 23 , Color ( " d8d4c4 " ) ) . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
text ( column , spec . subtitle , 15 ) . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
var scroll = ScrollContainer . new ( ) ; column . add_child ( scroll ) ; scroll . custom_minimum_size = Vector2 ( 376 , 470 ) ; scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED
preload ( " res://infernal_ui.gd " ) . apply_scroll ( scroll )
var branch = VBoxContainer . new ( ) ; scroll . add_child ( branch ) ; branch . size_flags_horizontal = Control . SIZE_EXPAND_FILL ; branch . add_theme_constant_override ( " separation " , 0 )
for i in range ( spec . nodes . size ( ) ) :
var n = spec . nodes [ i ]
if i > 0 :
var link = Control . new ( ) ; branch . add_child ( link ) ; link . custom_minimum_size = Vector2 ( 356 , 14 )
var key = n [ 3 ]
var b = action ( branch , " " , func ( ) : upgrade ( key ) ) ; b . custom_minimum_size = Vector2 ( 356 , 132 )
b . add_theme_stylebox_override ( " disabled " , b . get_theme_stylebox ( " normal " ) )
b . add_theme_color_override ( " font_disabled_color " , b . get_theme_color ( " font_color " ) )
var content = Control . new ( ) ; b . add_child ( content ) ; content . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT ) ; content . mouse_filter = Control . MOUSE_FILTER_IGNORE
var icon = Icon . new ( ) ; icon . kind = n [ 0 ] ; content . add_child ( icon ) ; icon . position = Vector2 ( 18 , 42 ) ; icon . size = Vector2 ( 40 , 40 ) ; icon . custom_minimum_size = Vector2 ( 40 , 40 )
var title = text ( content , n [ 1 ] , 18 , Color ( " d7d5c7 " ) ) ; title . mouse_filter = Control . MOUSE_FILTER_IGNORE
title . set_anchors_and_offsets_preset ( Control . PRESET_TOP_WIDE ) ; title . offset_left = 12 ; title . offset_right = - 12 ; title . offset_top = 12 ; title . offset_bottom = 36 ; title . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
var desc = text ( content , n [ 2 ] , 14 ) ; desc . mouse_filter = Control . MOUSE_FILTER_IGNORE ; desc . autowrap_mode = TextServer . AUTOWRAP_WORD_SMART
desc . set_anchors_and_offsets_preset ( Control . PRESET_TOP_WIDE ) ; desc . offset_left = 66 ; desc . offset_right = - 66 ; desc . offset_top = 40 ; desc . offset_bottom = 76 ; desc . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
var rank = text ( content , " " , 14 , Color ( " b8afa1 " ) ) ; rank . mouse_filter = Control . MOUSE_FILTER_IGNORE
rank . set_anchors_and_offsets_preset ( Control . PRESET_TOP_WIDE ) ; rank . offset_left = 12 ; rank . offset_right = - 12 ; rank . offset_top = 80 ; rank . offset_bottom = 98 ; rank . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
var gems = preload ( " res://skill_rubies.gd " ) . new ( ) ; b . add_child ( gems ) ; gems . mouse_filter = Control . MOUSE_FILTER_IGNORE
gems . slots = 3 if key in [ " speed " , " power " , " leadership " , " hire " , " haste " , " diligence " ] else 1
gems . set_anchors_and_offsets_preset ( Control . PRESET_BOTTOM_WIDE ) ; gems . offset_top = - 29 ; gems . offset_bottom = - 5
node_buttons . append ( { " button " : b , " key " : key , " rank " : rank , " description " : desc , " gems " : gems } )
text ( root , " Одно орудие — одно наказание. После завершения душа сгорает и приносит награду. " , 15 ) . horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
action ( root , " Вернуться в цех [T / Esc] " , toggle_tree )
tree . hide ( )
func make_grid ( ) :
if is_instance_valid ( grid ) : grid . free ( )
if is_instance_valid ( preview ) : preview . free ( )
var area = grid_area ( )
grid = Node3D . new ( ) ; g . add_child ( grid )
var plane = PlaneMesh . new ( ) ; plane . size = area
var lines = MeshInstance3D . new ( ) ; grid . add_child ( lines ) ; lines . mesh = plane
lines . position = Vector3 ( ORIGIN . x + area . x / 2 , . 205 , ORIGIN . y + area . y / 2 )
lines . cast_shadow = GeometryInstance3D . SHADOW_CASTING_SETTING_OFF
var grid_material = ShaderMaterial . new ( ) ; grid_material . shader = preload ( " res://build_grid.gdshader " )
grid_material . render_priority = 110
grid_material . set_shader_parameter ( " grid_origin " , ORIGIN ) ; grid_material . set_shader_parameter ( " grid_area " , area )
lines . material_override = grid_material
preview = MeshInstance3D . new ( ) ; g . add_child ( preview )
preview . mesh = BoxMesh . new ( ) ; preview . mesh . size = Vector3 ( 2 , . 06 , 2 )
var m = StandardMaterial3D . new ( ) ; m . transparency = BaseMaterial3D . TRANSPARENCY_ALPHA ; m . shading_mode = BaseMaterial3D . SHADING_MODE_UNSHADED ; m . albedo_color = Color ( . 2 , 1 , . 65 , . 35 )
preview . material_override = m ; preview . cast_shadow = GeometryInstance3D . SHADOW_CASTING_SETTING_OFF
m . render_priority = 110
grid . hide ( ) ; preview . hide ( )
func reset ( ) :
2026-10-29 21:39:15 +02:00
arcade . reset ( )
2026-10-28 15:39:06 +02:00
if g . life : g . life . activities . reset ( )
losses . reset ( ) ; expansion_level = 0 ; g . architecture . growth . set_level ( 0 )
cancel_placement ( false )
for s in stations : dispose_station ( s )
for h in helpers : h . root . queue_free ( )
for b in bars : b . queue_free ( )
stations . clear ( ) ; helpers . clear ( ) ; bars . clear ( )
make_grid ( )
unlock = 0 ; helper_speed = 0 ; helper_diligence = 0 ; automation = false ; spawn_clock = 0 ; darkness = 0
pressure_time = 0 ; penalty_clock = 0 ; penalty_gold_lost = 0 ; penalty_souls_lost = 0
if is_instance_valid ( pressure_label ) : pressure_label . text = " "
dialogue_clock = 0 ; dialogue_turn = 0
selected = - 1 ; pending = - 1 ; moving = - 1 ; build_mode = false
tree . hide ( ) ; tree_backdrop . hide ( ) ; context . hide ( ) ; catalogue . hide ( ) ; grid . hide ( ) ; preview . hide ( ) ; shade . color . a = 0
g . coins = 240
rebuild_nav ( ) ; refresh ( )
func message ( value ) :
notice . text = value ; notice_time = 4.0
func toggle_build ( ) :
if tree . visible : toggle_tree ( )
if not g . game_started or ( g . paused and not build_mode ) : return
if g . held > = 0 : drop_held ( )
cancel_placement ( false )
2026-10-29 21:39:15 +02:00
if not build_mode : arcade . release ( )
2026-10-28 15:39:06 +02:00
build_mode = not build_mode ; g . paused = build_mode
g . orbit . preserve_focus ( )
g . orbit . stop ( ) ; pending = - 1 ; moving = - 1 ; preview . hide ( ) ; context . hide ( )
grid . visible = build_mode ; catalogue . visible = build_mode
refresh ( )
func toggle_tree ( ) :
if not g . game_started : return
if tree . visible :
tree . hide ( ) ; g . paused = false
else :
if g . paused and not build_mode : return
if build_mode : toggle_build ( )
if g . held > = 0 : drop_held ( )
context . hide ( ) ; g . orbit . stop ( ) ; g . paused = true ; tree . show ( )
notice . text = " "
tree_backdrop . visible = tree . visible
refresh ( )
func begin_purchase ( kind ) :
if not build_mode or kind < 0 or kind > unlock or g . coins < PRICES [ kind ] : return
cancel_placement ( false )
pending = kind ; pending_turns = 0 ; moving = - 1 ; context . hide ( ) ; preview . show ( )
make_ghost ( )
catalogue . hide ( )
message ( " %s : выбери клетку. ЛКМ — разместить, ПКМ — отмена. " % TITLES [ kind ] )
func begin_move ( ) :
if not build_mode or selected < 0 or not is_free ( stations [ selected ] ) : return
cancel_placement ( false )
moving = selected ; pending = stations [ selected ] . selected ; pending_turns = stations [ selected ] . turns ; preview . show ( ) ; context . hide ( )
make_ghost ( )
stations [ moving ] . device . hide ( )
catalogue . hide ( )
message ( " Орудие следует за мышью. ЛКМ — поставить, ПКМ / Esc — вернуть назад. " )
func cancel_placement ( show_catalogue = true ) :
drag . cancel ( )
if moving > = 0 and moving < stations . size ( ) : stations [ moving ] . device . show ( )
if is_instance_valid ( ghost ) : ghost . hide ( ) ; ghost . queue_free ( )
ghost = null ; ghost_material = null ; pending = - 1 ; moving = - 1 ; pending_turns = 0
if is_instance_valid ( preview ) : preview . hide ( )
if is_instance_valid ( catalogue ) : catalogue . visible = show_catalogue and build_mode
func make_ghost ( ) :
2026-10-29 16:30:06 +02:00
# A placement preview needs only fresh visuals, not live restraint scripts,
# station dictionaries or references to the original moving nodes.
ghost = make_device ( pending , Vector3 . ZERO ) . device
2026-10-28 15:39:06 +02:00
ghost . name = " PlacementGhost " ; ghost . show ( )
ghost_material = StandardMaterial3D . new ( )
ghost_material . transparency = BaseMaterial3D . TRANSPARENCY_ALPHA
ghost_material . shading_mode = BaseMaterial3D . SHADING_MODE_UNSHADED
# The full-screen bokeh pass uses priority 100 and would overwrite transparent previews.
ghost_material . render_priority = 110
ghost_material . albedo_color = Color ( . 3 , . 95 , . 7 , . 55 )
var nodes = [ ghost ]
while not nodes . is_empty ( ) :
var node = nodes . pop_back ( )
for child in node . get_children ( ) : nodes . append ( child )
if node is MeshInstance3D :
node . material_override = ghost_material
node . cast_shadow = GeometryInstance3D . SHADOW_CASTING_SETTING_OFF
elif node is StaticBody3D :
node . collision_layer = 0 ; node . collision_mask = 0
elif node is Light3D : node . hide ( )
elif node is AudioStreamPlayer3D : node . stop ( )
update_preview ( )
func track_pointer ( event ) :
if event is InputEventMouseButton and event . button_index == MOUSE_BUTTON_LEFT : drag . left_down = event . pressed
if event is InputEventMouseMotion or event is InputEventMouseButton :
pointer_position = event . position
update_preview ( )
if drag . active and event is InputEventMouseMotion and drag . hover_delete ( event . position ) :
drag . confirm ( event . position ) ; g . get_viewport ( ) . set_input_as_handled ( ) ; return
if drag . active and event is InputEventMouseButton and event . button_index == MOUSE_BUTTON_LEFT :
if event . pressed : drag . confirm ( event . position )
else : drag . release ( event . position )
g . get_viewport ( ) . set_input_as_handled ( ) ; return
func update_preview ( ) :
if not build_mode or pending < 0 : return
var p = snap_to_grid ( ground_point ( pointer_position ) , pending , pending_turns )
preview . position = p + Vector3 ( 0 , . 25 , 0 )
var size = footprint ( pending , pending_turns )
preview . mesh . size = Vector3 ( size . x , . 06 , size . y )
var valid = valid_position ( p , pending , moving , pending_turns )
preview . material_override . albedo_color = Color ( . 15 , . 9 , . 55 , . 4 ) if valid else Color ( . 95 , . 12 , . 18 , . 5 )
if is_instance_valid ( ghost ) :
ghost . position = p
ghost . rotation . y = pending_turns * PI / 2
ghost_material . albedo_color = Color ( . 3 , . 95 , . 7 , . 55 ) if valid else Color ( 1 , . 2 , . 25 , . 55 )
func delete_selected ( ) :
if not build_mode or pending > = 0 or selected < 0 or not is_free ( stations [ selected ] ) : return
var s = stations [ selected ]
var removed = selected
var refund = int ( PRICES [ s . selected ] / 2 )
g . coins + = refund
dispose_station ( s ) ; bars . erase ( s . bar ) ; stations . remove_at ( selected )
for h in helpers :
if h . station > removed : h . station - = 1
elif h . station == removed : h . station = - 1
for soul in g . souls :
if soul . get ( " state " , " " ) == " mounted " and soul . assigned > removed : soul . assigned - = 1
if soul . get ( " origin_station " , - 1 ) > removed : soul . origin_station - = 1
selected = - 1 ; context . hide ( ) ; rebuild_nav ( ) ; refresh ( ) ; g . save_progress ( )
message ( " Орудие разобрано. Возвращено %d золота. " % refund )
play_build_sound ( false )
func play_build_sound ( placed ) :
build_player . stream = PLACE_SOUND if placed else REMOVE_SOUND
build_player . volume_db = - 3.0 + linear_to_db ( maxf ( . 0001 , g . whip_volume ) )
if not g . test_mode and not g . capture_mode and not g . muted and g . whip_volume > 0 : build_player . play ( )
func rotate_pending ( direction ) :
if not build_mode : return
if pending < 0 :
if not context . visible or selected < 0 or not is_free ( stations [ selected ] ) : return
begin_move ( )
if pending < 0 : return
pending_turns = wrapi ( pending_turns + direction , 0 , 4 )
update_preview ( )
func is_free ( s ) :
return s . soul < 0 and s . reserved < 0 and s . cooldown < = 0
func dispose_station ( s ) :
# Break the reference cycle between the apparatus state and its motion driver.
s . motion . d = null ; s . motion . g = null ; s . motion = null
if s . get ( " transfer " ) and is_instance_valid ( s . transfer ) : s . transfer . cancel ( )
s . device . queue_free ( ) ; s . bar . queue_free ( )
func _exit_tree ( ) :
for s in stations :
if s . motion : s . motion . d = null ; s . motion . g = null ; s . motion = null
func ground_point ( mouse = null ) :
if mouse == null : mouse = g . get_viewport ( ) . get_mouse_position ( )
var origin = g . camera . project_ray_origin ( mouse )
var direction = g . camera . project_ray_normal ( mouse )
if absf ( direction . y ) < . 00001 : return Vector3 . ZERO
return origin + direction * ( ( . 18 - origin . y ) / direction . y )
func footprint ( kind , turns = 0 ) :
var size = FOOTPRINTS [ kind ]
return Vector2i ( size . y , size . x ) if turns % 2 != 0 else size
func station_rect ( s ) :
return rect_at ( s . device . position , s . selected , s . turns )
func service_rect ( p , kind , turns ) :
var forward = Vector3 . BACK . rotated ( Vector3 . UP , turns * PI / 2 )
var center = p + forward * ( FOOTPRINTS [ kind ] . y / 2.0 + . 5 )
return Rect2 ( Vector2 ( center . x - . 5 , center . z - . 5 ) , Vector2 . ONE )
func snap_to_grid ( p , kind , turns = 0 ) :
var size = footprint ( kind , turns )
return Vector3 ( ORIGIN . x + floorf ( p . x - ORIGIN . x - size . x / 2.0 + . 5 ) + size . x / 2.0 , 0 , ORIGIN . y + floorf ( p . z - ORIGIN . y - size . y / 2.0 + . 5 ) + size . y / 2.0 )
func rect_at ( p , kind , turns = 0 ) :
var size = Vector2 ( footprint ( kind , turns ) )
return Rect2 ( Vector2 ( p . x , p . z ) - size / 2 , size )
func valid_position ( p , kind , ignore = - 1 , turns = 0 ) :
var r = rect_at ( p , kind , turns )
if not Rect2 ( ORIGIN , build_area ( ) ) . encloses ( r ) : return false
# Keep an approach lane in front of every device, including neighbouring devices.
var service = service_rect ( p , kind , turns )
if not Rect2 ( - 7.1 , - 4.8 , walk_right ( ) + 7.1 , 10.5 ) . encloses ( service ) : return false
for i in range ( stations . size ( ) ) :
if i == ignore : continue
var other = stations [ i ]
var o = station_rect ( other )
if r . intersects ( o ) or service . intersects ( o ) or r . intersects ( service_rect ( other . device . position , other . selected , other . turns ) ) : return false
return true
func place ( p ) :
if pending < 0 or not valid_position ( p , pending , moving , pending_turns ) : return false
var old = Vector3 . ZERO
var old_turns = 0
if moving > = 0 :
old = stations [ moving ] . device . position ; old_turns = stations [ moving ] . turns
stations [ moving ] . device . position = p ; stations [ moving ] . turns = pending_turns ; stations [ moving ] . device . rotation . y = pending_turns * PI / 2
else :
if g . coins < PRICES [ pending ] or pending > unlock : return false
add_station ( pending , p , pending_turns )
rebuild_nav ( )
if not accessible ( ) :
if moving > = 0 :
stations [ moving ] . device . position = old ; stations [ moving ] . turns = old_turns ; stations [ moving ] . device . rotation . y = old_turns * PI / 2
else :
var s = stations . pop_back ( ) ; dispose_station ( s ) ; bars . erase ( s . bar )
rebuild_nav ( ) ; message ( " Нужен свободный проход от ворот ко всем орудиям. " ) ; return false
if moving < 0 : g . coins - = PRICES [ pending ]
var placed = stations [ moving ] if moving > = 0 else stations . back ( )
var occupied = rect_at ( p , pending , pending_turns ) . grow ( . 4 )
if occupied . has_point ( Vector2 ( g . player . position . x , g . player . position . z ) ) : g . player . position = approach ( placed )
for h in helpers :
if occupied . has_point ( Vector2 ( h . root . position . x , h . root . position . z ) ) : h . root . position = approach ( placed )
for imp in g . life . imps :
if occupied . has_point ( Vector2 ( imp . root . position . x , imp . root . position . z ) ) :
imp . root . position = free_floor ( imp . root . position ) ; imp . revision = - 1 ; imp . velocity = Vector3 . ZERO ; imp . gait . reset ( )
placed . device . show ( )
cancel_placement ( false )
selected = - 1 ; context . hide ( ) ; refresh ( ) ; g . save_progress ( )
catalogue . visible = build_mode
play_build_sound ( true )
return true
func make_device ( kind , p ) :
var root = Node3D . new ( ) ; g . add_child ( root ) ; root . position = p
var s = { " device " : root , " selected " : kind , " crank " : null , " door " : null , " second_door " : null , " flame " : null , " elapsed " : 0.0 , " stage " : 0 , " release_clock " : 0.0 , " soul " : - 1 , " reserved " : - 1 , " cooldown " : 0.0 , " hits " : 0 , " hit_clock " : 0.0 , " placement " : 0.0 , " idle_time " : 0.0 , " transfer " : null , " from " : Vector3 . ZERO , " motion " : null , " operator " : - 1 , " ready " : false }
preload ( " res://equipment.gd " ) . new ( ) . build ( g , s )
return s
func add_station ( kind , p , turns = 0 ) :
var s = make_device ( kind , p )
s [ " turns " ] = wrapi ( turns , 0 , 4 ) ; s . device . rotation . y = s . turns * PI / 2
var motion = preload ( " res://apparatus_motion.gd " ) . new ( ) ; motion . setup ( g , s ) ; s . motion = motion
mesh_walking . build ( s . device )
var bar = ProgressBar . new ( ) ; g . ui_compat . add_child ( bar ) ; bar . size = Vector2 ( 96 , 9 ) ; bar . show_percentage = false ; bar . mouse_filter = Control . MOUSE_FILTER_IGNORE
var fill = StyleBoxFlat . new ( ) ; fill . bg_color = Color ( " a88b52 " )
var track = StyleBoxFlat . new ( ) ; track . bg_color = Color ( " 211826 " ) ; track . border_color = Color ( " 66513a " ) ; track . set_border_width_all ( 1 )
fill . bg_color = Color ( " 719a96 " ) ; track . bg_color = Color ( " 141b1d " ) ; track . border_color = Color ( " 757f7b " )
bar . add_theme_stylebox_override ( " fill " , fill ) ; bar . add_theme_stylebox_override ( " background " , track )
bar . add_theme_font_size_override ( " font_size " , 1 ) ; bar . size = Vector2 ( 96 , 9 )
bar . hide ( ) ; s [ " bar " ] = bar ; bars . append ( bar ) ; stations . append ( s )
return s
func approach ( s ) :
var p = s . device . position
return p + Vector3 ( 0 , 0 , FOOTPRINTS [ s . selected ] . y / 2.0 + . 55 ) . rotated ( Vector3 . UP , s . turns * PI / 2 )
func cell ( p ) :
return Vector2i ( clampi ( roundi ( ( p . x + 7.5 ) * 2 ) , 0 , nav . region . size . x - 1 ) , clampi ( roundi ( ( p . z + 5 ) * 2 ) , 0 , 21 ) )
func rebuild_nav ( ) :
mesh_walking . rebuild ( stations )
2026-10-29 13:16:22 +02:00
free_floor_points . clear ( )
2026-10-28 15:39:06 +02:00
nav . region = Rect2i ( 0 , 0 , 38 + ceili ( g . architecture . growth . extra_width ( expansion_level ) * 2 ) , 22 ) ; nav . cell_size = Vector2 ( . 5 , . 5 ) ; nav . offset = Vector2 ( - 7.5 , - 5 )
nav . diagonal_mode = AStarGrid2D . DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES ; nav . update ( )
for x in range ( nav . region . size . x ) :
for z in range ( 22 ) :
var p = Vector2 ( - 7.5 + x * . 5 , - 5 + z * . 5 )
2026-10-29 16:30:06 +02:00
var blocked = mesh_walking . blocked ( p , . 42 ) or p . x > walk_right ( )
2026-10-28 15:39:06 +02:00
nav . set_point_solid ( Vector2i ( x , z ) , blocked )
2026-10-29 13:16:22 +02:00
if not blocked and p . x > = - 7.1 and p . x < = walk_right ( ) and p . y > = - 4.8 and p . y < = 5.6 :
free_floor_points . append ( Vector3 ( p . x , 0 , p . y ) )
2026-10-28 15:39:06 +02:00
revision + = 1
func accessible ( ) :
for s in stations :
if nav . get_id_path ( cell ( g . GATE_EXIT ) , cell ( approach ( s ) ) ) . is_empty ( ) : return false
return true
func upgrade ( key ) :
if key . begins_with ( " unlock " ) :
var kind = int ( key . right ( 1 ) ) ; var cost = Economy . BLUEPRINT_PRICES [ kind ]
if unlock != kind - 1 or not can_afford_upgrade ( cost ) : return
g . coins - = cost ; unlock = kind
elif key in [ " speed " , " power " , " leadership " ] :
if g . development . points < 1 : return
if key == " speed " :
if g . speed_level > = 3 : return
g . speed_level + = 1
elif key == " power " :
if g . development . action_level > = 3 : return
g . development . action_level + = 1
else :
if g . development . leadership > = 3 : return
g . development . leadership + = 1
g . development . points - = 1
elif key == " hire " :
if helpers . size ( ) > = 3 : return
var cost = Economy . HIRE_PRICES [ helpers . size ( ) ]
if g . essence < cost : return
g . essence - = cost ; add_helper ( )
elif key == " haste " :
if helpers . is_empty ( ) or helper_speed > = 3 : return
var cost = Economy . HASTE_PRICES [ helper_speed ]
if g . essence < cost : return
g . essence - = cost ; helper_speed + = 1
elif key == " diligence " :
if helpers . is_empty ( ) or helper_diligence > = 3 : return
var cost = Economy . DILIGENCE_PRICES [ helper_diligence ]
if g . essence < cost : return
g . essence - = cost ; helper_diligence + = 1
elif key == " auto " :
if helpers . is_empty ( ) or automation or g . essence < Economy . AUTOMATION_PRICE : return
g . essence - = Economy . AUTOMATION_PRICE ; automation = true
refresh ( ) ; g . save_progress ( )
func action_rate ( d ) :
var skill = helper_diligence * . 25 if d . operator > = 0 else g . development . action_level * . 20
return ( 1.0 + skill ) * ( 1.0 + g . development . leadership * . 08 ) / Economy . work_multiplier ( g . development . xp )
func can_afford_upgrade ( cost ) :
# Keep enough for the first altar: spending everything on blueprints/staff must not strand a new game.
return g . coins > = cost + ( PRICES [ 0 ] if stations . is_empty ( ) else 0 )
func add_helper ( ) :
2026-10-29 21:39:15 +02:00
var root = Node3D . new ( ) ; g . add_child ( root ) ; root . position = roaming . spawn_point ( )
2026-10-28 15:39:06 +02:00
var model = preload ( " res://succubus_actor.gd " ) . new ( ) ; root . add_child ( model ) ; model . scale = Vector3 . ONE * . 9 ; model . configure ( g )
model . set_meta ( " helper_tint " , Color ( " 779fff " ) )
for mesh in model . find_children ( " * " , " MeshInstance3D " , true , false ) :
for surface in range ( mesh . mesh . get_surface_count ( ) ) :
var original = mesh . get_active_material ( surface )
if original is StandardMaterial3D :
var tinted = original . duplicate ( ) ; tinted . albedo_color = original . albedo_color . lerp ( Color ( . 20 , . 60 , . 95 ) , . 45 )
tinted . emission_enabled = true ; tinted . emission = Color ( . 035 , . 055 , . 14 ) ; tinted . emission_energy_multiplier = . 35
mesh . set_surface_override_material ( surface , tinted )
root . set_meta ( " floor_halo " , false )
helpers . append ( { " root " : root , " model " : model , " soul " : - 1 , " station " : - 1 , " state " : " idle " , " path " : PackedVector2Array ( ) , " destination " : Vector2i ( - 1 , - 1 ) , " revision " : - 1 } )
func refresh ( ) :
if expansion_button :
expansion_button . text = " Площадь +20 % % · 500 золота · %d / 3 " %expansion_level if expansion_level < 3 else " Площадь расширена · 3 / 3 "
expansion_button . disabled = expansion_level > = 3 or g . coins < 500
if not is_instance_valid ( info ) : return
g . refresh_ui ( )
info . text = " Уровень %d · Орудия %d · Помощницы %d " % [ Economy . level ( g . development . xp ) , stations . size ( ) , helpers . size ( ) ]
if tree_summary : tree_summary . text = " ЗОЛОТО %d · ДУШИ %d · УРОВЕНЬ %d · ОЧКИ %d " % [ g . coins , g . essence , Economy . level ( g . development . xp ) , g . development . points ]
for i in range ( buy_buttons . size ( ) ) :
buy_labels [ i ] . text = " %s
%d золота · %d × %d %s " % [ TITLES [ i ] , PRICES [ i ] , FOOTPRINTS [ i ] . x , FOOTPRINTS [ i ] . y , " [закрыто] " if i > unlock else " " ]
buy_buttons [ i ] . disabled = i > unlock or g . coins < PRICES [ i ]
var unavailable = buy_buttons [ i ] . disabled
var disabled_color = buy_buttons [ i ] . get_theme_color ( " font_disabled_color " )
buy_labels [ i ] . add_theme_color_override ( " font_color " , disabled_color if unavailable else Color ( " d5c9b5 " ) )
buy_icons [ i ] . tint = disabled_color if unavailable else Color ( " bac4bd " )
for n in node_buttons :
var enabled = false ; var value = " " ; var key = n . key
if key . begins_with ( " unlock " ) :
var kind = int ( key . right ( 1 ) ) ; var cost = Economy . BLUEPRINT_PRICES [ kind ]
enabled = unlock == kind - 1 and can_afford_upgrade ( cost )
value = " %d золота " %cost
else :
match key :
" speed " , " power " , " leadership " :
var rank = g . speed_level if key == " speed " else g . development . action_level if key == " power " else g . development . leadership
enabled = g . development . points > 0 and rank < 3 ; value = " 1 очко уровня "
" hire " :
enabled = helpers . size ( ) < 3 and g . essence > = Economy . HIRE_PRICES [ mini ( 2 , helpers . size ( ) ) ]
value = " %d душ " %Economy . HIRE_PRICES [ mini ( 2 , helpers . size ( ) ) ]
" auto " : enabled = not helpers . is_empty ( ) and not automation and g . essence > = Economy . AUTOMATION_PRICE ; value = " 4 души "
" haste " , " diligence " :
var rank = helper_speed if key == " haste " else helper_diligence
var prices = Economy . HASTE_PRICES if key == " haste " else Economy . DILIGENCE_PRICES
enabled = not helpers . is_empty ( ) and rank < 3 and g . essence > = prices [ mini ( rank , 2 ) ]
value = " %d душ " %prices [ mini ( rank , 2 ) ]
_ : value = " — "
n . button . disabled = not enabled ; n . rank . text = value
var purchased = 0
if key . begins_with ( " unlock " ) : purchased = 1 if unlock > = int ( key . right ( 1 ) ) else 0
else :
match key :
" speed " : purchased = g . speed_level
" power " : purchased = g . development . action_level
" leadership " : purchased = g . development . leadership
" hire " : purchased = helpers . size ( )
" auto " : purchased = 1 if automation else 0
" haste " : purchased = helper_speed
" diligence " : purchased = helper_diligence
n . gems . filled = purchased
n . button . modulate = Color . WHITE
build_button . text = " " ; build_button . set_pressed_no_signal ( build_mode )
grimoire_button . text = " " ; grimoire_button . set_pressed_no_signal ( tree . visible )
2026-10-29 21:39:15 +02:00
help_primary . text = " ЛКМ — установить · Колесо — поворот " if build_mode else " ЛКМ — душа / пульс · ПКМ — кликай для разгона "
2026-10-28 15:39:06 +02:00
help_secondary . text = " ПКМ / Esc — отменить · [B] — выйти " if build_mode else " WASD — идти · Колесо — камера "
func queued ( ) :
return g . souls . filter ( func ( s ) : return s . get ( " state " , " queue " ) == " queue " )
func waiting ( ) :
return g . souls . filter ( func ( s ) : return s . get ( " state " , " queue " ) in [ " queue " , " reserved " ] )
func queue_load ( ) :
# Carrying a soul reserves its queue slot so dropping it can never create an eighth occupant.
2026-10-29 21:39:15 +02:00
return waiting ( ) . size ( ) + g . souls . filter ( func ( s ) : return s . get ( " state " , " " ) in [ " held " , " charmed " ] and s . get ( " queue_reserved " , true ) ) . size ( )
2026-10-28 15:39:06 +02:00
func spawn ( ) :
if not g . game_started or stations . is_empty ( ) or queue_load ( ) > = QUEUE_CAPACITY : return false
g . spawn_soul ( )
var s = g . souls . back ( ) ; s [ " state " ] = " queue " ; s [ " assigned " ] = - 1 ; s [ " entry_time " ] = 0.0
return true
func queue_target ( index , count ) :
return Vector3 ( - 5.3 , 0 , 3.4 - mini ( index , QUEUE_CAPACITY - 1 ) * 1.15 )
func drop_held ( ) :
var i = g . index_of ( g . held )
if i > = 0 : sentences . drop ( g . souls [ i ] )
g . held = - 1
func attach ( s , station_index , operator_id = - 1 , claimant_id = - 1 ) :
if station_index < 0 or station_index > = stations . size ( ) : return false
var d = stations [ station_index ]
if d . soul > = 0 or d . cooldown > 0 or not sentences . accepts ( s , d . selected ) : return false
var displaced = d . reserved
if claimant_id > = 0 and displaced != claimant_id : return false
var transfer = preload ( " res://soul_transfer.gd " ) . new ( ) ; g . add_child ( transfer ) ; transfer . begin ( g , s )
sentences . release_origin ( s )
s . queue_reserved = false ; d . ready = false
d . soul = s . id ; d . reserved = - 1 ; d . operator = operator_id ; d . elapsed = 0 ; d . stage = 0 ; d . hits = 0 ; d . placement = . 5 ; d . idle_time = 0 ; d . transfer = transfer ; d . from = s . node . position
s . state = " mounted " ; s . assigned = station_index ; s . visual . position = Vector3 . ZERO ; s . visual . rotation = Vector3 . ZERO ; s . visual . scale = Vector3 . ONE ; s . visual . mount_station ( d . selected )
d . motion . reset ( )
if d . selected == 1 : s . visual . rotation . x = - PI / 2 ; s . visual . position = Vector3 ( 0 , 1.04 , 1.13 )
elif d . selected == 2 : s . visual . position = Vector3 ( 0 , . 47 , . 27 )
elif d . selected == 3 : s . visual . position = Vector3 ( 0 , . 22 , 0 )
elif d . selected == 4 : s . visual . position = Vector3 . ZERO
elif d . selected == 5 : s . visual . position = Vector3 ( 0 , . 45 , 0 ) ; s . visual . scale = Vector3 . ONE * . 85
s . visual . update_torture ( 0 , false )
s [ " pose_target " ] = s . visual . transform ; s . node . position = d . device . position ; s . node . rotation = Vector3 ( 0 , d . turns * PI / 2 , 0 )
transfer . target_ready ( )
sentences . update_label ( s )
announce_soul ( s )
# Arrival wins over a helper's advance reservation, never over an occupied device.
if displaced > = 0 and displaced != claimant_id : reroute_helper ( displaced )
return true
func try_player_attach ( station_index ) :
var index = g . index_of ( g . held )
if index < 0 or station_index < 0 or station_index > = stations . size ( ) : return false
var d = stations [ station_index ]
if g . player . position . distance_to ( approach ( d ) ) > 1.5 : return false
if not attach ( g . souls [ index ] , station_index ) : return false
g . held = - 1
2026-10-29 21:39:15 +02:00
arcade . add_charge ( 10 )
2026-10-28 15:39:06 +02:00
return true
func reroute_helper ( hi ) :
if hi < 0 or hi > = helpers . size ( ) : return false
var h = helpers [ hi ]
if h . station > = 0 and h . station < stations . size ( ) and stations [ h . station ] . reserved == hi : stations [ h . station ] . reserved = - 1
h . station = - 1 ; h . path = PackedVector2Array ( ) ; h . destination = Vector2i ( - 1 , - 1 ) ; h . revision = - 1
var index = g . index_of ( h . soul )
if index < 0 : h . state = " idle " ; h . soul = - 1 ; return false
var soul = g . souls [ index ]
var distance = INF
for si in range ( stations . size ( ) ) :
if not is_free ( stations [ si ] ) or not sentences . accepts ( soul , stations [ si ] . selected ) : continue
var candidate = h . root . position . distance_squared_to ( approach ( stations [ si ] ) )
if candidate < distance : distance = candidate ; h . station = si
if h . station > = 0 : stations [ h . station ] . reserved = hi
else : h . model . set_walking ( false )
return h . station > = 0
func finish ( d ) :
var index = g . index_of ( d . soul )
if index < 0 : return
var soul = g . souls [ index ]
var complete = sentences . complete_stage ( d )
EXTRA . animate ( g , d , 0 , false )
if not complete : return
if soul . has ( " task_badge " ) : soul . task_badge . hide ( )
g . life . burn ( soul ) ; g . souls . remove_at ( index )
var count = soul . required . size ( )
var reward = Economy . reward ( soul . required , g . development . xp )
g . coins + = reward . gold ; g . essence + = reward . souls ; g . done + = 1
g . development . reward ( reward . xp )
2026-10-29 21:39:15 +02:00
arcade . add_charge ( 5 )
2026-10-28 15:39:06 +02:00
d . soul = - 1 ; d . cooldown = 2.6 ; d . release_clock = 2.05 ; d . operator = - 1 ; d . bar . hide ( )
if d . flame : d . flame . hide ( )
refresh ( ) ; g . save_progress ( )
2026-10-29 21:39:15 +02:00
func step_station ( s , dt , active , production_scale = 1.0 , arcade_work = false ) :
2026-10-28 15:39:06 +02:00
s . cooldown = maxf ( 0 , s . cooldown - dt ) ; s . hit_clock = maxf ( 0 , s . hit_clock - dt )
s . release_clock = maxf ( 0 , s . release_clock - dt )
if s . cooldown < = . 45 and s . soul < 0 and s . door :
s . door . rotation . y = move_toward ( s . door . rotation . y , - 1.8 , dt * 4 )
s . second_door . rotation . y = move_toward ( s . second_door . rotation . y , 1.8 , dt * 4 )
var i = g . index_of ( s . soul )
if i < 0 :
EXTRA . animate ( g , s , dt , false )
if s . selected == 3 :
g . working = - 1 ; s . motion . update ( dt , false )
return
var soul = g . souls [ i ]
if s . placement > 0 :
var elapsed = minf ( dt , s . placement ) ; s . placement = maxf ( 0 , s . placement - dt )
if is_instance_valid ( s . transfer ) : s . transfer . advance ( elapsed )
if s . placement < = . 00001 :
s . placement = 0
if is_instance_valid ( s . transfer ) : s . transfer . finish ( )
s . transfer = null
return
2026-10-29 21:39:15 +02:00
if soul . state in [ " held " , " transit " , " charmed " ] : s . idle_time = 0 ; return
2026-10-28 15:39:06 +02:00
s . idle_time = 0.0 if active and not s . ready else s . idle_time + dt
if s . idle_time + . 00001 > = losses . TIMEOUT : losses . station_timeout ( s ) ; return
if s . ready :
soul . visual . update_torture ( dt , false ) ; EXTRA . animate ( g , s , dt , false )
s . bar . visible = soul . state in [ " ready " , " reserved_next " ]
s . bar . position = g . camera . unproject_position ( s . device . position + Vector3 ( 0 , 3.4 , 0 ) ) - Vector2 ( 48 , 0 )
return
soul . node . position = s . device . position
2026-10-29 21:39:15 +02:00
var rate = action_rate ( s ) * production_scale
2026-10-28 15:39:06 +02:00
if active :
if s . selected == 0 :
if s . hit_clock < = 0 :
2026-10-29 21:39:15 +02:00
s . hit_clock = . 45 / rate ; s . hits + = 1
if not arcade_work : g . play_whip ( )
2026-10-28 15:39:06 +02:00
soul . visual . whip_reaction ( )
2026-10-29 21:39:15 +02:00
if not arcade_work : preload ( " res://whip_impact.gd " ) . new ( ) . play ( g , s . device , soul . visual , ( g . avatar . global_position if s . operator < 0 else helpers [ s . operator ] . model . global_position ) + Vector3 ( 0 , 1.45 , 0 ) )
if not arcade_work and s . operator < 0 : g . avatar . strike ( s . hit_clock )
elif not arcade_work and s . operator > = 0 and s . operator < helpers . size ( ) : helpers [ s . operator ] . model . strike ( s . hit_clock )
2026-10-28 15:39:06 +02:00
s . elapsed = float ( s . hits ) / 5.0
elif s . selected == 1 :
s . elapsed + = dt * rate
if s . stage == 0 and s . elapsed > = 1 : s . stage = 1 ; s . elapsed = 0
elif s . selected == 2 : s . elapsed + = dt * rate
elif s . selected > = 4 : s . elapsed + = dt * rate
else :
if s . stage == 0 :
s . elapsed + = dt ; s . door . rotation . y = move_toward ( s . door . rotation . y , 0 , dt * 5.2 ) ; s . second_door . rotation . y = move_toward ( s . second_door . rotation . y , 0 , dt * 5.2 )
if s . elapsed > = . 35 : s . stage = 1 ; s . elapsed = 0
else : s . elapsed + = dt * rate
if s . crank : s . crank . rotation . z + = dt * rate * 4
elif s . selected == 1 and s . stage == 1 : s . elapsed = 0
if s . selected == 2 :
var a = s . crank . rotation . z ; soul . visual . rotation . z = a ; soul . visual . position = Vector3 ( sin ( a ) * 1.15 , 1.62 - cos ( a ) * 1.15 , . 27 )
var progress = s . elapsed
if s . selected == 1 : progress = ( s . elapsed if s . stage == 0 else 1 + s . elapsed ) / 3.0
elif s . selected == 2 : progress = s . elapsed / 5
elif s . selected == 3 : progress = ( s . elapsed if s . stage == 0 else . 35 + s . elapsed ) / 3.35
elif s . selected > = 4 : progress = s . elapsed / ( 6.0 if s . selected == 4 else 7.0 )
s . bar . value = progress * 100 ; s . bar . show ( )
s . bar . position = g . camera . unproject_position ( s . device . position + Vector3 ( 0 , 3.4 , 0 ) ) - Vector2 ( 48 , 0 )
if s . flame : s . flame . visible = active and ( s . stage == 1 or s . selected == 5 )
soul . visual . update_torture ( dt , active )
g . working = s . soul ; g . STATION = s . device . position ; s . motion . update ( dt , active ) ; g . working = - 1
EXTRA . animate ( g , s , dt , active )
if ( s . selected == 0 and s . hits > = 5 ) or ( s . selected == 1 and s . stage == 1 and s . elapsed > = 2 ) or ( s . selected == 2 and s . elapsed > = 5 ) or ( s . selected == 3 and s . stage == 1 and s . elapsed > = 3 ) or ( s . selected == 4 and s . elapsed > = 6 ) or ( s . selected == 5 and s . elapsed > = 7 ) : finish ( s )
func move_helper ( h , target , dt ) :
var destination = cell ( target )
if h . destination != destination or h . revision != revision :
h . destination = destination ; h . revision = revision ; h . path = nav . get_point_path ( cell ( h . root . position ) , destination )
if not h . path . is_empty ( ) : h . path . remove_at ( 0 )
var next = target
if not h . path . is_empty ( ) : next = Vector3 ( h . path [ 0 ] . x , 0 , h . path [ 0 ] . y )
var delta = next - h . root . position ; delta . y = 0
var walking = delta . length ( ) > . 06
if walking :
mesh_walking . move_actor ( h . root , h . root . position . move_toward ( next , dt * ( 2.5 + helper_speed * . 625 ) ) - h . root . position )
h . model . rotation . y = lerp_angle ( h . model . rotation . y , atan2 ( delta . x , delta . z ) , minf ( 1 , dt * 10 ) )
if h . root . position . distance_to ( next ) < . 08 and not h . path . is_empty ( ) : h . path . remove_at ( 0 )
h . model . set_walking ( walking )
return h . root . position . distance_to ( target ) < . 3
func update_helpers ( dt ) :
for hi in range ( helpers . size ( ) ) :
var h = helpers [ hi ]
if h . state == " idle " :
var waiting = g . souls . filter ( func ( s ) : return s . state == " ready " ) + queued ( ) . filter ( func ( s ) : return not s . entering )
var free = - 1
var soul = null
for candidate in waiting :
for si in range ( stations . size ( ) ) :
if is_free ( stations [ si ] ) and sentences . accepts ( candidate , stations [ si ] . selected ) : free = si ; soul = candidate ; break
if soul != null : break
if soul == null :
2026-10-29 21:39:15 +02:00
roaming . update ( h , dt ) ; continue
roaming . cancel ( h )
2026-10-28 15:39:06 +02:00
soul . state = " reserved_next " if soul . get ( " origin_station " , - 1 ) > = 0 else " reserved " ; soul . assigned = hi
h . soul = soul . id ; h . station = free ; h . state = " collect " ; stations [ free ] . reserved = hi
var index = g . index_of ( h . soul )
if h . state in [ " collect " , " deliver " ] :
if index < 0 :
reroute_helper ( hi ) ; continue
if h . station < 0 or h . station > = stations . size ( ) or stations [ h . station ] . reserved != hi or stations [ h . station ] . soul > = 0 :
if not reroute_helper ( hi ) : continue
if h . state == " collect " :
if index < 0 : h . state = " idle " ; stations [ h . station ] . reserved = - 1 ; continue
var target = g . souls [ index ] . node . position
if g . souls [ index ] . get ( " origin_station " , - 1 ) > = 0 : target = approach ( stations [ g . souls [ index ] . origin_station ] )
if move_helper ( h , target , dt ) :
h . state = " deliver " ; g . souls [ index ] . state = " transit " ; sentences . float_pose ( g . souls [ index ] )
elif h . state == " deliver " :
if index < 0 : h . state = " idle " ; stations [ h . station ] . reserved = - 1 ; continue
var s = g . souls [ index ]
s . node . position = s . node . position . move_toward ( h . root . position + Vector3 ( - . 65 , 0 , 0 ) , dt * 5 )
s . visual . position . y = . 65 + sin ( g . time * 2 ) * . 06
if move_helper ( h , approach ( stations [ h . station ] ) , dt ) :
if attach ( s , h . station , hi if automation else - 1 , hi ) :
h . state = " operate " if automation else " idle " ; h . soul = - 1
else : reroute_helper ( hi )
elif h . state == " operate " :
h . model . set_walking ( false )
if stations [ h . station ] . soul < 0 or stations [ h . station ] . ready : h . state = " idle "
func click_station ( index ) :
if not build_mode : context . hide ( ) ; return
selected = index ; var s = stations [ index ]
context . hide ( ) ; refresh ( )
if g . held > = 0 and is_free ( s ) : message ( " Подведи душу к передней стороне орудия. " )
func announce_soul ( s , override_text = " " ) :
if not g . dialogue . souls_enabled : return
if g . paused or s . entering : return
if dialogue_clock < DIALOGUE_INTERVAL : return
g . development . speak ( s , override_text ) ; dialogue_clock = 0
func update_soul_dialogue ( dt ) :
if not g . dialogue . souls_enabled : return
dialogue_clock + = dt
if dialogue_clock < DIALOGUE_INTERVAL : return
var available = g . souls . filter ( func ( s ) : return not s . entering and s . state in [ " queue " , " ready " , " mounted " ] )
if available . is_empty ( ) : return
var s = available [ dialogue_turn %available . size ( ) ] ; dialogue_turn + = 1
announce_soul ( s )
func input ( event ) :
2026-10-29 21:39:15 +02:00
if arcade . input ( event ) : return true
2026-10-28 15:39:06 +02:00
if drag . active and event is InputEventMouseButton and event . button_index == MOUSE_BUTTON_LEFT and event . pressed :
return drag . confirm ( event . position )
if event is InputEventMouseButton and event . button_index == MOUSE_BUTTON_LEFT and not event . pressed :
if drag . release ( event . position ) : return true
if event is InputEventKey and event . pressed and not event . echo :
if event . physical_keycode == KEY_B : toggle_build ( ) ; return true
if event . physical_keycode == KEY_T : toggle_tree ( ) ; return true
if event . keycode == KEY_F5 or event . physical_keycode == KEY_F5 :
g . development . test_boost ( ) ; refresh ( ) ; return true
if event . keycode == KEY_ESCAPE :
if pending > = 0 : cancel_placement ( ) ; return true
if tree . visible : toggle_tree ( ) ; return true
if build_mode : toggle_build ( ) ; return true
if context . visible : context . hide ( ) ; return true
if event is InputEventMouseButton and event . pressed :
if build_mode and event . button_index in [ MOUSE_BUTTON_WHEEL_UP , MOUSE_BUTTON_WHEEL_DOWN ] :
if ( pending > = 0 or context . visible ) and not event . ctrl_pressed :
rotate_pending ( 1 if event . button_index == MOUSE_BUTTON_WHEEL_UP else - 1 )
else : g . camera . size = clampf ( g . camera . size + ( - 1 if event . button_index == MOUSE_BUTTON_WHEEL_UP else 1 ) , 12 , 48 )
return true
if event . button_index == MOUSE_BUTTON_RIGHT and build_mode :
cancel_placement ( ) ; return true
if event . button_index == MOUSE_BUTTON_LEFT :
if build_mode and pending > = 0 : place ( snap_to_grid ( ground_point ( event . position ) , pending , pending_turns ) ) ; return true
if g . paused and not build_mode : return false
if not build_mode :
# Hit the visible mounted soul without opening any construction controls.
var picked = g . index_of ( g . pick_soul ( event . position ) )
if picked > = 0 and g . souls [ picked ] . state == " ready " :
var origin = g . souls [ picked ] . origin_station
if g . player . position . distance_to ( approach ( stations [ origin ] ) ) < 2.5 : sentences . pickup ( g . souls [ picked ] )
else : message ( " Подойди ближе к душе. " )
return true
if picked > = 0 and g . souls [ picked ] . get ( " state " , " " ) == " mounted " :
var target = g . souls [ picked ] . assigned
2026-10-29 21:39:15 +02:00
arcade . tap ( target )
2026-10-28 15:39:06 +02:00
return true
var p = ground_point ( event . position )
# Devices are selected by their floor footprint, independent of camera angle.
for i in range ( stations . size ( ) - 1 , - 1 , - 1 ) :
if i == station_at_screen ( event . position ) :
if build_mode : click_station ( i ) ; drag . arm ( i , event . position )
if not build_mode and g . held > = 0 and try_player_attach ( i ) : return true
if not build_mode and stations [ i ] . ready and g . player . position . distance_to ( approach ( stations [ i ] ) ) < 2.5 :
var ready_index = g . index_of ( stations [ i ] . soul )
if ready_index > = 0 : sentences . pickup ( g . souls [ ready_index ] )
return true
2026-10-29 21:39:15 +02:00
if not build_mode : arcade . tap ( i )
2026-10-28 15:39:06 +02:00
return true
context . hide ( ) ; selected = - 1
if build_mode : return true
var id = g . pick_soul ( event . position ) ; var si = g . index_of ( id )
if si > = 0 and g . souls [ si ] . get ( " state " , " " ) == " queue " :
if g . player . position . distance_to ( g . souls [ si ] . node . position ) > 2.5 : message ( " Подойди ближе к душе. " ) ; return true
if g . held > = 0 : drop_held ( )
sentences . pickup ( g . souls [ si ] ) ; message ( " Душа следует за тобой. Осталось: " + sentences . remaining_text ( g . souls [ si ] ) )
elif g . held > = 0 : drop_held ( )
return true
return false
func update ( dt ) :
for imp in g . life . imps + g . life . neighbours : g . life . activities . sync_audio ( imp )
if not g . game_started : return
for device in stations :
if device . has ( " special " ) :
for player in device . special . players : player . stream_paused = g . paused
if is_instance_valid ( g . life . hero_bubble ) : g . life . hero_bubble . visible = not g . paused
if is_instance_valid ( g . development . bubble ) : g . development . bubble . visible = not g . paused
if not build_mode : context . hide ( )
if build_mode and context . visible and selected > = 0 and selected < stations . size ( ) :
var pos = g . camera . unproject_position ( stations [ selected ] . device . position + Vector3 ( 0 , 2.7 , 0 ) )
context . position = Vector2 ( clampf ( pos . x - context . size . x / 2 , 24 , 1060 - context . size . x ) , clampf ( pos . y - context . size . y - 12 , 110 , 790 - context . size . y ) )
if build_mode : g . orbit . update ( dt )
drag . update ( dt )
update_preview ( )
sentences . update_icons ( )
2026-10-29 21:39:15 +02:00
arcade . update ( dt )
2026-10-28 15:39:06 +02:00
if g . paused : return
if is_instance_valid ( g . development . bubble ) :
var d = g . development ; d . bubble_time - = dt
var index = g . index_of ( d . bubble_id )
if index < 0 or d . bubble_time < = 0 : d . bubble . queue_free ( ) ; d . bubble = null
else :
var point = g . camera . unproject_position ( g . souls [ index ] . node . position + Vector3 ( 0 , 5.4 , 0 ) )
g . dialogue . place_bubble ( d . bubble , point )
g . talk_clock + = dt
if g . talk_clock > HERO_INTERVAL : g . say ( g . quips [ g . rng . randi_range ( 0 , g . quips . size ( ) - 1 ) ] )
notice_time = maxf ( 0 , notice_time - dt )
if notice_time < = 0 : notice . text = " "
spawn_clock = 0.0 if stations . is_empty ( ) else minf ( Economy . SPAWN_INTERVAL , spawn_clock + dt )
if spawn_clock > = Economy . SPAWN_INTERVAL and spawn ( ) : spawn_clock = 0
var queue = waiting ( )
var count = queue_load ( )
timer_label . text = " Очередь: %d / 7 %s \n %s " % [ count , " (1 в пути) " if g . held > = 0 else " " , " Ворота ждут свободного места " if count > = QUEUE_CAPACITY else " Следующая душа через %.1f с " % ( Economy . SPAWN_INTERVAL - spawn_clock ) ]
if stations . is_empty ( ) : timer_label . text = " Установи первое орудие, чтобы появились души "
var target = . 42 if count > = QUEUE_CAPACITY else 0.0
darkness = move_toward ( darkness , target , dt * . 035 ) ; shade . color . a = darkness
pressure . text = " ОЧЕРЕДЬ ЗАПОЛНЕНА \n Ускорь работу цеха " if count > = QUEUE_CAPACITY else " "
update_pressure ( dt , count )
for i in range ( queue . size ( ) ) :
var s = queue [ i ] ; s . entry_time + = dt
s . entering = s . entry_time < . 7
s . node . position = s . node . position . move_toward ( queue_target ( i , count ) , dt * 2.5 )
s . visual . position . y = . 55 + sin ( g . time * 2 + s . phase ) * . 06
g . set_soul_reveal ( s . visual , minf ( 1 , s . entry_time / . 7 ) )
losses . queue_step ( dt ) ; losses . update_departures ( dt )
update_soul_dialogue ( dt )
g . gate_target = 3.5 if not stations . is_empty ( ) and spawn_clock < 1.2 else 0
g . gate . position . y = move_toward ( g . gate . position . y , g . gate_target , dt * 5 )
g . stage_effects . update ( dt ) ; g . update_wisps ( dt )
move_player ( dt )
if g . held > = 0 :
var index = g . index_of ( g . held )
if index > = 0 :
var s = g . souls [ index ]
sentences . follow_carrier ( s , g . player . position , g . face , dt )
var candidates = range ( stations . size ( ) )
candidates . sort_custom ( func ( a , b ) : return g . player . position . distance_squared_to ( approach ( stations [ a ] ) ) < g . player . position . distance_squared_to ( approach ( stations [ b ] ) ) )
for i in candidates :
if try_player_attach ( i ) : break
2026-10-29 21:39:15 +02:00
arcade . follow ( dt )
2026-10-28 15:39:06 +02:00
update_helpers ( dt )
for s in stations :
2026-10-29 21:39:15 +02:00
step_station ( s , dt , true , arcade . production ( s ) , true )
2026-10-28 15:39:06 +02:00
g . life . update ( dt )
for i in range ( g . popups . size ( ) - 1 , - 1 , - 1 ) :
var p = g . popups [ i ] ; p . ttl - = dt ; p . node . position . y + = dt * . 7
if p . ttl < = 0 : p . node . queue_free ( ) ; g . popups . remove_at ( i )
func move_player ( dt ) :
var move = Vector2 ( float ( Input . is_physical_key_pressed ( KEY_D ) or Input . is_physical_key_pressed ( KEY_RIGHT ) ) - float ( Input . is_physical_key_pressed ( KEY_A ) or Input . is_physical_key_pressed ( KEY_LEFT ) ) , float ( Input . is_physical_key_pressed ( KEY_S ) or Input . is_physical_key_pressed ( KEY_DOWN ) ) - float ( Input . is_physical_key_pressed ( KEY_W ) or Input . is_physical_key_pressed ( KEY_UP ) ) )
var right = g . camera . global_basis . x ; right . y = 0 ; right = right . normalized ( )
var down = g . camera . global_basis . z ; down . y = 0 ; down = down . normalized ( )
var direction = ( right * move . x + down * move . y ) . normalized ( )
var previous_position = g . player . position
2026-10-29 21:39:15 +02:00
var desired = g . player . position + direction * dt * ( 3.3 + g . speed_level * . 825 ) * ( 1.5 if arcade . frenzy > 0 else 1.0 )
2026-10-28 15:39:06 +02:00
desired . x = clampf ( desired . x , - 7.1 , walk_right ( ) ) ; desired . z = clampf ( desired . z , - 4.8 , 5.6 )
mesh_walking . move_actor ( g . player , desired - g . player . position )
if direction . length ( ) > . 01 :
g . face = direction ; g . avatar . rotation . y = lerp_angle ( g . avatar . rotation . y , atan2 ( direction . x , direction . z ) , minf ( 1 , dt * 12 ) )
g . avatar . set_walking ( g . player . position . distance_squared_to ( previous_position ) > . 000001 )
g . orbit . update ( dt )
func snapshot ( ) :
var devices = [ ]
for s in stations : devices . append ( { " kind " : s . selected , " x " : s . device . position . x , " z " : s . device . position . z , " turns " : s . turns } )
return { " expansions " : expansion_level , " unlock " : unlock , " helpers " : helpers . size ( ) , " haste " : helper_speed , " automation " : automation , " diligence " : helper_diligence , " pressure_time " : pressure_time , " penalty_clock " : penalty_clock , " stations " : devices }
func restore ( saved ) :
expansion_level = clampi ( int ( saved . get ( " expansions " , 0 ) ) , 0 , 3 ) ; g . architecture . growth . set_level ( expansion_level ) ; make_grid ( )
unlock = clampi ( int ( saved . get ( " unlock " , 0 ) ) , 0 , TITLES . size ( ) - 1 )
helper_speed = clampi ( int ( saved . get ( " haste " , 0 ) ) , 0 , 3 )
automation = saved . get ( " automation " , false ) == true
helper_diligence = clampi ( int ( saved . get ( " diligence " , 0 ) ) , 0 , 3 )
pressure_time = clampf ( float ( saved . get ( " pressure_time " , 0 ) ) , 0 , 300 )
penalty_clock = clampf ( float ( saved . get ( " penalty_clock " , 0 ) ) , 0 , Economy . PENALTY_INTERVAL )
var devices = saved . get ( " stations " , [ ] )
if devices is Array :
for record in devices :
if not record is Dictionary : continue
var kind = clampi ( int ( record . get ( " kind " , 0 ) ) , 0 , unlock )
var p = Vector3 ( float ( record . get ( " x " , 0 ) ) , 0 , float ( record . get ( " z " , 0 ) ) )
if not is_finite ( p . x ) or not is_finite ( p . z ) : continue
var turns = wrapi ( int ( record . get ( " turns " , 0 ) ) , 0 , 4 )
if valid_position ( p , kind , - 1 , turns ) : add_station ( kind , p , turns )
for i in range ( clampi ( int ( saved . get ( " helpers " , 0 ) ) , 0 , 3 ) ) : add_helper ( )
rebuild_nav ( ) ; refresh ( )
func resume_saved ( ) :
g . game_started = true ; g . paused = false ; g . hud . show ( ) ; g . menu . show_page ( " " )
if g . souls . is_empty ( ) : spawn ( )
message ( " Смена продолжается. Планировка и свита восстановлены. " )
refresh ( )
func make_level_bar ( ) :
var label = g . development . xp_label ; var bar = g . development . xp_bar
label . reparent ( g . hud ) ; label . position = Vector2 ( 24 , 850 ) ; label . size = Vector2 ( 1375 , 26 ) ; label . mouse_filter = Control . MOUSE_FILTER_IGNORE ; label . z_index = 8
label . add_theme_font_size_override ( " font_size " , 16 ) ; label . show ( )
bar . reparent ( g . hud ) ; bar . position = Vector2 ( 24 , 881 ) ; bar . size = Vector2 ( 1552 , 10 ) ; bar . custom_minimum_size = Vector2 ( 0 , 10 ) ; bar . mouse_filter = Control . MOUSE_FILTER_IGNORE ; bar . z_index = 8 ; bar . show ( )
pressure_label = g . label ( " " , 17 , Color ( " e8ae8b " ) ) ; g . hud . add_child ( pressure_label ) ; pressure_label . position = Vector2 ( 24 , 820 ) ; pressure_label . size = Vector2 ( 1360 , 25 ) ; pressure_label . mouse_filter = Control . MOUSE_FILTER_IGNORE ; pressure_label . z_index = 8
pressure_label . tooltip_text = " Первая душа уходит через 10 секунд ожидания. На орудии 10 секунд простоя вызывают сгорание. Каждый случай — штраф 50 золота. "
var track = StyleBoxFlat . new ( ) ; track . bg_color = Color ( " 111719 " ) ; track . border_color = Color ( " 8c9690 " ) ; track . set_border_width_all ( 1 ) ; track . set_corner_radius_all ( 3 )
var fill = StyleBoxFlat . new ( ) ; fill . bg_color = Color ( " 5b8986 " ) ; fill . border_color = Color ( " 9eb5aa " ) ; fill . set_border_width_all ( 1 ) ; fill . set_corner_radius_all ( 3 )
bar . add_theme_stylebox_override ( " background " , track ) ; bar . add_theme_stylebox_override ( " fill " , fill )
g . development . refresh ( )
func update_pressure ( _dt , count ) :
pressure_label . text = " ОЧЕРЕДЬ %d / 7 · До ухода первой души: %.0f с · Штраф 50 золота " % [ count , maxf ( 0 , 10 - losses . waiting_time ) ] if count > 0 else " "
func build_area ( ) : return Vector2 ( AREA . x * pow ( 1.2 , expansion_level ) , AREA . y )
func grid_area ( ) : return build_area ( ) . floor ( )
func walk_right ( ) : return 11.05 + g . architecture . growth . extra_width ( expansion_level )
func purchase_expansion ( ) :
if not build_mode or expansion_level > = 3 or g . coins < 500 : return false
var previous_extra = g . architecture . growth . extra_width ( expansion_level )
g . coins - = 500 ; expansion_level + = 1 ; g . architecture . growth . set_level ( expansion_level )
expansion_button . release_focus ( )
# Keep the current camera view while room-centering metadata changes.
g . orbit . pan . x - = ( g . architecture . growth . extra_width ( expansion_level ) - previous_extra ) * . 35
make_grid ( ) ; grid . show ( ) ; rebuild_nav ( )
refresh ( ) ; g . save_progress ( ) ; return true
func station_at_screen ( point ) :
var origin = g . camera . project_ray_origin ( point ) ; var ray = g . camera . project_ray_normal ( point )
var hit = g . get_world_3d ( ) . direct_space_state . intersect_ray ( PhysicsRayQueryParameters3D . create ( origin , origin + ray * 200 , 2 ) )
if not hit . is_empty ( ) :
for i in range ( stations . size ( ) ) :
if stations [ i ] . device . is_ancestor_of ( hit . collider ) : return i
var p = ground_point ( point )
for i in range ( stations . size ( ) - 1 , - 1 , - 1 ) :
if station_rect ( stations [ i ] ) . has_point ( Vector2 ( p . x , p . z ) ) : return i
return - 1
2026-10-29 13:16:22 +02:00
func free_floor ( position , radius = . 24 ) :
2026-10-28 15:39:06 +02:00
var point = Vector2 ( position . x , position . z )
2026-10-29 13:16:22 +02:00
if not mesh_walking . blocked ( point , radius ) : return position
var candidates = Array ( free_floor_points )
candidates . sort_custom ( func ( a , b ) : return a . distance_squared_to ( position ) < b . distance_squared_to ( position ) )
for p in candidates :
if not mesh_walking . blocked ( Vector2 ( p . x , p . z ) , radius ) : return p
return Vector3 ( - 5.3 , 0 , 0 )