-
Notifications
You must be signed in to change notification settings - Fork 1
/
ME5_ObjectiveSurvival.lua
682 lines (584 loc) · 20.5 KB
/
ME5_ObjectiveSurvival.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
local __SCRIPT_NAME = "ME5_ObjectiveSurvival";
local debug = true
local function PrintLog(...)
if debug == true then
print("["..__SCRIPT_NAME.."]", unpack(arg));
end
end
PrintLog("Entered")
ScriptCB_DoFile("ME5_Objective")
if bStockFontLoaded == nil then
-- Has the stock font been loaded?
bStockFontLoaded = false
end
MEU_GameMode = "meu_surv"
ObjectiveSurvivalHasRan = 1
print("ObjectiveSurvival: Entered")
--=============================
-- CommandPost
-- Class representing a specific CP, allowing some measure of customization
-- of what happens at each post when it is captured
--=============================
CommandPost =
{
-- fields that need to be specified when calling New()
name = "noname", --name of the CP
-- Overridable functions
OnCapture = function()
--override me to customize behavior when the command post is captured
end,
}
function CommandPost:New(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
--=============================
-- ObjectiveSurvival
-- Handles the logic for a survival game (a.k.a. drain the other team's tickets)
--=============================
ObjectiveSurvival = Objective:New
{
-- external values
icon = "hud_objective_icon_circle",
-- internal values
defaultBleedRate = 0.0, -- 0.3333333333 --how many units will be lost per second
defeatTimerSeconds = 110, --how long the defeat timer lasts after capping the all the CPs
}
function ObjectiveSurvival:GetOpposingTeam(team)
if team == self.teamATT then
return self.teamDEF
else
return self.teamATT
end
end
function ObjectiveSurvival:AddCommandPost(cp)
--make sure we have a table to add the cp to
self.commandPosts = self.commandPosts or {}
--do all the error checking we can on the cp
assert(cp.name, "WARNING: no name supplied for the command post")
cp.name = string.lower(cp.name)
self.commandPosts[cp.name] = cp
--keep a running tally of the bleedValue relative to each team
--[[if not self.totalBleedValue then
self.totalBleedValue = {}
self.totalBleedValue[self.teamATT] = 0
self.totalBleedValue[self.teamDEF] = 0
end
self.totalBleedValue[self.teamATT] = self.totalBleedValue[self.teamATT] + GetCommandPostBleedValue(cp.name, self.teamATT)
self.totalBleedValue[self.teamDEF] = self.totalBleedValue[self.teamDEF] + GetCommandPostBleedValue(cp.name, self.teamDEF)]]
end
--Add a threshold value for bleeding. Basically
--[[function ObjectiveSurvival:AddBleedThreshold(team, threshold, rate)
--assert(team == self.teamATT or team == self.teamDEF, "invalid team!")
if not self.bleedRates then
--initialize the bleedRates two-dimensional array
self.bleedRates = {}
self.bleedRates[self.teamATT] = {}
self.bleedRates[self.teamDEF] = {}
end
self.bleedRates[team][threshold] = rate
end]]
-- Get game time limit as set in game options menu, if any. 0 if none.
--[[function ObjectiveSurvival:GetGameTimeLimit()
return ScriptCB_GetCONMaxTimeLimit()
end
function ObjectiveSurvival:GameOptionsTimeLimitUp()
local team1pts = GetReinforcementCount(1)
local team2pts = GetReinforcementCount(2)
if ( team1pts > team2pts ) then
MissionVictory(1)
elseif ( team1pts < team2pts ) then
MissionVictory(2)
else
--tied, so victory for both
MissionVictory({1,2})
end
end]]
function ObjectiveSurvival:Start()
--===============================
-- Local functions
--===============================
--[[local UpdateBleedRate = function(team)
--count up the total bleedPoints (bleedPoints only count if they're on a CP owned by a different team)
local bleedPoints = 0
for i, cp in pairs(self.commandPosts) do
local cpTeam = GetObjectTeam(cp.name)
if cpTeam == self:GetOpposingTeam(team) then
--print("cp.name:", cp.name, "bleedPoints:", GetCommandPostBleedValue(cp.name, cpTeam)) --uncomment me for test output!
bleedPoints = bleedPoints + GetCommandPostBleedValue(cp.name, cpTeam)
end
end
--set the bleed rate based on the total accumulated bleedPoints
local bleedRate = 0.0
if self.bleedRates and self.bleedRates[team] then
--look through the unsorted list for the highest threshold that bleedPoints is higher than
local highestThresholdSoFar = 0
for threshold, rate in pairs(self.bleedRates[team]) do
if bleedPoints >= threshold and threshold > highestThresholdSoFar then
bleedRate = rate
highestThresholdSoFar = threshold
end
end
else
--default bleeding rule is to start bleeding when the team's bleed points are greater
--than half the total points
if bleedPoints > (self.totalBleedValue[team] / 2.0) then
bleedRate = self.defaultBleedRate
end
end
--print("totalbleedpts:", self.totalBleedValue[team]) --uncomment me for test output!
--print("team:", team, "bleedPoints:", bleedPoints, "bleedRate:", bleedRate) --uncomment me for test output!
--setup the bleedrate display (i.e. how fast the score flashes in the HUD)
SetBleedRate(team, bleedRate)
if bleedRate > 0.0 then
--start bleeding reinforcements
StopTimer(self.bleedTimer[team])
SetTimerValue(self.bleedTimer[team], 1.0)
SetTimerRate(self.bleedTimer[team], bleedRate)
StartTimer(self.bleedTimer[team])
else
--stop bleeding reinforcements
StopTimer(self.bleedTimer[team])
end
end]]
--turns off the timers and resets the winningTeam number
local DisableWinnerDoodads = function()
self.winningTeam = 0
StopTimer(self.defeatTimer)
--hide the timers (HACK: this way of displaying the lose timer should be updated to use new HUD code)
SetDefeatTimer(nil, self.teamATT)
SetVictoryTimer(nil, self.teamATT)
SetDefeatTimer(nil, self.teamDEF)
SetVictoryTimer(nil, self.teamDEF)
end
--[[local UpdateState = function()
if self.multiplayerRules then
UpdateBleedRate(self.teamDEF)
UpdateBleedRate(self.teamATT)
end
--check to see if one team (the winningTeam) has all the CPs
self.winningTeam = 0
for i, cp in pairs(self.commandPosts) do
--NOTE: destroyed CP's aren't supposed to count against the win/loss accounting
if IsObjectAlive(cp.name) then
local cpTeam = GetObjectTeam(cp.name)
if cpTeam == 0 then
--can't have a winner if one of the CPs is still neutral
DisableWinnerDoodads()
return
elseif self.winningTeam == 0 then
--start tracking this team that might be winning
self.winningTeam = cpTeam
elseif self.winningTeam ~= cpTeam then
--there is no winner, since we just found two CP's that don't match
DisableWinnerDoodads()
return
end
end
end
if self.winningTeam ~= 0 then
if self.disallowDefensiveVictory and self.winningTeam ~= self.teamATT then
return
end
if self.multiplayerRules then
--start the defeat timer to end the game in a few seconds
SetTimerValue(self.defeatTimer, self.defeatTimerSeconds)
StartTimer(self.defeatTimer)
--tell the C++ code about the defeat/victory timer (which will display it on the HUD)
SetDefeatTimer(self.defeatTimer, self:GetOpposingTeam(self.winningTeam))
SetVictoryTimer(self.defeatTimer, self.winningTeam)
else
--end the objective immediately
self:Complete(self.winningTeam)
end
end
end]]
--[[local InitBleedTimer = function(team)
self.bleedTimer[team] = CreateTimer("bleed" .. team)
OnTimerElapse(
function (timer)
if GetReinforcementCount(team) > GetNumTeamMembersAlive(team) then
--tick off a reinforcement when the timer elapses, and start it up again
if GetReinforcementCount(team) > 0 then
AddReinforcements(team, -1)
end
SetTimerValue(timer, GetTimerValue(timer) + 1.0)
StartTimer(timer)
else
--disallow bleeding when a team gets really low on reinforcements (so the team
--doesn't run entirely out of units due to bleedrate, as per designer request)
SetBleedRate(team, 0.0)
StopTimer(timer)
end
end,
self.bleedTimer[team]
)
end]]
local InitDefeatTimer = function()
self.defeatTimer = CreateTimer("defeat")
SetTimerRate(self.defeatTimer, 1.0)
OnTimerElapse(
function (timer)
StopTimer(timer)
SetReinforcementCount(self:GetOpposingTeam(self.winningTeam), 0)
self:Complete(self.winningTeam)
end,
self.defeatTimer
)
end
local UpdatePostMapMarker = function(postPtr)
if not self.multiplayerRules then
--check the team that capped the CP, and change the map marker accordingly
if GetObjectTeam(postPtr) == self.teamATT then
MapRemoveEntityMarker(postPtr, self.teamATT)
else
MapAddEntityMarker(postPtr, self.icon, 4.0, self.teamATT, "YELLOW", true)
end
end
end
--==========
-- Set the number of guys in the level to number in game options
--==========
--ScriptCB_SetNumBots(ScriptCB_GetCONNumBots())
local ClassInitTimer = function()
SetClassProperty("gth_inf_trooper", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_rocketeer", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_sniper", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_machinist", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_hunter", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_shock", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_destroyer", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_juggernaut", "PointsToUnlock", 99999)
--SetClassProperty("gth_inf_prime", "PointsToUnlock", 99999)
SetClassProperty("gth_inf_default", "AddShield", 0.0)
SetClassProperty("gth_inf_trooper", "AddShield", 0.0)
CreateTimer("survGameTimer")
SetTimerValue("survGameTimer", 1200)
CreateTimer("team1ticketbonustimer")
SetTimerValue("team1ticketbonustimer", 900)
StartTimer("team1ticketbonustimer")
CreateTimer("gthMachinistTimer")
SetTimerValue("gthMachinistTimer", 240)
CreateTimer("gthHunterTimer")
SetTimerValue("gthHunterTimer", 120)
CreateTimer("gthShockTrooperTimer")
SetTimerValue("gthShockTrooperTimer", 120)
CreateTimer("gthDestroyerTimer")
SetTimerValue("gthDestroyerTimer", 180)
CreateTimer("gthJuggernautTimer")
SetTimerValue("gthJuggernautTimer", 180)
CreateTimer("gthPrimeTimer")
SetTimerValue("gthPrimeTimer", 180)
ShowTimer("survGameTimer")
StartTimer("survGameTimer")
OnTimerElapse(
function(timer)
local team1pts = GetReinforcementCount(1)
if team1pts > 0 then
ScriptCB_SndBusFade("music", 0.0, 1.0)
MissionVictory(1)
else
ScriptCB_SndBusFade("music", 0.0, 1.0)
MissionVictory(2)
end
DestroyTimer(Timer)
end,
"survGameTimer"
)
StartTimer("gthMachinistTimer")
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Machinists...")
AddUnitClass(2, "gth_inf_machinist",9, 9)
ShowMessageText("level.common.events.surv.classes.gthMachinist")
StartTimer("gthHunterTimer")
DestroyTimer(timer)
end,
"gthMachinistTimer"
)
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Hunters...")
AddUnitClass(2, "gth_inf_hunter",6, 6)
ShowMessageText("level.common.events.surv.classes.gthHunter")
StartTimer("gthShockTrooperTimer")
DestroyTimer(timer)
end,
"gthHunterTimer"
)
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Shock Troopers...")
AddUnitClass(2, "gth_inf_shock",6, 6)
ShowMessageText("level.common.events.surv.classes.gthShock")
StartTimer("gthDestroyerTimer")
DestroyTimer(timer)
end,
"gthShockTrooperTimer"
)
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Destroyers...")
AddUnitClass(2, "gth_inf_destroyer",5, 5)
ShowMessageText("level.common.events.surv.classes.gthDestroyer")
StartTimer("gthJuggernautTimer")
DestroyTimer(timer)
end,
"gthDestroyerTimer"
)
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Juggernauts...")
AddUnitClass(2, "gth_inf_juggernaut",3, 3)
ShowMessageText("level.common.events.surv.classes.gthJuggernaut")
StartTimer("gthPrimeTimer")
DestroyTimer(timer)
end,
"gthJuggernautTimer"
)
OnTimerElapse(
function(timer)
print("ObjectiveSurvival: Spawning Geth Primes...")
--AddUnitClass(2, "gth_inf_prime",2, 2)
ShowMessageText("level.common.events.surv.classes.gthPrime")
DestroyTimer(timer)
end,
"gthPrimeTimer"
)
end
--===============================
-- Initialization logic
--===============================
--initialize the base objective data first
Objective.Start(self)
--initialize internal values
self.commandPosts = self.commandPosts or {}
--[[self.bleedTimer = {}
InitBleedTimer(self.teamATT)
InitBleedTimer(self.teamDEF)]]
InitDefeatTimer()
--initialize team 2 class timer stuff
ClassInitTimer()
if self.multiplayerRules then
self.disallowDefensiveVictory = false
else
self.disallowDefensiveVictory = true --in single player/co-op, the defense can't win by capping all the CPs
end
numCPs = 0
for i, cp in pairs(self.commandPosts) do
if not self.multiplayerRules then
MapAddEntityMarker(cp.name, self.icon, 4.0, self.teamATT, "YELLOW", true)
end
numCPs = numCPs + 1
end
if(numCPs == 0) then
print ("ERROR: no valid CommandPosts were added to the ObjectiveSurvival")
return
end
--set AI goals
self.AIGoals = {}
if self.AIGoalWeight > 0.0 then
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Conquest", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Deathmatch", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Conquest", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Deathmatch", 100*self.AIGoalWeight))
end
--do an initial update on the state
--UpdateState()
--=======================================
-- Event responses
--=======================================
-- command post captures
OnFinishCapture(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
UpdatePostMapMarker(postPtr)
--UpdateState()
end
)
-- command post neutralize
OnFinishNeutralize(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
UpdatePostMapMarker(postPtr)
--UpdateState()
end
)
-- command post spawn
OnCommandPostRespawn(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
UpdatePostMapMarker(postPtr)
--UpdateState()
end
)
-- command post kill
OnCommandPostKill(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
if not self.multiplayerRules then
MapRemoveEntityMarker(postPtr, self.teamATT)
end
--UpdateState()
end
)
--[[CreateTimer("team1ticket_timer")
SetTimerValue("team1ticket_timer", 20)
team1ticket_flagged = 0
ShowTimer("team1ticket_timer")
OnTimerElapse(
function(timer)
team1ticket_flagged = 0
end,
"team1ticket_timer"
)
CreateTimer("team2ticket_timer")
SetTimerValue("team2ticket_timer", 20)
team2ticket_flagged = 0
ShowTimer("team2ticket_timer")
OnTimerElapse(
function(timer)
team2ticket_flagged = 0
end,
"team2ticket_timer"
)]]
-- These add reinforcements for CP captures
OnFinishCaptureTeam(
function(post)
team1cpcount = 0
-- Count the number of CPs team 1 possesses
print("ObjectiveSurvival: Counting the number of CPs owned by team 1...")
for i, cp in pairs(self.commandPosts) do
-- NOTE: destroyed CP's aren't supposed to count against the win/loss accounting
if IsObjectAlive(cp.name) then
team1cpTeam = GetObjectTeam(cp.name)
if team1cpTeam == 1 then
team1cpcount = team1cpcount + 1
print("ObjectiveSurvival: team 1 CP count = " .. team1cpcount)
end
end
end
--[[print("ObjectiveSurvival: Team 1 currently owns " .. team1cpcount .. " CPs")
team1ticketbonus = 30 / team1cpcount
print("ObjectiveSurvival: team 1 bonus = " .. team1ticketbonus)
AddReinforcements(1, team1ticketbonus)
ShowMessageText(team1ticketstring)]]
end,
1 -- Team number for the ticket bonus
)
OnTimerElapse(
function(timer)
if team1cpcount >= 2 then
AddReinforcements(1, 50)
else
end
end,
"team1ticketbonustimer"
)
-- spawn block for Husks --
OnTicketCountChange(
function (team, count)
if team == CIS and count == 20 then
AllowAISpawn(3, false)
end
end
)
--[[CaptureRegionsTable = {1}
for i, cp in pairs(self.commandPosts) do
CaptureRegionsTable[i] = GetCommandPostCaptureRegion(cp.name)
end
-- These add reinforcements for CP captures
OnFinishCaptureTeam(
function(post)
team1cpcount = 0
-- Count the number of CPs team 1 possesses
print("ObjectiveSurvival: Counting the number of CPs owned by team 1...")
for i, cp in pairs(self.commandPosts) do
-- NOTE: destroyed CP's aren't supposed to count against the win/loss accounting
if IsObjectAlive(cp.name) then
team1cpTeam = GetObjectTeam(cp.name)
if team1cpTeam == 1 then
team1cpcount = team1cpcount + 1
print("ObjectiveSurvival: team 1 CP count = " .. team1cpcount)
end
end
end
if team1cpcount == 1 then
for i, cp in pairs(self.commandPosts) do
team1cpTeam = GetObjectTeam(cp.name)
if team1cpTeam == 1 then
--SetProperty(cp.name, "CaptureRegion", "")
print("ObjectiveSurvival: Removing capture region for " .. cp.name)
end
end
elseif team1cpcount > 1 then
for i, cp in pairs(self.commandPosts) do
--SetProperty(cp.name, "CaptureRegion", CaptureRegionsTable[i])
print("ObjectiveSurvival: Replacing capture region for " .. cp.name)
end
end
print("ObjectiveSurvival: Team 1 currently owns " .. team1cpcount .. " CPs")
team1ticketbonus = 30 / team1cpcount
print("ObjectiveSurvival: team 1 bonus = " .. team1ticketbonus)
AddReinforcements(1, team1ticketbonus)
ShowMessageText(team1ticketstring)
end,
1 -- Team number for the ticket bonus
)]]
--[[Upon team 1 capturing command post
Team 1 ticket count is increased by ticketboostvariable
ticketboostvariable is product of team 1 total CP count and X (currently undefined)
End(er's Game)]]
-- These add reinforcements for CP captures
--[[OnFinishCaptureTeam(
function(post)
team2cpcount = 0
-- Count the number of CPs team 2 possesses
print("ObjectiveSurvival: Counting the number of CPs owned by team 2...")
for i, cp in pairs(self.commandPosts) do
-- NOTE: destroyed CP's aren't supposed to count against the win/loss accounting
if IsObjectAlive(cp.name) then
team2cpTeam = GetObjectTeam(cp.name)
if team2cpTeam == 2 then
team2cpcount = team2cpcount + 1
print("ObjectiveSurvival: team 2 CP count = " .. team2cpcount)
end
end
end
print("ObjectiveSurvival: Team 2 currently owns " .. team2cpcount .. " CPs")
team2ticketbonus = 30 / team2cpcount
print("ObjectiveSurvival: team 2 bonus = " .. team2ticketbonus)
AddReinforcements(2, team2ticketbonus)
ShowMessageText(team2ticketstring)
end,
2 -- Team number for the ticket bonus
)]]
end
function ObjectiveSurvival:Complete(winningTeam)
if not self.multiplayerRules then
--remove all the cp markers
for i, cp in pairs(self.commandPosts) do
MapRemoveEntityMarker(cp.name)
end
--[[if ME5_CustomHUD == 1 then
if bStockFontLoaded == false then
bStockFontLoaded = true
print("ME5_ObjectiveSurvival: Loading hud_font_stock.lvl...")
-- hotfix that reloads the stock fonts in the stats screen
ReadDataFile("..\\..\\addon\\ME5\\data\\_LVL_PC\\hud_font_stock.lvl")
end
end]]
end
--then call the default objective complete method
Objective.Complete(self, winningTeam)
end
PrintLog("Exited")