Changeset - r8836:911846a8cfa6
[Not reviewed]
master
0 22 0
rubidium - 17 years ago 2008-04-05 23:36:54
rubidium@openttd.org
(svn r12584) -Codechange: do not access the order type directly.
22 files changed with 259 insertions and 218 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -296,32 +296,31 @@ static EngineID AiChooseShipToReplaceWit
 
	/* Ships are not implemented in this (broken) AI */
 
	return INVALID_ENGINE;
 
}
 

	
 
static void AiHandleGotoDepot(Player *p, int cmd)
 
{
 
	if (_players_ai[p->index].cur_veh->current_order.type != OT_GOTO_DEPOT)
 
	if (!_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT))
 
		DoCommand(0, _players_ai[p->index].cur_veh->index, 0, DC_EXEC, cmd);
 

	
 
	if (++_players_ai[p->index].state_counter <= 1387) {
 
		_players_ai[p->index].state = AIS_VEH_DO_REPLACE_VEHICLE;
 
		return;
 
	}
 

	
 
	if (_players_ai[p->index].cur_veh->current_order.type == OT_GOTO_DEPOT) {
 
		_players_ai[p->index].cur_veh->current_order.type = OT_DUMMY;
 
		_players_ai[p->index].cur_veh->current_order.flags = 0;
 
	if (_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT)) {
 
		_players_ai[p->index].cur_veh->current_order.MakeDummy();
 
		InvalidateWindow(WC_VEHICLE_VIEW, _players_ai[p->index].cur_veh->index);
 
	}
 
}
 

	
 
static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
 
{
 
	if (bak->order == NULL) return;
 

	
 
	for (uint i = 0; bak->order[i].type != OT_NOTHING; i++) {
 
	for (uint i = 0; !bak->order[i].IsType(OT_NOTHING); i++) {
 
		if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
 
			break;
 
	}
 
}
 

	
 
static void AiHandleReplaceTrain(Player *p)
 
@@ -2550,15 +2549,13 @@ handle_nocash:
 
			_players_ai[p->index].cargo_type == CT_PASSENGERS ||
 
			_players_ai[p->index].cargo_type == CT_MAIL ||
 
			(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES)
 
		);
 
		Order order;
 

	
 
		order.type = OT_GOTO_STATION;
 
		order.flags = 0;
 
		order.dest = AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule);
 
		order.MakeGoToStation(AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule));
 

	
 
		if (!is_pass && i == 1) order.flags |= OFB_UNLOAD;
 
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
 
			order.flags |= OFB_FULL_LOAD;
 

	
 
		DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 
@@ -3287,15 +3284,13 @@ static void AiStateBuildRoadVehicles(Pla
 
			_players_ai[p->index].cargo_type == CT_PASSENGERS ||
 
			_players_ai[p->index].cargo_type == CT_MAIL ||
 
			(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES)
 
		);
 
		Order order;
 

	
 
		order.type = OT_GOTO_STATION;
 
		order.flags = 0;
 
		order.dest = AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule);
 
		order.MakeGoToStation(AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule));
 

	
 
		if (!is_pass && i == 1) order.flags |= OFB_UNLOAD;
 
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
 
			order.flags |= OFB_FULL_LOAD;
 

	
 
		DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 
@@ -3568,15 +3563,13 @@ static void AiStateBuildAircraftVehicles
 

	
 
	for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) {
 
		AiBuildRec *aib = (&_players_ai[p->index].src) + _players_ai[p->index].order_list_blocks[i];
 
		bool is_pass = (_players_ai[p->index].cargo_type == CT_PASSENGERS || _players_ai[p->index].cargo_type == CT_MAIL);
 
		Order order;
 

	
 
		order.type = OT_GOTO_STATION;
 
		order.flags = 0;
 
		order.dest = AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule);
 
		order.MakeGoToStation(AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule));
 

	
 
		if (!is_pass && i == 1) order.flags |= OFB_UNLOAD;
 
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
 
			order.flags |= OFB_FULL_LOAD;
 

	
 
		DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 
@@ -3611,31 +3604,31 @@ static void AiStateSellVeh(Player *p)
 
	Vehicle *v = _players_ai[p->index].cur_veh;
 

	
 
	if (v->owner == _current_player) {
 
		if (v->type == VEH_TRAIN) {
 

	
 
			if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) {
 
				if (v->current_order.type != OT_GOTO_DEPOT)
 
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
 
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_TRAIN_TO_DEPOT);
 
				goto going_to_depot;
 
			}
 

	
 
			// Sell whole train
 
			DoCommand(v->tile, v->index, 1, DC_EXEC, CMD_SELL_RAIL_WAGON);
 

	
 
		} else if (v->type == VEH_ROAD) {
 
			if (!v->IsStoppedInDepot()) {
 
				if (v->current_order.type != OT_GOTO_DEPOT)
 
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
 
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT);
 
				goto going_to_depot;
 
			}
 

	
 
			DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
 
		} else if (v->type == VEH_AIRCRAFT) {
 
			if (!v->IsStoppedInDepot()) {
 
				if (v->current_order.type != OT_GOTO_DEPOT)
 
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
 
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
				goto going_to_depot;
 
			}
 

	
 
			DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT);
 
		} else if (v->type == VEH_SHIP) {
 
@@ -3644,15 +3637,14 @@ static void AiStateSellVeh(Player *p)
 
	}
 

	
 
	goto return_to_loop;
 
going_to_depot:;
 
	if (++_players_ai[p->index].state_counter <= 832) return;
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT) {
 
		v->current_order.type = OT_DUMMY;
 
		v->current_order.flags = 0;
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.MakeDummy();
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
	}
 
return_to_loop:;
 
	_players_ai[p->index].state = AIS_VEH_LOOP;
 
}
 

	
 
@@ -3667,13 +3659,13 @@ static void AiStateRemoveStation(Player 
 
	_players_ai[p->index].state = AIS_1;
 

	
 
	// Get a list of all stations that are in use by a vehicle
 
	byte *in_use = MallocT<byte>(GetMaxStationIndex() + 1);
 
	memset(in_use, 0, GetMaxStationIndex() + 1);
 
	FOR_ALL_ORDERS(ord) {
 
		if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1;
 
		if (ord->IsType(OT_GOTO_STATION)) in_use[ord->dest] = 1;
 
	}
 

	
 
	// Go through all stations and delete those that aren't in use
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner == _current_player && !in_use[st->index] &&
 
				( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) ||
src/ai/trolly/trolly.cpp
Show inline comments
 
@@ -550,13 +550,13 @@ static bool AiNew_CheckVehicleStation(Pl
 
	// Also check if we don't have already a lot of busses to this city...
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->owner == _current_player) {
 
			const Order *order;
 

	
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->type == OT_GOTO_STATION && GetStation(order->dest) == st) {
 
				if (order->IsType(OT_GOTO_STATION) && GetStation(order->dest) == st) {
 
					// This vehicle has this city in its list
 
					count++;
 
				}
 
			}
 
		}
 
	}
 
@@ -1181,30 +1181,24 @@ static void AiNew_State_GiveOrders(Playe
 
		_players_ainew[p->index].veh_main_id = _players_ainew[p->index].veh_id;
 
	}
 

	
 
	// Very handy for AI, goto depot.. but yeah, it needs to be activated ;)
 
	if (_patches.gotodepot) {
 
		idx = 0;
 
		order.type = OT_GOTO_DEPOT;
 
		order.flags = OFB_UNLOAD;
 
		order.dest = GetDepotByTile(_players_ainew[p->index].depot_tile)->index;
 
		order.MakeGoToDepot(GetDepotByTile(_players_ainew[p->index].depot_tile)->index, true);
 
		AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 
	}
 

	
 
	idx = 0;
 
	order.type = OT_GOTO_STATION;
 
	order.flags = 0;
 
	order.dest = GetStationIndex(_players_ainew[p->index].to_tile);
 
	order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].to_tile));
 
	if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].to_deliver)
 
		order.flags |= OFB_FULL_LOAD;
 
	AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 

	
 
	idx = 0;
 
	order.type = OT_GOTO_STATION;
 
	order.flags = 0;
 
	order.dest = GetStationIndex(_players_ainew[p->index].from_tile);
 
	order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].from_tile));
 
	if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].from_deliver)
 
		order.flags |= OFB_FULL_LOAD;
 
	AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 

	
 
	// Start the engines!
 
	_players_ainew[p->index].state = AI_STATE_START_VEHICLE;
src/aircraft_cmd.cpp
Show inline comments
 
@@ -566,13 +566,13 @@ CommandCost CmdSendAircraftToHangar(Tile
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || v->IsInDepot()) return CMD_ERROR;
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT && !(p2 & DEPOT_LOCATE_HANGAR)) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) && !(p2 & DEPOT_LOCATE_HANGAR)) {
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same hangar.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in hangar) */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OF_PART_OF_ORDERS);
 
@@ -582,14 +582,13 @@ CommandCost CmdSendAircraftToHangar(Tile
 
			return CommandCost();
 
		}
 

	
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of hangar orders
 
		if (flags & DC_EXEC) {
 
			if (v->current_order.flags & OFB_UNLOAD) v->cur_order_index++;
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
	} else {
 
		bool next_airport_has_hangar = true;
 
		StationID next_airport_index = v->u.air.targetairport;
 
		const Station *st = GetStation(next_airport_index);
 
@@ -601,19 +600,16 @@ CommandCost CmdSendAircraftToHangar(Tile
 
			next_airport_has_hangar = false;
 
			if (station == INVALID_STATION) return CMD_ERROR;
 
			next_airport_index = station;
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
			if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 

	
 
			v->current_order.type = OT_GOTO_DEPOT;
 
			v->current_order.flags = OFB_NON_STOP;
 
			v->current_order.MakeGoToDepot(next_airport_index, false);
 
			if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT);
 
			v->current_order.refit_cargo = CT_INVALID;
 
			v->current_order.dest = next_airport_index;
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
			if (v->u.air.state == FLYING && !next_airport_has_hangar) {
 
				/* The aircraft is now heading for a different hangar than the next in the orders */
 
				AircraftNextAirportPos_and_Order(v);
 
			}
 
		}
 
@@ -711,18 +707,16 @@ static void CheckIfAircraftNeedsService(
 

	
 
	const Station *st = GetStation(v->current_order.dest);
 
	/* only goto depot if the target airport has terminals (eg. it is airport) */
 
	if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) {
 
//		printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
 
//		v->u.air.targetairport = st->index;
 
		v->current_order.type = OT_GOTO_DEPOT;
 
		v->current_order.flags = OFB_NON_STOP;
 
		v->current_order.MakeGoToDepot(INVALID_STATION, false);
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	} else if (v->current_order.type == OT_GOTO_DEPOT) {
 
		v->current_order.type = OT_DUMMY;
 
		v->current_order.flags = 0;
 
	} else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.MakeDummy();
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 
}
 

	
 
void Aircraft::OnNewDay()
 
{
 
@@ -777,13 +771,13 @@ static void HelicopterTickHandler(Vehicl
 
	Vehicle *u = v->Next()->Next();
 

	
 
	if (u->vehstatus & VS_HIDDEN) return;
 

	
 
	/* if true, helicopter rotors do not rotate. This should only be the case if a helicopter is
 
	 * loading/unloading at a terminal or stopped */
 
	if (v->current_order.type == OT_LOADING || (v->vehstatus & VS_STOPPED)) {
 
	if (v->current_order.IsType(OT_LOADING) || (v->vehstatus & VS_STOPPED)) {
 
		if (u->cur_speed != 0) {
 
			u->cur_speed++;
 
			if (u->cur_speed >= 0x80 && u->u.air.state == HRS_ROTOR_MOVING_3) {
 
				u->cur_speed = 0;
 
			}
 
		}
 
@@ -1385,13 +1379,13 @@ void HandleMissingAircraftOrders(Vehicle
 

	
 
		_current_player = v->owner;
 
		ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		_current_player = old_player;
 

	
 
		if (CmdFailed(ret)) CrashAirplane(v);
 
	} else if (v->current_order.type != OT_GOTO_DEPOT) {
 
	} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.Free();
 
	}
 
}
 

	
 

	
 
TileIndex Aircraft::GetOrderStationLocation(StationID station)
 
@@ -1468,13 +1462,13 @@ static void MaybeCrashAirplane(Vehicle *
 
	CrashAirplane(v);
 
}
 

	
 
/** we've landed and just arrived at a terminal */
 
static void AircraftEntersTerminal(Vehicle *v)
 
{
 
	if (v->current_order.type == OT_GOTO_DEPOT) return;
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) return;
 

	
 
	Station *st = GetStation(v->u.air.targetairport);
 
	v->last_station_visited = v->u.air.targetairport;
 

	
 
	/* Check if station was ever visited before */
 
	if (!(st->had_vehicle_of_type & HVOT_AIRCRAFT)) {
 
@@ -1502,14 +1496,14 @@ static void AircraftLandAirplane(Vehicle
 
}
 

	
 

	
 
/** set the right pos when heading to other airports after takeoff */
 
static void AircraftNextAirportPos_and_Order(Vehicle *v)
 
{
 
	if (v->current_order.type == OT_GOTO_STATION ||
 
			v->current_order.type == OT_GOTO_DEPOT)
 
	if (v->current_order.IsType(OT_GOTO_STATION) ||
 
			v->current_order.IsType(OT_GOTO_DEPOT))
 
		v->u.air.targetairport = v->current_order.dest;
 

	
 
	const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport();
 
	v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc);
 
}
 

	
 
@@ -1600,19 +1594,19 @@ static void AircraftEventHandler_InHanga
 
	if (v->u.air.previous_pos != v->u.air.pos) {
 
		AircraftEventHandler_EnterHangar(v, apc);
 
		return;
 
	}
 

	
 
	/* if we were sent to the depot, stay there */
 
	if (v->current_order.type == OT_GOTO_DEPOT && (v->vehstatus & VS_STOPPED)) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) && (v->vehstatus & VS_STOPPED)) {
 
		v->current_order.Free();
 
		return;
 
	}
 

	
 
	if (v->current_order.type != OT_GOTO_STATION &&
 
			v->current_order.type != OT_GOTO_DEPOT)
 
	if (!v->current_order.IsType(OT_GOTO_STATION) &&
 
			!v->current_order.IsType(OT_GOTO_DEPOT))
 
		return;
 

	
 
	/* if the block of the next position is busy, stay put */
 
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
 

	
 
	/* We are already at the target airport, we need to find a terminal */
 
