Changeset - r12084:850e45fd8022
[Not reviewed]
master
0 9 0
frosch - 15 years ago 2009-06-01 15:01:54
frosch@openttd.org
(svn r16498) -Codechange: Remove hardly used HASBITS.
9 files changed with 27 insertions and 39 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -445,13 +445,13 @@ CommandCost CmdSellAircraft(TileIndex ti
 
{
 
	Aircraft *v = Aircraft::GetIfValid(p1);
 

	
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
 

	
 
	if (flags & DC_EXEC) {
 
		delete v;
 
	}
 
@@ -1813,13 +1813,13 @@ static bool AirportHasBlock(Aircraft *v,
 

	
 
		/* check additional possible extra blocks */
 
		if (current_pos != reference && current_pos->block != NOTHING_block) {
 
			airport_flags |= current_pos->block;
 
		}
 

	
 
		if (HASBITS(st->airport_flags, airport_flags)) {
 
		if (st->airport_flags & airport_flags) {
 
			v->cur_speed = 0;
 
			v->subspeed = 0;
 
			return true;
 
		}
 
	}
 
	return false;
 
@@ -1854,13 +1854,13 @@ static bool AirportSetBlocks(Aircraft *v
 

	
 
		/* if the block to be checked is in the next position, then exclude that from
 
		 * checking, because it has been set by the airplane before */
 
		if (current_pos->block == next->block) airport_flags ^= next->block;
 

	
 
		Station *st = Station::Get(v->targetairport);
 
		if (HASBITS(st->airport_flags, airport_flags)) {
 
		if (st->airport_flags & airport_flags) {
 
			v->cur_speed = 0;
 
			v->subspeed = 0;
 
			return false;
 
		}
 

	
 
		if (next->block != NOTHING_block) {
 
@@ -1908,13 +1908,13 @@ static bool AirportFindFreeTerminal(Airc
 
	if (apc->terminals[0] > 1) {
 
		const Station *st = Station::Get(v->targetairport);
 
		const AirportFTA *temp = apc->layout[v->pos].next;
 

	
 
		while (temp != NULL) {
 
			if (temp->heading == 255) {
 
				if (!HASBITS(st->airport_flags, temp->block)) {
 
				if (!(st->airport_flags & temp->block)) {
 
					/* read which group do we want to go to?
 
					 * (the first free group) */
 
					uint target_group = temp->next_position + 1;
 

	
 
					/* at what terminal does the group start?
 
					 * that means, sum up all terminals of
 
@@ -1959,13 +1959,13 @@ static bool AirportFindFreeHelipad(Aircr
 
	if (apc->helipads[0] > 1) {
 
		const Station *st = Station::Get(v->targetairport);
 
		const AirportFTA *temp = apc->layout[v->pos].next;
 

	
 
		while (temp != NULL) {
 
			if (temp->heading == 255) {
 
				if (!HASBITS(st->airport_flags, temp->block)) {
 
				if (!(st->airport_flags & temp->block)) {
 

	
 
					/* read which group do we want to go to?
 
					 * (the first free group) */
 
					uint target_group = temp->next_position + 1;
 

	
 
					/* at what terminal does the group start?
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -610,13 +610,13 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 

	
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == NULL) return CMD_ERROR;
 

	
 
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (!v->IsInDepot()) return CMD_ERROR;
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return CMD_ERROR;
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	bool free_wagon = false;
 
	if (v->type == VEH_TRAIN) {
 
		if (IsArticulatedPart(v) || IsRearDualheaded(v)) return CMD_ERROR;
 
		free_wagon = !IsFrontEngine(v);
 
		if (free_wagon && IsFrontEngine(v->First())) return CMD_ERROR;
src/core/bitmath_func.hpp
Show inline comments
 
@@ -89,24 +89,12 @@ template <typename T>
 
static FORCEINLINE bool HasBit(const T x, const uint8 y)
 
{
 
	return (x & ((T)1U << y)) != 0;
 
}
 

	
 
/**
 
 * Check several bits in a value.
 
 *
 
 * This macro checks if a value contains at least one bit of an other
 
 * value.
 
 *
 
 * @param x The first value
 
 * @param y The second value
 
 * @return True if at least one bit is set in both values, false else.
 
 */
 
#define HASBITS(x, y) (((x) & (y)) != 0)
 

	
 
/**
 
 * Set a bit in a variable.
 
 *
 
 * This function sets a bit in a variable. The variable is changed
 
 * and the value is also returned. Parameter y defines the bit and
 
 * starts at the LSB with 0.
 
 *
src/newgrf_text.cpp
Show inline comments
 
@@ -256,13 +256,13 @@ StringID AddGRFString(uint32 grfid, uint
 
	 * English or American is among the set bits, simply add it as English in
 
	 * the new scheme, i.e. as langid = 1.
 
	 * If English is set, it is pretty safe to assume the translations are not
 
	 * actually translated.
 
	 */
 
	if (!new_scheme) {
 
		if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) {
 
		if (langid_to_add & (GRFLB_AMERICAN | GRFLB_ENGLISH)) {
 
			langid_to_add = GRFLX_ENGLISH;
 
		} else {
 
			StringID ret = STR_EMPTY;
 
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, GRFLX_GERMAN,  true, text_to_add, def_string);
 
			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, GRFLX_FRENCH,  true, text_to_add, def_string);
 
			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, text_to_add, def_string);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -317,13 +317,13 @@ bool RoadVehicle::IsStoppedInDepot() con
 
 */
 
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RoadVehicle *v = RoadVehicle::GetIfValid(p1);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	if (!v->IsStoppedInDepot()) {
 
		return_cmd_error(STR_ERROR_ROAD_MUST_BE_STOPPED_INSIDE_DEPOT);
 
	}
 

	
 
	CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
src/ship_cmd.cpp
Show inline comments
 
@@ -842,13 +842,13 @@ CommandCost CmdBuildShip(TileIndex tile,
 
 */
 
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Ship *v = Ship::GetIfValid(p1);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	if (!v->IsStoppedInDepot()) {
 
		return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
 
	}
 

	
 
	CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
src/sortlist_type.h
Show inline comments
 
@@ -103,13 +103,13 @@ public:
 
	 *
 
	 * @return the current sort conditions
 
	 */
 
	Listing GetListing() const
 
	{
 
		Listing l;
 
		l.order = HASBITS(this->flags, VL_DESC);
 
		l.order = (this->flags & VL_DESC) != 0;
 
		l.criteria = this->sort_type;
 

	
 
		return l;
 
	}
 

	
 
	/**
 
@@ -156,13 +156,13 @@ public:
 
	 *
 
	 * @return the current filter conditions
 
	 */
 
	Filtering GetFiltering() const
 
	{
 
		Filtering f;
 
		f.state = HASBITS(this->flags, VL_FILTER);
 
		f.state = (this->flags & VL_FILTER) != 0;
 
		f.criteria = this->filter_type;
 

	
 
		return f;
 
	}
 

	
 
	/**
 
@@ -211,13 +211,13 @@ public:
 
	 * Check if the sort order is descending
 
	 *
 
	 * @return true if the sort order is descending
 
	 */
 
	bool IsDescSortOrder() const
 
	{
 
		return HASBITS(this->flags, VL_DESC);
 
		return (this->flags & VL_DESC) != 0;
 
	}
 

	
 
	/**
 
	 * Toogle the sort order
 
	 *  Since that is the worst condition for the sort function
 
	 *  reverse the list here.
 
@@ -238,24 +238,24 @@ public:
 
	 * @param compare The function to compare two list items
 
	 * @return true if the list sequence has been altered
 
	 * */
 
	bool Sort(SortFunction *compare)
 
	{
 
		/* Do not sort if the resort bit is not set */
 
		if (!HASBITS(this->flags, VL_RESORT)) return false;
 
		if (!(this->flags & VL_RESORT)) return false;
 

	
 
		CLRBITS(this->flags, VL_RESORT);
 

	
 
		this->ResetResortTimer();
 

	
 
		/* Do not sort when the list is not sortable */
 
		if (!this->IsSortable()) return false;
 

	
 
		const bool desc = HASBITS(this->flags, VL_DESC);
 
		const bool desc = (this->flags & VL_DESC) != 0;
 

	
 
		if (HASBITS(this->flags, VL_FIRST_SORT)) {
 
		if (this->flags & VL_FIRST_SORT) {
 
			CLRBITS(this->flags, VL_FIRST_SORT);
 

	
 
			QSortT(this->data, this->items, compare, desc);
 
			return true;
 
		}
 

	
 
@@ -289,13 +289,13 @@ public:
 
	 * Check if the filter is enabled
 
	 *
 
	 * @return true if the filter is enabled
 
	 */
 
	bool IsFilterEnabled() const
 
	{
 
		return HASBITS(this->flags, VL_FILTER);
 
		return (this->flags & VL_FILTER) != 0;
 
	}
 

	
 
	/**
 
	 * Enable or disable the filter
 
	 *
 
	 * @param state If filtering should be enabled or disabled
 
@@ -316,13 +316,13 @@ public:
 
	 * @param filter_data Additional data passed to the filter function
 
	 * @return true if the list has been altered by filtering
 
	 */
 
	bool Filter(FilterFunction *decide, F filter_data)
 
	{
 
		/* Do not filter if the filter bit is not set */
 
		if (!HASBITS(this->flags, VL_FILTER)) return false;
 
		if (!(this->flags & VL_FILTER)) return false;
 

	
 
		bool changed = false;
 
		for (uint iter = 0; iter < this->items;) {
 
			T *item = &this->data[iter];
 
			if (!decide(item, filter_data)) {
 
				this->Erase(item);
 
@@ -360,13 +360,13 @@ public:
 
	/**
 
	 * Check if a rebuild is needed
 
	 * @return true if a rebuild is needed
 
	 */
 
	bool NeedRebuild() const
 
	{
 
		return HASBITS(this->flags, VL_REBUILD);
 
		return (this->flags & VL_REBUILD) != 0;
 
	}
 

	
 
	/**
 
	 * Force that a rebuild is needed
 
	 */
 
	void ForceRebuild()
src/town_cmd.cpp
Show inline comments
 
@@ -956,13 +956,13 @@ static bool GrowTownWithBridge(const Tow
 
	const Slope slope = GetTileSlope(tile, NULL);
 
	if (slope == SLOPE_FLAT) return false; // no slope, no bridge
 

	
 
	/* Make sure the direction is compatible with the slope.
 
	 * Well we check if the slope has an up bit set in the
 
	 * reverse direction. */
 
	if (HASBITS(slope, InclinedSlope(bridge_dir))) return false;
 
	if (slope & InclinedSlope(bridge_dir)) return false;
 

	
 
	/* Assure that the bridge is connectable to the start side */
 
	if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(bridge_dir))) & DiagDirToRoadBits(bridge_dir))) return false;
 

	
 
	/* We are in the right direction */
 
	uint8 bridge_length = 0;      // This value stores the length of the possible bridge
 
@@ -2118,13 +2118,13 @@ static bool BuildTownHouse(Town *t, Tile
 
		if (hs->building_flags & BUILDING_IS_CHURCH) {
 
			SetBit(oneof, TOWN_HAS_CHURCH);
 
		} else if (hs->building_flags & BUILDING_IS_STADIUM) {
 
			SetBit(oneof, TOWN_HAS_STADIUM);
 
		}
 

	
 
		if (HASBITS(t->flags12, oneof)) continue;
 
		if (t->flags12 & oneof) continue;
 

	
 
		/* Make sure there is no slope? */
 
		bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
 
		if (noslope && slope != SLOPE_FLAT) continue;
 

	
 
		if (hs->building_flags & TILE_SIZE_2x2) {
src/train_cmd.cpp
Show inline comments
 
@@ -675,13 +675,13 @@ static CommandCost CmdBuildRailWagon(Eng
 

	
 
		Train *w;
 
		FOR_ALL_TRAINS(w) {
 
			/* do not connect new wagon with crashed/flooded consists */
 
			if (w->tile == tile && IsFreeWagon(w) &&
 
					w->engine_type == engine &&
 
					!HASBITS(w->vehstatus, VS_CRASHED)) {
 
					!(w->vehstatus & VS_CRASHED)) {
 
				u = GetLastVehicleInChain(w);
 
				break;
 
			}
 
		}
 

	
 
		Train *v = new Train();
 
@@ -992,13 +992,13 @@ static Train *FindGoodVehiclePos(const T
 
{
 
	EngineID eng = src->engine_type;
 
	TileIndex tile = src->tile;
 

	
 
	Train *dst;
 
	FOR_ALL_TRAINS(dst) {
 
		if (IsFreeWagon(dst) && dst->tile == tile && !HASBITS(dst->vehstatus, VS_CRASHED)) {
 
		if (IsFreeWagon(dst) && dst->tile == tile && !(dst->vehstatus & VS_CRASHED)) {
 
			/* check so all vehicles in the line have the same engine. */
 
			Train *t = dst;
 
			while (t->engine_type == eng) {
 
				t = t->Next();
 
				if (t == NULL) return dst;
 
			}
 
@@ -1062,24 +1062,24 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
	VehicleID d = GB(p1, 16, 16);
 

	
 
	Train *src = Train::GetIfValid(s);
 
	if (src == NULL || !CheckOwnership(src->owner)) return CMD_ERROR;
 

	
 
	/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
 
	if (HASBITS(src->vehstatus, VS_CRASHED)) return CMD_ERROR;
 
	if (src->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	/* if nothing is selected as destination, try and find a matching vehicle to drag to. */
 
	Train *dst;
 
	if (d == INVALID_VEHICLE) {
 
		dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src);
 
	} else {
 
		dst = Train::GetIfValid(d);
 
		if (dst == NULL || !CheckOwnership(dst->owner)) return CMD_ERROR;
 

	
 
		/* Do not allow appending to crashed vehicles, too */
 
		if (HASBITS(dst->vehstatus, VS_CRASHED)) return CMD_ERROR;
 
		if (dst->vehstatus & VS_CRASHED) return CMD_ERROR;
 
	}
 

	
 
	/* if an articulated part is being handled, deal with its parent vehicle */
 
	while (IsArticulatedPart(src)) src = src->Previous();
 
	if (dst != NULL) {
 
		while (IsArticulatedPart(dst)) dst = dst->Previous();
 
@@ -1413,13 +1413,13 @@ CommandCost CmdSellRailWagon(TileIndex t
 
	Window *w = NULL;
 

	
 
	Train *v = Train::GetIfValid(p1);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (p2 > 1) return CMD_ERROR;
 

	
 
	if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 
	if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
 

	
 
	while (IsArticulatedPart(v)) v = v->Previous();
 
	Train *first = v->First();
 

	
 
	/* make sure the vehicle is stopped in the depot */
 
	if (CheckTrainStoppedInDepot(first) < 0) {
 
@@ -3571,13 +3571,13 @@ static Vehicle *FindTrainCollideEnum(Veh
 
		tcc->num += TrainCrashed((Train *)coll);
 

	
 
		/* Try to reserve all tiles directly under the crashed trains.
 
		 * As there might be more than two trains involved, we have to do that for all vehicles */
 
		const Train *u;
 
		FOR_ALL_TRAINS(u) {
 
			if (HASBITS(u->vehstatus, VS_CRASHED) && (u->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
 
			if ((u->vehstatus & VS_CRASHED) && (u->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
 
				TrackBits trackbits = u->track;
 
				if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
 
					/* Vehicle is inside a wormhole, v->track contains no useful value then. */
 
					trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile));
 
				}
 
				TryReserveRailTrack(u->tile, TrackBitsToTrack(trackbits));
 
@@ -4454,13 +4454,13 @@ bool Train::Tick()
 

	
 
		/* make sure vehicle wasn't deleted. */
 
		assert(Vehicle::Get(index) == this);
 
		assert(IsFrontEngine(this));
 

	
 
		return TrainLocoHandler(this, true);
 
	} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
 
	} else if (IsFreeWagon(this) && (this->vehstatus & VS_CRASHED)) {
 
		/* Delete flooded standalone wagon chain */
 
		if (++this->crash_anim_pos >= 4400) {
 
			delete this;
 
			return false;
 
		}
 
	}
0 comments (0 inline, 0 general)