From 5858c534202ef45039293e3a6020993621cc55a8 Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 21:01:12 +0000 Subject: (svn r23628) -Add: ScriptSubsidy::Create, to create subsidies (GameScript only) --- src/script/api/game/game_subsidy.hpp.sq | 1 + src/script/api/script_subsidy.cpp | 14 ++++++++++++++ src/script/api/script_subsidy.hpp | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+) (limited to 'src/script/api') diff --git a/src/script/api/game/game_subsidy.hpp.sq b/src/script/api/game/game_subsidy.hpp.sq index bba8abce5..2d636f74d 100644 --- a/src/script/api/game/game_subsidy.hpp.sq +++ b/src/script/api/game/game_subsidy.hpp.sq @@ -27,6 +27,7 @@ void SQGSSubsidy_Register(Squirrel *engine) SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::IsValidSubsidy, "IsValidSubsidy", 2, ".i"); SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::IsAwarded, "IsAwarded", 2, ".i"); + SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::Create, "Create", 6, ".iiiii"); SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::GetAwardedTo, "GetAwardedTo", 2, ".i"); SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::GetExpireDate, "GetExpireDate", 2, ".i"); SQGSSubsidy.DefSQStaticMethod(engine, &ScriptSubsidy::GetCargoType, "GetCargoType", 2, ".i"); diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp index 6bc7ba8b9..8ec074d4d 100644 --- a/src/script/api/script_subsidy.cpp +++ b/src/script/api/script_subsidy.cpp @@ -12,6 +12,9 @@ #include "../../stdafx.h" #include "script_subsidy.hpp" #include "script_date.hpp" +#include "script_industry.hpp" +#include "script_town.hpp" +#include "script_error.hpp" #include "../../subsidy_base.h" #include "../../station_base.h" @@ -27,6 +30,17 @@ return ::Subsidy::Get(subsidy_id)->IsAwarded(); } +/* static */ bool ScriptSubsidy::Create(CargoID cargo_type, SubsidyParticipantType from_type, uint16 from_id, SubsidyParticipantType to_type, uint16 to_id) +{ + EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type)); + EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN); + EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN); + EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id))); + EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id))); + + return ScriptObject::DoCommand(0, from_type | (from_id << 8) | (cargo_type << 24), to_type | (to_id << 8), CMD_CREATE_SUBSIDY); +} + /* static */ ScriptCompany::CompanyID ScriptSubsidy::GetAwardedTo(SubsidyID subsidy_id) { if (!IsAwarded(subsidy_id)) return ScriptCompany::COMPANY_INVALID; diff --git a/src/script/api/script_subsidy.hpp b/src/script/api/script_subsidy.hpp index b6742ab1c..bf565056e 100644 --- a/src/script/api/script_subsidy.hpp +++ b/src/script/api/script_subsidy.hpp @@ -25,6 +25,9 @@ public: * @note The list of values may grow in future. */ enum SubsidyParticipantType { + /* Values are important, as they represent the internal state of the game. + * It is orignally named SourceType. ST_HEADQUARTERS is intentionally + * left out, as it cannot be used for Subsidies. */ SPT_INDUSTRY = 0, ///< Subsidy participant is an industry SPT_TOWN = 1, ///< Subsidy participant is a town SPT_INVALID = 0xFF, ///< Invalid/unknown participant type @@ -45,6 +48,23 @@ public: */ static bool IsAwarded(SubsidyID subsidy_id); + /** + * Create a new subsidy. + * @param cargo_type The type of cargo to cary for the subsidy. + * @param from_type The type of the subsidy on the 'from' side. + * @param from_id The ID of the 'from' side. + * @param to_type The type of the subsidy on the 'to' side. + * @param to_id The ID of the 'to' side. + * @return True if the action succeeded. + * @pre ScriptCargo::IsValidCargo(cargo_type) + * @pre from_type == SPT_INDUSTRY || from_type == SPT_TOWN. + * @pre to_type == SPT_INDUSTRY || to_type == SPT_TOWN. + * @pre (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id)) + * @pre (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id)) + * @api -ai + */ + static bool Create(CargoID cargo_type, SubsidyParticipantType from_type, uint16 from_id, SubsidyParticipantType to_type, uint16 to_id); + /** * Get the company index of the company this subsidy is awarded to. * @param subsidy_id The SubsidyID to check. -- cgit v1.2.3-54-g00ecf