/
artefact.cc
1888 lines (1614 loc) · 56.8 KB
/
artefact.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 Random and unrandom artefact functions.
**/
#include "AppHdr.h"
#include "artefact.h"
#include "art-enum.h"
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "areas.h"
#include "branch.h"
#include "colour.h"
#include "coordit.h"
#include "database.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
#include "libutil.h"
#include "makeitem.h"
#include "random.h"
#include "religion.h"
#include "shout.h"
#include "spl-book.h"
#include "state.h"
#include "stringutil.h"
#include "unicode.h"
static bool _god_fits_artefact(const god_type which_god, const item_def &item,
bool name_check_only = false)
{
if (which_god == GOD_NO_GOD)
return false;
// Jellies can't eat artefacts, so their god won't make any.
if (which_god == GOD_JIYVA)
return false;
// First check the item's base_type and sub_type, then check the
// item's brand and other randart properties.
bool type_bad = false;
switch (which_god)
{
case GOD_ELYVILON:
// Peaceful healer god: no weapons, no berserking.
if (item.base_type == OBJ_WEAPONS)
type_bad = true;
if (item.is_type(OBJ_JEWELLERY, AMU_RAGE))
type_bad = true;
break;
case GOD_SHINING_ONE:
// Crusader god: holiness, honourable combat.
if (item.is_type(OBJ_JEWELLERY, RING_STEALTH))
type_bad = true;
break;
case GOD_OKAWARU:
// Precision fighter god: no inaccuracy.
if (item.is_type(OBJ_JEWELLERY, AMU_INACCURACY))
type_bad = true;
break;
case GOD_SIF_MUNA:
case GOD_VEHUMET:
// The magic gods: no weapons, no preventing spellcasting.
if (item.base_type == OBJ_WEAPONS)
type_bad = true;
break;
case GOD_TROG:
// Anti-magic god: no spell use, no enhancing magic.
if (item.base_type == OBJ_BOOKS)
type_bad = true;
if (item.base_type == OBJ_JEWELLERY
&& (item.sub_type == RING_WIZARDRY
|| item.sub_type == RING_FIRE
|| item.sub_type == RING_ICE
|| item.sub_type == RING_MAGICAL_POWER))
{
type_bad = true;
}
break;
case GOD_CHEIBRIADOS:
// Slow god: no quick blades, no berserking.
if (item.is_type(OBJ_WEAPONS, WPN_QUICK_BLADE))
type_bad = true;
if (item.is_type(OBJ_JEWELLERY, AMU_RAGE))
type_bad = true;
break;
case GOD_DITHMENOS:
// Shadow god: no reducing stealth.
if (item.is_type(OBJ_JEWELLERY, RING_LOUDNESS))
type_bad = true;
break;
default:
break;
}
if (type_bad && !name_check_only)
{
die("%s attempting to gift invalid type of item.",
god_name(which_god).c_str());
}
if (type_bad)
return false;
const int brand = get_weapon_brand(item);
const int ego = get_armour_ego_type(item);
if (is_evil_god(which_god) && brand == SPWPN_HOLY_WRATH)
return false;
else if (is_good_god(which_god)
&& (brand == SPWPN_DRAINING
|| brand == SPWPN_PAIN
|| brand == SPWPN_VAMPIRISM
|| brand == SPWPN_REAPING
|| brand == SPWPN_CHAOS
|| is_demonic(item)
|| artefact_property(item, ARTP_CURSE) != 0))
{
return false;
}
switch (which_god)
{
case GOD_ELYVILON:
// Peaceful healer god: no berserking.
if (artefact_property(item, ARTP_ANGRY)
|| artefact_property(item, ARTP_BERSERK))
{
return false;
}
break;
case GOD_ZIN:
// Lawful god: no mutagenics.
if (artefact_property(item, ARTP_CONTAM))
return false;
break;
case GOD_SHINING_ONE:
// Crusader god: holiness, honourable combat.
if (item.base_type == OBJ_WEAPONS && brand != SPWPN_HOLY_WRATH)
return false;
if (artefact_property(item, ARTP_INVISIBLE)
|| artefact_property(item, ARTP_STEALTH) > 0)
{
return false;
}
break;
case GOD_LUGONU:
// Abyss god: corruption.
if (item.base_type == OBJ_WEAPONS && brand != SPWPN_DISTORTION)
return false;
break;
case GOD_KIKUBAAQUDGHA:
// Necromancy god.
if (item.base_type == OBJ_WEAPONS && brand != SPWPN_PAIN)
return false;
case GOD_SIF_MUNA:
case GOD_VEHUMET:
// The magic gods: no preventing spellcasting.
if (artefact_property(item, ARTP_PREVENT_SPELLCASTING))
return false;
break;
case GOD_TROG:
// Anti-magic god: no spell use, no enhancing magic.
if (brand == SPWPN_PAIN) // Pain involves necromantic spell use.
return false;
if (artefact_property(item, ARTP_MAGICAL_POWER) > 0)
return false;
break;
case GOD_FEDHAS:
// Fedhas forbids necromancy involving corpses, only reaping
// really applies.
if (brand == SPWPN_REAPING)
return false;
break;
case GOD_CHEIBRIADOS:
// Slow god: no speed, no berserking.
if (brand == SPWPN_SPEED)
return false;
if (ego == SPARM_RUNNING)
return false;
if (artefact_property(item, ARTP_ANGRY)
|| artefact_property(item, ARTP_BERSERK))
{
return false;
}
break;
case GOD_ASHENZARI:
// Cursed god: no holy wrath (since that brand repels curses).
if (brand == SPWPN_HOLY_WRATH)
return false;
break;
case GOD_DITHMENOS:
// No fiery weapons.
if (item.base_type == OBJ_WEAPONS
&& brand == SPWPN_FLAMING)
{
return false;
}
// No reducing stealth.
if (artefact_property(item, ARTP_STEALTH) < 0)
return false;
break;
default:
break;
}
return true;
}
string replace_name_parts(const string &name_in, const item_def& item)
{
string name = name_in;
const god_type god_gift = origin_as_god_gift(item);
// Don't allow "player's Death" type names for god gifts (except
// for those from Xom).
if (name.find("@player_death@", 0) != string::npos
|| name.find("@player_doom@", 0) != string::npos)
{
if (god_gift == GOD_NO_GOD || god_gift == GOD_XOM)
{
name = replace_all(name, "@player_death@",
"@player_name@"
+ getRandNameString("killer_name"));
name = replace_all(name, "@player_doom@",
"@player_name@'s "
+ getRandNameString("death_or_doom"));
}
else
{
// Simply overwrite the name with one of type "God's Favour".
name = "of ";
name += god_name(god_gift, false);
name += "'s ";
name += getRandNameString("divine_esteem");
}
}
name = replace_all(name, "@player_name@", you.your_name);
name = replace_all(name, "@player_species@",
species_name(you.species, SPNAME_GENUS));
if (name.find("@branch_name@", 0) != string::npos)
{
string place = branches[random2(NUM_BRANCHES)].longname;
if (!place.empty())
name = replace_all(name, "@branch_name@", place);
}
// Occasionally use long name for Xom (see religion.cc).
name = replace_all(name, "@xom_name@", god_name(GOD_XOM, coinflip()));
if (name.find("@god_name@", 0) != string::npos)
{
god_type which_god;
// God gifts will always get the gifting god's name.
if (god_gift != GOD_NO_GOD)
which_god = god_gift;
else
{
do
{
which_god = random_god();
}
while (!_god_fits_artefact(which_god, item, true));
}
name = replace_all(name, "@god_name@", god_name(which_god, false));
}
return name;
}
// Remember: disallow unrandart creation in Abyss/Pan.
// Functions defined in art-func.h are referenced in art-data.h
#include "art-func.h"
static const unrandart_entry unranddata[] =
{
#include "art-data.h"
};
static const unrandart_entry *_seekunrandart(const item_def &item);
bool is_known_artefact(const item_def &item)
{
if (!item_type_known(item))
return false;
return is_artefact(item);
}
bool is_artefact(const item_def &item)
{
return item.flags & ISFLAG_ARTEFACT_MASK;
}
// returns true is item is a pure randart
bool is_random_artefact(const item_def &item)
{
return item.flags & ISFLAG_RANDART;
}
/** Is this an unrandart, and if so which one?
*
* @param item The item to be checked.
* @param which The unrand enum to be checked against (default 0).
* @returns true if item is an unrand, and if which is not 0, if it is the unrand
* specfied by enum in which.
*/
bool is_unrandom_artefact(const item_def &item, int which)
{
return item.flags & ISFLAG_UNRANDART
&& (!which || which == item.special);
}
bool is_special_unrandom_artefact(const item_def &item)
{
return item.flags & ISFLAG_UNRANDART
&& (_seekunrandart(item)->flags & UNRAND_FLAG_SPECIAL);
}
bool is_randapp_artefact(const item_def &item)
{
return item.flags & ISFLAG_UNRANDART
&& !(item.flags & ISFLAG_KNOW_TYPE)
&& (_seekunrandart(item)->flags & UNRAND_FLAG_RANDAPP);
}
void autoid_unrand(item_def &item)
{
if (!(item.flags & ISFLAG_UNRANDART) || item.flags & ISFLAG_KNOW_TYPE)
return;
const uint16_t uflags = _seekunrandart(item)->flags;
if (uflags & UNRAND_FLAG_RANDAPP || uflags & UNRAND_FLAG_UNIDED)
return;
set_ident_flags(item, ISFLAG_IDENT_MASK | ISFLAG_NOTED_ID);
}
unique_item_status_type get_unique_item_status(int art)
{
ASSERT_RANGE(art, UNRAND_START + 1, UNRAND_LAST);
return you.unique_items[art - UNRAND_START];
}
static void _set_unique_item_status(int art, unique_item_status_type status)
{
ASSERT_RANGE(art, UNRAND_START + 1, UNRAND_LAST);
you.unique_items[art - UNRAND_START] = status;
}
void set_unique_item_status(const item_def& item,
unique_item_status_type status)
{
if (item.flags & ISFLAG_UNRANDART)
_set_unique_item_status(item.special, status);
}
/**
* Fill out the inherent ARTPs corresponding to a given type of armour.
*
* @param arm The armour_type of the armour in question.
* @param proprt[out] The properties list to be populated.
*/
static void _populate_armour_intrinsic_artps(const armour_type arm,
artefact_properties_t &proprt)
{
proprt[ARTP_FIRE] += armour_type_prop(arm, ARMF_RES_FIRE);
proprt[ARTP_COLD] += armour_type_prop(arm, ARMF_RES_COLD);
proprt[ARTP_NEGATIVE_ENERGY] += armour_type_prop(arm, ARMF_RES_NEG);
proprt[ARTP_POISON] += armour_type_prop(arm, ARMF_RES_POISON);
proprt[ARTP_ELECTRICITY] += armour_type_prop(arm, ARMF_RES_ELEC);
proprt[ARTP_MAGIC_RESISTANCE] += armour_type_prop(arm, ARMF_RES_MAGIC);
proprt[ARTP_STEALTH] += armour_type_prop(arm, ARMF_STEALTH);
proprt[ARTP_REGENERATION] += armour_type_prop(arm, ARMF_REGENERATION);
}
/// The artefact properties corresponding to a given piece of jewellery.
struct jewellery_fake_artp
{
/// The artp matching the jewellery (e.g. ARTP_AC for RING_PROTECTION)
artefact_prop_type artp;
/// The value of the artp. (E.g. '9' for RING_MAGICAL_POWER.) If set to 0, uses item.plus instead.
int plus;
};
static map<jewellery_type, vector<jewellery_fake_artp>> jewellery_artps = {
{ AMU_RAGE, { { ARTP_BERSERK, 1 } } },
{ AMU_REGENERATION, { { ARTP_REGENERATION, 1 } } },
{ RING_INVISIBILITY, { { ARTP_INVISIBLE, 1 } } },
{ RING_MAGICAL_POWER, { { ARTP_MAGICAL_POWER, 9 } } },
{ RING_FLIGHT, { { ARTP_FLY, 1 } } },
{ RING_SEE_INVISIBLE, { { ARTP_SEE_INVISIBLE, 1 } } },
{ RING_STEALTH, { { ARTP_STEALTH, 1 } } },
{ RING_LOUDNESS, { { ARTP_STEALTH, -1 } } },
{ RING_PROTECTION_FROM_FIRE, { { ARTP_FIRE, 1 } } },
{ RING_PROTECTION_FROM_COLD, { { ARTP_COLD, 1 } } },
{ RING_POISON_RESISTANCE, { { ARTP_POISON, 1 } } },
{ RING_LIFE_PROTECTION, { { ARTP_NEGATIVE_ENERGY, 1 } } },
{ RING_PROTECTION_FROM_MAGIC, { { ARTP_MAGIC_RESISTANCE, 1 } } },
{ RING_FIRE, { { ARTP_FIRE, 1 }, { ARTP_COLD, -1 } } },
{ RING_ICE, { { ARTP_COLD, 1 }, { ARTP_FIRE, -1 } } },
{ RING_STRENGTH, { { ARTP_STRENGTH, 0 } } },
{ RING_INTELLIGENCE, { { ARTP_INTELLIGENCE, 0 } } },
{ RING_DEXTERITY, { { ARTP_DEXTERITY, 0 } } },
{ RING_PROTECTION, { { ARTP_AC, 0 } } },
{ RING_EVASION, { { ARTP_EVASION, 0 } } },
{ RING_SLAYING, { { ARTP_SLAYING, 0 } } },
};
/**
* Fill out the inherent ARTPs corresponding to a given type of jewellery.
*
* @param arm The jewellery in question.
* @param proprt[out] The properties list to be populated.
* @param known[out] The props which are known.
*/
static void _populate_jewel_intrinsic_artps(const item_def &item,
artefact_properties_t &proprt,
artefact_known_props_t &known)
{
const jewellery_type jewel = (jewellery_type)item.sub_type;
vector<jewellery_fake_artp> *props = map_find(jewellery_artps, jewel);
if (!props)
return;
const bool id_props = item_ident(item, ISFLAG_KNOW_PROPERTIES)
|| item_ident(item, ISFLAG_KNOW_TYPE);
for (const auto &fake_artp : *props)
{
proprt[fake_artp.artp] += fake_artp.plus ? fake_artp.plus : item.plus;
if (id_props)
known[fake_artp.artp] = true;
}
}
/**
* Fill out the inherent ARTPs corresponding to a given item.
*
* @param arm The item in question.
* @param proprt[out] The properties list to be populated.
* @param known[out] The props which are known.
*/
static void _populate_item_intrinsic_artps(const item_def &item,
artefact_properties_t &proprt,
artefact_known_props_t &known)
{
switch (item.base_type)
{
case OBJ_ARMOUR:
_populate_armour_intrinsic_artps((armour_type)item.sub_type,
proprt);
break;
case OBJ_JEWELLERY:
_populate_jewel_intrinsic_artps(item, proprt, known);
break;
default:
break;
}
}
void artefact_desc_properties(const item_def &item,
artefact_properties_t &proprt,
artefact_known_props_t &known)
{
// Randart books have no randart properties.
if (item.base_type == OBJ_BOOKS)
return;
// actual artefact properties
artefact_properties(item, proprt, known);
// fake artefact properties (intrinsics)
_populate_item_intrinsic_artps(item, proprt, known);
}
static void _add_randart_weapon_brand(const item_def &item,
artefact_properties_t &item_props)
{
const int item_type = item.sub_type;
if (is_range_weapon(item))
{
item_props[ARTP_BRAND] = random_choose_weighted(
2, SPWPN_SPEED,
4, SPWPN_VENOM,
4, SPWPN_VORPAL,
4, SPWPN_FLAMING,
4, SPWPN_FREEZING,
0);
if (item_type == WPN_BLOWGUN)
item_props[ARTP_BRAND] = coinflip() ? SPWPN_SPEED : SPWPN_EVASION;
else if (item_attack_skill(item) == SK_CROSSBOWS)
{
// Penetration and electrocution are only allowed on
// crossbows. This may change in future.
if (one_chance_in(5))
item_props[ARTP_BRAND] = SPWPN_ELECTROCUTION;
else if (one_chance_in(5))
item_props[ARTP_BRAND] = SPWPN_PENETRATION;
}
}
else if (is_demonic(item) && x_chance_in_y(7, 9))
{
item_props[ARTP_BRAND] = random_choose(
SPWPN_DRAINING,
SPWPN_FLAMING,
SPWPN_FREEZING,
SPWPN_ELECTROCUTION,
SPWPN_VAMPIRISM,
SPWPN_PAIN,
SPWPN_VENOM);
// fall back to regular melee brands 2/9 of the time
}
else
{
item_props[ARTP_BRAND] = random_choose_weighted(
73, SPWPN_VORPAL,
34, SPWPN_FLAMING,
34, SPWPN_FREEZING,
26, SPWPN_VENOM,
26, SPWPN_DRAINING,
13, SPWPN_HOLY_WRATH,
13, SPWPN_ELECTROCUTION,
13, SPWPN_SPEED,
13, SPWPN_VAMPIRISM,
13, SPWPN_PAIN,
13, SPWPN_ANTIMAGIC,
3, SPWPN_DISTORTION,
0);
}
// no brand = magic flag to reject and retry
if (!is_weapon_brand_ok(item_type, item_props[ARTP_BRAND], true))
item_props[ARTP_BRAND] = SPWPN_NORMAL;
}
/**
* Can the given artefact property be placed on the given item?
*
* @param prop The artefact property in question (e.g. ARTP_BLINK).
* @param item The item in question.
* @param extant_props The properties already chosen for the artefact.
* @return True if the property doesn't conflict with any chosen
* or intrinsic properties, and doesn't violate any other
* special constraints (e.g. no slaying on weapons);
* false otherwise.
*/
static bool _artp_can_go_on_item(artefact_prop_type prop, const item_def &item,
const artefact_properties_t &extant_props)
{
artefact_properties_t intrinsic_proprt;
intrinsic_proprt.init(0);
artefact_known_props_t _;
_populate_item_intrinsic_artps(item, intrinsic_proprt, _);
if (intrinsic_proprt[prop])
return false; // don't duplicate intrinsic props
const object_class_type item_class = item.base_type;
switch (prop)
{
case ARTP_SLAYING:
return item_class != OBJ_WEAPONS; // they already have slaying!
case ARTP_POISON:
case ARTP_SEE_INVISIBLE:
return !item.is_type(OBJ_ARMOUR, ARM_NAGA_BARDING);
// naga already have rPois & sInv!
case ARTP_CORRODE:
return !extant_props[ARTP_RCORR];
case ARTP_RCORR:
return item_class == OBJ_ARMOUR && !extant_props[ARTP_CORRODE];
case ARTP_REGENERATION:
case ARTP_PREVENT_SPELLCASTING:
return item_class == OBJ_ARMOUR; // limit availability to armour
case ARTP_BERSERK:
case ARTP_ANGRY:
case ARTP_NOISE:
return item_class == OBJ_WEAPONS && !is_range_weapon(item);
// works poorly with ranged weapons
case ARTP_CAUSE_TELEPORTATION:
return item_class != OBJ_WEAPONS
&& !crawl_state.game_is_sprint()
&& !extant_props[ARTP_PREVENT_TELEPORTATION];
// no tele in sprint, and too annoying on weapons (swappable)
// and obv we shouldn't generate contradictory props
case ARTP_PREVENT_TELEPORTATION:
return !extant_props[ARTP_BLINK]
&& !extant_props[ARTP_CAUSE_TELEPORTATION];
// no contradictory props
case ARTP_BLINK:
return !extant_props[ARTP_PREVENT_TELEPORTATION];
// no contradictory props
case ARTP_CONFUSE:
return !item.is_type(OBJ_JEWELLERY, AMU_CLARITY);
case ARTP_MAGICAL_POWER:
return item_class != OBJ_WEAPONS
|| get_weapon_brand(item) != SPWPN_ANTIMAGIC;
// not quite as interesting on armour, since you swap it less
case ARTP_FRAGILE:
return item_class != OBJ_ARMOUR;
default:
return true;
}
}
/// Generation info for a type of artefact property.
struct artefact_prop_data
{
/// The name of the prop, as displayed on item annotations, etc.
const char *name;
/// The types of values this prop can have (e.g. bool, positive int, int)
artp_value_type value_types;
/// Weight in randart selection (higher = more common)
int weight;
/// Randomly generate a 'good' value; null if this prop is never good
function<int ()> gen_good_value;
/// Randomly generate a 'bad' value; null if this prop is never bad
function<int ()> gen_bad_value;
/// The value beyond which the artp should not be repeatedly applied.
int max_dup;
/// The amount to increment the odds of a property being reapplied
int odds_inc;
};
/// Generate 'good' values for stat artps (e.g. ARTP_STRENGTH)
static int _gen_good_stat_artp() { return 1 + random2(3); }
/// Generate 'bad' values for stat artps (e.g. ARTP_STRENGTH)
static int _gen_bad_stat_artp() { return -2 - random2(4); }
/// Generate 'good' values for resist-ish artps (e.g. ARTP_FIRE)
static int _gen_good_res_artp() { return 1; }
/// Generate 'bad' values for resist-ish artps (e.g. ARTP_FIRE)
static int _gen_bad_res_artp() { return -1; }
/// Generate 'good' values for ARTP_HP/ARTP_MAGICAL_POWER
static int _gen_good_hpmp_artp() { return 9; }
/// Generate 'bad' values for ARTP_HP/ARTP_MAGICAL_POWER
static int _gen_bad_hpmp_artp() { return -_gen_good_hpmp_artp(); }
/// Generation info for artefact properties.
static const artefact_prop_data artp_data[] =
{
{ "Brand", ARTP_VAL_POS, 0, nullptr, nullptr, 0, 0 }, // ARTP_BRAND,
{ "AC", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0}, // ARTP_AC,
{ "EV", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0 }, // ARTP_EVASION,
{ "Str", ARTP_VAL_ANY, 100, // ARTP_STRENGTH,
_gen_good_stat_artp, _gen_bad_stat_artp, 7, 1 },
{ "Int", ARTP_VAL_ANY, 100, // ARTP_INTELLIGENCE,
_gen_good_stat_artp, _gen_bad_stat_artp, 7, 1 },
{ "Dex", ARTP_VAL_ANY, 100, // ARTP_DEXTERITY,
_gen_good_stat_artp, _gen_bad_stat_artp, 7, 1 },
{ "rF", ARTP_VAL_ANY, 60, // ARTP_FIRE,
_gen_good_res_artp, _gen_bad_res_artp, 2, 4},
{ "rC", ARTP_VAL_ANY, 60, // ARTP_COLD,
_gen_good_res_artp, _gen_bad_res_artp, 2, 4 },
{ "rElec", ARTP_VAL_BOOL, 55, // ARTP_ELECTRICITY,
[]() { return 1; }, nullptr, 0, 0 },
{ "rPois", ARTP_VAL_BOOL, 55, // ARTP_POISON,
[]() { return 1; }, nullptr, 0, 0 },
{ "rN", ARTP_VAL_ANY, 55, // ARTP_NEGATIVE_ENERGY,
_gen_good_res_artp, nullptr, 2, 4 },
{ "MR", ARTP_VAL_ANY, 50, // ARTP_MAGIC_RESISTANCE,
_gen_good_res_artp, _gen_bad_res_artp, 2, 4 },
{ "SInv", ARTP_VAL_BOOL, 30, // ARTP_SEE_INVISIBLE,
[]() { return 1; }, nullptr, 0, 0 },
{ "+Inv", ARTP_VAL_BOOL, 15, // ARTP_INVISIBLE,
[]() { return 1; }, nullptr, 0, 0 },
{ "+Fly", ARTP_VAL_BOOL, 15, // ARTP_FLY,
[]() { return 1; }, nullptr, 0, 0 },
#if TAG_MAJOR_VERSION > 34
{ "+Fog", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_FOG,
#endif
{ "+Blink", ARTP_VAL_BOOL, 15, // ARTP_BLINK,
[]() { return 1; }, nullptr, 0, 0 },
{ "+Rage", ARTP_VAL_BOOL, 15, // ARTP_BERSERK,
[]() { return 1; }, nullptr, 0, 0 },
{ "*Noise", ARTP_VAL_POS, 25, // ARTP_NOISE,
nullptr, []() { return 2; }, 0, 0 },
{ "-Cast", ARTP_VAL_BOOL, 25, // ARTP_PREVENT_SPELLCASTING,
nullptr, []() { return 1; }, 0, 0 },
{ "*Tele", ARTP_VAL_BOOL, 0, // ARTP_CAUSE_TELEPORTATION,
nullptr, []() { return 1; }, 0, 0 },
{ "-Tele", ARTP_VAL_BOOL, 25, // ARTP_PREVENT_TELEPORTATION,
nullptr, []() { return 1; }, 0, 0 },
{ "*Rage", ARTP_VAL_POS, 25, // ARTP_ANGRY,
nullptr, []() { return 5; }, 0, 0 },
#if TAG_MAJOR_VERSION == 34
{ "Hungry", ARTP_VAL_POS, 0, nullptr, nullptr, 0, 0 },// ARTP_METABOLISM,
#endif
{ "*Contam", ARTP_VAL_POS, 20, // ARTP_CONTAM
nullptr, []() { return 1; }, 0, 0 },
#if TAG_MAJOR_VERSION == 34
{ "Acc", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0 }, // ARTP_ACCURACY,
#endif
{ "Slay", ARTP_VAL_ANY, 30, // ARTP_SLAYING,
[]() { return 2 + random2(2); },
[]() { return -(2 + random2(3) + random2(3)); }, 3, 2 },
{ "*Curse", ARTP_VAL_POS, 0, nullptr, nullptr, 0 }, // ARTP_CURSE,
{ "Stlth", ARTP_VAL_ANY, 40, // ARTP_STEALTH,
_gen_good_res_artp, _gen_bad_res_artp, 0, 0 },
{ "MP", ARTP_VAL_ANY, 30, // ARTP_MAGICAL_POWER,
_gen_good_hpmp_artp, _gen_bad_hpmp_artp, 0, 0 },
{ "Delay", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0 }, // ARTP_BASE_DELAY,
{ "HP", ARTP_VAL_ANY, 0, // ARTP_HP,
_gen_good_hpmp_artp, _gen_bad_hpmp_artp, 0, 0 },
{ "Clar", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_CLARITY,
{ "BAcc", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0 }, // ARTP_BASE_ACC,
{ "BDam", ARTP_VAL_ANY, 0, nullptr, nullptr, 0, 0 }, // ARTP_BASE_DAM,
{ "RMsl", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_RMSL,
#if TAG_MAJOR_VERSION == 34
{ "+Fog", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_FOG,
#endif
{ "Regen", ARTP_VAL_BOOL, 35, // ARTP_REGENERATION,
[]() { return 1; }, nullptr, 0, 0 },
{ "SustAt", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_SUSTAT,
{ "nupgr", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 },// ARTP_NO_UPGRADE,
{ "rCorr", ARTP_VAL_BOOL, 40, // ARTP_RCORR,
[]() { return 1; }, nullptr, 0, 0 },
{ "rMut", ARTP_VAL_BOOL, 0, nullptr, nullptr, 0, 0 }, // ARTP_RMUT,
#if TAG_MAJOR_VERSION == 34
{ "+Twstr", ARTP_VAL_BOOL, 0, // ARTP_TWISTER,
[]() { return 1; }, nullptr, 0, 0 },
#endif
{ "*Corrode", ARTP_VAL_BOOL, 25, // ARTP_CORRODE,
nullptr, []() { return 1; }, 0, 0 },
{ "*Drain", ARTP_VAL_BOOL, 25, // ARTP_DRAIN,
nullptr, []() { return 1; }, 0, 0 },
{ "*Confuse", ARTP_VAL_BOOL, 25, // ARTP_CONFUSE,
nullptr, []() { return 1; }, 0, 0 },
{ "Fragile", ARTP_VAL_BOOL, 25, // ARTP_FRAGILE,
nullptr, []() { return 1; }, 0, 0 },
};
COMPILE_CHECK(ARRAYSZ(artp_data) == ARTP_NUM_PROPERTIES);
// weights sum to 1000
/**
* Is it possible for the given artp to be generated with 'good' values
* (generally helpful to the player?
* E.g. ARTP_SLAYING, ARTP_FIRE, ARTP_REGENERATION, etc.
*
* @param prop The artefact property in question.
* @return true if the ARTP is ever generated as a 'good' prop; false
* otherwise.
*/
bool artp_potentially_good(artefact_prop_type prop)
{
return artp_data[prop].gen_good_value != nullptr;
}
/**
* Is it possible for the given artp to be generated with 'bad' values
* (generally harmful to the player?
* E.g. ARTP_SLAYING, ARTP_AC, ARTP_CONTAM, etc.
*
* @param prop The artefact property in question.
* @return true if the ARTP is ever generated as a 'bad' prop; false
* otherwise.
*/
bool artp_potentially_bad(artefact_prop_type prop)
{
return artp_data[prop].gen_bad_value != nullptr;
}
/**
* What type of values can this prop have?
*
* Positive, boolean (0 or 1), or any (integer).
*
* There should be a better way of expressing this...
*
* @param prop The prop type in question.
* @return Possible value types for the prop.
*/
artp_value_type artp_potential_value_types(artefact_prop_type prop)
{
ASSERT_RANGE(prop, 0, ARRAYSZ(artp_data));
return artp_data[prop].value_types;
}
/**
* Return the name for a given artefact property.
*
* @param prop The artp in question.
* @return A name; e.g. rCorr, Slay, HP, etc.
*/
const char *artp_name(artefact_prop_type prop)
{
ASSERT_RANGE(prop, 0, ARRAYSZ(artp_data));
return artp_data[prop].name;
}
/**
* Add a 'good' version of a given prop to the given set of item props.
*
* The property may already exist in the set; if so, increase its value.
*
* @param prop[in] The prop to be added.
* @param item_props[out] The list of item props to be added to.
*/
static void _add_good_randart_prop(artefact_prop_type prop,
artefact_properties_t &item_props)
{
// Add one to the starting value for stat bonuses.
if ((prop == ARTP_STRENGTH
|| prop == ARTP_INTELLIGENCE
|| prop == ARTP_DEXTERITY)
&& item_props[prop] == 0)
{
item_props[prop]++;
}
item_props[prop] += artp_data[prop].gen_good_value();
}
static void _get_randart_properties(const item_def &item,
artefact_properties_t &item_props)
{
const object_class_type item_class = item.base_type;
// first figure out how good we want the artefact to be, range 1 to 7.
const int quality = max(1, binomial(7, 30));
// then consider adding bad properties. the better the artefact, the more
// likely we add a bad property, up to a max of 2.
int bad = min(binomial(1 + div_rand_round(quality, 5), 30), 2);
// we start by assuming we'll allow one good property per quality level
// and an additional one for each bad property.
int good = quality + bad;
// but we want avoid generating more then 4-ish properties properties or
// things get spammy. Extra "good" properties will be used to enhance
// properties only, not to add more distinct properties. There is still a
// small chance of >4 properties.
const int max_properties = 4 + one_chance_in(20) + one_chance_in(40);
int enhance = 0;
if (good + bad > max_properties)
{
enhance = good + bad - max_properties;
good = max_properties - bad;
}
// initialize a vector of weighted artefact properties to pick from
vector<pair<artefact_prop_type, int>> art_prop_weights;
for (int i = 0; i < ARTP_NUM_PROPERTIES; ++i)
{
art_prop_weights.emplace_back(static_cast<artefact_prop_type>(i),
artp_data[i].weight);
}
item_props.init(0);
// make sure all weapons have a brand
if (item_class == OBJ_WEAPONS)
_add_randart_weapon_brand(item, item_props);
// randomly pick properties from the list, choose an appropriate value,
// then subtract them from the good/bad/enhance count as needed
// the 'enhance' count is not guaranteed to be used.
while (good > 0 || bad > 0)
{
const artefact_prop_type *prop_ptr
= random_choose_weighted(art_prop_weights);
ASSERTM(prop_ptr, "all %d randart properties have weight 0?",
(int) art_prop_weights.size());
const artefact_prop_type prop = *prop_ptr;
if (!_artp_can_go_on_item(prop, item, item_props))
continue;
// should we try to generate a good or bad version of the prop?
const bool can_gen_good = good > 0 && artp_potentially_good(prop);
const bool can_gen_bad = bad > 0 && artp_potentially_bad(prop);
const bool gen_good = can_gen_good && (!can_gen_bad || coinflip());
if (gen_good)
{
// potentially increment the value of the property more than once,
// using up a good property each time.
// always do so if there's any 'enhance' left, if possible.
for (int chance_denom = 1;
item_props[prop] <= artp_data[prop].max_dup
&& (enhance > 0
|| good > 0 && one_chance_in(chance_denom));
chance_denom += artp_data[prop].odds_inc)
{
_add_good_randart_prop(prop, item_props);
if (enhance > 0 && chance_denom > 1)
--enhance;
else
--good;
}
}
else if (can_gen_bad)
{
item_props[prop] = artp_data[prop].gen_bad_value();
--bad;
}
else
continue;
// don't choose the same prop twice
const auto weight_tuple = make_pair(prop, artp_data[prop].weight);
const auto old_end = art_prop_weights.end();
const auto new_end = std::remove(art_prop_weights.begin(), old_end,
weight_tuple);
// That should have removed exactly one entry.
ASSERT(new_end == old_end - 1);
art_prop_weights.erase(new_end, old_end);
}
}
void setup_unrandart(item_def &item, bool creating)
{
ASSERT(is_unrandom_artefact(item));
CrawlVector &rap = item.props[ARTEFACT_PROPS_KEY].get_vector();
const unrandart_entry *unrand = _seekunrandart(item);
if (unrand->prpty[ARTP_NO_UPGRADE] && !creating)
return; // don't mangle mutable items
for (int i = 0; i < ART_PROPERTIES; i++)
rap[i] = static_cast<short>(unrand->prpty[i]);
item.base_type = unrand->base_type;
item.sub_type = unrand->sub_type;
item.plus = unrand->plus;
}
static bool _init_artefact_properties(item_def &item)
{
ASSERT(is_artefact(item));
if (is_unrandom_artefact(item))
{
setup_unrandart(item);
return true;
}
CrawlVector &rap = item.props[ARTEFACT_PROPS_KEY].get_vector();
for (vec_size i = 0; i < ART_PROPERTIES; i++)
rap[i] = static_cast<short>(0);
ASSERT(item.base_type != OBJ_BOOKS);
artefact_properties_t prop;
prop.init(0);
_get_randart_properties(item, prop);
for (int i = 0; i < ART_PROPERTIES; i++)
{
if (i == ARTP_CURSE && prop[i] < 0)
{
do_curse_item(item);
continue;
}
rap[i] = static_cast<short>(prop[i]);
}