summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_engine.cpp3
-rw-r--r--src/autoreplace_cmd.cpp2
-rw-r--r--src/engine.cpp23
-rw-r--r--src/engine_base.h5
-rw-r--r--src/vehicle.cpp4
5 files changed, 15 insertions, 22 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index 5e0ac5b4a..64c85de04 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -15,7 +15,8 @@
/* static */ bool AIEngine::IsValidEngine(EngineID engine_id)
{
- return ::IsEngineIndex(engine_id) && HasBit(::Engine::Get(engine_id)->company_avail, _current_company);
+ const Engine *e = ::Engine::GetIfValid(engine_id);
+ return e != NULL && HasBit(e->company_avail, _current_company);
}
/* static */ char *AIEngine::GetName(EngineID engine_id)
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 066f6bac7..2b035cbfa 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -42,7 +42,7 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
{
/* First we make sure that it's a valid type the user requested
* check that it's an engine that is in the engine array */
- if (!IsEngineIndex(from) || !IsEngineIndex(to)) return false;
+ if (!Engine::IsValidID(from) || !Engine::IsValidID(to)) return false;
/* we can't replace an engine into itself (that would be autorenew) */
if (from == to) return false;
diff --git a/src/engine.cpp b/src/engine.cpp
index 0f641d016..24918c11c 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -620,11 +620,8 @@ void EnginesDailyLoop()
*/
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Engine *e;
-
- if (!IsEngineIndex(p1)) return CMD_ERROR;
- e = Engine::Get(p1);
- if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
+ Engine *e = Engine::GetIfValid(p1);
+ if (e == NULL || GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
@@ -734,7 +731,8 @@ static bool IsUniqueEngineName(const char *name)
*/
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsEngineIndex(p1)) return CMD_ERROR;
+ Engine *e = Engine::GetIfValid(p1);
+ if (e == NULL) return CMD_ERROR;
bool reset = StrEmpty(text);
@@ -744,7 +742,6 @@ CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
if (flags & DC_EXEC) {
- Engine *e = Engine::Get(p1);
free(e->name);
if (reset) {
@@ -769,10 +766,10 @@ CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
*/
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
{
- /* check if it's an engine that is in the engine array */
- if (!IsEngineIndex(engine)) return false;
+ const Engine *e = Engine::GetIfValid(engine);
- const Engine *e = Engine::Get(engine);
+ /* check if it's an engine that is in the engine array */
+ if (e == NULL) return false;
/* check if it's an engine of specified type */
if (e->type != type) return false;
@@ -797,10 +794,10 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
*/
bool IsEngineRefittable(EngineID engine)
{
- /* check if it's an engine that is in the engine array */
- if (!IsEngineIndex(engine)) return false;
+ const Engine *e = Engine::GetIfValid(engine);
- const Engine *e = Engine::Get(engine);
+ /* check if it's an engine that is in the engine array */
+ if (e == NULL) return false;
if (e->type == VEH_SHIP && !e->u.ship.refittable) return false;
diff --git a/src/engine_base.h b/src/engine_base.h
index 0f6d70f90..8e71c573d 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -82,11 +82,6 @@ struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
extern EngineOverrideManager _engine_mngr;
-static inline bool IsEngineIndex(uint index)
-{
- return index < Engine::GetPoolSize();
-}
-
#define FOR_ALL_ENGINES_FROM(e, start) for (e = Engine::Get(start); e != NULL; e = (e->index + 1U < Engine::GetPoolSize()) ? Engine::Get(e->index + 1U) : NULL) if (e->IsValid())
#define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 94842b383..e449a03f5 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1747,8 +1747,8 @@ void VehiclesYearlyLoop()
*/
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
{
- assert(IsEngineIndex(engine_type));
- const Engine *e = Engine::Get(engine_type);
+ const Engine *e = Engine::GetIfValid(engine_type);
+ assert(e != NULL);
switch (e->type) {
case VEH_TRAIN: