找回密码
 点一下
查看: 3578|回复: 40

如何移植AI?

[复制链接]
发表于 2010-8-6 09:45:23 | 显示全部楼层 |阅读模式
听说AI这玩意儿可以移植?于是我把真三的zhensan.ai这个文件导入到我的地图,再在初始化触发-对非用户玩家启用对战AI-zhensan.ai,可是没有发现任何变化啊?求解。
还有,是不是选英雄方式不一样,导致AI无法运行?但是AI文件里,我貌似没有看到选英雄的函数……
发表于 2010-8-6 10:00:29 | 显示全部楼层
ai涉及很多东西,基本不可能移植
回复

使用道具 举报

发表于 2010-8-6 13:35:00 | 显示全部楼层
看懂别人怎么做的,然后自己照着改改再做一个-0-
回复

使用道具 举报

发表于 2010-8-8 14:26:50 | 显示全部楼层

回 1楼(疯人¢衰人) 的帖子

能不能提供一些AI资料!传上来看看嘛!
回复

使用道具 举报

 楼主| 发表于 2010-8-8 14:41:46 | 显示全部楼层
我发上来咦个,大家帮忙看看如何移植使用

dota.rar

5 KB, 下载次数: 41

回复

使用道具 举报

发表于 2010-8-8 14:47:24 | 显示全部楼层
引用第1楼疯人¢衰人于2010-08-06 10:00发表的  :
ai涉及很多东西,基本不可能移植
嗯,比如正規的,轉到對戰圖,要來個首發DK什麼嗎?,不可能。
回复

使用道具 举报

 楼主| 发表于 2010-8-8 15:31:14 | 显示全部楼层
你帮我看看我的那个AI文件,不知道怎么用
是游戏初始化时出发启用对战AI?
回复

使用道具 举报

 楼主| 发表于 2010-8-8 16:58:02 | 显示全部楼层
呼唤高人们!!!!
function main takes nothing returns nothing
    set ai_player=Player(GetAiPlayer())
    set start_loc=GetStartLocationLoc(GetPlayerStartLocation(Player(GetAiPlayer()-10)))
    if GetPlayerController(Player(GetAiPlayer()-10))==MAP_CONTROL_COMPUTER then
        set ally=true
    endif                                       
    call SetMeleeAI()                           //开始对战AI  
    call SetDefendPlayer(true)                  //设置单位攻击时防御  
    call SetHeroesBuyItems(true)                //设置英雄自动买物品  
    call SetHeroesFlee(true)                    //设置英雄生命值少时自动逃跑  
    call SetHeroesTakeItems(true)               //设置英雄自动捡物品  
    call SetIgnoreInjured(true)                 //设置单位忽视伤害(战斗时红血都不自动跑)  
    call SetPeonsRepair(true)                   //设置农民自动维修  
    call SetRandomPaths(true)                   //设置随机路线(估计在进攻,逃跑随机路线)  
    call SetSmartArtillery(true)                //设 置 炮 兵 巧 妙 攻 击 。 (太 近 会 走 开 点 去 攻 击 ?)
    call SetTargetHeroes(true)                  //设 置 英 雄 目 标 。( 为 主 要 目 标 ?)  
    call SetUnitsFlee(true)                     //设置单位可以逃跑  
    call SetWatchMegaTargets(true)              //开始对战AI  
    call SetCaptainChanges(true)                // 设 置 监 视 大 单 位 ( 主 要 的)。
    call CreateCaptains()                       // 创建队长(好像是英雄带领小兵)  
    call StartThread(function attack_loop)      // 开始线程,运行 (function attack_loop)  
    call StartThread(function check_hp)         // 开始线程,运行(function check_hp)
endfunction



globals
    unit array aihero           //设置英雄单位
    integer hero_num=0          //用于计算英雄数量  
    group udg_g=CreateGroup()   //用于记录AI玩家所有单位  
    boolean flee=false          //设置是否逃跑  
    boolean finishMF=false      //设置是否MF
    boolean attack_enemy=false  //设置是否攻击敌人  
    boolean ally=false          //设置是否攻击盟友
    real ratio=1                //radio是用于判断生命比的整数
    integer count=0             //记录游戏开始秒数  
    location start_loc          //玩家开始的地方  
    boolean buyitem=false       //设置是否在购买物品,一开始false表示不在,如果ture表示在
    boolean kabing=false        //设置是否在卡兵,一开始false表示不在,如果ture表示在
endglobals



function main takes nothing returns nothing  
    set ai_player=Player(GetAiPlayer())  //用变量记录当前的AI玩家为       ai_player                                   
    call SetMeleeAI()                           //开始对战AI   
    call SetHeroesBuyItems(true)                //设置英雄自动买物品   
    call SetHeroesFlee(true)                    //设置英雄生命值少时自动逃跑   
    call SetHeroesTakeItems(true)               //设置英雄自动捡物品   
    call SetIgnoreInjured(true)                 //在集结部队进攻时,忽略生命值低于50%的单位   
    call SetRandomPaths(true)                   //增加AI的选择目的地的随机性        
    call CreateCaptains()                       //创建攻击组   
    call ShareEverythingWithTeamAI ()             //可以和AI分享物品等
    call StartThread(function attack_loop)      // 开始线程,运行(function attack_loop)   
    call StartThread(function check_hp)         // 开始线程,运行(function check_hp)
    call StartThread(function buy_item)         // 开始线程,运行(function buy_item)  
    call StartThread(function attack)           // 开始线程,运行(function attack)
endfunction



function setup_force takes nothing returns nothing  //选取英雄
     local unit u=null  
     call GroupEnumUnitsOfPlayer(udg_g,ai_player,null)     //选取AI玩家的所有单位
     loop  
            set u=FirstOfGroup(udg_g) //设置u是单位组的第一个单位
            exitwhen u==null          //当u为没有单位时
            if IsUnitType(u,UNIT_TYPE_HERO)==true then  //如果单位u是英雄
                set aihero=u            //设置aihero就是英雄了  
            endif  
            call GroupRemoveUnit(udg_g,u)            //移除单位u后,单位组内就没有u这个单位了  
     endloop  
endfunction  



function setup_force takes nothing returns nothing          //AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组  
    local unit u=null
    local integer i=1
    call RemoveInjuries()
    call InitAssault()             //初始化攻击队伍  
    if (GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_CAP)-80)!=hero_num then
        call GroupEnumUnitsOfPlayer(udg_g,ai_player,null)     //选取AI玩家的所有单位  
        loop
            exitwhen i>hero_num
            call GroupRemoveUnit(udg_g,aihero<i>)
            set i=i+1
        endloop     
        loop
            set u=FirstOfGroup(udg_g)
            exitwhen u==null
            if IsUnitType(u,UNIT_TYPE_HERO)==true then
                set hero_num=hero_num+1
                set aihero[hero_num]=u            //设置aihero[1~n]=u   
            endif
            call GroupRemoveUnit(udg_g,u)            //移除单位u  
        endloop
        call GroupClear(udg_g)         //清楚单位组  
    endif
    set i=1
    loop
        exitwhen i>hero_num
        if GetUnitState(aihero<i>,UNIT_STATE_LIFE)/GetUnitState(aihero<i>,UNIT_STATE_MAX_LIFE)>0.15 then //选取英雄生命百分比大于15%的(radio是用于判断生命比的整数)  
            call AddAssault(1,GetUnitTypeId(aihero<i>))  //英雄加入攻击组  
        endif
        set i=i+1
    endloop
endfunction
function start_attack takes unit target returns nothing      //开始攻击  
    local integer index=0
    loop
        exitwhen CaptainRetreating() and flee   //(如果队长逃跑 and 逃跑 是真的)就退出  
        exitwhen ratio==0
        exitwhen not UnitAlive(target)          //(如果target不是存活的)就退出  
        exitwhen UnitInvis(target) and not IsUnitDetected(target,ai_player)    //(如果单位隐形 and 单位侦查)就退出   
        call AttackMoveKill(target)      // 攻 击 移 动 直 到 杀 死  target  
        call Sleep(3)                    //停止3秒  
        if index>=5 then
            set index=0
            call setup_force()           //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组  
        endif
        set index=index+1
    endloop                             //实际上此loop的功能是每3秒选取英雄去攻击,逃跑的话就停止  
    set index=0
    loop
        exitwhen not CaptainInCombat(true)  //当队长不在战斗时就退出  
        call Sleep(2)                       //停止3秒
        if index>=8 then
            set index=0
            call setup_force()               //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
        endif
        set index=index+1
    endloop                              //实际上此loop的功能是每2秒队长在战斗时选取英雄进入攻击组
endfunction
function attack_sequence takes nothing returns nothing      //战斗顺序(此函数实际是寻找敌人,先寻找敌人的分基地,没有就主基地,找不到就去MF)  
    local unit target=null
    local unit u=null
    if ally then                             //如果ally是真的 ,就做下面动作  
        set target=GetAllianceTarget()       //设置target是同盟的主基地  
        if target!=null then                 //如果同盟的主基地存在  ,就做下面动作  
            set attack_enemy=true            //设置攻击敌人开始  
            call setup_force()               //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
            call start_attack(target)        //调用开始攻击target的函数  
            call SetAllianceTarget(null)     //  
            set attack_enemy=false           //设置攻击敌人关闭
            return                           //跳过下列动作  
        endif
    endif
    if count>100 and GetRandomInt(0,200+count)>300 then       //如果count大于100 and 随机整数0或200+count大于300 就做下列动作  
        set u=CreateUnitAtLoc(ai_player,'h000',start_loc,270) //设置u是新建的单位在开始点  
        set target=GetEnemyExpansion()                        //设置target是敌人的分基地  
        if target!=null then                                  //*如果target存在就做下面动作  
            call KillUnit(u)                                  //杀死u  
            call SetAllianceTarget(target)                    //  
            call setup_force()                                //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组  
            call start_attack(target)                         //调用开始攻击target的函数
            return                                            //跳过下列动作  
        else                                                  //*如果target不存在就做下面动作
            call StartGetEnemyBase()                          //开始寻找敌人基地  
            loop
                exitwhen not WaitGetEnemyBase()               //当不寻找敌人的时候就退出循环  
                call Sleep(1)                                   
            endloop                                           //实际上是每一秒都判断是否寻找的英雄
            set target=GetEnemyBase()                         //设置target时敌人的主基地  
            call KillUnit(u)                                  //杀死u
        endif
        set u=null
        if target != null then                                 //如果target不等于没有,就做下列动作  
            set attack_enemy=true                              //设置攻击敌人开始
            call SetAllianceTarget(target)                     //
            call setup_force()                                 //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
            call start_attack(target)                          //调用开始攻击target的函数
            set attack_enemy=false                             //设置攻击敌人关闭
            return                                             //跳过下列动作  
        endif
    endif
    set target=GetCreepCamp(0,R2I(5*hero_num*ratio),false)     //设置target是中立敌对单位的营地(中立单位最小的等级为 0,最大为5*英雄总数量*ratio,没有飞行单位)  
    if target!=null then                                       //如果target存在,就做下列动作  
        call SetAllianceTarget(target)                         //
        call setup_force()                                     //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
        call start_attack(target)                              //调用开始攻击target的函数
        set finishMF=true                                      //设置正在MF 为 真(MF是指打中立怪升级)  
        return                                                 //跳过下列动作  
    endif
    if GetRandomInt(1,2)==1 then                               //随机整数1或2等于1就做下列动作  
        set target=GetCreepCamp(0,R2I(8*hero_num*ratio),false) //设置target是中立敌对单位的营地
        if target!=null then                                   //如果target存在,就做下列动作
            call SetAllianceTarget(target)                     //
            call setup_force()                                 //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
            call start_attack(target)                          //调用开始攻击target的函数
            set finishMF=true                                  //设置正在MF 为 真(MF是指打中立怪升级)
        endif
    endif
    call Sleep(10)                                             //停止10秒  
endfunction
function attack_loop takes nothing returns nothing
    local integer index=0
    call SetCaptainHome(0,GetLocationX(start_loc),GetLocationY(start_loc))  //设置组在家的点<组,x坐标,y坐标>
    call SetCaptainHome(1,GetLocationX(start_loc),GetLocationY(start_loc))  //设置组在家的点<组,x坐标,y坐标>, 组的参数: ATTACK_CAPTAIN = 1; 攻击组 DEFENSE_CAPTAIN = 2; 防御组 BOTH_CAPTAINS = 3 攻击和防御组;
    loop
        call Sleep(3)                                                        //停止3秒(实际上是进入循环每3秒做下列动作一次)
        exitwhen GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_CAP)>80 //当AI玩家食物多于80就退出循环  
    endloop
    call Sleep(2)                            //停止2秒  
    call setup_force()                       //命令AI玩家开始寻找生命大于15%可以攻击的英雄进入攻击组
    loop
        set index=1
        loop
            call Sleep(1)                                //停止1秒                              
            exitwhen finishMF and not flee               //当正在MF的时候 and 不逃跑为真的时候 退出 循环  
            call Sleep(1)                                //停止1秒
            exitwhen not CaptainRetreating() and ratio>0 //当队长不逃跑的时候 and ratio大于0的时候退出循环  
            exitwhen index>=10
            set index=index+1
        endloop
        if finishMF then                  //如果正在MF,就做下列动作  
            set finishMF=false            //设置不MF  
        endif
        if flee then                      //如果正在逃跑,就做下列动作
            call Sleep(25-ratio*20)       //停止25-ratio*20秒 (radio是用于判断生命比的整数)  
        endif
       call attack_sequence()              //调用攻击函数  
    endloop
endfunction
function check_hp takes nothing returns nothing   //检测Hp  
    local integer i=0
    local real x=0
    local real y=0
    local real z=0
    local real r1=0
    local real r2=0
    local unit u=null
    loop
        call Sleep(3)                            //停止3秒(实际上是进入循环每3秒做下列动作一次)  
        set u=GetCreepCamp(0,0,false)            //设置u是中立敌对的目标  
        set i=1
        set x=0
        set y=0
        set z=0
        loop
            exitwhen i>hero_num                   //当i大于总英雄人数是就退出循环  
            set r1=GetUnitState(aihero<i>,UNIT_STATE_LIFE)     //设置r1是英雄i号的现在生命值   (i=1,2.3,......)  
            set r2=GetUnitState(aihero<i>,UNIT_STATE_MAX_LIFE)  //设置r2是英雄i号的最大生命值  (i=1,2.3,......)
            set x=x+r1                          //设置x等于x+r1,即循环后所有英雄总的生命值  
            set y=y+r2                          //设置y等于x+r2,即循环后所有英雄总的最大生命值
            if r1>0 then                        //如果英雄的生命值大于0,就做下列动作  
                set z=z+r2                      //设置z等于z+r2,即循环后所有活着的英雄总的最大生命值
            endif
            set i=i+1
        endloop
        if z>0 then                            //如果Z大于0做下列动作  
            set ratio=x/y                      //设置ratio等于x/y,即所有英雄现在生命值和最大生命值的比  
            if x/z<0.5 then                    //如果所有英雄现在生命值和最大生命值的比  小于 0.5,就做下列动作  
                call SetGroupsFlee(true)       //设置队伍可以逃跑
                set flee=true                  //设置队伍可以逃跑
            else                                
                call SetGroupsFlee(false)      //如果不是的话,就 设置队伍不能逃跑
                set flee=false                 //设置队伍现在不逃跑
            endif                                
        else                                   //如果Z小于0做下列动作
            set ratio=0                        //设置radio为0  
            call SetGroupsFlee(true)           //设置队伍可以逃跑  
            set flee=true                      //设置队伍现在正在逃跑
        endif                                  //实际上每三秒就判断生命值  
        if attack_enemy then
            call SetGroupsFlee(true)           //如果攻击敌人的话  
            set flee=true                      //设置队伍可以逃跑
        endif
        if count<200 then
            set count=count+1
        endif                                  //实际上每三秒就设置count+1  
    endloop
endfunction



function check_hp takes nothing returns nothing
    local real r1=0  
    local real r2=0  
    loop  
        call Sleep(1)                            //停止1秒  
        set r1=GetUnitState(aihero,UNIT_STATE_LIFE)     //设置r1是英雄的现在生命值      
        set r2=GetUnitState(aihero,UNIT_STATE_MAX_LIFE)  //设置r2是英雄的最大生命值
        set ratio=r1/r2   
        if radio>0.3 then  
            set flee=flase          //设置逃跑为flase  
        else
            set flee=ture           //设置逃跑为false
            set buyitem=false       //设置购买物品为false
            set kabing=false        //设置卡兵为false   
            set attack_enemy        //设置攻击敌人为false     
            call IssuePointOrder( GetTriggerUnit(), "move", -2843.00, -3147.00 )  //命令英雄回家 ,-2843.00, -3147.00是地图中家的坐标                                      
        endif   
    endloop  
