(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
authortruelight
Tue, 22 Aug 2006 18:15:17 +0000
changeset 4352 8ddb01bc6075
parent 4351 63ae31104f07
child 4353 2b941f2c325c
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
-Codechange: IsValidXXXID now also checks if XXX is really valid, not if the number is within range
Both changes again in preperation of the new mem-pool system, which requires this.
IsValidXXXID is not a bit less pretty, but that will be cleaned up after the new mem-pool system
aircraft_cmd.c
depot.h
order_cmd.c
road_cmd.c
roadveh_cmd.c
ship_cmd.c
signs.c
signs.h
station.h
station_cmd.c
town.h
town_cmd.c
train_cmd.c
vehicle.c
vehicle.h
waypoint.c
waypoint.h
--- a/aircraft_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/aircraft_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -426,7 +426,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -456,7 +456,7 @@
 	Vehicle *v;
 	uint16 callback;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -500,7 +500,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -568,7 +568,7 @@
 	const AircraftVehicleInfo *avi;
 	uint16 callback = CALLBACK_FAILED;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
--- a/depot.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/depot.h	Tue Aug 22 18:15:17 2006 +0000
@@ -35,11 +35,6 @@
 	return _depot_pool.total_items;
 }
 
-static inline bool IsDepotIndex(uint index)
-{
-	return index < GetDepotPoolSize();
-}
-
 /**
  * Check if a depot really exists.
  */
@@ -48,6 +43,11 @@
 	return depot->xy != 0;
 }
 
+static inline bool IsValidDepotID(uint index)
+{
+	return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
+}
+
 #define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
 #define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
 
--- a/order_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/order_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -179,9 +179,11 @@
 	OrderID sel_ord = GB(p1, 16, 16);
 	Order new_order = UnpackOrder(p2);
 
-	if (!IsVehicleIndex(veh)) return CMD_ERROR;
+	if (!IsValidVehicleID(veh)) return CMD_ERROR;
+
 	v = GetVehicle(veh);
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
 	/* Check if the inserted order is to the correct destination (owner, type),
 	 * and has the correct flags if any */
