Go to the documentation of this file.
28 #include "table/strings.h"
41 assert(!this->IsAwarded());
43 this->awarded = company;
48 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
50 char *cn =
stredup(company_name);
93 default: NOT_REACHED();
106 default: NOT_REACHED();
127 default: NOT_REACHED();
154 if ((s->src_type == type && s->src == index) || (s->dst_type == type && s->dst == index)) {
178 if (s->cargo_type == cargo &&
179 s->src_type == src_type && s->src == src &&
180 s->dst_type == dst_type && s->dst == dst) {
337 AddProducedCargo(tile, town_cargo_produced);
342 town_cargo_produced[CT_PASSENGERS] = 0;
344 uint8 cargo_count = 0;
346 if (town_cargo_produced[i] > 0) cargo_count++;
350 if (cargo_count == 0)
return false;
356 if (town_cargo_produced[cid] > 0) {
357 if (cargo_number == 0)
break;
388 if (src_ind ==
nullptr)
return false;
400 if (num_cargos == 0)
return false;
404 if (cargo_num == 0)
break;
406 assert(cargo_num == 0);
448 AddAcceptedCargo(tile, town_cargo_accepted,
nullptr);
453 if (town_cargo_accepted[cid] < 8)
return false;
455 dst = dst_town->
index;
462 if (dst_ind ==
nullptr)
return false;
466 if (!
valid)
return false;
468 dst = dst_ind->
index;
472 default: NOT_REACHED();
476 if (src_type == dst_type && src == dst)
return false;
492 bool modified =
false;
495 if (--s->remaining == 0) {
496 if (!s->IsAwarded()) {
525 bool passenger_subsidy =
false;
526 bool town_subsidy =
false;
527 bool industry_subsidy =
false;
537 }
while (!passenger_subsidy && n--);
538 }
else if (random_chance == 2) {
544 }
while (!town_subsidy && n--);
545 }
else if (random_chance == 3) {
551 }
while (!industry_subsidy && n--);
554 modified |= passenger_subsidy || town_subsidy || industry_subsidy;
579 default:
return false;
584 std::vector<const Town *> towns_near;
585 if (!st->
rect.IsEmpty()) {
588 if (s->dst_type !=
ST_TOWN)
continue;
589 if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src)
continue;
590 if (s->IsAwarded() && s->awarded != company)
continue;
595 const Town *t = Town::GetByTile(tile);
602 bool subsidised =
false;
607 if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
608 switch (s->dst_type) {
611 if (s->dst == ind->
index) {
614 if (!s->IsAwarded()) s->AwardTo(company);
619 for (
const Town *tp : towns_near) {
620 if (s->dst == tp->index) {
621 assert(tp->cache.part_of_subsidy &
POS_DST);
623 if (!s->IsAwarded()) s->AwardTo(company);
@ MP_HOUSE
A house by a town.
uint32 TileIndex
The index/ID of a Tile.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new subsidy.
static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
Check whether a specific subsidy already exists.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
static Titem * Get(size_t index)
Returns Titem with given index.
PartOfSubsidy part_of_subsidy
NOSAVE: is this industry a source/destination of a subsidy?
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ NT_SUBSIDIES
News about subsidies (announcements, expirations, acceptance)
@ WC_SUBSIDIES_LIST
Subsidies list; Window numbers:
Iterator to iterate over all tiles belonging to a bitmaptilearea.
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
DistributionType distribution_mail
distribution type for mail
static const uint SUBSIDY_MAX_PCT_TRANSPORTED
Subsidy will be created only for towns/industries with less % transported.
Class for storing amounts of cargo.
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
DifficultySettings difficulty
settings related to the difficulty
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
static const uint SUBSIDY_CONTRACT_MONTHS
Duration of subsidy after awarding.
PartOfSubsidy part_of_subsidy
Is this town a source/destination of a subsidy?
TileIndex xy
town center tile
Specification of a cargo type.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Defines the internal data of a functional industry.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
DoCommandFlag
List of flags for a command.
static Town * GetRandom()
Return a random valid town.
bool FindSubsidyTownCargoRoute()
Tries to create a cargo subsidy with a town as source.
@ ST_TOWN
Source/destination is a town.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
static Industry * GetRandom()
Return a random valid industry.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
uint32 population
Current population of people.
static const uint SUBSIDY_CARGO_MIN_POPULATION
Min. population of destination town for cargo route.
CargoID cargo_type
Cargo type involved in this subsidy, CT_INVALID for invalid subsidy.
Struct about subsidies, offered and awarded.
byte subsidy_multiplier
amount of subsidy
static const uint SUBSIDY_TOWN_CARGO_RADIUS
Extent of a tile area around town center when scanning for town cargo acceptance and production (6 ~=...
Common return value for all commands.
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
bool FindSubsidyIndustryCargoRoute()
Tries to create a cargo subsidy with an industry as source.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
SourceID src
Index of source. Either TownID or IndustryID.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
static void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag)
Sets a flag indicating that given town/industry is part of subsidised route.
@ ST_INDUSTRY
Source/destination is an industry.
Represents the covered area of e.g.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
SubsidyPool _subsidy_pool("Subsidy")
Pool for the subsidies.
SourceID dst
Index of destination. Either TownID or IndustryID.
void InjectDParam(uint amount)
Shift the string parameters in the global string parameter array by amount positions,...
LinkGraphSettings linkgraph
settings for link graph calculations
@ NR_NONE
Empty reference.
@ NF_NORMAL
Normal news item. (Newspaper with text only)
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
NewsReferenceType
References to objects in news.
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
SourceType dst_type
Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
CompanyID _current_company
Company currently doing an action.
SourceType
Types of cargo source and destination.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
Setup the string parameters for printing the subsidy at the screen, and compute the news reference fo...
byte remaining
Remaining months when this subsidy is valid.
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan)
#define endof(x)
Get the end element of an fixed size array.
@ NUM_CARGO
Maximal number of cargo types in a game.
TownCache cache
Container for all cacheable data.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
StringID name
Name of this type of cargo.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
PartOfSubsidy
What part of a subsidy is something?
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
Tries to find a suitable destination for the given source and cargo.
StringID name_single
Name of a single entity of this type of cargo.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, void *free_data=nullptr)
Add a new newsitem to be shown.
#define lengthof(x)
Return the length of an fixed size array.
void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
Creates a subsidy with the given parameters.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
@ INVALID_COMPANY
An invalid company.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
DistributionType distribution_armoured
distribution type for armoured cargo class
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.
@ CT_INVALID
Invalid cargo type.
SourceType src_type
Source of subsidised path (ST_INDUSTRY or ST_TOWN)
@ NR_INDUSTRY
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
#define lastof(x)
Get the last element of an fixed size array.
CompanyID awarded
Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone.
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.
DistributionType distribution_pax
distribution type for passengers
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void SubsidyMonthlyLoop()
Perform the monthly update of open subsidies, and try to create a new one.
@ POS_DST
bit 1 set -> town/industry is destination of subsidised path
DistributionType distribution_default
distribution type for all other goods
@ POS_SRC
bit 0 set -> town/industry is source of subsidised path
static const uint SUBSIDY_PAX_MIN_POPULATION
Min. population of towns for subsidised pax route.
bool FindSubsidyPassengerRoute()
Tries to create a passenger subsidy between two towns.