endfunction

function isunithaveitem takes unit whichUnit integer itemId returns boolean
      local integer index=0
      loop
        set index=index+1
        if (UnitItemInSlot(whichUnit, index) != null) and (GetItemTypeId(UnitItemInSlot(whichUnit, index)) == itemId) then//判断是否有这样物品
            return ture //有就返回ture
        endif
        set index = index + 1
        exitwhen index >5
      endloop
      return false//没有就返回false
endfunction  

function UnithaveitemCount takes unit whichUnit returns integer
    local integer index = 0
    local integer count = 0 //记录物品数量
    loop
        if (UnitItemInSlot(whichUnit, index) != null) then//如果第几个物品栏不为空
            set count = count + 1//记录物品数量+1
        endif
        set index = index + 1
        exitwhen index >5
    endloop
    return count
endfunction  

function buyloop takes unit hero,unit Store,item whichitem returns nothing//监视英雄买东西
      set buyitem=ture //设置买东西为ture
      loop
         call IssueTargetOrderById( store, 852566, aihero() )   //852566是选择动作的ID ,命令中立商店选择英雄
         call IssueNeutralImmediateOrderById( ai_player, store, GetItemTypeId(whichitem)) //命令电脑玩家在中立商店购买医疗剂
         call IssuePointOrderByIdLoc( aihero, 851986, GetUnitLoc(store) )//英雄移动到中立商店
         call Sleep(1)
         exitwhen isunithaveitem( aihero,GetItemTypeId(whichitem))//英雄买到了退出循环
      endloop
      set buyitem=false//设置买东西为false
endfunction

function function buy_item takes nothing returns nothing
     loop
     if (not flee and not kabing)and (not attack_enemy and not useskills) then //如果flee为flase 和 kabing为false 和 attack_enemy为false
       if UnithaveitemCount(aihero)<6 then //如果英雄携带物品少于6
        if GetPlayerState(ai_player, PLAYER_STATE_RESOURCE_GOLD)>100 and not isunithaveitem( aihero,'hslv') then//如果玩家的金钱大于100和英雄没有医疗剂
            call buyloop(aihero,gg_unit_ngme_0003,'hslv')//调用上面监视英雄买东西的函数,参数英雄,商店,物品)
        endif
       endif  
       else  
          setbuyitem=false  
     endif
     call sleep(5)
     endloop
endfunction

function attack takes unit u returns nothing
      loop
      if (not buyitem and not skills) and (not flee and not kabing) then
      //这里设置动作
      call Sleep(1)
      endloop
endfunction

function GetWeakestUnit takes unit center,real range returns unit //得到一个单位组里最弱的单位
        local unit temp     //设置局部变量单位temp,用于记录单位组中存活的单位
        local unit weakest  //设置局部变量单位temp,用于记录单位组嫩生命值最少的单位
        local group g=CreateGroup() //建立一个单位组,用于记录全部单位
        local group group=CreateGroup()//建立一个单位组,这个单位组用于记录存活非英雄单位
        call  GroupEnumUnitsInRange(g,GetUnitX(center),GetUnitY(center),range,null)  //将英雄范围内的单位全送进单位组
        call  GroupRemoveUnit(g,center) //移除英雄自己出单位组,因为不可能自己杀自己吧
        loop //进入循环
            set  weakest=FirstOfGroup(g) //设置weakest是全部单位组内第一个单位
            exitwhen weakest==null //当weakest为没有单位时退出循环
            if GetUnitState(weakest,UNIT_STATE_LIFE)>0 and IsUnitType(weakest, UNIT_TYPE_HERO) == false then
                 GroupAddUnit(group, weakest) //如果weakest是存活非英雄单位,就进入单位组group
            endif
            call  GroupRemoveUnit(g,weakest) //移除weakest出单位组
        endloop
        loop
            set  temp=FirstOfGroup(group) //设置temp是group的第一个单位
            exitwhen temp == null //当temp为没有单位时退出
                if GetUnitState(weakest,UNIT_STATE_LIFE)>GetUnitState(temp,UNIT_STATE_LIFE) then
                    set weakest = temp//如果weakest得生命值大于temp就设置weakest为temp
                endif
            call GroupRemoveUnit(group,temp)//删除单位组移除单位temp出group
        endloop
                call DestroyGroup(g)     //删除单位组
                call DestroyGroup(group)     //删除单位组
                set temp = null          //设置temp为没有单位
                set g = null             //设置g为空单位组
        return weakest
