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.58 by root, Thu Oct 15 21:40:42 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 }
266 } 272 }
267 273
268 any_down = any_down || tmp->value; 274 any_down = any_down || tmp->value;
269 } 275 }
270 } 276 }
277 /* If this button hasn't changed, don't do anything */ 283 /* If this button hasn't changed, don't do anything */
278 if (op->value != old_value) 284 if (op->value != old_value)
279 { 285 {
280 SET_ANIMATION (op, op->value); 286 SET_ANIMATION (op, op->value);
281 update_object (op, UP_OBJ_FACE); 287 update_object (op, UP_OBJ_FACE);
282 push_button (op); /* Make all other buttons the same */ 288 push_button (op, originator); /* Make all other buttons the same */
283 } 289 }
284} 290}
285 291
286void 292void
287use_trigger (object *op) 293use_trigger (object *op, object *originator)
288{ 294{
289 /* Toggle value */ 295 /* Toggle value */
290 op->value = !op->value; 296 op->value = !op->value;
297
291 push_button (op); 298 push_button (op, originator);
292} 299}
293 300
294/* 301/*
295 * Note: animate_object should be used instead of this, 302 * Note: animate_object should be used instead of this,
296 * but it can't handle animations in the 8 directions 303 * but it can't handle animations in the 8 directions
317 * sacrificed. This fixes a bug of trying to put multiple altars/related 324 * sacrificed. This fixes a bug of trying to put multiple altars/related
318 * objects on the same space that take the same sacrifice. 325 * objects on the same space that take the same sacrifice.
319 */ 326 */
320 327
321int 328int
322check_altar_sacrifice (const object *altar, const object *sacrifice) 329check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
323{ 330{
331 if (sacrifice->flag [FLAG_UNPAID])
332 return 0;
333
334 if (is_match_expr (ARCH_SACRIFICE (altar)))
335 return match (ARCH_SACRIFICE (altar), altar, originator);
336
324 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 337 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE)
325 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 338 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
326 && sacrifice->type != PLAYER) 339 && sacrifice->type != PLAYER)
327 { 340 {
328 if (ARCH_SACRIFICE (altar) == shstr_money 341 if (ARCH_SACRIFICE (altar) == shstr_money
349 * 362 *
350 * If this function returns 1, '*sacrifice' is modified to point to the 363 * 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. 364 * remaining sacrifice, or is set to NULL if the sacrifice was used up.
352 */ 365 */
353int 366int
354operate_altar (object *altar, object **sacrifice) 367operate_altar (object *altar, object **sacrifice, object *originator)
355{ 368{
356 if (!altar->map) 369 if (!altar->map)
357 { 370 {
358 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 371 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
359 return 0; 372 return 0;
360 } 373 }
361 374
362 if (!altar->slaying || altar->value) 375 if (!altar->slaying || altar->value)
363 return 0; 376 return 0;
364 377
365 if (!check_altar_sacrifice (altar, *sacrifice)) 378 if (!check_altar_sacrifice (altar, *sacrifice, originator))
366 return 0; 379 return 0;
367 380
368 /* check_altar_sacrifice should have already verified that enough money 381 /* check_altar_sacrifice should have already verified that enough money
369 * has been dropped. 382 * has been dropped.
370 */ 383 */
388 401
389 return 1; 402 return 1;
390} 403}
391 404
392void 405void
393trigger_move (object *op, int state) /* 1 down and 0 up */ 406trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
394{ 407{
395 op->stats.wc = state; 408 op->stats.wc = state;
409
396 if (state) 410 if (state)
397 { 411 {
398 use_trigger (op); 412 use_trigger (op, originator);
399 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); 413 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.);
400 op->speed_left = -1; 414 op->speed_left = -1;
401 } 415 }
402 else 416 else
403 { 417 {
404 use_trigger (op); 418 use_trigger (op, originator);
405 op->set_speed (0); 419 op->set_speed (0);
406 } 420 }
407} 421}
408 422
409 423
418 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 432 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
419 * 433 *
420 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 434 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
421 */ 435 */
422int 436int
423check_trigger (object *op, object *cause) 437check_trigger (object *op, object *cause, object *originator)
424{ 438{
425 object *tmp; 439 object *tmp;
426 int push = 0, tot = 0; 440 int push = 0, tot = 0;
427 int in_movement = op->stats.wc || op->speed; 441 int in_movement = op->stats.wc || op->speed;
428 442
458 } 472 }
459 473
460 if (in_movement || !push) 474 if (in_movement || !push)
461 return 0; 475 return 0;
462 } 476 }
477
463 trigger_move (op, push); 478 trigger_move (op, push, cause);
464 } 479 }
465 480
466 return 0; 481 return 0;
467 482
468 case TRIGGER_PEDESTAL: 483 case TRIGGER_PEDESTAL:
496 511
497 if (in_movement || !push) 512 if (in_movement || !push)
498 return 0; 513 return 0;
499 } 514 }
500 515
501 trigger_move (op, push); 516 trigger_move (op, push, cause);
502 return 0; 517 return 0;
503 518
504 case TRIGGER_ALTAR: 519 case TRIGGER_ALTAR:
505 if (cause) 520 if (cause)
506 { 521 {
507 if (in_movement) 522 if (in_movement)
508 return 0; 523 return 0;
509 524
510 if (operate_altar (op, &cause)) 525 if (operate_altar (op, &cause)) /* TODO: originator? */
511 { 526 {
512 if (NUM_ANIMATIONS (op) > 1) 527 if (NUM_ANIMATIONS (op) > 1)
513 { 528 {
514 SET_ANIMATION (op, 1); 529 SET_ANIMATION (op, 1);
515 update_object (op, UP_OBJ_FACE); 530 update_object (op, UP_OBJ_FACE);
516 } 531 }
517 532
518 if (op->last_sp >= 0) 533 if (op->last_sp >= 0)
519 { 534 {
520 trigger_move (op, 1); 535 trigger_move (op, 1, cause);
536
521 if (op->last_sp > 0) 537 if (op->last_sp > 0)
522 op->last_sp = -op->last_sp; 538 op->last_sp = -op->last_sp;
523 } 539 }
524 else 540 else
525 { 541 {
526 /* for trigger altar with last_sp, the ON/OFF 542 /* for trigger altar with last_sp, the ON/OFF
527 * status (-> +/- value) is "simulated": 543 * status (-> +/- value) is "simulated":
528 */ 544 */
529 op->value = !op->value; 545 op->value = !op->value;
530 trigger_move (op, 1); 546 trigger_move (op, 1, cause);
531 op->last_sp = -op->last_sp; 547 op->last_sp = -op->last_sp;
532 op->value = !op->value; 548 op->value = !op->value;
533 } 549 }
534 550
535 return cause == NULL; 551 return cause == NULL;
549 * it will push the connected value only once per sacrifice. 565 * it will push the connected value only once per sacrifice.
550 * Otherwise (default), the connected value will be 566 * Otherwise (default), the connected value will be
551 * pushed twice: First by sacrifice, second by reset! -AV 567 * pushed twice: First by sacrifice, second by reset! -AV
552 */ 568 */
553 if (!op->last_sp) 569 if (!op->last_sp)
554 trigger_move (op, 0); 570 trigger_move (op, 0, cause);
555 else 571 else
556 { 572 {
557 op->stats.wc = 0; 573 op->stats.wc = 0;
558 op->value = !op->value; 574 op->value = !op->value;
559 op->set_speed (0); 575 op->set_speed (0);
574 { 590 {
575 SET_ANIMATION (op, push); 591 SET_ANIMATION (op, push);
576 update_object (op, UP_OBJ_FACE); 592 update_object (op, UP_OBJ_FACE);
577 } 593 }
578 594
579 trigger_move (op, push); 595 trigger_move (op, push, cause);
580 return 1; 596 return 1;
581 597
582 default: 598 default:
583 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 599 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
584 return 0; 600 return 0;
665 continue; 681 continue;
666 } 682 }
667 683
668 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) 684 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
669 { 685 {
670 update_button (ol->ob); 686 update_button (ol->ob, 0);
671 break; 687 break;
672 } 688 }
673 } 689 }
674} 690}
675 691
880 { 896 {
881 if (trig->last_heal) 897 if (trig->last_heal)
882 match->decrease (); 898 match->decrease ();
883 899
884 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 900 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
885 push_button (trig); 901 push_button (trig, op);
886 } 902 }
887 else if (!match && !trig->last_sp) // match == not having 903 else if (!match && !trig->last_sp) // match == not having
888 { 904 {
889 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 905 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
890 push_button (trig); 906 push_button (trig, op);
891 } 907 }
892} 908}
893 909

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines