… | |
… | |
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 | */ |
… | |
… | |
730 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
729 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
731 | shopitems *items = NULL; |
730 | shopitems *items = NULL; |
732 | int i = 0, number_of_entries = 0; |
731 | int i = 0, number_of_entries = 0; |
733 | const typedata *current_type; |
732 | const typedata *current_type; |
734 | |
733 | |
735 | shop_string = strdup_local (input_string); |
734 | shop_string = strdup (input_string); |
736 | p = shop_string; |
735 | p = shop_string; |
737 | /* 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 */ |
738 | while (p) |
737 | while (p) |
739 | { |
738 | { |
740 | p = strchr (p, ';'); |
739 | p = strchr (p, ';'); |
… | |
… | |
926 | * with nothing between). There is no reason in those cases to |
925 | * with nothing between). There is no reason in those cases to |
927 | * keep the empty message. Also, msgbuf contains garbage data |
926 | * keep the empty message. Also, msgbuf contains garbage data |
928 | * when msgpos is zero, so copying it results in crashes |
927 | * when msgpos is zero, so copying it results in crashes |
929 | */ |
928 | */ |
930 | if (msgpos != 0) |
929 | if (msgpos != 0) |
931 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup (msgbuf); |
932 | } |
931 | } |
933 | else if (!strcmp (key, "maplore")) |
932 | else if (!strcmp (key, "maplore")) |
934 | { |
933 | { |
935 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
936 | { |
935 | { |
… | |
… | |
942 | strcpy (maplorebuf + maplorepos, buf); |
941 | strcpy (maplorebuf + maplorepos, buf); |
943 | maplorepos += strlen (buf); |
942 | maplorepos += strlen (buf); |
944 | } |
943 | } |
945 | } |
944 | } |
946 | if (maplorepos != 0) |
945 | if (maplorepos != 0) |
947 | m->maplore = strdup_local (maplorebuf); |
946 | m->maplore = strdup (maplorebuf); |
948 | } |
947 | } |
949 | else if (!strcmp (key, "end")) |
948 | else if (!strcmp (key, "end")) |
950 | { |
949 | { |
951 | break; |
950 | break; |
952 | } |
951 | } |
… | |
… | |
961 | 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); |
962 | } |
961 | } |
963 | else if (!strcmp (key, "name")) |
962 | else if (!strcmp (key, "name")) |
964 | { |
963 | { |
965 | *end = 0; |
964 | *end = 0; |
966 | m->name = strdup_local (value); |
965 | m->name = strdup (value); |
967 | } |
966 | } |
968 | /* first strcmp value on these are old names supported |
967 | /* first strcmp value on these are old names supported |
969 | * for compatibility reasons. The new values (second) are |
968 | * for compatibility reasons. The new values (second) are |
970 | * what really should be used. |
969 | * what really should be used. |
971 | */ |
970 | */ |
… | |
… | |
1009 | else if (!strcmp (key, "shopmax")) |
1008 | else if (!strcmp (key, "shopmax")) |
1010 | m->shopmax = atol (value); |
1009 | m->shopmax = atol (value); |
1011 | else if (!strcmp (key, "shoprace")) |
1010 | else if (!strcmp (key, "shoprace")) |
1012 | { |
1011 | { |
1013 | *end = 0; |
1012 | *end = 0; |
1014 | m->shoprace = strdup_local (value); |
1013 | m->shoprace = strdup (value); |
1015 | } |
1014 | } |
1016 | else if (!strcmp (key, "outdoor")) |
1015 | else if (!strcmp (key, "outdoor")) |
1017 | m->outdoor = atoi (value); |
1016 | m->outdoor = atoi (value); |
1018 | else if (!strcmp (key, "temp")) |
1017 | else if (!strcmp (key, "temp")) |
1019 | m->temp = atoi (value); |
1018 | m->temp = atoi (value); |
… | |
… | |
1069 | } |
1068 | } |
1070 | |
1069 | |
1071 | if (editor) |
1070 | if (editor) |
1072 | { |
1071 | { |
1073 | /* Use the value as in the file. */ |
1072 | /* Use the value as in the file. */ |
1074 | m->tile_path[tile - 1] = strdup_local (value); |
1073 | m->tile_path[tile - 1] = strdup (value); |
1075 | } |
1074 | } |
1076 | else if (path != NULL) |
1075 | else if (path != NULL) |
1077 | { |
1076 | { |
1078 | /* Use the normalized value. */ |
1077 | /* Use the normalized value. */ |
1079 | m->tile_path[tile - 1] = strdup_local (path); |
1078 | m->tile_path[tile - 1] = strdup (path); |
1080 | } |
1079 | } |
1081 | } /* end if tile direction (in)valid */ |
1080 | } /* end if tile direction (in)valid */ |
1082 | } |
1081 | } |
1083 | else |
1082 | else |
1084 | 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); |
… | |
… | |
1343 | make_path_to_file (filename); |
1342 | make_path_to_file (filename); |
1344 | } |
1343 | } |
1345 | else |
1344 | else |
1346 | { |
1345 | { |
1347 | if (!m->tmpname) |
1346 | if (!m->tmpname) |
1348 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1347 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1349 | |
1348 | |
1350 | strcpy (filename, m->tmpname); |
1349 | strcpy (filename, m->tmpname); |
1351 | } |
1350 | } |
1352 | |
1351 | |
1353 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1352 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1532 | if (!m->in_memory) |
1531 | if (!m->in_memory) |
1533 | { |
1532 | { |
1534 | LOG (llevError, "Trying to free freed map.\n"); |
1533 | LOG (llevError, "Trying to free freed map.\n"); |
1535 | return; |
1534 | return; |
1536 | } |
1535 | } |
|
|
1536 | |
|
|
1537 | // TODO: use new/delete |
|
|
1538 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1539 | |
1537 | if (flag && m->spaces) |
1540 | if (flag && m->spaces) |
1538 | free_all_objects (m); |
1541 | free_all_objects (m); |
1539 | if (m->name) |
1542 | if (m->name) |
1540 | FREE_AND_CLEAR (m->name); |
1543 | FREE_AND_CLEAR (m->name); |
1541 | if (m->spaces) |
1544 | if (m->spaces) |
1542 | FREE_AND_CLEAR (m->spaces); |
1545 | FREE_AND_CLEAR (m->spaces); |
1543 | if (m->msg) |
1546 | if (m->msg) |
1544 | FREE_AND_CLEAR (m->msg); |
1547 | FREE_AND_CLEAR (m->msg); |
1545 | if (m->maplore) |
1548 | if (m->maplore) |
1546 | FREE_AND_CLEAR (m->maplore); |
1549 | FREE_AND_CLEAR (m->maplore); |
1547 | if (m->shopitems) |
1550 | |
1548 | delete[]m->shopitems; |
1551 | delete [] m->shopitems; |
1549 | m->shopitems = 0; |
1552 | m->shopitems = 0; |
|
|
1553 | |
1550 | if (m->shoprace) |
1554 | if (m->shoprace) |
1551 | FREE_AND_CLEAR (m->shoprace); |
1555 | FREE_AND_CLEAR (m->shoprace); |
|
|
1556 | |
1552 | if (m->buttons) |
1557 | if (m->buttons) |
1553 | free_objectlinkpt (m->buttons); |
1558 | free_objectlinkpt (m->buttons); |
|
|
1559 | |
1554 | m->buttons = NULL; |
1560 | m->buttons = NULL; |
|
|
1561 | |
1555 | for (i = 0; i < 4; i++) |
1562 | for (i = 0; i < 4; i++) |
1556 | { |
1563 | { |
1557 | if (m->tile_path[i]) |
1564 | if (m->tile_path[i]) |
1558 | FREE_AND_CLEAR (m->tile_path[i]); |
1565 | FREE_AND_CLEAR (m->tile_path[i]); |
1559 | m->tile_map[i] = NULL; |
1566 | m->tile_map[i] = NULL; |
1560 | } |
1567 | } |
|
|
1568 | |
1561 | m->in_memory = MAP_SWAPPED; |
1569 | m->in_memory = MAP_SWAPPED; |
|
|
1570 | |
|
|
1571 | #undef FREE_AND_CLEAR |
|
|
1572 | |
1562 | } |
1573 | } |
1563 | |
1574 | |
1564 | /* |
1575 | /* |
1565 | * function: vanish maptile |
1576 | * function: vanish maptile |
1566 | * m : pointer to maptile, if NULL no action |
1577 | * m : pointer to maptile, if NULL no action |
… | |
… | |
1626 | else |
1637 | else |
1627 | last->next = m->next; |
1638 | last->next = m->next; |
1628 | |
1639 | |
1629 | delete m; |
1640 | delete m; |
1630 | } |
1641 | } |
1631 | |
|
|
1632 | |
|
|
1633 | |
1642 | |
1634 | /* |
1643 | /* |
1635 | * Makes sure the given map is loaded and swapped in. |
1644 | * Makes sure the given map is loaded and swapped in. |
1636 | * name is path name of the map. |
1645 | * name is path name of the map. |
1637 | * flags meaning: |
1646 | * flags meaning: |
… | |
… | |
1640 | * 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. |
1641 | * dont do any more name translation on it. |
1650 | * dont do any more name translation on it. |
1642 | * |
1651 | * |
1643 | * Returns a pointer to the given map. |
1652 | * Returns a pointer to the given map. |
1644 | */ |
1653 | */ |
1645 | |
|
|
1646 | maptile * |
1654 | maptile * |
1647 | ready_map_name (const char *name, int flags) |
1655 | ready_map_name (const char *name, int flags) |
1648 | { |
1656 | { |
1649 | maptile *m; |
1657 | maptile *m; |
1650 | |
1658 | |
… | |
… | |
2096 | timeout = MAP_RESET_TIMEOUT (map); |
2104 | timeout = MAP_RESET_TIMEOUT (map); |
2097 | if (timeout <= 0) |
2105 | if (timeout <= 0) |
2098 | timeout = MAP_DEFAULTRESET; |
2106 | timeout = MAP_DEFAULTRESET; |
2099 | if (timeout >= MAP_MAXRESET) |
2107 | if (timeout >= MAP_MAXRESET) |
2100 | timeout = MAP_MAXRESET; |
2108 | timeout = MAP_MAXRESET; |
2101 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2109 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2102 | } |
2110 | } |
2103 | |
2111 | |
2104 | /* 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 |
2105 | * 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 |
2106 | * 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 |