1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
-- ____ _ __
-- / __ )____ _____ | | / /___ ___________
-- / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
-- / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
-- /_____/\____/____/ |__/|__/\__,_/_/ /____/
--
-- A futuristic real-time strategy game.
-- This file is part of Bos Wars.
--
-- air_attack.lua - Define a AI that needs many resources
-- and attacks through the air.
--
-- (c) Copyright 2010 by Michiel van der Wulp
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
-- $Id: air_attack.lua $
--
-- What we registered in AiTypes.
local this_ai_type
-- Same as AiState[AiPlayer()]. Valid only during AiLoop.
local state
local function AiLoop(funcs)
state = AiState[AiPlayer()]
while (true) do
local ret = funcs[state.loop_pos]()
if (ret) then
break
end
state.loop_pos = state.loop_pos + 1
end
return true
end
local function LocalDebugPrint(text)
-- DebugPrint(this_ai_type.Ident .. " player " .. AiPlayer() .. " " .. text)
end
local function InitAiScripts_air_attack()
AiState[AiPlayer()] = {
loop_pos = 1
}
end
local ai_funcs = {
function() AiDebug(false) return false end,
function() return AiNeed("unit-nukepowerplant") end,
function() return AiNeed("unit-magmapump") end,
function() return AiWait("unit-nukepowerplant") end,
function() return AiWait("unit-magmapump") end,
function() return AiSet("unit-engineer", 5) end,
function() return AiNeed("unit-magmapump") end,
function() return AiNeed("unit-magmapump") end,
-- but we do not wait for these ...
function() return AiForce(0, {"unit-bazoo", 4}) end,
function() return AiWaitForce(0) end,
function() return AiAttackWithForce(0) end,
function() return AiNeed("unit-cannon") end,
function() return AiSleep((SyncRand(600)+400) * GameSettings.Difficulty) end,
function() return AiNeed("unit-radar") end,
function() return AiWait("unit-radar") end,
function() return AiSleep((SyncRand(100)+100) * GameSettings.Difficulty) end,
function() return AiWait("unit-cannon") end,
-- Defense
function() return AiNeed("unit-aircraftfactory") end,
function() return AiWait("unit-jet") end,
function() return AiSleep((SyncRand(100)+100)*GameSettings.Difficulty) end,
-- Attack wave
function() return AiForce(2, {"unit-jet", 2}) end,
function() return AiWaitForce(2) end,
function() return AiSleep((SyncRand(70)+50)*GameSettings.Difficulty) end,
function() return AiAttackWithForce(2) end,
function() return AiNeed("unit-powerplant") end,
function() return AiNeed("unit-magmapump") end,
function() return AiSleep((SyncRand(60)+40)*GameSettings.Difficulty) end,
function()
LocalDebugPrint("Reached the end of AI script and will loop");
state.loop_pos = 0;
return false
end,
}
local function AiAirAttack()
LocalDebugPrint("Script position " .. AiState[AiPlayer()].loop_pos);
return AiLoop(ai_funcs)
end
this_ai_type = {
Ident = "ai-air_attack",
Name = _("Air attack"),
Init = InitAiScripts_air_attack,
EachSecond = AiAirAttack,
}
DefineAiType(this_ai_type)
|