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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue