Sound plays an important role in Cogmind, perhaps setting it apart from a majority of ASCII roguelikes. While sound will likely have little or no direct influence on the gameplay mechanics themselves, it still adds an important dimension to the experience since immersion is the primary focus of the game's design. (Remember, you are the Cogmind!)
There are of course sound effects related to major actions like shooting, as well as other spot sounds like projectile impacts, explosions, terrain destruction, door operation etc., but those don't do as much for the atmosphere as ambient sound.
Each map will feature some amount of global ambiance that reflects your location, be it the factory levels or somewhere deep in the caves. In addition to that we now have a complete system for sourced ambient sounds. These are the sounds that originate from specific props in the environment, like machines. Since we aren't doing videos yet, the only way you can check out the sound is by looking at it =p
In debug mode looking at the sound emitted by randomly placed test machines all playing one of two test ambient sounds.
Brighter orange represents a higher volume. You'll see that line of sight is not necessary to hear an object--sound properly turns corners. Each piece of terrain also has its own sound dampening properties, so in this example thick earth walls are blocking all sound while doors muffle sound by 50%, allowing the remainder to continue to propagate.
Similarly, action-related sounds (projectiles, explosions, etc.) all have distance-based volume as the sound takes the least muffled route to the player.
Sourced ambient sound propagation is not static, either, changing as the environment around it changes. This is absolutely essential since the environment is completely destructible and dynamic, not to mention simply opening a door will increase the perceived volume of whatever was behind it.
Ambient sound changing as a door is opened or wall destroyed.
Destroying a source itself will of course eliminate that sound completely.
The examples above only show how one particular sound travels as its volume drops (a plateau for distance 0-2, then drops off along an inverse curve up to a range of 8 spaces), while in practice different sounds will have different maximum ranges and types of falloff, depending on what's appropriate for the given sound.
Much of the sound system was copied over from X@COM, but some alterations were necessary due to the different game mechanics.
In X@COM, ambient sounds are heard differently by each member of the squad depending on their location, thus as you cycle through your units you hear whatever the selected unit does. This and the fact that maps were small meant that the best solution was to precalculate all sounds heard across the entire map, and update that only as necessary when ambient sound sources were added or removed.
In Cogmind this method no longer works because 1) maps are going to be much larger and 2) terrain can dampen sound (this effect does not exist in X@COM), which would require too many recalculations every time a door changes state or terrain is created or destroyed. So ambient sound in Cogmind is actually calculated on the fly, where every possibly sound-affecting change to the environment triggers an adjustment to whatever sounds you can hear.
Rather than the usual Dijkstra method used to find all areas within audible distance of a sound (as in the debugging images seen above), each nearby sound source pathfinds to the player via A* (w/heuristics) to determine its volume (or perhaps it can't be heard at all). This is fairly fast, thus one advantage of having a single actor is we can now properly implement sound dampening!
There are four different types of falloff supported for sound effects (graphs are drawn approximations, not rendered by actual graphing software):
Linear. Good for sounds heard over a large area, to make it easier for the listener to gauge distance from the source.
Logarithmic. Good for continuous complex environmental sounds like wind through trees.
Reverse Log. Loud sounds like the core of an explosion or gunfire.
Inverse. For sounds heard clearly up close, but at any distance beyond that only give a hint that they're nearby. Works well for terminals and machines with softer sounds.
I tend to use linear falloff for most non-looping event sounds so the volume holds more meaningful information for the player in terms of relative distance, and rely on log and inverse falloff as necessary for looping ambient samples to make them sound realistic as you approach/leave them. Believe it or not, it's not only 3D games in which there's a noticeable distinction--it even matters when exploring a grid-based 2D world!
Two other important parameters set for each sound are the min and max radius. Max radius is obvious--beyond that the sound is not heard at all; min radius defines the area within which the sound is heard at full volume, i.e. before falloff starts to take effect. When graphed this creates a plateau near the source:
Logarithmic falloff w/min radius plateau.
The sample sound seen in the debug shots further above uses a min radius of 2, hence the bright areas surrounding the sources.