Debian Codegraph @

scripts/ais/blitz.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 -- blitz.lua - Define the blitz AI.
11 --
12 -- (c) Copyright 2000-2007 by Lutz Sammer, Jimmy Salmon
13 -- and Tejay Penfold
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: blitz.lua 626 2007-10-14 18:10:03Z timberdragon $
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_blitz()
55 AiState[AiPlayer()] = {
56 loop_pos = 1,
57 loop_start = nil,
58 build_order = nil,
59 }
60 end
61
62 local function GetBuildOrder()
63 local order = {}
64
65 if (not AiHotSpotExists()) then
66 order[1] = "unit-powerplant"
67 order[2] = nil
68 elseif (Players[AiPlayer()].MagmaStored < 300) then
69 order[1] = "unit-magmapump"
70 order[2] = "unit-powerplant"
71 else
72 order[1] = "unit-powerplant"
73 order[2] = "unit-magmapump"
74 end
75
76 return order
77 end
78
79 local ai_funcs = {
80 function() AiDebug(false) return false end,
81
82 -- Build magma pump or power plant first depending on resources
83 function()
84 state.build_order = GetBuildOrder()
85 return AiNeed(state.build_order[1])
86 end,
87 function()
88 return AiWait(state.build_order[1])
89 end,
90 function()
91 if (state.build_order[2] ~= nil) then
92 return AiNeed(state.build_order[2])
93 else
94 return false
95 end
96 end,
97 function()
98 if (state.build_order[2] ~= nil) then
99 return AiWait(state.build_order[2])
100 else
101 return false
102 end
103 end,
104
105 function() return AiSet("unit-engineer", 3) end,
106 function() return AiNeed("unit-vault") end,
107 function() return AiNeed("unit-magmapump") end,
108 function() return AiWait("unit-vault") end,
109
110 function() return AiNeed("unit-camp") end,
111 function() return AiNeed("unit-nukepowerplant") end,
112 function() return AiNeed("unit-engineer") end,
113 function() return AiNeed("unit-engineer") end,
114 function() return AiNeed("unit-engineer") end,
115 function() return AiNeed("unit-engineer") end,
116 function() return AiNeed("unit-gturret") end,
117 function() return AiNeed("unit-gturret") end,
118 function() return AiNeed("unit-gturret") end,
119 function() return AiNeed("unit-vfac") end,
120 function() return AiNeed("unit-magmapump") end,
121 function() return AiNeed("unit-powerplant") end,
122 function() return AiNeed("unit-engineer") end,
123 function() return AiNeed("unit-magmapump") end,
124 function() return AiNeed("unit-powerplant") end,
125 function() return AiNeed("unit-vault") end,
126 function() return AiNeed("unit-engineer") end,
127 function() return AiNeed("unit-magmapump") end,
128 function() return AiNeed("unit-powerplant") end,
129 function() return AiNeed("unit-engineer") end,
130 function() return AiNeed("unit-gturret") end,
131 function() return AiWait("unit-gturret") end,
132 function() return AiSet("unit-engineer", 4) end,
133
134 -- Defense
135 function() return AiForce(0, {"unit-assault", 20}) end,
136 function() return AiWaitForce(0) end,
137
138 function() return AiNeed("unit-powerplant") end,
139 function() return AiNeed("unit-magmapump") end,
140 function() return AiNeed("unit-camp") end,
141 function() return AiNeed("unit-gturret") end,
142 function() return AiNeed("unit-magmapump") end,
143 function() return AiNeed("unit-engineer") end,
144 function() return AiNeed("unit-powerplant") end,
145 function() return AiNeed("unit-gturret") end,
146 function() return AiNeed("unit-magmapump") end,
147 function() return AiNeed("unit-engineer") end,
148 function() return AiNeed("unit-powerplant") end,
149 function() return AiNeed("unit-vault") end,
150 function() return AiNeed("unit-nukepowerplant") end,
151 function() return AiNeed("unit-engineer") end,
152 function() return AiNeed("unit-gturret") end,
153 function() return AiNeed("unit-engineer") end,
154 function() return AiNeed("unit-engineer") end,
155 function() return AiSleep(150*GameSettings.Difficulty) end,
156
157 -- Attack wave
158 function() return AiForce(1, {"unit-assault", 5}) end,
159 function() return AiWaitForce(1) end,
160 function() return AiSleep(50*GameSettings.Difficulty) end,
161 function() return AiAttackWithForce(1) end,
162
163 -- Bigger attack wave
164 function() return AiNeed("unit-magmapump") end,
165 function() return AiForce(1, {"unit-assault", 40, "unit-grenadier", 10, "unit-tank", 5}) end,
166 function() return AiWaitForce(1) end,
167 function() return AiAttackWithForce(1) end,
168
169 -- Bigger attack wave
170 function() return AiNeed("unit-magmapump") end,
171 function() return AiForce(2, {"unit-assault", 60, "unit-grenadier", 20, "unit-tank", 10}) end,
172 function() return AiWaitForce(2) end,
173 function() return AiAttackWithForce(2) end,
174
175 -- ============================================================
176
177 function()
178 LocalDebugPrint("is starting loop.");
179 state.loop_start = state.loop_pos;
180 return false
181 end,
182
183 function() return AiForce(1, {"unit-assault", 20,
184 "unit-grenadier", 8,
185 "unit-bazoo", 8}) end,
186 function() return AiWaitForce(1) end, -- wait until attack party is completed
187 function() return AiSleep(50*GameSettings.Difficulty) end,
188 function() return AiAttackWithForce(1) end,
189
190 function()
191 LocalDebugPrint("Reached the end of AI script and will loop");
192 state.loop_pos = state.loop_start - 1; -- AiLoop will immediately increment it.
193 return false
194 end,
195 }
196
197 local function AiBlitz()
198 LocalDebugPrint("Script position " .. AiState[AiPlayer()].loop_pos);
199 return AiLoop(ai_funcs)
200 end
201
202 this_ai_type = {
203 Ident = "ai-blitz",
204 Name = _("Blitz"),
205 Init = InitAiScripts_blitz,
206 EachSecond = AiBlitz,
207 }
208 DefineAiType(this_ai_type)