diff options
author | frosch <frosch@openttd.org> | 2012-08-21 19:53:08 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-08-21 19:53:08 +0000 |
commit | 9f9cad1ac9faa674fc6bafdf3df41c5ea3fa3c15 (patch) | |
tree | 4d57c47943c5a4dfd7d94b3692f311ccd3e30ba0 /src | |
parent | 4563c50c91e7a66d90fd35ecb84cebd2560beec5 (diff) | |
download | openttd-9f9cad1ac9faa674fc6bafdf3df41c5ea3fa3c15.tar.xz |
(svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 14 | ||||
-rw-r--r-- | src/script/api/script_engine.cpp | 7 | ||||
-rw-r--r-- | src/script/api/script_engine.hpp | 8 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 1500b9d89..541c025dd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -146,12 +146,12 @@ Engine::~Engine() } /** - * Checks whether the engine spec is properly initialised. + * Checks whether the engine is a valid (non-articulated part of an) engine. * @return true if enabled */ bool Engine::IsEnabled() const { - return this->info.string_id != STR_NEWGRF_INVALID_ENGINE; + return this->info.string_id != STR_NEWGRF_INVALID_ENGINE && HasBit(this->info.climates, _settings_game.game_creation.landscape); } /** @@ -998,8 +998,14 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company) /* check if it's an engine of specified type */ if (e->type != type) return false; - /* check if it's available */ - if (company != OWNER_DEITY && !HasBit(e->company_avail, company)) return false; + /* check if it's available ... */ + if (company == OWNER_DEITY) { + /* ... for any company (preview does not count) */ + if (!(e->flags & ENGINE_AVAILABLE) || e->company_avail == 0) return false; + } else { + /* ... for this company */ + if (!HasBit(e->company_avail, company)) return false; + } if (!e->IsEnabled()) return false; diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index adad559c5..a34d0910f 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -23,7 +23,12 @@ /* static */ bool ScriptEngine::IsValidEngine(EngineID engine_id) { const Engine *e = ::Engine::GetIfValid(engine_id); - return e != NULL && (::IsEngineBuildable(engine_id, e->type, ScriptObject::GetCompany()) || (ScriptObject::GetCompany() != OWNER_DEITY && ::Company::Get(ScriptObject::GetCompany())->group_all[e->type].num_engines[engine_id] > 0)); + if (e == NULL || !e->IsEnabled()) return false; + + /* AIs have only access to engines they can purchase or still have in use. + * Deity has access to all engined that will be or were available ever. */ + CompanyID company = ScriptObject::GetCompany(); + return company == OWNER_DEITY || ::IsEngineBuildable(engine_id, e->type, company) || ::Company::Get(company)->group_all[e->type].num_engines[engine_id] > 0; } /* static */ bool ScriptEngine::IsBuildable(EngineID engine_id) diff --git a/src/script/api/script_engine.hpp b/src/script/api/script_engine.hpp index c97707acd..20938ea66 100644 --- a/src/script/api/script_engine.hpp +++ b/src/script/api/script_engine.hpp @@ -23,15 +23,17 @@ class ScriptEngine : public ScriptObject { public: /** - * Checks whether the given engine type is valid. An engine is valid if you - * have at least one vehicle of this engine or it's currently buildable. + * Checks whether the given engine type is valid. + * An engine is valid for a company if it has at least one vehicle of this engine or it's currently buildable. + * @game Outside ScriptCompanyMode scope the function reports all engines valid, which were or will be available at some point. * @param engine_id The engine to check. * @return True if and only if the engine type is valid. */ static bool IsValidEngine(EngineID engine_id); /** - * Checks whether the given engine type is buildable by you. + * Checks whether the given engine type is buildable for a company. + * @game Outside ScriptCompanyMode scope the function checks whether the engine is currently buildable by all companies (no exclusive preview). * @param engine_id The engine to check. * @return True if and only if the engine type is buildable. */ |