… | |
… | |
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 |
… | |
… | |
398 | * carrying. |
329 | * carrying. |
399 | */ |
330 | */ |
400 | sum_weight (container); |
331 | sum_weight (container); |
401 | } |
332 | } |
402 | |
333 | |
|
|
334 | void |
|
|
335 | maptile::set_object_flag (int flag, int value) |
|
|
336 | { |
|
|
337 | if (!spaces) |
|
|
338 | return; |
|
|
339 | |
|
|
340 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
341 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
|
|
342 | tmp->flag [flag] = value; |
|
|
343 | } |
|
|
344 | |
403 | /* link_multipart_objects go through all the objects on the map looking |
345 | /* link_multipart_objects go through all the objects on the map looking |
404 | * for objects whose arch says they are multipart yet according to the |
346 | * for objects whose arch says they are multipart yet according to the |
405 | * info we have, they only have the head (as would be expected when |
347 | * info we have, they only have the head (as would be expected when |
406 | * they are saved). We do have to look for the old maps that did save |
348 | * they are saved). We do have to look for the old maps that did save |
407 | * the more sections and not re-add sections for them. |
349 | * the more sections and not re-add sections for them. |
… | |
… | |
528 | if (!spaces) |
470 | if (!spaces) |
529 | return; |
471 | return; |
530 | |
472 | |
531 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
473 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
532 | for (object *op = ms->bot; op; op = op->above) |
474 | for (object *op = ms->bot; op; op = op->above) |
533 | op->activate (1); |
475 | op->activate_recursive (); |
534 | } |
476 | } |
535 | |
477 | |
536 | void |
478 | void |
537 | maptile::deactivate () |
479 | maptile::deactivate () |
538 | { |
480 | { |
539 | if (!spaces) |
481 | if (!spaces) |
540 | return; |
482 | return; |
541 | |
483 | |
542 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
484 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
543 | for (object *op = ms->bot; op; op = op->above) |
485 | for (object *op = ms->bot; op; op = op->above) |
544 | op->deactivate (1); |
486 | op->deactivate_recursive (); |
545 | } |
487 | } |
546 | |
488 | |
547 | bool |
489 | bool |
548 | maptile::save_objects (object_freezer &freezer, int flags) |
490 | maptile::save_objects (object_freezer &freezer, int flags) |
549 | { |
491 | { |
… | |
… | |
789 | keyword kw = thawer.get_kv (); |
731 | keyword kw = thawer.get_kv (); |
790 | |
732 | |
791 | switch (kw) |
733 | switch (kw) |
792 | { |
734 | { |
793 | case KW_EOF: |
735 | case KW_EOF: |
794 | LOG (llevError, "%s: end of file while reading map header, aborting header load.", &path); |
736 | LOG (llevError, "%s: end of file while reading map header, aborting header load.\n", &path); |
795 | return false; |
737 | return false; |
796 | |
738 | |
797 | case KW_end: |
739 | case KW_end: |
798 | return true; |
740 | return true; |
799 | |
741 | |
… | |
… | |
957 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
899 | 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]); |
900 | 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]); |
901 | 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]); |
902 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
961 | |
903 | |
962 | MAP_OUT2 (end, 0); |
904 | freezer.put (this); |
|
|
905 | freezer.put (KW_end); |
963 | |
906 | |
964 | return true; |
907 | return true; |
965 | } |
908 | } |
966 | |
909 | |
967 | bool |
910 | bool |
… | |
… | |
1333 | * so that it is easier for calling functions to verify success. |
1276 | * so that it is easier for calling functions to verify success. |
1334 | */ |
1277 | */ |
1335 | static maptile * |
1278 | static maptile * |
1336 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
1279 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
1337 | { |
1280 | { |
1338 | maptile *mp = orig_map->find_map (orig_map->tile_path[tile_num]); |
1281 | maptile *mp = orig_map->load_map_sync (orig_map->tile_path [tile_num], orig_map); |
1339 | mp->load (); |
1282 | |
|
|
1283 | if (!mp || mp->in_memory != MAP_IN_MEMORY) |
|
|
1284 | { |
|
|
1285 | // emergency mode, manufacture a dummy map, this creates a memleak, but thats fine |
|
|
1286 | LOG (llevError, "FATAL: cannot load tiled map %s from %s, leaking memory and worse!\n", |
|
|
1287 | &orig_map->tile_path[tile_num], &orig_map->path); |
|
|
1288 | mp = new maptile (1, 1); |
|
|
1289 | mp->alloc (); |
|
|
1290 | mp->in_memory = MAP_IN_MEMORY; |
|
|
1291 | } |
1340 | |
1292 | |
1341 | int dest_tile = (tile_num + 2) % 4; |
1293 | int dest_tile = (tile_num + 2) % 4; |
1342 | |
1294 | |
1343 | orig_map->tile_map[tile_num] = mp; |
1295 | orig_map->tile_map[tile_num] = mp; |
1344 | |
1296 | |
1345 | /* need to do a strcmp here as the orig_map->path is not a shared string */ |
1297 | // 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) |
1298 | //TODO: non-euclidean maps MUST GO |
|
|
1299 | 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; |
1300 | orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map; |
1348 | |
1301 | |
1349 | return mp; |
1302 | return mp; |
1350 | } |
1303 | } |
1351 | |
1304 | |