1 /* $Id: subsidy_base.h 23704 2012-01-01 17:22:32Z alberth $ */
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/>.
10 /** @file subsidy_base.h %Subsidy base class. */
12 #ifndef SUBSIDY_BASE_H
13 #define SUBSIDY_BASE_H
15 #include "cargo_type.h"
16 #include "company_type.h"
17 #include "subsidy_type.h"
18 #include "core/pool_type.hpp"
20 typedef Pool
<Subsidy
, SubsidyID
, 1, 256> SubsidyPool
;
21 extern SubsidyPool _subsidy_pool
;
23 /** Struct about subsidies, offered and awarded */
24 struct Subsidy
: SubsidyPool::PoolItem
<&_subsidy_pool
> {
25 CargoID cargo_type
; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy
26 byte remaining
; ///< Remaining months when this subsidy is valid
27 CompanyByte awarded
; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone
28 SourceTypeByte src_type
; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN)
29 SourceTypeByte dst_type
; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN)
30 SourceID src
; ///< Index of source. Either TownID or IndustryID
31 SourceID dst
; ///< Index of destination. Either TownID or IndustryID
34 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
39 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
44 * Tests whether this subsidy has been awarded to someone
45 * @return is this subsidy awarded?
47 inline bool IsAwarded() const
49 return this->awarded
!= INVALID_COMPANY
;
52 void AwardTo(CompanyID company
);
55 /** Constants related to subsidies */
56 static const uint SUBSIDY_OFFER_MONTHS
= 12; ///< Duration of subsidy offer
57 static const uint SUBSIDY_CONTRACT_MONTHS
= 12; ///< Duration of subsidy after awarding
58 static const uint SUBSIDY_PAX_MIN_POPULATION
= 400; ///< Min. population of towns for subsidised pax route
59 static const uint SUBSIDY_CARGO_MIN_POPULATION
= 900; ///< Min. population of destination town for cargo route
60 static const uint SUBSIDY_MAX_PCT_TRANSPORTED
= 42; ///< Subsidy will be created only for towns/industries with less % transported
61 static const uint SUBSIDY_MAX_DISTANCE
= 70; ///< Max. length of subsidised route (DistanceManhattan)
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)
66 #endif /* SUBSIDY_BASE_H */