2801 _grf_data_type = GDT_SOUND; |
2801 _grf_data_type = GDT_SOUND; |
2802 |
2802 |
2803 if (_cur_grffile->sound_offset == 0) _cur_grffile->sound_offset = GetNumSounds(); |
2803 if (_cur_grffile->sound_offset == 0) _cur_grffile->sound_offset = GetNumSounds(); |
2804 } |
2804 } |
2805 |
2805 |
|
2806 static void ImportGRFSound(byte *buf, int len) |
|
2807 { |
|
2808 const GRFFile *file; |
|
2809 FileEntry *se = AllocateFileEntry(); |
|
2810 uint32 grfid = grf_load_dword(&buf); |
|
2811 uint16 sound = grf_load_word(&buf); |
|
2812 |
|
2813 file = GetFileByGRFID(grfid); |
|
2814 if (file == NULL || file->sound_offset == 0) { |
|
2815 grfmsg(GMS_WARN, "ImportGRFSound: Source file not available."); |
|
2816 return; |
|
2817 } |
|
2818 |
|
2819 if (file->sound_offset + sound >= GetNumSounds()) { |
|
2820 grfmsg(GMS_WARN, "ImportGRFSound: Sound effect %d is invalid.", sound); |
|
2821 return; |
|
2822 } |
|
2823 |
|
2824 grfmsg(GMS_NOTICE, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid); |
|
2825 |
|
2826 memcpy(se, GetSound(file->sound_offset + sound), sizeof(*se)); |
|
2827 |
|
2828 /* Reset volume and priority, which TTDPatch doesn't copy */ |
|
2829 se->volume = 128; |
|
2830 se->priority = 0; |
|
2831 } |
|
2832 |
|
2833 /* 'Action 0xFE' */ |
|
2834 static void GRFImportBlock(byte *buf, int len) |
|
2835 { |
|
2836 if (_grf_data_blocks == 0) { |
|
2837 grfmsg(GMS_WARN, "GRFImportBlock: Unexpected import block, skipping."); |
|
2838 return; |
|
2839 } |
|
2840 |
|
2841 buf++; |
|
2842 |
|
2843 _grf_data_blocks--; |
|
2844 |
|
2845 /* XXX 'Action 0xFE' isn't really specified. It is only mentioned for |
|
2846 * importing sounds, so this is probably all wrong... */ |
|
2847 if (grf_load_byte(&buf) != _grf_data_type) { |
|
2848 grfmsg(GMS_WARN, "GRFImportBlock: Import type mismatch."); |
|
2849 } |
|
2850 |
|
2851 switch (_grf_data_type) { |
|
2852 case GDT_SOUND: ImportGRFSound(buf, len - 1); break; |
|
2853 default: NOT_REACHED(); break; |
|
2854 } |
|
2855 } |
|
2856 |
2806 static void LoadGRFSound(byte *buf, int len) |
2857 static void LoadGRFSound(byte *buf, int len) |
2807 { |
2858 { |
2808 byte *buf_start = buf; |
2859 byte *buf_start = buf; |
2809 FileEntry *se; |
2860 FileEntry *se; |
2810 |
2861 |
3216 action = buf[0]; |
3267 action = buf[0]; |
3217 |
3268 |
3218 if (action == 0xFF) { |
3269 if (action == 0xFF) { |
3219 DEBUG(grf, 7) ("Handling data block in stage %d", stage); |
3270 DEBUG(grf, 7) ("Handling data block in stage %d", stage); |
3220 GRFDataBlock(buf, num); |
3271 GRFDataBlock(buf, num); |
|
3272 } else if (action == 0xFE) { |
|
3273 DEBUG(grf, 7) ("Handling import block in stage %d", stage); |
|
3274 GRFImportBlock(buf, num); |
3221 } else if (action >= lengthof(handlers)) { |
3275 } else if (action >= lengthof(handlers)) { |
3222 DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action); |
3276 DEBUG(grf, 7) ("Skipping unknown action 0x%02X", action); |
3223 } else if (!HASBIT(action_mask[stage], action)) { |
3277 } else if (!HASBIT(action_mask[stage], action)) { |
3224 DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage); |
3278 DEBUG(grf, 7) ("Skipping action 0x%02X in stage %d", action, stage); |
3225 } else if (handlers[action] == NULL) { |
3279 } else if (handlers[action] == NULL) { |