@@ -189,11 +191,10 @@
 		case OT_GOTO_STATION: {
 			const Station *st;
 
-			if (!IsStationIndex(new_order.station)) return CMD_ERROR;
+			if (!IsValidStationID(new_order.station)) return CMD_ERROR;
 			st = GetStation(new_order.station);
 
-			if (!IsValidStation(st) ||
-					(st->airport_type != AT_OILRIG && !IsBuoy(st) && !CheckOwnership(st->owner))) {
+			if (st->airport_type != AT_OILRIG && !IsBuoy(st) && !CheckOwnership(st->owner)) {
 				return CMD_ERROR;
 			}
 
@@ -251,11 +252,10 @@
 			if (v->type == VEH_Aircraft) {
 				const Station* st;
 
-				if (!IsStationIndex(new_order.station)) return CMD_ERROR;
+				if (!IsValidStationID(new_order.station)) return CMD_ERROR;
 				st = GetStation(new_order.station);
 
-				if (!IsValidStation(st) ||
-						(st->airport_type != AT_OILRIG && !CheckOwnership(st->owner)) ||
+				if ((st->airport_type != AT_OILRIG && !CheckOwnership(st->owner)) ||
 						!(st->facilities & FACIL_AIRPORT) ||
 						GetAirport(st->airport_type)->nof_depots == 0) {
 					return CMD_ERROR;
@@ -263,11 +263,10 @@
 			} else {
 				const Depot* dp;
 
-				if (!IsDepotIndex(new_order.station)) return CMD_ERROR;
+				if (!IsValidDepotID(new_order.station)) return CMD_ERROR;
 				dp = GetDepot(new_order.station);
 
-				if (!IsValidDepot(dp) || !CheckOwnership(GetTileOwner(dp->xy)))
-					return CMD_ERROR;
+				if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR;
 
 				switch (v->type) {
 					case VEH_Train:
@@ -309,7 +308,7 @@
 
 			if (v->type != VEH_Train) return CMD_ERROR;
 
-			if (!IsWaypointIndex(new_order.station)) return CMD_ERROR;
+			if (!IsValidWaypointID(new_order.station)) return CMD_ERROR;
 			wp = GetWaypoint(new_order.station);
 
 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
@@ -442,9 +441,11 @@
 	OrderID sel_ord = p2;
 	Order *order;
 
-	if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
+	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
+
 	v = GetVehicle(veh_id);
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
 	/* If we did not select an order, we maybe want to de-clone the orders */
 	if (sel_ord >= v->num_orders)
@@ -514,9 +515,11 @@
 	Vehicle *v;
 	VehicleID veh_id = p1;
 
-	if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
+	if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
+
 	v = GetVehicle(veh_id);
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
 		/* Goto next order */
@@ -561,11 +564,12 @@
 	OrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
 	VehicleID veh   = GB(p1,  0, 16);
 
-	if (!IsVehicleIndex(veh)) return CMD_ERROR;
+	if (!IsValidVehicleID(veh)) return CMD_ERROR;
 	if (p2 != OFB_FULL_LOAD && p2 != OFB_UNLOAD && p2 != OFB_NON_STOP && p2 != OFB_TRANSFER) return CMD_ERROR;
 
 	v = GetVehicle(veh);
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
 	/* Is it a valid order? */
 	if (sel_ord >= v->num_orders) return CMD_ERROR;
@@ -628,22 +632,22 @@
 	VehicleID veh_src = GB(p1, 16, 16);
 	VehicleID veh_dst = GB(p1,  0, 16);
 
-	if (!IsVehicleIndex(veh_dst)) return CMD_ERROR;
+	if (!IsValidVehicleID(veh_dst)) return CMD_ERROR;
 
 	dst = GetVehicle(veh_dst);
 
-	if (!IsValidVehicle(dst) || !CheckOwnership(dst->owner)) return CMD_ERROR;
+	if (!CheckOwnership(dst->owner)) return CMD_ERROR;
 
 	switch (p2) {
 		case CO_SHARE: {
 			Vehicle *src;
 
-			if (!IsVehicleIndex(veh_src)) return CMD_ERROR;
+			if (!IsValidVehicleID(veh_src)) return CMD_ERROR;
 
 			src = GetVehicle(veh_src);
 
 			/* Sanity checks */
-			if (!IsValidVehicle(src) || !CheckOwnership(src->owner) || dst->type != src->type || dst == src)
+			if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src)
 				return CMD_ERROR;
 
 			/* Trucks can't share orders with busses (and visa versa) */
@@ -685,12 +689,12 @@
 			Vehicle *src;
 			int delta;
 
-			if (!IsVehicleIndex(veh_src)) return CMD_ERROR;
+			if (!IsValidVehicleID(veh_src)) return CMD_ERROR;
 
 			src = GetVehicle(veh_src);
 
 			/* Sanity checks */
-			if (!IsValidVehicle(src) || !CheckOwnership(src->owner) || dst->type != src->type || dst == src)
+			if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src)
 				return CMD_ERROR;
 
 			/* Trucks can't copy all the orders from busses (and visa versa) */
@@ -844,11 +848,12 @@
 	OrderID cur_ord = GB(p2,  0, 16);
 	uint16 serv_int = GB(p2, 16, 16);
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
+
 	/* Check the vehicle type and ownership, and if the service interval and order are in range */
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 	if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
--- a/road_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/road_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -293,7 +293,7 @@
 
 	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
 	 * if a non-player is building the road */
-	if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsTownIndex(p2)) return CMD_ERROR;
+	if ((p1 >> 4) || (_current_player < MAX_PLAYERS && p2 != 0) || !IsValidTownID(p2)) return CMD_ERROR;
 	pieces = p1;
 
 	tileh = GetTileSlope(tile, NULL);
--- a/roadveh_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/roadveh_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -212,7 +212,7 @@
 	Vehicle *v;
 	uint16 callback;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -262,7 +262,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -364,7 +364,7 @@
 	Vehicle *v;
 	const Depot *dep;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -411,7 +411,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1757,7 +1757,7 @@
 	byte new_subtype = GB(p2, 8, 8);
 	uint16 capacity = CALLBACK_FAILED;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
--- a/ship_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/ship_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -929,7 +929,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -964,7 +964,7 @@
 	Vehicle *v;
 	uint16 callback;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1002,7 +1002,7 @@
 	Vehicle *v;
 	const Depot *dep;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1056,7 +1056,7 @@
 	byte new_subtype = GB(p2, 8, 8);
 	uint16 capacity = CALLBACK_FAILED;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
--- a/signs.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/signs.c	Tue Aug 22 18:15:17 2006 +0000
@@ -147,7 +147,7 @@
  */
 int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	if (!IsSignIndex(p1)) return CMD_ERROR;
+	if (!IsValidSignID(p1)) return CMD_ERROR;
 
 	/* If _cmd_text 0 means the new text for the sign is non-empty.
 	 * So rename the sign. If it is empty, it has no name, so delete it */
--- a/signs.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/signs.h	Tue Aug 22 18:15:17 2006 +0000
@@ -34,11 +34,6 @@
 	return _sign_pool.total_items;
 }
 
-static inline bool IsSignIndex(uint index)
-{
-	return index < GetSignPoolSize();
-}
-
 /**
  * Check if a Sign really exists.
  */
@@ -47,6 +42,11 @@
 	return si->str != STR_NULL;
 }
 
+static inline bool IsValidSignID(uint index)
+{
+	return index < GetSignPoolSize() && IsValidSign(GetSign(index));
+}
+
 #define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1 < GetSignPoolSize()) ? GetSign(ss->index + 1) : NULL) if (IsValidSign(ss))
 #define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
 
--- a/station.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/station.h	Tue Aug 22 18:15:17 2006 +0000
@@ -161,11 +161,6 @@
 	return _station_pool.total_items;
 }
 
-static inline bool IsStationIndex(StationID index)
-{
-	return index < GetStationPoolSize();
-}
-
 /**
  * Check if a station really exists.
  */
@@ -174,6 +169,11 @@
 	return st->xy != 0;
 }
 
+static inline bool IsValidStationID(StationID index)
+{
+	return index < GetStationPoolSize() && IsValidStation(GetStation(index));
+}
+
 #define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st))
 #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
 
--- a/station_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/station_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -2573,8 +2573,7 @@
 	i = _station_tick_ctr;
 	if (++_station_tick_ctr == GetStationPoolSize()) _station_tick_ctr = 0;
 
-	st = GetStation(i);
-	if (IsValidStation(st)) StationHandleBigTick(st);
+	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
 
 	FOR_ALL_STATIONS(st) {
 		StationHandleSmallTick(st);
@@ -2627,10 +2626,10 @@
 	StringID str;
 	Station *st;
 
-	if (!IsStationIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
+	if (!IsValidStationID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 	st = GetStation(p1);
 
-	if (!IsValidStation(st) || !CheckOwnership(st->owner)) return CMD_ERROR;
+	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 
 	str = AllocateNameUnique(_cmd_text, 6);
 	if (str == 0) return CMD_ERROR;
--- a/town.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/town.h	Tue Aug 22 18:15:17 2006 +0000
@@ -179,9 +179,9 @@
 	return _town_pool.total_items;
 }
 
-static inline bool IsTownIndex(uint index)
+static inline bool IsValidTownID(uint index)
 {
-	return index < GetTownPoolSize();
+	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
 }
 
 #define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) if (IsValidTown(t))
--- a/town_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/town_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -409,14 +409,11 @@
 	     _cur_town_iter >= TOWN_GROWTH_FREQUENCY;
 	     _cur_town_iter -= TOWN_GROWTH_FREQUENCY) {
 		uint32 i = _cur_town_ctr;
-		Town *t;
 
 		if (++_cur_town_ctr >= GetTownPoolSize())
 			_cur_town_ctr = 0;
 
-		t = GetTown(i);
-
-		if (IsValidTown(t)) TownTickHandler(t);
+		if (IsValidTownID(i)) TownTickHandler(GetTown(i));
 	}
 }
 
@@ -1348,7 +1345,7 @@
 	StringID str;
 	Town *t;
 
-	if (!IsTownIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
+	if (!IsValidTownID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 
 	t = GetTown(p1);
 
@@ -1605,7 +1602,7 @@
 	int32 cost;
 	Town *t;
 
-	if (!IsTownIndex(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
+	if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
 
 	t = GetTown(p1);
 
--- a/train_cmd.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/train_cmd.c	Tue Aug 22 18:15:17 2006 +0000
@@ -951,7 +951,7 @@
 	VehicleID d = GB(p1, 16, 16);
 	Vehicle *src, *dst, *src_head, *dst_head;
 
-	if (!IsVehicleIndex(s)) return CMD_ERROR;
+	if (!IsValidVehicleID(s)) return CMD_ERROR;
 
 	src = GetVehicle(s);
 
@@ -1230,7 +1230,7 @@
 	Vehicle *v;
 	uint16 callback;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1275,7 +1275,7 @@
 	Vehicle *new_f = NULL;
 	int32 cost = 0;
 
-	if (!IsVehicleIndex(p1) || p2 > 2) return CMD_ERROR;
+	if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1671,7 +1671,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1720,7 +1720,7 @@
 {
 	Vehicle *v;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1746,7 +1746,7 @@
 	int32 cost;
 	uint num;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1930,7 +1930,7 @@
 	Vehicle *v;
 	TrainFindDepotData tfdd;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
--- a/vehicle.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/vehicle.c	Tue Aug 22 18:15:17 2006 +0000
@@ -1526,7 +1526,7 @@
 	int cost, total_cost = 0;
 	uint32 build_argument = 2;
 
-	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 	v = GetVehicle(p1);
 	v_front = v;
 	w = NULL;
@@ -1907,7 +1907,7 @@
 	Vehicle *v;
 	StringID str;
 
-	if (!IsVehicleIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
+	if (!IsValidVehicleID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
@@ -1940,11 +1940,11 @@
 	Vehicle* v;
 	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
 
-	if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
+	if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
 
 	v = GetVehicle(p1);
 
-	if (!IsValidVehicle(v) || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
 		v->service_interval = serv_int;
--- a/vehicle.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/vehicle.h	Tue Aug 22 18:15:17 2006 +0000
@@ -375,9 +375,9 @@
  *
  * @return Returns true if the vehicle-id is in range
  */
-static inline bool IsVehicleIndex(uint index)
+static inline bool IsValidVehicleID(uint index)
 {
-	return index < GetVehiclePoolSize();
+	return index < GetVehiclePoolSize() && IsValidVehicle(GetVehicle(index));
 }
 
 /* Returns order 'index' of a vehicle or NULL when it doesn't exists */
--- a/waypoint.c	Tue Aug 22 17:13:49 2006 +0000
+++ b/waypoint.c	Tue Aug 22 18:15:17 2006 +0000
@@ -319,7 +319,7 @@
 {
 	Waypoint *wp;
 
-	if (!IsWaypointIndex(p1)) return CMD_ERROR;
+	if (!IsValidWaypointID(p1)) return CMD_ERROR;
 
 	if (_cmd_text[0] != '\0') {
 		StringID str = AllocateNameUnique(_cmd_text, 0);
--- a/waypoint.h	Tue Aug 22 17:13:49 2006 +0000
+++ b/waypoint.h	Tue Aug 22 18:15:17 2006 +0000
@@ -42,11 +42,6 @@
 	return _waypoint_pool.total_items;
 }
 
-static inline bool IsWaypointIndex(uint index)
-{
-	return index < GetWaypointPoolSize();
-}
-
 /**
  * Check if a Waypoint really exists.
  */
@@ -55,6 +50,11 @@
 	return wp->xy != 0;
 }
 
+static inline bool IsValidWaypointID(uint index)
+{
+	return index < GetWaypointPoolSize() && IsValidWaypoint(GetWaypoint(index));
+}
+
 #define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = GetWaypoint(start); wp != NULL; wp = (wp->index + 1 < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1) : NULL) if (IsValidWaypoint(wp))
 #define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)