… | |
… | |
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, bool 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")); |
… | |
… | |
159 | case DUPLICATOR: |
160 | case DUPLICATOR: |
160 | move_duplicator (tmp); |
161 | move_duplicator (tmp); |
161 | break; |
162 | break; |
162 | |
163 | |
163 | case MAPSCRIPT: |
164 | case MAPSCRIPT: |
164 | cfperl_mapscript_activate (tmp, source, state); |
165 | cfperl_mapscript_activate (tmp, state, activator, originator); |
165 | break; |
166 | break; |
166 | } |
167 | } |
167 | } |
168 | } |
168 | } |
169 | } |
169 | |
170 | |
… | |
… | |
178 | * Changed the routine to loop through _all_ objects. |
179 | * Changed the routine to loop through _all_ objects. |
179 | * Better hurry with that linked list... |
180 | * Better hurry with that linked list... |
180 | * |
181 | * |
181 | */ |
182 | */ |
182 | void |
183 | void |
183 | push_button (object *op) |
184 | push_button (object *op, object *originator) |
184 | { |
185 | { |
185 | if (oblinkpt *obp = op->find_link ()) |
186 | if (oblinkpt *obp = op->find_link ()) |
186 | { |
187 | { |
187 | if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value))) |
188 | if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator))) |
188 | return; |
189 | return; |
189 | |
190 | |
190 | activate_connection_link (obp->link, op->value, op); |
191 | activate_connection_link (obp->link, op->value, op, originator); |
191 | } |
192 | } |
192 | } |
193 | } |
193 | |
194 | |
194 | /* |
195 | /* |
195 | * elmex: |
196 | * elmex: |
… | |
… | |
198 | * the connection was 'state' or 'released'. So that you can activate objects |
199 | * the connection was 'state' or 'released'. So that you can activate objects |
199 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
200 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
200 | * |
201 | * |
201 | */ |
202 | */ |
202 | void |
203 | void |
203 | maptile::trigger (shstr_tmp id, bool state, object *originator) |
204 | maptile::trigger (shstr_tmp id, bool state, object *activator, object *originator) |
204 | { |
205 | { |
205 | if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator))) |
206 | if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator))) |
206 | return; |
207 | return; |
207 | |
208 | |
208 | if (oblinkpt *obp = find_link (id)) |
209 | if (oblinkpt *obp = find_link (id)) |
209 | activate_connection_link (obp->link, state, originator); |
210 | activate_connection_link (obp->link, state, activator, originator); |
210 | } |
211 | } |
211 | |
212 | |
212 | /* |
213 | /* |
213 | * Updates everything connected with the button op. |
214 | * Updates everything connected with the button op. |
214 | * After changing the state of a button, this function must be called |
215 | * After changing the state of a button, this function must be called |
215 | * to make sure that all gates and other buttons connected to the |
216 | * to make sure that all gates and other buttons connected to the |
216 | * button reacts to the (eventual) change of state. |
217 | * button reacts to the (eventual) change of state. |
217 | */ |
218 | */ |
218 | void |
219 | void |
219 | update_button (object *op) |
220 | update_button (object *op, object *originator) |
220 | { |
221 | { |
221 | int any_down = 0, old_value = op->value; |
222 | int any_down = 0, old_value = op->value; |
222 | |
223 | |
223 | if (oblinkpt *obp = op->find_link ()) |
224 | if (oblinkpt *obp = op->find_link ()) |
224 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
225 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
… | |
… | |
277 | /* If this button hasn't changed, don't do anything */ |
278 | /* If this button hasn't changed, don't do anything */ |
278 | if (op->value != old_value) |
279 | if (op->value != old_value) |
279 | { |
280 | { |
280 | SET_ANIMATION (op, op->value); |
281 | SET_ANIMATION (op, op->value); |
281 | update_object (op, UP_OBJ_FACE); |
282 | update_object (op, UP_OBJ_FACE); |
282 | push_button (op); /* Make all other buttons the same */ |
283 | push_button (op, originator); /* Make all other buttons the same */ |
283 | } |
284 | } |
284 | } |
285 | } |
285 | |
286 | |
286 | void |
287 | void |
287 | use_trigger (object *op) |
288 | use_trigger (object *op, object *originator) |
288 | { |
289 | { |
289 | /* Toggle value */ |
290 | /* Toggle value */ |
290 | op->value = !op->value; |
291 | op->value = !op->value; |
|
|
292 | |
291 | push_button (op); |
293 | push_button (op, originator); |
292 | } |
294 | } |
293 | |
295 | |
294 | /* |
296 | /* |
295 | * Note: animate_object should be used instead of this, |
297 | * Note: animate_object should be used instead of this, |
296 | * but it can't handle animations in the 8 directions |
298 | * but it can't handle animations in the 8 directions |
… | |
… | |
388 | |
390 | |
389 | return 1; |
391 | return 1; |
390 | } |
392 | } |
391 | |
393 | |
392 | void |
394 | void |
393 | trigger_move (object *op, int state) /* 1 down and 0 up */ |
395 | trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */ |
394 | { |
396 | { |
395 | op->stats.wc = state; |
397 | op->stats.wc = state; |
|
|
398 | |
396 | if (state) |
399 | if (state) |
397 | { |
400 | { |
398 | use_trigger (op); |
401 | use_trigger (op, originator); |
399 | op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); |
402 | op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); |
400 | op->speed_left = -1; |
403 | op->speed_left = -1; |
401 | } |
404 | } |
402 | else |
405 | else |
403 | { |
406 | { |
404 | use_trigger (op); |
407 | use_trigger (op, originator); |
405 | op->set_speed (0); |
408 | op->set_speed (0); |
406 | } |
409 | } |
407 | } |
410 | } |
408 | |
411 | |
409 | |
412 | |
… | |
… | |
458 | } |
461 | } |
459 | |
462 | |
460 | if (in_movement || !push) |
463 | if (in_movement || !push) |
461 | return 0; |
464 | return 0; |
462 | } |
465 | } |
|
|
466 | |
463 | trigger_move (op, push); |
467 | trigger_move (op, push, cause); |
464 | } |
468 | } |
465 | |
469 | |
466 | return 0; |
470 | return 0; |
467 | |
471 | |
468 | case TRIGGER_PEDESTAL: |
472 | case TRIGGER_PEDESTAL: |
… | |
… | |
496 | |
500 | |
497 | if (in_movement || !push) |
501 | if (in_movement || !push) |
498 | return 0; |
502 | return 0; |
499 | } |
503 | } |
500 | |
504 | |
501 | trigger_move (op, push); |
505 | trigger_move (op, push, cause); |
502 | return 0; |
506 | return 0; |
503 | |
507 | |
504 | case TRIGGER_ALTAR: |
508 | case TRIGGER_ALTAR: |
505 | if (cause) |
509 | if (cause) |
506 | { |
510 | { |
… | |
… | |
515 | update_object (op, UP_OBJ_FACE); |
519 | update_object (op, UP_OBJ_FACE); |
516 | } |
520 | } |
517 | |
521 | |
518 | if (op->last_sp >= 0) |
522 | if (op->last_sp >= 0) |
519 | { |
523 | { |
520 | trigger_move (op, 1); |
524 | trigger_move (op, 1, cause); |
|
|
525 | |
521 | if (op->last_sp > 0) |
526 | if (op->last_sp > 0) |
522 | op->last_sp = -op->last_sp; |
527 | op->last_sp = -op->last_sp; |
523 | } |
528 | } |
524 | else |
529 | else |
525 | { |
530 | { |
526 | /* for trigger altar with last_sp, the ON/OFF |
531 | /* for trigger altar with last_sp, the ON/OFF |
527 | * status (-> +/- value) is "simulated": |
532 | * status (-> +/- value) is "simulated": |
528 | */ |
533 | */ |
529 | op->value = !op->value; |
534 | op->value = !op->value; |
530 | trigger_move (op, 1); |
535 | trigger_move (op, 1, cause); |
531 | op->last_sp = -op->last_sp; |
536 | op->last_sp = -op->last_sp; |
532 | op->value = !op->value; |
537 | op->value = !op->value; |
533 | } |
538 | } |
534 | |
539 | |
535 | return cause == NULL; |
540 | return cause == NULL; |
… | |
… | |
549 | * it will push the connected value only once per sacrifice. |
554 | * it will push the connected value only once per sacrifice. |
550 | * Otherwise (default), the connected value will be |
555 | * Otherwise (default), the connected value will be |
551 | * pushed twice: First by sacrifice, second by reset! -AV |
556 | * pushed twice: First by sacrifice, second by reset! -AV |
552 | */ |
557 | */ |
553 | if (!op->last_sp) |
558 | if (!op->last_sp) |
554 | trigger_move (op, 0); |
559 | trigger_move (op, 0, cause); |
555 | else |
560 | else |
556 | { |
561 | { |
557 | op->stats.wc = 0; |
562 | op->stats.wc = 0; |
558 | op->value = !op->value; |
563 | op->value = !op->value; |
559 | op->set_speed (0); |
564 | op->set_speed (0); |
… | |
… | |
574 | { |
579 | { |
575 | SET_ANIMATION (op, push); |
580 | SET_ANIMATION (op, push); |
576 | update_object (op, UP_OBJ_FACE); |
581 | update_object (op, UP_OBJ_FACE); |
577 | } |
582 | } |
578 | |
583 | |
579 | trigger_move (op, push); |
584 | trigger_move (op, push, cause); |
580 | return 1; |
585 | return 1; |
581 | |
586 | |
582 | default: |
587 | default: |
583 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
588 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
584 | return 0; |
589 | return 0; |
… | |
… | |
665 | continue; |
670 | continue; |
666 | } |
671 | } |
667 | |
672 | |
668 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
673 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
669 | { |
674 | { |
670 | update_button (ol->ob); |
675 | update_button (ol->ob, 0); |
671 | break; |
676 | break; |
672 | } |
677 | } |
673 | } |
678 | } |
674 | } |
679 | } |
675 | |
680 | |
… | |
… | |
880 | { |
885 | { |
881 | if (trig->last_heal) |
886 | if (trig->last_heal) |
882 | match->decrease (); |
887 | match->decrease (); |
883 | |
888 | |
884 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
889 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
885 | push_button (trig); |
890 | push_button (trig, op); |
886 | } |
891 | } |
887 | else if (!match && !trig->last_sp) // match == not having |
892 | else if (!match && !trig->last_sp) // match == not having |
888 | { |
893 | { |
889 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
894 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
890 | push_button (trig); |
895 | push_button (trig, op); |
891 | } |
896 | } |
892 | } |
897 | } |
893 | |
898 | |