landscape.c
changeset 3491 35d747bb5e82
parent 3447 1c62c085638a
child 3493 c77bcf04294d
equal deleted inserted replaced
3490:d53bc3e794bd 3491:35d747bb5e82
   270 {
   270 {
   271 	_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
   271 	_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
   272 }
   272 }
   273 
   273 
   274 /** Clear a piece of landscape
   274 /** Clear a piece of landscape
   275  * @param x,y coordinates of clearance
   275  * @param tile tile to clear
   276  * @param p1 unused
   276  * @param p1 unused
   277  * @param p2 unused
   277  * @param p2 unused
   278  */
   278  */
   279 int32 CmdLandscapeClear(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   279 int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   280 {
   280 {
   281 	TileIndex tile = TileVirtXY(x, y);
       
   282 
       
   283 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   281 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   284 
   282 
   285 	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
   283 	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
   286 }
   284 }
   287 
   285 
   288 /** Clear a big piece of landscape
   286 /** Clear a big piece of landscape
   289  * @param x,y end coordinates of area dragging
   287  * @param tile end tile of area dragging
   290  * @param p1 start tile of area dragging
   288  * @param p1 start tile of area dragging
   291  * @param p2 unused
   289  * @param p2 unused
   292  */
   290  */
   293 int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   291 int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   294 {
   292 {
   295 	int32 cost, ret, money;
   293 	int32 cost, ret, money;
       
   294 	int ex;
       
   295 	int ey;
   296 	int sx,sy;
   296 	int sx,sy;
   297 	int x,y;
   297 	int x,y;
   298 	bool success = false;
   298 	bool success = false;
   299 
   299 
   300 	if (p1 >= MapSize()) return CMD_ERROR;
   300 	if (p1 >= MapSize()) return CMD_ERROR;
   301 
   301 
   302 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   302 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   303 
   303 
   304 	// make sure sx,sy are smaller than ex,ey
   304 	// make sure sx,sy are smaller than ex,ey
       
   305 	ex = TileX(tile) * TILE_SIZE;
       
   306 	ey = TileY(tile) * TILE_SIZE;
   305 	sx = TileX(p1) * TILE_SIZE;
   307 	sx = TileX(p1) * TILE_SIZE;
   306 	sy = TileY(p1) * TILE_SIZE;
   308 	sy = TileY(p1) * TILE_SIZE;
   307 	if (ex < sx) intswap(ex, sx);
   309 	if (ex < sx) intswap(ex, sx);
   308 	if (ey < sy) intswap(ey, sy);
   310 	if (ey < sy) intswap(ey, sy);
   309 
   311 
   310 	money = GetAvailableMoneyForCommand();
   312 	money = GetAvailableMoneyForCommand();
   311 	cost = 0;
   313 	cost = 0;
   312 
   314 
   313 	for (x = sx; x <= ex; x += TILE_SIZE) {
   315 	for (x = sx; x <= ex; x += TILE_SIZE) {
   314 		for (y = sy; y <= ey; y += TILE_SIZE) {
   316 		for (y = sy; y <= ey; y += TILE_SIZE) {
   315 			ret = DoCommandByTile(TileVirtXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
   317 			ret = DoCommand(TileVirtXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
   316 			if (CmdFailed(ret)) continue;
   318 			if (CmdFailed(ret)) continue;
   317 			cost += ret;
   319 			cost += ret;
   318 			success = true;
   320 			success = true;
   319 
   321 
   320 			if (flags & DC_EXEC) {
   322 			if (flags & DC_EXEC) {
   321 				if (ret > 0 && (money -= ret) < 0) {
   323 				if (ret > 0 && (money -= ret) < 0) {
   322 					_additional_cash_required = ret;
   324 					_additional_cash_required = ret;
   323 					return cost - ret;
   325 					return cost - ret;
   324 				}
   326 				}
   325 				DoCommandByTile(TileVirtXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   327 				DoCommand(TileVirtXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   326 
   328 
   327 				// draw explosion animation...
   329 				// draw explosion animation...
   328 				if ((x == sx || x == ex) && (y == sy || y == ey)) {
   330 				if ((x == sx || x == ex) && (y == sy || y == ey)) {
   329 					// big explosion in each corner, or small explosion for single tiles
   331 					// big explosion in each corner, or small explosion for single tiles
   330 					CreateEffectVehicleAbove(x + 8, y + 8, 2,
   332 					CreateEffectVehicleAbove(x + 8, y + 8, 2,