changeset 15048:c2279fa6ec2e draft

(svn r19668) -Codechange: Use WaterClass in parameters of CMD_BUILD_CANAL.
author frosch <frosch@openttd.org>
date Sat, 17 Apr 2010 23:34:00 +0000
parents d75e147e98d4
children 177c89d03be1
files src/ai/api/ai_marine.cpp src/dock_gui.cpp src/water_cmd.cpp src/water_map.h
diffstat 4 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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 @@
 					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;
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -285,16 +285,17 @@
  * @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<WaterClass, 0, 2>(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 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);
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -29,6 +29,7 @@
 	WATER_CLASS_RIVER,
 	WATER_CLASS_INVALID, ///< Used for industry tiles on land (also for oilrig if newgrf says so)
 };
+template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
 
 enum DepotPart {
 	DEPOT_NORTH = 0x80,