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.34 by root, Sun Dec 3 02:04:57 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
1186 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);
1187 delete_map (m); 1188 delete_map (m);
1188 return NULL; 1189 return NULL;
1189 } 1190 }
1190 1191
1191 allocate_map (m); 1192 m->allocate ();
1192 1193
1193 m->in_memory = MAP_LOADING; 1194 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1195 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1196
1196 m->in_memory = MAP_IN_MEMORY; 1197 m->in_memory = MAP_IN_MEMORY;
1242 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);
1243 delete_map (m); 1244 delete_map (m);
1244 m = load_original_map (m->path, 0); 1245 m = load_original_map (m->path, 0);
1245 return NULL; 1246 return NULL;
1246 } 1247 }
1248
1247 allocate_map (m); 1249 m->allocate ();
1248 1250
1249 m->in_memory = MAP_LOADING; 1251 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1252 load_objects (m, thawer, 0);
1251 1253
1252 m->in_memory = MAP_IN_MEMORY; 1254 m->in_memory = MAP_IN_MEMORY;
1277 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);
1278 delete_map (m); 1280 delete_map (m);
1279 m = load_original_map (m->path, 0); 1281 m = load_original_map (m->path, 0);
1280 return NULL; 1282 return NULL;
1281 } 1283 }
1282 /*allocate_map(m); */ 1284 /*m->allocate ();*/
1283 1285
1284 m->in_memory = MAP_LOADING; 1286 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1287 load_objects (m, thawer, MAP_OVERLAY);
1286 1288
1287 m->in_memory = MAP_IN_MEMORY; 1289 m->in_memory = MAP_IN_MEMORY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines