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

global function Dogfighter_Init

global function CreateDogFighterAttack
global function LaunchRandomDogFighterAttacks
global function CreateDogFighter
global function CreateDogFighterAssist
global function GetGunshipModel
const TURRET_WEAPON_BULLETS = "mp_weapon_yh803_bullet"

function Dogfighter_Init()
{

	AddDeathCallback( "npc_dropship", OnDogFighterDeath )

	RegisterSignal( "new_attack_thread" )
	RegisterSignal( "GunshipForceLeave" )
}

function LaunchRandomDogFighterAttacks( int team )
{
	svGlobal.levelEnt.Signal( "new_attack_thread" )
	svGlobal.levelEnt.EndSignal( "new_attack_thread" )

	for ( ;; )
	{
		thread CreateDogFighterAttack( team )
		wait RandomFloatRange( 3, 9 )
	}
}

function CreateDogFighterAttack( int team )
{
	FlightPath flightPath = GetAnalysisForModel( GetFlightPathModel( "fp_straton_model" ), STRATON_ATTACK_FULL )

	CallinData drop
	InitCallinData( drop )
	SetCallinStyle( drop, eDropStyle.RANDOM_FROM_YAW )
	SetCallinYaw( drop, RandomFloat( 360 ) )


 	SpawnPointFP spawnPoint = GetSpawnPointForStyle( flightPath, drop )
 	if ( !spawnPoint.valid )
 		return

	entity ship = CreateDogFighter( Vector(0,0,0), Vector(0,0,0), team )

	int hornet_health = 2000
	ship.SetHealth( hornet_health )
	ship.SetMaxHealth( hornet_health )

	ship.EndSignal( "OnDeath" )

	//AddBulletTurrets( ship, team )

	waitthread PlayAnimTeleport( ship, "st_AngelCity_IMC_Win_ComeIn", spawnPoint.origin, spawnPoint.angles )

	thread PlayAnim( ship, "st_AngelCity_IMC_Win_Idle", spawnPoint.origin, spawnPoint.angles )
	waitthread DogFighterWaitsUntilLeave( ship )

	waitthread PlayAnim( ship, "st_AngelCity_IMC_Win_Leave", spawnPoint.origin, spawnPoint.angles, 0.5 )

	ship.Kill_Deprecated_UseDestroyInstead()
}


function DogFighterWaitsUntilLeave( ship, idleMin = 10, idleMax = 15 )
{
	local duration = ship.GetSequenceDuration( "st_AngelCity_IMC_Win_Idle" )

	// make it play full increments of the idle anim
	local maxHealth = ship.GetMaxHealth().tofloat()
	local idleTime = RandomFloatRange( idleMin, idleMax )
	local reps = ( duration / idleTime ).tointeger()
	local totalTime = reps * duration
	local endTime = Time() + totalTime

	for ( ;; )
	{
		if ( ship.GetHealth().tofloat() / maxHealth < 0.2 )
			return
		if ( Time() >= endTime )
			return
		wait 0.1
	}
}

entity function CreateDogFighter( vector origin, vector angles, int team )
{
	entity hornet
	if ( GetBugReproNum() == 81765 )
	{
		hornet = CreateEntity( "npc_dropship" )
	}
	else
	{
		// HACK: using a prop script for now since NPC dropships are still buggy
		// Jiesang told me to do it!
		hornet = CreatePropScript( GetGunshipModel( team ), origin, angles, 8 )
		hornet.EnableAttackableByAI( 50, 0, AI_AP_FLAG_NONE )
		SetTeam( hornet, team )
		hornet.SetOrigin( origin )
		hornet.SetAngles( angles )
	}

	hornet.s.dogfighter <- true
	hornet.kv.teamnumber = team

	local title
	switch ( team )
	{
		case TEAM_MILITIA:
			hornet.SetModel( GetFlightPathModel( "fp_hornet_model" ) )
			title = "Militia Hornet"
			break

		case TEAM_IMC:
			hornet.SetModel( GetFlightPathModel( "fp_straton_model" ) )
			title = "IMC Phantom"
			break
	}

	hornet.SetTitle( title )

	hornet.SetOrigin( origin )
	hornet.SetAngles( angles )
	// DispatchSpawn( hornet )

	//hornet.EnableRenderAlways()
	//hornet.SetAimAssistAllowed( false )

	return hornet
}

