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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 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 |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
29 | |
29 | |
30 | /* |
30 | /* |
31 | * elmex: |
31 | * elmex: |
32 | * This function takes a objectlink list with all the objects are going to be activated. |
32 | * 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. |
33 | * 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. |
34 | * The activator argument can be 0 or the source object for this activation. |
|
|
35 | * the originator is the player or monster who did something. |
35 | */ |
36 | */ |
36 | void |
37 | static void |
37 | activate_connection_link (objectlink * ol, bool state, object *source = 0) |
38 | activate_connection_link (objectlink *ol, int state, object *activator, object *originator) |
38 | { |
39 | { |
39 | for (; ol; ol = ol->next) |
40 | for (; ol; ol = ol->next) |
40 | { |
41 | { |
41 | if (!ol->ob) |
42 | if (!ol->ob) |
42 | { |
43 | { |
… | |
… | |
105 | SET_ANIMATION (tmp, tmp->value); |
106 | SET_ANIMATION (tmp, tmp->value); |
106 | update_object (tmp, UP_OBJ_FACE); |
107 | update_object (tmp, UP_OBJ_FACE); |
107 | break; |
108 | break; |
108 | |
109 | |
109 | case MOOD_FLOOR: |
110 | case MOOD_FLOOR: |
110 | do_mood_floor (tmp, source); |
111 | do_mood_floor (tmp, activator); |
111 | break; |
112 | break; |
112 | |
113 | |
113 | case TIMED_GATE: |
114 | case TIMED_GATE: |
114 | if (!tmp->active) |
115 | if (!tmp->active) |
115 | tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); |
116 | tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); |
|
|
117 | |
116 | tmp->set_speed (tmp->arch->speed); |
118 | tmp->set_speed (tmp->arch->speed); |
117 | tmp->value = tmp->arch->value; |
119 | tmp->value = tmp->arch->value; |
118 | tmp->stats.sp = 1; |
120 | tmp->stats.sp = 1; |
119 | tmp->stats.hp = tmp->stats.maxhp; |
121 | tmp->stats.hp = tmp->stats.maxhp; |
120 | /* Handle multipart gates. We copy the value for the other parts |
122 | /* Handle multipart gates. We copy the value for the other parts |
… | |
… | |
133 | case FIREWALL: |
135 | case FIREWALL: |
134 | if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) |
136 | if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) |
135 | move_firewall (tmp); |
137 | move_firewall (tmp); |
136 | else |
138 | else |
137 | { |
139 | { |
138 | if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ |
140 | 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); |
141 | animate_turning (tmp); |
142 | } |
142 | } |
143 | break; |
143 | break; |
144 | |
144 | |
145 | case TELEPORTER: |
145 | case TELEPORTER: |
… | |
… | |
155 | move_marker (tmp); |
155 | move_marker (tmp); |
156 | break; |
156 | break; |
157 | |
157 | |
158 | case DUPLICATOR: |
158 | case DUPLICATOR: |
159 | move_duplicator (tmp); |
159 | move_duplicator (tmp); |
|
|
160 | break; |
|
|
161 | |
|
|
162 | case MAPSCRIPT: |
|
|
163 | cfperl_mapscript_activate (tmp, state, activator, originator); |
160 | break; |
164 | break; |
161 | } |
165 | } |
162 | } |
166 | } |
163 | } |
167 | } |
164 | |
168 | |
… | |
… | |
173 | * Changed the routine to loop through _all_ objects. |
177 | * Changed the routine to loop through _all_ objects. |
174 | * Better hurry with that linked list... |
178 | * Better hurry with that linked list... |
175 | * |
179 | * |
176 | */ |
180 | */ |
177 | void |
181 | void |
178 | push_button (object *op) |
182 | push_button (object *op, object *originator) |
179 | { |
183 | { |
180 | oblinkpt *obp = get_button_links (op); |
184 | if (oblinkpt *obp = op->find_link ()) |
181 | |
185 | { |
182 | if (!obp) |
186 | if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator))) |
183 | return; |
187 | return; |
184 | |
188 | |
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); |
189 | activate_connection_link (obp->link, op->value, op, originator); |
|
|
190 | } |
189 | } |
191 | } |
190 | |
192 | |
191 | /* |
193 | /* |
192 | * elmex: |
194 | * elmex: |
193 | * This activates a connection, similar to push_button (object *op) but it takes |
195 | * 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 |
197 | * the connection was 'state' or 'released'. So that you can activate objects |
196 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
198 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
197 | * |
199 | * |
198 | */ |
200 | */ |
199 | void |
201 | void |
200 | activate_connection (maptile *map, long connection, bool state) |
202 | maptile::trigger (shstr_tmp id, int state, object *activator, object *originator) |
201 | { |
203 | { |
202 | if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) |
204 | if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator))) |
203 | return; |
205 | return; |
204 | |
206 | |
205 | oblinkpt *obp = get_connection_links (map, connection); |
207 | if (oblinkpt *obp = find_link (id)) |
206 | |
|
|
207 | if (obp) |
|
|
208 | activate_connection_link (obp->link, state); |
208 | activate_connection_link (obp->link, state, activator, originator); |
209 | } |
209 | } |
210 | |
210 | |
211 | /* |
211 | /* |
212 | * Updates everything connected with the button op. |
212 | * Updates everything connected with the button op. |
213 | * After changing the state of a button, this function must be called |
213 | * 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 |
214 | * to make sure that all gates and other buttons connected to the |
215 | * button reacts to the (eventual) change of state. |
215 | * button reacts to the (eventual) change of state. |
216 | */ |
216 | */ |
217 | void |
217 | void |
218 | update_button (object *op) |
218 | update_button (object *op, object *originator) |
219 | { |
219 | { |
220 | int any_down = 0, old_value = op->value; |
220 | int any_down = 0, old_value = op->value; |
221 | oblinkpt *obp = 0; |
|
|
222 | objectlink *ol; |
|
|
223 | |
221 | |
224 | obp = get_button_links (op); |
222 | if (oblinkpt *obp = op->find_link ()) |
225 | if (obp) |
|
|
226 | for (ol = obp->link; ol; ol = ol->next) |
223 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
227 | { |
224 | { |
228 | if (!ol->ob) |
225 | if (!ol->ob) |
229 | { |
226 | { |
230 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
227 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
231 | continue; |
228 | continue; |
… | |
… | |
279 | /* If this button hasn't changed, don't do anything */ |
276 | /* If this button hasn't changed, don't do anything */ |
280 | if (op->value != old_value) |
277 | if (op->value != old_value) |
281 | { |
278 | { |
282 | SET_ANIMATION (op, op->value); |
279 | SET_ANIMATION (op, op->value); |
283 | update_object (op, UP_OBJ_FACE); |
280 | update_object (op, UP_OBJ_FACE); |
284 | push_button (op); /* Make all other buttons the same */ |
281 | push_button (op, originator); /* Make all other buttons the same */ |
285 | } |
282 | } |
286 | } |
283 | } |
287 | |
284 | |
288 | void |
285 | void |
289 | use_trigger (object *op) |
286 | use_trigger (object *op, object *originator) |
290 | { |
287 | { |
291 | /* Toggle value */ |
288 | /* Toggle value */ |
292 | op->value = !op->value; |
289 | op->value = !op->value; |
|
|
290 | |
293 | push_button (op); |
291 | push_button (op, originator); |
294 | } |
292 | } |
295 | |
293 | |
296 | /* |
294 | /* |
297 | * Note: animate_object should be used instead of this, |
295 | * Note: animate_object should be used instead of this, |
298 | * but it can't handle animations in the 8 directions |
296 | * but it can't handle animations in the 8 directions |
… | |
… | |
319 | * sacrificed. This fixes a bug of trying to put multiple altars/related |
317 | * sacrificed. This fixes a bug of trying to put multiple altars/related |
320 | * objects on the same space that take the same sacrifice. |
318 | * objects on the same space that take the same sacrifice. |
321 | */ |
319 | */ |
322 | |
320 | |
323 | int |
321 | int |
324 | check_altar_sacrifice (const object *altar, const object *sacrifice) |
322 | check_altar_sacrifice (object *altar, object *sacrifice, object *originator) |
325 | { |
323 | { |
|
|
324 | if (sacrifice->flag [FLAG_UNPAID]) |
|
|
325 | return 0; |
|
|
326 | |
|
|
327 | if (is_match_expr (ARCH_SACRIFICE (altar))) |
|
|
328 | return match (ARCH_SACRIFICE (altar), altar, originator); |
|
|
329 | |
326 | if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) |
330 | if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) |
327 | && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) |
331 | && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) |
328 | && sacrifice->type != PLAYER) |
332 | && sacrifice->type != PLAYER) |
329 | { |
333 | { |
330 | if (ARCH_SACRIFICE (altar) == shstr_money |
334 | if (ARCH_SACRIFICE (altar) == shstr_money |
… | |
… | |
351 | * |
355 | * |
352 | * If this function returns 1, '*sacrifice' is modified to point to the |
356 | * 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. |
357 | * remaining sacrifice, or is set to NULL if the sacrifice was used up. |
354 | */ |
358 | */ |
355 | int |
359 | int |
356 | operate_altar (object *altar, object **sacrifice) |
360 | operate_altar (object *altar, object **sacrifice, object *originator) |
357 | { |
361 | { |
358 | if (!altar->map) |
362 | if (!altar->map) |
359 | { |
363 | { |
360 | LOG (llevError, "BUG: operate_altar(): altar has no map\n"); |
364 | LOG (llevError, "BUG: operate_altar(): altar has no map\n"); |
361 | return 0; |
365 | return 0; |
362 | } |
366 | } |
363 | |
367 | |
364 | if (!altar->slaying || altar->value) |
368 | if (!altar->slaying || altar->value) |
365 | return 0; |
369 | return 0; |
366 | |
370 | |
367 | if (!check_altar_sacrifice (altar, *sacrifice)) |
371 | if (!check_altar_sacrifice (altar, *sacrifice, originator)) |
368 | return 0; |
372 | return 0; |
369 | |
373 | |
370 | /* check_altar_sacrifice should have already verified that enough money |
374 | /* check_altar_sacrifice should have already verified that enough money |
371 | * has been dropped. |
375 | * has been dropped. |
372 | */ |
376 | */ |
… | |
… | |
390 | |
394 | |
391 | return 1; |
395 | return 1; |
392 | } |
396 | } |
393 | |
397 | |
394 | void |
398 | void |
395 | trigger_move (object *op, int state) /* 1 down and 0 up */ |
399 | trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */ |
396 | { |
400 | { |
397 | op->stats.wc = state; |
401 | op->stats.wc = state; |
|
|
402 | |
398 | if (state) |
403 | if (state) |
399 | { |
404 | { |
400 | use_trigger (op); |
405 | use_trigger (op, originator); |
401 | op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); |
406 | op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); |
402 | op->speed_left = -1; |
407 | op->speed_left = -1; |
403 | } |
408 | } |
404 | else |
409 | else |
405 | { |
410 | { |
406 | use_trigger (op); |
411 | use_trigger (op, originator); |
407 | op->set_speed (0); |
412 | op->set_speed (0); |
408 | } |
413 | } |
409 | } |
414 | } |
410 | |
415 | |
411 | |
416 | |
… | |
… | |
420 | * TRIGGER: Returns 1 if handle could be moved, 0 if not. |
425 | * TRIGGER: Returns 1 if handle could be moved, 0 if not. |
421 | * |
426 | * |
422 | * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. |
427 | * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. |
423 | */ |
428 | */ |
424 | int |
429 | int |
425 | check_trigger (object *op, object *cause) |
430 | check_trigger (object *op, object *cause, object *originator) |
426 | { |
431 | { |
427 | object *tmp; |
432 | object *tmp; |
428 | int push = 0, tot = 0; |
433 | int push = 0, tot = 0; |
429 | int in_movement = op->stats.wc || op->speed; |
434 | int in_movement = op->stats.wc || op->speed; |
430 | |
435 | |
… | |
… | |
460 | } |
465 | } |
461 | |
466 | |
462 | if (in_movement || !push) |
467 | if (in_movement || !push) |
463 | return 0; |
468 | return 0; |
464 | } |
469 | } |
|
|
470 | |
465 | trigger_move (op, push); |
471 | trigger_move (op, push, cause); |
466 | } |
472 | } |
467 | |
473 | |
468 | return 0; |
474 | return 0; |
469 | |
475 | |
470 | case TRIGGER_PEDESTAL: |
476 | case TRIGGER_PEDESTAL: |
… | |
… | |
474 | { |
480 | { |
475 | object *head = tmp->head_ (); |
481 | object *head = tmp->head_ (); |
476 | |
482 | |
477 | /* See comment in TRIGGER_BUTTON about move_types */ |
483 | /* See comment in TRIGGER_BUTTON about move_types */ |
478 | if (((head->move_type & op->move_on) || head->move_type == 0) |
484 | if (((head->move_type & op->move_on) || head->move_type == 0) |
479 | && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) |
485 | && (head->race == op->slaying || (op->slaying == shstr_player && head->type == PLAYER))) |
480 | { |
486 | { |
481 | push = 1; |
487 | push = 1; |
482 | break; |
488 | break; |
483 | } |
489 | } |
484 | } |
490 | } |
… | |
… | |
498 | |
504 | |
499 | if (in_movement || !push) |
505 | if (in_movement || !push) |
500 | return 0; |
506 | return 0; |
501 | } |
507 | } |
502 | |
508 | |
503 | trigger_move (op, push); |
509 | trigger_move (op, push, cause); |
504 | return 0; |
510 | return 0; |
505 | |
511 | |
506 | case TRIGGER_ALTAR: |
512 | case TRIGGER_ALTAR: |
507 | if (cause) |
513 | if (cause) |
508 | { |
514 | { |
509 | if (in_movement) |
515 | if (in_movement) |
510 | return 0; |
516 | return 0; |
511 | |
517 | |
512 | if (operate_altar (op, &cause)) |
518 | if (operate_altar (op, &cause)) /* TODO: originator? */ |
513 | { |
519 | { |
514 | if (NUM_ANIMATIONS (op) > 1) |
520 | if (NUM_ANIMATIONS (op) > 1) |
515 | { |
521 | { |
516 | SET_ANIMATION (op, 1); |
522 | SET_ANIMATION (op, 1); |
517 | update_object (op, UP_OBJ_FACE); |
523 | update_object (op, UP_OBJ_FACE); |
518 | } |
524 | } |
519 | |
525 | |
520 | if (op->last_sp >= 0) |
526 | if (op->last_sp >= 0) |
521 | { |
527 | { |
522 | trigger_move (op, 1); |
528 | trigger_move (op, 1, cause); |
|
|
529 | |
523 | if (op->last_sp > 0) |
530 | if (op->last_sp > 0) |
524 | op->last_sp = -op->last_sp; |
531 | op->last_sp = -op->last_sp; |
525 | } |
532 | } |
526 | else |
533 | else |
527 | { |
534 | { |
528 | /* for trigger altar with last_sp, the ON/OFF |
535 | /* for trigger altar with last_sp, the ON/OFF |
529 | * status (-> +/- value) is "simulated": |
536 | * status (-> +/- value) is "simulated": |
530 | */ |
537 | */ |
531 | op->value = !op->value; |
538 | op->value = !op->value; |
532 | trigger_move (op, 1); |
539 | trigger_move (op, 1, cause); |
533 | op->last_sp = -op->last_sp; |
540 | op->last_sp = -op->last_sp; |
534 | op->value = !op->value; |
541 | op->value = !op->value; |
535 | } |
542 | } |
536 | |
543 | |
537 | return cause == NULL; |
544 | return cause == NULL; |
… | |
… | |
551 | * it will push the connected value only once per sacrifice. |
558 | * it will push the connected value only once per sacrifice. |
552 | * Otherwise (default), the connected value will be |
559 | * Otherwise (default), the connected value will be |
553 | * pushed twice: First by sacrifice, second by reset! -AV |
560 | * pushed twice: First by sacrifice, second by reset! -AV |
554 | */ |
561 | */ |
555 | if (!op->last_sp) |
562 | if (!op->last_sp) |
556 | trigger_move (op, 0); |
563 | trigger_move (op, 0, cause); |
557 | else |
564 | else |
558 | { |
565 | { |
559 | op->stats.wc = 0; |
566 | op->stats.wc = 0; |
560 | op->value = !op->value; |
567 | op->value = !op->value; |
561 | op->set_speed (0); |
568 | op->set_speed (0); |
… | |
… | |
576 | { |
583 | { |
577 | SET_ANIMATION (op, push); |
584 | SET_ANIMATION (op, push); |
578 | update_object (op, UP_OBJ_FACE); |
585 | update_object (op, UP_OBJ_FACE); |
579 | } |
586 | } |
580 | |
587 | |
581 | trigger_move (op, push); |
588 | trigger_move (op, push, cause); |
582 | return 1; |
589 | return 1; |
583 | |
590 | |
584 | default: |
591 | default: |
585 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
592 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
586 | return 0; |
593 | return 0; |
587 | } |
594 | } |
588 | } |
595 | } |
589 | |
596 | |
590 | void |
597 | void |
591 | add_button_link (object *button, maptile *map, int connected) |
598 | object::add_link (maptile *map, shstr_tmp id) |
592 | { |
599 | { |
593 | oblinkpt *obp; |
|
|
594 | objectlink *ol = get_objectlink (); |
|
|
595 | |
|
|
596 | if (!map) |
600 | if (!map) |
597 | { |
601 | { |
598 | LOG (llevError, "Tried to add button-link without map.\n"); |
602 | LOG (llevError, "Tried to add button-link without map.\n"); |
599 | return; |
603 | return; |
600 | } |
604 | } |
601 | |
605 | |
602 | button->path_attuned = connected; /* peterm: I need this so I can rebuild |
606 | flag [FLAG_IS_LINKED] = true; |
603 | a connected map from a template map. */ |
|
|
604 | |
607 | |
605 | SET_FLAG (button, FLAG_IS_LINKED); |
608 | objectlink *ol = get_objectlink (); |
606 | |
|
|
607 | ol->ob = button; |
609 | ol->ob = this; |
608 | |
610 | |
609 | for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) |
611 | for (oblinkpt *obp = map->buttons; obp; obp = obp->next) |
610 | ; |
612 | if (obp->id == id) |
611 | |
|
|
612 | if (obp) |
|
|
613 | { |
613 | { |
614 | ol->next = obp->link; |
614 | ol->next = obp->link; |
615 | obp->link = ol; |
615 | obp->link = ol; |
|
|
616 | return; |
616 | } |
617 | } |
617 | else |
618 | |
618 | { |
|
|
619 | obp = get_objectlinkpt (); |
619 | oblinkpt *obp = get_objectlinkpt (); |
620 | obp->value = connected; |
620 | obp->id = id; |
621 | |
621 | |
622 | obp->next = map->buttons; |
622 | obp->next = map->buttons; |
623 | map->buttons = obp; |
623 | map->buttons = obp; |
624 | obp->link = ol; |
624 | obp->link = ol; |
625 | } |
|
|
626 | } |
625 | } |
627 | |
626 | |
628 | /* |
627 | /* |
629 | * Remove the object from the linked lists of buttons in the map. |
628 | * Remove the object from the linked lists of buttons in the map. |
630 | * This is only needed by editors. |
629 | * This is only needed by editors. |
631 | */ |
630 | */ |
632 | |
|
|
633 | void |
631 | void |
634 | remove_button_link (object *op) |
632 | object::remove_link () |
635 | { |
633 | { |
636 | oblinkpt *obp; |
634 | if (!map) |
637 | objectlink **olp, *ol; |
|
|
638 | |
|
|
639 | if (op->map == NULL) |
|
|
640 | { |
635 | { |
641 | LOG (llevError, "remove_button_link() in object without map.\n"); |
636 | LOG (llevError, "remove_button_link() in object without map.\n"); |
642 | return; |
637 | return; |
643 | } |
638 | } |
644 | |
639 | |
645 | if (!QUERY_FLAG (op, FLAG_IS_LINKED)) |
640 | if (!flag [FLAG_IS_LINKED]) |
646 | { |
641 | { |
647 | LOG (llevError, "remove_button_linked() in unlinked object.\n"); |
642 | LOG (llevError, "remove_button_linked() in unlinked object.\n"); |
648 | return; |
643 | return; |
649 | } |
644 | } |
650 | |
645 | |
|
|
646 | flag [FLAG_IS_LINKED] = false; |
|
|
647 | |
651 | for (obp = op->map->buttons; obp; obp = obp->next) |
648 | for (oblinkpt *obp = map->buttons; obp; obp = obp->next) |
652 | for (olp = &obp->link; (ol = *olp); olp = &ol->next) |
649 | for (objectlink **olp = &obp->link; *olp; olp = &(*olp)->next) |
653 | if (ol->ob == op) |
650 | if ((*olp)->ob == this) |
654 | { |
651 | { |
655 | |
652 | 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; |
653 | *olp = ol->next; |
660 | delete ol; |
654 | delete ol; |
661 | return; |
655 | return; |
662 | } |
656 | } |
663 | |
657 | |
664 | LOG (llevError, "remove_button_linked(): couldn't find object.\n"); |
658 | LOG (llevError, "remove_button_linked(): couldn't find object.\n"); |
665 | CLEAR_FLAG (op, FLAG_IS_LINKED); |
659 | } |
|
|
660 | |
|
|
661 | /* |
|
|
662 | * Updates every button on the map (by calling update_button() for them). |
|
|
663 | */ |
|
|
664 | void |
|
|
665 | maptile::update_buttons () |
|
|
666 | { |
|
|
667 | for (oblinkpt *obp = buttons; obp; obp = obp->next) |
|
|
668 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
|
|
669 | { |
|
|
670 | if (!ol->ob) |
|
|
671 | { |
|
|
672 | LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", |
|
|
673 | ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, &obp->id); |
|
|
674 | continue; |
|
|
675 | } |
|
|
676 | |
|
|
677 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
|
|
678 | { |
|
|
679 | update_button (ol->ob, 0); |
|
|
680 | break; |
|
|
681 | } |
|
|
682 | } |
666 | } |
683 | } |
667 | |
684 | |
668 | /* |
685 | /* |
669 | * Gets the objectlink for this connection from the map. |
686 | * Gets the objectlink for this connection from the map. |
670 | */ |
687 | */ |
671 | oblinkpt * |
688 | oblinkpt * |
672 | get_connection_links (maptile *map, long connection) |
689 | maptile::find_link (shstr_tmp id) |
673 | { |
690 | { |
674 | for (oblinkpt * obp = map->buttons; obp; obp = obp->next) |
691 | for (oblinkpt *obp = buttons; obp; obp = obp->next) |
675 | if (obp->value == connection) |
692 | if (obp->id == id) |
676 | return obp; |
693 | return obp; |
677 | |
694 | |
678 | return 0; |
695 | return 0; |
679 | } |
696 | } |
680 | |
697 | |
681 | /* |
698 | /* |
682 | * Return the first objectlink in the objects linked to this one |
699 | * Return the first objectlink in the objects linked to this one |
683 | */ |
700 | */ |
684 | |
|
|
685 | oblinkpt * |
701 | oblinkpt * |
686 | get_button_links (const object *button) |
702 | object::find_link () const |
687 | { |
703 | { |
688 | oblinkpt *obp; |
704 | if (map) |
689 | objectlink *ol; |
|
|
690 | |
|
|
691 | if (!button->map) |
|
|
692 | return NULL; |
|
|
693 | |
|
|
694 | for (obp = button->map->buttons; obp; obp = obp->next) |
705 | for (oblinkpt *obp = map->buttons; obp; obp = obp->next) |
695 | for (ol = obp->link; ol; ol = ol->next) |
706 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
696 | if (ol->ob == button) |
707 | if (ol->ob == this) |
697 | return obp; |
708 | return obp; |
698 | |
709 | |
699 | return NULL; |
|
|
700 | } |
|
|
701 | |
|
|
702 | /* |
|
|
703 | * Made as a separate function to increase efficiency |
|
|
704 | */ |
|
|
705 | |
|
|
706 | int |
|
|
707 | get_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; |
710 | return 0; |
719 | } |
711 | } |
720 | |
712 | |
721 | /* This routine makes monsters who are |
713 | /* This routine makes monsters who are |
722 | * standing on the 'mood floor' change their |
714 | * standing on the 'mood floor' change their |
… | |
… | |
724 | * If floor is to be triggered must have |
716 | * If floor is to be triggered must have |
725 | * a speed of zero (default is 1 for all |
717 | * a speed of zero (default is 1 for all |
726 | * but the charm floor type). |
718 | * but the charm floor type). |
727 | * by b.t. thomas@nomad.astro.psu.edu |
719 | * by b.t. thomas@nomad.astro.psu.edu |
728 | */ |
720 | */ |
729 | |
|
|
730 | void |
721 | void |
731 | do_mood_floor (object *op, object *source) |
722 | do_mood_floor (object *op, object *source) |
732 | { |
723 | { |
733 | if (!source) |
724 | if (!source) |
734 | source = op; |
725 | source = op; |
… | |
… | |
898 | { |
889 | { |
899 | if (trig->last_heal) |
890 | if (trig->last_heal) |
900 | match->decrease (); |
891 | match->decrease (); |
901 | |
892 | |
902 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
893 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
903 | push_button (trig); |
894 | push_button (trig, op); |
904 | } |
895 | } |
905 | else if (!match && !trig->last_sp) // match == not having |
896 | else if (!match && !trig->last_sp) // match == not having |
906 | { |
897 | { |
907 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
898 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
908 | push_button (trig); |
899 | push_button (trig, op); |
909 | } |
900 | } |
910 | } |
901 | } |
911 | |
902 | |