diff --git a/src/command.cpp b/src/command.cpp --- a/src/command.cpp +++ b/src/command.cpp @@ -17,7 +17,6 @@ #include "strings_func.h" #include "gfx_func.h" #include "functions.h" -#include "town.h" const char *_cmd_text = NULL; @@ -389,7 +388,7 @@ byte GetCommandFlags(uint cmd) return _command_proc_table[cmd & 0xFF].flags; } -static int _docommand_recursive = 0; +static int _docommand_recursive; /*! * This function executes a given command with the parameters from the #CommandProc parameter list. @@ -421,9 +420,7 @@ CommandCost DoCommand(TileIndex tile, ui /* only execute the test call if it's toplevel, or we're not execing. */ if (_docommand_recursive == 1 || !(flags & DC_EXEC) || (flags & DC_FORCETEST) ) { - SetTownRatingTestMode(true); res = proc(tile, flags & ~DC_EXEC, p1, p2); - SetTownRatingTestMode(false); if (CmdFailed(res)) { res.SetGlobalErrorMessage(); goto error; @@ -557,7 +554,7 @@ bool DoCommandP(TileIndex tile, uint32 p (cmd & 0xFF) == CMD_REMOVE_ROAD || (cmd & 0xFF) == CMD_REMOVE_LONG_ROAD || (cmd & 0xFF) == CMD_CLONE_VEHICLE; - notest = false; + _docommand_recursive = 1; /* cost estimation only? */ @@ -584,9 +581,7 @@ bool DoCommandP(TileIndex tile, uint32 p if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) { /* first test if the command can be executed. */ - SetTownRatingTestMode(true); res = proc(tile, flags, p1, p2); - SetTownRatingTestMode(false); if (CmdFailed(res)) { res.SetGlobalErrorMessage(); goto show_error; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -201,8 +201,9 @@ CommandCost CmdRemoveRoad(TileIndex tile c &= present; if (c == ROAD_NONE) return CMD_ERROR; - ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); if (flags & DC_EXEC) { + ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); + present ^= c; if (present == ROAD_NONE) { RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt)); @@ -235,11 +236,11 @@ CommandCost CmdRemoveRoad(TileIndex tile * we can't draw the crossing without trambits ;) */ if (rt == ROADTYPE_ROAD && HasBit(GetRoadTypes(tile), ROADTYPE_TRAM) && ((flags & DC_EXEC) || !HasBit(p1, 6))) return CMD_ERROR; - if (rt == ROADTYPE_ROAD) { - ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); - } + if (flags & DC_EXEC) { + if (rt == ROADTYPE_ROAD) { + ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); + } - if (flags & DC_EXEC) { RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt)); if (rts == ROADTYPES_NONE) { MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile)); diff --git a/src/town.h b/src/town.h --- a/src/town.h +++ b/src/town.h @@ -109,7 +109,6 @@ struct Town : PoolItemtest_rating = t->ratings[_current_player]; - } - ref_count++; - } else { - assert(ref_count > 0); - ref_count--; - } - _town_rating_test = !(ref_count == 0); -} void ChangeTownRating(Town *t, int add, int max) { @@ -2292,7 +2275,7 @@ void ChangeTownRating(Town *t, int add, SetBit(t->have_ratings, _current_player); - rating = _town_rating_test ? t->test_rating : t->ratings[_current_player]; + rating = t->ratings[_current_player]; if (add < 0) { if (rating > max) { @@ -2305,11 +2288,7 @@ void ChangeTownRating(Town *t, int add, if (rating > max) rating = max; } } - if (_town_rating_test) { - t->test_rating = rating; - } else { - t->ratings[_current_player] = rating; - } + t->ratings[_current_player] = rating; } /* penalty for removing town-owned stuff */ @@ -2334,7 +2313,7 @@ bool CheckforTownRating(uint32 flags, To */ modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type]; - if ((_town_rating_test ? t->test_rating : t->ratings[_current_player]) < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) { + if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) { SetDParam(0, t->index); _error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; return false; diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -330,16 +330,16 @@ CommandCost CmdPlantTree(TileIndex tile, default: break; } - if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) { - Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority); - if (t != NULL) - ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); - } - if (flags & DC_EXEC) { TreeType treetype; uint growth; + if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) { + Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority); + if (t != NULL) + ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); + } + treetype = (TreeType)p1; if (treetype == TREE_INVALID) { treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); @@ -488,7 +488,7 @@ static CommandCost ClearTile_Trees(TileI { uint num; - if (IsValidPlayer(_current_player)) { + if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) { Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority); if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -599,16 +599,16 @@ static CommandCost DoClearTunnel(TileInd } } - /* Adjust the town's player rating. Do this before removing the tile owner info. */ - if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) - ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); - if (flags & DC_EXEC) { /* We first need to request the direction before calling DoClearSquare * else the direction is always 0.. dah!! ;) */ DiagDirection dir = GetTunnelBridgeDirection(tile); Track track; + /* Adjust the town's player rating. Do this before removing the tile owner info. */ + if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) + ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); + DoClearSquare(tile); DoClearSquare(endtile); UpdateSignalsOnSegment(tile, ReverseDiagDir(dir)); @@ -650,15 +650,15 @@ static CommandCost DoClearBridge(TileInd } } - /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until - * you have a "Poor" (0) town rating */ - if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) - ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); - if (flags & DC_EXEC) { TileIndex c; Track track; + /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until + * you have a "Poor" (0) town rating */ + if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) + ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); + DoClearSquare(tile); DoClearSquare(endtile); for (c = tile + delta; c != endtile; c += delta) {