mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19335) -Codechange: StationRect::BeforeAddTile() returns a CommandCost.
This commit is contained in:
parent
993c9e6f62
commit
d4b748e27e
|
@ -13,6 +13,7 @@
|
||||||
#define BASE_STATION_BASE_H
|
#define BASE_STATION_BASE_H
|
||||||
|
|
||||||
#include "core/pool_type.hpp"
|
#include "core/pool_type.hpp"
|
||||||
|
#include "command_type.h"
|
||||||
#include "viewport_type.h"
|
#include "viewport_type.h"
|
||||||
#include "station_map.h"
|
#include "station_map.h"
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ struct StationRect : public Rect {
|
||||||
void MakeEmpty();
|
void MakeEmpty();
|
||||||
bool PtInExtendedRect(int x, int y, int distance = 0) const;
|
bool PtInExtendedRect(int x, int y, int distance = 0) const;
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
bool BeforeAddTile(TileIndex tile, StationRectMode mode);
|
CommandCost BeforeAddTile(TileIndex tile, StationRectMode mode);
|
||||||
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
|
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
|
||||||
bool AfterRemoveTile(BaseStation *st, TileIndex tile);
|
bool AfterRemoveTile(BaseStation *st, TileIndex tile);
|
||||||
bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);
|
bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);
|
||||||
|
|
|
@ -366,7 +366,7 @@ bool StationRect::IsEmpty() const
|
||||||
return this->left == 0 || this->left > this->right || this->top > this->bottom;
|
return this->left == 0 || this->left > this->right || this->top > this->bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
||||||
{
|
{
|
||||||
int x = TileX(tile);
|
int x = TileX(tile);
|
||||||
int y = TileY(tile);
|
int y = TileY(tile);
|
||||||
|
@ -386,8 +386,7 @@ bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
||||||
int h = new_rect.bottom - new_rect.top + 1;
|
int h = new_rect.bottom - new_rect.top + 1;
|
||||||
if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
|
if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
|
||||||
assert(mode != ADD_TRY);
|
assert(mode != ADD_TRY);
|
||||||
_error_message = STR_ERROR_STATION_TOO_SPREAD_OUT;
|
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* spread-out ok, return true */
|
/* spread-out ok, return true */
|
||||||
|
@ -398,13 +397,19 @@ bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
||||||
} else {
|
} else {
|
||||||
; // new point is inside the rect, we don't need to do anything
|
; // new point is inside the rect, we don't need to do anything
|
||||||
}
|
}
|
||||||
return true;
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
|
bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
|
||||||
{
|
{
|
||||||
return (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) && // important when the old rect is completely inside the new rect, resp. the old one was empty
|
if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
|
||||||
this->BeforeAddTile(tile, mode) && this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
|
/* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
|
||||||
|
CommandCost ret = this->BeforeAddTile(tile, mode);
|
||||||
|
if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
|
||||||
|
if (ret.Succeeded()) return true;
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue