29 #include "table/strings.h" 42 assert(!this->IsAwarded());
44 this->awarded = company;
49 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
51 char *cn =
stredup(company_name);
94 default: NOT_REACHED();
107 default: NOT_REACHED();
128 default: NOT_REACHED();
142 FOR_ALL_SUBSIDIES(s) {
158 FOR_ALL_SUBSIDIES(s) {
183 FOR_ALL_SUBSIDIES(s) {
341 ClrBit(town_cargo_produced, CT_PASSENGERS);
344 if (town_cargo_produced == 0)
return false;
349 FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) {
350 if (cargo_number == 0)
break;
380 if (src_ind == NULL)
return false;
392 if (num_cargos == 0)
return false;
396 if (cargo_num == 0)
break;
398 assert(cargo_num == 0);
438 dst = dst_town->
index;
445 if (dst_ind == NULL)
return false;
449 if (!valid)
return false;
451 dst = dst_ind->
index;
455 default: NOT_REACHED();
459 if (src_type == dst_type && src == dst)
return false;
475 bool modified =
false;
478 FOR_ALL_SUBSIDIES(s) {
509 bool passenger_subsidy =
false;
510 bool town_subsidy =
false;
511 bool industry_subsidy =
false;
521 }
while (!passenger_subsidy && n--);
522 }
else if (random_chance == 2) {
528 }
while (!town_subsidy && n--);
529 }
else if (random_chance == 3) {
535 }
while (!industry_subsidy && n--);
538 modified |= passenger_subsidy || town_subsidy || industry_subsidy;
561 if (!(
Town::Get(src)->cache.part_of_subsidy & POS_SRC))
return false;
563 default:
return false;
569 if (!st->
rect.IsEmpty()) {
571 FOR_ALL_SUBSIDIES(s) {
579 for (
int y = rect.top; y <= rect.bottom; y++) {
580 for (
int x = rect.left; x <= rect.right; x++) {
583 const Town *t = Town::GetByTile(tile);
591 bool subsidised =
false;
596 FOR_ALL_SUBSIDIES(s) {
601 if (s->
dst == (*ip)->index) {
602 assert((*ip)->part_of_subsidy &
POS_DST);
609 for (
const Town *
const *tp = towns_near.
Begin(); tp != towns_near.
End(); tp++) {
610 if (s->
dst == (*tp)->index) {
611 assert((*tp)->cache.part_of_subsidy &
POS_DST);
Functions related to OTTD's strings.
static bool CheckSubsidyDuplicate(CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
Check whether a specific subsidy already exists.
News about subsidies (announcements, expirations, acceptance)
Source/destination is a town.
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.
IndustryVector industries_near
Cached list of industries near the station that can accept cargo,.
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
Setup the string parameters for printing the subsidy at the screen, and compute the news reference fo...
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
SourceID src
Index of source. Either TownID or IndustryID.
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
bool IsAwarded() const
Tests whether this subsidy has been awarded to someone.
static Titem * Get(size_t index)
Returns Titem with given index.
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.
void AwardTo(CompanyID company)
Marks subsidy as awarded, creates news and AI event.
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.
DistributionTypeByte distribution_mail
distribution type for mail
CargoTypes _town_cargoes_accepted
Bitmap of all cargoes accepted by houses.
Manual distribution. No link graph calculations are run.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Defines the internal data of a functional industry.
const T * Begin() const
Get the pointer to the first item (const)
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.
static const uint SUBSIDY_MAX_PCT_TRANSPORTED
Subsidy will be created only for towns/industries with less % transported.
SourceTypeByte src_type
Source of subsidised path (ST_INDUSTRY or ST_TOWN)
byte subsidy_multiplier
amount of subsidy
#define lastof(x)
Get the last element of an fixed size array.
Simple vector template class.
Common return value for all commands.
static Industry * GetRandom()
Return a random valid industry.
uint32 population
Current population of people.
const T * End() const
Get the pointer behind the last valid item (const)
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.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Pseudo random number generator.
The object is owned by a superuser / goal script.
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).
TileIndex xy
town center tile
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new subsidy.
PartOfSubsidyByte part_of_subsidy
NOSAVE: is this industry a source/destination of a subsidy?
bool FindSubsidyPassengerRoute()
Tries to create a passenger subsidy between two towns.
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)
CompanyByte awarded
Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone.
Subsidies list; Window numbers:
DistributionTypeByte distribution_pax
distribution type for passengers
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.
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.
SourceType
Types of cargo source and destination.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
bit 1 set -> town/industry is destination of subsidised path
execute the given command
Functions related to companies.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
void InjectDParam(uint amount)
Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.
Reference town. Scroll to town when clicking on the news.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
SourceTypeByte dst_type
Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
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=NULL)
Add a new newsitem to be shown.
Source/destination is an industry.
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.
bool Include(const T &item)
Tests whether a item is present in the vector, and appends it to the end if not.
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.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
NewsReferenceType
References to objects in news.
PartOfSubsidyByte part_of_subsidy
Is this town a source/destination of a subsidy?
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Base functions for all AIs.
Reference industry. Scroll to industry when clicking on the news. Delete news when industry is delete...
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Owner
Enum for all companies/owners.
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.
bit 0 set -> town/industry is source of subsidised path
DistributionTypeByte distribution_default
distribution type for all other goods
DistributionTypeByte distribution_armoured
distribution type for armoured cargo class
Functions related to subsidies.
LinkGraphSettings linkgraph
settings for link graph calculations
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
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-...
PartOfSubsidy
What part of a subsidy is something?
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.