OSDN Git Service

Initial revision
[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 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 (randint(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()
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_FAITH))
412           p_ptr->vir_types[i++] = V_VITALITY;
413          else p_ptr->vir_types[i++] = V_FAITH;
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      };
449     }
450
451    /* Get a virtue for realm2 */
452
453    if (p_ptr->realm2)
454    {
455     switch(p_ptr->realm2)
456     {
457         case REALM_LIFE:
458          if (virtue_number(V_FAITH))
459           p_ptr->vir_types[i++] = V_VITALITY;
460          else p_ptr->vir_types[i++] = V_FAITH;
461         break;
462         case REALM_SORCERY:
463          if (virtue_number(V_ENCHANT))
464           p_ptr->vir_types[i++] = V_KNOWLEDGE;
465          else p_ptr->vir_types[i++] = V_ENCHANT;
466         break;
467         case REALM_NATURE:
468          if (virtue_number(V_NATURE))
469           p_ptr->vir_types[i++] = V_HARMONY;
470          else p_ptr->vir_types[i++] = V_NATURE;
471         break;
472         case REALM_CHAOS:
473          if (virtue_number(V_CHANCE))
474           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
475          else p_ptr->vir_types[i++] = V_CHANCE;
476         break;
477         case REALM_DEATH:
478          p_ptr->vir_types[i++] = V_UNLIFE;
479         break;
480         case REALM_TRUMP:
481          p_ptr->vir_types[i++] = V_KNOWLEDGE;
482         break;
483         case REALM_ARCANE:
484         break;
485         case REALM_ENCHANT:
486          if (virtue_number(V_ENCHANT))
487           p_ptr->vir_types[i++] = V_INDIVIDUALISM;
488          else p_ptr->vir_types[i++] = V_ENCHANT;
489         break;
490         case REALM_DAEMON:
491          if (virtue_number(V_JUSTICE))
492           p_ptr->vir_types[i++] = V_FAITH;
493          else p_ptr->vir_types[i++] = V_JUSTICE;
494         break;
495      };
496     }
497
498    /* Eliminate doubles */
499    for (i = 0; i < 8; i++)
500    {
501     for (j = i+1; j < 8; j++)
502     {
503      if ((p_ptr->vir_types[j] != 0)
504       && (p_ptr->vir_types[j] == p_ptr->vir_types[i]))
505        p_ptr->vir_types[j] = 0;
506     }
507    }
508
509    /* Fill in the blanks */
510
511    for (i = 0; i < 8; i++)
512    {
513     if (p_ptr->vir_types[i]==0) get_random_virtue(i);
514    }
515 }
516
517 void chg_virtue(int virtue, int amount)
518 {
519     int i = 0;
520
521     for (i = 0; i < 8; i++)
522     {
523         if (p_ptr->vir_types[i] == virtue)
524         {
525             if (amount > 0)
526             {
527                 if ((amount + p_ptr->virtues[i] > 50) && one_in_(2))
528                 {
529                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 50);
530                     return;
531                 }
532                 if ((amount + p_ptr->virtues[i] > 80) && one_in_(2))
533                 {
534                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 80);
535                     return;
536                 }
537                 if ((amount + p_ptr->virtues[i] > 100) && one_in_(2))
538                 {
539                     p_ptr->virtues[i] = MAX(p_ptr->virtues[i], 100);
540                     return;
541                 }
542                 if (amount + p_ptr->virtues[i] > 125)
543                  p_ptr->virtues[i] = 125;
544                 else
545                  p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
546             }
547             else
548             {
549                 if ((amount + p_ptr->virtues[i] < -50) && one_in_(2))
550                 {
551                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -50);
552                     return;
553                 }
554                 if ((amount + p_ptr->virtues[i] < -80) && one_in_(2))
555                 {
556                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -80);
557                     return;
558                 }
559                 if ((amount + p_ptr->virtues[i] < -100) && one_in_(2))
560                 {
561                     p_ptr->virtues[i] = MIN(p_ptr->virtues[i], -100);
562                     return;
563                 }
564                 if (amount + p_ptr->virtues[i] < -125)
565                  p_ptr->virtues[i] = -125;
566                 else
567                  p_ptr->virtues[i] = p_ptr->virtues[i] + amount;
568             }
569             p_ptr->update |= (PU_BONUS);
570             return;
571         }
572     }
573
574 }
575
576 void set_virtue(int virtue, int amount)
577 {
578     int i = 0;
579
580     for (i = 0; i < 8; i++)
581     {
582         if (p_ptr->vir_types[i] == virtue)
583         {
584             p_ptr->virtues[i] = amount;
585             return;
586         }
587     }
588 }
589
590 void dump_virtues(FILE * OutFile)
591 {
592     int v_nr = 0;
593
594     if (!OutFile) return;
595
596         for (v_nr = 0; v_nr < 8; v_nr++)
597         {
598                 char v_name [20];
599
600                 int tester = p_ptr->virtues[v_nr];
601
602                 strcpy(v_name, virtue[(p_ptr->vir_types[v_nr])-1]);
603
604                 if (p_ptr->vir_types[v_nr] == 0 || p_ptr->vir_types[v_nr] >
605                     MAX_VIRTUE)
606 #ifdef JP
607                  fprintf(OutFile, "¤ª¤Ã¤È¡£%s¤Î¾ðÊó¤Ê¤·¡£", v_name);
608 #else
609                  fprintf(OutFile, "Oops. No info about %s.", v_name);
610 #endif
611
612                 else if (tester < -100)
613 #ifdef JP
614                   fprintf(OutFile, "[%s]¤ÎÂжË",
615 #else
616                   fprintf(OutFile, "You are the polar opposite of %s.",
617 #endif
618
619                    v_name);
620                 else if (tester < -80)
621 #ifdef JP
622                   fprintf(OutFile, "[%s]¤ÎÂçŨ",
623 #else
624                   fprintf(OutFile, "You are an arch-enemy of %s.",
625 #endif
626
627                    v_name);
628                 else if (tester < -60)
629 #ifdef JP
630                   fprintf(OutFile, "[%s]¤Î¶¯Å¨",
631 #else
632                   fprintf(OutFile, "You are a bitter enemy of %s.",
633 #endif
634
635                    v_name);
636                 else if (tester < -40)
637 #ifdef JP
638                   fprintf(OutFile, "[%s]¤ÎŨ",
639 #else
640                   fprintf(OutFile, "You are an enemy of %s.",
641 #endif
642
643                    v_name);
644                 else if (tester < -20)
645 #ifdef JP
646                   fprintf(OutFile, "[%s]¤Îºá¼Ô",
647 #else
648                   fprintf(OutFile, "You have sinned against %s.",
649 #endif
650
651                    v_name);
652                 else if (tester < 0)
653 #ifdef JP
654                   fprintf(OutFile, "[%s]¤ÎÌÂÆ»¼Ô",
655 #else
656                   fprintf(OutFile, "You have strayed from the path of %s.",
657 #endif
658
659                    v_name);
660                 else if (tester == 0)                   
661 #ifdef JP
662                   fprintf(OutFile,"[%s]¤ÎÃæΩ¼Ô",
663 #else
664                   fprintf(OutFile,"You are neutral to %s.",
665 #endif
666
667                    v_name);
668                 else if (tester < 20)
669 #ifdef JP
670                   fprintf(OutFile,"[%s]¤Î¾®ÆÁ¼Ô",
671 #else
672                   fprintf(OutFile,"You are somewhat virtuous in %s.",
673 #endif
674
675                    v_name);
676                 else if (tester < 40)
677 #ifdef JP
678                   fprintf(OutFile,"[%s]¤ÎÃæÆÁ¼Ô",
679 #else
680                   fprintf(OutFile,"You are virtuous in %s.",
681 #endif
682
683                    v_name);
684                 else if (tester < 60)
685 #ifdef JP
686                   fprintf(OutFile,"[%s]¤Î¹âÆÁ¼Ô",
687 #else
688                   fprintf(OutFile,"You are very virtuous in %s.",
689 #endif
690
691                    v_name);
692                 else if (tester < 80)
693 #ifdef JP
694                   fprintf(OutFile,"[%s]¤ÎÇƼÔ",
695 #else
696                   fprintf(OutFile,"You are a champion of %s.",
697 #endif
698
699                    v_name);
700                 else if (tester < 100)
701 #ifdef JP
702                   fprintf(OutFile,"[%s]¤Î°ÎÂç¤ÊÇƼÔ",
703 #else
704                   fprintf(OutFile,"You are a great champion of %s.",
705 #endif
706
707                    v_name);
708                 else
709 #ifdef JP
710                   fprintf(OutFile,"[%s]¤Î¶ñ¸½¼Ô",
711 #else
712                   fprintf(OutFile,"You are the living embodiment of %s.",
713 #endif
714
715                    v_name);
716
717             fprintf(OutFile, "\n");
718         }
719
720
721 }
722