Crossfire Server, Trunk
map.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <ctype.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/stat.h>
27 #include <math.h>
28 
29 #ifndef WIN32 /* ---win32 exclude header */
30 #include <unistd.h>
31 #endif /* win32 */
32 
33 #include "sproto.h"
34 #include "loader.h"
35 #include "output_file.h"
36 #include "path.h"
37 #include "stats.h"
38 
39 static void free_all_objects(mapstruct *m);
40 
46 const char *const map_layer_name[MAP_LAYERS] = {
47  "floor", "no_pick", "no_pick", "item", "item",
48  "item", "living", "living", "fly", "fly"
49 };
50 
53  uint8_t high_layer;
54  uint8_t honor_visibility;
55 };
56 
64  { MAP_LAYER_FLOOR, 1 },
66  { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 },
67  { MAP_LAYER_LIVING2, 1 }, { MAP_LAYER_LIVING2, 1 },
68  { MAP_LAYER_FLY2, 1 }, { MAP_LAYER_FLY2, 1 }
69 };
70 
80  mapstruct *map;
81 
82  if (!name || !*name)
83  return NULL;
84 
85  for (map = first_map; map; map = map->next)
86  if (!strcmp(name, map->path))
87  break;
88  return (map);
89 }
90 
104 char *create_pathname(const char *name, char *buf, size_t size) {
105  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
106  * someplace else in the code? msw 2-17-97
107  */
108  if (*name == '/')
109  snprintf(buf, size, "%s/%s%s", settings.datadir, settings.mapdir, name);
110  else
111  snprintf(buf, size, "%s/%s/%s", settings.datadir, settings.mapdir, name);
112  return buf;
113 }
114 
125 void create_overlay_pathname(const char *name, char *buf, size_t size) {
126  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
127  * someplace else in the code? msw 2-17-97
128  */
129  if (*name == '/')
130  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.mapdir, name);
131  else
132  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.mapdir, name);
133 }
134 
145 void create_template_pathname(const char *name, char *buf, size_t size) {
146  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
147  * someplace else in the code? msw 2-17-97
148  */
149  if (*name == '/')
150  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.templatedir, name);
151  else
152  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.templatedir, name);
153 }
154 
166 static void create_items_path(const char *s, char *buf, size_t size) {
167  char *t;
168 
169  if (*s == '/')
170  s++;
171 
172  snprintf(buf, size, "%s/%s/", settings.localdir, settings.uniquedir);
173  t = buf+strlen(buf);
174  snprintf(t, buf+size-t, "%s", s);
175 
176  while (*t != '\0') {
177  if (*t == '/')
178  *t = '@';
179  t++;
180  }
181 }
182 
201 int check_path(const char *name, int prepend_dir) {
202  char buf[MAX_BUF];
203 #ifndef WIN32
204  struct stat statbuf;
205  int mode = 0;
206 #endif
207 
208  if (prepend_dir)
210  else
211  strlcpy(buf, name, sizeof(buf));
212 #ifdef WIN32 /* ***win32: check this sucker in windows style. */
213  return(_access(buf, 0));
214 #else
215 
216  if (stat(buf, &statbuf) != 0)
217  return -1;
218 
219  if (!S_ISREG(statbuf.st_mode))
220  return (-1);
221 
222  if (((statbuf.st_mode&S_IRGRP) && getegid() == statbuf.st_gid)
223  || ((statbuf.st_mode&S_IRUSR) && geteuid() == statbuf.st_uid)
224  || (statbuf.st_mode&S_IROTH))
225  mode |= 4;
226 
227  if ((statbuf.st_mode&S_IWGRP && getegid() == statbuf.st_gid)
228  || (statbuf.st_mode&S_IWUSR && geteuid() == statbuf.st_uid)
229  || (statbuf.st_mode&S_IWOTH))
230  mode |= 2;
231 
232  return (mode);
233 #endif
234 }
235 
245 void dump_map(const mapstruct *m) {
246  LOG(llevError, "Map %s status: %d.\n", m->path, m->in_memory);
247  LOG(llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH(m), MAP_HEIGHT(m), MAP_ENTER_X(m), MAP_ENTER_Y(m));
248 
249  if (m->msg != NULL)
250  LOG(llevError, "Message:\n%s", m->msg);
251 
252  if (m->maplore != NULL)
253  LOG(llevError, "Lore:\n%s", m->maplore);
254 
255  if (m->tmpname != NULL)
256  LOG(llevError, "Tmpname: %s\n", m->tmpname);
257 
258  LOG(llevError, "Difficulty: %d\n", m->difficulty);
259  LOG(llevError, "Darkness: %d\n", m->darkness);
260 }
261 
268 void dump_all_maps(void) {
269  mapstruct *m;
270 
271  for (m = first_map; m != NULL; m = m->next) {
272  dump_map(m);
273  }
274 }
275 
300 int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny) {
301  int retval = 0;
302  mapstruct *mp;
303 
304  /*
305  * Since x and y are copies of the original values, we can directly
306  * mess with them here.
307  */
308  mp = get_map_from_coord(oldmap, &x, &y);
309  if (!mp)
310  return P_OUT_OF_MAP;
311  if (mp != oldmap)
312  retval |= P_NEW_MAP;
313  if (newmap)
314  *newmap = mp;
315  if (nx)
316  *nx = x;
317  if (ny)
318  *ny = y;
319  retval |= mp->spaces[x+mp->width*y].flags;
320  return retval;
321 }
322 
344 int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy) {
345  object *tmp_head;
346  int mflags, blocked;
347 
348  /* Make sure the coordinates are valid - they should be, as caller should
349  * have already checked this.
350  */
351  if (OUT_OF_REAL_MAP(m, sx, sy)) {
352  LOG(llevError, "blocked_link: Passed map, x, y coordinates outside of map\n");
353  return 1;
354  }
355 
356  /* special hack for transports: if it's a transport with a move_type of 0, it can do on the space anyway */
357  if (ob->type == TRANSPORT && ob->move_type == 0)
358  return 0;
359 
360  mflags = m->spaces[sx+m->width*sy].flags;
361 
362  blocked = GET_MAP_MOVE_BLOCK(m, sx, sy);
363 
364  /* If space is currently not blocked by anything, no need to
365  * go further. Not true for players - all sorts of special
366  * things we need to do for players.
367  */
368  if (ob->type != PLAYER && !(mflags&P_IS_ALIVE) && (blocked == 0))
369  return 0;
370 
371  /* if there isn't anytyhing alive on this space, and this space isn't
372  * otherwise blocked, we can return now. Only if there is a living
373  * creature do we need to investigate if it is part of this creature
374  * or another. Likewise, only if something is blocking us do we
375  * need to investigate if there is a special circumstance that would
376  * let the player through (inventory checkers for example)
377  */
378  if (!(mflags&P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK(ob, blocked))
379  return 0;
380 
381  ob = HEAD(ob);
382 
383  /* We basically go through the stack of objects, and if there is
384  * some other object that has NO_PASS or FLAG_ALIVE set, return
385  * true. If we get through the entire stack, that must mean
386  * ob is blocking it, so return 0.
387  */
388  FOR_MAP_PREPARE(m, sx, sy, tmp) {
389  /* Never block part of self. */
390  tmp_head = HEAD(tmp);
391  if (tmp_head == ob)
392  continue;
393  /* This must be before the checks below. Code for inventory checkers. */
394  if (tmp->type == CHECK_INV && OB_MOVE_BLOCK(ob, tmp)) {
395  /* If last_sp is set, the player/monster needs an object,
396  * so we check for it. If they don't have it, they can't
397  * pass through this space.
398  */
399  if (tmp->last_sp) {
400  if (check_inv_recursive(ob, tmp) == NULL) {
401  if (tmp->msg) {
402  /* Optionally display the reason why one cannot move
403  * there. Note: emitting a message from this function
404  * is not very elegant. Ideally, this should be done
405  * somewhere in server/player.c, but this is difficult
406  * for objects of type CHECK_INV that are not alive.
407  */
410  tmp->msg);
411  }
412  return 1;
413  }
414  } else {
415  /* In this case, the player must not have the object -
416  * if they do, they can't pass through.
417  */
418  if (check_inv_recursive(ob, tmp) != NULL) {
419  if (tmp->msg) {
422  tmp->msg);
423  }
424  return 1;
425  }
426  }
427  } /* if check_inv */
428  else {
429  /* Broke apart a big nasty if into several here to make
430  * this more readable. first check - if the space blocks
431  * movement, can't move here.
432  * second - if a monster, can't move there, unless it is a
433  * hidden dm
434  */
435  if (OB_MOVE_BLOCK(ob, tmp))
436  return 1;
438  && tmp->head != ob
439  && tmp != ob
440  && tmp->type != DOOR
441  && !(QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden))
442  return 1;
443  }
444  } FOR_MAP_FINISH();
445  return 0;
446 }
447 
479 int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y) {
480  archetype *tmp;
481  int flag;
482  mapstruct *m1;
483  int16_t sx, sy;
484  const object *part;
485 
486  if (ob == NULL) {
487  flag = get_map_flags(m, &m1, x, y, &sx, &sy);
488  if (flag&P_OUT_OF_MAP)
489  return P_OUT_OF_MAP;
490 
491  /* don't have object, so don't know what types would block */
492  return(GET_MAP_MOVE_BLOCK(m1, sx, sy));
493  }
494 
495  for (tmp = ob->arch, part = ob; tmp != NULL; tmp = tmp->more, part = part->more) {
496  flag = get_map_flags(m, &m1, x+tmp->clone.x, y+tmp->clone.y, &sx, &sy);
497 
498  if (flag&P_OUT_OF_MAP)
499  return P_OUT_OF_MAP;
500  if (flag&P_IS_ALIVE)
501  return P_IS_ALIVE;
502 
503  /* object_find_first_free_spot() calls this function. However, often
504  * ob doesn't have any move type (when used to place exits)
505  * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work.
506  */
507 
508  if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK(m1, sx, sy) != MOVE_ALL)
509  continue;
510 
511  /* A transport without move_type for a part should go through everything for that part. */
512  if (ob->type == TRANSPORT && part->move_type == 0)
513  continue;
514 
515  /* Note it is intentional that we check ob - the movement type of the
516  * head of the object should correspond for the entire object.
517  */
518  if (OB_TYPE_MOVE_BLOCK(ob, GET_MAP_MOVE_BLOCK(m1, sx, sy)))
519  return AB_NO_PASS;
520  }
521  return 0;
522 }
523 
534 static void fix_container_multipart(object *container) {
535  FOR_INV_PREPARE(container, tmp) {
536  archetype *at;
537  object *op, *last;
538 
539  if (tmp->inv)
541  /* already multipart, or non-multipart arch - don't do anything more */
542  for (at = tmp->arch->more, last = tmp; at != NULL; at = at->more, last = op) {
543  /* FIXME: We can't reuse object_fix_multipart() since that only
544  * works for items directly on maps. Maybe factor out common code?
545  */
546  op = arch_to_object(at);
547  op->head = tmp;
548  op->env = tmp->env;
549  last->more = op;
550  if (tmp->name != op->name) {
551  if (op->name)
552  free_string(op->name);
553  op->name = add_string(tmp->name);
554  }
555  if (tmp->title != op->title) {
556  if (op->title)
557  free_string(op->title);
558  op->title = add_string(tmp->title);
559  }
561  }
562  } FOR_INV_FINISH();
563 }
564 
576  int x, y;
577 
578  for (x = 0; x < MAP_WIDTH(m); x++)
579  for (y = 0; y < MAP_HEIGHT(m); y++)
580  FOR_MAP_PREPARE(m, x, y, tmp) {
581  if (tmp->inv)
583 
584  /* already multipart - don't do anything more */
585  if (tmp->head || tmp->more)
586  continue;
587 
589  } FOR_MAP_FINISH(); /* for objects on this space */
590 }
591 
603 void load_objects(mapstruct *m, FILE *fp, int mapflags) {
604  int i, j, bufstate = LO_NEWFILE;
605  int unique;
606  object *op, *prev = NULL, *last_more = NULL;
607 
608  op = object_new();
609  op->map = m; /* To handle buttons correctly */
610 
611  PROFILE_BEGIN();
612  while ((i = load_object(fp, op, bufstate, mapflags, false))) {
613  /* Since the loading of the map header does not load an object
614  * anymore, we need to pass LO_NEWFILE for the first object loaded,
615  * and then switch to LO_REPEAT for faster loading.
616  */
617  bufstate = LO_REPEAT;
618 
619  /* if the archetype for the object is null, means that we
620  * got an invalid object. Don't do anything with it - the game
621  * or editor will not be able to do anything with it either.
622  */
623  if (op->arch == NULL) {
624  LOG(llevDebug, "Discarding object without arch: %s\n", op->name ? op->name : "(null)");
625  continue;
626  }
627 
628  /*
629  * You can NOT have players on a map being loaded.
630  * Trying to use such a type leads to crashes everywhere as op->contr is NULL.
631  */
632  if (op->type == PLAYER) {
633  LOG(llevError, "Discarding invalid item with type PLAYER in map %s\n", m->path);
634  continue;
635  }
636 
637  /* don't use out_of_map because we don't want to consider tiling properties, we're loading a single map */
638  if (op->x < 0 || op->y < 0 || op->x >= MAP_WIDTH(m) || op->y >= MAP_HEIGHT(m)) {
639  LOG(llevError, " object %s not on valid map position %s:%d:%d\n", op->name ? op->name : "(null)", m->path, op->x, op->y);
640  if (op->x < 0) {
641  op->x = 0;
642  } else if (op->x >= MAP_WIDTH(m)) {
643  op->x = MAP_WIDTH(m) - 1;
644  }
645  if (op->y < 0) {
646  op->y = 0;
647  } else if (op->y >= MAP_HEIGHT(m)) {
648  op->y = MAP_HEIGHT(m) - 1;
649  }
650  }
651 
652  switch (i) {
653  case LL_NORMAL:
654  /* if we are loading an overlay, put the floors on the bottom */
656  && mapflags&MAP_OVERLAY)
658  else
660 
661  if (op->inv)
663 
664  prev = op,
665  last_more = op;
666  break;
667 
668  case LL_MORE:
670  op->head = prev,
671  last_more->more = op,
672  last_more = op;
673  break;
674  }
675  if (mapflags&MAP_STYLE) {
677  }
678  op = object_new();
679  op->map = m;
680  }
681  PROFILE_END(diff, LOG(llevDebug,
682  "load_objects on %s took %ld us\n", m->path, diff));
683  for (i = 0; i < m->width; i++) {
684  for (j = 0; j < m->height; j++) {
685  unique = 0;
686  /* check for unique items, or unique squares */
687  FOR_MAP_PREPARE(m, i, j, otmp) {
688  if (QUERY_FLAG(otmp, FLAG_UNIQUE))
689  unique = 1;
690  if (!(mapflags&(MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique))
692  } FOR_MAP_FINISH();
693  }
694  }
697 }
698 
715 int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag) {
716  int i, j = 0, unique = 0;
717  unsigned int count = 0;
718 
721 
722  long serialize_time, write_time;
723 
724  PROFILE_BEGIN();
725 
726  for (i = 0; i < MAP_WIDTH(m); i++) {
727  for (j = 0; j < MAP_HEIGHT(m); j++) {
728  unique = 0;
729  FOR_MAP_PREPARE(m, i, j, op) {
731  unique = 1;
732 
733  if (op->type == PLAYER) {
734  LOG(llevDebug, "Player on map that is being saved\n");
735  continue;
736  }
737 
738  if (op->head || object_get_owner(op) != NULL)
739  continue;
740 
741  if (unique || QUERY_FLAG(op, FLAG_UNIQUE)) {
743  count++ ;
744  } else if (flag == 0
747  count++;
748  }
749  } FOR_MAP_FINISH(); /* for this space */
750  } /* for this j */
751  }
752  PROFILE_END(diff, serialize_time = diff);
753 
754  PROFILE_BEGIN();
755  char *cp = stringbuffer_finish(sb);
756  char *cp2 = stringbuffer_finish(sb2);
757  fputs(cp, fp);
758  fputs(cp2, fp2);
759  free(cp);
760  free(cp2);
761  PROFILE_END(diff, write_time = diff);
762 
763  LOG(llevDebug, "saved %d objects on %s (%ld us serializing, %ld us writing)\n", count, m->path, serialize_time, write_time);
764  return 0;
765 }
766 
777  mapstruct *map = static_cast<mapstruct *>(calloc(1, sizeof(mapstruct)));
778  /* mapstruct *mp;*/
779 
780  if (map == NULL)
782 
783  map->next = first_map;
784  first_map = map;
785 
786  map->in_memory = MAP_SWAPPED;
787 
788  MAP_WIDTH(map) = 16;
789  MAP_HEIGHT(map) = 16;
790  MAP_RESET_TIMEOUT(map) = 0;
791  MAP_TIMEOUT(map) = 300;
792  MAP_ENTER_X(map) = 0;
793  MAP_ENTER_Y(map) = 0;
794  map->last_reset_time = 0;
795  return map;
796 }
797 
799 uint32_t map_size(mapstruct *m) {
800  return (uint32_t)m->width * (uint32_t)m->height;
801 }
802 
814  m->in_memory = MAP_IN_MEMORY;
815  /* Log this condition and free the storage. We could I suppose
816  * realloc, but if the caller is presuming the data will be intact,
817  * that is their poor assumption.
818  */
819  if (m->spaces) {
820  LOG(llevError, "allocate_map called with already allocated map (%s)\n", m->path);
821  free(m->spaces);
822  }
823 
824  m->spaces = static_cast<MapSpace *>(calloc(map_size(m), sizeof(MapSpace)));
825 
826  if (m->spaces == NULL)
828 }
829 
843 mapstruct *get_empty_map(int sizex, int sizey) {
845  m->width = sizex;
846  m->height = sizey;
847  m->in_memory = MAP_SWAPPED;
848  allocate_map(m);
849  return m;
850 }
851 
865 static shopitems *parse_shop_string(const char *input_string, const mapstruct *map) {
866  char *shop_string, *p, *q, *next_semicolon, *next_colon;
867  shopitems *items = NULL;
868  int i = 0, number_of_entries = 0;
869  const typedata *current_type;
870 
871  shop_string = strdup_local(input_string);
872  p = shop_string;
873  LOG(llevDebug, "parsing %s\n", input_string);
874  /* first we'll count the entries, we'll need that for allocating the array shortly */
875  while (p) {
876  p = strchr(p, ';');
877  number_of_entries++;
878  if (p)
879  p++;
880  }
881  p = shop_string;
882  strip_endline(p);
883  items = static_cast<shopitems *>(CALLOC(number_of_entries+1, sizeof(shopitems)));
884  /*
885  * The memset would always set at least one byte to zero,
886  * so a failed calloc would have segfaulted the program.
887  * Instead, check for a null and fail more gracefully.
888  */
889  if (!items)
891 
892  for (i = 0; i < number_of_entries; i++) {
893  if (!p) {
894  LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
895  break;
896  }
897  next_semicolon = strchr(p, ';');
898  next_colon = strchr(p, ':');
899  /* if there is a stregth specified, figure out what it is, we'll need it soon. */
900  if (next_colon && (!next_semicolon || next_colon < next_semicolon))
901  items[i].strength = atoi(strchr(p, ':')+1);
902 
903  if (isdigit(*p) || *p == '*') {
904  items[i].typenum = *p == '*' ? -1 : atoi(p);
905  current_type = get_typedata(items[i].typenum);
906  if (current_type) {
907  items[i].name = current_type->name;
908  items[i].name_pl = current_type->name_pl;
909  }
910  } else { /*we have a named type, let's figure out what it is */
911  q = strpbrk(p, ";:");
912  if (q)
913  *q = '\0';
914 
915  current_type = get_typedata_by_name(p);
916  if (current_type) {
917  items[i].name = current_type->name;
918  items[i].typenum = current_type->number;
919  items[i].name_pl = current_type->name_pl;
920  } else {
921  /* oh uh, something's wrong, let's free up this one, and try
922  * the next entry while we're at it, better print a warning */
923  LOG(llevError, "invalid type %s defined in shopitems for %s in string %s\n", p, map->name, input_string);
924  }
925  }
926  items[i].index = number_of_entries;
927  if (next_semicolon)
928  p = ++next_semicolon;
929  else
930  p = NULL;
931  }
932  free(shop_string);
933  return items;
934 }
935 
947 static void print_shop_string(mapstruct *m, char *output_string, int size) {
948  int i;
949  char tmp[MAX_BUF];
950 
951  output_string[0] = '\0';
952  for (i = 0; i < m->shopitems[0].index; i++) {
953  if (m->shopitems[i].typenum != -1) {
954  if (m->shopitems[i].strength) {
955  snprintf(tmp, sizeof(tmp), "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
956  } else
957  snprintf(tmp, sizeof(tmp), "%s;", m->shopitems[i].name);
958  } else {
959  if (m->shopitems[i].strength) {
960  snprintf(tmp, sizeof(tmp), "*:%d;", m->shopitems[i].strength);
961  } else
962  snprintf(tmp, sizeof(tmp), "*;");
963  }
964  snprintf(output_string+strlen(output_string), size-strlen(output_string), "%s", tmp);
965  }
966 
967  /* erase final ; else parsing back will lead to issues */
968  if (strlen(output_string) > 0) {
969  output_string[strlen(output_string) - 1] = '\0';
970  }
971 }
972 
989 static int load_map_header(FILE *fp, mapstruct *m) {
990  char buf[HUGE_BUF], *key = NULL, *value;
991 
992  m->width = m->height = 0;
993  while (fgets(buf, sizeof(buf), fp) != NULL) {
994  char *p;
995 
996  p = strchr(buf, '\n');
997  if (p == NULL) {
998  LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf);
999  return 1;
1000  }
1001  *p = '\0';
1002 
1003  key = buf;
1004  while (isspace(*key))
1005  key++;
1006  if (*key == 0)
1007  continue; /* empty line */
1008  value = strchr(key, ' ');
1009  if (value) {
1010  *value = 0;
1011  value++;
1012  while (isspace(*value)) {
1013  value++;
1014  if (*value == '\0') {
1015  /* Nothing but spaces. */
1016  value = NULL;
1017  break;
1018  }
1019  }
1020  }
1021 
1022  /* key is the field name, value is what it should be set
1023  * to. We've already done the work to null terminate key,
1024  * and strip off any leading spaces for both of these.
1025  * We have not touched the newline at the end of the line -
1026  * these are needed for some values. the end pointer
1027  * points to the first of the newlines.
1028  * value could be NULL! It would be easy enough to just point
1029  * this to "" to prevent cores, but that would let more errors slide
1030  * through.
1031  *
1032  * First check for entries that do not use the value parameter, then
1033  * validate that value is given and check for the remaining entries
1034  * that use the parameter.
1035  */
1036 
1037  if (!strcmp(key, "msg")) {
1038  char msgbuf[HUGE_BUF];
1039  int msgpos = 0;
1040 
1041  while (fgets(buf, sizeof(buf), fp) != NULL) {
1042  if (!strcmp(buf, "endmsg\n"))
1043  break;
1044  else {
1045  snprintf(msgbuf+msgpos, sizeof(msgbuf)-msgpos, "%s", buf);
1046  msgpos += strlen(buf);
1047  }
1048  }
1049  /* There are lots of maps that have empty messages (eg, msg/endmsg
1050  * with nothing between). There is no reason in those cases to
1051  * keep the empty message. Also, msgbuf contains garbage data
1052  * when msgpos is zero, so copying it results in crashes
1053  */
1054  if (msgpos != 0) {
1055  /* When loading eg an overlay, message is already set, so free() current one. */
1056  free(m->msg);
1057  m->msg = strdup_local(msgbuf);
1058  }
1059  } else if (!strcmp(key, "maplore")) {
1060  char maplorebuf[HUGE_BUF];
1061  size_t maplorepos = 0;
1062 
1063  while (fgets(buf, HUGE_BUF-1, fp) != NULL) {
1064  if (!strcmp(buf, "endmaplore\n"))
1065  break;
1066  else {
1067  if (maplorepos >= sizeof(maplorebuf)) {
1068  LOG(llevError, "Map lore exceeds buffer length\n");
1069  return 1;
1070  }
1071  snprintf(maplorebuf+maplorepos, sizeof(maplorebuf)-maplorepos, "%s", buf);
1072  maplorepos += strlen(buf);
1073  }
1074  }
1075  if (maplorepos != 0)
1076  m->maplore = strdup_local(maplorebuf);
1077  } else if (!strcmp(key, "end")) {
1078  break;
1079  } else if (value == NULL) {
1080  LOG(llevError, "Got '%s' line without parameter in map header\n", key);
1081  } else if (!strcmp(key, "arch")) {
1082  /* This is an oddity, but not something we care about much. */
1083  if (strcmp(value, "map")) {
1084  LOG(llevError, "load_map_header: expected 'arch map': check line endings?\n");
1085  return 1;
1086  }
1087  } else if (!strcmp(key, "name")) {
1088  /* When loading eg an overlay, the name is already set, so free() current one. */
1089  free(m->name);
1090  m->name = strdup_local(value);
1091  /* first strcmp value on these are old names supported
1092  * for compatibility reasons. The new values (second) are
1093  * what really should be used.
1094  */
1095  } else if (!strcmp(key, "enter_x")) {
1096  m->enter_x = atoi(value);
1097  } else if (!strcmp(key, "enter_y")) {
1098  m->enter_y = atoi(value);
1099  } else if (!strcmp(key, "width")) {
1100  m->width = atoi(value);
1101  } else if (!strcmp(key, "height")) {
1102  m->height = atoi(value);
1103  } else if (!strcmp(key, "reset_timeout")) {
1104  m->reset_timeout = atoi(value);
1105  } else if (!strcmp(key, "swap_time")) {
1106  m->timeout = atoi(value);
1107  } else if (!strcmp(key, "difficulty")) {
1108  m->difficulty = atoi(value);
1109  } else if (!strcmp(key, "darkness")) {
1110  m->darkness = atoi(value);
1111  } else if (!strcmp(key, "fixed_resettime")) {
1112  m->fixed_resettime = atoi(value);
1113  } else if (!strcmp(key, "unique")) {
1114  m->unique = atoi(value);
1115  } else if (!strcmp(key, "template")) {
1116  m->is_template = atoi(value);
1117  } else if (!strcmp(key, "region")) {
1118  m->region = get_region_by_name(value);
1119  } else if (!strcmp(key, "shopitems")) {
1120  m->shopitems = parse_shop_string(value, m);
1121  } else if (!strcmp(key, "shopgreed")) {
1122  m->shopgreed = atof(value);
1123  } else if (!strcmp(key, "shopmin")) {
1124  m->shopmin = atol(value);
1125  } else if (!strcmp(key, "shopmax")) {
1126  m->shopmax = atol(value);
1127  } else if (!strcmp(key, "shoprace")) {
1128  m->shoprace = strdup_local(value);
1129  } else if (!strcmp(key, "outdoor")) {
1130  m->outdoor = atoi(value);
1131  } else if (!strcmp(key, "nosmooth")) {
1132  m->nosmooth = atoi(value);
1133  } else if (!strcmp(key, "first_load")) {
1134  m->last_reset_time = atoi(value);
1135  } else if (!strncmp(key, "tile_path_", 10)) {
1136  int tile = atoi(key+10);
1137 
1138  if (tile < 1 || tile > 4) {
1139  LOG(llevError, "load_map_header: tile location %d out of bounds (%s)\n", tile, m->path);
1140  } else {
1141  if (m->tile_path[tile-1]) {
1142  LOG(llevError, "load_map_header: tile location %d duplicated (%s)\n", tile, m->path);
1143  free(m->tile_path[tile-1]);
1144  }
1145  m->tile_path[tile-1] = strdup_local(value);
1146  } /* end if tile direction (in)valid */
1147  } else if (!strcmp(key, "background_music")) {
1148  m->background_music = strdup_local(value);
1149  } else if (!strcmp(key, "reset_group")) {
1150  m->reset_group = add_string(value);
1151  } else {
1152  LOG(llevError, "Got unknown value in map header: %s %s\n", key, value);
1153  }
1154  }
1155  if ((m->width == 0) || (m->height == 0)) {
1156  LOG(llevError, "Map width or height not specified\n");
1157  return 1;
1158  }
1159  if (!key || strcmp(key, "end")) {
1160  LOG(llevError, "Got premature eof on map header!\n");
1161  return 1;
1162  }
1163  return 0;
1164 }
1165 
1166 void map_path(const char *map, int flags, char *pathname, size_t bufsize) {
1167  if (flags&MAP_PLAYER_UNIQUE) {
1168  snprintf(pathname, bufsize, "%s/%s/%s", settings.localdir, settings.playerdir, map+1);
1169  }
1170  else if (flags&MAP_OVERLAY)
1171  create_overlay_pathname(map, pathname, bufsize);
1172  else
1173  create_pathname(map, pathname, bufsize);
1174 }
1175 
1176 mapstruct *mapfile_load_lowlevel(const char *map, const char *pathname, int flags) {
1177  FILE *fp;
1178  if ((fp = fopen(pathname, "r")) == NULL) {
1180  "Can't open %s: %s\n", pathname, strerror(errno));
1181  return NULL;
1182  }
1183 
1184  mapstruct *m = get_linked_map();
1185  safe_strncpy(m->path, map, HUGE_BUF);
1186  if (load_map_header(fp, m)) {
1187  LOG(llevError, "Error loading map header for %s, flags=%d\n", map, flags);
1188  delete_map(m);
1189  fclose(fp);
1190  return NULL;
1191  }
1192 
1193  allocate_map(m);
1194 
1195  m->in_memory = MAP_LOADING;
1196  load_objects(m, fp, flags & MAP_STYLE);
1197  fclose(fp);
1198  m->in_memory = MAP_IN_MEMORY;
1199  return m;
1200 }
1201 
1217 mapstruct *mapfile_load(const char *map, int flags) {
1218  mapstruct *m;
1219  PROFILE_BEGIN();
1220  char pathname[MAX_BUF];
1221  map_path(map, flags, pathname, sizeof(pathname));
1222  m = mapfile_load_lowlevel(map, pathname, flags);
1223  if (!m) {
1224  return NULL;
1225  }
1226  if (!MAP_DIFFICULTY(m) && (!(flags & MAP_NO_DIFFICULTY)))
1229 
1230  /* In case other objects press some buttons down */
1231  update_buttons(m);
1232 
1234 
1235  if (!(flags & MAP_STYLE))
1236  apply_auto_fix(m); /* Chests which open as default */
1237 
1238  PROFILE_END(diff,
1239  LOG(llevDebug, "mapfile_load on %s" " took %ld us\n", map, diff));
1240 
1242  return (m);
1243 }
1244 
1254  FILE *fp;
1255 
1256  if (!m->tmpname) {
1257  LOG(llevError, "No temporary filename for map %s\n", m->path);
1258  return 1;
1259  }
1260 
1261  if ((fp = fopen(m->tmpname, "r")) == NULL) {
1262  LOG(llevError, "Cannot open %s: %s\n", m->tmpname, strerror(errno));
1263  return 2;
1264  }
1265 
1266  if (load_map_header(fp, m)) {
1267  LOG(llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1268  fclose(fp);
1269  return 3;
1270  }
1271  allocate_map(m);
1272 
1273  m->in_memory = MAP_LOADING;
1274  load_objects(m, fp, 0);
1275  fclose(fp);
1276  m->in_memory = MAP_IN_MEMORY;
1277  return 0;
1278 }
1279 
1289 static int load_overlay_map(const char *filename, mapstruct *m) {
1290  FILE *fp;
1291  char pathname[MAX_BUF];
1292 
1294 
1295  if ((fp = fopen(pathname, "r")) == NULL) {
1296  /* nothing bad to not having an overlay */
1297  return 0;
1298  }
1299 
1300  if (load_map_header(fp, m)) {
1301  LOG(llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1302  fclose(fp);
1303  return 1;
1304  }
1305  /*allocate_map(m);*/
1306 
1307  m->in_memory = MAP_LOADING;
1308  load_objects(m, fp, MAP_OVERLAY);
1309  fclose(fp);
1310  m->in_memory = MAP_IN_MEMORY;
1311  return 0;
1312 }
1313 
1314 /******************************************************************************
1315  * This is the start of unique map handling code
1316  *****************************************************************************/
1317 
1325  int i, j, unique = 0;
1326 
1327  for (i = 0; i < MAP_WIDTH(m); i++)
1328  for (j = 0; j < MAP_HEIGHT(m); j++) {
1329  unique = 0;
1330  FOR_MAP_PREPARE(m, i, j, op) {
1332  unique = 1;
1333  if (op->head == NULL && (QUERY_FLAG(op, FLAG_UNIQUE) || unique)) {
1334  clean_object(op);
1337  object_remove(op);
1339  }
1340  } FOR_MAP_FINISH();
1341  }
1342 }
1343 
1350  FILE *fp;
1351  int count;
1352  char name[MAX_BUF], firstname[sizeof(name) + 4];
1353 
1354  create_items_path(m->path, name, MAX_BUF);
1355  for (count = 0; count < 10; count++) {
1356  snprintf(firstname, sizeof(firstname), "%s.v%02d", name, count);
1357  if (!access(firstname, R_OK))
1358  break;
1359  }
1360  /* If we get here, we did not find any map */
1361  if (count == 10)
1362  return;
1363 
1364  if ((fp = fopen(firstname, "r")) == NULL) {
1365  /* There is no expectation that every map will have unique items, but this
1366  * is debug output, so leave it in.
1367  */
1368  LOG(llevDebug, "Can't open unique items file for %s\n", name);
1369  return;
1370  }
1371 
1372  m->in_memory = MAP_LOADING;
1373  if (m->tmpname == NULL) /* if we have loaded unique items from */
1374  delete_unique_items(m); /* original map before, don't duplicate them */
1375  load_object(fp, NULL, LO_NOREAD, 0, false);
1376  load_objects(m, fp, 0);
1377  fclose(fp);
1378  m->in_memory = MAP_IN_MEMORY;
1379 }
1380 
1396 int save_map(mapstruct *m, int flag) {
1397  FILE *fp, *fp2;
1398  OutputFile of, of2;
1399  char filename[MAX_BUF], shop[MAX_BUF];
1400  int i, res;
1401 
1402  if (flag && !*m->path) {
1403  LOG(llevError, "Tried to save map without path.\n");
1404  return SAVE_ERROR_NO_PATH;
1405  }
1406 
1407  PROFILE_BEGIN();
1408 
1409  if (flag != SAVE_MODE_NORMAL || (m->unique) || (m->is_template)) {
1410  if (!m->unique && !m->is_template) { /* flag is set */
1411  if (flag == SAVE_MODE_OVERLAY)
1413  else
1414  create_pathname(m->path, filename, MAX_BUF);
1415  } else {
1416  if (m->path[0] != '~') {
1417  LOG(llevError,
1418  "Cannot save unique map '%s' outside of LOCALDIR. Check "
1419  "that all exits to '%s' have FLAG_UNIQUE set correctly.\n",
1420  m->path, m->path);
1421  return SAVE_ERROR_UCREATION;
1422  }
1423  snprintf(filename, sizeof(filename), "%s/%s/%s", settings.localdir, settings.playerdir, m->path+1);
1424  }
1425 
1427  } else {
1428  if (!m->tmpname)
1429  m->tmpname = tempnam(settings.tmpdir, NULL);
1430  strlcpy(filename, m->tmpname, sizeof(filename));
1431  }
1432  m->in_memory = MAP_SAVING;
1433 
1434  fp = of_open(&of, filename);
1435  if (fp == NULL)
1436  return SAVE_ERROR_RCREATION;
1437 
1438  /* legacy */
1439  fprintf(fp, "arch map\n");
1440  if (m->name)
1441  fprintf(fp, "name %s\n", m->name);
1442  if (!flag)
1443  fprintf(fp, "swap_time %d\n", m->timeout);
1444  if (m->reset_timeout)
1445  fprintf(fp, "reset_timeout %u\n", m->reset_timeout);
1446  if (m->fixed_resettime)
1447  fprintf(fp, "fixed_resettime %d\n", m->fixed_resettime);
1448  /* we unfortunately have no idea if this is a value the creator set
1449  * or a difficulty value we generated when the map was first loaded
1450  */
1451  if (m->difficulty)
1452  fprintf(fp, "difficulty %d\n", m->difficulty);
1453  if (m->region)
1454  fprintf(fp, "region %s\n", m->region->name);
1455  if (m->shopitems) {
1456  print_shop_string(m, shop, sizeof(shop));
1457  fprintf(fp, "shopitems %s\n", shop);
1458  }
1459  if (m->shopgreed)
1460  fprintf(fp, "shopgreed %f\n", m->shopgreed);
1461  if (m->shopmin)
1462  fprintf(fp, "shopmin %" FMT64U "\n", m->shopmin);
1463  if (m->shopmax)
1464  fprintf(fp, "shopmax %" FMT64U "\n", m->shopmax);
1465  if (m->shoprace)
1466  fprintf(fp, "shoprace %s\n", m->shoprace);
1467  if (m->darkness)
1468  fprintf(fp, "darkness %d\n", m->darkness);
1469  if (m->width)
1470  fprintf(fp, "width %d\n", m->width);
1471  if (m->height)
1472  fprintf(fp, "height %d\n", m->height);
1473  if (m->enter_x)
1474  fprintf(fp, "enter_x %d\n", m->enter_x);
1475  if (m->enter_y)
1476  fprintf(fp, "enter_y %d\n", m->enter_y);
1477  if (m->msg)
1478  fprintf(fp, "msg\n%sendmsg\n", m->msg);
1479  if (m->maplore)
1480  fprintf(fp, "maplore\n%sendmaplore\n", m->maplore);
1481  if (m->unique)
1482  fprintf(fp, "unique %d\n", m->unique);
1483  if (m->is_template)
1484  fprintf(fp, "template %d\n", m->is_template);
1485  if (m->outdoor)
1486  fprintf(fp, "outdoor %d\n", m->outdoor);
1487  if (m->nosmooth)
1488  fprintf(fp, "nosmooth %d\n", m->nosmooth);
1489  if (m->last_reset_time)
1490  fprintf(fp, "first_load %ld\n", m->last_reset_time);
1491  if (m->background_music)
1492  fprintf(fp, "background_music %s\n", m->background_music);
1493  if (m->reset_group)
1494  fprintf(fp, "reset_group %s\n", m->reset_group);
1495 
1496  /* Save any tiling information, except on overlays */
1497  if (flag != SAVE_MODE_OVERLAY)
1498  for (i = 0; i < 4; i++)
1499  if (m->tile_path[i])
1500  fprintf(fp, "tile_path_%d %s\n", i+1, m->tile_path[i]);
1501 
1502  fprintf(fp, "end\n");
1503 
1504  /* In the game save unique items in the different file, but
1505  * in the editor save them to the normal map file.
1506  * If unique map, save files in the proper destination (set by
1507  * player)
1508  */
1509  if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->is_template) {
1510  char name[MAX_BUF], final_unique[sizeof(name) + 4];
1511 
1512  create_items_path(m->path, name, MAX_BUF);
1513  snprintf(final_unique, sizeof(final_unique), "%s.v00", name);
1514  fp2 = of_open(&of2, final_unique);
1515  if (fp2 == NULL) {
1516  of_cancel(&of);
1517  return SAVE_ERROR_UCREATION;
1518  }
1519  if (flag == SAVE_MODE_OVERLAY) {
1520  /* SO_FLAG_NO_REMOVE is non destructive save, so map is still valid. */
1521  res = save_objects(m, fp, fp2, SAVE_FLAG_NO_REMOVE);
1522  if (res < 0) {
1523  LOG(llevError, "Save error during object save: %d\n", res);
1524  of_cancel(&of);
1525  of_cancel(&of2);
1526  return res;
1527  }
1528  m->in_memory = MAP_IN_MEMORY;
1529  } else {
1530  res = save_objects(m, fp, fp2, 0);
1531  if (res < 0) {
1532  LOG(llevError, "Save error during object save: %d\n", res);
1533  of_cancel(&of);
1534  of_cancel(&of2);
1535  return res;
1536  }
1538  }
1539  if (ftell(fp2) == 0) {
1540  of_cancel(&of2);
1541  /* If there are no unique items left on the map, we need to
1542  * unlink the original unique map so that the unique
1543  * items don't show up again.
1544  */
1545  unlink(final_unique);
1546  } else {
1547  if (!of_close(&of2)) {
1548  of_cancel(&of);
1549  return SAVE_ERROR_URENAME;
1550  }
1551 
1552  if (chmod(final_unique, SAVE_MODE) != 0) {
1553  LOG(llevError, "Could not set permissions on '%s'\n",
1554  final_unique);
1555  }
1556  }
1557  } else { /* save same file when not playing, like in editor */
1558  res = save_objects(m, fp, fp, 0);
1559  if (res < 0) {
1560  LOG(llevError, "Save error during object save: %d\n", res);
1561  of_cancel(&of);
1562  return res;
1563  }
1565  }
1566 
1567  if (!of_close(&of))
1568  return SAVE_ERROR_CLOSE;
1569 
1570  if (chmod(filename, SAVE_MODE) != 0) {
1571  LOG(llevError, "Could not set permissions on '%s'\n", filename);
1572  }
1573 
1574  PROFILE_END(diff,
1575  LOG(llevDebug, "save_map on %s" " took %ld us\n", m->path, diff));
1576 
1577  maps_saved_total++;
1578  return SAVE_ERROR_OK;
1579 }
1580 
1590 void clean_object(object *op) {
1591  FOR_INV_PREPARE(op, tmp) {
1592  clean_object(tmp);
1595  object_remove(tmp);
1597  } FOR_INV_FINISH();
1598 }
1599 
1607  int i, j;
1608  object *op;
1609 
1610  for (i = 0; i < MAP_WIDTH(m); i++)
1611  for (j = 0; j < MAP_HEIGHT(m); j++) {
1612  object *previous_obj = NULL;
1613 
1614  while ((op = GET_MAP_OB(m, i, j)) != NULL) {
1615  if (op == previous_obj) {
1616  LOG(llevDebug, "free_all_objects: Link error, bailing out.\n");
1617  break;
1618  }
1619  previous_obj = op;
1620  op = HEAD(op);
1621 
1622  /* If the map isn't in memory, object_free_drop_inventory() will remove and
1623  * free objects in op's inventory. So let it do the job.
1624  */
1625  if (m->in_memory == MAP_IN_MEMORY)
1626  clean_object(op);
1627  object_remove(op);
1629  }
1630  }
1631 #ifdef MANY_CORES
1632  /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1633  * an item on that map was not saved - look for that condition and die as appropriate -
1634  * this leaves more of the map data intact for better debugging.
1635  */
1636  for (op = objects; op != NULL; op = op->next) {
1637  if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1638  LOG(llevError, "free_all_objects: object %s still on map after it should have been freed\n", op->name);
1639  abort();
1640  }
1641  }
1642 #endif
1643 }
1644 
1654  int i;
1655 
1656  if (!m->in_memory) {
1657  LOG(llevError, "Trying to free freed map.\n");
1658  return;
1659  }
1660 
1662 
1663  if (m->spaces)
1665  if (m->name)
1666  FREE_AND_CLEAR(m->name);
1667  if (m->spaces)
1668  FREE_AND_CLEAR(m->spaces);
1669  if (m->msg)
1670  FREE_AND_CLEAR(m->msg);
1671  if (m->maplore)
1672  FREE_AND_CLEAR(m->maplore);
1673  if (m->shopitems)
1674  FREE_AND_CLEAR(m->shopitems);
1675  if (m->shoprace)
1676  FREE_AND_CLEAR(m->shoprace);
1677  if (m->background_music)
1678  FREE_AND_CLEAR(m->background_music);
1679  if (m->buttons)
1680  free_objectlinkpt(m->buttons);
1681  m->buttons = NULL;
1682  for (i = 0; i < 4; i++) {
1683  if (m->tile_path[i])
1684  FREE_AND_CLEAR(m->tile_path[i]);
1685  m->tile_map[i] = NULL;
1686  }
1687  m->in_memory = MAP_SWAPPED;
1688 }
1689 
1700  mapstruct *tmp, *last;
1701  int i;
1702 
1703  if (!m)
1704  return;
1705  if (m->in_memory == MAP_IN_MEMORY) {
1706  /* change to MAP_SAVING, even though we are not,
1707  * so that object_remove() doesn't do as much work.
1708  */
1709  m->in_memory = MAP_SAVING;
1710  free_map(m);
1711  }
1712  /* move this out of free_map, since tmpname can still be needed if
1713  * the map is swapped out.
1714  */
1715  free(m->tmpname);
1716  m->tmpname = NULL;
1717  FREE_AND_CLEAR_STR_IF(m->reset_group);
1718  last = NULL;
1719  /* We need to look through all the maps and see if any maps
1720  * are pointing at this one for tiling information. Since
1721  * tiling can be assymetric, we just can not look to see which
1722  * maps this map tiles with and clears those.
1723  */
1724  for (tmp = first_map; tmp != NULL; tmp = tmp->next) {
1725  if (tmp->next == m)
1726  last = tmp;
1727 
1728  /* This should hopefully get unrolled on a decent compiler */
1729  for (i = 0; i < 4; i++)
1730  if (tmp->tile_map[i] == m)
1731  tmp->tile_map[i] = NULL;
1732  }
1733 
1734  /* If last is null, then this should be the first map in the list */
1735  if (!last) {
1736  if (m == first_map)
1737  first_map = m->next;
1738  else
1739  /* m->path is a static char, so should hopefully still have
1740  * some useful data in it.
1741  */
1742  LOG(llevError, "delete_map: Unable to find map %s in list\n", m->path);
1743  } else
1744  last->next = m->next;
1745 
1746  free(m);
1747 }
1748 
1762 mapstruct *ready_map_name(const char *name, int flags) {
1763  mapstruct *m;
1764 
1765  if (!name)
1766  return (NULL);
1767 
1768  /* Have we been at this level before? */
1769  m = has_been_loaded(name);
1770 
1771  /* Map is good to go, so just return it */
1772  if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) {
1773  return m;
1774  }
1775 
1776  /* Rewrite old paths starting with LOCALDIR/PLAYERDIR to new '~' paths. */
1777  char buf[MAX_BUF], buf2[MAX_BUF];
1778  snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, settings.playerdir);
1779  if (strncmp(name, buf, strlen(buf)) == 0) {
1780  snprintf(buf2, sizeof(buf2), "~%s", name+strlen(buf)+1);
1781  name = buf2;
1782  }
1783 
1784  /* Paths starting with '~' are unique. */
1785  if (name[0] == '~') {
1787  }
1788 
1789  /* unique maps always get loaded from their original location, and never
1790  * a temp location. Likewise, if map_flush is set, or we have never loaded
1791  * this map, load it now. I removed the reset checking from here -
1792  * it seems the probability of a player trying to enter a map that should
1793  * reset but hasn't yet is quite low, and removing that makes this function
1794  * a bit cleaner (and players probably shouldn't rely on exact timing for
1795  * resets in any case - if they really care, they should use the 'maps command.
1796  */
1797  if ((flags&(MAP_FLUSH|MAP_PLAYER_UNIQUE)) || !m) {
1798  /* first visit or time to reset */
1799  if (m) {
1800  clean_tmp_map(m); /* Doesn't make much difference */
1801  delete_map(m);
1802  }
1803 
1805  if (m == NULL) return NULL;
1806 
1807  /* If a player unique map, no extra unique object file to load.
1808  * if from the editor, likewise.
1809  */
1812 
1814  if (load_overlay_map(name, m) != 0) {
1815  delete_map(m);
1816  m = mapfile_load(name, 0);
1817  if (m == NULL) {
1818  /* Really, this map is bad :( */
1819  return NULL;
1820  }
1821  }
1822  }
1823  } else {
1824  /* If in this loop, we found a temporary map, so load it up. */
1825 
1826  if (load_temporary_map(m) != 0) {
1827  /*
1828  * There was a failure loading the temporary map, fall back to original one.
1829  * load_temporary_map() already logged the error.
1830  */
1831  delete_map(m);
1832  m = mapfile_load(name, 0);
1833  if (m == NULL) {
1834  /* Really, this map is bad :( */
1835  return NULL;
1836  }
1837  }
1839 
1840  clean_tmp_map(m);
1841  m->in_memory = MAP_IN_MEMORY;
1842  /* tempnam() on sun systems (probably others) uses malloc
1843  * to allocated space for the string. Free it here.
1844  * In some cases, load_temporary_map above won't find the
1845  * temporary map, and so has reloaded a new map. If that
1846  * is the case, tmpname is now null
1847  */
1848  free(m->tmpname);
1849  m->tmpname = NULL;
1850  /* It's going to be saved anew anyway */
1851  }
1852 
1853  /* Below here is stuff common to both first time loaded maps and
1854  * temp maps.
1855  */
1856 
1857  decay_objects(m); /* start the decay */
1858 
1859  if (m->outdoor)
1861 
1862  if (!(flags&(MAP_FLUSH))) {
1863  if (m->last_reset_time == 0) {
1864  m->last_reset_time = seconds();
1865  }
1866  }
1867 
1869 
1870  return m;
1871 }
1872 
1889  archetype *at;
1890  int x, y;
1891  int diff = 0;
1892  int i;
1893  int64_t exp_pr_sq, total_exp = 0;
1894 
1895  if (MAP_DIFFICULTY(m)) {
1896  return MAP_DIFFICULTY(m);
1897  }
1898 
1899  for (x = 0; x < MAP_WIDTH(m); x++)
1900  for (y = 0; y < MAP_HEIGHT(m); y++)
1901  FOR_MAP_PREPARE(m, x, y, op) {
1902  if (QUERY_FLAG(op, FLAG_MONSTER))
1903  total_exp += op->stats.exp;
1905  total_exp += op->stats.exp;
1906  // If we have an other_arch on our generator, just use that.
1907  // FIXME: Figure out what to do if we are doing template generation from inventory.
1908  at = op->other_arch ? op->other_arch : NULL;
1909  if (at != NULL) {
1910  // Make sure we can't set off a null pointer dereference in atoi().
1911  const char *val = object_get_value(op, "generator_limit");
1912  int lim = atoi(val ? val : "0");
1913  // We assume, on average, the generator will generate half its contents.
1914  if (!lim || lim >= 16)
1915  total_exp += at->clone.stats.exp*8;
1916  else
1917  total_exp += at->clone.stats.exp*(lim/2);
1918  }
1919  }
1920  } FOR_MAP_FINISH();
1921  // Used to be multiplied by 1000, but this undershot horribly
1922  // once I fixed the calculation for generators.
1923  // I'm trying out some exponentiation, since linear scaling
1924  // seems to overshoot low-level maps and undershoot high-level maps.
1925  // I also feel comfortable, knowing that generators return
1926  // sensible values, to up the max diff this calculates from 20 to 25.
1927  // - Neila Hawkins 2021-03-04
1928  exp_pr_sq = (pow(total_exp, 1.75))/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1);
1929  diff = 25;
1930  for (i = 1; i < 25; i++)
1931  if (exp_pr_sq <= level_exp(i, 1.0)) {
1932  diff = i;
1933  break;
1934  }
1935 
1936  return diff;
1937 }
1938 
1946  if (m->tmpname == NULL)
1947  return;
1948  (void)unlink(m->tmpname);
1949 }
1950 
1954 void free_all_maps(void) {
1955  int real_maps = 0;
1956 
1957  while (first_map) {
1958  /* I think some of the callers above before it gets here set this to be
1959  * saving, but we still want to free this data
1960  */
1961  if (first_map->in_memory == MAP_SAVING)
1964  real_maps++;
1965  }
1966  LOG(llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1967 }
1968 
1986 int change_map_light(mapstruct *m, int change) {
1987  int new_level = m->darkness+change;
1988 
1989  /* Nothing to do */
1990  if (!change
1991  || (new_level <= 0 && m->darkness == 0)
1992  || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) {
1993  return 0;
1994  }
1995 
1996  /* inform all players on the map */
1997  if (change > 0)
1998  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes darker.");
1999  else
2000  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes brighter.");
2001 
2002  /* Do extra checking. since m->darkness is a unsigned value,
2003  * we need to be extra careful about negative values.
2004  * In general, the checks below are only needed if change
2005  * is not +/-1
2006  */
2007  if (new_level < 0)
2008  m->darkness = 0;
2009  else if (new_level >= MAX_DARKNESS)
2010  m->darkness = MAX_DARKNESS;
2011  else
2012  m->darkness = new_level;
2013 
2014  /* All clients need to get re-updated for the change */
2016  return 1;
2017 }
2018 
2041 static inline void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) {
2042  int l, l1;
2043  object *tmp;
2044 
2045  for (l = low_layer; l <= high_layer; l++) {
2046  if (!layers[l]) {
2047  /* found an empty spot. now, we want to make sure
2048  * highest visibility at top, etc.
2049  */
2050  layers[l] = ob;
2051  if (!honor_visibility)
2052  return;
2053 
2054  /* This is basically a mini bubble sort. Only swap
2055  * position if the lower face has greater (not equal)
2056  * visibility - map stacking is secondary consideration here.
2057  */
2058  for (l1 = (l-1); l1 >= low_layer; l1--) {
2059  if (layers[l1]->face->visibility > layers[l1+1]->face->visibility) {
2060  tmp = layers[l1+1];
2061  layers[l1+1] = layers[l1];
2062  layers[l1] = tmp;
2063  }
2064  }
2065  /* Nothing more to do - face inserted */
2066  return;
2067  }
2068  }
2069  /* If we get here, all the layers have an object..
2070  */
2071  if (!honor_visibility) {
2072  /* Basically, in this case, it is pure stacking logic, so
2073  * new object goes on the top.
2074  */
2075  for (l = low_layer; l < high_layer; l++)
2076  layers[l] = layers[l+1];
2077  layers[high_layer] = ob;
2078  /* If this object doesn't have higher visibility than
2079  * the lowest object, no reason to go further.
2080  */
2081  } else if (ob->face->visibility >= layers[low_layer]->face->visibility) {
2082  /*
2083  * Start at the top (highest visibility) layer and work down.
2084  * once this face exceed that of the layer, push down those
2085  * other layers, and then replace the layer with our object.
2086  */
2087  for (l = high_layer; l >= low_layer; l--) {
2088  if (ob->face->visibility >= layers[l]->face->visibility) {
2089  for (l1 = low_layer; l1 < l; l1++)
2090  layers[l1] = layers[l1+1];
2091  layers[l] = ob;
2092  break;
2093  }
2094  }
2095  }
2096 }
2097 
2110 void update_position(mapstruct *m, int x, int y) {
2111  object *player = NULL;
2112  uint8_t flags = 0, oldflags, light = 0;
2113  object *layers[MAP_LAYERS];
2114 
2115  MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2116 
2117  oldflags = GET_MAP_FLAGS(m, x, y);
2118  if (!(oldflags&P_NEED_UPDATE)) {
2119  LOG(llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
2120  return;
2121  }
2122 
2123  memset(layers, 0, MAP_LAYERS*sizeof(object *));
2124 
2125  FOR_MAP_PREPARE(m, x, y, tmp) {
2126  /* DMs just don't do anything when hidden, including no light. */
2127  if (QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden)
2128  continue;
2129 
2130  if (tmp->type == PLAYER)
2131  player = tmp;
2132 
2133  /* This could be made additive I guess (two lights better than
2134  * one). But if so, it shouldn't be a simple additive - 2
2135  * light bulbs do not illuminate twice as far as once since
2136  * it is a dissipation factor that is squared (or is it cubed?)
2137  */
2138  if (tmp->glow_radius > light)
2139  light = tmp->glow_radius;
2140 
2141  /* if this object is visible and not a blank face,
2142  * update the objects that show how this space
2143  * looks.
2144  */
2145  if (!tmp->invisible && tmp->face != blank_face) {
2146  if (tmp->map_layer) {
2147  add_face_layer(tmp->map_layer, map_layer_info[tmp->map_layer].high_layer,
2148  tmp, layers, map_layer_info[tmp->map_layer].honor_visibility);
2149  } else if (tmp->move_type&MOVE_FLYING) {
2151  } else if ((tmp->type == PLAYER || QUERY_FLAG(tmp, FLAG_MONSTER))) {
2153  } else if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2154  layers[MAP_LAYER_FLOOR] = tmp;
2155  /* floors hide everything else */
2156  memset(layers+1, 0, (MAP_LAYERS-1)*sizeof(object *));
2157  /* Check for FLAG_SEE_ANYWHERE is removed - objects
2158  * with that flag should just have a high visibility
2159  * set - we shouldn't need special code here.
2160  */
2161  } else if (QUERY_FLAG(tmp, FLAG_NO_PICK)) {
2163  } else {
2165  }
2166  }
2167  if (tmp == tmp->above) {
2168  LOG(llevError, "Error in structure of map\n");
2169  exit(-1);
2170  }
2171 
2172  move_slow |= tmp->move_slow;
2173  move_block |= tmp->move_block;
2174  move_on |= tmp->move_on;
2175  move_off |= tmp->move_off;
2176  move_allow |= tmp->move_allow;
2177 
2178  if (QUERY_FLAG(tmp, FLAG_ALIVE))
2179  flags |= P_IS_ALIVE;
2181  flags |= P_NO_MAGIC;
2183  flags |= P_NO_CLERIC;
2184 
2186  flags |= P_BLOCKSVIEW;
2187  } FOR_MAP_FINISH(); /* for stack of objects */
2188 
2189  if (player)
2190  flags |= P_PLAYER;
2191 
2192  /* we don't want to rely on this function to have accurate flags, but
2193  * since we're already doing the work, we calculate them here.
2194  * if they don't match, logic is broken someplace.
2195  */
2196  if (((oldflags&~(P_NEED_UPDATE|P_NO_ERROR)) != flags)
2197  && (!(oldflags&P_NO_ERROR))) {
2198  LOG(llevDebug, "update_position: updated flags do not match old flags: %s (x=%d,y=%d) %x != %x\n",
2199  m->path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2200  }
2201 
2202  SET_MAP_FLAGS(m, x, y, flags);
2203  SET_MAP_MOVE_BLOCK(m, x, y, move_block&~move_allow);
2204  SET_MAP_MOVE_ON(m, x, y, move_on);
2205  SET_MAP_MOVE_OFF(m, x, y, move_off);
2206  SET_MAP_MOVE_SLOW(m, x, y, move_slow);
2207  SET_MAP_LIGHT(m, x, y, light);
2208 
2209  /* Note that player may be NULL here, which is fine - if no player, need
2210  * to clear any value that may be set.
2211  */
2212  SET_MAP_PLAYER(m, x, y, player);
2213 
2214  /* Note it is intentional we copy everything, including NULL values. */
2215  memcpy(GET_MAP_FACE_OBJS(m, x, y), layers, sizeof(object *)*MAP_LAYERS);
2216 }
2217 
2225  int timeout;
2226 
2227  timeout = MAP_RESET_TIMEOUT(map);
2228  if (timeout <= 0)
2229  timeout = MAP_DEFAULTRESET;
2230  if (timeout >= MAP_MAXRESET)
2231  timeout = MAP_MAXRESET;
2232  MAP_RESET_TIMEOUT(map) = timeout;
2233  MAP_WHEN_RESET(map) = seconds()+timeout;
2234 }
2235 
2250 static mapstruct *load_and_link_tiled_map(mapstruct *orig_map, int tile_num) {
2251  int dest_tile = (tile_num+2)%4;
2252  char path[HUGE_BUF];
2253 
2254  path_combine_and_normalize(orig_map->path, orig_map->tile_path[tile_num], path, sizeof(path));
2255 
2256  orig_map->tile_map[tile_num] = ready_map_name(path, 0);
2257  if (orig_map->tile_map[tile_num] == NULL) {
2258  LOG(llevError, "%s has invalid tiled map %s\n", orig_map->path, path);
2259  free(orig_map->tile_path[tile_num]);
2260  orig_map->tile_path[tile_num] = NULL;
2261  return NULL;
2262  }
2263 
2264  /* need to do a strcmp here as the orig_map->path is not a shared string */
2265  if (orig_map->tile_map[tile_num]->tile_path[dest_tile]
2266  && !strcmp(orig_map->tile_map[tile_num]->tile_path[dest_tile], orig_map->path))
2267  orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
2268 
2269  return orig_map->tile_map[tile_num];
2270 }
2271 
2289 int out_of_map(mapstruct *m, int x, int y) {
2290 
2291  /* Simple case - coordinates are within this local
2292  * map.
2293  */
2294  if (x >= 0 && x < MAP_WIDTH(m) && y >= 0 && y < MAP_HEIGHT(m))
2295  return 0;
2296 
2297  if (x < 0) {
2298  if (!m->tile_path[3])
2299  return 1;
2300  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) {
2302  /* Verify the tile map loaded correctly */
2303  if (!m->tile_map[3])
2304  return 0;
2305  }
2306  return (out_of_map(m->tile_map[3], x+MAP_WIDTH(m->tile_map[3]), y));
2307  } else if (x >= MAP_WIDTH(m)) {
2308  if (!m->tile_path[1])
2309  return 1;
2310  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) {
2312  /* Verify the tile map loaded correctly */
2313  if (!m->tile_map[1])
2314  return 0;
2315  }
2316  return (out_of_map(m->tile_map[1], x-MAP_WIDTH(m), y));
2317  }
2318 
2319  if (y < 0) {
2320  if (!m->tile_path[0])
2321  return 1;
2322  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) {
2324  /* Verify the tile map loaded correctly */
2325  if (!m->tile_map[0])
2326  return 0;
2327  }
2328  return (out_of_map(m->tile_map[0], x, y+MAP_HEIGHT(m->tile_map[0])));
2329  } else if (y >= MAP_HEIGHT(m)) {
2330  if (!m->tile_path[2])
2331  return 1;
2332  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) {
2334  /* Verify the tile map loaded correctly */
2335  if (!m->tile_map[2])
2336  return 0;
2337  }
2338  return (out_of_map(m->tile_map[2], x, y-MAP_HEIGHT(m)));
2339  }
2340  return 1;
2341 }
2342 
2362 mapstruct *get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y) {
2363 
2364  /* Simple case - coordinates are within this local
2365  * map.
2366  */
2367 
2368  if ( !m ) return NULL;
2369  if (*x >= 0 && *x < MAP_WIDTH(m) && *y >= 0 && *y < MAP_HEIGHT(m))
2370  return m;
2371 
2372  do /* With the first case there, we can assume we are out of the map if we get here */
2373  {
2374  // Figure out what map should be in the direction we are off the map, and then
2375  // load that map and look again.
2376  if (*x < 0) {
2377  if (!m->tile_path[3])
2378  return NULL;
2379  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY){
2381  /* Make sure we loaded properly. */
2382  if (!m->tile_map[3])
2383  return NULL;
2384  }
2385  *x += MAP_WIDTH(m->tile_map[3]);
2386  m = m->tile_map[3];
2387  }
2388  else if (*x >= MAP_WIDTH(m)) {
2389  if (!m->tile_path[1])
2390  return NULL;
2391  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY){
2393  /* Make sure we loaded properly. */
2394  if (!m->tile_map[1])
2395  return NULL;
2396  }
2397  *x -= MAP_WIDTH(m);
2398  m = m->tile_map[1];
2399  }
2400  // It is possible that x and y be considered separate compare groups,
2401  // But using an else-if here retains the old behavior that recursion produced.
2402  else if (*y < 0) {
2403  if (!m->tile_path[0])
2404  return NULL;
2405  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY){
2407  /* Make sure we loaded properly. */
2408  if (!m->tile_map[0])
2409  return NULL;
2410  }
2411  *y += MAP_HEIGHT(m->tile_map[0]);
2412  m = m->tile_map[0];
2413  }
2414  else if (*y >= MAP_HEIGHT(m)) {
2415  if (!m->tile_path[2])
2416  return NULL;
2417  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY){
2419  /* Make sure we loaded properly. */
2420  if (!m->tile_map[2])
2421  return NULL;
2422  }
2423  *y -= MAP_HEIGHT(m);
2424  m = m->tile_map[2];
2425  }
2426  // The check here is if our single tile is in the map.
2427  // That is exactly what the OUT_OF_MAP macro does.
2428  } while (OUT_OF_REAL_MAP(m, *x, *y));
2429  return m; /* We have found our map */
2430 }
2431 
2445 static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {
2446  if (!map1 || !map2)
2447  return 0;
2448 
2449  if (map1 == map2) {
2450  *dx = 0;
2451  *dy = 0;
2452  } else if (map1->tile_map[0] == map2) { /* up */
2453  *dx = 0;
2454  *dy = -MAP_HEIGHT(map2);
2455  } else if (map1->tile_map[1] == map2) { /* right */
2456  *dx = MAP_WIDTH(map1);
2457  *dy = 0;
2458  } else if (map1->tile_map[2] == map2) { /* down */
2459  *dx = 0;
2460  *dy = MAP_HEIGHT(map1);
2461  } else if (map1->tile_map[3] == map2) { /* left */
2462  *dx = -MAP_WIDTH(map2);
2463  *dy = 0;
2464  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) { /* up right */
2465  *dx = MAP_WIDTH(map1->tile_map[0]);
2466  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2467  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) { /* up left */
2468  *dx = -MAP_WIDTH(map2);
2469  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2470  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) { /* right up */
2471  *dx = MAP_WIDTH(map1);
2472  *dy = -MAP_HEIGHT(map2);
2473  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) { /* right down */
2474  *dx = MAP_WIDTH(map1);
2475  *dy = MAP_HEIGHT(map1->tile_map[1]);
2476  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) { /* down right */
2477  *dx = MAP_WIDTH(map1->tile_map[2]);
2478  *dy = MAP_HEIGHT(map1);
2479  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) { /* down left */
2480  *dx = -MAP_WIDTH(map2);
2481  *dy = MAP_HEIGHT(map1);
2482  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) { /* left up */
2483  *dx = -MAP_WIDTH(map1->tile_map[3]);
2484  *dy = -MAP_HEIGHT(map2);
2485  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) { /* left down */
2486  *dx = -MAP_WIDTH(map1->tile_map[3]);
2487  *dy = MAP_HEIGHT(map1->tile_map[3]);
2488  } else { /* not "adjacent" enough */
2489  return 0;
2490  }
2491 
2492  return 1;
2493 }
2494 
2522 int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags) {
2523  if (!adjacent_map(op1->map, op2->map, &retval->distance_x, &retval->distance_y)) {
2524  /* be conservative and fill in _some_ data */
2525  retval->distance = 100000;
2526  retval->distance_x = 32767;
2527  retval->distance_y = 32767;
2528  retval->direction = 0;
2529  retval->part = NULL;
2530  return 0;
2531  } else {
2532  object *best;
2533 
2534  retval->distance_x += op2->x-op1->x;
2535  retval->distance_y += op2->y-op1->y;
2536 
2537  best = op1;
2538  /* If this is multipart, find the closest part now */
2539  if (!(flags&0x1) && op1->more) {
2540  object *tmp;
2541  int best_distance = retval->distance_x*retval->distance_x+
2542  retval->distance_y*retval->distance_y, tmpi;
2543 
2544  /* we just take the offset of the piece to head to figure
2545  * distance instead of doing all that work above again
2546  * since the distance fields we set above are positive in the
2547  * same axis as is used for multipart objects, the simply arithmetic
2548  * below works.
2549  */
2550  for (tmp = op1->more; tmp != NULL; tmp = tmp->more) {
2551  tmpi = (op1->x-tmp->x+retval->distance_x)*(op1->x-tmp->x+retval->distance_x)+
2552  (op1->y-tmp->y+retval->distance_y)*(op1->y-tmp->y+retval->distance_y);
2553  if (tmpi < best_distance) {
2554  best_distance = tmpi;
2555  best = tmp;
2556  }
2557  }
2558  if (best != op1) {
2559  retval->distance_x += op1->x-best->x;
2560  retval->distance_y += op1->y-best->y;
2561  }
2562  }
2563  retval->part = best;
2564  retval->distance = ihypot(retval->distance_x, retval->distance_y);
2565  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2566  return 1;
2567  }
2568 }
2569 
2590 int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval) {
2591  if (!adjacent_map(m, op2->map, &retval->distance_x, &retval->distance_y)) {
2592  /* be conservative and fill in _some_ data */
2593  retval->distance = 100000;
2594  retval->distance_x = 32767;
2595  retval->distance_y = 32767;
2596  retval->direction = 0;
2597  retval->part = NULL;
2598  return 0;
2599  } else {
2600  retval->distance_x += op2->x-x;
2601  retval->distance_y += op2->y-y;
2602 
2603  retval->part = NULL;
2604  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2605  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2606  return 1;
2607  }
2608 }
2609 
2628 int on_same_map(const object *op1, const object *op2) {
2629  int dx, dy;
2630 
2631  return adjacent_map(op1->map, op2->map, &dx, &dy);
2632 }
2633 
2651 object *map_find_by_flag(mapstruct *map, int x, int y, int flag) {
2652  object *tmp;
2653 
2654  for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above) {
2655  object *head;
2656 
2657  head = HEAD(tmp);
2658  if (QUERY_FLAG(head, flag))
2659  return head;
2660  }
2661  return NULL;
2662 }
2663 
2669  char base[HUGE_BUF], path[sizeof(base) + 4];
2670  int count;
2671 
2672  if (map->unique) {
2673  snprintf(path, sizeof(path), "%s/%s/%s", settings.localdir, settings.playerdir, map->path+1);
2674  if (unlink(path) != 0) {
2675  LOG(llevError, "Could not delete %s: %s\n", path, strerror(errno));
2676  }
2677  return;
2678  }
2679 
2680  create_items_path(map->path, base, sizeof(base));
2681 
2682  for (count = 0; count < 10; count++) {
2683  snprintf(path, sizeof(path), "%s.v%02d", base, count);
2684  unlink(path);
2685  }
2686 }
2687 
2693 const char *map_get_path(const object *item) {
2694  if (item->map != NULL) {
2695  if (strlen(item->map->path) > 0) {
2696  return item->map->path;
2697  }
2698 
2699  return item->map->name ? item->map->name : "(empty path and name)";
2700  }
2701 
2702  if (item->env != NULL)
2703  return map_get_path(item->env);
2704 
2705  return "(no map and no env!)";
2706 }
2707 
2713 bool map_path_unique(const char *path) {
2714  return path != NULL && path[0] == '~';
2715 }
mapstruct::tile_path
char * tile_path[4]
Definition: map.h:351
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:170
living::exp
int64_t exp
Definition: living.h:47
S_IWUSR
#define S_IWUSR
Definition: win32.h:47
shopitems::strength
int8_t strength
Definition: map.h:297
PLAYER
@ PLAYER
Definition: object.h:112
object_get_owner
object * object_get_owner(object *op)
Definition: object.cpp:804
Settings::mapdir
const char * mapdir
Definition: global.h:251
output_file.h
path.h
FREE_AND_CLEAR_STR_IF
#define FREE_AND_CLEAR_STR_IF(xyz)
Definition: global.h:200
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:545
settings
struct Settings settings
Definition: init.cpp:139
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:582
banquet.l
l
Definition: banquet.py:164
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
SAVE_MODE
#define SAVE_MODE
Definition: config.h:563
MAP_SAVING
#define MAP_SAVING
Definition: map.h:129
llevError
@ llevError
Definition: logger.h:11
MAP_NO_DIFFICULTY
#define MAP_NO_DIFFICULTY
Definition: map.h:93
MAP_LAYER_ITEM3
#define MAP_LAYER_ITEM3
Definition: map.h:45
MOVE_ALL
#define MOVE_ALL
Definition: define.h:398
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.cpp:843
FLAG_OVERLAY_FLOOR
#define FLAG_OVERLAY_FLOOR
Definition: define.h:255
of_close
int of_close(OutputFile *of)
Definition: output_file.cpp:61
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
archetype::more
archetype * more
Definition: object.h:486
create_items_path
static void create_items_path(const char *s, char *buf, size_t size)
Definition: map.cpp:166
get_region_by_name
region * get_region_by_name(const char *region_name)
Definition: region.cpp:46
of_open
FILE * of_open(OutputFile *of, const char *fname)
Definition: output_file.cpp:30
FLAG_GENERATOR
#define FLAG_GENERATOR
Definition: define.h:248
player
Definition: player.h:105
MAP_RESET_TIMEOUT
#define MAP_RESET_TIMEOUT(m)
Definition: map.h:64
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.cpp:344
strdup_local
#define strdup_local
Definition: compat.h:29
SAVE_FLAG_NO_REMOVE
#define SAVE_FLAG_NO_REMOVE
Definition: map.h:107
diamondslots.x
x
Definition: diamondslots.py:15
delete_unique_items
static void delete_unique_items(mapstruct *m)
Definition: map.cpp:1324
ready_map_name
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.cpp:1762
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
S_IROTH
#define S_IROTH
Definition: win32.h:50
load_temporary_map
static int load_temporary_map(mapstruct *m)
Definition: map.cpp:1253
has_been_loaded
mapstruct * has_been_loaded(const char *name)
Definition: map.cpp:79
print_shop_string
static void print_shop_string(mapstruct *m, char *output_string, int size)
Definition: map.cpp:947
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.cpp:2110
MAP_LAYER_FLOOR
#define MAP_LAYER_FLOOR
Definition: map.h:40
Settings::datadir
const char * datadir
Definition: global.h:248
add_face_layer
static void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
Definition: map.cpp:2041
stringbuffer_new
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.cpp:57
if
if(!(yy_init))
Definition: loader.cpp:36428
FLAG_UNIQUE
#define FLAG_UNIQUE
Definition: define.h:287
FLAG_OBJ_ORIGINAL
#define FLAG_OBJ_ORIGINAL
Definition: define.h:357
object::x
int16_t x
Definition: object.h:335
maps_saved_total
int maps_saved_total
Definition: logger.cpp:40
object::map
struct mapstruct * map
Definition: object.h:305
MoveType
unsigned char MoveType
Definition: define.h:417
guildjoin.ob
ob
Definition: guildjoin.py:42
shopitems::index
int index
Definition: map.h:299
SET_MAP_MOVE_ON
#define SET_MAP_MOVE_ON(M, X, Y, C)
Definition: map.h:202
CHECK_INV
@ CHECK_INV
Definition: object.h:174
CALLOC
#define CALLOC(x, y)
Definition: compat.h:31
map_path
void map_path(const char *map, int flags, char *pathname, size_t bufsize)
Definition: map.cpp:1166
map_layer_info
static const Map_Layer_Info map_layer_info[MAP_LAYERS]
Definition: map.cpp:63
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:48
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.cpp:101
typedata::name
const char * name
Definition: define.h:91
clean_object
void clean_object(object *op)
Definition: map.cpp:1590
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:92
load_object
int load_object(FILE *fp, object *op, int bufstate, int map_flags, bool artifact_init)
Definition: loader.cpp:38944
PROFILE_BEGIN
#define PROFILE_BEGIN(expr)
Definition: global.h:373
MAP_OVERLAY
#define MAP_OVERLAY
Definition: map.h:95
Ice.tmp
int tmp
Definition: Ice.py:207
typedata::name_pl
const char * name_pl
Definition: define.h:92
dump_map
void dump_map(const mapstruct *m)
Definition: map.cpp:245
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:233
FLAG_NO_MAGIC
#define FLAG_NO_MAGIC
Definition: define.h:276
blank_face
const Face * blank_face
Definition: image.cpp:36
P_NO_MAGIC
#define P_NO_MAGIC
Definition: map.h:225
TRANSPORT
@ TRANSPORT
Definition: object.h:113
LO_NEWFILE
#define LO_NEWFILE
Definition: loader.h:17
FLAG_BLOCKSVIEW
#define FLAG_BLOCKSVIEW
Definition: define.h:269
rv_vector::part
object * part
Definition: map.h:373
npc_dialog.filename
filename
Definition: npc_dialog.py:99
mapstruct::path
char path[HUGE_BUF]
Definition: map.h:353
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.cpp:4342
GET_MAP_FACE_OBJS
#define GET_MAP_FACE_OBJS(M, X, Y)
Definition: map.h:187
P_IS_ALIVE
#define P_IS_ALIVE
Definition: map.h:235
MSG_TYPE_MISC
#define MSG_TYPE_MISC
Definition: newclient.h:402
free_all_maps
void free_all_maps(void)
Definition: map.cpp:1954
buf
StringBuffer * buf
Definition: readable.cpp:1565
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
AB_NO_PASS
#define AB_NO_PASS
Definition: map.h:233
ihypot
int ihypot(int a, int b)
Definition: utils.cpp:570
MAP_LAYER_ITEM1
#define MAP_LAYER_ITEM1
Definition: map.h:43
Map_Layer_Info::honor_visibility
uint8_t honor_visibility
Definition: map.cpp:54
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
mapstruct::width
uint16_t width
Definition: map.h:335
MAP_STYLE
#define MAP_STYLE
Definition: map.h:94
SAVE_MODE_OVERLAY
#define SAVE_MODE_OVERLAY
Definition: map.h:118
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
INS_ABOVE_FLOOR_ONLY
#define INS_ABOVE_FLOOR_ONLY
Definition: object.h:581
rv_vector::distance_y
int distance_y
Definition: map.h:371
map_remove_unique_files
void map_remove_unique_files(const mapstruct *map)
Definition: map.cpp:2668
LO_NOREAD
#define LO_NOREAD
Definition: loader.h:18
typedata
Definition: define.h:89
save_objects
int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
Definition: map.cpp:715
PROFILE_END
#define PROFILE_END(var, expr)
Definition: global.h:378
object::y
int16_t y
Definition: object.h:335
m
static event_registration m
Definition: citylife.cpp:425
set_darkness_map
void set_darkness_map(mapstruct *m)
Definition: main.cpp:371
rv_vector::distance_x
int distance_x
Definition: map.h:370
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:126
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.cpp:76
apply_auto_fix
void apply_auto_fix(mapstruct *m)
Definition: main.cpp:258
MAP_LAYER_NO_PICK2
#define MAP_LAYER_NO_PICK2
Definition: map.h:42
MAP_DIFFICULTY
#define MAP_DIFFICULTY(m)
Definition: map.h:65
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
item.q
q
Definition: item.py:32
map_size
uint32_t map_size(mapstruct *m)
Definition: map.cpp:799
disinfect.map
map
Definition: disinfect.py:4
P_NEW_MAP
#define P_NEW_MAP
Definition: map.h:248
SAVE_ERROR_CLOSE
#define SAVE_ERROR_CLOSE
Definition: map.h:145
object_value_set_shared
bool object_value_set_shared(const object *op, sstring key)
Definition: object.cpp:4386
of_cancel
void of_cancel(OutputFile *of)
Definition: output_file.cpp:89
get_typedata
const typedata * get_typedata(int itemtype)
Definition: item.cpp:323
P_NO_ERROR
#define P_NO_ERROR
Definition: map.h:238
MSG_TYPE_ATTACK_NOKEY
#define MSG_TYPE_ATTACK_NOKEY
Definition: newclient.h:606
stats.h
check_inv_recursive
object * check_inv_recursive(object *op, const object *trig)
Definition: button.cpp:782
path_combine_and_normalize
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
Definition: path.cpp:172
load_unique_objects
static void load_unique_objects(mapstruct *m)
Definition: map.cpp:1349
archetype::clone
object clone
Definition: object.h:487
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
first_map
mapstruct * first_map
Definition: init.cpp:107
HEAD
#define HEAD(op)
Definition: object.h:607
clean_tmp_map
void clean_tmp_map(mapstruct *m)
Definition: map.cpp:1945
SAVE_ERROR_RCREATION
#define SAVE_ERROR_RCREATION
Definition: map.h:140
MAP_WHEN_RESET
#define MAP_WHEN_RESET(m)
Definition: map.h:62
change_map_light
int change_map_light(mapstruct *m, int change)
Definition: map.cpp:1986
object::move_type
MoveType move_type
Definition: object.h:436
ext_info_map
void void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Definition: main.cpp:334
python_init.path
path
Definition: python_init.py:8
mapfile_load_lowlevel
mapstruct * mapfile_load_lowlevel(const char *map, const char *pathname, int flags)
Definition: map.cpp:1176
object::face
const Face * face
Definition: object.h:341
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.cpp:2289
MAX_DARKNESS
#define MAX_DARKNESS
Definition: define.h:454
MSG_TYPE_ATTACK
#define MSG_TYPE_ATTACK
Definition: newclient.h:398
isqrt
int isqrt(int n)
Definition: utils.cpp:562
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
Definition: events.h:51
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:580
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
SET_MAP_FLAGS
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:159
remove_button_link
void remove_button_link(object *op)
Definition: button.cpp:693
MAP_LAYER_LIVING1
#define MAP_LAYER_LIVING1
Definition: map.h:46
shopitems::name_pl
const char * name_pl
Definition: map.h:295
MAP_LAYER_FLY1
#define MAP_LAYER_FLY1
Definition: map.h:48
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1592
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:190
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
MAP_DEFAULTRESET
#define MAP_DEFAULTRESET
Definition: config.h:427
free_map
void free_map(mapstruct *m)
Definition: map.cpp:1653
disinfect.count
int count
Definition: disinfect.py:7
level_exp
int64_t level_exp(int level, double expmul)
Definition: living.cpp:1874
free_all_objects
static void free_all_objects(mapstruct *m)
Definition: map.cpp:1606
archetype
Definition: object.h:483
P_PLAYER
#define P_PLAYER
Definition: map.h:234
sproto.h
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.cpp:2362
MapSpace
Definition: map.h:254
get_rangevector_from_mapcoord
int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval)
Definition: map.cpp:2590
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.cpp:2651
delete_map
void delete_map(mapstruct *m)
Definition: map.cpp:1699
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:409
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.cpp:479
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:231
SAVE_ERROR_NO_PATH
#define SAVE_ERROR_NO_PATH
Definition: map.h:143
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.cpp:2100
link_multipart_objects
static void link_multipart_objects(mapstruct *m)
Definition: map.cpp:575
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
get_typedata_by_name
const typedata * get_typedata_by_name(const char *name)
Definition: item.cpp:343
fatal
void fatal(enum fatal_error err)
Definition: utils.cpp:590
get_linked_map
mapstruct * get_linked_map(void)
Definition: map.cpp:776
seconds
long seconds(void)
Definition: time.cpp:348
MAP_WIDTH
#define MAP_WIDTH(m)
Definition: map.h:73
maps_loaded_total
int maps_loaded_total
Definition: logger.cpp:39
create_template_pathname
void create_template_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:145
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:247
MAX_BUF
#define MAX_BUF
Definition: define.h:35
INS_ON_TOP
#define INS_ON_TOP
Definition: object.h:583
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.cpp:222
object_new
object * object_new(void)
Definition: object.cpp:1273
create_overlay_pathname
void create_overlay_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:125
OB_MOVE_BLOCK
#define OB_MOVE_BLOCK(ob1, ob2)
Definition: define.h:423
shopitems::typenum
int typenum
Definition: map.h:296
set_map_reset_time
void set_map_reset_time(mapstruct *map)
Definition: map.cpp:2224
free_string
void free_string(sstring str)
Definition: shstr.cpp:280
SAVE_MODE_NORMAL
#define SAVE_MODE_NORMAL
Definition: map.h:116
Settings::playerdir
const char * playerdir
Definition: global.h:250
SAVE_ERROR_UCREATION
#define SAVE_ERROR_UCREATION
Definition: map.h:141
StringBuffer
Definition: stringbuffer.cpp:25
SET_MAP_MOVE_SLOW
#define SET_MAP_MOVE_SLOW(M, X, Y, C)
Definition: map.h:197
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
OUT_OF_REAL_MAP
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:215
find_dir_2
int find_dir_2(int x, int y)
Definition: object.cpp:3673
load_and_link_tiled_map
static mapstruct * load_and_link_tiled_map(mapstruct *orig_map, int tile_num)
Definition: map.cpp:2250
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
MAP_LAYER_NO_PICK1
#define MAP_LAYER_NO_PICK1
Definition: map.h:41
INS_MAP_LOAD
#define INS_MAP_LOAD
Definition: object.h:585
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
decay_objects
void decay_objects(mapstruct *m)
Definition: utils.cpp:175
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:251
Floor.t
t
Definition: Floor.py:62
Map_Layer_Info
Definition: map.cpp:52
load_map_header
static int load_map_header(FILE *fp, mapstruct *m)
Definition: map.cpp:989
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:193
shopitems::name
const char * name
Definition: map.h:294
Map_Layer_Info::high_layer
uint8_t high_layer
Definition: map.cpp:53
adjacent_map
static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy)
Definition: map.cpp:2445
Face::visibility
uint8_t visibility
Definition: face.h:16
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.cpp:300
item
Definition: item.py:1
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:237
mapstruct
Definition: map.h:313
create_pathname
char * create_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:104
msgbuf
static char msgbuf[HUGE_BUF]
Definition: loader.cpp:35880
give.op
op
Definition: give.py:33
autojail.value
value
Definition: autojail.py:6
MapSpace::flags
uint8_t flags
Definition: map.h:258
mapstruct::in_memory
uint32_t in_memory
Definition: map.h:333
rv_vector
Definition: map.h:368
update_buttons
void update_buttons(mapstruct *m)
Definition: button.cpp:227
MAP_SWAPPED
#define MAP_SWAPPED
Definition: map.h:127
objects
object * objects
Definition: object.cpp:294
shopitems
Definition: map.h:293
map_get_path
const char * map_get_path(const object *item)
Definition: map.cpp:2693
diamondslots.y
y
Definition: diamondslots.py:16
SET_MAP_MOVE_BLOCK
#define SET_MAP_MOVE_BLOCK(M, X, Y, C)
Definition: map.h:192
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.cpp:2628
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
map_path_unique
bool map_path_unique(const char *path)
Definition: map.cpp:2713
MAP_HEIGHT
#define MAP_HEIGHT(m)
Definition: map.h:75
save_object_in_sb
void save_object_in_sb(StringBuffer *sb, object *op, const int flag)
Definition: object.cpp:5307
MAP_ENTER_Y
#define MAP_ENTER_Y(m)
Definition: map.h:82
SAVE_ERROR_URENAME
#define SAVE_ERROR_URENAME
Definition: map.h:144
strip_endline
void strip_endline(char *buf)
Definition: utils.cpp:314
mapstruct::tile_map
mapstruct * tile_map[4]
Definition: map.h:352
typedata::number
int number
Definition: define.h:90
object_remove_from_active_list
void object_remove_from_active_list(object *op)
Definition: object.cpp:1392
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
mapstruct::spaces
MapSpace * spaces
Definition: map.h:343
S_IRUSR
#define S_IRUSR
Definition: win32.h:56
get_rangevector
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.cpp:2522
create-tower.tile
tile
Definition: create-tower.py:8
update_all_map_los
void update_all_map_los(mapstruct *map)
Definition: los.cpp:567
allocate_map
void allocate_map(mapstruct *m)
Definition: map.cpp:813
castle_read.key
key
Definition: castle_read.py:64
MAP_LAYER_FLY2
#define MAP_LAYER_FLY2
Definition: map.h:49
FMT64U
#define FMT64U
Definition: compat.h:17
SAVE_ERROR_OK
#define SAVE_ERROR_OK
Definition: map.h:139
loader.h
object_fix_multipart
void object_fix_multipart(object *tmp)
Definition: object.cpp:4681
S_IWOTH
#define S_IWOTH
Definition: win32.h:41
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.cpp:308
fix_container_multipart
static void fix_container_multipart(object *container)
Definition: map.cpp:534
MAP_ENTER_X
#define MAP_ENTER_X(m)
Definition: map.h:80
Settings::templatedir
const char * templatedir
Definition: global.h:254
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
EVENT_MAPREADY
#define EVENT_MAPREADY
Definition: events.h:49
MAP_FLUSH
#define MAP_FLUSH
Definition: map.h:91
GET_MAP_FLAGS
#define GET_MAP_FLAGS(M, X, Y)
Definition: map.h:157
DOOR
@ DOOR
Definition: object.h:131
object_sum_weight
signed long object_sum_weight(object *op)
Definition: object.cpp:568
FLAG_UNPAID
#define FLAG_UNPAID
Definition: define.h:236
MAP_LAYER_LIVING2
#define MAP_LAYER_LIVING2
Definition: map.h:47
LL_NORMAL
#define LL_NORMAL
Definition: loader.h:12
OB_TYPE_MOVE_BLOCK
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:432
S_IWGRP
#define S_IWGRP
Definition: win32.h:44
P_NO_CLERIC
#define P_NO_CLERIC
Definition: map.h:236
make_path_to_file
void make_path_to_file(const char *filename)
Definition: porting.cpp:164
save_map
int save_map(mapstruct *m, int flag)
Definition: map.cpp:1396
calculate_difficulty
int calculate_difficulty(mapstruct *m)
Definition: map.cpp:1888
FLAG_IS_LINKED
#define FLAG_IS_LINKED
Definition: define.h:315
mapstruct::next
mapstruct * next
Definition: map.h:314
object::stats
living stats
Definition: object.h:378
object::more
object * more
Definition: object.h:303
SET_MAP_PLAYER
#define SET_MAP_PLAYER(M, X, Y, C)
Definition: map.h:167
blocks_prayer
sstring blocks_prayer
Definition: init.cpp:126
Settings::tmpdir
const char * tmpdir
Definition: global.h:255
MAP_TIMEOUT
#define MAP_TIMEOUT(m)
Definition: map.h:66
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.cpp:1217
LO_REPEAT
#define LO_REPEAT
Definition: loader.h:15
parse_shop_string
static shopitems * parse_shop_string(const char *input_string, const mapstruct *map)
Definition: map.cpp:865
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
MAP_MAXRESET
#define MAP_MAXRESET
Definition: config.h:425
SAVE_FLAG_SAVE_UNPAID
#define SAVE_FLAG_SAVE_UNPAID
Definition: map.h:106
rv_vector::direction
int direction
Definition: map.h:372
SET_MAP_LIGHT
#define SET_MAP_LIGHT(M, X, Y, L)
Definition: map.h:164
rv_vector::distance
unsigned int distance
Definition: map.h:369
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
Definition: map.cpp:46
MAP_LOADING
#define MAP_LOADING
Definition: map.h:128
load_overlay_map
static int load_overlay_map(const char *filename, mapstruct *m)
Definition: map.cpp:1289
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
check_path
int check_path(const char *name, int prepend_dir)
Definition: map.cpp:201
altar_valkyrie.res
int res
Definition: altar_valkyrie.py:74
S_IRGRP
#define S_IRGRP
Definition: win32.h:53
dump_all_maps
void dump_all_maps(void)
Definition: map.cpp:268
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:32
load_objects
void load_objects(mapstruct *m, FILE *fp, int mapflags)
Definition: map.cpp:603
llevDebug
@ llevDebug
Definition: logger.h:13
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302
P_BLOCKSVIEW
#define P_BLOCKSVIEW
Definition: map.h:224
give.name
name
Definition: give.py:27
LL_MORE
#define LL_MORE
Definition: loader.h:11
Settings::uniquedir
const char * uniquedir
Definition: global.h:253
OutputFile
Definition: output_file.h:41
SET_MAP_MOVE_OFF
#define SET_MAP_MOVE_OFF(M, X, Y, C)
Definition: map.h:207
Settings::localdir
const char * localdir
Definition: global.h:249