1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 23:34:37 +01:00

Do not access old small scenery age field

This commit is contained in:
Michael Steenbeek
2018-09-13 17:26:36 +02:00
parent 00429e6836
commit b5bb4c7fb9
8 changed files with 54 additions and 41 deletions

View File

@@ -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

View File

@@ -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));

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}
}
}
}

View File

@@ -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);