Exemple #1
0
char* CVoiceGroup::GetRandomSoundString()
{
	// Sanity checks...

	if (GetNumSounds() <= 0) return(DNULL);


	// Check if we only have one sound to play...

	if (GetNumSounds() == 1)
	{
		return(GetSoundString(0));
	}


	// Pick a random sound to play...

	int nMax    = GetNumSounds() - 1;
	int iRandom = GetRandom(0, nMax);
	int cSafety = 200;

	while (iRandom == m_iLast && cSafety > 0)
	{
		iRandom = GetRandom(0, nMax);
		cSafety--;
	}

	m_iLast = iRandom;


	// Return with the random sound...

	return(GetSoundString(iRandom));
}
/**
 * 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.
 */
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 */
	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;

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

		callback += file->sound_offset;
	}

	assert(callback < GetNumSounds());
	SndPlayVehicleFx(callback, v);
	return true;
}
bool 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 false;
		sound_id += file->sound_offset;
	}

	assert(sound_id < GetNumSounds());
	SndPlayTileFx(sound_id, tile);
	return true;
}
Exemple #4
0
DBOOL CVoiceGroup::AddSoundString(char* sSound)
{
	// Sanity checks...

	if (!sSound) return(DFALSE);
	if (GetNumSounds() >= VM_MAX_SOUNDS) return(DFALSE);
	if (_mbstrlen(sSound) >= VM_MAX_STRING) return(DFALSE);


	// Add the string...

	_mbscpy((unsigned char*)m_sSounds[m_cSounds], (const unsigned char*)sSound);

	m_cSounds++;


	// All done...

	return(DTRUE);
}