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.51 by root, Thu Jan 8 03:03:23 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"));
134 case FIREWALL: 136 case FIREWALL:
135 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 137 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL)
136 move_firewall (tmp); 138 move_firewall (tmp);
137 else 139 else
138 { 140 {
139 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 141 tmp->stats.sp = absdir (tmp->stats.sp + tmp->stats.maxsp); /* next direction */
140 tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1;
141
142 animate_turning (tmp); 142 animate_turning (tmp);
143 } 143 }
144 break; 144 break;
145 145
146 case TELEPORTER: 146 case TELEPORTER:
159 case DUPLICATOR: 159 case DUPLICATOR:
160 move_duplicator (tmp); 160 move_duplicator (tmp);
161 break; 161 break;
162 162
163 case MAPSCRIPT: 163 case MAPSCRIPT:
164 cfperl_mapscript_activate (tmp, source, state); 164 cfperl_mapscript_activate (tmp, state, activator, originator);
165 break; 165 break;
166 } 166 }
167 } 167 }
168} 168}
169 169
178 * Changed the routine to loop through _all_ objects. 178 * Changed the routine to loop through _all_ objects.
179 * Better hurry with that linked list... 179 * Better hurry with that linked list...
180 * 180 *
181 */ 181 */
182void 182void
183push_button (object *op) 183push_button (object *op, object *originator)
184{ 184{
185 if (oblinkpt *obp = op->find_link ()) 185 if (oblinkpt *obp = op->find_link ())
186 { 186 {
187 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value))) 187 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator)))
188 return; 188 return;
189 189
190 activate_connection_link (obp->link, op->value, op); 190 activate_connection_link (obp->link, op->value, op, originator);
191 } 191 }
192} 192}
193 193
194/* 194/*
195 * elmex: 195 * elmex:
198 * 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
199 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 199 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
200 * 200 *
201 */ 201 */
202void 202void
203maptile::trigger (shstr_tmp id, bool state, object *originator) 203maptile::trigger (shstr_tmp id, int state, object *activator, object *originator)
204{ 204{
205 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator))) 205 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator)))
206 return; 206 return;
207 207
208 if (oblinkpt *obp = find_link (id)) 208 if (oblinkpt *obp = find_link (id))
209 activate_connection_link (obp->link, state, originator); 209 activate_connection_link (obp->link, state, activator, originator);
210} 210}
211 211
212/* 212/*
213 * Updates everything connected with the button op. 213 * Updates everything connected with the button op.
214 * 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
215 * 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
216 * button reacts to the (eventual) change of state. 216 * button reacts to the (eventual) change of state.
217 */ 217 */
218void 218void
219update_button (object *op) 219update_button (object *op, object *originator)
220{ 220{
221 int any_down = 0, old_value = op->value; 221 int any_down = 0, old_value = op->value;
222 222
223 if (oblinkpt *obp = op->find_link ()) 223 if (oblinkpt *obp = op->find_link ())
224 for (objectlink *ol = obp->link; ol; ol = ol->next) 224 for (objectlink *ol = obp->link; ol; ol = ol->next)
249 249
250 any_down = any_down || tmp->value; 250 any_down = any_down || tmp->value;
251 } 251 }
252 else if (tmp->type == PEDESTAL) 252 else if (tmp->type == PEDESTAL)
253 { 253 {
254 bool is_match = is_match_expr (tmp->slaying);
254 tmp->value = 0; 255 tmp->value = 0;
255 256
256 for (object *ab = tmp->above; ab; ab = ab->above) 257 for (object *ab = tmp->above; ab; ab = ab->above)
257 { 258 {
258 object *head = ab->head_ (); 259 object *head = ab->head_ ();
259 260
260 /* Same note regarding move_type for buttons above apply here. */ 261 /* Same note regarding move_type for buttons above apply here. */
261 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)
262 && (head->race == tmp->slaying 265 : (head->race == tmp->slaying
263 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) 266 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
264 || (tmp->slaying == shstr_player && head->type == PLAYER))) 267 || (tmp->slaying == shstr_player && head->type == PLAYER)))
268 {
265 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 }
266 } 291 }
267 292
268 any_down = any_down || tmp->value; 293 any_down = any_down || tmp->value;
269 } 294 }
270 } 295 }
277 /* If this button hasn't changed, don't do anything */ 302 /* If this button hasn't changed, don't do anything */
278 if (op->value != old_value) 303 if (op->value != old_value)
279 { 304 {
280 SET_ANIMATION (op, op->value); 305 SET_ANIMATION (op, op->value);
281 update_object (op, UP_OBJ_FACE); 306 update_object (op, UP_OBJ_FACE);
282 push_button (op); /* Make all other buttons the same */ 307 push_button (op, originator); /* Make all other buttons the same */
283 } 308 }
284} 309}
285 310
286void 311void
287use_trigger (object *op) 312use_trigger (object *op, object *originator)
288{ 313{
289 /* Toggle value */ 314 /* Toggle value */
290 op->value = !op->value; 315 op->value = !op->value;
316
291 push_button (op); 317 push_button (op, originator);
292} 318}
293 319
294/* 320/*
295 * Note: animate_object should be used instead of this, 321 * Note: animate_object should be used instead of this,
296 * but it can't handle animations in the 8 directions 322 * but it can't handle animations in the 8 directions
317 * 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
318 * objects on the same space that take the same sacrifice. 344 * objects on the same space that take the same sacrifice.
319 */ 345 */
320 346
321int 347int
322check_altar_sacrifice (const object *altar, const object *sacrifice) 348check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
323{ 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
324 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 356 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE)
325 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 357 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
326 && sacrifice->type != PLAYER) 358 && sacrifice->type != PLAYER)
327 { 359 {
328 if (ARCH_SACRIFICE (altar) == shstr_money 360 if (ARCH_SACRIFICE (altar) == shstr_money
349 * 381 *
350 * 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
351 * 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.
352 */ 384 */
353int 385int
354operate_altar (object *altar, object **sacrifice) 386operate_altar (object *altar, object **sacrifice, object *originator)
355{ 387{
356 if (!altar->map) 388 if (!altar->map)
357 { 389 {
358 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 390 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
359 return 0; 391 return 0;
360 } 392 }
361 393
362 if (!altar->slaying || altar->value) 394 if (!altar->slaying || altar->value)
363 return 0; 395 return 0;
364 396
365 if (!check_altar_sacrifice (altar, *sacrifice)) 397 if (!check_altar_sacrifice (altar, *sacrifice, originator))
366 return 0; 398 return 0;
367 399
368 /* check_altar_sacrifice should have already verified that enough money 400 /* check_altar_sacrifice should have already verified that enough money
369 * has been dropped. 401 * has been dropped.
370 */ 402 */
388 420
389 return 1; 421 return 1;
390} 422}
391 423
392void 424void
393trigger_move (object *op, int state) /* 1 down and 0 up */ 425trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
394{ 426{
395 op->stats.wc = state; 427 op->stats.wc = state;
428
396 if (state) 429 if (state)
397 { 430 {
398 use_trigger (op); 431 use_trigger (op, originator);
399 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.);
400 op->speed_left = -1; 433 op->speed_left = -1;
401 } 434 }
402 else 435 else
403 { 436 {
404 use_trigger (op); 437 use_trigger (op, originator);
405 op->set_speed (0); 438 op->set_speed (0);
406 } 439 }
407} 440}
408 441
409 442
418 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 451 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
419 * 452 *
420 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 453 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
421 */ 454 */
422int 455int
423check_trigger (object *op, object *cause) 456check_trigger (object *op, object *cause, object *originator)
424{ 457{
425 object *tmp; 458 object *tmp;
426 int push = 0, tot = 0; 459 int push = 0, tot = 0;
427 int in_movement = op->stats.wc || op->speed; 460 int in_movement = op->stats.wc || op->speed;
428 461
458 } 491 }
459 492
460 if (in_movement || !push) 493 if (in_movement || !push)
461 return 0; 494 return 0;
462 } 495 }
496
463 trigger_move (op, push); 497 trigger_move (op, push, cause);
464 } 498 }
465 499
466 return 0; 500 return 0;
467 501
468 case TRIGGER_PEDESTAL: 502 case TRIGGER_PEDESTAL:
496 530
497 if (in_movement || !push) 531 if (in_movement || !push)
498 return 0; 532 return 0;
499 } 533 }
500 534
501 trigger_move (op, push); 535 trigger_move (op, push, cause);
502 return 0; 536 return 0;
503 537
504 case TRIGGER_ALTAR: 538 case TRIGGER_ALTAR:
505 if (cause) 539 if (cause)
506 { 540 {
507 if (in_movement) 541 if (in_movement)
508 return 0; 542 return 0;
509 543
510 if (operate_altar (op, &cause)) 544 if (operate_altar (op, &cause)) /* TODO: originator? */
511 { 545 {
512 if (NUM_ANIMATIONS (op) > 1) 546 if (NUM_ANIMATIONS (op) > 1)
513 { 547 {
514 SET_ANIMATION (op, 1); 548 SET_ANIMATION (op, 1);
515 update_object (op, UP_OBJ_FACE); 549 update_object (op, UP_OBJ_FACE);
516 } 550 }
517 551
518 if (op->last_sp >= 0) 552 if (op->last_sp >= 0)
519 { 553 {
520 trigger_move (op, 1); 554 trigger_move (op, 1, cause);
555
521 if (op->last_sp > 0) 556 if (op->last_sp > 0)
522 op->last_sp = -op->last_sp; 557 op->last_sp = -op->last_sp;
523 } 558 }
524 else 559 else
525 { 560 {
526 /* for trigger altar with last_sp, the ON/OFF 561 /* for trigger altar with last_sp, the ON/OFF
527 * status (-> +/- value) is "simulated": 562 * status (-> +/- value) is "simulated":
528 */ 563 */
529 op->value = !op->value; 564 op->value = !op->value;
530 trigger_move (op, 1); 565 trigger_move (op, 1, cause);
531 op->last_sp = -op->last_sp; 566 op->last_sp = -op->last_sp;
532 op->value = !op->value; 567 op->value = !op->value;
533 } 568 }
534 569
535 return cause == NULL; 570 return cause == NULL;
549 * it will push the connected value only once per sacrifice. 584 * it will push the connected value only once per sacrifice.
550 * Otherwise (default), the connected value will be 585 * Otherwise (default), the connected value will be
551 * pushed twice: First by sacrifice, second by reset! -AV 586 * pushed twice: First by sacrifice, second by reset! -AV
552 */ 587 */
553 if (!op->last_sp) 588 if (!op->last_sp)
554 trigger_move (op, 0); 589 trigger_move (op, 0, cause);
555 else 590 else
556 { 591 {
557 op->stats.wc = 0; 592 op->stats.wc = 0;
558 op->value = !op->value; 593 op->value = !op->value;
559 op->set_speed (0); 594 op->set_speed (0);
574 { 609 {
575 SET_ANIMATION (op, push); 610 SET_ANIMATION (op, push);
576 update_object (op, UP_OBJ_FACE); 611 update_object (op, UP_OBJ_FACE);
577 } 612 }
578 613
579 trigger_move (op, push); 614 trigger_move (op, push, cause);
580 return 1; 615 return 1;
581 616
582 default: 617 default:
583 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);
584 return 0; 619 return 0;
665 continue; 700 continue;
666 } 701 }
667 702
668 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) 703 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
669 { 704 {
670 update_button (ol->ob); 705 update_button (ol->ob, 0);
671 break; 706 break;
672 } 707 }
673 } 708 }
674} 709}
675 710
880 { 915 {
881 if (trig->last_heal) 916 if (trig->last_heal)
882 match->decrease (); 917 match->decrease ();
883 918
884 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
885 push_button (trig); 920 push_button (trig, op);
886 } 921 }
887 else if (!match && !trig->last_sp) // match == not having 922 else if (!match && !trig->last_sp) // match == not having
888 { 923 {
889 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
890 push_button (trig); 925 push_button (trig, op);
891 } 926 }
892} 927}
893 928

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines