summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/api/script_basestation.cpp2
-rw-r--r--src/script/api/script_company.cpp4
-rw-r--r--src/script/api/script_group.cpp2
-rw-r--r--src/script/api/script_object.cpp2
-rw-r--r--src/script/api/script_sign.cpp4
-rw-r--r--src/script/api/script_text.cpp13
-rw-r--r--src/script/api/script_text.hpp7
-rw-r--r--src/script/api/script_town.cpp2
-rw-r--r--src/script/api/script_vehicle.cpp2
9 files changed, 30 insertions, 8 deletions
diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp
index 981ec2c31..d46d717a0 100644
--- a/src/script/api/script_basestation.cpp
+++ b/src/script/api/script_basestation.cpp
@@ -38,7 +38,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidBaseStation(station_id));
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp
index 99fe34376..2f06fd69d 100644
--- a/src/script/api/script_company.cpp
+++ b/src/script/api/script_company.cpp
@@ -43,7 +43,7 @@
CCountedPtr<Text> counter(name);
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
@@ -64,7 +64,7 @@
CCountedPtr<Text> counter(name);
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp
index bd2ea3010..01569d824 100644
--- a/src/script/api/script_group.cpp
+++ b/src/script/api/script_group.cpp
@@ -53,7 +53,7 @@
EnforcePrecondition(false, IsValidGroup(group_id));
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 6615b58de..6d4140b2a 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -287,6 +287,8 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return false;
}
+ assert(StrEmpty(text) || (GetCommandFlags(cmd) & CMD_STR_CTRL) != 0 || StrValid(text, text + strlen(text)));
+
/* Set the default callback to return a true/false result of the DoCommand */
if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp
index 514dd4a21..3373800b5 100644
--- a/src/script/api/script_sign.cpp
+++ b/src/script/api/script_sign.cpp
@@ -37,7 +37,7 @@
EnforcePrecondition(false, IsValidSign(sign_id));
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
@@ -72,7 +72,7 @@
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
EnforcePrecondition(INVALID_SIGN, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(INVALID_SIGN, text);
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp
index 8507a176d..2339ce5d6 100644
--- a/src/script/api/script_text.cpp
+++ b/src/script/api/script_text.cpp
@@ -11,9 +11,12 @@
#include "../../stdafx.h"
#include "../../string_func.h"
+#include "../../strings_func.h"
#include "script_text.hpp"
#include "../../table/control_codes.h"
+#include "table/strings.h"
+
ScriptText::ScriptText(HSQUIRRELVM vm) :
ZeroedMemoryAllocator()
{
@@ -191,3 +194,13 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int &param_count)
return p;
}
+
+const char *Text::GetDecodedText()
+{
+ const char *encoded_text = this->GetEncodedText();
+ if (encoded_text == NULL) return NULL;
+
+ static char buf[1024];
+ ::SetDParamStr(0, encoded_text);
+ return ::GetString(buf, STR_JUST_RAW_STRING, lastof(buf));
+}
diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp
index 6dd022bb7..9b75e21c5 100644
--- a/src/script/api/script_text.hpp
+++ b/src/script/api/script_text.hpp
@@ -27,6 +27,13 @@ public:
* @api -all
*/
virtual const char *GetEncodedText() = 0;
+
+ /**
+ * Convert a #ScriptText into a decoded normal string.
+ * @return A string (in a static buffer), or NULL.
+ * @api -all
+ */
+ const char *GetDecodedText();
};
/**
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index 5ade6f40f..cb8fb62d6 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -43,7 +43,7 @@
CCountedPtr<Text> counter(text);
EnforcePrecondition(false, text != NULL);
- const char *encoded_text = text->GetEncodedText();
+ const char *encoded_text = text->GetDecodedText();
EnforcePreconditionEncodedText(false, encoded_text);
EnforcePrecondition(false, IsValidTown(town_id));
EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index 84cfc99fc..23003ca26 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -219,7 +219,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
EnforcePrecondition(false, name != NULL);
- const char *text = name->GetEncodedText();
+ const char *text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);