spaceship/controllers/GasBombController.gd
Loïc Wisniewski b50597b757 Garrison laser vessels and gas bombers, on a shared ability seam
#105 shipped with interceptors as the only garrisonable vessel, and the
reason was a design fault rather than a decision: firing the laser and the
gas bomb lived in the player's fleet controllers, so a stationed laser would
have held its position and never shot.

The shot is now a thing in the world rather than something a controller
draws. LaserBeamEffect and GasBombEffect are self-contained, self-animating
and self-freeing, added to the tree root - the same shape EnemyBigLaserBeam
and ArtilleryShell already had on the enemy side - and they outlive the
vessel that fired them.

Above them sits one seam, on VesselCooldownFillComponent: ability_range(),
ability_ammo_resource(), ability_ammo_cost() and fire_ability(). A beam and a
bomb are now the same shape of thing to whoever pulls the trigger, so the
garrison AI never names an ability - the test asserts that literally, by
reading the AI's own source. A third armed vessel needs to implement the
seam and nothing else.

Ammunition is the CALLER's business, deliberately: the fleet spends from its
hold, a garrison from its outpost's store, and neither concern belongs in
the component. A garrison with an empty magazine holds fire rather than
falling back on the fleet's hold.

Outpost storage: 50 gas per stationed bomber and 50 energy per stationed
laser, off the VESSEL definitions, so an outpost never learns which vessel
needs what. It is a capacity, not a stock - hub transporters fill it exactly
as they fill a gas burner's buffer, because building_logistics_deficit now
takes the larger of the definition's static buffer and the garrison's
magazine. Every other resource is capped at zero: an outpost is not a depot,
and ore parked at one has nothing to do there and no transporter coming for
it.

Also restores two properties the Godot editor dropped from
GasBurnerBuildingDefinition.tres when it re-saved the file:
collected_outputs and capabilities. Without the first, nothing ever collects
the burner's energy - test_gas_burner caught it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 19:23:35 +02:00

107 lines
3.8 KiB
GDScript

class_name GasBombController
extends "res://controllers/AimedFleetAbilityController.gd"
# The player's end of the gas bomb: the button, the aim, the fleet's
# magazine. The SHOT itself is a GasBombEffect in the world (see that file),
# lifted out of here for the same reason the beam was lifted out of
# LaserController - a garrisoned bomber fires the same bomb from a different
# trigger, and none of this controller is involved in that.
const BOMB_EFFECT = preload("res://vfx/GasBombEffect.gd")
const BOMB_COLOR := BOMB_EFFECT.BOMB_COLOR
const TARGET_COLOR := Color(0.78, 0.32, 1.0)
const MAX_RANGE := VesselGasBomberComponent.MAX_RANGE
const AOE_RADIUS := BOMB_EFFECT.AOE_RADIUS
const DRAG_RADIUS := 260.0
const DAMAGE := VesselGasBomberComponent.BLAST_DAMAGE
const COOLDOWN := VesselGasBomberComponent.SHOT_COOLDOWN
const GAS_PER_SHOT: int = VesselGasBomberComponent.GAS_PER_SHOT
# The bombs this controller has thrown that are still alive - in flight or
# still blooming. Split into the two lists the rest of the game already asks
# about rather than one, so "is a bomb still travelling" stays a question
# with a cheap answer.
var projectiles: Array = []
var explosions: Array = []
var last_hit_count: int = 0
var projectile_active: bool:
get: return not projectiles.is_empty()
var explosion_time: float:
get:
var longest: float = 0.0
for explosion in explosions:
if is_instance_valid(explosion):
longest = maxf(longest, float(explosion.explosion_time))
return longest
func _button_path() -> NodePath: return "../UI/GasBombButton"
func _status_path() -> NodePath: return "../UI/GasBombStatus"
func _component_id() -> String: return "gas_bomber"
func _ammo_resource() -> String: return GameState.RESOURCE_GAS
func _ammo_cost() -> int: return GAS_PER_SHOT
func _aim_padding() -> float: return AOE_RADIUS
func _aim_max_range() -> float: return MAX_RANGE
func _has_effect_visuals() -> bool: return not projectiles.is_empty() or not explosions.is_empty()
func _calculate_aim_target(drag: Vector2, origin: Vector2) -> Vector2:
if drag.length() < 0.001:
return origin
var distance: float = minf(drag.length() / DRAG_RADIUS, 1.0) * MAX_RANGE
return origin + drag.normalized() * distance
func _consume_shot(component: Node) -> bool:
return component.consume_shot(COOLDOWN)
func _perform_shot(ship: Node2D, _component: Node) -> void:
# The cooldown was already spent by _consume_shot() above, so this
# launches the effect directly rather than going through fire_ability()
# and spending it twice.
var effect: Node2D = BOMB_EFFECT.launch(get_tree().root, ship.global_position,
aim_target, DAMAGE)
effect.struck.connect(_on_bomb_struck)
projectiles.append(effect)
func _on_bomb_struck(hit_count: int) -> void:
last_hit_count = hit_count
func _next_ready_bomber() -> Node2D:
return _next_ready_ship()
func _advance_effects(_delta: float) -> void:
# The effects fly, explode and free themselves. This only re-sorts them
# into "still travelling" and "still blooming", and forgets the gone.
var flying: Array = []
var blooming: Array = []
for effect in projectiles + explosions:
if not is_instance_valid(effect):
continue
if effect.in_flight():
flying.append(effect)
else:
blooming.append(effect)
projectiles = flying
explosions = blooming
func _draw() -> void:
# Only the aim guide. Each bomb draws itself, in its own node.
if not aiming:
return
NeonDraw.draw_glowing_line(self, _aim_origin(), aim_target, TARGET_COLOR, 0.7, 0.8)
_draw_ring(aim_target, AOE_RADIUS, TARGET_COLOR, 0.8)
_draw_ring(aim_target, 18.0, BOMB_COLOR, 1.0)
func _draw_ring(center: Vector2, radius: float, color: Color, alpha: float) -> void:
draw_arc(center, radius, 0.0, TAU, 64, Color(color, 0.16 * alpha), 16.0, true)
draw_arc(center, radius, 0.0, TAU, 64, Color(color, 0.5 * alpha), 6.0, true)
draw_arc(center, radius, 0.0, TAU, 64, Color(1.0, 0.86, 0.96, 0.9 * alpha), 2.0, true)