| 1 |
/* |
| 2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
* |
| 4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
| 5 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
| 6 |
* Copyright (©) 1992,2007 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 <assert.h> |
| 26 |
#include <global.h> |
| 27 |
#include <living.h> |
| 28 |
#include <material.h> |
| 29 |
#include <skills.h> |
| 30 |
#include <sounds.h> |
| 31 |
#include <sproto.h> |
| 32 |
|
| 33 |
typedef struct att_msg_str |
| 34 |
{ |
| 35 |
char *msg1; |
| 36 |
char *msg2; |
| 37 |
} att_msg; |
| 38 |
|
| 39 |
/*#define ATTACK_DEBUG*/ |
| 40 |
|
| 41 |
/* cancels object *op. Cancellation basically means an object loses |
| 42 |
* its magical benefits. |
| 43 |
*/ |
| 44 |
void |
| 45 |
cancellation (object *op) |
| 46 |
{ |
| 47 |
if (op->invisible) |
| 48 |
return; |
| 49 |
|
| 50 |
if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) |
| 51 |
{ |
| 52 |
/* Recurse through the inventory */ |
| 53 |
for (object *tmp = op->inv; tmp; tmp = tmp->below) |
| 54 |
if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
| 55 |
cancellation (tmp); |
| 56 |
} |
| 57 |
else if (FABS (op->magic) <= rndm (0, 5)) |
| 58 |
{ |
| 59 |
/* Nullify this object. This code could probably be more complete */ |
| 60 |
/* in what abilities it should cancel */ |
| 61 |
op->magic = 0; |
| 62 |
|
| 63 |
CLEAR_FLAG (op, FLAG_DAMNED); |
| 64 |
CLEAR_FLAG (op, FLAG_CURSED); |
| 65 |
CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
| 66 |
CLEAR_FLAG (op, FLAG_KNOWN_CURSED); |
| 67 |
|
| 68 |
if (object *pl = op->visible_to ()) |
| 69 |
esrv_update_item (UPD_FLAGS, pl, op); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/* did_make_save_item just checks to make sure the item actually |
| 74 |
* made its saving throw based on the tables. It does not take |
| 75 |
* any further action (like destroying the item). |
| 76 |
*/ |
| 77 |
int |
| 78 |
did_make_save_item (object *op, int type, object *originator) |
| 79 |
{ |
| 80 |
int i, roll, saves = 0, attacks = 0, number; |
| 81 |
materialtype_t *mt; |
| 82 |
|
| 83 |
if (!op->materialname) |
| 84 |
{ |
| 85 |
for (mt = materialt; mt; mt = mt->next) |
| 86 |
if (op->materials & mt->material) |
| 87 |
break; |
| 88 |
} |
| 89 |
else |
| 90 |
mt = name_to_material (op->materialname); |
| 91 |
|
| 92 |
if (!mt) |
| 93 |
return TRUE; |
| 94 |
|
| 95 |
roll = rndm (1, 20); |
| 96 |
|
| 97 |
/* the attacktypes have no meaning for object saves |
| 98 |
* If the type is only magic, don't adjust type - basically, if |
| 99 |
* pure magic is hitting an object, it should save. However, if it |
| 100 |
* is magic teamed with something else, then strip out the |
| 101 |
* magic type, and instead let the fire, cold, or whatever component |
| 102 |
* destroy the item. Otherwise, you get the case of poisoncloud |
| 103 |
* destroying objects because it has magic attacktype. |
| 104 |
*/ |
| 105 |
if (type != AT_MAGIC) |
| 106 |
type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | |
| 107 |
AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | |
| 108 |
AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); |
| 109 |
|
| 110 |
if (type == 0) return TRUE; |
| 111 |
|
| 112 |
if (roll == 20) return TRUE; |
| 113 |
if (roll == 1) return FALSE; |
| 114 |
|
| 115 |
for (number = 0; number < NROFATTACKS; number++) |
| 116 |
{ |
| 117 |
i = 1 << number; |
| 118 |
|
| 119 |
if (!(i & type)) |
| 120 |
continue; |
| 121 |
|
| 122 |
attacks++; |
| 123 |
if (op->resist[number] == 100) |
| 124 |
saves++; |
| 125 |
else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100) |
| 126 |
saves++; |
| 127 |
else if ((20 - mt->save[number]) / 3 > originator->stats.dam) |
| 128 |
saves++; |
| 129 |
} |
| 130 |
|
| 131 |
if (saves == attacks || attacks == 0) |
| 132 |
return TRUE; |
| 133 |
|
| 134 |
if (saves == 0 || (rndm (1, attacks) > saves)) |
| 135 |
return FALSE; |
| 136 |
|
| 137 |
return TRUE; |
| 138 |
} |
| 139 |
|
| 140 |
/* This function calls did_make_save_item. It then performs the |
| 141 |
* appropriate actions to the item (such as burning the item up, |
| 142 |
* calling cancellation, etc.) |
| 143 |
*/ |
| 144 |
void |
| 145 |
save_throw_object (object *op, int type, object *originator) |
| 146 |
{ |
| 147 |
if (!did_make_save_item (op, type, originator)) |
| 148 |
{ |
| 149 |
object *env = op->env; |
| 150 |
int x = op->x, y = op->y; |
| 151 |
maptile *m = op->map; |
| 152 |
|
| 153 |
op = stop_item (op); |
| 154 |
if (!op) |
| 155 |
return; |
| 156 |
|
| 157 |
/* Hacked the following so that type LIGHTER will work. |
| 158 |
* Also, objects which are potential "lights" that are hit by |
| 159 |
* flame/elect attacks will be set to glow. "lights" are any |
| 160 |
* object with +/- glow_radius and an "other_arch" to change to. |
| 161 |
* (and please note that we cant fail our save and reach this |
| 162 |
* function if the object doesnt contain a material that can burn. |
| 163 |
* So forget lighting magical swords on fire with this!) -b.t. |
| 164 |
*/ |
| 165 |
if (type & (AT_FIRE | AT_ELECTRICITY) |
| 166 |
&& (QUERY_FLAG (op, FLAG_IS_LIGHTABLE) |
| 167 |
|| op->type == LAMP |
| 168 |
|| op->type == TORCH |
| 169 |
)) |
| 170 |
{ |
| 171 |
switch (op->type) |
| 172 |
{ |
| 173 |
case LAMP: |
| 174 |
case TORCH: |
| 175 |
// turn on a lamp |
| 176 |
apply_lamp (op, true); |
| 177 |
break; |
| 178 |
|
| 179 |
default: |
| 180 |
// for instance icecubes: |
| 181 |
if (op->other_arch) |
| 182 |
{ |
| 183 |
const char *arch = op->other_arch->archname; |
| 184 |
|
| 185 |
if (op->decrease ()) |
| 186 |
fix_stopped_item (op, m, originator); |
| 187 |
|
| 188 |
if ((op = archetype::get (arch))) |
| 189 |
{ |
| 190 |
if (env) |
| 191 |
env->insert (op); |
| 192 |
else |
| 193 |
m->insert (op, x, y, originator); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
return; |
| 198 |
} |
| 199 |
|
| 200 |
if (type & AT_CANCELLATION) |
| 201 |
{ /* Cancellation. */ |
| 202 |
cancellation (op); |
| 203 |
fix_stopped_item (op, m, originator); |
| 204 |
return; |
| 205 |
} |
| 206 |
|
| 207 |
if (op->nrof > 1) |
| 208 |
{ |
| 209 |
if (op->decrease (rndm (0, op->nrof - 1))) |
| 210 |
fix_stopped_item (op, m, originator); |
| 211 |
} |
| 212 |
else |
| 213 |
{ |
| 214 |
// drop everything to the ground, if possible |
| 215 |
op->insert_at (originator); |
| 216 |
op->drop_and_destroy (); |
| 217 |
} |
| 218 |
|
| 219 |
if (type & (AT_FIRE | AT_ELECTRICITY)) |
| 220 |
if (env) |
| 221 |
{ |
| 222 |
op = archetype::get (shstr_burnout); |
| 223 |
op->x = env->x, op->y = env->y; |
| 224 |
env->insert (op); |
| 225 |
} |
| 226 |
else |
| 227 |
replace_insert_ob_in_map (shstr_burnout, originator); |
| 228 |
|
| 229 |
return; |
| 230 |
} |
| 231 |
|
| 232 |
/* The value of 50 is arbitrary. */ |
| 233 |
if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2)) |
| 234 |
{ |
| 235 |
archetype *at = archetype::find (shstr_icecube); |
| 236 |
|
| 237 |
if (at == NULL) |
| 238 |
return; |
| 239 |
|
| 240 |
op = stop_item (op); |
| 241 |
if (op == NULL) |
| 242 |
return; |
| 243 |
|
| 244 |
object *tmp = present_arch (at, op->map, op->x, op->y); |
| 245 |
if (!tmp) |
| 246 |
{ |
| 247 |
tmp = arch_to_object (at); |
| 248 |
tmp->x = op->x, tmp->y = op->y; |
| 249 |
/* This was in the old (pre new movement code) - |
| 250 |
* icecubes have slow_move set to 1 - don't want |
| 251 |
* that for ones we create. |
| 252 |
*/ |
| 253 |
tmp->move_slow_penalty = 0; |
| 254 |
tmp->move_slow = 0; |
| 255 |
insert_ob_in_map (tmp, op->map, originator, 0); |
| 256 |
} |
| 257 |
|
| 258 |
tmp->insert (op); |
| 259 |
return; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
/* Object op is hitting the map. |
| 264 |
* op is going in direction 'dir' |
| 265 |
* type is the attacktype of the object. |
| 266 |
* full_hit is set if monster area does not matter. |
| 267 |
* returns 1 if it hits something, 0 otherwise. |
| 268 |
*/ |
| 269 |
int |
| 270 |
hit_map (object *op, int dir, int type, int full_hit) |
| 271 |
{ |
| 272 |
maptile *map; |
| 273 |
sint16 x, y; |
| 274 |
int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ |
| 275 |
|
| 276 |
if (QUERY_FLAG (op, FLAG_FREED)) |
| 277 |
{ |
| 278 |
LOG (llevError, "BUG: hit_map(): free object\n"); |
| 279 |
return 0; |
| 280 |
} |
| 281 |
|
| 282 |
if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) |
| 283 |
{ |
| 284 |
LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); |
| 285 |
return 0; |
| 286 |
} |
| 287 |
|
| 288 |
if (!op->map) |
| 289 |
{ |
| 290 |
LOG (llevError, "BUG: hit_map(): %s has no map\n", &op->name); |
| 291 |
return 0; |
| 292 |
} |
| 293 |
|
| 294 |
if (op->head) |
| 295 |
op = op->head; |
| 296 |
|
| 297 |
mapxy pos (op); |
| 298 |
pos.move (dir); |
| 299 |
|
| 300 |
if (!pos.normalise ()) |
| 301 |
return 0; |
| 302 |
|
| 303 |
// elmex: a safe map tile can't be hit! |
| 304 |
// this should prevent most harmful effects on items and players there. |
| 305 |
mapspace &ms = pos.ms (); |
| 306 |
|
| 307 |
if (ms.flags () & P_SAFE) |
| 308 |
return 0; |
| 309 |
|
| 310 |
/* peterm: a few special cases for special attacktypes --counterspell |
| 311 |
* must be out here because it strikes things which are not alive |
| 312 |
*/ |
| 313 |
if (type & (AT_COUNTERSPELL | AT_CHAOS)) |
| 314 |
{ |
| 315 |
if (type & AT_COUNTERSPELL) |
| 316 |
{ |
| 317 |
counterspell (op, dir); /* see spell_effect.c */ |
| 318 |
|
| 319 |
/* If the only attacktype is counterspell or magic, don't need |
| 320 |
* to do any further processing. |
| 321 |
*/ |
| 322 |
if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC))) |
| 323 |
return 0; |
| 324 |
|
| 325 |
type &= ~AT_COUNTERSPELL; |
| 326 |
} |
| 327 |
|
| 328 |
if (type & AT_CHAOS) |
| 329 |
{ |
| 330 |
shuffle_attack (op, 1); /* flag tells it to change the face */ |
| 331 |
update_object (op, UP_OBJ_FACE); |
| 332 |
type &= ~AT_CHAOS; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
/* There may still be objects that were above 'next', but there is no |
| 337 |
* simple way to find out short of copying all object references and |
| 338 |
* tags into a temporary array before we start processing the first |
| 339 |
* object. That's why we just abort on destroy. |
| 340 |
* |
| 341 |
* This happens whenever attack spells (like fire) hit a pile |
| 342 |
* of objects. This is not a bug - nor an error. |
| 343 |
*/ |
| 344 |
for (object *next = ms.bot; next && !next->destroyed (); ) |
| 345 |
{ |
| 346 |
object *tmp = next; |
| 347 |
next = tmp->above; |
| 348 |
|
| 349 |
/* Something could have happened to 'tmp' while 'tmp->below' was processed. |
| 350 |
* For example, 'tmp' was put in an icecube. |
| 351 |
* This is one of the few cases where on_same_map should not be used. |
| 352 |
*/ |
| 353 |
if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) |
| 354 |
continue; |
| 355 |
|
| 356 |
if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
| 357 |
{ |
| 358 |
hit_player (tmp, op->stats.dam, op, type, full_hit); |
| 359 |
retflag |= 1; |
| 360 |
|
| 361 |
if (op->destroyed ()) |
| 362 |
break; |
| 363 |
} |
| 364 |
/* Here we are potentially destroying an object. If the object has |
| 365 |
* NO_PASS set, it is also immune - you can't destroy walls. Note |
| 366 |
* that weak walls have is_alive set, which prevent objects from |
| 367 |
* passing over/through them. We don't care what type of movement |
| 368 |
* the wall blocks - if it blocks any type of movement, can't be |
| 369 |
* destroyed right now. |
| 370 |
*/ |
| 371 |
else if (tmp->materialname && op->stats.dam > 0 && !tmp->move_block) |
| 372 |
{ |
| 373 |
save_throw_object (tmp, type, op); |
| 374 |
|
| 375 |
if (op->destroyed ()) |
| 376 |
break; |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
return 0; |
| 381 |
} |
| 382 |
|
| 383 |
void |
| 384 |
attack_message (int dam, int type, object *op, object *hitter) |
| 385 |
{ |
| 386 |
char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF]; |
| 387 |
int i, found = 0; |
| 388 |
maptile *map; |
| 389 |
object *next, *tmp; |
| 390 |
|
| 391 |
/* put in a few special messages for some of the common attacktypes |
| 392 |
* a player might have. For example, fire, electric, cold, etc |
| 393 |
* [garbled 20010919] |
| 394 |
*/ |
| 395 |
|
| 396 |
if (dam == 9998 && op->type == DOOR) |
| 397 |
{ |
| 398 |
sprintf (buf1, "unlock %s", &op->name); |
| 399 |
sprintf (buf2, " unlocks"); |
| 400 |
found++; |
| 401 |
} |
| 402 |
if (dam < 0) |
| 403 |
{ |
| 404 |
sprintf (buf1, "hit %s", &op->name); |
| 405 |
sprintf (buf2, " hits"); |
| 406 |
found++; |
| 407 |
} |
| 408 |
else if (dam == 0) |
| 409 |
{ |
| 410 |
sprintf (buf1, "missed %s", &op->name); |
| 411 |
sprintf (buf2, " misses"); |
| 412 |
found++; |
| 413 |
} |
| 414 |
else if ((hitter->type == DISEASE || hitter->type == SYMPTOM || |
| 415 |
hitter->type == POISONING || (type & AT_POISON && op->is_alive ())) && !found) |
| 416 |
{ |
| 417 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++) |
| 418 |
if (dam < attack_mess[ATM_SUFFER][i].level || attack_mess[ATM_SUFFER][i + 1].level == -1) |
| 419 |
{ |
| 420 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, &op->name, attack_mess[ATM_SUFFER][i].buf2); |
| 421 |
strcpy (buf2, attack_mess[ATM_SUFFER][i].buf3); |
| 422 |
found++; |
| 423 |
break; |
| 424 |
} |
| 425 |
} |
| 426 |
else if (op->type == DOOR && !found) |
| 427 |
{ |
| 428 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DOOR][i].level != -1; i++) |
| 429 |
if (dam < attack_mess[ATM_DOOR][i].level || attack_mess[ATM_DOOR][i + 1].level == -1) |
| 430 |
{ |
| 431 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_DOOR][i].buf1, &op->name, attack_mess[ATM_DOOR][i].buf2); |
| 432 |
strcpy (buf2, attack_mess[ATM_DOOR][i].buf3); |
| 433 |
found++; |
| 434 |
break; |
| 435 |
} |
| 436 |
} |
| 437 |
else if (hitter->type == PLAYER && op->is_alive ()) |
| 438 |
{ |
| 439 |
if (USING_SKILL (hitter, SK_KARATE)) |
| 440 |
{ |
| 441 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++) |
| 442 |
if (dam < attack_mess[ATM_KARATE][i].level || attack_mess[ATM_KARATE][i + 1].level == -1) |
| 443 |
{ |
| 444 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_KARATE][i].buf1, &op->name, attack_mess[ATM_KARATE][i].buf2); |
| 445 |
strcpy (buf2, attack_mess[ATM_KARATE][i].buf3); |
| 446 |
found++; |
| 447 |
break; |
| 448 |
} |
| 449 |
} |
| 450 |
else if (USING_SKILL (hitter, SK_CLAWING)) |
| 451 |
{ |
| 452 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_CLAW][i].level != -1; i++) |
| 453 |
if (dam < attack_mess[ATM_CLAW][i].level || attack_mess[ATM_CLAW][i + 1].level == -1) |
| 454 |
{ |
| 455 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_CLAW][i].buf1, &op->name, attack_mess[ATM_CLAW][i].buf2); |
| 456 |
strcpy (buf2, attack_mess[ATM_CLAW][i].buf3); |
| 457 |
found++; |
| 458 |
break; |
| 459 |
} |
| 460 |
} |
| 461 |
else if (USING_SKILL (hitter, SK_PUNCHING)) |
| 462 |
{ |
| 463 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_PUNCH][i].level != -1; i++) |
| 464 |
if (dam < attack_mess[ATM_PUNCH][i].level || attack_mess[ATM_PUNCH][i + 1].level == -1) |
| 465 |
{ |
| 466 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_PUNCH][i].buf1, &op->name, attack_mess[ATM_PUNCH][i].buf2); |
| 467 |
strcpy (buf2, attack_mess[ATM_PUNCH][i].buf3); |
| 468 |
found++; |
| 469 |
break; |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
if (found) |
| 475 |
{ |
| 476 |
/* done */ |
| 477 |
} |
| 478 |
else if (hitter->is_arrow () && (type == AT_PHYSICAL || type == AT_MAGIC)) |
| 479 |
{ |
| 480 |
sprintf (buf1, "hit"); /* just in case */ |
| 481 |
for (i = 0; i < MAXATTACKMESS; i++) |
| 482 |
if (dam < attack_mess[ATM_ARROW][i].level || attack_mess[ATM_ARROW][i + 1].level == -1) |
| 483 |
{ |
| 484 |
strcpy (buf2, attack_mess[ATM_ARROW][i].buf3); |
| 485 |
found++; |
| 486 |
break; |
| 487 |
} |
| 488 |
} |
| 489 |
else if (type & AT_DRAIN && op->is_alive ()) |
| 490 |
{ |
| 491 |
/* drain is first, because some items have multiple attypes */ |
| 492 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++) |
| 493 |
if (dam < attack_mess[ATM_DRAIN][i].level || attack_mess[ATM_DRAIN][i + 1].level == -1) |
| 494 |
{ |
| 495 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_DRAIN][i].buf1, &op->name, attack_mess[ATM_DRAIN][i].buf2); |
| 496 |
strcpy (buf2, attack_mess[ATM_DRAIN][i].buf3); |
| 497 |
found++; |
| 498 |
break; |
| 499 |
} |
| 500 |
} |
| 501 |
else if (type & AT_ELECTRICITY && op->is_alive ()) |
| 502 |
{ |
| 503 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++) |
| 504 |
if (dam < attack_mess[ATM_ELEC][i].level || attack_mess[ATM_ELEC][i + 1].level == -1) |
| 505 |
{ |
| 506 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_ELEC][i].buf1, &op->name, attack_mess[ATM_ELEC][i].buf2); |
| 507 |
strcpy (buf2, attack_mess[ATM_ELEC][i].buf3); |
| 508 |
found++; |
| 509 |
break; |
| 510 |
} |
| 511 |
} |
| 512 |
else if (type & AT_COLD && op->is_alive ()) |
| 513 |
{ |
| 514 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++) |
| 515 |
if (dam < attack_mess[ATM_COLD][i].level || attack_mess[ATM_COLD][i + 1].level == -1) |
| 516 |
{ |
| 517 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_COLD][i].buf1, &op->name, attack_mess[ATM_COLD][i].buf2); |
| 518 |
strcpy (buf2, attack_mess[ATM_COLD][i].buf3); |
| 519 |
found++; |
| 520 |
break; |
| 521 |
} |
| 522 |
} |
| 523 |
else if (type & AT_FIRE) |
| 524 |
{ |
| 525 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_FIRE][i].level != -1; i++) |
| 526 |
if (dam < attack_mess[ATM_FIRE][i].level || attack_mess[ATM_FIRE][i + 1].level == -1) |
| 527 |
{ |
| 528 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_FIRE][i].buf1, &op->name, attack_mess[ATM_FIRE][i].buf2); |
| 529 |
strcpy (buf2, attack_mess[ATM_FIRE][i].buf3); |
| 530 |
found++; |
| 531 |
break; |
| 532 |
} |
| 533 |
} |
| 534 |
else if (hitter->current_weapon != NULL) |
| 535 |
{ |
| 536 |
int mtype; |
| 537 |
|
| 538 |
switch (hitter->current_weapon->weapontype) |
| 539 |
{ |
| 540 |
case WEAP_HIT: |
| 541 |
mtype = ATM_BASIC; |
| 542 |
break; |
| 543 |
case WEAP_SLASH: |
| 544 |
mtype = ATM_SLASH; |
| 545 |
break; |
| 546 |
case WEAP_PIERCE: |
| 547 |
mtype = ATM_PIERCE; |
| 548 |
break; |
| 549 |
case WEAP_CLEAVE: |
| 550 |
mtype = ATM_CLEAVE; |
| 551 |
break; |
| 552 |
case WEAP_SLICE: |
| 553 |
mtype = ATM_SLICE; |
| 554 |
break; |
| 555 |
case WEAP_STAB: |
| 556 |
mtype = ATM_STAB; |
| 557 |
break; |
| 558 |
case WEAP_WHIP: |
| 559 |
mtype = ATM_WHIP; |
| 560 |
break; |
| 561 |
case WEAP_CRUSH: |
| 562 |
mtype = ATM_CRUSH; |
| 563 |
break; |
| 564 |
case WEAP_BLUD: |
| 565 |
mtype = ATM_BLUD; |
| 566 |
break; |
| 567 |
default: |
| 568 |
mtype = ATM_BASIC; |
| 569 |
break; |
| 570 |
} |
| 571 |
|
| 572 |
for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
| 573 |
if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) |
| 574 |
{ |
| 575 |
sprintf (buf1, "%s %s%s", attack_mess[mtype][i].buf1, &op->name, attack_mess[mtype][i].buf2); |
| 576 |
strcpy (buf2, attack_mess[mtype][i].buf3); |
| 577 |
found++; |
| 578 |
break; |
| 579 |
} |
| 580 |
} |
| 581 |
else |
| 582 |
{ |
| 583 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_BASIC][i].level != -1; i++) |
| 584 |
if (dam < attack_mess[ATM_BASIC][i].level || attack_mess[ATM_BASIC][i + 1].level == -1) |
| 585 |
{ |
| 586 |
sprintf (buf1, "%s %s%s", attack_mess[ATM_BASIC][i].buf1, &op->name, attack_mess[ATM_BASIC][i].buf2); |
| 587 |
strcpy (buf2, attack_mess[ATM_BASIC][i].buf3); |
| 588 |
found++; |
| 589 |
break; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
if (!found) |
| 594 |
{ |
| 595 |
strcpy (buf1, "hit"); |
| 596 |
strcpy (buf2, " hits"); |
| 597 |
} |
| 598 |
|
| 599 |
/* bail out if a monster is casting spells */ |
| 600 |
if (!(hitter->type == PLAYER || (hitter->owner != NULL && hitter->owner->type == PLAYER))) |
| 601 |
return; |
| 602 |
|
| 603 |
/* scale down magic considerably. */ |
| 604 |
if (type & AT_MAGIC && rndm (0, 5)) |
| 605 |
return; |
| 606 |
|
| 607 |
/* Did a player hurt another player? Inform both! */ |
| 608 |
if (op->type == PLAYER && (hitter->owner == NULL ? hitter->type : hitter->owner->type) == PLAYER) |
| 609 |
{ |
| 610 |
if (hitter->owner != NULL) |
| 611 |
sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2); |
| 612 |
else |
| 613 |
{ |
| 614 |
sprintf (buf, "%s%s you.", &hitter->name, buf2); |
| 615 |
|
| 616 |
if (dam != 0) |
| 617 |
{ |
| 618 |
if (dam < 10) |
| 619 |
op->contr->play_sound (sound_find ("player_is_hit1")); |
| 620 |
else if (dam < 20) |
| 621 |
op->contr->play_sound (sound_find ("player_is_hit2")); |
| 622 |
else |
| 623 |
op->contr->play_sound (sound_find ("player_is_hit3")); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
new_draw_info (NDI_BLACK, 0, op, buf); |
| 628 |
} /* end of player hitting player */ |
| 629 |
|
| 630 |
if (hitter->type == PLAYER) |
| 631 |
{ |
| 632 |
sprintf (buf, "You %s.", buf1); |
| 633 |
|
| 634 |
if (dam != 0) |
| 635 |
{ |
| 636 |
if (dam < 10) |
| 637 |
op->play_sound (sound_find ("player_hits1")); |
| 638 |
else if (dam < 20) |
| 639 |
op->play_sound (sound_find ("player_hits2")); |
| 640 |
else |
| 641 |
op->play_sound (sound_find ("player_hits3")); |
| 642 |
} |
| 643 |
|
| 644 |
new_draw_info (NDI_BLACK, 0, hitter, buf); |
| 645 |
} |
| 646 |
else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
| 647 |
{ |
| 648 |
/* look for stacked spells and start reducing the message chances */ |
| 649 |
if (hitter->type == SPELL_EFFECT && (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE)) |
| 650 |
{ |
| 651 |
i = 4; |
| 652 |
map = hitter->map; |
| 653 |
if (out_of_map (map, hitter->x, hitter->y)) |
| 654 |
return; |
| 655 |
|
| 656 |
next = GET_MAP_OB (map, hitter->x, hitter->y); |
| 657 |
if (next) |
| 658 |
while (next) |
| 659 |
{ |
| 660 |
if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) |
| 661 |
i *= 3; |
| 662 |
|
| 663 |
tmp = next; |
| 664 |
next = tmp->above; |
| 665 |
} |
| 666 |
|
| 667 |
if (i < 0) |
| 668 |
return; |
| 669 |
|
| 670 |
if (rndm (0, i) != 0) |
| 671 |
return; |
| 672 |
} |
| 673 |
else if (rndm (0, 5) != 0) |
| 674 |
return; |
| 675 |
|
| 676 |
sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name); |
| 677 |
op->play_sound (sound_find ("player_hits4")); |
| 678 |
new_draw_info (NDI_BLACK, 0, hitter->owner, buf); |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
static int |
| 684 |
get_attack_mode (object **target, object **hitter, int *simple_attack) |
| 685 |
{ |
| 686 |
if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
| 687 |
{ |
| 688 |
LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
| 689 |
return 1; |
| 690 |
} |
| 691 |
|
| 692 |
if ((*target)->head) |
| 693 |
*target = (*target)->head; |
| 694 |
|
| 695 |
if ((*hitter)->head) |
| 696 |
*hitter = (*hitter)->head; |
| 697 |
|
| 698 |
if ((*target)->type == LOCKED_DOOR) |
| 699 |
return 1; // locked doors cannot be hit |
| 700 |
|
| 701 |
if ((*hitter)->env || (*target)->env) |
| 702 |
{ |
| 703 |
*simple_attack = 1; |
| 704 |
return 0; |
| 705 |
} |
| 706 |
|
| 707 |
if (QUERY_FLAG (*target, FLAG_REMOVED) |
| 708 |
|| QUERY_FLAG (*hitter, FLAG_REMOVED) |
| 709 |
|| !(*hitter)->map |
| 710 |
|| !on_same_map (*hitter, *target)) |
| 711 |
{ |
| 712 |
LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", |
| 713 |
(*hitter)->debug_desc (), (*target)->debug_desc ()); |
| 714 |
return 1; |
| 715 |
} |
| 716 |
|
| 717 |
*simple_attack = 0; |
| 718 |
return 0; |
| 719 |
} |
| 720 |
|
| 721 |
static int |
| 722 |
abort_attack (object *target, object *hitter, int simple_attack) |
| 723 |
{ |
| 724 |
|
| 725 |
/* Check if target and hitter are still in a relation similar to the one |
| 726 |
* determined by get_attack_mode(). Returns true if the relation has changed. |
| 727 |
*/ |
| 728 |
int new_mode; |
| 729 |
|
| 730 |
if (hitter->env == target || target->env == hitter) |
| 731 |
new_mode = 1; |
| 732 |
else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) || hitter->map == NULL || !on_same_map (hitter, target)) |
| 733 |
return 1; |
| 734 |
else |
| 735 |
new_mode = 0; |
| 736 |
return new_mode != simple_attack; |
| 737 |
} |
| 738 |
|
| 739 |
static void thrown_item_effect (object *, object *); |
| 740 |
|
| 741 |
static int |
| 742 |
attack_ob_simple (object *op, object *hitter, int base_dam, int base_wc) |
| 743 |
{ |
| 744 |
int simple_attack, roll, dam = 0; |
| 745 |
uint32 type; |
| 746 |
shstr op_name; |
| 747 |
|
| 748 |
if (get_attack_mode (&op, &hitter, &simple_attack)) |
| 749 |
goto error; |
| 750 |
|
| 751 |
if (hitter->current_weapon) |
| 752 |
if (INVOKE_OBJECT (WEAPON_ATTACK, hitter->current_weapon, ARG_OBJECT (hitter), ARG_OBJECT (op))) |
| 753 |
return RESULT_INT (0); |
| 754 |
|
| 755 |
if (INVOKE_OBJECT (ATTACK, op, ARG_OBJECT (hitter))) |
| 756 |
return RESULT_INT (0); |
| 757 |
|
| 758 |
/* |
| 759 |
* A little check to make it more difficult to dance forward and back |
| 760 |
* to avoid ever being hit by monsters. |
| 761 |
*/ |
| 762 |
if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > abs (op->speed) * -0.3f) |
| 763 |
{ |
| 764 |
/* Decrease speed BEFORE calling process_object. Otherwise, an |
| 765 |
* infinite loop occurs, with process_object calling move_monster, |
| 766 |
* which then gets here again. By decreasing the speed before |
| 767 |
* we call process_object, the 'if' statement above will fail. |
| 768 |
*/ |
| 769 |
--op->speed_left; |
| 770 |
process_object (op); |
| 771 |
|
| 772 |
if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack)) |
| 773 |
goto error; |
| 774 |
} |
| 775 |
|
| 776 |
op_name = op->name; |
| 777 |
|
| 778 |
roll = random_roll (1, 20, hitter, PREFER_HIGH); |
| 779 |
|
| 780 |
/* Adjust roll for various situations. */ |
| 781 |
if (!simple_attack) |
| 782 |
roll += adj_attackroll (hitter, op); |
| 783 |
|
| 784 |
/* See if we hit the creature */ |
| 785 |
if (roll == 20 || op->stats.ac >= base_wc - roll) |
| 786 |
{ |
| 787 |
int hitdam = base_dam; |
| 788 |
|
| 789 |
if (!simple_attack) |
| 790 |
{ |
| 791 |
/* If you hit something, the victim should *always* wake up. |
| 792 |
* Before, invisible hitters could avoid doing this. |
| 793 |
* -b.t. */ |
| 794 |
if (QUERY_FLAG (op, FLAG_SLEEP)) |
| 795 |
CLEAR_FLAG (op, FLAG_SLEEP); |
| 796 |
|
| 797 |
/* If the victim can't see the attacker, it may alert others |
| 798 |
* for help. */ |
| 799 |
if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
| 800 |
npc_call_help (op); |
| 801 |
|
| 802 |
/* if you were hidden and hit by a creature, you are discovered */ |
| 803 |
if (op->flag [FLAG_HIDDEN] && hitter->flag [FLAG_ALIVE]) |
| 804 |
{ |
| 805 |
make_visible (op); |
| 806 |
|
| 807 |
if (op->type == PLAYER) |
| 808 |
new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. You are no longer hidden!"); |
| 809 |
} |
| 810 |
|
| 811 |
/* thrown items (hitter) will have various effects |
| 812 |
* when they hit the victim. For things like thrown daggers, |
| 813 |
* this sets 'hitter' to the actual dagger, and not the |
| 814 |
* wrapper object. |
| 815 |
*/ |
| 816 |
thrown_item_effect (hitter, op); |
| 817 |
|
| 818 |
if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) |
| 819 |
goto leave; |
| 820 |
} |
| 821 |
|
| 822 |
/* Need to do at least 1 damage, otherwise there is no point |
| 823 |
* to go further and it will cause FPE's below. |
| 824 |
*/ |
| 825 |
if (hitdam <= 0) |
| 826 |
hitdam = 1; |
| 827 |
|
| 828 |
type = hitter->attacktype; |
| 829 |
|
| 830 |
/* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
| 831 |
* Crossfire we have to default the attacktype here to AT_PHYSICAL. |
| 832 |
* This check is important for the most simple monsters out there in the |
| 833 |
* game content (maps, archs). For example orcs: They would have |
| 834 |
* no attacktype at all. |
| 835 |
* |
| 836 |
* Some time in the future someone should just go into the game data |
| 837 |
* and fix every monster out there ;-/ Until then we will kill some |
| 838 |
* more trees in the african rain forests with this check. |
| 839 |
*/ |
| 840 |
if (!type) |
| 841 |
type = AT_PHYSICAL; |
| 842 |
|
| 843 |
/* Handle monsters that hit back */ |
| 844 |
if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) |
| 845 |
{ |
| 846 |
if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
| 847 |
new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); |
| 848 |
|
| 849 |
hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
| 850 |
|
| 851 |
if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack)) |
| 852 |
goto leave; |
| 853 |
} |
| 854 |
|
| 855 |
/* In the new attack code, it should handle multiple attack |
| 856 |
* types in its area, so remove it from here. |
| 857 |
*/ |
| 858 |
dam = hit_player (op, random_roll (1, hitdam, hitter, PREFER_HIGH), hitter, type, 1); |
| 859 |
|
| 860 |
if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack)) |
| 861 |
goto leave; |
| 862 |
} /* end of if hitter hit op */ |
| 863 |
/* if we missed, dam=0 */ |
| 864 |
|
| 865 |
/*attack_message(dam, type, op, hitter); */ |
| 866 |
|
| 867 |
goto leave; |
| 868 |
|
| 869 |
error: |
| 870 |
dam = 1; |
| 871 |
|
| 872 |
leave: |
| 873 |
|
| 874 |
return dam; |
| 875 |
} |
| 876 |
|
| 877 |
int |
| 878 |
attack_ob (object *op, object *hitter) |
| 879 |
{ |
| 880 |
hitter = hitter->head_ (); |
| 881 |
|
| 882 |
return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); |
| 883 |
} |
| 884 |
|
| 885 |
/* op is the arrow, tmp is what is stopping the arrow. |
| 886 |
* |
| 887 |
* Returns 1 if op was inserted into tmp's inventory, 0 otherwise. |
| 888 |
*/ |
| 889 |
static int |
| 890 |
stick_arrow (object *op, object *tmp) |
| 891 |
{ |
| 892 |
/* If the missile hit a player, we insert it in their inventory. |
| 893 |
* However, if the missile is heavy, we don't do so (assume it falls |
| 894 |
* to the ground after a hit). What a good value for this is up to |
| 895 |
* debate - 5000 is 5 kg, so arrows, knives, and other light weapons |
| 896 |
* stick around. |
| 897 |
*/ |
| 898 |
if (op->weight <= 5000 && tmp->stats.hp >= 0) |
| 899 |
{ |
| 900 |
tmp->head_ ()->insert (op); |
| 901 |
return 1; |
| 902 |
} |
| 903 |
else |
| 904 |
return 0; |
| 905 |
} |
| 906 |
|
| 907 |
/* hit_with_arrow() disassembles the missile, attacks the victim and |
| 908 |
* reassembles the missile. |
| 909 |
* |
| 910 |
* It returns a pointer to the reassembled missile, or NULL if the missile |
| 911 |
* isn't available anymore. |
| 912 |
*/ |
| 913 |
object * |
| 914 |
hit_with_arrow (object *op, object *victim) |
| 915 |
{ |
| 916 |
object *container, *hitter; |
| 917 |
int hit_something = 0; |
| 918 |
|
| 919 |
/* Disassemble missile */ |
| 920 |
if (op->inv) |
| 921 |
{ |
| 922 |
container = op; |
| 923 |
hitter = op->inv; |
| 924 |
hitter->insert_at (container, hitter, INS_NO_MERGE | INS_NO_WALK_ON); |
| 925 |
/* Note that we now have an empty THROWN_OBJ on the map. Code that |
| 926 |
* might be called until this THROWN_OBJ is either reassembled or |
| 927 |
* removed at the end of this function must be able to deal with empty |
| 928 |
* THROWN_OBJs. */ |
| 929 |
} |
| 930 |
else |
| 931 |
{ |
| 932 |
container = 0; |
| 933 |
hitter = op; |
| 934 |
} |
| 935 |
|
| 936 |
/* Try to hit victim */ |
| 937 |
hit_something = attack_ob_simple (victim, hitter, op->stats.dam, op->stats.wc); |
| 938 |
|
| 939 |
/* Arrow attacks door, rune of summoning is triggered, demon is put on |
| 940 |
* arrow, move_apply() calls this function, arrow sticks in demon, |
| 941 |
* attack_ob_simple() returns, and we've got an arrow that still exists |
| 942 |
* but is no longer on the map. Ugh. (Beware: Such things can happen at |
| 943 |
* other places as well!) |
| 944 |
*/ |
| 945 |
if (hitter->destroyed () || hitter->env != NULL) |
| 946 |
{ |
| 947 |
if (container) |
| 948 |
container->destroy (); |
| 949 |
|
| 950 |
return 0; |
| 951 |
} |
| 952 |
|
| 953 |
/* Missile hit victim */ |
| 954 |
/* if the speed is > 10, then this is a fast moving arrow, we go straight |
| 955 |
* through the target |
| 956 |
*/ |
| 957 |
if (hit_something && op->speed <= 10.0) |
| 958 |
{ |
| 959 |
/* Stop arrow */ |
| 960 |
if (!container) |
| 961 |
{ |
| 962 |
hitter = fix_stopped_arrow (hitter); |
| 963 |
if (!hitter) |
| 964 |
return 0; |
| 965 |
} |
| 966 |
else |
| 967 |
container->destroy (); |
| 968 |
|
| 969 |
/* Try to stick arrow into victim */ |
| 970 |
if (!victim->destroyed () && stick_arrow (hitter, victim)) |
| 971 |
return 0; |
| 972 |
|
| 973 |
/* Else try to put arrow on victim's map square |
| 974 |
* remove check for P_WALL here. If the arrow got to this |
| 975 |
* space, that is good enough - with the new movement code, |
| 976 |
* there is now the potential for lots of spaces where something |
| 977 |
* can fly over but not otherwise move over. What is the correct |
| 978 |
* way to handle those otherwise? |
| 979 |
*/ |
| 980 |
if (victim->x != hitter->x || victim->y != hitter->y) |
| 981 |
{ |
| 982 |
if (victim->destroyed ()) |
| 983 |
hitter->destroy (); |
| 984 |
else |
| 985 |
{ |
| 986 |
hitter->remove (); |
| 987 |
hitter->x = victim->x; |
| 988 |
hitter->y = victim->y; |
| 989 |
insert_ob_in_map (hitter, victim->map, hitter, 0); |
| 990 |
} |
| 991 |
} |
| 992 |
else |
| 993 |
/* Else leave arrow where it is */ |
| 994 |
merge_ob (hitter, NULL); |
| 995 |
|
| 996 |
return 0; |
| 997 |
} |
| 998 |
|
| 999 |
if (hit_something && op->speed >= 10.0) |
| 1000 |
op->speed -= 1.0; |
| 1001 |
|
| 1002 |
/* Missile missed victim - reassemble missile */ |
| 1003 |
if (container) |
| 1004 |
{ |
| 1005 |
hitter->remove (); |
| 1006 |
insert_ob_in_ob (hitter, container); |
| 1007 |
} |
| 1008 |
|
| 1009 |
return op; |
| 1010 |
} |
| 1011 |
|
| 1012 |
void |
| 1013 |
tear_down_wall (object *op) |
| 1014 |
{ |
| 1015 |
if (!op->stats.maxhp) |
| 1016 |
LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name); |
| 1017 |
else if (!op->has_anim ()) |
| 1018 |
{ |
| 1019 |
/* Object has been called - no animations, so remove it */ |
| 1020 |
if (op->stats.hp < 0) |
| 1021 |
op->destroy (); |
| 1022 |
|
| 1023 |
return; /* no animations, so nothing more to do */ |
| 1024 |
} |
| 1025 |
|
| 1026 |
// we use frames 1..num-2 as intermediate frames, so |
| 1027 |
// the last frame is used only when hp < 0. |
| 1028 |
int perc = clamp ( |
| 1029 |
lerp_ru<int> (op->stats.hp, 0, op->stats.maxhp, op->anim_frames () - 2, 0), |
| 1030 |
0, op->anim_frames () - 1 |
| 1031 |
); |
| 1032 |
|
| 1033 |
op->set_anim_frame (perc); |
| 1034 |
update_object (op, UP_OBJ_FACE); |
| 1035 |
|
| 1036 |
if (op->stats.hp < 0) |
| 1037 |
{ /* Reached the last animation */ |
| 1038 |
if (op->face == blank_face) |
| 1039 |
/* If the last face is blank, remove the ob */ |
| 1040 |
op->destroy (); |
| 1041 |
else |
| 1042 |
{ /* The last face was not blank, leave an image */ |
| 1043 |
op->flag [FLAG_BLOCKSVIEW] = false; |
| 1044 |
update_all_los (op->map, op->x, op->y); |
| 1045 |
op->move_block = 0; |
| 1046 |
op->flag [FLAG_ALIVE] = false; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
void |
| 1052 |
scare_creature (object *target, object *hitter) |
| 1053 |
{ |
| 1054 |
target->flag [FLAG_SCARED] = true; |
| 1055 |
|
| 1056 |
if (!target->enemy) |
| 1057 |
target->enemy = hitter->outer_owner (); |
| 1058 |
} |
| 1059 |
|
| 1060 |
/* This returns the amount of damage hitter does to op with the |
| 1061 |
* appropriate attacktype. Only 1 attacktype should be set at a time. |
| 1062 |
* This doesn't damage the player, but returns how much it should |
| 1063 |
* take. However, it will do other effects (paralyzation, slow, etc.) |
| 1064 |
* Note - changed for PR code - we now pass the attack number and not |
| 1065 |
* the attacktype. Makes it easier for the PR code. */ |
| 1066 |
int |
| 1067 |
hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic) |
| 1068 |
{ |
| 1069 |
int doesnt_slay = 1; |
| 1070 |
|
| 1071 |
/* Catch anyone that may be trying to send us a bitmask instead of the number */ |
| 1072 |
if (attacknum >= NROFATTACKS) |
| 1073 |
{ |
| 1074 |
LOG (llevError, "hit_player_attacktype: Invalid attacknumber passed: %u\n", attacknum); |
| 1075 |
return 0; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (dam < 0) |
| 1079 |
{ |
| 1080 |
LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n", |
| 1081 |
dam, hitter->debug_desc (), op->debug_desc ()); |
| 1082 |
return 0; |
| 1083 |
} |
| 1084 |
|
| 1085 |
/* AT_INTERNAL is supposed to do exactly dam. Put a case here so |
| 1086 |
* people can't mess with that or it otherwise get confused. */ |
| 1087 |
if (attacknum == ATNR_INTERNAL) |
| 1088 |
return dam; |
| 1089 |
|
| 1090 |
if (hitter->slaying) |
| 1091 |
{ |
| 1092 |
if ((op->race && hitter->slaying.contains (op->race)) |
| 1093 |
|| (op->arch && op->arch->archname.contains (hitter->slaying))) |
| 1094 |
{ |
| 1095 |
doesnt_slay = 0; |
| 1096 |
dam *= 3; |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
/* Adjust the damage for resistance. Note that neg. values increase damage. */ |
| 1101 |
if (op->resist[attacknum]) |
| 1102 |
{ |
| 1103 |
/* basically: dam = dam*(100-op->resist[attacknum])/100; |
| 1104 |
* in case 0>dam>1, we try to "simulate" a float value-effect */ |
| 1105 |
dam *= (100 - op->resist[attacknum]); |
| 1106 |
if (dam >= 100) |
| 1107 |
dam /= 100; |
| 1108 |
else |
| 1109 |
dam = (dam > (random_roll (0, 99, op, PREFER_LOW))) ? 1 : 0; |
| 1110 |
} |
| 1111 |
|
| 1112 |
/* Special hack. By default, if immune to something, you |
| 1113 |
* shouldn't need to worry. However, acid is an exception, since |
| 1114 |
* it can still damage your items. Only include attacktypes if |
| 1115 |
* special processing is needed */ |
| 1116 |
|
| 1117 |
if (op->resist[attacknum] >= 100 |
| 1118 |
&& doesnt_slay |
| 1119 |
&& attacknum != ATNR_ACID) |
| 1120 |
return 0; |
| 1121 |
|
| 1122 |
/* Keep this in order - makes things easier to find */ |
| 1123 |
|
| 1124 |
switch (attacknum) |
| 1125 |
{ |
| 1126 |
case ATNR_PHYSICAL: |
| 1127 |
/* here also check for diseases */ |
| 1128 |
check_physically_infect (op, hitter); |
| 1129 |
break; |
| 1130 |
|
| 1131 |
/* Don't need to do anything for: |
| 1132 |
magic, |
| 1133 |
fire, |
| 1134 |
electricity, |
| 1135 |
cold */ |
| 1136 |
|
| 1137 |
case ATNR_CONFUSION: |
| 1138 |
case ATNR_POISON: |
| 1139 |
case ATNR_SLOW: |
| 1140 |
case ATNR_PARALYZE: |
| 1141 |
case ATNR_FEAR: |
| 1142 |
case ATNR_CANCELLATION: |
| 1143 |
case ATNR_DEPLETE: |
| 1144 |
case ATNR_BLIND: |
| 1145 |
{ |
| 1146 |
/* chance for inflicting a special attack depends on the |
| 1147 |
* difference between attacker's and defender's level |
| 1148 |
*/ |
| 1149 |
int level_diff = MIN (110, MAX (0, op->level - hitter->level)); |
| 1150 |
|
| 1151 |
/* First, only creatures/players with speed can be affected. |
| 1152 |
* Second, just getting hit doesn't mean it always affects |
| 1153 |
* you. Third, you still get a saving through against the |
| 1154 |
* effect. |
| 1155 |
*/ |
| 1156 |
if (op->speed && |
| 1157 |
(QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && |
| 1158 |
!(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
| 1159 |
{ |
| 1160 |
|
| 1161 |
/* Player has been hit by something */ |
| 1162 |
if (attacknum == ATNR_CONFUSION) |
| 1163 |
confuse_player (op, hitter, dam); |
| 1164 |
else if (attacknum == ATNR_POISON) |
| 1165 |
poison_player (op, hitter, dam); |
| 1166 |
else if (attacknum == ATNR_SLOW) |
| 1167 |
slow_player (op, hitter, dam); |
| 1168 |
else if (attacknum == ATNR_PARALYZE) |
| 1169 |
paralyze_player (op, hitter, dam); |
| 1170 |
else if (attacknum == ATNR_FEAR) |
| 1171 |
scare_creature (op, hitter); |
| 1172 |
else if (attacknum == ATNR_CANCELLATION) |
| 1173 |
cancellation (op); |
| 1174 |
else if (attacknum == ATNR_DEPLETE) |
| 1175 |
op->drain_stat (); |
| 1176 |
else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) |
| 1177 |
blind_player (op, hitter, dam); |
| 1178 |
} |
| 1179 |
|
| 1180 |
dam = 0; /* These are all effects and don't do real damage */ |
| 1181 |
} |
| 1182 |
break; |
| 1183 |
|
| 1184 |
case ATNR_ACID: |
| 1185 |
{ |
| 1186 |
int flag = 0; |
| 1187 |
|
| 1188 |
/* Items only get corroded if you're not on a battleground and |
| 1189 |
* if your acid resistance is below 50%. */ |
| 1190 |
if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50)) |
| 1191 |
{ |
| 1192 |
for (object *tmp = op->inv; tmp; tmp = tmp->below) |
| 1193 |
{ |
| 1194 |
if (tmp->invisible) |
| 1195 |
continue; |
| 1196 |
if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
| 1197 |
/* >= 10% acid res. on items will protect these */ |
| 1198 |
continue; |
| 1199 |
if (!(tmp->materials & M_IRON)) |
| 1200 |
continue; |
| 1201 |
if (tmp->magic < -4) /* Let's stop at -5 */ |
| 1202 |
continue; |
| 1203 |
if (tmp->type == RING |
| 1204 |
/* removed boots and gloves from exclusion list in PR */ |
| 1205 |
|| tmp->type == GIRDLE |
| 1206 |
|| tmp->type == AMULET |
| 1207 |
|| tmp->type == WAND |
| 1208 |
|| tmp->type == ROD |
| 1209 |
|| tmp->type == HORN) |
| 1210 |
continue; /* To avoid some strange effects */ |
| 1211 |
|
| 1212 |
/* High damage acid has better chance of corroding |
| 1213 |
objects */ |
| 1214 |
if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic) |
| 1215 |
{ |
| 1216 |
flag = 1; |
| 1217 |
tmp->magic--; |
| 1218 |
|
| 1219 |
if (object *pl = tmp->visible_to ()) |
| 1220 |
{ |
| 1221 |
/* Make this more visible */ |
| 1222 |
new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, pl, |
| 1223 |
"The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp)); |
| 1224 |
|
| 1225 |
esrv_send_item (op, tmp); //TODO: UPD_NAME should be enough (it's enough in other cases) |
| 1226 |
} |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
if (flag) |
| 1231 |
op->update_stats (); /* Something was corroded */ |
| 1232 |
} |
| 1233 |
} |
| 1234 |
break; |
| 1235 |
|
| 1236 |
case ATNR_DRAIN: |
| 1237 |
{ |
| 1238 |
/* rate is the proportion of exp drained. High rate means |
| 1239 |
* not much is drained, low rate means a lot is drained. |
| 1240 |
*/ |
| 1241 |
int rate; |
| 1242 |
|
| 1243 |
if (op->resist[ATNR_DRAIN] >= 0) |
| 1244 |
rate = 400 + op->resist[ATNR_DRAIN] * 3; |
| 1245 |
else |
| 1246 |
rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
| 1247 |
|
| 1248 |
if (op->stats.exp <= rate) |
| 1249 |
{ |
| 1250 |
if (op->type == GOLEM) |
| 1251 |
dam = 999; /* Its force is "sucked" away. 8) */ |
| 1252 |
else |
| 1253 |
/* If we can't drain, lets try to do physical damage */ |
| 1254 |
dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
| 1255 |
} |
| 1256 |
else |
| 1257 |
{ |
| 1258 |
/* Randomly give the hitter some hp */ |
| 1259 |
if (hitter->stats.hp < hitter->stats.maxhp && |
| 1260 |
(op->level > hitter->level) && random_roll (0, (op->level - hitter->level + 2), hitter, PREFER_HIGH) > 3) |
| 1261 |
hitter->stats.hp++; |
| 1262 |
|
| 1263 |
/* Can't do drains on battleground spaces. |
| 1264 |
* Move the wiz check up here - before, the hitter wouldn't gain exp |
| 1265 |
* exp, but the wiz would still lose exp! If drainee is a wiz, |
| 1266 |
* nothing happens. |
| 1267 |
* Try to credit the owner. We try to display player -> player drain |
| 1268 |
* attacks, hence all the != PLAYER checks. |
| 1269 |
*/ |
| 1270 |
if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
| 1271 |
{ |
| 1272 |
object *owner = hitter->owner; |
| 1273 |
|
| 1274 |
if (owner && owner != hitter) |
| 1275 |
{ |
| 1276 |
if (op->type != PLAYER || owner->type != PLAYER) |
| 1277 |
change_exp (owner, op->stats.exp / (rate * 2), |
| 1278 |
hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); |
| 1279 |
} |
| 1280 |
else if (op->type != PLAYER || hitter->type != PLAYER) |
| 1281 |
change_exp (hitter, op->stats.exp / (rate * 2), |
| 1282 |
hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
| 1283 |
|
| 1284 |
change_exp (op, -op->stats.exp / rate, NULL, 0); |
| 1285 |
} |
| 1286 |
|
| 1287 |
dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure |
| 1288 |
* drain attack, you won't know that you are actually sucking out EXP, |
| 1289 |
* as the messages will say you missed |
| 1290 |
*/ |
| 1291 |
} |
| 1292 |
} |
| 1293 |
break; |
| 1294 |
|
| 1295 |
case ATNR_TURN_UNDEAD: |
| 1296 |
{ |
| 1297 |
if (QUERY_FLAG (op, FLAG_UNDEAD)) |
| 1298 |
{ |
| 1299 |
object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
| 1300 |
object *god = find_god (determine_god (owner)); |
| 1301 |
int div = 1; |
| 1302 |
|
| 1303 |
/* if undead are not an enemy of your god, you turn them |
| 1304 |
* at half strength */ |
| 1305 |
if (!god || !god->slaying.contains (shstr_undead)) |
| 1306 |
div = 2; |
| 1307 |
|
| 1308 |
/* Give a bonus if you resist turn undead */ |
| 1309 |
if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) |
| 1310 |
scare_creature (op, owner); |
| 1311 |
} |
| 1312 |
else |
| 1313 |
dam = 0; /* don't damage non undead - should we damage |
| 1314 |
undead? */ |
| 1315 |
} |
| 1316 |
break; |
| 1317 |
|
| 1318 |
case ATNR_DEATH: |
| 1319 |
deathstrike_player (op, hitter, &dam); |
| 1320 |
break; |
| 1321 |
|
| 1322 |
case ATNR_CHAOS: |
| 1323 |
LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc ()); |
| 1324 |
dam = 0; |
| 1325 |
break; |
| 1326 |
|
| 1327 |
case ATNR_COUNTERSPELL: |
| 1328 |
LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc ()); |
| 1329 |
dam = 0; |
| 1330 |
/* This should never happen. Counterspell is handled |
| 1331 |
* seperately and filtered out. If this does happen, |
| 1332 |
* Counterspell has no effect on anything but spells, so it |
| 1333 |
* does no damage. */ |
| 1334 |
break; |
| 1335 |
|
| 1336 |
case ATNR_HOLYWORD: |
| 1337 |
{ |
| 1338 |
/* This has already been handled by hit_player, |
| 1339 |
* no need to check twice -- DAMN */ |
| 1340 |
object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
| 1341 |
|
| 1342 |
/* As with turn undead above, give a bonus on the saving throw */ |
| 1343 |
if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) |
| 1344 |
scare_creature (op, owner); |
| 1345 |
} |
| 1346 |
break; |
| 1347 |
|
| 1348 |
case ATNR_LIFE_STEALING: |
| 1349 |
{ |
| 1350 |
int new_hp; |
| 1351 |
|
| 1352 |
/* this is replacement to drain for players, instead of taking |
| 1353 |
* exp it takes hp. It is geared for players, probably not |
| 1354 |
* much use giving it to monsters |
| 1355 |
* |
| 1356 |
* life stealing doesn't do a lot of damage, but it gives the |
| 1357 |
* damage it does do to the player. Given that, |
| 1358 |
* it only does 1/10'th normal damage (hence the divide by |
| 1359 |
* 1000). |
| 1360 |
*/ |
| 1361 |
/* You can't steal life from something undead */ |
| 1362 |
if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
| 1363 |
return 0; |
| 1364 |
|
| 1365 |
/* If drain protection is higher than life stealing, use that */ |
| 1366 |
if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
| 1367 |
dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
| 1368 |
else |
| 1369 |
dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000; |
| 1370 |
|
| 1371 |
/* You die at -1 hp, not zero. */ |
| 1372 |
if (dam > (op->stats.hp + 1)) |
| 1373 |
dam = op->stats.hp + 1; |
| 1374 |
|
| 1375 |
new_hp = hitter->stats.hp + dam; |
| 1376 |
if (new_hp > hitter->stats.maxhp) |
| 1377 |
new_hp = hitter->stats.maxhp; |
| 1378 |
|
| 1379 |
if (new_hp > hitter->stats.hp) |
| 1380 |
hitter->stats.hp = new_hp; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
|
| 1384 |
return dam; |
| 1385 |
} |
| 1386 |
|
| 1387 |
/* GROS: This code comes from hit_player. It has been made external to |
| 1388 |
* allow script procedures to "kill" objects in a combat-like fashion. |
| 1389 |
* It was initially used by (kill-object) developed for the Collector's |
| 1390 |
* Sword. Note that nothing has been changed from the original version |
| 1391 |
* of the following code. |
| 1392 |
* op is what is being killed. |
| 1393 |
* dam is the damage done to it. |
| 1394 |
* hitter is what is hitting it. |
| 1395 |
* type is the attacktype. |
| 1396 |
* |
| 1397 |
* This function was a bit of a mess with hitter getting changed, |
| 1398 |
* values being stored away but not used, etc. I've cleaned it up |
| 1399 |
* a bit - I think it should be functionally equivalant. |
| 1400 |
* MSW 2002-07-17 |
| 1401 |
*/ |
| 1402 |
int |
| 1403 |
kill_object (object *op, int dam, object *hitter, int type) |
| 1404 |
{ |
| 1405 |
char buf[MAX_BUF]; |
| 1406 |
shstr skill; |
| 1407 |
int maxdam = 0; |
| 1408 |
int battleg = 0; /* true if op standing on battleground */ |
| 1409 |
int pk = 0; /* true if op and what controls hitter are both players */ |
| 1410 |
object *owner = 0; |
| 1411 |
object *skop = 0; |
| 1412 |
|
| 1413 |
if (op->stats.hp >= 0) |
| 1414 |
return -1; |
| 1415 |
|
| 1416 |
if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter))) |
| 1417 |
return 0; |
| 1418 |
|
| 1419 |
/* maxdam needs to be the amount of damage it took to kill |
| 1420 |
* this creature. The function(s) that call us have already |
| 1421 |
* adjusted the creatures HP total, so that is negative. |
| 1422 |
*/ |
| 1423 |
maxdam = dam + op->stats.hp + 1; |
| 1424 |
|
| 1425 |
if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
| 1426 |
update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ |
| 1427 |
|
| 1428 |
if (op->type == DOOR) |
| 1429 |
{ |
| 1430 |
op->set_speed (0.1f); |
| 1431 |
op->speed_left = -0.05f; |
| 1432 |
return maxdam; |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
| 1436 |
{ |
| 1437 |
op->drop_and_destroy (); |
| 1438 |
return maxdam; |
| 1439 |
} |
| 1440 |
|
| 1441 |
/* Now lets start dealing with experience we get for killing something */ |
| 1442 |
|
| 1443 |
owner = hitter->outer_owner (); |
| 1444 |
if (!owner) |
| 1445 |
owner = hitter; |
| 1446 |
|
| 1447 |
/* is the victim (op) standing on battleground? */ |
| 1448 |
if (op_on_battleground (op, NULL, NULL)) |
| 1449 |
battleg = 1; |
| 1450 |
|
| 1451 |
/* is this player killing? */ |
| 1452 |
if (op->type == PLAYER && owner->type == PLAYER) |
| 1453 |
pk = 1; |
| 1454 |
|
| 1455 |
/* Player killed something */ |
| 1456 |
if (owner->type == PLAYER) |
| 1457 |
{ |
| 1458 |
/* Log players killing other players - makes it easier to detect |
| 1459 |
* and filter out malicious player killers - that is why the |
| 1460 |
* ip address is included. |
| 1461 |
*/ |
| 1462 |
if (op->type == PLAYER && !battleg) |
| 1463 |
{ |
| 1464 |
time_t t = time (NULL); |
| 1465 |
struct tm *tmv; |
| 1466 |
char buf[256]; |
| 1467 |
|
| 1468 |
tmv = localtime (&t); |
| 1469 |
strftime (buf, 256, "%a %b %d %H:%M:%S %Y", tmv); |
| 1470 |
|
| 1471 |
LOG (llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, &owner->name, owner->contr->ns->host, query_name (op)); |
| 1472 |
} |
| 1473 |
|
| 1474 |
/* try to filter some things out - basically, if you are |
| 1475 |
* killing a level 1 creature and your level 20, you |
| 1476 |
* probably don't want to see that. |
| 1477 |
*/ |
| 1478 |
if (owner->level < op->level * 2 || op->stats.exp > 1000) |
| 1479 |
{ |
| 1480 |
if (owner != hitter) |
| 1481 |
new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s with %s.", query_name (op), query_name (hitter)); |
| 1482 |
else |
| 1483 |
new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op)); |
| 1484 |
|
| 1485 |
/* Only play sounds for melee kills */ |
| 1486 |
if (hitter->type == PLAYER) |
| 1487 |
owner->play_sound (sound_find ("player_kills")); |
| 1488 |
} |
| 1489 |
|
| 1490 |
/* If a player kills another player, not on |
| 1491 |
* battleground, the "killer" looses 1 luck. Since this is |
| 1492 |
* not reversible, it's actually quite a pain IMHO. -AV |
| 1493 |
* Fix bug in that we were changing the luck of the hitter, not |
| 1494 |
* player that the object belonged to - so if you killed another player |
| 1495 |
* with spells, pets, whatever, there was no penalty. |
| 1496 |
* Changed to make luck penalty configurable in settings. |
| 1497 |
*/ |
| 1498 |
if (op->type == PLAYER && owner != op && !battleg) |
| 1499 |
owner->change_luck (-settings.pk_luck_penalty); |
| 1500 |
|
| 1501 |
/* This code below deals with finding the appropriate skill |
| 1502 |
* to credit exp to. This is a bit problematic - we should |
| 1503 |
* probably never really have to look at current_weapon->skill |
| 1504 |
*/ |
| 1505 |
if (hitter->skill && hitter->type != PLAYER) |
| 1506 |
skill = hitter->skill; |
| 1507 |
else if (owner->chosen_skill) |
| 1508 |
{ |
| 1509 |
skop = owner->chosen_skill; |
| 1510 |
skill = skop->skill; |
| 1511 |
} |
| 1512 |
else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
| 1513 |
skill = owner->current_weapon->skill; |
| 1514 |
else |
| 1515 |
{ |
| 1516 |
LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" |
| 1517 |
"op: %s\n" "hitter: %s\n" "owner: %s\n", |
| 1518 |
owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
| 1519 |
skill = 0; |
| 1520 |
} |
| 1521 |
|
| 1522 |
/* We have the skill we want to credit to - now find the object this goes |
| 1523 |
* to. Make sure skop is an actual skill, and not a skill tool! |
| 1524 |
*/ |
| 1525 |
skop = owner->contr->find_skill (skill); |
| 1526 |
} /* Was it a player that hit somethign */ |
| 1527 |
else |
| 1528 |
skill = 0; |
| 1529 |
|
| 1530 |
/* These may have been set in the player code section above */ |
| 1531 |
if (!skop) |
| 1532 |
skop = hitter->chosen_skill; |
| 1533 |
|
| 1534 |
if (!skill && skop) |
| 1535 |
skill = skop->skill; |
| 1536 |
|
| 1537 |
/* If you didn't kill yourself, and your not the wizard */ |
| 1538 |
if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
| 1539 |
{ |
| 1540 |
int exp; |
| 1541 |
|
| 1542 |
/* Really don't give much experience for killing other players */ |
| 1543 |
// schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
| 1544 |
if (op->type == PLAYER) |
| 1545 |
{ |
| 1546 |
if (battleg) |
| 1547 |
{ |
| 1548 |
new_draw_info (NDI_UNIQUE, 0, owner, "Your foe has fallen!"); |
| 1549 |
new_draw_info (NDI_UNIQUE, 0, owner, "VICTORY!!!"); |
| 1550 |
} |
| 1551 |
else |
| 1552 |
exp = op->stats.exp / 1000; |
| 1553 |
} |
| 1554 |
else |
| 1555 |
exp = calc_skill_exp (owner, op, skop); |
| 1556 |
|
| 1557 |
/* if op is standing on "battleground" (arena), no way to gain |
| 1558 |
* exp by killing him |
| 1559 |
*/ |
| 1560 |
if (battleg) |
| 1561 |
exp = 0; |
| 1562 |
|
| 1563 |
/* Don't know why this is set this way - doesn't make |
| 1564 |
* sense to just divide everything by two for no reason. |
| 1565 |
*/ |
| 1566 |
|
| 1567 |
if (!settings.simple_exp) |
| 1568 |
exp = exp / 2; |
| 1569 |
|
| 1570 |
if (owner->type != PLAYER || owner->contr->party == NULL) |
| 1571 |
change_exp (owner, exp, skill, 0); |
| 1572 |
else |
| 1573 |
{ |
| 1574 |
int shares = 0, count = 0; |
| 1575 |
partylist *party = owner->contr->party; |
| 1576 |
|
| 1577 |
add_kill_to_party (party, query_name (owner), query_name (op), exp); |
| 1578 |
|
| 1579 |
for_all_players (pl) |
| 1580 |
if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner)) |
| 1581 |
{ |
| 1582 |
count++; |
| 1583 |
shares += (pl->ob->level + 4); |
| 1584 |
} |
| 1585 |
|
| 1586 |
if (count == 1 || shares > exp || !shares) |
| 1587 |
change_exp (owner, exp, skill, SK_EXP_TOTAL); |
| 1588 |
else |
| 1589 |
{ |
| 1590 |
int share = exp / shares, given = 0, nexp; |
| 1591 |
|
| 1592 |
for_all_players (pl) |
| 1593 |
if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner)) |
| 1594 |
{ |
| 1595 |
nexp = (pl->ob->level + 4) * share; |
| 1596 |
change_exp (pl->ob, nexp, skill, SK_EXP_TOTAL); |
| 1597 |
given += nexp; |
| 1598 |
} |
| 1599 |
|
| 1600 |
exp -= given; |
| 1601 |
/* give any remainder to the player */ |
| 1602 |
change_exp (owner, exp, skill, SK_EXP_ADD_SKILL); |
| 1603 |
} |
| 1604 |
} /* else part of a party */ |
| 1605 |
} /* end if person didn't kill himself */ |
| 1606 |
|
| 1607 |
if (op->type != PLAYER) |
| 1608 |
{ |
| 1609 |
if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
| 1610 |
{ |
| 1611 |
object *owner1 = op->owner; |
| 1612 |
|
| 1613 |
if (owner1 && owner1->type == PLAYER) |
| 1614 |
{ |
| 1615 |
owner1->contr->play_sound (sound_find ("pet_is_killed")); |
| 1616 |
/* Maybe we should include the owner that killed this, maybe not */ |
| 1617 |
new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, was killed by %s.", &op->name, &hitter->name); |
| 1618 |
} |
| 1619 |
|
| 1620 |
remove_friendly_object (op); |
| 1621 |
} |
| 1622 |
|
| 1623 |
op->drop_and_destroy (); |
| 1624 |
} |
| 1625 |
else |
| 1626 |
/* Player has been killed! */ |
| 1627 |
op->contr->killer = owner->type == PLAYER ? owner : hitter; |
| 1628 |
|
| 1629 |
/* This was return -1 - that doesn't seem correct - if we return -1, process |
| 1630 |
* continues in the calling function. |
| 1631 |
*/ |
| 1632 |
return maxdam; |
| 1633 |
} |
| 1634 |
|
| 1635 |
/* Find out if this is friendly fire (PVP and attacker is peaceful) or not |
| 1636 |
* Returns 0 this is not friendly fire |
| 1637 |
*/ |
| 1638 |
int |
| 1639 |
friendly_fire (object *op, object *hitter) |
| 1640 |
{ |
| 1641 |
object *owner; |
| 1642 |
int friendlyfire; |
| 1643 |
|
| 1644 |
if (hitter->head) |
| 1645 |
hitter = hitter->head; |
| 1646 |
|
| 1647 |
friendlyfire = 0; |
| 1648 |
|
| 1649 |
if (op->type == PLAYER) |
| 1650 |
{ |
| 1651 |
if (op_on_battleground (hitter, 0, 0)) |
| 1652 |
return 0; |
| 1653 |
|
| 1654 |
if (hitter->type == PLAYER && hitter->contr->peaceful == 1) |
| 1655 |
return 1; |
| 1656 |
|
| 1657 |
if ((owner = hitter->owner) != NULL) |
| 1658 |
{ |
| 1659 |
if (owner->type == PLAYER && owner->contr->peaceful == 1) |
| 1660 |
friendlyfire = 2; |
| 1661 |
} |
| 1662 |
|
| 1663 |
if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE) |
| 1664 |
friendlyfire = 0; |
| 1665 |
} |
| 1666 |
|
| 1667 |
return friendlyfire; |
| 1668 |
} |
| 1669 |
|
| 1670 |
/* This isn't used just for players, but in fact most objects. |
| 1671 |
* op is the object to be hit, dam is the amount of damage, hitter |
| 1672 |
* is what is hitting the object, type is the attacktype, and |
| 1673 |
* full_hit is set if monster area does not matter. |
| 1674 |
* dam is base damage - protections/vulnerabilities/slaying matches can |
| 1675 |
* modify it. |
| 1676 |
*/ |
| 1677 |
/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack |
| 1678 |
* which needs new attacktype AT_HOLYWORD to work . b.t. */ |
| 1679 |
int |
| 1680 |
hit_player (object *op, int dam, object *hitter, int type, int full_hit) |
| 1681 |
{ |
| 1682 |
int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); |
| 1683 |
int maxattacktype, attacknum; |
| 1684 |
int body_attack = op && op->head; /* Did we hit op's head? */ |
| 1685 |
int simple_attack; |
| 1686 |
int rtn_kill = 0; |
| 1687 |
int friendlyfire; |
| 1688 |
|
| 1689 |
if (get_attack_mode (&op, &hitter, &simple_attack)) |
| 1690 |
return 0; |
| 1691 |
|
| 1692 |
/* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ |
| 1693 |
if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
| 1694 |
return 0; |
| 1695 |
|
| 1696 |
// only allow pk for hostile players |
| 1697 |
if (op->type == PLAYER) |
| 1698 |
{ |
| 1699 |
object *owner = hitter->owner; |
| 1700 |
|
| 1701 |
if (!owner) |
| 1702 |
owner = hitter; |
| 1703 |
|
| 1704 |
if (owner->type == PLAYER |
| 1705 |
&& (!op_on_battleground (op, 0, 0) |
| 1706 |
&& (op->contr->peaceful || owner->contr->peaceful)) |
| 1707 |
&& op != owner) |
| 1708 |
return 0; |
| 1709 |
} |
| 1710 |
|
| 1711 |
if (body_attack) |
| 1712 |
{ |
| 1713 |
/* slow and paralyze must hit the head. But we don't want to just |
| 1714 |
* return - we still need to process other attacks the spell still |
| 1715 |
* might have. So just remove the paralyze and slow attacktypes, |
| 1716 |
* and keep on processing if we have other attacktypes. |
| 1717 |
* return if only magic or nothing is left - under normal code |
| 1718 |
* we don't attack with pure magic if there is another attacktype. |
| 1719 |
* Only do processing if the initial attacktype includes one of those |
| 1720 |
* attack so we don't cancel out things like magic bullet. |
| 1721 |
*/ |
| 1722 |
if (type & (AT_PARALYZE | AT_SLOW)) |
| 1723 |
{ |
| 1724 |
type &= ~(AT_PARALYZE | AT_SLOW); |
| 1725 |
|
| 1726 |
if (!type || type == AT_MAGIC) |
| 1727 |
return 0; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
if (!simple_attack && op->type == DOOR) |
| 1732 |
{ |
| 1733 |
for (object *tmp = op->inv; tmp; tmp = tmp->below) |
| 1734 |
if (tmp->type == RUNE || tmp->type == TRAP) |
| 1735 |
{ |
| 1736 |
spring_trap (tmp, hitter); |
| 1737 |
|
| 1738 |
if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) |
| 1739 |
return 0; |
| 1740 |
|
| 1741 |
break; |
| 1742 |
} |
| 1743 |
} |
| 1744 |
|
| 1745 |
if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
| 1746 |
{ |
| 1747 |
/* FIXME: If a player is killed by a rune in a door, the |
| 1748 |
* destroyed() check above doesn't return, and might get here. |
| 1749 |
*/ |
| 1750 |
|
| 1751 |
/* FIXME: This for example happens when a dead door is on a mover and |
| 1752 |
gets it's speed_left raised on each mover-tick. |
| 1753 |
Doors are removed in a kinda funny way by giving them speed and speed_left |
| 1754 |
and waiting for that to run out. |
| 1755 |
*/ |
| 1756 |
LOG (llevDebug, "victim %s (%d) already dead in hit_player()\n", op->debug_desc (), op->stats.hp); |
| 1757 |
return 0; |
| 1758 |
} |
| 1759 |
|
| 1760 |
#ifdef ATTACK_DEBUG |
| 1761 |
LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); |
| 1762 |
#endif |
| 1763 |
|
| 1764 |
if (magic) |
| 1765 |
{ |
| 1766 |
/* basically: dam = dam*(100-op->resist[attacknum])/100; |
| 1767 |
* in case 0>dam>1, we try to "simulate" a float value-effect */ |
| 1768 |
dam = dam * (100 - op->resist[ATNR_MAGIC]); |
| 1769 |
if (dam >= 100) |
| 1770 |
dam /= 100; |
| 1771 |
else |
| 1772 |
dam = (dam > rndm (0, 99)) ? 1 : 0; |
| 1773 |
} |
| 1774 |
|
| 1775 |
/* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map |
| 1776 |
* If the attacktype still has chaos, shuffle it, then clear the Chaos bit |
| 1777 |
*/ |
| 1778 |
if (type & AT_CHAOS) |
| 1779 |
{ |
| 1780 |
shuffle_attack (op, 0); /*0 flag tells it to not change the face */ |
| 1781 |
update_object (op, UP_OBJ_FACE); |
| 1782 |
type &= ~AT_CHAOS; |
| 1783 |
} |
| 1784 |
|
| 1785 |
/* Holyword is really an attacktype modifier (like magic is). If |
| 1786 |
* holyword is part of an attacktype, then make sure the creature is |
| 1787 |
* a proper match, otherwise no damage. |
| 1788 |
*/ |
| 1789 |
if (type & AT_HOLYWORD) |
| 1790 |
{ |
| 1791 |
object *god; |
| 1792 |
|
| 1793 |
if ((!hitter->slaying |
| 1794 |
|| (!(op->race && hitter->slaying.contains (op->race)) |
| 1795 |
&& !(op->name && hitter->slaying.contains (op->name)))) |
| 1796 |
&& (!QUERY_FLAG (op, FLAG_UNDEAD) |
| 1797 |
|| (hitter->title |
| 1798 |
&& (god = find_god (determine_god (hitter))) != NULL |
| 1799 |
&& god->race.contains (shstr_undead)))) |
| 1800 |
return 0; |
| 1801 |
} |
| 1802 |
|
| 1803 |
maxattacktype = type; /* initialise this to something */ |
| 1804 |
for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) |
| 1805 |
{ |
| 1806 |
/* Magic isn't really a true attack type - it gets combined with other |
| 1807 |
* attack types. As such, skip it over. However, if magic is |
| 1808 |
* the only attacktype in the group, then still attack with it |
| 1809 |
*/ |
| 1810 |
if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) |
| 1811 |
continue; |
| 1812 |
|
| 1813 |
/* Go through and hit the player with each attacktype, one by one. |
| 1814 |
* hit_player_attacktype only figures out the damage, doesn't inflict |
| 1815 |
* it. It will do the appropriate action for attacktypes with |
| 1816 |
* effects (slow, paralization, etc. |
| 1817 |
*/ |
| 1818 |
if (type & attacktype) |
| 1819 |
{ |
| 1820 |
ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); |
| 1821 |
/* the >= causes us to prefer messages from special attacks, if |
| 1822 |
* the damage is equal. |
| 1823 |
*/ |
| 1824 |
if (ndam >= maxdam) |
| 1825 |
{ |
| 1826 |
maxdam = ndam; |
| 1827 |
maxattacktype = 1 << attacknum; |
| 1828 |
} |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
/* if this is friendly fire then do a set % of damage only |
| 1833 |
* Note - put a check in to make sure this attack is actually |
| 1834 |
* doing damage - otherwise, the +1 in the code below will make |
| 1835 |
* an attack do damage before when it otherwise didn't |
| 1836 |
*/ |
| 1837 |
friendlyfire = friendly_fire (op, hitter); |
| 1838 |
if (friendlyfire && maxdam) |
| 1839 |
{ |
| 1840 |
maxdam = ((dam * settings.set_friendly_fire) / 100); |
| 1841 |
|
| 1842 |
#ifdef ATTACK_DEBUG |
| 1843 |
LOG (llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n", |
| 1844 |
friendlyfire, settings.set_friendly_fire, dam, maxdam); |
| 1845 |
#endif |
| 1846 |
} |
| 1847 |
|
| 1848 |
if (!full_hit) |
| 1849 |
{ |
| 1850 |
int area; |
| 1851 |
int remainder; |
| 1852 |
|
| 1853 |
area = 0; |
| 1854 |
|
| 1855 |
for (archetype *at = op->arch; at; at = (archetype *)at->more) |
| 1856 |
area++; |
| 1857 |
|
| 1858 |
assert (area > 0); |
| 1859 |
|
| 1860 |
/* basically: maxdam /= area; we try to "simulate" a float |
| 1861 |
value-effect */ |
| 1862 |
remainder = 100 * (maxdam % area) / area; |
| 1863 |
maxdam /= area; |
| 1864 |
if (rndm (100) < remainder) |
| 1865 |
maxdam++; |
| 1866 |
} |
| 1867 |
|
| 1868 |
#ifdef ATTACK_DEBUG |
| 1869 |
LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); |
| 1870 |
#endif |
| 1871 |
|
| 1872 |
// for now, only do this for active objects, otherwise they |
| 1873 |
// keep a refcount for a long time and I see no usefulness |
| 1874 |
// for an non-active objetc to know its enemy. |
| 1875 |
if (op->active) |
| 1876 |
if (hitter->owner) |
| 1877 |
op->enemy = hitter->owner; |
| 1878 |
else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
| 1879 |
op->enemy = hitter; |
| 1880 |
|
| 1881 |
if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
| 1882 |
{ |
| 1883 |
/* The unaggressives look after themselves 8) */ |
| 1884 |
CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
| 1885 |
npc_call_help (op); |
| 1886 |
} |
| 1887 |
|
| 1888 |
if (magic && did_make_save (op, op->level, 0)) |
| 1889 |
maxdam = maxdam / 2; |
| 1890 |
|
| 1891 |
attack_message (maxdam, maxattacktype, op, hitter); |
| 1892 |
|
| 1893 |
op->stats.hp -= maxdam; |
| 1894 |
|
| 1895 |
/* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
| 1896 |
if ((op->stats.hp >= 0) && |
| 1897 |
(QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && |
| 1898 |
op->stats.hp < (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) |
| 1899 |
{ |
| 1900 |
|
| 1901 |
if (QUERY_FLAG (op, FLAG_MONSTER)) |
| 1902 |
SET_FLAG (op, FLAG_RUN_AWAY); |
| 1903 |
else |
| 1904 |
scare_creature (op, hitter); |
| 1905 |
} |
| 1906 |
|
| 1907 |
if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
| 1908 |
{ |
| 1909 |
if (maxdam) |
| 1910 |
tear_down_wall (op); |
| 1911 |
|
| 1912 |
return maxdam; /* nothing more to do for wall */ |
| 1913 |
} |
| 1914 |
|
| 1915 |
/* See if the creature has been killed */ |
| 1916 |
rtn_kill = kill_object (op, maxdam, hitter, type); |
| 1917 |
if (rtn_kill != -1) |
| 1918 |
return rtn_kill; |
| 1919 |
|
| 1920 |
/* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
| 1921 |
* that before if the player was immune to ghosthit, the monster |
| 1922 |
* remained - that is no longer the case. |
| 1923 |
*/ |
| 1924 |
if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
| 1925 |
hitter->drop_and_destroy (); |
| 1926 |
/* Lets handle creatures that are splitting now */ |
| 1927 |
else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) |
| 1928 |
{ |
| 1929 |
int i; |
| 1930 |
int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
| 1931 |
int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
| 1932 |
object *owner = op->owner; |
| 1933 |
|
| 1934 |
if (!op->other_arch) |
| 1935 |
{ |
| 1936 |
LOG (llevError, "SPLITTING without other_arch error.\n"); |
| 1937 |
return maxdam; |
| 1938 |
} |
| 1939 |
|
| 1940 |
op->remove (); |
| 1941 |
|
| 1942 |
for (i = 0; i < op->stats.food; i++) |
| 1943 |
{ /* This doesn't handle op->more yet */ |
| 1944 |
object *tmp = arch_to_object (op->other_arch); |
| 1945 |
int j; |
| 1946 |
|
| 1947 |
tmp->stats.hp = op->stats.hp; |
| 1948 |
|
| 1949 |
if (friendly) |
| 1950 |
{ |
| 1951 |
add_friendly_object (tmp); |
| 1952 |
tmp->attack_movement = PETMOVE; |
| 1953 |
|
| 1954 |
if (owner) |
| 1955 |
tmp->set_owner (owner); |
| 1956 |
} |
| 1957 |
|
| 1958 |
if (unaggressive) |
| 1959 |
SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
| 1960 |
|
| 1961 |
j = find_first_free_spot (tmp, op->map, op->x, op->y); |
| 1962 |
|
| 1963 |
if (j == -1) /* No spot to put this monster */ |
| 1964 |
tmp->destroy (); |
| 1965 |
else |
| 1966 |
{ |
| 1967 |
tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; |
| 1968 |
insert_ob_in_map (tmp, op->map, NULL, 0); |
| 1969 |
} |
| 1970 |
} |
| 1971 |
|
| 1972 |
op->destroy (); |
| 1973 |
} |
| 1974 |
else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) |
| 1975 |
hitter->drop_and_destroy (); |
| 1976 |
|
| 1977 |
return maxdam; |
| 1978 |
} |
| 1979 |
|
| 1980 |
void |
| 1981 |
poison_player (object *op, object *hitter, int dam) |
| 1982 |
{ |
| 1983 |
archetype *at = archetype::find ("poisoning"); |
| 1984 |
object *tmp = present_arch_in_ob (at, op); |
| 1985 |
|
| 1986 |
if (tmp == NULL) |
| 1987 |
{ |
| 1988 |
if ((tmp = arch_to_object (at)) == NULL) |
| 1989 |
LOG (llevError, "Failed to clone arch poisoning.\n"); |
| 1990 |
else |
| 1991 |
{ |
| 1992 |
tmp = insert_ob_in_ob (tmp, op); |
| 1993 |
/* peterm: give poisoning some teeth. It should |
| 1994 |
* be able to kill things better than it does: |
| 1995 |
* damage should be dependent something--I choose to |
| 1996 |
* do this: if it's a monster, the damage from the |
| 1997 |
* poisoning goes as the level of the monster/2. |
| 1998 |
* If anything else, goes as damage. |
| 1999 |
*/ |
| 2000 |
|
| 2001 |
if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
| 2002 |
tmp->stats.dam += hitter->level / 2; |
| 2003 |
else |
| 2004 |
tmp->stats.dam = dam; |
| 2005 |
|
| 2006 |
tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
| 2007 |
if (hitter->skill && hitter->skill != tmp->skill) |
| 2008 |
{ |
| 2009 |
tmp->skill = hitter->skill; |
| 2010 |
} |
| 2011 |
|
| 2012 |
tmp->stats.food += dam; /* more damage, longer poisoning */ |
| 2013 |
|
| 2014 |
if (op->type == PLAYER) |
| 2015 |
{ |
| 2016 |
/* player looses stats, maximum is -10 of each */ |
| 2017 |
tmp->stats.Con = MAX (-(dam / 4 + 1), -10); |
| 2018 |
tmp->stats.Str = MAX (-(dam / 3 + 2), -10); |
| 2019 |
tmp->stats.Dex = MAX (-(dam / 6 + 1), -10); |
| 2020 |
tmp->stats.Int = MAX (-dam / 7, -10); |
| 2021 |
SET_FLAG (tmp, FLAG_APPLIED); |
| 2022 |
op->update_stats (); |
| 2023 |
new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); |
| 2024 |
op->play_sound (tmp->sound); |
| 2025 |
} |
| 2026 |
|
| 2027 |
if (hitter->type == PLAYER) |
| 2028 |
new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); |
| 2029 |
else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
| 2030 |
new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); |
| 2031 |
} |
| 2032 |
|
| 2033 |
tmp->speed_left = 0; |
| 2034 |
} |
| 2035 |
else |
| 2036 |
tmp->stats.food++; |
| 2037 |
} |
| 2038 |
|
| 2039 |
void |
| 2040 |
slow_player (object *op, object *hitter, int dam) |
| 2041 |
{ |
| 2042 |
archetype *at = archetype::find ("slowness"); |
| 2043 |
object *tmp; |
| 2044 |
|
| 2045 |
if (at == NULL) |
| 2046 |
LOG (llevError, "Can't find slowness archetype.\n"); |
| 2047 |
|
| 2048 |
if ((tmp = present_arch_in_ob (at, op)) == NULL) |
| 2049 |
{ |
| 2050 |
tmp = arch_to_object (at); |
| 2051 |
tmp = insert_ob_in_ob (tmp, op); |
| 2052 |
new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); |
| 2053 |
} |
| 2054 |
else |
| 2055 |
tmp->stats.food++; |
| 2056 |
|
| 2057 |
SET_FLAG (tmp, FLAG_APPLIED); |
| 2058 |
tmp->speed_left = 0; |
| 2059 |
op->update_stats (); |
| 2060 |
} |
| 2061 |
|
| 2062 |
void |
| 2063 |
confuse_player (object *op, object *hitter, int dam) |
| 2064 |
{ |
| 2065 |
object *tmp; |
| 2066 |
int maxduration; |
| 2067 |
|
| 2068 |
tmp = present_in_ob_by_name (FORCE, "confusion", op); |
| 2069 |
if (!tmp) |
| 2070 |
{ |
| 2071 |
tmp = get_archetype (FORCE_NAME); |
| 2072 |
tmp = insert_ob_in_ob (tmp, op); |
| 2073 |
} |
| 2074 |
|
| 2075 |
/* Duration added per hit and max. duration of confusion both depend |
| 2076 |
* on the player's resistance |
| 2077 |
*/ |
| 2078 |
tmp->speed = 0.05; |
| 2079 |
tmp->subtype = FORCE_CONFUSION; |
| 2080 |
tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
| 2081 |
tmp->name = "confusion"; |
| 2082 |
maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
| 2083 |
|
| 2084 |
if (tmp->duration > maxduration) |
| 2085 |
tmp->duration = maxduration; |
| 2086 |
|
| 2087 |
if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
| 2088 |
new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); |
| 2089 |
|
| 2090 |
SET_FLAG (op, FLAG_CONFUSED); |
| 2091 |
} |
| 2092 |
|
| 2093 |
void |
| 2094 |
blind_player (object *op, object *hitter, int dam) |
| 2095 |
{ |
| 2096 |
object *tmp, *owner; |
| 2097 |
|
| 2098 |
/* Save some work if we know it isn't going to affect the player */ |
| 2099 |
if (op->resist[ATNR_BLIND] == 100) |
| 2100 |
return; |
| 2101 |
|
| 2102 |
tmp = present_in_ob (BLINDNESS, op); |
| 2103 |
if (!tmp) |
| 2104 |
{ |
| 2105 |
tmp = get_archetype ("blindness"); |
| 2106 |
SET_FLAG (tmp, FLAG_BLIND); |
| 2107 |
SET_FLAG (tmp, FLAG_APPLIED); |
| 2108 |
/* use floats so we don't lose too much precision due to rounding errors. |
| 2109 |
* speed is a float anyways. |
| 2110 |
*/ |
| 2111 |
tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
| 2112 |
|
| 2113 |
tmp = insert_ob_in_ob (tmp, op); |
| 2114 |
change_abil (op, tmp); /* Mostly to display any messages */ |
| 2115 |
op->update_stats (); /* This takes care of some other stuff */ |
| 2116 |
|
| 2117 |
if (hitter->owner) |
| 2118 |
owner = hitter->owner; |
| 2119 |
else |
| 2120 |
owner = hitter; |
| 2121 |
|
| 2122 |
new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op)); |
| 2123 |
} |
| 2124 |
tmp->stats.food += dam; |
| 2125 |
if (tmp->stats.food > 10) |
| 2126 |
tmp->stats.food = 10; |
| 2127 |
} |
| 2128 |
|
| 2129 |
void |
| 2130 |
paralyze_player (object *op, object *hitter, int dam) |
| 2131 |
{ |
| 2132 |
float effect, max; |
| 2133 |
|
| 2134 |
/* object *tmp; */ |
| 2135 |
|
| 2136 |
/* This is strange stuff... someone knows for what this is |
| 2137 |
* written? Well, i think this can and should be removed |
| 2138 |
*/ |
| 2139 |
|
| 2140 |
/* |
| 2141 |
if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) { |
| 2142 |
tmp=clone_arch(PARAIMAGE); |
| 2143 |
tmp->x=op->x,tmp->y=op->y; |
| 2144 |
insert_ob_in_map(tmp,op->map,tmp,INS_NO_MERGE | INS_NO_WALK_ON); |
| 2145 |
} |
| 2146 |
*/ |
| 2147 |
|
| 2148 |
/* Do this as a float - otherwise, rounding might very well reduce this to 0 */ |
| 2149 |
effect = (float) dam *3.0 * (100.0 - op->resist[ATNR_PARALYZE]) / 100; |
| 2150 |
|
| 2151 |
if (effect == 0) |
| 2152 |
return; |
| 2153 |
|
| 2154 |
op->speed_left -= FABS (op->speed) * effect; |
| 2155 |
/* tmp->stats.food+=(signed short) effect/op->speed; */ |
| 2156 |
|
| 2157 |
/* max number of ticks to be affected for. */ |
| 2158 |
max = (100 - op->resist[ATNR_PARALYZE]) / 2; |
| 2159 |
if (op->speed_left < -(FABS (op->speed) * max)) |
| 2160 |
op->speed_left = (float) -(FABS (op->speed) * max); |
| 2161 |
|
| 2162 |
/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ |
| 2163 |
} |
| 2164 |
|
| 2165 |
/* Attempts to kill 'op'. hitter is the attack object, dam is |
| 2166 |
* the computed damaged. |
| 2167 |
*/ |
| 2168 |
void |
| 2169 |
deathstrike_player (object *op, object *hitter, int *dam) |
| 2170 |
{ |
| 2171 |
/* The intention of a death attack is to kill outright things |
| 2172 |
** that are a lot weaker than the attacker, have a chance of killing |
| 2173 |
** things somewhat weaker than the caster, and no chance of |
| 2174 |
** killing something equal or stronger than the attacker. |
| 2175 |
** Also, if a deathstrike attack has a slaying, any monster |
| 2176 |
** whose name or race matches a comma-delimited list in the slaying |
| 2177 |
** field of the deathstriking object */ |
| 2178 |
|
| 2179 |
int atk_lev, def_lev, kill_lev; |
| 2180 |
|
| 2181 |
if (hitter->slaying) |
| 2182 |
if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
| 2183 |
|| (op->race && hitter->slaying.contains (op->race)))) |
| 2184 |
return; |
| 2185 |
|
| 2186 |
def_lev = op->level; |
| 2187 |
if (def_lev < 1) |
| 2188 |
{ |
| 2189 |
LOG (llevError, "BUG: arch %s with level < 1 (%s)\n", &op->arch->archname, op->debug_desc ()); |
| 2190 |
def_lev = 1; |
| 2191 |
} |
| 2192 |
|
| 2193 |
atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; |
| 2194 |
/* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", |
| 2195 |
atk_lev, def_lev); */ |
| 2196 |
|
| 2197 |
if (atk_lev >= def_lev) |
| 2198 |
{ |
| 2199 |
kill_lev = random_roll (0, atk_lev - 1, hitter, PREFER_HIGH); |
| 2200 |
|
| 2201 |
/* Note that the below effectively means the ratio of the atk vs |
| 2202 |
* defener level is important - if level 52 character has very little |
| 2203 |
* chance of killing a level 50 monster. This should probably be |
| 2204 |
* redone. |
| 2205 |
*/ |
| 2206 |
if (kill_lev >= def_lev) |
| 2207 |
{ |
| 2208 |
*dam = op->stats.hp + 10; /* take all hp. they can still save for 1/2 */ |
| 2209 |
/* I think this doesn't really do much. Because of |
| 2210 |
* integer rounding, this only makes any difference if the |
| 2211 |
* attack level is double the defender level. |
| 2212 |
*/ |
| 2213 |
*dam *= kill_lev / def_lev; |
| 2214 |
} |
| 2215 |
} |
| 2216 |
else |
| 2217 |
*dam = 0; /* no harm done */ |
| 2218 |
} |
| 2219 |
|
| 2220 |
/* thrown_item_effect() - handles any special effects of thrown |
| 2221 |
* items (like attacking living creatures--a potion thrown at a |
| 2222 |
* monster). |
| 2223 |
*/ |
| 2224 |
static void |
| 2225 |
thrown_item_effect (object *hitter, object *victim) |
| 2226 |
{ |
| 2227 |
if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
| 2228 |
{ |
| 2229 |
/* May not need a switch for just 2 types, but this makes it |
| 2230 |
* easier for expansion. |
| 2231 |
*/ |
| 2232 |
switch (hitter->type) |
| 2233 |
{ |
| 2234 |
case POTION: |
| 2235 |
/* should player get a save throw instead of checking magic protection? */ |
| 2236 |
if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_MAGIC] < 60)) |
| 2237 |
(void) apply_potion (victim, hitter); |
| 2238 |
break; |
| 2239 |
|
| 2240 |
case POISON: /* poison drinks */ |
| 2241 |
/* As with potions, should monster get a save? */ |
| 2242 |
if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_POISON] < 60)) |
| 2243 |
apply_poison (victim, hitter); |
| 2244 |
break; |
| 2245 |
|
| 2246 |
/* Removed case statements that did nothing. |
| 2247 |
* food may be poisonous, but monster must be willing to eat it, |
| 2248 |
* so we don't handle it here. |
| 2249 |
* Containers should perhaps break open, but that code was disabled. |
| 2250 |
*/ |
| 2251 |
} |
| 2252 |
} |
| 2253 |
} |
| 2254 |
|
| 2255 |
/* adj_attackroll() - adjustments to attacks by various conditions */ |
| 2256 |
int |
| 2257 |
adj_attackroll (object *hitter, object *target) |
| 2258 |
{ |
| 2259 |
object *attacker = hitter; |
| 2260 |
int adjust = 0; |
| 2261 |
|
| 2262 |
/* safety */ |
| 2263 |
if (!target || !hitter || !hitter->map || !target->map || !on_same_map (hitter, target)) |
| 2264 |
{ |
| 2265 |
LOG (llevError, "BUG: adj_attackroll(): hitter and target not on same " "map\n"); |
| 2266 |
return 0; |
| 2267 |
} |
| 2268 |
|
| 2269 |
/* aimed missiles use the owning object's sight */ |
| 2270 |
if (is_aimed_missile (hitter)) |
| 2271 |
{ |
| 2272 |
if ((attacker = hitter->owner) == NULL) |
| 2273 |
attacker = hitter; |
| 2274 |
/* A player who saves but hasn't quit still could have objects |
| 2275 |
* owned by him - need to handle that case to avoid crashes. |
| 2276 |
*/ |
| 2277 |
if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
| 2278 |
attacker = hitter; |
| 2279 |
} |
| 2280 |
else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
| 2281 |
return 0; |
| 2282 |
|
| 2283 |
/* determine the condtions under which we make an attack. |
| 2284 |
* Add more cases, as the need occurs. */ |
| 2285 |
|
| 2286 |
if (!can_see_enemy (attacker, target)) |
| 2287 |
{ |
| 2288 |
/* target is unseen */ |
| 2289 |
if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
| 2290 |
adjust -= 10; |
| 2291 |
/* dark map penalty for the hitter (lacks infravision if we got here). */ |
| 2292 |
else if (!stand_in_light (target)) |
| 2293 |
adjust -= target->map->darklevel (); |
| 2294 |
} |
| 2295 |
|
| 2296 |
if (QUERY_FLAG (attacker, FLAG_SCARED)) |
| 2297 |
adjust -= 3; |
| 2298 |
|
| 2299 |
if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
| 2300 |
adjust += 1; |
| 2301 |
|
| 2302 |
if (QUERY_FLAG (target, FLAG_SCARED)) |
| 2303 |
adjust += 1; |
| 2304 |
|
| 2305 |
if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
| 2306 |
adjust -= 3; |
| 2307 |
|
| 2308 |
/* if we attack at a different 'altitude' its harder */ |
| 2309 |
if ((attacker->move_type & target->move_type) == 0) |
| 2310 |
adjust -= 2; |
| 2311 |
|
| 2312 |
#if 0 |
| 2313 |
/* slower attacks are less likely to succeed. We should use a |
| 2314 |
* comparison between attacker/target speeds BUT, players have |
| 2315 |
* a generally faster speed, so this will wind up being a HUGE |
| 2316 |
* disadantage for the monsters! Too bad, because missiles which |
| 2317 |
* fly fast should have a better chance of hitting a slower target. |
| 2318 |
*/ |
| 2319 |
if (hitter->speed < target->speed) |
| 2320 |
adjust += ((float) hitter->speed - target->speed); |
| 2321 |
#endif |
| 2322 |
|
| 2323 |
#if 0 |
| 2324 |
LOG (llevDebug, "adj_attackroll() returns %d (%d)\n", adjust, attacker->count); |
| 2325 |
#endif |
| 2326 |
|
| 2327 |
return adjust; |
| 2328 |
} |
| 2329 |
|
| 2330 |
/* determine if the object is an 'aimed' missile */ |
| 2331 |
int |
| 2332 |
is_aimed_missile (object *op) |
| 2333 |
{ |
| 2334 |
|
| 2335 |
/* I broke what used to be one big if into a few nested |
| 2336 |
* ones so that figuring out the logic is at least possible. |
| 2337 |
*/ |
| 2338 |
if (op && (op->move_type & MOVE_FLYING)) |
| 2339 |
if (op->type == ARROW || op->type == THROWN_OBJ) |
| 2340 |
return 1; |
| 2341 |
else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION)) |
| 2342 |
return 1; |
| 2343 |
|
| 2344 |
return 0; |
| 2345 |
} |