aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/sh_powerup.gnut
blob: c390b5f579f1c8381736bceada6535b767e10729 (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
global function SH_PowerUp_Init
global function GetPowerUpFromIndex
global function GetPowerUpFromItemRef

//Proto Use Functions
global function PowerUp_Func_GiveEPG
global function PowerUp_Func_GiveHELL
global function PowerUp_Func_GiveLSTAR
global function PowerUp_Func_GiveSHOTGUN
global function PowerUp_Func_GiveArmorSmall
global function PowerUp_Func_GiveArmorMedium
global function PowerUp_Func_GiveArmorLarge
global function PowerUp_Func_TitanBuildTime
global function PowerUp_Func_PilotUpgrade
global function PowerUp_Func_GiveTicks

global struct PowerUp
{
	int index
	string name
	asset icon
	asset model
	asset baseModel
	string itemRef
	vector modelOffset
	vector modelAngles
	float respawnDelay
	vector glowColor
	bool titanPickup
	int maxInWorld
	void functionref( entity ) destroyFunc
	bool functionref() spawnFunc
}

const bool TITAN_PICKUP = true
const bool PILOT_PICKUP = false

struct
{
	array<PowerUp> powerUps
}file

const TEST_MODEL = $"models/communication/terminal_com_station.mdl"
const TEST_ICON = $"vgui/HUD/coop/minimap_coop_nuke_titan"

void function SH_PowerUp_Init()
{
	#if SERVER || CLIENT
	PrecacheWeapon( "mp_weapon_epg" )
	PrecacheWeapon( "mp_weapon_arena1" )
	PrecacheWeapon( "mp_weapon_arena2" )
	PrecacheWeapon( "mp_weapon_arena3" )
	PrecacheWeapon( "mp_weapon_lstar" )
	PrecacheWeapon( "mp_weapon_shotgun_doublebarrel" )
	PrecacheWeapon( "mp_weapon_frag_drone" )
	#endif

	file.powerUps.resize( ePowerUps.count )
	CreatePowerUp( ePowerUps.weaponEPG, 			 "mp_weapon_epg",					"EPG", 				60.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveEPG, 			<255,0,0>, PILOT_PICKUP, $"vgui/HUD/op_ammo_mini", $"models/weapons/auto_rocket_launcher_ARL/w_ARL.mdl", 	$"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.weaponHELL, 			 "mp_weapon_arena3",				"HELL", 			90.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveHELL, 			<255,0,0>, PILOT_PICKUP, $"vgui/HUD/op_ammo_mini", $"models/weapons/defender/w_defender.mdl", 				$"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.weaponLSTAR, 			 "mp_weapon_lstar",					"LSTAR", 			45.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveLSTAR, 			<255,0,0>, PILOT_PICKUP, $"vgui/HUD/op_ammo_mini", $"models/weapons/lstar/w_lstar.mdl", 					$"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.weaponSHOTGUN, 		 "mp_weapon_shotgun_doublebarrel",	"Shrapnel Shotgun", 30.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveSHOTGUN, 		<255,0,0>, PILOT_PICKUP, $"vgui/HUD/op_ammo_mini", $"models/weapons/mastiff_stgn/w_mastiff.mdl", 			$"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.armorSmall, 			 "mp_loot_armor_small", 			"Armor +5", 		30.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveArmorSmall, 	<0,0,255>, PILOT_PICKUP, $"vgui/HUD/op_health_mini", $"models/gameplay/health_pickup_small.mdl",				$"models/containers/plastic_pallet_01.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.armorMedium, 			 "mp_loot_armor_medium", 			"Armor +25", 		60.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveArmorMedium,	<0,0,255>, PILOT_PICKUP, $"vgui/HUD/op_health_mini", $"models/gameplay/health_pickup_small.mdl",				$"models/containers/plastic_pallet_01.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.armorLarge, 			 "mp_loot_armor_large", 			"Armor +50", 		120.0, 	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveArmorLarge, 	<0,0,255>, PILOT_PICKUP, $"vgui/HUD/op_health_mini", $"models/gameplay/health_pickup_large.mdl",				$"models/containers/plastic_pallet_01.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.titanTimeReduction,	 "mp_loot_titan_build_credit",		"Titan Build Time",	20.0, 	2, FRAShouldSpawnPowerUp, 	  PowerUp_Func_TitanBuildTime, 	<0,255,0>, PILOT_PICKUP, $"vgui/HUD/op_drone_mini", $"models/titans/medium/titan_medium_battery_static.mdl", $"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.LTS_TitanTimeReduction, "mp_loot_titan_build_credit_lts",	"Titan Build Time",	60.0, 	0, LTSShouldSpawnPowerUp, 	  PowerUp_Func_TitanBuildTime, 	<0,255,0>, PILOT_PICKUP, $"vgui/HUD/op_drone_mini", $"models/titans/medium/titan_medium_battery_static.mdl", $"models/communication/flag_base.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.pilotUpgrade, 			 "mp_loot_pilot_upgrade", 			"Can of Spinach",	120.0,	0, DefaultShouldSpawnPowerUp, PowerUp_Func_PilotUpgrade, 		<0,255,0>, PILOT_PICKUP, $"vgui/HUD/op_drone_mini", $"models/humans/pilots/pilot_light_ged_m.mdl", 			$"models/communication/flag_base.mdl", 	< 0, 0, 32 >, < 0, 0, 0 > )
	CreatePowerUp( ePowerUps.ticks, 				 "mp_weapon_frag_drone", 			"Ticks",			60.0,	0, DefaultShouldSpawnPowerUp, PowerUp_Func_GiveTicks, 			<255,0,0>, PILOT_PICKUP, $"vgui/HUD/op_ammo_mini", $"models/robots/drone_frag/frag_drone_proj.mdl", 		$"models/robots/drone_frag/frag_drone_proj.mdl", < 0, 0, 32 >, < 0, 0, 0 > )
}

bool function FRAShouldSpawnPowerUp()
{
	return GAMETYPE == FREE_AGENCY
}

bool function LTSShouldSpawnPowerUp()
{
	if ( HasIronRules() )
		return false

	// modified for fw
	//return ( GAMETYPE == LAST_TITAN_STANDING || GAMETYPE == LTS_BOMB )
	return ( GAMETYPE == LAST_TITAN_STANDING || GAMETYPE == LTS_BOMB || GAMETYPE == FORT_WAR )
}

bool function DefaultShouldSpawnPowerUp()
{
	return GetCurrentPlaylistVarInt( "power_ups_enabled", 0 ) == 1
}

void function CreatePowerUp( int enumIndex, string item, string displayName, float respawnTime, int worldLimit, bool functionref() shouldSpawnFunction, void functionref( entity ) destroyFunction, vector color, bool canTitanPickup, asset worldIcon, asset worldModel, asset worldBase, vector worldModelOffset, vector worldModelAngle )
{
	PowerUp power
	power.index = enumIndex
	power.name = displayName
	power.icon = worldIcon
	power.model = worldModel
	power.baseModel = worldBase
	power.itemRef = item
	power.modelOffset = worldModelOffset
	power.modelAngles = worldModelAngle
	power.respawnDelay = respawnTime
	power.destroyFunc = destroyFunction
	power.spawnFunc = shouldSpawnFunction
	power.glowColor = color
	power.titanPickup = canTitanPickup
	power.maxInWorld = worldLimit
	file.powerUps[enumIndex] = power

	#if CLIENT
		PrecacheHUDMaterial( worldIcon )
	#else
		PrecacheModel( worldModel )
		PrecacheModel( worldBase )
	#if R1_VGUI_MINIMAP
		Minimap_PrecacheMaterial( worldIcon )
	#endif
	#endif
}

PowerUp function GetPowerUpFromIndex( int index )
{
	return file.powerUps[index]
}

PowerUp function GetPowerUpFromItemRef( string ref )
{
	foreach( power in file.powerUps )
	{
		if ( power.itemRef == ref )
			return power
	}

	Assert( false, "Power Up not found")
	unreachable
}

//////////////////////////////////////////////
// PROTO USE FUNCTIONS - Maybe should be a bunch of new item_ classes with their own healthkit callbacks?
//////////////////////////////////////////////
void function PowerUp_Func_GiveEPG( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		GiveWeaponPowerUp( player, "mp_weapon_arena2" )
	#endif
}

void function PowerUp_Func_GiveHELL( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		GiveWeaponPowerUp( player, "mp_weapon_arena3" )
	#endif
}

void function PowerUp_Func_GiveLSTAR( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		GiveWeaponPowerUp( player, "mp_weapon_arena1" )
	#endif
}

void function PowerUp_Func_GiveSHOTGUN( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		GiveWeaponPowerUp( player, "mp_weapon_shotgun_doublebarrel" )
	#endif
}

void function PowerUp_Func_GiveTicks( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		player.TakeOffhandWeapon( OFFHAND_ORDNANCE )
		player.GiveOffhandWeapon( "mp_weapon_frag_drone", OFFHAND_ORDNANCE )
		thread RestoreDefaultOffhandWeapon( player )
	#endif
}

#if SERVER
void function RestoreDefaultOffhandWeapon( entity player )
{
	player.EndSignal( "OnDeath" )
	player.EndSignal( "OnDestroy" )

	while( true )
	{
		player.WaitSignal( "ThrowGrenade" )

		if ( player.IsTitan() )
			continue

		entity weapon = player.GetOffhandWeapon( OFFHAND_ORDNANCE )
		if ( weapon.GetWeaponPrimaryClipCount() == 0 )
		{
			player.TakeOffhandWeapon( OFFHAND_ORDNANCE )
			int loadoutIndex = GetActivePilotLoadoutIndex( player )
			PilotLoadoutDef loadout = GetPilotLoadoutFromPersistentData( player, loadoutIndex )
			player.GiveOffhandWeapon( loadout.ordnance, OFFHAND_ORDNANCE )
			return
		}
	}
}

void function GiveWeaponPowerUp( entity player, string newWeapon )
{
	array<entity> weapons = player.GetMainWeapons()
	string weaponToSwitch = player.GetLatestPrimaryWeapon().GetWeaponClassName()

	if ( player.GetActiveWeapon() != player.GetAntiTitanWeapon() )
	{
		foreach ( weapon in weapons )
		{
			string weaponClassName = weapon.GetWeaponClassName()
			if ( weaponClassName == newWeapon )
			{
				weaponToSwitch = weaponClassName
				break
			}
		}
	}

	player.TakeWeaponNow( weaponToSwitch )
	player.GiveWeapon( newWeapon )
	player.SetActiveWeaponByName( newWeapon )
}
#endif

void function PowerUp_Func_GiveArmorSmall( entity player )
{
	GiveArmor( player, 5 )
}

void function PowerUp_Func_GiveArmorMedium( entity player )
{
	GiveArmor( player, 25 )
}

void function PowerUp_Func_GiveArmorLarge( entity player )
{
	GiveArmor( player, 50 )
}

void function GiveArmor( entity player, int amount )
{
	#if SERVER
		if ( player.IsTitan() )
			return
		int currentShieldHealth = player.GetShieldHealth()
		int currentMaxShieldHealth = player.GetShieldHealthMax()
		player.SetShieldHealth( min( 200, amount + currentShieldHealth ) )
		player.SetShieldHealthMax( min( 200, amount + currentMaxShieldHealth ) )
	#endif
}

void function PowerUp_Func_TitanBuildTime( entity player )
{
	#if SERVER
	entity battery = Rodeo_CreateBatteryPack()
	battery.SetOrigin( player.GetOrigin() )
	#endif
}



void function PowerUp_Func_PilotUpgrade( entity player )
{
	#if SERVER
		if ( player.IsTitan() )
			return

		int loadoutIndex = GetPersistentSpawnLoadoutIndex( player, "pilot" )

		PilotLoadoutDef loadout = GetPilotLoadoutFromPersistentData( player, loadoutIndex )

		loadout.primary = "mp_weapon_arena2"
		loadout.secondary = "mp_weapon_mgl"
		loadout.ordnance = "mp_weapon_grenade_emp"

		UpdateDerivedPilotLoadoutData( loadout )

		GivePilotLoadout( player, loadout )
		SetActivePilotLoadoutIndex( player, loadoutIndex )
	#endif
}