Changeset - r23574:c4fadf1811cf
[Not reviewed]
master
0 2 0
peter1138 - 5 years ago 2019-02-25 13:07:29
peter1138@openttd.org
Change: Remove ship max order distance.

It is skipped when NPF is in use.
It is trivial to work around by adding and removing dummy orders.
It is mostly alleviated by the ship path cache in YAPF.
2 files changed with 0 insertions and 39 deletions:
0 comments (0 inline, 0 general)
src/order_cmd.cpp
Show inline comments
 
@@ -14,25 +14,24 @@
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "company_func.h"
 
#include "news_func.h"
 
#include "strings_func.h"
 
#include "timetable.h"
 
#include "vehicle_func.h"
 
#include "depot_base.h"
 
#include "core/pool_func.hpp"
 
#include "core/random_func.hpp"
 
#include "aircraft.h"
 
#include "roadveh.h"
 
#include "ship.h"
 
#include "station_base.h"
 
#include "waypoint_base.h"
 
#include "company_base.h"
 
#include "order_backup.h"
 
#include "cheat_type.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/* DestinationID must be at least as large as every these below, because it can
 
 * be any of them
 
@@ -891,60 +890,24 @@ CommandCost CmdInsertOrder(TileIndex til
 
			break;
 
		}
 

	
 
		default: return CMD_ERROR;
 
	}
 

	
 
	if (sel_ord > v->GetNumOrders()) return CMD_ERROR;
 

	
 
	if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS);
 
	if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
 
	if (v->orders.list == NULL && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
 

	
 
	if (v->type == VEH_SHIP && _settings_game.pf.pathfinder_for_ships != VPF_NPF) {
 
		/* Make sure the new destination is not too far away from the previous */
 
		const Order *prev = NULL;
 
		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. */
 
		const Order *o;
 
		FOR_VEHICLE_ORDERS(v, o) {
 
			switch (o->GetType()) {
 
				case OT_GOTO_STATION:
 
				case OT_GOTO_DEPOT:
 
				case OT_GOTO_WAYPOINT:
 
					prev = o;
 
					break;
 

	
 
				default: break;
 
			}
 
			if (++n == sel_ord && prev != NULL) break;
 
		}
 
		if (prev != NULL) {
 
			uint dist;
 
			if (new_order.IsType(OT_CONDITIONAL)) {
 
				/* The order is not yet inserted, so we have to do the first iteration here. */
 
				dist = GetOrderDistance(prev, v->GetOrder(new_order.GetConditionSkipToOrder()), v);
 
			} else {
 
				dist = GetOrderDistance(prev, &new_order, v);
 
			}
 

	
 
			if (dist >= SHIP_MAX_ORDER_DISTANCE) {
 
				return_cmd_error(STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION);
 
			}
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Order *new_o = new Order();
 
		new_o->AssignOrder(new_order);
 
		InsertOrder(v, new_o, sel_ord);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Insert a new order but skip the validation.
 
 * @param v       The vehicle to insert the order to.
src/ship.h
Show inline comments
 
@@ -48,21 +48,19 @@ struct Ship FINAL : public SpecializedVe
 
	int GetCurrentMaxSpeed() const { return min(this->vcache.cached_max_speed, this->current_order.GetMaxSpeed() * 2); }
 
	Money GetRunningCost() const;
 
	bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
 
	bool Tick();
 
	void OnNewDay();
 
	Trackdir GetVehicleTrackdir() const;
 
	TileIndex GetOrderStationLocation(StationID station);
 
	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
 
	void UpdateCache();
 
	void SetDestTile(TileIndex tile);
 
};
 

	
 
static const uint SHIP_MAX_ORDER_DISTANCE = 130;
 

	
 
/**
 
 * Iterate over all ships.
 
 * @param var The variable used for iteration.
 
 */
 
#define FOR_ALL_SHIPS(var) FOR_ALL_VEHICLES_OF_TYPE(Ship, var)
 

	
 
#endif /* SHIP_H */
0 comments (0 inline, 0 general)