diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index d5e4687..c943c7b 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -59,7 +59,7 @@ Joined officers gate whether `requires_joined` player deployments are loaded at Inventory and campaign flags are copied from `CampaignState` into `BattleState` when a scenario starts. The pre-battle Chapters overview reads `CampaignState` chapter progress and can load completed or current battles without mutating the save. Briefings preview first-clear rewards, can expose `briefing.camp_conversations` through a selectable Talk menu with `briefing.camp_dialogue` as a fallback, can filter those conversations by saved campaign flags, can claim saved one-time camp conversation supply effects through `CampaignState` and refresh the loaded battle inventory copy, and show completed replay rewards as already claimed. The pre-battle Save menu can write the current campaign state to `user://campaign_manual_save.json`, and loading that checkpoint restores it into `user://campaign_save.json` before re-entering the same pending-choice, completion, or current-briefing branch as startup. Pre-battle shop stock comes from the loaded scenario's `shop.items` list plus matching `shop.conditional_items` blocks, with optional finite limits from item entries or `stock` maps, and `shop.merchant` lines are presentation-only camp flavor. Shop purchases and 50% sell-back are campaign transactions: they update saved gold, unequipped inventory, and finite-stock purchase counts immediately, write the save file, and refresh the already-loaded battle inventory before the player begins the battle. Camp conversation supply claims are also campaign transactions: they save a per-scenario conversation claim ledger and inventory immediately, then refresh the already-loaded battle inventory. Pre-battle Armory equipment changes use the same equipment rules as battle HUD equipment changes, then immediately save merged roster equipment/stat snapshots and inventory stock. Pre-battle Roster uses scenario `roster.max_units`, `roster.required_officers`, and `roster.required_units` to mark optional player deployments as sortie or reserve; reserve units remain in the candidate list but are excluded from board occupancy, drawing, selection, AI targeting, and living-unit victory checks. Non-controllable player units can act as protected escort targets: enemies can attack them and conditions can reference them, but they are skipped by player selection, Armory, Formation, counterattacks, and campaign roster progression snapshots when `persist_progression` is false. Scenario `ai_target_priority` nudges enemy movement and damage-skill scoring toward important targets such as envoys without overriding defeat bonuses or range checks, and `set_ai_target_priority` events can retune that battle-only pressure after an ambush, gate closure, or escort exposure. Pre-battle Formation uses the loaded scenario's `formation.cells` and only mutates current battle unit positions before battle-begin events fire. Destination victory cells from `unit_reaches_tile` conditions are exposed to the scene for objective overlays and tile info, and can be expressed as one `pos` or a multi-cell `cells` list; gated victory conditions can also expose the `unit_reaches_tile` event that unlocks them as the next visible objective marker. Movement-triggered `unit_reaches_tile` events receive the unit that just moved, so ambushes and pickup events fire on entry rather than from units already standing on a marker; `unit_defeated` events receive the fallen unit before final victory/defeat checks, allowing named-officer reactions and last-moment reinforcements. Briefing data can append matching `briefing.conditional_lines`, and scenario events can use `when.campaign_flags` to branch dialogue, objective changes, item and gold pickups, AI target-priority shifts, and reinforcements from saved campaign choices or `when.after_event` to wait for earlier scenario beats. Consumable use can restore HP or MP, cure matching poison/seal/snare/disarm statuses, or cleanse negative stat debuffs, and in-battle item use, event pickup grants, event gold pickups, plus equipment swaps mutate only the battle copy until victory; defeats and restarts do not spend saved items, keep picked-up items or gold, or preserve in-battle gear changes. Post-battle choices write campaign `flags` only after the result-panel button is pressed; if the player reloads after rewards are saved but before selecting, the pending scenario id restores the victory choice panel without replaying rewards. The next battle button stays locked until the campaign choice save succeeds. Equipment rewards share the same `item_id -> count` inventory stock, cover weapon, armor, and accessory slots, can be equipped from the side HUD before the selected unit moves or acts, and do not appear in the consumable action menu. Named equipment currently uses the same stock model with a presentation-only rarity tag rather than unique item instances. Already completed scenarios can be replayed without granting duplicate rewards, choices, replay inventory consumption, event gold pickups, save writes, current-scenario advancement, finite-stock purchases, or camp conversation supply claims; pre-battle Shop, Armory, Roster, Formation, and Save are disabled on completed-scenario replays to avoid side effects. -The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing, objective text, condition-progress text, and defeat-risk text, active battles use battle BGM and show an objective/progress/risk panel fed by `BattleState`, objective-update signals show a short HUD notice and refresh the objective panel immediately, dialogue lines can show optional cached portrait textures or speaker-initial fallback panels in an expanded visual-novel-style panel, can place the portrait on the left or right side of that panel, and expose progress plus previous-line controls while a sequence is open, the side HUD reuses cached officer portrait textures or class sprites for the selected unit or hovered unit and formats focus text with role, movement type, current terrain move cost, defense/avoid bonuses, core stats, status effects, and gear, board maps can draw a scenario background texture under translucent terrain overlays, connected road segments, terrain detail patterns, and shoreline/castle/forest/hill edge blends, board units render class sprite tokens or generic-enemy transparent class cutouts, team rings, class badges, generic-enemy marks, officer pins, low-HP warning rings, HP bar color states, and active support/debuff/poison/seal/snare/disarm status pips from battle state fields, item buttons can show optional cached item icons, hover previews are rendered as target badges from existing `BattleState` forecast APIs, equipment option menus show stat/range/effect deltas, result and inventory summaries show named equipment with compact rarity tags, selected area tactics highlight their affected cells, the Threat toggle overlays enemy physical and hostile tactic reach while tile info names threat sources, estimates physical damage, and summarizes hostile tactic damage or status effects against occupied cells, log/result hooks trigger placeholder SFX, support, debuff, poison, seal, snare, disarm, objective updates, AI target-focus changes, and item/gold pickup effects use distinct feedback, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, `BattleState.unit_action_motion_requested` keeps its rules-facing signal shape while the scene maps attacker class ids to infantry, archer, cavalry, command, and heavy attack presentation profiles, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. +The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing, objective text, condition-progress text, and defeat-risk text, active battles use battle BGM and show an objective/progress/risk panel fed by `BattleState`, objective-update signals show a short HUD notice and refresh the objective panel immediately, dialogue lines can show optional cached portrait textures or speaker-initial fallback panels in an expanded visual-novel-style panel, can place the portrait on the left or right side of that panel, and expose progress plus previous-line controls while a sequence is open, the side HUD reuses cached officer portrait textures or class sprites for the selected unit or hovered unit and formats focus text with role, movement type, current terrain move cost, defense/avoid bonuses, core stats, status effects, guard-zone AI hints, and gear, board maps can draw a scenario background texture under translucent terrain overlays, connected road segments, terrain detail patterns, shoreline/castle/forest/hill edge blends, and compact recovery markers for healing terrain, board units render class sprite tokens or generic-enemy transparent class cutouts, team rings, class badges, generic-enemy marks, officer pins, low-HP warning rings, HP bar color states, and active support/debuff/poison/seal/snare/disarm status pips from battle state fields, item buttons can show optional cached item icons, hover previews are rendered as target badges from existing `BattleState` forecast APIs, equipment option menus show stat/range/effect deltas, result and inventory summaries show named equipment with compact rarity tags, selected area tactics highlight their affected cells, the Threat toggle overlays enemy physical and hostile tactic reach while tile info names threat sources, estimates physical damage, and summarizes hostile tactic damage or status effects against occupied cells, log/result hooks trigger placeholder SFX, support, debuff, poison, seal, snare, disarm, objective updates, AI target-focus changes, and item/gold pickup effects use distinct feedback, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, `BattleState.unit_action_motion_requested` keeps its rules-facing signal shape while the scene maps attacker class ids to infantry, archer, cavalry, command, and heavy attack presentation profiles, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. Large tactical maps are presented through a fixed visible map window rather than by shrinking the whole board. `BattleScene` keeps a clamped `board_scroll_offset`, scrolls the board while the mouse is near or slightly outside the visible map edge, ignores board clicks outside the visible map window, and draws a small minimap plate inside the map view; clicking or dragging the minimap recenters the tactical viewport, while action feedback can focus the board on off-screen cells before motion or combat effects play. diff --git a/scripts/scenes/battle_scene.gd b/scripts/scenes/battle_scene.gd index 2d118c7..5df325f 100644 --- a/scripts/scenes/battle_scene.gd +++ b/scripts/scenes/battle_scene.gd @@ -502,6 +502,7 @@ func _unhandled_input(event: InputEvent) -> void: func _draw() -> void: _draw_map() _draw_overlays() + _draw_recovery_terrain_markers(_visible_cell_bounds()) _draw_units() _draw_objective_foreground_markers() _draw_target_selection_markers() @@ -2755,6 +2756,37 @@ func _draw_silk_map_patina(board_rect: Rect2, has_background: bool) -> void: draw_circle(board_rect.end - Vector2(24, 22), 30.0, corner_stain) +func _draw_recovery_terrain_markers(bounds: Rect2i) -> void: + var font := _draw_ui_font(true) + for y in range(bounds.position.y, bounds.position.y + bounds.size.y): + for x in range(bounds.position.x, bounds.position.x + bounds.size.x): + var cell := Vector2i(x, y) + var marker_text := _recovery_marker_text(cell) + if marker_text.is_empty(): + continue + var marker_rect := _recovery_marker_rect(cell) + draw_rect(marker_rect, Color(0.035, 0.022, 0.012, 0.74)) + draw_rect(marker_rect, Color(UI_OLD_BRONZE.r, UI_OLD_BRONZE.g, UI_OLD_BRONZE.b, 0.88), false, 1.4) + var plus_center := marker_rect.position + Vector2(8.0, marker_rect.size.y * 0.5) + var plus_color := Color(0.54, 0.86, 0.48, 0.92) + draw_line(plus_center + Vector2(-3.0, 0.0), plus_center + Vector2(3.0, 0.0), plus_color, 1.6) + draw_line(plus_center + Vector2(0.0, -3.0), plus_center + Vector2(0.0, 3.0), plus_color, 1.6) + _draw_ink_text(font, marker_rect.position + Vector2(9.0, 13.0), marker_text, HORIZONTAL_ALIGNMENT_CENTER, marker_rect.size.x - 9.0, 11, Color(0.78, 0.98, 0.62, 0.96)) + + +func _recovery_marker_text(cell: Vector2i) -> String: + var heal := state.get_terrain_heal(cell) + if heal <= 0: + return "" + return "+%d" % heal + + +func _recovery_marker_rect(cell: Vector2i) -> Rect2: + var cell_rect := _rect_for_cell(cell) + var size := Vector2(34.0, 16.0) + return Rect2(cell_rect.position + Vector2(TILE_SIZE - size.x - 4.0, 4.0), size) + + func _draw_silk_map_frame(board_rect: Rect2) -> void: var padding := MAP_SCROLL_FRAME_PADDING var top_rod := Rect2(board_rect.position + Vector2(-padding, -padding), Vector2(board_rect.size.x + padding * 2.0, 7.0)) @@ -5175,6 +5207,9 @@ func _format_unit_focus_text(unit: Dictionary, prefix: String) -> String: int(unit.get("range", 1)) ]) lines.append(_unit_action_status_text(unit)) + var ai_text := _unit_ai_behavior_text(unit) + if not ai_text.is_empty(): + lines.append(ai_text) var terrain_text := _unit_current_terrain_text(unit) if not terrain_text.is_empty(): lines.append(terrain_text) @@ -5305,6 +5340,18 @@ func _unit_class_display_name(unit: Dictionary) -> String: return str(unit.get("class", "부대")) +func _unit_ai_behavior_text(unit: Dictionary) -> String: + if str(unit.get("team", "")) != BattleState.TEAM_ENEMY: + return "" + if str(unit.get("ai_behavior", "")).strip_edges().to_lower() != "guard": + return "" + var anchor: Vector2i = unit.get("ai_guard_anchor", unit.get("pos", Vector2i(-1, -1))) + var radius := int(unit.get("ai_guard_radius", 0)) + if not state.is_inside(anchor): + return "수비: 거점 경계" + return "수비: 거점 %d,%d 반경 %d" % [anchor.x + 1, anchor.y + 1, radius] + + func _unit_current_terrain_text(unit: Dictionary) -> String: var cell: Vector2i = unit.get("pos", Vector2i(-1, -1)) if not state.is_inside(cell): @@ -5422,6 +5469,9 @@ func _update_cell_info() -> void: _format_hover_unit_equipment(unit) ] var status_effects := state.get_status_effect_summary(unit["id"]) + var ai_text := _unit_ai_behavior_text(unit) + if not ai_text.is_empty(): + text += "\n%s" % ai_text if not status_effects.is_empty(): text += "\n상태: %s" % status_effects if show_threat_overlay: diff --git a/tools/smoke_visual_assets.gd b/tools/smoke_visual_assets.gd index 0578a25..9ae54c7 100644 --- a/tools/smoke_visual_assets.gd +++ b/tools/smoke_visual_assets.gd @@ -3055,6 +3055,19 @@ func _check_hud_focus_text(failures: Array[String]) -> void: failures.append("Enemy archer HUD focus should describe enemy control: %s" % archer_text) if not scene._unit_current_terrain_text(archer).contains("산지"): failures.append("Archer terrain text should reflect its current hill tile") + var guard: Dictionary = scene.state.get_unit("yellow_turban_7") + var guard_text := scene._format_unit_focus_text(guard, "Hover") + if not guard_text.contains("수비: 거점 20,3 반경 3"): + failures.append("Guard HUD focus should describe the defended zone: %s" % guard_text) + if scene._recovery_marker_text(Vector2i(6, 5)) != "+6": + failures.append("Village recovery marker should show healing amount") + if scene._recovery_marker_text(Vector2i(20, 1)) != "+8": + failures.append("Castle recovery marker should show healing amount") + if not scene._recovery_marker_text(Vector2i(1, 6)).is_empty(): + failures.append("Plain terrain should not show a recovery marker") + var marker_rect: Rect2 = scene._recovery_marker_rect(Vector2i(6, 5)) + if not scene._rect_for_cell(Vector2i(6, 5)).encloses(marker_rect): + failures.append("Recovery terrain marker should stay inside its tile: %s" % str(marker_rect)) _check_unit_class_mark(failures, scene, "cao_cao", "tactic", "책") _check_unit_class_mark(failures, scene, "xiahou_dun", "cavalry", "기") _check_unit_class_mark(failures, scene, "yellow_turban_2", "infantry", "보")