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.7 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.11 by root, Sat Sep 16 22:24:12 2006 UTC

1
2/*
3 * static char *rcsid_button_c =
4 * "$Id: button.C,v 1.7 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <funcpoint.h> 25#include <funcpoint.h>
32 26
193 * the connection was 'state' or 'released'. So that you can activate objects 187 * the connection was 'state' or 'released'. So that you can activate objects
194 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. 188 * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly.
195 * 189 *
196 */ 190 */
197void 191void
198activate_connection (mapstruct *map, long connection, bool state) 192activate_connection (maptile *map, long connection, bool state)
199{ 193{
200 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) 194 if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state)))
201 return; 195 return;
202 196
203 oblinkpt *obp = get_connection_links (map, connection); 197 oblinkpt *obp = get_connection_links (map, connection);
287/* 281/*
288 * Updates every button on the map (by calling update_button() for them). 282 * Updates every button on the map (by calling update_button() for them).
289 */ 283 */
290 284
291void 285void
292update_buttons (mapstruct *m) 286update_buttons (maptile *m)
293{ 287{
294 objectlink *ol; 288 objectlink *ol;
295 oblinkpt *obp; 289 oblinkpt *obp;
296 290
297 for (obp = m->buttons; obp; obp = obp->next) 291 for (obp = m->buttons; obp; obp = obp->next)
364 return 1; 358 return 1;
365 } 359 }
366 return 0; 360 return 0;
367} 361}
368 362
369
370/* 363/*
371 * operate_altar checks if sacrifice was accepted and removes sacrificed 364 * operate_altar checks if sacrifice was accepted and removes sacrificed
372 * objects. If sacrifice was succeed return 1 else 0. Might be better to 365 * objects. If sacrifice was succeed return 1 else 0. Might be better to
373 * call check_altar_sacrifice (above) than depend on the return value, 366 * call check_altar_sacrifice (above) than depend on the return value,
374 * since operate_altar will remove the sacrifice also. 367 * since operate_altar will remove the sacrifice also.
375 * 368 *
376 * If this function returns 1, '*sacrifice' is modified to point to the 369 * If this function returns 1, '*sacrifice' is modified to point to the
377 * remaining sacrifice, or is set to NULL if the sacrifice was used up. 370 * remaining sacrifice, or is set to NULL if the sacrifice was used up.
378 */ 371 */
379
380int 372int
381operate_altar (object *altar, object **sacrifice) 373operate_altar (object *altar, object **sacrifice)
382{ 374{
383
384 if (!altar->map) 375 if (!altar->map)
385 { 376 {
386 LOG (llevError, "BUG: operate_altar(): altar has no map\n"); 377 LOG (llevError, "BUG: operate_altar(): altar has no map\n");
387 return 0; 378 return 0;
388 } 379 }
401 int number = NROF_SACRIFICE (altar) / (*sacrifice)->value; 392 int number = NROF_SACRIFICE (altar) / (*sacrifice)->value;
402 393
403 /* Round up any sacrifices. Altars don't make change either */ 394 /* Round up any sacrifices. Altars don't make change either */
404 if (NROF_SACRIFICE (altar) % (*sacrifice)->value) 395 if (NROF_SACRIFICE (altar) % (*sacrifice)->value)
405 number++; 396 number++;
397
406 *sacrifice = decrease_ob_nr (*sacrifice, number); 398 *sacrifice = decrease_ob_nr (*sacrifice, number);
407 } 399 }
408 else 400 else
409 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); 401 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar));
410 402
411 if (altar->msg) 403 if (altar->msg)
412 new_info_map (NDI_BLACK, altar->map, altar->msg); 404 new_info_map (NDI_BLACK, altar->map, altar->msg);
405
413 return 1; 406 return 1;
414} 407}
415 408
416void 409void
417trigger_move (object *op, int state) /* 1 down and 0 up */ 410trigger_move (object *op, int state) /* 1 down and 0 up */
602 return 0; 595 return 0;
603 } 596 }
604} 597}
605 598
606void 599void
607add_button_link (object *button, mapstruct *map, int connected) 600add_button_link (object *button, maptile *map, int connected)
608{ 601{
609 oblinkpt *obp; 602 oblinkpt *obp;
610 objectlink *ol = get_objectlink (); 603 objectlink *ol = get_objectlink ();
611 604
612 if (!map) 605 if (!map)
682 675
683/* 676/*
684 * Gets the objectlink for this connection from the map. 677 * Gets the objectlink for this connection from the map.
685 */ 678 */
686oblinkpt * 679oblinkpt *
687get_connection_links (mapstruct *map, long connection) 680get_connection_links (maptile *map, long connection)
688{ 681{
689 for (oblinkpt * obp = map->buttons; obp; obp = obp->next) 682 for (oblinkpt * obp = map->buttons; obp; obp = obp->next)
690 if (obp->value == connection) 683 if (obp->value == connection)
691 return obp; 684 return obp;
692 return 0; 685 return 0;
758 if (!tmp || tmp->type == PLAYER) 751 if (!tmp || tmp->type == PLAYER)
759 return; 752 return;
760 753
761 switch (op->last_sp) 754 switch (op->last_sp)
762 { 755 {
763 case 0: /* furious--make all monsters mad */ 756 case 0: /* furious--make all monsters mad */
764 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 757 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
765 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE); 758 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
766 if (QUERY_FLAG (tmp, FLAG_FRIENDLY)) 759 if (QUERY_FLAG (tmp, FLAG_FRIENDLY))
767 { 760 {
768 CLEAR_FLAG (tmp, FLAG_FRIENDLY); 761 CLEAR_FLAG (tmp, FLAG_FRIENDLY);
769 remove_friendly_object (tmp); 762 remove_friendly_object (tmp);
770 tmp->attack_movement = 0; 763 tmp->attack_movement = 0;
771 /* lots of checks here, but want to make sure we don't 764 /* lots of checks here, but want to make sure we don't
772 * dereference a null value 765 * dereference a null value
773 */ 766 */
774 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp) 767 if (tmp->type == GOLEM && tmp->owner && tmp->owner->type == PLAYER && tmp->owner->contr->ranges[range_golem] == tmp)
775 { 768 {
776 tmp->owner->contr->ranges[range_golem] = NULL; 769 tmp->owner->contr->ranges[range_golem] = NULL;
777 tmp->owner->contr->golem_count = 0; 770 tmp->owner->contr->golem_count = 0;
778 } 771 }
779 tmp->owner = 0; 772 tmp->owner = 0;
780 } 773 }
774 break;
775 case 1: /* angry -- get neutral monsters mad */
776 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
777 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
778 break;
779 case 2: /* calm -- pacify unfriendly monsters */
780 if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
781 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
782 break;
783 case 3: /* make all monsters fall asleep */
784 if (!QUERY_FLAG (tmp, FLAG_SLEEP))
785 SET_FLAG (tmp, FLAG_SLEEP);
786 break;
787 case 4: /* charm all monsters */
788 if (op == source)
789 break; /* only if 'connected' */
790
791 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */
792 tmp2->type != PLAYER; tmp2 = tmp2->above)
793 if (tmp2->above == NULL)
794 break;
795
796 if (tmp2->type != PLAYER)
781 break; 797 break;
782 case 1: /* angry -- get neutral monsters mad */
783 if (QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (tmp, FLAG_FRIENDLY))
784 CLEAR_FLAG (tmp, FLAG_UNAGGRESSIVE);
785 break;
786 case 2: /* calm -- pacify unfriendly monsters */
787 if (!QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
788 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
789 break;
790 case 3: /* make all monsters fall asleep */
791 if (!QUERY_FLAG (tmp, FLAG_SLEEP))
792 SET_FLAG (tmp, FLAG_SLEEP);
793 break;
794 case 4: /* charm all monsters */
795 if (op == source)
796 break; /* only if 'connected' */
797
798 for (tmp2 = get_map_ob (source->map, source->x, source->y); /* finding an owner */
799 tmp2->type != PLAYER; tmp2 = tmp2->above)
800 if (tmp2->above == NULL)
801 break;
802
803 if (tmp2->type != PLAYER)
804 break;
805 set_owner (tmp, tmp2); 798 set_owner (tmp, tmp2);
806 SET_FLAG (tmp, FLAG_MONSTER); 799 SET_FLAG (tmp, FLAG_MONSTER);
807 tmp->stats.exp = 0; 800 tmp->stats.exp = 0;
808 SET_FLAG (tmp, FLAG_FRIENDLY); 801 SET_FLAG (tmp, FLAG_FRIENDLY);
809 add_friendly_object (tmp); 802 add_friendly_object (tmp);
810 tmp->attack_movement = PETMOVE; 803 tmp->attack_movement = PETMOVE;
811 break; 804 break;
812 805
813 default: 806 default:
814 break; 807 break;
815
816 } 808 }
817} 809}
818 810
819/* this function returns the object it matches, or NULL if non. 811/* this function returns the object it matches, or NULL if non.
820 * It will descend through containers to find the object. 812 * It will descend through containers to find the object.
879/* This does a minimal check of the button link consistency for object 871/* This does a minimal check of the button link consistency for object
880 * map. All it really does it much sure the object id link that is set 872 * map. All it really does it much sure the object id link that is set
881 * matches what the object has. 873 * matches what the object has.
882 */ 874 */
883void 875void
884verify_button_links (const mapstruct *map) 876verify_button_links (const maptile *map)
885{ 877{
886 oblinkpt *obp; 878 oblinkpt *obp;
887 objectlink *ol; 879 objectlink *ol;
888 880
889 if (!map) 881 if (!map)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines