ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/button.C
(Generate patch)

Comparing deliantra/server/common/button.C (file contents):
Revision 1.50 by root, Thu Jan 1 11:41:17 2009 UTC vs.
Revision 1.59 by root, Wed Oct 21 00:44:39 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
29 30
30/* 31/*
31 * elmex: 32 * elmex:
32 * This function takes a objectlink list with all the objects are going to be activated. 33 * This function takes a objectlink list with all the objects are going to be activated.
33 * state is a true/false flag that will actiavte objects that have FLAG_ACTIVATE_ON_PUSH/RELEASE set. 34 * state is a true/false flag that will actiavte objects that have FLAG_ACTIVATE_ON_PUSH/RELEASE set.
34 * The source argument can be 0 or the source object for this activation. 35 * The activator argument can be 0 or the source object for this activation.
36 * the originator is the player or monster who did something.
35 */ 37 */
36void 38static void
37activate_connection_link (objectlink * ol, bool state, object *source = 0) 39activate_connection_link (objectlink *ol, int state, object *activator, object *originator)
38{ 40{
39 for (; ol; ol = ol->next) 41 for (; ol; ol = ol->next)
40 { 42 {
41 if (!ol->ob) 43 if (!ol->ob)
42 { 44 {
74 : sound_find (tmp->type == GATE ? "trigger_gate" : "trigger_hole")); 76 : sound_find (tmp->type == GATE ? "trigger_gate" : "trigger_hole"));
75 tmp->value = tmp->stats.maxsp ? !state : state; 77 tmp->value = tmp->stats.maxsp ? !state : state;
76 tmp->set_speed (0.5); 78 tmp->set_speed (0.5);
77 break; 79 break;
78 80
79 case CF_HANDLE: 81 case T_HANDLE:
80 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); 82 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state));
81 update_object (tmp, UP_OBJ_FACE); 83 update_object (tmp, UP_OBJ_FACE);
82 break; 84 break;
83 85
84 case SIGN: 86 case SIGN:
105 SET_ANIMATION (tmp, tmp->value); 107 SET_ANIMATION (tmp, tmp->value);
106 update_object (tmp, UP_OBJ_FACE); 108 update_object (tmp, UP_OBJ_FACE);
107 break; 109 break;
108 110
109 case MOOD_FLOOR: 111 case MOOD_FLOOR:
110 do_mood_floor (tmp, source); 112 do_mood_floor (tmp, activator);
111 break; 113 break;
112 114
113 case TIMED_GATE: 115 case TIMED_GATE:
114 if (!tmp->active) 116 if (!tmp->active)
115 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); 117 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate"));
118
116 tmp->set_speed (tmp->arch->speed); 119 tmp->set_speed (tmp->arch->speed);
117 tmp->value = tmp->arch->value; 120 tmp->value = tmp->arch->value;
118 tmp->stats.sp = 1; 121 tmp->stats.sp = 1;
119 tmp->stats.hp = tmp->stats.maxhp; 122 tmp->stats.hp = tmp->stats.maxhp;
120 /* Handle multipart gates. We copy the value for the other parts 123 /* Handle multipart gates. We copy the value for the other parts
133 case FIREWALL: 136 case FIREWALL:
134 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 137 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL)
135 move_firewall (tmp); 138 move_firewall (tmp);
136 else 139 else
137 { 140 {
138 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 141 tmp->stats.sp = absdir (tmp->stats.sp + tmp->stats.maxsp); /* next direction */
139 tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1;
140
141 animate_turning (tmp); 142 animate_turning (tmp);
142 } 143 }
143 break; 144 break;
144 145
145 case TELEPORTER: 146 case TELEPORTER:
155 move_marker (tmp); 156 move_marker (tmp);
156 break; 157 break;
157 158
158 case DUPLICATOR: 159 case DUPLICATOR:
159 move_duplicator (tmp); 160 move_duplicator (tmp);
161 break;
162
163 case MAPSCRIPT:
164 cfperl_mapscript_activate (tmp, state, activator, originator);
160 break; 165 break;
161 } 166 }
162 } 167 }
163} 168}
164 169
173 * Changed the routine to loop through _all_ objects. 178 * Changed the routine to loop through _all_ objects.
174 * Better hurry with that linked list... 179 * Better hurry with that linked list...
175 * 180 *
176 */ 181 */
177void 182void
178push_button (object *op) 183push_button (object *op, object *originator)
179{ 184{
180 oblinkpt *obp = get_button_links (op); 185 if (oblinkpt *obp = op->find_link ())
181 186 {
182 if (!obp) 187 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator)))
183 return; 188 return;
184 189
185 if (INVOKE_MAP (TRIGGER, op->map, ARG_INT64 (obp->value), ARG_INT (op->value)))
186 return;
187
188 activate_connection_link (obp->link, op->value, op); 190 activate_connection_link (obp->link, op->value, op, originator);
191 }
189} 192}
190 193
191/* 194/*
192 * elmex: 195 * elmex:
193 * This activates a connection, similar to push_button (object *op) but it takes 196 * This activates a connection, similar to push_button (object *op) but it takes
195 * the connection was 'state' or 'released'. So that you can activate objects 198 * the connection was 'state' or 'released'. So that you can activate objects
196 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 199 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
197 * 200 *
198 */ 201 */
199void 202void
200activate_connection (maptile *map, long connection, bool state) 203maptile::trigger (shstr_tmp id, int state, object *activator, object *originator)
201{ 204{
202 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) 205 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator)))
203 return; 206 return;
204 207
205 oblinkpt *obp = get_connection_links (map, connection); 208 if (oblinkpt *obp = find_link (id))
206
207 if (obp)
208 activate_connection_link (obp->link, state); 209 activate_connection_link (obp->link, state, activator, originator);
209} 210}
210 211
211/* 212/*
212 * Updates everything connected with the button op. 213 * Updates everything connected with the button op.
213 * After changing the state of a button, this function must be called 214 * After changing the state of a button, this function must be called
214 * to make sure that all gates and other buttons connected to the 215 * to make sure that all gates and other buttons connected to the
215 * button reacts to the (eventual) change of state. 216 * button reacts to the (eventual) change of state.
216 */ 217 */
217void 218void
218update_button (object *op) 219update_button (object *op, object *originator)
219{ 220{
220 int any_down = 0, old_value = op->value; 221 int any_down = 0, old_value = op->value;
221 oblinkpt *obp = 0;
222 objectlink *ol;
223 222
224 obp = get_button_links (op); 223 if (oblinkpt *obp = op->find_link ())
225 if (obp)
226 for (ol = obp->link; ol; ol = ol->next) 224 for (objectlink *ol = obp->link; ol; ol = ol->next)
227 { 225 {
228 if (!ol->ob) 226 if (!ol->ob)
229 { 227 {
230 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); 228 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name);
231 continue; 229 continue;
251 249
252 any_down = any_down || tmp->value; 250 any_down = any_down || tmp->value;
253 } 251 }
254 else if (tmp->type == PEDESTAL) 252 else if (tmp->type == PEDESTAL)
255 { 253 {
254 bool is_match = is_match_expr (tmp->slaying);
256 tmp->value = 0; 255 tmp->value = 0;
257 256
258 for (object *ab = tmp->above; ab; ab = ab->above) 257 for (object *ab = tmp->above; ab; ab = ab->above)
259 { 258 {
260 object *head = ab->head_ (); 259 object *head = ab->head_ ();
261 260
262 /* Same note regarding move_type for buttons above apply here. */ 261 /* Same note regarding move_type for buttons above apply here. */
263 if (((ab->move_type & tmp->move_on) || ab->move_type == 0) 262 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
263 if (is_match
264 ? match (tmp->slaying, head, tmp, originator)
264 && (head->race == tmp->slaying 265 : (head->race == tmp->slaying
265 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) 266 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
266 || (tmp->slaying == shstr_player && head->type == PLAYER))) 267 || (tmp->slaying == shstr_player && head->type == PLAYER)))
268 {
267 tmp->value = 1; 269 tmp->value = 1;
270 break;
271 }
272 }
273
274 any_down = any_down || tmp->value;
275 }
276 else if (tmp->type == T_MATCH)
277 {
278 tmp->value = 0;
279
280 for (object *ab = tmp->above; ab; ab = ab->above)
281 {
282 object *head = ab->head_ ();
283
284 /* Same note regarding move_type for buttons above apply here. */
285 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
286 if (match (tmp->slaying, head, tmp, originator))
287 {
288 tmp->value = 1;
289 break;
290 }
268 } 291 }
269 292
270 any_down = any_down || tmp->value; 293 any_down = any_down || tmp->value;
271 } 294 }
272 } 295 }
279 /* If this button hasn't changed, don't do anything */ 302 /* If this button hasn't changed, don't do anything */
280 if (op->value != old_value) 303 if (op->value != old_value)
281 { 304 {
282 SET_ANIMATION (op, op->value); 305 SET_ANIMATION (op, op->value);
283 update_object (op, UP_OBJ_FACE); 306 update_object (op, UP_OBJ_FACE);
284 push_button (op); /* Make all other buttons the same */ 307 push_button (op, originator); /* Make all other buttons the same */
285 } 308 }
286} 309}
287 310
288void 311void
289use_trigger (object *op) 312use_trigger (object *op, object *originator)
290{ 313{
291 /* Toggle value */ 314 /* Toggle value */
292 op->value = !op->value; 315 op->value = !op->value;
316
293 push_button (op); 317 push_button (op, originator);
294} 318}
295 319
296/* 320/*
297 * Note: animate_object should be used instead of this, 321 * Note: animate_object should be used instead of this,
298 * but it can't handle animations in the 8 directions 322 * but it can't handle animations in the 8 directions
319 * sacrificed. This fixes a bug of trying to put multiple altars/related 343 * sacrificed. This fixes a bug of trying to put multiple altars/related
320 * objects on the same space that take the same sacrifice. 344 * objects on the same space that take the same sacrifice.
321 */ 345 */
322 346
323int 347int
324check_altar_sacrifice (const object *altar, const object *sacrifice) 348check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
325{ 349{
350 if (sacrifice->flag [FLAG_UNPAID])
351 return 0;
352
353 if (is_match_expr (ARCH_SACRIFICE (altar)))
354 return match (ARCH_SACRIFICE (altar), altar, originator);
355
326 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 356 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE)
327 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 357 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
328 && sacrifice->type != PLAYER) 358 && sacrifice->type != PLAYER)
329 { 359 {
330 if (ARCH_SACRIFICE (altar) == shstr_money 360 if (ARCH_SACRIFICE (altar) == shstr_money
351 * 381 *
352 * If this function returns 1, '*sacrifice' is modified to point to the 382 * If this function returns 1, '*sacrifice' is modified to point to the
353 * remaining sacrifice, or is set to NULL if the sacrifice was used up. 383 * remaining sacrifice, or is set to NULL if the sacrifice was used up.
354 */ 384 */
355int 385int
356operate_altar (object *altar, object **sacrifice) 386operate_altar (object *altar, object **sacrifice, object *originator)
357{ 387{
358 if (!altar->map) 388 if (!altar->map)
359 { 389 {
360 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 390 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
361 return 0; 391 return 0;
362 } 392 }
363 393
364 if (!altar->slaying || altar->value) 394 if (!altar->slaying || altar->value)
365 return 0; 395 return 0;
366 396
367 if (!check_altar_sacrifice (altar, *sacrifice)) 397 if (!check_altar_sacrifice (altar, *sacrifice, originator))
368 return 0; 398 return 0;
369 399
370 /* check_altar_sacrifice should have already verified that enough money 400 /* check_altar_sacrifice should have already verified that enough money
371 * has been dropped. 401 * has been dropped.
372 */ 402 */
390 420
391 return 1; 421 return 1;
392} 422}
393 423
394void 424void
395trigger_move (object *op, int state) /* 1 down and 0 up */ 425trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
396{ 426{
397 op->stats.wc = state; 427 op->stats.wc = state;
428
398 if (state) 429 if (state)
399 { 430 {
400 use_trigger (op); 431 use_trigger (op, originator);
401 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); 432 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.);
402 op->speed_left = -1; 433 op->speed_left = -1;
403 } 434 }
404 else 435 else
405 { 436 {
406 use_trigger (op); 437 use_trigger (op, originator);
407 op->set_speed (0); 438 op->set_speed (0);
408 } 439 }
409} 440}
410 441
411 442
420 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 451 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
421 * 452 *
422 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 453 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
423 */ 454 */
424int 455int
425check_trigger (object *op, object *cause) 456check_trigger (object *op, object *cause, object *originator)
426{ 457{
427 object *tmp; 458 object *tmp;
428 int push = 0, tot = 0; 459 int push = 0, tot = 0;
429 int in_movement = op->stats.wc || op->speed; 460 int in_movement = op->stats.wc || op->speed;
430 461
460 } 491 }
461 492
462 if (in_movement || !push) 493 if (in_movement || !push)
463 return 0; 494 return 0;
464 } 495 }
496
465 trigger_move (op, push); 497 trigger_move (op, push, cause);
466 } 498 }
467 499
468 return 0; 500 return 0;
469 501
470 case TRIGGER_PEDESTAL: 502 case TRIGGER_PEDESTAL:
498 530
499 if (in_movement || !push) 531 if (in_movement || !push)
500 return 0; 532 return 0;
501 } 533 }
502 534
503 trigger_move (op, push); 535 trigger_move (op, push, cause);
504 return 0; 536 return 0;
505 537
506 case TRIGGER_ALTAR: 538 case TRIGGER_ALTAR:
507 if (cause) 539 if (cause)
508 { 540 {
509 if (in_movement) 541 if (in_movement)
510 return 0; 542 return 0;
511 543
512 if (operate_altar (op, &cause)) 544 if (operate_altar (op, &cause)) /* TODO: originator? */
513 { 545 {
514 if (NUM_ANIMATIONS (op) > 1) 546 if (NUM_ANIMATIONS (op) > 1)
515 { 547 {
516 SET_ANIMATION (op, 1); 548 SET_ANIMATION (op, 1);
517 update_object (op, UP_OBJ_FACE); 549 update_object (op, UP_OBJ_FACE);
518 } 550 }
519 551
520 if (op->last_sp >= 0) 552 if (op->last_sp >= 0)
521 { 553 {
522 trigger_move (op, 1); 554 trigger_move (op, 1, cause);
555
523 if (op->last_sp > 0) 556 if (op->last_sp > 0)
524 op->last_sp = -op->last_sp; 557 op->last_sp = -op->last_sp;
525 } 558 }
526 else 559 else
527 { 560 {
528 /* for trigger altar with last_sp, the ON/OFF 561 /* for trigger altar with last_sp, the ON/OFF
529 * status (-> +/- value) is "simulated": 562 * status (-> +/- value) is "simulated":
530 */ 563 */
531 op->value = !op->value; 564 op->value = !op->value;
532 trigger_move (op, 1); 565 trigger_move (op, 1, cause);
533 op->last_sp = -op->last_sp; 566 op->last_sp = -op->last_sp;
534 op->value = !op->value; 567 op->value = !op->value;
535 } 568 }
536 569
537 return cause == NULL; 570 return cause == NULL;
551 * it will push the connected value only once per sacrifice. 584 * it will push the connected value only once per sacrifice.
552 * Otherwise (default), the connected value will be 585 * Otherwise (default), the connected value will be
553 * pushed twice: First by sacrifice, second by reset! -AV 586 * pushed twice: First by sacrifice, second by reset! -AV
554 */ 587 */
555 if (!op->last_sp) 588 if (!op->last_sp)
556 trigger_move (op, 0); 589 trigger_move (op, 0, cause);
557 else 590 else
558 { 591 {
559 op->stats.wc = 0; 592 op->stats.wc = 0;
560 op->value = !op->value; 593 op->value = !op->value;
561 op->set_speed (0); 594 op->set_speed (0);
576 { 609 {
577 SET_ANIMATION (op, push); 610 SET_ANIMATION (op, push);
578 update_object (op, UP_OBJ_FACE); 611 update_object (op, UP_OBJ_FACE);
579 } 612 }
580 613
581 trigger_move (op, push); 614 trigger_move (op, push, cause);
582 return 1; 615 return 1;
583 616
584 default: 617 default:
585 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 618 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
586 return 0; 619 return 0;
587 } 620 }
588} 621}
589 622
590void 623void
591add_button_link (object *button, maptile *map, int connected) 624object::add_link (maptile *map, shstr_tmp id)
592{ 625{
593 oblinkpt *obp;
594 objectlink *ol = get_objectlink ();
595
596 if (!map) 626 if (!map)
597 { 627 {
598 LOG (llevError, "Tried to add button-link without map.\n"); 628 LOG (llevError, "Tried to add button-link without map.\n");
599 return; 629 return;
600 } 630 }
601 631
602 button->path_attuned = connected; /* peterm: I need this so I can rebuild 632 flag [FLAG_IS_LINKED] = true;
603 a connected map from a template map. */
604 633
605 SET_FLAG (button, FLAG_IS_LINKED); 634 objectlink *ol = get_objectlink ();
606
607 ol->ob = button; 635 ol->ob = this;
608 636
609 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) 637 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
610 ; 638 if (obp->id == id)
611
612 if (obp)
613 { 639 {
614 ol->next = obp->link; 640 ol->next = obp->link;
615 obp->link = ol; 641 obp->link = ol;
642 return;
616 } 643 }
617 else 644
618 {
619 obp = get_objectlinkpt (); 645 oblinkpt *obp = get_objectlinkpt ();
620 obp->value = connected; 646 obp->id = id;
621 647
622 obp->next = map->buttons; 648 obp->next = map->buttons;
623 map->buttons = obp; 649 map->buttons = obp;
624 obp->link = ol; 650 obp->link = ol;
625 }
626} 651}
627 652
628/* 653/*
629 * Remove the object from the linked lists of buttons in the map. 654 * Remove the object from the linked lists of buttons in the map.
630 * This is only needed by editors. 655 * This is only needed by editors.
631 */ 656 */
632
633void 657void
634remove_button_link (object *op) 658object::remove_link ()
635{ 659{
636 oblinkpt *obp; 660 if (!map)
637 objectlink **olp, *ol;
638
639 if (op->map == NULL)
640 { 661 {
641 LOG (llevError, "remove_button_link() in object without map.\n"); 662 LOG (llevError, "remove_button_link() in object without map.\n");
642 return; 663 return;
643 } 664 }
644 665
645 if (!QUERY_FLAG (op, FLAG_IS_LINKED)) 666 if (!flag [FLAG_IS_LINKED])
646 { 667 {
647 LOG (llevError, "remove_button_linked() in unlinked object.\n"); 668 LOG (llevError, "remove_button_linked() in unlinked object.\n");
648 return; 669 return;
649 } 670 }
650 671
672 flag [FLAG_IS_LINKED] = false;
673
651 for (obp = op->map->buttons; obp; obp = obp->next) 674 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
652 for (olp = &obp->link; (ol = *olp); olp = &ol->next) 675 for (objectlink **olp = &obp->link; *olp; olp = &(*olp)->next)
653 if (ol->ob == op) 676 if ((*olp)->ob == this)
654 { 677 {
655 678 objectlink *ol = *olp;
656/* LOG(llevDebug, "Removed link %d in button %s and map %s.\n",
657 obp->value, op->name, op->map->path);
658*/
659 *olp = ol->next; 679 *olp = ol->next;
660 delete ol; 680 delete ol;
661 return; 681 return;
662 } 682 }
663 683
664 LOG (llevError, "remove_button_linked(): couldn't find object.\n"); 684 LOG (llevError, "remove_button_linked(): couldn't find object.\n");
665 CLEAR_FLAG (op, FLAG_IS_LINKED); 685}
686
687/*
688 * Updates every button on the map (by calling update_button() for them).
689 */
690void
691maptile::update_buttons ()
692{
693 for (oblinkpt *obp = buttons; obp; obp = obp->next)
694 for (objectlink *ol = obp->link; ol; ol = ol->next)
695 {
696 if (!ol->ob)
697 {
698 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
699 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, &obp->id);
700 continue;
701 }
702
703 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
704 {
705 update_button (ol->ob, 0);
706 break;
707 }
708 }
666} 709}
667 710
668/* 711/*
669 * Gets the objectlink for this connection from the map. 712 * Gets the objectlink for this connection from the map.
670 */ 713 */
671oblinkpt * 714oblinkpt *
672get_connection_links (maptile *map, long connection) 715maptile::find_link (shstr_tmp id)
673{ 716{
674 for (oblinkpt * obp = map->buttons; obp; obp = obp->next) 717 for (oblinkpt *obp = buttons; obp; obp = obp->next)
675 if (obp->value == connection) 718 if (obp->id == id)
676 return obp; 719 return obp;
677 720
678 return 0; 721 return 0;
679} 722}
680 723
681/* 724/*
682 * Return the first objectlink in the objects linked to this one 725 * Return the first objectlink in the objects linked to this one
683 */ 726 */
684
685oblinkpt * 727oblinkpt *
686get_button_links (const object *button) 728object::find_link () const
687{ 729{
688 oblinkpt *obp; 730 if (map)
689 objectlink *ol;
690
691 if (!button->map)
692 return NULL;
693
694 for (obp = button->map->buttons; obp; obp = obp->next) 731 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
695 for (ol = obp->link; ol; ol = ol->next) 732 for (objectlink *ol = obp->link; ol; ol = ol->next)
696 if (ol->ob == button) 733 if (ol->ob == this)
697 return obp; 734 return obp;
698 735
699 return NULL;
700}
701
702/*
703 * Made as a separate function to increase efficiency
704 */
705
706int
707get_button_value (const object *button)
708{
709 oblinkpt *obp;
710 objectlink *ol;
711
712 if (!button->map)
713 return 0;
714 for (obp = button->map->buttons; obp; obp = obp->next)
715 for (ol = obp->link; ol; ol = ol->next)
716 if (ol->ob == button)
717 return obp->value;
718 return 0; 736 return 0;
719} 737}
720 738
721/* This routine makes monsters who are 739/* This routine makes monsters who are
722 * standing on the 'mood floor' change their 740 * standing on the 'mood floor' change their
724 * If floor is to be triggered must have 742 * If floor is to be triggered must have
725 * a speed of zero (default is 1 for all 743 * a speed of zero (default is 1 for all
726 * but the charm floor type). 744 * but the charm floor type).
727 * by b.t. thomas@nomad.astro.psu.edu 745 * by b.t. thomas@nomad.astro.psu.edu
728 */ 746 */
729
730void 747void
731do_mood_floor (object *op, object *source) 748do_mood_floor (object *op, object *source)
732{ 749{
733 if (!source) 750 if (!source)
734 source = op; 751 source = op;
898 { 915 {
899 if (trig->last_heal) 916 if (trig->last_heal)
900 match->decrease (); 917 match->decrease ();
901 918
902 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 919 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
903 push_button (trig); 920 push_button (trig, op);
904 } 921 }
905 else if (!match && !trig->last_sp) // match == not having 922 else if (!match && !trig->last_sp) // match == not having
906 { 923 {
907 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 924 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
908 push_button (trig); 925 push_button (trig, op);
909 } 926 }
910} 927}
911 928

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines