From 893e405af09ed97261ff25de195b4bd6825bc8f6 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 17 Apr 2010 23:34:00 +0000 Subject: (svn r19668) -Codechange: Use WaterClass in parameters of CMD_BUILD_CANAL. --- src/ai/api/ai_marine.cpp | 2 +- src/dock_gui.cpp | 5 +++-- src/water_cmd.cpp | 31 ++++++++++++++++++++----------- src/water_map.h | 1 + 4 files changed, 25 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ai/api/ai_marine.cpp b/src/ai/api/ai_marine.cpp index 07de889da..0e2e26a8a 100644 --- a/src/ai/api/ai_marine.cpp +++ b/src/ai/api/ai_marine.cpp @@ -108,7 +108,7 @@ { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, tile, 0, CMD_BUILD_CANAL); + return AIObject::DoCommand(tile, tile, WATER_CLASS_CANAL, CMD_BUILD_CANAL); } /* static */ bool AIMarine::RemoveWaterDepot(TileIndex tile) diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 1b2336ef8..935e5a16a 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -17,6 +17,7 @@ #include "station_gui.h" #include "command_func.h" #include "water.h" +#include "water_map.h" #include "window_func.h" #include "vehicle_func.h" #include "sound_func.h" @@ -225,10 +226,10 @@ struct BuildDocksToolbarWindow : Window { GUIPlaceProcDragXY(select_proc, start_tile, end_tile); break; case DDSP_CREATE_WATER: - DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR ? _ctrl_pressed : 0), CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcBuildCanal); + DoCommandP(end_tile, start_tile, (_game_mode == GM_EDITOR && _ctrl_pressed) ? WATER_CLASS_SEA : WATER_CLASS_CANAL, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_BUILD_CANALS), CcBuildCanal); break; case DDSP_CREATE_RIVER: - DoCommandP(end_tile, start_tile, 2, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal); + DoCommandP(end_tile, start_tile, WATER_CLASS_RIVER, CMD_BUILD_CANAL | CMD_MSG(STR_ERROR_CAN_T_PLACE_RIVERS), CcBuildCanal); break; default: break; diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 805f46d29..d659398df 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -285,16 +285,17 @@ CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 * @param tile end tile of stretch-dragging * @param flags type of operation * @param p1 start tile of stretch-dragging - * @param p2 specifies canal (0), water (1) or river (2); last two can only be built in scenario editor + * @param p2 waterclass to build. sea and river can only be built in scenario editor * @param text unused * @return the cost of this operation or an error */ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - if (p1 >= MapSize() || p2 > 2) return CMD_ERROR; + WaterClass wc = Extract(p2); + if (p1 >= MapSize() || wc == WATER_CLASS_INVALID) return CMD_ERROR; /* Outside of the editor you can only build canals, not oceans */ - if (p2 != 0 && _game_mode != GM_EDITOR) return CMD_ERROR; + if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR; TileArea ta(tile, p1); @@ -306,24 +307,32 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 CommandCost ret; Slope slope = GetTileSlope(tile, NULL); - if (slope != SLOPE_FLAT && (p2 != 2 || !IsInclinedSlope(slope))) { + if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) { return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); } /* can't make water of water! */ - if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue; + if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue; ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; cost.AddCost(ret); if (flags & DC_EXEC) { - if (TileHeight(tile) == 0 && p2 == 1) { - MakeSea(tile); - } else if (p2 == 2) { - MakeRiver(tile, Random()); - } else { - MakeCanal(tile, _current_company, Random()); + switch (wc) { + case WATER_CLASS_RIVER: + MakeRiver(tile, Random()); + break; + + case WATER_CLASS_SEA: + if (TileHeight(tile) == 0) { + MakeSea(tile); + break; + } + /* FALL THROUGH */ + default: + MakeCanal(tile, _current_company, Random()); + break; } MarkTileDirtyByTile(tile); MarkCanalsAndRiversAroundDirty(tile); diff --git a/src/water_map.h b/src/water_map.h index 519326269..87267a7b9 100644 --- a/src/water_map.h +++ b/src/water_map.h @@ -29,6 +29,7 @@ enum WaterClass { WATER_CLASS_RIVER, WATER_CLASS_INVALID, ///< Used for industry tiles on land (also for oilrig if newgrf says so) }; +template <> struct EnumPropsT : MakeEnumPropsT {}; enum DepotPart { DEPOT_NORTH = 0x80, -- cgit v1.2.3-70-g09d2