summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bridge_gui.c3
-rw-r--r--command.h2
-rw-r--r--rail_cmd.c7
-rw-r--r--rail_gui.c19
-rw-r--r--settings_gui.c8
-rw-r--r--station_cmd.c4
-rw-r--r--tunnelbridge_cmd.c34
7 files changed, 45 insertions, 32 deletions
diff --git a/bridge_gui.c b/bridge_gui.c
index 881cb625a..5d9fa45ac 100644
--- a/bridge_gui.c
+++ b/bridge_gui.c
@@ -161,7 +161,6 @@ void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type)
w->vscroll.cap = 4;
w->vscroll.count = (byte)j;
} else {
- ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE,
- TileX(end) * 16, TileY(end) * 16);
+ ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * 16, TileY(end) * 16);
}
}
diff --git a/command.h b/command.h
index c6c514938..6a9764c06 100644
--- a/command.h
+++ b/command.h
@@ -192,5 +192,5 @@ bool IsValidCommand(uint cmd);
int32 GetAvailableMoneyForCommand(void);
/* Validate functions for rail building */
-static inline bool ValParamRailtype(uint32 rail) { return (rail > GetPlayer(_current_player)->max_railtype) ? false : true;}
+static inline bool ValParamRailtype(uint32 rail) { return rail <= GetPlayer(_current_player)->max_railtype;}
#endif /* COMMAND_H */
diff --git a/rail_cmd.c b/rail_cmd.c
index 7bb367c57..59eac26d6 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -276,7 +276,7 @@ static uint32 CheckRailSlope(uint tileh, uint rail_bits, uint existing, TileInde
}
/* Validate functions for rail building */
-static inline bool ValParamTrackOrientation(uint32 rail) {return (rail > 5) ? false : true;}
+static inline bool ValParamTrackOrientation(uint32 rail) {return rail <= 5;}
/** Build a single piece of rail
* @param x,y coordinates on where to build
@@ -292,7 +292,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
int32 cost = 0;
int32 ret;
- if (!(ValParamRailtype(p1) && ValParamTrackOrientation(p2))) return CMD_ERROR;
+ if (!ValParamRailtype(p1) || !ValParamTrackOrientation(p2)) return CMD_ERROR;
tile = TILE_FROM_XY(x, y);
tileh = GetTileSlope(tile, NULL);
@@ -590,7 +590,8 @@ static int32 CmdRailTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2
byte railbit = (p2 >> 4) & 7;
byte mode = HASBIT(p2, 7);
- if (!(ValParamRailtype(p2 & 0x3) && ValParamTrackOrientation(railbit))) return CMD_ERROR;
+ if (!ValParamRailtype(p2 & 0x3) || !ValParamTrackOrientation(railbit)) return CMD_ERROR;
+ if (p1 > MapSize()) return CMD_ERROR;
/* unpack end point */
ex = TileX(p1) * 16;
diff --git a/rail_gui.c b/rail_gui.c
index bc659196d..3a6d5a61e 100644
--- a/rail_gui.c
+++ b/rail_gui.c
@@ -639,14 +639,14 @@ static void HandleStationPlacement(uint start, uint end)
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
}
-static void StationBuildWndProc(Window *w, WindowEvent *e) {
- int rad;
- switch(e->event) {
+static void StationBuildWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
case WE_PAINT: {
+ int rad;
uint bits;
- if (WP(w,def_d).close)
- return;
+ if (WP(w,def_d).close) return;
bits = (1<<3) << ( _railstation.orientation);
if (_railstation.dragdrop) {
@@ -673,6 +673,13 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) {
if (_station_show_coverage)
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
+ /* Update buttons for correct spread value */
+ w->disabled_state = 0;
+ for (bits = _patches.station_spread; bits < 7; bits++) {
+ SETBIT(w->disabled_state, bits + 5);
+ SETBIT(w->disabled_state, bits + 12);
+ }
+
DrawWindowWidgets(w);
StationPickerDrawSprite(39, 42, _cur_railtype, 2);
@@ -687,7 +694,7 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) {
} break;
case WE_CLICK: {
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 3:
case 4:
_railstation.orientation = e->click.widget - 3;
diff --git a/settings_gui.c b/settings_gui.c
index dbfd9b91e..5ef7d8770 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -587,6 +587,12 @@ static int32 InValidateDetailsWindow(int32 p1)
return 0;
}
+static int32 InvalidateStationBuildWindow(int32 p1)
+{
+ InvalidateWindow(WC_BUILD_STATION, 0);
+ return 0;
+}
+
/* Check service intervals of vehicles, p1 is value of % or day based servicing */
static int32 CheckInterval(int32 p1)
{
@@ -704,7 +710,7 @@ static const PatchEntry _patches_stations[] = {
{PE_BOOL, 0, STR_CONFIG_PATCHES_SELECTGOODS, "select_goods", &_patches.selectgoods, 0, 0, 0, NULL},
{PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_NONSTOP, "new_nonstop", &_patches.new_nonstop, 0, 0, 0, NULL},
{PE_BOOL, 0, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, "nonuniform_stations", &_patches.nonuniform_stations, 0, 0, 0, NULL},
- {PE_UINT8, 0, STR_CONFIG_PATCHES_STATION_SPREAD, "station_spread", &_patches.station_spread, 4, 64, 1, NULL},
+ {PE_UINT8, 0, STR_CONFIG_PATCHES_STATION_SPREAD, "station_spread", &_patches.station_spread, 4, 64, 1, &InvalidateStationBuildWindow},
{PE_BOOL, 0, STR_CONFIG_PATCHES_SERVICEATHELIPAD, "service_at_helipad", &_patches.serviceathelipad, 0, 0, 0, NULL},
{PE_BOOL, 0, STR_CONFIG_PATCHES_CATCHMENT, "modified_catchment", &_patches.modified_catchment, 0, 0, 0, NULL},
diff --git a/station_cmd.c b/station_cmd.c
index d7cc53116..3b13c0fdb 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -918,7 +918,7 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, StationS
}
/** Build railroad station
- * @param x_org,y_org starting position of station dragging/placement
+ * @param x,y starting position of station dragging/placement
* @param p1 various bitstuffed elements
* - p1 = (bit 0) - orientation (p1 & 1)
* - p1 = (bit 8-15) - number of tracks (p1 >> 8) & 0xFF)
@@ -960,6 +960,8 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
h_org = numtracks;
}
+ if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
+
// these values are those that will be stored in train_tile and station_platforms
finalvalues[0] = tile_org;
finalvalues[1] = w_org;
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 592fe3a0c..d04ad1a70 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -148,15 +148,14 @@ bool CheckBridge_Stuff(byte bridge_type, int bridge_len)
{
int max; // max possible length of a bridge (with patch 100)
- if (_bridge_available_year[bridge_type] > _cur_year)
- return false;
+ if (bridge_type >= MAX_BRIDGES) return false;
+ if (_bridge_available_year[bridge_type] > _cur_year) return false;
max = _bridge_maxlen[bridge_type];
if (max >= 16 && _patches.longbridges)
max = 100;
- if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max)
- return false;
+ if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max) return false;
return true;
}
@@ -186,8 +185,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
bridge_type = p2 & 0xFF;
railtype = (byte)(p2 >> 8);
- /* Out of bounds bridge */
- if (bridge_type >= MAX_BRIDGES) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
+ if (p1 > MapSize()) return CMD_ERROR;
// type of bridge
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
@@ -220,6 +218,10 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} else
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
+ /* set and test bridge length, availability */
+ bridge_len = ((sx + sy - x - y) >> 4) - 1;
+ if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
+
/* retrieve landscape height and ensure it's on land */
if (
((FindLandscapeHeight(&ti_end, sx, sy),
@@ -246,8 +248,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// Towns are not allowed to use bridges on slopes.
allow_on_slopes = ((!_is_ai_player || _patches.ainew_active)
- && _current_player != OWNER_TOWN
- && _patches.build_on_slopes);
+ && _current_player != OWNER_TOWN && _patches.build_on_slopes);
/* Try and clear the start landscape */
@@ -295,17 +296,14 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
);
}
- /* set various params */
- bridge_len = ((sx + sy - x - y) >> 4) - 1;
-
- //position of middle part of the odd bridge (larger than MAX(i) otherwise)
- odd_middle_part=(bridge_len%2)?(bridge_len/2):bridge_len;
+ // position of middle part of the odd bridge (larger than MAX(i) otherwise)
+ odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len;
- for(i = 0; i != bridge_len; i++) {
- if (direction != 0)
- y+=16;
- else
- x+=16;
+ for (i = 0; i != bridge_len; i++) {
+ if (direction != 0) {
+ y += 16;
+ } else
+ x += 16;
FindLandscapeHeight(&ti, x, y);