aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Coop/scripts/vscripts/sp/_gamestate_sp.gnut
blob: ac741370f697dd78f3762decae37b9d5edd699d1 (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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
const RESPAWN_TRIG_RECHECK_WAIT 		= 1
const DEFAULT_SP_ARRIVAL_TOLERANCE = 200
const DEFAULT_SP_ASSAULT_TIMEOUT = 0

// move these to auto precache
global const TEAM_MIL_GRUNT_MODEL 			= $"models/humans/grunts/mlt_grunt_rifle.mdl"
global const TEAM_MIL_GRUNT_MODEL_LMG		= $"models/humans/grunts/mlt_grunt_lmg.mdl"
global const TEAM_MIL_GRUNT_MODEL_RIFLE		= $"models/humans/grunts/mlt_grunt_rifle.mdl"
global const TEAM_MIL_GRUNT_MODEL_ROCKET 	= $"models/humans/grunts/mlt_grunt_rifle.mdl"
global const TEAM_MIL_GRUNT_MODEL_SHOTGUN 	= $"models/humans/grunts/mlt_grunt_shotgun.mdl"
global const TEAM_MIL_GRUNT_MODEL_SMG		= $"models/humans/grunts/mlt_grunt_smg.mdl"


global function GamemodeSp_Init
global function GiveBatteryChargeTool
global function HasBatteryChargeTool
global function FriendlyFire_MissionFailure
global function DamageAlwaysLethal
global function ServerRestartMission
global function DisableFriendlyHighlight
global function EnableFriendlyHighlight
global function SP_PlayerLastSlideTime

//global function CodeCallback_Ping

global function SetGameState
global function GetGameModeAnnouncement

global function CodeCallback_GamerulesThink

global struct SvGlobalsSP
{
	int gruntCombatState = eGruntCombatState.IDLE

	array<void functionref( entity )> onLoadSaveGameCallbacks
}

global SvGlobalsSP svGlobalSP

//////////////////////////////

global function DEV_ToggleFriendlyHighlight

//////////////////////////////

struct
{
	LevelTransitionStruct ornull storedLevelTransitionStruct
	entity spPetTitanStart
	bool friendlyHighlightEnabled = true
	float playerLastSlideTime
} file

void function GamemodeSp_Init()
{
	FlagInit( "FriendlyFireStrict" )
	FlagInit( "TitanCanSavePlayer" )
	FlagInit( "TitanDeathPenalityDisabled" )
	FlagInit( "SaveGame_Enabled", true )
	FlagInit( "MissionFailed" )
	RegisterSignal( "TitanSavesPlayer" )

	FlagSet( "PilotBot" )

	AddSoulDeathCallback( SoulDeath_ReloadOnPetTitanDeath )
	AddClientCommandCallback( "RestartMission", ClientCommand_RestartMission )

	SetRoundBased( false )

	AddCallback_OnClientConnecting( SpPlayerConnecting )
	AddCallback_OnClientConnected( SpPlayerConnected )

	AddSpawnCallback( "npc_soldier", 	SpNpcCommon )
	AddSpawnCallback( "npc_spectre", 	SpNpcCommon )
	AddSpawnCallback( "npc_titan", 		SpNpcCommon )

	AddSpawnCallback( "npc_soldier", 	SpNpcCommonGrunt )

	AddSpawnCallbackEditorClass( "info_target", "info_pet_titan_start", PetTitanStartSpawnInit )
	AddCallback_OnPlayerRespawned( GameStateSP_OnPlayerRespawn )

	AddDamageCallbackSourceID( eDamageSourceId.damagedef_titan_fall, PreventFriendlyTitanfallDamage )
	AddDamageCallbackSourceID( eDamageSourceId.damagedef_reaper_fall, PreventFriendlyTitanfallDamage )

	shGlobal.proto_soldierShieldRegenDelay = 3000.0
	svGlobal.cloakBreaksOnMelee		= true
	svGlobal.defaultPilotLeechTime	= 2.0

	//AddDamageCallback( "player", DiminishPlayerComboDamage )

	SPTitanLoadout_SetupForLevelStart()

	SpSharedInit()

	AddCallback_EntitiesDidLoad( EntitiesDidLoad_SpGameState )
	AddDeathCallback( "npc_soldier", SoldierFriendlyFireCheck_OnKilled )

	AddCallback_OnPilotBecomesTitan( PilotBecomesTitanStoreWeaponVar )

	// SAVE THIS LEVEL IF IT'S IN THE LEVEL LIST
	var dataTable = GetDataTable( $"datatable/sp_levels.rpak" )
	string mapName = GetMapName()
	string startPoint = GetStartPoint()
	int numRows = GetDatatableRowCount( dataTable )
	int lastLevelNum = 0

	int bspCol = GetDataTableColumnByName( dataTable, "level" )
	int levelCol = GetDataTableColumnByName( dataTable, "levelNum" )

	for ( int i=0; i<numRows; i++ )
	{
		string levelBsp = GetDataTableString( dataTable, i, bspCol )
		int levelNum = GetDataTableInt( dataTable, i, levelCol )

		if ( levelBsp == mapName )
		{
			#if DEV
			printt( "Setting this level as unlocked" )
			printt( "BSP: " + levelBsp )
			printt( "Level Num: " + levelNum )
			#endif

			SetConVarInt( "sp_lastMission", levelNum )
			lastLevelNum = levelNum
			break
		}
	}

	int farthestLevelUnlocked = GetConVarInt( "sp_unlockedMission" )

	if( Script_IsRunningTrialVersion() )
		SetConVarInt( "sp_unlockedMission", 1 ) // Set to sp_crashsite so if they buy the game, it starts there.
	else
		SetConVarInt( "sp_unlockedMission", maxint(farthestLevelUnlocked, lastLevelNum) )

	foreach( entity player in GetPlayerArray() )
		UpdateHeroStatsForPlayer( player )

	if ( IsTestMap() )
	{
		PilotLoadoutDef loadout = GetPilotLoadoutForCurrentMapSP()
		foreach ( model in GetModelsFromSetFile( loadout.setFile ) )
		{
			PrecacheModel( model )
		}

		TitanLoadoutDef titanLoadout = GetTitanLoadoutForCurrentMap()
		foreach ( model in GetModelsFromSetFile( titanLoadout.setFile ) )
		{
			PrecacheModel( model )
		}
	}
}


void function EntitiesDidLoad_SpGameState()
{
	SetGameState( eGameState.Playing )
	FlagSet( "ReadyToStartMatch" )

	file.storedLevelTransitionStruct = GetLevelTransitionStruct()

	SetCustomIntroLength( 0 )

//	level.nv.replayDisabled = true //HACK - remove once the bug about replay hud is fixed
	level.nv.minimapState = eMinimapState.Hidden

	level.nv.replayDisabled = true
	if ( !IsTestMap() )
		level.nv.titanAvailability = eTitanAvailability.Never

	ServerCommand( "sv_weapon_despawn_Time 180" )
}

/************************************************************************************************\

 ######   #######  ##    ## ##    ## ########  ######  ########
##    ## ##     ## ###   ## ###   ## ##       ##    ##    ##
##       ##     ## ####  ## ####  ## ##       ##          ##
##       ##     ## ## ## ## ## ## ## ######   ##          ##
##       ##     ## ##  #### ##  #### ##       ##          ##
##    ## ##     ## ##   ### ##   ### ##       ##    ##    ##
 ######   #######  ##    ## ##    ## ########  ######     ##

\************************************************************************************************/
void function SpPlayerConnecting( entity player )
{
	if ( GetPlayerArray().len() > 1 )
	{
		CodeWarning( "Can't play SP with more or less than 1 player" )
		return
	}

	SetTeam( player, TEAM_MILITIA )
	InitPassives( player )

	player.SetInventoryChangedCallbackEnabled( true )

	entity ornull spawningOn = GetPlayerToSpawnOn()
	if ( spawningOn == null )
	{
		// vanilla spawning logic - spawn first player at the level's spawnpoint
		entity start = GetEnt( "info_player_start" )
		player.SetOrigin( start.GetOrigin() )
		player.SetAngles( start.GetAngles() )
	}
	else
	{
		expect entity( spawningOn )
		// use safe func otherwise we can get stuck in the ceiling and shit
		thread TeleportToEntitySafe( player, spawningOn )
	}

	if ( IsValid( file.spPetTitanStart ) )
	{
		CreatePetTitan( player )
		entity titan = player.GetPetTitan()
		if ( titan != null )
			titan.kv.alwaysAlert = false
	}
}

void function GameStateSP_OnPlayerRespawn( entity player )
{
	UpdateSpDifficulty( player )
	thread TrackPlayerLastSlideTime( player )

	if ( !IsTestMap() )
	{
		CheckPoint_ForcedSilent()
	}
}

void function SpPlayerConnected( entity player )
{
	thread SpPlayerConnected_Thread( player )
}

void function SpPlayerConnected_Thread( entity player )
{
	player.EndSignal( "OnDestroy" )

	if ( IsTestMap() )
		return

	string levelName = GetMapName()
	int startIndex = GetStartPointIndexFromName( levelName, GetCurrentStartPoint() )

	string startPointEnum = GetStartPointNameFromIndex( levelName, startIndex )
	if ( !StartPointHasDetente( levelName, startPointEnum ) )
		return

	var dataTable = GetDataTable( $"datatable/sp_introscreen.rpak" )
	int row = GetDataTableRowMatchingStringValue( dataTable, GetDataTableColumnByName( dataTable, "level" ), levelName )
	if ( row == -1 )
		return

	float delay = GetDataTableFloat( dataTable, row, GetDataTableColumnByName( dataTable, "bgFadeDelay" ) )
	float fadeTime = GetDataTableFloat( dataTable, row, GetDataTableColumnByName( dataTable, "bgFadeTime" ) )

	printt( "Detent fade in " + delay + " blend " + fadeTime )

	WaitFrame()
	WaitFrame() // wait two frames to fix ScreenFade bug

	ScreenFade( player, 0, 0, 0, 255, fadeTime, delay, FFADE_IN | FFADE_PURGE )
	//printt( "sv SCREENFADE: " + fadeTime + " " + delay )
}

float function SP_PlayerLastSlideTime()
{
	return file.playerLastSlideTime
}

void function PetTitanStartSpawnInit( entity spawn )
{
	file.spPetTitanStart = spawn
}

void function TrackPlayerLastSlideTime( entity player )
{
	player.EndSignal( "OnDeath" )

	for ( ;; )
	{
		if ( player.IsSliding() )
			file.playerLastSlideTime = Time()
		wait 0.5
	}
}

void function CreatePetTitan( entity player )
{
	Assert( IsValid( file.spPetTitanStart ) )
	// Player is in his Titan, don't create a titan
	if ( player.IsTitan() )
		return

	// Player already has a pet titan, don't create one
	entity petTitan = player.GetPetTitan()
	if ( IsValid( petTitan ) )
		return

	// Make a pet titan at the spawn point
	TitanLoadoutDef loadout = GetTitanLoadoutForCurrentMap()
	entity titanStart = file.spPetTitanStart
	entity titan = CreateAutoTitanForPlayer_FromTitanLoadout( player, loadout, titanStart.GetOrigin(), titanStart.GetAngles() )
	DispatchSpawn( titan )
	player.SetPetTitan( titan )

	titan.DisableHibernation()
}

/************************************************************************************************\

########     ###    ##      ##    ###     ######  ########
##     ##   ## ##   ###    ###   ## ##   ##    ## ##
##     ##  ##   ##  ####  ####  ##   ##  ##       ##
##     ## ##     ## ## #### ## ##     ## ##   ### ######
##     ## ######### ##  ##  ## ######### ##    ## ##
##     ## ##     ## ##      ## ##     ## ##    ## ##
########  ##     ## ##      ## ##     ##  ######  ########

\************************************************************************************************/

// putting this stuff here for now since it's only for SP at this point




bool function TryTitanSavesPlayer( entity player )
{
	if ( !Flag( "TitanCanSavePlayer" ) )
		return false

	if ( !IsAlive( player.GetPetTitan() ) )
		return false

	entity titan = player.GetPetTitan()
	if ( TitanIsCurrentlyEmbarkableForPlayer( player, titan ) )
	{
		thread TitanSavesPlayer( player, titan )
		return true
	}

	return false
}

void function TitanSavesPlayer( entity player, entity titan )
{
	player.EndSignal( "OnDestroy" )
	titan.EndSignal( "OnDeath" )

	player.SetNoTarget( true )
	player.SetInvulnerable()
	titan.SetInvulnerable()

	player.DisableWeapon()
	player.FreezeControlsOnServer()
	player.ForceCrouch()

	OnThreadEnd(
		function() : ( player, titan )
		{
			if ( IsValid( player ) )
			{
				if ( !IsPlayerEmbarking( player ) )
				{
					player.EnableWeapon()
				}
				player.UnforceCrouch()
				player.UnfreezeControlsOnServer()
				player.ClearInvulnerable()
				player.SetNoTarget( false )
			}

			if ( IsValid( titan ) )
				titan.ClearInvulnerable()
		}
	)

	wait 0.25

	float fadeTime = 2
	float blackTime_pre = 4.0
	float blackTime_post = 1.0

	thread ScreenFadeToBlack( player, 2.0, blackTime_pre )

	wait blackTime_pre * 0.5
	string titanAlias = GenerateTitanOSAlias( player, "briefCriticalDamage" )
	thread EmitSoundOnEntity( player, titanAlias )
	wait blackTime_pre * 0.5

	vector ornull clampedPos = NavMesh_ClampPointForAI( player.GetOrigin(), titan )
	if ( clampedPos != null )
		titan.SetOrigin( expect vector( clampedPos ) )

	titan.SetAngles( Vector( 0, player.GetAngles().y, 0 ) )

	entity soul = titan.GetTitanSoul()
	SetStanceKneel( soul )

	table criteria = {
		embark = "front",
		titanCanStandRequired = false
	}

	var embarkAction
	embarkAction = FindEmbarkActionForCriteria( criteria )
	if ( embarkAction == null )
		embarkAction = GetRandomEmbarkAction()

	table action = expect table( GenerateEmbarkActionTable( player, titan, embarkAction ) )
	thread PlayerEmbarksTitan( player, titan, action )
	thread ScreenFadeFromBlack( player, 12.0, blackTime_post )

	player.Signal( "TitanSavesPlayer" )
}

bool function DamageAlwaysLethal( var damageInfo )
{
	const damageMask = DF_INSTANT | DF_IMPACT | DF_TITAN_STEP | DF_KILLSHOT | DF_MELEE // | DF_EXPLOSION
	if ( DamageInfo_GetCustomDamageType( damageInfo ) & damageMask )
		return true
//	not quite sure what this returns. It doesn't seem to be the flags listed in death_package.nut
//	if ( DamageInfo_GetDamageType( damageInfo ) &  damageMask )
//		return false

	// damage type doesn't seem to be correct for most things so I'm forced to check GetDamageSourceIdentifier -Roger
	switch ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) )
	{
		case damagedef_crush:
		case damagedef_nuclear_core:
		case damagedef_suicide:
		case damagedef_titan_fall:
		case damagedef_titan_hotdrop:
		case eDamageSourceId.bubble_shield:
		case eDamageSourceId.burn:
		case eDamageSourceId.droppod_impact:
		case eDamageSourceId.evac_dropship_explosion:
		case eDamageSourceId.fall:
		case eDamageSourceId.flash_surge:
		case eDamageSourceId.floor_is_lava:
		case eDamageSourceId.human_execution:
		case eDamageSourceId.human_melee:
		case eDamageSourceId.indoor_inferno:
		case eDamageSourceId.outOfBounds:
		case eDamageSourceId.round_end:
		case eDamageSourceId.splat:
		case eDamageSourceId.stuck:
		case eDamageSourceId.submerged:
		case eDamageSourceId.switchback_trap:
		case eDamageSourceId.team_switch:
		case eDamageSourceId.titan_execution:
		case eDamageSourceId.titan_explosion:
		case eDamageSourceId.wall_smash:
//		case eDamageSourceId.grunt_melee:
//		case eDamageSourceId.prowler_melee:
//		case eDamageSourceId.spectre_melee:
			return true

		default:
			break
	}

	return false
}

