Merge branch 'master' into jgrpp
Replace build and refit, and group collapse implementations Fix template creation build and refit # Conflicts: # Makefile.bundle.in # config.lib # src/animated_tile.cpp # src/blitter/32bpp_anim.hpp # src/blitter/32bpp_base.hpp # src/blitter/8bpp_base.hpp # src/blitter/null.hpp # src/build_vehicle_gui.cpp # src/command.cpp # src/command_func.h # src/console_gui.cpp # src/core/smallstack_type.hpp # src/date.cpp # src/debug.cpp # src/genworld_gui.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/lang/korean.txt # src/linkgraph/linkgraph_gui.h # src/main_gui.cpp # src/misc_gui.cpp # src/network/core/game.h # src/network/core/packet.cpp # src/network/core/udp.cpp # src/network/core/udp.h # src/network/network_content.cpp # src/network/network_type.h # src/network/network_udp.cpp # src/newgrf_house.h # src/openttd.cpp # src/order_cmd.cpp # src/order_gui.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/osk_gui.cpp # src/pathfinder/opf/opf_ship.cpp # src/rail_cmd.cpp # src/rail_gui.cpp # src/saveload/saveload.cpp # src/settings.cpp # src/settings_gui.cpp # src/smallmap_gui.h # src/station_base.h # src/station_cmd.cpp # src/table/gameopt_settings.ini # src/table/newgrf_debug_data.h # src/table/settings.ini # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/train_gui.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/vehiclelist.cpp # src/viewport.cpp # src/widgets/dropdown.cpp # src/window_gui.h
This commit is contained in:
@@ -122,6 +122,8 @@ void SQAIVehicle_Register(Squirrel *engine)
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::IsInDepot, "IsInDepot", 2, ".i");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, ".i");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::BuildVehicle, "BuildVehicle", 3, ".ii");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::BuildVehicleWithRefit, "BuildVehicleWithRefit", 4, ".iii");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetBuildWithRefitCapacity, "GetBuildWithRefitCapacity", 4, ".iii");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::CloneVehicle, "CloneVehicle", 4, ".iib");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::MoveWagon, "MoveWagon", 5, ".iiii");
|
||||
SQAIVehicle.DefSQStaticMethod(engine, &ScriptVehicle::MoveWagonChain, "MoveWagonChain", 5, ".iiii");
|
||||
|
@@ -123,6 +123,8 @@ void SQGSVehicle_Register(Squirrel *engine)
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::IsInDepot, "IsInDepot", 2, ".i");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, ".i");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::BuildVehicle, "BuildVehicle", 3, ".ii");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::BuildVehicleWithRefit, "BuildVehicleWithRefit", 4, ".iii");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetBuildWithRefitCapacity, "GetBuildWithRefitCapacity", 4, ".iii");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::CloneVehicle, "CloneVehicle", 4, ".iib");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::MoveWagon, "MoveWagon", 5, ".iiii");
|
||||
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::MoveWagonChain, "MoveWagonChain", 5, ".iiii");
|
||||
|
@@ -135,7 +135,6 @@
|
||||
std::string json;
|
||||
ScriptAdmin::MakeJSON(vm, -1, SQUIRREL_MAX_DEPTH, json);
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (json.length() > NETWORK_GAMESCRIPT_JSON_LENGTH) {
|
||||
ScriptLog::Error("You are trying to send a table that is too large to the AdminPort. No data sent.");
|
||||
sq_pushinteger(vm, 0);
|
||||
@@ -143,7 +142,6 @@
|
||||
}
|
||||
|
||||
NetworkAdminGameScript(json.c_str());
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
sq_pushinteger(vm, 1);
|
||||
return 1;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
/**
|
||||
* Finds NetworkClientInfo given client-identifier,
|
||||
* is used by other methods to resolve client-identifier.
|
||||
@@ -29,46 +28,29 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
|
||||
if (!_networking) return NULL;
|
||||
return NetworkClientInfo::GetByClientID((::ClientID)client);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* static */ ScriptClient::ClientID ScriptClient::ResolveClientID(ScriptClient::ClientID client)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
return (FindClientInfo(client) == NULL ? ScriptClient::CLIENT_INVALID : client);
|
||||
#else
|
||||
return CLIENT_INVALID;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */ char *ScriptClient::GetName(ScriptClient::ClientID client)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == NULL) return NULL;
|
||||
return stredup(ci->client_name);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptClient::GetCompany(ScriptClient::ClientID client)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == NULL) return ScriptCompany::COMPANY_INVALID;
|
||||
return (ScriptCompany::CompanyID)ci->client_playas;
|
||||
#else
|
||||
return ScriptCompany::COMPANY_INVALID;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == NULL) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)ci->join_date;
|
||||
#else
|
||||
return ScriptDate::DATE_INVALID;
|
||||
#endif
|
||||
}
|
||||
|
@@ -19,18 +19,15 @@
|
||||
|
||||
ScriptClientList::ScriptClientList()
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (!_networking) return;
|
||||
NetworkClientInfo *ci;
|
||||
FOR_ALL_CLIENT_INFOS(ci) {
|
||||
this->AddItem(ci->client_id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ScriptClientList_Company::ScriptClientList_Company(ScriptCompany::CompanyID company)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (!_networking) return;
|
||||
CompanyID c;
|
||||
if (company == ScriptCompany::COMPANY_SPECTATOR) {
|
||||
@@ -45,5 +42,4 @@ ScriptClientList_Company::ScriptClientList_Company(ScriptCompany::CompanyID comp
|
||||
FOR_ALL_CLIENT_INFOS(ci) {
|
||||
if (ci->client_playas == c) this->AddItem(ci->client_id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -39,9 +39,5 @@
|
||||
|
||||
/* static */ bool ScriptGame::IsMultiplayer()
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
return _network_server;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
@@ -137,12 +137,8 @@
|
||||
{
|
||||
EnforcePrecondition(false, ScriptGame::IsMultiplayer());
|
||||
EnforcePrecondition(false, ScriptClient::ResolveClientID(client) != ScriptClient::CLIENT_INVALID);
|
||||
#ifdef ENABLE_NETWORK
|
||||
ClientIndex c = NetworkClientInfo::GetByClientID((::ClientID)client)->index;
|
||||
return DoQuestion(uniqueid, c, true, question, type, buttons);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGoal::CloseQuestion(uint16 uniqueid)
|
||||
|
@@ -303,10 +303,8 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
/* Are we only interested in the estimate costs? */
|
||||
bool estimate_only = GetDoCommandMode() != NULL && !GetDoCommandMode()();
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
/* Only set p2 when the command does not come from the network. */
|
||||
if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX;
|
||||
#endif
|
||||
|
||||
SCOPE_INFO_FMT([=], "ScriptObject::DoCommand: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, company: %s, cmd: 0x%X (%s), estimate_only: %d",
|
||||
tile, TileX(tile), TileY(tile), p1, p2, scope_dumper().CompanyInfo(_current_company), cmd, GetCommandName(cmd), estimate_only);
|
||||
|
@@ -45,7 +45,7 @@ public:
|
||||
RawText(const char *text);
|
||||
~RawText();
|
||||
|
||||
/* virtual */ const char *GetEncodedText() { return this->text; }
|
||||
const char *GetEncodedText() override { return this->text; }
|
||||
private:
|
||||
const char *text;
|
||||
};
|
||||
|
@@ -61,21 +61,44 @@
|
||||
return v->IsGroundVehicle() ? v->GetGroundVehicleCache()->cached_total_length : -1;
|
||||
}
|
||||
|
||||
/* static */ VehicleID ScriptVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
|
||||
/* static */ VehicleID ScriptVehicle::_BuildVehicleInternal(TileIndex depot, EngineID engine_id, CargoID cargo)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(VEHICLE_INVALID, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(VEHICLE_INVALID, ScriptEngine::IsBuildable(engine_id));
|
||||
EnforcePrecondition(VEHICLE_INVALID, cargo == CT_INVALID || ScriptCargo::IsValidCargo(cargo));
|
||||
|
||||
::VehicleType type = ::Engine::Get(engine_id)->type;
|
||||
|
||||
EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED);
|
||||
|
||||
if (!ScriptObject::DoCommand(depot, engine_id, 0, ::GetCmdBuildVeh(type), NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
|
||||
if (!ScriptObject::DoCommand(depot, engine_id | (cargo << 24), 0, ::GetCmdBuildVeh(type), NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return VehicleID 0 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* static */ VehicleID ScriptVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
|
||||
{
|
||||
return _BuildVehicleInternal(depot, engine_id, CT_INVALID);
|
||||
}
|
||||
|
||||
/* static */ VehicleID ScriptVehicle::BuildVehicleWithRefit(TileIndex depot, EngineID engine_id, CargoID cargo)
|
||||
{
|
||||
EnforcePrecondition(VEHICLE_INVALID, ScriptCargo::IsValidCargo(cargo));
|
||||
return _BuildVehicleInternal(depot, engine_id, cargo);
|
||||
}
|
||||
|
||||
/* static */ int ScriptVehicle::GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo)
|
||||
{
|
||||
if (!ScriptEngine::IsBuildable(engine_id)) return -1;
|
||||
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
|
||||
|
||||
::VehicleType type = ::Engine::Get(engine_id)->type;
|
||||
|
||||
CommandCost res = ::DoCommand(depot, engine_id | (cargo << 24), 0, DC_QUERY_COST, ::GetCmdBuildVeh(type));
|
||||
return res.Succeeded() ? _returned_refit_capacity : -1;
|
||||
}
|
||||
|
||||
/* static */ VehicleID ScriptVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
|
@@ -320,6 +320,41 @@ public:
|
||||
*/
|
||||
static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Builds a vehicle with the given engine at the given depot and refits it to the given cargo.
|
||||
* @param depot The depot where the vehicle will be build.
|
||||
* @param engine_id The engine to use for this vehicle.
|
||||
* @param cargo The cargo to refit to.
|
||||
* @pre The tile at depot has a depot that can build the engine and
|
||||
* is owned by you.
|
||||
* @pre ScriptEngine::IsBuildable(engine_id).
|
||||
* @pre ScriptCargo::IsValidCargo(cargo).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT
|
||||
* @return The VehicleID of the new vehicle, or an invalid VehicleID when
|
||||
* it failed. Check the return value using IsValidVehicle. In test-mode
|
||||
* 0 is returned if it was successful; any other value indicates failure.
|
||||
* @note In Test Mode it means you can't assign orders yet to this vehicle,
|
||||
* as the vehicle isn't really built yet. Build it for real first before
|
||||
* assigning orders.
|
||||
*/
|
||||
static VehicleID BuildVehicleWithRefit(TileIndex depot, EngineID engine_id, CargoID cargo);
|
||||
|
||||
/**
|
||||
* Gets the capacity of a vehicle built at the given depot with the given engine and refitted to the given cargo.
|
||||
* @param depot The depot where the vehicle will be build.
|
||||
* @param engine_id The engine to use for this vehicle.
|
||||
* @param cargo The cargo to refit to.
|
||||
* @pre The tile at depot has a depot that can build the engine and
|
||||
* is owned by you.
|
||||
* @pre ScriptEngine::IsBuildable(engine_id).
|
||||
* @pre ScriptCargo::IsValidCargo(cargo).
|
||||
* @return The capacity the vehicle will have when refited.
|
||||
*/
|
||||
static int GetBuildWithRefitCapacity(TileIndex depot, EngineID engine_id, CargoID cargo);
|
||||
|
||||
/**
|
||||
* Clones a vehicle at the given depot, copying or cloning its orders.
|
||||
* @param depot The depot where the vehicle will be build.
|
||||
@@ -563,6 +598,11 @@ public:
|
||||
static uint GetMaximumOrderDistance(VehicleID vehicle_id);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal function used by BuildVehicle(WithRefit).
|
||||
*/
|
||||
static VehicleID _BuildVehicleInternal(TileIndex depot, EngineID engine_id, CargoID cargo);
|
||||
|
||||
/**
|
||||
* Internal function used by SellWagon(Chain).
|
||||
*/
|
||||
|
Reference in New Issue
Block a user