diff --git a/src/openrct2/actions/StaffHireNewAction.hpp b/src/openrct2/actions/StaffHireNewAction.hpp index c91d7a763c..1565e3bfb5 100644 --- a/src/openrct2/actions/StaffHireNewAction.hpp +++ b/src/openrct2/actions/StaffHireNewAction.hpp @@ -158,8 +158,6 @@ private: } else { - move_sprite_to_list(newPeep, SPRITE_LIST_PEEP); - newPeep->sprite_identifier = 1; newPeep->window_invalidate_flags = 0; newPeep->action = PEEP_ACTION_NONE_2; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 9e355cf31c..c479aee42d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1122,17 +1122,14 @@ private: rct1_vehicle* srcVehicle = &_s4.sprites[i].vehicle; if (srcVehicle->x != LOCATION_NULL) { - Vehicle* vehicle = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_VEHICLE)); + // If vehicle is the first car on a train add to train list + auto llt = srcVehicle->type == VEHICLE_TYPE_HEAD ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE; + + Vehicle* vehicle = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_VEHICLE, llt)); spriteIndexMap[i] = vehicle->sprite_index; vehicles.push_back(vehicle); ImportVehicle(vehicle, srcVehicle); - - // If vehicle is the first car on a train add to train list - if (vehicle->IsHead()) - { - move_sprite_to_list(vehicle, SPRITE_LIST_TRAIN_HEAD); - } } } } diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 684995969f..b138c4fabf 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -23,13 +23,13 @@ Vehicle* cable_lift_segment_create( Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head) { - Vehicle* current = &(create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle); + Vehicle* current = &( + create_sprite(SPRITE_IDENTIFIER_VEHICLE, head ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE)->vehicle); current->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; current->ride = ride.id; current->ride_subtype = RIDE_ENTRY_INDEX_NULL; if (head) { - move_sprite_to_list(current, SPRITE_LIST_TRAIN_HEAD); ride.cable_lift = current->sprite_index; } current->type = head ? VEHICLE_TYPE_HEAD : VEHICLE_TYPE_TAIL; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 227f8056f2..bdfd7c0608 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4324,7 +4324,8 @@ static Vehicle* vehicle_create_car( return nullptr; auto vehicleEntry = &rideEntry->vehicles[vehicleEntryIndex]; - auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE)->vehicle; + auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE, carIndex == 0 ? SPRITE_LIST_TRAIN_HEAD : SPRITE_LIST_VEHICLE) + ->vehicle; if (vehicle == nullptr) return nullptr; @@ -4568,8 +4569,6 @@ static void vehicle_create_trains(ride_id_t rideIndex, int32_t x, int32_t y, int } lastTrain = train; - // Add train to ride vehicle list - move_sprite_to_list(train.head, SPRITE_LIST_TRAIN_HEAD); for (int32_t i = 0; i <= MAX_VEHICLES_PER_RIDE; i++) { if (ride->vehicles[i] == SPRITE_INDEX_NULL) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 1a09148c20..d608bf8140 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -50,6 +50,7 @@ static CoordsXYZ _spritelocations1[MAX_SPRITES]; static CoordsXYZ _spritelocations2[MAX_SPRITES]; static size_t GetSpatialIndexOffset(int32_t x, int32_t y); +static void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex); std::string rct_sprite_checksum::ToString() const { @@ -358,7 +359,7 @@ static void SpriteSpatialInsert(SpriteBase* sprite, const CoordsXY& newLoc); static constexpr uint16_t MAX_MISC_SPRITES = 300; -rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier) +rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, SPRITE_LIST linkedListIndex) { if (gSpriteListCount[SPRITE_LIST_FREE] == 0) { @@ -366,26 +367,6 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier) return nullptr; } - SPRITE_LIST linkedListIndex; - switch (spriteIdentifier) - { - case SPRITE_IDENTIFIER_VEHICLE: - linkedListIndex = SPRITE_LIST_VEHICLE; - break; - case SPRITE_IDENTIFIER_PEEP: - linkedListIndex = SPRITE_LIST_PEEP; - break; - case SPRITE_IDENTIFIER_MISC: - linkedListIndex = SPRITE_LIST_MISC; - break; - case SPRITE_IDENTIFIER_LITTER: - linkedListIndex = SPRITE_LIST_LITTER; - break; - default: - Guard::Assert(false, "Invalid sprite identifier: 0x%02X", spriteIdentifier); - return nullptr; - } - if (linkedListIndex == SPRITE_LIST_MISC) { // Misc sprites are commonly used for effects, if there are less than MAX_MISC_SPRITES @@ -420,12 +401,36 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier) return reinterpret_cast(sprite); } +rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier) +{ + SPRITE_LIST linkedListIndex = SPRITE_LIST_FREE; + switch (spriteIdentifier) + { + case SPRITE_IDENTIFIER_VEHICLE: + linkedListIndex = SPRITE_LIST_VEHICLE; + break; + case SPRITE_IDENTIFIER_PEEP: + linkedListIndex = SPRITE_LIST_PEEP; + break; + case SPRITE_IDENTIFIER_MISC: + linkedListIndex = SPRITE_LIST_MISC; + break; + case SPRITE_IDENTIFIER_LITTER: + linkedListIndex = SPRITE_LIST_LITTER; + break; + default: + Guard::Assert(false, "Invalid sprite identifier: 0x%02X", spriteIdentifier); + return nullptr; + } + return create_sprite(spriteIdentifier, linkedListIndex); +} + /* * rct2: 0x0069ED0B * This function moves a sprite to the specified sprite linked list. * The game uses this list to categorise sprites by type. */ -void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex) +static void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newListIndex) { int32_t oldListIndex = sprite->linked_list_index; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 62e5d84803..5981854de6 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -204,10 +204,10 @@ extern uint16_t gSpriteSpatialIndex[SPATIAL_INDEX_SIZE]; extern const rct_string_id litterNames[12]; rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier); +rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, SPRITE_LIST linkedListIndex); void reset_sprite_list(); void reset_sprite_spatial_index(); void sprite_clear_all_unused(); -void move_sprite_to_list(SpriteBase* sprite, SPRITE_LIST newList); void sprite_misc_update_all(); void sprite_move(int16_t x, int16_t y, int16_t z, SpriteBase* sprite); void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, SpriteBase* sprite);