1
0
Fork 0

(svn r19193) -Codechange: increase the maximum number of airport tiles to 256 and introduce AirportTileOverrideManager

release/1.1
yexo 2010-02-22 14:15:48 +00:00
parent 3530156e15
commit 683ad53d21
7 changed files with 90 additions and 19 deletions

View File

@ -16,12 +16,14 @@
#include "map_type.h" #include "map_type.h"
#include "date_type.h" #include "date_type.h"
/** Current limits for airports */ /** Some airport-related constants */
enum { enum {
MAX_TERMINALS = 10, ///< maximum number of terminals per airport MAX_TERMINALS = 10, ///< maximum number of terminals per airport
MAX_HELIPADS = 4, ///< maximum number of helipads per airport MAX_HELIPADS = 4, ///< maximum number of helipads per airport
MAX_ELEMENTS = 255, ///< maximum number of aircraft positions at airport MAX_ELEMENTS = 255, ///< maximum number of aircraft positions at airport
NUM_AIRPORTTILES = 74, ///< total number of airport tiles NUM_AIRPORTTILES = 256, ///< total number of airport tiles
NEW_AIRPORTTILE_OFFSET = 74, ///< offset of first newgrf airport tile
INVALID_AIRPORTTILE = NUM_AIRPORTTILES, ///< id for an invalid airport tile
}; };
/** Airport types */ /** Airport types */

View File

@ -19,6 +19,7 @@
#include "landscape_type.h" #include "landscape_type.h"
#include "strings_type.h" #include "strings_type.h"
#include "cargo_type.h" #include "cargo_type.h"
#include "newgrf_commons.h"
enum { enum {
CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
@ -94,15 +95,6 @@ struct IndustryTileTable {
IndustryGfx gfx; IndustryGfx gfx;
}; };
/** Data related to the handling of grf files. Common to both industry and industry tile */
struct GRFFileProps {
uint16 subst_id;
uint16 local_id; ///< id defined by the grf file for this industry
struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the industry
const struct GRFFile *grffile; ///< grf file that introduced this industry
uint16 override; ///< id of the entity been replaced by
};
/** /**
* Defines the data structure for constructing industry. * Defines the data structure for constructing industry.
*/ */

View File

@ -35,6 +35,7 @@
#include "newgrf_commons.h" #include "newgrf_commons.h"
#include "newgrf_townname.h" #include "newgrf_townname.h"
#include "newgrf_industries.h" #include "newgrf_industries.h"
#include "newgrf_airporttiles.h"
#include "rev.h" #include "rev.h"
#include "fios.h" #include "fios.h"
#include "rail.h" #include "rail.h"
@ -5768,6 +5769,9 @@ static void ResetNewGRFData()
ResetStationClasses(); ResetStationClasses();
ResetCustomStations(); ResetCustomStations();
/* Reset airport-related structures */
AirportTileSpec::ResetAirportTiles();
/* Reset canal sprite groups and flags */ /* Reset canal sprite groups and flags */
memset(_water_feature, 0, sizeof(_water_feature)); memset(_water_feature, 0, sizeof(_water_feature));

View File

@ -11,10 +11,15 @@
#include "stdafx.h" #include "stdafx.h"
#include "airport.h" #include "airport.h"
#include "newgrf.h"
#include "newgrf_airporttiles.h" #include "newgrf_airporttiles.h"
#include "table/airporttiles.h" #include "table/airporttiles.h"
AirportTileSpec AirportTileSpec::tiles[NUM_AIRPORTTILES];
AirportTileOverrideManager _airporttile_mngr(NEW_AIRPORTTILE_OFFSET, NUM_AIRPORTTILES, INVALID_AIRPORTTILE);
/** /**
* Retrieve airport tile spec for the given airport tile * Retrieve airport tile spec for the given airport tile
* @param gfx index of airport tile * @param gfx index of airport tile
@ -22,8 +27,43 @@
*/ */
/* static */ const AirportTileSpec *AirportTileSpec::Get(StationGfx gfx) /* static */ const AirportTileSpec *AirportTileSpec::Get(StationGfx gfx)
{ {
assert(gfx < NUM_AIRPORTTILES); assert(gfx < lengthof(AirportTileSpec::tiles));
extern const AirportTileSpec _origin_airporttile_specs[]; return &AirportTileSpec::tiles[gfx];
return &_origin_airporttile_specs[gfx]; }
/**
* This function initializes the tile array of AirportTileSpec
*/
void AirportTileSpec::ResetAirportTiles()
{
memset(&AirportTileSpec::tiles, 0, sizeof(AirportTileSpec::tiles));
memcpy(&AirportTileSpec::tiles, &_origin_airporttile_specs, sizeof(_origin_airporttile_specs));
/* Reset any overrides that have been set. */
_airporttile_mngr.ResetOverride();
}
void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
{
StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id);
if (airpt_id == invalid_ID) {
grfmsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
return;
}
memcpy(&AirportTileSpec::tiles[airpt_id], airpts, sizeof(*airpts));
/* Now add the overrides. */
for (int i = 0; i < max_offset; i++) {
AirportTileSpec *overridden_airpts = &AirportTileSpec::tiles[i];
if (entity_overrides[i] != airpts->grf_prop.local_id || grfid_overrides[i] != airpts->grf_prop.grffile->grfid) continue;
overridden_airpts->grf_prop.override = airpt_id;
overridden_airpts->enabled = false;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
}
} }

View File

@ -13,6 +13,8 @@
#define NEWGRF_AIRPORTTILES_H #define NEWGRF_AIRPORTTILES_H
#include "station_map.h" #include "station_map.h"
#include "newgrf_commons.h"
#include "airport.h"
/** /**
* Defines the data structure of each indivudual tile of an airport. * Defines the data structure of each indivudual tile of an airport.
@ -21,7 +23,17 @@ struct AirportTileSpec {
uint16 animation_info; ///< Information about the animation (is it looping, how many loops etc) uint16 animation_info; ///< Information about the animation (is it looping, how many loops etc)
uint8 animation_speed; ///< The speed of the animation uint8 animation_speed; ///< The speed of the animation
bool enabled; ///< entity still available (by default true). newgrf can disable it, though
GRFFileProps grf_prop; ///< properties related the the grf file
static const AirportTileSpec *Get(StationGfx gfx); static const AirportTileSpec *Get(StationGfx gfx);
static void ResetAirportTiles();
private:
static AirportTileSpec tiles[NUM_AIRPORTTILES];
friend void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts);
}; };
#endif /* NEWGRF_AIRPORTTILES_H */ #endif /* NEWGRF_AIRPORTTILES_H */

View File

@ -97,12 +97,33 @@ public:
void SetEntitySpec(const IndustryTileSpec *indts); void SetEntitySpec(const IndustryTileSpec *indts);
}; };
struct AirportTileSpec;
class AirportTileOverrideManager : public OverrideManagerBase {
protected:
virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
public:
AirportTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
OverrideManagerBase(offset, maximum, invalid) {}
void SetEntitySpec(const AirportTileSpec *ats);
};
extern HouseOverrideManager _house_mngr; extern HouseOverrideManager _house_mngr;
extern IndustryOverrideManager _industry_mngr; extern IndustryOverrideManager _industry_mngr;
extern IndustryTileOverrideManager _industile_mngr; extern IndustryTileOverrideManager _industile_mngr;
extern AirportTileOverrideManager _airporttile_mngr;
uint32 GetTerrainType(TileIndex tile); uint32 GetTerrainType(TileIndex tile);
TileIndex GetNearbyTile(byte parameter, TileIndex tile); TileIndex GetNearbyTile(byte parameter, TileIndex tile);
uint32 GetNearbyTileInformation(TileIndex tile); uint32 GetNearbyTileInformation(TileIndex tile);
/** Data related to the handling of grf files. */
struct GRFFileProps {
uint16 subst_id;
uint16 local_id; ///< id defined by the grf file for this entity
struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the entity
const struct GRFFile *grffile; ///< grf file that introduced this entity
uint16 override; ///< id of the entity been replaced by
};
#endif /* NEWGRF_COMMONS_H */ #endif /* NEWGRF_COMMONS_H */

View File

@ -13,7 +13,7 @@
#define AIRPORTTILES_H #define AIRPORTTILES_H
/** Writes all airport tile properties in the AirportTile struct */ /** Writes all airport tile properties in the AirportTile struct */
#define AT(num_frames, anim_speed) {(1 << 8) | num_frames, anim_speed} #define AT(num_frames, anim_speed) {(1 << 8) | num_frames, anim_speed, true, {INVALID_AIRPORTTILE, 0, NULL, NULL, INVALID_AIRPORTTILE}}
/** Writes an airport tile without animation in the AirportTile struct */ /** Writes an airport tile without animation in the AirportTile struct */
#define AT_NOANIM {0xFFFF, 2} #define AT_NOANIM {0xFFFF, 2}
@ -104,7 +104,7 @@ static const AirportTileSpec _origin_airporttile_specs[] = {
AT(4, 1), // APT_GRASS_FENCE_NE_FLAG_2 AT(4, 1), // APT_GRASS_FENCE_NE_FLAG_2
}; };
assert_compile(NUM_AIRPORTTILES == lengthof(_origin_airporttile_specs)); assert_compile(NEW_AIRPORTTILE_OFFSET == lengthof(_origin_airporttile_specs));
#undef AT_NOANIM #undef AT_NOANIM
#undef AT #undef AT