Source-first reverse engineering of a mainline Battle for Wesnoth campaign
AI Index
A campaign-wide index of declarative AI tuning, scripted reinforcements, autonomous allies, dormant factions, and Clearwater Port’s posture-based defense system.
Northern castles or southern riverbank, plus permanent wall goals
Special workaround
Temporary helper side during withdrawal
No helper-side retreat sequence
Use case
Readable multi-turn tactical transition
Responsive static-defense allocation
Scenario 15 Lua candidate action
ca_aggressive_attack_no_suicide.lua is added to all three continental sides at a maximum score of 100000. The standard combat, high-XP attack, and poison-spreading candidate actions are removed.
Evaluation step
Behavior
Enumerate attacks
Uses the campaign’s AI-helper dependency to find all possible attacks.
Simulate combat
Clones the attacker at the destination and calls wesnoth.simulate_combat.
Safety gate
Considers only attacks where att_stats.hp_chance[0] == 0.
Uses robust_move_and_attack on the highest-rated safe attack.
Technical lesson. The campaign does not build a whole AI. It replaces one decision point—the attack selector—because that is the only default behavior incompatible with a deathless scenario.
Three Saurian sides defend the cave region, one targets Haldric, and a hidden Dragon side is event-created. Boss awakening funds every Saurian army.
Lizard Beach
Two passive leaders anchor the trade site; progress creates fixed Naga reinforcements; first leader death funds the survivor.
Troll Hole
Four symmetric Troll sides are declared, but random setup removes two leaders. Aggression scales modestly by difficulty; recruit limits control regenerating unit density.
Cursed Isle
Two Spectre sides protect the island center, remain cautious by day, and become aggressive at night. The Queen is event-created and her death deletes the remaining faction.
The branch set shows a recurring campaign principle: ordinary AI handles movement and combat, while WML events guarantee the scenario-defining phase changes.
AI and scripted escalation in Scenarios 18–20
Scenario
AI architecture
Scenario-defining scripting
18
No tactical AI needed.
Temporary unit double moves through the council cutscene.
Each front’s proportional losses trigger one spatially searched undead wave.
20
Passive undead leader, night-aggressive orcs.
Turn-5 fog curse and Chocobones; exploration-triggered Cuttle Fish and Saurians.
Scenario 19 is a useful boundary case: the enemy sides themselves use ordinary AI, while the reinforcement director monitors army strength and map geometry outside the AI system.
Final-battle AI boundary
Layer
Responsibility
Jevyan AI
Passive leader, castle protection, night aggression, undead recruitment.
Orc AI
Maritime, defensive, and night-aggressive ordinary battlefield pressure.
Event director
Required killer, survivor count, boat escape, bridges, Naga arrival, random undead schedules, and faction reinforcement economy.
The final scenario demonstrates why objective logic should remain outside AI: the computer-controlled factions fight normally, while the event layer evaluates the player’s strategic deception contract.