summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2013-10-17 21:37:25 +0000
committerplanetmaker <planetmaker@openttd.org>2013-10-17 21:37:25 +0000
commit2ee9a2b5e70bb52ae08d8d18d94b7e082a12a63f (patch)
tree4aa8cc9e07c0c324fc198a6e3b6a6b7d72d218b7
parent547b1fba45cb7a877cd4966a6854aeebffef0c71 (diff)
downloadopenttd-2ee9a2b5e70bb52ae08d8d18d94b7e082a12a63f.tar.xz
(svn r25875) -Change: In scenario editor allow to build all objects which were available at any point in the past to support building scenarios with historic items
-rw-r--r--src/newgrf_object.cpp14
-rw-r--r--src/newgrf_object.h1
-rw-r--r--src/object_cmd.cpp3
3 files changed, 15 insertions, 3 deletions
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index 8eaff1385..57468d7c7 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -13,6 +13,7 @@
#include "company_base.h"
#include "company_func.h"
#include "debug.h"
+#include "genworld.h"
#include "newgrf_class_func.h"
#include "newgrf_object.h"
#include "newgrf_sound.h"
@@ -58,7 +59,16 @@ ObjectSpec _object_specs[NUM_OBJECTS];
bool ObjectSpec::IsEverAvailable() const
{
return this->enabled && HasBit(this->climate, _settings_game.game_creation.landscape) &&
- (this->flags & (_game_mode != GM_EDITOR ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
+ (this->flags & ((_game_mode != GM_EDITOR && !_generating_world) ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
+}
+
+/**
+ * Check whether the object was available at some point in the past or present in this game with the current game mode.
+ * @return true if it was ever or is available.
+ */
+bool ObjectSpec::WasEverAvailable() const
+{
+ return this->IsEverAvailable() && _date > this->introduction_date;
}
/**
@@ -67,7 +77,7 @@ bool ObjectSpec::IsEverAvailable() const
*/
bool ObjectSpec::IsAvailable() const
{
- return this->IsEverAvailable() && _date > this->introduction_date &&
+ return this->WasEverAvailable() &&
(_date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365);
}
diff --git a/src/newgrf_object.h b/src/newgrf_object.h
index 36b7d420e..660ad76aa 100644
--- a/src/newgrf_object.h
+++ b/src/newgrf_object.h
@@ -90,6 +90,7 @@ struct ObjectSpec {
Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
bool IsEverAvailable() const;
+ bool WasEverAvailable() const;
bool IsAvailable() const;
uint Index() const;
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index 3aabb3471..7c42dce78 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -209,7 +209,8 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (type >= NUM_OBJECTS) return CMD_ERROR;
uint8 view = GB(p2, 0, 2);
const ObjectSpec *spec = ObjectSpec::Get(type);
- if (!spec->IsAvailable()) return CMD_ERROR;
+ if (_game_mode == GM_NORMAL && !spec->IsAvailable()) return CMD_ERROR;
+ if (_game_mode == GM_EDITOR && !spec->WasEverAvailable()) 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;