src/clear_cmd.cpp
changeset 6123 04eb770ec17e
parent 6106 2898cd9417fd
child 6160 fa42299e967e
equal deleted inserted replaced
6122:3359af5a1f54 6123:04eb770ec17e
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file clear_cmd.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "clear_map.h"
     7 #include "clear_map.h"
     6 #include "rail_map.h"
     8 #include "rail_map.h"
   105 		static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E };
   107 		static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E };
   106 
   108 
   107 		Slope tileh;
   109 		Slope tileh;
   108 		uint z;
   110 		uint z;
   109 
   111 
   110 		// Nothing could be built at the steep slope - this avoids a bug
   112 		/* Nothing could be built at the steep slope - this avoids a bug
   111 		// when you have a single diagonal track in one corner on a
   113 		 * when you have a single diagonal track in one corner on a
   112 		// basement and then you raise/lower the other corner.
   114 		 * basement and then you raise/lower the other corner. */
   113 		tileh = GetTileSlope(tile, &z);
   115 		tileh = GetTileSlope(tile, &z);
   114 		if (tileh == unsafe_slope[mode] ||
   116 		if (tileh == unsafe_slope[mode] ||
   115 				tileh == ComplementSlope(unsafe_slope[mode])) {
   117 				tileh == ComplementSlope(unsafe_slope[mode])) {
   116 			_terraform_err_tile = tile;
   118 			_terraform_err_tile = tile;
   117 			_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
   119 			_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
   118 			return -1;
   120 			return -1;
   119 		}
   121 		}
   120 
   122 
   121 		// If we have a single diagonal track there, the other side of
   123 		/* If we have a single diagonal track there, the other side of
   122 		// tile can be terraformed.
   124 		 * tile can be terraformed. */
   123 		if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) {
   125 		if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) {
   124 			/* If terraforming downwards prevent damaging a potential tunnel below.
   126 			/* If terraforming downwards prevent damaging a potential tunnel below.
   125 			 * This check is only necessary for flat tiles, because if the tile is
   127 			 * This check is only necessary for flat tiles, because if the tile is
   126 			 * non-flat, then the corner opposing the rail is raised. Only this corner
   128 			 * non-flat, then the corner opposing the rail is raised. Only this corner
   127 			 * can be lowered and this is a safe action
   129 			 * can be lowered and this is a safe action
   221 	return true;
   223 	return true;
   222 }
   224 }
   223 
   225 
   224 /** Terraform land
   226 /** Terraform land
   225  * @param tile tile to terraform
   227  * @param tile tile to terraform
       
   228  * @param flags for this command type
   226  * @param p1 corners to terraform.
   229  * @param p1 corners to terraform.
   227  * @param p2 direction; eg up or down
   230  * @param p2 direction; eg up or down
       
   231  * @return error or cost of terraforming
   228  */
   232  */
   229 int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   233 int32 CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   230 {
   234 {
   231 	TerraformerState ts;
   235 	TerraformerState ts;
   232 	TileIndex t;
   236 	TileIndex t;
   344 }
   348 }
   345 
   349 
   346 
   350 
   347 /** Levels a selected (rectangle) area of land
   351 /** Levels a selected (rectangle) area of land
   348  * @param tile end tile of area-drag
   352  * @param tile end tile of area-drag
       
   353  * @param flags for this command type
   349  * @param p1 start tile of area drag
   354  * @param p1 start tile of area drag
   350  * @param p2 unused
   355  * @param p2 unused
       
   356  * @return  error or cost of terraforming
   351  */
   357  */
   352 int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   358 int32 CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   353 {
   359 {
   354 	int size_x, size_y;
   360 	int size_x, size_y;
   355 	int ex;
   361 	int ex;
   360 
   366 
   361 	if (p1 >= MapSize()) return CMD_ERROR;
   367 	if (p1 >= MapSize()) return CMD_ERROR;
   362 
   368 
   363 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   369 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   364 
   370 
   365 	// remember level height
   371 	/* remember level height */
   366 	h = TileHeight(p1);
   372 	h = TileHeight(p1);
   367 
   373 
   368 	// make sure sx,sy are smaller than ex,ey
   374 	/* make sure sx,sy are smaller than ex,ey */
   369 	ex = TileX(tile);
   375 	ex = TileX(tile);
   370 	ey = TileY(tile);
   376 	ey = TileY(tile);
   371 	sx = TileX(p1);
   377 	sx = TileX(p1);
   372 	sy = TileY(p1);
   378 	sy = TileY(p1);
   373 	if (ex < sx) Swap(ex, sx);
   379 	if (ex < sx) Swap(ex, sx);
   403 }
   409 }
   404 
   410 
   405 /** Purchase a land area. Actually you only purchase one tile, so
   411 /** Purchase a land area. Actually you only purchase one tile, so
   406  * the name is a bit confusing ;p
   412  * the name is a bit confusing ;p
   407  * @param tile the tile the player is purchasing
   413  * @param tile the tile the player is purchasing
       
   414  * @param flags for this command type
   408  * @param p1 unused
   415  * @param p1 unused
   409  * @param p2 unused
   416  * @param p2 unused
       
   417  * @return error of cost of operation
   410  */
   418  */
   411 int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   419 int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   412 {
   420 {
   413 	int32 cost;
   421 	int32 cost;
   414 
   422 
   457 }
   465 }
   458 
   466 
   459 /** Sell a land area. Actually you only sell one tile, so
   467 /** Sell a land area. Actually you only sell one tile, so
   460  * the name is a bit confusing ;p
   468  * the name is a bit confusing ;p
   461  * @param tile the tile the player is selling
   469  * @param tile the tile the player is selling
       
   470  * @param flags for this command type
   462  * @param p1 unused
   471  * @param p1 unused
   463  * @param p2 unused
   472  * @param p2 unused
       
   473  * @return error or cost of operation
   464  */
   474  */
   465 int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   475 int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   466 {
   476 {
   467 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   477 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   468 
   478 
   785 {
   795 {
   786 	_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT;
   796 	_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT;
   787 }
   797 }
   788 
   798 
   789 extern const TileTypeProcs _tile_type_clear_procs = {
   799 extern const TileTypeProcs _tile_type_clear_procs = {
   790 	DrawTile_Clear,           /* draw_tile_proc */
   800 	DrawTile_Clear,           ///< draw_tile_proc
   791 	GetSlopeZ_Clear,          /* get_slope_z_proc */
   801 	GetSlopeZ_Clear,          ///< get_slope_z_proc
   792 	ClearTile_Clear,          /* clear_tile_proc */
   802 	ClearTile_Clear,          ///< clear_tile_proc
   793 	GetAcceptedCargo_Clear,   /* get_accepted_cargo_proc */
   803 	GetAcceptedCargo_Clear,   ///< get_accepted_cargo_proc
   794 	GetTileDesc_Clear,        /* get_tile_desc_proc */
   804 	GetTileDesc_Clear,        ///< get_tile_desc_proc
   795 	GetTileTrackStatus_Clear, /* get_tile_track_status_proc */
   805 	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
   796 	ClickTile_Clear,          /* click_tile_proc */
   806 	ClickTile_Clear,          ///< click_tile_proc
   797 	AnimateTile_Clear,        /* animate_tile_proc */
   807 	AnimateTile_Clear,        ///< animate_tile_proc
   798 	TileLoop_Clear,           /* tile_loop_clear */
   808 	TileLoop_Clear,           ///< tile_loop_clear
   799 	ChangeTileOwner_Clear,    /* change_tile_owner_clear */
   809 	ChangeTileOwner_Clear,    ///< change_tile_owner_clear
   800 	NULL,                     /* get_produced_cargo_proc */
   810 	NULL,                     ///< get_produced_cargo_proc
   801 	NULL,                     /* vehicle_enter_tile_proc */
   811 	NULL,                     ///< vehicle_enter_tile_proc
   802 	GetSlopeTileh_Clear,      /* get_slope_tileh_proc */
   812 	GetSlopeTileh_Clear,      ///< get_slope_tileh_proc
   803 };
   813 };