|
@@ -14,24 +14,25 @@
|
|
|
#include "news_func.h"
|
|
|
#include "ai/ai.hpp"
|
|
|
#include "station_base.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 "string_func.h"
|
|
|
#include "tile_cmd.h"
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
SubsidyPool _subsidy_pool("Subsidy"); ///< Pool for the subsidies.
|
|
|
INSTANTIATE_POOL_METHODS(Subsidy)
|
|
|
|
|
|
/**
|
|
|
* Marks subsidy as awarded, creates news and AI event
|
|
|
* @param company awarded company
|
|
|
*/
|
|
@@ -319,25 +320,32 @@ bool FindSubsidyCargoDestination(CargoID
|
|
|
* @return True iff the subsidy was created.
|
|
|
*/
|
|
|
bool FindSubsidyTownCargoRoute()
|
|
|
{
|
|
|
if (!Subsidy::CanAllocateItem()) return false;
|
|
|
|
|
|
SourceType src_type = ST_TOWN;
|
|
|
|
|
|
/* Select a random town. */
|
|
|
const Town *src_town = Town::GetRandom();
|
|
|
if (src_town->cache.population < SUBSIDY_CARGO_MIN_POPULATION) return false;
|
|
|
|
|
|
CargoArray town_cargo_produced = GetProductionAroundTiles(src_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS);
|
|
|
/* Calculate the produced cargo of houses around town center. */
|
|
|
CargoArray town_cargo_produced;
|
|
|
TileArea ta = TileArea(src_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
if (IsTileType(tile, MP_HOUSE)) {
|
|
|
AddProducedCargo(tile, town_cargo_produced);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Passenger subsidies are not handled here. */
|
|
|
town_cargo_produced[CT_PASSENGERS] = 0;
|
|
|
|
|
|
uint8 cargo_count = 0;
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
|
|
if (town_cargo_produced[i] > 0) cargo_count++;
|
|
|
}
|
|
|
|
|
|
/* No cargo produced at all? */
|
|
|
if (cargo_count == 0) return false;
|
|
|
|
|
@@ -422,25 +430,33 @@ bool FindSubsidyIndustryCargoRoute()
|
|
|
* @return True iff the subsidy was created.
|
|
|
*/
|
|
|
bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
|
|
|
{
|
|
|
/* Choose a random destination. */
|
|
|
SourceType dst_type = Chance16(1, 2) ? ST_TOWN : ST_INDUSTRY;
|
|
|
|
|
|
SourceID dst;
|
|
|
switch (dst_type) {
|
|
|
case ST_TOWN: {
|
|
|
/* Select a random town. */
|
|
|
const Town *dst_town = Town::GetRandom();
|
|
|
CargoArray town_cargo_accepted = GetAcceptanceAroundTiles(dst_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS);
|
|
|
|
|
|
/* Calculate cargo acceptance of houses around town center. */
|
|
|
CargoArray town_cargo_accepted;
|
|
|
TileArea ta = TileArea(dst_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
if (IsTileType(tile, MP_HOUSE)) {
|
|
|
AddAcceptedCargo(tile, town_cargo_accepted, nullptr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Check if the town can accept this cargo. */
|
|
|
if (town_cargo_accepted[cid] < 8) return false;
|
|
|
|
|
|
dst = dst_town->index;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case ST_INDUSTRY: {
|
|
|
/* Select a random industry. */
|
|
|
const Industry *dst_ind = Industry::GetRandom();
|
|
|
if (dst_ind == nullptr) return false;
|