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>
This commit is contained in:
parent
0c595d775d
commit
b50597b757
16 changed files with 809 additions and 209 deletions
|
|
@ -1,16 +1,26 @@
|
|||
class_name GasBombController
|
||||
extends "res://controllers/AimedFleetAbilityController.gd"
|
||||
|
||||
const BOMB_COLOR := Color(0.96, 0.22, 0.72)
|
||||
const TARGET_COLOR := Color(0.78, 0.32, 1.0)
|
||||
const MAX_RANGE := 950.0
|
||||
const AOE_RADIUS := 180.0
|
||||
const DRAG_RADIUS := 260.0
|
||||
const PROJECTILE_SPEED := 720.0
|
||||
const DAMAGE := 3
|
||||
const COOLDOWN := 5.0
|
||||
const GAS_PER_SHOT: int = 5
|
||||
# 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
|
||||
|
|
@ -22,7 +32,8 @@ var explosion_time: float:
|
|||
get:
|
||||
var longest: float = 0.0
|
||||
for explosion in explosions:
|
||||
longest = maxf(longest, float(explosion.time))
|
||||
if is_instance_valid(explosion):
|
||||
longest = maxf(longest, float(explosion.explosion_time))
|
||||
return longest
|
||||
|
||||
|
||||
|
|
@ -48,78 +59,46 @@ func _consume_shot(component: Node) -> bool:
|
|||
|
||||
|
||||
func _perform_shot(ship: Node2D, _component: Node) -> void:
|
||||
projectiles.append({
|
||||
"position": ship.global_position,
|
||||
"target": aim_target,
|
||||
"trail": PackedVector2Array([ship.global_position]),
|
||||
})
|
||||
# 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:
|
||||
for i in range(projectiles.size() - 1, -1, -1):
|
||||
var projectile: Dictionary = projectiles[i]
|
||||
var distance: float = (projectile.position as Vector2).distance_to(projectile.target)
|
||||
if distance <= PROJECTILE_SPEED * delta:
|
||||
projectile.position = projectile.target
|
||||
_explode(projectile.target)
|
||||
projectiles.remove_at(i)
|
||||
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:
|
||||
projectile.position = (projectile.position as Vector2).move_toward(
|
||||
projectile.target, PROJECTILE_SPEED * delta)
|
||||
var trail: PackedVector2Array = projectile.trail
|
||||
trail.append(projectile.position)
|
||||
while trail.size() > 12:
|
||||
trail.remove_at(0)
|
||||
projectile.trail = trail
|
||||
for i in range(explosions.size() - 1, -1, -1):
|
||||
var explosion: Dictionary = explosions[i]
|
||||
explosion.time = maxf(float(explosion.time) - delta, 0.0)
|
||||
if float(explosion.time) <= 0.0:
|
||||
explosions.remove_at(i)
|
||||
|
||||
|
||||
func _explode(at: Vector2) -> void:
|
||||
explosions.append({"position": at, "time": 0.8})
|
||||
last_hit_count = 0
|
||||
# Asteroids too - a blast that clears everything around it but leaves the
|
||||
# rocks untouched would need explaining, and they take damage the same way.
|
||||
for enemy in get_tree().get_nodes_in_group("enemies") \
|
||||
+ get_tree().get_nodes_in_group("asteroids"):
|
||||
if is_instance_valid(enemy) and enemy is Node2D \
|
||||
and enemy.global_position.distance_to(at) <= AOE_RADIUS:
|
||||
enemy.take_damage(DAMAGE)
|
||||
last_hit_count += 1
|
||||
blooming.append(effect)
|
||||
projectiles = flying
|
||||
explosions = blooming
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if aiming:
|
||||
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)
|
||||
for projectile in projectiles:
|
||||
var trail: PackedVector2Array = projectile.trail
|
||||
if trail.size() >= 2:
|
||||
for i in range(1, trail.size()):
|
||||
var alpha: float = float(i) / trail.size()
|
||||
draw_line(trail[i - 1], trail[i], Color(BOMB_COLOR, alpha * 0.65),
|
||||
4.0 + alpha * 4.0, true)
|
||||
draw_circle(projectile.position, 12.0, Color(BOMB_COLOR, 0.35))
|
||||
NeonDraw.draw_glowing_circle(self, projectile.position, 7.0, BOMB_COLOR, 1.0)
|
||||
for explosion in explosions:
|
||||
var progress: float = 1.0 - float(explosion.time) / 0.8
|
||||
var radius: float = lerpf(24.0, AOE_RADIUS, minf(progress * 1.5, 1.0))
|
||||
draw_circle(explosion.position, radius, Color(BOMB_COLOR, (1.0 - progress) * 0.16))
|
||||
_draw_ring(explosion.position, radius, BOMB_COLOR, 1.0 - progress)
|
||||
for i in range(7):
|
||||
var angle: float = TAU * float(i) / 7.0 + progress
|
||||
var cloud_at: Vector2 = explosion.position \
|
||||
+ Vector2(cos(angle), sin(angle)) * radius * 0.55
|
||||
draw_circle(cloud_at, 18.0 + 14.0 * progress,
|
||||
Color(BOMB_COLOR, (1.0 - progress) * 0.22))
|
||||
# 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:
|
||||
|
|
|
|||
|
|
@ -1,39 +1,26 @@
|
|||
class_name LaserController
|
||||
extends "res://controllers/AimedFleetAbilityController.gd"
|
||||
|
||||
const BEAM_COLOR := Color(0.3, 0.9, 1.0)
|
||||
const TARGET_COLOR := Color(0.6, 0.95, 1.0)
|
||||
const BEAM_HALF_WIDTH := 38.0
|
||||
# The DRAWN beam is scaled from the hit width rather than tuned separately.
|
||||
# The two were independent numbers and had drifted apart: the beam struck
|
||||
# anything within 22 units of the line while its outer glow spanned about 11,
|
||||
# so it killed things it visibly missed. NeonDraw's widest layer is 18px at
|
||||
# scale 1, so this makes the glow span exactly what the beam hits.
|
||||
const BEAM_WIDTH_SCALE := BEAM_HALF_WIDTH * 2.0 / 18.0
|
||||
# #90: the beam was one flat line that blinked on at full length and faded.
|
||||
# It now IGNITES - it runs out of the ship over the first slice of its life,
|
||||
# holds white-hot, and falls away - which is the sabre look the report asked
|
||||
# for and also the only part of the shot the eye can follow.
|
||||
# The player's end of the laser: the button, the aim, the fleet's magazine.
|
||||
# The SHOT itself is a LaserBeamEffect in the world (see that file) - it was
|
||||
# lifted out of here so a garrisoned laser vessel could fire the same beam
|
||||
# from a different trigger without this controller being involved at all.
|
||||
#
|
||||
# Long enough for the extension to read as movement rather than as a
|
||||
# stutter, still short enough to be gone before the 4s cooldown is up.
|
||||
const FLASH_DURATION := 0.34
|
||||
# The fraction of that life spent extending. The rest holds and decays.
|
||||
const IGNITE_FRACTION := 0.3
|
||||
# The white-hot rod down the middle of the coloured glow. Drawn INSIDE the
|
||||
# beam's own width, never wider: the drawn beam is deliberately the same
|
||||
# span as the hit test (see BEAM_WIDTH_SCALE above), and a halo painted past
|
||||
# that would put the "it visibly missed" complaint back the other way round.
|
||||
const CORE_SCALE := 0.42
|
||||
const CORE_COLOR := Color(0.85, 0.99, 1.0)
|
||||
# The leading cap, and the flare left at the emitter. Both are radii, both
|
||||
# stay within the beam's half width so nothing suggests a wider reach.
|
||||
const TIP_RADIUS := BEAM_HALF_WIDTH * 0.55
|
||||
const MUZZLE_RADIUS := BEAM_HALF_WIDTH * 0.8
|
||||
const ENERGY_PER_SHOT: int = 8
|
||||
# By path, not by class name - see the note at the top of MuzzleSparkVFX.
|
||||
const MUZZLE_SPARK = preload("res://vfx/MuzzleSparkVFX.gd")
|
||||
# What is left here is everything that is genuinely about the player firing:
|
||||
# where they aimed, what it costs the fleet hold, and the guide line drawn
|
||||
# while they aim it.
|
||||
|
||||
const BEAM_EFFECT = preload("res://vfx/LaserBeamEffect.gd")
|
||||
const BEAM_COLOR := BEAM_EFFECT.BEAM_COLOR
|
||||
const TARGET_COLOR := Color(0.6, 0.95, 1.0)
|
||||
const BEAM_HALF_WIDTH := BEAM_EFFECT.BEAM_HALF_WIDTH
|
||||
const FLASH_DURATION := BEAM_EFFECT.FLASH_DURATION
|
||||
const ENERGY_PER_SHOT: int = VesselLaserComponent.ENERGY_PER_SHOT
|
||||
|
||||
# The beams this controller has fired and that are still alive. Kept so the
|
||||
# fleet's own shots can be reasoned about - "is anything still on screen" for
|
||||
# the redraw, and the tests' view of what a shot did - without this becoming
|
||||
# the owner of them again.
|
||||
var beams: Array = []
|
||||
var last_hit_count: int = 0
|
||||
|
||||
|
|
@ -72,101 +59,37 @@ func _consume_shot(component: Node) -> bool:
|
|||
|
||||
|
||||
func _perform_shot(ship: Node2D, component: Node) -> void:
|
||||
# The cooldown was already spent by _consume_shot() above, so this fires
|
||||
# the effect directly rather than going through fire_ability() and
|
||||
# spending it twice.
|
||||
var direction: Vector2 = aim_target - _aim_origin()
|
||||
direction = direction.normalized() if direction.length() > 0.001 else Vector2.UP
|
||||
var beam_to: Vector2 = ship.global_position + direction * component.beam_range
|
||||
_strike(ship.global_position, beam_to, direction, int(component.damage))
|
||||
# #90: something happens at the hull, not just out in space. The ordinary
|
||||
# gun already does this (#87); the laser fired in complete silence at its
|
||||
# own end, which is most of why a shot read as a line appearing rather
|
||||
# than as a vessel firing.
|
||||
MUZZLE_SPARK.spawn(get_tree().root, ship.global_position, direction, BEAM_COLOR)
|
||||
var effect: Node2D = BEAM_EFFECT.fire(get_tree().root, ship.global_position,
|
||||
direction, component.beam_range, int(component.damage))
|
||||
beams.append(effect)
|
||||
last_hit_count = int(effect.hit_count)
|
||||
|
||||
|
||||
func _next_ready_laser_ship() -> Node2D:
|
||||
return _next_ready_ship()
|
||||
|
||||
|
||||
func _advance_effects(delta: float) -> void:
|
||||
for i in range(beams.size() - 1, -1, -1):
|
||||
var beam: Dictionary = beams[i]
|
||||
beam.time = maxf(float(beam.time) - delta, 0.0)
|
||||
if float(beam.time) <= 0.0:
|
||||
beams.remove_at(i)
|
||||
func _advance_effects(_delta: float) -> void:
|
||||
# The effects animate and free themselves; this only forgets the ones that
|
||||
# have gone.
|
||||
beams = beams.filter(func(beam): return is_instance_valid(beam))
|
||||
|
||||
|
||||
func _strike(from: Vector2, to: Vector2, direction: Vector2, damage: int) -> void:
|
||||
# The damage below is dealt HERE, in full, along the whole beam, at the
|
||||
# instant of the shot. The extension in _draw is the picture of that, not
|
||||
# a travelling projectile - a beam that had to arrive would be a change
|
||||
# to how the weapon plays, which #90 did not ask for.
|
||||
beams.append({
|
||||
"from": from, "to": to, "time": FLASH_DURATION,
|
||||
# Per beam, so two lasers firing together do not flicker in lockstep.
|
||||
"phase": randf() * TAU,
|
||||
})
|
||||
last_hit_count = 0
|
||||
var range_along: float = from.distance_to(to)
|
||||
# Asteroids share the enemies' take_damage() contract, so the beam sweeps
|
||||
# both groups in one pass. Shooting a path clear through a field is a
|
||||
# perfectly good use of a laser, and the ore it leaves behind is the point.
|
||||
for enemy in get_tree().get_nodes_in_group("enemies") \
|
||||
+ get_tree().get_nodes_in_group("asteroids"):
|
||||
if not is_instance_valid(enemy) or not (enemy is Node2D):
|
||||
continue
|
||||
var to_enemy: Vector2 = enemy.global_position - from
|
||||
var along: float = to_enemy.dot(direction)
|
||||
if along < 0.0 or along > range_along:
|
||||
continue
|
||||
var perpendicular: float = (to_enemy - direction * along).length()
|
||||
if perpendicular <= BEAM_HALF_WIDTH:
|
||||
enemy.take_damage(damage)
|
||||
last_hit_count += 1
|
||||
func beam_extension(beam: Node2D) -> float:
|
||||
return beam.extension()
|
||||
|
||||
|
||||
# How far along its length a beam is currently drawn. Cubic ease-out, so it
|
||||
# leaves the ship fast and settles into full reach rather than crawling.
|
||||
# Public because it is the whole of #90's "it comes out of the ship" and is
|
||||
# worth asserting on directly.
|
||||
func beam_extension(beam: Dictionary) -> float:
|
||||
var progress: float = 1.0 - float(beam.time) / FLASH_DURATION
|
||||
var out: float = clampf(progress / IGNITE_FRACTION, 0.0, 1.0)
|
||||
return 1.0 - pow(1.0 - out, 3.0)
|
||||
|
||||
|
||||
func beam_tip(beam: Dictionary) -> Vector2:
|
||||
return Vector2(beam.from).lerp(Vector2(beam.to), beam_extension(beam))
|
||||
func beam_tip(beam: Node2D) -> Vector2:
|
||||
return beam.tip()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
# Only the aim guide. Each beam draws itself, in its own node.
|
||||
if aiming:
|
||||
NeonDraw.draw_glowing_line(self, _aim_origin(), aim_target,
|
||||
TARGET_COLOR, 0.7, 0.6)
|
||||
for beam in beams:
|
||||
var progress: float = 1.0 - float(beam.time) / FLASH_DURATION
|
||||
# Full brightness while it extends, then away. Squared so it holds
|
||||
# its light and drops at the end, instead of dimming from the first
|
||||
# frame the way a plain linear fade did.
|
||||
var decay: float = clampf((progress - IGNITE_FRACTION) / (1.0 - IGNITE_FRACTION), 0.0, 1.0)
|
||||
var alpha: float = 1.0 - decay * decay
|
||||
# A live blade hums. Small enough to be texture rather than a blink.
|
||||
var flicker: float = 1.0 + 0.09 * sin(float(beam.time) * 70.0 + float(beam.phase))
|
||||
var tip: Vector2 = beam_tip(beam)
|
||||
var from: Vector2 = beam.from
|
||||
|
||||
NeonDraw.draw_glowing_line(self, from, tip, BEAM_COLOR, alpha,
|
||||
BEAM_WIDTH_SCALE * flicker * (1.0 - decay * 0.45))
|
||||
# The white-hot rod, over the same span at a fraction of the width.
|
||||
# This is where the extra light comes from: brighter through the
|
||||
# middle, not broader across.
|
||||
NeonDraw.draw_glowing_line(self, from, tip, CORE_COLOR, alpha,
|
||||
BEAM_WIDTH_SCALE * CORE_SCALE * flicker)
|
||||
# The leading cap, brightest while the blade is still running out.
|
||||
var cap: float = TIP_RADIUS * (0.7 + 0.3 * (1.0 - decay)) * flicker
|
||||
NeonDraw.draw_glowing_circle(self, tip, cap, CORE_COLOR, alpha)
|
||||
# And the flare left at the emitter, which fades faster than the
|
||||
# beam so the hull does not keep glowing after the shot is over.
|
||||
var muzzle: float = MUZZLE_RADIUS * (1.0 - progress)
|
||||
if muzzle > 1.0:
|
||||
NeonDraw.draw_glowing_circle(self, from, muzzle, CORE_COLOR,
|
||||
alpha * (1.0 - progress))
|
||||
|
|
|
|||
Loading…
Reference in a new issue