-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathME5_ObjectiveOneFlagCTF.lua
583 lines (488 loc) · 18.8 KB
/
ME5_ObjectiveOneFlagCTF.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
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
local __SCRIPT_NAME = "ME5_ObjectiveOneFlagCTF";
local debug = true
local function PrintLog(...)
if debug == true then
print("["..__SCRIPT_NAME.."]", unpack(arg));
end
end
PrintLog("Entered")
ScriptCB_DoFile("ME5_Objective")
ScriptCB_DoFile("ME5_SoundEvent_ctf")
MEU_GameMode = "meu_1flag"
--=============================
-- ObjectiveCTF
-- Handles the logic for a capture the flag game
--=============================
ObjectiveOneFlagCTF = Objective:New
{
-- required external values
captureLimit = 5,
flag = "noname",
homeRegion = nil,
captureRegionATT = nil,
captureRegionDEF = nil,
capRegionDummyObjectATT = nil, --need dummy objects so we can add an in-HUD marker (regions can't be marked in the HUD currently...it's a long story)
capRegionDummyObjectDEF = nil,
-- optional external values
flagIcon = "hud_target_flag_onscreen",
flagIconScale = 3.0,
capRegionMarkerATT = "hud_objective_icon_circle",
capRegionMarkerDEF = "hud_objective_icon_circle",
capRegionMarkerScaleATT = 3.0,
capRegionMarkerScaleDEF = 3.0,
enemyFlagMessage = "game.oneflag.enemy.",
friendFlagMessage = "game.oneflag.friend.",
}
-- DESIGNERS: Override this function if necessary
function ObjectiveOneFlagCTF:OnCapture(flag, carrier)
end
function ObjectiveOneFlagCTF:OnTaken(flag, carrier)
end
-- Get game time limit as set in game options menu, if any. 0 if none.
function ObjectiveOneFlagCTF:GetGameTimeLimit()
return ScriptCB_GetCTFMaxTimeLimit()
end
function ObjectiveOneFlagCTF:GameOptionsTimeLimitUp()
local teamATTpts = GetTeamPoints(teamATT)
local teamDEFpts = GetTeamPoints(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
--
-- Initialize the capture objective
--
function ObjectiveOneFlagCTF:Start()
--=============================
-- local functions
--=============================
local GetOpposingTeam = function(team)
if team == self.teamATT then
return self.teamDEF
else
return self.teamATT
end
end
self.showTeamPoints = true
local FlagMessage = function(friendTeam, message)
if self.friendFlagMessage then
ShowMessageText(self.friendFlagMessage .. message, friendTeam)
end
local opposingTeam = GetOpposingTeam(friendTeam)
if self.enemyFlagMessage then
ShowMessageText(self.enemyFlagMessage .. message, opposingTeam)
end
local missionTime = ScriptCB_GetMissionTime()
local timeSinceLastPlayed = missionTime - self.lastVOPlayTime
if timeSinceLastPlayed > 3.0 then
SoundEvent_BroadcastVO( message, friendTeam, opposingTeam )
self.lastVOPlayTime = missionTime
end
end
local AddMarkers = function(team, bPulseFlag, bPulseCapRegion)
local capRegion
local capRegionMarker
local capRegionMarkerScale
local capRegionDummyObject
if team == self.teamATT then
capRegion = self.captureRegionATT
capRegionMarker = self.capRegionMarkerATT
capRegionMarkerScale = self.capRegionMarkerScaleATT
capRegionDummyObject = self.capRegionDummyObjectATT
elseif team == self.teamDEF then
capRegion = self.captureRegionDEF
capRegionMarker = self.capRegionMarkerDEF
capRegionMarkerScale = self.capRegionMarkerScaleDEF
capRegionDummyObject = self.capRegionDummyObjectDEF
else
return
end
if bPulseFlag then
--show an in-hud marker for the flag
MapAddEntityMarker(self.flag, self.flagIcon, self.flagIconScale, team, "YELLOW", true, false, true, true)
else
MapRemoveEntityMarker(self.flag)
end
if capRegionDummyObject then
if bPulseCapRegion then
--show an in-hud marker for the region
MapAddEntityMarker(capRegionDummyObject, capRegionMarker, capRegionMarkerScale, team, "YELLOW", bPulseCapRegion, false, bPulseCapRegion)
else
MapRemoveEntityMarker(capRegionDummyObject)
end
else
if bPulseCapRegion then
--show the region on the map only
MapAddRegionMarker(GetRegion(capRegion), capRegionMarker, capRegionMarkerScale,
team, "YELLOW", true, false, true)
else
MapRemoveRegionMarker(GetRegion(capRegion))
end
end
end
local UpdateMarkerPulses = function()
if not self.flagIcon then
return end
if self.carrier then
local carrierTeam = GetCharacterTeam(self.carrier)
local otherTeam = GetOpposingTeam(carrierTeam)
--for the carrier team, turn on the pulsey on the cap region, turn it off for the flag
AddMarkers(carrierTeam, false, true)
--for the other team, turn off the pulsey on the flag, and turn off the pulsey for the cap region
AddMarkers(otherTeam, false, false)
else
--for both teams, turn the pulsey on the flag, and turn off the pulsey for the cap region
AddMarkers(self.teamATT, true, false)
AddMarkers(self.teamDEF, true, false)
end
end
local CaptureFlag = function(carrierTeam)
AddFlagCapturePoints(GetFlagCarrier(self.flag))
FlagMessage(carrierTeam, "captured")
AddTeamPoints(carrierTeam, 1)
self:OnCapture(self.flag, self.carrier)
self.carrier = nil
KillObject(self.flag)
end
--==========
-- Set the number of guys in the level to number in game options
--==========
ScriptCB_SetNumBots(ScriptCB_GetCTFNumBots())
--===============================
-- Initialization logic
--===============================
--initialize the base objective data first-----
Objective.Start(self)
-- initialize internal values------------------
self.lastVOPlayTime = -100000.0
--just in case a player is already standing right where the flag spawns in...
self.carrier = GetFlagCarrier(self.flag)
if self.carrier then
UpdateMarkerPulses()
FlagMessage(GetCharacterTeam(self.carrier), "taken")
self:OnTaken(self.flag, self.carrier)
end
-- set AI goals
local flagPtr = GetObjectPtr(self.flag)
assert(flagPtr, "ERROR: flag "..self.flag.." does not exist in the map")
self.AIGoals = {}
if self.AIGoalWeight > 0.0 then
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "CTFOffense", 100*self.AIGoalWeight, self.captureRegionATT, flagPtr))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "CTFOffense", 100*self.AIGoalWeight, self.captureRegionDEF, flagPtr))
end
ActivateRegion(self.captureRegionATT)
ActivateRegion(self.captureRegionDEF)
UpdateMarkerPulses(self.flag)
if self.multiplayerRules then
self.captureLimit = ScriptCB_GetCTFCaptureLimit()
SetReinforcementCount(self.teamATT, -1)
SetReinforcementCount(self.teamDEF, -1)
SetFlagGameplayType("1flag") --let C++ know that we're running 1flag at the moment
else
SetFlagGameplayType("campaign")
end
if(self.homeRegion) then
SetProperty(self.flag, "HomeRegion", self.homeRegion)
ActivateRegion(self.homeRegion)
end
--=======================================
-- Event responses
--=======================================
-- flag reset to starting position
OnFlagReset(
function (flagPtr)
if self.isComplete then return end
local flagName = GetEntityName(flagPtr)
if self.flag ~= flagName then
return
end
-- set as not moved
self.carrier = nil
-- force enter-region event for anyone in the home region
if self.homeRegion then
DeactivateRegion(self.homeRegion)
ActivateRegion(self.homeRegion)
end
UpdateMarkerPulses(self.flag)
end
)
OnFlagPickUp(
function(flagPtr, carrierObj)
if self.isComplete then return end
local flagName = GetEntityName(flagPtr)
if self.flag ~= flagName then
assert("self.flag:", self.flag, " does not equal flagName:", flagName, " (don't forget flags cant have capitals in their names!)")
return
end
local carrierTeam = GetCharacterTeam(carrierObj)
self.carrier = carrierObj
--if the flag is in its capture region, cap the flag
if IsCharacterInRegion(carrierObj, self.captureRegion) and CanCharacterInteractWithFlag(carrierObj) then
CaptureFlag(carrierTeam)
else
FlagMessage(carrierTeam, "taken")
end
ScriptCB_SndPlaySound("common_flagAction_pickup")
UpdateMarkerPulses(self.flag)
end
)
OnFlagDrop(
function(flagPtr, carrierObj)
if self.isComplete then return end
local flagName = GetEntityName(flagPtr)
if self.flag ~= flagName then
return
end
self.carrier = nil
ScriptCB_SndPlaySound("common_flagAction_drop")
FlagMessage(GetCharacterTeam(carrierObj), "dropped")
UpdateMarkerPulses(self.flag)
end
)
--when a carrier enters the attacker's capture region
OnEnterRegion(
function(region, character)
if self.isComplete then return end
if not CanCharacterInteractWithFlag(character) then return end
if self.carrier == character then
local carrierTeam = GetCharacterTeam(character)
if carrierTeam == self.teamATT then
CaptureFlag(self.teamATT)
end
end
end,
self.captureRegionATT
)
--when a carrier enters the defender's capture region
OnEnterRegion(
function(region, character)
if self.isComplete then return end
if not CanCharacterInteractWithFlag(character) then return end
--just to be safe...
self.carrier = GetFlagCarrier(self.flag)
if self.carrier == character then
local carrierTeam = GetCharacterTeam(character)
if carrierTeam == self.teamDEF then
CaptureFlag(self.teamDEF)
end
end
end,
self.captureRegionDEF
)
-- team points change
OnTeamPointsChange(
function (team, points)
if self.isComplete then return end
if points >= self.captureLimit then
--SetFlagGameplayType("none") -- moved to objective:start
self:Complete(team)
end
end
)
end
-----------------------------------------------------
-- Sound cues for events
if not ScriptCB_InMultiplayer() then
if ME5_SideVar == 1 then
CTF_SoundEvents_Var = 1
elseif ME5_SideVar == 2 then
CTF_SoundEvents_Var = 2
elseif ME5_SideVar == 3 then
CTF_SoundEvents_Var = 3
elseif ME5_SideVar == 4 then
CTF_SoundEvents_Var = 4
end
else
if gCurrentMapManager.onlineSideVar == "SSVxGTH" or gCurrentMapManager.onlineSideVar == 1 then
CTF_SoundEvents_Var = 1
elseif gCurrentMapManager.onlineSideVar == "SSVxCOL" or gCurrentMapManager.onlineSideVar == 2 then
CTF_SoundEvents_Var = 2
elseif gCurrentMapManager.onlineSideVar == "EVGxGTH" or gCurrentMapManager.onlineSideVar == 3 then
CTF_SoundEvents_Var = 3
elseif gCurrentMapManager.onlineSideVar == "EVGxCOL" or gCurrentMapManager.onlineSideVar == 4 then
CTF_SoundEvents_Var = 4
end
end
if CTF_SoundEvents_Var == 1 then
gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = "ssv_adm_com_report_pickup_flag",
taken_def = "ssv_adm_com_report_enemyPickup_flag",
dropped_att = "ssv_adm_com_report_drop_flag",
dropped_def = "ssv_adm_com_report_enemyDrop_flag",
returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = "gth_ann_com_report_pickup_flag",
taken_def = "gth_ann_com_report_enemyPickup_flag",
dropped_att = "gth_ann_com_report_drop_flag",
dropped_def = "gth_ann_com_report_enemyDrop_flag",
returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}
elseif CTF_SoundEvents_Var == 2 then
gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = "ssv_adm_com_report_pickup_flag",
taken_def = "ssv_adm_com_report_enemyPickup_flag",
dropped_att = "ssv_adm_com_report_drop_flag",
dropped_def = "ssv_adm_com_report_enemyDrop_flag",
returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = "col_gen_com_report_pickup_flag",
taken_def = "col_gen_com_report_enemyPickup_flag",
dropped_att = "col_gen_com_report_drop_flag",
dropped_def = "col_gen_com_report_enemyDrop_flag",
returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}
elseif CTF_SoundEvents_Var == 3 then
gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = "evg_prm_com_report_pickup_flag",
taken_def = "evg_prm_com_report_enemyPickup_flag",
dropped_att = "evg_prm_com_report_drop_flag",
dropped_def = "evg_prm_com_report_enemyDrop_flag",
returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = "gth_ann_com_report_pickup_flag",
taken_def = "gth_ann_com_report_enemyPickup_flag",
dropped_att = "gth_ann_com_report_drop_flag",
dropped_def = "gth_ann_com_report_enemyDrop_flag",
returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}
elseif CTF_SoundEvents_Var == 4 then
gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = "evg_prm_com_report_pickup_flag",
taken_def = "evg_prm_com_report_enemyPickup_flag",
dropped_att = "evg_prm_com_report_drop_flag",
dropped_def = "evg_prm_com_report_enemyDrop_flag",
returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = "col_gen_com_report_pickup_flag",
taken_def = "col_gen_com_report_enemyPickup_flag",
dropped_att = "col_gen_com_report_drop_flag",
dropped_def = "col_gen_com_report_enemyDrop_flag",
returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}
end
PrintLog("Exited")