Merge pull request #8421 from IntelOrca/8405-use-cangrow

Use new canGrow property on surface objects
This commit is contained in:
Ted John 2018-12-13 16:51:21 +00:00 committed by GitHub
commit f8d91279ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 61 deletions

View File

@ -59,23 +59,17 @@ int32_t day_spinner_value = 1;
static void cheat_set_grass_length(int32_t length) static void cheat_set_grass_length(int32_t length)
{ {
int32_t x, y; int32_t x, y;
TileElement* tileElement;
for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
{ {
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{ {
tileElement = map_get_surface_element_at(x, y); auto surfaceElement = map_get_surface_element_at(x, y)->AsSurface();
if (!(tileElement->AsSurface()->GetOwnership() & OWNERSHIP_OWNED)) if (surfaceElement != nullptr && (surfaceElement->GetOwnership() & OWNERSHIP_OWNED)
continue; && surfaceElement->GetWaterHeight() == 0 && surfaceElement->CanGrassGrow())
{
if (tileElement->AsSurface()->GetSurfaceStyle() != TERRAIN_GRASS) surfaceElement->SetGrassLength(length);
continue; }
if (tileElement->AsSurface()->GetWaterHeight() > 0)
continue;
tileElement->AsSurface()->SetGrassLength(length);
} }
} }

View File

@ -81,7 +81,8 @@ void TerrainSurfaceObject::ReadJson(IReadObjectContext* context, const json_t* r
Flags = ObjectJsonHelpers::GetFlags<TERRAIN_SURFACE_FLAGS>( Flags = ObjectJsonHelpers::GetFlags<TERRAIN_SURFACE_FLAGS>(
properties, properties,
{ { "smoothWithSelf", TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_SELF }, { { "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"); auto jDefault = json_object_get(root, "default");
if (json_is_object(jDefault)) if (json_is_object(jDefault))

View File

@ -17,6 +17,7 @@ enum TERRAIN_SURFACE_FLAGS
NONE = 0, NONE = 0,
SMOOTH_WITH_SELF = 1 << 0, SMOOTH_WITH_SELF = 1 << 0,
SMOOTH_WITH_OTHER = 1 << 1, SMOOTH_WITH_OTHER = 1 << 1,
CAN_GROW = 1 << 2,
}; };
class TerrainSurfaceObject final : public Object class TerrainSurfaceObject final : public Object

View File

@ -21,6 +21,8 @@
#include "../management/Finance.h" #include "../management/Finance.h"
#include "../network/network.h" #include "../network/network.h"
#include "../object/ObjectList.h" #include "../object/ObjectList.h"
#include "../object/ObjectManager.h"
#include "../object/TerrainSurfaceObject.h"
#include "../paint/tile_element/Paint.TileElement.h" #include "../paint/tile_element/Paint.TileElement.h"
#include "../ride/RideData.h" #include "../ride/RideData.h"
#include "../ride/Station.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) if (chosenTile.x > 0x1FFF || chosenTile.y > 0x1FFF)
continue; continue;
TileElement* tileElement = map_get_surface_element_at(chosenTile); auto surfaceElement = map_get_surface_element_at(chosenTile)->AsSurface();
if (surfaceElement != nullptr)
if (tileElement->AsSurface()->GetSurfaceStyle() != TERRAIN_GRASS) {
continue; if (std::abs(surfaceElement->base_height - peep->next_z) <= 2)
{
if (abs(tileElement->base_height - peep->next_z) > 2) if (surfaceElement->CanGrassGrow() && (surfaceElement->GetGrassLength() & 0x7) >= GRASS_LENGTH_CLEAR_1)
continue; {
return chosenDirection;
if ((tileElement->AsSurface()->GetGrassLength() & 0x7) < GRASS_LENGTH_CLEAR_1) }
continue; }
}
return chosenDirection;
} }
return 0xFF; return 0xFF;
} }
@ -1674,15 +1675,11 @@ void rct_peep::UpdateMowing()
if (var_37 != 7) if (var_37 != 7)
continue; continue;
TileElement* tile_element = map_get_first_element_at(next_x / 32, next_y / 32); auto surfaceElement = map_get_surface_element_at(next_x / 32, next_y / 32)->AsSurface();
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
for (; (tile_element->GetType() != TILE_ELEMENT_TYPE_SURFACE); tile_element++)
;
if (tile_element->AsSurface()->GetSurfaceStyle() == TERRAIN_GRASS)
{ {
tile_element->AsSurface()->SetGrassLength(GRASS_LENGTH_MOWED); surfaceElement->SetGrassLength(GRASS_LENGTH_MOWED);
map_invalidate_tile_zoom0(next_x, next_y, tile_element->base_height * 8, tile_element->base_height * 8 + 16); map_invalidate_tile_zoom0(next_x, next_y, surfaceElement->base_height * 8, surfaceElement->base_height * 8 + 16);
} }
staff_lawns_mown++; staff_lawns_mown++;
window_invalidate_flags |= PEEP_INVALIDATE_STAFF_STATS; 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())) if (!(peep->GetNextIsSurface()))
return 0; return 0;
TileElement* tile_element = map_get_surface_element_at({ peep->next_x, peep->next_y }); auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y })->AsSurface();
if (surfaceElement != nullptr && surfaceElement->CanGrassGrow())
if ((tile_element->AsSurface()->GetSurfaceStyle()) != TERRAIN_GRASS) {
return 0; if ((surfaceElement->GetGrassLength() & 0x7) >= GRASS_LENGTH_CLEAR_1)
{
if ((tile_element->AsSurface()->GetGrassLength() & 0x7) < GRASS_LENGTH_CLEAR_1) peep->SetState(PEEP_STATE_MOWING);
return 0; 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->SetState(PEEP_STATE_MOWING); peep->destination_x = peep->next_x + _MowingWaypoints[0].x;
peep->var_37 = 0; peep->destination_y = peep->next_y + _MowingWaypoints[0].y;
// Original code used .y for both x and y. Changed to .x to make more sense (both x and y are 28) peep->destination_tolerance = 3;
peep->destination_x = peep->next_x + _MowingWaypoints[0].x; return 1;
peep->destination_y = peep->next_y + _MowingWaypoints[0].y; }
peep->destination_tolerance = 3; }
return 1; return 0;
} }
/** /**

View File

@ -1284,11 +1284,15 @@ static money32 map_change_surface_style(
continue; 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) if (surfaceStyle != 0xFF)
{ {
uint8_t cur_terrain = tileElement->AsSurface()->GetSurfaceStyle(); uint8_t cur_terrain = surfaceElement->GetSurfaceStyle();
if (surfaceStyle != cur_terrain) if (surfaceStyle != cur_terrain)
{ {
@ -1305,7 +1309,7 @@ static money32 map_change_surface_style(
if (flags & GAME_COMMAND_FLAG_APPLY) if (flags & GAME_COMMAND_FLAG_APPLY)
{ {
tileElement->AsSurface()->SetSurfaceStyle(surfaceStyle); surfaceElement->SetSurfaceStyle(surfaceStyle);
map_invalidate_tile_full(x, y); map_invalidate_tile_full(x, y);
footpath_remove_litter(x, y, tile_element_height(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) if (edgeStyle != 0xFF)
{ {
uint8_t currentEdge = tileElement->AsSurface()->GetEdgeStyle(); uint8_t currentEdge = surfaceElement->GetEdgeStyle();
if (edgeStyle != currentEdge) if (edgeStyle != currentEdge)
{ {
@ -1323,7 +1327,7 @@ static money32 map_change_surface_style(
if (flags & GAME_COMMAND_FLAG_APPLY) if (flags & GAME_COMMAND_FLAG_APPLY)
{ {
tileElement->AsSurface()->SetEdgeStyle(edgeStyle); surfaceElement->SetEdgeStyle(edgeStyle);
map_invalidate_tile_full(x, y); map_invalidate_tile_full(x, y);
} }
} }
@ -1331,13 +1335,10 @@ static money32 map_change_surface_style(
if (flags & GAME_COMMAND_FLAG_APPLY) 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) surfaceElement->SetGrassLength(GRASS_LENGTH_CLEAR_0);
{ map_invalidate_tile_full(x, y);
tileElement->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
map_invalidate_tile_full(x, y);
}
} }
} }
} }

View File

@ -9,6 +9,9 @@
#include "Surface.h" #include "Surface.h"
#include "../Context.h"
#include "../object/ObjectManager.h"
#include "../object/TerrainSurfaceObject.h"
#include "../scenario/Scenario.h" #include "../scenario/Scenario.h"
#include "Location.hpp" #include "Location.hpp"
#include "Map.h" #include "Map.h"
@ -67,6 +70,22 @@ void SurfaceElement::SetWaterHeight(uint32_t newWaterHeight)
terrain |= 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 uint8_t SurfaceElement::GetGrassLength() const
{ {
return grass_length; return grass_length;
@ -108,7 +127,7 @@ void SurfaceElement::SetGrassLengthAndInvalidate(uint8_t length, CoordsXY coords
void SurfaceElement::UpdateGrassLength(CoordsXY coords) void SurfaceElement::UpdateGrassLength(CoordsXY coords)
{ {
// Check if tile is grass // Check if tile is grass
if (GetSurfaceStyle() != TERRAIN_GRASS) if (!CanGrassGrow())
return; return;
uint8_t grassLengthTmp = grass_length & 7; uint8_t grassLengthTmp = grass_length & 7;
@ -226,4 +245,4 @@ void SurfaceElement::SetHasTrackThatNeedsWater(bool on)
type &= ~SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER; type &= ~SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER;
if (on) if (on)
type |= SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER; type |= SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER;
} }

View File

@ -143,6 +143,7 @@ public:
uint32_t GetEdgeStyle() const; uint32_t GetEdgeStyle() const;
void SetEdgeStyle(uint32_t newStyle); void SetEdgeStyle(uint32_t newStyle);
bool CanGrassGrow() const;
uint8_t GetGrassLength() const; uint8_t GetGrassLength() const;
void SetGrassLength(uint8_t newLength); void SetGrassLength(uint8_t newLength);
void SetGrassLengthAndInvalidate(uint8_t newLength, CoordsXY coords); void SetGrassLengthAndInvalidate(uint8_t newLength, CoordsXY coords);