-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
makeitem.cc
2218 lines (1935 loc) · 67.4 KB
/
makeitem.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 Item creation routines.
**/
#include "AppHdr.h"
#include "makeitem.h"
#include <algorithm>
#include "art-enum.h" // unrand -> magic staff silliness
#include "artefact.h"
#include "colour.h"
#include "decks.h"
#include "describe.h"
#include "dungeon.h"
#include "item-name.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "items.h"
#include "libutil.h" // map_find
#include "randbook.h"
#include "spl-book.h"
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
int create_item_named(string name, coord_def p, string *error)
{
trim_string(name);
item_list ilist;
const string err = ilist.add_item(name, false);
if (!err.empty())
{
if (error)
*error = err;
return NON_ITEM;
}
item_spec ispec = ilist.get_item(0);
int item = dgn_place_item(ispec, you.pos());
if (item != NON_ITEM)
link_items();
else if (error)
*error = "Failed to create item '" + name + "'";
return item;
}
bool got_curare_roll(const int item_level)
{
return one_chance_in(item_level > 27 ? 6 :
item_level < 2 ? 15 :
(364 - 7 * item_level) / 25);
}
/// A mapping from randomly-described object types to their per-game descript
static map<object_class_type, item_description_type> _type_to_idesc = {
{OBJ_WANDS, IDESC_WANDS},
{OBJ_POTIONS, IDESC_POTIONS},
{OBJ_JEWELLERY, IDESC_RINGS},
{OBJ_SCROLLS, IDESC_SCROLLS},
{OBJ_STAVES, IDESC_STAVES},
};
/**
* Initialize the randomized appearance of a given item.
*
* For e.g. wand names, potions colors, helmet tiles...
*
* XXX: could this be moved into a constructor or reset method...?
*
* @param item The item to have its appearance initialized.
*/
void item_colour(item_def &item)
{
// Compute random tile/colour choice.
item.rnd = 1 + random2(255); // reserve 0 for uninitialized
// reserve the high bit for marking 1 in 10 books "visually special"
if (item.base_type == OBJ_BOOKS)
{
if (one_chance_in(10))
item.rnd |= 128;
else
item.rnd = 1 + random2(127); // can't just trim the high bit,
// since it might be the only set bit
}
if (is_unrandom_artefact(item))
return; // don't stomp on item.special!
// initialize item appearance.
// we don't actually *need* to store this now, but we *do* need to store
// it in appearance at some point, since sub_type isn't public information
// for un-id'd items, and therefore can't be used to do a lookup at the
// time item names/colours are calculated.
// it would probably be better to store this at the time that item_info is
// generated (get_item_info), but that requires some save compat work (and
// would be wrong if we ever try to get item colour/names directly...?)
// possibly a todo for a later date.
if (auto idesc = map_find(_type_to_idesc, item.base_type))
item.subtype_rnd = you.item_description[*idesc][item.sub_type];
}
// Does Xom consider an item boring?
static bool _is_boring_item(int type, int sub_type)
{
switch (type)
{
case OBJ_SCROLLS:
// These scrolls increase knowledge and thus reduce risk.
switch (sub_type)
{
case SCR_REMOVE_CURSE:
case SCR_IDENTIFY:
case SCR_MAGIC_MAPPING:
return true;
default:
break;
}
break;
case OBJ_JEWELLERY:
return sub_type == AMU_NOTHING;
default:
break;
}
return false;
}
static weapon_type _determine_weapon_subtype(int item_level)
{
if (item_level > 6 && one_chance_in(30)
&& x_chance_in_y(10 + item_level, 100))
{
return random_choose(WPN_LAJATANG,
WPN_FUSTIBALUS,
WPN_TRIPLE_CROSSBOW,
WPN_DEMON_WHIP,
WPN_DEMON_BLADE,
WPN_DEMON_TRIDENT,
WPN_DOUBLE_SWORD,
WPN_EVENINGSTAR,
WPN_EXECUTIONERS_AXE,
WPN_QUICK_BLADE,
WPN_TRIPLE_SWORD);
}
else if (x_chance_in_y(item_level, 20))
{
// Pick a weapon based on rarity.
while (true)
{
const int wpntype = random2(NUM_WEAPONS);
if (x_chance_in_y(weapon_rarity(wpntype), 10))
return static_cast<weapon_type>(wpntype);
}
}
else if (x_chance_in_y(item_level, item_level+7))
{
return random_choose(WPN_QUARTERSTAFF,
WPN_FALCHION,
WPN_LONG_SWORD,
WPN_WAR_AXE,
WPN_TRIDENT,
WPN_FLAIL,
WPN_RAPIER);
}
else
{
return random_choose(WPN_HUNTING_SLING,
WPN_SPEAR,
WPN_HAND_AXE,
WPN_MACE,
// Not worth _weighted for one doubled type.
WPN_DAGGER, WPN_DAGGER,
WPN_CLUB,
WPN_WHIP,
WPN_SHORT_SWORD);
}
}
static bool _try_make_item_unrand(item_def& item, int force_type, int agent)
{
if (player_in_branch(BRANCH_PANDEMONIUM) && agent == NO_AGENT)
return false;
int idx = find_okay_unrandart(item.base_type, force_type,
player_in_branch(BRANCH_ABYSS)
&& agent == NO_AGENT);
if (idx != -1 && make_item_unrandart(item, idx))
return true;
return false;
}
static bool _weapon_disallows_randart(int sub_type)
{
// Clubs and blowguns are never randarts.
return sub_type == WPN_CLUB || sub_type == WPN_BLOWGUN;
}
// Return whether we made an artefact.
static bool _try_make_weapon_artefact(item_def& item, int force_type,
int item_level, bool force_randart,
int agent)
{
if (item_level > 2 && x_chance_in_y(101 + item_level * 3, 4000)
|| force_randart)
{
// Make a randart or unrandart.
// 1 in 20 randarts are unrandarts.
if (one_chance_in(item_level == ISPEC_GOOD_ITEM ? 7 : 20)
&& !force_randart)
{
if (_try_make_item_unrand(item, force_type, agent))
return true;
}
if (_weapon_disallows_randart(item.sub_type))
return false;
// Mean enchantment +6.
item.plus = 12 - biased_random2(7,2) - biased_random2(7,2) - biased_random2(7,2);
bool cursed = false;
if (one_chance_in(5))
{
cursed = true;
item.plus = 3 - random2(6);
}
else if (item.plus < 0 && !one_chance_in(3))
cursed = true;
// On weapons, an enchantment of less than 0 is never viable.
item.plus = max(static_cast<int>(item.plus), random2(2));
// The rest are normal randarts.
make_item_randart(item);
if (cursed)
do_curse_item(item);
if (get_weapon_brand(item) == SPWPN_HOLY_WRATH)
item.flags &= (~ISFLAG_CURSED);
return true;
}
return false;
}
/**
* The number of times to try finding a brand for a given item.
*
* Result may vary from call to call.
*/
static int _num_brand_tries(const item_def& item, int item_level)
{
if (item_level >= ISPEC_GIFT)
return 5;
if (is_demonic(item) || x_chance_in_y(101 + item_level, 300))
return 1;
return 0;
}
brand_type determine_weapon_brand(const item_def& item, int item_level)
{
// Forced ego.
if (item.brand != 0)
return static_cast<brand_type>(item.brand);
const weapon_type wpn_type = static_cast<weapon_type>(item.sub_type);
const int tries = _num_brand_tries(item, item_level);
brand_type rc = SPWPN_NORMAL;
for (int count = 0; count < tries && rc == SPWPN_NORMAL; ++count)
rc = choose_weapon_brand(wpn_type);
ASSERT(is_weapon_brand_ok(item.sub_type, rc, true));
return rc;
}
// Reject brands which are outright bad for the item. Unorthodox combinations
// are ok, since they can happen on randarts.
bool is_weapon_brand_ok(int type, int brand, bool strict)
{
item_def item;
item.base_type = OBJ_WEAPONS;
item.sub_type = type;
if (brand <= SPWPN_NORMAL)
return true;
if (type == WPN_QUICK_BLADE && brand == SPWPN_SPEED)
return false;
if (type == WPN_BLOWGUN)
return false;
switch ((brand_type)brand)
{
// Universal brands.
case SPWPN_NORMAL:
case SPWPN_VENOM:
case SPWPN_PROTECTION:
case SPWPN_SPEED:
case SPWPN_VORPAL:
case SPWPN_CHAOS:
case SPWPN_HOLY_WRATH:
case SPWPN_ELECTROCUTION:
case SPWPN_FLAMING:
case SPWPN_FREEZING:
break;
// Melee-only brands.
case SPWPN_DRAINING:
case SPWPN_VAMPIRISM:
case SPWPN_PAIN:
case SPWPN_DISTORTION:
case SPWPN_ANTIMAGIC:
case SPWPN_REAPING: // only exists on Sword of Zonguldrok
if (is_range_weapon(item))
return false;
break;
// Ranged-only brands.
case SPWPN_PENETRATION:
case SPWPN_ACID: // Only exists on Punk
if (!is_range_weapon(item))
return false;
break;
#if TAG_MAJOR_VERSION == 34
// Removed brands.
case SPWPN_RETURNING:
case SPWPN_REACHING:
case SPWPN_ORC_SLAYING:
case SPWPN_FLAME:
case SPWPN_FROST:
case SPWPN_DRAGON_SLAYING:
case SPWPN_EVASION:
return false;
#endif
case SPWPN_CONFUSE:
case SPWPN_FORBID_BRAND:
case SPWPN_DEBUG_RANDART:
case NUM_SPECIAL_WEAPONS:
case NUM_REAL_SPECIAL_WEAPONS:
die("invalid brand %d on weapon %d (%s)", brand, type,
item.name(DESC_PLAIN).c_str());
break;
}
return true;
}
static void _roll_weapon_type(item_def& item, int item_level)
{
for (int i = 0; i < 1000; ++i)
{
item.sub_type = _determine_weapon_subtype(item_level);
if (is_weapon_brand_ok(item.sub_type, item.brand, true))
return;
}
item.brand = SPWPN_NORMAL; // fall back to no brand
}
/// Plusses for a non-artefact weapon with positive plusses.
int determine_nice_weapon_plusses(int item_level)
{
const int chance = (item_level >= ISPEC_GIFT ? 200 : item_level);
// Odd-looking, but this is how the algorithm compacts {dlb}.
int plus = 0;
for (int i = 0; i < 4; ++i)
{
plus += random2(3);
if (random2(425) > 35 + chance)
break;
}
return plus;
}
static void _generate_weapon_item(item_def& item, bool allow_uniques,
int force_type, int item_level,
int agent = NO_AGENT)
{
// Determine weapon type.
if (force_type != OBJ_RANDOM)
item.sub_type = force_type;
else
_roll_weapon_type(item, item_level);
// Fall back to an ordinary item if randarts not allowed for this type.
if (item_level == ISPEC_RANDART && _weapon_disallows_randart(item.sub_type))
item_level = ISPEC_GOOD_ITEM;
// Forced randart.
if (item_level == ISPEC_RANDART)
{
int ego = item.brand;
for (int i = 0; i < 100; ++i)
if (_try_make_weapon_artefact(item, force_type, 0, true, agent)
&& is_artefact(item))
{
if (ego > SPWPN_NORMAL)
item.props[ARTEFACT_PROPS_KEY].get_vector()[ARTP_BRAND].get_short() = ego;
if (randart_is_bad(item)) // recheck, the brand changed
{
force_type = item.sub_type;
item.clear();
item.quantity = 1;
item.base_type = OBJ_WEAPONS;
item.sub_type = force_type;
continue;
}
return;
}
// fall back to an ordinary item
item_level = ISPEC_GOOD_ITEM;
}
// If we make the unique roll, no further generation necessary.
if (allow_uniques
&& _try_make_weapon_artefact(item, force_type, item_level, false, agent))
{
return;
}
ASSERT(!is_artefact(item));
// Artefacts handled, let's make a normal item.
const bool force_good = item_level >= ISPEC_GIFT;
const bool forced_ego = item.brand > 0;
const bool no_brand = item.brand == SPWPN_FORBID_BRAND;
if (no_brand)
set_item_ego_type(item, OBJ_WEAPONS, SPWPN_NORMAL);
// If it's forced to be a good item, reroll clubs.
while (force_good && force_type == OBJ_RANDOM && item.sub_type == WPN_CLUB)
_roll_weapon_type(item, item_level);
item.plus = 0;
if (item_level < 0)
{
// Thoroughly damaged, could had been good once.
if (!no_brand && (forced_ego || one_chance_in(4)))
{
// Brand is set as for "good" items.
set_item_ego_type(item, OBJ_WEAPONS,
determine_weapon_brand(item, 2 + 2 * env.absdepth0));
}
item.plus -= 1 + random2(3);
if (item_level == ISPEC_BAD)
do_curse_item(item);
}
else if ((force_good || is_demonic(item) || forced_ego
|| x_chance_in_y(51 + item_level, 200))
&& (!item.is_mundane() || force_good))
{
// Make a better item (possibly ego).
if (!no_brand)
{
set_item_ego_type(item, OBJ_WEAPONS,
determine_weapon_brand(item, item_level));
}
// if acquired item still not ego... enchant it up a bit.
if (force_good && item.brand == SPWPN_NORMAL)
item.plus += 2 + random2(3);
item.plus += determine_nice_weapon_plusses(item_level);
// squash boring items.
if (!force_good && item.brand == SPWPN_NORMAL && item.plus < 3)
item.plus = 0;
}
else
{
if (one_chance_in(12))
{
// Make a cursed item.
do_curse_item(item);
item.plus -= random2(4);
set_item_ego_type(item, OBJ_WEAPONS, SPWPN_NORMAL);
}
}
}
// Current list is based on dpeg's original post to the Wiki, found at the
// page: <http://crawl.develz.org/wiki/doku.php?id=DCSS%3Aissue%3A41>.
// Remember to update the code in is_missile_brand_ok if adding or altering
// brands that are applied to missiles. {due}
static special_missile_type _determine_missile_brand(const item_def& item,
int item_level)
{
// Forced ego.
if (item.brand != 0)
return static_cast<special_missile_type>(item.brand);
const bool force_good = item_level >= ISPEC_GIFT;
special_missile_type rc = SPMSL_NORMAL;
// "Normal weight" of SPMSL_NORMAL.
int nw = force_good ? 0 : random2(2000 - 55 * item_level);
switch (item.sub_type)
{
#if TAG_MAJOR_VERSION == 34
case MI_DART:
#endif
case MI_THROWING_NET:
case MI_STONE:
case MI_LARGE_ROCK:
case MI_SLING_BULLET:
case MI_ARROW:
case MI_BOLT:
rc = SPMSL_NORMAL;
break;
case MI_NEEDLE:
// Curare is special cased, all the others aren't.
if (got_curare_roll(item_level))
{
rc = SPMSL_CURARE;
break;
}
rc = random_choose_weighted(30, SPMSL_SLEEP,
30, SPMSL_CONFUSION,
10, SPMSL_PARALYSIS,
10, SPMSL_FRENZY,
nw, SPMSL_POISONED);
break;
case MI_JAVELIN:
rc = random_choose_weighted(30, SPMSL_RETURNING,
32, SPMSL_PENETRATION,
32, SPMSL_POISONED,
21, SPMSL_STEEL,
20, SPMSL_SILVER,
nw, SPMSL_NORMAL);
break;
case MI_TOMAHAWK:
rc = random_choose_weighted(15, SPMSL_POISONED,
10, SPMSL_SILVER,
10, SPMSL_STEEL,
12, SPMSL_DISPERSAL,
28, SPMSL_RETURNING,
15, SPMSL_EXPLODING,
nw, SPMSL_NORMAL);
break;
}
ASSERT(is_missile_brand_ok(item.sub_type, rc, true));
return rc;
}
bool is_missile_brand_ok(int type, int brand, bool strict)
{
// Launcher ammo can never be branded.
if ((type == MI_STONE
|| type == MI_LARGE_ROCK
|| type == MI_SLING_BULLET
|| type == MI_ARROW
|| type == MI_BOLT)
&& brand != SPMSL_NORMAL
&& strict)
{
return false;
}
// Never generates, only used for chaos-branded missiles.
if (brand == SPMSL_FLAME || brand == SPMSL_FROST)
return false;
// In contrast, needles should always be branded.
// And all of these brands save poison are unique to needles.
switch (brand)
{
case SPMSL_POISONED:
if (type == MI_NEEDLE)
return true;
break;
case SPMSL_CURARE:
case SPMSL_PARALYSIS:
#if TAG_MAJOR_VERSION == 34
case SPMSL_SLOW:
#endif
case SPMSL_SLEEP:
case SPMSL_CONFUSION:
#if TAG_MAJOR_VERSION == 34
case SPMSL_SICKNESS:
#endif
case SPMSL_FRENZY:
return type == MI_NEEDLE;
#if TAG_MAJOR_VERSION == 34
case SPMSL_BLINDING:
// possible on ex-pies
return type == MI_TOMAHAWK && !strict;
#endif
default:
if (type == MI_NEEDLE)
return false;
}
// Everything else doesn't matter.
if (brand == SPMSL_NORMAL)
return true;
// In non-strict mode, everything other than needles is mostly ok.
if (!strict)
return true;
// Not a missile?
if (type == 0)
return true;
// Specifics
switch (brand)
{
case SPMSL_POISONED:
return type == MI_JAVELIN || type == MI_TOMAHAWK;
case SPMSL_RETURNING:
return type == MI_JAVELIN || type == MI_TOMAHAWK;
case SPMSL_CHAOS:
return type == MI_TOMAHAWK || type == MI_JAVELIN;
case SPMSL_PENETRATION:
return type == MI_JAVELIN;
case SPMSL_DISPERSAL:
return type == MI_TOMAHAWK;
case SPMSL_EXPLODING:
return type == MI_TOMAHAWK;
case SPMSL_STEEL: // deliberate fall through
case SPMSL_SILVER:
return type == MI_JAVELIN || type == MI_TOMAHAWK;
default: break;
}
// Assume no, if we've gotten this far.
return false;
}
static void _generate_missile_item(item_def& item, int force_type,
int item_level)
{
const bool no_brand = (item.brand == SPMSL_FORBID_BRAND);
if (no_brand)
item.brand = SPMSL_NORMAL;
item.plus = 0;
if (force_type != OBJ_RANDOM)
item.sub_type = force_type;
else
{
item.sub_type =
random_choose_weighted(50, MI_STONE,
20, MI_ARROW,
12, MI_BOLT,
12, MI_SLING_BULLET,
10, MI_NEEDLE,
3, MI_TOMAHAWK,
2, MI_JAVELIN,
1, MI_THROWING_NET,
1, MI_LARGE_ROCK);
}
// No fancy rocks -- break out before we get to special stuff.
if (item.sub_type == MI_LARGE_ROCK)
{
item.quantity = 2 + random2avg(5,2);
return;
}
else if (item.sub_type == MI_STONE)
{
item.quantity = 1 + random2(7) + random2(10) + random2(12) + random2(10);
return;
}
else if (item.sub_type == MI_THROWING_NET) // no fancy nets, either
{
item.quantity = 1 + one_chance_in(4); // and only one, rarely two
return;
}
if (!no_brand)
{
set_item_ego_type(item, OBJ_MISSILES,
_determine_missile_brand(item, item_level));
}
// Reduced quantity if special.
if (item.sub_type == MI_JAVELIN || item.sub_type == MI_TOMAHAWK
|| (item.sub_type == MI_NEEDLE && get_ammo_brand(item) != SPMSL_POISONED)
|| get_ammo_brand(item) == SPMSL_RETURNING)
{
item.quantity = random_range(2, 8);
}
else if (get_ammo_brand(item) != SPMSL_NORMAL)
item.quantity = 1 + random2(7) + random2(10) + random2(10);
else
item.quantity = 1 + random2(7) + random2(10) + random2(10) + random2(12);
}
static bool _armour_disallows_randart(int sub_type)
{
// Scarves are never randarts.
return sub_type == ARM_SCARF;
}
static bool _try_make_armour_artefact(item_def& item, int force_type,
int item_level, bool force_randart,
int agent)
{
if (item_level > 2 && x_chance_in_y(101 + item_level * 3, 4000)
|| force_randart)
{
// Make a randart or unrandart.
// 1 in 20 randarts are unrandarts.
if (one_chance_in(item_level == ISPEC_GOOD_ITEM ? 7 : 20)
&& !force_randart)
{
if (_try_make_item_unrand(item, force_type, agent))
return true;
}
if (_armour_disallows_randart(item.sub_type))
return false;
// The rest are normal randarts.
// 10% of boots become barding.
if (item.sub_type == ARM_BOOTS && one_chance_in(10))
{
item.sub_type = random_choose(ARM_NAGA_BARDING,
ARM_CENTAUR_BARDING);
}
// Determine enchantment and cursedness.
if (one_chance_in(5))
{
do_curse_item(item);
item.plus = 0;
}
else
{
int max_plus = armour_max_enchant(item);
item.plus = random2(max_plus + 1);
if (one_chance_in(5))
item.plus += random2(max_plus + 6) / 2;
if (one_chance_in(6))
item.plus -= random2(max_plus + 6);
if (item.plus < 0 && !one_chance_in(3))
do_curse_item(item);
}
// On body armour, an enchantment of less than 0 is never viable.
if (get_armour_slot(item) == EQ_BODY_ARMOUR)
item.plus = max(static_cast<int>(item.plus), random2(2));
// Needs to be done after the barding chance else we get randart
// bardings named Boots of xy.
make_item_randart(item);
// Don't let unenchantable armour get minuses.
if (!armour_is_enchantable(item))
item.plus = 0;
return true;
}
return false;
}
/**
* Generate an appropriate ego for a type of armour.
*
* @param item The type of armour in question.
* @param item_level A 'level' of item to generate.
* Only currently used for robes.
* @return An ego appropriate to the item type.
* May be SPARM_NORMAL.
*/
static special_armour_type _generate_armour_type_ego(armour_type type,
int item_level)
{
// TODO: move this into data
switch (type)
{
case ARM_SHIELD:
case ARM_LARGE_SHIELD:
case ARM_BUCKLER:
return random_choose_weighted(1, SPARM_RESISTANCE,
3, SPARM_FIRE_RESISTANCE,
3, SPARM_COLD_RESISTANCE,
3, SPARM_POISON_RESISTANCE,
3, SPARM_POSITIVE_ENERGY,
6, SPARM_REFLECTION,
12, SPARM_PROTECTION);
case ARM_SCARF:
return random_choose_weighted(1, SPARM_SPIRIT_SHIELD,
1, SPARM_RESISTANCE,
1, SPARM_REPULSION,
1, SPARM_CLOUD_IMMUNE);
case ARM_CLOAK:
return random_choose(SPARM_POISON_RESISTANCE,
SPARM_INVISIBILITY,
SPARM_MAGIC_RESISTANCE);
case ARM_HAT:
return random_choose_weighted(7, SPARM_NORMAL,
3, SPARM_MAGIC_RESISTANCE,
2, SPARM_INTELLIGENCE,
2, SPARM_SEE_INVISIBLE);
case ARM_HELMET:
return random_choose(SPARM_SEE_INVISIBLE, SPARM_INTELLIGENCE);
case ARM_GLOVES:
return random_choose(SPARM_DEXTERITY, SPARM_STRENGTH, SPARM_ARCHERY);
case ARM_BOOTS:
return random_choose(SPARM_RUNNING, SPARM_FLYING, SPARM_STEALTH);
case ARM_NAGA_BARDING:
case ARM_CENTAUR_BARDING:
return random_choose(SPARM_FLYING, SPARM_STEALTH,
SPARM_COLD_RESISTANCE, SPARM_FIRE_RESISTANCE);
case ARM_ROBE:
return random_choose_weighted(1, SPARM_RESISTANCE,
1, SPARM_ARCHMAGI,
2, SPARM_NORMAL,
2, SPARM_COLD_RESISTANCE,
2, SPARM_FIRE_RESISTANCE,
2, SPARM_POSITIVE_ENERGY,
4, SPARM_MAGIC_RESISTANCE);
case ARM_PLATE_ARMOUR:
return random_choose_weighted(26, SPARM_FIRE_RESISTANCE,
26, SPARM_COLD_RESISTANCE,
19, SPARM_POISON_RESISTANCE,
15, SPARM_MAGIC_RESISTANCE,
7, SPARM_POSITIVE_ENERGY,
7, SPARM_PONDEROUSNESS);
// other body armour
default:
break;
}
// dragon/troll armour, animal hides, and crystal plate are never generated
// with egos. (unless they're artefacts, but those aren't handled here.)
// TODO: deduplicate with armour_is_special() (same except for animal skin)
if (armour_type_is_hide(type)
|| type == ARM_ANIMAL_SKIN
|| type == ARM_CRYSTAL_PLATE_ARMOUR)
{
return SPARM_NORMAL;
}
return random_choose_weighted(7, SPARM_FIRE_RESISTANCE,
7, SPARM_COLD_RESISTANCE,
5, SPARM_POISON_RESISTANCE,
4, SPARM_MAGIC_RESISTANCE,
2, SPARM_POSITIVE_ENERGY);
}
/**
* Generate an appropriate ego for a piece of armour.
*
* @param item The item in question.
* @param item_level A 'level' of item to generate.
* @return The item's current ego, if it already has one;
* otherwise, an ego appropriate to the item.
* May be SPARM_NORMAL.
*/
static special_armour_type _generate_armour_ego(const item_def& item,
int item_level)
{
if (item.brand != SPARM_NORMAL)
return static_cast<special_armour_type>(item.brand);
const special_armour_type ego
= _generate_armour_type_ego(static_cast<armour_type>(item.sub_type),
item_level);
ASSERT(is_armour_brand_ok(item.sub_type, ego, true));
return ego;
}
bool is_armour_brand_ok(int type, int brand, bool strict)
{
equipment_type slot = get_armour_slot((armour_type)type);
// Currently being too restrictive results in asserts, being too
// permissive will generate such items on "any armour ego:XXX".
// The latter is definitely so much safer -- 1KB
switch ((special_armour_type)brand)
{
case SPARM_FORBID_EGO:
case SPARM_NORMAL:
return true;
case SPARM_FLYING:
if (slot == EQ_BODY_ARMOUR)
return true;
// deliberate fall-through
case SPARM_RUNNING:
case SPARM_STEALTH:
#if TAG_MAJOR_VERSION == 34
case SPARM_JUMPING:
#endif
return slot == EQ_BOOTS;
case SPARM_ARCHMAGI:
return !strict || type == ARM_ROBE;
case SPARM_PONDEROUSNESS:
return true;
#if TAG_MAJOR_VERSION == 34
case SPARM_PRESERVATION:
if (type == ARM_PLATE_ARMOUR && !strict)
return true;
// deliberate fall-through
#endif
case SPARM_INVISIBILITY:
return slot == EQ_CLOAK;
case SPARM_REFLECTION:
case SPARM_PROTECTION:
return slot == EQ_SHIELD;
case SPARM_STRENGTH:
case SPARM_DEXTERITY:
if (!strict)
return true;
// deliberate fall-through
case SPARM_ARCHERY:
return slot == EQ_GLOVES;
case SPARM_SEE_INVISIBLE:
case SPARM_INTELLIGENCE:
return slot == EQ_HELMET;
case SPARM_FIRE_RESISTANCE:
case SPARM_COLD_RESISTANCE:
case SPARM_RESISTANCE:
if (type == ARM_FIRE_DRAGON_ARMOUR
|| type == ARM_ICE_DRAGON_ARMOUR
|| type == ARM_GOLD_DRAGON_ARMOUR)
{
return false; // contradictory or redundant
}
return true; // in portal vaults, these can happen on every slot
case SPARM_MAGIC_RESISTANCE:
if (type == ARM_HAT)
return true;
// deliberate fall-through
case SPARM_POISON_RESISTANCE:
case SPARM_POSITIVE_ENERGY:
if (type == ARM_PEARL_DRAGON_ARMOUR && brand == SPARM_POSITIVE_ENERGY)
return false; // contradictory or redundant
return slot == EQ_BODY_ARMOUR || slot == EQ_SHIELD || slot == EQ_CLOAK
|| !strict;
case SPARM_SPIRIT_SHIELD:
return
#if TAG_MAJOR_VERSION == 34
type == ARM_HAT ||
type == ARM_CAP ||
#endif
slot == EQ_SHIELD ||
type == ARM_SCARF || !strict;
case SPARM_REPULSION:
case SPARM_CLOUD_IMMUNE:
return type == ARM_SCARF;