summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 20:59:29 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 20:59:29 +0000
commite7cd301d3c9990b4ef9f0748789bb5e0318c0d24 (patch)
tree6be6c3a41b29a52a74a289293a012e7167f48884
parentafcf07ac8a0d5adede1b412600042a9f3b482648 (diff)
downloadopenttd-e7cd301d3c9990b4ef9f0748789bb5e0318c0d24.tar.xz
(svn r23621) -Add: allow manipulation of signs via GameScripts
-rw-r--r--src/command.cpp4
-rw-r--r--src/game/game_instance.cpp2
-rw-r--r--src/script/api/game/game_sign.hpp.sq39
-rw-r--r--src/script/api/script_sign.cpp2
-rw-r--r--src/script/api/script_sign.hpp2
-rw-r--r--src/signs_cmd.cpp1
-rw-r--r--src/signs_gui.cpp17
-rw-r--r--src/viewport.cpp9
8 files changed, 60 insertions, 16 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 636fdfcb1..a209f546e 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -253,8 +253,8 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION
DEF_CMD(CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT
- DEF_CMD(CmdPlaceSign, 0, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
- DEF_CMD(CmdRenameSign, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
+ DEF_CMD(CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
+ DEF_CMD(CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
DEF_CMD(CmdTurnRoadVeh, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_TURN_ROADVEH
diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp
index 9d9129b41..15447b9c1 100644
--- a/src/game/game_instance.cpp
+++ b/src/game/game_instance.cpp
@@ -54,6 +54,7 @@
#include "../script/api/game/game_rail.hpp.sq"
#include "../script/api/game/game_railtypelist.hpp.sq"
#include "../script/api/game/game_road.hpp.sq"
+#include "../script/api/game/game_sign.hpp.sq"
#include "../script/api/game/game_signlist.hpp.sq"
#include "../script/api/game/game_station.hpp.sq"
#include "../script/api/game/game_stationlist.hpp.sq"
@@ -125,6 +126,7 @@ void GameInstance::RegisterAPI()
SQGSRail_Register(this->engine);
SQGSRailTypeList_Register(this->engine);
SQGSRoad_Register(this->engine);
+ SQGSSign_Register(this->engine);
SQGSSignList_Register(this->engine);
SQGSStation_Register(this->engine);
SQGSStationList_Register(this->engine);
diff --git a/src/script/api/game/game_sign.hpp.sq b/src/script/api/game/game_sign.hpp.sq
new file mode 100644
index 000000000..20eb52ec2
--- /dev/null
+++ b/src/script/api/game/game_sign.hpp.sq
@@ -0,0 +1,39 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
+
+#include "../script_sign.hpp"
+#include "../template/template_sign.hpp.sq"
+
+
+template <> const char *GetClassName<ScriptSign, ST_GS>() { return "GSSign"; }
+
+void SQGSSign_Register(Squirrel *engine)
+{
+ DefSQClass<ScriptSign, ST_GS> SQGSSign("GSSign");
+ SQGSSign.PreRegister(engine);
+ SQGSSign.AddConstructor<void (ScriptSign::*)(), 1>(engine, "x");
+
+ SQGSSign.DefSQConst(engine, ScriptSign::ERR_SIGN_BASE, "ERR_SIGN_BASE");
+ SQGSSign.DefSQConst(engine, ScriptSign::ERR_SIGN_TOO_MANY_SIGNS, "ERR_SIGN_TOO_MANY_SIGNS");
+
+ ScriptError::RegisterErrorMap(STR_ERROR_TOO_MANY_SIGNS, ScriptSign::ERR_SIGN_TOO_MANY_SIGNS);
+
+ ScriptError::RegisterErrorMapString(ScriptSign::ERR_SIGN_TOO_MANY_SIGNS, "ERR_SIGN_TOO_MANY_SIGNS");
+
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::IsValidSign, "IsValidSign", 2, ".i");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::SetName, "SetName", 3, ".i.");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetName, "GetName", 2, ".i");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetLocation, "GetLocation", 2, ".i");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::BuildSign, "BuildSign", 3, ".i.");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::RemoveSign, "RemoveSign", 2, ".i");
+
+ SQGSSign.PostRegister(engine);
+}
diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp
index 051fb983d..ab7988cc1 100644
--- a/src/script/api/script_sign.cpp
+++ b/src/script/api/script_sign.cpp
@@ -24,7 +24,7 @@
/* static */ bool ScriptSign::IsValidSign(SignID sign_id)
{
const Sign *si = ::Sign::GetIfValid(sign_id);
- return si != NULL && si->owner == _current_company;
+ return si != NULL && (si->owner == _current_company || si->owner == OWNER_DEITY);
}
/* static */ bool ScriptSign::SetName(SignID sign_id, const char *name)
diff --git a/src/script/api/script_sign.hpp b/src/script/api/script_sign.hpp
index a4f2ba0b2..ee235615d 100644
--- a/src/script/api/script_sign.hpp
+++ b/src/script/api/script_sign.hpp
@@ -16,7 +16,7 @@
/**
* Class that handles all sign related functions.
- * @api ai
+ * @api ai game
*/
class ScriptSign : public ScriptObject {
public:
diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp
index 80d399ae9..033ddf123 100644
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -78,6 +78,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
{
Sign *si = Sign::GetIfValid(p1);
if (si == NULL) return CMD_ERROR;
+ if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY) return CMD_ERROR;
/* Rename the signs when empty, otherwise remove it */
if (!StrEmpty(text)) {
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 589af1cae..9c54ff2de 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -75,6 +75,7 @@ struct SignList {
const Sign *si;
FOR_ALL_SIGNS(si) *this->signs.Append() = si;
+ this->signs.SetFilterState(true);
this->FilterSignList();
this->signs.Compact();
this->signs.RebuildDone();
@@ -119,6 +120,13 @@ struct SignList {
return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
}
+ /** Filter sign list excluding OWNER_DEITY */
+ static bool CDECL OwnerDeityFilter(const Sign * const *a, FilterInfo filter_info)
+ {
+ /* You should never be able to edit signs of owner DEITY */
+ return (*a)->owner != OWNER_DEITY;
+ }
+
/** Filter sign list by owner */
static bool CDECL OwnerVisibilityFilter(const Sign * const *a, FilterInfo filter_info)
{
@@ -132,6 +140,7 @@ struct SignList {
{
FilterInfo filter_info = {this->filter_string, this->match_case};
this->signs.Filter(&SignNameFilter, filter_info);
+ this->signs.Filter(&OwnerDeityFilter, filter_info);
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
this->signs.Filter(&OwnerVisibilityFilter, filter_info);
}
@@ -196,14 +205,11 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
/* Copy new filter string */
strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
- this->signs.SetFilterState(true);
-
this->EnableWidget(WID_SIL_FILTER_CLEAR_BTN);
} else {
/* There is no new string -> clear this->filter_string */
this->filter_string[0] = '\0';
- this->signs.SetFilterState(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); // keep sign list filtering active if competitor signs should be hidden
this->DisableWidget(WID_SIL_FILTER_CLEAR_BTN);
}
@@ -378,11 +384,6 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
- if (data == -1) {
- /* The DO_SHOW_COMPETITOR_SIGNS display option has changed */
- this->signs.SetFilterState(!StrEmpty(this->filter_string) || !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
- }
-
/* When there is a filter string, we always need to rebuild the list even if
* the amount of signs in total is unchanged, as the subset of signs that is
* accepted by the filter might has changed. */
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 0d97c3d24..2388443d0 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1126,7 +1126,7 @@ static void ViewportAddLandscape()
* @param string_normal String for normal and 2x zoom level
* @param string_small String for 4x and 8x zoom level
* @param string_small_shadow Shadow string for 4x and 8x zoom level; or #STR_NULL if no shadow
- * @param colour colour of the sign background; or 0 if transparent
+ * @param colour colour of the sign background; or INVALID_COLOUR if transparent
*/
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2, Colours colour)
{
@@ -1207,12 +1207,12 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
/* Don't draw if sign is owned by another company and competitor signs should be hidden.
* Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt
* companies can leave OWNER_NONE signs after them. */
- if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
+ if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner && si->owner != OWNER_DEITY) continue;
ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &si->sign,
STR_WHITE_SIGN,
- IsTransparencySet(TO_SIGNS) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
- si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : _company_colours[si->owner]);
+ (IsTransparencySet(TO_SIGNS) || si->owner == OWNER_DEITY) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
+ si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : (si->owner == OWNER_DEITY ? INVALID_COLOUR : _company_colours[si->owner]));
}
}
@@ -1873,6 +1873,7 @@ static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
FOR_ALL_SIGNS(si) {
/* If competitor signs are hidden, don't check signs that aren't owned by local company */
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
+ if (si->owner == OWNER_DEITY) continue;
if (CheckClickOnViewportSign(vp, x, y, &si->sign)) {
HandleClickOnSign(si);