mirror of https://github.com/OpenTTD/OpenTTD
(svn r18381) -Codechange: Add RoadVehicle::IsBus() to simplify some stuff.
parent
2265202d77
commit
59f9163e37
|
@ -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 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
|
|||
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;
|
||||
|
|
|
@ -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 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
(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);
|
||||
|
|
|
@ -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 @@ public:
|
|||
{
|
||||
m_dest_station = sid;
|
||||
m_destTile = destTile;
|
||||
m_bus = IsCargoInClass(v->cargo_type, CC_PASSENGERS);
|
||||
m_bus = v->IsBus();
|
||||
m_non_artic = !v->HasArticulatedPart();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,8 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
|
|||
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
|
||||
|
|
|
@ -82,6 +82,17 @@ static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = {
|
|||
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 RoadVehicle *RoadVehFindCloseTo(RoadVehicle *v, int x, int y, Direction d
|
|||
|
||||
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 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
|
|||
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 @@ again:
|
|||
(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 @@ again:
|
|||
|
||||
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)) {
|
||||
|
|
|
@ -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 @@ void BaseStation::PostDestructor(size_t index)
|
|||
*/
|
||||
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) */
|
||||
|
|
|
@ -2699,7 +2699,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue