-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
item-use.cc
3340 lines (2901 loc) · 91.6 KB
/
item-use.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 Functions for making use of inventory items.
**/
#include "AppHdr.h"
#include "item-use.h"
#include "ability.h"
#include "acquire.h"
#include "act-iter.h"
#include "areas.h"
#include "artefact.h"
#include "art-enum.h"
#include "butcher.h"
#include "chardump.h"
#include "cloud.h"
#include "colour.h"
#include "coordit.h"
#include "database.h"
#include "decks.h"
#include "delay.h"
#include "describe.h"
#include "directn.h"
#include "english.h"
#include "env.h"
#include "evoke.h"
#include "exercise.h"
#include "food.h"
#include "god-abil.h"
#include "god-conduct.h"
#include "god-item.h"
#include "god-passive.h"
#include "hints.h"
#include "invent.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "items.h"
#include "level-state-type.h"
#include "libutil.h"
#include "macro.h"
#include "makeitem.h"
#include "message.h"
#include "misc.h"
#include "mon-behv.h"
#include "mutation.h"
#include "nearby-danger.h"
#include "orb.h"
#include "output.h"
#include "player-equip.h"
#include "player-stats.h"
#include "potion.h"
#include "prompt.h"
#include "religion.h"
#include "rot.h"
#include "shout.h"
#include "skills.h"
#include "sound.h"
#include "spl-book.h"
#include "spl-clouds.h"
#include "spl-goditem.h"
#include "spl-selfench.h"
#include "spl-summoning.h"
#include "spl-transloc.h"
#include "spl-wpnench.h"
#include "spl-zap.h"
#include "state.h"
#include "stringutil.h"
#include "target.h"
#include "terrain.h"
#include "throw.h"
#include "tiles-build-specific.h"
#include "transform.h"
#include "uncancel.h"
#include "unwind.h"
#include "view.h"
#include "xom.h"
// The menu class for using items from either inv or floor.
// Derivative of InvMenu
class UseItemMenu : public InvMenu
{
bool is_inventory = true;
void populate_list(int item_type);
void populate_menu();
bool process_key(int key) override;
public:
vector<const item_def*> item_inv;
vector<const item_def*> item_floor;
// Constructor
// Requires int for item filter.
// Accepts:
// OBJ_POTIONS
// OBJ_SCROLLS
UseItemMenu(int selector, const char* prompt);
void toggle();
};
UseItemMenu::UseItemMenu(int item_type, const char* prompt)
: InvMenu(MF_SINGLESELECT)
{
set_title(prompt);
populate_list(item_type);
populate_menu();
}
void UseItemMenu::populate_list(int item_type)
{
// Load inv items first
for (const auto &item : you.inv)
{
// Populate the vector with filter
if (item.defined() && item_is_selected(item, item_type))
item_inv.push_back(&item);
}
// Load floor items
item_floor = item_list_on_square(you.visible_igrd(you.pos()));
// Filter
erase_if(item_floor, [=](const item_def* item)
{
return !item_is_selected(*item,item_type);
});
}
void UseItemMenu::populate_menu()
{
if (item_inv.empty())
is_inventory = false;
else if (item_floor.empty())
is_inventory = true;
if (!item_inv.empty())
{
// Only clarify that these are inventory items if there are also floor
// items.
if (!item_floor.empty())
{
string subtitle_text = "Inventory Items";
if (!is_inventory)
subtitle_text += " (',' to select)";
auto subtitle = new MenuEntry(subtitle_text, MEL_TITLE);
subtitle->colour = LIGHTGREY;
add_entry(subtitle);
}
// nullptr means using the items' normal hotkeys
if (is_inventory)
load_items(item_inv);
else
{
load_items(item_inv,
[&](MenuEntry* entry) -> MenuEntry*
{
entry->hotkeys.clear();
return entry;
});
}
}
if (!item_floor.empty())
{
#ifndef USE_TILE
// vertical padding for console
if (!item_inv.empty())
add_entry(new MenuEntry("", MEL_TITLE));
#endif
// Load floor items to menu
string subtitle_text = "Floor Items";
if (is_inventory)
subtitle_text += " (',' to select)";
auto subtitle = new MenuEntry(subtitle_text, MEL_TITLE);
subtitle->colour = LIGHTGREY;
add_entry(subtitle);
// nullptr means using a-zA-Z
if (is_inventory)
{
load_items(item_floor,
[&](MenuEntry* entry) -> MenuEntry*
{
entry->hotkeys.clear();
return entry;
});
}
else
load_items(item_floor);
}
}
void UseItemMenu::toggle()
{
is_inventory = !is_inventory;
deleteAll(items);
populate_menu();
}
bool UseItemMenu::process_key(int key)
{
if (isadigit(key) || key == '*' || key == '\\' || key == ',')
{
lastch = key;
return false;
}
return Menu::process_key(key);
}
static string _weird_smell()
{
return getMiscString("smell_name");
}
static string _weird_sound()
{
return getMiscString("sound_name");
}
/**
* Prompt use of a consumable from either player inventory or the floor.
*
* This function generates a menu containing type_expect items based on the
* object_class_type to be acted on by another function. First it will list
* items in inventory, then items on the floor. If player cancels out of menu,
* nullptr is returned.
*
* @param item_type The object_class_type or OSEL_* of items to list.
* @param oper The operation being done to the selected item.
* @param prompt The prompt on the menu title
* @param allowcancel If the user tries to cancel out of the prompt, run this
* function. If it returns false, continue the prompt rather
* than returning null.
*
* @return a pointer to the chosen item, or nullptr if none was chosen.
*/
item_def* use_an_item(int item_type, operation_types oper, const char* prompt,
function<bool ()> allowcancel)
{
item_def* target = nullptr;
// First handle things that will return nullptr
// No selectable items in inv or floor
if (!any_items_of_type(item_type, -1, true))
{
mprf(MSGCH_PROMPT, "%s",
no_selectables_message(item_type).c_str());
return nullptr;
}
// Init the menu
UseItemMenu menu(item_type, prompt);
while (true)
{
vector<MenuEntry*> sel = menu.show(true);
int keyin = menu.getkey();
// Handle inscribed item keys
if (isadigit(keyin))
target = digit_inscription_to_item(keyin, oper);
// TODO: handle * key
else if (keyin == ',')
{
if (Options.easy_floor_use && menu.item_floor.size() == 1)
target = const_cast<item_def*>(menu.item_floor[0]);
else
{
menu.toggle();
continue;
}
}
else if (keyin == '\\')
{
check_item_knowledge();
continue;
}
else if (!sel.empty())
{
ASSERT(sel.size() == 1);
auto ie = dynamic_cast<InvEntry *>(sel[0]);
target = const_cast<item_def*>(ie->item);
}
redraw_screen();
if (target && !check_warning_inscriptions(*target, oper))
target = nullptr;
if (target)
return target;
else if (allowcancel())
{
prompt_failed(PROMPT_ABORT);
return nullptr;
}
else
continue;
}
}
static bool _safe_to_remove_or_wear(const item_def &item, bool remove,
bool quiet = false);
// Rather messy - we've gathered all the can't-wield logic from wield_weapon()
// here.
bool can_wield(const item_def *weapon, bool say_reason,
bool ignore_temporary_disability, bool unwield, bool only_known)
{
#define SAY(x) {if (say_reason) { x; }}
if (you.melded[EQ_WEAPON] && unwield)
{
SAY(mpr("Your weapon is melded into your body!"));
return false;
}
if (!ignore_temporary_disability && !form_can_wield(you.form))
{
SAY(mpr("You can't wield anything in your present form."));
return false;
}
if (!ignore_temporary_disability
&& you.weapon()
&& is_weapon(*you.weapon())
&& you.weapon()->cursed())
{
SAY(mprf("You can't unwield your weapon%s!",
!unwield ? " to draw a new one" : ""));
return false;
}
// If we don't have an actual weapon to check, return now.
if (!weapon)
return true;
if (you.get_mutation_level(MUT_MISSING_HAND)
&& you.hands_reqd(*weapon) == HANDS_TWO)
{
SAY(mpr("You can't wield that without your missing limb."));
return false;
}
for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; i++)
{
if (you.equip[i] != -1 && &you.inv[you.equip[i]] == weapon)
{
SAY(mpr("You are wearing that object!"));
return false;
}
}
if (!you.could_wield(*weapon, true, true, !say_reason))
return false;
// All non-weapons only need a shield check.
if (weapon->base_type != OBJ_WEAPONS)
{
if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
{
SAY(mpr("You can't wield that with a shield."));
return false;
}
else
return true;
}
bool id_brand = false;
if (you.undead_or_demonic() && is_holy_item(*weapon)
&& (item_type_known(*weapon) || !only_known))
{
if (say_reason)
{
mpr("This weapon is holy and will not allow you to wield it.");
id_brand = true;
}
else
return false;
}
else if (!ignore_temporary_disability
&& you.hunger_state < HS_FULL
&& get_weapon_brand(*weapon) == SPWPN_VAMPIRISM
&& you.undead_state() == US_ALIVE
&& !you_foodless()
&& (item_type_known(*weapon) || !only_known))
{
if (say_reason)
{
mpr("This weapon is vampiric, and you must be Full or above to equip it.");
id_brand = true;
}
else
return false;
}
if (id_brand)
{
auto wwpn = const_cast<item_def*>(weapon);
if (!is_artefact(*weapon) && !is_blessed(*weapon)
&& !item_type_known(*weapon))
{
set_ident_flags(*wwpn, ISFLAG_KNOW_TYPE);
if (in_inventory(*weapon))
mprf_nocap("%s", weapon->name(DESC_INVENTORY_EQUIP).c_str());
}
else if (is_artefact(*weapon) && !item_type_known(*weapon))
artefact_learn_prop(*wwpn, ARTP_BRAND);
return false;
}
if (!ignore_temporary_disability && is_shield_incompatible(*weapon))
{
SAY(mpr("You can't wield that with a shield."));
return false;
}
// We can wield this weapon. Phew!
return true;
#undef SAY
}
/**
* @param auto_wield true if this was initiated by the wield weapon command (w)
* false otherwise (e.g. switching between ranged and melee with the
* auto_switch option)
* @param slot Index into inventory of item to equip. Or one of following
* special values:
* - -1 (default): meaning no particular weapon. We'll either prompt for a
* choice of weapon (if auto_wield is false) or choose one by default.
* - SLOT_BARE_HANDS: equip nothing (unwielding current weapon, if any)
*/
bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages,
bool show_unwield_msg, bool show_wield_msg,
bool adjust_time_taken)
{
if (inv_count() < 1)
{
canned_msg(MSG_NOTHING_CARRIED);
return false;
}
// Look for conditions like berserking that could prevent wielding
// weapons.
if (!can_wield(nullptr, true, false, slot == SLOT_BARE_HANDS))
return false;
int item_slot = 0; // default is 'a'
if (auto_wield)
{
if (item_slot == you.equip[EQ_WEAPON]
|| you.equip[EQ_WEAPON] == -1
&& !item_is_wieldable(you.inv[item_slot]))
{
item_slot = 1; // backup is 'b'
}
if (slot != -1) // allow external override
item_slot = slot;
}
// If the swap slot has a bad (but valid) item in it,
// the swap will be to bare hands.
const bool good_swap = (item_slot == SLOT_BARE_HANDS
|| item_is_wieldable(you.inv[item_slot]));
// Prompt if not using the auto swap command, or if the swap slot
// is empty.
if (item_slot != SLOT_BARE_HANDS
&& (!auto_wield || !you.inv[item_slot].defined() || !good_swap))
{
if (!auto_wield)
{
item_slot = prompt_invent_item(
"Wield which item (- for none, * to show all)?",
MT_INVLIST, OSEL_WIELD,
OPER_WIELD, invprompt_flag::no_warning, '-');
}
else
item_slot = SLOT_BARE_HANDS;
}
if (prompt_failed(item_slot))
return false;
else if (item_slot == you.equip[EQ_WEAPON])
{
if (Options.equip_unequip)
item_slot = SLOT_BARE_HANDS;
else
{
mpr("You are already wielding that!");
return true;
}
}
// Reset the warning counter.
you.received_weapon_warning = false;
if (item_slot == SLOT_BARE_HANDS)
{
if (const item_def* wpn = you.weapon())
{
bool penance = false;
// Can we safely unwield this item?
if (needs_handle_warning(*wpn, OPER_WIELD, penance))
{
string prompt =
"Really unwield " + wpn->name(DESC_INVENTORY) + "?";
if (penance)
prompt += " This could place you under penance!";
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
// check if you'd get stat-zeroed
if (!_safe_to_remove_or_wear(*wpn, true))
return false;
if (!unwield_item(show_weff_messages))
return false;
if (show_unwield_msg)
{
#ifdef USE_SOUND
parse_sound(WIELD_NOTHING_SOUND);
#endif
canned_msg(MSG_EMPTY_HANDED_NOW);
}
// Switching to bare hands is extra fast.
you.turn_is_over = true;
if (adjust_time_taken)
{
you.time_taken *= 3;
you.time_taken /= 10;
}
}
else
canned_msg(MSG_EMPTY_HANDED_ALREADY);
return true;
}
item_def& new_wpn(you.inv[item_slot]);
// Switching to a launcher while berserk is likely a mistake.
if (you.berserk() && is_range_weapon(new_wpn))
{
string prompt = "You can't shoot while berserk! Really wield " +
new_wpn.name(DESC_INVENTORY) + "?";
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return false;
}
}
// Ensure wieldable
if (!can_wield(&new_wpn, true))
return false;
// Really ensure wieldable, even unknown brand
if (!can_wield(&new_wpn, true, false, false, false))
return false;
// At this point, we know it's possible to equip this item. However, there
// might be reasons it's not advisable.
if (!check_warning_inscriptions(new_wpn, OPER_WIELD)
|| !_safe_to_remove_or_wear(new_wpn, false))
{
canned_msg(MSG_OK);
return false;
}
// Unwield any old weapon.
if (you.weapon())
{
if (unwield_item(show_weff_messages))
{
// Enable skills so they can be re-disabled later
update_can_train();
}
else
return false;
}
const unsigned int old_talents = your_talents(false).size();
// Go ahead and wield the weapon.
equip_item(EQ_WEAPON, item_slot, show_weff_messages);
if (show_wield_msg)
{
#ifdef USE_SOUND
parse_sound(WIELD_WEAPON_SOUND);
#endif
mprf_nocap("%s", new_wpn.name(DESC_INVENTORY_EQUIP).c_str());
}
check_item_hint(new_wpn, old_talents);
// Time calculations.
if (adjust_time_taken)
you.time_taken /= 2;
you.wield_change = true;
you.m_quiver.on_weapon_changed();
you.turn_is_over = true;
return true;
}
bool item_is_worn(int inv_slot)
{
for (int i = EQ_MIN_ARMOUR; i <= EQ_MAX_WORN; ++i)
if (inv_slot == you.equip[i])
return true;
return false;
}
/**
* Prompt user for carried armour.
*
* @param mesg Title for the prompt
* @param index[out] the inventory slot of the item chosen; not initialised
* if a valid item was not chosen.
* @param oper if equal to OPER_TAKEOFF, only show items relevant to the 'T'
* command.
* @return whether a valid armour item was chosen.
*/
bool armour_prompt(const string & mesg, int *index, operation_types oper)
{
ASSERT(index != nullptr);
if (you.berserk())
canned_msg(MSG_TOO_BERSERK);
else
{
int selector = OBJ_ARMOUR;
if (oper == OPER_TAKEOFF && !Options.equip_unequip)
selector = OSEL_WORN_ARMOUR;
int slot = prompt_invent_item(mesg.c_str(), MT_INVLIST, selector, oper);
if (!prompt_failed(slot))
{
*index = slot;
return true;
}
}
return false;
}
/**
* The number of turns it takes to put on or take off a given piece of armour.
*
* @param item The armour in question.
* @return The number of turns it takes to don or doff the item.
*/
static int armour_equip_delay(const item_def &item)
{
return 5;
}
/**
* Can you wear this item of armour currently?
*
* Ignores whether or not an item is equipped in its slot already.
* If the item is Lear's hauberk, some of this comment may be incorrect.
*
* @param item The item. Only the base_type and sub_type really should get
* checked, since you_can_wear passes in a dummy item.
* @param verbose Whether to print a message about your inability to wear item.
* @param ignore_temporary Whether to take into account forms/fishtail/2handers.
* Note that no matter what this is set to, all
* mutations will be taken into account, except for
* ones from Beastly Appendage, which are only checked
* if this is false.
*/
bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary)
{
const object_class_type base_type = item.base_type;
if (base_type != OBJ_ARMOUR || you.species == SP_FELID)
{
if (verbose)
mpr("You can't wear that.");
return false;
}
const int sub_type = item.sub_type;
const equipment_type slot = get_armour_slot(item);
if (you.species == SP_OCTOPODE && slot != EQ_HELMET && slot != EQ_SHIELD)
{
if (verbose)
mpr("You can't wear that!");
return false;
}
if (species_is_draconian(you.species) && slot == EQ_BODY_ARMOUR)
{
if (verbose)
{
mprf("Your wings%s won't fit in that.", you.has_mutation(MUT_BIG_WINGS)
? "" : ", even vestigial as they are,");
}
return false;
}
if (sub_type == ARM_NAGA_BARDING || sub_type == ARM_CENTAUR_BARDING)
{
if (you.species == SP_NAGA && sub_type == ARM_NAGA_BARDING
|| you.species == SP_CENTAUR && sub_type == ARM_CENTAUR_BARDING)
{
if (ignore_temporary || !player_is_shapechanged())
return true;
else if (verbose)
mpr("You can wear that only in your normal form.");
}
else if (verbose)
mpr("You can't wear that!");
return false;
}
if (you.get_mutation_level(MUT_MISSING_HAND) && is_shield(item))
{
if (verbose)
{
if (you.species == SP_OCTOPODE)
mpr("You need the rest of your tentacles for walking.");
else
mprf("You'd need another %s to do that!", you.hand_name(false).c_str());
}
return false;
}
if (!ignore_temporary && you.weapon()
&& is_shield(item)
&& is_shield_incompatible(*you.weapon(), &item))
{
if (verbose)
{
if (you.species == SP_OCTOPODE)
mpr("You need the rest of your tentacles for walking.");
else
{
// Singular hand should have already been handled above.
mprf("You'd need three %s to do that!",
you.hand_name(true).c_str());
}
}
return false;
}
// Lear's hauberk covers also head, hands and legs.
if (is_unrandom_artefact(item, UNRAND_LEAR))
{
if (!player_has_feet(!ignore_temporary))
{
if (verbose)
mpr("You have no feet.");
return false;
}
if (you.get_mutation_level(MUT_CLAWS, !ignore_temporary) >= 3)
{
if (verbose)
{
mprf("The hauberk won't fit your %s.",
you.hand_name(true).c_str());
}
return false;
}
if (you.get_mutation_level(MUT_HORNS, !ignore_temporary) >= 3
|| you.get_mutation_level(MUT_ANTENNAE, !ignore_temporary) >= 3)
{
if (verbose)
mpr("The hauberk won't fit your head.");
return false;
}
if (!ignore_temporary)
{
for (int s = EQ_HELMET; s <= EQ_BOOTS; s++)
{
// No strange race can wear this.
const string parts[] = { "head", you.hand_name(true),
you.foot_name(true) };
COMPILE_CHECK(ARRAYSZ(parts) == EQ_BOOTS - EQ_HELMET + 1);
// Auto-disrobing would be nice.
if (you.equip[s] != -1)
{
if (verbose)
{
mprf("You'd need your %s free.",
parts[s - EQ_HELMET].c_str());
}
return false;
}
if (!get_form()->slot_available(s))
{
if (verbose)
{
mprf("The hauberk won't fit your %s.",
parts[s - EQ_HELMET].c_str());
}
return false;
}
}
}
}
else if (slot >= EQ_HELMET && slot <= EQ_BOOTS
&& !ignore_temporary
&& player_equip_unrand(UNRAND_LEAR))
{
// The explanation is iffy for loose headgear, especially crowns:
// kings loved hooded hauberks, according to portraits.
if (verbose)
mpr("You can't wear this over your hauberk.");
return false;
}
size_type player_size = you.body_size(PSIZE_TORSO, ignore_temporary);
int bad_size = fit_armour_size(item, player_size);
#if TAG_MAJOR_VERSION == 34
if (is_unrandom_artefact(item, UNRAND_TALOS))
{
// adjust bad_size for the oversized plate armour
// negative means levels too small, positive means levels too large
bad_size = SIZE_LARGE - player_size;
}
#endif
if (bad_size)
{
if (verbose)
{
mprf("This armour is too %s for you!",
(bad_size > 0) ? "big" : "small");
}
return false;
}
if (you.form == transformation::appendage
&& ignore_temporary
&& slot == beastly_slot(you.attribute[ATTR_APPENDAGE])
&& you.has_mutation(static_cast<mutation_type>(you.attribute[ATTR_APPENDAGE])))
{
unwind_var<uint8_t> mutv(you.mutation[you.attribute[ATTR_APPENDAGE]], 0);
// disable the mutation then check again
return can_wear_armour(item, verbose, ignore_temporary);
}
if (sub_type == ARM_GLOVES)
{
if (you.has_claws(false) == 3)
{
if (verbose)
{
mprf("You can't wear a glove with your huge claw%s!",
you.get_mutation_level(MUT_MISSING_HAND) ? "" : "s");
}
return false;
}
}
if (sub_type == ARM_BOOTS)
{
if (you.get_mutation_level(MUT_HOOVES, false) == 3)
{
if (verbose)
mpr("You can't wear boots with hooves!");
return false;
}
if (you.has_talons(false) == 3)
{
if (verbose)
mpr("Boots don't fit your talons!");
return false;
}
if (you.species == SP_NAGA)
{
if (verbose)
mpr("You have no legs!");
return false;
}
if (!ignore_temporary && you.fishtail)
{
if (verbose)
mpr("You don't currently have feet!");
return false;
}
}
if (slot == EQ_HELMET)
{
// Horns 3 & Antennae 3 mutations disallow all headgear
if (you.get_mutation_level(MUT_HORNS, false) == 3)
{
if (verbose)
mpr("You can't wear any headgear with your large horns!");
return false;
}
if (you.get_mutation_level(MUT_ANTENNAE, false) == 3)
{
if (verbose)
mpr("You can't wear any headgear with your large antennae!");
return false;
}
// Soft helmets (caps and wizard hats) always fit, otherwise.
if (is_hard_helmet(item))
{
if (you.get_mutation_level(MUT_HORNS, false))
{
if (verbose)
mpr("You can't wear that with your horns!");
return false;
}
if (you.get_mutation_level(MUT_BEAK, false))
{
if (verbose)
mpr("You can't wear that with your beak!");
return false;
}
if (you.get_mutation_level(MUT_ANTENNAE, false))
{
if (verbose)
mpr("You can't wear that with your antennae!");
return false;
}
if (species_is_draconian(you.species))
{
if (verbose)
mpr("You can't wear that with your reptilian head.");
return false;
}
if (you.species == SP_OCTOPODE)
{
if (verbose)
mpr("You can't wear that!");
return false;
}
}
}
// Can't just use Form::slot_available because of shroom caps.
if (!ignore_temporary && !get_form()->can_wear_item(item))
{
if (verbose)
mpr("You can't wear that in your present form.");
return false;
}
return true;
}
static bool _can_takeoff_armour(int item);
// Like can_wear_armour, but also takes into account currently worn equipment.
// e.g. you may be able to *wear* that robe, but you can't equip it if your
// currently worn armour is cursed, or melded.
// precondition: item is not already worn
static bool _can_equip_armour(const item_def &item)
{
const object_class_type base_type = item.base_type;
if (base_type != OBJ_ARMOUR)
{
mpr("You can't wear that.");
return false;
}
const equipment_type slot = get_armour_slot(item);
const int equipped = you.equip[slot];
if (equipped != -1 && !_can_takeoff_armour(equipped))
return false;
return can_wear_armour(item, true, false);
}