Handling of subsidies. More...
#include "stdafx.h"
#include "company_func.h"
#include "industry.h"
#include "town.h"
#include "news_func.h"
#include "ai/ai.hpp"
#include "station_base.h"
#include "strings_func.h"
#include "window_func.h"
#include "subsidy_base.h"
#include "subsidy_func.h"
#include "core/pool_func.hpp"
#include "core/random_func.hpp"
#include "game/game.hpp"
#include "command_func.h"
#include "table/strings.h"
Go to the source code of this file.
Functions | |
Pair | SetupSubsidyDecodeParam (const Subsidy *s, bool mode) |
Setup the string parameters for printing the subsidy at the screen, and compute the news reference for the subsidy. | |
static void | SetPartOfSubsidyFlag (SourceType type, SourceID index, PartOfSubsidy flag) |
Sets a flag indicating that given town/industry is part of subsidised route. | |
void | RebuildSubsidisedSourceAndDestinationCache () |
Perform a full rebuild of the subsidies cache. | |
void | DeleteSubsidyWith (SourceType type, SourceID index) |
Delete the subsidies associated with a given cargo source type and id. | |
static bool | CheckSubsidyDuplicate (CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
Check whether a specific subsidy already exists. | |
static bool | CheckSubsidyDistance (SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
Checks if the source and destination of a subsidy are inside the distance limit. | |
void | CreateSubsidy (CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
Creates a subsidy with the given parameters. | |
CommandCost | CmdCreateSubsidy (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Create a new subsidy. | |
bool | FindSubsidyPassengerRoute () |
Tries to create a passenger subsidy between two towns. | |
bool | FindSubsidyCargoDestination (CargoID cid, SourceType src_type, SourceID src) |
Tries to find a suitable destination for the given source and cargo. | |
bool | FindSubsidyTownCargoRoute () |
Tries to create a cargo subsidy with a town as source. | |
bool | FindSubsidyIndustryCargoRoute () |
Tries to create a cargo subsidy with an industry as source. | |
void | SubsidyMonthlyLoop () |
Perform the monthly update of open subsidies, and try to create a new one. | |
bool | CheckSubsidised (CargoID cargo_type, CompanyID company, SourceType src_type, SourceID src, const Station *st) |
Tests whether given delivery is subsidised and possibly awards the subsidy to delivering company. | |
Variables | |
SubsidyPool | _subsidy_pool ("Subsidy") |
Pool for the subsidies. |
Handling of subsidies.
Definition in file subsidy.cpp.
bool CheckSubsidised | ( | CargoID | cargo_type, | |
CompanyID | company, | |||
SourceType | src_type, | |||
SourceID | src, | |||
const Station * | st | |||
) |
Tests whether given delivery is subsidised and possibly awards the subsidy to delivering company.
cargo_type | type of cargo | |
company | company delivering the cargo | |
src_type | type of src | |
src | index of source | |
st | station where the cargo is delivered to |
Definition at line 525 of file subsidy.cpp.
References Subsidy::awarded, Subsidy::AwardTo(), SmallVector< T, S >::Begin(), Subsidy::cargo_type, Subsidy::dst, Subsidy::dst_type, SmallVector< T, S >::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), SmallVector< T, S >::Include(), INVALID_SOURCE, Subsidy::IsAwarded(), IsTileType(), MP_HOUSE, Town::part_of_subsidy, POS_DST, POS_SRC, Subsidy::src, Subsidy::src_type, ST_INDUSTRY, ST_TOWN, and TileXY().
Referenced by DeliverGoods().
static bool CheckSubsidyDistance | ( | SourceType | src_type, | |
SourceID | src, | |||
SourceType | dst_type, | |||
SourceID | dst | |||
) | [static] |
Checks if the source and destination of a subsidy are inside the distance limit.
src_type | Type of src. | |
src | Index of source. | |
dst_type | Type of dst. | |
dst | Index of destination. |
Definition at line 198 of file subsidy.cpp.
References DistanceManhattan(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), and SUBSIDY_MAX_DISTANCE.
Referenced by FindSubsidyCargoDestination().
static bool CheckSubsidyDuplicate | ( | CargoID | cargo, | |
SourceType | src_type, | |||
SourceID | src, | |||
SourceType | dst_type, | |||
SourceID | dst | |||
) | [static] |
Check whether a specific subsidy already exists.
cargo | Cargo type. | |
src_type | Type of source of the cargo, affects interpretation of src. | |
src | Id of the source. | |
dst_type | Type of the destination of the cargo, affects interpretation of dst. | |
dst | Id of the destination. |
true
if the subsidy already exists, false
if not. Definition at line 177 of file subsidy.cpp.
References Subsidy::cargo_type, Subsidy::dst, Subsidy::dst_type, Subsidy::src, and Subsidy::src_type.
Referenced by FindSubsidyCargoDestination(), and FindSubsidyPassengerRoute().
CommandCost CmdCreateSubsidy | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Create a new subsidy.
tile | unused. | |
flags | type of operation | |
p1 | various bitstuffed elements
| |
p2 | various bitstuffed elements
| |
text | unused. |
Definition at line 249 of file subsidy.cpp.
References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), CMD_ERROR, CreateSubsidy(), DC_EXEC, GB(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), NUM_CARGO, OWNER_DEITY, ST_INDUSTRY, and ST_TOWN.
void CreateSubsidy | ( | CargoID | cid, | |
SourceType | src_type, | |||
SourceID | src, | |||
SourceType | dst_type, | |||
SourceID | dst | |||
) |
Creates a subsidy with the given parameters.
cid | Subsidised cargo. | |
src_type | Type of src. | |
src | Index of source. | |
dst_type | Type of dst. | |
dst | Index of destination. |
Definition at line 214 of file subsidy.cpp.
References AddNewsItem(), Subsidy::awarded, AI::BroadcastNewEvent(), Subsidy::cargo_type, Subsidy::dst, Subsidy::dst_type, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), Game::NewEvent(), NS_SUBSIDIES, POS_DST, POS_SRC, Subsidy::remaining, SetPartOfSubsidyFlag(), SetupSubsidyDecodeParam(), Subsidy::src, Subsidy::src_type, SUBSIDY_OFFER_MONTHS, and WC_SUBSIDIES_LIST.
Referenced by CmdCreateSubsidy(), FindSubsidyCargoDestination(), and FindSubsidyPassengerRoute().
void DeleteSubsidyWith | ( | SourceType | type, | |
SourceID | index | |||
) |
Delete the subsidies associated with a given cargo source type and id.
type | Cargo source type of the id. | |
index | Id to remove. |
Definition at line 150 of file subsidy.cpp.
References Subsidy::dst, Subsidy::dst_type, InvalidateWindowData(), RebuildSubsidisedSourceAndDestinationCache(), Subsidy::src, Subsidy::src_type, and WC_SUBSIDIES_LIST.
Referenced by Town::~Town().
bool FindSubsidyCargoDestination | ( | CargoID | cid, | |
SourceType | src_type, | |||
SourceID | src | |||
) |
Tries to find a suitable destination for the given source and cargo.
cid | Subsidized cargo. | |
src_type | Type of src. | |
src | Index of source. |
Definition at line 403 of file subsidy.cpp.
References _town_cargoes_accepted, Industry::accepts_cargo, Town::cargo_accepted_total, Chance16(), CheckSubsidyDistance(), CheckSubsidyDuplicate(), CreateSubsidy(), Industry::GetRandom(), Town::GetRandom(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, ST_INDUSTRY, and ST_TOWN.
Referenced by FindSubsidyIndustryCargoRoute(), and FindSubsidyTownCargoRoute().
bool FindSubsidyIndustryCargoRoute | ( | ) |
Tries to create a cargo subsidy with an industry as source.
Definition at line 362 of file subsidy.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), CT_INVALID, FindSubsidyCargoDestination(), Industry::GetRandom(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::last_month_pct_transported, Industry::last_month_production, Industry::produced_cargo, and SUBSIDY_MAX_PCT_TRANSPORTED.
bool FindSubsidyPassengerRoute | ( | ) |
Tries to create a passenger subsidy between two towns.
Definition at line 295 of file subsidy.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), CheckSubsidyDuplicate(), CreateSubsidy(), DistanceManhattan(), Town::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Town::population, ST_TOWN, SUBSIDY_MAX_DISTANCE, SUBSIDY_MAX_PCT_TRANSPORTED, SUBSIDY_PAX_MIN_POPULATION, and Town::xy.
Referenced by SubsidyMonthlyLoop().
bool FindSubsidyTownCargoRoute | ( | ) |
Tries to create a cargo subsidy with a town as source.
Definition at line 325 of file subsidy.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), Town::cargo_produced, ClrBit(), CountBits(), FindSubsidyCargoDestination(), CargoSpec::Get(), Town::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, and SUBSIDY_MAX_PCT_TRANSPORTED.
Referenced by SubsidyMonthlyLoop().
void RebuildSubsidisedSourceAndDestinationCache | ( | ) |
Perform a full rebuild of the subsidies cache.
Definition at line 130 of file subsidy.cpp.
References Subsidy::dst, Subsidy::dst_type, Industry::part_of_subsidy, Town::part_of_subsidy, POS_DST, POS_SRC, SetPartOfSubsidyFlag(), Subsidy::src, and Subsidy::src_type.
Referenced by ChangeOwnershipOfCompanyItems(), DeleteSubsidyWith(), InitializeWindowsAndCaches(), and SubsidyMonthlyLoop().
static void SetPartOfSubsidyFlag | ( | SourceType | type, | |
SourceID | index, | |||
PartOfSubsidy | flag | |||
) | [inline, static] |
Sets a flag indicating that given town/industry is part of subsidised route.
type | is it a town or an industry? | |
index | index of town/industry | |
flag | flag to set |
Definition at line 120 of file subsidy.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), ST_INDUSTRY, and ST_TOWN.
Referenced by CreateSubsidy(), and RebuildSubsidisedSourceAndDestinationCache().
Setup the string parameters for printing the subsidy at the screen, and compute the news reference for the subsidy.
s | Subsidy being printed. | |
mode | Unit of cargo used, true means general name, false means singular form. |
Definition at line 73 of file subsidy.cpp.
References Subsidy::cargo_type, Subsidy::dst, Subsidy::dst_type, CargoSpec::Get(), CargoSpec::name, CargoSpec::name_single, SetDParam(), Subsidy::src, Subsidy::src_type, ST_INDUSTRY, and ST_TOWN.
Referenced by Subsidy::AwardTo(), CreateSubsidy(), SubsidyListWindow::DrawWidget(), and SubsidyMonthlyLoop().
void SubsidyMonthlyLoop | ( | ) |
Perform the monthly update of open subsidies, and try to create a new one.
Definition at line 455 of file subsidy.cpp.
References _local_company, AddNewsItem(), Subsidy::awarded, AI::BroadcastNewEvent(), Subsidy::dst, FindSubsidyPassengerRoute(), FindSubsidyTownCargoRoute(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), Subsidy::IsAwarded(), Game::NewEvent(), NS_SUBSIDIES, RebuildSubsidisedSourceAndDestinationCache(), Subsidy::remaining, SetupSubsidyDecodeParam(), Subsidy::src, and WC_SUBSIDIES_LIST.
Referenced by OnNewMonth().