OSDN Git Service

./bootstrap 実行時に warning が出ないよう修正。
[hengband/hengband.git] / src / artifact.c
1 /* Purpose: Artifact code */
2
3 /*
4  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research, and
7  * not for profit purposes provided that this copyright and statement are
8  * included in all such copies.
9  */
10
11 #include "angband.h"
12
13
14 /* Chance of using syllables to form the name instead of the "template" files */
15 #define SINDARIN_NAME   10
16 #define TABLE_NAME      20
17 #define A_CURSED        13
18 #define WEIRD_LUCK      12
19 #define BIAS_LUCK       20
20 #define IM_LUCK         7
21
22 /*
23  * Bias luck needs to be higher than weird luck,
24  * since it is usually tested several times...
25  */
26 #define ACTIVATION_CHANCE 3
27
28
29 /*
30  * Use for biased artifact creation
31  */
32 static int artifact_bias;
33
34
35 /*
36  * Choose one random sustain
37  */
38 void one_sustain(object_type *o_ptr)
39 {
40         switch (randint0(6))
41         {
42                 case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
43                 case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
44                 case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
45                 case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
46                 case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
47                 case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
48         }
49 }
50
51
52 /*
53  * Choose one random high resistance
54  */
55 void one_high_resistance(object_type *o_ptr)
56 {
57         switch (randint0(12))
58         {
59                 case  0: add_flag(o_ptr->art_flags, TR_RES_POIS);   break;
60                 case  1: add_flag(o_ptr->art_flags, TR_RES_LITE);   break;
61                 case  2: add_flag(o_ptr->art_flags, TR_RES_DARK);   break;
62                 case  3: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
63                 case  4: add_flag(o_ptr->art_flags, TR_RES_BLIND);  break;
64                 case  5: add_flag(o_ptr->art_flags, TR_RES_CONF);   break;
65                 case  6: add_flag(o_ptr->art_flags, TR_RES_SOUND);  break;
66                 case  7: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
67                 case  8: add_flag(o_ptr->art_flags, TR_RES_NEXUS);  break;
68                 case  9: add_flag(o_ptr->art_flags, TR_RES_CHAOS);  break;
69                 case 10: add_flag(o_ptr->art_flags, TR_RES_DISEN);  break;
70                 case 11: add_flag(o_ptr->art_flags, TR_RES_FEAR);   break;
71         }
72 }
73
74
75 /*
76  * Choose one random high resistance ( except poison and disenchantment )
77  */
78 void one_lordly_high_resistance(object_type *o_ptr)
79 {
80         switch (randint0(10))
81         {
82                 case 0: add_flag(o_ptr->art_flags, TR_RES_LITE);   break;
83                 case 1: add_flag(o_ptr->art_flags, TR_RES_DARK);   break;
84                 case 2: add_flag(o_ptr->art_flags, TR_RES_SHARDS); break;
85                 case 3: add_flag(o_ptr->art_flags, TR_RES_BLIND);  break;
86                 case 4: add_flag(o_ptr->art_flags, TR_RES_CONF);   break;
87                 case 5: add_flag(o_ptr->art_flags, TR_RES_SOUND);  break;
88                 case 6: add_flag(o_ptr->art_flags, TR_RES_NETHER); break;
89                 case 7: add_flag(o_ptr->art_flags, TR_RES_NEXUS);  break;
90                 case 8: add_flag(o_ptr->art_flags, TR_RES_CHAOS);  break;
91                 case 9: add_flag(o_ptr->art_flags, TR_RES_FEAR);   break;
92         }
93 }
94
95
96 /*
97  * Choose one random element resistance
98  */
99 void one_ele_resistance(object_type *o_ptr)
100 {
101         switch (randint0(4))
102         {
103                 case  0: add_flag(o_ptr->art_flags, TR_RES_ACID); break;
104                 case  1: add_flag(o_ptr->art_flags, TR_RES_ELEC); break;
105                 case  2: add_flag(o_ptr->art_flags, TR_RES_COLD); break;
106                 case  3: add_flag(o_ptr->art_flags, TR_RES_FIRE); break;
107         }
108 }
109
110
111 /*
112  * Choose one random element or poison resistance
113  */
114 void one_dragon_ele_resistance(object_type *o_ptr)
115 {
116         if (one_in_(7))
117         {
118                 add_flag(o_ptr->art_flags, TR_RES_POIS);
119         }
120         else
121         {
122                 one_ele_resistance(o_ptr);
123         }
124 }
125
126
127 /*
128  * Choose one lower rank esp
129  */
130 void one_low_esp(object_type *o_ptr)
131 {
132         switch (randint1(9))
133         {
134         case 1: add_flag(o_ptr->art_flags, TR_ESP_ANIMAL);   break;
135         case 2: add_flag(o_ptr->art_flags, TR_ESP_UNDEAD);   break;
136         case 3: add_flag(o_ptr->art_flags, TR_ESP_DEMON);   break;
137         case 4: add_flag(o_ptr->art_flags, TR_ESP_ORC);   break;
138         case 5: add_flag(o_ptr->art_flags, TR_ESP_TROLL);   break;
139         case 6: add_flag(o_ptr->art_flags, TR_ESP_GIANT);   break;
140         case 7: add_flag(o_ptr->art_flags, TR_ESP_DRAGON);   break;
141         case 8: add_flag(o_ptr->art_flags, TR_ESP_HUMAN);   break;
142         case 9: add_flag(o_ptr->art_flags, TR_ESP_GOOD);   break;
143         }
144 }
145
146
147
148 /*
149  * Choose one random resistance
150  */
151 void one_resistance(object_type *o_ptr)
152 {
153         if (one_in_(3))
154         {
155                 one_ele_resistance(o_ptr);
156         }
157         else
158         {
159                 one_high_resistance(o_ptr);
160         }
161 }
162
163
164 /*
165  * Choose one random ability
166  */
167 void one_ability(object_type *o_ptr)
168 {
169         switch (randint0(10))
170         {
171         case 0: add_flag(o_ptr->art_flags, TR_LEVITATION);     break;
172         case 1: add_flag(o_ptr->art_flags, TR_LITE);        break;
173         case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS);   break;
174         case 3: add_flag(o_ptr->art_flags, TR_WARNING);     break;
175         case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
176         case 5: add_flag(o_ptr->art_flags, TR_REGEN);       break;
177         case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT);    break;
178         case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE);   break;
179         case 8:
180         case 9:
181                 one_low_esp(o_ptr);
182                 break;
183         }
184 }
185
186
187 static void curse_artifact(object_type * o_ptr)
188 {
189         if (o_ptr->pval > 0) o_ptr->pval = 0 - (o_ptr->pval + randint1(4));
190         if (o_ptr->to_a > 0) o_ptr->to_a = 0 - (o_ptr->to_a + randint1(4));
191         if (o_ptr->to_h > 0) o_ptr->to_h = 0 - (o_ptr->to_h + randint1(4));
192         if (o_ptr->to_d > 0) o_ptr->to_d = 0 - (o_ptr->to_d + randint1(4));
193
194         o_ptr->curse_flags |= (TRC_HEAVY_CURSE | TRC_CURSED);
195         remove_flag(o_ptr->art_flags, TR_BLESSED);
196
197         if (one_in_(4)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
198         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
199         if (one_in_(2)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
200         if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
201         if (one_in_(2)) add_flag(o_ptr->art_flags, TR_TELEPORT);
202         else if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
203
204         if ((p_ptr->pclass != CLASS_WARRIOR) && (p_ptr->pclass != CLASS_ARCHER) && (p_ptr->pclass != CLASS_CAVALRY) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH) && one_in_(3))
205                 add_flag(o_ptr->art_flags, TR_NO_MAGIC);
206 }
207
208
209 static void random_plus(object_type * o_ptr)
210 {
211         int this_type = (object_is_weapon_ammo(o_ptr) ? 23 : 19);
212
213         switch (artifact_bias)
214         {
215         case BIAS_WARRIOR:
216                 if (!(have_flag(o_ptr->art_flags, TR_STR)))
217                 {
218                         add_flag(o_ptr->art_flags, TR_STR);
219                         if (one_in_(2)) return;
220                 }
221
222                 if (!(have_flag(o_ptr->art_flags, TR_CON)))
223                 {
224                         add_flag(o_ptr->art_flags, TR_CON);
225                         if (one_in_(2)) return;
226                 }
227
228                 if (!(have_flag(o_ptr->art_flags, TR_DEX)))
229                 {
230                         add_flag(o_ptr->art_flags, TR_DEX);
231                         if (one_in_(2)) return;
232                 }
233                 break;
234
235         case BIAS_MAGE:
236                 if (!(have_flag(o_ptr->art_flags, TR_INT)))
237                 {
238                         add_flag(o_ptr->art_flags, TR_INT);
239                         if (one_in_(2)) return;
240                 }
241                 if ((o_ptr->tval == TV_GLOVES) && !(have_flag(o_ptr->art_flags, TR_MAGIC_MASTERY)))
242                 {
243                         add_flag(o_ptr->art_flags, TR_MAGIC_MASTERY);
244                         if (one_in_(2)) return;
245                 }
246                 break;
247
248         case BIAS_PRIESTLY:
249                 if (!(have_flag(o_ptr->art_flags, TR_WIS)))
250                 {
251                         add_flag(o_ptr->art_flags, TR_WIS);
252                         if (one_in_(2)) return;
253                 }
254                 break;
255
256         case BIAS_RANGER:
257                 if (!(have_flag(o_ptr->art_flags, TR_DEX)))
258                 {
259                         add_flag(o_ptr->art_flags, TR_DEX);
260                         if (one_in_(2)) return;
261                 }
262
263                 if (!(have_flag(o_ptr->art_flags, TR_CON)))
264                 {
265                         add_flag(o_ptr->art_flags, TR_CON);
266                         if (one_in_(2)) return;
267                 }
268
269                 if (!(have_flag(o_ptr->art_flags, TR_STR)))
270                 {
271                         add_flag(o_ptr->art_flags, TR_STR);
272                         if (one_in_(2)) return;
273                 }
274                 break;
275
276         case BIAS_ROGUE:
277                 if (!(have_flag(o_ptr->art_flags, TR_STEALTH)))
278                 {
279                         add_flag(o_ptr->art_flags, TR_STEALTH);
280                         if (one_in_(2)) return;
281                 }
282                 if (!(have_flag(o_ptr->art_flags, TR_SEARCH)))
283                 {
284                         add_flag(o_ptr->art_flags, TR_SEARCH);
285                         if (one_in_(2)) return;
286                 }
287                 break;
288
289         case BIAS_STR:
290                 if (!(have_flag(o_ptr->art_flags, TR_STR)))
291                 {
292                         add_flag(o_ptr->art_flags, TR_STR);
293                         if (one_in_(2)) return;
294                 }
295                 break;
296
297         case BIAS_WIS:
298                 if (!(have_flag(o_ptr->art_flags, TR_WIS)))
299                 {
300                         add_flag(o_ptr->art_flags, TR_WIS);
301                         if (one_in_(2)) return;
302                 }
303                 break;
304
305         case BIAS_INT:
306                 if (!(have_flag(o_ptr->art_flags, TR_INT)))
307                 {
308                         add_flag(o_ptr->art_flags, TR_INT);
309                         if (one_in_(2)) return;
310                 }
311                 break;
312
313         case BIAS_DEX:
314                 if (!(have_flag(o_ptr->art_flags, TR_DEX)))
315                 {
316                         add_flag(o_ptr->art_flags, TR_DEX);
317                         if (one_in_(2)) return;
318                 }
319                 break;
320
321         case BIAS_CON:
322                 if (!(have_flag(o_ptr->art_flags, TR_CON)))
323                 {
324                         add_flag(o_ptr->art_flags, TR_CON);
325                         if (one_in_(2)) return;
326                 }
327                 break;
328
329         case BIAS_CHR:
330                 if (!(have_flag(o_ptr->art_flags, TR_CHR)))
331                 {
332                         add_flag(o_ptr->art_flags, TR_CHR);
333                         if (one_in_(2)) return;
334                 }
335                 break;
336         }
337
338         if ((artifact_bias == BIAS_MAGE || artifact_bias == BIAS_PRIESTLY) && (o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_ROBE))
339         {
340                 if (!(have_flag(o_ptr->art_flags, TR_DEC_MANA)) && one_in_(3))
341                 {
342                         add_flag(o_ptr->art_flags, TR_DEC_MANA);
343                         if (one_in_(2)) return;
344                 }
345         }
346
347         switch (randint1(this_type))
348         {
349         case 1: case 2:
350                 add_flag(o_ptr->art_flags, TR_STR);
351                 if (!artifact_bias && !one_in_(13))
352                         artifact_bias = BIAS_STR;
353                 else if (!artifact_bias && one_in_(7))
354                         artifact_bias = BIAS_WARRIOR;
355                 break;
356         case 3: case 4:
357                 add_flag(o_ptr->art_flags, TR_INT);
358                 if (!artifact_bias && !one_in_(13))
359                         artifact_bias = BIAS_INT;
360                 else if (!artifact_bias && one_in_(7))
361                         artifact_bias = BIAS_MAGE;
362                 break;
363         case 5: case 6:
364                 add_flag(o_ptr->art_flags, TR_WIS);
365                 if (!artifact_bias && !one_in_(13))
366                         artifact_bias = BIAS_WIS;
367                 else if (!artifact_bias && one_in_(7))
368                         artifact_bias = BIAS_PRIESTLY;
369                 break;
370         case 7: case 8:
371                 add_flag(o_ptr->art_flags, TR_DEX);
372                 if (!artifact_bias && !one_in_(13))
373                         artifact_bias = BIAS_DEX;
374                 else if (!artifact_bias && one_in_(7))
375                         artifact_bias = BIAS_ROGUE;
376                 break;
377         case 9: case 10:
378                 add_flag(o_ptr->art_flags, TR_CON);
379                 if (!artifact_bias && !one_in_(13))
380                         artifact_bias = BIAS_CON;
381                 else if (!artifact_bias && one_in_(9))
382                         artifact_bias = BIAS_RANGER;
383                 break;
384         case 11: case 12:
385                 add_flag(o_ptr->art_flags, TR_CHR);
386                 if (!artifact_bias && !one_in_(13))
387                         artifact_bias = BIAS_CHR;
388                 break;
389         case 13: case 14:
390                 add_flag(o_ptr->art_flags, TR_STEALTH);
391                 if (!artifact_bias && one_in_(3))
392                         artifact_bias = BIAS_ROGUE;
393                 break;
394         case 15: case 16:
395                 add_flag(o_ptr->art_flags, TR_SEARCH);
396                 if (!artifact_bias && one_in_(9))
397                         artifact_bias = BIAS_RANGER;
398                 break;
399         case 17: case 18:
400                 add_flag(o_ptr->art_flags, TR_INFRA);
401                 break;
402         case 19:
403                 add_flag(o_ptr->art_flags, TR_SPEED);
404                 if (!artifact_bias && one_in_(11))
405                         artifact_bias = BIAS_ROGUE;
406                 break;
407         case 20: case 21:
408                 add_flag(o_ptr->art_flags, TR_TUNNEL);
409                 break;
410         case 22: case 23:
411                 if (o_ptr->tval == TV_BOW) random_plus(o_ptr);
412                 else
413                 {
414                         add_flag(o_ptr->art_flags, TR_BLOWS);
415                         if (!artifact_bias && one_in_(11))
416                                 artifact_bias = BIAS_WARRIOR;
417                 }
418                 break;
419         }
420 }
421
422
423 static void random_resistance(object_type * o_ptr)
424 {
425         switch (artifact_bias)
426         {
427         case BIAS_ACID:
428                 if (!(have_flag(o_ptr->art_flags, TR_RES_ACID)))
429                 {
430                         add_flag(o_ptr->art_flags, TR_RES_ACID);
431                         if (one_in_(2)) return;
432                 }
433                 if (one_in_(BIAS_LUCK) && !(have_flag(o_ptr->art_flags, TR_IM_ACID)))
434                 {
435                         add_flag(o_ptr->art_flags, TR_IM_ACID);
436                         if (!one_in_(IM_LUCK))
437                         {
438                                 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
439                                 remove_flag(o_ptr->art_flags, TR_IM_COLD);
440                                 remove_flag(o_ptr->art_flags, TR_IM_FIRE);
441                         }
442                         if (one_in_(2)) return;
443                 }
444                 break;
445
446         case BIAS_ELEC:
447                 if (!(have_flag(o_ptr->art_flags, TR_RES_ELEC)))
448                 {
449                         add_flag(o_ptr->art_flags, TR_RES_ELEC);
450                         if (one_in_(2)) return;
451                 }
452                 if ((o_ptr->tval >= TV_CLOAK) && (o_ptr->tval <= TV_HARD_ARMOR) &&
453                     !(have_flag(o_ptr->art_flags, TR_SH_ELEC)))
454                 {
455                         add_flag(o_ptr->art_flags, TR_SH_ELEC);
456                         if (one_in_(2)) return;
457                 }
458                 if (one_in_(BIAS_LUCK) && !(have_flag(o_ptr->art_flags, TR_IM_ELEC)))
459                 {
460                         add_flag(o_ptr->art_flags, TR_IM_ELEC);
461                         if (!one_in_(IM_LUCK))
462                         {
463                                 remove_flag(o_ptr->art_flags, TR_IM_ACID);
464                                 remove_flag(o_ptr->art_flags, TR_IM_COLD);
465                                 remove_flag(o_ptr->art_flags, TR_IM_FIRE);
466                         }
467
468                         if (one_in_(2)) return;
469                 }
470                 break;
471
472         case BIAS_FIRE:
473                 if (!(have_flag(o_ptr->art_flags, TR_RES_FIRE)))
474                 {
475                         add_flag(o_ptr->art_flags, TR_RES_FIRE);
476                         if (one_in_(2)) return;
477                 }
478                 if ((o_ptr->tval >= TV_CLOAK) &&
479                     (o_ptr->tval <= TV_HARD_ARMOR) &&
480                     !(have_flag(o_ptr->art_flags, TR_SH_FIRE)))
481                 {
482                         add_flag(o_ptr->art_flags, TR_SH_FIRE);
483                         if (one_in_(2)) return;
484                 }
485                 if (one_in_(BIAS_LUCK) &&
486                     !(have_flag(o_ptr->art_flags, TR_IM_FIRE)))
487                 {
488                         add_flag(o_ptr->art_flags, TR_IM_FIRE);
489                         if (!one_in_(IM_LUCK))
490                         {
491                                 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
492                                 remove_flag(o_ptr->art_flags, TR_IM_COLD);
493                                 remove_flag(o_ptr->art_flags, TR_IM_ACID);
494                         }
495                         if (one_in_(2)) return;
496                 }
497                 break;
498
499         case BIAS_COLD:
500                 if (!(have_flag(o_ptr->art_flags, TR_RES_COLD)))
501                 {
502                         add_flag(o_ptr->art_flags, TR_RES_COLD);
503                         if (one_in_(2)) return;
504                 }
505                 if ((o_ptr->tval >= TV_CLOAK) &&
506                     (o_ptr->tval <= TV_HARD_ARMOR) &&
507                     !(have_flag(o_ptr->art_flags, TR_SH_COLD)))
508                 {
509                         add_flag(o_ptr->art_flags, TR_SH_COLD);
510                         if (one_in_(2)) return;
511                 }
512                 if (one_in_(BIAS_LUCK) && !(have_flag(o_ptr->art_flags, TR_IM_COLD)))
513                 {
514                         add_flag(o_ptr->art_flags, TR_IM_COLD);
515                         if (!one_in_(IM_LUCK))
516                         {
517                                 remove_flag(o_ptr->art_flags, TR_IM_ELEC);
518                                 remove_flag(o_ptr->art_flags, TR_IM_ACID);
519                                 remove_flag(o_ptr->art_flags, TR_IM_FIRE);
520                         }
521                         if (one_in_(2)) return;
522                 }
523                 break;
524
525         case BIAS_POIS:
526                 if (!(have_flag(o_ptr->art_flags, TR_RES_POIS)))
527                 {
528                         add_flag(o_ptr->art_flags, TR_RES_POIS);
529                         if (one_in_(2)) return;
530                 }
531                 break;
532
533         case BIAS_WARRIOR:
534                 if (!one_in_(3) && (!(have_flag(o_ptr->art_flags, TR_RES_FEAR))))
535                 {
536                         add_flag(o_ptr->art_flags, TR_RES_FEAR);
537                         if (one_in_(2)) return;
538                 }
539                 if (one_in_(3) && (!(have_flag(o_ptr->art_flags, TR_NO_MAGIC))))
540                 {
541                         add_flag(o_ptr->art_flags, TR_NO_MAGIC);
542                         if (one_in_(2)) return;
543                 }
544                 break;
545
546         case BIAS_NECROMANTIC:
547                 if (!(have_flag(o_ptr->art_flags, TR_RES_NETHER)))
548                 {
549                         add_flag(o_ptr->art_flags, TR_RES_NETHER);
550                         if (one_in_(2)) return;
551                 }
552                 if (!(have_flag(o_ptr->art_flags, TR_RES_POIS)))
553                 {
554                         add_flag(o_ptr->art_flags, TR_RES_POIS);
555                         if (one_in_(2)) return;
556                 }
557                 if (!(have_flag(o_ptr->art_flags, TR_RES_DARK)))
558                 {
559                         add_flag(o_ptr->art_flags, TR_RES_DARK);
560                         if (one_in_(2)) return;
561                 }
562                 break;
563
564         case BIAS_CHAOS:
565                 if (!(have_flag(o_ptr->art_flags, TR_RES_CHAOS)))
566                 {
567                         add_flag(o_ptr->art_flags, TR_RES_CHAOS);
568                         if (one_in_(2)) return;
569                 }
570                 if (!(have_flag(o_ptr->art_flags, TR_RES_CONF)))
571                 {
572                         add_flag(o_ptr->art_flags, TR_RES_CONF);
573                         if (one_in_(2)) return;
574                 }
575                 if (!(have_flag(o_ptr->art_flags, TR_RES_DISEN)))
576                 {
577                         add_flag(o_ptr->art_flags, TR_RES_DISEN);
578                         if (one_in_(2)) return;
579                 }
580                 break;
581         }
582
583         switch (randint1(42))
584         {
585                 case 1:
586                         if (!one_in_(WEIRD_LUCK))
587                                 random_resistance(o_ptr);
588                         else
589                         {
590                                 add_flag(o_ptr->art_flags, TR_IM_ACID);
591                                 if (!artifact_bias)
592                                         artifact_bias = BIAS_ACID;
593                         }
594                         break;
595                 case 2:
596                         if (!one_in_(WEIRD_LUCK))
597                                 random_resistance(o_ptr);
598                         else
599                         {
600                                 add_flag(o_ptr->art_flags, TR_IM_ELEC);
601                                 if (!artifact_bias)
602                                         artifact_bias = BIAS_ELEC;
603                         }
604                         break;
605                 case 3:
606                         if (!one_in_(WEIRD_LUCK))
607                                 random_resistance(o_ptr);
608                         else
609                         {
610                                 add_flag(o_ptr->art_flags, TR_IM_COLD);
611                                 if (!artifact_bias)
612                                         artifact_bias = BIAS_COLD;
613                         }
614                         break;
615                 case 4:
616                         if (!one_in_(WEIRD_LUCK))
617                                 random_resistance(o_ptr);
618                         else
619                         {
620                                 add_flag(o_ptr->art_flags, TR_IM_FIRE);
621                                 if (!artifact_bias)
622                                         artifact_bias = BIAS_FIRE;
623                         }
624                         break;
625                 case 5:
626                 case 6:
627                 case 13:
628                         add_flag(o_ptr->art_flags, TR_RES_ACID);
629                         if (!artifact_bias)
630                                 artifact_bias = BIAS_ACID;
631                         break;
632                 case 7:
633                 case 8:
634                 case 14:
635                         add_flag(o_ptr->art_flags, TR_RES_ELEC);
636                         if (!artifact_bias)
637                                 artifact_bias = BIAS_ELEC;
638                         break;
639                 case 9:
640                 case 10:
641                 case 15:
642                         add_flag(o_ptr->art_flags, TR_RES_FIRE);
643                         if (!artifact_bias)
644                                 artifact_bias = BIAS_FIRE;
645                         break;
646                 case 11:
647                 case 12:
648                 case 16:
649                         add_flag(o_ptr->art_flags, TR_RES_COLD);
650                         if (!artifact_bias)
651                                 artifact_bias = BIAS_COLD;
652                         break;
653                 case 17:
654                 case 18:
655                         add_flag(o_ptr->art_flags, TR_RES_POIS);
656                         if (!artifact_bias && !one_in_(4))
657                                 artifact_bias = BIAS_POIS;
658                         else if (!artifact_bias && one_in_(2))
659                                 artifact_bias = BIAS_NECROMANTIC;
660                         else if (!artifact_bias && one_in_(2))
661                                 artifact_bias = BIAS_ROGUE;
662                         break;
663                 case 19:
664                 case 20:
665                         add_flag(o_ptr->art_flags, TR_RES_FEAR);
666                         if (!artifact_bias && one_in_(3))
667                                 artifact_bias = BIAS_WARRIOR;
668                         break;
669                 case 21:
670                         add_flag(o_ptr->art_flags, TR_RES_LITE);
671                         break;
672                 case 22:
673                         add_flag(o_ptr->art_flags, TR_RES_DARK);
674                         break;
675                 case 23:
676                 case 24:
677                         add_flag(o_ptr->art_flags, TR_RES_BLIND);
678                         break;
679                 case 25:
680                 case 26:
681                         add_flag(o_ptr->art_flags, TR_RES_CONF);
682                         if (!artifact_bias && one_in_(6))
683                                 artifact_bias = BIAS_CHAOS;
684                         break;
685                 case 27:
686                 case 28:
687                         add_flag(o_ptr->art_flags, TR_RES_SOUND);
688                         break;
689                 case 29:
690                 case 30:
691                         add_flag(o_ptr->art_flags, TR_RES_SHARDS);
692                         break;
693                 case 31:
694                 case 32:
695                         add_flag(o_ptr->art_flags, TR_RES_NETHER);
696                         if (!artifact_bias && one_in_(3))
697                                 artifact_bias = BIAS_NECROMANTIC;
698                         break;
699                 case 33:
700                 case 34:
701                         add_flag(o_ptr->art_flags, TR_RES_NEXUS);
702                         break;
703                 case 35:
704                 case 36:
705                         add_flag(o_ptr->art_flags, TR_RES_CHAOS);
706                         if (!artifact_bias && one_in_(2))
707                                 artifact_bias = BIAS_CHAOS;
708                         break;
709                 case 37:
710                 case 38:
711                         add_flag(o_ptr->art_flags, TR_RES_DISEN);
712                         break;
713                 case 39:
714                         if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
715                                 add_flag(o_ptr->art_flags, TR_SH_ELEC);
716                         else
717                                 random_resistance(o_ptr);
718                         if (!artifact_bias)
719                                 artifact_bias = BIAS_ELEC;
720                         break;
721                 case 40:
722                         if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
723                                 add_flag(o_ptr->art_flags, TR_SH_FIRE);
724                         else
725                                 random_resistance(o_ptr);
726                         if (!artifact_bias)
727                                 artifact_bias = BIAS_FIRE;
728                         break;
729                 case 41:
730                         if (o_ptr->tval == TV_SHIELD || o_ptr->tval == TV_CLOAK ||
731                             o_ptr->tval == TV_HELM || o_ptr->tval == TV_HARD_ARMOR)
732                                 add_flag(o_ptr->art_flags, TR_REFLECT);
733                         else
734                                 random_resistance(o_ptr);
735                         break;
736                 case 42:
737                         if (o_ptr->tval >= TV_CLOAK && o_ptr->tval <= TV_HARD_ARMOR)
738                                 add_flag(o_ptr->art_flags, TR_SH_COLD);
739                         else
740                                 random_resistance(o_ptr);
741                         if (!artifact_bias)
742                                 artifact_bias = BIAS_COLD;
743                         break;
744         }
745 }
746
747
748
749 static void random_misc(object_type * o_ptr)
750 {
751         switch (artifact_bias)
752         {
753         case BIAS_RANGER:
754                 if (!(have_flag(o_ptr->art_flags, TR_SUST_CON)))
755                 {
756                         add_flag(o_ptr->art_flags, TR_SUST_CON);
757                         if (one_in_(2)) return;
758                 }
759                 break;
760
761         case BIAS_STR:
762                 if (!(have_flag(o_ptr->art_flags, TR_SUST_STR)))
763                 {
764                         add_flag(o_ptr->art_flags, TR_SUST_STR);
765                         if (one_in_(2)) return;
766                 }
767                 break;
768
769         case BIAS_WIS:
770                 if (!(have_flag(o_ptr->art_flags, TR_SUST_WIS)))
771                 {
772                         add_flag(o_ptr->art_flags, TR_SUST_WIS);
773                         if (one_in_(2)) return;
774                 }
775                 break;
776
777         case BIAS_INT:
778                 if (!(have_flag(o_ptr->art_flags, TR_SUST_INT)))
779                 {
780                         add_flag(o_ptr->art_flags, TR_SUST_INT);
781                         if (one_in_(2)) return;
782                 }
783                 break;
784
785         case BIAS_DEX:
786                 if (!(have_flag(o_ptr->art_flags, TR_SUST_DEX)))
787                 {
788                         add_flag(o_ptr->art_flags, TR_SUST_DEX);
789                         if (one_in_(2)) return;
790                 }
791                 break;
792
793         case BIAS_CON:
794                 if (!(have_flag(o_ptr->art_flags, TR_SUST_CON)))
795                 {
796                         add_flag(o_ptr->art_flags, TR_SUST_CON);
797                         if (one_in_(2)) return;
798                 }
799                 break;
800
801         case BIAS_CHR:
802                 if (!(have_flag(o_ptr->art_flags, TR_SUST_CHR)))
803                 {
804                         add_flag(o_ptr->art_flags, TR_SUST_CHR);
805                         if (one_in_(2)) return;
806                 }
807                 break;
808
809         case BIAS_CHAOS:
810                 if (!(have_flag(o_ptr->art_flags, TR_TELEPORT)))
811                 {
812                         add_flag(o_ptr->art_flags, TR_TELEPORT);
813                         if (one_in_(2)) return;
814                 }
815                 break;
816
817         case BIAS_FIRE:
818                 if (!(have_flag(o_ptr->art_flags, TR_LITE)))
819                 {
820                         add_flag(o_ptr->art_flags, TR_LITE); /* Freebie */
821                 }
822                 break;
823         }
824
825         switch (randint1(33))
826         {
827                 case 1:
828                         add_flag(o_ptr->art_flags, TR_SUST_STR);
829                         if (!artifact_bias)
830                                 artifact_bias = BIAS_STR;
831                         break;
832                 case 2:
833                         add_flag(o_ptr->art_flags, TR_SUST_INT);
834                         if (!artifact_bias)
835                                 artifact_bias = BIAS_INT;
836                         break;
837                 case 3:
838                         add_flag(o_ptr->art_flags, TR_SUST_WIS);
839                         if (!artifact_bias)
840                                 artifact_bias = BIAS_WIS;
841                         break;
842                 case 4:
843                         add_flag(o_ptr->art_flags, TR_SUST_DEX);
844                         if (!artifact_bias)
845                                 artifact_bias = BIAS_DEX;
846                         break;
847                 case 5:
848                         add_flag(o_ptr->art_flags, TR_SUST_CON);
849                         if (!artifact_bias)
850                                 artifact_bias = BIAS_CON;
851                         break;
852                 case 6:
853                         add_flag(o_ptr->art_flags, TR_SUST_CHR);
854                         if (!artifact_bias)
855                                 artifact_bias = BIAS_CHR;
856                         break;
857                 case 7:
858                 case 8:
859                 case 14:
860                         add_flag(o_ptr->art_flags, TR_FREE_ACT);
861                         break;
862                 case 9:
863                         add_flag(o_ptr->art_flags, TR_HOLD_LIFE);
864                         if (!artifact_bias && one_in_(5))
865                                 artifact_bias = BIAS_PRIESTLY;
866                         else if (!artifact_bias && one_in_(6))
867                                 artifact_bias = BIAS_NECROMANTIC;
868                         break;
869                 case 10:
870                 case 11:
871                         add_flag(o_ptr->art_flags, TR_LITE);
872                         break;
873                 case 12:
874                 case 13:
875                         add_flag(o_ptr->art_flags, TR_LEVITATION);
876                         break;
877                 case 15:
878                 case 16:
879                 case 17:
880                         add_flag(o_ptr->art_flags, TR_SEE_INVIS);
881                         break;
882                 case 19:
883                 case 20:
884                         add_flag(o_ptr->art_flags, TR_SLOW_DIGEST);
885                         break;
886                 case 21:
887                 case 22:
888                         add_flag(o_ptr->art_flags, TR_REGEN);
889                         break;
890                 case 23:
891                         add_flag(o_ptr->art_flags, TR_TELEPORT);
892                         break;
893                 case 24:
894                 case 25:
895                 case 26:
896                         if (object_is_armour(o_ptr))
897                                 random_misc(o_ptr);
898                         else
899                         {
900                                 o_ptr->to_a = 4 + randint1(11);
901                         }
902                         break;
903                 case 27:
904                 case 28:
905                 case 29:
906                 {
907                         int bonus_h, bonus_d;
908                         add_flag(o_ptr->art_flags, TR_SHOW_MODS);
909                         bonus_h = 4 + (randint1(11));
910                         bonus_d = 4 + (randint1(11));
911                         if ((o_ptr->tval != TV_SWORD) && (o_ptr->tval != TV_POLEARM) && (o_ptr->tval != TV_HAFTED) && (o_ptr->tval != TV_DIGGING) && (o_ptr->tval != TV_GLOVES) && (o_ptr->tval != TV_RING))
912                         {
913                                 bonus_h /= 2;
914                                 bonus_d /= 2;
915                         }
916                         o_ptr->to_h += bonus_h;
917                         o_ptr->to_d += bonus_d;
918                         break;
919                 }
920                 case 30:
921                         add_flag(o_ptr->art_flags, TR_NO_MAGIC);
922                         break;
923                 case 31:
924                         add_flag(o_ptr->art_flags, TR_NO_TELE);
925                         break;
926                 case 32:
927                         add_flag(o_ptr->art_flags, TR_WARNING);
928                         break;
929
930                 case 18:
931                         switch (randint1(3))
932                         {
933                         case 1:
934                                 add_flag(o_ptr->art_flags, TR_ESP_EVIL);
935                                 if (!artifact_bias && one_in_(3))
936                                         artifact_bias = BIAS_LAW;
937                                 break;
938                         case 2:
939                                 add_flag(o_ptr->art_flags, TR_ESP_NONLIVING);
940                                 if (!artifact_bias && one_in_(3))
941                                         artifact_bias = BIAS_MAGE;
942                                 break;
943                         case 3:
944                                 add_flag(o_ptr->art_flags, TR_TELEPATHY);
945                                 if (!artifact_bias && one_in_(9))
946                                         artifact_bias = BIAS_MAGE;
947                                 break;
948                         }
949                         break;
950
951                 case 33:
952                 {
953                         int idx[3];
954                         int n = randint1(3);
955
956                         idx[0] = randint1(8);
957
958                         idx[1] = randint1(7);
959                         if (idx[1] >= idx[0]) idx[1]++;
960
961                         idx[2] = randint1(6);
962                         if (idx[2] >= idx[0]) idx[2]++;
963                         if (idx[2] >= idx[1]) idx[2]++;
964
965                         while (n--) switch (idx[n])
966                         {
967                         case 1:
968                                 add_flag(o_ptr->art_flags, TR_ESP_ANIMAL);
969                                 if (!artifact_bias && one_in_(4))
970                                         artifact_bias = BIAS_RANGER;
971                                 break;
972                         case 2:
973                                 add_flag(o_ptr->art_flags, TR_ESP_UNDEAD);
974                                 if (!artifact_bias && one_in_(3))
975                                         artifact_bias = BIAS_PRIESTLY;
976                                 else if (!artifact_bias && one_in_(6))
977                                         artifact_bias = BIAS_NECROMANTIC;
978                                 break;
979                         case 3:
980                                 add_flag(o_ptr->art_flags, TR_ESP_DEMON);
981                                 break;
982                         case 4:
983                                 add_flag(o_ptr->art_flags, TR_ESP_ORC);
984                                 break;
985                         case 5:
986                                 add_flag(o_ptr->art_flags, TR_ESP_TROLL);
987                                 break;
988                         case 6:
989                                 add_flag(o_ptr->art_flags, TR_ESP_GIANT);
990                                 break;
991                         case 7:
992                                 add_flag(o_ptr->art_flags, TR_ESP_HUMAN);
993                                 if (!artifact_bias && one_in_(6))
994                                         artifact_bias = BIAS_ROGUE;
995                                 break;
996                         case 8:
997                                 add_flag(o_ptr->art_flags, TR_ESP_GOOD);
998                                 if (!artifact_bias && one_in_(3))
999                                         artifact_bias = BIAS_LAW;
1000                                 break;
1001                         }
1002                         break;
1003                 }
1004         }
1005 }
1006
1007
1008 static void random_slay(object_type *o_ptr)
1009 {
1010         if (o_ptr->tval == TV_BOW)
1011         {
1012                 switch (randint1(6))
1013                 {
1014                         case 1:
1015                         case 2:
1016                         case 3:
1017                                 add_flag(o_ptr->art_flags, TR_XTRA_MIGHT);
1018                                 if (!one_in_(7)) remove_flag(o_ptr->art_flags, TR_XTRA_SHOTS);
1019                                 if (!artifact_bias && one_in_(9))
1020                                         artifact_bias = BIAS_RANGER;
1021                                 break;
1022                         default:
1023                                 add_flag(o_ptr->art_flags, TR_XTRA_SHOTS);
1024                                 if (!one_in_(7)) remove_flag(o_ptr->art_flags, TR_XTRA_MIGHT);
1025                                 if (!artifact_bias && one_in_(9))
1026                                         artifact_bias = BIAS_RANGER;
1027                         break;
1028                 }
1029
1030                 return;
1031         }
1032
1033         switch (artifact_bias)
1034         {
1035         case BIAS_CHAOS:
1036                 if (!(have_flag(o_ptr->art_flags, TR_CHAOTIC)))
1037                 {
1038                         add_flag(o_ptr->art_flags, TR_CHAOTIC);
1039                         if (one_in_(2)) return;
1040                 }
1041                 break;
1042
1043         case BIAS_PRIESTLY:
1044                 if((o_ptr->tval == TV_SWORD || o_ptr->tval == TV_POLEARM) &&
1045                    !(have_flag(o_ptr->art_flags, TR_BLESSED)))
1046                 {
1047                         /* A free power for "priestly" random artifacts */
1048                         add_flag(o_ptr->art_flags, TR_BLESSED);
1049                 }
1050                 break;
1051
1052         case BIAS_NECROMANTIC:
1053                 if (!(have_flag(o_ptr->art_flags, TR_VAMPIRIC)))
1054                 {
1055                         add_flag(o_ptr->art_flags, TR_VAMPIRIC);
1056                         if (one_in_(2)) return;
1057                 }
1058                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_POIS)) && one_in_(2))
1059                 {
1060                         add_flag(o_ptr->art_flags, TR_BRAND_POIS);
1061                         if (one_in_(2)) return;
1062                 }
1063                 break;
1064
1065         case BIAS_RANGER:
1066                 if (!(have_flag(o_ptr->art_flags, TR_SLAY_ANIMAL)))
1067                 {
1068                         add_flag(o_ptr->art_flags, TR_SLAY_ANIMAL);
1069                         if (one_in_(2)) return;
1070                 }
1071                 break;
1072
1073         case BIAS_ROGUE:
1074                 if ((((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DAGGER)) ||
1075                      ((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_SPEAR))) &&
1076                          !(have_flag(o_ptr->art_flags, TR_THROW)))
1077                 {
1078                         /* Free power for rogues... */
1079                         add_flag(o_ptr->art_flags, TR_THROW);
1080                 }
1081                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_POIS)))
1082                 {
1083                         add_flag(o_ptr->art_flags, TR_BRAND_POIS);
1084                         if (one_in_(2)) return;
1085                 }
1086                 break;
1087
1088         case BIAS_POIS:
1089                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_POIS)))
1090                 {
1091                         add_flag(o_ptr->art_flags, TR_BRAND_POIS);
1092                         if (one_in_(2)) return;
1093                 }
1094                 break;
1095
1096         case BIAS_FIRE:
1097                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_FIRE)))
1098                 {
1099                         add_flag(o_ptr->art_flags, TR_BRAND_FIRE);
1100                         if (one_in_(2)) return;
1101                 }
1102                 break;
1103
1104         case BIAS_COLD:
1105                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_COLD)))
1106                 {
1107                         add_flag(o_ptr->art_flags, TR_BRAND_COLD);
1108                         if (one_in_(2)) return;
1109                 }
1110                 break;
1111
1112         case BIAS_ELEC:
1113                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_ELEC)))
1114                 {
1115                         add_flag(o_ptr->art_flags, TR_BRAND_ELEC);
1116                         if (one_in_(2)) return;
1117                 }
1118                 break;
1119
1120         case BIAS_ACID:
1121                 if (!(have_flag(o_ptr->art_flags, TR_BRAND_ACID)))
1122                 {
1123                         add_flag(o_ptr->art_flags, TR_BRAND_ACID);
1124                         if (one_in_(2)) return;
1125                 }
1126                 break;
1127
1128         case BIAS_LAW:
1129                 if (!(have_flag(o_ptr->art_flags, TR_SLAY_EVIL)))
1130                 {
1131                         add_flag(o_ptr->art_flags, TR_SLAY_EVIL);
1132                         if (one_in_(2)) return;
1133                 }
1134                 if (!(have_flag(o_ptr->art_flags, TR_SLAY_UNDEAD)))
1135                 {
1136                         add_flag(o_ptr->art_flags, TR_SLAY_UNDEAD);
1137                         if (one_in_(2)) return;
1138                 }
1139                 if (!(have_flag(o_ptr->art_flags, TR_SLAY_DEMON)))
1140                 {
1141                         add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
1142                         if (one_in_(2)) return;
1143                 }
1144                 break;
1145         }
1146
1147         switch (randint1(36))
1148         {
1149                 case 1:
1150                 case 2:
1151                         add_flag(o_ptr->art_flags, TR_SLAY_ANIMAL);
1152                         break;
1153                 case 3:
1154                 case 4:
1155                         add_flag(o_ptr->art_flags, TR_SLAY_EVIL);
1156                         if (!artifact_bias && one_in_(2))
1157                                 artifact_bias = BIAS_LAW;
1158                         else if (!artifact_bias && one_in_(9))
1159                                 artifact_bias = BIAS_PRIESTLY;
1160                         break;
1161                 case 5:
1162                 case 6:
1163                         add_flag(o_ptr->art_flags, TR_SLAY_UNDEAD);
1164                         if (!artifact_bias && one_in_(9))
1165                                 artifact_bias = BIAS_PRIESTLY;
1166                         break;
1167                 case 7:
1168                 case 8:
1169                         add_flag(o_ptr->art_flags, TR_SLAY_DEMON);
1170                         if (!artifact_bias && one_in_(9))
1171                                 artifact_bias = BIAS_PRIESTLY;
1172                         break;
1173                 case 9:
1174                 case 10:
1175                         add_flag(o_ptr->art_flags, TR_SLAY_ORC);
1176                         break;
1177                 case 11:
1178                 case 12:
1179                         add_flag(o_ptr->art_flags, TR_SLAY_TROLL);
1180                         break;
1181                 case 13:
1182                 case 14:
1183                         add_flag(o_ptr->art_flags, TR_SLAY_GIANT);
1184                         break;
1185                 case 15:
1186                 case 16:
1187                         add_flag(o_ptr->art_flags, TR_SLAY_DRAGON);
1188                         break;
1189                 case 17:
1190                         add_flag(o_ptr->art_flags, TR_KILL_DRAGON);
1191                         break;
1192                 case 18:
1193                 case 19:
1194                         if (o_ptr->tval == TV_SWORD)
1195                         {
1196                                 add_flag(o_ptr->art_flags, TR_VORPAL);
1197                                 if (!artifact_bias && one_in_(9))
1198                                         artifact_bias = BIAS_WARRIOR;
1199                         }
1200                         else
1201                                 random_slay(o_ptr);
1202                         break;
1203                 case 20:
1204                         add_flag(o_ptr->art_flags, TR_IMPACT);
1205                         break;
1206                 case 21:
1207                 case 22:
1208                         add_flag(o_ptr->art_flags, TR_BRAND_FIRE);
1209                         if (!artifact_bias)
1210                                 artifact_bias = BIAS_FIRE;
1211                         break;
1212                 case 23:
1213                 case 24:
1214                         add_flag(o_ptr->art_flags, TR_BRAND_COLD);
1215                         if (!artifact_bias)
1216                                 artifact_bias = BIAS_COLD;
1217                         break;
1218                 case 25:
1219                 case 26:
1220                         add_flag(o_ptr->art_flags, TR_BRAND_ELEC);
1221                         if (!artifact_bias)
1222                                 artifact_bias = BIAS_ELEC;
1223                         break;
1224                 case 27:
1225                 case 28:
1226                         add_flag(o_ptr->art_flags, TR_BRAND_ACID);
1227                         if (!artifact_bias)
1228                                 artifact_bias = BIAS_ACID;
1229                         break;
1230                 case 29:
1231                 case 30:
1232                         add_flag(o_ptr->art_flags, TR_BRAND_POIS);
1233                         if (!artifact_bias && !one_in_(3))
1234                                 artifact_bias = BIAS_POIS;
1235                         else if (!artifact_bias && one_in_(6))
1236                                 artifact_bias = BIAS_NECROMANTIC;
1237                         else if (!artifact_bias)
1238                                 artifact_bias = BIAS_ROGUE;
1239                         break;
1240                 case 31:
1241                         add_flag(o_ptr->art_flags, TR_VAMPIRIC);
1242                         if (!artifact_bias)
1243                                 artifact_bias = BIAS_NECROMANTIC;
1244                         break;
1245                 case 32:
1246                         add_flag(o_ptr->art_flags, TR_FORCE_WEAPON);
1247                         if (!artifact_bias)
1248                                 artifact_bias = (one_in_(2) ? BIAS_MAGE : BIAS_PRIESTLY);
1249                         break;
1250                 case 33:
1251                 case 34:
1252                         add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
1253                         break;
1254                 default:
1255                         add_flag(o_ptr->art_flags, TR_CHAOTIC);
1256                         if (!artifact_bias)
1257                                 artifact_bias = BIAS_CHAOS;
1258                         break;
1259         }
1260 }
1261
1262
1263 static void give_activation_power(object_type *o_ptr)
1264 {
1265         int type = 0, chance = 0;
1266
1267         switch (artifact_bias)
1268         {
1269                 case BIAS_ELEC:
1270                         if (!one_in_(3))
1271                         {
1272                                 type = ACT_BO_ELEC_1;
1273                         }
1274                         else if (!one_in_(5))
1275                         {
1276                                 type = ACT_BA_ELEC_2;
1277                         }
1278                         else
1279                         {
1280                                 type = ACT_BA_ELEC_3;
1281                         }
1282                         chance = 101;
1283                         break;
1284
1285                 case BIAS_POIS:
1286                         type = ACT_BA_POIS_1;
1287                         chance = 101;
1288                         break;
1289
1290                 case BIAS_FIRE:
1291                         if (!one_in_(3))
1292                         {
1293                                 type = ACT_BO_FIRE_1;
1294                         }
1295                         else if (!one_in_(5))
1296                         {
1297                                 type = ACT_BA_FIRE_1;
1298                         }
1299                         else
1300                         {
1301                                 type = ACT_BA_FIRE_2;
1302                         }
1303                         chance = 101;
1304                         break;
1305
1306                 case BIAS_COLD:
1307                         chance = 101;
1308                         if (!one_in_(3))
1309                                 type = ACT_BO_COLD_1;
1310                         else if (!one_in_(3))
1311                                 type = ACT_BA_COLD_1;
1312                         else if (!one_in_(3))
1313                                 type = ACT_BA_COLD_2;
1314                         else
1315                                 type = ACT_BA_COLD_3;
1316                         break;
1317
1318                 case BIAS_CHAOS:
1319                         chance = 50;
1320                         if (one_in_(6))
1321                                 type = ACT_SUMMON_DEMON;
1322                         else
1323                                 type = ACT_CALL_CHAOS;
1324                         break;
1325
1326                 case BIAS_PRIESTLY:
1327                         chance = 101;
1328
1329                         if (one_in_(13))
1330                                 type = ACT_CHARM_UNDEAD;
1331                         else if (one_in_(12))
1332                                 type = ACT_BANISH_EVIL;
1333                         else if (one_in_(11))
1334                                 type = ACT_DISP_EVIL;
1335                         else if (one_in_(10))
1336                                 type = ACT_PROT_EVIL;
1337                         else if (one_in_(9))
1338                                 type = ACT_CURE_1000;
1339                         else if (one_in_(8))
1340                                 type = ACT_CURE_700;
1341                         else if (one_in_(7))
1342                                 type = ACT_REST_ALL;
1343                         else if (one_in_(6))
1344                                 type = ACT_REST_LIFE;
1345                         else
1346                                 type = ACT_CURE_MW;
1347                         break;
1348
1349                 case BIAS_NECROMANTIC:
1350                         chance = 101;
1351                         if (one_in_(66))
1352                                 type = ACT_WRAITH;
1353                         else if (one_in_(13))
1354                                 type = ACT_DISP_GOOD;
1355                         else if (one_in_(9))
1356                                 type = ACT_MASS_GENO;
1357                         else if (one_in_(8))
1358                                 type = ACT_GENOCIDE;
1359                         else if (one_in_(13))
1360                                 type = ACT_SUMMON_UNDEAD;
1361                         else if (one_in_(9))
1362                                 type = ACT_VAMPIRE_2;
1363                         else if (one_in_(6))
1364                                 type = ACT_CHARM_UNDEAD;
1365                         else
1366                                 type = ACT_VAMPIRE_1;
1367                         break;
1368
1369                 case BIAS_LAW:
1370                         chance = 101;
1371                         if (one_in_(8))
1372                                 type = ACT_BANISH_EVIL;
1373                         else if (one_in_(4))
1374                                 type = ACT_DISP_EVIL;
1375                         else
1376                                 type = ACT_PROT_EVIL;
1377                         break;
1378
1379                 case BIAS_ROGUE:
1380                         chance = 101;
1381                         if (one_in_(50))
1382                                 type = ACT_SPEED;
1383                         else if (one_in_(4))
1384                                 type = ACT_SLEEP;
1385                         else if (one_in_(3))
1386                                 type = ACT_DETECT_ALL;
1387                         else if (one_in_(8))
1388                                 type = ACT_ID_FULL;
1389                         else
1390                                 type = ACT_ID_PLAIN;
1391                         break;
1392
1393                 case BIAS_MAGE:
1394                         chance = 66;
1395                         if (one_in_(20))
1396                                 type = ACT_SUMMON_ELEMENTAL;
1397                         else if (one_in_(10))
1398                                 type = ACT_SUMMON_PHANTOM;
1399                         else if (one_in_(5))
1400                                 type = ACT_RUNE_EXPLO;
1401                         else
1402                                 type = ACT_ESP;
1403                         break;
1404
1405                 case BIAS_WARRIOR:
1406                         chance = 80;
1407                         if (one_in_(100))
1408                                 type = ACT_INVULN;
1409                         else
1410                                 type = ACT_BERSERK;
1411                         break;
1412
1413                 case BIAS_RANGER:
1414                         chance = 101;
1415                         if (one_in_(20))
1416                                 type = ACT_CHARM_ANIMALS;
1417                         else if (one_in_(7))
1418                                 type = ACT_SUMMON_ANIMAL;
1419                         else if (one_in_(6))
1420                                 type = ACT_CHARM_ANIMAL;
1421                         else if (one_in_(4))
1422                                 type = ACT_RESIST_ALL;
1423                         else if (one_in_(3))
1424                                 type = ACT_SATIATE;
1425                         else
1426                                 type = ACT_CURE_POISON;
1427                         break;
1428         }
1429
1430         while (!type || (randint1(100) >= chance))
1431         {
1432                 type = randint1(255);
1433                 switch (type)
1434                 {
1435                         case ACT_SUNLIGHT:
1436                         case ACT_BO_MISS_1:
1437                         case ACT_BA_POIS_1:
1438                         case ACT_BO_ELEC_1:
1439                         case ACT_BO_ACID_1:
1440                         case ACT_BO_COLD_1:
1441                         case ACT_BO_FIRE_1:
1442                         case ACT_CONFUSE:
1443                         case ACT_SLEEP:
1444                         case ACT_QUAKE:
1445                         case ACT_CURE_LW:
1446                         case ACT_CURE_MW:
1447                         case ACT_CURE_POISON:
1448                         case ACT_BERSERK:
1449                         case ACT_LIGHT:
1450                         case ACT_MAP_LIGHT:
1451                         case ACT_DEST_DOOR:
1452                         case ACT_STONE_MUD:
1453                         case ACT_TELEPORT:
1454                                 chance = 101;
1455                                 break;
1456                         case ACT_BA_COLD_1:
1457                         case ACT_BA_FIRE_1:
1458                         case ACT_DRAIN_1:
1459                         case ACT_TELE_AWAY:
1460                         case ACT_ESP:
1461                         case ACT_RESIST_ALL:
1462                         case ACT_DETECT_ALL:
1463                         case ACT_RECALL:
1464                         case ACT_SATIATE:
1465                         case ACT_RECHARGE:
1466                                 chance = 85;
1467                                 break;
1468                         case ACT_TERROR:
1469                         case ACT_PROT_EVIL:
1470                         case ACT_ID_PLAIN:
1471                                 chance = 75;
1472                                 break;
1473                         case ACT_DRAIN_2:
1474                         case ACT_VAMPIRE_1:
1475                         case ACT_BO_MISS_2:
1476                         case ACT_BA_FIRE_2:
1477                         case ACT_REST_LIFE:
1478                                 chance = 66;
1479                                 break;
1480                         case ACT_BA_COLD_3:
1481                         case ACT_BA_ELEC_3:
1482                         case ACT_WHIRLWIND:
1483                         case ACT_VAMPIRE_2:
1484                         case ACT_CHARM_ANIMAL:
1485                                 chance = 50;
1486                                 break;
1487                         case ACT_SUMMON_ANIMAL:
1488                                 chance = 40;
1489                                 break;
1490                         case ACT_DISP_EVIL:
1491                         case ACT_BA_MISS_3:
1492                         case ACT_DISP_GOOD:
1493                         case ACT_BANISH_EVIL:
1494                         case ACT_GENOCIDE:
1495                         case ACT_MASS_GENO:
1496                         case ACT_CHARM_UNDEAD:
1497                         case ACT_CHARM_OTHER:
1498                         case ACT_SUMMON_PHANTOM:
1499                         case ACT_REST_ALL:
1500                         case ACT_RUNE_EXPLO:
1501                                 chance = 33;
1502                                 break;
1503                         case ACT_CALL_CHAOS:
1504                         case ACT_ROCKET:
1505                         case ACT_CHARM_ANIMALS:
1506                         case ACT_CHARM_OTHERS:
1507                         case ACT_SUMMON_ELEMENTAL:
1508                         case ACT_CURE_700:
1509                         case ACT_SPEED:
1510                         case ACT_ID_FULL:
1511                         case ACT_RUNE_PROT:
1512                                 chance = 25;
1513                                 break;
1514                         case ACT_CURE_1000:
1515                         case ACT_XTRA_SPEED:
1516                         case ACT_DETECT_XTRA:
1517                         case ACT_DIM_DOOR:
1518                                 chance = 10;
1519                                 break;
1520                         case ACT_SUMMON_UNDEAD:
1521                         case ACT_SUMMON_DEMON:
1522                         case ACT_WRAITH:
1523                         case ACT_INVULN:
1524                         case ACT_ALCHEMY:
1525                                 chance = 5;
1526                                 break;
1527                         default:
1528                                 chance = 0;
1529                 }
1530         }
1531
1532         /* A type was chosen... */
1533         o_ptr->xtra2 = type;
1534         add_flag(o_ptr->art_flags, TR_ACTIVATE);
1535         o_ptr->timeout = 0;
1536 }
1537
1538
1539 static void get_random_name(char *return_name, bool armour, int power)
1540 {
1541         int prob = randint1(100);
1542
1543         if (prob <= SINDARIN_NAME)
1544         {
1545                 get_table_sindarin(return_name);
1546         }
1547         else if (prob <= TABLE_NAME)
1548         {
1549                 get_table_name(return_name);
1550         }
1551         else
1552         {
1553                 cptr filename;
1554
1555                 switch (armour)
1556                 {
1557                         case 1:
1558                                 switch (power)
1559                                 {
1560                                         case 0:
1561 #ifdef JP
1562                                                 filename = "a_cursed_j.txt";
1563 #else
1564                                                 filename = "a_cursed.txt";
1565 #endif
1566                                                 break;
1567                                         case 1:
1568 #ifdef JP
1569                                                 filename = "a_low_j.txt";
1570 #else
1571                                                 filename = "a_low.txt";
1572 #endif
1573                                                 break;
1574                                         case 2:
1575 #ifdef JP
1576                                                 filename = "a_med_j.txt";
1577 #else
1578                                                 filename = "a_med.txt";
1579 #endif
1580                                                 break;
1581                                         default:
1582 #ifdef JP
1583                                                 filename = "a_high_j.txt";
1584 #else
1585                                                 filename = "a_high.txt";
1586 #endif
1587                                 }
1588                                 break;
1589                         default:
1590                                 switch (power)
1591                                 {
1592                                         case 0:
1593 #ifdef JP
1594                                                 filename = "w_cursed_j.txt";
1595 #else
1596                                                 filename = "w_cursed.txt";
1597 #endif
1598                                                 break;
1599                                         case 1:
1600 #ifdef JP
1601                                                 filename = "w_low_j.txt";
1602 #else
1603                                                 filename = "w_low.txt";
1604 #endif
1605                                                 break;
1606                                         case 2:
1607 #ifdef JP
1608                                                 filename = "w_med_j.txt";
1609 #else
1610                                                 filename = "w_med.txt";
1611 #endif
1612                                                 break;
1613                                         default:
1614 #ifdef JP
1615                                                 filename = "w_high_j.txt";
1616 #else
1617                                                 filename = "w_high.txt";
1618 #endif
1619                                 }
1620                 }
1621
1622                 (void)get_rnd_line(filename, artifact_bias, return_name);
1623 #ifdef JP
1624                  if (return_name[0] == 0) get_table_name(return_name);
1625 #endif
1626         }
1627 }
1628
1629
1630 bool create_artifact(object_type *o_ptr, bool a_scroll)
1631 {
1632         char    new_name[1024];
1633         int     has_pval = 0;
1634         int     powers = randint1(5) + 1;
1635         int     max_type = (object_is_weapon_ammo(o_ptr) ? 7 : 5);
1636         int     power_level;
1637         s32b    total_flags;
1638         bool    a_cursed = FALSE;
1639         int     warrior_artifact_bias = 0;
1640         int i;
1641
1642         /* Reset artifact bias */
1643         artifact_bias = 0;
1644
1645         /* Nuke enchantments */
1646         o_ptr->name1 = 0;
1647         o_ptr->name2 = 0;
1648
1649         for (i = 0; i < TR_FLAG_SIZE; i++)
1650                 o_ptr->art_flags[i] |= k_info[o_ptr->k_idx].flags[i];
1651
1652         if (o_ptr->pval) has_pval = TRUE;
1653
1654         if (a_scroll && one_in_(4))
1655         {
1656                 switch (p_ptr->pclass)
1657                 {
1658                         case CLASS_WARRIOR:
1659                         case CLASS_BERSERKER:
1660                         case CLASS_ARCHER:
1661                         case CLASS_SAMURAI:
1662                         case CLASS_CAVALRY:
1663                         case CLASS_SMITH:
1664                                 artifact_bias = BIAS_WARRIOR;
1665                                 break;
1666                         case CLASS_MAGE:
1667                         case CLASS_HIGH_MAGE:
1668                         case CLASS_SORCERER:
1669                         case CLASS_MAGIC_EATER:
1670                         case CLASS_BLUE_MAGE:
1671                                 artifact_bias = BIAS_MAGE;
1672                                 break;
1673                         case CLASS_PRIEST:
1674                                 artifact_bias = BIAS_PRIESTLY;
1675                                 break;
1676                         case CLASS_ROGUE:
1677                         case CLASS_NINJA:
1678                                 artifact_bias = BIAS_ROGUE;
1679                                 warrior_artifact_bias = 25;
1680                                 break;
1681                         case CLASS_RANGER:
1682                         case CLASS_SNIPER:
1683                                 artifact_bias = BIAS_RANGER;
1684                                 warrior_artifact_bias = 30;
1685                                 break;
1686                         case CLASS_PALADIN:
1687                                 artifact_bias = BIAS_PRIESTLY;
1688                                 warrior_artifact_bias = 40;
1689                                 break;
1690                         case CLASS_WARRIOR_MAGE:
1691                         case CLASS_RED_MAGE:
1692                                 artifact_bias = BIAS_MAGE;
1693                                 warrior_artifact_bias = 40;
1694                                 break;
1695                         case CLASS_CHAOS_WARRIOR:
1696                                 artifact_bias = BIAS_CHAOS;
1697                                 warrior_artifact_bias = 40;
1698                                 break;
1699                         case CLASS_MONK:
1700                         case CLASS_FORCETRAINER:
1701                                 artifact_bias = BIAS_PRIESTLY;
1702                                 break;
1703                         case CLASS_MINDCRAFTER:
1704                         case CLASS_BARD:
1705                                 if (randint1(5) > 2) artifact_bias = BIAS_PRIESTLY;
1706                                 break;
1707                         case CLASS_TOURIST:
1708                                 if (randint1(5) > 2) artifact_bias = BIAS_WARRIOR;
1709                                 break;
1710                         case CLASS_IMITATOR:
1711                                 if (randint1(2) > 1) artifact_bias = BIAS_RANGER;
1712                                 break;
1713                         case CLASS_BEASTMASTER:
1714                                 artifact_bias = BIAS_CHR;
1715                                 warrior_artifact_bias = 50;
1716                                 break;
1717                         case CLASS_MIRROR_MASTER:
1718                                 if (randint1(4) > 1) 
1719                                 {
1720                                     artifact_bias = BIAS_MAGE;
1721                                 }
1722                                 else
1723                                 {
1724                                     artifact_bias = BIAS_ROGUE;
1725                                 }
1726                                 break;
1727                 }
1728         }
1729
1730         if (a_scroll && (randint1(100) <= warrior_artifact_bias))
1731                 artifact_bias = BIAS_WARRIOR;
1732
1733         strcpy(new_name, "");
1734
1735         if (!a_scroll && one_in_(A_CURSED))
1736                 a_cursed = TRUE;
1737         if (((o_ptr->tval == TV_AMULET) || (o_ptr->tval == TV_RING)) && object_is_cursed(o_ptr))
1738                 a_cursed = TRUE;
1739
1740         while (one_in_(powers) || one_in_(7) || one_in_(10))
1741                 powers++;
1742
1743         if (!a_cursed && one_in_(WEIRD_LUCK))
1744                 powers *= 2;
1745
1746         if (a_cursed) powers /= 2;
1747
1748         /* Main loop */
1749         while (powers--)
1750         {
1751                 switch (randint1(max_type))
1752                 {
1753                         case 1: case 2:
1754                                 random_plus(o_ptr);
1755                                 has_pval = TRUE;
1756                                 break;
1757                         case 3: case 4:
1758                                 if (one_in_(2) && object_is_weapon_ammo(o_ptr) && (o_ptr->tval != TV_BOW))
1759                                 {
1760                                         if (a_cursed && !one_in_(13)) break;
1761                                         if (one_in_(13))
1762                                         {
1763                                                 if (one_in_(o_ptr->ds+4)) o_ptr->ds++;
1764                                         }
1765                                         else
1766                                         {
1767                                                 if (one_in_(o_ptr->dd+1)) o_ptr->dd++;
1768                                         }
1769                                 }
1770                                 else
1771                                         random_resistance(o_ptr);
1772                                 break;
1773                         case 5:
1774                                 random_misc(o_ptr);
1775                                 break;
1776                         case 6: case 7:
1777                                 random_slay(o_ptr);
1778                                 break;
1779                         default:
1780                                 if (p_ptr->wizard) msg_print("Switch error in create_artifact!");
1781                                 powers++;
1782                 }
1783         };
1784
1785         if (has_pval)
1786         {
1787 #if 0
1788                 add_flag(o_ptr->art_flags, TR_SHOW_MODS);
1789
1790                 /* This one commented out by gw's request... */
1791                 if (!a_scroll)
1792                         add_flag(o_ptr->art_flags, TR_HIDE_TYPE);
1793 #endif
1794
1795                 if (have_flag(o_ptr->art_flags, TR_BLOWS))
1796                 {
1797                         o_ptr->pval = randint1(2);
1798                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
1799                                 o_ptr->pval++;
1800                 }
1801                 else
1802                 {
1803                         do
1804                         {
1805                                 o_ptr->pval++;
1806                         }
1807                         while (o_ptr->pval < randint1(5) || one_in_(o_ptr->pval));
1808                 }
1809
1810                 if ((o_ptr->pval > 4) && !one_in_(WEIRD_LUCK))
1811                         o_ptr->pval = 4;
1812         }
1813
1814         /* give it some plusses... */
1815         if (object_is_armour(o_ptr))
1816                 o_ptr->to_a += randint1(o_ptr->to_a > 19 ? 1 : 20 - o_ptr->to_a);
1817         else if (object_is_weapon_ammo(o_ptr))
1818         {
1819                 o_ptr->to_h += randint1(o_ptr->to_h > 19 ? 1 : 20 - o_ptr->to_h);
1820                 o_ptr->to_d += randint1(o_ptr->to_d > 19 ? 1 : 20 - o_ptr->to_d);
1821                 if ((have_flag(o_ptr->art_flags, TR_WIS)) && (o_ptr->pval > 0)) add_flag(o_ptr->art_flags, TR_BLESSED);
1822         }
1823
1824         /* Just to be sure */
1825         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
1826         add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
1827         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
1828         add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
1829
1830         total_flags = flag_cost(o_ptr, o_ptr->pval);
1831         if (cheat_peek) msg_format("%ld", total_flags);
1832
1833         if (a_cursed) curse_artifact(o_ptr);
1834
1835         if (!a_cursed &&
1836             one_in_(object_is_armour(o_ptr) ? ACTIVATION_CHANCE * 2 : ACTIVATION_CHANCE))
1837         {
1838                 o_ptr->xtra2 = 0;
1839                 give_activation_power(o_ptr);
1840         }
1841
1842         if (object_is_armour(o_ptr))
1843         {
1844                 while ((o_ptr->to_d+o_ptr->to_h) > 20)
1845                 {
1846                         if (one_in_(o_ptr->to_d) && one_in_(o_ptr->to_h)) break;
1847                         o_ptr->to_d -= (s16b)randint0(3);
1848                         o_ptr->to_h -= (s16b)randint0(3);
1849                 }
1850                 while ((o_ptr->to_d+o_ptr->to_h) > 10)
1851                 {
1852                         if (one_in_(o_ptr->to_d) || one_in_(o_ptr->to_h)) break;
1853                         o_ptr->to_d -= (s16b)randint0(3);
1854                         o_ptr->to_h -= (s16b)randint0(3);
1855                 }
1856         }
1857
1858         if (((artifact_bias == BIAS_MAGE) || (artifact_bias == BIAS_INT)) && (o_ptr->tval == TV_GLOVES)) add_flag(o_ptr->art_flags, TR_FREE_ACT);
1859
1860         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI))
1861         {
1862                 o_ptr->to_h = 0;
1863                 o_ptr->to_d = 0;
1864                 remove_flag(o_ptr->art_flags, TR_BLOWS);
1865                 remove_flag(o_ptr->art_flags, TR_FORCE_WEAPON);
1866                 remove_flag(o_ptr->art_flags, TR_SLAY_ANIMAL);
1867                 remove_flag(o_ptr->art_flags, TR_SLAY_EVIL);
1868                 remove_flag(o_ptr->art_flags, TR_SLAY_UNDEAD);
1869                 remove_flag(o_ptr->art_flags, TR_SLAY_DEMON);
1870                 remove_flag(o_ptr->art_flags, TR_SLAY_ORC);
1871                 remove_flag(o_ptr->art_flags, TR_SLAY_TROLL);
1872                 remove_flag(o_ptr->art_flags, TR_SLAY_GIANT);
1873                 remove_flag(o_ptr->art_flags, TR_SLAY_DRAGON);
1874                 remove_flag(o_ptr->art_flags, TR_KILL_DRAGON);
1875                 remove_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
1876                 remove_flag(o_ptr->art_flags, TR_VORPAL);
1877                 remove_flag(o_ptr->art_flags, TR_BRAND_POIS);
1878                 remove_flag(o_ptr->art_flags, TR_BRAND_ACID);
1879                 remove_flag(o_ptr->art_flags, TR_BRAND_ELEC);
1880                 remove_flag(o_ptr->art_flags, TR_BRAND_FIRE);
1881                 remove_flag(o_ptr->art_flags, TR_BRAND_COLD);
1882         }
1883
1884         if (!object_is_weapon_ammo(o_ptr))
1885         {
1886                 /* For armors */
1887                 if (a_cursed) power_level = 0;
1888                 else if (total_flags < 15000) power_level = 1;
1889                 else if (total_flags < 35000) power_level = 2;
1890                 else power_level = 3;
1891         }
1892
1893         else
1894         {
1895                 /* For weapons */
1896                 if (a_cursed) power_level = 0;
1897                 else if (total_flags < 20000) power_level = 1;
1898                 else if (total_flags < 45000) power_level = 2;
1899                 else power_level = 3;
1900         }
1901
1902         if (a_scroll)
1903         {
1904                 char dummy_name[80] = "";
1905 #ifdef JP
1906                 cptr ask_msg = "¤³¤Î¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤ò²¿¤È̾ÉÕ¤±¤Þ¤¹¤«¡©";
1907 #else
1908                 cptr ask_msg = "What do you want to call the artifact? ";
1909 #endif
1910
1911                 /* Identify it fully */
1912                 object_aware(o_ptr);
1913                 object_known(o_ptr);
1914
1915                 /* Mark the item as fully known */
1916                 o_ptr->ident |= (IDENT_MENTAL);
1917
1918                 (void)screen_object(o_ptr, 0L);
1919
1920                 if (!get_string(ask_msg, dummy_name, sizeof dummy_name)
1921                     || !dummy_name[0])
1922                 {
1923                         /* Cancelled */
1924                         if (one_in_(2))
1925                         {
1926                                 get_table_sindarin_aux(dummy_name);
1927                         }
1928                         else
1929                         {
1930                                 get_table_name_aux(dummy_name);
1931                         }
1932                 }
1933
1934 #ifdef JP
1935                 sprintf(new_name, "¡Ô%s¡Õ", dummy_name);
1936 #else
1937                 sprintf(new_name, "'%s'", dummy_name);
1938 #endif
1939
1940                 chg_virtue(V_INDIVIDUALISM, 2);
1941                 chg_virtue(V_ENCHANT, 5);
1942         }
1943         else
1944         {
1945                 get_random_name(new_name, object_is_armour(o_ptr), power_level);
1946         }
1947
1948         if (cheat_xtra)
1949         {
1950 #ifdef JP
1951                 if (artifact_bias) msg_format("±¿¤ÎÊФä¿¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È: %d¡£", artifact_bias);
1952                 else msg_print("¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ë±¿¤ÎÊФê¤Ê¤·¡£");
1953 #else
1954                 if (artifact_bias) msg_format("Biased artifact: %d.", artifact_bias);
1955                 else msg_print("No bias in artifact.");
1956 #endif
1957         }
1958
1959         /* Save the inscription */
1960         o_ptr->art_name = quark_add(new_name);
1961
1962         /* Window stuff */
1963         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1964
1965         return TRUE;
1966 }
1967
1968
1969 bool activate_random_artifact(object_type * o_ptr)
1970 {
1971         int plev = p_ptr->lev;
1972         int k, dir, dummy = 0;
1973
1974         if (!o_ptr->art_name) return FALSE; /* oops? */
1975
1976         /* Activate for attack */
1977         switch (o_ptr->xtra2)
1978         {
1979                 case ACT_SUNLIGHT:
1980                 {
1981                         if (!get_aim_dir(&dir)) return FALSE;
1982 #ifdef JP
1983                         msg_print("ÂÀÍÛ¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
1984 #else
1985                         msg_print("A line of sunlight appears.");
1986 #endif
1987
1988                         (void)lite_line(dir);
1989                         o_ptr->timeout = 10;
1990                         break;
1991                 }
1992
1993                 case ACT_BO_MISS_1:
1994                 {
1995 #ifdef JP
1996                         msg_print("¤½¤ì¤ÏâÁ¤·¤¤¤¯¤é¤¤¤ËÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
1997 #else
1998                         msg_print("It glows extremely brightly...");
1999 #endif
2000
2001                         if (!get_aim_dir(&dir)) return FALSE;
2002                         fire_bolt(GF_MISSILE, dir, damroll(2, 6));
2003                         o_ptr->timeout = 2;
2004                         break;
2005                 }
2006
2007                 case ACT_BA_POIS_1:
2008                 {
2009 #ifdef JP
2010                         msg_print("¤½¤ì¤ÏÇ»Î理Ë̮ư¤·¤Æ¤¤¤ë...");
2011 #else
2012                         msg_print("It throbs deep green...");
2013 #endif
2014
2015                         if (!get_aim_dir(&dir)) return FALSE;
2016                         fire_ball(GF_POIS, dir, 12, 3);
2017                         o_ptr->timeout = randint0(4) + 4;
2018                         break;
2019                 }
2020
2021                 case ACT_BO_ELEC_1:
2022                 {
2023 #ifdef JP
2024                         msg_print("¤½¤ì¤Ï²Ð²Ö¤Ëʤ¤ï¤ì¤¿...");
2025 #else
2026                         msg_print("It is covered in sparks...");
2027 #endif
2028
2029                         if (!get_aim_dir(&dir)) return FALSE;
2030                         fire_bolt(GF_ELEC, dir, damroll(4, 8));
2031                         o_ptr->timeout = randint0(5) + 5;
2032                         break;
2033                 }
2034
2035                 case ACT_BO_ACID_1:
2036                 {
2037 #ifdef JP
2038                         msg_print("¤½¤ì¤Ï»À¤Ëʤ¤ï¤ì¤¿...");
2039 #else
2040                         msg_print("It is covered in acid...");
2041 #endif
2042
2043                         if (!get_aim_dir(&dir)) return FALSE;
2044                         fire_bolt(GF_ACID, dir, damroll(5, 8));
2045                         o_ptr->timeout = randint0(6) + 6;
2046                         break;
2047                 }
2048
2049                 case ACT_BO_COLD_1:
2050                 {
2051 #ifdef JP
2052                         msg_print("¤½¤ì¤ÏÁú¤Ëʤ¤ï¤ì¤¿...");
2053 #else
2054                         msg_print("It is covered in frost...");
2055 #endif
2056
2057                         if (!get_aim_dir(&dir)) return FALSE;
2058                         fire_bolt(GF_COLD, dir, damroll(6, 8));
2059                         o_ptr->timeout = randint0(7) + 7;
2060                         break;
2061                 }
2062
2063                 case ACT_BO_FIRE_1:
2064                 {
2065 #ifdef JP
2066                         msg_print("¤½¤ì¤Ï±ê¤Ëʤ¤ï¤ì¤¿...");
2067 #else
2068                         msg_print("It is covered in fire...");
2069 #endif
2070
2071                         if (!get_aim_dir(&dir)) return FALSE;
2072                         fire_bolt(GF_FIRE, dir, damroll(9, 8));
2073                         o_ptr->timeout = randint0(8) + 8;
2074                         break;
2075                 }
2076
2077                 case ACT_BA_COLD_1:
2078                 {
2079 #ifdef JP
2080                         msg_print("¤½¤ì¤ÏÁú¤Ëʤ¤ï¤ì¤¿...");
2081 #else
2082                         msg_print("It is covered in frost...");
2083 #endif
2084
2085                         if (!get_aim_dir(&dir)) return FALSE;
2086                         fire_ball(GF_COLD, dir, 48, 2);
2087                         o_ptr->timeout = 400;
2088                         break;
2089                 }
2090
2091                 case ACT_BA_FIRE_1:
2092                 {
2093 #ifdef JP
2094                         msg_print("¤½¤ì¤ÏÀÖ¤¯·ã¤·¤¯µ±¤¤¤¿...");
2095 #else
2096                         msg_print("It glows an intense red...");
2097 #endif
2098
2099                         if (!get_aim_dir(&dir)) return FALSE;
2100                         fire_ball(GF_FIRE, dir, 72, 2);
2101                         o_ptr->timeout = 400;
2102                         break;
2103                 }
2104
2105                 case ACT_DRAIN_1:
2106                 {
2107 #ifdef JP
2108                         msg_print("¤½¤ì¤Ï¹õ¤¯µ±¤¤¤¿...");
2109 #else
2110                         msg_print("It glows black...");
2111 #endif
2112
2113                         if (!get_aim_dir(&dir)) return FALSE;
2114                         if (drain_life(dir, 100))
2115                         o_ptr->timeout = randint0(100) + 100;
2116                         break;
2117                 }
2118
2119                 case ACT_BA_COLD_2:
2120                 {
2121 #ifdef JP
2122                         msg_print("¤½¤ì¤ÏÀĤ¯·ã¤·¤¯µ±¤¤¤¿...");
2123 #else
2124                         msg_print("It glows an intense blue...");
2125 #endif
2126
2127                         if (!get_aim_dir(&dir)) return FALSE;
2128                         fire_ball(GF_COLD, dir, 100, 2);
2129                         o_ptr->timeout = 300;
2130                         break;
2131                 }
2132
2133                 case ACT_BA_ELEC_2:
2134                 {
2135 #ifdef JP
2136                         msg_print("Åŵ¤¤¬¥Ñ¥Á¥Ñ¥Á²»¤òΩ¤Æ¤¿...");
2137 #else
2138                         msg_print("It crackles with electricity...");
2139 #endif
2140
2141                         if (!get_aim_dir(&dir)) return FALSE;
2142                         fire_ball(GF_ELEC, dir, 100, 3);
2143                         o_ptr->timeout = 500;
2144                         break;
2145                 }
2146
2147                 case ACT_DRAIN_2:
2148                 {
2149 #ifdef JP
2150                         msg_print("¹õ¤¯µ±¤¤¤Æ¤¤¤ë...");
2151 #else
2152                         msg_print("It glows black...");
2153 #endif
2154
2155                         if (!get_aim_dir(&dir)) return FALSE;
2156                         drain_life(dir, 120);
2157                         o_ptr->timeout = 400;
2158                         break;
2159                 }
2160
2161                 case ACT_VAMPIRE_1:
2162                 {
2163                         if (!get_aim_dir(&dir)) return FALSE;
2164                         for (dummy = 0; dummy < 3; dummy++)
2165                         {
2166                                 if (drain_life(dir, 50))
2167                                 hp_player(50);
2168                         }
2169                         o_ptr->timeout = 400;
2170                         break;
2171                 }
2172
2173                 case ACT_BO_MISS_2:
2174                 {
2175 #ifdef JP
2176                         msg_print("ËâË¡¤Î¥È¥²¤¬¸½¤ì¤¿...");
2177 #else
2178                         msg_print("It grows magical spikes...");
2179 #endif
2180
2181                         if (!get_aim_dir(&dir)) return FALSE;
2182                         fire_bolt(GF_ARROW, dir, 150);
2183                         o_ptr->timeout = randint0(90) + 90;
2184                         break;
2185                 }
2186
2187                 case ACT_BA_FIRE_2:
2188                 {
2189 #ifdef JP
2190                         msg_print("¿¼ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2191 #else
2192                         msg_print("It glows deep red...");
2193 #endif
2194
2195                         if (!get_aim_dir(&dir)) return FALSE;
2196                         fire_ball(GF_FIRE, dir, 120, 3);
2197                         o_ptr->timeout = randint0(225) + 225;
2198                         break;
2199                 }
2200
2201                 case ACT_BA_COLD_3:
2202                 {
2203 #ifdef JP
2204                         msg_print("ÌÀ¤ë¤¯Çò¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2205 #else
2206                         msg_print("It glows bright white...");
2207 #endif
2208
2209                         if (!get_aim_dir(&dir)) return FALSE;
2210                         fire_ball(GF_COLD, dir, 200, 3);
2211                         o_ptr->timeout = randint0(325) + 325;
2212                         break;
2213                 }
2214
2215                 case ACT_BA_ELEC_3:
2216                 {
2217 #ifdef JP
2218                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2219 #else
2220                         msg_print("It glows deep blue...");
2221 #endif
2222
2223                         if (!get_aim_dir(&dir)) return FALSE;
2224                         fire_ball(GF_ELEC, dir, 250, 3);
2225                         o_ptr->timeout = randint0(425) + 425;
2226                         break;
2227                 }
2228
2229                 case ACT_WHIRLWIND:
2230                 {
2231                         {
2232                                 int y = 0, x = 0;
2233                                 cave_type       *c_ptr;
2234                                 monster_type    *m_ptr;
2235
2236                                 for (dir = 0; dir <= 9; dir++)
2237                                 {
2238                                         y = py + ddy[dir];
2239                                         x = px + ddx[dir];
2240                                         c_ptr = &cave[y][x];
2241
2242                                         /* Get the monster */
2243                                         m_ptr = &m_list[c_ptr->m_idx];
2244
2245                                         /* Hack -- attack monsters */
2246                                         if (c_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
2247                                                 py_attack(y, x, 0);
2248                                 }
2249                         }
2250                         o_ptr->timeout = 250;
2251                         break;
2252                 }
2253
2254                 case ACT_VAMPIRE_2:
2255                 {
2256                         if (!get_aim_dir(&dir)) return FALSE;
2257                         for (dummy = 0; dummy < 3; dummy++)
2258                         {
2259                                 if (drain_life(dir, 100))
2260                                 hp_player(100);
2261                         }
2262
2263                         o_ptr->timeout = 400;
2264                         break;
2265                 }
2266
2267
2268                 case ACT_CALL_CHAOS:
2269                 {
2270 #ifdef JP
2271                         msg_print("ÍÍ¡¹¤Ê¿§¤Î²Ð²Ö¤òȯ¤·¤Æ¤¤¤ë...");
2272 #else
2273                         msg_print("It glows in scintillating colours...");
2274 #endif
2275
2276                         call_chaos();
2277                         o_ptr->timeout = 350;
2278                         break;
2279                 }
2280
2281                 case ACT_ROCKET:
2282                 {
2283                         if (!get_aim_dir(&dir)) return FALSE;
2284 #ifdef JP
2285                         msg_print("¥í¥±¥Ã¥È¤òȯ¼Í¤·¤¿¡ª");
2286 #else
2287                         msg_print("You launch a rocket!");
2288 #endif
2289
2290                         fire_ball(GF_ROCKET, dir, 250 + plev*3, 2);
2291                         o_ptr->timeout = 400;
2292                         break;
2293                 }
2294
2295                 case ACT_DISP_EVIL:
2296                 {
2297 #ifdef JP
2298                         msg_print("¿ÀÀ»¤ÊÊ·°Ïµ¤¤¬½¼Ëþ¤·¤¿...");
2299 #else
2300                         msg_print("It floods the area with goodness...");
2301 #endif
2302
2303                         dispel_evil(p_ptr->lev * 5);
2304                         o_ptr->timeout = randint0(300) + 300;
2305                         break;
2306                 }
2307
2308                 case ACT_DISP_GOOD:
2309                 {
2310 #ifdef JP
2311                         msg_print("¼Ù°­¤ÊÊ·°Ïµ¤¤¬½¼Ëþ¤·¤¿...");
2312 #else
2313                         msg_print("It floods the area with evil...");
2314 #endif
2315
2316                         dispel_good(p_ptr->lev * 5);
2317                         o_ptr->timeout = randint0(300) + 300;
2318                         break;
2319                 }
2320
2321                 case ACT_BA_MISS_3:
2322                 {
2323                         if (!get_aim_dir(&dir)) return FALSE;
2324 #ifdef JP
2325                         msg_print("¤¢¤Ê¤¿¤Ï¥¨¥ì¥á¥ó¥È¤Î¥Ö¥ì¥¹¤òÅǤ¤¤¿¡£");
2326 #else
2327                         msg_print("You breathe the elements.");
2328 #endif
2329
2330                         fire_ball(GF_MISSILE, dir, 300, 4);
2331                         o_ptr->timeout = 500;
2332                         break;
2333                 }
2334
2335                 /* Activate for other offensive action */
2336
2337                 case ACT_CONFUSE:
2338                 {
2339 #ifdef JP
2340                         msg_print("ÍÍ¡¹¤Ê¿§¤Î²Ð²Ö¤òȯ¤·¤Æ¤¤¤ë...");
2341 #else
2342                         msg_print("It glows in scintillating colours...");
2343 #endif
2344
2345                         if (!get_aim_dir(&dir)) return FALSE;
2346                         confuse_monster(dir, 20);
2347                         o_ptr->timeout = 15;
2348                         break;
2349                 }
2350
2351                 case ACT_SLEEP:
2352                 {
2353 #ifdef JP
2354                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2355 #else
2356                         msg_print("It glows deep blue...");
2357 #endif
2358
2359                         sleep_monsters_touch();
2360                         o_ptr->timeout = 55;
2361                         break;
2362                 }
2363
2364                 case ACT_QUAKE:
2365                 {
2366                         earthquake(py, px, 10);
2367                         o_ptr->timeout = 50;
2368                         break;
2369                 }
2370
2371                 case ACT_TERROR:
2372                 {
2373                         turn_monsters(40 + p_ptr->lev);
2374                         o_ptr->timeout = 3 * (p_ptr->lev + 10);
2375                         break;
2376                 }
2377
2378                 case ACT_TELE_AWAY:
2379                 {
2380                         if (!get_aim_dir(&dir)) return FALSE;
2381                         (void)fire_beam(GF_AWAY_ALL, dir, plev);
2382                         o_ptr->timeout = 200;
2383                         break;
2384                 }
2385
2386                 case ACT_BANISH_EVIL:
2387                 {
2388                         if (banish_evil(100))
2389                         {
2390 #ifdef JP
2391                                 msg_print("¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤ÎÎϤ¬¼Ù°­¤òÂǤÁʧ¤Ã¤¿¡ª");
2392 #else
2393                                 msg_print("The power of the artifact banishes evil!");
2394 #endif
2395
2396                         }
2397                         o_ptr->timeout = 250 + randint1(250);
2398                         break;
2399                 }
2400
2401                 case ACT_GENOCIDE:
2402                 {
2403 #ifdef JP
2404                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2405 #else
2406                         msg_print("It glows deep blue...");
2407 #endif
2408
2409                         (void)symbol_genocide(200, TRUE);
2410                         o_ptr->timeout = 500;
2411                         break;
2412                 }
2413
2414                 case ACT_MASS_GENO:
2415                 {
2416 #ifdef JP
2417                         msg_print("¤Ò¤É¤¯±Ô¤¤²»¤¬Î®¤ì½Ð¤¿...");
2418 #else
2419                         msg_print("It lets out a long, shrill note...");
2420 #endif
2421
2422                         (void)mass_genocide(200, TRUE);
2423                         o_ptr->timeout = 1000;
2424                         break;
2425                 }
2426
2427                 /* Activate for summoning / charming */
2428
2429                 case ACT_CHARM_ANIMAL:
2430                 {
2431                         if (!get_aim_dir(&dir)) return FALSE;
2432                         (void)charm_animal(dir, plev);
2433                         o_ptr->timeout = 300;
2434                         break;
2435                 }
2436
2437                 case ACT_CHARM_UNDEAD:
2438                 {
2439                         if (!get_aim_dir(&dir)) return FALSE;
2440                         (void)control_one_undead(dir, plev);
2441                         o_ptr->timeout = 333;
2442                         break;
2443                 }
2444
2445                 case ACT_CHARM_OTHER:
2446                 {
2447                         if (!get_aim_dir(&dir)) return FALSE;
2448                         (void)charm_monster(dir, plev);
2449                         o_ptr->timeout = 400;
2450                         break;
2451                 }
2452
2453                 case ACT_CHARM_ANIMALS:
2454                 {
2455                         (void)charm_animals(plev * 2);
2456                         o_ptr->timeout = 500;
2457                         break;
2458                 }
2459
2460                 case ACT_CHARM_OTHERS:
2461                 {
2462                         charm_monsters(plev * 2);
2463                         o_ptr->timeout = 750;
2464                         break;
2465                 }
2466
2467                 case ACT_SUMMON_ANIMAL:
2468                 {
2469                         (void)summon_specific(-1, py, px, plev, SUMMON_ANIMAL_RANGER, (PM_ALLOW_GROUP | PM_FORCE_PET));
2470                         o_ptr->timeout = 200 + randint1(300);
2471                         break;
2472                 }
2473
2474                 case ACT_SUMMON_PHANTOM:
2475                 {
2476 #ifdef JP
2477                         msg_print("¸¸Îî¤ò¾¤´­¤·¤¿¡£");
2478 #else
2479                         msg_print("You summon a phantasmal servant.");
2480 #endif
2481
2482                         (void)summon_specific(-1, py, px, dun_level, SUMMON_PHANTOM, (PM_ALLOW_GROUP | PM_FORCE_PET));
2483                         o_ptr->timeout = 200 + randint1(200);
2484                         break;
2485                 }
2486
2487                 case ACT_SUMMON_ELEMENTAL:
2488                 {
2489                         bool pet = one_in_(3);
2490                         u32b mode = 0L;
2491
2492                         if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
2493                         if (pet) mode |= PM_FORCE_PET;
2494                         else mode |= PM_NO_PET;
2495
2496                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), SUMMON_ELEMENTAL, mode))
2497                         {
2498 #ifdef JP
2499                                 msg_print("¥¨¥ì¥á¥ó¥¿¥ë¤¬¸½¤ì¤¿...");
2500 #else
2501                                 msg_print("An elemental materializes...");
2502 #endif
2503
2504
2505                                 if (pet)
2506 #ifdef JP
2507                                         msg_print("¤¢¤Ê¤¿¤ËÉþ½¾¤·¤Æ¤¤¤ë¤è¤¦¤À¡£");
2508 #else
2509                                         msg_print("It seems obedient to you.");
2510 #endif
2511
2512                                 else
2513 #ifdef JP
2514                                         msg_print("¤½¤ì¤ò¥³¥ó¥È¥í¡¼¥ë¤Ç¤­¤Ê¤«¤Ã¤¿¡ª");
2515 #else
2516                                         msg_print("You fail to control it!");
2517 #endif
2518
2519                         }
2520
2521                         o_ptr->timeout = 750;
2522                         break;
2523                 }
2524
2525                 case ACT_SUMMON_DEMON:
2526                 {
2527                         bool pet = one_in_(3);
2528                         u32b mode = 0L;
2529
2530                         if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
2531                         if (pet) mode |= PM_FORCE_PET;
2532                         else mode |= PM_NO_PET;
2533
2534                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), SUMMON_DEMON, mode))
2535                         {
2536 #ifdef JP
2537                                 msg_print("ⲫ¤Î°­½­¤¬½¼Ëþ¤·¤¿¡£");
2538 #else
2539                                 msg_print("The area fills with a stench of sulphur and brimstone.");
2540 #endif
2541
2542                                 if (pet)
2543 #ifdef JP
2544                                         msg_print("¡Ö¤´ÍѤǤ´¤¶¤¤¤Þ¤¹¤«¡¢¤´¼ç¿ÍÍÍ¡×");
2545 #else
2546                                         msg_print("'What is thy bidding... Master?'");
2547 #endif
2548
2549                                 else
2550 #ifdef JP
2551                                         msg_print("¡ÖNON SERVIAM! Wretch! ¤ªÁ°¤Îº²¤òĺ¤¯¤¾¡ª¡×");
2552 #else
2553                                         msg_print("'NON SERVIAM! Wretch! I shall feast on thy mortal soul!'");
2554 #endif
2555
2556                         }
2557
2558                         o_ptr->timeout = 666 + randint1(333);
2559                         break;
2560                 }
2561
2562                 case ACT_SUMMON_UNDEAD:
2563                 {
2564                         bool pet = one_in_(3);
2565                         int type;
2566                         u32b mode = 0L;
2567
2568                         type = (plev > 47 ? SUMMON_HI_UNDEAD : SUMMON_UNDEAD);
2569
2570                         if (!pet || ((plev > 24) && one_in_(3))) mode |= PM_ALLOW_GROUP;
2571                         if (pet) mode |= PM_FORCE_PET;
2572                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2573
2574                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), type, mode))
2575                         {
2576 #ifdef JP
2577                                 msg_print("Î䤿¤¤É÷¤¬¤¢¤Ê¤¿¤Î¼þ¤ê¤Ë¿á¤­»Ï¤á¤¿¡£¤½¤ì¤ÏÉåÇÔ½­¤ò±¿¤ó¤Ç¤¤¤ë...");
2578 #else
2579                                 msg_print("Cold winds begin to blow around you, carrying with them the stench of decay...");
2580 #endif
2581
2582                                 if (pet)
2583 #ifdef JP
2584                                         msg_print("¸Å¤¨¤Î»à¤»¤ë¼Ô¶¦¤¬¤¢¤Ê¤¿¤Ë»Å¤¨¤ë¤¿¤áÅÚ¤«¤éᴤä¿¡ª");
2585 #else
2586                                         msg_print("Ancient, long-dead forms arise from the ground to serve you!");
2587 #endif
2588
2589                                 else
2590 #ifdef JP
2591                                         msg_print("»à¼Ô¤¬á´¤Ã¤¿¡£Ì²¤ê¤ò˸¤²¤ë¤¢¤Ê¤¿¤òȳ¤¹¤ë¤¿¤á¤Ë¡ª");
2592 #else
2593                                         msg_print("'The dead arise... to punish you for disturbing them!'");
2594 #endif
2595
2596                         }
2597
2598                         o_ptr->timeout = 666 + randint1(333);
2599                         break;
2600                 }
2601
2602                 /* Activate for healing */
2603
2604                 case ACT_CURE_LW:
2605                 {
2606                         (void)set_afraid(0);
2607                         (void)hp_player(30);
2608                         o_ptr->timeout = 10;
2609                         break;
2610                 }
2611
2612                 case ACT_CURE_MW:
2613                 {
2614 #ifdef JP
2615                         msg_print("¿¼»ç¿§¤Î¸÷¤òȯ¤·¤Æ¤¤¤ë...");
2616 #else
2617                         msg_print("It radiates deep purple...");
2618 #endif
2619
2620                         hp_player(damroll(4, 8));
2621                         (void)set_cut((p_ptr->cut / 2) - 50);
2622                         o_ptr->timeout = randint0(3) + 3;
2623                         break;
2624                 }
2625
2626                 case ACT_CURE_POISON:
2627                 {
2628 #ifdef JP
2629                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2630 #else
2631                         msg_print("It glows deep blue...");
2632 #endif
2633
2634                         (void)set_afraid(0);
2635                         (void)set_poisoned(0);
2636                         o_ptr->timeout = 5;
2637                         break;
2638                 }
2639
2640                 case ACT_REST_LIFE:
2641                 {
2642 #ifdef JP
2643                         msg_print("¿¼¹È¤Ëµ±¤¤¤Æ¤¤¤ë...");
2644 #else
2645                         msg_print("It glows a deep red...");
2646 #endif
2647
2648                         restore_level();
2649                         o_ptr->timeout = 450;
2650                         break;
2651                 }
2652
2653                 case ACT_REST_ALL:
2654                 {
2655 #ifdef JP
2656                         msg_print("Ç»Îп§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2657 #else
2658                         msg_print("It glows a deep green...");
2659 #endif
2660
2661                         (void)do_res_stat(A_STR);
2662                         (void)do_res_stat(A_INT);
2663                         (void)do_res_stat(A_WIS);
2664                         (void)do_res_stat(A_DEX);
2665                         (void)do_res_stat(A_CON);
2666                         (void)do_res_stat(A_CHR);
2667                         (void)restore_level();
2668                         o_ptr->timeout = 750;
2669                         break;
2670                 }
2671
2672                 case ACT_CURE_700:
2673                 {
2674 #ifdef JP
2675                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2676 #else
2677                         msg_print("It glows deep blue...");
2678 #endif
2679
2680 #ifdef JP
2681                         msg_print("ÂÎÆâ¤ËÃȤ«¤¤¸ÝÆ°¤¬´¶¤¸¤é¤ì¤ë...");
2682 #else
2683                         msg_print("You feel a warm tingling inside...");
2684 #endif
2685
2686                         (void)hp_player(700);
2687                         (void)set_cut(0);
2688                         o_ptr->timeout = 250;
2689                         break;
2690                 }
2691
2692                 case ACT_CURE_1000:
2693                 {
2694 #ifdef JP
2695                         msg_print("Çò¤¯ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2696 #else
2697                         msg_print("It glows a bright white...");
2698 #endif
2699
2700 #ifdef JP
2701                         msg_print("¤Ò¤¸¤ç¤¦¤Ëµ¤Ê¬¤¬¤è¤¤...");
2702 #else
2703                         msg_print("You feel much better...");
2704 #endif
2705
2706                         (void)hp_player(1000);
2707                         (void)set_cut(0);
2708                         o_ptr->timeout = 888;
2709                         break;
2710                 }
2711
2712                 /* Activate for timed effect */
2713
2714                 case ACT_ESP:
2715                 {
2716                         (void)set_tim_esp(randint1(30) + 25, FALSE);
2717                         o_ptr->timeout = 200;
2718                         break;
2719                 }
2720
2721                 case ACT_BERSERK:
2722                 {
2723                         (void)set_afraid(0);
2724                         (void)set_hero(randint1(50) + 50, FALSE);
2725                         (void)set_blessed(randint1(50) + 50, FALSE);
2726                         o_ptr->timeout = 100 + randint1(100);
2727                         break;
2728                 }
2729
2730                 case ACT_PROT_EVIL:
2731                 {
2732 #ifdef JP
2733                         msg_print("±Ô¤¤²»¤¬Î®¤ì½Ð¤¿...");
2734 #else
2735                         msg_print("It lets out a shrill wail...");
2736 #endif
2737
2738                         k = 3 * p_ptr->lev;
2739                         (void)set_protevil(randint1(25) + k, FALSE);
2740                         o_ptr->timeout = randint0(225) + 225;
2741                         break;
2742                 }
2743
2744                 case ACT_RESIST_ALL:
2745                 {
2746 #ifdef JP
2747                         msg_print("ÍÍ¡¹¤Ê¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2748 #else
2749                         msg_print("It glows many colours...");
2750 #endif
2751
2752                         (void)set_oppose_acid(randint1(40) + 40, FALSE);
2753                         (void)set_oppose_elec(randint1(40) + 40, FALSE);
2754                         (void)set_oppose_fire(randint1(40) + 40, FALSE);
2755                         (void)set_oppose_cold(randint1(40) + 40, FALSE);
2756                         (void)set_oppose_pois(randint1(40) + 40, FALSE);
2757                         o_ptr->timeout = 200;
2758                         break;
2759                 }
2760
2761                 case ACT_SPEED:
2762                 {
2763 #ifdef JP
2764                         msg_print("ÌÀ¤ë¤¯Îп§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2765 #else
2766                         msg_print("It glows bright green...");
2767 #endif
2768
2769                         (void)set_fast(randint1(20) + 20, FALSE);
2770                         o_ptr->timeout = 250;
2771                         break;
2772                 }
2773
2774                 case ACT_XTRA_SPEED:
2775                 {
2776 #ifdef JP
2777                         msg_print("ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2778 #else
2779                         msg_print("It glows brightly...");
2780 #endif
2781
2782                         (void)set_fast(randint1(75) + 75, FALSE);
2783                         o_ptr->timeout = randint0(200) + 200;
2784                         break;
2785                 }
2786
2787                 case ACT_WRAITH:
2788                 {
2789                         set_wraith_form(randint1(plev / 2) + (plev / 2), FALSE);
2790                         o_ptr->timeout = 1000;
2791                         break;
2792                 }
2793
2794                 case ACT_INVULN:
2795                 {
2796                         (void)set_invuln(randint1(8) + 8, FALSE);
2797                         o_ptr->timeout = 1000;
2798                         break;
2799                 }
2800
2801                 /* Activate for general purpose effect (detection etc.) */
2802
2803                 case ACT_LIGHT:
2804                 {
2805 #ifdef JP
2806                         msg_print("À¡¤ó¤À¸÷¤¬¤¢¤Õ¤ì½Ð¤¿...");
2807 #else
2808                         msg_print("It wells with clear light...");
2809 #endif
2810
2811                         lite_area(damroll(2, 15), 3);
2812                         o_ptr->timeout = randint0(10) + 10;
2813                         break;
2814                 }
2815
2816                 case ACT_MAP_LIGHT:
2817                 {
2818 #ifdef JP
2819                         msg_print("âÁ¤·¤¯µ±¤¤¤¿...");
2820 #else
2821                         msg_print("It shines brightly...");
2822 #endif
2823
2824                         map_area(DETECT_RAD_MAP);
2825                         lite_area(damroll(2, 15), 3);
2826                         o_ptr->timeout = randint0(50) + 50;
2827                         break;
2828                 }
2829
2830                 case ACT_DETECT_ALL:
2831                 {
2832 #ifdef JP
2833                         msg_print("Çò¤¯ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2834 #else
2835                         msg_print("It glows bright white...");
2836 #endif
2837
2838 #ifdef JP
2839                         msg_print("¿´¤Ë¥¤¥á¡¼¥¸¤¬É⤫¤ó¤Ç¤­¤¿...");
2840 #else
2841                         msg_print("An image forms in your mind...");
2842 #endif
2843
2844                         detect_all(DETECT_RAD_DEFAULT);
2845                         o_ptr->timeout = randint0(55) + 55;
2846                         break;
2847                 }
2848
2849                 case ACT_DETECT_XTRA:
2850                 {
2851 #ifdef JP
2852                         msg_print("ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2853 #else
2854                         msg_print("It glows brightly...");
2855 #endif
2856
2857                         detect_all(DETECT_RAD_DEFAULT);
2858                         probing();
2859                         identify_fully(FALSE);
2860                         o_ptr->timeout = 1000;
2861                         break;
2862                 }
2863
2864                 case ACT_ID_FULL:
2865                 {
2866 #ifdef JP
2867                         msg_print("²«¿§¤¯µ±¤¤¤Æ¤¤¤ë...");
2868 #else
2869                         msg_print("It glows yellow...");
2870 #endif
2871
2872                         identify_fully(FALSE);
2873                         o_ptr->timeout = 750;
2874                         break;
2875                 }
2876
2877                 case ACT_ID_PLAIN:
2878                 {
2879                         if (!ident_spell(FALSE)) return FALSE;
2880                         o_ptr->timeout = 10;
2881                         break;
2882                 }
2883
2884                 case ACT_RUNE_EXPLO:
2885                 {
2886 #ifdef JP
2887                         msg_print("ÌÀ¤ë¤¤ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2888 #else
2889                         msg_print("It glows bright red...");
2890 #endif
2891
2892                         explosive_rune();
2893                         o_ptr->timeout = 200;
2894                         break;
2895                 }
2896
2897                 case ACT_RUNE_PROT:
2898                 {
2899 #ifdef JP
2900                         msg_print("¥Ö¥ë¡¼¤ËÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2901 #else
2902                         msg_print("It glows light blue...");
2903 #endif
2904
2905                         warding_glyph();
2906                         o_ptr->timeout = 400;
2907                         break;
2908                 }
2909
2910                 case ACT_SATIATE:
2911                 {
2912                         (void)set_food(PY_FOOD_MAX - 1);
2913                         o_ptr->timeout = 200;
2914                         break;
2915                 }
2916
2917                 case ACT_DEST_DOOR:
2918                 {
2919 #ifdef JP
2920                         msg_print("ÌÀ¤ë¤¤ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2921 #else
2922                         msg_print("It glows bright red...");
2923 #endif
2924
2925                         destroy_doors_touch();
2926                         o_ptr->timeout = 10;
2927                         break;
2928                 }
2929
2930                 case ACT_STONE_MUD:
2931                 {
2932 #ifdef JP
2933                         msg_print("¸ÝÆ°¤·¤Æ¤¤¤ë...");
2934 #else
2935                         msg_print("It pulsates...");
2936 #endif
2937
2938                         if (!get_aim_dir(&dir)) return FALSE;
2939                         wall_to_mud(dir);
2940                         o_ptr->timeout = 5;
2941                         break;
2942                 }
2943
2944                 case ACT_RECHARGE:
2945                 {
2946                         recharge(130);
2947                         o_ptr->timeout = 70;
2948                         break;
2949                 }
2950
2951                 case ACT_ALCHEMY:
2952                 {
2953 #ifdef JP
2954                         msg_print("ÌÀ¤ë¤¤²«¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2955 #else
2956                         msg_print("It glows bright yellow...");
2957 #endif
2958
2959                         (void)alchemy();
2960                         o_ptr->timeout = 500;
2961                         break;
2962                 }
2963
2964                 case ACT_DIM_DOOR:
2965                 {
2966 #ifdef JP
2967                         msg_print("¼¡¸µ¤ÎÈ⤬³«¤¤¤¿¡£ÌÜŪÃϤòÁª¤ó¤Ç²¼¤µ¤¤¡£");
2968 #else
2969                         msg_print("You open a dimensional gate. Choose a destination.");
2970 #endif
2971
2972                         if (!dimension_door()) return FALSE;
2973                         o_ptr->timeout = 100;
2974                         break;
2975                 }
2976
2977
2978                 case ACT_TELEPORT:
2979                 {
2980 #ifdef JP
2981                         msg_print("¼þ¤ê¤Î¶õ´Ö¤¬ÏĤó¤Ç¤¤¤ë...");
2982 #else
2983                         msg_print("It twists space around you...");
2984 #endif
2985
2986                         teleport_player(100, 0L);
2987                         o_ptr->timeout = 45;
2988                         break;
2989                 }
2990
2991                 case ACT_RECALL:
2992                 {
2993 #ifdef JP
2994                         msg_print("¤ä¤ï¤é¤«¤ÊÇò¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2995 #else
2996                         msg_print("It glows soft white...");
2997 #endif
2998                         if (!word_of_recall()) return FALSE;
2999                         o_ptr->timeout = 200;
3000                         break;
3001                 }
3002
3003                 default:
3004                 {
3005 #ifdef JP
3006                         msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
3007 #else
3008                         msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
3009 #endif
3010
3011                         return FALSE;
3012                 }
3013         }
3014
3015         return TRUE;
3016 }
3017
3018
3019 void get_bloody_moon_flags(object_type *o_ptr)
3020 {
3021         int dummy, i;
3022
3023         for (i = 0; i < TR_FLAG_SIZE; i++)
3024                 o_ptr->art_flags[i] = a_info[ART_BLOOD].flags[i];
3025
3026         dummy = randint1(2) + randint1(2);
3027         for (i = 0; i < dummy; i++)
3028         {
3029                 int flag = randint0(26);
3030                 if (flag >= 20) add_flag(o_ptr->art_flags, TR_KILL_UNDEAD + flag - 20);
3031                 else if (flag == 19) add_flag(o_ptr->art_flags, TR_KILL_ANIMAL);
3032                 else if (flag == 18) add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
3033                 else add_flag(o_ptr->art_flags, TR_CHAOTIC + flag);
3034         }
3035
3036         dummy = randint1(2);
3037         for (i = 0; i < dummy; i++) one_resistance(o_ptr);
3038
3039         for (i = 0; i < 2; i++)
3040         {
3041                 int tmp = randint0(11);
3042                 if (tmp < 6) add_flag(o_ptr->art_flags, TR_STR + tmp);
3043                 else add_flag(o_ptr->art_flags, TR_STEALTH + tmp - 6);
3044         }
3045 }
3046
3047
3048 void random_artifact_resistance(object_type * o_ptr, artifact_type *a_ptr)
3049 {
3050         bool give_resistance = FALSE, give_power = FALSE;
3051
3052         if (o_ptr->name1 == ART_TERROR) /* Terror Mask is for warriors... */
3053         {
3054                 if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_ARCHER || p_ptr->pclass == CLASS_CAVALRY || p_ptr->pclass == CLASS_BERSERKER)
3055                 {
3056                         give_power = TRUE;
3057                         give_resistance = TRUE;
3058                 }
3059                 else
3060                 {
3061                         add_flag(o_ptr->art_flags, TR_AGGRAVATE);
3062                         add_flag(o_ptr->art_flags, TR_TY_CURSE);
3063                         o_ptr->curse_flags |=
3064                             (TRC_CURSED | TRC_HEAVY_CURSE);
3065                         o_ptr->curse_flags |= get_curse(2, o_ptr);
3066                         return;
3067                 }
3068         }
3069
3070         if (o_ptr->name1 == ART_MURAMASA)
3071         {
3072                 if (p_ptr->pclass != CLASS_SAMURAI)
3073                 {
3074                         add_flag(o_ptr->art_flags, TR_NO_MAGIC);
3075                         o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3076                 }
3077         }
3078
3079         if (o_ptr->name1 == ART_XIAOLONG)
3080         {
3081                 if (p_ptr->pclass == CLASS_MONK)
3082                         add_flag(o_ptr->art_flags, TR_BLOWS);
3083         }
3084
3085         if (o_ptr->name1 == ART_BLOOD)
3086         {
3087                 get_bloody_moon_flags(o_ptr);
3088         }
3089
3090         if (o_ptr->name1 == ART_HEAVENLY_MAIDEN)
3091         {
3092                 if (p_ptr->psex != SEX_FEMALE)
3093                 {
3094                         add_flag(o_ptr->art_flags, TR_AGGRAVATE);
3095                 }
3096         }
3097
3098         if (a_ptr->gen_flags & (TRG_XTRA_POWER)) give_power = TRUE;
3099         if (a_ptr->gen_flags & (TRG_XTRA_H_RES)) give_resistance = TRUE;
3100         if (a_ptr->gen_flags & (TRG_XTRA_RES_OR_POWER))
3101         {
3102                 /* Give a resistance OR a power */
3103                 if (one_in_(2)) give_resistance = TRUE;
3104                 else give_power = TRUE;
3105         }
3106
3107         if (give_power)
3108         {
3109                 one_ability(o_ptr);
3110         }
3111
3112         if (give_resistance)
3113         {
3114                 one_high_resistance(o_ptr);
3115         }
3116 }
3117
3118
3119 /*
3120  * Create the artifact of the specified number
3121  */
3122 bool create_named_art(int a_idx, int y, int x)
3123 {
3124         object_type forge;
3125         object_type *q_ptr;
3126         int i;
3127
3128         artifact_type *a_ptr = &a_info[a_idx];
3129
3130         /* Get local object */
3131         q_ptr = &forge;
3132
3133         /* Ignore "empty" artifacts */
3134         if (!a_ptr->name) return FALSE;
3135
3136         /* Acquire the "kind" index */
3137         i = lookup_kind(a_ptr->tval, a_ptr->sval);
3138
3139         /* Oops */
3140         if (!i) return FALSE;
3141
3142         /* Create the artifact */
3143         object_prep(q_ptr, i);
3144
3145         /* Save the name */
3146         q_ptr->name1 = a_idx;
3147
3148         /* Extract the fields */
3149         q_ptr->pval = a_ptr->pval;
3150         q_ptr->ac = a_ptr->ac;
3151         q_ptr->dd = a_ptr->dd;
3152         q_ptr->ds = a_ptr->ds;
3153         q_ptr->to_a = a_ptr->to_a;
3154         q_ptr->to_h = a_ptr->to_h;
3155         q_ptr->to_d = a_ptr->to_d;
3156         q_ptr->weight = a_ptr->weight;
3157
3158         /* Hack -- extract the "cursed" flag */
3159         if (a_ptr->gen_flags & TRG_CURSED) q_ptr->curse_flags |= (TRC_CURSED);
3160         if (a_ptr->gen_flags & TRG_HEAVY_CURSE) q_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3161         if (a_ptr->gen_flags & TRG_PERMA_CURSE) q_ptr->curse_flags |= (TRC_PERMA_CURSE);
3162         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) q_ptr->curse_flags |= get_curse(0, q_ptr);
3163         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) q_ptr->curse_flags |= get_curse(1, q_ptr);
3164         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) q_ptr->curse_flags |= get_curse(2, q_ptr);
3165
3166         random_artifact_resistance(q_ptr, a_ptr);
3167
3168         /*
3169          * drop_near()Æâ¤ÇÉáÄ̤θÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤¬½Å¤Ê¤é¤Ê¤¤À­¼Á¤Ë°Í¸¤¹¤ë.
3170          * ²¾¤Ë2¸Ä°Ê¾å¸ºß²Äǽ¤«¤ÄÁõÈ÷Éʰʳ°¤Î¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤¬ºîÀ®¤µ¤ì¤ì¤Ð
3171          * ¤³¤Î´Ø¿ô¤ÎÊÖ¤êÃͤϿ®ÍѤǤ­¤Ê¤¯¤Ê¤ë.
3172          */
3173
3174         /* Drop the artifact from heaven */
3175         return drop_near(q_ptr, -1, y, x) ? TRUE : FALSE;
3176 }