-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMapViewState.h
402 lines (304 loc) · 10.5 KB
/
MapViewState.h
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#pragma once
#include "Wrapper.h"
#include "CrimeRateUpdate.h"
#include "CrimeExecution.h"
#include "StructureTracker.h"
#include "Planet.h"
#include "../StorableResources.h"
#include "../RobotPool.h"
#include "../Constants/Numbers.h"
#include "../MapObjects/Robot.h"
#include "../MapObjects/Structure.h"
#include "../UI/NotificationArea.h"
#include "../UI/NotificationWindow.h"
#include "../UI/DiggerDirection.h"
#include "../UI/FactoryProduction.h"
#include "../UI/GameOverDialog.h"
#include "../UI/GameOptionsDialog.h"
#include "../UI/IconGrid.h"
#include "../UI/MajorEventAnnouncement.h"
#include "../UI/MineOperationsWindow.h"
#include "../UI/PopulationPanel.h"
#include "../UI/ResourceBreakdownPanel.h"
#include "../UI/RobotInspector.h"
#include "../UI/StructureInspector.h"
#include "../UI/TileInspector.h"
#include "../UI/WarehouseInspector.h"
#include "../UI/ResourceInfoBar.h"
#include "../UI/RobotDeploymentSummary.h"
#include "../UI/MiniMap.h"
#include "../UI/CheatMenu.h"
#include <libOPHD/Map/MapCoordinate.h>
#include <libOPHD/Population/PopulationPool.h>
#include <libOPHD/Population/Population.h>
#include <libOPHD/Population/Morale.h>
#include <libOPHD/Technology/ResearchTracker.h>
#include <libOPHD/Technology/TechnologyCatalog.h>
#include <libControls/WindowStack.h>
#include <libControls/ToolTip.h>
#include <NAS2D/Signal/Signal.h>
#include <NAS2D/Math/Point.h>
#include <NAS2D/Math/Rectangle.h>
#include <NAS2D/Renderer/Fade.h>
#include <string>
#include <memory>
#include <map>
namespace NAS2D
{
namespace Xml
{
class XmlElement;
}
}
namespace micropather
{
class MicroPather;
}
enum class Direction;
class Tile;
class TileMap;
class MapView;
class DetailMap;
class NavControl;
class MainReportsUiState;
class GameState;
class FileIo;
class ColonyShip;
enum class InsertMode
{
None,
Robot,
Tube,
Structure
};
using RobotTileTable = std::map<Robot*, Tile*>;
class MapViewState : public Wrapper
{
public:
enum class PopulationLevel
{
Small = 1,
Large = 2
};
public:
using QuitSignal = NAS2D::Signal<>;
using ReportsUiSignal = NAS2D::Signal<>;
using MapChangedSignal = NAS2D::Signal<>;
public:
MapViewState(GameState& gameState, const std::string& savegame);
MapViewState(GameState& gameState, const Planet::Attributes& planetAttributes, Difficulty selectedDifficulty);
~MapViewState() override;
ReportsUiSignal::Source& showReportsUi() { return mReportsUiSignal; }
QuitSignal::Source& quit() { return mQuitSignal; }
MapChangedSignal::Source& mapChanged() { return mMapChangedSignal; }
void focusOnStructure(const Structure* s);
Difficulty difficulty() { return mDifficulty; }
void difficulty(Difficulty difficulty);
bool hasGameEnded();
void initialize() override;
State* update() override;
void save(const std::string& filePath);
private:
void onDeactivate() override;
void onActivate() override;
// EVENT HANDLERS
void onActivate(bool newActiveValue);
void onKeyDown(NAS2D::KeyCode key, NAS2D::KeyModifier mod, bool repeat);
void onMouseDown(NAS2D::MouseButton button, NAS2D::Point<int> position);
void onMouseDoubleClick(NAS2D::MouseButton button, NAS2D::Point<int> position);
void onMouseUp(NAS2D::MouseButton button, NAS2D::Point<int> position);
void onMouseMove(NAS2D::Point<int> position, NAS2D::Vector<int> relative);
void onMouseWheel(NAS2D::Vector<int> changeAmount);
void onWindowResized(NAS2D::Vector<int> newSize);
void onInspect(const MapCoordinate& tilePosition, bool inspectModifier);
void onInspectStructure(Structure& structure, bool inspectModifier);
void onInspectRobot(Robot& robot);
void onInspectTile(Tile& tile);
void onClickMap();
void onSystemMenu();
// ROBOT EVENT HANDLERS
void onDozerTaskComplete(Robot& robot);
void onDiggerTaskComplete(Robot& robot);
void onMinerTaskComplete(Robot& robot);
// DRAWING FUNCTIONS
void drawUI();
void drawSystemButton() const;
// INSERT OBJECT HANDLING
void onDeployCargoLander();
void onDeployColonistLander();
void onDeploySeedLander(NAS2D::Point<int> point);
void insertSeedLander(NAS2D::Point<int> point);
void insertTube(ConnectorDir dir, int depth, Tile& tile);
void placeTubes(Tile& tile);
void placeStructure(Tile& tile);
void placeRobot(Tile& tile);
void placeRobodozer(Tile&);
void placeRobodigger(Tile&);
void placeRobominer(Tile&);
Robot& addRobot(Robot::Type type);
void setStructureID(StructureID type, InsertMode mode);
// MISCELLANEOUS UTILITY FUNCTIONS
void updateFood();
void transferFoodToCommandCenter();
void updateCommRangeOverlay();
void updatePoliceOverlay();
void updateConnectedness();
void changeViewDepth(int);
void moveView(MapOffset offset);
void onChangeDepth(int oldDepth, int newDepth);
void pullRobotFromFactory(ProductType pt, Factory& factory);
void onFactoryProductionComplete(Factory& factory);
void onCheatCodeEntry(const std::string& cheatCode);
void onMineFacilityExtend(MineFacility* mf);
void onCrimeEvent(std::string title, std::string text, const Structure& structure);
void updatePlayerResources();
void updateResearch();
// TURN LOGIC
void checkColonyShip();
void onColonyShipCrash(const ColonyShipData&);
void checkWarehouseCapacity();
void nextTurn();
void updatePopulation();
void updateCommercial();
void updateMaintenance();
void updateMorale();
void notifyBirthsAndDeaths();
void updateResidentialCapacity();
void updateBiowasteRecycling();
void updateResources();
void updateRoads();
void updateRobots();
void findMineRoutes();
void transportOreFromMines();
void transportResourcesToStorage();
void checkAgingStructures();
void checkNewlyBuiltStructures();
// SAVE GAME MANAGEMENT FUNCTIONS
void readRobots(NAS2D::Xml::XmlElement* element);
void readStructures(NAS2D::Xml::XmlElement* element);
void readTurns(NAS2D::Xml::XmlElement* element);
void readPopulation(NAS2D::Xml::XmlElement* element);
void readMoraleChanges(NAS2D::Xml::XmlElement*);
void scrubRobotList();
void load(const std::string& filePath);
NAS2D::Xml::XmlElement* serializeProperties();
// UI MANAGEMENT FUNCTIONS
void clearMode();
void clearSelections();
void hideUi();
void unhideUi();
void initUi();
void resetUi();
bool modalUiElementDisplayed() const;
void setupUiPositions(NAS2D::Vector<int> size);
void populateRobotMenu();
void populateStructureMenu();
void updateStructuresAvailability();
// UI EVENT HANDLERS
void onTurns();
void setOverlay(std::vector<Tile*>& tileList, Tile::Overlay overlay);
void clearOverlays();
void clearOverlay(std::vector<Tile*>& tileList);
void updateOverlays();
void changePoliceOverlayDepth(int oldDepth, int newDepth);
void onToggleHeightmap();
void onToggleConnectedness();
void onToggleCommRangeOverlay();
void onToggleRouteOverlay();
void onTogglePoliceOverlay();
void onNotificationClicked(const NotificationArea::Notification&);
void onOpenSaveGameDialog();
void onOpenLoadGameDialog();
void onReturnToGame();
void onGameOver();
void onStructuresSelectionChange(const IconGrid::Item*);
void onConnectionsSelectionChange(const IconGrid::Item*);
void onRobotsSelectionChange(const IconGrid::Item*);
void onDiggerSelectionDialog(Direction direction, Tile& tile);
void onTakeMeThere(const MapCoordinate& position);
private:
Difficulty mDifficulty = Difficulty::Medium;
std::unique_ptr<TileMap> mTileMap;
CrimeRateUpdate mCrimeRateUpdate;
CrimeExecution mCrimeExecution;
StructureTracker mStructureTracker;
ResearchTracker mResearchTracker;
TechnologyCatalog mTechnologyReader;
Planet::Attributes mPlanetAttributes;
int mFood{0};
// Length of "honeymoon period" of no crime/morale updates after landing, in turns
static const std::map<Difficulty, int> GracePeriod;
// Morale loss multiplier on colonist death due to colony ship de-orbit
static const std::map<Difficulty, int> ColonyShipDeorbitMoraleLossMultiplier;
// MISCELLANEOUS
int mTurnCount = 0;
int mTurnNumberOfLanding = constants::ColonyShipOrbitTime; /**< First turn that human colonists landed. */
Morale mMorale;
int mResidentialCapacity = 0;
// POOLS
StorableResources mResourcesCount;
RobotPool mRobotPool; /**< Robots that are currently available for use. */
PopulationPool mPopulationPool;
RobotTileTable mRobotList; /**< List of active robots and their positions on the map. */
Population mPopulation;
// ROUTING
std::unique_ptr<micropather::MicroPather> mPathSolver;
bool mLoadingExisting = false;
std::string mExistingToLoad; /**< Filename of the existing game to load. */
MainReportsUiState& mMainReportsState;
std::unique_ptr<MapView> mMapView;
const NAS2D::Image mUiIcons{"ui/icons.png"}; /**< User interface icons. */
const NAS2D::Image mBackground{"sys/bg1.png"}; /**< Background image drawn behind the tile map. */
MapCoordinate mMouseTilePosition;
NAS2D::Rectangle<int> mMiniMapRect; /**< Area of the site map display. */
InsertMode mInsertMode = InsertMode::None; /**< What's being inserted into the TileMap if anything. */
StructureID mCurrentStructure = StructureID::SID_NONE; /**< Structure being placed. */
Robot::Type mCurrentRobot = Robot::Type::None; /**< Robot being placed. */
// USER INTERFACE
Button mBtnTurns;
Button mBtnToggleHeightmap;
Button mBtnToggleConnectedness;
Button mBtnToggleCommRangeOverlay;
Button mBtnToggleRouteOverlay;
Button mBtnTogglePoliceOverlay;
// Bare Control's use for ToolTips
Control mTooltipSystemButton;
Control mTooltipCurrentTurns;
ToolTip mToolTip;
IconGrid mStructures;
IconGrid mRobots;
IconGrid mConnections;
CheatMenu mCheatMenu;
DiggerDirection mDiggerDirection;
FactoryProduction mFactoryProduction;
FileIo& mFileIoDialog;
GameOverDialog mGameOverDialog;
GameOptionsDialog mGameOptionsDialog;
MajorEventAnnouncement mAnnouncement;
MineOperationsWindow mMineOperationsWindow;
NotificationArea mNotificationArea;
NotificationWindow mNotificationWindow;
PopulationPanel mPopulationPanel;
ResourceBreakdownPanel mResourceBreakdownPanel;
RobotInspector mRobotInspector;
StructureInspector mStructureInspector;
TileInspector mTileInspector;
WarehouseInspector mWarehouseInspector;
WindowStack mWindowStack;
NAS2D::Rectangle<int> mBottomUiRect;
// SIGNALS
QuitSignal mQuitSignal;
ReportsUiSignal mReportsUiSignal;
MapChangedSignal mMapChangedSignal;
std::vector<Tile*> mConnectednessOverlay;
std::vector<Tile*> mCommRangeOverlay;
std::vector<std::vector<Tile*>> mPoliceOverlays;
std::vector<Tile*> mTruckRouteOverlay;
ResourceInfoBar mResourceInfoBar;
RobotDeploymentSummary mRobotDeploymentSummary;
std::unique_ptr<MiniMap> mMiniMap;
std::unique_ptr<DetailMap> mDetailMap;
std::unique_ptr<NavControl> mNavControl;
NAS2D::Fade mFade;
ColonyShip& mColonyShip;
};