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.41 by root, Wed Apr 9 14:36:47 2008 UTC vs.
Revision 1.44 by root, Mon Apr 21 23:35:24 2008 UTC

20 * 20 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <funcpoint.h>
26 25
27/* 26/*
28 * This code is no longer highly inefficient 8) 27 * This code is no longer highly inefficient 8)
29 */ 28 */
30 29
235 } 234 }
236 235
237 tmp = ol->ob; 236 tmp = ol->ob;
238 if (tmp->type == BUTTON) 237 if (tmp->type == BUTTON)
239 { 238 {
240 for (ab = tmp->above, tot = 0; ab != NULL; ab = ab->above) 239 for (ab = tmp->above, tot = 0; ab; ab = ab->above)
241 /* Bug? The pedestal code below looks for the head of
242 * the object, this bit doesn't. I'd think we should check
243 * for head here also. Maybe it also makese sense to
244 * make the for ab=tmp->above loop common, and alter
245 * behaviour based on object within that loop?
246 */ 240 {
241 head = ab->head_ ();
247 242
248 /* Basically, if the move_type matches that on what the 243 /* Basically, if the move_type matches that on what the
249 * button wants, we count it. The second check is so that 244 * button wants, we count it. The second check is so that
250 * objects don't move (swords, etc) will count. Note that 245 * objects who don't move (swords, etc) will count. Note that
251 * this means that more work is needed to make buttons 246 * this means that more work is needed to make buttons
252 * that are only triggered by flying objects. 247 * that are only triggered by flying objects.
253 */ 248 */
254 if ((ab->move_type & tmp->move_on) || ab->move_type == 0) 249 if ((head->move_type & tmp->move_on) || head->move_type == 0)
255 tot += ab->weight * (ab->nrof ? ab->nrof : 1) + ab->carrying; 250 tot += head->total_weight ();
251 }
256 252
257 tmp->value = (tot >= tmp->weight) ? 1 : 0; 253 tmp->value = tot >= tmp->weight ? 1 : 0;
258 if (tmp->value)
259 any_down = 1;
260 } 254 }
261 else if (tmp->type == PEDESTAL) 255 else if (tmp->type == PEDESTAL)
262 { 256 {
263 tmp->value = 0; 257 tmp->value = 0;
258
264 for (ab = tmp->above; ab != NULL; ab = ab->above) 259 for (ab = tmp->above; ab; ab = ab->above)
265 { 260 {
266 head = ab->head_ (); 261 head = ab->head_ ();
262
267 /* Same note regarding move_type for buttons above apply here. */ 263 /* Same note regarding move_type for buttons above apply here. */
268 if (((head->move_type & tmp->move_on) || ab->move_type == 0) && 264 if (((head->move_type & tmp->move_on) || ab->move_type == 0) &&
269 (head->race == tmp->slaying || 265 (head->race == tmp->slaying ||
270 ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) || 266 ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) ||
271 (!strcmp (tmp->slaying, "player") && head->type == PLAYER))) 267 (!strcmp (tmp->slaying, "player") && head->type == PLAYER)))
272 tmp->value = 1; 268 tmp->value = 1;
273 } 269 }
274
275 if (tmp->value)
276 any_down = 1;
277 } 270 }
271
272 any_down = any_down || tmp->value;
278 } 273 }
274
279 if (any_down) /* If any other buttons were down, force this to remain down */ 275 if (any_down) /* If any other buttons were down, force this to remain down */
280 op->value = 1; 276 op->value = 1;
281 277
282 /* If this button hasn't changed, don't do anything */ 278 /* If this button hasn't changed, don't do anything */
283 if (op->value != old_value) 279 if (op->value != old_value)
337 333
338 if ((ARCH_SACRIFICE (altar) == sacrifice->arch->archname 334 if ((ARCH_SACRIFICE (altar) == sacrifice->arch->archname
339 || ARCH_SACRIFICE (altar) == sacrifice->name 335 || ARCH_SACRIFICE (altar) == sacrifice->name
340 || ARCH_SACRIFICE (altar) == sacrifice->slaying 336 || ARCH_SACRIFICE (altar) == sacrifice->slaying
341 || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar))) 337 || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar)))
342 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 338 && NROF_SACRIFICE (altar) <= sacrifice->number_of ())
343 return 1; 339 return 1;
344 } 340 }
345 341
346 return 0; 342 return 0;
347} 343}
379 375
380 /* Round up any sacrifices. Altars don't make change either */ 376 /* Round up any sacrifices. Altars don't make change either */
381 if (NROF_SACRIFICE (altar) % (*sacrifice)->value) 377 if (NROF_SACRIFICE (altar) % (*sacrifice)->value)
382 number++; 378 number++;
383 379
384 *sacrifice = decrease_ob_nr (*sacrifice, number); 380 if (!(*sacrifice)->decrease (number))
381 *sacrifice = 0;
385 } 382 }
386 else 383 else
387 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); 384 if (!(*sacrifice)->decrease (NROF_SACRIFICE (altar)))
385 *sacrifice = 0;
388 386
389 if (altar->msg) 387 if (altar->msg)
390 new_info_map (NDI_BLACK, altar->map, altar->msg); 388 new_info_map (NDI_BLACK, altar->map, altar->msg);
391 389
392 return 1; 390 return 1;
442 * button wants, we count it. The second check is so that 440 * button wants, we count it. The second check is so that
443 * objects that don't move (swords, etc) will count. Note that 441 * objects that don't move (swords, etc) will count. Note that
444 * this means that more work is needed to make buttons 442 * this means that more work is needed to make buttons
445 * that are only triggered by flying objects. 443 * that are only triggered by flying objects.
446 */ 444 */
447
448 if ((tmp->move_type & op->move_on) || tmp->move_type == 0) 445 if ((tmp->move_type & op->move_on) || tmp->move_type == 0)
449 { 446 tot += tmp->head_ ()->total_weight ();
450 tot += tmp->weight * (tmp->nrof ? tmp->nrof : 1) + tmp->carrying; 447
451 }
452 if (tot >= op->weight) 448 if (tot >= op->weight)
453 push = 1; 449 push = 1;
450
454 if (op->stats.ac == push) 451 if (op->stats.ac == push)
455 return 0; 452 return 0;
453
456 op->stats.ac = push; 454 op->stats.ac = push;
457 if (NUM_ANIMATIONS (op) > 1) 455 if (NUM_ANIMATIONS (op) > 1)
458 { 456 {
459 SET_ANIMATION (op, push); 457 SET_ANIMATION (op, push);
460 update_object (op, UP_OBJ_FACE); 458 update_object (op, UP_OBJ_FACE);
461 } 459 }
460
462 if (in_movement || !push) 461 if (in_movement || !push)
463 return 0; 462 return 0;
464 } 463 }
465 trigger_move (op, push); 464 trigger_move (op, push);
466 } 465 }
466
467 return 0; 467 return 0;
468 468
469 case TRIGGER_PEDESTAL: 469 case TRIGGER_PEDESTAL:
470 if (cause) 470 if (cause)
471 { 471 {
894 // and we have to set the value to 0 894 // and we have to set the value to 0
895 895
896 if (match && trig->last_sp) // match == having 896 if (match && trig->last_sp) // match == having
897 { 897 {
898 if (trig->last_heal) 898 if (trig->last_heal)
899 decrease_ob (match); 899 match->decrease ();
900 900
901 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left 901 trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left
902 push_button (trig); 902 push_button (trig);
903 } 903 }
904 else if (!match && !trig->last_sp) // match == not having 904 else if (!match && !trig->last_sp) // match == not having

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines