aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_control_panel.gnut
blob: f9d7a4ff830db358a1fba635e40ec47640512998 (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
untyped

global function ControlPanel_Init

global function InitControlPanelUseFuncTable
global function AddControlPanelUseFuncTable
global function SetControlPanelPrompts
global function SetPanelUsableToEnemies
global function PanelFlipsToPlayerTeamAndUsableByEnemies
global function GetAllControlPanels
global function CaptureAllAvailableControlPanels
global function GetPanelUseEnts
global function PlayIncomingFX
global function SetControlPanelUseFunc
global function ClearControlPanelUseFuncs

const INCOMING_SPAWN_FX = $"P_ar_titan_droppoint"

struct
{
	array<entity> controlPanels
} file

//=========================================================
// Control Panels
//
//=========================================================

//////////////////////////////////////////////////////////////////////
function ControlPanel_Init()
{
	PrecacheModel( $"models/communication/terminal_usable_imc_01.mdl" )
	PrecacheParticleSystem( INCOMING_SPAWN_FX )

	//PrecacheMaterial( $"vgui/hud/control_panel/console_disabled/console_disabled" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_f_deploy/console_f_deploy" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_f_search/console_f_search" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_f_active/console_f_active" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_f_repair/console_f_repair" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_e_deploy/console_e_deploy" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_e_search/console_e_search" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_e_active/console_e_active" )
	//PrecacheMaterial( $"vgui/hud/control_panel/console_e_repair/console_e_repair" )

	AddSpawnCallback( "prop_control_panel", 			OnPanelSpawn )


	RegisterSignal( "PanelReprogrammed" )
	RegisterSignal( "PanelReprogram_Success" )
	RegisterSignal( "OnContinousUseStopped" )
}

//////////////////////////////////////////////////////////
function GameModeRemovePanel( ent )
{
	local keepUndefined
	string gameMode = GameRules_GetGameMode()

	switch ( gameMode )
	{
		// if we are in this game mode, then don't keep undefined panels
		default:
			keepUndefined = true
			gameMode = TEAM_DEATHMATCH
			break
	}

	local gamemodeKey = "gamemode_" + gameMode

	if ( ent.HasKey( gamemodeKey ) && ent.kv[gamemodeKey] == "1" )
	{
		// the key exists and it's true so keep it
		return
	}

	if ( !ent.HasKey( gamemodeKey ) && keepUndefined )
	{
		// the key doesn't exist but keepUndefined is true so still keep it
		return
	}

	ent.Destroy()
}


//////////////////////////////////////////////////////////////////////
void function OnPanelSpawn( entity panel )
{
	Assert( panel.GetModelName() == $"models/communication/terminal_usable_imc_01.mdl" )

	thread OnPanelSpawn_Internal( panel )
}

//////////////////////////////////////////////////////////////////////
void function OnPanelSpawn_Internal( entity panel )
{
	panel.EndSignal( "OnDestroy" )
	GameModeRemovePanel( panel )

	panel.s.useFuncArray <- []

	Assert( IsValid( panel ), "Invalid panel " + panel )
	panel.EndSignal( "OnDestroy" )

	file.controlPanels.append( panel )

	thread PanelUpdateUsability( panel )

	panel.useFunction = ControlPanel_CanUseFunction

	panel.s.leechTimeNormal <- 3.0
	panel.s.leechTimeFast <- 1.1

	panel.kv.forceVisibleInPhaseShift = true

	panel.s.onPlayerFinishesUsing_func <- null
	panel.s.hackedOnce <- false
	//Used in Frontier Mode for knowing if NPCs are hacking the panel.
	panel.s.hackingEntity <- null

	panel.s.remoteTurret <- null
	panel.s.remoteTurretStartFunc <- null

	#if HAS_PANEL_HIGHLIGHT
		int contextId = 0
		panel.Highlight_SetFunctions( contextId, 0, true, HIGHLIGHT_OUTLINE_INTERACT_BUTTON, 1, 0, false )
		panel.Highlight_SetParam( contextId, 0, HIGHLIGHT_COLOR_INTERACT )
		panel.Highlight_SetCurrentContext( contextId )
		panel.Highlight_ShowInside( 0.0 )
		panel.Highlight_ShowOutline( 0.0 )
	#endif

	string flag
	if ( panel.HasKey( "scr_flag_set" ) )
	{
		string editorVal = expect string( panel.kv.scr_flag_set )
		if ( editorVal != "" )
		{
			flag = editorVal
			FlagInit( flag )
		}
	}

	string hackFlag
	if ( panel.HasKey( "scr_flag_hack_started" ) )
	{
		string editorVal = expect string( panel.kv.scr_flag_hack_started )
		if ( editorVal != "" )
		{
			hackFlag = editorVal
			FlagInit( hackFlag )
		}
	}

	bool toggleFlag = false
	if ( panel.HasKey( "toggleFlagWhenHacked" ) )
		toggleFlag = panel.kv.toggleFlagWhenHacked == "1"

	bool singleUse = false
	if ( panel.HasKey( "singleUse" ) )
		singleUse = panel.kv.singleUse.tointeger() > 0

	string requiredFlag = ""
	if ( panel.HasKey( "scr_flagRequired" ) && panel.GetValueForKey( "scr_flagRequired" ) != "" )
		requiredFlag = panel.GetValueForKey( "scr_flagRequired" )

	for ( ;; )
	{
		var player = panel.WaitSignal( "OnPlayerUse" ).player
		Assert( player.IsPlayer() )
		expect entity( player )

		if ( !IsAlive( player ) || player.IsTitan()  )
			continue

		// Panel might be disabled with a flag, so don't allow a hack. We don't disable usability though, because we want use prompts still, with custom hint text
		if ( (requiredFlag != "") && !Flag( requiredFlag ) )
			continue

		// already a user?
		if ( IsAlive( panel.GetBossPlayer() ) )
			continue

		if ( !panel.useFunction( player, panel ) )
		{
			//play buzzer sound
			//EmitSoundOnEntity( panel, "Operator.Ability_offline" )
			wait 1
			continue
		}

		waitthread PlayerUsesControlPanel( player, panel, flag, toggleFlag, hackFlag )

		if ( singleUse && (panel.s.hackedOnce == true) )
			break
	}

	// control panel no longer usable
	panel.UnsetUsable()
	panel.SetUsePrompts( "", "" )
	#if HAS_PANEL_HIGHLIGHT
	panel.Highlight_HideInside( 1.0 )
	panel.Highlight_HideOutline( 1.0 )
	#endif
}

void function PanelUpdateUsability( entity panel )
{
	panel.EndSignal( "OnDestroy" )

	//Default, set it usable by everyone
	panel.SetUsableByGroup( "pilot" )
	panel.SetUsePrompts( "#DEFAULT_HACK_HOLD_PROMPT", "#DEFAULT_HACK_PRESS_PROMPT" )

	if ( !panel.HasKey( "scr_flagRequired" ) )
		return

	string flag = panel.GetValueForKey( "scr_flagRequired" )

	if ( flag == "" )
		return

	FlagInit( flag )

	string disabledUsePrompt = ""
	if ( panel.HasKey( "disabledHintString" ) )
		disabledUsePrompt = panel.GetValueForKey( "disabledHintString" )

	while(true)
	{
		panel.SetUsePrompts( disabledUsePrompt, disabledUsePrompt )
		FlagWait( flag )
		panel.SetUsePrompts( "#DEFAULT_HACK_HOLD_PROMPT", "#DEFAULT_HACK_PRESS_PROMPT" )
		FlagWaitClear( flag )
	}
}

void function PlayIncomingFX( vector origin, int teamNum )
{
	wait 1.50
	EmitSoundAtPosition( teamNum, origin, "Titan_1P_Warpfall_Start" )

	local colorVec = Vector( 0, 255, 0 )
	entity cpoint = CreateEntity( "info_placement_helper" )
	SetTargetName( cpoint, UniqueString( "pickup_controlpoint" ) )
	DispatchSpawn( cpoint )
	cpoint.SetOrigin( colorVec )
	entity glowFX = PlayFXWithControlPoint( INCOMING_SPAWN_FX, origin, cpoint, -1, null, null, C_PLAYFX_LOOP )

	OnThreadEnd(
		function() : ( glowFX, cpoint )
		{
			if ( IsValid( glowFX ) )
				glowFX.Destroy()
			if ( IsValid( cpoint ) )
				cpoint.Destroy()
		}
	)

	wait 1.25
}

void function PlayerUsesControlPanel( entity player, entity panel, string flag, bool toggleFlag, string hackFlag )
{
	thread PlayerProgramsControlPanel( panel, player, hackFlag )

	local result = panel.WaitSignal( "PanelReprogrammed" )

	if ( result.success )
	{
		local panelEHandle = IsValid( panel ) ? panel.GetEncodedEHandle() : null
		array<entity> players = GetPlayerArray()
		foreach( player in players )
		{
			Remote_CallFunction_Replay( player, "ServerCallback_ControlPanelRefresh", panelEHandle )
		}

		RunPanelUseFunctions( panel, player )
		panel.Signal( "PanelReprogram_Success" )
		if ( flag != "" )
		{
			if ( toggleFlag && Flag( flag ) )
				FlagClear( flag )
			else
			{
				FlagSet( flag )
			}
		}

		panel.s.hackedOnce = true
	}
	else
	{
		//play buzzer sound
		//EmitSoundOnEntity( panel, "Operator.Ability_offline" )
		WaitFrame()	// arbitrary delay so that you can't restart the leech instantly after failing
		if ( hackFlag != "" )
			FlagClear( hackFlag )
	}
}

function RunPanelUseFunctions( panel, player )
{
	if ( panel.s.useFuncArray.len() <= 0 )
		return

	foreach ( useFuncTable in clone panel.s.useFuncArray )
	{
		if ( useFuncTable.useEnt == null )
			useFuncTable.useFunc( panel, player )
		else
			useFuncTable.useFunc( panel, player, useFuncTable.useEnt )
	}
}

function SetControlPanelUseFunc( panel, func, ent = null )
{
	local Table = InitControlPanelUseFuncTable()
	Table.useFunc <- func
	Table.useEnt <- ent
	AddControlPanelUseFuncTable( panel, Table )
}

function ClearControlPanelUseFuncs( panel )
{
	panel.s.useFuncArray.clear()
}

//////////////////////////////////////////////////////////////////////
void function PlayerProgramsControlPanel( entity panel, entity player, string hackFlag )
{
	Assert( IsAlive( player ) )

	// need to wait here so that the panel script can start waiting for the PanelReprogrammed signal.
	WaitFrame()

	local action =
	{
		playerAnimation1pStart = "ptpov_data_knife_console_leech_start"
		playerAnimation1pIdle = "ptpov_data_knife_console_leech_idle"
		playerAnimation1pEnd = "ptpov_data_knife_console_leech_end"

		playerAnimation3pStart = "pt_data_knife_console_leech_start"
		playerAnimation3pIdle = "pt_data_knife_console_leech_idle"
		playerAnimation3pEnd = "pt_data_knife_console_leech_end"

		panelAnimation3pStart = "tm_data_knife_console_leech_start"
		panelAnimation3pIdle = "tm_data_knife_console_leech_idle"
		panelAnimation3pEnd = "tm_data_knife_console_leech_end"

		direction = Vector( -1, 0, 0 )
	}

	#if HAS_PANEL_HIGHLIGHT
	panel.Highlight_HideInside( 1.0 )
	panel.Highlight_HideOutline( 1.0 )
	#endif

	local e = {}
	e.success <- false
	e.knives <- []

	e.panelUsableValueToRestore <- panel.GetUsableValue()
	e.startOrigin <- player.GetOrigin()
	panel.SetBossPlayer( player )
	panel.SetUsableValue( USABLE_BY_OWNER )

	e.setIntruder <- false

	e.finishedPanelOpen <- false
	e.animViewLerpoutTime <- 0.3
	e.doRequireUseButtonHeld <- true

	player.ForceStand()
	HolsterAndDisableWeapons( player ) //Do here instead of after doRequireUseButtonHeld check since DisableOffhandWeapons() is counter based, i.e. a call to DisableOffhandWeapons() must be matched with a call to EnableOffhandWeapons()

	//
	if ( panel.s.remoteTurret )
	{
		action.playerAnimation1pStart = "ptpov_data_knife_console_leech_remoteturret_start"
		action.playerAnimation3pStart = "pt_data_knife_console_leech_remoteturret_start"
		action.panelAnimation3pStart = "tm_data_knife_console_leech_remoteturret_start"

		e.animViewLerpoutTime = 0.0
		e.doRequireUseButtonHeld = false

		panel.SetUsePrompts( "", "" )
	}

	player.EndSignal( "OnDeath" )
	player.EndSignal( "ScriptAnimStop" )

	OnThreadEnd
	(
		function() : ( e, player, panel )
		{
			if ( e.setIntruder )
				level.nv.panelIntruder = null

			if ( IsValid( player ) )
			{
				player.ClearAnimNearZ()
				player.ClearParent()

				// stop any running first person sequences
				player.Anim_Stop()

				if ( IsAlive( player ) )
					PutEntityInSafeSpot( player, panel, null, expect vector( e.startOrigin ), player.GetOrigin() )

				// done with first person anims
				ClearPlayerAnimViewEntity( player, expect float( e.animViewLerpoutTime ) )
				DeployAndEnableWeapons( player )
				player.UnforceStand()

				if ( player.ContextAction_IsLeeching() )
					player.Event_LeechEnd()
			}

			if ( IsValid( panel ) )
			{
				// stop any running first person sequences
				panel.Anim_Stop()
				panel.Anim_Play( "ref" ) // close the hatch

				// reset default usability
				if ( !panel.s.remoteTurret || !e.finishedPanelOpen )
				{
					panel.ClearBossPlayer()
					panel.SetUsableValue( e.panelUsableValueToRestore )
				}

				if ( !e.success )
				{
					#if HAS_PANEL_HIGHLIGHT
					panel.Highlight_ShowInside( 1.0 )
					panel.Highlight_ShowOutline( 1.0 )
					#endif

					panel.Signal( "PanelReprogrammed", { success = e.success } )
					#if MP
					local turret = GetMegaTurretLinkedToPanel( panel ) //CHIN: Control panels shouldn't need to know about turrets
					if ( IsValid( turret ) && IsTurret( turret ) )
					{
						local usableValue = MegaTurretUsabilityFunc( turret, panel )
						panel.SetUsableByGroup( usableValue )
						SetUsePromptForPanel( panel, turret )
					}
					else
					{
						// Turret got destoyed while hacking.
						// Usability state has been set by ReleaseTurret( ... ) in ai_turret.nut
						// Changing it to the previous usable value would put us in a bad state.


						// we should change how this works for R2
						//
						// HACK remove s.scriptedPanel when these are refactored
						if ( "scriptedPanel" in panel.s )
							panel.SetUsableValue( e.panelUsableValueToRestore )
					}
					#endif

					#if SP
					if ( "scriptedPanel" in panel.s )
						panel.SetUsableValue( e.panelUsableValueToRestore )
					#endif
				}

				if ( panel.s.remoteTurret && e.finishedPanelOpen )
					thread panel.s.remoteTurretStartFunc( panel, player, e.panelUsableValueToRestore )

				if ( panel.s.onPlayerFinishesUsing_func )
					thread panel.s.onPlayerFinishesUsing_func( panel, player, e.success )
			}

			foreach ( knife in e.knives )
			{
				if ( IsValid( knife ) )
					knife.Destroy()
			}
		}
	)

	if ( e.doRequireUseButtonHeld && !player.UseButtonPressed() )
		return	// it's possible to get here and no longer be holding the use button. If that is the case lets not continue.

	if ( player.ContextAction_IsActive() )
		return

	if ( player.IsPhaseShifted() )
		return

	player.SetAnimNearZ( 1 )

	player.Event_LeechStart()

	local leechTime = panel.s.leechTimeNormal

	if ( PlayerHasPassive( player, ePassives.PAS_FAST_HACK ) )
		leechTime = panel.s.leechTimeFast

	local totalTime = leechTime + player.GetSequenceDuration( action.playerAnimation3pStart )

	thread TrackContinuousUse( player, totalTime, e.doRequireUseButtonHeld )

	waitthread ControlPanelFlipAnimation( panel, player, action, e )

	if ( e.doRequireUseButtonHeld && !player.UseButtonPressed() )
		return	// we might have returned from the flip anim because we released the use button.

	if ( hackFlag != "" )
		FlagSet( hackFlag )

	e.finishedPanelOpen = true
	if ( panel.s.remoteTurret )
	{
		// Called on thread end above.
		return
	}

	Remote_CallFunction_Replay( player, "ServerCallback_DataKnifeStartLeech", leechTime )

	waitthread WaitForEndLeechOrStoppedUse( player, leechTime, e, panel )

	if ( e.success )
	{
		thread DataKnifeSuccessSounds( player )
	}
	else
	{
		DataKnifeCanceledSounds( player )
		Remote_CallFunction_Replay( player, "ServerCallback_DataKnifeCancelLeech" )
	}

	waitthread ControlPanelFlipExitAnimation( player, panel, action, e )
}

function WaitForEndLeechOrStoppedUse( player, leechTime, e, panel )
{
	player.EndSignal( "OnContinousUseStopped" )
	wait leechTime
	e.success = true
	panel.Signal( "PanelReprogrammed", { success = e.success } )
}


//////////////////////////////////////////////////////////////////////
function ControlPanelFlipAnimation( entity panel, entity player, action, e )
{
//	OnThreadEnd
//	(
//		function() : ( panel )
//		{
//			if ( IsValid( panel ) )
//				DeleteAnimEvent( panel, "knife_popout" )
//		}
//	)
	player.EndSignal( "OnContinousUseStopped" )

	FirstPersonSequenceStruct playerSequence
	playerSequence.attachment = "ref"
	playerSequence.thirdPersonAnim = expect string ( action.playerAnimation3pStart )
	playerSequence.thirdPersonAnimIdle = expect string ( action.playerAnimation3pIdle )
	playerSequence.firstPersonAnim = expect string ( action.playerAnimation1pStart )
	playerSequence.firstPersonAnimIdle = expect string ( action.playerAnimation1pIdle )
	if ( IntroPreviewOn() )
		playerSequence.viewConeFunction = ControlPanelFlipViewCone

	FirstPersonSequenceStruct panelSequence
	panelSequence.thirdPersonAnim = expect string ( action.panelAnimation3pStart )
	panelSequence.thirdPersonAnimIdle = expect string ( action.panelAnimation3pIdle )


	asset model = DATA_KNIFE_MODEL

	entity knife = CreatePropDynamic( model )
	SetTargetName( knife, "dataKnife" )
	knife.SetParent( player, "PROPGUN", false, 0.0 )
	e.knives.append( knife )

	thread PanelFirstPersonSequence( panelSequence, panel, player )
	waitthread FirstPersonSequence( playerSequence, player, panel )
}


void function ControlPanelFlipViewCone( entity player )
{
	player.PlayerCone_FromAnim()
	player.PlayerCone_SetMinYaw( -80 )
	player.PlayerCone_SetMaxYaw( 80 )
	player.PlayerCone_SetMinPitch( -80 )
	player.PlayerCone_SetMaxPitch( 10 )
}


//////////////////////////////////////////////////////////////////////
function PanelFirstPersonSequence( FirstPersonSequenceStruct panelSequence, entity panel, entity player )
{
	player.EndSignal( "OnDeath" )
	panel.EndSignal( "OnDestroy" )

	waitthread FirstPersonSequence( panelSequence, panel )
}


//////////////////////////////////////////////////////////////////////
function ControlPanelFlipExitAnimation( entity player, entity panel, action, e )
{
	FirstPersonSequenceStruct playerSequence
	playerSequence.blendTime = 0.0
	playerSequence.attachment = "ref"
	playerSequence.teleport = true

	FirstPersonSequenceStruct panelSequence
	panelSequence.blendTime = 0.0

	playerSequence.thirdPersonAnim = expect string ( action.playerAnimation3pEnd )
	playerSequence.firstPersonAnim = expect string ( action.playerAnimation1pEnd )
	panelSequence.thirdPersonAnim = expect string ( action.panelAnimation3pEnd )

	thread FirstPersonSequence( panelSequence, panel )
	waitthread FirstPersonSequence( playerSequence, player, panel )
}


//////////////////////////////////////////////////////////////////////
function TrackContinuousUse( player, leechTime, doRequireUseButtonHeld )
{
	player.EndSignal( "OnDeath" )
	player.EndSignal( "ScriptAnimStop" )

	local result = {}
	result.success <- false

	OnThreadEnd
	(
		function() : ( player, result )
		{
			if ( !result.success )
			{
				player.Signal( "OnContinousUseStopped" )
			}
		}
	)

	float startTime = Time()
	while ( Time() < startTime + leechTime && (!doRequireUseButtonHeld || player.UseButtonPressed()) && !player.IsPhaseShifted() )
		WaitFrame()

	if ( !doRequireUseButtonHeld || player.UseButtonPressed() )
		result.success = true
}

function InitControlPanelUseFuncTable()
{
	local Table = {}
	Table.useEnt <- null
	Table.useFunc <- null
	return Table
}

function AddControlPanelUseFuncTable( panel, Table )
{
	// a table that contains
	//1. a function to be called when the control panel is used
	//2. an entity that the function refers to, e.g. the turret to be created
	panel.s.useFuncArray.append( Table )
}

function SetControlPanelPrompts( ent, func )
{
	ent.s.prompts <- func( ent )
}

function SetPanelUsableToEnemies( panel )
{
	if ( panel.GetTeam() == TEAM_IMC || panel.GetTeam() == TEAM_MILITIA  )
	{
		panel.SetUsableByGroup( "enemies pilot" )
		return
	}

	//Not on either player team, just set usable to everyone
	panel.SetUsableByGroup( "pilot" )
}

function PanelFlipsToPlayerTeamAndUsableByEnemies( panel, entity player )
{
	expect entity( panel )

	SetTeam( panel, player.GetTeam() )
	SetPanelUsableToEnemies( panel )
}

function GetPanelUseEnts( panel )
{
	local useEntsArray = []
	foreach( useFuncTable in panel.s.useFuncArray )
	{
		if ( useFuncTable.useEnt )
			useEntsArray.append( useFuncTable.useEnt )
	}

	return useEntsArray

}

array<entity> function GetAllControlPanels()
{
	//Defensively remove control panels that are invalid.
	//This is because we can have control panels in levels for some game modes
	//but not in others, e.g. refuel mode vs tdm

	ArrayRemoveInvalid( file.controlPanels )
	return file.controlPanels
}

function CaptureAllAvailableControlPanels( player )
{
	array<entity> panels = GetAllControlPanels()
	foreach ( panel in panels )
	{
		printt( "panel team " + panel.GetTeam() )
		RunPanelUseFunctions( panel, player )
	}
}