Changeset - r15725:0c28e29aa5d4
[Not reviewed]
master
0 7 0
rubidium - 14 years ago 2010-08-07 21:10:57
rubidium@openttd.org
(svn r20402) -Codechange: rename the airport/station class id to something slightly more generic
7 files changed with 13 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_rail.cpp
Show inline comments
 
@@ -154,49 +154,49 @@
 
/* static */ bool AIRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
 
{
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW);
 
	EnforcePrecondition(false, num_platforms > 0 && num_platforms <= 0xFF);
 
	EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF);
 
	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 
	EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id));
 
	EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry));
 
	EnforcePrecondition(false, goal_industry   == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry   == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry));
 

	
 
	uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
 
	if (direction == RAILTRACK_NW_SE) p1 |= 1 << 4;
 
	if (station_id != AIStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
 

	
 
	const GRFFile *file;
 
	uint16 res = GetAiPurchaseCallbackResult(GSF_STATIONS, cargo_id, 0, source_industry, goal_industry, min(255, distance / 2), AICE_STATION_GET_STATION_ID, source_station ? 0 : 1, min(15, num_platforms) << 4 | min(15, platform_length), &file);
 
	uint32 p2 = (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
 
	if (res != CALLBACK_FAILED) {
 
		int index = 0;
 
		const StationSpec *spec = GetCustomStationSpecByGrf(file->grfid, res, &index);
 
		if (spec == NULL) {
 
			DEBUG(grf, 1, "%s returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
 
		} else {
 
			p2 |= spec->sclass | index << 8;
 
			p2 |= spec->cls_id | index << 8;
 
		}
 

	
 
	}
 
	return AIObject::DoCommand(tile, p1, p2, CMD_BUILD_RAIL_STATION);
 
}
 

	
 
/* static */ bool AIRail::BuildRailWaypoint(TileIndex tile)
 
{
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, IsRailTile(tile));
 
	EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE);
 
	EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
 

	
 
	return AIObject::DoCommand(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 4 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT);
 
}
 

	
 
/* static */ bool AIRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
 
{
 
	EnforcePrecondition(false, ::IsValidTile(tile));
 
	EnforcePrecondition(false, ::IsValidTile(tile2));
 

	
 
	return AIObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_WAYPOINT);
 
}
 

	
src/newgrf.cpp
Show inline comments
 
