Debian Codegraph @

scripts/ais/rush.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 -- rush.lua
11 -- Define the AI that has the following philosophy:
12 -- constantly train and attack with as many units as possible,
13 -- no emphasis on expanding or building defenses. There could be multiple
14 -- rush AIs that try to attack with different units.
15 --
16 -- (c) Copyright 2000-2010 by Lutz Sammer and Jimmy Salmon
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: rush.lua 626 2006-11-25 18:10:03Z feb $
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_rush()
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 function() AiDebug(false) return false end,
84
85 -- Build magma pump or power plant first depending on resources
86 function()
87 state.build_order = GetBuildOrder()
88 return AiNeed(state.build_order[1])
89 end,
90 function()
91 return AiWait(state.build_order[1])
92 end,
93 function()
94 if (state.build_order[2] ~= nil) then
95 return AiNeed(state.build_order[2])
96 else
97 return false
98 end
99 end,
100 function()
101 if (state.build_order[2] ~= nil) then
102 return AiWait(state.build_order[2])
103 else
104 return false
105 end
106 end,
107
108 function() return AiSet("unit-engineer", 2) end,
109 function() return AiNeed("unit-vault") end,
110 function() return AiNeed("unit-magmapump") end,
111 function() return AiWait("unit-vault") end,
112
113 function() return AiNeed("unit-camp") end,
114 function() return AiWait("unit-camp") end,
115 function() return AiSet("unit-engineer", 3) end,
116
117 -- Defense
118 function() return AiForce(0, {"unit-assault", 4}) end,
119 function() return AiWaitForce(0) end,
120
121 function() return AiNeed("unit-powerplant") end,
122 function() return AiNeed("unit-magmapump") end,
123 function() return AiNeed("unit-camp") end,
124 function() return AiSleep(150*GameSettings.Difficulty) end,
125
126 -- Attack wave
127 function() return AiForce(1, {"unit-assault", 10}) end,
128 function() return AiWaitForce(1) end,
129 function() return AiSleep(50*GameSettings.Difficulty) end,
130 function() return AiAttackWithForce(1) end,
131
132 -- Bigger attack wave
133 function() return AiNeed("unit-magmapump") end,
134 function() return AiForce(1, {"unit-assault", 20, "unit-grenadier", 8}) end,
135 function() return AiWaitForce(1) end,
136 function() return AiAttackWithForce(1) end,
137
138 -- ============================================================
139
140 function()
141 LocalDebugPrint("is starting loop.");
142 state.loop_start = state.loop_pos;
143 return false
144 end,
145
146 function() return AiForce(1, {"unit-assault", 20,
147 "unit-grenadier", 8,
148 "unit-bazoo", 8}) end,
149 function() return AiWaitForce(1) end, -- wait until attack party is completed
150 function() return AiSleep(50*GameSettings.Difficulty) end,
151 function() return AiAttackWithForce(1) end,
152
153 function()
154 LocalDebugPrint("Reached the end of AI script and will loop");
155 state.loop_pos = state.loop_start - 1; -- AiLoop will immediately increment it.
156 return false
157 end,
158 }
159
160 local function AiRush()
161 LocalDebugPrint("Script position " .. AiState[AiPlayer()].loop_pos);
162 return AiLoop(ai_funcs)
163 end
164
165 this_ai_type = {
166 Ident = "ai-rush",
167 Name = _("Rush"),
168 Init = InitAiScripts_rush,
169 EachSecond = AiRush,
170 }
171 DefineAiType(this_ai_type)