OpenTTD Source: src/town_type.h Source File

OpenTTD Source 15.3

town_type.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 TOWN_TYPE_H
11#define TOWN_TYPE_H
12
13#include "core/enum_type.hpp"
14#include "core/pool_type.hpp"
15
16using TownID = PoolID<uint16_t, struct TownIDTag, 64000, 0xFFFF>;
17
18struct Town;
19
21 enum TownSize : uint8_t {
22 TSZ_SMALL,
23 TSZ_MEDIUM,
24 TSZ_LARGE,
25 TSZ_RANDOM,
26
27 TSZ_END,
28};
29 DECLARE_ENUM_AS_ADDABLE(TownSize)
30
31/* These refer to the maximums, so Appalling is -1000 to -400
32 * MAXIMUM RATINGS BOUNDARIES */
33static constexpr int RATING_MINIMUM = -1000;
34static constexpr int RATING_APPALLING = -400;
35static constexpr int RATING_VERYPOOR = -200;
36static constexpr int RATING_POOR = 0;
37static constexpr int RATING_MEDIOCRE = 200;
38static constexpr int RATING_GOOD = 400;
39static constexpr int RATING_VERYGOOD = 600;
40static constexpr int RATING_EXCELLENT = 800;
41 static constexpr int RATING_OUTSTANDING = 1000;
42
43static constexpr int RATING_MAXIMUM = RATING_OUTSTANDING;
44
45 static constexpr int RATING_INITIAL = 500;
46
47/* RATINGS AFFECTING NUMBERS */
48static constexpr int RATING_TREE_DOWN_STEP = -35;
49static constexpr int RATING_TREE_MINIMUM = RATING_MINIMUM;
50static constexpr int RATING_TREE_UP_STEP = 7;
51static constexpr int RATING_TREE_MAXIMUM = 220;
52
53 static constexpr int RATING_GROWTH_UP_STEP = 5;
54 static constexpr int RATING_GROWTH_MAXIMUM = RATING_MEDIOCRE;
55 static constexpr int RATING_STATION_UP_STEP = 12;
56 static constexpr int RATING_STATION_DOWN_STEP = -15;
57
58 static constexpr int RATING_TUNNEL_BRIDGE_UP_STEP = 50;
59 static constexpr int RATING_TUNNEL_BRIDGE_DOWN_STEP = -250;
60 static constexpr int RATING_TUNNEL_BRIDGE_MINIMUM = 0;
61 static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_LENIENT = 144;
62 static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL = 208;
63 static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE = 400;
64 static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE = RATING_MINIMUM;
65
66 static constexpr int RATING_ROAD_DOWN_STEP_INNER = -50;
67 static constexpr int RATING_ROAD_DOWN_STEP_EDGE = -18;
68 static constexpr int RATING_ROAD_MINIMUM = -100;
69 static constexpr int RATING_ROAD_NEEDED_LENIENT = 16;
70 static constexpr int RATING_ROAD_NEEDED_NEUTRAL = 64;
71 static constexpr int RATING_ROAD_NEEDED_HOSTILE = 112;
72 static constexpr int RATING_ROAD_NEEDED_PERMISSIVE = RATING_MINIMUM;
73
74static constexpr int RATING_HOUSE_MINIMUM = RATING_MINIMUM;
75
76static constexpr int RATING_BRIBE_UP_STEP = 200;
77static constexpr int RATING_BRIBE_MAXIMUM = 800;
78static constexpr int RATING_BRIBE_DOWN_TO = -50; // XXX SHOULD BE SOMETHING LOWER?
79
81 enum TownLayout : uint8_t {
82 TL_BEGIN = 0,
83 TL_ORIGINAL = 0,
84 TL_BETTER_ROADS,
85 TL_2X2_GRID,
86 TL_3X3_GRID,
87
88 TL_RANDOM,
89
90 NUM_TLS,
91};
92 DECLARE_ENUM_AS_ADDABLE(TownLayout)
93
94
95enum class TownExpandMode : uint8_t {
96 Buildings,
97 Roads,
98};
99
100using TownExpandModes = EnumBitSet<TownExpandMode, uint8_t>;
101
103 enum TownFounding : uint8_t {
104 TF_BEGIN = 0,
105 TF_FORBIDDEN = 0,
106 TF_ALLOWED,
107 TF_CUSTOM_LAYOUT,
108 TF_END,
109};
110
112 enum TownCargoGenMode : uint8_t {
113 TCGM_BEGIN = 0,
114 TCGM_ORIGINAL = 0,
115 TCGM_BITCOUNT,
116 TCGM_END,
117};
118
119 static const uint MAX_LENGTH_TOWN_NAME_CHARS = 32;
120
122template <typename Tstorage>
123 struct TransportedCargoStat {
124 Tstorage old_max = 0;
125 Tstorage new_max = 0;
126 Tstorage old_act = 0;
127 Tstorage new_act = 0;
128
130 void NewMonth()
131 {
132 this->old_max = this->new_max; this->new_max = 0;
133 this->old_act = this->new_act; this->new_act = 0;
134 }
135};
136
137#endif /* TOWN_TYPE_H */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
enum_type.hpp
Type (helpers) for enums.
DECLARE_ENUM_AS_ADDABLE
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition enum_type.hpp:129
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
PoolID< uint16_t, struct TownIDTag, 64000, 0xFFFF >
Town
Town data structure.
Definition town.h:63
TransportedCargoStat
Store the maximum and actually transported cargo amount for the current and the last month.
Definition town_type.h:123
TransportedCargoStat::new_max
Tstorage new_max
Maximum amount this month.
Definition town_type.h:125
TransportedCargoStat::NewMonth
void NewMonth()
Update stats for a new month.
Definition town_type.h:130
TransportedCargoStat::old_max
Tstorage old_max
Maximum amount last month.
Definition town_type.h:124
TransportedCargoStat::old_act
Tstorage old_act
Actually transported last month.
Definition town_type.h:126
TransportedCargoStat::new_act
Tstorage new_act
Actually transported this month.
Definition town_type.h:127
RATING_GROWTH_UP_STEP
static constexpr int RATING_GROWTH_UP_STEP
when a town grows, all companies have rating increased a bit ...
Definition town_type.h:53
RATING_INITIAL
static constexpr int RATING_INITIAL
initial rating
Definition town_type.h:45
RATING_ROAD_NEEDED_HOSTILE
static constexpr int RATING_ROAD_NEEDED_HOSTILE
"Hostile"
Definition town_type.h:71
RATING_TUNNEL_BRIDGE_UP_STEP
static constexpr int RATING_TUNNEL_BRIDGE_UP_STEP
rating increase for improving a town-owned bridge
Definition town_type.h:58
RATING_ROAD_DOWN_STEP_EDGE
static constexpr int RATING_ROAD_DOWN_STEP_EDGE
removing a roadpiece at the edge
Definition town_type.h:67
RATING_ROAD_DOWN_STEP_INNER
static constexpr int RATING_ROAD_DOWN_STEP_INNER
removing a roadpiece in the middle
Definition town_type.h:66
TownCargoGenMode
TownCargoGenMode
Town cargo generation modes.
Definition town_type.h:112
TCGM_BITCOUNT
@ TCGM_BITCOUNT
Bit-counted algorithm (normal distribution from individual house population)
Definition town_type.h:115
TCGM_ORIGINAL
@ TCGM_ORIGINAL
Original algorithm (quadratic cargo by population)
Definition town_type.h:114
RATING_ROAD_NEEDED_NEUTRAL
static constexpr int RATING_ROAD_NEEDED_NEUTRAL
"Neutral"
Definition town_type.h:70
RATING_TUNNEL_BRIDGE_MINIMUM
static constexpr int RATING_TUNNEL_BRIDGE_MINIMUM
minimum rating after removing tunnel or bridge
Definition town_type.h:60
TownLayout
TownLayout
Town Layouts.
Definition town_type.h:81
TL_3X3_GRID
@ TL_3X3_GRID
Geometric 3x3 grid algorithm.
Definition town_type.h:86
TL_ORIGINAL
@ TL_ORIGINAL
Original algorithm (min. 1 distance between roads)
Definition town_type.h:83
TL_2X2_GRID
@ TL_2X2_GRID
Geometric 2x2 grid algorithm.
Definition town_type.h:85
TL_RANDOM
@ TL_RANDOM
Random town layout.
Definition town_type.h:88
TL_BETTER_ROADS
@ TL_BETTER_ROADS
Extended original algorithm (min. 2 distance between roads)
Definition town_type.h:84
NUM_TLS
@ NUM_TLS
Number of town layouts.
Definition town_type.h:90
RATING_TUNNEL_BRIDGE_NEEDED_LENIENT
static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_LENIENT
rating needed, "Lenient" difficulty settings
Definition town_type.h:61
TownFounding
TownFounding
Town founding setting values.
Definition town_type.h:103
TF_ALLOWED
@ TF_ALLOWED
Allowed.
Definition town_type.h:106
TF_CUSTOM_LAYOUT
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
Definition town_type.h:107
TF_END
@ TF_END
Used for iterations and limit testing.
Definition town_type.h:108
TF_BEGIN
@ TF_BEGIN
Used for iterations and limit testing.
Definition town_type.h:104
TF_FORBIDDEN
@ TF_FORBIDDEN
Forbidden.
Definition town_type.h:105
RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE
static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE
"Hostile"
Definition town_type.h:63
RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE
static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE
"Permissive" (local authority disabled)
Definition town_type.h:64
RATING_STATION_DOWN_STEP
static constexpr int RATING_STATION_DOWN_STEP
... but loses for badly serviced stations
Definition town_type.h:56
RATING_ROAD_MINIMUM
static constexpr int RATING_ROAD_MINIMUM
minimum rating after removing town owned road
Definition town_type.h:68
RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL
static constexpr int RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL
"Neutral"
Definition town_type.h:62
RATING_ROAD_NEEDED_LENIENT
static constexpr int RATING_ROAD_NEEDED_LENIENT
rating needed, "Lenient" difficulty settings
Definition town_type.h:69
RATING_STATION_UP_STEP
static constexpr int RATING_STATION_UP_STEP
when a town grows, company gains reputation for all well serviced stations ...
Definition town_type.h:55
RATING_TUNNEL_BRIDGE_DOWN_STEP
static constexpr int RATING_TUNNEL_BRIDGE_DOWN_STEP
penalty for removing town owned tunnel or bridge
Definition town_type.h:59
TownSize
TownSize
Supported initial town sizes.
Definition town_type.h:21
TSZ_RANDOM
@ TSZ_RANDOM
Random size, bigger than small, smaller than large.
Definition town_type.h:25
TSZ_END
@ TSZ_END
Number of available town sizes.
Definition town_type.h:27
TSZ_MEDIUM
@ TSZ_MEDIUM
Medium town.
Definition town_type.h:23
TSZ_SMALL
@ TSZ_SMALL
Small town.
Definition town_type.h:22
TSZ_LARGE
@ TSZ_LARGE
Large town.
Definition town_type.h:24
MAX_LENGTH_TOWN_NAME_CHARS
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
Definition town_type.h:119
TownExpandMode
TownExpandMode
Options for growing towns.
Definition town_type.h:95
TownExpandMode::Roads
@ Roads
Allow town to place roads.
TownExpandMode::Buildings
@ Buildings
Allow town to place buildings.
RATING_ROAD_NEEDED_PERMISSIVE
static constexpr int RATING_ROAD_NEEDED_PERMISSIVE
"Permissive" (local authority disabled)
Definition town_type.h:72
RATING_OUTSTANDING
static constexpr int RATING_OUTSTANDING
OUTSTANDING.
Definition town_type.h:41
RATING_GROWTH_MAXIMUM
static constexpr int RATING_GROWTH_MAXIMUM
... up to RATING_MEDIOCRE
Definition town_type.h:54