mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #8421 from IntelOrca/8405-use-cangrow
Use new canGrow property on surface objects
This commit is contained in:
commit
f8d91279ea
|
@ -59,23 +59,17 @@ int32_t day_spinner_value = 1;
|
|||
static void cheat_set_grass_length(int32_t length)
|
||||
{
|
||||
int32_t x, y;
|
||||
TileElement* tileElement;
|
||||
|
||||
for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
{
|
||||
tileElement = map_get_surface_element_at(x, y);
|
||||
if (!(tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED))
|
||||
continue;
|
||||
|
||||
if (tileElement->AsSurface()->GetSurfaceStyle() != TERRAIN_GRASS)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsSurface()->GetWaterHeight() > 0)
|
||||
continue;
|
||||
|
||||
tileElement->AsSurface()->SetGrassLength(length);
|
||||
auto surfaceElement = map_get_surface_element_at(x, y)->AsSurface();
|
||||
if (surfaceElement != nullptr && (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
|
||||
&& surfaceElement->GetWaterHeight() == 0 && surfaceElement->CanGrassGrow())
|
||||
{
|
||||
surfaceElement->SetGrassLength(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ void TerrainSurfaceObject::ReadJson(IReadObjectContext* context, const json_t* r
|
|||
Flags = ObjectJsonHelpers::GetFlags<TERRAIN_SURFACE_FLAGS>(
|
||||
properties,
|
||||
{ { "smoothWithSelf", TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_SELF },
|
||||
{ "smoothWithOther", TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_OTHER } });
|
||||
{ "smoothWithOther", TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_OTHER },
|
||||
{ "canGrow", TERRAIN_SURFACE_FLAGS::CAN_GROW } });
|
||||
|
||||
auto jDefault = json_object_get(root, "default");
|
||||
if (json_is_object(jDefault))
|
||||
|
|
|
@ -17,6 +17,7 @@ enum TERRAIN_SURFACE_FLAGS
|
|||
NONE = 0,
|
||||
SMOOTH_WITH_SELF = 1 << 0,
|
||||
SMOOTH_WITH_OTHER = 1 << 1,
|
||||
CAN_GROW = 1 << 2,
|
||||
};
|
||||
|
||||
class TerrainSurfaceObject final : public Object
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "../management/Finance.h"
|
||||
#include "../network/network.h"
|
||||
#include "../object/ObjectList.h"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "../object/TerrainSurfaceObject.h"
|
||||
#include "../paint/tile_element/Paint.TileElement.h"
|
||||
#include "../ride/RideData.h"
|
||||
#include "../ride/Station.h"
|
||||
|
@ -990,18 +992,17 @@ static uint8_t staff_handyman_direction_to_uncut_grass(rct_peep* peep, uint8_t v
|
|||
if (chosenTile.x > 0x1FFF || chosenTile.y > 0x1FFF)
|
||||
continue;
|
||||
|
||||
TileElement* tileElement = map_get_surface_element_at(chosenTile);
|
||||
|
||||
if (tileElement->AsSurface()->GetSurfaceStyle() != TERRAIN_GRASS)
|
||||
continue;
|
||||
|
||||
if (abs(tileElement->base_height - peep->next_z) > 2)
|
||||
continue;
|
||||
|
||||
if ((tileElement->AsSurface()->GetGrassLength() & 0x7) < GRASS_LENGTH_CLEAR_1)
|
||||
continue;
|
||||
|
||||
return chosenDirection;
|
||||
auto surfaceElement = map_get_surface_element_at(chosenTile)->AsSurface();
|
||||
if (surfaceElement != nullptr)
|
||||
{
|
||||
if (std::abs(surfaceElement->base_height - peep->next_z) <= 2)
|
||||
{
|
||||
if (surfaceElement->CanGrassGrow() && (surfaceElement->GetGrassLength() & 0x7) >= GRASS_LENGTH_CLEAR_1)
|
||||
{
|
||||
return chosenDirection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
@ -1674,15 +1675,11 @@ void rct_peep::UpdateMowing()
|
|||
if (var_37 != 7)
|
||||
continue;
|
||||
|
||||
TileElement* tile_element = map_get_first_element_at(next_x / 32, next_y / 32);
|
||||
|
||||
for (; (tile_element->GetType() != TILE_ELEMENT_TYPE_SURFACE); tile_element++)
|
||||
;
|
||||
|
||||
if (tile_element->AsSurface()->GetSurfaceStyle() == TERRAIN_GRASS)
|
||||
auto surfaceElement = map_get_surface_element_at(next_x / 32, next_y / 32)->AsSurface();
|
||||
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
|
||||
{
|
||||
tile_element->AsSurface()->SetGrassLength(GRASS_LENGTH_MOWED);
|
||||
map_invalidate_tile_zoom0(next_x, next_y, tile_element->base_height * 8, tile_element->base_height * 8 + 16);
|
||||
surfaceElement->SetGrassLength(GRASS_LENGTH_MOWED);
|
||||
map_invalidate_tile_zoom0(next_x, next_y, surfaceElement->base_height * 8, surfaceElement->base_height * 8 + 16);
|
||||
}
|
||||
staff_lawns_mown++;
|
||||
window_invalidate_flags |= PEEP_INVALIDATE_STAFF_STATS;
|
||||
|
@ -2264,21 +2261,21 @@ static int32_t peep_update_patrolling_find_grass(rct_peep* peep)
|
|||
if (!(peep->GetNextIsSurface()))
|
||||
return 0;
|
||||
|
||||
TileElement* tile_element = map_get_surface_element_at({ peep->next_x, peep->next_y });
|
||||
|
||||
if ((tile_element->AsSurface()->GetSurfaceStyle()) != TERRAIN_GRASS)
|
||||
return 0;
|
||||
|
||||
if ((tile_element->AsSurface()->GetGrassLength() & 0x7) < GRASS_LENGTH_CLEAR_1)
|
||||
return 0;
|
||||
|
||||
peep->SetState(PEEP_STATE_MOWING);
|
||||
peep->var_37 = 0;
|
||||
// Original code used .y for both x and y. Changed to .x to make more sense (both x and y are 28)
|
||||
peep->destination_x = peep->next_x + _MowingWaypoints[0].x;
|
||||
peep->destination_y = peep->next_y + _MowingWaypoints[0].y;
|
||||
peep->destination_tolerance = 3;
|
||||
return 1;
|
||||
auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y })->AsSurface();
|
||||
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
|
||||
{
|
||||
if ((surfaceElement->GetGrassLength() & 0x7) >= GRASS_LENGTH_CLEAR_1)
|
||||
{
|
||||
peep->SetState(PEEP_STATE_MOWING);
|
||||
peep->var_37 = 0;
|
||||
// Original code used .y for both x and y. Changed to .x to make more sense (both x and y are 28)
|
||||
peep->destination_x = peep->next_x + _MowingWaypoints[0].x;
|
||||
peep->destination_y = peep->next_y + _MowingWaypoints[0].y;
|
||||
peep->destination_tolerance = 3;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1284,11 +1284,15 @@ static money32 map_change_surface_style(
|
|||
continue;
|
||||
}
|
||||
|
||||
TileElement* tileElement = map_get_surface_element_at({ x, y });
|
||||
auto surfaceElement = map_get_surface_element_at({ x, y })->AsSurface();
|
||||
if (surfaceElement == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (surfaceStyle != 0xFF)
|
||||
{
|
||||
uint8_t cur_terrain = tileElement->AsSurface()->GetSurfaceStyle();
|
||||
uint8_t cur_terrain = surfaceElement->GetSurfaceStyle();
|
||||
|
||||
if (surfaceStyle != cur_terrain)
|
||||
{
|
||||
|
@ -1305,7 +1309,7 @@ static money32 map_change_surface_style(
|
|||
|
||||
if (flags & GAME_COMMAND_FLAG_APPLY)
|
||||
{
|
||||
tileElement->AsSurface()->SetSurfaceStyle(surfaceStyle);
|
||||
surfaceElement->SetSurfaceStyle(surfaceStyle);
|
||||
|
||||
map_invalidate_tile_full(x, y);
|
||||
footpath_remove_litter(x, y, tile_element_height(x, y));
|
||||
|
@ -1315,7 +1319,7 @@ static money32 map_change_surface_style(
|
|||
|
||||
if (edgeStyle != 0xFF)
|
||||
{
|
||||
uint8_t currentEdge = tileElement->AsSurface()->GetEdgeStyle();
|
||||
uint8_t currentEdge = surfaceElement->GetEdgeStyle();
|
||||
|
||||
if (edgeStyle != currentEdge)
|
||||
{
|
||||
|
@ -1323,7 +1327,7 @@ static money32 map_change_surface_style(
|
|||
|
||||
if (flags & GAME_COMMAND_FLAG_APPLY)
|
||||
{
|
||||
tileElement->AsSurface()->SetEdgeStyle(edgeStyle);
|
||||
surfaceElement->SetEdgeStyle(edgeStyle);
|
||||
map_invalidate_tile_full(x, y);
|
||||
}
|
||||
}
|
||||
|
@ -1331,13 +1335,10 @@ static money32 map_change_surface_style(
|
|||
|
||||
if (flags & GAME_COMMAND_FLAG_APPLY)
|
||||
{
|
||||
if (tileElement->AsSurface()->GetSurfaceStyle() == TERRAIN_GRASS)
|
||||
if (surfaceElement->CanGrassGrow() && (surfaceElement->GetGrassLength() & 7) != GRASS_LENGTH_CLEAR_0)
|
||||
{
|
||||
if ((tileElement->AsSurface()->GetGrassLength() & 7) != GRASS_LENGTH_CLEAR_0)
|
||||
{
|
||||
tileElement->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
map_invalidate_tile_full(x, y);
|
||||
}
|
||||
surfaceElement->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
map_invalidate_tile_full(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
#include "Surface.h"
|
||||
|
||||
#include "../Context.h"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "../object/TerrainSurfaceObject.h"
|
||||
#include "../scenario/Scenario.h"
|
||||
#include "Location.hpp"
|
||||
#include "Map.h"
|
||||
|
@ -67,6 +70,22 @@ void SurfaceElement::SetWaterHeight(uint32_t newWaterHeight)
|
|||
terrain |= newWaterHeight;
|
||||
}
|
||||
|
||||
bool SurfaceElement::CanGrassGrow() const
|
||||
{
|
||||
auto surfaceStyle = GetSurfaceStyle();
|
||||
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
||||
auto obj = objMgr.GetLoadedObject(OBJECT_TYPE_TERRAIN_SURFACE, surfaceStyle);
|
||||
if (obj != nullptr)
|
||||
{
|
||||
auto surfaceObject = static_cast<TerrainSurfaceObject*>(obj);
|
||||
if (surfaceObject->Flags & TERRAIN_SURFACE_FLAGS::CAN_GROW)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t SurfaceElement::GetGrassLength() const
|
||||
{
|
||||
return grass_length;
|
||||
|
@ -108,7 +127,7 @@ void SurfaceElement::SetGrassLengthAndInvalidate(uint8_t length, CoordsXY coords
|
|||
void SurfaceElement::UpdateGrassLength(CoordsXY coords)
|
||||
{
|
||||
// Check if tile is grass
|
||||
if (GetSurfaceStyle() != TERRAIN_GRASS)
|
||||
if (!CanGrassGrow())
|
||||
return;
|
||||
|
||||
uint8_t grassLengthTmp = grass_length & 7;
|
||||
|
@ -226,4 +245,4 @@ void SurfaceElement::SetHasTrackThatNeedsWater(bool on)
|
|||
type &= ~SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER;
|
||||
if (on)
|
||||
type |= SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ public:
|
|||
uint32_t GetEdgeStyle() const;
|
||||
void SetEdgeStyle(uint32_t newStyle);
|
||||
|
||||
bool CanGrassGrow() const;
|
||||
uint8_t GetGrassLength() const;
|
||||
void SetGrassLength(uint8_t newLength);
|
||||
void SetGrassLengthAndInvalidate(uint8_t newLength, CoordsXY coords);
|
||||
|
|
Loading…
Reference in New Issue