-
Notifications
You must be signed in to change notification settings - Fork 5
/
thing.hpp
762 lines (702 loc) · 24.6 KB
/
thing.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
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#ifndef INDIVIDUAL_HPP
#define INDIVIDUAL_HPP
#include "reference_counter.hpp"
#include "geometry.hpp"
#include "map.hpp"
#include "hashtable.hpp"
#include "list.hpp"
#include "byte_buffer.hpp"
#include "string.hpp"
#include "text.hpp"
#include <stdbool.h>
enum ThingType {
ThingType_INDIVIDUAL,
ThingType_WAND,
ThingType_POTION,
ThingType_BOOK,
ThingType_WEAPON,
ThingType_COUNT,
};
enum WandDescriptionId {
WandDescriptionId_BONE_WAND,
WandDescriptionId_GOLD_WAND,
WandDescriptionId_PLASTIC_WAND,
WandDescriptionId_COPPER_WAND,
WandDescriptionId_PURPLE_WAND,
WandDescriptionId_SHINY_BONE_WAND,
WandDescriptionId_SHINY_GOLD_WAND,
WandDescriptionId_SHINY_PLASTIC_WAND,
WandDescriptionId_SHINY_COPPER_WAND,
WandDescriptionId_SHINY_PURPLE_WAND,
WandDescriptionId_COUNT,
WandDescriptionId_UNSEEN,
};
enum WandId {
WandId_WAND_OF_CONFUSION,
WandId_WAND_OF_DIGGING,
WandId_WAND_OF_MAGIC_MISSILE,
WandId_WAND_OF_SPEED,
WandId_WAND_OF_REMEDY,
WandId_WAND_OF_BLINDING,
WandId_WAND_OF_FORCE,
WandId_WAND_OF_INVISIBILITY,
WandId_WAND_OF_MAGIC_BULLET,
WandId_WAND_OF_SLOWING,
WandId_COUNT,
WandId_UNKNOWN,
};
enum PotionDescriptionId {
PotionDescriptionId_BLUE_POTION,
PotionDescriptionId_GREEN_POTION,
PotionDescriptionId_RED_POTION,
PotionDescriptionId_YELLOW_POTION,
PotionDescriptionId_ORANGE_POTION,
PotionDescriptionId_PURPLE_POTION,
PotionDescriptionId_GLITTERY_BLUE_POTION,
PotionDescriptionId_GLITTERY_GREEN_POTION,
PotionDescriptionId_COUNT,
PotionDescriptionId_UNSEEN,
};
enum PotionId {
PotionId_POTION_OF_HEALING,
PotionId_POTION_OF_POISON,
PotionId_POTION_OF_ETHEREAL_VISION,
PotionId_POTION_OF_COGNISCOPY,
PotionId_POTION_OF_BLINDNESS,
PotionId_POTION_OF_INVISIBILITY,
PotionId_POTION_OF_BURROWING,
PotionId_POTION_OF_LEVITATION,
PotionId_COUNT,
PotionId_UNKNOWN,
};
enum BookDescriptionId {
BookDescriptionId_PURPLE_BOOK,
BookDescriptionId_BLUE_BOOK,
BookDescriptionId_RED_BOOK,
BookDescriptionId_GREEN_BOOK,
BookDescriptionId_YELLOW_BOOK,
BookDescriptionId_COUNT,
BookDescriptionId_UNSEEN,
};
enum BookId {
BookId_SPELLBOOK_OF_MAGIC_BULLET,
BookId_SPELLBOOK_OF_SPEED,
BookId_SPELLBOOK_OF_MAPPING,
BookId_SPELLBOOK_OF_FORCE,
BookId_SPELLBOOK_OF_ASSUME_FORM,
BookId_COUNT,
BookId_UNKNOWN,
};
enum WeaponId {
WeaponId_DAGGER,
WeaponId_BATTLEAXE,
WeaponId_COUNT,
WeaponId_UNKNOWN,
};
enum SpeciesId {
SpeciesId_HUMAN,
SpeciesId_OGRE,
SpeciesId_LICH,
SpeciesId_SHAPESHIFTER,
SpeciesId_PINK_BLOB,
SpeciesId_AIR_ELEMENTAL,
SpeciesId_TAR_ELEMENTAL,
SpeciesId_DOG,
SpeciesId_ANT,
SpeciesId_BEE,
SpeciesId_BEETLE,
SpeciesId_SCORPION,
SpeciesId_SNAKE,
SpeciesId_COBRA,
SpeciesId_COUNT,
SpeciesId_UNSEEN,
};
enum DecisionMakerType {
DecisionMakerType_AI,
DecisionMakerType_PLAYER,
DecisionMakerType_COUNT,
};
typedef uint8_t VisionTypes;
enum VisionTypesBits {
VisionTypes_NORMAL = 0x1,
VisionTypes_ETHEREAL = 0x2,
VisionTypes_COGNISCOPY = 0x4,
VisionTypes_COLOCATION = 0x8,
VisionTypes_REACH_AND_TOUCH = 0x10,
};
static inline bool can_see_physical_presence(VisionTypes vision) {
return vision & (VisionTypes_ETHEREAL | VisionTypes_COLOCATION);
}
static inline bool can_see_shape(VisionTypes vision) {
return vision & (VisionTypes_NORMAL | VisionTypes_ETHEREAL | VisionTypes_COLOCATION);
}
static inline bool can_see_color(VisionTypes vision) {
return vision & (VisionTypes_NORMAL | VisionTypes_ETHEREAL);
}
static inline bool can_see_thoughts(VisionTypes vision) {
// you can only see your own thoughts.
// TODO: this should really be more like TELEPATHY, but that doesn't exist right now.
return vision & VisionTypes_COLOCATION;
}
enum Mind {
Mind_NONE,
Mind_BEAST,
Mind_SAVAGE,
Mind_CIVILIZED,
};
// everyone has the same action cost
static const int action_cost = 12;
static const int speedy_movement_cost = 3;
static const int slow_movement_cost = 48;
struct Species {
SpeciesId species_id;
// how many ticks does it cost to move one space? average human is 12.
int movement_cost;
int base_hitpoints;
int base_mana;
int base_attack_power;
int min_level;
int max_level;
Mind mind;
VisionTypes vision_types;
bool sucks_up_items;
bool auto_throws_items;
bool poison_attack;
bool flying;
};
static const Mind _none = Mind_NONE;
static const Mind _beas = Mind_BEAST;
static const Mind _savg = Mind_SAVAGE;
static const Mind _civl = Mind_CIVILIZED;
static const VisionTypes _norm = VisionTypes_NORMAL;
static const VisionTypes _ethe = VisionTypes_ETHEREAL;
static constexpr Species specieses[SpeciesId_COUNT] = {
// movement cost
// | health
// | | base mana
// | | | base attack
// | | | | min level
// | | | | | max level
// | | | | | | mind
// | | | | | | | vision
// | | | | | | | | sucks up items
// | | | | | | | | | auto throws items
// | | | | | | | | | | poison attack
// | | | | | | | | | | | flying
{SpeciesId_HUMAN , 12, 10, 3, 3, 0, 10,_civl,_norm, 0, 0, 0, 0},
{SpeciesId_OGRE , 24, 15, 0, 2, 4, 10,_savg,_norm, 0, 0, 0, 0},
{SpeciesId_LICH , 12, 12, 4, 3, 7, 10,_civl,_norm, 0, 0, 0, 0},
{SpeciesId_SHAPESHIFTER , 12, 5, 0, 2, 1, 10,_civl,_norm, 0, 0, 0, 0},
{SpeciesId_PINK_BLOB , 48, 4, 0, 1, 0, 1,_none,_ethe, 1, 0, 0, 0},
{SpeciesId_AIR_ELEMENTAL, 6, 6, 0, 1, 3, 10,_none,_ethe, 1, 1, 0, 1},
{SpeciesId_TAR_ELEMENTAL, 24, 10, 0, 1, 3, 10,_none,_ethe, 1, 0, 0, 0},
{SpeciesId_DOG , 12, 4, 0, 2, 1, 2,_beas,_norm, 0, 0, 0, 0},
{SpeciesId_ANT , 12, 2, 0, 1, 0, 1,_beas,_norm, 0, 0, 0, 0},
{SpeciesId_BEE , 12, 2, 0, 3, 1, 2,_beas,_norm, 0, 0, 0, 1},
{SpeciesId_BEETLE , 24, 6, 0, 1, 0, 1,_beas,_norm, 0, 0, 0, 0},
{SpeciesId_SCORPION , 24, 5, 0, 1, 2, 3,_beas,_norm, 0, 0, 1, 0},
{SpeciesId_SNAKE , 24, 4, 0, 2, 1, 2,_beas,_norm, 0, 0, 0, 0},
{SpeciesId_COBRA , 24, 2, 0, 1, 2, 3,_beas,_norm, 0, 0, 0, 0},
};
static bool constexpr _check_specieses() {
#if __cpp_constexpr >= 201304
for (int i = 0; i < SpeciesId_COUNT; i++)
if (specieses[i].species_id != i)
return false;
#endif
return true;
}
static_assert(_check_specieses(), "missed a spot");
struct StatusEffect {
enum Id {
CONFUSION,
SPEED,
ETHEREAL_VISION,
COGNISCOPY,
BLINDNESS,
INVISIBILITY,
POISON,
POLYMORPH,
SLOWING,
BURROWING,
LEVITATING,
PUSHED,
COUNT,
};
Id type;
// this is never in the past
int64_t expiration_time;
int64_t poison_next_damage_time;
// used for awarding experience
uint256 who_is_responsible;
// used for polymorph
SpeciesId species_id;
// used for levitation momentum
Coord coord;
};
static inline int compare_status_effects_by_type(const StatusEffect & a, const StatusEffect & b) {
assert_str(a.type != b.type, "status effect list contains duplicates");
return a.type - b.type;
}
static inline bool can_see_status_effect(StatusEffect::Id effect, VisionTypes vision) {
switch (effect) {
case StatusEffect::CONFUSION: // the derpy look on your face
case StatusEffect::SPEED: // the twitchy motion of your body
case StatusEffect::SLOWING: // the baywatchy motion of your body
case StatusEffect::BLINDNESS: // the empty look in your eyes
case StatusEffect::POISON: // the sick look on your face
case StatusEffect::BURROWING: // the ground rippling beneath your feet
case StatusEffect::LEVITATING: // the gap between you and the ground
return can_see_shape(vision);
case StatusEffect::INVISIBILITY:
// ironically, you need normal vision to tell when something can't be seen with it.
return (vision & VisionTypes_NORMAL);
case StatusEffect::ETHEREAL_VISION:
case StatusEffect::COGNISCOPY:
// you'd have to see things through my eyes.
case StatusEffect::POLYMORPH:
// the polymorphed status is unknown unless you can see the original mind.
// otherwise, you just look like the new species.
return can_see_thoughts(vision);
case StatusEffect::PUSHED:
// this is only used to track who is responsible
return false;
case StatusEffect::COUNT:
unreachable();
}
unreachable();
}
static inline bool can_see_potion_effect(PotionId effect, VisionTypes vision) {
switch (effect) {
case PotionId_POTION_OF_HEALING: // the wounds closing
return can_see_shape(vision);
case PotionId_POTION_OF_POISON:
return can_see_status_effect(StatusEffect::POISON, vision);
case PotionId_POTION_OF_ETHEREAL_VISION:
return can_see_status_effect(StatusEffect::ETHEREAL_VISION, vision);
case PotionId_POTION_OF_COGNISCOPY:
return can_see_status_effect(StatusEffect::COGNISCOPY, vision);
case PotionId_POTION_OF_BLINDNESS:
return can_see_status_effect(StatusEffect::BLINDNESS, vision);
case PotionId_POTION_OF_INVISIBILITY:
return can_see_status_effect(StatusEffect::INVISIBILITY, vision);
case PotionId_POTION_OF_BURROWING:
return can_see_status_effect(StatusEffect::BURROWING, vision);
case PotionId_POTION_OF_LEVITATION:
return can_see_status_effect(StatusEffect::LEVITATING, vision);
case PotionId_UNKNOWN: // you alread know you can't see it
return false;
case PotionId_COUNT:
unreachable();
}
unreachable();
}
enum AbilityId {
AbilityId_SPIT_BLINDING_VENOM,
AbilityId_THROW_TAR,
AbilityId_ASSUME_FORM,
AbilityId_LUNGE_ATTACK,
AbilityId_COUNT,
};
struct AbilityCooldown {
AbilityId ability_id;
int64_t expiration_time;
};
static inline int compare_ability_cooldowns_by_type(const AbilityCooldown & a, const AbilityCooldown & b) {
assert_str(a.ability_id != b.ability_id, "ability cooldown list contains duplicates");
return a.ability_id - b.ability_id;
}
struct PerceivedWandInfo {
WandDescriptionId description_id;
int used_count; // -1 for empty
};
struct PerceivedPotionInfo {
PotionDescriptionId description_id;
};
struct PerceivedBookInfo {
BookDescriptionId description_id;
};
struct PerceivedWeaponInfo {
WeaponId weapon_id;
};
struct PerceivedLife {
SpeciesId species_id;
};
class PerceivedThingImpl : public ReferenceCounted {
public:
uint256 id;
bool is_placeholder;
ThingType thing_type;
Coord location = Coord::nowhere();
uint256 container_id = uint256::zero();
int z_order = 0;
int64_t last_seen_time;
List<StatusEffect> status_effects;
// individual
PerceivedThingImpl(uint256 id, bool is_placeholder, SpeciesId species_id, int64_t last_seen_time) :
id(id), is_placeholder(is_placeholder), thing_type(ThingType_INDIVIDUAL), last_seen_time(last_seen_time) {
assert(id != uint256::zero());
_life = create<PerceivedLife>();
_life->species_id = species_id;
}
// wand
PerceivedThingImpl(uint256 id, bool is_placeholder, WandDescriptionId description_id, int64_t last_seen_time) :
id(id), is_placeholder(is_placeholder), thing_type(ThingType_WAND), last_seen_time(last_seen_time) {
_wand_info = create<PerceivedWandInfo>();
_wand_info->description_id = description_id;
_wand_info->used_count = 0;
}
// potion
PerceivedThingImpl(uint256 id, bool is_placeholder, PotionDescriptionId description_id, int64_t last_seen_time) :
id(id), is_placeholder(is_placeholder), thing_type(ThingType_POTION), last_seen_time(last_seen_time) {
_potion_info = create<PerceivedPotionInfo>();
_potion_info->description_id = description_id;
}
// book
PerceivedThingImpl(uint256 id, bool is_placeholder, BookDescriptionId description_id, int64_t last_seen_time) :
id(id), is_placeholder(is_placeholder), thing_type(ThingType_BOOK), last_seen_time(last_seen_time) {
_book_info = create<PerceivedBookInfo>();
_book_info->description_id = description_id;
}
// weapon
PerceivedThingImpl(uint256 id, bool is_placeholder, WeaponId weapon_id, int64_t last_seen_time) :
id(id), is_placeholder(is_placeholder), thing_type(ThingType_WEAPON), last_seen_time(last_seen_time) {
_weapon_info = create<PerceivedWeaponInfo>();
_weapon_info->weapon_id = weapon_id;
}
~PerceivedThingImpl() {
switch (thing_type) {
case ThingType_INDIVIDUAL:
destroy(_life, 1);
break;
case ThingType_WAND:
destroy(_wand_info, 1);
break;
case ThingType_POTION:
destroy(_potion_info, 1);
break;
case ThingType_BOOK:
destroy(_book_info, 1);
break;
case ThingType_WEAPON:
destroy(_weapon_info, 1);
break;
case ThingType_COUNT:
unreachable();
}
}
PerceivedLife * life() {
assert_str(thing_type == ThingType_INDIVIDUAL, "wrong type");
return _life;
}
PerceivedWandInfo * wand_info() {
assert_str(thing_type == ThingType_WAND, "wrong type");
return _wand_info;
}
PerceivedPotionInfo * potion_info() {
assert_str(thing_type == ThingType_POTION, "wrong type");
return _potion_info;
}
PerceivedBookInfo * book_info() {
assert_str(thing_type == ThingType_BOOK, "wrong type");
return _book_info;
}
PerceivedWeaponInfo * weapon_info() {
assert_str(thing_type == ThingType_WEAPON, "wrong type");
return _weapon_info;
}
private:
union {
PerceivedLife * _life;
PerceivedWandInfo * _wand_info;
PerceivedPotionInfo * _potion_info;
PerceivedBookInfo * _book_info;
PerceivedWeaponInfo * _weapon_info;
};
};
typedef Reference<PerceivedThingImpl> PerceivedThing;
struct RememberedEventImpl : public ReferenceCounted {
Span span = new_span();
};
typedef Reference<RememberedEventImpl> RememberedEvent;
struct Knowledge {
// terrain knowledge
MapMatrix<TileType> tiles;
MapMatrix<uint8_t> aesthetic_indexes;
MapMatrix<VisionTypes> tile_is_visible;
List<RememberedEvent> remembered_events;
// incremented whenever events were forgotten, which means we need to blank out and refresh the rendering of the events.
int event_forget_counter = 0;
// these are never wrong
WandId wand_identities[WandDescriptionId_COUNT];
PotionId potion_identities[PotionDescriptionId_COUNT];
BookId book_identities[BookDescriptionId_COUNT];
IdMap<PerceivedThing> perceived_things;
Knowledge() {
reset_map();
for (int i = 0; i < WandDescriptionId_COUNT; i++)
wand_identities[i] = WandId_UNKNOWN;
for (int i = 0; i < PotionDescriptionId_COUNT; i++)
potion_identities[i] = PotionId_UNKNOWN;
for (int i = 0; i < BookDescriptionId_COUNT; i++)
book_identities[i] = BookId_UNKNOWN;
}
void reset_map() {
tiles.set_all(TileType_UNKNOWN);
aesthetic_indexes.set_all(0);
tile_is_visible.set_all(0);
}
};
static inline int experience_to_level(int experience) {
return log2(experience);
}
// the lowest experience for this level
static inline int level_to_experience(int level) {
return 1 << level;
}
struct Life {
SpeciesId original_species_id;
int hitpoints;
int64_t hp_regen_deadline;
int mana;
int64_t mp_regen_deadline;
int experience = 0;
int64_t last_movement_time = 0;
int64_t last_action_time = 0;
bool can_dodge = false;
uint256 initiative;
DecisionMakerType decision_maker;
Knowledge knowledge;
};
static inline int find_status(const List<StatusEffect> & status_effects, StatusEffect::Id status) {
for (int i = 0; i < status_effects.length(); i++)
if (status_effects[i].type == status)
return i;
return -1;
}
struct WandInfo {
WandId wand_id;
int charges;
};
struct PotionInfo {
PotionId potion_id;
};
struct BookInfo {
BookId book_id;
};
struct WeaponInfo {
WeaponId weapon_id;
};
class ThingImpl : public ReferenceCounted {
public:
const uint256 id;
const ThingType thing_type;
// this is set to false in the time between actually being destroyed and being removed from the master list
bool still_exists = true;
Coord location = Coord::nowhere();
uint256 container_id = uint256::zero();
int z_order = 0;
List<StatusEffect> status_effects;
List<AbilityCooldown> ability_cooldowns;
// individual
ThingImpl(uint256 id, SpeciesId species_id, DecisionMakerType decision_maker, uint256 initiative);
// wand
ThingImpl(uint256 id, WandId wand_id, int charges);
// potion
ThingImpl(uint256 id, PotionId potion_id);
// book
ThingImpl(uint256 id, BookId book_id);
// weapon
ThingImpl(uint256 id, WeaponId weapon_id);
~ThingImpl() {
switch (thing_type) {
case ThingType_INDIVIDUAL:
destroy(_life, 1);
break;
case ThingType_WAND:
destroy(_wand_info, 1);
break;
case ThingType_POTION:
destroy(_potion_info, 1);
break;
case ThingType_BOOK:
destroy(_book_info, 1);
break;
case ThingType_WEAPON:
destroy(_weapon_info, 1);
break;
case ThingType_COUNT:
unreachable();
}
}
Life * life() {
assert(thing_type == ThingType_INDIVIDUAL);
return _life;
}
const Life * life() const {
assert(thing_type == ThingType_INDIVIDUAL);
return _life;
}
WandInfo * wand_info() {
assert(thing_type == ThingType_WAND);
return _wand_info;
}
PotionInfo * potion_info() {
assert(thing_type == ThingType_POTION);
return _potion_info;
}
BookInfo * book_info() {
assert(thing_type == ThingType_BOOK);
return _book_info;
}
WeaponInfo * weapon_info() {
assert(thing_type == ThingType_WEAPON);
return _weapon_info;
}
// these are only valid for individuals
const Species * mental_species() const {
return &specieses[life()->original_species_id];
}
SpeciesId physical_species_id() const {
const Life * life = this->life(); // assert now
int index = find_status(status_effects, StatusEffect::POLYMORPH);
if (index == -1)
return life->original_species_id;
return status_effects[index].species_id;
}
const Species * physical_species() const {
return &specieses[physical_species_id()];
}
int experience_level() const {
return experience_to_level(life()->experience);
}
int next_level_up() const {
return level_to_experience(experience_level() + 1);
}
int innate_attack_power() const {
return max(1, physical_species()->base_attack_power + experience_level() / 2);
}
int max_hitpoints() const {
return physical_species()->base_hitpoints + 2 * experience_level();
}
int max_mana() const {
return mental_species()->base_mana * (experience_level() + 1);
}
private:
union {
Life * _life;
WandInfo * _wand_info;
PotionInfo * _potion_info;
BookInfo * _book_info;
WeaponInfo * _weapon_info;
};
ThingImpl(ThingImpl &) = delete;
ThingImpl & operator=(ThingImpl &) = delete;
};
typedef Reference<ThingImpl> Thing;
static inline int compare_individuals_by_initiative(const Thing & a, const Thing & b) {
return compare(a->life()->initiative, b->life()->initiative);
}
static inline int compare_things_by_id(const Thing & a, const Thing & b) {
return compare(a->id, b->id);
}
static inline int compare_perceived_things_by_id(const PerceivedThing & a, const PerceivedThing & b) {
return compare(a->id, b->id);
}
static inline int compare_things_by_location(const Thing & a, const Thing & b) {
int result;
if ((result = compare(a->location, b->location)) != 0)
return result;
if ((result = compare(a->container_id, b->container_id)) != 0)
return result;
if ((result = compare(a->z_order, b->z_order)) != 0)
return result;
return 0;
}
// TODO: these are in the wrong place
void see_aesthetics(Thing observer);
void compute_vision(Thing observer);
static inline bool individual_has_mind(Thing thing) {
switch (thing->mental_species()->mind) {
case Mind_NONE:
return false;
case Mind_BEAST:
case Mind_SAVAGE:
case Mind_CIVILIZED:
return true;
}
unreachable();
}
static inline bool immune_to_poison(Thing individual) {
return individual->physical_species()->poison_attack;
}
static inline bool can_have_status(Thing individual, StatusEffect::Id status) {
switch (status) {
case StatusEffect::CONFUSION:
return individual_has_mind(individual);
case StatusEffect::SPEED:
// this is everything
return individual->physical_species()->movement_cost != speedy_movement_cost;
case StatusEffect::SLOWING:
// if you're already moving at the slow speed, you can't tell if it gets worse
return individual->physical_species()->movement_cost != slow_movement_cost;
case StatusEffect::BLINDNESS:
// you need normal vision to be blind
return individual->physical_species()->vision_types & VisionTypes_NORMAL;
case StatusEffect::ETHEREAL_VISION:
// if you have ethereal vision anyway, you can't get it again
return !(individual->physical_species()->vision_types & VisionTypes_ETHEREAL);
case StatusEffect::LEVITATING:
return !individual->physical_species()->flying;
case StatusEffect::POISON:
return !immune_to_poison(individual);
case StatusEffect::COGNISCOPY:
case StatusEffect::INVISIBILITY:
case StatusEffect::POLYMORPH:
case StatusEffect::BURROWING:
return true;
case StatusEffect::PUSHED:
// this is only used to track who is responsible
return false;
case StatusEffect::COUNT:
unreachable();
}
unreachable();
}
static inline StatusEffect * find_or_put_status(Thing thing, StatusEffect::Id status, int64_t expiration_time) {
int index = find_status(thing->status_effects, status);
if (index == -1) {
index = thing->status_effects.length();
thing->status_effects.append(StatusEffect { status, expiration_time, -1, uint256::zero(), SpeciesId_COUNT, Coord{0, 0} });
} else {
thing->status_effects[index].expiration_time = expiration_time;
}
return &thing->status_effects[index];
}
static inline bool has_status(const List<StatusEffect> & status_effects, StatusEffect::Id status) {
return find_status(status_effects, status) != -1;
}
static inline bool has_status(Thing thing, StatusEffect::Id status) {
return can_have_status(thing, status) && has_status(thing->status_effects, status);
}
static inline bool has_status(PerceivedThing thing, StatusEffect::Id status) {
return has_status(thing->status_effects, status);
}
static inline StatusEffect * find_or_put_status(PerceivedThing thing, StatusEffect::Id status) {
int index = find_status(thing->status_effects, status);
if (index == -1) {
index = thing->status_effects.length();
thing->status_effects.append(StatusEffect { status, -1, -1, uint256::zero(), SpeciesId_COUNT, Coord{0, 0} });
}
return &thing->status_effects[index];
}
static inline bool maybe_remove_status(List<StatusEffect> * status_effects, StatusEffect::Id status) {
int index = find_status(*status_effects, status);
if (index != -1) {
status_effects->swap_remove(index);
return true;
}
return false;
}
DEFINE_GDB_PY_SCRIPT("debug-scripts/vision_types.py")
#endif