src/vehicle.cpp
changeset 8891 1058c3b69b7f
parent 8881 ad608e8305ad
child 8892 8401e1338665
equal deleted inserted replaced
8890:8a0fa7ff70a0 8891:1058c3b69b7f
  3207 
  3207 
  3208 	this->cur_order_index++;
  3208 	this->cur_order_index++;
  3209 	InvalidateVehicleOrder(this);
  3209 	InvalidateVehicleOrder(this);
  3210 }
  3210 }
  3211 
  3211 
       
  3212 CommandCost Vehicle::SendToDepot(uint32 flags, DepotCommand command)
       
  3213 {
       
  3214 	if (!CheckOwnership(this->owner)) return CMD_ERROR;
       
  3215 	if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
       
  3216 	if (this->IsInDepot()) return CMD_ERROR;
       
  3217 
       
  3218 	if (this->current_order.IsType(OT_GOTO_DEPOT)) {
       
  3219 		bool halt_in_depot = this->current_order.GetDepotActionType() & ODATFB_HALT;
       
  3220 		if (!!(command & DEPOT_SERVICE) == halt_in_depot) {
       
  3221 			/* We called with a different DEPOT_SERVICE setting.
       
  3222 			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
       
  3223 			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
       
  3224 			if (flags & DC_EXEC) {
       
  3225 				this->current_order.SetDepotOrderType(ODTF_MANUAL);
       
  3226 				this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT);
       
  3227 				InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
       
  3228 			}
       
  3229 			return CommandCost();
       
  3230 		}
       
  3231 
       
  3232 		if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
       
  3233 		if (flags & DC_EXEC) {
       
  3234 			/* If the orders to 'goto depot' are in the orders list (forced servicing),
       
  3235 			 * then skip to the next order; effectively cancelling this forced service */
       
  3236 			if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->cur_order_index++;
       
  3237 
       
  3238 			this->current_order.MakeDummy();
       
  3239 			InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
       
  3240 		}
       
  3241 		return CommandCost();
       
  3242 	}
       
  3243 
       
  3244 	/* check if at a standstill (not stopped only) in a depot
       
  3245 	 * the check is down here to make it possible to alter stop/service for trains entering the depot */
       
  3246 	if (this->type == VEH_TRAIN && IsTileDepotType(this->tile, TRANSPORT_RAIL) && this->cur_speed == 0) return CMD_ERROR;
       
  3247 
       
  3248 	TileIndex location;
       
  3249 	DestinationID destination;
       
  3250 	bool reverse;
       
  3251 	static const StringID no_depot[] = {STR_883A_UNABLE_TO_FIND_ROUTE_TO, STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT, STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO};
       
  3252 	if (!this->FindClosestDepot	(&location, &destination, &reverse)) return_cmd_error(no_depot[this->type]);
       
  3253 
       
  3254 	if (flags & DC_EXEC) {
       
  3255 		if (this->current_order.IsType(OT_LOADING)) this->LeaveStation();
       
  3256 
       
  3257 		this->dest_tile = location;
       
  3258 		this->current_order.MakeGoToDepot(destination, ODTF_MANUAL);
       
  3259 		if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT);
       
  3260 		InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
       
  3261 
       
  3262 		/* If there is no depot in front, reverse automatically (trains only) */
       
  3263 		if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
       
  3264 
       
  3265 		if (this->type == VEH_AIRCRAFT && this->u.air.state == FLYING && this->u.air.targetairport != destination) {
       
  3266 				/* The aircraft is now heading for a different hangar than the next in the orders */
       
  3267 				extern void AircraftNextAirportPos_and_Order(Vehicle *v);
       
  3268 				AircraftNextAirportPos_and_Order(this);
       
  3269 			}
       
  3270 
       
  3271 	}
       
  3272 
       
  3273 	return CommandCost();
       
  3274 
       
  3275 }
       
  3276 
  3212 void Vehicle::SetNext(Vehicle *next)
  3277 void Vehicle::SetNext(Vehicle *next)
  3213 {
  3278 {
  3214 	if (this->next != NULL) {
  3279 	if (this->next != NULL) {
  3215 		/* We had an old next vehicle. Update the first and previous pointers */
  3280 		/* We had an old next vehicle. Update the first and previous pointers */
  3216 		for (Vehicle *v = this->next; v != NULL; v = v->Next()) {
  3281 		for (Vehicle *v = this->next; v != NULL; v = v->Next()) {