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> |
… | |
… | |
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 | int lastlevel = 0; |
163 | int lastlevel = 0; |
169 | sint64 lastexp = -1; |
164 | sint64 lastexp = -1; |
170 | |
165 | |
171 | object_thawer thawer (settings.datadir, "exp_table"); |
166 | object_thawer thawer (settings.datadir, "exp_table"); |
172 | |
167 | |
173 | if (!thawer) |
168 | if (!thawer) |
174 | { |
169 | { |
175 | LOG (llevError, "unable to parse experience table file"); |
170 | LOG (llevError, "unable to load experience table file"); |
176 | return; |
171 | return; |
177 | } |
172 | } |
178 | |
173 | |
179 | if (thawer.kw != KW_max_level) |
174 | if (thawer.kw != KW_max_level) |
180 | { |
175 | { |
… | |
… | |
183 | } |
178 | } |
184 | |
179 | |
185 | thawer.get (settings.max_level); |
180 | thawer.get (settings.max_level); |
186 | |
181 | |
187 | sint64 newlevels [MAXNUMLEVELS]; |
182 | sint64 newlevels [MAXNUMLEVELS]; |
|
|
183 | newlevels [0] = 0; |
188 | |
184 | |
189 | while (thawer.next_line ()) |
185 | while (thawer.next_line ()) |
190 | { |
186 | { |
191 | sint64 tmpexp; |
187 | sint64 tmpexp; |
192 | thawer.get (tmpexp); |
188 | thawer.get (tmpexp); |
… | |
… | |
200 | return; |
196 | return; |
201 | } |
197 | } |
202 | |
198 | |
203 | lastlevel++; |
199 | lastlevel++; |
204 | |
200 | |
205 | if (lastlevel > settings.max_level) |
201 | if (lastlevel > settings.max_level || lastlevel >= MAXNUMLEVELS - 1) |
206 | { |
202 | { |
207 | 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); |
208 | exit (1); |
204 | exit (1); |
209 | } |
205 | } |
210 | |
206 | |
211 | newlevels [lastlevel] = tmpexp; |
207 | newlevels [lastlevel] = tmpexp; |
212 | lastexp = tmpexp; |
208 | lastexp = tmpexp; |
… | |
… | |
216 | { |
212 | { |
217 | 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); |
218 | return; |
214 | return; |
219 | } |
215 | } |
220 | |
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 | |
221 | memcpy (levels, newlevels, sizeof (levels)); |
221 | memcpy (levels, newlevels, sizeof (levels)); |
222 | } |
222 | } |
223 | |
223 | |