From 6c0f108bc892d033cb0efb0e8288cc25bee51e12 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sat, 9 May 2026 12:58:24 -0700 Subject: [PATCH] =?UTF-8?q?fix(game):=20=F0=9F=90=9B=20lint=20fixes=20appl?= =?UTF-8?q?ied=20auto=5Fplay.gd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .project/objectives/objectives.json | 2 +- .project/objectives/p2-10k-gdlint-cleanup.md | 21 +++++++ src/game/engine/src/entities/auto_play.gd | 66 +++++++++++++++----- 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/.project/objectives/objectives.json b/.project/objectives/objectives.json index 5c080849..fb5a15ec 100644 --- a/.project/objectives/objectives.json +++ b/.project/objectives/objectives.json @@ -1,5 +1,5 @@ { - "generated_at": "2026-05-09T19:50:42Z", + "generated_at": "2026-05-09T19:57:18Z", "totals": { "done": 178, "in_progress": 1, diff --git a/.project/objectives/p2-10k-gdlint-cleanup.md b/.project/objectives/p2-10k-gdlint-cleanup.md index 7c0a3a84..50a4b985 100644 --- a/.project/objectives/p2-10k-gdlint-cleanup.md +++ b/.project/objectives/p2-10k-gdlint-cleanup.md @@ -86,3 +86,24 @@ removal reduces that category. - Full file-splitting of deferred files (tracked per-file in future objectives) - Refactoring auto_play.gd (blocked on p0-26 Rust port) + +## 2026-05-09 inline progress + +Reduced violation count from 56 → 41 (15 fixed) without specialist dispatch: + +- `auto_play.gd` 14 → 1 violation (only `max-file-lines` remains — needs file split, blocked on p0-26 Rust port). +- Mixed-tabs-and-spaces fix at lines 867-868 (tab+space→tab indent). +- Duplicated-load fix: `combat_resolver.gd` was loaded twice via `load()` in + attack-adjacent-enemy + attack-adjacent-city paths; promoted to a single + `const CombatResolverScript: GDScript = preload(...)` at the top. +- 9 max-line-length fixes across `auto_play.gd` (mechanical: split print + args across lines, hoist inline ternaries to multi-line if blocks, extract + long array literals into local vars). + +Remaining 41 violations break down: 22 max-line-length (mechanical), +10 max-file-lines (10 files exceed 500 lines — each needs a refactor), +6 class-definitions-order (audio_manager.gd / tech_web.gd / culture_web.gd), +1 no-elif-return (unit_renderer.gd:380), 1 load-constant-name, +1 function-variable-name. The mechanical max-line-length fixes can land in +another inline pass; the 10 max-file-lines blockers need per-file +extraction objectives or a project-wide max-file-lines lint relaxation. diff --git a/src/game/engine/src/entities/auto_play.gd b/src/game/engine/src/entities/auto_play.gd index 04052e68..b521c016 100644 --- a/src/game/engine/src/entities/auto_play.gd +++ b/src/game/engine/src/entities/auto_play.gd @@ -20,6 +20,9 @@ const ImprovementManagerScript = preload( const HappinessScript = preload("res://engine/src/modules/empire/happiness.gd") const ItemSystemScript = preload("res://engine/src/modules/management/item_system.gd") const SaveManagerScript = preload("res://engine/src/core/save_manager.gd") +const CombatResolverScript: GDScript = preload( + "res://engine/src/modules/combat/combat_resolver.gd" +) var _improvement_manager: RefCounted = null @@ -432,7 +435,9 @@ func _on_improvement_completed(tile: Vector2i, type: String) -> void: func _on_city_building_completed(city: Variant, building_id: String) -> void: var owner_idx: int = int(city.owner) if city != null and city.get("owner") != null else -1 - var city_name: String = str(city.city_name) if city != null and city.get("city_name") != null else "" + var city_name: String = "" + if city != null and city.get("city_name") != null: + city_name = str(city.city_name) _append_event({ "type": "city_building_completed", "player": owner_idx, @@ -481,7 +486,10 @@ func _on_victory(player_index: int, victory_type: String) -> void: # turn_stats line from _outcome, and without this override the line # persists as "in_progress" even though a winner was declared. _outcome = "victory" - print("AutoPlay: VICTORY! Player %d wins via %s on turn %d" % [player_index, victory_type, _turn_count]) + print( + "AutoPlay: VICTORY! Player %d wins via %s on turn %d" + % [player_index, victory_type, _turn_count] + ) _append_event({ "type": "victory", "player": player_index, @@ -647,7 +655,10 @@ func _process(_delta: float) -> void: var prev_turn: int = GameState.turn_number if prev_turn < _max_turns: GameState.turn_number = _max_turns - print("AutoPlay: invoking score-victory fallback (turn_number %d→%d, limit %d)" % [prev_turn, GameState.turn_number, _max_turns]) + print( + "AutoPlay: invoking score-victory fallback (turn_number %d→%d, limit %d)" + % [prev_turn, GameState.turn_number, _max_turns] + ) vm.check_all(GameState.get_game_map()) print("AutoPlay: fallback complete, victory=%s winner=%d" % [_victory, _victory_winner]) _screenshot("final_turn_%03d" % _turn_count) @@ -1036,7 +1047,9 @@ func _play_turn() -> void: var units_snapshot: Array = player.units.duplicate() - var city_pos: Vector2i = player.cities[0].position if not player.cities.is_empty() else Vector2i.ZERO + var city_pos: Vector2i = Vector2i.ZERO + if not player.cities.is_empty(): + city_pos = player.cities[0].position var intel: Dictionary = _get_enemy_intel() var enemy_mil: int = intel.get("military", 0) @@ -1141,7 +1154,10 @@ func _play_turn() -> void: for u: Variant in units_snapshot: if u.is_alive() and u.get("can_found_city") != true: unit_positions.append(str(u.position)) - print(" ATTACK: %d warriors at %s -> target %s" % [military_count, ", ".join(unit_positions), target]) + print( + " ATTACK: %d warriors at %s -> target %s" + % [military_count, ", ".join(unit_positions), target] + ) for u: Variant in units_snapshot: if not u.is_alive() or u.movement_remaining <= 0: continue @@ -1383,7 +1399,9 @@ func _score_site(pos: Vector2i, game_map: RefCounted) -> float: var y: Dictionary = tile.get_yields(-1) score += float(y.get("food", 0)) * 2.0 + float(y.get("production", 0)) * 1.5 for n: Vector2i in HexUtilsScript.get_neighbors(pos): - var norm: Vector2i = HexUtilsScript.normalize_position(n, game_map.width, game_map.height, game_map.wrap_mode) + var norm: Vector2i = HexUtilsScript.normalize_position( + n, game_map.width, game_map.height, game_map.wrap_mode + ) var nt: Resource = game_map.get_tile(norm) if nt == null: continue @@ -1440,7 +1458,10 @@ func _manage_production(city: Variant) -> void: if _turn_count <= 5 or _turn_count % 20 == 0: var q_size: int = city.production_queue.size() var item: String = city.production_queue[0].get("id", "") if q_size > 0 else "none" - print(" [PROD] %s: queue=%d item=%s progress=%d" % [city.city_name, q_size, item, city.production_progress]) + print( + " [PROD] %s: queue=%d item=%s progress=%d" + % [city.city_name, q_size, item, city.production_progress] + ) if city.production_queue.is_empty(): var gs: Node = get_node("/root/GameState") var player: RefCounted = gs.get_current_player() @@ -1463,7 +1484,12 @@ func _manage_production(city: Variant) -> void: # tier_peak/peak_unit_tier across 5-seed validation. Filler-only override # preserves the production chain while still firing wonders. var low_pri_filler: Array = ["warrior", "monument"] - if (built in low_pri_filler) and city_count >= 1 and Array(city.buildings).size() >= 3 and city.has_building("forge"): + if ( + (built in low_pri_filler) + and city_count >= 1 + and Array(city.buildings).size() >= 3 + and city.has_building("forge") + ): var existing: Array = Array(city.buildings) var has_wonder: bool = false for bld_id: String in existing: @@ -1586,7 +1612,10 @@ func _next_building(city: Variant, player: Variant, city_count: int, has_founder var tl: Resource = gm.get_tile(tp) if gm != null else null if tl == null: continue - if str(tl.get("improvement")) == "" and tl.biome_id in ["grassland", "plains", "forest", "boreal_forest", "jungle", "tundra"]: + var biome_ok: bool = tl.biome_id in [ + "grassland", "plains", "forest", "boreal_forest", "jungle", "tundra" + ] + if str(tl.get("improvement")) == "" and biome_ok: unimproved_food += 1 for tp2: Vector2i in city.get_worked_tiles(): var tl2: Resource = gm.get_tile(tp2) if gm != null else null @@ -1692,7 +1721,8 @@ func _next_building(city: Variant, player: Variant, city_count: int, has_founder continue var era_w: int = int(wb.get("era", 1)) # Score band: era 1 wonder ~ 5.5, era 5 wonder ~ 11.5, era 10 wonder ~ 19 - # (× 0.4-1.6 personality) — competitive with cavalry (5) → ironwarden (8) → forge_titan (12) → mithril_vanguard (18). + # (× 0.4-1.6 personality) — competitive with cavalry (5) → + # ironwarden (8) → forge_titan (12) → mithril_vanguard (18). scores[wid] = (4.0 + era_w * 1.5) * w_axis # Log top-3 each time production is selected — emergent strategy visibility @@ -2099,9 +2129,11 @@ func _try_attack_adjacent(unit: Variant, game_map: RefCounted) -> void: continue var dist: int = HexUtilsScript.hex_distance(unit.position, enemy.position) if dist <= 1: - print(" ATTACKING: %s at %s -> enemy at %s (dist=%d)" % [unit.type_id, unit.position, enemy.position, dist]) - var resolver_script: GDScript = load("res://engine/src/modules/combat/combat_resolver.gd") - var resolver: RefCounted = resolver_script.new() + print( + " ATTACKING: %s at %s -> enemy at %s (dist=%d)" + % [unit.type_id, unit.position, enemy.position, dist] + ) + var resolver: RefCounted = CombatResolverScript.new() resolver.resolve(unit, enemy, game_map, all_units) unit.movement_remaining = 0 return @@ -2113,9 +2145,11 @@ func _try_attack_adjacent(unit: Variant, game_map: RefCounted) -> void: for c: Variant in p.cities: var dist: int = HexUtilsScript.hex_distance(unit.position, c.position) if dist <= 1: - print(" ATTACKING CITY: %s at %s -> city at %s (dist=%d)" % [unit.type_id, unit.position, c.position, dist]) - var resolver_script: GDScript = load("res://engine/src/modules/combat/combat_resolver.gd") - var resolver: RefCounted = resolver_script.new() + print( + " ATTACKING CITY: %s at %s -> city at %s (dist=%d)" + % [unit.type_id, unit.position, c.position, dist] + ) + var resolver: RefCounted = CombatResolverScript.new() resolver.resolve(unit, c, game_map, all_units) unit.movement_remaining = 0 return