add SoundAt function in C4Script (part of #238), document

also, extend the documentation for Sound with previously undocumented parameters; threw out undocumented and also unused "multiple" parameter.
stable-5.4
Tobias Zwick 2013-11-29 18:20:36 +07:00
parent 7b9c1d5a9e
commit ceca8b8fc7
10 changed files with 191 additions and 97 deletions

View File

@ -1,31 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Music</title>
<category>Music</category>
<version>5.1 OC</version>
<syntax>
<rtype>int</rtype>
<params>
<param>
<type>string</type>
<name>song_name</name>
<desc>Filename of the music track. The file extension must be specified. If unspecified, music playback will be interrupted.</desc>
<optional />
</param>
<param>
<type>bool</type>
<name>loop</name>
<desc>If 1, the specified track will be looped forever.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Plays a music track. The corresponding music file must be available in the active music group. If the loaded scenario contains music files, the scenario file will be the music group. Otherwise, the global file Music.ocg will be used.</desc>
<related><funclink>SetPlayList</funclink></related>
</func>
<author>jwk</author><date>2002-08</date>
</funcs>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Music</title>
<category>Music</category>
<version>5.1 OC</version>
<syntax>
<rtype>int</rtype>
<params>
<param>
<type>string</type>
<name>song_name</name>
<desc>Filename of the music track. The file extension must be specified. If unspecified, music playback will be interrupted.</desc>
<optional />
</param>
<param>
<type>bool</type>
<name>loop</name>
<desc>If 1, the specified track will be looped forever.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Plays a music track. The corresponding music file must be available in the active music group. If the loaded scenario contains music files, the scenario file will be the music group. Otherwise, the global file Music.ocg will be used.</desc>
<related><funclink>SetPlayList</funclink></related>
<related><funclink>Sound</funclink></related>
<related><funclink>SoundAt</funclink></related>
</func>
<author>jwk</author><date>2002-08</date>
</funcs>

View File

@ -1,54 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Sound</title>
<category>Effects</category>
<version>5.1 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>string</type>
<name>name</name>
<desc>Name of the sound effect (without .wav/.ogg extension). Wildcards as used by <funclink>WildcardMatch</funclink> are used.</desc>
</param>
<param>
<type>bool</type>
<name>global</name>
<desc>Specifies wether the sound is played globally, i.e. independently of the object position always with the same loudness.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>volume</name>
<desc>0-100: volume for playback of the sound. A volume value of <code>nil</code> means playback at 100.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>player</name>
<desc>Player number of the player for which the sound is to be played. In network games, the sound will thus not be audible for the other players. If <code>nil</code> (or not specified), the sound will be played for all players.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>loop_count</name>
<desc>Increases or decreases the number of sounds running in a continuous loop. Value +1 will play this sound indefinitely until it is stopped by calling this function again with value -1. Value 0 will play the sound once normally.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Plays a sound. The specified sound file has to be available in the group Sound.ocg, in the active scenario file, or in any loaded object definition. The audibility of object local sounds will depend on the position of the object relative to the visible viewports.</desc>
<examples>
<example>
<code><funclink>FindObject</funclink>(<funclink>Find_ID</funclink>(WindGenerator))-&gt;Sound(&quot;Fanfare&quot;, false, 50);</code>
<text>Plays a 'Fanfare' sound next to the first found wind generator at half volume.</text>
</example>
</examples>
<related><funclink>Music</funclink></related>
</func>
<author>Sven2</author><date>2002-08</date>
</funcs>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Sound</title>
<category>Effects</category>
<version>5.1 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>string</type>
<name>name</name>
<desc>Name of the sound effect (without .wav/.ogg extension). Wildcards as used by <funclink>WildcardMatch</funclink> are used.</desc>
</param>
<param>
<type>bool</type>
<name>global</name>
<desc>Specifies wether the sound is played globally, i.e. independently of the object position always with the same loudness.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>volume</name>
<desc>0-100: volume for playback of the sound. A volume value of <code>nil</code> means playback at 100.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>player</name>
<desc>Player number of the player for which the sound is to be played. In network games, the sound will thus not be audible for the other players. If <code>nil</code> (or not specified), the sound will be played for all players.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>loop_count</name>
<desc>Increases or decreases the number of sounds running in a continuous loop. Value +1 will play this sound indefinitely until it is stopped by calling this function again with value -1. Value 0 will play the sound once normally.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>custom_falloff_distance</name>
<desc>The further away the sound effect from the player, the more quiet it is played. By default, the sound will not be hearable anymore in a distance of 700 pixels. A custom distance can be specified here.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Plays a sound. The specified sound file has to be available in the group Sound.ocg, in the active scenario file, or in any loaded object definition. The audibility of object local sounds will depend on the position of the object relative to the visible viewports.</desc>
<examples>
<example>
<code><funclink>FindObject</funclink>(<funclink>Find_ID</funclink>(WindGenerator))-&gt;Sound(&quot;Fanfare&quot;, false, 50);</code>
<text>Plays a 'Fanfare' sound next to the first found wind generator at half volume.</text>
</example>
</examples>
<related><funclink>SoundAt</funclink></related>
<related><funclink>Music</funclink></related>
</func>
<author>Sven2</author><date>2002-08</date>
</funcs>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>SoundAt</title>
<category>Effects</category>
<version>5.4 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>string</type>
<name>name</name>
<desc>Name of the sound effect (without .wav/.ogg extension). Wildcards as used by <funclink>WildcardMatch</funclink> are used.</desc>
</param>
<param>
<type>int</type>
<name>x</name>
<desc>X-Position of the sound effect. An offset if called from object-context.</desc>
</param>
<param>
<type>int</type>
<name>y</name>
<desc>Y-Position of the sound effect. An offset if called from object-context.</desc>
</param>
<param>
<type>int</type>
<name>volume</name>
<desc>0-100: volume for playback of the sound. A volume value of <code>nil</code> means playback at 100.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>player</name>
<desc>Player number of the player for which the sound is to be played. In network games, the sound will thus not be audible for the other players. If <code>nil</code> (or not specified), the sound will be played for all players.</desc>
<optional />
</param>
<param>
<type>int</type>
<name>custom_falloff_distance</name>
<desc>The further away the sound effect from the player, the more quiet it is played. By default, the sound will not be hearable anymore in a distance of 700 pixels. A custom distance can be specified here.</desc>
<optional />
</param>
</params>
</syntax>
<desc>Plays a sound at the specified position. The specified sound file has to be available in the group Sound.ocg, in the active scenario file, or in any loaded object definition.</desc>
<related><funclink>Sound</funclink></related>
<related><funclink>Music</funclink></related>
</func>
<author>Sven2</author><date>2002-08</date>
</funcs>

View File

@ -108,7 +108,7 @@ public func ControlUse(object clonk, int x, int y)
magic_number = ObjectNumber();
StartWeaponHitCheckEffect(clonk, length, 1);
this->Sound("WeaponSwing?", false, nil, nil, nil);
this->Sound("WeaponSwing?");
return true;
}

