summaryrefslogtreecommitdiff
path: root/src/newgrf_commons.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-07-11 16:32:19 +0000
committermichi_cc <michi_cc@openttd.org>2011-07-11 16:32:19 +0000
commit206ff68e65b1a679e96f5064e3595a183327ef6b (patch)
treeb8e692a54a0d9cf28150a6e2efb1a3c78ceff8b3 /src/newgrf_commons.cpp
parent1e855be4924d113d1e1eefd6345f174a86a9ef0b (diff)
downloadopenttd-206ff68e65b1a679e96f5064e3595a183327ef6b.tar.xz
(svn r22656) -Codechange: Deduplicate the custom error message of the industry shape and location callbacks.
Diffstat (limited to 'src/newgrf_commons.cpp')
-rw-r--r--src/newgrf_commons.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 8a50786fb..0c6cef3eb 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -24,6 +24,9 @@
#include "newgrf_object.h"
#include "genworld.h"
#include "newgrf_spritegroup.h"
+#include "newgrf_text.h"
+
+#include "table/strings.h"
/**
* Constructor of generic class
@@ -446,6 +449,30 @@ uint32 GetNearbyTileInformation(TileIndex tile)
return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
}
+/**
+ * Get the error message from a shape/location/slope check callback result.
+ * @param cb_res Callback result to translate. If bit 10 is set this is a standard error message, otherwise a NewGRF provided string.
+ * @param grfid grfID to use to resolve a custom error message.
+ * @param default_error Error message to use for the generic error.
+ * @return CommandCost indicating success or the error message.
+ */
+CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, uint32 grfid, StringID default_error)
+{
+ CommandCost res;
+ switch (cb_res) {
+ case 0x400: return res; // No error.
+ case 0x401: res = CommandCost(default_error); break;
+ case 0x402: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST); break;
+ case 0x403: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT); break;
+ default: res = CommandCost(GetGRFStringID(grfid, 0xD000 + cb_res)); break;
+ }
+
+ /* Copy some parameters from the registers to the error message text ref. stack */
+ res.UseTextRefStack(4);
+
+ return res;
+}
+
/* static */ SmallVector<DrawTileSeqStruct, 8> NewGRFSpriteLayout::result_seq;
/**