diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 14ddfb57fb..f418762977 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1873,7 +1873,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Age - int16_t age = tileElement->properties.scenery.age; + int16_t age = tileElement->AsSmallScenery()->GetAge(); gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_SCENERY_AGE, &age, COLOUR_DARK_GREEN, x, y); // Quadrant value diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index abd9a0c7e8..40347a3a46 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -91,7 +91,7 @@ static void cheat_water_plants() { if (it.element->GetType() == TILE_ELEMENT_TYPE_SMALL_SCENERY) { - it.element->properties.scenery.age = 0; + it.element->AsSmallScenery()->SetAge(0); } } while (tile_element_iterator_next(&it)); diff --git a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp index 78711da702..d6c85fc4fd 100644 --- a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp @@ -128,11 +128,11 @@ void scenery_paint(paint_session* session, uint8_t direction, int32_t height, co } if (scenery_small_entry_has_flag(entry, SMALL_SCENERY_FLAG_CAN_WITHER)) { - if (tileElement->properties.scenery.age >= SCENERY_WITHER_AGE_THRESHOLD_1) + if (tileElement->AsSmallScenery()->GetAge() >= SCENERY_WITHER_AGE_THRESHOLD_1) { baseImageid += 4; } - if (tileElement->properties.scenery.age >= SCENERY_WITHER_AGE_THRESHOLD_2) + if (tileElement->AsSmallScenery()->GetAge() >= SCENERY_WITHER_AGE_THRESHOLD_2) { baseImageid += 4; } diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index f9c0da89e2..1ebde80e9f 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1743,7 +1743,7 @@ void rct_peep::UpdateWatering() if (!scenery_small_entry_has_flag(scenery_entry, SMALL_SCENERY_FLAG_CAN_BE_WATERED)) continue; - tile_element->properties.scenery.age = 0; + tile_element->AsSmallScenery()->SetAge(0); map_invalidate_tile_zoom0(actionX, actionY, tile_element->base_height * 8, tile_element->clearance_height * 8); staff_gardens_watered++; window_invalidate_flags |= PEEP_INVALIDATE_STAFF_STATS; @@ -2159,14 +2159,14 @@ static int32_t peep_update_patrolling_find_watering(rct_peep* peep) continue; } - if (tile_element->properties.scenery.age < SCENERY_WITHER_AGE_THRESHOLD_2) + if (tile_element->AsSmallScenery()->GetAge() < SCENERY_WITHER_AGE_THRESHOLD_2) { if (chosen_position >= 4) { continue; } - if (tile_element->properties.scenery.age < SCENERY_WITHER_AGE_THRESHOLD_1) + if (tile_element->AsSmallScenery()->GetAge() < SCENERY_WITHER_AGE_THRESHOLD_1) { continue; } diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 7fa8402abe..6e203506a3 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -247,8 +247,9 @@ static void mapgen_place_tree(int32_t type, int32_t x, int32_t y) tileElement->clearance_height = surfaceZ + (sceneryEntry->small_scenery.height >> 3); tileElement->type = TILE_ELEMENT_TYPE_SMALL_SCENERY | (util_rand() & 3); - tileElement->AsSmallScenery()->SetEntryIndex(type); - tileElement->properties.scenery.age = 0; + SmallSceneryElement * sceneryElement = tileElement->AsSmallScenery(); + sceneryElement->SetEntryIndex(type); + sceneryElement->SetAge(0); scenery_small_set_primary_colour(tileElement, COLOUR_YELLOW); } diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index a71b3ffdc6..ec0c253a01 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -67,8 +67,6 @@ money32 gClearSceneryCost; // rct2: 0x009A3E74 const LocationXY8 ScenerySubTileOffsets[] = { { 7, 7 }, { 7, 23 }, { 23, 23 }, { 23, 7 } }; -void scenery_increase_age(int32_t x, int32_t y, rct_tile_element* tileElement); - void scenery_update_tile(int32_t x, int32_t y) { rct_tile_element* tileElement; @@ -130,9 +128,9 @@ void scenery_update_age(int32_t x, int32_t y, rct_tile_element* tileElement) } if (!scenery_small_entry_has_flag(sceneryEntry, SMALL_SCENERY_FLAG_CAN_BE_WATERED) - || (gClimateCurrent.Weather < WEATHER_RAIN) || (tileElement->properties.scenery.age < 5)) + || (gClimateCurrent.Weather < WEATHER_RAIN) || (tileElement->AsSmallScenery()->GetAge() < 5)) { - scenery_increase_age(x, y, tileElement); + tileElement->AsSmallScenery()->IncreaseAge(x, y); return; } @@ -153,13 +151,13 @@ void scenery_update_age(int32_t x, int32_t y, rct_tile_element* tileElement) case TILE_ELEMENT_TYPE_ENTRANCE: case TILE_ELEMENT_TYPE_PATH: map_invalidate_tile_zoom1(x, y, tileElementAbove->base_height * 8, tileElementAbove->clearance_height * 8); - scenery_increase_age(x, y, tileElement); + tileElement->AsSmallScenery()->IncreaseAge(x, y); return; case TILE_ELEMENT_TYPE_SMALL_SCENERY: sceneryEntry = get_small_scenery_entry(tileElementAbove->AsSmallScenery()->GetEntryIndex()); if (scenery_small_entry_has_flag(sceneryEntry, SMALL_SCENERY_FLAG_VOFFSET_CENTRE)) { - scenery_increase_age(x, y, tileElement); + tileElement->AsSmallScenery()->IncreaseAge(x, y); return; } break; @@ -167,32 +165,10 @@ void scenery_update_age(int32_t x, int32_t y, rct_tile_element* tileElement) } // Reset age / water plant - tileElement->properties.scenery.age = 0; + tileElement->AsSmallScenery()->SetAge(0); map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); } -void scenery_increase_age(int32_t x, int32_t y, rct_tile_element* tileElement) -{ - if (tileElement->flags & SMALL_SCENERY_FLAG_ANIMATED) - return; - - if (tileElement->properties.scenery.age < 255) - { - uint8_t newAge = tileElement->properties.scenery.age++; - - // Only invalidate tiles when scenery crosses the withering threshholds, and can be withered. - if (newAge == SCENERY_WITHER_AGE_THRESHOLD_1 || newAge == SCENERY_WITHER_AGE_THRESHOLD_2) - { - rct_scenery_entry* entry = get_small_scenery_entry(tileElement->AsSmallScenery()->GetEntryIndex()); - - if (scenery_small_entry_has_flag(entry, SMALL_SCENERY_FLAG_CAN_WITHER)) - { - map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); - } - } - } -} - /** * * rct2: 0x006E2712 diff --git a/src/openrct2/world/SmallScenery.cpp b/src/openrct2/world/SmallScenery.cpp index d48ffbc73c..874787c238 100644 --- a/src/openrct2/world/SmallScenery.cpp +++ b/src/openrct2/world/SmallScenery.cpp @@ -384,8 +384,9 @@ static money32 SmallSceneryPlace( type |= TILE_ELEMENT_TYPE_SMALL_SCENERY; type |= rotation; newElement->type = type; - newElement->AsSmallScenery()->SetEntryIndex(sceneryType); - newElement->properties.scenery.age = 0; + SmallSceneryElement * sceneryElement = newElement->AsSmallScenery(); + sceneryElement->SetEntryIndex(sceneryType); + sceneryElement->SetAge(0); scenery_small_set_primary_colour(newElement, primaryColour); scenery_small_set_secondary_colour(newElement, secondaryColour); newElement->clearance_height = newElement->base_height + ((sceneryEntry->small_scenery.height + 7) / 8); @@ -569,4 +570,36 @@ uint8_t SmallSceneryElement::GetEntryIndex() const void SmallSceneryElement::SetEntryIndex(uint8_t newIndex) { this->entryIndex = newIndex; +} + +uint8_t SmallSceneryElement::GetAge() const +{ + return this->age; +} + +void SmallSceneryElement::SetAge(uint8_t newAge) +{ + this->age = newAge; +} + +void SmallSceneryElement::IncreaseAge(int32_t x, int32_t y) +{ + if (flags & SMALL_SCENERY_FLAG_ANIMATED) + return; + + if (age < 255) + { + uint8_t newAge = age++; + + // Only invalidate tiles when scenery crosses the withering threshholds, and can be withered. + if (newAge == SCENERY_WITHER_AGE_THRESHOLD_1 || newAge == SCENERY_WITHER_AGE_THRESHOLD_2) + { + rct_scenery_entry* entry = get_small_scenery_entry(GetEntryIndex()); + + if (scenery_small_entry_has_flag(entry, SMALL_SCENERY_FLAG_CAN_WITHER)) + { + map_invalidate_tile_zoom1(x, y, base_height * 8, clearance_height * 8); + } + } + } } \ No newline at end of file diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 1f72c654bd..c8e1798c58 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -230,8 +230,11 @@ struct SmallSceneryElement : TileElementBase uint8_t colour_2; // 7 public: uint8_t GetEntryIndex() const; - void SetEntryIndex(uint8_t entryIndex); + void SetEntryIndex(uint8_t newIndex); + uint8_t GetAge() const; + void SetAge(uint8_t newAge); uint8_t GetSceneryQuadrant() const; + void IncreaseAge(int32_t x, int32_t y); }; assert_struct_size(SmallSceneryElement, 8);