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) {
340 ClrBit(town_cargo_produced, CT_PASSENGERS);
343 if (town_cargo_produced == 0)
return false;
348 FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) {
349 if (cargo_number == 0)
break;
379 if (src_ind == NULL)
return false;
431 dst = dst_town->
index;
440 if (dst_ind == NULL ||
447 dst = dst_ind->
index;
451 default: NOT_REACHED();
455 if (src_type == dst_type && src == dst)
return false;
471 bool modified =
false;
474 FOR_ALL_SUBSIDIES(s) {
505 bool passenger_subsidy =
false;
506 bool town_subsidy =
false;
507 bool industry_subsidy =
false;
517 }
while (!passenger_subsidy && n--);
518 }
else if (random_chance == 2) {
524 }
while (!town_subsidy && n--);
525 }
else if (random_chance == 3) {
531 }
while (!industry_subsidy && n--);
534 modified |= passenger_subsidy || town_subsidy || industry_subsidy;
557 if (!(
Town::Get(src)->cache.part_of_subsidy & POS_SRC))
return false;
559 default:
return false;
565 if (!st->
rect.IsEmpty()) {
567 FOR_ALL_SUBSIDIES(s) {
575 for (
int y = rect.top; y <= rect.bottom; y++) {
576 for (
int x = rect.left; x <= rect.right; x++) {
579 const Town *t = Town::GetByTile(tile);
587 bool subsidised =
false;
592 FOR_ALL_SUBSIDIES(s) {
597 if (s->
dst == (*ip)->index) {
598 assert((*ip)->part_of_subsidy &
POS_DST);
605 for (
const Town *
const *tp = towns_near.
Begin(); tp != towns_near.
End(); tp++) {
606 if (s->
dst == (*tp)->index) {
607 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.
uint16 last_month_production[2]
total units produced per cargo in the last full month
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.
SourceID dst
Index of destination. Either TownID or IndustryID.
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
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.
uint32 cargo_produced
Bitmap of all cargoes produced by houses in this town.
uint32 cargo_accepted_total
NOSAVE: Bitmap of all cargoes accepted by houses in this town.
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.
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.
TileIndex xy
town center tile
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give 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.
CargoID accepts_cargo[3]
3 input cargo slots
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan)
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Normal news item. (Newspaper with text only)
CompanyByte awarded
Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone.
uint32 _town_cargoes_accepted
Bitmap of all cargoes accepted by houses.
Subsidies list; Window numbers:
CargoID produced_cargo[2]
2 production cargo slots
DistributionTypeByte distribution_pax
distribution type for passengers
bool FindSubsidyIndustryCargoRoute()
Tries to create a cargo subsidy with an industry as source.
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.
byte last_month_pct_transported[2]
percentage transported per cargo in the last full month
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.
Maximal number of cargo types in a game.
#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.
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.
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.