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 "wskills.h"
22 #include "xfile.h"
23 #include "xapi.h"
24 
25 _SKILL_DB _skill_db[WSK_EOF] =
26 {					//  dv  hit dmg
27 					//  r   hit dmg
28 {"Unarmed fight",
29 {0, 0, 0, 1, 1, 1, 2, 2, 3,	4,	5,	6,	7,	8,	10,	12}, //dv
30 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	11,	12,	13,	14,	15}, //hit
31 {0, 0, 0, 0, 1, 1, 1, 2, 2,	3,	3,	4,	5,	7,	9,	12} //dmg
32 },
33 
34 {"Daggers & Knives",
35 {0, 0, 0, 1, 1, 1, 1, 2, 2,	2,	2,	3,	3,	4,	5,	6}, //dv
36 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	11,	12,	14,	16,	19}, //hit
37 {0, 0, 0, 1, 1, 2, 2, 3, 3,	4,	4,	5,	5,	6,	6,	8} //dmg
38 },
39 
40 {"Swords",
41 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
42 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
43 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
44 },
45 
46 {"Clubs & Hammers",
47 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
48 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
49 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
50 },
51 
52 {"Maces & Flails",
53 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
54 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
55 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
56 },
57 
58 {"Pole Arms",
59 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
60 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
61 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
62 },
63 
64 {"Axes",
65 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
66 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
67 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
68 },
69 
70 {"Staves",
71 {0, 0, 1, 2, 2, 3, 3, 4, 4,	5,	6,	7,	8,	9,	10,	12}, //dv
72 {0, 1, 1, 1, 2, 2, 2, 3, 3,	4,	4,	5,	6,	8,	10,	12}, //hit
73 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
74 },
75 
76 {"Shields",
77 {0, 1, 2, 3, 5, 7, 9, 11, 12,	14,	16,	18,	20,	23,	26,	30}, //dv
78 {0, 0, 0, 0, 0, 0, 0, 0, 0,	0,	0,	0,	0,	0,	0,	0}, //hit
79 {0, 0, 0, 0, 0, 0, 0, 0, 0,	0,	0,	0,	0,	0,	0,	0} //dmg
80 },
81 
82 {"Bows",
83 {0, 0, 1, 1, 1, 1, 2, 2, 2,	2,	3,	3,	3,	3,	4,	5}, //r
84 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	12,	14,	16,	18,	22}, //hit
85 {0, 0, 1, 1, 2, 2, 3, 3, 4,	4,	5,	6,	8,	10,	12,	14} //dmg
86 },
87 
88 {"Crossbows",
89 {0, 0, 0, 0, 0, 0, 0, 1, 1,	1,	1,	1,	1,	2,	2,	3}, //r
90 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	12,	14,	16,	18,	22}, //hit
91 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	11,	12,	13,	14,	16} //dmg
92 },
93 
94 {"Slings",
95 {0, 1, 1, 1, 2, 2, 2, 3, 3,	3,	4,	4,	4,	5,	5,	6}, //r
96 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	12,	14,	16,	18,	22}, //hit
97 {0, 0, 0, 0, 1, 1, 1, 1, 2,	2,	2,	3,	3,	4,	4,	6} //dmg
98 },
99 
100 {"Throwing items",
101 {0, 1, 1, 1, 1, 1, 2, 2, 2,	2,	3,	3,	3,	4,	4,	5}, //r
102 {0, 1, 2, 3, 4, 5, 6, 7, 8,	9,	10,	12,	14,	16,	18,	22}, //hit
103 {0, 0, 0, 0, 1, 1, 1, 1, 2,	2,	2,	3,	3,	4,	4,	6} //dmg
104 }
105 };
106 
XWarSkills()107 XWarSkills::XWarSkills()
108 {
109 	for (int i = 0; i < WSK_EOF; i++)
110 	{
111 		marks_counter[i] = GetN(1);
112 		levels[i] = 0;
113 	}
114 }
115 
GetName(WSK_TYPE wt)116 char * XWarSkills::GetName(WSK_TYPE wt)
117 {
118 	return _skill_db[wt].name;
119 }
120 
121 
122 
GetLevel(WSK_TYPE wt)123 int XWarSkills::GetLevel(WSK_TYPE wt)
124 {
125 	return levels[wt];
126 }
127 
128 
GetN(int level)129 int XWarSkills::GetN(int level)
130 {
131 	//30, 26
132 	return 10 * vRound((float)(25.0 * (pow(M_E, level / 4.0) - 1)));
133 }
134 
SetLevel(WSK_TYPE wt,int level)135 void XWarSkills::SetLevel(WSK_TYPE wt, int level)
136 {
137 	marks_counter[wt] = GetN(level + 1);
138 	levels[wt] = level;
139 }
140 
UseSkill(WSK_TYPE wt,int time)141 void XWarSkills::UseSkill(WSK_TYPE wt, int time)
142 {
143 	marks_counter[wt] -= time * 10;
144 	if (marks_counter[wt] <= 0)
145 	{
146 		if (levels[wt] < 15)
147 		{
148 			levels[wt]++;
149 			marks_counter[wt] += GetN(levels[wt]);
150 		}
151 	}
152 }
153 
154 
GetDV(WSK_TYPE wt)155 int XWarSkills::GetDV(WSK_TYPE wt)
156 {
157 	return _skill_db[wt].base_dv[levels[wt]];
158 }
159 
GetHIT(WSK_TYPE wt)160 int XWarSkills::GetHIT(WSK_TYPE wt)
161 {
162 	return _skill_db[wt].base_hit[levels[wt]];
163 }
164 
GetDMG(WSK_TYPE wt)165 int XWarSkills::GetDMG(WSK_TYPE wt)
166 {
167 	return _skill_db[wt].base_dmg[levels[wt]];
168 }
169 
GetUseTime(WSK_TYPE wt)170 int XWarSkills::GetUseTime(WSK_TYPE wt)
171 {
172 	return 1000 - GetLevel(wt) * 30;
173 }
174 
Store(XFile * f)175 void XWarSkills::Store(XFile * f)
176 {
177 	f->Write(marks_counter, sizeof(int), WSK_EOF);
178 	f->Write(levels, sizeof(int), WSK_EOF);
179 }
180 
Restore(XFile * f)181 void XWarSkills::Restore(XFile * f)
182 {
183 	f->Read(marks_counter, sizeof(int), WSK_EOF);
184 	f->Read(levels, sizeof(int), WSK_EOF);
185 }
186 
187 
188 
189