ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/exp.C
Revision: 1.40
Committed: Mon Oct 29 23:55:52 2012 UTC (11 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.39: +5 -5 lines
Log Message:
trailing space removal

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