aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/vehicle/_vehicle_dropship_new.nut
blob: 87010ca74cc3efe73cf1fe10e0cb97af03a5d3a5 (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
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
untyped

global function VehicleDropshipNew_Init

global function InitLeanDropship
global function CreateDropship
global function GetDropshipSquadSize
global function WarpinEffect
global function WarpoutEffect
global function WarpoutEffectFPS
global function WaitForNPCsDeployed
global function CreateNPCSForDropship
global function GuyDeploysOffShip
global function WaittillPlayDeployAnims
global function GetDropshipRopeAttachments
global function DelayDropshipDelete
global function PlayDropshipRampDoorOpenSound
global function PlayWarpFxOnPlayers
global function DefensiveFreePlayers
global function CreateDropshipAnimTable

global function InitDropShipFlightPaths

// _dropship
//
// dropship/passenger setup:
// 1. Create an npc_dropship and target it with a point_template. Give the point_template a name.
// 2. npc_dropship targets starting path_track (see below for path setup info) AND passenger spawning point_template
// 3. passenger spawning point_template points to six passengers that will spawn and rappel at the unload spot
//
// path/unload spot setup:
// 1. create your path out of path_track entities
// 2. to create rappel targets, add six info_targets on the ground around your unload node, name them all the same
// 3. on the node where the dropship will unload, create a key/value pair called "unload" and point it at the name you gave to the rappel target info_targets
//
// spawning in script:
// 1. use GetEnt to get the point_template that targets the dropship
// 2. pass that point_template into DropshipSpawn(), this returns with the dropship ent
// 3. pass the dropship ent into DropshipDropshipFlyPathAndUnload() (thread it off if you want to do stuff right after)
//


const FX_DROPSHIP_THRUSTERS = $"xo_atlas_jet_large"
const FX_GUNSHIP_DAMAGE =  $"veh_gunship_damage_FULL"
const FX_DROPSHIP_DEATH = $"P_veh_exp_crow"

const DROPSHIP_ROPE_ENDPOINT_FX = $"runway_light_blue"
const DROPSHIP_ACL_LIGHT_GREEN_FX = $"acl_light_green"
const DROPSHIP_ACL_LIGHT_RED_FX = $"acl_light_red"
const DROPSHIP_ACL_LIGHT_WHITE_FX = $"acl_light_white"

const ENGAGEMENT_DIST = 1024
const ENGAGEMENT_DIST_SQD = ENGAGEMENT_DIST * ENGAGEMENT_DIST

const DEFAULT_READYANIM_BLENDTIME = 1.0

table file = {
	dropshipAttachments = null
}

function VehicleDropshipNew_Init()
{

	RegisterSignal( "sRampOpen" )
	RegisterSignal( "sRampClose" )

	#if SERVER
		PrecacheParticleSystem( FX_GUNSHIP_CRASH_EXPLOSION_ENTRANCE )
		PrecacheParticleSystem( FX_GUNSHIP_CRASH_EXPLOSION_EXIT )
		PrecacheParticleSystem( FX_DROPSHIP_DEATH )
		AddDeathCallback( "npc_dropship", OnNPCDropshipDeath )
		AddDamageCallback( "npc_dropship", OnDropshipDamaged )
	#endif

	PrecacheParticleSystem( FX_HORNET_DEATH )
	PrecacheParticleSystem( FX_GUNSHIP_DAMAGE )
	PrecacheParticleSystem( FX_DROPSHIP_THRUSTERS )
	PrecacheParticleSystem( DROPSHIP_ROPE_ENDPOINT_FX )
	PrecacheParticleSystem( DROPSHIP_ACL_LIGHT_GREEN_FX )
	PrecacheParticleSystem( DROPSHIP_ACL_LIGHT_RED_FX )
	PrecacheParticleSystem( DROPSHIP_ACL_LIGHT_WHITE_FX )

	level.DROPSHIP_DEFAULT_AIRSPEED <- 750

	PrecacheEntity( "keyframe_rope" )
	PrecacheModel( DROPSHIP_MODEL )

	PrecacheSprite( $"sprites/laserbeam.vmt" )
	PrecacheSprite( $"sprites/glow_05.vmt" )


	//Array of all attachments in the dropship model. Used in DropshipDamageEffects
	local names = []
	names.append( "FRONT_TURRET"      )
	names.append( "BOMB_L"            )
	names.append( "BOMB_R"            )
	names.append( "Spotlight"         )
	names.append( "Light_Red0"        )
	names.append( "Light_Red1"        )
	names.append( "Light_Red2"        )
	names.append( "Light_Red3"        )
	names.append( "HeadlightLeft"     )
	names.append( "RopeAttachLeftA"   )
	names.append( "RopeAttachLeftB"   )
	names.append( "RopeAttachLeftC"   )
	names.append( "L_exhaust_rear_1"  )
	names.append( "L_exhaust_rear_2"  )
	names.append( "L_exhaust_front_1" )
	names.append( "Light_Green0"      )
	names.append( "Light_Green1"      )
	names.append( "Light_Green2"      )
	names.append( "Light_Green3"      )
	names.append( "HeadlightRight"    )
	names.append( "RopeAttachRightA"  )
	names.append( "RopeAttachRightB"  )
	names.append( "RopeAttachRightC"  )
	names.append( "R_exhaust_rear_1"  )
	names.append( "R_exhaust_rear_2"  )
	names.append( "R_exhaust_front_1" )

	file.dropshipAttachments = names

	level.DSAIziplineAnims <- {}
	level.DSAIziplineAnims[ "left" ] <- []
	level.DSAIziplineAnims[ "left" ].append( { idle = "pt_dropship_rider_L_A_idle", attach = "RopeAttachLeftA" } )
	level.DSAIziplineAnims[ "left" ].append( { idle = "pt_dropship_rider_L_C_idle", attach = "RopeAttachLeftC" } )
	level.DSAIziplineAnims[ "left" ].append( { idle = "pt_dropship_rider_L_B_idle", attach = "RopeAttachLeftB" } )

	level.DSAIziplineAnims[ "right" ] <- []
	level.DSAIziplineAnims[ "right" ].append( { idle = "pt_dropship_rider_R_A_idle", attach = "RopeAttachRightA" } )
	level.DSAIziplineAnims[ "right" ].append( { idle = "pt_dropship_rider_R_C_idle", attach = "RopeAttachRightC" } )
	level.DSAIziplineAnims[ "right" ].append( { idle = "pt_dropship_rider_R_B_idle", attach = "RopeAttachRightB" } )

	level.DSAIziplineAnims[ "both" ] <- []
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_L_A_idle", attach = "RopeAttachLeftA" } )
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_R_A_idle", attach = "RopeAttachRightA" } )
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_L_C_idle", attach = "RopeAttachLeftC" } )
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_R_B_idle", attach = "RopeAttachRightC" } )
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_L_B_idle", attach = "RopeAttachLeftB" } )
	level.DSAIziplineAnims[ "both" ].append( { idle = "pt_dropship_rider_R_B_idle", attach = "RopeAttachRightB" } )
}

function InitLeanDropship( dropship )
{
	if ( dropship.kv.desiredSpeed.tofloat() <= 0 )
	{
		dropship.kv.desiredSpeed = level.DROPSHIP_DEFAULT_AIRSPEED
	}

	//dropship.s.dropFunc <- ShipDropsGuys
}

array<entity> function CreateNPCSForDropship( entity ship, array<entity functionref( int, vector, vector )> spawnFuncs, string side = "both" )
{
	int count = minint( spawnFuncs.len(), level.DSAIziplineAnims[ side ].len() )

	int team = ship.GetTeam()
	string squadName = expect string( ship.kv.squadname )
	vector origin = ship.GetOrigin()
	vector angles = ship.GetAngles()

	array<entity> guys = []

	if ( Flag( "disable_npcs" ) )
		return guys //i.e. empty aray

	local guy

	// this is to maintain sketchy support for just passing an array of 1 spawn function
	entity functionref( int, vector, vector ) spawnFunc = spawnFuncs[0]

	for ( int i = 0; i < count; i++ )
	{
		if ( i < spawnFuncs.len() )
			spawnFunc = spawnFuncs[i]

		entity guy = spawnFunc( team, origin, angles )
		guy.kv.squadname = squadName
		DispatchSpawn( guy )

		if ( !IsAlive( guy ) )
			continue

		guys.append( guy )

		local seat 	= i
		table Table = CreateDropshipAnimTable( ship, side, seat )

		thread GuyDeploysOffShip( guy, Table )
	}

	return guys
}



table function CreateDropshipAnimTable( ship, side, seat )
{
	table Table

	Table.idleAnim			<- level.DSAIziplineAnims[ side ][ seat ].idle
	Table.deployAnim		<- "zipline"
	Table.shipAttach 		<- level.DSAIziplineAnims[ side ][ seat ].attach
	Table.attachIndex 		<- null
	Table.ship 				<- ship
	Table.side				<- side
	Table.blendTime			<- DEFAULT_SCRIPTED_ANIMATION_BLEND_TIME

	return Table
}

function WaitForNPCsDeployed( npcArray )
{
	local ent = CreateScriptRef()
	ent.s.count <- 0

	OnThreadEnd(
		function() : ( ent )
		{
			if ( IsValid( ent ) )
				ent.Kill_Deprecated_UseDestroyInstead()
		}
	)

	local func =
		function( ent, guy )
		{
			ent.s.count++

			WaitSignal( guy, "npc_deployed", "OnDeath", "OnDestroy" )
			ent.s.count--

			if ( !ent.s.count )
				ent.Kill_Deprecated_UseDestroyInstead()
		}

	foreach ( entity guy in npcArray )
	{
		if ( IsAlive( guy ) )
			thread func( ent, guy )
	}

	ent.WaitSignal( "OnDestroy" )
}

function InitDropShipFlightPaths( spawnPoints )
{
	entity tempDropShip = CreateEntity( "prop_dynamic" )
	tempDropShip.kv.spawnflags = 0
	tempDropShip.SetModel( DROPSHIP_MODEL )

	DispatchSpawn( tempDropShip )

	foreach ( spawnPoint in spawnPoints )
	{
		tempDropShip.SetOrigin( spawnPoint.GetOrigin() )

		spawnPoint.s.dropShipPathAnims <- {}
		spawnPoint.s.dropShipPathAnims[ "gd_goblin_zipline_strafe" ] <- GetDropShipAnimOffset( tempDropShip, "gd_goblin_zipline_strafe", spawnPoint )
		spawnPoint.s.dropShipPathAnims[ "gd_goblin_zipline_dive" ] <- GetDropShipAnimOffset( tempDropShip, "gd_goblin_zipline_dive", spawnPoint )
	}

	tempDropShip.Destroy()
}

entity function CreateDropship( int team, vector origin, vector angles )
{
	entity dropship = CreateEntity( "npc_dropship" )
	dropship.kv.teamnumber = team
	dropship.SetOrigin( origin )
	dropship.SetAngles( angles )
	return dropship
}

function GetDropShipAnimOffset( dropShip, animName, refEnt )
{
	local animStart = dropShip.Anim_GetStartForRefPoint_Old( animName, refEnt.GetOrigin(), refEnt.GetAngles() )
	return animStart.origin - refEnt.GetOrigin()
}



function GetDropshipSquadSize( squadname )
{
	local squadsize = 0
	array<entity> dropships = GetNPCArrayByClass( "npc_dropship" )

	//printl( dropships.len()+ " dropships, checking squadname: " + squadname )
	foreach ( ship in dropships )
		if ( ship.kv.squadname == squadname )
			squadsize++

	//printl( dropships.len()+ " dropships, squadsize: " + squadsize )
	return squadsize
}

function DelayDropshipDelete( dropship )
{
	dropship.EndSignal( "OnDeath" )

	//very defensive check
	DefensiveFreePlayers( dropship )

	WaitFrame() // so the dropship wont pop out before it warps out

	dropship.Kill_Deprecated_UseDestroyInstead()
}

function DefensiveFreePlayers( dropship )
{
	array<entity> players = GetPlayerArrayOfTeam( dropship.GetTeam() )
	foreach ( player in players )
	{
		if ( !IsValid( player ) )
			continue

		if ( player.GetParent() != dropship )
			continue

		player.ClearParent() //Clear parent before dropship gets deleted with players still attached to it. Defensive fix for bug 178543

		KillPlayer( player, eDamageSourceId.fall )
	}
}

void function OnNPCDropshipDeath( entity dropship, var damageInfo )
{
	if ( !IsValid( dropship ) )
		return

	asset modelName = dropship.GetModelName()

	vector dropshipOrigin = dropship.GetOrigin()

	PlayFX( $"P_veh_exp_crow", dropshipOrigin )

	EmitSoundAtPosition( TEAM_UNASSIGNED, dropshipOrigin, "Goblin_Dropship_Explode" )
}

void function OnDropshipDamaged( entity dropship, var damageInfo )
{
	float damage = DamageInfo_GetDamage( damageInfo )

	//Tried to give visual shield indicator, but it doesn't seem to work?
	//DamageInfo_AddCustomDamageType( damageInfo, DF_SHIELD_DAMAGE )

	// store the damage so all hits can be tallied
	entity inflictor = DamageInfo_GetInflictor( damageInfo )
	Assert( IsValid( inflictor ) )//Done so we can still get the error in dev
	if ( !IsValid( inflictor ) ) //JFS Defensive fix
		return

	StoreDamageHistoryAndUpdate( dropship, 120.0, DamageInfo_GetDamage( damageInfo ), inflictor.GetOrigin(), DamageInfo_GetCustomDamageType( damageInfo ), DamageInfo_GetDamageSourceIdentifier( damageInfo ), DamageInfo_GetAttacker( damageInfo ) )

	if ( DamageInfo_GetDamage( damageInfo ) < 450 )
		return

	vector pos = DamageInfo_GetDamagePosition( damageInfo )
	PlayFX( FX_GUNSHIP_DAMAGE, pos )
}

void function GuyDeploysOffShip( entity guy, table Table )
{
	guy.EndSignal( "OnDeath" )
	entity ship 		= expect entity( Table.ship )
	local shipAttach 	= Table.shipAttach

	OnThreadEnd(
		function() : ( guy, ship )
		{
			if ( !IsValid( guy ) )
				return

			if ( ship != null )
			{
				if ( !IsAlive( ship ) && IsAlive( guy ) )
				{
					// try to transfer the last attacker from the ship to the attached guys.
					entity attacker = null
					entity lastAttacker = GetLastAttacker( ship )
					if ( IsValid( lastAttacker ) )
						attacker = lastAttacker

					guy.TakeDamage( 500, attacker, attacker, null )
				}
			}

			if ( !IsAlive( guy ) )
				guy.BecomeRagdoll( Vector(0,0,0), false )
			}
	)

	guy.SetEfficientMode( true )
	HideName( guy )

	Assert( shipAttach, "Ship but no shipAttach" )
	ship.EndSignal( "OnDeath" )
	GuyAnimatesRelativeToShipAttachment( guy, Table )

	WaittillPlayDeployAnims( ship )

	GuyAnimatesOut( guy, Table )
}

function WaittillPlayDeployAnims( ref )
{
	waitthread WaittillPlayDeployAnimsThread( ref )
}

function WaittillPlayDeployAnimsThread( ref )
{
	ref.EndSignal( "OnDeath" )

	ref.WaitSignal( "deploy" )
}

void function GuyAnimatesOut( entity guy, table Table )
{
	switch ( Table.side )
	{
		case "left":
		case "right":
		case "both":
		case "zipline":
			waitthread GuyZiplinesToGround( guy, Table )
			break

		default:
			thread PlayAnim( guy, Table.deployAnim, Table.ship, Table.shipAttach )
			break
	}


	guy.SetEfficientMode( false )
	guy.SetNameVisibleToOwner( true )

	WaittillAnimDone( guy )
	guy.ClearParent()

	UpdateEnemyMemoryFromTeammates( guy )

	guy.Signal( "npc_deployed" )
}

function GuyAnimatesRelativeToShipAttachment( guy, Table )
{
	expect entity( guy )
	Table.attachIndex <- Table.ship.LookupAttachment( Table.shipAttach )
	guy.SetOrigin( Table.ship.GetOrigin() )

	guy.SetParent( Table.ship, Table.shipAttach, false, 0 )

	guy.Anim_ScriptedPlay( Table.idleAnim )
}

table<string, array<string> > function GetDropshipRopeAttachments( string side = "both" )
{
	table<string, array<string> > attachments

	if ( side == "both" )
	{
		attachments[ "left" ] <- []
		attachments[ "right" ] <- []

		foreach ( seat, Table in level.DSAIziplineAnims[ "left"] )
		{
			attachments[ "left" ].append( expect string( Table.attach ) )
		}

		foreach ( seat, Table in level.DSAIziplineAnims[ "right"] )
		{
			attachments[ "right" ].append( expect string( Table.attach ) )
		}
	}
	else
	{
		attachments[ side ] <- []

		foreach ( seat, Table in level.DSAIziplineAnims[ side ] )
		{
			attachments[ side ].append( expect string( Table.attach ) )
		}
	}

	return attachments
}

function PlayDropshipRampDoorOpenSound( entity dropship )
{
	entity snd = CreateOwnedScriptMover( dropship )
	snd.SetParent( dropship, "RAMPDOORLIP" )

	EmitSoundOnEntity( snd, "fracture_scr_intro_dropship_dooropen" )
}

void function WarpoutEffect( entity dropship )
{
	if ( !IsValid( dropship ) )
		return

	__WarpOutEffectShared( dropship )

	thread DelayDropshipDelete( dropship )
}

void function WarpoutEffectFPS( entity dropship )
{
	__WarpOutEffectShared( dropship )
}

void function WarpinEffect( asset model, string animation, vector origin, vector angles, string sfx = "" )
{
	//we need a temp dropship to get the anim offsets
	Point start = GetWarpinPosition( model, animation, origin, angles )

	__WarpInEffectShared( start.origin, start.angles, sfx )
}

function PlayWarpFxOnPlayers( guys )
{
	foreach ( entity guy in guys )
	{
		if ( !IsAlive( guy ) )
			continue

		Remote_CallFunction_Replay( guy, "ServerCallback_PlayScreenFXWarpJump" )
	}
}