翔鹰帝国网|帝国时代论坛|帝国时代系列|神话时代
 找回密码
 注册翔鹰会员(昵称)
搜索
查看: 660|回复: 5

[教程] [UP1.5] AI教学模块 - DUC:向固定点巡逻

[复制链接]

183

主题

9

精华

2万

积分

教皇

耕战
3325
鹰币
15206
天龙币
0
回帖
1200

翔鹰建站十周年纪念章

附庸关系3
 楼主| 发表于 2020-5-21 15:24:24 | 显示全部楼层 |阅读模式
AI文件:(与下面的正文完全一致,可选择其中一种阅读)
注:本per文件为UTF-8编码,可直接用于DE。在旧版里用时,需要自己转码为GBK。





;///////////////////////////////////////////////////////////
;// -------------------- AI教学模块 ----------------------//
;//                  DUC:向固定点巡逻                    //
;//                                     作者:newtonerdai //
;//                                       www.hawkaoe.net //
;///////////////////////////////////////////////////////////
;
;                         【前言】
;▲模块作用:收到AI事件5号(或输入数字5后),搜索给定点附近的AI部队,向给定目的地巡逻

;    而你如果明白了坐标是可变的,你可以通过DUC搜索,实时获取己方和敌方位置
;作为实时变化的搜索圆心和目的地,那样的话你的AI灵活性将会更大!
;
;▲适用版本:仅适用于支持UP1.5 AI语句的版本。如UP1.5、WK、DE。
;
;▲使用方法:
;   准备阶段
;       1. 把这个AI(包括.ai和.per两个文件)放到游戏根目录的ai文件夹(DE的为 AoE2DE\resources\_common\ai)。
;       2. 重载你的编辑器场景,在编辑器中给任意电脑玩家指定这个AI(上方[玩家]选项卡)。
;   测点阶段
;       3. 通过[模块 - 获取闪光坐标]获取你需要的坐标(己方部队圆心、巡逻目的地),填写到下面的“参数输入部分”里。
;   指派阶段
;       4. 回到编辑器,在你需要命令AI执行巡逻的触发里,添加效果:[发送AI触发器/AI事件/AI信号],触发器编号为5
;       4.'(为了方便测试,你也可以使用数字5来触发,如果不需要,可以自行把(or (A)(B))的或逻辑删掉)
;       5. 进入测试,你会发现在合适的时机(或输入数字5)后,在圆心附近的部队往目的地巡逻了。
;   学以致用
;       6. 现在,你已经理解了比较简单的DUC巡逻方法。但范例这里的部队圆心、目的地都是固定的,你可以善用DUC搜索,实时调整圆心和目的地,运用到你的AI里。

;----------------------------------------------------------
;                     DUC:向固定点巡逻           
;----------------------------------------------------------

(defconst g-army-x 111)
(defconst g-army-y 112)
(defconst g-destination-x 113)
(defconst g-destination-y 114)

(defconst gl-local-total 120)
(defconst gl-local-last 121)
(defconst gl-remote-total 122)
(defconst gl-remote-last 123)

;=========== 参数输入部分  ===========
;注:以下参数数值设为 -1 时会被DUC系统忽略
(defconst army-range 3)         ; 稍后搜索AI部队时,以g-army-x为中心,只搜索这个半径内的单位
(defconst exclude-class -1)     ; 稍后搜索AI部队时,你不想搜索的种属(可查AGE和文末种属表,替换-1为某个种属编号)
(defconst cmdid-military 4)     ; 稍后搜索AI部队时,你想搜索的单位分类。这里代表[军事单位]分类
(defrule
    (true)
=>
    (up-modify-goal g-army-x c:= -1)            ; 稍后要搜索并巡逻的AI部队中心点坐标。可通过[模块 - 获取闪光坐标]获取
    (up-modify-goal g-army-y c:= -1)            ; 同上。如果想要使用可变的坐标,可以将“c:”改为“g:”,后面数字换成另外实时获取的坐标目标。可自行找教程学习(关键词 DUC或UP1.5)。
    (up-modify-goal g-destination-x c:= -1)     ; 稍后要让AI部队巡逻到的目的地坐标。获取方法同上
    (up-modify-goal g-destination-y c:= -1)     ; 同上
    (disable-self)
)

