-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardModel.hpp
241 lines (204 loc) · 7.87 KB
/
BoardModel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ifndef BOARDMODEL_HPP
#define BOARDMODEL_HPP
#include <QList>
#include <QSet>
#include <QDataStream>
#include "HexModel.hpp"
#include "RegionModel.hpp"
#include "EventCard.hpp"
#include "AdvanceModel.hpp"
#include "WonderModel.hpp"
#include <boost/assert.hpp>
class BoardModel : public QObject
{
Q_OBJECT
public:
enum Empire {ATLANTEA = 0, FLOREN, GILDA, NORDIG};
enum MoveTribesType {CANT_MOVE = 0, NORMAL = 1, OVERSEAS = 2};
signals:
void boardUpdated();
void boardCleared();
void sendMessage(const QString &text);
void clearMessages();
void sendCardsLeftCount(int cardsLeftCount);
void sendDoneText(const QString &text);
void sendDialogClosed();
void eraChanged(int era);
void goldChanged(int gold);
void gloryScoreChanged(int gloryScore);
void advanceAquired(AdvanceModel::Advance advance);
void changeAdvanceSelected(AdvanceModel::Advance advance);
private:
QList<QList<HexModel *> > hexModels; // Saved, Initialize with newBoard(width,height)
QList<QSet<HexModel *> > seas; // Derived from hexModels after loading (groupSeas())
QMap<int, QSet<HexModel *> > regionHexes; // Derived from hexModels after loading (deriveRegionHexes())
QMap<int, RegionModel *> regions; // Saved
QList<const EventCard *> eventCardsLeft; // Saved, content derived from eventCards
RegionModel *activeRegion; // Initialized
QList<const EventCard *> eventCards; // Initialized
QMap<AdvanceModel::Advance, const AdvanceModel *> advances; // Initialized
QSet<AdvanceModel::Advance> advancesAquired; // Saved
QSet<AdvanceModel::Advance> selectedAdvances; // Derived (Empty at first)
QMap<WonderModel::Wonder, const WonderModel *> wonders; // Initialized
QSet<Empire> tradingPartners; // Saved
// Save
bool buildCity;
bool buildFarm;
bool expedition;
bool aquireAdvances;
bool buildWonder;
bool collectTaxes;
bool forestation;
bool mining;
bool doneEnabled;
int gold;
int era;
int lastEra;
QList<int> gloryScoreByEra;
int gloryScore;
bool agricultureLeft;
// Initialized
bool aquiringAdvances;
bool buildingWonders;
const EventCard *originalCard;
public:
BoardModel(int width = 20, int height = 10, QObject *parent = 0);
~BoardModel();
void printMessage(const QString &text);
void emitDialogClosed();
void setDoneText(const QString &text);
bool toggleHexToRegion(int region, int x, int y);
void enableAllHexes();
void setUnsetHexesToSea();
void setChoosingHexesDone();
void enableRegionSelectableHexes();
void groupSeas();
void initialRegionModels();
BoardModel::MoveTribesType getMoveTribesType(int fromRegion, int toRegion);
void mergeAllMovedTribes();
void increaseEra();
void populationGrowth();
void moveTribes(int fromRegion, int toRegion, int howMany, BoardModel::MoveTribesType moveTribesType);
bool bordersOnFrontier(int region) const;
bool bordersOnSea(int region) const;
bool bordersOnDesert(int region) const;
void decimateUnsupportedTribes();
void decimateGold();
void checkCitySupport();
int checkCartageCitySupport();
void decimateZeroAVCities();
void selectAdvanceableRegions();
void scoreSelectedAdvances();
void toggleSelectAquiredAdvance(AdvanceModel::Advance advance);
void unsetAdvancesAquired();
bool canAquireAdvance(AdvanceModel::Advance advance) const;
bool canBuildWonder(WonderModel::Wonder wonder) const;
bool otherWonderRequirementsMet(WonderModel::Wonder wonder) const;
const EventCard *drawCard(bool tell = true);
const EventCard *drawOriginalCard(bool tell = true);
void discardDrawnCards();
void reshuffleCards();
void setSelectRegion(int region, bool select);
void unselectAllRegions();
void disableButtons();
void enableMainPhaseButtons();
void decimateAllSelectedTribes();
void unselectAllSelectedTribes();
void reduceAllSelectedCityAV();
void unselectAllSelectedCityAV();
void gainGold(int gold);
void removeGold(int gold);
void addAdvanceGloryScore();
private:
void newBoard(int width, int height);
void initializeBoard();
bool checkRegionHexSet(const QSet<HexModel *> ®ionHexSet);
void deriveRegionHexes();
void initializeCards();
void initializeWonders();
public:
// Get-Methods
int getWidth() const;
int getHeight() const;
QMap<int, QSet<HexModel *> > getRegionHexes() const;
QMap<int, RegionModel *> getRegions() const;
QMap<int, RegionModel *> getAdjacentRegions(int fromRegion) const;
QMap<int, RegionModel *> getContinentRegions(int fromRegion) const;
QMap<int, RegionModel *> getRegionsReachableBySea(int fromRegion) const;
QMap<int, RegionModel *> getMountainRegions() const;
QMap<int, RegionModel *> getForestRegions() const;
int getMountainCount() const;
int getForestCount() const;
int getFarmCount() const;
int getDesertCount() const;
int getTribeCount() const;
int getCityCount() const;
int getCityAVCount() const;
int getAllSelectedCityAV() const;
QMap<int, RegionModel *> getSelectedRegions() const;
bool canBuildCity() const;
bool hasCity() const;
bool hasCapitolAssigned() const;
bool canBuildFarm() const;
bool canDoExpedition() const;
bool canAquireAdvance() const;
bool canBuildAnyWonder() const;
QMap<WonderModel::Wonder, int> getAllBuiltWonders() const;
QMap<WonderModel::Wonder, int> getAllWonders() const;
bool canCollectTaxes() const;
bool canDoForestation() const;
bool canDoMining() const;
bool isDoneEnabled() const;
int getEra() const;
int getLastEra() const;
int getEventCardCount() const;
bool isEndOfEra() const;
int getAllMovedTribes() const;
int getAllSelectedTribes() const;
int getGold() const;
int getGloryScore() const;
QList<int> getGloryScoreByEra() const;
QList<const EventCard *> getEventCards() const;
QList<const EventCard *> getDiscardedEventCards() const;
QList<const EventCard *> getEventCardsLeft() const;
QSet<AdvanceModel::Advance> getAdvancesSelected() const;
int getAdvanceSelectionLimit() const;
bool hasAquiredAdvanceSelected(AdvanceModel::Advance advance) const;
bool hasAdvanceAquired(AdvanceModel::Advance advance) const;
QSet<AdvanceModel::Advance> getAdvancesAquired() const;
bool hasAgricultureLeft() const;
bool isTradingPartner(Empire empire) const;
bool isAquiringAdvances() const;
bool isBuildingWonders() const;
// Set-Methods
void setActiveRegion(int region, bool isBad = true);
void unsetActiveRegion();
void setEra(int era);
void setGold(int gold);
void setGloryScore(int gloryScore);
void setAdvanceAquired(AdvanceModel::Advance advance);
void setAgricultureLeft(bool agricultureLeft);
void setDoneButton(bool enabled);
void setTradingPartner(Empire empire);
void setAquiringAdvances(bool aquiringAdvances);
void setBuildingWonders(bool buildingWonders);
// Ref-Methods
HexModel *refHexModel(int x, int y);
RegionModel *refRegionModel(int x, int y);
RegionModel *refRegionModel(int region) const;
RegionModel *refActiveRegion() const;
RegionModel *refCapitolRegion() const;
const EventCard *refOriginalCard() const;
const AdvanceModel *refAdvanceModel(AdvanceModel::Advance advance) const;
const WonderModel *refWonderModel(WonderModel::Wonder wonder) const;
public slots:
void aquireAdvance(AdvanceModel::Advance advance, bool tell = true);
void doBuildWonder(WonderModel::Wonder wonder, bool tell = true);
private slots:
void clearBoard();
public:
// Serialization
void serialize(QDataStream &writer) const;
void deserialize(QDataStream &reader);
};
#endif // BOARDMODEL_HPP