File diff r8839:479975d442dd → r8840:f5c2213cf909
src/station_cmd.cpp
Show inline comments
 
@@ -1877,49 +1877,49 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
		UpdateStationAcceptance(st, false);
 
		RebuildStationLists();
 
		InvalidateWindow(WC_STATION_LIST, st->owner);
 
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
 
		/* success, so don't delete the new station */
 
		st_auto_delete.Detach();
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
 
}
 

	
 
/**
 
 * Tests whether the player's vehicles have this station in orders
 
 * When player == INVALID_PLAYER, then check all vehicles
 
 * @param station station ID
 
 * @param player player ID, INVALID_PLAYER to disable the check
 
 */
 
bool HasStationInUse(StationID station, PlayerID player)
 
{
 
	const Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (player == INVALID_PLAYER || v->owner == player) {
 
			const Order *order;
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->IsType(OT_GOTO_STATION) && order->dest == station) {
 
				if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station) {
 
					return true;
 
				}
 
			}
 
		}
 
	}
 
	return false;
 
}
 

	
 
static CommandCost RemoveBuoy(Station *st, uint32 flags)
 
{
 
	/* XXX: strange stuff */
 
	if (!IsValidPlayer(_current_player))  return_cmd_error(INVALID_STRING_ID);
 

	
 
	TileIndex tile = st->dock_tile;
 

	
 
	if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE);
 
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
 
	if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		st->dock_tile = 0;
 
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
 
		 * braindead.. */
 
		st->facilities &= ~FACIL_DOCK;
 
@@ -2416,49 +2416,49 @@ static VehicleEnterTileStatus VehicleEnt
 
				if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */
 
				if (x < 12) {
 
					uint16 spd;
 

	
 
					v->vehstatus |= VS_TRAIN_SLOWING;
 
					spd = _enter_station_speedtable[x];
 
					if (spd < v->cur_speed) v->cur_speed = spd;
 
				}
 
			}
 
		}
 
	} else if (v->type == VEH_ROAD) {
 
		if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) {
 
			if (IsRoadStop(tile) && IsRoadVehFront(v)) {
 
				/* Attempt to allocate a parking bay in a road stop */
 
				RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
 

	
 
				if (IsDriveThroughStopTile(tile)) {
 
					/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */
 
					byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1;
 

	
 
					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
 

	
 
					/* Check if the vehicle is stopping at this road stop */
 
					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 
							v->current_order.dest == GetStationIndex(tile)) {
 
							v->current_order.GetDestination() == GetStationIndex(tile)) {
 
						SetBit(v->u.road.state, RVS_IS_STOPPING);
 
						rs->AllocateDriveThroughBay(side);
 
					}
 

	
 
					/* Indicate if vehicle is using second bay. */
 
					if (side == 1) SetBit(v->u.road.state, RVS_USING_SECOND_BAY);
 
					/* Indicate a drive-through stop */
 
					SetBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
 
					return VETSB_CONTINUE;
 
				}
 

	
 
				/* For normal (non drive-through) road stops */
 
				/* Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */
 
				if (rs->IsEntranceBusy() || !rs->HasFreeBay() || RoadVehHasArticPart(v)) return VETSB_CANNOT_ENTER;
 

	
 
				SetBit(v->u.road.state, RVS_IN_ROAD_STOP);
 

	
 
				/* Allocate a bay and update the road state */
 
				uint bay_nr = rs->AllocateBay();
 
				SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr);
 

	
 
				/* Mark the station entrace as busy */
 
				rs->SetEntranceBusy(true);
 
			}