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.31 by root, Sat Sep 16 22:24:12 2006 UTC vs.
Revision 1.37 by pippijn, Mon Dec 11 14:28:12 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 */
275 retval |= mp->spaces[newx + mp->width * newy].flags; 273 retval |= mp->spaces[newx + mp->width * newy].flags;
276 274
277 return retval; 275 return retval;
278} 276}
279 277
280
281/* 278/*
282 * Returns true if the given coordinate is blocked except by the 279 * Returns true if the given coordinate is blocked except by the
283 * object passed is not blocking. This is used with 280 * object passed is not blocking. This is used with
284 * multipart monsters - if we want to see if a 2x2 monster 281 * multipart monsters - if we want to see if a 2x2 monster
285 * can move 1 space to the left, we don't want its own area 282 * can move 1 space to the left, we don't want its own area
288 * monster. 285 * monster.
289 * m, x, y are the target map/coordinates - needed for map tiling. 286 * m, x, y are the target map/coordinates - needed for map tiling.
290 * the coordinates & map passed in should have been updated for tiling 287 * the coordinates & map passed in should have been updated for tiling
291 * by the caller. 288 * by the caller.
292 */ 289 */
293
294int 290int
295blocked_link (object *ob, maptile *m, int sx, int sy) 291blocked_link (object *ob, maptile *m, int sx, int sy)
296{ 292{
297 object *tmp; 293 object *tmp;
298 int mflags, blocked; 294 int mflags, blocked;
647 643
648 } /* for this space */ 644 } /* for this space */
649 } /* for this j */ 645 } /* for this j */
650} 646}
651 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
652/* 665/*
653 * Allocates, initialises, and returns a pointer to a maptile. 666 * Allocates, initialises, and returns a pointer to a maptile.
654 * 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
655 * used anyways. MSW 2001-07-01 668 * used anyways. MSW 2001-07-01
656 */ 669 */
657
658maptile * 670maptile *
659get_linked_map (void) 671get_linked_map (void)
660{ 672{
661 maptile *map = new maptile; 673 maptile *mp, *map = new maptile;
662 maptile *mp;
663 674
664 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 675 for (mp = first_map; mp && mp->next; mp = mp->next);
676
665 if (mp == NULL) 677 if (mp == NULL)
666 first_map = map; 678 first_map = map;
667 else 679 else
668 mp->next = map; 680 mp->next = map;
669 681
670 map->in_memory = MAP_SWAPPED;
671 /* The maps used to pick up default x and y values from the
672 * map archetype. Mimic that behaviour.
673 */
674 MAP_WIDTH (map) = 16;
675 MAP_HEIGHT (map) = 16;
676 MAP_RESET_TIMEOUT (map) = 0;
677 MAP_TIMEOUT (map) = 300;
678 MAP_ENTER_X (map) = 0;
679 MAP_ENTER_Y (map) = 0;
680 /*set part to -1 indicating conversion to weather map not yet done */
681 MAP_WORLDPARTX (map) = -1;
682 MAP_WORLDPARTY (map) = -1;
683 return map; 682 return map;
684} 683}
685 684
686/* 685/*
687 * Allocates the arrays contained in a maptile. 686 * Allocates the arrays contained in a maptile.
688 * This basically allocates the dynamic array of spaces for the 687 * This basically allocates the dynamic array of spaces for the
689 * map. 688 * map.
690 */ 689 */
691
692void 690void
693allocate_map (maptile *m) 691maptile::allocate ()
694{ 692{
695 m->in_memory = MAP_IN_MEMORY; 693 in_memory = MAP_IN_MEMORY;
694
696 /* Log this condition and free the storage. We could I suppose 695 /* Log this condition and free the storage. We could I suppose
697 * 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,
698 * that is their poor assumption. 697 * that is their poor assumption.
699 */ 698 */
700 if (m->spaces) 699 if (spaces)
701 { 700 {
702 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);
703 free (m->spaces); 702 free (spaces);
704 } 703 }
705 704
706 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 705 spaces = (MapSpace *)
706 calloc (1, width * height * sizeof (MapSpace));
707 707
708 if (m->spaces == NULL) 708 if (!spaces)
709 fatal (OUT_OF_MEMORY); 709 fatal (OUT_OF_MEMORY);
710} 710}
711 711
712/* Create and returns a map of the specific size. Used 712/* Create and returns a map of the specific size. Used
713 * in random map code and the editor. 713 * in random map code and the editor.
718 maptile *m = get_linked_map (); 718 maptile *m = get_linked_map ();
719 719
720 m->width = sizex; 720 m->width = sizex;
721 m->height = sizey; 721 m->height = sizey;
722 m->in_memory = MAP_SWAPPED; 722 m->in_memory = MAP_SWAPPED;
723 allocate_map (m); 723 m->allocate ();
724
724 return m; 725 return m;
725} 726}
726 727
727/* 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
728 * 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
855{ 856{
856 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;
857 int msgpos = 0; 858 int msgpos = 0;
858 int maplorepos = 0; 859 int maplorepos = 0;
859 860
860 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 861 while (fgets (buf, HUGE_BUF, fp) != NULL)
861 { 862 {
862 buf[HUGE_BUF - 1] = 0; 863 buf[HUGE_BUF - 1] = 0;
863 key = buf; 864 key = buf;
865
864 while (isspace (*key)) 866 while (isspace (*key))
865 key++; 867 key++;
868
866 if (*key == 0) 869 if (*key == 0)
867 continue; /* empty line */ 870 continue; /* empty line */
871
868 value = strchr (key, ' '); 872 value = strchr (key, ' ');
873
869 if (!value) 874 if (!value)
870 { 875 {
871 end = strchr (key, '\n'); 876 if ((end = strchr (key, '\n')))
872 if (end != NULL)
873 {
874 *end = 0; 877 *end = 0;
875 }
876 } 878 }
877 else 879 else
878 { 880 {
879 *value = 0; 881 *value = 0;
880 value++; 882 value++;
881 end = strchr (value, '\n'); 883 end = strchr (value, '\n');
884
882 while (isspace (*value)) 885 while (isspace (*value))
883 { 886 {
884 value++; 887 value++;
888
885 if (*value == '\0' || value == end) 889 if (*value == '\0' || value == end)
886 { 890 {
887 /* Nothing but spaces. */ 891 /* Nothing but spaces. */
888 value = NULL; 892 value = NULL;
889 break; 893 break;
912 * that use the parameter. 916 * that use the parameter.
913 */ 917 */
914 918
915 if (!strcmp (key, "msg")) 919 if (!strcmp (key, "msg"))
916 { 920 {
917 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 921 while (fgets (buf, HUGE_BUF, fp) != NULL)
918 { 922 {
919 if (!strcmp (buf, "endmsg\n")) 923 if (!strcmp (buf, "endmsg\n"))
920 break; 924 break;
921 else 925 else
922 { 926 {
933 if (msgpos != 0) 937 if (msgpos != 0)
934 m->msg = strdup_local (msgbuf); 938 m->msg = strdup_local (msgbuf);
935 } 939 }
936 else if (!strcmp (key, "maplore")) 940 else if (!strcmp (key, "maplore"))
937 { 941 {
938 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 942 while (fgets (buf, HUGE_BUF, fp) != NULL)
939 { 943 {
940 if (!strcmp (buf, "endmaplore\n")) 944 if (!strcmp (buf, "endmaplore\n"))
941 break; 945 break;
942 else 946 else
943 { 947 {
1186 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);
1187 delete_map (m); 1191 delete_map (m);
1188 return NULL; 1192 return NULL;
1189 } 1193 }
1190 1194
1191 allocate_map (m); 1195 m->allocate ();
1192 1196
1193 m->in_memory = MAP_LOADING; 1197 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1198 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1199
1196 m->in_memory = MAP_IN_MEMORY; 1200 m->in_memory = MAP_IN_MEMORY;
1242 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);
1243 delete_map (m); 1247 delete_map (m);
1244 m = load_original_map (m->path, 0); 1248 m = load_original_map (m->path, 0);
1245 return NULL; 1249 return NULL;
1246 } 1250 }
1251
1247 allocate_map (m); 1252 m->allocate ();
1248 1253
1249 m->in_memory = MAP_LOADING; 1254 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1255 load_objects (m, thawer, 0);
1251 1256
1252 m->in_memory = MAP_IN_MEMORY; 1257 m->in_memory = MAP_IN_MEMORY;
1277 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);
1278 delete_map (m); 1283 delete_map (m);
1279 m = load_original_map (m->path, 0); 1284 m = load_original_map (m->path, 0);
1280 return NULL; 1285 return NULL;
1281 } 1286 }
1282 /*allocate_map(m); */ 1287 /*m->allocate ();*/
1283 1288
1284 m->in_memory = MAP_LOADING; 1289 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1290 load_objects (m, thawer, MAP_OVERLAY);
1286 1291
1287 m->in_memory = MAP_IN_MEMORY; 1292 m->in_memory = MAP_IN_MEMORY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines