* Load an old fashioned GRF file. * @param filename The name of the file to open. * @param load_index The offset of the first sprite. * @param needs_palette_remap Whether the colours in the GRF file need a palette remap. * @return The number of loaded sprites. */
| 43 | * @return The number of loaded sprites. |
| 44 | */ |
| 45 | static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap) |
| 46 | { |
| 47 | SpriteID load_index_org = load_index; |
| 48 | SpriteID sprite_id = 0; |
| 49 | |
| 50 | SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap); |
| 51 | |
| 52 | Debug(sprite, 2, "Reading grf-file '{}'", filename); |
| 53 | |
| 54 | uint8_t container_ver = file.GetContainerVersion(); |
| 55 | if (container_ver == 0) UserError("Base grf '{}' is corrupt", filename); |
| 56 | ReadGRFSpriteOffsets(file); |
| 57 | if (container_ver >= 2) { |
| 58 | /* Read compression. */ |
| 59 | uint8_t compression = file.ReadByte(); |
| 60 | if (compression != 0) UserError("Unsupported compression format"); |
| 61 | } |
| 62 | |
| 63 | while (LoadNextSprite(load_index, file, sprite_id)) { |
| 64 | load_index++; |
| 65 | sprite_id++; |
| 66 | if (load_index >= MAX_SPRITES) { |
| 67 | UserError("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files."); |
| 68 | } |
| 69 | } |
| 70 | Debug(sprite, 2, "Currently {} sprites are loaded", load_index); |
| 71 | |
| 72 | return load_index - load_index_org; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Load an old fashioned GRF file to replace already loaded sprites. |
no test coverage detected