src/water_cmd.cpp
branchcpp_gui
changeset 6268 4b5241e5dd10
parent 6253 23983700e3d7
child 6285 187e3ef04cc9
equal deleted inserted replaced
6267:7c8ec33959b1 6268:4b5241e5dd10
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
     5 #include "bridge_map.h"
     5 #include "bridge_map.h"
       
     6 #include "cmd_helper.h"
     6 #include "station_map.h"
     7 #include "station_map.h"
     7 #include "table/sprites.h"
     8 #include "table/sprites.h"
     8 #include "table/strings.h"
     9 #include "table/strings.h"
     9 #include "functions.h"
    10 #include "functions.h"
    10 #include "map.h"
    11 #include "map.h"
    43 static Vehicle *FindFloodableVehicleOnTile(TileIndex tile);
    44 static Vehicle *FindFloodableVehicleOnTile(TileIndex tile);
    44 static void FloodVehicle(Vehicle *v);
    45 static void FloodVehicle(Vehicle *v);
    45 
    46 
    46 /** Build a ship depot.
    47 /** Build a ship depot.
    47  * @param tile tile where ship depot is built
    48  * @param tile tile where ship depot is built
    48  * @param p1 depot direction (0 == X or 1 == Y)
    49  * @param p1 bit 0 depot orientation (Axis)
    49  * @param p2 unused
    50  * @param p2 unused
    50  */
    51  */
    51 int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    52 int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    52 {
    53 {
    53 	TileIndex tile2;
    54 	TileIndex tile2;
    55 	int32 cost, ret;
    56 	int32 cost, ret;
    56 	Depot *depot;
    57 	Depot *depot;
    57 
    58 
    58 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    59 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    59 
    60 
    60 	if (p1 > 1) return CMD_ERROR;
       
    61 
       
    62 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    61 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    63 
    62 
    64 	tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
    63 	Axis axis = Extract<Axis, 0>(p1);
       
    64 
       
    65 	tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
    65 	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
    66 	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
    66 
    67 
    67 	if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
    68 	if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2))
    68 		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
    69 		return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER);
    69 
    70 
    82 
    83 
    83 	if (flags & DC_EXEC) {
    84 	if (flags & DC_EXEC) {
    84 		depot->xy = tile;
    85 		depot->xy = tile;
    85 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
    86 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
    86 
    87 
    87 		MakeShipDepot(tile, _current_player, DEPOT_NORTH, (Axis)p1);
    88 		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis);
    88 		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, (Axis)p1);
    89 		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis);
    89 		MarkTileDirtyByTile(tile);
    90 		MarkTileDirtyByTile(tile);
    90 		MarkTileDirtyByTile(tile2);
    91 		MarkTileDirtyByTile(tile2);
    91 	}
    92 	}
    92 
    93 
    93 	return cost + _price.build_ship_depot;
    94 	return cost + _price.build_ship_depot;
   227 	sx = TileX(p1);
   228 	sx = TileX(p1);
   228 	sy = TileY(p1);
   229 	sy = TileY(p1);
   229 
   230 
   230 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   231 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   231 
   232 
   232 	if (x < sx) intswap(x, sx);
   233 	if (x < sx) Swap(x, sx);
   233 	if (y < sy) intswap(y, sy);
   234 	if (y < sy) Swap(y, sy);
   234 	size_x = (x - sx) + 1;
   235 	size_x = (x - sx) + 1;
   235 	size_y = (y - sy) + 1;
   236 	size_y = (y - sy) + 1;
   236 
   237 
   237 	/* Outside the editor you can only drag canals, and not areas */
   238 	/* Outside the editor you can only drag canals, and not areas */
   238 	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
   239 	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;