diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index e90c7b2843..af4dc6b8ea 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -684,13 +684,13 @@ void SpriteLayoutProcessor::ProcessRegisters(uint8_t resolved_var10, uint32_t re if (result.IsParentSprite()) { if (flags & TLF_BB_XY_OFFSET) { - result.delta_x += static_cast(GetRegister(regs->delta.parent[0])); - result.delta_y += static_cast(GetRegister(regs->delta.parent[1])); + result.delta_x += GetRegister(regs->delta.parent[0]); + result.delta_y += GetRegister(regs->delta.parent[1]); } - if (flags & TLF_BB_Z_OFFSET) result.delta_z += static_cast(GetRegister(regs->delta.parent[2])); + if (flags & TLF_BB_Z_OFFSET) result.delta_z += GetRegister(regs->delta.parent[2]); } else { - if (flags & TLF_CHILD_X_OFFSET) result.delta_x += static_cast(GetRegister(regs->delta.child[0])); - if (flags & TLF_CHILD_Y_OFFSET) result.delta_y += static_cast(GetRegister(regs->delta.child[1])); + if (flags & TLF_CHILD_X_OFFSET) result.delta_x += GetRegister(regs->delta.child[0]); + if (flags & TLF_CHILD_Y_OFFSET) result.delta_y += GetRegister(regs->delta.child[1]); } } } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 021ff8a264..300f246a4b 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -621,7 +621,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec if (object->ro.callback == CBID_NO_CALLBACK || object->ro.callback == CBID_RANDOM_TRIGGER || object->ro.callback == CBID_TRAIN_ALLOW_WAGON_ATTACH || object->ro.callback == CBID_VEHICLE_START_STOP_CHECK || object->ro.callback == CBID_VEHICLE_32DAY_CALLBACK || object->ro.callback == CBID_VEHICLE_COLOUR_MAPPING || object->ro.callback == CBID_VEHICLE_SPAWN_VISUAL_EFFECT) { - Vehicle *u = v->Move((int32_t)GetRegister(0x10F)); + Vehicle *u = v->Move(GetRegister(0x10F)); if (u == nullptr) return 0; // available, but zero if (parameter == 0x5F) { @@ -1102,7 +1102,7 @@ static void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction d object.ResetState(); object.callback_param1 = image_type | (stack << 8); const auto *group = object.Resolve(); - uint32_t reg100 = sprite_stack ? GetRegister(0x100) : 0; + int32_t reg100 = sprite_stack ? GetRegister(0x100) : 0; if (group != nullptr && group->num_sprites != 0) { result->seq[result->count].sprite = group->sprite + (direction % group->num_sprites); result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring @@ -1145,7 +1145,7 @@ static void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, En object.ResetState(); object.callback_param1 = image_type | (stack << 8); const auto *group = object.Resolve(); - uint32_t reg100 = sprite_stack ? GetRegister(0x100) : 0; + int32_t reg100 = sprite_stack ? GetRegister(0x100) : 0; if (group != nullptr && group->num_sprites != 0) { result->seq[result->count].sprite = group->sprite + (rotor_pos % group->num_sprites); result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 61b3e65e6f..d3d3f085f0 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -115,7 +115,7 @@ static uint32_t GetClosestIndustry(TileIndex tile, IndustryType type, const Indu */ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_set_id, uint8_t layout_filter, bool town_filter, const Industry *current) { - uint32_t grf_id = GetRegister(0x100); ///< Get the GRFID of the definition to look for in register 100h + uint32_t grf_id = static_cast(GetRegister(0x100)); ///< Get the GRFID of the definition to look for in register 100h IndustryType industry_type; uint32_t closest_dist = UINT32_MAX; uint8_t count = 0; @@ -311,7 +311,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_set_id, uint8 uint8_t layout_filter = 0; bool town_filter = false; if (variable == 0x68) { - uint32_t reg = GetRegister(0x101); + int32_t reg = GetRegister(0x101); layout_filter = GB(reg, 0, 8); town_filter = HasBit(reg, 8); } @@ -598,7 +598,7 @@ uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityC static int32_t DerefIndProd(int field, bool use_register) { - return use_register ? (int32_t)GetRegister(field) : field; + return use_register ? GetRegister(field) : field; } /** diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index a1ccfbbcf6..397cd4db3c 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -233,7 +233,7 @@ static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object * */ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current) { - uint32_t grf_id = GetRegister(0x100); // Get the GRFID of the definition to look for in register 100h + uint32_t grf_id = static_cast(GetRegister(0x100)); // Get the GRFID of the definition to look for in register 100h uint32_t idx; /* Determine what will be the object type to look for */ diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index b8121dcef9..ae736aa2db 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -27,7 +27,7 @@ * @pre i < 0x110 * @return the value of the register */ -inline uint32_t GetRegister(uint i) +inline int32_t GetRegister(uint i) { extern TemporaryStorageArray _temp_store; return _temp_store.GetValue(i); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 11b424cf46..bdae414ab3 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -655,7 +655,7 @@ SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseS const auto *group = object.Resolve(); /* Note: SpriteGroup::Resolve zeroes all registers, so register 0x100 is initialised to 0. (compatibility) */ - auto offset = GetRegister(0x100); + uint32_t offset = static_cast(GetRegister(0x100)); if (group == nullptr || group->num_sprites <= offset) return 0; return group->sprite + offset; diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index 81a89f1e70..eb0dc8a597 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -36,7 +36,7 @@ /* Get a variable from the persistent storage */ case 0x7C: { /* Check the persistent storage for the GrfID stored in register 100h. */ - uint32_t grfid = GetRegister(0x100); + uint32_t grfid = static_cast(GetRegister(0x100)); if (grfid == 0xFFFFFFFF) { if (this->ro.grffile == nullptr) return 0; grfid = this->ro.grffile->grfid; @@ -132,7 +132,7 @@ if (this->ro.grffile == nullptr) return; /* Check the persistent storage for the GrfID stored in register 100h. */ - uint32_t grfid = GetRegister(0x100); + uint32_t grfid = static_cast(GetRegister(0x100)); /* A NewGRF can only write in the persistent storage associated to its own GRFID. */ if (grfid == 0xFFFFFFFF) grfid = this->ro.grffile->grfid; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e1f67b3352..ee5364d2dd 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2725,7 +2725,7 @@ static void SpawnAdvancedVisualEffect(const Vehicle *v) int8_t y_center = _vehicle_smoke_pos[t_dir] * l_center; for (uint i = 0; i < count; i++) { - uint32_t reg = GetRegister(0x100 + i); + int32_t reg = GetRegister(0x100 + i); uint type = GB(reg, 0, 8); int8_t x = GB(reg, 8, 8); int8_t y = GB(reg, 16, 8);