Source-first reverse engineering of a mainline Battle for Wesnoth campaign
08 — Clearwater Port
A timed coastal evacuation with four graded victories, three physical ship departures, escalating orc pressure, and the campaign’s first deeply stateful allied AI.
Clearwater Port is already evacuating its population when Haldric arrives. Commander Aethyr explains that the local army initially drove the orcs back into the Swamp of Esten, but reinforcements destroyed the defense and killed the King of Clearwater. Three more shiploads are needed before the remaining population can escape.
The opening conversation formalizes the Wesfolk as Haldric’s allies, introduces Aethyr as the local commander, and turns the scenario into a moral timing choice. The player may leave early, remain for a later ship, or fight until every enemy leader is dead. The longer the party remains, the more heroic—and mechanically rewarding—the outcome becomes.
Dialogue phase
Function
Arrival briefing
Explains the port’s losses, missing fleet, and evacuation schedule.
Wesfolk recognition
Publicly confirms Jessene’s people as allies rather than prisoners.
Three ship announcements
Turn the timetable into character-delivered tactical information.
Aethyr’s final decision
Leaves the commander behind as a tragic rear guard.
Victory detour
Redirects the refugees to Fallen Lich Point for the Book of Fire and Darkness.
Map description
The 42 × 37 winter coastal map stretches from mountains and frozen inland approaches in the west to Clearwater’s harbor and open sea in the east. Haldric enters near the city, Aethyr’s forward castle and inner wall guard the eastern settlement, and three orc armies attack from the landward side. Bridges, shallow water, deep water, snow, hills, roads, villages, city terrain, and a lighthouse create several distinct defensive layers.
Map element
Design role
Forward castle
Gives Aethyr’s AI a first defensive posture before falling back.
Inner city wall
Supports a second defensive posture and evacuation pier.
Harbor pier
Hosts three different Haldric-only boarding hexes.
Large western land approach
Supports three enemy recruitment fronts and player counterattacks.
Lighthouse at 34,8
Uses scenery, halo, and a local time schedule to simulate illumination.
Four signposts
Connect the port to Dead-Man’s Ford, the River Road, and local geography.
Objectives and graded victory
Outcome
Requirement
Bonus
Cowardly
Haldric boards the first ship.
No early-finish bonus
Normal
Haldric boards the second ship.
No early-finish bonus
Heroic
Haldric boards the third ship.
Early-finish bonus
Heroic
Defeat all three enemy leaders.
Early-finish bonus
Defeat condition
Reason
Haldric dies
Campaign protagonist lost
Lady Jessene dies
Required companion and translator lost
Commander Aethyr dies
The port’s evacuation command collapses
The last ship leaves
The refugees are trapped by winter
Every valid victory carries 40% gold. The third ship and total enemy defeat award the scenario’s early-finish bonus even though they occur later, because the objectives explicitly define heroic success rather than using elapsed turns alone.
Temporary side used during withdrawal attack handling
4 — Orcs
Tan-Vragar, Orcish Warlord
180 / 225 / 270; income 5 / 7 / 9
Land army; gains Naga recruits on turn 3
5 — Orcs
Tan-Burg, Orcish Warlord
180 / 225 / 270; income 5 / 7 / 9
Second land army
6 — Orcs
Ut’Tan-Vrork, Orcish Warlord
240 / 300 / 360; income 8 / 12 / 16
Primary high-resource enemy army
Commander Aethyr’s stateful allied AI
Side 2 is reconfigured every one of its turns. The scenario records its posture in previous_ai_position and can move among four broad modes:
FORWARD DEFENSE
├── player pushes far west ─────────────► OFFENSIVE SUPPORT
└── 10+ orcs swarm forward castle
├── first withdrawal turn ───────► RETREAT FIRSTTURN
├── second withdrawal turn ──────► RETREAT SECONDTURN
└── withdrawal completed ────────► CITY-WALL DEFENSE
Mode
Implementation behavior
Forward defense
Resets defensive AI, assigns high-value goal hexes in the outer castle, and avoids overextension.
Full retreat
Uses extreme caution, disables ordinary attacking, and moves troops toward the inner city.
Retreat attack workaround
Temporarily moves non-leader units to hidden side 3 for one turn so adjacent enemies can still be attacked without allowing forward movement.
City-wall defense
Assigns weighted goal hexes along the wall and avoids advancing back into the field.
Offensive support
If at least four player units are far forward, resets side 2 to an offensive posture so it can support them.
Dynamic allied recruitment
Aethyr normally recruits inexpensive Peasants, Bowmen, and Spearmen. Peasants are limited to two so the AI does not repeatedly expose fragile units along the wall. At the start of each side-2 turn, the scenario checks the garrison’s stored gold:
Gold state
Extra recruits
60 or less
None
More than 60
Heavy Infantryman, Longbowman, Javelineer, Pikeman, Swordsman
This allows the AI to spend accumulated resources on advanced defenders when the player has not captured its villages.
Ship timetable and local macro
Ship
Arrives
Leaves
Boarding hex
Victory bonus
First
Turn 12
Turn 18
31,16
No
Second
Turn 20
Turn 24
32,14
No
Third
Turn 26
Time over
29,16
Yes
BOARDING_EVENT SHIP_EVENT ABSCISSA ORDINATE BONUS removes three nearly identical movement events. It validates that the moving unit is Haldric, checks whether the correct ship flag is active, ends the level with the specified bonus, or explains why boarding is currently invalid.
#define BOARDING_EVENT SHIP_EVENT ABSCISSA ORDINATE BONUS
[event]
name=moveto
first_time_only=no
...
# Haldric + active ship flag -> victory
# Haldric + no ship -> wait and defend
# other unit -> Prince Haldric must board here
[/event]
#enddef
Enemy escalation
Trigger
Effect
Turn 3
Side 4 gains Naga Fighter recruitment and receives 1 / 2 / 3 loyal Nagas.
Turns 10, 16, 22, 28
On Normal and Hard, all three orc sides receive periodic gold.
Turns 16, 22, 28
On Easy, the first reinforcement payment is omitted.
Design interpretation. The scenario turns time into an ethical difficulty selector. The player chooses when enough has been sacrificed, while the allied AI makes the city feel defended by an actual garrison rather than decorative units.
Pattern
Reuse lesson
Graded victories
Offer multiple valid exits with narrative labels and different rewards.
Stateful allied AI
Track posture explicitly when an ally must perform recognizable military phases.
Dynamic recruit quality
Let accumulated AI gold unlock stronger units instead of sitting unused.
Schedule-driven physical transport
Animate arrivals and departures so the turn deadline exists on the map.
Refactor repeated exits into a macro
Keep three boarding interactions consistent and easy to rebalance.
Unlock a humble recruit through story
The new Peasant recruit records the port farmers’ support.