summaryrefslogtreecommitdiffstats
path: root/TemplePushing.c4s/Script.c
diff options
context:
space:
mode:
authorJan <>2015-07-22 22:16:34 +0200
committerJan <_>2015-07-23 00:14:01 +0200
commit070efdaa1839f28d1ca93c33945930539d0d2158 (patch)
tree17303e042dc12fda2159d5cc15d419926005aeca /TemplePushing.c4s/Script.c
parent83d5f00e47e2a036ecd246a1c679a8fbf10c742f (diff)
downloadtempelschubsen-070efdaa1839f28d1ca93c33945930539d0d2158.tar.gz
tempelschubsen-070efdaa1839f28d1ca93c33945930539d0d2158.zip
Add rule for enabling/disabling background music per player
Diffstat (limited to 'TemplePushing.c4s/Script.c')
-rw-r--r--TemplePushing.c4s/Script.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/TemplePushing.c4s/Script.c b/TemplePushing.c4s/Script.c
index d123912..5df463a 100644
--- a/TemplePushing.c4s/Script.c
+++ b/TemplePushing.c4s/Script.c
@@ -10,6 +10,10 @@ static const SORT_SORTCOL_Team = 0, SORT_SORTCOL_Player = 1, SORT_SORTCOL_Leaver
static const MaxTeamCount = 3;
+static const PlrData_EnableAmbienceSounds = "TemplePushing_EnableAmbienceSounds";
+static const PlrData_EnableAmbienceSounds_Yes = 1;
+static const PlrData_EnableAmbienceSounds_No = 2;
+
static section, mode;
static numRelaunches;
static deathmatchEnabled, deathmatchWinScore;
@@ -79,6 +83,8 @@ func InitializePlayer(int player)
SetScoreboardData(PlayerRow(player), SBRD_TeamSortCol, " ", GetPlayerTeam(player));
UpdateScoreboard(player);
LaunchClonk(player, GetCrew(player));
+
+ if (ambienceEnabled) DoAmbienceSounds(player);
}
func GetRelaunchesLeft(int player) { return numRelaunches - playerDeaths[GetPlayerID(player)]; }
@@ -185,15 +191,6 @@ func Script0()
LoadScenarioSection(DefinitionCall(sectionID, "SectionName"));
loadingSection = false;
section = CreateObject(sectionID, 0, 0, NO_OWNER);
-
- // Play ambience sounds
- if (ambienceEnabled)
- {
- for(var sound in section->SectionAmbienceSounds())
- {
- SoundLevel(sound[0], sound[1]);
- }
- }
// Create spawnpoints
if (mode != MODE_Apocalyptic)
@@ -248,6 +245,7 @@ func Script0()
CreateObject(MELE, 0, 0, NO_OWNER);
// Create rules
+ CreateObject(TBMC, 0, 0, NO_OWNER); // Rule for enabling/disabling music
if (extinguisherEnabled) CreateObject(_ETG, 0, 0, NO_OWNER);
if (suddendeathEnabled) CreateObject(SDDT, 0, 0, NO_OWNER);
if (rotateInJumpEnabled) CreateObject(RIJP, 0, 0, NO_OWNER);
@@ -683,3 +681,37 @@ func CheckGameStatus()
}
}
}
+
+func WantsAmbienceSounds(int player)
+{
+ // Check if user already specified in the past if he wants to enable ambience sounds
+ var preference = GetPlrExtraData(player, PlrData_EnableAmbienceSounds);
+ if (preference == PlrData_EnableAmbienceSounds_Yes) return true;
+ if (preference == PlrData_EnableAmbienceSounds_No) return false;
+ // Preference not set yet/invalid? Enable for non-league games and disable otherwise.
+ return !GetLeague();
+}
+
+func DoAmbienceSounds(int player)
+{
+ for (var sound in section->SectionAmbienceSounds())
+ {
+ Sound(sound[0], true, 0, sound[1], player + 1, WantsAmbienceSounds(player) * 2 - 1);
+ }
+}
+
+func ToggleAmbienceSounds(int player)
+{
+ var preference;
+ if (WantsAmbienceSounds(player))
+ {
+ preference = PlrData_EnableAmbienceSounds_No;
+ }
+ else
+ {
+ preference = PlrData_EnableAmbienceSounds_Yes;
+ }
+
+ SetPlrExtraData(player, PlrData_EnableAmbienceSounds, preference);
+ DoAmbienceSounds(player);
+} \ No newline at end of file