endfunction

function moverandom takes unit h returns nothing
      local real x = GetUnitX(h)  
      local real y = GetUnitY(h)
      local rect i = Rect(x-250, y-250, x+250, y+250)
      IssuePointOrderByIdLoc( aihero, 851986, Location(GetRandomReal(GetRectMinX(i), GetRectMaxX(i)), GetRandomReal(GetRectMinY(i), GetRectMaxY(i))))
      //命令移动到矩形区域内随机点   
function attack takes nothing returns nothing
      local unit target
      loop
      if (not buyitem and not useskills) and (not flee and not kabing) then
         if GetEnemyBingInRangeCount(aihero,500)> 0 and GetAllyBingInRangeCount(aihero,500)<=0
           call IssuePointOrder( aihero, "move", -2843.00, -3147.00 )  //命令英雄回家 ,-2843.00, -3147.00是地图中家的坐标
      else
         set target=GetWeakestUnit(aihero,500)//设置target是单位组内最弱的单位
          if (target!=null) then  
            set attack_enemy=ture //设置正在攻击  
            call IssueTargetOrder(aihero,"attack",target)//命令英雄攻击target
            call Sleep(1)
            set attack_enemy=false//设置不在攻击了
            set target=null
          else  
              call moverandom //如果target不存在,就命令他移动到随机点   
          endif
      endif
      call Sleep(1)
      endloop
endfunction

function attack takes nothing returns nothing
      local unit target
      loop
      if (not buyitem and not useskills) and (not flee and not kabing) then
         if GetEnemyBingInRangeCount(aihero,500)> 0 and GetAllyBingInRangeCount(aihero,500)<=0
           call IssuePointOrder( GetTriggerUnit(), "move", -2843.00, -3147.00 )  //命令英雄回家 ,-2843.00, -3147.00是地图中家的坐标
      else
         set target=GetWeakestUnit(aihero,500)//设置target是单位组内最弱的单位
          if (target!=null) then  
            set attack_enemy=ture //设置正在攻击  
            call IssueTargetOrder(aihero,"attack",target)//命令英雄攻击target
            call Sleep(1)
            set attack_enemy=false//设置不在攻击了
            set target=null
          else  
              call moverandom //如果target不存在,就命令他移动到随机点   
          endif
         set target=GetWeakestUnit(aihero,500)//设置target为范围内的英雄
          if GetEnemyHeroInRangeCount(aihero,500)!=0 then
              SetPlayerAbilityAvailable( Player(0), 'AHtb', true )//允许使用技能
              call IssueTargetOrderById(aihero, 852095, target )//命令使用技能风暴之锤
              SetPlayerAbilityAvailable( Player(0), 'AHtb', true )//禁止使用技能了
              set target=null
           endif
      endif
      call Sleep(1)
      endloop
endfunction

function RangeToLoc takes unit u,location Target returns real//到点的距离
  local real X=GetLocationX(Target)-GetUnitX(u)
  local real Y=GetLocationY(Target)-GetUnitY(u)
  return(SquareRoot(X*X+Y*Y))
endfunction
function RangeToUnit takes unit u,unit Target returns real//到单位的距离
  local real X=GetUnitX(Target)-GetUnitX(u)
  local real Y=GetUnitY(Target)-GetUnitY(u)
  return(SquareRoot(X*X+Y*Y))
endfunction

function IsUnitHero takes unit u returns boolean//判断单位是否英雄,
  return((IsUnitType(u,UNIT_TYPE_HERO))and(IsUnitIllusion(u)==false))//判断单位是否英雄,是否镜像
endfunction
function IsNotHero takes unit u returns boolean//判断单位是否英雄
return(IsUnitHero(u)==false)
endfunction
function IsMoving takes unit u returns boolean//判断单位是否移动
  local integer Order=GetUnitCurrentOrder(u)
  return(Order==OrderId("move"))or(Order==OrderId("AImove"))or(Order==OrderId("blink"))or(Order==OrderId("patrol"))or(Order==OrderId("attack"))or(Order==OrderId("smart"))     
endfunction

function GetExtSoldierToBarrack takes unit Hero,点real Radius returns unit//得到单位离基地距离最长的单位
  local real R
  local real FR=0
  local unit u=null
  local unit ru=null
  local location Loc=GetUnitLoc(Hero)
  local player p=GetOwningPlayer(Hero)
  local group g=CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g,Loc,Radius,null)//选取点圆范围的所有单位
    call RemoveLocation(Loc)//清除点?
    set Loc=null
    loop
      set u = FirstOfGroup(g)
      exitwhen u == null
      if(IsMoving(u))and(IsNotHero(u))then                                  //用于判断单位是移动的非英雄单位
       set R=RangeToLoc(u,GetUnitLoc(gg_unit_hatw_0022)) //设置R为小兵到塔的距离
        if R>FR then  
          set FR=R                      //设置小的FR为R,即FR现在为最大距离
          set ru=u                      //设置ru为最大距离的单位
        endif
      endif
      call GroupRemoveUnit(g,u)         //移除单位u
    endloop
    call DestroyGroup(g)
    set g=null
  return ru
endfunction
function SmartToLoc takes unit u,location loc returns nothing//命令英雄点击到点
call IssuePointOrderByIdLoc(u,851971,loc)
endfunction

function GetUnitFrontLoc takes unit Target,real Range returns location//得到单位前的点
  local real rad
    if(Target!=null)then
      set rad=Deg2Rad(GetUnitFacing(Target)) //getunitfacing是面向角度
      return(Location(Range*Cos(rad)+GetUnitX(Target),Range*Sin(rad)+GetUnitY(Target)))//location将坐标转换为点
    endif
  return null
endfunction

function cccc takes nothing returns nothing  
  local unit u=GetExtSoldierToBarrack(gg_unit_U00A_0006,600)
    call SmartToLoc(gg_unit_U00A_0006,GetUnitFrontLoc(u,190))//命令英雄点击到点
    call Sleep(0.25)                                                //卡一次停顿0.25秒
  set u=null
endfunction

//===========================================================================
function kabing takes nothing returns nothing
      local timer t==CreateTimer()  
      call  timerstart(t,0.45,ture,function cccc) //每0.45卡一次兵
      loop
      if GetEnemyBingInRangeCount(aihero,300)>0 then
      call DestroyTimer(t)
      set t=null
      return //跳过剩余动作,可以跳过循环
      endif
      call Sleep(0.45)
      endloop
endfunction

