summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2012-04-08 17:29:00 +0000
committeralberth <alberth@openttd.org>2012-04-08 17:29:00 +0000
commit2911732841da752417c06dfd7b0db3d26146d0a3 (patch)
tree4deed4e7838168b8bddb517cf7f0c4d2b948336a /src
parenta01948dbf31f377d7161400125eb62e2d3463442 (diff)
downloadopenttd-2911732841da752417c06dfd7b0db3d26146d0a3.tar.xz
(svn r24104) -Codechange: Output the resulting tile through the user data.
Diffstat (limited to 'src')
-rw-r--r--src/town_cmd.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 2dba67c20..ec0f474d7 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2717,14 +2717,23 @@ static bool TryClearTile(TileIndex tile)
return r.Succeeded();
}
+/** Structure for storing data while searching the best place to build a statue. */
+struct StatueBuildSearchData {
+ TileIndex best_position; ///< Best position found so far.
+
+ StatueBuildSearchData(TileIndex best_pos) : best_position(best_pos) { }
+};
+
/**
- * Search callback function for TownActionBuildStatue.
+ * Search callback function for #TownActionBuildStatue.
* @param tile Tile on which to perform the search.
- * @param user_data Unused.
+ * @param user_data Reference to the statue search data.
* @return Result of the test.
*/
static bool SearchTileForStatue(TileIndex tile, void *user_data)
{
+ StatueBuildSearchData *statue_data = (StatueBuildSearchData *)user_data;
+
/* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */
if (IsSteepSlope(GetTileSlope(tile))) return false;
/* Don't build statues under bridges. */
@@ -2732,11 +2741,13 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data)
/* A clear-able open space is always preferred. */
if ((IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) && TryClearTile(tile)) {
+ statue_data->best_position = tile;
return true;
}
bool house = IsTileType(tile, MP_HOUSE);
+ statue_data->best_position = tile; // Is optimistic, the condition below must also hold.
return house && TryClearTile(tile);
}
@@ -2752,15 +2763,16 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS);
TileIndex tile = t->xy;
- if (!CircularTileSearch(&tile, 9, SearchTileForStatue, NULL)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE);
+ StatueBuildSearchData statue_data(INVALID_TILE);
+ if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE);
if (flags & DC_EXEC) {
Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
- DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
cur_company.Restore();
- BuildObject(OBJECT_STATUE, tile, _current_company, t);
+ BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t);
SetBit(t->statues, _current_company); // Once found and built, "inform" the Town.
- MarkTileDirtyByTile(tile);
+ MarkTileDirtyByTile(statue_data.best_position);
}
return CommandCost();
}