void function OnDogFighterDeath( entity ent, var damageInfo )
{
	if ( !IsValid( ent ) )
		return

	if ( !( "dogfighter" in ent.s ) )
		return

	if ( ent.GetHealth() <= 0 )
		FighterExplodes( ent )
}




function AddRocketTurrets( entity ship, int team, int prof = eWeaponProficiency.VERYGOOD )
{
	entity turret = AddTurret( ship, team, "mp_weapon_yh803", "l_exhaust_front_1" )
 	turret.kv.WeaponProficiency = prof
	turret.NotSolid()
	turret.Show()
	entity weapon = turret.GetActiveWeapon()
	weapon.Show()

	turret = AddTurret( ship, team, "mp_weapon_yh803", "r_exhaust_front_1" )
	turret.kv.WeaponProficiency = prof
	turret.NotSolid()
	turret.Show()
	weapon = turret.GetActiveWeapon()
	weapon.Show()
}

void function AddBulletTurrets( entity ship, int team, int prof = eWeaponProficiency.VERYGOOD )
{
	entity turret = AddTurret( ship, team, TURRET_WEAPON_BULLETS, "l_exhaust_front_1" )
 	turret.kv.WeaponProficiency = prof
	turret.NotSolid()
	turret = AddTurret( ship, team, TURRET_WEAPON_BULLETS, "r_exhaust_front_1" )
	turret.kv.WeaponProficiency = prof
	turret.NotSolid()
}

asset function GetGunshipModel( int team )
{
	switch ( team )
	{
		case TEAM_MILITIA:
			return GetFlightPathModel( "fp_hornet_model" )

		case TEAM_IMC:
			return GetFlightPathModel( "fp_straton_model" )
	}

	unreachable
}

