ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.32 by root, Thu Oct 5 16:50:06 2006 UTC vs.
Revision 1.35 by root, Sun Dec 10 01:16:27 2006 UTC

30# include <unistd.h> 30# include <unistd.h>
31#endif /* win32 */ 31#endif /* win32 */
32 32
33#include "path.h" 33#include "path.h"
34 34
35
36extern int nrofallocobjects, nroffreeobjects;
37 35
38/* 36/*
39 * Returns the maptile which has a name matching the given argument. 37 * Returns the maptile which has a name matching the given argument.
40 * return NULL if no match is found. 38 * return NULL if no match is found.
41 */ 39 */
645 643
646 } /* for this space */ 644 } /* for this space */
647 } /* for this j */ 645 } /* for this j */
648} 646}
649 647
648maptile::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
650/* 665/*
651 * Allocates, initialises, and returns a pointer to a maptile. 666 * Allocates, initialises, and returns a pointer to a maptile.
652 * 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
653 * used anyways. MSW 2001-07-01 668 * used anyways. MSW 2001-07-01
654 */ 669 */
655
656maptile * 670maptile *
657get_linked_map (void) 671get_linked_map (void)
658{ 672{
659 maptile *map = new maptile; 673 maptile *mp, *map = new maptile;
660 maptile *mp;
661 674
662 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 675 for (mp = first_map; mp && mp->next; mp = mp->next);
676
663 if (mp == NULL) 677 if (mp == NULL)
664 first_map = map; 678 first_map = map;
665 else 679 else
666 mp->next = map; 680 mp->next = map;
667 681
668 map->in_memory = MAP_SWAPPED;
669 /* The maps used to pick up default x and y values from the
670 * map archetype. Mimic that behaviour.
671 */
672 MAP_WIDTH (map) = 16;
673 MAP_HEIGHT (map) = 16;
674 MAP_RESET_TIMEOUT (map) = 0;
675 MAP_TIMEOUT (map) = 300;
676 MAP_ENTER_X (map) = 0;
677 MAP_ENTER_Y (map) = 0;
678 /*set part to -1 indicating conversion to weather map not yet done */
679 MAP_WORLDPARTX (map) = -1;
680 MAP_WORLDPARTY (map) = -1;
681 return map; 682 return map;
682} 683}
683 684
684/* 685/*
685 * Allocates the arrays contained in a maptile. 686 * Allocates the arrays contained in a maptile.
686 * This basically allocates the dynamic array of spaces for the 687 * This basically allocates the dynamic array of spaces for the
687 * map. 688 * map.
688 */ 689 */
689
690void 690void
691allocate_map (maptile *m) 691maptile::allocate ()
692{ 692{
693 m->in_memory = MAP_IN_MEMORY; 693 in_memory = MAP_IN_MEMORY;
694
694 /* Log this condition and free the storage. We could I suppose 695 /* Log this condition and free the storage. We could I suppose
695 * 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,
696 * that is their poor assumption. 697 * that is their poor assumption.
697 */ 698 */
698 if (m->spaces) 699 if (spaces)
699 { 700 {
700 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);
701 free (m->spaces); 702 free (spaces);
702 } 703 }
703 704
704 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 705 spaces = (MapSpace *)
706 calloc (1, width * height * sizeof (MapSpace));
705 707
706 if (m->spaces == NULL) 708 if (!spaces)
707 fatal (OUT_OF_MEMORY); 709 fatal (OUT_OF_MEMORY);
708} 710}
709 711
710/* Create and returns a map of the specific size. Used 712/* Create and returns a map of the specific size. Used
711 * in random map code and the editor. 713 * in random map code and the editor.
716 maptile *m = get_linked_map (); 718 maptile *m = get_linked_map ();
717 719
718 m->width = sizex; 720 m->width = sizex;
719 m->height = sizey; 721 m->height = sizey;
720 m->in_memory = MAP_SWAPPED; 722 m->in_memory = MAP_SWAPPED;
721 allocate_map (m); 723 m->allocate ();
724
722 return m; 725 return m;
723} 726}
724 727
725/* 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
726 * 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
853{ 856{
854 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 857 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
855 int msgpos = 0; 858 int msgpos = 0;
856 int maplorepos = 0; 859 int maplorepos = 0;
857 860
858 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 861 while (fgets (buf, HUGE_BUF, fp) != NULL)
859 { 862 {
860 buf[HUGE_BUF - 1] = 0; 863 buf[HUGE_BUF - 1] = 0;
861 key = buf; 864 key = buf;
862 while (isspace (*key)) 865 while (isspace (*key))
863 key++; 866 key++;
910 * that use the parameter. 913 * that use the parameter.
911 */ 914 */
912 915
913 if (!strcmp (key, "msg")) 916 if (!strcmp (key, "msg"))
914 { 917 {
915 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 918 while (fgets (buf, HUGE_BUF, fp) != NULL)
916 { 919 {
917 if (!strcmp (buf, "endmsg\n")) 920 if (!strcmp (buf, "endmsg\n"))
918 break; 921 break;
919 else 922 else
920 { 923 {
931 if (msgpos != 0) 934 if (msgpos != 0)
932 m->msg = strdup_local (msgbuf); 935 m->msg = strdup_local (msgbuf);
933 } 936 }
934 else if (!strcmp (key, "maplore")) 937 else if (!strcmp (key, "maplore"))
935 { 938 {
936 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 939 while (fgets (buf, HUGE_BUF, fp) != NULL)
937 { 940 {
938 if (!strcmp (buf, "endmaplore\n")) 941 if (!strcmp (buf, "endmaplore\n"))
939 break; 942 break;
940 else 943 else
941 { 944 {
1184 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);
1185 delete_map (m); 1188 delete_map (m);
1186 return NULL; 1189 return NULL;
1187 } 1190 }
1188 1191
1189 allocate_map (m); 1192 m->allocate ();
1190 1193
1191 m->in_memory = MAP_LOADING; 1194 m->in_memory = MAP_LOADING;
1192 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1195 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1193 1196
1194 m->in_memory = MAP_IN_MEMORY; 1197 m->in_memory = MAP_IN_MEMORY;
1240 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);
1241 delete_map (m); 1244 delete_map (m);
1242 m = load_original_map (m->path, 0); 1245 m = load_original_map (m->path, 0);
1243 return NULL; 1246 return NULL;
1244 } 1247 }
1248
1245 allocate_map (m); 1249 m->allocate ();
1246 1250
1247 m->in_memory = MAP_LOADING; 1251 m->in_memory = MAP_LOADING;
1248 load_objects (m, thawer, 0); 1252 load_objects (m, thawer, 0);
1249 1253
1250 m->in_memory = MAP_IN_MEMORY; 1254 m->in_memory = MAP_IN_MEMORY;
1275 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);
1276 delete_map (m); 1280 delete_map (m);
1277 m = load_original_map (m->path, 0); 1281 m = load_original_map (m->path, 0);
1278 return NULL; 1282 return NULL;
1279 } 1283 }
1280 /*allocate_map(m); */ 1284 /*m->allocate ();*/
1281 1285
1282 m->in_memory = MAP_LOADING; 1286 m->in_memory = MAP_LOADING;
1283 load_objects (m, thawer, MAP_OVERLAY); 1287 load_objects (m, thawer, MAP_OVERLAY);
1284 1288
1285 m->in_memory = MAP_IN_MEMORY; 1289 m->in_memory = MAP_IN_MEMORY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines