aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/rodeo/_rodeo.gnut
blob: 72ff58b781adee0ede41b3c0901f0eaf8470ff5e (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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
untyped

global function Rodeo_Init

global function CodeCallback_StartRodeo
global function CodeCallback_ForceEndRodeo
global function CodeCallback_EmbarkTitan
global function CodeCallback_EmbarkTitanFromGrapple

global function PlayerBeginsRodeo
global function WatchForPlayerJumpingOffRodeo
global function PlayerJumpsOffRodeoTarget
global function PlayerClimbsIntoRodeoPosition
global function rodeodebug

//-----------------------------------------------------------------------------
//  _rodeo.nut
//
//  The central location for rodeo, mostly a place to put code callbacks that
//  then call other things in other files based on the thing being rodeod.
//
//-----------------------------------------------------------------------------
//
// HOW TO ADD A NEW RODEO TYPE
//
// Create a new file for the rodeo type like _rodeo_prowler.nut and:
//      Implement "IsValid_NEWTYPE_RodeoTarget()"
//      Implement "GetRodeoPackage_RIDER_to_NEWTYPE_()"
//      Implement "_RIDER_Begins_NEWTYPE_Rodeo()"
//      Implement "_RIDER_LerpsInto_NEWTYPE_Rodeo()"
//
//   _RIDER_ is the rodeo rider type like "Player" or "Prowler"
//   _NEWTYPE_ is the new kind of rodeo target like "SuperSpectre" or "Drone"
//
// In _rodeo_shared.nut:
//		IncludeFile() the NEWTYPE file
// 		Add a hook for NEWTYPE in CodeCallback_OnRodeoAttach()
//		Add a hook for NEWTYPE in CodeCallback_IsValidRodeoTarget()
//		Add a hook for NEWTYPE in GetRodeoPackage() if needed
//
//-----------------------------------------------------------------------------

function Rodeo_Init()
{
	RodeoShared_Init()
	RodeoTitan_Init()
	RegisterSignal( "RodeoPointOfNoReturn" )
	AddCallback_OnTitanDoomed( OnTitanDoomed_Rodeo )
}


void function CodeCallback_EmbarkTitan( entity player, entity titan )
{
	if ( player.Lunge_IsActive() && (titan == player.Lunge_GetTargetEntity()) )
	{
		if ( PlayerCanImmediatelyEmbarkTitan( player, titan ) )
		{
			table embarkDirection = expect table( FindBestEmbark( player, titan ) )
			thread PlayerEmbarksTitan( player, titan, embarkDirection )
		}
	}
}

bool function CodeCallback_EmbarkTitanFromGrapple( entity player, entity titan )
{
	Assert( player.IsHuman() )
	Assert( titan.IsTitan() )

	if ( !PlayerCanEmbarkIntoTitan( player, titan ) )
		return false

	table ornull embarkDirection = expect table ornull( FindBestEmbark( player, titan, false ) )
	if ( !embarkDirection )
		return false

	expect table( embarkDirection )
	thread PlayerEmbarksTitan( player, titan, embarkDirection )

	return true
}


void function CodeCallback_StartRodeo( entity player, entity rodeoTarget )
{
	if ( IsMenuLevel() )
		return

	// Review: Good to remove?
	if ( GetBugReproNum() == 7205 )
	{
		thread RodeoTest( player, rodeoTarget )
		return
	}

	thread PlayerBeginsRodeo( player, player.p.rodeoPackage, rodeoTarget )
}


void function CodeCallback_ForceEndRodeo( entity player )
{
	ForceEndRodeo( player )
}

void function ForceEndRodeo( entity player )
{
	player.Signal( "RodeoOver" )
}


function RodeoTest( player, rodeoTarget )
{
	player.SetParent( rodeoTarget, "RODEO", false, 1 )
	wait 5
	player.ClearParent()
	Rodeo_Detach( player )
}

function PlayerBeginsRodeo( entity player, RodeoPackageStruct rodeoPackage, entity rodeoTarget )
{
	Assert( player.GetParent() == null )
	player.Lunge_ClearTarget()

	Assert( IsValid( player ) )
	Assert( IsValid( rodeoTarget ) )
	Assert( !player.IsTitan() )

	if ( rodeoTarget.IsTitan() )
		PlayerBeginsTitanRodeo( player, rodeoPackage, rodeoTarget )
	else
		PlayerBeginsNPCRodeo( player, rodeoPackage, rodeoTarget ) //Not tested very well since non-Titan Rodeo never really became a thing. Should work thought
}

function PlayerBeginsNPCRodeo( entity player, RodeoPackageStruct rodeoPackage, entity rodeoTarget )
{
	bool sameTeam = player.GetTeam() == rodeoTarget.GetTeam()
	bool playerWasEjecting = player.p.pilotEjecting // have to store this off here because the "RodeoStarted" signal below ends eject, so it will be too late to check it in actual rodeo function

	player.Signal( "RodeoStarted" )

	OnThreadEnd(
		function () : ( player, rodeoTarget )
		{
			RodeoPackageStruct rodeoPackage = player.p.rodeoPackage

			entity newRodeoTarget = rodeoTarget
			if ( IsValid( player ) )
			{
				player.Signal( "RodeoOver" )

				// Added via AddCallback_OnRodeoEnded
				foreach ( callbackFunc in level.onRodeoEndedCallbacks ) //TODO: Remove this!
				{
					callbackFunc( player )
				}

				// show name of the pilot again
				player.SetNameVisibleToFriendly( true )
				player.SetNameVisibleToEnemy( true )

				ClearPlayerAnimViewEntity( player )

				// blend out the clear anim view entity
				player.AnimViewEntity_SetLerpOutTime( 0.4 )

				player.ClearParent()
				player.Anim_Stop()
				player.SetOneHandedWeaponUsageOff()
				player.SetTitanSoulBeingRodeoed( null )
				player.UnforceStand()
				player.kv.PassDamageToParent = false
				player.TouchGround() // so you can double jump off

				StopSoundOnEntity( player, rodeoPackage.cockpitSound )
				StopSoundOnEntity( player, rodeoPackage.worldSound )

				if ( Rodeo_IsAttached( player ) )
				{
					Rodeo_Detach( player )
				}

				if ( IsAlive( player ) )
				{
					int attachIndex = newRodeoTarget.LookupAttachment( rodeoPackage.attachPoint )
					vector startPos = newRodeoTarget.GetAttachmentOrigin( attachIndex )

					if ( !PlayerCanTeleportHere( player, startPos, newRodeoTarget ) )
					{
						startPos = newRodeoTarget.GetOrigin()
						if ( !PlayerCanTeleportHere( player, startPos, newRodeoTarget ) )
							startPos = player.GetOrigin()
					}

					thread PlayerJumpsOffRodeoTarget( player, newRodeoTarget, startPos )
				}
			}
		}
	)

	rodeoTarget.EndSignal( "OnDestroy" )
	player.EndSignal( "OnDeath" )
	player.EndSignal( "RodeoOver" )

	string rodeoTargetType = rodeoPackage.rodeoTargetType

	thread WatchForPlayerJumpingOffRodeo( player )

	player.SetNameVisibleToFriendly( false ) // hide name of the pilot while he is rodeoing
	player.SetNameVisibleToEnemy( false )
	player.ForceStand()
	HolsterAndDisableWeapons( player )
	player.SetOneHandedWeaponUsageOn()
	player.TouchGround() // so you can double jump off

	waitthread PlayerClimbsIntoRodeoPosition( player, rodeoTarget, rodeoPackage, playerWasEjecting )

	#if FACTION_DIALOGUE_ENABLED
	if ( !sameTeam )
		PlayFactionDialogueToPlayer( "kc_rodeo", player )
	#endif

	// Go straight into idle animations
	FirstPersonSequenceStruct sequence
	sequence.thirdPersonAnimIdle 	= GetAnimFromAlias( rodeoTargetType, "pt_rodeo_panel_aim_idle" )
	sequence.firstPersonAnimIdle 	= GetAnimFromAlias( rodeoTargetType, "ptpov_rodeo_panel_aim_idle" )

	if ( !rodeoPackage.useAttachAngles )
		player.Anim_IgnoreParentRotation( true )

	sequence.useAnimatedRefAttachment  = true

	thread FirstPersonSequence( sequence, player, rodeoTarget )

	if ( sameTeam )
	{
		player.GetFirstPersonProxy().HideFirstPersonProxy()
		OpenViewCone( player )
	}
	else
	{
		PlayerRodeoViewCone( player, rodeoTargetType )   // TODO: Add air_drone and make enum in this func()
	}

	// look! he rodeoed!
	thread AIChatter( "aichat_rodeo_cheer", player.GetTeam(), player.GetOrigin() )

	Rodeo_OnFinishClimbOnAnimation( player ) // This is to let code know the player has finished climbing on the rodeo and ready to fire

	if ( sameTeam )
	{
		player.PlayerCone_Disable()
		player.EnableWorldSpacePlayerEyeAngles()
	}

	DeployAndEnableWeapons( player )

	WaitForever()
}

void function PlayerClimbsIntoRodeoPosition( entity player, entity rodeoTarget, RodeoPackageStruct rodeoPackage, bool playerWasEjecting = false ) //TODO: Rename this function since new style rodeo anims have climbing as part of the anim
{
	player.EndSignal( "OnDeath" )


	// The only thing that should have a soul is titans now. Legacy. Can't remove without major code feature work.
	entity soul
	if ( rodeoTarget.IsTitan() )
	{
		soul = rodeoTarget.GetTitanSoul()
		soul.EndSignal( "OnTitanDeath" )
		soul.EndSignal( "OnDestroy" )
	}
	else
	{
		rodeoTarget.EndSignal( "OnTitanDeath" )
		rodeoTarget.EndSignal( "OnDestroy" )
	}

	FirstPersonSequenceStruct sequence
	sequence.attachment =  rodeoPackage.attachPoint
	SetRodeoAnimsFromPackage( sequence, rodeoPackage )

	switch ( rodeoPackage.method )
	{
		case RODEO_APPROACH_FALLING_FROM_ABOVE:
			table animStartPos = player.Anim_GetStartForRefEntity_Old( sequence.thirdPersonAnim, rodeoTarget, rodeoPackage.attachPoint )
			float dist = Distance( player.GetOrigin(), animStartPos.origin )
			float speed = Length( player.GetVelocity() )
			float fallTime = dist / speed
			fallTime *= 0.95

			sequence.blendTime = clamp( fallTime, 0.4, 1 )

			break

		case RODEO_APPROACH_JUMP_ON:
			sequence.blendTime = 0.6
			break

		default:
			Assert( 0, "Unhandled rodeo method " + rodeoPackage.method )
	}

	if ( !PlayerHasPassive( player, ePassives.PAS_STEALTH_MOVEMENT ) )
		EmitDifferentSoundsOnEntityForPlayerAndWorld( rodeoPackage.cockpitSound, rodeoPackage.worldSound, player, rodeoTarget )

	string titanType

	// Titans only
	if ( IsValid( soul ) )
	{
		if ( !( player in soul.rodeoRiderTracker ) )
		{
			soul.rodeoRiderTracker[ player ] <- true
			if ( rodeoTarget.GetTeam() == player.GetTeam() )
			{
				AddPlayerScore( player, "HitchRide" )
				AddPlayerScore( rodeoTarget, "GiveRide" )
			}
			else
			{
				AddPlayerScore( player, "RodeoEnemyTitan" )

				#if HAS_STATS
				UpdatePlayerStat( player, "misc_stats", "rodeos" )

				if ( playerWasEjecting )
					UpdatePlayerStat( player, "misc_stats", "rodeosFromEject" )
				#endif

				#if SERVER && MP
					PIN_AddToPlayerCountStat( player, "rodeos" )
					if ( rodeoTarget.IsPlayer() )
						PIN_AddToPlayerCountStat( rodeoTarget, "rodeo_receives" )
				#endif
			}
		}

		titanType = GetSoulTitanSubClass( soul )
	}

	MessageToPlayer( player, eEventNotifications.Rodeo_HideBatteryHint )

	float time = player.GetSequenceDuration( sequence.thirdPersonAnim )

	if ( !rodeoPackage.useAttachAngles )
		player.Anim_IgnoreParentRotation( true )

	thread FirstPersonSequence( sequence, player, rodeoTarget )
	wait time
}

void function WatchForPlayerJumpingOffRodeo( entity player )
{
	player.EndSignal( "OnDeath" )
	player.EndSignal( "RodeoOver" )
	player.EndSignal( "RodeoPointOfNoReturn" )

	wait 0.6 // debounce so you dont accihop

	AddButtonPressedPlayerInputCallback( player, IN_JUMP, ForceEndRodeo )

	OnThreadEnd(
	function() : ( player )
		{
			//RodeoOver is signalled at the end of PlayerBeginsRodeo, so even if Rodeo ends via the Titan disconnecting etc this will run
			RemoveButtonPressedPlayerInputCallback( player, IN_JUMP, ForceEndRodeo )
		}
	)

	WaitForever()
}


void function PlayerJumpsOffRodeoTarget( entity player, entity rodeoTarget, vector startPos )
{
	#if DEV
		if ( GetDebugRodeoPrint() )
			printt( "PlayerJumpsOffRodeoTarget, playerPos: " + player.GetOrigin() + " playerAngles: " + player.GetAngles() + " rodeoTargetPos: " + rodeoTarget.GetOrigin() + " rodeoTargetAngles: " + rodeoTarget.GetAngles() + ", startPos: " + startPos )
	#endif

	// ejected, or rip off battery, etc. Those adjust velocity for the rodeo player anyway, so don't do any more adjustments for them.
	if ( player.p.rodeoShouldAdjustJumpOffVelocity == false )
		return

	if ( !IsValid( rodeoTarget ) )
	{
		PutEntityInSafeSpot( player, null, null, startPos, player.GetOrigin() )

		#if DEV
			if ( GetDebugRodeoPrint() )
				printt( "PlayerJumpsOffRodeoTarget, playerPos after PutEntityInSafeSpot, !ISValid(rodeoTarget): " + player.GetOrigin() )
		#endif
		return
	}

	PutEntityInSafeSpot( player, rodeoTarget, null, startPos, player.GetOrigin() )
	#if DEV
		if ( GetDebugRodeoPrint() )
			printt( "PlayerJumpsOffRodeoTarget, playerPos after PutEntityInSafeSpot, rodeoTarget valid: " + player.GetOrigin() )
	#endif

	EmitDifferentSoundsOnEntityForPlayerAndWorld( "Rodeo_Jump_Off_Interior", "Rodeo_Jump_Off", player, rodeoTarget )

	vector forward = player.GetViewForward()
	vector right = player.GetViewRight()

	forward.z = 0
	right.z = 0

	// map the player's controls to his angles, and add that velocity
	float xAxis = player.GetInputAxisRight()
	float yAxis = player.GetInputAxisForward()

	vector velocity
	if ( fabs( xAxis ) < 0.2 && fabs( yAxis ) < 0.2 )
	{
	    // no press = back press
	    velocity = Vector(0,0,0)
	}
	else
	{
	    vector forwardVec = forward * yAxis
	    vector rightVec = right * xAxis
	    vector directionVec = ( rightVec + forwardVec )

	    //printt( "ForwardVec: " + forwardVec + ", rightVec: " + rightVec + ", directionVec :" + directionVec + ", directionVec scaled: " + (directionVec * 350 ) ) // for bug 123013

	    float speed = 350
	    velocity = directionVec * speed
	}

	// IMPORTANT: Don't give boost pilots too much vertical or they go sky high
	if ( player.GetPlayerSettingsField( "boostEnabled" ).tointeger() > 0 )
	    velocity += Vector(0,0,200)
	else
	    velocity += Vector(0,0,390 )

	//printt( "Setting velocity to: " + velocity ) // for bug 123013

	player.SetVelocity( velocity )
	player.JumpedOffRodeo()
}

void function rodeodebug()
{
	// console command for forcing rodeo amongst 2 players
	thread makerodeothread()
}

void function makerodeothread()
{
	array<entity> players = GetPlayerArray()
	vector titanOrg
	bool titanOrgSet = false
	entity titan, pilot

	for ( int i = players.len() - 1; i >= 0; i-- )
	{
		entity player = players[i]

		if ( player.IsTitan() )
		{
			titan = player
		}
		else
		{
			pilot = player
		}
	}

	if ( !titan )
	{
		for ( int i = players.len() - 1; i >= 0; i-- )
		{
			entity player = players[i]

			if ( !player.IsTitan() )
			{
				player.SetPlayerSettings( "titan_atlas" )
				titan = player
				break
			}
		}
	}
	else
	if ( !pilot )
	{
		for ( int i = players.len() - 1; i >= 0; i-- )
		{
			entity player = players[i]

			if ( player.IsTitan() )
			{
				thread TitanEjectPlayer( player )
				wait 1.5
				pilot = player
				break
			}
		}
	}

	for ( int i = players.len() - 1; i >= 0; i-- )
	{
		entity player = players[i]

		if ( player.IsTitan() )
		{
			titanOrg = player.GetOrigin()
			titanOrgSet = true
		}
	}

	if ( !titanOrgSet )
		return

	for ( int i = players.len() - 1; i >= 0; i-- )
	{
		entity player = players[i]

		if ( !player.IsTitan() )
		{
			vector angles = titan.GetAngles()
			vector forward = AnglesToForward( angles )
			titanOrg += forward * -100
			titanOrg.z += 500
			angles.x = 30
			player.SetAngles( angles )
			player.SetOrigin( titanOrg )
			player.SetVelocity( Vector(0,0,0) )
			break
		}
	}
}

void function OnTitanDoomed_Rodeo( entity titan, var damageInfo )
{
	if ( !IsAlive( titan ) )
		return

	entity rodeoPilot = GetRodeoPilot( titan )
	if ( !IsValid( rodeoPilot ) )
		return

	Remote_CallFunction_NonReplay( rodeoPilot, "ServerCallback_UpdateRodeoRiderHud" )
}