loop //开始进入循环
        loop  
            call Sleep(1)                                //停止1秒                              
            exitwhen ((not buyitem and not flee)and not useskills) and ((not kabing and radio=<0.3) and ( GetUnitCurrentOrder(aihero) == OrderId("stop"))   //当不在购买物品的时候,血少逃跑的时候和卡兵的时候,单位停止的时候,不使用技能时退出循环
        endloop  
        call IssueNeutralPointOrder( Player(0), GetTriggerUnit(), "attack", 2817.00, 2555.00 )//命令攻击到坐标2817.00, 2555.00
        if GetAllyBingInRangeCount(aihero,500)>0 and  GetEnemyBingInRangeCount(aihero,500)<0 then
        call kabing()
        endif
        call Sleep(1)
    endloop
回复

使用道具 举报

发表于 2010-8-8 18:00:27 | 显示全部楼层

回 7楼(bloodyliao) 的帖子

这个是wow8转来的吧!
回复

使用道具 举报

发表于 2010-8-8 19:22:41 | 显示全部楼层
ai在写法上有两种,ai与j的写法。专用的ai函数写法会的人不多,相关教程也就那么两个而已。真三的就是纯ai
j版就是用j写ai,描述一些什么状态做什么而已,实质上ai函数在多线程上以及条件执行(满足一些状态就做什么)比j强很多,(j中要timer循环判断的)。dota那版就是j的。
ai版要执行ai,是单独文件,j版的直接写在脚本里,
回复

使用道具 举报

 楼主| 发表于 2010-8-8 19:48:54 | 显示全部楼层
那么,为什么我用触发执行AI却没效果??
我初始化使选取所有非用户玩家使用对战AI,然后选择我导入的DOTA.AI文件了啊???
回复

使用道具 举报

发表于 2010-8-8 21:28:49 | 显示全部楼层
ai是专用的,英雄的技能类型什么都定死了,你自己的图必然无法执行
回复

使用道具 举报

 楼主| 发表于 2010-8-9 08:04:24 | 显示全部楼层
那么,普通的A小兵什么的,为什么也无法执行?
回复

使用道具 举报

发表于 2010-8-9 08:07:50 | 显示全部楼层

回 9楼(疯人¢衰人) 的帖子

口说无凭,上演示~呦呦呦!
回复

使用道具 举报

 楼主| 发表于 2010-8-9 08:19:23 | 显示全部楼层
演示在地下室啊!!!
回复

使用道具 举报

发表于 2010-8-9 09:07:42 | 显示全部楼层
set start_loc=GetStartLocationLoc(GetPlayerStartLocation(Player(GetAiPlayer()-10)))
这句代码也就是说:设置主基地为该玩家序列前10的玩家的开始点。
也就是如果是玩家11,那么主基地就是玩家1的开始点.
也就是如果是玩家12,那么主基地就是玩家2的开始点.
如果是玩家3,那么就是玩家-7.......这样电脑应该会直接爆掉吧......
可见这应该是专属的AI吧,只能供一个玩家在特定条件的地图中使用.......

还有,上面你的脚本错了竟然有两个main事件
回复

使用道具 举报

发表于 2010-8-9 09:12:26 | 显示全部楼层
诶,打开AI文件看了一眼,发现。。。你传的内容根本不一样
唉~~~受不了你


那么,发现:
一:该AI必须要在你发布0信号时才开始选取英雄(不是“选英雄”,是选取已有英雄加入攻击组),发布1信号时开始攻击。(就是说你要自己在选完英雄后对它发AI信号)否则它是不会动的

二:call IssuePointOrder( GetTriggerUnit(), "move", -7700.00, -6307.00 )  //命令英雄回家 ,-2843.00, -3147.00是地图中家的坐标

三:call IssueNeutralPointOrder( Player(0), GetTriggerUnit(), "attack", 181.00, -161.00 )//命令攻击到坐标2817.00, 2555.00 ,该坐标是敌人老家

四:该AI在某些地方根本没有代码,说明它根本就不是给你移植的!!!
[jass]
function attack takes unit u returns nothing
      loop
      if (not buyitem and not skills) and (not flee and not kabing) then
      //这里设置动作
      call Sleep(1)
      endloop
endfunction
[/jass]五:对该AI进行一次DEBUG.........结果发现了一堆语法错误............这哪里是DOTA AI啊.....

结论:该AI只是给你学习原理的,最好的移植办法就是看懂之后自己根据实际情况修改。
而且还有人做了详细的解释,那么你就不要想偷懒了,自己研究吧。。。
回复

使用道具 举报

 楼主| 发表于 2010-8-9 10:53:09 | 显示全部楼层
这样子啊……
什么叫【发布0信号时】?
要我输入0?
还有,这个是别人传给我的,说导入就能用……
回复

使用道具 举报

 楼主| 发表于 2010-8-9 10:55:22 | 显示全部楼层
对了,哀怨……
还有啊,他还给我发了个真三的AI……
顺便传上来大家看看……
记事本打开是乱码啊?

zhensan.rar

39 KB, 下载次数: 19

回复

使用道具 举报

发表于 2010-8-9 11:44:25 | 显示全部楼层
引用第17楼bloodyliao于2010-08-09 10:53发表的  :
这样子啊……
什么叫【发布0信号时】?
要我输入0?
还有,这个是别人传给我的,说导入就能用……   
[trigger]AI - 对 玩家1(红色) 发送AI命令:(0, 0)[/trigger]
引用第18楼bloodyliao于2010-08-09 10:55发表的  :
对了,哀怨……
还有啊,他还给我发了个真三的AI……
顺便传上来大家看看……
记事本打开是乱码啊?

既然他说导入就能用,那么你就让他教你吧。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-6-27 14:52 , Processed in 0.409960 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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