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 | 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 | { |
… | |
… | |
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 | */ |