Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/commit-checker.yml # src/industry_cmd.cpp # src/industry_gui.cpp # src/landscape.cpp # src/linkgraph/linkgraph_gui.cpp # src/order_base.h # src/order_cmd.cpp # src/order_gui.cpp # src/saveload/afterload.cpp # src/saveload/league_sl.cpp # src/saveload/saveload.h # src/script/api/script_object.hpp # src/script/squirrel_helper.hpp # src/settings_table.cpp # src/station_cmd.cpp # src/table/settings.h.preamble # src/tree_cmd.cpp # src/tree_map.h # src/vehicle.cpp # src/waypoint_cmd.cpp
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../game/game_text.hpp"
|
||||
#include "script_text.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "../../table/control_codes.h"
|
||||
@@ -24,7 +25,7 @@ RawText::RawText(const char *text) : text(text)
|
||||
|
||||
|
||||
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
string(STR_NULL), params(), parami(), paramt(), paramc(0)
|
||||
string(STR_NULL), param(), paramc(0)
|
||||
{
|
||||
int nparam = sq_gettop(vm) - 1;
|
||||
if (nparam < 1) {
|
||||
@@ -53,32 +54,16 @@ ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
}
|
||||
}
|
||||
|
||||
ScriptText::~ScriptText()
|
||||
{
|
||||
for (int i = 0; i < SCRIPT_TEXT_MAX_PARAMETERS; i++) {
|
||||
free(this->params[i]);
|
||||
if (this->paramt[i] != nullptr) this->paramt[i]->Release();
|
||||
}
|
||||
}
|
||||
|
||||
SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
{
|
||||
if (parameter >= SCRIPT_TEXT_MAX_PARAMETERS) return SQ_ERROR;
|
||||
|
||||
free(this->params[parameter]);
|
||||
if (this->paramt[parameter] != nullptr) this->paramt[parameter]->Release();
|
||||
|
||||
this->parami[parameter] = 0;
|
||||
this->params[parameter] = nullptr;
|
||||
this->paramt[parameter] = nullptr;
|
||||
|
||||
switch (sq_gettype(vm, -1)) {
|
||||
case OT_STRING: {
|
||||
const SQChar *value;
|
||||
sq_getstring(vm, -1, &value);
|
||||
|
||||
this->params[parameter] = stredup(value);
|
||||
StrMakeValidInPlace(this->params[parameter]);
|
||||
this->param[parameter] = StrMakeValid(value);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -86,7 +71,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
SQInteger value;
|
||||
sq_getinteger(vm, -1, &value);
|
||||
|
||||
this->parami[parameter] = value;
|
||||
this->param[parameter] = value;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -109,8 +94,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
if (real_instance == nullptr) return SQ_ERROR;
|
||||
|
||||
ScriptText *value = static_cast<ScriptText *>(real_instance);
|
||||
value->AddRef();
|
||||
this->paramt[parameter] = value;
|
||||
this->param[parameter] = ScriptTextRef(value);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -185,19 +169,37 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||
{
|
||||
p += Utf8Encode(p, SCC_ENCODED);
|
||||
p += seprintf(p, lastofp, "%X", this->string);
|
||||
for (int i = 0; i < this->paramc; i++) {
|
||||
if (this->params[i] != nullptr) {
|
||||
p += seprintf(p, lastofp, ":\"%s\"", this->params[i]);
|
||||
param_count++;
|
||||
continue;
|
||||
|
||||
const StringParams ¶ms = GetGameStringParams(this->string);
|
||||
int cur_idx = 0;
|
||||
|
||||
for (const StringParam &cur_param : params) {
|
||||
if (cur_idx >= this->paramc) throw Script_FatalError("Not enough string parameters");
|
||||
|
||||
switch (cur_param.type) {
|
||||
case StringParam::RAW_STRING:
|
||||
if (!std::holds_alternative<std::string>(this->param[cur_idx])) throw Script_FatalError("Wrong string parameter type");
|
||||
p += seprintf(p, lastofp, ":\"%s\"", std::get<std::string>(this->param[cur_idx++]).c_str());
|
||||
break;
|
||||
|
||||
case StringParam::STRING: {
|
||||
if (!std::holds_alternative<ScriptTextRef>(this->param[cur_idx])) throw Script_FatalError("Wrong string parameter type");
|
||||
int count = 1; // 1 because the string id is included in consumed parameters
|
||||
p += seprintf(p, lastofp, ":");
|
||||
p = std::get<ScriptTextRef>(this->param[cur_idx++])->_GetEncodedText(p, lastofp, count);
|
||||
if (count != cur_param.consumes) throw Script_FatalError("Substring doesn't consume the expected amount of parameters.");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if (cur_idx + cur_param.consumes > this->paramc) throw Script_FatalError("Not enough string parameters");
|
||||
for (int i = 0; i < cur_param.consumes; i++) {
|
||||
if (!std::holds_alternative<SQInteger>(this->param[cur_idx])) throw Script_FatalError("Wrong string parameter type");
|
||||
p += seprintf(p, lastofp,":" OTTD_PRINTFHEX64, std::get<SQInteger>(this->param[cur_idx++]));
|
||||
}
|
||||
}
|
||||
if (this->paramt[i] != nullptr) {
|
||||
p += seprintf(p, lastofp, ":");
|
||||
p = this->paramt[i]->_GetEncodedText(p, lastofp, param_count);
|
||||
continue;
|
||||
}
|
||||
p += seprintf(p, lastofp,":" OTTD_PRINTFHEX64, this->parami[i]);
|
||||
param_count++;
|
||||
|
||||
param_count += cur_param.consumes;
|
||||
}
|
||||
|
||||
return p;
|
||||
|
Reference in New Issue
Block a user