summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-09-21 13:07:42 +0000
committerzuu <zuu@openttd.org>2013-09-21 13:07:42 +0000
commitab69c6c2a0ba9ab36db4a20c0e6db2ea404746bf (patch)
treecadbe91c284755b63ace0e8a146bdbbb48cb2fdc /src/script
parent01dea4ec37e79b2db08bbeb99727592b01eeb492 (diff)
downloadopenttd-ab69c6c2a0ba9ab36db4a20c0e6db2ea404746bf.tar.xz
(svn r25788) -Feature: [Script] Game Scripts can now charge fees and give money to companies
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/game/game_company.hpp.sq33
-rw-r--r--src/script/api/game_changelog.hpp1
-rw-r--r--src/script/api/script_company.cpp12
-rw-r--r--src/script/api/script_company.hpp35
-rw-r--r--src/script/api/template/template_company.hpp.sq2
5 files changed, 74 insertions, 9 deletions
diff --git a/src/script/api/game/game_company.hpp.sq b/src/script/api/game/game_company.hpp.sq
index 98c6d4476..f53d55baa 100644
--- a/src/script/api/game/game_company.hpp.sq
+++ b/src/script/api/game/game_company.hpp.sq
@@ -21,15 +21,29 @@ void SQGSCompany_Register(Squirrel *engine)
SQGSCompany.PreRegister(engine);
SQGSCompany.AddConstructor<void (ScriptCompany::*)(), 1>(engine, "x");
- SQGSCompany.DefSQConst(engine, ScriptCompany::CURRENT_QUARTER, "CURRENT_QUARTER");
- SQGSCompany.DefSQConst(engine, ScriptCompany::EARLIEST_QUARTER, "EARLIEST_QUARTER");
- SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_FIRST, "COMPANY_FIRST");
- SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_LAST, "COMPANY_LAST");
- SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_INVALID, "COMPANY_INVALID");
- SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_SELF, "COMPANY_SELF");
- SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_MALE, "GENDER_MALE");
- SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_FEMALE, "GENDER_FEMALE");
- SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::CURRENT_QUARTER, "CURRENT_QUARTER");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EARLIEST_QUARTER, "EARLIEST_QUARTER");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_FIRST, "COMPANY_FIRST");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_LAST, "COMPANY_LAST");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_INVALID, "COMPANY_INVALID");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_SELF, "COMPANY_SELF");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_MALE, "GENDER_MALE");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_FEMALE, "GENDER_FEMALE");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_CONSTRUCTION, "EXPENSES_CONSTRUCTION");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_NEW_VEHICLES, "EXPENSES_NEW_VEHICLES");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_TRAIN_RUN, "EXPENSES_TRAIN_RUN");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_ROADVEH_RUN, "EXPENSES_ROADVEH_RUN");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_AIRCRAFT_RUN, "EXPENSES_AIRCRAFT_RUN");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_SHIP_RUN, "EXPENSES_SHIP_RUN");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_PROPERTY, "EXPENSES_PROPERTY");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_TRAIN_INC, "EXPENSES_TRAIN_INC");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_ROADVEH_INC, "EXPENSES_ROADVEH_INC");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_AIRCRAFT_INC, "EXPENSES_AIRCRAFT_INC");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_SHIP_INC, "EXPENSES_SHIP_INC");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_LOAN_INT, "EXPENSES_LOAN_INT");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::EXPENSES_OTHER, "EXPENSES_OTHER");
+ SQGSCompany.DefSQConst(engine, ScriptCompany::INVALID_EXPENSES, "INVALID_EXPENSES");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::SetName, "SetName", 2, "..");
@@ -43,6 +57,7 @@ void SQGSCompany_Register(Squirrel *engine)
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetMaxLoanAmount, "GetMaxLoanAmount", 1, ".");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetLoanInterval, "GetLoanInterval", 1, ".");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetBankBalance, "GetBankBalance", 2, ".i");
+ SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::ChangeBankBalance, "ChangeBankBalance", 4, ".iii");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetQuarterlyIncome, "GetQuarterlyIncome", 3, ".ii");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetQuarterlyExpenses, "GetQuarterlyExpenses", 3, ".ii");
SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetQuarterlyCargoDelivered, "GetQuarterlyCargoDelivered", 3, ".ii");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index ebab776a4..59893a19a 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -20,6 +20,7 @@
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
* API additions:
+ * \li GSCompany::ChangeBankBalance
* \li GSGoal::IsCompleted
* \li GSGoal::SetCompleted
* \li GSGoal::SetProgress
diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp
index 2f06fd69d..01c2ce6ec 100644
--- a/src/script/api/script_company.cpp
+++ b/src/script/api/script_company.cpp
@@ -12,6 +12,7 @@
#include "../../stdafx.h"
#include "script_company.hpp"
#include "script_error.hpp"
+#include "script_companymode.hpp"
#include "../../company_func.h"
#include "../../company_base.h"
#include "../../company_manager_face.h"
@@ -223,6 +224,17 @@
return GetLoanAmount() == loan;
}
+/* static */ bool ScriptCompany::ChangeBankBalance(CompanyID company, int32 delta, ExpensesType expenses_type)
+{
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, expenses_type < ::EXPENSES_END);
+
+ company = ResolveCompanyID(company);
+ EnforcePrecondition(false, ResolveCompanyID(company) != COMPANY_INVALID);
+
+ return ScriptObject::DoCommand(0, (uint32)(delta), company | expenses_type << 8 , CMD_CHANGE_BANK_BALANCE);
+}
+
/* static */ bool ScriptCompany::BuildCompanyHQ(TileIndex tile)
{
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp
index e6c3dcb31..349961961 100644
--- a/src/script/api/script_company.hpp
+++ b/src/script/api/script_company.hpp
@@ -13,6 +13,7 @@
#define SCRIPT_COMPANY_HPP
#include "script_text.hpp"
+#include "../../economy_type.h"
/**
* Class that handles all company related functions.
@@ -45,6 +46,27 @@ public:
};
/**
+ * Types of expenses.
+ * @api -ai
+ */
+ enum ExpensesType {
+ EXPENSES_CONSTRUCTION = ::EXPENSES_CONSTRUCTION, ///< Construction costs.
+ EXPENSES_NEW_VEHICLES = ::EXPENSES_NEW_VEHICLES, ///< New vehicles.
+ EXPENSES_TRAIN_RUN = ::EXPENSES_TRAIN_RUN, ///< Running costs trains.
+ EXPENSES_ROADVEH_RUN = ::EXPENSES_ROADVEH_RUN, ///< Running costs road vehicles.
+ EXPENSES_AIRCRAFT_RUN = ::EXPENSES_AIRCRAFT_RUN, ///< Running costs aircrafts.
+ EXPENSES_SHIP_RUN = ::EXPENSES_SHIP_RUN, ///< Running costs ships.
+ EXPENSES_PROPERTY = ::EXPENSES_PROPERTY, ///< Property costs.
+ EXPENSES_TRAIN_INC = ::EXPENSES_TRAIN_INC, ///< Income from trains.
+ EXPENSES_ROADVEH_INC = ::EXPENSES_ROADVEH_INC, ///< Income from road vehicles.
+ EXPENSES_AIRCRAFT_INC = ::EXPENSES_AIRCRAFT_INC, ///< Income from aircrafts.
+ EXPENSES_SHIP_INC = ::EXPENSES_SHIP_INC, ///< Income from ships.
+ EXPENSES_LOAN_INT = ::EXPENSES_LOAN_INT, ///< Interest payments over the loan.
+ EXPENSES_OTHER = ::EXPENSES_OTHER, ///< Other expenses.
+ INVALID_EXPENSES = ::INVALID_EXPENSES, ///< Invalid expense type.
+ };
+
+ /**
* Resolved the given company index to the correct index for the company. If
* the company index was COMPANY_SELF it will be resolved to the index of
* your company. If the company with the given index does not exist it will
@@ -165,6 +187,19 @@ public:
static Money GetBankBalance(CompanyID company);
/**
+ * Changes the bank balance by a delta value. This method does not affect the loan but instead
+ * allows a GS to give or take money from a company.
+ * @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.
+ * @game @pre No ScriptCompanyMode active in scope.
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID.
+ * @note You need to create your own news message to inform about costs/gifts that you create using this command.
+ * @api -ai
+ */
+ static bool ChangeBankBalance(CompanyID company, int32 delta, ExpensesType expenses_type);
+
+ /**
* Get the income of the company in the given quarter.
* Note that this function only considers recurring income from vehicles;
* it does not include one-time income from selling stuff.
diff --git a/src/script/api/template/template_company.hpp.sq b/src/script/api/template/template_company.hpp.sq
index 5668e893e..7dc63f24b 100644
--- a/src/script/api/template/template_company.hpp.sq
+++ b/src/script/api/template/template_company.hpp.sq
@@ -19,6 +19,8 @@ namespace SQConvert {
template <> inline int Return<ScriptCompany::CompanyID>(HSQUIRRELVM vm, ScriptCompany::CompanyID res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptCompany::Gender GetParam(ForceType<ScriptCompany::Gender>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptCompany::Gender)tmp; }
template <> inline int Return<ScriptCompany::Gender>(HSQUIRRELVM vm, ScriptCompany::Gender res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline ScriptCompany::ExpensesType GetParam(ForceType<ScriptCompany::ExpensesType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptCompany::ExpensesType)tmp; }
+ template <> inline int Return<ScriptCompany::ExpensesType>(HSQUIRRELVM vm, ScriptCompany::ExpensesType res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow ScriptCompany to be used as Squirrel parameter */
template <> inline ScriptCompany *GetParam(ForceType<ScriptCompany *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptCompany *)instance; }