-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathplayer_control.h
313 lines (285 loc) · 12.5 KB
/
player_control.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
/* Copyright (C) 2013-2014 Michal Brzozowski ([email protected])
This file is part of KeeperRL.
KeeperRL 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; either version 2
of the License, or (at your option) any later version.
KeeperRL 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/ . */
#pragma once
#include "creature_view.h"
#include "entity_set.h"
#include "collective_control.h"
#include "game_info.h"
#include "map_memory.h"
#include "position.h"
#include "event_listener.h"
#include "keeper_creature_info.h"
#include "workshop_type.h"
#include "resource_id.h"
#include "bed_type.h"
class Model;
class Technology;
class View;
class Collective;
class CollectiveTeams;
class MapMemory;
class VisibilityMap;
class UserInput;
class MinionAction;
struct TaskActionInfo;
struct EquipmentGroupAction;
struct AIActionInfo;
struct CreatureDropInfo;
struct EquipmentActionInfo;
struct TeamCreatureInfo;
class CostInfo;
struct WorkshopItem;
struct WorkshopQueuedItem;
class ScrollPosition;
class Tutorial;
struct BuildInfo;
class MoveInfo;
class UnknownLocations;
class AttackTrigger;
class ImmigrantInfo;
struct WorkshopOptionInfo;
struct FurnaceOptionInfo;
class ScriptedUIState;
namespace BuildInfoTypes {
struct BuildType;
}
class PlayerControl : public CreatureView, public CollectiveControl, public EventListener<PlayerControl> {
public:
static PPlayerControl create(Collective* col, vector<TString> introText, TribeAlignment);
~PlayerControl() override;
void processInput(View* view, UserInput);
MoveInfo getMove(Creature* c);
void render(View*);
void loadImmigrationAndWorkshops(ContentFactory*, const KeeperCreatureInfo&);
void leaveControl();
void teamMemberAction(TeamMemberAction, UniqueEntity<Creature>::Id);
void toggleControlAllTeamMembers();
void onControlledKilled(Creature* victim);
void onSunlightVisibilityChanged();
void setTutorial(STutorial);
STutorial getTutorial() const;
bool isEnemy(const Creature*) const;
void addToMemory(Position);
SERIALIZATION_DECL(PlayerControl)
vector<Creature*> getTeam(const Creature*);
optional<FurnitureType> getMissingTrainingDummy(const Creature*);
bool canControlInTeam(const Creature*) const;
bool canControlSingle(const Creature*) const;
void addToCurrentTeam(Creature* c);
void updateUnknownLocations();
vector<Creature*> getConsumptionTargets(Creature* consumer) const;
TribeAlignment getTribeAlignment() const;
void onEvent(const GameEvent&);
const vector<Creature*>& getControlled() const;
void controlSingle(Creature*);
void checkKeeperDanger();
void dismissKeeperWarning();
optional<TeamId> getCurrentTeam() const;
CollectiveTeams& getTeams();
const CollectiveTeams& getTeams() const;
Model* getModel() const;
void takeScreenshot();
void addAllianceAttack(vector<Collective*> attackers);
private:
struct Private {};
public:
PlayerControl(Private, Collective*, TribeAlignment);
//protected:
// from CreatureView
virtual const MapMemory& getMemory() const override;
virtual void getViewIndex(Vec2 pos, ViewIndex&) const override;
virtual void refreshGameInfo(GameInfo&) const override;
virtual Vec2 getScrollCoord() const override;
virtual Level* getCreatureViewLevel() const override;
virtual vector<Vec2> getVisibleEnemies() const override;
virtual double getAnimationTime() const override;
virtual CenterType getCenterType() const override;
virtual const vector<Vec2>& getUnknownLocations(const Level*) const override;
virtual optional<Vec2> getSelectionSize() const override;
virtual vector<vector<Vec2>> getPathTo(UniqueEntity<Creature>::Id, Vec2) const override;
virtual vector<vector<Vec2>> getGroupPathTo(const TString&, Vec2) const override;
virtual vector<vector<Vec2>> getTeamPathTo(TeamId, Vec2) const override;
virtual vector<Vec2> getHighlightedPathTo(Vec2) const override;
virtual CreatureView::PlacementInfo canPlaceItem(Vec2, int) const override;
optional<QuartersInfo> getQuarters(Vec2) const override;
// from CollectiveControl
virtual void addAttack(const CollectiveAttack&) override;
virtual void addMessage(const PlayerMessage&) override;
virtual void addWindowMessage(ViewIdList, const TString&) override;
virtual void onMemberKilledOrStunned(Creature* victim, const Creature* killer) override;
virtual void onConquered(Creature* victim, Creature* killer) override;
virtual void onMemberAdded(Creature*) override;
virtual void onConstructed(Position, FurnitureType) override;
virtual void onDestructed(Position, FurnitureType, const DestroyAction&) override;
virtual void onClaimedSquare(Position) override;
virtual void tick() override;
virtual void update(bool currentlyActive) override;
virtual DuelAnswer acceptDuel(Creature* attacker) override;
private:
bool canAllyJoin(Creature* ally) const;
Level* getCurrentLevel() const;
void considerNightfallMessage();
void considerWarning();
void considerAllianceAttack();
void considerNewAttacks();
TribeId getTribeId() const;
bool canSee(const Creature*) const;
bool canSee(Position) const;
bool isConsideredAttacking(const CollectiveAttack&);
static string getWarningText(CollectiveWarning);
void updateSquareMemory(Position);
void updateKnownLocations(const Position&);
vector<Collective*> getKnownVillains() const;
Collective* getVillain(UniqueEntity<Collective>::Id num);
Creature* getConsumptionTarget(View*, Creature* consumer);
Creature* getCreature(UniqueEntity<Creature>::Id id) const;
void commandTeam(TeamId);
void setScrollPos(Position);
void handleSelection(Vec2 pos, const BuildInfo&, bool dryRun);
void handleSelection(Position, const BuildInfoTypes::BuildType&, bool dryRun);
vector<CollectiveInfo::Button> fillButtons() const;
VillageInfo::Village getVillageInfo(const Collective* enemy) const;
TString getTriggerLabel(const AttackTrigger&) const;
void fillWorkshopInfo(CollectiveInfo&) const;
vector<CollectiveInfo::QueuedItemInfo> getQueuedWorkshopItems() const;
vector<CollectiveInfo::QueuedItemInfo> getFurnaceQueue() const;
vector<WorkshopOptionInfo> getWorkshopOptions(int resourceIndex) const;
vector<FurnaceOptionInfo> getFurnaceOptions() const;
void fillImmigration(CollectiveInfo&) const;
void fillImmigrationHelp(CollectiveInfo&) const;
void fillLibraryInfo(CollectiveInfo&) const;
void fillTechUnlocks(CollectiveInfo::LibraryInfo::TechInfo&) const;
void fillCurrentLevelInfo(GameInfo&) const;
void getEquipmentItem(View* view, ItemPredicate predicate);
ItemInfo getWorkshopItem(const WorkshopItem&, int queuedCount) const;
Item* chooseEquipmentItem(Creature* creature, vector<Item*> currentItems, ItemPredicate,
ScriptedUIState* uiState = nullptr);
Creature* chooseSteed(Creature* creature, vector<Creature*> allSteeds);
int getNumMinions() const;
void minionTaskAction(const TaskActionInfo&);
void equipmentGroupAction(const EquipmentGroupAction&);
void minionAIAction(const AIActionInfo&);
void minionDragAndDrop(Vec2 pos, variant<TString, UniqueEntity<Creature>::Id>);
void fillMinions(CollectiveInfo&) const;
vector<Creature*> getMinionGroup(const TString& groupName) const;
vector<PlayerInfo> getPlayerInfos(vector<Creature*>) const;
void sortMinionsForUI(vector<Creature*>&) const;
vector<CollectiveInfo::CreatureGroup> getCreatureGroups(const vector<Creature*>&) const;
vector<CollectiveInfo::CreatureGroup> getAutomatonGroups(const vector<Creature*>&) const;
void minionEquipmentAction(const EquipmentActionInfo&);
void addEquipment(Creature*, EquipmentSlot);
void addConsumableItem(Creature*);
void handleEquipment(View* view, Creature* creature);
void fillSteedInfo(Creature*, PlayerInfo&) const;
void fillEquipment(Creature*, PlayerInfo&) const;
void fillPromotions(Creature*, CollectiveInfo&) const;
void handleTrading(Collective* ally);
vector<Item*> getPillagedItems(Collective*) const;
void handlePillage(Collective* enemy);
ViewObject getTrapObject(FurnitureType, bool built) const;
void getSquareViewIndex(Position, bool canSee, ViewIndex&) const;
void onSquareClick(Position);
Game* getGame() const;
View* getView() const;
PController createMinionController(Creature*);
mutable SMapMemory SERIAL(memory);
vector<TString> SERIAL(introText);
struct SelectionInfo {
Vec2 corner1;
Vec2 corner2;
bool deselect;
};
optional<SelectionInfo> rectSelection;
void updateSelectionSquares();
GlobalTime SERIAL(nextKeeperWarning) = GlobalTime(-1000);
struct ChosenCreatureInfo {
UniqueEntity<Creature>::Id id;
TString group;
};
optional<ChosenCreatureInfo> chosenCreature;
void setChosenCreature(optional<UniqueEntity<Creature>::Id>, TString group);
struct ChosenWorkshopInfo {
int resourceIndex;
WorkshopType type;
};
optional<ChosenWorkshopInfo> chosenWorkshop;
void setChosenWorkshop(optional<ChosenWorkshopInfo>);
optional<TeamId> getChosenTeam() const;
void setChosenTeam(optional<TeamId>, optional<UniqueEntity<Creature>::Id> = none);
optional<TeamId> chosenTeam;
void clearChosenInfo();
vector<PlayerMessage> SERIAL(messages);
vector<PlayerMessage> SERIAL(messageHistory);
vector<CollectiveAttack> SERIAL(newAttacks);
vector<CollectiveAttack> SERIAL(notifiedAttacks);
vector<TString> SERIAL(hints);
optional<PlayerMessage&> findMessage(PlayerMessage::Id);
SVisibilityMap SERIAL(visibilityMap);
bool firstRender = true;
bool isNight = true;
optional<UniqueEntity<Creature>::Id> draggedCreature;
void updateMinionVisibility(const Creature*);
STutorial SERIAL(tutorial);
void acquireTech(TechId);
SMessageBuffer SERIAL(controlModeMessages);
unordered_set<int> dismissedNextWaves;
vector<ImmigrantDataInfo> getPrisonerImmigrantData() const;
vector<ImmigrantDataInfo> getUnrealizedPromotionsImmigrantData() const;
vector<ImmigrantDataInfo> getNecromancerImmigrationHelp() const;
void acceptPrisoner(int index);
void rejectPrisoner(int index);
struct StunnedInfo {
vector<Creature*> creatures;
Collective* collective = nullptr;
};
vector<StunnedInfo> getPrisonerImmigrantStack() const;
vector<pair<Creature*, Collective*>> SERIAL(stunnedCreatures);
ViewIdList getMinionGroupViewId(Creature*) const;
SUnknownLocations SERIAL(unknownLocations);
optional<LocalTime> lastWarningDismiss;
set<pair<UniqueEntity<Collective>::Id, TStringId>> SERIAL(dismissedVillageInfos);
void considerTransferingLostMinions();
vector<PItem> retrievePillageItems(Collective*, vector<Item*> items);
TribeAlignment SERIAL(tribeAlignment);
vector<BuildInfo> SERIAL(buildInfo);
void loadBuildingMenu(const ContentFactory*, const KeeperCreatureInfo&);
Level* currentLevel = nullptr;
void scrollStairs(int dir);
CollectiveInfo::QueuedItemInfo getQueuedItemInfo(const WorkshopQueuedItem&, int cnt, int itemIndex) const;
vector<pair<Item*, Position>> getItemUpgradesFor(const WorkshopItem&) const;
void fillDungeonLevel(AvatarLevelInfo&) const;
void fillResources(CollectiveInfo&) const;
bool takingScreenshot = false;
void addBodyPart(Creature*);
void handleBanishing(Creature*);
optional<pair<ViewId,int>> getCostObj(CostInfo) const;
optional<pair<ViewId,int>> getCostObj(const optional<CostInfo>&) const;
ViewId getViewId(const BuildInfoTypes::BuildType&) const;
EntityMap<Creature, LocalTime> leaderWoundedTime;
void handleDestructionOrder(Position position, HighlightType, DestroyAction, bool dryRun);
HashSet<CollectiveResourceId> SERIAL(usedResources);
optional<vector<Collective*>> SERIAL(allianceAttack);
enum class Selection { SELECT, DESELECT, NONE } selection = Selection::NONE;
void considerTogglingCaptureOrderOnMinions() const;
struct BattleSummary {
vector<Creature*> SERIAL(minionsKilled);
vector<Creature*> SERIAL(minionsCaptured);
vector<Creature*> SERIAL(enemiesKilled);
vector<Creature*> SERIAL(enemiesCaptured);
SERIALIZE_ALL(minionsKilled, minionsCaptured, enemiesKilled, enemiesCaptured)
};
BattleSummary SERIAL(battleSummary);
void presentAndClearBattleSummary();
void presentMinionsFreedMessage(const vector<Creature*>&);
void considerSoloAchievement();
bool SERIAL(soloKeeper) = true;
mutable EnumMap<BedType, optional<int>> prisonSizeCache;
};