Changeset - r4352:460a517b040f
[Not reviewed]
master
0 17 0
truelight - 18 years ago 2006-08-22 18:15:17
truelight@openttd.org
(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
17 files changed with 88 insertions and 87 deletions:
0 comments (0 inline, 0 general)
aircraft_cmd.c
Show inline comments
 
@@ -423,13 +423,13 @@ static void DoDeleteAircraft(Vehicle *v)
 
 * @param p2 unused
 
 */
 
int32 CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 

	
 
@@ -453,13 +453,13 @@ int32 CmdSellAircraft(TileIndex tile, ui
 
 */
 
int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	// cannot stop airplane when in flight, or when taking off / landing
 
@@ -497,13 +497,13 @@ int32 CmdStartStopAircraft(TileIndex til
 
 * - p2 (bit 17) - aircraft will try to goto a depot at the airport specified by low word of p2 XXX - Not Used
 
 */
 
int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->current_order.type == OT_GOTO_DEPOT && p2 == 0) {
 
@@ -565,13 +565,13 @@ int32 CmdRefitAircraft(TileIndex tile, u
 
	int32 cost;
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	const AircraftVehicleInfo *avi;
 
	uint16 callback = CALLBACK_FAILED;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 

	
depot.h
Show inline comments
 
@@ -32,25 +32,25 @@ static inline Depot *GetDepot(uint index
 
 */
 
static inline uint16 GetDepotPoolSize(void)
 
{
 
	return _depot_pool.total_items;
 
}
 

	
 
static inline bool IsDepotIndex(uint index)
 
{
 
	return index < GetDepotPoolSize();
 
}
 

	
 
/**
 
 * Check if a depot really exists.
 
 */
 
static inline bool IsValidDepot(const Depot* depot)
 
{
 
	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)
 

	
 
#define MIN_SERVINT_PERCENT  5
 
#define MAX_SERVINT_PERCENT 90
 
#define MIN_SERVINT_DAYS    30
order_cmd.c
Show inline comments
 
@@ -176,27 +176,28 @@ int32 CmdInsertOrder(TileIndex tile, uin
 
{
 
	Vehicle *v;
 
	VehicleID veh   = GB(p1,  0, 16);
 
	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 */
 
	switch (new_order.type) {
 
		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;
 
			}
 

	
 
			switch (v->type) {
 
				case VEH_Train:
 
					if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR;
 
@@ -248,29 +249,27 @@ int32 CmdInsertOrder(TileIndex tile, uin
 
		}
 

	
 
		case OT_GOTO_DEPOT: {
 
			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;
 
				}
 
			} 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:
 
						if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
 
						break;
 

	
 
@@ -306,13 +305,13 @@ int32 CmdInsertOrder(TileIndex tile, uin
 

	
 
		case OT_GOTO_WAYPOINT: {
 
			const Waypoint* wp;
 

	
 
			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;
 

	
 
			/* Order flags can be any of the following for waypoints:
 
			 * [non-stop]
 
@@ -439,15 +438,17 @@ int32 CmdDeleteOrder(TileIndex tile, uin
 
{
 
	Vehicle *v, *u;
 
	VehicleID veh_id = p1;
 
	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)
 
		return DecloneOrder(v, flags);
 

	
 
	order = GetVehicleOrder(v, sel_ord);
 
@@ -511,15 +512,17 @@ int32 CmdDeleteOrder(TileIndex tile, uin
 
 */
 
int32 CmdSkipOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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 */
 
		OrderID b = v->cur_order_index + 1;
 
		if (b >= v->num_orders) b = 0;
 

	
 
@@ -558,17 +561,18 @@ int32 CmdModifyOrder(TileIndex tile, uin
 
{
 
	Vehicle *v;
 
	Order *order;
 
	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;
 

	
 
	order = GetVehicleOrder(v, sel_ord);
 
	if (order->type != OT_GOTO_STATION &&
 
@@ -625,28 +629,28 @@ int32 CmdModifyOrder(TileIndex tile, uin
 
int32 CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *dst;
 
	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) */
 
			if (src->type == VEH_Road) {
 
				if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS))
 
					return CMD_ERROR;
 
@@ -682,18 +686,18 @@ int32 CmdCloneOrder(TileIndex tile, uint
 
		} break;
 

	
 
		case CO_COPY: {
 
			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) */
 
			if (src->type == VEH_Road) {
 
				const Order *order;
 
				TileIndex required_dst = INVALID_TILE;
 
@@ -841,17 +845,18 @@ void RestoreVehicleOrders(const Vehicle*
 
int32 CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	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) {
 
		v->cur_order_index = cur_ord;
 
		v->service_interval = serv_int;
 
	}
road_cmd.c
Show inline comments
 
@@ -290,13 +290,13 @@ int32 CmdBuildRoad(TileIndex tile, uint3
 
	Slope tileh;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* 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);
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_STREET:
roadveh_cmd.c
Show inline comments
 
@@ -209,13 +209,13 @@ int32 CmdBuildRoadVeh(TileIndex tile, ui
 
 */
 
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Check if this road veh can be started/stopped. The callback will fail or
 
@@ -259,13 +259,13 @@ void ClearSlot(Vehicle *v)
 
 * @param p2 unused
 
 */
 
int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -361,13 +361,13 @@ static const Depot* FindClosestRoadDepot
 
 */
 
int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	const Depot *dep;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 
@@ -408,13 +408,13 @@ int32 CmdSendRoadVehToDepot(TileIndex ti
 
 * @param p2 unused
 
 */
 
int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & (VS_HIDDEN | VS_STOPPED) ||
 
@@ -1754,13 +1754,13 @@ int32 CmdRefitRoadVeh(TileIndex tile, ui
 
	Vehicle *v;
 
	int32 cost;
 
	CargoID new_cid = GB(p2, 0, 8);
 
	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);
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!IsRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
 

	
ship_cmd.c
Show inline comments
 
@@ -926,13 +926,13 @@ int32 CmdBuildShip(TileIndex tile, uint3
 
 * @param p2 unused
 
 */
 
int32 CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -961,13 +961,13 @@ int32 CmdSellShip(TileIndex tile, uint32
 
 */
 
int32 CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Check if this ship can be started/stopped. The callback will fail or
 
@@ -999,13 +999,13 @@ int32 CmdStartStopShip(TileIndex tile, u
 
 */
 
int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	const Depot *dep;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 
@@ -1053,13 +1053,13 @@ int32 CmdRefitShip(TileIndex tile, uint3
 
	Vehicle *v;
 
	int32 cost;
 
	CargoID new_cid = GB(p2, 0, 8); //gets the cargo number
 
	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);
 

	
 
	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (!IsShipInDepotStopped(v)) {
signs.c
Show inline comments
 
@@ -144,13 +144,13 @@ int32 CmdPlaceSign(TileIndex tile, uint3
 
 * @param tile unused
 
 * @param p1 index of the sign to be renamed/removed
 
 * @param p2 unused
 
 */
 
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 */
 
	if (_cmd_text[0] != '\0') {
 
		/* Create the name */
 
		StringID str = AllocateName(_cmd_text, 0);
signs.h
Show inline comments
 
@@ -31,25 +31,25 @@ static inline Sign *GetSign(SignID index
 
 */
 
static inline uint16 GetSignPoolSize(void)
 
{
 
	return _sign_pool.total_items;
 
}
 

	
 
static inline bool IsSignIndex(uint index)
 
{
 
	return index < GetSignPoolSize();
 
}
 

	
 
/**
 
 * Check if a Sign really exists.
 
 */
 
static inline bool IsValidSign(const Sign *si)
 
{
 
	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)
 

	
 
VARDEF bool _sign_sort_dirty;
 
VARDEF SignID *_sign_sort;
 

	
station.h
Show inline comments
 
@@ -158,25 +158,25 @@ static inline Station *GetStation(Statio
 
 */
 
static inline uint16 GetStationPoolSize(void)
 
{
 
	return _station_pool.total_items;
 
}
 

	
 
static inline bool IsStationIndex(StationID index)
 
{
 
	return index < GetStationPoolSize();
 
}
 

	
 
/**
 
 * Check if a station really exists.
 
 */
 
static inline bool IsValidStation(const Station *st)
 
{
 
	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)
 

	
 

	
 
/* Stuff for ROADSTOPS */
 

	
station_cmd.c
Show inline comments
 
@@ -2570,14 +2570,13 @@ void OnTick_Station(void)
 

	
 
	if (_game_mode == GM_EDITOR) return;
 

	
 
	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);
 
	}
 
}
 

	
 
@@ -2624,16 +2623,16 @@ static void UpdateStationWaiting(Station
 
 */
 
int32 CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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;
 

	
 
	if (flags & DC_EXEC) {
 
		StringID old_str = st->string_id;
town.h
Show inline comments
 
@@ -176,15 +176,15 @@ static inline Town *GetTown(uint index)
 
 */
 
static inline uint16 GetTownPoolSize(void)
 
{
 
	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))
 
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
 

	
 
VARDEF uint _total_towns; // For the AI: the amount of towns active
town_cmd.c
Show inline comments
 
@@ -406,20 +406,17 @@ void OnTick_Town(void)
 
	/* Make sure each town's tickhandler invocation frequency is about the
 
	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
 
	for (_cur_town_iter += GetTownPoolSize();
 
	     _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));
 
	}
 
}
 

	
 
static RoadBits GetTownRoadMask(TileIndex tile)
 
{
 
	TrackBits b = GetAnyRoadTrackBits(tile);
 
@@ -1345,13 +1342,13 @@ static void ClearTownHouse(Town *t, Tile
 
 */
 
int32 CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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);
 

	
 
	str = AllocateNameUnique(_cmd_text, 4);
 
	if (str == 0) return CMD_ERROR;
 

	
 
@@ -1602,13 +1599,13 @@ extern uint GetMaskOfTownActions(int *nu
 
 */
 
int32 CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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);
 

	
 
	if (!HASBIT(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
train_cmd.c
Show inline comments
 
@@ -948,13 +948,13 @@ static void NormaliseTrainConsist(Vehicl
 
int32 CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	VehicleID s = GB(p1, 0, 16);
 
	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);
 

	
 
	if (src->type != VEH_Train) return CMD_ERROR;
 

	
 
	// if nothing is selected as destination, try and find a matching vehicle to drag to.
 
@@ -1227,13 +1227,13 @@ int32 CmdMoveRailVehicle(TileIndex tile,
 
 */
 
int32 CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	uint16 callback;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	/* Check if this train can be started/stopped. The callback will fail or
 
@@ -1272,13 +1272,13 @@ int32 CmdStartStopTrain(TileIndex tile, 
 
int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v, *tmp, *first;
 
	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);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -1668,13 +1668,13 @@ static void ReverseTrainDirection(Vehicl
 
 * @param p2 if true, reverse a unit in a train (needs to be in a depot)
 
 */
 
int32 CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (p2) {
 
@@ -1717,13 +1717,13 @@ int32 CmdReverseTrainDirection(TileIndex
 
 * @param p2 unused
 
 */
 
int32 CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) v->u.rail.force_proceed = 0x50;
 
@@ -1743,13 +1743,13 @@ int32 CmdRefitRailVehicle(TileIndex tile
 
	CargoID new_cid = GB(p2, 0, 8);
 
	byte new_subtype = GB(p2, 8, 8);
 
	Vehicle *v;
 
	int32 cost;
 
	uint num;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
 

	
 
@@ -1927,13 +1927,13 @@ static TrainFindDepotData FindClosestTra
 
 */
 
int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *v;
 
	TrainFindDepotData tfdd;
 

	
 
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
	if (!IsValidVehicleID(p1)) return CMD_ERROR;
 

	
 
	v = GetVehicle(p1);
 

	
 
	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
vehicle.c
Show inline comments
 
@@ -1523,13 +1523,13 @@ int32 CmdCloneVehicle(TileIndex tile, ui
 
{
 
	Vehicle *v_front, *v;
 
	Vehicle *w_front, *w, *w_rear;
 
	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;
 
	w_front = NULL;
 
	w_rear = NULL;
 

	
 
@@ -1904,13 +1904,13 @@ static void MaybeReplaceVehicle(Vehicle 
 
 */
 
int32 CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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);
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	str = AllocateNameUnique(_cmd_text, 2);
 
@@ -1937,17 +1937,17 @@ int32 CmdNameVehicle(TileIndex tile, uin
 
 */
 
int32 CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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;
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
	}
 

	
vehicle.h
Show inline comments
 
@@ -372,15 +372,15 @@ static inline bool IsValidVehicle(const 
 

	
 
/**
 
 * Check if an index is a vehicle-index (so between 0 and max-vehicles)
 
 *
 
 * @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 */
 
static inline Order *GetVehicleOrder(const Vehicle *v, int index)
 
{
 
	Order *order = v->orders;
waypoint.c
Show inline comments
 
@@ -316,13 +316,13 @@ int32 CmdRemoveTrainWaypoint(TileIndex t
 
 * @param p2 unused
 
 */
 
int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	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);
 

	
 
		if (str == 0) return CMD_ERROR;
 

	
waypoint.h
Show inline comments
 
@@ -39,25 +39,25 @@ static inline Waypoint *GetWaypoint(uint
 
 */
 
static inline uint16 GetWaypointPoolSize(void)
 
{
 
	return _waypoint_pool.total_items;
 
}
 

	
 
static inline bool IsWaypointIndex(uint index)
 
{
 
	return index < GetWaypointPoolSize();
 
}
 

	
 
/**
 
 * Check if a Waypoint really exists.
 
 */
 
static inline bool IsValidWaypoint(const Waypoint *wp)
 
{
 
	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)
 

	
 

	
 
/**
 
 * Fetch a waypoint by tile
0 comments (0 inline, 0 general)