1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | #include <stdio.h> |
26 | #include <stdio.h> |
26 | #include <global.h> |
27 | #include <global.h> |
27 | |
28 | |
28 | sint64 levels[MAXNUMLEVELS]; |
29 | sint64 levels[MAXNUMLEVELS]; |
29 | |
30 | |
30 | static float exp_att_mult[NROFATTACKS + 2] = { |
31 | static const float exp_att_mult[NROFATTACKS + 2] = { |
31 | 0.0, /* AT_PHYSICAL */ |
32 | 0.0, /* AT_PHYSICAL */ |
32 | 0.0, /* AT_MAGIC */ |
33 | 0.0, /* AT_MAGIC */ |
33 | 0.0, /* AT_FIRE */ |
34 | 0.0, /* AT_FIRE */ |
34 | 0.0, /* AT_ELECTRICITY */ |
35 | 0.0, /* AT_ELECTRICITY */ |
35 | 0.0, /* AT_COLD */ |
36 | 0.0, /* AT_COLD */ |
… | |
… | |
48 | 0.0, /* AT_DEATH */ |
49 | 0.0, /* AT_DEATH */ |
49 | 0.0, /* AT_CHAOS */ |
50 | 0.0, /* AT_CHAOS */ |
50 | 0.0 /* AT_COUNTERSPELL */ |
51 | 0.0 /* AT_COUNTERSPELL */ |
51 | }; |
52 | }; |
52 | |
53 | |
53 | static float exp_prot_mult[NROFATTACKS + 2] = { |
54 | static const float exp_prot_mult[NROFATTACKS + 2] = { |
54 | 0.4, /* AT_PHYSICAL */ |
55 | 0.4, /* AT_PHYSICAL */ |
55 | 0.5, /* AT_MAGIC */ |
56 | 0.5, /* AT_MAGIC */ |
56 | 0.1, /* AT_FIRE */ |
57 | 0.1, /* AT_FIRE */ |
57 | 0.1, /* AT_ELECTRICITY */ |
58 | 0.1, /* AT_ELECTRICITY */ |
58 | 0.1, /* AT_COLD */ |
59 | 0.1, /* AT_COLD */ |
… | |
… | |
148 | } |
149 | } |
149 | |
150 | |
150 | sint64 |
151 | sint64 |
151 | level_to_min_exp (int level) |
152 | level_to_min_exp (int level) |
152 | { |
153 | { |
153 | if (level <= 0) |
|
|
154 | return 0; |
|
|
155 | else |
|
|
156 | return levels [min (level, settings.max_level)]; |
154 | return levels [clamp (level, 0, settings.max_level)]; |
157 | } |
155 | } |
158 | |
156 | |
159 | /* This loads the experience table from the exp_table |
157 | /* This loads the experience table from the exp_table |
160 | * file. This tends to exit on any errors, since it |
158 | * file. |
161 | * populates the table as it goes along, so if there |
|
|
162 | * are errors, the table is likely in an inconsistent |
|
|
163 | * state. |
|
|
164 | */ |
159 | */ |
165 | void |
160 | void |
166 | init_experience () |
161 | _reload_exp_table () |
167 | { |
162 | { |
168 | char buf[MAX_BUF], *cp; |
|
|
169 | int lastlevel = 0, comp; |
163 | int lastlevel = 0; |
170 | sint64 lastexp = -1, tmpexp; |
164 | sint64 lastexp = -1; |
171 | |
165 | |
172 | sprintf (buf, "%s/exp_table", settings.confdir); |
166 | object_thawer thawer (settings.datadir, "exp_table"); |
173 | |
|
|
174 | object_thawer thawer (buf); |
|
|
175 | |
167 | |
176 | if (!thawer) |
168 | if (!thawer) |
177 | { |
169 | { |
178 | LOG (llevError, "unable to parse experience table file"); |
170 | LOG (llevError, "unable to load experience table file"); |
179 | return; |
171 | return; |
180 | } |
172 | } |
181 | |
173 | |
182 | if (thawer.kw != KW_max_level) |
174 | if (thawer.kw != KW_max_level) |
183 | { |
175 | { |
184 | thawer.parse_error ("experience table file", "max_level"); |
176 | thawer.parse_error ("experience table file"); |
185 | return; |
177 | return; |
186 | } |
178 | } |
187 | |
179 | |
188 | thawer.get (settings.max_level); |
180 | thawer.get (settings.max_level); |
189 | |
181 | |
190 | sint64 newlevels [MAXNUMLEVELS]; |
182 | sint64 newlevels [MAXNUMLEVELS]; |
|
|
183 | newlevels [0] = 0; |
191 | |
184 | |
192 | while (thawer.next_line ()) |
185 | while (thawer.next_line ()) |
193 | { |
186 | { |
|
|
187 | sint64 tmpexp; |
194 | thawer.get (tmpexp); |
188 | thawer.get (tmpexp); |
195 | |
189 | |
196 | /* Do some sanity checking - if value is bogus, just exit because |
190 | /* Do some sanity checking - if value is bogus, just exit because |
197 | * the table otherwise is probably in an inconsistent state |
191 | * the table otherwise is probably in an inconsistent state |
198 | */ |
192 | */ |
… | |
… | |
202 | return; |
196 | return; |
203 | } |
197 | } |
204 | |
198 | |
205 | lastlevel++; |
199 | lastlevel++; |
206 | |
200 | |
207 | if (lastlevel > settings.max_level) |
201 | if (lastlevel > settings.max_level || lastlevel >= MAXNUMLEVELS - 1) |
208 | { |
202 | { |
209 | LOG (llevError, "Too many levels specified in table (%d > %d)\n", lastlevel, settings.max_level); |
203 | LOG (llevError, "Too many levels specified in table (%d > %d (settings.max_level) or >= %d (MAXNUMLEVELS - 1))\n", lastlevel, settings.max_level, MAXNUMLEVELS - 1); |
210 | exit (1); |
204 | exit (1); |
211 | } |
205 | } |
212 | |
206 | |
213 | newlevels [lastlevel] = tmpexp; |
207 | newlevels [lastlevel] = tmpexp; |
214 | lastexp = tmpexp; |
208 | lastexp = tmpexp; |
… | |
… | |
218 | { |
212 | { |
219 | LOG (llevError, "Warning: exp_table does not have %d entries (%d)\n", settings.max_level, lastlevel); |
213 | LOG (llevError, "Warning: exp_table does not have %d entries (%d)\n", settings.max_level, lastlevel); |
220 | return; |
214 | return; |
221 | } |
215 | } |
222 | |
216 | |
|
|
217 | // copy the last exp value one level higher, so we can take the difference to the "next" level |
|
|
218 | // eve4n for players at max. level |
|
|
219 | newlevels [lastlevel + 1] = newlevels [lastlevel]; |
|
|
220 | |
223 | memcpy (levels, newlevels, sizeof (levels)); |
221 | memcpy (levels, newlevels, sizeof (levels)); |
224 | } |
222 | } |
225 | |
223 | |