1 /* File: artifact.c */
2 
3 /* Purpose: Artifact code */
4 
5 /*
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research, and
9  * not for profit purposes provided that this copyright and statement are
10  * included in all such copies.
11  */
12 
13 #include "angband.h"
14 #include "script.h"
15 
16 /* Chance of using syllables to form the name instead of the "template" files */
17 #define TABLE_NAME      45
18 
19 /* Chance of a random artifact being cursed (1 in 13) */
20 #define A_CURSED        13
21 
22 /* Chance of getting a 'basic 4' immunity rather than resist (1 in 48) */
23 #define LOW_IM_LUCK  	48
24 /* Chance of getting a 'high' immunity rather than resist (1 in 12) */
25 #define HI_IM_LUCK	12
26 
27 #define ACTIVATION_CHANCE 3
28 
random_plus(object_type * o_ptr)29 static void random_plus(object_type *o_ptr)
30 {
31   bad_type:
32 	switch (randint1(o_ptr->tval < TV_BOOTS ? 24 : 20))
33 	{
34 		case 1:  case 2:
35 			SET_FLAG(o_ptr, TR_STR);
36 			break;
37 		case 3:  case 4:
38 			SET_FLAG(o_ptr, TR_INT);
39 			break;
40 		case 5:  case 6:
41 			SET_FLAG(o_ptr, TR_WIS);
42 			break;
43 		case 7:  case 8:
44 			SET_FLAG(o_ptr, TR_DEX);
45 			break;
46 		case 9:  case 10:
47 			SET_FLAG(o_ptr, TR_CON);
48 			break;
49 		case 11:  case 12:
50 			SET_FLAG(o_ptr, TR_CHR);
51 			break;
52 		case 13:  case 14:
53 			SET_FLAG(o_ptr, TR_STEALTH);
54 			break;
55 		case 15:  case 16:
56 			SET_FLAG(o_ptr, TR_SEARCH);
57 			break;
58 		case 17:  case 18:
59 			SET_FLAG(o_ptr, TR_INFRA);
60 			break;
61 		case 19:
62 			SET_FLAG(o_ptr, TR_SPEED);
63 			break;
64 		case 20:
65 			SET_FLAG(o_ptr, TR_SP);
66 			break;
67 		case 21:  case 22:
68 			SET_FLAG(o_ptr, TR_TUNNEL);
69 			break;
70 		case 23:  case 24:
71 			if (o_ptr->tval == TV_BOW)
72 				goto bad_type;
73 
74 			SET_FLAG(o_ptr, TR_BLOWS);
75 			break;
76 	}
77 }
78 
79 
random_resistance(object_type * o_ptr,int specific)80 static void random_resistance(object_type *o_ptr, int specific)
81 {
82   bad_type:
83 	switch (specific ? specific : randint1(42))
84 	{
85 		case 1:
86 		case 5:
87 		case 6:
88 		case 13:
89 			if (!one_in_(LOW_IM_LUCK))
90 				SET_FLAG(o_ptr, TR_RES_ACID);
91 			else
92 				SET_FLAG(o_ptr, TR_IM_ACID);
93 			break;
94 		case 2:
95 		case 7:
96 		case 8:
97 		case 14:
98 			if (!one_in_(LOW_IM_LUCK))
99 				SET_FLAG(o_ptr, TR_RES_ELEC);
100 			else
101 				SET_FLAG(o_ptr, TR_IM_ELEC);
102 			break;
103 		case 3:
104 		case 11:
105 		case 12:
106 		case 16:
107 			if (!one_in_(LOW_IM_LUCK))
108 				SET_FLAG(o_ptr, TR_RES_COLD);
109 			else
110 				SET_FLAG(o_ptr, TR_IM_COLD);
111 			break;
112 		case 4:
113 		case 9:
114 		case 10:
115 		case 15:
116 			if (!one_in_(LOW_IM_LUCK))
117 				SET_FLAG(o_ptr, TR_RES_FIRE);
118 			else
119 				SET_FLAG(o_ptr, TR_IM_FIRE);
120 			break;
121 		case 17:
122 		case 18:
123 			if (!one_in_(LOW_IM_LUCK))
124 				SET_FLAG(o_ptr, TR_RES_POIS);
125 			else
126 				SET_FLAG(o_ptr, TR_IM_POIS);
127 			break;
128 		case 19:
129 		case 20:
130 			SET_FLAG(o_ptr, TR_RES_FEAR);
131 			break;
132 		case 21:
133 			if (!one_in_(HI_IM_LUCK))
134 				SET_FLAG(o_ptr, TR_RES_LITE);
135 			else
136 				SET_FLAG(o_ptr, TR_IM_LITE);
137 			break;
138 		case 22:
139 			if (!one_in_(HI_IM_LUCK))
140 				SET_FLAG(o_ptr, TR_RES_DARK);
141 			else
142 				SET_FLAG(o_ptr, TR_IM_DARK);
143 			break;
144 		case 23:
145 		case 24:
146 			SET_FLAG(o_ptr, TR_RES_BLIND);
147 			break;
148 		case 25:
149 		case 26:
150 			SET_FLAG(o_ptr, TR_RES_CONF);
151 			break;
152 		case 27:
153 		case 28:
154 			SET_FLAG(o_ptr, TR_RES_SOUND);
155 			break;
156 		case 29:
157 		case 30:
158 			SET_FLAG(o_ptr, TR_RES_SHARDS);
159 			break;
160 		case 31:
161 		case 32:
162 			SET_FLAG(o_ptr, TR_RES_NETHER);
163 			break;
164 		case 33:
165 		case 34:
166 			SET_FLAG(o_ptr, TR_RES_NEXUS);
167 			break;
168 		case 35:
169 		case 36:
170 			SET_FLAG(o_ptr, TR_RES_CHAOS);
171 			break;
172 		case 37:
173 		case 38:
174 			SET_FLAG(o_ptr, TR_RES_DISEN);
175 			break;
176 		case 39:
177 			if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
178 				SET_FLAG(o_ptr, TR_SH_ELEC);
179 			else
180 				SET_FLAG(o_ptr, TR_RES_ELEC);
181 			break;
182 		case 40:
183 			if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
184 				SET_FLAG(o_ptr, TR_SH_FIRE);
185 			else
186 				SET_FLAG(o_ptr, TR_RES_FIRE);
187 			break;
188 		case 41:
189 			if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
190 				SET_FLAG(o_ptr, TR_SH_COLD);
191 			else
192 				SET_FLAG(o_ptr, TR_RES_COLD);
193 			break;
194 		/* Note: SH_ACID is deliberately omitted here */
195 		case 42:
196 			if (o_ptr->tval != TV_SHIELD && o_ptr->tval != TV_CLOAK &&
197 				o_ptr->tval != TV_HELM && o_ptr->tval != TV_HARD_ARMOR)
198 			{
199 				goto bad_type;
200 			}
201 
202 			SET_FLAG(o_ptr, TR_REFLECT);
203 			break;
204 	}
205 }
206 
207 
208 
random_misc(object_type * o_ptr)209 static void random_misc(object_type *o_ptr)
210 {
211   bad_type:
212 	switch (randint1(39))
213 	{
214 		case 1:
215 			SET_FLAG(o_ptr, TR_SUST_STR);
216 			break;
217 		case 2:
218 			SET_FLAG(o_ptr, TR_SUST_INT);
219 			break;
220 		case 3:
221 			SET_FLAG(o_ptr, TR_SUST_WIS);
222 			break;
223 		case 4:
224 			SET_FLAG(o_ptr, TR_SUST_DEX);
225 			break;
226 		case 5:
227 			SET_FLAG(o_ptr, TR_SUST_CON);
228 			break;
229 		case 6:
230 			SET_FLAG(o_ptr, TR_SUST_CHR);
231 			break;
232 		case 7:
233 		case 8:
234 		case 14:
235 			SET_FLAG(o_ptr, TR_FREE_ACT);
236 			break;
237 		case 9:
238 			SET_FLAG(o_ptr, TR_HOLD_LIFE);
239 			break;
240 		case 10:
241 		case 11:
242 			SET_FLAG(o_ptr, TR_LITE);
243 			break;
244 		case 12:
245 		case 13:
246 			SET_FLAG(o_ptr, TR_FEATHER);
247 			break;
248 		case 15:
249 			if (o_ptr->tval != TV_GLOVES)
250 				goto bad_type;
251 
252 			SET_FLAG(o_ptr, TR_GHOUL_TOUCH);
253 			break;
254 		case 16:
255 		case 17:
256 			SET_FLAG(o_ptr, TR_SEE_INVIS);
257 			break;
258 		case 18:
259 			SET_FLAG(o_ptr, TR_TELEPATHY);
260 			break;
261 		case 19:
262 		case 20:
263 			SET_FLAG(o_ptr, TR_SLOW_DIGEST);
264 			break;
265 		case 21:
266 		case 22:
267 			SET_FLAG(o_ptr, TR_REGEN);
268 			break;
269 		case 23:
270 			SET_FLAG(o_ptr, TR_TELEPORT);
271 			break;
272 		case 24:
273 		case 25:
274 		case 26:
275 			SET_FLAG(o_ptr, TR_SHOW_MODS);
276 			o_ptr->to_a += (s16b)rand_range(5, 15);
277 			break;
278 		case 27:
279 		case 28:
280 		case 29:
281 			SET_FLAG(o_ptr, TR_SHOW_MODS);
282 			o_ptr->to_h += (s16b)rand_range(5, 15);
283 			o_ptr->to_d += (s16b)rand_range(5, 15);
284 			break;
285 		case 30:
286 			SET_FLAG(o_ptr, TR_NO_MAGIC);
287 			break;
288 		case 31:
289 			SET_FLAG(o_ptr, TR_NO_TELE);
290 			break;
291 		case 32:
292 		case 33:
293 		case 34:
294 			/* A slay on a non-weapon gives protection */
295 			switch (randint1(8))
296 			{
297 				case 1: SET_FLAG(o_ptr, TR_SLAY_ANIMAL); break;
298 				case 2: SET_FLAG(o_ptr, TR_SLAY_EVIL);   break;
299 				case 3: SET_FLAG(o_ptr, TR_SLAY_UNDEAD); break;
300 				case 4: SET_FLAG(o_ptr, TR_SLAY_DEMON);  break;
301 				case 5: SET_FLAG(o_ptr, TR_SLAY_ORC);	 break;
302 				case 6: SET_FLAG(o_ptr, TR_SLAY_TROLL);  break;
303 				case 7: SET_FLAG(o_ptr, TR_SLAY_GIANT);  break;
304 				case 8: SET_FLAG(o_ptr, TR_SLAY_DRAGON); break;
305 			}
306 			break;
307 		case 35:
308 			SET_FLAG(o_ptr, TR_MUTATE);
309 			break;
310 		case 36:
311 			SET_FLAG(o_ptr, TR_PATRON);
312 			break;
313 		case 37:
314 			SET_FLAG(o_ptr, TR_STRANGE_LUCK);
315 			break;
316 		case 38:
317 			SET_FLAG(o_ptr, TR_LUCK_10);
318 			break;
319 		case 39:
320 			if (o_ptr->tval != TV_BOOTS)
321 				goto bad_type;
322 
323 			SET_FLAG(o_ptr, TR_WILD_WALK);
324 			break;
325 	}
326 }
327 
random_curse(object_type * o_ptr,bool evil)328 static void random_curse(object_type *o_ptr, bool evil)
329 {
330 	switch (randint1(evil ? 32 : 18))
331 	{
332 		case 1:
333 		case 19:
334 			SET_FLAG(o_ptr, TR_HURT_ACID);
335 			break;
336 		case 2:
337 		case 20:
338 			SET_FLAG(o_ptr, TR_HURT_ELEC);
339 			break;
340 		case 3:
341 		case 21:
342 			SET_FLAG(o_ptr, TR_HURT_FIRE);
343 			break;
344 		case 4:
345 		case 22:
346 			SET_FLAG(o_ptr, TR_HURT_COLD);
347 			break;
348 		case 5:
349 			SET_FLAG(o_ptr, TR_HURT_LITE);
350 			break;
351 		case 6:
352 			SET_FLAG(o_ptr, TR_HURT_DARK);
353 			break;
354 		case 7:
355 		case 8:
356 			SET_FLAG(o_ptr, TR_AGGRAVATE);
357 			break;
358 		case 9:
359 			SET_FLAG(o_ptr, TR_SLOW_HEAL);
360 			break;
361 		case 10:
362 		case 23:
363 			SET_FLAG(o_ptr, TR_DRAIN_STATS);
364 			break;
365 		case 11:
366 		case 12:
367 			SET_FLAG(o_ptr, TR_AUTO_CURSE);
368 			break;
369 		case 13:
370 		case 14:
371 			SET_FLAG(o_ptr, TR_CANT_EAT);
372 			break;
373 		case 15:
374 		case 16:
375 			SET_FLAG(o_ptr, TR_CURSED);
376 			break;
377 		case 17:
378 			o_ptr->to_a -= (s16b) rand_range(5, 15);
379 			break;
380 		case 18:
381 			o_ptr->to_h -= (s16b) rand_range(5, 10);
382 			o_ptr->to_d -= (s16b) rand_range(5, 10);
383 			break;
384 		case 24:
385 		case 25:
386 			SET_FLAG(o_ptr, TR_TELEPORT);
387 			break;
388 		case 26:
389 			SET_FLAG(o_ptr, TR_DRAIN_EXP);
390 			break;
391 		case 27:
392 		case 28:
393 			SET_FLAG(o_ptr, TR_TY_CURSE);
394 			break;
395 		case 29:
396 		case 30:
397 		case 31:
398 			SET_FLAG(o_ptr, TR_CURSED);
399 			SET_FLAG(o_ptr, TR_HEAVY_CURSE);
400 			break;
401 		case 32:
402 			SET_FLAG(o_ptr, TR_NO_MAGIC);
403 			break;
404 	}
405 }
406 
random_slay(object_type * o_ptr)407 static void random_slay(object_type *o_ptr)
408 {
409 	/* Bows get special treatment */
410 	if (o_ptr->tval == TV_BOW)
411 	{
412 		switch (randint1(12))
413 		{
414 			case 1:
415 			case 2:
416 			case 3:
417 			case 4:
418 			case 5:
419 				SET_FLAG(o_ptr, TR_XTRA_MIGHT);
420 				break;
421 			case 6:
422 				SET_FLAG(o_ptr, TR_WILD_SHOT);
423 				break;
424 			default:
425 				SET_FLAG(o_ptr, TR_XTRA_SHOTS);
426 				break;
427 		}
428 	}
429 
430 	switch (randint1(36))
431 	{
432 		case 1:
433 		case 2:
434 			SET_FLAG(o_ptr, TR_SLAY_ANIMAL);
435 			break;
436 		case 3:
437 		case 4:
438 			SET_FLAG(o_ptr, TR_SLAY_EVIL);
439 			break;
440 		case 5:
441 		case 6:
442 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
443 			break;
444 		case 7:
445 		case 8:
446 			SET_FLAG(o_ptr, TR_SLAY_DEMON);
447 			break;
448 		case 9:
449 		case 10:
450 			SET_FLAG(o_ptr, TR_SLAY_ORC);
451 			break;
452 		case 11:
453 		case 12:
454 			SET_FLAG(o_ptr, TR_SLAY_TROLL);
455 			break;
456 		case 13:
457 		case 14:
458 			SET_FLAG(o_ptr, TR_SLAY_GIANT);
459 			break;
460 		case 15:
461 		case 16:
462 			SET_FLAG(o_ptr, TR_SLAY_DRAGON);
463 			break;
464 		case 17:
465 			SET_FLAG(o_ptr, TR_KILL_DRAGON);
466 			break;
467 		case 18:
468 		case 19:
469 			if (o_ptr->tval == TV_SWORD)
470 			{
471 				SET_FLAG(o_ptr, TR_VORPAL);
472 			}
473 			else
474 			{
475 				SET_FLAG(o_ptr, TR_IMPACT);
476 			}
477 			break;
478 		case 20:
479 		case 21:
480 		case 22:
481 			SET_FLAG(o_ptr, TR_BRAND_FIRE);
482 			break;
483 		case 23:
484 		case 24:
485 			SET_FLAG(o_ptr, TR_BRAND_COLD);
486 			break;
487 		case 25:
488 		case 26:
489 			SET_FLAG(o_ptr, TR_BRAND_ELEC);
490 			break;
491 		case 27:
492 		case 28:
493 			SET_FLAG(o_ptr, TR_BRAND_ACID);
494 			break;
495 		case 29:
496 		case 30:
497 			SET_FLAG(o_ptr, TR_BRAND_POIS);
498 			break;
499 		case 31:
500 		case 32:
501 			SET_FLAG(o_ptr, TR_VAMPIRIC);
502 			break;
503 		case 33:
504 		case 34:
505 			SET_FLAG(o_ptr, TR_PSI_CRIT);
506 			break;
507 		default:
508 			SET_FLAG(o_ptr, TR_CHAOTIC);
509 			break;
510 	}
511 }
512 
513 
514 static cptr activation_text[] = {
515 	"The %v glows extremely brightly...",
516 	"The %v throbs deep green...",
517 	"The %v glows an intense red...",
518 	"The %v glows black...",
519 	"The %v glows an intense blue...",
520 	"The %v throbs red...",
521 	"The %v glows deep red...",
522 	"The %v glows bright white...",
523 	"The %v glows deep blue...",
524 	"The %v glows in scintillating colours...",
525 	"The %v vibrates...",
526 	"The %v glows violet...",
527 	"The %v lets out a long, shrill note...",
528 	"The %v twists in your hands...",
529 	"The %v shudders...",
530 	"The %v fades in and out...",
531 	"The %v hums softly...",
532 	"The %v blinks in and out...",
533 	"The %v radiates light blue...",
534 	"The %v radiates deep purple...",
535 	"The %v glows deep green...",
536 	"The %v lets out a shrill wail...",
537 	"The %v glows brightly...",
538 	"The %v shines brightly...",
539 	"The %v glows yellow...",
540 	"The %v glows light blue...",
541 	"The %v glows brown...",
542 	"The %v pulsates...",
543 	"The %v hums...",
544 	"The %v glows bright yellow..."
545 };
546 
547 static cptr element_list[] =
548 {
549 	"GF_ACID", "GF_ELEC", "GF_FIRE", "GF_COLD", "GF_POIS",
550 	"GF_PLASMA", "GF_WATER", "GF_LITE", "GF_DARK", "GF_SHARDS",
551 	"GF_SOUND", "GF_CONFUSION", "GF_FORCE", "GF_INERTIA", "GF_MANA",
552 	"GF_ICE", "GF_CHAOS", "GF_NETHER", "GF_NEXUS", "GF_TIME",
553 	"GF_GRAVITY", "GF_NUKE", "GF_HOLY_FIRE", "GF_HELL_FIRE", "GF_MISSILE",
554 };
555 static cptr element_names[] =
556 {
557 	"acid", "lightning", "fire", "cold", "poison",
558 	"plasma", "water", "light", "darkness", "shards",
559 	"sound", "confusion", "force", "inertia", "mana",
560 	"ice", "chaos", "nether", "nexus", "time",
561 	"gravity", "toxic waste", "holy power", "unholy power", "elemental force",
562 };
563 static cptr element_colors[] =
564 {
565 	"dark grey", "light blue", "bright red", "pale white", "dark green",
566 	"bright orange", "dark blue", "bright white", "black", "dark red",
567 	"amber", "dark purple", "light grey", "silver", "many colors",
568 	"pale white", "many colors", "black", "yellow", "silver",
569 	"dark grey", "sickly yellow", "pure white", "dark red", "many colors",
570 };
571 static cptr glow_desc[] =
572 {
573 	"glows", "shines", "pulses", "throbs", "radiates", "sparks"
574 };
575 
576 /*
577  * An activation for random artifacts
578  */
579 typedef struct randart_activation randart_activation;
580 
581 struct randart_activation
582 {
583 	cptr text;
584 	cptr desc;
585 	cptr effect;
586 	int freq;
587 	bool aimed;
588 	int pp;
589 	int dice;
590 	int bonus;
591 };
592 
593 #define SPDICE_MM -1
594 
595 /*
596  * {
597  * text,
598  * desc,
599  * effect,
600  * freq, aimed, pp, dice, bonus
601  * }
602  */
603 static const struct randart_activation randart_activations[] =
604 {
605 	{
606 		NULL,
607 		"remove fear and cure poison",
608 		"clear_afraid(); clear_poisoned()",
609 		20, FALSE, 100, 0, 0
610 	},
611 	{
612 		NULL,
613 		"stone to mud",
614 		"wall_to_mud(dir)",
615 		100, TRUE, 1000, 0, 0
616 	},
617 	{
618 		NULL,
619 		"destroy doors",
620 		"destroy_doors_touch()",
621 		20, FALSE, 1000, 0, 0
622 	},
623 	{
624 		NULL,
625 		"confuse monster",
626 		"confuse_monster(dir, 50)",
627 		50, TRUE, 1000, 0, 0
628 	},
629 	{
630 		NULL,
631 		"sleep monster",
632 		"sleep_monster(dir)",
633 		50, TRUE, 1000, 0, 0
634 	},
635 	{
636 		NULL,
637 		"slow monster",
638 		"slow_monster(dir)",
639 		50, TRUE, 1000, 0, 0
640 	},
641 	{
642 		NULL,
643 		"identify",
644 		"if not ident_spell() then return end",
645 		100, FALSE, 1000, 0, 0
646 	},
647 	{
648 		NULL,
649 		"recharging",
650 		"recharge(130)",
651 		25, FALSE, 1000, 0, 0
652 	},
653 	{
654 		NULL,
655 		"sleep nearby monsters",
656 		"sleep_monsters_touch()",
657 		25, FALSE, 1000, 0, 0
658 	},
659 	{
660 		NULL,
661 		"sleep monsters",
662 		"sleep_monsters()",
663 		10, FALSE, 5000, 0, 0
664 	},
665 	{
666 		"You open a dimensional gate. Choose a destination.",
667 		"dimension door",
668 		"if not dimension_door() return end",
669 		25, FALSE, 1000, 0, 0
670 	},
671 	{
672 		"The %v twists space around you...",
673 		"teleport (100)",
674 		"teleport_player(100)",
675 		100, FALSE, 1000, 0, 0
676 	},
677 	{
678 		"An image forms in your mind...",
679 		"detection",
680 		"detect_all()",
681 		50, FALSE, 1000, 0, 0
682 	},
683 	{
684 		"The %v glows bright red...",
685 		"explosive rune",
686 		"explosive_rune()",
687 		5, FALSE, 5000, 0, 0
688 	},
689 	{
690 		NULL,
691 		"word of recall",
692 		"word_of_recall()",
693 		100, FALSE, 5000, 0, 0
694 	},
695 	{
696 		NULL,
697 		"restore life levels",
698 		"restore_level()",
699 		10, FALSE, 25000, 0, 0
700 	},
701 	{
702 		NULL,
703 		"teleport away",
704 		"fire_beam(GF_AWAY_ALL, dir, player.lev)",
705 		50, TRUE, 5000, 0, 0
706 	},
707 	{
708 		NULL,
709 		"charm animal",
710 		"charm_animal(dir, player.lev)",
711 		10, TRUE, 5000, 0, 0
712 	},
713 	{
714 		NULL,
715 		"charm animal (level %s)",
716 		"charm_animal(dir, %s)",
717 		10, TRUE, 200, 100, 0	/* lev */
718 	},
719 	{
720 		NULL,
721 		"enslave undead",
722 		"control_one_undead(dir, player.lev)",
723 		10, TRUE, 7500, 0, 0
724 	},
725 	{
726 		NULL,
727 		"enslave undead (level %s)",
728 		"control_one_undead(dir, %s)",
729 		10, TRUE, 300, 100, 0	/* lev */
730 	},
731 	{
732 		NULL,
733 		"charm monster",
734 		"charm_monster(dir, player.lev)",
735 		10, TRUE, 10000, 0, 0
736 	},
737 	{
738 		NULL,
739 		"charm monster (level %s)",
740 		"charm_monster(dir, %s)",
741 		10, TRUE, 400, 100, 0	/* lev */
742 	},
743 	{
744 		NULL,
745 		"alchemy",
746 		"alchemy()",
747 		5, FALSE, 10000, 0, 0
748 	},
749 	{
750 		NULL,
751 		"rune of protection",
752 		"warding_glyph()",
753 		10, FALSE, 10000, 0, 0
754 	},
755 	{
756 		NULL,
757 		"animal friendship",
758 		"charm_animals(player.lev * 2)",
759 		5, FALSE, 10000, 0, 0
760 	},
761 	{
762 		NULL,
763 		"animal friendship (level %s)",
764 		"charm_animals(%s * 2)",
765 		5, FALSE, 750, 100, 0	/* lev */
766 	},
767 	{
768 		"The power of the %v banishes evil!",
769 		"banish evil",
770 		"banish_evil(200)",
771 		25, FALSE, 10000, 0, 0
772 	},
773 	{
774 		NULL,
775 		"genocide",
776 		"genocide(TRUE)",
777 		10, FALSE, 10000, 0, 0
778 	},
779 	{
780 		NULL,
781 		"satisfy hunger",
782 		"set_food(PY_FOOD_MAX - 1)",
783 		100, FALSE, 10000, 0, 0
784 	},
785 	{
786 		"The %v emits a blast of air...",
787 		"whirlwind attack",
788 		"whirlwind_attack()",
789 		10, FALSE, 20000, 0, 0
790 	},
791 	{
792 		"The %v glows in scintillating colours...",
793 		"call chaos",
794 		"call_chaos()",
795 		10, FALSE, 25000, 0, 0
796 	},
797 	{
798 		NULL,
799 		"mass genocide",
800 		"mass_genocide(TRUE)",
801 		5, FALSE, 25000, 0, 0
802 	},
803 	{
804 		NULL,
805 		"mass charm",
806 		"charm_monsters(player.lev * 2)",
807 		5, FALSE, 25000, 0, 0
808 	},
809 	{
810 		NULL,
811 		"mass charm (level %s)",
812 		"charm_monsters(%s * 2)",
813 		5, FALSE, 2000, 100, 0	/* lev */
814 	},
815 	{
816 		NULL,
817 		"restore stats",
818 		"restore_all_stats()",
819 		10, FALSE, 25000, 0, 0
820 	},
821 	{
822 		NULL,
823 		"restore stats and life levels",
824 		"restore_all_stats(); restore_level()",
825 		5, FALSE, 50000, 0, 0
826 	},
827 	{
828 		NULL,
829 		"identify true",
830 		"identify_fully()",
831 		25, FALSE, 25000, 0, 0
832 	},
833 	{
834 		NULL,
835 		"detection, probing and identify true",
836 		"detect_all(); probing(); identify_fully()",
837 		5, FALSE, 50000, 0, 0
838 	},
839 	{
840 		"A line of sunlight appears.",
841 		"beam of sunlight (%sd8)",
842 		"lite_line(dir, damroll(%s, 8))",
843 		100, TRUE, 100, 10, 4	/* lev / 10 + 4 */
844 	},
845 	{
846 		"The %v glow extremely brightly...",
847 		"magic missile (%sd6)",
848 		"fire_bolt(GF_MISSILE, dir, damroll(%s, 6))",
849 		100, TRUE, 12, 10, 2	/* lev / 10 + 2 */
850 	},
851 	{
852 		"The %v throbs deep green...",
853 		"stinking cloud (%s)",
854 		"fire_ball(GF_POIS, dir, %s, 2)",
855 		50, TRUE, 5, 100, 10	/* lev + 10 */
856 	},
857 	{
858 		"The %v glows black...",
859 		"drain life (%s)",
860 		"drain_life(dir, %s)",
861 		25, TRUE, 10, 500, 0	/* lev * 5 */
862 	},
863 	{
864 		"The %v throbs red...",
865 		"vampiric drain (%s)",
866 		"drain_gain_life(dir, %s)",
867 		25, TRUE, 15, 500, 0	/* lev * 5 */
868 	},
869 	{
870 		"The %v grows magical spikes...",
871 		"arrows (%s)",
872 		"fire_bolt(GF_ARROW, dir, %s)",
873 		10, TRUE, 10, 500, 0	/* lev * 5 */
874 	},
875 	{
876 		"The %v grows magical spikes...",
877 		"arrows (%sd25)",
878 		"fire_bolt(GF_ARROW, dir, damroll(%s, 25))",
879 		5, TRUE, 125, 33, 1	/* lev / 3 + 1 */
880 	},
881 	{
882 		"The %v grows magical spikes...",
883 		"arrows (%sd50)",
884 		"fire_bolt(GF_ARROW, dir, damroll(%s, 50))",
885 		5, TRUE, 250, 33, 1	/* lev / 3 + 1 */
886 	},
887 	{
888 		"You launch a rocket!",
889 		"launch rocket (%s)",
890 		"fire_ball(GF_ROCKET, dir, %s, 2)",
891 		5, TRUE, 20, 500, 100	/* rlev * 5 + 100 */
892 	},
893 	{
894 		"The %v floods the area with goodness...",
895 		"dispel evil (%s)",
896 		"dispel_evil(%s)",
897 		50, FALSE, 100, 500, 0	/* rlev * 5 */
898 	},
899 	{
900 		"The %v floods the area with evil...",
901 		"dispel good (%s)",
902 		"dispel_good(%s)",
903 		25, FALSE, 100, 500, 0	/* rlev * 5 */
904 	},
905 	{
906 		/* Note that this is more powerful than a normal breath activation */
907 		"You breathe the elements.",
908 		"breathe the elements (%s, rad. 4)",
909 		"fire_ball(GF_MISSILE, dir, %s, 4)",
910 		5, TRUE, 40, 1000, 0	/* rlev * 10 */
911 	},
912 	{
913 		"The %v vibrates...",
914 		"earthquake (rad. %s)",
915 		"earthquake(px, py, %s)",
916 		10, FALSE, 250, 25, 5	/* lev / 4 + 5 */
917 	},
918 	{
919 		"The %v emits a loud blast...",
920 		"terror",
921 		"turn_monsters(40 + player.lev)",
922 		10, FALSE, 2500, 0, 0
923 	},
924 	{
925 		"You summon a beast.",
926 		"summon animal",
927 		"summon_controlled(SUMMON_ANIMAL_RANGER)",
928 		25, FALSE, 10000, 0, 0
929 	},
930 	{
931 		"You summon a phantasmal servant.",
932 		"summon phantasmal servant",
933 		"summon_controlled(SUMMON_PHANTOM)",
934 		25, FALSE, 10000, 0, 0
935 	},
936 	{
937 		"You summon an elemental.",
938 		"summon elemental",
939 		"summon_unsafe(SUMMON_ELEMENTAL)",
940 		25, FALSE, 25000, 0, 0
941 	},
942 	{
943 		"Ancient, long-dead forms rise from the ground.",
944 		"summon undead",
945 		"summon_unsafe(SUMMON_UNDEAD)",
946 		25, FALSE, 25000, 0, 0
947 	},
948 	{
949 		"Ancient, long-dead forms rise from the ground.",
950 		"summon greater undead",
951 		"summon_unsafe(SUMMON_HI_UNDEAD)",
952 		10, FALSE, 50000, 0, 0
953 	},
954 	{
955 		"The area fills with the stench of sulphur and brimstone.",
956 		"summon demon",
957 		"summon_unsafe(SUMMON_DEMON)",
958 		25, FALSE, 25000, 0, 0
959 	},
960 	{
961 		"The area fills with brilliant white light.",
962 		"summon angel",
963 		"summon_controlled(SUMMON_ANGEL)",
964 		10, FALSE, 50000, 0, 0
965 	},
966 	{
967 		NULL,
968 		"remove fear and heal (%sd10)",
969 		"clear_afraid(); hp_player(damroll(%s, 10))",
970 		25, FALSE, 100, 33, 1	/* lev / 3 + 1 */
971 	},
972 	{
973 		NULL,
974 		"cure wounds and heal (%sd10)",
975 		"hp_player(damroll(%s, 10)); clear_cut(); clear_stun()",
976 		100, FALSE, 100, 100, 0	/* lev */
977 	},
978 	{
979 		NULL,
980 		"cure wounds and heal (%s)",
981 		"hp_player(%s); clear_cut(); clear_stun()",
982 		100, FALSE, 20, 1000, 0	/* lev * 10 */
983 	},
984 	{
985 		"The %v enters your thoughts...",
986 		"telepathy (%s+ turns)",
987 		"inc_tim_esp(rand_range2(%s))",
988 		25, FALSE, 200, 100, 0	/* lev */
989 	},
990 	{
991 		NULL,
992 		"heroism (%s+ turns)",
993 		"inc_hero(rand_range2(%s))",
994 		25, FALSE, 150, 100, 0	/* lev */
995 	},
996 	{
997 		NULL,
998 		"berserk (%s+ turns)",
999 		"inc_shero(rand_range2(%s))",
1000 		25, FALSE, 150, 100, 0	/* lev */
1001 	},
1002 	{
1003 		NULL,
1004 		"bless (%s+ turns)",
1005 		"inc_blessed(rand_range2(%s))",
1006 		25, FALSE, 100, 100, 0	/* lev */
1007 	},
1008 	{
1009 		NULL,
1010 		"protection from evil (%s+ turns)",
1011 		"inc_protevil(rand_range2(%s))",
1012 		25, FALSE, 100, 200, 0	/* lev * 2 */
1013 	},
1014 	{
1015 		"The %v glows many colours...",
1016 		"resist elements (%s+ turns)",
1017 		"inc_oppose_all(rand_range2(%s))",
1018 		25, FALSE, 250, 100, 0	/* lev */
1019 	},
1020 	{
1021 		NULL,
1022 		"resist acid (%s+ turns)",
1023 		"inc_oppose_acid(rand_range2(%s))",
1024 		10, FALSE, 100, 100, 0	/* lev */
1025 	},
1026 	{
1027 		NULL,
1028 		"resist lightning (%s+ turns)",
1029 		"inc_oppose_elec(rand_range2(%s))",
1030 		10, FALSE, 100, 100, 0	/* lev */
1031 	},
1032 	{
1033 		NULL,
1034 		"resist fire (%s+ turns)",
1035 		"inc_oppose_fire(rand_range2(%s))",
1036 		10, FALSE, 100, 100, 0	/* lev */
1037 	},
1038 	{
1039 		NULL,
1040 		"resist cold (%s+ turns)",
1041 		"inc_oppose_cold(rand_range2(%s))",
1042 		10, FALSE, 100, 100, 0	/* lev */
1043 	},
1044 	{
1045 		NULL,
1046 		"resist poison (%s+ turns)",
1047 		"inc_oppose_poison(rand_range2(%s))",
1048 		5, FALSE, 100, 100, 0	/* lev */
1049 	},
1050 	{
1051 		NULL,
1052 		"speed (%s+ turns)",
1053 		"inc_fast(rand_range2(%s))",
1054 		25, FALSE, 200, 100, 0	/* lev */
1055 	},
1056 	{
1057 		"The %v fades out...",
1058 		"wraith form (%s+ turns)",
1059 		"inc_wraith_form(rand_range2(%s))",
1060 		5, FALSE, 2000, 33, 1	/* lev / 3 + 1 */
1061 	},
1062 	{
1063 		"The %v fires a beam of bright light at you...",
1064 		"invulnerability (%s+ turns)",
1065 		"inc_invuln(rand_range2(%s))",
1066 		5, FALSE, 2000, 10, 3	/* lev / 10 + 3 */
1067 	},
1068 	{
1069 		"The %v wells with clear light...",
1070 		"light area (2d20)",
1071 		"lite_area(damroll(2, 20), 3)",
1072 		100, FALSE, 100, 0, 0
1073 	},
1074 	{
1075 		"The %v shines brightly...",
1076 		"magic mapping and light area (5d20)",
1077 		"map_area(); lite_area(damroll(5, 20), 3)",
1078 		50, FALSE, 400, 0, 0
1079 	},
1080 	{
1081 		NULL,
1082 		"detect evil",
1083 		"detect_monsters_evil()",
1084 		25, FALSE, 1000, 0, 0
1085 	},
1086 	{
1087 		NULL,
1088 		"detect monsters",
1089 		"detect_monsters()",
1090 		50, FALSE, 1000, 0, 0
1091 	},
1092 	{
1093 		NULL,
1094 		"detect traps and doors",
1095 		"detect_traps(TRUE); detect_doors(); detect_stairs()",
1096 		50, FALSE, 1000, 0, 0
1097 	},
1098 	{
1099 		NULL,
1100 		"remove curse",
1101 		"remove_curse()",
1102 		10, FALSE, 25000, 0, 0
1103 	},
1104 	{
1105 		NULL,
1106 		"dispel curse",
1107 		"remove_all_curse()",
1108 		5, FALSE, 50000, 0, 0
1109 	},
1110 	{
1111 		NULL,
1112 		"dispel undead (%s)",
1113 		"dispel_undead(%s)",
1114 		25, FALSE, 50, 500, 0	/* rlev * 5 */
1115 	},
1116 	{
1117 		NULL,
1118 		"dispel demons (%s)",
1119 		"dispel_demons(%s)",
1120 		25, FALSE, 50, 500, 0	/* rlev * 5 */
1121 	},
1122 	{
1123 		NULL,
1124 		"dispel living (%s)",
1125 		"dispel_living (%s)",
1126 		5, FALSE, 200, 400, 0	/* lev * 4 */
1127 	},
1128 	{
1129 		NULL,
1130 		"dispel monsters (%s)",
1131 		"dispel_monsters(%s)",
1132 		5, FALSE, 250, 400, 0	/* lev * 4 */
1133 	},
1134 	{
1135 		NULL,
1136 		"slow monsters",
1137 		"slow_monsters()",
1138 		10, FALSE, 25000, 0, 0
1139 	},
1140 	{
1141 		NULL,
1142 		"detect objects",
1143 		"detect_objects_normal()",
1144 		25, FALSE, 1000, 0, 0
1145 	},
1146 	{
1147 		NULL,
1148 		"detect treasure",
1149 		"detect_treasure(); detect_objects_gold()",
1150 		10, FALSE, 1000, 0, 0
1151 	},
1152 	{
1153 		NULL,
1154 		"detect enchantment",
1155 		"detect_objects_magic()",
1156 		10, FALSE, 2500, 0, 0
1157 	},
1158 	{
1159 		NULL,
1160 		"self knowledge",
1161 		"self_knowledge()",
1162 		10, FALSE, 10000, 0, 0
1163 	},
1164 	{
1165 		NULL,
1166 		"teleport level",
1167 		"teleport_player_level()",
1168 		5, FALSE, 10000, 0, 0
1169 	},
1170 	{
1171 		NULL,
1172 		"create doors",
1173 		"door_creation()",
1174 		5, FALSE, 2500, 0, 0
1175 	},
1176 	{
1177 		NULL,
1178 		"create stairs",
1179 		"stair_creation()",
1180 		5, FALSE, 10000, 0, 0
1181 	},
1182 	{
1183 		NULL,
1184 		"alter reality",
1185 		"alter_reality()",
1186 		5, FALSE, 10000, 0, 0
1187 	},
1188 	{
1189 		NULL,
1190 		"polymorph self",
1191 		"polymorph_self()",
1192 		10, FALSE, 5000, 0, 0
1193 	},
1194 	{
1195 		NULL,
1196 		"phase door",
1197 		"teleport_player(10)",
1198 		100, FALSE, 100, 0, 0
1199 	},
1200 	{
1201 		NULL,
1202 		"banishment",
1203 		"banish_monsters(200)",
1204 		5, FALSE, 25000, 0, 0
1205 	},
1206 
1207 	/* XXX stun, confuse, turn, stasis */
1208 
1209 };
1210 
apply_activation_power(object_type * o_ptr,cptr text,cptr desc,cptr effect,bool aimed,int pp,int level)1211 static void apply_activation_power(object_type *o_ptr, cptr text, cptr desc, cptr effect, bool aimed, int pp, int level)
1212 {
1213 	char buf[1024];
1214 	char text_buf[256];
1215 	int len;
1216 	int charge_min;
1217 
1218 	/* Don't add a power if there already is one */
1219 	if (FLAG(o_ptr, TR_ACTIVATE))
1220 		return;
1221 
1222 	/* Calculate charge time */
1223 	if (level > 0)
1224 		charge_min = pp / level;
1225 	else
1226 		charge_min = pp;
1227 
1228 	/* Round to nice numbers */
1229 	if (charge_min >= 1000)
1230 		charge_min -= charge_min % 100;
1231 	else if (charge_min >= 250)
1232 		charge_min -= charge_min % 50;
1233 	else if (charge_min >= 100)
1234 		charge_min -= charge_min % 10;
1235 	else if (charge_min >= 25)
1236 		charge_min -= charge_min % 5;
1237 
1238 	/* Enforce minimum & maximum charge time */
1239 	if (charge_min < 1) charge_min = 1;
1240 	if (charge_min > 5000) charge_min = 5000;
1241 
1242 
1243 	/* Get a description if needed */
1244 	if (text == NULL)
1245 		text = activation_text[randint0(NUM_ELEMENTS(activation_text))];
1246 
1247 	/* Get the basic name of the object in the description */
1248 	strnfmt(text_buf, 256, text, OBJECT_FMT(o_ptr, FALSE, 0));
1249 
1250 	/* Construct the usage script */
1251 	len = strnfmt(buf, 1024, "msgf(\"%s\"); ", text_buf);
1252 
1253 	if (aimed) strnfcat(buf, 1024, &len,
1254 				"local success; local dir; "
1255 				"success, dir = get_aim_dir(); "
1256 				"if not success then return; end; ");
1257 
1258 	strnfcat(buf, 1024, &len, "%s; object.timeout = rand_range(%i, %i)", effect, charge_min, charge_min * 2);
1259 
1260 	o_ptr->trigger[TRIGGER_USE] = quark_add(buf);
1261 
1262 
1263 	/* Description script */
1264 	len = strnfmt(buf, 1024, "return \"%s every %i-%i turns\"", desc, charge_min, charge_min * 2);
1265 	o_ptr->trigger[TRIGGER_DESC] = quark_fmt(buf);
1266 
1267 	SET_FLAG(o_ptr, TR_ACTIVATE);
1268 	o_ptr->timeout = 0;
1269 }
1270 
attack_activation_power(object_type * o_ptr,int level,cptr fix_element)1271 static void attack_activation_power(object_type *o_ptr, int level, cptr fix_element)
1272 {
1273 	static char text[256];
1274 	char effect[256] = "";
1275 	char desc[256] = "";
1276 	int element;
1277 	int dice = 0;
1278 	int sides = 1;
1279 	int radius = 0;
1280 	int pp = 0;	/* Charge time * level */
1281 	bool aimed = TRUE;
1282 
1283 	int rlev = level * rand_range(50, 150) / 100;
1284 	if (rlev < 1) rlev = 1;
1285 
1286 	if (fix_element == NULL)
1287 	{
1288 		/* Pick a low or high element */
1289 		if (level <= randint1(60))
1290 			element = randint0(5);
1291 		else
1292 			element = randint0(NUM_ELEMENTS(element_list));
1293 	}
1294 	else
1295 	{
1296 		for (element = 0; strcmp(fix_element, element_list[element]) != 0; element++)
1297 			;
1298 	}
1299 
1300 	/* Describe the visual */
1301 	strnfmt(text, 256, "The %%v %s %s...", glow_desc[randint0(NUM_ELEMENTS(glow_desc))], element_colors[element]);
1302 
1303 	switch (randint1(10))
1304 	{
1305 	/* Breathe */
1306 	case 1:
1307 		strnfmt(text, 256, "You breathe %s.", element_names[element]);
1308 
1309 		/* Dice, radius, and charge time */
1310 		dice = rlev * 5;
1311 		radius = 2 + dice / rand_range(100, 200);
1312 		pp = dice * 10 * radius;
1313 
1314 		/* Create the lua */
1315 		strnfmt(desc, 256, "breathe %s (%i, rad. %i)", element_names[element], dice, radius);
1316 		strnfmt(effect, 256, "fire_ball(%s, dir, %i, %i)", element_list[element], dice, radius);
1317 
1318 		break;
1319 
1320 	/* Emit a blast */
1321 	case 2:
1322 		strnfmt(text, 256, "The %%v emits a blast of %s...", element_names[element]);
1323 
1324 		/* Dice, radius, and charge time */
1325 		dice = rlev * 10;
1326 		radius = 2 + dice / rand_range(50, 100);
1327 		pp = dice * 2 * radius;
1328 
1329 		aimed = FALSE;
1330 
1331 		/* Create the lua */
1332 		strnfmt(desc, 256, "%s blast (%i, rad. %i)", element_names[element], dice, radius);
1333 		strnfmt(effect, 256, "fire_ball(%s, 0, %i, %i)", element_list[element], dice, radius);
1334 
1335 		break;
1336 
1337 	/* Fire a ball */
1338 	case 3:
1339 	case 4:
1340 	case 5:
1341 		/* Dice, radius, and charge time */
1342 		dice = 5 * (1 + rlev / 2);
1343 		radius = 2 + dice / rand_range(100, 200);
1344 		pp = dice * 10 * radius;
1345 
1346 		/* Create the lua */
1347 		strnfmt(desc, 256, "%s%s ball (%i)", radius > 2 ? "large " : "", element_names[element], dice);
1348 		strnfmt(effect, 256, "fire_ball(%s, dir, %i, %i)", element_list[element], dice, radius);
1349 
1350 		break;
1351 
1352 	/* Fire a beam */
1353 	case 6:
1354 		/* Dice and charge time */
1355 		dice = 1 + rlev / 3;
1356 		sides = rand_range(5, 8);
1357 		pp = dice * sides * 10;
1358 
1359 		/* Create the lua */
1360 		strnfmt(desc, 256, "%s beam (%id%i)", element_names[element], dice, sides);
1361 		strnfmt(effect, 256, "fire_beam(%s, dir, damroll(%i, %i))", element_list[element], dice, sides);
1362 
1363 		break;
1364 
1365 	/* Fire a bolt */
1366 	default:
1367 		/* Dice and charge time */
1368 		dice = 1 + rlev / 2;
1369 		sides = rand_range(5, 8);
1370 		pp = dice * sides * 5;
1371 
1372 		/* Create the lua */
1373 		strnfmt(desc, 256, "%s bolt (%id%i)", element_names[element], dice, sides);
1374 		strnfmt(effect, 256, "fire_bolt(%s, dir, damroll(%i, %i))", element_list[element], dice, sides);
1375 
1376 		break;
1377 	}
1378 
1379 	apply_activation_power(o_ptr, text, desc, effect, aimed, pp, level);
1380 }
1381 
misc_activation_power(object_type * o_ptr,int level,cptr fix_power)1382 static void misc_activation_power(object_type *o_ptr, int level, cptr fix_power)
1383 {
1384 	const struct randart_activation *act = NULL;
1385 	char dice[32];
1386 	char dice_desc[32];
1387 	char effect[256] = "";
1388 	char desc[256] = "";
1389 	int pp;
1390 
1391 	int rlev = level * rand_range(50, 150) / 100;
1392 	if (rlev < 1) rlev = 1;
1393 
1394 	if (!fix_power)
1395 	{
1396 		do
1397 		{
1398 			act = &randart_activations[randint0(NUM_ELEMENTS(randart_activations))];
1399 		}
1400 		while (act->freq < randint1(100));
1401 	}
1402 	else
1403 	{
1404 		int i;
1405 		for (i = 0; strcmp(randart_activations[i].desc, fix_power) != 0; i++)
1406 			;
1407 		act = &randart_activations[i];
1408 	}
1409 
1410 	/* Sometimes make the activation dependent on the player's level */
1411 	if (one_in_(10) && act->dice >= 100 && act->bonus == 0)
1412 	{
1413 		/* Deeper items may give better multipliers */
1414 		int mult = act->dice * rand_range(50, 100 + 2 * rlev) / 10000;
1415 		if (mult < 1) mult = 1;
1416 
1417 		if (mult > 1)
1418 		{
1419 			strnfmt(dice, 32, "player.lev * %i", mult);
1420 			strnfmt(dice_desc, 32, "plev * %i", mult);
1421 		}
1422 		else
1423 		{
1424 			strcpy(dice, "player.lev");
1425 			strcpy(dice_desc, "plev");
1426 		}
1427 
1428 		/* Fill in the dice */
1429 		strnfmt(desc, 256, act->desc, dice_desc);
1430 		strnfmt(effect, 256, act->effect, dice);
1431 
1432 		/* Assume plev 30 for power calculation */
1433 		pp = act->pp * mult * 30;
1434 	}
1435 	else
1436 	{
1437 		int d = rlev * act->dice / 100 + act->bonus;
1438 		if (d < 1) d = 1;
1439 
1440 		/* Fill in the dice */
1441 		strnfmt(dice, 32, "%i", d);
1442 		strnfmt(desc, 256, act->desc, dice);
1443 		strnfmt(effect, 256, act->effect, dice);
1444 
1445 		pp = act->pp * d;
1446 	}
1447 
1448 	apply_activation_power(o_ptr, act->text, desc, effect, act->aimed, pp, level);
1449 }
1450 
random_activation_power(object_type * o_ptr,int level)1451 static void random_activation_power(object_type *o_ptr, int level)
1452 {
1453 	int rlev = level * rand_range(50, 150) / 100;
1454 	if (rlev < 1) rlev = 1;
1455 
1456 	/* 60%/20% chance of a random attack */
1457 	if (randint0(100) < (o_ptr->tval < TV_BOOTS ? 60 : 20))
1458 		attack_activation_power(o_ptr, level, NULL);
1459 	else
1460 		misc_activation_power(o_ptr, level, NULL);
1461 }
1462 
get_random_name(char * return_name,byte tval,int power)1463 static void get_random_name(char *return_name, byte tval, int power)
1464 {
1465 	if ((randint1(100) <= TABLE_NAME) ||
1466 		(tval == TV_AMULET) || (tval == TV_RING))
1467 	{
1468 		get_table_name(return_name, TRUE);
1469 	}
1470 	else
1471 	{
1472 		cptr filename;
1473 
1474 		/* Armour or a Weapon? */
1475 		if (tval >= TV_BOOTS)
1476 		{
1477 			switch (power)
1478 			{
1479 				case 0:
1480 					filename = "a_cursed.txt";
1481 					break;
1482 				case 1:
1483 					filename = "a_low.txt";
1484 					break;
1485 				case 2:
1486 					filename = "a_med.txt";
1487 					break;
1488 				default:
1489 					filename = "a_high.txt";
1490 			}
1491 		}
1492 		else
1493 		{
1494 			switch (power)
1495 			{
1496 				case 0:
1497 					filename = "w_cursed.txt";
1498 					break;
1499 				case 1:
1500 					filename = "w_low.txt";
1501 					break;
1502 				case 2:
1503 					filename = "w_med.txt";
1504 					break;
1505 				default:
1506 					filename = "w_high.txt";
1507 			}
1508 		}
1509 
1510 		(void)get_rnd_line(filename, 0, return_name);
1511 	}
1512 }
1513 
1514 
random_minor_theme_weapon(object_type * o_ptr,int level)1515 static int random_minor_theme_weapon(object_type *o_ptr, int level)
1516 {
1517 	int activate = 0;
1518 
1519 	switch (randint1(39))
1520 	{
1521 		case 1:
1522 		case 2:
1523 		case 3:
1524 			SET_FLAG(o_ptr, TR_WIS);
1525 			SET_FLAG(o_ptr, TR_BLESSED);
1526 
1527 			break;
1528 
1529 		case 4:
1530 		case 5:
1531 			SET_FLAG(o_ptr, TR_BRAND_ACID);
1532 			SET_FLAG(o_ptr, TR_RES_ACID);
1533 			if (o_ptr->tval == TV_SWORD && one_in_(3))
1534 				SET_FLAG(o_ptr, TR_TUNNEL);
1535 
1536 			if (one_in_(ACTIVATION_CHANCE))
1537 				attack_activation_power(o_ptr, level, "GF_ACID");
1538 
1539 			break;
1540 
1541 		case 6:
1542 		case 7:
1543 			SET_FLAG(o_ptr, TR_BRAND_ELEC);
1544 			SET_FLAG(o_ptr, TR_RES_ELEC);
1545 
1546 			if (one_in_(ACTIVATION_CHANCE))
1547 				attack_activation_power(o_ptr, level, "GF_ELEC");
1548 
1549 			break;
1550 
1551 		case 8:
1552 		case 9:
1553 		case 10:
1554 			SET_FLAG(o_ptr, TR_BRAND_FIRE);
1555 			SET_FLAG(o_ptr, TR_RES_FIRE);
1556 			SET_FLAG(o_ptr, TR_LITE);
1557 
1558 			if (one_in_(ACTIVATION_CHANCE))
1559 				attack_activation_power(o_ptr, level, "GF_FIRE");
1560 
1561 			break;
1562 
1563 		case 11:
1564 		case 12:
1565 		case 13:
1566 			SET_FLAG(o_ptr, TR_BRAND_COLD);
1567 			SET_FLAG(o_ptr, TR_RES_COLD);
1568 
1569 			if (one_in_(ACTIVATION_CHANCE))
1570 				attack_activation_power(o_ptr, level, "GF_COLD");
1571 
1572 			break;
1573 
1574 		case 14:
1575 		case 15:
1576 			SET_FLAG(o_ptr, TR_BRAND_POIS);
1577 			SET_FLAG(o_ptr, TR_RES_POIS);
1578 
1579 			if (one_in_(ACTIVATION_CHANCE))
1580 				attack_activation_power(o_ptr, level, "GF_POIS");
1581 
1582 			break;
1583 
1584 		case 16:
1585 		case 17:
1586 			SET_FLAG(o_ptr, TR_CHAOTIC);
1587 			SET_FLAG(o_ptr, TR_RES_CHAOS);
1588 			if (one_in_(3))
1589 				SET_FLAG(o_ptr, TR_PATRON);
1590 
1591 			if (one_in_(ACTIVATION_CHANCE))
1592 				attack_activation_power(o_ptr, level, "GF_CHAOS");
1593 
1594 			break;
1595 
1596 		case 18:
1597 			if (o_ptr->tval == TV_SWORD)
1598 			{
1599 				SET_FLAG(o_ptr, TR_VORPAL);
1600 				SET_FLAG(o_ptr, TR_TUNNEL);
1601 			}
1602 			else
1603 			{
1604 				SET_FLAG(o_ptr, TR_BLOWS);
1605 			}
1606 
1607 			break;
1608 
1609 		case 19:
1610 		case 20:
1611 			SET_FLAG(o_ptr, TR_SLAY_ANIMAL);
1612 			if (one_in_(2))
1613 				SET_FLAG(o_ptr, TR_INT);
1614 			if (one_in_(2))
1615 				SET_FLAG(o_ptr, TR_REGEN);
1616 
1617 			break;
1618 
1619 		case 21:
1620 		case 22:
1621 		case 23:
1622 			SET_FLAG(o_ptr, TR_SLAY_EVIL);
1623 			SET_FLAG(o_ptr, TR_BLESSED);
1624 			if (one_in_(2))
1625 				SET_FLAG(o_ptr, TR_WIS);
1626 			if (one_in_(2))
1627 				SET_FLAG(o_ptr, TR_RES_FEAR);
1628 
1629 			break;
1630 
1631 		case 24:
1632 		case 25:
1633 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
1634 			if (one_in_(2))
1635 				SET_FLAG(o_ptr, TR_INT);
1636 			if (one_in_(2))
1637 				SET_FLAG(o_ptr, TR_HOLD_LIFE);
1638 			if (one_in_(2))
1639 				SET_FLAG(o_ptr, TR_SEE_INVIS);
1640 
1641 			break;
1642 
1643 		case 26:
1644 		case 27:
1645 			SET_FLAG(o_ptr, TR_SLAY_DEMON);
1646 			SET_FLAG(o_ptr, TR_INT);
1647 
1648 			break;
1649 
1650 		case 28:
1651 		case 29:
1652 			SET_FLAG(o_ptr, TR_SLAY_ORC);
1653 			SET_FLAG(o_ptr, TR_DEX);
1654 
1655 			break;
1656 
1657 		case 30:
1658 		case 31:
1659 			SET_FLAG(o_ptr, TR_SLAY_GIANT);
1660 			SET_FLAG(o_ptr, TR_STR);
1661 
1662 			break;
1663 
1664 		case 32:
1665 		case 33:
1666 			SET_FLAG(o_ptr, TR_SLAY_DRAGON);
1667 			if (one_in_(3))
1668 				SET_FLAG(o_ptr, TR_KILL_DRAGON);
1669 			SET_FLAG(o_ptr, TR_CON);
1670 
1671 			break;
1672 
1673 		case 34:
1674 		case 35:
1675 			SET_FLAG(o_ptr, TR_VAMPIRIC);
1676 			SET_FLAG(o_ptr, TR_HOLD_LIFE);
1677 
1678 			if (one_in_(ACTIVATION_CHANCE))
1679 				misc_activation_power(o_ptr, level, "vampiric drain (%s)");
1680 
1681 			break;
1682 
1683 		case 36:
1684 			SET_FLAG(o_ptr, TR_HOLD_LIFE);
1685 			if (one_in_(ACTIVATION_CHANCE))
1686 				misc_activation_power(o_ptr, level, "drain life (%s)");
1687 
1688 			break;
1689 
1690 		case 37:
1691 			o_ptr->to_h += (s16b) rand_range(5, 15);
1692 			o_ptr->to_d += (s16b) rand_range(5, 15);
1693 
1694 			if (one_in_(ACTIVATION_CHANCE))
1695 				misc_activation_power(o_ptr, level, "whirlwind attack");
1696 
1697 			break;
1698 
1699 		case 38:
1700 			SET_FLAG(o_ptr, TR_SLAY_ANIMAL);
1701 
1702 			if (one_in_(ACTIVATION_CHANCE))
1703 				misc_activation_power(o_ptr, level, "charm animal");
1704 
1705 			break;
1706 
1707 		case 39:
1708 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
1709 
1710 			if (one_in_(ACTIVATION_CHANCE))
1711 				misc_activation_power(o_ptr, level, "enslave undead");
1712 
1713 			break;
1714 
1715 		case 40:
1716 			if (o_ptr->tval == TV_SWORD)
1717 				SET_FLAG(o_ptr, TR_TUNNEL);
1718 
1719 #if 0
1720 			activate = ACT_STONE_MUD;
1721 #endif
1722 
1723 			break;
1724 	}
1725 
1726 	return activate;
1727 }
1728 
random_major_theme_weapon(object_type * o_ptr,int level)1729 static int random_major_theme_weapon(object_type *o_ptr, int level)
1730 {
1731 	int activate = 0;
1732 
1733 	switch (randint1(7))
1734 	{
1735 	case 1:
1736 		/* Holy Avenger */
1737 		SET_FLAG(o_ptr, TR_SLAY_EVIL);
1738 		SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
1739 		SET_FLAG(o_ptr, TR_SLAY_DEMON);
1740 		SET_FLAG(o_ptr, TR_SEE_INVIS);
1741 		SET_FLAG(o_ptr, TR_BLESSED);
1742 
1743 		if (one_in_(ACTIVATION_CHANCE))
1744 			misc_activation_power(o_ptr, level, "dispel evil (%s)");
1745 
1746 		break;
1747 
1748 	case 2:
1749 		/* Defender */
1750 		SET_FLAG(o_ptr, TR_RES_ACID);
1751 		SET_FLAG(o_ptr, TR_RES_ELEC);
1752 		SET_FLAG(o_ptr, TR_RES_FIRE);
1753 		SET_FLAG(o_ptr, TR_RES_COLD);
1754 		if (one_in_(2))
1755 			SET_FLAG(o_ptr, TR_FREE_ACT);
1756 		if (one_in_(2))
1757 			SET_FLAG(o_ptr, TR_SEE_INVIS);
1758 		if (one_in_(2))
1759 			SET_FLAG(o_ptr, TR_FEATHER);
1760 		if (one_in_(2))
1761 			SET_FLAG(o_ptr, TR_REGEN);
1762 		if (one_in_(2))
1763 			o_ptr->to_a += randint1(5);
1764 
1765 #if 0
1766 		if (one_in_(8))
1767 			activate = ACT_RESIST_ALL;
1768 #endif
1769 
1770 		break;
1771 
1772 	case 3:
1773 		/* Westernesse */
1774 		SET_FLAG(o_ptr, TR_STR);
1775 		SET_FLAG(o_ptr, TR_DEX);
1776 		SET_FLAG(o_ptr, TR_CON);
1777 		SET_FLAG(o_ptr, TR_SLAY_ORC);
1778 		SET_FLAG(o_ptr, TR_SLAY_TROLL);
1779 		SET_FLAG(o_ptr, TR_SLAY_GIANT);
1780 
1781 		break;
1782 
1783 	case 4:
1784 		/* Trump Weapon */
1785 		SET_FLAG(o_ptr, TR_SLAY_EVIL);
1786 		SET_FLAG(o_ptr, TR_TELEPORT);
1787 		SET_FLAG(o_ptr, TR_FREE_ACT);
1788 		if (one_in_(2))
1789 			SET_FLAG(o_ptr, TR_SEARCH);
1790 		if (one_in_(2))
1791 			SET_FLAG(o_ptr, TR_REGEN);
1792 		if (one_in_(2))
1793 			SET_FLAG(o_ptr, TR_SLOW_DIGEST);
1794 
1795 		if (one_in_(ACTIVATION_CHANCE))
1796 			misc_activation_power(o_ptr, level, "teleport (100)");
1797 
1798 		break;
1799 
1800 	case 5:
1801 		/* Pattern Weapon */
1802 		SET_FLAG(o_ptr, TR_STR);
1803 		SET_FLAG(o_ptr, TR_CON);
1804 		SET_FLAG(o_ptr, TR_FREE_ACT);
1805 		SET_FLAG(o_ptr, TR_SEE_INVIS);
1806 		if (one_in_(2))
1807 			SET_FLAG(o_ptr, TR_SLAY_EVIL);
1808 		if (one_in_(2))
1809 			SET_FLAG(o_ptr, TR_SLAY_DEMON);
1810 		if (one_in_(2))
1811 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
1812 
1813 		break;
1814 
1815 	case 6:
1816 		/* Mixed slays */
1817 		if (one_in_(3))
1818 			SET_FLAG(o_ptr, TR_SLAY_ANIMAL);
1819 		if (one_in_(3))
1820 			SET_FLAG(o_ptr, TR_SLAY_EVIL);
1821 		if (one_in_(3))
1822 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
1823 		if (one_in_(3))
1824 			SET_FLAG(o_ptr, TR_SLAY_DEMON);
1825 		if (one_in_(3))
1826 			SET_FLAG(o_ptr, TR_SLAY_ORC);
1827 		if (one_in_(3))
1828 			SET_FLAG(o_ptr, TR_SLAY_TROLL);
1829 		if (one_in_(3))
1830 			SET_FLAG(o_ptr, TR_SLAY_GIANT);
1831 		if (one_in_(3))
1832 			SET_FLAG(o_ptr, TR_SLAY_DRAGON);
1833 
1834 		break;
1835 
1836 	case 7:
1837 		/* Assassin blade */
1838 		SET_FLAG(o_ptr, TR_STEALTH);
1839 		SET_FLAG(o_ptr, TR_BLOWS);
1840 		SET_FLAG(o_ptr, TR_FREE_ACT);
1841 
1842 		if (one_in_(2))
1843 			SET_FLAG(o_ptr, TR_BRAND_POIS);
1844 		else
1845 			SET_FLAG(o_ptr, TR_VAMPIRIC);
1846 
1847 		if (o_ptr->tval == TV_SWORD)
1848 			SET_FLAG(o_ptr, TR_THROW);
1849 
1850 		break;
1851 	}
1852 
1853 	return activate;
1854 }
1855 
random_minor_theme_armor(object_type * o_ptr,int level)1856 static int random_minor_theme_armor(object_type *o_ptr, int level)
1857 {
1858 	int activate = 0;
1859 
1860 	switch (randint1(33))
1861 	{
1862 		case 1:
1863 		case 2:
1864 		case 3:
1865 			SET_FLAG(o_ptr, TR_SEE_INVIS);
1866 			SET_FLAG(o_ptr, TR_SEARCH);
1867 
1868 			break;
1869 
1870 		case 4:
1871 		case 5:
1872 			SET_FLAG(o_ptr, TR_STR);
1873 			SET_FLAG(o_ptr, TR_SUST_STR);
1874 			if (one_in_(3))
1875 				SET_FLAG(o_ptr, TR_RES_FEAR);
1876 
1877 			break;
1878 
1879 		case 6:
1880 		case 7:
1881 			SET_FLAG(o_ptr, TR_INT);
1882 			SET_FLAG(o_ptr, TR_SUST_INT);
1883 			if (one_in_(3))
1884 				SET_FLAG(o_ptr, TR_FEATHER);
1885 
1886 			break;
1887 
1888 		case 8:
1889 		case 9:
1890 			SET_FLAG(o_ptr, TR_WIS);
1891 			SET_FLAG(o_ptr, TR_SUST_WIS);
1892 			if (one_in_(3))
1893 				SET_FLAG(o_ptr, TR_SEE_INVIS);
1894 
1895 			break;
1896 
1897 		case 10:
1898 		case 11:
1899 			SET_FLAG(o_ptr, TR_DEX);
1900 			SET_FLAG(o_ptr, TR_SUST_DEX);
1901 			if (one_in_(3))
1902 				SET_FLAG(o_ptr, TR_FREE_ACT);
1903 
1904 			break;
1905 
1906 		case 12:
1907 		case 13:
1908 			SET_FLAG(o_ptr, TR_CON);
1909 			SET_FLAG(o_ptr, TR_SUST_CON);
1910 			if (one_in_(3))
1911 				SET_FLAG(o_ptr, TR_REGEN);
1912 
1913 			break;
1914 
1915 		case 14:
1916 		case 15:
1917 			SET_FLAG(o_ptr, TR_CHR);
1918 			SET_FLAG(o_ptr, TR_SUST_CHR);
1919 			if (one_in_(3))
1920 				SET_FLAG(o_ptr, TR_LITE);
1921 
1922 			break;
1923 
1924 		case 16:
1925 			SET_FLAG(o_ptr, TR_LITE);
1926 			SET_FLAG(o_ptr, TR_RES_LITE);
1927 
1928 			if (one_in_(ACTIVATION_CHANCE))
1929 				misc_activation_power(o_ptr, level, "light area (2d20)");
1930 
1931 			break;
1932 
1933 		case 17:
1934 		case 18:
1935 			SET_FLAG(o_ptr, TR_RES_FIRE);
1936 			SET_FLAG(o_ptr, TR_SH_FIRE);
1937 
1938 			break;
1939 
1940 		case 19:
1941 			SET_FLAG(o_ptr, TR_RES_ELEC);
1942 			SET_FLAG(o_ptr, TR_SH_ELEC);
1943 
1944 			break;
1945 
1946 		case 20:
1947 			SET_FLAG(o_ptr, TR_RES_COLD);
1948 			SET_FLAG(o_ptr, TR_SH_COLD);
1949 
1950 			break;
1951 
1952 		case 21:
1953 			SET_FLAG(o_ptr, TR_INT);
1954 			SET_FLAG(o_ptr, TR_WIS);
1955 
1956 			break;
1957 
1958 		case 22:
1959 			SET_FLAG(o_ptr, TR_RES_LITE);
1960 			SET_FLAG(o_ptr, TR_RES_DARK);
1961 			if (one_in_(2))
1962 				SET_FLAG(o_ptr, TR_LITE);
1963 
1964 			break;
1965 
1966 		case 23:
1967 			SET_FLAG(o_ptr, TR_SLAY_EVIL);
1968 
1969 			if (one_in_(ACTIVATION_CHANCE))
1970 				misc_activation_power(o_ptr, level, "banish evil");
1971 			else if (one_in_(ACTIVATION_CHANCE))
1972 				misc_activation_power(o_ptr, level, "dispel evil (%s)");
1973 
1974 			break;
1975 
1976 		case 24:
1977 			SET_FLAG(o_ptr, TR_STEALTH);
1978 
1979 			if (one_in_(ACTIVATION_CHANCE))
1980 				misc_activation_power(o_ptr, level, "sleep nearby monsters");
1981 
1982 			break;
1983 
1984 		case 25:
1985 			SET_FLAG(o_ptr, TR_WIS);
1986 
1987 			if (one_in_(ACTIVATION_CHANCE))
1988 				misc_activation_power(o_ptr, level, "telepathy (%s+ turns)");
1989 
1990 			break;
1991 
1992 		case 26:
1993 			SET_FLAG(o_ptr, TR_RES_DARK);
1994 
1995 			if (one_in_(ACTIVATION_CHANCE))
1996 				misc_activation_power(o_ptr, level, "beam of sunlight (%sd8)");
1997 			else if (one_in_(ACTIVATION_CHANCE))
1998 				misc_activation_power(o_ptr, level, "light area (2d20)");
1999 
2000 			break;
2001 
2002 		case 27:
2003 			SET_FLAG(o_ptr, TR_RES_CHAOS);
2004 			SET_FLAG(o_ptr, TR_RES_CONF);
2005 
2006 			break;
2007 
2008 		case 28:
2009 			SET_FLAG(o_ptr, TR_RES_NETHER);
2010 			SET_FLAG(o_ptr, TR_HOLD_LIFE);
2011 
2012 			if (one_in_(ACTIVATION_CHANCE))
2013 				misc_activation_power(o_ptr, level, "restore life levels");
2014 
2015 			break;
2016 
2017 		case 29:
2018 			SET_FLAG(o_ptr, TR_RES_SOUND);
2019 			SET_FLAG(o_ptr, TR_RES_SHARDS);
2020 
2021 			break;
2022 
2023 		case 30:
2024 			SET_FLAG(o_ptr, TR_RES_FEAR);
2025 
2026 			if (one_in_(ACTIVATION_CHANCE))
2027 				misc_activation_power(o_ptr, level, "terror");
2028 			else if (one_in_(ACTIVATION_CHANCE))
2029 				misc_activation_power(o_ptr, level, "heroism (%s+ turns)");
2030 
2031 			break;
2032 
2033 		case 31:
2034 			SET_FLAG(o_ptr, TR_SLAY_ANIMAL);
2035 
2036 #if 0
2037 			if (one_in_(3))
2038 				activate = ACT_CHARM_ANIMAL;
2039 			else if (one_in_(2))
2040 				activate = ACT_CHARM_ANIMALS;
2041 			else
2042 				activate = ACT_SUMMON_ANIMAL;
2043 #endif
2044 
2045 			break;
2046 
2047 		case 32:
2048 			SET_FLAG(o_ptr, TR_SLAY_UNDEAD);
2049 
2050 #if 0
2051 			if (one_in_(2))
2052 				activate = ACT_CHARM_UNDEAD;
2053 			else
2054 				activate = ACT_SUMMON_UNDEAD;
2055 #endif
2056 
2057 			break;
2058 
2059 		case 33:
2060 			SET_FLAG(o_ptr, TR_SLAY_DEMON);
2061 
2062 #if 0
2063 			activate = ACT_SUMMON_DEMON;
2064 #endif
2065 
2066 			break;
2067 	}
2068 
2069 	return activate;
2070 }
2071 
random_major_theme_armor(object_type * o_ptr,int level)2072 static int random_major_theme_armor(object_type *o_ptr, int level)
2073 {
2074 	int activate = 0;
2075 
2076 	int i;
2077 
2078 	/* Hack - ignore unused parameter */
2079 	(void) level;
2080 
2081 	switch (randint1(10))
2082 	{
2083 		case 1:
2084 			SET_FLAG(o_ptr, TR_RES_ACID);
2085 			SET_FLAG(o_ptr, TR_RES_ELEC);
2086 			SET_FLAG(o_ptr, TR_RES_FIRE);
2087 			SET_FLAG(o_ptr, TR_RES_COLD);
2088 
2089 			if (one_in_(3))
2090 				SET_FLAG(o_ptr, TR_RES_POIS);
2091 
2092 			break;
2093 
2094 		case 2:
2095 			SET_FLAG(o_ptr, TR_SUST_STR);
2096 			SET_FLAG(o_ptr, TR_SUST_INT);
2097 			SET_FLAG(o_ptr, TR_SUST_WIS);
2098 			SET_FLAG(o_ptr, TR_SUST_DEX);
2099 			SET_FLAG(o_ptr, TR_SUST_CON);
2100 			SET_FLAG(o_ptr, TR_SUST_CHR);
2101 
2102 			break;
2103 
2104 		case 3:
2105 			/* Might */
2106 			SET_FLAG(o_ptr, TR_STR);
2107 			SET_FLAG(o_ptr, TR_SUST_STR);
2108 			SET_FLAG(o_ptr, TR_DEX);
2109 			SET_FLAG(o_ptr, TR_SUST_DEX);
2110 			SET_FLAG(o_ptr, TR_CON);
2111 			SET_FLAG(o_ptr, TR_SUST_CON);
2112 
2113 			break;
2114 
2115 		case 4:
2116 			/* Mental */
2117 			SET_FLAG(o_ptr, TR_INT);
2118 			SET_FLAG(o_ptr, TR_SUST_INT);
2119 			SET_FLAG(o_ptr, TR_WIS);
2120 			SET_FLAG(o_ptr, TR_SUST_WIS);
2121 			if (one_in_(3))
2122 				SET_FLAG(o_ptr, TR_SP);
2123 
2124 			break;
2125 
2126 		case 5:
2127 			/* Lohengrin */
2128 			SET_FLAG(o_ptr, TR_STEALTH);
2129 			SET_FLAG(o_ptr, TR_INT);
2130 			SET_FLAG(o_ptr, TR_WIS);
2131 			SET_FLAG(o_ptr, TR_SEE_INVIS);
2132 
2133 			break;
2134 
2135 		case 6:
2136 		case 7:
2137 		case 8:
2138 			/* Several high resists */
2139 			for (i = randint1(3) + 1; i > 0; --i)
2140 				random_resistance(o_ptr, rand_range(17, 38));
2141 
2142 			break;
2143 
2144 		case 9:
2145 			/* Mixed stat boosts */
2146 			for (i = 3; i > 0; --i)
2147 			{
2148 				switch (randint1(6))
2149 				{
2150 					case 1: SET_FLAG(o_ptr, TR_STR); break;
2151 					case 2: SET_FLAG(o_ptr, TR_INT); break;
2152 					case 3: SET_FLAG(o_ptr, TR_WIS); break;
2153 					case 4: SET_FLAG(o_ptr, TR_DEX); break;
2154 					case 5: SET_FLAG(o_ptr, TR_CON); break;
2155 					case 6: SET_FLAG(o_ptr, TR_CHR); break;
2156 				}
2157 			}
2158 
2159 			break;
2160 
2161 		case 10:
2162 			/* Thranduil */
2163 			SET_FLAG(o_ptr, TR_INT);
2164 			SET_FLAG(o_ptr, TR_WIS);
2165 			SET_FLAG(o_ptr, TR_RES_BLIND);
2166 			if (o_ptr->tval == TV_HELM || o_ptr->tval == TV_CROWN)
2167 				SET_FLAG(o_ptr, TR_TELEPATHY);
2168 
2169 			break;
2170 	}
2171 
2172 	return activate;
2173 }
2174 
curse_artifact(object_type * o_ptr)2175 static void curse_artifact(object_type *o_ptr)
2176 {
2177 	int i;
2178 
2179 	if (o_ptr->pval > 0) o_ptr->pval = 0 - (o_ptr->pval + randint1(4));
2180 	if (o_ptr->to_a > 0) o_ptr->to_a = 0 - (o_ptr->to_a + randint1(4));
2181 	if (o_ptr->to_h > 0) o_ptr->to_h = 0 - (o_ptr->to_h + randint1(4));
2182 	if (o_ptr->to_d > 0) o_ptr->to_d = 0 - (o_ptr->to_d + randint1(4));
2183 
2184 	SET_FLAG(o_ptr, TR_CURSED);
2185 
2186 	for (i = rand_range(2, 6); i > 0; --i)
2187 		random_curse(o_ptr, TRUE);
2188 }
2189 
2190 
create_artifact(object_type * o_ptr,int level,bool a_scroll)2191 bool create_artifact(object_type *o_ptr, int level, bool a_scroll)
2192 {
2193 	char new_name[1024];
2194 	int powers = rand_range(2, 6);
2195 	int power_level;
2196 	s32b total_flags, target_flags;
2197 	bool a_cursed = FALSE;
2198 	int i;
2199 	int given = 0;
2200 
2201 	/* No activation yet */
2202 	o_ptr->a_idx = 0;
2203 
2204 	new_name[0] = 0;
2205 
2206 	if (!a_scroll && one_in_(A_CURSED))
2207 		a_cursed = TRUE;
2208 
2209 	while (one_in_(powers + 1))
2210 		powers++;
2211 
2212 #if 0
2213 	if (!a_cursed && one_in_(12))
2214 		powers *= 2;
2215 #endif
2216 
2217 	if (a_cursed) powers /= 2;
2218 
2219 	target_flags = 0;
2220 	for (i = 0; i < powers; i++)
2221 		target_flags += rand_range(10, 50) * (level + 5);
2222 
2223 	/* Sometimes select a major theme - or two */
2224 	while (o_ptr->tval < TV_LITE && randint1(powers) > 3)
2225 	{
2226 		int act;
2227 
2228 		if (o_ptr->tval == TV_BOW)
2229 		{
2230 			/* Hack - bows don't have major themes yet */
2231 			random_slay(o_ptr);
2232 		}
2233 		else if (o_ptr->tval < TV_BOOTS)
2234 		{
2235 			act = random_major_theme_weapon(o_ptr, level);
2236 			o_ptr->to_h += (s16b) rand_range(5, 15);
2237 			o_ptr->to_d += (s16b) rand_range(5, 15);
2238 		}
2239 		else
2240 		{
2241 			act = random_major_theme_armor(o_ptr, level);
2242 			o_ptr->to_a += (s16b) rand_range(5, 15);
2243 		}
2244 		powers -= 3;
2245 	}
2246 
2247 	/* Possibly apply a power typical for the item's slot */
2248 	if (one_in_(2))
2249 	{
2250 		switch (o_ptr->tval)
2251 		{
2252 			case TV_BOOTS:
2253 				if (one_in_(12))
2254 					SET_FLAG(o_ptr, TR_SPEED);
2255 				else if (one_in_(2))
2256 					SET_FLAG(o_ptr, TR_FREE_ACT);
2257 				else
2258 					SET_FLAG(o_ptr, TR_FEATHER);
2259 				given++;
2260 				break;
2261 
2262 			case TV_GLOVES:
2263 				switch (randint1(3))
2264 				{
2265 				case 1:
2266 					SET_FLAG(o_ptr, TR_FREE_ACT);
2267 					break;
2268 				case 2:
2269 					SET_FLAG(o_ptr, TR_DEX);
2270 					break;
2271 				case 3:
2272 					SET_FLAG(o_ptr, TR_STR);
2273 					break;
2274 				}
2275 				given++;
2276 				break;
2277 
2278 			case TV_HELM:
2279 			case TV_CROWN:
2280 				switch (randint1(5))
2281 				{
2282 				case 1:
2283 					SET_FLAG(o_ptr, TR_TELEPATHY);
2284 					break;
2285 				case 2:
2286 					SET_FLAG(o_ptr, TR_SEE_INVIS);
2287 					break;
2288 				case 3:
2289 					SET_FLAG(o_ptr, TR_INFRA);
2290 					break;
2291 				case 4:
2292 					SET_FLAG(o_ptr, TR_INT);
2293 					break;
2294 				case 5:
2295 					SET_FLAG(o_ptr, TR_WIS);
2296 					break;
2297 				}
2298 				given++;
2299 				break;
2300 
2301 			case TV_CLOAK:
2302 				if (one_in_(2))
2303 					SET_FLAG(o_ptr, TR_LUCK_10);
2304 				else
2305 					SET_FLAG(o_ptr, TR_STEALTH);
2306 				given++;
2307 				break;
2308 
2309 			case TV_SOFT_ARMOR:
2310 				switch (randint1(3))
2311 				{
2312 				case 1:
2313 					SET_FLAG(o_ptr, TR_DEX);
2314 					break;
2315 				case 2:
2316 					SET_FLAG(o_ptr, TR_CON);
2317 					break;
2318 				case 3:
2319 					SET_FLAG(o_ptr, TR_STEALTH);
2320 					break;
2321 				}
2322 				given++;
2323 				break;
2324 
2325 			case TV_HARD_ARMOR:
2326 				switch (randint1(3))
2327 				{
2328 				case 1:
2329 					SET_FLAG(o_ptr, TR_HOLD_LIFE);
2330 					break;
2331 				case 2:
2332 					SET_FLAG(o_ptr, TR_CON);
2333 					break;
2334 				case 3:
2335 					SET_FLAG(o_ptr, TR_REGEN);
2336 					break;
2337 				}
2338 				given++;
2339 				break;
2340 
2341 			case TV_SHIELD:
2342 				switch (randint1(3))
2343 				{
2344 				case 1:
2345 					SET_FLAG(o_ptr, TR_REFLECT);
2346 					break;
2347 				case 2:
2348 					SET_FLAG(o_ptr, TR_LITE);
2349 					break;
2350 				case 3:
2351 					SET_FLAG(o_ptr, TR_FREE_ACT);
2352 					break;
2353 				}
2354 				given++;
2355 				break;
2356 		}
2357 	}
2358 
2359 	/* Lights already have permanent light */
2360 	if (o_ptr->tval == TV_LITE)
2361 		given++;
2362 
2363 	total_flags = flag_cost(o_ptr, 1);
2364 
2365 	/* Main loop */
2366 	while (total_flags < target_flags || given < 2)
2367 	{
2368 		int act = 0;
2369 
2370 		switch (randint1(o_ptr->tval < TV_BOOTS ? 11 : 7))
2371 		{
2372 			case 1:  case 2:
2373 				random_plus(o_ptr);
2374 				break;
2375 			case 3:  case 4:
2376 				random_resistance(o_ptr, 0);
2377 				break;
2378 			case 5:
2379 				random_misc(o_ptr);
2380 				break;
2381 			case 6:  case 7:
2382 				act = random_minor_theme_armor(o_ptr, level);
2383 				break;
2384 			case 8:  case 9:
2385 				random_slay(o_ptr);
2386 				break;
2387 			case 10:  case 11:
2388 				act = random_minor_theme_weapon(o_ptr, level);
2389 				break;
2390 		}
2391 		given++;
2392 
2393 		total_flags = flag_cost(o_ptr, 1);
2394 	}
2395 
2396 	if (FLAG(o_ptr, TR_PVAL_MASK))
2397 	{
2398 		if (FLAG(o_ptr, TR_BLOWS))
2399 		{
2400 			if (one_in_(100))
2401 			{
2402 				o_ptr->pval = 2;
2403 			}
2404 			else
2405 			{
2406 				o_ptr->pval = 1;
2407 			}
2408 		}
2409 		else
2410 		{
2411 			i = randint1(100);
2412 
2413 			if (i <= 35)
2414 				o_ptr->pval = 1;
2415 			else if (i <= 65)
2416 				o_ptr->pval = 2;
2417 			else if (i <= 85)
2418 				o_ptr->pval = 3;
2419 			else if (i <= 99)
2420 				o_ptr->pval = 4;
2421 			else
2422 				o_ptr->pval = 5;
2423 		}
2424 	}
2425 	else
2426 		o_ptr->pval = 0;
2427 
2428 	/* give it some plusses... */
2429 	if (o_ptr->tval >= TV_BOOTS && o_ptr->tval < TV_LITE)
2430 		o_ptr->to_a += randint1(o_ptr->to_a > 19 ? 1 : 20 - o_ptr->to_a);
2431 	else if (o_ptr->tval < TV_BOOTS)
2432 	{
2433 		o_ptr->to_h += randint1(o_ptr->to_h > 19 ? 1 : 20 - o_ptr->to_h);
2434 		o_ptr->to_d += randint1(o_ptr->to_d > 19 ? 1 : 20 - o_ptr->to_d);
2435 	}
2436 
2437 	/* Just to be sure */
2438 	o_ptr->flags[2] |= (TR2_IGNORE_ACID | TR2_IGNORE_ELEC |
2439 					  TR2_IGNORE_FIRE | TR2_IGNORE_COLD);
2440 
2441 	/* Possibly add some curses ... */
2442 	total_flags = flag_cost(o_ptr, o_ptr->pval);
2443 	if (one_in_(13))
2444 	{
2445 		random_curse(o_ptr, FALSE);
2446 		total_flags = flag_cost(o_ptr, o_ptr->pval);
2447 	}
2448 
2449 	/* Penalize too-good artifacts */
2450 	if (!a_scroll)
2451 	{
2452 		if (total_flags >= target_flags * 2 && total_flags >= 5000 &&
2453 				one_in_(2))
2454 		{
2455 			random_curse(o_ptr, FALSE);
2456 			total_flags = flag_cost(o_ptr, o_ptr->pval);
2457 		}
2458 		if (total_flags >= target_flags * 3 && total_flags >= 10000 &&
2459 				!one_in_(12))
2460 		{
2461 			random_curse(o_ptr, TRUE);
2462 			total_flags = flag_cost(o_ptr, o_ptr->pval);
2463 		}
2464 	}
2465 
2466 	if (cheat_peek) msgf("%ld", total_flags);
2467 
2468 	if (a_cursed) curse_artifact(o_ptr);
2469 
2470 	/* Check if it has an activation */
2471 	if (!a_cursed && one_in_((o_ptr->tval >= TV_BOOTS)
2472 							 ? ACTIVATION_CHANCE * 2 : ACTIVATION_CHANCE))
2473 	{
2474 		int activation_level = level + randint0(10);
2475 
2476 		if (one_in_(5))
2477 			activation_level = activation_level * 3 / 2;
2478 
2479 		if (activation_level > 100) activation_level = 100;
2480 
2481 		/*
2482 		 * Get a random activation
2483 		 */
2484 		random_activation_power(o_ptr, activation_level);
2485 	}
2486 
2487 	if (o_ptr->dd && o_ptr->ds)
2488 	{
2489 		if (one_in_(10L * o_ptr->dd * o_ptr->ds))
2490 		{
2491 			o_ptr->ds += (o_ptr->ds * randint1(5)) / 5;
2492 		}
2493 	}
2494 
2495 	if (o_ptr->tval >= TV_BOOTS)
2496 	{
2497 		if (a_cursed) power_level = 0;
2498 		else if (total_flags < 10000) power_level = 1;
2499 		else if (total_flags < 20000) power_level = 2;
2500 		else
2501 			power_level = 3;
2502 	}
2503 
2504 	else
2505 	{
2506 		if (a_cursed) power_level = 0;
2507 		else if (total_flags < 15000) power_level = 1;
2508 		else if (total_flags < 30000) power_level = 2;
2509 		else
2510 			power_level = 3;
2511 	}
2512 
2513 	/* If this non-weapon has the show_mod flag */
2514 	if (o_ptr->tval >= TV_BOOTS &&
2515 		o_ptr->tval <= TV_RING &&
2516 		FLAG(o_ptr, TR_SHOW_MODS))
2517 	{
2518 		/* Check if it is not accidentally zero */
2519 		if (!o_ptr->to_h && !o_ptr->to_d)
2520 		{
2521 			/* Turn of that flag, no silly (+0, +0%) display */
2522 			o_ptr->flags[2] &= ~(TR2_SHOW_MODS);
2523 		}
2524 	}
2525 
2526 	if (a_scroll)
2527 	{
2528 		char dummy_name[80];
2529 		dummy_name[0] = 0;
2530 
2531 		/* Identify it fully */
2532 		object_aware(o_ptr);
2533 		object_known(o_ptr);
2534 		object_mental(o_ptr);
2535 
2536 		/* Save all the known flags */
2537 		o_ptr->kn_flags[0] = o_ptr->flags[0];
2538 		o_ptr->kn_flags[1] = o_ptr->flags[1];
2539 		o_ptr->kn_flags[2] = o_ptr->flags[2];
2540 		o_ptr->kn_flags[3] = o_ptr->flags[3];
2541 
2542 		identify_fully_aux(o_ptr);
2543 
2544 		if (!(get_string(dummy_name, 80,
2545         				 "What do you want to call the artifact? ")))
2546 		{
2547 			get_random_name(new_name, o_ptr->tval, power_level);
2548 		}
2549 		else
2550 		{
2551 			strnfmt(new_name, 1024, "'%s'", dummy_name);
2552 		}
2553 	}
2554 	else
2555 	{
2556 		get_random_name(new_name, o_ptr->tval, power_level);
2557 	}
2558 
2559 	chg_virtue(V_INDIVIDUALISM, 2);
2560 	chg_virtue(V_ENCHANT, 5);
2561 
2562 	/* Save the inscription */
2563 	o_ptr->xtra_name = quark_add(new_name);
2564 
2565 	/* Make the object an artifact */
2566 	SET_FLAG(o_ptr, TR_INSTA_ART);
2567 
2568 	/* Set the cost */
2569 	o_ptr->cost = k_info[o_ptr->k_idx].cost + flag_cost(o_ptr, o_ptr->pval);
2570 
2571 	/* Notice changes */
2572 	notice_item();
2573 
2574 	return TRUE;
2575 }
2576 
2577 
2578 /*
2579  * Create the artifact of the specified number
2580  */
create_named_art(int a_idx,int x,int y)2581 void create_named_art(int a_idx, int x, int y)
2582 {
2583 	object_type *q_ptr;
2584 	int i;
2585 
2586 	artifact_type *a_ptr = &a_info[a_idx];
2587 
2588 	/* Ignore "empty" artifacts */
2589 	if (!a_ptr->name) return;
2590 
2591 	/* Acquire the "kind" index */
2592 	i = lookup_kind(a_ptr->tval, a_ptr->sval);
2593 
2594 	/* Oops */
2595 	if (!i) return;
2596 
2597 	/* Create the artifact */
2598 	q_ptr = object_prep(i);
2599 
2600 	/* Save the artifact number */
2601 	q_ptr->a_idx = a_idx;
2602 
2603 	/* Add any special scripts */
2604 	for (i = 0; i < MAX_TRIGGER; i++)
2605 	{
2606 		if (a_ptr->trigger[i])
2607 			q_ptr->trigger[i] = quark_add(a_text + a_ptr->trigger[i]);
2608 	}
2609 
2610 	/* Do not make another one */
2611 	a_ptr->cur_num = 1;
2612 
2613 	/* Save the artifact flags */
2614 	q_ptr->flags[0] |= a_ptr->flags[0];
2615 	q_ptr->flags[1] |= a_ptr->flags[1];
2616 	q_ptr->flags[2] |= a_ptr->flags[2];
2617 	q_ptr->flags[3] |= a_ptr->flags[3];
2618 
2619 	/* Extract the fields */
2620 	q_ptr->pval = a_ptr->pval;
2621 	q_ptr->ac = a_ptr->ac;
2622 	q_ptr->dd = a_ptr->dd;
2623 	q_ptr->ds = a_ptr->ds;
2624 	q_ptr->to_a = a_ptr->to_a;
2625 	q_ptr->to_h = a_ptr->to_h;
2626 	q_ptr->to_d = a_ptr->to_d;
2627 	q_ptr->weight = a_ptr->weight;
2628 
2629 	/* Save the inscription */
2630 	q_ptr->xtra_name = quark_add(a_name + a_ptr->name);
2631 
2632 	/* Apply special scripts */
2633 	apply_object_trigger(TRIGGER_MAKE, q_ptr, "i", "lev", a_ptr->level);
2634 
2635 	if (!a_ptr->cost)
2636 	{
2637 		/* Hack -- "worthless" artifacts */
2638 		q_ptr->cost = 0L;
2639 	}
2640 	else
2641 	{
2642 		/* Hack - use the artifact price */
2643 		q_ptr->cost = k_info[q_ptr->k_idx].cost + a_ptr->cost;
2644 	}
2645 
2646 	/* Drop the artifact from heaven */
2647 	drop_near(q_ptr, -1, x, y);
2648 }
2649