ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/exp.C
(Generate patch)

Comparing deliantra/server/common/exp.C (file contents):
Revision 1.29 by root, Sun Apr 11 00:34:05 2010 UTC vs.
Revision 1.45 by root, Mon Jun 10 17:06:31 2024 UTC

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
28sint64 *levels; 29sint64 levels[MAXNUMLEVELS];
29 30
30static float exp_att_mult[NROFATTACKS + 2] = { 31static 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
53static float exp_prot_mult[NROFATTACKS + 2] = { 54static 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 */
134 exp /= 2; 135 exp /= 2;
135 136
136 return exp; 137 return exp;
137} 138}
138 139
140//TODO: binary search...
141int
142exp_to_level (sint64 exp)
143{
144 for (int i = 1; i <= settings.max_level; i++)
145 if (levels [i] > exp)
146 return i - 1;
147
148 return settings.max_level;
149}
150
151sint64
152level_to_min_exp (int level)
153{
154 return levels [clamp (level, 0, settings.max_level)];
155}
156
139/* This loads the experience table from the exp_table 157/* This loads the experience table from the exp_table
140 * file. This tends to exit on any errors, since it 158 * file.
141 * populates the table as it goes along, so if there
142 * are errors, the table is likely in an inconsistent
143 * state.
144 */ 159 */
145void 160void
146init_experience () 161_reload_exp_table ()
147{ 162{
148 char buf[MAX_BUF], *cp;
149 int lastlevel = 0, comp; 163 int lastlevel = 0;
150 sint64 lastexp = -1, tmpexp; 164 sint64 lastexp = -1;
151 FILE *fp;
152 165
153 sprintf (buf, "%s/exp_table", settings.confdir); 166 object_thawer thawer (settings.datadir, "exp_table");
154 167
155 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 168 if (!thawer)
156 { 169 {
170 LOG (llevError, "unable to load experience table file");
157 return; 171 return;
158 } 172 }
159 while (fgets (buf, MAX_BUF - 1, fp) != NULL) 173
174 if (thawer.kw != KW_max_level)
175 {
176 thawer.parse_error ("experience table file");
177 return;
160 { 178 }
161 if (buf[0] == '#')
162 continue;
163 179
164 /* eliminate newline */ 180 thawer.get (settings.max_level);
165 if ((cp = strrchr (buf, '\n')) != NULL)
166 *cp = '\0';
167 181
168 /* Skip over empty lines */ 182 sint64 newlevels [MAXNUMLEVELS];
169 if (buf[0] == 0) 183 newlevels [0] = 0;
170 continue; 184
171 cp = buf; 185 while (thawer.next_line ())
172 while (isspace (*cp) && *cp != 0) 186 {
173 cp++; 187 sint64 tmpexp;
174 if (!strncasecmp (cp, "max_level", 9)) 188 thawer.get (tmpexp);
189
190 /* Do some sanity checking - if value is bogus, just exit because
191 * the table otherwise is probably in an inconsistent state
192 */
193 if (tmpexp <= lastexp)
175 { 194 {
176 if (settings.max_level) 195 LOG (llevError, "Experience for level %d is lower than previous level (%" PRId64 " <= %" PRId64 ")\n", lastlevel + 1, tmpexp, lastexp);
177 { 196 return;
178 LOG (llevDebug, "Got more than one max_level value from exp_table file?\n");
179 free (levels);
180 }
181 settings.max_level = atoi (cp + 9);
182 if (!settings.max_level)
183 {
184 LOG (llevDebug, "Got invalid max_level from exp_table file? %s\n", buf);
185 }
186 else
187 {
188 levels = (sint64 *) calloc (settings.max_level + 1, sizeof (sint64));
189 }
190 } 197 }
191 while (isdigit (*cp) && *cp != 0) 198
199 lastlevel++;
200
201 if (lastlevel > settings.max_level || lastlevel >= MAXNUMLEVELS - 1)
192 { 202 {
193 if (!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);
194 {
195 LOG (llevError, "max_level is not set in exp_table file. Did you remember to update it?\n");
196 exit (1); 204 exit (1);
197 }
198
199 tmpexp = atoll (cp);
200 /* Do some sanity checking - if value is bogus, just exit because
201 * the table otherwise is probably in an inconsistent state
202 */
203 if (tmpexp <= lastexp)
204 {
205 LOG (llevError, "Experience for level %d is lower than previous level (%" PRId64 " <= %" PRId64 ")\n", lastlevel + 1, tmpexp, lastexp);
206 exit (1);
207 }
208 lastlevel++;
209 if (lastlevel > settings.max_level)
210 {
211 LOG (llevError, "Too many levels specified in table (%d > %d)\n", lastlevel, settings.max_level);
212 exit (1);
213 }
214 levels[lastlevel] = tmpexp;
215 lastexp = tmpexp;
216 /* First, skip over the number we just processed. Then skip over
217 * any spaces, commas, etc.
218 */
219 while (isdigit (*cp) && *cp != 0)
220 cp++;
221 while (!isdigit (*cp) && *cp != 0)
222 cp++;
223 } 205 }
206
207 newlevels [lastlevel] = tmpexp;
208 lastexp = tmpexp;
224 } 209 }
225 close_and_delete (fp, comp); 210
226 if (lastlevel != settings.max_level && lastlevel != 0) 211 if (lastlevel != settings.max_level && lastlevel != 0)
227 { 212 {
228 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);
229 exit (1); 214 return;
230 } 215 }
231}
232 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));
222}
223

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines