summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-28 17:36:28 +0000
committerrubidium <rubidium@openttd.org>2010-08-28 17:36:28 +0000
commit0a86eac2f1d8f646180cdd1d56f555e7956f7ebb (patch)
tree9785d9b5ee09781c32f3de801befeb6f498ed2eb
parent6348aa796471fd7f88772b4db4b0005707a59db8 (diff)
downloadopenttd-0a86eac2f1d8f646180cdd1d56f555e7956f7ebb.tar.xz
(svn r20651) -Codechange: add a function to determine whether an object is available and use it
-rw-r--r--src/newgrf_object.cpp11
-rw-r--r--src/newgrf_object.h6
-rw-r--r--src/object_cmd.cpp2
3 files changed, 18 insertions, 1 deletions
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index 30dd23df5..dc01d11d3 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -11,6 +11,7 @@
#include "stdafx.h"
#include "core/mem_func.hpp"
+#include "date_func.h"
#include "newgrf.h"
#include "newgrf_class_func.h"
#include "newgrf_object.h"
@@ -35,6 +36,16 @@ ObjectSpec _object_specs[NUM_OBJECTS];
return ObjectSpec::Get(GetObjectType(tile));
}
+bool ObjectSpec::IsAvailable() const
+{
+ return
+ this->enabled &&
+ _date > this->introduction_date &&
+ (_date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365) &&
+ HasBit(this->climate, _settings_game.game_creation.landscape) &&
+ (flags & (_game_mode != GM_EDITOR ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
+}
+
/** This function initialize the spec arrays of objects. */
void ResetObjects()
{
diff --git a/src/newgrf_object.h b/src/newgrf_object.h
index da2874c3c..5aaf5c286 100644
--- a/src/newgrf_object.h
+++ b/src/newgrf_object.h
@@ -70,6 +70,12 @@ struct ObjectSpec {
bool enabled; ///< Is this spec enabled?
/**
+ * Check whether the object is available at this time.
+ * @return true if it is available.
+ */
+ bool IsAvailable() const;
+
+ /**
* Get the cost for building a structure of this type.
* @return The cost for building.
*/
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index 564c9f9a6..660d32991 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -122,7 +122,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
ObjectType type = (ObjectType)GB(p1, 0, 8);
const ObjectSpec *spec = ObjectSpec::Get(type);
- if (!spec->enabled) return CMD_ERROR;
+ if (!spec->IsAvailable()) return CMD_ERROR;
if (spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT && (_game_mode != GM_EDITOR || _current_company != OWNER_NONE)) return CMD_ERROR;
if (spec->flags & OBJECT_FLAG_ONLY_IN_GAME && (_game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;