ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.31 by root, Sat Sep 16 22:24:12 2006 UTC vs.
Revision 1.45 by root, Wed Dec 20 09:14:21 2006 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26#include <funcpoint.h>
27 27
28#include <loader.h> 28#include <loader.h>
29#ifndef WIN32 /* ---win32 exclude header */
30# include <unistd.h> 29#include <unistd.h>
31#endif /* win32 */
32 30
33#include "path.h" 31#include "path.h"
34
35
36extern int nrofallocobjects, nroffreeobjects;
37 32
38/* 33/*
39 * Returns the maptile which has a name matching the given argument. 34 * Returns the maptile which has a name matching the given argument.
40 * return NULL if no match is found. 35 * return NULL if no match is found.
41 */ 36 */
159int 154int
160check_path (const char *name, int prepend_dir) 155check_path (const char *name, int prepend_dir)
161{ 156{
162 char buf[MAX_BUF]; 157 char buf[MAX_BUF];
163 158
164#ifndef WIN32
165 char *endbuf; 159 char *endbuf;
166 struct stat statbuf; 160 struct stat statbuf;
167 int mode = 0; 161 int mode = 0;
168#endif
169 162
170 if (prepend_dir) 163 if (prepend_dir)
171 strcpy (buf, create_pathname (name)); 164 strcpy (buf, create_pathname (name));
172 else 165 else
173 strcpy (buf, name); 166 strcpy (buf, name);
174#ifdef WIN32 /* ***win32: check this sucker in windows style. */
175 return (_access (buf, 0));
176#else
177 167
178 /* old method (strchr(buf, '\0')) seemd very odd to me - 168 /* old method (strchr(buf, '\0')) seemd very odd to me -
179 * this method should be equivalant and is clearer. 169 * this method should be equivalant and is clearer.
180 * Can not use strcat because we need to cycle through 170 * Can not use strcat because we need to cycle through
181 * all the names. 171 * all the names.
194 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 184 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
195 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) 185 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH))
196 mode |= 2; 186 mode |= 2;
197 187
198 return (mode); 188 return (mode);
199#endif
200} 189}
201 190
202/* 191/*
203 * Prints out debug-information about a map. 192 * Prints out debug-information about a map.
204 * Dumping these at llevError doesn't seem right, but is 193 * Dumping these at llevError doesn't seem right, but is
275 retval |= mp->spaces[newx + mp->width * newy].flags; 264 retval |= mp->spaces[newx + mp->width * newy].flags;
276 265
277 return retval; 266 return retval;
278} 267}
279 268
280
281/* 269/*
282 * Returns true if the given coordinate is blocked except by the 270 * Returns true if the given coordinate is blocked except by the
283 * object passed is not blocking. This is used with 271 * object passed is not blocking. This is used with
284 * multipart monsters - if we want to see if a 2x2 monster 272 * multipart monsters - if we want to see if a 2x2 monster
285 * can move 1 space to the left, we don't want its own area 273 * can move 1 space to the left, we don't want its own area
288 * monster. 276 * monster.
289 * m, x, y are the target map/coordinates - needed for map tiling. 277 * m, x, y are the target map/coordinates - needed for map tiling.
290 * the coordinates & map passed in should have been updated for tiling 278 * the coordinates & map passed in should have been updated for tiling
291 * by the caller. 279 * by the caller.
292 */ 280 */
293
294int 281int
295blocked_link (object *ob, maptile *m, int sx, int sy) 282blocked_link (object *ob, maptile *m, int sx, int sy)
296{ 283{
297 object *tmp; 284 object *tmp;
298 int mflags, blocked; 285 int mflags, blocked;
336 /* We basically go through the stack of objects, and if there is 323 /* We basically go through the stack of objects, and if there is
337 * some other object that has NO_PASS or FLAG_ALIVE set, return 324 * some other object that has NO_PASS or FLAG_ALIVE set, return
338 * true. If we get through the entire stack, that must mean 325 * true. If we get through the entire stack, that must mean
339 * ob is blocking it, so return 0. 326 * ob is blocking it, so return 0.
340 */ 327 */
341 for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) 328 for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above)
342 { 329 {
343 330
344 /* This must be before the checks below. Code for inventory checkers. */ 331 /* This must be before the checks below. Code for inventory checkers. */
345 if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) 332 if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp))
346 { 333 {
410 * 397 *
411 * Note this used to be arch_blocked, but with new movement 398 * Note this used to be arch_blocked, but with new movement
412 * code, we need to have actual object to check its move_type 399 * code, we need to have actual object to check its move_type
413 * against the move_block values. 400 * against the move_block values.
414 */ 401 */
415
416int 402int
417ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) 403ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
418{ 404{
419 archetype *tmp; 405 archetype *tmp;
420 int flag; 406 int flag;
450 436
451 /* Note it is intentional that we check ob - the movement type of the 437 /* Note it is intentional that we check ob - the movement type of the
452 * head of the object should correspond for the entire object. 438 * head of the object should correspond for the entire object.
453 */ 439 */
454 if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) 440 if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy)))
455 return AB_NO_PASS; 441 return P_NO_PASS;
456
457 } 442 }
443
458 return 0; 444 return 0;
459} 445}
460 446
461/* When the map is loaded, load_object does not actually insert objects 447/* When the map is loaded, load_object does not actually insert objects
462 * into inventory, but just links them. What this does is go through 448 * into inventory, but just links them. What this does is go through
499 object *tmp, *op, *last, *above; 485 object *tmp, *op, *last, *above;
500 archetype *at; 486 archetype *at;
501 487
502 for (x = 0; x < MAP_WIDTH (m); x++) 488 for (x = 0; x < MAP_WIDTH (m); x++)
503 for (y = 0; y < MAP_HEIGHT (m); y++) 489 for (y = 0; y < MAP_HEIGHT (m); y++)
504 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) 490 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
505 { 491 {
506 above = tmp->above; 492 above = tmp->above;
507 493
508 /* already multipart - don't do anything more */ 494 /* already multipart - don't do anything more */
509 if (tmp->head || tmp->more) 495 if (tmp->head || tmp->more)
544{ 530{
545 int i, j; 531 int i, j;
546 int unique; 532 int unique;
547 object *op, *prev = NULL, *last_more = NULL, *otmp; 533 object *op, *prev = NULL, *last_more = NULL, *otmp;
548 534
549 op = get_object (); 535 op = object::create ();
550 op->map = m; /* To handle buttons correctly */ 536 op->map = m; /* To handle buttons correctly */
551 537
552 while ((i = load_object (fp, op, mapflags))) 538 while ((i = load_object (fp, op, mapflags)))
553 { 539 {
554 /* if the archetype for the object is null, means that we 540 /* if the archetype for the object is null, means that we
562 } 548 }
563 549
564 550
565 switch (i) 551 switch (i)
566 { 552 {
567 case LL_NORMAL: 553 case LL_NORMAL:
568 /* if we are loading an overlay, put the floors on the bottom */ 554 /* if we are loading an overlay, put the floors on the bottom */
569 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 555 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
570 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 556 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
571 else 557 else
572 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 558 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
573 559
574 if (op->inv) 560 if (op->inv)
575 sum_weight (op); 561 sum_weight (op);
576 562
577 prev = op, last_more = op; 563 prev = op, last_more = op;
578 break; 564 break;
579 565
580 case LL_MORE: 566 case LL_MORE:
581 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 567 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
582 op->head = prev, last_more->more = op, last_more = op; 568 op->head = prev, last_more->more = op, last_more = op;
583 break; 569 break;
584 } 570 }
585 571
586 if (mapflags & MAP_STYLE) 572 if (mapflags & MAP_STYLE)
587 remove_from_active_list (op); 573 remove_from_active_list (op);
588 574
589 op = get_object (); 575 op = object::create ();
590 op->map = m; 576 op->map = m;
591 } 577 }
592 578
593 for (i = 0; i < m->width; i++) 579 for (i = 0; i < m->width; i++)
594 { 580 {
595 for (j = 0; j < m->height; j++) 581 for (j = 0; j < m->height; j++)
596 { 582 {
597 unique = 0; 583 unique = 0;
598 /* check for unique items, or unique squares */ 584 /* check for unique items, or unique squares */
599 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) 585 for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above)
600 { 586 {
601 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) 587 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
602 unique = 1; 588 unique = 1;
589
603 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 590 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
604 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 591 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
605 } 592 }
606 } 593 }
607 } 594 }
608 595
609 free_object (op); 596 op->destroy ();
610 link_multipart_objects (m); 597 link_multipart_objects (m);
611} 598}
612 599
613/* This saves all the objects on the map in a non destructive fashion. 600/* This saves all the objects on the map in a non destructive fashion.
614 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 601 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
624 /* first pass - save one-part objects */ 611 /* first pass - save one-part objects */
625 for (i = 0; i < MAP_WIDTH (m); i++) 612 for (i = 0; i < MAP_WIDTH (m); i++)
626 for (j = 0; j < MAP_HEIGHT (m); j++) 613 for (j = 0; j < MAP_HEIGHT (m); j++)
627 { 614 {
628 unique = 0; 615 unique = 0;
629 for (op = get_map_ob (m, i, j); op; op = op->above) 616 for (op = GET_MAP_OB (m, i, j); op; op = op->above)
630 { 617 {
631 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 618 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
632 unique = 1; 619 unique = 1;
633 620
634 if (op->type == PLAYER) 621 if (op->type == PLAYER)
635 {
636 LOG (llevDebug, "Player on map that is being saved\n");
637 continue; 622 continue;
638 }
639 623
640 if (op->head || op->owner) 624 if (op->head || op->owner)
641 continue; 625 continue;
642 626
643 if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) 627 if (unique || QUERY_FLAG (op, FLAG_UNIQUE))
644 save_object (fp2, op, 3); 628 save_object (fp2, op, 3);
645 else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) 629 else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID))))
646 save_object (fp, op, 3); 630 save_object (fp, op, 3);
631 }
632 }
633}
647 634
648 } /* for this space */ 635maptile::maptile ()
649 } /* for this j */ 636{
637 in_memory = MAP_SWAPPED;
638 /* The maps used to pick up default x and y values from the
639 * map archetype. Mimic that behaviour.
640 */
641 MAP_WIDTH (this) = 16;
642 MAP_HEIGHT (this) = 16;
643 MAP_RESET_TIMEOUT (this) = 0;
644 MAP_TIMEOUT (this) = 300;
645 MAP_ENTER_X (this) = 0;
646 MAP_ENTER_Y (this) = 0;
647 /*set part to -1 indicating conversion to weather map not yet done */
648 MAP_WORLDPARTX (this) = -1;
649 MAP_WORLDPARTY (this) = -1;
650} 650}
651 651
652/* 652/*
653 * Allocates, initialises, and returns a pointer to a maptile. 653 * Allocates, initialises, and returns a pointer to a maptile.
654 * Modified to no longer take a path option which was not being 654 * Modified to no longer take a path option which was not being
655 * used anyways. MSW 2001-07-01 655 * used anyways. MSW 2001-07-01
656 */ 656 */
657
658maptile * 657maptile *
659get_linked_map (void) 658get_linked_map (void)
660{ 659{
661 maptile *map = new maptile; 660 maptile *mp, *map = new maptile;
662 maptile *mp;
663 661
664 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 662 for (mp = first_map; mp && mp->next; mp = mp->next);
663
665 if (mp == NULL) 664 if (mp == NULL)
666 first_map = map; 665 first_map = map;
667 else 666 else
668 mp->next = map; 667 mp->next = map;
669 668
670 map->in_memory = MAP_SWAPPED;
671 /* The maps used to pick up default x and y values from the
672 * map archetype. Mimic that behaviour.
673 */
674 MAP_WIDTH (map) = 16;
675 MAP_HEIGHT (map) = 16;
676 MAP_RESET_TIMEOUT (map) = 0;
677 MAP_TIMEOUT (map) = 300;
678 MAP_ENTER_X (map) = 0;
679 MAP_ENTER_Y (map) = 0;
680 /*set part to -1 indicating conversion to weather map not yet done */
681 MAP_WORLDPARTX (map) = -1;
682 MAP_WORLDPARTY (map) = -1;
683 return map; 669 return map;
684} 670}
685 671
686/* 672/*
687 * Allocates the arrays contained in a maptile. 673 * Allocates the arrays contained in a maptile.
688 * This basically allocates the dynamic array of spaces for the 674 * This basically allocates the dynamic array of spaces for the
689 * map. 675 * map.
690 */ 676 */
691
692void 677void
693allocate_map (maptile *m) 678maptile::allocate ()
694{ 679{
695 m->in_memory = MAP_IN_MEMORY; 680 in_memory = MAP_IN_MEMORY;
681
696 /* Log this condition and free the storage. We could I suppose 682 /* Log this condition and free the storage. We could I suppose
697 * realloc, but if the caller is presuming the data will be intact, 683 * realloc, but if the caller is presuming the data will be intact,
698 * that is their poor assumption. 684 * that is their poor assumption.
699 */ 685 */
700 if (m->spaces) 686 if (spaces)
701 { 687 {
702 LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); 688 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
703 free (m->spaces); 689 free (spaces);
704 } 690 }
705 691
706 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 692 spaces = (mapspace *)
693 calloc (1, width * height * sizeof (mapspace));
707 694
708 if (m->spaces == NULL) 695 if (!spaces)
709 fatal (OUT_OF_MEMORY); 696 fatal (OUT_OF_MEMORY);
710} 697}
711 698
712/* Create and returns a map of the specific size. Used 699/* Create and returns a map of the specific size. Used
713 * in random map code and the editor. 700 * in random map code and the editor.
718 maptile *m = get_linked_map (); 705 maptile *m = get_linked_map ();
719 706
720 m->width = sizex; 707 m->width = sizex;
721 m->height = sizey; 708 m->height = sizey;
722 m->in_memory = MAP_SWAPPED; 709 m->in_memory = MAP_SWAPPED;
723 allocate_map (m); 710 m->allocate ();
711
724 return m; 712 return m;
725} 713}
726 714
727/* Takes a string from a map definition and outputs a pointer to the array of shopitems 715/* Takes a string from a map definition and outputs a pointer to the array of shopitems
728 * corresponding to that string. Memory is allocated for this, it must be freed 716 * corresponding to that string. Memory is allocated for this, it must be freed
736 char *shop_string, *p, *q, *next_semicolon, *next_colon; 724 char *shop_string, *p, *q, *next_semicolon, *next_colon;
737 shopitems *items = NULL; 725 shopitems *items = NULL;
738 int i = 0, number_of_entries = 0; 726 int i = 0, number_of_entries = 0;
739 const typedata *current_type; 727 const typedata *current_type;
740 728
741 shop_string = strdup_local (input_string); 729 shop_string = strdup (input_string);
742 p = shop_string; 730 p = shop_string;
743 /* first we'll count the entries, we'll need that for allocating the array shortly */ 731 /* first we'll count the entries, we'll need that for allocating the array shortly */
744 while (p) 732 while (p)
745 { 733 {
746 p = strchr (p, ';'); 734 p = strchr (p, ';');
855{ 843{
856 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 844 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
857 int msgpos = 0; 845 int msgpos = 0;
858 int maplorepos = 0; 846 int maplorepos = 0;
859 847
860 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 848 while (fgets (buf, HUGE_BUF, fp) != NULL)
861 { 849 {
862 buf[HUGE_BUF - 1] = 0; 850 buf[HUGE_BUF - 1] = 0;
863 key = buf; 851 key = buf;
852
864 while (isspace (*key)) 853 while (isspace (*key))
865 key++; 854 key++;
855
866 if (*key == 0) 856 if (*key == 0)
867 continue; /* empty line */ 857 continue; /* empty line */
858
868 value = strchr (key, ' '); 859 value = strchr (key, ' ');
860
869 if (!value) 861 if (!value)
870 { 862 {
871 end = strchr (key, '\n'); 863 if ((end = strchr (key, '\n')))
872 if (end != NULL)
873 {
874 *end = 0; 864 *end = 0;
875 }
876 } 865 }
877 else 866 else
878 { 867 {
879 *value = 0; 868 *value = 0;
880 value++; 869 value++;
881 end = strchr (value, '\n'); 870 end = strchr (value, '\n');
871
882 while (isspace (*value)) 872 while (isspace (*value))
883 { 873 {
884 value++; 874 value++;
875
885 if (*value == '\0' || value == end) 876 if (*value == '\0' || value == end)
886 { 877 {
887 /* Nothing but spaces. */ 878 /* Nothing but spaces. */
888 value = NULL; 879 value = NULL;
889 break; 880 break;
912 * that use the parameter. 903 * that use the parameter.
913 */ 904 */
914 905
915 if (!strcmp (key, "msg")) 906 if (!strcmp (key, "msg"))
916 { 907 {
917 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 908 while (fgets (buf, HUGE_BUF, fp) != NULL)
918 { 909 {
919 if (!strcmp (buf, "endmsg\n")) 910 if (!strcmp (buf, "endmsg\n"))
920 break; 911 break;
921 else 912 else
922 { 913 {
929 * with nothing between). There is no reason in those cases to 920 * with nothing between). There is no reason in those cases to
930 * keep the empty message. Also, msgbuf contains garbage data 921 * keep the empty message. Also, msgbuf contains garbage data
931 * when msgpos is zero, so copying it results in crashes 922 * when msgpos is zero, so copying it results in crashes
932 */ 923 */
933 if (msgpos != 0) 924 if (msgpos != 0)
934 m->msg = strdup_local (msgbuf); 925 m->msg = strdup (msgbuf);
935 } 926 }
936 else if (!strcmp (key, "maplore")) 927 else if (!strcmp (key, "maplore"))
937 { 928 {
938 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 929 while (fgets (buf, HUGE_BUF, fp) != NULL)
939 { 930 {
940 if (!strcmp (buf, "endmaplore\n")) 931 if (!strcmp (buf, "endmaplore\n"))
941 break; 932 break;
942 else 933 else
943 { 934 {
945 strcpy (maplorebuf + maplorepos, buf); 936 strcpy (maplorebuf + maplorepos, buf);
946 maplorepos += strlen (buf); 937 maplorepos += strlen (buf);
947 } 938 }
948 } 939 }
949 if (maplorepos != 0) 940 if (maplorepos != 0)
950 m->maplore = strdup_local (maplorebuf); 941 m->maplore = strdup (maplorebuf);
951 } 942 }
952 else if (!strcmp (key, "end")) 943 else if (!strcmp (key, "end"))
953 { 944 {
954 break; 945 break;
955 } 946 }
964 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); 955 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value);
965 } 956 }
966 else if (!strcmp (key, "name")) 957 else if (!strcmp (key, "name"))
967 { 958 {
968 *end = 0; 959 *end = 0;
969 m->name = strdup_local (value); 960 m->name = strdup (value);
970 } 961 }
971 /* first strcmp value on these are old names supported 962 /* first strcmp value on these are old names supported
972 * for compatibility reasons. The new values (second) are 963 * for compatibility reasons. The new values (second) are
973 * what really should be used. 964 * what really should be used.
974 */ 965 */
975 else if (!strcmp (key, "oid")) 966 else if (!strcmp (key, "oid"))
976 {
977 fp.get (m, atoi (value)); 967 fp.get (m, atoi (value));
978 }
979 else if (!strcmp (key, "attach")) 968 else if (!strcmp (key, "attach"))
980 {
981 m->attach = value; 969 m->attach = value;
982 }
983 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 970 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
984 {
985 m->enter_x = atoi (value); 971 m->enter_x = atoi (value);
986 }
987 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 972 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
988 {
989 m->enter_y = atoi (value); 973 m->enter_y = atoi (value);
990 }
991 else if (!strcmp (key, "x") || !strcmp (key, "width")) 974 else if (!strcmp (key, "x") || !strcmp (key, "width"))
992 {
993 m->width = atoi (value); 975 m->width = atoi (value);
994 }
995 else if (!strcmp (key, "y") || !strcmp (key, "height")) 976 else if (!strcmp (key, "y") || !strcmp (key, "height"))
996 {
997 m->height = atoi (value); 977 m->height = atoi (value);
998 }
999 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 978 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
1000 {
1001 m->reset_timeout = atoi (value); 979 m->reset_timeout = atoi (value);
1002 }
1003 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 980 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1004 {
1005 m->timeout = atoi (value); 981 m->timeout = atoi (value);
1006 }
1007 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 982 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1008 { 983 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1009 m->difficulty = atoi (value);
1010 }
1011 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 984 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1012 {
1013 m->darkness = atoi (value); 985 m->darkness = atoi (value);
1014 }
1015 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 986 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1016 {
1017 m->fixed_resettime = atoi (value); 987 m->fixed_resettime = atoi (value);
1018 }
1019 else if (!strcmp (key, "unique")) 988 else if (!strcmp (key, "unique"))
1020 {
1021 m->unique = atoi (value); 989 m->unique = atoi (value);
1022 }
1023 else if (!strcmp (key, "template")) 990 else if (!strcmp (key, "template"))
1024 {
1025 m->templatemap = atoi (value); 991 m->templatemap = atoi (value);
1026 }
1027 else if (!strcmp (key, "region")) 992 else if (!strcmp (key, "region"))
1028 {
1029 m->region = get_region_by_name (value); 993 m->region = get_region_by_name (value);
1030 }
1031 else if (!strcmp (key, "shopitems")) 994 else if (!strcmp (key, "shopitems"))
1032 { 995 {
1033 *end = 0; 996 *end = 0;
1034 m->shopitems = parse_shop_string (value); 997 m->shopitems = parse_shop_string (value);
1035 } 998 }
1036 else if (!strcmp (key, "shopgreed")) 999 else if (!strcmp (key, "shopgreed"))
1037 {
1038 m->shopgreed = atof (value); 1000 m->shopgreed = atof (value);
1039 }
1040 else if (!strcmp (key, "shopmin")) 1001 else if (!strcmp (key, "shopmin"))
1041 {
1042 m->shopmin = atol (value); 1002 m->shopmin = atol (value);
1043 }
1044 else if (!strcmp (key, "shopmax")) 1003 else if (!strcmp (key, "shopmax"))
1045 {
1046 m->shopmax = atol (value); 1004 m->shopmax = atol (value);
1047 }
1048 else if (!strcmp (key, "shoprace")) 1005 else if (!strcmp (key, "shoprace"))
1049 { 1006 {
1050 *end = 0; 1007 *end = 0;
1051 m->shoprace = strdup_local (value); 1008 m->shoprace = strdup (value);
1052 } 1009 }
1053 else if (!strcmp (key, "outdoor")) 1010 else if (!strcmp (key, "outdoor"))
1054 {
1055 m->outdoor = atoi (value); 1011 m->outdoor = atoi (value);
1056 }
1057 else if (!strcmp (key, "temp")) 1012 else if (!strcmp (key, "temp"))
1058 {
1059 m->temp = atoi (value); 1013 m->temp = atoi (value);
1060 }
1061 else if (!strcmp (key, "pressure")) 1014 else if (!strcmp (key, "pressure"))
1062 {
1063 m->pressure = atoi (value); 1015 m->pressure = atoi (value);
1064 }
1065 else if (!strcmp (key, "humid")) 1016 else if (!strcmp (key, "humid"))
1066 {
1067 m->humid = atoi (value); 1017 m->humid = atoi (value);
1068 }
1069 else if (!strcmp (key, "windspeed")) 1018 else if (!strcmp (key, "windspeed"))
1070 {
1071 m->windspeed = atoi (value); 1019 m->windspeed = atoi (value);
1072 }
1073 else if (!strcmp (key, "winddir")) 1020 else if (!strcmp (key, "winddir"))
1074 {
1075 m->winddir = atoi (value); 1021 m->winddir = atoi (value);
1076 }
1077 else if (!strcmp (key, "sky")) 1022 else if (!strcmp (key, "sky"))
1078 {
1079 m->sky = atoi (value); 1023 m->sky = atoi (value);
1080 }
1081 else if (!strcmp (key, "nosmooth")) 1024 else if (!strcmp (key, "nosmooth"))
1082 {
1083 m->nosmooth = atoi (value); 1025 m->nosmooth = atoi (value);
1084 }
1085 else if (!strncmp (key, "tile_path_", 10)) 1026 else if (!strncmp (key, "tile_path_", 10))
1086 { 1027 {
1087 int tile = atoi (key + 10); 1028 int tile = atoi (key + 10);
1088 1029
1089 if (tile < 1 || tile > 4) 1030 if (tile < 1 || tile > 4)
1122 } 1063 }
1123 1064
1124 if (editor) 1065 if (editor)
1125 { 1066 {
1126 /* Use the value as in the file. */ 1067 /* Use the value as in the file. */
1127 m->tile_path[tile - 1] = strdup_local (value); 1068 m->tile_path[tile - 1] = strdup (value);
1128 } 1069 }
1129 else if (path != NULL) 1070 else if (path != NULL)
1130 { 1071 {
1131 /* Use the normalized value. */ 1072 /* Use the normalized value. */
1132 m->tile_path[tile - 1] = strdup_local (path); 1073 m->tile_path[tile - 1] = strdup (path);
1133 } 1074 }
1134 } /* end if tile direction (in)valid */ 1075 } /* end if tile direction (in)valid */
1135 } 1076 }
1136 else 1077 else
1137 {
1138 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); 1078 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value);
1139 }
1140 } 1079 }
1080
1141 if (!key || strcmp (key, "end")) 1081 if (!key || strcmp (key, "end"))
1142 { 1082 {
1143 LOG (llevError, "Got premature eof on map header!\n"); 1083 LOG (llevError, "Got premature eof on map header!\n");
1144 return 1; 1084 return 1;
1145 } 1085 }
1086
1146 return 0; 1087 return 0;
1147} 1088}
1148 1089
1149/* 1090/*
1150 * Opens the file "filename" and reads information about the map 1091 * Opens the file "filename" and reads information about the map
1186 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1127 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1187 delete_map (m); 1128 delete_map (m);
1188 return NULL; 1129 return NULL;
1189 } 1130 }
1190 1131
1191 allocate_map (m); 1132 m->allocate ();
1192 1133
1193 m->in_memory = MAP_LOADING; 1134 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1135 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1136
1196 m->in_memory = MAP_IN_MEMORY; 1137 m->in_memory = MAP_IN_MEMORY;
1242 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1183 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1243 delete_map (m); 1184 delete_map (m);
1244 m = load_original_map (m->path, 0); 1185 m = load_original_map (m->path, 0);
1245 return NULL; 1186 return NULL;
1246 } 1187 }
1188
1247 allocate_map (m); 1189 m->allocate ();
1248 1190
1249 m->in_memory = MAP_LOADING; 1191 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1192 load_objects (m, thawer, 0);
1251 1193
1252 m->in_memory = MAP_IN_MEMORY; 1194 m->in_memory = MAP_IN_MEMORY;
1277 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1219 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1278 delete_map (m); 1220 delete_map (m);
1279 m = load_original_map (m->path, 0); 1221 m = load_original_map (m->path, 0);
1280 return NULL; 1222 return NULL;
1281 } 1223 }
1282 /*allocate_map(m); */ 1224 /*m->allocate ();*/
1283 1225
1284 m->in_memory = MAP_LOADING; 1226 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1227 load_objects (m, thawer, MAP_OVERLAY);
1286 1228
1287 m->in_memory = MAP_IN_MEMORY; 1229 m->in_memory = MAP_IN_MEMORY;
1301 1243
1302 for (i = 0; i < MAP_WIDTH (m); i++) 1244 for (i = 0; i < MAP_WIDTH (m); i++)
1303 for (j = 0; j < MAP_HEIGHT (m); j++) 1245 for (j = 0; j < MAP_HEIGHT (m); j++)
1304 { 1246 {
1305 unique = 0; 1247 unique = 0;
1248
1306 for (op = get_map_ob (m, i, j); op; op = next) 1249 for (op = GET_MAP_OB (m, i, j); op; op = next)
1307 { 1250 {
1308 next = op->above; 1251 next = op->above;
1252
1309 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1253 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1310 unique = 1; 1254 unique = 1;
1255
1311 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1256 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1312 { 1257 {
1313 clean_object (op); 1258 clean_object (op);
1259
1314 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1260 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1315 remove_button_link (op); 1261 remove_button_link (op);
1316 remove_ob (op); 1262
1317 free_object (op); 1263 op->destroy ();
1318 } 1264 }
1319 } 1265 }
1320 } 1266 }
1321} 1267}
1322 1268
1391 make_path_to_file (filename); 1337 make_path_to_file (filename);
1392 } 1338 }
1393 else 1339 else
1394 { 1340 {
1395 if (!m->tmpname) 1341 if (!m->tmpname)
1396 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1342 m->tmpname = tempnam (settings.tmpdir, NULL);
1397 1343
1398 strcpy (filename, m->tmpname); 1344 strcpy (filename, m->tmpname);
1399 } 1345 }
1400 1346
1401 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1347 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1425 print_shop_string (m, shop); 1371 print_shop_string (m, shop);
1426 fprintf (freezer, "shopitems %s\n", shop); 1372 fprintf (freezer, "shopitems %s\n", shop);
1427 } 1373 }
1428 if (m->shopgreed) 1374 if (m->shopgreed)
1429 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1375 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1430#ifndef WIN32
1431 if (m->shopmin) 1376 if (m->shopmin)
1432 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1377 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1433 if (m->shopmax) 1378 if (m->shopmax)
1434 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1379 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1435#else
1436 if (m->shopmin)
1437 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1438 if (m->shopmax)
1439 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1440#endif
1441 if (m->shoprace) 1380 if (m->shoprace)
1442 fprintf (freezer, "shoprace %s\n", m->shoprace); 1381 fprintf (freezer, "shoprace %s\n", m->shoprace);
1443 if (m->darkness) 1382 if (m->darkness)
1444 fprintf (freezer, "darkness %d\n", m->darkness); 1383 fprintf (freezer, "darkness %d\n", m->darkness);
1445 if (m->width) 1384 if (m->width)
1524 object *tmp, *next; 1463 object *tmp, *next;
1525 1464
1526 for (tmp = op->inv; tmp; tmp = next) 1465 for (tmp = op->inv; tmp; tmp = next)
1527 { 1466 {
1528 next = tmp->below; 1467 next = tmp->below;
1468
1529 clean_object (tmp); 1469 clean_object (tmp);
1530 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1470 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1531 remove_button_link (tmp); 1471 remove_button_link (tmp);
1532 remove_ob (tmp); 1472
1533 free_object (tmp); 1473 tmp->destroy ();
1534 } 1474 }
1535} 1475}
1536 1476
1537/* 1477/*
1538 * Remove and free all objects in the given map. 1478 * Remove and free all objects in the given map.
1554 if (op == previous_obj) 1494 if (op == previous_obj)
1555 { 1495 {
1556 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1496 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1557 break; 1497 break;
1558 } 1498 }
1499
1559 previous_obj = op; 1500 previous_obj = op;
1501
1560 if (op->head != NULL) 1502 if (op->head != NULL)
1561 op = op->head; 1503 op = op->head;
1562 1504
1563 /* If the map isn't in memory, free_object will remove and 1505 /* If the map isn't in memory, free_object will remove and
1564 * free objects in op's inventory. So let it do the job. 1506 * free objects in op's inventory. So let it do the job.
1565 */ 1507 */
1566 if (m->in_memory == MAP_IN_MEMORY) 1508 if (m->in_memory == MAP_IN_MEMORY)
1567 clean_object (op); 1509 clean_object (op);
1568 remove_ob (op); 1510
1569 free_object (op); 1511 op->destroy ();
1570 } 1512 }
1571 } 1513 }
1572} 1514}
1573 1515
1574/* 1516/*
1584 if (!m->in_memory) 1526 if (!m->in_memory)
1585 { 1527 {
1586 LOG (llevError, "Trying to free freed map.\n"); 1528 LOG (llevError, "Trying to free freed map.\n");
1587 return; 1529 return;
1588 } 1530 }
1531
1532 // TODO: use new/delete
1533#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1534
1589 if (flag && m->spaces) 1535 if (flag && m->spaces)
1590 free_all_objects (m); 1536 free_all_objects (m);
1591 if (m->name) 1537 if (m->name)
1592 FREE_AND_CLEAR (m->name); 1538 FREE_AND_CLEAR (m->name);
1593 if (m->spaces) 1539 if (m->spaces)
1594 FREE_AND_CLEAR (m->spaces); 1540 FREE_AND_CLEAR (m->spaces);
1595 if (m->msg) 1541 if (m->msg)
1596 FREE_AND_CLEAR (m->msg); 1542 FREE_AND_CLEAR (m->msg);
1597 if (m->maplore) 1543 if (m->maplore)
1598 FREE_AND_CLEAR (m->maplore); 1544 FREE_AND_CLEAR (m->maplore);
1599 if (m->shopitems) 1545
1600 delete[]m->shopitems; 1546 delete [] m->shopitems;
1601 m->shopitems = 0; 1547 m->shopitems = 0;
1548
1602 if (m->shoprace) 1549 if (m->shoprace)
1603 FREE_AND_CLEAR (m->shoprace); 1550 FREE_AND_CLEAR (m->shoprace);
1551
1604 if (m->buttons) 1552 if (m->buttons)
1605 free_objectlinkpt (m->buttons); 1553 free_objectlinkpt (m->buttons);
1554
1606 m->buttons = NULL; 1555 m->buttons = NULL;
1556
1607 for (i = 0; i < 4; i++) 1557 for (i = 0; i < 4; i++)
1608 { 1558 {
1609 if (m->tile_path[i]) 1559 if (m->tile_path[i])
1610 FREE_AND_CLEAR (m->tile_path[i]); 1560 FREE_AND_CLEAR (m->tile_path[i]);
1611 m->tile_map[i] = NULL; 1561 m->tile_map[i] = NULL;
1612 } 1562 }
1563
1613 m->in_memory = MAP_SWAPPED; 1564 m->in_memory = MAP_SWAPPED;
1565
1566#undef FREE_AND_CLEAR
1567
1614} 1568}
1615 1569
1616/* 1570/*
1617 * function: vanish maptile 1571 * function: vanish maptile
1618 * m : pointer to maptile, if NULL no action 1572 * m : pointer to maptile, if NULL no action
1678 else 1632 else
1679 last->next = m->next; 1633 last->next = m->next;
1680 1634
1681 delete m; 1635 delete m;
1682} 1636}
1683
1684
1685 1637
1686/* 1638/*
1687 * Makes sure the given map is loaded and swapped in. 1639 * Makes sure the given map is loaded and swapped in.
1688 * name is path name of the map. 1640 * name is path name of the map.
1689 * flags meaning: 1641 * flags meaning:
1692 * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. 1644 * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player.
1693 * dont do any more name translation on it. 1645 * dont do any more name translation on it.
1694 * 1646 *
1695 * Returns a pointer to the given map. 1647 * Returns a pointer to the given map.
1696 */ 1648 */
1697
1698maptile * 1649maptile *
1699ready_map_name (const char *name, int flags) 1650ready_map_name (const char *name, int flags)
1700{ 1651{
1701 maptile *m; 1652 maptile *m;
1702 1653
1825 return MAP_DIFFICULTY (m); 1776 return MAP_DIFFICULTY (m);
1826 } 1777 }
1827 1778
1828 for (x = 0; x < MAP_WIDTH (m); x++) 1779 for (x = 0; x < MAP_WIDTH (m); x++)
1829 for (y = 0; y < MAP_HEIGHT (m); y++) 1780 for (y = 0; y < MAP_HEIGHT (m); y++)
1830 for (op = get_map_ob (m, x, y); op != NULL; op = op->above) 1781 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
1831 { 1782 {
1832 if (QUERY_FLAG (op, FLAG_MONSTER)) 1783 if (QUERY_FLAG (op, FLAG_MONSTER))
1833 { 1784 {
1834 total_exp += op->stats.exp; 1785 total_exp += op->stats.exp;
1835 monster_cnt++; 1786 monster_cnt++;
1928 /* All clients need to get re-updated for the change */ 1879 /* All clients need to get re-updated for the change */
1929 update_all_map_los (m); 1880 update_all_map_los (m);
1930 return 1; 1881 return 1;
1931} 1882}
1932 1883
1933
1934/* 1884/*
1935 * This function updates various attributes about a specific space 1885 * This function updates various attributes about a specific space
1936 * on the map (what it looks like, whether it blocks magic, 1886 * on the map (what it looks like, whether it blocks magic,
1937 * has a living creatures, prevents people from passing 1887 * has a living creatures, prevents people from passing
1938 * through, etc) 1888 * through, etc)
1939 */ 1889 */
1940void 1890void
1941update_position (maptile *m, int x, int y) 1891update_position (maptile *m, int x, int y)
1942{ 1892{
1943 object *tmp, *last = NULL; 1893 object *tmp, *last = 0;
1944 uint8 flags = 0, oldflags, light = 0, anywhere = 0; 1894 uint8 flags = 0, oldflags, light = 0, anywhere = 0;
1945 New_Face *top, *floor, *middle; 1895 New_Face *top, *floor, *middle;
1946 object *top_obj, *floor_obj, *middle_obj; 1896 object *top_obj, *floor_obj, *middle_obj;
1947 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1897 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1948 1898
1952 LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); 1902 LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
1953 return; 1903 return;
1954 } 1904 }
1955 1905
1956 middle = blank_face; 1906 middle = blank_face;
1957 top = blank_face; 1907 top = blank_face;
1958 floor = blank_face; 1908 floor = blank_face;
1959 1909
1960 middle_obj = NULL; 1910 middle_obj = 0;
1961 top_obj = NULL; 1911 top_obj = 0;
1962 floor_obj = NULL; 1912 floor_obj = 0;
1963 1913
1964 for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) 1914 for (tmp = GET_MAP_OB (m, x, y); tmp; last = tmp, tmp = tmp->above)
1965 { 1915 {
1966
1967 /* This could be made additive I guess (two lights better than 1916 /* This could be made additive I guess (two lights better than
1968 * one). But if so, it shouldn't be a simple additive - 2 1917 * one). But if so, it shouldn't be a simple additive - 2
1969 * light bulbs do not illuminate twice as far as once since 1918 * light bulbs do not illuminate twice as far as once since
1970 * it is a disapation factor that is squared (or is it cubed?) 1919 * it is a dissapation factor that is cubed.
1971 */ 1920 */
1972 if (tmp->glow_radius > light) 1921 if (tmp->glow_radius > light)
1973 light = tmp->glow_radius; 1922 light = tmp->glow_radius;
1974 1923
1975 /* This call is needed in order to update objects the player 1924 /* This call is needed in order to update objects the player
2013 { 1962 {
2014 middle = tmp->face; 1963 middle = tmp->face;
2015 middle_obj = tmp; 1964 middle_obj = tmp;
2016 } 1965 }
2017 } 1966 }
1967
2018 if (tmp == tmp->above) 1968 if (tmp == tmp->above)
2019 { 1969 {
2020 LOG (llevError, "Error in structure of map\n"); 1970 LOG (llevError, "Error in structure of map\n");
2021 exit (-1); 1971 exit (-1);
2022 } 1972 }
2023 1973
2024 move_slow |= tmp->move_slow; 1974 move_slow |= tmp->move_slow;
2025 move_block |= tmp->move_block; 1975 move_block |= tmp->move_block;
2026 move_on |= tmp->move_on; 1976 move_on |= tmp->move_on;
2027 move_off |= tmp->move_off; 1977 move_off |= tmp->move_off;
2028 move_allow |= tmp->move_allow; 1978 move_allow |= tmp->move_allow;
2029 1979
2030 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2031 flags |= P_IS_ALIVE;
2032 if (QUERY_FLAG (tmp, FLAG_NO_MAGIC))
2033 flags |= P_NO_MAGIC;
2034 if (QUERY_FLAG (tmp, FLAG_DAMNED))
2035 flags |= P_NO_CLERIC;
2036 if (tmp->type == SAFE_GROUND)
2037 flags |= P_SAFE;
2038
2039 if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) 1980 if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW;
2040 flags |= P_BLOCKSVIEW; 1981 if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC;
2041 } /* for stack of objects */ 1982 if (tmp->type == PLAYER) flags |= P_PLAYER;
1983 if (tmp->type == SAFE_GROUND) flags |= P_SAFE;
1984 if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE;
1985 if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC;
1986 }
2042 1987
2043 /* we don't want to rely on this function to have accurate flags, but 1988 /* we don't want to rely on this function to have accurate flags, but
2044 * since we're already doing the work, we calculate them here. 1989 * since we're already doing the work, we calculate them here.
2045 * if they don't match, logic is broken someplace. 1990 * if they don't match, logic is broken someplace.
2046 */ 1991 */
2047 if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) 1992 if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR)))
2048 {
2049 LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", 1993 LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n",
2050 m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); 1994 m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags);
2051 } 1995
2052 SET_MAP_FLAGS (m, x, y, flags); 1996 mapspace &s = m->at (x, y);
2053 SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); 1997
2054 SET_MAP_MOVE_ON (m, x, y, move_on); 1998 s.flags = flags;
2055 SET_MAP_MOVE_OFF (m, x, y, move_off); 1999 s.move_block = move_block & ~move_allow;
2056 SET_MAP_MOVE_SLOW (m, x, y, move_slow); 2000 s.move_on = move_on;
2001 s.move_off = move_off;
2002 s.move_slow = move_slow;
2057 2003
2058 /* At this point, we have a floor face (if there is a floor), 2004 /* At this point, we have a floor face (if there is a floor),
2059 * and the floor is set - we are not going to touch it at 2005 * and the floor is set - we are not going to touch it at
2060 * this point. 2006 * this point.
2061 * middle contains the highest visibility face. 2007 * middle contains the highest visibility face.
2115 break; 2061 break;
2116 } 2062 }
2117 } 2063 }
2118 } 2064 }
2119 } 2065 }
2066
2120 if (middle == floor) 2067 if (middle == floor)
2121 middle = blank_face; 2068 middle = blank_face;
2069
2122 if (top == middle) 2070 if (top == middle)
2123 middle = blank_face; 2071 middle = blank_face;
2072
2124 SET_MAP_FACE (m, x, y, top, 0); 2073 SET_MAP_FACE (m, x, y, top, 0);
2125 if (top != blank_face) 2074 if (top != blank_face)
2126 SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); 2075 SET_MAP_FACE_OBJ (m, x, y, top_obj, 0);
2127 else 2076 else
2128 SET_MAP_FACE_OBJ (m, x, y, NULL, 0); 2077 SET_MAP_FACE_OBJ (m, x, y, NULL, 0);
2078
2129 SET_MAP_FACE (m, x, y, middle, 1); 2079 SET_MAP_FACE (m, x, y, middle, 1);
2130 if (middle != blank_face) 2080 if (middle != blank_face)
2131 SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); 2081 SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1);
2132 else 2082 else
2133 SET_MAP_FACE_OBJ (m, x, y, NULL, 1); 2083 SET_MAP_FACE_OBJ (m, x, y, NULL, 1);
2084
2134 SET_MAP_FACE (m, x, y, floor, 2); 2085 SET_MAP_FACE (m, x, y, floor, 2);
2135 if (floor != blank_face) 2086 if (floor != blank_face)
2136 SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); 2087 SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2);
2137 else 2088 else
2138 SET_MAP_FACE_OBJ (m, x, y, NULL, 2); 2089 SET_MAP_FACE_OBJ (m, x, y, NULL, 2);
2090
2139 SET_MAP_LIGHT (m, x, y, light); 2091 SET_MAP_LIGHT (m, x, y, light);
2140} 2092}
2141 2093
2142 2094
2143void 2095void
2148 timeout = MAP_RESET_TIMEOUT (map); 2100 timeout = MAP_RESET_TIMEOUT (map);
2149 if (timeout <= 0) 2101 if (timeout <= 0)
2150 timeout = MAP_DEFAULTRESET; 2102 timeout = MAP_DEFAULTRESET;
2151 if (timeout >= MAP_MAXRESET) 2103 if (timeout >= MAP_MAXRESET)
2152 timeout = MAP_MAXRESET; 2104 timeout = MAP_MAXRESET;
2153 MAP_WHEN_RESET (map) = seconds () + timeout; 2105 MAP_WHEN_RESET (map) = time (0) + timeout;
2154} 2106}
2155 2107
2156/* this updates the orig_map->tile_map[tile_num] value after loading 2108/* this updates the orig_map->tile_map[tile_num] value after loading
2157 * the map. It also takes care of linking back the freshly loaded 2109 * the map. It also takes care of linking back the freshly loaded
2158 * maps tile_map values if it tiles back to this one. It returns 2110 * maps tile_map values if it tiles back to this one. It returns

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines