src/water_cmd.cpp
branchnoai
changeset 9694 e72987579514
parent 9686 d3c195c226f9
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
    26 #include "train.h"
    26 #include "train.h"
    27 #include "roadveh.h"
    27 #include "roadveh.h"
    28 #include "water_map.h"
    28 #include "water_map.h"
    29 #include "newgrf.h"
    29 #include "newgrf.h"
    30 #include "newgrf_canal.h"
    30 #include "newgrf_canal.h"
       
    31 #include "misc/autoptr.hpp"
    31 
    32 
    32 static const SpriteID _water_shore_sprites[] = {
    33 static const SpriteID _water_shore_sprites[] = {
    33 	0,
    34 	0,
    34 	SPR_SHORE_TILEH_1,
    35 	SPR_SHORE_TILEH_1,
    35 	SPR_SHORE_TILEH_2,
    36 	SPR_SHORE_TILEH_2,
    60 CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    61 CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    61 {
    62 {
    62 	TileIndex tile2;
    63 	TileIndex tile2;
    63 
    64 
    64 	CommandCost cost, ret;
    65 	CommandCost cost, ret;
    65 	Depot *depot;
       
    66 
    66 
    67 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    67 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    68 
    68 
    69 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    69 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    70 
    70 
    81 	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
    81 	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
    82 	if (CmdFailed(ret)) return CMD_ERROR;
    82 	if (CmdFailed(ret)) return CMD_ERROR;
    83 	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
    83 	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
    84 	if (CmdFailed(ret)) return CMD_ERROR;
    84 	if (CmdFailed(ret)) return CMD_ERROR;
    85 
    85 
    86 	depot = AllocateDepot();
    86 	Depot *depot = new Depot(tile);
    87 	if (depot == NULL) return CMD_ERROR;
    87 	if (depot == NULL) return CMD_ERROR;
       
    88 	AutoPtrT<Depot> d_auto_delete = depot;
    88 
    89 
    89 	if (flags & DC_EXEC) {
    90 	if (flags & DC_EXEC) {
    90 		depot->xy = tile;
       
    91 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
    91 		depot->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
    92 
    92 
    93 		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis);
    93 		MakeShipDepot(tile,  _current_player, DEPOT_NORTH, axis);
    94 		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis);
    94 		MakeShipDepot(tile2, _current_player, DEPOT_SOUTH, axis);
    95 		MarkTileDirtyByTile(tile);
    95 		MarkTileDirtyByTile(tile);
    96 		MarkTileDirtyByTile(tile2);
    96 		MarkTileDirtyByTile(tile2);
       
    97 		d_auto_delete.Detach();
    97 	}
    98 	}
    98 
    99 
    99 	return cost.AddCost(_price.build_ship_depot);
   100 	return cost.AddCost(_price.build_ship_depot);
   100 }
   101 }
   101 
   102 
   111 
   112 
   112 	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
   113 	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
   113 
   114 
   114 	if (flags & DC_EXEC) {
   115 	if (flags & DC_EXEC) {
   115 		/* Kill the depot, which is registered at the northernmost tile. Use that one */
   116 		/* Kill the depot, which is registered at the northernmost tile. Use that one */
   116 		DeleteDepot(GetDepotByTile(tile2 < tile ? tile2 : tile));
   117 		delete GetDepotByTile(tile2 < tile ? tile2 : tile);
   117 
   118 
   118 		MakeWater(tile);
   119 		MakeWater(tile);
   119 		MakeWater(tile2);
   120 		MakeWater(tile2);
   120 		MarkTileDirtyByTile(tile);
   121 		MarkTileDirtyByTile(tile);
   121 		MarkTileDirtyByTile(tile2);
   122 		MarkTileDirtyByTile(tile2);
   439 	image = wdts++->image;
   440 	image = wdts++->image;
   440 	if (image < 4) image += water_base;
   441 	if (image < 4) image += water_base;
   441 	DrawGroundSprite(image, PAL_NONE);
   442 	DrawGroundSprite(image, PAL_NONE);
   442 
   443 
   443 	for (; wdts->delta_x != 0x80; wdts++) {
   444 	for (; wdts->delta_x != 0x80; wdts++) {
   444 		SpriteID image = wdts->image;
   445 		AddSortableSpriteToDraw(wdts->image + base + ((wdts->image < 24) ? locks_base : 0), palette,
   445 		SpriteID pal;
       
   446 
       
   447 		if (image < 24) image += locks_base;
       
   448 		image += base;
       
   449 
       
   450 		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   451 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   452 			pal = PALETTE_TO_TRANSPARENT;
       
   453 		} else {
       
   454 			pal = palette;
       
   455 		}
       
   456 
       
   457 		AddSortableSpriteToDraw(image, pal,
       
   458 			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
   446 			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
   459 			wdts->width, wdts->height,
   447 			wdts->width, wdts->height,
   460 			wdts->unk, ti->z + wdts->delta_z);
   448 			wdts->unk, ti->z + wdts->delta_z,
       
   449 			HASBIT(_transparent_opt, TO_BUILDINGS));
   461 	}
   450 	}
   462 }
   451 }
   463 
   452 
   464 static void DrawTile_Water(TileInfo *ti)
   453 static void DrawTile_Water(TileInfo *ti)
   465 {
   454 {
   510 	Slope tileh = GetTileSlope(tile, &z);
   499 	Slope tileh = GetTileSlope(tile, &z);
   511 
   500 
   512 	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
   501 	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
   513 }
   502 }
   514 
   503 
   515 static Slope GetSlopeTileh_Water(TileIndex tile, Slope tileh)
   504 static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
   516 {
   505 {
   517 	return tileh;
   506 	return FOUNDATION_NONE;
   518 }
   507 }
   519 
   508 
   520 static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
   509 static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
   521 {
   510 {
   522 	/* not used */
   511 	/* not used */
   822 	AnimateTile_Water,        /* animate_tile_proc */
   811 	AnimateTile_Water,        /* animate_tile_proc */
   823 	TileLoop_Water,           /* tile_loop_clear */
   812 	TileLoop_Water,           /* tile_loop_clear */
   824 	ChangeTileOwner_Water,    /* change_tile_owner_clear */
   813 	ChangeTileOwner_Water,    /* change_tile_owner_clear */
   825 	NULL,                     /* get_produced_cargo_proc */
   814 	NULL,                     /* get_produced_cargo_proc */
   826 	VehicleEnter_Water,       /* vehicle_enter_tile_proc */
   815 	VehicleEnter_Water,       /* vehicle_enter_tile_proc */
   827 	GetSlopeTileh_Water,      /* get_slope_tileh_proc */
   816 	GetFoundation_Water,      /* get_foundation_proc */
   828 };
   817 };