diff options
author | tron <tron@openttd.org> | 2006-03-01 08:56:38 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-03-01 08:56:38 +0000 |
commit | b404072ccc43fad529e8cf13532e646d3d4767d5 (patch) | |
tree | c9a6270610c574618ee43157834cb8fe59329fe0 | |
parent | 6c1576143bb031c7c0ebb94f6b45dc6ce007382f (diff) | |
download | openttd-b404072ccc43fad529e8cf13532e646d3d4767d5.tar.xz |
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
-rw-r--r-- | rail_cmd.c | 17 | ||||
-rw-r--r-- | rail_map.h | 49 | ||||
-rw-r--r-- | road_cmd.c | 15 | ||||
-rw-r--r-- | waypoint.c | 19 |
4 files changed, 71 insertions, 29 deletions
diff --git a/rail_cmd.c b/rail_cmd.c index 099c2a859..eb98ce8b8 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "rail_map.h" #include "road.h" #include "table/sprites.h" #include "table/strings.h" @@ -372,13 +373,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (CmdFailed(ret)) return ret; cost += ret; - if (flags & DC_EXEC) { - SetTileType(tile, MP_RAILWAY); - SetTileOwner(tile, _current_player); - _m[tile].m2 = 0; // Bare land - _m[tile].m3 = p1; // No signals, rail type - _m[tile].m5 = trackbit; - } + if (flags & DC_EXEC) MakeRailNormal(tile, _current_player, trackbit, p1); break; } @@ -681,12 +676,8 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { if (IsLocalPlayer()) _last_built_train_depot_tile = tile; - ModifyTile(tile, - MP_SETTYPE(MP_RAILWAY) | - MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, - p1, /* map3_lo */ - p2 | RAIL_TYPE_DEPOT_WAYPOINT /* map5 */ - ); + MakeRailDepot(tile, _current_player, p2, p1); + MarkTileDirtyByTile(tile); d->xy = tile; d->town_index = ClosestTownFromTile(tile, (uint)-1)->index; diff --git a/rail_map.h b/rail_map.h new file mode 100644 index 000000000..35a0ddfd3 --- /dev/null +++ b/rail_map.h @@ -0,0 +1,49 @@ +/* $Id$ */ + +#ifndef RAIL_MAP_H +#define RAIL_MAP_H + +#include "rail.h" +#include "tile.h" +#include "waypoint.h" + + +static inline TrackBits GetRailWaypointBits(TileIndex t) +{ + return _m[t].m5 & RAIL_WAYPOINT_TRACK_MASK ? TRACK_BIT_DIAG2 : TRACK_BIT_DIAG1; +} + + +static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r) +{ + SetTileType(t, MP_RAILWAY); + SetTileOwner(t, o); + _m[t].m2 = 0; + _m[t].m3 = r; + _m[t].m4 = 0; + _m[t].m5 = RAIL_TYPE_NORMAL | b; +} + + +static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r) +{ + SetTileType(t, MP_RAILWAY); + SetTileOwner(t, o); + _m[t].m2 = 0; + _m[t].m3 = r; + _m[t].m4 = 0; + _m[t].m5 = RAIL_TYPE_DEPOT_WAYPOINT | RAIL_SUBTYPE_DEPOT | d; +} + + +static inline void MakeRailWaypoint(TileIndex t, Owner o, Axis a, RailType r, uint index) +{ + SetTileType(t, MP_RAILWAY); + SetTileOwner(t, o); + _m[t].m2 = index; + _m[t].m3 = r; + _m[t].m4 = 0; + _m[t].m5 = RAIL_TYPE_DEPOT_WAYPOINT | RAIL_SUBTYPE_WAYPOINT | a; +} + +#endif diff --git a/road_cmd.c b/road_cmd.c index 589b274ef..3b2c8164e 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -2,6 +2,7 @@ #include "stdafx.h" #include "openttd.h" +#include "rail_map.h" #include "road.h" #include "table/sprites.h" #include "table/strings.h" @@ -234,26 +235,22 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) } case ROAD_CROSSING: { - byte c; + TrackBits track; if (!(ti.map5 & 8)) { - c = 2; if (pieces & ROAD_Y) goto return_error; + track = TRACK_BIT_DIAG2; } else { - c = 1; if (pieces & ROAD_X) goto return_error; + track = TRACK_BIT_DIAG1; } cost = _price.remove_road * 2; if (flags & DC_EXEC) { ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); - ModifyTile(tile, - MP_SETTYPE(MP_RAILWAY) | - MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, - _m[tile].m4 & 0xF, /* map3_lo */ - c /* map5 */ - ); + MakeRailNormal(tile, GetTileOwner(tile), track, GB(_m[tile].m4, 0, 4)); + MarkTileDirtyByTile(tile); } return cost; } diff --git a/waypoint.c b/waypoint.c index d3eff1603..dbe5728ea 100644 --- a/waypoint.c +++ b/waypoint.c @@ -8,6 +8,7 @@ #include "gfx.h" #include "map.h" #include "order.h" +#include "rail_map.h" #include "saveload.h" #include "station.h" #include "tile.h" @@ -174,15 +175,19 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) TileIndex tile = TileVirtXY(x, y); Waypoint *wp; uint tileh; - uint dir; + Axis axis; SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); /* if custom gfx are used, make sure it is within bounds */ if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR; - if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _m[tile].m5 != 1) && (dir = 1, _m[tile].m5 != 2))) + if (!IsTileType(tile, MP_RAILWAY) || ( + (axis = AXIS_X, _m[tile].m5 != TRACK_BIT_DIAG1) && + (axis = AXIS_Y, _m[tile].m5 != TRACK_BIT_DIAG2) + )) { return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); + } if (!CheckTileOwnership(tile)) return CMD_ERROR; @@ -191,7 +196,7 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) tileh = GetTileSlope(tile, NULL); if (tileh != 0) { - if (!_patches.build_on_slopes || IsSteepTileh(tileh) || !(tileh & (0x3 << dir)) || !(tileh & ~(0x3 << dir))) + if (!_patches.build_on_slopes || IsSteepTileh(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis))) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); } @@ -208,7 +213,8 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { const StationSpec *spec = NULL; - ModifyTile(tile, MP_MAP2 | MP_MAP5, wp->index, RAIL_TYPE_WAYPOINT | dir); + MakeRailWaypoint(tile, GetTileOwner(tile), axis, GB(_m[tile].m3, 0, 4), wp->index); + MarkTileDirtyByTile(tile); if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP)) spec = GetCustomStation(STAT_CLASS_WAYP, GB(p1, 0, 8)); @@ -294,9 +300,8 @@ int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove) RedrawWaypointSign(wp); if (justremove) { - ModifyTile(tile, MP_MAP2_CLEAR | MP_MAP5, 1<<direction); - CLRBIT(_m[tile].m3, 4); - _m[tile].m4 = 0; + MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GB(_m[tile].m3, 0, 4)); + MarkTileDirtyByTile(tile); } else { DoClearSquare(tile); SetSignalsOnBothDir(tile, direction); |