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