From 0bdbd509be8fcb7bac921aeffb7b77b55d968155 Mon Sep 17 00:00:00 2001 From: glx22 Date: Thu, 14 Nov 2019 21:10:03 +0100 Subject: Fix #7673: [Script] Allow removal of custom town text (#7834) --- src/script/api/script_town.cpp | 8 +++++--- src/script/api/script_town.hpp | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index 29183aa89..fb5589707 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -58,9 +58,11 @@ { CCountedPtr counter(text); - EnforcePrecondition(false, text != nullptr); - const char *encoded_text = text->GetEncodedText(); - EnforcePreconditionEncodedText(false, encoded_text); + const char *encoded_text = nullptr; + if (text != nullptr) { + encoded_text = text->GetEncodedText(); + EnforcePreconditionEncodedText(false, encoded_text); + } EnforcePrecondition(false, IsValidTown(town_id)); return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text); diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp index f2244e7bf..71fb5a712 100644 --- a/src/script/api/script_town.hpp +++ b/src/script/api/script_town.hpp @@ -146,7 +146,7 @@ public: /** * Rename a town. * @param town_id The town to rename - * @param name The new name of the town. If nullptr or an empty string is passed, the town name will be reset to the default name. + * @param name The new name of the town. If null is passed, the town name will be reset to the default name. * @pre IsValidTown(town_id). * @return True if the action succeeded. * @api -ai @@ -156,7 +156,7 @@ public: /** * Set the custom text of a town, shown in the GUI. * @param town_id The town to set the custom text of. - * @param text The text to set it to (can be either a raw string, or a ScriptText object). + * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null is passed, the text will be removed. * @pre IsValidTown(town_id). * @return True if the action succeeded. * @api -ai -- cgit v1.2.3-54-g00ecf