@@ -1130,49 +1130,49 @@ static ChangeInfoResult StationChangeInf
 
		return CIR_INVALID_ID;
 
	}
 

	
 
	/* Allocate station specs if necessary */
 
	if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT<StationSpec*>(MAX_STATIONS);
 

	
 
	for (int i = 0; i < numinfo; i++) {
 
		StationSpec *statspec = _cur_grffile->stations[stid + i];
 

	
 
		/* Check that the station we are modifying is defined. */
 
		if (statspec == NULL && prop != 0x08) {
 
			grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
 
			return CIR_INVALID_ID;
 
		}
 

	
 
		switch (prop) {
 
			case 0x08: { // Class ID
 
				StationSpec **spec = &_cur_grffile->stations[stid + i];
 

	
 
				/* Property 0x08 is special; it is where the station is allocated */
 
				if (*spec == NULL) *spec = CallocT<StationSpec>(1);
 

	
 
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
 
				uint32 classid = buf->ReadDWord();
 
				(*spec)->sclass = AllocateStationClass(BSWAP32(classid));
 
				(*spec)->cls_id = AllocateStationClass(BSWAP32(classid));
 
				break;
 
			}
 

	
 
			case 0x09: // Define sprite layout
 
				statspec->tiles = buf->ReadExtendedByte();
 
				statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
 
				statspec->copied_renderdata = false;
 

	
 
				for (uint t = 0; t < statspec->tiles; t++) {
 
					DrawTileSprites *dts = &statspec->renderdata[t];
 
					uint seq_count = 0;
 

	
 
					dts->seq = NULL;
 
					dts->ground.sprite = buf->ReadWord();
 
					dts->ground.pal = buf->ReadWord();
 
					if (dts->ground.sprite == 0) continue;
 
					if (HasBit(dts->ground.pal, 15)) {
 
						/* Use sprite from Action 1 */
 
						ClrBit(dts->ground.pal, 15);
 
						SetBit(dts->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE);
 
					}
 

	
 
					MapSpriteMappingRecolour(&dts->ground);
 

	
 
@@ -4249,50 +4249,50 @@ static void FeatureNewName(ByteReader *b
 
			case GSF_SHIPS:
 
			case GSF_AIRCRAFT:
 
				if (!generic) {
 
					Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, id, HasBit(_cur_grfconfig->flags, GCF_STATIC));
 
					if (e == NULL) break;
 
					StringID string = AddGRFString(_cur_grffile->grfid, e->index, lang, new_scheme, name, e->info.string_id);
 
					e->info.string_id = string;
 
				} else {
 
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
				}
 
				break;
 

	
 
			case GSF_INDUSTRIES: {
 
				AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
				break;
 
			}
 

	
 
			case GSF_HOUSES:
 
			default:
 
				switch (GB(id, 8, 8)) {
 
					case 0xC4: // Station class name
 
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
 
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
 
							StationClassID cls_id = _cur_grffile->stations[GB(id, 0, 8)]->cls_id;
 
							SetStationClassName(cls_id, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
 
						}
 
						break;
 

	
 
					case 0xC5: // Station name
 
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
						}
 
						break;
 

	
 
					case 0xC7: // Airporttile name
 
						if (_cur_grffile->airtspec == NULL || _cur_grffile->airtspec[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							_cur_grffile->airtspec[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 
						}
 
						break;
 

	
 
					case 0xC9: // House name
 
						if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
 
						} else {
 
							_cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
src/newgrf_airport.cpp
Show inline comments
 
@@ -132,50 +132,50 @@ StringID GetAirportClassName(AirportClas
 
uint GetNumAirportClasses()
 
{
 
	uint i;
 
	for (i = APC_BEGIN; i < APC_MAX && _airport_classes[i].id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Return the number of airports for the given airport class.
 
 * @param id Index of the airport class.
 
 * @return Number of airports in the class.
 
 */
 
uint GetNumAirportsInClass(AirportClassID id)
 
{
 
	assert(id < APC_MAX);
 
	return _airport_classes[id].airports;
 
}
 

	
 
/**
 
 * Tie an airport spec to its airport class.
 
 * @param statspec The airport spec.
 
 */
 
static void BindAirportSpecToClass(AirportSpec *as)
 
{
 
	assert(as->aclass < APC_MAX);
 
	AirportClass *airport_class = &_airport_classes[as->aclass];
 
	assert(as->cls_id < APC_MAX);
 
	AirportClass *airport_class = &_airport_classes[as->cls_id];
 

	
 
	int i = airport_class->airports++;
 
	airport_class->spec = ReallocT(airport_class->spec, airport_class->airports);
 

	
 
	airport_class->spec[i] = as;
 
}
 

	
 
/**
 
 * Tie all airportspecs to their class.
 
 */
 
void BindAirportSpecs()
 
{
 
	for (int i = 0; i < NUM_AIRPORTS; i++) {
 
		AirportSpec *as = AirportSpec::GetWithoutOverride(i);
 
		if (as->enabled) BindAirportSpecToClass(as);
 
	}
 
}
 

	
 

	
 
/**
 
 * Retrieve an airport spec from a class.
 
 * @param aclass Index of the airport class.
 
 * @param airport The airport index with the class.
 
 * @return The station spec.
src/newgrf_airport.h
Show inline comments
 
@@ -51,49 +51,49 @@ enum TTDPAirportType {
 
/** A list of all hangar tiles in an airport */
 
struct HangarTileTable {
 
	TileIndexDiffC ti; ///< Tile offset from the top-most airport tile.
 
	byte hangar_num;   ///< The hanger to which this tile belongs.
 
};
 

	
 
/**
 
 * Defines the data structure for an airport.
 
 */
 
struct AirportSpec {
 
	const struct AirportFTAClass *fsm;     ///< the finite statemachine for the default airports
 
	const AirportTileTable * const *table; ///< list of the tiles composing the airport
 
	Direction *rotation;                   ///< the rotation of each tiletable
 
	byte num_table;                        ///< number of elements in the table
 
	const HangarTileTable *depot_table;    ///< gives the position of the depots on the airports
 
	byte nof_depots;                       ///< the number of hangar tiles in this airport
 
	byte size_x;                           ///< size of airport in x direction
 
	byte size_y;                           ///< size of airport in y direction
 
	byte noise_level;                      ///< noise that this airport generates
 
	byte catchment;                        ///< catchment area of this airport
 
	Year min_year;                         ///< first year the airport is available
 
	Year max_year;                         ///< last year the airport is available
 
	StringID name;                         ///< name of this airport
 
	TTDPAirportType ttd_airport_type;      ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
 
	AirportClassID aclass;                 ///< the class to which this airport type belongs
 
	AirportClassID cls_id;                 ///< the class to which this airport type belongs
 
	SpriteID preview_sprite;               ///< preview sprite for this airport
 
	/* Newgrf data */
 
	bool enabled;                          ///< entity still avaible (by default true).newgrf can disable it, though
 
	struct GRFFileProps grf_prop;          ///< properties related the the grf file
 

	
 
	static const AirportSpec *Get(byte type);
 
	static AirportSpec *GetWithoutOverride(byte type);
 

	
 
	bool IsAvailable() const;
 

	
 
	static void ResetAirports();
 

	
 
	/** Get the index of this spec. */
 
	byte GetIndex() const
 
	{
 
		assert(this >= specs && this < endof(specs));
 
		return (byte)(this - specs);
 
	}
 

	
 
	static AirportSpec dummy;
 

	
 
private:
 
	static AirportSpec specs[NUM_AIRPORTS];
 
};
src/newgrf_station.cpp
Show inline comments
 
@@ -155,50 +155,50 @@ uint GetNumStationClasses()
 

	
 
/**
 
 * Return the number of stations for the given station class.
 
 * @param sclass Index of the station class.
 
 * @return Number of stations in the class.
 
 */
 
uint GetNumCustomStations(StationClassID sclass)
 
{
 
	assert(sclass < STAT_CLASS_MAX);
 
	return _station_classes[sclass].stations;
 
}
 

	
 
/**
 
 * Tie a station spec to its station class.
 
 * @param statspec The station spec.
 
 */
 
void SetCustomStationSpec(StationSpec *statspec)
 
{
 
	StationClass *station_class;
 
	int i;
 

	
 
	/* If the station has already been allocated, don't reallocate it. */
 
	if (statspec->allocated) return;
 

	
 
	assert(statspec->sclass < STAT_CLASS_MAX);
 
	station_class = &_station_classes[statspec->sclass];
 
	assert(statspec->cls_id < STAT_CLASS_MAX);
 
	station_class = &_station_classes[statspec->cls_id];
 

	
 
	i = station_class->stations++;
 
	station_class->spec = ReallocT(station_class->spec, station_class->stations);
 

	
 
	station_class->spec[i] = statspec;
 
	statspec->allocated = true;
 
}
 

	
 
/**
 
 * Retrieve a station spec from a class.
 
 * @param sclass Index of the station class.
 
 * @param station The station index with the class.
 
 * @return The station spec.
 
 */
 
const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
 
{
 
	assert(sclass < STAT_CLASS_MAX);
 
	if (station < _station_classes[sclass].stations) return _station_classes[sclass].spec[station];
 

	
 
	/* If the custom station isn't defined any more, then the GRF file
 
	 * probably was not loaded. */
 
	return NULL;
 
}
 

	
 
@@ -585,49 +585,49 @@ uint32 Waypoint::GetNewGRFVariable(const
 
	/* Handle cargo variables (deprecated) */
 
	if (variable >= 0x8C && variable <= 0xEC) {
 
		switch (GB(variable - 0x8C, 0, 3)) {
 
			case 3: return INITIAL_STATION_RATING;
 
			case 4: return INVALID_STATION;
 
			default: return 0;
 
		}
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
 

	
 
	*available = false;
 
	return UINT_MAX;
 
}
 

	
 
static const SpriteGroup *StationResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
 
{
 
	const BaseStation *bst = object->u.station.st;
 
	const StationSpec *statspec = object->u.station.statspec;
 
	uint set;
 

	
 
	uint cargo = 0;
 
	CargoID cargo_type = object->u.station.cargo_type;
 

	
 
	if (bst == NULL || statspec->sclass == STAT_CLASS_WAYP) {
 
	if (bst == NULL || statspec->cls_id == STAT_CLASS_WAYP) {
 
		return group->loading[0];
 
	}
 

	
 
	const Station *st = Station::From(bst);
 

	
 
	switch (cargo_type) {
 
		case CT_INVALID:
 
		case CT_DEFAULT_NA:
 
		case CT_PURCHASE:
 
			cargo = 0;
 
			break;
 

	
 
		case CT_DEFAULT:
 
			for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
 
				cargo += st->goods[cargo_type].cargo.Count();
 
			}
 
			break;
 

	
 
		default:
 
			cargo = st->goods[cargo_type].cargo.Count();
 
			break;
 
	}
 

	
 
	if (HasBit(statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h);
src/newgrf_station.h
Show inline comments
 
@@ -30,50 +30,50 @@ enum StationClassID {
 
typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
 
template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
 

	
 
/** Allow incrementing of StationClassID variables */
 
DECLARE_POSTFIX_INCREMENT(StationClassID)
 

	
 
enum StationSpecFlags {
 
	SSF_SEPARATE_GROUND,      ///< Use different sprite set for ground sprites.
 
	SSF_DIV_BY_STATION_SIZE,  ///< Divide cargo amount by station size.
 
	SSF_CB141_RANDOM_BITS,    ///< Callback 141 needs random bits.
 
	SSF_CUSTOM_FOUNDATIONS,   ///< Draw custom foundations.
 
	SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
 
};
 

	
 
/* Station layout for given dimensions - it is a two-dimensional array
 
 * where index is computed as (x * platforms) + platform. */
 
typedef byte *StationLayout;
 

	
 
/** Station specification. */
 
struct StationSpec {
 
	GRFFilePropsBase grf_prop; ///< Properties related the the grf file
 

	
 
	bool allocated; ///< Flag whether this station has been added to a station class list
 

	
 
	StationClassID sclass; ///< The class to which this spec belongs.
 
	StringID name; ///< Name of this station.
 
	StationClassID cls_id;    ///< The class to which this spec belongs.
 
	StringID name;            ///< Name of this station.
 

	
 
	/**
 
	 * Bitmask of number of platforms available for the station.
 
	 * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 platforms.
 
	 */
 
	byte disallowed_platforms;
 
	/**
 
	 * Bitmask of platform lengths available for the station.
 
	 * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 tiles long.
 
	 */
 
	byte disallowed_lengths;
 

	
 
	/**
 
	 * Number of tile layouts.
 
	 * A minimum of 8 is required is required for stations.
 
	 * 0-1 = plain platform
 
	 * 2-3 = platform with building
 
	 * 4-5 = platform with roof, left side
 
	 * 6-7 = platform with roof, right side
 
	 */
 
	uint tiles;
 
	DrawTileSprites *renderdata; ///< Array of tile layouts.
 
	bool copied_renderdata;
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -2780,49 +2780,49 @@ static void GetTileDesc_Station(TileInde
 
		if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
 
		if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
 

	
 
		/* Is there a mix of owners? */
 
		if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
 
				(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
 
			uint i = 1;
 
			if (road_owner != INVALID_OWNER) {
 
				td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
 
				td->owner[i] = road_owner;
 
				i++;
 
			}
 
			if (tram_owner != INVALID_OWNER) {
 
				td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
 
				td->owner[i] = tram_owner;
 
			}
 
		}
 
	}
 
	td->build_date = BaseStation::GetByTile(tile)->build_date;
 

	
 
	if (HasStationTileRail(tile)) {
 
		const StationSpec *spec = GetStationSpec(tile);
 

	
 
		if (spec != NULL) {
 
			td->station_class = GetStationClassName(spec->sclass);
 
			td->station_class = GetStationClassName(spec->cls_id);
 
			td->station_name  = spec->name;
 

	
 
			if (spec->grf_prop.grffile != NULL) {
 
				const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
 
				td->grf = gc->GetName();
 
			}
 
		}
 

	
 
		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
 
		td->rail_speed = rti->max_speed;
 
	}
 

	
 
	if (IsAirport(tile)) {
 
		const AirportTileSpec *ats = AirportTileSpec::Get(GetAirportGfx(tile));
 
		td->airport_tile_name = ats->name;
 

	
 
		if (ats->grf_prop.grffile != NULL) {
 
			const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
 
			td->grf = gc->GetName();
 
		}
 
	}
 

	
 
	StringID str;
 
	switch (GetStationType(tile)) {
0 comments (0 inline, 0 general)