Apply the new ground_level method.
[crawl.git] / crawl-ref / source / mon-gear.cc
blobdff9fd705288b5d2616438c162bb8e66d6b09a7d
1 /*
2 * File: mon-gear.cc
3 * Summary: Monsters' starting equipment.
4 */
6 #include "AppHdr.h"
8 #include <algorithm>
10 #include "enum.h"
11 #include "externs.h"
12 #include "mon-gear.h"
14 #include "artefact.h"
15 #include "colour.h"
16 #include "dungeon.h"
17 #include "env.h"
18 #include "itemprop.h"
19 #include "items.h"
20 #include "makeitem.h"
21 #include "mgen_enum.h"
22 #include "mon-place.h"
23 #include "mon-util.h"
24 #include "random.h"
25 #include "spl-book.h"
28 static void _give_monster_item(monster* mon, int thing,
29 bool force_item = false,
30 bool (monster::*pickupfn)(item_def&, int) = NULL,
31 bool keep_ident = false)
33 if (thing == NON_ITEM || thing == -1)
34 return;
36 item_def &mthing = mitm[thing];
37 ASSERT(mthing.defined());
39 #ifdef DEBUG_DIAGNOSTICS
40 mprf(MSGCH_DIAGNOSTICS,
41 "Giving %s to %s...", mthing.name(DESC_PLAIN).c_str(),
42 mon->name(DESC_PLAIN, true).c_str());
43 #endif
45 mthing.pos.reset();
46 mthing.link = NON_ITEM;
48 if (!keep_ident)
49 unset_ident_flags(mthing, ISFLAG_IDENT_MASK);
51 if ((mon->undead_or_demonic() || mon->god == GOD_YREDELEMNUL)
52 && (is_blessed(mthing)
53 || get_weapon_brand(mthing) == SPWPN_HOLY_WRATH))
55 if (is_blessed(mthing))
56 convert2bad(mthing);
57 if (get_weapon_brand(mthing) == SPWPN_HOLY_WRATH)
58 set_item_ego_type(mthing, OBJ_WEAPONS, SPWPN_NORMAL);
61 unwind_var<int> save_speedinc(mon->speed_increment);
62 if (!(pickupfn ? (mon->*pickupfn)(mthing, false)
63 : mon->pickup_item(mthing, false, true)))
65 #ifdef DEBUG_DIAGNOSTICS
66 mprf(MSGCH_DIAGNOSTICS, "Destroying %s because %s doesn't want it!",
67 mthing.name(DESC_PLAIN, false, true).c_str(),
68 mon->name(DESC_PLAIN, true).c_str());
69 #endif
70 destroy_item(thing, true);
71 return;
73 if (!mthing.defined()) // missiles merged into an existing stack
74 return;
75 ASSERT(mthing.holding_monster() == mon);
77 if (!force_item || mthing.colour == BLACK)
78 item_colour(mthing);
81 void give_specific_item(monster* mon, const item_def& tpl)
83 int thing = get_item_slot();
84 if (thing == NON_ITEM)
85 return;
87 mitm[thing] = tpl;
88 _give_monster_item(mon, thing, true, NULL, true);
91 static void _give_scroll(monster* mon, int level)
93 int thing_created = NON_ITEM;
95 if (mon->type == MONS_ROXANNE)
97 // Not a scroll, but this comes closest.
98 int which_book = (one_chance_in(3) ? BOOK_TRANSFIGURATIONS
99 : BOOK_EARTH);
101 thing_created = items(0, OBJ_BOOKS, which_book, true, level, 0);
103 if (thing_created != NON_ITEM && coinflip())
105 // Give Roxanne a random book containing Statue Form instead.
106 item_def &item(mitm[thing_created]);
107 make_book_Roxanne_special(&item);
108 _give_monster_item(mon, thing_created, true);
109 return;
112 else if (mons_is_unique(mon->type) && one_chance_in(3))
113 thing_created = items(0, OBJ_SCROLLS, OBJ_RANDOM, true, level, 0);
115 if (thing_created == NON_ITEM)
116 return;
118 mitm[thing_created].flags = 0;
119 _give_monster_item(mon, thing_created, true);
122 static void _give_wand(monster* mon, int level)
124 if (mons_is_unique(mon->type) && !mons_class_flag(mon->type, M_NO_WAND)
125 && (one_chance_in(5)
126 || (mon->type == MONS_MAURICE && one_chance_in(3))))
128 const int idx = items(0, OBJ_WANDS, OBJ_RANDOM, true, level, 0);
130 if (idx == NON_ITEM)
131 return;
133 item_def& wand = mitm[idx];
135 // Don't give top-tier wands before 5 HD.
136 if (mon->hit_dice < 5 || mons_class_flag(mon->type, M_NO_HT_WAND))
138 // Technically these wands will be undercharged, but it
139 // doesn't really matter.
140 if (wand.sub_type == WAND_FIRE)
141 wand.sub_type = WAND_FLAME;
143 if (wand.sub_type == WAND_COLD)
144 wand.sub_type = WAND_FROST;
146 if (wand.sub_type == WAND_LIGHTNING)
147 wand.sub_type = (coinflip() ? WAND_FLAME : WAND_FROST);
150 wand.flags = 0;
151 _give_monster_item(mon, idx);
155 static void _give_potion(monster* mon, int level)
157 if (mons_species(mon->type) == MONS_VAMPIRE
158 && (one_chance_in(5) || mon->type == MONS_JORY))
160 // This handles initialization of stack timer.
161 const int thing_created =
162 items(0, OBJ_POTIONS, POT_BLOOD, true, level, 0);
164 if (thing_created == NON_ITEM)
165 return;
167 mitm[thing_created].flags = 0;
168 _give_monster_item(mon, thing_created);
170 else if (mons_species(mon->type) == MONS_DEEP_DWARF && one_chance_in(3))
172 const int thing_created =
173 items(0, OBJ_POTIONS, coinflip() ? POT_HEAL_WOUNDS
174 : POT_HEALING, true, level, 0);
176 if (thing_created == NON_ITEM)
177 return;
179 mitm[thing_created].flags = 0;
180 _give_monster_item(mon, thing_created);
182 else if (mons_is_unique(mon->type) && one_chance_in(3))
184 const int thing_created =
185 items(0, OBJ_POTIONS, OBJ_RANDOM, true, level, 0);
187 if (thing_created == NON_ITEM)
188 return;
190 mitm[thing_created].flags = 0;
191 _give_monster_item(mon, thing_created, false,
192 &monster::pickup_potion);
196 static item_make_species_type _give_weapon(monster* mon, int level,
197 bool melee_only = false,
198 bool give_aux_melee = true,
199 bool spectral_orcs = false)
201 bool force_item = false;
203 item_def item;
204 item_make_species_type item_race = MAKE_ITEM_RANDOM_RACE;
205 int type = mon->type;
207 item.base_type = OBJ_UNASSIGNED;
209 if (mon->type == MONS_DANCING_WEAPON
210 && player_in_branch(BRANCH_HALL_OF_BLADES))
212 level = MAKE_GOOD_ITEM;
215 // moved setting of quantity here to keep it in mind {dlb}
216 item.quantity = 1;
218 if (spectral_orcs)
219 type = mon->number;
221 switch (type)
223 case MONS_KOBOLD:
224 // A few of the smarter kobolds have blowguns.
225 if (one_chance_in(10) && level > 1)
227 item.base_type = OBJ_WEAPONS;
228 item.sub_type = WPN_BLOWGUN;
229 break;
231 // intentional fallthrough
232 case MONS_BIG_KOBOLD:
233 if (x_chance_in_y(3, 5)) // give hand weapon
235 item.base_type = OBJ_WEAPONS;
236 item.sub_type = random_choose(WPN_DAGGER, WPN_DAGGER,
237 WPN_SHORT_SWORD, WPN_SHORT_SWORD,
238 WPN_CLUB, WPN_WHIP, -1);
240 else
241 return (item_race);
242 break;
244 case MONS_HOBGOBLIN:
245 if (one_chance_in(3))
246 item_race = MAKE_ITEM_ORCISH;
248 if (x_chance_in_y(3, 5)) // give hand weapon
250 item.base_type = OBJ_WEAPONS;
251 item.sub_type = WPN_CLUB;
253 else
254 return (item_race);
255 break;
257 case MONS_GOBLIN:
258 if (one_chance_in(3))
259 item_race = MAKE_ITEM_ORCISH;
261 if (!melee_only && one_chance_in(12) && level)
263 item.base_type = OBJ_WEAPONS;
264 item.sub_type = WPN_SLING;
265 break;
267 // deliberate fall through {dlb}
268 case MONS_JESSICA:
269 case MONS_IJYB:
270 if (x_chance_in_y(3, 5)) // give hand weapon
272 item.base_type = OBJ_WEAPONS;
273 item.sub_type = (coinflip() ? WPN_DAGGER : WPN_CLUB);
275 else
276 return (item_race);
277 break;
279 case MONS_WIGHT:
280 case MONS_NORRIS:
281 item.base_type = OBJ_WEAPONS;
283 if (one_chance_in(6))
285 item.sub_type = random_choose(WPN_SPIKED_FLAIL, WPN_GREAT_MACE,
286 WPN_WAR_AXE, WPN_TRIDENT, -1);
288 else
290 item.sub_type = random_choose(
291 WPN_MACE, WPN_FLAIL, WPN_MORNINGSTAR,
292 WPN_DAGGER, WPN_SHORT_SWORD, WPN_LONG_SWORD,
293 WPN_SCIMITAR, WPN_GREAT_SWORD, WPN_HAND_AXE,
294 WPN_BATTLEAXE, WPN_SPEAR, WPN_HALBERD,
295 -1);
298 if (coinflip())
300 force_item = true;
301 item.plus += 1 + random2(3);
302 item.plus2 += 1 + random2(3);
304 if (one_chance_in(5))
305 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_FREEZING);
308 if (one_chance_in(3))
309 do_curse_item(item);
310 break;
312 case MONS_EDMUND:
313 item_race = MAKE_ITEM_NO_RACE;
314 item.base_type = OBJ_WEAPONS;
315 item.sub_type = random_choose_weighted (30, WPN_FLAIL, 10, WPN_SPIKED_FLAIL,
316 5, WPN_DIRE_FLAIL, 0);
317 // "expensive" flail. {due}
318 if (item.sub_type == WPN_FLAIL)
319 level = MAKE_GOOD_ITEM;
321 break;
323 case MONS_DWARF:
324 case MONS_DEEP_DWARF:
325 item_race = MAKE_ITEM_DWARVEN;
326 if (one_chance_in(9))
328 item.base_type = OBJ_WEAPONS;
329 item.sub_type = WPN_CROSSBOW;
330 break;
332 // deliberate fall through
333 case MONS_DEEP_DWARF_SCION:
334 case MONS_DEEP_DWARF_DEATH_KNIGHT:
335 case MONS_DEEP_DWARF_BERSERKER:
336 item_race = MAKE_ITEM_DWARVEN;
337 item.base_type = OBJ_WEAPONS;
339 if (one_chance_in(6))
341 item.sub_type = random_choose_weighted(5, WPN_SPIKED_FLAIL, 5, WPN_GREAT_MACE,
342 5, WPN_GREAT_SWORD, 10, WPN_BROAD_AXE,
343 15, WPN_BATTLEAXE, 0);
345 else
347 item.sub_type = random_choose_weighted(5, WPN_FLAIL, 5, WPN_MACE,
348 5, WPN_SPEAR, 5, WPN_HALBERD,
349 5, WPN_GREAT_SWORD, 10, WPN_WAR_AXE,
350 15, WPN_HAND_AXE, 0);
353 if (coinflip() || mon->type == MONS_DEEP_DWARF_BERSERKER
354 || mon->type == MONS_DEEP_DWARF_SCION)
356 force_item = true;
357 item.plus += 1 + random2(4);
358 item.plus2 += 1 + random2(4);
360 if (one_chance_in(30) && (mon->type == MONS_DEEP_DWARF_BERSERKER
361 || mon->type == MONS_DEEP_DWARF_SCION))
363 level = MAKE_GOOD_ITEM;
366 else if (one_chance_in(3) && mon->type != MONS_DEEP_DWARF_BERSERKER)
368 item.plus = -1 + (-1 * random2(4));
369 item.plus2 = -1 + (-1 * random2(4));
370 do_curse_item(item);
372 break;
374 case MONS_GNOLL:
375 case MONS_OGRE_MAGE:
376 case MONS_NAGA_WARRIOR:
377 case MONS_GREATER_NAGA:
378 item_race = MAKE_ITEM_NO_RACE;
379 if (!one_chance_in(5))
381 item.base_type = OBJ_WEAPONS;
382 item.sub_type = random_choose(WPN_SPEAR, WPN_SPEAR, WPN_HALBERD,
383 WPN_CLUB, WPN_WHIP, WPN_FLAIL, -1);
385 break;
387 case MONS_PIKEL:
388 force_item = true; // guaranteed flaming or pain
389 item.base_type = OBJ_WEAPONS;
390 item.sub_type = WPN_WHIP;
391 set_item_ego_type(item, OBJ_WEAPONS, coinflip() ? SPWPN_PAIN : SPWPN_FLAMING);
392 item.plus += random2(3);
393 item.plus2 += random2(3);
394 break;
396 case MONS_GRUM:
397 force_item = true; // guaranteed reaching
398 item_race = MAKE_ITEM_NO_RACE;
399 item.base_type = OBJ_WEAPONS;
400 item.sub_type = random_choose(WPN_WHIP, WPN_WHIP, WPN_SPEAR,
401 WPN_HALBERD, WPN_GLAIVE, -1);
402 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_REACHING);
403 item.plus += -2 + random2(4);
404 item.plus2 += -1 + random2(2);
405 break;
407 case MONS_CRAZY_YIUF:
408 force_item = true; // guaranteed chaos
409 item_race = MAKE_ITEM_NO_RACE;
410 item.base_type = OBJ_WEAPONS;
411 item.sub_type = WPN_QUARTERSTAFF;
412 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_CHAOS);
413 item.plus += 2 + random2(3);
414 item.plus2 += 2 + random2(3);
415 break;
417 case MONS_JOSEPH:
418 if (!melee_only)
420 item.base_type = OBJ_WEAPONS;
421 item.sub_type = WPN_SLING;
422 break;
424 item_race = MAKE_ITEM_NO_RACE;
425 item.base_type = OBJ_WEAPONS;
426 item.sub_type = WPN_QUARTERSTAFF;
427 break;
429 case MONS_GRINDER:
430 force_item = true; // guaranteed pain
431 item.base_type = OBJ_WEAPONS;
432 item.sub_type = random_choose_weighted(
433 30, WPN_DAGGER, 20, WPN_HAMMER,
434 5, WPN_WHIP,
436 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_PAIN);
438 break;
441 case MONS_ORC:
442 case MONS_ORC_PRIEST:
443 item_race = MAKE_ITEM_ORCISH;
444 // deliberate fall through {gdl}
446 case MONS_DRACONIAN:
447 case MONS_DRACONIAN_ZEALOT:
448 if (!one_chance_in(5))
450 item.base_type = OBJ_WEAPONS;
451 item.sub_type = random_choose_weighted(
452 30, WPN_DAGGER, 30, WPN_CLUB,
453 27, WPN_FLAIL, 24, WPN_HAND_AXE,
454 20, WPN_HAMMER, 20, WPN_SHORT_SWORD,
455 20, WPN_MACE, 10, WPN_WHIP,
456 10, WPN_TRIDENT, 10, WPN_FALCHION,
457 10, WPN_MORNINGSTAR, 6, WPN_WAR_AXE,
458 3, WPN_SPIKED_FLAIL,
461 else
462 return (item_race);
463 break;
465 case MONS_TERENCE:
466 item.base_type = OBJ_WEAPONS;
467 item.sub_type = random_choose_weighted(30, WPN_FLAIL,
468 20, WPN_HAND_AXE,
469 20, WPN_SHORT_SWORD,
470 20, WPN_MACE,
471 10, WPN_TRIDENT,
472 10, WPN_FALCHION,
473 10, WPN_MORNINGSTAR,
474 3, WPN_SPIKED_FLAIL,
476 break;
478 case MONS_DUVESSA:
479 item_race = MAKE_ITEM_ELVEN;
480 item.base_type = OBJ_WEAPONS;
481 item.sub_type = random_choose_weighted(30, WPN_SHORT_SWORD,
482 10, WPN_SABRE,
484 break;
486 case MONS_MARA:
487 item.base_type = OBJ_WEAPONS;
488 item.sub_type = random_choose(WPN_DEMON_BLADE, WPN_DEMON_TRIDENT,
489 WPN_DEMON_WHIP, -1);
490 level = MAKE_GOOD_ITEM;
491 break;
493 case MONS_ELF:
494 case MONS_DEEP_ELF_FIGHTER:
495 case MONS_DEEP_ELF_HIGH_PRIEST:
496 case MONS_DEEP_ELF_KNIGHT:
497 case MONS_DEEP_ELF_PRIEST:
498 case MONS_DEEP_ELF_SOLDIER:
499 item_race = MAKE_ITEM_ELVEN;
500 item.base_type = OBJ_WEAPONS;
501 item.sub_type = random_choose_weighted(
502 22, WPN_LONG_SWORD, 22, WPN_SHORT_SWORD, 17, WPN_SCIMITAR,
503 17, WPN_BOW, 5, WPN_LONGBOW,
505 break;
507 case MONS_DEEP_ELF_BLADEMASTER:
509 item_race = MAKE_ITEM_ELVEN;
510 item.base_type = OBJ_WEAPONS;
512 // If the blademaster already has a weapon, give him the exact same
513 // sub_type to match.
515 const item_def *weap = mon->mslot_item(MSLOT_WEAPON);
516 if (weap && weap->base_type == OBJ_WEAPONS)
517 item.sub_type = weap->sub_type;
518 else
520 item.sub_type = random_choose_weighted(40, WPN_SABRE,
521 10, WPN_SHORT_SWORD,
522 2, WPN_QUICK_BLADE,
525 break;
528 case MONS_DEEP_ELF_MASTER_ARCHER:
529 item_race = MAKE_ITEM_ELVEN;
530 item.base_type = OBJ_WEAPONS;
531 item.sub_type = WPN_LONGBOW;
532 break;
534 case MONS_DEEP_ELF_ANNIHILATOR:
535 case MONS_DEEP_ELF_CONJURER:
536 case MONS_DEEP_ELF_DEATH_MAGE:
537 case MONS_DEEP_ELF_DEMONOLOGIST:
538 case MONS_DEEP_ELF_MAGE:
539 case MONS_DEEP_ELF_SORCERER:
540 case MONS_DEEP_ELF_SUMMONER:
541 item_race = MAKE_ITEM_ELVEN;
542 item.base_type = OBJ_WEAPONS;
543 item.sub_type = random_choose(WPN_LONG_SWORD, WPN_LONG_SWORD,
544 WPN_SHORT_SWORD, WPN_SABRE,
545 WPN_DAGGER,
546 -1);
547 break;
549 case MONS_DRACONIAN_SHIFTER:
550 case MONS_DRACONIAN_SCORCHER:
551 case MONS_DRACONIAN_ANNIHILATOR:
552 case MONS_DRACONIAN_CALLER:
553 item.base_type = OBJ_WEAPONS;
554 item.sub_type = random_choose(WPN_LONG_SWORD, WPN_LONG_SWORD,
555 WPN_SHORT_SWORD, WPN_SABRE,
556 WPN_DAGGER, WPN_WHIP,
557 -1);
558 break;
560 case MONS_ORC_WARRIOR:
561 case MONS_ORC_HIGH_PRIEST:
562 case MONS_BLORK_THE_ORC:
563 item_race = MAKE_ITEM_ORCISH;
564 // deliberate fall-through {dlb}
566 case MONS_DANCING_WEAPON: // give_level may have been adjusted above
567 case MONS_FRANCES:
568 case MONS_HAROLD:
569 case MONS_LOUISE:
570 case MONS_NAGA:
571 case MONS_NAGA_MAGE:
572 case MONS_SKELETAL_WARRIOR:
573 case MONS_PALE_DRACONIAN:
574 case MONS_RED_DRACONIAN:
575 case MONS_WHITE_DRACONIAN:
576 case MONS_GREEN_DRACONIAN:
577 case MONS_MOTTLED_DRACONIAN:
578 case MONS_BLACK_DRACONIAN:
579 case MONS_YELLOW_DRACONIAN:
580 case MONS_PURPLE_DRACONIAN:
581 case MONS_GREY_DRACONIAN:
582 if (mons_genus(mon->type) == MONS_NAGA)
583 item_race = MAKE_ITEM_NO_RACE;
585 item.base_type = OBJ_WEAPONS;
586 item.sub_type = random_choose_weighted(
587 10, WPN_LONG_SWORD, 10, WPN_SHORT_SWORD,
588 10, WPN_SCIMITAR, 10, WPN_BATTLEAXE,
589 10, WPN_HAND_AXE, 10, WPN_HALBERD,
590 10, WPN_GLAIVE, 10, WPN_MORNINGSTAR,
591 10, WPN_GREAT_MACE, 10, WPN_TRIDENT,
592 9, WPN_WAR_AXE, 9, WPN_FLAIL,
593 1, WPN_BROAD_AXE, 1, WPN_SPIKED_FLAIL,
595 break;
597 case MONS_TIAMAT:
598 item.base_type = OBJ_WEAPONS;
599 item.sub_type = random_choose(WPN_BARDICHE, WPN_DEMON_TRIDENT,
600 WPN_GLAIVE, -1);
601 level = MAKE_GOOD_ITEM;
602 break;
605 case MONS_RUPERT:
606 item.base_type = OBJ_WEAPONS;
607 // Rupert favours big two-handers with visceral up-close
608 // effects, i.e. no polearms.
609 item.sub_type = random_choose_weighted(10, WPN_GREAT_MACE,
610 6, WPN_GREAT_SWORD,
611 2, WPN_TRIPLE_SWORD,
612 8, WPN_BATTLEAXE,
613 2, WPN_EXECUTIONERS_AXE,
615 level = MAKE_GOOD_ITEM;
616 break;
618 case MONS_WIGLAF:
619 item_race = MAKE_ITEM_DWARVEN;
621 item.base_type = OBJ_WEAPONS;
622 // speech references an axe
623 item.sub_type = random_choose(WPN_WAR_AXE, WPN_BROAD_AXE,
624 WPN_BATTLEAXE, -1);
625 break;
627 case MONS_ORC_WARLORD:
628 case MONS_SAINT_ROKA:
629 // being at the top has its privileges
630 if (one_chance_in(3))
631 level = MAKE_GOOD_ITEM;
632 // deliberate fall-through
634 case MONS_ORC_KNIGHT:
635 item_race = MAKE_ITEM_ORCISH;
636 // Occasionally get crossbows.
637 if (!melee_only && one_chance_in(9))
639 item.base_type = OBJ_WEAPONS;
640 item.sub_type = WPN_CROSSBOW;
641 break;
643 // deliberate fall-through
645 case MONS_URUG:
646 item_race = MAKE_ITEM_ORCISH;
647 // deliberate fall-through
649 case MONS_JOZEF:
650 case MONS_VAULT_GUARD:
651 case MONS_VAMPIRE_KNIGHT:
652 case MONS_DRACONIAN_KNIGHT:
653 case MONS_JORY:
655 item.base_type = OBJ_WEAPONS;
657 item.sub_type = random_choose_weighted(
658 4, WPN_GREAT_SWORD, 4, WPN_LONG_SWORD,
659 4, WPN_BATTLEAXE, 4, WPN_WAR_AXE,
660 3, WPN_GREAT_MACE, 2, WPN_DIRE_FLAIL,
661 1, WPN_BARDICHE, 1, WPN_GLAIVE,
662 1, WPN_BROAD_AXE, 1, WPN_HALBERD,
665 if (one_chance_in(4))
666 item.plus += 1 + random2(3);
667 break;
670 case MONS_POLYPHEMUS:
671 case MONS_CYCLOPS:
672 case MONS_STONE_GIANT:
673 item.base_type = OBJ_MISSILES;
674 item.sub_type = MI_LARGE_ROCK;
675 break;
677 case MONS_TWO_HEADED_OGRE:
678 case MONS_ETTIN:
679 case MONS_IRON_GIANT:
680 item_race = MAKE_ITEM_NO_RACE;
681 item.base_type = OBJ_WEAPONS;
682 item.sub_type = (one_chance_in(3) ? WPN_GIANT_SPIKED_CLUB
683 : WPN_GIANT_CLUB);
685 if (one_chance_in(10) || mon->type == MONS_ETTIN)
687 item.sub_type = (one_chance_in(10) ? WPN_DIRE_FLAIL
688 : WPN_GREAT_MACE);
690 break;
692 case MONS_REAPER:
693 level = MAKE_GOOD_ITEM;
694 // intentional fall-through...
695 case MONS_SIGMUND:
696 item.base_type = OBJ_WEAPONS;
697 item.sub_type = WPN_SCYTHE;
698 break;
700 case MONS_BALRUG:
701 item.base_type = OBJ_WEAPONS;
702 item.sub_type = WPN_DEMON_WHIP;
703 break;
705 case MONS_RED_DEVIL:
706 if (!one_chance_in(3))
708 item_race = MAKE_ITEM_NO_RACE;
709 item.base_type = OBJ_WEAPONS;
710 item.sub_type = (one_chance_in(3) ? WPN_DEMON_TRIDENT
711 : WPN_TRIDENT);
713 break;
715 case MONS_OGRE:
716 case MONS_HILL_GIANT:
717 case MONS_EROLCHA:
718 item_race = MAKE_ITEM_NO_RACE;
719 item.base_type = OBJ_WEAPONS;
720 item.sub_type = (one_chance_in(3) ? WPN_GIANT_SPIKED_CLUB
721 : WPN_GIANT_CLUB);
723 if (one_chance_in(10))
725 item.sub_type = (one_chance_in(10) ? WPN_DIRE_FLAIL
726 : WPN_GREAT_MACE);
728 break;
730 case MONS_ILSUIW:
731 item_race = MAKE_ITEM_NO_RACE;
732 item.base_type = OBJ_WEAPONS;
733 item.sub_type = WPN_TRIDENT;
734 item.special = SPWPN_FREEZING;
735 item.plus = random_range(-1, 6, 2);
736 item.plus2 = random_range(-1, 6, 2);
737 item.colour = ETC_ICE;
738 force_item = true;
739 break;
741 case MONS_MERFOLK_IMPALER:
742 item_race = MAKE_ITEM_NO_RACE;
743 item.base_type = OBJ_WEAPONS;
744 item.sub_type = random_choose_weighted(100, WPN_TRIDENT,
745 15, WPN_DEMON_TRIDENT,
747 if (coinflip())
748 level = MAKE_GOOD_ITEM;
749 else if (coinflip())
751 // Per dpeg request :)
752 item.special = SPWPN_REACHING;
753 item.plus = random_range(-1, 6, 2);
754 item.plus2 = random_range(-1, 5, 2);
755 force_item = true;
757 break;
760 case MONS_MERFOLK_AQUAMANCER:
761 item_race = MAKE_ITEM_NO_RACE;
762 item.base_type = OBJ_WEAPONS;
763 item.sub_type = WPN_SABRE;
764 if (coinflip())
765 level = MAKE_GOOD_ITEM;
766 break;
768 case MONS_MERFOLK_JAVELINEER:
769 item_race = MAKE_ITEM_NO_RACE;
770 item.base_type = OBJ_WEAPONS;
771 item.sub_type = WPN_SPEAR;
772 if (!one_chance_in(3))
773 level = MAKE_GOOD_ITEM;
774 break;
776 case MONS_MERFOLK:
777 if (active_monster_band == BAND_MERFOLK_IMPALER)
779 item_race = MAKE_ITEM_NO_RACE;
780 item.base_type = OBJ_WEAPONS;
781 item.sub_type = random_choose_weighted(10, WPN_SPEAR,
782 10, WPN_TRIDENT,
783 5, WPN_HALBERD,
784 5, WPN_GLAIVE,
786 break;
788 if (one_chance_in(3))
790 item_race = MAKE_ITEM_NO_RACE;
791 item.base_type = OBJ_WEAPONS;
792 item.sub_type = WPN_TRIDENT;
793 break;
795 // intentionally fall through
797 case MONS_MERMAID:
798 if (one_chance_in(3))
800 item_race = MAKE_ITEM_NO_RACE;
801 item.base_type = OBJ_WEAPONS;
802 item.sub_type = WPN_SPEAR;
804 break;
806 case MONS_CENTAUR:
807 case MONS_CENTAUR_WARRIOR:
808 item_race = MAKE_ITEM_NO_RACE;
809 item.base_type = OBJ_WEAPONS;
810 item.sub_type = WPN_BOW;
811 if (mon->type == MONS_CENTAUR_WARRIOR && one_chance_in(3))
812 item.sub_type = WPN_LONGBOW;
813 break;
815 case MONS_NESSOS:
816 item_race = MAKE_ITEM_NO_RACE;
817 item.base_type = OBJ_WEAPONS;
818 item.sub_type = WPN_LONGBOW;
819 item.special = SPWPN_FLAME;
820 item.plus += 1 + random2(3);
821 item.plus2 += 1 + random2(3);
822 item.colour = DARKGREY;
823 force_item = true;
824 break;
826 case MONS_YAKTAUR:
827 case MONS_YAKTAUR_CAPTAIN:
828 item_race = MAKE_ITEM_NO_RACE;
829 item.base_type = OBJ_WEAPONS;
830 item.sub_type = WPN_CROSSBOW;
831 break;
833 case MONS_EFREET:
834 case MONS_ERICA:
835 case MONS_AZRAEL:
836 force_item = true;
837 item_race = MAKE_ITEM_NO_RACE;
838 item.base_type = OBJ_WEAPONS;
839 item.sub_type = WPN_SCIMITAR;
840 item.plus = random2(5);
841 item.plus2 = random2(5);
842 item.colour = RED; // forced by force_item above {dlb}
843 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_FLAMING);
844 break;
846 case MONS_ANGEL:
847 case MONS_CHERUB:
848 force_item = true;
849 item_race = MAKE_ITEM_NO_RACE;
850 item.base_type = OBJ_WEAPONS;
851 item.colour = YELLOW; // forced by force_item above {dlb}
853 item.sub_type = (one_chance_in(4) ? WPN_SACRED_SCOURGE
854 : WPN_WHIP);
856 set_equip_desc(item, ISFLAG_GLOWING);
857 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_HOLY_WRATH);
858 item.plus = 1 + random2(3);
859 item.plus2 = 1 + random2(3);
860 break;
862 case MONS_PALADIN:
863 case MONS_DAEVA:
864 case MONS_MENNAS:
865 force_item = true;
866 item_race = MAKE_ITEM_NO_RACE;
867 item.base_type = OBJ_WEAPONS;
868 item.colour = YELLOW; // forced by force_item above {dlb}
870 item.sub_type = (one_chance_in(4) ? WPN_EUDEMON_BLADE
871 : WPN_LONG_SWORD);
873 set_equip_desc(item, ISFLAG_GLOWING);
874 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_HOLY_WRATH);
875 item.plus = 1 + random2(3);
876 item.plus2 = 1 + random2(3);
877 break;
879 case MONS_DONALD:
880 force_item = true;
881 item.base_type = OBJ_WEAPONS;
882 item.sub_type = random_choose_weighted(12, WPN_SCIMITAR,
883 11, WPN_LONG_SWORD,
884 1, WPN_EVENINGSTAR,
885 4, WPN_WAR_AXE,
886 5, WPN_BROAD_AXE,
887 6, WPN_DEMON_WHIP,
888 7, WPN_DEMON_BLADE,
889 7, WPN_DEMON_TRIDENT,
892 if (x_chance_in_y(5, 9))
894 set_item_ego_type(item, OBJ_WEAPONS,
895 random_choose_weighted(15, SPWPN_FLAMING,
896 2, SPWPN_DRAINING,
897 2, SPWPN_VORPAL,
898 2, SPWPN_DISTORTION,
899 2, SPWPN_SPEED,
900 2, SPWPN_PAIN,
901 0));
904 item.plus += random2(6);
905 item.plus2 += random2(6);
907 item.colour = random_choose_weighted(1, CYAN,
908 1, DARKGREY,
909 2, BLUE,
912 break;
914 case MONS_HELL_KNIGHT:
915 case MONS_MAUD:
916 case MONS_FREDERICK:
917 case MONS_MARGERY:
918 force_item = true;
919 item.base_type = OBJ_WEAPONS;
920 item.sub_type = random_choose_weighted(5, WPN_HALBERD,
921 5, WPN_GLAIVE,
922 6, WPN_WAR_AXE,
923 6, WPN_GREAT_MACE,
924 7, WPN_BATTLEAXE,
925 8, WPN_LONG_SWORD,
926 8, WPN_SCIMITAR,
927 8, WPN_GREAT_SWORD,
928 9, WPN_BROAD_AXE,
929 10, WPN_DEMON_WHIP,
930 13, WPN_DEMON_BLADE,
931 14, WPN_DEMON_TRIDENT,
934 if (x_chance_in_y(5, 9))
936 set_item_ego_type(item, OBJ_WEAPONS,
937 random_choose_weighted(15, SPWPN_FLAMING,
938 2, SPWPN_DRAINING,
939 2, SPWPN_VORPAL,
940 2, SPWPN_DISTORTION,
941 2, SPWPN_SPEED,
942 2, SPWPN_PAIN,
943 0));
946 item.plus += random2(6);
947 item.plus2 += random2(6);
949 item.colour = random_choose_weighted(3, CYAN,
950 4, DARKGREY,
951 8, RED,
953 break;
955 case MONS_FIRE_GIANT:
956 force_item = true;
957 item_race = MAKE_ITEM_NO_RACE;
958 item.base_type = OBJ_WEAPONS;
959 item.sub_type = WPN_GREAT_SWORD;
960 item.plus = 0;
961 item.plus2 = 0;
962 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_FLAMING);
964 item.colour = random_choose_weighted(3, CYAN,
965 4, DARKGREY,
966 8, RED,
969 break;
971 case MONS_FROST_GIANT:
972 force_item = true;
973 item_race = MAKE_ITEM_NO_RACE;
974 item.base_type = OBJ_WEAPONS;
975 item.sub_type = WPN_BATTLEAXE;
976 item.plus = 0;
977 item.plus2 = 0;
978 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_FREEZING);
980 // forced by force_item above {dlb}
981 item.colour = (one_chance_in(3) ? WHITE : CYAN);
982 break;
984 case MONS_ORC_WIZARD:
985 case MONS_ORC_SORCERER:
986 case MONS_NERGALLE:
987 item_race = MAKE_ITEM_ORCISH;
988 item.base_type = OBJ_WEAPONS;
989 item.sub_type = WPN_DAGGER;
990 break;
992 case MONS_UNBORN_DEEP_DWARF:
993 if (one_chance_in(6))
994 level = MAKE_GOOD_ITEM;
995 // deliberate fallthrough
997 case MONS_DEEP_DWARF_NECROMANCER:
998 item_race = MAKE_ITEM_DWARVEN;
999 item.base_type = OBJ_WEAPONS;
1000 item.sub_type = WPN_HAND_AXE;
1001 break;
1003 case MONS_DEEP_DWARF_ARTIFICER:
1004 if (coinflip())
1006 item.base_type = OBJ_STAVES;
1007 item.sub_type = STAFF_STRIKING;
1009 else if (one_chance_in(100))
1011 dprf("generating a rare rod");
1012 const int rand_staff = random2(NUM_STAVES - STAFF_FIRST_ROD)
1013 + STAFF_FIRST_ROD;
1014 item.base_type = OBJ_STAVES;
1015 item.sub_type = rand_staff;
1017 else
1019 item_race = MAKE_ITEM_DWARVEN;
1020 item.base_type = OBJ_WEAPONS;
1021 item.sub_type = ((one_chance_in(3))? WPN_HAND_AXE: WPN_BROAD_AXE);
1023 break;
1025 case MONS_DOWAN:
1026 item_race = MAKE_ITEM_ELVEN;
1027 item.base_type = OBJ_WEAPONS;
1028 item.sub_type = WPN_DAGGER;
1029 break;
1031 case MONS_KOBOLD_DEMONOLOGIST:
1032 case MONS_NECROMANCER:
1033 case MONS_WIZARD:
1034 case MONS_PSYCHE:
1035 case MONS_JOSEPHINE:
1036 item.base_type = OBJ_WEAPONS;
1037 item.sub_type = WPN_DAGGER;
1039 if (mon->type == MONS_PSYCHE)
1041 force_item = true;
1042 set_item_ego_type(item, OBJ_WEAPONS,
1043 random_choose_weighted(3, SPWPN_CHAOS,
1044 1, SPWPN_DISTORTION,
1045 0));
1047 break;
1049 case MONS_AGNES:
1050 item.base_type = OBJ_WEAPONS;
1051 item.sub_type = WPN_LAJATANG;
1052 if (!one_chance_in(3))
1053 level = MAKE_GOOD_ITEM;
1054 break;
1056 case MONS_SONJA:
1057 if (!melee_only)
1059 item.base_type = OBJ_WEAPONS;
1060 item.sub_type = WPN_BLOWGUN;
1061 item_race = MAKE_ITEM_NO_RACE;
1062 break;
1064 force_item = true;
1065 item_race = MAKE_ITEM_NO_RACE;
1066 item.base_type = OBJ_WEAPONS;
1067 item.sub_type = coinflip() ? WPN_DAGGER : WPN_SHORT_SWORD;
1068 set_item_ego_type(item, OBJ_WEAPONS,
1069 random_choose_weighted(3, SPWPN_DISTORTION,
1070 2, SPWPN_VENOM,
1071 1, SPWPN_DRAINING,
1072 0));
1073 break;
1075 case MONS_MAURICE:
1076 item_race = MAKE_ITEM_NO_RACE;
1077 item.base_type = OBJ_WEAPONS;
1078 item.sub_type = coinflip() ? WPN_DAGGER : WPN_SHORT_SWORD;
1079 break;
1081 case MONS_EUSTACHIO:
1082 item_race = MAKE_ITEM_NO_RACE;
1083 item.base_type = OBJ_WEAPONS;
1084 item.sub_type = (one_chance_in(3) ? WPN_FALCHION : WPN_SABRE);
1085 break;
1087 case MONS_NIKOLA:
1088 force_item = true;
1089 item_race = MAKE_ITEM_NO_RACE;
1090 item.base_type = OBJ_WEAPONS;
1091 item.sub_type = WPN_SABRE;
1092 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_ELECTROCUTION);
1093 item.plus = random2(5);
1094 item.plus2 = random2(5);
1095 break;
1097 case MONS_CEREBOV:
1098 force_item = true;
1099 make_item_unrandart(item, UNRAND_CEREBOV);
1100 break;
1102 case MONS_DISPATER:
1103 force_item = true;
1104 make_item_unrandart(item, UNRAND_DISPATER);
1105 break;
1107 case MONS_ASMODEUS:
1108 force_item = true;
1109 make_item_unrandart(item, UNRAND_ASMODEUS);
1110 break;
1112 case MONS_GERYON:
1113 // mv: Probably should be moved out of this switch, but it's not
1114 // worth it, unless we have more monsters with misc. items.
1115 item.base_type = OBJ_MISCELLANY;
1116 item.sub_type = MISC_HORN_OF_GERYON;
1117 break;
1119 case MONS_SALAMANDER: // mv: new 8 Aug 2001
1120 // Yes, they've got really nice items, but
1121 // it's almost impossible to get them.
1122 force_item = true;
1123 item_race = MAKE_ITEM_NO_RACE;
1124 item.base_type = OBJ_WEAPONS;
1125 item.sub_type = random_choose(WPN_GREAT_SWORD, WPN_TRIDENT,
1126 WPN_SPEAR, WPN_GLAIVE,
1127 WPN_BOW, WPN_HALBERD,
1128 -1);
1130 set_item_ego_type(item, OBJ_WEAPONS, is_range_weapon(item) ?
1131 SPWPN_FLAME : SPWPN_FLAMING);
1133 item.plus = random2(5);
1134 item.plus2 = random2(5);
1135 item.colour = RED; // forced by force_item above {dlb}
1136 break;
1138 case MONS_SPRIGGAN:
1139 item_race = MAKE_ITEM_NO_RACE;
1140 item.base_type = OBJ_WEAPONS;
1141 // no quick blades for mooks
1142 item.sub_type = random_choose(WPN_DAGGER, WPN_SHORT_SWORD,
1143 WPN_SABRE, -1);
1144 break;
1146 case MONS_SPRIGGAN_RIDER:
1147 if (!melee_only && one_chance_in(4))
1149 item.base_type = OBJ_WEAPONS;
1150 item.sub_type = WPN_BLOWGUN;
1151 item_race = MAKE_ITEM_NO_RACE;
1152 break;
1154 item_race = MAKE_ITEM_NO_RACE;
1155 item.base_type = OBJ_WEAPONS;
1156 item.sub_type = WPN_SPEAR;
1157 break;
1159 case MONS_SPRIGGAN_BERSERKER:
1160 item_race = MAKE_ITEM_NO_RACE;
1161 item.base_type = OBJ_WEAPONS;
1162 item.sub_type = random_choose(WPN_HAND_AXE,
1163 WPN_MACE,
1164 WPN_SHORT_SWORD,
1165 -1);
1166 break;
1168 case MONS_SPRIGGAN_DRUID:
1169 item_race = MAKE_ITEM_NO_RACE;
1170 item.base_type = OBJ_WEAPONS;
1171 item.sub_type = WPN_QUARTERSTAFF;
1172 break;
1174 case MONS_SPRIGGAN_DEFENDER:
1175 case MONS_THE_ENCHANTRESS:
1176 // High end gear, but alas, with an extra chance for distortion.
1177 item_race = MAKE_ITEM_NO_RACE;
1178 item.base_type = OBJ_WEAPONS;
1179 item.sub_type = random_choose(WPN_LAJATANG, // best spriggan weapon
1180 WPN_QUICK_BLADE, // overrated
1181 WPN_SABRE, // ordinary but popular
1182 WPN_DEMON_WHIP, // goodness
1183 WPN_FLAIL, // best ordinary 1.5-handed
1184 -1);
1185 level = MAKE_GOOD_ITEM;
1186 if (one_chance_in(mon->type == MONS_THE_ENCHANTRESS ? 4 : 10))
1188 force_item = true;
1189 set_item_ego_type(item, OBJ_WEAPONS, SPWPN_DISTORTION);
1190 item.plus = random2(5);
1191 item.plus2 = random2(5);
1193 break;
1195 default:
1196 break;
1199 // Only happens if something in above switch doesn't set it. {dlb}
1200 if (item.base_type == OBJ_UNASSIGNED)
1201 return (item_race);
1203 if (!force_item && mons_is_unique(mon->type))
1205 if (x_chance_in_y(10 + mon->hit_dice, 100))
1206 level = MAKE_GOOD_ITEM;
1207 else if (level != MAKE_GOOD_ITEM)
1208 level += 5;
1211 const object_class_type xitc = item.base_type;
1212 const int xitt = item.sub_type;
1214 // Note this mess, all the work above doesn't mean much unless
1215 // force_item is set... otherwise we're just going to take the base
1216 // and subtype and create a new item. - bwr
1217 const int thing_created =
1218 ((force_item) ? get_item_slot() : items(0, xitc, xitt, true,
1219 level, item_race));
1221 if (thing_created == NON_ITEM)
1222 return (item_race);
1224 // Copy temporary item into the item array if were forcing it, since
1225 // items() won't have done it for us.
1226 if (force_item)
1227 mitm[thing_created] = item;
1229 item_def &i = mitm[thing_created];
1230 if (melee_only && (i.base_type != OBJ_WEAPONS || is_range_weapon(i)))
1232 destroy_item(thing_created);
1233 return (item_race);
1236 if (force_item)
1237 item_set_appearance(i);
1239 _give_monster_item(mon, thing_created, force_item);
1241 if (give_aux_melee && (i.base_type != OBJ_WEAPONS || is_range_weapon(i)))
1242 _give_weapon(mon, level, true, false);
1244 return (item_race);
1247 // Hands out ammunition fitting the monster's launcher (if any), or else any
1248 // throwable weapon depending on the monster type.
1249 static void _give_ammo(monster* mon, int level,
1250 item_make_species_type item_race,
1251 bool mons_summoned)
1253 // Note that item_race is not reset for this section.
1254 if (const item_def *launcher = mon->launcher())
1256 const object_class_type xitc = OBJ_MISSILES;
1257 int xitt = fires_ammo_type(*launcher);
1259 if (xitt == MI_STONE && (one_chance_in(15) || mon->type == MONS_JOSEPH))
1260 xitt = MI_SLING_BULLET;
1262 const int thing_created = items(0, xitc, xitt, true, level, item_race);
1264 if (thing_created == NON_ITEM)
1265 return;
1267 if (xitt == MI_NEEDLE)
1269 if (mon->type == MONS_SONJA)
1271 set_item_ego_type(mitm[thing_created], OBJ_MISSILES,
1272 SPMSL_CURARE);
1274 mitm[thing_created].quantity = random_range(4, 10);
1276 else
1278 set_item_ego_type(mitm[thing_created], OBJ_MISSILES,
1279 got_curare_roll(level) ? SPMSL_CURARE
1280 : SPMSL_POISONED);
1282 if (get_ammo_brand(mitm[thing_created]) == SPMSL_CURARE)
1283 mitm[thing_created].quantity = random_range(2, 8);
1286 else
1288 // Sanity check to avoid useless brands.
1289 const int bow_brand = get_weapon_brand(*launcher);
1290 const int ammo_brand = get_ammo_brand(mitm[thing_created]);
1291 if (ammo_brand != SPMSL_NORMAL
1292 && (bow_brand == SPWPN_FLAME || bow_brand == SPWPN_FROST))
1294 mitm[thing_created].special = SPMSL_NORMAL;
1298 switch (mon->type)
1300 case MONS_DEEP_ELF_MASTER_ARCHER:
1301 // Master archers get double ammo - archery is their only attack
1302 mitm[thing_created].quantity *= 2;
1303 break;
1305 case MONS_NESSOS:
1306 mitm[thing_created].special = SPMSL_POISONED;
1307 break;
1309 case MONS_JOSEPH:
1310 mitm[thing_created].quantity += 2 + random2(7);
1311 mitm[thing_created].plus += 2 + random2(2);
1312 if (mitm[thing_created].plus > 6)
1313 mitm[thing_created].plus = 6;
1314 break;
1316 default:
1317 break;
1320 _give_monster_item(mon, thing_created);
1322 else
1324 // Give some monsters throwing weapons.
1325 int weap_type = -1;
1326 object_class_type weap_class = OBJ_WEAPONS;
1327 int qty = 0;
1328 switch (mon->type)
1330 case MONS_KOBOLD:
1331 case MONS_BIG_KOBOLD:
1332 if (x_chance_in_y(2, 5))
1334 item_race = MAKE_ITEM_NO_RACE;
1335 weap_class = OBJ_MISSILES;
1336 weap_type = MI_DART;
1337 qty = 1 + random2(5);
1339 break;
1341 case MONS_ORC_WARRIOR:
1342 if (one_chance_in(
1343 you.where_are_you == BRANCH_ORCISH_MINES? 9 : 20))
1345 weap_type = random_choose(WPN_HAND_AXE, WPN_SPEAR, -1);
1346 qty = random_range(4, 8);
1347 item_race = MAKE_ITEM_ORCISH;
1349 break;
1351 case MONS_ORC:
1352 if (one_chance_in(20))
1354 weap_type = random_choose(WPN_HAND_AXE, WPN_SPEAR, -1);
1355 qty = random_range(2, 5);
1356 item_race = MAKE_ITEM_ORCISH;
1358 break;
1360 case MONS_URUG:
1361 weap_type = MI_JAVELIN;
1362 weap_class = OBJ_MISSILES;
1363 item_race = MAKE_ITEM_ORCISH;
1364 qty = random_range(4, 7);
1365 break;
1367 case MONS_CHUCK:
1368 weap_type = MI_LARGE_ROCK;
1369 weap_class = OBJ_MISSILES;
1370 qty = 2;
1371 break;
1373 case MONS_MERFOLK_JAVELINEER:
1374 weap_class = OBJ_MISSILES;
1375 weap_type = MI_JAVELIN;
1376 item_race = MAKE_ITEM_NO_RACE;
1377 qty = random_range(9, 23, 2);
1378 if (one_chance_in(3))
1379 level = MAKE_GOOD_ITEM;
1380 break;
1382 case MONS_MERFOLK:
1383 if (one_chance_in(3)
1384 || active_monster_band == BAND_MERFOLK_JAVELINEER)
1386 item_race = MAKE_ITEM_NO_RACE;
1387 weap_class = OBJ_WEAPONS;
1388 weap_type = WPN_SPEAR;
1389 qty = random_range(4, 8);
1390 if (active_monster_band == BAND_MERFOLK_JAVELINEER)
1391 break;
1393 if (one_chance_in(6) && !mons_summoned)
1395 weap_class = OBJ_MISSILES;
1396 weap_type = MI_THROWING_NET;
1397 qty = 1;
1398 if (one_chance_in(4))
1399 qty += random2(3); // up to three nets
1401 break;
1403 case MONS_DRACONIAN_KNIGHT:
1404 case MONS_GNOLL:
1405 case MONS_HILL_GIANT:
1406 if (!one_chance_in(20))
1407 break;
1408 // deliberate fall-through
1410 case MONS_HAROLD: // bounty hunters
1411 case MONS_JOZEF: // up to 5 nets
1412 if (mons_summoned)
1413 break;
1415 weap_class = OBJ_MISSILES;
1416 weap_type = MI_THROWING_NET;
1417 qty = 1;
1418 if (one_chance_in(3))
1419 qty++;
1420 if (mon->type == MONS_HAROLD || mon->type == MONS_JOZEF)
1421 qty += random2(4);
1423 break;
1425 default:
1426 break;
1429 if (weap_type == -1)
1430 return;
1432 const int thing_created =
1433 items(0, weap_class, weap_type, true, level, item_race);
1435 if (thing_created != NON_ITEM)
1437 item_def& w(mitm[thing_created]);
1439 // Limit returning brand to only one.
1440 if (weap_type == OBJ_WEAPONS
1441 && get_weapon_brand(w) == SPWPN_RETURNING)
1443 qty = 1;
1446 if (mon->type == MONS_CHUCK)
1447 set_item_ego_type(w, OBJ_MISSILES, SPMSL_RETURNING);
1449 w.quantity = qty;
1450 _give_monster_item(mon, thing_created, false,
1451 (weap_class == OBJ_WEAPONS?
1452 &monster::pickup_melee_weapon
1453 : &monster::pickup_throwable_weapon));
1458 static bool make_item_for_monster(
1459 monster* mons,
1460 object_class_type base,
1461 int subtype,
1462 int level,
1463 item_make_species_type race = MAKE_ITEM_NO_RACE,
1464 int allow_uniques = 0)
1466 const int bp = get_item_slot();
1467 if (bp == NON_ITEM)
1468 return (false);
1470 const int thing_created =
1471 items(allow_uniques, base, subtype, true, level, race);
1473 if (thing_created == NON_ITEM)
1474 return (false);
1476 _give_monster_item(mons, thing_created);
1477 return (true);
1480 void give_shield(monster* mon, int level)
1482 const item_def *main_weap = mon->mslot_item(MSLOT_WEAPON);
1483 const item_def *alt_weap = mon->mslot_item(MSLOT_ALT_WEAPON);
1485 // If the monster is already wielding/carrying a two-handed weapon,
1486 // it doesn't get a shield. (Monsters always prefer raw damage to
1487 // protection!)
1488 if (main_weap && hands_reqd(*main_weap, mon->body_size()) == HANDS_TWO
1489 || alt_weap && hands_reqd(*alt_weap, mon->body_size()) == HANDS_TWO)
1491 return;
1494 switch (mon->type)
1496 case MONS_PALADIN:
1497 case MONS_DAEVA:
1498 case MONS_MENNAS:
1499 make_item_for_monster(mon, OBJ_ARMOUR, ARM_LARGE_SHIELD,
1500 level * 2 + 1, MAKE_ITEM_NO_RACE, 1);
1501 break;
1503 case MONS_DEEP_ELF_SOLDIER:
1504 case MONS_DEEP_ELF_FIGHTER:
1505 if (one_chance_in(6))
1507 make_item_for_monster(mon, OBJ_ARMOUR, ARM_BUCKLER,
1508 level, MAKE_ITEM_ELVEN);
1510 break;
1511 case MONS_NAGA_WARRIOR:
1512 case MONS_VAULT_GUARD:
1513 if (one_chance_in(3))
1515 make_item_for_monster(mon, OBJ_ARMOUR,
1516 one_chance_in(3) ? ARM_LARGE_SHIELD
1517 : ARM_SHIELD,
1518 level, MAKE_ITEM_NO_RACE);
1520 break;
1521 case MONS_DRACONIAN_KNIGHT:
1522 if (coinflip())
1524 make_item_for_monster(mon, OBJ_ARMOUR,
1525 coinflip()? ARM_LARGE_SHIELD : ARM_SHIELD,
1526 level, MAKE_ITEM_NO_RACE);
1528 break;
1529 case MONS_DEEP_ELF_KNIGHT:
1530 if (one_chance_in(3))
1532 make_item_for_monster(mon, OBJ_ARMOUR, ARM_BUCKLER,
1533 level, MAKE_ITEM_ELVEN);
1535 break;
1536 case MONS_SPRIGGAN:
1537 case MONS_SPRIGGAN_RIDER:
1538 if (!one_chance_in(4))
1539 break;
1540 case MONS_SPRIGGAN_DEFENDER:
1541 case MONS_THE_ENCHANTRESS:
1542 make_item_for_monster(mon, OBJ_ARMOUR, ARM_BUCKLER,
1543 mon->type == MONS_THE_ENCHANTRESS ? MAKE_GOOD_ITEM :
1544 mon->type == MONS_SPRIGGAN_DEFENDER ? level * 2 + 1 :
1545 level, MAKE_ITEM_NO_RACE);
1546 break;
1547 case MONS_NORRIS:
1548 make_item_for_monster(mon, OBJ_ARMOUR, ARM_BUCKLER,
1549 level * 2 + 1, MAKE_ITEM_RANDOM_RACE, 1);
1550 break;
1551 case MONS_WIGLAF:
1552 make_item_for_monster(mon, OBJ_ARMOUR, ARM_SHIELD,
1553 level * 2 + 1, MAKE_ITEM_DWARVEN, 1);
1554 break;
1555 case MONS_LOUISE:
1556 make_item_for_monster(mon, OBJ_ARMOUR, ARM_LARGE_SHIELD,
1557 level * 2 + 1, MAKE_ITEM_RANDOM_RACE, 1);
1558 break;
1559 case MONS_DONALD:
1560 make_item_for_monster(mon, OBJ_ARMOUR, ARM_SHIELD,
1561 level * 2 + 1, MAKE_ITEM_RANDOM_RACE, 1);
1563 if (coinflip())
1565 item_def *shield = mon->shield();
1566 if (shield)
1567 set_item_ego_type(*shield, OBJ_ARMOUR, SPARM_REFLECTION);
1570 break;
1571 case MONS_NIKOLA:
1573 make_item_for_monster(mon, OBJ_ARMOUR, ARM_GLOVES,
1574 level * 2 + 1, MAKE_ITEM_NO_RACE, 1);
1576 item_def *gaunt = mon->shield();
1577 if (gaunt)
1579 if (get_armour_ego_type(*gaunt) == SPARM_ARCHERY)
1580 set_item_ego_type(*gaunt, OBJ_ARMOUR, SPARM_NORMAL);
1581 gaunt->plus2 = TGLOV_DESC_GAUNTLETS;
1584 break;
1585 default:
1586 break;
1590 void give_armour(monster* mon, int level, bool spectral_orcs)
1592 item_def item;
1593 item_make_species_type item_race = MAKE_ITEM_RANDOM_RACE;
1595 item.base_type = OBJ_UNASSIGNED;
1596 item.quantity = 1;
1598 int force_colour = 0; // mv: Important!!! Items with force_colour = 0
1599 // are colored by default after following
1600 // switch. Others will get force_colour.
1602 bool force_item = false;
1603 int type = mon->type;
1605 if (spectral_orcs)
1607 type = mon->number;
1610 switch (type)
1612 case MONS_DEEP_ELF_BLADEMASTER:
1613 case MONS_DEEP_ELF_MASTER_ARCHER:
1614 item_race = MAKE_ITEM_ELVEN;
1615 item.base_type = OBJ_ARMOUR;
1616 item.sub_type = ARM_LEATHER_ARMOUR;
1617 break;
1619 case MONS_DUVESSA:
1620 case MONS_ELF:
1621 case MONS_DEEP_ELF_ANNIHILATOR:
1622 case MONS_DEEP_ELF_CONJURER:
1623 case MONS_DEEP_ELF_DEATH_MAGE:
1624 case MONS_DEEP_ELF_DEMONOLOGIST:
1625 case MONS_DEEP_ELF_FIGHTER:
1626 case MONS_DEEP_ELF_HIGH_PRIEST:
1627 case MONS_DEEP_ELF_KNIGHT:
1628 case MONS_DEEP_ELF_MAGE:
1629 case MONS_DEEP_ELF_PRIEST:
1630 case MONS_DEEP_ELF_SOLDIER:
1631 case MONS_DEEP_ELF_SORCERER:
1632 case MONS_DEEP_ELF_SUMMONER:
1633 if (item_race == MAKE_ITEM_RANDOM_RACE)
1634 item_race = MAKE_ITEM_ELVEN;
1635 // deliberate fall through {dlb}
1637 case MONS_IJYB:
1638 case MONS_ORC:
1639 case MONS_ORC_HIGH_PRIEST:
1640 case MONS_ORC_PRIEST:
1641 case MONS_ORC_SORCERER:
1642 if (item_race == MAKE_ITEM_RANDOM_RACE)
1643 item_race = MAKE_ITEM_ORCISH;
1644 // deliberate fall through {dlb}
1646 case MONS_ERICA:
1647 case MONS_HAROLD:
1648 case MONS_JOSEPHINE:
1649 case MONS_JOZEF:
1650 case MONS_PSYCHE:
1651 if (x_chance_in_y(2, 5))
1653 item.base_type = OBJ_ARMOUR;
1655 const int temp_rand = random2(8);
1656 item.sub_type = ((temp_rand < 4) ? ARM_LEATHER_ARMOUR :
1657 (temp_rand < 6) ? ARM_RING_MAIL :
1658 (temp_rand == 6) ? ARM_SCALE_MAIL
1659 : ARM_CHAIN_MAIL);
1661 else
1662 return;
1663 break;
1665 case MONS_JOSEPH:
1666 item.base_type = OBJ_ARMOUR;
1667 item.sub_type = random_choose_weighted(3, ARM_LEATHER_ARMOUR,
1668 2, ARM_RING_MAIL,
1670 break;
1672 case MONS_TERENCE:
1673 item.base_type = OBJ_ARMOUR;
1674 item.sub_type = random_choose_weighted(1, ARM_RING_MAIL,
1675 3, ARM_SCALE_MAIL,
1676 2, ARM_CHAIN_MAIL,
1678 break;
1680 case MONS_SLAVE:
1681 case MONS_GRUM:
1682 case MONS_SPRIGGAN_BERSERKER:
1683 item.base_type = OBJ_ARMOUR;
1684 item.sub_type = ARM_ANIMAL_SKIN;
1685 break;
1687 case MONS_URUG:
1688 item_race = MAKE_ITEM_ORCISH;
1689 // deliberate fall through {dlb}
1691 case MONS_EDMUND:
1692 case MONS_RUPERT:
1694 item.base_type = OBJ_ARMOUR;
1696 const int temp_rand = random2(4);
1697 item.sub_type = ((temp_rand == 0) ? ARM_LEATHER_ARMOUR :
1698 (temp_rand == 1) ? ARM_RING_MAIL :
1699 (temp_rand == 2) ? ARM_SCALE_MAIL
1700 : ARM_CHAIN_MAIL);
1701 break;
1704 case MONS_WIGLAF:
1705 item_race = MAKE_ITEM_DWARVEN;
1706 item.base_type = OBJ_ARMOUR;
1707 if (one_chance_in(3))
1708 level = MAKE_GOOD_ITEM;
1710 item.sub_type = random_choose_weighted(3, ARM_CHAIN_MAIL,
1711 3, ARM_BANDED_MAIL, 3, ARM_SPLINT_MAIL,
1712 10, ARM_PLATE_MAIL, 1, ARM_CRYSTAL_PLATE_MAIL,
1714 break;
1716 case MONS_ORC_WARLORD:
1717 case MONS_SAINT_ROKA:
1718 // Being at the top has its privileges. :)
1719 if (one_chance_in(3))
1720 level = MAKE_GOOD_ITEM;
1721 // deliberate fall through
1723 case MONS_ORC_KNIGHT:
1724 case MONS_ORC_WARRIOR:
1725 item_race = MAKE_ITEM_ORCISH;
1726 // deliberate fall through {dlb}
1728 case MONS_PALADIN:
1729 case MONS_FREDERICK:
1730 case MONS_HELL_KNIGHT:
1731 case MONS_LOUISE:
1732 case MONS_MARGERY:
1733 case MONS_DONALD:
1734 case MONS_MAUD:
1735 case MONS_VAMPIRE_KNIGHT:
1736 case MONS_JORY:
1737 case MONS_VAULT_GUARD:
1739 item.base_type = OBJ_ARMOUR;
1741 const int temp_rand = random2(4);
1742 item.sub_type = ((temp_rand == 0) ? ARM_CHAIN_MAIL :
1743 (temp_rand == 1) ? ARM_SPLINT_MAIL :
1744 (temp_rand == 2) ? ARM_BANDED_MAIL
1745 : ARM_PLATE_MAIL);
1746 break;
1749 case MONS_DEEP_DWARF_NECROMANCER:
1750 force_colour = MAGENTA;
1751 // deliberate fall through
1753 case MONS_UNBORN_DEEP_DWARF:
1754 if (mon->type == MONS_UNBORN_DEEP_DWARF)
1756 force_colour = WHITE;
1757 if (one_chance_in(6))
1758 level = MAKE_GOOD_ITEM;
1760 // deliberate fall through
1762 case MONS_DEEP_DWARF_ARTIFICER:
1763 item_race = MAKE_ITEM_NO_RACE;
1764 item.base_type = OBJ_ARMOUR;
1765 item.sub_type = ARM_ROBE;
1766 break;
1768 case MONS_DWARF:
1769 case MONS_DEEP_DWARF:
1770 case MONS_DEEP_DWARF_SCION:
1771 case MONS_DEEP_DWARF_DEATH_KNIGHT:
1772 case MONS_DEEP_DWARF_BERSERKER:
1773 item_race = MAKE_ITEM_DWARVEN;
1774 item.base_type = OBJ_ARMOUR;
1775 item.sub_type = random_choose_weighted(5, ARM_CHAIN_MAIL,
1776 1, ARM_SPLINT_MAIL,
1777 1, ARM_BANDED_MAIL,
1778 1, ARM_PLATE_MAIL,
1780 break;
1782 case MONS_MERFOLK_IMPALER:
1783 item_race = MAKE_ITEM_NO_RACE;
1784 item.base_type = OBJ_ARMOUR;
1785 item.sub_type = random_choose_weighted(100, ARM_ROBE,
1786 60, ARM_LEATHER_ARMOUR,
1787 5, ARM_TROLL_LEATHER_ARMOUR,
1788 5, ARM_STEAM_DRAGON_ARMOUR,
1790 break;
1792 case MONS_MERFOLK_JAVELINEER:
1793 item_race = MAKE_ITEM_NO_RACE;
1794 item.base_type = OBJ_ARMOUR;
1795 item.sub_type = ARM_LEATHER_ARMOUR;
1796 break;
1798 case MONS_ANGEL:
1799 case MONS_CHERUB:
1800 case MONS_SIGMUND:
1801 case MONS_WIGHT:
1802 item_race = MAKE_ITEM_NO_RACE;
1803 item.base_type = OBJ_ARMOUR;
1804 item.sub_type = ARM_ROBE;
1805 force_colour = WHITE;
1806 break;
1808 // Centaurs sometimes wear barding.
1809 case MONS_CENTAUR:
1810 case MONS_CENTAUR_WARRIOR:
1811 case MONS_YAKTAUR:
1812 case MONS_YAKTAUR_CAPTAIN:
1813 if (one_chance_in(mon->type == MONS_CENTAUR ? 1000 :
1814 mon->type == MONS_CENTAUR_WARRIOR ? 500 :
1815 mon->type == MONS_YAKTAUR ? 300
1816 /* mon->type == MONS_YAKTAUR_CAPTAIN ? */ : 200))
1818 item.base_type = OBJ_ARMOUR;
1819 item.sub_type = ARM_CENTAUR_BARDING;
1821 else
1822 return;
1823 break;
1825 case MONS_NAGA:
1826 case MONS_NAGA_MAGE:
1827 case MONS_NAGA_WARRIOR:
1828 case MONS_GREATER_NAGA:
1829 if (one_chance_in(mon->type == MONS_NAGA ? 800 :
1830 mon->type == MONS_NAGA_WARRIOR ? 300 :
1831 mon->type == MONS_NAGA_MAGE ? 200
1832 : 100))
1834 item_race = MAKE_ITEM_NO_RACE;
1835 item.base_type = OBJ_ARMOUR;
1836 item.sub_type = ARM_NAGA_BARDING;
1838 else if (mon->type == MONS_GREATER_NAGA || one_chance_in(3))
1840 item_race = MAKE_ITEM_NO_RACE;
1841 item.base_type = OBJ_ARMOUR;
1842 item.sub_type = ARM_ROBE;
1844 else
1845 return;
1846 break;
1848 case MONS_GASTRONOK:
1849 if (one_chance_in(10))
1851 force_item = true;
1852 make_item_unrandart(item, UNRAND_PONDERING);
1854 else
1856 item_race = MAKE_ITEM_NO_RACE;
1857 item.base_type = OBJ_ARMOUR;
1858 item.sub_type = ARM_WIZARD_HAT;
1860 // Not as good as it sounds. Still just +0 a lot of the time.
1861 level = MAKE_GOOD_ITEM;
1863 break;
1865 case MONS_MAURICE:
1866 force_colour = DARKGREY;
1867 // intentional fall-through
1868 case MONS_CRAZY_YIUF:
1869 item_race = MAKE_ITEM_NO_RACE;
1870 item.base_type = OBJ_ARMOUR;
1871 item.sub_type = ARM_CLOAK;
1872 break;
1874 case MONS_DOWAN:
1875 item_race = MAKE_ITEM_ELVEN;
1876 // intentional fall-through
1877 case MONS_JESSICA:
1878 case MONS_KOBOLD_DEMONOLOGIST:
1879 case MONS_OGRE_MAGE:
1880 case MONS_EROLCHA:
1881 case MONS_DRACONIAN:
1882 case MONS_RED_DRACONIAN:
1883 case MONS_WHITE_DRACONIAN:
1884 case MONS_GREEN_DRACONIAN:
1885 case MONS_PALE_DRACONIAN:
1886 case MONS_MOTTLED_DRACONIAN:
1887 case MONS_BLACK_DRACONIAN:
1888 case MONS_YELLOW_DRACONIAN:
1889 case MONS_PURPLE_DRACONIAN:
1890 case MONS_GREY_DRACONIAN:
1891 case MONS_DRACONIAN_SHIFTER:
1892 case MONS_DRACONIAN_SCORCHER:
1893 case MONS_DRACONIAN_ANNIHILATOR:
1894 case MONS_DRACONIAN_CALLER:
1895 case MONS_DRACONIAN_MONK:
1896 case MONS_DRACONIAN_ZEALOT:
1897 case MONS_DRACONIAN_KNIGHT:
1898 case MONS_WIZARD:
1899 case MONS_ILSUIW:
1900 case MONS_MARA:
1901 case MONS_MERFOLK_AQUAMANCER:
1902 case MONS_SPRIGGAN:
1903 case MONS_SPRIGGAN_DEFENDER:
1904 if (item_race == MAKE_ITEM_RANDOM_RACE)
1905 item_race = MAKE_ITEM_NO_RACE;
1906 item.base_type = OBJ_ARMOUR;
1907 item.sub_type = ARM_ROBE;
1908 break;
1910 case MONS_SPRIGGAN_DRUID:
1911 item_race = MAKE_ITEM_NO_RACE;
1912 item.base_type = OBJ_ARMOUR;
1913 item.sub_type = ARM_ROBE;
1914 force_colour = GREEN;
1915 break;
1917 case MONS_THE_ENCHANTRESS:
1918 force_item = true;
1919 make_item_unrandart(item, UNRAND_FAERIE);
1920 break;
1922 case MONS_TIAMAT:
1923 item_race = MAKE_ITEM_NO_RACE;
1924 item.base_type = OBJ_ARMOUR;
1925 item.sub_type = ARM_GOLD_DRAGON_ARMOUR;
1926 break;
1928 case MONS_ORC_WIZARD:
1929 case MONS_BLORK_THE_ORC:
1930 case MONS_NERGALLE:
1931 item_race = MAKE_ITEM_ORCISH;
1932 item.base_type = OBJ_ARMOUR;
1933 item.sub_type = ARM_ROBE;
1934 break;
1936 case MONS_BORIS:
1937 level = MAKE_GOOD_ITEM;
1938 // fall-through
1939 case MONS_AGNES:
1940 case MONS_FRANCES:
1941 case MONS_NECROMANCER:
1942 case MONS_VAMPIRE_MAGE:
1943 case MONS_PIKEL:
1944 item.base_type = OBJ_ARMOUR;
1945 item.sub_type = ARM_ROBE;
1946 force_colour = DARKGREY;
1947 break;
1949 case MONS_EUSTACHIO:
1950 item_race = MAKE_ITEM_NO_RACE;
1951 item.base_type = OBJ_ARMOUR;
1952 item.sub_type = ARM_LEATHER_ARMOUR;
1953 break;
1955 case MONS_NESSOS:
1956 item_race = MAKE_ITEM_NO_RACE;
1957 item.base_type = OBJ_ARMOUR;
1958 item.sub_type = ARM_CENTAUR_BARDING;
1959 force_colour = DARKGREY;
1960 break;
1962 case MONS_NIKOLA:
1963 item_race = MAKE_ITEM_NO_RACE;
1964 item.base_type = OBJ_ARMOUR;
1965 item.sub_type = ARM_CLOAK;
1966 force_colour = LIGHTCYAN;
1967 break;
1969 default:
1970 return;
1973 // Only happens if something in above switch doesn't set it. {dlb}
1974 if (item.base_type == OBJ_UNASSIGNED)
1975 return;
1977 const object_class_type xitc = item.base_type;
1978 const int xitt = item.sub_type;
1980 if (!force_item && mons_is_unique(mon->type) && level != MAKE_GOOD_ITEM)
1982 if (x_chance_in_y(9 + mon->hit_dice, 100))
1983 level = MAKE_GOOD_ITEM;
1984 else
1985 level = level * 2 + 5;
1988 // Note this mess, all the work above doesn't mean much unless
1989 // force_item is set... otherwise we're just going to take the base
1990 // and subtype and create a new item. - bwr
1991 const int thing_created =
1992 ((force_item) ? get_item_slot() : items(0, xitc, xitt, true,
1993 level, item_race));
1995 if (thing_created == NON_ITEM)
1996 return;
1998 // Copy temporary item into the item array if were forcing it, since
1999 // items() won't have done it for us.
2000 if (force_item)
2001 mitm[thing_created] = item;
2003 item_def &i = mitm[thing_created];
2005 if (force_item)
2006 item_set_appearance(i);
2008 _give_monster_item(mon, thing_created, force_item);
2010 // mv: All items with force_colour = 0 are colored via items().
2011 if (force_colour)
2012 mitm[thing_created].colour = force_colour;
2014 switch (mon->type)
2016 case MONS_NIKOLA:
2017 mitm[thing_created].plus2 = TGLOV_DESC_GAUNTLETS;
2018 break;
2019 default:
2020 break;
2024 static void _give_gold(monster* mon, int level)
2026 const int idx = items(0, OBJ_GOLD, 0, true, level, 0);
2027 _give_monster_item(mon, idx);
2030 void give_weapon(int mid, int level_number, bool mons_summoned, bool spectral_orcs)
2032 monster *mons = &menv[mid];
2033 _give_weapon(mons, level_number, false, true, spectral_orcs);
2036 void give_item(int mid, int level_number, bool mons_summoned, bool spectral_orcs)
2038 monster* mons = &menv[mid];
2040 if (mons->type == MONS_MAURICE || mons->type == MONS_DEEP_DWARF_SCION)
2041 _give_gold(mons, level_number);
2043 _give_scroll(mons, level_number);
2044 _give_wand(mons, level_number);
2045 _give_potion(mons, level_number);
2047 const item_make_species_type item_race = _give_weapon(mons, level_number, false, true, spectral_orcs);
2049 _give_ammo(mons, level_number, item_race, mons_summoned);
2051 give_armour(mons, 1 + level_number / 2, spectral_orcs);
2052 give_shield(mons, 1 + level_number / 2);