Age of Empires II - AI Scripting.

This is a brief introduction to AI scripting in Age Of Empires II. In the following resources you may find an in depth overview of the tools and relevant settings.

Resources:

Resources

.per and .ai files:

  • AIs files come in pairs: name.ai and name.per (name’s must be identical).
  • This files should be located:

– AoE II DE: C:\Program Files (x86)\Steam\steamapps\common\AoE2DE\resources\_common\ai\

– Classic AoE II: \Age Of Empires II\AOE II - The Conquerors\AI

Scripting Language Overview:

  • AoE II scripting language is based on CLIPS (C Language Integrated Production System).
  • Defining rules involves defrule instruction with facts and actions.
  • Facts trigger actions as long as they remain true unless disabled.
  • Example:
(defrule
	(true)
=>
	(chat-to-all "Hi, let's play AoE II!")
	(disable-self)	;Disable after executed once.
)

Programming Levels:

  • There are five levels of AoE II programming:
    1. Defrules, defconsts, timers…
    2. Random generator, conditional (file) loading, goals
    3. Strategic Numbers
    4. Userpatch commands
    5. Direct Unit Control

Scouting the Map:

  • Level 3 programming involves strategic numbers (SN) for adjusting AI parameters.
  • SN adjust AI behavior and can be changed throughout the game.
  • Default values are important to understand AI behavior fully.

Setting Strategic Numbers:

(defrule
	(true)
=>
	(set-strategic-number strategic-number number)
	(disable-self)
)

Example:

(defrule
	(true)
=>
	(set-strategic-number sn-cap-civilian-explorers 0)
	(set-strategic-number sn-total-number-explorers 0)
	(disable-self)
)

Units and Buildings IDs:

Example:

(defconst livestock-class 958)
(unit-type-count livestock-class > 0)

Conditionals:

  • Use #load-if-defined to check civilization.
  • Example:
#load-if-defined BRITON-CIV
	(defconst text-my-civ "I'm Britons, will make Longbows")
#else
	(defconst text-my-civ "I'm not Britons, will not make Longbows")
#end-if

Training Villagers:

  • Use fact-checkers like can-train to avoid bugs.
  • Example:
(defrule
	(can-train villager)
=>
	(train villager)
)

Miscellaneous:

  • Use space with relative operators like >= 5.
  • Prefix types with TypeOp (only for level 4 and 5).
  • Example:
(defconst starting-vills-on-sheep 6)
(defrule
	(true)
=>
	(chat-to-all "I need %d villagers on sheep" c: starting-vills-on-sheep)
	(disable-self)
)
  • Building conditions:
    • can-build checks if the building is available.
    • sn-initial-exploration-required: Change default from 2 to 0.
    • (housing-headroom < 4): Example condition for housing.

Related Posts