forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creature.h
409 lines (365 loc) · 13 KB
/
creature.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
403
404
405
406
407
408
409
/* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm)
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/ . */
#ifndef _CREATURE_H
#define _CREATURE_H
#include "creature_attributes.h"
#include "equipment.h"
#include "enums.h"
#include "attack.h"
#include "shortest_path.h"
#include "tribe.h"
#include "skill.h"
#include "controller.h"
#include "unique_entity.h"
#include "event.h"
#include "sectors.h"
#include "vision.h"
#include "square_type.h"
#include "creature_action.h"
#include "renderable.h"
#include "movement_type.h"
#include "player_message.h"
#include "game_info.h"
class Level;
class Tribe;
class EnemyCheck;
class ViewObject;
class Creature : private CreatureAttributes, public Renderable, public UniqueEntity<Creature> {
public:
typedef CreatureAttributes CreatureAttributes;
Creature(Tribe*, const CreatureAttributes&, ControllerFactory);
Creature(const ViewObject&, Tribe*, const CreatureAttributes&, ControllerFactory);
virtual ~Creature();
static string getBodyPartName(BodyPart);
void makeMove();
double getTime() const;
void setTime(double t);
void setLevel(Level* l);
vector<const Creature*> getVisibleEnemies() const;
Level* getLevel();
const Level* getLevel() const;
Square* getSquare();
const Square* getSquare() const;
Square* getSafeSquare(Vec2 direction);
const Square* getSafeSquare(Vec2 direction) const;
vector<Square*> getSquare(Vec2 direction);
vector<const Square*> getSquare(Vec2 direction) const;
vector<Square*> getSquares(const vector<Vec2>& direction);
vector<const Square*> getSquares(const vector<Vec2>& direction) const;
void setPosition(Vec2 pos);
Vec2 getPosition() const;
bool dodgeAttack(const Attack&);
bool takeDamage(const Attack&);
void heal(double amount = 1, bool replaceLimbs = false);
double getHealth() const;
double getMorale() const;
void addMorale(double);
DEF_UNIQUE_PTR(MoraleOverride);
class MoraleOverride {
public:
virtual optional<double> getMorale() = 0;
virtual ~MoraleOverride() {}
template <class Archive>
void serialize(Archive& ar, const unsigned int version);
};
void addMoraleOverride(PMoraleOverride);
double getWeight() const;
bool canSleep() const;
void take(PItem item);
void take(vector<PItem> item);
const Equipment& getEquipment() const;
Equipment& getEquipment();
vector<PItem> steal(const vector<Item*> items);
bool canSee(const Creature*) const;
bool canSee(Vec2 pos) const;
bool isEnemy(const Creature*) const;
void tick(double realTime);
const EntityName& getName() const;
string getSpeciesName() const;
string getNameAndTitle() const;
optional<string> getFirstName() const;
void setFirstName(const string&);
string getGroupName(int count) const;
int getModifier(ModifierType) const;
int getAttr(AttrType) const;
static string getAttrName(AttrType);
static string getModifierName(ModifierType);
int getPoints() const;
VisionId getVision() const;
const Tribe* getTribe() const;
Tribe* getTribe();
bool isFriend(const Creature*) const;
void addEnemyCheck(EnemyCheck*);
void removeEnemyCheck(EnemyCheck*);
int getDebt(const Creature* debtor) const;
vector<Item*> getGold(int num) const;
void takeItems(vector<PItem> items, const Creature* from);
void youHit(BodyPart part, AttackType type) const;
void dropCorpse();
virtual vector<PItem> getCorpse();
void monsterMessage(const PlayerMessage& playerCanSee, const PlayerMessage& cant = "") const;
void globalMessage(const PlayerMessage& playerCanSee, const PlayerMessage& cant = "") const;
bool isDead() const;
bool isBlind() const;
const Creature* getLastAttacker() const;
vector<const Creature*> getKills() const;
bool isHumanoid() const;
bool isAnimal() const;
bool isStationary() const;
void setStationary();
bool isInvincible() const;
bool isUndead() const;
bool hasBrain() const;
bool isNotLiving() const;
bool isCorporal() const;
bool isWorshipped() const;
bool isHatcheryAnimal() const;
bool dontChase() const;
optional<SpawnType> getSpawnType() const;
MovementType getMovementType() const;
int numBodyParts(BodyPart) const;
int numLost(BodyPart) const;
int numInjured(BodyPart) const;
int lostOrInjuredBodyParts() const;
int numGood(BodyPart) const;
void injureBodyPart(BodyPart part, bool drop);
bool isCritical(BodyPart part) const;
double getMinDamage(BodyPart part) const;
string bodyDescription() const;
double getCourage() const;
void setCourage(double);
Gender getGender() const;
int getDifficultyPoints() const;
int getExpLevel() const;
void exerciseAttr(AttrType, double value = 1);
void increaseExpLevel(double increase);
string getDescription() const;
bool isSpecialMonster() const;
bool isInnocent() const;
void addSkill(Skill* skill);
bool hasSkill(Skill*) const;
double getSkillValue(const Skill*) const;
const EnumSet<SkillId>& getDiscreteSkills() const;
typedef GameInfo::PlayerInfo::SkillInfo SkillInfo;
vector<SkillInfo> getSkillNames() const;
string getPluralTheName(Item* item, int num) const;
string getPluralAName(Item* item, int num) const;
CreatureAction move(Vec2 direction) const;
CreatureAction forceMove(Vec2 direction) const;
CreatureAction swapPosition(Vec2 direction, bool force = false) const;
CreatureAction wait() const;
vector<Item*> getPickUpOptions() const;
CreatureAction pickUp(const vector<Item*>& item, bool spendTime = true) const;
CreatureAction drop(const vector<Item*>& item) const;
void drop(vector<PItem> item);
CreatureAction attack(const Creature*, optional<AttackLevel> = none, bool spendTime = true) const;
CreatureAction bumpInto(Vec2 direction) const;
CreatureAction applyItem(Item* item) const;
CreatureAction equip(Item* item) const;
CreatureAction unequip(Item* item) const;
bool canEquipIfEmptySlot(const Item* item, string* reason = nullptr) const;
bool canEquip(const Item* item) const;
CreatureAction throwItem(Item*, Vec2 direction) const;
CreatureAction heal(Vec2 direction) const;
CreatureAction applySquare() const;
CreatureAction hide() const;
bool isHidden() const;
bool knowsHiding(const Creature*) const;
CreatureAction flyAway() const;
CreatureAction disappear() const;
CreatureAction torture(Creature*) const;
CreatureAction chatTo(Vec2 direction) const;
CreatureAction stealFrom(Vec2 direction, const vector<Item*>&) const;
void give(const Creature* whom, vector<Item*> items);
CreatureAction fire(Vec2 direction) const;
CreatureAction construct(Vec2 direction, SquareType) const;
bool canConstruct(SquareType) const;
CreatureAction eat(Item*) const;
enum DestroyAction { BASH, EAT, DESTROY };
CreatureAction destroy(Vec2 direction, DestroyAction) const;
CreatureAction copulate(Vec2 direction) const;
bool canCopulateWith(const Creature*) const;
CreatureAction consume(Vec2 direction) const;
bool canConsume(const Creature*) const;
virtual void onChat(Creature*);
void learnLocation(const Location*);
Item* getWeapon() const;
vector<vector<Item*>> stackItems(vector<Item*>) const;
CreatureAction moveTowards(Vec2 pos, bool stepOnTile = false);
CreatureAction moveAway(Vec2 pos, bool pathfinding = true);
CreatureAction continueMoving();
CreatureAction stayIn(const Location*);
bool isSameSector(Vec2) const;
bool atTarget() const;
void die(const Creature* attacker = nullptr, bool dropInventory = true, bool dropCorpse = true);
void bleed(double severity);
void setOnFire(double amount);
void poisonWithGas(double amount);
void shineLight();
void setHeld(const Creature* holding);
bool isHeld() const;
void you(MsgType type, const string& param) const;
void you(const string& param) const;
void playerMessage(const PlayerMessage&) const;
bool isPlayer() const;
Controller* getController();
void pushController(PController);
void setController(PController);
void popController();
void setBoulderSpeed(double);
CreatureSize getSize() const;
void addCreatureVision(CreatureVision*);
void removeCreatureVision(CreatureVision*);
void addSpell(Spell*);
vector<Spell*> getSpells() const;
CreatureAction castSpell(Spell*) const;
CreatureAction castSpell(Spell*, Vec2) const;
double getSpellDelay(Spell*) const;
bool isReady(Spell*) const;
SERIALIZATION_DECL(Creature);
void addEffect(LastingEffect, double time, bool msg = true);
void removeEffect(LastingEffect, bool msg = true);
void addPermanentEffect(LastingEffect, bool msg = true);
void removePermanentEffect(LastingEffect, bool msg = true);
bool isAffected(LastingEffect) const;
bool isAffectedPermanently(LastingEffect) const;
bool isFireResistant() const;
bool isDarknessSource() const;
vector<AttackLevel> getAttackLevels() const;
bool hasSuicidalAttack() const;
vector<const Creature*> getUnknownAttacker() const;
const MinionTaskMap& getMinionTasks() const;
int accuracyBonus() const;
vector<string> getMainAdjectives() const;
vector<string> getGoodAdjectives() const;
vector<string> getWeaponAdjective() const;
vector<string> getBadAdjectives() const;
vector<string> popPersonalEvents();
private:
REGISTER_HANDLER(KillEvent, const Creature* victim, const Creature* killer);
double getExpLevelDouble() const;
double getRawAttr(AttrType) const;
bool affects(LastingEffect effect) const;
void onAffected(LastingEffect effect, bool msg);
void consumeEffects(const EnumMap<LastingEffect, int>&);
void consumeBodyParts(const EnumMap<BodyPart, int>&);
void onRemoved(LastingEffect effect, bool msg);
void onTimedOut(LastingEffect effect, bool msg);
CreatureAction moveTowards(Vec2 pos, bool away, bool stepOnTile);
double getInventoryWeight() const;
Item* getAmmo() const;
void updateViewObject();
int getStrengthAttackBonus() const;
BodyPart getBodyPart(AttackLevel attack) const;
void injure(BodyPart, bool drop);
AttackLevel getRandomAttackLevel() const;
AttackType getAttackType() const;
void spendTime(double time);
BodyPart armOrWing() const;
pair<double, double> getStanding(const Creature* c) const;
Level* SERIAL2(level, nullptr);
Vec2 SERIAL(position);
double SERIAL2(time, 1);
Equipment SERIAL(equipment);
optional<ShortestPath> SERIAL(shortestPath);
unordered_set<const Creature*> SERIAL(knownHiding);
Tribe* SERIAL(tribe);
vector<EnemyCheck*> SERIAL(enemyChecks);
double SERIAL2(health, 1);
double SERIAL2(morale, 0);
bool SERIAL2(dead, false);
double SERIAL2(lastTick, 0);
bool SERIAL2(collapsed, false);
EnumMap<BodyPart, int> SERIAL(injuredBodyParts);
EnumMap<BodyPart, int> SERIAL(lostBodyParts);
bool SERIAL2(hidden, false);
const Creature* SERIAL2(lastAttacker, nullptr);
int SERIAL2(swapPositionCooldown, 0);
vector<const Creature*> SERIAL(unknownAttacker);
vector<const Creature*> SERIAL(privateEnemies);
const Creature* SERIAL2(holding, nullptr);
PController SERIAL(controller);
vector<PController> SERIAL(controllerStack);
vector<CreatureVision*> SERIAL(creatureVisions);
mutable vector<const Creature*> SERIAL(kills);
mutable double SERIAL2(difficultyPoints, 0);
int SERIAL2(points, 0);
int SERIAL2(numAttacksThisTurn, 0);
EnumMap<LastingEffect, double> SERIAL(lastingEffects);
vector<PMoraleOverride> SERIAL(moraleOverrides);
EnumMap<AttrType, double> SERIAL(attrIncrease);
void updateVisibleCreatures(Rectangle range);
vector<const Creature*> SERIAL(visibleEnemies);
double getTimeRemaining(LastingEffect) const;
string getRemainingString(LastingEffect) const;
VisionId SERIAL(vision);
void updateVision();
vector<string> SERIAL(personalEvents);
bool forceMovement = false;
};
enum class AttackLevel { LOW, MIDDLE, HIGH };
enum class MsgType {
FEEL, // better
BLEEDING_STOPS,
COLLAPSE,
FALL,
PANIC,
RAGE,
DIE_OF,
ARE, // bleeding
YOUR, // your head is cut off
FALL_ASLEEP, //
WAKE_UP,
DIE, //
FALL_APART,
TELE_APPEAR,
TELE_DISAPPEAR,
ATTACK_SURPRISE,
CAN_SEE_HIDING,
SWING_WEAPON,
THRUST_WEAPON,
KICK,
PUNCH,
BITE,
HIT,
TOUCH,
CRAWL,
TRIGGER_TRAP,
DISARM_TRAP,
DROP_WEAPON,
GET_HIT_NODAMAGE, // body part
HIT_THROWN_ITEM,
HIT_THROWN_ITEM_PLURAL,
MISS_THROWN_ITEM,
MISS_THROWN_ITEM_PLURAL,
ITEM_CRASHES,
ITEM_CRASHES_PLURAL,
STAND_UP,
TURN_INVISIBLE,
TURN_VISIBLE,
ENTER_PORTAL,
HAPPENS_TO,
BURN,
DROWN,
SET_UP_TRAP,
DECAPITATE,
TURN,
BECOME,
KILLED_BY,
BREAK_FREE,
MISS_ATTACK,
PRAY,
SACRIFICE,
COPULATE,
CONSUME,
GROW,
};
#endif