mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Feature: GS method to control engine availability for a specific company (#7791)
* Feature: GS method to allow company to use an engine before its introduction date * Feature: GS method to retire an engine early for a specific company
This commit is contained in:
parent
4366f8e46a
commit
d7a928a08b
@ -105,6 +105,7 @@ CommandProc CmdIncreaseLoan;
|
|||||||
CommandProc CmdDecreaseLoan;
|
CommandProc CmdDecreaseLoan;
|
||||||
|
|
||||||
CommandProc CmdWantEnginePreview;
|
CommandProc CmdWantEnginePreview;
|
||||||
|
CommandProc CmdEngineCtrl;
|
||||||
|
|
||||||
CommandProc CmdRenameVehicle;
|
CommandProc CmdRenameVehicle;
|
||||||
CommandProc CmdRenameEngine;
|
CommandProc CmdRenameEngine;
|
||||||
@ -270,6 +271,7 @@ static const Command _command_proc_table[] = {
|
|||||||
DEF_CMD(CmdDecreaseLoan, 0, CMDT_MONEY_MANAGEMENT ), // CMD_DECREASE_LOAN
|
DEF_CMD(CmdDecreaseLoan, 0, CMDT_MONEY_MANAGEMENT ), // CMD_DECREASE_LOAN
|
||||||
|
|
||||||
DEF_CMD(CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_WANT_ENGINE_PREVIEW
|
DEF_CMD(CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_WANT_ENGINE_PREVIEW
|
||||||
|
DEF_CMD(CmdEngineCtrl, CMD_DEITY, CMDT_VEHICLE_MANAGEMENT ), // CMD_ENGINE_CTRL
|
||||||
|
|
||||||
DEF_CMD(CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE
|
DEF_CMD(CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE
|
||||||
DEF_CMD(CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE
|
DEF_CMD(CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE
|
||||||
|
@ -238,6 +238,7 @@ enum Commands {
|
|||||||
CMD_DECREASE_LOAN, ///< decrease the loan from the bank
|
CMD_DECREASE_LOAN, ///< decrease the loan from the bank
|
||||||
|
|
||||||
CMD_WANT_ENGINE_PREVIEW, ///< confirm the preview of an engine
|
CMD_WANT_ENGINE_PREVIEW, ///< confirm the preview of an engine
|
||||||
|
CMD_ENGINE_CTRL, ///< control availability of the engine for companies
|
||||||
|
|
||||||
CMD_RENAME_VEHICLE, ///< rename a whole vehicle
|
CMD_RENAME_VEHICLE, ///< rename a whole vehicle
|
||||||
CMD_RENAME_ENGINE, ///< rename a engine (in the engine list)
|
CMD_RENAME_ENGINE, ///< rename a engine (in the engine list)
|
||||||
|
@ -710,11 +710,11 @@ void StartupEngines()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Company \a company accepts engine \a eid for preview.
|
* Allows engine \a eid to be used by a company \a company.
|
||||||
* @param eid Engine being accepted (is under preview).
|
* @param eid The engine to enable.
|
||||||
* @param company Current company previewing the engine.
|
* @param company The company to allow using the engine.
|
||||||
*/
|
*/
|
||||||
static void AcceptEnginePreview(EngineID eid, CompanyID company)
|
static void EnableEngineForCompany(EngineID eid, CompanyID company)
|
||||||
{
|
{
|
||||||
Engine *e = Engine::Get(eid);
|
Engine *e = Engine::Get(eid);
|
||||||
Company *c = Company::Get(company);
|
Company *c = Company::Get(company);
|
||||||
@ -728,15 +728,45 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
|
|||||||
c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
|
c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->u.road.roadtype)->introduces_roadtypes, _date);
|
||||||
}
|
}
|
||||||
|
|
||||||
e->preview_company = INVALID_COMPANY;
|
if (company == _local_company) {
|
||||||
e->preview_asked = (CompanyMask)-1;
|
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||||
|
|
||||||
|
/* Update the toolbar. */
|
||||||
|
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
||||||
|
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||||
|
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forbids engine \a eid to be used by a company \a company.
|
||||||
|
* @param eid The engine to disable.
|
||||||
|
* @param company The company to forbid using the engine.
|
||||||
|
*/
|
||||||
|
static void DisableEngineForCompany(EngineID eid, CompanyID company)
|
||||||
|
{
|
||||||
|
Engine *e = Engine::Get(eid);
|
||||||
|
|
||||||
|
ClrBit(e->company_avail, company);
|
||||||
|
|
||||||
if (company == _local_company) {
|
if (company == _local_company) {
|
||||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Update the toolbar. */
|
/**
|
||||||
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
* Company \a company accepts engine \a eid for preview.
|
||||||
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
* @param eid Engine being accepted (is under preview).
|
||||||
|
* @param company Current company previewing the engine.
|
||||||
|
*/
|
||||||
|
static void AcceptEnginePreview(EngineID eid, CompanyID company)
|
||||||
|
{
|
||||||
|
Engine *e = Engine::Get(eid);
|
||||||
|
|
||||||
|
e->preview_company = INVALID_COMPANY;
|
||||||
|
e->preview_asked = (CompanyMask)-1;
|
||||||
|
|
||||||
|
EnableEngineForCompany(eid, company);
|
||||||
|
|
||||||
/* Notify preview window, that it might want to close.
|
/* Notify preview window, that it might want to close.
|
||||||
* Note: We cannot directly close the window.
|
* Note: We cannot directly close the window.
|
||||||
@ -891,6 +921,37 @@ CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or forbid a specific company to use an engine
|
||||||
|
* @param tile unused
|
||||||
|
* @param flags operation to perform
|
||||||
|
* @param p1 engine id
|
||||||
|
* @param p2 various bitstuffed elements
|
||||||
|
* - p2 = (bit 0 - 7) - Company to allow/forbid the use of an engine.
|
||||||
|
* - p2 = (bit 31) - 0 to forbid, 1 to allow.
|
||||||
|
* @param text unused
|
||||||
|
* @return the cost of this operation or an error
|
||||||
|
*/
|
||||||
|
CommandCost CmdEngineCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
|
{
|
||||||
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||||
|
EngineID engine_id = (EngineID)p1;
|
||||||
|
CompanyID company_id = (CompanyID)GB(p2, 0, 8);
|
||||||
|
bool allow = HasBit(p2, 31);
|
||||||
|
|
||||||
|
if (!Engine::IsValidID(engine_id) || !Company::IsValidID(company_id)) return CMD_ERROR;
|
||||||
|
|
||||||
|
if (flags & DC_EXEC) {
|
||||||
|
if (allow) {
|
||||||
|
EnableEngineForCompany(engine_id, company_id);
|
||||||
|
} else {
|
||||||
|
DisableEngineForCompany(engine_id, company_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandCost();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An engine has become available for general use.
|
* An engine has become available for general use.
|
||||||
* Also handle the exclusive engine preview contract.
|
* Also handle the exclusive engine preview contract.
|
||||||
|
@ -46,6 +46,8 @@ void SQGSEngine_Register(Squirrel *engine)
|
|||||||
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::IsArticulated, "IsArticulated", 2, ".i");
|
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::IsArticulated, "IsArticulated", 2, ".i");
|
||||||
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetPlaneType, "GetPlaneType", 2, ".i");
|
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetPlaneType, "GetPlaneType", 2, ".i");
|
||||||
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetMaximumOrderDistance, "GetMaximumOrderDistance", 2, ".i");
|
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetMaximumOrderDistance, "GetMaximumOrderDistance", 2, ".i");
|
||||||
|
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::EnableForCompany, "EnableForCompany", 3, ".ii");
|
||||||
|
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::DisableForCompany, "DisableForCompany", 3, ".ii");
|
||||||
|
|
||||||
SQGSEngine.PostRegister(engine);
|
SQGSEngine.PostRegister(engine);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
* \li GSRoad::RoadVehHasPowerOnRoad
|
* \li GSRoad::RoadVehHasPowerOnRoad
|
||||||
* \li GSRoad::ConvertRoadType
|
* \li GSRoad::ConvertRoadType
|
||||||
* \li GSRoad::GetMaxSpeed
|
* \li GSRoad::GetMaxSpeed
|
||||||
|
* \li GSEngine::EnableForCompany
|
||||||
|
* \li GSEngine::DisableForCompany
|
||||||
*
|
*
|
||||||
* \b 1.9.0
|
* \b 1.9.0
|
||||||
*
|
*
|
||||||
|
@ -276,3 +276,25 @@
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ bool ScriptEngine::EnableForCompany(EngineID engine_id, ScriptCompany::CompanyID company)
|
||||||
|
{
|
||||||
|
company = ScriptCompany::ResolveCompanyID(company);
|
||||||
|
|
||||||
|
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||||
|
EnforcePrecondition(false, IsValidEngine(engine_id));
|
||||||
|
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
|
||||||
|
|
||||||
|
return ScriptObject::DoCommand(0, engine_id, (uint32)company | (1 << 31), CMD_ENGINE_CTRL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ bool ScriptEngine::DisableForCompany(EngineID engine_id, ScriptCompany::CompanyID company)
|
||||||
|
{
|
||||||
|
company = ScriptCompany::ResolveCompanyID(company);
|
||||||
|
|
||||||
|
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||||
|
EnforcePrecondition(false, IsValidEngine(engine_id));
|
||||||
|
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
|
||||||
|
|
||||||
|
return ScriptObject::DoCommand(0, engine_id, company, CMD_ENGINE_CTRL);
|
||||||
|
}
|
||||||
|
@ -287,6 +287,29 @@ public:
|
|||||||
* @see ScriptOrder::GetOrderDistance
|
* @see ScriptOrder::GetOrderDistance
|
||||||
*/
|
*/
|
||||||
static uint GetMaximumOrderDistance(EngineID engine_id);
|
static uint GetMaximumOrderDistance(EngineID engine_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows a company to use an engine before its intro date or after retirement.
|
||||||
|
* @param engine_id The engine to enable.
|
||||||
|
* @param company_id The company to allow using the engine.
|
||||||
|
* @pre IsValidEngine(engine_id).
|
||||||
|
* @pre ScriptCompany.ResolveCompanyID(company_id) != ScriptCompany::COMPANY_INVALID.
|
||||||
|
* @return True if the action succeeded.
|
||||||
|
* @api -ai
|
||||||
|
*/
|
||||||
|
static bool EnableForCompany(EngineID engine_id, ScriptCompany::CompanyID company_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forbids a company to use an engine before its natural retirement.
|
||||||
|
* @param engine_id The engine to disable.
|
||||||
|
* @param company_id The company to forbid using the engine.
|
||||||
|
* @pre IsValidEngine(engine_id).
|
||||||
|
* @pre ScriptCompany.ResolveCompanyID(company_id) != ScriptCompany::COMPANY_INVALID.
|
||||||
|
* @return True if the action succeeded.
|
||||||
|
* @api -ai
|
||||||
|
*/
|
||||||
|
static bool DisableForCompany(EngineID engine_id, ScriptCompany::CompanyID company_id);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SCRIPT_ENGINE_HPP */
|
#endif /* SCRIPT_ENGINE_HPP */
|
||||||
|
Loading…
Reference in New Issue
Block a user