/************************************************************************************************\

 ##    ## ########   ######
 ###   ## ##     ## ##    ##
 ####  ## ##     ## ##
 ## ## ## ########  ##
 ##  #### ##        ##
 ##   ### ##        ##    ##
 ##    ## ##         ######

\************************************************************************************************/
void function SpNpcCommon( entity npc )
{
	if ( npc.GetTeam() == TEAM_MILITIA )
	{
		if ( !npc.IsTitan() )
			HideName( npc )

		// this is a temporary stop gap until we get skins
		if ( file.friendlyHighlightEnabled )
			Highlight_SetFriendlyHighlight( npc, "sp_friendly_pilot" )
	}
}

void function SpNpcCommonGrunt( entity npc )
{
	// heros clear this setting so they should keep their names
	if ( npc.GetTeam() == TEAM_MILITIA )
	{

		string title
		if ( npc.Dev_GetAISettingByKeyField( "IsGenericGrunt" ) == 0 )
		{
			title = npc.GetSettingTitle()
		}
		else
		{
			title = GetMilitiaTitle()
		}

		npc.SetTitle( title )
		ShowName( npc )
	}
}

void function DiminishPlayerComboDamage( entity player, var damageInfo )
{
	if ( !IsPilot( player ) )
		return

//	printt( "damage " + DamageInfo_GetDamage( damageInfo ) )
//	printt( "shield health " + player.GetShieldHealth() )
	if ( player.GetShieldHealth() > 0 )
		return

	// blunt damage from combos
	float damage = DamageInfo_GetDamage( damageInfo )

	float recentDamage = TotalDamageOverTime_BlendedOut( player, 0.5, 1.5 )

	// damage is ramped down based on how much damage was taken recently
	float damageMod = GraphCapped( recentDamage, 70, 140, 1.0, 0.1 )
	DamageInfo_ScaleDamage( damageInfo, damageMod )
}

