2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file script_company.hpp Everything to query a company's financials and statistics or build company related buildings. */
10 #ifndef SCRIPT_COMPANY_HPP
11 #define SCRIPT_COMPANY_HPP
13 #include "script_text.hpp"
14 #include "../../economy_type.h"
15 #include "../../livery.h"
16 #include "../../gfx_type.h"
19 * Class that handles all company related functions.
22 class ScriptCompany
: public ScriptObject
{
24 /** The range of possible quarters to get company information of. */
26 CURRENT_QUARTER
= 0, ///< The current quarter.
27 EARLIEST_QUARTER
= ::MAX_HISTORY_QUARTERS
, ///< The earliest quarter company information is available for.
30 /** Different constants related to CompanyID. */
32 /* Note: these values represent part of the in-game Owner enum */
33 COMPANY_FIRST
= ::COMPANY_FIRST
, ///< The first available company.
34 COMPANY_LAST
= ::MAX_COMPANIES
, ///< The last available company.
36 /* Custom added value, only valid for this API */
37 COMPANY_INVALID
= -1, ///< An invalid company.
38 COMPANY_SELF
= 254, ///< Constant that gets resolved to the correct company index for your company.
39 COMPANY_SPECTATOR
= 255, ///< Constant indicating that player is spectating (gets resolved to COMPANY_INVALID)
42 /** Possible genders for company presidents. */
44 GENDER_MALE
, ///< A male person.
45 GENDER_FEMALE
, ///< A female person.
46 GENDER_INVALID
= -1, ///< An invalid gender.
49 /** List of different livery schemes. */
51 LS_DEFAULT
, ///< Default scheme.
52 LS_STEAM
, ///< Steam engines.
53 LS_DIESEL
, ///< Diesel engines.
54 LS_ELECTRIC
, ///< Electric engines.
55 LS_MONORAIL
, ///< Monorail engines.
56 LS_MAGLEV
, ///< Maglev engines.
57 LS_DMU
, ///< DMUs and their passenger wagons.
58 LS_EMU
, ///< EMUs and their passenger wagons.
59 LS_PASSENGER_WAGON_STEAM
, ///< Passenger wagons attached to steam engines.
60 LS_PASSENGER_WAGON_DIESEL
, ///< Passenger wagons attached to diesel engines.
61 LS_PASSENGER_WAGON_ELECTRIC
, ///< Passenger wagons attached to electric engines.
62 LS_PASSENGER_WAGON_MONORAIL
, ///< Passenger wagons attached to monorail engines.
63 LS_PASSENGER_WAGON_MAGLEV
, ///< Passenger wagons attached to maglev engines.
64 LS_FREIGHT_WAGON
, ///< Freight wagons.
66 LS_TRUCK
, ///< Trucks.
67 LS_PASSENGER_SHIP
, ///< Passenger ships.
68 LS_FREIGHT_SHIP
, ///< Freight ships.
69 LS_HELICOPTER
, ///< Helicopters.
70 LS_SMALL_PLANE
, ///< Small aeroplanes.
71 LS_LARGE_PLANE
, ///< Large aeroplanes.
72 LS_PASSENGER_TRAM
, ///< Passenger trams.
73 LS_FREIGHT_TRAM
, ///< Freight trams.
77 /** List of colours. */
95 COLOUR_INVALID
= ::INVALID_COLOUR
102 enum ExpensesType
: uint8_t {
103 EXPENSES_CONSTRUCTION
= ::EXPENSES_CONSTRUCTION
, ///< Construction costs.
104 EXPENSES_NEW_VEHICLES
= ::EXPENSES_NEW_VEHICLES
, ///< New vehicles.
105 EXPENSES_TRAIN_RUN
= ::EXPENSES_TRAIN_RUN
, ///< Running costs trains.
106 EXPENSES_ROADVEH_RUN
= ::EXPENSES_ROADVEH_RUN
, ///< Running costs road vehicles.
107 EXPENSES_AIRCRAFT_RUN
= ::EXPENSES_AIRCRAFT_RUN
, ///< Running costs aircraft.
108 EXPENSES_SHIP_RUN
= ::EXPENSES_SHIP_RUN
, ///< Running costs ships.
109 EXPENSES_PROPERTY
= ::EXPENSES_PROPERTY
, ///< Property costs.
110 EXPENSES_TRAIN_INC
= ::EXPENSES_TRAIN_REVENUE
, ///< Revenue from trains.
111 EXPENSES_ROADVEH_INC
= ::EXPENSES_ROADVEH_REVENUE
, ///< Revenue from road vehicles.
112 EXPENSES_AIRCRAFT_INC
= ::EXPENSES_AIRCRAFT_REVENUE
, ///< Revenue from aircraft.
113 EXPENSES_SHIP_INC
= ::EXPENSES_SHIP_REVENUE
, ///< Revenue from ships.
114 EXPENSES_LOAN_INT
= ::EXPENSES_LOAN_INTEREST
, ///< Interest payments over the loan.
115 EXPENSES_OTHER
= ::EXPENSES_OTHER
, ///< Other expenses.
116 EXPENSES_INVALID
= ::INVALID_EXPENSES
, ///< Invalid expense type.
120 * Resolved the given company index to the correct index for the company. If
121 * the company index was COMPANY_SELF it will be resolved to the index of
122 * your company. If the company with the given index does not exist it will
123 * return COMPANY_INVALID.
124 * @param company The company index to resolve.
125 * @return The resolved company index.
127 static CompanyID
ResolveCompanyID(CompanyID company
);
130 * Check if a CompanyID is your CompanyID, to ease up checks.
131 * @param company The company index to check.
132 * @game @pre ScriptCompanyMode::IsValid().
133 * @return True if and only if this company is your CompanyID.
135 static bool IsMine(CompanyID company
);
138 * Set the name of your company.
139 * @param name The new name of the company (can be either a raw string, or a ScriptText object).
140 * @pre name != null && len(name) != 0.
141 * @game @pre ScriptCompanyMode::IsValid().
142 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
143 * @return True if the name was changed.
145 static bool SetName(Text
*name
);
148 * Get the name of the given company.
149 * @param company The company to get the name for.
150 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
151 * @return The name of the given company.
153 static std::optional
<std::string
> GetName(CompanyID company
);
156 * Set the name of your president.
157 * @param name The new name of the president (can be either a raw string, or a ScriptText object).
158 * @pre name != null && len(name) != 0.
159 * @game @pre ScriptCompanyMode::IsValid().
160 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
161 * @return True if the name was changed.
163 static bool SetPresidentName(Text
*name
);
166 * Get the name of the president of the given company.
167 * @param company The company to get the president's name for.
168 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
169 * @return The name of the president of the given company.
171 static std::optional
<std::string
> GetPresidentName(CompanyID company
);
174 * Set the gender of the president of your company.
175 * @param gender The new gender for your president.
176 * @pre GetPresidentGender(ScriptCompany.COMPANY_SELF) != gender.
177 * @game @pre ScriptCompanyMode::IsValid().
178 * @return True if the gender was changed.
179 * @note When successful a random face will be created.
181 static bool SetPresidentGender(Gender gender
);
184 * Get the gender of the president of the given company.
185 * @param company The company to get the presidents gender off.
186 * @return The gender of the president.
188 static Gender
GetPresidentGender(CompanyID company
);
191 * Sets the amount to loan.
192 * @param loan The amount to loan (multiplier of GetLoanInterval()).
193 * @pre 'loan' must be non-negative.
194 * @pre GetLoanInterval() must be a multiplier of 'loan'.
195 * @pre 'loan' must be below GetMaxLoanAmount().
196 * @pre 'loan' - GetLoanAmount() + GetBankBalance() must be non-negative.
197 * @game @pre ScriptCompanyMode::IsValid().
198 * @return True if the loan could be set to your requested amount.
200 static bool SetLoanAmount(Money loan
);
203 * Sets the minimum amount to loan, i.e. the given amount of loan rounded up.
204 * @param loan The amount to loan (any positive number).
205 * @pre 'loan' must be non-negative.
206 * @pre 'loan' must be below GetMaxLoanAmount().
207 * @game @pre ScriptCompanyMode::IsValid().
208 * @return True if we could allocate a minimum of 'loan' loan.
210 static bool SetMinimumLoanAmount(Money loan
);
213 * Gets the amount your company have loaned.
214 * @return The amount loaned money.
215 * @post GetLoanInterval() is always a multiplier of the return value.
217 static Money
GetLoanAmount();
220 * Gets the maximum amount your company can loan. In deity mode returns the global max loan.
221 * @return The maximum amount your company can loan.
222 * @post GetLoanInterval() is always a multiplier of the return value.
224 static Money
GetMaxLoanAmount();
227 * Sets the max amount of money company can loan.
228 * @param company The company ID.
229 * @param amount Max loan amount. Will be rounded down to a multiple of GetLoanInterval().
230 * @return True, if the max loan was changed.
231 * @pre ScriptCompanyMode::IsDeity().
233 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
234 * @note You need to create your own news message to inform about max loan change.
235 * @note Max loan value set with this method is not affected by inflation.
238 static bool SetMaxLoanAmountForCompany(CompanyID company
, Money amount
);
241 * Makes the max amount of money company can loan follow the global max loan setting.
242 * @param company The company ID.
243 * @return True, if the max loan was reset.
244 * @pre ScriptCompanyMode::IsDeity().
245 * @pre amount >= 0 && amount <= MAX_LOAN_LIMIT.
246 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
247 * @note You need to create your own news message to inform about max loan change.
250 static bool ResetMaxLoanAmountForCompany(CompanyID company
);
253 * Gets the interval/loan step.
254 * @return The loan step.
255 * @post Return value is always positive.
257 static Money
GetLoanInterval();
260 * Gets the bank balance. In other words, the amount of money the given company can spent.
261 * If infinite money is enabled, it returns INT32_MAX.
262 * @param company The company to get the bank balance of.
263 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
264 * @return The actual bank balance or INT32_MAX.
266 static Money
GetBankBalance(CompanyID company
);
269 * Changes the bank balance by a delta value. This method does not affect the loan but instead
270 * allows a GS to give or take money from a company.
271 * @param company The company to change the bank balance of.
272 * @param delta Amount of money to give or take from the bank balance. A positive value adds money to the bank balance.
273 * @param expenses_type The account in the finances window that will register the cost.
274 * @param tile The tile to show text effect on or ScriptMap::TILE_INVALID
275 * @return True, if the bank balance was changed.
276 * @game @pre ScriptCompanyMode::IsDeity().
277 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
278 * @note You need to create your own news message to inform about costs/gifts that you create using this command.
281 static bool ChangeBankBalance(CompanyID company
, Money delta
, ExpensesType expenses_type
, TileIndex tile
);
284 * Get the income of the company in the given economy-quarter.
285 * Note that this function only considers recurring income from vehicles;
286 * it does not include one-time income from selling stuff.
287 * @param company The company to get the quarterly income of.
288 * @param quarter The economy-quarter to get the income of.
289 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
290 * @pre quarter <= EARLIEST_QUARTER.
291 * @return The gross income of the company in the given economy-quarter.
292 * @see \ref ScriptEconomyTime
294 static Money
GetQuarterlyIncome(CompanyID company
, SQInteger quarter
);
297 * Get the expenses of the company in the given economy-quarter.
298 * Note that this function only considers recurring expenses from vehicle
299 * running cost, maintenance and interests; it does not include one-time
300 * expenses from construction and buying stuff.
301 * @param company The company to get the quarterly expenses of.
302 * @param quarter The economy-quarter to get the expenses of.
303 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
304 * @pre quarter <= EARLIEST_QUARTER.
305 * @return The expenses of the company in the given economy-quarter.
306 * @see \ref ScriptEconomyTime
308 static Money
GetQuarterlyExpenses(CompanyID company
, SQInteger quarter
);
311 * Get the amount of cargo delivered by the given company in the given economy-quarter.
312 * @param company The company to get the amount of delivered cargo of.
313 * @param quarter The economy-quarter to get the amount of delivered cargo of.
314 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
315 * @pre quarter <= EARLIEST_QUARTER.
316 * @return The amount of cargo delivered by the given company in the given economy-quarter.
317 * @see \ref ScriptEconomyTime
319 static SQInteger
GetQuarterlyCargoDelivered(CompanyID company
, SQInteger quarter
);
322 * Get the performance rating of the given company in the given economy-quarter.
323 * @param company The company to get the performance rating of.
324 * @param quarter The economy-quarter to get the performance rating of.
325 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
326 * @pre quarter <= EARLIEST_QUARTER.
327 * @pre quarter != CURRENT_QUARTER.
328 * @note The performance rating is calculated after every economy-quarter, so the value for CURRENT_QUARTER is undefined.
329 * @return The performance rating of the given company in the given economy-quarter.
330 * @see \ref ScriptEconomyTime
332 static SQInteger
GetQuarterlyPerformanceRating(CompanyID company
, SQInteger quarter
);
335 * Get the value of the company in the given economy-quarter.
336 * @param company The company to get the value of.
337 * @param quarter The economy-quarter to get the value of.
338 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
339 * @pre quarter <= EARLIEST_QUARTER.
340 * @return The value of the company in the given economy-quarter.
341 * @see \ref ScriptEconomyTime
343 static Money
GetQuarterlyCompanyValue(CompanyID company
, SQInteger quarter
);
346 * Build your company's HQ on the given tile.
347 * @param tile The tile to build your HQ on, this tile is the most northern tile of your HQ.
348 * @pre ScriptMap::IsValidTile(tile).
349 * @game @pre ScriptCompanyMode::IsValid().
350 * @exception ScriptError::ERR_AREA_NOT_CLEAR
351 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED
352 * @return True if the HQ could be build.
353 * @note An HQ can not be removed, only by water or rebuilding; If an HQ is
354 * build again, the old one is removed.
356 static bool BuildCompanyHQ(TileIndex tile
);
359 * Return the location of a company's HQ.
360 * @param company The company the get the HQ of.
361 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
362 * @return The tile of the company's HQ, this tile is the most northern tile
363 * of that HQ, or ScriptMap::TILE_INVALID if there is no HQ yet.
365 static TileIndex
GetCompanyHQ(CompanyID company
);
368 * Set whether autorenew is enabled for your company.
369 * @param autorenew The new autorenew status.
370 * @game @pre ScriptCompanyMode::IsValid().
371 * @return True if autorenew status has been modified.
373 static bool SetAutoRenewStatus(bool autorenew
);
376 * Return whether autorenew is enabled for a company.
377 * @param company The company to get the autorenew status of.
378 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
379 * @return True if autorenew is enabled.
381 static bool GetAutoRenewStatus(CompanyID company
);
384 * Set the number of months before/after max age to autorenew an engine for your company.
385 * @param months The number of calendar-months before/after max age of engine.
386 * The value will be clamped to MIN(int16_t) .. MAX(int16_t).
387 * @game @pre ScriptCompanyMode::IsValid().
388 * @return True if autorenew months has been modified.
389 * @see \ref ScriptCalendarTime
391 static bool SetAutoRenewMonths(SQInteger months
);
394 * Return the number of months before/after max age to autorenew an engine for a company.
395 * @param company The company to get the autorenew months of.
396 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
397 * @return The number of calendar-months before/after max age of engine.
398 * @see \ref ScriptCalendarTime
400 static SQInteger
GetAutoRenewMonths(CompanyID company
);
403 * Set the minimum money needed to autorenew an engine for your company.
404 * @param money The new minimum required money for autorenew to work.
405 * @game @pre ScriptCompanyMode::IsValid().
406 * @return True if autorenew money has been modified.
410 static bool SetAutoRenewMoney(Money money
);
413 * Return the minimum money needed to autorenew an engine for a company.
414 * @param company The company to get the autorenew money of.
415 * @pre ResolveCompanyID(company) != COMPANY_INVALID.
416 * @return The minimum required money for autorenew to work.
418 static Money
GetAutoRenewMoney(CompanyID company
);
421 * Set primary colour for your company.
422 * @param scheme Livery scheme to set.
423 * @param colour Colour to set.
424 * @game @pre ScriptCompanyMode::IsValid().
425 * @return False if unable to set primary colour of the livery scheme (e.g. colour in use).
427 static bool SetPrimaryLiveryColour(LiveryScheme scheme
, Colours colour
);
430 * Set secondary colour for your company.
431 * @param scheme Livery scheme to set.
432 * @param colour Colour to set.
433 * @game @pre ScriptCompanyMode::IsValid().
434 * @return False if unable to set secondary colour of the livery scheme.
436 static bool SetSecondaryLiveryColour(LiveryScheme scheme
, Colours colour
);
439 * Get primary colour of a livery for your company.
440 * @param scheme Livery scheme to get.
441 * @return Primary colour of livery.
443 static ScriptCompany::Colours
GetPrimaryLiveryColour(LiveryScheme scheme
);
446 * Get secondary colour of a livery for your company.
447 * @param scheme Livery scheme to get.
448 * @return Secondary colour of livery.
450 static ScriptCompany::Colours
GetSecondaryLiveryColour(LiveryScheme scheme
);
453 DECLARE_POSTFIX_INCREMENT(ScriptCompany::CompanyID
)
455 #endif /* SCRIPT_COMPANY_HPP */