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.47 by root, Tue May 6 16:55:25 2008 UTC vs.
Revision 1.74 by root, Sat Nov 17 23:39:59 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License 19 * 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/>. 20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
20 * 22 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 24 */
23 25
24#include <global.h> 26#include <global.h>
25 27
29 31
30/* 32/*
31 * elmex: 33 * elmex:
32 * This function takes a objectlink list with all the objects are going to be activated. 34 * 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. 35 * 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. 36 * The activator argument can be 0 or the source object for this activation.
37 * the originator is the player or monster who did something.
35 */ 38 */
36void 39static void
37activate_connection_link (objectlink * ol, bool state, object *source = 0) 40activate_connection_link (objectlink *ol, int state, object *activator, object *originator)
38{ 41{
39 for (; ol; ol = ol->next) 42 for (; ol; ol = ol->next)
40 { 43 {
41 if (!ol->ob) 44 if (!ol->ob)
42 { 45 {
50 * is getting moved out of memory, the status of buttons and levers 53 * is getting moved out of memory, the status of buttons and levers
51 * probably isn't important - it will get sorted out when the map is 54 * probably isn't important - it will get sorted out when the map is
52 * re-loaded. As such, just exit this function if that is the case. 55 * re-loaded. As such, just exit this function if that is the case.
53 */ 56 */
54 57
55 if (QUERY_FLAG (ol->ob, FLAG_FREED)) 58 if (ol->ob->flag [FLAG_FREED])
56 return; 59 return;
57 60
58 object *tmp = ol->ob; 61 object *tmp = ol->ob;
59 62
60 /* if the criteria isn't appropriate, don't do anything */ 63 /* if the criteria isn't appropriate, don't do anything */
61 if (state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_PUSH)) 64 if (state && !tmp->flag [FLAG_ACTIVATE_ON_PUSH])
62 continue; 65 continue;
63 66
64 if (!state && !QUERY_FLAG (tmp, FLAG_ACTIVATE_ON_RELEASE)) 67 if (!state && !tmp->flag [FLAG_ACTIVATE_ON_RELEASE])
65 continue; 68 continue;
66 69
67 switch (tmp->type) 70 switch (tmp->type)
68 { 71 {
69 case GATE: 72 case GATE:
74 : sound_find (tmp->type == GATE ? "trigger_gate" : "trigger_hole")); 77 : sound_find (tmp->type == GATE ? "trigger_gate" : "trigger_hole"));
75 tmp->value = tmp->stats.maxsp ? !state : state; 78 tmp->value = tmp->stats.maxsp ? !state : state;
76 tmp->set_speed (0.5); 79 tmp->set_speed (0.5);
77 break; 80 break;
78 81
79 case CF_HANDLE: 82 case T_HANDLE:
80 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state)); 83 SET_ANIMATION (tmp, (tmp->value = tmp->stats.maxsp ? !state : state));
81 update_object (tmp, UP_OBJ_FACE); 84 update_object (tmp, UP_OBJ_FACE);
82 break; 85 break;
83 86
84 case SIGN: 87 case SIGN:
85 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food) 88 if (!tmp->stats.food || tmp->last_eat < tmp->stats.food)
86 { 89 {
87 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_sign")); 90 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("msg_voice"));
91
92 if (originator && originator->contr)
93 originator->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n%s", &tmp->name, &tmp->msg));
94
88 new_info_map (NDI_UNIQUE | NDI_NAVY, tmp->map, tmp->msg); 95 new_info_map_except (NDI_UNIQUE | NDI_NAVY, tmp->map, originator, tmp->msg);
96
89 if (tmp->stats.food) 97 if (tmp->stats.food)
90 tmp->last_eat++; 98 tmp->last_eat++;
91 } 99 }
92 break; 100 break;
93 101
105 SET_ANIMATION (tmp, tmp->value); 113 SET_ANIMATION (tmp, tmp->value);
106 update_object (tmp, UP_OBJ_FACE); 114 update_object (tmp, UP_OBJ_FACE);
107 break; 115 break;
108 116
109 case MOOD_FLOOR: 117 case MOOD_FLOOR:
110 do_mood_floor (tmp, source); 118 do_mood_floor (tmp, activator);
111 break; 119 break;
112 120
113 case TIMED_GATE: 121 case TIMED_GATE:
114 if (!tmp->active) 122 if (!tmp->active)
115 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate")); 123 tmp->play_sound (tmp->sound ? tmp->sound : sound_find ("trigger_gate"));
124
116 tmp->set_speed (tmp->arch->speed); 125 tmp->set_speed (tmp->arch->speed);
117 tmp->value = tmp->arch->value; 126 tmp->value = tmp->arch->value;
118 tmp->stats.sp = 1; 127 tmp->stats.sp = 1;
119 tmp->stats.hp = tmp->stats.maxhp; 128 tmp->stats.hp = tmp->stats.maxhp;
120 /* Handle multipart gates. We copy the value for the other parts 129 /* Handle multipart gates. We copy the value for the other parts
129 } 138 }
130 break; 139 break;
131 140
132 case DIRECTOR: 141 case DIRECTOR:
133 case FIREWALL: 142 case FIREWALL:
134 if (!QUERY_FLAG (tmp, FLAG_ANIMATE) && tmp->type == FIREWALL) 143 if (!tmp->flag [FLAG_ANIMATE] && tmp->type == FIREWALL)
135 move_firewall (tmp); 144 move_firewall (tmp);
136 else 145 else
137 { 146 {
138 if ((tmp->stats.sp += tmp->stats.maxsp) > 8) /* next direction */ 147 tmp->stats.sp = absdir (tmp->stats.sp + tmp->stats.maxsp); /* next direction */
139 tmp->stats.sp = ((tmp->stats.sp - 1) % 8) + 1;
140
141 animate_turning (tmp); 148 animate_turning (tmp);
142 } 149 }
143 break; 150 break;
144 151
145 case TELEPORTER: 152 case TELEPORTER:
155 move_marker (tmp); 162 move_marker (tmp);
156 break; 163 break;
157 164
158 case DUPLICATOR: 165 case DUPLICATOR:
159 move_duplicator (tmp); 166 move_duplicator (tmp);
167 break;
168
169 case MAPSCRIPT:
170 cfperl_mapscript_activate (tmp, state, activator, originator);
160 break; 171 break;
161 } 172 }
162 } 173 }
163} 174}
164 175
173 * Changed the routine to loop through _all_ objects. 184 * Changed the routine to loop through _all_ objects.
174 * Better hurry with that linked list... 185 * Better hurry with that linked list...
175 * 186 *
176 */ 187 */
177void 188void
178push_button (object *op) 189push_button (object *op, object *originator)
179{ 190{
180 oblinkpt *obp = get_button_links (op); 191 if (oblinkpt *obp = op->find_link ())
181 192 {
182 if (!obp) 193 if (INVOKE_MAP (TRIGGER, op->map, ARG_STRING (&obp->id), ARG_INT (op->value), ARG_OBJECT (op), ARG_OBJECT (originator)))
183 return; 194 return;
184 195
185 if (INVOKE_MAP (TRIGGER, op->map, ARG_INT64 (obp->value), ARG_INT (op->value)))
186 return;
187
188 activate_connection_link (obp->link, op->value, op); 196 activate_connection_link (obp->link, op->value, op, originator);
197 }
189} 198}
190 199
191/* 200/*
192 * elmex: 201 * elmex:
193 * This activates a connection, similar to push_button (object *op) but it takes 202 * This activates a connection, similar to push_button (object *op) but it takes
195 * the connection was 'state' or 'released'. So that you can activate objects 204 * the connection was 'state' or 'released'. So that you can activate objects
196 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 205 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
197 * 206 *
198 */ 207 */
199void 208void
200activate_connection (maptile *map, long connection, bool state) 209maptile::trigger (shstr_tmp id, int state, object *activator, object *originator)
201{ 210{
202 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) 211 if (INVOKE_MAP (TRIGGER, this, ARG_STRING (&id), ARG_INT (state), ARG_OBJECT (originator)))
203 return; 212 return;
204 213
205 oblinkpt *obp = get_connection_links (map, connection); 214 if (oblinkpt *obp = find_link (id))
206
207 if (obp)
208 activate_connection_link (obp->link, state); 215 activate_connection_link (obp->link, state, activator, originator);
209} 216}
210 217
211/* 218/*
212 * Updates everything connected with the button op. 219 * Updates everything connected with the button op.
213 * After changing the state of a button, this function must be called 220 * After changing the state of a button, this function must be called
214 * to make sure that all gates and other buttons connected to the 221 * to make sure that all gates and other buttons connected to the
215 * button reacts to the (eventual) change of state. 222 * button reacts to the (eventual) change of state.
216 */ 223 */
217void 224void
218update_button (object *op) 225update_button (object *op, object *originator)
219{ 226{
220 int any_down = 0, old_value = op->value; 227 int any_down = 0, old_value = op->value;
221 oblinkpt *obp = 0;
222 objectlink *ol;
223 228
224 obp = get_button_links (op); 229 if (oblinkpt *obp = op->find_link ())
225 if (obp)
226 for (ol = obp->link; ol; ol = ol->next) 230 for (objectlink *ol = obp->link; ol; ol = ol->next)
227 { 231 {
228 if (!ol->ob) 232 if (!ol->ob)
229 { 233 {
230 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); 234 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name);
231 continue; 235 continue;
233 237
234 object *tmp = ol->ob; 238 object *tmp = ol->ob;
235 239
236 if (tmp->type == BUTTON) 240 if (tmp->type == BUTTON)
237 { 241 {
238 sint32 total = 0; 242 weight_t total = 0;
239 243
240 for (object *ab = tmp->above; ab; ab = ab->above) 244 for (object *ab = tmp->above; ab; ab = ab->above)
241 /* Basically, if the move_type matches that on what the 245 /* Basically, if the move_type matches that on what the
242 * button wants, we count it. The second check is so that 246 * button wants, we count it. The second check is so that
243 * objects who don't move (swords, etc) will count. Note that 247 * objects who don't move (swords, etc) will count. Note that
251 255
252 any_down = any_down || tmp->value; 256 any_down = any_down || tmp->value;
253 } 257 }
254 else if (tmp->type == PEDESTAL) 258 else if (tmp->type == PEDESTAL)
255 { 259 {
260 bool is_match = is_match_expr (tmp->slaying);
256 tmp->value = 0; 261 tmp->value = 0;
257 262
258 for (object *ab = tmp->above; ab; ab = ab->above) 263 for (object *ab = tmp->above; ab; ab = ab->above)
259 { 264 {
260 object *head = ab->head_ (); 265 object *head = ab->head_ ();
261 266
262 /* Same note regarding move_type for buttons above apply here. */ 267 /* Same note regarding move_type for buttons above apply here. */
263 if (((ab->move_type & tmp->move_on) || ab->move_type == 0) 268 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
269 if (is_match
270 ? match (tmp->slaying, head, tmp, originator)
264 && (head->race == tmp->slaying 271 : (head->race == tmp->slaying
265 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) 272 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
266 || (tmp->slaying == shstr_player && head->type == PLAYER))) 273 || (tmp->slaying == shstr_player && head->type == PLAYER)))
274 {
267 tmp->value = 1; 275 tmp->value = 1;
276 break;
277 }
278 }
279
280 any_down = any_down || tmp->value;
281 }
282 else if (tmp->type == T_MATCH)
283 {
284 tmp->value = 0;
285
286 for (object *ab = tmp->above; ab; ab = ab->above)
287 {
288 object *head = ab->head_ ();
289
290 /* Same note regarding move_type for buttons above apply here. */
291 if (((ab->move_type & tmp->move_on) || ab->move_type == 0))
292 if (match (tmp->slaying, head, tmp, originator))
293 {
294 tmp->value = 1;
295 break;
296 }
268 } 297 }
269 298
270 any_down = any_down || tmp->value; 299 any_down = any_down || tmp->value;
271 } 300 }
272 } 301 }
279 /* If this button hasn't changed, don't do anything */ 308 /* If this button hasn't changed, don't do anything */
280 if (op->value != old_value) 309 if (op->value != old_value)
281 { 310 {
282 SET_ANIMATION (op, op->value); 311 SET_ANIMATION (op, op->value);
283 update_object (op, UP_OBJ_FACE); 312 update_object (op, UP_OBJ_FACE);
284 push_button (op); /* Make all other buttons the same */ 313 push_button (op, originator); /* Make all other buttons the same */
285 } 314 }
286} 315}
287 316
288void 317void
289use_trigger (object *op) 318use_trigger (object *op, object *originator)
290{ 319{
291 /* Toggle value */ 320 /* Toggle value */
292 op->value = !op->value; 321 op->value = !op->value;
322
293 push_button (op); 323 push_button (op, originator);
294} 324}
295 325
296/* 326/*
297 * Note: animate_object should be used instead of this, 327 * Note: animate_object should be used instead of this,
298 * but it can't handle animations in the 8 directions 328 * but it can't handle animations in the 8 directions
317 * 347 *
318 * 0.93.4: Linked objects (ie, objects that are connected) can not be 348 * 0.93.4: Linked objects (ie, objects that are connected) can not be
319 * sacrificed. This fixes a bug of trying to put multiple altars/related 349 * sacrificed. This fixes a bug of trying to put multiple altars/related
320 * objects on the same space that take the same sacrifice. 350 * objects on the same space that take the same sacrifice.
321 */ 351 */
322
323int 352int
324check_altar_sacrifice (const object *altar, const object *sacrifice) 353check_altar_sacrifice (object *altar, object *sacrifice, object *originator)
325{ 354{
326 if (!QUERY_FLAG (sacrifice, FLAG_ALIVE) 355 if (sacrifice->flag [FLAG_UNPAID]
327 && !QUERY_FLAG (sacrifice, FLAG_IS_LINKED) 356 || sacrifice->flag [FLAG_IS_LINKED]
328 && sacrifice->type != PLAYER) 357 || sacrifice->is_player ())
358 return 0;
359
360 if (is_match_expr (ARCH_SACRIFICE (altar)))
361 return match (ARCH_SACRIFICE (altar), sacrifice, altar, originator);
362
363 if (!sacrifice->flag [FLAG_ALIVE])
329 { 364 {
330 if (ARCH_SACRIFICE (altar) == shstr_money 365 if (ARCH_SACRIFICE (altar) == shstr_money
331 && sacrifice->type == MONEY 366 && sacrifice->type == MONEY
332 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar)) 367 && sacrifice->nrof * sacrifice->value >= NROF_SACRIFICE (altar))
333 return 1; 368 return 1;
351 * 386 *
352 * 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
353 * 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.
354 */ 389 */
355int 390int
356operate_altar (object *altar, object **sacrifice) 391operate_altar (object *altar, object **sacrifice, object *originator)
357{ 392{
358 if (!altar->map) 393 if (!altar->map)
359 { 394 {
360 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 395 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
361 return 0; 396 return 0;
362 } 397 }
363 398
364 if (!altar->slaying || altar->value) 399 if (!altar->slaying || altar->value)
365 return 0; 400 return 0;
366 401
367 if (!check_altar_sacrifice (altar, *sacrifice)) 402 if (!check_altar_sacrifice (altar, *sacrifice, originator))
368 return 0; 403 return 0;
369 404
370 /* check_altar_sacrifice should have already verified that enough money 405 /* check_altar_sacrifice should have already verified that enough money
371 * has been dropped. 406 * has been dropped.
372 */ 407 */
389 new_info_map (NDI_BLACK, altar->map, altar->msg); 424 new_info_map (NDI_BLACK, altar->map, altar->msg);
390 425
391 return 1; 426 return 1;
392} 427}
393 428
394void 429static void
395trigger_move (object *op, int state) /* 1 down and 0 up */ 430trigger_move (object *op, int state, object *originator) /* 1 down and 0 up */
396{ 431{
397 op->stats.wc = state; 432 op->stats.wc = state;
433
398 if (state) 434 if (state)
399 { 435 {
400 use_trigger (op); 436 use_trigger (op, originator);
401 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.);
402 op->speed_left = -1; 438 op->speed_left = -1;
403 } 439 }
404 else 440 else
405 { 441 {
406 use_trigger (op); 442 use_trigger (op, originator);
407 op->set_speed (0); 443 op->set_speed (0);
408 } 444 }
409} 445}
410 446
411 447
420 * TRIGGER: Returns 1 if handle could be moved, 0 if not. 456 * TRIGGER: Returns 1 if handle could be moved, 0 if not.
421 * 457 *
422 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0. 458 * TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.
423 */ 459 */
424int 460int
425check_trigger (object *op, object *cause) 461check_trigger (object *op, object *cause, object *originator)
426{ 462{
427 object *tmp; 463 object *tmp;
428 int push = 0, tot = 0; 464 int push = 0, tot = 0;
429 int in_movement = op->stats.wc || op->speed; 465 int in_movement = op->stats.wc || op->has_active_speed ();
430 466
431 switch (op->type) 467 switch (op->type)
432 { 468 {
433 case TRIGGER_BUTTON: 469 case TRIGGER_BUTTON:
434 if (op->weight > 0) 470 if (op->weight > 0)
460 } 496 }
461 497
462 if (in_movement || !push) 498 if (in_movement || !push)
463 return 0; 499 return 0;
464 } 500 }
501
465 trigger_move (op, push); 502 trigger_move (op, push, cause);
466 } 503 }
467 504
468 return 0; 505 return 0;
469 506
470 case TRIGGER_PEDESTAL: 507 case TRIGGER_PEDESTAL:
474 { 511 {
475 object *head = tmp->head_ (); 512 object *head = tmp->head_ ();
476 513
477 /* See comment in TRIGGER_BUTTON about move_types */ 514 /* See comment in TRIGGER_BUTTON about move_types */
478 if (((head->move_type & op->move_on) || head->move_type == 0) 515 if (((head->move_type & op->move_on) || head->move_type == 0)
479 && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) 516 && (head->race == op->slaying || (op->slaying == shstr_player && head->type == PLAYER)))
480 { 517 {
481 push = 1; 518 push = 1;
482 break; 519 break;
483 } 520 }
484 } 521 }
498 535
499 if (in_movement || !push) 536 if (in_movement || !push)
500 return 0; 537 return 0;
501 } 538 }
502 539
503 trigger_move (op, push); 540 trigger_move (op, push, cause);
504 return 0; 541 return 0;
505 542
506 case TRIGGER_ALTAR: 543 case TRIGGER_ALTAR:
507 if (cause) 544 if (cause)
508 { 545 {
509 if (in_movement) 546 if (in_movement)
510 return 0; 547 return 0;
511 548
512 if (operate_altar (op, &cause)) 549 if (operate_altar (op, &cause)) /* TODO: originator? */
513 { 550 {
514 if (NUM_ANIMATIONS (op) > 1) 551 if (NUM_ANIMATIONS (op) > 1)
515 { 552 {
516 SET_ANIMATION (op, 1); 553 SET_ANIMATION (op, 1);
517 update_object (op, UP_OBJ_FACE); 554 update_object (op, UP_OBJ_FACE);
518 } 555 }
519 556
520 if (op->last_sp >= 0) 557 if (op->last_sp >= 0)
521 { 558 {
522 trigger_move (op, 1); 559 trigger_move (op, 1, cause);
560
523 if (op->last_sp > 0) 561 if (op->last_sp > 0)
524 op->last_sp = -op->last_sp; 562 op->last_sp = -op->last_sp;
525 } 563 }
526 else 564 else
527 { 565 {
528 /* for trigger altar with last_sp, the ON/OFF 566 /* for trigger altar with last_sp, the ON/OFF
529 * status (-> +/- value) is "simulated": 567 * status (-> +/- value) is "simulated":
530 */ 568 */
531 op->value = !op->value; 569 op->value = !op->value;
532 trigger_move (op, 1); 570 trigger_move (op, 1, cause);
533 op->last_sp = -op->last_sp; 571 op->last_sp = -op->last_sp;
534 op->value = !op->value; 572 op->value = !op->value;
535 } 573 }
536 574
537 return cause == NULL; 575 return cause == NULL;
548 } 586 }
549 587
550 /* If trigger_altar has "last_sp > 0" set on the map, 588 /* If trigger_altar has "last_sp > 0" set on the map,
551 * it will push the connected value only once per sacrifice. 589 * it will push the connected value only once per sacrifice.
552 * Otherwise (default), the connected value will be 590 * Otherwise (default), the connected value will be
553 * pushed twice: First by sacrifice, second by reset! -AV 591 * pushed twice: First by sacrifice, second by reset! -AV
554 */ 592 */
555 if (!op->last_sp) 593 if (!op->last_sp)
556 trigger_move (op, 0); 594 trigger_move (op, 0, cause);
557 else 595 else
558 { 596 {
559 op->stats.wc = 0; 597 op->stats.wc = 0;
560 op->value = !op->value; 598 op->value = !op->value;
561 op->set_speed (0); 599 op->set_speed (0);
576 { 614 {
577 SET_ANIMATION (op, push); 615 SET_ANIMATION (op, push);
578 update_object (op, UP_OBJ_FACE); 616 update_object (op, UP_OBJ_FACE);
579 } 617 }
580 618
581 trigger_move (op, push); 619 trigger_move (op, push, cause);
582 return 1; 620 return 1;
583 621
584 default: 622 default:
585 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);
586 return 0; 624 return 0;
587 } 625 }
588} 626}
589 627
590void 628void
591add_button_link (object *button, maptile *map, int connected) 629object::add_link (maptile *map, shstr_tmp id)
592{ 630{
593 oblinkpt *obp;
594 objectlink *ol = get_objectlink ();
595
596 if (!map) 631 if (!map)
597 { 632 {
598 LOG (llevError, "Tried to add button-link without map.\n"); 633 LOG (llevError, "Tried to add button-link without map.\n");
599 return; 634 return;
600 } 635 }
601 636
602 button->path_attuned = connected; /* peterm: I need this so I can rebuild 637 flag [FLAG_IS_LINKED] = true;
603 a connected map from a template map. */
604 638
605 SET_FLAG (button, FLAG_IS_LINKED); 639 objectlink *ol = get_objectlink ();
606
607 ol->ob = button; 640 ol->ob = this;
608 641
609 for (obp = map->buttons; obp && obp->value != connected; obp = obp->next) 642 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
610 ; 643 if (obp->id == id)
611
612 if (obp)
613 { 644 {
614 ol->next = obp->link; 645 ol->next = obp->link;
615 obp->link = ol; 646 obp->link = ol;
647 return;
616 } 648 }
617 else 649
618 {
619 obp = get_objectlinkpt (); 650 oblinkpt *obp = get_objectlinkpt ();
620 obp->value = connected; 651 obp->id = id;
621 652
622 obp->next = map->buttons; 653 obp->next = map->buttons;
623 map->buttons = obp; 654 map->buttons = obp;
624 obp->link = ol; 655 obp->link = ol;
625 }
626} 656}
627 657
628/* 658/*
629 * Remove the object from the linked lists of buttons in the map. 659 * Remove the object from the linked lists of buttons in the map.
630 * This is only needed by editors. 660 * This is only needed by editors.
631 */ 661 */
632
633void 662void
634remove_button_link (object *op) 663object::remove_link ()
635{ 664{
636 oblinkpt *obp; 665 if (!map)
637 objectlink **olp, *ol;
638
639 if (op->map == NULL)
640 { 666 {
641 LOG (llevError, "remove_button_link() in object without map.\n"); 667 LOG (llevError, "remove_button_link() in object without map.\n");
642 return; 668 return;
643 } 669 }
644 670
645 if (!QUERY_FLAG (op, FLAG_IS_LINKED)) 671 if (!flag [FLAG_IS_LINKED])
646 { 672 {
647 LOG (llevError, "remove_button_linked() in unlinked object.\n"); 673 LOG (llevError, "remove_button_linked() in unlinked object.\n");
648 return; 674 return;
649 } 675 }
650 676
677 flag [FLAG_IS_LINKED] = false;
678
651 for (obp = op->map->buttons; obp; obp = obp->next) 679 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
652 for (olp = &obp->link; (ol = *olp); olp = &ol->next) 680 for (objectlink **olp = &obp->link; *olp; olp = &(*olp)->next)
653 if (ol->ob == op) 681 if ((*olp)->ob == this)
654 { 682 {
655 683 objectlink *ol = *olp;
656/* LOG(llevDebug, "Removed link %d in button %s and map %s.\n",
657 obp->value, op->name, op->map->path);
658*/
659 *olp = ol->next; 684 *olp = ol->next;
660 delete ol; 685 delete ol;
661 return; 686 return;
662 } 687 }
663 688
664 LOG (llevError, "remove_button_linked(): couldn't find object.\n"); 689 LOG (llevError, "remove_button_linked(): couldn't find object.\n");
665 CLEAR_FLAG (op, FLAG_IS_LINKED); 690}
691
692/*
693 * Updates every button on the map (by calling update_button() for them).
694 */
695void
696maptile::update_buttons ()
697{
698 for (oblinkpt *obp = buttons; obp; obp = obp->next)
699 for (objectlink *ol = obp->link; ol; ol = ol->next)
700 {
701 if (!ol->ob)
702 {
703 LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n",
704 ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, &obp->id);
705 continue;
706 }
707
708 if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL)
709 {
710 update_button (ol->ob, 0);
711 break;
712 }
713 }
666} 714}
667 715
668/* 716/*
669 * Gets the objectlink for this connection from the map. 717 * Gets the objectlink for this connection from the map.
670 */ 718 */
671oblinkpt * 719oblinkpt *
672get_connection_links (maptile *map, long connection) 720maptile::find_link (shstr_tmp id)
673{ 721{
674 for (oblinkpt * obp = map->buttons; obp; obp = obp->next) 722 for (oblinkpt *obp = buttons; obp; obp = obp->next)
675 if (obp->value == connection) 723 if (obp->id == id)
676 return obp; 724 return obp;
677 725
678 return 0; 726 return 0;
679} 727}
680 728
681/* 729/*
682 * Return the first objectlink in the objects linked to this one 730 * Return the first objectlink in the objects linked to this one
683 */ 731 */
684
685oblinkpt * 732oblinkpt *
686get_button_links (const object *button) 733object::find_link () const
687{ 734{
688 oblinkpt *obp; 735 if (map)
689 objectlink *ol;
690
691 if (!button->map)
692 return NULL;
693
694 for (obp = button->map->buttons; obp; obp = obp->next) 736 for (oblinkpt *obp = map->buttons; obp; obp = obp->next)
695 for (ol = obp->link; ol; ol = ol->next) 737 for (objectlink *ol = obp->link; ol; ol = ol->next)
696 if (ol->ob == button) 738 if (ol->ob == this)
697 return obp; 739 return obp;
698 740
699 return NULL;
700}
701
702/*
703 * Made as a separate function to increase efficiency
704 */
705
706int
707get_button_value (const object *button)
708{
709 oblinkpt *obp;
710 objectlink *ol;
711
712 if (!button->map)
713 return 0;
714 for (obp = button->map->buttons; obp; obp = obp->next)
715 for (ol = obp->link; ol; ol = ol->next)
716 if (ol->ob == button)
717 return obp->value;
718 return 0; 741 return 0;
719} 742}
720 743
721/* This routine makes monsters who are 744/* This routine makes monsters who are
722 * standing on the 'mood floor' change their 745 * standing on the 'mood floor' change their
723 * disposition if it is different. 746 * disposition if it is different.
724 * If floor is to be triggered must have 747 * If floor is to be triggered must have
725 * a speed of zero (default is 1 for all 748 * a speed of zero (default is 1 for all
726 * but the charm floor type). 749 * but the charm floor type).
727 * by b.t. thomas@nomad.astro.psu.edu 750 * by b.t. thomas@nomad.astro.psu.edu
728 */ 751 */
729
730void 752void
731do_mood_floor (object *op, object *source) 753do_mood_floor (object *op, object *source)
732{ 754{
733 if (!source) 755 if (!source)
734 source = op; 756 source = op;
739 return; 761 return;
740 762
741 object *tmp; 763 object *tmp;
742 764
743 for (tmp = ms.top; tmp; tmp = tmp->below) 765 for (tmp = ms.top; tmp; tmp = tmp->below)
744 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 766 if (tmp->flag [FLAG_MONSTER])
745 break; 767 break;
746 768
747 /* doesn't effect players, and if there is a player on this space, won't also 769 /* doesn't effect players, and if there is a player on this space, won't also
748 * be a monster here. 770 * be a monster here.
749 */ 771 */
752 return; 774 return;
753 775
754 switch (op->last_sp) 776 switch (op->last_sp)
755 { 777 {
756 case 0: /* furious--make all monsters mad */ 778 case 0: /* furious--make all monsters mad */
757 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 779 if (tmp->flag [FLAG_UNAGGRESSIVE])
758 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 780 tmp->clr_flag (FLAG_UNAGGRESSIVE);
759 781
760 if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) 782 if (tmp->flag [FLAG_FRIENDLY])
761 { 783 {
762 tmp->attack_movement = 0; 784 tmp->attack_movement = 0;
763 /* lots of checks here, but want to make sure we don't 785 /* lots of checks here, but want to make sure we don't
764 * dereference a null value 786 * dereference a null value
765 */ 787 */
774 remove_friendly_object (tmp); 796 remove_friendly_object (tmp);
775 } 797 }
776 break; 798 break;
777 799
778 case 1: /* angry -- get neutral monsters mad */ 800 case 1: /* angry -- get neutral monsters mad */
779 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY)) 801 if (tmp->flag [FLAG_UNAGGRESSIVE] && !tmp->flag [FLAG_FRIENDLY])
780 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 802 tmp->clr_flag (FLAG_UNAGGRESSIVE);
781 break; 803 break;
782 804
783 case 2: /* calm -- pacify unfriendly monsters */ 805 case 2: /* calm -- pacify unfriendly monsters */
784 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 806 tmp->set_flag (FLAG_UNAGGRESSIVE);
785 break; 807 break;
786 808
787 case 3: /* make all monsters fall asleep */ 809 case 3: /* make all monsters fall asleep */
788 SET_FLAG (tmp, FLAG_SLEEP); 810 tmp->set_flag (FLAG_SLEEP);
789 break; 811 break;
790 812
791 case 4: /* charm all monsters */ 813 case 4: /* charm all monsters */
792 if (op == source) 814 if (op == source)
793 break; /* only if 'connected' */ 815 break; /* only if 'connected' */
794 816
795 if (object *pl = source->ms ().player ()) 817 if (object *pl = source->ms ().player ())
796 { 818 {
797 tmp->set_owner (pl); 819 tmp->set_owner (pl);
798 SET_FLAG (tmp, FLAG_MONSTER); 820 tmp->set_flag (FLAG_MONSTER);
799 821
800 tmp->stats.exp = 0; 822 tmp->stats.exp = 0;
801 823
802 add_friendly_object (tmp); 824 add_friendly_object (tmp);
803 tmp->attack_movement = PETMOVE; 825 tmp->attack_movement = PETMOVE;
804 } 826 }
805 break; 827 break;
806 828
807 case 6: // kill monsters 829 case 6: // kill monsters
808 if (!QUERY_FLAG (tmp, FLAG_FRIENDLY)) 830 if (!tmp->flag [FLAG_FRIENDLY])
809 break; 831 break;
810 832
811 // FALL THROUGH 833 // FALL THROUGH
812 case 5: // kill all alives 834 case 5: // kill all alives
813 if (!tmp->flag [FLAG_PRECIOUS]) 835 if (!tmp->flag [FLAG_PRECIOUS])
853 return tmp; 875 return tmp;
854 } 876 }
855 return NULL; 877 return NULL;
856} 878}
857 879
858/* check_inv(), a function to search the inventory, 880/* check_inv(), a function to search the inventory,
859 * of a player and then based on a set of conditions, 881 * of a player and then based on a set of conditions,
860 * the square will activate connected items. 882 * the square will activate connected items.
861 * Monsters can't trigger this square (for now) 883 * Monsters can't trigger this square (for now)
862 * Values are: last_sp = 1/0 obj/no obj triggers 884 * Values are: last_sp = 1/0 obj/no obj triggers
863 * last_heal = 1/0 remove/dont remove obj if triggered 885 * last_heal = 1/0 remove/dont remove obj if triggered
864 * -b.t. (thomas@nomad.astro.psu.edu 886 * -b.t. (thomas@nomad.astro.psu.edu
865 * 887 *
866 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op 888 * Tue Dec 19 15:34:00 CET 2006 elmex: changed the function to ignore op
867 * because the check-inventory semantic essentially only applies when 889 * because the check-inventory semantic essentially only applies when
868 * something is above the inventory checker. 890 * something is above the inventory checker.
869 * The semantic prior this change was: trigger if something has moved on or off 891 * The semantic prior this change was: trigger if something has moved on or off
872 * away, and then leaves the inventory checker. That would've caused an always-enabled 894 * away, and then leaves the inventory checker. That would've caused an always-enabled
873 * state in the inventory checker. This won't happen anymore now. 895 * state in the inventory checker. This won't happen anymore now.
874 * 896 *
875 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check 897 * Wed Jan 10 11:34:26 CET 2007 elmex: fixed this function, we now check
876 * whether op is on this mapspace or not, because the value (1|0) depends 898 * whether op is on this mapspace or not, because the value (1|0) depends
877 * on this information. also make sure to only push_button if op has 899 * on this information. also make sure to only push_button if op has
878 * a matching item (because when we do a push_button with value=0 timed gates 900 * a matching item (because when we do a push_button with value=0 timed gates
879 * will still open)! (i hope i got the semantics right this time) 901 * will still open)! (i hope i got the semantics right this time)
880 * 902 *
881 */ 903 */
882void 904void
898 { 920 {
899 if (trig->last_heal) 921 if (trig->last_heal)
900 match->decrease (); 922 match->decrease ();
901 923
902 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
903 push_button (trig); 925 push_button (trig, op);
904 } 926 }
905 else if (!match && !trig->last_sp) // match == not having 927 else if (!match && !trig->last_sp) // match == not having
906 { 928 {
907 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
908 push_button (trig); 930 push_button (trig, op);
909 } 931 }
910} 932}
911 933

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines