12#include "../newgrf_house.h"
13#include "../newgrf_sound.h"
14#include "../spritecache.h"
18#include "../safeguards.h"
31 if (file ==
nullptr || file->sound_offset == 0) {
32 GrfMsg(1,
"ImportGRFSound: Source file not available");
36 if (sound_id >= file->num_sounds) {
37 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
41 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
43 *sound = *GetSound(file->sound_offset + sound_id);
46 sound->volume = SOUND_EFFECT_MAX_VOLUME;
58 sound->volume = SOUND_EFFECT_MAX_VOLUME;
61 if (offs != SIZE_MAX) {
63 sound->file = _cur.
file;
64 sound->file_offset = offs;
65 sound->source = SoundSource::NewGRF;
81 if (_cur.
grffile->sound_offset == 0) {
82 _cur.
grffile->sound_offset = GetNumSounds();
86 sound = GetSound(_cur.
grffile->sound_offset);
91 for (
int i = 0; i < num; i++) {
96 bool invalid = i >= _cur.
grffile->num_sounds;
98 size_t offs = file.
GetPos();
103 if (grf_container_version >= 2 && type == 0xFD) {
106 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
108 }
else if (len != 4) {
109 GrfMsg(1,
"GRFSound: Invalid sprite section import");
119 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
126 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
134 if (_cur.
stage == GLS_INIT) {
135 if (grf_container_version >= 2) {
136 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
145 if (_cur.
stage == GLS_ACTIVATION) {
148 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
156 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
172 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
size_t GetPos() const
Get position in the file.
uint8_t ReadByte()
Read a byte from the file.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
void SkipBytes(size_t n)
Skip n bytes ahead in the file.
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
RandomAccessFile with some extra information specific for sprite files.
uint8_t GetContainerVersion() const
Get the version number of container type used by the file.
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
GRFFile * GetFileByGRFID(uint32_t grfid)
Obtain a NewGRF file by its grfID.
static void LoadGRFSound(size_t offs, SoundEntry *sound)
Load a sound from a file.
static void ImportGRFSound(SoundEntry *sound)
Process a sound import from another GRF file.
NewGRF buffer reader definition.
NewGRF internal processing state.
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
size_t GetGRFSpriteOffset(uint32_t id)
Get the file offset for a specific sprite in the sprite section of a GRF.
bool SkipSpriteData(SpriteFile &file, uint8_t type, uint16_t num)
Skip the given amount of sprite graphics data.
Dynamic data of a loaded NewGRF.
SpriteFile * file
File of currently processed GRF file.
GRFFile * grffile
Currently processed GRF file.
uint32_t nfo_line
Currently processed pseudo sprite number in the GRF.
GrfLoadingStage stage
Current loading stage.
int skip_sprites
Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file)
uint8_t grf_container_ver
NewGRF container version if the sound is from a NewGRF.