-
Notifications
You must be signed in to change notification settings - Fork 35
/
reinforcements_module.lua
378 lines (352 loc) · 17.3 KB
/
reinforcements_module.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
local ReinforcementsCountPerTeam = {}
local TryingToSpawnReinforcements = {}
local ReinforcementsFaction = {}
local ReinforcementsChancePerTeam = {}
local numOfSpawnBeaconsTeamsForSpawn = {}
local CaptureProgressForBeacons = {}
function CaptureBeacons(n)
local scavengerunits = Spring.GetTeamUnits(GaiaTeamID)
local spGetUnitTeam = Spring.GetUnitTeam
for i = 1,#scavengerunits do
local scav = scavengerunits[i]
local scavDef = Spring.GetUnitDefID(scav)
if scavSpawnBeacon[scav] then
if not CaptureProgressForBeacons[scav] then
CaptureProgressForBeacons[scav] = 0
Spring.SetUnitHealth(scav, {capture = CaptureProgressForBeacons[scav]})
end
local posx,posy,posz = Spring.GetUnitPosition(scav)
--Spring.Echo("posx "..posx)
--Spring.Echo("posz "..posz)
unitsAround = Spring.GetUnitsInCylinder(posx, posz, 256)
--Spring.Echo("#unitsAround "..#unitsAround)
CapturingUnits = {}
CapturingUnitsTeam = {}
CapturingUnitsTeamTest = {}
local TeamsCapturing = 0
CapturingUnits[scav] = 0
for j = 1,#unitsAround do
local unitID = unitsAround[j]
local unitTeamID = spGetUnitTeam(unitID)
local unitAllyTeam = Spring.GetUnitAllyTeam(unitID)
local LuaAI = Spring.GetTeamLuaAI(unitTeamID)
local _,_,_,isAI,_,_ = Spring.GetTeamInfo(unitTeamID)
if (not LuaAI) and unitTeamID ~= GaiaTeamID and unitTeamID ~= Spring.GetGaiaTeamID() and (not isAI) then
captureraiTeam = false
else
captureraiTeam = true
end
if not CapturingUnitsTeamTest[unitAllyTeam] then
CapturingUnitsTeamTest[unitAllyTeam] = true
if unitTeamID ~= GaiaTeamID and captureraiTeam == false then
TeamsCapturing = TeamsCapturing + 1
if TeamsCapturing > 1 then
break
end
end
end
captureraiTeam = nil
end
for j = 1,#unitsAround do
local unitID = unitsAround[j]
local unitTeamID = spGetUnitTeam(unitID)
if not CapturingUnitsTeam[unitTeamID] then
CapturingUnitsTeam[unitTeamID] = 0
end
local unitDefID = Spring.GetUnitDefID(unitID)
local LuaAI = Spring.GetTeamLuaAI(unitTeamID)
local _,_,_,isAI,_,_ = Spring.GetTeamInfo(unitTeamID)
if (not LuaAI) and unitTeamID ~= GaiaTeamID and unitTeamID ~= Spring.GetGaiaTeamID() and (not isAI) then
captureraiTeam = false
else
captureraiTeam = true
end
if not CapturingUnitsTeam[unitTeamID] then
CapturingUnitsTeam[unitTeamID] = 0
end
for k = 1,#BeaconCaptureExcludedUnits do
if UnitDefs[unitDefID].name == BeaconCaptureExcludedUnits[k] then
IsUnitExcluded = true
break
else
IsUnitExcluded = false
end
end
if unitDefID == scavDef then
CaptureProgressForBeacons[scav] = CaptureProgressForBeacons[scav] - 0.0005
--Spring.Echo("uncapturing myself")
elseif unitTeamID == GaiaTeamID and (not unitDefID == scavDef) then
CaptureProgressForBeacons[scav] = CaptureProgressForBeacons[scav] - 1
--Spring.Echo("uncapturing our beacon")
elseif captureraiTeam == false and unitTeamID ~= GaiaTeamID and unitTeamID ~= Spring.GetGaiaTeamID() and IsUnitExcluded == false and (not UnitDefs[unitDefID].canFly) then
CaptureProgressForBeacons[scav] = CaptureProgressForBeacons[scav] + 0.001
CapturingUnitsTeam[unitTeamID] = CapturingUnitsTeam[unitTeamID] + 1
--Spring.Echo("capturing scav beacon")
end
if CaptureProgressForBeacons[scav] < 0 then
CaptureProgressForBeacons[scav] = 0
--Spring.Echo("capture below 0")
end
if CaptureProgressForBeacons[scav] > 1 then
CaptureProgressForBeacons[scav] = 1
--Spring.Echo("capture above 1")
end
Spring.SetUnitHealth(scav, {capture = CaptureProgressForBeacons[scav]})
if TeamsCapturing < 2 and captureraiTeam == false and CaptureProgressForBeacons[scav] >= 1 then
CaptureProgressForBeacons[scav] = 0
Spring.SetUnitHealth(scav, {capture = 0})
Spring.TransferUnit(scav, unitTeamID, true)
captureraiTeam = nil
break
end
captureraiTeam = nil
IsUnitExcluded = nil
end
CapturingUnits = nil
CapturingUnitsTeam = nil
unitsAround = nil
end
end
end
function SetBeaconsResourceProduction(n)
if globalScore then
local units = Spring.GetAllUnits()
local minutes = math.ceil(Spring.GetGameSeconds()/300)
local beaconmetalproduction = minutes
local beaconenergyproduction = beaconmetalproduction*20
for i = 1,#units do
local unitID = units[i]
local unitDefID = Spring.GetUnitDefID(unitID)
local name = UnitDefs[unitDefID].name
if name == "scavengerdroppodbeacon_scav" then
--Spring.AddUnitResource(unitID, "m", beaconmetalproduction)
Spring.AddUnitResource(unitID, "e", beaconenergyproduction)
end
end
end
end
function SpawnDefencesAfterCapture(unitID, teamID)
local spawnTier = math_random(1,100)
if spawnTier <= TierSpawnChances.T0 then
grouptier = BeaconDefenceStructuresT0
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 then
grouptier = BeaconDefenceStructuresT1
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 then
grouptier = BeaconDefenceStructuresT2
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 + TierSpawnChances.T4 then
grouptier = BeaconDefenceStructuresT3
end
if spawnTier <= TierSpawnChances.T0 then
grouptiersea = StartboxDefenceStructuresT0Sea
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 then
grouptiersea = StartboxDefenceStructuresT1Sea
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 then
grouptiersea = StartboxDefenceStructuresT2Sea
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 + TierSpawnChances.T4 then
grouptiersea = StartboxDefenceStructuresT3Sea
end
local posx,posy,posz = Spring.GetUnitPosition(unitID)
local posy = Spring.GetGroundHeight(posx, posz)
local n = Spring.GetGameFrame()
local r = grouptier[math_random(1,#grouptier)]
local r2 = grouptiersea[math_random(1,#grouptiersea)]
Spring.CreateUnit("scavengerdroppodfriendly_scav", posx-128, posy, posz-128, math_random(0,3),teamID)
local posy = Spring.GetGroundHeight(posx-128, posz-128)
if posy > 0 then
QueueSpawn(r..scavconfig.unitnamesuffix, posx-128, posy, posz-128, math_random(0,3),teamID, n+90)
else
QueueSpawn(r2..scavconfig.unitnamesuffix, posx-128, posy, posz-128, math_random(0,3),teamID, n+90)
end
local r = grouptier[math_random(1,#grouptier)]
local r2 = grouptiersea[math_random(1,#grouptiersea)]
Spring.CreateUnit("scavengerdroppodfriendly_scav", posx+128, posy, posz+128, math_random(0,3),teamID)
local posy = Spring.GetGroundHeight(posx+128, posz+128)
if posy > 0 then
QueueSpawn(r..scavconfig.unitnamesuffix, posx+128, posy, posz+128, math_random(0,3),teamID, n+90)
else
QueueSpawn(r2..scavconfig.unitnamesuffix, posx+128, posy, posz+128, math_random(0,3),teamID, n+90)
end
local r = grouptier[math_random(1,#grouptier)]
local r2 = grouptiersea[math_random(1,#grouptiersea)]
Spring.CreateUnit("scavengerdroppodfriendly_scav", posx-128, posy, posz+128, math_random(0,3),teamID)
local posy = Spring.GetGroundHeight(posx-128, posz+128)
if posy > 0 then
QueueSpawn(r..scavconfig.unitnamesuffix, posx-128, posy, posz+128, math_random(0,3),teamID, n+90)
else
QueueSpawn(r2..scavconfig.unitnamesuffix, posx-128, posy, posz+128, math_random(0,3),teamID, n+90)
end
local r = grouptier[math_random(1,#grouptier)]
local r2 = grouptiersea[math_random(1,#grouptiersea)]
Spring.CreateUnit("scavengerdroppodfriendly_scav", posx+128, posy, posz-128, math_random(0,3),teamID)
local posy = Spring.GetGroundHeight(posx+128, posz-128)
if posy > 0 then
QueueSpawn(r..scavconfig.unitnamesuffix, posx+128, posy, posz-128, math_random(0,3),teamID, n+90)
else
QueueSpawn(r2..scavconfig.unitnamesuffix, posx+128, posy, posz-128, math_random(0,3),teamID, n+90)
end
grouptier = nil
grouptiersea = nil
end
function spawnPlayerReinforcements(n)
--mapsizeX
--mapsizeZ
--ScavengerStartboxXMin
--ScavengerStartboxZMin
--ScavengerStartboxXMax
--ScavengerStartboxZMax
--GaiaTeamID
--GaiaAllyTeamID
--posCheck(posx, posy, posz, posradius)
--posOccupied(posx, posy, posz, posradius)
for _,teamID in ipairs(Spring.GetTeamList()) do
local LuaAI = Spring.GetTeamLuaAI(teamID)
local _,teamLeader,isDead,isAI,_,allyTeamID = Spring.GetTeamInfo(teamID)
if (not LuaAI) and teamID ~= GaiaTeamID and teamID ~= Spring.GetGaiaTeamID() and (not isAI) then
local playerName = Spring.GetPlayerInfo(teamLeader)
if not numOfSpawnBeaconsTeams[teamID] then
numOfSpawnBeaconsTeams[teamID] = 0
end
if not numOfSpawnBeaconsTeamsForSpawn[teamID] or numOfSpawnBeaconsTeamsForSpawn[teamID] == 0 then
numOfSpawnBeaconsTeamsForSpawn[teamID] = 2
else
numOfSpawnBeaconsTeamsForSpawn[teamID] = numOfSpawnBeaconsTeams[teamID] + 2
end
if not ReinforcementsCountPerTeam[teamID] then
ReinforcementsCountPerTeam[teamID] = 0
end
if not ReinforcementsChancePerTeam[teamID] then
ReinforcementsChancePerTeam[teamID] = (((unitSpawnerModuleConfig.spawnchance)*10)/numOfSpawnBeaconsTeamsForSpawn[teamID])
end
if not isDead then
if TryingToSpawnReinforcements[teamID] == true then
local playerunits = Spring.GetTeamUnits(teamID)
PlayerSpawnBeacons = {}
for i = 1,#playerunits do
local playerbeacon = playerunits[i]
local playerbeaconDef = Spring.GetUnitDefID(playerbeacon)
local UnitName = UnitDefs[playerbeaconDef].name
if UnitName == "scavengerdroppodbeacon_scav" then
table.insert(PlayerSpawnBeacons,playerbeacon)
end
end
--numOfSpawnBeaconsTeams[teamID] = 10
if numOfSpawnBeaconsTeams[teamID] == 1 then
pickedBeacon = PlayerSpawnBeacons[1]
elseif numOfSpawnBeaconsTeams[teamID] > 1 then
pickedBeacon = PlayerSpawnBeacons[math_random(1,#PlayerSpawnBeacons)]
else
pickedBeacon = nil
TryingToSpawnReinforcements[teamID] = false
ReinforcementsChancePerTeam[teamID] = (((unitSpawnerModuleConfig.spawnchance)*10)/numOfSpawnBeaconsTeamsForSpawn[teamID])
end
PlayerSpawnBeacons = nil
if pickedBeacon then
if not globalScore then
teamsCheck()
end
local groupsize = (bestTeamScore / unitSpawnerModuleConfig.globalscoreperoneunit)*spawnmultiplier
local groupsize = math.ceil(groupsize*2)
if scorePerTeam[teamID] < bestTeamScore*2 then
groupsize = math.ceil(groupsize*2)
end
local posradius = 160
local posx,posy,posz = Spring.GetUnitPosition(pickedBeacon)
local posy = Spring.GetGroundHeight(posx, posz)
local spawnTier = math_random(1,100)
local aircraftchance = math_random(0,unitSpawnerModuleConfig.aircraftchance)
if aircraftchance == 0 then
if spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 then
groupunit1 = T1ReinforcementAirUnits[math_random(1,#T1ReinforcementAirUnits)]
groupunit2 = T1ReinforcementAirUnits[math_random(1,#T1ReinforcementAirUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.airmultiplier*unitSpawnerModuleConfig.t1multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 then
groupunit1 = T2ReinforcementAirUnits[math_random(1,#T2ReinforcementAirUnits)]
groupunit2 = T2ReinforcementAirUnits[math_random(1,#T2ReinforcementAirUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.airmultiplier*unitSpawnerModuleConfig.t2multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 then
groupunit1 = T3ReinforcementAirUnits[math_random(1,#T3ReinforcementAirUnits)]
groupunit2 = T3ReinforcementAirUnits[math_random(1,#T3ReinforcementAirUnits)]
groupsize = 2
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 + TierSpawnChances.T4 then
groupunit1 = T4ReinforcementAirUnits[math_random(1,#T4ReinforcementAirUnits)]
groupunit2 = T4ReinforcementAirUnits[math_random(1,#T4ReinforcementAirUnits)]
groupsize = 1
end
elseif posy > -20 then
if spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 then
groupunit1 = T1ReinforcementLandUnits[math_random(1,#T1ReinforcementLandUnits)]
groupunit2 = T1ReinforcementLandUnits[math_random(1,#T1ReinforcementLandUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.landmultiplier*unitSpawnerModuleConfig.t1multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 then
groupunit1 = T2ReinforcementLandUnits[math_random(1,#T2ReinforcementLandUnits)]
groupunit2 = T2ReinforcementLandUnits[math_random(1,#T2ReinforcementLandUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.landmultiplier*unitSpawnerModuleConfig.t2multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 then
groupunit1 = T3ReinforcementLandUnits[math_random(1,#T3ReinforcementLandUnits)]
groupunit2 = T3ReinforcementLandUnits[math_random(1,#T3ReinforcementLandUnits)]
groupsize = 2
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 + TierSpawnChances.T4 then
groupunit1 = T4ReinforcementLandUnits[math_random(1,#T4ReinforcementLandUnits)]
groupunit2 = T4ReinforcementLandUnits[math_random(1,#T4ReinforcementLandUnits)]
groupsize = 1
end
elseif posy <= -20 then
if spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 then
groupunit1 = T1ReinforcementSeaUnits[math_random(1,#T1ReinforcementSeaUnits)]
groupunit2 = T1ReinforcementSeaUnits[math_random(1,#T1ReinforcementSeaUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.seamultiplier*unitSpawnerModuleConfig.t1multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 then
groupunit1 = T2ReinforcementSeaUnits[math_random(1,#T2ReinforcementSeaUnits)]
groupunit2 = T2ReinforcementSeaUnits[math_random(1,#T2ReinforcementSeaUnits)]
groupsize = groupsize*unitSpawnerModuleConfig.seamultiplier*unitSpawnerModuleConfig.t2multiplier
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 then
groupunit1 = T3ReinforcementSeaUnits[math_random(1,#T3ReinforcementSeaUnits)]
groupunit2 = T3ReinforcementSeaUnits[math_random(1,#T3ReinforcementSeaUnits)]
groupsize = 2
elseif spawnTier <= TierSpawnChances.T0 + TierSpawnChances.T1 + TierSpawnChances.T2 + TierSpawnChances.T3 + TierSpawnChances.T4 then
groupunit1 = T4ReinforcementSeaUnits[math_random(1,#T4ReinforcementSeaUnits)]
groupunit2 = T4ReinforcementSeaUnits[math_random(1,#T4ReinforcementSeaUnits)]
groupsize = 1
end
end
if groupsize == 1 then
ScavSendMessage(playerName .."'s reinforcements detected. Unit: ".. UDN[groupunit1].humanName .. ".")
else
ScavSendMessage(playerName .."'s reinforcements detected. Units: ".. groupsize .." ".. UDN[groupunit1].humanName .."s and ".. UDN[groupunit2].humanName .."s.")
end
for i = 1,groupsize do
local posx = posx+(math_random(-posradius,posradius))
local posz = posz+(math_random(-posradius,posradius))
local posy = Spring.GetGroundHeight(posx, posz)
if i then
if i < 2 or i < groupsize/2 then
QueueSpawn(groupunit1..scavconfig.unitnamesuffix, posx, posy, posz, math_random(0,3),teamID, n+100+i)
else
QueueSpawn(groupunit2..scavconfig.unitnamesuffix, posx, posy, posz, math_random(0,3),teamID, n+100+i)
end
else
QueueSpawn(groupunit1..scavconfig.unitnamesuffix, posx, posy, posz, math_random(0,3),teamID, n+100)
end
Spring.CreateUnit("scavengerdroppodfriendly_scav", posx, posy, posz, math_random(0,3),teamID)
end
groupsize = nil
groupunit1 = nil
groupunit2 = nil
TryingToSpawnReinforcements[teamID] = false
ReinforcementsCountPerTeam[teamID] = ReinforcementsCountPerTeam[teamID] + 1
end
else
local r = math_random(0,ReinforcementsChancePerTeam[teamID])
if r == 0 or ReinforcementsCountPerTeam[teamID] == 0 then
TryingToSpawnReinforcements[teamID] = true
ReinforcementsChancePerTeam[teamID] = (((unitSpawnerModuleConfig.spawnchance)*10)/numOfSpawnBeaconsTeamsForSpawn[teamID])
else
TryingToSpawnReinforcements[teamID] = false
ReinforcementsChancePerTeam[teamID] = ReinforcementsChancePerTeam[teamID] - 1
end
end
end
end
pickedBeacon = nil
end
end