(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
authorpeter1138
Sun, 18 Mar 2007 22:07:44 +0000
changeset 6655 951b0ba32eb1
parent 6654 c864458011b9
child 6656 5e1fd586ca85
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
src/cargotype.h
src/order_cmd.cpp
src/order_gui.cpp
src/roadveh_cmd.cpp
src/station_cmd.cpp
--- a/src/cargotype.h	Sun Mar 18 21:58:03 2007 +0000
+++ b/src/cargotype.h	Sun Mar 18 22:07:44 2007 +0000
@@ -57,5 +57,10 @@
 /* Get the cargo ID with the cargo label */
 CargoID GetCargoIDByLabel(CargoLabel cl);
 
+static inline bool IsCargoInClass(CargoID c, uint16 cc)
+{
+	return GetCargo(c)->classes & cc;
+}
+
 
 #endif /* CARGOTYPE_H */
--- a/src/order_cmd.cpp	Sun Mar 18 21:58:03 2007 +0000
+++ b/src/order_cmd.cpp	Sun Mar 18 22:07:44 2007 +0000
@@ -15,6 +15,7 @@
 #include "news.h"
 #include "saveload.h"
 #include "vehicle_gui.h"
+#include "cargotype.h"
 
 /**
  * Called if a new block is added to the order-pool
@@ -218,7 +219,7 @@
 					break;
 
 				case VEH_ROAD:
-					if (v->cargo_type == CT_PASSENGERS) {
+					if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
 						if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR;
 					} else {
 						if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR;
@@ -685,7 +686,7 @@
 
 			/* Trucks can't share orders with busses (and visa versa) */
 			if (src->type == VEH_ROAD) {
-				if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS))
+				if (src->cargo_type != dst->cargo_type && (IsCargoInClass(src->cargo_type, CC_PASSENGERS) || IsCargoInClass(dst->cargo_type, CC_PASSENGERS)))
 					return CMD_ERROR;
 			}
 
@@ -738,7 +739,7 @@
 				FOR_VEHICLE_ORDERS(src, order) {
 					if (order->type == OT_GOTO_STATION) {
 						const Station *st = GetStation(order->dest);
-						if (dst->cargo_type == CT_PASSENGERS) {
+						if (IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) {
 							if (st->bus_stops != NULL) required_dst = st->bus_stops->xy;
 						} else {
 							if (st->truck_stops != NULL) required_dst = st->truck_stops->xy;
@@ -953,7 +954,7 @@
 		case VEH_AIRCRAFT:  return st->airport_tile;
 		case VEH_SHIP:      return st->dock_tile;
 		case VEH_ROAD:
-			if (v->cargo_type == CT_PASSENGERS) {
+			if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
 				return (st->bus_stops != NULL) ? st->bus_stops->xy : 0;
 			} else {
 				return (st->truck_stops != NULL) ? st->truck_stops->xy : 0;
--- a/src/order_gui.cpp	Sun Mar 18 21:58:03 2007 +0000
+++ b/src/order_gui.cpp	Sun Mar 18 22:07:44 2007 +0000
@@ -297,7 +297,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 && v->cargo_type == CT_PASSENGERS) ||
+			(facil=FACIL_BUS_STOP, v->type == VEH_ROAD && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) ||
 			(facil=FACIL_TRUCK_STOP, 1);
 			if (st->facilities & facil) {
 				order.type = OT_GOTO_STATION;
--- a/src/roadveh_cmd.cpp	Sun Mar 18 21:58:03 2007 +0000
+++ b/src/roadveh_cmd.cpp	Sun Mar 18 22:07:44 2007 +0000
@@ -30,6 +30,7 @@
 #include "newgrf_sound.h"
 #include "yapf/yapf.h"
 #include "date.h"
+#include "cargotype.h"
 
 static const uint16 _roadveh_images[63] = {
 	0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
@@ -705,7 +706,7 @@
 			}
 
 			rs = GetStation(order->dest)->GetPrimaryRoadStop(
-				v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK
+				IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK
 			);
 
 			if (rs != NULL) {
@@ -843,7 +844,7 @@
 
 static void RoadVehArrivesAt(const Vehicle* v, Station* st)
 {
-	if (v->cargo_type == CT_PASSENGERS) {
+	if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
 		/* Check if station was ever visited before */
 		if (!(st->had_vehicle_of_type & HVOT_BUS)) {
 			uint32 flags;
@@ -1091,7 +1092,7 @@
 			trackdirs = TRACKDIR_BIT_NONE;
 		} else {
 			/* Our station */
-			RoadStop::Type rstype = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
+			RoadStop::Type rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
 
 			if (GetRoadStopType(tile) != rstype) {
 				/* Wrong station type */
@@ -1546,7 +1547,7 @@
 			_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) ||
 			(IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
 			v->current_order.dest == GetStationIndex(v->tile) &&
-			GetRoadStopType(v->tile) == ((v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
+			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
 			v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME)) {
 
 		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
@@ -1562,7 +1563,7 @@
 
 			if (IsDriveThroughStopTile(v->tile)) {
 				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
-				RoadStop::Type type = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
+				RoadStop::Type type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
 
 				assert(HASBIT(v->u.road.state, RVS_IS_STOPPING));
 
@@ -1754,7 +1755,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 = st->GetPrimaryRoadStop(v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK);
+		RoadStop* rs = st->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK);
 		RoadStop* best = NULL;
 
 		if (rs != NULL) {
--- a/src/station_cmd.cpp	Sun Mar 18 21:58:03 2007 +0000
+++ b/src/station_cmd.cpp	Sun Mar 18 22:07:44 2007 +0000
@@ -529,8 +529,9 @@
 		uint amt = min(accepts[i], 15);
 
 		// Make sure the station can accept the goods type.
-		if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
-				(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
+		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
+		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
+				(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
 			amt = 0;
 
 		SB(st->goods[i].waiting_acceptance, 12, 4, amt);
@@ -2163,7 +2164,7 @@
 					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
 
 					/* Check if the vehicle is stopping at this road stop */
-					if (GetRoadStopType(tile) == ((v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
+					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
 							v->current_order.dest == GetStationIndex(tile)) {
 						SETBIT(v->u.road.state, RVS_IS_STOPPING);
 						rs->AllocateDriveThroughBay(side);
@@ -2425,8 +2426,8 @@
 						(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights
 						st->goods[type].rating != 0 &&
 						(!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there.
-						((st->facilities & ~FACIL_BUS_STOP)   != 0 || type == CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers
-						((st->facilities & ~FACIL_TRUCK_STOP) != 0 || type != CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers
+						((st->facilities & ~FACIL_BUS_STOP)   != 0 || IsCargoInClass(type, CC_PASSENGERS)) && // if we have other fac. than a bus stop, or the cargo is passengers
+						((st->facilities & ~FACIL_TRUCK_STOP) != 0 || !IsCargoInClass(type, CC_PASSENGERS))) { // if we have other fac. than a cargo bay or the cargo is not passengers
 					if (_patches.modified_catchment) {
 						// min and max coordinates of the producer relative
 						const int x_min_prod = 9;