;============= 运行部分  =============
(defrule
    (or (taunt-detected 1 5)                        ; 测试用,发出数字5后,直到下一条规则成功巡逻前会一直执行。只要两种触发方式满足一种即可。
        (event-detected trigger 5))                 ; 收到触发发送的AI触发器(AI事件)5号后,直到下一条规则成功巡逻前会一直执行
    (up-timer-status 10 <= 1)                       ; 10 = 定时器10号。<=1 :定时器禁用或已触发
=>
    (up-full-reset-search)                          ; 使用DUC前先完全重置一次。

    (up-set-target-point g-army-x)                  ; 设置下面up-filter-distance的中心点。其代表的应为AI部队的中心点
    (up-filter-distance c: -1 c: army-range)        ; 设置距离筛选条件,只有在距离g-army-x点army-range半径范围内的单位会被搜索。
    (up-filter-exclude -1 -1 -1 exclude-class)      ; 设置排除筛选条件,种属是exclude-class的单位不会被搜索。
    (up-filter-include cmdid-military -1 -1 -1)     ; 设置包括筛选条件,只有是cmdid-military(军事单位)分类的单位才会被搜索。

    (up-find-local c: -1 c: 60)                     ; 搜索最多60个本AI玩家任何单位,用于之后的指派巡逻。-1可以替换为其他的单位编号/种属编号/单位系,这样可以只搜索某种单位。
                                                    ; 如果想只搜索特定的单位,可以把-1替换为单位编号/种属编号/单位系
    (up-get-search-state gl-local-total)                            ; 获取搜索结果计数
    (up-chat-data-to-all "找到本地单位:%d 个" g: gl-local-total)   ; 测试用,播报出找到的AI部队数量
)
(defrule
    (or (taunt-detected 1 5)                        ; 测试用,发出数字5时会执行一次。只要两种触发方式满足一种即可。
        (event-detected trigger 5))                 ; 收到触发发送的AI触发器(AI事件)5号时,执行一次
    (up-timer-status 10 <= 1)                       ; 10 = 定时器10号。<=1 :定时器禁用或已触发
    (up-compare-goal gl-local-total c:> 0)          ; 只有找到AI的部队时才会执行指派
=>
    (up-target-point g-destination-x 2 -1 -1)       ; 把搜索到的AI部队,向g-destination-x点处巡逻。2 = action-patrol(巡逻)。也可以使用 1 = action-move(移动)

    (enable-timer 10 2)                             ; 10 = 定时器10号。2 = 两秒执行一次。避免快速指派造成抽搐
    (acknowledge-taunt 1 5)                         ; 测试用,承收数字5,使其可以重复使用
    (acknowledge-event trigger 5)                   ; 承收AI触发器(AI事件)5号,使其可以重复使用
)

;【附录:物件编号】
; 注:这里只列举了一部分单位编号和种属编号,更多物件编号可以自行查找AGE,然后在你的AI或UserPatchConst.per里添加。

;(defconst flare 274)                   ;闪光信号
;(defconst town-center-foundation 621)  ;城镇中心地基

;(defconst all-units-class -1)          ;所有种属
;(defconst archery-class 900)           ;弓箭手种属
;(defconst building-class 903)          ;建筑种属
;(defconst villager-class 904)          ;村民种属
;(defconst ocean-fish-class 905)        ;海洋鱼种属
;(defconst infantry-class 906)          ;步兵种属
;(defconst cavalry-class 912)           ;骑兵种属
;(defconst siege-weapon-class 913)      ;攻城武器种属
;(defconst monastery-class 918)         ;修道院种属
;(defconst warship-class 922)           ;战船种属
;(defconst cavalry-cannon-class 923)    ;征服者种属
;(defconst wall-class 927)              ;城墙种属
;(defconst shore-fish-class 933)        ;沿海鱼种属
;(defconst petard-class 935)            ;破坏者种属
;(defconst cavalry-archer-class 936)    ;骑射手种属
;(defconst gate-class 939)              ;城门种属
;(defconst archery-cannon-class 944)    ;火枪手种属
;(defconst farm-class 949)              ;农田种属
;(defconst packed-trebuchet-class 951)  ;打包的攻城武器种属
;(defconst tower-class 952)             ;塔种属
;(defconst unpacked-trebuchet-class 954);展开的攻城武器种属
;(defconst scorpion-class 955)          ;弩炮种属
;(defconst livestock-class 958)         ;牲畜种属
;(defconst king-class 959)              ;国王种属




