aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_fastball_intro.gnut
blob: 7548255824f9576c0a598b609c09071d6bb56331 (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
untyped
global function GamemodeFastballIntroSetup
global function FastballAddBuddySpawnForLevel

struct {
	float introStartTime
	
	table< int, Point > buddySpawns
	entity militiaBuddy
	entity imcBuddy
	
	table<entity, bool> playersHoldingJump
} file

void function GamemodeFastballIntroSetup()
{
	RegisterSignal( "fastball_start_throw" )
	RegisterSignal( "fastball_release" )
	
	AddCallback_GameStateEnter( eGameState.Prematch, OnPrematchStart )
	AddCallback_OnClientConnected( AddPlayerToFastballIntro )
}

void function FastballAddBuddySpawnForLevel( string level, int team, vector origin, vector angles )
{
	if ( GetMapName() != level )
		return
		
	Point spawnPoint
	spawnPoint.origin = origin
	spawnPoint.angles = angles
	
	file.buddySpawns[ team ] <- spawnPoint
}

void function OnPrematchStart()
{
	ClassicMP_OnIntroStarted()

	file.introStartTime = Time()
	file.playersHoldingJump = {} // clear it
	
	Point militiaBuddySpawn
	Point imcBuddySpawn
	
	// figure out positions if there's none manually specified
	if ( file.buddySpawns.len() == 0 )
	{
		array<entity> militiaSpawns
		array<entity> imcSpawns
	
		foreach ( entity spawnpoint in GetEntArrayByClass_Expensive( "info_spawnpoint_titan_start" ) )
		{
			// trace from top to bottom
			float result = TraceHullSimple( spawnpoint.GetOrigin() + < 0, 0, 250 >, spawnpoint.GetOrigin(), < -200, -200, 0 >, < 200, 200, 400 >, null )
			
			// don't need to trace much, as long as it's over 0 that means it fits
			// cases where it's over 0 but less than 1 are usually caused by terrain
			if ( result > 0 )
			{
				if ( spawnpoint.GetTeam() == TEAM_MILITIA ) 
					militiaSpawns.append( spawnpoint )
				else
					imcSpawns.append( spawnpoint )
			}
		}
		
		entity milititaSpawnEnt = militiaSpawns[ RandomInt( militiaSpawns.len() ) ]
		militiaBuddySpawn.origin = milititaSpawnEnt.GetOrigin()
		militiaBuddySpawn.angles = milititaSpawnEnt.GetAngles()
		
		entity imcSpawnEnt = imcSpawns[ RandomInt( imcSpawns.len() ) ]
		imcBuddySpawn.origin = imcSpawnEnt.GetOrigin()
		imcBuddySpawn.angles = imcSpawnEnt.GetAngles()
	}
	else
	{
		militiaBuddySpawn = file.buddySpawns[ TEAM_MILITIA ]
		imcBuddySpawn = file.buddySpawns[ TEAM_IMC ] 
	}
			
	file.militiaBuddy = CreatePropDynamic( $"models/titans/buddy/titan_buddy.mdl" )
	file.militiaBuddy.SetOrigin( militiaBuddySpawn.origin )
	file.militiaBuddy.SetAngles( militiaBuddySpawn.angles )
	thread AnimateBuddy( file.militiaBuddy )
	
	file.imcBuddy = CreatePropDynamic( $"models/titans/buddy/titan_buddy.mdl" )
	file.imcBuddy.SetOrigin( imcBuddySpawn.origin )
	file.imcBuddy.SetAngles( imcBuddySpawn.angles )
	thread AnimateBuddy( file.imcBuddy )
	
	foreach ( entity player in GetPlayerArray() )
		thread FastballPlayer( player )
}

void function AnimateBuddy( entity buddy )
{
	print( "buddy spawn at " + buddy.GetOrigin() + " " + buddy.GetAngles() )

	thread PlayAnim( buddy, "bt_beacon_fastball_throw_end" )
	
	// play dialogue at the right time
	buddy.WaitSignal( "fastball_start_throw" )
	float diagDuration = EmitSoundOnEntity( buddy, "diag_sp_spoke1_BE117_04_01_mcor_bt" ) // trust me
	StartParticleEffectOnEntity( buddy, GetParticleSystemIndex( $"P_BT_eye_SM" ), FX_PATTACH_POINT_FOLLOW, buddy.LookupAttachment( "EYEGLOW" ) )
	
	wait diagDuration
	if ( GetGameState() != eGameState.Playing )
		ClassicMP_OnIntroFinished()
	
	buddy.WaitSignal( "fastball_release" )
	wait 5.0
	buddy.Destroy()
}

void function AddPlayerToFastballIntro( entity player )
{	
	if ( GetGameState() == eGameState.Prematch )
		thread FastballPlayer( player )
}

void function FastballPlayer( entity player )
{
	player.EndSignal( "OnDeath" )
	player.EndSignal( "OnDestroy" )
	
	OnThreadEnd( function() : ( player )
	{
		RemoveCinematicFlag( player, CE_FLAG_CLASSIC_MP_SPAWNING )
		player.ClearParent()
		ClearPlayerAnimViewEntity( player )
		player.DeployWeapon()
		player.PlayerCone_Disable()
	})
	
	FirstPersonSequenceStruct throwSequence
	throwSequence.attachment = "REF"
	throwSequence.useAnimatedRefAttachment = true
	throwSequence.hideProxy = true
	throwSequence.viewConeFunction = ViewConeFastball // this seemingly does not trigger for some reason
	throwSequence.firstPersonAnim = "ptpov_beacon_fastball_throw_end"
	// mp models seemingly have no 3p animation for this
	throwSequence.firstPersonBlendOutTime = 0.0
	throwSequence.teleport = true
	throwSequence.setInitialTime = Time() - file.introStartTime
	
	// get our buddy
	entity buddy
	if ( player.GetTeam() == TEAM_MILITIA )
		buddy = file.militiaBuddy
	else
		buddy = file.imcBuddy
	
	// respawn the player
	player.SetOrigin( buddy.GetOrigin() )
	player.RespawnPlayer( null )
	player.Hide()
	player.HolsterWeapon()
	
	// hide hud, fade screen out from black
	AddCinematicFlag( player, CE_FLAG_CLASSIC_MP_SPAWNING )
	ScreenFadeFromBlack( player, 0.5, 0.5 )
	
	// start fp sequence
	thread FirstPersonSequence( throwSequence, player, buddy )
	
	// manually do this because i can't get viewconefastball to work
	player.PlayerCone_FromAnim()
	player.PlayerCone_SetMinYaw( -50 )
	player.PlayerCone_SetMaxYaw( 25 )
	player.PlayerCone_SetMinPitch( -15 )
	player.PlayerCone_SetMaxPitch( 15 )
	
	buddy.WaitSignal( "fastball_start_throw" )
	// lock in their final angles at this point
	vector throwVel = AnglesToForward( player.EyeAngles() ) * 950
	throwVel.z = 675.0
	
	// wait for it to finish
	buddy.WaitSignal( "fastball_release" )
	
	if ( player.IsInputCommandHeld( IN_JUMP ) )
		throwVel.z = 850.0
	
	// have to correct this manually here since due to no 3p animation our position isn't set right during this sequence
	player.SetOrigin( buddy.GetAttachmentOrigin( buddy.LookupAttachment( "FASTBALL_R" ) ) )
	player.Show()
	player.SetVelocity( throwVel )
	
	TryGameModeAnnouncement( player )
}

void function PlayerHoldingJumpInIntro( entity player )
{
	file.playersHoldingJump[ player ] <- true
}

void function PlayerNoLongerHoldingJumpInIntro( entity player )
{
	file.playersHoldingJump[ player ] <- false
}