(svn r19457) -Codechange: introduce AirportOverrideManager to keep track of airports if a newgrf can't be found

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
yexo 14 years ago
parent a99a7e7a37
commit 38f4cb6469

@ -2083,6 +2083,10 @@
RelativePath=".\..\src\saveload\ai_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\airport_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\animated_tile_sl.cpp"
>

@ -2080,6 +2080,10 @@
RelativePath=".\..\src\saveload\ai_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\airport_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\animated_tile_sl.cpp"
>

@ -450,6 +450,7 @@ waypoint_cmd.cpp
# Save/Load handlers
saveload/afterload.cpp
saveload/ai_sl.cpp
saveload/airport_sl.cpp
saveload/animated_tile_sl.cpp
saveload/autoreplace_sl.cpp
saveload/cargopacket_sl.cpp

@ -39,6 +39,7 @@ enum {
AT_OILRIG = 9,
NEW_AIRPORT_OFFSET = 10,
NUM_AIRPORTS = 128,
AT_INVALID = 254,
AT_DUMMY = 255
};

@ -6258,6 +6258,15 @@ static void FinaliseAirportsArray()
{
const GRFFile * const *end = _grf_files.End();
for (GRFFile **file = _grf_files.Begin(); file != end; file++) {
AirportSpec **&airportspec = (*file)->airportspec;
if (airportspec != NULL) {
for (int i = 0; i < NUM_AIRPORTS; i++) {
if (airportspec[i] != NULL && airportspec[i]->enabled) {
_airport_mngr.SetEntitySpec(airportspec[i]);
}
}
}
AirportTileSpec **&airporttilespec = (*file)->airtspec;
if (airporttilespec != NULL) {
for (int i = 0; i < NUM_AIRPORTTILES; i++) {

@ -104,6 +104,7 @@ struct GRFFile {
HouseSpec **housespec;
IndustrySpec **industryspec;
IndustryTileSpec **indtspec;
struct AirportSpec **airportspec;
struct AirportTileSpec **airtspec;
uint32 param[0x80];

@ -16,11 +16,14 @@
#include "settings_type.h"
#include "core/alloc_type.hpp"
#include "newgrf.h"
#include "newgrf_commons.h"
#include "table/strings.h"
static AirportClass _airport_classes[APC_MAX];
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false};
AirportOverrideManager _airport_mngr(NEW_AIRPORT_OFFSET, NUM_AIRPORTS, AT_INVALID);
AirportSpec AirportSpec::dummy = {NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, STR_NULL, ATP_TTDP_LARGE, APC_BEGIN, false, {AT_INVALID, 0, NULL, NULL, AT_INVALID}};
AirportSpec AirportSpec::specs[NUM_AIRPORTS];
@ -33,7 +36,14 @@ AirportSpec AirportSpec::specs[NUM_AIRPORTS];
/* static */ const AirportSpec *AirportSpec::Get(byte type)
{
assert(type < lengthof(AirportSpec::specs));
return &AirportSpec::specs[type];
const AirportSpec *as = &AirportSpec::specs[type];
if (type >= NEW_AIRPORT_OFFSET && !as->enabled) {
byte subst_id = _airport_mngr.GetSubstituteID(type);
if (subst_id == AT_INVALID) return as;
as = &AirportSpec::specs[subst_id];
}
if (as->grf_prop.override != AT_INVALID) return &AirportSpec::specs[as->grf_prop.override];
return as;
}
/**
@ -64,6 +74,8 @@ void AirportSpec::ResetAirports()
extern const AirportSpec _origin_airport_specs[];
memset(&AirportSpec::specs, 0, sizeof(AirportSpec::specs));
memcpy(&AirportSpec::specs, &_origin_airport_specs, sizeof(AirportSpec) * NEW_AIRPORT_OFFSET);
_airport_mngr.ResetOverride();
}
/**
@ -203,3 +215,27 @@ void ResetAirportClasses()
SetAirportClassName(id, STR_AIRPORT_CLASS_HELIPORTS);
}
void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
{
byte airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id);
if (airport_id == invalid_ID) {
grfmsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
return;
}
memcpy(AirportSpec::GetWithoutOverride(airport_id), as, sizeof(*as));
/* Now add the overrides. */
for (int i = 0; i < max_offset; i++) {
AirportSpec *overridden_as = AirportSpec::GetWithoutOverride(i);
if (entity_overrides[i] != as->grf_prop.local_id || grfid_overrides[i] != as->grf_prop.grffile->grfid) continue;
overridden_as->grf_prop.override = airport_id;
overridden_as->enabled = false;
entity_overrides[i] = invalid_ID;
grfid_overrides[i] = 0;
}
}

@ -15,6 +15,7 @@
#include "date_type.h"
#include "map_type.h"
#include "strings_type.h"
#include "newgrf_commons.h"
/* Copy from station_map.h */
typedef byte StationGfx;
@ -65,6 +66,7 @@ struct AirportSpec {
AirportClassID aclass; ///< the class to which this airport type belongs
/* Newgrf data */
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
GRFFileProps grf_prop; ///< properties related the the grf file
static const AirportSpec *Get(byte type);
static AirportSpec *GetWithoutOverride(byte type);

@ -97,6 +97,15 @@ public:
void SetEntitySpec(const IndustryTileSpec *indts);
};
struct AirportSpec;
class AirportOverrideManager : public OverrideManagerBase {
public:
AirportOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
OverrideManagerBase(offset, maximum, invalid) {}
void SetEntitySpec(AirportSpec *inds);
};
struct AirportTileSpec;
class AirportTileOverrideManager : public OverrideManagerBase {
protected:
@ -111,6 +120,7 @@ public:
extern HouseOverrideManager _house_mngr;
extern IndustryOverrideManager _industry_mngr;
extern IndustryTileOverrideManager _industile_mngr;
extern AirportOverrideManager _airport_mngr;
extern AirportTileOverrideManager _airporttile_mngr;
uint32 GetTerrainType(TileIndex tile);

@ -313,6 +313,7 @@ static void InitializeDynamicVariables()
_house_mngr.ResetMapping();
_industry_mngr.ResetMapping();
_industile_mngr.ResetMapping();
_airport_mngr.ResetMapping();
_airporttile_mngr.ResetMapping();
}

@ -128,6 +128,7 @@ extern const ChunkHandler _group_chunk_handlers[];
extern const ChunkHandler _cargopacket_chunk_handlers[];
extern const ChunkHandler _autoreplace_chunk_handlers[];
extern const ChunkHandler _labelmaps_chunk_handlers[];
extern const ChunkHandler _airport_chunk_handlers[];
static const ChunkHandler * const _chunk_handlers[] = {
_gamelog_chunk_handlers,
@ -155,6 +156,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_cargopacket_chunk_handlers,
_autoreplace_chunk_handlers,
_labelmaps_chunk_handlers,
_airport_chunk_handlers,
NULL,
};

@ -378,7 +378,7 @@ static AirportTileTable *_tile_table_helistation[] = {
/** General AirportSpec definition. */
#define AS_GENERIC(fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, enabled) \
{fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled}
{fsm, att, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled, {AT_INVALID, 0, NULL, NULL, AT_INVALID}}
/** AirportSpec definition for airports without any depot. */
#define AS_ND(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id, name) \

Loading…
Cancel
Save