changeset 13852:5caf1ea3a9f9 draft

(svn r18381) -Codechange: Add RoadVehicle::IsBus() to simplify some stuff.
author frosch <frosch@openttd.org>
date Wed, 02 Dec 2009 17:37:02 +0000
parents 06143488a65f
children ce07aa728b20
files src/network/network_server.cpp src/order_cmd.cpp src/order_gui.cpp src/pathfinder/yapf/yapf_road.cpp src/roadveh.h src/roadveh_cmd.cpp src/station.cpp src/station_cmd.cpp
diffstat 8 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -28,7 +28,7 @@
 #include "../company_func.h"
 #include "../company_gui.h"
 #include "../window_func.h"
-#include "../cargotype.h"
+#include "../roadveh.h"
 
 #include "table/strings.h"
 
@@ -1368,7 +1368,7 @@
 		byte type = 0;
 		switch (v->type) {
 			case VEH_TRAIN: type = 0; break;
-			case VEH_ROAD: type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? 2 : 1; break;
+			case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? 2 : 1; break;
 			case VEH_AIRCRAFT: type = 3; break;
 			case VEH_SHIP: type = 4; break;
 			default: continue;
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -15,7 +15,6 @@
 #include "company_func.h"
 #include "news_func.h"
 #include "vehicle_gui.h"
-#include "cargotype.h"
 #include "strings_func.h"
 #include "functions.h"
 #include "window_func.h"
@@ -1140,7 +1139,7 @@
 			}
 
 			/* Trucks can't share orders with busses (and visa versa) */
-			if (src->type == VEH_ROAD && IsCargoInClass(src->cargo_type, CC_PASSENGERS) != IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) {
+			if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
 				return CMD_ERROR;
 			}
 
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -17,6 +17,7 @@
 #include "depot_base.h"
 #include "vehicle_base.h"
 #include "vehicle_gui.h"
+#include "roadveh.h"
 #include "timetable.h"
 #include "cargotype.h"
 #include "strings_func.h"
@@ -379,7 +380,7 @@
 			(facil = FACIL_DOCK, v->type == VEH_SHIP) ||
 			(facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
 			(facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
-			(facil = FACIL_BUS_STOP, v->type == VEH_ROAD && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) ||
+			(facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
 			(facil = FACIL_TRUCK_STOP, 1);
 			if (st->facilities & facil) {
 				order.MakeGoToStation(st_index);
--- a/src/pathfinder/yapf/yapf_road.cpp
+++ b/src/pathfinder/yapf/yapf_road.cpp
@@ -11,7 +11,6 @@
 
 #include "../../stdafx.h"
 #include "../../roadstop_base.h"
-#include "../../cargotype.h"
 
 #include "yapf.hpp"
 #include "yapf_node_road.hpp"
@@ -209,7 +208,7 @@
 	{
 		m_dest_station = sid;
 		m_destTile     = destTile;
-		m_bus          = IsCargoInClass(v->cargo_type, CC_PASSENGERS);
+		m_bus          = v->IsBus();
 		m_non_artic    = !v->HasArticulatedPart();
 	}
 
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -132,6 +132,8 @@
 	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
 	void FindRoadStopSlot();
 
+	bool IsBus() const;
+
 	/**
 	 * Check if vehicle is a front engine
 	 * @return Returns true if vehicle is a front engine
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -82,6 +82,17 @@
 	TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW
 };
 
+
+/**
+ * Check whether a roadvehicle is a bus
+ * @return true if bus
+ */
+bool RoadVehicle::IsBus() const
+{
+	assert(this->IsRoadVehFront());
+	return IsCargoInClass(this->cargo_type, CC_PASSENGERS);
+}
+
 /**
  * Get the width of a road vehicle image in the GUI.
  * @param offset Additional offset for positioning the sprite; set to NULL if not needed
@@ -729,7 +740,7 @@
 
 static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
 {
-	if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
+	if (v->IsBus()) {
 		/* Check if station was ever visited before */
 		if (!(st->had_vehicle_of_type & HVOT_BUS)) {
 			st->had_vehicle_of_type |= HVOT_BUS;
@@ -960,7 +971,7 @@
 			trackdirs = TRACKDIR_BIT_NONE;
 		} else {
 			/* Our station */
-			RoadStopType rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK;
+			RoadStopType rstype = v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK;
 
 			if (GetRoadStopType(tile) != rstype) {
 				/* Wrong station type */
@@ -1489,7 +1500,7 @@
 			(IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
 			v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile)) &&
 			v->owner == GetTileOwner(v->tile) &&
-			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
+			GetRoadStopType(v->tile) == (v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 			v->frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
 
 		RoadStop *rs = RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile));
@@ -1503,7 +1514,7 @@
 
 			if (IsDriveThroughStopTile(v->tile)) {
 				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
-				RoadStopType type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK;
+				RoadStopType type = v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK;
 
 				/* Check if next inline bay is free */
 				if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type) && GetStationIndex(v->tile) == GetStationIndex(next_tile)) {
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -11,7 +11,6 @@
 
 #include "stdafx.h"
 #include "company_func.h"
-#include "cargotype.h"
 #include "roadveh.h"
 #include "functions.h"
 #include "window_func.h"
@@ -119,7 +118,7 @@
  */
 RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
 {
-	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK);
+	RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
 
 	for (; rs != NULL; rs = rs->next) {
 		/* The vehicle cannot go to this roadstop (different roadtype) */
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2699,7 +2699,7 @@
 					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
 
 					/* Check if the vehicle is stopping at this road stop */
-					if (GetRoadStopType(tile) == (IsCargoInClass(rv->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
+					if (GetRoadStopType(tile) == (rv->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 							rv->current_order.GetDestination() == GetStationIndex(tile)) {
 						SetBit(rv->state, RVS_IS_STOPPING);
 						rs->AllocateDriveThroughBay(side);