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 #define PROFILE_BEGIN(expr) { \
39  struct timespec _begin, _end; \
40  clock_gettime(CLOCK_MONOTONIC, &_begin); \
41  expr;
42 
43 #define PROFILE_END(var, expr) \
44  clock_gettime(CLOCK_MONOTONIC, &_end); \
45  long var = timespec_diff(&_end, &_begin); \
46  expr; }
47 
48 static void free_all_objects(mapstruct *m);
49 
55 const char *const map_layer_name[MAP_LAYERS] = {
56  "floor", "no_pick", "no_pick", "item", "item",
57  "item", "living", "living", "fly", "fly"
58 };
59 
61 typedef struct Map_Layer_Info {
62  uint8_t high_layer;
63  uint8_t honor_visibility;
65 
73  { MAP_LAYER_FLOOR, 1 },
75  { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 }, { MAP_LAYER_ITEM3, 1 },
76  { MAP_LAYER_LIVING2, 1 }, { MAP_LAYER_LIVING2, 1 },
77  { MAP_LAYER_FLY2, 1 }, { MAP_LAYER_FLY2, 1 }
78 };
79 
89  mapstruct *map;
90 
91  if (!name || !*name)
92  return NULL;
93 
94  for (map = first_map; map; map = map->next)
95  if (!strcmp(name, map->path))
96  break;
97  return (map);
98 }
99 
113 char *create_pathname(const char *name, char *buf, size_t size) {
114  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
115  * someplace else in the code? msw 2-17-97
116  */
117  if (*name == '/')
118  snprintf(buf, size, "%s/%s%s", settings.datadir, settings.mapdir, name);
119  else
120  snprintf(buf, size, "%s/%s/%s", settings.datadir, settings.mapdir, name);
121  return buf;
122 }
123 
134 void create_overlay_pathname(const char *name, char *buf, size_t size) {
135  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
136  * someplace else in the code? msw 2-17-97
137  */
138  if (*name == '/')
139  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.mapdir, name);
140  else
141  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.mapdir, name);
142 }
143 
154 void create_template_pathname(const char *name, char *buf, size_t size) {
155  /* Why? having extra / doesn't confuse unix anyplace? Dependancies
156  * someplace else in the code? msw 2-17-97
157  */
158  if (*name == '/')
159  snprintf(buf, size, "%s/%s%s", settings.localdir, settings.templatedir, name);
160  else
161  snprintf(buf, size, "%s/%s/%s", settings.localdir, settings.templatedir, name);
162 }
163 
177 static void create_items_path(const char *s, char *buf, size_t size) {
178  char *t;
179 
180  if (*s == '/')
181  s++;
182 
183  snprintf(buf, size, "%s/%s/", settings.localdir, settings.uniquedir);
184  t = buf+strlen(buf);
185  snprintf(t, buf+size-t, "%s", s);
186 
187  while (*t != '\0') {
188  if (*t == '/')
189  *t = '@';
190  t++;
191  }
192 }
193 
212 int check_path(const char *name, int prepend_dir) {
213  char buf[MAX_BUF];
214 #ifndef WIN32
215  struct stat statbuf;
216  int mode = 0;
217 #endif
218 
219  if (prepend_dir)
221  else
222  strlcpy(buf, name, sizeof(buf));
223 #ifdef WIN32 /* ***win32: check this sucker in windows style. */
224  return(_access(buf, 0));
225 #else
226 
227  if (stat(buf, &statbuf) != 0)
228  return -1;
229 
230  if (!S_ISREG(statbuf.st_mode))
231  return (-1);
232 
233  if (((statbuf.st_mode&S_IRGRP) && getegid() == statbuf.st_gid)
234  || ((statbuf.st_mode&S_IRUSR) && geteuid() == statbuf.st_uid)
235  || (statbuf.st_mode&S_IROTH))
236  mode |= 4;
237 
238  if ((statbuf.st_mode&S_IWGRP && getegid() == statbuf.st_gid)
239  || (statbuf.st_mode&S_IWUSR && geteuid() == statbuf.st_uid)
240  || (statbuf.st_mode&S_IWOTH))
241  mode |= 2;
242 
243  return (mode);
244 #endif
245 }
246 
256 void dump_map(const mapstruct *m) {
257  LOG(llevError, "Map %s status: %d.\n", m->path, m->in_memory);
258  LOG(llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH(m), MAP_HEIGHT(m), MAP_ENTER_X(m), MAP_ENTER_Y(m));
259 
260  if (m->msg != NULL)
261  LOG(llevError, "Message:\n%s", m->msg);
262 
263  if (m->maplore != NULL)
264  LOG(llevError, "Lore:\n%s", m->maplore);
265 
266  if (m->tmpname != NULL)
267  LOG(llevError, "Tmpname: %s\n", m->tmpname);
268 
269  LOG(llevError, "Difficulty: %d\n", m->difficulty);
270  LOG(llevError, "Darkness: %d\n", m->darkness);
271 }
272 
279 void dump_all_maps(void) {
280  mapstruct *m;
281 
282  for (m = first_map; m != NULL; m = m->next) {
283  dump_map(m);
284  }
285 }
286 
311 int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny) {
312  int retval = 0;
313  mapstruct *mp;
314 
315  /*
316  * Since x and y are copies of the original values, we can directly
317  * mess with them here.
318  */
319  mp = get_map_from_coord(oldmap, &x, &y);
320  if (!mp)
321  return P_OUT_OF_MAP;
322  if (mp != oldmap)
323  retval |= P_NEW_MAP;
324  if (newmap)
325  *newmap = mp;
326  if (nx)
327  *nx = x;
328  if (ny)
329  *ny = y;
330  retval |= mp->spaces[x+mp->width*y].flags;
331  return retval;
332 }
333 
355 int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy) {
356  object *tmp_head;
357  int mflags, blocked;
358 
359  /* Make sure the coordinates are valid - they should be, as caller should
360  * have already checked this.
361  */
362  if (OUT_OF_REAL_MAP(m, sx, sy)) {
363  LOG(llevError, "blocked_link: Passed map, x, y coordinates outside of map\n");
364  return 1;
365  }
366 
367  /* special hack for transports: if it's a transport with a move_type of 0, it can do on the space anyway */
368  if (ob->type == TRANSPORT && ob->move_type == 0)
369  return 0;
370 
371  /* Save some cycles - instead of calling get_map_flags(), just get the value
372  * directly.
373  */
374  mflags = m->spaces[sx+m->width*sy].flags;
375 
376  blocked = GET_MAP_MOVE_BLOCK(m, sx, sy);
377 
378  /* If space is currently not blocked by anything, no need to
379  * go further. Not true for players - all sorts of special
380  * things we need to do for players.
381  */
382  if (ob->type != PLAYER && !(mflags&P_IS_ALIVE) && (blocked == 0))
383  return 0;
384 
385  /* if there isn't anytyhing alive on this space, and this space isn't
386  * otherwise blocked, we can return now. Only if there is a living
387  * creature do we need to investigate if it is part of this creature
388  * or another. Likewise, only if something is blocking us do we
389  * need to investigate if there is a special circumstance that would
390  * let the player through (inventory checkers for example)
391  */
392  if (!(mflags&P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK(ob, blocked))
393  return 0;
394 
395  ob = HEAD(ob);
396 
397  /* We basically go through the stack of objects, and if there is
398  * some other object that has NO_PASS or FLAG_ALIVE set, return
399  * true. If we get through the entire stack, that must mean
400  * ob is blocking it, so return 0.
401  */
402  FOR_MAP_PREPARE(m, sx, sy, tmp) {
403  /* Never block part of self. */
404  tmp_head = HEAD(tmp);
405  if (tmp_head == ob)
406  continue;
407  /* This must be before the checks below. Code for inventory checkers. */
408  if (tmp->type == CHECK_INV && OB_MOVE_BLOCK(ob, tmp)) {
409  /* If last_sp is set, the player/monster needs an object,
410  * so we check for it. If they don't have it, they can't
411  * pass through this space.
412  */
413  if (tmp->last_sp) {
414  if (check_inv_recursive(ob, tmp) == NULL) {
415  if (tmp->msg) {
416  /* Optionally display the reason why one cannot move
417  * there. Note: emitting a message from this function
418  * is not very elegant. Ideally, this should be done
419  * somewhere in server/player.c, but this is difficult
420  * for objects of type CHECK_INV that are not alive.
421  */
424  tmp->msg);
425  }
426  return 1;
427  }
428  } else {
429  /* In this case, the player must not have the object -
430  * if they do, they can't pass through.
431  */
432  if (check_inv_recursive(ob, tmp) != NULL) {
433  if (tmp->msg) {
436  tmp->msg);
437  }
438  return 1;
439  }
440  }
441  } /* if check_inv */
442  else {
443  /* Broke apart a big nasty if into several here to make
444  * this more readable. first check - if the space blocks
445  * movement, can't move here.
446  * second - if a monster, can't move there, unless it is a
447  * hidden dm
448  */
449  if (OB_MOVE_BLOCK(ob, tmp))
450  return 1;
452  && tmp->head != ob
453  && tmp != ob
454  && tmp->type != DOOR
455  && !(QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden))
456  return 1;
457  }
458  } FOR_MAP_FINISH();
459  return 0;
460 }
461 
498 int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y) {
499  archetype *tmp;
500  int flag;
501  mapstruct *m1;
502  int16_t sx, sy;
503  const object *part;
504 
505  if (ob == NULL) {
506  flag = get_map_flags(m, &m1, x, y, &sx, &sy);
507  if (flag&P_OUT_OF_MAP)
508  return P_OUT_OF_MAP;
509 
510  /* don't have object, so don't know what types would block */
511  return(GET_MAP_MOVE_BLOCK(m1, sx, sy));
512  }
513 
514  for (tmp = ob->arch, part = ob; tmp != NULL; tmp = tmp->more, part = part->more) {
515  flag = get_map_flags(m, &m1, x+tmp->clone.x, y+tmp->clone.y, &sx, &sy);
516 
517  if (flag&P_OUT_OF_MAP)
518  return P_OUT_OF_MAP;
519  if (flag&P_IS_ALIVE)
520  return P_IS_ALIVE;
521 
522  /* object_find_first_free_spot() calls this function. However, often
523  * ob doesn't have any move type (when used to place exits)
524  * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work.
525  */
526 
527  if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK(m1, sx, sy) != MOVE_ALL)
528  continue;
529 
530  /* A transport without move_type for a part should go through everything for that part. */
531  if (ob->type == TRANSPORT && part->move_type == 0)
532  continue;
533 
534  /* Note it is intentional that we check ob - the movement type of the
535  * head of the object should correspond for the entire object.
536  */
537  if (OB_TYPE_MOVE_BLOCK(ob, GET_MAP_MOVE_BLOCK(m1, sx, sy)))
538  return AB_NO_PASS;
539  }
540  return 0;
541 }
542 
553 static void fix_container_multipart(object *container) {
554  FOR_INV_PREPARE(container, tmp) {
555  archetype *at;
556  object *op, *last;
557 
558  if (tmp->inv)
560  /* already multipart, or non-multipart arch - don't do anything more */
561  for (at = tmp->arch->more, last = tmp; at != NULL; at = at->more, last = op) {
562  /* FIXME: We can't reuse object_fix_multipart() since that only
563  * works for items directly on maps. Maybe factor out common code?
564  */
565  op = arch_to_object(at);
566  op->head = tmp;
567  op->env = tmp->env;
568  last->more = op;
569  if (tmp->name != op->name) {
570  if (op->name)
571  free_string(op->name);
572  op->name = add_string(tmp->name);
573  }
574  if (tmp->title != op->title) {
575  if (op->title)
576  free_string(op->title);
577  op->title = add_string(tmp->title);
578  }
580  }
581  } FOR_INV_FINISH();
582 }
583 
595  int x, y;
596 
597  for (x = 0; x < MAP_WIDTH(m); x++)
598  for (y = 0; y < MAP_HEIGHT(m); y++)
599  FOR_MAP_PREPARE(m, x, y, tmp) {
600  if (tmp->inv)
602 
603  /* already multipart - don't do anything more */
604  if (tmp->head || tmp->more)
605  continue;
606 
608  } FOR_MAP_FINISH(); /* for objects on this space */
609 }
610 
622 static void load_objects(mapstruct *m, FILE *fp, int mapflags) {
623  int i, j, bufstate = LO_NEWFILE;
624  int unique;
625  object *op, *prev = NULL, *last_more = NULL;
626 
627  op = object_new();
628  op->map = m; /* To handle buttons correctly */
629 
630  PROFILE_BEGIN();
631  while ((i = load_object(fp, op, bufstate, mapflags))) {
632  /* Since the loading of the map header does not load an object
633  * anymore, we need to pass LO_NEWFILE for the first object loaded,
634  * and then switch to LO_REPEAT for faster loading.
635  */
636  bufstate = LO_REPEAT;
637 
638  /* if the archetype for the object is null, means that we
639  * got an invalid object. Don't do anything with it - the game
640  * or editor will not be able to do anything with it either.
641  */
642  if (op->arch == NULL) {
643  LOG(llevDebug, "Discarding object without arch: %s\n", op->name ? op->name : "(null)");
644  continue;
645  }
646 
647  /*
648  * You can NOT have players on a map being loaded.
649  * Trying to use such a type leads to crashes everywhere as op->contr is NULL.
650  */
651  if (op->type == PLAYER) {
652  LOG(llevError, "Discarding invalid item with type PLAYER in map %s\n", m->path);
653  continue;
654  }
655 
656  /* don't use out_of_map because we don't want to consider tiling properties, we're loading a single map */
657  if (op->x < 0 || op->y < 0 || op->x >= MAP_WIDTH(m) || op->y >= MAP_HEIGHT(m)) {
658  LOG(llevError, " object %s not on valid map position %s:%d:%d\n", op->name ? op->name : "(null)", m->path, op->x, op->y);
659  if (op->x < 0) {
660  op->x = 0;
661  } else if (op->x >= MAP_WIDTH(m)) {
662  op->x = MAP_WIDTH(m) - 1;
663  }
664  if (op->y < 0) {
665  op->y = 0;
666  } else if (op->y >= MAP_HEIGHT(m)) {
667  op->y = MAP_HEIGHT(m) - 1;
668  }
669  }
670 
671  switch (i) {
672  case LL_NORMAL:
673  /* if we are loading an overlay, put the floors on the bottom */
675  && mapflags&MAP_OVERLAY)
677  else
679 
680  if (op->inv)
682 
683  prev = op,
684  last_more = op;
685  break;
686 
687  case LL_MORE:
689  op->head = prev,
690  last_more->more = op,
691  last_more = op;
692  break;
693  }
694  if (mapflags&MAP_STYLE) {
696  }
697  op = object_new();
698  op->map = m;
699  }
700  PROFILE_END(diff, LOG(llevDebug,
701  "load_objects on %s took %ld us\n", m->path, diff));
702  for (i = 0; i < m->width; i++) {
703  for (j = 0; j < m->height; j++) {
704  unique = 0;
705  /* check for unique items, or unique squares */
706  FOR_MAP_PREPARE(m, i, j, otmp) {
707  if (QUERY_FLAG(otmp, FLAG_UNIQUE))
708  unique = 1;
709  if (!(mapflags&(MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique))
711  } FOR_MAP_FINISH();
712  }
713  }
716 }
717 
735 static int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag) {
736  int i, j = 0, unique = 0, res = 0;
737  unsigned int count = 0;
738 
739  PROFILE_BEGIN();
740  /* first pass - save one-part objects */
741  for (i = 0; i < MAP_WIDTH(m); i++)
742  for (j = 0; j < MAP_HEIGHT(m); j++) {
743  unique = 0;
744  FOR_MAP_PREPARE(m, i, j, op) {
746  unique = 1;
747 
748  if (op->type == PLAYER) {
749  LOG(llevDebug, "Player on map that is being saved\n");
750  continue;
751  }
752 
753  if (op->head || object_get_owner(op) != NULL)
754  continue;
755 
756  if (unique || QUERY_FLAG(op, FLAG_UNIQUE)) {
758  count++ ;
759  } else if (flag == 0
762  count++;
763  }
764 
765  if (res != 0)
766  return res;
767  } FOR_MAP_FINISH(); /* for this space */
768  } /* for this j */
769 
770  PROFILE_END(diff,
771  LOG(llevDebug, "save_objects on %s took %ld us (%u objects = %f us each)\n", m->path, diff, count, (double)diff/count));
772  return 0;
773 }
774 
787  mapstruct *map = (mapstruct *)calloc(1, sizeof(mapstruct));
788  /* mapstruct *mp;*/
789 
790  if (map == NULL)
792  /*
793  * Nothing in the code appears to require we add new maps to the end of the list.
794  * Why not just add them to the front instead? Its faster.
795  *
796  * SilverNexus 2016-05-18
797  *
798  for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next)
799  ;
800  if (mp == NULL)
801  first_map = map;
802  else
803  mp->next = map;
804  */
805  map->next = first_map;
806  first_map = map;
807 
808  map->in_memory = MAP_SWAPPED;
809  /* The maps used to pick up default x and y values from the
810  * map archetype. Mimic that behaviour.
811  */
812  MAP_WIDTH(map) = 16;
813  MAP_HEIGHT(map) = 16;
814  MAP_RESET_TIMEOUT(map) = 0;
815  MAP_TIMEOUT(map) = 300;
816  MAP_ENTER_X(map) = 0;
817  MAP_ENTER_Y(map) = 0;
818  map->last_reset_time = 0;
819  return map;
820 }
821 
823 uint32_t map_size(mapstruct *m) {
824  return (uint32_t)m->width * (uint32_t)m->height;
825 }
826 
837 static void allocate_map(mapstruct *m) {
838  m->in_memory = MAP_IN_MEMORY;
839  /* Log this condition and free the storage. We could I suppose
840  * realloc, but if the caller is presuming the data will be intact,
841  * that is their poor assumption.
842  */
843  if (m->spaces) {
844  LOG(llevError, "allocate_map called with already allocated map (%s)\n", m->path);
845  free(m->spaces);
846  }
847 
848  m->spaces = calloc(map_size(m), sizeof(MapSpace));
849 
850  if (m->spaces == NULL)
852 }
853 
867 mapstruct *get_empty_map(int sizex, int sizey) {
869  m->width = sizex;
870  m->height = sizey;
871  m->in_memory = MAP_SWAPPED;
872  allocate_map(m);
873  return m;
874 }
875 
889 static shopitems *parse_shop_string(const char *input_string, const mapstruct *map) {
890  char *shop_string, *p, *q, *next_semicolon, *next_colon;
891  shopitems *items = NULL;
892  int i = 0, number_of_entries = 0;
893  const typedata *current_type;
894 
895  shop_string = strdup_local(input_string);
896  p = shop_string;
897  LOG(llevDebug, "parsing %s\n", input_string);
898  /* first we'll count the entries, we'll need that for allocating the array shortly */
899  while (p) {
900  p = strchr(p, ';');
901  number_of_entries++;
902  if (p)
903  p++;
904  }
905  p = shop_string;
906  strip_endline(p);
907  items = CALLOC(number_of_entries+1, sizeof(shopitems));
908  /*
909  * The memset would always set at least one byte to zero,
910  * so a failed calloc would have segfaulted the program.
911  * Instead, check for a null and fail more gracefully.
912  */
913  if (!items)
915  /*
916  * calloc() already sets each byte to zero already
917  *
918  memset(items, 0, (sizeof(shopitems)*number_of_entries+1));
919  */
920  for (i = 0; i < number_of_entries; i++) {
921  if (!p) {
922  LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
923  break;
924  }
925  next_semicolon = strchr(p, ';');
926  next_colon = strchr(p, ':');
927  /* if there is a stregth specified, figure out what it is, we'll need it soon. */
928  if (next_colon && (!next_semicolon || next_colon < next_semicolon))
929  items[i].strength = atoi(strchr(p, ':')+1);
930 
931  if (isdigit(*p) || *p == '*') {
932  items[i].typenum = *p == '*' ? -1 : atoi(p);
933  current_type = get_typedata(items[i].typenum);
934  if (current_type) {
935  items[i].name = current_type->name;
936  items[i].name_pl = current_type->name_pl;
937  }
938  } else { /*we have a named type, let's figure out what it is */
939  q = strpbrk(p, ";:");
940  if (q)
941  *q = '\0';
942 
943  current_type = get_typedata_by_name(p);
944  if (current_type) {
945  items[i].name = current_type->name;
946  items[i].typenum = current_type->number;
947  items[i].name_pl = current_type->name_pl;
948  } else {
949  /* oh uh, something's wrong, let's free up this one, and try
950  * the next entry while we're at it, better print a warning */
951  LOG(llevError, "invalid type %s defined in shopitems for %s in string %s\n", p, map->name, input_string);
952  }
953  }
954  items[i].index = number_of_entries;
955  if (next_semicolon)
956  p = ++next_semicolon;
957  else
958  p = NULL;
959  }
960  free(shop_string);
961  return items;
962 }
963 
975 static void print_shop_string(mapstruct *m, char *output_string, int size) {
976  int i;
977  char tmp[MAX_BUF];
978 
979  output_string[0] = '\0';
980  for (i = 0; i < m->shopitems[0].index; i++) {
981  if (m->shopitems[i].typenum != -1) {
982  if (m->shopitems[i].strength) {
983  snprintf(tmp, sizeof(tmp), "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
984  } else
985  snprintf(tmp, sizeof(tmp), "%s;", m->shopitems[i].name);
986  } else {
987  if (m->shopitems[i].strength) {
988  snprintf(tmp, sizeof(tmp), "*:%d;", m->shopitems[i].strength);
989  } else
990  snprintf(tmp, sizeof(tmp), "*;");
991  }
992  snprintf(output_string+strlen(output_string), size-strlen(output_string), "%s", tmp);
993  }
994 
995  /* erase final ; else parsing back will lead to issues */
996  if (strlen(output_string) > 0) {
997  output_string[strlen(output_string) - 1] = '\0';
998  }
999 }
1000 
1020 static int load_map_header(FILE *fp, mapstruct *m) {
1021  char buf[HUGE_BUF], *key = NULL, *value;
1022 
1023  m->width = m->height = 0;
1024  while (fgets(buf, sizeof(buf), fp) != NULL) {
1025  char *p;
1026 
1027  p = strchr(buf, '\n');
1028  if (p == NULL) {
1029  LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", buf);
1030  return 1;
1031  }
1032  *p = '\0';
1033 
1034  key = buf;
1035  while (isspace(*key))
1036  key++;
1037  if (*key == 0)
1038  continue; /* empty line */
1039  value = strchr(key, ' ');
1040  if (value) {
1041  *value = 0;
1042  value++;
1043  while (isspace(*value)) {
1044  value++;
1045  if (*value == '\0') {
1046  /* Nothing but spaces. */
1047  value = NULL;
1048  break;
1049  }
1050  }
1051  }
1052 
1053  /* key is the field name, value is what it should be set
1054  * to. We've already done the work to null terminate key,
1055  * and strip off any leading spaces for both of these.
1056  * We have not touched the newline at the end of the line -
1057  * these are needed for some values. the end pointer
1058  * points to the first of the newlines.
1059  * value could be NULL! It would be easy enough to just point
1060  * this to "" to prevent cores, but that would let more errors slide
1061  * through.
1062  *
1063  * First check for entries that do not use the value parameter, then
1064  * validate that value is given and check for the remaining entries
1065  * that use the parameter.
1066  */
1067 
1068  if (!strcmp(key, "msg")) {
1069  char msgbuf[HUGE_BUF];
1070  int msgpos = 0;
1071 
1072  while (fgets(buf, sizeof(buf), fp) != NULL) {
1073  if (!strcmp(buf, "endmsg\n"))
1074  break;
1075  else {
1076  snprintf(msgbuf+msgpos, sizeof(msgbuf)-msgpos, "%s", buf);
1077  msgpos += strlen(buf);
1078  }
1079  }
1080  /* There are lots of maps that have empty messages (eg, msg/endmsg
1081  * with nothing between). There is no reason in those cases to
1082  * keep the empty message. Also, msgbuf contains garbage data
1083  * when msgpos is zero, so copying it results in crashes
1084  */
1085  if (msgpos != 0) {
1086  /* When loading eg an overlay, message is already set, so free() current one. */
1087  free(m->msg);
1088  m->msg = strdup_local(msgbuf);
1089  }
1090  } else if (!strcmp(key, "maplore")) {
1091  char maplorebuf[HUGE_BUF];
1092  size_t maplorepos = 0;
1093 
1094  while (fgets(buf, HUGE_BUF-1, fp) != NULL) {
1095  if (!strcmp(buf, "endmaplore\n"))
1096  break;
1097  else {
1098  if (maplorepos >= sizeof(maplorebuf)) {
1099  LOG(llevError, "Map lore exceeds buffer length\n");
1100  return 1;
1101  }
1102  snprintf(maplorebuf+maplorepos, sizeof(maplorebuf)-maplorepos, "%s", buf);
1103  maplorepos += strlen(buf);
1104  }
1105  }
1106  if (maplorepos != 0)
1107  m->maplore = strdup_local(maplorebuf);
1108  } else if (!strcmp(key, "end")) {
1109  break;
1110  } else if (value == NULL) {
1111  LOG(llevError, "Got '%s' line without parameter in map header\n", key);
1112  } else if (!strcmp(key, "arch")) {
1113  /* This is an oddity, but not something we care about much. */
1114  if (strcmp(value, "map")) {
1115  LOG(llevError, "load_map_header: expected 'arch map': check line endings?\n");
1116  return 1;
1117  }
1118  } else if (!strcmp(key, "name")) {
1119  /* When loading eg an overlay, the name is already set, so free() current one. */
1120  free(m->name);
1121  m->name = strdup_local(value);
1122  /* first strcmp value on these are old names supported
1123  * for compatibility reasons. The new values (second) are
1124  * what really should be used.
1125  */
1126  } else if (!strcmp(key, "enter_x")) {
1127  m->enter_x = atoi(value);
1128  } else if (!strcmp(key, "enter_y")) {
1129  m->enter_y = atoi(value);
1130  } else if (!strcmp(key, "width")) {
1131  m->width = atoi(value);
1132  } else if (!strcmp(key, "height")) {
1133  m->height = atoi(value);
1134  } else if (!strcmp(key, "reset_timeout")) {
1135  m->reset_timeout = atoi(value);
1136  } else if (!strcmp(key, "swap_time")) {
1137  m->timeout = atoi(value);
1138  } else if (!strcmp(key, "difficulty")) {
1139  m->difficulty = atoi(value);
1140  } else if (!strcmp(key, "darkness")) {
1141  m->darkness = atoi(value);
1142  } else if (!strcmp(key, "fixed_resettime")) {
1143  m->fixed_resettime = atoi(value);
1144  } else if (!strcmp(key, "unique")) {
1145  m->unique = atoi(value);
1146  } else if (!strcmp(key, "template")) {
1147  m->is_template = atoi(value);
1148  } else if (!strcmp(key, "region")) {
1149  m->region = get_region_by_name(value);
1150  } else if (!strcmp(key, "shopitems")) {
1151  m->shopitems = parse_shop_string(value, m);
1152  } else if (!strcmp(key, "shopgreed")) {
1153  m->shopgreed = atof(value);
1154  } else if (!strcmp(key, "shopmin")) {
1155  m->shopmin = atol(value);
1156  } else if (!strcmp(key, "shopmax")) {
1157  m->shopmax = atol(value);
1158  } else if (!strcmp(key, "shoprace")) {
1159  m->shoprace = strdup_local(value);
1160  } else if (!strcmp(key, "outdoor")) {
1161  m->outdoor = atoi(value);
1162  } else if (!strcmp(key, "nosmooth")) {
1163  m->nosmooth = atoi(value);
1164  } else if (!strcmp(key, "first_load")) {
1165  m->last_reset_time = atoi(value);
1166  } else if (!strncmp(key, "tile_path_", 10)) {
1167  int tile = atoi(key+10);
1168 
1169  if (tile < 1 || tile > 4) {
1170  LOG(llevError, "load_map_header: tile location %d out of bounds (%s)\n", tile, m->path);
1171  } else {
1172  if (m->tile_path[tile-1]) {
1173  LOG(llevError, "load_map_header: tile location %d duplicated (%s)\n", tile, m->path);
1174  free(m->tile_path[tile-1]);
1175  }
1176  m->tile_path[tile-1] = strdup_local(value);
1177  } /* end if tile direction (in)valid */
1178  } else if (!strcmp(key, "background_music")) {
1179  m->background_music = strdup_local(value);
1180  } else {
1181  LOG(llevError, "Got unknown value in map header: %s %s\n", key, value);
1182  }
1183  }
1184  if ((m->width == 0) || (m->height == 0)) {
1185  LOG(llevError, "Map width or height not specified\n");
1186  return 1;
1187  }
1188  if (!key || strcmp(key, "end")) {
1189  LOG(llevError, "Got premature eof on map header!\n");
1190  return 1;
1191  }
1192  return 0;
1193 }
1194 
1210 mapstruct *mapfile_load(const char *map, int flags) {
1211  FILE *fp;
1212  mapstruct *m;
1213  char pathname[MAX_BUF];
1214 
1215  PROFILE_BEGIN();
1216 
1217  if (flags&MAP_PLAYER_UNIQUE) {
1218  snprintf(pathname, sizeof(pathname), "%s/%s/%s", settings.localdir, settings.playerdir, map+1);
1219  }
1220  else if (flags&MAP_OVERLAY)
1221  create_overlay_pathname(map, pathname, MAX_BUF);
1222  else
1223  create_pathname(map, pathname, MAX_BUF);
1224 
1225  if ((fp = fopen(pathname, "r")) == NULL) {
1227  "Can't open %s: %s\n", pathname, strerror(errno));
1228  return (NULL);
1229  }
1230 
1231  m = get_linked_map();
1232 
1233  safe_strncpy(m->path, map, HUGE_BUF);
1234  if (load_map_header(fp, m)) {
1235  LOG(llevError, "Error loading map header for %s, flags=%d\n", map, flags);
1236  delete_map(m);
1237  fclose(fp);
1238  return NULL;
1239  }
1240 
1241  allocate_map(m);
1242 
1243  m->in_memory = MAP_LOADING;
1244  load_objects(m, fp, flags & MAP_STYLE);
1245  fclose(fp);
1246  m->in_memory = MAP_IN_MEMORY;
1247  if (!MAP_DIFFICULTY(m) && (!(flags & MAP_NO_DIFFICULTY)))
1250 
1251  /* In case other objects press some buttons down */
1252  update_buttons(m);
1253 
1255 
1256  if (!(flags & MAP_STYLE))
1257  apply_auto_fix(m); /* Chests which open as default */
1258 
1259  PROFILE_END(diff,
1260  LOG(llevDebug, "mapfile_load on %s" " took %ld us\n", map, diff));
1261 
1262  return (m);
1263 }
1264 
1274  FILE *fp;
1275 
1276  if (!m->tmpname) {
1277  LOG(llevError, "No temporary filename for map %s\n", m->path);
1278  return 1;
1279  }
1280 
1281  if ((fp = fopen(m->tmpname, "r")) == NULL) {
1282  LOG(llevError, "Cannot open %s: %s\n", m->tmpname, strerror(errno));
1283  return 2;
1284  }
1285 
1286  if (load_map_header(fp, m)) {
1287  LOG(llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1288  fclose(fp);
1289  return 3;
1290  }
1291  allocate_map(m);
1292 
1293  m->in_memory = MAP_LOADING;
1294  load_objects(m, fp, 0);
1295  fclose(fp);
1296  m->in_memory = MAP_IN_MEMORY;
1297  return 0;
1298 }
1299 
1309 static int load_overlay_map(const char *filename, mapstruct *m) {
1310  FILE *fp;
1311  char pathname[MAX_BUF];
1312 
1314 
1315  if ((fp = fopen(pathname, "r")) == NULL) {
1316  /* nothing bad to not having an overlay */
1317  return 0;
1318  }
1319 
1320  if (load_map_header(fp, m)) {
1321  LOG(llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1322  fclose(fp);
1323  return 1;
1324  }
1325  /*allocate_map(m);*/
1326 
1327  m->in_memory = MAP_LOADING;
1328  load_objects(m, fp, MAP_OVERLAY);
1329  fclose(fp);
1330  m->in_memory = MAP_IN_MEMORY;
1331  return 0;
1332 }
1333 
1334 /******************************************************************************
1335  * This is the start of unique map handling code
1336  *****************************************************************************/
1337 
1345  int i, j, unique = 0;
1346 
1347  for (i = 0; i < MAP_WIDTH(m); i++)
1348  for (j = 0; j < MAP_HEIGHT(m); j++) {
1349  unique = 0;
1350  FOR_MAP_PREPARE(m, i, j, op) {
1352  unique = 1;
1353  if (op->head == NULL && (QUERY_FLAG(op, FLAG_UNIQUE) || unique)) {
1354  clean_object(op);
1357  object_remove(op);
1359  }
1360  } FOR_MAP_FINISH();
1361  }
1362 }
1363 
1370  FILE *fp;
1371  int count;
1372  char firstname[MAX_BUF], name[MAX_BUF];
1373 
1374  create_items_path(m->path, name, MAX_BUF);
1375  for (count = 0; count < 10; count++) {
1376  snprintf(firstname, sizeof(firstname), "%s.v%02d", name, count);
1377  if (!access(firstname, R_OK))
1378  break;
1379  }
1380  /* If we get here, we did not find any map */
1381  if (count == 10)
1382  return;
1383 
1384  if ((fp = fopen(firstname, "r")) == NULL) {
1385  /* There is no expectation that every map will have unique items, but this
1386  * is debug output, so leave it in.
1387  */
1388  LOG(llevDebug, "Can't open unique items file for %s\n", name);
1389  return;
1390  }
1391 
1392  m->in_memory = MAP_LOADING;
1393  if (m->tmpname == NULL) /* if we have loaded unique items from */
1394  delete_unique_items(m); /* original map before, don't duplicate them */
1395  load_object(fp, NULL, LO_NOREAD, 0);
1396  load_objects(m, fp, 0);
1397  fclose(fp);
1398  m->in_memory = MAP_IN_MEMORY;
1399 }
1400 
1416 int save_map(mapstruct *m, int flag) {
1417  FILE *fp, *fp2;
1418  OutputFile of, of2;
1419  char filename[MAX_BUF], shop[MAX_BUF];
1420  int i, res;
1421 
1422  if (flag && !*m->path) {
1423  LOG(llevError, "Tried to save map without path.\n");
1424  return SAVE_ERROR_NO_PATH;
1425  }
1426 
1427  PROFILE_BEGIN();
1428 
1429  if (flag != SAVE_MODE_NORMAL || (m->unique) || (m->is_template)) {
1430  if (!m->unique && !m->is_template) { /* flag is set */
1431  if (flag == SAVE_MODE_OVERLAY)
1433  else
1434  create_pathname(m->path, filename, MAX_BUF);
1435  } else {
1436  if (m->path[0] != '~') {
1437  LOG(llevError,
1438  "Cannot save unique map '%s' outside of LOCALDIR. Check "
1439  "that all exits to '%s' have FLAG_UNIQUE set correctly.\n",
1440  m->path, m->path);
1441  return SAVE_ERROR_UCREATION;
1442  }
1443  snprintf(filename, sizeof(filename), "%s/%s/%s", settings.localdir, settings.playerdir, m->path+1);
1444  }
1445 
1447  } else {
1448  if (!m->tmpname)
1449  m->tmpname = tempnam(settings.tmpdir, NULL);
1450  strlcpy(filename, m->tmpname, sizeof(filename));
1451  }
1452  m->in_memory = MAP_SAVING;
1453 
1454  fp = of_open(&of, filename);
1455  if (fp == NULL)
1456  return SAVE_ERROR_RCREATION;
1457 
1458  /* legacy */
1459  fprintf(fp, "arch map\n");
1460  if (m->name)
1461  fprintf(fp, "name %s\n", m->name);
1462  if (!flag)
1463  fprintf(fp, "swap_time %d\n", m->swap_time);
1464  if (m->reset_timeout)
1465  fprintf(fp, "reset_timeout %u\n", m->reset_timeout);
1466  if (m->fixed_resettime)
1467  fprintf(fp, "fixed_resettime %d\n", m->fixed_resettime);
1468  /* we unfortunately have no idea if this is a value the creator set
1469  * or a difficulty value we generated when the map was first loaded
1470  */
1471  if (m->difficulty)
1472  fprintf(fp, "difficulty %d\n", m->difficulty);
1473  if (m->region)
1474  fprintf(fp, "region %s\n", m->region->name);
1475  if (m->shopitems) {
1476  print_shop_string(m, shop, sizeof(shop));
1477  fprintf(fp, "shopitems %s\n", shop);
1478  }
1479  if (m->shopgreed)
1480  fprintf(fp, "shopgreed %f\n", m->shopgreed);
1481  if (m->shopmin)
1482  fprintf(fp, "shopmin %"FMT64U"\n", m->shopmin);
1483  if (m->shopmax)
1484  fprintf(fp, "shopmax %"FMT64U"\n", m->shopmax);
1485  if (m->shoprace)
1486  fprintf(fp, "shoprace %s\n", m->shoprace);
1487  if (m->darkness)
1488  fprintf(fp, "darkness %d\n", m->darkness);
1489  if (m->width)
1490  fprintf(fp, "width %d\n", m->width);
1491  if (m->height)
1492  fprintf(fp, "height %d\n", m->height);
1493  if (m->enter_x)
1494  fprintf(fp, "enter_x %d\n", m->enter_x);
1495  if (m->enter_y)
1496  fprintf(fp, "enter_y %d\n", m->enter_y);
1497  if (m->msg)
1498  fprintf(fp, "msg\n%sendmsg\n", m->msg);
1499  if (m->maplore)
1500  fprintf(fp, "maplore\n%sendmaplore\n", m->maplore);
1501  if (m->unique)
1502  fprintf(fp, "unique %d\n", m->unique);
1503  if (m->is_template)
1504  fprintf(fp, "template %d\n", m->is_template);
1505  if (m->outdoor)
1506  fprintf(fp, "outdoor %d\n", m->outdoor);
1507  if (m->nosmooth)
1508  fprintf(fp, "nosmooth %d\n", m->nosmooth);
1509  if (m->last_reset_time)
1510  fprintf(fp, "first_load %ld\n", m->last_reset_time);
1511  if (m->background_music)
1512  fprintf(fp, "background_music %s\n", m->background_music);
1513 
1514  /* Save any tiling information, except on overlays */
1515  if (flag != SAVE_MODE_OVERLAY)
1516  for (i = 0; i < 4; i++)
1517  if (m->tile_path[i])
1518  fprintf(fp, "tile_path_%d %s\n", i+1, m->tile_path[i]);
1519 
1520  fprintf(fp, "end\n");
1521 
1522  /* In the game save unique items in the different file, but
1523  * in the editor save them to the normal map file.
1524  * If unique map, save files in the proper destination (set by
1525  * player)
1526  */
1527  if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->is_template) {
1528  char name[MAX_BUF], final_unique[MAX_BUF];
1529 
1530  create_items_path(m->path, name, MAX_BUF);
1531  snprintf(final_unique, sizeof(final_unique), "%s.v00", name);
1532  fp2 = of_open(&of2, final_unique);
1533  if (fp2 == NULL) {
1534  of_cancel(&of);
1535  return SAVE_ERROR_UCREATION;
1536  }
1537  if (flag == SAVE_MODE_OVERLAY) {
1538  /* SO_FLAG_NO_REMOVE is non destructive save, so map is still valid. */
1539  res = save_objects(m, fp, fp2, SAVE_FLAG_NO_REMOVE);
1540  if (res < 0) {
1541  LOG(llevError, "Save error during object save: %d\n", res);
1542  of_cancel(&of);
1543  of_cancel(&of2);
1544  return res;
1545  }
1546  m->in_memory = MAP_IN_MEMORY;
1547  } else {
1548  res = save_objects(m, fp, fp2, 0);
1549  if (res < 0) {
1550  LOG(llevError, "Save error during object save: %d\n", res);
1551  of_cancel(&of);
1552  of_cancel(&of2);
1553  return res;
1554  }
1556  }
1557  if (ftell(fp2) == 0) {
1558  of_cancel(&of2);
1559  /* If there are no unique items left on the map, we need to
1560  * unlink the original unique map so that the unique
1561  * items don't show up again.
1562  */
1563  unlink(final_unique);
1564  } else {
1565  if (!of_close(&of2)) {
1566  of_cancel(&of);
1567  return SAVE_ERROR_URENAME;
1568  }
1569 
1570  if (chmod(final_unique, SAVE_MODE) != 0) {
1571  LOG(llevError, "Could not set permissions on '%s'\n",
1572  final_unique);
1573  }
1574  }
1575  } else { /* save same file when not playing, like in editor */
1576  res = save_objects(m, fp, fp, 0);
1577  if (res < 0) {
1578  LOG(llevError, "Save error during object save: %d\n", res);
1579  of_cancel(&of);
1580  return res;
1581  }
1583  }
1584 
1585  if (!of_close(&of))
1586  return SAVE_ERROR_CLOSE;
1587 
1588  if (chmod(filename, SAVE_MODE) != 0) {
1589  LOG(llevError, "Could not set permissions on '%s'\n", filename);
1590  }
1591 
1592  PROFILE_END(diff,
1593  LOG(llevDebug, "save_map on %s" " took %ld us\n", m->path, diff));
1594 
1595  return SAVE_ERROR_OK;
1596 }
1597 
1607 void clean_object(object *op) {
1608  FOR_INV_PREPARE(op, tmp) {
1609  clean_object(tmp);
1612  object_remove(tmp);
1614  } FOR_INV_FINISH();
1615 }
1616 
1624  int i, j;
1625  object *op;
1626 
1627  for (i = 0; i < MAP_WIDTH(m); i++)
1628  for (j = 0; j < MAP_HEIGHT(m); j++) {
1629  object *previous_obj = NULL;
1630 
1631  while ((op = GET_MAP_OB(m, i, j)) != NULL) {
1632  if (op == previous_obj) {
1633  LOG(llevDebug, "free_all_objects: Link error, bailing out.\n");
1634  break;
1635  }
1636  previous_obj = op;
1637  op = HEAD(op);
1638 
1639  /* If the map isn't in memory, object_free_drop_inventory() will remove and
1640  * free objects in op's inventory. So let it do the job.
1641  */
1642  if (m->in_memory == MAP_IN_MEMORY)
1643  clean_object(op);
1644  object_remove(op);
1646  }
1647  }
1648 #ifdef MANY_CORES
1649  /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1650  * an item on that map was not saved - look for that condition and die as appropriate -
1651  * this leaves more of the map data intact for better debugging.
1652  */
1653  for (op = objects; op != NULL; op = op->next) {
1654  if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1655  LOG(llevError, "free_all_objects: object %s still on map after it should have been freed\n", op->name);
1656  abort();
1657  }
1658  }
1659 #endif
1660 }
1661 
1671  int i;
1672 
1673  if (!m->in_memory) {
1674  LOG(llevError, "Trying to free freed map.\n");
1675  return;
1676  }
1677 
1679 
1680  if (m->spaces)
1682  if (m->name)
1683  FREE_AND_CLEAR(m->name);
1684  if (m->spaces)
1685  FREE_AND_CLEAR(m->spaces);
1686  if (m->msg)
1687  FREE_AND_CLEAR(m->msg);
1688  if (m->maplore)
1689  FREE_AND_CLEAR(m->maplore);
1690  if (m->shopitems)
1691  FREE_AND_CLEAR(m->shopitems);
1692  if (m->shoprace)
1693  FREE_AND_CLEAR(m->shoprace);
1694  if (m->background_music)
1695  FREE_AND_CLEAR(m->background_music);
1696  if (m->buttons)
1697  free_objectlinkpt(m->buttons);
1698  m->buttons = NULL;
1699  for (i = 0; i < 4; i++) {
1700  if (m->tile_path[i])
1701  FREE_AND_CLEAR(m->tile_path[i]);
1702  m->tile_map[i] = NULL;
1703  }
1704  m->in_memory = MAP_SWAPPED;
1705 }
1706 
1717  mapstruct *tmp, *last;
1718  int i;
1719 
1720  if (!m)
1721  return;
1722  if (m->in_memory == MAP_IN_MEMORY) {
1723  /* change to MAP_SAVING, even though we are not,
1724  * so that object_remove() doesn't do as much work.
1725  */
1726  m->in_memory = MAP_SAVING;
1727  free_map(m);
1728  }
1729  /* move this out of free_map, since tmpname can still be needed if
1730  * the map is swapped out.
1731  */
1732  free(m->tmpname);
1733  m->tmpname = NULL;
1734  last = NULL;
1735  /* We need to look through all the maps and see if any maps
1736  * are pointing at this one for tiling information. Since
1737  * tiling can be assymetric, we just can not look to see which
1738  * maps this map tiles with and clears those.
1739  */
1740  for (tmp = first_map; tmp != NULL; tmp = tmp->next) {
1741  if (tmp->next == m)
1742  last = tmp;
1743 
1744  /* This should hopefully get unrolled on a decent compiler */
1745  for (i = 0; i < 4; i++)
1746  if (tmp->tile_map[i] == m)
1747  tmp->tile_map[i] = NULL;
1748  }
1749 
1750  /* If last is null, then this should be the first map in the list */
1751  if (!last) {
1752  if (m == first_map)
1753  first_map = m->next;
1754  else
1755  /* m->path is a static char, so should hopefully still have
1756  * some useful data in it.
1757  */
1758  LOG(llevError, "delete_map: Unable to find map %s in list\n", m->path);
1759  } else
1760  last->next = m->next;
1761 
1762  free(m);
1763 }
1764 
1778 mapstruct *ready_map_name(const char *name, int flags) {
1779  mapstruct *m;
1780 
1781  if (!name)
1782  return (NULL);
1783 
1784  /* Have we been at this level before? */
1785  m = has_been_loaded(name);
1786 
1787  /* Map is good to go, so just return it */
1788  if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) {
1789  return m;
1790  }
1791 
1792  /* Rewrite old paths starting with LOCALDIR/PLAYERDIR to new '~' paths. */
1793  char buf[MAX_BUF], buf2[MAX_BUF];
1794  snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, settings.playerdir);
1795  if (strncmp(name, buf, strlen(buf)) == 0) {
1796  snprintf(buf2, sizeof(buf2), "~%s", name+strlen(buf)+1);
1797  name = buf2;
1798  }
1799 
1800  /* Paths starting with '~' are unique. */
1801  if (name[0] == '~') {
1803  }
1804 
1805  /* unique maps always get loaded from their original location, and never
1806  * a temp location. Likewise, if map_flush is set, or we have never loaded
1807  * this map, load it now. I removed the reset checking from here -
1808  * it seems the probability of a player trying to enter a map that should
1809  * reset but hasn't yet is quite low, and removing that makes this function
1810  * a bit cleaner (and players probably shouldn't rely on exact timing for
1811  * resets in any case - if they really care, they should use the 'maps command.
1812  */
1813  if ((flags&(MAP_FLUSH|MAP_PLAYER_UNIQUE)) || !m) {
1814  /* first visit or time to reset */
1815  if (m) {
1816  clean_tmp_map(m); /* Doesn't make much difference */
1817  delete_map(m);
1818  }
1819 
1821  if (m == NULL) return NULL;
1822 
1823  /* If a player unique map, no extra unique object file to load.
1824  * if from the editor, likewise.
1825  */
1828 
1830  if (load_overlay_map(name, m) != 0) {
1831  delete_map(m);
1832  m = mapfile_load(name, 0);
1833  if (m == NULL) {
1834  /* Really, this map is bad :( */
1835  return NULL;
1836  }
1837  }
1838  }
1839  } else {
1840  /* If in this loop, we found a temporary map, so load it up. */
1841 
1842  if (load_temporary_map(m) != 0) {
1843  /*
1844  * There was a failure loading the temporary map, fall back to original one.
1845  * load_temporary_map() already logged the error.
1846  */
1847  delete_map(m);
1848  m = mapfile_load(name, 0);
1849  if (m == NULL) {
1850  /* Really, this map is bad :( */
1851  return NULL;
1852  }
1853  }
1855 
1856  clean_tmp_map(m);
1857  m->in_memory = MAP_IN_MEMORY;
1858  /* tempnam() on sun systems (probably others) uses malloc
1859  * to allocated space for the string. Free it here.
1860  * In some cases, load_temporary_map above won't find the
1861  * temporary map, and so has reloaded a new map. If that
1862  * is the case, tmpname is now null
1863  */
1864  free(m->tmpname);
1865  m->tmpname = NULL;
1866  /* It's going to be saved anew anyway */
1867  }
1868 
1869  /* Below here is stuff common to both first time loaded maps and
1870  * temp maps.
1871  */
1872 
1873  decay_objects(m); /* start the decay */
1874 
1875  if (m->outdoor)
1877 
1878  if (!(flags&(MAP_FLUSH))) {
1879  if (m->last_reset_time == 0) {
1880  m->last_reset_time = seconds();
1881  }
1882  }
1883  return m;
1884 }
1885 
1902  archetype *at;
1903  int x, y;
1904  int diff = 0;
1905  int i;
1906  int64_t exp_pr_sq, total_exp = 0;
1907 
1908  if (MAP_DIFFICULTY(m)) {
1909  return MAP_DIFFICULTY(m);
1910  }
1911 
1912  for (x = 0; x < MAP_WIDTH(m); x++)
1913  for (y = 0; y < MAP_HEIGHT(m); y++)
1914  FOR_MAP_PREPARE(m, x, y, op) {
1915  if (QUERY_FLAG(op, FLAG_MONSTER))
1916  total_exp += op->stats.exp;
1918  total_exp += op->stats.exp;
1919  // If we have an other_arch on our generator, just use that.
1920  // FIXME: Figure out what to do if we are doing template generation from inventory.
1921  at = op->other_arch ? op->other_arch : NULL;
1922  if (at != NULL) {
1923  // Make sure we can't set off a null pointer dereference in atoi().
1924  const char *val = object_get_value(op, "generator_limit");
1925  int lim = atoi(val ? val : "0");
1926  // We assume, on average, the generator will generate half its contents.
1927  if (!lim || lim >= 16)
1928  total_exp += at->clone.stats.exp*8;
1929  else
1930  total_exp += at->clone.stats.exp*(lim/2);
1931  }
1932  }
1933  } FOR_MAP_FINISH();
1934  // Used to be multiplied by 1000, but this undershot horribly
1935  // once I fixed the calculation for generators.
1936  // I'm trying out some exponentiation, since linear scaling
1937  // seems to overshoot low-level maps and undershoot high-level maps.
1938  // I also feel comfortable, knowing that generators return
1939  // sensible values, to up the max diff this calculates from 20 to 25.
1940  // - Daniel Hawkins 2021-03-04
1941  exp_pr_sq = (pow(total_exp, 1.75))/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1);
1942  diff = 25;
1943  for (i = 1; i < 25; i++)
1944  if (exp_pr_sq <= level_exp(i, 1.0)) {
1945  diff = i;
1946  break;
1947  }
1948 
1949  return diff;
1950 }
1951 
1959  if (m->tmpname == NULL)
1960  return;
1961  (void)unlink(m->tmpname);
1962 }
1963 
1967 void free_all_maps(void) {
1968  int real_maps = 0;
1969 
1970  while (first_map) {
1971  /* I think some of the callers above before it gets here set this to be
1972  * saving, but we still want to free this data
1973  */
1974  if (first_map->in_memory == MAP_SAVING)
1977  real_maps++;
1978  }
1979  LOG(llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1980 }
1981 
1999 int change_map_light(mapstruct *m, int change) {
2000  int new_level = m->darkness+change;
2001 
2002  /* Nothing to do */
2003  if (!change
2004  || (new_level <= 0 && m->darkness == 0)
2005  || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) {
2006  return 0;
2007  }
2008 
2009  /* inform all players on the map */
2010  if (change > 0)
2011  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes darker.");
2012  else
2013  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes brighter.");
2014 
2015  /* Do extra checking. since m->darkness is a unsigned value,
2016  * we need to be extra careful about negative values.
2017  * In general, the checks below are only needed if change
2018  * is not +/-1
2019  */
2020  if (new_level < 0)
2021  m->darkness = 0;
2022  else if (new_level >= MAX_DARKNESS)
2023  m->darkness = MAX_DARKNESS;
2024  else
2025  m->darkness = new_level;
2026 
2027  /* All clients need to get re-updated for the change */
2029  return 1;
2030 }
2031 
2054 static inline void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) {
2055  int l, l1;
2056  object *tmp;
2057 
2058  for (l = low_layer; l <= high_layer; l++) {
2059  if (!layers[l]) {
2060  /* found an empty spot. now, we want to make sure
2061  * highest visibility at top, etc.
2062  */
2063  layers[l] = ob;
2064  if (!honor_visibility)
2065  return;
2066 
2067  /* This is basically a mini bubble sort. Only swap
2068  * position if the lower face has greater (not equal)
2069  * visibility - map stacking is secondary consideration here.
2070  */
2071  for (l1 = (l-1); l1 >= low_layer; l1--) {
2072  if (layers[l1]->face->visibility > layers[l1+1]->face->visibility) {
2073  tmp = layers[l1+1];
2074  layers[l1+1] = layers[l1];
2075  layers[l1] = tmp;
2076  }
2077  }
2078  /* Nothing more to do - face inserted */
2079  return;
2080  }
2081  }
2082  /* If we get here, all the layers have an object..
2083  */
2084  if (!honor_visibility) {
2085  /* Basically, in this case, it is pure stacking logic, so
2086  * new object goes on the top.
2087  */
2088  for (l = low_layer; l < high_layer; l++)
2089  layers[l] = layers[l+1];
2090  layers[high_layer] = ob;
2091  /* If this object doesn't have higher visibility than
2092  * the lowest object, no reason to go further.
2093  */
2094  } else if (ob->face->visibility >= layers[low_layer]->face->visibility) {
2095  /*
2096  * Start at the top (highest visibility) layer and work down.
2097  * once this face exceed that of the layer, push down those
2098  * other layers, and then replace the layer with our object.
2099  */
2100  for (l = high_layer; l >= low_layer; l--) {
2101  if (ob->face->visibility >= layers[l]->face->visibility) {
2102  for (l1 = low_layer; l1 < l; l1++)
2103  layers[l1] = layers[l1+1];
2104  layers[l] = ob;
2105  break;
2106  }
2107  }
2108  }
2109 }
2110 
2123 void update_position(mapstruct *m, int x, int y) {
2124  object *player = NULL;
2125  uint8_t flags = 0, oldflags, light = 0;
2126  object *layers[MAP_LAYERS];
2127 
2128  MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2129 
2130  oldflags = GET_MAP_FLAGS(m, x, y);
2131  if (!(oldflags&P_NEED_UPDATE)) {
2132  LOG(llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
2133  return;
2134  }
2135 
2136  memset(layers, 0, MAP_LAYERS*sizeof(object *));
2137 
2138  FOR_MAP_PREPARE(m, x, y, tmp) {
2139  /* DMs just don't do anything when hidden, including no light. */
2140  if (QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden)
2141  continue;
2142 
2143  if (tmp->type == PLAYER)
2144  player = tmp;
2145 
2146  /* This could be made additive I guess (two lights better than
2147  * one). But if so, it shouldn't be a simple additive - 2
2148  * light bulbs do not illuminate twice as far as once since
2149  * it is a dissipation factor that is squared (or is it cubed?)
2150  */
2151  if (tmp->glow_radius > light)
2152  light = tmp->glow_radius;
2153 
2154  /* if this object is visible and not a blank face,
2155  * update the objects that show how this space
2156  * looks.
2157  */
2158  if (!tmp->invisible && tmp->face != blank_face) {
2159  if (tmp->map_layer) {
2160  add_face_layer(tmp->map_layer, map_layer_info[tmp->map_layer].high_layer,
2161  tmp, layers, map_layer_info[tmp->map_layer].honor_visibility);
2162  } else if (tmp->move_type&MOVE_FLYING) {
2164  } else if ((tmp->type == PLAYER || QUERY_FLAG(tmp, FLAG_MONSTER))) {
2166  } else if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2167  layers[MAP_LAYER_FLOOR] = tmp;
2168  /* floors hide everything else */
2169  memset(layers+1, 0, (MAP_LAYERS-1)*sizeof(object *));
2170  /* Check for FLAG_SEE_ANYWHERE is removed - objects
2171  * with that flag should just have a high visibility
2172  * set - we shouldn't need special code here.
2173  */
2174  } else if (QUERY_FLAG(tmp, FLAG_NO_PICK)) {
2176  } else {
2178  }
2179  }
2180  if (tmp == tmp->above) {
2181  LOG(llevError, "Error in structure of map\n");
2182  exit(-1);
2183  }
2184 
2185  move_slow |= tmp->move_slow;
2186  move_block |= tmp->move_block;
2187  move_on |= tmp->move_on;
2188  move_off |= tmp->move_off;
2189  move_allow |= tmp->move_allow;
2190 
2191  if (QUERY_FLAG(tmp, FLAG_ALIVE))
2192  flags |= P_IS_ALIVE;
2194  flags |= P_NO_MAGIC;
2195  if (QUERY_FLAG(tmp, FLAG_DAMNED) || object_value_set(tmp, "blocks_prayer"))
2196  flags |= P_NO_CLERIC;
2197 
2199  flags |= P_BLOCKSVIEW;
2200  } FOR_MAP_FINISH(); /* for stack of objects */
2201 
2202  if (player)
2203  flags |= P_PLAYER;
2204 
2205  /* we don't want to rely on this function to have accurate flags, but
2206  * since we're already doing the work, we calculate them here.
2207  * if they don't match, logic is broken someplace.
2208  */
2209  if (((oldflags&~(P_NEED_UPDATE|P_NO_ERROR)) != flags)
2210  && (!(oldflags&P_NO_ERROR))) {
2211  LOG(llevDebug, "update_position: updated flags do not match old flags: %s (x=%d,y=%d) %x != %x\n",
2212  m->path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2213  }
2214 
2215  SET_MAP_FLAGS(m, x, y, flags);
2216  SET_MAP_MOVE_BLOCK(m, x, y, move_block&~move_allow);
2217  SET_MAP_MOVE_ON(m, x, y, move_on);
2218  SET_MAP_MOVE_OFF(m, x, y, move_off);
2219  SET_MAP_MOVE_SLOW(m, x, y, move_slow);
2220  SET_MAP_LIGHT(m, x, y, light);
2221 
2222  /* Note that player may be NULL here, which is fine - if no player, need
2223  * to clear any value that may be set.
2224  */
2225  SET_MAP_PLAYER(m, x, y, player);
2226 
2227  /* Note it is intentional we copy everything, including NULL values. */
2228  memcpy(GET_MAP_FACE_OBJS(m, x, y), layers, sizeof(object *)*MAP_LAYERS);
2229 }
2230 
2238  int timeout;
2239 
2240  timeout = MAP_RESET_TIMEOUT(map);
2241  if (timeout <= 0)
2242  timeout = MAP_DEFAULTRESET;
2243  if (timeout >= MAP_MAXRESET)
2244  timeout = MAP_MAXRESET;
2245  MAP_RESET_TIMEOUT(map) = timeout;
2246  MAP_WHEN_RESET(map) = seconds()+timeout;
2247 }
2248 
2263 static mapstruct *load_and_link_tiled_map(mapstruct *orig_map, int tile_num) {
2264  int dest_tile = (tile_num+2)%4;
2265  char path[HUGE_BUF];
2266 
2267  path_combine_and_normalize(orig_map->path, orig_map->tile_path[tile_num], path, sizeof(path));
2268 
2269  orig_map->tile_map[tile_num] = ready_map_name(path, 0);
2270  if (orig_map->tile_map[tile_num] == NULL) {
2271  LOG(llevError, "%s has invalid tiled map %s\n", orig_map->path, path);
2272  free(orig_map->tile_path[tile_num]);
2273  orig_map->tile_path[tile_num] = NULL;
2274  return NULL;
2275  }
2276 
2277  /* need to do a strcmp here as the orig_map->path is not a shared string */
2278  if (orig_map->tile_map[tile_num]->tile_path[dest_tile]
2279  && !strcmp(orig_map->tile_map[tile_num]->tile_path[dest_tile], orig_map->path))
2280  orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
2281 
2282  return orig_map->tile_map[tile_num];
2283 }
2284 
2302 int out_of_map(mapstruct *m, int x, int y) {
2303 
2304  /* Simple case - coordinates are within this local
2305  * map.
2306  */
2307  if (x >= 0 && x < MAP_WIDTH(m) && y >= 0 && y < MAP_HEIGHT(m))
2308  return 0;
2309 
2310  if (x < 0) {
2311  if (!m->tile_path[3])
2312  return 1;
2313  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) {
2315  /* Verify the tile map loaded correctly */
2316  if (!m->tile_map[3])
2317  return 0;
2318  }
2319  return (out_of_map(m->tile_map[3], x+MAP_WIDTH(m->tile_map[3]), y));
2320  } else if (x >= MAP_WIDTH(m)) {
2321  if (!m->tile_path[1])
2322  return 1;
2323  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) {
2325  /* Verify the tile map loaded correctly */
2326  if (!m->tile_map[1])
2327  return 0;
2328  }
2329  return (out_of_map(m->tile_map[1], x-MAP_WIDTH(m), y));
2330  }
2331 
2332  if (y < 0) {
2333  if (!m->tile_path[0])
2334  return 1;
2335  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) {
2337  /* Verify the tile map loaded correctly */
2338  if (!m->tile_map[0])
2339  return 0;
2340  }
2341  return (out_of_map(m->tile_map[0], x, y+MAP_HEIGHT(m->tile_map[0])));
2342  } else if (y >= MAP_HEIGHT(m)) {
2343  if (!m->tile_path[2])
2344  return 1;
2345  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) {
2347  /* Verify the tile map loaded correctly */
2348  if (!m->tile_map[2])
2349  return 0;
2350  }
2351  return (out_of_map(m->tile_map[2], x, y-MAP_HEIGHT(m)));
2352  }
2353  return 1;
2354 }
2355 
2375 mapstruct *get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y) {
2376 
2377  /* Simple case - coordinates are within this local
2378  * map.
2379  */
2380 
2381  if ( !m ) return NULL;
2382  if (*x >= 0 && *x < MAP_WIDTH(m) && *y >= 0 && *y < MAP_HEIGHT(m))
2383  return m;
2384 
2385  do /* With the first case there, we can assume we are out of the map if we get here */
2386  {
2387  // Figure out what map should be in the direction we are off the map, and then
2388  // load that map and look again.
2389  if (*x < 0) {
2390  if (!m->tile_path[3])
2391  return NULL;
2392  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY){
2394  /* Make sure we loaded properly. */
2395  if (!m->tile_map[3])
2396  return NULL;
2397  }
2398  *x += MAP_WIDTH(m->tile_map[3]);
2399  m = m->tile_map[3];
2400  }
2401  else if (*x >= MAP_WIDTH(m)) {
2402  if (!m->tile_path[1])
2403  return NULL;
2404  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY){
2406  /* Make sure we loaded properly. */
2407  if (!m->tile_map[1])
2408  return NULL;
2409  }
2410  *x -= MAP_WIDTH(m);
2411  m = m->tile_map[1];
2412  }
2413  // It is possible that x and y be considered separate compare groups,
2414  // But using an else-if here retains the old behavior that recursion produced.
2415  else if (*y < 0) {
2416  if (!m->tile_path[0])
2417  return NULL;
2418  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY){
2420  /* Make sure we loaded properly. */
2421  if (!m->tile_map[0])
2422  return NULL;
2423  }
2424  *y += MAP_HEIGHT(m->tile_map[0]);
2425  m = m->tile_map[0];
2426  }
2427  else if (*y >= MAP_HEIGHT(m)) {
2428  if (!m->tile_path[2])
2429  return NULL;
2430  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY){
2432  /* Make sure we loaded properly. */
2433  if (!m->tile_map[2])
2434  return NULL;
2435  }
2436  *y -= MAP_HEIGHT(m);
2437  m = m->tile_map[2];
2438  }
2439  // The check here is if our single tile is in the map.
2440  // That is exactly what the OUT_OF_MAP macro does.
2441  } while (OUT_OF_REAL_MAP(m, *x, *y));
2442  return m; /* We have found our map */
2443 }
2444 
2458 static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {
2459  if (!map1 || !map2)
2460  return 0;
2461 
2462  if (map1 == map2) {
2463  *dx = 0;
2464  *dy = 0;
2465  } else if (map1->tile_map[0] == map2) { /* up */
2466  *dx = 0;
2467  *dy = -MAP_HEIGHT(map2);
2468  } else if (map1->tile_map[1] == map2) { /* right */
2469  *dx = MAP_WIDTH(map1);
2470  *dy = 0;
2471  } else if (map1->tile_map[2] == map2) { /* down */
2472  *dx = 0;
2473  *dy = MAP_HEIGHT(map1);
2474  } else if (map1->tile_map[3] == map2) { /* left */
2475  *dx = -MAP_WIDTH(map2);
2476  *dy = 0;
2477  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) { /* up right */
2478  *dx = MAP_WIDTH(map1->tile_map[0]);
2479  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2480  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) { /* up left */
2481  *dx = -MAP_WIDTH(map2);
2482  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2483  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) { /* right up */
2484  *dx = MAP_WIDTH(map1);
2485  *dy = -MAP_HEIGHT(map2);
2486  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) { /* right down */
2487  *dx = MAP_WIDTH(map1);
2488  *dy = MAP_HEIGHT(map1->tile_map[1]);
2489  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) { /* down right */
2490  *dx = MAP_WIDTH(map1->tile_map[2]);
2491  *dy = MAP_HEIGHT(map1);
2492  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) { /* down left */
2493  *dx = -MAP_WIDTH(map2);
2494  *dy = MAP_HEIGHT(map1);
2495  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) { /* left up */
2496  *dx = -MAP_WIDTH(map1->tile_map[3]);
2497  *dy = -MAP_HEIGHT(map2);
2498  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) { /* left down */
2499  *dx = -MAP_WIDTH(map1->tile_map[3]);
2500  *dy = MAP_HEIGHT(map1->tile_map[3]);
2501  } else { /* not "adjacent" enough */
2502  return 0;
2503  }
2504 
2505  return 1;
2506 }
2507 
2535 int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags) {
2536  if (!adjacent_map(op1->map, op2->map, &retval->distance_x, &retval->distance_y)) {
2537  /* be conservative and fill in _some_ data */
2538  retval->distance = 100000;
2539  retval->distance_x = 32767;
2540  retval->distance_y = 32767;
2541  retval->direction = 0;
2542  retval->part = NULL;
2543  return 0;
2544  } else {
2545  object *best;
2546 
2547  retval->distance_x += op2->x-op1->x;
2548  retval->distance_y += op2->y-op1->y;
2549 
2550  best = op1;
2551  /* If this is multipart, find the closest part now */
2552  if (!(flags&0x1) && op1->more) {
2553  object *tmp;
2554  int best_distance = retval->distance_x*retval->distance_x+
2555  retval->distance_y*retval->distance_y, tmpi;
2556 
2557  /* we just take the offset of the piece to head to figure
2558  * distance instead of doing all that work above again
2559  * since the distance fields we set above are positive in the
2560  * same axis as is used for multipart objects, the simply arithmetic
2561  * below works.
2562  */
2563  for (tmp = op1->more; tmp != NULL; tmp = tmp->more) {
2564  tmpi = (op1->x-tmp->x+retval->distance_x)*(op1->x-tmp->x+retval->distance_x)+
2565  (op1->y-tmp->y+retval->distance_y)*(op1->y-tmp->y+retval->distance_y);
2566  if (tmpi < best_distance) {
2567  best_distance = tmpi;
2568  best = tmp;
2569  }
2570  }
2571  if (best != op1) {
2572  retval->distance_x += op1->x-best->x;
2573  retval->distance_y += op1->y-best->y;
2574  }
2575  }
2576  retval->part = best;
2577  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2578  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2579  return 1;
2580  }
2581 }
2582 
2608 int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags) {
2609  (void)flags; // unused [avoid compiler warning]
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[HUGE_BUF];
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 }
get_linked_map
mapstruct * get_linked_map(void)
Definition: map.c:786
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:1778
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:247
output_file.h
path.h
global.h
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:569
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:1806
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:728
SAVE_MODE
#define SAVE_MODE
Definition: config.h:555
object_sum_weight
signed long object_sum_weight(object *op)
Definition: object.c:561
MAP_SAVING
#define MAP_SAVING
Definition: map.h:134
obj::face
const Face * face
Definition: object.h:334
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:212
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:306
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:5166
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:1958
obj::map
struct mapdef * map
Definition: object.h:298
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:1607
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2302
decay_objects
void decay_objects(mapstruct *m)
Definition: utils.c:175
object_new
object * object_new(void)
Definition: object.c:1242
MAP_LAYER_FLOOR
#define MAP_LAYER_FLOOR
Definition: map.h:40
Settings::datadir
const char * datadir
Definition: global.h:244
calculate_difficulty
int calculate_difficulty(mapstruct *m)
Definition: map.c:1901
objects
object * objects
Definition: object.c:283
FLAG_UNIQUE
#define FLAG_UNIQUE
Definition: define.h:287
pl
Definition: player.h:92
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
python_event.path
path
Definition: python_event.py:11
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:344
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.c:355
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:113
mapdef::tile_map
struct mapdef * tile_map[4]
Definition: map.h:363
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:2263
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:498
MAP_OVERLAY
#define MAP_OVERLAY
Definition: map.h:100
shopitem::typenum
int typenum
Definition: map.h:307
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:279
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:2535
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:384
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:586
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:63
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
Definition: map.c:55
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:362
archt
Definition: object.h:468
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:889
INS_ABOVE_FLOOR_ONLY
#define INS_ABOVE_FLOOR_ONLY
Definition: object.h:568
rv_vector::distance_y
int distance_y
Definition: map.h:382
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4354
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:2458
m
static event_registration m
Definition: citylife.cpp:425
set_darkness_map
void set_darkness_map(mapstruct *m)
Definition: main.c:372
rv_vector::distance_x
int distance_x
Definition: map.h:381
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:1273
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:1999
SAVE_ERROR_CLOSE
#define SAVE_ERROR_CLOSE
Definition: map.h:150
strip_endline
void strip_endline(char *buf)
Definition: utils.c:341
PROFILE_BEGIN
#define PROFILE_BEGIN(expr)
Definition: map.c:38
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:1020
HEAD
#define HEAD(op)
Definition: object.h:594
fatal
void fatal(enum fatal_error err)
Definition: utils.c:597
object_fix_multipart
void object_fix_multipart(object *tmp)
Definition: object.c:4672
SAVE_ERROR_RCREATION
#define SAVE_ERROR_RCREATION
Definition: map.h:145
MAP_WHEN_RESET
#define MAP_WHEN_RESET(m)
Definition: map.h:62
get_region_by_name
region * get_region_by_name(const char *region_name)
Definition: region.c:46
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:72
obj::x
int16_t x
Definition: object.h:328
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
Definition: events.h:49
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:567
create_items_path
static void create_items_path(const char *s, char *buf, size_t size)
Definition: map.c:177
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:2670
MAP_LAYER_LIVING1
#define MAP_LAYER_LIVING1
Definition: map.h:46
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:675
MAP_DEFAULTRESET
#define MAP_DEFAULTRESET
Definition: config.h:419
archt::more
struct archt * more
Definition: object.h:471
free_map
void free_map(mapstruct *m)
Definition: map.c:1670
disinfect.count
int count
Definition: disinfect.py:7
link_multipart_objects
static void link_multipart_objects(mapstruct *m)
Definition: map.c:594
mapdef::spaces
MapSpace * spaces
Definition: map.h:354
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
load_objects
static void load_objects(mapstruct *m, FILE *fp, int mapflags)
Definition: map.c:622
sproto.h
map_get_path
const char * map_get_path(const object *item)
Definition: map.c:2712
MapSpace
Definition: map.h:257
mapdef
Definition: map.h:324
Map_Layer_Info
struct Map_Layer_Info Map_Layer_Info
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:420
delete_map
void delete_map(mapstruct *m)
Definition: map.c:1716
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:134
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:570
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:246
SAVE_ERROR_UCREATION
#define SAVE_ERROR_UCREATION
Definition: map.h:146
save_map
int save_map(mapstruct *m, int flag)
Definition: map.c:1416
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:721
obj::y
int16_t y
Definition: object.h:328
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:339
add_face_layer
static void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
Definition: map.c:2054
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:572
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:61
obj::stats
living stats
Definition: object.h:371
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:191
archt::clone
object clone
Definition: object.h:472
free_all_maps
void free_all_maps(void)
Definition: map.c:1967
Map_Layer_Info::high_layer
uint8_t high_layer
Definition: map.c:62
Face::visibility
uint8_t visibility
Definition: face.h:16
shopitem::name
const char * name
Definition: map.h:305
item
Definition: item.py:1
object_remove_from_active_list
void object_remove_from_active_list(object *op)
Definition: object.c:1365
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
bool object_value_set(const object *op, const char *const key)
Definition: object.c:4384
rv_vector
Definition: map.h:379
MAP_SWAPPED
#define MAP_SWAPPED
Definition: map.h:132
shopitem::index
int index
Definition: map.h:310
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:1606
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:319
SAVE_ERROR_URENAME
#define SAVE_ERROR_URENAME
Definition: map.h:149
dump_map
void dump_map(const mapstruct *m)
Definition: map.c:256
guild_entry.x1
int x1
Definition: guild_entry.py:33
load_unique_objects
static void load_unique_objects(mapstruct *m)
Definition: map.c:1369
obj::more
struct obj * more
Definition: object.h:296
typedata::number
int number
Definition: define.h:90
obj::move_type
MoveType move_type
Definition: object.h:428
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
S_IRUSR
#define S_IRUSR
Definition: win32.h:56
fix_container_multipart
static void fix_container_multipart(object *container)
Definition: map.c:553
map_size
uint32_t map_size(mapstruct *m)
Definition: map.c:823
castle_read.key
key
Definition: castle_read.py:64
find_dir_2
int find_dir_2(int x, int y)
Definition: object.c:3685
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
PROFILE_END
#define PROFILE_END(var, expr)
Definition: map.c:43
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:2067
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:1533
print_shop_string
static void print_shop_string(mapstruct *m, char *output_string, int size)
Definition: map.c:975
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2123
MAP_ENTER_X
#define MAP_ENTER_X(m)
Definition: map.h:85
Settings::templatedir
const char * templatedir
Definition: global.h:250
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
save_objects
static int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
Definition: map.c:735
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:251
mapdef::path
char path[HUGE_BUF]
Definition: map.h:364
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:311
delete_unique_items
static void delete_unique_items(mapstruct *m)
Definition: map.c:1344
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:346
SAVE_FLAG_SAVE_UNPAID
#define SAVE_FLAG_SAVE_UNPAID
Definition: map.h:111
rv_vector::direction
int direction
Definition: map.h:383
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:867
free_all_objects
static void free_all_objects(mapstruct *m)
Definition: map.c:1623
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2647
shopitem::strength
int8_t strength
Definition: map.h:308
set_map_reset_time
void set_map_reset_time(mapstruct *map)
Definition: map.c:2237
if
if(!(yy_init))
Definition: loader.c:2589
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2375
mapdef::next
struct mapdef * next
Definition: map.h:325
rv_vector::distance
unsigned int distance
Definition: map.h:380
MAP_LOADING
#define MAP_LOADING
Definition: map.h:133
shopitem
Definition: map.h:304
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:668
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:2608
altar_valkyrie.res
int res
Definition: altar_valkyrie.py:74
S_IRGRP
#define S_IRGRP
Definition: win32.h:53
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:27
update_all_map_los
void update_all_map_los(mapstruct *map)
Definition: los.c:508
save_object
int save_object(FILE *fp, object *op, int flag)
Definition: object.c:5347
llevDebug
@ llevDebug
Definition: logger.h:13
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.c:1210
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302
P_BLOCKSVIEW
#define P_BLOCKSVIEW
Definition: map.h:227
allocate_map
static void allocate_map(mapstruct *m)
Definition: map.c:837
load_overlay_map
static int load_overlay_map(const char *filename, mapstruct *m)
Definition: map.c:1309
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:88
Settings::uniquedir
const char * uniquedir
Definition: global.h:249
OutputFile
Definition: output_file.h:41
create_template_pathname
void create_template_pathname(const char *name, char *buf, size_t size)
Definition: map.c:154
map_remove_unique_files
void map_remove_unique_files(const mapstruct *map)
Definition: map.c:2687
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:797
Settings::localdir
const char * localdir
Definition: global.h:245