| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "global.h" |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
#include <stdlib.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "living.h" |
| 28 |
#include "material.h" |
| 29 |
#include "skills.h" |
| 30 |
#include "sounds.h" |
| 31 |
#include "sproto.h" |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
static void slow_living(object *op, object *hitter, int dam); |
| 36 |
static void deathstrike_living(object *op, object *hitter, int *dam); |
| 37 |
static int adj_attackroll(object *hitter, object *target); |
| 38 |
static int is_aimed_missile(object *op); |
| 39 |
static int did_make_save_item(object *op, int type, object *originator); |
| 40 |
static void poison_living(object *op, object *hitter, int dam); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
static void cancellation(object *op) { |
| 50 |
if (op->invisible) |
| 51 |
return; |
| 52 |
|
| 53 |
if (QUERY_FLAG(op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) { |
| 54 |
|
| 55 |
FOR_INV_PREPARE(op, inv) |
| 56 |
if (!did_make_save_item(inv, AT_CANCELLATION, op)) |
| 57 |
cancellation(inv); |
| 58 |
FOR_INV_FINISH(); |
| 59 |
} else if (FABS(op->magic) <= rndm(0, 5)) { |
| 60 |
|
| 61 |
|
| 62 |
op->magic = 0; |
| 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 |
if (op->env && op->env->type == PLAYER) { |
| 68 |
esrv_update_item(UPD_FLAGS, op->env, op); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
static void object_get_materialtype(object* op, materialtype_t** mt) { |
| 74 |
if (op->materialname == NULL) { |
| 75 |
for (*mt = materialt; *mt != NULL && (*mt)->next != NULL; *mt = (*mt)->next) { |
| 76 |
if (op->material & (*mt)->material) |
| 77 |
break; |
| 78 |
} |
| 79 |
} else |
| 80 |
*mt = name_to_material(op->materialname); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
static int did_make_save_item(object *op, int type, object *originator) { |
| 99 |
int i, roll, saves = 0, attacks = 0, number; |
| 100 |
materialtype_t* mt; |
| 101 |
object_get_materialtype(op, &mt); |
| 102 |
if (mt == NULL) |
| 103 |
return TRUE; |
| 104 |
roll = rndm(1, 20); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
if (type != AT_MAGIC) |
| 115 |
type &= ~(AT_CONFUSION|AT_DRAIN|AT_GHOSTHIT|AT_POISON|AT_SLOW| |
| 116 |
AT_PARALYZE|AT_TURN_UNDEAD|AT_FEAR|AT_DEPLETE|AT_DEATH| |
| 117 |
AT_COUNTERSPELL|AT_HOLYWORD|AT_BLIND|AT_LIFE_STEALING| |
| 118 |
AT_MAGIC); |
| 119 |
|
| 120 |
if (type == 0) |
| 121 |
return TRUE; |
| 122 |
if (roll == 20) |
| 123 |
return TRUE; |
| 124 |
|
| 125 |
for (number = 0; number < NROFATTACKS; number++) { |
| 126 |
i = 1<<number; |
| 127 |
if (!(i&type)) |
| 128 |
continue; |
| 129 |
attacks++; |
| 130 |
if (op->resist[number] == 100) |
| 131 |
saves++; |
| 132 |
else if (roll >= mt->save[number]-op->magic-op->resist[number]/100) |
| 133 |
saves++; |
| 134 |
else if ((20-mt->save[number])/3 > originator->stats.dam) |
| 135 |
saves++; |
| 136 |
} |
| 137 |
|
| 138 |
if (saves == attacks || attacks == 0) |
| 139 |
return TRUE; |
| 140 |
if (saves == 0 || rndm(1, attacks) > saves) |
| 141 |
return FALSE; |
| 142 |
return TRUE; |
| 143 |
} |
| 144 |
|
| 145 |
static void put_in_icecube(object* op, object* originator) { |
| 146 |
archetype* at = find_archetype("icecube"); |
| 147 |
if (at == NULL) |
| 148 |
return; |
| 149 |
op = stop_item(op); |
| 150 |
if (op == NULL) |
| 151 |
return; |
| 152 |
|
| 153 |
|
| 154 |
object* tmp = map_find_by_archetype(op->map, op->x, op->y, at); |
| 155 |
if (tmp == NULL) { |
| 156 |
tmp = arch_to_object(at); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
tmp->move_slow_penalty = 0; |
| 162 |
tmp->move_slow = 0; |
| 163 |
object_insert_in_map_at(tmp, op->map, originator, 0, op->x, op->y); |
| 164 |
} |
| 165 |
if (!QUERY_FLAG(op, FLAG_REMOVED)) |
| 166 |
object_remove(op); |
| 167 |
(void)object_insert_in_ob(op, tmp); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
void save_throw_object(object *op, uint32_t type, object *originator) { |
| 183 |
int dam; |
| 184 |
|
| 185 |
if (!did_make_save_item(op, type, originator)) { |
| 186 |
object *env = op->env; |
| 187 |
int x = op->x, y = op->y; |
| 188 |
mapstruct *m = op->map; |
| 189 |
|
| 190 |
int weight = op->weight; |
| 191 |
|
| 192 |
op = stop_item(op); |
| 193 |
if (op == NULL) |
| 194 |
return; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
if (op->type == TRANSPORT && op->inv) { |
| 200 |
if (op->map == NULL) { |
| 201 |
LOG(llevError, "Transport %s not on a map but with an item %s in it?\n", op->name, op->inv->name); |
| 202 |
} else { |
| 203 |
char name[MAX_BUF]; |
| 204 |
query_name(op, name, sizeof(name)); |
| 205 |
FOR_INV_PREPARE(op, inv) { |
| 206 |
if (inv->contr) { |
| 207 |
draw_ext_info_format(NDI_UNIQUE, 0, inv, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 208 |
"You are expelled from the %s during its destruction.", |
| 209 |
name); |
| 210 |
inv->contr->transport = NULL; |
| 211 |
} |
| 212 |
} |
| 213 |
FOR_INV_FINISH(); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
FOR_INV_PREPARE(op, inv) |
| 220 |
if (inv->type == RUNE) |
| 221 |
spring_trap(inv, originator); |
| 222 |
FOR_INV_FINISH(); |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
if (type&(AT_FIRE|AT_ELECTRICITY) |
| 233 |
&& op->other_arch |
| 234 |
&& QUERY_FLAG(op, FLAG_IS_LIGHTABLE)) { |
| 235 |
const char *arch = op->other_arch->name; |
| 236 |
|
| 237 |
op = object_decrease_nrof(op, 1); |
| 238 |
if (op) |
| 239 |
fix_stopped_item(op, m, originator); |
| 240 |
op = create_archetype(arch); |
| 241 |
if (op != NULL) { |
| 242 |
if (env) { |
| 243 |
op->x = env->x, |
| 244 |
op->y = env->y; |
| 245 |
object_insert_in_ob(op, env); |
| 246 |
} else |
| 247 |
object_insert_in_map_at(op, m, originator, 0, x, y); |
| 248 |
} |
| 249 |
return; |
| 250 |
} |
| 251 |
if (type&AT_CANCELLATION) { |
| 252 |
cancellation(op); |
| 253 |
fix_stopped_item(op, m, originator); |
| 254 |
return; |
| 255 |
} |
| 256 |
if (op->nrof > 1) { |
| 257 |
op = object_decrease_nrof(op, rndm(0, op->nrof-1)); |
| 258 |
if (op) |
| 259 |
fix_stopped_item(op, m, originator); |
| 260 |
} else { |
| 261 |
if (!QUERY_FLAG(op, FLAG_REMOVED)) |
| 262 |
object_remove(op); |
| 263 |
object_free_drop_inventory(op); |
| 264 |
} |
| 265 |
if (type&(AT_FIRE|AT_ELECTRICITY)) { |
| 266 |
if (env) { |
| 267 |
|
| 268 |
if (QUERY_FLAG(op, FLAG_APPLIED)) { |
| 269 |
|
| 270 |
if (env->resist[ATNR_FIRE] < 100) |
| 271 |
|
| 272 |
draw_ext_info_format(NDI_RED, 0, env, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 273 |
"OUCH! It burns!"); |
| 274 |
else |
| 275 |
draw_ext_info_format(NDI_UNIQUE, 0, env, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 276 |
"Despite the flame, you feel nothing."); |
| 277 |
|
| 278 |
dam = weight / 1000 * (100 - env->resist[ATNR_FIRE]) / 100; |
| 279 |
|
| 280 |
if (QUERY_FLAG(op, FLAG_CURSED)) |
| 281 |
dam *= 2; |
| 282 |
|
| 283 |
if (QUERY_FLAG(op, FLAG_DAMNED)) |
| 284 |
dam *= 3; |
| 285 |
env->stats.hp -= dam; |
| 286 |
|
| 287 |
if (env->stats.hp < 0) |
| 288 |
kill_player(env, NULL); |
| 289 |
} |
| 290 |
op = create_archetype("burnout"); |
| 291 |
op->x = env->x, |
| 292 |
op->y = env->y; |
| 293 |
object_insert_in_ob(op, env); |
| 294 |
} else { |
| 295 |
object_replace_insert_in_map("burnout", originator); |
| 296 |
} |
| 297 |
} |
| 298 |
return; |
| 299 |
} |
| 300 |
|
| 301 |
if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && |
| 302 |
!QUERY_FLAG(op, FLAG_NO_PICK) && (RANDOM() & 2)) { |
| 303 |
put_in_icecube(op, originator); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
int hit_map(object *op, int dir, uint32_t type, int full_hit) { |
| 323 |
mapstruct *map; |
| 324 |
int16_t x, y; |
| 325 |
int retflag = 0; |
| 326 |
tag_t op_tag; |
| 327 |
|
| 328 |
if (QUERY_FLAG(op, FLAG_FREED)) { |
| 329 |
LOG(llevError, "BUG: hit_map(): free object\n"); |
| 330 |
return 0; |
| 331 |
} |
| 332 |
|
| 333 |
if (QUERY_FLAG(op, FLAG_REMOVED) || op->env != NULL) { |
| 334 |
LOG(llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", op->arch->name, op->name); |
| 335 |
return 0; |
| 336 |
} |
| 337 |
|
| 338 |
if (!op->map) { |
| 339 |
LOG(llevError, "BUG: hit_map(): %s has no map\n", op->name); |
| 340 |
return 0; |
| 341 |
} |
| 342 |
|
| 343 |
op = HEAD(op); |
| 344 |
op_tag = op->count; |
| 345 |
|
| 346 |
map = op->map; |
| 347 |
x = op->x+freearr_x[dir]; |
| 348 |
y = op->y+freearr_y[dir]; |
| 349 |
if (get_map_flags(map, &map, x, y, &x, &y)&P_OUT_OF_MAP) |
| 350 |
return 0; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
if (type&AT_COUNTERSPELL) { |
| 357 |
counterspell(op, dir); |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
if (!(type&~(AT_COUNTERSPELL|AT_MAGIC))) { |
| 363 |
return 0; |
| 364 |
} |
| 365 |
type &= ~AT_COUNTERSPELL; |
| 366 |
} |
| 367 |
|
| 368 |
if (type&AT_CHAOS) { |
| 369 |
shuffle_attack(op, 1); |
| 370 |
object_update(op, UP_OBJ_FACE); |
| 371 |
type &= ~AT_CHAOS; |
| 372 |
} |
| 373 |
|
| 374 |
FOR_MAP_PREPARE(map, x, y, tmp) { |
| 375 |
if (QUERY_FLAG(tmp, FLAG_FREED)) { |
| 376 |
LOG(llevError, "BUG: hit_map(): found freed object\n"); |
| 377 |
break; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
if (tmp->map != map || tmp->x != x || tmp->y != y) |
| 385 |
continue; |
| 386 |
|
| 387 |
tmp = HEAD(tmp); |
| 388 |
|
| 389 |
|
| 390 |
if (tmp->type == TRANSPORT) { |
| 391 |
FOR_INV_PREPARE(tmp, pl) |
| 392 |
if (pl->type == PLAYER) |
| 393 |
hit_player(pl, op->stats.dam, op, type, full_hit); |
| 394 |
FOR_INV_FINISH(); |
| 395 |
} |
| 396 |
|
| 397 |
if (QUERY_FLAG(tmp, FLAG_ALIVE)) { |
| 398 |
hit_player(tmp, op->stats.dam, op, type, full_hit); |
| 399 |
retflag |= 1; |
| 400 |
if (object_was_destroyed(op, op_tag)) |
| 401 |
break; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block) { |
| 411 |
save_throw_object(tmp, type, op); |
| 412 |
if (object_was_destroyed(op, op_tag)) |
| 413 |
break; |
| 414 |
} |
| 415 |
} FOR_MAP_FINISH(); |
| 416 |
return 0; |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
static void attack_message(int dam, int type, object *op, object *hitter) { |
| 435 |
char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF]; |
| 436 |
int i, found = 0; |
| 437 |
mapstruct *map; |
| 438 |
object *owner; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
if (dam == 9998 && op->type == DOOR) { |
| 446 |
snprintf(buf1, sizeof(buf1), "unlock %s", op->name); |
| 447 |
snprintf(buf2, sizeof(buf2), " unlocks"); |
| 448 |
found++; |
| 449 |
} |
| 450 |
if (dam < 0) { |
| 451 |
snprintf(buf1, sizeof(buf1), "hit %s", op->name); |
| 452 |
snprintf(buf2, sizeof(buf2), " hits"); |
| 453 |
found++; |
| 454 |
} else if (dam == 0) { |
| 455 |
snprintf(buf1, sizeof(buf1), "missed %s", op->name); |
| 456 |
snprintf(buf2, sizeof(buf2), " misses"); |
| 457 |
found++; |
| 458 |
} else if ((hitter->type == DISEASE |
| 459 |
|| hitter->type == SYMPTOM |
| 460 |
|| hitter->type == POISONING |
| 461 |
|| (type&AT_POISON && IS_LIVE(op))) && !found) { |
| 462 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++) |
| 463 |
if (dam < attack_mess[ATM_SUFFER][i].level |
| 464 |
|| attack_mess[ATM_SUFFER][i+1].level == -1) { |
| 465 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, op->name, attack_mess[ATM_SUFFER][i].buf2); |
| 466 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_SUFFER][i].buf3); |
| 467 |
found++; |
| 468 |
break; |
| 469 |
} |
| 470 |
} else if (op->type == DOOR && !found) { |
| 471 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DOOR][i].level != -1; i++) |
| 472 |
if (dam < attack_mess[ATM_DOOR][i].level |
| 473 |
|| attack_mess[ATM_DOOR][i+1].level == -1) { |
| 474 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_DOOR][i].buf1, op->name, attack_mess[ATM_DOOR][i].buf2); |
| 475 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_DOOR][i].buf3); |
| 476 |
found++; |
| 477 |
break; |
| 478 |
} |
| 479 |
} else if (hitter->type == PLAYER && IS_LIVE(op)) { |
| 480 |
if (USING_SKILL(hitter, SK_KARATE)) { |
| 481 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++) |
| 482 |
if (dam < attack_mess[ATM_KARATE][i].level |
| 483 |
|| attack_mess[ATM_KARATE][i+1].level == -1) { |
| 484 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_KARATE][i].buf1, op->name, attack_mess[ATM_KARATE][i].buf2); |
| 485 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_KARATE][i].buf3); |
| 486 |
found++; |
| 487 |
break; |
| 488 |
} |
| 489 |
} else if (USING_SKILL(hitter, SK_CLAWING)) { |
| 490 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_CLAW][i].level != -1; i++) |
| 491 |
if (dam < attack_mess[ATM_CLAW][i].level |
| 492 |
|| attack_mess[ATM_CLAW][i+1].level == -1) { |
| 493 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_CLAW][i].buf1, op->name, attack_mess[ATM_CLAW][i].buf2); |
| 494 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_CLAW][i].buf3); |
| 495 |
found++; |
| 496 |
break; |
| 497 |
} |
| 498 |
} else if (USING_SKILL(hitter, SK_PUNCHING)) { |
| 499 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_PUNCH][i].level != -1; i++) |
| 500 |
if (dam < attack_mess[ATM_PUNCH][i].level |
| 501 |
|| attack_mess[ATM_PUNCH][i+1].level == -1) { |
| 502 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_PUNCH][i].buf1, op->name, attack_mess[ATM_PUNCH][i].buf2); |
| 503 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_PUNCH][i].buf3); |
| 504 |
found++; |
| 505 |
break; |
| 506 |
} |
| 507 |
} else if (USING_SKILL(hitter, SK_WRAITH_FEED)) { |
| 508 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_WRAITH_FEED][i].level != -1; i++) |
| 509 |
if (dam < attack_mess[ATM_WRAITH_FEED][i].level) { |
| 510 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_WRAITH_FEED][i].buf1, op->name, attack_mess[ATM_WRAITH_FEED][i].buf2); |
| 511 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_WRAITH_FEED][i].buf3); |
| 512 |
found++; |
| 513 |
break; |
| 514 |
} |
| 515 |
} |
| 516 |
} |
| 517 |
if (found) { |
| 518 |
|
| 519 |
} else if (IS_ARROW(hitter) && (type == AT_PHYSICAL || type == AT_MAGIC)) { |
| 520 |
snprintf(buf1, sizeof(buf1), "hit"); |
| 521 |
for (i = 0; i < MAXATTACKMESS; i++) |
| 522 |
if (dam < attack_mess[ATM_ARROW][i].level |
| 523 |
|| attack_mess[ATM_ARROW][i+1].level == -1) { |
| 524 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_ARROW][i].buf3); |
| 525 |
found++; |
| 526 |
break; |
| 527 |
} |
| 528 |
} else if (type&AT_DRAIN && IS_LIVE(op)) { |
| 529 |
|
| 530 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++) |
| 531 |
if (dam < attack_mess[ATM_DRAIN][i].level |
| 532 |
|| attack_mess[ATM_DRAIN][i+1].level == -1) { |
| 533 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_DRAIN][i].buf1, op->name, attack_mess[ATM_DRAIN][i].buf2); |
| 534 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_DRAIN][i].buf3); |
| 535 |
found++; |
| 536 |
break; |
| 537 |
} |
| 538 |
} else if (type&AT_ELECTRICITY && IS_LIVE(op)) { |
| 539 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++) |
| 540 |
if (dam < attack_mess[ATM_ELEC][i].level |
| 541 |
|| attack_mess[ATM_ELEC][i+1].level == -1) { |
| 542 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_ELEC][i].buf1, op->name, attack_mess[ATM_ELEC][i].buf2); |
| 543 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_ELEC][i].buf3); |
| 544 |
found++; |
| 545 |
break; |
| 546 |
} |
| 547 |
} else if (type&AT_COLD && IS_LIVE(op)) { |
| 548 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++) |
| 549 |
if (dam < attack_mess[ATM_COLD][i].level |
| 550 |
|| attack_mess[ATM_COLD][i+1].level == -1) { |
| 551 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_COLD][i].buf1, op->name, attack_mess[ATM_COLD][i].buf2); |
| 552 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_COLD][i].buf3); |
| 553 |
found++; |
| 554 |
break; |
| 555 |
} |
| 556 |
} else if (type&AT_FIRE) { |
| 557 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_FIRE][i].level != -1; i++) |
| 558 |
if (dam < attack_mess[ATM_FIRE][i].level |
| 559 |
|| attack_mess[ATM_FIRE][i+1].level == -1) { |
| 560 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_FIRE][i].buf1, op->name, attack_mess[ATM_FIRE][i].buf2); |
| 561 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_FIRE][i].buf3); |
| 562 |
found++; |
| 563 |
break; |
| 564 |
} |
| 565 |
} else if (hitter->current_weapon != NULL) { |
| 566 |
int mtype; |
| 567 |
|
| 568 |
switch (hitter->current_weapon->weapontype) { |
| 569 |
case WEAP_HIT: mtype = ATM_BASIC; break; |
| 570 |
case WEAP_SLASH: mtype = ATM_SLASH; break; |
| 571 |
case WEAP_PIERCE: mtype = ATM_PIERCE; break; |
| 572 |
case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; |
| 573 |
case WEAP_SLICE: mtype = ATM_SLICE; break; |
| 574 |
case WEAP_STAB: mtype = ATM_STAB; break; |
| 575 |
case WEAP_WHIP: mtype = ATM_WHIP; break; |
| 576 |
case WEAP_CRUSH: mtype = ATM_CRUSH; break; |
| 577 |
case WEAP_BLUD: mtype = ATM_BLUD; break; |
| 578 |
default: mtype = ATM_BASIC; break; |
| 579 |
} |
| 580 |
for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
| 581 |
if (dam < attack_mess[mtype][i].level |
| 582 |
|| attack_mess[mtype][i+1].level == -1) { |
| 583 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[mtype][i].buf1, op->name, attack_mess[mtype][i].buf2); |
| 584 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[mtype][i].buf3); |
| 585 |
found++; |
| 586 |
break; |
| 587 |
} |
| 588 |
} else { |
| 589 |
for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_BASIC][i].level != -1; i++) |
| 590 |
if (dam < attack_mess[ATM_BASIC][i].level |
| 591 |
|| attack_mess[ATM_BASIC][i+1].level == -1) { |
| 592 |
snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_BASIC][i].buf1, op->name, attack_mess[ATM_BASIC][i].buf2); |
| 593 |
snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_BASIC][i].buf3); |
| 594 |
found++; |
| 595 |
break; |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
if (!found) { |
| 600 |
snprintf(buf1, sizeof(buf1), "hit"); |
| 601 |
snprintf(buf2, sizeof(buf2), "hits"); |
| 602 |
} |
| 603 |
|
| 604 |
if (dam > 0) { |
| 605 |
if (hitter->chosen_skill) |
| 606 |
play_sound_map(SOUND_TYPE_HIT, hitter, 0, hitter->chosen_skill->name); |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
owner = object_get_owner(hitter); |
| 611 |
if (hitter->type != PLAYER && (owner == NULL || owner->type != PLAYER)) |
| 612 |
return; |
| 613 |
|
| 614 |
|
| 615 |
if (type&AT_MAGIC && rndm(0, 5)) |
| 616 |
return; |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
if (op->type == PLAYER |
| 621 |
&& rndm(0, 1) |
| 622 |
&& ((owner != NULL ? owner : hitter)->type) == PLAYER) { |
| 623 |
if (owner != NULL) |
| 624 |
snprintf(buf, sizeof(buf), "%s's %s %s you.", owner->name, hitter->name, buf2); |
| 625 |
else { |
| 626 |
snprintf(buf, sizeof(buf), "%s%s you.", hitter->name, buf2); |
| 627 |
} |
| 628 |
draw_ext_info(NDI_BLACK, 0, op, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_WAS_HIT, buf); |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
if (hitter->type == PLAYER) { |
| 634 |
snprintf(buf, sizeof(buf), "You %s.", buf1); |
| 635 |
draw_ext_info(NDI_BLACK, 0, hitter, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_HIT, |
| 636 |
buf); |
| 637 |
} else if (owner != NULL && owner->type == PLAYER) { |
| 638 |
|
| 639 |
if (hitter->type == SPELL_EFFECT |
| 640 |
&& (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE)) { |
| 641 |
i = 4; |
| 642 |
map = hitter->map; |
| 643 |
if (OUT_OF_REAL_MAP(map, hitter->x, hitter->y)) |
| 644 |
return; |
| 645 |
FOR_MAP_PREPARE(map, hitter->x, hitter->y, next) |
| 646 |
if (next->type == SPELL_EFFECT |
| 647 |
&& (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) { |
| 648 |
i *= 3; |
| 649 |
if (i > 10000) |
| 650 |
|
| 651 |
break; |
| 652 |
} |
| 653 |
FOR_MAP_FINISH(); |
| 654 |
if (i < 0) |
| 655 |
return; |
| 656 |
if (rndm(0, i) != 0) |
| 657 |
return; |
| 658 |
} else if (rndm(0, 5) != 0) |
| 659 |
return; |
| 660 |
play_sound_map(SOUND_TYPE_HIT, owner, 0, "hit"); |
| 661 |
draw_ext_info_format(NDI_BLACK, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_PET_HIT, |
| 662 |
"Your %s%s %s.", |
| 663 |
hitter->name, buf2, op->name); |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
static int get_attack_mode(object **target, object **hitter, |
| 679 |
int *simple_attack) { |
| 680 |
if (QUERY_FLAG(*target, FLAG_FREED) || QUERY_FLAG(*hitter, FLAG_FREED)) { |
| 681 |
LOG(llevError, "BUG: get_attack_mode(): freed object\n"); |
| 682 |
return 1; |
| 683 |
} |
| 684 |
*target = HEAD(*target); |
| 685 |
*hitter = HEAD(*hitter); |
| 686 |
if ((*hitter)->env != NULL || (*target)->env != NULL) { |
| 687 |
*simple_attack = 1; |
| 688 |
return 0; |
| 689 |
} |
| 690 |
if (QUERY_FLAG(*target, FLAG_REMOVED) |
| 691 |
|| QUERY_FLAG(*hitter, FLAG_REMOVED) |
| 692 |
|| (*hitter)->map == NULL |
| 693 |
|| !on_same_map((*hitter), (*target))) { |
| 694 |
LOG(llevError, "BUG: hitter (arch %s, name %s) with no relation to target\n", (*hitter)->arch->name, (*hitter)->name); |
| 695 |
return 1; |
| 696 |
} |
| 697 |
*simple_attack = 0; |
| 698 |
return 0; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
static int abort_attack(object *target, object *hitter, int simple_attack) { |
| 715 |
int new_mode; |
| 716 |
|
| 717 |
if (hitter->env == target || target->env == hitter) |
| 718 |
new_mode = 1; |
| 719 |
else if (QUERY_FLAG(hitter, FLAG_REMOVED) |
| 720 |
|| QUERY_FLAG(target, FLAG_REMOVED) |
| 721 |
|| hitter->map == NULL || !on_same_map(hitter, target)) |
| 722 |
return 1; |
| 723 |
else |
| 724 |
new_mode = 0; |
| 725 |
return new_mode != simple_attack; |
| 726 |
} |
| 727 |
|
| 728 |
static void thrown_item_effect(object *, object *); |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
static int attack_ob_simple(object *op, object *hitter, int base_dam, int base_wc) { |
| 746 |
int simple_attack, roll, dam; |
| 747 |
uint32_t type; |
| 748 |
tag_t op_tag, hitter_tag; |
| 749 |
const char *anim_suffix = NULL; |
| 750 |
|
| 751 |
if (get_attack_mode(&op, &hitter, &simple_attack)) |
| 752 |
return 1; |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
if (hitter->type == PLAYER) { |
| 758 |
if (hitter->current_weapon != NULL) { |
| 759 |
|
| 760 |
if (execute_event(hitter->current_weapon, EVENT_ATTACKS, |
| 761 |
hitter, op, NULL, SCRIPT_FIX_ALL) != 0) |
| 762 |
return 0; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
if (hitter->current_weapon) { |
| 767 |
anim_suffix = hitter->current_weapon->anim_suffix; |
| 768 |
} else if (hitter->chosen_skill) { |
| 769 |
anim_suffix = hitter->chosen_skill->anim_suffix; |
| 770 |
} |
| 771 |
|
| 772 |
if (!anim_suffix) { |
| 773 |
anim_suffix = "attack"; |
| 774 |
} |
| 775 |
apply_anim_suffix(hitter, anim_suffix); |
| 776 |
|
| 777 |
|
| 778 |
op_tag = op->count; |
| 779 |
hitter_tag = hitter->count; |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
if (!simple_attack && QUERY_FLAG(op, FLAG_MONSTER) |
| 785 |
&& op->speed_left > -(FABS(op->speed))*0.3) { |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
op->speed_left--; |
| 792 |
process_object(op); |
| 793 |
if (object_was_destroyed(op, op_tag) |
| 794 |
|| object_was_destroyed(hitter, hitter_tag) |
| 795 |
|| abort_attack(op, hitter, simple_attack)) |
| 796 |
return 1; |
| 797 |
} |
| 798 |
|
| 799 |
roll = random_roll(1, 20, hitter, PREFER_HIGH); |
| 800 |
|
| 801 |
|
| 802 |
if (!simple_attack) |
| 803 |
roll += adj_attackroll(hitter, op); |
| 804 |
|
| 805 |
|
| 806 |
if (roll >= 20 || op->stats.ac >= base_wc-roll) { |
| 807 |
if (settings.casting_time == TRUE) { |
| 808 |
if (hitter->type == PLAYER && hitter->casting_time > -1) { |
| 809 |
hitter->casting_time = -1; |
| 810 |
draw_ext_info(NDI_UNIQUE, 0, hitter, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_FUMBLE, |
| 811 |
"You attacked and lost your spell!"); |
| 812 |
} |
| 813 |
if (op->casting_time > -1 && base_dam > 0) { |
| 814 |
op->casting_time = -1; |
| 815 |
if (op->type == PLAYER) { |
| 816 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_FUMBLE, |
| 817 |
"You were hit and lost your spell!"); |
| 818 |
draw_ext_info_format(NDI_ALL|NDI_UNIQUE, 5, NULL, |
| 819 |
MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_FUMBLE, |
| 820 |
"%s was hit by %s and lost a spell.", |
| 821 |
op->name, hitter->name); |
| 822 |
} |
| 823 |
} |
| 824 |
} |
| 825 |
if (!simple_attack) { |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
if (QUERY_FLAG(op, FLAG_SLEEP)) |
| 830 |
CLEAR_FLAG(op, FLAG_SLEEP); |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
if (op->type != PLAYER && !monster_can_see_enemy(op, hitter) |
| 835 |
&& !object_get_owner(op) && rndm(0, op->stats.Int)) |
| 836 |
monster_npc_call_help(op); |
| 837 |
|
| 838 |
|
| 839 |
if (op->hide && QUERY_FLAG(hitter, FLAG_ALIVE)) { |
| 840 |
make_visible(op); |
| 841 |
if (op->type == PLAYER) |
| 842 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_WAS_HIT, |
| 843 |
"You were hit by a wild attack. You are no longer hidden!"); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
thrown_item_effect(hitter, op); |
| 852 |
if (object_was_destroyed(hitter, hitter_tag) |
| 853 |
|| object_was_destroyed(op, op_tag) |
| 854 |
|| abort_attack(op, hitter, simple_attack)) { |
| 855 |
return 0; |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
if (base_dam <= 0) |
| 863 |
base_dam = 1; |
| 864 |
|
| 865 |
type = hitter->attacktype; |
| 866 |
if (!type) |
| 867 |
type = AT_PHYSICAL; |
| 868 |
|
| 869 |
if (!simple_attack && QUERY_FLAG(op, FLAG_HITBACK) |
| 870 |
&& QUERY_FLAG(hitter, FLAG_ALIVE)) { |
| 871 |
if (op->attacktype&AT_ACID && hitter->type == PLAYER) |
| 872 |
draw_ext_info(NDI_UNIQUE, 0, hitter, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_WAS_HIT, |
| 873 |
"You are splashed by acid!\n"); |
| 874 |
hit_player(hitter, random_roll(0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
| 875 |
if (object_was_destroyed(op, op_tag) |
| 876 |
|| object_was_destroyed(hitter, hitter_tag) |
| 877 |
|| abort_attack(op, hitter, simple_attack)) { |
| 878 |
return 0; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
dam = hit_player(op, random_roll(1, base_dam, hitter, PREFER_HIGH), hitter, type, 1); |
| 886 |
if (object_was_destroyed(op, op_tag) |
| 887 |
|| object_was_destroyed(hitter, hitter_tag) |
| 888 |
|| abort_attack(op, hitter, simple_attack)) { |
| 889 |
return 0; |
| 890 |
} |
| 891 |
} else { |
| 892 |
play_sound_map(SOUND_TYPE_HIT, hitter, 0, "miss"); |
| 893 |
dam = 0; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
return dam; |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
int attack_ob(object *op, object *hitter) { |
| 911 |
hitter = HEAD(hitter); |
| 912 |
return attack_ob_simple(op, hitter, hitter->stats.dam, hitter->stats.wc); |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
static int stick_arrow(object *op, object *tmp) { |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
if (op->weight <= 5000 && tmp->stats.hp >= 0) { |
| 933 |
object_remove(op); |
| 934 |
op = object_insert_in_ob(op, HEAD(tmp)); |
| 935 |
return 1; |
| 936 |
} else |
| 937 |
return 0; |
| 938 |
} |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
object *hit_with_arrow(object *op, object *victim) { |
| 953 |
object *container, *hitter; |
| 954 |
int hit_something = 0; |
| 955 |
tag_t victim_tag, hitter_tag, container_tag; |
| 956 |
int16_t victim_x, victim_y; |
| 957 |
mapstruct *victim_map; |
| 958 |
const char *old_skill = NULL; |
| 959 |
|
| 960 |
|
| 961 |
hitter = op->inv; |
| 962 |
FOR_OB_AND_BELOW_PREPARE(hitter) |
| 963 |
if (hitter->type != EVENT_CONNECTOR) { |
| 964 |
break; |
| 965 |
} |
| 966 |
FOR_OB_AND_BELOW_FINISH(); |
| 967 |
if (!hitter) { |
| 968 |
container = NULL; |
| 969 |
hitter = op; |
| 970 |
if (free_no_drop(hitter)) |
| 971 |
return NULL; |
| 972 |
} else { |
| 973 |
container = op; |
| 974 |
object_remove(hitter); |
| 975 |
if (free_no_drop(hitter)) |
| 976 |
return NULL; |
| 977 |
|
| 978 |
object_insert_in_map_at(hitter, container->map, hitter, INS_NO_MERGE|INS_NO_WALK_ON, container->x, container->y); |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
container_tag = container->count; |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
victim_x = victim->x; |
| 988 |
victim_y = victim->y; |
| 989 |
victim_map = victim->map; |
| 990 |
victim_tag = victim->count; |
| 991 |
hitter_tag = hitter->count; |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
if (execute_event(op, EVENT_ATTACKS, hitter, victim, NULL, SCRIPT_FIX_ALL) == 0) { |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
if (container != NULL) { |
| 1005 |
old_skill = hitter->skill; |
| 1006 |
hitter->skill = add_refcount(container->skill); |
| 1007 |
} |
| 1008 |
hit_something = attack_ob_simple(victim, hitter, op->stats.dam, op->stats.wc); |
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
if (object_was_destroyed(hitter, hitter_tag) || hitter->env != NULL) { |
| 1017 |
if (container) { |
| 1018 |
object_remove(container); |
| 1019 |
object_free_drop_inventory(container); |
| 1020 |
} |
| 1021 |
return NULL; |
| 1022 |
} |
| 1023 |
if (container != NULL) { |
| 1024 |
free_string(hitter->skill); |
| 1025 |
hitter->skill = old_skill; |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
if (hit_something && op->speed <= 10.0) { |
| 1032 |
|
| 1033 |
if (container == NULL) { |
| 1034 |
hitter = fix_stopped_arrow(hitter); |
| 1035 |
if (hitter == NULL) |
| 1036 |
return NULL; |
| 1037 |
} else { |
| 1038 |
if(!object_was_destroyed(container, container_tag)) { |
| 1039 |
object_remove(container); |
| 1040 |
object_free_drop_inventory(container); |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
if (!object_was_destroyed(victim, victim_tag) |
| 1046 |
&& stick_arrow(hitter, victim)) { |
| 1047 |
object_set_owner(hitter, NULL); |
| 1048 |
return NULL; |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
if (victim_x != hitter->x || victim_y != hitter->y) { |
| 1059 |
object_remove(hitter); |
| 1060 |
object_set_owner(hitter, NULL); |
| 1061 |
object_insert_in_map_at(hitter, victim_map, hitter, 0, victim_x, victim_y); |
| 1062 |
} else { |
| 1063 |
|
| 1064 |
object_merge(hitter, NULL); |
| 1065 |
object_set_owner(hitter, NULL); |
| 1066 |
} |
| 1067 |
return NULL; |
| 1068 |
} |
| 1069 |
|
| 1070 |
if (hit_something && op->speed >= 10.0) |
| 1071 |
op->speed -= 1.0; |
| 1072 |
|
| 1073 |
|
| 1074 |
if (container) { |
| 1075 |
object_remove(hitter); |
| 1076 |
object_insert_in_ob(hitter, container); |
| 1077 |
} |
| 1078 |
return op; |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
static void tear_down_wall(object *op) { |
| 1088 |
int perc = 0; |
| 1089 |
|
| 1090 |
if (!op->stats.maxhp) { |
| 1091 |
LOG(llevError, "TEAR_DOWN wall %s had no maxhp.\n", op->name); |
| 1092 |
perc = 1; |
| 1093 |
} else if (!GET_ANIM_ID(op)) { |
| 1094 |
|
| 1095 |
if (op->stats.hp < 0) { |
| 1096 |
object_remove(op); |
| 1097 |
object_free_drop_inventory(op); |
| 1098 |
|
| 1099 |
|
| 1100 |
} |
| 1101 |
return; |
| 1102 |
} |
| 1103 |
assert(op->stats.maxhp > 0); |
| 1104 |
perc = NUM_ANIMATIONS(op)-((int)NUM_ANIMATIONS(op)*op->stats.hp)/op->stats.maxhp; |
| 1105 |
|
| 1106 |
if (perc >= (int)NUM_ANIMATIONS(op)) |
| 1107 |
perc = NUM_ANIMATIONS(op)-1; |
| 1108 |
else if (perc < 1) |
| 1109 |
perc = 1; |
| 1110 |
SET_ANIMATION(op, perc); |
| 1111 |
object_update(op, UP_OBJ_FACE); |
| 1112 |
if (perc == NUM_ANIMATIONS(op)-1) { |
| 1113 |
if (op->face == blank_face) { |
| 1114 |
|
| 1115 |
object_remove(op); |
| 1116 |
object_free_drop_inventory(op); |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
} else { |
| 1121 |
CLEAR_FLAG(op, FLAG_BLOCKSVIEW); |
| 1122 |
update_all_los(op->map, op->x, op->y); |
| 1123 |
op->move_block = 0; |
| 1124 |
CLEAR_FLAG(op, FLAG_ALIVE); |
| 1125 |
} |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
static void scare_creature(object *target, object *hitter) { |
| 1137 |
object *owner = object_get_owner(hitter); |
| 1138 |
|
| 1139 |
if (!owner) |
| 1140 |
owner = hitter; |
| 1141 |
|
| 1142 |
SET_FLAG(target, FLAG_SCARED); |
| 1143 |
if (!target->enemy) |
| 1144 |
object_set_enemy(target, owner); |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
static int hit_with_one_attacktype(object *op, object *hitter, int dam, uint32_t attacknum) { |
| 1164 |
int doesnt_slay = 1; |
| 1165 |
char name_hitter[MAX_BUF], name_op[MAX_BUF]; |
| 1166 |
|
| 1167 |
|
| 1168 |
if (attacknum >= NROFATTACKS) { |
| 1169 |
LOG(llevError, "hit_with_one_attacktype: Invalid attacknumber passed: %u\n", attacknum); |
| 1170 |
return 0; |
| 1171 |
} |
| 1172 |
|
| 1173 |
if (dam < 0) { |
| 1174 |
LOG(llevError, "hit_with_one_attacktype called with negative damage: %d\n", dam); |
| 1175 |
return 0; |
| 1176 |
} |
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
if (attacknum == ATNR_INTERNAL) |
| 1181 |
return dam; |
| 1182 |
|
| 1183 |
if (hitter->slaying) { |
| 1184 |
|
| 1185 |
if ((op->race != NULL && strstr(op->race, hitter->slaying)) |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
) { |
| 1191 |
doesnt_slay = 0; |
| 1192 |
dam *= 3; |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
if (attacknum != ATNR_LIFE_STEALING && op->resist[attacknum]) { |
| 1204 |
|
| 1205 |
|
| 1206 |
dam *= (100-op->resist[attacknum]); |
| 1207 |
if (dam >= 100) |
| 1208 |
dam /= 100; |
| 1209 |
else |
| 1210 |
dam = (dam > (random_roll(0, 99, op, PREFER_LOW))) ? 1 : 0; |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
if (op->resist[attacknum] >= 100 |
| 1219 |
&& doesnt_slay |
| 1220 |
&& attacknum != ATNR_ACID) |
| 1221 |
return 0; |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
switch (attacknum) { |
| 1226 |
case ATNR_PHYSICAL: |
| 1227 |
|
| 1228 |
check_physically_infect(op, hitter); |
| 1229 |
break; |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
case ATNR_CONFUSION: |
| 1238 |
case ATNR_POISON: |
| 1239 |
case ATNR_SLOW: |
| 1240 |
case ATNR_PARALYZE: |
| 1241 |
case ATNR_FEAR: |
| 1242 |
case ATNR_CANCELLATION: |
| 1243 |
case ATNR_DEPLETE: |
| 1244 |
case ATNR_BLIND: { |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
int level_diff = MIN(110, MAX(0, op->level-hitter->level)); |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
if (op->speed |
| 1256 |
&& (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER) |
| 1257 |
&& !(rndm(0, (attacknum == ATNR_SLOW ? 6 : 3)-1)) |
| 1258 |
&& !did_make_save(op, level_diff, op->resist[attacknum]/10)) { |
| 1259 |
|
| 1260 |
if (attacknum == ATNR_CONFUSION) |
| 1261 |
confuse_living(op, hitter, dam); |
| 1262 |
else if (attacknum == ATNR_POISON) |
| 1263 |
poison_living(op, hitter, dam); |
| 1264 |
else if (attacknum == ATNR_SLOW) |
| 1265 |
slow_living(op, hitter, dam); |
| 1266 |
else if (attacknum == ATNR_PARALYZE) |
| 1267 |
paralyze_living(op, dam); |
| 1268 |
else if (attacknum == ATNR_FEAR) |
| 1269 |
scare_creature(op, hitter); |
| 1270 |
else if (attacknum == ATNR_CANCELLATION) |
| 1271 |
cancellation(op); |
| 1272 |
else if (attacknum == ATNR_DEPLETE) |
| 1273 |
drain_stat(op); |
| 1274 |
else if (attacknum == ATNR_BLIND |
| 1275 |
&& !QUERY_FLAG(op, FLAG_UNDEAD) |
| 1276 |
&& !QUERY_FLAG(op, FLAG_GENERATOR)) |
| 1277 |
blind_living(op, hitter, dam); |
| 1278 |
} |
| 1279 |
dam = 0; |
| 1280 |
} |
| 1281 |
break; |
| 1282 |
|
| 1283 |
case ATNR_ACID: { |
| 1284 |
int flag = 0; |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
if (!op_on_battleground(op, NULL, NULL, NULL) |
| 1289 |
&& (op->resist[ATNR_ACID] < 50)) { |
| 1290 |
FOR_INV_PREPARE(op, tmp) { |
| 1291 |
if (tmp->invisible) |
| 1292 |
continue; |
| 1293 |
if (!QUERY_FLAG(tmp, FLAG_APPLIED) |
| 1294 |
|| (tmp->resist[ATNR_ACID] >= 10)) |
| 1295 |
|
| 1296 |
continue; |
| 1297 |
if (!(tmp->material&M_IRON)) |
| 1298 |
continue; |
| 1299 |
if (tmp->magic < -4) |
| 1300 |
continue; |
| 1301 |
if (tmp->type == RING |
| 1302 |
|
| 1303 |
|| tmp->type == GIRDLE |
| 1304 |
|| tmp->type == AMULET |
| 1305 |
|| tmp->type == WAND |
| 1306 |
|| tmp->type == ROD) |
| 1307 |
continue; |
| 1308 |
|
| 1309 |
|
| 1310 |
if (rndm(0, dam+4) > random_roll(0, 39, op, PREFER_HIGH)+2*tmp->magic) { |
| 1311 |
if (op->type == PLAYER) { |
| 1312 |
|
| 1313 |
query_name(hitter, name_hitter, MAX_BUF); |
| 1314 |
query_name(tmp, name_op, MAX_BUF); |
| 1315 |
draw_ext_info_format(NDI_UNIQUE|NDI_RED, 0, op, |
| 1316 |
MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_WAS_HIT, |
| 1317 |
"The %s's acid corrodes your %s!", |
| 1318 |
name_hitter, name_op); |
| 1319 |
} |
| 1320 |
flag = 1; |
| 1321 |
tmp->magic--; |
| 1322 |
if (op->type == PLAYER) |
| 1323 |
esrv_update_item(UPD_NAME, op, tmp); |
| 1324 |
} |
| 1325 |
} FOR_INV_FINISH(); |
| 1326 |
if (flag) |
| 1327 |
fix_object(op); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
break; |
| 1331 |
|
| 1332 |
case ATNR_DRAIN: { |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
int rate; |
| 1337 |
|
| 1338 |
if (op->resist[ATNR_DRAIN] >= 0) |
| 1339 |
rate = 50+op->resist[ATNR_DRAIN]/2; |
| 1340 |
else |
| 1341 |
rate = 5000/(100-op->resist[ATNR_DRAIN]); |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
if (!rate) |
| 1346 |
return 0; |
| 1347 |
|
| 1348 |
if (op->stats.exp <= rate) { |
| 1349 |
if (op->type == GOLEM) |
| 1350 |
dam = 999; |
| 1351 |
else |
| 1352 |
|
| 1353 |
dam = hit_with_one_attacktype(op, hitter, dam, ATNR_PHYSICAL); |
| 1354 |
} else { |
| 1355 |
|
| 1356 |
if (hitter->stats.hp < hitter->stats.maxhp |
| 1357 |
&& (op->level > hitter->level) |
| 1358 |
&& random_roll(0, (op->level-hitter->level+2), hitter, PREFER_HIGH) > 3) |
| 1359 |
hitter->stats.hp++; |
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
if (!op_on_battleground(hitter, NULL, NULL, NULL) && !QUERY_FLAG(op, FLAG_WAS_WIZ)) { |
| 1369 |
object *owner = object_get_owner(hitter); |
| 1370 |
int64_t orig_exp = op->stats.exp; |
| 1371 |
|
| 1372 |
change_exp(op, -op->stats.exp/rate, NULL, 0); |
| 1373 |
|
| 1374 |
if (owner && owner != hitter) { |
| 1375 |
if (op->type != PLAYER || owner->type != PLAYER) |
| 1376 |
change_exp(owner, MIN(op->stats.exp/(rate*2), orig_exp - op->stats.exp), |
| 1377 |
hitter->chosen_skill ? hitter->chosen_skill->skill : NULL, SK_EXP_TOTAL); |
| 1378 |
} else if (op->type != PLAYER || hitter->type != PLAYER) { |
| 1379 |
change_exp(hitter, MIN(op->stats.exp/(rate*2), orig_exp - op->stats.exp), |
| 1380 |
hitter->chosen_skill ? hitter->chosen_skill->skill : NULL, 0); |
| 1381 |
} |
| 1382 |
} |
| 1383 |
dam = 1; |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
} |
| 1388 |
} |
| 1389 |
break; |
| 1390 |
|
| 1391 |
case ATNR_TURN_UNDEAD: { |
| 1392 |
if (QUERY_FLAG(op, FLAG_UNDEAD)) { |
| 1393 |
object *owner = object_get_owner(hitter) == NULL ? hitter : object_get_owner(hitter); |
| 1394 |
const object *god = find_god(determine_god(owner)); |
| 1395 |
int div = 1; |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
if (!god |
| 1400 |
|| !god->slaying |
| 1401 |
|| strstr(god->slaying, undead_name) == NULL) |
| 1402 |
div = 2; |
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
if ((op->level*div + (op->resist[ATNR_TURN_UNDEAD] / 20)) < (get_turn_bonus(owner->stats.Wis)+owner->level)) |
| 1411 |
scare_creature(op, owner); |
| 1412 |
} else |
| 1413 |
dam = 0; |
| 1414 |
} |
| 1415 |
break; |
| 1416 |
|
| 1417 |
case ATNR_DEATH: |
| 1418 |
deathstrike_living(op, hitter, &dam); |
| 1419 |
break; |
| 1420 |
|
| 1421 |
case ATNR_CHAOS: |
| 1422 |
query_name(op, name_op, MAX_BUF); |
| 1423 |
query_name(hitter, name_hitter, MAX_BUF); |
| 1424 |
LOG(llevError, "%s was hit by %s with non-specific chaos.\n", name_op, name_hitter); |
| 1425 |
dam = 0; |
| 1426 |
break; |
| 1427 |
|
| 1428 |
case ATNR_COUNTERSPELL: |
| 1429 |
dam = 0; |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
break; |
| 1435 |
|
| 1436 |
case ATNR_HOLYWORD: { |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
object *owner = object_get_owner(hitter) == NULL ? hitter : object_get_owner(hitter); |
| 1441 |
|
| 1442 |
|
| 1443 |
if (op->level+(op->resist[ATNR_HOLYWORD]/100) < owner->level+get_turn_bonus(owner->stats.Wis)) |
| 1444 |
scare_creature(op, owner); |
| 1445 |
} |
| 1446 |
break; |
| 1447 |
|
| 1448 |
case ATNR_LIFE_STEALING: { |
| 1449 |
int new_hp; |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
int dam_modifier = is_wraith_pl(hitter) ? 200 : 3000; |
| 1462 |
|
| 1463 |
|
| 1464 |
if (op->type == GOLEM |
| 1465 |
|| (QUERY_FLAG(op, FLAG_UNDEAD)) |
| 1466 |
|| !(QUERY_FLAG(op, FLAG_ALIVE)) |
| 1467 |
|| (op->type == DOOR)) |
| 1468 |
return 0; |
| 1469 |
|
| 1470 |
if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
| 1471 |
dam = (dam*(100-op->resist[ATNR_DRAIN]))/dam_modifier; |
| 1472 |
else |
| 1473 |
dam = (dam*(100-op->resist[ATNR_LIFE_STEALING]))/dam_modifier; |
| 1474 |
|
| 1475 |
if (dam > op->stats.hp+1) |
| 1476 |
dam = op->stats.hp+1; |
| 1477 |
new_hp = hitter->stats.hp+dam; |
| 1478 |
if (new_hp > hitter->stats.maxhp) |
| 1479 |
new_hp = hitter->stats.maxhp; |
| 1480 |
if (new_hp > hitter->stats.hp) |
| 1481 |
hitter->stats.hp = new_hp; |
| 1482 |
|
| 1483 |
|
| 1484 |
if (is_wraith_pl(hitter)) { |
| 1485 |
if (hitter->stats.food+dam >= MAX_FOOD) |
| 1486 |
hitter->stats.food = MAX_FOOD; |
| 1487 |
else |
| 1488 |
hitter->stats.food += dam; |
| 1489 |
fix_object(hitter); |
| 1490 |
} |
| 1491 |
} |
| 1492 |
} |
| 1493 |
return dam; |
| 1494 |
} |
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
#ifdef PARTY_KILL_LOG |
| 1501 |
void party_add_kill(partylist *party, const char *killer, const char *dead, long exp); |
| 1502 |
#endif |
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
static int kill_object(object *op, int dam, object *hitter) { |
| 1532 |
char kill_message[MAX_BUF]; |
| 1533 |
const char *skill; |
| 1534 |
int maxdam = 0; |
| 1535 |
int battleg = 0; |
| 1536 |
int pk = 0; |
| 1537 |
object *owner = NULL; |
| 1538 |
const object *skop = NULL; |
| 1539 |
sstring death_animation; |
| 1540 |
|
| 1541 |
if (op->stats.hp >= 0) |
| 1542 |
return -1; |
| 1543 |
|
| 1544 |
|
| 1545 |
if (execute_event(op, EVENT_DEATH, hitter, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 1546 |
return 0; |
| 1547 |
|
| 1548 |
execute_global_event(EVENT_GKILL, op, hitter); |
| 1549 |
|
| 1550 |
if (op->map) { |
| 1551 |
death_animation = object_get_value(op, "death_animation"); |
| 1552 |
if (death_animation != NULL) { |
| 1553 |
object *death = create_archetype(death_animation); |
| 1554 |
|
| 1555 |
if (death) |
| 1556 |
object_insert_in_map_at(death, op->map, op, 0, op->x, op->y); |
| 1557 |
} |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
maxdam = dam+op->stats.hp+1; |
| 1565 |
|
| 1566 |
if (QUERY_FLAG(op, FLAG_BLOCKSVIEW)) |
| 1567 |
update_all_los(op->map, op->x, op->y); |
| 1568 |
|
| 1569 |
if (op->type == DOOR) { |
| 1570 |
op->speed = 0.1; |
| 1571 |
object_update_speed(op); |
| 1572 |
op->speed_left = -0.05; |
| 1573 |
return maxdam; |
| 1574 |
} |
| 1575 |
if (QUERY_FLAG(op, FLAG_FRIENDLY) && op->type != PLAYER) { |
| 1576 |
object *owner; |
| 1577 |
|
| 1578 |
remove_friendly_object(op); |
| 1579 |
owner = object_get_owner(op); |
| 1580 |
if (owner != NULL |
| 1581 |
&& owner->type == PLAYER) { |
| 1582 |
if (owner->contr->ranges[range_golem] == op) { |
| 1583 |
owner->contr->ranges[range_golem] = NULL; |
| 1584 |
owner->contr->golem_count = 0; |
| 1585 |
} |
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
draw_ext_info_format(NDI_UNIQUE, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_PET_DIED, |
| 1590 |
"Your pet, the %s, is killed by %s.", |
| 1591 |
op->name, hitter->name); |
| 1592 |
} |
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
object_remove(op); |
| 1601 |
object_free_drop_inventory(op); |
| 1602 |
return maxdam; |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
owner = object_get_owner(hitter); |
| 1608 |
if (owner == NULL) |
| 1609 |
owner = hitter; |
| 1610 |
|
| 1611 |
|
| 1612 |
if (op_on_battleground(op, NULL, NULL, NULL)) |
| 1613 |
battleg = 1; |
| 1614 |
|
| 1615 |
|
| 1616 |
if (op->type == PLAYER && owner->type == PLAYER && owner != op) |
| 1617 |
pk = 1; |
| 1618 |
|
| 1619 |
|
| 1620 |
if (owner->type == PLAYER) { |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
if (op->type == PLAYER && !battleg) { |
| 1627 |
time_t t = time(NULL); |
| 1628 |
struct tm *tmv; |
| 1629 |
char buf[256]; |
| 1630 |
char name[MAX_BUF]; |
| 1631 |
|
| 1632 |
tmv = localtime(&t); |
| 1633 |
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y", tmv); |
| 1634 |
query_name(op, name, MAX_BUF); |
| 1635 |
|
| 1636 |
LOG(llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, owner->name, owner->contr->socket.host, name); |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
if (owner->level < op->level*2 || op->stats.exp > 1000) { |
| 1644 |
if (owner != hitter) { |
| 1645 |
char killed[MAX_BUF], with[MAX_BUF]; |
| 1646 |
|
| 1647 |
query_name(op, killed, MAX_BUF); |
| 1648 |
query_name(hitter, with, MAX_BUF); |
| 1649 |
draw_ext_info_format(NDI_BLACK, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_KILL, |
| 1650 |
"You killed %s with %s.", |
| 1651 |
killed, with); |
| 1652 |
} else { |
| 1653 |
char killed[MAX_BUF]; |
| 1654 |
|
| 1655 |
query_name(op, killed, MAX_BUF); |
| 1656 |
draw_ext_info_format(NDI_BLACK, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_KILL, |
| 1657 |
"You killed %s.", |
| 1658 |
killed); |
| 1659 |
} |
| 1660 |
} |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
if (pk == 1 && !battleg) |
| 1674 |
change_luck(owner, -settings.pk_luck_penalty); |
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
skill = NULL; |
| 1681 |
if (hitter->skill && hitter->type != PLAYER) |
| 1682 |
skill = hitter->skill; |
| 1683 |
else if (owner->chosen_skill) { |
| 1684 |
skill = owner->chosen_skill->skill; |
| 1685 |
skop = owner->chosen_skill; |
| 1686 |
} else if (QUERY_FLAG(owner, FLAG_READY_WEAPON)) |
| 1687 |
skill = owner->current_weapon->skill; |
| 1688 |
else |
| 1689 |
LOG(llevError, "kill_object - unable to find skill that killed monster\n"); |
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
if ((!skop || skop->type != SKILL) && skill) { |
| 1695 |
skop = find_applied_skill_by_name(owner, skill); |
| 1696 |
} |
| 1697 |
} |
| 1698 |
else { |
| 1699 |
skill = NULL; |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
if (owner != hitter) { |
| 1704 |
char name_op[MAX_BUF], name_hitter[MAX_BUF]; |
| 1705 |
const char *owner_prefix; |
| 1706 |
const char *op_prefix; |
| 1707 |
|
| 1708 |
owner_prefix = !battleg && pk && owner->contr != NULL && !owner->contr->peaceful ? "hostile " : ""; |
| 1709 |
op_prefix = !battleg && pk && op->contr != NULL && !op->contr->peaceful ? "hostile " : ""; |
| 1710 |
|
| 1711 |
query_name(op, name_op, MAX_BUF); |
| 1712 |
query_name(hitter, name_hitter, MAX_BUF); |
| 1713 |
snprintf(kill_message, sizeof(kill_message), "%s%s killed %s%s with %s%s.", owner_prefix, owner->name, op_prefix, name_op, name_hitter, battleg ? " (duel)" : (pk ? " (pk)" : "")); |
| 1714 |
} else { |
| 1715 |
const char *hitter_prefix; |
| 1716 |
const char *op_prefix; |
| 1717 |
|
| 1718 |
hitter_prefix = !battleg && pk && hitter->contr != NULL && !hitter->contr->peaceful ? "hostile " : ""; |
| 1719 |
op_prefix = !battleg && pk && op->contr != NULL && !op->contr->peaceful ? "hostile " : ""; |
| 1720 |
|
| 1721 |
snprintf(kill_message, sizeof(kill_message), "%s%s killed %s%s%s%s.", hitter_prefix, hitter->name, op_prefix, op->name, |
| 1722 |
(QUERY_FLAG(hitter, FLAG_MONSTER)) || hitter->type == PLAYER ? |
| 1723 |
" in hand to hand combat" : "", battleg ? " (duel)" : (pk ? " (pk)" : "")); |
| 1724 |
} |
| 1725 |
|
| 1726 |
if (!skop) |
| 1727 |
skop = hitter->chosen_skill; |
| 1728 |
if (!skill && skop) |
| 1729 |
skill = skop->skill; |
| 1730 |
|
| 1731 |
draw_ext_info(NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER, |
| 1732 |
kill_message); |
| 1733 |
play_sound_map(SOUND_TYPE_HIT, op, 0, "kill"); |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
if (owner != op && !QUERY_FLAG(op, FLAG_WAS_WIZ)) { |
| 1738 |
int64_t exp; |
| 1739 |
|
| 1740 |
exp = calc_skill_exp(owner, op, skop); |
| 1741 |
|
| 1742 |
|
| 1743 |
if (op->type == PLAYER) { |
| 1744 |
if (battleg) { |
| 1745 |
draw_ext_info(NDI_UNIQUE, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_KILL, |
| 1746 |
"Your foe has fallen!\nVICTORY!!!"); |
| 1747 |
} else { |
| 1748 |
exp = settings.pk_max_experience_percent*exp/100; |
| 1749 |
if (settings.pk_max_experience >= 0) |
| 1750 |
exp = MIN(settings.pk_max_experience, exp); |
| 1751 |
|
| 1752 |
exp = check_exp_loss(op, exp); |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
if (!settings.simple_exp) |
| 1761 |
exp = exp/2; |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
if (battleg) |
| 1767 |
exp = 0; |
| 1768 |
|
| 1769 |
#ifdef PARTY_KILL_LOG |
| 1770 |
if (owner->type == PLAYER && owner->contr->party != NULL) { |
| 1771 |
char name[MAX_BUF]; |
| 1772 |
char op_name[MAX_BUF]; |
| 1773 |
|
| 1774 |
query_name(owner, name, MAX_BUF); |
| 1775 |
query_name(op, op_name, sizeof(op_name)); |
| 1776 |
party_add_kill(owner->contr->party, name, op_name, exp); |
| 1777 |
} |
| 1778 |
#endif |
| 1779 |
share_exp(owner, exp, skill, SK_EXP_TOTAL); |
| 1780 |
} |
| 1781 |
|
| 1782 |
if (op->type != PLAYER) { |
| 1783 |
object_remove(op); |
| 1784 |
object_free_drop_inventory(op); |
| 1785 |
|
| 1786 |
} else { |
| 1787 |
if (owner->type == PLAYER) { |
| 1788 |
snprintf(op->contr->killer, BIG_NAME, "%s the %s", owner->name, owner->contr->title); |
| 1789 |
} else { |
| 1790 |
strncpy(op->contr->killer, hitter->name, BIG_NAME); |
| 1791 |
op->contr->killer[BIG_NAME-1] = '\0'; |
| 1792 |
} |
| 1793 |
|
| 1794 |
if (!QUERY_FLAG(op, FLAG_WIZ)) |
| 1795 |
kill_player(op, owner->type == PLAYER ? owner : hitter); |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
return maxdam; |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
int friendly_fire(object *op, object *hitter) { |
| 1814 |
object *owner; |
| 1815 |
int friendlyfire; |
| 1816 |
|
| 1817 |
hitter = HEAD(hitter); |
| 1818 |
friendlyfire = 0; |
| 1819 |
|
| 1820 |
if (op->type == PLAYER) { |
| 1821 |
if (hitter->type == PLAYER && hitter->contr->peaceful == 1) |
| 1822 |
return 1; |
| 1823 |
|
| 1824 |
owner = object_get_owner(hitter); |
| 1825 |
if (owner != NULL) { |
| 1826 |
if (owner->type == PLAYER && owner->contr->peaceful == 1) |
| 1827 |
friendlyfire = 2; |
| 1828 |
} |
| 1829 |
|
| 1830 |
if (hitter->type == SPELL |
| 1831 |
|| hitter->type == POISONING |
| 1832 |
|| hitter->type == DISEASE |
| 1833 |
|| hitter->type == RUNE) |
| 1834 |
friendlyfire = 0; |
| 1835 |
} |
| 1836 |
return friendlyfire; |
| 1837 |
} |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit) { |
| 1863 |
int maxdam = 0, ndam = 0, magic = (type&AT_MAGIC); |
| 1864 |
int maxattacktype, attacknum; |
| 1865 |
int body_attack = op->head != NULL; |
| 1866 |
int simple_attack; |
| 1867 |
tag_t op_tag, hitter_tag; |
| 1868 |
int rtn_kill = 0; |
| 1869 |
int friendlyfire; |
| 1870 |
object *owner; |
| 1871 |
|
| 1872 |
|
| 1873 |
if (execute_event(op, EVENT_ATTACKED, hitter, hitter->current_weapon ? hitter->current_weapon : hitter, NULL, SCRIPT_FIX_ALL) != 0) |
| 1874 |
return 0; |
| 1875 |
FOR_INV_PREPARE(op, inv) |
| 1876 |
if (execute_event(inv, EVENT_ATTACKED, hitter, hitter->current_weapon ? hitter->current_weapon : hitter, NULL, SCRIPT_FIX_ALL) != 0) |
| 1877 |
return 0; |
| 1878 |
FOR_INV_FINISH(); |
| 1879 |
|
| 1880 |
if (get_attack_mode(&op, &hitter, &simple_attack)) |
| 1881 |
return 0; |
| 1882 |
|
| 1883 |
|
| 1884 |
if (QUERY_FLAG(op, FLAG_WIZ) || QUERY_FLAG(op, FLAG_NO_DAMAGE)) |
| 1885 |
return 0; |
| 1886 |
|
| 1887 |
op_tag = op->count; |
| 1888 |
hitter_tag = hitter->count; |
| 1889 |
|
| 1890 |
if (body_attack) { |
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
if (type&(AT_PARALYZE|AT_SLOW)) { |
| 1901 |
type &= ~(AT_PARALYZE|AT_SLOW); |
| 1902 |
if (!type || type == AT_MAGIC) |
| 1903 |
return 0; |
| 1904 |
} |
| 1905 |
} |
| 1906 |
|
| 1907 |
if (!simple_attack && op->type == DOOR) { |
| 1908 |
object *tmp; |
| 1909 |
|
| 1910 |
tmp = object_find_by_type2(op, RUNE, TRAP); |
| 1911 |
if (tmp != NULL) { |
| 1912 |
spring_trap(tmp, hitter); |
| 1913 |
if (object_was_destroyed(hitter, hitter_tag) |
| 1914 |
|| object_was_destroyed(op, op_tag) |
| 1915 |
|| abort_attack(op, hitter, simple_attack)) |
| 1916 |
return 0; |
| 1917 |
} |
| 1918 |
} |
| 1919 |
|
| 1920 |
if (!QUERY_FLAG(op, FLAG_ALIVE) || op->stats.hp < 0) { |
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
LOG(llevDebug, "victim (arch %s, name %s) already dead in hit_player()\n", op->arch->name, op->name); |
| 1925 |
return 0; |
| 1926 |
} |
| 1927 |
|
| 1928 |
#ifdef ATTACK_DEBUG |
| 1929 |
LOG(llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); |
| 1930 |
#endif |
| 1931 |
|
| 1932 |
if (magic) { |
| 1933 |
|
| 1934 |
|
| 1935 |
dam = dam*(100-op->resist[ATNR_MAGIC]); |
| 1936 |
if (dam >= 100) |
| 1937 |
dam /= 100; |
| 1938 |
else |
| 1939 |
dam = (dam > (rndm(0, 99))) ? 1 : 0; |
| 1940 |
} |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
if (type&AT_CHAOS) { |
| 1948 |
type = ATTACKS[RANDOM()%(sizeof(ATTACKS)/sizeof(*ATTACKS))].attacktype|AT_MAGIC; |
| 1949 |
} |
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
if (type&AT_HOLYWORD) { |
| 1956 |
const object *god; |
| 1957 |
|
| 1958 |
if ((!hitter->slaying || (!(op->race && strstr(hitter->slaying, op->race)) |
| 1959 |
&& !(op->name && strstr(hitter->slaying, op->name)))) |
| 1960 |
&& (!QUERY_FLAG(op, FLAG_UNDEAD) || (hitter->title != NULL |
| 1961 |
&& (god = find_god(determine_god(hitter))) != NULL |
| 1962 |
&& god->race != NULL |
| 1963 |
&& strstr(god->race, undead_name) != NULL))) |
| 1964 |
return 0; |
| 1965 |
} |
| 1966 |
|
| 1967 |
maxattacktype = type; |
| 1968 |
for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) { |
| 1969 |
int attacktype; |
| 1970 |
|
| 1971 |
attacktype = 1<<attacknum; |
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
if (attacktype == AT_MAGIC && (type&~AT_MAGIC)) |
| 1978 |
continue; |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
if (type&attacktype) { |
| 1986 |
ndam = hit_with_one_attacktype(op, hitter, dam, attacknum); |
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
if (ndam >= maxdam) { |
| 1991 |
maxdam = ndam; |
| 1992 |
maxattacktype = 1<<attacknum; |
| 1993 |
} |
| 1994 |
|
| 1995 |
|
| 1996 |
if (attacktype == AT_DEATH && ndam > 0) |
| 1997 |
full_hit = 1; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
friendlyfire = friendly_fire(op, hitter); |
| 2014 |
if (friendlyfire && maxdam) { |
| 2015 |
if (!op_on_battleground(op, NULL, NULL, NULL)) { |
| 2016 |
maxdam = ((dam*settings.set_friendly_fire)/100)+1; |
| 2017 |
#ifdef ATTACK_DEBUG |
| 2018 |
LOG(llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n", friendlyfire, settings.set_friendly_fire, dam, maxdam); |
| 2019 |
#endif |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
if (!full_hit) { |
| 2024 |
archetype *at; |
| 2025 |
unsigned int area = 0; |
| 2026 |
for (at = op->arch; at != NULL; at = at->more) |
| 2027 |
area++; |
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
unsigned int remainder = 100*(maxdam%area)/area; |
| 2032 |
maxdam /= area; |
| 2033 |
if (RANDOM()%100 < remainder) |
| 2034 |
maxdam++; |
| 2035 |
} |
| 2036 |
|
| 2037 |
#ifdef ATTACK_DEBUG |
| 2038 |
LOG(llevDebug, "Attacktype %d did %d damage\n", type, maxdam); |
| 2039 |
#endif |
| 2040 |
|
| 2041 |
owner = object_get_owner(hitter); |
| 2042 |
if (owner != NULL) { |
| 2043 |
if (op->enemy != hitter) |
| 2044 |
object_set_enemy(op, owner); |
| 2045 |
} else if (QUERY_FLAG(hitter, FLAG_ALIVE)) |
| 2046 |
if (op->enemy == NULL || rndm(1, 20) == 0) |
| 2047 |
object_set_enemy(op, hitter); |
| 2048 |
|
| 2049 |
if (QUERY_FLAG(op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) { |
| 2050 |
|
| 2051 |
CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); |
| 2052 |
monster_npc_call_help(op); |
| 2053 |
} |
| 2054 |
|
| 2055 |
if (magic && did_make_save(op, op->level, 0)) |
| 2056 |
maxdam = maxdam/2; |
| 2057 |
|
| 2058 |
attack_message(maxdam, maxattacktype, op, hitter); |
| 2059 |
|
| 2060 |
op->stats.hp -= maxdam; |
| 2061 |
|
| 2062 |
|
| 2063 |
if (op->stats.hp >= 0 |
| 2064 |
&& (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER) |
| 2065 |
&& op->stats.hp < (int16_t)((int32_t)op->run_away * op->stats.maxhp / 100)) { |
| 2066 |
if (QUERY_FLAG(op, FLAG_MONSTER)) |
| 2067 |
SET_FLAG(op, FLAG_RUN_AWAY); |
| 2068 |
else |
| 2069 |
scare_creature(op, hitter); |
| 2070 |
} |
| 2071 |
|
| 2072 |
if (QUERY_FLAG(op, FLAG_TEAR_DOWN)) { |
| 2073 |
if (maxdam) |
| 2074 |
tear_down_wall(op); |
| 2075 |
return maxdam; |
| 2076 |
} |
| 2077 |
|
| 2078 |
|
| 2079 |
rtn_kill = kill_object(op, maxdam, hitter); |
| 2080 |
if (rtn_kill != -1) |
| 2081 |
return rtn_kill; |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
if (QUERY_FLAG(hitter, FLAG_ONE_HIT)) { |
| 2088 |
if (QUERY_FLAG(hitter, FLAG_FRIENDLY)) |
| 2089 |
remove_friendly_object(hitter); |
| 2090 |
object_remove(hitter); |
| 2091 |
object_free_drop_inventory(hitter); |
| 2092 |
|
| 2093 |
} else if (type&AT_PHYSICAL && !QUERY_FLAG(op, FLAG_FREED) && QUERY_FLAG(op, FLAG_SPLITTING)) { |
| 2094 |
change_object(op); |
| 2095 |
} else if (type&AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) { |
| 2096 |
object_remove(hitter); |
| 2097 |
object_free_drop_inventory(hitter); |
| 2098 |
} |
| 2099 |
return maxdam; |
| 2100 |
} |
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
static void poison_living(object *op, object *hitter, int dam) { |
| 2113 |
archetype *at = find_archetype("poisoning"); |
| 2114 |
if (at == NULL) { |
| 2115 |
return; |
| 2116 |
} |
| 2117 |
object *tmp = arch_present_in_ob(at, op); |
| 2118 |
const char *skill; |
| 2119 |
|
| 2120 |
if (tmp == NULL) { |
| 2121 |
tmp = arch_to_object(at); |
| 2122 |
if (tmp == NULL) |
| 2123 |
LOG(llevError, "Failed to clone arch poisoning.\n"); |
| 2124 |
else { |
| 2125 |
tmp = object_insert_in_ob(tmp, op); |
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
if (QUERY_FLAG(hitter, FLAG_ALIVE)) |
| 2135 |
tmp->stats.dam += hitter->level/2; |
| 2136 |
else |
| 2137 |
tmp->stats.dam = dam; |
| 2138 |
|
| 2139 |
object_copy_owner(tmp, hitter); |
| 2140 |
skill = hitter->skill; |
| 2141 |
if (!skill && hitter->chosen_skill) |
| 2142 |
skill = hitter->chosen_skill->name; |
| 2143 |
|
| 2144 |
if (skill && skill != tmp->skill) { |
| 2145 |
if (tmp->skill) |
| 2146 |
free_string(tmp->skill); |
| 2147 |
tmp->skill = add_refcount(skill); |
| 2148 |
} |
| 2149 |
|
| 2150 |
tmp->stats.food += dam; |
| 2151 |
|
| 2152 |
if (op->type == PLAYER) { |
| 2153 |
|
| 2154 |
tmp->stats.Con = MAX(-(dam/4+1), -10); |
| 2155 |
tmp->stats.Str = MAX(-(dam/3+2), -10); |
| 2156 |
tmp->stats.Dex = MAX(-(dam/6+1), -10); |
| 2157 |
tmp->stats.Int = MAX(-dam/7, -10); |
| 2158 |
SET_FLAG(tmp, FLAG_APPLIED); |
| 2159 |
fix_object(op); |
| 2160 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 2161 |
MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, |
| 2162 |
"You suddenly feel very ill."); |
| 2163 |
} |
| 2164 |
if (hitter->type == PLAYER) |
| 2165 |
draw_ext_info_format(NDI_UNIQUE, 0, hitter, |
| 2166 |
MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_HIT, |
| 2167 |
"You poison %s.", |
| 2168 |
op->name); |
| 2169 |
else { |
| 2170 |
object *owner; |
| 2171 |
|
| 2172 |
owner = object_get_owner(hitter); |
| 2173 |
if (owner != NULL && owner->type == PLAYER) |
| 2174 |
draw_ext_info_format(NDI_UNIQUE, 0, owner, |
| 2175 |
MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_PET_HIT, |
| 2176 |
"Your %s poisons %s.", |
| 2177 |
hitter->name, op->name); |
| 2178 |
} |
| 2179 |
tmp->speed_left = 0; |
| 2180 |
} |
| 2181 |
} else |
| 2182 |
tmp->stats.food++; |
| 2183 |
} |
| 2184 |
|
| 2185 |
int slow_living_by(object *op, const int speed_penalty) { |
| 2186 |
archetype *at = find_archetype("slowness"); |
| 2187 |
if (at == NULL) { |
| 2188 |
return 0; |
| 2189 |
} |
| 2190 |
object* tmp = arch_present_in_ob(at, op); |
| 2191 |
int ret; |
| 2192 |
if (tmp == NULL) { |
| 2193 |
tmp = arch_to_object(at); |
| 2194 |
tmp->stats.exp = -speed_penalty; |
| 2195 |
tmp = object_insert_in_ob(tmp, op); |
| 2196 |
ret = 1; |
| 2197 |
} |
| 2198 |
|
| 2199 |
else if (tmp->stats.exp > -speed_penalty) { |
| 2200 |
tmp->stats.exp = -speed_penalty; |
| 2201 |
tmp->stats.food -= 3; |
| 2202 |
ret = 2; |
| 2203 |
} else { |
| 2204 |
tmp->stats.food++; |
| 2205 |
ret = 3; |
| 2206 |
} |
| 2207 |
SET_FLAG(tmp, FLAG_APPLIED); |
| 2208 |
tmp->speed_left = 0; |
| 2209 |
fix_object(op); |
| 2210 |
return ret; |
| 2211 |
} |
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
static void slow_living(object *op, object *hitter, int dam) { |
| 2224 |
|
| 2225 |
int speed_penalty; |
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
speed_penalty = hitter->level - op->level + random_roll(1, 5, hitter, PREFER_LOW); |
| 2234 |
|
| 2235 |
speed_penalty = speed_penalty * (100-op->resist[ATNR_SLOW]) / 100; |
| 2236 |
|
| 2237 |
if (speed_penalty < 1) |
| 2238 |
speed_penalty = 1; |
| 2239 |
else if (speed_penalty > 30) |
| 2240 |
speed_penalty = 30; |
| 2241 |
switch (slow_living_by(op, speed_penalty)) { |
| 2242 |
case 1: |
| 2243 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, |
| 2244 |
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, |
| 2245 |
"The world suddenly moves very fast!"); |
| 2246 |
break; |
| 2247 |
case 2: |
| 2248 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, |
| 2249 |
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, |
| 2250 |
"The world moves even faster!"); |
| 2251 |
break; |
| 2252 |
|
| 2253 |
} |
| 2254 |
} |
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
void confuse_living(object *op, object *hitter, int dam) { |
| 2267 |
object *tmp; |
| 2268 |
int maxduration; |
| 2269 |
|
| 2270 |
tmp = object_present_in_ob_by_name(FORCE, "confusion", op); |
| 2271 |
if (!tmp) { |
| 2272 |
tmp = create_archetype(FORCE_NAME); |
| 2273 |
tmp = object_insert_in_ob(tmp, op); |
| 2274 |
} |
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
tmp->speed = 0.05; |
| 2280 |
tmp->subtype = FORCE_CONFUSION; |
| 2281 |
tmp->duration = 8+MAX(1, 5*(100-op->resist[ATNR_CONFUSION])/100); |
| 2282 |
if (tmp->name) |
| 2283 |
free_string(tmp->name); |
| 2284 |
tmp->name = add_string("confusion"); |
| 2285 |
maxduration = MAX(2, 30*(100-op->resist[ATNR_CONFUSION])/100); |
| 2286 |
if (tmp->duration > maxduration) |
| 2287 |
tmp->duration = maxduration; |
| 2288 |
|
| 2289 |
if (op->type == PLAYER && !QUERY_FLAG(op, FLAG_CONFUSED)) |
| 2290 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, |
| 2291 |
"You suddenly feel very confused!"); |
| 2292 |
SET_FLAG(op, FLAG_CONFUSED); |
| 2293 |
} |
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
void blind_living(object *op, object *hitter, int dam) { |
| 2306 |
object *tmp, *owner; |
| 2307 |
char victim[MAX_BUF]; |
| 2308 |
|
| 2309 |
|
| 2310 |
if (op->resist[ATNR_BLIND] == 100) |
| 2311 |
return; |
| 2312 |
|
| 2313 |
tmp = object_present_in_ob(BLINDNESS, op); |
| 2314 |
if (!tmp) { |
| 2315 |
tmp = create_archetype("blindness"); |
| 2316 |
SET_FLAG(tmp, FLAG_BLIND); |
| 2317 |
SET_FLAG(tmp, FLAG_APPLIED); |
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
tmp->speed = tmp->speed*(100.0-(float)op->resist[ATNR_BLIND])/100; |
| 2322 |
|
| 2323 |
tmp = object_insert_in_ob(tmp, op); |
| 2324 |
change_abil(op, tmp); |
| 2325 |
fix_object(op); |
| 2326 |
|
| 2327 |
owner = object_get_owner(hitter); |
| 2328 |
if (owner == NULL) |
| 2329 |
owner = hitter; |
| 2330 |
|
| 2331 |
query_name(op, victim, MAX_BUF); |
| 2332 |
draw_ext_info_format(NDI_UNIQUE, 0, owner, MSG_TYPE_ATTACK, MSG_TYPE_ATTACK_DID_HIT, |
| 2333 |
"Your attack blinds %s!", |
| 2334 |
victim); |
| 2335 |
} |
| 2336 |
tmp->stats.food += dam; |
| 2337 |
if (tmp->stats.food > 10) |
| 2338 |
tmp->stats.food = 10; |
| 2339 |
} |
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
void paralyze_living(object *op, int dam) { |
| 2350 |
float effect, max; |
| 2351 |
|
| 2352 |
|
| 2353 |
effect = (float)dam*3.0*(100.0-op->resist[ATNR_PARALYZE])/100; |
| 2354 |
|
| 2355 |
if (effect == 0) |
| 2356 |
return; |
| 2357 |
|
| 2358 |
op->speed_left -= FABS(op->speed)*effect; |
| 2359 |
|
| 2360 |
|
| 2361 |
max = (100-op->resist[ATNR_PARALYZE])/2; |
| 2362 |
if (op->speed_left < -(FABS(op->speed)*max)) |
| 2363 |
op->speed_left = (float)-(FABS(op->speed)*max); |
| 2364 |
|
| 2365 |
|
| 2366 |
if (!QUERY_FLAG(op, FLAG_PARALYZED)) { |
| 2367 |
SET_FLAG(op, FLAG_PARALYZED); |
| 2368 |
if (op->type == PLAYER) |
| 2369 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, |
| 2370 |
"You limbs stop moving!"); |
| 2371 |
} |
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
} |
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
static void deathstrike_living(object *op, object *hitter, int *dam) { |
| 2401 |
int atk_lev, def_lev, kill_lev, roll; |
| 2402 |
|
| 2403 |
if (hitter->slaying) { |
| 2404 |
if (!((QUERY_FLAG(op, FLAG_UNDEAD) && strstr(hitter->slaying, undead_name)) |
| 2405 |
|| (op->race && strstr(op->race, hitter->slaying)))) |
| 2406 |
{ |
| 2407 |
*dam = 0; |
| 2408 |
return; |
| 2409 |
} |
| 2410 |
} else |
| 2411 |
if (QUERY_FLAG(op, FLAG_UNDEAD)) |
| 2412 |
{ |
| 2413 |
*dam = 0; |
| 2414 |
return; |
| 2415 |
} |
| 2416 |
|
| 2417 |
def_lev = op->level; |
| 2418 |
if (def_lev < 1) { |
| 2419 |
LOG(llevError, "deathstrike_living: arch %s (%s in %s at %d, %d) has level < 1\n", op->arch->name, op->name, op->map->name, op->x, op->y); |
| 2420 |
def_lev = 1; |
| 2421 |
} |
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level); |
| 2432 |
|
| 2433 |
|
| 2434 |
roll = random_roll(1, 20, hitter, PREFER_HIGH); |
| 2435 |
kill_lev = roll - 18 + atk_lev; |
| 2436 |
kill_lev = kill_lev * (100 - op->resist[ATNR_DEATH]) / 100; |
| 2437 |
|
| 2438 |
|
| 2439 |
if (kill_lev > def_lev) { |
| 2440 |
*dam = op->stats.hp+10; |
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
*dam *= kill_lev/def_lev; |
| 2446 |
} |
| 2447 |
else { |
| 2448 |
*dam = 0; |
| 2449 |
} |
| 2450 |
} |
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
static void thrown_item_effect(object *hitter, object *victim) { |
| 2465 |
if (!QUERY_FLAG(hitter, FLAG_ALIVE)) { |
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
switch (hitter->type) { |
| 2470 |
case POTION: |
| 2471 |
|
| 2472 |
if (QUERY_FLAG(victim, FLAG_ALIVE) |
| 2473 |
&& !QUERY_FLAG(victim, FLAG_UNDEAD) |
| 2474 |
&& (victim->resist[ATNR_MAGIC] < 60)) |
| 2475 |
(void)ob_apply(hitter, victim, 0); |
| 2476 |
break; |
| 2477 |
|
| 2478 |
case POISON: |
| 2479 |
|
| 2480 |
if (QUERY_FLAG(victim, FLAG_ALIVE) |
| 2481 |
&& !QUERY_FLAG(victim, FLAG_UNDEAD) |
| 2482 |
&& (victim->resist[ATNR_POISON] < 60)) |
| 2483 |
(void)ob_apply(victim, hitter, 0); |
| 2484 |
break; |
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
} |
| 2492 |
} |
| 2493 |
} |
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
static int adj_attackroll(object *hitter, object *target) { |
| 2505 |
object *attacker = hitter; |
| 2506 |
int adjust = 0; |
| 2507 |
|
| 2508 |
|
| 2509 |
if (!target || !hitter || !hitter->map || !target->map || !on_same_map(hitter, target)) { |
| 2510 |
LOG(llevError, "BUG: adj_attackroll(): hitter and target not on same map\n"); |
| 2511 |
return 0; |
| 2512 |
} |
| 2513 |
|
| 2514 |
|
| 2515 |
if (is_aimed_missile(hitter)) { |
| 2516 |
attacker = object_get_owner(hitter); |
| 2517 |
if (attacker == NULL) |
| 2518 |
attacker = hitter; |
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
if (QUERY_FLAG(attacker, FLAG_REMOVED)) |
| 2523 |
attacker = hitter; |
| 2524 |
} else if (!QUERY_FLAG(hitter, FLAG_ALIVE)) |
| 2525 |
return 0; |
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
if (!monster_can_see_enemy(attacker, target)) { |
| 2531 |
|
| 2532 |
if (target->invisible || QUERY_FLAG(attacker, FLAG_BLIND)) |
| 2533 |
adjust -= 10; |
| 2534 |
|
| 2535 |
else if (target->map && target->map->darkness > 0 && !monster_stand_in_light(target) && (hitter->type != PLAYER || !player_can_view(hitter, target))) |
| 2536 |
adjust -= target->map->darkness; |
| 2537 |
} |
| 2538 |
|
| 2539 |
if (QUERY_FLAG(attacker, FLAG_SCARED)) |
| 2540 |
adjust -= 3; |
| 2541 |
|
| 2542 |
if (QUERY_FLAG(target, FLAG_UNAGGRESSIVE)) |
| 2543 |
adjust += 1; |
| 2544 |
|
| 2545 |
if (QUERY_FLAG(target, FLAG_SCARED)) |
| 2546 |
adjust += 1; |
| 2547 |
|
| 2548 |
if (QUERY_FLAG(attacker, FLAG_CONFUSED)) |
| 2549 |
adjust -= 3; |
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
if (target->move_type && (attacker->move_type&target->move_type) == 0) |
| 2558 |
adjust -= 2; |
| 2559 |
|
| 2560 |
return adjust; |
| 2561 |
} |
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
static int is_aimed_missile(object *op) { |
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
if (op && (op->move_type&MOVE_FLYING)) { |
| 2576 |
if (op->type == ARROW || op->type == THROWN_OBJ) |
| 2577 |
return 1; |
| 2578 |
else if (op->type == SPELL_EFFECT |
| 2579 |
&& (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION)) |
| 2580 |
return 1; |
| 2581 |
} |
| 2582 |
return 0; |
| 2583 |
} |