Skip to content

04 Research Feudal age

Satoshi Teshiba edited this page Jan 17, 2021 · 4 revisions

After build two buildings, the Feudal age will be able to research.
And to start researching the Feudal age faster, training villagers should be continued and need some houses.

To tell the researching status, LibAoe2AISharp outputs a script which sets goal-ID, after research Feudal age.
But AgeStateCollection class and InitGoalId class are needed to output goal-ID.

To research Feudal age and build a barrack and six farms during researching Feudal age, write the following C # code.

using System;
using LibAoe2AISharp.Framework;
using LibAoe2AISharp.Specifications;
using static LibAoe2AISharp.Framework.EachAgesCommandCollection;
using static LibAoe2AISharp.Specifications.Ope;

namespace Aoe2AISharpSample
{
    class Program
    {
        static void Main(string[] args)
        {
            var systemDefine = new CommandCollection("framework defined goal") {
                new AgeStateCollection(),
                new InitGoalId(),
            };

            var researchLoom = new Research(ri.loom);
            researchLoom.Facts.Add(
                 !new can_train(unit.villager)
                | new unit_type_count(unit.villager, relop.ge, 7)
                );

            var DuringDarkAge = new EachAgesCommandCollection(
                GroupType.DarkAge, "Dark age") {
                researchLoom,
                new TrainVillager(25),
                new BuildHouse(3),
                new BuildLumberCamp(1),
                new BuildMill(1)
            };

            var DuringResearchingFeudalAge = new EachAgesCommandCollection(
                GroupType.DarkAge, ResearchState.Researching, "Rule during Researching Feudal age") {
                new Build(building.barracks, 1),
                new Build(building.farm, 6),
            };

            Console.WriteLine(systemDefine.ToScript());
            Console.WriteLine(DuringDarkAge.ToScript());
            Console.WriteLine(new ResearchAge(age.feudal_age, 25).ToScript());
            Console.WriteLine(DuringResearchingFeudalAge.ToScript());
        }
    }
}

Then, it will output the following AI script.

;===============================================================================
; description: framework defined goal
; Initialize goal ID parameters
;===============================================================================
(defconst AgeState 1) ;goal-id[1] Age transit state
(defconst Transitioned 1) ;goal-id value[1] Age is transitioned
(defconst Transitioning 2) ;goal-id value[2] Age is transitioning
;Initalize goal ID parameters
(defrule
    (true)
=>
    (set-goal AgeState Transitioned)
    (disable-self)
)


;===============================================================================
;description: dark_age NotResearching: Dark age
;common fact: [DarkAge]
; [DarkAge]: Research loom
; [DarkAge]: Train villager up to 25
; [DarkAge]: Build house remaining capacity less than 3
; [DarkAge]: Build lumber_camp up to 1.
; [DarkAge]: Build mill up to 1.
;===============================================================================
;[DarkAge]: Research loom
(defrule
    (can-research ri-loom) ;Can research loom?
    (or
        (not (can-train villager)) ;Can train villager?
        (unit-type-count villager >= 7) ;Check count : unit villager
    )
    (current-age == dark-age) ;[DarkAge]
=>
    (research ri-loom) ;Research loom
)

;[DarkAge]: Train villager up to 25
(defrule
    (can-train villager) ;Can train villager?
    (unit-type-count-total villager < 25) ;Check count : unit villager
    (current-age == dark-age) ;[DarkAge]
=>
    (train villager) ;Train villager
)

;[DarkAge]: Build house remaining capacity less than 3
(defrule
    (can-build house) ;Can build house?
    (housing-headroom <= 3) ;checks remaining populations capacity
    (current-age == dark-age) ;[DarkAge]
=>
    (build house) ;Build house
)

;[DarkAge]: Build lumber_camp up to 1.
(defrule
    (can-build lumber-camp) ;Can build lumber-camp?
    (building-type-count-total lumber-camp < 1) ;Count of lumber-camp
    (current-age == dark-age) ;[DarkAge]
=>
    (build lumber-camp) ;Build lumber_camp
)

;[DarkAge]: Build mill up to 1.
(defrule
    (can-build mill) ;Can build mill?
    (building-type-count-total mill < 1) ;Count of mill
    (current-age == dark-age) ;[DarkAge]
=>
    (build mill) ;Build mill
)


;Research feudal_age
(defrule
    (can-research feudal-age) ;Can research feudal-age?
    (current-age == dark-age) ;Check dark-age
    (unit-type-count villager >= 25) ;Check count : unit villager
=>
    (research feudal-age) ;Research feudal_age
    (set-goal AgeState Transitioning)
)

;===============================================================================
;description: feudal_age Researching: Rule during Researching Feudal age
;common fact: [ToFeudalAge]
; [ToFeudalAge]: Build barracks up to 1.
; [ToFeudalAge]: Build farm up to 6.
;===============================================================================
;[ToFeudalAge]: Build barracks up to 1.
(defrule
    (can-build barracks) ;Can build barracks?
    (building-type-count-total barracks < 1) ;Count of barracks
    (current-age == dark-age) ;[ToFeudalAge]
    (goal AgeState Transitioning) ;Researching
=>
    (build barracks) ;Build barracks
)

;[ToFeudalAge]: Build farm up to 6.
(defrule
    (can-build farm) ;Can build farm?
    (building-type-count-total farm < 6) ;Count of farm
    (current-age == dark-age) ;[ToFeudalAge]
    (goal AgeState Transitioning) ;Researching
=>
    (build farm) ;Build farm
)