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
|
untyped
global function DialogueScheduleServer_Init
global function GetConversationIndex
global function PlaySquadConversationToPlayer
global function PlaySquadConversationToTeam
global function PlaySquadConversationToAll
global function PlaySpectreChatterToAll
global function PlaySpectreChatterToTeam
global function PlaySpectreChatterToPlayer
global function PlaySquadConversation
global function PlayConversationToPlayer
global function Delayed_PlayConversationToPlayer
global function PlayConversationToTeam
global function PlayConversationToAll
global function PlayConversationToAllExcept
global function PlayConversationToTeamExceptPlayer
global function ForcePlayConversationToPlayer
global function ForcePlayConversationToAll
global function ForcePlayConversationToTeam
global function SetGlobalForcedDialogueOnly
global function SetPlayerForcedDialogueOnly
global function CodeCallback_ScriptedDialogue
global function GetNearbyEnemyGrunts
global function GetNearbyFriendlyGrunts
global function CodeCallback_OnNPCLookAtHint
global function ScriptDialog_PilotCloaked
struct
{
array< void functionref( entity ) > codeDialogueFunc
} file
void function DialogueScheduleServer_Init()
{
#document( "PlayConversationToPlayer", " Play conversation passed in to player specified" )
// dialogue that comes from ai schedule notifies
// must match order of enum eCodeDialogueID
file.codeDialogueFunc = [
CodeDialogue_ManDown,
CodeDialogue_GruntSalute,
CodeDialogue_EnemyContact, //As per Conger's advice: Don't depend on this one. Use WaitSignal( guy, "OnFoundEnemy", "OnSeeEnemy", "OnLostEnemy" )
CodeDialogue_RunFromEnemy,
CodeDialogue_Reload,
CodeDialogue_MoveToAssault,
CodeDialogue_MoveToSquadLeader,
CodeDialogue_FanOut,
CodeDialogue_TakeCoverFromEnemy,
CodeDialogue_ChaseEnemy,
CodeDialogue_GrenadeOut,
CodeDialogue_DangerousAreaDisplace,
CodeDialogue_ReactSurprised,
]
Assert( file.codeDialogueFunc.len() == eCodeDialogueID.DIALOGUE_COUNT )
}
void function ScriptDialog_PilotCloaked( entity guy, entity enemy )
{
Assert( IsPilot( enemy ), "These dialog lines assume enemy is a pilot" )
if ( NPC_GruntChatterSPEnabled( guy ) )
{
#if GRUNTCHATTER_ENABLED
GruntChatter_TryCloakedPilotSpotted( guy, enemy )
#endif
}
else
{
#if GRUNT_CHATTER_MP_ENABLED
PlayGruntChatterMPLine( guy, "bc_engageenemycloakedpilot" )
#endif
}
}
void function CodeDialogue_GruntSalute( entity guy )
{
//EmitSoundOnEntity( guy, "grunt_salute" )
//PlaySquadConversationToAll( "grunt_salute" )
}
void function CodeDialogue_EnemyContact( entity guy ) //As per Conger's advice: Don't depend on this one. Use WaitSignal( guy, "OnFoundEnemy", "OnSeeEnemy", "OnLostEnemy" )
{
}
void function CodeDialogue_RunFromEnemy( entity guy )
{
//MP and SP use different systems.
#if GRUNT_CHATTER_MP_ENABLED
//MP, use PlayOneLinerConversationOnEntWithPriority() as base function
entity enemy = guy.GetEnemy()
if ( !IsAlive( enemy ) )
return
if ( enemy.IsTitan() )
PlayGruntChatterMPLine( guy, "bc_fleePlayerTitanCall" )
#else
//SP, use r1 style PlayConversation calls()
// only imc has these currently
if ( guy.GetTeam() != TEAM_IMC )
return
entity enemy = guy.GetEnemy()
if ( !IsAlive( enemy ) )
return
if ( enemy.IsTitan() )
{
local squadName = guy.Get( "squadname" )
bool isSquad = false
if ( squadName != "" )
{
array<entity> squad = GetNPCArrayBySquad( squadName )
isSquad = squad.len() > 1
}
if ( isSquad )
{
// has a safe hint? running to building
if ( guy.GetSafeHint() )
PlaySquadConversationToAll( "grunt_flees_titan_building", guy )
else
PlaySquadConversationToAll( "grunt_group_flees_titan", guy )
}
else
{
PlaySquadConversationToAll( "grunt_flees_titan", guy )
}
}
#endif
}
void function CodeDialogue_Reload( entity guy )
{
//PlaySquadConversationToAll( "aichat_reload", guy )
}
void function CodeDialogue_FanOut( entity guy )
{
}
void function CodeDialogue_MoveToSquadLeader( entity guy )
{
}
void function CodeDialogue_MoveToAssault( entity guy )
{
}
void function CodeDialogue_TakeCoverFromEnemy( entity guy )
{
#if HAS_BOSS_AI
if ( guy.IsTitan() )
BossTitanRetreat( guy )
#endif
}
void function CodeDialogue_ChaseEnemy( entity guy )
{
#if HAS_BOSS_AI
if ( guy.IsTitan() )
BossTitanAdvance( guy )
#endif
}
void function CodeDialogue_GrenadeOut( entity guy )
{
if ( NPC_GruntChatterSPEnabled( guy ) )
{
#if GRUNTCHATTER_ENABLED
// Ticks are actually thrown like grenades, but the callouts work differently because only Specialists use them
// TODO- move this info to the weapon data file
if ( guy.kv.grenadeWeaponName == "mp_weapon_frag_drone" )
GruntChatter_TryFriendlyEquipmentDeployed( guy, "mp_weapon_frag_drone" )
else
GruntChatter_TryThrowingGrenade( guy )
#endif
}
else
{
if ( IsSpectre( guy ) )
{
#if SPECTRE_CHATTER_MP_ENABLED
PlaySpectreChatterMPLine( guy, "diag_imc_spectre_gs_grenadeout_01_1" )
#else
PlaySpectreChatterToAll( "spectre_gs_grenadeout_01_1", guy )
#endif
}
else if ( IsGrunt( guy ) )
{
#if GRUNT_CHATTER_MP_ENABLED
PlayGruntChatterMPLine( guy, "bc_grenadeOutCall" )
#endif
}
}
}
void function CodeDialogue_DangerousAreaDisplace( entity guy )
{
#if GRUNT_CHATTER_MP_ENABLED
//MP ONly
string dangerousAreaWeaponName = guy.GetDangerousAreaWeapon()
//printt( "CodeDialogue_DangerousAreaDisplace, Dangerous weapon name: " + dangerousAreaWeaponName )
string conversationName = ""
switch ( dangerousAreaWeaponName ) //String comparison, not great...
{
case "mp_weapon_frag_grenade":
conversationName = "bc_grenadecall"
break
case "mp_weapon_thermite_grenade":
conversationName = "bc_reactGrenadeThermite"
break
case "mp_weapon_grenade_gravity": //By the time this triggers it looks like they're already being sucked in.
conversationName = "bc_reactGrenadeGravity"
break
case "mp_weapon_grenade_electric_smoke":
conversationName = "bc_reactGrenadeElecSmoke"
break
//Arc grenades have their dialogue triggered by PlayGruntChatterMP_DamagedByEMP() since arc grenades don't create dangerous areas
}
if( conversationName != "" )
PlayGruntChatterMPLine( guy, conversationName )
#endif
#if GRUNTCHATTER_ENABLED
//SP Only
if ( NPC_GruntChatterSPEnabled( guy ) )
GruntChatter_TryDisplacingFromDangerousArea( guy )
#endif
}
void function CodeDialogue_ReactSurprised( entity guy )
{
#if GRUNTCHATTER_ENABLED
if ( NPC_GruntChatterSPEnabled( guy ) )
{
int aiSurprisedReactionType = guy.GetSurprisedReactionReason()
switch ( aiSurprisedReactionType )
{
case RSR_SIDE_FLANK:
case RSR_REAR_FLANK:
GruntChatter_TryGruntFlankedByPlayer( guy, aiSurprisedReactionType )
break
}
}
#endif
}
void function CodeDialogue_ManDown( entity guy )
{
}
void function SetGlobalForcedDialogueOnly( bool value )
{
level.nv.forcedDialogueOnly = value
}
void function SetPlayerForcedDialogueOnly( entity player, bool value )
{
player.SetForcedDialogueOnly( value )
}
void function Delayed_PlayConversationToPlayer( string conversation, entity player, float delay )
{
player.EndSignal( "OnDeath" )
wait delay
PlayConversationToPlayer( conversation, player )
}
void function PlayConversationToPlayer( string conversationType, entity player )
{
if ( IsForcedDialogueOnly( player ) )
{
printt( "ForcedDialogueOnly, not playing conversationType: " + conversationType )
return
}
PlayConversation_internal( conversationType, player )
}
void function PlayConversationToTeam( string conversationType, int team )
{
array<entity> playerArr = GetPlayerArrayOfTeam( team )
foreach( player in playerArr )
PlayConversationToPlayer( conversationType, player )
}
void function PlayConversationToTeamExceptPlayer( string conversationType, int team, entity excludePlayer )
{
array<entity> playerArr = GetPlayerArrayOfTeam( team )
foreach( player in playerArr )
{
if ( player == excludePlayer )
continue
PlayConversation_internal( conversationType, player )
}
}
void function PlayConversationToAll( string conversationType )
{
array<entity> playerArr = GetPlayerArray()
foreach( player in playerArr )
PlayConversationToPlayer( conversationType, player )
}
void function PlayConversation_internal( string conversationType, entity player )
{
#if FACTION_DIALOGUE_ENABLED
return
#endif
int conversationID = GetConversationIndex( conversationType )
Remote_CallFunction_NonReplay( player, "ServerCallback_PlayConversation", conversationID )
}
void function ForcePlayConversationToAll( string conversationType )
{
array<entity> playerArr = GetPlayerArray()
foreach( player in playerArr )
{
ForcePlayConversationToPlayer( conversationType, player )
}
}
void function ForcePlayConversationToTeam( string conversationType, team )
{
array<entity> playerArr = GetPlayerArrayOfTeam( team )
foreach( player in playerArr )
{
ForcePlayConversationToPlayer( conversationType, player )
}
}
//Like PlayConversation, but no checking for flags
void function ForcePlayConversationToPlayer( string conversationType, entity player )
{
PlayConversation_internal( conversationType, player )
}
array<entity> function GetNearbyFriendlyGrunts( vector origin, int team, range = null )
{
float searchRange = AI_CONVERSATION_RANGE
if ( range != null )
searchRange = expect float( range )
array<entity> guys
array<entity> ai = GetNPCArrayEx( "npc_soldier", team, TEAM_ANY, origin, searchRange )
foreach ( guy in ai )
{
if ( IsAlive( guy ) )
guys.append( guy )
}
return guys
}
array<entity> function GetNearbyEnemyGrunts( vector origin, int team, range = null )
{
float searchRange = AI_CONVERSATION_RANGE
if ( range != null )
searchRange = expect float( range )
array<entity> guys
array<entity> ai = GetNPCArrayEx( "npc_soldier", TEAM_ANY, team, origin, searchRange )
foreach ( guy in ai )
{
if ( IsAlive( guy ) )
guys.append( guy )
}
return guys
}
bool function SquadExistsForConversation( entity ai, string conversationType )
{
if ( !IsAlive( ai ) )
return false
// only soldiers play squad conversations
if ( !IsGrunt( ai ) )
return false
//Squadless AI don't play squad conversations
local squadName = ai.Get( "squadname" )
if ( squadName == "" )
return false
// only all-soldier squads can use squad conversations
array<entity> squad = GetNPCArrayBySquad( squadName )
if ( !squad.len() )
return false
bool foundNonSoldier = false
foreach ( guy in squad )
{
if ( !IsGrunt( guy ) )
{
foundNonSoldier = true
break
}
}
if ( !(DoesConversationExist( conversationType ) ))
{
printt( "*****CONVERSATION WARNING***** Conversation " + conversationType + " does not exist! Returning" )
return false
}
return true
}
function GetSquadEHandles( ai )
{
expect entity( ai )
local aiHandles = [ null, null, null, null ]
string squadName = expect string( ai.Get( "squadname" ) )
if ( squadName == "" )
return aiHandles
array<entity> squad = GetNPCArrayBySquad( squadName )
squad.fastremovebyvalue( ai )
aiHandles[0] = ai.GetEncodedEHandle()
int nextIdx = 1
foreach ( guy in squad )
{
if ( !IsValid( guy ) )
continue
switch ( guy.GetClassName() )
{
case "npc_soldier":
aiHandles[ nextIdx ] = guy.GetEncodedEHandle()
++nextIdx
break
}
if ( nextIdx >= aiHandles.len() )
break
}
return aiHandles
}
void function PlaySquadConversationToPlayer( string conversationType, entity player, entity ai, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
if ( SquadExistsForConversation( ai, conversationType ) )
{
local aiHandles = GetSquadEHandles( ai )
PlaySquadConversationToPlayer_Internal( conversationType, player, ai, rangeSqr, aiHandles )
}
}
// All PlaySquadConversation functions eventually funnel down to this.
// Funciton is broken apart from PlaySquadConversationToPlayer since PlaySquadConversationToPlayer has
// a few expensive checks that only need to be run once for every conversation we're trying to play,
// as opposed to for every player we're trying to play a conversation to.
void function PlaySquadConversationToPlayer_Internal( string conversationType, entity player, entity ai, float rangeSqr, aiHandles )
{
#if GRUNT_CHATTER_MP_ENABLED
return
#endif
Assert( IsAlive( ai ), ai + " is dead." )
Assert( aiHandles.len() == 4 )
vector org = ai.GetOrigin()
float debounceTime = GetConversationDebounce( conversationType )
float allowedTime = Time() - debounceTime
// tell client to play conversation
int conversationID = GetConversationIndex( conversationType )
if ( !ShouldPlaySquadConversation( player, conversationType, allowedTime, org, rangeSqr ) )
return
UpdateConversationTracking( player, conversationType, Time() )
Remote_CallFunction_Replay( player, "ServerCallback_PlaySquadConversation", conversationID, aiHandles[0], aiHandles[1], aiHandles[2], aiHandles[3] )
}
void function PlaySquadConversation( string conversationType, entity ai )
{
PlaySquadConversationToAll( conversationType, ai )
}
void function PlaySquadConversationToAll( string conversationType, entity ai, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
if ( !SquadExistsForConversation( ai, conversationType ) )
return
local aiHandles = GetSquadEHandles( ai )
array<entity> players = GetPlayerArray()
foreach ( player in players )
{
PlaySquadConversationToPlayer_Internal( conversationType, player, ai, rangeSqr, aiHandles )
}
}
void function PlaySquadConversationToTeam( string conversationType, int team, entity ai, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
if ( !SquadExistsForConversation( ai, conversationType ) )
return
local aiHandles = GetSquadEHandles( ai )
array<entity> players = GetPlayerArrayOfTeam( team )
foreach ( player in players )
{
PlaySquadConversationToPlayer_Internal( conversationType, player, ai, rangeSqr, aiHandles )
}
}
void function PlaySpectreChatterToAll( string conversationType, entity spectre, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
PlaySpectreChatterToTeam( conversationType, TEAM_IMC, spectre, rangeSqr )
PlaySpectreChatterToTeam( conversationType, TEAM_MILITIA, spectre, rangeSqr )
}
void function PlaySpectreChatterToTeam( string conversationType, team, entity spectre, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
array<entity> players = GetPlayerArrayOfTeam( team )
foreach ( player in players )
{
PlaySpectreChatterToPlayer( conversationType, player, spectre, rangeSqr )
}
}
void function PlaySpectreChatterToPlayer( string conversationType, entity player, entity spectre, float rangeSqr = AI_CONVERSATION_RANGE_SQR )
{
//PrintFunc()
vector spectreOrigin = spectre.GetOrigin()
float debounceTime = DEFAULT_CONVERSATION_DEBOUNCE_TIME // Spectre conversations aren't as real as the Grunt ones- they don't get registered bc they just EmitSound
float allowedTime = Time() - debounceTime
string teamSpecificSoundAlias = GetSpectreTeamSpecificSoundAlias( spectre, conversationType )
if ( teamSpecificSoundAlias == "" )
// neutral AI don't have dialog
return
Assert( DoesAliasExist( teamSpecificSoundAlias ) )
//printt( "Trying to play spectre chatter: " + teamSpecificSoundAlias + " to player: " + player)
if ( !ShouldPlaySquadConversation( player, teamSpecificSoundAlias, allowedTime, spectreOrigin, rangeSqr ) )
return
UpdateConversationTracking( player, teamSpecificSoundAlias, Time() )
EmitSoundOnEntityOnlyToPlayer( spectre, player, teamSpecificSoundAlias )
}
string function GetSpectreTeamSpecificSoundAlias( entity spectre, string partialConversationAlias )
{
int spectreTeam = spectre.GetTeam()
if ( spectreTeam == TEAM_IMC )
return "diag_imc_" + partialConversationAlias
else if ( spectreTeam == TEAM_MILITIA )
return "diag_militia_" + partialConversationAlias
return ""
}
void function PlayConversationToAllExcept( string conversationType, array<entity> exceptions )
{
array<entity> playerArr = GetPlayerArray()
table<entity, int> exceptionsTable
foreach( exceptionPlayer in exceptions )
{
exceptionsTable[ exceptionPlayer ] <- 1
}
foreach ( player in playerArr )
{
if ( player in exceptionsTable )
continue
PlayConversationToPlayer( conversationType, player )
}
}
void function CodeCallback_ScriptedDialogue( entity guy, int dialogueID )
{
Assert( dialogueID < file.codeDialogueFunc.len() )
if ( dialogueID in file.codeDialogueFunc )
{
file.codeDialogueFunc[ dialogueID ]( guy )
}
}
function UpdateConversationTracking( player, conversationType, time )
{
if ( !(conversationType in player.s.lastAIConversationTime) )
player.s.lastAIConversationTime[ conversationType ] <- time
else
player.s.lastAIConversationTime[ conversationType ] = time
}
int function GetConversationIndex( string conversation )
{
Assert( conversation != "", "No conversation specified." )
Assert( typeof(conversation) == "string" )
return GetConversationToIndexTable()[ conversation ]
}
void function CodeCallback_OnNPCLookAtHint( entity npc, entity hint )
{
}
|