@@ -1657,13 +1651,13 @@ static void AircraftEventHandler_AtTermi
 
	/* if the block of the next position is busy, stay put */
 
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
 

	
 
	/* airport-road is free. We either have to go to another airport, or to the hangar
 
	 * ---> start moving */
 

	
 
	switch (v->current_order.type) {
 
	switch (v->current_order.GetType()) {
 
		case OT_GOTO_STATION: // ready to fly to another airport
 
			/* airplane goto state takeoff, helicopter to helitakeoff */
 
			v->u.air.state = (v->subtype == AIR_HELICOPTER) ? HELITAKEOFF : TAKEOFF;
 
			break;
 
		case OT_GOTO_DEPOT:   // visit hangar for serivicing, sale, etc.
 
			if (v->current_order.dest == v->u.air.targetairport) {
 
@@ -1783,13 +1777,13 @@ static void AircraftEventHandler_EndLand
 
	if (AirportHasBlock(v, &apc->layout[v->u.air.pos], apc)) return;
 

	
 
	/* if going to terminal (OT_GOTO_STATION) choose one
 
	 * 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
 
	 * 2. not going for terminal (but depot, no order),
 
	 * --> get out of the way to the hangar. */
 
	if (v->current_order.type == OT_GOTO_STATION) {
 
	if (v->current_order.IsType(OT_GOTO_STATION)) {
 
		if (AirportFindFreeTerminal(v, apc)) return;
 
	}
 
	v->u.air.state = HANGAR;
 

	
 
}
 

	
 
@@ -1802,13 +1796,13 @@ static void AircraftEventHandler_HeliEnd
 
	 * 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or
 
	 * 2. not going for terminal (but depot, no order),
 
	 * --> get out of the way to the hangar IF there are terminals on the airport.
 
	 * --> else TAKEOFF
 
	 * the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
 
	 * must go to a hangar. */
 
	if (v->current_order.type == OT_GOTO_STATION) {
 
	if (v->current_order.IsType(OT_GOTO_STATION)) {
 
		if (AirportFindFreeHelipad(v, apc)) return;
 
	}
 
	v->u.air.state = (apc->nof_depots != 0) ? HANGAR : HELITAKEOFF;
 
}
 

	
 
typedef void AircraftStateHandler(Vehicle *v, const AirportFTAClass *apc);
 
@@ -2123,13 +2117,13 @@ static void AircraftEventHandler(Vehicle
 
	}
 

	
 
	HandleAircraftSmoke(v);
 
	ProcessOrders(v);
 
	v->HandleLoading(loop != 0);
 

	
 
	if (v->current_order.type >= OT_LOADING) return;
 
	if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return;
 

	
 
	AirportGoToNextPosition(v);
 
}
 

	
 
void Aircraft::Tick()
 
{
src/industry_cmd.cpp
Show inline comments
 
@@ -1964,13 +1964,13 @@ int WhoCanServiceIndustry(Industry* ind)
 
		/* Check orders of the vehicle.
 
		 * We cannot check the first of shared orders only, since the first vehicle in such a chain
 
		 * may have a different cargo type.
 
		 */
 
		const Order *o;
 
		FOR_VEHICLE_ORDERS(v, o) {
 
			if (o->type == OT_GOTO_STATION && !HasBit(o->flags, OF_TRANSFER)) {
 
			if (o->IsType(OT_GOTO_STATION) && !HasBit(o->flags, OF_TRANSFER)) {
 
				/* Vehicle visits a station to load or unload */
 
				Station *st = GetStation(o->dest);
 
				if (!st->IsValid()) continue;
 

	
 
				/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
 
				if (HasBit(o->flags, OF_UNLOAD) && !c_accepts) break;
src/newgrf_engine.cpp
Show inline comments
 
@@ -345,27 +345,27 @@ static byte MapAircraftMovementAction(co
 
	switch (v->u.air.state) {
 
		case HANGAR:
 
			return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
 

	
 
		case TERM1:
 
		case HELIPAD1:
 
			return (v->current_order.type == OT_LOADING) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
 
			return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
 

	
 
		case TERM2:
 
		case HELIPAD2:
 
			return (v->current_order.type == OT_LOADING) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
 
			return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
 

	
 
		case TERM3:
 
		case TERM4:
 
		case TERM5:
 
		case TERM6:
 
		case TERM7:
 
		case TERM8:
 
		case HELIPAD3:
 
		case HELIPAD4:
 
			return (v->current_order.type == OT_LOADING) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
 
			return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
 

	
 
		case TAKEOFF:      // Moving to takeoff position
 
		case STARTTAKEOFF: // Accelerating down runway
 
		case ENDTAKEOFF:   // Ascent
 
		case HELITAKEOFF:
 
			/* @todo Need to find which terminal (or hanger) we've come from. How? */
 
@@ -376,13 +376,13 @@ static byte MapAircraftMovementAction(co
 

	
 
		case LANDING:    // Descent
 
		case ENDLANDING: // On the runway braking
 
		case HELILANDING:
 
		case HELIENDLANDING:
 
			/* @todo Need to check terminal we're landing to. Is it known yet? */
 
			return (v->current_order.type == OT_GOTO_DEPOT) ?
 
			return (v->current_order.IsType(OT_GOTO_DEPOT)) ?
 
				AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
 

	
 
		default:
 
			return AMA_TTDP_IN_HANGAR;
 
	}
 
}
 
@@ -808,13 +808,13 @@ static const SpriteGroup *VehicleResolve
 
	if (v == NULL) {
 
		if (group->g.real.num_loading > 0) return group->g.real.loading[0];
 
		if (group->g.real.num_loaded  > 0) return group->g.real.loaded[0];
 
		return NULL;
 
	}
 

	
 
	bool in_motion = v->First()->current_order.type != OT_LOADING;
 
	bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
 

	
 
	totalsets = in_motion ? group->g.real.num_loaded : group->g.real.num_loading;
 

	
 
	if (v->cargo.Count() >= v->cargo_cap || totalsets == 1) {
 
		set = totalsets - 1;
 
	} else if (v->cargo.Empty() || totalsets == 2) {
src/npf.cpp
Show inline comments
 
@@ -977,13 +977,13 @@ void NPFFillWithOrderData(NPFFindStation
 
	/* Ships don't really reach their stations, but the tile in front. So don't
 
	 * save the station id for ships. For roadvehs we don't store it either,
 
	 * because multistop depends on vehicles actually reaching the exact
 
	 * dest_tile, not just any stop of that station.
 
	 * So only for train orders to stations we fill fstd->station_index, for all
 
	 * others only dest_coords */
 
	if (v->current_order.type == OT_GOTO_STATION && v->type == VEH_TRAIN) {
 
	if (v->current_order.IsType(OT_GOTO_STATION) && v->type == VEH_TRAIN) {
 
		fstd->station_index = v->current_order.dest;
 
		/* Let's take the closest tile of the station as our target for trains */
 
		fstd->dest_coords = CalcClosestStationTile(v->current_order.dest, v->tile);
 
	} else {
 
		fstd->dest_coords = v->dest_tile;
 
		fstd->station_index = INVALID_STATION;
src/oldloader.cpp
Show inline comments
 
@@ -342,14 +342,14 @@ static void FixOldVehicles()
 

	
 
		/* Sometimes primary vehicles would have a nothing (invalid) order
 
		 * or vehicles that could not have an order would still have a
 
		 * (loading) order which causes assertions and the like later on.
 
		 */
 
		if (!IsPlayerBuildableVehicleType(v) ||
 
				(v->IsPrimaryVehicle() && v->current_order.type == OT_NOTHING)) {
 
			v->current_order.type = OT_DUMMY;
 
				(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
 
			v->current_order.MakeDummy();
 
		}
 

	
 
		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
 
			/* If a vehicle has the same orders, add the link to eachother
 
			 * in both vehicles */
 
			if (v->orders == u->orders) {
src/openttd.cpp
Show inline comments
 
@@ -2175,13 +2175,13 @@ bool AfterLoadGame()
 
	if (CheckSavegameVersion(57)) {
 
		Vehicle *v;
 
		/* Added a FIFO queue of vehicles loading at stations */
 
		FOR_ALL_VEHICLES(v) {
 
			if ((v->type != VEH_TRAIN || IsFrontEngine(v)) &&  // for all locs
 
					!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
 
					v->current_order.type == OT_LOADING) {         // loading
 
					v->current_order.IsType(OT_LOADING)) {         // loading
 
				GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
 

	
 
				/* The loading finished flag is *only* set when actually completely
 
				 * finished. Because the vehicle is loading, it is not finished. */
 
				ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
 
			}
 
@@ -2192,13 +2192,13 @@ bool AfterLoadGame()
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			std::list<Vehicle *>::iterator iter;
 
			for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
 
				Vehicle *v = *iter;
 
				iter++;
 
				if (v->current_order.type != OT_LOADING) st->loading_vehicles.remove(v);
 
				if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
 
			}
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(58)) {
 
		/* patch difficulty number_industries other then zero get bumped to +1
 
@@ -2304,13 +2304,13 @@ bool AfterLoadGame()
 
	}
 

	
 
	if (CheckSavegameVersion(84)) {
 
		/* Update go to buoy orders because they are just waypoints */
 
		Order *order;
 
		FOR_ALL_ORDERS(order) {
 
			if (order->type == OT_GOTO_STATION && GetStation(order->dest)->IsBuoy()) {
 
			if (order->IsType(OT_GOTO_STATION) && GetStation(order->dest)->IsBuoy()) {
 
				order->flags = 0;
 
			}
 
		}
 

	
 
		/* Set all share owners to PLAYER_SPECTATOR for
 
		 * 1) all inactive players
src/order_base.h
Show inline comments
 
@@ -6,26 +6,39 @@
 
#define ORDER_BASE_H
 

	
 
#include "order_type.h"
 
#include "oldpool.h"
 
#include "core/bitmath_func.hpp"
 
#include "cargo_type.h"
 
#include "depot_type.h"
 
#include "station_type.h"
 
#include "vehicle_type.h"
 
#include "waypoint_type.h"
 

	
 
DECLARE_OLD_POOL(Order, Order, 6, 1000)
 

	
 
/* If you change this, keep in mind that it is saved on 3 places:
 
 * - Load_ORDR, all the global orders
 
 * - Vehicle -> current_order
 
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
 
 */
 
struct Order : PoolItem<Order, OrderID, &_Order_pool> {
 
private:
 
	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt); ///< Saving and loading the current order of vehicles.
 
	friend void Load_VEHS();                                             ///< Loading of ancient vehicles.
 
	friend const struct SaveLoad *GetOrderDescription();                 ///< Saving and loading of orders.
 
	friend uint32 PackOrder(const Order *order);                         ///< 'Compressing' an order.
 
	friend Order UnpackOrder(uint32 packed);                             ///< 'Uncompressing' an order.
 
	friend Order UnpackOldOrder(uint16 packed);                          ///< 'Uncompressing' a loaded old order.
 
	friend Order UnpackVersion4Order(uint16 packed);                     ///< 'Uncompressing' a loaded ancient order.
 

	
 
	OrderTypeByte type;
 

	
 
public:
 
	Order *next;          ///< Pointer to next order. If NULL, end of list
 

	
 
	OrderTypeByte type;
 
	uint8  flags;
 
	DestinationID dest;   ///< The destionation of the order.
 

	
 
	CargoID refit_cargo; // Refit CargoID
 
	byte refit_subtype; // Refit subtype
 

	
 
@@ -34,22 +47,70 @@ struct Order : PoolItem<Order, OrderID, 
 

	
 
	Order() : refit_cargo(CT_NO_REFIT) {}
 
	~Order() { this->type = OT_NOTHING; }
 

	
 
	/**
 
	 * Check if a Order really exists.
 
	 * @return true if the order is valid.
 
	 */
 
	inline bool IsValid() const { return this->type != OT_NOTHING; }
 

	
 
	/**
 
	 * Check whether this order is of the given type.
 
	 * @param type the type to check against.
 
	 * @return true if the order matches.
 
	 */
 
	inline bool IsType(OrderType type) const { return this->type == type; }
 

	
 
	/**
 
	 * Get the type of order of this order.
 
	 * @return the order type.
 
	 */
 
	inline OrderType GetType() const { return this->type; }
 

	
 
	/**
 
	 * 'Free' the order
 
	 * @note ONLY use on "current_order" vehicle orders!
 
	 */
 
	void Free();
 

	
 
	/**
 
	 * Makes this order a Go To Station order.
 
	 * @param destsination the station to go to.
 
	 */
 
	void MakeGoToStation(StationID destination);
 

	
 
	/**
 
	 * Makes this order a Go To Depot order.
 
	 * @param destination the depot to go to.
 
	 * @param order       is this order a 'default' order, or an overriden vehicle order?
 
	 */
 
	void MakeGoToDepot(DepotID destination, bool order);
 

	
 
	/**
 
	 * Makes this order a Go To Waypoint order.
 
	 * @param destination the waypoint to go to.
 
	 */
 
	void MakeGoToWaypoint(WaypointID destination);
 

	
 
	/**
 
	 * Makes this order a Loading order.
 
	 */
 
	void MakeLoading();
 

	
 
	/**
 
	 * Makes this order a Leave Station order.
 
	 */
 
	void MakeLeaveStation();
 

	
 
	/**
 
	 * Makes this order a Dummy order.
 
	 */
 
	void MakeDummy();
 

	
 
	/**
 
	 * Free a complete order chain.
 
	 * @note do not use on "current_order" vehicle orders!
 
	 */
 
	void FreeChain();
 

	
 
	bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
src/order_cmd.cpp
Show inline comments
 
@@ -45,12 +45,52 @@ void Order::Free()
 
	this->type  = OT_NOTHING;
 
	this->flags = 0;
 
	this->dest  = 0;
 
	this->next  = NULL;
 
}
 

	
 
void Order::MakeGoToStation(StationID destination)
 
{
 
	this->type = OT_GOTO_STATION;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 

	
 
void Order::MakeGoToDepot(DepotID destination, bool order)
 
{
 
	this->type = OT_GOTO_DEPOT;
 
	this->flags = order ? OFB_PART_OF_ORDERS : OFB_NON_STOP;
 
	this->dest = destination;
 
	this->refit_cargo = CT_NO_REFIT;
 
	this->refit_subtype = 0;
 
}
 

	
 
void Order::MakeGoToWaypoint(WaypointID destination)
 
{
 
	this->type = OT_GOTO_WAYPOINT;
 
	this->flags = 0;
 
	this->dest = destination;
 
}
 

	
 
void Order::MakeLoading()
 
{
 
	this->type = OT_LOADING;
 
}
 

	
 
void Order::MakeLeaveStation()
 
{
 
	this->type = OT_LEAVESTATION;
 
	this->flags = 0;
 
}
 

	
 
void Order::MakeDummy()
 
{
 
	this->type = OT_DUMMY;
 
	this->flags = 0;
 
}
 

	
 
void Order::FreeChain()
 
{
 
	if (next != NULL) next->FreeChain();
 
	delete this;
 
}
 

	
 
@@ -125,13 +165,13 @@ Order UnpackOldOrder(uint16 packed)
 

	
 
/**
 
 *
 
 * Unpacks a order from savegames with version 4 and lower
 
 *
 
 */
 
static Order UnpackVersion4Order(uint16 packed)
 
Order UnpackVersion4Order(uint16 packed)
 
{
 
	Order order;
 
	order.type  = (OrderType)GB(packed, 0, 4);
 
	order.flags = GB(packed, 4, 4);
 
	order.dest  = GB(packed, 8, 8);
 
	order.next  = NULL;
 
@@ -205,13 +245,13 @@ static void DeleteOrderWarnings(const Ve
 
	DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY   + v->type * 4);
 
}
 

	
 

	
 
static TileIndex GetOrderLocation(const Order& o)
 
{
 
	switch (o.type) {
 
	switch (o.GetType()) {
 
		default: NOT_REACHED();
 
		case OT_GOTO_STATION: return GetStation(o.dest)->xy;
 
		case OT_GOTO_DEPOT:   return GetDepot(o.dest)->xy;
 
	}
 
}
 

	
 
@@ -238,13 +278,13 @@ CommandCost CmdInsertOrder(TileIndex til
 
	v = GetVehicle(veh);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Check if the inserted order is to the correct destination (owner, type),
 
	 * and has the correct flags if any */
 
	switch (new_order.type) {
 
	switch (new_order.GetType()) {
 
		case OT_GOTO_STATION: {
 
			const Station *st;
 

	
 
			if (!IsValidStationID(new_order.dest)) return CMD_ERROR;
 
			st = GetStation(new_order.dest);
 

	
 
@@ -398,13 +438,13 @@ CommandCost CmdInsertOrder(TileIndex til
 
		uint n = 0;
 

	
 
		/* Find the last goto station or depot order before the insert location.
 
		 * If the order is to be inserted at the beginning of the order list this
 
		 * finds the last order in the list. */
 
		for (const Order *o = v->orders; o != NULL; o = o->next) {
 
			if (o->type == OT_GOTO_STATION || o->type == OT_GOTO_DEPOT) prev = o;
 
			if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o;
 
			if (++n == sel_ord && prev != NULL) break;
 
		}
 
		if (prev != NULL) {
 
			uint dist = DistanceManhattan(
 
				GetOrderLocation(*prev),
 
				GetOrderLocation(new_order)
 
@@ -572,13 +612,13 @@ CommandCost CmdDeleteOrder(TileIndex til
 
			if (v->orders == NULL) u->orders = NULL;
 

	
 
			assert(v->orders == u->orders);
 

	
 
			/* NON-stop flag is misused to see if a train is in a station that is
 
			 * on his order list or not */
 
			if (sel_ord == u->cur_order_index && u->current_order.type == OT_LOADING &&
 
			if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING) &&
 
					HasBit(u->current_order.flags, OF_NON_STOP)) {
 
				u->current_order.flags = 0;
 
			}
 

	
 
			/* Update any possible open window of the vehicle */
 
			InvalidateVehicleOrder(u);
 
@@ -611,13 +651,13 @@ CommandCost CmdSkipToOrder(TileIndex til
 

	
 
	if (flags & DC_EXEC) {
 
		v->cur_order_index = sel_ord;
 

	
 
		if (v->type == VEH_ROAD) ClearSlot(v);
 

	
 
		if (v->current_order.type == OT_LOADING) {
 
		if (v->current_order.IsType(OT_LOADING)) {
 
			v->LeaveStation();
 
			/* NON-stop flag is misused to see if a train is in a station that is
 
			 * on his order list or not */
 
			if (HasBit(v->current_order.flags, OF_NON_STOP)) v->current_order.flags = 0;
 
		}
 

	
 
@@ -742,23 +782,23 @@ CommandCost CmdModifyOrder(TileIndex til
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Is it a valid order? */
 
	if (sel_ord >= v->num_orders) return CMD_ERROR;
 

	
 
	order = GetVehicleOrder(v, sel_ord);
 
	if ((order->type != OT_GOTO_STATION  || GetStation(order->dest)->IsBuoy()) &&
 
			(order->type != OT_GOTO_DEPOT    || p2 == OF_UNLOAD) &&
 
			(order->type != OT_GOTO_WAYPOINT || p2 != OF_NON_STOP)) {
 
	if ((!order->IsType(OT_GOTO_STATION)  || GetStation(order->dest)->IsBuoy()) &&
 
			(!order->IsType(OT_GOTO_DEPOT)    || p2 == OF_UNLOAD) &&
 
			(!order->IsType(OT_GOTO_WAYPOINT) || p2 != OF_NON_STOP)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		switch (p2) {
 
		case OF_FULL_LOAD:
 
			ToggleBit(order->flags, OF_FULL_LOAD);
 
			if (order->type != OT_GOTO_DEPOT) ClrBit(order->flags, OF_UNLOAD);
 
			if (!order->IsType(OT_GOTO_DEPOT)) ClrBit(order->flags, OF_UNLOAD);
 
			break;
 
		case OF_UNLOAD:
 
			ToggleBit(order->flags, OF_UNLOAD);
 
			ClrBit(order->flags, OF_FULL_LOAD);
 
			break;
 
		case OF_NON_STOP:
 
@@ -784,13 +824,13 @@ CommandCost CmdModifyOrder(TileIndex til
 
				 * one case where the flag is used for depot orders. In the
 
				 * other cases for the OrderTypeByte the flags are not used,
 
				 * so do not care and those orders should not be active
 
				 * when this function is called.
 
				 */
 
				if (sel_ord == u->cur_order_index &&
 
						u->current_order.type != OT_GOTO_DEPOT &&
 
						!u->current_order.IsType(OT_GOTO_DEPOT) &&
 
						HasBit(u->current_order.flags, OF_FULL_LOAD) != HasBit(order->flags, OF_FULL_LOAD)) {
 
					ToggleBit(u->current_order.flags, OF_FULL_LOAD);
 
				}
 
				InvalidateVehicleOrder(u);
 
			}
 
		}
 
@@ -881,13 +921,13 @@ CommandCost CmdCloneOrder(TileIndex tile
 
			/* Trucks can't copy all the orders from busses (and visa versa) */
 
			if (src->type == VEH_ROAD) {
 
				const Order *order;
 
				TileIndex required_dst = INVALID_TILE;
 

	
 
				FOR_VEHICLE_ORDERS(src, order) {
 
					if (order->type == OT_GOTO_STATION) {
 
					if (order->IsType(OT_GOTO_STATION)) {
 
						const Station *st = GetStation(order->dest);
 
						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;
 
						}
 
@@ -1159,18 +1199,18 @@ void CheckOrders(const Vehicle* v)
 

	
 
		/* Check the order list */
 
		n_st = 0;
 

	
 
		FOR_VEHICLE_ORDERS(v, order) {
 
			/* Dummy order? */
 
			if (order->type == OT_DUMMY) {
 
			if (order->IsType(OT_DUMMY)) {
 
				problem_type = 1;
 
				break;
 
			}
 
			/* Does station have a load-bay for this vehicle? */
 
			if (order->type == OT_GOTO_STATION) {
 
			if (order->IsType(OT_GOTO_STATION)) {
 
				const Station* st = GetStation(order->dest);
 
				TileIndex required_tile = GetStationTileForVehicle(v, st);
 

	
 
				n_st++;
 
				if (required_tile == 0) problem_type = 3;
 
			}
 
@@ -1225,26 +1265,24 @@ void RemoveOrderFromAllVehicles(OrderTyp
 
		/* Forget about this station if this station is removed */
 
		if (v->last_station_visited == destination && type == OT_GOTO_STATION) {
 
			v->last_station_visited = INVALID_STATION;
 
		}
 

	
 
		order = &v->current_order;
 
		if ((v->type == VEH_AIRCRAFT && order->type == OT_GOTO_DEPOT ? OT_GOTO_STATION : order->type) == type &&
 
		if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type &&
 
				v->current_order.dest == destination) {
 
			order->type = OT_DUMMY;
 
			order->flags = 0;
 
			order->MakeDummy();
 
			InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
		}
 

	
 
		/* Clear the order from the order-list */
 
		invalidate = false;
 
		FOR_VEHICLE_ORDERS(v, order) {
 
			if ((v->type == VEH_AIRCRAFT && order->type == OT_GOTO_DEPOT ? OT_GOTO_STATION : order->type) == type &&
 
			if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type &&
 
					order->dest == destination) {
 
				order->type = OT_DUMMY;
 
				order->flags = 0;
 
				order->MakeDummy();
 
				invalidate = true;
 
			}
 
		}
 

	
 
		/* Only invalidate once, and if needed */
 
		if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index);
 
@@ -1260,13 +1298,13 @@ void RemoveOrderFromAllVehicles(OrderTyp
 
 */
 
bool VehicleHasDepotOrders(const Vehicle *v)
 
{
 
	const Order *order;
 

	
 
	FOR_VEHICLE_ORDERS(v, order) {
 
		if (order->type == OT_GOTO_DEPOT)
 
		if (order->IsType(OT_GOTO_DEPOT))
 
			return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
@@ -1337,13 +1375,13 @@ Date GetServiceIntervalClamped(uint inde
 
 *
 
 */
 
static bool CheckForValidOrders(const Vehicle *v)
 
{
 
	const Order *order;
 

	
 
	FOR_VEHICLE_ORDERS(v, order) if (order->type != OT_DUMMY) return true;
 
	FOR_VEHICLE_ORDERS(v, order) if (!order->IsType(OT_DUMMY)) return true;
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Handle the orders of a vehicle and determine the next place
 
@@ -1351,13 +1389,13 @@ static bool CheckForValidOrders(const Ve
 
 * @param v the vehicle to do this for.
 
 * @return true *if* the vehicle is eligible for reversing
 
 *              (basically only when leaving a station).
 
 */
 
bool ProcessOrders(Vehicle *v)
 
{
 
	switch (v->current_order.type) {
 
	switch (v->current_order.GetType()) {
 
		case OT_GOTO_DEPOT:
 
			/* Let a depot order in the orderlist interrupt. */
 
			if (!(v->current_order.flags & OFB_PART_OF_ORDERS)) return false;
 

	
 
			if ((v->current_order.flags & OFB_SERVICE_IF_NEEDED) && !VehicleNeedsService(v)) {
 
				UpdateVehicleTimetable(v, true);
 
@@ -1379,16 +1417,16 @@ bool ProcessOrders(Vehicle *v)
 
	 * Reversing because of order change is allowed only just after leaving a
 
	 * station (and the difficulty setting to allowed, of course)
 
	 * this can be detected because only after OT_LEAVESTATION, current_order
 
	 * will be reset to nothing. (That also happens if no order, but in that case
 
	 * it won't hit the point in code where may_reverse is checked)
 
	 */
 
	bool may_reverse = v->current_order.type == OT_NOTHING;
 
	bool may_reverse = v->current_order.IsType(OT_NOTHING);
 

	
 
	/* Check if we've reached the waypoint? */
 
	if (v->current_order.type == OT_GOTO_WAYPOINT && v->tile == v->dest_tile) {
 
	if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
 
		UpdateVehicleTimetable(v, true);
 
		v->cur_order_index++;
 
	}
 

	
 
	/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
 
	if (_patches.new_nonstop &&
 
@@ -1403,13 +1441,13 @@ bool ProcessOrders(Vehicle *v)
 
	/* Get the current order */
 
	if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
 

	
 
	const Order *order = GetVehicleOrder(v, v->cur_order_index);
 

	
 
	/* If no order, do nothing. */
 
	if (order == NULL || (v->type == VEH_AIRCRAFT && order->type == OT_DUMMY && !CheckForValidOrders(v))) {
 
	if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) {
 
		if (v->type == VEH_AIRCRAFT) {
 
			/* Aircraft do something vastly different here, so handle separately */
 
			extern void HandleMissingAircraftOrders(Vehicle *v);
 
			HandleMissingAircraftOrders(v);
 
			return false;
 
		}
 
@@ -1419,13 +1457,13 @@ bool ProcessOrders(Vehicle *v)
 
		if (v->type == VEH_ROAD) ClearSlot(v);
 
		return false;
 
	}
 

	
 
	/* If it is unchanged, keep it. */
 
	if (order->Equals(v->current_order) &&
 
			(v->type != VEH_SHIP || order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0)) {
 
			(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->dest)->dock_tile != 0)) {
 
		return false;
 
	}
 

	
 
	/* Otherwise set it, and determine the destination tile. */
 
	v->current_order = *order;
 

	
 
@@ -1441,13 +1479,13 @@ bool ProcessOrders(Vehicle *v)
 
		case VEH_AIRCRAFT:
 
		case VEH_SHIP:
 
			InvalidateWindowClasses(v->GetVehicleListWindowClass());
 
			break;
 
	}
 

	
 
	switch (order->type) {
 
	switch (order->GetType()) {
 
		case OT_GOTO_STATION:
 
			v->dest_tile = v->GetOrderStationLocation(order->dest);
 
			break;
 

	
 
		case OT_GOTO_DEPOT:
 
			if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->dest)->xy;
 
@@ -1487,12 +1525,13 @@ void InitializeOrders()
 
	_Order_pool.CleanPool();
 
	_Order_pool.AddBlockToPool();
 

	
 
	_backup_orders_tile = 0;
 
}
 

	
 
const SaveLoad *GetOrderDescription() {
 
static const SaveLoad _order_desc[] = {
 
	SLE_VAR(Order, type,  SLE_UINT8),
 
	SLE_VAR(Order, flags, SLE_UINT8),
 
	SLE_VAR(Order, dest,  SLE_UINT16),
 
	SLE_REF(Order, next,  REF_ORDER),
 
	SLE_CONDVAR(Order, refit_cargo,    SLE_UINT8,  36, SL_MAX_VERSION),
 
@@ -1502,20 +1541,22 @@ static const SaveLoad _order_desc[] = {
 

	
 
	/* Leftover from the minor savegame version stuff
 
	 * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */
 
	SLE_CONDNULL(10, 5, 35),
 
	SLE_END()
 
};
 
	return _order_desc;
 
}
 

	
 
static void Save_ORDR()
 
{
 
	Order *order;
 

	
 
	FOR_ALL_ORDERS(order) {
 
		SlSetArrayIndex(order->index);
 
		SlObject(order, _order_desc);
 
		SlObject(order, GetOrderDescription());
 
	}
 
}
 

	
 
static void Load_ORDR()
 
{
 
	if (CheckSavegameVersionOldStyle(5, 2)) {
 
@@ -1562,13 +1603,13 @@ static void Load_ORDR()
 
		}
 
	} else {
 
		int index;
 

	
 
		while ((index = SlIterateArray()) != -1) {
 
			Order *order = new (index) Order();
 
			SlObject(order, _order_desc);
 
			SlObject(order, GetOrderDescription());
 
		}
 
	}
 
}
 

	
 
extern const ChunkHandler _order_chunk_handlers[] = {
 
	{ 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST},
src/order_gui.cpp
Show inline comments
 
@@ -150,13 +150,13 @@ static void DrawOrdersWindow(Window *w)
 
		w->DisableWidget(ORDER_WIDGET_TRANSFER);
 
	}
 

	
 
	w->ShowWidget(ORDER_WIDGET_UNLOAD); // Unload
 

	
 
	if (order != NULL) {
 
		switch (order->type) {
 
		switch (order->GetType()) {
 
			case OT_GOTO_STATION:
 
				if (!GetStation(order->dest)->IsBuoy()) break;
 
				/* Fall-through */
 

	
 
			case OT_GOTO_WAYPOINT:
 
				w->DisableWidget(ORDER_WIDGET_FULL_LOAD);
 
@@ -191,13 +191,13 @@ static void DrawOrdersWindow(Window *w)
 
		str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
 
		SetDParam(3, STR_EMPTY);
 

	
 
		if (i - w->vscroll.pos < w->vscroll.cap) {
 
			SetDParam(1, 6);
 

	
 
			switch (order->type) {
 
			switch (order->GetType()) {
 
				case OT_DUMMY:
 
					SetDParam(1, STR_INVALID_ORDER);
 
					SetDParam(2, order->dest);
 
					break;
 

	
 
				case OT_GOTO_STATION:
 
@@ -269,48 +269,40 @@ static Order GetOrderCmdFromTile(const V
 
	// check depot first
 
	if (_patches.gotodepot) {
 
		switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) {
 
				if (IsRailDepot(tile)) {
 
					order.type = OT_GOTO_DEPOT;
 
					order.flags = OFB_PART_OF_ORDERS;
 
					order.dest = GetDepotByTile(tile)->index;
 
					order.MakeGoToDepot(GetDepotByTile(tile)->index, true);
 
					return order;
 
				}
 
			}
 
			break;
 

	
 
		case MP_ROAD:
 
			if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_player)) {
 
				order.type = OT_GOTO_DEPOT;
 
				order.flags = OFB_PART_OF_ORDERS;
 
				order.dest = GetDepotByTile(tile)->index;
 
				order.MakeGoToDepot(GetDepotByTile(tile)->index, true);
 
				return order;
 
			}
 
			break;
 

	
 
		case MP_STATION:
 
			if (v->type != VEH_AIRCRAFT) break;
 
			if (IsHangar(tile) && IsTileOwner(tile, _local_player)) {
 
				order.type = OT_GOTO_DEPOT;
 
				order.flags = OFB_PART_OF_ORDERS;
 
				order.dest = GetStationIndex(tile);
 
				order.MakeGoToDepot(GetStationIndex(tile), true);
 
				return order;
 
			}
 
			break;
 

	
 
		case MP_WATER:
 
			if (v->type != VEH_SHIP) break;
 
			if (IsTileDepotType(tile, TRANSPORT_WATER) &&
 
					IsTileOwner(tile, _local_player)) {
 
				TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
				order.type = OT_GOTO_DEPOT;
 
				order.flags = OFB_PART_OF_ORDERS;
 
				order.dest = GetDepotByTile(tile < tile2 ? tile : tile2)->index;
 
				order.MakeGoToDepot(GetDepotByTile(tile < tile2 ? tile : tile2)->index, true);
 
				return order;
 
			}
 

	
 
			default:
 
				break;
 
		}
 
@@ -318,15 +310,13 @@ static Order GetOrderCmdFromTile(const V
 

	
 
	// check waypoint
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			v->type == VEH_TRAIN &&
 
			IsTileOwner(tile, _local_player) &&
 
			IsRailWaypoint(tile)) {
 
		order.type = OT_GOTO_WAYPOINT;
 
		order.flags = 0;
 
		order.dest = GetWaypointByTile(tile)->index;
 
		order.MakeGoToWaypoint(GetWaypointByTile(tile)->index);
 
		return order;
 
	}
 

	
 
	if (IsTileType(tile, MP_STATION)) {
 
		StationID st_index = GetStationIndex(tile);
 
		const Station *st = GetStation(st_index);
 
@@ -336,15 +326,13 @@ static Order GetOrderCmdFromTile(const V
 
			(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_TRUCK_STOP, 1);
 
			if (st->facilities & facil) {
 
				order.type = OT_GOTO_STATION;
 
				order.flags = 0;
 
				order.dest = st_index;
 
				order.MakeGoToStation(st_index);
 
				return order;
 
			}
 
		}
 
	}
 

	
 
	// not found
 
@@ -573,13 +561,13 @@ static void OrdersWndProc(Window *w, Win
 
			}
 

	
 
			if (_ctrl_pressed && sel < v->num_orders) {
 
				const Order *ord = GetVehicleOrder(v, sel);
 
				TileIndex xy;
 

	
 
				switch (ord->type) {
 
				switch (ord->GetType()) {
 
					case OT_GOTO_STATION:  xy = GetStation(ord->dest)->xy ; break;
 
					case OT_GOTO_DEPOT:    xy = (v->type == VEH_AIRCRAFT) ?  GetStation(ord->dest)->xy : GetDepot(ord->dest)->xy;    break;
 
					case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->dest)->xy; break;
 
					default:               xy = 0; break;
 
				}
 

	
 
@@ -688,13 +676,13 @@ static void OrdersWndProc(Window *w, Win
 

	
 
	case WE_RCLICK: {
 
		const Vehicle *v = GetVehicle(w->window_number);
 
		int s = OrderGetSel(w);
 

	
 
		if (e->we.click.widget != ORDER_WIDGET_FULL_LOAD) break;
 
		if (s == v->num_orders || GetVehicleOrder(v, s)->type != OT_GOTO_DEPOT) {
 
		if (s == v->num_orders || !GetVehicleOrder(v, s)->IsType(OT_GOTO_DEPOT)) {
 
			GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
 
		} else {
 
			GuiShowTooltips(STR_SERVICE_HINT);
 
		}
 
	} break;
 

	
src/roadveh_cmd.cpp
Show inline comments
 
@@ -473,13 +473,13 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	if (v->IsInDepot()) return CMD_ERROR;
 

	
 
	/* If the current orders are already goto-depot */
 
	if (v->current_order.type == OT_GOTO_DEPOT) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot) */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OF_PART_OF_ORDERS);
 
@@ -493,31 +493,27 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 
		if (flags & DC_EXEC) {
 
			/* If the orders to 'goto depot' are in the orders list (forced servicing),
 
			 * then skip to the next order; effectively cancelling this forced service */
 
			if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS))
 
				v->cur_order_index++;
 

	
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return CommandCost();
 
	}
 

	
 
	dep = FindClosestRoadDepot(v);
 
	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
 

	
 
	if (flags & DC_EXEC) {
 
		if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 

	
 
		ClearSlot(v);
 
		v->current_order.type = OT_GOTO_DEPOT;
 
		v->current_order.flags = OFB_NON_STOP;
 
		v->current_order.MakeGoToDepot(dep->index, false);
 
		if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT);
 
		v->current_order.refit_cargo = CT_INVALID;
 
		v->current_order.dest = dep->index;
 
		v->dest_tile = dep->xy;
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -1754,14 +1750,14 @@ again:
 
		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 
		Station* st = GetStationByTile(v->tile);
 

	
 
		/* Vehicle is at the stop position (at a bay) in a road stop.
 
		 * Note, if vehicle is loading/unloading it has already been handled,
 
		 * so if we get here the vehicle has just arrived or is just ready to leave. */
 
		if (v->current_order.type != OT_LEAVESTATION &&
 
				v->current_order.type != OT_GOTO_DEPOT) {
 
		if (!v->current_order.IsType(OT_LEAVESTATION) &&
 
				!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			/* Vehicle has arrived at a bay in a road stop */
 

	
 
			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;
 

	
 
@@ -1792,13 +1788,13 @@ again:
 
			v->BeginLoading();
 

	
 
			return false;
 
		}
 

	
 
		/* Vehicle is ready to leave a bay in a road stop */
 
		if (v->current_order.type != OT_GOTO_DEPOT) {
 
		if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			if (rs->IsEntranceBusy()) {
 
				/* Road stop entrance is busy, so wait as there is nowhere else to go */
 
				v->cur_speed = 0;
 
				return false;
 
			}
 
			v->current_order.Free();
 
@@ -1818,14 +1814,14 @@ again:
 
			if (v->tile != v->dest_tile) {
 
				DEBUG(ms, 2, " current tile 0x%X is not destination tile 0x%X. Route problem", v->tile, v->dest_tile);
 
			}
 
			if (v->dest_tile != v->u.road.slot->xy) {
 
				DEBUG(ms, 2, " stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile);
 
			}
 
			if (v->current_order.type != OT_GOTO_STATION) {
 
				DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.type);
 
			if (!v->current_order.IsType(OT_GOTO_STATION)) {
 
				DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.GetType());
 
			} else {
 
				if (v->current_order.dest != st->index)
 
					DEBUG(ms, 2, " current station %d is not target station in current_order.station (%d)",
 
							st->index, v->current_order.dest);
 
			}
 

	
 
@@ -1881,13 +1877,13 @@ static void RoadVehController(Vehicle *v
 

	
 
	if (v->vehstatus & VS_STOPPED) return;
 

	
 
	ProcessOrders(v);
 
	v->HandleLoading();
 

	
 
	if (v->current_order.type == OT_LOADING) return;
 
	if (v->current_order.IsType(OT_LOADING)) return;
 

	
 
	if (v->IsInDepot() && RoadVehLeaveDepot(v, true)) return;
 

	
 
	/* Check if vehicle needs to proceed, return if it doesn't */
 
	if (!RoadVehAccelerate(v)) return;
 

	
 
@@ -1922,32 +1918,29 @@ static void CheckIfRoadVehNeedsService(V
 
	}
 

	
 
	/* XXX If we already have a depot order, WHY do we search over and over? */
 
	const Depot *depot = FindClosestRoadDepot(v);
 

	
 
	if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
 
		if (v->current_order.type == OT_GOTO_DEPOT) {
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
		if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return;
 
	}
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT &&
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) &&
 
			v->current_order.flags & OFB_NON_STOP &&
 
			!Chance16(1, 20)) {
 
		return;
 
	}
 

	
 
	if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
	if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 
	ClearSlot(v);
 

	
 
	v->current_order.type = OT_GOTO_DEPOT;
 
	v->current_order.flags = OFB_NON_STOP;
 
	v->current_order.dest = depot->index;
 
	v->current_order.MakeGoToDepot(depot->index, false);
 
	v->dest_tile = depot->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void RoadVehicle::OnNewDay()
 
{
 
@@ -1959,20 +1952,20 @@ void RoadVehicle::OnNewDay()
 
	AgeVehicle(this);
 
	CheckIfRoadVehNeedsService(this);
 

	
 
	CheckOrders(this);
 

	
 
	/* Current slot has expired */
 
	if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
 
	if (this->current_order.IsType(OT_GOTO_STATION) && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
 
		DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X",
 
			this->unitnumber, this->index, this->u.road.slot->xy);
 
		ClearSlot(this);
 
	}
 

	
 
	/* update destination */
 
	if (!(this->vehstatus & VS_STOPPED) && this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
 
	if (!(this->vehstatus & VS_STOPPED) && this->current_order.IsType(OT_GOTO_STATION) && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
 
		Station *st = GetStation(this->current_order.dest);
 
		RoadStop *rs = st->GetPrimaryRoadStop(this);
 
		RoadStop *best = NULL;
 

	
 
		if (rs != NULL) {
 
			/* We try to obtain a slot if:
src/ship_cmd.cpp
Show inline comments
 
@@ -150,23 +150,20 @@ static void CheckIfShipNeedsService(Vehi
 
		return;
 
	}
 

	
 
	const Depot *depot = FindClosestShipDepot(v);
 

	
 
	if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
 
		if (v->current_order.type == OT_GOTO_DEPOT) {
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
		if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return;
 
	}
 

	
 
	v->current_order.type = OT_GOTO_DEPOT;
 
	v->current_order.flags = OFB_NON_STOP;
 
	v->current_order.dest = depot->index;
 
	v->current_order.MakeGoToDepot(depot->index, false);
 
	v->dest_tile = depot->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void Ship::OnNewDay()
 
{
 
@@ -601,13 +598,13 @@ static void ShipController(Vehicle *v)
 

	
 
	if (v->vehstatus & VS_STOPPED) return;
 

	
 
	ProcessOrders(v);
 
	v->HandleLoading();
 

	
 
	if (v->current_order.type == OT_LOADING) return;
 
	if (v->current_order.IsType(OT_LOADING)) return;
 

	
 
	CheckShipLeaveDepot(v);
 

	
 
	if (!ShipAccelerate(v)) return;
 

	
 
	BeginVehicleMove(v);
 
@@ -622,46 +619,44 @@ static void ShipController(Vehicle *v)
 
			/* Not inside depot */
 
			r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
			if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
 

	
 
			/* A leave station order only needs one tick to get processed, so we can
 
			 * always skip ahead. */
 
			if (v->current_order.type == OT_LEAVESTATION) {
 
			if (v->current_order.IsType(OT_LEAVESTATION)) {
 
				v->current_order.Free();
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
			} else if (v->dest_tile != 0) {
 
				/* We have a target, let's see if we reached it... */
 
				if (v->current_order.type == OT_GOTO_STATION &&
 
				if (v->current_order.IsType(OT_GOTO_STATION) &&
 
						IsBuoyTile(v->dest_tile) &&
 
						DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
 
					/* We got within 3 tiles of our target buoy, so let's skip to our
 
					 * next order */
 
					UpdateVehicleTimetable(v, true);
 
					v->cur_order_index++;
 
					v->current_order.type = OT_DUMMY;
 
					v->current_order.MakeDummy();
 
					InvalidateVehicleOrder(v);
 
				} else {
 
					/* Non-buoy orders really need to reach the tile */
 
					if (v->dest_tile == gp.new_tile) {
 
						if (v->current_order.type == OT_GOTO_DEPOT) {
 
						if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
							if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
 
								VehicleEnterDepot(v);
 
								return;
 
							}
 
						} else if (v->current_order.type == OT_GOTO_STATION) {
 
							Station *st;
 

	
 
						} else if (v->current_order.IsType(OT_GOTO_STATION)) {
 
							v->last_station_visited = v->current_order.dest;
 

	
 
							/* Process station in the orderlist. */
 
							st = GetStation(v->current_order.dest);
 
							Station *st = GetStation(v->current_order.dest);
 
							if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
 
								ShipArrivesAt(v, st);
 
								v->BeginLoading();
 
							} else { // leave stations without docks right aways
 
								v->current_order.type = OT_LEAVESTATION;
 
								v->current_order.MakeLeaveStation();
 
								v->cur_order_index++;
 
								InvalidateVehicleOrder(v);
 
							}
 
						}
 
					}
 
				}
 
@@ -944,13 +939,13 @@ CommandCost CmdSendShipToDepot(TileIndex
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	if (v->IsInDepot()) return CMD_ERROR;
 

	
 
	/* If the current orders are already goto-depot */
 
	if (v->current_order.type == OT_GOTO_DEPOT) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OF_PART_OF_ORDERS);
 
@@ -964,31 +959,27 @@ CommandCost CmdSendShipToDepot(TileIndex
 
		if (flags & DC_EXEC) {
 
			/* If the orders to 'goto depot' are in the orders list (forced servicing),
 
			 * then skip to the next order; effectively cancelling this forced service */
 
			if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS))
 
				v->cur_order_index++;
 

	
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return CommandCost();
 
	}
 

	
 
	dep = FindClosestShipDepot(v);
 
	if (dep == NULL) return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT);
 

	
 
	if (flags & DC_EXEC) {
 
		if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 

	
 
		v->dest_tile = dep->xy;
 
		v->current_order.type = OT_GOTO_DEPOT;
 
		v->current_order.flags = OFB_NON_STOP;
 
		v->current_order.MakeGoToDepot(dep->index, false);
 
		if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT);
 
		v->current_order.refit_cargo = CT_INVALID;
 
		v->current_order.dest = dep->index;
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1895,13 +1895,13 @@ bool HasStationInUse(StationID station, 
 
{
 
	const Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (player == INVALID_PLAYER || v->owner == player) {
 
			const Order *order;
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->type == OT_GOTO_STATION && order->dest == station) {
 
				if (order->IsType(OT_GOTO_STATION) && order->dest == station) {
 
					return true;
 
				}
 
			}
 
		}
 
	}
 
	return false;
src/timetable_cmd.cpp
Show inline comments
 
@@ -66,13 +66,13 @@ CommandCost CmdChangeTimetable(TileIndex
 
	Order *order = GetVehicleOrder(v, order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	bool packed_time = HasBit(p1, 25);
 
	bool is_journey = HasBit(p1, 24) || packed_time;
 
	if (!is_journey) {
 
		if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
 
		if (!order->IsType(OT_GOTO_STATION)) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
 
		if (_patches.new_nonstop && (order->flags & OFB_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		ChangeTimetable(v, order_number, GB(p2, 0, 16), is_journey);
 
		if (packed_time) ChangeTimetable(v, order_number, GB(p2, 16, 16), false);
src/timetable_gui.cpp
Show inline comments
 
@@ -76,13 +76,13 @@ static void DrawTimetableWindow(Window *
 
			w->DisableWidget(TTV_CLEAR_TIME);
 
		} else if (selected % 2 == 1) {
 
			w->EnableWidget(TTV_CHANGE_TIME);
 
			w->EnableWidget(TTV_CLEAR_TIME);
 
		} else {
 
			const Order *order = GetVehicleOrder(v, (selected + 1) / 2);
 
			bool disable = order == NULL || order->type != OT_GOTO_STATION || (_patches.new_nonstop && (order->flags & OFB_NON_STOP));
 
			bool disable = order == NULL || !order->IsType(OT_GOTO_STATION) || (_patches.new_nonstop && (order->flags & OFB_NON_STOP));
 

	
 
			w->SetWidgetDisabledState(TTV_CHANGE_TIME, disable);
 
			w->SetWidgetDisabledState(TTV_CLEAR_TIME, disable);
 
		}
 

	
 
		w->EnableWidget(TTV_RESET_LATENESS);
 
@@ -110,13 +110,13 @@ static void DrawTimetableWindow(Window *
 
		/* Don't draw anything if it extends past the end of the window. */
 
		if (i - w->vscroll.pos >= w->vscroll.cap) break;
 

	
 
		if (i % 2 == 0) {
 
			SetDParam(2, STR_EMPTY);
 

	
 
			switch (order->type) {
 
			switch (order->GetType()) {
 
				case OT_DUMMY:
 
					SetDParam(0, STR_INVALID_ORDER);
 
					break;
 

	
 
				case OT_GOTO_STATION:
 
					SetDParam(0, (order->flags & OFB_NON_STOP) ? STR_880A_GO_NON_STOP_TO : STR_8806_GO_TO);
 
@@ -194,13 +194,13 @@ static void DrawTimetableWindow(Window *
 
		uint total_time = 0;
 
		bool complete = true;
 

	
 
		for (const Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
 
			total_time += order->travel_time + order->wait_time;
 
			if (order->travel_time == 0) complete = false;
 
			if (order->wait_time == 0 && order->type == OT_GOTO_STATION && !(_patches.new_nonstop && (order->flags & OFB_NON_STOP))) complete = false;
 
			if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(_patches.new_nonstop && (order->flags & OFB_NON_STOP))) complete = false;
 
		}
 

	
 
		if (total_time != 0) {
 
			SetTimetableParams(0, 1, total_time);
 
			DrawString(2, y, complete ? STR_TIMETABLE_TOTAL_TIME : STR_TIMETABLE_TOTAL_TIME_INCOMPLETE, TC_BLACK);
 
		}
src/train_cmd.cpp
Show inline comments
 
@@ -2104,13 +2104,13 @@ CommandCost CmdSendTrainToDepot(TileInde
 
	Vehicle *v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OF_PART_OF_ORDERS);
 
@@ -2123,14 +2123,13 @@ CommandCost CmdSendTrainToDepot(TileInde
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
 
		if (flags & DC_EXEC) {
 
			if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS)) {
 
				v->cur_order_index++;
 
			}
 

	
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return CommandCost();
 
	}
 

	
 
	/* check if at a standstill (not stopped only) in a depot
 
@@ -2138,20 +2137,17 @@ CommandCost CmdSendTrainToDepot(TileInde
 
	if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && v->cur_speed == 0) return CMD_ERROR;
 

	
 
	TrainFindDepotData tfdd = FindClosestTrainDepot(v, 0);
 
	if (tfdd.best_length == (uint)-1) return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO);
 

	
 
	if (flags & DC_EXEC) {
 
		if (v->current_order.type == OT_LOADING) v->LeaveStation();
 
		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
 

	
 
		v->dest_tile = tfdd.tile;
 
		v->current_order.type = OT_GOTO_DEPOT;
 
		v->current_order.flags = OFB_NON_STOP;
 
		v->current_order.MakeGoToDepot(GetDepotByTile(tfdd.tile)->index, false);
 
		if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT);
 
		v->current_order.dest = GetDepotByTile(tfdd.tile)->index;
 
		v->current_order.refit_cargo = CT_INVALID;
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		/* If there is no depot in front, reverse automatically */
 
		if (tfdd.reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 
	}
 

	
 
	return CommandCost();
 
@@ -2343,17 +2339,13 @@ static bool NtpCallbFindStation(TileInde
 
	}
 
}
 

	
 
static void FillWithStationData(TrainTrackFollowerData* fd, const Vehicle* v)
 
{
 
	fd->dest_coords = v->dest_tile;
 
	if (v->current_order.type == OT_GOTO_STATION) {
 
		fd->station_index = v->current_order.dest;
 
	} else {
 
		fd->station_index = INVALID_STATION;
 
	}
 
	fd->station_index = v->current_order.IsType(OT_GOTO_STATION) ? v->current_order.dest : INVALID_STATION;
 
}
 

	
 
static const byte _initial_tile_subcoord[6][4][3] = {
 
{{ 15, 8, 1 }, { 0, 0, 0 }, { 0, 8, 5 }, { 0,  0, 0 }},
 
{{  0, 0, 0 }, { 8, 0, 3 }, { 0, 0, 0 }, { 8, 15, 7 }},
 
{{  0, 0, 0 }, { 7, 0, 2 }, { 0, 7, 6 }, { 0,  0, 0 }},
 
@@ -2955,13 +2947,13 @@ static void TrainController(Vehicle *v, 
 
					}
 
					if (HasBit(r, VETS_ENTERED_STATION)) {
 
						TrainEnterStation(v, r >> VETS_STATION_ID_OFFSET);
 
						return;
 
					}
 

	
 
					if (v->current_order.type == OT_LEAVESTATION) {
 
					if (v->current_order.IsType(OT_LEAVESTATION)) {
 
						v->current_order.Free();
 
						InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
					}
 
				}
 
			} else {
 
				/* A new tile is about to be entered. */
 
@@ -3467,13 +3459,13 @@ static void TrainLocoHandler(Vehicle *v,
 
		ReverseTrainDirection(v);
 
		return;
 
	}
 

	
 
	v->HandleLoading(mode);
 

	
 
	if (v->current_order.type == OT_LOADING) return;
 
	if (v->current_order.IsType(OT_LOADING)) return;
 

	
 
	if (CheckTrainStayInDepot(v)) return;
 

	
 
	if (!mode) HandleLocomotiveSmokeCloud(v);
 

	
 
	int j = UpdateTrainSpeed(v);
 
@@ -3551,34 +3543,31 @@ static void CheckIfTrainNeedsService(Veh
 
		return;
 
	}
 

	
 
	TrainFindDepotData tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST);
 
	/* Only go to the depot if it is not too far out of our way. */
 
	if (tfdd.best_length == (uint)-1 || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {
 
		if (v->current_order.type == OT_GOTO_DEPOT) {
 
		if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
			/* If we were already heading for a depot but it has
 
			 * suddenly moved farther away, we continue our normal
 
			 * schedule? */
 
			v->current_order.type = OT_DUMMY;
 
			v->current_order.flags = 0;
 
			v->current_order.MakeDummy();
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		}
 
		return;
 
	}
 

	
 
	const Depot* depot = GetDepotByTile(tfdd.tile);
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT &&
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) &&
 
			v->current_order.dest != depot->index &&
 
			!Chance16(3, 16)) {
 
		return;
 
	}
 

	
 
	v->current_order.type = OT_GOTO_DEPOT;
 
	v->current_order.flags = OFB_NON_STOP;
 
	v->current_order.dest = depot->index;
 
	v->current_order.MakeGoToDepot(depot->index, false);
 
	v->dest_tile = tfdd.tile;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void Train::OnNewDay()
 
{
 
@@ -3590,13 +3579,13 @@ void Train::OnNewDay()
 

	
 
		CheckIfTrainNeedsService(this);
 

	
 
		CheckOrders(this);
 

	
 
		/* update destination */
 
		if (this->current_order.type == OT_GOTO_STATION) {
 
		if (this->current_order.IsType(OT_GOTO_STATION)) {
 
			TileIndex tile = GetStation(this->current_order.dest)->train_tile;
 
			if (tile != 0) this->dest_tile = tile;
 
		}
 

	
 
		if (this->running_ticks != 0) {
 
			/* running costs */
src/vehicle.cpp
Show inline comments
 
@@ -117,16 +117,16 @@ void VehicleServiceInDepot(Vehicle *v)
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
 
}
 

	
 
bool VehicleNeedsService(const Vehicle *v)
 
{
 
	if (v->vehstatus & (VS_STOPPED | VS_CRASHED))       return false;
 
	if (v->current_order.type != OT_GOTO_DEPOT || !(v->current_order.flags & OFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list
 
	if (!v->current_order.IsType(OT_GOTO_DEPOT) || !(v->current_order.flags & OFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list
 
		if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false;
 
		if (v->current_order.type == OT_LOADING)            return false;
 
		if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OFB_HALT_IN_DEPOT) return false;
 
		if (v->current_order.IsType(OT_LOADING))            return false;
 
		if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.flags & OFB_HALT_IN_DEPOT) return false;
 
	}
 

	
 
	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
 
		return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id);  /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */
 
	}
 

	
 
@@ -628,13 +628,13 @@ static Vehicle* _first_veh_in_depot_list
 
 * @param *v vehicle to add
 
 */
 
void VehicleEnteredDepotThisTick(Vehicle *v)
 
{
 
	/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time.
 
	 * Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */
 
	if ((HasBit(v->current_order.flags, OF_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OF_PART_OF_ORDERS) && v->current_order.type == OT_GOTO_DEPOT) ||
 
	if ((HasBit(v->current_order.flags, OF_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OF_PART_OF_ORDERS) && v->current_order.IsType(OT_GOTO_DEPOT)) ||
 
			(v->vehstatus & VS_STOPPED)) {
 
		/* we keep the vehicle in the depot since the user ordered it to stay */
 
		v->leave_depot_instantly = false;
 
	} else {
 
		/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path
 
		 * out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path
 
@@ -2030,13 +2030,13 @@ uint GenerateVehicleSortList(const Vehic
 
		case VLW_STATION_LIST: {
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type == type && v->IsPrimaryVehicle()) {
 
					const Order *order;
 

	
 
					FOR_VEHICLE_ORDERS(v, order) {
 
						if (order->type == OT_GOTO_STATION && order->dest == index) {
 
						if (order->IsType(OT_GOTO_STATION) && order->dest == index) {
 
							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
 
							(*sort_list)[n++] = v;
 
							break;
 
						}
 
					}
 
				}
 
@@ -2074,13 +2074,13 @@ uint GenerateVehicleSortList(const Vehic
 
		case VLW_DEPOT_LIST: {
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type == type && v->IsPrimaryVehicle()) {
 
					const Order *order;
 

	
 
					FOR_VEHICLE_ORDERS(v, order) {
 
						if (order->type == OT_GOTO_DEPOT && order->dest == index) {
 
						if (order->IsType(OT_GOTO_DEPOT) && order->dest == index) {
 
							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
 
							(*sort_list)[n++] = v;
 
							break;
 
						}
 
					}
 
				}
 
@@ -2232,20 +2232,19 @@ void VehicleEnterDepot(Vehicle *v)
 
	v->cur_speed = 0;
 

	
 
	VehicleServiceInDepot(v);
 

	
 
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT) {
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		Order t;
 

	
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 

	
 
		t = v->current_order;
 
		v->current_order.type = OT_DUMMY;
 
		v->current_order.flags = 0;
 
		v->current_order.MakeDummy();
 

	
 
		if (t.refit_cargo < NUM_CARGO) {
 
			CommandCost cost;
 

	
 
			_current_player = v->owner;
 
			cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v));
 
@@ -3051,13 +3050,13 @@ static void Save_VEHS()
 
		SlSetArrayIndex(v->index);
 
		SlObject(v, GetVehicleDescription(v->type));
 
	}
 
}
 

	
 
/** Will be called when vehicles need to be loaded. */
 
static void Load_VEHS()
 
void Load_VEHS()
 
{
 
	int index;
 
	Vehicle *v;
 

	
 
	_cargo_count = 0;
 

	
 
@@ -3094,13 +3093,13 @@ static void Load_VEHS()
 
		if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF)
 
			v->last_station_visited = INVALID_STATION;
 

	
 
		if (CheckSavegameVersion(5)) {
 
			/* Convert the current_order.type (which is a mix of type and flags, because
 
			 *  in those versions, they both were 4 bits big) to type and flags */
 
			v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
 
			v->current_order.flags = GB(v->current_order.type, 4, 4);
 
			v->current_order.type.m_val &= 0x0F;
 
		}
 

	
 
		/* Advanced vehicle lists got added */
 
		if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP;
 
	}
 
@@ -3128,13 +3127,13 @@ extern const ChunkHandler _veh_chunk_han
 
};
 

	
 
void Vehicle::BeginLoading()
 
{
 
	assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP);
 

	
 
	if (this->current_order.type == OT_GOTO_STATION &&
 
	if (this->current_order.IsType(OT_GOTO_STATION) &&
 
			this->current_order.dest == this->last_station_visited) {
 
		/* Arriving at the ordered station.
 
		 * Keep the load/unload flags, as we (obviously) still need them. */
 
		this->current_order.flags &= OFB_FULL_LOAD | OFB_UNLOAD | OFB_TRANSFER;
 

	
 
		/* Furthermore add the Non Stop flag to mark that this station
 
@@ -3146,13 +3145,13 @@ void Vehicle::BeginLoading()
 
		UpdateVehicleTimetable(this, true);
 
	} else {
 
		/* This is just an unordered intermediate stop */
 
		this->current_order.flags = 0;
 
	}
 

	
 
	current_order.type = OT_LOADING;
 
	current_order.MakeLoading();
 
	GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
 

	
 
	VehiclePayment(this);
 

	
 
	InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
 
@@ -3167,24 +3166,23 @@ void Vehicle::LeaveStation()
 
{
 
	assert(current_order.type == OT_LOADING);
 

	
 
	/* Only update the timetable if the vehicle was supposed to stop here. */
 
	if (current_order.flags & OFB_NON_STOP) UpdateVehicleTimetable(this, false);
 

	
 
	current_order.type = OT_LEAVESTATION;
 
	current_order.flags = 0;
 
	current_order.MakeLeaveStation();
 
	GetStation(this->last_station_visited)->loading_vehicles.remove(this);
 

	
 
	HideFillingPercent(this->fill_percent_te_id);
 
	this->fill_percent_te_id = INVALID_TE_ID;
 
}
 

	
 

	
 
void Vehicle::HandleLoading(bool mode)
 
{
 
	switch (this->current_order.type) {
 
	switch (this->current_order.GetType()) {
 
		case OT_LOADING: {
 
			uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0);
 

	
 
			/* Not the first call for this tick, or still loading */
 
			if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) ||
 
					(_patches.timetabling && this->current_order_time < wait_time)) return;
src/vehicle_gui.cpp
Show inline comments
 
@@ -914,13 +914,13 @@ void DrawSmallOrderList(const Vehicle *v
 
	sel = v->cur_order_index;
 

	
 
	FOR_VEHICLE_ORDERS(v, order) {
 
		if (sel == 0) DrawString(x - 6, y, STR_SMALL_RIGHT_ARROW, TC_BLACK);
 
		sel--;
 

	
 
		if (order->type == OT_GOTO_STATION) {
 
		if (order->IsType(OT_GOTO_STATION)) {
 
			if (v->type == VEH_SHIP && GetStation(order->dest)->IsBuoy()) continue;
 

	
 
			SetDParam(0, order->dest);
 
			DrawString(x, y, STR_A036, TC_FROMSTRING);
 

	
 
			y += 6;
 
@@ -1949,13 +1949,13 @@ static void DrawVehicleViewWindow(Window
 
				str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
 
			}
 
		} else { // no train
 
			str = STR_8861_STOPPED;
 
		}
 
	} else { // vehicle is in a "normal" state, show current order
 
		switch (v->current_order.type) {
 
		switch (v->current_order.GetType()) {
 
			case OT_GOTO_STATION: {
 
				SetDParam(0, v->current_order.dest);
 
				SetDParam(1, v->GetDisplaySpeed());
 
				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
 
			} break;
 

	
src/waypoint.cpp
Show inline comments
 
@@ -233,13 +233,13 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
		/* First we update the destination for all vehicles that
 
		 * have the old waypoint in their orders. */
 
		Vehicle *v;
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type == VEH_TRAIN &&
 
					v->First() == v &&
 
					v->current_order.type == OT_GOTO_WAYPOINT &&
 
					v->current_order.IsType(OT_GOTO_WAYPOINT) &&
 
					v->dest_tile == wp->xy) {
 
				v->dest_tile = tile;
 
			}
 
		}
 

	
 
		RedrawWaypointSign(wp);
src/yapf/yapf_destrail.hpp
Show inline comments
 
@@ -83,13 +83,13 @@ protected:
 
		return TileXY(x, y);
 
	}
 

	
 
public:
 
	void SetDestination(Vehicle* v)
 
	{
 
		switch (v->current_order.type) {
 
		switch (v->current_order.GetType()) {
 
			case OT_GOTO_STATION:
 
				m_destTile = CalcStationCenterTile(v->current_order.dest);
 
				m_dest_station_id = v->current_order.dest;
 
				m_destTrackdirs = INVALID_TRACKDIR_BIT;
 
				break;
 

	
src/yapf/yapf_road.cpp
Show inline comments
 
@@ -81,13 +81,13 @@ public:
 
		while (true) {
 
			// base tile cost depending on distance between edges
 
			segment_cost += Yapf().OneTileCost(tile, trackdir);
 

	
 
			const Vehicle* v = Yapf().GetVehicle();
 
			// we have reached the vehicle's destination - segment should end here to avoid target skipping
 
			if (v->current_order.type == OT_GOTO_STATION && tile == v->dest_tile) break;
 
			if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break;
 

	
 
			// stop if we have just entered the depot
 
			if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
 
				// next time we will reverse and leave the depot
 
				break;
 
			}
0 comments (0 inline, 0 general)