void function CreateDogFighterAssist( int team, vector origin, vector angles, float duration = 10.0, entity ship = null, float dropHeight = 1500 )
{
	angles += <0,90,0>

	angles = < 0, angles.y%360, 0 >

 	// DebugDrawSphere( origin, 256, 255, 0, 0, true, 10.0 )

	// warp in effect before
	Point start = GetWarpinPosition( GetFighterModelForTeam( team ), "st_AngelCity_IMC_Win_ComeIn_fast", origin, angles )

	if ( !IsValid( ship ) )
	{
		ship = CreateDogFighter( start.origin, start.angles, team )
	}
	else
	{
		ship.SetOrigin( start.origin )
		ship.SetAngles( start.angles )
	}

	waitthread __WarpInEffectShared( start.origin, start.angles, "", 0.0 )


	ship.SetHealth( 10000 )
	ship.SetMaxHealth( 10000 )
	ship.EndSignal( "OnDeath" )

	#if R1_VGUI_MINIMAP
		ship.Minimap_SetDefaultMaterial( GetMinimapMaterial( "VIP_friendly" ) )
		ship.Minimap_SetFriendlyMaterial( GetMinimapMaterial( "VIP_friendly" ) )
		ship.Minimap_SetEnemyMaterial( GetMinimapMaterial( "VIP_enemy" ) )
		ship.Minimap_SetBossPlayerMaterial( GetMinimapMaterial( "VIP_friendly" ) )
	#endif
	ship.Minimap_SetObjectScale( 0.11 )
	ship.Minimap_SetZOrder( MINIMAP_Z_NPC )

	entity mover = CreateScriptMover( origin, angles )

	OnThreadEnd(
		function () : ( ship, mover )
		{
			if ( IsValid( mover ) )
				mover.Destroy()
			if ( IsValid( ship ) )
				ship.Destroy()
		}
	)

	float SHIP_SIZE = 530
	vector SHIP_MIN = Vector( -SHIP_SIZE/2, -SHIP_SIZE/2, -250 )
	vector SHIP_MAX = Vector( SHIP_SIZE/2, SHIP_SIZE/2, 100 )

	entity turret

	turret = CreateEntity( "npc_turret_sentry" )
	SetSpawnOption_AISettings( turret, "npc_turret_sentry_rockets_dropship" )
	SetSpawnOption_Weapon( turret, "mp_turretweapon_blaster" )
	SetSpawnOption_Alert( turret )
	SetTeam( turret, team )
	DispatchSpawn( turret )
	turret.SetInvulnerable()
	turret.SetParent( ship, "r_turret_attach", false, 0.0 )
	turret.SetTitle( ship.GetTitle() )
	NPC_NoTarget( turret )

	turret = CreateEntity( "npc_turret_sentry" )
	SetSpawnOption_AISettings( turret, "npc_turret_sentry_rockets_dropship" )
	SetSpawnOption_Weapon( turret, "mp_turretweapon_blaster" )
	SetSpawnOption_Alert( turret )
	SetTeam( turret, team )
	DispatchSpawn( turret )
	turret.SetInvulnerable()
	turret.SetParent( ship, "l_turret_attach", false, 0.0 )
	turret.SetTitle( ship.GetTitle() )
	NPC_NoTarget( turret )

	// DrawArrow( origin, angles, 10, 50 )

	waitthread PlayAnimTeleport( ship, "st_AngelCity_IMC_Win_ComeIn_fast", origin, angles )

	// -------------------------------------------------
	// now we want to drop the ship close to the ground
	// -------------------------------------------------

	vector shipOrigin = ship.GetOrigin()
	vector newOrigin = shipOrigin

	if ( dropHeight > 0 )
	{
		// TRACE to find the floor
		float traceFrac = TraceLineSimple( shipOrigin, shipOrigin - Vector(0,0,dropHeight), ship )
		vector floorPos = shipOrigin - Vector(0,0,dropHeight * traceFrac)
		floorPos += Vector( 0,0,400 ) //we don't want the ship to land!

		// TRACE to see if anything is in the way
		float result = TraceHullSimple( shipOrigin, floorPos, SHIP_MIN, SHIP_MAX, ship )
		vector offset = ( shipOrigin - floorPos ) * result

		// This is where we will move the spawnpoint
		newOrigin = origin - offset
	}

	// float duration = ship.GetSequenceDuration( "st_AngelCity_IMC_Win_Idle" )

	ship.SetParent( mover, "REF" )
	ship.Anim_EnableUseAnimatedRefAttachmentInsteadOfRootMotion()

	// Ship comes in...
	thread PlayAnim( ship, "st_AngelCity_IMC_Win_Idle", mover, "REF" )

	// Ship goes down...
	float dropDuration = 5.0
	if ( dropHeight > 0 )
	{
		mover.NonPhysicsMoveTo( newOrigin, dropDuration, dropDuration*0.4, dropDuration*0.4 )
		wait dropDuration
	}

	// Ship hangs out for a while...
	waitthread GunshipWaitLeave( ship, duration )

	// Ship raises before it leaves...
	if ( dropHeight > 0 )
	{
		mover.NonPhysicsMoveTo( origin, dropDuration, dropDuration*0.4, dropDuration*0.4 )
		wait dropDuration
	}
	ship.ClearParent()

	// Ship leaves...
	waitthread PlayAnim( ship, "st_AngelCity_IMC_Win_Leave", origin, angles, 0.5 )
}

void function GunshipWaitLeave( entity ship, float duration )
{
	ship.EndSignal( "GunshipForceLeave" )
	wait duration
}

asset function GetFighterModelForTeam( int team )
{
	switch ( team )
	{
		case TEAM_MILITIA:
			return GetFlightPathModel( "fp_hornet_model" )

		case TEAM_IMC:
			return GetFlightPathModel( "fp_straton_model" )
	}
	unreachable
}