OpenTTD

subsidy_base.h
Go to the documentation of this file.
1 /* $Id: subsidy_base.h 23704 2012-01-01 17:22:32Z alberth $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef SUBSIDY_BASE_H
13 #define SUBSIDY_BASE_H
14
15 #include "cargo_type.h"
16 #include "company_type.h"
17 #include "subsidy_type.h"
18 #include "core/pool_type.hpp"
19
20 typedef Pool<Subsidy, SubsidyID, 1, 256> SubsidyPool;
21 extern SubsidyPool _subsidy_pool;
22
24 struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> {
25 CargoID cargo_type;
26 byte remaining;
27 CompanyByte awarded;
28 SourceTypeByte src_type;
29 SourceTypeByte dst_type;
30 SourceID src;
31 SourceID dst;
32
36 inline Subsidy() { }
37
41 inline ~Subsidy() { }
42
47 inline bool IsAwarded() const
48 {
49 return this->awarded != INVALID_COMPANY;
50 }
51
52 void AwardTo(CompanyID company);
53 };
54
56 static const uint SUBSIDY_OFFER_MONTHS = 12;
57 static const uint SUBSIDY_CONTRACT_MONTHS = 12;
58 static const uint SUBSIDY_PAX_MIN_POPULATION = 400;
59 static const uint SUBSIDY_CARGO_MIN_POPULATION = 900;
60 static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42;
61 static const uint SUBSIDY_MAX_DISTANCE = 70;
62
63 #define FOR_ALL_SUBSIDIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Subsidy, subsidy_index, var, start)
64 #define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)
65
66 #endif /* SUBSIDY_BASE_H */
SUBSIDY_CONTRACT_MONTHS
static const uint SUBSIDY_CONTRACT_MONTHS
Duration of subsidy after awarding.
Definition: subsidy_base.h:57
subsidy_type.h
basic types related to subsidies
Subsidy::src
SourceID src
Index of source. Either TownID or IndustryID.
Definition: subsidy_base.h:30
SUBSIDY_OFFER_MONTHS
static const uint SUBSIDY_OFFER_MONTHS
Constants related to subsidies.
Definition: subsidy_base.h:56
Subsidy::IsAwarded
bool IsAwarded() const
Tests whether this subsidy has been awarded to someone.
Definition: subsidy_base.h:47
Subsidy::dst
SourceID dst
Index of destination. Either TownID or IndustryID.
Definition: subsidy_base.h:31
Subsidy::AwardTo
void AwardTo(CompanyID company)
Marks subsidy as awarded, creates news and AI event.
Definition: subsidy.cpp:40
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:60
Subsidy::src_type
SourceTypeByte src_type
Source of subsidised path (ST_INDUSTRY or ST_TOWN)
Definition: subsidy_base.h:28
cargo_type.h
Types related to cargoes...
pool_type.hpp
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
SUBSIDY_CARGO_MIN_POPULATION
static const uint SUBSIDY_CARGO_MIN_POPULATION
Min. population of destination town for cargo route.
Definition: subsidy_base.h:59
Subsidy::~Subsidy
~Subsidy()
(Empty) destructor has to be defined else operator delete might be called with NULL parameter ...
Definition: subsidy_base.h:41
SUBSIDY_MAX_DISTANCE
static const uint SUBSIDY_MAX_DISTANCE
Max. length of subsidised route (DistanceManhattan)
Definition: subsidy_base.h:61
Subsidy::awarded
CompanyByte awarded
Subsidy is awarded to this company; INVALID_COMPANY if it&#39;s not awarded to anyone.
Definition: subsidy_base.h:27
TinyEnumT< Owner >
Subsidy::cargo_type
CargoID cargo_type
Cargo type involved in this subsidy, CT_INVALID for invalid subsidy.
Definition: subsidy_base.h:25
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
SimpleTinyEnumT< SourceType, byte >
Pool
Base class for all pools.
Definition: pool_type.hpp:83
Subsidy
Struct about subsidies, offered and awarded.
Definition: subsidy_base.h:24
Subsidy::Subsidy
Subsidy()
We need an (empty) constructor so struct isn&#39;t zeroed (as C++ standard states)
Definition: subsidy_base.h:36
Subsidy::dst_type
SourceTypeByte dst_type
Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
Definition: subsidy_base.h:29
SourceID
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:146
company_type.h
Types related to companies.
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Subsidy::remaining
byte remaining
Remaining months when this subsidy is valid.
Definition: subsidy_base.h:26
_subsidy_pool
SubsidyPool _subsidy_pool
Pool for the subsidies.
SUBSIDY_PAX_MIN_POPULATION
static const uint SUBSIDY_PAX_MIN_POPULATION
Min. population of towns for subsidised pax route.
Definition: subsidy_base.h:58
INVALID_COMPANY
An invalid company.
Definition: company_type.h:32