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)