- New Externalization: Externalized the used music to an OPTIONAL "Scripts\Music.lua" file (by Jazz)

o This file is OPTIONAL and if not available, the game uses the default music tracks
o With the user of the Music.lua script file, you can play different musics and types for each sector (*.WAV or *.OGG)
o An example of the usage has been added to "Docs\Externalized Music Example.zip"
o See comments from the Music.lua scripts below

--[[
AddMusic(SectorX,SectorY,SectorZ,MusicType,MusicID)

MusicType :
1 - standard music, sector no enemy (NOTHING_xxx.wav or NOTHING_xxx.ogg)
2 - enemy in sector  (TENSOR_xxx.wav or TENSOR_xxx.ogg)
3 - start battle  (BATTLE_xxx.wav or BATTLE_xxx.ogg)
4 - victory  (TRIUMPH_xxx.wav or TRIUMPH_xxx.ogg)
5 - death merc  (DEATH_xxx.wav or DEATH_xxx.ogg)

xxx - number file

MusicID - id of music

Put to "Music" folder ogg or wav file. We number the names of files NOTHING_0.wav... NOTHING_10.wav ... etc

Example :
AddMusic(1,10,0,1,0) -- add to sector A10, music type "1" and file NOTHING_0.wav or NOTHING_0.ogg.
AddMusic(1,10,1,1,0) -- add to sector A10_B1, music type "1" and file NOTHING_0.wav or NOTHING_0.ogg.
AddMusic(1,9,0,2,10) -- add to sector A9, music type "2" and file TENSOR_10.wav or TENSOR_10.ogg.

for x = 1,16 do
        for y = 1,16 do
		AddMusic(x,y,0,1,10) -- add to all sector, music type "1" and file NOTHING_10.wav or NOTHING_10.ogg.
	end
end

]]

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6295 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2013-08-20 07:15:30 +00:00
parent 74f52b3982
commit ab02106512
11 changed files with 500 additions and 21 deletions
+164 -1
View File
@@ -519,8 +519,12 @@ static int l_AnimMercPtsrusStrategicInsertionData (lua_State *L);
static int l_SetMusicMode (lua_State *L);
static int l_MusicPlay (lua_State *L);
static int l_MusicPlayId (lua_State *L);
static int l_MusicSetVolume (lua_State *L);
static int l_MusicGetVolume (lua_State *L);
static int l_gAddMusic(lua_State *L);
static int l_SetMusicID (lua_State *L);
static int l_GetMusicID (lua_State *L);
//static int l_MusicStop (lua_State *L);
//static int l_MusicFadeOut (lua_State *L);
//static int l_MusicFadeIn (lua_State *L);
@@ -787,6 +791,7 @@ BOOLEAN LuaInternalQuest( UINT8 ubQuest, INT16 sSectorX, INT16 sSectorY, BOOLEAN
static int l_GiveQuestRewardPoint(lua_State *L);
BOOLEAN LuaExecuteStrategicEvent( UINT8 EventCallbackID, UINT32 uiTimeStamp, UINT32 uiTimeOffset, UINT8 ubEventType, UINT8 ubFlags, UINT32 EventParam, UINT32 Init);
BOOLEAN LuaIDScripts(UINT8 Init, UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum);
BOOLEAN LetLuaMusicControl(UINT8 Init);
static int l_CurrentSquad (lua_State *L);
static int l_SetgfTacticalTraversal (lua_State *L);
@@ -1281,6 +1286,12 @@ void IniFunction(lua_State *L, BOOLEAN bQuests )
lua_register(L, "PlayJA2Sample", l_PlayJA2Sample);
lua_register(L, "SetMusicMode", l_SetMusicMode );
lua_register(L, "MusicPlay", l_MusicPlay );
lua_register(L, "MusicIdPlay", l_MusicPlayId );
lua_register(L, "AddMusic", l_gAddMusic );
lua_register(L, "SetMusicID", l_SetMusicID );
lua_register(L, "GetMusicID", l_GetMusicID );
lua_register(L, "MusicSetVolume", l_MusicSetVolume );
lua_register(L, "MusicGetVolume", l_MusicGetVolume );
//lua_register(L, "MusicStop", l_MusicStop );
@@ -1591,6 +1602,25 @@ void IniFunction(lua_State *L, BOOLEAN bQuests )
}
BOOLEAN LetLuaMusicControl(UINT8 Init)
{
const char* filename = "scripts\\Music.lua";
LuaScopeState _LS(true);
IniFunction( _LS.L(), TRUE );
IniGlobalGameSetting( _LS.L() );
SGP_THROW_IFFALSE( _LS.L.EvalFile(filename), _BS("Cannot open file: ") << filename << _BS::cget );
if ( Init == 0 )
{
LuaFunction(_LS.L, "Music" ).Call(0);
}
return true;
}
//------------------- intro -----------
BOOLEAN LuaIntro(UINT8 Init, UINT32 uiCurrentVideo, INT8 bIntroType, UINT32 iStringToUse )
@@ -5219,13 +5249,146 @@ static int l_MusicSetVolume (lua_State *L)
return 0;
}
static int l_SetMusicID (lua_State *L)
{
if ( lua_gettop(L) >= 4 )
{
INT16 x = lua_tointeger(L,1);
INT16 y = lua_tointeger(L,2);
INT16 z = lua_tointeger(L,3);
UINT8 MusicType = lua_tointeger(L,4);
if ( MusicType == 1 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalNothing[z] );
}
else if ( MusicType == 2 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalTensor[z] );
}
else if ( MusicType == 3 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SetMusicModeID( MUSIC_TACTICAL_BATTLE, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalBattle[z] );
}
else if ( MusicType == 4 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SetMusicModeID( MUSIC_TACTICAL_VICTORY, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalVictory[z] );
}
else if ( MusicType == 5 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SetMusicModeID( MUSIC_TACTICAL_DEATH, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalDeath[z] );
}
}
return 0;
}
static int l_GetMusicID (lua_State *L)
{
INT32 SoundID = -1;
if ( lua_gettop(L) >= 4 )
{
INT16 x = lua_tointeger(L,1);
INT16 y = lua_tointeger(L,2);
INT16 z = lua_tointeger(L,3);
UINT8 MusicType = lua_tointeger(L,4);
if ( MusicType == 1 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalNothing[z];
}
else if ( MusicType == 2 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalTensor[z];
}
else if ( MusicType == 3 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalBattle[z];
}
else if ( MusicType == 4 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalVictory[z];
}
}
lua_pushinteger(L, SoundID);
return 1;
}
static int l_gAddMusic(lua_State *L)
{
if ( lua_gettop(L) >= 5 )
{
INT16 x = lua_tointeger(L,1);
INT16 y = lua_tointeger(L,2);
INT16 z = lua_tointeger(L,3);
UINT8 MusicType = lua_tointeger(L,4);
INT32 SoundId = lua_tointeger(L,5);
/*
MUSIC_NONE 0
MUSIC_TACTICAL_NOTHING, 1
MUSIC_TACTICAL_ENEMYPRESENT,2
MUSIC_TACTICAL_BATTLE,3
MUSIC_TACTICAL_VICTORY,4
*/
if ( MusicType == 1 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
MusicSoundValues[SECTOR( x, y )].SoundTacticalNothing[z] = SoundId;
}
else if ( MusicType == 2 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
MusicSoundValues[SECTOR( x, y )].SoundTacticalTensor[z] = SoundId;
}
else if ( MusicType == 3 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
MusicSoundValues[SECTOR( x, y )].SoundTacticalBattle[z] = SoundId;
}
else if ( MusicType == 4 )
{
if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) )
MusicSoundValues[SECTOR( x, y )].SoundTacticalVictory[z] = SoundId;
}
}
return 0;
}
static int l_MusicPlay (lua_State *L)
{
if ( lua_gettop(L) >= 1 )
{
UINT32 uiNum = lua_tointeger(L,1);
MusicPlay( uiNum );
MusicPlay( uiNum, MUSIC_OLD_TYPE, FALSE);
}
return 0;
}
static int l_MusicPlayId (lua_State *L)
{
if ( lua_gettop(L) >= 2 )
{
UINT32 uiNum = lua_tointeger(L,1);
UINT32 uiType = lua_tointeger(L,2);
if (uiType>=1 || uiType<=5 )
MusicPlay( uiNum, uiType, TRUE);
}
return 0;
}
+1
View File
@@ -82,4 +82,5 @@ extern BOOLEAN LetLuaMakeBadSectorListFromMapsOnHardDrive(UINT8 Init);
extern BOOLEAN LuaIntro(UINT8 Init, UINT32 uiCurrentVideo, INT8 bIntroType, UINT32 iStringToUse);
extern BOOLEAN LuaIDScripts(UINT8 Init, UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum);
extern BOOLEAN LetLuaMusicControl(UINT8 Init);
#endif
+9
View File
@@ -2282,6 +2282,10 @@ BOOLEAN SetCurrentWorldSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ )
// ATE; Fade FA.T....
SetMusicFadeSpeed( 5 );
GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ];
if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 )
SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] );
else
SetMusicMode( MUSIC_TACTICAL_NOTHING );
}
@@ -4464,6 +4468,11 @@ void AllMercsHaveWalkedOffSector( )
// ATE; Fade FAST....
SetMusicFadeSpeed( 5 );
GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ];
if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 )
SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] );
else
SetMusicMode( MUSIC_TACTICAL_NOTHING );
}
}