forked from capt-t/EEScenarios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenario_01_waves.lua
executable file
·271 lines (254 loc) · 7.83 KB
/
scenario_01_waves.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
-- Name: Waves
-- Description: Waves of increasingly difficult enemies.
-- Type: Basic
-- Variation[Hard]: Difficulty starts at wave 5 and increases by 1.5 after the players defeat each wave. (Players are more quickly overwhelmed, leading to shorter games.)
-- Variation[Easy]: Makes each wave easier by decreasing the number of ships in each wave. (Takes longer for the players to be overwhelmed; good for new players.)
require("utils.lua")
-- For this scenario, utils.lua provides:
-- vectorFromAngle(angle, length)
-- Returns a relative vector (x, y coordinates)
-- setCirclePos(obj, x, y, angle, distance)
-- Returns the object with its position set to the resulting coordinates.
function randomStationTemplate()
if random(0, 100) < 10 then
return 'Huge Station'
end
if random(0, 100) < 20 then
return 'Large Station'
end
if random(0, 100) < 50 then
return 'Medium Station'
end
return 'Small Station'
end
function init()
waveNumber = 0
spawnWaveDelay = nil
enemyList = {}
friendlyList = {}
PlayerSpaceship():setFaction("Human Navy"):setTemplate("Atlantis")
for n=1, 2 do
table.insert(friendlyList, SpaceStation():setTemplate(randomStationTemplate()):setFaction("Human Navy"):setPosition(random(-5000, 5000), random(-5000, 5000)))
end
friendlyList[1]:addReputationPoints(150.0)
local x, y = vectorFromAngle(random(0, 360), 15000)
for n=1, 5 do
local xx, yy = vectorFromAngle(random(0, 360), random(2500, 10000))
Nebula():setPosition(x + xx, y + yy)
end
for cnt=1,random(2, 7) do
a = random(0, 360)
a2 = random(0, 360)
d = random(3000, 15000 + cnt * 5000)
x, y = vectorFromAngle(a, d)
for acnt=1,25 do
dx1, dy1 = vectorFromAngle(a2, random(-1000, 1000))
dx2, dy2 = vectorFromAngle(a2 + 90, random(-10000, 10000))
Asteroid():setPosition(x + dx1 + dx2, y + dy1 + dy2)
end
for acnt=1,50 do
dx1, dy1 = vectorFromAngle(a2, random(-1500, 1500))
dx2, dy2 = vectorFromAngle(a2 + 90, random(-10000, 10000))
VisualAsteroid():setPosition(x + dx1 + dx2, y + dy1 + dy2)
end
end
spawnWave()
for n=1, 6 do
setCirclePos(SpaceStation():setTemplate(randomStationTemplate()):setFaction("Independent"), 0, 0, random(0, 360), random(15000, 30000))
end
Script():run("util_random_transports.lua")
end
function randomSpawnPointInfo(distance)
if random(0, 100) < 50 then
if random(0, 100) < 50 then
x = -distance
else
x = distance
end
rx = 2500
y = 0
ry = 5000 + 1000 * waveNumber
else
x = 0
rx = 5000 + 1000 * waveNumber
if random(0, 100) < 50 then
y = -distance
else
y = distance
end
ry = 2500
end
return x, y, rx, ry
end
function spawnWave()
waveNumber = waveNumber + 1
friendlyList[1]:addReputationPoints(150 + waveNumber * 15)
enemyList = {}
if getScenarioVariation() == "Hard" then
totalScoreRequirement = math.pow(waveNumber * 1.5 + 4, 1.3) * 10;
elseif getScenarioVariation() == "Easy" then
totalScoreRequirement = math.pow(waveNumber * 0.8, 1.3) * 9;
else
totalScoreRequirement = math.pow(waveNumber, 1.3) * 10;
end
scoreInSpawnPoint = 0
spawnDistance = 20000
spawnPointLeader = nil
spawn_x, spawn_y, spawn_range_x, spawn_range_y = randomSpawnPointInfo(spawnDistance)
while totalScoreRequirement > 0 do
ship = CpuShip():setFaction("Ghosts");
ship:setPosition(random(-spawn_range_x, spawn_range_x) + spawn_x, random(-spawn_range_y, spawn_range_y) + spawn_y);
if spawnPointLeader == nil then
ship:orderRoaming()
spawnPointLeader = ship
else
ship:orderDefendTarget(spawnPointLeader)
end
type = random(0, 10)
score = 9999
if type < 2 then
if irandom(1, 100) < 80 then
ship:setTemplate("MT52 Hornet");
else
ship:setTemplate("MU52 Hornet");
end
score = 5
elseif type < 3 then
if irandom(1, 100) < 80 then
ship:setTemplate("Adder MK5")
else
ship:setTemplate("WX-Lindworm")
end
score = 7
elseif type < 6 then
if irandom(1, 100) < 80 then
ship:setTemplate("Phobos T3");
else
ship:setTemplate("Piranha F12");
end
score = 15
elseif type < 7 then
ship:setTemplate("Ranus U");
score = 25
elseif type < 8 then
if irandom(1, 100) < 50 then
ship:setTemplate("Stalker Q7");
else
ship:setTemplate("Stalker R7");
end
score = 25
elseif type < 9 then
ship:setTemplate("Atlantis X23");
score = 50
else
ship:setTemplate("Odin");
score = 250
end
if score > totalScoreRequirement * 1.1 + 5 then
ship:destroy()
else
table.insert(enemyList, ship);
totalScoreRequirement = totalScoreRequirement - score
scoreInSpawnPoint = scoreInSpawnPoint + score
end
if scoreInSpawnPoint > totalScoreRequirement * 2.0 then
spawnDistance = spawnDistance + 5000
spawn_x, spawn_y, spawn_range_x, spawn_range_y = randomSpawnPointInfo(spawnDistance)
scoreInSpawnPoint = 0
spawnPointLeader = nil
end
end
globalMessage(string.format(_("Wave %d"), waveNumber));
end
function update(delta)
if spawnWaveDelay ~= nil then
spawnWaveDelay = spawnWaveDelay - delta
if spawnWaveDelay < 5 then
globalMessage(math.ceil(spawnWaveDelay));
end
if spawnWaveDelay < 0 then
spawnWave();
spawnWaveDelay = nil;
end
return
end
enemy_count = 0
friendly_count = 0
local order = nil
local order_target = nil
local ship_type = nil
local victim_station = nil
for _, enemy in ipairs(enemyList) do
if enemy:isValid() then
enemy_count = enemy_count + 1
order = enemy:getOrder()
if order == "Idle" then
if random(1,100) < 50 then
enemy:orderRoaming()
else
victim_station = nil
repeat
victim_station = friendlyList[math.random(1,#friendlyList)]
until(victim_station ~= nil and victim_station:isValid())
local vx, vy = victim_station:getPosition()
enemy:orderFlyTowards(vx,vy)
end
end
ship_type = enemy:getTypeName()
if ship_type == "WX-Lindworm" or ship_type == "Piranha F12" then
if enemy.regenerate_timer == nil then
if enemy:getWeaponStorage("HVLI") < 1 and enemy:getWeaponStorage("Homing") < 1 then
enemy.regenerate_timer = delta + 60
end
else
enemy.regenerate_timer = enemy.regenerate_timer - delta
if enemy.regenerate_timer < 0 then
enemy.regenerate_timer = nil
enemy:setWeaponStorage("Homing",enemy:getWeaponStorageMax("Homing"))
enemy:setWeaponStorage("HVLI",enemy:getWeaponStorageMax("HVLI"))
end
end
end
if ship_type == "Ranus U" then
if enemy.regenerate_timer == nil then
if enemy:getWeaponStorage("Nuke") < 1 and enemy:getWeaponStorage("Homing") < 1 then
enemy.regenerate_timer = delta + 60
end
else
enemy.regenerate_timer = enemy.regenerate_timer - delta
if enemy.regenerate_timer < 0 then
enemy.regenerate_timer = nil
enemy:setWeaponStorage("Homing",enemy:getWeaponStorageMax("Homing"))
enemy:setWeaponStorage("Nuke",enemy:getWeaponStorageMax("Nuke"))
end
end
end
end
end
for _, friendly in ipairs(friendlyList) do
if friendly:isValid() then
friendly_count = friendly_count + 1
end
end
if enemy_count == 0 then
spawnWaveDelay = 15.0;
globalMessage("Wave cleared!");
end
if friendly_count == 0 then
globalMessage(string.format("Stopped on Wave %d", waveNumber));
victory("Ghosts"); --Victory for the Ghosts (== defeat for the players)
end
for pidx=1,32 do
local p = getPlayerShip(pidx)
if p ~= nil and p:isValid() then
if p:hasPlayerAtPosition("Relay") then
p.wave_info = "wave_info"
p:addCustomInfo("Relay",p.wave_info,string.format(_("Wave %d"), waveNumber))
end
if p:hasPlayerAtPosition("Operations") then
p.wave_info_ops = "wave_info_ops"
p:addCustomInfo("Operations",p.wave_info_ops,string.format(_("Wave %d"), waveNumber))
end
end
end
end