(svn r19668) -Codechange: Use WaterClass in parameters of CMD_BUILD_CANAL.

This commit is contained in:
frosch 2010-04-17 23:34:00 +00:00
parent 1647c2d50e
commit 893e405af0
4 changed files with 25 additions and 14 deletions

View File

@ -108,7 +108,7 @@
{ {
EnforcePrecondition(false, ::IsValidTile(tile)); 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) /* static */ bool AIMarine::RemoveWaterDepot(TileIndex tile)

View File

@ -17,6 +17,7 @@
#include "station_gui.h" #include "station_gui.h"
#include "command_func.h" #include "command_func.h"
#include "water.h" #include "water.h"
#include "water_map.h"
#include "window_func.h" #include "window_func.h"
#include "vehicle_func.h" #include "vehicle_func.h"
#include "sound_func.h" #include "sound_func.h"
@ -225,10 +226,10 @@ struct BuildDocksToolbarWindow : Window {
GUIPlaceProcDragXY(select_proc, start_tile, end_tile); GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break; break;
case DDSP_CREATE_WATER: 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; break;
case DDSP_CREATE_RIVER: 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; break;
default: break; default: break;

View File

@ -285,16 +285,17 @@ CommandCost CmdBuildLock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
* @param tile end tile of stretch-dragging * @param tile end tile of stretch-dragging
* @param flags type of operation * @param flags type of operation
* @param p1 start tile of stretch-dragging * @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 * @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) 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 */ /* 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); TileArea ta(tile, p1);
@ -306,24 +307,32 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CommandCost ret; CommandCost ret;
Slope slope = GetTileSlope(tile, NULL); 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); return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
} }
/* can't make water of water! */ /* 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); ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (TileHeight(tile) == 0 && p2 == 1) { switch (wc) {
MakeSea(tile); case WATER_CLASS_RIVER:
} else if (p2 == 2) { MakeRiver(tile, Random());
MakeRiver(tile, Random()); break;
} else {
MakeCanal(tile, _current_company, Random()); case WATER_CLASS_SEA:
if (TileHeight(tile) == 0) {
MakeSea(tile);
break;
}
/* FALL THROUGH */
default:
MakeCanal(tile, _current_company, Random());
break;
} }
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkCanalsAndRiversAroundDirty(tile); MarkCanalsAndRiversAroundDirty(tile);

View File

@ -29,6 +29,7 @@ enum WaterClass {
WATER_CLASS_RIVER, WATER_CLASS_RIVER,
WATER_CLASS_INVALID, ///< Used for industry tiles on land (also for oilrig if newgrf says so) 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 { enum DepotPart {
DEPOT_NORTH = 0x80, DEPOT_NORTH = 0x80,