… | |
… | |
643 | |
643 | |
644 | } /* for this space */ |
644 | } /* for this space */ |
645 | } /* for this j */ |
645 | } /* for this j */ |
646 | } |
646 | } |
647 | |
647 | |
|
|
648 | maptile::maptile () |
|
|
649 | { |
|
|
650 | in_memory = MAP_SWAPPED; |
|
|
651 | /* The maps used to pick up default x and y values from the |
|
|
652 | * map archetype. Mimic that behaviour. |
|
|
653 | */ |
|
|
654 | MAP_WIDTH (this) = 16; |
|
|
655 | MAP_HEIGHT (this) = 16; |
|
|
656 | MAP_RESET_TIMEOUT (this) = 0; |
|
|
657 | MAP_TIMEOUT (this) = 300; |
|
|
658 | MAP_ENTER_X (this) = 0; |
|
|
659 | MAP_ENTER_Y (this) = 0; |
|
|
660 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
661 | MAP_WORLDPARTX (this) = -1; |
|
|
662 | MAP_WORLDPARTY (this) = -1; |
|
|
663 | } |
|
|
664 | |
648 | /* |
665 | /* |
649 | * Allocates, initialises, and returns a pointer to a maptile. |
666 | * Allocates, initialises, and returns a pointer to a maptile. |
650 | * Modified to no longer take a path option which was not being |
667 | * Modified to no longer take a path option which was not being |
651 | * used anyways. MSW 2001-07-01 |
668 | * used anyways. MSW 2001-07-01 |
652 | */ |
669 | */ |
653 | |
|
|
654 | maptile * |
670 | maptile * |
655 | get_linked_map (void) |
671 | get_linked_map (void) |
656 | { |
672 | { |
657 | maptile *map = new maptile; |
673 | maptile *mp, *map = new maptile; |
658 | maptile *mp; |
|
|
659 | |
674 | |
660 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
675 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
676 | |
661 | if (mp == NULL) |
677 | if (mp == NULL) |
662 | first_map = map; |
678 | first_map = map; |
663 | else |
679 | else |
664 | mp->next = map; |
680 | mp->next = map; |
665 | |
681 | |
666 | map->in_memory = MAP_SWAPPED; |
|
|
667 | /* The maps used to pick up default x and y values from the |
|
|
668 | * map archetype. Mimic that behaviour. |
|
|
669 | */ |
|
|
670 | MAP_WIDTH (map) = 16; |
|
|
671 | MAP_HEIGHT (map) = 16; |
|
|
672 | MAP_RESET_TIMEOUT (map) = 0; |
|
|
673 | MAP_TIMEOUT (map) = 300; |
|
|
674 | MAP_ENTER_X (map) = 0; |
|
|
675 | MAP_ENTER_Y (map) = 0; |
|
|
676 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
677 | MAP_WORLDPARTX (map) = -1; |
|
|
678 | MAP_WORLDPARTY (map) = -1; |
|
|
679 | return map; |
682 | return map; |
680 | } |
683 | } |
681 | |
684 | |
682 | /* |
685 | /* |
683 | * Allocates the arrays contained in a maptile. |
686 | * Allocates the arrays contained in a maptile. |
684 | * This basically allocates the dynamic array of spaces for the |
687 | * This basically allocates the dynamic array of spaces for the |
685 | * map. |
688 | * map. |
686 | */ |
689 | */ |
687 | |
|
|
688 | void |
690 | void |
689 | allocate_map (maptile *m) |
691 | maptile::allocate () |
690 | { |
692 | { |
691 | m->in_memory = MAP_IN_MEMORY; |
693 | in_memory = MAP_IN_MEMORY; |
|
|
694 | |
692 | /* Log this condition and free the storage. We could I suppose |
695 | /* Log this condition and free the storage. We could I suppose |
693 | * realloc, but if the caller is presuming the data will be intact, |
696 | * realloc, but if the caller is presuming the data will be intact, |
694 | * that is their poor assumption. |
697 | * that is their poor assumption. |
695 | */ |
698 | */ |
696 | if (m->spaces) |
699 | if (spaces) |
697 | { |
700 | { |
698 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); |
701 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
699 | free (m->spaces); |
702 | free (spaces); |
700 | } |
703 | } |
701 | |
704 | |
702 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
705 | spaces = (MapSpace *) |
|
|
706 | calloc (1, width * height * sizeof (MapSpace)); |
703 | |
707 | |
704 | if (m->spaces == NULL) |
708 | if (!spaces) |
705 | fatal (OUT_OF_MEMORY); |
709 | fatal (OUT_OF_MEMORY); |
706 | } |
710 | } |
707 | |
711 | |
708 | /* Create and returns a map of the specific size. Used |
712 | /* Create and returns a map of the specific size. Used |
709 | * in random map code and the editor. |
713 | * in random map code and the editor. |
… | |
… | |
714 | maptile *m = get_linked_map (); |
718 | maptile *m = get_linked_map (); |
715 | |
719 | |
716 | m->width = sizex; |
720 | m->width = sizex; |
717 | m->height = sizey; |
721 | m->height = sizey; |
718 | m->in_memory = MAP_SWAPPED; |
722 | m->in_memory = MAP_SWAPPED; |
719 | allocate_map (m); |
723 | m->allocate (); |
|
|
724 | |
720 | return m; |
725 | return m; |
721 | } |
726 | } |
722 | |
727 | |
723 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
728 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
724 | * corresponding to that string. Memory is allocated for this, it must be freed |
729 | * corresponding to that string. Memory is allocated for this, it must be freed |
… | |
… | |
1182 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1187 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1183 | delete_map (m); |
1188 | delete_map (m); |
1184 | return NULL; |
1189 | return NULL; |
1185 | } |
1190 | } |
1186 | |
1191 | |
1187 | allocate_map (m); |
1192 | m->allocate (); |
1188 | |
1193 | |
1189 | m->in_memory = MAP_LOADING; |
1194 | m->in_memory = MAP_LOADING; |
1190 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1195 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1191 | |
1196 | |
1192 | m->in_memory = MAP_IN_MEMORY; |
1197 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1238 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1243 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1239 | delete_map (m); |
1244 | delete_map (m); |
1240 | m = load_original_map (m->path, 0); |
1245 | m = load_original_map (m->path, 0); |
1241 | return NULL; |
1246 | return NULL; |
1242 | } |
1247 | } |
|
|
1248 | |
1243 | allocate_map (m); |
1249 | m->allocate (); |
1244 | |
1250 | |
1245 | m->in_memory = MAP_LOADING; |
1251 | m->in_memory = MAP_LOADING; |
1246 | load_objects (m, thawer, 0); |
1252 | load_objects (m, thawer, 0); |
1247 | |
1253 | |
1248 | m->in_memory = MAP_IN_MEMORY; |
1254 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1273 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1279 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1274 | delete_map (m); |
1280 | delete_map (m); |
1275 | m = load_original_map (m->path, 0); |
1281 | m = load_original_map (m->path, 0); |
1276 | return NULL; |
1282 | return NULL; |
1277 | } |
1283 | } |
1278 | /*allocate_map(m); */ |
1284 | /*m->allocate ();*/ |
1279 | |
1285 | |
1280 | m->in_memory = MAP_LOADING; |
1286 | m->in_memory = MAP_LOADING; |
1281 | load_objects (m, thawer, MAP_OVERLAY); |
1287 | load_objects (m, thawer, MAP_OVERLAY); |
1282 | |
1288 | |
1283 | m->in_memory = MAP_IN_MEMORY; |
1289 | m->in_memory = MAP_IN_MEMORY; |