QuakeC from Scratch tutorials - Chapter 3: And all was quiet...
Created By: | Ender |
eMail: | ender@admdev.com |
Difficulty Scale: | Hard |
/* +-------+ |Ambient| +-------+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+ | Scratch Http://www.admdev.com/scratch | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Spawns and handles the 'Ambient' (background) sound effects for Quake. | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ */Once again as in the previous tutorial, we will remove the spawn functions for the Ambient sound entities from dummys.qc, as we are about to redeclare these in out new Ambient.qc file.
// Ambients void() ambient_suck_wind = {remove(self);}; void() ambient_flouro_buzz = {remove(self);}; void() ambient_drip = {remove(self);}; void() ambient_comp_hum = {remove(self);}; void() ambient_drone = {remove(self);}; void() ambient_thunder = {remove(self);}; void() ambient_light_buzz = {remove(self);}; void() ambient_swamp1 = {remove(self);}; void() ambient_swamp2 = {remove(self);};In Ambient.qc, we will improve on some of the 'wasted' code ID used in the standard QC. In the normal Quake 1.06 QuakeC, the ambient sounds all use the same lines:
void() ambient_suck_wind = { precache_sound ("ambience/suck1.wav"); ambientsound (self.origin, "ambience/suck1.wav", 1, ATTN_STATIC); };However, our ambient.qc file should look like this:
void(string soundfile, float volume) doambient; // Definition from Ambient.qc void() ambient_suck_wind = {doambient("ambience/suck1.wav", 1);}; void() ambient_flouro_buzz = {doambient("ambience/buzz1.wav", 1);}; void() ambient_drip = {doambient("ambience/drip1.wav", 1);}; void() ambient_comp_hum = {doambient("ambience/comp1.wav", 1);}; void() ambient_drone = {doambient("ambience/drone6.wav", 0.5);}; void() ambient_thunder = {doambient("ambience/thunder1.wav", 0.5);}; void() ambient_light_buzz = {doambient("ambience/fl_hum1.wav", 0.5);}; void() ambient_swamp1 = {doambient("ambience/swamp1.wav", 0.5);}; void() ambient_swamp2 = {doambient("ambience/swamp2.wav", 0.5);}; void(string soundfile, float volume) doambient = { precache_sound (soundfile); ambientsound (self.origin, soundfile, volume, ATTN_STATIC); };As you can see, we have put those two lines into a function, and instead call that function for all the sounds. A bit pointless? Perhaps, but it saves just those few bytes of the size of progs.dat :)
void(string soundfile, float volume) doambient; // Definition from Ambient.qcThe comments in my original code for Lights.QC should help you locate the lights that have Ambient noises with them.
void() light_fluoro = // Light with hum ambientAt the end of this function (eg, after Light_setup) add the line:
doambient("ambience/fl_hum1.wav", 0.5); // Spawn Ambient hum soundLikewise for light_fluorospark add:
doambient("ambience/buzz1.wav", 0.5); // Spawn ambient buzz soundlight_torch_small_walltorch:
doambient("ambience/fire1.wav", 0.5); // Spawn fire ambient soundlight_flame_small_yellow:
doambient("ambience/fire1.wav", 0.5); // Spawn fire ambient soundlight_flame_large_yellow:
doambient("ambience/fire1.wav", 0.5); // Spawn fire ambient soundAnd finally, light_flame_small_white:
doambient("ambience/fire1.wav", 0.5); // Spawn fire ambient sound