-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
player.cc
8295 lines (6925 loc) · 229 KB
/
player.cc
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
* @brief Player related functions.
**/
#include "AppHdr.h"
#include "player.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include "ability.h"
#include "abyss.h"
#include "act-iter.h"
#include "areas.h"
#include "art-enum.h"
#include "attack.h"
#include "bloodspatter.h"
#include "branch.h"
#include "chardump.h"
#include "cloud.h"
#include "coordit.h"
#include "delay.h"
#include "dgn-overview.h"
#include "dgn-event.h"
#include "directn.h"
#include "english.h"
#include "env.h"
#include "tile-env.h"
#include "errors.h"
#include "exercise.h"
#include "files.h"
#include "god-abil.h"
#include "god-conduct.h"
#include "god-passive.h"
#include "god-wrath.h"
#include "hints.h"
#include "hiscores.h"
#include "invent.h"
#include "item-prop.h"
#include "items.h"
#include "item-use.h"
#include "kills.h"
#include "level-state-type.h"
#include "libutil.h"
#include "macro.h"
#include "melee-attack.h"
#include "message.h"
#include "mon-place.h"
#include "movement.h"
#include "mutation.h"
#include "nearby-danger.h"
#include "notes.h"
#include "output.h"
#include "player-equip.h"
#include "player-save-info.h"
#include "player-stats.h"
#include "prompt.h"
#include "religion.h"
#include "shout.h"
#include "skills.h"
#include "species.h" // random_starting_species
#include "spl-damage.h"
#include "spl-selfench.h"
#include "spl-summoning.h"
#include "spl-transloc.h"
#include "spl-util.h"
#include "sprint.h"
#include "stairs.h"
#include "stash.h"
#include "state.h"
#include "status.h"
#include "stepdown.h"
#include "stringutil.h"
#include "tag-version.h"
#include "terrain.h"
#ifdef USE_TILE
#include "tilepick.h"
#include "tileview.h"
#endif
#include "transform.h"
#include "traps.h"
#include "travel.h"
#include "view.h"
#include "wizard-option-type.h"
#include "xom.h"
static void _pruneify()
{
if (!you.may_pruneify())
return;
mpr("The curse of the Prune overcomes you.");
did_god_conduct(DID_CHAOS, 10);
}
static void _moveto_maybe_repel_stairs()
{
const dungeon_feature_type new_grid = env.grid(you.pos());
const command_type stair_dir = feat_stair_direction(new_grid);
if (stair_dir == CMD_NO_CMD
|| new_grid == DNGN_ENTER_SHOP
|| !you.duration[DUR_REPEL_STAIRS_MOVE])
{
return;
}
int pct = you.duration[DUR_REPEL_STAIRS_CLIMB] ? 29 : 50;
// When the effect is still strong, the chance to actually catch
// a stair is smaller. (Assuming the duration starts out at 1000.)
const int dur = max(0, you.duration[DUR_REPEL_STAIRS_MOVE] - 700);
pct += dur/10;
if (x_chance_in_y(pct, 100))
{
const string stair_str = feature_description_at(you.pos(), false,
DESC_THE);
const string prep = feat_preposition(new_grid, true, &you);
if (slide_feature_over(you.pos()))
{
mprf("%s slides away as you move %s it!", stair_str.c_str(),
prep.c_str());
if (player_in_a_dangerous_place() && one_chance_in(5))
xom_is_stimulated(25);
}
}
}
bool check_moveto_cloud(const coord_def& p, const string &move_verb,
bool *prompted)
{
if (you.confused())
return true;
const cloud_type ctype = env.map_knowledge(p).cloud();
// Don't prompt if already in a cloud of the same type.
if (is_damaging_cloud(ctype, true, cloud_is_yours_at(p))
&& ctype != cloud_type_at(you.pos())
&& !crawl_state.disables[DIS_CONFIRMATIONS])
{
// Don't prompt for steam unless we're at uncomfortably low hp.
if (ctype == CLOUD_STEAM)
{
int threshold = 20;
if (player_res_steam(false) < 0)
threshold = threshold * 3 / 2;
threshold = threshold * you.time_taken / BASELINE_DELAY;
// Do prompt if we'd lose icemail, though.
if (you.hp > threshold && !you.has_mutation(MUT_CONDENSATION_SHIELD))
return true;
}
// Don't prompt for meph if we have clarity, unless at very low HP.
if (ctype == CLOUD_MEPHITIC && you.clarity(false)
&& you.hp > 2 * you.time_taken / BASELINE_DELAY)
{
return true;
}
if (prompted)
*prompted = true;
string prompt = make_stringf("Really %s into that cloud of %s?",
move_verb.c_str(),
cloud_type_name(ctype).c_str());
learned_something_new(HINT_CLOUD_WARNING);
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
return true;
}
bool check_moveto_trap(const coord_def& p, const string &move_verb,
bool *prompted)
{
// Boldly go into the unknown (for shadow step and other ranged move
// prompts)
if (env.map_knowledge(p).trap() == TRAP_UNASSIGNED)
return true;
// If there's no trap, let's go.
trap_def* trap = trap_at(p);
if (!trap)
return true;
if (trap->type == TRAP_ZOT && !trap->is_safe() && !crawl_state.disables[DIS_CONFIRMATIONS])
{
string msg = "Do you really want to %s into the Zot trap?";
string prompt = make_stringf(msg.c_str(), move_verb.c_str());
if (prompted)
*prompted = true;
if (!yes_or_no("%s", prompt.c_str()))
{
canned_msg(MSG_OK);
return false;
}
}
else if (!trap->is_safe() && !crawl_state.disables[DIS_CONFIRMATIONS])
{
string prompt;
if (prompted)
*prompted = true;
prompt = make_stringf("Really %s %s that %s?", move_verb.c_str(),
(trap->type == TRAP_ALARM
|| trap->type == TRAP_PLATE) ? "onto"
: "into",
feature_description_at(p, false, DESC_BASENAME).c_str());
if (!yesno(prompt.c_str(), true, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
return true;
}
static bool _check_moveto_dangerous(const coord_def& p, const string& msg)
{
if (you.can_swim() && feat_is_water(env.grid(p))
|| you.airborne() || !is_feat_dangerous(env.grid(p)))
{
return true;
}
if (!msg.empty())
mpr(msg);
else if (species::likes_water(you.species) && feat_is_water(env.grid(p)))
{
// player normally likes water, but is in a form that doesn't
mpr("You cannot enter water in your current form.");
}
else
canned_msg(MSG_UNTHINKING_ACT);
return false;
}
bool check_moveto_terrain(const coord_def& p, const string &move_verb,
const string &msg, bool *prompted)
{
// Boldly go into the unknown (for shadow step and other ranged move
// prompts)
if (!env.map_knowledge(p).known())
return true;
if (!_check_moveto_dangerous(p, msg))
return false;
if (!you.airborne() && !you.duration[DUR_NOXIOUS_BOG]
&& env.grid(you.pos()) != DNGN_TOXIC_BOG
&& env.grid(p) == DNGN_TOXIC_BOG)
{
string prompt;
if (prompted)
*prompted = true;
if (!msg.empty())
prompt = msg + " ";
prompt += "Are you sure you want to " + move_verb
+ " into a toxic bog?";
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
if (!need_expiration_warning() && need_expiration_warning(p)
&& !crawl_state.disables[DIS_CONFIRMATIONS])
{
string prompt;
if (prompted)
*prompted = true;
if (!msg.empty())
prompt = msg + " ";
prompt += "Are you sure you want to " + move_verb;
if (you.ground_level())
prompt += " into ";
else
prompt += " over ";
prompt += env.grid(p) == DNGN_DEEP_WATER ? "deep water" : "lava";
prompt += need_expiration_warning(DUR_FLIGHT, p)
? " while you are losing your buoyancy?"
: " while your transformation is expiring?";
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
return true;
}
bool check_moveto_exclusions(const vector<coord_def> &areas,
const string &move_verb,
bool *prompted)
{
const bool you_pos_excluded = is_excluded(you.pos())
&& !is_stair_exclusion(you.pos());
if (you_pos_excluded || crawl_state.disables[DIS_CONFIRMATIONS])
return true;
int count = 0;
for (auto p : areas)
{
if (is_excluded(p) && !is_stair_exclusion(p))
count++;
}
if (count == 0)
return true;
const string prompt = make_stringf((count == (int) areas.size() ?
"Really %s into a travel-excluded area?" :
"You might %s into a travel-excluded area, are you sure?"),
move_verb.c_str());
if (prompted)
*prompted = true;
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
return true;
}
bool check_moveto_exclusion(const coord_def& p, const string &move_verb,
bool *prompted)
{
return check_moveto_exclusions({p}, move_verb, prompted);
}
/**
* Confirm that the player really does want to go to the indicated place.
* May give many prompts, or no prompts if the move is safe.
*
* @param p The location the player wants to go to
* @param move_verb The method of locomotion the player is using
* @param physically Whether the player is considered to be "walking" for the
* purposes of barbs causing damage and ice spells expiring
* @return If true, continue with the move, otherwise cancel it
*/
bool check_moveto(const coord_def& p, const string &move_verb, bool physically)
{
return !(physically && cancel_harmful_move(physically, move_verb == "rampage"))
&& check_moveto_terrain(p, move_verb, "")
&& check_moveto_cloud(p, move_verb)
&& check_moveto_trap(p, move_verb)
&& check_moveto_exclusion(p, move_verb);
}
// Returns true if this is a valid swap for this monster. If true, then
// the valid location is set in loc. (Otherwise loc becomes garbage.)
bool swap_check(monster* mons, coord_def &loc, bool quiet)
{
loc = you.pos();
if (you.is_stationary())
return false;
// Don't move onto dangerous terrain.
if (is_feat_dangerous(env.grid(mons->pos())))
{
canned_msg(MSG_UNTHINKING_ACT);
return false;
}
if (mons_is_projectile(*mons))
{
if (!quiet)
mpr("It's unwise to walk into this.");
return false;
}
if (mons->caught())
{
if (!quiet)
{
simple_monster_message(*mons,
make_stringf(" is %s!", held_status(mons)).c_str());
}
return false;
}
if (mons->is_constricted())
{
if (!quiet)
simple_monster_message(*mons, " is being constricted!");
return false;
}
if (mons->is_stationary() || mons->asleep() || mons->cannot_act())
{
if (!quiet)
simple_monster_message(*mons, " cannot move out of your way!");
return false;
}
// prompt when swapping into known zot traps
if (!quiet && trap_at(loc) && trap_at(loc)->type == TRAP_ZOT
&& !yes_or_no("Do you really want to swap %s into the Zot trap?",
mons->name(DESC_YOUR).c_str()))
{
return false;
}
// First try: move monster onto your position.
bool swap = !monster_at(loc) && monster_habitable_grid(mons, env.grid(loc));
// Choose an appropriate habitat square at random around the target.
if (!swap)
{
int num_found = 0;
for (adjacent_iterator ai(mons->pos()); ai; ++ai)
if (!monster_at(*ai) && monster_habitable_grid(mons, env.grid(*ai))
&& one_chance_in(++num_found))
{
loc = *ai;
}
if (num_found)
swap = true;
}
if (!swap && !quiet)
{
// Might not be ideal, but it's better than insta-killing
// the monster... maybe try for a short blink instead? - bwr
simple_monster_message(*mons, " cannot make way for you.");
// FIXME: activity_interrupt::hit_monster isn't ideal.
interrupt_activity(activity_interrupt::hit_monster, mons);
}
return swap;
}
static void _splash()
{
if (you.can_swim())
noisy(4, you.pos(), "Floosh!");
else if (!you.can_water_walk())
noisy(8, you.pos(), "Splash!");
}
void moveto_location_effects(dungeon_feature_type old_feat,
bool stepped, const coord_def& old_pos)
{
const dungeon_feature_type new_grid = env.grid(you.pos());
// Terrain effects.
if (is_feat_dangerous(new_grid))
fall_into_a_pool(new_grid);
// called after fall_into_a_pool, in case of emergency untransform
if (you.has_innate_mutation(MUT_MERTAIL))
merfolk_check_swimming(stepped);
if (you.ground_level())
{
if (feat_is_water(new_grid))
{
if (!stepped)
_splash();
if (!you.can_swim() && !you.can_water_walk())
{
if (!feat_is_water(old_feat))
{
if (new_grid == DNGN_TOXIC_BOG)
{
mprf("You %s the toxic bog.",
stepped ? "enter" : "fall into");
}
else
{
mprf("You %s the %s water.",
stepped ? "enter" : "fall into",
new_grid == DNGN_SHALLOW_WATER ? "shallow"
: "deep");
}
}
if (new_grid == DNGN_DEEP_WATER && old_feat != DNGN_DEEP_WATER)
mpr("You sink to the bottom.");
if (!feat_is_water(old_feat))
{
mpr("Moving in this stuff is going to be slow.");
if (you.invisible())
mpr("...and don't expect to remain undetected.");
}
}
if ((you.can_swim() || you.extra_balanced())
&& !feat_is_water(old_feat)
&& you.invisible())
{
mpr("Don't expect to remain undetected while in the water.");
}
}
else if (you.props.exists(TEMP_WATERWALK_KEY))
you.props.erase(TEMP_WATERWALK_KEY);
}
id_floor_items();
// Falling into a toxic bog, take the damage
if (old_pos == you.pos() && stepped)
actor_apply_toxic_bog(&you);
// Traps go off.
// (But not when losing flight - i.e., moving into the same tile)
trap_def* ptrap = trap_at(you.pos());
if (ptrap && old_pos != you.pos())
ptrap->trigger(you);
if (stepped)
_moveto_maybe_repel_stairs();
bool was_running = you.running;
update_monsters_in_view();
maybe_update_stashes();
if (check_for_interesting_features() && you.running.is_explore())
stop_running();
// If travel was interrupted, we need to add the last step
// to the travel trail.
if (was_running && !you.running)
env.travel_trail.push_back(you.pos());
}
// Use this function whenever the player enters (or lands and thus re-enters)
// a grid.
//
// stepped - normal walking moves
void move_player_to_grid(const coord_def& p, bool stepped)
{
ASSERT(!crawl_state.game_is_arena());
ASSERT_IN_BOUNDS(p);
// assuming that entering the same square means coming from above (flight)
const coord_def old_pos = you.pos();
const bool from_above = (old_pos == p);
const dungeon_feature_type old_grid =
(from_above) ? DNGN_FLOOR : env.grid(old_pos);
// Really must be clear.
ASSERT(you.can_pass_through_feat(env.grid(p)));
// Better not be an unsubmerged monster either.
ASSERT(!monster_at(p) || monster_at(p)->submerged()
|| fedhas_passthrough(monster_at(p))
|| mons_is_player_shadow(*monster_at(p))
|| mons_is_wrath_avatar(*monster_at(p)));
// Move the player to new location.
you.moveto(p, true);
viewwindow();
update_screen();
moveto_location_effects(old_grid, stepped, old_pos);
}
/**
* Check if the given terrain feature is safe for the player to move into.
* (Or, at least, not instantly lethal.)
*
* @param grid The type of terrain feature under consideration.
* @param permanently Whether to disregard temporary effects (non-permanent
* flight, forms, etc)
* @param ignore_flight Whether to ignore all forms of flight (including
* permanent flight)
* @return Whether the terrain is safe.
*/
bool is_feat_dangerous(dungeon_feature_type grid, bool permanently,
bool ignore_flight)
{
if (!ignore_flight
&& (you.permanent_flight() || you.airborne() && !permanently))
{
return false;
}
else if (grid == DNGN_DEEP_WATER && !player_likes_water(permanently)
|| grid == DNGN_LAVA)
{
return true;
}
else
return false;
}
bool is_map_persistent()
{
return !testbits(your_branch().branch_flags, brflag::no_map)
|| env.properties.exists(FORCE_MAPPABLE_KEY);
}
bool player_in_hell(bool vestibule)
{
return vestibule ? is_hell_branch(you.where_are_you) :
is_hell_subbranch(you.where_are_you);
}
/**
* Is the player in the slightly-special version of the abyss that AKs start
* in?
*/
bool player_in_starting_abyss()
{
return you.chapter == CHAPTER_POCKET_ABYSS
&& player_in_branch(BRANCH_ABYSS) && you.depth <= 1;
}
bool player_in_connected_branch()
{
return is_connected_branch(you.where_are_you);
}
bool player_likes_water(bool permanently)
{
return !permanently && you.can_water_walk()
|| (species::likes_water(you.species) || !permanently)
&& form_likes_water();
}
/**
* Is the player considered to be closely related, if not the same species, to
* the given monster? (See mon-data.h for species/genus info.)
*
* @param mon The type of monster to be compared.
* @return Whether the player's species is related to the one given.
*/
bool is_player_same_genus(const monster_type mon)
{
return mons_genus(mon) == mons_genus(player_mons(false));
}
void update_player_symbol()
{
you.symbol = Options.show_player_species ? player_mons() : transform_mons();
}
monster_type player_mons(bool transform)
{
monster_type mons;
if (transform)
{
mons = transform_mons();
if (mons != MONS_PLAYER)
return mons;
}
mons = you.mons_species();
if (mons == MONS_ORC)
{
if (you_worship(GOD_BEOGH))
{
mons = (you.piety >= piety_breakpoint(4)) ? MONS_ORC_HIGH_PRIEST
: MONS_ORC_PRIEST;
}
}
else if (mons == MONS_OGRE)
{
const skill_type sk = best_skill(SK_FIRST_SKILL, SK_LAST_SKILL);
if (sk >= SK_SPELLCASTING && sk <= SK_LAST_MAGIC)
mons = MONS_OGRE_MAGE;
}
return mons;
}
void update_vision_range()
{
you.normal_vision = LOS_DEFAULT_RANGE;
// Daystalker gives +1 base LOS. (currently capped to one level for
// console reasons, a modular hud might someday permit more levels)
if (you.get_mutation_level(MUT_DAYSTALKER))
you.normal_vision += you.get_mutation_level(MUT_DAYSTALKER);
// Nightstalker gives -1/-2/-3 to base LOS.
if (you.get_mutation_level(MUT_NIGHTSTALKER))
you.normal_vision -= you.get_mutation_level(MUT_NIGHTSTALKER);
// Halo and umbra radius scale with you.normal_vision, so to avoid
// penalizing players with low LOS from items, don't shrink normal_vision.
you.current_vision = you.normal_vision;
// scarf of shadows gives -1.
if (you.wearing_ego(EQ_CLOAK, SPARM_SHADOWS))
you.current_vision -= 1;
// robe of Night.
if (player_equip_unrand(UNRAND_NIGHT))
you.current_vision = you.current_vision * 3 / 4;
ASSERT(you.current_vision > 0);
set_los_radius(you.current_vision);
}
/**
* Ignoring form & most equipment, but not the UNRAND_FINGER_AMULET, can the
* player use (usually wear) a given equipment slot?
*
* @param eq The slot in question.
* @param temp Whether to consider forms.
* @return MB_FALSE if the player can never use the slot;
* MB_MAYBE if the player can only use some items for the slot;
* MB_TRUE if the player can use any (fsvo any) item for the slot.
*/
maybe_bool you_can_wear(equipment_type eq, bool temp)
{
if (temp && !get_form()->slot_available(eq))
return MB_FALSE;
// handles incorrect ring slots vs species
if (species::bans_eq(you.species, eq))
return MB_FALSE;
switch (eq)
{
case EQ_RING_EIGHT:
case EQ_LEFT_RING:
if (you.get_mutation_level(MUT_MISSING_HAND))
return MB_FALSE;
// intentional fallthrough
case EQ_RIGHT_RING:
case EQ_RING_ONE:
case EQ_RING_TWO:
case EQ_RING_THREE:
case EQ_RING_FOUR:
case EQ_RING_FIVE:
case EQ_RING_SIX:
case EQ_RING_SEVEN:
return MB_TRUE;
case EQ_WEAPON:
case EQ_STAFF:
return you.has_mutation(MUT_NO_GRASPING) ? MB_FALSE :
you.body_size(PSIZE_TORSO, !temp) < SIZE_MEDIUM ? MB_MAYBE :
MB_TRUE;
// You can always wear at least one ring (forms were already handled).
case EQ_RINGS:
case EQ_ALL_ARMOUR:
case EQ_AMULET:
return MB_TRUE;
case EQ_RING_AMULET:
return player_equip_unrand(UNRAND_FINGER_AMULET) ? MB_TRUE : MB_FALSE;
default:
break;
}
item_def dummy, alternate;
dummy.base_type = alternate.base_type = OBJ_ARMOUR;
dummy.sub_type = alternate.sub_type = NUM_ARMOURS;
// Make sure can_wear_armour doesn't think it's Lear's.
dummy.unrand_idx = alternate.unrand_idx = 0;
switch (eq)
{
case EQ_CLOAK:
dummy.sub_type = ARM_CLOAK;
alternate.sub_type = ARM_SCARF;
break;
case EQ_GLOVES:
dummy.sub_type = ARM_GLOVES;
break;
case EQ_BOOTS: // And bardings
dummy.sub_type = ARM_BOOTS;
if (you.wear_barding())
alternate.sub_type = ARM_BARDING;
break;
case EQ_BODY_ARMOUR:
// Assume that anything that can wear any armour at all can wear a robe
// and that anything that can wear CPA can wear all armour.
dummy.sub_type = ARM_CRYSTAL_PLATE_ARMOUR;
alternate.sub_type = ARM_ROBE;
break;
case EQ_SHIELD:
// Assume that anything that can use an orb can wear some kind of
// shield
dummy.sub_type = ARM_ORB;
break;
case EQ_HELMET:
dummy.sub_type = ARM_HELMET;
alternate.sub_type = ARM_HAT;
break;
default:
die("unhandled equipment type %d", eq);
break;
}
ASSERT(dummy.sub_type != NUM_ARMOURS);
if (can_wear_armour(dummy, false, !temp))
return MB_TRUE;
else if (alternate.sub_type != NUM_ARMOURS
&& can_wear_armour(alternate, false, !temp))
{
return MB_MAYBE;
}
else
return MB_FALSE;
}
bool player_has_feet(bool temp, bool include_mutations)
{
if (you.has_innate_mutation(MUT_CONSTRICTING_TAIL)
|| you.has_innate_mutation(MUT_FLOAT)
|| you.has_innate_mutation(MUT_PAWS) // paws are not feet?
|| you.has_tentacles(temp)
|| you.fishtail && temp)
{
return false;
}
if (include_mutations &&
(you.get_mutation_level(MUT_HOOVES, temp) == 3
|| you.get_mutation_level(MUT_TALONS, temp) == 3))
{
return false;
}
return true;
}
// Returns false if the player is wielding a weapon inappropriate for Berserk.
bool berserk_check_wielded_weapon()
{
const item_def * const wpn = you.weapon();
bool penance = false;
if (wpn && wpn->defined()
&& (!is_melee_weapon(*wpn)
|| needs_handle_warning(*wpn, OPER_ATTACK, penance)))
{
string prompt = "Do you really want to go berserk while wielding "
+ wpn->name(DESC_YOUR) + "?";
if (penance)
prompt += " This could place you under penance!";
if (!yesno(prompt.c_str(), true, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
return true;
}
// Looks in equipment "slot" to see if there is an equipped "sub_type".
// Returns number of matches (in the case of rings, both are checked)
int player::wearing(equipment_type slot, int sub_type) const
{
int ret = 0;
const item_def* item;
switch (slot)
{
case EQ_WEAPON:
// Hands can have more than just weapons.
if (weapon() && weapon()->is_type(OBJ_WEAPONS, sub_type))
ret++;
break;
case EQ_STAFF:
// Like above, but must be magical staff.
if (weapon() && weapon()->is_type(OBJ_STAVES, sub_type))
ret++;
break;
case EQ_AMULET:
if ((item = slot_item(static_cast<equipment_type>(EQ_AMULET)))
&& item->sub_type == sub_type)
{
ret++;
}
break;
case EQ_RINGS:
case EQ_RINGS_PLUS:
for (int slots = EQ_FIRST_JEWELLERY; slots <= EQ_LAST_JEWELLERY; slots++)
{
if (slots == EQ_AMULET)
continue;
if ((item = slot_item(static_cast<equipment_type>(slots)))
&& item->sub_type == sub_type)
{
ret += (slot == EQ_RINGS_PLUS ? item->plus : 1);
}
}
break;
case EQ_ALL_ARMOUR:
// Doesn't make much sense here... be specific. -- bwr
die("EQ_ALL_ARMOUR is not a proper slot");
break;
default:
if (!(slot >= EQ_FIRST_EQUIP && slot < NUM_EQUIP))
die("invalid slot");
if ((item = slot_item(slot)) && item->sub_type == sub_type)
ret++;
break;
}
return ret;
}
// Looks in equipment "slot" to see if equipped item has "special" ego-type
// Returns number of matches (jewellery returns zero -- no ego type).
int player::wearing_ego(equipment_type slot, int special) const
{
int ret = 0;
const item_def* item;
switch (slot)
{
case EQ_WEAPON:
// Hands can have more than just weapons.
if ((item = slot_item(EQ_WEAPON))
&& item->base_type == OBJ_WEAPONS
&& get_weapon_brand(*item) == special)
{
ret++;
}
break;
case EQ_LEFT_RING:
case EQ_RIGHT_RING:
case EQ_AMULET:
case EQ_STAFF:
case EQ_RINGS:
case EQ_RINGS_PLUS:
// no ego types for these slots
break;
case EQ_ALL_ARMOUR:
// Check all armour slots:
for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_ARMOUR; i++)
{
if ((item = slot_item(static_cast<equipment_type>(i)))
&& get_armour_ego_type(*item) == special)
{
ret++;
}
}
break;
default:
if (slot < EQ_MIN_ARMOUR || slot > EQ_MAX_ARMOUR)
die("invalid slot: %d", slot);
// Check a specific armour slot for an ego type:
if ((item = slot_item(static_cast<equipment_type>(slot)))
&& get_armour_ego_type(*item) == special)
{
ret++;
}
break;
}
return ret;
}