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

pull/155/head
frosch 14 years ago
parent 74d7b676f2
commit 099f734be9

@ -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)

@ -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;

@ -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<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 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);

@ -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<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
enum DepotPart {
DEPOT_NORTH = 0x80,

Loading…
Cancel
Save