-
Notifications
You must be signed in to change notification settings - Fork 1
/
ME5_ObjectiveConquest.lua
853 lines (691 loc) · 28.9 KB
/
ME5_ObjectiveConquest.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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
ScriptCB_DoFile("ME5_Objective")
local __SCRIPT_NAME = "ME5_ObjectiveConquest";
local debug = false
local function PrintLog(...)
if debug == true then
print("["..__SCRIPT_NAME.."]", unpack(arg));
end
end
if bStockFontLoaded == nil then
-- Has the stock font been loaded?
bStockFontLoaded = false
end
MEU_GameMode = "meu_con"
CommandPostCaptureState = {
Idle = 0,
Neutralizing = 1,
Capturing = 2,
}
--=============================
-- 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
--=============================
-- ObjectiveConquest
-- Handles the logic for a conquest game (A.K.A. capture the command posts)
--=============================
ObjectiveConquest = Objective:New
{
-- external values
icon = "hud_objective_icon_circle",
-- internal values
-- defaultBleedRate = 0.3333333333, --how many units will be lost per second
defaultBleedRate = 0.4444444444, --how many units will be lost per second
defeatTimerSeconds = 40, --how long the defeat timer lasts after capping the all the CPs
bCanShowCaptureMessage = true,
numMsgDelayTimers = 0,
bShowCPMarkers = true,
postCaptureRegionEventHandlers = {},
}
function ObjectiveConquest:GetOpposingTeam(team)
if team == self.teamATT then
return self.teamDEF
else
return self.teamATT
end
end
function ObjectiveConquest:AddCommandPost(cp)
--make sure we have a table to add the cp to
self.commandPosts = self.commandPosts or {}
self.commandPostStates = self.commandPostStates or {}
self.commandPostAbortedNeutralize = self.commandPostAbortedNeutralize 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
self.commandPostStates[cp.name] = CommandPostCaptureState.Idle
self.commandPostAbortedNeutralize[cp.name] = 0
--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 ObjectiveConquest: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 ObjectiveConquest:GetGameTimeLimit()
return ScriptCB_GetCONMaxTimeLimit()
end
function ObjectiveConquest:GameOptionsTimeLimitUp()
local teamATTpts = GetReinforcementCount(teamATT)
local teamDEFpts = GetReinforcementCount(teamDEF)
if ( teamATTpts > teamDEFpts ) then
self:Complete(teamATT)
elseif ( teamATTpts < teamDEFpts ) then
self:Complete(teamDEF)
else
ScriptCB_SndBusFade("music", 0.0, 1.0)
--tied, so victory for both
MissionVictory({1,2})
end
end
function ObjectiveConquest:Start()
if gCurrentMapManager.gameMode == "tdm" then
PrintLog("Game mode is TDM, hiding CP HUD markers")
bShowCPMarkers = false
else
PrintLog("Game mode is not TDM, showing CP HUD markers")
bShowCPMarkers = true
end
--===============================
-- 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
--PrintLog("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
--PrintLog("totalbleedpts:", self.totalBleedValue[team]) --uncomment me for test output!
--PrintLog("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])
--[[if not ScriptCB_InMultiplayer() then
if ME5_SideVar == 1 then
if team == REP then
ShowMessageText("level.common.events.siege.control_".."ssv")
elseif team == CIS then
ShowMessageText("level.common.events.siege.control_".."gth")
end
elseif ME5_SideVar == 2 then
if team == REP then
ShowMessageText("level.common.events.siege.control_".."ssv")
elseif team == CIS then
ShowMessageText("level.common.events.siege.control_".."col")
end
end
else
if gCurrentMapManager.onlineSideVar == "SSVxGTH" or gCurrentMapManager.onlineSideVar == 1 then
if team == REP then
ShowMessageText("level.common.events.siege.control_".."ssv")
elseif team == CIS then
ShowMessageText("level.common.events.siege.control_".."gth")
end
elseif gCurrentMapManager.onlineSideVar == "SSVxCOL" or gCurrentMapManager.onlineSideVar == 2 then
if team == REP then
ShowMessageText("level.common.events.siege.control_".."ssv")
elseif team == CIS then
ShowMessageText("level.common.events.siege.control_".."col")
end
end
end]]
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 ScriptCB_InMultiplayer() then
if not IsCampaign() and bShowCPMarkers == true then
local playerTeam = GetCharacterTeam(0)
local otherTeam = (3 - playerTeam)
local pulseSize = false
if self.commandPostStates[GetEntityName(postPtr)] == CommandPostCaptureState.Idle then
pulseSize = false
elseif self.commandPostStates[GetEntityName(postPtr)] == CommandPostCaptureState.Neutralizing then
pulseSize = true
elseif self.commandPostStates[GetEntityName(postPtr)] == CommandPostCaptureState.Capturing then
pulseSize = true
end
-- If playerTeam owns the post, add a blue marker for playerTeam and a red marker for otherTeam
if GetObjectTeam(postPtr) == playerTeam then
MapRemoveEntityMarker(postPtr, playerTeam)
MapRemoveEntityMarker(postPtr, otherTeam)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, playerTeam, "BLUE", true, false, pulseSize)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, otherTeam, "RED", true, false, pulseSize)
-- If otherTeam owns the post, add a blue marker for otherTeam and a red marker for playerTeam
elseif GetObjectTeam(postPtr) == otherTeam then
MapRemoveEntityMarker(postPtr, playerTeam)
MapRemoveEntityMarker(postPtr, otherTeam)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, playerTeam, "RED", true, false, pulseSize)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, otherTeam, "BLUE", true, false, pulseSize)
-- If neither team owns the post, add a white marker for both teams
else
MapRemoveEntityMarker(postPtr, playerTeam)
MapRemoveEntityMarker(postPtr, otherTeam)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, playerTeam, "WHITE", true, false, pulseSize)
MapAddEntityMarker(postPtr, "hud_objective_icon", 0.75, otherTeam, "WHITE", true, false, pulseSize)
end
end
end
end
local function ShowCaptureMessage(postPtr)
--PrintLog("ShowCaptureMessage(): Entered")
if self.bCanShowCaptureMessage == false then return end
if self.bCanShowCaptureMessage == true then
-- Don't allow another capture message to be shown for a little bit
self.bCanShowCaptureMessage = false
SetTimerValue(self.postCaptureMsgBufferTimer, 3.0)
StartTimer(self.postCaptureMsgBufferTimer)
local msgDelayValue = 0.05 -- Duration in seconds to delay the message displaying which CP was captured
local postName = GetEntityName(postPtr) -- Name of the post that was captured
local postTeam = GetObjectTeam(postName) -- Captured post's team
local playerTeam = GetCharacterTeam(0) -- Player's team
local msgContext = nil -- Who captured the post from the player's perspective ("ally" or "enemy")
local messageStr = nil
if string.lower(GetWorldFilename()) == "vrm" then
postName = string.sub(postName,1,3)
end
-- Does the captured post now belong to the player's team?
if playerTeam == postTeam then
msgContext = "ally" -- "Allied forces have captured the..."
else
msgContext = "enemy" -- "Enemy forces have captured the..."
end
-- Show first message
ShowMessageText("level.common.events.con.post.captured_"..msgContext)
-- Short delay before showing second message displaying which CP was captured
--[[self.numMsgDelayTimers = self.numMsgDelayTimers + 1
local postCaptureMsgDelayTimer = CreateTimer("postCaptureMsgDelayTimer"..self.numMsgDelayTimers)
SetTimerValue(postCaptureMsgDelayTimer, msgDelayValue)
StartTimer(postCaptureMsgDelayTimer)
local postCaptureMsgDelayTimerElapse = OnTimerElapse(
function(timer)]]
messageStr = "level."..GetWorldFilename().."."..postName
PrintLog("ShowCaptureMessage(): messageStr = ", messageStr)
ShowMessageText(messageStr)
--[[DestroyTimer(timer)
postCaptureMsgDelayTimer = nil
postCaptureMsgDelayTimerElapse = nil
ReleaseTimerElapse(postCaptureMsgDelayTimerElapse)
end,
postCaptureMsgDelayTimer
)]]
end
end
-- TODO: need to add lines for SSVxRPR and SSVxCER
-- WARNING: these have to be defined no matter what, they cannot be left blank
if gCurrentMapManager.gameMode ~= "tdm" then
if not ScriptCB_InMultiplayer() then
if ME5_SideVar == 1 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_GTH_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_GTH_cpCapture_enemy
snd_CIS_cpLost_ally = snd_GTH_cpLost_ally
snd_CIS_cpLost_enemy = snd_GTH_cpLost_enemy
elseif ME5_SideVar == 2 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
elseif ME5_SideVar == 3 then
snd_REP_cpCapture_ally = snd_EVG_cpCapture_ally
snd_REP_cpCapture_enemy = snd_EVG_cpCapture_enemy
snd_REP_cpLost_ally = snd_EVG_cpLost_ally
snd_REP_cpLost_enemy = snd_EVG_cpLost_enemy
snd_CIS_cpCapture_ally = snd_GTH_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_GTH_cpCapture_enemy
snd_CIS_cpLost_ally = snd_GTH_cpLost_ally
snd_CIS_cpLost_enemy = snd_GTH_cpLost_enemy
elseif ME5_SideVar == 4 then
snd_REP_cpCapture_ally = snd_EVG_cpCapture_ally
snd_REP_cpCapture_enemy = snd_EVG_cpCapture_enemy
snd_REP_cpLost_ally = snd_EVG_cpLost_ally
snd_REP_cpLost_enemy = snd_EVG_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
elseif ME5_SideVar == 5 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
elseif ME5_SideVar == 6 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_GTH_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_GTH_cpCapture_enemy
snd_CIS_cpLost_ally = snd_GTH_cpLost_ally
snd_CIS_cpLost_enemy = snd_GTH_cpLost_enemy
end
else
if gCurrentMapManager.onlineSideVar == "SSVxGTH" or gCurrentMapManager.onlineSideVar == 1 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_GTH_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_GTH_cpCapture_enemy
snd_CIS_cpLost_ally = snd_GTH_cpLost_ally
snd_CIS_cpLost_enemy = snd_GTH_cpLost_enemy
elseif gCurrentMapManager.onlineSideVar == "SSVxCOL" or gCurrentMapManager.onlineSideVar == 2 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
elseif gCurrentMapManager.onlineSideVar == "EVGxGTH" or gCurrentMapManager.onlineSideVar == 3 then
snd_REP_cpCapture_ally = snd_EVG_cpCapture_ally
snd_REP_cpCapture_enemy = snd_EVG_cpCapture_enemy
snd_REP_cpLost_ally = snd_EVG_cpLost_ally
snd_REP_cpLost_enemy = snd_EVG_cpLost_enemy
snd_CIS_cpCapture_ally = snd_GTH_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_GTH_cpCapture_enemy
snd_CIS_cpLost_ally = snd_GTH_cpLost_ally
snd_CIS_cpLost_enemy = snd_GTH_cpLost_enemy
elseif gCurrentMapManager.onlineSideVar == "EVGxCOL" or gCurrentMapManager.onlineSideVar == 4 then
snd_REP_cpCapture_ally = snd_EVG_cpCapture_ally
snd_REP_cpCapture_enemy = snd_EVG_cpCapture_enemy
snd_REP_cpLost_ally = snd_EVG_cpLost_ally
snd_REP_cpLost_enemy = snd_EVG_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
elseif gCurrentMapManager.onlineSideVar == "SSVxRPR" or gCurrentMapManager.onlineSideVar == 5 then
snd_REP_cpCapture_ally = snd_SSV_cpCapture_ally
snd_REP_cpCapture_enemy = snd_SSV_cpCapture_enemy
snd_REP_cpLost_ally = snd_SSV_cpLost_ally
snd_REP_cpLost_enemy = snd_SSV_cpLost_enemy
snd_CIS_cpCapture_ally = snd_COL_cpCapture_ally
snd_CIS_cpCapture_enemy = snd_COL_cpCapture_enemy
snd_CIS_cpLost_ally = snd_COL_cpLost_ally
snd_CIS_cpLost_enemy = snd_COL_cpLost_enemy
end
end
for i, cp in pairs(self.commandPosts) do
SetProperty(cp.name, "VO_Rep_RepCapture", snd_REP_cpCapture_ally)
SetProperty(cp.name, "VO_Rep_CisCapture", snd_REP_cpCapture_enemy)
SetProperty(cp.name, "VO_Rep_RepLost", snd_REP_cpLost_ally)
SetProperty(cp.name, "VO_Rep_CisLost", snd_REP_cpLost_enemy)
SetProperty(cp.name, "VO_Cis_CisCapture", snd_CIS_cpCapture_ally)
SetProperty(cp.name, "VO_Cis_RepCapture", snd_CIS_cpCapture_enemy)
SetProperty(cp.name, "VO_Cis_CisLost", snd_CIS_cpLost_ally)
SetProperty(cp.name, "VO_Cis_RepLost", snd_CIS_cpLost_enemy)
UpdatePostMapMarker(cp.name)
end
if gCurrentMapManager.mapSize == "sm" or
gCurrentMapManager.mapSize == "xs" or
gCurrentMapManager.mapSize == "xxs" then
SetClassProperty("com_bldg_controlzone", "NeutralizeTime", 20)
SetClassProperty("com_bldg_controlzone", "CaptureTime", 15)
else
SetClassProperty("com_bldg_controlzone", "NeutralizeTime", 15)
SetClassProperty("com_bldg_controlzone", "CaptureTime", 10)
end
end
--==========
-- Set the number of guys in the level to number in game options
--==========
ScriptCB_SetNumBots(ScriptCB_GetCONNumBots())
--===============================
-- 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()
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 ObjectiveConquest")
return
end
--set AI goals
self.AIGoals = {}
if self.AIGoalWeight > 0.0 then
if gCurrentMapManager.gameMode == "conquest" then
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Conquest", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Conquest", 100*self.AIGoalWeight))
elseif gCurrentMapManager.gameMode == "tdm" then
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Deathmatch", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Deathmatch", 100*self.AIGoalWeight))
else
PrintLog("ERROR! MapManager was given invalid gameMode value! Value is `"..gCurrentMapManager.gameMode..
"`, should be `conquest` or `tdm`. Defaulting to Deathmatch goals")
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Deathmatch", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Deathmatch", 100*self.AIGoalWeight))
end
end
-- Create timers for CP capture messages
self.postCaptureMsgBufferTimer = CreateTimer("postCaptureMsgBufferTimer")
--ShowTimer(self.postCaptureMsgBufferTimer) -- uncomment me for test output!
--do an initial update on the state
UpdateState()
--=======================================
-- Event responses
--=======================================
-- command post capture message buffer timer
self.postCaptureMsgBufferTimerElapse = OnTimerElapse(
function(timer)
self.bCanShowCaptureMessage = true
end,
self.postCaptureMsgBufferTimer
)
local function OnBeginNeutralizeConquest(postPtr, holding)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
PrintLog("OnBeginNeutralize:", GetEntityName(postPtr), table.getn(holding))
if debug == true and table.getn(holding) > 0 then
tprint(holding)
end
self.commandPostAbortedNeutralize[GetEntityName(postPtr)] = 0
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Neutralizing
UpdatePostMapMarker(postPtr)
end
OnBeginNeutralize(OnBeginNeutralizeConquest)
OnAbortNeutralize(
function(postPtr, holding)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
-- OnAbortNeutralize gets spammed when initially called, so need to make sure that doesn't happen
if self.commandPostAbortedNeutralize[GetEntityName(postPtr)] == 1 then return end
PrintLog("OnAbortNeutralize:", GetEntityName(postPtr), table.getn(holding))
if debug == true and table.getn(holding) > 0 then
tprint(holding)
end
self.commandPostAbortedNeutralize[GetEntityName(postPtr)] = 1
if table.getn(holding) == 0 then
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Idle
end
-- OnBeginNeutralize only triggers on first neutralize so we need to do it manually after aborts
local capRegionName = GetCommandPostCaptureRegion(postPtr)
ActivateRegion(capRegionName)
self.postCaptureRegionEventHandlers[capRegionName] = OnEnterRegion(
function(region, character)
PrintLog("Entered region", capRegionName)
OnBeginNeutralizeConquest(postPtr, holding)
DeactivateRegion(capRegionName)
ReleaseEnterRegion(self.postCaptureRegionEventHandlers[capRegionName])
self.postCaptureRegionEventHandlers[capRegionName] = nil
end,
capRegionName
)
UpdatePostMapMarker(postPtr)
end
)
OnFinishNeutralize(
function(postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
PrintLog("OnFinishNeutralize:", GetEntityName(postPtr))
-- OnBeginCapture doesn't trigger when flowing straight through from neutralizing
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Capturing
UpdatePostMapMarker(postPtr)
UpdateState()
end
)
OnBeginCapture(
function(postPtr, holding)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
PrintLog("OnBeginCapture:", GetEntityName(postPtr), table.getn(holding))
if debug == true and table.getn(holding) > 0 then
tprint(holding)
end
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Capturing
UpdatePostMapMarker(postPtr)
end
)
OnAbortCapture(
function(postPtr, holding)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
PrintLog("OnAbortCapture:", GetEntityName(postPtr), table.getn(holding))
if debug == true and table.getn(holding) > 0 then
tprint(holding)
end
if table.getn(holding) == 0 then
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Idle
end
UpdatePostMapMarker(postPtr)
end
)
OnFinishCapture(
function(postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
PrintLog("OnFinishCapture:", GetEntityName(postPtr))
self.commandPostStates[GetEntityName(postPtr)] = CommandPostCaptureState.Idle
ShowCaptureMessage(postPtr)
UpdatePostMapMarker(postPtr)
UpdateState()
end
)
OnCommandPostRespawn(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end
UpdatePostMapMarker(postPtr)
UpdateState()
end
)
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
)
-- spawn block for Husks --
OnTicketCountChange(
function (team, count)
if team == CIS and count <= 20 then
PrintLog("Blocking HuskTeam spawn")
AllowAISpawn(3, false)
end
end
)
-- player spawn
OnCharacterSpawn(
function (player)
if IsCharacterHuman(player) then
-- Update all of the post markers
for i, cp in pairs(self.commandPosts) do
UpdatePostMapMarker(cp.name)
end
end
end
)
end
function ObjectiveConquest:Complete(winningTeam)
PrintLog("Complete(): Entered")
if not self.multiplayerRules then
--remove all the cp markers
for i, cp in pairs(self.commandPosts) do
MapRemoveEntityMarker(cp.name)
end
end
--then call the default objective complete method
Objective.Complete(self, winningTeam)
end
PrintLog("Exited")