| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "global.h" |
| 21 |
|
| 22 |
#include <stdlib.h> |
| 23 |
|
| 24 |
#include "spells.h" |
| 25 |
#include "sproto.h" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
void remove_door(object *op) { |
| 38 |
int i; |
| 39 |
object *tmp; |
| 40 |
|
| 41 |
for (i = 1; i < 9; i += 2) |
| 42 |
if ((tmp = map_find_by_type(op->map, op->x+freearr_x[i], op->y+freearr_y[i], DOOR)) != NULL) { |
| 43 |
tmp->speed = 0.1; |
| 44 |
object_update_speed(tmp); |
| 45 |
tmp->speed_left = -0.2; |
| 46 |
} |
| 47 |
|
| 48 |
if (op->other_arch) { |
| 49 |
tmp = arch_to_object(op->other_arch); |
| 50 |
tmp->level = op->level; |
| 51 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y); |
| 52 |
} |
| 53 |
object_remove(op); |
| 54 |
object_free_drop_inventory(op); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
void remove_locked_door(object *op) { |
| 64 |
int i; |
| 65 |
object *tmp; |
| 66 |
|
| 67 |
for (i = 1; i < 9; i += 2) { |
| 68 |
tmp = map_find_by_type(op->map, op->x+freearr_x[i], op->y+freearr_y[i], LOCKED_DOOR); |
| 69 |
if (tmp && tmp->slaying == op->slaying) { |
| 70 |
tmp->speed = 0.1; |
| 71 |
object_update_speed(tmp); |
| 72 |
tmp->speed_left = -0.2; |
| 73 |
} |
| 74 |
} |
| 75 |
if (op->other_arch) { |
| 76 |
tmp = arch_to_object(op->other_arch); |
| 77 |
tmp->level = op->level; |
| 78 |
object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y); |
| 79 |
} |
| 80 |
object_remove(op); |
| 81 |
object_free_drop_inventory(op); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static int generate_monster_inv(object *gen) { |
| 97 |
int i; |
| 98 |
int nx, ny; |
| 99 |
object *op, *head = NULL; |
| 100 |
const char *code; |
| 101 |
int qty = 0; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if (gen->map == NULL) { |
| 108 |
LOG(llevError, "Generator (%s) not on a map?\n", gen->name); |
| 109 |
return FALSE; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
FOR_INV_PREPARE(gen, op) |
| 114 |
qty++; |
| 115 |
FOR_INV_FINISH(); |
| 116 |
if (!qty) { |
| 117 |
LOG(llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", gen->name); |
| 118 |
return FALSE; |
| 119 |
} |
| 120 |
qty = rndm(0, qty-1); |
| 121 |
op = NULL; |
| 122 |
FOR_INV_PREPARE(gen, tmp) { |
| 123 |
op = tmp; |
| 124 |
if (qty == 0) |
| 125 |
break; |
| 126 |
qty--; |
| 127 |
} FOR_INV_FINISH(); |
| 128 |
i = object_find_multi_free_spot_within_radius(op, gen, &nx, &ny); |
| 129 |
if (i == -1) |
| 130 |
return FALSE; |
| 131 |
head = object_create_clone(op); |
| 132 |
CLEAR_FLAG(head, FLAG_IS_A_TEMPLATE); |
| 133 |
object_unset_flag_inv(head, FLAG_IS_A_TEMPLATE); |
| 134 |
if (rndm(0, 9)) |
| 135 |
generate_artifact(head, gen->map->difficulty); |
| 136 |
code = object_get_value(gen, "generator_code"); |
| 137 |
if (code) { |
| 138 |
object_set_value(head, "generator_code", code, 1); |
| 139 |
} |
| 140 |
object_insert_in_map_at(head, gen->map, gen, 0, nx, ny); |
| 141 |
if (QUERY_FLAG(head, FLAG_FREED)) |
| 142 |
return TRUE; |
| 143 |
object_fix_multipart(head); |
| 144 |
if (HAS_RANDOM_ITEMS(head)) { |
| 145 |
create_treasure(head->randomitems, head, 0, gen->map->difficulty, 0); |
| 146 |
if (QUERY_FLAG(head, FLAG_MONSTER)) { |
| 147 |
monster_check_apply_all(head); |
| 148 |
} |
| 149 |
} |
| 150 |
return TRUE; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static int generate_monster_arch(object *gen) { |
| 164 |
int i; |
| 165 |
int nx, ny; |
| 166 |
object *op, *head = NULL, *prev = NULL; |
| 167 |
archetype *at = gen->other_arch; |
| 168 |
const char *code; |
| 169 |
|
| 170 |
if (gen->other_arch == NULL) { |
| 171 |
LOG(llevError, "Generator without other_arch: %s\n", gen->name); |
| 172 |
return FALSE; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
if (gen->map == NULL) { |
| 179 |
LOG(llevError, "Generator (%s) not on a map?\n", gen->name); |
| 180 |
return FALSE; |
| 181 |
} |
| 182 |
i = object_find_multi_free_spot_within_radius(&at->clone, gen, &nx, &ny); |
| 183 |
if (i == -1) |
| 184 |
return FALSE; |
| 185 |
while (at != NULL) { |
| 186 |
op = arch_to_object(at); |
| 187 |
op->x = nx+at->clone.x; |
| 188 |
op->y = ny+at->clone.y; |
| 189 |
|
| 190 |
if (head != NULL) { |
| 191 |
op->head = head; |
| 192 |
prev->more = op; |
| 193 |
} |
| 194 |
|
| 195 |
if (rndm(0, 9)) |
| 196 |
generate_artifact(op, gen->map->difficulty); |
| 197 |
|
| 198 |
code = object_get_value(gen, "generator_code"); |
| 199 |
|
| 200 |
object_insert_in_map(op, gen->map, gen, 0); |
| 201 |
|
| 202 |
if (QUERY_FLAG(op, FLAG_FREED)) |
| 203 |
return TRUE; |
| 204 |
if (HAS_RANDOM_ITEMS(op)) { |
| 205 |
create_treasure(op->randomitems, op, 0, gen->map->difficulty, 0); |
| 206 |
if (QUERY_FLAG(op, FLAG_MONSTER)) { |
| 207 |
monster_check_apply_all(op); |
| 208 |
} |
| 209 |
} |
| 210 |
if (head == NULL) { |
| 211 |
head = op; |
| 212 |
if (code) { |
| 213 |
object_set_value(head, "generator_code", code, 1); |
| 214 |
} |
| 215 |
} |
| 216 |
prev = op; |
| 217 |
at = at->more; |
| 218 |
} |
| 219 |
return TRUE; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
static void generate_monster(object *gen) { |
| 229 |
int8_t children, max_children; |
| 230 |
int8_t x, y; |
| 231 |
const char *code, *value; |
| 232 |
int did_gen = 0; |
| 233 |
|
| 234 |
if (GENERATE_SPEED(gen) && rndm(0, GENERATE_SPEED(gen)-1)) |
| 235 |
return; |
| 236 |
|
| 237 |
value = object_get_value(gen, "generator_max_map"); |
| 238 |
if (value) { |
| 239 |
max_children = (int8_t)strtol(value, NULL, 10); |
| 240 |
if (max_children < 1) |
| 241 |
return; |
| 242 |
code = object_get_value(gen, "generator_code"); |
| 243 |
if (code) { |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
children = 0; |
| 248 |
for (x = 0; x < MAP_WIDTH(gen->map); x++) { |
| 249 |
for (y = 0; y < MAP_HEIGHT(gen->map); y++) { |
| 250 |
FOR_MAP_PREPARE(gen->map, x, y, tmp) { |
| 251 |
value = object_get_value(tmp, "generator_code"); |
| 252 |
if (value && value == code) { |
| 253 |
children++; |
| 254 |
} |
| 255 |
} FOR_MAP_FINISH(); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
if (children >= max_children+1) |
| 260 |
return; |
| 261 |
} else { |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
value = object_get_value(gen, "generator_name"); |
| 266 |
if (value) { |
| 267 |
object_set_value(gen, "generator_code", value, 1); |
| 268 |
} else if (gen->name) { |
| 269 |
object_set_value(gen, "generator_code", gen->name, 1); |
| 270 |
} else { |
| 271 |
object_set_value(gen, "generator_code", "generator", 1); |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
if (QUERY_FLAG(gen, FLAG_CONTENT_ON_GEN)) |
| 277 |
did_gen = generate_monster_inv(gen); |
| 278 |
else |
| 279 |
did_gen = generate_monster_arch(gen); |
| 280 |
|
| 281 |
|
| 282 |
value = object_get_value(gen, "generator_limit"); |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
if (value && did_gen) { |
| 289 |
int limit = atoi(value), num_generated = 0; |
| 290 |
|
| 291 |
value = object_get_value(gen, "generator_generated"); |
| 292 |
if (value) |
| 293 |
num_generated = atoi(value); |
| 294 |
|
| 295 |
if (num_generated++ >= limit) { |
| 296 |
object_remove(gen); |
| 297 |
object_free_drop_inventory(gen); |
| 298 |
} else { |
| 299 |
char buf[50]; |
| 300 |
|
| 301 |
snprintf(buf, sizeof(buf), "%d", num_generated); |
| 302 |
object_set_value(gen, "generator_generated", buf, 1); |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
static void remove_force(object *op) { |
| 315 |
if (--op->duration > 0) { |
| 316 |
check_spell_expiry(op); |
| 317 |
return; |
| 318 |
} |
| 319 |
|
| 320 |
switch (op->subtype) { |
| 321 |
case FORCE_CONFUSION: |
| 322 |
if (op->env != NULL) { |
| 323 |
CLEAR_FLAG(op->env, FLAG_CONFUSED); |
| 324 |
draw_ext_info(NDI_UNIQUE, 0, op->env, |
| 325 |
MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END, |
| 326 |
"You regain your senses."); |
| 327 |
} |
| 328 |
break; |
| 329 |
|
| 330 |
case FORCE_TRANSFORMED_ITEM: |
| 331 |
|
| 332 |
if (op->env != NULL && op->inv != NULL) { |
| 333 |
object *inv = op->inv; |
| 334 |
object *pl = object_get_player_container(op); |
| 335 |
|
| 336 |
object_remove(inv); |
| 337 |
inv->weight = (inv->nrof ? (int32_t)(op->env->weight/inv->nrof) : op->env->weight); |
| 338 |
if (op->env->env) { |
| 339 |
object_insert_in_ob(inv, op->env->env); |
| 340 |
if (pl) { |
| 341 |
char name[HUGE_BUF]; |
| 342 |
|
| 343 |
query_short_name(inv, name, HUGE_BUF); |
| 344 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, |
| 345 |
"Your %s recovers its original form.", |
| 346 |
name); |
| 347 |
} |
| 348 |
} else { |
| 349 |
|
| 350 |
object_insert_in_map_at(inv, op->env->map, NULL, 0, op->env->x, op->env->y); |
| 351 |
} |
| 352 |
inv = op->env; |
| 353 |
object_remove(op); |
| 354 |
object_free_drop_inventory(op); |
| 355 |
object_remove(inv); |
| 356 |
} |
| 357 |
return; |
| 358 |
|
| 359 |
default: |
| 360 |
break; |
| 361 |
} |
| 362 |
|
| 363 |
if (op->env != NULL) { |
| 364 |
CLEAR_FLAG(op, FLAG_APPLIED); |
| 365 |
change_abil(op->env, op); |
| 366 |
fix_object(op->env); |
| 367 |
} |
| 368 |
object_remove(op); |
| 369 |
object_free_drop_inventory(op); |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
static void animate_trigger(object *op) { |
| 379 |
if ((unsigned char)++op->stats.wc >= NUM_ANIMATIONS(op)) { |
| 380 |
op->stats.wc = 0; |
| 381 |
check_trigger(op, NULL); |
| 382 |
} else { |
| 383 |
SET_ANIMATION(op, op->stats.wc); |
| 384 |
object_update(op, UP_OBJ_FACE); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
static void move_hole(object *op) { |
| 395 |
if (op->value) { |
| 396 |
if (--op->stats.wc <= 0) { |
| 397 |
op->stats.wc = 0; |
| 398 |
op->speed = 0; |
| 399 |
object_update_speed(op); |
| 400 |
|
| 401 |
|
| 402 |
op->move_on = MOVE_WALK; |
| 403 |
FOR_ABOVE_PREPARE(op, tmp) |
| 404 |
ob_move_on(op, tmp, tmp); |
| 405 |
FOR_ABOVE_FINISH(); |
| 406 |
} |
| 407 |
|
| 408 |
op->state = op->stats.wc; |
| 409 |
animate_object(op, 0); |
| 410 |
object_update(op, UP_OBJ_FACE); |
| 411 |
return; |
| 412 |
} |
| 413 |
|
| 414 |
op->move_on = 0; |
| 415 |
|
| 416 |
op->stats.wc++; |
| 417 |
if ((int)op->stats.wc >= NUM_ANIMATIONS(op)) |
| 418 |
op->stats.wc = NUM_ANIMATIONS(op)-1; |
| 419 |
|
| 420 |
op->state = op->stats.wc; |
| 421 |
animate_object(op, 0); |
| 422 |
object_update(op, UP_OBJ_FACE); |
| 423 |
if ((unsigned char)op->stats.wc == (NUM_ANIMATIONS(op)-1)) { |
| 424 |
op->speed = 0; |
| 425 |
object_update_speed(op); |
| 426 |
return; |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
object *stop_item(object *op) { |
| 451 |
if (free_no_drop(op)) |
| 452 |
return NULL; |
| 453 |
|
| 454 |
if (op->map == NULL) |
| 455 |
return op; |
| 456 |
|
| 457 |
switch (op->type) { |
| 458 |
case THROWN_OBJ: { |
| 459 |
object *payload = op->inv; |
| 460 |
|
| 461 |
if (payload == NULL) |
| 462 |
return NULL; |
| 463 |
object_remove(payload); |
| 464 |
object_remove(op); |
| 465 |
object_free_drop_inventory(op); |
| 466 |
return payload; |
| 467 |
} |
| 468 |
|
| 469 |
case ARROW: |
| 470 |
if (op->speed >= MIN_ACTIVE_SPEED) |
| 471 |
op = fix_stopped_arrow(op); |
| 472 |
return op; |
| 473 |
|
| 474 |
default: |
| 475 |
return op; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
void fix_stopped_item(object *op, mapstruct *map, object *originator) { |
| 491 |
if (map == NULL) |
| 492 |
return; |
| 493 |
if (QUERY_FLAG(op, FLAG_REMOVED)) |
| 494 |
object_insert_in_map(op, map, originator, 0); |
| 495 |
else if (op->type == ARROW) |
| 496 |
object_merge(op, NULL); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
object *fix_stopped_arrow(object *op) { |
| 508 |
if (free_no_drop(op)) |
| 509 |
return NULL; |
| 510 |
|
| 511 |
if (rndm(0, 99) < op->stats.food) { |
| 512 |
|
| 513 |
object_remove(op); |
| 514 |
object_free_drop_inventory(op); |
| 515 |
return NULL; |
| 516 |
} |
| 517 |
|
| 518 |
op->direction = 0; |
| 519 |
op->move_on = 0; |
| 520 |
op->move_type = 0; |
| 521 |
op->speed = 0; |
| 522 |
object_update_speed(op); |
| 523 |
op->stats.wc = op->stats.sp; |
| 524 |
op->stats.dam = op->stats.hp; |
| 525 |
op->attacktype = op->stats.grace; |
| 526 |
if (op->slaying != NULL) |
| 527 |
FREE_AND_CLEAR_STR(op->slaying); |
| 528 |
|
| 529 |
if (op->skill != NULL) |
| 530 |
FREE_AND_CLEAR_STR(op->skill); |
| 531 |
|
| 532 |
if (op->spellarg != NULL) { |
| 533 |
op->slaying = add_string(op->spellarg); |
| 534 |
free(op->spellarg); |
| 535 |
op->spellarg = NULL; |
| 536 |
} else |
| 537 |
op->slaying = NULL; |
| 538 |
|
| 539 |
|
| 540 |
op->spellarg = NULL; |
| 541 |
op->stats.sp = 0; |
| 542 |
op->stats.hp = 0; |
| 543 |
op->stats.grace = 0; |
| 544 |
op->level = 0; |
| 545 |
animate_object(op, 0); |
| 546 |
object_clear_owner(op); |
| 547 |
object_update(op, UP_OBJ_FACE); |
| 548 |
return op; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
int free_no_drop(object *op) { |
| 561 |
if (!QUERY_FLAG(op, FLAG_NO_DROP)) { |
| 562 |
return 0; |
| 563 |
} |
| 564 |
|
| 565 |
if (!QUERY_FLAG(op, FLAG_REMOVED)) { |
| 566 |
object_remove(op); |
| 567 |
} |
| 568 |
|
| 569 |
object_free(op, FREE_OBJ_FREE_INVENTORY); |
| 570 |
return 1; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
void change_object(object *op) { |
| 588 |
object *env; |
| 589 |
int i; |
| 590 |
int friendly; |
| 591 |
int unaggressive; |
| 592 |
object *owner; |
| 593 |
|
| 594 |
if (op->other_arch == NULL) { |
| 595 |
LOG(llevError, "Change object (%s) without other_arch error.\n", op->name); |
| 596 |
return; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
if (!QUERY_FLAG(op, FLAG_ALIVE)) { |
| 601 |
if (op->stats.food-- > 0) |
| 602 |
return; |
| 603 |
else |
| 604 |
op->stats.food = 1; |
| 605 |
} |
| 606 |
|
| 607 |
env = op->env; |
| 608 |
object_remove(op); |
| 609 |
friendly = QUERY_FLAG(op, FLAG_FRIENDLY); |
| 610 |
unaggressive = QUERY_FLAG(op, FLAG_UNAGGRESSIVE); |
| 611 |
owner = object_get_owner(op); |
| 612 |
for (i = 0; i < op->stats.food; i++) { |
| 613 |
object *tmp; |
| 614 |
|
| 615 |
tmp = arch_to_object(op->other_arch); |
| 616 |
if (op->type == LAMP) |
| 617 |
tmp->stats.food = op->stats.food-1; |
| 618 |
tmp->stats.hp = op->stats.hp; |
| 619 |
if (friendly) { |
| 620 |
SET_FLAG(tmp, FLAG_FRIENDLY); |
| 621 |
add_friendly_object(tmp); |
| 622 |
tmp->attack_movement = PETMOVE; |
| 623 |
if (owner != NULL) |
| 624 |
object_set_owner(tmp, owner); |
| 625 |
} |
| 626 |
if (unaggressive) |
| 627 |
SET_FLAG(tmp, FLAG_UNAGGRESSIVE); |
| 628 |
if (env) { |
| 629 |
tmp->x = env->x, |
| 630 |
tmp->y = env->y; |
| 631 |
tmp = object_insert_in_ob(tmp, env); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
else if (tmp->arch->more) |
| 636 |
{ |
| 637 |
tmp->map = op->map; |
| 638 |
|
| 639 |
|
| 640 |
if (object_find_multi_free_spot_around(&tmp->arch->clone, op, &tmp->x, &tmp->y) != 0) |
| 641 |
{ |
| 642 |
LOG(llevInfo, "change_object: Failed to find a spot to put changing multipart object\n"); |
| 643 |
|
| 644 |
object_insert_in_map(op, op->map, NULL, INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); |
| 645 |
|
| 646 |
object_free_drop_inventory(tmp); |
| 647 |
|
| 648 |
return; |
| 649 |
} |
| 650 |
object_insert_in_map(tmp, op->map, op, INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); |
| 651 |
object_fix_multipart(tmp); |
| 652 |
} |
| 653 |
else{ |
| 654 |
|
| 655 |
object_insert_to_free_spot_or_free(tmp, op->map, op->x, op->y, 1, SIZEOFFREE1+1, op); |
| 656 |
} |
| 657 |
} |
| 658 |
if (friendly) |
| 659 |
remove_friendly_object(op); |
| 660 |
object_free_drop_inventory(op); |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
void move_firewall(object *op) { |
| 674 |
object *spell; |
| 675 |
|
| 676 |
if (!op->map) |
| 677 |
return; |
| 678 |
|
| 679 |
spell = op->inv; |
| 680 |
if (!spell) { |
| 681 |
LOG(llevError, "firewall '%s' in (%s, %d, %d) has no spell\n", op->name, op->map->path, op->x, op->y); |
| 682 |
return; |
| 683 |
} |
| 684 |
|
| 685 |
cast_spell(op, op, op->direction ? op->direction : get_random_dir(), spell, NULL); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
void move_player_mover(object *op) { |
| 703 |
int dir = op->stats.sp; |
| 704 |
int16_t nx, ny; |
| 705 |
mapstruct *m; |
| 706 |
|
| 707 |
if (!op->map) { |
| 708 |
if (op->env && op->env->map) |
| 709 |
LOG(llevError, "move_player_mover: mover not in a map at %s %d %d!\n", op->env->map->path, op->env->x, op->env->y); |
| 710 |
else |
| 711 |
LOG(llevError, "move_player_mover: mover not in a map at undefinite location!"); |
| 712 |
op->speed = 0; |
| 713 |
object_update_speed(op); |
| 714 |
return; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
if (!dir) |
| 719 |
dir = get_random_dir(); |
| 720 |
|
| 721 |
FOR_MAP_PREPARE(op->map, op->x, op->y, victim) { |
| 722 |
if (QUERY_FLAG(victim, FLAG_ALIVE) |
| 723 |
&& !QUERY_FLAG(victim, FLAG_WIZPASS) |
| 724 |
&& (victim->move_type&op->move_type || !victim->move_type)) { |
| 725 |
victim = HEAD(victim); |
| 726 |
|
| 727 |
if (QUERY_FLAG(op, FLAG_LIFESAVE) && op->stats.hp-- < 0) { |
| 728 |
object_remove(op); |
| 729 |
object_free_drop_inventory(op); |
| 730 |
return; |
| 731 |
} |
| 732 |
nx = op->x+freearr_x[dir]; |
| 733 |
ny = op->y+freearr_y[dir]; |
| 734 |
m = op->map; |
| 735 |
if (get_map_flags(m, &m, nx, ny, &nx, &ny)&P_OUT_OF_MAP) { |
| 736 |
LOG(llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y); |
| 737 |
return; |
| 738 |
} |
| 739 |
|
| 740 |
if (should_director_abort(op, victim)) |
| 741 |
return; |
| 742 |
|
| 743 |
FOR_MAP_PREPARE(m, nx, ny, nextmover) { |
| 744 |
if (nextmover->type == PLAYERMOVER) |
| 745 |
nextmover->speed_left = -.99; |
| 746 |
if (QUERY_FLAG(nextmover, FLAG_ALIVE)) { |
| 747 |
op->speed_left = -1.1; |
| 748 |
} |
| 749 |
} FOR_MAP_FINISH(); |
| 750 |
|
| 751 |
if (victim->type == PLAYER) { |
| 752 |
|
| 753 |
if (op->level) { |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
victim->contr->fire_on = 0; |
| 760 |
victim->speed_left = -FABS(victim->speed); |
| 761 |
move_player(victim, dir); |
| 762 |
} else |
| 763 |
return; |
| 764 |
} else |
| 765 |
move_object(victim, dir); |
| 766 |
|
| 767 |
if (!op->stats.maxsp && op->attacktype) |
| 768 |
op->stats.maxsp = 2.0; |
| 769 |
|
| 770 |
if (op->attacktype) { |
| 771 |
victim->speed_left = -FABS(op->stats.maxsp*victim->speed/op->speed); |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
if (victim->speed_left < -5.0) |
| 779 |
victim->speed_left = -5.0; |
| 780 |
} |
| 781 |
} |
| 782 |
} FOR_MAP_FINISH(); |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
int process_object(object *op) { |
| 795 |
if (QUERY_FLAG(op, FLAG_IS_A_TEMPLATE)) |
| 796 |
return 0; |
| 797 |
|
| 798 |
|
| 799 |
if (execute_event(op, EVENT_TIME, NULL, NULL, NULL, SCRIPT_FIX_NOTHING) != 0) |
| 800 |
return 0; |
| 801 |
|
| 802 |
if (QUERY_FLAG(op, FLAG_MONSTER)) |
| 803 |
if (monster_move(op) || QUERY_FLAG(op, FLAG_FREED)) |
| 804 |
return 1; |
| 805 |
|
| 806 |
if ((QUERY_FLAG(op, FLAG_ANIMATE) && op->anim_speed == 0) |
| 807 |
|| (op->temp_animation && op->temp_anim_speed == 0)) { |
| 808 |
op->state++; |
| 809 |
if (op->type == PLAYER) |
| 810 |
animate_object(op, op->facing); |
| 811 |
else |
| 812 |
animate_object(op, op->direction); |
| 813 |
|
| 814 |
if (QUERY_FLAG(op, FLAG_SEE_ANYWHERE)) |
| 815 |
make_sure_seen(op); |
| 816 |
} |
| 817 |
if (QUERY_FLAG(op, FLAG_CHANGING) && !op->state) { |
| 818 |
change_object(op); |
| 819 |
return 1; |
| 820 |
} |
| 821 |
if (QUERY_FLAG(op, FLAG_GENERATOR) && !QUERY_FLAG(op, FLAG_FRIENDLY)) |
| 822 |
generate_monster(op); |
| 823 |
|
| 824 |
|
| 825 |
if (QUERY_FLAG(op, FLAG_IS_USED_UP) && op->stats.food-- <= 0) { |
| 826 |
if (QUERY_FLAG(op, FLAG_APPLIED)) { |
| 827 |
remove_force(op); |
| 828 |
} else { |
| 829 |
if (op->env != NULL && op->env->type == PLAYER) { |
| 830 |
sstring key; |
| 831 |
key_value *used_up_message; |
| 832 |
|
| 833 |
key = add_string("used_up_message"); |
| 834 |
used_up_message = object_get_key_value(op, key); |
| 835 |
free_string(key); |
| 836 |
|
| 837 |
if (used_up_message != NULL) { |
| 838 |
draw_ext_info_format( |
| 839 |
NDI_BLACK, 0, op->env, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, |
| 840 |
"The %s %s.", op->name, used_up_message->value); |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
object_remove(op); |
| 845 |
if (QUERY_FLAG(op, FLAG_SEE_ANYWHERE)) |
| 846 |
make_sure_not_seen(op); |
| 847 |
object_free(op, FREE_OBJ_DROP_ABOVE_FLOOR); |
| 848 |
} |
| 849 |
return 1; |
| 850 |
} |
| 851 |
return (ob_process(op) == METHOD_OK ? 1 : 0); |
| 852 |
} |
| 853 |
|
| 854 |
void legacy_remove_force(object *op) { |
| 855 |
remove_force(op); |
| 856 |
} |
| 857 |
|
| 858 |
void legacy_animate_trigger(object *op) { |
| 859 |
animate_trigger(op); |
| 860 |
} |
| 861 |
|
| 862 |
void legacy_move_hole(object *op) { |
| 863 |
move_hole(op); |
| 864 |
} |