27 #include "table/strings.h" 40 assert(!this->IsAwarded());
42 this->awarded = company;
47 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
49 char *cn =
stredup(company_name);
92 default: NOT_REACHED();
105 default: NOT_REACHED();
126 default: NOT_REACHED();
153 if ((s->src_type == type && s->src == index) || (s->dst_type == type && s->dst == index)) {
177 if (s->cargo_type == cargo &&
178 s->src_type == src_type && s->src == src &&
179 s->dst_type == dst_type && s->dst == dst) {
334 ClrBit(town_cargo_produced, CT_PASSENGERS);
337 if (town_cargo_produced == 0)
return false;
342 FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) {
343 if (cargo_number == 0)
break;
373 if (src_ind ==
nullptr)
return false;
385 if (num_cargos == 0)
return false;
389 if (cargo_num == 0)
break;
391 assert(cargo_num == 0);
431 dst = dst_town->
index;
438 if (dst_ind ==
nullptr)
return false;
442 if (!valid)
return false;
444 dst = dst_ind->
index;
448 default: NOT_REACHED();
452 if (src_type == dst_type && src == dst)
return false;
468 bool modified =
false;
471 if (--s->remaining == 0) {
472 if (!s->IsAwarded()) {
501 bool passenger_subsidy =
false;
502 bool town_subsidy =
false;
503 bool industry_subsidy =
false;
513 }
while (!passenger_subsidy && n--);
514 }
else if (random_chance == 2) {
520 }
while (!town_subsidy && n--);
521 }
else if (random_chance == 3) {
527 }
while (!industry_subsidy && n--);
530 modified |= passenger_subsidy || town_subsidy || industry_subsidy;
553 if (!(
Town::Get(src)->cache.part_of_subsidy & POS_SRC))
return false;
555 default:
return false;
560 std::vector<const Town *> towns_near;
561 if (!st->
rect.IsEmpty()) {
564 if (s->dst_type !=
ST_TOWN)
continue;
565 if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src)
continue;
566 if (s->IsAwarded() && s->awarded != company)
continue;
571 const Town *t = Town::GetByTile(tile);
578 bool subsidised =
false;
583 if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
584 switch (s->dst_type) {
587 if (s->dst == ind->
index) {
590 if (!s->IsAwarded()) s->AwardTo(company);
595 for (
const Town *tp : towns_near) {
596 if (s->dst == tp->index) {
597 assert(tp->cache.part_of_subsidy &
POS_DST);
599 if (!s->IsAwarded()) s->AwardTo(company);
Functions related to OTTD's strings.
SourceType
Types of cargo source and destination.
Owner
Enum for all companies/owners.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
Check whether a specific subsidy already exists.
Source/destination is a town.
News about subsidies (announcements, expirations, acceptance)
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
static const uint SUBSIDY_CONTRACT_MONTHS
Duration of subsidy after awarding.
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
Setup the string parameters for printing the subsidy at the screen, and compute the news reference fo...
PartOfSubsidy part_of_subsidy
Is this town a source/destination of a subsidy?
CompanyID awarded
Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone.
SourceID src
Index of source. Either TownID or IndustryID.
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
static Titem * Get(size_t index)
Returns Titem with given index.
SourceType dst_type
Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
void SubsidyMonthlyLoop()
Perform the monthly update of open subsidies, and try to create a new one.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Maximal number of cargo types in a game.
SourceID dst
Index of destination. Either TownID or IndustryID.
CargoTypes cargo_produced
Bitmap of all cargoes produced by houses in this town.
Specification of a cargo type.
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
Tries to find a suitable destination for the given source and cargo.
CargoTypes _town_cargoes_accepted
Bitmap of all cargoes accepted by houses.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Defines the internal data of a functional industry.
DifficultySettings difficulty
settings related to the difficulty
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Tindex index
Index of this pool item.
StringID name_single
Name of a single entity of this type of cargo.
Manual distribution. No link graph calculations are run.
static const uint SUBSIDY_MAX_PCT_TRANSPORTED
Subsidy will be created only for towns/industries with less % transported.
byte subsidy_multiplier
amount of subsidy
DistributionType distribution_default
distribution type for all other goods
#define lastof(x)
Get the last element of an fixed size array.
Common return value for all commands.
static Industry * GetRandom()
Return a random valid industry.
uint32 population
Current population of people.
bool FindSubsidyTownCargoRoute()
Tries to create a cargo subsidy with a town as source.
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
StringID name
Name of this type of cargo.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
bit 1 set -> town/industry is destination of subsidised path
Pseudo random number generator.
static const uint SUBSIDY_CARGO_MIN_POPULATION
Min. population of destination town for cargo route.
void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
Creates a subsidy with the given parameters.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to low-level strings.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
uint8 valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
DistributionType distribution_mail
distribution type for mail
TileIndex xy
town center tile
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
PartOfSubsidy part_of_subsidy
NOSAVE: is this industry a source/destination of a subsidy?
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.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
DoCommandFlag
List of flags for a command.
Definition of base types and functions in a cross-platform compatible way.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
A number of safeguards to prevent using unsafe methods.
static Town * GetRandom()
Return a random valid town.
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan)
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
Normal news item. (Newspaper with text only)
Subsidies list; Window numbers:
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
#define lengthof(x)
Return the length of an fixed size array.
bool FindSubsidyIndustryCargoRoute()
Tries to create a cargo subsidy with an industry as source.
CargoTypes cargo_accepted_total
NOSAVE: Bitmap of all cargoes accepted by houses in this town.
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...
SubsidyPool _subsidy_pool("Subsidy")
Pool for the subsidies.
CargoID cargo_type
Cargo type involved in this subsidy, CT_INVALID for invalid subsidy.
DistributionType distribution_armoured
distribution type for armoured cargo class
Base class for all pools.
Struct about subsidies, offered and awarded.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
bit 0 set -> town/industry is source of subsidised path
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
execute the given command
Functions related to companies.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void InjectDParam(uint amount)
Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.
DistributionType distribution_pax
distribution type for passengers
Reference town. Scroll to town when clicking on the news.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
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...
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
SourceType src_type
Source of subsidised path (ST_INDUSTRY or ST_TOWN)
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
TownCache cache
Container for all cacheable data.
#define endof(x)
Get the end element of an fixed size array.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
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.
static uint CountBits(T value)
Counts the number of set bits in a variable.
Base functions for all Games.
Functions related to commands.
static void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag)
Sets a flag indicating that given town/industry is part of subsidised route.
CompanyID _current_company
Company currently doing an action.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
NewsReferenceType
References to objects in news.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
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.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
byte CargoID
Cargo slots to indicate a cargo type within a game.
PartOfSubsidy
What part of a subsidy is something?
byte remaining
Remaining months when this subsidy is valid.
Window functions not directly related to making/drawing windows.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
static const uint SUBSIDY_PAX_MIN_POPULATION
Min. population of towns for subsidised pax route.
Functions related to news.
Base classes/functions for stations.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
The object is owned by a superuser / goal script.
Functions related to subsidies.
LinkGraphSettings linkgraph
settings for link graph calculations
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-...
Source/destination is an industry.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.