ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/exp.C
Revision: 1.28
Committed: Fri Apr 9 17:44:17 2010 UTC (14 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.27: +2 -3 lines
Log Message:
indent

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
8 * 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 *
13 * 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 *
18 * 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 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */
24
25 #include <stdio.h>
26 #include <global.h>
27
28 sint64 *levels;
29
30 static float exp_att_mult[NROFATTACKS + 2] = {
31 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 };
52
53 static float exp_prot_mult[NROFATTACKS + 2] = {
54 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 };
75
76 /*
77 * Returns true if the monster specified has any innate abilities.
78 */
79 static int
80 has_ability (const object *ob)
81 {
82 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
83 if (tmp->type == SPELL || tmp->type == SPELLBOOK)
84 return true;
85
86 return false;
87 }
88
89 /*
90 * 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 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
117 spec_mult += (0.3 * (QUERY_FLAG (ob, FLAG_SEE_INVISIBLE) != 0)) +
118 (0.5 * (QUERY_FLAG (ob, FLAG_SPLITTING) != 0)) +
119 (0.3 * (QUERY_FLAG (ob, FLAG_HITBACK) != 0)) +
120 (0.1 * (QUERY_FLAG (ob, FLAG_REFL_MISSILE) != 0)) +
121 (0.3 * (QUERY_FLAG (ob, FLAG_REFL_SPELL) != 0)) +
122 (1.0 * (QUERY_FLAG (ob, FLAG_NO_MAGIC) != 0)) +
123 (0.1 * (QUERY_FLAG (ob, FLAG_PICK_UP) != 0)) +
124 (0.1 * (QUERY_FLAG (ob, FLAG_USE_SCROLL) != 0)) +
125 (0.2 * (QUERY_FLAG (ob, FLAG_USE_RANGE) != 0)) + (0.1 * (QUERY_FLAG (ob, FLAG_USE_BOW) != 0));
126
127 exp = (ob->stats.maxhp < 5) ? 5 : ob->stats.maxhp;
128 exp *= (QUERY_FLAG (ob, FLAG_CAST_SPELL) && has_ability (ob)) ? (40 + (ob->stats.maxsp > 80 ? 80 : ob->stats.maxsp)) / 40 : 1;
129 exp *= (80.0 / (70.0 + ob->stats.wc)) * (80.0 / (70.0 + ob->stats.ac)) * (50.0 + ob->stats.dam) / 50.0;
130 exp *= att_mult * prot_mult * spec_mult;
131 exp *= 2.0 / (2.0 - min (ob->speed, 0.95));
132 exp *= (20.0 + ob->stats.Con) / 20.0;
133 if (QUERY_FLAG (ob, FLAG_STAND_STILL))
134 exp /= 2;
135
136 return exp;
137 }
138
139 /* This loads the experience table from the exp_table
140 * file. This tends to exit on any errors, since it
141 * populates the table as it goes along, so if there
142 * are errors, the table is likely in an inconsistent
143 * state.
144 */
145 void
146 init_experience ()
147 {
148 char buf[MAX_BUF], *cp;
149 int lastlevel = 0, comp;
150 sint64 lastexp = -1, tmpexp;
151 FILE *fp;
152
153 sprintf (buf, "%s/exp_table", settings.confdir);
154
155 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
156 {
157 return;
158 }
159 while (fgets (buf, MAX_BUF - 1, fp) != NULL)
160 {
161 if (buf[0] == '#')
162 continue;
163
164 /* eliminate newline */
165 if ((cp = strrchr (buf, '\n')) != NULL)
166 *cp = '\0';
167
168 /* Skip over empty lines */
169 if (buf[0] == 0)
170 continue;
171 cp = buf;
172 while (isspace (*cp) && *cp != 0)
173 cp++;
174 if (!strncasecmp (cp, "max_level", 9))
175 {
176 if (settings.max_level)
177 {
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 }
191 while (isdigit (*cp) && *cp != 0)
192 {
193 if (!settings.max_level)
194 {
195 LOG (llevError, "max_level is not set in exp_table file. Did you remember to update it?\n");
196 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 }
224 }
225 close_and_delete (fp, comp);
226 if (lastlevel != settings.max_level && lastlevel != 0)
227 {
228 LOG (llevError, "Warning: exp_table does not have %d entries (%d)\n", settings.max_level, lastlevel);
229 exit (1);
230 }
231 }
232