| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <ctype.h> |
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
int64_t *levels; |
| 27 |
|
| 28 |
static const float exp_att_mult[NROFATTACKS] = { |
| 29 |
0.0, |
| 30 |
0.0, |
| 31 |
0.0, |
| 32 |
0.0, |
| 33 |
0.0, |
| 34 |
0.0, |
| 35 |
0.4, |
| 36 |
1.5, |
| 37 |
0.0, |
| 38 |
0.1, |
| 39 |
0.3, |
| 40 |
0.1, |
| 41 |
0.3, |
| 42 |
0.0, |
| 43 |
0.0, |
| 44 |
0.0, |
| 45 |
0.0, |
| 46 |
0.0, |
| 47 |
0.0, |
| 48 |
0.0, |
| 49 |
0.5, |
| 50 |
0.1, |
| 51 |
0.2, |
| 52 |
0.0, |
| 53 |
0.5, |
| 54 |
0.2, |
| 55 |
}; |
| 56 |
|
| 57 |
static const float exp_prot_mult[NROFATTACKS] = { |
| 58 |
0.4, |
| 59 |
0.5, |
| 60 |
0.1, |
| 61 |
0.1, |
| 62 |
0.1, |
| 63 |
0.1, |
| 64 |
0.1, |
| 65 |
0.1, |
| 66 |
0.1, |
| 67 |
0.1, |
| 68 |
0.1, |
| 69 |
0.0, |
| 70 |
0.1, |
| 71 |
0.1, |
| 72 |
0.1, |
| 73 |
0.0, |
| 74 |
0.0, |
| 75 |
0.0, |
| 76 |
0.0, |
| 77 |
0.0, |
| 78 |
0.0, |
| 79 |
0.1, |
| 80 |
0.0, |
| 81 |
0.0, |
| 82 |
0.0, |
| 83 |
0.1, |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
int64_t new_exp(const object *ob) { |
| 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 |
mask = 1<<i; |
| 109 |
att_mult += (exp_att_mult[i]*((ob->attacktype&mask) != FALSE)); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
prot_mult += (exp_prot_mult[i]*ob->resist[i])/10.0; |
| 120 |
} |
| 121 |
|
| 122 |
if (prot_mult < 0) |
| 123 |
prot_mult = 1; |
| 124 |
|
| 125 |
spec_mult += (0.3*(QUERY_FLAG(ob, FLAG_SEE_INVISIBLE) != FALSE))+ |
| 126 |
(0.5*(QUERY_FLAG(ob, FLAG_SPLITTING) != FALSE))+ |
| 127 |
(0.3*(QUERY_FLAG(ob, FLAG_HITBACK) != FALSE))+ |
| 128 |
(0.1*(QUERY_FLAG(ob, FLAG_REFL_MISSILE) != FALSE))+ |
| 129 |
(0.3*(QUERY_FLAG(ob, FLAG_REFL_SPELL) != FALSE))+ |
| 130 |
(1.0*(QUERY_FLAG(ob, FLAG_NO_MAGIC) != FALSE))+ |
| 131 |
(0.1*(QUERY_FLAG(ob, FLAG_USE_SCROLL) != FALSE))+ |
| 132 |
(0.2*(QUERY_FLAG(ob, FLAG_USE_RANGE) != FALSE))+ |
| 133 |
(0.1*(QUERY_FLAG(ob, FLAG_USE_BOW) != FALSE)); |
| 134 |
|
| 135 |
exp = MAX(ob->stats.maxhp, 5); |
| 136 |
exp *= (QUERY_FLAG(ob, FLAG_CAST_SPELL) && has_ability(ob)) ? (40+MIN(ob->stats.maxsp, 80))/40 : 1; |
| 137 |
exp *= (80.0/(70.0+ob->stats.wc))*(80.0/(70.0+ob->stats.ac))*(50.0+ob->stats.dam)/50.0; |
| 138 |
exp *= att_mult*prot_mult*spec_mult; |
| 139 |
|
| 140 |
exp *= 2.0/(2.0-FABS(ob->speed)); |
| 141 |
exp *= (20.0+ob->stats.Con)/20.0; |
| 142 |
if (QUERY_FLAG(ob, FLAG_STAND_STILL)) |
| 143 |
exp /= 2; |
| 144 |
|
| 145 |
return (int64_t)exp; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
int has_ability(const object *ob) { |
| 154 |
return object_find_by_type(ob, SPELL) != NULL || object_find_by_type(ob, SPELLBOOK) != NULL; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
void init_experience(void) { |
| 168 |
char buf[MAX_BUF], *cp; |
| 169 |
int lastlevel = 0; |
| 170 |
int64_t lastexp = -1, tmpexp; |
| 171 |
FILE *fp; |
| 172 |
|
| 173 |
snprintf(buf, sizeof(buf), "%s/exp_table", settings.confdir); |
| 174 |
if ((fp = fopen(buf, "r")) == NULL) { |
| 175 |
LOG(llevError, "Fatal error: could not open experience table (%s)\n", buf); |
| 176 |
exit(1); |
| 177 |
} |
| 178 |
while (fgets(buf, MAX_BUF-1, fp) != NULL) { |
| 179 |
if (buf[0] == '#') |
| 180 |
continue; |
| 181 |
|
| 182 |
|
| 183 |
if ((cp = strrchr(buf, '\n')) != NULL) |
| 184 |
*cp = '\0'; |
| 185 |
|
| 186 |
|
| 187 |
cp = buf; |
| 188 |
while (isspace(*cp) && *cp != 0) |
| 189 |
cp++; |
| 190 |
if ( *cp == 0 ) continue; |
| 191 |
|
| 192 |
|
| 193 |
if (!strncasecmp(cp, "max_level", 9)) { |
| 194 |
if (settings.max_level) { |
| 195 |
LOG(llevDebug, "Got more than one max_level value from exp_table file?\n"); |
| 196 |
free(levels); |
| 197 |
} |
| 198 |
settings.max_level = atoi(cp+9); |
| 199 |
if (!settings.max_level) { |
| 200 |
LOG(llevDebug, "Got invalid max_level from exp_table file? %s\n", buf); |
| 201 |
} else { |
| 202 |
levels = calloc(settings.max_level+1, sizeof(int64_t)); |
| 203 |
} |
| 204 |
} |
| 205 |
while (isdigit(*cp) && *cp != 0) { |
| 206 |
if (!settings.max_level) { |
| 207 |
LOG(llevError, "max_level is not set in exp_table file. Did you remember to update it?\n"); |
| 208 |
exit(1); |
| 209 |
} |
| 210 |
|
| 211 |
tmpexp = atoll(cp); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
if (tmpexp <= lastexp) { |
| 216 |
LOG(llevError, "Experience for level %d is lower than previous level (%"FMT64" <= %"FMT64")\n", lastlevel+1, tmpexp, lastexp); |
| 217 |
exit(1); |
| 218 |
} |
| 219 |
lastlevel++; |
| 220 |
if (lastlevel > settings.max_level) { |
| 221 |
LOG(llevError, "Too many levels specified in table (%d > %d)\n", lastlevel, settings.max_level); |
| 222 |
exit(1); |
| 223 |
} |
| 224 |
levels[lastlevel] = tmpexp; |
| 225 |
lastexp = tmpexp; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
while (isdigit(*cp) && *cp != 0) |
| 230 |
cp++; |
| 231 |
while (!isdigit(*cp) && *cp != 0) |
| 232 |
cp++; |
| 233 |
} |
| 234 |
} |
| 235 |
fclose(fp); |
| 236 |
if (settings.max_level == 0 || lastlevel != settings.max_level) { |
| 237 |
LOG(llevError, "Fatal: exp_table does not have any level definition or not %d as defined, found %d.\n", settings.max_level, lastlevel); |
| 238 |
exit(1); |
| 239 |
} |
| 240 |
if (lastlevel != settings.max_level && lastlevel != 0) { |
| 241 |
LOG(llevError, "Warning: exp_table does not have %d entries (%d)\n", settings.max_level, lastlevel); |
| 242 |
exit(1); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
void dump_experience(void) { |
| 251 |
int i; |
| 252 |
|
| 253 |
for (i = 1; i <= settings.max_level; i++) { |
| 254 |
fprintf(logfile, "%4d %20"FMT64"\n", i, levels[i]); |
| 255 |
} |
| 256 |
exit(0); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
void free_experience(void) { |
| 263 |
FREE_AND_CLEAR(levels); |
| 264 |
} |