Crossfire Server, Trunk
map.c
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 
38 static void free_all_objects(mapstruct *m);
39 
45 const char *const map_layer_name[MAP_LAYERS] = {
46  "floor", "no_pick", "no_pick", "item", "item",
47  "item", "living", "living", "fly", "fly"
48 };
49 
51 typedef struct Map_Layer_Info {
52  uint8_t high_layer;
53  uint8_t honor_visibility;
55 
63  { MAP_LAYER_FLOOR, 1 },
65  { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 },
66  { MAP_LAYER_LIVING2, 1 }, { MAP_LAYER_LIVING2, 1 },
67  { MAP_LAYER_FLY2, 1 }, { MAP_LAYER_FLY2, 1 }
68 };
69 
79  mapstruct *map;
80 
81  if (!name || !*name)
82  return NULL;
83 
84  for (map = first_map; map; map = map->next)
85  if (!strcmp(name, map->path))
86  break;
87  return (map);
88 }
89 
103 char *create_pathname(const char *name, char *buf, size_t size) {
104  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
105  * someplace else in the code? msw 2-17-97
106  */
107  if (*name == '/')
108  snprintf(buf, size, "%s/%s%s", settings.datadir, settings.mapdir, name);
109  else
110  snprintf(buf, size, "%s/%s/%s", settings.datadir, settings.mapdir, name);
111  return buf;
112 }
113 
124 void create_overlay_pathname(const char *name, char *buf, size_t size) {
125  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
126  * someplace else in the code? msw 2-17-97
127  */
128  if (*name == '/')
129  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.mapdir, name);
130  else
131  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.mapdir, name);
132 }
133 
144 void create_template_pathname(const char *name, char *buf, size_t size) {
145  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
146  * someplace else in the code? msw 2-17-97
147  */
148  if (*name == '/')
149  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.templatedir, name);
150  else
151  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.templatedir, name);
152 }
153 
167 static void create_items_path(const char *s, char *buf, size_t size) {
168  char *t;
169 
170  if (*s == '/')
171  s++;
172 
173  snprintf(buf, size, "%s/%s/", settings.localdir, settings.uniquedir);
174  t = buf+strlen(buf);
175  snprintf(t, buf+size-t, "%s", s);
176 
177  while (*t != '\0') {
178  if (*t == '/')
179  *t = '@';
180  t++;
181  }
182 }
183 
202 int check_path(const char *name, int prepend_dir) {
203  char buf[MAX_BUF];
204 #ifndef WIN32
205  struct stat statbuf;
206  int mode = 0;
207 #endif
208 
209  if (prepend_dir)
211  else
212  strlcpy(buf, name, sizeof(buf));
213 #ifdef WIN32 /* ***win32: check this sucker in windows style. */
214  return(_access(buf, 0));
215 #else
216 
217  if (stat(buf, &statbuf) != 0)
218  return -1;
219 
220  if (!S_ISREG(statbuf.st_mode))
221  return (-1);
222 
223  if (((statbuf.st_mode&S_IRGRP) && getegid() == statbuf.st_gid)
224  || ((statbuf.st_mode&S_IRUSR) && geteuid() == statbuf.st_uid)
225  || (statbuf.st_mode&S_IROTH))
226  mode |= 4;
227 
228  if ((statbuf.st_mode&S_IWGRP && getegid() == statbuf.st_gid)
229  || (statbuf.st_mode&S_IWUSR && geteuid() == statbuf.st_uid)
230  || (statbuf.st_mode&S_IWOTH))
231  mode |= 2;
232 
233  return (mode);
234 #endif
235 }
236 
246 void dump_map(const mapstruct *m) {
247  LOG(llevError, "Map %s status: %d.\n", m->path, m->in_memory);
248  LOG(llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH(m), MAP_HEIGHT(m), MAP_ENTER_X(m), MAP_ENTER_Y(m));
249 
250  if (m->msg != NULL)
251  LOG(llevError, "Message:\n%s", m->msg);
252 
253  if (m->maplore != NULL)
254  LOG(llevError, "Lore:\n%s", m->maplore);
255 
256  if (m->tmpname != NULL)
257  LOG(llevError, "Tmpname: %s\n", m->tmpname);
258 
259  LOG(llevError, "Difficulty: %d\n", m->difficulty);
260  LOG(llevError, "Darkness: %d\n", m->darkness);
261 }
262 
269 void dump_all_maps(void) {
270  mapstruct *m;
271 
272  for (m = first_map; m != NULL; m = m->next) {
273  dump_map(m);
274  }
275 }
276 
301 int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny) {
302  int retval = 0;
303  mapstruct *mp;
304 
305  /*
306  * Since x and y are copies of the original values, we can directly
307  * mess with them here.
308  */
309  mp = get_map_from_coord(oldmap, &x, &y);
310  if (!mp)
311  return P_OUT_OF_MAP;
312  if (mp != oldmap)
313  retval |= P_NEW_MAP;
314  if (newmap)
315  *newmap = mp;
316  if (nx)
317  *nx = x;
318  if (ny)
319  *ny = y;
320  retval |= mp->spaces[x+mp->width*y].flags;
321  return retval;
322 }
323 
345 int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy) {
346  object *tmp_head;
347  int mflags, blocked;
348 
349  /* Make sure the coordinates are valid - they should be, as caller should
350  * have already checked this.
351  */
352  if (OUT_OF_REAL_MAP(m, sx, sy)) {
353  LOG(llevError, "blocked_link: Passed map, x, y coordinates outside of map\n");
354  return 1;
355  }
356 
357  /* special hack for transports: if it's a transport with a move_type of 0, it can do on the space anyway */
358  if (ob->type == TRANSPORT && ob->move_type == 0)
359  return 0;
360 
361  /* Save some cycles - instead of calling get_map_flags(), just get the value
362  * directly.
363  */
364  mflags = m->spaces[sx+m->width*sy].flags;
365 
366  blocked = GET_MAP_MOVE_BLOCK(m, sx, sy);
367 
368  /* If space is currently not blocked by anything, no need to
369  * go further. Not true for players - all sorts of special
370  * things we need to do for players.
371  */
372  if (ob->type != PLAYER && !(mflags&P_IS_ALIVE) && (blocked == 0))
373  return 0;
374 
375  /* if there isn't anytyhing alive on this space, and this space isn't
376  * otherwise blocked, we can return now. Only if there is a living
377  * creature do we need to investigate if it is part of this creature
378  * or another. Likewise, only if something is blocking us do we
379  * need to investigate if there is a special circumstance that would
380  * let the player through (inventory checkers for example)
381  */
382  if (!(mflags&P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK(ob, blocked))
383  return 0;
384 
385  ob = HEAD(ob);
386 
387  /* We basically go through the stack of objects, and if there is
388  * some other object that has NO_PASS or FLAG_ALIVE set, return
389  * true. If we get through the entire stack, that must mean
390  * ob is blocking it, so return 0.
391  */
392  FOR_MAP_PREPARE(m, sx, sy, tmp) {
393  /* Never block part of self. */
394  tmp_head = HEAD(tmp);
395  if (tmp_head == ob)
396  continue;
397  /* This must be before the checks below. Code for inventory checkers. */
398  if (tmp->type == CHECK_INV && OB_MOVE_BLOCK(ob, tmp)) {
399  /* If last_sp is set, the player/monster needs an object,
400  * so we check for it. If they don't have it, they can't
401  * pass through this space.
402  */
403  if (tmp->last_sp) {
404  if (check_inv_recursive(ob, tmp) == NULL) {
405  if (tmp->msg) {
406  /* Optionally display the reason why one cannot move
407  * there. Note: emitting a message from this function
408  * is not very elegant. Ideally, this should be done
409  * somewhere in server/player.c, but this is difficult
410  * for objects of type CHECK_INV that are not alive.
411  */
414  tmp->msg);
415  }
416  return 1;
417  }
418  } else {
419  /* In this case, the player must not have the object -
420  * if they do, they can't pass through.
421  */
422  if (check_inv_recursive(ob, tmp) != NULL) {
423  if (tmp->msg) {
426  tmp->msg);
427  }
428  return 1;
429  }
430  }
431  } /* if check_inv */
432  else {
433  /* Broke apart a big nasty if into several here to make
434  * this more readable. first check - if the space blocks
435  * movement, can't move here.
436  * second - if a monster, can't move there, unless it is a
437  * hidden dm
438  */
439  if (OB_MOVE_BLOCK(ob, tmp))
440  return 1;
442  && tmp->head != ob
443  && tmp != ob
444  && tmp->type != DOOR
445  && !(QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden))
446  return 1;
447  }
448  } FOR_MAP_FINISH();
449  return 0;
450 }
451 
488 int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y) {
489  archetype *tmp;
490  int flag;
491  mapstruct *m1;
492  int16_t sx, sy;
493  const object *part;
494 
495  if (ob == NULL) {
496  flag = get_map_flags(m, &m1, x, y, &sx, &sy);
497  if (flag&P_OUT_OF_MAP)
498  return P_OUT_OF_MAP;
499 
500  /* don't have object, so don't know what types would block */
501  return(GET_MAP_MOVE_BLOCK(m1, sx, sy));
502  }
503 
504  for (tmp = ob->arch, part = ob; tmp != NULL; tmp = tmp->more, part = part->more) {
505  flag = get_map_flags(m, &m1, x+tmp->clone.x, y+tmp->clone.y, &sx, &sy);
506 
507  if (flag&P_OUT_OF_MAP)
508  return P_OUT_OF_MAP;
509  if (flag&P_IS_ALIVE)
510  return P_IS_ALIVE;
511 
512  /* object_find_first_free_spot() calls this function. However, often
513  * ob doesn't have any move type (when used to place exits)
514  * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work.
515  */
516 
517  if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK(m1, sx, sy) != MOVE_ALL)
518  continue;
519 
520  /* A transport without move_type for a part should go through everything for that part. */
521  if (ob->type == TRANSPORT && part->move_type == 0)
522  continue;
523 
524  /* Note it is intentional that we check ob - the movement type of the
525  * head of the object should correspond for the entire object.
526  */
527  if (OB_TYPE_MOVE_BLOCK(ob, GET_MAP_MOVE_BLOCK(m1, sx, sy)))
528  return AB_NO_PASS;
529  }
530  return 0;
531 }
532 
543 static void fix_container_multipart(object *container) {
544  FOR_INV_PREPARE(container, tmp) {
545  archetype *at;
546  object *op, *last;
547 
548  if (tmp->inv)
550  /* already multipart, or non-multipart arch - don't do anything more */
551  for (at = tmp->arch->more, last = tmp; at != NULL; at = at->more, last = op) {
552  /* FIXME: We can't reuse object_fix_multipart() since that only
553  * works for items directly on maps. Maybe factor out common code?
554  */
555  op = arch_to_object(at);
556  op->head = tmp;
557  op->env = tmp->env;
558  last->more = op;
559  if (tmp->name != op->name) {
560  if (op->name)
561  free_string(op->name);
562  op->name = add_string(tmp->name);
563  }
564  if (tmp->title != op->title) {
565  if (op->title)
566  free_string(op->title);
567  op->title = add_string(tmp->title);
568  }
570  }
571  } FOR_INV_FINISH();
572 }
573 
585  int x, y;
586 
587  for (x = 0; x < MAP_WIDTH(m); x++)
588  for (y = 0; y < MAP_HEIGHT(m); y++)
589  FOR_MAP_PREPARE(m, x, y, tmp) {
590  if (tmp->inv)
592 
593  /* already multipart - don't do anything more */
594  if (tmp->head || tmp->more)
595  continue;
596 
598  } FOR_MAP_FINISH(); /* for objects on this space */
599 }
600 
612 void load_objects(mapstruct *m, FILE *fp, int mapflags) {
613  int i, j, bufstate = LO_NEWFILE;
614  int unique;
615  object *op, *prev = NULL, *last_more = NULL;
616 
617  op = object_new();
618  op->map = m; /* To handle buttons correctly */
619 
620  PROFILE_BEGIN();
621  while ((i = load_object(fp, op, bufstate, mapflags))) {
622  /* Since the loading of the map header does not load an object
623  * anymore, we need to pass LO_NEWFILE for the first object loaded,
624  * and then switch to LO_REPEAT for faster loading.
625  */
626  bufstate = LO_REPEAT;
627 
628  /* if the archetype for the object is null, means that we
629  * got an invalid object. Don't do anything with it - the game
630  * or editor will not be able to do anything with it either.
631  */
632  if (op->arch == NULL) {
633  LOG(llevDebug, "Discarding object without arch: %s\n", op->name ? op->name : "(null)");
634  continue;
635  }
636 
637  /*
638  * You can NOT have players on a map being loaded.
639  * Trying to use such a type leads to crashes everywhere as op->contr is NULL.
640  */
641  if (op->type == PLAYER) {
642  LOG(llevError, "Discarding invalid item with type PLAYER in map %s\n", m->path);
643  continue;
644  }
645 
646  /* don't use out_of_map because we don't want to consider tiling properties, we're loading a single map */
647  if (op->x < 0 || op->y < 0 || op->x >= MAP_WIDTH(m) || op->y >= MAP_HEIGHT(m)) {
648  LOG(llevError, " object %s not on valid map position %s:%d:%d\n", op->name ? op->name : "(null)", m->path, op->x, op->y);
649  if (op->x < 0) {
650  op->x = 0;
651  } else if (op->x >= MAP_WIDTH(m)) {
652  op->x = MAP_WIDTH(m) - 1;
653  }
654  if (op->y < 0) {
655  op->y = 0;
656  } else if (op->y >= MAP_HEIGHT(m)) {
657  op->y = MAP_HEIGHT(m) - 1;
658  }
659  }
660 
661  switch (i) {
662  case LL_NORMAL:
663  /* if we are loading an overlay, put the floors on the bottom */
665  && mapflags&MAP_OVERLAY)
667  else
669 
670  if (op->inv)
672 
673  prev = op,
674  last_more = op;
675  break;
676 
677  case LL_MORE:
679  op->head = prev,
680  last_more->more = op,
681  last_more = op;
682  break;
683  }
684  if (mapflags&MAP_STYLE) {
686  }
687  op = object_new();
688  op->map = m;
689  }
690  PROFILE_END(diff, LOG(llevDebug,
691  "load_objects on %s took %ld us\n", m->path, diff));
692  for (i = 0; i < m->width; i++) {
693  for (j = 0; j < m->height; j++) {
694  unique = 0;
695  /* check for unique items, or unique squares */
696  FOR_MAP_PREPARE(m, i, j, otmp) {
697  if (QUERY_FLAG(otmp, FLAG_UNIQUE))
698  unique = 1;
699  if (!(mapflags&(MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique))
701  } FOR_MAP_FINISH();
702  }
703  }
706 }
707 
725 int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag) {
726  int i, j = 0, unique = 0;
727  unsigned int count = 0;
728 
731 
732  long serialize_time, write_time;
733 
734  PROFILE_BEGIN();
735  /* first pass - save one-part objects */
736  for (i = 0; i < MAP_WIDTH(m); i++) {
737  for (j = 0; j < MAP_HEIGHT(m); j++) {
738  unique = 0;
739  FOR_MAP_PREPARE(m, i, j, op) {
741  unique = 1;
742 
743  if (op->type == PLAYER) {
744  LOG(llevDebug, "Player on map that is being saved\n");
745  continue;
746  }
747 
748  if (op->head || object_get_owner(op) != NULL)
749  continue;
750 
751  if (unique || QUERY_FLAG(op, FLAG_UNIQUE)) {
753  count++ ;
754  } else if (flag == 0
757  count++;
758  }
759  } FOR_MAP_FINISH(); /* for this space */
760  } /* for this j */
761  }
762  PROFILE_END(diff, serialize_time = diff);
763 
764  PROFILE_BEGIN();
765  char *cp = stringbuffer_finish(sb);
766  char *cp2 = stringbuffer_finish(sb2);
767  fputs(cp, fp);
768  fputs(cp2, fp2);
769  free(cp);
770  free(cp2);
771  PROFILE_END(diff, write_time = diff);
772 
773  LOG(llevDebug, "saved %d objects on %s (%d us serializing, %d us writing)\n", count, m->path, serialize_time, write_time);
774  return 0;
775 }
776 
789  mapstruct *map = (mapstruct *)calloc(1, sizeof(mapstruct));
790  /* mapstruct *mp;*/
791 
792  if (map == NULL)
794  /*
795  * Nothing in the code appears to require we add new maps to the end of the list.
796  * Why not just add them to the front instead? Its faster.
797  *
798  * SilverNexus 2016-05-18
799  *
800  for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next)
801  ;
802  if (mp == NULL)
803  first_map = map;
804  else
805  mp->next = map;
806  */
807  map->next = first_map;
808  first_map = map;
809 
810  map->in_memory = MAP_SWAPPED;
811  /* The maps used to pick up default x and y values from the
812  * map archetype. Mimic that behaviour.
813  */
814  MAP_WIDTH(map) = 16;
815  MAP_HEIGHT(map) = 16;
816  MAP_RESET_TIMEOUT(map) = 0;
817  MAP_TIMEOUT(map) = 300;
818  MAP_ENTER_X(map) = 0;
819  MAP_ENTER_Y(map) = 0;
820  map->last_reset_time = 0;
821  return map;
822 }
823 
825 uint32_t map_size(mapstruct *m) {
826  return (uint32_t)m->width * (uint32_t)m->height;
827 }
828 
840  m->in_memory = MAP_IN_MEMORY;
841  /* Log this condition and free the storage. We could I suppose
842  * realloc, but if the caller is presuming the data will be intact,
843  * that is their poor assumption.
844  */
845  if (m->spaces) {
846  LOG(llevError, "allocate_map called with already allocated map (%s)\n", m->path);
847  free(m->spaces);
848  }
849 
850  m->spaces = calloc(map_size(m), sizeof(MapSpace));
851 
852  if (m->spaces == NULL)
854 }
855 
869 mapstruct *get_empty_map(int sizex, int sizey) {
871  m->width = sizex;
872  m->height = sizey;
873  m->in_memory = MAP_SWAPPED;
874  allocate_map(m);
875  return m;
876 }
877 
891 static shopitems *parse_shop_string(const char *input_string, const mapstruct *map) {
892  char *shop_string, *p, *q, *next_semicolon, *next_colon;
893  shopitems *items = NULL;
894  int i = 0, number_of_entries = 0;
895  const typedata *current_type;
896 
897  shop_string = strdup_local(input_string);
898  p = shop_string;
899  LOG(llevDebug, "parsing %s\n", input_string);
900  /* first we'll count the entries, we'll need that for allocating the array shortly */
901  while (p) {
902  p = strchr(p, ';');
903  number_of_entries++;
904  if (p)
905  p++;
906  }
907  p = shop_string;
908  strip_endline(p);
909  items = CALLOC(number_of_entries+1, sizeof(shopitems));
910  /*
911  * The memset would always set at least one byte to zero,
912  * so a failed calloc would have segfaulted the program.
913  * Instead, check for a null and fail more gracefully.
914  */
915  if (!items)
917  /*
918  * calloc() already sets each byte to zero already
919  *
920  memset(items, 0, (sizeof(shopitems)*number_of_entries+1));
921  */
922  for (i = 0; i < number_of_entries; i++) {
923  if (!p) {
924  LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
925  break;
926  }
927  next_semicolon = strchr(p, ';');
928  next_colon = strchr(p, ':');
929  /* if there is a stregth specified, figure out what it is, we'll need it soon. */
930  if (next_colon && (!next_semicolon || next_colon < next_semicolon))
931  items[i].strength = atoi(strchr(p, ':')+1);
932 
933  if (isdigit(*p) || *p == '*') {
934  items[i].typenum = *p == '*' ? -1 : atoi(p);
935  current_type = get_typedata(items[i].typenum);
936  if (current_type) {
937  items[i].name = current_type->name;
938  items[i].name_pl = current_type->name_pl;
939  }
940  } else { /*we have a named type, let's figure out what it is */
941  q = strpbrk(p, ";:");
942  if (q)
943  *q = '\0';
944 
945  current_type = get_typedata_by_name(p);
946  if (current_type) {
947  items[i].name = current_type->name;
948  items[i].typenum = current_type->number;
949  items[i].name_pl = current_type->name_pl;
950  } else {
951  /* oh uh, something's wrong, let's free up this one, and try
952  * the next entry while we're at it, better print a warning */
953  LOG(llevError, "invalid type %s defined in shopitems for %s in string %s\n", p, map->name, input_string);
954  }
955  }
956  items[i].index = number_of_entries;
957  if (next_semicolon)
958  p = ++next_semicolon;
959  else
960  p = NULL;
961  }
962  free(shop_string);
963  return items;
964 }
965 
977 static void print_shop_string(mapstruct *m, char *output_string, int size) {
978  int i;
979  char tmp[MAX_BUF];
980 
981  output_string[0] = '\0';
982  for (i = 0; i < m->shopitems[0].index; i++) {
983  if (m->shopitems[i].typenum != -1) {
984  if (m->shopitems[i].strength) {
985  snprintf(tmp, sizeof(tmp), "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
986  } else
987  snprintf(tmp, sizeof(tmp), "%s;", m->shopitems[i].name);
988  } else {
989  if (m->shopitems[i].strength) {
990  snprintf(tmp, sizeof(tmp), "*:%d;", m->shopitems[i].strength);
991  } else
992  snprintf(tmp, sizeof(tmp), "*;");
993  }
994  snprintf(output_string+strlen(output_string), size-strlen(output_string), "%s", tmp);
995  }
996 
997  /* erase final ; else parsing back will lead to issues */
998  if (strlen(output_string) > 0) {
999  output_string[strlen(output_string) - 1] = '\0';
1000  }
1001 }
1002 
1022 static int load_map_header(FILE *fp, mapstruct *m) {
1023  char buf[HUGE_BUF], *key = NULL, *value;
1024 
1025  m->width = m->height = 0;
1026  while (fgets(buf, sizeof(buf), fp) != NULL) {
1027  char *p;
1028 
1029  p = strchr(buf, '\n');
1030  if (p == NULL) {
1031  LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf);
1032  return 1;
1033  }
1034  *p = '\0';
1035 
1036  key = buf;
1037  while (isspace(*key))
1038  key++;
1039  if (*key == 0)
1040  continue; /* empty line */
1041  value = strchr(key, ' ');
1042  if (value) {
1043  *value = 0;
1044  value++;
1045  while (isspace(*value)) {
1046  value++;
1047  if (*value == '\0') {
1048  /* Nothing but spaces. */
1049  value = NULL;
1050  break;
1051  }
1052  }
1053  }
1054 
1055  /* key is the field name, value is what it should be set
1056  * to. We've already done the work to null terminate key,
1057  * and strip off any leading spaces for both of these.
1058  * We have not touched the newline at the end of the line -
1059  * these are needed for some values. the end pointer
1060  * points to the first of the newlines.
1061  * value could be NULL! It would be easy enough to just point
1062  * this to "" to prevent cores, but that would let more errors slide
1063  * through.
1064  *
1065  * First check for entries that do not use the value parameter, then
1066  * validate that value is given and check for the remaining entries
1067  * that use the parameter.
1068  */
1069 
1070  if (!strcmp(key, "msg")) {
1071  char msgbuf[HUGE_BUF];
1072  int msgpos = 0;
1073 
1074  while (fgets(buf, sizeof(buf), fp) != NULL) {
1075  if (!strcmp(buf, "endmsg\n"))
1076  break;
1077  else {
1078  snprintf(msgbuf+msgpos, sizeof(msgbuf)-msgpos, "%s", buf);
1079  msgpos += strlen(buf);
1080  }
1081  }
1082  /* There are lots of maps that have empty messages (eg, msg/endmsg
1083  * with nothing between). There is no reason in those cases to
1084  * keep the empty message. Also, msgbuf contains garbage data
1085  * when msgpos is zero, so copying it results in crashes
1086  */
1087  if (msgpos != 0) {
1088  /* When loading eg an overlay, message is already set, so free() current one. */
1089  free(m->msg);
1090  m->msg = strdup_local(msgbuf);
1091  }
1092  } else if (!strcmp(key, "maplore")) {
1093  char maplorebuf[HUGE_BUF];
1094  size_t maplorepos = 0;
1095 
1096  while (fgets(buf, HUGE_BUF-1, fp) != NULL) {
1097  if (!strcmp(buf, "endmaplore\n"))
1098  break;
1099  else {
1100  if (maplorepos >= sizeof(maplorebuf)) {
1101  LOG(llevError, "Map lore exceeds buffer length\n");
1102  return 1;
1103  }
1104  snprintf(maplorebuf+maplorepos, sizeof(maplorebuf)-maplorepos, "%s", buf);
1105  maplorepos += strlen(buf);
1106  }
1107  }
1108  if (maplorepos != 0)
1109  m->maplore = strdup_local(maplorebuf);
1110  } else if (!strcmp(key, "end")) {
1111  break;
1112  } else if (value == NULL) {
1113  LOG(llevError, "Got '%s' line without parameter in map header\n", key);
1114  } else if (!strcmp(key, "arch")) {
1115  /* This is an oddity, but not something we care about much. */
1116  if (strcmp(value, "map")) {
1117  LOG(llevError, "load_map_header: expected 'arch map': check line endings?\n");
1118  return 1;
1119  }
1120  } else if (!strcmp(key, "name")) {
1121  /* When loading eg an overlay, the name is already set, so free() current one. */
1122  free(m->name);
1123  m->name = strdup_local(value);
1124  /* first strcmp value on these are old names supported
1125  * for compatibility reasons. The new values (second) are
1126  * what really should be used.
1127  */
1128  } else if (!strcmp(key, "enter_x")) {
1129  m->enter_x = atoi(value);
1130  } else if (!strcmp(key, "enter_y")) {
1131  m->enter_y = atoi(value);
1132  } else if (!strcmp(key, "width")) {
1133  m->width = atoi(value);
1134  } else if (!strcmp(key, "height")) {
1135  m->height = atoi(value);
1136  } else if (!strcmp(key, "reset_timeout")) {
1137  m->reset_timeout = atoi(value);
1138  } else if (!strcmp(key, "swap_time")) {
1139  m->timeout = atoi(value);
1140  } else if (!strcmp(key, "difficulty")) {
1141  m->difficulty = atoi(value);
1142  } else if (!strcmp(key, "darkness")) {
1143  m->darkness = atoi(value);
1144  } else if (!strcmp(key, "fixed_resettime")) {
1145  m->fixed_resettime = atoi(value);
1146  } else if (!strcmp(key, "unique")) {
1147  m->unique = atoi(value);
1148  } else if (!strcmp(key, "template")) {
1149  m->is_template = atoi(value);
1150  } else if (!strcmp(key, "region")) {
1151  m->region = get_region_by_name(value);
1152  } else if (!strcmp(key, "shopitems")) {
1153  m->shopitems = parse_shop_string(value, m);
1154  } else if (!strcmp(key, "shopgreed")) {
1155  m->shopgreed = atof(value);
1156  } else if (!strcmp(key, "shopmin")) {
1157  m->shopmin = atol(value);
1158  } else if (!strcmp(key, "shopmax")) {
1159  m->shopmax = atol(value);
1160  } else if (!strcmp(key, "shoprace")) {
1161  m->shoprace = strdup_local(value);
1162  } else if (!strcmp(key, "outdoor")) {
1163  m->outdoor = atoi(value);
1164  } else if (!strcmp(key, "nosmooth")) {
1165  m->nosmooth = atoi(value);
1166  } else if (!strcmp(key, "first_load")) {
1167  m->last_reset_time = atoi(value);
1168  } else if (!strncmp(key, "tile_path_", 10)) {
1169  int tile = atoi(key+10);
1170 
1171  if (tile < 1 || tile > 4) {
1172  LOG(llevError, "load_map_header: tile location %d out of bounds (%s)\n", tile, m->path);
1173  } else {
1174  if (m->tile_path[tile-1]) {
1175  LOG(llevError, "load_map_header: tile location %d duplicated (%s)\n", tile, m->path);
1176  free(m->tile_path[tile-1]);
1177  }
1178  m->tile_path[tile-1] = strdup_local(value);
1179  } /* end if tile direction (in)valid */
1180  } else if (!strcmp(key, "background_music")) {
1181  m->background_music = strdup_local(value);
1182  } else if (!strcmp(key, "reset_group")) {
1183  m->reset_group = add_string(value);
1184  } else {
1185  LOG(llevError, "Got unknown value in map header: %s %s\n", key, value);
1186  }
1187  }
1188  if ((m->width == 0) || (m->height == 0)) {
1189  LOG(llevError, "Map width or height not specified\n");
1190  return 1;
1191  }
1192  if (!key || strcmp(key, "end")) {
1193  LOG(llevError, "Got premature eof on map header!\n");
1194  return 1;
1195  }
1196  return 0;
1197 }
1198 
1214 mapstruct *mapfile_load(const char *map, int flags) {
1215  FILE *fp;
1216  mapstruct *m;
1217  char pathname[MAX_BUF];
1218 
1219  PROFILE_BEGIN();
1220 
1221  if (flags&MAP_PLAYER_UNIQUE) {
1222  snprintf(pathname, sizeof(pathname), "%s/%s/%s", settings.localdir, settings.playerdir, map+1);
1223  }
1224  else if (flags&MAP_OVERLAY)
1225  create_overlay_pathname(map, pathname, MAX_BUF);
1226  else
1227  create_pathname(map, pathname, MAX_BUF);
1228 
1229  if ((fp = fopen(pathname, "r")) == NULL) {
1231  "Can't open %s: %s\n", pathname, strerror(errno));
1232  return (NULL);
1233  }
1234 
1235  m = get_linked_map();
1236 
1237  safe_strncpy(m->path, map, HUGE_BUF);
1238  if (load_map_header(fp, m)) {
1239  LOG(llevError, "Error loading map header for %s, flags=%d\n", map, flags);
1240  delete_map(m);
1241  fclose(fp);
1242  return NULL;
1243  }
1244 
1245  allocate_map(m);
1246 
1247  m->in_memory = MAP_LOADING;
1248  load_objects(m, fp, flags & MAP_STYLE);
1249  fclose(fp);
1250  m->in_memory = MAP_IN_MEMORY;
1251  if (!MAP_DIFFICULTY(m) && (!(flags & MAP_NO_DIFFICULTY)))
1254 
1255  /* In case other objects press some buttons down */
1256  update_buttons(m);
1257 
1259 
1260  if (!(flags & MAP_STYLE))
1261  apply_auto_fix(m); /* Chests which open as default */
1262 
1263  PROFILE_END(diff,
1264  LOG(llevDebug, "mapfile_load on %s" " took %ld us\n", map, diff));
1265 
1266  return (m);
1267 }
1268 
1278  FILE *fp;
1279 
1280  if (!m->tmpname) {
1281  LOG(llevError, "No temporary filename for map %s\n", m->path);
1282  return 1;
1283  }
1284 
1285  if ((fp = fopen(m->tmpname, "r")) == NULL) {
1286  LOG(llevError, "Cannot open %s: %s\n", m->tmpname, strerror(errno));
1287  return 2;
1288  }
1289 
1290  if (load_map_header(fp, m)) {
1291  LOG(llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1292  fclose(fp);
1293  return 3;
1294  }
1295  allocate_map(m);
1296 
1297  m->in_memory = MAP_LOADING;
1298  load_objects(m, fp, 0);
1299  fclose(fp);
1300  m->in_memory = MAP_IN_MEMORY;
1301  return 0;
1302 }
1303 
1313 static int load_overlay_map(const char *filename, mapstruct *m) {
1314  FILE *fp;
1315  char pathname[MAX_BUF];
1316 
1318 
1319  if ((fp = fopen(pathname, "r")) == NULL) {
1320  /* nothing bad to not having an overlay */
1321  return 0;
1322  }
1323 
1324  if (load_map_header(fp, m)) {
1325  LOG(llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1326  fclose(fp);
1327  return 1;
1328  }
1329  /*allocate_map(m);*/
1330 
1331  m->in_memory = MAP_LOADING;
1332  load_objects(m, fp, MAP_OVERLAY);
1333  fclose(fp);
1334  m->in_memory = MAP_IN_MEMORY;
1335  return 0;
1336 }
1337 
1338 /******************************************************************************
1339  * This is the start of unique map handling code
1340  *****************************************************************************/
1341 
1349  int i, j, unique = 0;
1350 
1351  for (i = 0; i < MAP_WIDTH(m); i++)
1352  for (j = 0; j < MAP_HEIGHT(m); j++) {
1353  unique = 0;
1354  FOR_MAP_PREPARE(m, i, j, op) {
1356  unique = 1;
1357  if (op->head == NULL && (QUERY_FLAG(op, FLAG_UNIQUE) || unique)) {
1358  clean_object(op);
1361  object_remove(op);
1363  }
1364  } FOR_MAP_FINISH();
1365  }
1366 }
1367 
1374  FILE *fp;
1375  int count;
1376  char firstname[MAX_BUF], name[MAX_BUF];
1377 
1378  create_items_path(m->path, name, MAX_BUF);
1379  for (count = 0; count < 10; count++) {
1380  snprintf(firstname, sizeof(firstname), "%s.v%02d", name, count);
1381  if (!access(firstname, R_OK))
1382  break;
1383  }
1384  /* If we get here, we did not find any map */
1385  if (count == 10)
1386  return;
1387 
1388  if ((fp = fopen(firstname, "r")) == NULL) {
1389  /* There is no expectation that every map will have unique items, but this
1390  * is debug output, so leave it in.
1391  */
1392  LOG(llevDebug, "Can't open unique items file for %s\n", name);
1393  return;
1394  }
1395 
1396  m->in_memory = MAP_LOADING;
1397  if (m->tmpname == NULL) /* if we have loaded unique items from */
1398  delete_unique_items(m); /* original map before, don't duplicate them */
1399  load_object(fp, NULL, LO_NOREAD, 0);
1400  load_objects(m, fp, 0);
1401  fclose(fp);
1402  m->in_memory = MAP_IN_MEMORY;
1403 }
1404 
1420 int save_map(mapstruct *m, int flag) {
1421  FILE *fp, *fp2;
1422  OutputFile of, of2;
1423  char filename[MAX_BUF], shop[MAX_BUF];
1424  int i, res;
1425 
1426  if (flag && !*m->path) {
1427  LOG(llevError, "Tried to save map without path.\n");
1428  return SAVE_ERROR_NO_PATH;
1429  }
1430 
1431  PROFILE_BEGIN();
1432 
1433  if (flag != SAVE_MODE_NORMAL || (m->unique) || (m->is_template)) {
1434  if (!m->unique && !m->is_template) { /* flag is set */
1435  if (flag == SAVE_MODE_OVERLAY)
1437  else
1438  create_pathname(m->path, filename, MAX_BUF);
1439  } else {
1440  if (m->path[0] != '~') {
1441  LOG(llevError,
1442  "Cannot save unique map '%s' outside of LOCALDIR. Check "
1443  "that all exits to '%s' have FLAG_UNIQUE set correctly.\n",
1444  m->path, m->path);
1445  return SAVE_ERROR_UCREATION;
1446  }
1447  snprintf(filename, sizeof(filename), "%s/%s/%s", settings.localdir, settings.playerdir, m->path+1);
1448  }
1449 
1451  } else {
1452  if (!m->tmpname)
1453  m->tmpname = tempnam(settings.tmpdir, NULL);
1454  strlcpy(filename, m->tmpname, sizeof(filename));
1455  }
1456  m->in_memory = MAP_SAVING;
1457 
1458  fp = of_open(&of, filename);
1459  if (fp == NULL)
1460  return SAVE_ERROR_RCREATION;
1461 
1462  /* legacy */
1463  fprintf(fp, "arch map\n");
1464  if (m->name)
1465  fprintf(fp, "name %s\n", m->name);
1466  if (!flag)
1467  fprintf(fp, "swap_time %d\n", m->swap_time);
1468  if (m->reset_timeout)
1469  fprintf(fp, "reset_timeout %u\n", m->reset_timeout);
1470  if (m->fixed_resettime)
1471  fprintf(fp, "fixed_resettime %d\n", m->fixed_resettime);
1472  /* we unfortunately have no idea if this is a value the creator set
1473  * or a difficulty value we generated when the map was first loaded
1474  */
1475  if (m->difficulty)
1476  fprintf(fp, "difficulty %d\n", m->difficulty);
1477  if (m->region)
1478  fprintf(fp, "region %s\n", m->region->name);
1479  if (m->shopitems) {
1480  print_shop_string(m, shop, sizeof(shop));
1481  fprintf(fp, "shopitems %s\n", shop);
1482  }
1483  if (m->shopgreed)
1484  fprintf(fp, "shopgreed %f\n", m->shopgreed);
1485  if (m->shopmin)
1486  fprintf(fp, "shopmin %"FMT64U"\n", m->shopmin);
1487  if (m->shopmax)
1488  fprintf(fp, "shopmax %"FMT64U"\n", m->shopmax);
1489  if (m->shoprace)
1490  fprintf(fp, "shoprace %s\n", m->shoprace);
1491  if (m->darkness)
1492  fprintf(fp, "darkness %d\n", m->darkness);
1493  if (m->width)
1494  fprintf(fp, "width %d\n", m->width);
1495  if (m->height)
1496  fprintf(fp, "height %d\n", m->height);
1497  if (m->enter_x)
1498  fprintf(fp, "enter_x %d\n", m->enter_x);
1499  if (m->enter_y)
1500  fprintf(fp, "enter_y %d\n", m->enter_y);
1501  if (m->msg)
1502  fprintf(fp, "msg\n%sendmsg\n", m->msg);
1503  if (m->maplore)
1504  fprintf(fp, "maplore\n%sendmaplore\n", m->maplore);
1505  if (m->unique)
1506  fprintf(fp, "unique %d\n", m->unique);
1507  if (m->is_template)
1508  fprintf(fp, "template %d\n", m->is_template);
1509  if (m->outdoor)
1510  fprintf(fp, "outdoor %d\n", m->outdoor);
1511  if (m->nosmooth)
1512  fprintf(fp, "nosmooth %d\n", m->nosmooth);
1513  if (m->last_reset_time)
1514  fprintf(fp, "first_load %ld\n", m->last_reset_time);
1515  if (m->background_music)
1516  fprintf(fp, "background_music %s\n", m->background_music);
1517  if (m->reset_group)
1518  fprintf(fp, "reset_group %s\n", m->reset_group);
1519 
1520  /* Save any tiling information, except on overlays */
1521  if (flag != SAVE_MODE_OVERLAY)
1522  for (i = 0; i < 4; i++)
1523  if (m->tile_path[i])
1524  fprintf(fp, "tile_path_%d %s\n", i+1, m->tile_path[i]);
1525 
1526  fprintf(fp, "end\n");
1527 
1528  /* In the game save unique items in the different file, but
1529  * in the editor save them to the normal map file.
1530  * If unique map, save files in the proper destination (set by
1531  * player)
1532  */
1533  if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->is_template) {
1534  char name[MAX_BUF], final_unique[MAX_BUF];
1535 
1536  create_items_path(m->path, name, MAX_BUF);
1537  snprintf(final_unique, sizeof(final_unique), "%s.v00", name);
1538  fp2 = of_open(&of2, final_unique);
1539  if (fp2 == NULL) {
1540  of_cancel(&of);
1541  return SAVE_ERROR_UCREATION;
1542  }
1543  if (flag == SAVE_MODE_OVERLAY) {
1544  /* SO_FLAG_NO_REMOVE is non destructive save, so map is still valid. */
1545  res = save_objects(m, fp, fp2, SAVE_FLAG_NO_REMOVE);
1546  if (res < 0) {
1547  LOG(llevError, "Save error during object save: %d\n", res);
1548  of_cancel(&of);
1549  of_cancel(&of2);
1550  return res;
1551  }
1552  m->in_memory = MAP_IN_MEMORY;
1553  } else {
1554  res = save_objects(m, fp, fp2, 0);
1555  if (res < 0) {
1556  LOG(llevError, "Save error during object save: %d\n", res);
1557  of_cancel(&of);
1558  of_cancel(&of2);
1559  return res;
1560  }
1562  }
1563  if (ftell(fp2) == 0) {
1564  of_cancel(&of2);
1565  /* If there are no unique items left on the map, we need to
1566  * unlink the original unique map so that the unique
1567  * items don't show up again.
1568  */
1569  unlink(final_unique);
1570  } else {
1571  if (!of_close(&of2)) {
1572  of_cancel(&of);
1573  return SAVE_ERROR_URENAME;
1574  }
1575 
1576  if (chmod(final_unique, SAVE_MODE) != 0) {
1577  LOG(llevError, "Could not set permissions on '%s'\n",
1578  final_unique);
1579  }
1580  }
1581  } else { /* save same file when not playing, like in editor */
1582  res = save_objects(m, fp, fp, 0);
1583  if (res < 0) {
1584  LOG(llevError, "Save error during object save: %d\n", res);
1585  of_cancel(&of);
1586  return res;
1587  }
1589  }
1590 
1591  if (!of_close(&of))
1592  return SAVE_ERROR_CLOSE;
1593 
1594  if (chmod(filename, SAVE_MODE) != 0) {
1595  LOG(llevError, "Could not set permissions on '%s'\n", filename);
1596  }
1597 
1598  PROFILE_END(diff,
1599  LOG(llevDebug, "save_map on %s" " took %ld us\n", m->path, diff));
1600 
1601  return SAVE_ERROR_OK;
1602 }
1603 
1613 void clean_object(object *op) {
1614  FOR_INV_PREPARE(op, tmp) {
1615  clean_object(tmp);
1618  object_remove(tmp);
1620  } FOR_INV_FINISH();
1621 }
1622 
1630  int i, j;
1631  object *op;
1632 
1633  for (i = 0; i < MAP_WIDTH(m); i++)
1634  for (j = 0; j < MAP_HEIGHT(m); j++) {
1635  object *previous_obj = NULL;
1636 
1637  while ((op = GET_MAP_OB(m, i, j)) != NULL) {
1638  if (op == previous_obj) {
1639  LOG(llevDebug, "free_all_objects: Link error, bailing out.\n");
1640  break;
1641  }
1642  previous_obj = op;
1643  op = HEAD(op);
1644 
1645  /* If the map isn't in memory, object_free_drop_inventory() will remove and
1646  * free objects in op's inventory. So let it do the job.
1647  */
1648  if (m->in_memory == MAP_IN_MEMORY)
1649  clean_object(op);
1650  object_remove(op);
1652  }
1653  }
1654 #ifdef MANY_CORES
1655  /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1656  * an item on that map was not saved - look for that condition and die as appropriate -
1657  * this leaves more of the map data intact for better debugging.
1658  */
1659  for (op = objects; op != NULL; op = op->next) {
1660  if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1661  LOG(llevError, "free_all_objects: object %s still on map after it should have been freed\n", op->name);
1662  abort();
1663  }
1664  }
1665 #endif
1666 }
1667 
1677  int i;
1678 
1679  if (!m->in_memory) {
1680  LOG(llevError, "Trying to free freed map.\n");
1681  return;
1682  }
1683 
1685 
1686  if (m->spaces)
1688  if (m->name)
1689  FREE_AND_CLEAR(m->name);
1690  if (m->spaces)
1691  FREE_AND_CLEAR(m->spaces);
1692  if (m->msg)
1693  FREE_AND_CLEAR(m->msg);
1694  if (m->maplore)
1695  FREE_AND_CLEAR(m->maplore);
1696  if (m->shopitems)
1697  FREE_AND_CLEAR(m->shopitems);
1698  if (m->shoprace)
1699  FREE_AND_CLEAR(m->shoprace);
1700  if (m->background_music)
1701  FREE_AND_CLEAR(m->background_music);
1702  if (m->buttons)
1703  free_objectlinkpt(m->buttons);
1704  m->buttons = NULL;
1705  for (i = 0; i < 4; i++) {
1706  if (m->tile_path[i])
1707  FREE_AND_CLEAR(m->tile_path[i]);
1708  m->tile_map[i] = NULL;
1709  }
1710  m->in_memory = MAP_SWAPPED;
1711 }
1712 
1723  mapstruct *tmp, *last;
1724  int i;
1725 
1726  if (!m)
1727  return;
1728  if (m->in_memory == MAP_IN_MEMORY) {
1729  /* change to MAP_SAVING, even though we are not,
1730  * so that object_remove() doesn't do as much work.
1731  */
1732  m->in_memory = MAP_SAVING;
1733  free_map(m);
1734  }
1735  /* move this out of free_map, since tmpname can still be needed if
1736  * the map is swapped out.
1737  */
1738  free(m->tmpname);
1739  m->tmpname = NULL;
1740  FREE_AND_CLEAR_STR_IF(m->reset_group);
1741  last = NULL;
1742  /* We need to look through all the maps and see if any maps
1743  * are pointing at this one for tiling information. Since
1744  * tiling can be assymetric, we just can not look to see which
1745  * maps this map tiles with and clears those.
1746  */
1747  for (tmp = first_map; tmp != NULL; tmp = tmp->next) {
1748  if (tmp->next == m)
1749  last = tmp;
1750 
1751  /* This should hopefully get unrolled on a decent compiler */
1752  for (i = 0; i < 4; i++)
1753  if (tmp->tile_map[i] == m)
1754  tmp->tile_map[i] = NULL;
1755  }
1756 
1757  /* If last is null, then this should be the first map in the list */
1758  if (!last) {
1759  if (m == first_map)
1760  first_map = m->next;
1761  else
1762  /* m->path is a static char, so should hopefully still have
1763  * some useful data in it.
1764  */
1765  LOG(llevError, "delete_map: Unable to find map %s in list\n", m->path);
1766  } else
1767  last->next = m->next;
1768 
1769  free(m);
1770 }
1771 
1785 mapstruct *ready_map_name(const char *name, int flags) {
1786  mapstruct *m;
1787 
1788  if (!name)
1789  return (NULL);
1790 
1791  /* Have we been at this level before? */
1792  m = has_been_loaded(name);
1793 
1794  /* Map is good to go, so just return it */
1795  if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) {
1796  return m;
1797  }
1798 
1799  /* Rewrite old paths starting with LOCALDIR/PLAYERDIR to new '~' paths. */
1800  char buf[MAX_BUF], buf2[MAX_BUF];
1801  snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, settings.playerdir);
1802  if (strncmp(name, buf, strlen(buf)) == 0) {
1803  snprintf(buf2, sizeof(buf2), "~%s", name+strlen(buf)+1);
1804  name = buf2;
1805  }
1806 
1807  /* Paths starting with '~' are unique. */
1808  if (name[0] == '~') {
1810  }
1811 
1812  /* unique maps always get loaded from their original location, and never
1813  * a temp location. Likewise, if map_flush is set, or we have never loaded
1814  * this map, load it now. I removed the reset checking from here -
1815  * it seems the probability of a player trying to enter a map that should
1816  * reset but hasn't yet is quite low, and removing that makes this function
1817  * a bit cleaner (and players probably shouldn't rely on exact timing for
1818  * resets in any case - if they really care, they should use the 'maps command.
1819  */
1820  if ((flags&(MAP_FLUSH|MAP_PLAYER_UNIQUE)) || !m) {
1821  /* first visit or time to reset */
1822  if (m) {
1823  clean_tmp_map(m); /* Doesn't make much difference */
1824  delete_map(m);
1825  }
1826 
1828  if (m == NULL) return NULL;
1829 
1830  /* If a player unique map, no extra unique object file to load.
1831  * if from the editor, likewise.
1832  */
1835 
1837  if (load_overlay_map(name, m) != 0) {
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  }
1845  }
1846  } else {
1847  /* If in this loop, we found a temporary map, so load it up. */
1848 
1849  if (load_temporary_map(m) != 0) {
1850  /*
1851  * There was a failure loading the temporary map, fall back to original one.
1852  * load_temporary_map() already logged the error.
1853  */
1854  delete_map(m);
1855  m = mapfile_load(name, 0);
1856  if (m == NULL) {
1857  /* Really, this map is bad :( */
1858  return NULL;
1859  }
1860  }
1862 
1863  clean_tmp_map(m);
1864  m->in_memory = MAP_IN_MEMORY;
1865  /* tempnam() on sun systems (probably others) uses malloc
1866  * to allocated space for the string. Free it here.
1867  * In some cases, load_temporary_map above won't find the
1868  * temporary map, and so has reloaded a new map. If that
1869  * is the case, tmpname is now null
1870  */
1871  free(m->tmpname);
1872  m->tmpname = NULL;
1873  /* It's going to be saved anew anyway */
1874  }
1875 
1876  /* Below here is stuff common to both first time loaded maps and
1877  * temp maps.
1878  */
1879 
1880  decay_objects(m); /* start the decay */
1881 
1882  if (m->outdoor)
1884 
1885  if (!(flags&(MAP_FLUSH))) {
1886  if (m->last_reset_time == 0) {
1887  m->last_reset_time = seconds();
1888  }
1889  }
1890 
1892 
1893  return m;
1894 }
1895 
1912  archetype *at;
1913  int x, y;
1914  int diff = 0;
1915  int i;
1916  int64_t exp_pr_sq, total_exp = 0;
1917 
1918  if (MAP_DIFFICULTY(m)) {
1919  return MAP_DIFFICULTY(m);
1920  }
1921 
1922  for (x = 0; x < MAP_WIDTH(m); x++)
1923  for (y = 0; y < MAP_HEIGHT(m); y++)
1924  FOR_MAP_PREPARE(m, x, y, op) {
1925  if (QUERY_FLAG(op, FLAG_MONSTER))
1926  total_exp += op->stats.exp;
1928  total_exp += op->stats.exp;
1929  // If we have an other_arch on our generator, just use that.
1930  // FIXME: Figure out what to do if we are doing template generation from inventory.
1931  at = op->other_arch ? op->other_arch : NULL;
1932  if (at != NULL) {
1933  // Make sure we can't set off a null pointer dereference in atoi().
1934  const char *val = object_get_value(op, "generator_limit");
1935  int lim = atoi(val ? val : "0");
1936  // We assume, on average, the generator will generate half its contents.
1937  if (!lim || lim >= 16)
1938  total_exp += at->clone.stats.exp*8;
1939  else
1940  total_exp += at->clone.stats.exp*(lim/2);
1941  }
1942  }
1943  } FOR_MAP_FINISH();
1944  // Used to be multiplied by 1000, but this undershot horribly
1945  // once I fixed the calculation for generators.
1946  // I'm trying out some exponentiation, since linear scaling
1947  // seems to overshoot low-level maps and undershoot high-level maps.
1948  // I also feel comfortable, knowing that generators return
1949  // sensible values, to up the max diff this calculates from 20 to 25.
1950  // - Daniel Hawkins 2021-03-04
1951  exp_pr_sq = (pow(total_exp, 1.75))/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1);
1952  diff = 25;
1953  for (i = 1; i < 25; i++)
1954  if (exp_pr_sq <= level_exp(i, 1.0)) {
1955  diff = i;
1956  break;
1957  }
1958 
1959  return diff;
1960 }
1961 
1969  if (m->tmpname == NULL)
1970  return;
1971  (void)unlink(m->tmpname);
1972 }
1973 
1977 void free_all_maps(void) {
1978  int real_maps = 0;
1979 
1980  while (first_map) {
1981  /* I think some of the callers above before it gets here set this to be
1982  * saving, but we still want to free this data
1983  */
1984  if (first_map->in_memory == MAP_SAVING)
1987  real_maps++;
1988  }
1989  LOG(llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1990 }
1991 
2009 int change_map_light(mapstruct *m, int change) {
2010  int new_level = m->darkness+change;
2011 
2012  /* Nothing to do */
2013  if (!change
2014  || (new_level <= 0 && m->darkness == 0)
2015  || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) {
2016  return 0;
2017  }
2018 
2019  /* inform all players on the map */
2020  if (change > 0)
2021  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes darker.");
2022  else
2023  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes brighter.");
2024 
2025  /* Do extra checking. since m->darkness is a unsigned value,
2026  * we need to be extra careful about negative values.
2027  * In general, the checks below are only needed if change
2028  * is not +/-1
2029  */
2030  if (new_level < 0)
2031  m->darkness = 0;
2032  else if (new_level >= MAX_DARKNESS)
2033  m->darkness = MAX_DARKNESS;
2034  else
2035  m->darkness = new_level;
2036 
2037  /* All clients need to get re-updated for the change */
2039  return 1;
2040 }
2041 
2064 static inline void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) {
2065  int l, l1;
2066  object *tmp;
2067 
2068  for (l = low_layer; l <= high_layer; l++) {
2069  if (!layers[l]) {
2070  /* found an empty spot. now, we want to make sure
2071  * highest visibility at top, etc.
2072  */
2073  layers[l] = ob;
2074  if (!honor_visibility)
2075  return;
2076 
2077  /* This is basically a mini bubble sort. Only swap
2078  * position if the lower face has greater (not equal)
2079  * visibility - map stacking is secondary consideration here.
2080  */
2081  for (l1 = (l-1); l1 >= low_layer; l1--) {
2082  if (layers[l1]->face->visibility > layers[l1+1]->face->visibility) {
2083  tmp = layers[l1+1];
2084  layers[l1+1] = layers[l1];
2085  layers[l1] = tmp;
2086  }
2087  }
2088  /* Nothing more to do - face inserted */
2089  return;
2090  }
2091  }
2092  /* If we get here, all the layers have an object..
2093  */
2094  if (!honor_visibility) {
2095  /* Basically, in this case, it is pure stacking logic, so
2096  * new object goes on the top.
2097  */
2098  for (l = low_layer; l < high_layer; l++)
2099  layers[l] = layers[l+1];
2100  layers[high_layer] = ob;
2101  /* If this object doesn't have higher visibility than
2102  * the lowest object, no reason to go further.
2103  */
2104  } else if (ob->face->visibility >= layers[low_layer]->face->visibility) {
2105  /*
2106  * Start at the top (highest visibility) layer and work down.
2107  * once this face exceed that of the layer, push down those
2108  * other layers, and then replace the layer with our object.
2109  */
2110  for (l = high_layer; l >= low_layer; l--) {
2111  if (ob->face->visibility >= layers[l]->face->visibility) {
2112  for (l1 = low_layer; l1 < l; l1++)
2113  layers[l1] = layers[l1+1];
2114  layers[l] = ob;
2115  break;
2116  }
2117  }
2118  }
2119 }
2120 
2133 void update_position(mapstruct *m, int x, int y) {
2134  object *player = NULL;
2135  uint8_t flags = 0, oldflags, light = 0;
2136  object *layers[MAP_LAYERS];
2137 
2138  MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2139 
2140  oldflags = GET_MAP_FLAGS(m, x, y);
2141  if (!(oldflags&P_NEED_UPDATE)) {
2142  LOG(llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
2143  return;
2144  }
2145 
2146  memset(layers, 0, MAP_LAYERS*sizeof(object *));
2147 
2148  FOR_MAP_PREPARE(m, x, y, tmp) {
2149  /* DMs just don't do anything when hidden, including no light. */
2150  if (QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden)
2151  continue;
2152 
2153  if (tmp->type == PLAYER)
2154  player = tmp;
2155 
2156  /* This could be made additive I guess (two lights better than
2157  * one). But if so, it shouldn't be a simple additive - 2
2158  * light bulbs do not illuminate twice as far as once since
2159  * it is a dissipation factor that is squared (or is it cubed?)
2160  */
2161  if (tmp->glow_radius > light)
2162  light = tmp->glow_radius;
2163 
2164  /* if this object is visible and not a blank face,
2165  * update the objects that show how this space
2166  * looks.
2167  */
2168  if (!tmp->invisible && tmp->face != blank_face) {
2169  if (tmp->map_layer) {
2170  add_face_layer(tmp->map_layer, map_layer_info[tmp->map_layer].high_layer,
2171  tmp, layers, map_layer_info[tmp->map_layer].honor_visibility);
2172  } else if (tmp->move_type&MOVE_FLYING) {
2174  } else if ((tmp->type == PLAYER || QUERY_FLAG(tmp, FLAG_MONSTER))) {
2176  } else if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2177  layers[MAP_LAYER_FLOOR] = tmp;
2178  /* floors hide everything else */
2179  memset(layers+1, 0, (MAP_LAYERS-1)*sizeof(object *));
2180  /* Check for FLAG_SEE_ANYWHERE is removed - objects
2181  * with that flag should just have a high visibility
2182  * set - we shouldn't need special code here.
2183  */
2184  } else if (QUERY_FLAG(tmp, FLAG_NO_PICK)) {
2186  } else {
2188  }
2189  }
2190  if (tmp == tmp->above) {
2191  LOG(llevError, "Error in structure of map\n");
2192  exit(-1);
2193  }
2194 
2195  move_slow |= tmp->move_slow;
2196  move_block |= tmp->move_block;
2197  move_on |= tmp->move_on;
2198  move_off |= tmp->move_off;
2199  move_allow |= tmp->move_allow;
2200 
2201  if (QUERY_FLAG(tmp, FLAG_ALIVE))
2202  flags |= P_IS_ALIVE;
2204  flags |= P_NO_MAGIC;
2206  flags |= P_NO_CLERIC;
2207 
2209  flags |= P_BLOCKSVIEW;
2210  } FOR_MAP_FINISH(); /* for stack of objects */
2211 
2212  if (player)
2213  flags |= P_PLAYER;
2214 
2215  /* we don't want to rely on this function to have accurate flags, but
2216  * since we're already doing the work, we calculate them here.
2217  * if they don't match, logic is broken someplace.
2218  */
2219  if (((oldflags&~(P_NEED_UPDATE|P_NO_ERROR)) != flags)
2220  && (!(oldflags&P_NO_ERROR))) {
2221  LOG(llevDebug, "update_position: updated flags do not match old flags: %s (x=%d,y=%d) %x != %x\n",
2222  m->path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2223  }
2224 
2225  SET_MAP_FLAGS(m, x, y, flags);
2226  SET_MAP_MOVE_BLOCK(m, x, y, move_block&~move_allow);
2227  SET_MAP_MOVE_ON(m, x, y, move_on);
2228  SET_MAP_MOVE_OFF(m, x, y, move_off);
2229  SET_MAP_MOVE_SLOW(m, x, y, move_slow);
2230  SET_MAP_LIGHT(m, x, y, light);
2231 
2232  /* Note that player may be NULL here, which is fine - if no player, need
2233  * to clear any value that may be set.
2234  */
2235  SET_MAP_PLAYER(m, x, y, player);
2236 
2237  /* Note it is intentional we copy everything, including NULL values. */
2238  memcpy(GET_MAP_FACE_OBJS(m, x, y), layers, sizeof(object *)*MAP_LAYERS);
2239 }
2240 
2248  int timeout;
2249 
2250  timeout = MAP_RESET_TIMEOUT(map);
2251  if (timeout <= 0)
2252  timeout = MAP_DEFAULTRESET;
2253  if (timeout >= MAP_MAXRESET)
2254  timeout = MAP_MAXRESET;
2255  MAP_RESET_TIMEOUT(map) = timeout;
2256  MAP_WHEN_RESET(map) = seconds()+timeout;
2257 }
2258 
2273 static mapstruct *load_and_link_tiled_map(mapstruct *orig_map, int tile_num) {
2274  int dest_tile = (tile_num+2)%4;
2275  char path[HUGE_BUF];
2276 
2277  path_combine_and_normalize(orig_map->path, orig_map->tile_path[tile_num], path, sizeof(path));
2278 
2279  orig_map->tile_map[tile_num] = ready_map_name(path, 0);
2280  if (orig_map->tile_map[tile_num] == NULL) {
2281  LOG(llevError, "%s has invalid tiled map %s\n", orig_map->path, path);
2282  free(orig_map->tile_path[tile_num]);
2283  orig_map->tile_path[tile_num] = NULL;
2284  return NULL;
2285  }
2286 
2287  /* need to do a strcmp here as the orig_map->path is not a shared string */
2288  if (orig_map->tile_map[tile_num]->tile_path[dest_tile]
2289  && !strcmp(orig_map->tile_map[tile_num]->tile_path[dest_tile], orig_map->path))
2290  orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
2291 
2292  return orig_map->tile_map[tile_num];
2293 }
2294 
2312 int out_of_map(mapstruct *m, int x, int y) {
2313 
2314  /* Simple case - coordinates are within this local
2315  * map.
2316  */
2317  if (x >= 0 && x < MAP_WIDTH(m) && y >= 0 && y < MAP_HEIGHT(m))
2318  return 0;
2319 
2320  if (x < 0) {
2321  if (!m->tile_path[3])
2322  return 1;
2323  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) {
2325  /* Verify the tile map loaded correctly */
2326  if (!m->tile_map[3])
2327  return 0;
2328  }
2329  return (out_of_map(m->tile_map[3], x+MAP_WIDTH(m->tile_map[3]), y));
2330  } else if (x >= MAP_WIDTH(m)) {
2331  if (!m->tile_path[1])
2332  return 1;
2333  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) {
2335  /* Verify the tile map loaded correctly */
2336  if (!m->tile_map[1])
2337  return 0;
2338  }
2339  return (out_of_map(m->tile_map[1], x-MAP_WIDTH(m), y));
2340  }
2341 
2342  if (y < 0) {
2343  if (!m->tile_path[0])
2344  return 1;
2345  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) {
2347  /* Verify the tile map loaded correctly */
2348  if (!m->tile_map[0])
2349  return 0;
2350  }
2351  return (out_of_map(m->tile_map[0], x, y+MAP_HEIGHT(m->tile_map[0])));
2352  } else if (y >= MAP_HEIGHT(m)) {
2353  if (!m->tile_path[2])
2354  return 1;
2355  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) {
2357  /* Verify the tile map loaded correctly */
2358  if (!m->tile_map[2])
2359  return 0;
2360  }
2361  return (out_of_map(m->tile_map[2], x, y-MAP_HEIGHT(m)));
2362  }
2363  return 1;
2364 }
2365 
2385 mapstruct *get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y) {
2386 
2387  /* Simple case - coordinates are within this local
2388  * map.
2389  */
2390 
2391  if ( !m ) return NULL;
2392  if (*x >= 0 && *x < MAP_WIDTH(m) && *y >= 0 && *y < MAP_HEIGHT(m))
2393  return m;
2394 
2395  do /* With the first case there, we can assume we are out of the map if we get here */
2396  {
2397  // Figure out what map should be in the direction we are off the map, and then
2398  // load that map and look again.
2399  if (*x < 0) {
2400  if (!m->tile_path[3])
2401  return NULL;
2402  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY){
2404  /* Make sure we loaded properly. */
2405  if (!m->tile_map[3])
2406  return NULL;
2407  }
2408  *x += MAP_WIDTH(m->tile_map[3]);
2409  m = m->tile_map[3];
2410  }
2411  else if (*x >= MAP_WIDTH(m)) {
2412  if (!m->tile_path[1])
2413  return NULL;
2414  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY){
2416  /* Make sure we loaded properly. */
2417  if (!m->tile_map[1])
2418  return NULL;
2419  }
2420  *x -= MAP_WIDTH(m);
2421  m = m->tile_map[1];
2422  }
2423  // It is possible that x and y be considered separate compare groups,
2424  // But using an else-if here retains the old behavior that recursion produced.
2425  else if (*y < 0) {
2426  if (!m->tile_path[0])
2427  return NULL;
2428  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY){
2430  /* Make sure we loaded properly. */
2431  if (!m->tile_map[0])
2432  return NULL;
2433  }
2434  *y += MAP_HEIGHT(m->tile_map[0]);
2435  m = m->tile_map[0];
2436  }
2437  else if (*y >= MAP_HEIGHT(m)) {
2438  if (!m->tile_path[2])
2439  return NULL;
2440  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY){
2442  /* Make sure we loaded properly. */
2443  if (!m->tile_map[2])
2444  return NULL;
2445  }
2446  *y -= MAP_HEIGHT(m);
2447  m = m->tile_map[2];
2448  }
2449  // The check here is if our single tile is in the map.
2450  // That is exactly what the OUT_OF_MAP macro does.
2451  } while (OUT_OF_REAL_MAP(m, *x, *y));
2452  return m; /* We have found our map */
2453 }
2454 
2468 static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {
2469  if (!map1 || !map2)
2470  return 0;
2471 
2472  if (map1 == map2) {
2473  *dx = 0;
2474  *dy = 0;
2475  } else if (map1->tile_map[0] == map2) { /* up */
2476  *dx = 0;
2477  *dy = -MAP_HEIGHT(map2);
2478  } else if (map1->tile_map[1] == map2) { /* right */
2479  *dx = MAP_WIDTH(map1);
2480  *dy = 0;
2481  } else if (map1->tile_map[2] == map2) { /* down */
2482  *dx = 0;
2483  *dy = MAP_HEIGHT(map1);
2484  } else if (map1->tile_map[3] == map2) { /* left */
2485  *dx = -MAP_WIDTH(map2);
2486  *dy = 0;
2487  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) { /* up right */
2488  *dx = MAP_WIDTH(map1->tile_map[0]);
2489  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2490  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) { /* up left */
2491  *dx = -MAP_WIDTH(map2);
2492  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2493  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) { /* right up */
2494  *dx = MAP_WIDTH(map1);
2495  *dy = -MAP_HEIGHT(map2);
2496  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) { /* right down */
2497  *dx = MAP_WIDTH(map1);
2498  *dy = MAP_HEIGHT(map1->tile_map[1]);
2499  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) { /* down right */
2500  *dx = MAP_WIDTH(map1->tile_map[2]);
2501  *dy = MAP_HEIGHT(map1);
2502  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) { /* down left */
2503  *dx = -MAP_WIDTH(map2);
2504  *dy = MAP_HEIGHT(map1);
2505  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) { /* left up */
2506  *dx = -MAP_WIDTH(map1->tile_map[3]);
2507  *dy = -MAP_HEIGHT(map2);
2508  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) { /* left down */
2509  *dx = -MAP_WIDTH(map1->tile_map[3]);
2510  *dy = MAP_HEIGHT(map1->tile_map[3]);
2511  } else { /* not "adjacent" enough */
2512  return 0;
2513  }
2514 
2515  return 1;
2516 }
2517 
2545 int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags) {
2546  if (!adjacent_map(op1->map, op2->map, &retval->distance_x, &retval->distance_y)) {
2547  /* be conservative and fill in _some_ data */
2548  retval->distance = 100000;
2549  retval->distance_x = 32767;
2550  retval->distance_y = 32767;
2551  retval->direction = 0;
2552  retval->part = NULL;
2553  return 0;
2554  } else {
2555  object *best;
2556 
2557  retval->distance_x += op2->x-op1->x;
2558  retval->distance_y += op2->y-op1->y;
2559 
2560  best = op1;
2561  /* If this is multipart, find the closest part now */
2562  if (!(flags&0x1) && op1->more) {
2563  object *tmp;
2564  int best_distance = retval->distance_x*retval->distance_x+
2565  retval->distance_y*retval->distance_y, tmpi;
2566 
2567  /* we just take the offset of the piece to head to figure
2568  * distance instead of doing all that work above again
2569  * since the distance fields we set above are positive in the
2570  * same axis as is used for multipart objects, the simply arithmetic
2571  * below works.
2572  */
2573  for (tmp = op1->more; tmp != NULL; tmp = tmp->more) {
2574  tmpi = (op1->x-tmp->x+retval->distance_x)*(op1->x-tmp->x+retval->distance_x)+
2575  (op1->y-tmp->y+retval->distance_y)*(op1->y-tmp->y+retval->distance_y);
2576  if (tmpi < best_distance) {
2577  best_distance = tmpi;
2578  best = tmp;
2579  }
2580  }
2581  if (best != op1) {
2582  retval->distance_x += op1->x-best->x;
2583  retval->distance_y += op1->y-best->y;
2584  }
2585  }
2586  retval->part = best;
2587  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2588  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2589  return 1;
2590  }
2591 }
2592 
2618 int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags) {
2619  (void)flags; // unused [avoid compiler warning]
2620  if (!adjacent_map(m, op2->map, &retval->distance_x, &retval->distance_y)) {
2621  /* be conservative and fill in _some_ data */
2622  retval->distance = 100000;
2623  retval->distance_x = 32767;
2624  retval->distance_y = 32767;
2625  retval->direction = 0;
2626  retval->part = NULL;
2627  return 0;
2628  } else {
2629  retval->distance_x += op2->x-x;
2630  retval->distance_y += op2->y-y;
2631 
2632  retval->part = NULL;
2633  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2634  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2635  return 1;
2636  }
2637 }
2638 
2657 int on_same_map(const object *op1, const object *op2) {
2658  int dx, dy;
2659 
2660  return adjacent_map(op1->map, op2->map, &dx, &dy);
2661 }
2662 
2680 object *map_find_by_flag(mapstruct *map, int x, int y, int flag) {
2681  object *tmp;
2682 
2683  for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above) {
2684  object *head;
2685 
2686  head = HEAD(tmp);
2687  if (QUERY_FLAG(head, flag))
2688  return head;
2689  }
2690  return NULL;
2691 }
2692 
2698  char base[HUGE_BUF], path[HUGE_BUF];
2699  int count;
2700 
2701  if (map->unique) {
2702  snprintf(path, sizeof(path), "%s/%s/%s", settings.localdir, settings.playerdir, map->path+1);
2703  if (unlink(path) != 0) {
2704  LOG(llevError, "Could not delete %s: %s\n", path, strerror(errno));
2705  }
2706  return;
2707  }
2708 
2709  create_items_path(map->path, base, sizeof(base));
2710 
2711  for (count = 0; count < 10; count++) {
2712  snprintf(path, sizeof(path), "%s.v%02d", base, count);
2713  unlink(path);
2714  }
2715 }
2716 
2722 const char *map_get_path(const object *item) {
2723  if (item->map != NULL) {
2724  if (strlen(item->map->path) > 0) {
2725  return item->map->path;
2726  }
2727 
2728  return item->map->name ? item->map->name : "(empty path and name)";
2729  }
2730 
2731  if (item->env != NULL)
2732  return map_get_path(item->env);
2733 
2734  return "(no map and no env!)";
2735 }
get_linked_map
mapstruct * get_linked_map(void)
Definition: map.c:788
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
ready_map_name
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.c:1785
S_IWUSR
#define S_IWUSR
Definition: win32.h:47
of_cancel
void of_cancel(OutputFile *of)
Definition: output_file.c:89
PLAYER
@ PLAYER
Definition: object.h:107
Settings::mapdir
const char * mapdir
Definition: global.h:246
output_file.h
path.h
FREE_AND_CLEAR_STR_IF
#define FREE_AND_CLEAR_STR_IF(xyz)
Definition: global.h:197
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:531
object_free
void object_free(object *ob, int flags)
Definition: object.c:1578
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:568
banquet.l
l
Definition: banquet.py:164
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
object_remove
void object_remove(object *op)
Definition: object.c:1819
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
stringbuffer_new
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.c:57
SAVE_MODE
#define SAVE_MODE
Definition: config.h:555
object_sum_weight
signed long object_sum_weight(object *op)
Definition: object.c:572
MAP_SAVING
#define MAP_SAVING
Definition: map.h:134
obj::face
const Face * face
Definition: object.h:336
llevError
@ llevError
Definition: logger.h:11
MAP_NO_DIFFICULTY
#define MAP_NO_DIFFICULTY
Definition: map.h:98
MAP_LAYER_ITEM3
#define MAP_LAYER_ITEM3
Definition: map.h:45
MOVE_ALL
#define MOVE_ALL
Definition: define.h:398
check_path
int check_path(const char *name, int prepend_dir)
Definition: map.c:202
FLAG_OVERLAY_FLOOR
#define FLAG_OVERLAY_FLOOR
Definition: define.h:255
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
shopitem::name_pl
const char * name_pl
Definition: map.h:299
get_region_by_name
region * get_region_by_name(const char *region_name)
Definition: region.cpp:48
FLAG_GENERATOR
#define FLAG_GENERATOR
Definition: define.h:248
MAP_RESET_TIMEOUT
#define MAP_RESET_TIMEOUT(m)
Definition: map.h:64
load_object
int load_object(FILE *fp, object *op, int bufstate, int map_flags)
Definition: loader.c:5205
strdup_local
#define strdup_local
Definition: compat.h:29
SAVE_FLAG_NO_REMOVE
#define SAVE_FLAG_NO_REMOVE
Definition: map.h:112
diamondslots.x
x
Definition: diamondslots.py:15
clean_tmp_map
void clean_tmp_map(mapstruct *m)
Definition: map.c:1968
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
S_IROTH
#define S_IROTH
Definition: win32.h:50
clean_object
void clean_object(object *op)
Definition: map.c:1613
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2312
decay_objects
void decay_objects(mapstruct *m)
Definition: utils.c:175
object_new
object * object_new(void)
Definition: object.c:1255
MAP_LAYER_FLOOR
#define MAP_LAYER_FLOOR
Definition: map.h:40
Settings::datadir
const char * datadir
Definition: global.h:243
calculate_difficulty
int calculate_difficulty(mapstruct *m)
Definition: map.c:1911
objects
object * objects
Definition: object.c:294
FLAG_UNIQUE
#define FLAG_UNIQUE
Definition: define.h:287
pl
Definition: player.h:105
FLAG_OBJ_ORIGINAL
#define FLAG_OBJ_ORIGINAL
Definition: define.h:357
MoveType
unsigned char MoveType
Definition: define.h:417
guildjoin.ob
ob
Definition: guildjoin.py:42
blank_face
const Face * blank_face
Definition: image.c:35
SET_MAP_MOVE_ON
#define SET_MAP_MOVE_ON(M, X, Y, C)
Definition: map.h:205
CHECK_INV
@ CHECK_INV
Definition: object.h:169
CALLOC
#define CALLOC(x, y)
Definition: compat.h:31
mapdef::in_memory
uint32_t in_memory
Definition: map.h:338
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.c:345
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:47
create_pathname
char * create_pathname(const char *name, char *buf, size_t size)
Definition: map.c:103
mapdef::tile_map
struct mapdef * tile_map[4]
Definition: map.h:357
msgbuf
static char msgbuf[HUGE_BUF]
Definition: loader.c:2079
load_and_link_tiled_map
static mapstruct * load_and_link_tiled_map(mapstruct *orig_map, int tile_num)
Definition: map.c:2273
typedata::name
const char * name
Definition: define.h:91
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:97
path_combine_and_normalize
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
Definition: path.c:172
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:488
PROFILE_BEGIN
#define PROFILE_BEGIN(expr)
Definition: global.h:361
MAP_OVERLAY
#define MAP_OVERLAY
Definition: map.h:100
shopitem::typenum
int typenum
Definition: map.h:300
Ice.tmp
int tmp
Definition: Ice.py:207
typedata::name_pl
const char * name_pl
Definition: define.h:92
dump_all_maps
void dump_all_maps(void)
Definition: map.c:269
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
FLAG_NO_MAGIC
#define FLAG_NO_MAGIC
Definition: define.h:276
P_NO_MAGIC
#define P_NO_MAGIC
Definition: map.h:228
TRANSPORT
@ TRANSPORT
Definition: object.h:108
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
LO_NEWFILE
#define LO_NEWFILE
Definition: loader.h:17
get_rangevector
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2545
ext_info_map
void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Definition: main.c:335
FLAG_BLOCKSVIEW
#define FLAG_BLOCKSVIEW
Definition: define.h:269
rv_vector::part
object * part
Definition: map.h:378
npc_dialog.filename
filename
Definition: npc_dialog.py:99
first_map
EXTERN mapstruct * first_map
Definition: global.h:116
GET_MAP_FACE_OBJS
#define GET_MAP_FACE_OBJS(M, X, Y)
Definition: map.h:190
P_IS_ALIVE
#define P_IS_ALIVE
Definition: map.h:238
MSG_TYPE_MISC
#define MSG_TYPE_MISC
Definition: newclient.h:413
remove_button_link
void remove_button_link(object *op)
Definition: button.c:693
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
isqrt
int isqrt(int n)
Definition: utils.c:569
make_path_to_file
void make_path_to_file(const char *filename)
Definition: porting.c:162
AB_NO_PASS
#define AB_NO_PASS
Definition: map.h:236
MAP_LAYER_ITEM1
#define MAP_LAYER_ITEM1
Definition: map.h:43
Map_Layer_Info::honor_visibility
uint8_t honor_visibility
Definition: map.c:53
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
Definition: map.c:45
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
MAP_STYLE
#define MAP_STYLE
Definition: map.h:99
SAVE_MODE_OVERLAY
#define SAVE_MODE_OVERLAY
Definition: map.h:123
mapdef::tile_path
char * tile_path[4]
Definition: map.h:356
archt
Definition: object.h:469
settings
struct Settings settings
Definition: init.c:39
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
parse_shop_string
static shopitems * parse_shop_string(const char *input_string, const mapstruct *map)
Definition: map.c:891
INS_ABOVE_FLOOR_ONLY
#define INS_ABOVE_FLOOR_ONLY
Definition: object.h:567
rv_vector::distance_y
int distance_y
Definition: map.h:376
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4317
LO_NOREAD
#define LO_NOREAD
Definition: loader.h:18
free_string
void free_string(sstring str)
Definition: shstr.c:280
typedata
Definition: define.h:89
adjacent_map
static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy)
Definition: map.c:2468
PROFILE_END
#define PROFILE_END(var, expr)
Definition: global.h:366
m
static event_registration m
Definition: citylife.cpp:427
set_darkness_map
void set_darkness_map(mapstruct *m)
Definition: main.c:372
rv_vector::distance_x
int distance_x
Definition: map.h:375
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:131
apply_auto_fix
void apply_auto_fix(mapstruct *m)
Definition: main.c:259
MAP_LAYER_NO_PICK2
#define MAP_LAYER_NO_PICK2
Definition: map.h:42
load_temporary_map
static int load_temporary_map(mapstruct *m)
Definition: map.c:1277
MAP_DIFFICULTY
#define MAP_DIFFICULTY(m)
Definition: map.h:65
liv::exp
int64_t exp
Definition: living.h:47
item.q
q
Definition: item.py:32
disinfect.map
map
Definition: disinfect.py:4
P_NEW_MAP
#define P_NEW_MAP
Definition: map.h:251
change_map_light
int change_map_light(mapstruct *m, int change)
Definition: map.c:2009
SAVE_ERROR_CLOSE
#define SAVE_ERROR_CLOSE
Definition: map.h:150
strip_endline
void strip_endline(char *buf)
Definition: utils.c:324
P_NO_ERROR
#define P_NO_ERROR
Definition: map.h:241
MSG_TYPE_ATTACK_NOKEY
#define MSG_TYPE_ATTACK_NOKEY
Definition: newclient.h:617
of_close
int of_close(OutputFile *of)
Definition: output_file.c:61
load_map_header
static int load_map_header(FILE *fp, mapstruct *m)
Definition: map.c:1022
HEAD
#define HEAD(op)
Definition: object.h:593
fatal
void fatal(enum fatal_error err)
Definition: utils.c:580
object_fix_multipart
void object_fix_multipart(object *tmp)
Definition: object.c:4655
SAVE_ERROR_RCREATION
#define SAVE_ERROR_RCREATION
Definition: map.h:145
MAP_WHEN_RESET
#define MAP_WHEN_RESET(m)
Definition: map.h:62
python_init.path
path
Definition: python_init.py:8
MAX_DARKNESS
#define MAX_DARKNESS
Definition: define.h:454
MSG_TYPE_ATTACK
#define MSG_TYPE_ATTACK
Definition: newclient.h:409
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
map_layer_info
static const Map_Layer_Info map_layer_info[MAP_LAYERS]
Definition: map.c:62
obj::x
int16_t x
Definition: object.h:330
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
Definition: events.h:50
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:566
create_items_path
static void create_items_path(const char *s, char *buf, size_t size)
Definition: map.c:167
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
SET_MAP_FLAGS
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:164
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.c:2680
MAP_LAYER_LIVING1
#define MAP_LAYER_LIVING1
Definition: map.h:46
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76
MAP_LAYER_FLY1
#define MAP_LAYER_FLY1
Definition: map.h:48
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:193
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
MAP_DEFAULTRESET
#define MAP_DEFAULTRESET
Definition: config.h:419
archt::more
struct archt * more
Definition: object.h:472
free_map
void free_map(mapstruct *m)
Definition: map.c:1676
disinfect.count
int count
Definition: disinfect.py:7
link_multipart_objects
static void link_multipart_objects(mapstruct *m)
Definition: map.c:584
mapdef::spaces
MapSpace * spaces
Definition: map.h:348
check_inv_recursive
object * check_inv_recursive(object *op, const object *trig)
Definition: button.c:782
P_PLAYER
#define P_PLAYER
Definition: map.h:237
sproto.h
load_objects
void load_objects(mapstruct *m, FILE *fp, int mapflags)
Definition: map.c:612
map_get_path
const char * map_get_path(const object *item)
Definition: map.c:2722
MapSpace
Definition: map.h:257
mapdef
Definition: map.h:317
Map_Layer_Info
struct Map_Layer_Info Map_Layer_Info
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:420
blocks_prayer
EXTERN sstring blocks_prayer
Definition: global.h:154
delete_map
void delete_map(mapstruct *m)
Definition: map.c:1722
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:242
create_overlay_pathname
void create_overlay_pathname(const char *name, char *buf, size_t size)
Definition: map.c:124
SAVE_ERROR_NO_PATH
#define SAVE_ERROR_NO_PATH
Definition: map.h:148
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
MAP_WIDTH
#define MAP_WIDTH(m)
Definition: map.h:78
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:220
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:250
MAX_BUF
#define MAX_BUF
Definition: define.h:35
INS_ON_TOP
#define INS_ON_TOP
Definition: object.h:569
OB_MOVE_BLOCK
#define OB_MOVE_BLOCK(ob1, ob2)
Definition: define.h:423
level_exp
int64_t level_exp(int level, double expmul)
Definition: living.c:1874
SAVE_MODE_NORMAL
#define SAVE_MODE_NORMAL
Definition: map.h:121
Settings::playerdir
const char * playerdir
Definition: global.h:245
SAVE_ERROR_UCREATION
#define SAVE_ERROR_UCREATION
Definition: map.h:146
StringBuffer
Definition: stringbuffer.c:25
save_map
int save_map(mapstruct *m, int flag)
Definition: map.c:1420
SET_MAP_MOVE_SLOW
#define SET_MAP_MOVE_SLOW(M, X, Y, C)
Definition: map.h:200
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
obj::y
int16_t y
Definition: object.h:330
OUT_OF_REAL_MAP
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:218
get_typedata_by_name
const typedata * get_typedata_by_name(const char *name)
Definition: item.c:340
add_face_layer
static void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
Definition: map.c:2064
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:571
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
Floor.t
t
Definition: Floor.py:62
Map_Layer_Info
Definition: map.c:51
obj::stats
living stats
Definition: object.h:373
save_objects
int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
Definition: map.c:725
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:190
archt::clone
object clone
Definition: object.h:473
free_all_maps
void free_all_maps(void)
Definition: map.c:1977
Map_Layer_Info::high_layer
uint8_t high_layer
Definition: map.c:52
Face::visibility
uint8_t visibility
Definition: face.h:16
shopitem::name
const char * name
Definition: map.h:298
item
Definition: item.py:1
object_remove_from_active_list
void object_remove_from_active_list(object *op)
Definition: object.c:1378
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:240
of_open
FILE * of_open(OutputFile *of, const char *fname)
Definition: output_file.c:30
give.op
op
Definition: give.py:33
autojail.value
value
Definition: autojail.py:6
MapSpace::flags
uint8_t flags
Definition: map.h:261
object_value_set_shared
bool object_value_set_shared(const object *op, sstring key)
Definition: object.c:4361
rv_vector
Definition: map.h:373
MAP_SWAPPED
#define MAP_SWAPPED
Definition: map.h:132
shopitem::index
int index
Definition: map.h:303
diamondslots.y
y
Definition: diamondslots.py:16
SET_MAP_MOVE_BLOCK
#define SET_MAP_MOVE_BLOCK(M, X, Y, C)
Definition: map.h:195
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
buf
StringBuffer * buf
Definition: readable.c:1610
MAP_HEIGHT
#define MAP_HEIGHT(m)
Definition: map.h:80
MAP_ENTER_Y
#define MAP_ENTER_Y(m)
Definition: map.h:87
get_typedata
const typedata * get_typedata(int itemtype)
Definition: item.c:320
SAVE_ERROR_URENAME
#define SAVE_ERROR_URENAME
Definition: map.h:149
dump_map
void dump_map(const mapstruct *m)
Definition: map.c:246
guild_entry.x1
int x1
Definition: guild_entry.py:33
load_unique_objects
static void load_unique_objects(mapstruct *m)
Definition: map.c:1373
obj::more
struct obj * more
Definition: object.h:298
typedata::number
int number
Definition: define.h:90
obj::move_type
MoveType move_type
Definition: object.h:429
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
S_IRUSR
#define S_IRUSR
Definition: win32.h:56
create-tower.tile
tile
Definition: create-tower.py:8
fix_container_multipart
static void fix_container_multipart(object *container)
Definition: map.c:543
map_size
uint32_t map_size(mapstruct *m)
Definition: map.c:825
castle_read.key
key
Definition: castle_read.py:64
find_dir_2
int find_dir_2(int x, int y)
Definition: object.c:3648
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:144
loader.h
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.c:2080
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.c:309
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
print_shop_string
static void print_shop_string(mapstruct *m, char *output_string, int size)
Definition: map.c:977
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2133
MAP_ENTER_X
#define MAP_ENTER_X(m)
Definition: map.h:85
Settings::templatedir
const char * templatedir
Definition: global.h:249
EVENT_MAPREADY
#define EVENT_MAPREADY
Definition: events.h:48
MAP_FLUSH
#define MAP_FLUSH
Definition: map.h:96
GET_MAP_FLAGS
#define GET_MAP_FLAGS(M, X, Y)
Definition: map.h:162
DOOR
@ DOOR
Definition: object.h:126
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
seconds
long seconds(void)
Definition: time.c:344
S_IWGRP
#define S_IWGRP
Definition: win32.h:44
P_NO_CLERIC
#define P_NO_CLERIC
Definition: map.h:239
FLAG_IS_LINKED
#define FLAG_IS_LINKED
Definition: define.h:315
update_buttons
void update_buttons(mapstruct *m)
Definition: button.c:227
SET_MAP_PLAYER
#define SET_MAP_PLAYER(M, X, Y, C)
Definition: map.h:170
Settings::tmpdir
const char * tmpdir
Definition: global.h:250
mapdef::path
char path[HUGE_BUF]
Definition: map.h:358
MAP_TIMEOUT
#define MAP_TIMEOUT(m)
Definition: map.h:66
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.c:301
delete_unique_items
static void delete_unique_items(mapstruct *m)
Definition: map.c:1348
LO_REPEAT
#define LO_REPEAT
Definition: loader.h:15
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
MAP_MAXRESET
#define MAP_MAXRESET
Definition: config.h:417
mapdef::width
uint16_t width
Definition: map.h:340
SAVE_FLAG_SAVE_UNPAID
#define SAVE_FLAG_SAVE_UNPAID
Definition: map.h:111
rv_vector::direction
int direction
Definition: map.h:377
SET_MAP_LIGHT
#define SET_MAP_LIGHT(M, X, Y, L)
Definition: map.h:168
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:869
free_all_objects
static void free_all_objects(mapstruct *m)
Definition: map.c:1629
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2657
shopitem::strength
int8_t strength
Definition: map.h:301
set_map_reset_time
void set_map_reset_time(mapstruct *map)
Definition: map.c:2247
if
if(!(yy_init))
Definition: loader.c:2626
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2385
mapdef::next
struct mapdef * next
Definition: map.h:318
rv_vector::distance
unsigned int distance
Definition: map.h:374
MAP_LOADING
#define MAP_LOADING
Definition: map.h:133
shopitem
Definition: map.h:297
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
get_rangevector_from_mapcoord
int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2618
altar_valkyrie.res
int res
Definition: altar_valkyrie.py:74
S_IRGRP
#define S_IRGRP
Definition: win32.h:53
allocate_map
void allocate_map(mapstruct *m)
Definition: map.c:839
save_object_in_sb
void save_object_in_sb(StringBuffer *sb, object *op, const int flag)
Definition: object.c:5277
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:29
update_all_map_los
void update_all_map_los(mapstruct *map)
Definition: los.c:508
llevDebug
@ llevDebug
Definition: logger.h:13
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.c:1214
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302
P_BLOCKSVIEW
#define P_BLOCKSVIEW
Definition: map.h:227
load_overlay_map
static int load_overlay_map(const char *filename, mapstruct *m)
Definition: map.c:1313
give.name
name
Definition: give.py:27
LL_MORE
#define LL_MORE
Definition: loader.h:11
has_been_loaded
mapstruct * has_been_loaded(const char *name)
Definition: map.c:78
Settings::uniquedir
const char * uniquedir
Definition: global.h:248
OutputFile
Definition: output_file.h:41
create_template_pathname
void create_template_pathname(const char *name, char *buf, size_t size)
Definition: map.c:144
map_remove_unique_files
void map_remove_unique_files(const mapstruct *map)
Definition: map.c:2697
SET_MAP_MOVE_OFF
#define SET_MAP_MOVE_OFF(M, X, Y, C)
Definition: map.h:210
object_get_owner
object * object_get_owner(object *op)
Definition: object.c:808
Settings::localdir
const char * localdir
Definition: global.h:244