aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/_pain_death_sounds.gnut
blob: 10d2b6166dfa4b333f80469ebd5c7030b1e12765 (plain)
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
global function PainDeathSounds_Init
global function PlayDeathSounds
global function PlayPainSounds
global function TogglePainDeathDebug

struct PainOrDeathSound
{
	bool functionref( entity, entity, bool, int, int ) isSoundTypeFunc
	string alias_1p_victim_only
	string alias_3p_except_victim
	string alias_3p_attacker_only
	string alias_3p_except_attacker
	bool blocksPriority
	int priority
}

struct
{
	array< array<PainOrDeathSound> > painSounds
	array< array<PainOrDeathSound> > deathSounds

	bool painDeathDebug
} file


enum eBodyTypes
{
	NPC_ANDROID
	NPC_GRUNT
	NPC_MARVIN
	NPC_PROWLER
	NPC_SPECIALIST
	NPC_SPECTRE
	NPC_STALKER
	NPC_SUPER_SPECTRE
	PLAYER_ANDROID_FEMALE
	PLAYER_ANDROID_MALE
	PLAYER_HUMAN_FEMALE
	PLAYER_HUMAN_MALE
	TITAN
	total
}

int function GetBodyTypeIndexFromVictim( entity victim )
{
	// can add hologram support if needed
	if ( victim.IsHologram() )
		return -1

	if ( victim.IsTitan() )
		return eBodyTypes.TITAN

	if ( victim.IsPlayer() )
	{
		if ( victim.IsMechanical() )
		{
			if ( IsPlayerFemale( victim ) )
				return eBodyTypes.PLAYER_ANDROID_FEMALE

			return eBodyTypes.PLAYER_ANDROID_MALE
		}
		else
		{
			if ( IsPlayerFemale( victim ) )
				return eBodyTypes.PLAYER_HUMAN_FEMALE

			return eBodyTypes.PLAYER_HUMAN_MALE
		}
	}

	if ( IsSpecialist( victim ) )
		return eBodyTypes.NPC_SPECIALIST

	if ( IsGrunt( victim ) )
		return eBodyTypes.NPC_GRUNT

	if ( IsProwler( victim ) )
		return eBodyTypes.NPC_PROWLER

	if ( IsSuperSpectre( victim ) )
		return eBodyTypes.NPC_SUPER_SPECTRE

	if ( IsSpectre( victim ) )
		return eBodyTypes.NPC_SPECTRE

	if ( IsStalker( victim ) )
		return eBodyTypes.NPC_STALKER

	if ( IsMarvin( victim ) )
		return eBodyTypes.NPC_MARVIN

	return -1
}

void function PainDeathSounds_Init()
{
	file.painSounds.resize( eBodyTypes.total )
	file.deathSounds.resize( eBodyTypes.total )

	var dataTable = GetDataTable( $"datatable/pain_death_sounds.rpak" )
	int numRows = GetDatatableRowCount( dataTable )

	int eventColumn	 			= GetDataTableColumnByName( dataTable, "event" )
	int blocksPriorityColumn	= GetDataTableColumnByName( dataTable, "blocksNextPriority" )
	int methodColumn	 		= GetDataTableColumnByName( dataTable, "method" )
	int priorityColumn	 		= GetDataTableColumnByName( dataTable, "priority" )
	int bodyTypeColumn	 		= GetDataTableColumnByName( dataTable, "bodyType" )
	int alias_1p_victim_only_column = GetDataTableColumnByName( dataTable, "alias_1p_victim_only" )
	int alias_3p_except_victim_column = GetDataTableColumnByName( dataTable, "alias_3p_except_victim" )
	int alias_3p_attacker_only_column = GetDataTableColumnByName( dataTable, "alias_3p_attacker_only" )
	int alias_3p_except_attacker_column = GetDataTableColumnByName( dataTable, "alias_3p_except_attacker" )
	int visibleColumn			= GetDataTableColumnByName( dataTable, "spmp" )

 	table<string,bool> visibleMask
	visibleMask[ "spmp" ] <- true
	if ( IsMultiplayer() )
		visibleMask[ "mp" ] <- true
	else if ( IsSingleplayer() )
		visibleMask[ "sp" ] <- true

	for ( int i = 0; i < numRows; i++ )
	{
		string visible = GetDataTableString( dataTable, i, visibleColumn )
		if ( !( visible in visibleMask ) )
			continue

		int priority			 		= GetDataTableInt( dataTable, i, priorityColumn )
		bool blocksPriority		 		= GetDataTableBool( dataTable, i, blocksPriorityColumn )
		string event	 				= GetDataTableString( dataTable, i, eventColumn )
		string method	 				= GetDataTableString( dataTable, i, methodColumn )
		string bodyTypeName				= GetDataTableString( dataTable, i, bodyTypeColumn )
		string alias_1p_victim_only 	= GetDataTableString( dataTable, i, alias_1p_victim_only_column )
		string alias_3p_except_victim 	= GetDataTableString( dataTable, i, alias_3p_except_victim_column )
		string alias_3p_attacker_only 	= GetDataTableString( dataTable, i, alias_3p_attacker_only_column )
		string alias_3p_except_attacker = GetDataTableString( dataTable, i, alias_3p_except_attacker_column )
		int bodyType = eBodyTypes[ bodyTypeName ]

		PainOrDeathSound painOrDeathSound
		painOrDeathSound.isSoundTypeFunc 	= GetSoundTypeFuncFromName( method )
		painOrDeathSound.alias_1p_victim_only = alias_1p_victim_only
		painOrDeathSound.alias_3p_except_victim = alias_3p_except_victim
		painOrDeathSound.alias_3p_attacker_only = alias_3p_attacker_only
		painOrDeathSound.alias_3p_except_attacker = alias_3p_except_attacker
		painOrDeathSound.blocksPriority = blocksPriority
		painOrDeathSound.priority = priority

		#if DEV
		if ( priority < 100 || priority > 500 )
			CodeWarning( "PainDeathSound event priority must be between 100 and 500. See " + event + " " + method )
		#endif

		switch ( event )
		{
			case "pain":
				file.painSounds[ bodyType ].append( painOrDeathSound )
				break

			case "death":
				file.deathSounds[ bodyType ].append( painOrDeathSound )
				break

			default:
				CodeWarning( "Couldn't find pain/death event type " + event )
				break
		}
	}

	for ( int i = 0; i < eBodyTypes.total; i++ )
	{
		file.painSounds[ i ].sort( PainOrDeathSort )
		file.deathSounds[ i ].sort( PainOrDeathSort )
	}
}

