Skip to content
Satoshi Teshiba edited this page Sep 27, 2020 · 5 revisions

Welcome to the LibAoe2AISharp wiki!

"defrule" sample code.

Write the following C# code to train a villager.

using System;
using LibAoe2AISharp.Specifications;
using LibAoe2AISharp.Utilty;

namespace Aoe2AISharpSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(new Train(unit.villager).ToScript());
        }
    }

    public class Train : defrule
    {
        public Train(unit trainingUnit)
        {
            Comment = "Train " + trainingUnit.ToLocalLang();
            Facts.Add(new can_train(trainingUnit));
            Actions.Add(new train(trainingUnit));
        }
    }
}

Then, it will output the following AI script.

;Train villager
(defrule
    (can-train villager) ;Can train villager?
=>
    (train villager) ;Train villager
)