changeset 5836:0b68d5a508a2 draft

(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
author celestar <celestar@openttd.org>
date Thu, 25 Jan 2007 10:06:58 +0000
parents 60c031ec09c7
children e18480817d2c
files src/ai/default/default.cpp src/ai/trolly/build.cpp src/road_gui.cpp src/roadveh_cmd.cpp src/station.h src/station_cmd.cpp src/station_map.h
diffstat 7 files changed, 43 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -2591,10 +2591,10 @@
 		} else if (p->mode == 1) {
 			if (_want_road_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 {
 				// 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:;
 
--- a/src/ai/trolly/build.cpp
+++ b/src/ai/trolly/build.cpp
@@ -42,9 +42,9 @@
 		return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
 
 	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);
 }
 
 
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -94,12 +94,12 @@
 
 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)
 {
-	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)
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -695,7 +695,7 @@
 
 			rs = GetPrimaryRoadStop(
 				GetStation(order->dest),
-				v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK
+				v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK
 			);
 
 			if (rs != NULL) {
@@ -1077,7 +1077,7 @@
 			bitmask = 0;
 		} else {
 			/* 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) {
 				// wrong station type
@@ -1663,7 +1663,7 @@
 	/* update destination */
 	if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
 		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;
 
 		if (rs != NULL) {
--- a/src/station.h
+++ b/src/station.h
@@ -35,24 +35,27 @@
 	int32 feeder_profit;
 } GoodsEntry;
 
-typedef enum RoadStopType {
-	RS_BUS,
-	RS_TRUCK
-} RoadStopType;
-
 enum {
 	ROAD_STOP_LIMIT = 16,
 };
 
-typedef struct RoadStop {
-	TileIndex xy;
-	RoadStopID index;
-	byte status;
-	byte num_vehicles;
-	struct RoadStop *next;
-	struct RoadStop *prev;
+/** A Stop for a Road Vehicle */
+struct RoadStop {
+	/** Types of RoadStops */
+	enum Type {
+		BUS,                                ///< A standard stop for buses
+		TRUCK                               ///< A standard stop for trucks
+	};
 
-	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();
@@ -67,7 +70,7 @@
 	bool IsValid() const;
 protected:
 	static RoadStop *AllocateRaw(void);
-} RoadStop;
+};
 
 typedef struct StationSpecList {
 	const StationSpec *spec;
@@ -271,9 +274,9 @@
 const DrawTileSprites *GetStationTileLayout(byte gfx);
 void StationPickerDrawSprite(int x, int y, RailType railtype, int image);
 
-RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
-RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type);
-uint GetNumRoadStops(const Station* st, RoadStopType type);
+RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
+RoadStop * GetPrimaryRoadStop(const Station *st, RoadStop::Type type);
+uint GetNumRoadStops(const Station* st, RoadStop::Type type);
 RoadStop * AllocateRoadStop( void );
 void ClearSlot(Vehicle *v);
 
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -81,18 +81,18 @@
 extern void UpdateAirplanesOnNewStation(Station *st);
 
 
-RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type)
+RoadStop* GetPrimaryRoadStop(const Station* st, RoadStop::Type type)
 {
 	switch (type) {
-		case RS_BUS:   return st->bus_stops;
-		case RS_TRUCK: return st->truck_stops;
+		case RoadStop::BUS:   return st->bus_stops;
+		case RoadStop::TRUCK: return st->truck_stops;
 		default: NOT_REACHED();
 	}
 
 	return NULL;
 }
 
-RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
+RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type)
 {
 	const Station* st = GetStationByTile(tile);
 	RoadStop* rs;
@@ -104,7 +104,7 @@
 	return rs;
 }
 
-uint GetNumRoadStopsInStation(const Station* st, RoadStopType type)
+uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type)
 {
 	uint num = 0;
 	const RoadStop *rs;
@@ -1299,7 +1299,7 @@
  * then point into the global roadstop array. *prev (in CmdBuildRoadStop)
  * is the pointer tino the global roadstop array which has *currstop in
  * 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[out] currstop See the detailed function description
  * @param prev See the detailed function description
@@ -1369,7 +1369,7 @@
 	std::auto_ptr<RoadStop> rs_auto_delete(road_stop);
 
 	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);
 	}
 
@@ -1418,7 +1418,7 @@
 
 		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);
 		UpdateStationAcceptance(st, false);
@@ -1444,10 +1444,10 @@
 
 	if (is_truck) { // truck stop
 		primary_stop = &st->truck_stops;
-		cur_stop = GetRoadStopByTile(tile, RS_TRUCK);
+		cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK);
 	} else {
 		primary_stop = &st->bus_stops;
-		cur_stop = GetRoadStopByTile(tile, RS_BUS);
+		cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
 	}
 
 	assert(cur_stop != NULL);
--- a/src/station_map.h
+++ b/src/station_map.h
@@ -75,10 +75,10 @@
 
 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);
-	return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS;
+	return GetStationType(t) == STATION_TRUCK ? RoadStop::TRUCK : RoadStop::BUS;
 }
 
 static inline StationGfx GetStationGfx(TileIndex t)
@@ -275,9 +275,9 @@
 	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)