[Scummvm-git-logs] scummvm master -> bd270e91ded4266126746e625f0ee309c5a7b89a

whoozle noreply at scummvm.org
Thu Jul 16 17:21:35 UTC 2026


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
bd270e91de PHOENIXVR: Implement playrndsound command


Commit: bd270e91ded4266126746e625f0ee309c5a7b89a
    https://github.com/scummvm/scummvm/commit/bd270e91ded4266126746e625f0ee309c5a7b89a
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2026-07-16T18:17:40+01:00

Commit Message:
PHOENIXVR: Implement playrndsound command

Found in a few places in Chapter 4 of Amerzone.

Changed paths:
    engines/phoenixvr/commands.h
    engines/phoenixvr/phoenixvr.cpp
    engines/phoenixvr/phoenixvr.h
    engines/phoenixvr/script.cpp


diff --git a/engines/phoenixvr/commands.h b/engines/phoenixvr/commands.h
index ae04ba7790b..0116f492c55 100644
--- a/engines/phoenixvr/commands.h
+++ b/engines/phoenixvr/commands.h
@@ -1861,14 +1861,13 @@ struct PlaySound : public Script::Command {
 	}
 };
 
-struct PlayRandomSound : public PlaySound {
-	int unk;
+struct PlayRndSound : public PlaySound {
+	int probability;
 
-	PlayRandomSound(Common::String s, int v, int u, int l) : PlaySound(Common::move(s), v, l), unk(u) {}
+	PlayRndSound(Common::String s, int v, int p, int l, Audio::Mixer::SoundType t = Audio::Mixer::kSFXSoundType) : PlaySound(Common::move(s), v, l, t), probability(p) {}
 
 	void exec(Script::ExecutionContext &ctx) const override {
-		debug("PlayRandomSound %s %d %d %d", sound.c_str(), volume, unk, loops);
-		PlaySound::exec(ctx);
+		g_engine->playRandomSound(sound, type, volume, probability, loops);
 	}
 };
 
diff --git a/engines/phoenixvr/phoenixvr.cpp b/engines/phoenixvr/phoenixvr.cpp
index 8a748e631e9..6c153704f5f 100644
--- a/engines/phoenixvr/phoenixvr.cpp
+++ b/engines/phoenixvr/phoenixvr.cpp
@@ -841,6 +841,16 @@ void PhoenixVREngine::playSound(const Common::String &sound, Audio::Mixer::Sound
 	_sounds[sound] = Sound{h, spatial, angle, volume, loops, subtitles};
 }
 
+void PhoenixVREngine::playRandomSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int probability, int loops) {
+	debug("register random sound %s %d %d, probability: %d", sound.c_str(), volume, loops, probability);
+	_randomSounds.push_back(RandomSound{
+		sound,
+		type,
+		volume,
+		probability,
+		loops});
+}
+
 void PhoenixVREngine::stopSound(const Common::String &sound) {
 	debug("stop sound %s", sound.c_str());
 	if (sound == _currentMusic)
@@ -862,6 +872,7 @@ void PhoenixVREngine::stopAllSounds() {
 			kv._value.subtitles->clearSubtitle();
 	}
 	_sounds.clear();
+	_randomSounds.clear();
 }
 
 Common::Path PhoenixVREngine::getSubtitlePath(const Common::String &path) const {
@@ -1438,6 +1449,17 @@ void PhoenixVREngine::tick(float dt) {
 			_sounds.erase(it);
 		}
 	}
+	if (!_randomSounds.empty()) {
+		for (auto &sound : _randomSounds) {
+			uint32 rnd = getRandomNumber(UINT_MAX);
+			rnd /= (((0x3C0000 * sound.probability) >> 8) + 0x40000);
+			uint32 lastFrameMs = dt * 1000u;
+			if (rnd < lastFrameMs) {
+				debug("random sound %s triggered: rnd: %d -> %d < %u", sound.sound.c_str(), sound.probability, rnd, lastFrameMs);
+				playSound(sound.sound, sound.type, sound.volume, sound.loops);
+			}
+		}
+	}
 
 	if (!_nextScript.empty()) {
 		loadNextScript();
@@ -1451,6 +1473,7 @@ void PhoenixVREngine::tick(float dt) {
 		_warp = _script->getWarp(_nextWarp);
 		debug("warp %d -> %s %s", _nextWarp, _warp->vrFile.c_str(), _warp->testFile.c_str());
 		_nextWarp = -1;
+		_randomSounds.clear();
 
 		{
 			Common::String origName;
diff --git a/engines/phoenixvr/phoenixvr.h b/engines/phoenixvr/phoenixvr.h
index 5eb688bcef8..7e303dd683c 100644
--- a/engines/phoenixvr/phoenixvr.h
+++ b/engines/phoenixvr/phoenixvr.h
@@ -130,6 +130,7 @@ public:
 	void hideCursor(const Common::String &warp, int idx);
 
 	void playSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int loops, bool spatial = false, float angle = 0);
+	void playRandomSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int probability, int loops);
 	void stopSound(const Common::String &sound);
 	void stopAllSounds();
 	void playMovie(const Common::String &movie);
@@ -298,6 +299,15 @@ private:
 		Common::SharedPtr<Video::Subtitles> subtitles;
 	};
 	Common::HashMap<Common::String, Sound, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _sounds;
+	struct RandomSound {
+		Common::String sound;
+		Audio::Mixer::SoundType type;
+		int volume;
+		int probability;
+		int loops;
+	};
+	Common::Array<RandomSound> _randomSounds;
+
 	Common::ScopedPtr<Script> _script;
 
 	Common::ScopedPtr<RegionSet> _regSet;
diff --git a/engines/phoenixvr/script.cpp b/engines/phoenixvr/script.cpp
index f8e8c37b756..e19ce21e5c2 100644
--- a/engines/phoenixvr/script.cpp
+++ b/engines/phoenixvr/script.cpp
@@ -244,7 +244,7 @@ public:
 			int arg2 = 0;
 			if (maybe(','))
 				arg2 = nextInt();
-			return CommandPtr(new PlayRandomSound(Common::move(sound), arg0, arg1, arg2));
+			return CommandPtr(new PlayRndSound(Common::move(sound), arg0, arg1, arg2));
 		} else if (keyword("stopsound3d")) {
 			return CommandPtr(new StopSound3D(nextWord()));
 		} else if (keyword("stopsound") || keyword("stopmusique")) {




More information about the Scummvm-git-logs mailing list