Changeset - r12236:ae676539361d
[Not reviewed]
master
0 4 0
smatz - 15 years ago 2009-06-25 23:49:59
smatz@openttd.org
(svn r16661) -Codechange: move definition of few very short functions to header files
4 files changed with 29 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/cargotype.cpp
Show inline comments
 
@@ -4,26 +4,24 @@
 

	
 
#include "stdafx.h"
 
#include "newgrf_cargo.h"
 
#include "cargotype.h"
 
#include "core/bitmath_func.hpp"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "table/cargo_const.h"
 

	
 
CargoSpec _cargo[NUM_CARGO];
 

	
 
static const byte INVALID_CARGO = 0xFF;
 

	
 
/* Bitmask of cargo types available */
 
uint32 _cargo_mask;
 

	
 

	
 
void SetupCargoForClimate(LandscapeID l)
 
{
 
	assert(l < lengthof(_default_climate_cargo));
 

	
 
	/* Reset and disable all cargo types */
 
	memset(_cargo, 0, sizeof(_cargo));
 
	for (CargoID i = 0; i < lengthof(_cargo); i++) _cargo[i].bitnum = INVALID_CARGO;
 

	
 
@@ -46,37 +44,24 @@ void SetupCargoForClimate(LandscapeID l)
 
			if (_default_cargo[j].label == cl) {
 
				_cargo[i] = _default_cargo[j];
 

	
 
				/* Populate the available cargo mask */
 
				SetBit(_cargo_mask, i);
 
				break;
 
			}
 
		}
 
	}
 
}
 

	
 

	
 
const CargoSpec *GetCargo(CargoID c)
 
{
 
	assert(c < lengthof(_cargo));
 
	return &_cargo[c];
 
}
 

	
 

	
 
bool CargoSpec::IsValid() const
 
{
 
	return bitnum != INVALID_CARGO;
 
}
 

	
 

	
 
CargoID GetCargoIDByLabel(CargoLabel cl)
 
{
 
	for (CargoID c = 0; c < lengthof(_cargo); c++) {
 
		if (_cargo[c].bitnum == INVALID_CARGO) continue;
 
		if (_cargo[c].label == cl) return c;
 
	}
 

	
 
	/* No matching label was found, so it is invalid */
 
	return CT_INVALID;
 
}
 

	
 

	
src/cargotype.h
Show inline comments
 
@@ -13,24 +13,26 @@
 
typedef uint32 CargoLabel;
 

	
 
enum TownEffect {
 
	TE_NONE,
 
	TE_PASSENGERS,
 
	TE_MAIL,
 
	TE_GOODS,
 
	TE_WATER,
 
	TE_FOOD,
 
};
 

	
 

	
 
static const byte INVALID_CARGO = 0xFF;
 

	
 
struct CargoSpec {
 
	uint8 bitnum;
 
	CargoLabel label;
 
	uint8 legend_colour;
 
	uint8 rating_colour;
 
	uint8 weight;
 
	uint16 initial_payment;
 
	uint8 transit_days[2];
 

	
 
	bool is_freight;
 
	TownEffect town_effect; ///< The effect this cargo type has on towns
 
