… | |
… | |
36 | * it really should be called create_mapname |
36 | * it really should be called create_mapname |
37 | */ |
37 | */ |
38 | const char * |
38 | const char * |
39 | create_pathname (const char *name) |
39 | create_pathname (const char *name) |
40 | { |
40 | { |
41 | static char buf[MAX_BUF]; |
41 | static char buf[8192]; |
42 | |
|
|
43 | /* Why? having extra / doesn't confuse unix anyplace? Dependancies |
|
|
44 | * someplace else in the code? msw 2-17-97 |
|
|
45 | */ |
|
|
46 | if (*name == '/') |
|
|
47 | sprintf (buf, "%s/%s%s", settings.datadir, settings.mapdir, name); |
|
|
48 | else |
|
|
49 | sprintf (buf, "%s/%s/%s", settings.datadir, settings.mapdir, name); |
42 | snprintf (buf, sizeof (buf), "%s/%s/%s", settings.datadir, settings.mapdir, name); |
50 | return (buf); |
43 | return buf; |
51 | } |
|
|
52 | |
|
|
53 | /* |
|
|
54 | * same as create_pathname, but for the overlay maps. |
|
|
55 | */ |
|
|
56 | const char * |
|
|
57 | create_overlay_pathname (const char *name) |
|
|
58 | { |
|
|
59 | static char buf[MAX_BUF]; |
|
|
60 | |
|
|
61 | /* Why? having extra / doesn't confuse unix anyplace? Dependancies |
|
|
62 | * someplace else in the code? msw 2-17-97 |
|
|
63 | */ |
|
|
64 | if (*name == '/') |
|
|
65 | sprintf (buf, "%s/%s%s", settings.localdir, settings.mapdir, name); |
|
|
66 | else |
|
|
67 | sprintf (buf, "%s/%s/%s", settings.localdir, settings.mapdir, name); |
|
|
68 | return (buf); |
|
|
69 | } |
|
|
70 | |
|
|
71 | /* |
|
|
72 | * same as create_pathname, but for the template maps. |
|
|
73 | */ |
|
|
74 | const char * |
|
|
75 | create_template_pathname (const char *name) |
|
|
76 | { |
|
|
77 | static char buf[MAX_BUF]; |
|
|
78 | |
|
|
79 | /* Why? having extra / doesn't confuse unix anyplace? Dependancies |
|
|
80 | * someplace else in the code? msw 2-17-97 |
|
|
81 | */ |
|
|
82 | if (*name == '/') |
|
|
83 | sprintf (buf, "%s/%s%s", settings.localdir, settings.templatedir, name); |
|
|
84 | else |
|
|
85 | sprintf (buf, "%s/%s/%s", settings.localdir, settings.templatedir, name); |
|
|
86 | return (buf); |
|
|
87 | } |
|
|
88 | |
|
|
89 | /* |
|
|
90 | * This makes absolute path to the itemfile where unique objects |
|
|
91 | * will be saved. Converts '/' to '@'. I think it's essier maintain |
|
|
92 | * files than full directory structure, but if this is problem it can |
|
|
93 | * be changed. |
|
|
94 | */ |
|
|
95 | static const char * |
|
|
96 | create_items_path (const char *s) |
|
|
97 | { |
|
|
98 | static char buf[MAX_BUF]; |
|
|
99 | char *t; |
|
|
100 | |
|
|
101 | if (*s == '/') |
|
|
102 | s++; |
|
|
103 | |
|
|
104 | sprintf (buf, "%s/%s/", settings.localdir, settings.uniquedir); |
|
|
105 | |
|
|
106 | for (t = buf + strlen (buf); *s; s++, t++) |
|
|
107 | if (*s == '/') |
|
|
108 | *t = '@'; |
|
|
109 | else |
|
|
110 | *t = *s; |
|
|
111 | *t = 0; |
|
|
112 | return (buf); |
|
|
113 | } |
44 | } |
114 | |
45 | |
115 | /* |
46 | /* |
116 | * This function checks if a file with the given path exists. |
47 | * This function checks if a file with the given path exists. |
117 | * -1 is returned if it fails, otherwise the mode of the file |
48 | * -1 is returned if it fails, otherwise the mode of the file |
… | |
… | |
528 | if (!spaces) |
459 | if (!spaces) |
529 | return; |
460 | return; |
530 | |
461 | |
531 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
462 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
532 | for (object *op = ms->bot; op; op = op->above) |
463 | for (object *op = ms->bot; op; op = op->above) |
533 | op->activate (1); |
464 | op->activate_recursive (); |
534 | } |
465 | } |
535 | |
466 | |
536 | void |
467 | void |
537 | maptile::deactivate () |
468 | maptile::deactivate () |
538 | { |
469 | { |
539 | if (!spaces) |
470 | if (!spaces) |
540 | return; |
471 | return; |
541 | |
472 | |
542 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
473 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
543 | for (object *op = ms->bot; op; op = op->above) |
474 | for (object *op = ms->bot; op; op = op->above) |
544 | op->deactivate (1); |
475 | op->deactivate_recursive (); |
545 | } |
476 | } |
546 | |
477 | |
547 | bool |
478 | bool |
548 | maptile::save_objects (object_freezer &freezer, int flags) |
479 | maptile::save_objects (object_freezer &freezer, int flags) |
549 | { |
480 | { |
… | |
… | |
789 | keyword kw = thawer.get_kv (); |
720 | keyword kw = thawer.get_kv (); |
790 | |
721 | |
791 | switch (kw) |
722 | switch (kw) |
792 | { |
723 | { |
793 | case KW_EOF: |
724 | case KW_EOF: |
794 | LOG (llevError, "%s: end of file while reading map header, aborting header load.", &path); |
725 | LOG (llevError, "%s: end of file while reading map header, aborting header load.\n", &path); |
795 | return false; |
726 | return false; |
796 | |
727 | |
797 | case KW_end: |
728 | case KW_end: |
798 | return true; |
729 | return true; |
799 | |
730 | |
… | |
… | |
957 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
888 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
958 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
889 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
959 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
890 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
960 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
891 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
961 | |
892 | |
962 | MAP_OUT2 (end, 0); |
893 | freezer.put (this); |
|
|
894 | freezer.put (KW_end); |
963 | |
895 | |
964 | return true; |
896 | return true; |
965 | } |
897 | } |
966 | |
898 | |
967 | bool |
899 | bool |
… | |
… | |
1333 | * so that it is easier for calling functions to verify success. |
1265 | * so that it is easier for calling functions to verify success. |
1334 | */ |
1266 | */ |
1335 | static maptile * |
1267 | static maptile * |
1336 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
1268 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
1337 | { |
1269 | { |
1338 | maptile *mp = orig_map->find_map (orig_map->tile_path[tile_num]); |
1270 | maptile *mp = orig_map->load_map_sync (orig_map->tile_path [tile_num], orig_map); |
1339 | mp->load (); |
1271 | |
|
|
1272 | if (!mp || mp->in_memory != MAP_IN_MEMORY) |
|
|
1273 | { |
|
|
1274 | // emergency mode, manufacture a dummy map, this creates a memleak, but thats fine |
|
|
1275 | LOG (llevError, "FATAL: cannot load tiled map %s from %s, leaking memory and worse!\n", |
|
|
1276 | &orig_map->tile_path[tile_num], &orig_map->path); |
|
|
1277 | mp = new maptile (1, 1); |
|
|
1278 | mp->alloc (); |
|
|
1279 | mp->in_memory = MAP_IN_MEMORY; |
|
|
1280 | } |
1340 | |
1281 | |
1341 | int dest_tile = (tile_num + 2) % 4; |
1282 | int dest_tile = (tile_num + 2) % 4; |
1342 | |
1283 | |
1343 | orig_map->tile_map[tile_num] = mp; |
1284 | orig_map->tile_map[tile_num] = mp; |
1344 | |
1285 | |
1345 | /* need to do a strcmp here as the orig_map->path is not a shared string */ |
1286 | // optimisation: back-link map to origin map if euclidean |
1346 | if (orig_map->tile_map[tile_num]->tile_path[dest_tile] && orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path) |
1287 | //TODO: non-euclidean maps MUST GO |
|
|
1288 | if (orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path) |
1347 | orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map; |
1289 | orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map; |
1348 | |
1290 | |
1349 | return mp; |
1291 | return mp; |
1350 | } |
1292 | } |
1351 | |
1293 | |