OpenTTD Source 20260311-master-g511d3794ce
newgrf_act12.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11#include "../debug.h"
12#include "../fontcache.h"
13#include "../spritecache.h"
14#include "newgrf_bytereader.h"
15#include "newgrf_internal.h"
16
17#include "../safeguards.h"
18
23static void LoadFontGlyph(ByteReader &buf)
24{
25 /* <12> <num_def> <font_size> <num_char> <base_char>
26 *
27 * B num_def Number of definitions
28 * B font_size Size of font (0 = normal, 1 = small, 2 = large, 3 = mono)
29 * B num_char Number of consecutive glyphs
30 * W base_char First character index */
31
32 uint8_t num_def = buf.ReadByte();
33
34 for (uint i = 0; i < num_def; i++) {
35 FontSize size = (FontSize)buf.ReadByte();
36 uint8_t num_char = buf.ReadByte();
37 uint16_t base_char = buf.ReadWord();
38
39 if (size >= FS_END) {
40 GrfMsg(1, "LoadFontGlyph: Size {} is not supported, ignoring", size);
41 }
42
43 GrfMsg(7, "LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
44
45 for (uint c = 0; c < num_char; c++) {
46 if (size < FS_END) SetUnicodeGlyph(size, base_char + c, _cur_gps.spriteid);
47 _cur_gps.nfo_line++;
48 LoadNextSprite(_cur_gps.spriteid++, *_cur_gps.file, _cur_gps.nfo_line);
49 }
50 }
51}
52
57static void SkipAct12(ByteReader &buf)
58{
59 /* <12> <num_def> <font_size> <num_char> <base_char>
60 *
61 * B num_def Number of definitions
62 * B font_size Size of font (0 = normal, 1 = small, 2 = large)
63 * B num_char Number of consecutive glyphs
64 * W base_char First character index */
65
66 uint8_t num_def = buf.ReadByte();
67
68 for (uint i = 0; i < num_def; i++) {
69 /* Ignore 'size' byte */
70 buf.ReadByte();
71
72 /* Sum up number of characters */
73 _cur_gps.skip_sprites += buf.ReadByte();
74
75 /* Ignore 'base_char' word */
76 buf.ReadWord();
77 }
78
79 GrfMsg(3, "SkipAct12: Skipping {} sprites", _cur_gps.skip_sprites);
80}
81
89template <> void GrfActionHandler<0x12>::Init(ByteReader &buf) { SkipAct12(buf); }
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
Functions related to debugging.
Functions to read fonts from files and cache them.
void SetUnicodeGlyph(FontSize size, char32_t key, SpriteID sprite)
Set the SpriteID for a unicode character.
FontSize
Available font sizes.
Definition gfx_type.h:248
static void SkipAct12(ByteReader &buf)
Action 0x12 (SKIP).
static void LoadFontGlyph(ByteReader &buf)
Action 0x12 - Define fonts.
NewGRF buffer reader definition.
NewGRF internal processing state.
A number of safeguards to prevent using unsafe methods.
bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
Functions to cache sprites in memory.
Definition of base types and functions in a cross-platform compatible way.
static void FileScan(ByteReader &buf)
Implementation of the GrfLoadingStage::FileScan stage of this action.
static void SafetyScan(ByteReader &buf)
Implementation of the GrfLoadingStage::SafetyScan stage of this action.
static void Reserve(ByteReader &buf)
Implementation of the GrfLoadingStage::Reserve stage of this action.
static void Activation(ByteReader &buf)
Implementation of the GrfLoadingStage::Activation stage of this action.
static void Init(ByteReader &buf)
Implementation of the GrfLoadingStage::Init stage of this action.
static void LabelScan(ByteReader &buf)
Implementation of the GrfLoadingStage::LabelScan stage of this action.