	uint16 multipliertowngrowth;
 
@@ -39,37 +41,45 @@ struct CargoSpec {
 
	StringID name;
 
	StringID name_single;
 
	StringID units_volume;
 
	StringID quantifier;
 
	StringID abbrev;
 

	
 
	SpriteID sprite;
 

	
 
	uint16 classes;
 
	const struct GRFFile *grffile;   ///< NewGRF where 'group' belongs to
 
	const struct SpriteGroup *group;
 

	
 
	bool IsValid() const;
 
	bool IsValid() const
 
	{
 
		return this->bitnum != INVALID_CARGO;
 
	}
 
};
 

	
 

	
 
extern uint32 _cargo_mask;
 
extern CargoSpec _cargo[NUM_CARGO];
 

	
 

	
 
/* Set up the default cargo types for the given landscape type */
 
void SetupCargoForClimate(LandscapeID l);
 
/* Retrieve cargo details for the given cargo ID */
 
const CargoSpec *GetCargo(CargoID c);
 
/* Get the cargo icon for a given cargo ID */
 
SpriteID GetCargoSprite(CargoID i);
 
/* Get the cargo ID with the cargo label */
 
CargoID GetCargoIDByLabel(CargoLabel cl);
 
CargoID GetCargoIDByBitnum(uint8 bitnum);
 

	
 
/* Retrieve cargo details for the given cargo ID */
 
static inline const CargoSpec *GetCargo(CargoID c)
 
{
 
	assert(c < lengthof(_cargo));
 
	return &_cargo[c];
 
}
 

	
 

	
 
static inline bool IsCargoInClass(CargoID c, uint16 cc)
 
{
 
	return (GetCargo(c)->classes & cc) != 0;
 
}
 

	
 

	
 
#endif /* CARGOTYPE_H */
src/station.cpp
Show inline comments
 
@@ -177,29 +177,24 @@ void Station::MarkTilesDirty(bool cargo_
 

	
 
	for (h = 0; h < trainst_h; h++) {
 
		for (w = 0; w < trainst_w; w++) {
 
			if (TileBelongsToRailStation(tile)) {
 
				MarkTileDirtyByTile(tile);
 
			}
 
			tile += TileDiffXY(1, 0);
 
		}
 
		tile += TileDiffXY(-w, 1);
 
	}
 
}
 

	
 
bool Station::TileBelongsToRailStation(TileIndex tile) const
 
{
 
	return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
 
}
 

	
 
/** Obtain the length of a platform
 
 * @pre tile must be a railway station tile
 
 * @param tile A tile that contains the platform in question
 
 * @return The length of the platform
 
 */
 
uint Station::GetPlatformLength(TileIndex tile) const
 
{
 
	TileIndex t;
 
	TileIndexDiff delta;
 
	uint len = 0;
 
	assert(TileBelongsToRailStation(tile));
 

	
 
@@ -232,32 +227,24 @@ uint Station::GetPlatformLength(TileInde
 
	uint length = 0;
 
	assert(IsRailwayStationTile(tile));
 
	assert(dir < DIAGDIR_END);
 

	
 
	do {
 
		length ++;
 
		tile += TileOffsByDiagDir(dir);
 
	} while (IsCompatibleTrainStationTile(tile, start_tile));
 

	
 
	return length;
 
}
 

	
 
/** Determines whether a station is a buoy only.
 
 * @todo Ditch this encoding of buoys
 
 */
 
bool Station::IsBuoy() const
 
{
 
	return (had_vehicle_of_type & HVOT_BUOY) != 0;
 
}
 

	
 
/** Determines the catchment radius of the station
 
 * @return The radius
 
 */
 
uint Station::GetCatchmentRadius() const
 
{
 
	uint ret = CA_NONE;
 

	
 
	if (_settings_game.station.modified_catchment) {
 
		if (this->bus_stops    != NULL)         ret = max<uint>(ret, CA_BUS);
 
		if (this->truck_stops  != NULL)         ret = max<uint>(ret, CA_TRUCK);
 
		if (this->train_tile   != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
 
		if (this->dock_tile    != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
src/station_base.h
Show inline comments
 
@@ -151,32 +151,44 @@ public:
 
	 * Mark the sign of a station dirty for repaint.
 
	 *
 
	 * @ingroup dirty
 
	 */
 
	void MarkDirty() const;
 

	
 
	/**
 
	 * Marks the tiles of the station as dirty.
 
	 *
 
	 * @ingroup dirty
 
	 */
 
	void MarkTilesDirty(bool cargo_change) const;
 
	bool TileBelongsToRailStation(TileIndex tile) const;
 

	
 
	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
 
	uint GetPlatformLength(TileIndex tile) const;
 
	bool IsBuoy() const;
 

	
 
	void RecomputeIndustriesNear();
 
	static void RecomputeIndustriesNearForAll();
 

	
 
	uint GetCatchmentRadius() const;
 

	
 
	FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
 
	{
 
		return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
 
	}
 

	
 
	/**
 
	 * Determines whether a station is a buoy only.
 
	 * @todo Ditch this encoding of buoys
 
	 */
 
	FORCEINLINE bool IsBuoy() const
 
	{
 
		return (this->had_vehicle_of_type & HVOT_BUOY) != 0;
 
	}
 

	
 
	static FORCEINLINE Station *GetByTile(TileIndex tile)
 
	{
 
		return Station::Get(GetStationIndex(tile));
 
	}
 
};
 

	
 
#define FOR_ALL_STATIONS_FROM(var, start) FOR_ALL_ITEMS_FROM(Station, station_index, var, start)
 
#define FOR_ALL_STATIONS(var) FOR_ALL_STATIONS_FROM(var, 0)
 

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