;///////////////////////////////////////////////////////////
;// -------------------- AI教学模块 ----------------------//
;//                  DUC:向固定点巡逻                    //
;//                                     作者:newtonerdai //
;//                                       www.hawkaoe.net //
;///////////////////////////////////////////////////////////
;
;                         【前言】
;▲模块作用:收到AI事件5号(或输入数字5后),搜索给定点附近的AI部队,向给定目的地巡逻

;    而你如果明白了坐标是可变的,你可以通过DUC搜索,实时获取己方和敌方位置,
;作为实时变化的搜索圆心和目的地,那样的话你的AI灵活性将会更大!
;
;▲适用版本:仅适用于支持UP1.5 AI语句的版本。如UP1.5、WK、DE。
;
;▲使用方法:
;   准备阶段
;       1. 把这个AI(包括.ai和.per两个文件)放到游戏根目录的ai文件夹(DE的为 AoE2DE\resources\_common\ai)。
;       2. 重载你的编辑器场景,在编辑器中给任意电脑玩家指定这个AI(上方[玩家]选项卡)。
;   测点阶段
;       3. 通过[模块 - 获取闪光坐标]获取你需要的坐标(己方部队圆心、巡逻目的地),填写到下面的“参数输入部分”里。
;   指派阶段
;       4. 回到编辑器,在你需要命令AI执行巡逻的触发里,添加效果:[发送AI触发器/AI事件/AI信号],触发器编号为5
;       4.'(为了方便测试,你也可以使用数字5来触发,如果不需要,可以自行把(or (A)(B))的或逻辑删掉)
;       5. 进入测试,你会发现在合适的时机(或输入数字5)后,在圆心附近的部队会往目的地巡逻了。
;   学以致用
;       6. 现在,你已经理解了比较简单的DUC巡逻方法。但范例这里的部队圆心、目的地都是固定的,你可以善用DUC搜索,实时调整圆心和目的地,运用到你的AI里。

;----------------------------------------------------------
;                     DUC:向固定点巡逻           
;----------------------------------------------------------

(defconst g-army-x 111)
(defconst g-army-y 112)
(defconst g-destination-x 113)
(defconst g-destination-y 114)

(defconst gl-local-total 120)
(defconst gl-local-last 121)
(defconst gl-remote-total 122)
(defconst gl-remote-last 123)

;=========== 参数输入部分  ===========
;注:以下参数数值设为 -1 时会被DUC系统忽略

; 稍后搜索AI部队时,以g-army-x为中心,只搜索这个半径内的单位
(defconst army-range 3)         
; 稍后搜索AI部队时,你不想搜索的种属(可查AGE和文末种属表,替换-1为某个种属编号)
(defconst exclude-class -1)     
; 稍后搜索AI部队时,你想搜索的单位分类。这里代表[军事单位]分类
(defconst cmdid-military 4)     

(defrule
    (true)
=>
    ; 稍后要搜索并巡逻的AI部队中心点坐标。可通过[模块 - 获取闪光坐标]获取
    (up-modify-goal g-army-x c:= -1)            
    ; 同上。如果想要使用可变的坐标,可以将“c:”改为“g:”,后面数字换成另外实时获取的坐标目标。
    ; 可自行找教程学习(关键词 DUC或UP1.5)。
    (up-modify-goal g-army-y c:= -1)            
    ; 稍后要让AI部队巡逻到的目的地坐标。获取方法同上
    (up-modify-goal g-destination-x c:= -1)     
    ; 同上
    (up-modify-goal g-destination-y c:= -1)     
    (disable-self)
)