int function PainOrDeathSort( PainOrDeathSound a, PainOrDeathSound b )
{
	if ( a.priority < b.priority )
		return -1
	if ( b.priority < a.priority )
		return 1
	return 0
}


bool functionref( entity, entity, bool, int, int ) function GetSoundTypeFuncFromName( string method )
{
	switch ( method )
	{
		case "SE_ANY":
			return SE_ANY

		case "SE_GIB":
			return SE_GIB

		case "SE_BULLET":
			return SE_BULLET

		case "SE_DISSOLVE":
			return SE_DISSOLVE

		case "SE_ELECTRICAL":
			return SE_ELECTRICAL

		case "SE_EXPLOSION":
			return SE_EXPLOSION

		case "SE_FALL":
			return SE_FALL

		case "SE_HEADSHOT_BULLET":
			return SE_HEADSHOT_BULLET

		case "SE_HEADSHOT_SHOTGUN":
			return SE_HEADSHOT_SHOTGUN

		case "SE_HEADSHOT_TITAN":
			return SE_HEADSHOT_TITAN

		case "SE_NECK_SNAP":
			return SE_NECK_SNAP

		case "SE_THERMITE_GRENADE":
			return SE_THERMITE_GRENADE

		case "SE_PROWLER":
			return SE_PROWLER

		case "SE_SMOKE":
			return SE_SMOKE

		case "SE_TITAN_STEP":
			return SE_TITAN_STEP
	}
}

bool function SE_ANY( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return true
}

bool function SE_GIB( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_GIB )
}

bool function SE_BULLET( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_BULLET )
}

bool function SE_DISSOLVE( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_DISSOLVE )
}

bool function SE_ELECTRICAL( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_ELECTRICAL )
}

bool function SE_EXPLOSION( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_EXPLOSION )
}

bool function SE_FALL( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return damageSourceID == eDamageSourceId.fall
}

bool function SE_HEADSHOT_BULLET( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	if ( !isValidHeadshot )
		return false

	return bool( damageTypes & DF_BULLET )
}

bool function SE_HEADSHOT_SHOTGUN( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	if ( !isValidHeadshot )
		return false

	return bool( damageTypes & DF_SHOTGUN )
}

bool function SE_HEADSHOT_TITAN( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	if ( !attacker.IsTitan() )
		return false

	return isValidHeadshot
}

bool function SE_NECK_SNAP( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return damageSourceID == eDamageSourceId.human_execution
}

bool function SE_THERMITE_GRENADE( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return damageSourceID == eDamageSourceId.mp_weapon_thermite_grenade
}

bool function SE_PROWLER( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	if ( !IsValid( attacker ) )
		return false

	return IsProwler( attacker )
}

bool function SE_SMOKE( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return damageSourceID == eDamageSourceId.mp_weapon_grenade_electric_smoke
}

