mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
3 Commits
47d49dd752
...
cf8e1a376e
Author | SHA1 | Date |
---|---|---|
|
cf8e1a376e | |
|
7bb4940ebd | |
|
5d8f3ae6db |
|
@ -877,12 +877,12 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
|||
GetAirportHeight(8): 2
|
||||
GetAirportCoverageRadius(8): 4
|
||||
GetAirportNumHelipads(8): 3
|
||||
IsAirportInformationAvailable(9): false
|
||||
IsAirportInformationAvailable(9): true
|
||||
IsValidAirportType(9): false
|
||||
GetAirportWidth(9): -1
|
||||
GetAirportHeight(9): -1
|
||||
GetAirportCoverageRadius(9): -1
|
||||
GetAirportNumHelipads(9): -1
|
||||
GetAirportWidth(9): 1
|
||||
GetAirportHeight(9): 1
|
||||
GetAirportCoverageRadius(9): 4
|
||||
GetAirportNumHelipads(9): 1
|
||||
GetBankBalance(): 1999999790
|
||||
GetPrice(): 5400
|
||||
BuildAirport(): true
|
||||
|
|
|
@ -83,7 +83,7 @@ void AIInstance::Died()
|
|||
|
||||
void AIInstance::LoadDummyScript()
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this->engine);
|
||||
ScriptAllocatorScope alloc_scope(this->engine.get());
|
||||
Script_CreateDummy(this->engine->GetVM(), STR_ERROR_AI_NO_AI_FOUND, "AI");
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
* \li AICargo::CC_POTABLE
|
||||
* \li AICargo::CC_NON_POTABLE
|
||||
* \li AIVehicleList_Waypoint
|
||||
* \li AIAirport::AT_OILRIG
|
||||
*
|
||||
* Other changes:
|
||||
* \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* \li GSCargo::CC_NON_POTABLE
|
||||
* \li GSVehicleList_Waypoint
|
||||
* \li GSBaseStation::GetOwner
|
||||
* \li GSAirport::AT_OILRIG
|
||||
*
|
||||
* Other changes:
|
||||
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
/* static */ bool ScriptAirport::IsAirportInformationAvailable(AirportType type)
|
||||
{
|
||||
return type >= 0 && type < (AirportType)NUM_AIRPORTS && AirportSpec::Get(type)->enabled;
|
||||
return type == AT_OILRIG || (type >= 0 && type < (AirportType)NUM_AIRPORTS && AirportSpec::Get(type)->enabled);
|
||||
}
|
||||
|
||||
/* static */ Money ScriptAirport::GetPrice(AirportType type)
|
||||
|
@ -67,6 +67,7 @@
|
|||
{
|
||||
if (!IsAirportInformationAvailable(type)) return -1;
|
||||
|
||||
if (type == AT_OILRIG && !_settings_game.station.serve_neutral_industries) return (uint)CA_NONE;
|
||||
return _settings_game.station.modified_catchment ? ::AirportSpec::Get(type)->catchment : (uint)CA_UNMODIFIED;
|
||||
}
|
||||
|
||||
|
@ -96,9 +97,8 @@
|
|||
if (!::IsTileType(tile, MP_STATION)) return -1;
|
||||
|
||||
const Station *st = ::Station::GetByTile(tile);
|
||||
if (st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return -1;
|
||||
if (st->owner != OWNER_NONE && st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return -1;
|
||||
if (!st->facilities.Test(StationFacility::Airport)) return -1;
|
||||
|
||||
return st->airport.GetNumHangars();
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@
|
|||
if (GetNumHangars(tile) < 1) return INVALID_TILE;
|
||||
|
||||
const Station *st = ::Station::GetByTile(tile);
|
||||
if (st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return INVALID_TILE;
|
||||
if (st->owner != OWNER_NONE && st->owner != ScriptObject::GetCompany() && ScriptCompanyMode::IsValid()) return INVALID_TILE;
|
||||
if (!st->facilities.Test(StationFacility::Airport)) return INVALID_TILE;
|
||||
|
||||
return st->airport.GetHangarTile(0);
|
||||
|
@ -143,7 +143,7 @@
|
|||
return GetAirportNoiseLevelForDistance(as, dist);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return type == AT_OILRIG ? 0 : 1;
|
||||
}
|
||||
|
||||
/* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type)
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
AT_HELIPORT = ::AT_HELIPORT, ///< The heliport.
|
||||
AT_HELISTATION = ::AT_HELISTATION, ///< The helistation.
|
||||
AT_HELIDEPOT = ::AT_HELIDEPOT, ///< The helidepot.
|
||||
AT_OILRIG = ::AT_OILRIG, ///< The oil rig heliport.
|
||||
AT_INVALID = ::AT_INVALID, ///< Invalid airport.
|
||||
};
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ static ScriptStorage &GetStorage()
|
|||
|
||||
/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = nullptr;
|
||||
|
||||
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance &instance) : alc_scope(instance.engine)
|
||||
ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance &instance) : alc_scope(instance.engine.get())
|
||||
{
|
||||
this->last_active = ScriptObject::ActiveInstance::active;
|
||||
ScriptObject::ActiveInstance::active = &instance;
|
||||
|
@ -230,8 +230,8 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
|||
|
||||
/* static */ bool ScriptObject::CanSuspend()
|
||||
{
|
||||
Squirrel *squirrel = ScriptObject::GetActiveInstance().engine;
|
||||
return GetStorage().allow_do_command && squirrel->CanSuspend();
|
||||
Squirrel &squirrel = *ScriptObject::GetActiveInstance().engine;
|
||||
return GetStorage().allow_do_command && squirrel.CanSuspend();
|
||||
}
|
||||
|
||||
/* static */ ScriptEventQueue &ScriptObject::GetEventQueue()
|
||||
|
|
|
@ -50,8 +50,8 @@ static void PrintFunc(bool error_msg, std::string_view message)
|
|||
|
||||
ScriptInstance::ScriptInstance(std::string_view api_name)
|
||||
{
|
||||
this->storage = new ScriptStorage();
|
||||
this->engine = new Squirrel(api_name);
|
||||
this->storage = std::make_unique<ScriptStorage>();
|
||||
this->engine = std::make_unique<Squirrel>(api_name);
|
||||
this->engine->SetPrintFunction(&PrintFunc);
|
||||
}
|
||||
|
||||
|
@ -59,10 +59,10 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
|
|||
{
|
||||
ScriptObject::ActiveInstance active(*this);
|
||||
|
||||
this->controller = new ScriptController(company);
|
||||
this->controller = std::make_unique<ScriptController>(company);
|
||||
|
||||
/* Register the API functions and classes */
|
||||
this->engine->SetGlobalPointer(this->engine);
|
||||
this->engine->SetGlobalPointer(this->engine.get());
|
||||
this->RegisterAPI();
|
||||
if (this->IsDead()) {
|
||||
/* Failed to register API; a message has already been logged. */
|
||||
|
@ -81,12 +81,11 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
|
|||
}
|
||||
|
||||
/* Create the main-class */
|
||||
this->instance = new SQObject();
|
||||
if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) {
|
||||
this->instance = std::make_unique<SQObject>();
|
||||
if (!this->engine->CreateClassInstance(instance_name, this->controller.get(), this->instance.get())) {
|
||||
/* If CreateClassInstance has returned false instance has not been
|
||||
* registered with squirrel, so avoid trying to Release it by clearing it now */
|
||||
delete this->instance;
|
||||
this->instance = nullptr;
|
||||
this->instance.reset();
|
||||
this->Died();
|
||||
return;
|
||||
}
|
||||
|
@ -158,11 +157,10 @@ ScriptInstance::~ScriptInstance()
|
|||
ScriptObject::ActiveInstance active(*this);
|
||||
this->in_shutdown = true;
|
||||
|
||||
if (instance != nullptr) this->engine->ReleaseObject(this->instance);
|
||||
if (engine != nullptr) delete this->engine;
|
||||
delete this->storage;
|
||||
delete this->controller;
|
||||
delete this->instance;
|
||||
if (instance != nullptr) this->engine->ReleaseObject(this->instance.get());
|
||||
|
||||
/* Engine must be reset explicitly in scope of the active instance. */
|
||||
this->engine.reset();
|
||||
}
|
||||
|
||||
void ScriptInstance::Continue()
|
||||
|
@ -179,11 +177,9 @@ void ScriptInstance::Died()
|
|||
|
||||
this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache
|
||||
|
||||
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance);
|
||||
delete this->instance;
|
||||
delete this->engine;
|
||||
this->instance = nullptr;
|
||||
this->engine = nullptr;
|
||||
if (this->instance != nullptr) this->engine->ReleaseObject(this->instance.get());
|
||||
this->engine.reset();
|
||||
this->instance.reset();
|
||||
}
|
||||
|
||||
void ScriptInstance::GameLoop()
|
||||
|
|
|
@ -256,7 +256,7 @@ public:
|
|||
void ReleaseSQObject(HSQOBJECT *obj);
|
||||
|
||||
protected:
|
||||
class Squirrel *engine = nullptr; ///< A wrapper around the squirrel vm.
|
||||
std::unique_ptr<class Squirrel> engine; ///< A wrapper around the squirrel vm.
|
||||
std::string api_version{}; ///< Current API used by this script.
|
||||
|
||||
/**
|
||||
|
@ -288,9 +288,9 @@ protected:
|
|||
virtual void LoadDummyScript() = 0;
|
||||
|
||||
private:
|
||||
class ScriptController *controller = nullptr; ///< The script main class.
|
||||
class ScriptStorage *storage = nullptr; ///< Some global information for each running script.
|
||||
SQObject *instance = nullptr; ///< Squirrel-pointer to the script main class.
|
||||
std::unique_ptr<class ScriptStorage> storage; ///< Some global information for each running script.
|
||||
std::unique_ptr<class ScriptController> controller; ///< The script main class.
|
||||
std::unique_ptr<SQObject> instance; ///< Squirrel-pointer to the script main class.
|
||||
|
||||
bool is_started = false; ///< Is the scripts constructor executed?
|
||||
bool is_dead = false; ///< True if the script has been stopped.
|
||||
|
|
|
@ -359,6 +359,15 @@ static const std::initializer_list<AirportTileLayout> _tile_table_helistation =
|
|||
{ _tile_table_helistation_0, DIR_N },
|
||||
};
|
||||
|
||||
/** Tiles for oilrig */
|
||||
static const std::initializer_list<AirportTileTable> _tile_table_oilrig_0 = {
|
||||
MK(0, 0, APT_EMPTY),
|
||||
};
|
||||
|
||||
static const std::initializer_list<AirportTileLayout> _tile_table_oilrig = {
|
||||
{ _tile_table_oilrig_0, DIR_N, }
|
||||
};
|
||||
|
||||
#undef MK
|
||||
|
||||
/** General AirportSpec definition. */
|
||||
|
@ -377,7 +386,7 @@ static const std::initializer_list<AirportTileLayout> _tile_table_helistation =
|
|||
|
||||
/* The helidepot and helistation have ATP_TTDP_SMALL because they are at ground level */
|
||||
extern const AirportSpec _origin_airport_specs[] = {
|
||||
AS(country, 4, 3, 0, 1959, 4, 3, 7, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_SMALL, SPR_AIRPORT_PREVIEW_SMALL),
|
||||
AS(country, 4, 3, CalendarTime::MIN_YEAR, 1959, 4, 3, 7, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_SMALL, SPR_AIRPORT_PREVIEW_SMALL),
|
||||
AS(city, 6, 6, 1955, CalendarTime::MAX_YEAR, 5, 5, 24, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_CITY, SPR_AIRPORT_PREVIEW_LARGE),
|
||||
AS_ND(heliport, 1, 1, 1963, CalendarTime::MAX_YEAR, 4, 1, 4, ATP_TTDP_HELIPORT, APC_HELIPORT, STR_AIRPORT_HELIPORT, SPR_AIRPORT_PREVIEW_HELIPORT),
|
||||
AS(metropolitan, 6, 6, 1980, CalendarTime::MAX_YEAR, 6, 8, 28, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_METRO, SPR_AIRPORT_PREVIEW_METROPOLITAN),
|
||||
|
@ -386,7 +395,7 @@ extern const AirportSpec _origin_airport_specs[] = {
|
|||
AS(helidepot, 2, 2, 1976, CalendarTime::MAX_YEAR, 4, 2, 7, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELIDEPOT, SPR_AIRPORT_PREVIEW_HELIDEPOT),
|
||||
AS(intercontinental, 9, 11, 2002, CalendarTime::MAX_YEAR, 10, 25, 72, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERCONTINENTAL, SPR_AIRPORT_PREVIEW_INTERCONTINENTAL),
|
||||
AS(helistation, 4, 2, 1980, CalendarTime::MAX_YEAR, 4, 3, 14, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELISTATION, SPR_AIRPORT_PREVIEW_HELISTATION),
|
||||
AS_GENERIC(&_airportfta_oilrig, {}, {}, 1, 1, 0, 4, 0, 0, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, 0, false),
|
||||
AS_GENERIC(&_airportfta_oilrig, _tile_table_oilrig, {}, 1, 1, 0, 4, CalendarTime::MIN_YEAR, CalendarTime::MIN_YEAR, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, 0, false),
|
||||
};
|
||||
|
||||
static_assert(NEW_AIRPORT_OFFSET == lengthof(_origin_airport_specs));
|
||||
|
|
Loading…
Reference in New Issue