1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <funcpoint.h> |
26 | #include <funcpoint.h> |
26 | |
27 | |
27 | /* |
28 | /* |
… | |
… | |
273 | update_object (op, UP_OBJ_FACE); |
274 | update_object (op, UP_OBJ_FACE); |
274 | push_button (op); /* Make all other buttons the same */ |
275 | push_button (op); /* Make all other buttons the same */ |
275 | } |
276 | } |
276 | } |
277 | } |
277 | |
278 | |
278 | /* |
|
|
279 | * Updates every button on the map (by calling update_button() for them). |
|
|
280 | */ |
|
|
281 | |
|
|
282 | void |
|
|
283 | update_buttons (maptile *m) |
|
|
284 | { |
|
|
285 | objectlink *ol; |
|
|
286 | oblinkpt *obp; |
|
|
287 | |
|
|
288 | for (obp = m->buttons; obp; obp = obp->next) |
|
|
289 | for (ol = obp->link; ol; ol = ol->next) |
|
|
290 | { |
|
|
291 | if (!ol->ob) |
|
|
292 | { |
|
|
293 | LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", |
|
|
294 | ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); |
|
|
295 | continue; |
|
|
296 | } |
|
|
297 | |
|
|
298 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
|
|
299 | { |
|
|
300 | update_button (ol->ob); |
|
|
301 | break; |
|
|
302 | } |
|
|
303 | } |
|
|
304 | } |
|
|
305 | |
|
|
306 | void |
279 | void |
307 | use_trigger (object *op) |
280 | use_trigger (object *op) |
308 | { |
281 | { |
309 | |
|
|
310 | /* Toggle value */ |
282 | /* Toggle value */ |
311 | op->value = !op->value; |
283 | op->value = !op->value; |
312 | push_button (op); |
284 | push_button (op); |
313 | } |
285 | } |
314 | |
286 | |
315 | /* |
287 | /* |
316 | * Note: animate_object should be used instead of this, |
288 | * Note: animate_object should be used instead of this, |
317 | * but it can't handle animations in the 8 directions |
289 | * but it can't handle animations in the 8 directions |
318 | */ |
290 | */ |
319 | |
|
|
320 | void |
291 | void |
321 | animate_turning (object *op) /* only one part objects */ |
292 | animate_turning (object *op) /* only one part objects */ |
322 | { |
293 | { |
323 | if (++op->state >= NUM_ANIMATIONS (op) / 8) |
294 | if (++op->state >= NUM_ANIMATIONS (op) / 8) |
324 | op->state = 0; |
295 | op->state = 0; |
… | |
… | |
797 | |
768 | |
798 | tmp->set_owner (tmp2); |
769 | tmp->set_owner (tmp2); |
799 | SET_FLAG (tmp, FLAG_MONSTER); |
770 | SET_FLAG (tmp, FLAG_MONSTER); |
800 | |
771 | |
801 | tmp->stats.exp = 0; |
772 | tmp->stats.exp = 0; |
802 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
803 | |
773 | |
804 | add_friendly_object (tmp); |
774 | add_friendly_object (tmp); |
805 | tmp->attack_movement = PETMOVE; |
775 | tmp->attack_movement = PETMOVE; |
806 | break; |
776 | break; |
807 | |
777 | |
… | |
… | |
858 | * and has a matching item. Imagine what happens if someone steps on the inventory |
828 | * and has a matching item. Imagine what happens if someone steps on the inventory |
859 | * checker with a matching item, has it, activates the connection, throws the item |
829 | * checker with a matching item, has it, activates the connection, throws the item |
860 | * away, and then leaves the inventory checker. That would've caused an always-enabled |
830 | * away, and then leaves the inventory checker. That would've caused an always-enabled |
861 | * state in the inventory checker. This won't happen anymore now. |
831 | * state in the inventory checker. This won't happen anymore now. |
862 | * |
832 | * |
|
|
833 | * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check |
|
|
834 | * whether op is on this mapspace or not, because the value (1|0) depends |
|
|
835 | * on this information. also make sure to only push_button if op has |
|
|
836 | * a matching item (because when we do a push_button with value=0 timed gates |
|
|
837 | * will still open)! (i hope i got the semantics right this time) |
|
|
838 | * |
863 | */ |
839 | */ |
864 | void |
840 | void |
865 | check_inv (object *op, object *trig) |
841 | check_inv (object *op, object *trig) |
866 | { |
842 | { |
867 | trig->value = 0; // deactivate if none of the following conditions apply |
843 | trig->value = 0; // deactivate if none of the following conditions apply |
868 | |
844 | |
869 | if (object *pl = trig->ms ().player ()) |
845 | object *pl = trig->ms ().player (); |
870 | { |
|
|
871 | object *match = check_inv_recursive (pl, trig); |
846 | object *match = check_inv_recursive (op, trig); |
872 | |
847 | |
|
|
848 | // elmex: a note about (pl == op): |
|
|
849 | // if pl == 0 then the player has left this space |
|
|
850 | // if pl != 0 then a player is on this mapspace, but then |
|
|
851 | // we still have to check whether it's the player that triggered |
|
|
852 | // this inv-checker, because if not, then the op left this inv-checker |
|
|
853 | // and we have to set the value to 0 |
|
|
854 | |
873 | if (match && trig->last_sp) // match == having |
855 | if (match && trig->last_sp) // match == having |
874 | { |
856 | { |
875 | if (trig->last_heal) |
857 | if (trig->last_heal) |
876 | decrease_ob (match); |
858 | decrease_ob (match); |
877 | |
859 | |
878 | trig->value = 1; |
860 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
879 | } |
861 | push_button (trig); |
|
|
862 | } |
880 | else if (!match && !trig->last_sp) // match == not having |
863 | else if (!match && !trig->last_sp) // match == not having |
881 | trig->value = 1; |
|
|
882 | } |
864 | { |
883 | |
865 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
884 | push_button (trig); |
866 | push_button (trig); |
|
|
867 | } |
885 | } |
868 | } |
886 | |
869 | |