OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
28 #include "table/strings.h"
41 assert(!this->IsAwarded());
43 this->awarded = company;
56 reftype.first, this->src, reftype.second, this->dst,
88 SetDParam(parameter_offset + 1, STR_INDUSTRY_NAME);
92 SetDParam(parameter_offset + 1, STR_TOWN_NAME);
94 default: NOT_REACHED();
101 SetDParam(parameter_offset + 4, STR_INDUSTRY_NAME);
105 SetDParam(parameter_offset + 4, STR_TOWN_NAME);
107 default: NOT_REACHED();
116 return std::pair<NewsReferenceType, NewsReferenceType>(reftype1, reftype2);
130 default: NOT_REACHED();
157 if ((s->src_type == type && s->src == index) || (s->dst_type == type && s->dst == index)) {
181 if (s->cargo_type == cargo &&
182 s->src_type == src_type && s->src == src &&
183 s->dst_type == dst_type && s->dst == dst) {
340 AddProducedCargo(tile, town_cargo_produced);
345 town_cargo_produced[CT_PASSENGERS] = 0;
347 uint8 cargo_count = 0;
349 if (town_cargo_produced[i] > 0) cargo_count++;
353 if (cargo_count == 0)
return false;
359 if (town_cargo_produced[cid] > 0) {
360 if (cargo_number == 0)
break;
391 if (src_ind ==
nullptr)
return false;
403 if (num_cargos == 0)
return false;
407 if (cargo_num == 0)
break;
409 assert(cargo_num == 0);
451 AddAcceptedCargo(tile, town_cargo_accepted,
nullptr);
456 if (town_cargo_accepted[cid] < 8)
return false;
458 dst = dst_town->
index;
465 if (dst_ind ==
nullptr)
return false;
469 if (!
valid)
return false;
471 dst = dst_ind->
index;
475 default: NOT_REACHED();
479 if (src_type == dst_type && src == dst)
return false;
495 bool modified =
false;
498 if (--s->remaining == 0) {
499 if (!s->IsAwarded()) {
531 bool passenger_subsidy =
false;
532 bool town_subsidy =
false;
533 bool industry_subsidy =
false;
543 }
while (!passenger_subsidy && n--);
544 }
else if (random_chance == 2) {
550 }
while (!town_subsidy && n--);
551 }
else if (random_chance == 3) {
557 }
while (!industry_subsidy && n--);
560 modified |= passenger_subsidy || town_subsidy || industry_subsidy;
585 default:
return false;
590 std::vector<const Town *> towns_near;
591 if (!st->
rect.IsEmpty()) {
594 if (s->dst_type !=
ST_TOWN)
continue;
595 if (s->cargo_type != cargo_type || s->src_type != src_type || s->src != src)
continue;
596 if (s->IsAwarded() && s->awarded != company)
continue;
601 const Town *t = Town::GetByTile(tile);
608 bool subsidised =
false;
613 if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
614 switch (s->dst_type) {
617 if (s->dst == ind->
index) {
620 if (!s->IsAwarded()) s->AwardTo(company);
625 for (
const Town *tp : towns_near) {
626 if (s->dst == tp->index) {
627 assert(tp->cache.part_of_subsidy &
POS_DST);
629 if (!s->IsAwarded()) s->AwardTo(company);
uint16 remaining
Remaining months when this subsidy is valid.
@ 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-...
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.
uint16 subsidy_duration
duration of subsidies
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ NT_SUBSIDIES
News about subsidies (announcements, expirations, acceptance)
@ NewsAwarded
News item for an awarded subsidy.
@ 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.
@ NewsOffered
News item for an offered subsidy.
DifficultySettings difficulty
settings related to the difficulty
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, const NewsAllocatedData *data=nullptr)
Add a new newsitem to be shown.
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).
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
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 fo...
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.
CommandCost CmdCreateSubsidy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Create a new subsidy.
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
payment multiplier for subsidized deliveries
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)
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.
Container for a single string to be passed as NewsAllocatedData.
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.
@ Gui
Subsidies listed in the Subsidy GUI.
static const int MONTHS_IN_YEAR
months per year
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.
@ NewsWithdrawn
News item for a subsidy offer withdrawn, or expired subsidy.
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.
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.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
#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.
SubsidyDecodeParamType
Types of subsidy news messages, which determine how the date is printed and whether to use singular o...
std::string string
The string to retain.
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...
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.