(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop

This commit is contained in:
celestar 2007-01-25 10:06:58 +00:00
parent 600cb8a314
commit b0a0086e7c
7 changed files with 43 additions and 40 deletions

View File

@ -2591,10 +2591,10 @@ static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData
} else if (p->mode == 1) { } else if (p->mode == 1) {
if (_want_road_truck_station) { if (_want_road_truck_station) {
// Truck station // Truck station
ret = DoCommand(c, p->attr, RS_TRUCK, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP); ret = DoCommand(c, p->attr, RoadStop::TRUCK, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP);
} else { } else {
// Bus station // Bus station
ret = DoCommand(c, p->attr, RS_BUS, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP); ret = DoCommand(c, p->attr, RoadStop::BUS, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP);
} }
clear_town_stuff:; clear_town_stuff:;

View File

@ -42,9 +42,9 @@ int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte
return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION); return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
if (type == AI_BUS) if (type == AI_BUS)
return AI_DoCommand(tile, direction, RS_BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP); return AI_DoCommand(tile, direction, RoadStop::BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
return AI_DoCommand(tile, direction, RS_TRUCK, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP); return AI_DoCommand(tile, direction, RoadStop::TRUCK, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
} }

View File

@ -94,12 +94,12 @@ static void PlaceRoad_Depot(TileIndex tile)
static void PlaceRoad_BusStation(TileIndex tile) static void PlaceRoad_BusStation(TileIndex tile)
{ {
DoCommandP(tile, _road_station_picker_orientation, RS_BUS, CcRoadDepot, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION)); DoCommandP(tile, _road_station_picker_orientation, RoadStop::BUS, CcRoadDepot, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1808_CAN_T_BUILD_BUS_STATION));
} }
static void PlaceRoad_TruckStation(TileIndex tile) static void PlaceRoad_TruckStation(TileIndex tile)
{ {
DoCommandP(tile, _road_station_picker_orientation, RS_TRUCK, CcRoadDepot, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION)); DoCommandP(tile, _road_station_picker_orientation, RoadStop::TRUCK, CcRoadDepot, CMD_BUILD_ROAD_STOP | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1809_CAN_T_BUILD_TRUCK_STATION));
} }
static void PlaceRoad_DemolishArea(TileIndex tile) static void PlaceRoad_DemolishArea(TileIndex tile)

View File

