Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Gameplay.MusicInfo


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
class MusicInfo extends Engine.MusicManagerBase
	placeable
	native;

var() string IntroMusic;
var() string ExplorationMusic;
var() string CombatMusic;
var() string TensionMusic;

enum EMusicType
{
	MS_NoMusic,
	MS_ExplorationMusic,
	MS_IntroMusic,
	MS_CombatMusic,
	MS_TensionMusic,
};

struct native DynamicMusicOptions
{
	var() float FadeInTime;
	var() float FadeOutTime;
	var() float MinLifetime;
};

// ug hacky. seeing as we only have 2 dynamic music types, dont bother generalisin this into an array or anythin
var() DynamicMusicOptions	CombatMusicOptions;
var() DynamicMusicOptions	TensionMusicOptions;
var() float					IntroMusicFadeOutTime;

// state
var EMusicType			CurrentMusicType;
var float				CurrentSongTimer;		// if non zero, countdown to when we should start fading out the current song
var float				CurrentSongFadeTime;	// time to fade out the current song over (when CurrentSongTimer has elapsed)
var bool				TriggeredIntroMusic;	// just to make sure we onyl do it once

// transient (within sound system)
var transient float		CurrentMusicLength;
var transient int		CurrentSongHandle;

simulated function Tick(float Delta)
{
	// restart music from savegame (music type is set, but we dont have a valid handle)
	if (CurrentMusicType != MS_NoMusic && !PlayingMusic())
		RestartSavegameMusic();

	// start intro/level music
	if (CurrentMusicType == MS_NoMusic)
	{
		if (Len(IntroMusic) != 0 && !TriggeredIntroMusic)
			TriggerIntroMusic();
		
		// if intro music not started (not specified, play failed or already triggered), start normal level music
		if (!PlayingMusic())
			StartMusicType(MS_ExplorationMusic, 0);
	}

	// handle fade out of current music
	if (ShouldProcessFadeOut())
	{
		CurrentSongTimer -= Delta;
		// song timer expired, transition to explotation music
		if (CurrentSongTimer <= 0)
			StartMusicType(MS_ExplorationMusic, CurrentSongFadeTime);
	}
}

simulated function TriggerIntroMusic()
{
	StartMusicType(MS_IntroMusic, 0);

	CurrentSongFadeTime = IntroMusicFadeOutTime;
	CurrentSongTimer = CurrentMusicLength - IntroMusicFadeOutTime;
	
	TriggeredIntroMusic = true;
}

simulated function TriggerDynamicMusic(EDynamicMusicType Type)
{
	switch(Type)
	{
	case MT_Combat:
		ProcessDynamicMusic(MS_CombatMusic, CombatMusic, CombatMusicOptions.FadeInTime, 
				CombatMusicOptions.FadeOutTime, CombatMusicOptions.MinLifeTime);
		break;
		
	case MT_Tension:
		// NOTE: tension should not override combat music
		if (CurrentMusicType != MS_CombatMusic)
			ProcessDynamicMusic(MS_TensionMusic, TensionMusic, TensionMusicOptions.FadeInTime, 
					TensionMusicOptions.FadeOutTime, TensionMusicOptions.MinLifeTime);
		break;
	}
}

simulated function TriggerScriptMusic(string MusicName, float FadeTime)
{
	// TBD: do we need this anymore???
}

// NOTE: MusicName is only passed in so that this funciton can validate whether to even try playing music (incase none is specified)
simulated function ProcessDynamicMusic(EMusicType MusicType, string MusicName, float FadeInTime, float FadeOutTime, float MinLifeTime)
{
	if (CurrentMusicType != MusicType && Len(MusicName) != 0)
	{
		StartMusicType(MusicType, FadeInTime);
		CurrentSongFadeTime = FadeOutTime;
	}
		
	// restart music timer if succsefully playing
	if (CurrentMusicType == MusicType)
		CurrentSongTimer = MinLifeTime;
}

simulated function bool ShouldProcessFadeOut()
{
	return PlayingMusic() && ( CurrentMusicType == MS_IntroMusic || CurrentMusicType == MS_CombatMusic || CurrentMusicType == MS_TensionMusic);
}

simulated function bool PlayingMusic()
{
	return CurrentSongHandle != 0;
}

simulated function RestartSavegameMusic()
{
	// dont re-play intro music when loading a saved game
	if (CurrentMusicType == MS_IntroMusic)
		CurrentMusicType = MS_ExplorationMusic;

	StartMusicType(CurrentMusicType, 0);	
}

simulated function StartMusicType(EMusicType Music, float FadeTime)
{
	switch (Music)
	{
	case MS_ExplorationMusic:	StartMusic(ExplorationMusic, FadeTime); break;
	case MS_IntroMusic:			StartMusic(IntroMusic, FadeTime); break;
	case MS_CombatMusic:		StartMusic(CombatMusic, FadeTime); break;
	case MS_TensionMusic:		StartMusic(TensionMusic, FadeTime); break;
	};

	if (PlayingMusic())
		CurrentMusicType = Music;
	else
		CurrentMusicType = MS_NoMusic;
}

simulated function StartMusic(string MusicName, float FadeTime)
{
	// stop old music
	StopCurrentMusic(FadeTime);

	// startup new music
	CurrentSongHandle = PlayMusic(MusicName, FadeTime);
	if (CurrentSongHandle != 0)
	{
		CurrentMusicLength = GetMusicDuration(MusicName);
	}
	else
	{
		CurrentMusicLength = 0;
	}

//	log("Start Music on "$MusicName$"     Length = "$CurrentMusicLength$"  FadeTime = "$FadeTime);
}

// NOTE!: this function will only work if the music is playing in the sound system
native function float GetMusicDuration(string MusicName);

simulated function StopCurrentMusic(float FadeTime)
{
	if (CurrentSongHandle != 0)
	{
		StopMusic(CurrentSongHandle, FadeTime);
	}

	CurrentSongHandle = 0;
	CurrentMusicType = MS_NoMusic;
}

defaultproperties
{
	CurrentMusicType	= MS_NoMusic
	CurrentSongHandle	= 0
	CurrentSongTimer	= 0
	TriggeredIntroMusic = 0
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:12.000 - Creation time: st 23.5.2018 00:10:46.037 - Created with UnCodeX