Fix format, move validation logic to query, update network version

This commit is contained in:
Christopher G. Dolan 2019-02-04 17:27:41 -08:00
parent a8864092c0
commit 19a58fa5fe
2 changed files with 53 additions and 35 deletions

View File

@ -15,8 +15,8 @@
#include "../localisation/StringIds.h"
#include "../ui/UiContext.h"
#include "../windows/Intent.h"
#include "../world/Sprite.h"
#include "../world/Banner.h"
#include "../world/Sprite.h"
#include "GameAction.h"
DEFINE_GAME_ACTION(SignSetStyleAction, GAME_COMMAND_SET_SIGN_STYLE, GameActionResult)
@ -25,15 +25,15 @@ private:
int32_t _bannerIndex;
uint8_t _mainColour;
uint8_t _textColour;
bool _is_large;
bool _isLarge;
public:
SignSetStyleAction() = default;
SignSetStyleAction(int32_t bannerIndex, uint8_t mainColour, uint8_t textColour, bool is_large)
SignSetStyleAction(int32_t bannerIndex, uint8_t mainColour, uint8_t textColour, bool isLarge)
: _bannerIndex(bannerIndex)
, _mainColour(mainColour)
, _textColour(textColour)
, _is_large(is_large)
, _isLarge(isLarge)
{
}
@ -45,17 +45,61 @@ public:
void Serialise(DataSerialiser & stream) override
{
GameAction::Serialise(stream);
stream << DS_TAG(_bannerIndex) << DS_TAG(_mainColour) << DS_TAG(_textColour) << DS_TAG(_is_large);
stream << DS_TAG(_bannerIndex) << DS_TAG(_mainColour) << DS_TAG(_textColour) << DS_TAG(_isLarge);
}
GameActionResult::Ptr Query() const override
{
if ((BannerIndex)_bannerIndex >= MAX_BANNERS || _bannerIndex < 0)
{
log_warning("Invalid game command for setting sign style, banner id = %d", _bannerIndex);
log_warning("Invalid game command for setting sign style, banner id '%d' out of range", _bannerIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
rct_banner* banner = &gBanners[_bannerIndex];
int32_t x = banner->x << 5;
int32_t y = banner->y << 5;
if (_isLarge)
{
TileElement* tileElement = banner_get_tile_element((BannerIndex)_bannerIndex);
if (tileElement == nullptr)
{
log_warning("Invalid game command for setting sign style, banner id '%d' not found", _bannerIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
if (tileElement->GetType() != TILE_ELEMENT_TYPE_LARGE_SCENERY)
{
log_warning("Invalid game command for setting sign style, banner id '%d' is not large", _bannerIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
}
else
{
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
bool wallFound = false;
do
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL)
continue;
rct_scenery_entry* scenery_entry = tileElement->AsWall()->GetEntry();
if (scenery_entry->wall.scrolling_mode == 0xFF)
continue;
if (tileElement->AsWall()->GetBannerIndex() != (BannerIndex)_bannerIndex)
continue;
wallFound = true;
break;
} while (!(tileElement++)->IsLastForTile());
if (!wallFound == false)
{
log_warning("Invalid game command for setting sign style, banner id '%d' not found", _bannerIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
}
return MakeResult();
}
@ -66,47 +110,21 @@ public:
int32_t x = banner->x << 5;
int32_t y = banner->y << 5;
if (_is_large)
if (_isLarge)
{
TileElement* tileElement = banner_get_tile_element((BannerIndex)_bannerIndex);
if (tileElement == nullptr || tileElement->GetType() != TILE_ELEMENT_TYPE_LARGE_SCENERY)
{
return MakeResult(GA_ERROR::NO_FREE_ELEMENTS, STR_ERR_CANT_SET_BANNER_TEXT);
}
if (!sign_set_colour(
banner->x * 32, banner->y * 32, tileElement->base_height, tileElement->GetDirection(),
tileElement->AsLargeScenery()->GetSequenceIndex(), _mainColour, _textColour))
{
return MakeResult();
return MakeResult(GA_ERROR::UNKNOWN, STR_NONE);
}
}
else
{
TileElement* tileElement = map_get_first_element_at(x / 32, y / 32);
bool wall_found = false;
do
{
if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL)
continue;
rct_scenery_entry* scenery_entry = tileElement->AsWall()->GetEntry();
if (scenery_entry->wall.scrolling_mode == 0xFF)
continue;
if (tileElement->AsWall()->GetBannerIndex() != (BannerIndex)_bannerIndex)
continue;
wall_found = true;
break;
} while (!(tileElement++)->IsLastForTile());
if (wall_found == false)
{
return MakeResult();
}
tileElement->AsWall()->SetPrimaryColour(_mainColour);
tileElement->AsWall()->SetSecondaryColour(_textColour);
map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8);
}

View File

@ -30,7 +30,7 @@
// This string specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "26"
#define NETWORK_STREAM_VERSION "27"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
static rct_peep* _pickup_peep = nullptr;