diff options
author | frosch <frosch@openttd.org> | 2009-03-08 18:08:30 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-03-08 18:08:30 +0000 |
commit | fd1609fd11d0e9c496218c860076da5fc113a6d7 (patch) | |
tree | 5ad8e8c67ee66d5676d112da6b1ac61fc2998e91 | |
parent | 959c297fb90d7ed0baf7fbd66d2a21a1b3c807ae (diff) | |
download | openttd-fd1609fd11d0e9c496218c860076da5fc113a6d7.tar.xz |
(svn r15646) -Fix: Be lenient on users who do stupid things like loading newgrfs statically, which modify engine names, while dynamic_engines is enabled or the to be modified engine is not (yet) present.
-rw-r--r-- | src/newgrf.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index d85fd610d..93bed06e2 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -324,7 +324,15 @@ static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid) grfmsg(5, "SetNewGRFOverride: Added override of 0x%X to 0x%X", BSWAP32(source_grfid), BSWAP32(target_grfid)); } -static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id) +/** + * Returns the engine associated to a certain internal_id, resp. allocates it. + * @param file NewGRF that wants to change the engine + * @param type Vehicle type + * @param internal_id Engine ID inside the NewGRF + * @param static_access If the engine is not present, return NULL instead of allocating a new engine. (Used for static Action 0x04) + * @return The requested engine + */ +static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id, bool static_access = false) { /* Hack for add-on GRFs that need to modify another GRF's engines. This lets * them use the same engine slots. */ @@ -359,12 +367,16 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern } /* Reserve the engine slot */ - EngineIDMapping *eid = _engine_mngr.Get(engine); - eid->grfid = scope_grfid; // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation + if (!static_access) { + EngineIDMapping *eid = _engine_mngr.Get(engine); + eid->grfid = scope_grfid; // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation + } return e; } + if (static_access) return NULL; + uint engine_pool_size = GetEnginePoolSize(); /* ... it's not, so create a new one based off an existing engine */ @@ -3443,7 +3455,8 @@ static void FeatureNewName(byte *buf, size_t len) case GSF_SHIP: case GSF_AIRCRAFT: if (!generic) { - Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, id); + 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 { |