Functions | Variables

subsidy.cpp File Reference

Handling of subsidies. More...

#include "stdafx.h"
#include "company_func.h"
#include "industry.h"
#include "town.h"
#include "news_func.h"
#include "ai/ai.hpp"
#include "station_base.h"
#include "cargotype.h"
#include "strings_func.h"
#include "window_func.h"
#include "subsidy_base.h"
#include "subsidy_func.h"
#include "core/pool_func.hpp"
#include "core/random_func.hpp"
#include "game/game.hpp"
#include "command_func.h"
#include "table/strings.h"

Go to the source code of this file.

Functions

Pair SetupSubsidyDecodeParam (const Subsidy *s, bool mode)
static void SetPartOfSubsidyFlag (SourceType type, SourceID index, PartOfSubsidy flag)
 Sets a flag indicating that given town/industry is part of subsidised route.
void RebuildSubsidisedSourceAndDestinationCache ()
void DeleteSubsidyWith (SourceType type, SourceID index)
static bool CheckSubsidyDuplicate (CargoID cargo, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
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.
void CreateSubsidy (CargoID cid, SourceType src_type, SourceID src, SourceType dst_type, SourceID dst)
 Creates a subsidy with the given parameters.
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.
bool FindSubsidyCargoDestination (CargoID cid, SourceType src_type, SourceID src)
 Tries to find a suitable destination for the given source and cargo.
bool FindSubsidyTownCargoRoute ()
 Tries to create a cargo subsidy with a town as source.
bool FindSubsidyIndustryCargoRoute ()
 Tries to create a cargo subsidy with an industry as source.
void SubsidyMonthlyLoop ()
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.

Variables

SubsidyPool _subsidy_pool ("Subsidy")

Detailed Description

Handling of subsidies.

Definition in file subsidy.cpp.


Function Documentation

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.

Parameters:
cargo_type type of cargo
company company delivering the cargo
src_type type of src
src index of source
st station where the cargo is delivered to
Returns:
is the delivery subsidised?

Definition at line 498 of file subsidy.cpp.

References Subsidy::awarded, Subsidy::AwardTo(), SmallVector< T, S >::Begin(), Subsidy::cargo_type, Subsidy::dst, Subsidy::dst_type, SmallVector< T, S >::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), SmallVector< T, S >::Include(), INVALID_SOURCE, Subsidy::IsAwarded(), IsTileType(), MP_HOUSE, Town::part_of_subsidy, POS_DST, POS_SRC, Subsidy::src, Subsidy::src_type, ST_INDUSTRY, ST_TOWN, and TileXY().

Referenced by DeliverGoods().

static bool CheckSubsidyDistance ( SourceType  src_type,
SourceID  src,
SourceType  dst_type,
SourceID  dst 
) [static]

Checks if the source and destination of a subsidy are inside the distance limit.

Parameters:
src_type Type of src.
src Index of source.
dst_type Type of dst.
dst Index of destination.
Returns:
True if they are inside the distance limit.

Definition at line 177 of file subsidy.cpp.

References DistanceManhattan(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), and SUBSIDY_MAX_DISTANCE.

Referenced by FindSubsidyCargoDestination().

CommandCost CmdCreateSubsidy ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Create a new subsidy.

Parameters:
tile unused.
flags type of operation
p1 various bitstuffed elements

  • p1 = (bit 0 - 7) - SourceType of source.
  • p1 = (bit 8 - 23) - SourceID of source.
  • p1 = (bit 24 - 31) - CargoID of subsidy.
p2 various bitstuffed elements

  • p2 = (bit 0 - 7) - SourceType of destination.
  • p2 = (bit 8 - 23) - SourceID of destionation.
text unused.
Returns:
the cost of this operation or an error

Definition at line 227 of file subsidy.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::CanAllocateItem(), CMD_ERROR, CreateSubsidy(), DC_EXEC, GB(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), NUM_CARGO, OWNER_DEITY, ST_INDUSTRY, and ST_TOWN.

void CreateSubsidy ( CargoID  cid,
SourceType  src_type,
SourceID  src,
SourceType  dst_type,
SourceID  dst 
)
bool FindSubsidyCargoDestination ( CargoID  cid,
SourceType  src_type,
SourceID  src 
)

Tries to find a suitable destination for the given source and cargo.

Parameters:
cid Subsidized cargo.
src_type Type of src.
src Index of source.
Returns:
True iff the subsidy was created.

Definition at line 377 of file subsidy.cpp.

References _town_cargoes_accepted, Industry::accepts_cargo, Town::cargo_accepted_total, Chance16(), CheckSubsidyDistance(), CreateSubsidy(), Industry::GetRandom(), Town::GetRandom(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, ST_INDUSTRY, and ST_TOWN.

Referenced by FindSubsidyIndustryCargoRoute(), and FindSubsidyTownCargoRoute().

bool FindSubsidyIndustryCargoRoute (  ) 
bool FindSubsidyPassengerRoute (  ) 
bool FindSubsidyTownCargoRoute (  ) 
static void SetPartOfSubsidyFlag ( SourceType  type,
SourceID  index,
PartOfSubsidy  flag 
) [inline, static]

Sets a flag indicating that given town/industry is part of subsidised route.

Parameters:
type is it a town or an industry?
index index of town/industry
flag flag to set

Definition at line 115 of file subsidy.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), ST_INDUSTRY, and ST_TOWN.

Referenced by CreateSubsidy().