2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.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"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.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"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-11 22:07:08 +00:00
|
|
|
/* When true, GetTrackStatus for roads will treat roads under reconstruction
|
|
|
|
* as normal roads instead of impassable. This is used when detecting whether
|
|
|
|
* a road can be removed. This is of course ugly, but I don't know a better
|
|
|
|
* solution just like that... */
|
2004-08-09 17:04:08 +00:00
|
|
|
static bool _road_special_gettrackstatus;
|
|
|
|
|
|
|
|
void RoadVehEnterDepot(Vehicle *v);
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static bool HasTileRoadAt(TileIndex tile, int i)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int mask;
|
|
|
|
byte b;
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case MP_STREET:
|
2005-07-13 18:04:01 +00:00
|
|
|
b = _m[tile].m5;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((b & 0xF0) == 0) {
|
2005-06-07 21:37:00 +00:00
|
|
|
} else if (IsLevelCrossing(tile)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
b = (b&8)?5:10;
|
|
|
|
} else if ((b & 0xF0) == 0x20) {
|
|
|
|
return (~b & 3) == i;
|
2006-02-01 06:32:03 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case MP_STATION:
|
2005-07-13 18:04:01 +00:00
|
|
|
b = _m[tile].m5;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (!IS_BYTE_INSIDE(b, 0x43, 0x43 + 8)) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
return ((~(b - 0x43) & 3) == i);
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
|
|
|
mask = GetRoadBitsByTile(tile);
|
|
|
|
b = 10; if (mask & 1) break;
|
|
|
|
b = 5; if (mask & 2) break;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HASBIT(b, i);
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static bool CheckAllowRemoveRoad(TileIndex tile, uint br, bool *edge_road)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int blocks;
|
|
|
|
byte owner;
|
|
|
|
uint n;
|
|
|
|
*edge_road = true;
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_game_mode == GM_EDITOR) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
blocks = GetRoadBitsByTile(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
if (blocks == 0) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Only do the special processing for actual players.
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_current_player >= MAX_PLAYERS) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// A railway crossing has the road owner in the map3_lo byte.
|
2005-06-07 21:37:00 +00:00
|
|
|
if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
owner = _m[tile].m3;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-06-04 11:56:32 +00:00
|
|
|
owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
// Only do the special processing if the road is owned
|
|
|
|
// by a town
|
|
|
|
if (owner != OWNER_TOWN) {
|
|
|
|
return owner == OWNER_NONE || CheckOwnership(owner);
|
|
|
|
}
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_cheats.magic_bulldozer.value) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Get a bitmask of which neighbouring roads has a tile
|
|
|
|
n = 0;
|
|
|
|
if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8;
|
|
|
|
if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4;
|
|
|
|
if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2;
|
|
|
|
if (blocks&0x16 && HasTileRoadAt(TILE_ADDXY(tile, 0,-1), 2)) n |= 1;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
|
|
|
|
// then allow it
|
|
|
|
if ((n & (n-1)) != 0 && (n & br) != 0) {
|
|
|
|
Town *t;
|
|
|
|
*edge_road = false;
|
|
|
|
// 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
|
|
|
|
2005-04-03 13:37:35 +00:00
|
|
|
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint GetRoadBitsByTile(TileIndex tile)
|
|
|
|
{
|
2004-09-05 16:15:22 +00:00
|
|
|
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
|
2004-08-09 17:04:08 +00:00
|
|
|
return (byte)(r | (r >> 8));
|
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Delete a piece of road.
|
|
|
|
* @param x,y tile coordinates for road construction
|
|
|
|
* @param p1 road piece flags
|
|
|
|
* @param p2 unused
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-04-03 13:37:35 +00:00
|
|
|
// cost for removing inner/edge -roads
|
|
|
|
static const uint16 road_remove_cost[2] = {50, 18};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
TileInfo ti;
|
|
|
|
int32 cost;
|
2005-04-03 13:37:35 +00:00
|
|
|
TileIndex tile;
|
2005-07-15 21:17:38 +00:00
|
|
|
PlayerID owner;
|
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;
|
2005-05-09 22:33:00 +00:00
|
|
|
byte pieces = (byte)p1;
|
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) */
|
|
|
|
if (pieces >> 4) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
FindLandscapeHeight(&ti, x, y);
|
|
|
|
tile = ti.tile;
|
2005-04-03 13:37:35 +00:00
|
|
|
|
2005-07-15 21:17:38 +00:00
|
|
|
if (!IsTileType(tile, MP_STREET) && !IsTileType(tile, MP_TUNNELBRIDGE)) return CMD_ERROR;
|
|
|
|
|
|
|
|
// owner for railroad crossing is stored somewhere else
|
2005-04-03 13:37:35 +00:00
|
|
|
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
|
2005-07-15 21:17:38 +00:00
|
|
|
owner = IsLevelCrossing(tile) ? _m[tile].m3 : GetTileOwner(tile);
|
2005-04-03 13:37:35 +00:00
|
|
|
|
|
|
|
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
|
|
|
|
if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
|
|
|
|
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
2006-02-13 21:15:00 +00:00
|
|
|
} else {
|
2005-07-13 18:04:01 +00:00
|
|
|
t = GetTown(_m[tile].m2);
|
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
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// allow deleting road under bridge
|
2006-02-13 21:15:00 +00:00
|
|
|
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
bool b;
|
|
|
|
_road_special_gettrackstatus = true;
|
2005-05-09 22:33:00 +00:00
|
|
|
b = CheckAllowRemoveRoad(tile, pieces, &edge_road);
|
2004-08-09 17:04:08 +00:00
|
|
|
_road_special_gettrackstatus = false;
|
2005-05-09 22:33:00 +00:00
|
|
|
if (!b) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ti.type == MP_TUNNELBRIDGE) {
|
2005-01-16 14:06:22 +00:00
|
|
|
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
|
|
if ((ti.map5 & 0xE9) == 0xE8) {
|
2005-05-09 22:33:00 +00:00
|
|
|
if (pieces & 10) goto return_error;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if ((ti.map5 & 0xE9) == 0xE9) {
|
2005-05-09 22:33:00 +00:00
|
|
|
if (pieces & 5) goto return_error;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else
|
|
|
|
goto return_error;
|
|
|
|
|
|
|
|
cost = _price.remove_road * 2;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-04-03 13:37:35 +00:00
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = ti.map5 & 0xC7;
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
} else if (ti.type == MP_STREET) {
|
2005-04-03 13:37:35 +00:00
|
|
|
// check if you're allowed to remove the street owned by a town
|
|
|
|
// removal allowance depends on difficulty setting
|
2006-02-02 07:15:46 +00:00
|
|
|
if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
|
2005-04-03 13:37:35 +00:00
|
|
|
|
|
|
|
// XXX - change cascading ifs to switch when doing rewrite
|
|
|
|
if ((ti.map5 & 0xF0) == 0) { // normal road
|
2005-05-09 22:33:00 +00:00
|
|
|
byte c = pieces, t2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) {
|
|
|
|
c |= (c & 0xC) >> 2;
|
|
|
|
c |= (c & 0x3) << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// limit the bits to delete to the existing bits.
|
|
|
|
if ((c &= ti.map5) == 0) goto return_error;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// calculate the cost
|
|
|
|
t2 = c;
|
|
|
|
cost = 0;
|
|
|
|
do {
|
2006-02-01 07:36:15 +00:00
|
|
|
if (t2 & 1) cost += _price.remove_road;
|
|
|
|
} while (t2 >>= 1);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-04-03 13:37:35 +00:00
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 ^= c;
|
2005-10-05 07:20:26 +00:00
|
|
|
if (GB(_m[tile].m5, 0, 4) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DoClearSquare(tile);
|
2005-10-05 07:20:26 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2005-10-05 07:20:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
return cost;
|
2005-04-03 13:37:35 +00:00
|
|
|
} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing
|
2004-08-09 17:04:08 +00:00
|
|
|
byte c;
|
|
|
|
|
|
|
|
if (!(ti.map5 & 8)) {
|
2004-09-11 09:55:19 +00:00
|
|
|
c = 2;
|
2005-05-09 22:33:00 +00:00
|
|
|
if (pieces & 5) goto return_error;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
c = 1;
|
2005-05-09 22:33:00 +00:00
|
|
|
if (pieces & 10) goto return_error;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cost = _price.remove_road * 2;
|
|
|
|
if (flags & DC_EXEC) {
|
2005-04-03 13:37:35 +00:00
|
|
|
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
|
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
ModifyTile(tile,
|
2004-08-09 17:04:08 +00:00
|
|
|
MP_SETTYPE(MP_RAILWAY) |
|
|
|
|
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5,
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m4 & 0xF, /* map3_lo */
|
2004-08-09 17:04:08 +00:00
|
|
|
c /* map5 */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
} else
|
|
|
|
goto return_error;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return_error:;
|
|
|
|
return_cmd_error(INVALID_STRING_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ROAD_NW = 1, // NW road track
|
|
|
|
ROAD_SW = 2, // SW road track
|
|
|
|
ROAD_SE = 4, // SE road track
|
|
|
|
ROAD_NE = 8, // NE road track
|
|
|
|
ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE)
|
|
|
|
};
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-10 18:35:43 +00:00
|
|
|
static const byte _valid_tileh_slopes_road[3][15] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
// set of normal ones
|
|
|
|
{
|
|
|
|
ROAD_ALL, 0, 0,
|
|
|
|
ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5
|
|
|
|
ROAD_NW | ROAD_SE, 0, 0,
|
|
|
|
ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11
|
|
|
|
ROAD_SW | ROAD_NE, 0, 0
|
2004-09-11 09:55:19 +00:00
|
|
|
},
|
2004-08-09 17:04:08 +00:00
|
|
|
// allowed road for an evenly raised platform
|
2004-09-11 09:55:19 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
0,
|
|
|
|
ROAD_SW | ROAD_NW,
|
|
|
|
ROAD_SW | ROAD_SE,
|
|
|
|
ROAD_NW | ROAD_SE | ROAD_SW,
|
|
|
|
|
|
|
|
ROAD_SE | ROAD_NE, // 4
|
|
|
|
ROAD_ALL,
|
|
|
|
ROAD_SW | ROAD_NE | ROAD_SE,
|
|
|
|
ROAD_ALL,
|
|
|
|
|
|
|
|
ROAD_NW | ROAD_NE, // 8
|
|
|
|
ROAD_SW | ROAD_NE | ROAD_NW,
|
|
|
|
ROAD_ALL,
|
|
|
|
ROAD_ALL,
|
|
|
|
|
|
|
|
ROAD_NW | ROAD_SE | ROAD_NE, // 12
|
|
|
|
ROAD_ALL,
|
|
|
|
ROAD_ALL
|
2004-08-10 18:35:43 +00:00
|
|
|
},
|
|
|
|
// valid railway crossings on slopes
|
|
|
|
{
|
|
|
|
1, 0, 0, // 0, 1, 2
|
|
|
|
0, 0, 1, // 3, 4, 5
|
|
|
|
0, 1, 0, // 6, 7, 8
|
|
|
|
0, 1, 1, // 9, 10, 11
|
|
|
|
0, 1, 1, // 12, 13, 14
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-16 23:47:37 +00:00
|
|
|
if (!IsSteepTileh(tileh)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
byte road_bits = *pieces | existing;
|
|
|
|
|
|
|
|
// no special foundation
|
|
|
|
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
|
|
|
|
// force that all bits are set when we have slopes
|
|
|
|
if (tileh != 0) *pieces |= _valid_tileh_slopes_road[0][tileh];
|
|
|
|
return 0; // no extra cost
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// foundation is used. Whole tile is leveled up
|
|
|
|
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
|
2004-09-11 09:55:19 +00:00
|
|
|
return existing ? 0 : _price.terraform;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// partly leveled up tile, only if there's no road on that tile
|
2006-02-13 21:15:00 +00:00
|
|
|
if (!existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// force full pieces.
|
|
|
|
*pieces |= (*pieces & 0xC) >> 2;
|
|
|
|
*pieces |= (*pieces & 0x3) << 2;
|
2004-08-17 09:23:25 +00:00
|
|
|
return (*pieces == (ROAD_NE|ROAD_SW) || *pieces == (ROAD_SE|ROAD_NW)) ? _price.terraform : CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a piece of road.
|
|
|
|
* @param x,y tile coordinates for road construction
|
|
|
|
* @param p1 road piece flags
|
|
|
|
* @param p2 the town that is building the road (0 if not applicable)
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
|
|
|
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
TileInfo ti;
|
|
|
|
int32 cost;
|
|
|
|
byte pieces = (byte)p1, existing = 0;
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex tile;
|
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 */
|
|
|
|
if ((pieces >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
FindLandscapeHeight(&ti, x, y);
|
|
|
|
tile = ti.tile;
|
|
|
|
|
|
|
|
// allow building road under bridge
|
2005-05-09 22:33:00 +00:00
|
|
|
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (ti.type == MP_STREET) {
|
|
|
|
if (!(ti.map5 & 0xF0)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if ((pieces & (byte)ti.map5) == pieces)
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
existing = ti.map5;
|
|
|
|
} else {
|
|
|
|
if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10))
|
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
goto do_clear;
|
|
|
|
}
|
|
|
|
} else if (ti.type == MP_RAILWAY) {
|
|
|
|
byte m5;
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (!_valid_tileh_slopes_road[2][ti.tileh]) { // prevent certain slopes
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ti.map5 == 2) {
|
|
|
|
if (pieces & 5) goto do_clear;
|
|
|
|
m5 = 0x10;
|
|
|
|
} else if (ti.map5 == 1) {
|
|
|
|
if (pieces & 10) goto do_clear;
|
|
|
|
m5 = 0x18;
|
2006-02-13 21:15:00 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
goto do_clear;
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
ModifyTile(tile,
|
|
|
|
MP_SETTYPE(MP_STREET) |
|
2005-02-02 14:17:13 +00:00
|
|
|
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
|
|
|
|
p2,
|
2004-08-09 17:04:08 +00:00
|
|
|
_current_player, /* map3_lo */
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 & 0xF, /* map3_hi */
|
2004-08-09 17:04:08 +00:00
|
|
|
m5 /* map5 */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return _price.build_road * 2;
|
|
|
|
} else if (ti.type == MP_TUNNELBRIDGE) {
|
|
|
|
/* check for flat land */
|
2006-02-13 21:15:00 +00:00
|
|
|
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* is this middle part of a bridge? */
|
2006-02-13 21:15:00 +00:00
|
|
|
if ((ti.map5 & 0xC0) != 0xC0) goto do_clear;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* only allow roads pertendicular to bridge */
|
2006-02-13 21:15:00 +00:00
|
|
|
if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0)) goto do_clear;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* check if clear land under bridge */
|
2006-02-13 21:15:00 +00:00
|
|
|
if ((ti.map5 & 0xF8) == 0xE8) { /* road under bridge */
|
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
} else if ((ti.map5 & 0xE0) == 0xE0) { /* other transport route under bridge */
|
|
|
|
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
|
|
|
|
} else if ((ti.map5 & 0xF8) == 0xC8) { /* water under bridge */
|
|
|
|
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* all checked, can build road now! */
|
|
|
|
cost = _price.build_road * 2;
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
ModifyTile(tile,
|
|
|
|
MP_MAPOWNER_CURRENT | MP_MAP5,
|
|
|
|
(ti.map5 & 0xC7) | 0x28 // map5
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
} else {
|
|
|
|
do_clear:;
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR)))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cost = CheckRoadSlope(ti.tileh, &pieces, existing);
|
2005-05-09 22:33:00 +00:00
|
|
|
if (CmdFailed(cost)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-13 12:19:27 +00:00
|
|
|
if (cost && (!_patches.build_on_slopes || _is_old_ai_player))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (ti.type != MP_STREET || (ti.map5 & 0xF0) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
} else {
|
|
|
|
// Don't put the pieces that already exist
|
|
|
|
pieces &= ~ti.map5;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
byte t = pieces;
|
|
|
|
while (t) {
|
|
|
|
if (t & 1) cost += _price.build_road;
|
|
|
|
t >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if (ti.type != MP_STREET) {
|
2005-01-18 18:41:56 +00:00
|
|
|
SetTileType(tile, MP_STREET);
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = 0;
|
|
|
|
_m[tile].m2 = p2;
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, _current_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
_m[tile].m5 |= pieces;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec)
|
2004-08-09 17:04:08 +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
|
|
|
|
|
|
|
// not owned by me?
|
|
|
|
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
|
|
|
|
|
|
|
|
// tile is already of requested type?
|
2005-10-05 07:20:26 +00:00
|
|
|
if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (exec) {
|
|
|
|
// change type.
|
2005-10-05 07:20:26 +00:00
|
|
|
SB(_m[tile].m4, 0, 4, totype);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _price.build_rail >> 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
/** Build a long piece of road.
|
|
|
|
* @param x,y end tile of drag
|
|
|
|
* @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)
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex start_tile, end_tile, tile;
|
|
|
|
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;
|
2005-06-25 06:15:43 +00:00
|
|
|
end_tile = TileVirtXY(x, y);
|
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;
|
2004-08-09 17:04:08 +00:00
|
|
|
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cost = 0;
|
|
|
|
tile = start_tile;
|
|
|
|
// Start tile is the small number.
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
|
|
|
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE;
|
|
|
|
if (tile == end_tile && !HASBIT(p2, 1)) bits &= ROAD_NW | ROAD_NE;
|
|
|
|
if (tile == start_tile && HASBIT(p2, 0)) bits &= ROAD_SE | ROAD_SW;
|
|
|
|
|
|
|
|
ret = DoCommandByTile(tile, bits, 0, flags, CMD_BUILD_ROAD);
|
|
|
|
if (CmdFailed(ret)) {
|
|
|
|
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
|
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.
|
|
|
|
* @param x,y end tile of drag
|
|
|
|
* @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)
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex start_tile, end_tile, tile;
|
|
|
|
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;
|
2005-06-25 06:15:43 +00:00
|
|
|
end_tile = TileVirtXY(x, y);
|
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;
|
|
|
|
// Start tile is the small number.
|
2005-05-09 22:33:00 +00:00
|
|
|
for (;;) {
|
|
|
|
uint bits = HASBIT(p2, 2) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE;
|
|
|
|
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
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// try to remove the halves.
|
|
|
|
if (bits) {
|
|
|
|
ret = DoCommandByTile(tile, 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.
|
|
|
|
* @param x,y tile coordinates where the depot will be built
|
|
|
|
* @param p1 depot direction (0 through 3), where 0 is NW, 1 is NE, etc.
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
TileInfo ti;
|
|
|
|
int32 cost;
|
|
|
|
Depot *dep;
|
2005-05-09 22:33:00 +00:00
|
|
|
TileIndex tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-05-10 08:45:55 +00:00
|
|
|
if (p1 > 3) return CMD_ERROR; // check direction
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
FindLandscapeHeight(&ti, x, y);
|
|
|
|
|
|
|
|
tile = ti.tile;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (ti.tileh != 0 && (
|
|
|
|
!_patches.build_on_slopes ||
|
|
|
|
IsSteepTileh(ti.tileh) ||
|
|
|
|
!CanBuildDepotByTileh(p1, ti.tileh)
|
|
|
|
)) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cost = DoCommandByTile(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
|
|
|
|
|
|
|
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) {
|
2005-09-14 18:03:38 +00:00
|
|
|
if (IsLocalPlayer()) _last_built_road_depot_tile = tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
dep->xy = tile;
|
|
|
|
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
|
|
|
|
|
|
|
ModifyTile(tile,
|
|
|
|
MP_SETTYPE(MP_STREET) |
|
|
|
|
MP_MAPOWNER_CURRENT | MP_MAP5,
|
|
|
|
(p1 | 0x20) /* map5 */
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (flags & DC_EXEC) DoDeleteDepot(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return _price.remove_road_depot;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define M(x) (1<<(x))
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Road(TileIndex tile, byte flags)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int32 ret;
|
2005-07-13 18:04:01 +00:00
|
|
|
byte m5 = _m[tile].m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if ( (m5 & 0xF0) == 0) {
|
|
|
|
byte b = m5 & 0xF;
|
|
|
|
|
|
|
|
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) {
|
2005-06-04 11:56:32 +00:00
|
|
|
if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO)
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
|
|
|
}
|
|
|
|
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD);
|
|
|
|
} else if ( (m5 & 0xE0) == 0) {
|
|
|
|
if (flags & DC_AUTO)
|
|
|
|
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
|
|
|
|
|
|
|
|
ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD);
|
2005-12-10 12:05:39 +00:00
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
if (flags & DC_AUTO)
|
|
|
|
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
|
|
return RemoveRoadDepot(tile,flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct DrawRoadTileStruct {
|
|
|
|
uint16 image;
|
|
|
|
byte subcoord_x;
|
|
|
|
byte subcoord_y;
|
|
|
|
} DrawRoadTileStruct;
|
|
|
|
|
|
|
|
typedef struct DrawRoadSeqStruct {
|
|
|
|
uint32 image;
|
|
|
|
byte subcoord_x;
|
|
|
|
byte subcoord_y;
|
|
|
|
byte width;
|
|
|
|
byte height;
|
|
|
|
} DrawRoadSeqStruct;
|
|
|
|
|
|
|
|
#include "table/road_land.h"
|
|
|
|
|
|
|
|
|
2005-10-22 06:39:32 +00:00
|
|
|
uint GetRoadFoundation(uint tileh, uint bits)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int i;
|
|
|
|
// normal level sloped building
|
2006-02-13 21:15:00 +00:00
|
|
|
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return tileh;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// inclined sloped building
|
2006-02-13 21:15:00 +00:00
|
|
|
if ((
|
|
|
|
(i = 0, tileh == 1) ||
|
|
|
|
(i += 2, tileh == 2) ||
|
|
|
|
(i += 2, tileh == 4) ||
|
|
|
|
(i += 2, tileh == 8)
|
|
|
|
) && (
|
|
|
|
( bits == (ROAD_SW | ROAD_NE)) ||
|
|
|
|
(i++, bits == (ROAD_NW | ROAD_SE))
|
|
|
|
)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return i + 15;
|
2006-02-13 21:15:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-10 18:35:43 +00:00
|
|
|
// rail crossing
|
2006-02-13 21:15:00 +00:00
|
|
|
if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh]) return tileh;
|
2004-08-10 18:35:43 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const byte _road_sloped_sprites[14] = {
|
|
|
|
0, 0, 2, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
3, 0, 0, 0,
|
|
|
|
0, 0
|
|
|
|
};
|
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
/**
|
|
|
|
* Draw ground sprite and road pieces
|
|
|
|
* @param ti TileInfo
|
|
|
|
* @param road RoadBits to draw
|
|
|
|
* @param ground_type Ground type
|
|
|
|
* @param snow Draw snow
|
|
|
|
* @param flat Draw foundation
|
|
|
|
*/
|
2006-01-05 12:40:50 +00:00
|
|
|
static void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool flat)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-09-29 19:59:57 +00:00
|
|
|
const DrawRoadTileStruct *drts;
|
|
|
|
PalSpriteID image = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
if (ti->tileh != 0) {
|
|
|
|
int foundation;
|
|
|
|
if (flat) {
|
|
|
|
foundation = ti->tileh;
|
|
|
|
} else {
|
|
|
|
foundation = GetRoadFoundation(ti->tileh, road);
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (foundation != 0) DrawFoundation(ti, foundation);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
// DrawFoundation() modifies ti.
|
|
|
|
// Default sloped sprites..
|
2005-11-14 19:48:04 +00:00
|
|
|
if (ti->tileh != 0) 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
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (ground_type == 0) image |= PALETTE_TO_BARE_LAND;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
if (snow) {
|
|
|
|
image += 19;
|
|
|
|
} else if (ground_type > 1 && ground_type != 6) {
|
|
|
|
// Pavement tiles.
|
|
|
|
image -= 19;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
DrawGroundSprite(image);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
// Return if full detail is disabled, or we are zoomed fully out.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
if (ground_type >= 6) {
|
|
|
|
// Road works
|
2006-01-23 17:43:46 +00:00
|
|
|
DrawGroundSprite(HASBIT(road, 3) ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y);
|
2005-09-29 19:59:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-29 19:59:57 +00:00
|
|
|
// Draw extra details.
|
2006-02-13 21:15:00 +00:00
|
|
|
for (drts = _road_display_table[ground_type][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;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (ti->tileh != 0) z = GetSlopeZ(x, y);
|
2006-02-13 21:15:00 +00:00
|
|
|
AddSortableSpriteToDraw(drts->image, 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)
|
|
|
|
{
|
|
|
|
PalSpriteID image;
|
|
|
|
uint16 m2;
|
|
|
|
|
|
|
|
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0
|
|
|
|
DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false);
|
2004-08-10 18:35:43 +00:00
|
|
|
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing
|
|
|
|
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
|
|
|
|
if (f) DrawFoundation(ti, f);
|
|
|
|
|
2005-10-13 16:00:14 +00:00
|
|
|
image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-13 16:00:14 +00:00
|
|
|
if (GB(ti->map5, 3, 1) == 0) image++; /* direction */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if ( (ti->map5 & 4) != 0)
|
|
|
|
image += 2;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
if ( _m[ti->tile].m4 & 0x80) {
|
2004-08-09 17:04:08 +00:00
|
|
|
image += 8;
|
|
|
|
} else {
|
2005-07-20 15:29:28 +00:00
|
|
|
m2 = GB(_m[ti->tile].m4, 4, 3);
|
2005-07-24 15:56:31 +00:00
|
|
|
if (m2 == 0) image |= PALETTE_TO_BARE_LAND;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m2 > 1) image += 4;
|
|
|
|
}
|
|
|
|
|
2005-10-13 16:00:14 +00:00
|
|
|
DrawGroundSprite(image);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
uint32 ormod;
|
2005-10-20 17:43:13 +00:00
|
|
|
PlayerID player;
|
2004-08-09 17:04:08 +00:00
|
|
|
const DrawRoadSeqStruct *drss;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
|
|
|
|
|
2005-07-24 15:56:31 +00:00
|
|
|
ormod = PALETTE_TO_GREY; //was this a bug/problem?
|
2005-06-04 11:56:32 +00:00
|
|
|
player = GetTileOwner(ti->tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (player < MAX_PLAYERS)
|
|
|
|
ormod = PLAYER_SPRITE_COLOR(player);
|
|
|
|
|
2005-02-22 15:39:45 +00:00
|
|
|
drss = _road_display_datas[ti->map5 & 0xF];
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-02-22 15:39:45 +00:00
|
|
|
DrawGroundSprite(drss++->image);
|
|
|
|
|
|
|
|
for (; drss->image != 0; drss++) {
|
|
|
|
uint32 image = drss->image;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-24 15:56:31 +00:00
|
|
|
if (image & PALETTE_MODIFIER_COLOR)
|
2004-08-09 17:04:08 +00:00
|
|
|
image |= ormod;
|
2004-11-23 22:36:11 +00:00
|
|
|
if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots
|
2005-07-20 22:05:13 +00:00
|
|
|
MAKE_TRANSPARENT(image);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-11 09:55:19 +00:00
|
|
|
AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
|
2004-08-09 17:04:08 +00:00
|
|
|
ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawRoadDepotSprite(int x, int y, int image)
|
|
|
|
{
|
|
|
|
uint32 ormod;
|
|
|
|
const DrawRoadSeqStruct *dtss;
|
|
|
|
|
|
|
|
ormod = PLAYER_SPRITE_COLOR(_local_player);
|
|
|
|
|
2005-02-22 15:39:45 +00:00
|
|
|
dtss = _road_display_datas[image];
|
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
|
|
|
|
2005-02-22 15:39:45 +00:00
|
|
|
DrawSprite(dtss++->image, x, y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (; dtss->image != 0; dtss++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
image = dtss->image;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawSprite(image, x + pt.x, y + pt.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-19 14:49:46 +00:00
|
|
|
static uint GetSlopeZ_Road(const TileInfo* ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint z = ti->z;
|
|
|
|
int th = ti->tileh;
|
|
|
|
|
|
|
|
// check if it's a foundation
|
|
|
|
if (ti->tileh != 0) {
|
2004-08-10 18:35:43 +00:00
|
|
|
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
|
2004-08-09 17:04:08 +00:00
|
|
|
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
|
|
|
|
if (f != 0) {
|
|
|
|
if (f < 15) {
|
|
|
|
// leveled foundation
|
|
|
|
return z + 8;
|
|
|
|
}
|
|
|
|
// inclined foundation
|
|
|
|
th = _inclined_tileh[f - 15];
|
|
|
|
}
|
|
|
|
} else if ((ti->map5 & 0xF0) == 0x20) {
|
|
|
|
// depot
|
|
|
|
return z + 8;
|
|
|
|
}
|
|
|
|
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
|
|
|
|
}
|
2004-08-13 18:27:33 +00:00
|
|
|
return z; // normal Z if no slope
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static uint GetSlopeTileh_Road(const TileInfo *ti)
|
2004-08-13 18:27:33 +00:00
|
|
|
{
|
|
|
|
// check if it's a foundation
|
|
|
|
if (ti->tileh != 0) {
|
|
|
|
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
|
|
|
|
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
|
|
|
|
if (f != 0) {
|
|
|
|
if (f < 15) {
|
|
|
|
// leveled foundation
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// inclined foundation
|
|
|
|
return _inclined_tileh[f - 15];
|
|
|
|
}
|
|
|
|
} else if ((ti->map5 & 0xF0) == 0x20) {
|
|
|
|
// depot
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ti->tileh;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _town_road_types[5][2] = {
|
|
|
|
{1,1},
|
|
|
|
{2,2},
|
|
|
|
{2,2},
|
|
|
|
{5,5},
|
|
|
|
{3,2},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte _town_road_types_2[5][2] = {
|
|
|
|
{1,1},
|
|
|
|
{2,2},
|
|
|
|
{3,2},
|
|
|
|
{3,2},
|
|
|
|
{3,2},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Town *t;
|
|
|
|
int grp;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
switch (_opt.landscape) {
|
|
|
|
case LT_HILLY:
|
|
|
|
if ((_m[tile].m4 & 0x80) != (GetTileZ(tile) > _opt.snow_line ? 0x80 : 0x00)) {
|
|
|
|
_m[tile].m4 ^= 0x80;
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_DESERT:
|
|
|
|
if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
|
|
|
|
_m[tile].m4 |= 0x80;
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (_m[tile].m5 & 0xE0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-20 15:29:28 +00:00
|
|
|
if (GB(_m[tile].m4, 4, 3) < 6) {
|
2005-02-04 14:05:28 +00:00
|
|
|
t = ClosestTownFromTile(tile, (uint)-1);
|
2005-02-04 13:56:51 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
grp = 0;
|
|
|
|
if (t != NULL) {
|
|
|
|
grp = GetTownRadiusGroup(t, tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Show an animation to indicate road work
|
2004-09-11 09:55:19 +00:00
|
|
|
if (t->road_build_months != 0 &&
|
2005-01-31 07:23:15 +00:00
|
|
|
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) &&
|
2006-02-13 21:15:00 +00:00
|
|
|
(_m[tile].m5 == 5 || _m[tile].m5 == 10)) {
|
|
|
|
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1, 20)) {
|
2005-07-20 15:29:28 +00:00
|
|
|
_m[tile].m4 |= (GB(_m[tile].m4, 4, 3) <= 2 ? 7 : 6) << 4;
|
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(
|
2005-01-07 17:02:43 +00:00
|
|
|
TileX(tile) * 16 + 7,
|
|
|
|
TileY(tile) * 16 + 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
|
2005-07-20 15:29:28 +00:00
|
|
|
byte b = GB(_m[tile].m4, 4, 3);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-13 21:15:00 +00:00
|
|
|
if (b == p[0]) return;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (b == p[1]) {
|
|
|
|
b = p[0];
|
|
|
|
} else if (b == 0) {
|
|
|
|
b = p[1];
|
|
|
|
} else {
|
|
|
|
b = 0;
|
|
|
|
}
|
2005-10-05 07:20:26 +00:00
|
|
|
SB(_m[tile].m4, 4, 3, b);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Handle road work
|
2005-02-02 14:17:13 +00:00
|
|
|
//XXX undocumented
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
byte b = _m[tile].m4;
|
2005-02-02 14:17:13 +00:00
|
|
|
//roadworks take place only
|
|
|
|
//keep roadworks running for 16 loops
|
|
|
|
//lower 4 bits of map3_hi store the counter now
|
|
|
|
if ((b & 0xF) != 0xF) {
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m4 = b + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-02-02 14:17:13 +00:00
|
|
|
//roadworks finished
|
2005-07-20 15:29:28 +00:00
|
|
|
_m[tile].m4 = (GB(b, 4, 3) == 6 ? 1 : 2) << 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void ShowRoadDepotWindow(TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Road(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-05 07:20:26 +00:00
|
|
|
if (GB(_m[tile].m5, 4, 4) == 2) ShowRoadDepotWindow(tile);
|
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)
|
|
|
|
{
|
2004-09-05 16:15:22 +00:00
|
|
|
if (mode == TRANSPORT_RAIL) {
|
2005-06-07 21:37:00 +00:00
|
|
|
if (!IsLevelCrossing(tile))
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
2005-07-13 18:04:01 +00:00
|
|
|
return _m[tile].m5 & 8 ? 0x101 : 0x202;
|
2004-09-05 16:15:22 +00:00
|
|
|
} else if (mode == TRANSPORT_ROAD) {
|
2005-07-13 18:04:01 +00:00
|
|
|
byte b = _m[tile].m5;
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((b & 0xF0) == 0) {
|
2004-09-05 16:15:22 +00:00
|
|
|
/* Ordinary road */
|
2005-07-20 15:29:28 +00:00
|
|
|
if (!_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6)
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
return _road_trackbits[b&0xF] * 0x101;
|
2005-06-07 21:37:00 +00:00
|
|
|
} else if (IsLevelCrossing(tile)) {
|
2004-09-05 16:15:22 +00:00
|
|
|
/* Crossing */
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r = 0x101;
|
|
|
|
if (b&8) r <<= 1;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (b&4) {
|
|
|
|
r *= 0x10001;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const StringID _road_tile_strings[] = {
|
|
|
|
STR_1818_ROAD_RAIL_LEVEL_CROSSING,
|
|
|
|
STR_1817_ROAD_VEHICLE_DEPOT,
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2006-02-06 09:18:04 +00:00
|
|
|
int i = GB(_m[tile].m5, 4, 4);
|
|
|
|
if (i == 0) i = GB(_m[tile].m4, 4, 3) + 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
td->str = _road_tile_strings[i - 1];
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
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
|
|
|
{
|
2005-06-07 21:37:00 +00:00
|
|
|
if (IsLevelCrossing(tile)) {
|
2005-10-05 07:20:26 +00:00
|
|
|
if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
/* train crossing a road */
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
|
2005-10-05 07:20:26 +00:00
|
|
|
SB(_m[tile].m5, 2, 1, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2005-10-05 07:20:26 +00:00
|
|
|
} else if (GB(_m[tile].m5, 4, 4) == 2) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->type == VEH_Road && v->u.road.frame == 11) {
|
2005-10-05 07:20:26 +00:00
|
|
|
if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) {
|
2004-08-09 17:04:08 +00:00
|
|
|
RoadVehEnterDepot(v);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-07 21:37:00 +00:00
|
|
|
if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
|
|
|
|
// Turn off level crossing lights
|
2005-10-05 07:20:26 +00:00
|
|
|
SB(_m[tile].m5, 2, 1, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
// road/rail crossing where the road is owned by the current player?
|
2005-07-13 18:04:01 +00:00
|
|
|
if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
|
2005-09-28 19:35:36 +00:00
|
|
|
_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-04 11:56:32 +00:00
|
|
|
if (!IsTileOwner(tile, old_player)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-10 10:36:37 +00:00
|
|
|
if (new_player != OWNER_SPECTATOR) {
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, new_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-10-05 07:20:26 +00:00
|
|
|
if (GB(_m[tile].m5, 4, 4) == 0) {
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
2005-06-07 21:37:00 +00:00
|
|
|
} else if (IsLevelCrossing(tile)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA;
|
|
|
|
SetTileOwner(tile, _m[tile].m3);
|
|
|
|
_m[tile].m3 = 0;
|
|
|
|
_m[tile].m4 &= 0x80;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeRoad(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_last_built_road_depot_tile = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TileTypeProcs _tile_type_road_procs = {
|
|
|
|
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 */
|
|
|
|
VehicleLeave_Road, /* vehicle_leave_tile_proc */
|
2004-08-13 18:27:33 +00:00
|
|
|
GetSlopeTileh_Road, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|