src/order_cmd.cpp
branchnoai
changeset 11126 72d4c9314c72
parent 11044 097ea3e7ec56
equal deleted inserted replaced
11111:1b984dab8cec 11126:72d4c9314c72
   296 		case OT_GOTO_STATION: return GetStation(o.GetDestination())->xy;
   296 		case OT_GOTO_STATION: return GetStation(o.GetDestination())->xy;
   297 		case OT_GOTO_DEPOT:   return GetDepot(o.GetDestination())->xy;
   297 		case OT_GOTO_DEPOT:   return GetDepot(o.GetDestination())->xy;
   298 	}
   298 	}
   299 }
   299 }
   300 
   300 
       
   301 static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0)
       
   302 {
       
   303 	if (cur->IsType(OT_CONDITIONAL)) {
       
   304 		if (conditional_depth > v->num_orders) return 0;
       
   305 
       
   306 		conditional_depth++;
       
   307 		return max(GetOrderDistance(prev, &v->orders[cur->GetConditionSkipToOrder()], v, conditional_depth),
       
   308 				GetOrderDistance(prev, (prev + 1 == &v->orders[v->num_orders]) ? v->orders : (prev + 1), v, conditional_depth));
       
   309 	}
       
   310 
       
   311 	return DistanceManhattan(GetOrderLocation(*prev), GetOrderLocation(*cur));
       
   312 }
   301 
   313 
   302 /** Add an order to the orderlist of a vehicle.
   314 /** Add an order to the orderlist of a vehicle.
   303  * @param tile unused
   315  * @param tile unused
   304  * @param flags operation to perform
   316  * @param flags operation to perform
   305  * @param p1 various bitstuffed elements
   317  * @param p1 various bitstuffed elements
   417 			} else {
   429 			} else {
   418 				if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR;
   430 				if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR;
   419 			}
   431 			}
   420 
   432 
   421 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
   433 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
   422 			if (new_order.GetDepotOrderType() & ~ODTFB_PART_OF_ORDERS) return CMD_ERROR;
   434 			if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
   423 			if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR;
   435 			if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR;
   424 			break;
   436 			break;
   425 		}
   437 		}
   426 
   438 
   427 		case OT_GOTO_WAYPOINT: {
   439 		case OT_GOTO_WAYPOINT: {
   466 		for (const Order *o = v->orders; o != NULL; o = o->next) {
   478 		for (const Order *o = v->orders; o != NULL; o = o->next) {
   467 			if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o;
   479 			if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o;
   468 			if (++n == sel_ord && prev != NULL) break;
   480 			if (++n == sel_ord && prev != NULL) break;
   469 		}
   481 		}
   470 		if (prev != NULL) {
   482 		if (prev != NULL) {
   471 			uint dist = DistanceManhattan(
   483 			uint dist = GetOrderDistance(prev, &new_order, v);
   472 				GetOrderLocation(*prev),
       
   473 				GetOrderLocation(new_order)
       
   474 			);
       
   475 			if (dist >= 130) {
   484 			if (dist >= 130) {
   476 				return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
   485 				return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
   477 			}
   486 			}
   478 		}
   487 		}
   479 	}
   488 	}