
我是从这http://bbs.wow8.org/thread-152120-1-1.html帖子转来的 很详细,你可以看看.★1★main程序 + Shingo Jass Highlighter 0.41 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★2★全局变量 + Shingo Jass Highlighter 0.41 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 //玩家开始的地方 endglobals★3★功能程序 + Shingo Jass Highlighter 0.41 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) 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,UNIT_STATE_LIFE)/GetUnitState(aihero,UNIT_STATE_MAX_LIFE)>0.15 then //选取英雄生命百分比大于15%的(radio是用于判断生命比的整数) call AddAssault(1,GetUnitTypeId(aihero)) //英雄加入攻击组 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,UNIT_STATE_LIFE) //设置r1是英雄i号的现在生命值 (i=1,2.3,......) set r2=GetUnitState(aihero,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 收藏 分享 11 0 鱼妹 莫鱼
