ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/exp.C
Revision: 1.44
Committed: Thu Nov 22 00:40:12 2018 UTC (5 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.43: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.17 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.40 *
4 root 1.43 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.42 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.26 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.40 *
9 root 1.20 * Deliantra is free software: you can redistribute it and/or modify it under
10     * the terms of the Affero GNU General Public License as published by the
11     * Free Software Foundation, either version 3 of the License, or (at your
12     * option) any later version.
13 root 1.40 *
14 root 1.16 * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     * GNU General Public License for more details.
18 root 1.40 *
19 root 1.20 * You should have received a copy of the Affero GNU General Public License
20     * and the GNU General Public License along with this program. If not, see
21     * <http://www.gnu.org/licenses/>.
22 root 1.40 *
23 root 1.17 * The authors can be reached via e-mail to <support@deliantra.net>
24 pippijn 1.11 */
25 elmex 1.1
26     #include <stdio.h>
27     #include <global.h>
28    
29 root 1.30 sint64 levels[MAXNUMLEVELS];
30 elmex 1.1
31 root 1.31 static const float exp_att_mult[NROFATTACKS + 2] = {
32 root 1.5 0.0, /* AT_PHYSICAL */
33     0.0, /* AT_MAGIC */
34     0.0, /* AT_FIRE */
35     0.0, /* AT_ELECTRICITY */
36     0.0, /* AT_COLD */
37     0.0, /* AT_WATER *//*AT_CONFUSION! */
38     0.4, /* AT_ACID */
39     1.5, /* AT_DRAIN */
40     0.0, /* AT_WEAPONMAGIC */
41     0.1, /* AT_GHOSTHIT */
42     0.3, /* AT_POISON */
43     0.2, /* AT_DISEASE */
44     0.3, /* AT_PARALYZE */
45     0.0, /* AT_TURN_UNDEAD */
46     0.0, /* AT_FEAR */
47     0.0, /* AT_CANCELLATION */
48     0.0, /* AT_DEPLETE */
49     0.0, /* AT_DEATH */
50     0.0, /* AT_CHAOS */
51     0.0 /* AT_COUNTERSPELL */
52 elmex 1.1 };
53    
54 root 1.31 static const float exp_prot_mult[NROFATTACKS + 2] = {
55 root 1.5 0.4, /* AT_PHYSICAL */
56     0.5, /* AT_MAGIC */
57     0.1, /* AT_FIRE */
58     0.1, /* AT_ELECTRICITY */
59     0.1, /* AT_COLD */
60     0.1, /* AT_WATER */
61     0.1, /* AT_ACID */
62     0.1, /* AT_DRAIN */
63     0.1, /* AT_WEAPONMAGIC */
64     0.1, /* AT_GHOSTHIT */
65     0.1, /* AT_POISON */
66     0.1, /* AT_DISEASE */
67     0.1, /* AT_PARALYZE */
68     0.1, /* AT_TURN_UNDEAD */
69     0.1, /* AT_FEAR */
70     0.0, /* AT_CANCELLATION */
71     0.0, /* AT_DEPLETE */
72     0.0, /* AT_DEATH */
73     0.0, /* AT_CHAOS */
74     0.0 /* AT_COUNTERSPELL */
75 elmex 1.1 };
76    
77     /*
78 root 1.21 * Returns true if the monster specified has any innate abilities.
79     */
80 root 1.23 static int
81 root 1.21 has_ability (const object *ob)
82     {
83 root 1.28 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
84 root 1.21 if (tmp->type == SPELL || tmp->type == SPELLBOOK)
85     return true;
86 root 1.28
87 root 1.21 return false;
88     }
89    
90     /*
91 elmex 1.1 * new_exp() is an alternative way to calculate experience based
92     * on the ability of a monster.
93     * It's far from perfect, and doesn't consider everything which
94     * can be considered, thus it's only used in debugging.
95     * this is only used with one of the dumpflags,
96     * and not anyplace in the code.
97     */
98 root 1.5 int
99     new_exp (const object *ob)
100     {
101     double att_mult, prot_mult, spec_mult;
102     double exp;
103     int i;
104     long mask = 1;
105    
106     att_mult = prot_mult = spec_mult = 1.0;
107     for (i = 0; i < NROFATTACKS; i++)
108     {
109     mask = 1 << i;
110     att_mult += (exp_att_mult[i] * ((ob->attacktype & mask) != 0));
111     /* We multiply & then divide to prevent roundoffs on the floats.
112     * the doubling is to take into account the table and resistances
113     * are lower than they once were.
114     */
115     prot_mult += (exp_prot_mult[i] * 200 * ob->resist[i]) / 100.0;
116     }
117 root 1.24
118 root 1.29 spec_mult += (0.3 * (ob->flag [FLAG_SEE_INVISIBLE] != 0)) +
119     (0.5 * (ob->flag [FLAG_SPLITTING] != 0)) +
120     (0.3 * (ob->flag [FLAG_HITBACK] != 0)) +
121     (0.1 * (ob->flag [FLAG_REFL_MISSILE] != 0)) +
122     (0.3 * (ob->flag [FLAG_REFL_SPELL] != 0)) +
123     (1.0 * (ob->flag [FLAG_NO_MAGIC] != 0)) +
124     (0.1 * (ob->flag [FLAG_PICK_UP] != 0)) +
125     (0.1 * (ob->flag [FLAG_USE_SCROLL] != 0)) +
126     (0.2 * (ob->flag [FLAG_USE_RANGE] != 0)) + (0.1 * (ob->flag [FLAG_USE_BOW] != 0));
127 root 1.5
128     exp = (ob->stats.maxhp < 5) ? 5 : ob->stats.maxhp;
129 root 1.29 exp *= (ob->flag [FLAG_CAST_SPELL] && has_ability (ob)) ? (40 + (ob->stats.maxsp > 80 ? 80 : ob->stats.maxsp)) / 40 : 1;
130 root 1.5 exp *= (80.0 / (70.0 + ob->stats.wc)) * (80.0 / (70.0 + ob->stats.ac)) * (50.0 + ob->stats.dam) / 50.0;
131 elmex 1.1 exp *= att_mult * prot_mult * spec_mult;
132 root 1.25 exp *= 2.0 / (2.0 - min (ob->speed, 0.95));
133 root 1.5 exp *= (20.0 + ob->stats.Con) / 20.0;
134 root 1.29 if (ob->flag [FLAG_STAND_STILL])
135 elmex 1.1 exp /= 2;
136    
137 root 1.25 return exp;
138 elmex 1.1 }
139    
140 root 1.30 //TODO: binary search...
141     int
142     exp_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    
151     sint64
152     level_to_min_exp (int level)
153     {
154 root 1.38 return levels [clamp (level, 0, settings.max_level)];
155 root 1.30 }
156    
157 elmex 1.1 /* This loads the experience table from the exp_table
158 root 1.35 * file.
159 elmex 1.1 */
160 root 1.5 void
161 root 1.41 _reload_exp_table ()
162 elmex 1.1 {
163 root 1.33 int lastlevel = 0;
164     sint64 lastexp = -1;
165 elmex 1.1
166 root 1.34 object_thawer thawer (settings.datadir, "exp_table");
167 root 1.30
168     if (!thawer)
169 root 1.5 {
170 root 1.36 LOG (llevError, "unable to load experience table file");
171 root 1.5 return;
172 elmex 1.1 }
173 root 1.30
174     if (thawer.kw != KW_max_level)
175 root 1.5 {
176 root 1.32 thawer.parse_error ("experience table file");
177 root 1.30 return;
178     }
179 root 1.5
180 root 1.30 thawer.get (settings.max_level);
181    
182     sint64 newlevels [MAXNUMLEVELS];
183 root 1.44 newlevels [0] = 0;
184 root 1.30
185     while (thawer.next_line ())
186     {
187 root 1.33 sint64 tmpexp;
188 root 1.30 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)
194 root 1.5 {
195 root 1.30 LOG (llevError, "Experience for level %d is lower than previous level (%" PRId64 " <= %" PRId64 ")\n", lastlevel + 1, tmpexp, lastexp);
196     return;
197 root 1.2 }
198 root 1.30
199     lastlevel++;
200    
201     if (lastlevel > settings.max_level)
202 root 1.5 {
203 root 1.30 LOG (llevError, "Too many levels specified in table (%d > %d)\n", lastlevel, settings.max_level);
204     exit (1);
205 root 1.2 }
206 root 1.30
207     newlevels [lastlevel] = tmpexp;
208     lastexp = tmpexp;
209 elmex 1.1 }
210 root 1.30
211 root 1.5 if (lastlevel != settings.max_level && lastlevel != 0)
212     {
213     LOG (llevError, "Warning: exp_table does not have %d entries (%d)\n", settings.max_level, lastlevel);
214 root 1.30 return;
215 elmex 1.1 }
216 root 1.30
217     memcpy (levels, newlevels, sizeof (levels));
218 elmex 1.1 }
219