|
OpenTTD Source
13.2.1
|
#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 "string_func.h"#include "tile_cmd.h"#include "subsidy_cmd.h"#include "table/strings.h"#include "safeguards.h"Go to the source code of this file.
Functions | |
| std::pair< NewsReferenceType, NewsReferenceType > | SetupSubsidyDecodeParam (const Subsidy *s, SubsidyDecodeParamType mode, uint parameter_offset) |
| Setup the string parameters for printing the subsidy at the screen, and compute the news reference for the subsidy. More... | |
| static void | SetPartOfSubsidyFlag (SourceType type, SourceID index, PartOfSubsidy flag) |
| Sets a flag indicating that given town/industry is part of subsidised route. More... | |
| 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. More... | |
| static bool | CheckSubsidyDuplicate (CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
| Check whether a specific subsidy already exists. More... | |
| 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. More... | |
| void | CreateSubsidy (CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
| Creates a subsidy with the given parameters. More... | |
| CommandCost | CmdCreateSubsidy (DoCommandFlag flags, CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst) |
| Create a new subsidy. More... | |
| bool | FindSubsidyPassengerRoute () |
| Tries to create a passenger subsidy between two towns. More... | |
| bool | FindSubsidyCargoDestination (CargoID cid, SourceType src_type, SourceID src) |
| Tries to find a suitable destination for the given source and cargo. More... | |
| bool | FindSubsidyTownCargoRoute () |
| Tries to create a cargo subsidy with a town as source. More... | |
| bool | FindSubsidyIndustryCargoRoute () |
| Tries to create a cargo subsidy with an industry as source. More... | |
| 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. More... | |
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 561 of file subsidy.cpp.
References Town::cache, Station::catchment_tiles, 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(), include(), Station::industries_near, INVALID_SOURCE, INVALID_TILE, IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::Iterate(), MP_HOUSE, TownCache::part_of_subsidy, POS_DST, POS_SRC, BaseStation::rect, ST_INDUSTRY, and ST_TOWN.
|
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 195 of file subsidy.cpp.
References DistanceManhattan(), 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_TOWN, and SUBSIDY_MAX_DISTANCE.
|
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 175 of file subsidy.cpp.
| CommandCost CmdCreateSubsidy | ( | DoCommandFlag | flags, |
| CargoID | cid, | ||
| SourceType | src_type, | ||
| SourceID | src, | ||
| SourceType | dst_type, | ||
| SourceID | dst | ||
| ) |
Create a new subsidy.
| flags | type of operation |
| cid | CargoID of subsidy. |
| src_type | SourceType of source. |
| src | SourceID of source. |
| dst_type | SourceType of destination. |
| dst | SourceID of destination. |
Definition at line 242 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, CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_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 211 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, INVALID_COMPANY, InvalidateWindowData(), Game::NewEvent(), NewsOffered, NF_NORMAL, NT_SUBSIDIES, POS_DST, POS_SRC, Subsidy::remaining, SetPartOfSubsidyFlag(), SetupSubsidyDecodeParam(), Subsidy::src, Subsidy::src_type, SUBSIDY_OFFER_MONTHS, and WC_SUBSIDIES_LIST.
Referenced by CmdCreateSubsidy().
| 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 149 of file subsidy.cpp.
References InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::Iterate(), RebuildSubsidisedSourceAndDestinationCache(), 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 422 of file subsidy.cpp.
References Chance16(), OrthogonalTileArea::Expand(), Town::GetRandom(), IsTileType(), MP_HOUSE, ST_INDUSTRY, ST_TOWN, SUBSIDY_TOWN_CARGO_RADIUS, and Town::xy.
Referenced by FindSubsidyIndustryCargoRoute().
| bool FindSubsidyIndustryCargoRoute | ( | ) |
Tries to create a cargo subsidy with an industry as source.
Definition at line 370 of file subsidy.cpp.
References _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), CT_INVALID, DT_MANUAL, FindSubsidyCargoDestination(), Industry::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::last_month_pct_transported, Industry::last_month_production, lengthof, GameSettings::linkgraph, Industry::produced_cargo, RandomRange(), ST_INDUSTRY, and SUBSIDY_MAX_PCT_TRANSPORTED.
Referenced by SubsidyMonthlyLoop().
| bool FindSubsidyPassengerRoute | ( | ) |
Tries to create a passenger subsidy between two towns.
Definition at line 282 of file subsidy.cpp.
References Town::cache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), Town::GetRandom(), TownCache::population, and SUBSIDY_PAX_MIN_POPULATION.
Referenced by SubsidyMonthlyLoop().
| bool FindSubsidyTownCargoRoute | ( | ) |
Tries to create a cargo subsidy with a town as source.
Definition at line 312 of file subsidy.cpp.
References Town::cache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), OrthogonalTileArea::Expand(), Town::GetRandom(), IsTileType(), MP_HOUSE, TownCache::population, ST_TOWN, SUBSIDY_CARGO_MIN_POPULATION, SUBSIDY_TOWN_CARGO_RADIUS, and Town::xy.
Referenced by SubsidyMonthlyLoop().
|
inlinestatic |
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 122 of file subsidy.cpp.
References 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(), ST_INDUSTRY, and ST_TOWN.
Referenced by CreateSubsidy(), and RebuildSubsidisedSourceAndDestinationCache().
| std::pair<NewsReferenceType, NewsReferenceType> SetupSubsidyDecodeParam | ( | const Subsidy * | s, |
| SubsidyDecodeParamType | mode, | ||
| uint | parameter_offset | ||
| ) |
Setup the string parameters for printing the subsidy at the screen, and compute the news reference for the subsidy.
| s | Subsidy being printed. |
| mode | Type of subsidy news message to decide on parameter format. |
| parameter_offset | The location/index in the String DParams to start decoding the subsidy's parameters. Defaults to 0. |
Definition at line 73 of file subsidy.cpp.
References Subsidy::cargo_type, CargoSpec::Get(), CargoSpec::name, NR_INDUSTRY, NR_NONE, NR_TOWN, SetDParam(), Subsidy::src_type, ST_INDUSTRY, and ST_TOWN.
Referenced by CreateSubsidy(), SubsidyListWindow::DrawWidget(), and SubsidyMonthlyLoop().