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.29 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.40 by root, Tue Dec 12 21:39:56 2006 UTC

1
2/*
3 * static char *rcsid_map_c =
4 * "$Id: map.C,v 1.29 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30 24
31#include <global.h> 25#include <global.h>
32#include <funcpoint.h> 26#include <funcpoint.h>
33 27
34#include <loader.h> 28#include <loader.h>
35#ifndef WIN32 /* ---win32 exclude header */
36# include <unistd.h> 29#include <unistd.h>
37#endif /* win32 */
38 30
39#include "path.h" 31#include "path.h"
40 32
41 33
42extern int nrofallocobjects, nroffreeobjects;
43
44/* 34/*
45 * Returns the mapstruct which has a name matching the given argument. 35 * Returns the maptile which has a name matching the given argument.
46 * return NULL if no match is found. 36 * return NULL if no match is found.
47 */ 37 */
48 38
49mapstruct * 39maptile *
50has_been_loaded (const char *name) 40has_been_loaded (const char *name)
51{ 41{
52 mapstruct *map; 42 maptile *map;
53 43
54 if (!name || !*name) 44 if (!name || !*name)
55 return 0; 45 return 0;
56 for (map = first_map; map; map = map->next) 46 for (map = first_map; map; map = map->next)
57 if (!strcmp (name, map->path)) 47 if (!strcmp (name, map->path))
165int 155int
166check_path (const char *name, int prepend_dir) 156check_path (const char *name, int prepend_dir)
167{ 157{
168 char buf[MAX_BUF]; 158 char buf[MAX_BUF];
169 159
170#ifndef WIN32
171 char *endbuf; 160 char *endbuf;
172 struct stat statbuf; 161 struct stat statbuf;
173 int mode = 0; 162 int mode = 0;
174#endif
175 163
176 if (prepend_dir) 164 if (prepend_dir)
177 strcpy (buf, create_pathname (name)); 165 strcpy (buf, create_pathname (name));
178 else 166 else
179 strcpy (buf, name); 167 strcpy (buf, name);
180#ifdef WIN32 /* ***win32: check this sucker in windows style. */
181 return (_access (buf, 0));
182#else
183 168
184 /* old method (strchr(buf, '\0')) seemd very odd to me - 169 /* old method (strchr(buf, '\0')) seemd very odd to me -
185 * this method should be equivalant and is clearer. 170 * this method should be equivalant and is clearer.
186 * Can not use strcat because we need to cycle through 171 * Can not use strcat because we need to cycle through
187 * all the names. 172 * all the names.
200 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 185 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
201 (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))
202 mode |= 2; 187 mode |= 2;
203 188
204 return (mode); 189 return (mode);
205#endif
206} 190}
207 191
208/* 192/*
209 * Prints out debug-information about a map. 193 * Prints out debug-information about a map.
210 * Dumping these at llevError doesn't seem right, but is 194 * Dumping these at llevError doesn't seem right, but is
211 * necessary to make sure the information is in fact logged. 195 * necessary to make sure the information is in fact logged.
212 */ 196 */
213 197
214void 198void
215dump_map (const mapstruct *m) 199dump_map (const maptile *m)
216{ 200{
217 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);
218 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));
219 203
220 if (m->msg != NULL) 204 if (m->msg != NULL)
237 */ 221 */
238 222
239void 223void
240dump_all_maps (void) 224dump_all_maps (void)
241{ 225{
242 mapstruct *m; 226 maptile *m;
243 227
244 for (m = first_map; m != NULL; m = m->next) 228 for (m = first_map; m != NULL; m = m->next)
245 { 229 {
246 dump_map (m); 230 dump_map (m);
247 } 231 }
256 * 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
257 * checking for the existence of something on those spaces, but 241 * checking for the existence of something on those spaces, but
258 * don't expect to insert/remove anything from those spaces. 242 * don't expect to insert/remove anything from those spaces.
259 */ 243 */
260int 244int
261get_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)
262{ 246{
263 sint16 newx, newy; 247 sint16 newx, newy;
264 int retval = 0; 248 int retval = 0;
265 mapstruct *mp; 249 maptile *mp;
266 250
267 if (out_of_map (oldmap, x, y)) 251 if (out_of_map (oldmap, x, y))
268 return P_OUT_OF_MAP; 252 return P_OUT_OF_MAP;
269 newx = x; 253 newx = x;
270 newy = y; 254 newy = y;
281 retval |= mp->spaces[newx + mp->width * newy].flags; 265 retval |= mp->spaces[newx + mp->width * newy].flags;
282 266
283 return retval; 267 return retval;
284} 268}
285 269
286
287/* 270/*
288 * Returns true if the given coordinate is blocked except by the 271 * Returns true if the given coordinate is blocked except by the
289 * object passed is not blocking. This is used with 272 * object passed is not blocking. This is used with
290 * multipart monsters - if we want to see if a 2x2 monster 273 * multipart monsters - if we want to see if a 2x2 monster
291 * 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
294 * monster. 277 * monster.
295 * 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.
296 * the coordinates & map passed in should have been updated for tiling 279 * the coordinates & map passed in should have been updated for tiling
297 * by the caller. 280 * by the caller.
298 */ 281 */
299
300int 282int
301blocked_link (object *ob, mapstruct *m, int sx, int sy) 283blocked_link (object *ob, maptile *m, int sx, int sy)
302{ 284{
303 object *tmp; 285 object *tmp;
304 int mflags, blocked; 286 int mflags, blocked;
305 287
306 /* 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
418 * 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
419 * against the move_block values. 401 * against the move_block values.
420 */ 402 */
421 403
422int 404int
423ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) 405ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
424{ 406{
425 archetype *tmp; 407 archetype *tmp;
426 int flag; 408 int flag;
427 mapstruct *m1; 409 maptile *m1;
428 sint16 sx, sy; 410 sint16 sx, sy;
429 411
430 if (ob == NULL) 412 if (ob == NULL)
431 { 413 {
432 flag = get_map_flags (m, &m1, x, y, &sx, &sy); 414 flag = get_map_flags (m, &m1, x, y, &sx, &sy);
497 * 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
498 * the more sections and not re-add sections for them. 480 * the more sections and not re-add sections for them.
499 */ 481 */
500 482
501static void 483static void
502link_multipart_objects (mapstruct *m) 484link_multipart_objects (maptile *m)
503{ 485{
504 int x, y; 486 int x, y;
505 object *tmp, *op, *last, *above; 487 object *tmp, *op, *last, *above;
506 archetype *at; 488 archetype *at;
507 489
544 * 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
545 * file pointer. 527 * file pointer.
546 * mapflags is the same as we get with load_original_map 528 * mapflags is the same as we get with load_original_map
547 */ 529 */
548void 530void
549load_objects (mapstruct *m, object_thawer & fp, int mapflags) 531load_objects (maptile *m, object_thawer & fp, int mapflags)
550{ 532{
551 int i, j; 533 int i, j;
552 int unique; 534 int unique;
553 object *op, *prev = NULL, *last_more = NULL, *otmp; 535 object *op, *prev = NULL, *last_more = NULL, *otmp;
554 536
555 op = get_object (); 537 op = object::create ();
556 op->map = m; /* To handle buttons correctly */ 538 op->map = m; /* To handle buttons correctly */
557 539
558 while ((i = load_object (fp, op, mapflags))) 540 while ((i = load_object (fp, op, mapflags)))
559 { 541 {
560 /* if the archetype for the object is null, means that we 542 /* if the archetype for the object is null, means that we
590 } 572 }
591 573
592 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
593 remove_from_active_list (op); 575 remove_from_active_list (op);
594 576
595 op = get_object (); 577 op = object::create ();
596 op->map = m; 578 op->map = m;
597 } 579 }
598 580
599 for (i = 0; i < m->width; i++) 581 for (i = 0; i < m->width; i++)
600 { 582 {
610 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 592 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
611 } 593 }
612 } 594 }
613 } 595 }
614 596
615 free_object (op); 597 op->destroy ();
616 link_multipart_objects (m); 598 link_multipart_objects (m);
617} 599}
618 600
619/* 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.
620 * 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,
621 * 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
622 * in order to do map tiling properly. 604 * in order to do map tiling properly.
623 */ 605 */
624void 606void
625save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) 607save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag)
626{ 608{
627 int i, j = 0, unique = 0; 609 int i, j = 0, unique = 0;
628 object *op; 610 object *op;
629 611
630 /* first pass - save one-part objects */ 612 /* first pass - save one-part objects */
653 635
654 } /* for this space */ 636 } /* for this space */
655 } /* for this j */ 637 } /* for this j */
656} 638}
657 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
658/* 657/*
659 * Allocates, initialises, and returns a pointer to a mapstruct. 658 * Allocates, initialises, and returns a pointer to a maptile.
660 * 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
661 * used anyways. MSW 2001-07-01 660 * used anyways. MSW 2001-07-01
662 */ 661 */
663 662maptile *
664mapstruct *
665get_linked_map (void) 663get_linked_map (void)
666{ 664{
667 mapstruct *map = new mapstruct; 665 maptile *mp, *map = new maptile;
668 mapstruct *mp;
669 666
670 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 667 for (mp = first_map; mp && mp->next; mp = mp->next);
668
671 if (mp == NULL) 669 if (mp == NULL)
672 first_map = map; 670 first_map = map;
673 else 671 else
674 mp->next = map; 672 mp->next = map;
675 673
676 map->in_memory = MAP_SWAPPED;
677 /* The maps used to pick up default x and y values from the
678 * map archetype. Mimic that behaviour.
679 */
680 MAP_WIDTH (map) = 16;
681 MAP_HEIGHT (map) = 16;
682 MAP_RESET_TIMEOUT (map) = 0;
683 MAP_TIMEOUT (map) = 300;
684 MAP_ENTER_X (map) = 0;
685 MAP_ENTER_Y (map) = 0;
686 /*set part to -1 indicating conversion to weather map not yet done */
687 MAP_WORLDPARTX (map) = -1;
688 MAP_WORLDPARTY (map) = -1;
689 return map; 674 return map;
690} 675}
691 676
692/* 677/*
693 * Allocates the arrays contained in a mapstruct. 678 * Allocates the arrays contained in a maptile.
694 * This basically allocates the dynamic array of spaces for the 679 * This basically allocates the dynamic array of spaces for the
695 * map. 680 * map.
696 */ 681 */
697
698void 682void
699allocate_map (mapstruct *m) 683maptile::allocate ()
700{ 684{
701 m->in_memory = MAP_IN_MEMORY; 685 in_memory = MAP_IN_MEMORY;
686
702 /* Log this condition and free the storage. We could I suppose 687 /* Log this condition and free the storage. We could I suppose
703 * 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,
704 * that is their poor assumption. 689 * that is their poor assumption.
705 */ 690 */
706 if (m->spaces) 691 if (spaces)
707 { 692 {
708 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);
709 free (m->spaces); 694 free (spaces);
710 } 695 }
711 696
712 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 697 spaces = (MapSpace *)
698 calloc (1, width * height * sizeof (MapSpace));
713 699
714 if (m->spaces == NULL) 700 if (!spaces)
715 fatal (OUT_OF_MEMORY); 701 fatal (OUT_OF_MEMORY);
716} 702}
717 703
718/* Create and returns a map of the specific size. Used 704/* Create and returns a map of the specific size. Used
719 * in random map code and the editor. 705 * in random map code and the editor.
720 */ 706 */
721mapstruct * 707maptile *
722get_empty_map (int sizex, int sizey) 708get_empty_map (int sizex, int sizey)
723{ 709{
724 mapstruct *m = get_linked_map (); 710 maptile *m = get_linked_map ();
725 711
726 m->width = sizex; 712 m->width = sizex;
727 m->height = sizey; 713 m->height = sizey;
728 m->in_memory = MAP_SWAPPED; 714 m->in_memory = MAP_SWAPPED;
729 allocate_map (m); 715 m->allocate ();
716
730 return m; 717 return m;
731} 718}
732 719
733/* 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
734 * 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
811} 798}
812 799
813/* 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
814 * the map (or something equivilent) into output_string. */ 801 * the map (or something equivilent) into output_string. */
815static void 802static void
816print_shop_string (mapstruct *m, char *output_string) 803print_shop_string (maptile *m, char *output_string)
817{ 804{
818 int i; 805 int i;
819 char tmp[MAX_BUF]; 806 char tmp[MAX_BUF];
820 807
821 strcpy (output_string, ""); 808 strcpy (output_string, "");
855 * MSW 2001-07-01 842 * MSW 2001-07-01
856 * return 0 on success, 1 on failure. 843 * return 0 on success, 1 on failure.
857 */ 844 */
858 845
859static int 846static int
860load_map_header (object_thawer & fp, mapstruct *m) 847load_map_header (object_thawer & fp, maptile *m)
861{ 848{
862 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;
863 int msgpos = 0; 850 int msgpos = 0;
864 int maplorepos = 0; 851 int maplorepos = 0;
865 852
866 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 853 while (fgets (buf, HUGE_BUF, fp) != NULL)
867 { 854 {
868 buf[HUGE_BUF - 1] = 0; 855 buf[HUGE_BUF - 1] = 0;
869 key = buf; 856 key = buf;
857
870 while (isspace (*key)) 858 while (isspace (*key))
871 key++; 859 key++;
860
872 if (*key == 0) 861 if (*key == 0)
873 continue; /* empty line */ 862 continue; /* empty line */
863
874 value = strchr (key, ' '); 864 value = strchr (key, ' ');
865
875 if (!value) 866 if (!value)
876 { 867 {
877 end = strchr (key, '\n'); 868 if ((end = strchr (key, '\n')))
878 if (end != NULL)
879 {
880 *end = 0; 869 *end = 0;
881 }
882 } 870 }
883 else 871 else
884 { 872 {
885 *value = 0; 873 *value = 0;
886 value++; 874 value++;
887 end = strchr (value, '\n'); 875 end = strchr (value, '\n');
876
888 while (isspace (*value)) 877 while (isspace (*value))
889 { 878 {
890 value++; 879 value++;
880
891 if (*value == '\0' || value == end) 881 if (*value == '\0' || value == end)
892 { 882 {
893 /* Nothing but spaces. */ 883 /* Nothing but spaces. */
894 value = NULL; 884 value = NULL;
895 break; 885 break;
918 * that use the parameter. 908 * that use the parameter.
919 */ 909 */
920 910
921 if (!strcmp (key, "msg")) 911 if (!strcmp (key, "msg"))
922 { 912 {
923 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 913 while (fgets (buf, HUGE_BUF, fp) != NULL)
924 { 914 {
925 if (!strcmp (buf, "endmsg\n")) 915 if (!strcmp (buf, "endmsg\n"))
926 break; 916 break;
927 else 917 else
928 { 918 {
939 if (msgpos != 0) 929 if (msgpos != 0)
940 m->msg = strdup_local (msgbuf); 930 m->msg = strdup_local (msgbuf);
941 } 931 }
942 else if (!strcmp (key, "maplore")) 932 else if (!strcmp (key, "maplore"))
943 { 933 {
944 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 934 while (fgets (buf, HUGE_BUF, fp) != NULL)
945 { 935 {
946 if (!strcmp (buf, "endmaplore\n")) 936 if (!strcmp (buf, "endmaplore\n"))
947 break; 937 break;
948 else 938 else
949 { 939 {
1153} 1143}
1154 1144
1155/* 1145/*
1156 * Opens the file "filename" and reads information about the map 1146 * Opens the file "filename" and reads information about the map
1157 * from the given file, and stores it in a newly allocated 1147 * from the given file, and stores it in a newly allocated
1158 * 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.
1159 * flags correspond to those in map.h. Main ones used are 1149 * flags correspond to those in map.h. Main ones used are
1160 * 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
1161 * 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
1162 * cases, no matter if this flag is set or not. 1152 * cases, no matter if this flag is set or not.
1163 * 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
1164 * managed map list. 1154 * managed map list.
1165 */ 1155 */
1166 1156
1167mapstruct * 1157maptile *
1168load_original_map (const char *filename, int flags) 1158load_original_map (const char *filename, int flags)
1169{ 1159{
1170 mapstruct *m; 1160 maptile *m;
1171 char pathname[MAX_BUF]; 1161 char pathname[MAX_BUF];
1172 1162
1173 if (flags & MAP_PLAYER_UNIQUE) 1163 if (flags & MAP_PLAYER_UNIQUE)
1174 strcpy (pathname, filename); 1164 strcpy (pathname, filename);
1175 else if (flags & MAP_OVERLAY) 1165 else if (flags & MAP_OVERLAY)
1192 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);
1193 delete_map (m); 1183 delete_map (m);
1194 return NULL; 1184 return NULL;
1195 } 1185 }
1196 1186
1197 allocate_map (m); 1187 m->allocate ();
1198 1188
1199 m->in_memory = MAP_LOADING; 1189 m->in_memory = MAP_LOADING;
1200 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1190 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1201 1191
1202 m->in_memory = MAP_IN_MEMORY; 1192 m->in_memory = MAP_IN_MEMORY;
1211 * Loads a map, which has been loaded earlier, from file. 1201 * Loads a map, which has been loaded earlier, from file.
1212 * 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
1213 * option if we can't find the original map) 1203 * option if we can't find the original map)
1214 */ 1204 */
1215 1205
1216static mapstruct * 1206static maptile *
1217load_temporary_map (mapstruct *m) 1207load_temporary_map (maptile *m)
1218{ 1208{
1219 char buf[MAX_BUF]; 1209 char buf[MAX_BUF];
1220 1210
1221 if (!m->tmpname) 1211 if (!m->tmpname)
1222 { 1212 {
1248 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);
1249 delete_map (m); 1239 delete_map (m);
1250 m = load_original_map (m->path, 0); 1240 m = load_original_map (m->path, 0);
1251 return NULL; 1241 return NULL;
1252 } 1242 }
1243
1253 allocate_map (m); 1244 m->allocate ();
1254 1245
1255 m->in_memory = MAP_LOADING; 1246 m->in_memory = MAP_LOADING;
1256 load_objects (m, thawer, 0); 1247 load_objects (m, thawer, 0);
1257 1248
1258 m->in_memory = MAP_IN_MEMORY; 1249 m->in_memory = MAP_IN_MEMORY;
1264 * Loads a map, which has been loaded earlier, from file. 1255 * Loads a map, which has been loaded earlier, from file.
1265 * 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
1266 * option if we can't find the original map) 1257 * option if we can't find the original map)
1267 */ 1258 */
1268 1259
1269mapstruct * 1260maptile *
1270load_overlay_map (const char *filename, mapstruct *m) 1261load_overlay_map (const char *filename, maptile *m)
1271{ 1262{
1272 char pathname[MAX_BUF]; 1263 char pathname[MAX_BUF];
1273 1264
1274 strcpy (pathname, create_overlay_pathname (filename)); 1265 strcpy (pathname, create_overlay_pathname (filename));
1275 1266
1283 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);
1284 delete_map (m); 1275 delete_map (m);
1285 m = load_original_map (m->path, 0); 1276 m = load_original_map (m->path, 0);
1286 return NULL; 1277 return NULL;
1287 } 1278 }
1288 /*allocate_map(m); */ 1279 /*m->allocate ();*/
1289 1280
1290 m->in_memory = MAP_LOADING; 1281 m->in_memory = MAP_LOADING;
1291 load_objects (m, thawer, MAP_OVERLAY); 1282 load_objects (m, thawer, MAP_OVERLAY);
1292 1283
1293 m->in_memory = MAP_IN_MEMORY; 1284 m->in_memory = MAP_IN_MEMORY;
1298 * This is the start of unique map handling code 1289 * This is the start of unique map handling code
1299 *****************************************************************************/ 1290 *****************************************************************************/
1300 1291
1301/* 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. */
1302static void 1293static void
1303delete_unique_items (mapstruct *m) 1294delete_unique_items (maptile *m)
1304{ 1295{
1305 int i, j, unique; 1296 int i, j, unique;
1306 object *op, *next; 1297 object *op, *next;
1307 1298
1308 for (i = 0; i < MAP_WIDTH (m); i++) 1299 for (i = 0; i < MAP_WIDTH (m); i++)
1309 for (j = 0; j < MAP_HEIGHT (m); j++) 1300 for (j = 0; j < MAP_HEIGHT (m); j++)
1310 { 1301 {
1311 unique = 0; 1302 unique = 0;
1303
1312 for (op = get_map_ob (m, i, j); op; op = next) 1304 for (op = get_map_ob (m, i, j); op; op = next)
1313 { 1305 {
1314 next = op->above; 1306 next = op->above;
1307
1315 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))
1316 unique = 1; 1309 unique = 1;
1310
1317 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1311 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1318 { 1312 {
1319 clean_object (op); 1313 clean_object (op);
1314
1320 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1315 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1321 remove_button_link (op); 1316 remove_button_link (op);
1322 remove_ob (op); 1317
1323 free_object (op); 1318 op->destroy ();
1324 } 1319 }
1325 } 1320 }
1326 } 1321 }
1327} 1322}
1328 1323
1330/* 1325/*
1331 * 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
1332 * m is the map to load unique items into. 1327 * m is the map to load unique items into.
1333 */ 1328 */
1334static void 1329static void
1335load_unique_objects (mapstruct *m) 1330load_unique_objects (maptile *m)
1336{ 1331{
1337 int count; 1332 int count;
1338 char firstname[MAX_BUF]; 1333 char firstname[MAX_BUF];
1339 1334
1340 for (count = 0; count < 10; count++) 1335 for (count = 0; count < 10; count++)
1363 1358
1364/* 1359/*
1365 * 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
1366 * file it was (originally) loaded from. Otherwise a temporary 1361 * file it was (originally) loaded from. Otherwise a temporary
1367 * filename will be genarated, and the file will be stored there. 1362 * filename will be genarated, and the file will be stored there.
1368 * The temporary filename will be stored in the mapstructure. 1363 * The temporary filename will be stored in the maptileure.
1369 * 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
1370 * (this should have been updated when first loaded) 1365 * (this should have been updated when first loaded)
1371 */ 1366 */
1372 1367
1373int 1368int
1374new_save_map (mapstruct *m, int flag) 1369new_save_map (maptile *m, int flag)
1375{ 1370{
1376 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1371 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1377 int i; 1372 int i;
1378 1373
1379 if (flag && !*m->path) 1374 if (flag && !*m->path)
1431 print_shop_string (m, shop); 1426 print_shop_string (m, shop);
1432 fprintf (freezer, "shopitems %s\n", shop); 1427 fprintf (freezer, "shopitems %s\n", shop);
1433 } 1428 }
1434 if (m->shopgreed) 1429 if (m->shopgreed)
1435 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1430 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1436#ifndef WIN32
1437 if (m->shopmin) 1431 if (m->shopmin)
1438 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1432 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1439 if (m->shopmax) 1433 if (m->shopmax)
1440 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1434 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1441#else
1442 if (m->shopmin)
1443 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1444 if (m->shopmax)
1445 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1446#endif
1447 if (m->shoprace) 1435 if (m->shoprace)
1448 fprintf (freezer, "shoprace %s\n", m->shoprace); 1436 fprintf (freezer, "shoprace %s\n", m->shoprace);
1449 if (m->darkness) 1437 if (m->darkness)
1450 fprintf (freezer, "darkness %d\n", m->darkness); 1438 fprintf (freezer, "darkness %d\n", m->darkness);
1451 if (m->width) 1439 if (m->width)
1530 object *tmp, *next; 1518 object *tmp, *next;
1531 1519
1532 for (tmp = op->inv; tmp; tmp = next) 1520 for (tmp = op->inv; tmp; tmp = next)
1533 { 1521 {
1534 next = tmp->below; 1522 next = tmp->below;
1523
1535 clean_object (tmp); 1524 clean_object (tmp);
1536 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1525 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1537 remove_button_link (tmp); 1526 remove_button_link (tmp);
1538 remove_ob (tmp); 1527
1539 free_object (tmp); 1528 tmp->destroy ();
1540 } 1529 }
1541} 1530}
1542 1531
1543/* 1532/*
1544 * Remove and free all objects in the given map. 1533 * Remove and free all objects in the given map.
1545 */ 1534 */
1546 1535
1547void 1536void
1548free_all_objects (mapstruct *m) 1537free_all_objects (maptile *m)
1549{ 1538{
1550 int i, j; 1539 int i, j;
1551 object *op; 1540 object *op;
1552 1541
1553 for (i = 0; i < MAP_WIDTH (m); i++) 1542 for (i = 0; i < MAP_WIDTH (m); i++)
1560 if (op == previous_obj) 1549 if (op == previous_obj)
1561 { 1550 {
1562 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1551 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1563 break; 1552 break;
1564 } 1553 }
1554
1565 previous_obj = op; 1555 previous_obj = op;
1556
1566 if (op->head != NULL) 1557 if (op->head != NULL)
1567 op = op->head; 1558 op = op->head;
1568 1559
1569 /* 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
1570 * 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.
1571 */ 1562 */
1572 if (m->in_memory == MAP_IN_MEMORY) 1563 if (m->in_memory == MAP_IN_MEMORY)
1573 clean_object (op); 1564 clean_object (op);
1574 remove_ob (op); 1565
1575 free_object (op); 1566 op->destroy ();
1576 } 1567 }
1577 } 1568 }
1578} 1569}
1579 1570
1580/* 1571/*
1581 * Frees everything allocated by the given mapstructure. 1572 * Frees everything allocated by the given maptileure.
1582 * don't free tmpname - our caller is left to do that 1573 * don't free tmpname - our caller is left to do that
1583 */ 1574 */
1584 1575
1585void 1576void
1586free_map (mapstruct *m, int flag) 1577free_map (maptile *m, int flag)
1587{ 1578{
1588 int i; 1579 int i;
1589 1580
1590 if (!m->in_memory) 1581 if (!m->in_memory)
1591 { 1582 {
1618 } 1609 }
1619 m->in_memory = MAP_SWAPPED; 1610 m->in_memory = MAP_SWAPPED;
1620} 1611}
1621 1612
1622/* 1613/*
1623 * function: vanish mapstruct 1614 * function: vanish maptile
1624 * m : pointer to mapstruct, if NULL no action 1615 * m : pointer to maptile, if NULL no action
1625 * this deletes all the data on the map (freeing pointers) 1616 * this deletes all the data on the map (freeing pointers)
1626 * 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.
1627 */ 1618 */
1628 1619
1629void 1620void
1630delete_map (mapstruct *m) 1621delete_map (maptile *m)
1631{ 1622{
1632 mapstruct *tmp, *last; 1623 maptile *tmp, *last;
1633 int i; 1624 int i;
1634 1625
1635 if (!m) 1626 if (!m)
1636 return; 1627 return;
1637 1628
1699 * dont do any more name translation on it. 1690 * dont do any more name translation on it.
1700 * 1691 *
1701 * Returns a pointer to the given map. 1692 * Returns a pointer to the given map.
1702 */ 1693 */
1703 1694
1704mapstruct * 1695maptile *
1705ready_map_name (const char *name, int flags) 1696ready_map_name (const char *name, int flags)
1706{ 1697{
1707 mapstruct *m; 1698 maptile *m;
1708 1699
1709 if (!name) 1700 if (!name)
1710 return (NULL); 1701 return (NULL);
1711 1702
1712 /* Have we been at this level before? */ 1703 /* Have we been at this level before? */
1814 * have a difficulty set than using this function - human calculation 1805 * have a difficulty set than using this function - human calculation
1815 * is much better than this functions guesswork. 1806 * is much better than this functions guesswork.
1816 */ 1807 */
1817 1808
1818int 1809int
1819calculate_difficulty (mapstruct *m) 1810calculate_difficulty (maptile *m)
1820{ 1811{
1821 object *op; 1812 object *op;
1822 archetype *at; 1813 archetype *at;
1823 int x, y, i; 1814 int x, y, i;
1824 long monster_cnt = 0; 1815 long monster_cnt = 0;
1866 1857
1867 return 1; 1858 return 1;
1868} 1859}
1869 1860
1870void 1861void
1871clean_tmp_map (mapstruct *m) 1862clean_tmp_map (maptile *m)
1872{ 1863{
1873 if (m->tmpname == NULL) 1864 if (m->tmpname == NULL)
1874 return; 1865 return;
1875 INVOKE_MAP (CLEAN, m); 1866 INVOKE_MAP (CLEAN, m);
1876 (void) unlink (m->tmpname); 1867 (void) unlink (m->tmpname);
1901 * to maps than los. 1892 * to maps than los.
1902 * postive values make it darker, negative make it brighter 1893 * postive values make it darker, negative make it brighter
1903 */ 1894 */
1904 1895
1905int 1896int
1906change_map_light (mapstruct *m, int change) 1897change_map_light (maptile *m, int change)
1907{ 1898{
1908 int new_level = m->darkness + change; 1899 int new_level = m->darkness + change;
1909 1900
1910 /* Nothing to do */ 1901 /* Nothing to do */
1911 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))
1942 * on the map (what it looks like, whether it blocks magic, 1933 * on the map (what it looks like, whether it blocks magic,
1943 * has a living creatures, prevents people from passing 1934 * has a living creatures, prevents people from passing
1944 * through, etc) 1935 * through, etc)
1945 */ 1936 */
1946void 1937void
1947update_position (mapstruct *m, int x, int y) 1938update_position (maptile *m, int x, int y)
1948{ 1939{
1949 object *tmp, *last = NULL; 1940 object *tmp, *last = NULL;
1950 uint8 flags = 0, oldflags, light = 0, anywhere = 0; 1941 uint8 flags = 0, oldflags, light = 0, anywhere = 0;
1951 New_Face *top, *floor, *middle; 1942 New_Face *top, *floor, *middle;
1952 object *top_obj, *floor_obj, *middle_obj; 1943 object *top_obj, *floor_obj, *middle_obj;
2145 SET_MAP_LIGHT (m, x, y, light); 2136 SET_MAP_LIGHT (m, x, y, light);
2146} 2137}
2147 2138
2148 2139
2149void 2140void
2150set_map_reset_time (mapstruct *map) 2141set_map_reset_time (maptile *map)
2151{ 2142{
2152 int timeout; 2143 int timeout;
2153 2144
2154 timeout = MAP_RESET_TIMEOUT (map); 2145 timeout = MAP_RESET_TIMEOUT (map);
2155 if (timeout <= 0) 2146 if (timeout <= 0)
2164 * 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
2165 * 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
2166 * so that it is easier for calling functions to verify success. 2157 * so that it is easier for calling functions to verify success.
2167 */ 2158 */
2168 2159
2169static mapstruct * 2160static maptile *
2170load_and_link_tiled_map (mapstruct *orig_map, int tile_num) 2161load_and_link_tiled_map (maptile *orig_map, int tile_num)
2171{ 2162{
2172 int dest_tile = (tile_num + 2) % 4; 2163 int dest_tile = (tile_num + 2) % 4;
2173 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]);
2174 2165
2175 orig_map->tile_map[tile_num] = ready_map_name (path, 0); 2166 orig_map->tile_map[tile_num] = ready_map_name (path, 0);
2190 * tiled maps. 2181 * tiled maps.
2191 * 2182 *
2192 * 2183 *
2193 */ 2184 */
2194int 2185int
2195out_of_map (mapstruct *m, int x, int y) 2186out_of_map (maptile *m, int x, int y)
2196{ 2187{
2197 2188
2198 /* If we get passed a null map, this is obviously the 2189 /* If we get passed a null map, this is obviously the
2199 * case. This generally shouldn't happen, but if the 2190 * case. This generally shouldn't happen, but if the
2200 * map loads fail below, it could happen. 2191 * map loads fail below, it could happen.
2255 * the map as that the coordinates are really on, and 2246 * the map as that the coordinates are really on, and
2256 * updates x and y to be the localized coordinates. 2247 * updates x and y to be the localized coordinates.
2257 * Using this is more efficient of calling out_of_map 2248 * Using this is more efficient of calling out_of_map
2258 * and then figuring out what the real map is 2249 * and then figuring out what the real map is
2259 */ 2250 */
2260mapstruct * 2251maptile *
2261get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) 2252get_map_from_coord (maptile *m, sint16 * x, sint16 * y)
2262{ 2253{
2263 2254
2264 if (*x < 0) 2255 if (*x < 0)
2265 { 2256 {
2266 if (!m->tile_path[3]) 2257 if (!m->tile_path[3])
2312/** 2303/**
2313 * 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
2314 * map1 to map2 in dx/dy. 2305 * map1 to map2 in dx/dy.
2315 */ 2306 */
2316static int 2307static int
2317adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) 2308adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy)
2318{ 2309{
2319 if (!map1 || !map2) 2310 if (!map1 || !map2)
2320 return 0; 2311 return 0;
2321 2312
2322 if (map1 == map2) 2313 if (map1 == map2)
2480 * 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
2481 * field of the rv_vector is set to NULL. 2472 * field of the rv_vector is set to NULL.
2482 */ 2473 */
2483 2474
2484void 2475void
2485get_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)
2486{ 2477{
2487 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))
2488 { 2479 {
2489 /* be conservative and fill in _some_ data */ 2480 /* be conservative and fill in _some_ data */
2490 retval->distance = 100000; 2481 retval->distance = 100000;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines