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.34 by root, Sun Dec 3 02:04:57 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,
737 char *shop_string, *p, *q, *next_semicolon, *next_colon; 729 char *shop_string, *p, *q, *next_semicolon, *next_colon;
738 shopitems *items = NULL; 730 shopitems *items = NULL;
739 int i = 0, number_of_entries = 0; 731 int i = 0, number_of_entries = 0;
740 const typedata *current_type; 732 const typedata *current_type;
741 733
742 shop_string = strdup_local (input_string); 734 shop_string = strdup (input_string);
743 p = shop_string; 735 p = shop_string;
744 /* 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 */
745 while (p) 737 while (p)
746 { 738 {
747 p = strchr (p, ';'); 739 p = strchr (p, ';');
856{ 848{
857 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;
858 int msgpos = 0; 850 int msgpos = 0;
859 int maplorepos = 0; 851 int maplorepos = 0;
860 852
861 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 853 while (fgets (buf, HUGE_BUF, fp) != NULL)
862 { 854 {
863 buf[HUGE_BUF - 1] = 0; 855 buf[HUGE_BUF - 1] = 0;
864 key = buf; 856 key = buf;
857
865 while (isspace (*key)) 858 while (isspace (*key))
866 key++; 859 key++;
860
867 if (*key == 0) 861 if (*key == 0)
868 continue; /* empty line */ 862 continue; /* empty line */
863
869 value = strchr (key, ' '); 864 value = strchr (key, ' ');
865
870 if (!value) 866 if (!value)
871 { 867 {
872 end = strchr (key, '\n'); 868 if ((end = strchr (key, '\n')))
873 if (end != NULL)
874 {
875 *end = 0; 869 *end = 0;
876 }
877 } 870 }
878 else 871 else
879 { 872 {
880 *value = 0; 873 *value = 0;
881 value++; 874 value++;
882 end = strchr (value, '\n'); 875 end = strchr (value, '\n');
876
883 while (isspace (*value)) 877 while (isspace (*value))
884 { 878 {
885 value++; 879 value++;
880
886 if (*value == '\0' || value == end) 881 if (*value == '\0' || value == end)
887 { 882 {
888 /* Nothing but spaces. */ 883 /* Nothing but spaces. */
889 value = NULL; 884 value = NULL;
890 break; 885 break;
913 * that use the parameter. 908 * that use the parameter.
914 */ 909 */
915 910
916 if (!strcmp (key, "msg")) 911 if (!strcmp (key, "msg"))
917 { 912 {
918 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 913 while (fgets (buf, HUGE_BUF, fp) != NULL)
919 { 914 {
920 if (!strcmp (buf, "endmsg\n")) 915 if (!strcmp (buf, "endmsg\n"))
921 break; 916 break;
922 else 917 else
923 { 918 {
930 * with nothing between). There is no reason in those cases to 925 * with nothing between). There is no reason in those cases to
931 * keep the empty message. Also, msgbuf contains garbage data 926 * keep the empty message. Also, msgbuf contains garbage data
932 * when msgpos is zero, so copying it results in crashes 927 * when msgpos is zero, so copying it results in crashes
933 */ 928 */
934 if (msgpos != 0) 929 if (msgpos != 0)
935 m->msg = strdup_local (msgbuf); 930 m->msg = strdup (msgbuf);
936 } 931 }
937 else if (!strcmp (key, "maplore")) 932 else if (!strcmp (key, "maplore"))
938 { 933 {
939 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 934 while (fgets (buf, HUGE_BUF, fp) != NULL)
940 { 935 {
941 if (!strcmp (buf, "endmaplore\n")) 936 if (!strcmp (buf, "endmaplore\n"))
942 break; 937 break;
943 else 938 else
944 { 939 {
946 strcpy (maplorebuf + maplorepos, buf); 941 strcpy (maplorebuf + maplorepos, buf);
947 maplorepos += strlen (buf); 942 maplorepos += strlen (buf);
948 } 943 }
949 } 944 }
950 if (maplorepos != 0) 945 if (maplorepos != 0)
951 m->maplore = strdup_local (maplorebuf); 946 m->maplore = strdup (maplorebuf);
952 } 947 }
953 else if (!strcmp (key, "end")) 948 else if (!strcmp (key, "end"))
954 { 949 {
955 break; 950 break;
956 } 951 }
965 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);
966 } 961 }
967 else if (!strcmp (key, "name")) 962 else if (!strcmp (key, "name"))
968 { 963 {
969 *end = 0; 964 *end = 0;
970 m->name = strdup_local (value); 965 m->name = strdup (value);
971 } 966 }
972 /* first strcmp value on these are old names supported 967 /* first strcmp value on these are old names supported
973 * for compatibility reasons. The new values (second) are 968 * for compatibility reasons. The new values (second) are
974 * what really should be used. 969 * what really should be used.
975 */ 970 */
976 else if (!strcmp (key, "oid")) 971 else if (!strcmp (key, "oid"))
977 {
978 fp.get (m, atoi (value)); 972 fp.get (m, atoi (value));
979 }
980 else if (!strcmp (key, "attach")) 973 else if (!strcmp (key, "attach"))
981 {
982 m->attach = value; 974 m->attach = value;
983 }
984 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 975 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
985 {
986 m->enter_x = atoi (value); 976 m->enter_x = atoi (value);
987 }
988 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 977 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
989 {
990 m->enter_y = atoi (value); 978 m->enter_y = atoi (value);
991 }
992 else if (!strcmp (key, "x") || !strcmp (key, "width")) 979 else if (!strcmp (key, "x") || !strcmp (key, "width"))
993 {
994 m->width = atoi (value); 980 m->width = atoi (value);
995 }
996 else if (!strcmp (key, "y") || !strcmp (key, "height")) 981 else if (!strcmp (key, "y") || !strcmp (key, "height"))
997 {
998 m->height = atoi (value); 982 m->height = atoi (value);
999 }
1000 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 983 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
1001 {
1002 m->reset_timeout = atoi (value); 984 m->reset_timeout = atoi (value);
1003 }
1004 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 985 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1005 {
1006 m->timeout = atoi (value); 986 m->timeout = atoi (value);
1007 }
1008 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 987 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1009 { 988 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1010 m->difficulty = atoi (value);
1011 }
1012 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 989 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1013 {
1014 m->darkness = atoi (value); 990 m->darkness = atoi (value);
1015 }
1016 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 991 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1017 {
1018 m->fixed_resettime = atoi (value); 992 m->fixed_resettime = atoi (value);
1019 }
1020 else if (!strcmp (key, "unique")) 993 else if (!strcmp (key, "unique"))
1021 {
1022 m->unique = atoi (value); 994 m->unique = atoi (value);
1023 }
1024 else if (!strcmp (key, "template")) 995 else if (!strcmp (key, "template"))
1025 {
1026 m->templatemap = atoi (value); 996 m->templatemap = atoi (value);
1027 }
1028 else if (!strcmp (key, "region")) 997 else if (!strcmp (key, "region"))
1029 {
1030 m->region = get_region_by_name (value); 998 m->region = get_region_by_name (value);
1031 }
1032 else if (!strcmp (key, "shopitems")) 999 else if (!strcmp (key, "shopitems"))
1033 { 1000 {
1034 *end = 0; 1001 *end = 0;
1035 m->shopitems = parse_shop_string (value); 1002 m->shopitems = parse_shop_string (value);
1036 } 1003 }
1037 else if (!strcmp (key, "shopgreed")) 1004 else if (!strcmp (key, "shopgreed"))
1038 {
1039 m->shopgreed = atof (value); 1005 m->shopgreed = atof (value);
1040 }
1041 else if (!strcmp (key, "shopmin")) 1006 else if (!strcmp (key, "shopmin"))
1042 {
1043 m->shopmin = atol (value); 1007 m->shopmin = atol (value);
1044 }
1045 else if (!strcmp (key, "shopmax")) 1008 else if (!strcmp (key, "shopmax"))
1046 {
1047 m->shopmax = atol (value); 1009 m->shopmax = atol (value);
1048 }
1049 else if (!strcmp (key, "shoprace")) 1010 else if (!strcmp (key, "shoprace"))
1050 { 1011 {
1051 *end = 0; 1012 *end = 0;
1052 m->shoprace = strdup_local (value); 1013 m->shoprace = strdup (value);
1053 } 1014 }
1054 else if (!strcmp (key, "outdoor")) 1015 else if (!strcmp (key, "outdoor"))
1055 {
1056 m->outdoor = atoi (value); 1016 m->outdoor = atoi (value);
1057 }
1058 else if (!strcmp (key, "temp")) 1017 else if (!strcmp (key, "temp"))
1059 {
1060 m->temp = atoi (value); 1018 m->temp = atoi (value);
1061 }
1062 else if (!strcmp (key, "pressure")) 1019 else if (!strcmp (key, "pressure"))
1063 {
1064 m->pressure = atoi (value); 1020 m->pressure = atoi (value);
1065 }
1066 else if (!strcmp (key, "humid")) 1021 else if (!strcmp (key, "humid"))
1067 {
1068 m->humid = atoi (value); 1022 m->humid = atoi (value);
1069 }
1070 else if (!strcmp (key, "windspeed")) 1023 else if (!strcmp (key, "windspeed"))
1071 {
1072 m->windspeed = atoi (value); 1024 m->windspeed = atoi (value);
1073 }
1074 else if (!strcmp (key, "winddir")) 1025 else if (!strcmp (key, "winddir"))
1075 {
1076 m->winddir = atoi (value); 1026 m->winddir = atoi (value);
1077 }
1078 else if (!strcmp (key, "sky")) 1027 else if (!strcmp (key, "sky"))
1079 {
1080 m->sky = atoi (value); 1028 m->sky = atoi (value);
1081 }
1082 else if (!strcmp (key, "nosmooth")) 1029 else if (!strcmp (key, "nosmooth"))
1083 {
1084 m->nosmooth = atoi (value); 1030 m->nosmooth = atoi (value);
1085 }
1086 else if (!strncmp (key, "tile_path_", 10)) 1031 else if (!strncmp (key, "tile_path_", 10))
1087 { 1032 {
1088 int tile = atoi (key + 10); 1033 int tile = atoi (key + 10);
1089 1034
1090 if (tile < 1 || tile > 4) 1035 if (tile < 1 || tile > 4)
1123 } 1068 }
1124 1069
1125 if (editor) 1070 if (editor)
1126 { 1071 {
1127 /* Use the value as in the file. */ 1072 /* Use the value as in the file. */
1128 m->tile_path[tile - 1] = strdup_local (value); 1073 m->tile_path[tile - 1] = strdup (value);
1129 } 1074 }
1130 else if (path != NULL) 1075 else if (path != NULL)
1131 { 1076 {
1132 /* Use the normalized value. */ 1077 /* Use the normalized value. */
1133 m->tile_path[tile - 1] = strdup_local (path); 1078 m->tile_path[tile - 1] = strdup (path);
1134 } 1079 }
1135 } /* end if tile direction (in)valid */ 1080 } /* end if tile direction (in)valid */
1136 } 1081 }
1137 else 1082 else
1138 {
1139 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);
1140 }
1141 } 1084 }
1085
1142 if (!key || strcmp (key, "end")) 1086 if (!key || strcmp (key, "end"))
1143 { 1087 {
1144 LOG (llevError, "Got premature eof on map header!\n"); 1088 LOG (llevError, "Got premature eof on map header!\n");
1145 return 1; 1089 return 1;
1146 } 1090 }
1091
1147 return 0; 1092 return 0;
1148} 1093}
1149 1094
1150/* 1095/*
1151 * Opens the file "filename" and reads information about the map 1096 * Opens the file "filename" and reads information about the map
1303 1248
1304 for (i = 0; i < MAP_WIDTH (m); i++) 1249 for (i = 0; i < MAP_WIDTH (m); i++)
1305 for (j = 0; j < MAP_HEIGHT (m); j++) 1250 for (j = 0; j < MAP_HEIGHT (m); j++)
1306 { 1251 {
1307 unique = 0; 1252 unique = 0;
1253
1308 for (op = get_map_ob (m, i, j); op; op = next) 1254 for (op = get_map_ob (m, i, j); op; op = next)
1309 { 1255 {
1310 next = op->above; 1256 next = op->above;
1257
1311 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))
1312 unique = 1; 1259 unique = 1;
1260
1313 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1261 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1314 { 1262 {
1315 clean_object (op); 1263 clean_object (op);
1264
1316 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1265 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1317 remove_button_link (op); 1266 remove_button_link (op);
1318 remove_ob (op); 1267
1319 free_object (op); 1268 op->destroy ();
1320 } 1269 }
1321 } 1270 }
1322 } 1271 }
1323} 1272}
1324 1273
1393 make_path_to_file (filename); 1342 make_path_to_file (filename);
1394 } 1343 }
1395 else 1344 else
1396 { 1345 {
1397 if (!m->tmpname) 1346 if (!m->tmpname)
1398 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1347 m->tmpname = tempnam (settings.tmpdir, NULL);
1399 1348
1400 strcpy (filename, m->tmpname); 1349 strcpy (filename, m->tmpname);
1401 } 1350 }
1402 1351
1403 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1352 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1427 print_shop_string (m, shop); 1376 print_shop_string (m, shop);
1428 fprintf (freezer, "shopitems %s\n", shop); 1377 fprintf (freezer, "shopitems %s\n", shop);
1429 } 1378 }
1430 if (m->shopgreed) 1379 if (m->shopgreed)
1431 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1380 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1432#ifndef WIN32
1433 if (m->shopmin) 1381 if (m->shopmin)
1434 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1382 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1435 if (m->shopmax) 1383 if (m->shopmax)
1436 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1384 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1437#else
1438 if (m->shopmin)
1439 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1440 if (m->shopmax)
1441 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1442#endif
1443 if (m->shoprace) 1385 if (m->shoprace)
1444 fprintf (freezer, "shoprace %s\n", m->shoprace); 1386 fprintf (freezer, "shoprace %s\n", m->shoprace);
1445 if (m->darkness) 1387 if (m->darkness)
1446 fprintf (freezer, "darkness %d\n", m->darkness); 1388 fprintf (freezer, "darkness %d\n", m->darkness);
1447 if (m->width) 1389 if (m->width)
1526 object *tmp, *next; 1468 object *tmp, *next;
1527 1469
1528 for (tmp = op->inv; tmp; tmp = next) 1470 for (tmp = op->inv; tmp; tmp = next)
1529 { 1471 {
1530 next = tmp->below; 1472 next = tmp->below;
1473
1531 clean_object (tmp); 1474 clean_object (tmp);
1532 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1475 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1533 remove_button_link (tmp); 1476 remove_button_link (tmp);
1534 remove_ob (tmp); 1477
1535 free_object (tmp); 1478 tmp->destroy ();
1536 } 1479 }
1537} 1480}
1538 1481
1539/* 1482/*
1540 * Remove and free all objects in the given map. 1483 * Remove and free all objects in the given map.
1556 if (op == previous_obj) 1499 if (op == previous_obj)
1557 { 1500 {
1558 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1501 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1559 break; 1502 break;
1560 } 1503 }
1504
1561 previous_obj = op; 1505 previous_obj = op;
1506
1562 if (op->head != NULL) 1507 if (op->head != NULL)
1563 op = op->head; 1508 op = op->head;
1564 1509
1565 /* 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
1566 * 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.
1567 */ 1512 */
1568 if (m->in_memory == MAP_IN_MEMORY) 1513 if (m->in_memory == MAP_IN_MEMORY)
1569 clean_object (op); 1514 clean_object (op);
1570 remove_ob (op); 1515
1571 free_object (op); 1516 op->destroy ();
1572 } 1517 }
1573 } 1518 }
1574} 1519}
1575 1520
1576/* 1521/*
1586 if (!m->in_memory) 1531 if (!m->in_memory)
1587 { 1532 {
1588 LOG (llevError, "Trying to free freed map.\n"); 1533 LOG (llevError, "Trying to free freed map.\n");
1589 return; 1534 return;
1590 } 1535 }
1536
1537 // TODO: use new/delete
1538#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1539
1591 if (flag && m->spaces) 1540 if (flag && m->spaces)
1592 free_all_objects (m); 1541 free_all_objects (m);
1593 if (m->name) 1542 if (m->name)
1594 FREE_AND_CLEAR (m->name); 1543 FREE_AND_CLEAR (m->name);
1595 if (m->spaces) 1544 if (m->spaces)
1596 FREE_AND_CLEAR (m->spaces); 1545 FREE_AND_CLEAR (m->spaces);
1597 if (m->msg) 1546 if (m->msg)
1598 FREE_AND_CLEAR (m->msg); 1547 FREE_AND_CLEAR (m->msg);
1599 if (m->maplore) 1548 if (m->maplore)
1600 FREE_AND_CLEAR (m->maplore); 1549 FREE_AND_CLEAR (m->maplore);
1601 if (m->shopitems) 1550
1602 delete[]m->shopitems; 1551 delete [] m->shopitems;
1603 m->shopitems = 0; 1552 m->shopitems = 0;
1553
1604 if (m->shoprace) 1554 if (m->shoprace)
1605 FREE_AND_CLEAR (m->shoprace); 1555 FREE_AND_CLEAR (m->shoprace);
1556
1606 if (m->buttons) 1557 if (m->buttons)
1607 free_objectlinkpt (m->buttons); 1558 free_objectlinkpt (m->buttons);
1559
1608 m->buttons = NULL; 1560 m->buttons = NULL;
1561
1609 for (i = 0; i < 4; i++) 1562 for (i = 0; i < 4; i++)
1610 { 1563 {
1611 if (m->tile_path[i]) 1564 if (m->tile_path[i])
1612 FREE_AND_CLEAR (m->tile_path[i]); 1565 FREE_AND_CLEAR (m->tile_path[i]);
1613 m->tile_map[i] = NULL; 1566 m->tile_map[i] = NULL;
1614 } 1567 }
1568
1615 m->in_memory = MAP_SWAPPED; 1569 m->in_memory = MAP_SWAPPED;
1570
1571#undef FREE_AND_CLEAR
1572
1616} 1573}
1617 1574
1618/* 1575/*
1619 * function: vanish maptile 1576 * function: vanish maptile
1620 * m : pointer to maptile, if NULL no action 1577 * m : pointer to maptile, if NULL no action
1680 else 1637 else
1681 last->next = m->next; 1638 last->next = m->next;
1682 1639
1683 delete m; 1640 delete m;
1684} 1641}
1685
1686
1687 1642
1688/* 1643/*
1689 * Makes sure the given map is loaded and swapped in. 1644 * Makes sure the given map is loaded and swapped in.
1690 * name is path name of the map. 1645 * name is path name of the map.
1691 * flags meaning: 1646 * flags meaning:
1694 * 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.
1695 * dont do any more name translation on it. 1650 * dont do any more name translation on it.
1696 * 1651 *
1697 * Returns a pointer to the given map. 1652 * Returns a pointer to the given map.
1698 */ 1653 */
1699
1700maptile * 1654maptile *
1701ready_map_name (const char *name, int flags) 1655ready_map_name (const char *name, int flags)
1702{ 1656{
1703 maptile *m; 1657 maptile *m;
1704 1658
2150 timeout = MAP_RESET_TIMEOUT (map); 2104 timeout = MAP_RESET_TIMEOUT (map);
2151 if (timeout <= 0) 2105 if (timeout <= 0)
2152 timeout = MAP_DEFAULTRESET; 2106 timeout = MAP_DEFAULTRESET;
2153 if (timeout >= MAP_MAXRESET) 2107 if (timeout >= MAP_MAXRESET)
2154 timeout = MAP_MAXRESET; 2108 timeout = MAP_MAXRESET;
2155 MAP_WHEN_RESET (map) = seconds () + timeout; 2109 MAP_WHEN_RESET (map) = time (0) + timeout;
2156} 2110}
2157 2111
2158/* 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
2159 * 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
2160 * 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