Merge commit 'a8b575671894ffe1329ef37dca4989c0e60d70f5'
These merges are becoming more awful every time Conflicts: src/ai/ai_gui.cpp src/build_vehicle_gui.cpp src/cheat_gui.cpp src/company_gui.cpp src/depot_gui.cpp src/dock_gui.cpp src/error_gui.cpp src/genworld_gui.cpp src/misc_gui.cpp src/network/network_content_gui.cpp src/network/network_gui.cpp src/newgrf_gui.cpp src/news_gui.cpp src/rail_gui.cpp src/rev.cpp.in src/road_gui.cpp src/settings_gui.cpp src/settings_gui.h src/signs_gui.cpp src/station_gui.cpp src/table/settings.ini src/terraform_gui.cpp src/toolbar_gui.cpp src/toolbar_gui.h src/vehicle_gui.cpp src/video/sdl_v.cpp src/viewport.cpp src/widget.cpp src/widgets/settings_widget.h
This commit is contained in:
@@ -40,6 +40,7 @@ void SQAIList_Register(Squirrel *engine)
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::SetValue, "SetValue", 3, "xii");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::Sort, "Sort", 3, "xib");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::AddList, "AddList", 2, "xx");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::SwapList, "SwapList", 2, "xx");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveBelowValue, "RemoveBelowValue", 2, "xi");
|
||||
SQAIList.DefSQMethod(engine, &ScriptList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");
|
||||
|
||||
@@ -50,6 +50,10 @@ void SQAIStation_Register(Squirrel *engine)
|
||||
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::GetCargoPlanned, "GetCargoPlanned", 3, ".ii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedFrom, "GetCargoPlannedFrom", 4, ".iii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedVia, "GetCargoPlannedVia", 4, ".iii");
|
||||
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedFromVia, "GetCargoPlannedFromVia", 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");
|
||||
|
||||
@@ -25,6 +25,145 @@ void SQAIStationList_Register(Squirrel *engine)
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_Cargo, ST_AI>() { return "AIStationList_Cargo"; }
|
||||
|
||||
void SQAIStationList_Cargo_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_Cargo, ST_AI> SQAIStationList_Cargo("AIStationList_Cargo");
|
||||
SQAIStationList_Cargo.PreRegister(engine, "AIList");
|
||||
SQAIStationList_Cargo.AddConstructor<void (ScriptStationList_Cargo::*)(ScriptStationList_Cargo::CargoMode mode, ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 6>(engine, "xiiiii");
|
||||
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_BY_FROM, "CS_BY_FROM");
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_VIA_BY_FROM, "CS_VIA_BY_FROM");
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_BY_VIA, "CS_BY_VIA");
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_FROM_BY_VIA, "CS_FROM_BY_VIA");
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CM_WAITING, "CM_WAITING");
|
||||
SQAIStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CM_PLANNED, "CM_PLANNED");
|
||||
|
||||
SQAIStationList_Cargo.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaiting, ST_AI>() { return "AIStationList_CargoWaiting"; }
|
||||
|
||||
void SQAIStationList_CargoWaiting_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaiting, ST_AI> SQAIStationList_CargoWaiting("AIStationList_CargoWaiting");
|
||||
SQAIStationList_CargoWaiting.PreRegister(engine, "AIStationList_Cargo");
|
||||
SQAIStationList_CargoWaiting.AddConstructor<void (ScriptStationList_CargoWaiting::*)(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 5>(engine, "xiiii");
|
||||
|
||||
SQAIStationList_CargoWaiting.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlanned, ST_AI>() { return "AIStationList_CargoPlanned"; }
|
||||
|
||||
void SQAIStationList_CargoPlanned_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlanned, ST_AI> SQAIStationList_CargoPlanned("AIStationList_CargoPlanned");
|
||||
SQAIStationList_CargoPlanned.PreRegister(engine, "AIStationList_Cargo");
|
||||
SQAIStationList_CargoPlanned.AddConstructor<void (ScriptStationList_CargoPlanned::*)(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 5>(engine, "xiiii");
|
||||
|
||||
SQAIStationList_CargoPlanned.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingByFrom, ST_AI>() { return "AIStationList_CargoWaitingByFrom"; }
|
||||
|
||||
void SQAIStationList_CargoWaitingByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingByFrom, ST_AI> SQAIStationList_CargoWaitingByFrom("AIStationList_CargoWaitingByFrom");
|
||||
SQAIStationList_CargoWaitingByFrom.PreRegister(engine, "AIStationList_CargoWaiting");
|
||||
SQAIStationList_CargoWaitingByFrom.AddConstructor<void (ScriptStationList_CargoWaitingByFrom::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQAIStationList_CargoWaitingByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingViaByFrom, ST_AI>() { return "AIStationList_CargoWaitingViaByFrom"; }
|
||||
|
||||
void SQAIStationList_CargoWaitingViaByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingViaByFrom, ST_AI> SQAIStationList_CargoWaitingViaByFrom("AIStationList_CargoWaitingViaByFrom");
|
||||
SQAIStationList_CargoWaitingViaByFrom.PreRegister(engine, "AIStationList_CargoWaiting");
|
||||
SQAIStationList_CargoWaitingViaByFrom.AddConstructor<void (ScriptStationList_CargoWaitingViaByFrom::*)(StationID station_id, CargoID cargo, StationID via), 4>(engine, "xiii");
|
||||
|
||||
SQAIStationList_CargoWaitingViaByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingByVia, ST_AI>() { return "AIStationList_CargoWaitingByVia"; }
|
||||
|
||||
void SQAIStationList_CargoWaitingByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingByVia, ST_AI> SQAIStationList_CargoWaitingByVia("AIStationList_CargoWaitingByVia");
|
||||
SQAIStationList_CargoWaitingByVia.PreRegister(engine, "AIStationList_CargoWaiting");
|
||||
SQAIStationList_CargoWaitingByVia.AddConstructor<void (ScriptStationList_CargoWaitingByVia::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQAIStationList_CargoWaitingByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingFromByVia, ST_AI>() { return "AIStationList_CargoWaitingFromByVia"; }
|
||||
|
||||
void SQAIStationList_CargoWaitingFromByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingFromByVia, ST_AI> SQAIStationList_CargoWaitingFromByVia("AIStationList_CargoWaitingFromByVia");
|
||||
SQAIStationList_CargoWaitingFromByVia.PreRegister(engine, "AIStationList_CargoWaiting");
|
||||
SQAIStationList_CargoWaitingFromByVia.AddConstructor<void (ScriptStationList_CargoWaitingFromByVia::*)(StationID station_id, CargoID cargo, StationID from), 4>(engine, "xiii");
|
||||
|
||||
SQAIStationList_CargoWaitingFromByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedByFrom, ST_AI>() { return "AIStationList_CargoPlannedByFrom"; }
|
||||
|
||||
void SQAIStationList_CargoPlannedByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedByFrom, ST_AI> SQAIStationList_CargoPlannedByFrom("AIStationList_CargoPlannedByFrom");
|
||||
SQAIStationList_CargoPlannedByFrom.PreRegister(engine, "AIStationList_CargoPlanned");
|
||||
SQAIStationList_CargoPlannedByFrom.AddConstructor<void (ScriptStationList_CargoPlannedByFrom::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQAIStationList_CargoPlannedByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedViaByFrom, ST_AI>() { return "AIStationList_CargoPlannedViaByFrom"; }
|
||||
|
||||
void SQAIStationList_CargoPlannedViaByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedViaByFrom, ST_AI> SQAIStationList_CargoPlannedViaByFrom("AIStationList_CargoPlannedViaByFrom");
|
||||
SQAIStationList_CargoPlannedViaByFrom.PreRegister(engine, "AIStationList_CargoPlanned");
|
||||
SQAIStationList_CargoPlannedViaByFrom.AddConstructor<void (ScriptStationList_CargoPlannedViaByFrom::*)(StationID station_id, CargoID cargo, StationID via), 4>(engine, "xiii");
|
||||
|
||||
SQAIStationList_CargoPlannedViaByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedByVia, ST_AI>() { return "AIStationList_CargoPlannedByVia"; }
|
||||
|
||||
void SQAIStationList_CargoPlannedByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedByVia, ST_AI> SQAIStationList_CargoPlannedByVia("AIStationList_CargoPlannedByVia");
|
||||
SQAIStationList_CargoPlannedByVia.PreRegister(engine, "AIStationList_CargoPlanned");
|
||||
SQAIStationList_CargoPlannedByVia.AddConstructor<void (ScriptStationList_CargoPlannedByVia::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQAIStationList_CargoPlannedByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedFromByVia, ST_AI>() { return "AIStationList_CargoPlannedFromByVia"; }
|
||||
|
||||
void SQAIStationList_CargoPlannedFromByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedFromByVia, ST_AI> SQAIStationList_CargoPlannedFromByVia("AIStationList_CargoPlannedFromByVia");
|
||||
SQAIStationList_CargoPlannedFromByVia.PreRegister(engine, "AIStationList_CargoPlanned");
|
||||
SQAIStationList_CargoPlannedFromByVia.AddConstructor<void (ScriptStationList_CargoPlannedFromByVia::*)(StationID station_id, CargoID cargo, StationID from), 4>(engine, "xiii");
|
||||
|
||||
SQAIStationList_CargoPlannedFromByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_Vehicle, ST_AI>() { return "AIStationList_Vehicle"; }
|
||||
|
||||
void SQAIStationList_Vehicle_Register(Squirrel *engine)
|
||||
|
||||
@@ -15,12 +15,47 @@
|
||||
* functions may still be available if you return an older API version
|
||||
* in GetAPIVersion() in info.nut.
|
||||
*
|
||||
* \b 1.6.0
|
||||
*
|
||||
* 1.6.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* \b 1.5.3
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.2
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.1
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.0
|
||||
*
|
||||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li AIList::SwapList
|
||||
* \li AIStation::GetCargoPlanned
|
||||
* \li AIStation::GetCargoPlannedFrom
|
||||
* \li AIStation::GetCargoPlannedFromVia
|
||||
* \li AIStation::GetCargoPlannedVia
|
||||
* \li AIStation::GetCargoWaitingFromVia
|
||||
* \li AIStationList_CargoPlannedByFrom
|
||||
* \li AIStationList_CargoPlannedByVia
|
||||
* \li AIStationList_CargoPlannedFromByVia
|
||||
* \li AIStationList_CargoPlannedViaByFrom
|
||||
* \li AIStationList_CargoWaitingByFrom
|
||||
* \li AIStationList_CargoWaitingByVia
|
||||
* \li AIStationList_CargoWaitingFromByVia
|
||||
* \li AIStationList_CargoWaitingViaByFrom
|
||||
*
|
||||
* \b 1.4.4
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.3
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.2
|
||||
*
|
||||
|
||||
@@ -40,6 +40,7 @@ void SQGSList_Register(Squirrel *engine)
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::SetValue, "SetValue", 3, "xii");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::Sort, "Sort", 3, "xib");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::AddList, "AddList", 2, "xx");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::SwapList, "SwapList", 2, "xx");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveAboveValue, "RemoveAboveValue", 2, "xi");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveBelowValue, "RemoveBelowValue", 2, "xi");
|
||||
SQGSList.DefSQMethod(engine, &ScriptList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii");
|
||||
|
||||
@@ -28,8 +28,13 @@ void SQGSNews_Register(Squirrel *engine)
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NT_ACCEPTANCE, "NT_ACCEPTANCE");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NT_SUBSIDIES, "NT_SUBSIDIES");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NT_GENERAL, "NT_GENERAL");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NR_NONE, "NR_NONE");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NR_TILE, "NR_TILE");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NR_STATION, "NR_STATION");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NR_INDUSTRY, "NR_INDUSTRY");
|
||||
SQGSNews.DefSQConst(engine, ScriptNews::NR_TOWN, "NR_TOWN");
|
||||
|
||||
SQGSNews.DefSQStaticMethod(engine, &ScriptNews::Create, "Create", 4, ".i.i");
|
||||
SQGSNews.DefSQStaticMethod(engine, &ScriptNews::Create, "Create", 6, ".i.iii");
|
||||
|
||||
SQGSNews.PostRegister(engine);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ void SQGSStation_Register(Squirrel *engine)
|
||||
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::GetCargoPlanned, "GetCargoPlanned", 3, ".ii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedFrom, "GetCargoPlannedFrom", 4, ".iii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedVia, "GetCargoPlannedVia", 4, ".iii");
|
||||
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoPlannedFromVia, "GetCargoPlannedFromVia", 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");
|
||||
|
||||
@@ -25,6 +25,145 @@ void SQGSStationList_Register(Squirrel *engine)
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_Cargo, ST_GS>() { return "GSStationList_Cargo"; }
|
||||
|
||||
void SQGSStationList_Cargo_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_Cargo, ST_GS> SQGSStationList_Cargo("GSStationList_Cargo");
|
||||
SQGSStationList_Cargo.PreRegister(engine, "GSList");
|
||||
SQGSStationList_Cargo.AddConstructor<void (ScriptStationList_Cargo::*)(ScriptStationList_Cargo::CargoMode mode, ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 6>(engine, "xiiiii");
|
||||
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_BY_FROM, "CS_BY_FROM");
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_VIA_BY_FROM, "CS_VIA_BY_FROM");
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_BY_VIA, "CS_BY_VIA");
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CS_FROM_BY_VIA, "CS_FROM_BY_VIA");
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CM_WAITING, "CM_WAITING");
|
||||
SQGSStationList_Cargo.DefSQConst(engine, ScriptStationList_Cargo::CM_PLANNED, "CM_PLANNED");
|
||||
|
||||
SQGSStationList_Cargo.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaiting, ST_GS>() { return "GSStationList_CargoWaiting"; }
|
||||
|
||||
void SQGSStationList_CargoWaiting_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaiting, ST_GS> SQGSStationList_CargoWaiting("GSStationList_CargoWaiting");
|
||||
SQGSStationList_CargoWaiting.PreRegister(engine, "GSStationList_Cargo");
|
||||
SQGSStationList_CargoWaiting.AddConstructor<void (ScriptStationList_CargoWaiting::*)(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 5>(engine, "xiiii");
|
||||
|
||||
SQGSStationList_CargoWaiting.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlanned, ST_GS>() { return "GSStationList_CargoPlanned"; }
|
||||
|
||||
void SQGSStationList_CargoPlanned_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlanned, ST_GS> SQGSStationList_CargoPlanned("GSStationList_CargoPlanned");
|
||||
SQGSStationList_CargoPlanned.PreRegister(engine, "GSStationList_Cargo");
|
||||
SQGSStationList_CargoPlanned.AddConstructor<void (ScriptStationList_CargoPlanned::*)(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station), 5>(engine, "xiiii");
|
||||
|
||||
SQGSStationList_CargoPlanned.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingByFrom, ST_GS>() { return "GSStationList_CargoWaitingByFrom"; }
|
||||
|
||||
void SQGSStationList_CargoWaitingByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingByFrom, ST_GS> SQGSStationList_CargoWaitingByFrom("GSStationList_CargoWaitingByFrom");
|
||||
SQGSStationList_CargoWaitingByFrom.PreRegister(engine, "GSStationList_CargoWaiting");
|
||||
SQGSStationList_CargoWaitingByFrom.AddConstructor<void (ScriptStationList_CargoWaitingByFrom::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQGSStationList_CargoWaitingByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingViaByFrom, ST_GS>() { return "GSStationList_CargoWaitingViaByFrom"; }
|
||||
|
||||
void SQGSStationList_CargoWaitingViaByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingViaByFrom, ST_GS> SQGSStationList_CargoWaitingViaByFrom("GSStationList_CargoWaitingViaByFrom");
|
||||
SQGSStationList_CargoWaitingViaByFrom.PreRegister(engine, "GSStationList_CargoWaiting");
|
||||
SQGSStationList_CargoWaitingViaByFrom.AddConstructor<void (ScriptStationList_CargoWaitingViaByFrom::*)(StationID station_id, CargoID cargo, StationID via), 4>(engine, "xiii");
|
||||
|
||||
SQGSStationList_CargoWaitingViaByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingByVia, ST_GS>() { return "GSStationList_CargoWaitingByVia"; }
|
||||
|
||||
void SQGSStationList_CargoWaitingByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingByVia, ST_GS> SQGSStationList_CargoWaitingByVia("GSStationList_CargoWaitingByVia");
|
||||
SQGSStationList_CargoWaitingByVia.PreRegister(engine, "GSStationList_CargoWaiting");
|
||||
SQGSStationList_CargoWaitingByVia.AddConstructor<void (ScriptStationList_CargoWaitingByVia::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQGSStationList_CargoWaitingByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoWaitingFromByVia, ST_GS>() { return "GSStationList_CargoWaitingFromByVia"; }
|
||||
|
||||
void SQGSStationList_CargoWaitingFromByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoWaitingFromByVia, ST_GS> SQGSStationList_CargoWaitingFromByVia("GSStationList_CargoWaitingFromByVia");
|
||||
SQGSStationList_CargoWaitingFromByVia.PreRegister(engine, "GSStationList_CargoWaiting");
|
||||
SQGSStationList_CargoWaitingFromByVia.AddConstructor<void (ScriptStationList_CargoWaitingFromByVia::*)(StationID station_id, CargoID cargo, StationID from), 4>(engine, "xiii");
|
||||
|
||||
SQGSStationList_CargoWaitingFromByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedByFrom, ST_GS>() { return "GSStationList_CargoPlannedByFrom"; }
|
||||
|
||||
void SQGSStationList_CargoPlannedByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedByFrom, ST_GS> SQGSStationList_CargoPlannedByFrom("GSStationList_CargoPlannedByFrom");
|
||||
SQGSStationList_CargoPlannedByFrom.PreRegister(engine, "GSStationList_CargoPlanned");
|
||||
SQGSStationList_CargoPlannedByFrom.AddConstructor<void (ScriptStationList_CargoPlannedByFrom::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQGSStationList_CargoPlannedByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedViaByFrom, ST_GS>() { return "GSStationList_CargoPlannedViaByFrom"; }
|
||||
|
||||
void SQGSStationList_CargoPlannedViaByFrom_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedViaByFrom, ST_GS> SQGSStationList_CargoPlannedViaByFrom("GSStationList_CargoPlannedViaByFrom");
|
||||
SQGSStationList_CargoPlannedViaByFrom.PreRegister(engine, "GSStationList_CargoPlanned");
|
||||
SQGSStationList_CargoPlannedViaByFrom.AddConstructor<void (ScriptStationList_CargoPlannedViaByFrom::*)(StationID station_id, CargoID cargo, StationID via), 4>(engine, "xiii");
|
||||
|
||||
SQGSStationList_CargoPlannedViaByFrom.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedByVia, ST_GS>() { return "GSStationList_CargoPlannedByVia"; }
|
||||
|
||||
void SQGSStationList_CargoPlannedByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedByVia, ST_GS> SQGSStationList_CargoPlannedByVia("GSStationList_CargoPlannedByVia");
|
||||
SQGSStationList_CargoPlannedByVia.PreRegister(engine, "GSStationList_CargoPlanned");
|
||||
SQGSStationList_CargoPlannedByVia.AddConstructor<void (ScriptStationList_CargoPlannedByVia::*)(StationID station_id, CargoID cargo), 3>(engine, "xii");
|
||||
|
||||
SQGSStationList_CargoPlannedByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_CargoPlannedFromByVia, ST_GS>() { return "GSStationList_CargoPlannedFromByVia"; }
|
||||
|
||||
void SQGSStationList_CargoPlannedFromByVia_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptStationList_CargoPlannedFromByVia, ST_GS> SQGSStationList_CargoPlannedFromByVia("GSStationList_CargoPlannedFromByVia");
|
||||
SQGSStationList_CargoPlannedFromByVia.PreRegister(engine, "GSStationList_CargoPlanned");
|
||||
SQGSStationList_CargoPlannedFromByVia.AddConstructor<void (ScriptStationList_CargoPlannedFromByVia::*)(StationID station_id, CargoID cargo, StationID from), 4>(engine, "xiii");
|
||||
|
||||
SQGSStationList_CargoPlannedFromByVia.PostRegister(engine);
|
||||
}
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptStationList_Vehicle, ST_GS>() { return "GSStationList_Vehicle"; }
|
||||
|
||||
void SQGSStationList_Vehicle_Register(Squirrel *engine)
|
||||
|
||||
@@ -213,6 +213,9 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AP_BTN_DONTHILIGHT, "WID_AP_BTN_DONTHILIGHT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_AP_BTN_DOHILIGHT, "WID_AP_BTN_DOHILIGHT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_CAPTION, "WID_RV_CAPTION");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SORT_ASCENDING_DESCENDING, "WID_RV_SORT_ASCENDING_DESCENDING");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SHOW_HIDDEN_ENGINES, "WID_RV_SHOW_HIDDEN_ENGINES");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SORT_DROPDOWN, "WID_RV_SORT_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_LEFT_MATRIX, "WID_RV_LEFT_MATRIX");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_LEFT_SCROLLBAR, "WID_RV_LEFT_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_RIGHT_MATRIX, "WID_RV_RIGHT_MATRIX");
|
||||
@@ -237,13 +240,15 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BBS_BRIDGE_LIST, "WID_BBS_BRIDGE_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BBS_SCROLLBAR, "WID_BBS_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_CAPTION, "WID_BV_CAPTION");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SORT_ASSENDING_DESCENDING, "WID_BV_SORT_ASSENDING_DESCENDING");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SORT_ASCENDING_DESCENDING, "WID_BV_SORT_ASCENDING_DESCENDING");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SORT_DROPDOWN, "WID_BV_SORT_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_CARGO_FILTER_DROPDOWN, "WID_BV_CARGO_FILTER_DROPDOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SHOW_HIDDEN_ENGINES, "WID_BV_SHOW_HIDDEN_ENGINES");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_LIST, "WID_BV_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SCROLLBAR, "WID_BV_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_PANEL, "WID_BV_PANEL");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_BUILD, "WID_BV_BUILD");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_SHOW_HIDE, "WID_BV_SHOW_HIDE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_BUILD_SEL, "WID_BV_BUILD_SEL");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BV_RENAME, "WID_BV_RENAME");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_C_PANEL, "WID_C_PANEL");
|
||||
@@ -456,6 +461,9 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
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_GENERATE_BUTTON, "WID_GL_GENERATE_BUTTON");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_MAX_HEIGHTLEVEL_DOWN, "WID_GL_MAX_HEIGHTLEVEL_DOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_MAX_HEIGHTLEVEL_TEXT, "WID_GL_MAX_HEIGHTLEVEL_TEXT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_MAX_HEIGHTLEVEL_UP, "WID_GL_MAX_HEIGHTLEVEL_UP");
|
||||
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");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_START_DATE_UP, "WID_GL_START_DATE_UP");
|
||||
@@ -768,10 +776,12 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_RIGHT, "WID_SA_RIGHT");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_DOWN, "WID_SA_DOWN");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_SPRITE, "WID_SA_SPRITE");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_OFFSETS, "WID_SA_OFFSETS");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_OFFSETS_ABS, "WID_SA_OFFSETS_ABS");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_OFFSETS_REL, "WID_SA_OFFSETS_REL");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_PICKER, "WID_SA_PICKER");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_LIST, "WID_SA_LIST");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_SCROLLBAR, "WID_SA_SCROLLBAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SA_RESET_REL, "WID_SA_RESET_REL");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NP_SHOW_NUMPAR, "WID_NP_SHOW_NUMPAR");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NP_NUMPAR_DEC, "WID_NP_NUMPAR_DEC");
|
||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NP_NUMPAR_INC, "WID_NP_NUMPAR_INC");
|
||||
@@ -998,6 +1008,7 @@ 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_GUI_ZOOM_DROPDOWN, "WID_GO_GUI_ZOOM_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");
|
||||
|
||||
@@ -15,12 +15,52 @@
|
||||
* functions may still be available if you return an older API version
|
||||
* in GetAPIVersion() in info.nut.
|
||||
*
|
||||
* \b 1.6.0
|
||||
*
|
||||
* 1.6.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* \b 1.5.3
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.2
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.1
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.5.0
|
||||
*
|
||||
* 1.5.0 is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li GSList::SwapList
|
||||
* \li GSStation::GetCargoPlanned
|
||||
* \li GSStation::GetCargoPlannedFrom
|
||||
* \li GSStation::GetCargoPlannedFromVia
|
||||
* \li GSStation::GetCargoPlannedVia
|
||||
* \li GSStation::GetCargoWaitingFromVia
|
||||
* \li GSStationList_CargoPlannedByFrom
|
||||
* \li GSStationList_CargoPlannedByVia
|
||||
* \li GSStationList_CargoPlannedFromByVia
|
||||
* \li GSStationList_CargoPlannedViaByFrom
|
||||
* \li GSStationList_CargoWaitingByFrom
|
||||
* \li GSStationList_CargoWaitingByVia
|
||||
* \li GSStationList_CargoWaitingFromByVia
|
||||
* \li GSStationList_CargoWaitingViaByFrom
|
||||
*
|
||||
* Other changes:
|
||||
* \li GSNews::Create takes two extra parameters to refer to a location, station,
|
||||
* industry, or town. The user can click at the news message to jump to the
|
||||
* referred location.
|
||||
*
|
||||
* \b 1.4.4
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.3
|
||||
*
|
||||
* No changes
|
||||
*
|
||||
* \b 1.4.2
|
||||
*
|
||||
|
||||
@@ -37,12 +37,9 @@
|
||||
}
|
||||
|
||||
case OT_STRING: {
|
||||
const SQChar *res;
|
||||
sq_getstring(vm, index, &res);
|
||||
const SQChar *buf;
|
||||
sq_getstring(vm, index, &buf);
|
||||
|
||||
/* @bug if a string longer than 512 characters is given to SQ2OTTD, the
|
||||
* internal buffer overflows. */
|
||||
const char *buf = SQ2OTTD(res);
|
||||
size_t len = strlen(buf) + 1;
|
||||
if (len >= 255) {
|
||||
ScriptLog::Error("Maximum string length is 254 chars. No data sent.");
|
||||
@@ -129,10 +126,10 @@
|
||||
|
||||
/* static */ SQInteger ScriptAdmin::Send(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettop(vm) - 1 != 1) return sq_throwerror(vm, _SC("wrong number of parameters"));
|
||||
if (sq_gettop(vm) - 1 != 1) return sq_throwerror(vm, "wrong number of parameters");
|
||||
|
||||
if (sq_gettype(vm, 2) != OT_TABLE) {
|
||||
return sq_throwerror(vm, _SC("ScriptAdmin::Send requires a table as first parameter. No data sent."));
|
||||
return sq_throwerror(vm, "ScriptAdmin::Send requires a table as first parameter. No data sent.");
|
||||
}
|
||||
|
||||
std::string json;
|
||||
|
||||
@@ -90,8 +90,15 @@ public:
|
||||
* @param cargo_type The cargo to get the string representation of.
|
||||
* @pre ScriptCargo::IsValidCargo(cargo_type).
|
||||
* @return The cargo label.
|
||||
* @note Never use this to check if it is a certain cargo. NewGRF can
|
||||
* redefine all of the names.
|
||||
* @note
|
||||
* - The label uniquely identifies a specific cargo. Use this if you want to
|
||||
* detect special cargos from specific industry set (like production booster cargos, supplies, ...).
|
||||
* - For more generic cargo support, rather check cargo properties though. For example:
|
||||
* - Use ScriptCargo::HasCargoClass(..., CC_PASSENGER) to decide bus vs. truck requirements.
|
||||
* - Use ScriptCargo::GetTownEffect(...) paired with ScriptTown::GetCargoGoal(...) to determine
|
||||
* town growth requirements.
|
||||
* - In other words: Only use the cargo label, if you know more about the behaviour
|
||||
* of a specific cargo from a specific industry set, than the API methods can tell you.
|
||||
*/
|
||||
static char *GetCargoLabel(CargoID cargo_type);
|
||||
|
||||
|
||||
@@ -230,8 +230,8 @@
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(false, expenses_type < (ExpensesType)::EXPENSES_END);
|
||||
EnforcePrecondition(false, delta >= INT32_MIN);
|
||||
EnforcePrecondition(false, delta <= INT32_MAX);
|
||||
EnforcePrecondition(false, (int64)delta >= INT32_MIN);
|
||||
EnforcePrecondition(false, (int64)delta <= INT32_MAX);
|
||||
|
||||
company = ResolveCompanyID(company);
|
||||
EnforcePrecondition(false, company != COMPANY_INVALID);
|
||||
|
||||
@@ -192,6 +192,7 @@ public:
|
||||
* @param company The company to change the bank balance of.
|
||||
* @param delta Amount of money to give or take from the bank balance. A positive value adds money to the bank balance.
|
||||
* @param expenses_type The account in the finances window that will register the cost.
|
||||
* @return True, if the bank balance was changed.
|
||||
* @game @pre No ScriptCompanyMode active in scope.
|
||||
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @pre delta >= -2**31
|
||||
|
||||
@@ -122,7 +122,7 @@ ScriptController::~ScriptController()
|
||||
if (lib == NULL) {
|
||||
char error[1024];
|
||||
seprintf(error, lastof(error), "couldn't find library '%s' with version %d", library, version);
|
||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
||||
throw sq_throwerror(vm, error);
|
||||
}
|
||||
|
||||
/* Get the current table/class we belong to */
|
||||
@@ -142,13 +142,13 @@ ScriptController::~ScriptController()
|
||||
|
||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, OTTD2SQ(fake_class), -1);
|
||||
sq_pushstring(vm, fake_class, -1);
|
||||
sq_newclass(vm, SQFalse);
|
||||
/* Load the library */
|
||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
char error[1024];
|
||||
seprintf(error, lastof(error), "there was a compile error when importing '%s' version %d", library, version);
|
||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
||||
throw sq_throwerror(vm, error);
|
||||
}
|
||||
/* Create the fake class */
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
@@ -159,15 +159,15 @@ ScriptController::~ScriptController()
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, OTTD2SQ(fake_class), -1);
|
||||
sq_pushstring(vm, fake_class, -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
throw sq_throwerror(vm, _SC("internal error assigning library class"));
|
||||
throw sq_throwerror(vm, "internal error assigning library class");
|
||||
}
|
||||
sq_pushstring(vm, OTTD2SQ(lib->GetInstanceName()), -1);
|
||||
sq_pushstring(vm, lib->GetInstanceName(), -1);
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
char error[1024];
|
||||
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));
|
||||
throw sq_throwerror(vm, error);
|
||||
}
|
||||
HSQOBJECT obj;
|
||||
sq_getstackobj(vm, -1, &obj);
|
||||
@@ -177,7 +177,7 @@ ScriptController::~ScriptController()
|
||||
|
||||
/* Now link the name the user wanted to our 'fake' class */
|
||||
sq_pushobject(vm, parent);
|
||||
sq_pushstring(vm, OTTD2SQ(class_name), -1);
|
||||
sq_pushstring(vm, class_name, -1);
|
||||
sq_pushobject(vm, obj);
|
||||
sq_newclass(vm, SQTrue);
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
|
||||
@@ -18,8 +18,32 @@
|
||||
|
||||
/**
|
||||
* The Controller, the class each Script should extend. It creates the Script,
|
||||
* makes sure the logic kicks in correctly, and that GetTick() has a valid
|
||||
* makes sure the logic kicks in correctly, and that #GetTick() has a valid
|
||||
* value.
|
||||
*
|
||||
* When starting a new game, or when loading a game, OpenTTD tries to match a
|
||||
* script that matches to the specified version as close as possible. It tries
|
||||
* (from first to last, stopping as soon as the attempt succeeds)
|
||||
*
|
||||
* - load the exact same version of the same script,
|
||||
* - load the latest version of the same script that supports loading data from
|
||||
* the saved version (the version of saved data must be equal or greater
|
||||
* than ScriptInfo::MinVersionToLoad),
|
||||
* - load the latest version of the same script (ignoring version requirements),
|
||||
* - (for AIs) load a random AI, and finally
|
||||
* - (for AIs) load the dummy AI.
|
||||
*
|
||||
* After determining the script to use, starting it is done as follows
|
||||
*
|
||||
* - An instance is constructed of the class derived from ScriptController
|
||||
* (class name is retrieved from ScriptInfo::CreateInstance).
|
||||
* - If there is script data available in the loaded game and if the data is
|
||||
* loadable according to ScriptInfo::MinVersionToLoad, #Load is called with the
|
||||
* data from the loaded game.
|
||||
* - Finally, #Start is called to start execution of the script.
|
||||
*
|
||||
* See also http://wiki.openttd.org/AI:Save/Load for more details.
|
||||
*
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptController {
|
||||
@@ -46,6 +70,48 @@ public:
|
||||
*/
|
||||
void Start();
|
||||
|
||||
#ifdef DOXYGEN_API
|
||||
/**
|
||||
* Save the state of the script.
|
||||
*
|
||||
* By implementing this function, you can store some data inside the savegame.
|
||||
* The function should return a table with the information you want to store.
|
||||
* You can only store:
|
||||
*
|
||||
* - integers,
|
||||
* - strings,
|
||||
* - arrays (max. 25 levels deep),
|
||||
* - tables (max. 25 levels deep),
|
||||
* - booleans, and
|
||||
* - nulls.
|
||||
*
|
||||
* In particular, instances of classes can't be saved including
|
||||
* ScriptList. Such a list should be converted to an array or table on
|
||||
* save and converted back on load.
|
||||
*
|
||||
* The function is called as soon as the user saves the game,
|
||||
* independently of other activities of the script. The script is not
|
||||
* notified of the call. To avoid race-conditions between #Save and the
|
||||
* other script code, change variables directly after a #Sleep, it is
|
||||
* very unlikely, to get interrupted at that point in the execution.
|
||||
* See also http://wiki.openttd.org/AI:Save/Load for more details.
|
||||
*
|
||||
* @note No other information is saved than the table returned by #Save.
|
||||
* For example all pending events are lost as soon as the game is loaded.
|
||||
*
|
||||
* @return Data of the script that should be stored in the save game.
|
||||
*/
|
||||
SquirrelTable Save();
|
||||
|
||||
/**
|
||||
* Load saved data just before calling #Start.
|
||||
* The function is only called when there is data to load.
|
||||
* @param version Version number of the script that created the \a data.
|
||||
* @param data Data that was saved (return value of #Save).
|
||||
*/
|
||||
void Load(int version, SquirrelTable data);
|
||||
#endif /* DOXYGEN_API */
|
||||
|
||||
/**
|
||||
* Find at which tick your script currently is.
|
||||
* @return returns the current tick.
|
||||
|
||||
@@ -108,7 +108,6 @@ public:
|
||||
* Get the maximum speed of an engine.
|
||||
* @param engine_id The engine to get the maximum speed of.
|
||||
* @pre IsValidEngine(engine_id).
|
||||
* @pre GetVehicleType(engine_id) != ScriptVehicle::VT_TRAIN || !IsWagon(engine_id).
|
||||
* @return The maximum speed the engine has.
|
||||
* @note The speed is in OpenTTD's internal speed unit.
|
||||
* This is mph / 1.6, which is roughly km/h.
|
||||
|
||||
@@ -171,7 +171,7 @@ char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, char *p)
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
sq_pushstring(vm, OTTD2SQ(value), -1);
|
||||
sq_pushstring(vm, value, -1);
|
||||
*p++ = '"';
|
||||
|
||||
return p;
|
||||
@@ -259,10 +259,10 @@ char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p)
|
||||
sq_newarray(vm, 0);
|
||||
|
||||
/* Empty array? */
|
||||
char *p2 = p+1;
|
||||
char *p2 = p + 1;
|
||||
SKIP_EMPTY(p2);
|
||||
if (*p2 == ']') {
|
||||
p = p2+1;
|
||||
p = p2 + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ ScriptExecMode::ScriptExecMode()
|
||||
this->SetDoCommandMode(&ScriptExecMode::ModeProc, this);
|
||||
}
|
||||
|
||||
ScriptExecMode::~ScriptExecMode()
|
||||
void ScriptExecMode::FinalRelease()
|
||||
{
|
||||
if (this->GetDoCommandModeInstance() != this) {
|
||||
/* Ignore this error if the script already died. */
|
||||
@@ -38,5 +38,9 @@ ScriptExecMode::~ScriptExecMode()
|
||||
throw Script_FatalError("ScriptExecMode object was removed while it was not the latest *Mode object created.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptExecMode::~ScriptExecMode()
|
||||
{
|
||||
this->SetDoCommandMode(this->last_mode, this->last_instance);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
* in when the instance was created.
|
||||
*/
|
||||
~ScriptExecMode();
|
||||
|
||||
virtual void FinalRelease();
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_EXECMODE_HPP */
|
||||
|
||||
+101
-67
@@ -21,9 +21,9 @@
|
||||
*/
|
||||
class ScriptListSorter {
|
||||
protected:
|
||||
ScriptList *list; ///< The list that's being sorted.
|
||||
ScriptList *list; ///< The list that's being sorted.
|
||||
bool has_no_more_items; ///< Whether we have more items to iterate over.
|
||||
int32 item_next; ///< The next item we will show.
|
||||
int64 item_next; ///< The next item we will show.
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
/**
|
||||
* Get the first item of the sorter.
|
||||
*/
|
||||
virtual int32 Begin() = 0;
|
||||
virtual int64 Begin() = 0;
|
||||
|
||||
/**
|
||||
* Stop iterating a sorter.
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
/**
|
||||
* Get the next item of the sorter.
|
||||
*/
|
||||
virtual int32 Next() = 0;
|
||||
virtual int64 Next() = 0;
|
||||
|
||||
/**
|
||||
* See if the sorter has reached the end.
|
||||
@@ -58,6 +58,17 @@ public:
|
||||
* Callback from the list if an item gets removed.
|
||||
*/
|
||||
virtual void Remove(int item) = 0;
|
||||
|
||||
/**
|
||||
* Attach the sorter to a new list. This assumes the content of the old list has been moved to
|
||||
* the new list, too, so that we don't have to invalidate any iterators. Note that std::swap
|
||||
* doesn't invalidate iterators on lists and maps, so that should be safe.
|
||||
* @param target New list to attach to.
|
||||
*/
|
||||
virtual void Retarget(ScriptList *new_list)
|
||||
{
|
||||
this->list = new_list;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -80,7 +91,7 @@ public:
|
||||
this->End();
|
||||
}
|
||||
|
||||
int32 Begin()
|
||||
int64 Begin()
|
||||
{
|
||||
if (this->list->buckets.empty()) return 0;
|
||||
this->has_no_more_items = false;
|
||||
@@ -90,7 +101,7 @@ public:
|
||||
this->bucket_list_iter = this->bucket_list->begin();
|
||||
this->item_next = *this->bucket_list_iter;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -125,11 +136,11 @@ public:
|
||||
this->item_next = *this->bucket_list_iter;
|
||||
}
|
||||
|
||||
int32 Next()
|
||||
int64 Next()
|
||||
{
|
||||
if (this->IsEnd()) return 0;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -169,7 +180,7 @@ public:
|
||||
this->End();
|
||||
}
|
||||
|
||||
int32 Begin()
|
||||
int64 Begin()
|
||||
{
|
||||
if (this->list->buckets.empty()) return 0;
|
||||
this->has_no_more_items = false;
|
||||
@@ -184,7 +195,7 @@ public:
|
||||
--this->bucket_list_iter;
|
||||
this->item_next = *this->bucket_list_iter;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -222,11 +233,11 @@ public:
|
||||
this->item_next = *this->bucket_list_iter;
|
||||
}
|
||||
|
||||
int32 Next()
|
||||
int64 Next()
|
||||
{
|
||||
if (this->IsEnd()) return 0;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -261,7 +272,7 @@ public:
|
||||
this->End();
|
||||
}
|
||||
|
||||
int32 Begin()
|
||||
int64 Begin()
|
||||
{
|
||||
if (this->list->items.empty()) return 0;
|
||||
this->has_no_more_items = false;
|
||||
@@ -269,7 +280,7 @@ public:
|
||||
this->item_iter = this->list->items.begin();
|
||||
this->item_next = (*this->item_iter).first;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -292,11 +303,11 @@ public:
|
||||
if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first;
|
||||
}
|
||||
|
||||
int32 Next()
|
||||
int64 Next()
|
||||
{
|
||||
if (this->IsEnd()) return 0;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -334,7 +345,7 @@ public:
|
||||
this->End();
|
||||
}
|
||||
|
||||
int32 Begin()
|
||||
int64 Begin()
|
||||
{
|
||||
if (this->list->items.empty()) return 0;
|
||||
this->has_no_more_items = false;
|
||||
@@ -343,7 +354,7 @@ public:
|
||||
--this->item_iter;
|
||||
this->item_next = (*this->item_iter).first;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -371,11 +382,11 @@ public:
|
||||
if (this->item_iter != this->list->items.end()) item_next = (*this->item_iter).first;
|
||||
}
|
||||
|
||||
int32 Next()
|
||||
int64 Next()
|
||||
{
|
||||
if (this->IsEnd()) return 0;
|
||||
|
||||
int32 item_current = this->item_next;
|
||||
int64 item_current = this->item_next;
|
||||
FindNext();
|
||||
return item_current;
|
||||
}
|
||||
@@ -409,7 +420,7 @@ ScriptList::~ScriptList()
|
||||
delete this->sorter;
|
||||
}
|
||||
|
||||
bool ScriptList::HasItem(int32 item)
|
||||
bool ScriptList::HasItem(int64 item)
|
||||
{
|
||||
return this->items.count(item) == 1;
|
||||
}
|
||||
@@ -423,39 +434,40 @@ void ScriptList::Clear()
|
||||
this->sorter->End();
|
||||
}
|
||||
|
||||
void ScriptList::AddItem(int32 item, int32 value)
|
||||
void ScriptList::AddItem(int64 item, int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
if (this->HasItem(item)) return;
|
||||
|
||||
this->items[item] = 0;
|
||||
this->buckets[0].insert(item);
|
||||
|
||||
this->SetValue(item, value);
|
||||
this->items[item] = value;
|
||||
this->buckets[value].insert(item);
|
||||
}
|
||||
|
||||
void ScriptList::RemoveItem(int32 item)
|
||||
void ScriptList::RemoveItem(int64 item)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
if (!this->HasItem(item)) return;
|
||||
ScriptListMap::iterator item_iter = this->items.find(item);
|
||||
if (item_iter == this->items.end()) return;
|
||||
|
||||
int32 value = this->GetValue(item);
|
||||
int64 value = item_iter->second;
|
||||
|
||||
this->sorter->Remove(item);
|
||||
this->buckets[value].erase(item);
|
||||
if (this->buckets[value].empty()) this->buckets.erase(value);
|
||||
this->items.erase(item);
|
||||
ScriptListBucket::iterator bucket_iter = this->buckets.find(value);
|
||||
assert(bucket_iter != this->buckets.end());
|
||||
bucket_iter->second.erase(item);
|
||||
if (bucket_iter->second.empty()) this->buckets.erase(bucket_iter);
|
||||
this->items.erase(item_iter);
|
||||
}
|
||||
|
||||
int32 ScriptList::Begin()
|
||||
int64 ScriptList::Begin()
|
||||
{
|
||||
this->initialized = true;
|
||||
return this->sorter->Begin();
|
||||
}
|
||||
|
||||
int32 ScriptList::Next()
|
||||
int64 ScriptList::Next()
|
||||
{
|
||||
if (this->initialized == false) {
|
||||
DEBUG(script, 0, "Next() is invalid as Begin() is never called");
|
||||
@@ -483,26 +495,28 @@ int32 ScriptList::Count()
|
||||
return (int32)this->items.size();
|
||||
}
|
||||
|
||||
int32 ScriptList::GetValue(int32 item)
|
||||
int64 ScriptList::GetValue(int64 item)
|
||||
{
|
||||
if (!this->HasItem(item)) return 0;
|
||||
|
||||
return this->items[item];
|
||||
ScriptListMap::const_iterator item_iter = this->items.find(item);
|
||||
return item_iter == this->items.end() ? 0 : item_iter->second;
|
||||
}
|
||||
|
||||
bool ScriptList::SetValue(int32 item, int32 value)
|
||||
bool ScriptList::SetValue(int64 item, int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
if (!this->HasItem(item)) return false;
|
||||
ScriptListMap::iterator item_iter = this->items.find(item);
|
||||
if (item_iter == this->items.end()) return false;
|
||||
|
||||
int32 value_old = this->GetValue(item);
|
||||
int64 value_old = item_iter->second;
|
||||
if (value_old == value) return true;
|
||||
|
||||
this->sorter->Remove(item);
|
||||
this->buckets[value_old].erase(item);
|
||||
if (this->buckets[value_old].empty()) this->buckets.erase(value_old);
|
||||
this->items[item] = value;
|
||||
ScriptListBucket::iterator bucket_iter = this->buckets.find(value_old);
|
||||
assert(bucket_iter != this->buckets.end());
|
||||
bucket_iter->second.erase(item);
|
||||
if (bucket_iter->second.empty()) this->buckets.erase(bucket_iter);
|
||||
item_iter->second = value;
|
||||
this->buckets[value].insert(item);
|
||||
|
||||
return true;
|
||||
@@ -542,6 +556,8 @@ void ScriptList::Sort(SorterType sorter, bool ascending)
|
||||
|
||||
void ScriptList::AddList(ScriptList *list)
|
||||
{
|
||||
if (list == this) return;
|
||||
|
||||
ScriptListMap *list_items = &list->items;
|
||||
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
|
||||
this->AddItem((*iter).first);
|
||||
@@ -549,7 +565,22 @@ void ScriptList::AddList(ScriptList *list)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::RemoveAboveValue(int32 value)
|
||||
void ScriptList::SwapList(ScriptList *list)
|
||||
{
|
||||
if (list == this) return;
|
||||
|
||||
this->items.swap(list->items);
|
||||
this->buckets.swap(list->buckets);
|
||||
Swap(this->sorter, list->sorter);
|
||||
Swap(this->sorter_type, list->sorter_type);
|
||||
Swap(this->sort_ascending, list->sort_ascending);
|
||||
Swap(this->initialized, list->initialized);
|
||||
Swap(this->modifications, list->modifications);
|
||||
this->sorter->Retarget(this);
|
||||
list->sorter->Retarget(list);
|
||||
}
|
||||
|
||||
void ScriptList::RemoveAboveValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -559,7 +590,7 @@ void ScriptList::RemoveAboveValue(int32 value)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::RemoveBelowValue(int32 value)
|
||||
void ScriptList::RemoveBelowValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -569,7 +600,7 @@ void ScriptList::RemoveBelowValue(int32 value)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::RemoveBetweenValue(int32 start, int32 end)
|
||||
void ScriptList::RemoveBetweenValue(int64 start, int64 end)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -579,7 +610,7 @@ void ScriptList::RemoveBetweenValue(int32 start, int32 end)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::RemoveValue(int32 value)
|
||||
void ScriptList::RemoveValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -667,13 +698,17 @@ void ScriptList::RemoveList(ScriptList *list)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
ScriptListMap *list_items = &list->items;
|
||||
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
|
||||
this->RemoveItem((*iter).first);
|
||||
if (list == this) {
|
||||
Clear();
|
||||
} else {
|
||||
ScriptListMap *list_items = &list->items;
|
||||
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
|
||||
this->RemoveItem((*iter).first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::KeepAboveValue(int32 value)
|
||||
void ScriptList::KeepAboveValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -683,7 +718,7 @@ void ScriptList::KeepAboveValue(int32 value)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::KeepBelowValue(int32 value)
|
||||
void ScriptList::KeepBelowValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -693,7 +728,7 @@ void ScriptList::KeepBelowValue(int32 value)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::KeepBetweenValue(int32 start, int32 end)
|
||||
void ScriptList::KeepBetweenValue(int64 start, int64 end)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -703,7 +738,7 @@ void ScriptList::KeepBetweenValue(int32 start, int32 end)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptList::KeepValue(int32 value)
|
||||
void ScriptList::KeepValue(int64 value)
|
||||
{
|
||||
this->modifications++;
|
||||
|
||||
@@ -729,14 +764,12 @@ void ScriptList::KeepBottom(int32 count)
|
||||
|
||||
void ScriptList::KeepList(ScriptList *list)
|
||||
{
|
||||
if (list == this) return;
|
||||
|
||||
this->modifications++;
|
||||
|
||||
ScriptList tmp;
|
||||
for (ScriptListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
|
||||
tmp.AddItem((*iter).first);
|
||||
tmp.SetValue((*iter).first, (*iter).second);
|
||||
}
|
||||
|
||||
tmp.AddList(this);
|
||||
tmp.RemoveList(list);
|
||||
this->RemoveList(&tmp);
|
||||
}
|
||||
@@ -748,9 +781,10 @@ SQInteger ScriptList::_get(HSQUIRRELVM vm)
|
||||
SQInteger idx;
|
||||
sq_getinteger(vm, 2, &idx);
|
||||
|
||||
if (!this->HasItem(idx)) return SQ_ERROR;
|
||||
ScriptListMap::const_iterator item_iter = this->items.find(idx);
|
||||
if (item_iter == this->items.end()) return SQ_ERROR;
|
||||
|
||||
sq_pushinteger(vm, this->GetValue(idx));
|
||||
sq_pushinteger(vm, item_iter->second);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -758,7 +792,7 @@ SQInteger ScriptList::_set(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
|
||||
if (sq_gettype(vm, 3) != OT_INTEGER && sq_gettype(vm, 3) != OT_NULL) {
|
||||
return sq_throwerror(vm, _SC("you can only assign integers to this list"));
|
||||
return sq_throwerror(vm, "you can only assign integers to this list");
|
||||
}
|
||||
|
||||
SQInteger idx, val;
|
||||
@@ -810,7 +844,7 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
|
||||
int nparam = sq_gettop(vm) - 1;
|
||||
|
||||
if (nparam < 1) {
|
||||
return sq_throwerror(vm, _SC("You need to give a least a Valuator as parameter to ScriptList::Valuate"));
|
||||
return sq_throwerror(vm, "You need to give a least a Valuator as parameter to ScriptList::Valuate");
|
||||
}
|
||||
|
||||
/* Make sure the valuator function is really a function, and not any
|
||||
@@ -818,7 +852,7 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
|
||||
* first parameter they give. */
|
||||
SQObjectType valuator_type = sq_gettype(vm, 2);
|
||||
if (valuator_type != OT_CLOSURE && valuator_type != OT_NATIVECLOSURE) {
|
||||
return sq_throwerror(vm, _SC("parameter 1 has an invalid type (expected function)"));
|
||||
return sq_throwerror(vm, "parameter 1 has an invalid type (expected function)");
|
||||
}
|
||||
|
||||
/* Don't allow docommand from a Valuator, as we can't resume in
|
||||
@@ -867,7 +901,7 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
|
||||
sq_pop(vm, nparam + 4);
|
||||
|
||||
ScriptObject::SetAllowDoCommand(backup_allow);
|
||||
return sq_throwerror(vm, _SC("return value of valuator is not valid (not integer/bool)"));
|
||||
return sq_throwerror(vm, "return value of valuator is not valid (not integer/bool)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -877,7 +911,7 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
|
||||
sq_pop(vm, nparam + 4);
|
||||
|
||||
ScriptObject::SetAllowDoCommand(backup_allow);
|
||||
return sq_throwerror(vm, _SC("modifying valuated list outside of valuator function"));
|
||||
return sq_throwerror(vm, "modifying valuated list outside of valuator function");
|
||||
}
|
||||
|
||||
this->SetValue((*iter).first, value);
|
||||
|
||||
@@ -44,9 +44,9 @@ private:
|
||||
int modifications; ///< Number of modification that has been done. To prevent changing data while valuating.
|
||||
|
||||
public:
|
||||
typedef std::set<int32> ScriptItemList; ///< The list of items inside the bucket
|
||||
typedef std::map<int32, ScriptItemList> ScriptListBucket; ///< The bucket list per value
|
||||
typedef std::map<int32, int32> ScriptListMap; ///< List per item
|
||||
typedef std::set<int64> ScriptItemList; ///< The list of items inside the bucket
|
||||
typedef std::map<int64, ScriptItemList> ScriptListBucket; ///< The bucket list per value
|
||||
typedef std::map<int64, int64> ScriptListMap; ///< List per item
|
||||
|
||||
ScriptListMap items; ///< The items in the list
|
||||
ScriptListBucket buckets; ///< The items in the list, sorted by value
|
||||
@@ -60,16 +60,16 @@ public:
|
||||
* @param item the item to add. Should be unique, otherwise it is ignored.
|
||||
* @param value the value to assign.
|
||||
*/
|
||||
void AddItem(int32 item, int32 value);
|
||||
void AddItem(int64 item, int64 value);
|
||||
#else
|
||||
void AddItem(int32 item, int32 value = 0);
|
||||
void AddItem(int64 item, int64 value = 0);
|
||||
#endif /* DOXYGEN_API */
|
||||
|
||||
/**
|
||||
* Remove a single item from the list.
|
||||
* @param item the item to remove. If not existing, it is ignored.
|
||||
*/
|
||||
void RemoveItem(int32 item);
|
||||
void RemoveItem(int64 item);
|
||||
|
||||
/**
|
||||
* Clear the list, making Count() returning 0 and IsEmpty() returning true.
|
||||
@@ -81,21 +81,21 @@ public:
|
||||
* @param item the item to check for.
|
||||
* @return true if the item is in the list.
|
||||
*/
|
||||
bool HasItem(int32 item);
|
||||
bool HasItem(int64 item);
|
||||
|
||||
/**
|
||||
* Go to the beginning of the list and return the item. To get the value use list.GetValue(list.Begin()).
|
||||
* @return the first item.
|
||||
* @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
|
||||
*/
|
||||
int32 Begin();
|
||||
int64 Begin();
|
||||
|
||||
/**
|
||||
* Go to the next item in the list and return the item. To get the value use list.GetValue(list.Next()).
|
||||
* @return the next item.
|
||||
* @note returns 0 if beyond end-of-list. Use IsEnd() to check for end-of-list.
|
||||
*/
|
||||
int32 Next();
|
||||
int64 Next();
|
||||
|
||||
/**
|
||||
* Check if a list is empty.
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
* @param item the item to get the value from
|
||||
* @return the value that belongs to this item.
|
||||
*/
|
||||
int32 GetValue(int32 item);
|
||||
int64 GetValue(int64 item);
|
||||
|
||||
/**
|
||||
* Set a value of an item directly.
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
* @note Changing values of items while looping through a list might cause
|
||||
* entries to be skipped. Be very careful with such operations.
|
||||
*/
|
||||
bool SetValue(int32 item, int32 value);
|
||||
bool SetValue(int64 item, int64 value);
|
||||
|
||||
/**
|
||||
* Sort this list by the given sorter and direction.
|
||||
@@ -152,30 +152,36 @@ public:
|
||||
*/
|
||||
void AddList(ScriptList *list);
|
||||
|
||||
/**
|
||||
* Swap the contents of two lists.
|
||||
* @param list The list that will be swapped with.
|
||||
*/
|
||||
void SwapList(ScriptList *list);
|
||||
|
||||
/**
|
||||
* Removes all items with a higher value than 'value'.
|
||||
* @param value the value above which all items are removed.
|
||||
*/
|
||||
void RemoveAboveValue(int32 value);
|
||||
void RemoveAboveValue(int64 value);
|
||||
|
||||
/**
|
||||
* Removes all items with a lower value than 'value'.
|
||||
* @param value the value below which all items are removed.
|
||||
*/
|
||||
void RemoveBelowValue(int32 value);
|
||||
void RemoveBelowValue(int64 value);
|
||||
|
||||
/**
|
||||
* Removes all items with a value above start and below end.
|
||||
* @param start the lower bound of the to be removed values (exclusive).
|
||||
* @param end the upper bound of the to be removed values (exclusive).
|
||||
*/
|
||||
void RemoveBetweenValue(int32 start, int32 end);
|
||||
void RemoveBetweenValue(int64 start, int64 end);
|
||||
|
||||
/**
|
||||
* Remove all items with this value.
|
||||
* @param value the value to remove.
|
||||
*/
|
||||
void RemoveValue(int32 value);
|
||||
void RemoveValue(int64 value);
|
||||
|
||||
/**
|
||||
* Remove the first count items.
|
||||
@@ -200,26 +206,26 @@ public:
|
||||
* Keep all items with a higher value than 'value'.
|
||||
* @param value the value above which all items are kept.
|
||||
*/
|
||||
void KeepAboveValue(int32 value);
|
||||
void KeepAboveValue(int64 value);
|
||||
|
||||
/**
|
||||
* Keep all items with a lower value than 'value'.
|
||||
* @param value the value below which all items are kept.
|
||||
*/
|
||||
void KeepBelowValue(int32 value);
|
||||
void KeepBelowValue(int64 value);
|
||||
|
||||
/**
|
||||
* Keep all items with a value above start and below end.
|
||||
* @param start the lower bound of the to be kept values (exclusive).
|
||||
* @param end the upper bound of the to be kept values (exclusive).
|
||||
*/
|
||||
void KeepBetweenValue(int32 start, int32 end);
|
||||
void KeepBetweenValue(int64 start, int64 end);
|
||||
|
||||
/**
|
||||
* Keep all items with this value.
|
||||
* @param value the value to keep.
|
||||
*/
|
||||
void KeepValue(int32 value);
|
||||
void KeepValue(int64 value);
|
||||
|
||||
/**
|
||||
* Keep the first count items, i.e. remove everything except the first count items.
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_news.hpp"
|
||||
#include "script_industry.hpp"
|
||||
#include "script_station.hpp"
|
||||
#include "script_map.hpp"
|
||||
#include "script_town.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../command_type.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company)
|
||||
/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference)
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
@@ -26,9 +30,15 @@
|
||||
EnforcePreconditionEncodedText(false, encoded);
|
||||
EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
|
||||
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
||||
EnforcePrecondition(false, (ref_type == NR_NONE) ||
|
||||
(ref_type == NR_TILE && ScriptMap::IsValidTile(reference)) ||
|
||||
(ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) ||
|
||||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
|
||||
(ref_type == NR_TOWN && ScriptTown::IsValidTown(reference)));
|
||||
|
||||
uint8 c = company;
|
||||
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||
|
||||
return ScriptObject::DoCommand(0, type | (NR_NONE << 8) | (c << 16), 0, CMD_CUSTOM_NEWS_ITEM, encoded);
|
||||
if (ref_type == NR_NONE) reference = 0;
|
||||
return ScriptObject::DoCommand(0, type | (ref_type << 8) | (c << 16), reference, CMD_CUSTOM_NEWS_ITEM, encoded);
|
||||
}
|
||||
|
||||
@@ -36,15 +36,36 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a news messages for a company.
|
||||
* Reference to a game element.
|
||||
*/
|
||||
enum NewsReferenceType {
|
||||
/* Selection of useful game elements to refer to. */
|
||||
NR_NONE = ::NR_NONE, ///< No reference supplied.
|
||||
NR_TILE = ::NR_TILE, ///< Reference location, scroll to the location when clicking on the news.
|
||||
NR_STATION = ::NR_STATION, ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted.
|
||||
NR_INDUSTRY = ::NR_INDUSTRY, ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted.
|
||||
NR_TOWN = ::NR_TOWN, ///< Reference town, scroll to the town when clicking on the news.
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a news message for everybody, or for one company.
|
||||
* @param type The type of the news.
|
||||
* @param text The text message to show (can be either a raw string, or a ScriptText object).
|
||||
* @param company The company, or COMPANY_INVALID for all companies.
|
||||
* @param ref_type Type of referred game element.
|
||||
* @param reference The referenced game element of \a ref_type.
|
||||
* - For #NR_NONE this parameter is ignored.
|
||||
* - For #NR_TILE this parameter should be a valid location (ScriptMap::IsValidTile).
|
||||
* - For #NR_STATION this parameter should be a valid stationID (ScriptStation::IsValidStation).
|
||||
* - For #NR_INDUSTRY this parameter should be a valid industryID (ScriptIndustry::IsValidIndustry).
|
||||
* - For #NR_TOWN this parameter should be a valid townID (ScriptTown::IsValidTown).
|
||||
* @return True if the action succeeded.
|
||||
* @pre type must be #NT_ECONOMY, #NT_SUBSIDIES, or #NT_GENERAL.
|
||||
* @pre text != NULL.
|
||||
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @pre The \a reference condition must be fulfilled.
|
||||
*/
|
||||
static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company);
|
||||
static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_NEWS_HPP */
|
||||
|
||||
@@ -371,8 +371,8 @@ static bool NormaliseTileOffset(int32 *tile)
|
||||
if (!::IsValidTile(tile) || !::IsValidTile(start) || !::IsValidTile(end)) return -1;
|
||||
if (::DistanceManhattan(tile, start) != 1 || ::DistanceManhattan(tile, end) != 1) return -1;
|
||||
|
||||
/* ROAD_NW ROAD_SW ROAD_SE ROAD_NE */
|
||||
static const TileIndex neighbours[] = {::TileDiffXY(0, -1), ::TileDiffXY(1, 0), ::TileDiffXY(0, 1), ::TileDiffXY(-1, 0)};
|
||||
/* ROAD_NW ROAD_SW ROAD_SE ROAD_NE */
|
||||
static const TileIndexDiff neighbours[] = {::TileDiffXY(0, -1), ::TileDiffXY(1, 0), ::TileDiffXY(0, 1), ::TileDiffXY(-1, 0)};
|
||||
Array *existing = (Array*)alloca(sizeof(Array) + lengthof(neighbours) * sizeof(int32));
|
||||
existing->size = 0;
|
||||
|
||||
|
||||
@@ -39,14 +39,25 @@
|
||||
return ::GetStationIndex(tile);
|
||||
}
|
||||
|
||||
template<bool Tfrom, bool Tvia>
|
||||
/* static */ bool ScriptStation::IsCargoRequestValid(StationID station_id,
|
||||
StationID from_station_id, StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return false;
|
||||
if (Tfrom && !IsValidStation(from_station_id) && from_station_id != STATION_INVALID) return false;
|
||||
if (Tvia && !IsValidStation(via_station_id) && via_station_id != STATION_INVALID) return false;
|
||||
if (!ScriptCargo::IsValidCargo(cargo_id)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
if (!ScriptStation::IsCargoRequestValid<Tfrom, Tvia>(station_id, from_station_id,
|
||||
via_station_id, cargo_id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
if (!Tfrom && !Tvia) return cargo_list.TotalCount();
|
||||
@@ -87,6 +98,47 @@ template<bool Tfrom, bool Tvia>
|
||||
return CountCargoWaiting<true, true>(station_id, from_station_id, via_station_id, cargo_id);
|
||||
}
|
||||
|
||||
template<bool Tfrom, bool Tvia>
|
||||
/* static */ int32 ScriptStation::CountCargoPlanned(StationID station_id,
|
||||
StationID from_station_id, StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!ScriptStation::IsCargoRequestValid<Tfrom, Tvia>(station_id, from_station_id,
|
||||
via_station_id, cargo_id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const FlowStatMap &flows = ::Station::Get(station_id)->goods[cargo_id].flows;
|
||||
if (Tfrom) {
|
||||
return Tvia ? flows.GetFlowFromVia(from_station_id, via_station_id) :
|
||||
flows.GetFlowFrom(from_station_id);
|
||||
} else {
|
||||
return Tvia ? flows.GetFlowVia(via_station_id) : flows.GetFlow();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoPlanned(StationID station_id, CargoID cargo_id)
|
||||
{
|
||||
return CountCargoPlanned<false, false>(station_id, STATION_INVALID, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoPlannedFrom(StationID station_id,
|
||||
StationID from_station_id, CargoID cargo_id)
|
||||
{
|
||||
return CountCargoPlanned<true, false>(station_id, from_station_id, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoPlannedVia(StationID station_id,
|
||||
StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
return CountCargoPlanned<false, true>(station_id, STATION_INVALID, via_station_id, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoPlannedFromVia(StationID station_id,
|
||||
StationID from_station_id, StationID via_station_id, CargoID cargo_id)
|
||||
{
|
||||
return CountCargoPlanned<true, true>(station_id, from_station_id, via_station_id, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)
|
||||
{
|
||||
if (!IsValidStation(station_id)) return false;
|
||||
@@ -178,7 +230,7 @@ template<bool Tfrom, bool Tvia>
|
||||
return ::Station::Get(station_id)->town->index;
|
||||
}
|
||||
|
||||
/*static */ bool ScriptStation::IsAirportClosed(StationID station_id)
|
||||
/* static */ bool ScriptStation::IsAirportClosed(StationID station_id)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidStation(station_id));
|
||||
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
|
||||
@@ -186,7 +238,7 @@ template<bool Tfrom, bool Tvia>
|
||||
return (::Station::Get(station_id)->airport.flags & AIRPORT_CLOSED_block) != 0;
|
||||
}
|
||||
|
||||
/*static */ bool ScriptStation::OpenCloseAirport(StationID station_id)
|
||||
/* static */ bool ScriptStation::OpenCloseAirport(StationID station_id)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidStation(station_id));
|
||||
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
|
||||
|
||||
@@ -127,6 +127,58 @@ public:
|
||||
*/
|
||||
static int32 GetCargoWaitingFromVia(StationID station_id, StationID from_station_id, StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* See how much cargo was planned to pass (including production and consumption) this station per month.
|
||||
* @param station_id The station to get the planned flow for.
|
||||
* @param cargo_id The cargo type to get the planned flow for.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidCargo(cargo_id).
|
||||
* @return The amount of cargo units planned to pass the station per month.
|
||||
*/
|
||||
static int32 GetCargoPlanned(StationID station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* See how much cargo from the specified origin was planned to pass (including production and consumption) this station per month.
|
||||
* @param station_id The station to get the planned flow for.
|
||||
* @param from_station_id The station the cargo originates at.
|
||||
* @param cargo_id The cargo type to get the planned flow for.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidStation(from_station_id) || from_station_id == STATION_INVALID.
|
||||
* @pre IsValidCargo(cargo_id).
|
||||
* @return The amount of cargo units from the specified origin planned to pass the station per month.
|
||||
*/
|
||||
static int32 GetCargoPlannedFrom(StationID station_id, StationID from_station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* See how much cargo was planned to pass (including production and consumption) this station per month, heading for the specified next hop.
|
||||
* @param station_id The station to get the planned flow for.
|
||||
* @param via_station_id The next station the cargo will go on to.
|
||||
* @param cargo_id The cargo type to get the planned flow for.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre IsValidStation(via_station_id) || via_station_id == STATION_INVALID.
|
||||
* @pre IsValidCargo(cargo_id).
|
||||
* @return The amount of cargo units planned to pass the station per month, going via the specified next hop.
|
||||
* @note Cargo planned to go "via" the same station that's being queried is actually planned to be consumed there.
|
||||
*/
|
||||
static int32 GetCargoPlannedVia(StationID station_id, StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
/**
|
||||
* See how much cargo from the specified origin was planned to pass this station per month,
|
||||
* heading for the specified next hop.
|
||||
* @param station_id The station to get the planned flow for.
|
||||
* @param from_station_id The station the cargo originates at.
|
||||
* @param via_station_id The next station the cargo will go on to.
|
||||
* @param cargo_id The cargo type to get the planned flow for.
|
||||
* @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 cargo units from the specified origin planned to pass the station per month, going via the specified next hop.
|
||||
* @note Cargo planned to go "via" the same station that's being queried is actually planned to be consumed there.
|
||||
* @note Cargo planned to pass "from" the same station that's being queried is actually produced there.
|
||||
*/
|
||||
static int32 GetCargoPlannedFromVia(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.
|
||||
@@ -239,15 +291,23 @@ public:
|
||||
* @param station_id The airport to modify.
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre HasStationType(station_id, STATION_AIRPORT).
|
||||
* @return True if the state could be toggled.
|
||||
* @return True if the state was toggled successfully.
|
||||
*/
|
||||
static bool OpenCloseAirport(StationID station_id);
|
||||
|
||||
private:
|
||||
template<bool Tfrom, bool Tvia>
|
||||
static bool IsCargoRequestValid(StationID station_id, StationID from_station_id,
|
||||
StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
template<bool Tfrom, bool Tvia>
|
||||
static int32 CountCargoWaiting(StationID station_id, StationID from_station_id,
|
||||
StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
template<bool Tfrom, bool Tvia>
|
||||
static int32 CountCargoPlanned(StationID station_id, StationID from_station_id,
|
||||
StationID via_station_id, CargoID cargo_id);
|
||||
|
||||
};
|
||||
|
||||
DECLARE_ENUM_AS_BIT_SET(ScriptStation::StationType)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../../stdafx.h"
|
||||
#include "script_stationlist.hpp"
|
||||
#include "script_vehicle.hpp"
|
||||
#include "script_cargo.hpp"
|
||||
#include "../../station_base.h"
|
||||
#include "../../vehicle_base.h"
|
||||
|
||||
@@ -35,3 +36,240 @@ ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id)
|
||||
if (o->IsType(OT_GOTO_STATION)) this->AddItem(o->GetDestination());
|
||||
}
|
||||
}
|
||||
|
||||
ScriptStationList_Cargo::ScriptStationList_Cargo(ScriptStationList_Cargo::CargoMode mode,
|
||||
ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo,
|
||||
StationID other_station)
|
||||
{
|
||||
switch (mode) {
|
||||
case CM_WAITING:
|
||||
ScriptStationList_CargoWaiting(selector, station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
case CM_PLANNED:
|
||||
ScriptStationList_CargoPlanned(selector, station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
ScriptStationList_CargoWaiting::ScriptStationList_CargoWaiting(
|
||||
ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo,
|
||||
StationID other_station)
|
||||
{
|
||||
switch (selector) {
|
||||
case CS_BY_FROM:
|
||||
ScriptStationList_CargoWaitingByFrom(station_id, cargo).SwapList(this);
|
||||
break;
|
||||
case CS_VIA_BY_FROM:
|
||||
ScriptStationList_CargoWaitingViaByFrom(station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
case CS_BY_VIA:
|
||||
ScriptStationList_CargoWaitingByVia(station_id, cargo).SwapList(this);
|
||||
break;
|
||||
case CS_FROM_BY_VIA:
|
||||
ScriptStationList_CargoWaitingFromByVia(station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
ScriptStationList_CargoPlanned::ScriptStationList_CargoPlanned(
|
||||
ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo,
|
||||
StationID other_station)
|
||||
{
|
||||
switch (selector) {
|
||||
case CS_BY_FROM:
|
||||
ScriptStationList_CargoPlannedByFrom(station_id, cargo).SwapList(this);
|
||||
break;
|
||||
case CS_VIA_BY_FROM:
|
||||
ScriptStationList_CargoPlannedViaByFrom(station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
case CS_BY_VIA:
|
||||
ScriptStationList_CargoPlannedByVia(station_id, cargo).SwapList(this);
|
||||
break;
|
||||
case CS_FROM_BY_VIA:
|
||||
ScriptStationList_CargoPlannedFromByVia(station_id, cargo, other_station).SwapList(this);
|
||||
break;
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
class CargoCollector {
|
||||
public:
|
||||
CargoCollector(ScriptStationList_Cargo *parent, StationID station_id, CargoID cargo,
|
||||
StationID other);
|
||||
~CargoCollector() ;
|
||||
|
||||
template<ScriptStationList_Cargo::CargoSelector Tselector>
|
||||
void Update(StationID from, StationID via, uint amount);
|
||||
const GoodsEntry *GE() const { return ge; }
|
||||
|
||||
private:
|
||||
void SetValue();
|
||||
|
||||
ScriptStationList_Cargo *list;
|
||||
const GoodsEntry *ge;
|
||||
StationID other_station;
|
||||
|
||||
StationID last_key;
|
||||
uint amount;
|
||||
};
|
||||
|
||||
CargoCollector::CargoCollector(ScriptStationList_Cargo *parent,
|
||||
StationID station_id, CargoID cargo, StationID other) :
|
||||
list(parent), ge(NULL), other_station(other), last_key(INVALID_STATION), amount(0)
|
||||
{
|
||||
if (!ScriptStation::IsValidStation(station_id)) return;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return;
|
||||
this->ge = &(Station::Get(station_id)->goods[cargo]);
|
||||
}
|
||||
|
||||
CargoCollector::~CargoCollector()
|
||||
{
|
||||
this->SetValue();
|
||||
}
|
||||
|
||||
void CargoCollector::SetValue()
|
||||
{
|
||||
if (this->amount > 0) {
|
||||
if (this->list->HasItem(this->last_key)) {
|
||||
this->list->SetValue(this->last_key,
|
||||
this->list->GetValue(this->last_key) + this->amount);
|
||||
} else {
|
||||
this->list->AddItem(this->last_key, this->amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<ScriptStationList_Cargo::CargoSelector Tselector>
|
||||
void CargoCollector::Update(StationID from, StationID via, uint amount)
|
||||
{
|
||||
StationID key = INVALID_STATION;
|
||||
switch (Tselector) {
|
||||
case ScriptStationList_Cargo::CS_VIA_BY_FROM:
|
||||
if (via != this->other_station) return;
|
||||
/* fall through */
|
||||
case ScriptStationList_Cargo::CS_BY_FROM:
|
||||
key = from;
|
||||
break;
|
||||
case ScriptStationList_Cargo::CS_FROM_BY_VIA:
|
||||
if (from != this->other_station) return;
|
||||
/* fall through */
|
||||
case ScriptStationList_Cargo::CS_BY_VIA:
|
||||
key = via;
|
||||
break;
|
||||
}
|
||||
if (key == this->last_key) {
|
||||
this->amount += amount;
|
||||
} else {
|
||||
this->SetValue();
|
||||
this->amount = amount;
|
||||
this->last_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<ScriptStationList_Cargo::CargoSelector Tselector>
|
||||
void ScriptStationList_CargoWaiting::Add(StationID station_id, CargoID cargo, StationID other_station)
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, other_station);
|
||||
if (collector.GE() == NULL) return;
|
||||
|
||||
StationCargoList::ConstIterator iter = collector.GE()->cargo.Packets()->begin();
|
||||
StationCargoList::ConstIterator end = collector.GE()->cargo.Packets()->end();
|
||||
for (; iter != end; ++iter) {
|
||||
collector.Update<Tselector>((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<ScriptStationList_Cargo::CargoSelector Tselector>
|
||||
void ScriptStationList_CargoPlanned::Add(StationID station_id, CargoID cargo, StationID other_station)
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, other_station);
|
||||
if (collector.GE() == NULL) return;
|
||||
|
||||
FlowStatMap::const_iterator iter = collector.GE()->flows.begin();
|
||||
FlowStatMap::const_iterator end = collector.GE()->flows.end();
|
||||
for (; iter != end; ++iter) {
|
||||
const FlowStat::SharesMap *shares = iter->second.GetShares();
|
||||
uint prev = 0;
|
||||
for (FlowStat::SharesMap::const_iterator flow_iter = shares->begin();
|
||||
flow_iter != shares->end(); ++flow_iter) {
|
||||
collector.Update<Tselector>(iter->first, flow_iter->second, flow_iter->first - prev);
|
||||
prev = flow_iter->first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptStationList_CargoWaitingByFrom::ScriptStationList_CargoWaitingByFrom(StationID station_id,
|
||||
CargoID cargo)
|
||||
{
|
||||
this->Add<CS_BY_FROM>(station_id, cargo);
|
||||
}
|
||||
|
||||
ScriptStationList_CargoWaitingViaByFrom::ScriptStationList_CargoWaitingViaByFrom(
|
||||
StationID station_id, CargoID cargo, StationID via)
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, via);
|
||||
if (collector.GE() == NULL) return;
|
||||
|
||||
std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range =
|
||||
collector.GE()->cargo.Packets()->equal_range(via);
|
||||
for (StationCargoList::ConstIterator iter = range.first; iter != range.second; ++iter) {
|
||||
collector.Update<CS_VIA_BY_FROM>((*iter)->SourceStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ScriptStationList_CargoWaitingByVia::ScriptStationList_CargoWaitingByVia(StationID station_id,
|
||||
CargoID cargo)
|
||||
{
|
||||
this->Add<CS_BY_VIA>(station_id, cargo);
|
||||
}
|
||||
|
||||
ScriptStationList_CargoWaitingFromByVia::ScriptStationList_CargoWaitingFromByVia(
|
||||
StationID station_id, CargoID cargo, StationID from)
|
||||
{
|
||||
this->Add<CS_FROM_BY_VIA>(station_id, cargo, from);
|
||||
}
|
||||
|
||||
ScriptStationList_CargoPlannedByFrom::ScriptStationList_CargoPlannedByFrom(StationID station_id,
|
||||
CargoID cargo)
|
||||
{
|
||||
this->Add<CS_BY_FROM>(station_id, cargo);
|
||||
}
|
||||
|
||||
ScriptStationList_CargoPlannedViaByFrom::ScriptStationList_CargoPlannedViaByFrom(
|
||||
StationID station_id, CargoID cargo, StationID via)
|
||||
{
|
||||
this->Add<CS_VIA_BY_FROM>(station_id, cargo, via);
|
||||
}
|
||||
|
||||
|
||||
ScriptStationList_CargoPlannedByVia::ScriptStationList_CargoPlannedByVia(StationID station_id,
|
||||
CargoID cargo)
|
||||
{
|
||||
this->Add<CS_BY_VIA>(station_id, cargo);
|
||||
}
|
||||
|
||||
|
||||
ScriptStationList_CargoPlannedFromByVia::ScriptStationList_CargoPlannedFromByVia(
|
||||
StationID station_id, CargoID cargo, StationID from)
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, from);
|
||||
if (collector.GE() == NULL) return;
|
||||
|
||||
FlowStatMap::const_iterator iter = collector.GE()->flows.find(from);
|
||||
if (iter == collector.GE()->flows.end()) return;
|
||||
const FlowStat::SharesMap *shares = iter->second.GetShares();
|
||||
uint prev = 0;
|
||||
for (FlowStat::SharesMap::const_iterator flow_iter = shares->begin();
|
||||
flow_iter != shares->end(); ++flow_iter) {
|
||||
collector.Update<CS_FROM_BY_VIA>(iter->first, flow_iter->second, flow_iter->first - prev);
|
||||
prev = flow_iter->first;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,251 @@ public:
|
||||
ScriptStationList(ScriptStation::StationType station_type);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with cargo at a station. This is very generic. Use the
|
||||
* subclasses for all practical purposes.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_Cargo : public ScriptList {
|
||||
public:
|
||||
/**
|
||||
* Criteria of selecting and grouping cargo at a station.
|
||||
*/
|
||||
enum CargoSelector {
|
||||
CS_BY_FROM, ///< Group by origin station.
|
||||
CS_VIA_BY_FROM, ///< Select by next hop and group by origin station.
|
||||
CS_BY_VIA, ///< Group by next hop.
|
||||
CS_FROM_BY_VIA ///< Select by origin station and group by next hop.
|
||||
};
|
||||
|
||||
/**
|
||||
* Ways of associating cargo to stations.
|
||||
*/
|
||||
enum CargoMode {
|
||||
CM_WAITING, ///< Waiting cargo.
|
||||
CM_PLANNED ///< Planned cargo.
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with cargo in the specified way, selected and grouped
|
||||
* by the chosen criteria.
|
||||
* @param mode Mode of association, either waiting cargo or planned cargo.
|
||||
* @param selector Mode of grouping and selecting to be applied.
|
||||
* @param station_id Station to be queried.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param other_station Other station to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_Cargo(ScriptStationList_Cargo::CargoMode mode, ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Creates an empty list.
|
||||
*/
|
||||
ScriptStationList_Cargo() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with cargo waiting at a station. This is very generic. Use
|
||||
* the subclasses for all practical purposes.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoWaiting : public ScriptStationList_Cargo {
|
||||
protected:
|
||||
friend class ScriptStationList_Cargo;
|
||||
|
||||
/**
|
||||
* Creates an empty list.
|
||||
*/
|
||||
ScriptStationList_CargoWaiting() {}
|
||||
|
||||
/**
|
||||
* Add waiting cargo to the list.
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param other_station Other station to restrict the query with.
|
||||
*/
|
||||
template<CargoSelector Tselector>
|
||||
void Add(StationID station_id, CargoID cargo, StationID other_station = INVALID_STATION);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with waiting cargo, selected and grouped by the chosen
|
||||
* criteria.
|
||||
* @param selector Mode of grouping and selecting to be applied.
|
||||
* @param station_id Station to be queried.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param other_station Other station to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoWaiting(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with cargo planned to pass a station. This is very
|
||||
* generic. Use the subclasses for all practical purposes.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoPlanned : public ScriptStationList_Cargo {
|
||||
protected:
|
||||
friend class ScriptStationList_Cargo;
|
||||
|
||||
/**
|
||||
* Creates an empty list.
|
||||
*/
|
||||
ScriptStationList_CargoPlanned() {}
|
||||
|
||||
/**
|
||||
* Add planned cargo to the list.
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param other_station Other station to restrict the query with.
|
||||
*/
|
||||
template<CargoSelector Tselector>
|
||||
void Add(StationID station_id, CargoID cargo, StationID other_station = INVALID_STATION);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a list of stations associated with cargo planned to pass the station, selected and
|
||||
* grouped by the chosen criteria.
|
||||
* @param selector Mode of grouping and selecting to be applied.
|
||||
* @param station_id Station to be queried.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param other_station Other station to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoPlanned(ScriptStationList_Cargo::CargoSelector selector, StationID station_id, CargoID cargo, StationID other_station);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of origin stations of waiting cargo at a station, with the amounts of cargo
|
||||
* waiting from each of those origin stations as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoWaitingByFrom : public ScriptStationList_CargoWaiting {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
*/
|
||||
ScriptStationList_CargoWaitingByFrom(StationID station_id, CargoID cargo);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of origin stations of cargo waiting at a station for a transfer via another
|
||||
* station, with the amounts of cargo waiting from each of those origin stations as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoWaitingViaByFrom : public ScriptStationList_CargoWaiting {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param via Next hop to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoWaitingViaByFrom(StationID station_id, CargoID cargo, StationID via);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of next hops of waiting cargo at a station, with the amounts of cargo waiting for
|
||||
* each of those next hops as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoWaitingByVia : public ScriptStationList_CargoWaiting {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
*/
|
||||
ScriptStationList_CargoWaitingByVia(StationID station_id, CargoID cargo);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of next hops of waiting cargo from a specific station at another station, with
|
||||
* the amounts of cargo waiting for each of those next hops as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoWaitingFromByVia : public ScriptStationList_CargoWaiting {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for waiting cargo.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param from Origin station to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoWaitingFromByVia(StationID station_id, CargoID cargo, StationID from);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of origin stations of cargo planned to pass a station, with the monthly amounts
|
||||
* of cargo planned for each of those origin stations as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoPlannedByFrom : public ScriptStationList_CargoPlanned {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for planned flows.
|
||||
* @param cargo Cargo type to query for.
|
||||
*/
|
||||
ScriptStationList_CargoPlannedByFrom(StationID station_id, CargoID cargo);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of origin stations of cargo planned to pass a station going via another station,
|
||||
* with the monthly amounts of cargo planned for each of those origin stations as values.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoPlannedViaByFrom : public ScriptStationList_CargoPlanned {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for planned flows.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param via Next hop to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoPlannedViaByFrom(StationID station_id, CargoID cargo, StationID via);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of next hops of cargo planned to pass a station, with the monthly amounts of
|
||||
* cargo planned for each of those next hops as values.
|
||||
* Cargo planned to go "via" the station being queried will actually be delivered there.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoPlannedByVia : public ScriptStationList_CargoPlanned {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for planned flows.
|
||||
* @param cargo Cargo type to query for.
|
||||
*/
|
||||
ScriptStationList_CargoPlannedByVia(StationID station_id, CargoID cargo);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of next hops of cargo planned to pass a station and originating from another
|
||||
* station, with the monthly amounts of cargo planned for each of those next hops as values.
|
||||
* Cargo planned to go "via" the station being queried will actually be delivered there.
|
||||
* @api ai game
|
||||
* @ingroup ScriptList
|
||||
*/
|
||||
class ScriptStationList_CargoPlannedFromByVia : public ScriptStationList_CargoPlanned {
|
||||
public:
|
||||
/**
|
||||
* @param station_id Station to query for planned flows.
|
||||
* @param cargo Cargo type to query for.
|
||||
* @param from Origin station to restrict the query with.
|
||||
*/
|
||||
ScriptStationList_CargoPlannedFromByVia(StationID station_id, CargoID cargo, StationID from);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list of stations which the vehicle has in its orders.
|
||||
* @api ai game
|
||||
|
||||
@@ -30,7 +30,7 @@ ScriptTestMode::ScriptTestMode()
|
||||
this->SetDoCommandMode(&ScriptTestMode::ModeProc, this);
|
||||
}
|
||||
|
||||
ScriptTestMode::~ScriptTestMode()
|
||||
void ScriptTestMode::FinalRelease()
|
||||
{
|
||||
if (this->GetDoCommandModeInstance() != this) {
|
||||
/* Ignore this error if the script already died. */
|
||||
@@ -38,5 +38,9 @@ ScriptTestMode::~ScriptTestMode()
|
||||
throw Script_FatalError("Testmode object was removed while it was not the latest *Mode object created.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptTestMode::~ScriptTestMode()
|
||||
{
|
||||
this->SetDoCommandMode(this->last_mode, this->last_instance);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
* in when the instance was created.
|
||||
*/
|
||||
~ScriptTestMode();
|
||||
|
||||
virtual void FinalRelease();
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_TESTMODE_HPP */
|
||||
|
||||
@@ -34,13 +34,13 @@ ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
{
|
||||
int nparam = sq_gettop(vm) - 1;
|
||||
if (nparam < 1) {
|
||||
throw sq_throwerror(vm, _SC("You need to pass at least a StringID to the constructor"));
|
||||
throw sq_throwerror(vm, "You need to pass at least a StringID to the constructor");
|
||||
}
|
||||
|
||||
/* First resolve the StringID. */
|
||||
SQInteger sqstring;
|
||||
if (SQ_FAILED(sq_getinteger(vm, 2, &sqstring))) {
|
||||
throw sq_throwerror(vm, _SC("First argument must be a valid StringID"));
|
||||
throw sq_throwerror(vm, "First argument must be a valid StringID");
|
||||
}
|
||||
this->string = sqstring;
|
||||
|
||||
@@ -51,7 +51,7 @@ ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
|
||||
if (SQ_FAILED(this->_SetParam(i, vm))) {
|
||||
this->~ScriptText();
|
||||
throw sq_throwerror(vm, _SC("Invalid parameter"));
|
||||
throw sq_throwerror(vm, "Invalid parameter");
|
||||
}
|
||||
|
||||
/* Pop the parameter again. */
|
||||
@@ -83,7 +83,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
const SQChar *value;
|
||||
sq_getstring(vm, -1, &value);
|
||||
|
||||
this->params[parameter] = stredup(SQ2OTTD(value));
|
||||
this->params[parameter] = stredup(value);
|
||||
ValidateString(this->params[parameter]);
|
||||
break;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
|
||||
/* Validate if it is a GSText instance */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, _SC("GSText"), -1);
|
||||
sq_pushstring(vm, "GSText", -1);
|
||||
sq_get(vm, -2);
|
||||
sq_pushobject(vm, instance);
|
||||
if (sq_instanceof(vm) != SQTrue) return SQ_ERROR;
|
||||
@@ -157,9 +157,8 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
|
||||
int32 k;
|
||||
|
||||
if (sq_gettype(vm, 2) == OT_STRING) {
|
||||
const SQChar *key;
|
||||
sq_getstring(vm, 2, &key);
|
||||
const char *key_string = SQ2OTTD(key);
|
||||
const SQChar *key_string;
|
||||
sq_getstring(vm, 2, &key_string);
|
||||
ValidateString(key_string);
|
||||
|
||||
if (strncmp(key_string, "param_", 6) != 0 || strlen(key_string) > 8) return SQ_ERROR;
|
||||
@@ -202,7 +201,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||
p = this->paramt[i]->_GetEncodedText(p, lastofp, param_count);
|
||||
continue;
|
||||
}
|
||||
p += seprintf(p, lastofp,":%X", (uint32)this->parami[i]);
|
||||
p += seprintf(p, lastofp,":" OTTD_PRINTFHEX64, this->parami[i]);
|
||||
param_count++;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
private:
|
||||
StringID string;
|
||||
char *params[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
int parami[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
int64 parami[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
ScriptText *paramt[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
int paramc;
|
||||
|
||||
|
||||
@@ -65,9 +65,10 @@ class ScriptTileList_IndustryAccepting : public ScriptTileList {
|
||||
public:
|
||||
/**
|
||||
* @param industry_id The industry to create the ScriptTileList around.
|
||||
* @param radius The radius of the station you will be using.
|
||||
* @param radius The coverage radius of the station type you will be using.
|
||||
* @pre ScriptIndustry::IsValidIndustry(industry_id).
|
||||
* @pre radius > 0.
|
||||
* @note A station part built on any of the returned tiles will give you coverage.
|
||||
*/
|
||||
ScriptTileList_IndustryAccepting(IndustryID industry_id, int radius);
|
||||
};
|
||||
@@ -82,9 +83,10 @@ class ScriptTileList_IndustryProducing : public ScriptTileList {
|
||||
public:
|
||||
/**
|
||||
* @param industry_id The industry to create the ScriptTileList around.
|
||||
* @param radius The radius of the station you will be using.
|
||||
* @param radius The coverage radius of the station type you will be using.
|
||||
* @pre ScriptIndustry::IsValidIndustry(industry_id).
|
||||
* @pre radius > 0.
|
||||
* @note A station part built on any of the returned tiles will give you acceptance.
|
||||
*/
|
||||
ScriptTileList_IndustryProducing(IndustryID industry_id, int radius);
|
||||
};
|
||||
|
||||
@@ -232,10 +232,10 @@ public:
|
||||
/**
|
||||
* Set the goal of a cargo for this town.
|
||||
* @param town_id The index of the town.
|
||||
* @param towneffect_id The index of the cargo.
|
||||
* @param towneffect_id The index of the towneffect.
|
||||
* @param goal The new goal.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre ScriptCargo::IsValidTownEffect(cargo_id).
|
||||
* @pre ScriptCargo::IsValidTownEffect(towneffect_id).
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -247,7 +247,7 @@ public:
|
||||
* @param town_id The index of the town.
|
||||
* @param towneffect_id The index of the towneffect.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre ScriptCargo::IsValidTownEffect(cargo_id).
|
||||
* @pre ScriptCargo::IsValidTownEffect(towneffect_id).
|
||||
* @return The goal of the cargo.
|
||||
* @note Goals can change over time. For example with a changing snowline, or
|
||||
* with a growing town.
|
||||
@@ -263,6 +263,7 @@ public:
|
||||
* @return True if the action succeeded.
|
||||
* @note Even when setting a growth rate, towns only grow when the conditions for growth (SetCargoCoal) are met,
|
||||
* and the game settings (economy.town_growth_rate) allow town growth at all.
|
||||
* @note When changing the growth rate, the relative progress is preserved and scaled to the new rate.
|
||||
* @api -ai
|
||||
*/
|
||||
static bool SetGrowthRate(TownID town_id, uint32 days_between_town_growth);
|
||||
|
||||
@@ -536,7 +536,7 @@ public:
|
||||
/**
|
||||
* Generate landscape (newgame); %Window numbers:
|
||||
* - GLWM_SCENARIO = #CreateScenarioWidgets
|
||||
* - #GenenerateLandscapeWindowMode = #GenerateLandscapeWidgets
|
||||
* - #GenerateLandscapeWindowMode = #GenerateLandscapeWidgets
|
||||
*/
|
||||
WC_GENERATE_LANDSCAPE = ::WC_GENERATE_LANDSCAPE,
|
||||
|
||||
@@ -930,6 +930,11 @@ public:
|
||||
enum ReplaceVehicleWidgets {
|
||||
WID_RV_CAPTION = ::WID_RV_CAPTION, ///< Caption of the window.
|
||||
|
||||
/* Sort dropdown at the right. */
|
||||
WID_RV_SORT_ASCENDING_DESCENDING = ::WID_RV_SORT_ASCENDING_DESCENDING, ///< Ascending/descending sort order button.
|
||||
WID_RV_SHOW_HIDDEN_ENGINES = ::WID_RV_SHOW_HIDDEN_ENGINES, ///< Toggle whether to display the hidden vehicles.
|
||||
WID_RV_SORT_DROPDOWN = ::WID_RV_SORT_DROPDOWN, ///< Dropdown for the sort criteria.
|
||||
|
||||
/* Left and right matrix + details. */
|
||||
WID_RV_LEFT_MATRIX = ::WID_RV_LEFT_MATRIX, ///< The matrix on the left.
|
||||
WID_RV_LEFT_SCROLLBAR = ::WID_RV_LEFT_SCROLLBAR, ///< The scrollbar for the matrix on the left.
|
||||
@@ -978,13 +983,15 @@ public:
|
||||
/** Widgets of the #BuildVehicleWindow class. */
|
||||
enum BuildVehicleWidgets {
|
||||
WID_BV_CAPTION = ::WID_BV_CAPTION, ///< Caption of window.
|
||||
WID_BV_SORT_ASSENDING_DESCENDING = ::WID_BV_SORT_ASSENDING_DESCENDING, ///< Sort direction.
|
||||
WID_BV_SORT_ASCENDING_DESCENDING = ::WID_BV_SORT_ASCENDING_DESCENDING, ///< Sort direction.
|
||||
WID_BV_SORT_DROPDOWN = ::WID_BV_SORT_DROPDOWN, ///< Criteria of sorting dropdown.
|
||||
WID_BV_CARGO_FILTER_DROPDOWN = ::WID_BV_CARGO_FILTER_DROPDOWN, ///< Cargo filter dropdown.
|
||||
WID_BV_SHOW_HIDDEN_ENGINES = ::WID_BV_SHOW_HIDDEN_ENGINES, ///< Toggle whether to display the hidden vehicles.
|
||||
WID_BV_LIST = ::WID_BV_LIST, ///< List of vehicles.
|
||||
WID_BV_SCROLLBAR = ::WID_BV_SCROLLBAR, ///< Scrollbar of list.
|
||||
WID_BV_PANEL = ::WID_BV_PANEL, ///< Button panel.
|
||||
WID_BV_BUILD = ::WID_BV_BUILD, ///< Build panel.
|
||||
WID_BV_SHOW_HIDE = ::WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine.
|
||||
WID_BV_BUILD_SEL = ::WID_BV_BUILD_SEL, ///< Build button.
|
||||
WID_BV_RENAME = ::WID_BV_RENAME, ///< Rename button.
|
||||
};
|
||||
@@ -1293,6 +1300,10 @@ public:
|
||||
|
||||
WID_GL_GENERATE_BUTTON = ::WID_GL_GENERATE_BUTTON, ///< 'Generate' button.
|
||||
|
||||
WID_GL_MAX_HEIGHTLEVEL_DOWN = ::WID_GL_MAX_HEIGHTLEVEL_DOWN, ///< Decrease max. heightlevel
|
||||
WID_GL_MAX_HEIGHTLEVEL_TEXT = ::WID_GL_MAX_HEIGHTLEVEL_TEXT, ///< Max. heightlevel
|
||||
WID_GL_MAX_HEIGHTLEVEL_UP = ::WID_GL_MAX_HEIGHTLEVEL_UP, ///< Increase max. heightlevel
|
||||
|
||||
WID_GL_START_DATE_DOWN = ::WID_GL_START_DATE_DOWN, ///< Decrease start year.
|
||||
WID_GL_START_DATE_TEXT = ::WID_GL_START_DATE_TEXT, ///< Start year.
|
||||
WID_GL_START_DATE_UP = ::WID_GL_START_DATE_UP, ///< Increase start year.
|
||||
@@ -1798,10 +1809,12 @@ public:
|
||||
WID_SA_RIGHT = ::WID_SA_RIGHT, ///< Move the sprite to the right.
|
||||
WID_SA_DOWN = ::WID_SA_DOWN, ///< Move the sprite down.
|
||||
WID_SA_SPRITE = ::WID_SA_SPRITE, ///< The actual sprite.
|
||||
WID_SA_OFFSETS = ::WID_SA_OFFSETS, ///< The sprite offsets.
|
||||
WID_SA_OFFSETS_ABS = ::WID_SA_OFFSETS_ABS, ///< The sprite offsets (absolute).
|
||||
WID_SA_OFFSETS_REL = ::WID_SA_OFFSETS_REL, ///< The sprite offsets (relative).
|
||||
WID_SA_PICKER = ::WID_SA_PICKER, ///< Sprite picker.
|
||||
WID_SA_LIST = ::WID_SA_LIST, ///< Queried sprite list.
|
||||
WID_SA_SCROLLBAR = ::WID_SA_SCROLLBAR, ///< Scrollbar for sprite list.
|
||||
WID_SA_RESET_REL = ::WID_SA_RESET_REL, ///< Reset relative sprite offset
|
||||
};
|
||||
|
||||
/* automatically generated from ../../widgets/newgrf_widget.h */
|
||||
@@ -2126,6 +2139,7 @@ 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_GUI_ZOOM_DROPDOWN = ::WID_GO_GUI_ZOOM_DROPDOWN, ///< Dropdown for the GUI zoom level.
|
||||
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).
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace SQConvert {
|
||||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> inline ScriptNews::NewsType GetParam(ForceType<ScriptNews::NewsType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsType)tmp; }
|
||||
template <> inline int Return<ScriptNews::NewsType>(HSQUIRRELVM vm, ScriptNews::NewsType res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptNews::NewsReferenceType GetParam(ForceType<ScriptNews::NewsReferenceType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsReferenceType)tmp; }
|
||||
template <> inline int Return<ScriptNews::NewsReferenceType>(HSQUIRRELVM vm, ScriptNews::NewsReferenceType res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow ScriptNews to be used as Squirrel parameter */
|
||||
template <> inline ScriptNews *GetParam(ForceType<ScriptNews *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptNews *)instance; }
|
||||
|
||||
@@ -20,6 +20,111 @@ namespace SQConvert {
|
||||
template <> inline int Return<ScriptStationList *>(HSQUIRRELVM vm, ScriptStationList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList", res, NULL, DefSQDestructorCallback<ScriptStationList>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> inline ScriptStationList_Cargo::CargoSelector GetParam(ForceType<ScriptStationList_Cargo::CargoSelector>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptStationList_Cargo::CargoSelector)tmp; }
|
||||
template <> inline int Return<ScriptStationList_Cargo::CargoSelector>(HSQUIRRELVM vm, ScriptStationList_Cargo::CargoSelector res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> inline ScriptStationList_Cargo::CargoMode GetParam(ForceType<ScriptStationList_Cargo::CargoMode>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptStationList_Cargo::CargoMode)tmp; }
|
||||
template <> inline int Return<ScriptStationList_Cargo::CargoMode>(HSQUIRRELVM vm, ScriptStationList_Cargo::CargoMode res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow ScriptStationList_Cargo to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_Cargo *GetParam(ForceType<ScriptStationList_Cargo *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_Cargo *)instance; }
|
||||
template <> inline ScriptStationList_Cargo &GetParam(ForceType<ScriptStationList_Cargo &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_Cargo *)instance; }
|
||||
template <> inline const ScriptStationList_Cargo *GetParam(ForceType<const ScriptStationList_Cargo *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_Cargo *)instance; }
|
||||
template <> inline const ScriptStationList_Cargo &GetParam(ForceType<const ScriptStationList_Cargo &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_Cargo *)instance; }
|
||||
template <> inline int Return<ScriptStationList_Cargo *>(HSQUIRRELVM vm, ScriptStationList_Cargo *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_Cargo", res, NULL, DefSQDestructorCallback<ScriptStationList_Cargo>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoWaiting to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoWaiting *GetParam(ForceType<ScriptStationList_CargoWaiting *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaiting *)instance; }
|
||||
template <> inline ScriptStationList_CargoWaiting &GetParam(ForceType<ScriptStationList_CargoWaiting &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaiting *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaiting *GetParam(ForceType<const ScriptStationList_CargoWaiting *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaiting *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaiting &GetParam(ForceType<const ScriptStationList_CargoWaiting &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaiting *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoWaiting *>(HSQUIRRELVM vm, ScriptStationList_CargoWaiting *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoWaiting", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoWaiting>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoPlanned to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoPlanned *GetParam(ForceType<ScriptStationList_CargoPlanned *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlanned *)instance; }
|
||||
template <> inline ScriptStationList_CargoPlanned &GetParam(ForceType<ScriptStationList_CargoPlanned &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlanned *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlanned *GetParam(ForceType<const ScriptStationList_CargoPlanned *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlanned *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlanned &GetParam(ForceType<const ScriptStationList_CargoPlanned &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlanned *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoPlanned *>(HSQUIRRELVM vm, ScriptStationList_CargoPlanned *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoPlanned", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoPlanned>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoWaitingByFrom to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoWaitingByFrom *GetParam(ForceType<ScriptStationList_CargoWaitingByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingByFrom *)instance; }
|
||||
template <> inline ScriptStationList_CargoWaitingByFrom &GetParam(ForceType<ScriptStationList_CargoWaitingByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingByFrom *GetParam(ForceType<const ScriptStationList_CargoWaitingByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingByFrom &GetParam(ForceType<const ScriptStationList_CargoWaitingByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingByFrom *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoWaitingByFrom *>(HSQUIRRELVM vm, ScriptStationList_CargoWaitingByFrom *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoWaitingByFrom", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoWaitingByFrom>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoWaitingViaByFrom to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoWaitingViaByFrom *GetParam(ForceType<ScriptStationList_CargoWaitingViaByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingViaByFrom *)instance; }
|
||||
template <> inline ScriptStationList_CargoWaitingViaByFrom &GetParam(ForceType<ScriptStationList_CargoWaitingViaByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingViaByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingViaByFrom *GetParam(ForceType<const ScriptStationList_CargoWaitingViaByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingViaByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingViaByFrom &GetParam(ForceType<const ScriptStationList_CargoWaitingViaByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingViaByFrom *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoWaitingViaByFrom *>(HSQUIRRELVM vm, ScriptStationList_CargoWaitingViaByFrom *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoWaitingViaByFrom", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoWaitingViaByFrom>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoWaitingByVia to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoWaitingByVia *GetParam(ForceType<ScriptStationList_CargoWaitingByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingByVia *)instance; }
|
||||
template <> inline ScriptStationList_CargoWaitingByVia &GetParam(ForceType<ScriptStationList_CargoWaitingByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingByVia *GetParam(ForceType<const ScriptStationList_CargoWaitingByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingByVia &GetParam(ForceType<const ScriptStationList_CargoWaitingByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingByVia *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoWaitingByVia *>(HSQUIRRELVM vm, ScriptStationList_CargoWaitingByVia *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoWaitingByVia", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoWaitingByVia>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoWaitingFromByVia to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoWaitingFromByVia *GetParam(ForceType<ScriptStationList_CargoWaitingFromByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingFromByVia *)instance; }
|
||||
template <> inline ScriptStationList_CargoWaitingFromByVia &GetParam(ForceType<ScriptStationList_CargoWaitingFromByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingFromByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingFromByVia *GetParam(ForceType<const ScriptStationList_CargoWaitingFromByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoWaitingFromByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoWaitingFromByVia &GetParam(ForceType<const ScriptStationList_CargoWaitingFromByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoWaitingFromByVia *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoWaitingFromByVia *>(HSQUIRRELVM vm, ScriptStationList_CargoWaitingFromByVia *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoWaitingFromByVia", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoWaitingFromByVia>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoPlannedByFrom to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoPlannedByFrom *GetParam(ForceType<ScriptStationList_CargoPlannedByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedByFrom *)instance; }
|
||||
template <> inline ScriptStationList_CargoPlannedByFrom &GetParam(ForceType<ScriptStationList_CargoPlannedByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedByFrom *GetParam(ForceType<const ScriptStationList_CargoPlannedByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedByFrom &GetParam(ForceType<const ScriptStationList_CargoPlannedByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedByFrom *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoPlannedByFrom *>(HSQUIRRELVM vm, ScriptStationList_CargoPlannedByFrom *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoPlannedByFrom", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoPlannedByFrom>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoPlannedViaByFrom to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoPlannedViaByFrom *GetParam(ForceType<ScriptStationList_CargoPlannedViaByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedViaByFrom *)instance; }
|
||||
template <> inline ScriptStationList_CargoPlannedViaByFrom &GetParam(ForceType<ScriptStationList_CargoPlannedViaByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedViaByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedViaByFrom *GetParam(ForceType<const ScriptStationList_CargoPlannedViaByFrom *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedViaByFrom *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedViaByFrom &GetParam(ForceType<const ScriptStationList_CargoPlannedViaByFrom &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedViaByFrom *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoPlannedViaByFrom *>(HSQUIRRELVM vm, ScriptStationList_CargoPlannedViaByFrom *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoPlannedViaByFrom", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoPlannedViaByFrom>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoPlannedByVia to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoPlannedByVia *GetParam(ForceType<ScriptStationList_CargoPlannedByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedByVia *)instance; }
|
||||
template <> inline ScriptStationList_CargoPlannedByVia &GetParam(ForceType<ScriptStationList_CargoPlannedByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedByVia *GetParam(ForceType<const ScriptStationList_CargoPlannedByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedByVia &GetParam(ForceType<const ScriptStationList_CargoPlannedByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedByVia *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoPlannedByVia *>(HSQUIRRELVM vm, ScriptStationList_CargoPlannedByVia *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoPlannedByVia", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoPlannedByVia>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_CargoPlannedFromByVia to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_CargoPlannedFromByVia *GetParam(ForceType<ScriptStationList_CargoPlannedFromByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedFromByVia *)instance; }
|
||||
template <> inline ScriptStationList_CargoPlannedFromByVia &GetParam(ForceType<ScriptStationList_CargoPlannedFromByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedFromByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedFromByVia *GetParam(ForceType<const ScriptStationList_CargoPlannedFromByVia *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_CargoPlannedFromByVia *)instance; }
|
||||
template <> inline const ScriptStationList_CargoPlannedFromByVia &GetParam(ForceType<const ScriptStationList_CargoPlannedFromByVia &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStationList_CargoPlannedFromByVia *)instance; }
|
||||
template <> inline int Return<ScriptStationList_CargoPlannedFromByVia *>(HSQUIRRELVM vm, ScriptStationList_CargoPlannedFromByVia *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StationList_CargoPlannedFromByVia", res, NULL, DefSQDestructorCallback<ScriptStationList_CargoPlannedFromByVia>, true); return 1; }
|
||||
} // namespace SQConvert
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow ScriptStationList_Vehicle to be used as Squirrel parameter */
|
||||
template <> inline ScriptStationList_Vehicle *GetParam(ForceType<ScriptStationList_Vehicle *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStationList_Vehicle *)instance; }
|
||||
|
||||
+10
-14
@@ -125,15 +125,14 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
/* Read the table, and find all properties we care about */
|
||||
sq_pushnull(vm);
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||
const SQChar *sqkey;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &sqkey))) return SQ_ERROR;
|
||||
const char *key = SQ2OTTD(sqkey);
|
||||
const SQChar *key;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &key))) return SQ_ERROR;
|
||||
ValidateString(key);
|
||||
|
||||
if (strcmp(key, "name") == 0) {
|
||||
const SQChar *sqvalue;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
|
||||
char *name = stredup(SQ2OTTD(sqvalue));
|
||||
char *name = stredup(sqvalue);
|
||||
char *s;
|
||||
ValidateString(name);
|
||||
|
||||
@@ -146,7 +145,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 = stredup(SQ2OTTD(sqdescription));
|
||||
config.description = stredup(sqdescription);
|
||||
ValidateString(config.description);
|
||||
items |= 0x002;
|
||||
} else if (strcmp(key, "min_value") == 0) {
|
||||
@@ -230,9 +229,8 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||
|
||||
SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||
{
|
||||
const SQChar *sq_setting_name;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &sq_setting_name))) return SQ_ERROR;
|
||||
const char *setting_name = SQ2OTTD(sq_setting_name);
|
||||
const SQChar *setting_name;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &setting_name))) return SQ_ERROR;
|
||||
ValidateString(setting_name);
|
||||
|
||||
ScriptConfigItem *config = NULL;
|
||||
@@ -253,15 +251,13 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||
/* Read the table and find all labels */
|
||||
sq_pushnull(vm);
|
||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||
const SQChar *sq_key;
|
||||
const SQChar *sq_label;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &sq_key))) return SQ_ERROR;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &sq_label))) return SQ_ERROR;
|
||||
const SQChar *key_string;
|
||||
const SQChar *label;
|
||||
if (SQ_FAILED(sq_getstring(vm, -2, &key_string))) return SQ_ERROR;
|
||||
if (SQ_FAILED(sq_getstring(vm, -1, &label))) return SQ_ERROR;
|
||||
/* Because squirrel doesn't support identifiers starting with a digit,
|
||||
* we skip the first character. */
|
||||
const char *key_string = SQ2OTTD(sq_key);
|
||||
int key = atoi(key_string + 1);
|
||||
const char *label = SQ2OTTD(sq_label);
|
||||
ValidateString(label);
|
||||
|
||||
/* !Contains() prevents stredup from leaking. */
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
/** @file script_info_dummy.cpp Implementation of a dummy Script. */
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "../stdafx.h"
|
||||
#include <squirrel.h>
|
||||
|
||||
#include "../string_func.h"
|
||||
#include "../strings_func.h"
|
||||
@@ -41,12 +41,12 @@ void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir)
|
||||
dp += seprintf(dp, lastof(dummy_script), "function CreateInstance() { return \"Dummy%s\"; }\n", type);
|
||||
dp += seprintf(dp, lastof(dummy_script), "} RegisterDummy%s(Dummy%s());\n", type, type);
|
||||
|
||||
const SQChar *sq_dummy_script = OTTD2SQ(dummy_script);
|
||||
const SQChar *sq_dummy_script = dummy_script;
|
||||
|
||||
sq_pushroottable(vm);
|
||||
|
||||
/* Load and run the script */
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, sq_dummy_script, scstrlen(sq_dummy_script), _SC("dummy"), SQTrue))) {
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, sq_dummy_script, strlen(sq_dummy_script), "dummy", SQTrue))) {
|
||||
sq_push(vm, -2);
|
||||
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
|
||||
sq_pop(vm, 1);
|
||||
@@ -97,11 +97,11 @@ void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
|
||||
/* 3) We translate the error message in the character format that Squirrel wants.
|
||||
* We can use the fact that the wchar string printing also uses %s to print
|
||||
* old style char strings, which is what was generated during the script generation. */
|
||||
const SQChar *sq_dummy_script = OTTD2SQ(dummy_script);
|
||||
const SQChar *sq_dummy_script = dummy_script;
|
||||
|
||||
/* And finally we load and run the script */
|
||||
sq_pushroottable(vm);
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, sq_dummy_script, scstrlen(sq_dummy_script), _SC("dummy"), SQTrue))) {
|
||||
if (SQ_SUCCEEDED(sq_compilebuffer(vm, sq_dummy_script, strlen(sq_dummy_script), "dummy", SQTrue))) {
|
||||
sq_push(vm, -2);
|
||||
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
|
||||
sq_pop(vm, 1);
|
||||
|
||||
@@ -46,7 +46,7 @@ ScriptStorage::~ScriptStorage()
|
||||
static void PrintFunc(bool error_msg, const SQChar *message)
|
||||
{
|
||||
/* Convert to OpenTTD internal capable string */
|
||||
ScriptController::Print(error_msg, SQ2OTTD(message));
|
||||
ScriptController::Print(error_msg, message);
|
||||
}
|
||||
|
||||
ScriptInstance::ScriptInstance(const char *APIName) :
|
||||
@@ -367,11 +367,8 @@ static const SaveLoad _script_byte[] = {
|
||||
_script_sl_byte = SQSL_STRING;
|
||||
SlObject(NULL, _script_byte);
|
||||
}
|
||||
const SQChar *res;
|
||||
sq_getstring(vm, index, &res);
|
||||
/* @bug if a string longer than 512 characters is given to SQ2OTTD, the
|
||||
* internal buffer overflows. */
|
||||
const char *buf = SQ2OTTD(res);
|
||||
const SQChar *buf;
|
||||
sq_getstring(vm, index, &buf);
|
||||
size_t len = strlen(buf) + 1;
|
||||
if (len >= 255) {
|
||||
ScriptLog::Error("Maximum string length is 254 chars. No data saved.");
|
||||
@@ -569,7 +566,7 @@ bool ScriptInstance::IsPaused()
|
||||
SlObject(NULL, _script_byte);
|
||||
static char buf[256];
|
||||
SlArray(buf, _script_sl_byte, SLE_CHAR);
|
||||
if (vm != NULL) sq_pushstring(vm, OTTD2SQ(buf), -1);
|
||||
if (vm != NULL) sq_pushstring(vm, buf, -1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -594,7 +591,7 @@ bool ScriptInstance::IsPaused()
|
||||
|
||||
case SQSL_BOOL: {
|
||||
SlObject(NULL, _script_byte);
|
||||
if (vm != NULL) sq_pushinteger(vm, (SQBool)(_script_sl_byte != 0));
|
||||
if (vm != NULL) sq_pushbool(vm, (SQBool)(_script_sl_byte != 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -658,7 +655,7 @@ bool ScriptInstance::CallLoad()
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(vm, *this->instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(vm, OTTD2SQ("Load"), -1);
|
||||
sq_pushstring(vm, "Load", -1);
|
||||
/* Change the "Load" string in a function pointer */
|
||||
sq_get(vm, -2);
|
||||
/* Push the main instance as "this" object */
|
||||
|
||||
+49
-68
@@ -19,26 +19,20 @@
|
||||
#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];
|
||||
|
||||
scsnprintf(buf, lengthof(buf), _SC("Error %s:") SQ_PRINTF64 _SC("/") SQ_PRINTF64 _SC(": %s"), source, line, column, desc);
|
||||
seprintf(buf, lastof(buf), "Error %s:" OTTD_PRINTF64 "/" OTTD_PRINTF64 ": %s", source, line, column, desc);
|
||||
|
||||
/* Check if we have a custom print function */
|
||||
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
|
||||
engine->crashed = true;
|
||||
SQPrintFunc *func = engine->print_func;
|
||||
if (func == NULL) {
|
||||
DEBUG(misc, 0, "[Squirrel] Compile error: %s", SQ2OTTD(buf));
|
||||
DEBUG(misc, 0, "[Squirrel] Compile error: %s", buf);
|
||||
} else {
|
||||
(*func)(true, buf);
|
||||
}
|
||||
@@ -50,13 +44,13 @@ void Squirrel::ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
|
||||
SQChar buf[1024];
|
||||
|
||||
va_start(arglist, s);
|
||||
scvsnprintf(buf, lengthof(buf), s, arglist);
|
||||
vseprintf(buf, lastof(buf), s, arglist);
|
||||
va_end(arglist);
|
||||
|
||||
/* Check if we have a custom print function */
|
||||
SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func;
|
||||
if (func == NULL) {
|
||||
scfprintf(stderr, _SC("%s"), buf);
|
||||
fprintf(stderr, "%s", buf);
|
||||
} else {
|
||||
(*func)(true, buf);
|
||||
}
|
||||
@@ -70,11 +64,11 @@ void Squirrel::RunError(HSQUIRRELVM vm, const SQChar *error)
|
||||
|
||||
/* Check if we have a custom print function */
|
||||
SQChar buf[1024];
|
||||
scsnprintf(buf, lengthof(buf), _SC("Your script made an error: %s\n"), error);
|
||||
seprintf(buf, lastof(buf), "Your script made an error: %s\n", error);
|
||||
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
|
||||
SQPrintFunc *func = engine->print_func;
|
||||
if (func == NULL) {
|
||||
scfprintf(stderr, _SC("%s"), buf);
|
||||
fprintf(stderr, "%s", buf);
|
||||
} else {
|
||||
(*func)(true, buf);
|
||||
}
|
||||
@@ -96,7 +90,7 @@ SQInteger Squirrel::_RunError(HSQUIRRELVM vm)
|
||||
}
|
||||
}
|
||||
|
||||
Squirrel::RunError(vm, _SC("unknown error"));
|
||||
Squirrel::RunError(vm, "unknown error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -106,14 +100,14 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
|
||||
SQChar buf[1024];
|
||||
|
||||
va_start(arglist, s);
|
||||
scvsnprintf(buf, lengthof(buf) - 2, s, arglist);
|
||||
vseprintf(buf, lastof(buf) - 2, s, arglist);
|
||||
va_end(arglist);
|
||||
scstrcat(buf, _SC("\n"));
|
||||
strecat(buf, "\n", lastof(buf));
|
||||
|
||||
/* Check if we have a custom print function */
|
||||
SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func;
|
||||
if (func == NULL) {
|
||||
scprintf(_SC("%s"), buf);
|
||||
printf("%s", buf);
|
||||
} else {
|
||||
(*func)(false, buf);
|
||||
}
|
||||
@@ -121,7 +115,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
|
||||
|
||||
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
|
||||
{
|
||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
|
||||
if (size != 0) {
|
||||
void *ptr = sq_newuserdata(vm, size);
|
||||
@@ -129,21 +123,21 @@ void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam,
|
||||
}
|
||||
|
||||
sq_newclosure(this->vm, proc, size != 0 ? 1 : 0);
|
||||
if (nparam != 0) sq_setparamscheck(this->vm, nparam, OTTD2SQ(params));
|
||||
sq_setnativeclosurename(this->vm, -1, OTTD2SQ(method_name));
|
||||
if (nparam != 0) sq_setparamscheck(this->vm, nparam, params);
|
||||
sq_setnativeclosurename(this->vm, -1, method_name);
|
||||
sq_newslot(this->vm, -3, SQFalse);
|
||||
}
|
||||
|
||||
void Squirrel::AddConst(const char *var_name, int value)
|
||||
{
|
||||
sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushinteger(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
}
|
||||
|
||||
void Squirrel::AddConst(const char *var_name, bool value)
|
||||
{
|
||||
sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushbool(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
}
|
||||
@@ -151,15 +145,15 @@ void Squirrel::AddConst(const char *var_name, bool value)
|
||||
void Squirrel::AddClassBegin(const char *class_name)
|
||||
{
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_newclass(this->vm, SQFalse);
|
||||
}
|
||||
|
||||
void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
|
||||
{
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
|
||||
sq_pushstring(this->vm, OTTD2SQ(parent_class), -1);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_pushstring(this->vm, parent_class, -1);
|
||||
if (SQ_FAILED(sq_get(this->vm, -3))) {
|
||||
DEBUG(misc, 0, "[squirrel] Failed to initialize class '%s' based on parent class '%s'", class_name, parent_class);
|
||||
DEBUG(misc, 0, "[squirrel] Make sure that '%s' exists before trying to define '%s'", parent_class, class_name);
|
||||
@@ -181,7 +175,7 @@ bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(this->vm, instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||
sq_settop(this->vm, top);
|
||||
return false;
|
||||
@@ -232,7 +226,7 @@ bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(this->vm, instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||
DEBUG(misc, 0, "[squirrel] Could not find '%s' in the class", method_name);
|
||||
sq_settop(this->vm, top);
|
||||
@@ -293,9 +287,9 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
|
||||
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);
|
||||
sq_pushstring(vm, class_name2, -1);
|
||||
} else {
|
||||
sq_pushstring(vm, OTTD2SQ(class_name), -1);
|
||||
sq_pushstring(vm, class_name, -1);
|
||||
}
|
||||
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
@@ -386,58 +380,45 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static SQInteger _io_file_lexfeed_ASCII(SQUserPointer file)
|
||||
static WChar _io_file_lexfeed_ASCII(SQUserPointer file)
|
||||
{
|
||||
char c;
|
||||
unsigned char c;
|
||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
||||
static WChar _io_file_lexfeed_UTF8(SQUserPointer file)
|
||||
{
|
||||
static const SQInteger utf8_lengths[16] =
|
||||
{
|
||||
1, 1, 1, 1, 1, 1, 1, 1, /* 0000 to 0111 : 1 byte (plain ASCII) */
|
||||
0, 0, 0, 0, /* 1000 to 1011 : not valid */
|
||||
2, 2, /* 1100, 1101 : 2 bytes */
|
||||
3, /* 1110 : 3 bytes */
|
||||
4 /* 1111 : 4 bytes */
|
||||
};
|
||||
static unsigned char byte_masks[5] = {0, 0, 0x1F, 0x0F, 0x07};
|
||||
unsigned char inchar;
|
||||
SQInteger c = 0;
|
||||
if (((SQFile *)file)->Read(&inchar, sizeof(inchar), 1) != 1) return 0;
|
||||
c = inchar;
|
||||
char buffer[5];
|
||||
|
||||
if (c >= 0x80) {
|
||||
SQInteger tmp;
|
||||
SQInteger codelen = utf8_lengths[c >> 4];
|
||||
if (codelen == 0) return 0;
|
||||
/* Read the first character, and get the length based on UTF-8 specs. If invalid, bail out. */
|
||||
if (((SQFile *)file)->Read(buffer, sizeof(buffer[0]), 1) != 1) return 0;
|
||||
uint len = Utf8EncodedCharLen(buffer[0]);
|
||||
if (len == 0) return -1;
|
||||
|
||||
/* Read the remaining bits. */
|
||||
if (len > 1 && ((SQFile *)file)->Read(buffer + 1, sizeof(buffer[0]), len - 1) != len - 1) return 0;
|
||||
|
||||
/* Convert the character, and when definitely invalid, bail out as well. */
|
||||
WChar c;
|
||||
if (Utf8Decode(&c, buffer) != len) return -1;
|
||||
|
||||
tmp = c & byte_masks[codelen];
|
||||
for (SQInteger n = 0; n < codelen - 1; n++) {
|
||||
tmp <<= 6;
|
||||
if (((SQFile *)file)->Read(&inchar, sizeof(inchar), 1) != 1) return 0;
|
||||
tmp |= inchar & 0x3F;
|
||||
}
|
||||
c = tmp;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UCS2_no_swap(SQUserPointer file)
|
||||
static WChar _io_file_lexfeed_UCS2_no_swap(SQUserPointer file)
|
||||
{
|
||||
wchar_t c;
|
||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (SQChar)c;
|
||||
unsigned short c;
|
||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (WChar)c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger _io_file_lexfeed_UCS2_swap(SQUserPointer file)
|
||||
static WChar _io_file_lexfeed_UCS2_swap(SQUserPointer file)
|
||||
{
|
||||
unsigned short c;
|
||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) {
|
||||
c = ((c >> 8) & 0x00FF)| ((c << 8) & 0xFF00);
|
||||
return (SQChar)c;
|
||||
return (WChar)c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -478,14 +459,14 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||
case SQ_BYTECODE_STREAM_TAG: { // BYTECODE
|
||||
if (fseek(file, -2, SEEK_CUR) < 0) {
|
||||
FioFCloseFile(file);
|
||||
return sq_throwerror(vm, _SC("cannot seek the file"));
|
||||
return sq_throwerror(vm, "cannot seek the file");
|
||||
}
|
||||
if (SQ_SUCCEEDED(sq_readclosure(vm, _io_file_read, &f))) {
|
||||
FioFCloseFile(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
FioFCloseFile(file);
|
||||
return sq_throwerror(vm, _SC("Couldn't read bytecode"));
|
||||
return sq_throwerror(vm, "Couldn't read bytecode");
|
||||
}
|
||||
case 0xFFFE:
|
||||
/* Either this file is encoded as big-endian and we're on a little-endian
|
||||
@@ -498,11 +479,11 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||
case 0xEFBB: // UTF-8 on big-endian machine
|
||||
if (fread(&uc, 1, sizeof(uc), file) == 0) {
|
||||
FioFCloseFile(file);
|
||||
return sq_throwerror(vm, _SC("I/O error"));
|
||||
return sq_throwerror(vm, "I/O error");
|
||||
}
|
||||
if (uc != 0xBF) {
|
||||
FioFCloseFile(file);
|
||||
return sq_throwerror(vm, _SC("Unrecognized encoding"));
|
||||
return sq_throwerror(vm, "Unrecognized encoding");
|
||||
}
|
||||
func = _io_file_lexfeed_UTF8;
|
||||
break;
|
||||
@@ -510,19 +491,19 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||
func = _io_file_lexfeed_ASCII;
|
||||
if (fseek(file, -2, SEEK_CUR) < 0) {
|
||||
FioFCloseFile(file);
|
||||
return sq_throwerror(vm, _SC("cannot seek the file"));
|
||||
return sq_throwerror(vm, "cannot seek the file");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (SQ_SUCCEEDED(sq_compile(vm, func, &f, OTTD2SQ(filename), printerror))) {
|
||||
if (SQ_SUCCEEDED(sq_compile(vm, func, &f, filename, printerror))) {
|
||||
FioFCloseFile(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
FioFCloseFile(file);
|
||||
return SQ_ERROR;
|
||||
}
|
||||
return sq_throwerror(vm, _SC("cannot open the file"));
|
||||
return sq_throwerror(vm, "cannot open the file");
|
||||
}
|
||||
|
||||
bool Squirrel::LoadScript(HSQUIRRELVM vm, const char *script, bool in_root)
|
||||
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
/**
|
||||
* Convert a Squirrel-object to a string.
|
||||
*/
|
||||
static const char *ObjectToString(HSQOBJECT *ptr) { return SQ2OTTD(sq_objtostring(ptr)); }
|
||||
static const char *ObjectToString(HSQOBJECT *ptr) { return sq_objtostring(ptr); }
|
||||
|
||||
/**
|
||||
* Convert a Squirrel-object to an integer.
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
/**
|
||||
* Throw a Squirrel error that will be nicely displayed to the user.
|
||||
*/
|
||||
void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2SQ(error)); }
|
||||
void ThrowError(const char *error) { sq_throwerror(this->vm, error); }
|
||||
|
||||
/**
|
||||
* Release a SQ object.
|
||||
|
||||
@@ -88,8 +88,8 @@ namespace SQConvert {
|
||||
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; }
|
||||
template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, 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, res, -1); } return 1; }
|
||||
template <> inline int Return<void *> (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; }
|
||||
template <> inline int Return<HSQOBJECT> (HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; }
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace SQConvert {
|
||||
|
||||
const SQChar *tmp;
|
||||
sq_getstring(vm, -1, &tmp);
|
||||
char *tmp_str = stredup(SQ2OTTD(tmp));
|
||||
char *tmp_str = stredup(tmp);
|
||||
sq_poptop(vm);
|
||||
*ptr->Append() = (void *)tmp_str;
|
||||
str_validate(tmp_str, tmp_str + strlen(tmp_str));
|
||||
@@ -125,7 +125,7 @@ namespace SQConvert {
|
||||
template <> inline Array *GetParam(ForceType<Array *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr)
|
||||
{
|
||||
/* Sanity check of the size. */
|
||||
if (sq_getsize(vm, index) > UINT16_MAX) throw sq_throwerror(vm, _SC("an array used as parameter to a function is too large"));
|
||||
if (sq_getsize(vm, index) > UINT16_MAX) throw sq_throwerror(vm, "an array used as parameter to a function is too large");
|
||||
|
||||
SQObject obj;
|
||||
sq_getstackobj(vm, index, &obj);
|
||||
@@ -140,7 +140,7 @@ namespace SQConvert {
|
||||
*data.Append() = (int32)tmp;
|
||||
} else {
|
||||
sq_pop(vm, 4);
|
||||
throw sq_throwerror(vm, _SC("a member of an array used as parameter to a function is not numeric"));
|
||||
throw sq_throwerror(vm, "a member of an array used as parameter to a function is not numeric");
|
||||
}
|
||||
|
||||
sq_pop(vm, 2);
|
||||
@@ -749,17 +749,17 @@ namespace SQConvert {
|
||||
/* Protect against calls to a non-static method in a static way */
|
||||
sq_pushroottable(vm);
|
||||
const char *className = GetClassName<Tcls, Ttype>();
|
||||
sq_pushstring(vm, OTTD2SQ(className), -1);
|
||||
sq_pushstring(vm, className, -1);
|
||||
sq_get(vm, -2);
|
||||
sq_pushobject(vm, instance);
|
||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, "class method is non-static");
|
||||
sq_pop(vm, 3);
|
||||
|
||||
/* Get the 'real' instance of this class */
|
||||
sq_getinstanceup(vm, 1, &real_instance, 0);
|
||||
/* Get the real function pointer */
|
||||
sq_getuserdata(vm, nparam, &ptr, 0);
|
||||
if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
|
||||
if (real_instance == NULL) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call");
|
||||
/* Remove the userdata from the stack */
|
||||
sq_pop(vm, 1);
|
||||
|
||||
@@ -791,17 +791,17 @@ namespace SQConvert {
|
||||
/* Protect against calls to a non-static method in a static way */
|
||||
sq_pushroottable(vm);
|
||||
const char *className = GetClassName<Tcls, Ttype>();
|
||||
sq_pushstring(vm, OTTD2SQ(className), -1);
|
||||
sq_pushstring(vm, className, -1);
|
||||
sq_get(vm, -2);
|
||||
sq_pushobject(vm, instance);
|
||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, "class method is non-static");
|
||||
sq_pop(vm, 3);
|
||||
|
||||
/* Get the 'real' instance of this class */
|
||||
sq_getinstanceup(vm, 1, &real_instance, 0);
|
||||
/* Get the real function pointer */
|
||||
sq_getuserdata(vm, nparam, &ptr, 0);
|
||||
if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
|
||||
if (real_instance == NULL) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call");
|
||||
/* Remove the userdata from the stack */
|
||||
sq_pop(vm, 1);
|
||||
|
||||
|
||||
@@ -9,20 +9,16 @@
|
||||
|
||||
/** @file squirrel_std.cpp Implements the Squirrel Standard Function class */
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include <squirrel.h>
|
||||
#include <sqstdmath.h>
|
||||
#include "../stdafx.h"
|
||||
#include "../debug.h"
|
||||
#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)
|
||||
@@ -49,7 +45,6 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
|
||||
{
|
||||
SQInteger top = sq_gettop(vm);
|
||||
const SQChar *filename;
|
||||
SQChar *real_filename;
|
||||
|
||||
sq_getstring(vm, 2, &filename);
|
||||
|
||||
@@ -60,31 +55,26 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
|
||||
DEBUG(misc, 0, "[squirrel] Couldn't detect the script-name of the 'require'-caller; this should never happen!");
|
||||
return SQ_ERROR;
|
||||
}
|
||||
real_filename = scstrdup(si.source);
|
||||
|
||||
char path[MAX_PATH];
|
||||
strecpy(path, si.source, lastof(path));
|
||||
/* Keep the dir, remove the rest */
|
||||
SQChar *s = scstrrchr(real_filename, PATHSEPCHAR);
|
||||
SQChar *s = strrchr(path, PATHSEPCHAR);
|
||||
if (s != NULL) {
|
||||
/* Keep the PATHSEPCHAR there, remove the rest */
|
||||
s++;
|
||||
*s = '\0';
|
||||
}
|
||||
/* And now we concat, so we are relative from the current script
|
||||
* First, we have to make sure we have enough space for the full path */
|
||||
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 = stredup(SQ2OTTD(real_filename));
|
||||
strecat(path, filename, lastof(path));
|
||||
#if (PATHSEPCHAR != '/')
|
||||
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
|
||||
for (char *n = path; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
|
||||
#endif
|
||||
|
||||
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
|
||||
bool ret = engine->LoadScript(vm, filen);
|
||||
bool ret = engine->LoadScript(vm, path);
|
||||
|
||||
/* Reset the top, so the stack stays correct */
|
||||
sq_settop(vm, top);
|
||||
free(real_filename);
|
||||
free(filen);
|
||||
|
||||
return ret ? 0 : SQ_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user