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.63 by root, Tue Nov 10 20:57:56 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:
85 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) 87 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food)
86 { 88 {
87 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_sign")); 89 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("msg_voice"));
90
91 if (originator && originator->contr)
92 originator->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n%s", &tmp->name, &tmp->msg));
93
88 new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); 94 new_info_map_except (NDI_UNIQUE | NDI_NAVY, tmp->map, originator, tmp->msg);
95
89 if (tmp->stats.food) 96 if (tmp->stats.food)
90 tmp->last_eat++; 97 tmp->last_eat++;
91 } 98 }
92 break; 99 break;
93 100
105 SET_ANIMATION (tmp, tmp->value); 112 SET_ANIMATION (tmp, tmp->value);
106 update_object (tmp, UP_OBJ_FACE); 113 update_object (tmp, UP_OBJ_FACE);
107 break; 114 break;
108 115
109 case MOOD_FLOOR: 116 case MOOD_FLOOR:
110 do_mood_floor (tmp, source); 117 do_mood_floor (tmp, activator);
111 break; 118 break;
112 119
113 case TIMED_GATE: 120 case TIMED_GATE:
114 if (!tmp->active) 121 if (!tmp->active)
115 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); 122 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate"));
134 case FIREWALL: 141 case FIREWALL:
135 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 142 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL)
136 move_firewall (tmp); 143 move_firewall (tmp);
137 else 144 else
138 { 145 {
139 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 146 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); 147 animate_turning (tmp);
143 } 148 }
144 break; 149 break;
145 150
146 case TELEPORTER: 151 case TELEPORTER:
159 case DUPLICATOR: 164 case DUPLICATOR:
160 move_duplicator (tmp); 165 move_duplicator (tmp);
161 break; 166 break;
162 167
163 case MAPSCRIPT: 168 case MAPSCRIPT:
164 cfperl_mapscript_activate (tmp, source, state); 169 cfperl_mapscript_activate (tmp, state, activator, originator);
165 break; 170 break;
166 } 171 }
167 } 172 }
168} 173}
169 174
178 * Changed the routine to loop through _all_ objects. 183 * Changed the routine to loop through _all_ objects.
179 * Better hurry with that linked list... 184 * Better hurry with that linked list...
180 * 185 *
181 */ 186 */
182void 187void
183push_button (object *op) 188push_button (object *op, object *originator)
184{ 189{
185 if (oblinkpt *obp = op->find_link ()) 190 if (oblinkpt *obp = op->find_link ())
186 { 191 {
187 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value))) 192 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator)))
188 return; 193 return;
189 194
190 activate_connection_link (obp->link, op->value, op); 195 activate_connection_link (obp->link, op->value, op, originator);
191 } 196 }
192} 197}
193 198
194/* 199/*
195 * elmex: 200 * elmex:
198 * the connection was 'state' or 'released'. So that you can activate objects 203 * the connection was 'state' or 'released'. So that you can activate objects
199 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 204 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
200 * 205 *
201 */ 206 */
202void 207void
203maptile::trigger (shstr_tmp id, bool state, object *originator) 208maptile::trigger (shstr_tmp id, int state, object *activator, object *originator)
204{ 209{
205 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator))) 210 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator)))
206 return; 211 return;
207 212
208 if (oblinkpt *obp = find_link (id)) 213 if (oblinkpt *obp = find_link (id))
209 activate_connection_link (obp->link, state, originator); 214 activate_connection_link (obp->link, state, activator, originator);
210} 215}
211 216
212/* 217/*
213 * Updates everything connected with the button op. 218 * Updates everything connected with the button op.
214 * After changing the state of a button, this function must be called 219 * 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 220 * to make sure that all gates and other buttons connected to the
216 * button reacts to the (eventual) change of state. 221 * button reacts to the (eventual) change of state.
217 */ 222 */
218void 223void
219update_button (object *op) 224update_button (object *op, object *originator)
220{ 225{
221 int any_down = 0, old_value = op->value; 226 int any_down = 0, old_value = op->value;
222 227
223 if (oblinkpt *obp = op->find_link ()) 228 if (oblinkpt *obp = op->find_link ())
224 for (objectlink *ol = obp->link; ol; ol = ol->next) 229 for (objectlink *ol = obp->link; ol; ol = ol->next)
249 254
250 any_down = any_down || tmp->value; 255 any_down = any_down || tmp->value;
251 } 256 }
252 else if (tmp->type == PEDESTAL) 257 else if (tmp->type == PEDESTAL)
253 { 258 {
259 bool is_match = is_match_expr (tmp->slaying);
254 tmp->value = 0; 260 tmp->value = 0;
255 261
256 for (object *ab = tmp->above; ab; ab = ab->above) 262 for (object *ab = tmp->above; ab; ab = ab->above)
257 { 263 {
258 object *head = ab->head_ (); 264 object *head = ab->head_ ();
259 265
260 /* Same note regarding move_type for buttons above apply here. */ 266 /* Same note regarding move_type for buttons above apply here. */
261 if (((ab->move_type & tmp->move_on) || ab->move_type == 0) 267 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
268 if (is_match
269 ? match (tmp->slaying, head, tmp, originator)
262 && (head->race == tmp->slaying 270 : (head->race == tmp->slaying
263 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) 271 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
264 || (tmp->slaying == shstr_player && head->type == PLAYER))) 272 || (tmp->slaying == shstr_player && head->type == PLAYER)))
273 {
265 tmp->value = 1; 274 tmp->value = 1;
275 break;
276 }
277 }
278
279 any_down = any_down || tmp->value;
280 }
281 else if (tmp->type == T_MATCH)
282 {
283 tmp->value = 0;
284
285 for (object *ab = tmp->above; ab; ab = ab->above)
286 {
287 object *head = ab->head_ ();
288
289 /* Same note regarding move_type for buttons above apply here. */
290 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
291 if (match (tmp->slaying, head, tmp, originator))
292 {
293 tmp->value = 1;
294 break;
295 }
266 } 296 }
267 297
268 any_down = any_down || tmp->value; 298 any_down = any_down || tmp->value;
269 } 299 }
270 } 300 }
277 /* If this button hasn't changed, don't do anything */ 307 /* If this button hasn't changed, don't do anything */
278 if (op->value != old_value) 308 if (op->value != old_value)
279 { 309 {
280 SET_ANIMATION (op, op->value); 310 SET_ANIMATION (op, op->value);
281 update_object (op, UP_OBJ_FACE); 311 update_object (op, UP_OBJ_FACE);
282 push_button (op); /* Make all other buttons the same */ 312 push_button (op, originator); /* Make all other buttons the same */
283 } 313 }
284} 314}
285 315
286void 316void
287use_trigger (object *op) 317use_trigger (object *op, object *originator)
288{ 318{
289 /* Toggle value */ 319 /* Toggle value */
290 op->value = !op->value; 320 op->value = !op->value;
321
291 push_button (op); 322 push_button (op, originator);
292} 323}
293 324
294/* 325/*
295 * Note: animate_object should be used instead of this, 326 * Note: animate_object should be used instead of this,
296 * but it can't handle animations in the 8 directions 327 * but it can't handle animations in the 8 directions
315 * 346 *
316 * 0.93.4: Linked objects (ie, objects that are connected) can not be 347 * 0.93.4: Linked objects (ie, objects that are connected) can not be
317 * sacrificed. This fixes a bug of trying to put multiple altars/related 348 * sacrificed. This fixes a bug of trying to put multiple altars/related
318 * objects on the same space that take the same sacrifice. 349 * objects on the same space that take the same sacrifice.
319 */ 350 */
320
321int 351int
322check_altar_sacrifice (const object *altar, const object *sacrifice) 352check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
323{ 353{
354 if (sacrifice->flag [FLAG_UNPAID])
355 return 0;
356
357 if (is_match_expr (ARCH_SACRIFICE (altar)))
358 return match (ARCH_SACRIFICE (altar), altar, originator);
359
324 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 360 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE)
325 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 361 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
326 && sacrifice->type != PLAYER) 362 && sacrifice->type != PLAYER)
327 { 363 {
328 if (ARCH_SACRIFICE (altar) == shstr_money 364 if (ARCH_SACRIFICE (altar) == shstr_money
349 * 385 *
350 * If this function returns 1, '*sacrifice' is modified to point to the 386 * 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. 387 * remaining sacrifice, or is set to NULL if the sacrifice was used up.
352 */ 388 */
353int 389int
354operate_altar (object *altar, object **sacrifice) 390operate_altar (object *altar, object **sacrifice, object *originator)
355{ 391{
356 if (!altar->map) 392 if (!altar->map)
357 { 393 {
358 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 394 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
359 return 0; 395 return 0;
360 } 396 }
361 397
362 if (!altar->slaying || altar->value) 398 if (!altar->slaying || altar->value)
363 return 0; 399 return 0;
364 400
365 if (!check_altar_sacrifice (altar, *sacrifice)) 401 if (!check_altar_sacrifice (altar, *sacrifice, originator))
366 return 0; 402 return 0;
367 403
368 /* check_altar_sacrifice should have already verified that enough money 404 /* check_altar_sacrifice should have already verified that enough money
369 * has been dropped. 405 * has been dropped.
370 */ 406 */
387 new_info_map (NDI_BLACK, altar->map, altar->msg); 423 new_info_map (NDI_BLACK, altar->map, altar->msg);
388 424
389 return 1; 425 return 1;
390} 426}
391 427
392void 428static void
393trigger_move (object *op, int state) /* 1 down and 0 up */ 429trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
394{ 430{
395 op->stats.wc = state; 431 op->stats.wc = state;
432
396 if (state) 433 if (state)
397 { 434 {
398 use_trigger (op); 435 use_trigger (op, originator);
399 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); 436 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.);
400 op->speed_left = -1; 437 op->speed_left = -1;
401 } 438 }
402 else 439 else
403 { 440 {
404 use_trigger (op); 441 use_trigger (op, originator);
405 op->set_speed (0); 442 op->set_speed (0);
406 } 443 }
407} 444}
408 445
409 446
418 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 455 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
419 * 456 *
420 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 457 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
421 */ 458 */
422int 459int
423check_trigger (object *op, object *cause) 460check_trigger (object *op, object *cause, object *originator)
424{ 461{
425 object *tmp; 462 object *tmp;
426 int push = 0, tot = 0; 463 int push = 0, tot = 0;
427 int in_movement = op->stats.wc || op->speed; 464 int in_movement = op->stats.wc || op->has_active_speed ();
428 465
429 switch (op->type) 466 switch (op->type)
430 { 467 {
431 case TRIGGER_BUTTON: 468 case TRIGGER_BUTTON:
432 if (op->weight > 0) 469 if (op->weight > 0)
458 } 495 }
459 496
460 if (in_movement || !push) 497 if (in_movement || !push)
461 return 0; 498 return 0;
462 } 499 }
500
463 trigger_move (op, push); 501 trigger_move (op, push, cause);
464 } 502 }
465 503
466 return 0; 504 return 0;
467 505
468 case TRIGGER_PEDESTAL: 506 case TRIGGER_PEDESTAL:
496 534
497 if (in_movement || !push) 535 if (in_movement || !push)
498 return 0; 536 return 0;
499 } 537 }
500 538
501 trigger_move (op, push); 539 trigger_move (op, push, cause);
502 return 0; 540 return 0;
503 541
504 case TRIGGER_ALTAR: 542 case TRIGGER_ALTAR:
505 if (cause) 543 if (cause)
506 { 544 {
507 if (in_movement) 545 if (in_movement)
508 return 0; 546 return 0;
509 547
510 if (operate_altar (op, &cause)) 548 if (operate_altar (op, &cause)) /* TODO: originator? */
511 { 549 {
512 if (NUM_ANIMATIONS (op) > 1) 550 if (NUM_ANIMATIONS (op) > 1)
513 { 551 {
514 SET_ANIMATION (op, 1); 552 SET_ANIMATION (op, 1);
515 update_object (op, UP_OBJ_FACE); 553 update_object (op, UP_OBJ_FACE);
516 } 554 }
517 555
518 if (op->last_sp >= 0) 556 if (op->last_sp >= 0)
519 { 557 {
520 trigger_move (op, 1); 558 trigger_move (op, 1, cause);
559
521 if (op->last_sp > 0) 560 if (op->last_sp > 0)
522 op->last_sp = -op->last_sp; 561 op->last_sp = -op->last_sp;
523 } 562 }
524 else 563 else
525 { 564 {
526 /* for trigger altar with last_sp, the ON/OFF 565 /* for trigger altar with last_sp, the ON/OFF
527 * status (-> +/- value) is "simulated": 566 * status (-> +/- value) is "simulated":
528 */ 567 */
529 op->value = !op->value; 568 op->value = !op->value;
530 trigger_move (op, 1); 569 trigger_move (op, 1, cause);
531 op->last_sp = -op->last_sp; 570 op->last_sp = -op->last_sp;
532 op->value = !op->value; 571 op->value = !op->value;
533 } 572 }
534 573
535 return cause == NULL; 574 return cause == NULL;
549 * it will push the connected value only once per sacrifice. 588 * it will push the connected value only once per sacrifice.
550 * Otherwise (default), the connected value will be 589 * Otherwise (default), the connected value will be
551 * pushed twice: First by sacrifice, second by reset! -AV 590 * pushed twice: First by sacrifice, second by reset! -AV
552 */ 591 */
553 if (!op->last_sp) 592 if (!op->last_sp)
554 trigger_move (op, 0); 593 trigger_move (op, 0, cause);
555 else 594 else
556 { 595 {
557 op->stats.wc = 0; 596 op->stats.wc = 0;
558 op->value = !op->value; 597 op->value = !op->value;
559 op->set_speed (0); 598 op->set_speed (0);
574 { 613 {
575 SET_ANIMATION (op, push); 614 SET_ANIMATION (op, push);
576 update_object (op, UP_OBJ_FACE); 615 update_object (op, UP_OBJ_FACE);
577 } 616 }
578 617
579 trigger_move (op, push); 618 trigger_move (op, push, cause);
580 return 1; 619 return 1;
581 620
582 default: 621 default:
583 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 622 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
584 return 0; 623 return 0;
665 continue; 704 continue;
666 } 705 }
667 706
668 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) 707 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
669 { 708 {
670 update_button (ol->ob); 709 update_button (ol->ob, 0);
671 break; 710 break;
672 } 711 }
673 } 712 }
674} 713}
675 714
880 { 919 {
881 if (trig->last_heal) 920 if (trig->last_heal)
882 match->decrease (); 921 match->decrease ();
883 922
884 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 923 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
885 push_button (trig); 924 push_button (trig, op);
886 } 925 }
887 else if (!match && !trig->last_sp) // match == not having 926 else if (!match && !trig->last_sp) // match == not having
888 { 927 {
889 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 928 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
890 push_button (trig); 929 push_button (trig, op);
891 } 930 }
892} 931}
893 932

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines