summaryrefslogtreecommitdiff
path: root/src/news_gui.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 21:01:03 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 21:01:03 +0000
commite0ffe4faf268298f3a20427cd87462c70e3d9bc2 (patch)
treeb2958b45d880e8ed5fe40f2a176652ef072ea5a6 /src/news_gui.cpp
parentad48ab923764087bf66153d1c26ed0eb05a19989 (diff)
downloadopenttd-e0ffe4faf268298f3a20427cd87462c70e3d9bc2.tar.xz
(svn r23627) -Add: ScriptNews::Create, to create custom news messages (GameScript only)
Diffstat (limited to 'src/news_gui.cpp')
-rw-r--r--src/news_gui.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index a20be0f9f..04347844c 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -31,6 +31,8 @@
#include "engine_base.h"
#include "engine_gui.h"
#include "core/geometry_func.hpp"
+#include "command_func.h"
+#include "company_base.h"
#include "widgets/news_widget.h"
@@ -707,6 +709,70 @@ void AddNewsItem(StringID string, NewsSubtype subtype, NewsReferenceType reftype
SetWindowDirty(WC_MESSAGE_HISTORY, 0);
}
+/**
+ * Create a new custom news item.
+ * @param tile unused
+ * @param flags type of operation
+ * @param p1 various bitstuffed elements
+ * - p1 = (bit 0 - 7) - NewsSubtype of the message.
+ * - p1 = (bit 8 - 15) - NewsReferenceType of first reference.
+ * - p1 = (bit 16 - 23) - Company this news message is for.
+ * @param p2 First reference of the news message.
+ * @param text The text of the news message.
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+
+ NewsSubtype subtype = (NewsSubtype)GB(p1, 0, 8);
+ NewsReferenceType reftype1 = (NewsReferenceType)GB(p1, 8, 8);
+ CompanyID company = (CompanyID)GB(p1, 16, 8);
+
+ if (company != INVALID_OWNER && !Company::IsValidID(company)) return CMD_ERROR;
+ if (subtype >= NS_END) return CMD_ERROR;
+ if (StrEmpty(text)) return CMD_ERROR;
+
+ switch (reftype1) {
+ case NR_NONE: break;
+ case NR_TILE:
+ if (!IsValidTile(p2)) return CMD_ERROR;
+ break;
+
+ case NR_VEHICLE:
+ if (!Vehicle::IsValidID(p2)) return CMD_ERROR;
+ break;
+
+ case NR_STATION:
+ if (!Station::IsValidID(p2)) return CMD_ERROR;
+ break;
+
+ case NR_INDUSTRY:
+ if (!Industry::IsValidID(p2)) return CMD_ERROR;
+ break;
+
+ case NR_TOWN:
+ if (!Town::IsValidID(p2)) return CMD_ERROR;
+ break;
+
+ case NR_ENGINE:
+ if (!Engine::IsValidID(p2)) return CMD_ERROR;
+ break;
+
+ default: return CMD_ERROR;
+ }
+
+ if (company != INVALID_OWNER && company != _local_company) return CommandCost();
+
+ if (flags & DC_EXEC) {
+ char *news = strdup(text);
+ SetDParamStr(0, news);
+ AddNewsItem(STR_NEWS_CUSTOM_ITEM, subtype, reftype1, p2, NR_NONE, UINT32_MAX, news);
+ }
+
+ return CommandCost();
+}
+
/** Delete a news item from the queue */
static void DeleteNewsItem(NewsItem *ni)
{