2006-09-27 18:17:01 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/** @file newgrf_sound.cpp */
|
|
|
|
|
2006-09-27 18:17:01 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2006-09-27 18:17:01 +00:00
|
|
|
#include "sound.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "newgrf_callbacks.h"
|
|
|
|
#include "newgrf_engine.h"
|
|
|
|
#include "newgrf_sound.h"
|
|
|
|
|
|
|
|
static uint _sound_count = 0;
|
2006-12-03 17:27:43 +00:00
|
|
|
STATIC_OLD_POOL(SoundInternal, FileEntry, 3, 1000, NULL, NULL)
|
2006-09-27 18:17:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Allocate a new FileEntry */
|
2007-03-07 11:47:46 +00:00
|
|
|
FileEntry *AllocateFileEntry()
|
2006-09-27 18:17:01 +00:00
|
|
|
{
|
2006-10-28 11:32:12 +00:00
|
|
|
if (_sound_count == GetSoundInternalPoolSize()) {
|
2007-08-03 20:18:38 +00:00
|
|
|
if (!_SoundInternal_pool.AddBlockToPool()) return NULL;
|
2006-09-27 18:17:01 +00:00
|
|
|
}
|
|
|
|
|
2006-10-28 11:32:12 +00:00
|
|
|
return GetSoundInternal(_sound_count++);
|
2006-09-27 18:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeSoundPool()
|
2006-09-27 18:17:01 +00:00
|
|
|
{
|
2007-08-03 20:18:38 +00:00
|
|
|
_SoundInternal_pool.CleanPool();
|
2006-09-27 18:17:01 +00:00
|
|
|
_sound_count = 0;
|
|
|
|
|
|
|
|
/* Copy original sound data to the pool */
|
|
|
|
SndCopyToPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FileEntry *GetSound(uint index)
|
|
|
|
{
|
2007-02-23 12:56:10 +00:00
|
|
|
if (index >= GetNumSounds()) return NULL;
|
2006-10-28 11:32:12 +00:00
|
|
|
return GetSoundInternal(index);
|
2006-09-27 18:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
uint GetNumSounds()
|
2006-09-27 18:17:01 +00:00
|
|
|
{
|
|
|
|
return _sound_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
|
|
|
|
{
|
|
|
|
const GRFFile *file = GetEngineGRF(v->engine_type);
|
|
|
|
uint16 callback;
|
|
|
|
|
|
|
|
/* If the engine has no GRF ID associated it can't ever play any new sounds */
|
|
|
|
if (file == NULL) return false;
|
|
|
|
|
|
|
|
/* Check that the vehicle type uses the sound effect callback */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_SOUND_EFFECT)) return false;
|
2006-09-27 18:17:01 +00:00
|
|
|
|
|
|
|
callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v);
|
|
|
|
if (callback == CALLBACK_FAILED) return false;
|
|
|
|
if (callback >= GetNumOriginalSounds()) callback += file->sound_offset - GetNumOriginalSounds();
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
if (callback < GetNumSounds()) SndPlayVehicleFx((SoundFx)callback, v);
|
2006-09-27 18:17:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
bool PlayHouseSound(uint16 sound_id, TileIndex tile)
|
|
|
|
{
|
|
|
|
if (sound_id < GetNumOriginalSounds()) {
|
|
|
|
SndPlayTileFx((SoundFx)sound_id, tile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|