aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/mp/_music.gnut
blob: 44320336146a57c8569a5cbee1e8d1c235413e50 (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
global function Music_Init
global function CreateTeamMusicEvent
global function PlayCurrentTeamMusicEventsOnPlayer
global function CreateLevelIntroMusicEvent
global function PlayMusicToCompletion
global function PlayMusicToAll
global function CreateLevelWinnerDeterminedMusicEvent

const int MUSIC_EVENT_UNINITIALIZED = -1


struct MusicEvent
{
	int musicPieceID = MUSIC_EVENT_UNINITIALIZED
	float timeMusicStarted
	bool shouldSeek
}

struct
{
	table< int, MusicEvent > musicEvents
} file


void function Music_Init()
{
	MusicEvent imcMusicEvent
	MusicEvent militiaMusicEvent
	file.musicEvents[ TEAM_IMC ] <- imcMusicEvent
	file.musicEvents[ TEAM_MILITIA ] <- militiaMusicEvent

	AddCallback_GameStateEnter( eGameState.Prematch, CreateLevelIntroMusicEvent )
}

void function CreateTeamMusicEvent( int team, int musicPieceID, float timeMusicStarted, bool shouldSeek = true )
{
	Assert( !( shouldSeek == false && timeMusicStarted > 0 ), "Don't pass in timeMusicStarted when creating a TeamMusicEvent with shouldSeek set to false!" )

	MusicEvent musicEvent
	musicEvent.musicPieceID  = musicPieceID
	musicEvent.timeMusicStarted = timeMusicStarted
	musicEvent.shouldSeek = shouldSeek

	file.musicEvents[ team ] = musicEvent
}

void function PlayCurrentTeamMusicEventsOnPlayer( entity player )
{
	int team = player.GetTeam()
	MusicEvent musicEvent

	if ( team in file.musicEvents )
		musicEvent = file.musicEvents[ team ]
	else
		musicEvent = file.musicEvents[ TEAM_MILITIA ] //This normally means we're in FFA. Fine to failsafe to use any music event

	if ( musicEvent.musicPieceID == MUSIC_EVENT_UNINITIALIZED ) //No current music event
		return

	Remote_CallFunction_NonReplay( player, "ServerCallback_PlayTeamMusicEvent", musicEvent.musicPieceID, musicEvent.timeMusicStarted, musicEvent.shouldSeek )
}

void function CreateLevelIntroMusicEvent()
{
	//printt( "Creating LevelIntroMusicEvent" )
	CreateTeamMusicEvent( TEAM_IMC, eMusicPieceID.LEVEL_INTRO, Time() )
	CreateTeamMusicEvent( TEAM_MILITIA, eMusicPieceID.LEVEL_INTRO, Time() )
}

void function PlayMusicToCompletion( int musicID )
{
	array<entity> players = GetPlayerArray()
	foreach ( entity player in players )
	{
		Remote_CallFunction_NonReplay( player, "ServerCallback_PlayMusicToCompletion", musicID )
	}
}

void function PlayMusicToAll( int musicID )
{
	array<entity> players = GetPlayerArray()
	foreach ( entity player in players )
	{
		Remote_CallFunction_NonReplay( player, "ServerCallback_PlayMusic", musicID )
	}
}

void function CreateLevelWinnerDeterminedMusicEvent()
{
	//printt( "Creating CreateLevelWinnerDeterminedMusicEvent" )
	if ( IsFFAGame() )
		return

	int winningTeam = GetWinningTeam()

	if ( winningTeam )
	{
		int losingTeam = GetOtherTeam( winningTeam )
		CreateTeamMusicEvent( winningTeam, eMusicPieceID.LEVEL_WIN, Time() )
		CreateTeamMusicEvent( losingTeam, eMusicPieceID.LEVEL_LOSS, Time() )
	}
	else
	{
		CreateTeamMusicEvent( TEAM_MILITIA, eMusicPieceID.LEVEL_DRAW, Time() )
		CreateTeamMusicEvent( TEAM_IMC, eMusicPieceID.LEVEL_DRAW, Time() )
	}
}