OSDN Git Service

溜まり場に出ていた次のバグらしき挙動を修正。
[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                                 artifact_bias = BIAS_RANGER;
1683                                 warrior_artifact_bias = 30;
1684                                 break;
1685                         case CLASS_PALADIN:
1686                                 artifact_bias = BIAS_PRIESTLY;
1687                                 warrior_artifact_bias = 40;
1688                                 break;
1689                         case CLASS_WARRIOR_MAGE:
1690                         case CLASS_RED_MAGE:
1691                                 artifact_bias = BIAS_MAGE;
1692                                 warrior_artifact_bias = 40;
1693                                 break;
1694                         case CLASS_CHAOS_WARRIOR:
1695                                 artifact_bias = BIAS_CHAOS;
1696                                 warrior_artifact_bias = 40;
1697                                 break;
1698                         case CLASS_MONK:
1699                         case CLASS_FORCETRAINER:
1700                                 artifact_bias = BIAS_PRIESTLY;
1701                                 break;
1702                         case CLASS_MINDCRAFTER:
1703                         case CLASS_BARD:
1704                                 if (randint1(5) > 2) artifact_bias = BIAS_PRIESTLY;
1705                                 break;
1706                         case CLASS_TOURIST:
1707                                 if (randint1(5) > 2) artifact_bias = BIAS_WARRIOR;
1708                                 break;
1709                         case CLASS_IMITATOR:
1710                                 if (randint1(2) > 1) artifact_bias = BIAS_RANGER;
1711                                 break;
1712                         case CLASS_BEASTMASTER:
1713                                 artifact_bias = BIAS_CHR;
1714                                 warrior_artifact_bias = 50;
1715                                 break;
1716                         case CLASS_MIRROR_MASTER:
1717                                 if (randint1(4) > 1) 
1718                                 {
1719                                     artifact_bias = BIAS_MAGE;
1720                                 }
1721                                 else
1722                                 {
1723                                     artifact_bias = BIAS_ROGUE;
1724                                 }
1725                                 break;
1726                 }
1727         }
1728
1729         if (a_scroll && (randint1(100) <= warrior_artifact_bias))
1730                 artifact_bias = BIAS_WARRIOR;
1731
1732         strcpy(new_name, "");
1733
1734         if (!a_scroll && one_in_(A_CURSED))
1735                 a_cursed = TRUE;
1736         if (((o_ptr->tval == TV_AMULET) || (o_ptr->tval == TV_RING)) && object_is_cursed(o_ptr))
1737                 a_cursed = TRUE;
1738
1739         while (one_in_(powers) || one_in_(7) || one_in_(10))
1740                 powers++;
1741
1742         if (!a_cursed && one_in_(WEIRD_LUCK))
1743                 powers *= 2;
1744
1745         if (a_cursed) powers /= 2;
1746
1747         /* Main loop */
1748         while (powers--)
1749         {
1750                 switch (randint1(max_type))
1751                 {
1752                         case 1: case 2:
1753                                 random_plus(o_ptr);
1754                                 has_pval = TRUE;
1755                                 break;
1756                         case 3: case 4:
1757                                 if (one_in_(2) && object_is_weapon_ammo(o_ptr) && (o_ptr->tval != TV_BOW))
1758                                 {
1759                                         if (a_cursed && !one_in_(13)) break;
1760                                         if (one_in_(13))
1761                                         {
1762                                                 if (one_in_(o_ptr->ds+4)) o_ptr->ds++;
1763                                         }
1764                                         else
1765                                         {
1766                                                 if (one_in_(o_ptr->dd+1)) o_ptr->dd++;
1767                                         }
1768                                 }
1769                                 else
1770                                         random_resistance(o_ptr);
1771                                 break;
1772                         case 5:
1773                                 random_misc(o_ptr);
1774                                 break;
1775                         case 6: case 7:
1776                                 random_slay(o_ptr);
1777                                 break;
1778                         default:
1779                                 if (p_ptr->wizard) msg_print("Switch error in create_artifact!");
1780                                 powers++;
1781                 }
1782         };
1783
1784         if (has_pval)
1785         {
1786 #if 0
1787                 add_flag(o_ptr->art_flags, TR_SHOW_MODS);
1788
1789                 /* This one commented out by gw's request... */
1790                 if (!a_scroll)
1791                         add_flag(o_ptr->art_flags, TR_HIDE_TYPE);
1792 #endif
1793
1794                 if (have_flag(o_ptr->art_flags, TR_BLOWS))
1795                 {
1796                         o_ptr->pval = randint1(2);
1797                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
1798                                 o_ptr->pval++;
1799                 }
1800                 else
1801                 {
1802                         do
1803                         {
1804                                 o_ptr->pval++;
1805                         }
1806                         while (o_ptr->pval < randint1(5) || one_in_(o_ptr->pval));
1807                 }
1808
1809                 if ((o_ptr->pval > 4) && !one_in_(WEIRD_LUCK))
1810                         o_ptr->pval = 4;
1811         }
1812
1813         /* give it some plusses... */
1814         if (object_is_armour(o_ptr))
1815                 o_ptr->to_a += randint1(o_ptr->to_a > 19 ? 1 : 20 - o_ptr->to_a);
1816         else if (object_is_weapon_ammo(o_ptr))
1817         {
1818                 o_ptr->to_h += randint1(o_ptr->to_h > 19 ? 1 : 20 - o_ptr->to_h);
1819                 o_ptr->to_d += randint1(o_ptr->to_d > 19 ? 1 : 20 - o_ptr->to_d);
1820                 if ((have_flag(o_ptr->art_flags, TR_WIS)) && (o_ptr->pval > 0)) add_flag(o_ptr->art_flags, TR_BLESSED);
1821         }
1822
1823         /* Just to be sure */
1824         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
1825         add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
1826         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
1827         add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
1828
1829         total_flags = flag_cost(o_ptr, o_ptr->pval);
1830         if (cheat_peek) msg_format("%ld", total_flags);
1831
1832         if (a_cursed) curse_artifact(o_ptr);
1833
1834         if (!a_cursed &&
1835             one_in_(object_is_armour(o_ptr) ? ACTIVATION_CHANCE * 2 : ACTIVATION_CHANCE))
1836         {
1837                 o_ptr->xtra2 = 0;
1838                 give_activation_power(o_ptr);
1839         }
1840
1841         if (object_is_armour(o_ptr))
1842         {
1843                 while ((o_ptr->to_d+o_ptr->to_h) > 20)
1844                 {
1845                         if (one_in_(o_ptr->to_d) && one_in_(o_ptr->to_h)) break;
1846                         o_ptr->to_d -= (s16b)randint0(3);
1847                         o_ptr->to_h -= (s16b)randint0(3);
1848                 }
1849                 while ((o_ptr->to_d+o_ptr->to_h) > 10)
1850                 {
1851                         if (one_in_(o_ptr->to_d) || one_in_(o_ptr->to_h)) break;
1852                         o_ptr->to_d -= (s16b)randint0(3);
1853                         o_ptr->to_h -= (s16b)randint0(3);
1854                 }
1855         }
1856
1857         if (((artifact_bias == BIAS_MAGE) || (artifact_bias == BIAS_INT)) && (o_ptr->tval == TV_GLOVES)) add_flag(o_ptr->art_flags, TR_FREE_ACT);
1858
1859         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI))
1860         {
1861                 o_ptr->to_h = 0;
1862                 o_ptr->to_d = 0;
1863                 remove_flag(o_ptr->art_flags, TR_BLOWS);
1864                 remove_flag(o_ptr->art_flags, TR_FORCE_WEAPON);
1865                 remove_flag(o_ptr->art_flags, TR_SLAY_ANIMAL);
1866                 remove_flag(o_ptr->art_flags, TR_SLAY_EVIL);
1867                 remove_flag(o_ptr->art_flags, TR_SLAY_UNDEAD);
1868                 remove_flag(o_ptr->art_flags, TR_SLAY_DEMON);
1869                 remove_flag(o_ptr->art_flags, TR_SLAY_ORC);
1870                 remove_flag(o_ptr->art_flags, TR_SLAY_TROLL);
1871                 remove_flag(o_ptr->art_flags, TR_SLAY_GIANT);
1872                 remove_flag(o_ptr->art_flags, TR_SLAY_DRAGON);
1873                 remove_flag(o_ptr->art_flags, TR_KILL_DRAGON);
1874                 remove_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
1875                 remove_flag(o_ptr->art_flags, TR_VORPAL);
1876                 remove_flag(o_ptr->art_flags, TR_BRAND_POIS);
1877                 remove_flag(o_ptr->art_flags, TR_BRAND_ACID);
1878                 remove_flag(o_ptr->art_flags, TR_BRAND_ELEC);
1879                 remove_flag(o_ptr->art_flags, TR_BRAND_FIRE);
1880                 remove_flag(o_ptr->art_flags, TR_BRAND_COLD);
1881         }
1882
1883         if (!object_is_weapon_ammo(o_ptr))
1884         {
1885                 /* For armors */
1886                 if (a_cursed) power_level = 0;
1887                 else if (total_flags < 15000) power_level = 1;
1888                 else if (total_flags < 35000) power_level = 2;
1889                 else power_level = 3;
1890         }
1891
1892         else
1893         {
1894                 /* For weapons */
1895                 if (a_cursed) power_level = 0;
1896                 else if (total_flags < 20000) power_level = 1;
1897                 else if (total_flags < 45000) power_level = 2;
1898                 else power_level = 3;
1899         }
1900
1901         if (a_scroll)
1902         {
1903                 char dummy_name[80] = "";
1904 #ifdef JP
1905                 cptr ask_msg = "¤³¤Î¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤ò²¿¤È̾ÉÕ¤±¤Þ¤¹¤«¡©";
1906 #else
1907                 cptr ask_msg = "What do you want to call the artifact? ";
1908 #endif
1909
1910                 /* Identify it fully */
1911                 object_aware(o_ptr);
1912                 object_known(o_ptr);
1913
1914                 /* Mark the item as fully known */
1915                 o_ptr->ident |= (IDENT_MENTAL);
1916
1917                 (void)screen_object(o_ptr, 0L);
1918
1919                 if (!get_string(ask_msg, dummy_name, sizeof dummy_name)
1920                     || !dummy_name[0])
1921                 {
1922                         /* Cancelled */
1923                         if (one_in_(2))
1924                         {
1925                                 get_table_sindarin_aux(dummy_name);
1926                         }
1927                         else
1928                         {
1929                                 get_table_name_aux(dummy_name);
1930                         }
1931                 }
1932
1933 #ifdef JP
1934                 sprintf(new_name, "¡Ô%s¡Õ", dummy_name);
1935 #else
1936                 sprintf(new_name, "'%s'", dummy_name);
1937 #endif
1938
1939                 chg_virtue(V_INDIVIDUALISM, 2);
1940                 chg_virtue(V_ENCHANT, 5);
1941         }
1942         else
1943         {
1944                 get_random_name(new_name, object_is_armour(o_ptr), power_level);
1945         }
1946
1947         if (cheat_xtra)
1948         {
1949 #ifdef JP
1950                 if (artifact_bias) msg_format("±¿¤ÎÊФä¿¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È: %d¡£", artifact_bias);
1951                 else msg_print("¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ë±¿¤ÎÊФê¤Ê¤·¡£");
1952 #else
1953                 if (artifact_bias) msg_format("Biased artifact: %d.", artifact_bias);
1954                 else msg_print("No bias in artifact.");
1955 #endif
1956         }
1957
1958         /* Save the inscription */
1959         o_ptr->art_name = quark_add(new_name);
1960
1961         /* Window stuff */
1962         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1963
1964         return TRUE;
1965 }
1966
1967
1968 bool activate_random_artifact(object_type * o_ptr)
1969 {
1970         int plev = p_ptr->lev;
1971         int k, dir, dummy = 0;
1972
1973         if (!o_ptr->art_name) return FALSE; /* oops? */
1974
1975         /* Activate for attack */
1976         switch (o_ptr->xtra2)
1977         {
1978                 case ACT_SUNLIGHT:
1979                 {
1980                         if (!get_aim_dir(&dir)) return FALSE;
1981 #ifdef JP
1982                         msg_print("ÂÀÍÛ¸÷Àþ¤¬Êü¤¿¤ì¤¿¡£");
1983 #else
1984                         msg_print("A line of sunlight appears.");
1985 #endif
1986
1987                         (void)lite_line(dir);
1988                         o_ptr->timeout = 10;
1989                         break;
1990                 }
1991
1992                 case ACT_BO_MISS_1:
1993                 {
1994 #ifdef JP
1995                         msg_print("¤½¤ì¤ÏâÁ¤·¤¤¤¯¤é¤¤¤ËÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
1996 #else
1997                         msg_print("It glows extremely brightly...");
1998 #endif
1999
2000                         if (!get_aim_dir(&dir)) return FALSE;
2001                         fire_bolt(GF_MISSILE, dir, damroll(2, 6));
2002                         o_ptr->timeout = 2;
2003                         break;
2004                 }
2005
2006                 case ACT_BA_POIS_1:
2007                 {
2008 #ifdef JP
2009                         msg_print("¤½¤ì¤ÏÇ»Î理Ë̮ư¤·¤Æ¤¤¤ë...");
2010 #else
2011                         msg_print("It throbs deep green...");
2012 #endif
2013
2014                         if (!get_aim_dir(&dir)) return FALSE;
2015                         fire_ball(GF_POIS, dir, 12, 3);
2016                         o_ptr->timeout = randint0(4) + 4;
2017                         break;
2018                 }
2019
2020                 case ACT_BO_ELEC_1:
2021                 {
2022 #ifdef JP
2023                         msg_print("¤½¤ì¤Ï²Ð²Ö¤Ëʤ¤ï¤ì¤¿...");
2024 #else
2025                         msg_print("It is covered in sparks...");
2026 #endif
2027
2028                         if (!get_aim_dir(&dir)) return FALSE;
2029                         fire_bolt(GF_ELEC, dir, damroll(4, 8));
2030                         o_ptr->timeout = randint0(5) + 5;
2031                         break;
2032                 }
2033
2034                 case ACT_BO_ACID_1:
2035                 {
2036 #ifdef JP
2037                         msg_print("¤½¤ì¤Ï»À¤Ëʤ¤ï¤ì¤¿...");
2038 #else
2039                         msg_print("It is covered in acid...");
2040 #endif
2041
2042                         if (!get_aim_dir(&dir)) return FALSE;
2043                         fire_bolt(GF_ACID, dir, damroll(5, 8));
2044                         o_ptr->timeout = randint0(6) + 6;
2045                         break;
2046                 }
2047
2048                 case ACT_BO_COLD_1:
2049                 {
2050 #ifdef JP
2051                         msg_print("¤½¤ì¤ÏÁú¤Ëʤ¤ï¤ì¤¿...");
2052 #else
2053                         msg_print("It is covered in frost...");
2054 #endif
2055
2056                         if (!get_aim_dir(&dir)) return FALSE;
2057                         fire_bolt(GF_COLD, dir, damroll(6, 8));
2058                         o_ptr->timeout = randint0(7) + 7;
2059                         break;
2060                 }
2061
2062                 case ACT_BO_FIRE_1:
2063                 {
2064 #ifdef JP
2065                         msg_print("¤½¤ì¤Ï±ê¤Ëʤ¤ï¤ì¤¿...");
2066 #else
2067                         msg_print("It is covered in fire...");
2068 #endif
2069
2070                         if (!get_aim_dir(&dir)) return FALSE;
2071                         fire_bolt(GF_FIRE, dir, damroll(9, 8));
2072                         o_ptr->timeout = randint0(8) + 8;
2073                         break;
2074                 }
2075
2076                 case ACT_BA_COLD_1:
2077                 {
2078 #ifdef JP
2079                         msg_print("¤½¤ì¤ÏÁú¤Ëʤ¤ï¤ì¤¿...");
2080 #else
2081                         msg_print("It is covered in frost...");
2082 #endif
2083
2084                         if (!get_aim_dir(&dir)) return FALSE;
2085                         fire_ball(GF_COLD, dir, 48, 2);
2086                         o_ptr->timeout = 400;
2087                         break;
2088                 }
2089
2090                 case ACT_BA_FIRE_1:
2091                 {
2092 #ifdef JP
2093                         msg_print("¤½¤ì¤ÏÀÖ¤¯·ã¤·¤¯µ±¤¤¤¿...");
2094 #else
2095                         msg_print("It glows an intense red...");
2096 #endif
2097
2098                         if (!get_aim_dir(&dir)) return FALSE;
2099                         fire_ball(GF_FIRE, dir, 72, 2);
2100                         o_ptr->timeout = 400;
2101                         break;
2102                 }
2103
2104                 case ACT_DRAIN_1:
2105                 {
2106 #ifdef JP
2107                         msg_print("¤½¤ì¤Ï¹õ¤¯µ±¤¤¤¿...");
2108 #else
2109                         msg_print("It glows black...");
2110 #endif
2111
2112                         if (!get_aim_dir(&dir)) return FALSE;
2113                         if (drain_life(dir, 100))
2114                         o_ptr->timeout = randint0(100) + 100;
2115                         break;
2116                 }
2117
2118                 case ACT_BA_COLD_2:
2119                 {
2120 #ifdef JP
2121                         msg_print("¤½¤ì¤ÏÀĤ¯·ã¤·¤¯µ±¤¤¤¿...");
2122 #else
2123                         msg_print("It glows an intense blue...");
2124 #endif
2125
2126                         if (!get_aim_dir(&dir)) return FALSE;
2127                         fire_ball(GF_COLD, dir, 100, 2);
2128                         o_ptr->timeout = 300;
2129                         break;
2130                 }
2131
2132                 case ACT_BA_ELEC_2:
2133                 {
2134 #ifdef JP
2135                         msg_print("Åŵ¤¤¬¥Ñ¥Á¥Ñ¥Á²»¤òΩ¤Æ¤¿...");
2136 #else
2137                         msg_print("It crackles with electricity...");
2138 #endif
2139
2140                         if (!get_aim_dir(&dir)) return FALSE;
2141                         fire_ball(GF_ELEC, dir, 100, 3);
2142                         o_ptr->timeout = 500;
2143                         break;
2144                 }
2145
2146                 case ACT_DRAIN_2:
2147                 {
2148 #ifdef JP
2149                         msg_print("¹õ¤¯µ±¤¤¤Æ¤¤¤ë...");
2150 #else
2151                         msg_print("It glows black...");
2152 #endif
2153
2154                         if (!get_aim_dir(&dir)) return FALSE;
2155                         drain_life(dir, 120);
2156                         o_ptr->timeout = 400;
2157                         break;
2158                 }
2159
2160                 case ACT_VAMPIRE_1:
2161                 {
2162                         if (!get_aim_dir(&dir)) return FALSE;
2163                         for (dummy = 0; dummy < 3; dummy++)
2164                         {
2165                                 if (drain_life(dir, 50))
2166                                 hp_player(50);
2167                         }
2168                         o_ptr->timeout = 400;
2169                         break;
2170                 }
2171
2172                 case ACT_BO_MISS_2:
2173                 {
2174 #ifdef JP
2175                         msg_print("ËâË¡¤Î¥È¥²¤¬¸½¤ì¤¿...");
2176 #else
2177                         msg_print("It grows magical spikes...");
2178 #endif
2179
2180                         if (!get_aim_dir(&dir)) return FALSE;
2181                         fire_bolt(GF_ARROW, dir, 150);
2182                         o_ptr->timeout = randint0(90) + 90;
2183                         break;
2184                 }
2185
2186                 case ACT_BA_FIRE_2:
2187                 {
2188 #ifdef JP
2189                         msg_print("¿¼ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2190 #else
2191                         msg_print("It glows deep red...");
2192 #endif
2193
2194                         if (!get_aim_dir(&dir)) return FALSE;
2195                         fire_ball(GF_FIRE, dir, 120, 3);
2196                         o_ptr->timeout = randint0(225) + 225;
2197                         break;
2198                 }
2199
2200                 case ACT_BA_COLD_3:
2201                 {
2202 #ifdef JP
2203                         msg_print("ÌÀ¤ë¤¯Çò¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2204 #else
2205                         msg_print("It glows bright white...");
2206 #endif
2207
2208                         if (!get_aim_dir(&dir)) return FALSE;
2209                         fire_ball(GF_COLD, dir, 200, 3);
2210                         o_ptr->timeout = randint0(325) + 325;
2211                         break;
2212                 }
2213
2214                 case ACT_BA_ELEC_3:
2215                 {
2216 #ifdef JP
2217                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2218 #else
2219                         msg_print("It glows deep blue...");
2220 #endif
2221
2222                         if (!get_aim_dir(&dir)) return FALSE;
2223                         fire_ball(GF_ELEC, dir, 250, 3);
2224                         o_ptr->timeout = randint0(425) + 425;
2225                         break;
2226                 }
2227
2228                 case ACT_WHIRLWIND:
2229                 {
2230                         {
2231                                 int y = 0, x = 0;
2232                                 cave_type       *c_ptr;
2233                                 monster_type    *m_ptr;
2234
2235                                 for (dir = 0; dir <= 9; dir++)
2236                                 {
2237                                         y = py + ddy[dir];
2238                                         x = px + ddx[dir];
2239                                         c_ptr = &cave[y][x];
2240
2241                                         /* Get the monster */
2242                                         m_ptr = &m_list[c_ptr->m_idx];
2243
2244                                         /* Hack -- attack monsters */
2245                                         if (c_ptr->m_idx && (m_ptr->ml || cave_have_flag_bold(y, x, FF_PROJECT)))
2246                                                 py_attack(y, x, 0);
2247                                 }
2248                         }
2249                         o_ptr->timeout = 250;
2250                         break;
2251                 }
2252
2253                 case ACT_VAMPIRE_2:
2254                 {
2255                         if (!get_aim_dir(&dir)) return FALSE;
2256                         for (dummy = 0; dummy < 3; dummy++)
2257                         {
2258                                 if (drain_life(dir, 100))
2259                                 hp_player(100);
2260                         }
2261
2262                         o_ptr->timeout = 400;
2263                         break;
2264                 }
2265
2266
2267                 case ACT_CALL_CHAOS:
2268                 {
2269 #ifdef JP
2270                         msg_print("ÍÍ¡¹¤Ê¿§¤Î²Ð²Ö¤òȯ¤·¤Æ¤¤¤ë...");
2271 #else
2272                         msg_print("It glows in scintillating colours...");
2273 #endif
2274
2275                         call_chaos();
2276                         o_ptr->timeout = 350;
2277                         break;
2278                 }
2279
2280                 case ACT_ROCKET:
2281                 {
2282                         if (!get_aim_dir(&dir)) return FALSE;
2283 #ifdef JP
2284                         msg_print("¥í¥±¥Ã¥È¤òȯ¼Í¤·¤¿¡ª");
2285 #else
2286                         msg_print("You launch a rocket!");
2287 #endif
2288
2289                         fire_ball(GF_ROCKET, dir, 250 + plev*3, 2);
2290                         o_ptr->timeout = 400;
2291                         break;
2292                 }
2293
2294                 case ACT_DISP_EVIL:
2295                 {
2296 #ifdef JP
2297                         msg_print("¿ÀÀ»¤ÊÊ·°Ïµ¤¤¬½¼Ëþ¤·¤¿...");
2298 #else
2299                         msg_print("It floods the area with goodness...");
2300 #endif
2301
2302                         dispel_evil(p_ptr->lev * 5);
2303                         o_ptr->timeout = randint0(300) + 300;
2304                         break;
2305                 }
2306
2307                 case ACT_DISP_GOOD:
2308                 {
2309 #ifdef JP
2310                         msg_print("¼Ù°­¤ÊÊ·°Ïµ¤¤¬½¼Ëþ¤·¤¿...");
2311 #else
2312                         msg_print("It floods the area with evil...");
2313 #endif
2314
2315                         dispel_good(p_ptr->lev * 5);
2316                         o_ptr->timeout = randint0(300) + 300;
2317                         break;
2318                 }
2319
2320                 case ACT_BA_MISS_3:
2321                 {
2322                         if (!get_aim_dir(&dir)) return FALSE;
2323 #ifdef JP
2324                         msg_print("¤¢¤Ê¤¿¤Ï¥¨¥ì¥á¥ó¥È¤Î¥Ö¥ì¥¹¤òÅǤ¤¤¿¡£");
2325 #else
2326                         msg_print("You breathe the elements.");
2327 #endif
2328
2329                         fire_ball(GF_MISSILE, dir, 300, 4);
2330                         o_ptr->timeout = 500;
2331                         break;
2332                 }
2333
2334                 /* Activate for other offensive action */
2335
2336                 case ACT_CONFUSE:
2337                 {
2338 #ifdef JP
2339                         msg_print("ÍÍ¡¹¤Ê¿§¤Î²Ð²Ö¤òȯ¤·¤Æ¤¤¤ë...");
2340 #else
2341                         msg_print("It glows in scintillating colours...");
2342 #endif
2343
2344                         if (!get_aim_dir(&dir)) return FALSE;
2345                         confuse_monster(dir, 20);
2346                         o_ptr->timeout = 15;
2347                         break;
2348                 }
2349
2350                 case ACT_SLEEP:
2351                 {
2352 #ifdef JP
2353                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2354 #else
2355                         msg_print("It glows deep blue...");
2356 #endif
2357
2358                         sleep_monsters_touch();
2359                         o_ptr->timeout = 55;
2360                         break;
2361                 }
2362
2363                 case ACT_QUAKE:
2364                 {
2365                         earthquake(py, px, 10);
2366                         o_ptr->timeout = 50;
2367                         break;
2368                 }
2369
2370                 case ACT_TERROR:
2371                 {
2372                         turn_monsters(40 + p_ptr->lev);
2373                         o_ptr->timeout = 3 * (p_ptr->lev + 10);
2374                         break;
2375                 }
2376
2377                 case ACT_TELE_AWAY:
2378                 {
2379                         if (!get_aim_dir(&dir)) return FALSE;
2380                         (void)fire_beam(GF_AWAY_ALL, dir, plev);
2381                         o_ptr->timeout = 200;
2382                         break;
2383                 }
2384
2385                 case ACT_BANISH_EVIL:
2386                 {
2387                         if (banish_evil(100))
2388                         {
2389 #ifdef JP
2390                                 msg_print("¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤ÎÎϤ¬¼Ù°­¤òÂǤÁʧ¤Ã¤¿¡ª");
2391 #else
2392                                 msg_print("The power of the artifact banishes evil!");
2393 #endif
2394
2395                         }
2396                         o_ptr->timeout = 250 + randint1(250);
2397                         break;
2398                 }
2399
2400                 case ACT_GENOCIDE:
2401                 {
2402 #ifdef JP
2403                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2404 #else
2405                         msg_print("It glows deep blue...");
2406 #endif
2407
2408                         (void)symbol_genocide(200, TRUE);
2409                         o_ptr->timeout = 500;
2410                         break;
2411                 }
2412
2413                 case ACT_MASS_GENO:
2414                 {
2415 #ifdef JP
2416                         msg_print("¤Ò¤É¤¯±Ô¤¤²»¤¬Î®¤ì½Ð¤¿...");
2417 #else
2418                         msg_print("It lets out a long, shrill note...");
2419 #endif
2420
2421                         (void)mass_genocide(200, TRUE);
2422                         o_ptr->timeout = 1000;
2423                         break;
2424                 }
2425
2426                 /* Activate for summoning / charming */
2427
2428                 case ACT_CHARM_ANIMAL:
2429                 {
2430                         if (!get_aim_dir(&dir)) return FALSE;
2431                         (void)charm_animal(dir, plev);
2432                         o_ptr->timeout = 300;
2433                         break;
2434                 }
2435
2436                 case ACT_CHARM_UNDEAD:
2437                 {
2438                         if (!get_aim_dir(&dir)) return FALSE;
2439                         (void)control_one_undead(dir, plev);
2440                         o_ptr->timeout = 333;
2441                         break;
2442                 }
2443
2444                 case ACT_CHARM_OTHER:
2445                 {
2446                         if (!get_aim_dir(&dir)) return FALSE;
2447                         (void)charm_monster(dir, plev);
2448                         o_ptr->timeout = 400;
2449                         break;
2450                 }
2451
2452                 case ACT_CHARM_ANIMALS:
2453                 {
2454                         (void)charm_animals(plev * 2);
2455                         o_ptr->timeout = 500;
2456                         break;
2457                 }
2458
2459                 case ACT_CHARM_OTHERS:
2460                 {
2461                         charm_monsters(plev * 2);
2462                         o_ptr->timeout = 750;
2463                         break;
2464                 }
2465
2466                 case ACT_SUMMON_ANIMAL:
2467                 {
2468                         (void)summon_specific(-1, py, px, plev, SUMMON_ANIMAL_RANGER, (PM_ALLOW_GROUP | PM_FORCE_PET));
2469                         o_ptr->timeout = 200 + randint1(300);
2470                         break;
2471                 }
2472
2473                 case ACT_SUMMON_PHANTOM:
2474                 {
2475 #ifdef JP
2476                         msg_print("¸¸Îî¤ò¾¤´­¤·¤¿¡£");
2477 #else
2478                         msg_print("You summon a phantasmal servant.");
2479 #endif
2480
2481                         (void)summon_specific(-1, py, px, dun_level, SUMMON_PHANTOM, (PM_ALLOW_GROUP | PM_FORCE_PET));
2482                         o_ptr->timeout = 200 + randint1(200);
2483                         break;
2484                 }
2485
2486                 case ACT_SUMMON_ELEMENTAL:
2487                 {
2488                         bool pet = one_in_(3);
2489                         u32b mode = 0L;
2490
2491                         if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
2492                         if (pet) mode |= PM_FORCE_PET;
2493                         else mode |= PM_NO_PET;
2494
2495                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), SUMMON_ELEMENTAL, mode))
2496                         {
2497 #ifdef JP
2498                                 msg_print("¥¨¥ì¥á¥ó¥¿¥ë¤¬¸½¤ì¤¿...");
2499 #else
2500                                 msg_print("An elemental materializes...");
2501 #endif
2502
2503
2504                                 if (pet)
2505 #ifdef JP
2506                                         msg_print("¤¢¤Ê¤¿¤ËÉþ½¾¤·¤Æ¤¤¤ë¤è¤¦¤À¡£");
2507 #else
2508                                         msg_print("It seems obedient to you.");
2509 #endif
2510
2511                                 else
2512 #ifdef JP
2513                                         msg_print("¤½¤ì¤ò¥³¥ó¥È¥í¡¼¥ë¤Ç¤­¤Ê¤«¤Ã¤¿¡ª");
2514 #else
2515                                         msg_print("You fail to control it!");
2516 #endif
2517
2518                         }
2519
2520                         o_ptr->timeout = 750;
2521                         break;
2522                 }
2523
2524                 case ACT_SUMMON_DEMON:
2525                 {
2526                         bool pet = one_in_(3);
2527                         u32b mode = 0L;
2528
2529                         if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
2530                         if (pet) mode |= PM_FORCE_PET;
2531                         else mode |= PM_NO_PET;
2532
2533                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), SUMMON_DEMON, mode))
2534                         {
2535 #ifdef JP
2536                                 msg_print("ⲫ¤Î°­½­¤¬½¼Ëþ¤·¤¿¡£");
2537 #else
2538                                 msg_print("The area fills with a stench of sulphur and brimstone.");
2539 #endif
2540
2541                                 if (pet)
2542 #ifdef JP
2543                                         msg_print("¡Ö¤´ÍѤǤ´¤¶¤¤¤Þ¤¹¤«¡¢¤´¼ç¿ÍÍÍ¡×");
2544 #else
2545                                         msg_print("'What is thy bidding... Master?'");
2546 #endif
2547
2548                                 else
2549 #ifdef JP
2550                                         msg_print("¡ÖNON SERVIAM! Wretch! ¤ªÁ°¤Îº²¤òĺ¤¯¤¾¡ª¡×");
2551 #else
2552                                         msg_print("'NON SERVIAM! Wretch! I shall feast on thy mortal soul!'");
2553 #endif
2554
2555                         }
2556
2557                         o_ptr->timeout = 666 + randint1(333);
2558                         break;
2559                 }
2560
2561                 case ACT_SUMMON_UNDEAD:
2562                 {
2563                         bool pet = one_in_(3);
2564                         int type;
2565                         u32b mode = 0L;
2566
2567                         type = (plev > 47 ? SUMMON_HI_UNDEAD : SUMMON_UNDEAD);
2568
2569                         if (!pet || ((plev > 24) && one_in_(3))) mode |= PM_ALLOW_GROUP;
2570                         if (pet) mode |= PM_FORCE_PET;
2571                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2572
2573                         if (summon_specific((pet ? -1 : 0), py, px, ((plev * 3) / 2), type, mode))
2574                         {
2575 #ifdef JP
2576                                 msg_print("Î䤿¤¤É÷¤¬¤¢¤Ê¤¿¤Î¼þ¤ê¤Ë¿á¤­»Ï¤á¤¿¡£¤½¤ì¤ÏÉåÇÔ½­¤ò±¿¤ó¤Ç¤¤¤ë...");
2577 #else
2578                                 msg_print("Cold winds begin to blow around you, carrying with them the stench of decay...");
2579 #endif
2580
2581                                 if (pet)
2582 #ifdef JP
2583                                         msg_print("¸Å¤¨¤Î»à¤»¤ë¼Ô¶¦¤¬¤¢¤Ê¤¿¤Ë»Å¤¨¤ë¤¿¤áÅÚ¤«¤éᴤä¿¡ª");
2584 #else
2585                                         msg_print("Ancient, long-dead forms arise from the ground to serve you!");
2586 #endif
2587
2588                                 else
2589 #ifdef JP
2590                                         msg_print("»à¼Ô¤¬á´¤Ã¤¿¡£Ì²¤ê¤ò˸¤²¤ë¤¢¤Ê¤¿¤òȳ¤¹¤ë¤¿¤á¤Ë¡ª");
2591 #else
2592                                         msg_print("'The dead arise... to punish you for disturbing them!'");
2593 #endif
2594
2595                         }
2596
2597                         o_ptr->timeout = 666 + randint1(333);
2598                         break;
2599                 }
2600
2601                 /* Activate for healing */
2602
2603                 case ACT_CURE_LW:
2604                 {
2605                         (void)set_afraid(0);
2606                         (void)hp_player(30);
2607                         o_ptr->timeout = 10;
2608                         break;
2609                 }
2610
2611                 case ACT_CURE_MW:
2612                 {
2613 #ifdef JP
2614                         msg_print("¿¼»ç¿§¤Î¸÷¤òȯ¤·¤Æ¤¤¤ë...");
2615 #else
2616                         msg_print("It radiates deep purple...");
2617 #endif
2618
2619                         hp_player(damroll(4, 8));
2620                         (void)set_cut((p_ptr->cut / 2) - 50);
2621                         o_ptr->timeout = randint0(3) + 3;
2622                         break;
2623                 }
2624
2625                 case ACT_CURE_POISON:
2626                 {
2627 #ifdef JP
2628                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2629 #else
2630                         msg_print("It glows deep blue...");
2631 #endif
2632
2633                         (void)set_afraid(0);
2634                         (void)set_poisoned(0);
2635                         o_ptr->timeout = 5;
2636                         break;
2637                 }
2638
2639                 case ACT_REST_LIFE:
2640                 {
2641 #ifdef JP
2642                         msg_print("¿¼¹È¤Ëµ±¤¤¤Æ¤¤¤ë...");
2643 #else
2644                         msg_print("It glows a deep red...");
2645 #endif
2646
2647                         restore_level();
2648                         o_ptr->timeout = 450;
2649                         break;
2650                 }
2651
2652                 case ACT_REST_ALL:
2653                 {
2654 #ifdef JP
2655                         msg_print("Ç»Îп§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2656 #else
2657                         msg_print("It glows a deep green...");
2658 #endif
2659
2660                         (void)do_res_stat(A_STR);
2661                         (void)do_res_stat(A_INT);
2662                         (void)do_res_stat(A_WIS);
2663                         (void)do_res_stat(A_DEX);
2664                         (void)do_res_stat(A_CON);
2665                         (void)do_res_stat(A_CHR);
2666                         (void)restore_level();
2667                         o_ptr->timeout = 750;
2668                         break;
2669                 }
2670
2671                 case ACT_CURE_700:
2672                 {
2673 #ifdef JP
2674                         msg_print("¿¼ÀÄ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2675 #else
2676                         msg_print("It glows deep blue...");
2677 #endif
2678
2679 #ifdef JP
2680                         msg_print("ÂÎÆâ¤ËÃȤ«¤¤¸ÝÆ°¤¬´¶¤¸¤é¤ì¤ë...");
2681 #else
2682                         msg_print("You feel a warm tingling inside...");
2683 #endif
2684
2685                         (void)hp_player(700);
2686                         (void)set_cut(0);
2687                         o_ptr->timeout = 250;
2688                         break;
2689                 }
2690
2691                 case ACT_CURE_1000:
2692                 {
2693 #ifdef JP
2694                         msg_print("Çò¤¯ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2695 #else
2696                         msg_print("It glows a bright white...");
2697 #endif
2698
2699 #ifdef JP
2700                         msg_print("¤Ò¤¸¤ç¤¦¤Ëµ¤Ê¬¤¬¤è¤¤...");
2701 #else
2702                         msg_print("You feel much better...");
2703 #endif
2704
2705                         (void)hp_player(1000);
2706                         (void)set_cut(0);
2707                         o_ptr->timeout = 888;
2708                         break;
2709                 }
2710
2711                 /* Activate for timed effect */
2712
2713                 case ACT_ESP:
2714                 {
2715                         (void)set_tim_esp(randint1(30) + 25, FALSE);
2716                         o_ptr->timeout = 200;
2717                         break;
2718                 }
2719
2720                 case ACT_BERSERK:
2721                 {
2722                         (void)set_afraid(0);
2723                         (void)set_hero(randint1(50) + 50, FALSE);
2724                         (void)set_blessed(randint1(50) + 50, FALSE);
2725                         o_ptr->timeout = 100 + randint1(100);
2726                         break;
2727                 }
2728
2729                 case ACT_PROT_EVIL:
2730                 {
2731 #ifdef JP
2732                         msg_print("±Ô¤¤²»¤¬Î®¤ì½Ð¤¿...");
2733 #else
2734                         msg_print("It lets out a shrill wail...");
2735 #endif
2736
2737                         k = 3 * p_ptr->lev;
2738                         (void)set_protevil(randint1(25) + k, FALSE);
2739                         o_ptr->timeout = randint0(225) + 225;
2740                         break;
2741                 }
2742
2743                 case ACT_RESIST_ALL:
2744                 {
2745 #ifdef JP
2746                         msg_print("ÍÍ¡¹¤Ê¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2747 #else
2748                         msg_print("It glows many colours...");
2749 #endif
2750
2751                         (void)set_oppose_acid(randint1(40) + 40, FALSE);
2752                         (void)set_oppose_elec(randint1(40) + 40, FALSE);
2753                         (void)set_oppose_fire(randint1(40) + 40, FALSE);
2754                         (void)set_oppose_cold(randint1(40) + 40, FALSE);
2755                         (void)set_oppose_pois(randint1(40) + 40, FALSE);
2756                         o_ptr->timeout = 200;
2757                         break;
2758                 }
2759
2760                 case ACT_SPEED:
2761                 {
2762 #ifdef JP
2763                         msg_print("ÌÀ¤ë¤¯Îп§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2764 #else
2765                         msg_print("It glows bright green...");
2766 #endif
2767
2768                         (void)set_fast(randint1(20) + 20, FALSE);
2769                         o_ptr->timeout = 250;
2770                         break;
2771                 }
2772
2773                 case ACT_XTRA_SPEED:
2774                 {
2775 #ifdef JP
2776                         msg_print("ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2777 #else
2778                         msg_print("It glows brightly...");
2779 #endif
2780
2781                         (void)set_fast(randint1(75) + 75, FALSE);
2782                         o_ptr->timeout = randint0(200) + 200;
2783                         break;
2784                 }
2785
2786                 case ACT_WRAITH:
2787                 {
2788                         set_wraith_form(randint1(plev / 2) + (plev / 2), FALSE);
2789                         o_ptr->timeout = 1000;
2790                         break;
2791                 }
2792
2793                 case ACT_INVULN:
2794                 {
2795                         (void)set_invuln(randint1(8) + 8, FALSE);
2796                         o_ptr->timeout = 1000;
2797                         break;
2798                 }
2799
2800                 /* Activate for general purpose effect (detection etc.) */
2801
2802                 case ACT_LIGHT:
2803                 {
2804 #ifdef JP
2805                         msg_print("À¡¤ó¤À¸÷¤¬¤¢¤Õ¤ì½Ð¤¿...");
2806 #else
2807                         msg_print("It wells with clear light...");
2808 #endif
2809
2810                         lite_area(damroll(2, 15), 3);
2811                         o_ptr->timeout = randint0(10) + 10;
2812                         break;
2813                 }
2814
2815                 case ACT_MAP_LIGHT:
2816                 {
2817 #ifdef JP
2818                         msg_print("âÁ¤·¤¯µ±¤¤¤¿...");
2819 #else
2820                         msg_print("It shines brightly...");
2821 #endif
2822
2823                         map_area(DETECT_RAD_MAP);
2824                         lite_area(damroll(2, 15), 3);
2825                         o_ptr->timeout = randint0(50) + 50;
2826                         break;
2827                 }
2828
2829                 case ACT_DETECT_ALL:
2830                 {
2831 #ifdef JP
2832                         msg_print("Çò¤¯ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2833 #else
2834                         msg_print("It glows bright white...");
2835 #endif
2836
2837 #ifdef JP
2838                         msg_print("¿´¤Ë¥¤¥á¡¼¥¸¤¬É⤫¤ó¤Ç¤­¤¿...");
2839 #else
2840                         msg_print("An image forms in your mind...");
2841 #endif
2842
2843                         detect_all(DETECT_RAD_DEFAULT);
2844                         o_ptr->timeout = randint0(55) + 55;
2845                         break;
2846                 }
2847
2848                 case ACT_DETECT_XTRA:
2849                 {
2850 #ifdef JP
2851                         msg_print("ÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2852 #else
2853                         msg_print("It glows brightly...");
2854 #endif
2855
2856                         detect_all(DETECT_RAD_DEFAULT);
2857                         probing();
2858                         identify_fully(FALSE);
2859                         o_ptr->timeout = 1000;
2860                         break;
2861                 }
2862
2863                 case ACT_ID_FULL:
2864                 {
2865 #ifdef JP
2866                         msg_print("²«¿§¤¯µ±¤¤¤Æ¤¤¤ë...");
2867 #else
2868                         msg_print("It glows yellow...");
2869 #endif
2870
2871                         identify_fully(FALSE);
2872                         o_ptr->timeout = 750;
2873                         break;
2874                 }
2875
2876                 case ACT_ID_PLAIN:
2877                 {
2878                         if (!ident_spell(FALSE)) return FALSE;
2879                         o_ptr->timeout = 10;
2880                         break;
2881                 }
2882
2883                 case ACT_RUNE_EXPLO:
2884                 {
2885 #ifdef JP
2886                         msg_print("ÌÀ¤ë¤¤ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2887 #else
2888                         msg_print("It glows bright red...");
2889 #endif
2890
2891                         explosive_rune();
2892                         o_ptr->timeout = 200;
2893                         break;
2894                 }
2895
2896                 case ACT_RUNE_PROT:
2897                 {
2898 #ifdef JP
2899                         msg_print("¥Ö¥ë¡¼¤ËÌÀ¤ë¤¯µ±¤¤¤Æ¤¤¤ë...");
2900 #else
2901                         msg_print("It glows light blue...");
2902 #endif
2903
2904                         warding_glyph();
2905                         o_ptr->timeout = 400;
2906                         break;
2907                 }
2908
2909                 case ACT_SATIATE:
2910                 {
2911                         (void)set_food(PY_FOOD_MAX - 1);
2912                         o_ptr->timeout = 200;
2913                         break;
2914                 }
2915
2916                 case ACT_DEST_DOOR:
2917                 {
2918 #ifdef JP
2919                         msg_print("ÌÀ¤ë¤¤ÀÖ¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2920 #else
2921                         msg_print("It glows bright red...");
2922 #endif
2923
2924                         destroy_doors_touch();
2925                         o_ptr->timeout = 10;
2926                         break;
2927                 }
2928
2929                 case ACT_STONE_MUD:
2930                 {
2931 #ifdef JP
2932                         msg_print("¸ÝÆ°¤·¤Æ¤¤¤ë...");
2933 #else
2934                         msg_print("It pulsates...");
2935 #endif
2936
2937                         if (!get_aim_dir(&dir)) return FALSE;
2938                         wall_to_mud(dir);
2939                         o_ptr->timeout = 5;
2940                         break;
2941                 }
2942
2943                 case ACT_RECHARGE:
2944                 {
2945                         recharge(130);
2946                         o_ptr->timeout = 70;
2947                         break;
2948                 }
2949
2950                 case ACT_ALCHEMY:
2951                 {
2952 #ifdef JP
2953                         msg_print("ÌÀ¤ë¤¤²«¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2954 #else
2955                         msg_print("It glows bright yellow...");
2956 #endif
2957
2958                         (void)alchemy();
2959                         o_ptr->timeout = 500;
2960                         break;
2961                 }
2962
2963                 case ACT_DIM_DOOR:
2964                 {
2965 #ifdef JP
2966                         msg_print("¼¡¸µ¤ÎÈ⤬³«¤¤¤¿¡£ÌÜŪÃϤòÁª¤ó¤Ç²¼¤µ¤¤¡£");
2967 #else
2968                         msg_print("You open a dimensional gate. Choose a destination.");
2969 #endif
2970
2971                         if (!dimension_door()) return FALSE;
2972                         o_ptr->timeout = 100;
2973                         break;
2974                 }
2975
2976
2977                 case ACT_TELEPORT:
2978                 {
2979 #ifdef JP
2980                         msg_print("¼þ¤ê¤Î¶õ´Ö¤¬ÏĤó¤Ç¤¤¤ë...");
2981 #else
2982                         msg_print("It twists space around you...");
2983 #endif
2984
2985                         teleport_player(100, 0L);
2986                         o_ptr->timeout = 45;
2987                         break;
2988                 }
2989
2990                 case ACT_RECALL:
2991                 {
2992 #ifdef JP
2993                         msg_print("¤ä¤ï¤é¤«¤ÊÇò¿§¤Ëµ±¤¤¤Æ¤¤¤ë...");
2994 #else
2995                         msg_print("It glows soft white...");
2996 #endif
2997                         if (!word_of_recall()) return FALSE;
2998                         o_ptr->timeout = 200;
2999                         break;
3000                 }
3001
3002                 default:
3003                 {
3004 #ifdef JP
3005                         msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
3006 #else
3007                         msg_format("Unknown activation effect: %d.", o_ptr->xtra2);
3008 #endif
3009
3010                         return FALSE;
3011                 }
3012         }
3013
3014         return TRUE;
3015 }
3016
3017
3018 void get_bloody_moon_flags(object_type *o_ptr)
3019 {
3020         int dummy, i;
3021
3022         for (i = 0; i < TR_FLAG_SIZE; i++)
3023                 o_ptr->art_flags[i] = a_info[ART_BLOOD].flags[i];
3024
3025         dummy = randint1(2) + randint1(2);
3026         for (i = 0; i < dummy; i++)
3027         {
3028                 int flag = randint0(26);
3029                 if (flag >= 20) add_flag(o_ptr->art_flags, TR_KILL_UNDEAD + flag - 20);
3030                 else if (flag == 19) add_flag(o_ptr->art_flags, TR_KILL_ANIMAL);
3031                 else if (flag == 18) add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
3032                 else add_flag(o_ptr->art_flags, TR_CHAOTIC + flag);
3033         }
3034
3035         dummy = randint1(2);
3036         for (i = 0; i < dummy; i++) one_resistance(o_ptr);
3037
3038         for (i = 0; i < 2; i++)
3039         {
3040                 int tmp = randint0(11);
3041                 if (tmp < 6) add_flag(o_ptr->art_flags, TR_STR + tmp);
3042                 else add_flag(o_ptr->art_flags, TR_STEALTH + tmp - 6);
3043         }
3044 }
3045
3046
3047 void random_artifact_resistance(object_type * o_ptr, artifact_type *a_ptr)
3048 {
3049         bool give_resistance = FALSE, give_power = FALSE;
3050
3051         if (o_ptr->name1 == ART_TERROR) /* Terror Mask is for warriors... */
3052         {
3053                 if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_ARCHER || p_ptr->pclass == CLASS_CAVALRY || p_ptr->pclass == CLASS_BERSERKER)
3054                 {
3055                         give_power = TRUE;
3056                         give_resistance = TRUE;
3057                 }
3058                 else
3059                 {
3060                         add_flag(o_ptr->art_flags, TR_AGGRAVATE);
3061                         add_flag(o_ptr->art_flags, TR_TY_CURSE);
3062                         o_ptr->curse_flags |=
3063                             (TRC_CURSED | TRC_HEAVY_CURSE);
3064                         o_ptr->curse_flags |= get_curse(2, o_ptr);
3065                         return;
3066                 }
3067         }
3068
3069         if (o_ptr->name1 == ART_MURAMASA)
3070         {
3071                 if (p_ptr->pclass != CLASS_SAMURAI)
3072                 {
3073                         add_flag(o_ptr->art_flags, TR_NO_MAGIC);
3074                         o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3075                 }
3076         }
3077
3078         if (o_ptr->name1 == ART_XIAOLONG)
3079         {
3080                 if (p_ptr->pclass == CLASS_MONK)
3081                         add_flag(o_ptr->art_flags, TR_BLOWS);
3082         }
3083
3084         if (o_ptr->name1 == ART_BLOOD)
3085         {
3086                 get_bloody_moon_flags(o_ptr);
3087         }
3088
3089         if (a_ptr->gen_flags & (TRG_XTRA_POWER)) give_power = TRUE;
3090         if (a_ptr->gen_flags & (TRG_XTRA_H_RES)) give_resistance = TRUE;
3091         if (a_ptr->gen_flags & (TRG_XTRA_RES_OR_POWER))
3092         {
3093                 /* Give a resistance OR a power */
3094                 if (one_in_(2)) give_resistance = TRUE;
3095                 else give_power = TRUE;
3096         }
3097
3098         if (give_power)
3099         {
3100                 one_ability(o_ptr);
3101         }
3102
3103         if (give_resistance)
3104         {
3105                 one_high_resistance(o_ptr);
3106         }
3107 }
3108
3109
3110 /*
3111  * Create the artifact of the specified number
3112  */
3113 bool create_named_art(int a_idx, int y, int x)
3114 {
3115         object_type forge;
3116         object_type *q_ptr;
3117         int i;
3118
3119         artifact_type *a_ptr = &a_info[a_idx];
3120
3121         /* Get local object */
3122         q_ptr = &forge;
3123
3124         /* Ignore "empty" artifacts */
3125         if (!a_ptr->name) return FALSE;
3126
3127         /* Acquire the "kind" index */
3128         i = lookup_kind(a_ptr->tval, a_ptr->sval);
3129
3130         /* Oops */
3131         if (!i) return FALSE;
3132
3133         /* Create the artifact */
3134         object_prep(q_ptr, i);
3135
3136         /* Save the name */
3137         q_ptr->name1 = a_idx;
3138
3139         /* Extract the fields */
3140         q_ptr->pval = a_ptr->pval;
3141         q_ptr->ac = a_ptr->ac;
3142         q_ptr->dd = a_ptr->dd;
3143         q_ptr->ds = a_ptr->ds;
3144         q_ptr->to_a = a_ptr->to_a;
3145         q_ptr->to_h = a_ptr->to_h;
3146         q_ptr->to_d = a_ptr->to_d;
3147         q_ptr->weight = a_ptr->weight;
3148
3149         /* Hack -- extract the "cursed" flag */
3150         if (a_ptr->gen_flags & TRG_CURSED) q_ptr->curse_flags |= (TRC_CURSED);
3151         if (a_ptr->gen_flags & TRG_HEAVY_CURSE) q_ptr->curse_flags |= (TRC_HEAVY_CURSE);
3152         if (a_ptr->gen_flags & TRG_PERMA_CURSE) q_ptr->curse_flags |= (TRC_PERMA_CURSE);
3153         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0)) q_ptr->curse_flags |= get_curse(0, q_ptr);
3154         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) q_ptr->curse_flags |= get_curse(1, q_ptr);
3155         if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) q_ptr->curse_flags |= get_curse(2, q_ptr);
3156
3157         random_artifact_resistance(q_ptr, a_ptr);
3158
3159         /*
3160          * drop_near()Æâ¤ÇÉáÄ̤θÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤¬½Å¤Ê¤é¤Ê¤¤À­¼Á¤Ë°Í¸¤¹¤ë.
3161          * ²¾¤Ë2¸Ä°Ê¾å¸ºß²Äǽ¤«¤ÄÁõÈ÷Éʰʳ°¤Î¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤¬ºîÀ®¤µ¤ì¤ì¤Ð
3162          * ¤³¤Î´Ø¿ô¤ÎÊÖ¤êÃͤϿ®ÍѤǤ­¤Ê¤¯¤Ê¤ë.
3163          */
3164
3165         /* Drop the artifact from heaven */
3166         return drop_near(q_ptr, -1, y, x) ? TRUE : FALSE;
3167 }