2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/** @file road_cmd.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "bridge_map.h"
|
2007-02-26 18:25:03 +00:00
|
|
|
#include "bridge.h"
|
2007-02-24 09:42:39 +00:00
|
|
|
#include "cmd_helper.h"
|
2006-03-01 08:56:38 +00:00
|
|
|
#include "rail_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "road_map.h"
|
2006-08-06 18:36:36 +00:00
|
|
|
#include "sprite.h"
|
2005-07-04 14:58:55 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2006-03-24 12:00:24 +00:00
|
|
|
#include "town_map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "gfx.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2007-04-27 21:35:02 +00:00
|
|
|
#include "newgrf.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2006-03-31 06:16:04 +00:00
|
|
|
static uint CountRoadBits(RoadBits r)
|
|
|
|
{
|
|
|
|
uint count = 0;
|
|
|
|
|
|
|
|
if (r & ROAD_NW) ++count;
|
|
|
|
if (r & ROAD_SW) ++count;
|
|
|
|
if (r & ROAD_SE) ++count;
|
|
|
|
if (r & ROAD_NE) ++count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-05 17:24:04 +00:00
|
|
|
RoadBits present;
|
|
|
|
RoadBits n;
|
2004-08-09 17:04:08 +00:00
|
|
|
*edge_road = true;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Only do the special processing for actual players. */
|
2006-10-14 22:31:18 +00:00
|
|
|
if (!IsValidPlayer(_current_player)) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Only do the special processing if the road is owned
|
|
|
|
* by a town */
|
2006-10-14 22:22:48 +00:00
|
|
|
if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_cheats.magic_bulldozer.value) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Get a bitmask of which neighbouring roads has a tile */
|
2007-01-10 18:56:51 +00:00
|
|
|
n = ROAD_NONE;
|
2007-05-20 19:14:08 +00:00
|
|
|
present = GetAnyRoadBits(tile, rt);
|
|
|
|
if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1, 0), rt) & ROAD_SW) n |= ROAD_NE;
|
|
|
|
if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile, 0, 1), rt) & ROAD_NW) n |= ROAD_SE;
|
|
|
|
if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile, 1, 0), rt) & ROAD_NE) n |= ROAD_SW;
|
|
|
|
if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile, 0, -1), rt) & ROAD_SE) n |= ROAD_NW;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
|
|
|
|
* then allow it */
|
2006-03-05 17:24:04 +00:00
|
|
|
if ((n & (n - 1)) != 0 && (n & remove) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Town *t;
|
|
|
|
*edge_road = false;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* you can remove all kind of roads with extra dynamite */
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_patches.extra_dynamite) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-08 13:54:19 +00:00
|
|
|
t = ClosestTownFromTile(tile, (uint)-1);
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool *edge_road, RoadType rt)
|
2007-02-23 00:17:46 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
return CheckAllowRemoveRoad(tile, remove, GetRoadOwner(tile, rt), edge_road, rt);
|
2007-02-23 00:17:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Delete a piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to remove road from
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0..3 road pieces to remove (RoadBits)
|
2007-05-20 19:14:08 +00:00
|
|
|
* bit 4..5 road type
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-28 20:41:35 +00:00
|
|
|
/* cost for removing inner/edge -roads */
|
2005-04-03 13:37:35 +00:00
|
|
|
static const uint16 road_remove_cost[2] = {50, 18};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
Town *t;
|
2005-05-09 22:33:00 +00:00
|
|
|
/* true if the roadpiece was always removeable,
|
|
|
|
* false if it was a center piece. Affects town ratings drop */
|
2004-08-09 17:04:08 +00:00
|
|
|
bool edge_road;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)GB(p1, 4, 2);
|
|
|
|
if (!IsTileType(tile, MP_STREET) || !IsValidRoadType(rt)) return CMD_ERROR;
|
2005-07-15 21:17:38 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
Owner owner = GetRoadOwner(tile, rt);
|
2005-04-03 13:37:35 +00:00
|
|
|
|
|
|
|
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
|
2006-12-27 12:38:02 +00:00
|
|
|
t = GetTownByTile(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
} else {
|
2005-02-04 13:56:51 +00:00
|
|
|
t = NULL;
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-02-24 09:42:39 +00:00
|
|
|
RoadBits pieces = Extract<RoadBits, 0>(p1);
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile);
|
|
|
|
/* The tile doesn't have the given road type */
|
|
|
|
if (!HASBIT(rts, rt)) return CMD_ERROR;
|
2007-02-24 09:42:39 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (!CheckAllowRemoveRoad(tile, pieces, &edge_road, rt)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* check if you're allowed to remove the street owned by a town
|
|
|
|
* removal allowance depends on difficulty setting */
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL: {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits present = GetRoadBits(tile, rt);
|
2006-12-27 12:38:02 +00:00
|
|
|
RoadBits c = pieces;
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
2006-06-19 17:22:57 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (GetTileSlope(tile, NULL) != SLOPE_FLAT &&
|
|
|
|
(present == ROAD_Y || present == ROAD_X)) {
|
2007-01-10 18:56:51 +00:00
|
|
|
c |= (RoadBits)((c & 0xC) >> 2);
|
|
|
|
c |= (RoadBits)((c & 0x3) << 2);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* limit the bits to delete to the existing bits. */
|
2006-12-27 12:38:02 +00:00
|
|
|
c &= present;
|
|
|
|
if (c == 0) return CMD_ERROR;
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
present ^= c;
|
|
|
|
if (present == 0) {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
|
|
|
|
if (rts == ROADTYPES_NONE) {
|
|
|
|
DoClearSquare(tile);
|
|
|
|
} else {
|
|
|
|
SetRoadTypes(tile, rts);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2007-05-20 19:14:08 +00:00
|
|
|
SetRoadBits(tile, present, rt);
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
return CountRoadBits(c) * _price.remove_road;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
|
|
|
if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-05-20 19:14:08 +00:00
|
|
|
if (rt == ROADTYPE_ROAD) {
|
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
|
|
|
|
if (rts == ROADTYPES_NONE) {
|
|
|
|
MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailType(tile));
|
|
|
|
} else {
|
|
|
|
SetRoadTypes(tile, rts);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-01-10 18:56:51 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
return _price.remove_road * 2;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
default:
|
|
|
|
case ROAD_TILE_DEPOT:
|
|
|
|
return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-01 15:03:47 +00:00
|
|
|
static const RoadBits _valid_tileh_slopes_road[][15] = {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* set of normal ones */
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
ROAD_ALL, ROAD_NONE, ROAD_NONE,
|
|
|
|
ROAD_X, ROAD_NONE, ROAD_NONE, // 3, 4, 5
|
|
|
|
ROAD_Y, ROAD_NONE, ROAD_NONE,
|
|
|
|
ROAD_Y, ROAD_NONE, ROAD_NONE, // 9, 10, 11
|
|
|
|
ROAD_X, ROAD_NONE, ROAD_NONE
|
2004-09-11 09:55:19 +00:00
|
|
|
},
|
2007-03-28 20:41:35 +00:00
|
|
|
/* allowed road for an evenly raised platform */
|
2004-09-11 09:55:19 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
ROAD_NONE,
|
2004-08-09 17:04:08 +00:00
|
|
|
ROAD_SW | ROAD_NW,
|
|
|
|
ROAD_SW | ROAD_SE,
|
2006-02-28 13:18:14 +00:00
|
|
|
ROAD_Y | ROAD_SW,
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
ROAD_SE | ROAD_NE, // 4
|
|
|
|
ROAD_ALL,
|
2006-02-28 13:18:14 +00:00
|
|
|
ROAD_X | ROAD_SE,
|
2004-08-09 17:04:08 +00:00
|
|
|
ROAD_ALL,
|
|
|
|
|
|
|
|
ROAD_NW | ROAD_NE, // 8
|
2006-02-28 13:18:14 +00:00
|
|
|
ROAD_X | ROAD_NW,
|
2004-08-09 17:04:08 +00:00
|
|
|
ROAD_ALL,
|
|
|
|
ROAD_ALL,
|
|
|
|
|
2006-02-28 13:18:14 +00:00
|
|
|
ROAD_Y | ROAD_NE, // 12
|
2004-08-09 17:04:08 +00:00
|
|
|
ROAD_ALL,
|
|
|
|
ROAD_ALL
|
2004-08-10 18:35:43 +00:00
|
|
|
},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static uint32 CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-31 06:16:04 +00:00
|
|
|
RoadBits road_bits;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
|
|
|
if (existing == 0) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* force full pieces. */
|
2007-01-10 18:56:51 +00:00
|
|
|
*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
|
|
|
|
*pieces |= (RoadBits)((*pieces & 0x3) << 2);
|
2006-08-10 14:44:32 +00:00
|
|
|
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
|
|
|
|
}
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2006-03-31 06:16:04 +00:00
|
|
|
road_bits = *pieces | existing;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* no special foundation */
|
2006-03-31 06:16:04 +00:00
|
|
|
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* force that all bits are set when we have slopes */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh != SLOPE_FLAT) *pieces |= _valid_tileh_slopes_road[0][tileh];
|
2006-03-31 06:16:04 +00:00
|
|
|
return 0; // no extra cost
|
|
|
|
}
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* foundation is used. Whole tile is leveled up */
|
2006-03-31 06:16:04 +00:00
|
|
|
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
|
2006-06-27 21:25:53 +00:00
|
|
|
return existing != 0 ? 0 : _price.terraform;
|
2006-03-31 06:16:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* partly leveled up tile, only if there's no road on that tile */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (existing == 0 && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* force full pieces. */
|
2007-01-10 18:56:51 +00:00
|
|
|
*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
|
|
|
|
*pieces |= (RoadBits)((*pieces & 0x3) << 2);
|
2006-03-31 06:16:04 +00:00
|
|
|
if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to build road
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0..3 road pieces to build (RoadBits)
|
2007-05-20 19:14:08 +00:00
|
|
|
* bit 4..5 road type
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 the town that is building the road (0 if not applicable)
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-31 06:16:04 +00:00
|
|
|
int32 cost = 0;
|
|
|
|
int32 ret;
|
2007-01-10 18:56:51 +00:00
|
|
|
RoadBits existing = ROAD_NONE;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
|
|
|
|
* if a non-player is building the road */
|
2007-02-24 09:42:39 +00:00
|
|
|
if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
|
|
|
|
|
|
|
|
RoadBits pieces = Extract<RoadBits, 0>(p1);
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)GB(p1, 4, 2);
|
|
|
|
if (!IsValidRoadType(rt)) return CMD_ERROR;
|
|
|
|
|
2006-04-03 15:18:12 +00:00
|
|
|
tileh = GetTileSlope(tile, NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 15:18:12 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
case MP_STREET:
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL:
|
2006-06-19 17:22:57 +00:00
|
|
|
if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
existing = GetRoadBits(tile, rt);
|
2006-03-06 13:11:08 +00:00
|
|
|
if ((existing & pieces) == pieces) {
|
2006-02-23 07:26:49 +00:00
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
}
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2006-02-23 07:26:49 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING:
|
2007-05-20 19:14:08 +00:00
|
|
|
if (HASBIT(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) goto do_clear;
|
|
|
|
break;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2006-02-23 07:26:49 +00:00
|
|
|
goto do_clear;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-21 18:07:35 +00:00
|
|
|
case MP_RAILWAY: {
|
2006-02-28 21:19:50 +00:00
|
|
|
Axis roaddir;
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2006-03-01 15:03:47 +00:00
|
|
|
#define M(x) (1 << (x))
|
|
|
|
/* Level crossings may only be built on these slopes */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (!HASBIT(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2006-03-01 15:03:47 +00:00
|
|
|
#undef M
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 08:17:33 +00:00
|
|
|
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
|
2006-03-19 13:48:08 +00:00
|
|
|
switch (GetTrackBits(tile)) {
|
|
|
|
case TRACK_BIT_X:
|
|
|
|
if (pieces & ROAD_X) goto do_clear;
|
|
|
|
roaddir = AXIS_Y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRACK_BIT_Y:
|
|
|
|
if (pieces & ROAD_Y) goto do_clear;
|
|
|
|
roaddir = AXIS_X;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: goto do_clear;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2006-03-31 06:16:04 +00:00
|
|
|
|
2006-02-21 18:07:35 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-01-10 18:56:51 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt), p2);
|
2006-03-01 06:39:04 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
return _price.build_road * 2;
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-21 18:07:35 +00:00
|
|
|
default:
|
2004-08-09 17:04:08 +00:00
|
|
|
do_clear:;
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-03-31 06:16:04 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
|
|
|
cost += ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 15:18:12 +00:00
|
|
|
ret = CheckRoadSlope(tileh, &pieces, existing);
|
2006-04-26 21:44:22 +00:00
|
|
|
/* Return an error if we need to build a foundation (ret != 0) but the
|
|
|
|
* current patch-setting is turned off (or stupid AI@work) */
|
2006-04-27 08:24:48 +00:00
|
|
|
if (CmdFailed(ret) || (ret != 0 && (!_patches.build_on_slopes || _is_old_ai_player)))
|
2006-04-26 21:44:22 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
|
2006-03-31 06:16:04 +00:00
|
|
|
cost += ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 15:18:12 +00:00
|
|
|
if (IsTileType(tile, MP_STREET)) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Don't put the pieces that already exist */
|
2006-03-06 13:11:08 +00:00
|
|
|
pieces &= ComplementRoadBits(existing);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 06:16:04 +00:00
|
|
|
cost += CountRoadBits(pieces) * _price.build_road;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-04-03 15:18:12 +00:00
|
|
|
if (IsTileType(tile, MP_STREET)) {
|
2007-05-20 19:14:08 +00:00
|
|
|
if (existing == 0) {
|
|
|
|
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
|
|
|
SetRoadOwner(tile, rt, _current_player);
|
|
|
|
}
|
|
|
|
SetRoadBits(tile, existing | pieces, rt);
|
2006-02-28 21:19:50 +00:00
|
|
|
} else {
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2007-03-24 09:12:03 +00:00
|
|
|
/**
|
|
|
|
* Switches the rail type on a level crossing.
|
|
|
|
* @param tile The tile on which the railtype is to be convert.
|
|
|
|
* @param totype The railtype we want to convert to
|
|
|
|
* @param exec Switches between test and execute mode
|
|
|
|
* @return The cost and state of the operation
|
|
|
|
* @retval CMD_ERROR An error occured during the operation.
|
|
|
|
*/
|
2006-04-03 18:11:42 +00:00
|
|
|
int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-28 20:41:35 +00:00
|
|
|
/* not a railroad crossing? */
|
2005-06-07 21:37:00 +00:00
|
|
|
if (!IsLevelCrossing(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* not owned by me? */
|
2007-04-01 11:11:49 +00:00
|
|
|
if (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
if (GetRailType(tile) == totype) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */
|
2007-02-27 23:36:28 +00:00
|
|
|
if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
|
2006-11-17 19:31:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (exec) {
|
2007-02-27 23:36:28 +00:00
|
|
|
SetRailType(tile, totype);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2007-01-10 18:56:51 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile)));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-24 09:12:03 +00:00
|
|
|
return _price.build_rail / 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a long piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param end_tile end tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 start tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
|
|
|
|
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
|
|
|
|
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
|
2007-05-20 19:14:08 +00:00
|
|
|
* - p2 = (bit 3) - road type
|
2005-05-09 22:33:00 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
TileIndex start_tile, tile;
|
2005-05-09 22:33:00 +00:00
|
|
|
int32 cost, ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
start_tile = p1;
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)HASBIT(p2, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Only drag in X or Y direction dictated by the direction variable */
|
|
|
|
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
|
|
|
|
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
|
|
|
|
|
|
|
|
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
|
|
|
|
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
|
|
|
|
TileIndex t = start_tile;
|
|
|
|
start_tile = end_tile;
|
|
|
|
end_tile = t;
|
2007-04-18 22:10:36 +00:00
|
|
|
p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cost = 0;
|
|
|
|
tile = start_tile;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Start tile is the small number. */
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
2006-02-28 13:18:14 +00:00
|
|
|
RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X;
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
|
|
|
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
ret = DoCommand(tile, rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(ret)) {
|
|
|
|
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
|
2006-04-26 21:48:22 +00:00
|
|
|
_error_message = INVALID_STRING_ID;
|
2005-10-23 13:04:44 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
cost += ret;
|
2005-10-23 13:04:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
return (cost == 0) ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Remove a long piece of road.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param end_tile end tile of drag
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p1 start tile of drag
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
|
|
|
|
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
|
|
|
|
* - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
|
2007-05-20 19:14:08 +00:00
|
|
|
* - p2 = (bit 3) - road type
|
2005-05-09 22:33:00 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 07:15:58 +00:00
|
|
|
TileIndex start_tile, tile;
|
2005-05-09 22:33:00 +00:00
|
|
|
int32 cost, ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-04 17:11:03 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
start_tile = p1;
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)HASBIT(p2, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/* Only drag in X or Y direction dictated by the direction variable */
|
|
|
|
if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
|
|
|
|
if (HASBIT(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
|
|
|
|
|
|
|
|
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
|
|
|
|
if (start_tile > end_tile || (start_tile == end_tile && HASBIT(p2, 0))) {
|
|
|
|
TileIndex t = start_tile;
|
|
|
|
start_tile = end_tile;
|
|
|
|
end_tile = t;
|
2006-02-13 21:15:00 +00:00
|
|
|
p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cost = 0;
|
|
|
|
tile = start_tile;
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Start tile is the small number. */
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
2006-02-28 13:18:14 +00:00
|
|
|
RoadBits bits = HASBIT(p2, 2) ? ROAD_Y : ROAD_X;
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
|
|
|
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* try to remove the halves. */
|
2006-02-28 13:18:14 +00:00
|
|
|
if (bits != 0) {
|
2007-05-20 19:14:08 +00:00
|
|
|
ret = DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (!CmdFailed(ret)) cost += ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (tile == end_tile) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-25 16:44:57 +00:00
|
|
|
tile += HASBIT(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
return (cost == 0) ? CMD_ERROR : cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a road depot.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where to build the depot
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param flags operation to perform
|
2007-02-24 09:42:39 +00:00
|
|
|
* @param p1 bit 0..1 entrance direction (DiagDirection)
|
2007-05-20 19:14:08 +00:00
|
|
|
* bit 2 road type
|
2005-05-09 22:33:00 +00:00
|
|
|
* @param p2 unused
|
2005-07-16 23:47:37 +00:00
|
|
|
*
|
|
|
|
* @todo When checking for the tile slope,
|
|
|
|
* distingush between "Flat land required" and "land sloped in wrong direction"
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int32 cost;
|
|
|
|
Depot *dep;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2007-02-24 09:42:39 +00:00
|
|
|
DiagDirection dir = Extract<DiagDirection, 0>(p1);
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = (RoadType)HASBIT(p1, 2);
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2006-02-21 07:41:54 +00:00
|
|
|
tileh = GetTileSlope(tile, NULL);
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh != SLOPE_FLAT && (
|
2005-10-23 13:04:44 +00:00
|
|
|
!_patches.build_on_slopes ||
|
2006-04-23 13:48:16 +00:00
|
|
|
IsSteepSlope(tileh) ||
|
2007-02-24 09:42:39 +00:00
|
|
|
!CanBuildDepotByTileh(dir, tileh)
|
2005-10-23 13:04:44 +00:00
|
|
|
)) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(cost)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
dep = AllocateDepot();
|
2005-10-23 13:04:44 +00:00
|
|
|
if (dep == NULL) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2004-08-09 17:04:08 +00:00
|
|
|
dep->xy = tile;
|
|
|
|
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadDepot(tile, _current_player, dir, rt);
|
2006-03-01 06:39:04 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return cost + _price.build_road_depot;
|
|
|
|
}
|
|
|
|
|
2005-06-24 17:41:08 +00:00
|
|
|
static int32 RemoveRoadDepot(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-03 17:57:27 +00:00
|
|
|
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-26 14:44:55 +00:00
|
|
|
if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return _price.remove_road_depot;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Road(TileIndex tile, byte flags)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL: {
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits b = GetAllRoadBits(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-13 14:48:47 +00:00
|
|
|
#define M(x) (1 << (x))
|
|
|
|
/* Clear the road if only one piece is on the tile OR the AI tries
|
|
|
|
* to clear town road OR we are not using the DC_AUTO flag */
|
|
|
|
if ((M(b) & (M(ROAD_NW) | M(ROAD_SW) | M(ROAD_SE) | M(ROAD_NE))) ||
|
|
|
|
((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
|
|
|
|
!(flags & DC_AUTO)
|
|
|
|
) {
|
|
|
|
return DoCommand(tile, b, 0, flags, CMD_REMOVE_ROAD);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
2007-01-13 14:48:47 +00:00
|
|
|
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
2007-01-13 15:55:22 +00:00
|
|
|
}
|
2007-01-13 14:48:47 +00:00
|
|
|
#undef M
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2006-02-21 18:07:35 +00:00
|
|
|
int32 ret;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile, GetCrossingRoadBits(tile), 0, flags, CMD_REMOVE_ROAD);
|
2006-02-21 18:07:35 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2006-02-21 18:07:35 +00:00
|
|
|
if (flags & DC_AUTO) {
|
|
|
|
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
}
|
|
|
|
return RemoveRoadDepot(tile, flags);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawRoadTileStruct {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 image;
|
|
|
|
byte subcoord_x;
|
|
|
|
byte subcoord_y;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#include "table/road_land.h"
|
|
|
|
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
uint GetRoadFoundation(Slope tileh, RoadBits bits)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2006-05-20 18:03:22 +00:00
|
|
|
uint i;
|
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* normal level sloped building */
|
2006-08-10 14:44:32 +00:00
|
|
|
if (!IsSteepSlope(tileh) &&
|
|
|
|
(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) {
|
|
|
|
return tileh;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* inclined sloped building */
|
2006-05-20 18:03:22 +00:00
|
|
|
switch (bits) {
|
|
|
|
case ROAD_X: i = 0; break;
|
|
|
|
case ROAD_Y: i = 1; break;
|
|
|
|
default: return 0;
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2006-05-20 18:03:22 +00:00
|
|
|
switch (tileh) {
|
2006-08-10 14:44:32 +00:00
|
|
|
case SLOPE_W:
|
|
|
|
case SLOPE_STEEP_W: i += 0; break;
|
|
|
|
case SLOPE_S:
|
|
|
|
case SLOPE_STEEP_S: i += 2; break;
|
|
|
|
case SLOPE_E:
|
|
|
|
case SLOPE_STEEP_E: i += 4; break;
|
|
|
|
case SLOPE_N:
|
|
|
|
case SLOPE_STEEP_N: i += 6; break;
|
|
|
|
default: return 0;
|
2006-05-20 18:03:22 +00:00
|
|
|
}
|
|
|
|
return i + 15;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const byte _road_sloped_sprites[14] = {
|
|
|
|
0, 0, 2, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
3, 0, 0, 0,
|
|
|
|
0, 0
|
|
|
|
};
|
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
/**
|
|
|
|
* Whether to draw unpaved roads regardless of the town zone.
|
|
|
|
* By default, OpenTTD always draws roads as unpaved if they are on a desert
|
|
|
|
* tile or above the snowline. Newgrf files, however, can set a bit that allows
|
|
|
|
* paved roads to be built on desert tiles as they would be on grassy tiles.
|
|
|
|
*
|
|
|
|
* @param tile The tile the road is on
|
|
|
|
* @param roadside What sort of road this is
|
|
|
|
* @return True if the road should be drawn unpaved regardless of the roadside.
|
|
|
|
*/
|
|
|
|
static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
|
|
|
|
{
|
|
|
|
return (IsOnSnow(tile) &&
|
|
|
|
!(_opt.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
|
|
|
|
roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
|
|
|
|
}
|
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
/**
|
|
|
|
* Draw ground sprite and road pieces
|
|
|
|
* @param ti TileInfo
|
|
|
|
*/
|
2006-06-28 06:10:20 +00:00
|
|
|
static void DrawRoadBits(TileInfo* ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
|
2005-09-29 19:59:57 +00:00
|
|
|
const DrawRoadTileStruct *drts;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = 0;
|
|
|
|
SpriteID pal = PAL_NONE;
|
2006-06-19 20:13:50 +00:00
|
|
|
Roadside roadside;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
2006-04-03 13:35:19 +00:00
|
|
|
int foundation = GetRoadFoundation(ti->tileh, road);
|
2005-09-29 19:59:57 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (foundation != 0) DrawFoundation(ti, foundation);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* DrawFoundation() modifies ti.
|
|
|
|
* Default sloped sprites.. */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (image == 0) image = _road_tile_sprites_1[road];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
roadside = GetRoadside(ti->tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
|
2005-09-29 19:59:57 +00:00
|
|
|
image += 19;
|
2006-06-19 20:13:50 +00:00
|
|
|
} else {
|
|
|
|
switch (roadside) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
case ROADSIDE_GRASS: break;
|
|
|
|
case ROADSIDE_GRASS_ROAD_WORKS: break;
|
|
|
|
default: image -= 19; break; // Paved
|
|
|
|
}
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 13:35:19 +00:00
|
|
|
if (HasRoadWorks(ti->tile)) {
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Road works */
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(road & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
|
2005-09-29 19:59:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Return if full detail is disabled, or we are zoomed fully out. */
|
2007-05-15 16:08:46 +00:00
|
|
|
if (!HASBIT(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
|
2006-11-22 18:16:50 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Draw extra details. */
|
2006-06-19 20:13:50 +00:00
|
|
|
for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) {
|
2005-09-29 19:59:57 +00:00
|
|
|
int x = ti->x | drts->subcoord_x;
|
|
|
|
int y = ti->y | drts->subcoord_y;
|
|
|
|
byte z = ti->z;
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
|
2007-01-14 19:57:49 +00:00
|
|
|
AddSortableSpriteToDraw(drts->image, PAL_NONE, x, y, 2, 2, 0x10, z);
|
2005-09-29 19:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
static void DrawTile_Road(TileInfo *ti)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(ti->tile)) {
|
|
|
|
case ROAD_TILE_NORMAL:
|
2006-06-28 06:10:20 +00:00
|
|
|
DrawRoadBits(ti);
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
|
|
|
SpriteID pal = PAL_NONE;
|
2007-04-27 21:35:02 +00:00
|
|
|
Roadside roadside = GetRoadside(ti->tile);
|
2006-06-10 08:37:41 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-19 17:15:33 +00:00
|
|
|
if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
|
2006-03-24 15:24:16 +00:00
|
|
|
if (IsCrossingBarred(ti->tile)) image += 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-27 21:35:02 +00:00
|
|
|
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
image += 8;
|
|
|
|
} else {
|
2007-04-27 21:35:02 +00:00
|
|
|
switch (roadside) {
|
2007-01-14 19:57:49 +00:00
|
|
|
case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
case ROADSIDE_GRASS: break;
|
|
|
|
default: image += 4; break; // Paved
|
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
2007-02-27 23:36:28 +00:00
|
|
|
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-28 13:18:14 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT: {
|
2006-08-06 18:36:36 +00:00
|
|
|
const DrawTileSprites* dts;
|
|
|
|
const DrawTileSeqStruct* dtss;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID palette;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-05 16:57:39 +00:00
|
|
|
palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-06 18:36:36 +00:00
|
|
|
dts = &_road_depot[GetRoadDepotDirection(ti->tile)];
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(dts->ground_sprite, PAL_NONE);
|
2005-02-22 15:39:45 +00:00
|
|
|
|
2006-08-06 18:36:36 +00:00
|
|
|
for (dtss = dts->seq; dtss->image != 0; dtss++) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = dtss->image;
|
|
|
|
SpriteID pal;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-05 07:49:04 +00:00
|
|
|
if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
|
|
|
|
pal = PALETTE_TO_TRANSPARENT;
|
|
|
|
} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
|
|
|
|
pal = palette;
|
|
|
|
} else {
|
|
|
|
pal = PAL_NONE;
|
2006-08-05 16:57:39 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
AddSortableSpriteToDraw(
|
2007-01-14 19:57:49 +00:00
|
|
|
image, pal,
|
2006-08-06 18:36:36 +00:00
|
|
|
ti->x + dtss->delta_x, ti->y + dtss->delta_y,
|
|
|
|
dtss->size_x, dtss->size_y,
|
|
|
|
dtss->size_z, ti->z
|
2006-02-21 18:07:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-03 06:44:54 +00:00
|
|
|
void DrawRoadDepotSprite(int x, int y, DiagDirection dir)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
2006-08-06 18:36:36 +00:00
|
|
|
const DrawTileSprites* dts = &_road_depot[dir];
|
|
|
|
const DrawTileSeqStruct* dtss;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
x += 33;
|
|
|
|
y += 17;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(dts->ground_sprite, PAL_NONE, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-06 18:36:36 +00:00
|
|
|
for (dtss = dts->seq; dtss->image != 0; dtss++) {
|
|
|
|
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = dtss->image;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh == SLOPE_FLAT) return z;
|
2006-08-06 16:32:49 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
|
2007-05-20 19:14:08 +00:00
|
|
|
uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2006-03-21 22:06:32 +00:00
|
|
|
if (f != 0) {
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh)) {
|
|
|
|
z += TILE_HEIGHT;
|
|
|
|
} else if (f < 15) {
|
|
|
|
return z + TILE_HEIGHT; // leveled foundation
|
|
|
|
}
|
2006-03-21 22:06:32 +00:00
|
|
|
tileh = _inclined_tileh[f - 15]; // inclined foundation
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-08-06 16:32:49 +00:00
|
|
|
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
|
2006-03-21 22:06:32 +00:00
|
|
|
} else {
|
2006-04-23 19:35:36 +00:00
|
|
|
return z + TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Road(TileIndex tile, Slope tileh)
|
2004-08-13 18:27:33 +00:00
|
|
|
{
|
2006-04-23 13:48:16 +00:00
|
|
|
if (tileh == SLOPE_FLAT) return SLOPE_FLAT;
|
2006-05-09 08:25:31 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
|
2007-05-20 19:14:08 +00:00
|
|
|
uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
|
2006-02-21 18:07:35 +00:00
|
|
|
|
2006-04-02 12:49:18 +00:00
|
|
|
if (f == 0) return tileh;
|
2006-04-23 13:48:16 +00:00
|
|
|
if (f < 15) return SLOPE_FLAT; // leveled foundation
|
2006-03-21 22:06:32 +00:00
|
|
|
return _inclined_tileh[f - 15]; // inclined foundation
|
|
|
|
} else {
|
2006-04-23 13:48:16 +00:00
|
|
|
return SLOPE_FLAT;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
|
|
|
|
static const Roadside _town_road_types[][2] = {
|
|
|
|
{ ROADSIDE_GRASS, ROADSIDE_GRASS },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_TREES, ROADSIDE_TREES },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
static const Roadside _town_road_types_2[][2] = {
|
|
|
|
{ ROADSIDE_GRASS, ROADSIDE_GRASS },
|
|
|
|
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
|
|
|
|
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-13 21:15:00 +00:00
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
2007-03-20 13:47:00 +00:00
|
|
|
if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
|
2006-04-03 13:35:19 +00:00
|
|
|
ToggleSnow(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
2006-04-03 13:35:19 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
|
|
|
|
ToggleDesert(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-03 13:35:19 +00:00
|
|
|
if (!HasRoadWorks(tile)) {
|
2006-06-27 21:25:53 +00:00
|
|
|
const Town* t = ClosestTownFromTile(tile, (uint)-1);
|
|
|
|
int grp = 0;
|
2005-02-04 13:56:51 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t != NULL) {
|
|
|
|
grp = GetTownRadiusGroup(t, tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-03-28 20:41:35 +00:00
|
|
|
/* Show an animation to indicate road work */
|
2004-09-11 09:55:19 +00:00
|
|
|
if (t->road_build_months != 0 &&
|
2006-06-27 21:25:53 +00:00
|
|
|
(DistanceManhattan(t->xy, tile) < 8 || grp != 0) &&
|
2007-05-20 19:14:08 +00:00
|
|
|
GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetAllRoadBits(tile) == ROAD_X || GetAllRoadBits(tile) == ROAD_Y)) {
|
2007-04-01 11:11:49 +00:00
|
|
|
if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && CHANCE16(1, 20)) {
|
2006-04-03 13:35:19 +00:00
|
|
|
StartRoadWorks(tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_21_JACKHAMMER, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
CreateEffectVehicleAbove(
|
2006-04-03 05:32:11 +00:00
|
|
|
TileX(tile) * TILE_SIZE + 7,
|
|
|
|
TileY(tile) * TILE_SIZE + 7,
|
2004-08-09 17:04:08 +00:00
|
|
|
0,
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_BULLDOZER);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2006-04-03 13:35:19 +00:00
|
|
|
/* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
|
2007-03-22 03:42:43 +00:00
|
|
|
const Roadside* new_rs = (_opt.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
|
2006-06-19 20:13:50 +00:00
|
|
|
Roadside cur_rs = GetRoadside(tile);
|
2006-04-03 13:35:19 +00:00
|
|
|
|
|
|
|
/* We have our desired type, do nothing */
|
2006-06-19 20:13:50 +00:00
|
|
|
if (cur_rs == new_rs[0]) return;
|
2006-04-03 13:35:19 +00:00
|
|
|
|
|
|
|
/* We have the pre-type of the desired type, switch to the desired type */
|
2006-06-19 20:13:50 +00:00
|
|
|
if (cur_rs == new_rs[1]) {
|
|
|
|
cur_rs = new_rs[0];
|
2006-04-03 13:35:19 +00:00
|
|
|
/* We have barren land, install the pre-type */
|
2006-06-19 20:13:50 +00:00
|
|
|
} else if (cur_rs == ROADSIDE_BARREN) {
|
|
|
|
cur_rs = new_rs[1];
|
2006-04-03 13:35:19 +00:00
|
|
|
/* We're totally off limits, remove any installation and make barren land */
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-06-19 20:13:50 +00:00
|
|
|
cur_rs = ROADSIDE_BARREN;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-06-19 20:13:50 +00:00
|
|
|
SetRoadside(tile, cur_rs);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2006-04-03 13:35:19 +00:00
|
|
|
} else if (IncreaseRoadWorksCounter(tile)) {
|
|
|
|
TerminateRoadWorks(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-08 16:27:54 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) ShowDepotWindow(tile, VEH_ROAD);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _road_trackbits[16] = {
|
|
|
|
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode)
|
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadType rt = ROADTYPE_ROAD;
|
|
|
|
|
2006-02-23 07:26:49 +00:00
|
|
|
switch (mode) {
|
|
|
|
case TRANSPORT_RAIL:
|
|
|
|
if (!IsLevelCrossing(tile)) return 0;
|
2006-03-19 12:06:12 +00:00
|
|
|
return GetCrossingRailBits(tile) * 0x101;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
|
|
|
case TRANSPORT_ROAD:
|
2007-05-20 19:14:08 +00:00
|
|
|
if (!HASBIT(GetRoadTypes(tile), rt)) return 0;
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_NORMAL:
|
2007-05-20 19:14:08 +00:00
|
|
|
return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile, rt)] * 0x101;
|
2006-02-23 07:26:49 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_CROSSING: {
|
2006-07-22 08:59:52 +00:00
|
|
|
uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101;
|
2006-03-19 17:15:33 +00:00
|
|
|
|
2006-03-30 09:08:43 +00:00
|
|
|
if (IsCrossingBarred(tile)) r *= 0x10001;
|
2006-02-23 07:26:49 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
default:
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2006-07-22 08:59:52 +00:00
|
|
|
return AxisToTrackBits(DiagDirToAxis(GetRoadDepotDirection(tile))) * 0x101;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2006-02-23 07:26:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const StringID _road_tile_strings[] = {
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1815_ROAD_WITH_STREETLIGHTS,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1816_TREE_LINED_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
STR_1814_ROAD,
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_CROSSING: td->str = STR_1818_ROAD_RAIL_LEVEL_CROSSING; break;
|
|
|
|
case ROAD_TILE_DEPOT: td->str = STR_1817_ROAD_VEHICLE_DEPOT; break;
|
2006-06-19 20:13:50 +00:00
|
|
|
default: td->str = _road_tile_strings[GetRoadside(tile)]; break;
|
2006-02-23 08:20:28 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _roadveh_enter_depot_unk0[4] = {
|
|
|
|
8, 9, 0, 1
|
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
switch (GetRoadTileType(tile)) {
|
|
|
|
case ROAD_TILE_CROSSING:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN && !IsCrossingBarred(tile)) {
|
2006-02-21 18:07:35 +00:00
|
|
|
/* train crossing a road */
|
|
|
|
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
|
2006-03-24 15:24:16 +00:00
|
|
|
BarCrossing(tile);
|
2006-02-21 18:07:35 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-21 18:07:35 +00:00
|
|
|
break;
|
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
case ROAD_TILE_DEPOT:
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD &&
|
2006-06-27 21:25:53 +00:00
|
|
|
v->u.road.frame == 11 &&
|
|
|
|
_roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) {
|
2006-10-04 12:01:59 +00:00
|
|
|
VehicleEnterDepot(v);
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-02-21 18:07:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
|
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
|
|
|
if (!HASBIT(GetRoadTypes(tile), rt)) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (GetRoadOwner(tile, rt) == old_player) {
|
|
|
|
SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
|
|
|
|
|
|
|
|
if (rt == ROADTYPE_TRAM) {
|
|
|
|
DoCommand(tile, ROADTYPE_TRAM << 4 | GetRoadBits(tile, ROADTYPE_ROAD), 0, DC_EXEC, CMD_REMOVE_ROAD);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
|
|
|
|
if (IsLevelCrossing(tile)) {
|
|
|
|
MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_road_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
DrawTile_Road, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Road, /* get_slope_z_proc */
|
|
|
|
ClearTile_Road, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_Road, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Road, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Road, /* click_tile_proc */
|
|
|
|
AnimateTile_Road, /* animate_tile_proc */
|
|
|
|
TileLoop_Road, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_Road, /* change_tile_owner_clear */
|
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
|
VehicleEnter_Road, /* vehicle_enter_tile_proc */
|
|
|
|
GetSlopeTileh_Road, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|