Mercurial > hg > openttd
changeset 8954:454ba10a0cff draft
(svn r12745) -Codechange: a bit of naming conventions, introduce Is*DepotTile()
author | smatz <smatz@openttd.org> |
---|---|
date | Thu, 17 Apr 2008 00:44:20 +0000 |
parents | 0f3c6c845c6f |
children | f1d3f0d8bccc |
files | src/ai/default/default.cpp src/ai/trolly/pathfinder.cpp src/ai/trolly/trolly.cpp src/depot.h src/npf.cpp src/openttd.cpp src/order_cmd.cpp src/order_gui.cpp src/pathfind.cpp src/rail_cmd.cpp src/rail_map.h src/roadveh_cmd.cpp src/ship_cmd.cpp src/smallmap_gui.cpp src/train_cmd.cpp src/vehicle.cpp src/water_map.h src/yapf/follow_track.hpp src/yapf/yapf_destrail.hpp src/yapf/yapf_road.cpp |
diffstat | 20 files changed, 70 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -330,7 +330,7 @@ EngineID veh; // wait until the vehicle reaches the depot. - if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { + if (!IsDepotTypeTile(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { AiHandleGotoDepot(p, CMD_SEND_TRAIN_TO_DEPOT); return; } @@ -2886,7 +2886,7 @@ are.dest = _players_ai[p->index].cur_tile_b; tile = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(dir)); - if (IsRoadStopTile(tile) || IsTileDepotType(tile, TRANSPORT_ROAD)) return false; + if (IsRoadStopTile(tile) || IsDepotTypeTile(tile, TRANSPORT_ROAD)) return false; TrackdirBits bits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ROADTYPES_ROAD)) & DiagdirReachesTrackdirs(dir); if (bits == TRACKDIR_BIT_NONE) return false; @@ -3606,7 +3606,7 @@ if (v->owner == _current_player) { if (v->type == VEH_TRAIN) { - if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { + if (!IsDepotTypeTile(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { if (!v->current_order.IsType(OT_GOTO_DEPOT)) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_TRAIN_TO_DEPOT); goto going_to_depot;
--- a/src/ai/trolly/pathfinder.cpp +++ b/src/ai/trolly/pathfinder.cpp @@ -45,7 +45,7 @@ { return // MP_ROAD, but not a road depot? - (IsTileType(tile, MP_ROAD) && !IsTileDepotType(tile, TRANSPORT_ROAD)) || + (IsTileType(tile, MP_ROAD) && !IsDepotTypeTile(tile, TRANSPORT_ROAD)) || (IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD); }
--- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -1254,7 +1254,7 @@ // We are already sending him back if (AiNew_GetSpecialVehicleFlag(p, v) & AI_VEHICLEFLAG_SELL) { - if (v->type == VEH_ROAD && IsTileDepotType(v->tile, TRANSPORT_ROAD) && + if (v->type == VEH_ROAD && IsDepotTypeTile(v->tile, TRANSPORT_ROAD) && (v->vehstatus&VS_STOPPED)) { // We are at the depot, sell the vehicle AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
--- a/src/depot.h +++ b/src/depot.h @@ -36,23 +36,20 @@ #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) /** - * Check if a tile is a depot of the given type. + * Check if a tile is a depot and it is a depot of the given type. */ -static inline bool IsTileDepotType(TileIndex tile, TransportType type) +static inline bool IsDepotTypeTile(TileIndex tile, TransportType type) { switch (type) { + default: NOT_REACHED(); case TRANSPORT_RAIL: - return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT; + return IsRailDepotTile(tile); case TRANSPORT_ROAD: return IsRoadDepotTile(tile); case TRANSPORT_WATER: - return IsTileType(tile, MP_WATER) && GetWaterTileType(tile) == WATER_TILE_DEPOT; - - default: - NOT_REACHED(); - return false; + return IsShipDepotTile(tile); } } @@ -63,13 +60,7 @@ */ static inline bool IsDepotTile(TileIndex tile) { - switch (GetTileType(tile)) { - case MP_ROAD: return IsRoadDepot(tile); - case MP_WATER: return GetWaterTileType(tile) == WATER_TILE_DEPOT; - case MP_RAILWAY: return GetRailTileType(tile) == RAIL_TILE_DEPOT; - case MP_STATION: return IsHangar(tile); - default: return false; - } + return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile); } /**
--- a/src/npf.cpp +++ b/src/npf.cpp @@ -231,14 +231,14 @@ switch (GetTileType(tile)) { case MP_RAILWAY: /* DEBUG: mark visited tiles by mowing the grass under them ;-) */ - if (!IsTileDepotType(tile, TRANSPORT_RAIL)) { + if (!IsDepotTypeTile(tile, TRANSPORT_RAIL)) { SetRailGroundType(tile, RAIL_GROUND_BARREN); MarkTileDirtyByTile(tile); } break; case MP_ROAD: - if (!IsTileDepotType(tile, TRANSPORT_ROAD)) { + if (!IsDepotTypeTile(tile, TRANSPORT_ROAD)) { SetRoadside(tile, ROADSIDE_BARREN); MarkTileDirtyByTile(tile); } @@ -397,7 +397,7 @@ * curves should be taken into account, as this affects the speed limit. */ /* Check for reverse in depot */ - if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { + if (IsDepotTypeTile(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { /* Penalise any depot tile that is not the last tile in the path. This * _should_ penalise every occurence of reversing in a depot (and only * that) */ @@ -417,7 +417,7 @@ { /* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below, * since checking the cache not that much faster than the actual check */ - return IsTileDepotType(current->path.node.tile, (TransportType)as->user_data[NPF_TYPE]) ? + return IsDepotTypeTile(current->path.node.tile, (TransportType)as->user_data[NPF_TYPE]) ? AYSTAR_FOUND_END_NODE : AYSTAR_DONE; } @@ -466,7 +466,7 @@ { if (IsTileType(tile, MP_RAILWAY) || /* Rail tile (also rail depot) */ IsRailwayStationTile(tile) || /* Rail station tile */ - IsTileDepotType(tile, TRANSPORT_ROAD) || /* Road depot tile */ + IsDepotTypeTile(tile, TRANSPORT_ROAD) || /* Road depot tile */ IsStandardRoadStopTile(tile)) { /* Road station tile (but not drive-through stops) */ return IsTileOwner(tile, owner); /* You need to own these tiles entirely to use them */ } @@ -499,7 +499,7 @@ */ static DiagDirection GetDepotDirection(TileIndex tile, TransportType type) { - assert(IsTileDepotType(tile, type)); + assert(IsDepotTypeTile(tile, type)); switch (type) { case TRANSPORT_RAIL: return GetRailDepotDirection(tile); @@ -537,7 +537,7 @@ */ static DiagDirection GetTileSingleEntry(TileIndex tile, TransportType type, uint subtype) { - if (type != TRANSPORT_WATER && IsTileDepotType(tile, type)) return GetDepotDirection(tile, type); + if (type != TRANSPORT_WATER && IsDepotTypeTile(tile, type)) return GetDepotDirection(tile, type); if (type == TRANSPORT_ROAD) { if (IsStandardRoadStopTile(tile)) return GetRoadStopDir(tile); @@ -879,7 +879,7 @@ FOR_ALL_DEPOTS(depot) { /* Check if this is really a valid depot, it is of the needed type and * owner */ - if (IsTileDepotType(depot->xy, type) && IsTileOwner(depot->xy, owner)) + if (IsDepotTypeTile(depot->xy, type) && IsTileOwner(depot->xy, owner)) /* If so, let's add it to the queue, sorted by distance */ depots.push(&depots, depot, DistanceManhattan(tile, depot->xy)); }
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1874,7 +1874,7 @@ } /* Clear PBS reservation on track */ - if (!IsTileDepotType(t, TRANSPORT_RAIL)) { + if (!IsDepotTypeTile(t, TRANSPORT_RAIL)) { SB(_m[t].m4, 4, 4, 0); } else { ClrBit(_m[t].m3, 6);
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -392,15 +392,15 @@ switch (v->type) { case VEH_TRAIN: - if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR; + if (!IsDepotTypeTile(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR; break; case VEH_ROAD: - if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR; + if (!IsDepotTypeTile(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR; break; case VEH_SHIP: - if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR; + if (!IsDepotTypeTile(dp->xy, TRANSPORT_WATER)) return CMD_ERROR; break; default: return CMD_ERROR;
--- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -462,7 +462,7 @@ case MP_WATER: if (v->type != VEH_SHIP) break; - if (IsTileDepotType(tile, TRANSPORT_WATER) && + if (IsDepotTypeTile(tile, TRANSPORT_WATER) && IsTileOwner(tile, _local_player)) { TileIndex tile2 = GetOtherShipDepotTile(tile);
--- a/src/pathfind.cpp +++ b/src/pathfind.cpp @@ -170,10 +170,10 @@ { if (tracktype == TRANSPORT_RAIL) { /* depot from wrong side */ - if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) != side) return false; + if (IsDepotTypeTile(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) != side) return false; } else if (tracktype == TRANSPORT_ROAD) { /* depot from wrong side */ - if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != side) return false; + if (IsDepotTypeTile(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != side) return false; /* non-driverthrough road station from wrong side */ if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; }
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2268,7 +2268,7 @@ int length; /* this routine applies only to trains in depot tiles */ - if (v->type != VEH_TRAIN || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE; + if (v->type != VEH_TRAIN || !IsDepotTypeTile(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE; /* depot direction */ dir = GetRailDepotDirection(tile);
--- a/src/rail_map.h +++ b/src/rail_map.h @@ -72,7 +72,18 @@ } /** - * Is this tile a rail depot? + * Is this rail tile a rail waypoint? + * @param t the tile to get the information from + * @pre IsTileType(t, MP_RAILWAY) + * @return true if and only if the tile is a rail waypoint + */ +static inline bool IsRailWaypoint(TileIndex t) +{ + return GetRailTileType(t) == RAIL_TILE_WAYPOINT; +} + +/** + * Is this rail tile a rail depot? * @param t the tile to get the information from * @pre IsTileType(t, MP_RAILWAY) * @return true if and only if the tile is a rail depot @@ -83,17 +94,16 @@ } /** - * Is this tile a rail waypoint? + * Is this tile rail tile and a rail depot? * @param t the tile to get the information from * @pre IsTileType(t, MP_RAILWAY) - * @return true if and only if the tile is a rail waypoint + * @return true if and only if the tile is a rail depot */ -static inline bool IsRailWaypoint(TileIndex t) +static inline bool IsRailDepotTile(TileIndex t) { - return GetRailTileType(t) == RAIL_TILE_WAYPOINT; + return IsTileType(t, MP_RAILWAY) && IsRailDepot(t); } - /** * Gets the rail type of the given tile * @param t the tile to get the rail type from
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -178,7 +178,7 @@ /* The ai_new queries the vehicle cost before building the route, * so we must check against cheaters no sooner than now. --pasky */ - if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR; + if (!IsDepotTypeTile(tile, TRANSPORT_ROAD)) return CMD_ERROR; if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_DEPOT_WRONG_DEPOT_TYPE); @@ -340,7 +340,7 @@ { TileIndex tile = v->tile; - if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return false; + if (!IsDepotTypeTile(tile, TRANSPORT_ROAD)) return false; if (IsRoadVehFront(v) && !(v->vehstatus & VS_STOPPED)) return false; for (; v != NULL; v = v->Next()) {
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -130,7 +130,7 @@ FOR_ALL_DEPOTS(depot) { TileIndex tile = depot->xy; - if (IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) { + if (IsDepotTypeTile(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) { uint dist = DistanceManhattan(tile, v->tile); if (dist < best_dist) { best_dist = dist; @@ -762,7 +762,7 @@ /* The ai_new queries the vehicle cost before building the route, * so we must check against cheaters no sooner than now. --pasky */ - if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR; + if (!IsDepotTypeTile(tile, TRANSPORT_WATER)) return CMD_ERROR; if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
--- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1,4 +1,3 @@ - /* $Id$ */ /** @file smallmap_gui.cpp */
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -678,7 +678,7 @@ /* Check if the train is actually being built in a depot belonging * to the player. Doesn't matter if only the cost is queried */ if (!(flags & DC_QUERY_COST)) { - if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR; + if (!IsDepotTypeTile(tile, TRANSPORT_RAIL)) return CMD_ERROR; if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; } @@ -806,7 +806,7 @@ TileIndex tile = v->tile; /* check if stopped in a depot */ - if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1; + if (!IsDepotTypeTile(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1; int count = 0; for (; v != NULL; v = v->Next()) { @@ -1787,7 +1787,7 @@ static void ReverseTrainDirection(Vehicle *v) { - if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) { + if (IsDepotTypeTile(v->tile, TRANSPORT_RAIL)) { InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); } @@ -1807,7 +1807,7 @@ AdvanceWagonsAfterSwap(v); - if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) { + if (IsDepotTypeTile(v->tile, TRANSPORT_RAIL)) { InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); } @@ -2035,7 +2035,7 @@ tfdd.reverse = false; TileIndex tile = v->tile; - if (IsTileDepotType(tile, TRANSPORT_RAIL)) { + if (IsDepotTypeTile(tile, TRANSPORT_RAIL)) { tfdd.tile = tile; tfdd.best_length = 0; return tfdd; @@ -2154,7 +2154,7 @@ } /* No smoke in depots or tunnels */ - if (IsTileDepotType(v->tile, TRANSPORT_RAIL) || IsTunnelTile(v->tile)) continue; + if (IsDepotTypeTile(v->tile, TRANSPORT_RAIL) || IsTunnelTile(v->tile)) continue; /* No sparks for electric vehicles on nonelectrified tracks */ if (!HasPowerOnRail(v->u.rail.railtype, GetTileRailType(v->tile))) continue; @@ -3149,7 +3149,7 @@ if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile); /* Update signals */ - if (IsTileType(tile, MP_TUNNELBRIDGE) || IsTileDepotType(tile, TRANSPORT_RAIL)) { + if (IsTileType(tile, MP_TUNNELBRIDGE) || IsDepotTypeTile(tile, TRANSPORT_RAIL)) { UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner); } else { SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)), owner); @@ -3311,7 +3311,7 @@ } /* entering a depot? */ - if (IsTileDepotType(tile, TRANSPORT_RAIL)) { + if (IsDepotTypeTile(tile, TRANSPORT_RAIL)) { DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); if (DiagDirToDir(dir) == v->direction) return false; }
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3217,7 +3217,7 @@ /* check if at a standstill (not stopped only) in a depot * the check is down here to make it possible to alter stop/service for trains entering the depot */ - if (this->type == VEH_TRAIN && IsTileDepotType(this->tile, TRANSPORT_RAIL) && this->cur_speed == 0) return CMD_ERROR; + if (this->type == VEH_TRAIN && IsDepotTypeTile(this->tile, TRANSPORT_RAIL) && this->cur_speed == 0) return CMD_ERROR; TileIndex location; DestinationID destination;
--- a/src/water_map.h +++ b/src/water_map.h @@ -96,6 +96,11 @@ return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END); } +static inline TileIndex IsShipDepotTile(TileIndex t) +{ + return IsTileType(t, MP_WATER) && IsShipDepot(t); +} + static inline Axis GetShipDepotAxis(TileIndex t) { return (Axis)GB(_m[t].m5, 1, 1);
--- a/src/yapf/follow_track.hpp +++ b/src/yapf/follow_track.hpp @@ -196,7 +196,7 @@ } // road depots can be also left in one direction only - if (IsRoadTT() && IsTileDepotType(m_old_tile, TT())) { + if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) { DiagDirection exitdir = GetRoadDepotDirection(m_old_tile); if (exitdir != m_exitdir) { m_err = EC_NO_WAY; @@ -226,7 +226,7 @@ } // road and rail depots can also be entered from one direction only - if (IsRoadTT() && IsTileDepotType(m_new_tile, TT())) { + if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) { DiagDirection exitdir = GetRoadDepotDirection(m_new_tile); if (ReverseDiagDir(exitdir) != m_exitdir) { m_err = EC_NO_WAY; @@ -238,7 +238,7 @@ return false; } } - if (IsRailTT() && IsTileDepotType(m_new_tile, TT())) { + if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) { DiagDirection exitdir = GetRailDepotDirection(m_new_tile); if (ReverseDiagDir(exitdir) != m_exitdir) { m_err = EC_NO_WAY; @@ -305,7 +305,7 @@ FORCEINLINE bool ForcedReverse() { // rail and road depots cause reversing - if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) { + if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) { DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile); if (exitdir != m_exitdir) { // reverse
--- a/src/yapf/yapf_destrail.hpp +++ b/src/yapf/yapf_destrail.hpp @@ -43,7 +43,7 @@ /// Called by YAPF to detect if node ends in the desired destination FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td) { - bool bDest = IsTileDepotType(tile, TRANSPORT_RAIL); + bool bDest = IsDepotTypeTile(tile, TRANSPORT_RAIL); return bDest; }
--- a/src/yapf/yapf_road.cpp +++ b/src/yapf/yapf_road.cpp @@ -87,7 +87,7 @@ if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break; // stop if we have just entered the depot - if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) { + if (IsDepotTypeTile(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) { // next time we will reverse and leave the depot break; } @@ -148,7 +148,7 @@ /// Called by YAPF to detect if node ends in the desired destination FORCEINLINE bool PfDetectDestination(Node& n) { - bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD); + bool bDest = IsDepotTypeTile(n.m_segment_last_tile, TRANSPORT_ROAD); return bDest; } @@ -370,7 +370,7 @@ // get found depot tile Node *n = Yapf().GetBestNode(); TileIndex depot_tile = n->m_segment_last_tile; - assert(IsTileDepotType(depot_tile, TRANSPORT_ROAD)); + assert(IsDepotTypeTile(depot_tile, TRANSPORT_ROAD)); Depot* ret = GetDepotByTile(depot_tile); return ret; } @@ -439,7 +439,7 @@ return NULL; // handle the case when our vehicle is already in the depot tile - if (IsTileType(tile, MP_ROAD) && IsTileDepotType(tile, TRANSPORT_ROAD)) { + if (IsTileType(tile, MP_ROAD) && IsDepotTypeTile(tile, TRANSPORT_ROAD)) { // only what we need to return is the Depot* return GetDepotByTile(tile); }