aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_fastball.gnut
blob: 0f04ed579f50f3b87cdbe9b65694a0a6cf15e1d2 (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
untyped
global function GamemodeFastball_Init

struct {
	// first panel is a, second is b, third is c
	array<Point> panelSpawns
} file

void function GamemodeFastball_Init()
{
	// used for intro
	PrecacheModel( $"models/titans/buddy/titan_buddy.mdl" )
	PrecacheParticleSystem( $"P_BT_eye_SM" )
	
	// used for respawn
	PrecacheParticleSystem( $"P_pod_screen_lasers_OUT" )
	
	SetShouldUseRoundWinningKillReplay( true )
	SetRoundBased( true )
	SetRespawnsEnabled( false )
	Riff_ForceTitanAvailability( eTitanAvailability.Never )
	Riff_ForceSetEliminationMode( eEliminationMode.Pilots )
	ScoreEvent_SetupEarnMeterValuesForMixedModes()
	
	// implementing intro in a different file because it'll likely be big 
	ClassicMP_SetCustomIntro( GamemodeFastballIntroSetup, 14.5 ) // bit of a guess number
	ClassicMP_ForceDisableEpilogue( true )
	AddCallback_EntitiesDidLoad( SpawnPanelsForLevel )
	AddCallback_GameStateEnter( eGameState.Prematch, ResetPanels )
	SetTimeoutWinnerDecisionFunc( FastballDecideWinner )
	
	AddCallback_OnClientConnected( FastballInitPlayer )
	
	// setup spawns
	// first is a, second is b, third is c
	
	FastballAddBuddySpawnForLevel( "mp_angel_city", TEAM_IMC, < 2281.39, -3333.06, 200.031 >, < 0, 91.23, 0 > )
	FastballAddBuddySpawnForLevel( "mp_angel_city", TEAM_MILITIA, < -4139.57, 4684.4, 41.0313 >, <0, -14.326, 0 > )
	FastballAddPanelSpawnsForLevel( "mp_angel_city", [
		< 2055.94, 2040.03, 128.031 >, < 0, -180, 0 >,
		< -274.757, 2255.22, 400.031 >, < 0, -176.251, 0 >,
		< -3208.28, 2741.17, 128.031 >, < 0, -0.0821686, 0 >
	])
	
	FastballAddBuddySpawnForLevel( "mp_thaw", TEAM_MILITIA, < 2049.29, -4085.22, -274.839 >, < 0, 89.2991, 0 > )
	FastballAddBuddySpawnForLevel( "mp_thaw", TEAM_IMC, < 834.484, 2664.28, -380.515 >, < 0.532141, -90.875, -0.542593 > )
	FastballAddPanelSpawnsForLevel( "mp_thaw", [
		< -1026.71, -1691.93, -319.969 >, < 0, 90, 0 >,
		< 1836.07, -538.823, -64.1245 >, < 0, -135, 0 >,
		< 2840.15, 1321.17, -63.9688 >, < 0, 0, 0 >
	])
	
	FastballAddBuddySpawnForLevel( "mp_wargames", TEAM_MILITIA, < -4848.87, 682.17, -127.969 >, < 0, 0, 0 > )
	FastballAddBuddySpawnForLevel( "mp_wargames", TEAM_IMC, < 2960.78, 1229.36, -127.969 >, < 7.89891e-005, 146.505, 1.38387e-005 > )
	FastballAddPanelSpawnsForLevel( "mp_wargames", [
		< -691.961, 1888.56, 112.031 >, < 0, 90, 0 >,
		< -1072.03, -508.229, -127.969 >, < 0, 180, 0 >,
		< -24.291, -1403.69, -119.969 >, < 0, -90, 0 >
	])
	
	FastballAddBuddySpawnForLevel( "mp_eden", TEAM_MILITIA, < -2404.4, 1738.07, 167.767 >, <0, -40.0894, 0> )
	FastballAddBuddySpawnForLevel( "mp_eden", TEAM_IMC, < 5248.01, 414.698, 77.1051 >, < 0, 180, 0 > )
	FastballAddPanelSpawnsForLevel( "mp_eden", [
		< 704.333, 1530.18, 144.031 >, < 0, 90, 0 >,
		< -108.43, 272.638, 72.0313 >, < 0, -90, 0 >,
		<1044.25, -1145.68, 68.0313>, < 0, 180, 0 >
	])
	
	FastballAddBuddySpawnForLevel( "mp_black_water_canal", TEAM_MILITIA, < 1222.88, -5050.63, -187.763 >, < 0, 45, 0 > )
	FastballAddBuddySpawnForLevel( "mp_black_water_canal", TEAM_IMC, < -235.375, 4736.75, -255.969 >, < 0, -90, 0 > )
	FastballAddPanelSpawnsForLevel( "mp_black_water_canal", [
		< 1566.13, -731.539, -63.9688 >, < 0, -90, 0 >,
		< 502.603, 1102.92, 260.031 >, < 0, 152.328, 0 >,
		< 2337.37, 2099.91, -26.9688 >, < 0, 0, 0 >
	])
	
	FastballAddBuddySpawnForLevel( "mp_grave", TEAM_MILITIA, < 11026.8, -5163.18, 1885.64 >, < 0, 155.05, 0 > )
	FastballAddBuddySpawnForLevel( "mp_grave", TEAM_IMC, < -1952, -3120, 1993.33 >, < 0, 0, 0 > )
	FastballAddPanelSpawnsForLevel( "mp_grave", [
		< 5204.54, -2726.54, 2376.03 >, < 0, -90, 0 >,
		< 6001.58, -4126.61, 2252.03 >, < 0, -135, 0 >,
		< 3595.96, -4568.04, 2376.03 >, < 0, -135, 0 >
	])
}

void function SpawnPanelsForLevel()
{
	int panelId
	foreach ( Point panelSpawn in file.panelSpawns )
	{
		entity panel = CreatePanel( panelSpawn.origin, panelSpawn.angles )	
		panel.s.panelId <- panelId++
	}
}

void function ResetPanels()
{
	foreach ( entity panel in GetAllControlPanels() )
		SetTeam( panel, TEAM_UNASSIGNED )
}

void function FastballInitPlayer( entity player )
{
	foreach ( entity panel in GetAllControlPanels() )
		Remote_CallFunction_NonReplay( player, "ServerCallback_FastballUpdatePanelRui", panel.GetEncodedEHandle(), panel.s.panelId )
}

void function FastballAddPanelSpawnsForLevel( string level, array<vector> positionsAndOrigins )
{
	if ( GetMapName() != level )
		return
	
	for ( int i = 0; i < positionsAndOrigins.len(); i += 2 )
	{
		Point spawnPoint
		spawnPoint.origin = positionsAndOrigins[ i ]
		spawnPoint.angles = positionsAndOrigins[ i + 1 ]
		
		file.panelSpawns.append( spawnPoint )
	}
}

entity function CreatePanel( vector origin, vector angles )
{
	entity panel = CreateEntity( "prop_control_panel" )
	panel.SetValueForModelKey( $"models/communication/terminal_usable_imc_01.mdl" )
	panel.SetOrigin( origin )
	panel.SetAngles( angles )
	panel.kv.solid = SOLID_VPHYSICS
	DispatchSpawn( panel )
	
	panel.SetModel( $"models/communication/terminal_usable_imc_01.mdl" )
	panel.s.onPlayerFinishesUsing_func = FastballOnPanelHacked
	
	Highlight_SetNeutralHighlight( panel, "sp_enemy_pilot" )
	
	return panel
}

// control panel code isn't very statically typed, pain
function FastballOnPanelHacked( panel, player, success )
{
	expect entity( panel )
	expect entity( player )
	expect bool( success )
	
	if ( !success )
		return
		
	print( panel + " was hacked by " + player )
	PanelFlipsToPlayerTeamAndUsableByEnemies( panel, player )
	player.SetPlayerGameStat( PGS_ASSAULT_SCORE, player.GetPlayerGameStat( PGS_ASSAULT_SCORE ) + 1 )
	
	foreach ( entity otherPlayer in GetPlayerArray() )
		Remote_CallFunction_NonReplay( otherPlayer, "ServerCallback_FastballPanelHacked", panel.GetEncodedEHandle(), panel.s.panelId, player.GetEncodedEHandle() )
	
	// respawn dead players
	foreach ( entity deadPlayer in GetPlayerArrayOfTeam( player.GetTeam() ) )
	{
		if ( !IsAlive( deadPlayer ) )
		{
			deadPlayer.SetOrigin( player.GetOrigin() )
			deadPlayer.RespawnPlayer( null )
			Remote_CallFunction_NonReplay( deadPlayer, "ServerCallback_FastballRespawnPlayer" ) 
		}
	}
}

int function FastballDecideWinner()
{
	int militiaPanels
	int imcPanels
	
	foreach ( entity panel in GetAllControlPanels() )
	{
		if ( panel.GetTeam() == TEAM_MILITIA )
			militiaPanels++
		else if ( panel.GetTeam() == TEAM_IMC )
			imcPanels++
	}
	
	if ( militiaPanels > imcPanels )
		return TEAM_MILITIA
	else if ( imcPanels > militiaPanels )
		return TEAM_IMC
		
	return TEAM_UNASSIGNED
}