| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#include "sproto.h" |
| 25 |
|
| 26 |
static objectlink *get_button_links(const object *button); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
void trigger_connected(objectlink *ol, object *cause, const int state) { |
| 42 |
object *tmp; |
| 43 |
|
| 44 |
for (; ol; ol = ol->next) { |
| 45 |
object *part; |
| 46 |
|
| 47 |
if (!ol->ob || ol->ob->count != ol->id) { |
| 48 |
LOG(llevError, "Internal error in trigger_connect. No object associated with link id (%u) (cause='%s'.\n", ol->id, (cause && cause->name) ? cause->name : ""); |
| 49 |
continue; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
if (QUERY_FLAG(ol->ob, FLAG_FREED)) |
| 60 |
return; |
| 61 |
tmp = ol->ob; |
| 62 |
|
| 63 |
|
| 64 |
if (state && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_PUSH)) |
| 65 |
continue; |
| 66 |
if (!state && !QUERY_FLAG(tmp, FLAG_ACTIVATE_ON_RELEASE)) |
| 67 |
continue; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if (execute_event(tmp, EVENT_TRIGGER, cause, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 75 |
continue; |
| 76 |
|
| 77 |
switch (tmp->type) { |
| 78 |
case GATE: |
| 79 |
case HOLE: |
| 80 |
tmp->value = tmp->stats.maxsp ? !state : state; |
| 81 |
tmp->speed = 0.5; |
| 82 |
object_update_speed(tmp); |
| 83 |
break; |
| 84 |
|
| 85 |
case CF_HANDLE: |
| 86 |
SET_ANIMATION(tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); |
| 87 |
object_update(tmp, UP_OBJ_FACE); |
| 88 |
break; |
| 89 |
|
| 90 |
case SIGN: |
| 91 |
if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) { |
| 92 |
ext_info_map(NDI_UNIQUE|NDI_NAVY, tmp->map, |
| 93 |
MSG_TYPE_SIGN, MSG_SUBTYPE_NONE, |
| 94 |
tmp->msg); |
| 95 |
if (tmp->stats.food) |
| 96 |
tmp->last_eat++; |
| 97 |
} |
| 98 |
break; |
| 99 |
|
| 100 |
case ALTAR: |
| 101 |
tmp->value = 1; |
| 102 |
SET_ANIMATION(tmp, tmp->value); |
| 103 |
object_update(tmp, UP_OBJ_FACE); |
| 104 |
break; |
| 105 |
|
| 106 |
case BUTTON: |
| 107 |
case PEDESTAL: |
| 108 |
tmp->value = state; |
| 109 |
SET_ANIMATION(tmp, tmp->value); |
| 110 |
object_update(tmp, UP_OBJ_FACE); |
| 111 |
break; |
| 112 |
|
| 113 |
case TIMED_GATE: |
| 114 |
for (part = tmp; tmp != NULL; tmp = tmp->more) { |
| 115 |
part->speed = tmp->arch->clone.speed; |
| 116 |
part->value = tmp->arch->clone.value; |
| 117 |
part->stats.sp = 1; |
| 118 |
part->stats.hp = tmp->stats.maxhp; |
| 119 |
object_update_speed(part); |
| 120 |
} |
| 121 |
break; |
| 122 |
|
| 123 |
case DIRECTOR: |
| 124 |
if ((tmp->stats.sp += tmp->stats.maxsp) > 8) |
| 125 |
tmp->stats.sp = ((tmp->stats.sp-1)%8)+1; |
| 126 |
animate_turning(tmp); |
| 127 |
break; |
| 128 |
case FIREWALL: |
| 129 |
|
| 130 |
if (!QUERY_FLAG(tmp, FLAG_ANIMATE)) |
| 131 |
move_firewall(tmp); |
| 132 |
else { |
| 133 |
if ((tmp->direction += tmp->stats.maxsp) > 8) |
| 134 |
tmp->direction = ((tmp->direction-1)%8)+1; |
| 135 |
animate_turning(tmp); |
| 136 |
} |
| 137 |
break; |
| 138 |
|
| 139 |
|
| 140 |
default: |
| 141 |
ob_trigger(tmp, cause, state); |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
void push_button(object *op) { |
| 155 |
|
| 156 |
trigger_connected(get_button_links(op), op, op->value); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
void update_button(object *op) { |
| 168 |
object *tmp, *head; |
| 169 |
int tot, any_down = 0, old_value = op->value; |
| 170 |
objectlink *ol; |
| 171 |
|
| 172 |
|
| 173 |
for (ol = get_button_links(op); ol; ol = ol->next) { |
| 174 |
if (!ol->ob || ol->ob->count != ol->id) { |
| 175 |
LOG(llevDebug, "Internal error in update_button (%s).\n", op->name); |
| 176 |
continue; |
| 177 |
} |
| 178 |
|
| 179 |
tmp = ol->ob; |
| 180 |
if (tmp->type == BUTTON) { |
| 181 |
tot = 0; |
| 182 |
FOR_ABOVE_PREPARE(tmp, ab) |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if ((ab->move_type&tmp->move_on) || ab->move_type == 0) |
| 197 |
tot += ab->weight*NROF(ab)+ab->carrying; |
| 198 |
FOR_ABOVE_FINISH(); |
| 199 |
|
| 200 |
tmp->value = (tot >= tmp->weight) ? 1 : 0; |
| 201 |
if (tmp->value) |
| 202 |
any_down = 1; |
| 203 |
} else if (tmp->type == PEDESTAL) { |
| 204 |
tmp->value = 0; |
| 205 |
FOR_ABOVE_PREPARE(tmp, ab) { |
| 206 |
head = ab->head ? ab->head : ab; |
| 207 |
|
| 208 |
if (((head->move_type&tmp->move_on) || ab->move_type == 0) |
| 209 |
&& (head->race == tmp->slaying |
| 210 |
|| ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) |
| 211 |
|| (!strcmp(tmp->slaying, "player") && head->type == PLAYER))) |
| 212 |
tmp->value = 1; |
| 213 |
} FOR_ABOVE_FINISH(); |
| 214 |
if (tmp->value) |
| 215 |
any_down = 1; |
| 216 |
} |
| 217 |
} |
| 218 |
if (any_down) |
| 219 |
op->value = 1; |
| 220 |
|
| 221 |
|
| 222 |
if (op->value != old_value) { |
| 223 |
SET_ANIMATION(op, op->value); |
| 224 |
object_update(op, UP_OBJ_FACE); |
| 225 |
push_button(op); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
void update_buttons(mapstruct *m) { |
| 233 |
objectlink *ol; |
| 234 |
oblinkpt *obp; |
| 235 |
|
| 236 |
for (obp = m->buttons; obp; obp = obp->next) |
| 237 |
for (ol = obp->link; ol; ol = ol->next) { |
| 238 |
if (!ol->ob || ol->ob->count != ol->id) { |
| 239 |
LOG(llevError, "Internal error in update_button (%s (%dx%d):%u, connected %ld).\n", |
| 240 |
ol->ob ? ol->ob->name : "null", |
| 241 |
ol->ob ? ol->ob->x : -1, |
| 242 |
ol->ob ? ol->ob->y : -1, |
| 243 |
ol->id, |
| 244 |
obp->value); |
| 245 |
continue; |
| 246 |
} |
| 247 |
if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) { |
| 248 |
update_button(ol->ob); |
| 249 |
break; |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
void use_trigger(object *op) { |
| 260 |
|
| 261 |
op->value = !op->value; |
| 262 |
push_button(op); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
void animate_turning(object *op) { |
| 276 |
if (++op->state >= NUM_ANIMATIONS(op)/8) |
| 277 |
op->state = 0; |
| 278 |
|
| 279 |
if (op->type == FIREWALL){ |
| 280 |
SET_ANIMATION(op, (op->direction-1)*NUM_ANIMATIONS(op)/8+op->state); |
| 281 |
} |
| 282 |
else { |
| 283 |
SET_ANIMATION(op, (op->stats.sp-1)*NUM_ANIMATIONS(op)/8+op->state); |
| 284 |
} |
| 285 |
object_update(op, UP_OBJ_FACE); |
| 286 |
} |
| 287 |
|
| 288 |
#define ARCH_SACRIFICE(xyz) ((xyz)->slaying) |
| 289 |
#define NROF_SACRIFICE(xyz) ((uint32_t)(xyz)->stats.food) |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
static int matches_sacrifice(const object *altar, const object *sacrifice) { |
| 303 |
char name[MAX_BUF]; |
| 304 |
|
| 305 |
if ((QUERY_FLAG(sacrifice, FLAG_ALIVE) && object_get_value(altar, "accept_alive") == NULL) |
| 306 |
|| QUERY_FLAG(sacrifice, FLAG_IS_LINKED) |
| 307 |
|| sacrifice->type == PLAYER) |
| 308 |
return 0; |
| 309 |
|
| 310 |
query_base_name(sacrifice, 0, name, MAX_BUF); |
| 311 |
if (ARCH_SACRIFICE(altar) == sacrifice->arch->name |
| 312 |
|| ARCH_SACRIFICE(altar) == sacrifice->name |
| 313 |
|| ARCH_SACRIFICE(altar) == sacrifice->slaying |
| 314 |
|| (!strcmp(ARCH_SACRIFICE(altar), name))) |
| 315 |
return 1; |
| 316 |
|
| 317 |
if (strcmp(ARCH_SACRIFICE(altar), "money") == 0 |
| 318 |
&& sacrifice->type == MONEY) |
| 319 |
return 1; |
| 320 |
|
| 321 |
return 0; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
int check_altar_sacrifice(const object *altar, const object *sacrifice, int remove_others, int *toremove) { |
| 353 |
int money; |
| 354 |
uint32_t wanted, rest; |
| 355 |
|
| 356 |
if (!matches_sacrifice(altar, sacrifice)) |
| 357 |
|
| 358 |
|
| 359 |
return 0; |
| 360 |
|
| 361 |
|
| 362 |
if (QUERY_FLAG(sacrifice, FLAG_UNPAID)) { |
| 363 |
return 0; |
| 364 |
} |
| 365 |
|
| 366 |
money = (strcmp(ARCH_SACRIFICE(altar), "money") == 0) ? 1 : 0; |
| 367 |
|
| 368 |
|
| 369 |
if (money && sacrifice->nrof*sacrifice->value >= NROF_SACRIFICE(altar)) { |
| 370 |
if (toremove) { |
| 371 |
*toremove = NROF_SACRIFICE(altar)/sacrifice->value; |
| 372 |
|
| 373 |
if (NROF_SACRIFICE(altar)%sacrifice->value) |
| 374 |
(*toremove)++; |
| 375 |
} |
| 376 |
return 1; |
| 377 |
} |
| 378 |
|
| 379 |
if (!money && NROF_SACRIFICE(altar) <= NROF(sacrifice)) { |
| 380 |
if (toremove) |
| 381 |
*toremove = NROF_SACRIFICE(altar); |
| 382 |
return 1; |
| 383 |
} |
| 384 |
|
| 385 |
if (money) { |
| 386 |
wanted = NROF_SACRIFICE(altar)-sacrifice->nrof*sacrifice->value; |
| 387 |
} else { |
| 388 |
wanted = NROF_SACRIFICE(altar)-NROF(sacrifice); |
| 389 |
} |
| 390 |
rest = wanted; |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
FOR_ABOVE_PREPARE(altar, tmp) { |
| 396 |
if (wanted <= 0) |
| 397 |
break; |
| 398 |
if (tmp == sacrifice || !matches_sacrifice(altar, tmp)) |
| 399 |
continue; |
| 400 |
if (money) |
| 401 |
wanted -= tmp->nrof*tmp->value; |
| 402 |
else |
| 403 |
wanted -= NROF(tmp); |
| 404 |
} FOR_ABOVE_FINISH(); |
| 405 |
|
| 406 |
if (wanted > 0) |
| 407 |
|
| 408 |
return 0; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
if (toremove) |
| 414 |
*toremove = NROF(sacrifice); |
| 415 |
|
| 416 |
if (!remove_others) |
| 417 |
return 1; |
| 418 |
|
| 419 |
|
| 420 |
FOR_ABOVE_PREPARE(altar, tmp) { |
| 421 |
if (rest <= 0) |
| 422 |
break; |
| 423 |
if (tmp == sacrifice || !matches_sacrifice(altar, tmp)) |
| 424 |
continue; |
| 425 |
if (money) { |
| 426 |
wanted = tmp->nrof*tmp->value; |
| 427 |
if (rest > wanted) { |
| 428 |
object_remove(tmp); |
| 429 |
rest -= wanted; |
| 430 |
} else { |
| 431 |
wanted = rest/tmp->value; |
| 432 |
if (rest%tmp->value) |
| 433 |
wanted++; |
| 434 |
object_decrease_nrof(tmp, wanted); |
| 435 |
return 1; |
| 436 |
} |
| 437 |
} else |
| 438 |
if (rest > NROF(tmp)) { |
| 439 |
rest -= NROF(tmp); |
| 440 |
object_remove(tmp); |
| 441 |
} else { |
| 442 |
object_decrease_nrof(tmp, rest); |
| 443 |
return 1; |
| 444 |
} |
| 445 |
} FOR_ABOVE_FINISH(); |
| 446 |
|
| 447 |
|
| 448 |
LOG(llevError, "check_altar_sacrifice on %s: found objects to sacrifice, but couldn't remove them??\n", altar->map->path); |
| 449 |
return 1; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
int operate_altar(object *altar, object **sacrifice) { |
| 469 |
int number; |
| 470 |
|
| 471 |
if (!altar->map) { |
| 472 |
LOG(llevError, "BUG: operate_altar(): altar has no map\n"); |
| 473 |
return 0; |
| 474 |
} |
| 475 |
|
| 476 |
if (!altar->slaying || altar->value) |
| 477 |
return 0; |
| 478 |
|
| 479 |
if (!check_altar_sacrifice(altar, *sacrifice, 1, &number)) |
| 480 |
return 0; |
| 481 |
|
| 482 |
|
| 483 |
*sacrifice = object_decrease_nrof(*sacrifice, number); |
| 484 |
|
| 485 |
if (altar->msg) |
| 486 |
ext_info_map(NDI_BLACK, altar->map, MSG_TYPE_DIALOG, MSG_TYPE_DIALOG_ALTAR, altar->msg); |
| 487 |
return 1; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
static void trigger_move(object *op, int state) { |
| 494 |
op->stats.wc = state; |
| 495 |
if (state) { |
| 496 |
use_trigger(op); |
| 497 |
if (op->stats.exp > 0) |
| 498 |
op->speed = 1.0/op->stats.exp; |
| 499 |
else |
| 500 |
op->speed = 1.0; |
| 501 |
object_update_speed(op); |
| 502 |
op->speed_left = -1; |
| 503 |
} else { |
| 504 |
use_trigger(op); |
| 505 |
op->speed = 0; |
| 506 |
object_update_speed(op); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
int check_trigger(object *op, object *cause) { |
| 524 |
int push = 0, tot = 0; |
| 525 |
int in_movement = op->stats.wc || op->speed; |
| 526 |
|
| 527 |
switch (op->type) { |
| 528 |
case TRIGGER_BUTTON: |
| 529 |
if (op->weight > 0) { |
| 530 |
if (cause) { |
| 531 |
FOR_ABOVE_PREPARE(op, tmp) |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
if ((tmp->move_type&op->move_on) || tmp->move_type == 0) { |
| 540 |
tot += tmp->weight*NROF(tmp)+tmp->carrying; |
| 541 |
} |
| 542 |
FOR_ABOVE_FINISH(); |
| 543 |
if (tot >= op->weight) |
| 544 |
push = 1; |
| 545 |
if (op->stats.ac == push) |
| 546 |
return 0; |
| 547 |
op->stats.ac = push; |
| 548 |
if (NUM_ANIMATIONS(op) > 1) { |
| 549 |
SET_ANIMATION(op, push); |
| 550 |
object_update(op, UP_OBJ_FACE); |
| 551 |
} |
| 552 |
if (in_movement || !push) |
| 553 |
return 0; |
| 554 |
} |
| 555 |
trigger_move(op, push); |
| 556 |
} |
| 557 |
return 0; |
| 558 |
|
| 559 |
case TRIGGER_PEDESTAL: |
| 560 |
if (cause) { |
| 561 |
FOR_ABOVE_PREPARE(op, tmp) { |
| 562 |
object *head = tmp->head ? tmp->head : tmp; |
| 563 |
|
| 564 |
|
| 565 |
if (((head->move_type&op->move_on) || head->move_type == 0) |
| 566 |
&& (head->race == op->slaying || (!strcmp(op->slaying, "player") && head->type == PLAYER))) { |
| 567 |
push = 1; |
| 568 |
break; |
| 569 |
} |
| 570 |
} FOR_ABOVE_FINISH(); |
| 571 |
if (op->stats.ac == push) |
| 572 |
return 0; |
| 573 |
op->stats.ac = push; |
| 574 |
if (NUM_ANIMATIONS(op) > 1) { |
| 575 |
SET_ANIMATION(op, push); |
| 576 |
object_update(op, UP_OBJ_FACE); |
| 577 |
} |
| 578 |
if (in_movement || !push) |
| 579 |
return 0; |
| 580 |
} |
| 581 |
trigger_move(op, push); |
| 582 |
return 0; |
| 583 |
|
| 584 |
case TRIGGER_ALTAR: |
| 585 |
if (cause) { |
| 586 |
if (in_movement) |
| 587 |
return 0; |
| 588 |
if (operate_altar(op, &cause)) { |
| 589 |
if (NUM_ANIMATIONS(op) > 1) { |
| 590 |
SET_ANIMATION(op, 1); |
| 591 |
object_update(op, UP_OBJ_FACE); |
| 592 |
} |
| 593 |
|
| 594 |
if (op->last_sp >= 0) { |
| 595 |
trigger_move(op, 1); |
| 596 |
if (op->last_sp > 0) |
| 597 |
op->last_sp = -op->last_sp; |
| 598 |
} else { |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
op->value = !op->value; |
| 603 |
trigger_move(op, 1); |
| 604 |
op->last_sp = -op->last_sp; |
| 605 |
op->value = !op->value; |
| 606 |
} |
| 607 |
return cause == NULL; |
| 608 |
} else { |
| 609 |
return 0; |
| 610 |
} |
| 611 |
} else { |
| 612 |
if (NUM_ANIMATIONS(op) > 1) { |
| 613 |
SET_ANIMATION(op, 0); |
| 614 |
object_update(op, UP_OBJ_FACE); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
if (!op->last_sp) |
| 623 |
trigger_move(op, 0); |
| 624 |
else { |
| 625 |
op->stats.wc = 0; |
| 626 |
op->value = !op->value; |
| 627 |
op->speed = 0; |
| 628 |
object_update_speed(op); |
| 629 |
} |
| 630 |
} |
| 631 |
return 0; |
| 632 |
|
| 633 |
case TRIGGER: |
| 634 |
if (cause) { |
| 635 |
if (in_movement) |
| 636 |
return 0; |
| 637 |
push = 1; |
| 638 |
} |
| 639 |
if (NUM_ANIMATIONS(op) > 1) { |
| 640 |
SET_ANIMATION(op, push); |
| 641 |
object_update(op, UP_OBJ_FACE); |
| 642 |
} |
| 643 |
trigger_move(op, push); |
| 644 |
return 1; |
| 645 |
|
| 646 |
default: |
| 647 |
LOG(llevDebug, "Unknown trigger type: %s (%d)\n", op->name, op->type); |
| 648 |
return 0; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
void add_button_link(object *button, mapstruct *map, int connected) { |
| 662 |
oblinkpt *obp; |
| 663 |
objectlink *ol = get_objectlink(); |
| 664 |
|
| 665 |
if (!map) { |
| 666 |
LOG(llevError, "Tried to add button-link without map.\n"); |
| 667 |
free_objectlink(ol); |
| 668 |
return; |
| 669 |
} |
| 670 |
|
| 671 |
SET_FLAG(button, FLAG_IS_LINKED); |
| 672 |
|
| 673 |
ol->ob = button; |
| 674 |
ol->id = button->count; |
| 675 |
|
| 676 |
for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) |
| 677 |
; |
| 678 |
|
| 679 |
if (obp) { |
| 680 |
ol->next = obp->link; |
| 681 |
obp->link = ol; |
| 682 |
} else { |
| 683 |
obp = get_objectlinkpt(); |
| 684 |
obp->value = connected; |
| 685 |
|
| 686 |
obp->next = map->buttons; |
| 687 |
map->buttons = obp; |
| 688 |
obp->link = ol; |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
void remove_button_link(object *op) { |
| 699 |
oblinkpt *obp; |
| 700 |
objectlink **olp, *ol; |
| 701 |
|
| 702 |
if (op->map == NULL) { |
| 703 |
LOG(llevError, "remove_button_link() in object without map.\n"); |
| 704 |
return; |
| 705 |
} |
| 706 |
if (!QUERY_FLAG(op, FLAG_IS_LINKED)) { |
| 707 |
LOG(llevError, "remove_button_linked() in unlinked object.\n"); |
| 708 |
return; |
| 709 |
} |
| 710 |
|
| 711 |
for (obp = op->map->buttons; obp; obp = obp->next) |
| 712 |
for (olp = &obp->link; (ol = *olp); olp = &ol->next) |
| 713 |
if (ol->ob == op) { |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
*olp = ol->next; |
| 718 |
free(ol); |
| 719 |
return; |
| 720 |
} |
| 721 |
LOG(llevError, "remove_button_linked(): couldn't find object.\n"); |
| 722 |
CLEAR_FLAG(op, FLAG_IS_LINKED); |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
static objectlink *get_button_links(const object *button) { |
| 733 |
oblinkpt *obp; |
| 734 |
objectlink *ol; |
| 735 |
|
| 736 |
if (!button->map) |
| 737 |
return NULL; |
| 738 |
|
| 739 |
for (obp = button->map->buttons; obp; obp = obp->next) |
| 740 |
for (ol = obp->link; ol; ol = ol->next) |
| 741 |
if (ol->ob == button && ol->id == button->count) |
| 742 |
return obp->link; |
| 743 |
return NULL; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
int get_button_value(const object *button) { |
| 755 |
oblinkpt *obp; |
| 756 |
objectlink *ol; |
| 757 |
|
| 758 |
if (!button->map) |
| 759 |
return 0; |
| 760 |
|
| 761 |
for (obp = button->map->buttons; obp; obp = obp->next) |
| 762 |
for (ol = obp->link; ol; ol = ol->next) |
| 763 |
if (ol->ob == button && ol->id == button->count) |
| 764 |
return obp->value; |
| 765 |
return 0; |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
object *check_inv_recursive(object *op, const object *trig) { |
| 788 |
object *ret = NULL; |
| 789 |
|
| 790 |
|
| 791 |
if ((!trig->stats.hp || (op->type == trig->stats.hp)) |
| 792 |
&& (!trig->slaying || (op->slaying == trig->slaying)) |
| 793 |
&& (!trig->race || (op->arch->name == trig->race)) |
| 794 |
&& (!trig->title || (op->title == trig->title)) |
| 795 |
&& (QUERY_FLAG(op, FLAG_UNPAID) == QUERY_FLAG(trig, FLAG_UNPAID))) |
| 796 |
return op; |
| 797 |
|
| 798 |
FOR_INV_PREPARE(op, tmp) { |
| 799 |
if (tmp->inv) { |
| 800 |
ret = check_inv_recursive(tmp, trig); |
| 801 |
if (ret) |
| 802 |
return ret; |
| 803 |
} else if ((!trig->stats.hp || (tmp->type == trig->stats.hp)) |
| 804 |
&& (!trig->slaying || (tmp->slaying == trig->slaying)) |
| 805 |
&& (!trig->race || (tmp->arch->name == trig->race)) |
| 806 |
&& (!trig->title || (tmp->title == trig->title)) |
| 807 |
&& (QUERY_FLAG(tmp, FLAG_UNPAID) == QUERY_FLAG(trig, FLAG_UNPAID))) |
| 808 |
return tmp; |
| 809 |
} FOR_INV_FINISH(); |
| 810 |
|
| 811 |
return NULL; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
void check_inv(object *op, object *trig) { |
| 831 |
object *match; |
| 832 |
|
| 833 |
if (op->type != PLAYER) |
| 834 |
return; |
| 835 |
|
| 836 |
match = check_inv_recursive(op, trig); |
| 837 |
if (match && trig->last_sp) { |
| 838 |
if (trig->last_heal) |
| 839 |
object_decrease_nrof_by_one(match); |
| 840 |
use_trigger(trig); |
| 841 |
} else if (!match && !trig->last_sp) |
| 842 |
use_trigger(trig); |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
void verify_button_links(const mapstruct *map) { |
| 856 |
oblinkpt *obp; |
| 857 |
objectlink *ol; |
| 858 |
|
| 859 |
if (!map) |
| 860 |
return; |
| 861 |
|
| 862 |
for (obp = map->buttons; obp; obp = obp->next) { |
| 863 |
for (ol = obp->link; ol; ol = ol->next) { |
| 864 |
if (ol->id != ol->ob->count) |
| 865 |
LOG(llevError, "verify_button_links: object %s on list is corrupt (%u!=%u)\n", ol->ob->name, ol->id, ol->ob->count); |
| 866 |
} |
| 867 |
} |
| 868 |
} |