mirror of https://github.com/OpenTTD/OpenTTD
(svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
parent
929fae7b68
commit
e63e3bb84c
|
@ -11,6 +11,7 @@
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "tree_map.h"
|
#include "tree_map.h"
|
||||||
|
#include "tunnel_map.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
|
@ -345,12 +346,17 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
|
||||||
TileType t = GetTileType(tile);
|
TileType t = GetTileType(tile);
|
||||||
|
|
||||||
if (t == MP_TUNNELBRIDGE) {
|
if (t == MP_TUNNELBRIDGE) {
|
||||||
t = _m[tile].m5;
|
TransportType tt;
|
||||||
if ((t & 0x80) == 0) t >>= 1;
|
|
||||||
switch (t & 0x06) {
|
if (_m[tile].m5 & 0x80) {
|
||||||
case 0x00: t = MP_RAILWAY; break;
|
tt = GB(_m[tile].m5, 1, 2);
|
||||||
case 0x02: t = MP_STREET; break;
|
} else {
|
||||||
default: t = MP_WATER; break;
|
tt = GetTunnelTransportType(tile);
|
||||||
|
}
|
||||||
|
switch (tt) {
|
||||||
|
case TRANSPORT_RAIL: t = MP_RAILWAY; break;
|
||||||
|
case TRANSPORT_ROAD: t = MP_STREET; break;
|
||||||
|
default: t = MP_WATER; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
|
|
@ -195,7 +195,9 @@ bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
|
||||||
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
int bridge_type;
|
int bridge_type;
|
||||||
byte rail_or_road, railtype, m5;
|
byte m5;
|
||||||
|
TransportType transport;
|
||||||
|
RailType railtype;
|
||||||
int sx,sy;
|
int sx,sy;
|
||||||
TileInfo ti_start, ti_end;
|
TileInfo ti_start, ti_end;
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
|
@ -211,17 +213,17 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
/* unpack parameters */
|
/* unpack parameters */
|
||||||
bridge_type = GB(p2, 0, 8);
|
bridge_type = GB(p2, 0, 8);
|
||||||
railtype = GB(p2, 8, 8);
|
|
||||||
|
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
if (p1 >= MapSize()) return CMD_ERROR;
|
||||||
|
|
||||||
// type of bridge
|
// type of bridge
|
||||||
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param
|
if (HASBIT(p2, 15)) {
|
||||||
railtype = 0;
|
railtype = 0;
|
||||||
rail_or_road = 2;
|
transport = TRANSPORT_ROAD;
|
||||||
} else {
|
} else {
|
||||||
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
|
||||||
rail_or_road = 0;
|
railtype = GB(p2, 8, 8);
|
||||||
|
transport = TRANSPORT_RAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sx = TileX(p1) * 16;
|
sx = TileX(p1) * 16;
|
||||||
|
@ -311,7 +313,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
|
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
|
||||||
(bridge_type << 4), /* map2 */
|
(bridge_type << 4), /* map2 */
|
||||||
railtype, /* map3_lo */
|
railtype, /* map3_lo */
|
||||||
0x80 | direction | rail_or_road /* map5 */
|
0x80 | direction | transport << 1 /* map5 */
|
||||||
);
|
);
|
||||||
|
|
||||||
/* build the end tile */
|
/* build the end tile */
|
||||||
|
@ -320,7 +322,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
|
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
|
||||||
(bridge_type << 4), /* map2 */
|
(bridge_type << 4), /* map2 */
|
||||||
railtype, /* map3_lo */
|
railtype, /* map3_lo */
|
||||||
0x80 | 0x20 | direction | rail_or_road /* map5 */
|
0x80 | 0x20 | direction | transport << 1 /* map5 */
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +376,7 @@ not_valid_below:;
|
||||||
|
|
||||||
/* do middle part of bridge */
|
/* do middle part of bridge */
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
_m[tile].m5 = (byte)(m5 | direction | rail_or_road);
|
_m[tile].m5 = (byte)(m5 | direction | transport << 1);
|
||||||
SetTileType(tile, MP_TUNNELBRIDGE);
|
SetTileType(tile, MP_TUNNELBRIDGE);
|
||||||
|
|
||||||
//bridges pieces sequence (middle parts)
|
//bridges pieces sequence (middle parts)
|
||||||
|
|
Loading…
Reference in New Issue