diff options
-rw-r--r-- | ai/default/default.c | 15 | ||||
-rw-r--r-- | ai/trolly/trolly.c | 5 | ||||
-rw-r--r-- | aircraft_cmd.c | 5 | ||||
-rw-r--r-- | aircraft_gui.c | 3 | ||||
-rw-r--r-- | disaster_cmd.c | 7 | ||||
-rw-r--r-- | npf.c | 3 | ||||
-rw-r--r-- | order_gui.c | 7 | ||||
-rw-r--r-- | roadveh_cmd.c | 5 | ||||
-rw-r--r-- | station_cmd.c | 33 | ||||
-rw-r--r-- | station_map.h | 14 | ||||
-rw-r--r-- | train_cmd.c | 23 |
11 files changed, 74 insertions, 46 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index 4ba475e06..e87079dc5 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -7,6 +7,7 @@ #include "../../map.h" #include "../../rail_map.h" #include "../../road_map.h" +#include "../../station_map.h" #include "../../tile.h" #include "../../player.h" #include "../../tunnel_map.h" @@ -2313,11 +2314,11 @@ static void AiStateBuildRail(Player *p) p->ai.banned_tile_count = 0; } -static int AiGetStationIdByDef(TileIndex tile, int id) +static StationID AiGetStationIdByDef(TileIndex tile, int id) { const AiDefaultBlockData *p = _default_rail_track_data[id]->data; while (p->mode != 1) p++; - return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2; + return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); } static void AiStateBuildRailVeh(Player *p) @@ -3096,11 +3097,11 @@ static void AiStateBuildRoad(Player *p) p->ai.banned_tile_count = 0; } -static int AiGetStationIdFromRoadBlock(TileIndex tile, int id) +static StationID AiGetStationIdFromRoadBlock(TileIndex tile, int id) { const AiDefaultBlockData *p = _road_default_block_data[id]->data; while (p->mode != 1) p++; - return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2; + return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); } static void AiStateBuildRoadVehicles(Player *p) @@ -3406,11 +3407,11 @@ static void AiStateBuildDefaultAirportBlocks(Player *p) p->ai.state = AIS_BUILD_AIRCRAFT_VEHICLES; } -static int AiGetStationIdFromAircraftBlock(TileIndex tile, int id) +static StationID AiGetStationIdFromAircraftBlock(TileIndex tile, int id) { const AiDefaultBlockData *p = _airport_default_block_data[id]; while (p->mode != 1) p++; - return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2; + return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); } static void AiStateBuildAircraftVehicles(Player *p) @@ -3431,7 +3432,7 @@ static void AiStateBuildAircraftVehicles(Player *p) /* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type * and offset to the FIRST depot because the AI picks the st->xy tile */ - tile += ToTileIndexDiff(GetAirport(GetStation(_m[tile].m2)->airport_type)->airport_depots[0]); + tile += ToTileIndexDiff(GetAirport(GetStationByTile(tile)->airport_type)->airport_depots[0]); if (CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) return; loco_id = _new_aircraft_id; diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c index 57cac9698..eac7793ae 100644 --- a/ai/trolly/trolly.c +++ b/ai/trolly/trolly.c @@ -22,6 +22,7 @@ #include "../../debug.h" #include "../../functions.h" #include "../../road_map.h" +#include "../../station_map.h" #include "../../table/strings.h" #include "../../map.h" #include "../../tile.h" @@ -1202,7 +1203,7 @@ static void AiNew_State_GiveOrders(Player *p) idx = 0; order.type = OT_GOTO_STATION; order.flags = 0; - order.station = _m[p->ainew.to_tile].m2; + order.station = GetStationIndex(p->ainew.to_tile); if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver) order.flags |= OF_FULL_LOAD; AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); @@ -1210,7 +1211,7 @@ static void AiNew_State_GiveOrders(Player *p) idx = 0; order.type = OT_GOTO_STATION; order.flags = 0; - order.station = _m[p->ainew.from_tile].m2; + order.station = GetStationIndex(p->ainew.from_tile); if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver) order.flags |= OF_FULL_LOAD; AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); diff --git a/aircraft_cmd.c b/aircraft_cmd.c index 8d07cb0dc..60904f4e6 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "station_map.h" #include "table/strings.h" #include "map.h" #include "tile.h" @@ -239,7 +240,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) * layout for #th position of depot. Since layout must start with a listing * of all depots, it is simple */ { - const Station* st = GetStation(_m[tile].m2); + const Station* st = GetStationByTile(tile); const AirportFTAClass* apc = GetAirport(st->airport_type); uint i; @@ -256,7 +257,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) v->u.air.state = HANGAR; v->u.air.previous_pos = v->u.air.pos; - v->u.air.targetairport = _m[tile].m2; + v->u.air.targetairport = GetStationIndex(tile); v->next = u; v->service_interval = _patches.servint_aircraft; diff --git a/aircraft_gui.c b/aircraft_gui.c index 398bb1fc9..bed7ace18 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "station_map.h" #include "table/sprites.h" #include "table/strings.h" #include "map.h" @@ -650,7 +651,7 @@ static void DrawAircraftDepotWindow(Window *w) } SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); - SetDParam(0, _m[tile].m2); + SetDParam(0, GetStationIndex(tile)); DrawWindowWidgets(w); x = 2; diff --git a/disaster_cmd.c b/disaster_cmd.c index 59346e6e7..95481db5f 100644 --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -3,6 +3,7 @@ #include "stdafx.h" #include "openttd.h" #include "industry_map.h" +#include "station_map.h" #include "table/strings.h" #include "functions.h" #include "map.h" @@ -183,7 +184,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) v->current_order.station = 1; v->age = 0; - SetDParam(0, _m[tile].m2); + SetDParam(0, GetStationIndex(tile)); AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), v->index, @@ -205,7 +206,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) && IS_HUMAN_PLAYER(GetTileOwner(tile))) { - st = GetStation(_m[tile].m2); + st = GetStationByTile(tile); CLRBITS(st->airport_flags, RUNWAY_IN_block); } @@ -247,7 +248,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v) IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) && IS_HUMAN_PLAYER(GetTileOwner(tile))) { - st = GetStation(_m[tile].m2); + st = GetStationByTile(tile); SETBITS(st->airport_flags, RUNWAY_IN_block); } } @@ -10,6 +10,7 @@ #include "macros.h" #include "pathfind.h" #include "station.h" +#include "station_map.h" #include "tile.h" #include "depot.h" #include "tunnel_map.h" @@ -423,7 +424,7 @@ static int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) * is correct */ if ( (fstd->station_index == INVALID_STATION && tile == fstd->dest_coords) || /* We've found the tile, or */ - (IsTileType(tile, MP_STATION) && _m[tile].m2 == fstd->station_index) /* the station */ + (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == fstd->station_index) /* the station */ ) { return AYSTAR_FOUND_END_NODE; } else { diff --git a/order_gui.c b/order_gui.c index a83c7b70e..c1f4bc79b 100644 --- a/order_gui.c +++ b/order_gui.c @@ -3,6 +3,7 @@ #include "stdafx.h" #include "openttd.h" #include "road_map.h" +#include "station_map.h" #include "table/sprites.h" #include "table/strings.h" #include "functions.h" @@ -190,7 +191,6 @@ static void DrawOrdersWindow(Window *w) static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) { Order order; - int st_index; // check depot first if (_patches.gotodepot) { @@ -221,7 +221,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) { order.type = OT_GOTO_DEPOT; order.flags = OF_PART_OF_ORDERS; - order.station = _m[tile].m2; + order.station = GetStationIndex(tile); return order; } break; @@ -257,7 +257,8 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) } if (IsTileType(tile, MP_STATION)) { - const Station* st = GetStation(st_index = _m[tile].m2); + StationID st_index = GetStationIndex(tile); + const Station* st = GetStation(st_index); if (st->owner == _current_player || st->owner == OWNER_NONE) { byte facil; diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 070695f6b..e3f1c6fb4 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -5,6 +5,7 @@ #include "debug.h" #include "functions.h" #include "road_map.h" +#include "station_map.h" #include "table/strings.h" #include "map.h" #include "tile.h" @@ -1415,7 +1416,7 @@ again: if (v->u.road.state >= 0x20 && _road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); - Station* st = GetStation(_m[v->tile].m2); + Station* st = GetStationByTile(v->tile); if (v->current_order.type != OT_LEAVESTATION && v->current_order.type != OT_GOTO_DEPOT) { @@ -1423,7 +1424,7 @@ again: CLRBIT(rs->status, 7); - v->last_station_visited = _m[v->tile].m2; + v->last_station_visited = GetStationIndex(v->tile); RoadVehArrivesAt(v, st); diff --git a/station_cmd.c b/station_cmd.c index 0e5aec5ef..9cfccf055 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -7,6 +7,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "station_map.h" #include "table/sprites.h" #include "table/strings.h" #include "map.h" @@ -110,7 +111,7 @@ RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type) RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type) { - const Station* st = GetStation(_m[tile].m2); + const Station* st = GetStationByTile(tile); RoadStop* rs; for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) { @@ -184,7 +185,7 @@ static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest // check around to see if there's any stations there BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) if (IsTileType(tile_cur, MP_STATION)) { - StationID t = _m[tile_cur].m2; + StationID t = GetStationIndex(tile_cur); { Station *st = GetStation(t); // you cannot take control of an oilrig!! @@ -232,7 +233,7 @@ static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h) uint t; for (i = 0; i != MapSize(); i++) { - if (IsTileType(i, MP_STATION) && _m[i].m2 == station_index) { + if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) { t = TileX(i); if (t < x1) x1 = t; if (t > x2) x2 = t; @@ -797,7 +798,7 @@ int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invali if (_m[tile_cur].m5 >= 8) { return ClearTile_Station(tile_cur, DC_AUTO); // get error message } else { - StationID st = _m[tile_cur].m2; + StationID st = GetStationIndex(tile_cur); if (*station == INVALID_STATION) { *station = st; } else if (*station != st) { @@ -1069,7 +1070,7 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) static bool TileBelongsToRailStation(const Station *st, TileIndex tile) { - return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8; + return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && _m[tile].m5 < 8; } static void MakeRailwayStationAreaSmaller(Station *st) @@ -1144,7 +1145,7 @@ int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 // make sure the specified tile belongs to the current player, and that it is a railroad station. if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR; - st = GetStation(_m[tile].m2); + st = GetStationByTile(tile); if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; // if we reached here, it means we can actually delete it. do that. @@ -1252,7 +1253,8 @@ static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec) { - const Station *st = GetStation(_m[tile].m2); + const Station* st = GetStationByTile(tile); + if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; // tile is not a railroad station? @@ -1971,7 +1973,7 @@ static void DrawTile_Station(TileInfo *ti) //debug("Cust-o-mized %p", statspec); if (statspec != NULL) { - const Station* st = GetStation(_m[ti->tile].m2); + const Station* st = GetStationByTile(ti->tile); relocation = GetCustomStationRelocation(statspec, st, 0); //debug("Relocation %d", relocation); @@ -2051,7 +2053,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td) StringID str; td->owner = GetTileOwner(tile); - td->build_date = GetStation(_m[tile].m2)->build_date; + td->build_date = GetStationByTile(tile)->build_date; m5 = _m[tile].m5; (str=STR_305E_RAILROAD_STATION, m5 < 8) || @@ -2166,7 +2168,7 @@ static void ClickTile_Station(TileIndex tile) if (_m[tile].m5 == 32 || _m[tile].m5 == 65) { ShowAircraftDepotWindow(tile); } else { - ShowStationViewWindow(_m[tile].m2); + ShowStationViewWindow(GetStationIndex(tile)); } } @@ -2179,7 +2181,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) if (v->type == VEH_Train) { if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) && !IsCompatibleTrainStationTile(tile + TileOffsByDir(DirToDiagDir(v->direction)), tile)) { - StationID station_id = _m[tile].m2; + StationID station_id = GetStationIndex(tile); if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) || (v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) { @@ -2563,7 +2565,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) cur_tile = TILE_MASK(cur_tile); if (!IsTileType(cur_tile, MP_STATION)) continue; - st = GetStation(_m[cur_tile].m2); + st = GetStationByTile(cur_tile); for (i = 0; i != lengthof(around); i++) { if (around[i] == NULL) { @@ -2721,7 +2723,7 @@ void BuildOilRig(TileIndex tile) void DeleteOilRig(TileIndex tile) { - Station *st = GetStation(_m[tile].m2); + Station* st = GetStationByTile(tile); DoClearSquare(tile); @@ -2738,7 +2740,8 @@ static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerI if (!IsTileOwner(tile, old_player)) return; if (new_player != OWNER_SPECTATOR) { - Station *st = GetStation(_m[tile].m2); + Station* st = GetStationByTile(tile); + SetTileOwner(tile, new_player); st->owner = new_player; _global_station_sort_dirty = true; // transfer ownership of station to another player @@ -2764,7 +2767,7 @@ static int32 ClearTile_Station(TileIndex tile, byte flags) return_cmd_error(STR_4800_IN_THE_WAY); } - st = GetStation(_m[tile].m2); + st = GetStationByTile(tile); if (m5 < 8) return RemoveRailroadStation(st, tile, flags); // original airports < 67, new airports between 83 - 114 diff --git a/station_map.h b/station_map.h new file mode 100644 index 000000000..192979d77 --- /dev/null +++ b/station_map.h @@ -0,0 +1,14 @@ +/* $Id$ */ + +#include "station.h" + + +static inline StationID GetStationIndex(TileIndex t) +{ + return (StationID)_m[t].m2; +} + +static inline Station* GetStationByTile(TileIndex t) +{ + return GetStation(GetStationIndex(t)); +} diff --git a/train_cmd.c b/train_cmd.c index 13124d92b..e9c58bae9 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -6,6 +6,7 @@ #include "debug.h" #include "functions.h" #include "gui.h" +#include "station_map.h" #include "table/strings.h" #include "map.h" #include "tile.h" @@ -196,21 +197,20 @@ enum AccelType { static bool TrainShouldStop(const Vehicle* v, TileIndex tile) { const Order* o = &v->current_order; + StationID sid = GetStationIndex(tile); assert(v->type == VEH_Train); - assert(IsTileType(v->tile, MP_STATION)); //When does a train drive through a station //first we deal with the "new nonstop handling" - if (_patches.new_nonstop && o->flags & OF_NON_STOP && - _m[tile].m2 == o->station ) + if (_patches.new_nonstop && o->flags & OF_NON_STOP && sid == o->station) { return false; + } - if (v->last_station_visited == _m[tile].m2) - return false; + if (v->last_station_visited == sid) return false; - if (_m[tile].m2 != o->station && - (o->flags & OF_NON_STOP || _patches.new_nonstop)) + if (sid != o->station && (o->flags & OF_NON_STOP || _patches.new_nonstop)) { return false; + } return true; } @@ -2027,8 +2027,11 @@ static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, in if (ttfd->dest_coords == 0) return false; // did we reach the final station? - if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) || - (IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) { + if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) || ( + IsTileType(tile, MP_STATION) && + IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && + GetStationIndex(tile) == ttfd->station_index + )) { /* We do not check for dest_coords if we have a station_index, * because in that case the dest_coords are just an * approximation of where the station is */ @@ -2301,7 +2304,7 @@ static bool ProcessTrainOrder(Vehicle *v) if (_patches.new_nonstop && v->current_order.flags & OF_NON_STOP && IsTileType(v->tile, MP_STATION) && - v->current_order.station == _m[v->tile].m2) { + v->current_order.station == GetStationIndex(v->tile)) { v->cur_order_index++; } |