void function SoulDeath_ReloadOnPetTitanDeath( entity soul, var damageInfo )
{
	if ( Flag( "TitanDeathPenalityDisabled" ) )
		return

	if ( IsTestMap() )
		return

	thread SoulDeath_ReloadOnPetTitanDeath_Thread( soul, damageInfo )
}

void function SoldierFriendlyFireCheck_OnKilled( entity npc, var damageInfo )
{
	if ( !Flag( "FriendlyFireStrict" ) )
		return

	entity attacker = DamageInfo_GetAttacker( damageInfo )
	if ( !attacker.IsPlayer() )
		return

	if ( npc.GetTeam() != attacker.GetTeam() )
		return

	thread SoldierFriendlyFireCheck_OnKilledDelayed()
}

void function SoldierFriendlyFireCheck_OnKilledDelayed()
{
	FlagClear( "SaveGame_Enabled" ) // no more saving, you have lost
	wait 0.75
	FriendlyFire_MissionFailure()
}

void function FriendlyFire_MissionFailure()
{
	if ( Flag( "MissionFailed" ) )
		return

	foreach ( player in GetPlayerArray() )
	{
		Remote_CallFunction_NonReplay( player, "ServerCallback_FriendlyFire_MissionFailure" )
	}

	ReloadForMissionFailure()
}

