Debian Codegraph @

scripts/ais/zombies.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 -- zombies.lua
11 -- Define the AI that has the following philosophy:
12 -- constantly train and attack with as many simple assault units as possible,
13 -- no effort is done on expanding or building defenses.
14 -- This AI script is based on the "rush" AI.
15 --
16 -- (c) Copyright 2010 by Michiel van der Wulp
17 --
18 -- This program is free software; you can redistribute it and/or modify
19 -- it under the terms of the GNU General Public License as published by
20 -- the Free Software Foundation; either version 2 of the License, or
21 -- (at your option) any later version.
22 --
23 -- This program is distributed in the hope that it will be useful,
24 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
25 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 -- GNU General Public License for more details.
27 --
28 -- You should have received a copy of the GNU General Public License
29 -- along with this program; if not, write to the Free Software
30 -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 --
32 -- $Id: $
33 --
34
35 -- What we registered in AiTypes.
36 local this_ai_type
37
38 -- Same as AiState[AiPlayer()]. Valid only during AiLoop.
39 local state
40
41 local function AiLoop(funcs)
42 state = AiState[AiPlayer()]
43 while (true) do
44 local ret = funcs[state.loop_pos]()
45 if (ret) then
46 break
47 end
48 state.loop_pos = state.loop_pos + 1
49 end
50 return true
51 end
52
53 local function LocalDebugPrint(text)
54 -- DebugPrint(this_ai_type.Ident .. " player " .. AiPlayer() .. " " .. text)
55 end
56
57 local function InitAiScripts_zombies()
58 AiState[AiPlayer()] = {
59 loop_pos = 1,
60 loop_start = nil,
61 build_order = nil,
62 }
63 end
64
65 local function GetBuildOrder()
66 local order = {}
67
68 if (not AiHotSpotExists()) then
69 order[1] = "unit-powerplant"
70 order[2] = nil
71 elseif (Players[AiPlayer()].MagmaStored < 300) then
72 order[1] = "unit-magmapump"
73 order[2] = "unit-powerplant"
74 else
75 order[1] = "unit-powerplant"
76 order[2] = "unit-magmapump"
77 end
78
79 return order
80 end
81
82 local ai_funcs = {
83 -- Build magma pump or power plant first depending on resources
84 function()
85 state.build_order = GetBuildOrder()
86 return AiNeed(state.build_order[1])
87 end,
88 function()
89 return AiWait(state.build_order[1])
90 end,
91 function()
92 if (state.build_order[2] ~= nil) then
93 return AiNeed(state.build_order[2])
94 else
95 return false
96 end
97 end,
98 function()
99 if (state.build_order[2] ~= nil) then
100 return AiWait(state.build_order[2])
101 else
102 return false
103 end
104 end,
105
106 function() return AiSet("unit-engineer", 2) end,
107 function() return AiNeed("unit-vault") end,
108 function() return AiNeed("unit-magmapump") end,
109 function() return AiWait("unit-vault") end,
110
111 function() return AiNeed("unit-camp") end,
112 function() return AiWait("unit-camp") end,
113 function() return AiSet("unit-engineer", 3) end,
114
115 -- Defense
116 function() return AiForce(0, {"unit-assault", 4}) end,
117 function() return AiWaitForce(0) end,
118
119 function() return AiNeed("unit-powerplant") end,
120 function() return AiNeed("unit-magmapump") end,
121 function() return AiNeed("unit-camp") end,
122 function() return AiSleep((SyncRand(100)+100)*GameSettings.Difficulty) end,
123
124 -- Attack wave
125 function() return AiForce(1, {"unit-assault", 10}) end,
126 function() return AiWaitForce(1) end,
127 function() return AiSleep((SyncRand(50)+50)*GameSettings.Difficulty) end,
128 function() return AiAttackWithForce(1) end,
129
130 -- Bigger attack wave
131 function() return AiNeed("unit-magmapump") end,
132 function() return AiForce(1, {"unit-assault", 20, "unit-grenadier", 1}) end,
133 function() return AiWaitForce(1) end,
134 function() return AiAttackWithForce(1) end,
135
136 -- ============================================================
137
138 function()
139 LocalDebugPrint("is starting loop.");
140 state.loop_start = state.loop_pos;
141 return false
142 end,
143
144 function() return AiForce(1, {"unit-assault", SyncRand(20)+10,
145 "unit-grenadier", SyncRand(12)+1,
146 "unit-bazoo", SyncRand(12)+1}) end,
147 function() return AiWaitForce(1) end, -- wait until attack party is completed
148 function() return AiSleep((SyncRand(200)+30)*GameSettings.Difficulty) end,
149 function() return AiAttackWithForce(1) end,
150
151 function()
152 LocalDebugPrint("Reached the end of AI script and will loop");
153 state.loop_pos = state.loop_start - 1; -- AiLoop will immediately increment it.
154 return false
155 end,
156 }
157
158 local function AiZombies()
159 LocalDebugPrint("Script position " .. AiState[AiPlayer()].loop_pos);
160 return AiLoop(ai_funcs)
161 end
162
163 this_ai_type = {
164 Ident = "ai-zombies",
165 Name = _("Zombies"),
166 Init = InitAiScripts_zombies,
167 EachSecond = AiZombies,
168 }
169 DefineAiType(this_ai_type)