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.30 by root, Thu Sep 14 22:33:59 2006 UTC vs.
Revision 1.40 by root, Tue Dec 12 21:39:56 2006 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26#include <funcpoint.h>
27 27
28#include <loader.h> 28#include <loader.h>
29#ifndef WIN32 /* ---win32 exclude header */
30# include <unistd.h> 29#include <unistd.h>
31#endif /* win32 */
32 30
33#include "path.h" 31#include "path.h"
34 32
35 33
36extern int nrofallocobjects, nroffreeobjects;
37
38/* 34/*
39 * Returns the mapstruct which has a name matching the given argument. 35 * Returns the maptile which has a name matching the given argument.
40 * return NULL if no match is found. 36 * return NULL if no match is found.
41 */ 37 */
42 38
43mapstruct * 39maptile *
44has_been_loaded (const char *name) 40has_been_loaded (const char *name)
45{ 41{
46 mapstruct *map; 42 maptile *map;
47 43
48 if (!name || !*name) 44 if (!name || !*name)
49 return 0; 45 return 0;
50 for (map = first_map; map; map = map->next) 46 for (map = first_map; map; map = map->next)
51 if (!strcmp (name, map->path)) 47 if (!strcmp (name, map->path))
159int 155int
160check_path (const char *name, int prepend_dir) 156check_path (const char *name, int prepend_dir)
161{ 157{
162 char buf[MAX_BUF]; 158 char buf[MAX_BUF];
163 159
164#ifndef WIN32
165 char *endbuf; 160 char *endbuf;
166 struct stat statbuf; 161 struct stat statbuf;
167 int mode = 0; 162 int mode = 0;
168#endif
169 163
170 if (prepend_dir) 164 if (prepend_dir)
171 strcpy (buf, create_pathname (name)); 165 strcpy (buf, create_pathname (name));
172 else 166 else
173 strcpy (buf, name); 167 strcpy (buf, name);
174#ifdef WIN32 /* ***win32: check this sucker in windows style. */
175 return (_access (buf, 0));
176#else
177 168
178 /* old method (strchr(buf, '\0')) seemd very odd to me - 169 /* old method (strchr(buf, '\0')) seemd very odd to me -
179 * this method should be equivalant and is clearer. 170 * this method should be equivalant and is clearer.
180 * Can not use strcat because we need to cycle through 171 * Can not use strcat because we need to cycle through
181 * all the names. 172 * all the names.
194 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 185 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
195 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) 186 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH))
196 mode |= 2; 187 mode |= 2;
197 188
198 return (mode); 189 return (mode);
199#endif
200} 190}
201 191
202/* 192/*
203 * Prints out debug-information about a map. 193 * Prints out debug-information about a map.
204 * Dumping these at llevError doesn't seem right, but is 194 * Dumping these at llevError doesn't seem right, but is
205 * necessary to make sure the information is in fact logged. 195 * necessary to make sure the information is in fact logged.
206 */ 196 */
207 197
208void 198void
209dump_map (const mapstruct *m) 199dump_map (const maptile *m)
210{ 200{
211 LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); 201 LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory);
212 LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); 202 LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m));
213 203
214 if (m->msg != NULL) 204 if (m->msg != NULL)
231 */ 221 */
232 222
233void 223void
234dump_all_maps (void) 224dump_all_maps (void)
235{ 225{
236 mapstruct *m; 226 maptile *m;
237 227
238 for (m = first_map; m != NULL; m = m->next) 228 for (m = first_map; m != NULL; m = m->next)
239 { 229 {
240 dump_map (m); 230 dump_map (m);
241 } 231 }
250 * is needed. The case of not passing values is if we're just 240 * is needed. The case of not passing values is if we're just
251 * checking for the existence of something on those spaces, but 241 * checking for the existence of something on those spaces, but
252 * don't expect to insert/remove anything from those spaces. 242 * don't expect to insert/remove anything from those spaces.
253 */ 243 */
254int 244int
255get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) 245get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny)
256{ 246{
257 sint16 newx, newy; 247 sint16 newx, newy;
258 int retval = 0; 248 int retval = 0;
259 mapstruct *mp; 249 maptile *mp;
260 250
261 if (out_of_map (oldmap, x, y)) 251 if (out_of_map (oldmap, x, y))
262 return P_OUT_OF_MAP; 252 return P_OUT_OF_MAP;
263 newx = x; 253 newx = x;
264 newy = y; 254 newy = y;
275 retval |= mp->spaces[newx + mp->width * newy].flags; 265 retval |= mp->spaces[newx + mp->width * newy].flags;
276 266
277 return retval; 267 return retval;
278} 268}
279 269
280
281/* 270/*
282 * Returns true if the given coordinate is blocked except by the 271 * Returns true if the given coordinate is blocked except by the
283 * object passed is not blocking. This is used with 272 * object passed is not blocking. This is used with
284 * multipart monsters - if we want to see if a 2x2 monster 273 * 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 274 * can move 1 space to the left, we don't want its own area
288 * monster. 277 * monster.
289 * m, x, y are the target map/coordinates - needed for map tiling. 278 * m, x, y are the target map/coordinates - needed for map tiling.
290 * the coordinates & map passed in should have been updated for tiling 279 * the coordinates & map passed in should have been updated for tiling
291 * by the caller. 280 * by the caller.
292 */ 281 */
293
294int 282int
295blocked_link (object *ob, mapstruct *m, int sx, int sy) 283blocked_link (object *ob, maptile *m, int sx, int sy)
296{ 284{
297 object *tmp; 285 object *tmp;
298 int mflags, blocked; 286 int mflags, blocked;
299 287
300 /* Make sure the coordinates are valid - they should be, as caller should 288 /* Make sure the coordinates are valid - they should be, as caller should
412 * code, we need to have actual object to check its move_type 400 * code, we need to have actual object to check its move_type
413 * against the move_block values. 401 * against the move_block values.
414 */ 402 */
415 403
416int 404int
417ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) 405ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
418{ 406{
419 archetype *tmp; 407 archetype *tmp;
420 int flag; 408 int flag;
421 mapstruct *m1; 409 maptile *m1;
422 sint16 sx, sy; 410 sint16 sx, sy;
423 411
424 if (ob == NULL) 412 if (ob == NULL)
425 { 413 {
426 flag = get_map_flags (m, &m1, x, y, &sx, &sy); 414 flag = get_map_flags (m, &m1, x, y, &sx, &sy);
491 * they are saved). We do have to look for the old maps that did save 479 * they are saved). We do have to look for the old maps that did save
492 * the more sections and not re-add sections for them. 480 * the more sections and not re-add sections for them.
493 */ 481 */
494 482
495static void 483static void
496link_multipart_objects (mapstruct *m) 484link_multipart_objects (maptile *m)
497{ 485{
498 int x, y; 486 int x, y;
499 object *tmp, *op, *last, *above; 487 object *tmp, *op, *last, *above;
500 archetype *at; 488 archetype *at;
501 489
538 * Loads (ands parses) the objects into a given map from the specified 526 * Loads (ands parses) the objects into a given map from the specified
539 * file pointer. 527 * file pointer.
540 * mapflags is the same as we get with load_original_map 528 * mapflags is the same as we get with load_original_map
541 */ 529 */
542void 530void
543load_objects (mapstruct *m, object_thawer & fp, int mapflags) 531load_objects (maptile *m, object_thawer & fp, int mapflags)
544{ 532{
545 int i, j; 533 int i, j;
546 int unique; 534 int unique;
547 object *op, *prev = NULL, *last_more = NULL, *otmp; 535 object *op, *prev = NULL, *last_more = NULL, *otmp;
548 536
549 op = get_object (); 537 op = object::create ();
550 op->map = m; /* To handle buttons correctly */ 538 op->map = m; /* To handle buttons correctly */
551 539
552 while ((i = load_object (fp, op, mapflags))) 540 while ((i = load_object (fp, op, mapflags)))
553 { 541 {
554 /* if the archetype for the object is null, means that we 542 /* if the archetype for the object is null, means that we
584 } 572 }
585 573
586 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
587 remove_from_active_list (op); 575 remove_from_active_list (op);
588 576
589 op = get_object (); 577 op = object::create ();
590 op->map = m; 578 op->map = m;
591 } 579 }
592 580
593 for (i = 0; i < m->width; i++) 581 for (i = 0; i < m->width; i++)
594 { 582 {
604 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 592 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
605 } 593 }
606 } 594 }
607 } 595 }
608 596
609 free_object (op); 597 op->destroy ();
610 link_multipart_objects (m); 598 link_multipart_objects (m);
611} 599}
612 600
613/* This saves all the objects on the map in a non destructive fashion. 601/* This saves all the objects on the map in a non destructive fashion.
614 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 602 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
615 * and we only save the head of multi part objects - this is needed 603 * and we only save the head of multi part objects - this is needed
616 * in order to do map tiling properly. 604 * in order to do map tiling properly.
617 */ 605 */
618void 606void
619save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) 607save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag)
620{ 608{
621 int i, j = 0, unique = 0; 609 int i, j = 0, unique = 0;
622 object *op; 610 object *op;
623 611
624 /* first pass - save one-part objects */ 612 /* first pass - save one-part objects */
647 635
648 } /* for this space */ 636 } /* for this space */
649 } /* for this j */ 637 } /* for this j */
650} 638}
651 639
640maptile::maptile ()
641{
642 in_memory = MAP_SWAPPED;
643 /* The maps used to pick up default x and y values from the
644 * map archetype. Mimic that behaviour.
645 */
646 MAP_WIDTH (this) = 16;
647 MAP_HEIGHT (this) = 16;
648 MAP_RESET_TIMEOUT (this) = 0;
649 MAP_TIMEOUT (this) = 300;
650 MAP_ENTER_X (this) = 0;
651 MAP_ENTER_Y (this) = 0;
652 /*set part to -1 indicating conversion to weather map not yet done */
653 MAP_WORLDPARTX (this) = -1;
654 MAP_WORLDPARTY (this) = -1;
655}
656
652/* 657/*
653 * Allocates, initialises, and returns a pointer to a mapstruct. 658 * Allocates, initialises, and returns a pointer to a maptile.
654 * Modified to no longer take a path option which was not being 659 * Modified to no longer take a path option which was not being
655 * used anyways. MSW 2001-07-01 660 * used anyways. MSW 2001-07-01
656 */ 661 */
657 662maptile *
658mapstruct *
659get_linked_map (void) 663get_linked_map (void)
660{ 664{
661 mapstruct *map = new mapstruct; 665 maptile *mp, *map = new maptile;
662 mapstruct *mp;
663 666
664 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 667 for (mp = first_map; mp && mp->next; mp = mp->next);
668
665 if (mp == NULL) 669 if (mp == NULL)
666 first_map = map; 670 first_map = map;
667 else 671 else
668 mp->next = map; 672 mp->next = map;
669 673
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; 674 return map;
684} 675}
685 676
686/* 677/*
687 * Allocates the arrays contained in a mapstruct. 678 * Allocates the arrays contained in a maptile.
688 * This basically allocates the dynamic array of spaces for the 679 * This basically allocates the dynamic array of spaces for the
689 * map. 680 * map.
690 */ 681 */
691
692void 682void
693allocate_map (mapstruct *m) 683maptile::allocate ()
694{ 684{
695 m->in_memory = MAP_IN_MEMORY; 685 in_memory = MAP_IN_MEMORY;
686
696 /* Log this condition and free the storage. We could I suppose 687 /* Log this condition and free the storage. We could I suppose
697 * realloc, but if the caller is presuming the data will be intact, 688 * realloc, but if the caller is presuming the data will be intact,
698 * that is their poor assumption. 689 * that is their poor assumption.
699 */ 690 */
700 if (m->spaces) 691 if (spaces)
701 { 692 {
702 LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); 693 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
703 free (m->spaces); 694 free (spaces);
704 } 695 }
705 696
706 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 697 spaces = (MapSpace *)
698 calloc (1, width * height * sizeof (MapSpace));
707 699
708 if (m->spaces == NULL) 700 if (!spaces)
709 fatal (OUT_OF_MEMORY); 701 fatal (OUT_OF_MEMORY);
710} 702}
711 703
712/* Create and returns a map of the specific size. Used 704/* Create and returns a map of the specific size. Used
713 * in random map code and the editor. 705 * in random map code and the editor.
714 */ 706 */
715mapstruct * 707maptile *
716get_empty_map (int sizex, int sizey) 708get_empty_map (int sizex, int sizey)
717{ 709{
718 mapstruct *m = get_linked_map (); 710 maptile *m = get_linked_map ();
719 711
720 m->width = sizex; 712 m->width = sizex;
721 m->height = sizey; 713 m->height = sizey;
722 m->in_memory = MAP_SWAPPED; 714 m->in_memory = MAP_SWAPPED;
723 allocate_map (m); 715 m->allocate ();
716
724 return m; 717 return m;
725} 718}
726 719
727/* Takes a string from a map definition and outputs a pointer to the array of shopitems 720/* 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 721 * corresponding to that string. Memory is allocated for this, it must be freed
805} 798}
806 799
807/* opposite of parse string, this puts the string that was originally fed in to 800/* opposite of parse string, this puts the string that was originally fed in to
808 * the map (or something equivilent) into output_string. */ 801 * the map (or something equivilent) into output_string. */
809static void 802static void
810print_shop_string (mapstruct *m, char *output_string) 803print_shop_string (maptile *m, char *output_string)
811{ 804{
812 int i; 805 int i;
813 char tmp[MAX_BUF]; 806 char tmp[MAX_BUF];
814 807
815 strcpy (output_string, ""); 808 strcpy (output_string, "");
849 * MSW 2001-07-01 842 * MSW 2001-07-01
850 * return 0 on success, 1 on failure. 843 * return 0 on success, 1 on failure.
851 */ 844 */
852 845
853static int 846static int
854load_map_header (object_thawer & fp, mapstruct *m) 847load_map_header (object_thawer & fp, maptile *m)
855{ 848{
856 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 849 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
857 int msgpos = 0; 850 int msgpos = 0;
858 int maplorepos = 0; 851 int maplorepos = 0;
859 852
860 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 853 while (fgets (buf, HUGE_BUF, fp) != NULL)
861 { 854 {
862 buf[HUGE_BUF - 1] = 0; 855 buf[HUGE_BUF - 1] = 0;
863 key = buf; 856 key = buf;
857
864 while (isspace (*key)) 858 while (isspace (*key))
865 key++; 859 key++;
860
866 if (*key == 0) 861 if (*key == 0)
867 continue; /* empty line */ 862 continue; /* empty line */
863
868 value = strchr (key, ' '); 864 value = strchr (key, ' ');
865
869 if (!value) 866 if (!value)
870 { 867 {
871 end = strchr (key, '\n'); 868 if ((end = strchr (key, '\n')))
872 if (end != NULL)
873 {
874 *end = 0; 869 *end = 0;
875 }
876 } 870 }
877 else 871 else
878 { 872 {
879 *value = 0; 873 *value = 0;
880 value++; 874 value++;
881 end = strchr (value, '\n'); 875 end = strchr (value, '\n');
876
882 while (isspace (*value)) 877 while (isspace (*value))
883 { 878 {
884 value++; 879 value++;
880
885 if (*value == '\0' || value == end) 881 if (*value == '\0' || value == end)
886 { 882 {
887 /* Nothing but spaces. */ 883 /* Nothing but spaces. */
888 value = NULL; 884 value = NULL;
889 break; 885 break;
912 * that use the parameter. 908 * that use the parameter.
913 */ 909 */
914 910
915 if (!strcmp (key, "msg")) 911 if (!strcmp (key, "msg"))
916 { 912 {
917 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 913 while (fgets (buf, HUGE_BUF, fp) != NULL)
918 { 914 {
919 if (!strcmp (buf, "endmsg\n")) 915 if (!strcmp (buf, "endmsg\n"))
920 break; 916 break;
921 else 917 else
922 { 918 {
933 if (msgpos != 0) 929 if (msgpos != 0)
934 m->msg = strdup_local (msgbuf); 930 m->msg = strdup_local (msgbuf);
935 } 931 }
936 else if (!strcmp (key, "maplore")) 932 else if (!strcmp (key, "maplore"))
937 { 933 {
938 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 934 while (fgets (buf, HUGE_BUF, fp) != NULL)
939 { 935 {
940 if (!strcmp (buf, "endmaplore\n")) 936 if (!strcmp (buf, "endmaplore\n"))
941 break; 937 break;
942 else 938 else
943 { 939 {
1147} 1143}
1148 1144
1149/* 1145/*
1150 * Opens the file "filename" and reads information about the map 1146 * Opens the file "filename" and reads information about the map
1151 * from the given file, and stores it in a newly allocated 1147 * from the given file, and stores it in a newly allocated
1152 * mapstruct. A pointer to this structure is returned, or NULL on failure. 1148 * maptile. A pointer to this structure is returned, or NULL on failure.
1153 * flags correspond to those in map.h. Main ones used are 1149 * flags correspond to those in map.h. Main ones used are
1154 * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and 1150 * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and
1155 * MAP_BLOCK, in which case we block on this load. This happens in all 1151 * MAP_BLOCK, in which case we block on this load. This happens in all
1156 * cases, no matter if this flag is set or not. 1152 * cases, no matter if this flag is set or not.
1157 * MAP_STYLE: style map - don't add active objects, don't add to server 1153 * MAP_STYLE: style map - don't add active objects, don't add to server
1158 * managed map list. 1154 * managed map list.
1159 */ 1155 */
1160 1156
1161mapstruct * 1157maptile *
1162load_original_map (const char *filename, int flags) 1158load_original_map (const char *filename, int flags)
1163{ 1159{
1164 mapstruct *m; 1160 maptile *m;
1165 char pathname[MAX_BUF]; 1161 char pathname[MAX_BUF];
1166 1162
1167 if (flags & MAP_PLAYER_UNIQUE) 1163 if (flags & MAP_PLAYER_UNIQUE)
1168 strcpy (pathname, filename); 1164 strcpy (pathname, filename);
1169 else if (flags & MAP_OVERLAY) 1165 else if (flags & MAP_OVERLAY)
1186 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1182 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1187 delete_map (m); 1183 delete_map (m);
1188 return NULL; 1184 return NULL;
1189 } 1185 }
1190 1186
1191 allocate_map (m); 1187 m->allocate ();
1192 1188
1193 m->in_memory = MAP_LOADING; 1189 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1190 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1191
1196 m->in_memory = MAP_IN_MEMORY; 1192 m->in_memory = MAP_IN_MEMORY;
1205 * Loads a map, which has been loaded earlier, from file. 1201 * Loads a map, which has been loaded earlier, from file.
1206 * Return the map object we load into (this can change from the passed 1202 * Return the map object we load into (this can change from the passed
1207 * option if we can't find the original map) 1203 * option if we can't find the original map)
1208 */ 1204 */
1209 1205
1210static mapstruct * 1206static maptile *
1211load_temporary_map (mapstruct *m) 1207load_temporary_map (maptile *m)
1212{ 1208{
1213 char buf[MAX_BUF]; 1209 char buf[MAX_BUF];
1214 1210
1215 if (!m->tmpname) 1211 if (!m->tmpname)
1216 { 1212 {
1242 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1238 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1243 delete_map (m); 1239 delete_map (m);
1244 m = load_original_map (m->path, 0); 1240 m = load_original_map (m->path, 0);
1245 return NULL; 1241 return NULL;
1246 } 1242 }
1243
1247 allocate_map (m); 1244 m->allocate ();
1248 1245
1249 m->in_memory = MAP_LOADING; 1246 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1247 load_objects (m, thawer, 0);
1251 1248
1252 m->in_memory = MAP_IN_MEMORY; 1249 m->in_memory = MAP_IN_MEMORY;
1258 * Loads a map, which has been loaded earlier, from file. 1255 * Loads a map, which has been loaded earlier, from file.
1259 * Return the map object we load into (this can change from the passed 1256 * Return the map object we load into (this can change from the passed
1260 * option if we can't find the original map) 1257 * option if we can't find the original map)
1261 */ 1258 */
1262 1259
1263mapstruct * 1260maptile *
1264load_overlay_map (const char *filename, mapstruct *m) 1261load_overlay_map (const char *filename, maptile *m)
1265{ 1262{
1266 char pathname[MAX_BUF]; 1263 char pathname[MAX_BUF];
1267 1264
1268 strcpy (pathname, create_overlay_pathname (filename)); 1265 strcpy (pathname, create_overlay_pathname (filename));
1269 1266
1277 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1274 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1278 delete_map (m); 1275 delete_map (m);
1279 m = load_original_map (m->path, 0); 1276 m = load_original_map (m->path, 0);
1280 return NULL; 1277 return NULL;
1281 } 1278 }
1282 /*allocate_map(m); */ 1279 /*m->allocate ();*/
1283 1280
1284 m->in_memory = MAP_LOADING; 1281 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1282 load_objects (m, thawer, MAP_OVERLAY);
1286 1283
1287 m->in_memory = MAP_IN_MEMORY; 1284 m->in_memory = MAP_IN_MEMORY;
1292 * This is the start of unique map handling code 1289 * This is the start of unique map handling code
1293 *****************************************************************************/ 1290 *****************************************************************************/
1294 1291
1295/* This goes through map 'm' and removed any unique items on the map. */ 1292/* This goes through map 'm' and removed any unique items on the map. */
1296static void 1293static void
1297delete_unique_items (mapstruct *m) 1294delete_unique_items (maptile *m)
1298{ 1295{
1299 int i, j, unique; 1296 int i, j, unique;
1300 object *op, *next; 1297 object *op, *next;
1301 1298
1302 for (i = 0; i < MAP_WIDTH (m); i++) 1299 for (i = 0; i < MAP_WIDTH (m); i++)
1303 for (j = 0; j < MAP_HEIGHT (m); j++) 1300 for (j = 0; j < MAP_HEIGHT (m); j++)
1304 { 1301 {
1305 unique = 0; 1302 unique = 0;
1303
1306 for (op = get_map_ob (m, i, j); op; op = next) 1304 for (op = get_map_ob (m, i, j); op; op = next)
1307 { 1305 {
1308 next = op->above; 1306 next = op->above;
1307
1309 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1308 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1310 unique = 1; 1309 unique = 1;
1310
1311 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1311 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1312 { 1312 {
1313 clean_object (op); 1313 clean_object (op);
1314
1314 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1315 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1315 remove_button_link (op); 1316 remove_button_link (op);
1316 remove_ob (op); 1317
1317 free_object (op); 1318 op->destroy ();
1318 } 1319 }
1319 } 1320 }
1320 } 1321 }
1321} 1322}
1322 1323
1324/* 1325/*
1325 * Loads unique objects from file(s) into the map which is in memory 1326 * Loads unique objects from file(s) into the map which is in memory
1326 * m is the map to load unique items into. 1327 * m is the map to load unique items into.
1327 */ 1328 */
1328static void 1329static void
1329load_unique_objects (mapstruct *m) 1330load_unique_objects (maptile *m)
1330{ 1331{
1331 int count; 1332 int count;
1332 char firstname[MAX_BUF]; 1333 char firstname[MAX_BUF];
1333 1334
1334 for (count = 0; count < 10; count++) 1335 for (count = 0; count < 10; count++)
1357 1358
1358/* 1359/*
1359 * Saves a map to file. If flag is set, it is saved into the same 1360 * Saves a map to file. If flag is set, it is saved into the same
1360 * file it was (originally) loaded from. Otherwise a temporary 1361 * file it was (originally) loaded from. Otherwise a temporary
1361 * filename will be genarated, and the file will be stored there. 1362 * filename will be genarated, and the file will be stored there.
1362 * The temporary filename will be stored in the mapstructure. 1363 * The temporary filename will be stored in the maptileure.
1363 * If the map is unique, we also save to the filename in the map 1364 * If the map is unique, we also save to the filename in the map
1364 * (this should have been updated when first loaded) 1365 * (this should have been updated when first loaded)
1365 */ 1366 */
1366 1367
1367int 1368int
1368new_save_map (mapstruct *m, int flag) 1369new_save_map (maptile *m, int flag)
1369{ 1370{
1370 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1371 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1371 int i; 1372 int i;
1372 1373
1373 if (flag && !*m->path) 1374 if (flag && !*m->path)
1425 print_shop_string (m, shop); 1426 print_shop_string (m, shop);
1426 fprintf (freezer, "shopitems %s\n", shop); 1427 fprintf (freezer, "shopitems %s\n", shop);
1427 } 1428 }
1428 if (m->shopgreed) 1429 if (m->shopgreed)
1429 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1430 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1430#ifndef WIN32
1431 if (m->shopmin) 1431 if (m->shopmin)
1432 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1432 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1433 if (m->shopmax) 1433 if (m->shopmax)
1434 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1434 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1435#else
1436 if (m->shopmin)
1437 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1438 if (m->shopmax)
1439 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1440#endif
1441 if (m->shoprace) 1435 if (m->shoprace)
1442 fprintf (freezer, "shoprace %s\n", m->shoprace); 1436 fprintf (freezer, "shoprace %s\n", m->shoprace);
1443 if (m->darkness) 1437 if (m->darkness)
1444 fprintf (freezer, "darkness %d\n", m->darkness); 1438 fprintf (freezer, "darkness %d\n", m->darkness);
1445 if (m->width) 1439 if (m->width)
1524 object *tmp, *next; 1518 object *tmp, *next;
1525 1519
1526 for (tmp = op->inv; tmp; tmp = next) 1520 for (tmp = op->inv; tmp; tmp = next)
1527 { 1521 {
1528 next = tmp->below; 1522 next = tmp->below;
1523
1529 clean_object (tmp); 1524 clean_object (tmp);
1530 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1525 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1531 remove_button_link (tmp); 1526 remove_button_link (tmp);
1532 remove_ob (tmp); 1527
1533 free_object (tmp); 1528 tmp->destroy ();
1534 } 1529 }
1535} 1530}
1536 1531
1537/* 1532/*
1538 * Remove and free all objects in the given map. 1533 * Remove and free all objects in the given map.
1539 */ 1534 */
1540 1535
1541void 1536void
1542free_all_objects (mapstruct *m) 1537free_all_objects (maptile *m)
1543{ 1538{
1544 int i, j; 1539 int i, j;
1545 object *op; 1540 object *op;
1546 1541
1547 for (i = 0; i < MAP_WIDTH (m); i++) 1542 for (i = 0; i < MAP_WIDTH (m); i++)
1554 if (op == previous_obj) 1549 if (op == previous_obj)
1555 { 1550 {
1556 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1551 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1557 break; 1552 break;
1558 } 1553 }
1554
1559 previous_obj = op; 1555 previous_obj = op;
1556
1560 if (op->head != NULL) 1557 if (op->head != NULL)
1561 op = op->head; 1558 op = op->head;
1562 1559
1563 /* If the map isn't in memory, free_object will remove and 1560 /* If the map isn't in memory, free_object will remove and
1564 * free objects in op's inventory. So let it do the job. 1561 * free objects in op's inventory. So let it do the job.
1565 */ 1562 */
1566 if (m->in_memory == MAP_IN_MEMORY) 1563 if (m->in_memory == MAP_IN_MEMORY)
1567 clean_object (op); 1564 clean_object (op);
1568 remove_ob (op); 1565
1569 free_object (op); 1566 op->destroy ();
1570 } 1567 }
1571 } 1568 }
1572} 1569}
1573 1570
1574/* 1571/*
1575 * Frees everything allocated by the given mapstructure. 1572 * Frees everything allocated by the given maptileure.
1576 * don't free tmpname - our caller is left to do that 1573 * don't free tmpname - our caller is left to do that
1577 */ 1574 */
1578 1575
1579void 1576void
1580free_map (mapstruct *m, int flag) 1577free_map (maptile *m, int flag)
1581{ 1578{
1582 int i; 1579 int i;
1583 1580
1584 if (!m->in_memory) 1581 if (!m->in_memory)
1585 { 1582 {
1612 } 1609 }
1613 m->in_memory = MAP_SWAPPED; 1610 m->in_memory = MAP_SWAPPED;
1614} 1611}
1615 1612
1616/* 1613/*
1617 * function: vanish mapstruct 1614 * function: vanish maptile
1618 * m : pointer to mapstruct, if NULL no action 1615 * m : pointer to maptile, if NULL no action
1619 * this deletes all the data on the map (freeing pointers) 1616 * this deletes all the data on the map (freeing pointers)
1620 * and then removes this map from the global linked list of maps. 1617 * and then removes this map from the global linked list of maps.
1621 */ 1618 */
1622 1619
1623void 1620void
1624delete_map (mapstruct *m) 1621delete_map (maptile *m)
1625{ 1622{
1626 mapstruct *tmp, *last; 1623 maptile *tmp, *last;
1627 int i; 1624 int i;
1628 1625
1629 if (!m) 1626 if (!m)
1630 return; 1627 return;
1631 1628
1693 * dont do any more name translation on it. 1690 * dont do any more name translation on it.
1694 * 1691 *
1695 * Returns a pointer to the given map. 1692 * Returns a pointer to the given map.
1696 */ 1693 */
1697 1694
1698mapstruct * 1695maptile *
1699ready_map_name (const char *name, int flags) 1696ready_map_name (const char *name, int flags)
1700{ 1697{
1701 mapstruct *m; 1698 maptile *m;
1702 1699
1703 if (!name) 1700 if (!name)
1704 return (NULL); 1701 return (NULL);
1705 1702
1706 /* Have we been at this level before? */ 1703 /* Have we been at this level before? */
1808 * have a difficulty set than using this function - human calculation 1805 * have a difficulty set than using this function - human calculation
1809 * is much better than this functions guesswork. 1806 * is much better than this functions guesswork.
1810 */ 1807 */
1811 1808
1812int 1809int
1813calculate_difficulty (mapstruct *m) 1810calculate_difficulty (maptile *m)
1814{ 1811{
1815 object *op; 1812 object *op;
1816 archetype *at; 1813 archetype *at;
1817 int x, y, i; 1814 int x, y, i;
1818 long monster_cnt = 0; 1815 long monster_cnt = 0;
1860 1857
1861 return 1; 1858 return 1;
1862} 1859}
1863 1860
1864void 1861void
1865clean_tmp_map (mapstruct *m) 1862clean_tmp_map (maptile *m)
1866{ 1863{
1867 if (m->tmpname == NULL) 1864 if (m->tmpname == NULL)
1868 return; 1865 return;
1869 INVOKE_MAP (CLEAN, m); 1866 INVOKE_MAP (CLEAN, m);
1870 (void) unlink (m->tmpname); 1867 (void) unlink (m->tmpname);
1895 * to maps than los. 1892 * to maps than los.
1896 * postive values make it darker, negative make it brighter 1893 * postive values make it darker, negative make it brighter
1897 */ 1894 */
1898 1895
1899int 1896int
1900change_map_light (mapstruct *m, int change) 1897change_map_light (maptile *m, int change)
1901{ 1898{
1902 int new_level = m->darkness + change; 1899 int new_level = m->darkness + change;
1903 1900
1904 /* Nothing to do */ 1901 /* Nothing to do */
1905 if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) 1902 if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS))
1936 * on the map (what it looks like, whether it blocks magic, 1933 * on the map (what it looks like, whether it blocks magic,
1937 * has a living creatures, prevents people from passing 1934 * has a living creatures, prevents people from passing
1938 * through, etc) 1935 * through, etc)
1939 */ 1936 */
1940void 1937void
1941update_position (mapstruct *m, int x, int y) 1938update_position (maptile *m, int x, int y)
1942{ 1939{
1943 object *tmp, *last = NULL; 1940 object *tmp, *last = NULL;
1944 uint8 flags = 0, oldflags, light = 0, anywhere = 0; 1941 uint8 flags = 0, oldflags, light = 0, anywhere = 0;
1945 New_Face *top, *floor, *middle; 1942 New_Face *top, *floor, *middle;
1946 object *top_obj, *floor_obj, *middle_obj; 1943 object *top_obj, *floor_obj, *middle_obj;
2139 SET_MAP_LIGHT (m, x, y, light); 2136 SET_MAP_LIGHT (m, x, y, light);
2140} 2137}
2141 2138
2142 2139
2143void 2140void
2144set_map_reset_time (mapstruct *map) 2141set_map_reset_time (maptile *map)
2145{ 2142{
2146 int timeout; 2143 int timeout;
2147 2144
2148 timeout = MAP_RESET_TIMEOUT (map); 2145 timeout = MAP_RESET_TIMEOUT (map);
2149 if (timeout <= 0) 2146 if (timeout <= 0)
2158 * maps tile_map values if it tiles back to this one. It returns 2155 * maps tile_map values if it tiles back to this one. It returns
2159 * the value of orig_map->tile_map[tile_num]. It really only does this 2156 * the value of orig_map->tile_map[tile_num]. It really only does this
2160 * so that it is easier for calling functions to verify success. 2157 * so that it is easier for calling functions to verify success.
2161 */ 2158 */
2162 2159
2163static mapstruct * 2160static maptile *
2164load_and_link_tiled_map (mapstruct *orig_map, int tile_num) 2161load_and_link_tiled_map (maptile *orig_map, int tile_num)
2165{ 2162{
2166 int dest_tile = (tile_num + 2) % 4; 2163 int dest_tile = (tile_num + 2) % 4;
2167 char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); 2164 char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]);
2168 2165
2169 orig_map->tile_map[tile_num] = ready_map_name (path, 0); 2166 orig_map->tile_map[tile_num] = ready_map_name (path, 0);
2184 * tiled maps. 2181 * tiled maps.
2185 * 2182 *
2186 * 2183 *
2187 */ 2184 */
2188int 2185int
2189out_of_map (mapstruct *m, int x, int y) 2186out_of_map (maptile *m, int x, int y)
2190{ 2187{
2191 2188
2192 /* If we get passed a null map, this is obviously the 2189 /* If we get passed a null map, this is obviously the
2193 * case. This generally shouldn't happen, but if the 2190 * case. This generally shouldn't happen, but if the
2194 * map loads fail below, it could happen. 2191 * map loads fail below, it could happen.
2249 * the map as that the coordinates are really on, and 2246 * the map as that the coordinates are really on, and
2250 * updates x and y to be the localized coordinates. 2247 * updates x and y to be the localized coordinates.
2251 * Using this is more efficient of calling out_of_map 2248 * Using this is more efficient of calling out_of_map
2252 * and then figuring out what the real map is 2249 * and then figuring out what the real map is
2253 */ 2250 */
2254mapstruct * 2251maptile *
2255get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) 2252get_map_from_coord (maptile *m, sint16 * x, sint16 * y)
2256{ 2253{
2257 2254
2258 if (*x < 0) 2255 if (*x < 0)
2259 { 2256 {
2260 if (!m->tile_path[3]) 2257 if (!m->tile_path[3])
2306/** 2303/**
2307 * Return whether map2 is adjacent to map1. If so, store the distance from 2304 * Return whether map2 is adjacent to map1. If so, store the distance from
2308 * map1 to map2 in dx/dy. 2305 * map1 to map2 in dx/dy.
2309 */ 2306 */
2310static int 2307static int
2311adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) 2308adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy)
2312{ 2309{
2313 if (!map1 || !map2) 2310 if (!map1 || !map2)
2314 return 0; 2311 return 0;
2315 2312
2316 if (map1 == map2) 2313 if (map1 == map2)
2474 * for something in the future. Also, since no object is pasted, the best 2471 * for something in the future. Also, since no object is pasted, the best
2475 * field of the rv_vector is set to NULL. 2472 * field of the rv_vector is set to NULL.
2476 */ 2473 */
2477 2474
2478void 2475void
2479get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) 2476get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags)
2480{ 2477{
2481 if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) 2478 if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y))
2482 { 2479 {
2483 /* be conservative and fill in _some_ data */ 2480 /* be conservative and fill in _some_ data */
2484 retval->distance = 100000; 2481 retval->distance = 100000;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines