| 1 |
/* |
| 2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
* |
| 4 |
* Copyright (©) 2017,2018 Marc Alexander Lehmann / 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 |
| 6 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
| 7 |
* Copyright (©) 1992 Frank Tore Johansen |
| 8 |
* |
| 9 |
* 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 |
* |
| 14 |
* 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 |
* |
| 19 |
* 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 |
* |
| 23 |
* The authors can be reached via e-mail to <support@deliantra.net> |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
#include <global.h> |
| 28 |
|
| 29 |
sint64 levels[MAXNUMLEVELS]; |
| 30 |
|
| 31 |
static const float exp_att_mult[NROFATTACKS + 2] = { |
| 32 |
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 |
}; |
| 53 |
|
| 54 |
static const float exp_prot_mult[NROFATTACKS + 2] = { |
| 55 |
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 |
}; |
| 76 |
|
| 77 |
/* |
| 78 |
* Returns true if the monster specified has any innate abilities. |
| 79 |
*/ |
| 80 |
static int |
| 81 |
has_ability (const object *ob) |
| 82 |
{ |
| 83 |
for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
| 84 |
if (tmp->type == SPELL || tmp->type == SPELLBOOK) |
| 85 |
return true; |
| 86 |
|
| 87 |
return false; |
| 88 |
} |
| 89 |
|
| 90 |
/* |
| 91 |
* 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 |
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 |
|
| 118 |
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 |
|
| 128 |
exp = (ob->stats.maxhp < 5) ? 5 : ob->stats.maxhp; |
| 129 |
exp *= (ob->flag [FLAG_CAST_SPELL] && has_ability (ob)) ? (40 + (ob->stats.maxsp > 80 ? 80 : ob->stats.maxsp)) / 40 : 1; |
| 130 |
exp *= (80.0 / (70.0 + ob->stats.wc)) * (80.0 / (70.0 + ob->stats.ac)) * (50.0 + ob->stats.dam) / 50.0; |
| 131 |
exp *= att_mult * prot_mult * spec_mult; |
| 132 |
exp *= 2.0 / (2.0 - min (ob->speed, 0.95)); |
| 133 |
exp *= (20.0 + ob->stats.Con) / 20.0; |
| 134 |
if (ob->flag [FLAG_STAND_STILL]) |
| 135 |
exp /= 2; |
| 136 |
|
| 137 |
return exp; |
| 138 |
} |
| 139 |
|
| 140 |
//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 |
return levels [clamp (level, 0, settings.max_level)]; |
| 155 |
} |
| 156 |
|
| 157 |
/* This loads the experience table from the exp_table |
| 158 |
* file. |
| 159 |
*/ |
| 160 |
void |
| 161 |
_reload_exp_table () |
| 162 |
{ |
| 163 |
int lastlevel = 0; |
| 164 |
sint64 lastexp = -1; |
| 165 |
|
| 166 |
object_thawer thawer (settings.datadir, "exp_table"); |
| 167 |
|
| 168 |
if (!thawer) |
| 169 |
{ |
| 170 |
LOG (llevError, "unable to load experience table file"); |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
if (thawer.kw != KW_max_level) |
| 175 |
{ |
| 176 |
thawer.parse_error ("experience table file"); |
| 177 |
return; |
| 178 |
} |
| 179 |
|
| 180 |
thawer.get (settings.max_level); |
| 181 |
|
| 182 |
sint64 newlevels [MAXNUMLEVELS]; |
| 183 |
newlevels [0] = 0; |
| 184 |
|
| 185 |
while (thawer.next_line ()) |
| 186 |
{ |
| 187 |
sint64 tmpexp; |
| 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) |
| 194 |
{ |
| 195 |
LOG (llevError, "Experience for level %d is lower than previous level (%" PRId64 " <= %" PRId64 ")\n", lastlevel + 1, tmpexp, lastexp); |
| 196 |
return; |
| 197 |
} |
| 198 |
|
| 199 |
lastlevel++; |
| 200 |
|
| 201 |
if (lastlevel > settings.max_level || lastlevel >= MAXNUMLEVELS - 1) |
| 202 |
{ |
| 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); |
| 204 |
exit (1); |
| 205 |
} |
| 206 |
|
| 207 |
newlevels [lastlevel] = tmpexp; |
| 208 |
lastexp = tmpexp; |
| 209 |
} |
| 210 |
|
| 211 |
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 |
return; |
| 215 |
} |
| 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 |
|