void function SoulDeath_ReloadOnPetTitanDeath_Thread( entity soul, var damageInfo )
{
	entity player = soul.GetBossPlayer()

	if ( !IsValid( player ) )
		return

	if ( !level.nv.replayDisabled )
	{
		if ( player.p.watchingPetTitanKillReplay )
			return

		player.p.watchingPetTitanKillReplay = true
	}

	if ( damageInfo == null )
	{
		printt( "ServerCallback_TitanDied with null sourceid" )
		ReloadForMissionFailure()
		return
	}

	int source = DamageInfo_GetDamageSourceIdentifier( damageInfo )
	Remote_CallFunction_NonReplay( player, "ServerCallback_TitanDied", source )
	#if DEV
	printt( "ServerCallback_TitanDied with sourceid " + source + " and source string " + GetObitFromDamageSourceID( source )  )
	#endif

	if ( IsInstantDeath( damageInfo ) )
	{
		ReloadForMissionFailure()
		return
	}
	entity attacker = DamageInfo_GetAttacker( damageInfo )
	if ( !IsValid( attacker ) )
	{
		ReloadForMissionFailure()
		return
	}

	int index = attacker.GetIndexForEntity()
	entity titan = soul.GetTitan()

	FlagClear( "SaveGame_Enabled" ) // no more saving, you have lost

	if ( !level.nv.replayDisabled )
	{
		/*
		wait 3.8
		float replayDelay = 6.5
		player.SetKillReplayDelay( replayDelay )
		player.SetViewIndex( index )

		if ( IsValid( titan ) )
			player.SetKillReplayVictim( titan )

		ReloadForMissionFailure( replayDelay + 2.5 )
		*/
	}
	else
	{
		ReloadForMissionFailure() // replayDelay + 2.5
	}
}

bool function HasBatteryChargeTool( entity player )
{
	switch ( CHARGE_TOOL )
	{
		case "sp_weapon_proto_battery_charger_offhand":
			return HasOffhandWeapon( player, CHARGE_TOOL )

		case "sp_weapon_arc_tool":
			return HasWeapon( player, CHARGE_TOOL )
	}

	unreachable
}

void function GiveBatteryChargeTool( entity player )
{
	switch ( CHARGE_TOOL )
	{
		case "sp_weapon_proto_battery_charger_offhand":
			player.GiveOffhandWeapon( CHARGE_TOOL, OFFHAND_SPECIAL )
			break

		case "sp_weapon_arc_tool":
			player.GiveWeapon( CHARGE_TOOL )
			break
	}
	UpdateArcConnectorHints()
}

/*
void function CodeCallback_Ping( entity player )
{

}
*/

/* ----------------------------------------------------------------------------------------------

STUFF FORM MP THAT WE WILL SLOWLY GET RID OF

-------------------------------------------------------------------------------------------------*/

string function GetGameModeAnnouncement()
{
	return ""
}

void function SetGameState( int newState )
{
	level.nv.gameStartTime = Time()
	level.nv.gameStateChangeTime = Time()
	level.nv.gameState = newState
	svGlobal.levelEnt.Signal( "GameStateChanged" )

	foreach ( callbackFunc in svGlobal.gameStateEnterCallbacks[ newState ] )
	{
		callbackFunc()
	}
}

