* Handles the case when a sprite of different type is requested than is present in the SpriteCache. * For SpriteType::Font sprites, it is normal. In other cases, default sprite is loaded instead. * @param sprite ID of loaded sprite * @param requested requested sprite type * @param sc the currently known sprite cache for the requested sprite * @param allocator Callback that provides the memory
| 808 | * @note this function will do UserError() in the case the fallback sprite isn't available |
| 809 | */ |
| 810 | static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, SpriteAllocator *allocator, SpriteEncoder *encoder) |
| 811 | { |
| 812 | static const std::string_view sprite_types[] = { |
| 813 | "normal", // SpriteType::Normal |
| 814 | "map generator", // SpriteType::MapGen |
| 815 | "character", // SpriteType::Font |
| 816 | "recolour", // SpriteType::Recolour |
| 817 | }; |
| 818 | |
| 819 | SpriteType available = sc->type; |
| 820 | if (requested == SpriteType::Font && available == SpriteType::Normal) { |
| 821 | if (sc->ptr == nullptr) sc->type = SpriteType::Font; |
| 822 | return GetRawSprite(sprite, sc->type, allocator, encoder); |
| 823 | } |
| 824 | |
| 825 | uint8_t warning_level = sc->warned ? 6 : 0; |
| 826 | sc->warned = true; |
| 827 | Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[static_cast<uint8_t>(available)], sprite, sprite_types[static_cast<uint8_t>(requested)]); |
| 828 | |
| 829 | switch (requested) { |
| 830 | case SpriteType::Normal: |
| 831 | if (sprite == SPR_IMG_QUERY) UserError("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?"); |
| 832 | [[fallthrough]]; |
| 833 | case SpriteType::Font: |
| 834 | return GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder); |
| 835 | case SpriteType::Recolour: |
| 836 | if (sprite == PALETTE_TO_DARK_BLUE) UserError("Uhm, would you be so kind not to load a NewGRF that makes the 'PALETTE_TO_DARK_BLUE' sprite a non-remap sprite?"); |
| 837 | return GetRawSprite(PALETTE_TO_DARK_BLUE, SpriteType::Recolour, allocator, encoder); |
| 838 | case SpriteType::MapGen: |
| 839 | /* this shouldn't happen, overriding of SpriteType::MapGen sprites is checked in LoadNextSprite() |
| 840 | * (the only case the check fails is when these sprites weren't even loaded...) */ |
| 841 | default: |
| 842 | NOT_REACHED(); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * Reads a sprite (from disk or sprite cache). |
no test coverage detected