| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "global.h" |
| 25 |
|
| 26 |
#include <assert.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "object.h" |
| 31 |
#include "living.h" |
| 32 |
#include "sproto.h" |
| 33 |
#include "spells.h" |
| 34 |
#include "sounds.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
int fire_bolt(object *op, object *caster, int dir, object *spob) { |
| 62 |
object *tmp = NULL; |
| 63 |
int mflags; |
| 64 |
|
| 65 |
if (!spob->other_arch) |
| 66 |
return 0; |
| 67 |
|
| 68 |
tmp = arch_to_object(spob->other_arch); |
| 69 |
if (tmp == NULL) |
| 70 |
return 0; |
| 71 |
|
| 72 |
|
| 73 |
tmp->stats.dam = spob->stats.dam+SP_level_dam_adjust(caster, spob); |
| 74 |
tmp->attacktype = spob->attacktype; |
| 75 |
if (spob->slaying) |
| 76 |
tmp->slaying = add_refcount(spob->slaying); |
| 77 |
tmp->range = spob->range+SP_level_range_adjust(caster, spob); |
| 78 |
tmp->duration = spob->duration+SP_level_duration_adjust(caster, spob); |
| 79 |
tmp->stats.Dex = spob->stats.Dex; |
| 80 |
tmp->stats.Con = spob->stats.Con; |
| 81 |
|
| 82 |
tmp->direction = dir; |
| 83 |
object_update_turn_face(tmp); |
| 84 |
|
| 85 |
object_set_owner(tmp, op); |
| 86 |
set_spell_skill(op, caster, spob, tmp); |
| 87 |
|
| 88 |
mflags = get_map_flags(op->map, &tmp->map, op->x+DIRX(tmp), op->y+DIRY(tmp), &tmp->x, &tmp->y); |
| 89 |
if (mflags&P_OUT_OF_MAP) { |
| 90 |
object_free_drop_inventory(tmp); |
| 91 |
return 0; |
| 92 |
} |
| 93 |
if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) { |
| 94 |
if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) { |
| 95 |
object_free_drop_inventory(tmp); |
| 96 |
return 0; |
| 97 |
} |
| 98 |
tmp->direction = absdir(tmp->direction+4); |
| 99 |
tmp->map = op->map; |
| 100 |
tmp->x = op->x; |
| 101 |
tmp->y = op->y; |
| 102 |
} |
| 103 |
tmp = object_insert_in_map_at(tmp, op->map, op, 0, tmp->x, tmp->y); |
| 104 |
if (tmp != NULL) |
| 105 |
ob_process(tmp); |
| 106 |
return 1; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
void explode_bullet(object *op) { |
| 122 |
tag_t op_tag = op->count; |
| 123 |
object *tmp, *owner; |
| 124 |
|
| 125 |
if (op->other_arch == NULL) { |
| 126 |
LOG(llevError, "BUG: explode_bullet(): op without other_arch\n"); |
| 127 |
object_remove(op); |
| 128 |
object_free_drop_inventory(op); |
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
if (op->env) { |
| 133 |
object *env; |
| 134 |
|
| 135 |
env = object_get_env_recursive(op); |
| 136 |
if (env->map == NULL || out_of_map(env->map, env->x, env->y)) { |
| 137 |
LOG(llevError, "BUG: explode_bullet(): env out of map\n"); |
| 138 |
object_remove(op); |
| 139 |
object_free_drop_inventory(op); |
| 140 |
return; |
| 141 |
} |
| 142 |
object_remove(op); |
| 143 |
object_insert_in_map_at(op, env->map, op, INS_NO_MERGE|INS_NO_WALK_ON, env->x, env->y); |
| 144 |
} else if (out_of_map(op->map, op->x, op->y)) { |
| 145 |
LOG(llevError, "BUG: explode_bullet(): op out of map\n"); |
| 146 |
object_remove(op); |
| 147 |
object_free_drop_inventory(op); |
| 148 |
return; |
| 149 |
} |
| 150 |
|
| 151 |
if (op->attacktype) { |
| 152 |
hit_map(op, 0, op->attacktype, 1); |
| 153 |
if (object_was_destroyed(op, op_tag)) |
| 154 |
return; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
tmp = arch_to_object(op->other_arch); |
| 159 |
|
| 160 |
object_copy_owner(tmp, op); |
| 161 |
if (tmp->skill) |
| 162 |
FREE_AND_CLEAR_STR(tmp->skill); |
| 163 |
if (op->skill) |
| 164 |
tmp->skill = add_refcount(op->skill); |
| 165 |
|
| 166 |
owner = object_get_owner(op); |
| 167 |
if ((tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) && owner && !tailor_god_spell(tmp, owner)) { |
| 168 |
object_remove(op); |
| 169 |
object_free_drop_inventory(op); |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
if (op->type == SPELL_EFFECT && op->subtype == SP_BOMB) { |
| 175 |
tmp->attacktype = op->attacktype; |
| 176 |
tmp->range = op->range; |
| 177 |
tmp->stats.dam = op->stats.dam; |
| 178 |
tmp->duration = op->duration; |
| 179 |
} else { |
| 180 |
if (op->attacktype&AT_MAGIC) |
| 181 |
tmp->attacktype |= AT_MAGIC; |
| 182 |
|
| 183 |
tmp->stats.dam = op->dam_modifier; |
| 184 |
tmp->range = op->stats.maxhp; |
| 185 |
tmp->duration = op->stats.hp; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
tmp->stats.maxhp = op->count; |
| 192 |
if (tmp->stats.maxhp == 0) |
| 193 |
tmp->stats.maxhp = 1; |
| 194 |
|
| 195 |
|
| 196 |
if (tmp->type == SPELL_EFFECT && tmp->subtype == SP_CONE) |
| 197 |
tmp->stats.sp = op->direction; |
| 198 |
|
| 199 |
|
| 200 |
op->move_on = 0; |
| 201 |
|
| 202 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y); |
| 203 |
|
| 204 |
if (!object_was_destroyed(op, op_tag)) { |
| 205 |
object_remove(op); |
| 206 |
object_free_drop_inventory(op); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
void check_bullet(object *op) { |
| 218 |
tag_t op_tag = op->count, tmp_tag; |
| 219 |
int dam, mflags; |
| 220 |
mapstruct *m; |
| 221 |
int16_t sx, sy; |
| 222 |
|
| 223 |
mflags = get_map_flags(op->map, &m, op->x, op->y, &sx, &sy); |
| 224 |
|
| 225 |
if (!(mflags&P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) |
| 226 |
return; |
| 227 |
|
| 228 |
if (op->other_arch) { |
| 229 |
|
| 230 |
explode_bullet(op); |
| 231 |
return; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
if (!(mflags&P_IS_ALIVE)) |
| 236 |
return; |
| 237 |
|
| 238 |
FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) { |
| 239 |
if (QUERY_FLAG(tmp, FLAG_ALIVE)) { |
| 240 |
tmp_tag = tmp->count; |
| 241 |
dam = hit_player(tmp, op->stats.dam, op, op->attacktype, 1); |
| 242 |
if (object_was_destroyed(op, op_tag) || !object_was_destroyed(tmp, tmp_tag) || (op->stats.dam -= dam) < 0) { |
| 243 |
if (!QUERY_FLAG(op, FLAG_REMOVED)) { |
| 244 |
object_remove(op); |
| 245 |
object_free_drop_inventory(op); |
| 246 |
return; |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
} FOR_MAP_FINISH(); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
void cone_drop(object *op) { |
| 266 |
object *new_ob = arch_to_object(op->other_arch); |
| 267 |
|
| 268 |
new_ob->level = op->level; |
| 269 |
object_set_owner(new_ob, object_get_owner(op)); |
| 270 |
|
| 271 |
|
| 272 |
if (op->skill && op->skill != new_ob->skill) { |
| 273 |
if (new_ob->skill) |
| 274 |
free_string(new_ob->skill); |
| 275 |
new_ob->skill = add_refcount(op->skill); |
| 276 |
} |
| 277 |
object_insert_in_map_at(new_ob, op->map, op, 0, op->x, op->y); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
int cast_cone(object *op, object *caster, int dir, object *spell) { |
| 298 |
object *tmp; |
| 299 |
int i, success = 0, range_min = -1, range_max = 1; |
| 300 |
mapstruct *m; |
| 301 |
int16_t sx, sy; |
| 302 |
MoveType movetype; |
| 303 |
|
| 304 |
if (!spell->other_arch) |
| 305 |
return 0; |
| 306 |
|
| 307 |
if (op->type == PLAYER && QUERY_FLAG(op, FLAG_UNDEAD) && op->attacktype&AT_TURN_UNDEAD) { |
| 308 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, "Your undead nature prevents you from turning undead!"); |
| 309 |
return 0; |
| 310 |
} |
| 311 |
|
| 312 |
if (!dir) { |
| 313 |
range_min = 0; |
| 314 |
range_max = 8; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
movetype = spell->other_arch->clone.move_type; |
| 322 |
|
| 323 |
for (i = range_min; i <= range_max; i++) { |
| 324 |
int16_t x, y, d; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
d = dir+i; |
| 332 |
while (d < 0) |
| 333 |
d += 8; |
| 334 |
while (d > 8) |
| 335 |
d -= 8; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
if (caster->type != RUNE && d == 0) { |
| 345 |
if (dir != 0) |
| 346 |
d = 8; |
| 347 |
else |
| 348 |
continue; |
| 349 |
} |
| 350 |
|
| 351 |
x = op->x+freearr_x[d]; |
| 352 |
y = op->y+freearr_y[d]; |
| 353 |
|
| 354 |
if (get_map_flags(op->map, &m, x, y, &sx, &sy)&P_OUT_OF_MAP) |
| 355 |
continue; |
| 356 |
|
| 357 |
if ((movetype&GET_MAP_MOVE_BLOCK(m, sx, sy)) == movetype) |
| 358 |
continue; |
| 359 |
|
| 360 |
success = 1; |
| 361 |
tmp = arch_to_object(spell->other_arch); |
| 362 |
object_set_owner(tmp, op); |
| 363 |
set_spell_skill(op, caster, spell, tmp); |
| 364 |
tmp->level = caster_level(caster, spell); |
| 365 |
tmp->attacktype = spell->attacktype; |
| 366 |
|
| 367 |
|
| 368 |
if ((tmp->attacktype&AT_HOLYWORD) || (tmp->attacktype&AT_GODPOWER)) { |
| 369 |
if (!tailor_god_spell(tmp, op)) |
| 370 |
return 0; |
| 371 |
} |
| 372 |
|
| 373 |
if (dir) |
| 374 |
tmp->stats.sp = dir; |
| 375 |
else |
| 376 |
tmp->stats.sp = i; |
| 377 |
|
| 378 |
tmp->range = spell->range+SP_level_range_adjust(caster, spell); |
| 379 |
|
| 380 |
|
| 381 |
if (dir == 0) { |
| 382 |
tmp->range /= 4; |
| 383 |
if (tmp->range < 2 && spell->range >= 2) |
| 384 |
tmp->range = 2; |
| 385 |
} |
| 386 |
tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 387 |
tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell); |
| 388 |
|
| 389 |
|
| 390 |
if (tmp->attacktype&AT_FEAR) { |
| 391 |
if (caster->type == PLAYER) |
| 392 |
tmp->duration += get_fear_bonus(caster->stats.Cha); |
| 393 |
else |
| 394 |
tmp->duration += caster->level/3; |
| 395 |
} |
| 396 |
if (tmp->attacktype&(AT_HOLYWORD|AT_TURN_UNDEAD)) { |
| 397 |
if (caster->type == PLAYER) |
| 398 |
tmp->duration += get_turn_bonus(caster->stats.Wis)/5; |
| 399 |
else |
| 400 |
tmp->duration += caster->level/3; |
| 401 |
} |
| 402 |
|
| 403 |
if (!(tmp->move_type&MOVE_FLY_LOW)) |
| 404 |
LOG(llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", spell->other_arch->name); |
| 405 |
|
| 406 |
if (!tmp->move_on && tmp->stats.dam) { |
| 407 |
LOG(llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", spell->other_arch->name); |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
tmp->stats.maxhp = tmp->count; |
| 414 |
if (tmp->stats.maxhp == 0) |
| 415 |
tmp->stats.maxhp = 1; |
| 416 |
|
| 417 |
object_insert_in_map_at(tmp, m, op, 0, sx, sy); |
| 418 |
|
| 419 |
if (tmp->other_arch) |
| 420 |
cone_drop(tmp); |
| 421 |
} |
| 422 |
return success; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
int create_bomb(object *op, object *caster, int dir, object *spell) { |
| 448 |
object *tmp; |
| 449 |
int mflags; |
| 450 |
int16_t dx = op->x+freearr_x[dir], dy = op->y+freearr_y[dir]; |
| 451 |
mapstruct *m; |
| 452 |
|
| 453 |
mflags = get_map_flags(op->map, &m, dx, dy, &dx, &dy); |
| 454 |
if ((mflags&P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK(m, dx, dy)&MOVE_WALK)) { |
| 455 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, "There is something in the way."); |
| 456 |
return 0; |
| 457 |
} |
| 458 |
tmp = arch_to_object(spell->other_arch); |
| 459 |
|
| 460 |
|
| 461 |
tmp->range = spell->range+SP_level_range_adjust(caster, spell); |
| 462 |
tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 463 |
tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell); |
| 464 |
tmp->attacktype = spell->attacktype; |
| 465 |
|
| 466 |
object_set_owner(tmp, op); |
| 467 |
set_spell_skill(op, caster, spell, tmp); |
| 468 |
object_insert_in_map_at(tmp, m, op, 0, dx, dy); |
| 469 |
return 1; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
static object *get_pointed_target(object *op, int dir, int range, int type) { |
| 497 |
object *target; |
| 498 |
int16_t x, y; |
| 499 |
int dist, mflags; |
| 500 |
mapstruct *mp; |
| 501 |
|
| 502 |
if (dir == 0) |
| 503 |
return NULL; |
| 504 |
|
| 505 |
for (dist = 1; dist < range; dist++) { |
| 506 |
x = op->x+freearr_x[dir]*dist; |
| 507 |
y = op->y+freearr_y[dir]*dist; |
| 508 |
mp = op->map; |
| 509 |
mflags = get_map_flags(op->map, &mp, x, y, &x, &y); |
| 510 |
|
| 511 |
if (mflags&P_OUT_OF_MAP) |
| 512 |
return NULL; |
| 513 |
if ((type&SPELL_MANA) && (mflags&P_NO_MAGIC)) |
| 514 |
return NULL; |
| 515 |
if ((type&SPELL_GRACE) && (mflags&P_NO_CLERIC)) |
| 516 |
return NULL; |
| 517 |
if (GET_MAP_MOVE_BLOCK(mp, x, y)&MOVE_FLY_LOW) |
| 518 |
return NULL; |
| 519 |
|
| 520 |
if (mflags&P_IS_ALIVE) { |
| 521 |
target = map_find_by_flag(mp, x, y, FLAG_MONSTER); |
| 522 |
if (target != NULL) { |
| 523 |
return target; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
return NULL; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
int cast_smite_spell(object *op, object *caster, int dir, object *spell) { |
| 547 |
object *effect, *target; |
| 548 |
const object *god = find_god(determine_god(op)); |
| 549 |
int range; |
| 550 |
|
| 551 |
range = spell->range+SP_level_range_adjust(caster, spell); |
| 552 |
target = get_pointed_target(op, dir, range, spell->stats.grace ? SPELL_GRACE : SPELL_MANA); |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
if (!target |
| 564 |
|| QUERY_FLAG(target, FLAG_REFL_SPELL) |
| 565 |
|| (!god && spell->stats.grace) |
| 566 |
|| (target->title && god && !strcmp(target->title, god->name)) |
| 567 |
|| (target->race && god && strstr(target->race, god->race))) { |
| 568 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Your request is unheeded."); |
| 569 |
return 0; |
| 570 |
} |
| 571 |
|
| 572 |
if (spell->other_arch) |
| 573 |
effect = arch_to_object(spell->other_arch); |
| 574 |
else |
| 575 |
return 0; |
| 576 |
|
| 577 |
|
| 578 |
effect->level = caster_level(caster, spell); |
| 579 |
effect->attacktype = spell->attacktype; |
| 580 |
if (effect->attacktype&(AT_HOLYWORD|AT_GODPOWER)) { |
| 581 |
if (tailor_god_spell(effect, op)) |
| 582 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 583 |
"%s answers your call!", |
| 584 |
determine_god(op)); |
| 585 |
else { |
| 586 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Your request is ignored."); |
| 587 |
return 0; |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
effect->range = spell->range+SP_level_range_adjust(caster, spell); |
| 593 |
effect->duration = spell->duration+SP_level_range_adjust(caster, spell); |
| 594 |
|
| 595 |
if (effect->attacktype&AT_DEATH) { |
| 596 |
effect->level = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 597 |
|
| 598 |
|
| 599 |
if (QUERY_FLAG(target, FLAG_UNDEAD)) { |
| 600 |
if (random_roll(0, 2, op, PREFER_LOW)) { |
| 601 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Idiot! Your spell boomerangs!"); |
| 602 |
effect->x = op->x; |
| 603 |
effect->y = op->y; |
| 604 |
} else { |
| 605 |
char target_name[HUGE_BUF]; |
| 606 |
|
| 607 |
query_name(target, target_name, HUGE_BUF); |
| 608 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 609 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 610 |
"The %s looks stronger!", |
| 611 |
target_name); |
| 612 |
target->stats.hp = target->stats.maxhp*2; |
| 613 |
object_free_drop_inventory(effect); |
| 614 |
return 0; |
| 615 |
} |
| 616 |
} |
| 617 |
} else { |
| 618 |
|
| 619 |
effect->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 620 |
} |
| 621 |
|
| 622 |
if (effect->type == SPELL_EFFECT && effect->subtype == SP_EXPLOSION) { |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
effect->stats.maxhp = spell->count; |
| 630 |
if (effect->stats.maxhp == 0) |
| 631 |
effect->stats.maxhp = 1; |
| 632 |
} |
| 633 |
|
| 634 |
object_set_owner(effect, op); |
| 635 |
set_spell_skill(op, caster, spell, effect); |
| 636 |
|
| 637 |
|
| 638 |
object_insert_in_map_at(effect, target->map, op, 0, target->x, target->y); |
| 639 |
|
| 640 |
return 1; |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
static int make_object_glow(object *op, int radius, int time) { |
| 666 |
object *tmp; |
| 667 |
|
| 668 |
|
| 669 |
if (op->path_denied&PATH_LIGHT) |
| 670 |
return 0; |
| 671 |
|
| 672 |
tmp = create_archetype(FORCE_NAME); |
| 673 |
tmp->speed = 0.01; |
| 674 |
tmp->stats.food = time; |
| 675 |
SET_FLAG(tmp, FLAG_IS_USED_UP); |
| 676 |
tmp->glow_radius = radius; |
| 677 |
if (tmp->glow_radius > MAX_LIGHT_RADII) |
| 678 |
tmp->glow_radius = MAX_LIGHT_RADII; |
| 679 |
|
| 680 |
tmp->x = op->x; |
| 681 |
tmp->y = op->y; |
| 682 |
if (tmp->speed < MIN_ACTIVE_SPEED) |
| 683 |
tmp->speed = MIN_ACTIVE_SPEED; |
| 684 |
tmp = object_insert_in_ob(tmp, op); |
| 685 |
if (tmp->glow_radius > op->glow_radius) |
| 686 |
op->glow_radius = tmp->glow_radius; |
| 687 |
|
| 688 |
if (!tmp->env || op != tmp->env) { |
| 689 |
LOG(llevError, "make_object_glow() failed to insert glowing force in %s\n", op->name); |
| 690 |
return 0; |
| 691 |
} |
| 692 |
return 1; |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
int cast_destruction(object *op, object *caster, object *spell_ob) { |
| 708 |
int i, j, range, mflags, friendly = 0, dam, dur; |
| 709 |
int16_t sx, sy; |
| 710 |
mapstruct *m; |
| 711 |
object *tmp, *found_skill; |
| 712 |
const char *skill; |
| 713 |
|
| 714 |
range = spell_ob->range+SP_level_range_adjust(caster, spell_ob); |
| 715 |
dam = spell_ob->stats.dam+SP_level_dam_adjust(caster, spell_ob); |
| 716 |
dur = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob); |
| 717 |
if (QUERY_FLAG(op, FLAG_FRIENDLY) || op->type == PLAYER) |
| 718 |
friendly = 1; |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
skill = op->skill; |
| 727 |
if (caster == op) |
| 728 |
op->skill = spell_ob->skill; |
| 729 |
else if (caster->skill) |
| 730 |
op->skill = caster->skill; |
| 731 |
else |
| 732 |
op->skill = NULL; |
| 733 |
|
| 734 |
|
| 735 |
found_skill = find_skill_by_name(op, op->skill); |
| 736 |
change_skill(op, found_skill, 1); |
| 737 |
|
| 738 |
for (i = -range; i < range; i++) { |
| 739 |
for (j = -range; j < range; j++) { |
| 740 |
m = op->map; |
| 741 |
sx = op->x+i; |
| 742 |
sy = op->y+j; |
| 743 |
mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); |
| 744 |
if (mflags&P_OUT_OF_MAP) |
| 745 |
continue; |
| 746 |
if (mflags&P_IS_ALIVE) { |
| 747 |
tmp = NULL; |
| 748 |
FOR_MAP_PREPARE(m, sx, sy, inv) { |
| 749 |
tmp = inv; |
| 750 |
if (QUERY_FLAG(tmp, FLAG_ALIVE) || tmp->type == PLAYER) |
| 751 |
break; |
| 752 |
} FOR_MAP_FINISH(); |
| 753 |
if (tmp) { |
| 754 |
tmp = HEAD(tmp); |
| 755 |
if ((friendly && !QUERY_FLAG(tmp, FLAG_FRIENDLY) && tmp->type != PLAYER) |
| 756 |
|| (!friendly && (QUERY_FLAG(tmp, FLAG_FRIENDLY) || tmp->type == PLAYER))) { |
| 757 |
if (spell_ob->subtype == SP_DESTRUCTION) { |
| 758 |
hit_player(tmp, dam, op, spell_ob->attacktype, 0); |
| 759 |
if (spell_ob->other_arch) { |
| 760 |
tmp = arch_to_object(spell_ob->other_arch); |
| 761 |
object_insert_in_map_at(tmp, m, op, 0, sx, sy); |
| 762 |
} |
| 763 |
} else if (spell_ob->subtype == SP_FAERY_FIRE && tmp->resist[ATNR_MAGIC] != 100) { |
| 764 |
if (make_object_glow(tmp, 1, dur) && spell_ob->other_arch) { |
| 765 |
object *effect = arch_to_object(spell_ob->other_arch); |
| 766 |
object_insert_in_map_at(effect, m, op, 0, sx, sy); |
| 767 |
} |
| 768 |
} |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
op->skill = skill; |
| 775 |
return 1; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
int cast_curse(object *op, object *caster, object *spell_ob, int dir) { |
| 801 |
const object *god = find_god(determine_god(op)); |
| 802 |
object *tmp, *force; |
| 803 |
|
| 804 |
tmp = get_pointed_target(op, (dir == 0) ? op->direction : dir, spell_ob->range, SPELL_GRACE); |
| 805 |
if (!tmp) { |
| 806 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "There is no one in that direction to curse."); |
| 807 |
return 0; |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
force = NULL; |
| 812 |
FOR_INV_PREPARE(tmp, inv) { |
| 813 |
if (inv->type == FORCE && inv->subtype == FORCE_CHANGE_ABILITY) { |
| 814 |
if (inv->name == spell_ob->name) { |
| 815 |
force = inv; |
| 816 |
break; |
| 817 |
} else if (spell_ob->race && spell_ob->race == inv->name) { |
| 818 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 819 |
MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, |
| 820 |
"You can not cast %s while %s is in effect", |
| 821 |
spell_ob->name, force->name_pl); |
| 822 |
return 0; |
| 823 |
} |
| 824 |
} |
| 825 |
} FOR_INV_FINISH(); |
| 826 |
|
| 827 |
if (force == NULL) { |
| 828 |
force = create_archetype(FORCE_NAME); |
| 829 |
force->subtype = FORCE_CHANGE_ABILITY; |
| 830 |
free_string(force->name); |
| 831 |
if (spell_ob->race) |
| 832 |
force->name = add_refcount(spell_ob->race); |
| 833 |
else |
| 834 |
force->name = add_refcount(spell_ob->name); |
| 835 |
free_string(force->name_pl); |
| 836 |
force->name_pl = add_refcount(spell_ob->name); |
| 837 |
} else { |
| 838 |
int duration; |
| 839 |
|
| 840 |
duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 841 |
if (duration > force->duration) { |
| 842 |
force->duration = duration; |
| 843 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, "You recast the spell while in effect."); |
| 844 |
} else { |
| 845 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Recasting the spell had no effect."); |
| 846 |
} |
| 847 |
return 1; |
| 848 |
} |
| 849 |
force->duration = spell_ob->duration+SP_level_duration_adjust(caster, spell_ob)*50; |
| 850 |
force->speed = 1.0; |
| 851 |
force->speed_left = -1.0; |
| 852 |
SET_FLAG(force, FLAG_APPLIED); |
| 853 |
|
| 854 |
if (god) { |
| 855 |
if (spell_ob->last_grace) |
| 856 |
force->path_repelled = god->path_repelled; |
| 857 |
if (spell_ob->last_grace) |
| 858 |
force->path_denied = god->path_denied; |
| 859 |
draw_ext_info_format(NDI_UNIQUE, 0, tmp, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SPELL, |
| 860 |
"You are a victim of %s's curse!", |
| 861 |
god->name); |
| 862 |
} else |
| 863 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Your curse seems empty."); |
| 864 |
|
| 865 |
|
| 866 |
if (tmp != op && op->type == PLAYER) |
| 867 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, |
| 868 |
"You curse %s!", |
| 869 |
tmp->name); |
| 870 |
|
| 871 |
force->stats.ac = spell_ob->stats.ac; |
| 872 |
force->stats.wc = spell_ob->stats.wc; |
| 873 |
|
| 874 |
change_abil(tmp, force); |
| 875 |
object_insert_in_ob(force, tmp); |
| 876 |
fix_object(tmp); |
| 877 |
|
| 878 |
if (spell_ob->other_arch != NULL && tmp->map != NULL) { |
| 879 |
object_insert_in_map_at(arch_to_object(spell_ob->other_arch), tmp->map, NULL, INS_ON_TOP, tmp->x, tmp->y); |
| 880 |
} |
| 881 |
|
| 882 |
return 1; |
| 883 |
} |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
int mood_change(object *op, object *caster, object *spell) { |
| 905 |
object *tmp, *head; |
| 906 |
const object *god; |
| 907 |
int done_one, range, mflags, level, at, best_at, immunity_chance = 50; |
| 908 |
int16_t x, y, nx, ny; |
| 909 |
mapstruct *m; |
| 910 |
const char *race; |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
god = find_god(determine_god(op)); |
| 916 |
level = caster_level(caster, spell); |
| 917 |
range = spell->range+SP_level_range_adjust(caster, spell); |
| 918 |
race = object_get_value(spell, "immunity_chance"); |
| 919 |
if (race != NULL) { |
| 920 |
immunity_chance = atoi(race); |
| 921 |
if (immunity_chance < 0 || immunity_chance > 100) { |
| 922 |
LOG(llevError, "ignoring invalid immunity_chance %d for %s\n", immunity_chance, spell->arch->name); |
| 923 |
immunity_chance = 50; |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
if (!spell->race) |
| 932 |
race = NULL; |
| 933 |
else if (god && !strcmp(spell->race, "GOD_SLAYING")) |
| 934 |
race = god->slaying; |
| 935 |
else if (god && !strcmp(spell->race, "GOD_FRIEND")) |
| 936 |
race = god->race; |
| 937 |
else |
| 938 |
race = spell->race; |
| 939 |
|
| 940 |
for (x = op->x-range; x <= op->x+range; x++) |
| 941 |
for (y = op->y-range; y <= op->y+range; y++) { |
| 942 |
done_one = 0; |
| 943 |
m = op->map; |
| 944 |
mflags = get_map_flags(m, &m, x, y, &nx, &ny); |
| 945 |
if (mflags&P_OUT_OF_MAP) |
| 946 |
continue; |
| 947 |
|
| 948 |
|
| 949 |
if (!(mflags&P_IS_ALIVE)) |
| 950 |
continue; |
| 951 |
|
| 952 |
head = map_find_by_flag(m, nx, ny, FLAG_MONSTER); |
| 953 |
|
| 954 |
if (!head || head->type == PLAYER) |
| 955 |
continue; |
| 956 |
|
| 957 |
|
| 958 |
if (race && head->race && !strstr(race, head->race)) |
| 959 |
continue; |
| 960 |
if (QUERY_FLAG(head, FLAG_UNDEAD) && !QUERY_FLAG(spell, FLAG_UNDEAD)) |
| 961 |
continue; |
| 962 |
|
| 963 |
|
| 964 |
best_at = -1; |
| 965 |
if (spell->attacktype) { |
| 966 |
for (at = 0; at < NROFATTACKS; at++) |
| 967 |
if (spell->attacktype&(1<<at)) |
| 968 |
if (best_at == -1 || head->resist[at] > head->resist[best_at]) |
| 969 |
best_at = at; |
| 970 |
|
| 971 |
if (best_at == -1) |
| 972 |
at = 0; |
| 973 |
else { |
| 974 |
if (head->resist[best_at] == 100) |
| 975 |
continue; |
| 976 |
else |
| 977 |
at = head->resist[best_at]/5; |
| 978 |
} |
| 979 |
at -= level/5; |
| 980 |
if (did_make_save(head, head->level, at)) |
| 981 |
continue; |
| 982 |
} else { |
| 983 |
const char *value; |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
if (head->level > level) |
| 998 |
continue; |
| 999 |
if (random_roll(0, 100, caster, PREFER_LOW) >= (20+MIN(50, 2*(level-head->level)))) { |
| 1000 |
|
| 1001 |
if (random_roll(0, 100, caster, PREFER_HIGH) <= immunity_chance) { |
| 1002 |
object_set_value(head, "no_mood_change", "1", 1); |
| 1003 |
} |
| 1004 |
continue; |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
value = object_get_value(head, "no_mood_change"); |
| 1012 |
if (value && strcmp(value, "1") == 0) |
| 1013 |
continue; |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
if (QUERY_FLAG(spell, FLAG_MONSTER)) { |
| 1020 |
CLEAR_FLAG(head, FLAG_SLEEP); |
| 1021 |
|
| 1022 |
CLEAR_FLAG(head, FLAG_UNAGGRESSIVE); |
| 1023 |
if (QUERY_FLAG(head, FLAG_FRIENDLY)) |
| 1024 |
remove_friendly_object(head); |
| 1025 |
|
| 1026 |
done_one = 1; |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
object_set_value(head, "no_mood_change", "1", 1); |
| 1031 |
|
| 1032 |
object_set_enemy(head, op); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
if (QUERY_FLAG(spell, FLAG_UNAGGRESSIVE) && !QUERY_FLAG(head, FLAG_UNAGGRESSIVE)) { |
| 1037 |
SET_FLAG(head, FLAG_UNAGGRESSIVE); |
| 1038 |
object_set_enemy(head, NULL); |
| 1039 |
done_one = 1; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
if (QUERY_FLAG(spell, FLAG_BERSERK) && !QUERY_FLAG(head, FLAG_BERSERK)) { |
| 1044 |
SET_FLAG(head, FLAG_BERSERK); |
| 1045 |
done_one = 1; |
| 1046 |
} |
| 1047 |
|
| 1048 |
if (QUERY_FLAG(spell, FLAG_NO_ATTACK) && !QUERY_FLAG(head, FLAG_FRIENDLY)) { |
| 1049 |
SET_FLAG(head, FLAG_FRIENDLY); |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
CLEAR_FLAG(head, FLAG_GENERATOR); |
| 1054 |
object_set_owner(head, op); |
| 1055 |
set_spell_skill(op, caster, spell, head); |
| 1056 |
add_friendly_object(head); |
| 1057 |
head->attack_movement = PETMOVE; |
| 1058 |
done_one = 1; |
| 1059 |
share_exp(op, head->stats.exp/2, head->skill, SK_EXP_ADD_SKILL); |
| 1060 |
head->stats.exp = 0; |
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
if (done_one && spell->other_arch) { |
| 1065 |
tmp = arch_to_object(spell->other_arch); |
| 1066 |
object_insert_in_map_at(tmp, m, op, 0, nx, ny); |
| 1067 |
} |
| 1068 |
} |
| 1069 |
|
| 1070 |
return 1; |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
int fire_swarm(object *op, object *caster, object *spell, int dir) { |
| 1092 |
object *tmp; |
| 1093 |
int i; |
| 1094 |
|
| 1095 |
if (!spell->other_arch) |
| 1096 |
return 0; |
| 1097 |
|
| 1098 |
tmp = create_archetype(SWARM_SPELL); |
| 1099 |
object_set_owner(tmp, op); |
| 1100 |
set_spell_skill(op, caster, spell, tmp); |
| 1101 |
|
| 1102 |
tmp->level = caster_level(caster, spell); |
| 1103 |
tmp->spell = arch_to_object(spell->other_arch); |
| 1104 |
|
| 1105 |
tmp->attacktype = tmp->spell->attacktype; |
| 1106 |
|
| 1107 |
if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) { |
| 1108 |
if (!tailor_god_spell(tmp, op)) |
| 1109 |
return 1; |
| 1110 |
} |
| 1111 |
tmp->duration = SP_level_duration_adjust(caster, spell); |
| 1112 |
for (i = 0; i < spell->duration; i++) |
| 1113 |
tmp->duration += die_roll(1, 3, op, PREFER_HIGH); |
| 1114 |
|
| 1115 |
tmp->direction = dir; |
| 1116 |
tmp->invisible = 1; |
| 1117 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y); |
| 1118 |
return 1; |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
int cast_light(object *op, object *caster, object *spell, int dir) { |
| 1140 |
object *target = NULL, *tmp = NULL; |
| 1141 |
int16_t x, y; |
| 1142 |
int dam, mflags; |
| 1143 |
mapstruct *m; |
| 1144 |
|
| 1145 |
dam = spell->stats.dam+SP_level_dam_adjust(caster, spell); |
| 1146 |
|
| 1147 |
if (!dir) { |
| 1148 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, "In what direction?"); |
| 1149 |
return 0; |
| 1150 |
} |
| 1151 |
|
| 1152 |
x = op->x+freearr_x[dir]; |
| 1153 |
y = op->y+freearr_y[dir]; |
| 1154 |
m = op->map; |
| 1155 |
|
| 1156 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 1157 |
|
| 1158 |
if (mflags&P_OUT_OF_MAP) { |
| 1159 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "Nothing is there."); |
| 1160 |
return 0; |
| 1161 |
} |
| 1162 |
|
| 1163 |
if (mflags&P_IS_ALIVE && spell->attacktype) { |
| 1164 |
target = map_find_by_flag(m, x, y, FLAG_MONSTER); |
| 1165 |
if (target != NULL) { |
| 1166 |
|
| 1167 |
(void)hit_player(target, dam, op, spell->attacktype, 1); |
| 1168 |
return 1; |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y))) { |
| 1174 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, "Something is in the way."); |
| 1175 |
return 0; |
| 1176 |
} |
| 1177 |
|
| 1178 |
|
| 1179 |
tmp = arch_to_object(spell->other_arch); |
| 1180 |
if (!tmp) { |
| 1181 |
LOG(llevError, "Error: spell arch for cast_light() missing.\n"); |
| 1182 |
return 0; |
| 1183 |
} |
| 1184 |
tmp->stats.food = spell->duration+SP_level_duration_adjust(caster, spell); |
| 1185 |
if (tmp->glow_radius) { |
| 1186 |
tmp->glow_radius = spell->range+SP_level_range_adjust(caster, spell); |
| 1187 |
if (tmp->glow_radius > MAX_LIGHT_RADII) |
| 1188 |
tmp->glow_radius = MAX_LIGHT_RADII; |
| 1189 |
} |
| 1190 |
object_insert_in_map_at(tmp, m, op, 0, x, y); |
| 1191 |
return 1; |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
int cast_cause_disease(object *op, object *caster, object *spell, int dir) { |
| 1211 |
int16_t x, y; |
| 1212 |
int i, mflags, range, dam_mod, dur_mod; |
| 1213 |
object *target_head; |
| 1214 |
mapstruct *m; |
| 1215 |
|
| 1216 |
x = op->x; |
| 1217 |
y = op->y; |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
if (!dir) |
| 1223 |
dir = op->facing; |
| 1224 |
if (!dir) |
| 1225 |
return 0; |
| 1226 |
|
| 1227 |
|
| 1228 |
range = spell->range+SP_level_range_adjust(caster, spell); |
| 1229 |
dam_mod = SP_level_dam_adjust(caster, spell); |
| 1230 |
dur_mod = SP_level_duration_adjust(caster, spell); |
| 1231 |
|
| 1232 |
|
| 1233 |
for (i = 1; i < range; i++) { |
| 1234 |
x = op->x+i*freearr_x[dir]; |
| 1235 |
y = op->y+i*freearr_y[dir]; |
| 1236 |
m = op->map; |
| 1237 |
|
| 1238 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 1239 |
|
| 1240 |
if (mflags&P_OUT_OF_MAP) |
| 1241 |
return 0; |
| 1242 |
|
| 1243 |
|
| 1244 |
if (GET_MAP_MOVE_BLOCK(m, x, y)&MOVE_FLY_LOW) |
| 1245 |
return 0; |
| 1246 |
|
| 1247 |
|
| 1248 |
if (mflags&P_IS_ALIVE) { |
| 1249 |
|
| 1250 |
FOR_MAP_PREPARE(m, x, y, walk) { |
| 1251 |
|
| 1252 |
target_head = HEAD(walk); |
| 1253 |
if (QUERY_FLAG(target_head, FLAG_MONSTER) || (target_head->type == PLAYER)) { |
| 1254 |
object *disease = arch_to_object(spell->other_arch); |
| 1255 |
|
| 1256 |
object_set_owner(disease, op); |
| 1257 |
set_spell_skill(op, caster, spell, disease); |
| 1258 |
disease->stats.exp = 0; |
| 1259 |
disease->level = caster_level(caster, spell); |
| 1260 |
|
| 1261 |
|
| 1262 |
if (disease->stats.wc) |
| 1263 |
disease->stats.wc += dur_mod/2; |
| 1264 |
|
| 1265 |
if (disease->magic > 0) |
| 1266 |
disease->magic += dur_mod/4; |
| 1267 |
|
| 1268 |
if (disease->stats.maxhp > 0) |
| 1269 |
disease->stats.maxhp += dur_mod; |
| 1270 |
|
| 1271 |
if (disease->stats.maxgrace > 0) |
| 1272 |
disease->stats.maxgrace += dur_mod; |
| 1273 |
|
| 1274 |
if (disease->stats.dam) { |
| 1275 |
if (disease->stats.dam > 0) |
| 1276 |
disease->stats.dam += dam_mod; |
| 1277 |
else |
| 1278 |
disease->stats.dam -= dam_mod; |
| 1279 |
} |
| 1280 |
|
| 1281 |
if (disease->last_sp) { |
| 1282 |
disease->last_sp -= 2*dam_mod; |
| 1283 |
if (disease->last_sp < 1) |
| 1284 |
disease->last_sp = 1; |
| 1285 |
} |
| 1286 |
|
| 1287 |
if (disease->stats.maxsp) { |
| 1288 |
if (disease->stats.maxsp > 0) |
| 1289 |
disease->stats.maxsp += dam_mod; |
| 1290 |
else |
| 1291 |
disease->stats.maxsp -= dam_mod; |
| 1292 |
} |
| 1293 |
|
| 1294 |
if (disease->stats.ac) |
| 1295 |
disease->stats.ac += dam_mod; |
| 1296 |
|
| 1297 |
if (disease->last_eat) |
| 1298 |
disease->last_eat -= dam_mod; |
| 1299 |
|
| 1300 |
if (disease->stats.hp) |
| 1301 |
disease->stats.hp -= dam_mod; |
| 1302 |
|
| 1303 |
if (disease->stats.sp) |
| 1304 |
disease->stats.sp -= dam_mod; |
| 1305 |
|
| 1306 |
if (infect_object(target_head, disease, 1)) { |
| 1307 |
object *flash; |
| 1308 |
|
| 1309 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_SUCCESS, "You inflict %s on %s!", disease->name, target_head->name); |
| 1310 |
|
| 1311 |
object_free_drop_inventory(disease); |
| 1312 |
flash = create_archetype(ARCH_DETECT_MAGIC); |
| 1313 |
object_insert_in_map_at(flash, walk->map, op, 0, x, y); |
| 1314 |
return 1; |
| 1315 |
} |
| 1316 |
object_free_drop_inventory(disease); |
| 1317 |
} |
| 1318 |
} FOR_MAP_FINISH(); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, "No one caught anything!"); |
| 1322 |
return 1; |
| 1323 |
} |