@ -695,7 +695,7 @@ static void ProcessRoadVehOrder(Vehicle *v)
rs = GetPrimaryRoadStop( rs = GetPrimaryRoadStop(
GetStation(order->dest), GetStation(order->dest),
v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK
); );
if (rs != NULL) { if (rs != NULL) {
@ -1077,7 +1077,7 @@ static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir
bitmask = 0; bitmask = 0;
} else { } else {
/* Our station */ /* Our station */
RoadStopType rstype = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; RoadStop::Type rstype = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
if (GetRoadStopType(tile) != rstype) { if (GetRoadStopType(tile) != rstype) {
// wrong station type // wrong station type
@ -1663,7 +1663,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
/* update destination */ /* update destination */
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) { if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
Station* st = GetStation(v->current_order.dest); Station* st = GetStation(v->current_order.dest);
RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK); RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK);
RoadStop* best = NULL; RoadStop* best = NULL;
if (rs != NULL) { if (rs != NULL) {

View File

@ -35,24 +35,27 @@ typedef struct GoodsEntry {
int32 feeder_profit; int32 feeder_profit;
} GoodsEntry; } GoodsEntry;
typedef enum RoadStopType {
RS_BUS,
RS_TRUCK
} RoadStopType;
enum { enum {
ROAD_STOP_LIMIT = 16, ROAD_STOP_LIMIT = 16,
}; };
typedef struct RoadStop { /** A Stop for a Road Vehicle */
TileIndex xy; struct RoadStop {
RoadStopID index; /** Types of RoadStops */
byte status; enum Type {
byte num_vehicles; BUS, ///< A standard stop for buses
struct RoadStop *next; TRUCK ///< A standard stop for trucks
struct RoadStop *prev; };
static const int cDebugCtorLevel = 3; static const int cDebugCtorLevel = 3; ///< Debug level on which Contructor / Destructor messages are printed
static const int LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station
TileIndex xy; ///< Position on the map
RoadStopID index; ///< Global (i.e. pool-wide) index
byte status; ///< Current status of the Stop. Like which spot is taken. TODO - enumify this
byte num_vehicles; ///< Number of vehicles currently slotted to this stop
struct RoadStop *next; ///< Next stop of the given type at this station
struct RoadStop *prev; ///< Previous stop of the given type at this station
RoadStop(TileIndex tile); RoadStop(TileIndex tile);
~RoadStop(); ~RoadStop();
@ -67,7 +70,7 @@ typedef struct RoadStop {
bool IsValid() const; bool IsValid() const;
protected: protected:
static RoadStop *AllocateRaw(void); static RoadStop *AllocateRaw(void);
} RoadStop; };
typedef struct StationSpecList { typedef struct StationSpecList {
const StationSpec *spec; const StationSpec *spec;
@ -271,9 +274,9 @@ uint GetPlatformLength(TileIndex tile, DiagDirection dir);
const DrawTileSprites *GetStationTileLayout(byte gfx); const DrawTileSprites *GetStationTileLayout(byte gfx);
void StationPickerDrawSprite(int x, int y, RailType railtype, int image); void StationPickerDrawSprite(int x, int y, RailType railtype, int image);
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type); RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type); RoadStop * GetPrimaryRoadStop(const Station *st, RoadStop::Type type);
uint GetNumRoadStops(const Station* st, RoadStopType type); uint GetNumRoadStops(const Station* st, RoadStop::Type type);
RoadStop * AllocateRoadStop( void ); RoadStop * AllocateRoadStop( void );
void ClearSlot(Vehicle *v); void ClearSlot(Vehicle *v);

View File

@ -81,18 +81,18 @@ DEFINE_OLD_POOL(RoadStop, RoadStop, RoadStopPoolNewBlock, NULL)
extern void UpdateAirplanesOnNewStation(Station *st); extern void UpdateAirplanesOnNewStation(Station *st);
RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type) RoadStop* GetPrimaryRoadStop(const Station* st, RoadStop::Type type)
{ {
switch (type) { switch (type) {
case RS_BUS: return st->bus_stops; case RoadStop::BUS: return st->bus_stops;
case RS_TRUCK: return st->truck_stops; case RoadStop::TRUCK: return st->truck_stops;
default: NOT_REACHED(); default: NOT_REACHED();
} }
return NULL; return NULL;
} }
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type) RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type)
{ {
const Station* st = GetStationByTile(tile); const Station* st = GetStationByTile(tile);
RoadStop* rs; RoadStop* rs;
@ -104,7 +104,7 @@ RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
return rs; return rs;
} }
uint GetNumRoadStopsInStation(const Station* st, RoadStopType type) uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type)
{ {
uint num = 0; uint num = 0;
const RoadStop *rs; const RoadStop *rs;
@ -1299,7 +1299,7 @@ int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
* then point into the global roadstop array. *prev (in CmdBuildRoadStop) * then point into the global roadstop array. *prev (in CmdBuildRoadStop)
* is the pointer tino the global roadstop array which has *currstop in * is the pointer tino the global roadstop array which has *currstop in
* its ->next element. * its ->next element.
* @param[in] truck_station Determines whether a stop is RS_BUS or RS_TRUCK * @param[in] truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK
* @param[in] station The station to do the whole procedure for * @param[in] station The station to do the whole procedure for
* @param[out] currstop See the detailed function description * @param[out] currstop See the detailed function description
* @param prev See the detailed function description * @param prev See the detailed function description
@ -1369,7 +1369,7 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
std::auto_ptr<RoadStop> rs_auto_delete(road_stop); std::auto_ptr<RoadStop> rs_auto_delete(road_stop);
if (st != NULL && if (st != NULL &&
GetNumRoadStopsInStation(st, RS_BUS) + GetNumRoadStopsInStation(st, RS_TRUCK) >= ROAD_STOP_LIMIT) { GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= ROAD_STOP_LIMIT) {
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
} }
@ -1418,7 +1418,7 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->rect.BeforeAddTile(tile, StationRect::ADD_TRY); st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
MakeRoadStop(tile, st->owner, st->index, type ? RS_TRUCK : RS_BUS, (DiagDirection)p1); MakeRoadStop(tile, st->owner, st->index, type ? RoadStop::TRUCK : RoadStop::BUS, (DiagDirection)p1);
UpdateStationVirtCoordDirty(st); UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false); UpdateStationAcceptance(st, false);
@ -1444,10 +1444,10 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
if (is_truck) { // truck stop if (is_truck) { // truck stop
primary_stop = &st->truck_stops; primary_stop = &st->truck_stops;
cur_stop = GetRoadStopByTile(tile, RS_TRUCK); cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK);
} else { } else {
primary_stop = &st->bus_stops; primary_stop = &st->bus_stops;
cur_stop = GetRoadStopByTile(tile, RS_BUS); cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
} }
assert(cur_stop != NULL); assert(cur_stop != NULL);

View File

@ -75,10 +75,10 @@ typedef enum StationType {
StationType GetStationType(TileIndex); StationType GetStationType(TileIndex);
static inline RoadStopType GetRoadStopType(TileIndex t) static inline RoadStop::Type GetRoadStopType(TileIndex t)
{ {
assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS); assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS; return GetStationType(t) == STATION_TRUCK ? RoadStop::TRUCK : RoadStop::BUS;
} }
static inline StationGfx GetStationGfx(TileIndex t) static inline StationGfx GetStationGfx(TileIndex t)
@ -275,9 +275,9 @@ static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a,
SetRailType(t, rt); SetRailType(t, rt);
} }
static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d) static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStop::Type rst, DiagDirection d)
{ {
MakeStation(t, o, sid, (rst == RS_BUS ? GFX_BUS_BASE : GFX_TRUCK_BASE) + d); MakeStation(t, o, sid, (rst == RoadStop::BUS ? GFX_BUS_BASE : GFX_TRUCK_BASE) + d);
} }
static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section) static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)