;============= 运行部分  =============
(defrule
    ; 测试用,发出数字5后,直到下一条规则成功巡逻前会一直执行。只要两种触发方式满足一种即可。
    (or (taunt-detected 1 5)                        
    ; 收到触发发送的AI触发器(AI事件)5号后,直到下一条规则成功巡逻前会一直执行
        (event-detected trigger 5))                 
    ; 10 = 定时器10号。<=1 :定时器禁用或已触发
    (up-timer-status 10 <= 1)                       
=>
    ; 使用DUC前先完全重置一次。
    (up-full-reset-search)                          

    ; 设置下面up-filter-distance的中心点。其代表的应为AI部队的中心点
    (up-set-target-point g-army-x)
    ; 设置距离筛选条件,只有在距离g-army-x点army-range半径范围内的单位会被搜索
    (up-filter-distance c: -1 c: army-range)
    ; 设置排除筛选条件,种属是exclude-class的单位不会被搜索。
    (up-filter-exclude -1 -1 -1 exclude-class)
    ; 设置包括筛选条件,只有是cmdid-military(军事单位)分类的单位才会被搜索。
    (up-filter-include cmdid-military -1 -1 -1)

    ; 搜索最多60个本AI玩家任何单位,用于之后的指派巡逻。
    ; -1可以替换为其他的单位编号/种属编号/单位系,这样可以只搜索某种单位。
    ; 如果想只搜索特定的单位,可以把-1替换为单位编号/种属编号/单位系
    (up-find-local c: -1 c: 60)                     
    ; 获取搜索结果计数         
    (up-get-search-state gl-local-total)               
    ; 测试用,播报出找到的AI部队数量            
    (up-chat-data-to-all "找到本地单位:%d 个" g: gl-local-total)   
)
(defrule
    ; 测试用,发出数字5时会执行一次。只要两种触发方式满足一种即可。
    (or (taunt-detected 1 5)                        
    ; 收到触发发送的AI触发器(AI事件)5号时,执行一次   
        (event-detected trigger 5))                 
    ; 10 = 定时器10号。<=1 :定时器禁用或已触发        
    (up-timer-status 10 <= 1)                       
    ; 只有找到AI的部队时才会执行指派   
    (up-compare-goal gl-local-total c:> 0)         
=>
    ; 把搜索到的AI部队,向g-destination-x点处巡逻。2 = action-patrol(巡逻)。
    ; 也可以使用 1 = action-move(移动)
    (up-target-point g-destination-x 2 -1 -1)      

    ; 10 = 定时器10号。2 = 两秒执行一次。避免快速指派造成抽搐
    (enable-timer 10 2)                             
    ; 测试用,承收数字5,使其可以重复使用
    (acknowledge-taunt 1 5)                        
    ; 承收AI触发器(AI事件)5号,使其可以重复使用
    (acknowledge-event trigger 5)                  
)

;【附录:物件编号】
;注:物件包括了单位和建筑,有些语句可支持使用单位/建筑编号、单位系和种属编号。
;    这里只列举了一部分单位编号和种属编号,更多物件编号可以查找AGE,然后在你的AI或UserPatchConst.per里添加。
;    标注[*]号的表示未包含在UserPatchConst.per里,需要自行defconst。
;(defconst flare 274)                   ;闪光信号
;(defconst town-center-foundation 621)  ;城镇中心地基
;……
;(defconst all-units-class -1)          ;所有种属
;(defconst archery-class 900)           ;弓箭手种属
;(defconst artifact-class 901)          ;文物种属   [*]
;(defconst trade-cog-class 902)         ;商船种属   [*]
;(defconst building-class 903)          ;建筑种属
;(defconst villager-class 904)          ;村民种属
;(defconst ocean-fish-class 905)        ;海洋鱼种属
;(defconst infantry-class 906)          ;步兵种属
;(defconst forage-class 907)            ;浆果丛种属  [*]
;(defconst stone-mine-class 908)        ;石矿种属   [*]
;(defconst prey-animal-class 909)       ;被动型动物种属    [*]
;(defconst predator-animal-class 910)   ;攻击型动物种属    [*]
;(defconst miscellaneous-class 911)     ;杂类种属   [*]
;(defconst cavalry-class 912)           ;骑兵种属
;(defconst siege-weapon-class 913)      ;攻城武器种属
;(defconst terrain-class 914)           ;地形物种属  [*]
;(defconst tree-class 915)              ;树木种属   [*]
;(defconst monastery-class 918)         ;修道院种属
;(defconst trade-cart-class 919)        ;贸易车种属  [*]
;(defconst transport-ship-class 920)    ;运输船种属  [*]
;(defconst fishing-ship-class 921)      ;渔船种属   [*]
;(defconst warship-class 922)           ;战船种属
;(defconst cavalry-cannon-class 923)    ;征服者种属
;(defconst wall-class 927)              ;城墙种属
;(defconst flare-class 930)             ;旗帜种属   [*]
;(defconst gold-mine-class 932)         ;金矿种属   [*]
;(defconst shore-fish-class 933)        ;沿海鱼种属
;(defconst petard-class 935)            ;破坏者种属
;(defconst cavalry-archer-class 936)    ;骑射手种属
;(defconst gate-class 939)              ;城门种属
;(defconst relic-class 942)             ;圣物种属   [*]
;(defconst monk-with-relic-class 943)   ;带着圣物的僧侣种属  [*]
;(defconst archery-cannon-class 944)    ;火枪手种属种属
;(defconst scout-cavalry-class 947)     ;斥候骑兵种属 [*]
;(defconst farm-class 949)              ;农田种属
;(defconst packed-trebuchet-class 951)  ;打包的攻城武器种属
;(defconst tower-class 952)             ;塔种属
;(defconst unpacked-trebuchet-class 954);展开的攻城武器种属
;(defconst scorpion-class 955)          ;弩炮种属
;(defconst livestock-class 958)         ;牲畜种属
;(defconst king-class 959)              ;国王种属




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册翔鹰会员(昵称)

x
索引:
Userpatch 实用技术贴索引←点击进入
决定版精品贴大索引←点击进入

战役:
《 兔与豹》——柔弱奴隶公主  猛兽口中求生←点击进入
《敛由国的统一》←点击进入

殊途战役制作群 QQ: 616317226
翔鹰帝国Ⅱ:决定版交流群 QQ: 112822759
回复

使用道具 举报

33

主题

2

精华

2万

积分

征服者

耕战
4681
鹰币
18616
天龙币
0
回帖
477
附庸关系2
发表于 2020-5-21 16:41:58 | 显示全部楼层
新桶高产似母猪
回复

使用道具 举报

15

主题

0

精华

1033

积分

伯爵

耕战
175
鹰币
580
天龙币
0
回帖
188
附庸关系0
发表于 2020-5-23 02:45:24 | 显示全部楼层
哀 我想说这个 ;(defconst gate-class 939)  ;城门种属   可以无视了,AI无法使用而且决定版内部硬代码疯狂命令AI不断攻击,导致AI一台重型冲车撞个城门都要撞2分钟之久
回复

使用道具 举报

183

主题

9

精华

2万

积分

教皇

耕战
3325
鹰币
15206
天龙币
0
回帖
1200

翔鹰建站十周年纪念章

附庸关系3
 楼主| 发表于 2020-5-24 12:17:25 | 显示全部楼层
blazefires 发表于 2020-5-23 02:45
哀 我想说这个 ;(defconst gate-class 939)  ;城门种属   可以无视了,AI无法使用而且决定版内部硬代码疯狂 ...

疯狂命令可能是DE执行频率的问题。
jacky lin说DE执行频率加快了很多,需要配合定时器限制执行频率
或许可以试试用一个1秒的定时器作为事实来执行你的指派
索引:
Userpatch 实用技术贴索引←点击进入
决定版精品贴大索引←点击进入

战役:
《 兔与豹》——柔弱奴隶公主  猛兽口中求生←点击进入
《敛由国的统一》←点击进入

殊途战役制作群 QQ: 616317226
翔鹰帝国Ⅱ:决定版交流群 QQ: 112822759
回复

使用道具 举报

15

主题

0

精华

1033

积分

伯爵

耕战
175
鹰币
580
天龙币
0
回帖
188
附庸关系0
发表于 2020-5-24 16:49:22 | 显示全部楼层
本帖最后由 blazefires 于 2020-5-24 16:53 编辑
newtonerdai 发表于 2020-5-24 12:17
疯狂命令可能是DE执行频率的问题。
jacky lin说DE执行频率加快了很多,需要配合定时器限制执行频率
或许 ...

是这样的,DE版AI对墙右键,但是周围如果有城门会强制AI去攻击城门
这就算了,还会一直自动命令攻击城门的单位一直攻击
这将导致冲车撞门5秒钟才扣了1次城门血条...   只有1次攻击是成功的
这种bug是DE内部造成的,有计时器也没用

这跟以前玩家命令肉马疯狂点击敌人打包机,但肉马还是爱跟敌人枪兵对拼一样的bug...
回复

使用道具 举报

本版积分规则

排行榜|小黑屋|翔鹰帝国

GMT+8, 2024-4-25 03:08 , Processed in 0.115484 second(s), 65 queries , File On.

Powered by Hawk Studio  QS Security Corp.® Licensed

Copyright © 2001-2023, Hawkaoe.net All Rights Reserved

快速回复 返回顶部 返回列表