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.61 by root, Fri Nov 6 13:03:34 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
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 351
321int 352int
322check_altar_sacrifice (const object *altar, const object *sacrifice) 353check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
323{ 354{
355 if (sacrifice->flag [FLAG_UNPAID])
356 return 0;
357
358 if (is_match_expr (ARCH_SACRIFICE (altar)))
359 return match (ARCH_SACRIFICE (altar), altar, originator);
360
324 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 361 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE)
325 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 362 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED)
326 && sacrifice->type != PLAYER) 363 && sacrifice->type != PLAYER)
327 { 364 {
328 if (ARCH_SACRIFICE (altar) == shstr_money 365 if (ARCH_SACRIFICE (altar) == shstr_money
349 * 386 *
350 * If this function returns 1, '*sacrifice' is modified to point to the 387 * 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. 388 * remaining sacrifice, or is set to NULL if the sacrifice was used up.
352 */ 389 */
353int 390int
354operate_altar (object *altar, object **sacrifice) 391operate_altar (object *altar, object **sacrifice, object *originator)
355{ 392{
356 if (!altar->map) 393 if (!altar->map)
357 { 394 {
358 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 395 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
359 return 0; 396 return 0;
360 } 397 }
361 398
362 if (!altar->slaying || altar->value) 399 if (!altar->slaying || altar->value)
363 return 0; 400 return 0;
364 401
365 if (!check_altar_sacrifice (altar, *sacrifice)) 402 if (!check_altar_sacrifice (altar, *sacrifice, originator))
366 return 0; 403 return 0;
367 404
368 /* check_altar_sacrifice should have already verified that enough money 405 /* check_altar_sacrifice should have already verified that enough money
369 * has been dropped. 406 * has been dropped.
370 */ 407 */
387 new_info_map (NDI_BLACK, altar->map, altar->msg); 424 new_info_map (NDI_BLACK, altar->map, altar->msg);
388 425
389 return 1; 426 return 1;
390} 427}
391 428
392void 429static void
393trigger_move (object *op, int state) /* 1 down and 0 up */ 430trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
394{ 431{
395 op->stats.wc = state; 432 op->stats.wc = state;
433
396 if (state) 434 if (state)
397 { 435 {
398 use_trigger (op); 436 use_trigger (op, originator);
399 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.); 437 op->set_speed (op->stats.exp > 0 ? 1. / op->stats.exp : 1.);
400 op->speed_left = -1; 438 op->speed_left = -1;
401 } 439 }
402 else 440 else
403 { 441 {
404 use_trigger (op); 442 use_trigger (op, originator);
405 op->set_speed (0); 443 op->set_speed (0);
406 } 444 }
407} 445}
408 446
409 447
418 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 456 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
419 * 457 *
420 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 458 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
421 */ 459 */
422int 460int
423check_trigger (object *op, object *cause) 461check_trigger (object *op, object *cause, object *originator)
424{ 462{
425 object *tmp; 463 object *tmp;
426 int push = 0, tot = 0; 464 int push = 0, tot = 0;
427 int in_movement = op->stats.wc || op->speed; 465 int in_movement = op->stats.wc || op->speed;
428 466
458 } 496 }
459 497
460 if (in_movement || !push) 498 if (in_movement || !push)
461 return 0; 499 return 0;
462 } 500 }
501
463 trigger_move (op, push); 502 trigger_move (op, push, cause);
464 } 503 }
465 504
466 return 0; 505 return 0;
467 506
468 case TRIGGER_PEDESTAL: 507 case TRIGGER_PEDESTAL:
496 535
497 if (in_movement || !push) 536 if (in_movement || !push)
498 return 0; 537 return 0;
499 } 538 }
500 539
501 trigger_move (op, push); 540 trigger_move (op, push, cause);
502 return 0; 541 return 0;
503 542
504 case TRIGGER_ALTAR: 543 case TRIGGER_ALTAR:
505 if (cause) 544 if (cause)
506 { 545 {
507 if (in_movement) 546 if (in_movement)
508 return 0; 547 return 0;
509 548
510 if (operate_altar (op, &cause)) 549 if (operate_altar (op, &cause)) /* TODO: originator? */
511 { 550 {
512 if (NUM_ANIMATIONS (op) > 1) 551 if (NUM_ANIMATIONS (op) > 1)
513 { 552 {
514 SET_ANIMATION (op, 1); 553 SET_ANIMATION (op, 1);
515 update_object (op, UP_OBJ_FACE); 554 update_object (op, UP_OBJ_FACE);
516 } 555 }
517 556
518 if (op->last_sp >= 0) 557 if (op->last_sp >= 0)
519 { 558 {
520 trigger_move (op, 1); 559 trigger_move (op, 1, cause);
560
521 if (op->last_sp > 0) 561 if (op->last_sp > 0)
522 op->last_sp = -op->last_sp; 562 op->last_sp = -op->last_sp;
523 } 563 }
524 else 564 else
525 { 565 {
526 /* for trigger altar with last_sp, the ON/OFF 566 /* for trigger altar with last_sp, the ON/OFF
527 * status (-> +/- value) is "simulated": 567 * status (-> +/- value) is "simulated":
528 */ 568 */
529 op->value = !op->value; 569 op->value = !op->value;
530 trigger_move (op, 1); 570 trigger_move (op, 1, cause);
531 op->last_sp = -op->last_sp; 571 op->last_sp = -op->last_sp;
532 op->value = !op->value; 572 op->value = !op->value;
533 } 573 }
534 574
535 return cause == NULL; 575 return cause == NULL;
549 * it will push the connected value only once per sacrifice. 589 * it will push the connected value only once per sacrifice.
550 * Otherwise (default), the connected value will be 590 * Otherwise (default), the connected value will be
551 * pushed twice: First by sacrifice, second by reset! -AV 591 * pushed twice: First by sacrifice, second by reset! -AV
552 */ 592 */
553 if (!op->last_sp) 593 if (!op->last_sp)
554 trigger_move (op, 0); 594 trigger_move (op, 0, cause);
555 else 595 else
556 { 596 {
557 op->stats.wc = 0; 597 op->stats.wc = 0;
558 op->value = !op->value; 598 op->value = !op->value;
559 op->set_speed (0); 599 op->set_speed (0);
574 { 614 {
575 SET_ANIMATION (op, push); 615 SET_ANIMATION (op, push);
576 update_object (op, UP_OBJ_FACE); 616 update_object (op, UP_OBJ_FACE);
577 } 617 }
578 618
579 trigger_move (op, push); 619 trigger_move (op, push, cause);
580 return 1; 620 return 1;
581 621
582 default: 622 default:
583 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); 623 LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type);
584 return 0; 624 return 0;
665 continue; 705 continue;
666 } 706 }
667 707
668 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) 708 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
669 { 709 {
670 update_button (ol->ob); 710 update_button (ol->ob, 0);
671 break; 711 break;
672 } 712 }
673 } 713 }
674} 714}
675 715
880 { 920 {
881 if (trig->last_heal) 921 if (trig->last_heal)
882 match->decrease (); 922 match->decrease ();
883 923
884 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
885 push_button (trig); 925 push_button (trig, op);
886 } 926 }
887 else if (!match && !trig->last_sp) // match == not having 927 else if (!match && !trig->last_sp) // match == not having
888 { 928 {
889 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 929 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
890 push_button (trig); 930 push_button (trig, op);
891 } 931 }
892} 932}
893 933

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines