(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
authortron
Fri, 05 Nov 2004 23:12:33 +0000
changeset 337 66647f97e7c0
parent 336 9581e0c581fd
child 338 04ad3e897bf8
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
This includes 2 fixes
-Fix: [1048596] Monorail and Maglev sounds are swapped (r511)
-Add special case to load the jackhammer sound (r478)
The rest are cleanups und enumeration to make merging possible/easier
aircraft_cmd.c
airport_gui.c
bridge_gui.c
disaster_cmd.c
dock_gui.c
economy.c
functions.h
industry_cmd.c
main_gui.c
misc_gui.c
news_gui.c
players.c
rail_cmd.c
rail_gui.c
road_cmd.c
road_gui.c
roadveh_cmd.c
ship_cmd.c
smallmap_gui.c
sound.c
sound.h
terraform_gui.c
train_cmd.c
tree_cmd.c
tunnelbridge_cmd.c
vehicle.c
water_cmd.c
--- a/aircraft_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/aircraft_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -6,6 +6,7 @@
 #include "station.h"
 #include "news.h"
 #include "gfx.h"
+#include "sound.h"
 #include "player.h"
 #include "airport.h"
 
--- a/airport_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/airport_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "gui.h"
 #include "viewport.h"
 #include "gfx.h"
+#include "sound.h"
 #include "command.h"
 #include "vehicle.h"
 #include "station.h"
--- a/bridge_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/bridge_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -6,6 +6,7 @@
 #include "viewport.h"
 #include "gfx.h"
 #include "command.h"
+#include "sound.h"
 
 static struct BridgeData {
 	int count;
--- a/disaster_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/disaster_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,6 +9,7 @@
 #include "industry.h"
 #include "player.h"
 #include "airport_movement.h"
+#include "sound.h"
 
 static void DisasterClearSquare(uint tile)
 {
--- a/dock_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/dock_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "gui.h"
 #include "viewport.h"
 #include "gfx.h"
+#include "sound.h"
 #include "command.h"
 
 static void ShowBuildDockStationPicker();
--- a/economy.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/economy.c	Fri Nov 05 23:12:33 2004 +0000
@@ -12,6 +12,7 @@
 #include "industry.h"
 #include "town.h"
 #include "network.h"
+#include "sound.h"
 
 void UpdatePlayerHouse(Player *p, uint score)
 {
--- a/functions.h	Thu Nov 04 18:41:39 2004 +0000
+++ b/functions.h	Fri Nov 05 23:12:33 2004 +0000
@@ -55,11 +55,6 @@
 int GetParamUint16();
 
 
-/* sound.c */
-void SndPlayTileFx(int sound, TileIndex tile);
-void SndPlayVehicleFx(int sound, Vehicle *v);
-void SndPlayFx(int sound);
-
 /* clear_land.c */
 void DrawHillyLandTile(TileInfo *ti);
 void DrawClearLandTile(TileInfo *ti, byte set);
--- a/industry_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/industry_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -8,6 +8,7 @@
 #include "news.h"
 #include "saveload.h"
 #include "economy.h"
+#include "sound.h"
 
 byte _industry_sound_ctr;
 TileIndex _industry_sound_tile;
--- a/main_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/main_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -11,6 +11,7 @@
 #include "town.h"
 #include "vehicle.h"
 #include "console.h"
+#include "sound.h"
 
 #include "table/animcursors.h"
 
--- a/misc_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/misc_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,6 +9,7 @@
 #include "command.h"
 #include "player.h"
 #include "town.h"
+#include "sound.h"
 
 #include "hal.h" // Fios items
 
--- a/news_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/news_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -7,6 +7,7 @@
 #include "gfx.h"
 #include "news.h"
 #include "vehicle.h"
+#include "sound.h"
 
 /* News system
 News system is realized as a FIFO queue (in an array)
--- a/players.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/players.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,6 +9,7 @@
 #include "saveload.h"
 #include "command.h"
 #include "ai.h"
+#include "sound.h"
 
 extern void StartupEconomy();
 
--- a/rail_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/rail_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "command.h"
 #include "pathfind.h"
 #include "town.h"
+#include "sound.h"
 
 void ShowTrainDepotWindow(uint tile);
 
--- a/rail_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/rail_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "gui.h"
 #include "viewport.h"
 #include "gfx.h"
+#include "sound.h"
 #include "command.h"
 #include "vehicle.h"
 
--- a/road_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/road_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -7,6 +7,7 @@
 #include "town.h"
 #include "gfx.h"
 #include "table/directions.h"
+#include "sound.h"
 
 /* When true, GetTrackStatus for roads will treat roads under reconstruction
  * as normal roads instead of impassable. This is used when detecting whether
--- a/road_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/road_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "gui.h"
 #include "viewport.h"
 #include "gfx.h"
+#include "sound.h"
 #include "command.h"
 
 static void ShowBusStationPicker();
--- a/roadveh_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/roadveh_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -8,6 +8,7 @@
 #include "gfx.h"
 #include "pathfind.h"
 #include "player.h"
+#include "sound.h"
 
 void ShowRoadVehViewWindow(Vehicle *v);
 
--- a/ship_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/ship_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,7 +9,7 @@
 #include "engine.h"
 #include "gui.h"
 #include "player.h"
-
+#include "sound.h"
 
 static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
 static const byte _ship_sometracks[4] = {0x19, 0x16, 0x25, 0x2A};
--- a/smallmap_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/smallmap_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -7,6 +7,7 @@
 #include "player.h"
 #include "vehicle.h"
 #include "town.h"
+#include "sound.h"
 
 static const Widget _smallmap_megabig_widgets[] = {
 {    WWT_TEXTBTN,    13,     0,    10,     0,    13, STR_00C5,		STR_018B_CLOSE_WINDOW},
--- a/sound.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/sound.c	Fri Nov 05 23:12:33 2004 +0000
@@ -6,13 +6,13 @@
 #include "viewport.h"
 #include "fileio.h"
 
-typedef struct {
+typedef struct MixerChannel {
 	// Mixer
 	Mixer *mx;
 	bool active;
 
 	// pointer to allocated buffer memory
-	void *memory;
+	int8 *memory;
 
 	// current position in memory
 	uint32 pos;
@@ -27,14 +27,13 @@
 	uint flags;
 } MixerChannel;
 
-typedef struct FileEntry FileEntry;
-struct FileEntry {
+typedef struct FileEntry {
 	uint32 file_offset;
 	uint32 file_size;
 	uint16 rate;
 	uint8 bits_per_sample;
 	uint8 channels;
-};
+} FileEntry;
 
 struct Mixer {
 	uint32 play_rate;
@@ -53,8 +52,6 @@
 #define SOUND_SLOT 31
 
 
-FILE *out;
-
 static void mix_int8_to_int16(MixerChannel *sc, int16 *buffer, uint samples)
 {
 	int8 *b;
@@ -67,7 +64,7 @@
 	sc->samples_left -= samples;
 	assert(samples > 0);
 
-	b = (int8*)sc->memory + sc->pos;
+	b = sc->memory + sc->pos;
 	frac_pos = sc->frac_pos;
 	frac_speed = sc->frac_speed;
 	volume_left = sc->volume_left;
@@ -76,11 +73,11 @@
 	if (frac_speed == 0x10000) {
 		// Special case when frac_speed is 0x10000
 		do {
-			buffer[0]+= *b * volume_left >> 8;
-			buffer[1]+= *b * volume_right >> 8;
+			buffer[0] += *b * volume_left >> 8;
+			buffer[1] += *b * volume_right >> 8;
 			b++;
 			buffer += 2;
-		} while (--samples);
+		} while (--samples > 0);
 	} else {
 		do {
 			buffer[0] += *b * volume_left >> 8;
@@ -89,52 +86,50 @@
 			frac_pos += frac_speed;
 			b += frac_pos >> 16;
 			frac_pos &= 0xffff;
-		} while (--samples);
+		} while (--samples > 0);
 	}
 
 	sc->frac_pos = frac_pos;
-	sc->pos = b - (int8*)sc->memory;
+	sc->pos = b - sc->memory;
 }
 
 static void MxCloseChannel(MixerChannel *mc)
 {
-	void *mem = mc->memory;
+	if (mc->flags & MX_AUTOFREE) free(mc->memory);
 	mc->memory = NULL;
 	mc->active = false;
-
-	if (mc->flags & MX_AUTOFREE)
-		free(mem);
 }
 
 void MxMixSamples(Mixer *mx, void *buffer, uint samples)
 {
-	int i;
 	MixerChannel *mc;
 
 	// Clear the buffer
-	memset(buffer, 0, sizeof(int16)*2*samples);
+	memset(buffer, 0, sizeof(int16) * 2 * samples);
 
 	// Mix each channel
-	for(i=0,mc=mx->channels; i!=lengthof(mx->channels); i++,mc++) {
+	for (mc = mx->channels; mc != endof(mx->channels); mc++) {
 		if (mc->active) {
-			mix_int8_to_int16(mc, (int16*)buffer, samples);
-			if (mc->samples_left == 0) {
-				MxCloseChannel(mc);
-			}
+			mix_int8_to_int16(mc, buffer, samples);
+			if (mc->samples_left == 0) MxCloseChannel(mc);
 		}
 	}
 
-//	if (out == NULL)
-//		out = fopen("d:\\dump.raw", "wb");
-//	fwrite(buffer, samples*4, 1, out);
+	#if 0
+	{
+		static FILE *out = NULL;
+		if (out == NULL)
+			out = fopen("d:\\dump.raw", "wb");
+		fwrite(buffer, samples * 4, 1, out);
+	}
+	#endif
 }
 
 static MixerChannel *MxAllocateChannel(Mixer *mx)
 {
-	int i;
 	MixerChannel *mc;
-	for(i=0,mc=mx->channels; i!=lengthof(mx->channels); i++,mc++)
-		if (!mc->memory) {
+	for (mc = mx->channels; mc != endof(mx->channels); mc++)
+		if (mc->memory == NULL) {
 			mc->active = false;
 			mc->mx = mx;
 			return mc;
@@ -142,18 +137,20 @@
 	return NULL;
 }
 
-static void MxSetChannelRawSrc(MixerChannel *mc, void *mem, uint size, uint rate, uint flags)
+static void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, uint size, uint rate, uint flags)
 {
 	mc->memory = mem;
 	mc->flags = flags;
 	mc->frac_pos = 0;
 	mc->pos = 0;
 
-	mc->frac_speed = (rate<<16) / mc->mx->play_rate;
+	mc->frac_speed = (rate << 16) / mc->mx->play_rate;
 
 	// adjust the magnitude to prevent overflow
-	while (size & 0xFFFF0000)
-		size >>= 1, rate = (rate >> 1) + 1;
+	while (size & 0xFFFF0000) {
+		size >>= 1;
+		rate = (rate >> 1) + 1;
+	}
 
 	mc->samples_left = size * mc->mx->play_rate / rate;
 }
@@ -176,39 +173,55 @@
 
 	FioSeekTo(0, SEEK_SET);
 
-	for(i=0; i!=count; i++,fe++) {
+	for (i = 0; i != count; i++, fe++) {
 		fe->file_offset = FioReadDword();
 		fe->file_size = FioReadDword();
 	}
 
 	fe = mx->files;
-	for(i=0; i!=count; i++,fe++) {
-		FioSeekTo(fe->file_offset, SEEK_SET);
-		// Skip past string and the name.
-		FioSeekTo(FioReadByte() + 12, SEEK_CUR);
-
-		// Read riff tags
-		while(true) {
-			tag = FioReadDword();
-			size = FioReadDword();
+	for (i = 0; i != count; i++, fe++) {
+		char name[255];
 
-			if (tag == ' tmf') {
-				FioReadWord(); // wFormatTag
-				fe->channels = FioReadWord(); // wChannels
-				FioReadDword(); // samples per second
-				fe->rate = 11025; // seems like all samples should be played at this rate.
-				FioReadDword();						// avg bytes per second
-				FioReadWord();							// alignment
-				fe->bits_per_sample = FioReadByte(); // bits per sample
-				FioSeekTo(size - (2+2+4+4+2+1), SEEK_CUR);
-			} else if (tag == 'atad') {
-				fe->file_size = size;
-				fe->file_offset = FioGetPos() | (SOUND_SLOT << 24);
-				break;
-			} else {
-				fe->file_size = 0;
-				break;
+		FioSeekTo(fe->file_offset, SEEK_SET);
+
+		// Check for special case, see else case
+		FioReadBlock(name, FioReadByte()); // Read the name of the sound
+		if (strcmp(name, "Corrupt sound") != 0) {
+			FioSeekTo(12, SEEK_CUR); // Skip past RIFF header
+
+			// Read riff tags
+			for (;;) {
+				tag = FioReadDword();
+				size = FioReadDword();
+
+				if (tag == ' tmf') {
+					FioReadWord(); // wFormatTag
+					fe->channels = FioReadWord(); // wChannels
+					FioReadDword();   // samples per second
+					fe->rate = 11025; // seems like all samples should be played at this rate.
+					FioReadDword();   // avg bytes per second
+					FioReadWord();    // alignment
+					fe->bits_per_sample = FioReadByte(); // bits per sample
+					FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
+				} else if (tag == 'atad') {
+					fe->file_size = size;
+					fe->file_offset = FioGetPos() | (SOUND_SLOT << 24);
+					break;
+				} else {
+					fe->file_size = 0;
+					break;
+				}
 			}
+		} else {
+			/*
+			 * Special case for the jackhammer sound
+			 * (name in sample.cat is "Corrupt sound")
+			 * It's no RIFF file, but raw PCM data
+			 */
+			fe->channels = 1;
+			fe->rate = 11025;
+			fe->bits_per_sample = 8;
+			fe->file_offset = FioGetPos() | (SOUND_SLOT << 24);
 		}
 	}
 }
@@ -216,19 +229,18 @@
 static bool MxSetBankSource(MixerChannel *mc, uint bank)
 {
 	FileEntry *fe = &mc->mx->files[bank];
-	void *mem;
+	int8 *mem;
 	uint i;
 
 	if (fe->file_size == 0)
 		return false;
 
-	mem = malloc(fe->file_size);
+	mem = malloc(fe->file_size); /* XXX unchecked malloc */
 	FioSeekToFile(fe->file_offset);
 	FioReadBlock(mem, fe->file_size);
 
-	for(i=0; i!=fe->file_size; i++) {
-		((byte*)mem)[i] ^= 0x80;
-	}
+	for (i = 0; i != fe->file_size; i++)
+		mem[i] -= 128; // Convert unsigned sound data to signed
 
 	assert(fe->bits_per_sample == 8 && fe->channels == 1 && fe->file_size != 0 && fe->rate != 0);
 
@@ -289,7 +301,7 @@
 	72,
 };
 
-void SndPlayScreenCoordFx(int sound, int x, int y)
+static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
 {
 	Window *w;
 	ViewPort *vp;
@@ -298,8 +310,8 @@
 	if (msf.effect_vol == 0)
 		return;
 
-	for(w=_windows; w!=_last_window; w++) {
-		if ((vp=w->viewport) &&
+	for (w = _windows; w != _last_window; w++) {
+		if ((vp = w->viewport) != NULL &&
 				IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) &&
 				IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) {
 
@@ -315,23 +327,24 @@
 
 }
 
-void SndPlayTileFx(int sound, TileIndex tile)
+void SndPlayTileFx(SoundFx sound, TileIndex tile)
 {
-	int x = GET_TILE_X(tile)*16;
-	int y = GET_TILE_Y(tile)*16;
-	Point pt = RemapCoords(x,y, GetSlopeZ(x+8, y+8));
+	/* emits sound from center (+ 8) of the tile */
+	int x = GET_TILE_X(tile) * 16 + 8;
+	int y = GET_TILE_Y(tile) * 16 + 8;
+	Point pt = RemapCoords(x, y, GetSlopeZ(x, y));
 	SndPlayScreenCoordFx(sound, pt.x, pt.y);
 }
 
-void SndPlayVehicleFx(int sound, Vehicle *v)
+void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
 {
 	SndPlayScreenCoordFx(sound,
-		(v->left_coord + v->right_coord) >> 1,
-		(v->top_coord + v->bottom_coord) >> 1
+		(v->left_coord + v->right_coord) / 2,
+		(v->top_coord + v->bottom_coord) / 2
 	);
 }
 
-void SndPlayFx(int sound)
+void SndPlayFx(SoundFx sound)
 {
 	StartSound(
 		_sound_idx[sound],
--- a/sound.h	Thu Nov 04 18:41:39 2004 +0000
+++ b/sound.h	Fri Nov 05 23:12:33 2004 +0000
@@ -22,4 +22,84 @@
 bool MxInitialize(uint rate, const char *filename);
 void MxMixSamples(Mixer *mx, void *buffer, uint samples);
 
+typedef enum SoundFx {
+	SND_02_SPLAT,                          //  0 == 0x00 !
+	SND_03_FACTORY_WHISTLE,
+	SND_04_TRAIN,
+	SND_05_TRAIN_THROUGH_TUNNEL,
+	SND_06_SHIP_HORN,
+	SND_07_FERRY_HORN,
+	SND_08_PLANE_TAKE_OFF,
+	SND_09_JET,
+	SND_0A_TRAIN_HORN,
+	SND_0B_MINING_MACHINERY,
+	SND_0C_ELECTRIC_SPARK,
+	SND_0D_STEAM,
+	SND_0E_LEVEL_CROSSING,
+	SND_0F_VEHICLE_BREAKDOWN,
+	SND_10_TRAIN_BREAKDOWN,
+	SND_11_CRASH,
+	SND_12_EXPLOSION,                      // 16 == 0x10
+	SND_13_BIG_CRASH,
+	SND_14_CASHTILL,
+	SND_15_BEEP,                           // 19 == 0x13
+	SND_16_MORSE,                          // 20 == 0x14
+	SND_17_SKID_PLANE,
+	SND_18_HELICOPTER,
+	SND_19_BUS_START_PULL_AWAY,
+	SND_1A_BUS_START_PULL_AWAY_WITH_HORN,
+	SND_1B_TRUCK_START,
+	SND_1C_TRUCK_START_2,
+	SND_1D_APPLAUSE,
+	SND_1E_OOOOH,
+	SND_1F_SPLAT,                          // 29 == 0x1D
+	SND_20_SPLAT_2,                        // 30 == 0x1E
+	SND_21_JACKHAMMER,
+	SND_22_CAR_HORN,
+	SND_23_CAR_HORN_2,
+	SND_24_SHEEP,
+	SND_25_COW,
+	SND_26_HORSE,
+	SND_27_BLACKSMITH_ANVIL,
+	SND_28_SAWMILL,                        // 38 == 0x26 !
+	SND_00_GOOD_YEAR,                      // 39 == 0x27 !
+	SND_01_BAD_YEAR,                       // 40 == 0x28 !
+	SND_29_RIP,                            // 41 == 0x29 !
+	SND_2A_EXTRACT_AND_POP,
+	SND_2B_COMEDY_HIT,
+	SND_2C_MACHINERY,
+	SND_2D_RIP_2,
+	SND_2E_EXTRACT_AND_POP,
+	SND_2F_POP,
+	SND_30_CARTOON_SOUND,
+	SND_31_EXTRACT,
+	SND_32_POP_2,
+	SND_33_PLASTIC_MINE,
+	SND_34_WIND,
+	SND_35_COMEDY_BREAKDOWN,
+	SND_36_CARTOON_CRASH,
+	SND_37_BALLOON_SQUEAK,
+	SND_38_CHAINSAW,
+	SND_39_HEAVY_WIND,
+	SND_3A_COMEDY_BREAKDOWN_2,
+	SND_3B_JET_OVERHEAD,
+	SND_3C_COMEDY_CAR,
+	SND_3D_ANOTHER_JET_OVERHEAD,
+	SND_3E_COMEDY_CAR_2,
+	SND_3F_COMEDY_CAR_3,
+	SND_40_COMEDY_CAR_START_AND_PULL_AWAY,
+	SND_41_MAGLEV,
+	SND_42_LOON_BIRD,
+	SND_43_LION,
+	SND_44_MONKEYS,
+	SND_45_PLANE_CRASHING,
+	SND_46_PLANE_ENGINE_SPUTTERING,
+	SND_47_MAGLEV_2,
+	SND_48_DISTANT_BIRD                    // 72 == 0x48
+} SoundFx;
+
+void SndPlayTileFx(SoundFx sound, TileIndex tile);
+void SndPlayVehicleFx(SoundFx sound, const Vehicle *v);
+void SndPlayFx(SoundFx sound);
+
 #endif /* SOUND_H */
--- a/terraform_gui.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/terraform_gui.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "gui.h"
 #include "viewport.h"
 #include "gfx.h"
+#include "sound.h"
 #include "command.h"
 #include "vehicle.h"
 
--- a/train_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/train_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,7 +9,7 @@
 #include "news.h"
 #include "engine.h"
 #include "player.h"
-
+#include "sound.h"
 
 #define is_firsthead_sprite(spritenum) \
 	(is_custom_sprite(spritenum) \
@@ -1241,9 +1241,15 @@
 	int engtype = v->engine_type;
 
 	switch (_engines[engtype].railtype) {
-		case 0: SndPlayVehicleFx(sfx[_rail_vehicle_info[engtype].engclass], v); break;
-		case 1: SndPlayVehicleFx(0x41, v); break;
-		case 2: SndPlayVehicleFx(0x47, v); break;
+		case 0:
+			SndPlayVehicleFx(sfx[_rail_vehicle_info[engtype].engclass], v);
+			break;
+		case 1:
+			SndPlayVehicleFx(SND_47_MAGLEV_2, v);
+			break;
+		case 2:
+			SndPlayVehicleFx(SND_41_MAGLEV, v);
+			break;
 	}
 }
 
--- a/tree_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/tree_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -3,6 +3,7 @@
 #include "viewport.h"
 #include "command.h"
 #include "town.h"
+#include "sound.h"
 
 static int GetRandomTreeType(uint tile, uint seed)
 {
--- a/tunnelbridge_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/tunnelbridge_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "command.h"
 #include "player.h"
 #include "town.h"
+#include "sound.h"
 
 extern void DrawCanalWater(uint tile);
 
--- a/vehicle.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/vehicle.c	Fri Nov 05 23:12:33 2004 +0000
@@ -9,6 +9,7 @@
 #include "saveload.h"
 #include "player.h"
 #include "engine.h"
+#include "sound.h"
 
 #define INVALID_COORD (-0x8000)
 #define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
--- a/water_cmd.c	Thu Nov 04 18:41:39 2004 +0000
+++ b/water_cmd.c	Fri Nov 05 23:12:33 2004 +0000
@@ -5,6 +5,7 @@
 #include "command.h"
 #include "town.h"
 #include "news.h"
+#include "sound.h"
 
 static void FloodVehicle(Vehicle *v);