summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Trahan <tyler@tylertrahan.com>2021-11-28 07:16:42 -0700
committerGitHub <noreply@github.com>2021-11-28 15:16:42 +0100
commit802ca4e72231895e9f043a7b380c59dfbba366cd (patch)
tree3f65113f1b513c0fda4d73e52d4ce1a7ba35d7e7
parent6953df7b5e52d749e50275640197e5fc17e2310c (diff)
downloadopenttd-802ca4e72231895e9f043a7b380c59dfbba366cd.tar.xz
Fix: Don't try to rename OWNER_DEITY signs in-game (#9716)
-rw-r--r--src/signs.cpp12
-rw-r--r--src/signs_cmd.cpp2
-rw-r--r--src/signs_func.h1
-rw-r--r--src/signs_gui.cpp4
4 files changed, 18 insertions, 1 deletions
diff --git a/src/signs.cpp b/src/signs.cpp
index 3e0e7a7a3..0f1d7a78f 100644
--- a/src/signs.cpp
+++ b/src/signs.cpp
@@ -9,6 +9,7 @@
#include "stdafx.h"
#include "landscape.h"
+#include "company_func.h"
#include "signs_base.h"
#include "signs_func.h"
#include "strings_func.h"
@@ -61,3 +62,14 @@ void UpdateAllSignVirtCoords()
si->UpdateVirtCoord();
}
}
+
+/**
+ * Check if the current company can rename a given sign.
+ * @param *si The sign in question.
+ * @return true if the sign can be renamed, else false.
+ */
+bool CompanyCanRenameSign(const Sign *si)
+{
+ if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return false;
+ return true;
+}
diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp
index 0dd821157..78bbb8b4b 100644
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -79,7 +79,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
{
Sign *si = Sign::GetIfValid(p1);
if (si == nullptr) return CMD_ERROR;
- if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return CMD_ERROR;
+ if (!CompanyCanRenameSign(si)) return CMD_ERROR;
/* Rename the signs when empty, otherwise remove it */
if (!text.empty()) {
diff --git a/src/signs_func.h b/src/signs_func.h
index 55e831fdc..af677201c 100644
--- a/src/signs_func.h
+++ b/src/signs_func.h
@@ -18,6 +18,7 @@ extern SignID _new_sign_id;
void UpdateAllSignVirtCoords();
void PlaceProc_Sign(TileIndex tile);
+bool CompanyCanRenameSign(const Sign *si);
/* signs_gui.cpp */
void ShowRenameSignWindow(const Sign *si);
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 0240a6a25..516906462 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -565,10 +565,14 @@ static WindowDesc _query_sign_edit_desc(
*/
void HandleClickOnSign(const Sign *si)
{
+ /* If we can't rename the sign, don't even open the rename GUI. */
+ if (!CompanyCanRenameSign(si)) return;
+
if (_ctrl_pressed && (si->owner == _local_company || (si->owner == OWNER_DEITY && _game_mode == GM_EDITOR))) {
RenameSign(si->index, "");
return;
}
+
ShowRenameSignWindow(si);
}