13#include "../newgrf_cargo.h"
14#include "../newgrf_house.h"
19#include "table/strings.h"
21#include "../safeguards.h"
68 for (uint j = 0; j < 4; j++) buf.
ReadByte();
73 for (uint8_t j = 0; j < count; j++) buf.
ReadByte();
101 GrfMsg(1,
"TownHouseChangeInfo: Too many houses loaded ({}), max ({}). Ignoring.", last,
NUM_HOUSES_PER_GRF);
106 if (_cur_gps.
grffile->housespec.size() < last) _cur_gps.
grffile->housespec.resize(last);
108 for (uint
id = first;
id < last; ++id) {
109 auto &housespec = _cur_gps.
grffile->housespec[id];
111 if (prop != 0x08 && housespec ==
nullptr) {
114 if (cir > ret) ret = cir;
121 if (subs_id == 0xFF) {
128 GrfMsg(2,
"TownHouseChangeInfo: Attempt to use new house {} as substitute house for {}. Ignoring.", subs_id,
id);
133 if (housespec ==
nullptr) {
135 housespec = std::make_unique<HouseSpec>(*
HouseSpec::Get(subs_id));
137 housespec->enabled =
true;
138 housespec->grf_prop.local_id = id;
139 housespec->grf_prop.subst_id = subs_id;
140 housespec->grf_prop.SetGRFFile(_cur_gps.
grffile);
142 housespec->random_colour[0] = COLOUR_RED;
143 housespec->random_colour[1] = COLOUR_BLUE;
144 housespec->random_colour[2] = COLOUR_ORANGE;
145 housespec->random_colour[3] = COLOUR_GREEN;
148 housespec->building_flags.Reset({BuildingFlag::IsChurch, BuildingFlag::IsStadium});
154 CargoType cargo_type = housespec->accepts_cargo[2];
155 if (!
IsValidCargoType(cargo_type)) cargo_type = GetCargoTypeByLabel(housespec->accepts_cargo_label[2]);
157 housespec->cargo_acceptance[2] = 0;
175 housespec->population = buf.
ReadByte();
179 housespec->mail_generation = buf.
ReadByte();
184 housespec->cargo_acceptance[prop - 0x0D] = buf.
ReadByte();
198 housespec->accepts_cargo[2] = cargo_type;
199 housespec->accepts_cargo_label[2] =
CT_INVALID;
200 housespec->cargo_acceptance[2] =
abs(goods);
205 housespec->remove_rating_decrease = buf.
ReadWord();
209 housespec->removal_cost = buf.
ReadByte();
221 auto mask = housespec->callback_mask.base();
228 uint8_t override_id = buf.
ReadByte();
232 GrfMsg(2,
"TownHouseChangeInfo: Attempt to override new house {} with house id {}. Ignoring.", override_id,
id);
236 _house_mngr.
Add(
id, _cur_gps.
grffile->grfid, override_id);
241 housespec->processing_time = std::min<uint8_t>(buf.
ReadByte(), 63u);
245 for (uint j = 0; j < 4; j++) housespec->random_colour[j] =
static_cast<Colours
>(
GB(buf.
ReadByte(), 0, 4));
249 housespec->probability = buf.
ReadByte();
258 housespec->animation.frames =
GB(info, 0, 7);
268 housespec->class_id = AllocateHouseClassID(buf.
ReadByte(), _cur_gps.
grffile->grfid);
272 auto mask = housespec->callback_mask.base();
282 if (cargotypes == 0xFFFFFFFF)
break;
286 uint8_t cargo_part =
GB(cargotypes, 8 * j, 8);
291 housespec->cargo_acceptance[j] = 0;
293 housespec->accepts_cargo[j] = cargo;
295 housespec->accepts_cargo_label[j] =
CT_INVALID;
301 housespec->minimum_life = buf.
ReadByte();
306 for (uint8_t j = 0; j < count; j++) {
324 if (count >
lengthof(housespec->accepts_cargo)) {
332 for (uint i = 0; i <
lengthof(housespec->accepts_cargo); i++) {
335 housespec->cargo_acceptance[i] = buf.
ReadByte();
337 housespec->accepts_cargo[i] = INVALID_CARGO;
338 housespec->cargo_acceptance[i] = 0;
340 if (i < std::size(housespec->accepts_cargo_label)) housespec->accepts_cargo_label[i] =
CT_INVALID;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static constexpr CargoLabel CT_INVALID
Invalid cargo type.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
void Add(uint16_t local_id, uint32_t grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF.
static const uint HOUSE_ORIGINAL_NUM_ACCEPTS
Original number of accepted cargo types.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
static ChangeInfoResult IgnoreTownHouseProperty(int prop, ByteReader &buf)
Ignore a house property.
static ChangeInfoResult TownHouseChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for houses.
@ NonLooping
Animation is not looping.
@ Looping
Animation is looping.
NewGRF buffer reader definition.
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_DISABLED
GRF was disabled due to error.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_UNHANDLED
Variable was parsed but unread.
@ CIR_SUCCESS
Variable was parsed and read.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
#define lengthof(array)
Return the length of an fixed size array.
Information about why GRF had problems during initialisation.
std::array< uint32_t, 2 > param_value
Values of GRF parameters to show for message and custom_message.
LandscapeType landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
GRFFile * grffile
Currently processed GRF file.
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.