OSDN Git Service

新職業スナイパーといくつかの新or移植アーティファクトをマージ。
[hengband/hengband.git] / src / avatar.c
1 /* File: avatar.c */
2
3 /*
4  * Purpose: Enable an Ultima IV style "avatar" game where you try to
5  * achieve perfection in various virtues.
6  *
7  * Topi Ylinen 1998
8  * f1toyl@uta.fi
9  * topi.ylinen@noodi.fi
10  *
11  */
12
13 /*
14  * Copyright (c) 1989 James E. Wilson, Christopher J. Stuart
15  *
16  * This software may be copied and distributed for educational, research, and
17  * not for profit purposes provided that this copyright and statement are
18  * included in all such copies.
19  */
20
21 #include "angband.h"
22
23
24 /* The names of the virtues */
25
26 cptr virtue[MAX_VIRTUE] =
27 {
28 #ifdef JP
29         "¾ð",
30         "ÍÀ",
31         "Àµ",
32         "µ¾",
33         "¼±",
34         "À¿",
35         "·¼",
36         "Èë",
37         "±¿",
38         "Á³",
39         "Ĵ",
40         "³è",
41         "»à",
42         "Ǧ",
43         "Àá",
44         "¶Ð",
45         "ͦ",
46         "¸Ä",
47 #else
48         "Compassion",
49         "Honour",
50         "Justice",
51         "Sacrifice",
52         "Knowledge",
53         "Faith",
54         "Enlightenment",
55         "Mysticism",
56         "Chance",
57         "Nature",
58         "Harmony",
59         "Vitality",
60         "Unlife",
61         "Patience",
62         "Temperance",
63         "Diligence",
64         "Valour",
65         "Individualism",
66 #endif
67 };
68
69
70 bool compare_virtue(int type, int num, int tekitou)
71 {
72         int vir;
73         if (virtue_number(type))
74                 vir = p_ptr->virtues[virtue_number(type) - 1];
75         else
76                 vir = 0;
77
78         switch (tekitou)
79         {
80         case VIRTUE_LARGE:
81                 if (vir > num) return TRUE;
82                 else return FALSE;
83         case VIRTUE_SMALL:
84                 if (vir < num) return TRUE;
85                 else return FALSE;
86         }
87
88         return FALSE;
89 }
90
91
92 /* Aux function */
93
94 int virtue_number(int type)
95 {
96         int i;
97
98         /* Search */
99         for (i = 0; i < 8; i++)
100         {
101                 if (p_ptr->vir_types[i] == type) return i + 1;
102         }
103
104         /* No match */
105         return 0;
106 }
107
108 /* Aux function */
109
110 static void get_random_virtue(int which)
111 {
112         int type = 0;
113
114         /* Randomly choose a type */
115         while (!(type) || virtue_number(type))
116         {
117                 switch (randint1(29))
118                 {
119                 case 1: case 2: case 3:
120                         type = V_SACRIFICE;
121                         break;
122                 case 4: case 5: case 6:
123                         type = V_COMPASSION;
124                         break;
125                 case 7: case 8: case 9: case 10: case 11: case 12:
126                         type = V_VALOUR;
127                         break;
128                 case 13: case 14: case 15: case 16: case 17:
129                         type = V_HONOUR;
130                         break;
131                 case 18: case 19: case 20: case 21:
132                         type = V_JUSTICE;
133                         break;
134                 case 22: case 23:
135                         type = V_TEMPERANCE;
136                         break;
137                 case 24: case 25:
138                         type = V_HARMONY;
139                         break;
140                 case 26: case 27: case 28:
141                         type = V_PATIENCE;
142                         break;
143                 default:
144                         type = V_DILIGENCE;
145                         break;
146                 }
147         }
148
149         /* Chosen */
150         p_ptr->vir_types[which] = type;
151 }
152
153 static s16b get_realm_virtues(byte realm)
154 {
155         switch (realm)
156         {
157         case REALM_LIFE:
158                 if (virtue_number(V_VITALITY)) return V_TEMPERANCE;
159                 else return V_VITALITY;
160         case REALM_SORCERY:
161                 if (virtue_number(V_KNOWLEDGE)) return V_ENCHANT;
162                 else return V_KNOWLEDGE;
163         case REALM_NATURE:
164                 if (virtue_number(V_NATURE)) return V_HARMONY;
165                 else return V_NATURE;
166         case REALM_CHAOS:
167                 if (virtue_number(V_CHANCE)) return V_INDIVIDUALISM;
168                 else return V_CHANCE;
169         case REALM_DEATH:
170                 return V_UNLIFE;
171         case REALM_TRUMP:
172                 return V_KNOWLEDGE;
173         case REALM_ARCANE:
174                 return 0;
175         case REALM_CRAFT:
176                 if (virtue_number(V_ENCHANT)) return V_INDIVIDUALISM;
177                 else return V_ENCHANT;
178         case REALM_DAEMON:
179                 if (virtue_number(V_JUSTICE)) return V_FAITH;
180                 else return V_JUSTICE;
181         case REALM_CRUSADE:
182                 if (virtue_number(V_JUSTICE)) return V_HONOUR;
183                 else return V_JUSTICE;
184         };
185
186         return 0;
187 }
188
189 /* Select virtues & reset values for a new character */
190
191 void get_virtues(void)
192 {
193         int i = 0, j = 0;
194         s16b tmp_vir;
195
196         /* Reset */
197         for (i = 0; i < 8; i++)
198         {
199                 p_ptr->virtues[i] = 0;
200                 p_ptr->vir_types[i] = 0;
201         }
202
203         i = 0;
204
205         /* Get pre-defined types */
206         /* 1 or more virtues based on class */
207         switch (p_ptr->pclass)
208         {
209         case CLASS_WARRIOR:
210         case CLASS_SAMURAI:
211                 p_ptr->vir_types[i++] = V_VALOUR;
212                 p_ptr->vir_types[i++] = V_HONOUR;
213                 break;
214         case CLASS_MAGE:
215                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
216                 p_ptr->vir_types[i++] = V_ENCHANT;
217                 break;
218         case CLASS_PRIEST:
219                 p_ptr->vir_types[i++] = V_FAITH;
220                 p_ptr->vir_types[i++] = V_TEMPERANCE;
221                 break;
222         case CLASS_ROGUE:
223         case CLASS_SNIPER:
224                 p_ptr->vir_types[i++] = V_HONOUR;
225                 break;
226         case CLASS_RANGER:
227         case CLASS_ARCHER:
228                 p_ptr->vir_types[i++] = V_NATURE;
229                 p_ptr->vir_types[i++] = V_TEMPERANCE;
230                 break;
231         case CLASS_PALADIN:
232                 p_ptr->vir_types[i++] = V_JUSTICE;
233                 p_ptr->vir_types[i++] = V_VALOUR;
234                 p_ptr->vir_types[i++] = V_HONOUR;
235                 p_ptr->vir_types[i++] = V_FAITH;
236                 break;
237         case CLASS_WARRIOR_MAGE:
238         case CLASS_RED_MAGE:
239                 p_ptr->vir_types[i++] = V_ENCHANT;
240                 p_ptr->vir_types[i++] = V_VALOUR;
241                 break;
242         case CLASS_CHAOS_WARRIOR:
243                 p_ptr->vir_types[i++] = V_CHANCE;
244                 p_ptr->vir_types[i++] = V_INDIVIDUALISM;
245                 break;
246         case CLASS_MONK:
247         case CLASS_FORCETRAINER:
248                 p_ptr->vir_types[i++] = V_FAITH;
249                 p_ptr->vir_types[i++] = V_HARMONY;
250                 p_ptr->vir_types[i++] = V_TEMPERANCE;
251                 p_ptr->vir_types[i++] = V_PATIENCE;
252                 break;
253         case CLASS_MINDCRAFTER:
254         case CLASS_MIRROR_MASTER:
255                 p_ptr->vir_types[i++] = V_HARMONY;
256                 p_ptr->vir_types[i++] = V_ENLIGHTEN;
257                 p_ptr->vir_types[i++] = V_PATIENCE;
258                 break;
259         case CLASS_HIGH_MAGE:
260         case CLASS_SORCERER:
261                 p_ptr->vir_types[i++] = V_ENLIGHTEN;
262                 p_ptr->vir_types[i++] = V_ENCHANT;
263                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
264                 break;
265         case CLASS_TOURIST:
266                 p_ptr->vir_types[i++] = V_ENLIGHTEN;
267                 p_ptr->vir_types[i++] = V_CHANCE;
268                 break;
269         case CLASS_IMITATOR:
270                 p_ptr->vir_types[i++] = V_CHANCE;
271                 break;
272         case CLASS_BLUE_MAGE:
273                 p_ptr->vir_types[i++] = V_CHANCE;
274                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
275                 break;
276         case CLASS_BEASTMASTER:
277                 p_ptr->vir_types[i++] = V_NATURE;
278                 p_ptr->vir_types[i++] = V_CHANCE;
279                 p_ptr->vir_types[i++] = V_VITALITY;
280                 break;
281         case CLASS_MAGIC_EATER:
282                 p_ptr->vir_types[i++] = V_ENCHANT;
283                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
284                 break;
285         case CLASS_BARD:
286                 p_ptr->vir_types[i++] = V_HARMONY;
287                 p_ptr->vir_types[i++] = V_COMPASSION;
288                 break;
289         case CLASS_CAVALRY:
290                 p_ptr->vir_types[i++] = V_VALOUR;
291                 p_ptr->vir_types[i++] = V_HARMONY;
292                 break;
293         case CLASS_BERSERKER:
294                 p_ptr->vir_types[i++] = V_VALOUR;
295                 p_ptr->vir_types[i++] = V_INDIVIDUALISM;
296                 break;
297         case CLASS_SMITH:
298                 p_ptr->vir_types[i++] = V_HONOUR;
299                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
300                 break;
301         case CLASS_NINJA:
302                 p_ptr->vir_types[i++] = V_PATIENCE;
303                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
304                 p_ptr->vir_types[i++] = V_FAITH;
305                 p_ptr->vir_types[i++] = V_UNLIFE;
306                 break;
307         };
308
309         /* Get one virtue based on race */
310         switch (p_ptr->prace)
311         {
312         case RACE_HUMAN: case RACE_HALF_ELF: case RACE_DUNADAN:
313                 p_ptr->vir_types[i++] = V_INDIVIDUALISM;
314                 break;
315         case RACE_ELF: case RACE_SPRITE: case RACE_ENT:
316                 p_ptr->vir_types[i++] = V_NATURE;
317                 break;
318         case RACE_HOBBIT: case RACE_HALF_OGRE:
319                 p_ptr->vir_types[i++] = V_TEMPERANCE;
320                 break;
321         case RACE_DWARF: case RACE_KLACKON: case RACE_ANDROID:
322                 p_ptr->vir_types[i++] = V_DILIGENCE;
323                 break;
324         case RACE_GNOME: case RACE_CYCLOPS:
325                 p_ptr->vir_types[i++] = V_KNOWLEDGE;
326                 break;
327         case RACE_HALF_ORC: case RACE_AMBERITE: case RACE_KOBOLD:
328                 p_ptr->vir_types[i++] = V_HONOUR;
329                 break;
330         case RACE_HALF_TROLL: case RACE_BARBARIAN:
331                 p_ptr->vir_types[i++] = V_VALOUR;
332                 break;
333         case RACE_HIGH_ELF: case RACE_KUTA:
334                 p_ptr->vir_types[i++] = V_VITALITY;
335                 break;
336         case RACE_HALF_GIANT: case RACE_GOLEM: case RACE_ANGEL: case RACE_DEMON:
337                 p_ptr->vir_types[i++] = V_JUSTICE;
338                 break;
339         case RACE_HALF_TITAN:
340                 p_ptr->vir_types[i++] = V_HARMONY;
341                 break;
342         case RACE_YEEK:
343                 p_ptr->vir_types[i++] = V_SACRIFICE;
344                 break;
345         case RACE_MIND_FLAYER:
346                 p_ptr->vir_types[i++] = V_ENLIGHTEN;
347                 break;
348         case RACE_DARK_ELF: case RACE_DRACONIAN: case RACE_S_FAIRY:
349                 p_ptr->vir_types[i++] = V_ENCHANT;
350                 break;
351         case RACE_NIBELUNG:
352                 p_ptr->vir_types[i++] = V_PATIENCE;
353                 break;
354         case RACE_IMP:
355                 p_ptr->vir_types[i++] = V_FAITH;
356                 break;
357         case RACE_ZOMBIE: case RACE_SKELETON:
358         case RACE_VAMPIRE: case RACE_SPECTRE:
359                 p_ptr->vir_types[i++] = V_UNLIFE;
360                 break;
361         case RACE_BEASTMAN:
362                 p_ptr->vir_types[i++] = V_CHANCE;
363                 break;
364         }
365
366         /* Get a virtue for realms */
367         if (p_ptr->realm1)
368         {
369                 tmp_vir = get_realm_virtues(p_ptr->realm1);
370                 if (tmp_vir) p_ptr->vir_types[i++] = tmp_vir;
371         }
372         if (p_ptr->realm2)
373         {
374                 tmp_vir = get_realm_virtues(p_ptr->realm2);
375                 if (tmp_vir) p_ptr->vir_types[i++] = tmp_vir;
376         }
377
378         /* Eliminate doubles */
379         for (i = 0; i < 8; i++)
380         {
381                 for (j = i + 1; j < 8; j++)
382                 {
383                         if ((p_ptr->vir_types[j] != 0) && (p_ptr->vir_types[j] == p_ptr->vir_types[i]))
384                                 p_ptr->vir_types[j] = 0;
385                 }
386         }
387
388         /* Fill in the blanks */
389         for (i = 0; i < 8; i++)
390         {
391                 if (p_ptr->vir_types[i] == 0) get_random_virtue(i);
392         }
393 }
394
395 void chg_virtue(int virtue, int amount)
396 {
397         int i = 0;
398
399         for (i = 0; i < 8; i++)
400         {
401                 if (p_ptr->vir_types[i] == virtue)
402                 {
403                         if (amount > 0)
404                         {
405                                 if ((amount + p_ptr->virtues[i] > 50) && one_in_(2))
406                                 {
407                                         p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 50);
408                                         return;
409                                 }
410                                 if ((amount + p_ptr->virtues[i] > 80) && one_in_(2))
411                                 {
412                                         p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 80);
413                                         return;
414                                 }
415                                 if ((amount + p_ptr->virtues[i] > 100) && one_in_(2))
416                                 {
417                                         p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 100);
418                                         return;
419                                 }
420                                 if (amount + p_ptr->virtues[i] > 125)
421                                         p_ptr->virtues[i] = 125;
422                                 else
423                                         p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
424                         }
425                         else
426                         {
427                                 if ((amount + p_ptr->virtues[i] < -50) && one_in_(2))
428                                 {
429                                         p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -50);
430                                         return;
431                                 }
432                                 if ((amount + p_ptr->virtues[i] < -80) && one_in_(2))
433                                 {
434                                         p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -80);
435                                         return;
436                                 }
437                                 if ((amount + p_ptr->virtues[i] < -100) && one_in_(2))
438                                 {
439                                         p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -100);
440                                         return;
441                                 }
442                                 if (amount + p_ptr->virtues[i] < -125)
443                                         p_ptr->virtues[i] = -125;
444                                 else
445                                         p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
446                         }
447                         p_ptr->update |= (PU_BONUS);
448                         return;
449                 }
450         }
451 }
452
453 void set_virtue(int virtue, int amount)
454 {
455         int i = 0;
456
457         for (i = 0; i < 8; i++)
458         {
459                 if (p_ptr->vir_types[i] == virtue)
460                 {
461                         p_ptr->virtues[i] = amount;
462                         return;
463                 }
464         }
465 }
466
467 void dump_virtues(FILE *OutFile)
468 {
469         int v_nr = 0;
470
471         if (!OutFile) return;
472
473         for (v_nr = 0; v_nr < 8; v_nr++)
474         {
475                 char v_name [20];
476                 int tester = p_ptr->virtues[v_nr];
477
478                 strcpy(v_name, virtue[(p_ptr->vir_types[v_nr])-1]);
479
480                 if (p_ptr->vir_types[v_nr] == 0 || p_ptr->vir_types[v_nr] > MAX_VIRTUE)
481 #ifdef JP
482                         fprintf(OutFile, "¤ª¤Ã¤È¡£%s¤Î¾ðÊó¤Ê¤·¡£", v_name);
483 #else
484                         fprintf(OutFile, "Oops. No info about %s.", v_name);
485 #endif
486
487                 else if (tester < -100)
488 #ifdef JP
489                         fprintf(OutFile, "[%s]¤ÎÂжË",
490 #else
491                         fprintf(OutFile, "You are the polar opposite of %s.",
492 #endif
493
494                                 v_name);
495                 else if (tester < -80)
496 #ifdef JP
497                         fprintf(OutFile, "[%s]¤ÎÂçŨ",
498 #else
499                         fprintf(OutFile, "You are an arch-enemy of %s.",
500 #endif
501
502                                 v_name);
503                 else if (tester < -60)
504 #ifdef JP
505                         fprintf(OutFile, "[%s]¤Î¶¯Å¨",
506 #else
507                         fprintf(OutFile, "You are a bitter enemy of %s.",
508 #endif
509
510                                 v_name);
511                 else if (tester < -40)
512 #ifdef JP
513                         fprintf(OutFile, "[%s]¤ÎŨ",
514 #else
515                         fprintf(OutFile, "You are an enemy of %s.",
516 #endif
517
518                                 v_name);
519                 else if (tester < -20)
520 #ifdef JP
521                         fprintf(OutFile, "[%s]¤Îºá¼Ô",
522 #else
523                         fprintf(OutFile, "You have sinned against %s.",
524 #endif
525
526                                 v_name);
527                 else if (tester < 0)
528 #ifdef JP
529                         fprintf(OutFile, "[%s]¤ÎÌÂÆ»¼Ô",
530 #else
531                         fprintf(OutFile, "You have strayed from the path of %s.",
532 #endif
533
534                                 v_name);
535                 else if (tester == 0)
536 #ifdef JP
537                         fprintf(OutFile,"[%s]¤ÎÃæΩ¼Ô",
538 #else
539                         fprintf(OutFile,"You are neutral to %s.",
540 #endif
541
542                                 v_name);
543                 else if (tester < 20)
544 #ifdef JP
545                         fprintf(OutFile,"[%s]¤Î¾®ÆÁ¼Ô",
546 #else
547                         fprintf(OutFile,"You are somewhat virtuous in %s.",
548 #endif
549
550                                 v_name);
551                 else if (tester < 40)
552 #ifdef JP
553                         fprintf(OutFile,"[%s]¤ÎÃæÆÁ¼Ô",
554 #else
555                         fprintf(OutFile,"You are virtuous in %s.",
556 #endif
557
558                                 v_name);
559                 else if (tester < 60)
560 #ifdef JP
561                         fprintf(OutFile,"[%s]¤Î¹âÆÁ¼Ô",
562 #else
563                         fprintf(OutFile,"You are very virtuous in %s.",
564 #endif
565
566                                 v_name);
567                 else if (tester < 80)
568 #ifdef JP
569                         fprintf(OutFile,"[%s]¤ÎÇƼÔ",
570 #else
571                         fprintf(OutFile,"You are a champion of %s.",
572 #endif
573
574                                 v_name);
575                 else if (tester < 100)
576 #ifdef JP
577                         fprintf(OutFile,"[%s]¤Î°ÎÂç¤ÊÇƼÔ",
578 #else
579                         fprintf(OutFile,"You are a great champion of %s.",
580 #endif
581
582                                 v_name);
583                 else
584 #ifdef JP
585                         fprintf(OutFile,"[%s]¤Î¶ñ¸½¼Ô",
586 #else
587                         fprintf(OutFile,"You are the living embodiment of %s.",
588 #endif
589
590                                 v_name);
591
592             fprintf(OutFile, "\n");
593         }
594 }