Merge remote-tracking branch 'upstream/master'
Conflicts: src/console_gui.cpp src/genworld_gui.cpp src/group_gui.cpp src/misc_gui.cpp src/settings_gui.cpp src/widgets/settings_widget.h
This commit is contained in:
@@ -49,6 +49,7 @@ void SQAIStation_Register(Squirrel *engine)
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFromVia, "GetCargoWaitingFromVia", 5, ".iiii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
*
|
||||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* \b 1.4.0
|
||||
* API additions:
|
||||
* \li AIStation::GetCargoWaitingFromVia
|
||||
*
|
||||
* 1.4.0 is not yet released. The following changes are not set in stone yet.
|
||||
* \b 1.4.0
|
||||
*
|
||||
* API additions:
|
||||
* \li AICargo::GetDistributionType
|
||||
|
||||
@@ -50,6 +50,7 @@ void SQGSStation_Register(Squirrel *engine)
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFromVia, "GetCargoWaitingFromVia", 5, ".iiii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
|
||||
|
||||
@@ -138,6 +138,7 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WC_NEWGRF_INSPECT, "WC_NEWGRF_INSPECT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WC_SPRITE_ALIGNER, "WC_SPRITE_ALIGNER");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WC_LINKGRAPH_LEGEND, "WC_LINKGRAPH_LEGEND");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WC_SAVE_PRESET, "WC_SAVE_PRESET");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WC_INVALID, "WC_INVALID");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::TC_BLUE, "TC_BLUE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::TC_SILVER, "TC_SILVER");
|
||||
@@ -455,8 +456,6 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_MAPSIZE_Y_PULLDOWN, "WID_GL_MAPSIZE_Y_PULLDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_TOWN_PULLDOWN, "WID_GL_TOWN_PULLDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_INDUSTRY_PULLDOWN, "WID_GL_INDUSTRY_PULLDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_RANDOM_EDITBOX, "WID_GL_RANDOM_EDITBOX");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_RANDOM_BUTTON, "WID_GL_RANDOM_BUTTON");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_GENERATE_BUTTON, "WID_GL_GENERATE_BUTTON");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_START_DATE_DOWN, "WID_GL_START_DATE_DOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_START_DATE_TEXT, "WID_GL_START_DATE_TEXT");
|
||||
@@ -792,6 +791,7 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_REMOVE, "WID_NS_REMOVE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_MOVE_UP, "WID_NS_MOVE_UP");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_MOVE_DOWN, "WID_NS_MOVE_DOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_UPGRADE, "WID_NS_UPGRADE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_FILTER, "WID_NS_FILTER");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_FILE_LIST, "WID_NS_FILE_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_SCROLLBAR, "WID_NS_SCROLLBAR");
|
||||
@@ -811,6 +811,11 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_CONTENT_DOWNLOAD2, "WID_NS_CONTENT_DOWNLOAD2");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_SHOW_REMOVE, "WID_NS_SHOW_REMOVE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NS_SHOW_APPLY, "WID_NS_SHOW_APPLY");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SVP_PRESET_LIST, "WID_SVP_PRESET_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SVP_SCROLLBAR, "WID_SVP_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SVP_EDITBOX, "WID_SVP_EDITBOX");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SVP_CANCEL, "WID_SVP_CANCEL");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SVP_SAVE, "WID_SVP_SAVE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SP_PROGRESS_BAR, "WID_SP_PROGRESS_BAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SP_PROGRESS_TEXT, "WID_SP_PROGRESS_TEXT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_N_PANEL, "WID_N_PANEL");
|
||||
@@ -994,7 +999,6 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_LANG_DROPDOWN, "WID_GO_LANG_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_RESOLUTION_DROPDOWN, "WID_GO_RESOLUTION_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_FULLSCREEN_BUTTON, "WID_GO_FULLSCREEN_BUTTON");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_SCREENSHOT_DROPDOWN, "WID_GO_SCREENSHOT_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_DROPDOWN, "WID_GO_BASE_GRF_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_STATUS, "WID_GO_BASE_GRF_STATUS");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GO_BASE_GRF_TEXTFILE, "WID_GO_BASE_GRF_TEXTFILE");
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
*
|
||||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* \b 1.4.0
|
||||
* API additions:
|
||||
* \li GSStation::GetCargoWaitingFromVia
|
||||
*
|
||||
* 1.4.0 is not yet released. The following changes are not set in stone yet.
|
||||
* \b 1.4.0
|
||||
*
|
||||
* API additions:
|
||||
* \li AICargo::GetDistributionType
|
||||
@@ -34,8 +35,8 @@
|
||||
* \li GSGoal::SetProgress
|
||||
* \li GSGoal::SetText
|
||||
* \li GSStation::HasCargoRating
|
||||
* \li AIStation::GetCargoWaitingFrom
|
||||
* \li AIStation::GetCargoWaitingVia
|
||||
* \li GSStation::GetCargoWaitingFrom
|
||||
* \li GSStation::GetCargoWaitingVia
|
||||
* \li GSStoryPage
|
||||
* \li GSStoryPageList
|
||||
* \li GSStoryPageElementList
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "script_accounting.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
Money ScriptAccounting::GetCosts()
|
||||
{
|
||||
return this->GetDoCommandCosts();
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include "script_log.hpp"
|
||||
#include "../../network/network_admin.h"
|
||||
#include "../script_instance.hpp"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptAdmin::MakeJSON(HSQUIRRELVM vm, SQInteger index, int max_depth, std::string &data)
|
||||
{
|
||||
@@ -28,7 +31,7 @@
|
||||
sq_getinteger(vm, index, &res);
|
||||
|
||||
char buf[10];
|
||||
snprintf(buf, sizeof(buf), "%d", (int32)res);
|
||||
seprintf(buf, lastof(buf), "%d", (int32)res);
|
||||
data = buf;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../station_base.h"
|
||||
#include "../../town.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptAirport::IsValidAirportType(AirportType type)
|
||||
{
|
||||
return IsAirportInformationAvailable(type) && ::AirportSpec::Get(type)->IsAvailable();
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../network/network.h"
|
||||
#include "../../core/random_func.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ uint32 ScriptBase::Rand()
|
||||
{
|
||||
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../../strings_func.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id)
|
||||
{
|
||||
const BaseStation *st = ::BaseStation::GetIfValid(station_id);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../../strings_func.h"
|
||||
#include "../../date_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptBridge::IsValidBridge(BridgeID bridge_id)
|
||||
{
|
||||
return bridge_id < MAX_BRIDGES && ::GetBridgeSpec(bridge_id)->avail_year <= _cur_year;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "script_bridge.hpp"
|
||||
#include "../../bridge.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptBridgeList::ScriptBridgeList()
|
||||
{
|
||||
for (byte j = 0; j < MAX_BRIDGES; j++) {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../core/bitmath_func.hpp"
|
||||
#include "../../settings_type.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptCargo::IsValidCargo(CargoID cargo_type)
|
||||
{
|
||||
return (cargo_type < NUM_CARGO && ::CargoSpec::Get(cargo_type)->IsValid());
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../../industry.h"
|
||||
#include "../../station_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptCargoList::ScriptCargoList()
|
||||
{
|
||||
const CargoSpec *cs;
|
||||
@@ -57,6 +59,6 @@ ScriptCargoList_StationAccepting::ScriptCargoList_StationAccepting(StationID sta
|
||||
|
||||
Station *st = ::Station::Get(station_id);
|
||||
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
||||
if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i);
|
||||
if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "script_cargomonitor.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ uint32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
|
||||
{
|
||||
CargoMonitorID monitor = EncodeCargoTownMonitor(static_cast<CompanyID>(company), cargo, town_id);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "../../settings_func.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptCompany::ResolveCompanyID(ScriptCompany::CompanyID company)
|
||||
{
|
||||
if (company == COMPANY_SELF) {
|
||||
@@ -194,11 +196,11 @@
|
||||
return LOAN_INTERVAL;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetLoanAmount(int32 loan)
|
||||
/* static */ bool ScriptCompany::SetLoanAmount(Money loan)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, loan >= 0);
|
||||
EnforcePrecondition(false, (loan % GetLoanInterval()) == 0);
|
||||
EnforcePrecondition(false, ((int64)loan % GetLoanInterval()) == 0);
|
||||
EnforcePrecondition(false, loan <= GetMaxLoanAmount());
|
||||
EnforcePrecondition(false, (loan - GetLoanAmount() + GetBankBalance(COMPANY_SELF)) >= 0);
|
||||
|
||||
@@ -209,12 +211,12 @@
|
||||
(loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetMinimumLoanAmount(int32 loan)
|
||||
/* static */ bool ScriptCompany::SetMinimumLoanAmount(Money loan)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, loan >= 0);
|
||||
|
||||
int32 over_interval = loan % GetLoanInterval();
|
||||
Money over_interval = (int64)loan % GetLoanInterval();
|
||||
if (over_interval != 0) loan += GetLoanInterval() - over_interval;
|
||||
|
||||
EnforcePrecondition(false, loan <= GetMaxLoanAmount());
|
||||
@@ -224,10 +226,12 @@
|
||||
return GetLoanAmount() == loan;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::ChangeBankBalance(CompanyID company, int32 delta, ExpensesType expenses_type)
|
||||
/* static */ bool ScriptCompany::ChangeBankBalance(CompanyID company, Money delta, ExpensesType expenses_type)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(false, expenses_type < (ExpensesType)::EXPENSES_END);
|
||||
EnforcePrecondition(false, delta >= INT32_MIN);
|
||||
EnforcePrecondition(false, delta <= INT32_MAX);
|
||||
|
||||
company = ResolveCompanyID(company);
|
||||
EnforcePrecondition(false, company != COMPANY_INVALID);
|
||||
@@ -278,12 +282,14 @@
|
||||
return ::Company::Get((CompanyID)company)->settings.engine_renew_months;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetAutoRenewMoney(uint32 money)
|
||||
/* static */ bool ScriptCompany::SetAutoRenewMoney(Money money)
|
||||
{
|
||||
EnforcePrecondition(false, money >= 0);
|
||||
EnforcePrecondition(false, (int64)money <= UINT32_MAX);
|
||||
return ScriptObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew_money"), money, CMD_CHANGE_COMPANY_SETTING);
|
||||
}
|
||||
|
||||
/* static */ uint32 ScriptCompany::GetAutoRenewMoney(CompanyID company)
|
||||
/* static */ Money ScriptCompany::GetAutoRenewMoney(CompanyID company)
|
||||
{
|
||||
company = ResolveCompanyID(company);
|
||||
if (company == COMPANY_INVALID) return 0;
|
||||
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @return True if the loan could be set to your requested amount.
|
||||
*/
|
||||
static bool SetLoanAmount(int32 loan);
|
||||
static bool SetLoanAmount(Money loan);
|
||||
|
||||
/**
|
||||
* Sets the minimum amount to loan, i.e. the given amount of loan rounded up.
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @return True if we could allocate a minimum of 'loan' loan.
|
||||
*/
|
||||
static bool SetMinimumLoanAmount(int32 loan);
|
||||
static bool SetMinimumLoanAmount(Money loan);
|
||||
|
||||
/**
|
||||
* Gets the amount your company have loaned.
|
||||
@@ -194,10 +194,12 @@ public:
|
||||
* @param expenses_type The account in the finances window that will register the cost.
|
||||
* @game @pre No ScriptCompanyMode active in scope.
|
||||
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @pre delta >= -2**31
|
||||
* @pre delta < 2**31
|
||||
* @note You need to create your own news message to inform about costs/gifts that you create using this command.
|
||||
* @api -ai
|
||||
*/
|
||||
static bool ChangeBankBalance(CompanyID company, int32 delta, ExpensesType expenses_type);
|
||||
static bool ChangeBankBalance(CompanyID company, Money delta, ExpensesType expenses_type);
|
||||
|
||||
/**
|
||||
* Get the income of the company in the given quarter.
|
||||
@@ -314,9 +316,11 @@ public:
|
||||
* Set the minimum money needed to autorenew an engine for your company.
|
||||
* @param money The new minimum required money for autorenew to work.
|
||||
* @return True if autorenew money has been modified.
|
||||
* @pre money >= 0
|
||||
* @pre money < 2**32
|
||||
* @api -game
|
||||
*/
|
||||
static bool SetAutoRenewMoney(uint32 money);
|
||||
static bool SetAutoRenewMoney(Money money);
|
||||
|
||||
/**
|
||||
* Return the minimum money needed to autorenew an engine for a company.
|
||||
@@ -324,7 +328,7 @@ public:
|
||||
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @return The minimum required money for autorenew to work.
|
||||
*/
|
||||
static uint32 GetAutoRenewMoney(CompanyID company);
|
||||
static Money GetAutoRenewMoney(CompanyID company);
|
||||
};
|
||||
|
||||
DECLARE_POSTFIX_INCREMENT(ScriptCompany::CompanyID)
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "script_companymode.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptCompanyMode::ScriptCompanyMode(int company)
|
||||
{
|
||||
if (company < OWNER_BEGIN || company >= MAX_COMPANIES) company = INVALID_COMPANY;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "../../settings_type.h"
|
||||
#include "../../network/network.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ void ScriptController::SetCommandDelay(int ticks)
|
||||
{
|
||||
if (ticks <= 0) return;
|
||||
@@ -51,7 +53,7 @@
|
||||
ScriptObject::GetActiveInstance()->Pause();
|
||||
|
||||
char log_message[1024];
|
||||
snprintf(log_message, sizeof(log_message), "Break: %s", message);
|
||||
seprintf(log_message, lastof(log_message), "Break: %s", message);
|
||||
ScriptLog::Log(ScriptLog::LOG_SQ_ERROR, log_message);
|
||||
|
||||
/* Inform script developer that his script has been paused and
|
||||
@@ -113,13 +115,13 @@ ScriptController::~ScriptController()
|
||||
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
char library_name[1024];
|
||||
snprintf(library_name, sizeof(library_name), "%s.%d", library, version);
|
||||
seprintf(library_name, lastof(library_name), "%s.%d", library, version);
|
||||
strtolower(library_name);
|
||||
|
||||
ScriptInfo *lib = ScriptObject::GetActiveInstance()->FindLibrary(library, version);
|
||||
if (lib == NULL) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "couldn't find library '%s' with version %d", library, version);
|
||||
seprintf(error, lastof(error), "couldn't find library '%s' with version %d", library, version);
|
||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
||||
}
|
||||
|
||||
@@ -131,12 +133,12 @@ ScriptController::~ScriptController()
|
||||
|
||||
LoadedLibraryList::iterator iter = controller->loaded_library.find(library_name);
|
||||
if (iter != controller->loaded_library.end()) {
|
||||
ttd_strlcpy(fake_class, (*iter).second, sizeof(fake_class));
|
||||
strecpy(fake_class, (*iter).second, lastof(fake_class));
|
||||
} else {
|
||||
int next_number = ++controller->loaded_library_count;
|
||||
|
||||
/* Create a new fake internal name */
|
||||
snprintf(fake_class, sizeof(fake_class), "_internalNA%d", next_number);
|
||||
seprintf(fake_class, lastof(fake_class), "_internalNA%d", next_number);
|
||||
|
||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||
sq_pushroottable(vm);
|
||||
@@ -145,14 +147,14 @@ ScriptController::~ScriptController()
|
||||
/* Load the library */
|
||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "there was a compile error when importing '%s' version %d", library, version);
|
||||
seprintf(error, lastof(error), "there was a compile error when importing '%s' version %d", library, version);
|
||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
||||
}
|
||||
/* Create the fake class */
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
controller->loaded_library[strdup(library_name)] = strdup(fake_class);
|
||||
controller->loaded_library[stredup(library_name)] = stredup(fake_class);
|
||||
}
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
@@ -164,7 +166,7 @@ ScriptController::~ScriptController()
|
||||
sq_pushstring(vm, OTTD2SQ(lib->GetInstanceName()), -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "unable to find class '%s' in the library '%s' version %d", lib->GetInstanceName(), library, version);
|
||||
seprintf(error, lastof(error), "unable to find class '%s' in the library '%s' version %d", lib->GetInstanceName(), library, version);
|
||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
||||
}
|
||||
HSQOBJECT obj;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "script_date.hpp"
|
||||
#include "../../date_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptDate::IsValidDate(Date date)
|
||||
{
|
||||
return date >= 0;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "../../depot_base.h"
|
||||
#include "../../station_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
||||
{
|
||||
::TileType tile_type;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "../../articulated_vehicles.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptEngine::IsValidEngine(EngineID engine_id)
|
||||
{
|
||||
const Engine *e = ::Engine::GetIfValid(engine_id);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_enginelist.hpp"
|
||||
#include "../../engine_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type)
|
||||
{
|
||||
Engine *e;
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "script_error.hpp"
|
||||
#include "../../core/bitmath_func.hpp"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptError::ScriptErrorMap ScriptError::error_map = ScriptError::ScriptErrorMap();
|
||||
ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::ScriptErrorMapString();
|
||||
@@ -23,7 +26,7 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
|
||||
|
||||
/* static */ char *ScriptError::GetLastErrorString()
|
||||
{
|
||||
return strdup((*error_map_string.find(ScriptError::GetLastError())).second);
|
||||
return stredup((*error_map_string.find(ScriptError::GetLastError())).second);
|
||||
}
|
||||
|
||||
/* static */ ScriptErrorType ScriptError::StringToError(StringID internal_string_id)
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/** The queue of events for a script. */
|
||||
struct ScriptEventData {
|
||||
std::queue<ScriptEvent *> stack; ///< The actual queue.
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
#include "../../settings_type.h"
|
||||
#include "../../engine_base.h"
|
||||
#include "../../articulated_vehicles.h"
|
||||
#include "../../string_func.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool ScriptEventEnginePreview::IsEngineValid() const
|
||||
{
|
||||
const Engine *e = ::Engine::GetIfValid(this->engine);
|
||||
@@ -117,6 +120,17 @@ bool ScriptEventCompanyAskMerger::AcceptMerger()
|
||||
return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
|
||||
}
|
||||
|
||||
ScriptEventAdminPort::ScriptEventAdminPort(const char *json) :
|
||||
ScriptEvent(ET_ADMIN_PORT),
|
||||
json(stredup(json))
|
||||
{
|
||||
}
|
||||
|
||||
ScriptEventAdminPort::~ScriptEventAdminPort()
|
||||
{
|
||||
free(this->json);
|
||||
}
|
||||
|
||||
#define SKIP_EMPTY(p) while (*(p) == ' ' || *(p) == '\n' || *(p) == '\r') (p)++;
|
||||
#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return NULL; }
|
||||
|
||||
|
||||
@@ -839,15 +839,8 @@ public:
|
||||
/**
|
||||
* @param json The JSON string which got sent.
|
||||
*/
|
||||
ScriptEventAdminPort(const char *json) :
|
||||
ScriptEvent(ET_ADMIN_PORT),
|
||||
json(strdup(json))
|
||||
{}
|
||||
|
||||
~ScriptEventAdminPort()
|
||||
{
|
||||
free(this->json);
|
||||
}
|
||||
ScriptEventAdminPort(const char *json);
|
||||
~ScriptEventAdminPort();
|
||||
|
||||
/**
|
||||
* Convert an ScriptEvent to the real instance.
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "../script_instance.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool ScriptExecMode::ModeProc()
|
||||
{
|
||||
/* In execution mode we only return 'true', telling the DoCommand it
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../settings_type.h"
|
||||
#include "../../network/network.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptGame::Pause()
|
||||
{
|
||||
return ScriptObject::DoCommand(0, PM_PAUSED_GAME_SCRIPT, 1, CMD_PAUSE);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../settings_type.h"
|
||||
#include "../../command_type.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptGameSettings::IsValid(const char *setting)
|
||||
{
|
||||
uint i;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "../../goal_base.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptGoal::IsValidGoal(GoalID goal_id)
|
||||
{
|
||||
return ::Goal::IsValidID(goal_id);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "../../settings_func.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptGroup::IsValidGroup(GroupID group_id)
|
||||
{
|
||||
const Group *g = ::Group::GetIfValid(group_id);
|
||||
@@ -57,7 +59,7 @@
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id, 0, CMD_RENAME_GROUP, text);
|
||||
return ScriptObject::DoCommand(0, group_id, 0, CMD_ALTER_GROUP, text);
|
||||
}
|
||||
|
||||
/* static */ char *ScriptGroup::GetName(GroupID group_id)
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_grouplist.hpp"
|
||||
#include "../../group.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptGroupList::ScriptGroupList()
|
||||
{
|
||||
Group *g;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "../../newgrf_industries.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ int32 ScriptIndustry::GetIndustryCount()
|
||||
{
|
||||
return (int32)::Industry::GetNumItems();
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_industrylist.hpp"
|
||||
#include "../../industry.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptIndustryList::ScriptIndustryList()
|
||||
{
|
||||
Industry *i;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "../../newgrf_industries.h"
|
||||
#include "../../core/random_func.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptIndustryType::IsValidIndustryType(IndustryType industry_type)
|
||||
{
|
||||
if (industry_type >= NUM_INDUSTRYTYPES) return false;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_industrytypelist.hpp"
|
||||
#include "../../industry.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptIndustryTypeList::ScriptIndustryTypeList()
|
||||
{
|
||||
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../../water.h"
|
||||
#include "../../station_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
||||
/* static */ uint32 ScriptInfrastructure::GetRailPieceCount(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "../../debug.h"
|
||||
#include "../../script/squirrel.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/**
|
||||
* Base class for any ScriptList sorter.
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include "../../core/alloc_func.hpp"
|
||||
#include "../../debug.h"
|
||||
#include "../../window_func.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ void ScriptLog::Info(const char *message)
|
||||
{
|
||||
@@ -51,7 +54,7 @@
|
||||
|
||||
/* Free last message, and write new message */
|
||||
free(log->lines[log->pos]);
|
||||
log->lines[log->pos] = strdup(message);
|
||||
log->lines[log->pos] = stredup(message);
|
||||
log->type[log->pos] = level;
|
||||
|
||||
/* Cut string after first \n */
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_map.hpp"
|
||||
#include "../../tile_map.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptMap::IsValidTile(TileIndex t)
|
||||
{
|
||||
return ::IsValidTile(t);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../station_base.h"
|
||||
#include "../../tile_cmd.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
||||
/* static */ bool ScriptMarine::IsWaterDepotTile(TileIndex tile)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../command_type.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company)
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "script_error.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/**
|
||||
* Get the storage associated with the current ScriptInstance.
|
||||
* @return The storage.
|
||||
@@ -262,7 +264,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
char buffer[64];
|
||||
::GetString(buffer, string, lastof(buffer));
|
||||
::str_validate(buffer, lastof(buffer), SVS_NONE);
|
||||
return ::strdup(buffer);
|
||||
return ::stredup(buffer);
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCallbackVariable(int index, int value)
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "../../station_base.h"
|
||||
#include "../../waypoint_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/**
|
||||
* Gets the order type given a tile
|
||||
* @param t the tile to get the order from
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "../../newgrf_station.h"
|
||||
#include "../../strings_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ char *ScriptRail::GetName(RailType rail_type)
|
||||
{
|
||||
if (!IsRailTypeAvailable(rail_type)) return NULL;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_railtypelist.hpp"
|
||||
#include "../../rail.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptRailTypeList::ScriptRailTypeList()
|
||||
{
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "../../station_base.h"
|
||||
#include "../../script/squirrel_helper_type.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ ScriptRoad::RoadVehicleType ScriptRoad::GetRoadVehicleTypeForCargo(CargoID cargo_type)
|
||||
{
|
||||
return ScriptCargo::HasCargoClass(cargo_type, ScriptCargo::CC_PASSENGERS) ? ROADVEHTYPE_BUS : ROADVEHTYPE_TRUCK;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "../../strings_func.h"
|
||||
#include "../../tile_map.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptSign::IsValidSign(SignID sign_id)
|
||||
{
|
||||
const Sign *si = ::Sign::GetIfValid(sign_id);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "script_sign.hpp"
|
||||
#include "../../signs_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptSignList::ScriptSignList()
|
||||
{
|
||||
Sign *s;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "../../roadstop_base.h"
|
||||
#include "../../town.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptStation::IsValidStation(StationID station_id)
|
||||
{
|
||||
const Station *st = ::Station::GetIfValid(station_id);
|
||||
@@ -37,45 +39,52 @@
|
||||
return ::GetStationIndex(tile);
|
||||
}
|
||||
|
||||
template<bool Tfrom, bool Tvia>
|
||||
/* static */ int32 ScriptStation::CountCargoWaiting(StationID station_id,
|
||||
StationID from_station_id, StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return -1;
|
||||
if (Tfrom && !IsValidStation(from_station_id) && from_station_id != STATION_INVALID) return -1;
|
||||
if (Tvia && !IsValidStation(via_station_id) && via_station_id != STATION_INVALID) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
if (!Tfrom && !Tvia) return cargo_list.TotalCount();
|
||||
|
||||
uint16 cargo_count = 0;
|
||||
std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range = Tvia ?
|
||||
cargo_list.Packets()->equal_range(via_station_id) :
|
||||
std::make_pair(StationCargoList::ConstIterator(cargo_list.Packets()->begin()),
|
||||
StationCargoList::ConstIterator(cargo_list.Packets()->end()));
|
||||
for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
|
||||
const CargoPacket *cp = *it;
|
||||
if (!Tfrom || cp->SourceStation() == from_station_id) cargo_count += cp->Count();
|
||||
}
|
||||
|
||||
return cargo_count;
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoWaiting(StationID station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
||||
|
||||
return ::Station::Get(station_id)->goods[cargo_id].cargo.TotalCount();
|
||||
return CountCargoWaiting<false, false>(station_id, STATION_INVALID, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id, StationID from_station_id, CargoID cargo_id)
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id,
|
||||
StationID from_station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return -1;
|
||||
if (!IsValidStation(from_station_id) && from_station_id != STATION_INVALID) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
uint16 cargo_count = 0;
|
||||
for (StationCargoList::ConstIterator it = cargo_list.Packets()->begin(); it != cargo_list.Packets()->end(); it++) {
|
||||
CargoPacket *cp = *it;
|
||||
if (cp->SourceStation() == from_station_id) cargo_count += cp->Count();
|
||||
}
|
||||
|
||||
return cargo_count;
|
||||
return CountCargoWaiting<true, false>(station_id, from_station_id, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id, StationID via_station_id, CargoID cargo_id)
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id,
|
||||
StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return -1;
|
||||
if (!IsValidStation(via_station_id) && via_station_id != STATION_INVALID) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
||||
return CountCargoWaiting<false, true>(station_id, STATION_INVALID, via_station_id, cargo_id);
|
||||
}
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
uint16 cargo_count = 0;
|
||||
std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range = cargo_list.Packets()->equal_range(via_station_id);
|
||||
for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
|
||||
CargoPacket *cp = *it;
|
||||
cargo_count += cp->Count();
|
||||
}
|
||||
|
||||
return cargo_count;
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingFromVia(StationID station_id,
|
||||
StationID from_station_id, StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
return CountCargoWaiting<true, true>(station_id, from_station_id, via_station_id, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
/**
|
||||
* See how much cargo with a specific source station there is waiting on a station.
|
||||
* @param station_id The station to get the cargo-waiting of.
|
||||
* @param from_station_id The source station of the cargo. Pass STATION_INVALID to get cargo of which the source has been deleted.
|
||||
* @param cargo_id The cargo to get the cargo-waiting of.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidStation(from_station_id) || from_station_id == STATION_INVALID.
|
||||
@@ -100,17 +101,32 @@ public:
|
||||
|
||||
/**
|
||||
* See how much cargo with a specific via-station there is waiting on a station.
|
||||
* @param station_id The station to get the cargo-waiting of, or pass STATION_INVALID to get waiting cargo for "via any station".
|
||||
* @param station_id The station to get the cargo-waiting of.
|
||||
* @param via_station_id The next station the cargo is going to. Pass STATION_INVALID to get waiting cargo for "via any station".
|
||||
* @param cargo_id The cargo to get the cargo-waiting of.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidStation(via_station_id) || via_station_id == STATION_INVALID.
|
||||
* @pre IsValidCargo(cargo_id).
|
||||
* @return The amount of units waiting at the station with via_station_id as next hop.
|
||||
* @note if ScriptCargo.GetCargoDistributionType(cargo_id) == ScriptCargo.DT_MANUAL, then all waiting cargo will have STATION_INVALID as next hop.
|
||||
|
||||
*/
|
||||
static int32 GetCargoWaitingVia(StationID station_id, StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* See how much cargo with a specific via-station and source station there is waiting on a station.
|
||||
* @param station_id The station to get the cargo-waiting of.
|
||||
* @param from_station_id The source station of the cargo. Pass STATION_INVALID to get cargo of which the source has been deleted.
|
||||
* @param via_station_id The next station the cargo is going to. Pass STATION_INVALID to get waiting cargo for "via any station".
|
||||
* @param cargo_id The cargo to get the cargo-waiting of.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidStation(from_station_id) || from_station_id == STATION_INVALID.
|
||||
* @pre IsValidStation(via_station_id) || via_station_id == STATION_INVALID.
|
||||
* @pre IsValidCargo(cargo_id).
|
||||
* @return The amount of units waiting at the station with from_station_id as source and via_station_id as next hop.
|
||||
* @note if ScriptCargo.GetCargoDistributionType(cargo_id) == ScriptCargo.DT_MANUAL, then all waiting cargo will have STATION_INVALID as next hop.
|
||||
*/
|
||||
static int32 GetCargoWaitingFromVia(StationID station_id, StationID from_station_id, StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* Check whether the given cargo at the given station a rating.
|
||||
* @param station_id The station to get the cargo-rating state of.
|
||||
@@ -226,6 +242,12 @@ public:
|
||||
* @return True if the state could be toggled.
|
||||
*/
|
||||
static bool OpenCloseAirport(StationID station_id);
|
||||
|
||||
private:
|
||||
template<bool Tfrom, bool Tvia>
|
||||
static int32 CountCargoWaiting(StationID station_id, StationID from_station_id,
|
||||
StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
};
|
||||
|
||||
DECLARE_ENUM_AS_BIT_SET(ScriptStation::StationType)
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../station_base.h"
|
||||
#include "../../vehicle_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
|
||||
{
|
||||
Station *st;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "../../string_func.h"
|
||||
#include "../../tile_map.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptStoryPage::IsValidStoryPage(StoryPageID story_page_id)
|
||||
{
|
||||
return ::StoryPage::IsValidID(story_page_id);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_storypageelementlist.hpp"
|
||||
#include "../../story_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptStoryPageElementList::ScriptStoryPageElementList(ScriptStoryPage::StoryPageID story_page_id)
|
||||
{
|
||||
if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "script_story_page.hpp"
|
||||
#include "../../story_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company)
|
||||
{
|
||||
uint8 c = company;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "../../subsidy_base.h"
|
||||
#include "../../station_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptSubsidy::IsValidSubsidy(SubsidyID subsidy_id)
|
||||
{
|
||||
return ::Subsidy::IsValidID(subsidy_id);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_subsidylist.hpp"
|
||||
#include "../../subsidy_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptSubsidyList::ScriptSubsidyList()
|
||||
{
|
||||
const Subsidy *s;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "../script_instance.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
bool ScriptTestMode::ModeProc()
|
||||
{
|
||||
/* In test mode we only return 'false', telling the DoCommand it
|
||||
|
||||
@@ -17,6 +17,18 @@
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
RawText::RawText(const char *text) : text(stredup(text))
|
||||
{
|
||||
}
|
||||
|
||||
RawText::~RawText()
|
||||
{
|
||||
free(this->text);
|
||||
}
|
||||
|
||||
|
||||
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
ZeroedMemoryAllocator()
|
||||
{
|
||||
@@ -71,7 +83,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
const SQChar *value;
|
||||
sq_getstring(vm, -1, &value);
|
||||
|
||||
this->params[parameter] = strdup(SQ2OTTD(value));
|
||||
this->params[parameter] = stredup(SQ2OTTD(value));
|
||||
ValidateString(this->params[parameter]);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,8 @@ public:
|
||||
*/
|
||||
class RawText : public Text {
|
||||
public:
|
||||
RawText(const char *text) :
|
||||
text(strdup(text)) {}
|
||||
~RawText() { free(this->text); }
|
||||
RawText(const char *text);
|
||||
~RawText();
|
||||
|
||||
/* virtual */ const char *GetEncodedText() { return this->text; }
|
||||
private:
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "../../town.h"
|
||||
#include "../../landscape.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptTile::IsBuildable(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../industry.h"
|
||||
#include "../../station_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
||||
{
|
||||
if (!::IsValidTile(t1)) return;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "../../landscape.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ int32 ScriptTown::GetTownCount()
|
||||
{
|
||||
return (int32)::Town::GetNumItems();
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "script_townlist.hpp"
|
||||
#include "../../town.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptTownList::ScriptTownList()
|
||||
{
|
||||
Town *t;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../script_instance.hpp"
|
||||
#include "../../tunnel_map.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptTunnel::IsTunnelTile(TileIndex tile)
|
||||
{
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "../../aircraft.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptVehicle::IsValidVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../../depot_map.h"
|
||||
#include "../../vehicle_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptVehicleList::ScriptVehicleList()
|
||||
{
|
||||
const Vehicle *v;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "script_map.hpp"
|
||||
#include "../../viewport_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ void ScriptViewport::ScrollTo(TileIndex tile)
|
||||
{
|
||||
if (ScriptGame::IsMultiplayer()) return;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "script_marine.hpp"
|
||||
#include "../../waypoint_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id)
|
||||
{
|
||||
const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../vehicle_base.h"
|
||||
#include "../../waypoint_base.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)
|
||||
{
|
||||
const Waypoint *wp;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../../window_func.h"
|
||||
#include "../../window_gui.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ void ScriptWindow::Close(WindowClass window, uint32 number)
|
||||
{
|
||||
if (ScriptGame::IsMultiplayer()) return;
|
||||
|
||||
@@ -766,11 +766,17 @@ public:
|
||||
WC_SPRITE_ALIGNER = ::WC_SPRITE_ALIGNER,
|
||||
|
||||
/**
|
||||
* Linkgraph legend; Window numbers:
|
||||
* Linkgraph legend; %Window numbers:
|
||||
* - 0 = #LinkGraphWidgets
|
||||
*/
|
||||
WC_LINKGRAPH_LEGEND = ::WC_LINKGRAPH_LEGEND,
|
||||
|
||||
/**
|
||||
* Save preset; %Window numbers:
|
||||
* - 0 = #SavePresetWidgets
|
||||
*/
|
||||
WC_SAVE_PRESET = ::WC_SAVE_PRESET,
|
||||
|
||||
WC_INVALID = ::WC_INVALID, ///< Invalid window.
|
||||
};
|
||||
|
||||
@@ -1291,9 +1297,6 @@ public:
|
||||
WID_GL_TOWN_PULLDOWN = ::WID_GL_TOWN_PULLDOWN, ///< Dropdown 'No. of towns'.
|
||||
WID_GL_INDUSTRY_PULLDOWN = ::WID_GL_INDUSTRY_PULLDOWN, ///< Dropdown 'No. of industries'.
|
||||
|
||||
WID_GL_RANDOM_EDITBOX = ::WID_GL_RANDOM_EDITBOX, ///< 'Random seed' editbox.
|
||||
WID_GL_RANDOM_BUTTON = ::WID_GL_RANDOM_BUTTON, ///< 'Randomise' button.
|
||||
|
||||
WID_GL_GENERATE_BUTTON = ::WID_GL_GENERATE_BUTTON, ///< 'Generate' button.
|
||||
|
||||
WID_GL_START_DATE_DOWN = ::WID_GL_START_DATE_DOWN, ///< Decrease start year.
|
||||
@@ -1832,6 +1835,7 @@ public:
|
||||
WID_NS_REMOVE = ::WID_NS_REMOVE, ///< Remove NewGRF from active list.
|
||||
WID_NS_MOVE_UP = ::WID_NS_MOVE_UP, ///< Move NewGRF up in active list.
|
||||
WID_NS_MOVE_DOWN = ::WID_NS_MOVE_DOWN, ///< Move NewGRF down in active list.
|
||||
WID_NS_UPGRADE = ::WID_NS_UPGRADE, ///< Upgrade NewGRFs that have a newer version available.
|
||||
WID_NS_FILTER = ::WID_NS_FILTER, ///< Filter list of available NewGRFs.
|
||||
WID_NS_FILE_LIST = ::WID_NS_FILE_LIST, ///< List window of active NewGRFs.
|
||||
WID_NS_SCROLLBAR = ::WID_NS_SCROLLBAR, ///< Scrollbar for active NewGRF list.
|
||||
@@ -1853,6 +1857,15 @@ public:
|
||||
WID_NS_SHOW_APPLY = ::WID_NS_SHOW_APPLY, ///< Select display of the buttons below the 'details'.
|
||||
};
|
||||
|
||||
/** Widgets of the #SavePresetWindow class. */
|
||||
enum SavePresetWidgets {
|
||||
WID_SVP_PRESET_LIST = ::WID_SVP_PRESET_LIST, ///< List with available preset names.
|
||||
WID_SVP_SCROLLBAR = ::WID_SVP_SCROLLBAR, ///< Scrollbar for the list available preset names.
|
||||
WID_SVP_EDITBOX = ::WID_SVP_EDITBOX, ///< Edit box for changing the preset name.
|
||||
WID_SVP_CANCEL = ::WID_SVP_CANCEL, ///< Button to cancel saving the preset.
|
||||
WID_SVP_SAVE = ::WID_SVP_SAVE, ///< Button to save the preset.
|
||||
};
|
||||
|
||||
/** Widgets of the #ScanProgressWindow class. */
|
||||
enum ScanProgressWidgets {
|
||||
WID_SP_PROGRESS_BAR = ::WID_SP_PROGRESS_BAR, ///< Simple progress bar.
|
||||
@@ -2119,7 +2132,6 @@ public:
|
||||
WID_GO_LANG_DROPDOWN = ::WID_GO_LANG_DROPDOWN, ///< Language dropdown.
|
||||
WID_GO_RESOLUTION_DROPDOWN = ::WID_GO_RESOLUTION_DROPDOWN, ///< Dropdown for the resolution.
|
||||
WID_GO_FULLSCREEN_BUTTON = ::WID_GO_FULLSCREEN_BUTTON, ///< Toggle fullscreen.
|
||||
WID_GO_SCREENSHOT_DROPDOWN = ::WID_GO_SCREENSHOT_DROPDOWN, ///< Select the screenshot type... please use PNG!.
|
||||
WID_GO_BASE_GRF_DROPDOWN = ::WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF.
|
||||
WID_GO_BASE_GRF_STATUS = ::WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.
|
||||
WID_GO_BASE_GRF_TEXTFILE = ::WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2).
|
||||
|
||||
@@ -161,6 +161,8 @@ namespace SQConvert {
|
||||
template <> inline int Return<ScriptWindow::NewGRFParametersWidgets>(HSQUIRRELVM vm, ScriptWindow::NewGRFParametersWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptWindow::NewGRFStateWidgets GetParam(ForceType<ScriptWindow::NewGRFStateWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::NewGRFStateWidgets)tmp; }
|
||||
template <> inline int Return<ScriptWindow::NewGRFStateWidgets>(HSQUIRRELVM vm, ScriptWindow::NewGRFStateWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptWindow::SavePresetWidgets GetParam(ForceType<ScriptWindow::SavePresetWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::SavePresetWidgets)tmp; }
|
||||
template <> inline int Return<ScriptWindow::SavePresetWidgets>(HSQUIRRELVM vm, ScriptWindow::SavePresetWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptWindow::ScanProgressWidgets GetParam(ForceType<ScriptWindow::ScanProgressWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::ScanProgressWidgets)tmp; }
|
||||
template <> inline int Return<ScriptWindow::ScanProgressWidgets>(HSQUIRRELVM vm, ScriptWindow::ScanProgressWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptWindow::NewsWidgets GetParam(ForceType<ScriptWindow::NewsWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::NewsWidgets)tmp; }
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
#include "../core/random_func.hpp"
|
||||
#include "script_info.hpp"
|
||||
#include "../textfile_gui.h"
|
||||
#include "../string_func.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
|
||||
{
|
||||
free(this->name);
|
||||
this->name = (name == NULL) ? NULL : strdup(name);
|
||||
this->name = (name == NULL) ? NULL : stredup(name);
|
||||
this->info = (name == NULL) ? NULL : this->FindInfo(this->name, version, force_exact_match);
|
||||
this->version = (info == NULL) ? -1 : info->GetVersion();
|
||||
this->is_random = is_random;
|
||||
@@ -42,14 +45,14 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
|
||||
|
||||
ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
||||
{
|
||||
this->name = (config->name == NULL) ? NULL : strdup(config->name);
|
||||
this->name = (config->name == NULL) ? NULL : stredup(config->name);
|
||||
this->info = config->info;
|
||||
this->version = config->version;
|
||||
this->config_list = NULL;
|
||||
this->is_random = config->is_random;
|
||||
|
||||
for (SettingValueList::const_iterator it = config->settings.begin(); it != config->settings.end(); it++) {
|
||||
this->settings[strdup((*it).first)] = (*it).second;
|
||||
this->settings[stredup((*it).first)] = (*it).second;
|
||||
}
|
||||
this->AddRandomDeviation();
|
||||
}
|
||||
@@ -114,7 +117,7 @@ void ScriptConfig::SetSetting(const char *name, int value)
|
||||
if (it != this->settings.end()) {
|
||||
(*it).second = value;
|
||||
} else {
|
||||
this->settings[strdup(name)] = value;
|
||||
this->settings[stredup(name)] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +160,7 @@ int ScriptConfig::GetVersion() const
|
||||
|
||||
void ScriptConfig::StringToSettings(const char *value)
|
||||
{
|
||||
char *value_copy = strdup(value);
|
||||
char *value_copy = stredup(value);
|
||||
char *s = value_copy;
|
||||
|
||||
while (s != NULL) {
|
||||
@@ -181,27 +184,27 @@ void ScriptConfig::StringToSettings(const char *value)
|
||||
free(value_copy);
|
||||
}
|
||||
|
||||
void ScriptConfig::SettingsToString(char *string, size_t size) const
|
||||
void ScriptConfig::SettingsToString(char *string, const char *last) const
|
||||
{
|
||||
string[0] = '\0';
|
||||
char *s = string;
|
||||
*s = '\0';
|
||||
for (SettingValueList::const_iterator it = this->settings.begin(); it != this->settings.end(); it++) {
|
||||
char no[10];
|
||||
snprintf(no, sizeof(no), "%d", (*it).second);
|
||||
seprintf(no, lastof(no), "%d", (*it).second);
|
||||
|
||||
/* Check if the string would fit in the destination */
|
||||
size_t needed_size = strlen((*it).first) + 1 + strlen(no) + 1;
|
||||
size_t needed_size = strlen((*it).first) + 1 + strlen(no);
|
||||
/* If it doesn't fit, skip the next settings */
|
||||
if (size <= needed_size) break;
|
||||
size -= needed_size;
|
||||
if (string + needed_size > last) break;
|
||||
|
||||
strcat(string, (*it).first);
|
||||
strcat(string, "=");
|
||||
strcat(string, no);
|
||||
strcat(string, ",");
|
||||
s = strecat(s, (*it).first, last);
|
||||
s = strecat(s, "=", last);
|
||||
s = strecat(s, no, last);
|
||||
s = strecat(s, ",", last);
|
||||
}
|
||||
|
||||
/* Remove the last ',', but only if at least one setting was saved. */
|
||||
size_t len = strlen(string);
|
||||
if (len > 0) string[len - 1] = '\0';
|
||||
if (s != string) s[-1] = '\0';
|
||||
}
|
||||
|
||||
const char *ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const
|
||||
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
* Convert the custom settings to a string that can be stored in the config
|
||||
* file or savegames.
|
||||
*/
|
||||
void SettingsToString(char *string, size_t size) const;
|
||||
void SettingsToString(char *string, const char *last) const;
|
||||
|
||||
/**
|
||||
* Search a textfile file next to this script.
|
||||
|
||||
+13
-11
@@ -17,6 +17,8 @@
|
||||
#include "script_info.hpp"
|
||||
#include "script_scanner.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
ScriptInfo::~ScriptInfo()
|
||||
{
|
||||
/* Free all allocated strings */
|
||||
@@ -48,7 +50,7 @@ bool ScriptInfo::CheckMethod(const char *name) const
|
||||
{
|
||||
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
|
||||
seprintf(error, lastof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
|
||||
this->engine->ThrowError(error);
|
||||
return false;
|
||||
}
|
||||
@@ -81,9 +83,9 @@ bool ScriptInfo::CheckMethod(const char *name) const
|
||||
}
|
||||
|
||||
/* Get location information of the scanner */
|
||||
info->main_script = strdup(info->scanner->GetMainScript());
|
||||
info->main_script = stredup(info->scanner->GetMainScript());
|
||||
const char *tar_name = info->scanner->GetTarFile();
|
||||
if (tar_name != NULL) info->tar_file = strdup(tar_name);
|
||||
if (tar_name != NULL) info->tar_file = stredup(tar_name);
|
||||
|
||||
/* Cache the data the info file gives us. */
|
||||
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author, MAX_GET_OPS)) return SQ_ERROR;
|
||||
@@ -131,7 +133,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
if (strcmp(key, "name") == 0) {
|
||||
const SQChar *sqvalue;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
|
||||
char *name = strdup(SQ2OTTD(sqvalue));
|
||||
char *name = stredup(SQ2OTTD(sqvalue));
|
||||
char *s;
|
||||
ValidateString(name);
|
||||
|
||||
@@ -144,7 +146,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
} else if (strcmp(key, "description") == 0) {
|
||||
const SQChar *sqdescription;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
|
||||
config.description = strdup(SQ2OTTD(sqdescription));
|
||||
config.description = stredup(SQ2OTTD(sqdescription));
|
||||
ValidateString(config.description);
|
||||
items |= 0x002;
|
||||
} else if (strcmp(key, "min_value") == 0) {
|
||||
@@ -193,7 +195,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
items |= 0x100;
|
||||
} else {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "unknown setting property '%s'", key);
|
||||
seprintf(error, lastof(error), "unknown setting property '%s'", key);
|
||||
this->engine->ThrowError(error);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
@@ -206,7 +208,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
* be set for the same config item. */
|
||||
if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_RANDOM) != 0) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
|
||||
seprintf(error, lastof(error), "Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
|
||||
this->engine->ThrowError(error);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
@@ -217,7 +219,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
uint mask = (config.flags & SCRIPTCONFIG_BOOLEAN) ? 0x1F3 : 0x1FF;
|
||||
if (items != mask) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "please define all properties of a setting (min/max not allowed for booleans)");
|
||||
seprintf(error, lastof(error), "please define all properties of a setting (min/max not allowed for booleans)");
|
||||
this->engine->ThrowError(error);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
@@ -240,7 +242,7 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||
|
||||
if (config == NULL) {
|
||||
char error[1024];
|
||||
snprintf(error, sizeof(error), "Trying to add labels for non-defined setting '%s'", setting_name);
|
||||
seprintf(error, lastof(error), "Trying to add labels for non-defined setting '%s'", setting_name);
|
||||
this->engine->ThrowError(error);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
@@ -262,8 +264,8 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||
const char *label = SQ2OTTD(sq_label);
|
||||
ValidateString(label);
|
||||
|
||||
/* !Contains() prevents strdup from leaking. */
|
||||
if (!config->labels->Contains(key)) config->labels->Insert(key, strdup(label));
|
||||
/* !Contains() prevents stredup from leaking. */
|
||||
if (!config->labels->Contains(key)) config->labels->Insert(key, stredup(label));
|
||||
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "../string_func.h"
|
||||
#include "../strings_func.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/* The reason this exists in C++, is that a user can trash his ai/ or game/ dir,
|
||||
* leaving no Scripts available. The complexity to solve this is insane, and
|
||||
* therefore the alternative is used, and make sure there is always a Script
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "../company_func.h"
|
||||
#include "../fileio_func.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
ScriptStorage::~ScriptStorage()
|
||||
{
|
||||
/* Free our pointers */
|
||||
@@ -114,8 +116,8 @@ bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirect
|
||||
char buf[MAX_PATH];
|
||||
Searchpath sp;
|
||||
FOR_ALL_SEARCHPATHS(sp) {
|
||||
FioAppendDirectory(buf, MAX_PATH, sp, dir);
|
||||
ttd_strlcat(buf, script_name, MAX_PATH);
|
||||
FioAppendDirectory(buf, lastof(buf), sp, dir);
|
||||
strecat(buf, script_name, lastof(buf));
|
||||
if (!FileExists(buf)) continue;
|
||||
|
||||
if (this->engine->LoadScript(buf)) return true;
|
||||
|
||||
@@ -18,15 +18,23 @@
|
||||
#include "script_scanner.hpp"
|
||||
#include "script_info.hpp"
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
#include "../network/network_content.h"
|
||||
#include "../3rdparty/md5/md5.h"
|
||||
#include "../tar_type.h"
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
|
||||
{
|
||||
free(this->main_script);
|
||||
this->main_script = strdup(filename);
|
||||
this->main_script = stredup(filename);
|
||||
if (this->main_script == NULL) return false;
|
||||
|
||||
free(this->tar_file);
|
||||
if (tar_filename != NULL) {
|
||||
this->tar_file = strdup(tar_filename);
|
||||
this->tar_file = stredup(tar_filename);
|
||||
if (this->tar_file == NULL) return false;
|
||||
} else {
|
||||
this->tar_file = NULL;
|
||||
@@ -45,9 +53,9 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const
|
||||
|
||||
if (!FioCheckFileExists(filename, this->subdir) || !FioCheckFileExists(this->main_script, this->subdir)) return false;
|
||||
|
||||
/* We don't care if one of the other scripts failed to load. */
|
||||
this->engine->ResetCrashed();
|
||||
this->ResetEngine();
|
||||
this->engine->LoadScript(filename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -58,17 +66,20 @@ ScriptScanner::ScriptScanner() :
|
||||
{
|
||||
}
|
||||
|
||||
void ScriptScanner::ResetEngine()
|
||||
{
|
||||
this->engine->Reset();
|
||||
this->engine->SetGlobalPointer(this);
|
||||
this->RegisterAPI(this->engine);
|
||||
}
|
||||
|
||||
void ScriptScanner::Initialize(const char *name)
|
||||
{
|
||||
this->engine = new Squirrel(name);
|
||||
|
||||
/* Mark this class as global pointer */
|
||||
this->engine->SetGlobalPointer(this);
|
||||
|
||||
this->RegisterAPI(this->engine);
|
||||
this->RescanDir();
|
||||
|
||||
this->engine->ResetCrashed();
|
||||
this->ResetEngine();
|
||||
}
|
||||
|
||||
ScriptScanner::~ScriptScanner()
|
||||
@@ -108,11 +119,11 @@ void ScriptScanner::Reset()
|
||||
void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||
{
|
||||
char script_original_name[1024];
|
||||
this->GetScriptName(info, script_original_name, sizeof(script_original_name));
|
||||
this->GetScriptName(info, script_original_name, lastof(script_original_name));
|
||||
strtolower(script_original_name);
|
||||
|
||||
char script_name[1024];
|
||||
snprintf(script_name, sizeof(script_name), "%s.%d", script_original_name, info->GetVersion());
|
||||
seprintf(script_name, lastof(script_name), "%s.%d", script_original_name, info->GetVersion());
|
||||
|
||||
/* Check if GetShortName follows the rules */
|
||||
if (strlen(info->GetShortName()) != 4) {
|
||||
@@ -142,13 +153,13 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
this->info_list[strdup(script_name)] = info;
|
||||
this->info_list[stredup(script_name)] = info;
|
||||
|
||||
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||
/* Add the script to the 'unique' script list, where only the highest version
|
||||
* of the script is registered. */
|
||||
if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) {
|
||||
this->info_single_list[strdup(script_original_name)] = info;
|
||||
this->info_single_list[stredup(script_original_name)] = info;
|
||||
} else if (this->info_single_list[script_original_name]->GetVersion() < info->GetVersion()) {
|
||||
this->info_single_list[script_original_name] = info;
|
||||
}
|
||||
@@ -170,9 +181,6 @@ char *ScriptScanner::GetConsoleList(char *p, const char *last, bool newest_only)
|
||||
}
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
#include "../network/network_content.h"
|
||||
#include "../3rdparty/md5/md5.h"
|
||||
#include "../tar_type.h"
|
||||
|
||||
/** Helper for creating a MD5sum of all files within of a script. */
|
||||
struct ScriptFileChecksumCreator : FileScanner {
|
||||
|
||||
@@ -101,7 +101,7 @@ protected:
|
||||
/**
|
||||
* Get the script name how to store the script in memory.
|
||||
*/
|
||||
virtual void GetScriptName(ScriptInfo *info, char *name, int len) = 0;
|
||||
virtual void GetScriptName(ScriptInfo *info, char *name, const char *last) = 0;
|
||||
|
||||
/**
|
||||
* Get the filename to scan for this type of script.
|
||||
@@ -128,6 +128,10 @@ protected:
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* Reset the engine to ensure a clean environment for further steps.
|
||||
*/
|
||||
void ResetEngine();
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_SCANNER_HPP */
|
||||
|
||||
+33
-17
@@ -19,15 +19,19 @@
|
||||
#include <../squirrel/sqpcheader.h>
|
||||
#include <../squirrel/sqvm.h>
|
||||
|
||||
/* Due to the different characters for Squirrel, the scsnprintf might be a simple
|
||||
* snprint which triggers the safeguard. But it isn't always a simple snprintf.
|
||||
* Likewise for scvsnprintf and scstrcat. */
|
||||
#include "../safeguards.h"
|
||||
#undef snprintf
|
||||
#undef vsnprintf
|
||||
#undef strcat
|
||||
|
||||
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
|
||||
{
|
||||
SQChar buf[1024];
|
||||
|
||||
#ifdef _SQ64
|
||||
scsnprintf(buf, lengthof(buf), _SC("Error %s:%ld/%ld: %s"), source, line, column, desc);
|
||||
#else
|
||||
scsnprintf(buf, lengthof(buf), _SC("Error %s:%d/%d: %s"), source, line, column, desc);
|
||||
#endif
|
||||
scsnprintf(buf, lengthof(buf), _SC("Error %s:") SQ_PRINTF64 _SC("/") SQ_PRINTF64 _SC(": %s"), source, line, column, desc);
|
||||
|
||||
/* Check if we have a custom print function */
|
||||
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
|
||||
@@ -252,7 +256,7 @@ bool Squirrel::CallStringMethodStrdup(HSQOBJECT instance, const char *method_nam
|
||||
HSQOBJECT ret;
|
||||
if (!this->CallMethod(instance, method_name, &ret, suspend)) return false;
|
||||
if (ret._type != OT_STRING) return false;
|
||||
*res = strdup(ObjectToString(&ret));
|
||||
*res = stredup(ObjectToString(&ret));
|
||||
ValidateString(*res);
|
||||
return true;
|
||||
}
|
||||
@@ -285,8 +289,9 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
|
||||
sq_pushroottable(vm);
|
||||
|
||||
if (prepend_API_name) {
|
||||
char *class_name2 = (char *)alloca(strlen(class_name) + strlen(engine->GetAPIName()) + 1);
|
||||
sprintf(class_name2, "%s%s", engine->GetAPIName(), class_name);
|
||||
size_t len = strlen(class_name) + strlen(engine->GetAPIName()) + 1;
|
||||
char *class_name2 = (char *)alloca(len);
|
||||
seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name);
|
||||
|
||||
sq_pushstring(vm, OTTD2SQ(class_name2), -1);
|
||||
} else {
|
||||
@@ -330,12 +335,17 @@ bool Squirrel::CreateClassInstance(const char *class_name, void *real_instance,
|
||||
}
|
||||
|
||||
Squirrel::Squirrel(const char *APIName) :
|
||||
global_pointer(NULL),
|
||||
print_func(NULL),
|
||||
crashed(false),
|
||||
overdrawn_ops(0),
|
||||
APIName(APIName)
|
||||
{
|
||||
this->Initialize();
|
||||
}
|
||||
|
||||
void Squirrel::Initialize()
|
||||
{
|
||||
this->global_pointer = NULL;
|
||||
this->print_func = NULL;
|
||||
this->crashed = false;
|
||||
this->overdrawn_ops = 0;
|
||||
this->vm = sq_open(1024);
|
||||
|
||||
/* Handle compile-errors ourself, so we can display it nicely */
|
||||
@@ -543,12 +553,23 @@ bool Squirrel::LoadScript(const char *script)
|
||||
}
|
||||
|
||||
Squirrel::~Squirrel()
|
||||
{
|
||||
this->Uninitialize();
|
||||
}
|
||||
|
||||
void Squirrel::Uninitialize()
|
||||
{
|
||||
/* Clean up the stuff */
|
||||
sq_pop(this->vm, 1);
|
||||
sq_close(this->vm);
|
||||
}
|
||||
|
||||
void Squirrel::Reset()
|
||||
{
|
||||
this->Uninitialize();
|
||||
this->Initialize();
|
||||
}
|
||||
|
||||
void Squirrel::InsertResult(bool result)
|
||||
{
|
||||
sq_pushbool(this->vm, result);
|
||||
@@ -582,11 +603,6 @@ bool Squirrel::HasScriptCrashed()
|
||||
return this->crashed;
|
||||
}
|
||||
|
||||
void Squirrel::ResetCrashed()
|
||||
{
|
||||
this->crashed = false;
|
||||
}
|
||||
|
||||
void Squirrel::CrashOccurred()
|
||||
{
|
||||
this->crashed = true;
|
||||
|
||||
+10
-5
@@ -41,6 +41,11 @@ private:
|
||||
*/
|
||||
const char *GetAPIName() { return this->APIName; }
|
||||
|
||||
/** Perform all initialization steps to create the engine. */
|
||||
void Initialize();
|
||||
/** Perform all the cleanups for the engine. */
|
||||
void Uninitialize();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The CompileError handler.
|
||||
@@ -248,11 +253,6 @@ public:
|
||||
*/
|
||||
bool HasScriptCrashed();
|
||||
|
||||
/**
|
||||
* Reset the crashed status.
|
||||
*/
|
||||
void ResetCrashed();
|
||||
|
||||
/**
|
||||
* Set the script status to crashed.
|
||||
*/
|
||||
@@ -267,6 +267,11 @@ public:
|
||||
* How many operations can we execute till suspension?
|
||||
*/
|
||||
SQInteger GetOpsTillSuspend();
|
||||
|
||||
/**
|
||||
* Completely reset the engine; start from scratch.
|
||||
*/
|
||||
void Reset();
|
||||
};
|
||||
|
||||
#endif /* SQUIRREL_HPP */
|
||||
|
||||
@@ -26,7 +26,7 @@ template <class CL, ScriptType ST> const char *GetClassName();
|
||||
namespace SQConvert {
|
||||
/**
|
||||
* Pointers assigned to this class will be free'd when this instance
|
||||
* comes out of scope. Useful to make sure you can use strdup(),
|
||||
* comes out of scope. Useful to make sure you can use stredup(),
|
||||
* without leaking memory.
|
||||
*/
|
||||
struct SQAutoFreePointers : SmallVector<void *, 1> {
|
||||
@@ -85,8 +85,8 @@ namespace SQConvert {
|
||||
template <> inline int Return<int8> (HSQUIRRELVM vm, int8 res) { sq_pushinteger(vm, res); return 1; }
|
||||
template <> inline int Return<int16> (HSQUIRRELVM vm, int16 res) { sq_pushinteger(vm, res); return 1; }
|
||||
template <> inline int Return<int32> (HSQUIRRELVM vm, int32 res) { sq_pushinteger(vm, res); return 1; }
|
||||
template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, ClampToI32(res)); return 1; }
|
||||
template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, ClampToI32(res)); return 1; }
|
||||
template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, res); return 1; }
|
||||
template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; }
|
||||
template <> inline int Return<bool> (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
|
||||
template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); free(res); } return 1; }
|
||||
template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); } return 1; }
|
||||
@@ -104,6 +104,8 @@ namespace SQConvert {
|
||||
template <> inline int8 GetParam(ForceType<int8> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; }
|
||||
template <> inline int16 GetParam(ForceType<int16> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; }
|
||||
template <> inline int32 GetParam(ForceType<int32> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; }
|
||||
template <> inline int64 GetParam(ForceType<int64> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; }
|
||||
template <> inline Money GetParam(ForceType<Money> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger (vm, index, &tmp); return tmp; }
|
||||
template <> inline bool GetParam(ForceType<bool> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQBool tmp; sq_getbool (vm, index, &tmp); return tmp != 0; }
|
||||
template <> inline void *GetParam(ForceType<void *> , HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer tmp; sq_getuserpointer(vm, index, &tmp); return tmp; }
|
||||
template <> inline const char *GetParam(ForceType<const char *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr)
|
||||
@@ -113,7 +115,7 @@ namespace SQConvert {
|
||||
|
||||
const SQChar *tmp;
|
||||
sq_getstring(vm, -1, &tmp);
|
||||
char *tmp_str = strdup(SQ2OTTD(tmp));
|
||||
char *tmp_str = stredup(SQ2OTTD(tmp));
|
||||
sq_poptop(vm);
|
||||
*ptr->Append() = (void *)tmp_str;
|
||||
str_validate(tmp_str, tmp_str + strlen(tmp_str));
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
#include "squirrel_std.hpp"
|
||||
#include "../core/alloc_func.hpp"
|
||||
#include "../core/math_func.hpp"
|
||||
#include "../string_func.h"
|
||||
|
||||
/* Due to the different characters for Squirrel, the scstrcat might be a simple
|
||||
* strcat which triggers the safeguard. But it isn't always a simple strcat. */
|
||||
#include "../safeguards.h"
|
||||
#undef strcat
|
||||
#undef strdup
|
||||
|
||||
|
||||
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
|
||||
@@ -66,7 +73,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
|
||||
real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
|
||||
scstrcat(real_filename, filename);
|
||||
/* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
|
||||
char *filen = strdup(SQ2OTTD(real_filename));
|
||||
char *filen = stredup(SQ2OTTD(real_filename));
|
||||
#if (PATHSEPCHAR != '/')
|
||||
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user