bool function SE_TITAN_STEP( entity victim, entity attacker, bool isValidHeadshot, int damageTypes, int damageSourceID )
{
	return bool( damageTypes & DF_TITAN_STEP )
}

void function PlayPainSounds( entity victim, var damageInfo )
{
	int bodyType = GetBodyTypeIndexFromVictim( victim )
	if ( bodyType >= 0 )
		PlayPainOrDeathSounds( file.painSounds[ bodyType ], victim, damageInfo )
}

void function PlayDeathSounds( entity victim, var damageInfo )
{
	int bodyType = GetBodyTypeIndexFromVictim( victim )
	if ( bodyType >= 0 )
		PlayPainOrDeathSounds( file.deathSounds[ bodyType ], victim, damageInfo )
}

void function PlayPainOrDeathSounds( array<PainOrDeathSound> soundEvents, entity victim, var damageInfo )
{
	array<string> alias_1p_victim_only
	array<string> alias_3p_except_victim
	array<string> alias_3p_attacker_only
	array<string> alias_3p_except_attacker

	entity attacker = DamageInfo_GetAttacker( damageInfo )
	bool isValidHeadshot = IsValidHeadShot( damageInfo, victim )
	int damageTypes = DamageInfo_GetCustomDamageType( damageInfo )
	int damageSourceID = DamageInfo_GetDamageSourceIdentifier( damageInfo )

	int lastPriority = 0
	bool blockingPriority

	foreach ( painOrDeathSound in soundEvents )
	{
		Assert( painOrDeathSound.priority >= lastPriority )

		if ( blockingPriority )
		{
			if ( painOrDeathSound.priority > lastPriority )
				break
		}

		if ( painOrDeathSound.isSoundTypeFunc( victim, attacker, isValidHeadshot, damageTypes, damageSourceID ) )
		{
			if ( painOrDeathSound.alias_1p_victim_only != "" )
				alias_1p_victim_only.append( painOrDeathSound.alias_1p_victim_only )
			if ( painOrDeathSound.alias_3p_except_victim != "" )
				alias_3p_except_victim.append( painOrDeathSound.alias_3p_except_victim )
			if ( painOrDeathSound.alias_3p_attacker_only != "" )
				alias_3p_attacker_only.append( painOrDeathSound.alias_3p_attacker_only )
			if ( painOrDeathSound.alias_3p_except_attacker != "" )
				alias_3p_except_attacker.append( painOrDeathSound.alias_3p_except_attacker )

			blockingPriority = painOrDeathSound.blocksPriority || blockingPriority
		}

		lastPriority = painOrDeathSound.priority
	}

	foreach ( sound in alias_3p_except_victim )
	{
		EmitSoundOnEntity( victim, sound )
	}

	if ( victim.IsPlayer() )
	{
		foreach ( sound in alias_1p_victim_only )
		{
			EmitSoundOnEntityOnlyToPlayer( victim, victim, sound )
		}
	}

	if ( attacker.IsPlayer() )
	{
		foreach ( sound in alias_3p_except_attacker )
		{
			EmitSoundOnEntityExceptToPlayer( victim, attacker, sound )
		}

		foreach ( sound in alias_3p_attacker_only )
		{
			EmitSoundOnEntityOnlyToPlayer( victim, attacker, sound )
		}
	}
	else
	{
		foreach ( sound in alias_3p_except_attacker )
		{
			EmitSoundOnEntity( victim, sound )
		}
	}

	#if DEV
	if ( !file.painDeathDebug )
		return

	foreach ( sound in alias_3p_except_victim )
	{
		printt( "PAIN_DEATH_DEBUG: EmitSoundOnEntity - " + sound )
	}

	if ( victim.IsPlayer() )
	{
		foreach ( sound in alias_1p_victim_only )
		{
			printt( "PAIN_DEATH_DEBUG: EmitSoundOnEntityOnlyToPlayer - " + sound )
		}
	}

	if ( attacker.IsPlayer() )
	{
		foreach ( sound in alias_3p_except_attacker )
		{
			printt( "PAIN_DEATH_DEBUG: EmitSoundOnEntityExceptToPlayer - " + sound )
		}

		foreach ( sound in alias_3p_attacker_only )
		{
			printt( "PAIN_DEATH_DEBUG: EmitSoundOnEntityOnlyToPlayer - " + sound )
		}
	}
	else
	{
		foreach ( sound in alias_3p_except_attacker )
		{
			printt( "PAIN_DEATH_DEBUG: EmitSoundOnEntity - " + sound )
		}
	}
	#endif
}

void function TogglePainDeathDebug()
{
	file.painDeathDebug = !file.painDeathDebug
	printt( "PainDeathDebug is " + file.painDeathDebug )
}