OpenTTD Source: src/subsidy_base.h Source File

OpenTTD Source 15.0-RC2

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
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
23 struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
24 CargoType cargo_type = INVALID_CARGO;
25 uint16_t remaining = 0;
26 CompanyID awarded = CompanyID::Invalid();
27 Source src{};
28 Source dst{};
29
33 Subsidy() { }
34 Subsidy(CargoType cargo_type, Source src, Source dst, uint16_t remaining) : cargo_type(cargo_type), remaining(remaining), src(src), dst(dst) {}
35
39 ~Subsidy() { }
40
45 inline bool IsAwarded() const
46 {
47 return this->awarded != CompanyID::Invalid();
48 }
49
50 void AwardTo(CompanyID company);
51};
52
54 static const uint SUBSIDY_OFFER_MONTHS = 12;
55 static const uint SUBSIDY_PAX_MIN_POPULATION = 400;
56 static const uint SUBSIDY_CARGO_MIN_POPULATION = 900;
57 static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42;
58 static const uint SUBSIDY_MAX_DISTANCE = 70;
59 static const uint SUBSIDY_TOWN_CARGO_RADIUS = 6;
60
61#endif /* SUBSIDY_BASE_H */
cargo_type.h
Types related to cargoes...
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
company_type.h
Types related to companies.
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
source_type.h
Type for the source of cargo.
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem
Base class for all PoolItems.
Definition pool_type.hpp:285
Pool
Base class for all pools.
Definition pool_type.hpp:133
Source
A location from where cargo can come from (or go to).
Definition source_type.h:32
Subsidy
Struct about subsidies, offered and awarded.
Definition subsidy_base.h:23
Subsidy::IsAwarded
bool IsAwarded() const
Tests whether this subsidy has been awarded to someone.
Definition subsidy_base.h:45
Subsidy::cargo_type
CargoType cargo_type
Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy.
Definition subsidy_base.h:24
Subsidy::awarded
CompanyID awarded
Subsidy is awarded to this company; CompanyID::Invalid() if it's not awarded to anyone.
Definition subsidy_base.h:26
Subsidy::AwardTo
void AwardTo(CompanyID company)
Marks subsidy as awarded, creates news and AI event.
Definition subsidy.cpp:69
Subsidy::~Subsidy
~Subsidy()
(Empty) destructor has to be defined else operator delete might be called with nullptr parameter
Definition subsidy_base.h:39
Subsidy::Subsidy
Subsidy()
We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
Definition subsidy_base.h:33
Subsidy::dst
Source dst
Destination of subsidised path.
Definition subsidy_base.h:28
Subsidy::src
Source src
Source of subsidised path.
Definition subsidy_base.h:27
Subsidy::remaining
uint16_t remaining
Remaining months when this subsidy is valid.
Definition subsidy_base.h:25
_subsidy_pool
SubsidyPool _subsidy_pool("Subsidy")
Pool for the subsidies.
SUBSIDY_MAX_DISTANCE
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan)
Definition subsidy_base.h:58
SUBSIDY_CARGO_MIN_POPULATION
static const uint SUBSIDY_CARGO_MIN_POPULATION
Min. population of destination town for cargo route.
Definition subsidy_base.h:56
SUBSIDY_TOWN_CARGO_RADIUS
static const uint SUBSIDY_TOWN_CARGO_RADIUS
Extent of a tile area around town center when scanning for town cargo acceptance and production (6 ~=...
Definition subsidy_base.h:59
SUBSIDY_PAX_MIN_POPULATION
static const uint SUBSIDY_PAX_MIN_POPULATION
Min. population of towns for subsidised pax route.
Definition subsidy_base.h:55
SUBSIDY_MAX_PCT_TRANSPORTED
static const uint SUBSIDY_MAX_PCT_TRANSPORTED
Subsidy will be created only for towns/industries with less % transported.
Definition subsidy_base.h:57
SUBSIDY_OFFER_MONTHS
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
Definition subsidy_base.h:54
subsidy_type.h
basic types related to subsidies