OpenTTD Source 20260208-master-g43af8e94d0
subsidy_base.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef SUBSIDY_BASE_H
11#define SUBSIDY_BASE_H
12
13#include "cargo_type.h"
14#include "company_type.h"
15#include "source_type.h"
16#include "subsidy_type.h"
17#include "core/pool_type.hpp"
18
19using SubsidyPool = Pool<Subsidy, SubsidyID, 1>;
20extern SubsidyPool _subsidy_pool;
21
23struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
24 CargoType cargo_type = INVALID_CARGO;
25 uint16_t remaining = 0;
26 CompanyID awarded = CompanyID::Invalid();
29
30 Subsidy(SubsidyID index, CargoType cargo_type = INVALID_CARGO, Source src = {}, Source dst = {}, uint16_t remaining = 0) :
32
37
42 inline bool IsAwarded() const
43 {
44 return this->awarded != CompanyID::Invalid();
45 }
46
47 void AwardTo(CompanyID company);
48};
49
51static const uint SUBSIDY_OFFER_MONTHS = 12;
52static const uint SUBSIDY_PAX_MIN_POPULATION = 400;
53static const uint SUBSIDY_CARGO_MIN_POPULATION = 900;
54static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42;
55static const uint SUBSIDY_MAX_DISTANCE = 70;
56static const uint SUBSIDY_TOWN_CARGO_RADIUS = 6;
57
58#endif /* SUBSIDY_BASE_H */
Types related to cargoes...
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
Types related to companies.
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Type for the source of cargo.
Base class for all pools.
A location from where cargo can come from (or go to).
Definition source_type.h:32
Struct about subsidies, offered and awarded.
bool IsAwarded() const
Tests whether this subsidy has been awarded to someone.
CargoType cargo_type
Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy.
CompanyID awarded
Subsidy is awarded to this company; CompanyID::Invalid() if it's not awarded to anyone.
void AwardTo(CompanyID company)
Marks subsidy as awarded, creates news and AI event.
Definition subsidy.cpp:69
~Subsidy()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Source dst
Destination of subsidised path.
Source src
Source of subsidised path.
uint16_t remaining
Remaining months when this subsidy is valid.
SubsidyPool _subsidy_pool("Subsidy")
Pool for the subsidies.
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan).
static const uint SUBSIDY_CARGO_MIN_POPULATION
Min. population of destination town for cargo route.
static const uint SUBSIDY_TOWN_CARGO_RADIUS
Extent of a tile area around town center when scanning for town cargo acceptance and production (6 ~=...
static const uint SUBSIDY_PAX_MIN_POPULATION
Min. population of towns for subsidised pax route.
static const uint SUBSIDY_MAX_PCT_TRANSPORTED
Subsidy will be created only for towns/industries with less % transported.
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
Basic types related to subsidies.
@ Source
town/industry is source of subsidised path
PoolID< uint16_t, struct SubsidyIDTag, 256, 0xFFFF > SubsidyID
ID of a subsidy.