1 /*
2 This file is part of "Avanor, the Land of Mystery" roguelike game
3 Home page: http://www.avanor.com/
4 Copyright (C) 2000-2003 Vadim Gaidukevich
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "resist.h"
22 #include "xfile.h"
23 #include "global.h"
24
25 RESIST_REC resists_data[] = {
26 {"unknown", FLU_NONE},
27 {"white", FLU_CREATURE},
28 {"black", FLU_CREATURE},
29 {"fire", FLU_ALL},
30 {"water", FLU_ALL},
31 {"air", FLU_ALL},
32 {"earth", FLU_ALL},
33 {"acid", FLU_ALL},
34 {"cold", FLU_ALL},
35 {"poison", FLU_CREATURE},
36 {"decease", FLU_CREATURE},
37 {"paralyse", FLU_CREATURE},
38 {"stun", FLU_CREATURE},
39 {"confuse", FLU_CREATURE},
40 {"blind", FLU_CREATURE},
41 {"light", FLU_CREATURE},
42 {"darkness", FLU_CREATURE},
43 {"invisible", FLU_CREATURE},
44 {"see_invisible", FLU_CREATURE},
45 "eof", FLU_NONE};
46
47
XResistance(XResistance * xr)48 XResistance::XResistance(XResistance * xr)
49 {
50 Set(xr);
51 }
52
XResistance()53 XResistance::XResistance()
54 {
55 for (int i = R_WHITE; i < R_EOF; i++)
56 SetResistance((RESISTANCE)i, 0);
57 }
58
XResistance(const char * str1)59 XResistance::XResistance(const char * str1)
60 {
61 XStringProc xsp1(str1);
62 char buf[256];
63 XDice d;
64 for(int i = R_WHITE; i < R_EOF; i++)
65 {
66 if (xsp1.GetParam(buf, resists_data[i + 1].name))
67 {
68 d.Setup(buf);
69 SetResistance((RESISTANCE)i, d.Throw());
70 } else
71 SetResistance((RESISTANCE)i, 0);
72 }
73 }
74
Set(XResistance * r)75 void XResistance::Set(XResistance * r)
76 {
77 if (r)
78 for (int i = R_WHITE; i < R_EOF; i++)
79 SetResistance((RESISTANCE)i, r->GetResistance((RESISTANCE)i));
80 }
81
Add(XResistance * r)82 void XResistance::Add(XResistance * r)
83 {
84 if (r)
85 for (int i = R_WHITE; i < R_EOF; i++)
86 resistances[i] += r->resistances[i];
87 }
88
Sub(XResistance * r)89 void XResistance::Sub(XResistance * r)
90 {
91 if (r)
92 for (int i = R_WHITE; i < R_EOF; i++)
93 resistances[i] -= r->resistances[i];
94 };
95
isEqual(XResistance * xr)96 bool XResistance::isEqual(XResistance * xr)
97 {
98 for (int i = R_WHITE; i < R_EOF; i++)
99 if (resistances[i] != xr->resistances[i])
100 return false;
101 return true;
102 }
103
104
Store(XFile * f)105 void XResistance::Store(XFile * f)
106 {
107 f->Write(&resistances[R_WHITE], sizeof(int), R_EOF);
108 }
109
Restore(XFile * f)110 void XResistance::Restore(XFile * f)
111 {
112 f->Read(&resistances[R_WHITE], sizeof(int), R_EOF);
113 }
114
115
116 char * resist_name[] =
117 { "White magic", "Black magic", "Fire magic", "Water magic", "Air magic", "Earth magic",
118 "Acid", "Cold", "Poison", "Disease", "Paralyzation",
119 "Stun", "Confusion", "Blindness",
120 "Light", "Darkness", "Invisible", "See Invisible"
121 };
122
GetResistanceName(RESISTANCE r)123 char * XResistance::GetResistanceName(RESISTANCE r)
124 {
125 return resist_name[r];
126 }
127
128 char * resist_level[] =
129 {
130 MSG_LIGHTRED "awful", MSG_LIGHTRED "bad",
131 MSG_LIGHTGRAY "none", MSG_LIGHTGREEN "mediocre", MSG_LIGHTGREEN "fair",
132 MSG_LIGHTGREEN "good", MSG_YELLOW "excellent", MSG_WHITE "complete"
133 };
134
GetResistanceLevel(RESISTANCE r)135 char * XResistance::GetResistanceLevel(RESISTANCE r)
136 {
137 if (resistances[r] < -50)
138 return resist_level[0];
139 else if (resistances[r] < 0)
140 return resist_level[1];
141 else if (resistances[r] == 0)
142 return resist_level[2];
143 else if (resistances[r] < 10)
144 return resist_level[3];
145 else if (resistances[r] < 40)
146 return resist_level[4];
147 else if (resistances[r] < 80)
148 return resist_level[5];
149 else if (resistances[r] < 100)
150 return resist_level[6];
151 else
152 return resist_level[7];
153 }
154