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; }
|
||||
|
||||
Reference in New Issue
Block a user