diff options
author | rubidium <rubidium@openttd.org> | 2008-04-21 11:29:01 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-21 11:29:01 +0000 |
commit | a40bba8bace426b961d31f5b0362629044c0766e (patch) | |
tree | 05dfb2564e3487afc402523c5fbe4b764fc97d54 | |
parent | 2a779a5e100be9133e21b5645d90d0d390af9ecd (diff) | |
download | openttd-a40bba8bace426b961d31f5b0362629044c0766e.tar.xz |
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
-rw-r--r-- | src/newgrf_house.cpp | 8 | ||||
-rw-r--r-- | src/newgrf_house.h | 2 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 13 | ||||
-rw-r--r-- | src/newgrf_sound.cpp | 6 | ||||
-rw-r--r-- | src/newgrf_sound.h | 2 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 9 | ||||
-rw-r--r-- | src/town_cmd.cpp | 8 |
7 files changed, 35 insertions, 13 deletions
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index b64537bea..15db58ffd 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -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); } } diff --git a/src/newgrf_house.h b/src/newgrf_house.h index a74906aad..089f771fc 100644 --- a/src/newgrf_house.h +++ b/src/newgrf_house.h @@ -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); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 418539e8f..79bbf72eb 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -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; } diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp index 6c017b377..adafd8d90 100644 --- a/src/newgrf_sound.cpp +++ b/src/newgrf_sound.cpp @@ -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; } diff --git a/src/newgrf_sound.h b/src/newgrf_sound.h index 608c7c659..794cee77f 100644 --- a/src/newgrf_sound.h +++ b/src/newgrf_sound.h @@ -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 */ diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index aa81743bf..edb49515f 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -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 { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 45de37aeb..b40f41166 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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); |