OSDN Git Service

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