… | |
… | |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #include <unistd.h> |
29 | #include <unistd.h> |
30 | |
30 | |
31 | #include "path.h" |
31 | #include "path.h" |
32 | |
|
|
33 | |
32 | |
34 | /* |
33 | /* |
35 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
36 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
37 | */ |
36 | */ |
… | |
… | |
532 | { |
531 | { |
533 | int i, j; |
532 | int i, j; |
534 | int unique; |
533 | int unique; |
535 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
534 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
536 | |
535 | |
537 | op = get_object (); |
536 | op = object::create (); |
538 | op->map = m; /* To handle buttons correctly */ |
537 | op->map = m; /* To handle buttons correctly */ |
539 | |
538 | |
540 | while ((i = load_object (fp, op, mapflags))) |
539 | while ((i = load_object (fp, op, mapflags))) |
541 | { |
540 | { |
542 | /* if the archetype for the object is null, means that we |
541 | /* if the archetype for the object is null, means that we |
… | |
… | |
550 | } |
549 | } |
551 | |
550 | |
552 | |
551 | |
553 | switch (i) |
552 | switch (i) |
554 | { |
553 | { |
555 | case LL_NORMAL: |
554 | case LL_NORMAL: |
556 | /* 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 */ |
557 | 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) |
558 | 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); |
559 | else |
558 | else |
560 | 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); |
561 | |
560 | |
562 | if (op->inv) |
561 | if (op->inv) |
563 | sum_weight (op); |
562 | sum_weight (op); |
564 | |
563 | |
565 | prev = op, last_more = op; |
564 | prev = op, last_more = op; |
566 | break; |
565 | break; |
567 | |
566 | |
568 | case LL_MORE: |
567 | case LL_MORE: |
569 | 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); |
570 | op->head = prev, last_more->more = op, last_more = op; |
569 | op->head = prev, last_more->more = op, last_more = op; |
571 | break; |
570 | break; |
572 | } |
571 | } |
573 | |
572 | |
574 | if (mapflags & MAP_STYLE) |
573 | if (mapflags & MAP_STYLE) |
575 | remove_from_active_list (op); |
574 | remove_from_active_list (op); |
576 | |
575 | |
577 | op = get_object (); |
576 | op = object::create (); |
578 | op->map = m; |
577 | op->map = m; |
579 | } |
578 | } |
580 | |
579 | |
581 | for (i = 0; i < m->width; i++) |
580 | for (i = 0; i < m->width; i++) |
582 | { |
581 | { |
… | |
… | |
586 | /* check for unique items, or unique squares */ |
585 | /* check for unique items, or unique squares */ |
587 | 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) |
588 | { |
587 | { |
589 | 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)) |
590 | unique = 1; |
589 | unique = 1; |
|
|
590 | |
591 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
591 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
592 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
592 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
593 | } |
593 | } |
594 | } |
594 | } |
595 | } |
595 | } |
596 | |
596 | |
597 | op->destroy (0); |
597 | op->destroy (); |
598 | link_multipart_objects (m); |
598 | link_multipart_objects (m); |
599 | } |
599 | } |
600 | |
600 | |
601 | /* 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. |
602 | * 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, |
… | |
… | |
729 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
729 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
730 | shopitems *items = NULL; |
730 | shopitems *items = NULL; |
731 | int i = 0, number_of_entries = 0; |
731 | int i = 0, number_of_entries = 0; |
732 | const typedata *current_type; |
732 | const typedata *current_type; |
733 | |
733 | |
734 | shop_string = strdup_local (input_string); |
734 | shop_string = strdup (input_string); |
735 | p = shop_string; |
735 | p = shop_string; |
736 | /* 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 */ |
737 | while (p) |
737 | while (p) |
738 | { |
738 | { |
739 | p = strchr (p, ';'); |
739 | p = strchr (p, ';'); |
… | |
… | |
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, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
935 | { |
935 | { |
… | |
… | |
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 |
… | |
… | |
1298 | |
1248 | |
1299 | for (i = 0; i < MAP_WIDTH (m); i++) |
1249 | for (i = 0; i < MAP_WIDTH (m); i++) |
1300 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1250 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1301 | { |
1251 | { |
1302 | unique = 0; |
1252 | unique = 0; |
|
|
1253 | |
1303 | for (op = get_map_ob (m, i, j); op; op = next) |
1254 | for (op = get_map_ob (m, i, j); op; op = next) |
1304 | { |
1255 | { |
1305 | next = op->above; |
1256 | next = op->above; |
|
|
1257 | |
1306 | 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)) |
1307 | unique = 1; |
1259 | unique = 1; |
|
|
1260 | |
1308 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1261 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1309 | { |
1262 | { |
1310 | clean_object (op); |
1263 | clean_object (op); |
|
|
1264 | |
1311 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1265 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1312 | remove_button_link (op); |
1266 | remove_button_link (op); |
1313 | op->remove (); |
1267 | |
1314 | op->destroy (0); |
1268 | op->destroy (); |
1315 | } |
1269 | } |
1316 | } |
1270 | } |
1317 | } |
1271 | } |
1318 | } |
1272 | } |
1319 | |
1273 | |
… | |
… | |
1388 | make_path_to_file (filename); |
1342 | make_path_to_file (filename); |
1389 | } |
1343 | } |
1390 | else |
1344 | else |
1391 | { |
1345 | { |
1392 | if (!m->tmpname) |
1346 | if (!m->tmpname) |
1393 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1347 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1394 | |
1348 | |
1395 | strcpy (filename, m->tmpname); |
1349 | strcpy (filename, m->tmpname); |
1396 | } |
1350 | } |
1397 | |
1351 | |
1398 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1352 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1514 | object *tmp, *next; |
1468 | object *tmp, *next; |
1515 | |
1469 | |
1516 | for (tmp = op->inv; tmp; tmp = next) |
1470 | for (tmp = op->inv; tmp; tmp = next) |
1517 | { |
1471 | { |
1518 | next = tmp->below; |
1472 | next = tmp->below; |
|
|
1473 | |
1519 | clean_object (tmp); |
1474 | clean_object (tmp); |
1520 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1475 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1521 | remove_button_link (tmp); |
1476 | remove_button_link (tmp); |
1522 | tmp->remove (); |
1477 | |
1523 | tmp->destroy (0); |
1478 | tmp->destroy (); |
1524 | } |
1479 | } |
1525 | } |
1480 | } |
1526 | |
1481 | |
1527 | /* |
1482 | /* |
1528 | * Remove and free all objects in the given map. |
1483 | * Remove and free all objects in the given map. |
… | |
… | |
1544 | if (op == previous_obj) |
1499 | if (op == previous_obj) |
1545 | { |
1500 | { |
1546 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1501 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1547 | break; |
1502 | break; |
1548 | } |
1503 | } |
|
|
1504 | |
1549 | previous_obj = op; |
1505 | previous_obj = op; |
|
|
1506 | |
1550 | if (op->head != NULL) |
1507 | if (op->head != NULL) |
1551 | op = op->head; |
1508 | op = op->head; |
1552 | |
1509 | |
1553 | /* 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 |
1554 | * 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. |
1555 | */ |
1512 | */ |
1556 | if (m->in_memory == MAP_IN_MEMORY) |
1513 | if (m->in_memory == MAP_IN_MEMORY) |
1557 | clean_object (op); |
1514 | clean_object (op); |
1558 | op->remove (); |
1515 | |
1559 | op->destroy (0); |
1516 | op->destroy (); |
1560 | } |
1517 | } |
1561 | } |
1518 | } |
1562 | } |
1519 | } |
1563 | |
1520 | |
1564 | /* |
1521 | /* |
… | |
… | |
1574 | if (!m->in_memory) |
1531 | if (!m->in_memory) |
1575 | { |
1532 | { |
1576 | LOG (llevError, "Trying to free freed map.\n"); |
1533 | LOG (llevError, "Trying to free freed map.\n"); |
1577 | return; |
1534 | return; |
1578 | } |
1535 | } |
|
|
1536 | |
|
|
1537 | // TODO: use new/delete |
|
|
1538 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1539 | |
1579 | if (flag && m->spaces) |
1540 | if (flag && m->spaces) |
1580 | free_all_objects (m); |
1541 | free_all_objects (m); |
1581 | if (m->name) |
1542 | if (m->name) |
1582 | FREE_AND_CLEAR (m->name); |
1543 | FREE_AND_CLEAR (m->name); |
1583 | if (m->spaces) |
1544 | if (m->spaces) |
1584 | FREE_AND_CLEAR (m->spaces); |
1545 | FREE_AND_CLEAR (m->spaces); |
1585 | if (m->msg) |
1546 | if (m->msg) |
1586 | FREE_AND_CLEAR (m->msg); |
1547 | FREE_AND_CLEAR (m->msg); |
1587 | if (m->maplore) |
1548 | if (m->maplore) |
1588 | FREE_AND_CLEAR (m->maplore); |
1549 | FREE_AND_CLEAR (m->maplore); |
1589 | if (m->shopitems) |
1550 | |
1590 | delete[]m->shopitems; |
1551 | delete [] m->shopitems; |
1591 | m->shopitems = 0; |
1552 | m->shopitems = 0; |
|
|
1553 | |
1592 | if (m->shoprace) |
1554 | if (m->shoprace) |
1593 | FREE_AND_CLEAR (m->shoprace); |
1555 | FREE_AND_CLEAR (m->shoprace); |
|
|
1556 | |
1594 | if (m->buttons) |
1557 | if (m->buttons) |
1595 | free_objectlinkpt (m->buttons); |
1558 | free_objectlinkpt (m->buttons); |
|
|
1559 | |
1596 | m->buttons = NULL; |
1560 | m->buttons = NULL; |
|
|
1561 | |
1597 | for (i = 0; i < 4; i++) |
1562 | for (i = 0; i < 4; i++) |
1598 | { |
1563 | { |
1599 | if (m->tile_path[i]) |
1564 | if (m->tile_path[i]) |
1600 | FREE_AND_CLEAR (m->tile_path[i]); |
1565 | FREE_AND_CLEAR (m->tile_path[i]); |
1601 | m->tile_map[i] = NULL; |
1566 | m->tile_map[i] = NULL; |
1602 | } |
1567 | } |
|
|
1568 | |
1603 | m->in_memory = MAP_SWAPPED; |
1569 | m->in_memory = MAP_SWAPPED; |
|
|
1570 | |
|
|
1571 | #undef FREE_AND_CLEAR |
|
|
1572 | |
1604 | } |
1573 | } |
1605 | |
1574 | |
1606 | /* |
1575 | /* |
1607 | * function: vanish maptile |
1576 | * function: vanish maptile |
1608 | * m : pointer to maptile, if NULL no action |
1577 | * m : pointer to maptile, if NULL no action |
… | |
… | |
1668 | else |
1637 | else |
1669 | last->next = m->next; |
1638 | last->next = m->next; |
1670 | |
1639 | |
1671 | delete m; |
1640 | delete m; |
1672 | } |
1641 | } |
1673 | |
|
|
1674 | |
|
|
1675 | |
1642 | |
1676 | /* |
1643 | /* |
1677 | * Makes sure the given map is loaded and swapped in. |
1644 | * Makes sure the given map is loaded and swapped in. |
1678 | * name is path name of the map. |
1645 | * name is path name of the map. |
1679 | * flags meaning: |
1646 | * flags meaning: |
… | |
… | |
1682 | * 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. |
1683 | * dont do any more name translation on it. |
1650 | * dont do any more name translation on it. |
1684 | * |
1651 | * |
1685 | * Returns a pointer to the given map. |
1652 | * Returns a pointer to the given map. |
1686 | */ |
1653 | */ |
1687 | |
|
|
1688 | maptile * |
1654 | maptile * |
1689 | ready_map_name (const char *name, int flags) |
1655 | ready_map_name (const char *name, int flags) |
1690 | { |
1656 | { |
1691 | maptile *m; |
1657 | maptile *m; |
1692 | |
1658 | |
… | |
… | |
2138 | timeout = MAP_RESET_TIMEOUT (map); |
2104 | timeout = MAP_RESET_TIMEOUT (map); |
2139 | if (timeout <= 0) |
2105 | if (timeout <= 0) |
2140 | timeout = MAP_DEFAULTRESET; |
2106 | timeout = MAP_DEFAULTRESET; |
2141 | if (timeout >= MAP_MAXRESET) |
2107 | if (timeout >= MAP_MAXRESET) |
2142 | timeout = MAP_MAXRESET; |
2108 | timeout = MAP_MAXRESET; |
2143 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2109 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2144 | } |
2110 | } |
2145 | |
2111 | |
2146 | /* 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 |
2147 | * 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 |
2148 | * 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 |