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_ENTER_X(map) = 0;
792  MAP_ENTER_Y(map) = 0;
793  map->last_reset_time = 0;
794  return map;
795 }
796 
798 uint32_t map_size(mapstruct *m) {
799  return (uint32_t)m->width * (uint32_t)m->height;
800 }
801 
813  m->in_memory = MAP_IN_MEMORY;
814  /* Log this condition and free the storage. We could I suppose
815  * realloc, but if the caller is presuming the data will be intact,
816  * that is their poor assumption.
817  */
818  if (m->spaces) {
819  LOG(llevError, "allocate_map called with already allocated map (%s)\n", m->path);
820  free(m->spaces);
821  }
822 
823  m->spaces = static_cast<MapSpace *>(calloc(map_size(m), sizeof(MapSpace)));
824 
825  if (m->spaces == NULL)
827 }
828 
842 mapstruct *get_empty_map(int sizex, int sizey) {
844  m->width = sizex;
845  m->height = sizey;
846  m->in_memory = MAP_SWAPPED;
847  allocate_map(m);
848  return m;
849 }
850 
864 static shopitems *parse_shop_string(const char *input_string, const mapstruct *map) {
865  char *shop_string, *p, *q, *next_semicolon, *next_colon;
866  shopitems *items = NULL;
867  int i = 0, number_of_entries = 0;
868  const typedata *current_type;
869 
870  shop_string = strdup_local(input_string);
871  p = shop_string;
872  LOG(llevDebug, "parsing %s\n", input_string);
873  /* first we'll count the entries, we'll need that for allocating the array shortly */
874  while (p) {
875  p = strchr(p, ';');
876  number_of_entries++;
877  if (p)
878  p++;
879  }
880  p = shop_string;
881  strip_endline(p);
882  items = static_cast<shopitems *>(CALLOC(number_of_entries+1, sizeof(shopitems)));
883  /*
884  * The memset would always set at least one byte to zero,
885  * so a failed calloc would have segfaulted the program.
886  * Instead, check for a null and fail more gracefully.
887  */
888  if (!items)
890 
891  for (i = 0; i < number_of_entries; i++) {
892  if (!p) {
893  LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
894  break;
895  }
896  next_semicolon = strchr(p, ';');
897  next_colon = strchr(p, ':');
898  /* if there is a stregth specified, figure out what it is, we'll need it soon. */
899  if (next_colon && (!next_semicolon || next_colon < next_semicolon))
900  items[i].strength = atoi(strchr(p, ':')+1);
901 
902  if (isdigit(*p) || *p == '*') {
903  items[i].typenum = *p == '*' ? -1 : atoi(p);
904  current_type = get_typedata(items[i].typenum);
905  if (current_type) {
906  items[i].name = current_type->name;
907  items[i].name_pl = current_type->name_pl;
908  }
909  } else { /*we have a named type, let's figure out what it is */
910  q = strpbrk(p, ";:");
911  if (q)
912  *q = '\0';
913 
914  current_type = get_typedata_by_name(p);
915  if (current_type) {
916  items[i].name = current_type->name;
917  items[i].typenum = current_type->number;
918  items[i].name_pl = current_type->name_pl;
919  } else {
920  /* oh uh, something's wrong, let's free up this one, and try
921  * the next entry while we're at it, better print a warning */
922  LOG(llevError, "invalid type %s defined in shopitems for %s in string %s\n", p, map->name, input_string);
923  }
924  }
925  items[i].index = number_of_entries;
926  if (next_semicolon)
927  p = ++next_semicolon;
928  else
929  p = NULL;
930  }
931  free(shop_string);
932  return items;
933 }
934 
946 static void print_shop_string(mapstruct *m, char *output_string, int size) {
947  int i;
948  char tmp[MAX_BUF];
949 
950  output_string[0] = '\0';
951  for (i = 0; i < m->shopitems[0].index; i++) {
952  if (m->shopitems[i].typenum != -1) {
953  if (m->shopitems[i].strength) {
954  snprintf(tmp, sizeof(tmp), "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
955  } else
956  snprintf(tmp, sizeof(tmp), "%s;", m->shopitems[i].name);
957  } else {
958  if (m->shopitems[i].strength) {
959  snprintf(tmp, sizeof(tmp), "*:%d;", m->shopitems[i].strength);
960  } else
961  snprintf(tmp, sizeof(tmp), "*;");
962  }
963  snprintf(output_string+strlen(output_string), size-strlen(output_string), "%s", tmp);
964  }
965 
966  /* erase final ; else parsing back will lead to issues */
967  if (strlen(output_string) > 0) {
968  output_string[strlen(output_string) - 1] = '\0';
969  }
970 }
971 
988 static int load_map_header(FILE *fp, mapstruct *m) {
989  char buf[HUGE_BUF], *key = NULL, *value;
990 
991  m->width = m->height = 0;
992  while (fgets(buf, sizeof(buf), fp) != NULL) {
993  char *p;
994 
995  p = strchr(buf, '\n');
996  if (p == NULL) {
997  LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf);
998  return 1;
999  }
1000  *p = '\0';
1001 
1002  key = buf;
1003  while (isspace(*key))
1004  key++;
1005  if (*key == 0)
1006  continue; /* empty line */
1007  value = strchr(key, ' ');
1008  if (value) {
1009  *value = 0;
1010  value++;
1011  while (isspace(*value)) {
1012  value++;
1013  if (*value == '\0') {
1014  /* Nothing but spaces. */
1015  value = NULL;
1016  break;
1017  }
1018  }
1019  }
1020 
1021  /* key is the field name, value is what it should be set
1022  * to. We've already done the work to null terminate key,
1023  * and strip off any leading spaces for both of these.
1024  * We have not touched the newline at the end of the line -
1025  * these are needed for some values. the end pointer
1026  * points to the first of the newlines.
1027  * value could be NULL! It would be easy enough to just point
1028  * this to "" to prevent cores, but that would let more errors slide
1029  * through.
1030  *
1031  * First check for entries that do not use the value parameter, then
1032  * validate that value is given and check for the remaining entries
1033  * that use the parameter.
1034  */
1035 
1036  if (!strcmp(key, "msg")) {
1037  char msgbuf[HUGE_BUF];
1038  int msgpos = 0;
1039 
1040  while (fgets(buf, sizeof(buf), fp) != NULL) {
1041  if (!strcmp(buf, "endmsg\n"))
1042  break;
1043  else {
1044  snprintf(msgbuf+msgpos, sizeof(msgbuf)-msgpos, "%s", buf);
1045  msgpos += strlen(buf);
1046  }
1047  }
1048  /* There are lots of maps that have empty messages (eg, msg/endmsg
1049  * with nothing between). There is no reason in those cases to
1050  * keep the empty message. Also, msgbuf contains garbage data
1051  * when msgpos is zero, so copying it results in crashes
1052  */
1053  if (msgpos != 0) {
1054  /* When loading eg an overlay, message is already set, so free() current one. */
1055  free(m->msg);
1056  m->msg = strdup_local(msgbuf);
1057  }
1058  } else if (!strcmp(key, "maplore")) {
1059  char maplorebuf[HUGE_BUF];
1060  size_t maplorepos = 0;
1061 
1062  while (fgets(buf, HUGE_BUF-1, fp) != NULL) {
1063  if (!strcmp(buf, "endmaplore\n"))
1064  break;
1065  else {
1066  if (maplorepos >= sizeof(maplorebuf)) {
1067  LOG(llevError, "Map lore exceeds buffer length\n");
1068  return 1;
1069  }
1070  snprintf(maplorebuf+maplorepos, sizeof(maplorebuf)-maplorepos, "%s", buf);
1071  maplorepos += strlen(buf);
1072  }
1073  }
1074  if (maplorepos != 0)
1075  m->maplore = strdup_local(maplorebuf);
1076  } else if (!strcmp(key, "end")) {
1077  break;
1078  } else if (value == NULL) {
1079  LOG(llevError, "Got '%s' line without parameter in map header\n", key);
1080  } else if (!strcmp(key, "arch")) {
1081  /* This is an oddity, but not something we care about much. */
1082  if (strcmp(value, "map")) {
1083  LOG(llevError, "load_map_header: expected 'arch map': check line endings?\n");
1084  return 1;
1085  }
1086  } else if (!strcmp(key, "name")) {
1087  /* When loading eg an overlay, the name is already set, so free() current one. */
1088  free(m->name);
1089  m->name = strdup_local(value);
1090  /* first strcmp value on these are old names supported
1091  * for compatibility reasons. The new values (second) are
1092  * what really should be used.
1093  */
1094  } else if (!strcmp(key, "enter_x")) {
1095  m->enter_x = atoi(value);
1096  } else if (!strcmp(key, "enter_y")) {
1097  m->enter_y = atoi(value);
1098  } else if (!strcmp(key, "width")) {
1099  m->width = atoi(value);
1100  } else if (!strcmp(key, "height")) {
1101  m->height = atoi(value);
1102  } else if (!strcmp(key, "reset_timeout")) {
1103  m->reset_timeout = atoi(value);
1104  } else if (!strcmp(key, "swap_time")) {
1105  // deprecated and ignored
1106  } else if (!strcmp(key, "difficulty")) {
1107  m->difficulty = atoi(value);
1108  } else if (!strcmp(key, "darkness")) {
1109  m->darkness = atoi(value);
1110  } else if (!strcmp(key, "fixed_resettime")) {
1111  m->fixed_resettime = atoi(value);
1112  } else if (!strcmp(key, "unique")) {
1113  m->unique = atoi(value);
1114  } else if (!strcmp(key, "template")) {
1115  m->is_template = atoi(value);
1116  } else if (!strcmp(key, "region")) {
1117  m->region = get_region_by_name(value);
1118  } else if (!strcmp(key, "shopitems")) {
1119  m->shopitems = parse_shop_string(value, m);
1120  } else if (!strcmp(key, "shopgreed")) {
1121  m->shopgreed = atof(value);
1122  } else if (!strcmp(key, "shopmin")) {
1123  m->shopmin = atol(value);
1124  } else if (!strcmp(key, "shopmax")) {
1125  m->shopmax = atol(value);
1126  } else if (!strcmp(key, "shoprace")) {
1127  m->shoprace = strdup_local(value);
1128  } else if (!strcmp(key, "outdoor")) {
1129  m->outdoor = atoi(value);
1130  } else if (!strcmp(key, "nosmooth")) {
1131  m->nosmooth = atoi(value);
1132  } else if (!strcmp(key, "first_load")) {
1133  m->last_reset_time = atoi(value);
1134  } else if (!strncmp(key, "tile_path_", 10)) {
1135  int tile = atoi(key+10);
1136 
1137  if (tile < 1 || tile > 4) {
1138  LOG(llevError, "load_map_header: tile location %d out of bounds (%s)\n", tile, m->path);
1139  } else {
1140  if (m->tile_path[tile-1]) {
1141  LOG(llevError, "load_map_header: tile location %d duplicated (%s)\n", tile, m->path);
1142  free(m->tile_path[tile-1]);
1143  }
1144  m->tile_path[tile-1] = strdup_local(value);
1145  } /* end if tile direction (in)valid */
1146  } else if (!strcmp(key, "background_music")) {
1147  m->background_music = strdup_local(value);
1148  } else if (!strcmp(key, "reset_group")) {
1149  m->reset_group = add_string(value);
1150  } else {
1151  LOG(llevError, "Got unknown value in map header: %s %s\n", key, value);
1152  }
1153  }
1154  if ((m->width == 0) || (m->height == 0)) {
1155  LOG(llevError, "Map width or height not specified\n");
1156  return 1;
1157  }
1158  if (!key || strcmp(key, "end")) {
1159  LOG(llevError, "Got premature eof on map header!\n");
1160  return 1;
1161  }
1162  return 0;
1163 }
1164 
1165 void map_path(const char *map, int flags, char *pathname, size_t bufsize) {
1166  if (flags&MAP_PLAYER_UNIQUE) {
1167  snprintf(pathname, bufsize, "%s/%s/%s", settings.localdir, settings.playerdir, map+1);
1168  }
1169  else if (flags&MAP_OVERLAY)
1170  create_overlay_pathname(map, pathname, bufsize);
1171  else
1172  create_pathname(map, pathname, bufsize);
1173 }
1174 
1175 mapstruct *mapfile_load_lowlevel(const char *map, const char *pathname, int flags) {
1176  FILE *fp;
1177  if ((fp = fopen(pathname, "r")) == NULL) {
1179  "Can't open %s: %s\n", pathname, strerror(errno));
1180  return NULL;
1181  }
1182 
1183  mapstruct *m = get_linked_map();
1184  safe_strncpy(m->path, map, HUGE_BUF);
1185  if (load_map_header(fp, m)) {
1186  LOG(llevError, "Error loading map header for %s, flags=%d\n", map, flags);
1187  delete_map(m);
1188  fclose(fp);
1189  return NULL;
1190  }
1191 
1192  allocate_map(m);
1193 
1194  m->in_memory = MAP_LOADING;
1195  load_objects(m, fp, flags & MAP_STYLE);
1196  fclose(fp);
1197  m->in_memory = MAP_IN_MEMORY;
1198  return m;
1199 }
1200 
1216 mapstruct *mapfile_load(const char *map, int flags) {
1217  mapstruct *m;
1218  PROFILE_BEGIN();
1219  char pathname[MAX_BUF];
1220  map_path(map, flags, pathname, sizeof(pathname));
1221  m = mapfile_load_lowlevel(map, pathname, flags);
1222  if (!m) {
1223  return NULL;
1224  }
1225  if (!MAP_DIFFICULTY(m) && (!(flags & MAP_NO_DIFFICULTY)))
1228 
1229  /* In case other objects press some buttons down */
1230  update_buttons(m);
1231 
1233 
1234  if (!(flags & MAP_STYLE))
1235  apply_auto_fix(m); /* Chests which open as default */
1236 
1237  PROFILE_END(diff,
1238  LOG(llevDebug, "mapfile_load on %s" " took %ld us\n", map, diff));
1239 
1241  return (m);
1242 }
1243 
1253  FILE *fp;
1254 
1255  if (!m->tmpname) {
1256  LOG(llevError, "No temporary filename for map %s\n", m->path);
1257  return 1;
1258  }
1259 
1260  if ((fp = fopen(m->tmpname, "r")) == NULL) {
1261  LOG(llevError, "Cannot open %s: %s\n", m->tmpname, strerror(errno));
1262  return 2;
1263  }
1264 
1265  if (load_map_header(fp, m)) {
1266  LOG(llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1267  fclose(fp);
1268  return 3;
1269  }
1270  allocate_map(m);
1271 
1272  m->in_memory = MAP_LOADING;
1273  load_objects(m, fp, 0);
1274  fclose(fp);
1275  m->in_memory = MAP_IN_MEMORY;
1276  return 0;
1277 }
1278 
1288 static int load_overlay_map(const char *filename, mapstruct *m) {
1289  FILE *fp;
1290  char pathname[MAX_BUF];
1291 
1293 
1294  if ((fp = fopen(pathname, "r")) == NULL) {
1295  /* nothing bad to not having an overlay */
1296  return 0;
1297  }
1298 
1299  if (load_map_header(fp, m)) {
1300  LOG(llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1301  fclose(fp);
1302  return 1;
1303  }
1304  /*allocate_map(m);*/
1305 
1306  m->in_memory = MAP_LOADING;
1307  load_objects(m, fp, MAP_OVERLAY);
1308  fclose(fp);
1309  m->in_memory = MAP_IN_MEMORY;
1310  return 0;
1311 }
1312 
1313 /******************************************************************************
1314  * This is the start of unique map handling code
1315  *****************************************************************************/
1316 
1324  int i, j, unique = 0;
1325 
1326  for (i = 0; i < MAP_WIDTH(m); i++)
1327  for (j = 0; j < MAP_HEIGHT(m); j++) {
1328  unique = 0;
1329  FOR_MAP_PREPARE(m, i, j, op) {
1331  unique = 1;
1332  if (op->head == NULL && (QUERY_FLAG(op, FLAG_UNIQUE) || unique)) {
1333  clean_object(op);
1336  object_remove(op);
1338  }
1339  } FOR_MAP_FINISH();
1340  }
1341 }
1342 
1349  FILE *fp;
1350  int count;
1351  char name[MAX_BUF], firstname[sizeof(name) + 4];
1352 
1353  create_items_path(m->path, name, MAX_BUF);
1354  for (count = 0; count < 10; count++) {
1355  snprintf(firstname, sizeof(firstname), "%s.v%02d", name, count);
1356  if (!access(firstname, R_OK))
1357  break;
1358  }
1359  /* If we get here, we did not find any map */
1360  if (count == 10)
1361  return;
1362 
1363  if ((fp = fopen(firstname, "r")) == NULL) {
1364  /* There is no expectation that every map will have unique items, but this
1365  * is debug output, so leave it in.
1366  */
1367  LOG(llevDebug, "Can't open unique items file for %s\n", name);
1368  return;
1369  }
1370 
1371  m->in_memory = MAP_LOADING;
1372  if (m->tmpname == NULL) /* if we have loaded unique items from */
1373  delete_unique_items(m); /* original map before, don't duplicate them */
1374  load_object(fp, NULL, LO_NOREAD, 0, false);
1375  load_objects(m, fp, 0);
1376  fclose(fp);
1377  m->in_memory = MAP_IN_MEMORY;
1378 }
1379 
1395 int save_map(mapstruct *m, int flag) {
1396  FILE *fp, *fp2;
1397  OutputFile of, of2;
1398  char filename[MAX_BUF], shop[MAX_BUF];
1399  int i, res;
1400 
1401  if (flag && !*m->path) {
1402  LOG(llevError, "Tried to save map without path.\n");
1403  return SAVE_ERROR_NO_PATH;
1404  }
1405 
1406  PROFILE_BEGIN();
1407 
1408  if (flag != SAVE_MODE_NORMAL || (m->unique) || (m->is_template)) {
1409  if (!m->unique && !m->is_template) { /* flag is set */
1410  if (flag == SAVE_MODE_OVERLAY)
1412  else
1413  create_pathname(m->path, filename, MAX_BUF);
1414  } else {
1415  if (m->path[0] != '~') {
1416  LOG(llevError,
1417  "Cannot save unique map '%s' outside of LOCALDIR. Check "
1418  "that all exits to '%s' have FLAG_UNIQUE set correctly.\n",
1419  m->path, m->path);
1420  return SAVE_ERROR_UCREATION;
1421  }
1422  snprintf(filename, sizeof(filename), "%s/%s/%s", settings.localdir, settings.playerdir, m->path+1);
1423  }
1424 
1426  } else {
1427  if (!m->tmpname)
1428  m->tmpname = tempnam(settings.tmpdir, NULL);
1429  strlcpy(filename, m->tmpname, sizeof(filename));
1430  }
1431  m->in_memory = MAP_SAVING;
1432 
1433  fp = of_open(&of, filename);
1434  if (fp == NULL)
1435  return SAVE_ERROR_RCREATION;
1436 
1437  /* legacy */
1438  fprintf(fp, "arch map\n");
1439  if (m->name)
1440  fprintf(fp, "name %s\n", m->name);
1441  if (m->reset_timeout)
1442  fprintf(fp, "reset_timeout %u\n", m->reset_timeout);
1443  if (m->fixed_resettime)
1444  fprintf(fp, "fixed_resettime %d\n", m->fixed_resettime);
1445  /* we unfortunately have no idea if this is a value the creator set
1446  * or a difficulty value we generated when the map was first loaded
1447  */
1448  if (m->difficulty)
1449  fprintf(fp, "difficulty %d\n", m->difficulty);
1450  if (m->region)
1451  fprintf(fp, "region %s\n", m->region->name);
1452  if (m->shopitems) {
1453  print_shop_string(m, shop, sizeof(shop));
1454  fprintf(fp, "shopitems %s\n", shop);
1455  }
1456  if (m->shopgreed)
1457  fprintf(fp, "shopgreed %f\n", m->shopgreed);
1458  if (m->shopmin)
1459  fprintf(fp, "shopmin %" FMT64U "\n", m->shopmin);
1460  if (m->shopmax)
1461  fprintf(fp, "shopmax %" FMT64U "\n", m->shopmax);
1462  if (m->shoprace)
1463  fprintf(fp, "shoprace %s\n", m->shoprace);
1464  if (m->darkness)
1465  fprintf(fp, "darkness %d\n", m->darkness);
1466  if (m->width)
1467  fprintf(fp, "width %d\n", m->width);
1468  if (m->height)
1469  fprintf(fp, "height %d\n", m->height);
1470  if (m->enter_x)
1471  fprintf(fp, "enter_x %d\n", m->enter_x);
1472  if (m->enter_y)
1473  fprintf(fp, "enter_y %d\n", m->enter_y);
1474  if (m->msg)
1475  fprintf(fp, "msg\n%sendmsg\n", m->msg);
1476  if (m->maplore)
1477  fprintf(fp, "maplore\n%sendmaplore\n", m->maplore);
1478  if (m->unique)
1479  fprintf(fp, "unique %d\n", m->unique);
1480  if (m->is_template)
1481  fprintf(fp, "template %d\n", m->is_template);
1482  if (m->outdoor)
1483  fprintf(fp, "outdoor %d\n", m->outdoor);
1484  if (m->nosmooth)
1485  fprintf(fp, "nosmooth %d\n", m->nosmooth);
1486  if (m->last_reset_time)
1487  fprintf(fp, "first_load %ld\n", m->last_reset_time);
1488  if (m->background_music)
1489  fprintf(fp, "background_music %s\n", m->background_music);
1490  if (m->reset_group)
1491  fprintf(fp, "reset_group %s\n", m->reset_group);
1492 
1493  /* Save any tiling information, except on overlays */
1494  if (flag != SAVE_MODE_OVERLAY)
1495  for (i = 0; i < 4; i++)
1496  if (m->tile_path[i])
1497  fprintf(fp, "tile_path_%d %s\n", i+1, m->tile_path[i]);
1498 
1499  fprintf(fp, "end\n");
1500 
1501  /* In the game save unique items in the different file, but
1502  * in the editor save them to the normal map file.
1503  * If unique map, save files in the proper destination (set by
1504  * player)
1505  */
1506  if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->is_template) {
1507  char name[MAX_BUF], final_unique[sizeof(name) + 4];
1508 
1509  create_items_path(m->path, name, MAX_BUF);
1510  snprintf(final_unique, sizeof(final_unique), "%s.v00", name);
1511  fp2 = of_open(&of2, final_unique);
1512  if (fp2 == NULL) {
1513  of_cancel(&of);
1514  return SAVE_ERROR_UCREATION;
1515  }
1516  if (flag == SAVE_MODE_OVERLAY) {
1517  /* SO_FLAG_NO_REMOVE is non destructive save, so map is still valid. */
1518  res = save_objects(m, fp, fp2, SAVE_FLAG_NO_REMOVE);
1519  if (res < 0) {
1520  LOG(llevError, "Save error during object save: %d\n", res);
1521  of_cancel(&of);
1522  of_cancel(&of2);
1523  return res;
1524  }
1525  m->in_memory = MAP_IN_MEMORY;
1526  } else {
1527  res = save_objects(m, fp, fp2, 0);
1528  if (res < 0) {
1529  LOG(llevError, "Save error during object save: %d\n", res);
1530  of_cancel(&of);
1531  of_cancel(&of2);
1532  return res;
1533  }
1535  }
1536  if (ftell(fp2) == 0) {
1537  of_cancel(&of2);
1538  /* If there are no unique items left on the map, we need to
1539  * unlink the original unique map so that the unique
1540  * items don't show up again.
1541  */
1542  unlink(final_unique);
1543  } else {
1544  if (!of_close(&of2)) {
1545  of_cancel(&of);
1546  return SAVE_ERROR_URENAME;
1547  }
1548 
1549  if (chmod(final_unique, SAVE_MODE) != 0) {
1550  LOG(llevError, "Could not set permissions on '%s'\n",
1551  final_unique);
1552  }
1553  }
1554  } else { /* save same file when not playing, like in editor */
1555  res = save_objects(m, fp, fp, 0);
1556  if (res < 0) {
1557  LOG(llevError, "Save error during object save: %d\n", res);
1558  of_cancel(&of);
1559  return res;
1560  }
1562  }
1563 
1564  if (!of_close(&of))
1565  return SAVE_ERROR_CLOSE;
1566 
1567  if (chmod(filename, SAVE_MODE) != 0) {
1568  LOG(llevError, "Could not set permissions on '%s'\n", filename);
1569  }
1570 
1571  PROFILE_END(diff,
1572  LOG(llevDebug, "save_map on %s" " took %ld us\n", m->path, diff));
1573 
1574  maps_saved_total++;
1575  return SAVE_ERROR_OK;
1576 }
1577 
1587 void clean_object(object *op) {
1588  FOR_INV_PREPARE(op, tmp) {
1589  clean_object(tmp);
1592  object_remove(tmp);
1594  } FOR_INV_FINISH();
1595 }
1596 
1604  int i, j;
1605  object *op;
1606 
1607  for (i = 0; i < MAP_WIDTH(m); i++)
1608  for (j = 0; j < MAP_HEIGHT(m); j++) {
1609  object *previous_obj = NULL;
1610 
1611  while ((op = GET_MAP_OB(m, i, j)) != NULL) {
1612  if (op == previous_obj) {
1613  LOG(llevDebug, "free_all_objects: Link error, bailing out.\n");
1614  break;
1615  }
1616  previous_obj = op;
1617  op = HEAD(op);
1618 
1619  /* If the map isn't in memory, object_free_drop_inventory() will remove and
1620  * free objects in op's inventory. So let it do the job.
1621  */
1622  if (m->in_memory == MAP_IN_MEMORY)
1623  clean_object(op);
1624  object_remove(op);
1626  }
1627  }
1628 #ifdef MANY_CORES
1629  /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1630  * an item on that map was not saved - look for that condition and die as appropriate -
1631  * this leaves more of the map data intact for better debugging.
1632  */
1633  for (op = objects; op != NULL; op = op->next) {
1634  if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1635  LOG(llevError, "free_all_objects: object %s still on map after it should have been freed\n", op->name);
1636  abort();
1637  }
1638  }
1639 #endif
1640 }
1641 
1651  int i;
1652 
1653  if (!m->in_memory) {
1654  LOG(llevError, "Trying to free freed map.\n");
1655  return;
1656  }
1657 
1659 
1660  if (m->spaces)
1662  if (m->name)
1663  FREE_AND_CLEAR(m->name);
1664  if (m->spaces)
1665  FREE_AND_CLEAR(m->spaces);
1666  if (m->msg)
1667  FREE_AND_CLEAR(m->msg);
1668  if (m->maplore)
1669  FREE_AND_CLEAR(m->maplore);
1670  if (m->shopitems)
1671  FREE_AND_CLEAR(m->shopitems);
1672  if (m->shoprace)
1673  FREE_AND_CLEAR(m->shoprace);
1674  if (m->background_music)
1675  FREE_AND_CLEAR(m->background_music);
1676  if (m->buttons)
1677  free_objectlinkpt(m->buttons);
1678  m->buttons = NULL;
1679  for (i = 0; i < 4; i++) {
1680  if (m->tile_path[i])
1681  FREE_AND_CLEAR(m->tile_path[i]);
1682  m->tile_map[i] = NULL;
1683  }
1684  m->in_memory = MAP_SWAPPED;
1685 }
1686 
1697  mapstruct *tmp, *last;
1698  int i;
1699 
1700  if (!m)
1701  return;
1702  if (m->in_memory == MAP_IN_MEMORY) {
1703  /* change to MAP_SAVING, even though we are not,
1704  * so that object_remove() doesn't do as much work.
1705  */
1706  m->in_memory = MAP_SAVING;
1707  free_map(m);
1708  }
1709  /* move this out of free_map, since tmpname can still be needed if
1710  * the map is swapped out.
1711  */
1712  free(m->tmpname);
1713  m->tmpname = NULL;
1714  FREE_AND_CLEAR_STR_IF(m->reset_group);
1715  last = NULL;
1716  /* We need to look through all the maps and see if any maps
1717  * are pointing at this one for tiling information. Since
1718  * tiling can be assymetric, we just can not look to see which
1719  * maps this map tiles with and clears those.
1720  */
1721  for (tmp = first_map; tmp != NULL; tmp = tmp->next) {
1722  if (tmp->next == m)
1723  last = tmp;
1724 
1725  /* This should hopefully get unrolled on a decent compiler */
1726  for (i = 0; i < 4; i++)
1727  if (tmp->tile_map[i] == m)
1728  tmp->tile_map[i] = NULL;
1729  }
1730 
1731  /* If last is null, then this should be the first map in the list */
1732  if (!last) {
1733  if (m == first_map)
1734  first_map = m->next;
1735  else
1736  /* m->path is a static char, so should hopefully still have
1737  * some useful data in it.
1738  */
1739  LOG(llevError, "delete_map: Unable to find map %s in list\n", m->path);
1740  } else
1741  last->next = m->next;
1742 
1743  free(m);
1744 }
1745 
1751  // Right now this just sets the fixed swap time.
1752  m->timeout = MAP_MINTIMEOUT;
1753 }
1754 
1768 mapstruct *ready_map_name(const char *name, int flags) {
1769  mapstruct *m;
1770 
1771  if (!name)
1772  return (NULL);
1773 
1774  /* Have we been at this level before? */
1775  m = has_been_loaded(name);
1776 
1777  /* Map is good to go, so just return it */
1778  if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) {
1779  map_reset_swap(m);
1780  return m;
1781  }
1782 
1783  /* Rewrite old paths starting with LOCALDIR/PLAYERDIR to new '~' paths. */
1784  char buf[MAX_BUF], buf2[MAX_BUF];
1785  snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, settings.playerdir);
1786  if (strncmp(name, buf, strlen(buf)) == 0) {
1787  snprintf(buf2, sizeof(buf2), "~%s", name+strlen(buf)+1);
1788  name = buf2;
1789  }
1790 
1791  /* Paths starting with '~' are unique. */
1792  if (name[0] == '~') {
1794  }
1795 
1796  /* unique maps always get loaded from their original location, and never
1797  * a temp location. Likewise, if map_flush is set, or we have never loaded
1798  * this map, load it now. I removed the reset checking from here -
1799  * it seems the probability of a player trying to enter a map that should
1800  * reset but hasn't yet is quite low, and removing that makes this function
1801  * a bit cleaner (and players probably shouldn't rely on exact timing for
1802  * resets in any case - if they really care, they should use the 'maps command.
1803  */
1804  if ((flags&(MAP_FLUSH|MAP_PLAYER_UNIQUE)) || !m) {
1805  /* first visit or time to reset */
1806  if (m) {
1807  clean_tmp_map(m); /* Doesn't make much difference */
1808  delete_map(m);
1809  }
1810 
1812  if (m == NULL) return NULL;
1813 
1814  /* If a player unique map, no extra unique object file to load.
1815  * if from the editor, likewise.
1816  */
1819 
1821  if (load_overlay_map(name, m) != 0) {
1822  delete_map(m);
1823  m = mapfile_load(name, 0);
1824  if (m == NULL) {
1825  /* Really, this map is bad :( */
1826  return NULL;
1827  }
1828  }
1829  }
1830  } else {
1831  /* If in this loop, we found a temporary map, so load it up. */
1832 
1833  if (load_temporary_map(m) != 0) {
1834  /*
1835  * There was a failure loading the temporary map, fall back to original one.
1836  * load_temporary_map() already logged the error.
1837  */
1838  delete_map(m);
1839  m = mapfile_load(name, 0);
1840  if (m == NULL) {
1841  /* Really, this map is bad :( */
1842  return NULL;
1843  }
1844  }
1846 
1847  clean_tmp_map(m);
1848  m->in_memory = MAP_IN_MEMORY;
1849  /* tempnam() on sun systems (probably others) uses malloc
1850  * to allocated space for the string. Free it here.
1851  * In some cases, load_temporary_map above won't find the
1852  * temporary map, and so has reloaded a new map. If that
1853  * is the case, tmpname is now null
1854  */
1855  free(m->tmpname);
1856  m->tmpname = NULL;
1857  /* It's going to be saved anew anyway */
1858  }
1859 
1860  /* Below here is stuff common to both first time loaded maps and
1861  * temp maps.
1862  */
1863 
1864  decay_objects(m); /* start the decay */
1865 
1866  if (m->outdoor)
1868 
1869  if (!(flags&(MAP_FLUSH))) {
1870  if (m->last_reset_time == 0) {
1871  m->last_reset_time = seconds();
1872  }
1873  }
1874 
1875  map_reset_swap(m);
1877 
1878  return m;
1879 }
1880 
1897  archetype *at;
1898  int x, y;
1899  int diff = 0;
1900  int i;
1901  int64_t exp_pr_sq, total_exp = 0;
1902 
1903  if (MAP_DIFFICULTY(m)) {
1904  return MAP_DIFFICULTY(m);
1905  }
1906 
1907  for (x = 0; x < MAP_WIDTH(m); x++)
1908  for (y = 0; y < MAP_HEIGHT(m); y++)
1909  FOR_MAP_PREPARE(m, x, y, op) {
1910  if (QUERY_FLAG(op, FLAG_MONSTER))
1911  total_exp += op->stats.exp;
1913  total_exp += op->stats.exp;
1914  // If we have an other_arch on our generator, just use that.
1915  // FIXME: Figure out what to do if we are doing template generation from inventory.
1916  at = op->other_arch ? op->other_arch : NULL;
1917  if (at != NULL) {
1918  // Make sure we can't set off a null pointer dereference in atoi().
1919  const char *val = object_get_value(op, "generator_limit");
1920  int lim = atoi(val ? val : "0");
1921  // We assume, on average, the generator will generate half its contents.
1922  if (!lim || lim >= 16)
1923  total_exp += at->clone.stats.exp*8;
1924  else
1925  total_exp += at->clone.stats.exp*(lim/2);
1926  }
1927  }
1928  } FOR_MAP_FINISH();
1929  // Used to be multiplied by 1000, but this undershot horribly
1930  // once I fixed the calculation for generators.
1931  // I'm trying out some exponentiation, since linear scaling
1932  // seems to overshoot low-level maps and undershoot high-level maps.
1933  // I also feel comfortable, knowing that generators return
1934  // sensible values, to up the max diff this calculates from 20 to 25.
1935  // - Neila Hawkins 2021-03-04
1936  exp_pr_sq = (pow(total_exp, 1.75))/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1);
1937  diff = 25;
1938  for (i = 1; i < 25; i++)
1939  if (exp_pr_sq <= level_exp(i, 1.0)) {
1940  diff = i;
1941  break;
1942  }
1943 
1944  return diff;
1945 }
1946 
1954  if (m->tmpname == NULL)
1955  return;
1956  (void)unlink(m->tmpname);
1957 }
1958 
1962 void free_all_maps(void) {
1963  int real_maps = 0;
1964 
1965  while (first_map) {
1966  /* I think some of the callers above before it gets here set this to be
1967  * saving, but we still want to free this data
1968  */
1969  if (first_map->in_memory == MAP_SAVING)
1972  real_maps++;
1973  }
1974  LOG(llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1975 }
1976 
1994 int change_map_light(mapstruct *m, int change) {
1995  int new_level = m->darkness+change;
1996 
1997  /* Nothing to do */
1998  if (!change
1999  || (new_level <= 0 && m->darkness == 0)
2000  || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) {
2001  return 0;
2002  }
2003 
2004  /* inform all players on the map */
2005  if (change > 0)
2006  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes darker.");
2007  else
2008  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes brighter.");
2009 
2010  /* Do extra checking. since m->darkness is a unsigned value,
2011  * we need to be extra careful about negative values.
2012  * In general, the checks below are only needed if change
2013  * is not +/-1
2014  */
2015  if (new_level < 0)
2016  m->darkness = 0;
2017  else if (new_level >= MAX_DARKNESS)
2018  m->darkness = MAX_DARKNESS;
2019  else
2020  m->darkness = new_level;
2021 
2022  /* All clients need to get re-updated for the change */
2024  return 1;
2025 }
2026 
2049 static inline void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) {
2050  int l, l1;
2051  object *tmp;
2052 
2053  for (l = low_layer; l <= high_layer; l++) {
2054  if (!layers[l]) {
2055  /* found an empty spot. now, we want to make sure
2056  * highest visibility at top, etc.
2057  */
2058  layers[l] = ob;
2059  if (!honor_visibility)
2060  return;
2061 
2062  /* This is basically a mini bubble sort. Only swap
2063  * position if the lower face has greater (not equal)
2064  * visibility - map stacking is secondary consideration here.
2065  */
2066  for (l1 = (l-1); l1 >= low_layer; l1--) {
2067  if (layers[l1]->face->visibility > layers[l1+1]->face->visibility) {
2068  tmp = layers[l1+1];
2069  layers[l1+1] = layers[l1];
2070  layers[l1] = tmp;
2071  }
2072  }
2073  /* Nothing more to do - face inserted */
2074  return;
2075  }
2076  }
2077  /* If we get here, all the layers have an object..
2078  */
2079  if (!honor_visibility) {
2080  /* Basically, in this case, it is pure stacking logic, so
2081  * new object goes on the top.
2082  */
2083  for (l = low_layer; l < high_layer; l++)
2084  layers[l] = layers[l+1];
2085  layers[high_layer] = ob;
2086  /* If this object doesn't have higher visibility than
2087  * the lowest object, no reason to go further.
2088  */
2089  } else if (ob->face->visibility >= layers[low_layer]->face->visibility) {
2090  /*
2091  * Start at the top (highest visibility) layer and work down.
2092  * once this face exceed that of the layer, push down those
2093  * other layers, and then replace the layer with our object.
2094  */
2095  for (l = high_layer; l >= low_layer; l--) {
2096  if (ob->face->visibility >= layers[l]->face->visibility) {
2097  for (l1 = low_layer; l1 < l; l1++)
2098  layers[l1] = layers[l1+1];
2099  layers[l] = ob;
2100  break;
2101  }
2102  }
2103  }
2104 }
2105 
2118 void update_position(mapstruct *m, int x, int y) {
2119  object *player = NULL;
2120  uint8_t flags = 0, oldflags, light = 0;
2121  object *layers[MAP_LAYERS];
2122 
2123  MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2124 
2125  oldflags = GET_MAP_FLAGS(m, x, y);
2126  if (!(oldflags&P_NEED_UPDATE)) {
2127  LOG(llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
2128  return;
2129  }
2130 
2131  memset(layers, 0, MAP_LAYERS*sizeof(object *));
2132 
2133  FOR_MAP_PREPARE(m, x, y, tmp) {
2134  /* DMs just don't do anything when hidden, including no light. */
2135  if (QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden)
2136  continue;
2137 
2138  if (tmp->type == PLAYER)
2139  player = tmp;
2140 
2141  /* This could be made additive I guess (two lights better than
2142  * one). But if so, it shouldn't be a simple additive - 2
2143  * light bulbs do not illuminate twice as far as once since
2144  * it is a dissipation factor that is squared (or is it cubed?)
2145  */
2146  if (tmp->glow_radius > light)
2147  light = tmp->glow_radius;
2148 
2149  /* if this object is visible and not a blank face,
2150  * update the objects that show how this space
2151  * looks.
2152  */
2153  if (!tmp->invisible && tmp->face != blank_face) {
2154  if (tmp->map_layer) {
2155  add_face_layer(tmp->map_layer, map_layer_info[tmp->map_layer].high_layer,
2156  tmp, layers, map_layer_info[tmp->map_layer].honor_visibility);
2157  } else if (tmp->move_type&MOVE_FLYING) {
2159  } else if ((tmp->type == PLAYER || QUERY_FLAG(tmp, FLAG_MONSTER))) {
2161  } else if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2162  layers[MAP_LAYER_FLOOR] = tmp;
2163  /* floors hide everything else */
2164  memset(layers+1, 0, (MAP_LAYERS-1)*sizeof(object *));
2165  /* Check for FLAG_SEE_ANYWHERE is removed - objects
2166  * with that flag should just have a high visibility
2167  * set - we shouldn't need special code here.
2168  */
2169  } else if (QUERY_FLAG(tmp, FLAG_NO_PICK)) {
2171  } else {
2173  }
2174  }
2175  if (tmp == tmp->above) {
2176  LOG(llevError, "Error in structure of map\n");
2177  exit(-1);
2178  }
2179 
2180  move_slow |= tmp->move_slow;
2181  move_block |= tmp->move_block;
2182  move_on |= tmp->move_on;
2183  move_off |= tmp->move_off;
2184  move_allow |= tmp->move_allow;
2185 
2186  if (QUERY_FLAG(tmp, FLAG_ALIVE))
2187  flags |= P_IS_ALIVE;
2189  flags |= P_NO_MAGIC;
2191  flags |= P_NO_CLERIC;
2192 
2194  flags |= P_BLOCKSVIEW;
2195  } FOR_MAP_FINISH(); /* for stack of objects */
2196 
2197  if (player)
2198  flags |= P_PLAYER;
2199 
2200  /* we don't want to rely on this function to have accurate flags, but
2201  * since we're already doing the work, we calculate them here.
2202  * if they don't match, logic is broken someplace.
2203  */
2204  if (((oldflags&~(P_NEED_UPDATE|P_NO_ERROR)) != flags)
2205  && (!(oldflags&P_NO_ERROR))) {
2206  LOG(llevDebug, "update_position: updated flags do not match old flags: %s (x=%d,y=%d) %x != %x\n",
2207  m->path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2208  }
2209 
2210  SET_MAP_FLAGS(m, x, y, flags);
2211  SET_MAP_MOVE_BLOCK(m, x, y, move_block&~move_allow);
2212  SET_MAP_MOVE_ON(m, x, y, move_on);
2213  SET_MAP_MOVE_OFF(m, x, y, move_off);
2214  SET_MAP_MOVE_SLOW(m, x, y, move_slow);
2215  SET_MAP_LIGHT(m, x, y, light);
2216 
2217  /* Note that player may be NULL here, which is fine - if no player, need
2218  * to clear any value that may be set.
2219  */
2220  SET_MAP_PLAYER(m, x, y, player);
2221 
2222  /* Note it is intentional we copy everything, including NULL values. */
2223  memcpy(GET_MAP_FACE_OBJS(m, x, y), layers, sizeof(object *)*MAP_LAYERS);
2224 }
2225 
2233  int timeout;
2234 
2235  timeout = MAP_RESET_TIMEOUT(map);
2236  if (timeout <= 0)
2237  timeout = MAP_DEFAULTRESET;
2238  if (timeout >= MAP_MAXRESET)
2239  timeout = MAP_MAXRESET;
2240  MAP_RESET_TIMEOUT(map) = timeout;
2241  MAP_WHEN_RESET(map) = seconds()+timeout;
2242 }
2243 
2258 static mapstruct *load_and_link_tiled_map(mapstruct *orig_map, int tile_num) {
2259  int dest_tile = (tile_num+2)%4;
2260  char path[HUGE_BUF];
2261 
2262  path_combine_and_normalize(orig_map->path, orig_map->tile_path[tile_num], path, sizeof(path));
2263 
2264  orig_map->tile_map[tile_num] = ready_map_name(path, 0);
2265  if (orig_map->tile_map[tile_num] == NULL) {
2266  LOG(llevError, "%s has invalid tiled map %s\n", orig_map->path, path);
2267  free(orig_map->tile_path[tile_num]);
2268  orig_map->tile_path[tile_num] = NULL;
2269  return NULL;
2270  }
2271 
2272  /* need to do a strcmp here as the orig_map->path is not a shared string */
2273  if (orig_map->tile_map[tile_num]->tile_path[dest_tile]
2274  && !strcmp(orig_map->tile_map[tile_num]->tile_path[dest_tile], orig_map->path))
2275  orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
2276 
2277  return orig_map->tile_map[tile_num];
2278 }
2279 
2297 int out_of_map(mapstruct *m, int x, int y) {
2298 
2299  /* Simple case - coordinates are within this local
2300  * map.
2301  */
2302  if (x >= 0 && x < MAP_WIDTH(m) && y >= 0 && y < MAP_HEIGHT(m))
2303  return 0;
2304 
2305  if (x < 0) {
2306  if (!m->tile_path[3])
2307  return 1;
2308  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) {
2310  /* Verify the tile map loaded correctly */
2311  if (!m->tile_map[3])
2312  return 0;
2313  }
2314  return (out_of_map(m->tile_map[3], x+MAP_WIDTH(m->tile_map[3]), y));
2315  } else if (x >= MAP_WIDTH(m)) {
2316  if (!m->tile_path[1])
2317  return 1;
2318  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) {
2320  /* Verify the tile map loaded correctly */
2321  if (!m->tile_map[1])
2322  return 0;
2323  }
2324  return (out_of_map(m->tile_map[1], x-MAP_WIDTH(m), y));
2325  }
2326 
2327  if (y < 0) {
2328  if (!m->tile_path[0])
2329  return 1;
2330  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) {
2332  /* Verify the tile map loaded correctly */
2333  if (!m->tile_map[0])
2334  return 0;
2335  }
2336  return (out_of_map(m->tile_map[0], x, y+MAP_HEIGHT(m->tile_map[0])));
2337  } else if (y >= MAP_HEIGHT(m)) {
2338  if (!m->tile_path[2])
2339  return 1;
2340  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) {
2342  /* Verify the tile map loaded correctly */
2343  if (!m->tile_map[2])
2344  return 0;
2345  }
2346  return (out_of_map(m->tile_map[2], x, y-MAP_HEIGHT(m)));
2347  }
2348  return 1;
2349 }
2350 
2370 mapstruct *get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y) {
2371 
2372  /* Simple case - coordinates are within this local
2373  * map.
2374  */
2375 
2376  if ( !m ) return NULL;
2377  if (!OUT_OF_REAL_MAP(m, *x, *y))
2378  return m;
2379  if (m->in_memory != MAP_IN_MEMORY) {
2380  // callers are calling get_map_from_coord() to access the map, so if
2381  // it's swapped out return early here. While we could finish this
2382  // computation without having to swap the map in, when they try to
2383  // get/set it will abort()
2384  //
2385  // This should never happen (if it did, the swapper is buggy) but it
2386  // does actually happen because of object recycling (e.g. op->enemy
2387  // points to a completely different object on a swapped out map)
2388  return NULL;
2389  }
2390 
2391  do /* With the first case there, we can assume we are out of the map if we get here */
2392  {
2393  // Figure out what map should be in the direction we are off the map, and then
2394  // load that map and look again.
2395  if (*x < 0) {
2396  if (!m->tile_path[3])
2397  return NULL;
2398  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY){
2400  /* Make sure we loaded properly. */
2401  if (!m->tile_map[3])
2402  return NULL;
2403  }
2404  *x += MAP_WIDTH(m->tile_map[3]);
2405  m = m->tile_map[3];
2406  }
2407  else if (*x >= MAP_WIDTH(m)) {
2408  if (!m->tile_path[1])
2409  return NULL;
2410  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY){
2412  /* Make sure we loaded properly. */
2413  if (!m->tile_map[1])
2414  return NULL;
2415  }
2416  *x -= MAP_WIDTH(m);
2417  m = m->tile_map[1];
2418  }
2419  // It is possible that x and y be considered separate compare groups,
2420  // But using an else-if here retains the old behavior that recursion produced.
2421  else if (*y < 0) {
2422  if (!m->tile_path[0])
2423  return NULL;
2424  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY){
2426  /* Make sure we loaded properly. */
2427  if (!m->tile_map[0])
2428  return NULL;
2429  }
2430  *y += MAP_HEIGHT(m->tile_map[0]);
2431  m = m->tile_map[0];
2432  }
2433  else if (*y >= MAP_HEIGHT(m)) {
2434  if (!m->tile_path[2])
2435  return NULL;
2436  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY){
2438  /* Make sure we loaded properly. */
2439  if (!m->tile_map[2])
2440  return NULL;
2441  }
2442  *y -= MAP_HEIGHT(m);
2443  m = m->tile_map[2];
2444  }
2445  // The check here is if our single tile is in the map.
2446  // That is exactly what the OUT_OF_MAP macro does.
2447  } while (OUT_OF_REAL_MAP(m, *x, *y));
2448  return m; /* We have found our map */
2449 }
2450 
2464 static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {
2465  if (!map1 || !map2)
2466  return 0;
2467 
2468  if (map1 == map2) {
2469  *dx = 0;
2470  *dy = 0;
2471  } else if (map1->tile_map[0] == map2) { /* up */
2472  *dx = 0;
2473  *dy = -MAP_HEIGHT(map2);
2474  } else if (map1->tile_map[1] == map2) { /* right */
2475  *dx = MAP_WIDTH(map1);
2476  *dy = 0;
2477  } else if (map1->tile_map[2] == map2) { /* down */
2478  *dx = 0;
2479  *dy = MAP_HEIGHT(map1);
2480  } else if (map1->tile_map[3] == map2) { /* left */
2481  *dx = -MAP_WIDTH(map2);
2482  *dy = 0;
2483  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) { /* up right */
2484  *dx = MAP_WIDTH(map1->tile_map[0]);
2485  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2486  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) { /* up left */
2487  *dx = -MAP_WIDTH(map2);
2488  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2489  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) { /* right up */
2490  *dx = MAP_WIDTH(map1);
2491  *dy = -MAP_HEIGHT(map2);
2492  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) { /* right down */
2493  *dx = MAP_WIDTH(map1);
2494  *dy = MAP_HEIGHT(map1->tile_map[1]);
2495  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) { /* down right */
2496  *dx = MAP_WIDTH(map1->tile_map[2]);
2497  *dy = MAP_HEIGHT(map1);
2498  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) { /* down left */
2499  *dx = -MAP_WIDTH(map2);
2500  *dy = MAP_HEIGHT(map1);
2501  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) { /* left up */
2502  *dx = -MAP_WIDTH(map1->tile_map[3]);
2503  *dy = -MAP_HEIGHT(map2);
2504  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) { /* left down */
2505  *dx = -MAP_WIDTH(map1->tile_map[3]);
2506  *dy = MAP_HEIGHT(map1->tile_map[3]);
2507  } else { /* not "adjacent" enough */
2508  return 0;
2509  }
2510 
2511  return 1;
2512 }
2513 
2541 int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags) {
2542  if (!adjacent_map(op1->map, op2->map, &retval->distance_x, &retval->distance_y)) {
2543  /* be conservative and fill in _some_ data */
2544  retval->distance = 100000;
2545  retval->distance_x = 32767;
2546  retval->distance_y = 32767;
2547  retval->direction = 0;
2548  retval->part = NULL;
2549  return 0;
2550  } else {
2551  object *best;
2552 
2553  retval->distance_x += op2->x-op1->x;
2554  retval->distance_y += op2->y-op1->y;
2555 
2556  best = op1;
2557  /* If this is multipart, find the closest part now */
2558  if (!(flags&0x1) && op1->more) {
2559  object *tmp;
2560  int best_distance = retval->distance_x*retval->distance_x+
2561  retval->distance_y*retval->distance_y, tmpi;
2562 
2563  /* we just take the offset of the piece to head to figure
2564  * distance instead of doing all that work above again
2565  * since the distance fields we set above are positive in the
2566  * same axis as is used for multipart objects, the simply arithmetic
2567  * below works.
2568  */
2569  for (tmp = op1->more; tmp != NULL; tmp = tmp->more) {
2570  tmpi = (op1->x-tmp->x+retval->distance_x)*(op1->x-tmp->x+retval->distance_x)+
2571  (op1->y-tmp->y+retval->distance_y)*(op1->y-tmp->y+retval->distance_y);
2572  if (tmpi < best_distance) {
2573  best_distance = tmpi;
2574  best = tmp;
2575  }
2576  }
2577  if (best != op1) {
2578  retval->distance_x += op1->x-best->x;
2579  retval->distance_y += op1->y-best->y;
2580  }
2581  }
2582  retval->part = best;
2583  retval->distance = ihypot(retval->distance_x, retval->distance_y);
2584  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2585  return 1;
2586  }
2587 }
2588 
2609 int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval) {
2610  if (!adjacent_map(m, op2->map, &retval->distance_x, &retval->distance_y)) {
2611  /* be conservative and fill in _some_ data */
2612  retval->distance = 100000;
2613  retval->distance_x = 32767;
2614  retval->distance_y = 32767;
2615  retval->direction = 0;
2616  retval->part = NULL;
2617  return 0;
2618  } else {
2619  retval->distance_x += op2->x-x;
2620  retval->distance_y += op2->y-y;
2621 
2622  retval->part = NULL;
2623  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2624  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2625  return 1;
2626  }
2627 }
2628 
2647 int on_same_map(const object *op1, const object *op2) {
2648  int dx, dy;
2649 
2650  return adjacent_map(op1->map, op2->map, &dx, &dy);
2651 }
2652 
2670 object *map_find_by_flag(mapstruct *map, int x, int y, int flag) {
2671  object *tmp;
2672 
2673  for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above) {
2674  object *head;
2675 
2676  head = HEAD(tmp);
2677  if (QUERY_FLAG(head, flag))
2678  return head;
2679  }
2680  return NULL;
2681 }
2682 
2688  char base[HUGE_BUF], path[sizeof(base) + 4];
2689  int count;
2690 
2691  if (map->unique) {
2692  snprintf(path, sizeof(path), "%s/%s/%s", settings.localdir, settings.playerdir, map->path+1);
2693  if (unlink(path) != 0) {
2694  LOG(llevError, "Could not delete %s: %s\n", path, strerror(errno));
2695  }
2696  return;
2697  }
2698 
2699  create_items_path(map->path, base, sizeof(base));
2700 
2701  for (count = 0; count < 10; count++) {
2702  snprintf(path, sizeof(path), "%s.v%02d", base, count);
2703  unlink(path);
2704  }
2705 }
2706 
2712 const char *map_get_path(const object *item) {
2713  if (item->map != NULL) {
2714  if (strlen(item->map->path) > 0) {
2715  return item->map->path;
2716  }
2717 
2718  return item->map->name ? item->map->name : "(empty path and name)";
2719  }
2720 
2721  if (item->env != NULL)
2722  return map_get_path(item->env);
2723 
2724  return "(no map and no env!)";
2725 }
2726 
2732 bool map_path_unique(const char *path) {
2733  return path != NULL && path[0] == '~';
2734 }
2735 
2736 MapSpace *map_space(const mapstruct *m, int x, int y) {
2737  if (m->spaces == NULL) // guard against map being swapped out
2738  abort();
2739  if (OUT_OF_REAL_MAP(m, x, y)) // array out of bounds check
2740  abort();
2741  return &m->spaces[x + m->width * y];
2742 }
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:842
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:1323
ready_map_name
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.cpp:1768
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:1252
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:946
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.cpp:2118
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:2049
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:1165
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:1587
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:247
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:416
free_all_maps
void free_all_maps(void)
Definition: map.cpp:1962
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:2687
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_MINTIMEOUT
#define MAP_MINTIMEOUT
Definition: config.h:409
map_size
uint32_t map_size(mapstruct *m)
Definition: map.cpp:798
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:620
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:1348
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:1953
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:1994
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:1175
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:2297
MAX_DARKNESS
#define MAX_DARKNESS
Definition: define.h:454
MSG_TYPE_ATTACK
#define MSG_TYPE_ATTACK
Definition: newclient.h:412
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:1650
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:1603
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:2370
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:2609
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.cpp:2670
delete_map
void delete_map(mapstruct *m)
Definition: map.cpp:1696
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:423
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:245
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
map_space
MapSpace * map_space(const mapstruct *m, int x, int y)
Definition: map.cpp:2736
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:2232
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:2258
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:265
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:988
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:2464
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:2712
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:2647
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
map_path_unique
bool map_path_unique(const char *path)
Definition: map.cpp:2732
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:2541
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:812
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:1395
calculate_difficulty
int calculate_difficulty(mapstruct *m)
Definition: map.cpp:1896
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
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.cpp:1216
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:864
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_reset_swap
void map_reset_swap(mapstruct *m)
Definition: map.cpp:1750
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:1288
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