mirror of https://github.com/OpenTTD/OpenTTD
(svn r26693) -Codechange: Simplify GetOrderCmdFromTile (Juanjo)
parent
14c4b24405
commit
8701514172
|
@ -348,7 +348,12 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
|
||||||
DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
|
DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the order command a vehicle can do in a given tile.
|
||||||
|
* @param v Vehicle involved.
|
||||||
|
* @param tile Tile being queried.
|
||||||
|
* @return The order associated to vehicle v in given tile (or empty order if vehicle can do nothing in the tile).
|
||||||
|
*/
|
||||||
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||||
{
|
{
|
||||||
/* Hack-ish; unpack order 0, so everything gets initialised with either zero
|
/* Hack-ish; unpack order 0, so everything gets initialised with either zero
|
||||||
|
@ -358,54 +363,21 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||||
order.index = 0;
|
order.index = 0;
|
||||||
|
|
||||||
/* check depot first */
|
/* check depot first */
|
||||||
switch (GetTileType(tile)) {
|
if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
|
||||||
case MP_RAILWAY:
|
order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
|
||||||
if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
|
ODTFB_PART_OF_ORDERS,
|
||||||
if (IsRailDepot(tile)) {
|
(_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
|
||||||
order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
|
|
||||||
_settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
|
|
||||||
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MP_ROAD:
|
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
|
||||||
if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
|
|
||||||
order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS,
|
|
||||||
_settings_client.gui.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
|
|
||||||
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MP_STATION:
|
return order;
|
||||||
if (v->type != VEH_AIRCRAFT) break;
|
|
||||||
if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
|
|
||||||
order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
|
|
||||||
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MP_WATER:
|
|
||||||
if (v->type != VEH_SHIP) break;
|
|
||||||
if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
|
|
||||||
order.MakeGoToDepot(GetDepotIndex(tile), ODTFB_PART_OF_ORDERS, ONSF_STOP_EVERYWHERE);
|
|
||||||
if (_ctrl_pressed) order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() ^ ODTFB_SERVICE));
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check waypoint */
|
/* check rail waypoint */
|
||||||
if (IsRailWaypointTile(tile) &&
|
if (IsRailWaypointTile(tile) &&
|
||||||
v->type == VEH_TRAIN &&
|
v->type == VEH_TRAIN &&
|
||||||
IsTileOwner(tile, _local_company)) {
|
IsTileOwner(tile, _local_company)) {
|
||||||
order.MakeGoToWaypoint(Waypoint::GetByTile(tile)->index);
|
order.MakeGoToWaypoint(GetStationIndex(tile));
|
||||||
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
|
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue