Debian Codegraph @

scripts/ais/air_attack.lua

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