(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.

pull/155/head
rubidium 16 years ago
parent 23c0017272
commit 5a17e6b395

@ -430,7 +430,7 @@ void AnimateNewHouseTile(TileIndex tile)
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback_res, 8, 7) != 0) PlayHouseSound(GB(callback_res, 8, 7), tile);
if (GB(callback_res, 8, 7) != 0) PlayTileSound(hs->grffile, GB(callback_res, 8, 7), tile);
}
}
@ -450,7 +450,7 @@ void AnimateNewHouseTile(TileIndex tile)
MarkTileDirtyByTile(tile);
}
void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result)
void ChangeHouseAnimationFrame(const GRFFile *file, TileIndex tile, uint16 callback_result)
{
switch (callback_result & 0xFF) {
case 0xFD: /* Do nothing. */ break;
@ -463,7 +463,7 @@ void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result)
}
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback_result, 8, 7) != 0) PlayHouseSound(GB(callback_result, 8, 7), tile);
if (GB(callback_result, 8, 7) != 0) PlayTileSound(file, GB(callback_result, 8, 7), tile);
}
bool CanDeleteHouse(TileIndex tile)
@ -491,7 +491,7 @@ static void AnimationControl(TileIndex tile, uint16 random_bits)
uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
}
}

@ -36,7 +36,7 @@ void DecreaseBuildingCount(Town *t, HouseID house_id);
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
void AnimateNewHouseTile(TileIndex tile);
void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result);
void ChangeHouseAnimationFrame(const struct GRFFile *file, TileIndex tile, uint16 callback_result);
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);

@ -15,6 +15,7 @@
#include "newgrf_callbacks.h"
#include "newgrf_industries.h"
#include "newgrf_industrytiles.h"
#include "newgrf_sound.h"
#include "newgrf_text.h"
#include "industry_map.h"
#include "clear_map.h"
@ -337,6 +338,10 @@ void AnimateNewIndustryTile(TileIndex tile)
frame = callback_res & 0xFF;
break;
}
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile);
}
}
@ -356,7 +361,7 @@ void AnimateNewIndustryTile(TileIndex tile)
MarkTileDirtyByTile(tile);
}
static void ChangeIndustryTileAnimationFrame(TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind)
static void ChangeIndustryTileAnimationFrame(const IndustryTileSpec *itspec, TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind)
{
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile);
if (callback_res == CALLBACK_FAILED) return;
@ -370,6 +375,10 @@ static void ChangeIndustryTileAnimationFrame(TileIndex tile, IndustryAnimationTr
AddAnimatedTile(tile);
break;
}
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile);
}
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random)
@ -380,7 +389,7 @@ bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat
if (!HasBit(itspec->animation_triggers, iat)) return false;
Industry *ind = GetIndustryByTile(tile);
ChangeIndustryTileAnimationFrame(tile, iat, random, gfx, ind);
ChangeIndustryTileAnimationFrame(itspec, tile, iat, random, gfx, ind);
return true;
}

@ -69,9 +69,11 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
return true;
}
bool PlayHouseSound(uint16 sound_id, TileIndex tile)
bool PlayTileSound(const GRFFile *file, uint16 sound_id, TileIndex tile)
{
if (sound_id < GetNumOriginalSounds()) {
if (sound_id >= GetNumOriginalSounds()) sound_id += file->sound_offset - GetNumOriginalSounds();
if (sound_id < GetNumSounds()) {
SndPlayTileFx((SoundFx)sound_id, tile);
return true;
}

@ -26,6 +26,6 @@ void InitializeSoundPool();
FileEntry *GetSound(uint index);
uint GetNumSounds();
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event);
bool PlayHouseSound(uint16 sound_id, TileIndex tile);
bool PlayTileSound(const struct GRFFile *file, uint16 sound_id, TileIndex tile);
#endif /* NEWGRF_SOUND_H */

@ -16,6 +16,7 @@
#include "newgrf_commons.h"
#include "newgrf_station.h"
#include "newgrf_spritegroup.h"
#include "newgrf_sound.h"
#include "cargotype.h"
#include "town_map.h"
#include "newgrf_town.h"
@ -901,6 +902,10 @@ void AnimateStationTile(TileIndex tile)
frame = callback & 0xFF;
break;
}
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
}
}
@ -935,6 +940,10 @@ static void ChangeStationAnimationFrame(const StationSpec *ss, const Station *st
AddAnimatedTile(tile);
break;
}
/* If the lower 7 bits of the upper byte of the callback
* result are not empty, it is a sound effect. */
if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
}
enum TriggerArea {

@ -381,16 +381,18 @@ static void MakeSingleHouseBigger(TileIndex tile)
IncHouseConstructionTick(tile);
if (GetHouseConstructionTick(tile) != 0) return;
const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
/* Check and/or */
if (HasBit(GetHouseSpecs(GetHouseType(tile))->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) {
if (HasBit(hs->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) {
uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
}
if (IsHouseCompleted(tile)) {
/* Now that construction is complete, we can add the population of the
* building to the town. */
ChangePopulation(GetTownByTile(tile), GetHouseSpecs(GetHouseType(tile))->population);
ChangePopulation(GetTownByTile(tile), hs->population);
SetHouseConstructionYear(tile, _cur_year);
}
MarkTileDirtyByTile(tile);

Loading…
Cancel
Save