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.33 by root, Sun Oct 8 16:51:50 2006 UTC vs.
Revision 1.36 by root, Mon Dec 11 02:41:25 2006 UTC

643 643
644 } /* for this space */ 644 } /* for this space */
645 } /* for this j */ 645 } /* for this j */
646} 646}
647 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
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
654maptile * 670maptile *
655get_linked_map (void) 671get_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
688void 690void
689allocate_map (maptile *m) 691maptile::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
851{ 856{
852 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;
853 int msgpos = 0; 858 int msgpos = 0;
854 int maplorepos = 0; 859 int maplorepos = 0;
855 860
856 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 861 while (fgets (buf, HUGE_BUF, fp) != NULL)
857 { 862 {
858 buf[HUGE_BUF - 1] = 0; 863 buf[HUGE_BUF - 1] = 0;
859 key = buf; 864 key = buf;
865
860 while (isspace (*key)) 866 while (isspace (*key))
861 key++; 867 key++;
868
862 if (*key == 0) 869 if (*key == 0)
863 continue; /* empty line */ 870 continue; /* empty line */
871
864 value = strchr (key, ' '); 872 value = strchr (key, ' ');
873
865 if (!value) 874 if (!value)
866 { 875 {
867 end = strchr (key, '\n'); 876 if (end = strchr (key, '\n'))
868 if (end != NULL)
869 {
870 *end = 0; 877 *end = 0;
871 }
872 } 878 }
873 else 879 else
874 { 880 {
875 *value = 0; 881 *value = 0;
876 value++; 882 value++;
877 end = strchr (value, '\n'); 883 end = strchr (value, '\n');
884
878 while (isspace (*value)) 885 while (isspace (*value))
879 { 886 {
880 value++; 887 value++;
888
881 if (*value == '\0' || value == end) 889 if (*value == '\0' || value == end)
882 { 890 {
883 /* Nothing but spaces. */ 891 /* Nothing but spaces. */
884 value = NULL; 892 value = NULL;
885 break; 893 break;
908 * that use the parameter. 916 * that use the parameter.
909 */ 917 */
910 918
911 if (!strcmp (key, "msg")) 919 if (!strcmp (key, "msg"))
912 { 920 {
913 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 921 while (fgets (buf, HUGE_BUF, fp) != NULL)
914 { 922 {
915 if (!strcmp (buf, "endmsg\n")) 923 if (!strcmp (buf, "endmsg\n"))
916 break; 924 break;
917 else 925 else
918 { 926 {
929 if (msgpos != 0) 937 if (msgpos != 0)
930 m->msg = strdup_local (msgbuf); 938 m->msg = strdup_local (msgbuf);
931 } 939 }
932 else if (!strcmp (key, "maplore")) 940 else if (!strcmp (key, "maplore"))
933 { 941 {
934 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 942 while (fgets (buf, HUGE_BUF, fp) != NULL)
935 { 943 {
936 if (!strcmp (buf, "endmaplore\n")) 944 if (!strcmp (buf, "endmaplore\n"))
937 break; 945 break;
938 else 946 else
939 { 947 {
1182 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1190 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1183 delete_map (m); 1191 delete_map (m);
1184 return NULL; 1192 return NULL;
1185 } 1193 }
1186 1194
1187 allocate_map (m); 1195 m->allocate ();
1188 1196
1189 m->in_memory = MAP_LOADING; 1197 m->in_memory = MAP_LOADING;
1190 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1198 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1191 1199
1192 m->in_memory = MAP_IN_MEMORY; 1200 m->in_memory = MAP_IN_MEMORY;
1238 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1246 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1239 delete_map (m); 1247 delete_map (m);
1240 m = load_original_map (m->path, 0); 1248 m = load_original_map (m->path, 0);
1241 return NULL; 1249 return NULL;
1242 } 1250 }
1251
1243 allocate_map (m); 1252 m->allocate ();
1244 1253
1245 m->in_memory = MAP_LOADING; 1254 m->in_memory = MAP_LOADING;
1246 load_objects (m, thawer, 0); 1255 load_objects (m, thawer, 0);
1247 1256
1248 m->in_memory = MAP_IN_MEMORY; 1257 m->in_memory = MAP_IN_MEMORY;
1273 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1282 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1274 delete_map (m); 1283 delete_map (m);
1275 m = load_original_map (m->path, 0); 1284 m = load_original_map (m->path, 0);
1276 return NULL; 1285 return NULL;
1277 } 1286 }
1278 /*allocate_map(m); */ 1287 /*m->allocate ();*/
1279 1288
1280 m->in_memory = MAP_LOADING; 1289 m->in_memory = MAP_LOADING;
1281 load_objects (m, thawer, MAP_OVERLAY); 1290 load_objects (m, thawer, MAP_OVERLAY);
1282 1291
1283 m->in_memory = MAP_IN_MEMORY; 1292 m->in_memory = MAP_IN_MEMORY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines