OSDN Git Service

b150844e3632afa381eeb65a3e4fcf0175ef38d6
[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 #else
31   "Compassion",
32 #endif
33
34 #ifdef JP
35   "ÍÀ",
36 #else
37   "Honour",
38 #endif
39
40 #ifdef JP
41   "Àµ",
42 #else
43   "Justice",
44 #endif
45
46 #ifdef JP
47   "µ¾",
48 #else
49   "Sacrifice",
50 #endif
51
52 #ifdef JP
53   "¼±",
54 #else
55   "Knowledge",
56 #endif
57
58 #ifdef JP
59   "À¿",
60 #else
61   "Faith",
62 #endif
63
64 #ifdef JP
65   "·¼",
66 #else
67   "Enlightenment",
68 #endif
69
70 #ifdef JP
71   "Èë",
72 #else
73   "Mysticism",
74 #endif
75
76 #ifdef JP
77   "±¿",
78 #else
79   "Chance",
80 #endif
81
82 #ifdef JP
83 "Á³",
84 #else
85   "Nature",
86 #endif
87
88 #ifdef JP
89   "Ĵ",
90 #else
91   "Harmony",
92 #endif
93
94 #ifdef JP
95   "³è",
96 #else
97   "Vitality",
98 #endif
99
100 #ifdef JP
101   "»à",
102 #else
103   "Unlife",
104 #endif
105
106 #ifdef JP
107   "Ǧ",
108 #else
109   "Patience",
110 #endif
111
112 #ifdef JP
113   "Àá",
114 #else
115   "Temperance",
116 #endif
117
118 #ifdef JP
119   "¶Ð",
120 #else
121   "Diligence",
122 #endif
123
124 #ifdef JP
125   "ͦ",
126 #else
127   "Valour",
128 #endif
129
130 #ifdef JP
131   "¸Ä",
132 #else
133   "Individualism",
134 #endif
135
136 };
137
138
139 bool compare_virtue(int type, int num, int tekitou)
140 {
141   int vir;
142   if (virtue_number(type))
143     vir = p_ptr->virtues[virtue_number(type)-1];
144   else
145     vir = 0;
146
147   switch(tekitou)
148     {
149     case VIRTUE_LARGE:
150       if (vir > num) return TRUE;
151       else return FALSE;
152       break;
153     case VIRTUE_SMALL:
154       if (vir < num) return TRUE;
155       else return FALSE;
156       break;
157     default:
158       break;
159     }
160   return FALSE;
161 }
162
163
164 /* Aux function */
165
166 int virtue_number(int type)
167 {
168  int i;
169
170  /* Search */
171  for (i = 0; i < 8; i++)
172  {
173   if (p_ptr->vir_types[i] == type) return i+1;
174  }
175
176
177  /* No match */
178  return 0;
179
180 }
181
182 /* Aux function */
183
184 static void get_random_virtue(int which)
185 {
186   int type = 0;
187
188   /* Randomly choose a type */
189   while (!(type) || virtue_number(type))
190   {
191    switch (randint1(29))
192    {
193         case 1: case 2: case 3:
194               type = V_SACRIFICE;
195               break;
196         case 4: case 5: case 6:
197                 type = V_COMPASSION;
198                 break;
199         case 7: case 8: case 9: case 10: case 11: case 12:
200                 type = V_VALOUR;
201                 break;
202         case 13: case 14: case 15: case 16: case 17:
203                 type = V_HONOUR;
204                 break;
205         case 18: case 19: case 20: case 21:
206                 type = V_JUSTICE;
207                 break;
208         case 22: case 23:
209                 type = V_TEMPERANCE;
210                 break;
211         case 24: case 25:
212                 type = V_HARMONY;
213                 break;
214         case 26: case 27: case 28:
215                 type = V_PATIENCE;
216                 break;
217         default:
218                 type = V_DILIGENCE;
219    }
220   }
221
222   /* Chosen */
223
224   p_ptr->vir_types[which] = type;
225
226 }
227
228 /* Select virtues & reset values for a new character */
229
230 void get_virtues(void)
231 {
232    int i = 0, j = 0;
233
234    /* Reset */
235    for (i = 0; i < 8; i++)
236    {
237      p_ptr->virtues[i]=0;
238      p_ptr->vir_types[i]=0;
239    }
240
241    i = 0;
242
243    /* Get pre-defined types */
244    /* 1 or more virtues based on class */
245    switch (p_ptr->pclass)
246    {
247     case CLASS_WARRIOR:
248     case CLASS_SAMURAI:
249       p_ptr->vir_types[i++] = V_VALOUR;
250       p_ptr->vir_types[i++] = V_HONOUR;
251       break;
252     case CLASS_MAGE:
253       p_ptr->vir_types[i++] = V_KNOWLEDGE;
254       p_ptr->vir_types[i++] = V_ENCHANT;
255       break;
256     case CLASS_PRIEST:
257       p_ptr->vir_types[i++] = V_FAITH;
258       p_ptr->vir_types[i++] = V_TEMPERANCE;
259       break;
260     case CLASS_ROGUE:
261       p_ptr->vir_types[i++] = V_HONOUR;
262       break;
263     case CLASS_RANGER:
264     case CLASS_ARCHER:
265       p_ptr->vir_types[i++] = V_NATURE;
266       p_ptr->vir_types[i++] = V_TEMPERANCE;
267       break;
268     case CLASS_PALADIN:
269       p_ptr->vir_types[i++] = V_JUSTICE;
270       p_ptr->vir_types[i++] = V_VALOUR;
271       p_ptr->vir_types[i++] = V_HONOUR;
272       p_ptr->vir_types[i++] = V_FAITH;
273       break;
274     case CLASS_WARRIOR_MAGE:
275     case CLASS_RED_MAGE:
276       p_ptr->vir_types[i++] = V_ENCHANT;
277       p_ptr->vir_types[i++] = V_VALOUR;
278       break;
279     case CLASS_CHAOS_WARRIOR:
280       p_ptr->vir_types[i++] = V_CHANCE;
281       p_ptr->vir_types[i++] = V_INDIVIDUALISM;
282       break;
283     case CLASS_MONK:
284     case CLASS_FORCETRAINER:
285       p_ptr->vir_types[i++] = V_FAITH;
286       p_ptr->vir_types[i++] = V_HARMONY;
287       p_ptr->vir_types[i++] = V_TEMPERANCE;
288       p_ptr->vir_types[i++] = V_PATIENCE;
289       break;
290     case CLASS_MINDCRAFTER:
291     case CLASS_MIRROR_MASTER:
292       p_ptr->vir_types[i++] = V_HARMONY;
293       p_ptr->vir_types[i++] = V_ENLIGHTEN;
294       p_ptr->vir_types[i++] = V_PATIENCE;
295       break;
296     case CLASS_HIGH_MAGE:
297     case CLASS_SORCERER:
298       p_ptr->vir_types[i++] = V_ENLIGHTEN;
299       p_ptr->vir_types[i++] = V_ENCHANT;
300       p_ptr->vir_types[i++] = V_KNOWLEDGE;
301       break;
302     case CLASS_TOURIST:
303       p_ptr->vir_types[i++] = V_ENLIGHTEN;
304       p_ptr->vir_types[i++] = V_CHANCE;
305       break;
306     case CLASS_IMITATOR:
307       p_ptr->vir_types[i++] = V_CHANCE;
308       break;
309     case CLASS_BLUE_MAGE:
310       p_ptr->vir_types[i++] = V_CHANCE;
311       p_ptr->vir_types[i++] = V_KNOWLEDGE;
312       break;
313     case CLASS_BEASTMASTER:
314       p_ptr->vir_types[i++] = V_NATURE;
315       p_ptr->vir_types[i++] = V_CHANCE;
316       p_ptr->vir_types[i++] = V_VITALITY;
317       break;
318     case CLASS_MAGIC_EATER:
319       p_ptr->vir_types[i++] = V_ENCHANT;
320       p_ptr->vir_types[i++] = V_KNOWLEDGE;
321       break;
322     case CLASS_BARD:
323       p_ptr->vir_types[i++] = V_HARMONY;
324       p_ptr->vir_types[i++] = V_COMPASSION;
325       break;
326     case CLASS_CAVALRY:
327       p_ptr->vir_types[i++] = V_VALOUR;
328       p_ptr->vir_types[i++] = V_HARMONY;
329       break;
330     case CLASS_BERSERKER:
331       p_ptr->vir_types[i++] = V_VALOUR;
332       p_ptr->vir_types[i++] = V_INDIVIDUALISM;
333       break;
334     case CLASS_SMITH:
335       p_ptr->vir_types[i++] = V_HONOUR;
336       p_ptr->vir_types[i++] = V_KNOWLEDGE;
337       break;
338     case CLASS_NINJA:
339       p_ptr->vir_types[i++] = V_PATIENCE;
340       p_ptr->vir_types[i++] = V_KNOWLEDGE;
341       p_ptr->vir_types[i++] = V_FAITH;
342       p_ptr->vir_types[i++] = V_UNLIFE;
343       break;
344
345    };
346
347
348    /* Get one virtue based on race */
349    switch (p_ptr->prace)
350    {
351    case RACE_HUMAN: case RACE_HALF_ELF: case RACE_DUNADAN:
352      p_ptr->vir_types[i++] = V_INDIVIDUALISM;
353      break;
354    case RACE_ELF: case RACE_SPRITE: case RACE_ENT:
355      p_ptr->vir_types[i++] = V_NATURE;
356      break;
357    case RACE_HOBBIT: case RACE_HALF_OGRE:
358      p_ptr->vir_types[i++] = V_TEMPERANCE;
359      break;
360    case RACE_DWARF: case RACE_KLACKON: case RACE_ANDROID:
361      p_ptr->vir_types[i++] = V_DILIGENCE;
362      break;
363    case RACE_GNOME: case RACE_CYCLOPS:
364      p_ptr->vir_types[i++] = V_KNOWLEDGE;
365      break;
366    case RACE_HALF_ORC: case RACE_AMBERITE: case RACE_KOBOLD:
367      p_ptr->vir_types[i++] = V_HONOUR;
368      break;
369    case RACE_HALF_TROLL: case RACE_BARBARIAN:
370      p_ptr->vir_types[i++] = V_VALOUR;
371      break;
372    case RACE_HIGH_ELF: case RACE_KUTA:
373      p_ptr->vir_types[i++] = V_VITALITY;
374      break;
375    case RACE_HALF_GIANT: case RACE_GOLEM: case RACE_ANGEL: case RACE_DEMON:
376      p_ptr->vir_types[i++] = V_JUSTICE;
377      break;
378    case RACE_HALF_TITAN:
379      p_ptr->vir_types[i++] = V_HARMONY;
380      break;
381    case RACE_YEEK:
382      p_ptr->vir_types[i++] = V_SACRIFICE;
383      break;
384    case RACE_MIND_FLAYER:
385      p_ptr->vir_types[i++] = V_ENLIGHTEN;
386      break;
387    case RACE_DARK_ELF: case RACE_DRACONIAN: case RACE_S_FAIRY:
388      p_ptr->vir_types[i++] = V_ENCHANT;
389      break;
390    case RACE_NIBELUNG:
391      p_ptr->vir_types[i++] = V_PATIENCE;
392      break;
393    case RACE_IMP:
394      p_ptr->vir_types[i++] = V_FAITH;
395      break;
396    case RACE_ZOMBIE: case RACE_SKELETON:
397    case RACE_VAMPIRE: case RACE_SPECTRE:
398      p_ptr->vir_types[i++] = V_UNLIFE;
399      break;
400    case RACE_BEASTMAN:
401      p_ptr->vir_types[i++] = V_CHANCE;
402      break;
403    }     
404
405    /* Get a virtue for realm1 */
406    if (p_ptr->realm1)
407    {
408     switch(p_ptr->realm1)
409     {
410         case REALM_LIFE:
411          if (virtue_number(V_VITALITY))
412           p_ptr->vir_types[i++] = V_TEMPERANCE;
413          else p_ptr->vir_types[i++] = V_VITALITY;
414         break;
415         case REALM_SORCERY:
416          if (virtue_number(V_KNOWLEDGE))
417           p_ptr->vir_types[i++] = V_ENCHANT;
418          else p_ptr->vir_types[i++] = V_KNOWLEDGE;
419         break;
420         case REALM_NATURE:
421          if (virtue_number(V_NATURE))
422           p_ptr->vir_types[i++] = V_HARMONY;
423          else p_ptr->vir_types[i++] = V_NATURE;
424         break;
425         case REALM_CHAOS:
426          if (virtue_number(V_CHANCE))
427           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
428          else p_ptr->vir_types[i++] = V_CHANCE;
429         break;
430         case REALM_DEATH:
431          p_ptr->vir_types[i++] = V_UNLIFE;
432         break;
433         case REALM_TRUMP:
434          p_ptr->vir_types[i++] = V_KNOWLEDGE;
435         break;
436         case REALM_ARCANE:
437         break;
438         case REALM_ENCHANT:
439          if (virtue_number(V_ENCHANT))
440           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
441          else p_ptr->vir_types[i++] = V_ENCHANT;
442         break;
443         case REALM_DAEMON:
444          if (virtue_number(V_JUSTICE))
445           p_ptr->vir_types[i++] = V_FAITH;
446          else p_ptr->vir_types[i++] = V_JUSTICE;
447         break;
448         case REALM_CRUSADE:
449          if (virtue_number(V_JUSTICE))
450           p_ptr->vir_types[i++] = V_HONOUR;
451          else p_ptr->vir_types[i++] = V_JUSTICE;
452         break;
453      };
454     }
455
456    /* Get a virtue for realm2 */
457
458    if (p_ptr->realm2)
459    {
460     switch(p_ptr->realm2)
461     {
462         case REALM_LIFE:
463          if (virtue_number(V_VITALITY))
464           p_ptr->vir_types[i++] = V_TEMPERANCE;
465          else p_ptr->vir_types[i++] = V_VITALITY;
466         break;
467         case REALM_SORCERY:
468          if (virtue_number(V_ENCHANT))
469           p_ptr->vir_types[i++] = V_KNOWLEDGE;
470          else p_ptr->vir_types[i++] = V_ENCHANT;
471         break;
472         case REALM_NATURE:
473          if (virtue_number(V_NATURE))
474           p_ptr->vir_types[i++] = V_HARMONY;
475          else p_ptr->vir_types[i++] = V_NATURE;
476         break;
477         case REALM_CHAOS:
478          if (virtue_number(V_CHANCE))
479           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
480          else p_ptr->vir_types[i++] = V_CHANCE;
481         break;
482         case REALM_DEATH:
483          p_ptr->vir_types[i++] = V_UNLIFE;
484         break;
485         case REALM_TRUMP:
486          p_ptr->vir_types[i++] = V_KNOWLEDGE;
487         break;
488         case REALM_ARCANE:
489         break;
490         case REALM_ENCHANT:
491          if (virtue_number(V_ENCHANT))
492           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
493          else p_ptr->vir_types[i++] = V_ENCHANT;
494         break;
495         case REALM_DAEMON:
496          if (virtue_number(V_JUSTICE))
497           p_ptr->vir_types[i++] = V_FAITH;
498          else p_ptr->vir_types[i++] = V_JUSTICE;
499         break;
500         case REALM_CRUSADE:
501          if (virtue_number(V_JUSTICE))
502           p_ptr->vir_types[i++] = V_HONOUR;
503          else p_ptr->vir_types[i++] = V_JUSTICE;
504         break;
505      };
506     }
507
508    /* Eliminate doubles */
509    for (i = 0; i < 8; i++)
510    {
511     for (j = i+1; j < 8; j++)
512     {
513      if ((p_ptr->vir_types[j] != 0)
514       && (p_ptr->vir_types[j] == p_ptr->vir_types[i]))
515        p_ptr->vir_types[j] = 0;
516     }
517    }
518
519    /* Fill in the blanks */
520
521    for (i = 0; i < 8; i++)
522    {
523     if (p_ptr->vir_types[i]==0) get_random_virtue(i);
524    }
525 }
526
527 void chg_virtue(int virtue, int amount)
528 {
529     int i = 0;
530
531     for (i = 0; i < 8; i++)
532     {
533         if (p_ptr->vir_types[i] == virtue)
534         {
535             if (amount > 0)
536             {
537                 if ((amount + p_ptr->virtues[i] > 50) && one_in_(2))
538                 {
539                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 50);
540                     return;
541                 }
542                 if ((amount + p_ptr->virtues[i] > 80) && one_in_(2))
543                 {
544                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 80);
545                     return;
546                 }
547                 if ((amount + p_ptr->virtues[i] > 100) && one_in_(2))
548                 {
549                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 100);
550                     return;
551                 }
552                 if (amount + p_ptr->virtues[i] > 125)
553                  p_ptr->virtues[i] = 125;
554                 else
555                  p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
556             }
557             else
558             {
559                 if ((amount + p_ptr->virtues[i] < -50) && one_in_(2))
560                 {
561                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -50);
562                     return;
563                 }
564                 if ((amount + p_ptr->virtues[i] < -80) && one_in_(2))
565                 {
566                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -80);
567                     return;
568                 }
569                 if ((amount + p_ptr->virtues[i] < -100) && one_in_(2))
570                 {
571                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -100);
572                     return;
573                 }
574                 if (amount + p_ptr->virtues[i] < -125)
575                  p_ptr->virtues[i] = -125;
576                 else
577                  p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
578             }
579             p_ptr->update |= (PU_BONUS);
580             return;
581         }
582     }
583
584 }
585
586 void set_virtue(int virtue, int amount)
587 {
588     int i = 0;
589
590     for (i = 0; i < 8; i++)
591     {
592         if (p_ptr->vir_types[i] == virtue)
593         {
594             p_ptr->virtues[i] = amount;
595             return;
596         }
597     }
598 }
599
600 void dump_virtues(FILE * OutFile)
601 {
602     int v_nr = 0;
603
604     if (!OutFile) return;
605
606         for (v_nr = 0; v_nr < 8; v_nr++)
607         {
608                 char v_name [20];
609
610                 int tester = p_ptr->virtues[v_nr];
611
612                 strcpy(v_name, virtue[(p_ptr->vir_types[v_nr])-1]);
613
614                 if (p_ptr->vir_types[v_nr] == 0 || p_ptr->vir_types[v_nr] >
615                     MAX_VIRTUE)
616 #ifdef JP
617                  fprintf(OutFile, "¤ª¤Ã¤È¡£%s¤Î¾ðÊó¤Ê¤·¡£", v_name);
618 #else
619                  fprintf(OutFile, "Oops. No info about %s.", v_name);
620 #endif
621
622                 else if (tester < -100)
623 #ifdef JP
624                   fprintf(OutFile, "[%s]¤ÎÂжË",
625 #else
626                   fprintf(OutFile, "You are the polar opposite of %s.",
627 #endif
628
629                    v_name);
630                 else if (tester < -80)
631 #ifdef JP
632                   fprintf(OutFile, "[%s]¤ÎÂçŨ",
633 #else
634                   fprintf(OutFile, "You are an arch-enemy of %s.",
635 #endif
636
637                    v_name);
638                 else if (tester < -60)
639 #ifdef JP
640                   fprintf(OutFile, "[%s]¤Î¶¯Å¨",
641 #else
642                   fprintf(OutFile, "You are a bitter enemy of %s.",
643 #endif
644
645                    v_name);
646                 else if (tester < -40)
647 #ifdef JP
648                   fprintf(OutFile, "[%s]¤ÎŨ",
649 #else
650                   fprintf(OutFile, "You are an enemy of %s.",
651 #endif
652
653                    v_name);
654                 else if (tester < -20)
655 #ifdef JP
656                   fprintf(OutFile, "[%s]¤Îºá¼Ô",
657 #else
658                   fprintf(OutFile, "You have sinned against %s.",
659 #endif
660
661                    v_name);
662                 else if (tester < 0)
663 #ifdef JP
664                   fprintf(OutFile, "[%s]¤ÎÌÂÆ»¼Ô",
665 #else
666                   fprintf(OutFile, "You have strayed from the path of %s.",
667 #endif
668
669                    v_name);
670                 else if (tester == 0)                   
671 #ifdef JP
672                   fprintf(OutFile,"[%s]¤ÎÃæΩ¼Ô",
673 #else
674                   fprintf(OutFile,"You are neutral to %s.",
675 #endif
676
677                    v_name);
678                 else if (tester < 20)
679 #ifdef JP
680                   fprintf(OutFile,"[%s]¤Î¾®ÆÁ¼Ô",
681 #else
682                   fprintf(OutFile,"You are somewhat virtuous in %s.",
683 #endif
684
685                    v_name);
686                 else if (tester < 40)
687 #ifdef JP
688                   fprintf(OutFile,"[%s]¤ÎÃæÆÁ¼Ô",
689 #else
690                   fprintf(OutFile,"You are virtuous in %s.",
691 #endif
692
693                    v_name);
694                 else if (tester < 60)
695 #ifdef JP
696                   fprintf(OutFile,"[%s]¤Î¹âÆÁ¼Ô",
697 #else
698                   fprintf(OutFile,"You are very virtuous in %s.",
699 #endif
700
701                    v_name);
702                 else if (tester < 80)
703 #ifdef JP
704                   fprintf(OutFile,"[%s]¤ÎÇƼÔ",
705 #else
706                   fprintf(OutFile,"You are a champion of %s.",
707 #endif
708
709                    v_name);
710                 else if (tester < 100)
711 #ifdef JP
712                   fprintf(OutFile,"[%s]¤Î°ÎÂç¤ÊÇƼÔ",
713 #else
714                   fprintf(OutFile,"You are a great champion of %s.",
715 #endif
716
717                    v_name);
718                 else
719 #ifdef JP
720                   fprintf(OutFile,"[%s]¤Î¶ñ¸½¼Ô",
721 #else
722                   fprintf(OutFile,"You are the living embodiment of %s.",
723 #endif
724
725                    v_name);
726
727             fprintf(OutFile, "\n");
728         }
729
730
731 }
732