#204 the Beam Collimator widens the beam instead of adding range to one that already crosses the screen; beam width becomes a per-shot vessel stat. #205 the Energy Propulser gains three upgrades - dash recharge, dash reach, and boosted-cruise drain - which turns three constants into vessel stats. #206 three further doctrines carry the fleet from ten to twenty. #207 the prologue's World Ship gets a marker, through the scanner's own guidance arrow rather than a second one. #208 #210 #213 #214 four new synthesised sounds: the breach opening, cargo reaching the hold, a rock breaking, and a gas bomb blooming. #215 building health bars are larger, plated and framed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
111 lines
4 KiB
GDScript
111 lines
4 KiB
GDScript
extends Node2D
|
|
|
|
const BUILDING_DEFINITIONS = preload("res://buildings/BuildingDefinitions.gd")
|
|
|
|
@export var definition_id: String = "mothership"
|
|
@export var building_id: int = 0
|
|
@export var interact_radius: float = 150.0
|
|
|
|
var definition: Resource
|
|
var visual: Node2D
|
|
|
|
var building_type: String:
|
|
get: return definition_id
|
|
set(value): definition_id = value
|
|
|
|
|
|
# #99: drawn only once the structure has actually been hit. A full bar over
|
|
# every building would be permanent clutter saying nothing, and the fleet
|
|
# would be flying over a field of meters in peacetime.
|
|
# #215 made it bigger and brighter. It stays a DAMAGE-ONLY bar: the reason
|
|
# above still holds, and a field of full meters in peacetime is clutter, not
|
|
# visibility. What was actually hard to see was the bar when it was there -
|
|
# 74x7 of muted colour against a lit structure, at the zoom the game is
|
|
# usually played at.
|
|
const HEALTH_BAR_WIDTH: float = 104.0
|
|
const HEALTH_BAR_HEIGHT: float = 14.0
|
|
const HEALTH_BAR_OFFSET: float = -88.0
|
|
# The dark plate the bar sits on, drawn past its edges so the meter reads
|
|
# against the structure's own glow instead of competing with it.
|
|
const HEALTH_BAR_PAD: float = 3.0
|
|
const HEALTH_FULL_COLOR: Color = Color(0.5, 1.0, 0.55)
|
|
const HEALTH_HURT_COLOR: Color = Color(1.0, 0.28, 0.2)
|
|
const HEALTH_PLATE_COLOR: Color = Color(0.02, 0.02, 0.06, 0.92)
|
|
const HEALTH_FRAME_COLOR: Color = Color(0.85, 0.96, 1.0, 0.95)
|
|
const HEALTH_FRAME_WIDTH: float = 2.0
|
|
|
|
var _drawn_health: float = 1.0
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("buildings")
|
|
z_index = -1
|
|
definition = BUILDING_DEFINITIONS.get_definition(definition_id)
|
|
if definition == null or definition.visual_scene == null:
|
|
return
|
|
visual = definition.visual_scene.instantiate()
|
|
get_node("VisualHost").add_child(visual)
|
|
|
|
|
|
func health_fraction() -> float:
|
|
return GameState.building_health_fraction(building_id) if building_id != 0 else 1.0
|
|
|
|
|
|
func is_damaged() -> bool:
|
|
return health_fraction() < 0.999
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
# Redraw only when the number moves. A building that is not being shot at
|
|
# costs nothing, which is the same bargain Ship.gd's constant glow makes.
|
|
var health: float = health_fraction()
|
|
if is_equal_approx(health, _drawn_health):
|
|
return
|
|
_drawn_health = health
|
|
queue_redraw()
|
|
|
|
|
|
func _draw() -> void:
|
|
if not is_damaged():
|
|
return
|
|
# Above the structure rather than across it: the visual scenes all draw
|
|
# around their own origin, and a bar laid over one would be read as part
|
|
# of the building.
|
|
var health: float = health_fraction()
|
|
var left: float = -HEALTH_BAR_WIDTH * 0.5
|
|
var top: float = HEALTH_BAR_OFFSET
|
|
var fill_color: Color = HEALTH_HURT_COLOR.lerp(HEALTH_FULL_COLOR, health)
|
|
draw_rect(Rect2(left - HEALTH_BAR_PAD, top - HEALTH_BAR_PAD,
|
|
HEALTH_BAR_WIDTH + HEALTH_BAR_PAD * 2.0,
|
|
HEALTH_BAR_HEIGHT + HEALTH_BAR_PAD * 2.0), HEALTH_PLATE_COLOR)
|
|
# The empty part is not left blank: a dim wash of the fill colour shows
|
|
# how much has GONE, which is the thing being reported.
|
|
draw_rect(Rect2(left, top, HEALTH_BAR_WIDTH, HEALTH_BAR_HEIGHT),
|
|
Color(fill_color.r, fill_color.g, fill_color.b, 0.16))
|
|
draw_rect(Rect2(left, top, HEALTH_BAR_WIDTH * health, HEALTH_BAR_HEIGHT),
|
|
fill_color)
|
|
# A bright square cap on the fill's leading edge, so the level itself has
|
|
# an edge to catch rather than only the colour changing.
|
|
if health > 0.001:
|
|
draw_rect(Rect2(left + HEALTH_BAR_WIDTH * health - HEALTH_FRAME_WIDTH,
|
|
top, HEALTH_FRAME_WIDTH, HEALTH_BAR_HEIGHT), HEALTH_FRAME_COLOR)
|
|
draw_rect(Rect2(left, top, HEALTH_BAR_WIDTH, HEALTH_BAR_HEIGHT),
|
|
HEALTH_FRAME_COLOR, false, HEALTH_FRAME_WIDTH)
|
|
|
|
|
|
func available_actions() -> PackedStringArray:
|
|
if visual == null:
|
|
return PackedStringArray()
|
|
var provider: Node = visual.get_node_or_null("ActionProvider")
|
|
return provider.actions if provider != null else PackedStringArray()
|
|
|
|
|
|
func primary_action() -> String:
|
|
for action in available_actions():
|
|
if action != "transfer" and action != "hangar":
|
|
return action
|
|
return ""
|
|
|
|
|
|
func get_display_name() -> String:
|
|
return String(definition.display_name) if definition != null else definition_id.capitalize()
|