1 /*
2 * Copyright (C) 2007-2020 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20 #ifndef WL_LOGIC_WIDELANDS_H
21 #define WL_LOGIC_WIDELANDS_H
22
23 #include <cstdint>
24 #include <limits>
25 #include <vector>
26
27 namespace Widelands {
28
29 // Type definitions for the game logic.
30 using MilitaryInfluence = uint16_t;
31
32 /// 5 bits used, so 0 .. 31
33 /// Data type must match kMaxPlayers in graphics/playercolor.h
34 using PlayerNumber = uint8_t;
neutral()35 inline PlayerNumber neutral() {
36 return 0;
37 }
38 #define iterate_player_numbers(p, nr_players) \
39 for (Widelands::PlayerNumber p = 1; p < nr_players + 1; ++p)
40
41 /**
42 * Every player has a team number. Team number 0 is special,
43 * indicating that the player is not part of any team.
44 *
45 * Players having the same positive team number are allied.
46 */
47 using TeamNumber = uint8_t;
48
49 /** This is used as index for wares, workers, terrain and other Descriptions.
50 *
51 * So we can have at most 254 types of these,
52 * as some are predefined as invalid by the declarations below.
53 *
54 * A DescriptionMaintainer can be used to lookup the actual item.
55 * See TerrainDescription, WareDescr, WorkerDescr
56 * EditorCategory, BuildingDescr, ImmovableDescr, ShipDescr, TribeDescr
57 * and others.
58 */
59 using DescriptionIndex = uint16_t;
60
61 constexpr DescriptionIndex INVALID_INDEX = std::numeric_limits<uint16_t>::max();
62 constexpr DescriptionIndex kInvalidWare = INVALID_INDEX - 1;
63 constexpr DescriptionIndex kNoResource = INVALID_INDEX - 1;
64
65 using ResourceAmount = uint8_t; /// 4 bits used, so 0 .. 15.
66
67 using Quantity = uint32_t; // e.g. the number of a type of ware in a warehouse.
68
69 using Vision = uint16_t;
70
71 using Time = int32_t; // TODO(unknown): should be unsigned
never()72 inline Time never() {
73 return 0xffffffff;
74 }
75
76 using Duration = uint32_t;
endless()77 inline Duration endless() {
78 return 0xffffffff;
79 }
80
81 using Serial = uint32_t; /// Serial number for MapObject.
82 constexpr Serial kInvalidSerial = std::numeric_limits<uint32_t>::max();
83
84 using Direction = uint8_t;
85
86 struct SoldierStrength {
87 uint8_t health, attack, defense, evade;
88 bool operator==(const SoldierStrength& other) const {
89 return health == other.health && attack == other.attack && defense == other.defense &&
90 evade == other.evade;
91 }
92 bool operator<(const SoldierStrength& other) const {
93 return health < other.health ||
94 (health == other.health &&
95 (attack < other.attack ||
96 (attack == other.attack &&
97 (defense < other.defense || (defense == other.defense && evade < other.evade)))));
98 }
99 };
100
101 // For suggested teams info during map preload
102 using SuggestedTeam = std::vector<PlayerNumber>; // Players in a team
103 // Recommended teams to play against each other
104 using SuggestedTeamLineup = std::vector<SuggestedTeam>;
105
106 } // namespace Widelands
107
108 #endif // end of include guard: WL_LOGIC_WIDELANDS_H
109