View File

@ -82,19 +82,19 @@ func LostCase()
func StartEngine()
{
Sound("ElevatorStart", nil, nil, nil, nil, nil, 100);
Sound("ElevatorStart", nil, nil, nil, nil, 100);
ScheduleCall(this, "EngineLoop", 34);
//Sound("ElevatorMoving", nil, nil, nil, 1);
}
func EngineLoop()
{
Sound("ElevatorMoving", nil, nil, nil, 1, nil, 100);
Sound("ElevatorMoving", nil, nil, nil, 1, 100);
}
func StopEngine()
{
Sound("ElevatorMoving", nil, nil, nil, -1);
ClearScheduleCall(this, "EngineLoop");
Sound("ElevatorStop", nil, nil, nil, nil, nil, 100);
Sound("ElevatorStop", nil, nil, nil, nil, 100);
}
/* Construction */

View File

@ -79,9 +79,9 @@ func Wind2Turn()
if (Abs(current_wind) >= 10 && Random(15 - Abs(current_wind / 10)) < 5)
{
if (!Random(2))
Sound("WoodCreak?",false,nil,nil,0,false, 75);
Sound("WoodCreak?",false,nil,nil,nil, 75);
else
Sound("HingeCreak?",false,nil,nil,0,false, 75);
Sound("HingeCreak?",false,nil,nil,nil, 75);
}
}

View File

@ -454,7 +454,37 @@ static C4Void FnBlastFree(C4PropList * _this, long iX, long iY, long iLevel, Nil
return C4Void();
}
static bool FnSound(C4PropList * _this, C4String *szSound, bool fGlobal, Nillable<long> iLevel, Nillable<long> iAtPlayer, long iLoop, bool fMultiple, long iCustomFalloffDistance)
static bool FnSoundAt(C4PropList * _this, C4String *szSound, long iX, long iY, Nillable<long> iLevel, Nillable<long> iAtPlayer, long iCustomFalloffDistance)
{
// play here?
if (!iAtPlayer.IsNil())
{
// get player to play at
C4Player *pPlr = ::Players.Get(iAtPlayer);
// not existant? fail
if (!pPlr) return false;
// network client: don't play here
// return true for network sync
if (!pPlr->LocalControl) return true;
}
// even less than nothing?
if (iLevel<0) return true;
// default sound level
if (iLevel.IsNil() || iLevel>100)
iLevel=100;
// target object
C4Object *pObj = Object(_this);
if (pObj)
{
iX += pObj->GetX();
iY += pObj->GetY();
}
StartSoundEffectAt(FnStringPar(szSound),iX,iY,iLevel,iCustomFalloffDistance);
// always return true (network safety!)
return true;
}
static bool FnSound(C4PropList * _this, C4String *szSound, bool fGlobal, Nillable<long> iLevel, Nillable<long> iAtPlayer, long iLoop, long iCustomFalloffDistance)
{
// play here?
if (!iAtPlayer.IsNil())
@ -476,7 +506,7 @@ static bool FnSound(C4PropList * _this, C4String *szSound, bool fGlobal, Nillabl
C4Object *pObj = NULL;
if (!fGlobal) pObj = Object(_this);
// already playing?
if (iLoop >= 0 && !fMultiple && GetSoundInstance(FnStringPar(szSound), pObj))
if (iLoop >= 0 && GetSoundInstance(FnStringPar(szSound), pObj))
return false;
// try to play effect
if (iLoop >= 0)
@ -2418,6 +2448,7 @@ void InitGameFunctionMap(C4AulScriptEngine *pEngine)
AddFunc(pEngine, "FindConstructionSite", FnFindConstructionSite);
AddFunc(pEngine, "CheckConstructionSite", FnCheckConstructionSite);
AddFunc(pEngine, "Sound", FnSound);
AddFunc(pEngine, "SoundAt", FnSoundAt);
AddFunc(pEngine, "Music", FnMusic);
AddFunc(pEngine, "MusicLevel", FnMusicLevel);
AddFunc(pEngine, "SetPlayList", FnSetPlayList);

View File

@ -525,7 +525,8 @@ uint32_t C4PacketPing::getTravelTime() const
void C4PacketPing::CompileFunc(StdCompiler *pComp)
{
// FIXME: the compiler can't compile 64bit integers yet, the ping will return wrong times if GetTime() returns large ints
// FIXME: the compiler can't compile 64bit integers (yet), the ping will
// return wrong times if GetTime() returns integers too large for uint32
uint32_t time;
pComp->Value(mkNamingAdapt(time, "Time", 0U));
tTime = time;

View File

@ -628,12 +628,12 @@ C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop, int32_t iVo
return Application.SoundSystem.NewEffect(szSndName, fLoop, iVolume, pObj, iCustomFalloffDistance);
}
C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, bool fLoop, int32_t iVolume)
C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, int32_t iVolume, int32_t iCustomFallofDistance)
{
// Sound check
if (!Config.Sound.RXSound) return NULL;
// Create
C4SoundInstance *pInst = StartSoundEffect(szSndName, fLoop, iVolume);
C4SoundInstance *pInst = StartSoundEffect(szSndName, false, iVolume, NULL, iCustomFallofDistance);
// Set volume by position
if (pInst) pInst->SetVolumeByPos(iX, iY);
// Return

View File

@ -137,7 +137,7 @@ protected:
};
class C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj=NULL, int32_t iCustomFalloffDistance=0);
class C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, bool fLoop = false, int32_t iVolume = 100);
class C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, int32_t iVolume = 100, int32_t iCustomFallofDistance=0);
class C4SoundInstance *GetSoundInstance(const char *szSndName, C4Object *pObj);
void StopSoundEffect(const char *szSndName, C4Object *pObj);
void SoundLevel(const char *szSndName, C4Object *pObj, int32_t iLevel);