mirror of https://github.com/OpenTTD/OpenTTD
(svn r19420) -Codechange: Don't use _error_message to keep track of success/failure, use a had_success boolean.
parent
28b0a3e335
commit
05e549ccdc
|
@ -760,16 +760,20 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
||||||
|
|
||||||
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
|
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
|
||||||
|
|
||||||
|
bool had_success = false;
|
||||||
|
CommandCost last_error = CMD_ERROR;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
CommandCost ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
CommandCost ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
||||||
|
|
||||||
if (ret.Failed()) {
|
if (ret.Failed()) {
|
||||||
if (_error_message != STR_ERROR_ALREADY_BUILT && !remove) {
|
last_error = ret;
|
||||||
if (HasBit(p2, 8)) return CMD_ERROR;
|
last_error.SetGlobalErrorMessage();
|
||||||
|
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
|
||||||
|
if (HasBit(p2, 8)) return last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_error_message = INVALID_STRING_ID;
|
|
||||||
} else {
|
} else {
|
||||||
|
had_success = true;
|
||||||
total_cost.AddCost(ret);
|
total_cost.AddCost(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,7 +785,9 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
||||||
if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
|
if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (total_cost.GetCost() == 0) ? CommandCost(remove ? INVALID_STRING_ID : (_error_message == INVALID_STRING_ID ? STR_ERROR_ALREADY_BUILT : _error_message)) : total_cost;
|
if (had_success) return total_cost;
|
||||||
|
if (remove) return CMD_ERROR;
|
||||||
|
return last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build rail on a stretch of track.
|
/** Build rail on a stretch of track.
|
||||||
|
@ -1128,7 +1134,6 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
|
||||||
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||||
bool err = true;
|
|
||||||
TileIndex start_tile = tile;
|
TileIndex start_tile = tile;
|
||||||
|
|
||||||
Track track = (Track)GB(p2, 0, 3);
|
Track track = (Track)GB(p2, 0, 3);
|
||||||
|
@ -1191,6 +1196,8 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
||||||
* and convert all others to semaphore/signal
|
* and convert all others to semaphore/signal
|
||||||
* remove - 1 remove signals, 0 build signals */
|
* remove - 1 remove signals, 0 build signals */
|
||||||
int signal_ctr = 0;
|
int signal_ctr = 0;
|
||||||
|
CommandCost last_error = CMD_ERROR;
|
||||||
|
bool had_success = false;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* only build/remove signals with the specified density */
|
/* only build/remove signals with the specified density */
|
||||||
if ((remove && autofill) || signal_ctr % signal_density == 0) {
|
if ((remove && autofill) || signal_ctr % signal_density == 0) {
|
||||||
|
@ -1209,8 +1216,11 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
||||||
|
|
||||||
/* Be user-friendly and try placing signals as much as possible */
|
/* Be user-friendly and try placing signals as much as possible */
|
||||||
if (ret.Succeeded()) {
|
if (ret.Succeeded()) {
|
||||||
err = false;
|
had_success = true;
|
||||||
total_cost.AddCost(ret);
|
total_cost.AddCost(ret);
|
||||||
|
} else {
|
||||||
|
last_error = ret;
|
||||||
|
last_error.SetGlobalErrorMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1234,7 +1244,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err ? CMD_ERROR : total_cost;
|
return had_success ? total_cost : last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build signals on a stretch of track.
|
/** Build signals on a stretch of track.
|
||||||
|
|
|
@ -728,14 +728,8 @@ do_clear:;
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
||||||
bool had_bridge = false;
|
|
||||||
bool had_tunnel = false;
|
|
||||||
bool had_success = false;
|
|
||||||
DisallowedRoadDirections drd = DRD_NORTHBOUND;
|
DisallowedRoadDirections drd = DRD_NORTHBOUND;
|
||||||
|
|
||||||
_error_message = INVALID_STRING_ID;
|
|
||||||
|
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
|
||||||
TileIndex end_tile = p1;
|
TileIndex end_tile = p1;
|
||||||
|
@ -763,7 +757,12 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
|
||||||
/* No disallowed direction bits have to be toggled */
|
/* No disallowed direction bits have to be toggled */
|
||||||
if (!HasBit(p2, 5)) drd = DRD_NONE;
|
if (!HasBit(p2, 5)) drd = DRD_NONE;
|
||||||
|
|
||||||
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||||
|
CommandCost last_error = CMD_ERROR;
|
||||||
TileIndex tile = start_tile;
|
TileIndex tile = start_tile;
|
||||||
|
bool had_bridge = false;
|
||||||
|
bool had_tunnel = false;
|
||||||
|
bool had_success = false;
|
||||||
/* Start tile is the first tile clicked by the user. */
|
/* Start tile is the first tile clicked by the user. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
RoadBits bits = AxisToRoadBits(axis);
|
RoadBits bits = AxisToRoadBits(axis);
|
||||||
|
@ -772,11 +771,12 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
|
||||||
if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
|
if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
|
||||||
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
|
if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
|
||||||
|
|
||||||
_error_message = INVALID_STRING_ID;
|
|
||||||
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
||||||
if (ret.Failed()) {
|
if (ret.Failed()) {
|
||||||
if (_error_message != STR_ERROR_ALREADY_BUILT) {
|
last_error = ret;
|
||||||
if (HasBit(p2, 6)) return CMD_ERROR;
|
last_error.SetGlobalErrorMessage();
|
||||||
|
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
|
||||||
|
if (HasBit(p2, 6)) return last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -804,7 +804,7 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
|
||||||
tile += TileOffsByDiagDir(dir);
|
tile += TileOffsByDiagDir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !had_success ? CMD_ERROR : cost;
|
return had_success ? cost : last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a long piece of road.
|
/** Remove a long piece of road.
|
||||||
|
|
Loading…
Reference in New Issue