|
发表于 2009-11-15 17:57:22
|
显示全部楼层
这里是一个我刚整的建造\\攻击双线程AI演示。
进入地图后按ESC可与AI共享控制,可以进一步看到AI工作的细节。
[jass]
function WorkerAssignment takes nothing returns nothing
local integer wg
local integer ww
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"采矿、建造、生产线程开始...")
loop
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"重新分配采集工作,重置中...")
call ClearHarvestAI()
set wg=GetUnitCountDone('nmpe')
if (wg<6) then
if(wg<2) then
call HarvestGold(0,wg)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"奴隶不足2名,全部分去采矿...")
else
call HarvestGold(0,wg-1)
call HarvestWood(0,1)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"奴隶不足6名,留一人伐木,其余全部分去采矿...")
endif
else
set ww=wg-5
set wg=5
call HarvestGold(0,wg)
call HarvestWood(0,ww)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"5人采矿,其余全部伐木...")
endif
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"重新分配建造、训练工作,重置中...")
call InitBuildArray()
if (GetPlayerState(ai_player, PLAYER_STATE_RESOURCE_FOOD_CAP)>=GetPlayerState(ai_player, PLAYER_STATE_FOOD_CAP_CEILING)) then
//call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"已达食物上限,不再建造珊瑚礁...")
else
if ((GetPlayerState(ai_player, PLAYER_STATE_RESOURCE_FOOD_CAP)-GetPlayerState(ai_player, PLAYER_STATE_RESOURCE_FOOD_USED))<5) then
call SetBuildUnit(GetUnitCount('nnfm')+1,'nnfm')
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"建筑计划:食物紧张,将珊瑚礁纳入建筑计划...")
endif
endif
if (GetUnitCount('nmpe')<10) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"奴隶不足10人,继续去抓!")
call SetBuildUnit(10,'nmpe')
endif
if (GetUnitCount('nnsg')<3) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"建筑计划:我们需要三个兵营,将产卵地纳入建筑计划...")
call SetBuildUnit(GetUnitCount('nnsg')+1,'nnsg')
endif
if ((GetUnitCountDone('nnsg')>0) and (GetPlayerState(ai_player, PLAYER_STATE_RESOURCE_FOOD_USED)<=GetPlayerState(ai_player, PLAYER_STATE_FOOD_CAP_CEILING)-3)) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"训练计划:所有兵营暴毒龙...")
call SetBuildUnit(30,'nsnp')
endif
call Sleep( 2 )
endloop
endfunction
function AttackAssignment takes nothing returns nothing
local unit target
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"攻击线程开始...")
call StaggerSleep( 0, 2 )
loop
if (GetUnitCountDone('nsnp')>=3) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000开始进行进攻准备...|r")
call InitAssaultGroup()
call SetAssaultGroup(GetUnitCountDone('nsnp'),GetUnitCountDone('nsnp'), 'nsnp' )
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000队员名单生成完毕,尝试获取敌方分基地位置...|r")
set target = GetEnemyExpansion()
if (target == null) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000找不到敌方分基地,尝试获取敌方主基地位置...|r")
call StartGetEnemyBase( )
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000获取中...|r")
loop
exitwhen (not WaitGetEnemyBase())
call SuicideSleep(1)
endloop
set target = GetEnemyBase()
endif
if (target != null) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000已定位敌方基地。开始集结队伍...|r")
call FormGroup( 5, false)
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000队伍集结完毕,开始进攻...|r")
call AttackMoveKill(target)
call SleepUntilAtGoal()
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000抵达目的地...|r")
call SleepInCombat()
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000战斗结束...|r")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1,"|cffff0000找不到敌人,放弃进攻...|r")
endif
endif
call Sleep( 1.0 )
endloop
endfunction
function main takes nothing returns nothing
call InitAI()
call CreateCaptains()
call Sleep(0.1)
call StartThread(function WorkerAssignment)
call StartThread(function AttackAssignment)
call PlayGame()
endfunction
[/jass] |
|