2022-11-20 07:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DukeSoundController : DukeActor
|
|
|
|
{
|
2023-05-14 10:18:47 +00:00
|
|
|
override void Initialize(DukeActor spawner)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
|
|
|
if (ud.multimode < 2 && self.pal == 1)
|
|
|
|
{
|
|
|
|
self.scale = (0, 0);
|
|
|
|
self.ChangeStat(STAT_MISC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.cstat = CSTAT_SPRITE_INVISIBLE;
|
2022-12-19 09:21:20 +00:00
|
|
|
self.ChangeStat(STAT_FX);
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override void Tick()
|
|
|
|
{
|
|
|
|
double maxdist = self.hitag * maptoworld;
|
|
|
|
|
|
|
|
if (self.temp_data[1] != Raze.SoundEnabled())
|
|
|
|
{
|
|
|
|
self.temp_data[1] = Raze.SoundEnabled();
|
2022-12-22 08:49:42 +00:00
|
|
|
self.counter = 0;
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 08:25:46 +00:00
|
|
|
let p = Duke.GetViewPlayer();
|
2022-11-20 07:10:15 +00:00
|
|
|
if (self.lotag >= 1000 && self.lotag < 2000)
|
|
|
|
{
|
2022-11-21 08:25:46 +00:00
|
|
|
double dist = (p.actor.pos.XY - self.pos.XY).LengthSquared();
|
2022-12-22 08:49:42 +00:00
|
|
|
if (dist < maxdist * maxdist && self.counter == 0)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
|
|
|
Raze.SetReverb(self.lotag - 1100);
|
2022-12-22 08:49:42 +00:00
|
|
|
self.counter = 1;
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
2022-12-22 08:49:42 +00:00
|
|
|
if (dist >= maxdist * maxdist && self.counter == 1)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
|
|
|
Raze.SetReverb(0);
|
|
|
|
Raze.SetReverbDelay(0);
|
2022-12-22 08:49:42 +00:00
|
|
|
self.counter = 0;
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let sec = self.sector;
|
|
|
|
if (self.lotag < 999 && sec.lotag >= 0 && sec.lotag < ST_9_SLIDING_ST_DOOR && snd_ambience && sec.floorz != sec.ceilingz)
|
|
|
|
{
|
2023-01-15 08:51:21 +00:00
|
|
|
int flags = Duke.GetSoundFlags(Raze.FindSoundByResID(self.lotag));
|
2022-11-20 07:10:15 +00:00
|
|
|
if (flags & Duke.SF_MSFX)
|
|
|
|
{
|
2022-11-21 08:25:46 +00:00
|
|
|
double distance = (p.actor.pos - self.pos).Length();
|
2022-11-20 07:10:15 +00:00
|
|
|
|
2022-12-22 08:49:42 +00:00
|
|
|
if (distance < maxdist && self.counter == 0)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
|
|
|
// Start playing an ambience sound.
|
2022-11-26 08:08:58 +00:00
|
|
|
self.PlayActorSound(Raze.FindSoundByResID(self.lotag), CHAN_AUTO, CHANF_LOOP);
|
2022-12-22 08:49:42 +00:00
|
|
|
self.counter = 1; // AMBIENT_SFX_PLAYING
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
2022-12-22 08:49:42 +00:00
|
|
|
else if (distance >= maxdist && self.counter == 1)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
|
|
|
// Stop playing ambience sound because we're out of its range.
|
|
|
|
self.StopSound(self.lotag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & (Duke.SF_GLOBAL | Duke.SF_DTAG)) == Duke.SF_GLOBAL)
|
|
|
|
{
|
|
|
|
if (self.temp_data[4] > 0) self.temp_data[4]--;
|
2022-11-21 08:25:46 +00:00
|
|
|
else if (sec == p.actor.sector)
|
2022-11-20 07:10:15 +00:00
|
|
|
{
|
2022-11-26 08:08:58 +00:00
|
|
|
Duke.PlaySound(Raze.FindSoundByResID(self.lotag + uint(Duke.global_random()) % uint(self.hitag + 1)));
|
2022-11-20 07:10:15 +00:00
|
|
|
self.temp_data[4] = 26 * 40 + (Duke.global_random() % (26 * 40));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override void OnDestroy()
|
|
|
|
{
|
2022-12-22 08:49:42 +00:00
|
|
|
if (self.counter == 1)
|
2022-12-05 10:27:25 +00:00
|
|
|
self.StopSound(-1);
|
|
|
|
Super.OnDestroy();
|
2022-11-20 07:10:15 +00:00
|
|
|
}
|
|
|
|
}
|