src/landscape.cpp
branchNewGRF_ports
changeset 6720 35756db7e577
parent 6719 4cc327ad39d5
child 6743 cabfaa4a0295
equal deleted inserted replaced
6719:4cc327ad39d5 6720:35756db7e577
    20 #include "variables.h"
    20 #include "variables.h"
    21 #include "void_map.h"
    21 #include "void_map.h"
    22 #include "water_map.h"
    22 #include "water_map.h"
    23 #include "tgp.h"
    23 #include "tgp.h"
    24 #include "genworld.h"
    24 #include "genworld.h"
    25 #include "heightmap.h"
       
    26 
    25 
    27 extern const TileTypeProcs
    26 extern const TileTypeProcs
    28 	_tile_type_clear_procs,
    27 	_tile_type_clear_procs,
    29 	_tile_type_rail_procs,
    28 	_tile_type_rail_procs,
    30 	_tile_type_road_procs,
    29 	_tile_type_road_procs,
   251 		}
   250 		}
   252 	} else {
   251 	} else {
   253 		if (f < 15) {
   252 		if (f < 15) {
   254 			/* leveled foundation
   253 			/* leveled foundation
   255 			 * Use the original slope sprites if NW and NE borders should be visible */
   254 			 * Use the original slope sprites if NW and NE borders should be visible */
   256 			if (sprite_base  == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
   255 			if (sprite_base == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
   257 
   256 
   258 			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
   257 			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
   259 			ti->z += TILE_HEIGHT;
   258 			ti->z += TILE_HEIGHT;
   260 			ti->tileh = SLOPE_FLAT;
   259 			ti->tileh = SLOPE_FLAT;
   261 			OffsetGroundSprite(31, 1);
   260 			OffsetGroundSprite(31, 1);
   365  * @param tile tile to clear
   364  * @param tile tile to clear
   366  * @param flags of operation to conduct
   365  * @param flags of operation to conduct
   367  * @param p1 unused
   366  * @param p1 unused
   368  * @param p2 unused
   367  * @param p2 unused
   369  */
   368  */
   370 int32 CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   369 CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   371 {
   370 {
   372 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   371 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   373 
   372 
   374 	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
   373 	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
   375 }
   374 }
   378  * @param tile end tile of area dragging
   377  * @param tile end tile of area dragging
   379  * @param p1 start tile of area dragging
   378  * @param p1 start tile of area dragging
   380  * @param flags of operation to conduct
   379  * @param flags of operation to conduct
   381  * @param p2 unused
   380  * @param p2 unused
   382  */
   381  */
   383 int32 CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   382 CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   384 {
   383 {
   385 	int32 cost, ret, money;
   384 	CommandCost cost, ret, money;
   386 	int ex;
   385 	int ex;
   387 	int ey;
   386 	int ey;
   388 	int sx, sy;
   387 	int sx, sy;
   389 	int x, y;
   388 	int x, y;
   390 	bool success = false;
   389 	bool success = false;
   399 	sx = TileX(p1);
   398 	sx = TileX(p1);
   400 	sy = TileY(p1);
   399 	sy = TileY(p1);
   401 	if (ex < sx) Swap(ex, sx);
   400 	if (ex < sx) Swap(ex, sx);
   402 	if (ey < sy) Swap(ey, sy);
   401 	if (ey < sy) Swap(ey, sy);
   403 
   402 
   404 	money = GetAvailableMoneyForCommand();
   403 	money.AddCost(GetAvailableMoneyForCommand());
   405 	cost = 0;
       
   406 
   404 
   407 	for (x = sx; x <= ex; ++x) {
   405 	for (x = sx; x <= ex; ++x) {
   408 		for (y = sy; y <= ey; ++y) {
   406 		for (y = sy; y <= ey; ++y) {
   409 			ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
   407 			ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
   410 			if (CmdFailed(ret)) continue;
   408 			if (CmdFailed(ret)) continue;
   411 			cost += ret;
       
   412 			success = true;
   409 			success = true;
   413 
   410 
   414 			if (flags & DC_EXEC) {
   411 			if (flags & DC_EXEC) {
   415 				if (ret > 0 && (money -= ret) < 0) {
   412 				money.AddCost(-ret.GetCost());
   416 					_additional_cash_required = ret;
   413 				if (ret.GetCost() > 0 && money.GetCost() < 0) {
   417 					return cost - ret;
   414 					_additional_cash_required = ret.GetCost();
       
   415 					return cost;
   418 				}
   416 				}
   419 				DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   417 				DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   420 
   418 
   421 				/* draw explosion animation... */
   419 				/* draw explosion animation... */
   422 				if ((x == sx || x == ex) && (y == sy || y == ey)) {
   420 				if ((x == sx || x == ex) && (y == sy || y == ey)) {
   424 					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
   422 					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
   425 						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
   423 						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
   426 					);
   424 					);
   427 				}
   425 				}
   428 			}
   426 			}
       
   427 			cost.AddCost(ret);
   429 		}
   428 		}
   430 	}
   429 	}
   431 
   430 
   432 	return (success) ? cost : CMD_ERROR;
   431 	return (success) ? cost : CMD_ERROR;
   433 }
   432 }