Mercurial > hg > openttd
changeset 4818:d1176489b31f draft
(svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Thu, 12 Oct 2006 07:42:37 +0000 |
parents | e2984d603b59 |
children | f78414f9cadf |
files | newgrf.c |
diffstat | 1 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/newgrf.c +++ b/newgrf.c @@ -2803,6 +2803,57 @@ if (_cur_grffile->sound_offset == 0) _cur_grffile->sound_offset = GetNumSounds(); } +static void ImportGRFSound(byte *buf, int len) +{ + const GRFFile *file; + FileEntry *se = AllocateFileEntry(); + uint32 grfid = grf_load_dword(&buf); + uint16 sound = grf_load_word(&buf); + + file = GetFileByGRFID(grfid); + if (file == NULL || file->sound_offset == 0) { + grfmsg(GMS_WARN, "ImportGRFSound: Source file not available."); + return; + } + + if (file->sound_offset + sound >= GetNumSounds()) { + grfmsg(GMS_WARN, "ImportGRFSound: Sound effect %d is invalid.", sound); + return; + } + + grfmsg(GMS_NOTICE, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid); + + memcpy(se, GetSound(file->sound_offset + sound), sizeof(*se)); + + /* Reset volume and priority, which TTDPatch doesn't copy */ + se->volume = 128; + se->priority = 0; +} + +/* 'Action 0xFE' */ +static void GRFImportBlock(byte *buf, int len) +{ + if (_grf_data_blocks == 0) { + grfmsg(GMS_WARN, "GRFImportBlock: Unexpected import block, skipping."); + return; + } + + buf++; + + _grf_data_blocks--; + + /* XXX 'Action 0xFE' isn't really specified. It is only mentioned for + * importing sounds, so this is probably all wrong... */ + if (grf_load_byte(&buf) != _grf_data_type) { + grfmsg(GMS_WARN, "GRFImportBlock: Import type mismatch."); + } + + switch (_grf_data_type) { + case GDT_SOUND: ImportGRFSound(buf, len - 1); break; + default: NOT_REACHED(); break; + } +} + static void LoadGRFSound(byte *buf, int len) { byte *buf_start = buf; @@ -3218,6 +3269,9 @@ if (action == 0xFF) { DEBUG(grf, 7) ("Handling data block in stage %d", stage); GRFDataBlock(buf, num); + } else if (action == 0xFE) { + DEBUG(grf, 7) ("Handling import block in stage %d", stage); + GRFImportBlock(buf, num); } else if (action >= lengthof(handlers)) { DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action); } else if (!HASBIT(action_mask[stage], action)) {