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.33 by root, Sun Oct 8 16:51:50 2006 UTC vs.
Revision 1.44 by root, Mon Dec 18 04:07:30 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 32
36/* 33/*
37 * Returns the maptile which has a name matching the given argument. 34 * Returns the maptile which has a name matching the given argument.
38 * return NULL if no match is found. 35 * return NULL if no match is found.
39 */ 36 */
157int 154int
158check_path (const char *name, int prepend_dir) 155check_path (const char *name, int prepend_dir)
159{ 156{
160 char buf[MAX_BUF]; 157 char buf[MAX_BUF];
161 158
162#ifndef WIN32
163 char *endbuf; 159 char *endbuf;
164 struct stat statbuf; 160 struct stat statbuf;
165 int mode = 0; 161 int mode = 0;
166#endif
167 162
168 if (prepend_dir) 163 if (prepend_dir)
169 strcpy (buf, create_pathname (name)); 164 strcpy (buf, create_pathname (name));
170 else 165 else
171 strcpy (buf, name); 166 strcpy (buf, name);
172#ifdef WIN32 /* ***win32: check this sucker in windows style. */
173 return (_access (buf, 0));
174#else
175 167
176 /* old method (strchr(buf, '\0')) seemd very odd to me - 168 /* old method (strchr(buf, '\0')) seemd very odd to me -
177 * this method should be equivalant and is clearer. 169 * this method should be equivalant and is clearer.
178 * Can not use strcat because we need to cycle through 170 * Can not use strcat because we need to cycle through
179 * all the names. 171 * all the names.
192 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 184 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
193 (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))
194 mode |= 2; 186 mode |= 2;
195 187
196 return (mode); 188 return (mode);
197#endif
198} 189}
199 190
200/* 191/*
201 * Prints out debug-information about a map. 192 * Prints out debug-information about a map.
202 * Dumping these at llevError doesn't seem right, but is 193 * Dumping these at llevError doesn't seem right, but is
540{ 531{
541 int i, j; 532 int i, j;
542 int unique; 533 int unique;
543 object *op, *prev = NULL, *last_more = NULL, *otmp; 534 object *op, *prev = NULL, *last_more = NULL, *otmp;
544 535
545 op = get_object (); 536 op = object::create ();
546 op->map = m; /* To handle buttons correctly */ 537 op->map = m; /* To handle buttons correctly */
547 538
548 while ((i = load_object (fp, op, mapflags))) 539 while ((i = load_object (fp, op, mapflags)))
549 { 540 {
550 /* if the archetype for the object is null, means that we 541 /* if the archetype for the object is null, means that we
558 } 549 }
559 550
560 551
561 switch (i) 552 switch (i)
562 { 553 {
563 case LL_NORMAL: 554 case LL_NORMAL:
564 /* if we are loading an overlay, put the floors on the bottom */ 555 /* if we are loading an overlay, put the floors on the bottom */
565 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 556 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
566 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 557 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
567 else 558 else
568 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 559 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
569 560
570 if (op->inv) 561 if (op->inv)
571 sum_weight (op); 562 sum_weight (op);
572 563
573 prev = op, last_more = op; 564 prev = op, last_more = op;
574 break; 565 break;
575 566
576 case LL_MORE: 567 case LL_MORE:
577 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 568 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
578 op->head = prev, last_more->more = op, last_more = op; 569 op->head = prev, last_more->more = op, last_more = op;
579 break; 570 break;
580 } 571 }
581 572
582 if (mapflags & MAP_STYLE) 573 if (mapflags & MAP_STYLE)
583 remove_from_active_list (op); 574 remove_from_active_list (op);
584 575
585 op = get_object (); 576 op = object::create ();
586 op->map = m; 577 op->map = m;
587 } 578 }
588 579
589 for (i = 0; i < m->width; i++) 580 for (i = 0; i < m->width; i++)
590 { 581 {
594 /* check for unique items, or unique squares */ 585 /* check for unique items, or unique squares */
595 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) 586 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
596 { 587 {
597 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) 588 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
598 unique = 1; 589 unique = 1;
590
599 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 591 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
600 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 592 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
601 } 593 }
602 } 594 }
603 } 595 }
604 596
605 free_object (op); 597 op->destroy ();
606 link_multipart_objects (m); 598 link_multipart_objects (m);
607} 599}
608 600
609/* This saves all the objects on the map in a non destructive fashion. 601/* This saves all the objects on the map in a non destructive fashion.
610 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 602 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
643 635
644 } /* for this space */ 636 } /* for this space */
645 } /* for this j */ 637 } /* for this j */
646} 638}
647 639
640maptile::maptile ()
641{
642 in_memory = MAP_SWAPPED;
643 /* The maps used to pick up default x and y values from the
644 * map archetype. Mimic that behaviour.
645 */
646 MAP_WIDTH (this) = 16;
647 MAP_HEIGHT (this) = 16;
648 MAP_RESET_TIMEOUT (this) = 0;
649 MAP_TIMEOUT (this) = 300;
650 MAP_ENTER_X (this) = 0;
651 MAP_ENTER_Y (this) = 0;
652 /*set part to -1 indicating conversion to weather map not yet done */
653 MAP_WORLDPARTX (this) = -1;
654 MAP_WORLDPARTY (this) = -1;
655}
656
648/* 657/*
649 * Allocates, initialises, and returns a pointer to a maptile. 658 * Allocates, initialises, and returns a pointer to a maptile.
650 * Modified to no longer take a path option which was not being 659 * Modified to no longer take a path option which was not being
651 * used anyways. MSW 2001-07-01 660 * used anyways. MSW 2001-07-01
652 */ 661 */
653
654maptile * 662maptile *
655get_linked_map (void) 663get_linked_map (void)
656{ 664{
657 maptile *map = new maptile; 665 maptile *mp, *map = new maptile;
658 maptile *mp;
659 666
660 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 667 for (mp = first_map; mp && mp->next; mp = mp->next);
668
661 if (mp == NULL) 669 if (mp == NULL)
662 first_map = map; 670 first_map = map;
663 else 671 else
664 mp->next = map; 672 mp->next = map;
665 673
666 map->in_memory = MAP_SWAPPED;
667 /* The maps used to pick up default x and y values from the
668 * map archetype. Mimic that behaviour.
669 */
670 MAP_WIDTH (map) = 16;
671 MAP_HEIGHT (map) = 16;
672 MAP_RESET_TIMEOUT (map) = 0;
673 MAP_TIMEOUT (map) = 300;
674 MAP_ENTER_X (map) = 0;
675 MAP_ENTER_Y (map) = 0;
676 /*set part to -1 indicating conversion to weather map not yet done */
677 MAP_WORLDPARTX (map) = -1;
678 MAP_WORLDPARTY (map) = -1;
679 return map; 674 return map;
680} 675}
681 676
682/* 677/*
683 * Allocates the arrays contained in a maptile. 678 * Allocates the arrays contained in a maptile.
684 * This basically allocates the dynamic array of spaces for the 679 * This basically allocates the dynamic array of spaces for the
685 * map. 680 * map.
686 */ 681 */
687
688void 682void
689allocate_map (maptile *m) 683maptile::allocate ()
690{ 684{
691 m->in_memory = MAP_IN_MEMORY; 685 in_memory = MAP_IN_MEMORY;
686
692 /* Log this condition and free the storage. We could I suppose 687 /* Log this condition and free the storage. We could I suppose
693 * realloc, but if the caller is presuming the data will be intact, 688 * realloc, but if the caller is presuming the data will be intact,
694 * that is their poor assumption. 689 * that is their poor assumption.
695 */ 690 */
696 if (m->spaces) 691 if (spaces)
697 { 692 {
698 LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); 693 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
699 free (m->spaces); 694 free (spaces);
700 } 695 }
701 696
702 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 697 spaces = (MapSpace *)
698 calloc (1, width * height * sizeof (MapSpace));
703 699
704 if (m->spaces == NULL) 700 if (!spaces)
705 fatal (OUT_OF_MEMORY); 701 fatal (OUT_OF_MEMORY);
706} 702}
707 703
708/* Create and returns a map of the specific size. Used 704/* Create and returns a map of the specific size. Used
709 * in random map code and the editor. 705 * in random map code and the editor.
714 maptile *m = get_linked_map (); 710 maptile *m = get_linked_map ();
715 711
716 m->width = sizex; 712 m->width = sizex;
717 m->height = sizey; 713 m->height = sizey;
718 m->in_memory = MAP_SWAPPED; 714 m->in_memory = MAP_SWAPPED;
719 allocate_map (m); 715 m->allocate ();
716
720 return m; 717 return m;
721} 718}
722 719
723/* Takes a string from a map definition and outputs a pointer to the array of shopitems 720/* Takes a string from a map definition and outputs a pointer to the array of shopitems
724 * corresponding to that string. Memory is allocated for this, it must be freed 721 * corresponding to that string. Memory is allocated for this, it must be freed
732 char *shop_string, *p, *q, *next_semicolon, *next_colon; 729 char *shop_string, *p, *q, *next_semicolon, *next_colon;
733 shopitems *items = NULL; 730 shopitems *items = NULL;
734 int i = 0, number_of_entries = 0; 731 int i = 0, number_of_entries = 0;
735 const typedata *current_type; 732 const typedata *current_type;
736 733
737 shop_string = strdup_local (input_string); 734 shop_string = strdup (input_string);
738 p = shop_string; 735 p = shop_string;
739 /* first we'll count the entries, we'll need that for allocating the array shortly */ 736 /* first we'll count the entries, we'll need that for allocating the array shortly */
740 while (p) 737 while (p)
741 { 738 {
742 p = strchr (p, ';'); 739 p = strchr (p, ';');
851{ 848{
852 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 849 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
853 int msgpos = 0; 850 int msgpos = 0;
854 int maplorepos = 0; 851 int maplorepos = 0;
855 852
856 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 853 while (fgets (buf, HUGE_BUF, fp) != NULL)
857 { 854 {
858 buf[HUGE_BUF - 1] = 0; 855 buf[HUGE_BUF - 1] = 0;
859 key = buf; 856 key = buf;
857
860 while (isspace (*key)) 858 while (isspace (*key))
861 key++; 859 key++;
860
862 if (*key == 0) 861 if (*key == 0)
863 continue; /* empty line */ 862 continue; /* empty line */
863
864 value = strchr (key, ' '); 864 value = strchr (key, ' ');
865
865 if (!value) 866 if (!value)
866 { 867 {
867 end = strchr (key, '\n'); 868 if ((end = strchr (key, '\n')))
868 if (end != NULL)
869 {
870 *end = 0; 869 *end = 0;
871 }
872 } 870 }
873 else 871 else
874 { 872 {
875 *value = 0; 873 *value = 0;
876 value++; 874 value++;
877 end = strchr (value, '\n'); 875 end = strchr (value, '\n');
876
878 while (isspace (*value)) 877 while (isspace (*value))
879 { 878 {
880 value++; 879 value++;
880
881 if (*value == '\0' || value == end) 881 if (*value == '\0' || value == end)
882 { 882 {
883 /* Nothing but spaces. */ 883 /* Nothing but spaces. */
884 value = NULL; 884 value = NULL;
885 break; 885 break;
908 * that use the parameter. 908 * that use the parameter.
909 */ 909 */
910 910
911 if (!strcmp (key, "msg")) 911 if (!strcmp (key, "msg"))
912 { 912 {
913 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 913 while (fgets (buf, HUGE_BUF, fp) != NULL)
914 { 914 {
915 if (!strcmp (buf, "endmsg\n")) 915 if (!strcmp (buf, "endmsg\n"))
916 break; 916 break;
917 else 917 else
918 { 918 {
925 * with nothing between). There is no reason in those cases to 925 * with nothing between). There is no reason in those cases to
926 * keep the empty message. Also, msgbuf contains garbage data 926 * keep the empty message. Also, msgbuf contains garbage data
927 * when msgpos is zero, so copying it results in crashes 927 * when msgpos is zero, so copying it results in crashes
928 */ 928 */
929 if (msgpos != 0) 929 if (msgpos != 0)
930 m->msg = strdup_local (msgbuf); 930 m->msg = strdup (msgbuf);
931 } 931 }
932 else if (!strcmp (key, "maplore")) 932 else if (!strcmp (key, "maplore"))
933 { 933 {
934 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 934 while (fgets (buf, HUGE_BUF, fp) != NULL)
935 { 935 {
936 if (!strcmp (buf, "endmaplore\n")) 936 if (!strcmp (buf, "endmaplore\n"))
937 break; 937 break;
938 else 938 else
939 { 939 {
941 strcpy (maplorebuf + maplorepos, buf); 941 strcpy (maplorebuf + maplorepos, buf);
942 maplorepos += strlen (buf); 942 maplorepos += strlen (buf);
943 } 943 }
944 } 944 }
945 if (maplorepos != 0) 945 if (maplorepos != 0)
946 m->maplore = strdup_local (maplorebuf); 946 m->maplore = strdup (maplorebuf);
947 } 947 }
948 else if (!strcmp (key, "end")) 948 else if (!strcmp (key, "end"))
949 { 949 {
950 break; 950 break;
951 } 951 }
960 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); 960 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value);
961 } 961 }
962 else if (!strcmp (key, "name")) 962 else if (!strcmp (key, "name"))
963 { 963 {
964 *end = 0; 964 *end = 0;
965 m->name = strdup_local (value); 965 m->name = strdup (value);
966 } 966 }
967 /* first strcmp value on these are old names supported 967 /* first strcmp value on these are old names supported
968 * for compatibility reasons. The new values (second) are 968 * for compatibility reasons. The new values (second) are
969 * what really should be used. 969 * what really should be used.
970 */ 970 */
971 else if (!strcmp (key, "oid")) 971 else if (!strcmp (key, "oid"))
972 {
973 fp.get (m, atoi (value)); 972 fp.get (m, atoi (value));
974 }
975 else if (!strcmp (key, "attach")) 973 else if (!strcmp (key, "attach"))
976 {
977 m->attach = value; 974 m->attach = value;
978 }
979 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 975 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
980 {
981 m->enter_x = atoi (value); 976 m->enter_x = atoi (value);
982 }
983 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 977 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
984 {
985 m->enter_y = atoi (value); 978 m->enter_y = atoi (value);
986 }
987 else if (!strcmp (key, "x") || !strcmp (key, "width")) 979 else if (!strcmp (key, "x") || !strcmp (key, "width"))
988 {
989 m->width = atoi (value); 980 m->width = atoi (value);
990 }
991 else if (!strcmp (key, "y") || !strcmp (key, "height")) 981 else if (!strcmp (key, "y") || !strcmp (key, "height"))
992 {
993 m->height = atoi (value); 982 m->height = atoi (value);
994 }
995 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 983 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
996 {
997 m->reset_timeout = atoi (value); 984 m->reset_timeout = atoi (value);
998 }
999 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 985 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1000 {
1001 m->timeout = atoi (value); 986 m->timeout = atoi (value);
1002 }
1003 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 987 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1004 { 988 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1005 m->difficulty = atoi (value);
1006 }
1007 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 989 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1008 {
1009 m->darkness = atoi (value); 990 m->darkness = atoi (value);
1010 }
1011 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 991 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1012 {
1013 m->fixed_resettime = atoi (value); 992 m->fixed_resettime = atoi (value);
1014 }
1015 else if (!strcmp (key, "unique")) 993 else if (!strcmp (key, "unique"))
1016 {
1017 m->unique = atoi (value); 994 m->unique = atoi (value);
1018 }
1019 else if (!strcmp (key, "template")) 995 else if (!strcmp (key, "template"))
1020 {
1021 m->templatemap = atoi (value); 996 m->templatemap = atoi (value);
1022 }
1023 else if (!strcmp (key, "region")) 997 else if (!strcmp (key, "region"))
1024 {
1025 m->region = get_region_by_name (value); 998 m->region = get_region_by_name (value);
1026 }
1027 else if (!strcmp (key, "shopitems")) 999 else if (!strcmp (key, "shopitems"))
1028 { 1000 {
1029 *end = 0; 1001 *end = 0;
1030 m->shopitems = parse_shop_string (value); 1002 m->shopitems = parse_shop_string (value);
1031 } 1003 }
1032 else if (!strcmp (key, "shopgreed")) 1004 else if (!strcmp (key, "shopgreed"))
1033 {
1034 m->shopgreed = atof (value); 1005 m->shopgreed = atof (value);
1035 }
1036 else if (!strcmp (key, "shopmin")) 1006 else if (!strcmp (key, "shopmin"))
1037 {
1038 m->shopmin = atol (value); 1007 m->shopmin = atol (value);
1039 }
1040 else if (!strcmp (key, "shopmax")) 1008 else if (!strcmp (key, "shopmax"))
1041 {
1042 m->shopmax = atol (value); 1009 m->shopmax = atol (value);
1043 }
1044 else if (!strcmp (key, "shoprace")) 1010 else if (!strcmp (key, "shoprace"))
1045 { 1011 {
1046 *end = 0; 1012 *end = 0;
1047 m->shoprace = strdup_local (value); 1013 m->shoprace = strdup (value);
1048 } 1014 }
1049 else if (!strcmp (key, "outdoor")) 1015 else if (!strcmp (key, "outdoor"))
1050 {
1051 m->outdoor = atoi (value); 1016 m->outdoor = atoi (value);
1052 }
1053 else if (!strcmp (key, "temp")) 1017 else if (!strcmp (key, "temp"))
1054 {
1055 m->temp = atoi (value); 1018 m->temp = atoi (value);
1056 }
1057 else if (!strcmp (key, "pressure")) 1019 else if (!strcmp (key, "pressure"))
1058 {
1059 m->pressure = atoi (value); 1020 m->pressure = atoi (value);
1060 }
1061 else if (!strcmp (key, "humid")) 1021 else if (!strcmp (key, "humid"))
1062 {
1063 m->humid = atoi (value); 1022 m->humid = atoi (value);
1064 }
1065 else if (!strcmp (key, "windspeed")) 1023 else if (!strcmp (key, "windspeed"))
1066 {
1067 m->windspeed = atoi (value); 1024 m->windspeed = atoi (value);
1068 }
1069 else if (!strcmp (key, "winddir")) 1025 else if (!strcmp (key, "winddir"))
1070 {
1071 m->winddir = atoi (value); 1026 m->winddir = atoi (value);
1072 }
1073 else if (!strcmp (key, "sky")) 1027 else if (!strcmp (key, "sky"))
1074 {
1075 m->sky = atoi (value); 1028 m->sky = atoi (value);
1076 }
1077 else if (!strcmp (key, "nosmooth")) 1029 else if (!strcmp (key, "nosmooth"))
1078 {
1079 m->nosmooth = atoi (value); 1030 m->nosmooth = atoi (value);
1080 }
1081 else if (!strncmp (key, "tile_path_", 10)) 1031 else if (!strncmp (key, "tile_path_", 10))
1082 { 1032 {
1083 int tile = atoi (key + 10); 1033 int tile = atoi (key + 10);
1084 1034
1085 if (tile < 1 || tile > 4) 1035 if (tile < 1 || tile > 4)
1118 } 1068 }
1119 1069
1120 if (editor) 1070 if (editor)
1121 { 1071 {
1122 /* Use the value as in the file. */ 1072 /* Use the value as in the file. */
1123 m->tile_path[tile - 1] = strdup_local (value); 1073 m->tile_path[tile - 1] = strdup (value);
1124 } 1074 }
1125 else if (path != NULL) 1075 else if (path != NULL)
1126 { 1076 {
1127 /* Use the normalized value. */ 1077 /* Use the normalized value. */
1128 m->tile_path[tile - 1] = strdup_local (path); 1078 m->tile_path[tile - 1] = strdup (path);
1129 } 1079 }
1130 } /* end if tile direction (in)valid */ 1080 } /* end if tile direction (in)valid */
1131 } 1081 }
1132 else 1082 else
1133 {
1134 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); 1083 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value);
1135 }
1136 } 1084 }
1085
1137 if (!key || strcmp (key, "end")) 1086 if (!key || strcmp (key, "end"))
1138 { 1087 {
1139 LOG (llevError, "Got premature eof on map header!\n"); 1088 LOG (llevError, "Got premature eof on map header!\n");
1140 return 1; 1089 return 1;
1141 } 1090 }
1091
1142 return 0; 1092 return 0;
1143} 1093}
1144 1094
1145/* 1095/*
1146 * Opens the file "filename" and reads information about the map 1096 * Opens the file "filename" and reads information about the map
1182 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1132 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1183 delete_map (m); 1133 delete_map (m);
1184 return NULL; 1134 return NULL;
1185 } 1135 }
1186 1136
1187 allocate_map (m); 1137 m->allocate ();
1188 1138
1189 m->in_memory = MAP_LOADING; 1139 m->in_memory = MAP_LOADING;
1190 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1140 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1191 1141
1192 m->in_memory = MAP_IN_MEMORY; 1142 m->in_memory = MAP_IN_MEMORY;
1238 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1188 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1239 delete_map (m); 1189 delete_map (m);
1240 m = load_original_map (m->path, 0); 1190 m = load_original_map (m->path, 0);
1241 return NULL; 1191 return NULL;
1242 } 1192 }
1193
1243 allocate_map (m); 1194 m->allocate ();
1244 1195
1245 m->in_memory = MAP_LOADING; 1196 m->in_memory = MAP_LOADING;
1246 load_objects (m, thawer, 0); 1197 load_objects (m, thawer, 0);
1247 1198
1248 m->in_memory = MAP_IN_MEMORY; 1199 m->in_memory = MAP_IN_MEMORY;
1273 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1224 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1274 delete_map (m); 1225 delete_map (m);
1275 m = load_original_map (m->path, 0); 1226 m = load_original_map (m->path, 0);
1276 return NULL; 1227 return NULL;
1277 } 1228 }
1278 /*allocate_map(m); */ 1229 /*m->allocate ();*/
1279 1230
1280 m->in_memory = MAP_LOADING; 1231 m->in_memory = MAP_LOADING;
1281 load_objects (m, thawer, MAP_OVERLAY); 1232 load_objects (m, thawer, MAP_OVERLAY);
1282 1233
1283 m->in_memory = MAP_IN_MEMORY; 1234 m->in_memory = MAP_IN_MEMORY;
1297 1248
1298 for (i = 0; i < MAP_WIDTH (m); i++) 1249 for (i = 0; i < MAP_WIDTH (m); i++)
1299 for (j = 0; j < MAP_HEIGHT (m); j++) 1250 for (j = 0; j < MAP_HEIGHT (m); j++)
1300 { 1251 {
1301 unique = 0; 1252 unique = 0;
1253
1302 for (op = get_map_ob (m, i, j); op; op = next) 1254 for (op = get_map_ob (m, i, j); op; op = next)
1303 { 1255 {
1304 next = op->above; 1256 next = op->above;
1257
1305 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1258 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1306 unique = 1; 1259 unique = 1;
1260
1307 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1261 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1308 { 1262 {
1309 clean_object (op); 1263 clean_object (op);
1264
1310 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1265 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1311 remove_button_link (op); 1266 remove_button_link (op);
1312 remove_ob (op); 1267
1313 free_object (op); 1268 op->destroy ();
1314 } 1269 }
1315 } 1270 }
1316 } 1271 }
1317} 1272}
1318 1273
1387 make_path_to_file (filename); 1342 make_path_to_file (filename);
1388 } 1343 }
1389 else 1344 else
1390 { 1345 {
1391 if (!m->tmpname) 1346 if (!m->tmpname)
1392 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1347 m->tmpname = tempnam (settings.tmpdir, NULL);
1393 1348
1394 strcpy (filename, m->tmpname); 1349 strcpy (filename, m->tmpname);
1395 } 1350 }
1396 1351
1397 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1352 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1421 print_shop_string (m, shop); 1376 print_shop_string (m, shop);
1422 fprintf (freezer, "shopitems %s\n", shop); 1377 fprintf (freezer, "shopitems %s\n", shop);
1423 } 1378 }
1424 if (m->shopgreed) 1379 if (m->shopgreed)
1425 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1380 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1426#ifndef WIN32
1427 if (m->shopmin) 1381 if (m->shopmin)
1428 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1382 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1429 if (m->shopmax) 1383 if (m->shopmax)
1430 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1384 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1431#else
1432 if (m->shopmin)
1433 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1434 if (m->shopmax)
1435 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1436#endif
1437 if (m->shoprace) 1385 if (m->shoprace)
1438 fprintf (freezer, "shoprace %s\n", m->shoprace); 1386 fprintf (freezer, "shoprace %s\n", m->shoprace);
1439 if (m->darkness) 1387 if (m->darkness)
1440 fprintf (freezer, "darkness %d\n", m->darkness); 1388 fprintf (freezer, "darkness %d\n", m->darkness);
1441 if (m->width) 1389 if (m->width)
1520 object *tmp, *next; 1468 object *tmp, *next;
1521 1469
1522 for (tmp = op->inv; tmp; tmp = next) 1470 for (tmp = op->inv; tmp; tmp = next)
1523 { 1471 {
1524 next = tmp->below; 1472 next = tmp->below;
1473
1525 clean_object (tmp); 1474 clean_object (tmp);
1526 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1475 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1527 remove_button_link (tmp); 1476 remove_button_link (tmp);
1528 remove_ob (tmp); 1477
1529 free_object (tmp); 1478 tmp->destroy ();
1530 } 1479 }
1531} 1480}
1532 1481
1533/* 1482/*
1534 * Remove and free all objects in the given map. 1483 * Remove and free all objects in the given map.
1550 if (op == previous_obj) 1499 if (op == previous_obj)
1551 { 1500 {
1552 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1501 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1553 break; 1502 break;
1554 } 1503 }
1504
1555 previous_obj = op; 1505 previous_obj = op;
1506
1556 if (op->head != NULL) 1507 if (op->head != NULL)
1557 op = op->head; 1508 op = op->head;
1558 1509
1559 /* If the map isn't in memory, free_object will remove and 1510 /* If the map isn't in memory, free_object will remove and
1560 * free objects in op's inventory. So let it do the job. 1511 * free objects in op's inventory. So let it do the job.
1561 */ 1512 */
1562 if (m->in_memory == MAP_IN_MEMORY) 1513 if (m->in_memory == MAP_IN_MEMORY)
1563 clean_object (op); 1514 clean_object (op);
1564 remove_ob (op); 1515
1565 free_object (op); 1516 op->destroy ();
1566 } 1517 }
1567 } 1518 }
1568} 1519}
1569 1520
1570/* 1521/*
1580 if (!m->in_memory) 1531 if (!m->in_memory)
1581 { 1532 {
1582 LOG (llevError, "Trying to free freed map.\n"); 1533 LOG (llevError, "Trying to free freed map.\n");
1583 return; 1534 return;
1584 } 1535 }
1536
1537 // TODO: use new/delete
1538#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1539
1585 if (flag && m->spaces) 1540 if (flag && m->spaces)
1586 free_all_objects (m); 1541 free_all_objects (m);
1587 if (m->name) 1542 if (m->name)
1588 FREE_AND_CLEAR (m->name); 1543 FREE_AND_CLEAR (m->name);
1589 if (m->spaces) 1544 if (m->spaces)
1590 FREE_AND_CLEAR (m->spaces); 1545 FREE_AND_CLEAR (m->spaces);
1591 if (m->msg) 1546 if (m->msg)
1592 FREE_AND_CLEAR (m->msg); 1547 FREE_AND_CLEAR (m->msg);
1593 if (m->maplore) 1548 if (m->maplore)
1594 FREE_AND_CLEAR (m->maplore); 1549 FREE_AND_CLEAR (m->maplore);
1595 if (m->shopitems) 1550
1596 delete[]m->shopitems; 1551 delete [] m->shopitems;
1597 m->shopitems = 0; 1552 m->shopitems = 0;
1553
1598 if (m->shoprace) 1554 if (m->shoprace)
1599 FREE_AND_CLEAR (m->shoprace); 1555 FREE_AND_CLEAR (m->shoprace);
1556
1600 if (m->buttons) 1557 if (m->buttons)
1601 free_objectlinkpt (m->buttons); 1558 free_objectlinkpt (m->buttons);
1559
1602 m->buttons = NULL; 1560 m->buttons = NULL;
1561
1603 for (i = 0; i < 4; i++) 1562 for (i = 0; i < 4; i++)
1604 { 1563 {
1605 if (m->tile_path[i]) 1564 if (m->tile_path[i])
1606 FREE_AND_CLEAR (m->tile_path[i]); 1565 FREE_AND_CLEAR (m->tile_path[i]);
1607 m->tile_map[i] = NULL; 1566 m->tile_map[i] = NULL;
1608 } 1567 }
1568
1609 m->in_memory = MAP_SWAPPED; 1569 m->in_memory = MAP_SWAPPED;
1570
1571#undef FREE_AND_CLEAR
1572
1610} 1573}
1611 1574
1612/* 1575/*
1613 * function: vanish maptile 1576 * function: vanish maptile
1614 * m : pointer to maptile, if NULL no action 1577 * m : pointer to maptile, if NULL no action
1674 else 1637 else
1675 last->next = m->next; 1638 last->next = m->next;
1676 1639
1677 delete m; 1640 delete m;
1678} 1641}
1679
1680
1681 1642
1682/* 1643/*
1683 * Makes sure the given map is loaded and swapped in. 1644 * Makes sure the given map is loaded and swapped in.
1684 * name is path name of the map. 1645 * name is path name of the map.
1685 * flags meaning: 1646 * flags meaning:
1688 * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. 1649 * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player.
1689 * dont do any more name translation on it. 1650 * dont do any more name translation on it.
1690 * 1651 *
1691 * Returns a pointer to the given map. 1652 * Returns a pointer to the given map.
1692 */ 1653 */
1693
1694maptile * 1654maptile *
1695ready_map_name (const char *name, int flags) 1655ready_map_name (const char *name, int flags)
1696{ 1656{
1697 maptile *m; 1657 maptile *m;
1698 1658
2144 timeout = MAP_RESET_TIMEOUT (map); 2104 timeout = MAP_RESET_TIMEOUT (map);
2145 if (timeout <= 0) 2105 if (timeout <= 0)
2146 timeout = MAP_DEFAULTRESET; 2106 timeout = MAP_DEFAULTRESET;
2147 if (timeout >= MAP_MAXRESET) 2107 if (timeout >= MAP_MAXRESET)
2148 timeout = MAP_MAXRESET; 2108 timeout = MAP_MAXRESET;
2149 MAP_WHEN_RESET (map) = seconds () + timeout; 2109 MAP_WHEN_RESET (map) = time (0) + timeout;
2150} 2110}
2151 2111
2152/* this updates the orig_map->tile_map[tile_num] value after loading 2112/* this updates the orig_map->tile_map[tile_num] value after loading
2153 * the map. It also takes care of linking back the freshly loaded 2113 * the map. It also takes care of linking back the freshly loaded
2154 * maps tile_map values if it tiles back to this one. It returns 2114 * maps tile_map values if it tiles back to this one. It returns

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines