| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include <global.h> |
| 29 |
#include <ob_methods.h> |
| 30 |
#include <ob_types.h> |
| 31 |
#include <sounds.h> |
| 32 |
#include <sproto.h> |
| 33 |
|
| 34 |
static method_ret spell_effect_type_move_on(ob_methods *context, object *trap, object *victim, object *originator); |
| 35 |
static method_ret spell_effect_type_process(ob_methods *context, object *op); |
| 36 |
|
| 37 |
static void move_bolt(object *op); |
| 38 |
static void move_bullet(object *op); |
| 39 |
static void explosion(object *op); |
| 40 |
static void move_cone(object *op); |
| 41 |
static void animate_bomb(object *op); |
| 42 |
static void move_missile(object *op); |
| 43 |
static void execute_word_of_recall(object *op); |
| 44 |
static void move_ball_spell(object *op); |
| 45 |
static void move_swarm_spell(object *op); |
| 46 |
static void move_aura(object *aura); |
| 47 |
|
| 48 |
static void forklightning(object *op, object *tmp); |
| 49 |
static void check_spell_knockback(object *op); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
void init_type_spell_effect(void) { |
| 55 |
register_move_on(SPELL_EFFECT, spell_effect_type_move_on); |
| 56 |
register_process(SPELL_EFFECT, spell_effect_type_process); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static method_ret spell_effect_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) { |
| 68 |
if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR) |
| 69 |
return METHOD_OK; |
| 70 |
|
| 71 |
switch (trap->subtype) { |
| 72 |
case SP_CONE: |
| 73 |
if (QUERY_FLAG(victim, FLAG_ALIVE) |
| 74 |
&& trap->speed |
| 75 |
&& trap->attacktype) |
| 76 |
hit_player(victim, trap->stats.dam, trap, trap->attacktype, 0); |
| 77 |
break; |
| 78 |
|
| 79 |
case SP_MAGIC_MISSILE: |
| 80 |
if (QUERY_FLAG(victim, FLAG_ALIVE)) { |
| 81 |
tag_t spell_tag = trap->count; |
| 82 |
|
| 83 |
hit_player(victim, trap->stats.dam, trap, trap->attacktype, 1); |
| 84 |
if (!object_was_destroyed(trap, spell_tag)) { |
| 85 |
object_remove(trap); |
| 86 |
object_free_drop_inventory(trap); |
| 87 |
} |
| 88 |
} |
| 89 |
break; |
| 90 |
|
| 91 |
case SP_MOVING_BALL: |
| 92 |
if (QUERY_FLAG(victim, FLAG_ALIVE)) |
| 93 |
hit_player(victim, trap->stats.dam, trap, trap->attacktype, 1); |
| 94 |
else if (victim->material || victim->materialname) |
| 95 |
save_throw_object(victim, trap->attacktype, trap); |
| 96 |
break; |
| 97 |
} |
| 98 |
common_post_ob_move_on(trap, victim, originator); |
| 99 |
return METHOD_OK; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static method_ret spell_effect_type_process(ob_methods *context, object *op) { |
| 109 |
switch (op->subtype) { |
| 110 |
case SP_BOLT: |
| 111 |
move_bolt(op); |
| 112 |
break; |
| 113 |
|
| 114 |
case SP_BULLET: |
| 115 |
move_bullet(op); |
| 116 |
break; |
| 117 |
|
| 118 |
case SP_EXPLOSION: |
| 119 |
explosion(op); |
| 120 |
break; |
| 121 |
|
| 122 |
case SP_CONE: |
| 123 |
move_cone(op); |
| 124 |
break; |
| 125 |
|
| 126 |
case SP_BOMB: |
| 127 |
animate_bomb(op); |
| 128 |
break; |
| 129 |
|
| 130 |
case SP_MAGIC_MISSILE: |
| 131 |
move_missile(op); |
| 132 |
break; |
| 133 |
|
| 134 |
case SP_WORD_OF_RECALL: |
| 135 |
execute_word_of_recall(op); |
| 136 |
break; |
| 137 |
|
| 138 |
case SP_MOVING_BALL: |
| 139 |
move_ball_spell(op); |
| 140 |
break; |
| 141 |
|
| 142 |
case SP_SWARM: |
| 143 |
move_swarm_spell(op); |
| 144 |
break; |
| 145 |
|
| 146 |
case SP_AURA: |
| 147 |
move_aura(op); |
| 148 |
break; |
| 149 |
} |
| 150 |
return METHOD_OK; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static void move_bolt(object *op) { |
| 159 |
object *tmp; |
| 160 |
int mflags; |
| 161 |
int16_t x, y; |
| 162 |
mapstruct *m; |
| 163 |
|
| 164 |
if (--(op->duration) < 0) { |
| 165 |
object_remove(op); |
| 166 |
object_free_drop_inventory(op); |
| 167 |
return; |
| 168 |
} |
| 169 |
hit_map(op, 0, op->attacktype, 1); |
| 170 |
|
| 171 |
check_spell_knockback(op); |
| 172 |
|
| 173 |
if (!op->direction) |
| 174 |
return; |
| 175 |
|
| 176 |
if (--op->range < 0) { |
| 177 |
op->range = 0; |
| 178 |
} else { |
| 179 |
x = op->x+DIRX(op); |
| 180 |
y = op->y+DIRY(op); |
| 181 |
m = op->map; |
| 182 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 183 |
|
| 184 |
if (mflags&P_OUT_OF_MAP) |
| 185 |
return; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y)) |
| 193 |
|| ((mflags&P_IS_ALIVE) && reflwall(m, x, y, op))) { |
| 194 |
if (!QUERY_FLAG(op, FLAG_REFLECTING)) |
| 195 |
return; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
if (op->direction&1) { |
| 206 |
op->direction = absdir(op->direction+4); |
| 207 |
} else { |
| 208 |
int left, right; |
| 209 |
int mflags; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction-1)], op->y+freearr_y[absdir(op->direction-1)], &x, &y); |
| 217 |
|
| 218 |
left = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y)); |
| 219 |
|
| 220 |
mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction+1)], op->y+freearr_y[absdir(op->direction+1)], &x, &y); |
| 221 |
right = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y)); |
| 222 |
|
| 223 |
if (left == right) |
| 224 |
op->direction = absdir(op->direction+4); |
| 225 |
else if (left) |
| 226 |
op->direction = absdir(op->direction+2); |
| 227 |
else if (right) |
| 228 |
op->direction = absdir(op->direction-2); |
| 229 |
} |
| 230 |
object_update_turn_face(op); |
| 231 |
return; |
| 232 |
} else { |
| 233 |
tmp = object_new(); |
| 234 |
object_copy(op, tmp); |
| 235 |
tmp->speed_left = -0.1; |
| 236 |
tmp = object_insert_in_map_at(tmp, op->map, op, 0, op->x+DIRX(op), op->y+DIRY(op)); |
| 237 |
|
| 238 |
tmp->duration++; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
if (rndm(0, 99) < tmp->stats.Dex) { |
| 245 |
forklightning(op, tmp); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
op->range = 0; |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
static void move_bullet(object *op) { |
| 262 |
int16_t new_x, new_y; |
| 263 |
int mflags; |
| 264 |
mapstruct *m; |
| 265 |
|
| 266 |
|
| 267 |
if (--op->range <= 0) { |
| 268 |
if (op->other_arch) { |
| 269 |
explode_bullet(op); |
| 270 |
} else { |
| 271 |
object_remove(op); |
| 272 |
object_free_drop_inventory(op); |
| 273 |
} |
| 274 |
return; |
| 275 |
} |
| 276 |
|
| 277 |
new_x = op->x+DIRX(op); |
| 278 |
new_y = op->y+DIRY(op); |
| 279 |
m = op->map; |
| 280 |
mflags = get_map_flags(m, &m, new_x, new_y, &new_x, &new_y); |
| 281 |
|
| 282 |
if (mflags&P_OUT_OF_MAP) { |
| 283 |
object_remove(op); |
| 284 |
object_free_drop_inventory(op); |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
if (!op->direction || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y))) { |
| 289 |
if (op->other_arch) { |
| 290 |
explode_bullet(op); |
| 291 |
} else { |
| 292 |
object_remove(op); |
| 293 |
object_free_drop_inventory(op); |
| 294 |
} |
| 295 |
return; |
| 296 |
} |
| 297 |
|
| 298 |
object_remove(op); |
| 299 |
if ((op = object_insert_in_map_at(op, m, op, 0, new_x, new_y)) == NULL) |
| 300 |
return; |
| 301 |
|
| 302 |
if (reflwall(op->map, op->x, op->y, op)) { |
| 303 |
op->direction = absdir(op->direction+4); |
| 304 |
object_update_turn_face(op); |
| 305 |
} else { |
| 306 |
check_bullet(op); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
static void explosion(object *op) { |
| 316 |
object *tmp; |
| 317 |
mapstruct *m = op->map; |
| 318 |
int i; |
| 319 |
|
| 320 |
if (--(op->duration) < 0) { |
| 321 |
object_remove(op); |
| 322 |
object_free_drop_inventory(op); |
| 323 |
return; |
| 324 |
} |
| 325 |
hit_map(op, 0, op->attacktype, 0); |
| 326 |
check_spell_knockback(op); |
| 327 |
|
| 328 |
if (op->range > 0) { |
| 329 |
for (i = 1; i < 9; i++) { |
| 330 |
int16_t dx, dy; |
| 331 |
int16_t Dx, Dy; |
| 332 |
dx = op->x+freearr_x[i]; |
| 333 |
dy = op->y+freearr_y[i]; |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
if (ok_to_put_more(op->map, dx, dy, op, op->attacktype)) { |
| 338 |
tmp = object_new(); |
| 339 |
object_copy(op, tmp); |
| 340 |
tmp->state = 0; |
| 341 |
tmp->speed_left = -0.21; |
| 342 |
tmp->range--; |
| 343 |
tmp->value = 0; |
| 344 |
Dx=dx-op->x; |
| 345 |
Dy=dy-op->y; |
| 346 |
if (Dx==-1 && Dy==-1){ |
| 347 |
tmp->direction=8; |
| 348 |
} |
| 349 |
if (Dx==0 && Dy==-1){ |
| 350 |
tmp->direction=1; |
| 351 |
} |
| 352 |
if (Dx==1 && Dy==-1){ |
| 353 |
tmp->direction=2; |
| 354 |
} |
| 355 |
if (Dx==1 && Dy==0){ |
| 356 |
tmp->direction=3; |
| 357 |
} |
| 358 |
if (Dx==1 && Dy==1){ |
| 359 |
tmp->direction=4; |
| 360 |
} |
| 361 |
if (Dx==0 && Dy==1){ |
| 362 |
tmp->direction=5; |
| 363 |
} |
| 364 |
if (Dx==-1 && Dy==-1){ |
| 365 |
tmp->direction=6; |
| 366 |
} |
| 367 |
if (Dx==-1 && Dy==0){ |
| 368 |
tmp->direction=7; |
| 369 |
} |
| 370 |
|
| 371 |
object_insert_in_map_at(tmp, m, op, 0, dx, dy); |
| 372 |
|
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
op->range = 0; |
| 380 |
object_merge_spell(op, op->x, op->y); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
static void move_cone(object *op) { |
| 389 |
int i; |
| 390 |
tag_t tag; |
| 391 |
|
| 392 |
|
| 393 |
if (!op->map) { |
| 394 |
LOG(llevError, "Tried to move_cone object %s without a map.\n", op->name ? op->name : "unknown"); |
| 395 |
op->speed = 0; |
| 396 |
object_update_speed(op); |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
if (QUERY_FLAG(op, FLAG_LIFESAVE)) { |
| 402 |
hit_map(op, 0, op->attacktype, 0); |
| 403 |
return; |
| 404 |
} |
| 405 |
|
| 406 |
tag = op->count; |
| 407 |
hit_map(op, 0, op->attacktype, 0); |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
check_spell_knockback(op); |
| 414 |
|
| 415 |
if (object_was_destroyed(op, tag)) |
| 416 |
return; |
| 417 |
|
| 418 |
if ((op->duration--) < 0) { |
| 419 |
object_remove(op); |
| 420 |
object_free_drop_inventory(op); |
| 421 |
return; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
if (--op->range < 0) { |
| 429 |
op->range = 0; |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
for (i = -1; i < 2; i++) { |
| 434 |
int16_t x = op->x+freearr_x[absdir(op->stats.sp+i)]; |
| 435 |
int16_t y = op->y+freearr_y[absdir(op->stats.sp+i)]; |
| 436 |
|
| 437 |
if (ok_to_put_more(op->map, x, y, op, op->attacktype)) { |
| 438 |
object *tmp = object_new(); |
| 439 |
|
| 440 |
object_copy(op, tmp); |
| 441 |
tmp->duration = op->duration+1; |
| 442 |
|
| 443 |
|
| 444 |
tmp->stats.maxhp = op->stats.maxhp; |
| 445 |
object_insert_in_map_at(tmp, op->map, op, 0, x, y); |
| 446 |
if (tmp->other_arch) |
| 447 |
cone_drop(tmp); |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
static void animate_bomb(object *op) { |
| 457 |
int i; |
| 458 |
object *env, *tmp; |
| 459 |
archetype *at; |
| 460 |
|
| 461 |
if (op->state != NUM_ANIMATIONS(op)-1) |
| 462 |
return; |
| 463 |
|
| 464 |
env = object_get_env_recursive(op); |
| 465 |
|
| 466 |
if (op->env) { |
| 467 |
if (env->map == NULL) |
| 468 |
return; |
| 469 |
|
| 470 |
object_remove(op); |
| 471 |
if ((op = object_insert_in_map_at(op, env->map, op, 0, env->x, env->y)) == NULL) |
| 472 |
return; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
at = find_archetype(SPLINT); |
| 480 |
if (at) { |
| 481 |
for (i = 1; i < 9; i++) { |
| 482 |
if (out_of_map(op->map, op->x+freearr_x[i], op->y+freearr_x[i])) |
| 483 |
continue; |
| 484 |
tmp = arch_to_object(at); |
| 485 |
tmp->direction = i; |
| 486 |
tmp->range = op->range; |
| 487 |
tmp->stats.dam = op->stats.dam; |
| 488 |
tmp->duration = op->duration; |
| 489 |
tmp->attacktype = op->attacktype; |
| 490 |
object_copy_owner(tmp, op); |
| 491 |
if (op->skill && op->skill != tmp->skill) { |
| 492 |
if (tmp->skill) |
| 493 |
free_string(tmp->skill); |
| 494 |
tmp->skill = add_refcount(op->skill); |
| 495 |
} |
| 496 |
object_update_turn_face(tmp); |
| 497 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[i], op->y+freearr_x[i]); |
| 498 |
ob_process(tmp); |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
explode_bullet(op); |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
static void move_missile(object *op) { |
| 510 |
int i, mflags; |
| 511 |
int16_t new_x, new_y; |
| 512 |
mapstruct *m; |
| 513 |
|
| 514 |
if (op->range-- <= 0) { |
| 515 |
object_remove(op); |
| 516 |
object_free_drop_inventory(op); |
| 517 |
return; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
object_get_owner(op); |
| 522 |
|
| 523 |
new_x = op->x+DIRX(op); |
| 524 |
new_y = op->y+DIRY(op); |
| 525 |
|
| 526 |
mflags = get_map_flags(op->map, &m, new_x, new_y, &new_x, &new_y); |
| 527 |
|
| 528 |
if (!(mflags&P_OUT_OF_MAP) |
| 529 |
&& ((mflags&P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y)))) { |
| 530 |
tag_t tag = op->count; |
| 531 |
|
| 532 |
hit_map(op, op->direction, AT_MAGIC, 1); |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
if (!object_was_destroyed(op, tag)) { |
| 537 |
object_remove(op); |
| 538 |
object_free_drop_inventory(op); |
| 539 |
} |
| 540 |
return; |
| 541 |
} |
| 542 |
|
| 543 |
object_remove(op); |
| 544 |
if (!op->direction || (mflags&P_OUT_OF_MAP)) { |
| 545 |
object_free_drop_inventory(op); |
| 546 |
return; |
| 547 |
} |
| 548 |
i = spell_find_dir(m, new_x, new_y, object_get_owner(op)); |
| 549 |
if (i > 0 && i != op->direction) { |
| 550 |
op->direction = adjust_dir(op->direction, i); |
| 551 |
object_update_turn_face(op); |
| 552 |
} |
| 553 |
object_insert_in_map_at(op, m, op, 0, new_x, new_y); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
static void execute_word_of_recall(object *op) { |
| 561 |
object *wor = op; |
| 562 |
|
| 563 |
while (op != NULL && op->type != PLAYER) |
| 564 |
op = op->env; |
| 565 |
|
| 566 |
if (op != NULL) { |
| 567 |
|
| 568 |
|
| 569 |
remove_unpaid_objects(op->inv, op, 0); |
| 570 |
|
| 571 |
enter_exit(op, wor); |
| 572 |
} |
| 573 |
object_remove(wor); |
| 574 |
object_free_drop_inventory(wor); |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
static void move_ball_spell(object *op) { |
| 583 |
int i, j, dam_save, dir, mflags; |
| 584 |
int16_t nx, ny, hx, hy; |
| 585 |
object *owner; |
| 586 |
mapstruct *m; |
| 587 |
|
| 588 |
owner = object_get_owner(op); |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
dir = 0; |
| 598 |
j = rndm(0, 1); |
| 599 |
for (i = 1; i <= 9; i++) { |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
int offset = ((i^j)&1) ? (i/2) : -(i/2); |
| 605 |
int tmpdir = absdir(op->direction+offset); |
| 606 |
|
| 607 |
nx = op->x+freearr_x[tmpdir]; |
| 608 |
ny = op->y+freearr_y[tmpdir]; |
| 609 |
if (!(get_map_flags(op->map, &m, nx, ny, &nx, &ny)&P_OUT_OF_MAP) |
| 610 |
&& !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, nx, ny)))) { |
| 611 |
dir = tmpdir; |
| 612 |
break; |
| 613 |
} |
| 614 |
} |
| 615 |
if (dir == 0) { |
| 616 |
nx = op->x; |
| 617 |
ny = op->y; |
| 618 |
m = op->map; |
| 619 |
} |
| 620 |
|
| 621 |
object_remove(op); |
| 622 |
object_insert_in_map_at(op, m, op, 0, nx, ny); |
| 623 |
|
| 624 |
dam_save = op->stats.dam; |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
for (j = 0; j < 9; j++) { |
| 632 |
object *new_ob; |
| 633 |
|
| 634 |
hx = nx+freearr_x[j]; |
| 635 |
hy = ny+freearr_y[j]; |
| 636 |
|
| 637 |
m = op->map; |
| 638 |
mflags = get_map_flags(m, &m, hx, hy, &hx, &hy); |
| 639 |
|
| 640 |
if (mflags&P_OUT_OF_MAP) |
| 641 |
continue; |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
if ((mflags&P_IS_ALIVE) && (!owner || owner->x != hx || owner->y != hy || !on_same_map(owner, op))) { |
| 648 |
if (j) |
| 649 |
op->stats.dam = dam_save/2; |
| 650 |
hit_map(op, j, op->attacktype, 1); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
if (op->other_arch && !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, hx, hy)))) { |
| 655 |
new_ob = arch_to_object(op->other_arch); |
| 656 |
object_insert_in_map_at(new_ob, m, op, 0, hx, hy); |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
op->stats.dam = dam_save; |
| 662 |
|
| 663 |
i = spell_find_dir(op->map, op->x, op->y, object_get_owner(op)); |
| 664 |
if (i >= 0) { |
| 665 |
op->direction = adjust_dir(op->direction, i); |
| 666 |
if (rndm(0, 3) != 0) |
| 667 |
op->direction = adjust_dir(op->direction, i); |
| 668 |
if (rndm(0, 3) == 0) |
| 669 |
op->direction = adjust_dir(op->direction, i); |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
static void move_swarm_spell(object *op) { |
| 682 |
static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 }; |
| 683 |
static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; |
| 684 |
int16_t target_x, target_y, origin_x, origin_y; |
| 685 |
int basedir, adjustdir; |
| 686 |
mapstruct *m; |
| 687 |
object *owner; |
| 688 |
|
| 689 |
owner = object_get_owner(op); |
| 690 |
if (op->duration == 0 || owner == NULL || owner->x != op->x || owner->y != op->y) { |
| 691 |
object_remove(op); |
| 692 |
object_free_drop_inventory(op); |
| 693 |
return; |
| 694 |
} |
| 695 |
op->duration--; |
| 696 |
|
| 697 |
basedir = op->direction; |
| 698 |
if (basedir == 0) { |
| 699 |
|
| 700 |
basedir = get_random_dir(); |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
if (op->duration) { |
| 707 |
if (basedir&1) { |
| 708 |
adjustdir = cardinal_adjust[rndm(0, 8)]; |
| 709 |
} else { |
| 710 |
adjustdir = diagonal_adjust[rndm(0, 9)]; |
| 711 |
} |
| 712 |
} else { |
| 713 |
adjustdir = 0; |
| 714 |
} |
| 715 |
|
| 716 |
target_x = op->x+freearr_x[absdir(basedir+adjustdir)]; |
| 717 |
target_y = op->y+freearr_y[absdir(basedir+adjustdir)]; |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
origin_x = target_x-freearr_x[basedir]; |
| 723 |
origin_y = target_y-freearr_y[basedir]; |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
if (op->spell && op->spell->type == SPELL && !(get_map_flags(op->map, &m, target_x, target_y, &target_x, &target_y)&P_OUT_OF_MAP)) { |
| 733 |
|
| 734 |
if (op->spell->subtype == SP_BULLET) |
| 735 |
fire_arch_from_position(owner, op, origin_x+freearr_x[basedir], origin_y+freearr_y[basedir], basedir, op->spell); |
| 736 |
else if (op->spell->subtype == SP_MAGIC_MISSILE) |
| 737 |
fire_arch_from_position(owner, op, origin_x, origin_y, basedir, op->spell); |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
static void move_aura(object *aura) { |
| 752 |
int i, mflags; |
| 753 |
object *env; |
| 754 |
mapstruct *m; |
| 755 |
|
| 756 |
|
| 757 |
env = aura->env; |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
object_remove(aura); |
| 763 |
|
| 764 |
|
| 765 |
if (aura->duration-- < 0) { |
| 766 |
object_free_drop_inventory(aura); |
| 767 |
return; |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
if (env == NULL || env->map == NULL) { |
| 772 |
object_free_drop_inventory(aura); |
| 773 |
return; |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
object_insert_in_map_at(aura, env->map, aura, 0, env->x, env->y); |
| 780 |
|
| 781 |
for (i = 1; i < 9; i++) { |
| 782 |
int16_t nx, ny; |
| 783 |
|
| 784 |
nx = aura->x+freearr_x[i]; |
| 785 |
ny = aura->y+freearr_y[i]; |
| 786 |
mflags = get_map_flags(env->map, &m, nx, ny, &nx, &ny); |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
if (!(mflags&P_OUT_OF_MAP) && !(OB_TYPE_MOVE_BLOCK(env, GET_MAP_MOVE_BLOCK(m, nx, ny)))) { |
| 793 |
hit_map(aura, i, aura->attacktype, 0); |
| 794 |
|
| 795 |
if (aura->other_arch) { |
| 796 |
object *new_ob; |
| 797 |
|
| 798 |
new_ob = arch_to_object(aura->other_arch); |
| 799 |
object_insert_in_map_at(new_ob, m, aura, 0, nx, ny); |
| 800 |
} |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
object_remove(aura); |
| 806 |
object_insert_in_ob(aura, env); |
| 807 |
check_spell_expiry(aura); |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
static void forklightning(object *op, object *tmp) { |
| 816 |
int new_dir = 1; |
| 817 |
int t_dir; |
| 818 |
mapstruct *m; |
| 819 |
int16_t sx, sy; |
| 820 |
object *new_bolt; |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
if (rndm(0, 99) < tmp->stats.Con) |
| 829 |
new_dir = -1; |
| 830 |
|
| 831 |
|
| 832 |
t_dir = absdir(tmp->direction+new_dir); |
| 833 |
|
| 834 |
if (get_map_flags(tmp->map, &m, tmp->x+freearr_x[t_dir], tmp->y+freearr_y[t_dir], &sx, &sy)&P_OUT_OF_MAP) |
| 835 |
return; |
| 836 |
|
| 837 |
if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(m, sx, sy))) |
| 838 |
return; |
| 839 |
|
| 840 |
|
| 841 |
new_bolt = object_new(); |
| 842 |
|
| 843 |
object_copy(tmp, new_bolt); |
| 844 |
|
| 845 |
|
| 846 |
new_bolt->stats.Dex -= 10; |
| 847 |
tmp->stats.Dex -= 10; |
| 848 |
new_bolt->stats.Con += 25*new_dir; |
| 849 |
new_bolt->speed_left = -0.1; |
| 850 |
new_bolt->direction = t_dir; |
| 851 |
new_bolt->duration++; |
| 852 |
new_bolt->stats.dam /= 2; |
| 853 |
new_bolt->stats.dam++; |
| 854 |
tmp->stats.dam /= 2; |
| 855 |
tmp->stats.dam++; |
| 856 |
new_bolt = object_insert_in_map_at(new_bolt, m, op, 0, sx, sy); |
| 857 |
object_update_turn_face(new_bolt); |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
static void check_spell_knockback(object *op) { |
| 867 |
object *tmp, *tmp2; |
| 868 |
int weight_move; |
| 869 |
int frictionmod = 2; |
| 870 |
|
| 871 |
|
| 872 |
if (!op->weight) { |
| 873 |
return; |
| 874 |
} |
| 875 |
|
| 876 |
weight_move = op->weight+(op->weight*op->level)/3; |
| 877 |
|
| 878 |
|
| 879 |
for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) { |
| 880 |
int num_sections = 1; |
| 881 |
|
| 882 |
|
| 883 |
if (QUERY_FLAG(tmp, FLAG_WIZ)) |
| 884 |
return; |
| 885 |
|
| 886 |
|
| 887 |
if (tmp->head) |
| 888 |
continue; |
| 889 |
|
| 890 |
|
| 891 |
if (QUERY_FLAG(tmp, FLAG_IS_FLOOR) || QUERY_FLAG(tmp, FLAG_NO_PICK)) |
| 892 |
continue; |
| 893 |
|
| 894 |
|
| 895 |
for (tmp2 = tmp; tmp2 != NULL; tmp2 = tmp2->more) |
| 896 |
num_sections++; |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
if (tmp->move_type&MOVE_FLYING) |
| 906 |
frictionmod = 1; |
| 907 |
if (rndm(0, weight_move-1) > ((tmp->weight/num_sections)*frictionmod)) { |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
if (op->direction){ |
| 917 |
move_object(tmp,absdir(op->direction)); |
| 918 |
} |
| 919 |
|
| 920 |
else { |
| 921 |
(move_object(tmp, absdir(op->stats.sp))); |
| 922 |
|
| 923 |
} |
| 924 |
} |
| 925 |
else{ |
| 926 |
|
| 927 |
} |
| 928 |
} |
| 929 |
} |