Changeset - r22317:3ed40f22eff9
[Not reviewed]
master
0 4 0
frosch - 9 years ago 2016-02-08 21:05:57
frosch@openttd.org
(svn r27507) -Add: [NewGRF] Allow custom sound IDs in RV property 0x12, ship property 0x10 and aircraft property 0x12.
4 files changed with 27 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -1399,13 +1399,13 @@ static ChangeInfoResult RoadVehicleChang
 

	
 
			case PROP_ROADVEH_COST_FACTOR: // 0x11 Cost factor
 
				rvi->cost_factor = buf->ReadByte();
 
				break;
 

	
 
			case 0x12: // SFX
 
				rvi->sfx = buf->ReadByte();
 
				rvi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
 
				break;
 

	
 
			case PROP_ROADVEH_POWER: // Power in units of 10 HP.
 
				rvi->power = buf->ReadByte();
 
				break;
 

	
 
@@ -1587,13 +1587,13 @@ static ChangeInfoResult ShipVehicleChang
 

	
 
			case PROP_SHIP_RUNNING_COST_FACTOR: // 0x0F Running cost factor
 
				svi->running_cost = buf->ReadByte();
 
				break;
 

	
 
			case 0x10: // SFX
 
				svi->sfx = buf->ReadByte();
 
				svi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
 
				break;
 

	
 
			case 0x11: { // Cargoes available for refitting
 
				uint32 mask = buf->ReadDWord();
 
				_gted[e->index].UpdateRefittability(mask != 0);
 
				ei->refit_mask = TranslateRefitMask(mask);
 
@@ -1755,13 +1755,13 @@ static ChangeInfoResult AircraftVehicleC
 

	
 
			case PROP_AIRCRAFT_MAIL_CAPACITY: // 0x11 Mail capacity
 
				avi->mail_capacity = buf->ReadByte();
 
				break;
 

	
 
			case 0x12: // SFX
 
				avi->sfx = buf->ReadByte();
 
				avi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
 
				break;
 

	
 
			case 0x13: { // Cargoes available for refitting
 
				uint32 mask = buf->ReadDWord();
 
				_gted[e->index].UpdateRefittability(mask != 0);
 
				ei->refit_mask = TranslateRefitMask(mask);
src/newgrf_sound.cpp
Show inline comments
 
@@ -158,12 +158,28 @@ bool LoadNewGRFSound(SoundEntry *sound)
 

	
 
	/* Clear everything that was read */
 
	MemSetT(sound, 0);
 
	return false;
 
}
 

	
 
/**
 
 * Resolve NewGRF sound ID.
 
 * @param file NewGRF to get sound from.
 
 * @param sound_id GRF-specific sound ID. (GRF-local for IDs above ORIGINAL_SAMPLE_COUNT)
 
 * @return Translated (global) sound ID, or INVALID_SOUND.
 
 */
 
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
 
{
 
	/* Global sound? */
 
	if (sound_id < ORIGINAL_SAMPLE_COUNT) return sound_id;
 

	
 
	sound_id -= ORIGINAL_SAMPLE_COUNT;
 
	if (file == NULL || sound_id >= file->num_sounds) return INVALID_SOUND;
 

	
 
	return file->sound_offset  + sound_id;
 
}
 

	
 
/**
 
 * Checks whether a NewGRF wants to play a different vehicle sound effect.
 
 * @param v Vehicle to play sound effect for.
 
 * @param event Trigger for the sound effect.
 
 * @return false if the default sound effect shall be played instead.
 
@@ -182,20 +198,16 @@ bool PlayVehicleSound(const Vehicle *v, 
 
	if (!HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_SOUND_EFFECT)) return false;
 

	
 
	callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v);
 
	/* Play default sound if callback fails */
 
	if (callback == CALLBACK_FAILED) return false;
 

	
 
	if (callback >= ORIGINAL_SAMPLE_COUNT) {
 
		callback -= ORIGINAL_SAMPLE_COUNT;
 
	callback = GetNewGRFSoundID(file, callback);
 

	
 
		/* Play no sound if result is out of range */
 
		if (callback > file->num_sounds) return true;
 

	
 
		callback += file->sound_offset;
 
	}
 
	/* Play no sound, if result is invalid */
 
	if (callback == INVALID_SOUND) return true;
 

	
 
	assert(callback < GetNumSounds());
 
	SndPlayVehicleFx(callback, v);
 
	return true;
 
}
 

	
 
@@ -204,15 +216,12 @@ bool PlayVehicleSound(const Vehicle *v, 
 
 * @param file NewGRF triggering the sound effect.
 
 * @param sound_id Sound effect the NewGRF wants to play.
 
 * @param tile Location of the effect.
 
 */
 
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
 
{
 
	if (sound_id >= ORIGINAL_SAMPLE_COUNT) {
 
		sound_id -= ORIGINAL_SAMPLE_COUNT;
 
		if (sound_id > file->num_sounds) return;
 
		sound_id += file->sound_offset;
 
	}
 
	sound_id = GetNewGRFSoundID(file, sound_id);
 
	if (sound_id == INVALID_SOUND) return;
 

	
 
	assert(sound_id < GetNumSounds());
 
	SndPlayTileFx(sound_id, tile);
 
}
src/newgrf_sound.h
Show inline comments
 
@@ -30,12 +30,13 @@ enum VehicleSoundEvent {
 
};
 

	
 

	
 
SoundEntry *AllocateSound(uint num);
 
void InitializeSoundPool();
 
bool LoadNewGRFSound(SoundEntry *sound);
 
SoundID GetNewGRFSoundID(const struct GRFFile *file, SoundID sound_id);
 
SoundEntry *GetSound(SoundID sound_id);
 
uint GetNumSounds();
 
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event);
 
void PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);
 

	
 
#endif /* NEWGRF_SOUND_H */
src/sound_type.h
Show inline comments
 
@@ -116,7 +116,9 @@ enum SoundFx {
 

	
 
/** The number of sounds in the original sample.cat */
 
static const uint ORIGINAL_SAMPLE_COUNT = 73;
 

	
 
typedef uint16 SoundID;
 

	
 
static const SoundID INVALID_SOUND = 0xFFFF;
 

	
 
#endif /* SOUND_TYPE_H */
0 comments (0 inline, 0 general)