mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3689) Add functions to turn a tile into either a normal road tile, a level crossing or a road depot
This commit is contained in:
parent
530a44436c
commit
0d044cabca
|
@ -354,10 +354,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
(track == TRACK_DIAG2 && m5 == ROAD_X) // correct direction?
|
(track == TRACK_DIAG2 && m5 == ROAD_X) // correct direction?
|
||||||
)) {
|
)) {
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
_m[tile].m3 = GetTileOwner(tile);
|
MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_DIAG1 ? AXIS_Y : AXIS_X), p1, _m[tile].m2);
|
||||||
SetTileOwner(tile, _current_player);
|
|
||||||
_m[tile].m4 = p1;
|
|
||||||
_m[tile].m5 = 0x10 | (track == TRACK_DIAG1 ? 0x08 : 0x00); // level crossing
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -460,9 +457,7 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (!(flags & DC_EXEC))
|
if (!(flags & DC_EXEC))
|
||||||
return _price.remove_rail;
|
return _price.remove_rail;
|
||||||
|
|
||||||
SetTileOwner(tile, _m[tile].m3);
|
MakeRoadNormal(tile, _m[tile].m3, bits, 0);
|
||||||
_m[tile].m2 = 0;
|
|
||||||
_m[tile].m5 = (ROAD_NORMAL << 4) | bits;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
road.h
35
road.h
|
@ -4,6 +4,8 @@
|
||||||
#define ROAD_H
|
#define ROAD_H
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
#include "rail.h"
|
||||||
|
#include "tile.h"
|
||||||
|
|
||||||
typedef enum RoadBits {
|
typedef enum RoadBits {
|
||||||
ROAD_NW = 1,
|
ROAD_NW = 1,
|
||||||
|
@ -36,4 +38,37 @@ static inline RoadType GetRoadType(TileIndex tile)
|
||||||
return GB(_m[tile].m5, 4, 4);
|
return GB(_m[tile].m5, 4, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town)
|
||||||
|
{
|
||||||
|
SetTileType(t, MP_STREET);
|
||||||
|
SetTileOwner(t, owner);
|
||||||
|
_m[t].m2 = town;
|
||||||
|
_m[t].m3 = 0;
|
||||||
|
_m[t].m4 = 0 << 7 | 0 << 4 | 0;
|
||||||
|
_m[t].m5 = ROAD_NORMAL << 4 | bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
|
||||||
|
{
|
||||||
|
SetTileType(t, MP_STREET);
|
||||||
|
SetTileOwner(t, rail);
|
||||||
|
_m[t].m2 = town;
|
||||||
|
_m[t].m3 = road;
|
||||||
|
_m[t].m4 = 0 << 7 | 0 << 4 | rt;
|
||||||
|
_m[t].m5 = ROAD_CROSSING << 4 | roaddir << 3 | 0 << 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)
|
||||||
|
{
|
||||||
|
SetTileType(t, MP_STREET);
|
||||||
|
SetTileOwner(t, owner);
|
||||||
|
_m[t].m2 = 0;
|
||||||
|
_m[t].m3 = 0;
|
||||||
|
_m[t].m4 = 0;
|
||||||
|
_m[t].m5 = ROAD_DEPOT << 4 | dir;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
36
road_cmd.c
36
road_cmd.c
|
@ -386,7 +386,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_RAILWAY: {
|
case MP_RAILWAY: {
|
||||||
byte m5;
|
Axis roaddir;
|
||||||
|
|
||||||
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
if (IsSteepTileh(ti.tileh)) { // very steep tile
|
||||||
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
|
@ -398,23 +398,16 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
if (ti.map5 == 2) {
|
if (ti.map5 == 2) {
|
||||||
if (pieces & ROAD_Y) goto do_clear;
|
if (pieces & ROAD_Y) goto do_clear;
|
||||||
m5 = 0x10;
|
roaddir = AXIS_X;
|
||||||
} else if (ti.map5 == 1) {
|
} else if (ti.map5 == 1) {
|
||||||
if (pieces & ROAD_X) goto do_clear;
|
if (pieces & ROAD_X) goto do_clear;
|
||||||
m5 = 0x18;
|
roaddir = AXIS_Y;
|
||||||
} else {
|
} else {
|
||||||
goto do_clear;
|
goto do_clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
ModifyTile(tile,
|
MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GB(_m[tile].m3, 0, 4), p2);
|
||||||
MP_SETTYPE(MP_STREET) |
|
|
||||||
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
|
|
||||||
p2,
|
|
||||||
_current_player, /* map3_lo */
|
|
||||||
_m[tile].m3 & 0xF, /* map3_hi */
|
|
||||||
m5 /* map5 */
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return _price.build_road * 2;
|
return _price.build_road * 2;
|
||||||
}
|
}
|
||||||
|
@ -479,14 +472,11 @@ do_clear:;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (ti.type != MP_STREET) {
|
if (ti.type != MP_STREET) {
|
||||||
SetTileType(tile, MP_STREET);
|
MakeRoadNormal(tile, _current_player, pieces, p2);
|
||||||
_m[tile].m5 = 0;
|
} else {
|
||||||
_m[tile].m2 = p2;
|
_m[tile].m5 |= pieces;
|
||||||
SetTileOwner(tile, _current_player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_m[tile].m5 |= pieces;
|
|
||||||
|
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
|
@ -668,12 +658,7 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
dep->xy = tile;
|
dep->xy = tile;
|
||||||
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
||||||
|
|
||||||
ModifyTile(tile,
|
MakeRoadDepot(tile, _current_player, p1);
|
||||||
MP_SETTYPE(MP_STREET) |
|
|
||||||
MP_MAPOWNER_CURRENT | MP_MAP5,
|
|
||||||
(ROAD_DEPOT << 4) | p1 /* map5 */
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return cost + _price.build_road_depot;
|
return cost + _price.build_road_depot;
|
||||||
}
|
}
|
||||||
|
@ -1215,10 +1200,7 @@ static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID n
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROAD_CROSSING:
|
case ROAD_CROSSING:
|
||||||
SetTileOwner(tile, _m[tile].m3);
|
MakeRoadNormal(tile, _m[tile].m3, GetCrossingRoadBits(tile), _m[tile].m2);
|
||||||
_m[tile].m3 = 0;
|
|
||||||
_m[tile].m4 &= 0x80;
|
|
||||||
_m[tile].m5 = (ROAD_NORMAL << 4) | GetCrossingRoadBits(tile);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
6
tile.h
6
tile.h
|
@ -44,6 +44,12 @@ typedef enum DiagonalDirections {
|
||||||
INVALID_DIAGDIR = 0xFF,
|
INVALID_DIAGDIR = 0xFF,
|
||||||
} DiagDirection;
|
} DiagDirection;
|
||||||
|
|
||||||
|
/* the 2 axis */
|
||||||
|
typedef enum Axis {
|
||||||
|
AXIS_X = 0,
|
||||||
|
AXIS_Y = 1
|
||||||
|
} Axis;
|
||||||
|
|
||||||
void SetMapExtraBits(TileIndex tile, byte flags);
|
void SetMapExtraBits(TileIndex tile, byte flags);
|
||||||
uint GetMapExtraBits(TileIndex tile);
|
uint GetMapExtraBits(TileIndex tile);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue