http://puu.sh/idzA6/04bc30d0a6.txt
Specifically,
/atom/movable
var/list/audible_sounds = list() //Attached sound datums to this object, both heard and playing.
/sound
var/atom/source = null //Source of the sound.
var/atom/target = null //target of the sound.
var/surround = 1
var/range = SOUND_MAX_DISTANCE //Sound range
/atom/movable/Move() //This function adjusts 3d sound coordinates based on the distance between the player and the sound source.
..()
for(var/sound/S in audible_sounds)
if(get_dist(S.target, S.source) > S.range)
audible_sounds -= S
continue
// 3D sounds, the technology is here!
var/turf/turf_source = get_turf(S.source)
var/turf/T = get_turf(S.target)
if (S.surround)
var/dx = (turf_source.x - T.x) // Hearing from the right/left
S.x = round(max(-SURROUND_CAP, min(SURROUND_CAP, dx)), 1)
var/dz = (turf_source.y - T.y) // Hearing from infront/behind
S.z = round(max(-SURROUND_CAP, min(SURROUND_CAP, dz)), 1)
//This is playing with the player's brain: when the sound plays in front AND above the player, their brain will react accordingly. Since our prespective is top down it helps the emulsions.
S.y = round(S.z / 2) //This effect is extremely subtle, but it does seem to work pretty well.
// src << S //This woulda been fine and dandy but it doesn't UPDATE the sound, it creates a NEW ONE.
world << "SOUND: [S] TRG: [S.target] SRC: [S.source] SX: [S.x] SZ: [S.z] SY: [S.y] CHANNEL: [S.channel]"
Problem description:
Alright, so I can't get 3d sounds to take player's position into account no matter what I do.
What I want to do is check when either the source atom or the target atom has moved for the playing sound, and if they did, adjust the 3d sound's coordinates to make sure a proper "fading" effect is applied.
So, for example, if you open an airlock then walk away from it, instead of the airlock being at consistent volume it'd fade when you walk away.
Save yourself some trouble and don't initialize this list until you need it, and get rid of it once it's empty. It's unlikely that every obj and mob would need this list.
What you need to do to update the sound's position is set SOUND_UPDATE in its flags, and re-send the sound (which now has that flag along with the changed position) to whoever heard it.
Also, I suggest making that list /tmp.