void function CodeCallback_GamerulesThink()
{

}

void function DEV_ToggleFriendlyHighlight()
{
	file.friendlyHighlightEnabled = !file.friendlyHighlightEnabled
	UpdateFriendlyHighlight()
}

void function DisableFriendlyHighlight()
{
	file.friendlyHighlightEnabled = false
	UpdateFriendlyHighlight()
}

void function EnableFriendlyHighlight()
{
	file.friendlyHighlightEnabled = true
	UpdateFriendlyHighlight()
}

void function UpdateFriendlyHighlight()
{
	if ( file.friendlyHighlightEnabled )
	{
		foreach ( npc in GetNPCArrayOfTeam( TEAM_MILITIA ) )
			Highlight_SetFriendlyHighlight( npc, "sp_friendly_pilot" )
	}
	else
	{
		foreach ( npc in GetNPCArrayOfTeam( TEAM_MILITIA ) )
			Highlight_ClearFriendlyHighlight( npc )
	}
}

bool function ClientCommand_RestartMission( entity player, array<string> args )
{
	ServerRestartMission( player )
	return true
}

void function ServerRestartMission( entity player )
{
	if ( IsTestMap() )
	{
		ServerCommand( "reload" )
		return
	}

	string mapName = GetMapName()
	LevelTransitionStruct ornull trans = file.storedLevelTransitionStruct
	if ( trans == null )
	{
		int startIndex = 0
		#if DEV
		string startName = Dev_GetStartCommandLine( mapName )
		if ( startName != "" )
			startIndex = GetStartPointIndexFromName( mapName, startName )
		#endif
		// loaded a level manually in dev or are in sp_training
		ExecuteLoadingClientCommands_SetStartPoint( mapName, startIndex )
		ClientCommand( player, "map " + mapName )
		return
	}

	expect LevelTransitionStruct( trans )
	ExecuteLoadingClientCommands_SetStartPoint( mapName, trans.startPointIndex )
	ChangeLevel( mapName, trans )
}

void function PilotBecomesTitanStoreWeaponVar( entity pilot, entity npc_titan )
{
	entity weapon = pilot.GetMainWeapons()[0]
	int index = GetTitanLoadoutIndex( weapon.GetWeaponClassName() )
	SetConVarInt( "sp_titanLoadoutCurrent", index )
}

void function PreventFriendlyTitanfallDamage( entity ent, var damageInfo )
{
	entity attacker = DamageInfo_GetAttacker( damageInfo )

	if ( attacker.GetTeam() == ent.GetTeam() )
	{
		DamageInfo_SetDamage( damageInfo, 0 )
	}
}