Crossfire Server, Trunk
map.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <ctype.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/stat.h>
27 #include <math.h>
28 
29 #ifndef WIN32 /* ---win32 exclude header */
30 #include <unistd.h>
31 #endif /* win32 */
32 
33 #include "sproto.h"
34 #include "loader.h"
35 #include "output_file.h"
36 #include "path.h"
37 
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, false))) {
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 (%ld us serializing, %ld us writing)\n", count, m->path, serialize_time, write_time);
774  return 0;
775 }
776 
789  mapstruct *map = static_cast<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 = static_cast<MapSpace *>(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 = static_cast<shopitems *>(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 
1199 void map_path(const char *map, int flags, char *pathname, size_t bufsize) {
1200  if (flags&MAP_PLAYER_UNIQUE) {
1201  snprintf(pathname, bufsize, "%s/%s/%s", settings.localdir, settings.playerdir, map+1);
1202  }
1203  else if (flags&MAP_OVERLAY)
1204  create_overlay_pathname(map, pathname, bufsize);
1205  else
1206  create_pathname(map, pathname, bufsize);
1207 }
1208 
1209 mapstruct *mapfile_load_lowlevel(const char *map, const char *pathname, int flags) {
1210  FILE *fp;
1211  if ((fp = fopen(pathname, "r")) == NULL) {
1213  "Can't open %s: %s\n", pathname, strerror(errno));
1214  return NULL;
1215  }
1216 
1217  mapstruct *m = get_linked_map();
1218  safe_strncpy(m->path, map, HUGE_BUF);
1219  if (load_map_header(fp, m)) {
1220  LOG(llevError, "Error loading map header for %s, flags=%d\n", map, flags);
1221  delete_map(m);
1222  fclose(fp);
1223  return NULL;
1224  }
1225 
1226  allocate_map(m);
1227 
1228  m->in_memory = MAP_LOADING;
1229  load_objects(m, fp, flags & MAP_STYLE);
1230  fclose(fp);
1231  m->in_memory = MAP_IN_MEMORY;
1232  return m;
1233 }
1234 
1250 mapstruct *mapfile_load(const char *map, int flags) {
1251  mapstruct *m;
1252  PROFILE_BEGIN();
1253  char pathname[MAX_BUF];
1254  map_path(map, flags, pathname, sizeof(pathname));
1255  m = mapfile_load_lowlevel(map, pathname, flags);
1256  if (!m) {
1257  return NULL;
1258  }
1259  if (!MAP_DIFFICULTY(m) && (!(flags & MAP_NO_DIFFICULTY)))
1262 
1263  /* In case other objects press some buttons down */
1264  update_buttons(m);
1265 
1267 
1268  if (!(flags & MAP_STYLE))
1269  apply_auto_fix(m); /* Chests which open as default */
1270 
1271  PROFILE_END(diff,
1272  LOG(llevDebug, "mapfile_load on %s" " took %ld us\n", map, diff));
1273 
1274  return (m);
1275 }
1276 
1286  FILE *fp;
1287 
1288  if (!m->tmpname) {
1289  LOG(llevError, "No temporary filename for map %s\n", m->path);
1290  return 1;
1291  }
1292 
1293  if ((fp = fopen(m->tmpname, "r")) == NULL) {
1294  LOG(llevError, "Cannot open %s: %s\n", m->tmpname, strerror(errno));
1295  return 2;
1296  }
1297 
1298  if (load_map_header(fp, m)) {
1299  LOG(llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1300  fclose(fp);
1301  return 3;
1302  }
1303  allocate_map(m);
1304 
1305  m->in_memory = MAP_LOADING;
1306  load_objects(m, fp, 0);
1307  fclose(fp);
1308  m->in_memory = MAP_IN_MEMORY;
1309  return 0;
1310 }
1311 
1321 static int load_overlay_map(const char *filename, mapstruct *m) {
1322  FILE *fp;
1323  char pathname[MAX_BUF];
1324 
1326 
1327  if ((fp = fopen(pathname, "r")) == NULL) {
1328  /* nothing bad to not having an overlay */
1329  return 0;
1330  }
1331 
1332  if (load_map_header(fp, m)) {
1333  LOG(llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1334  fclose(fp);
1335  return 1;
1336  }
1337  /*allocate_map(m);*/
1338 
1339  m->in_memory = MAP_LOADING;
1340  load_objects(m, fp, MAP_OVERLAY);
1341  fclose(fp);
1342  m->in_memory = MAP_IN_MEMORY;
1343  return 0;
1344 }
1345 
1346 /******************************************************************************
1347  * This is the start of unique map handling code
1348  *****************************************************************************/
1349 
1357  int i, j, unique = 0;
1358 
1359  for (i = 0; i < MAP_WIDTH(m); i++)
1360  for (j = 0; j < MAP_HEIGHT(m); j++) {
1361  unique = 0;
1362  FOR_MAP_PREPARE(m, i, j, op) {
1364  unique = 1;
1365  if (op->head == NULL && (QUERY_FLAG(op, FLAG_UNIQUE) || unique)) {
1366  clean_object(op);
1369  object_remove(op);
1371  }
1372  } FOR_MAP_FINISH();
1373  }
1374 }
1375 
1382  FILE *fp;
1383  int count;
1384  char firstname[MAX_BUF], name[MAX_BUF];
1385 
1386  create_items_path(m->path, name, MAX_BUF);
1387  for (count = 0; count < 10; count++) {
1388  snprintf(firstname, sizeof(firstname), "%s.v%02d", name, count);
1389  if (!access(firstname, R_OK))
1390  break;
1391  }
1392  /* If we get here, we did not find any map */
1393  if (count == 10)
1394  return;
1395 
1396  if ((fp = fopen(firstname, "r")) == NULL) {
1397  /* There is no expectation that every map will have unique items, but this
1398  * is debug output, so leave it in.
1399  */
1400  LOG(llevDebug, "Can't open unique items file for %s\n", name);
1401  return;
1402  }
1403 
1404  m->in_memory = MAP_LOADING;
1405  if (m->tmpname == NULL) /* if we have loaded unique items from */
1406  delete_unique_items(m); /* original map before, don't duplicate them */
1407  load_object(fp, NULL, LO_NOREAD, 0, false);
1408  load_objects(m, fp, 0);
1409  fclose(fp);
1410  m->in_memory = MAP_IN_MEMORY;
1411 }
1412 
1428 int save_map(mapstruct *m, int flag) {
1429  FILE *fp, *fp2;
1430  OutputFile of, of2;
1431  char filename[MAX_BUF], shop[MAX_BUF];
1432  int i, res;
1433 
1434  if (flag && !*m->path) {
1435  LOG(llevError, "Tried to save map without path.\n");
1436  return SAVE_ERROR_NO_PATH;
1437  }
1438 
1439  PROFILE_BEGIN();
1440 
1441  if (flag != SAVE_MODE_NORMAL || (m->unique) || (m->is_template)) {
1442  if (!m->unique && !m->is_template) { /* flag is set */
1443  if (flag == SAVE_MODE_OVERLAY)
1445  else
1446  create_pathname(m->path, filename, MAX_BUF);
1447  } else {
1448  if (m->path[0] != '~') {
1449  LOG(llevError,
1450  "Cannot save unique map '%s' outside of LOCALDIR. Check "
1451  "that all exits to '%s' have FLAG_UNIQUE set correctly.\n",
1452  m->path, m->path);
1453  return SAVE_ERROR_UCREATION;
1454  }
1455  snprintf(filename, sizeof(filename), "%s/%s/%s", settings.localdir, settings.playerdir, m->path+1);
1456  }
1457 
1459  } else {
1460  if (!m->tmpname)
1461  m->tmpname = tempnam(settings.tmpdir, NULL);
1462  strlcpy(filename, m->tmpname, sizeof(filename));
1463  }
1464  m->in_memory = MAP_SAVING;
1465 
1466  fp = of_open(&of, filename);
1467  if (fp == NULL)
1468  return SAVE_ERROR_RCREATION;
1469 
1470  /* legacy */
1471  fprintf(fp, "arch map\n");
1472  if (m->name)
1473  fprintf(fp, "name %s\n", m->name);
1474  if (!flag)
1475  fprintf(fp, "swap_time %d\n", m->swap_time);
1476  if (m->reset_timeout)
1477  fprintf(fp, "reset_timeout %u\n", m->reset_timeout);
1478  if (m->fixed_resettime)
1479  fprintf(fp, "fixed_resettime %d\n", m->fixed_resettime);
1480  /* we unfortunately have no idea if this is a value the creator set
1481  * or a difficulty value we generated when the map was first loaded
1482  */
1483  if (m->difficulty)
1484  fprintf(fp, "difficulty %d\n", m->difficulty);
1485  if (m->region)
1486  fprintf(fp, "region %s\n", m->region->name);
1487  if (m->shopitems) {
1488  print_shop_string(m, shop, sizeof(shop));
1489  fprintf(fp, "shopitems %s\n", shop);
1490  }
1491  if (m->shopgreed)
1492  fprintf(fp, "shopgreed %f\n", m->shopgreed);
1493  if (m->shopmin)
1494  fprintf(fp, "shopmin %" FMT64U "\n", m->shopmin);
1495  if (m->shopmax)
1496  fprintf(fp, "shopmax %" FMT64U "\n", m->shopmax);
1497  if (m->shoprace)
1498  fprintf(fp, "shoprace %s\n", m->shoprace);
1499  if (m->darkness)
1500  fprintf(fp, "darkness %d\n", m->darkness);
1501  if (m->width)
1502  fprintf(fp, "width %d\n", m->width);
1503  if (m->height)
1504  fprintf(fp, "height %d\n", m->height);
1505  if (m->enter_x)
1506  fprintf(fp, "enter_x %d\n", m->enter_x);
1507  if (m->enter_y)
1508  fprintf(fp, "enter_y %d\n", m->enter_y);
1509  if (m->msg)
1510  fprintf(fp, "msg\n%sendmsg\n", m->msg);
1511  if (m->maplore)
1512  fprintf(fp, "maplore\n%sendmaplore\n", m->maplore);
1513  if (m->unique)
1514  fprintf(fp, "unique %d\n", m->unique);
1515  if (m->is_template)
1516  fprintf(fp, "template %d\n", m->is_template);
1517  if (m->outdoor)
1518  fprintf(fp, "outdoor %d\n", m->outdoor);
1519  if (m->nosmooth)
1520  fprintf(fp, "nosmooth %d\n", m->nosmooth);
1521  if (m->last_reset_time)
1522  fprintf(fp, "first_load %ld\n", m->last_reset_time);
1523  if (m->background_music)
1524  fprintf(fp, "background_music %s\n", m->background_music);
1525  if (m->reset_group)
1526  fprintf(fp, "reset_group %s\n", m->reset_group);
1527 
1528  /* Save any tiling information, except on overlays */
1529  if (flag != SAVE_MODE_OVERLAY)
1530  for (i = 0; i < 4; i++)
1531  if (m->tile_path[i])
1532  fprintf(fp, "tile_path_%d %s\n", i+1, m->tile_path[i]);
1533 
1534  fprintf(fp, "end\n");
1535 
1536  /* In the game save unique items in the different file, but
1537  * in the editor save them to the normal map file.
1538  * If unique map, save files in the proper destination (set by
1539  * player)
1540  */
1541  if ((flag == SAVE_MODE_NORMAL || flag == SAVE_MODE_OVERLAY) && !m->unique && !m->is_template) {
1542  char name[MAX_BUF], final_unique[MAX_BUF];
1543 
1544  create_items_path(m->path, name, MAX_BUF);
1545  snprintf(final_unique, sizeof(final_unique), "%s.v00", name);
1546  fp2 = of_open(&of2, final_unique);
1547  if (fp2 == NULL) {
1548  of_cancel(&of);
1549  return SAVE_ERROR_UCREATION;
1550  }
1551  if (flag == SAVE_MODE_OVERLAY) {
1552  /* SO_FLAG_NO_REMOVE is non destructive save, so map is still valid. */
1553  res = save_objects(m, fp, fp2, SAVE_FLAG_NO_REMOVE);
1554  if (res < 0) {
1555  LOG(llevError, "Save error during object save: %d\n", res);
1556  of_cancel(&of);
1557  of_cancel(&of2);
1558  return res;
1559  }
1560  m->in_memory = MAP_IN_MEMORY;
1561  } else {
1562  res = save_objects(m, fp, fp2, 0);
1563  if (res < 0) {
1564  LOG(llevError, "Save error during object save: %d\n", res);
1565  of_cancel(&of);
1566  of_cancel(&of2);
1567  return res;
1568  }
1570  }
1571  if (ftell(fp2) == 0) {
1572  of_cancel(&of2);
1573  /* If there are no unique items left on the map, we need to
1574  * unlink the original unique map so that the unique
1575  * items don't show up again.
1576  */
1577  unlink(final_unique);
1578  } else {
1579  if (!of_close(&of2)) {
1580  of_cancel(&of);
1581  return SAVE_ERROR_URENAME;
1582  }
1583 
1584  if (chmod(final_unique, SAVE_MODE) != 0) {
1585  LOG(llevError, "Could not set permissions on '%s'\n",
1586  final_unique);
1587  }
1588  }
1589  } else { /* save same file when not playing, like in editor */
1590  res = save_objects(m, fp, fp, 0);
1591  if (res < 0) {
1592  LOG(llevError, "Save error during object save: %d\n", res);
1593  of_cancel(&of);
1594  return res;
1595  }
1597  }
1598 
1599  if (!of_close(&of))
1600  return SAVE_ERROR_CLOSE;
1601 
1602  if (chmod(filename, SAVE_MODE) != 0) {
1603  LOG(llevError, "Could not set permissions on '%s'\n", filename);
1604  }
1605 
1606  PROFILE_END(diff,
1607  LOG(llevDebug, "save_map on %s" " took %ld us\n", m->path, diff));
1608 
1609  return SAVE_ERROR_OK;
1610 }
1611 
1621 void clean_object(object *op) {
1622  FOR_INV_PREPARE(op, tmp) {
1623  clean_object(tmp);
1626  object_remove(tmp);
1628  } FOR_INV_FINISH();
1629 }
1630 
1638  int i, j;
1639  object *op;
1640 
1641  for (i = 0; i < MAP_WIDTH(m); i++)
1642  for (j = 0; j < MAP_HEIGHT(m); j++) {
1643  object *previous_obj = NULL;
1644 
1645  while ((op = GET_MAP_OB(m, i, j)) != NULL) {
1646  if (op == previous_obj) {
1647  LOG(llevDebug, "free_all_objects: Link error, bailing out.\n");
1648  break;
1649  }
1650  previous_obj = op;
1651  op = HEAD(op);
1652 
1653  /* If the map isn't in memory, object_free_drop_inventory() will remove and
1654  * free objects in op's inventory. So let it do the job.
1655  */
1656  if (m->in_memory == MAP_IN_MEMORY)
1657  clean_object(op);
1658  object_remove(op);
1660  }
1661  }
1662 #ifdef MANY_CORES
1663  /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1664  * an item on that map was not saved - look for that condition and die as appropriate -
1665  * this leaves more of the map data intact for better debugging.
1666  */
1667  for (op = objects; op != NULL; op = op->next) {
1668  if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1669  LOG(llevError, "free_all_objects: object %s still on map after it should have been freed\n", op->name);
1670  abort();
1671  }
1672  }
1673 #endif
1674 }
1675 
1685  int i;
1686 
1687  if (!m->in_memory) {
1688  LOG(llevError, "Trying to free freed map.\n");
1689  return;
1690  }
1691 
1693 
1694  if (m->spaces)
1696  if (m->name)
1697  FREE_AND_CLEAR(m->name);
1698  if (m->spaces)
1699  FREE_AND_CLEAR(m->spaces);
1700  if (m->msg)
1701  FREE_AND_CLEAR(m->msg);
1702  if (m->maplore)
1703  FREE_AND_CLEAR(m->maplore);
1704  if (m->shopitems)
1705  FREE_AND_CLEAR(m->shopitems);
1706  if (m->shoprace)
1707  FREE_AND_CLEAR(m->shoprace);
1708  if (m->background_music)
1709  FREE_AND_CLEAR(m->background_music);
1710  if (m->buttons)
1711  free_objectlinkpt(m->buttons);
1712  m->buttons = NULL;
1713  for (i = 0; i < 4; i++) {
1714  if (m->tile_path[i])
1715  FREE_AND_CLEAR(m->tile_path[i]);
1716  m->tile_map[i] = NULL;
1717  }
1718  m->in_memory = MAP_SWAPPED;
1719 }
1720 
1731  mapstruct *tmp, *last;
1732  int i;
1733 
1734  if (!m)
1735  return;
1736  if (m->in_memory == MAP_IN_MEMORY) {
1737  /* change to MAP_SAVING, even though we are not,
1738  * so that object_remove() doesn't do as much work.
1739  */
1740  m->in_memory = MAP_SAVING;
1741  free_map(m);
1742  }
1743  /* move this out of free_map, since tmpname can still be needed if
1744  * the map is swapped out.
1745  */
1746  free(m->tmpname);
1747  m->tmpname = NULL;
1748  FREE_AND_CLEAR_STR_IF(m->reset_group);
1749  last = NULL;
1750  /* We need to look through all the maps and see if any maps
1751  * are pointing at this one for tiling information. Since
1752  * tiling can be assymetric, we just can not look to see which
1753  * maps this map tiles with and clears those.
1754  */
1755  for (tmp = first_map; tmp != NULL; tmp = tmp->next) {
1756  if (tmp->next == m)
1757  last = tmp;
1758 
1759  /* This should hopefully get unrolled on a decent compiler */
1760  for (i = 0; i < 4; i++)
1761  if (tmp->tile_map[i] == m)
1762  tmp->tile_map[i] = NULL;
1763  }
1764 
1765  /* If last is null, then this should be the first map in the list */
1766  if (!last) {
1767  if (m == first_map)
1768  first_map = m->next;
1769  else
1770  /* m->path is a static char, so should hopefully still have
1771  * some useful data in it.
1772  */
1773  LOG(llevError, "delete_map: Unable to find map %s in list\n", m->path);
1774  } else
1775  last->next = m->next;
1776 
1777  free(m);
1778 }
1779 
1793 mapstruct *ready_map_name(const char *name, int flags) {
1794  mapstruct *m;
1795 
1796  if (!name)
1797  return (NULL);
1798 
1799  /* Have we been at this level before? */
1800  m = has_been_loaded(name);
1801 
1802  /* Map is good to go, so just return it */
1803  if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) {
1804  return m;
1805  }
1806 
1807  /* Rewrite old paths starting with LOCALDIR/PLAYERDIR to new '~' paths. */
1808  char buf[MAX_BUF], buf2[MAX_BUF];
1809  snprintf(buf, sizeof(buf), "%s/%s", settings.localdir, settings.playerdir);
1810  if (strncmp(name, buf, strlen(buf)) == 0) {
1811  snprintf(buf2, sizeof(buf2), "~%s", name+strlen(buf)+1);
1812  name = buf2;
1813  }
1814 
1815  /* Paths starting with '~' are unique. */
1816  if (name[0] == '~') {
1818  }
1819 
1820  /* unique maps always get loaded from their original location, and never
1821  * a temp location. Likewise, if map_flush is set, or we have never loaded
1822  * this map, load it now. I removed the reset checking from here -
1823  * it seems the probability of a player trying to enter a map that should
1824  * reset but hasn't yet is quite low, and removing that makes this function
1825  * a bit cleaner (and players probably shouldn't rely on exact timing for
1826  * resets in any case - if they really care, they should use the 'maps command.
1827  */
1828  if ((flags&(MAP_FLUSH|MAP_PLAYER_UNIQUE)) || !m) {
1829  /* first visit or time to reset */
1830  if (m) {
1831  clean_tmp_map(m); /* Doesn't make much difference */
1832  delete_map(m);
1833  }
1834 
1836  if (m == NULL) return NULL;
1837 
1838  /* If a player unique map, no extra unique object file to load.
1839  * if from the editor, likewise.
1840  */
1843 
1845  if (load_overlay_map(name, m) != 0) {
1846  delete_map(m);
1847  m = mapfile_load(name, 0);
1848  if (m == NULL) {
1849  /* Really, this map is bad :( */
1850  return NULL;
1851  }
1852  }
1853  }
1854  } else {
1855  /* If in this loop, we found a temporary map, so load it up. */
1856 
1857  if (load_temporary_map(m) != 0) {
1858  /*
1859  * There was a failure loading the temporary map, fall back to original one.
1860  * load_temporary_map() already logged the error.
1861  */
1862  delete_map(m);
1863  m = mapfile_load(name, 0);
1864  if (m == NULL) {
1865  /* Really, this map is bad :( */
1866  return NULL;
1867  }
1868  }
1870 
1871  clean_tmp_map(m);
1872  m->in_memory = MAP_IN_MEMORY;
1873  /* tempnam() on sun systems (probably others) uses malloc
1874  * to allocated space for the string. Free it here.
1875  * In some cases, load_temporary_map above won't find the
1876  * temporary map, and so has reloaded a new map. If that
1877  * is the case, tmpname is now null
1878  */
1879  free(m->tmpname);
1880  m->tmpname = NULL;
1881  /* It's going to be saved anew anyway */
1882  }
1883 
1884  /* Below here is stuff common to both first time loaded maps and
1885  * temp maps.
1886  */
1887 
1888  decay_objects(m); /* start the decay */
1889 
1890  if (m->outdoor)
1892 
1893  if (!(flags&(MAP_FLUSH))) {
1894  if (m->last_reset_time == 0) {
1895  m->last_reset_time = seconds();
1896  }
1897  }
1898 
1900 
1901  return m;
1902 }
1903 
1920  archetype *at;
1921  int x, y;
1922  int diff = 0;
1923  int i;
1924  int64_t exp_pr_sq, total_exp = 0;
1925 
1926  if (MAP_DIFFICULTY(m)) {
1927  return MAP_DIFFICULTY(m);
1928  }
1929 
1930  for (x = 0; x < MAP_WIDTH(m); x++)
1931  for (y = 0; y < MAP_HEIGHT(m); y++)
1932  FOR_MAP_PREPARE(m, x, y, op) {
1933  if (QUERY_FLAG(op, FLAG_MONSTER))
1934  total_exp += op->stats.exp;
1936  total_exp += op->stats.exp;
1937  // If we have an other_arch on our generator, just use that.
1938  // FIXME: Figure out what to do if we are doing template generation from inventory.
1939  at = op->other_arch ? op->other_arch : NULL;
1940  if (at != NULL) {
1941  // Make sure we can't set off a null pointer dereference in atoi().
1942  const char *val = object_get_value(op, "generator_limit");
1943  int lim = atoi(val ? val : "0");
1944  // We assume, on average, the generator will generate half its contents.
1945  if (!lim || lim >= 16)
1946  total_exp += at->clone.stats.exp*8;
1947  else
1948  total_exp += at->clone.stats.exp*(lim/2);
1949  }
1950  }
1951  } FOR_MAP_FINISH();
1952  // Used to be multiplied by 1000, but this undershot horribly
1953  // once I fixed the calculation for generators.
1954  // I'm trying out some exponentiation, since linear scaling
1955  // seems to overshoot low-level maps and undershoot high-level maps.
1956  // I also feel comfortable, knowing that generators return
1957  // sensible values, to up the max diff this calculates from 20 to 25.
1958  // - Daniel Hawkins 2021-03-04
1959  exp_pr_sq = (pow(total_exp, 1.75))/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1);
1960  diff = 25;
1961  for (i = 1; i < 25; i++)
1962  if (exp_pr_sq <= level_exp(i, 1.0)) {
1963  diff = i;
1964  break;
1965  }
1966 
1967  return diff;
1968 }
1969 
1977  if (m->tmpname == NULL)
1978  return;
1979  (void)unlink(m->tmpname);
1980 }
1981 
1985 void free_all_maps(void) {
1986  int real_maps = 0;
1987 
1988  while (first_map) {
1989  /* I think some of the callers above before it gets here set this to be
1990  * saving, but we still want to free this data
1991  */
1992  if (first_map->in_memory == MAP_SAVING)
1995  real_maps++;
1996  }
1997  LOG(llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1998 }
1999 
2017 int change_map_light(mapstruct *m, int change) {
2018  int new_level = m->darkness+change;
2019 
2020  /* Nothing to do */
2021  if (!change
2022  || (new_level <= 0 && m->darkness == 0)
2023  || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) {
2024  return 0;
2025  }
2026 
2027  /* inform all players on the map */
2028  if (change > 0)
2029  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes darker.");
2030  else
2031  ext_info_map(NDI_BLACK, m, MSG_TYPE_MISC, MSG_SUBTYPE_NONE, "It becomes brighter.");
2032 
2033  /* Do extra checking. since m->darkness is a unsigned value,
2034  * we need to be extra careful about negative values.
2035  * In general, the checks below are only needed if change
2036  * is not +/-1
2037  */
2038  if (new_level < 0)
2039  m->darkness = 0;
2040  else if (new_level >= MAX_DARKNESS)
2041  m->darkness = MAX_DARKNESS;
2042  else
2043  m->darkness = new_level;
2044 
2045  /* All clients need to get re-updated for the change */
2047  return 1;
2048 }
2049 
2072 static inline void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility) {
2073  int l, l1;
2074  object *tmp;
2075 
2076  for (l = low_layer; l <= high_layer; l++) {
2077  if (!layers[l]) {
2078  /* found an empty spot. now, we want to make sure
2079  * highest visibility at top, etc.
2080  */
2081  layers[l] = ob;
2082  if (!honor_visibility)
2083  return;
2084 
2085  /* This is basically a mini bubble sort. Only swap
2086  * position if the lower face has greater (not equal)
2087  * visibility - map stacking is secondary consideration here.
2088  */
2089  for (l1 = (l-1); l1 >= low_layer; l1--) {
2090  if (layers[l1]->face->visibility > layers[l1+1]->face->visibility) {
2091  tmp = layers[l1+1];
2092  layers[l1+1] = layers[l1];
2093  layers[l1] = tmp;
2094  }
2095  }
2096  /* Nothing more to do - face inserted */
2097  return;
2098  }
2099  }
2100  /* If we get here, all the layers have an object..
2101  */
2102  if (!honor_visibility) {
2103  /* Basically, in this case, it is pure stacking logic, so
2104  * new object goes on the top.
2105  */
2106  for (l = low_layer; l < high_layer; l++)
2107  layers[l] = layers[l+1];
2108  layers[high_layer] = ob;
2109  /* If this object doesn't have higher visibility than
2110  * the lowest object, no reason to go further.
2111  */
2112  } else if (ob->face->visibility >= layers[low_layer]->face->visibility) {
2113  /*
2114  * Start at the top (highest visibility) layer and work down.
2115  * once this face exceed that of the layer, push down those
2116  * other layers, and then replace the layer with our object.
2117  */
2118  for (l = high_layer; l >= low_layer; l--) {
2119  if (ob->face->visibility >= layers[l]->face->visibility) {
2120  for (l1 = low_layer; l1 < l; l1++)
2121  layers[l1] = layers[l1+1];
2122  layers[l] = ob;
2123  break;
2124  }
2125  }
2126  }
2127 }
2128 
2141 void update_position(mapstruct *m, int x, int y) {
2142  object *player = NULL;
2143  uint8_t flags = 0, oldflags, light = 0;
2144  object *layers[MAP_LAYERS];
2145 
2146  MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
2147 
2148  oldflags = GET_MAP_FLAGS(m, x, y);
2149  if (!(oldflags&P_NEED_UPDATE)) {
2150  LOG(llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
2151  return;
2152  }
2153 
2154  memset(layers, 0, MAP_LAYERS*sizeof(object *));
2155 
2156  FOR_MAP_PREPARE(m, x, y, tmp) {
2157  /* DMs just don't do anything when hidden, including no light. */
2158  if (QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden)
2159  continue;
2160 
2161  if (tmp->type == PLAYER)
2162  player = tmp;
2163 
2164  /* This could be made additive I guess (two lights better than
2165  * one). But if so, it shouldn't be a simple additive - 2
2166  * light bulbs do not illuminate twice as far as once since
2167  * it is a dissipation factor that is squared (or is it cubed?)
2168  */
2169  if (tmp->glow_radius > light)
2170  light = tmp->glow_radius;
2171 
2172  /* if this object is visible and not a blank face,
2173  * update the objects that show how this space
2174  * looks.
2175  */
2176  if (!tmp->invisible && tmp->face != blank_face) {
2177  if (tmp->map_layer) {
2178  add_face_layer(tmp->map_layer, map_layer_info[tmp->map_layer].high_layer,
2179  tmp, layers, map_layer_info[tmp->map_layer].honor_visibility);
2180  } else if (tmp->move_type&MOVE_FLYING) {
2182  } else if ((tmp->type == PLAYER || QUERY_FLAG(tmp, FLAG_MONSTER))) {
2184  } else if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2185  layers[MAP_LAYER_FLOOR] = tmp;
2186  /* floors hide everything else */
2187  memset(layers+1, 0, (MAP_LAYERS-1)*sizeof(object *));
2188  /* Check for FLAG_SEE_ANYWHERE is removed - objects
2189  * with that flag should just have a high visibility
2190  * set - we shouldn't need special code here.
2191  */
2192  } else if (QUERY_FLAG(tmp, FLAG_NO_PICK)) {
2194  } else {
2196  }
2197  }
2198  if (tmp == tmp->above) {
2199  LOG(llevError, "Error in structure of map\n");
2200  exit(-1);
2201  }
2202 
2203  move_slow |= tmp->move_slow;
2204  move_block |= tmp->move_block;
2205  move_on |= tmp->move_on;
2206  move_off |= tmp->move_off;
2207  move_allow |= tmp->move_allow;
2208 
2209  if (QUERY_FLAG(tmp, FLAG_ALIVE))
2210  flags |= P_IS_ALIVE;
2212  flags |= P_NO_MAGIC;
2214  flags |= P_NO_CLERIC;
2215 
2217  flags |= P_BLOCKSVIEW;
2218  } FOR_MAP_FINISH(); /* for stack of objects */
2219 
2220  if (player)
2221  flags |= P_PLAYER;
2222 
2223  /* we don't want to rely on this function to have accurate flags, but
2224  * since we're already doing the work, we calculate them here.
2225  * if they don't match, logic is broken someplace.
2226  */
2227  if (((oldflags&~(P_NEED_UPDATE|P_NO_ERROR)) != flags)
2228  && (!(oldflags&P_NO_ERROR))) {
2229  LOG(llevDebug, "update_position: updated flags do not match old flags: %s (x=%d,y=%d) %x != %x\n",
2230  m->path, x, y, (oldflags&~P_NEED_UPDATE), flags);
2231  }
2232 
2233  SET_MAP_FLAGS(m, x, y, flags);
2234  SET_MAP_MOVE_BLOCK(m, x, y, move_block&~move_allow);
2235  SET_MAP_MOVE_ON(m, x, y, move_on);
2236  SET_MAP_MOVE_OFF(m, x, y, move_off);
2237  SET_MAP_MOVE_SLOW(m, x, y, move_slow);
2238  SET_MAP_LIGHT(m, x, y, light);
2239 
2240  /* Note that player may be NULL here, which is fine - if no player, need
2241  * to clear any value that may be set.
2242  */
2243  SET_MAP_PLAYER(m, x, y, player);
2244 
2245  /* Note it is intentional we copy everything, including NULL values. */
2246  memcpy(GET_MAP_FACE_OBJS(m, x, y), layers, sizeof(object *)*MAP_LAYERS);
2247 }
2248 
2256  int timeout;
2257 
2258  timeout = MAP_RESET_TIMEOUT(map);
2259  if (timeout <= 0)
2260  timeout = MAP_DEFAULTRESET;
2261  if (timeout >= MAP_MAXRESET)
2262  timeout = MAP_MAXRESET;
2263  MAP_RESET_TIMEOUT(map) = timeout;
2264  MAP_WHEN_RESET(map) = seconds()+timeout;
2265 }
2266 
2281 static mapstruct *load_and_link_tiled_map(mapstruct *orig_map, int tile_num) {
2282  int dest_tile = (tile_num+2)%4;
2283  char path[HUGE_BUF];
2284 
2285  path_combine_and_normalize(orig_map->path, orig_map->tile_path[tile_num], path, sizeof(path));
2286 
2287  orig_map->tile_map[tile_num] = ready_map_name(path, 0);
2288  if (orig_map->tile_map[tile_num] == NULL) {
2289  LOG(llevError, "%s has invalid tiled map %s\n", orig_map->path, path);
2290  free(orig_map->tile_path[tile_num]);
2291  orig_map->tile_path[tile_num] = NULL;
2292  return NULL;
2293  }
2294 
2295  /* need to do a strcmp here as the orig_map->path is not a shared string */
2296  if (orig_map->tile_map[tile_num]->tile_path[dest_tile]
2297  && !strcmp(orig_map->tile_map[tile_num]->tile_path[dest_tile], orig_map->path))
2298  orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map;
2299 
2300  return orig_map->tile_map[tile_num];
2301 }
2302 
2320 int out_of_map(mapstruct *m, int x, int y) {
2321 
2322  /* Simple case - coordinates are within this local
2323  * map.
2324  */
2325  if (x >= 0 && x < MAP_WIDTH(m) && y >= 0 && y < MAP_HEIGHT(m))
2326  return 0;
2327 
2328  if (x < 0) {
2329  if (!m->tile_path[3])
2330  return 1;
2331  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) {
2333  /* Verify the tile map loaded correctly */
2334  if (!m->tile_map[3])
2335  return 0;
2336  }
2337  return (out_of_map(m->tile_map[3], x+MAP_WIDTH(m->tile_map[3]), y));
2338  } else if (x >= MAP_WIDTH(m)) {
2339  if (!m->tile_path[1])
2340  return 1;
2341  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) {
2343  /* Verify the tile map loaded correctly */
2344  if (!m->tile_map[1])
2345  return 0;
2346  }
2347  return (out_of_map(m->tile_map[1], x-MAP_WIDTH(m), y));
2348  }
2349 
2350  if (y < 0) {
2351  if (!m->tile_path[0])
2352  return 1;
2353  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) {
2355  /* Verify the tile map loaded correctly */
2356  if (!m->tile_map[0])
2357  return 0;
2358  }
2359  return (out_of_map(m->tile_map[0], x, y+MAP_HEIGHT(m->tile_map[0])));
2360  } else if (y >= MAP_HEIGHT(m)) {
2361  if (!m->tile_path[2])
2362  return 1;
2363  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) {
2365  /* Verify the tile map loaded correctly */
2366  if (!m->tile_map[2])
2367  return 0;
2368  }
2369  return (out_of_map(m->tile_map[2], x, y-MAP_HEIGHT(m)));
2370  }
2371  return 1;
2372 }
2373 
2393 mapstruct *get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y) {
2394 
2395  /* Simple case - coordinates are within this local
2396  * map.
2397  */
2398 
2399  if ( !m ) return NULL;
2400  if (*x >= 0 && *x < MAP_WIDTH(m) && *y >= 0 && *y < MAP_HEIGHT(m))
2401  return m;
2402 
2403  do /* With the first case there, we can assume we are out of the map if we get here */
2404  {
2405  // Figure out what map should be in the direction we are off the map, and then
2406  // load that map and look again.
2407  if (*x < 0) {
2408  if (!m->tile_path[3])
2409  return NULL;
2410  if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY){
2412  /* Make sure we loaded properly. */
2413  if (!m->tile_map[3])
2414  return NULL;
2415  }
2416  *x += MAP_WIDTH(m->tile_map[3]);
2417  m = m->tile_map[3];
2418  }
2419  else if (*x >= MAP_WIDTH(m)) {
2420  if (!m->tile_path[1])
2421  return NULL;
2422  if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY){
2424  /* Make sure we loaded properly. */
2425  if (!m->tile_map[1])
2426  return NULL;
2427  }
2428  *x -= MAP_WIDTH(m);
2429  m = m->tile_map[1];
2430  }
2431  // It is possible that x and y be considered separate compare groups,
2432  // But using an else-if here retains the old behavior that recursion produced.
2433  else if (*y < 0) {
2434  if (!m->tile_path[0])
2435  return NULL;
2436  if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY){
2438  /* Make sure we loaded properly. */
2439  if (!m->tile_map[0])
2440  return NULL;
2441  }
2442  *y += MAP_HEIGHT(m->tile_map[0]);
2443  m = m->tile_map[0];
2444  }
2445  else if (*y >= MAP_HEIGHT(m)) {
2446  if (!m->tile_path[2])
2447  return NULL;
2448  if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY){
2450  /* Make sure we loaded properly. */
2451  if (!m->tile_map[2])
2452  return NULL;
2453  }
2454  *y -= MAP_HEIGHT(m);
2455  m = m->tile_map[2];
2456  }
2457  // The check here is if our single tile is in the map.
2458  // That is exactly what the OUT_OF_MAP macro does.
2459  } while (OUT_OF_REAL_MAP(m, *x, *y));
2460  return m; /* We have found our map */
2461 }
2462 
2476 static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {
2477  if (!map1 || !map2)
2478  return 0;
2479 
2480  if (map1 == map2) {
2481  *dx = 0;
2482  *dy = 0;
2483  } else if (map1->tile_map[0] == map2) { /* up */
2484  *dx = 0;
2485  *dy = -MAP_HEIGHT(map2);
2486  } else if (map1->tile_map[1] == map2) { /* right */
2487  *dx = MAP_WIDTH(map1);
2488  *dy = 0;
2489  } else if (map1->tile_map[2] == map2) { /* down */
2490  *dx = 0;
2491  *dy = MAP_HEIGHT(map1);
2492  } else if (map1->tile_map[3] == map2) { /* left */
2493  *dx = -MAP_WIDTH(map2);
2494  *dy = 0;
2495  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) { /* up right */
2496  *dx = MAP_WIDTH(map1->tile_map[0]);
2497  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2498  } else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) { /* up left */
2499  *dx = -MAP_WIDTH(map2);
2500  *dy = -MAP_HEIGHT(map1->tile_map[0]);
2501  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) { /* right up */
2502  *dx = MAP_WIDTH(map1);
2503  *dy = -MAP_HEIGHT(map2);
2504  } else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) { /* right down */
2505  *dx = MAP_WIDTH(map1);
2506  *dy = MAP_HEIGHT(map1->tile_map[1]);
2507  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) { /* down right */
2508  *dx = MAP_WIDTH(map1->tile_map[2]);
2509  *dy = MAP_HEIGHT(map1);
2510  } else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) { /* down left */
2511  *dx = -MAP_WIDTH(map2);
2512  *dy = MAP_HEIGHT(map1);
2513  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) { /* left up */
2514  *dx = -MAP_WIDTH(map1->tile_map[3]);
2515  *dy = -MAP_HEIGHT(map2);
2516  } else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) { /* left down */
2517  *dx = -MAP_WIDTH(map1->tile_map[3]);
2518  *dy = MAP_HEIGHT(map1->tile_map[3]);
2519  } else { /* not "adjacent" enough */
2520  return 0;
2521  }
2522 
2523  return 1;
2524 }
2525 
2553 int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags) {
2554  if (!adjacent_map(op1->map, op2->map, &retval->distance_x, &retval->distance_y)) {
2555  /* be conservative and fill in _some_ data */
2556  retval->distance = 100000;
2557  retval->distance_x = 32767;
2558  retval->distance_y = 32767;
2559  retval->direction = 0;
2560  retval->part = NULL;
2561  return 0;
2562  } else {
2563  object *best;
2564 
2565  retval->distance_x += op2->x-op1->x;
2566  retval->distance_y += op2->y-op1->y;
2567 
2568  best = op1;
2569  /* If this is multipart, find the closest part now */
2570  if (!(flags&0x1) && op1->more) {
2571  object *tmp;
2572  int best_distance = retval->distance_x*retval->distance_x+
2573  retval->distance_y*retval->distance_y, tmpi;
2574 
2575  /* we just take the offset of the piece to head to figure
2576  * distance instead of doing all that work above again
2577  * since the distance fields we set above are positive in the
2578  * same axis as is used for multipart objects, the simply arithmetic
2579  * below works.
2580  */
2581  for (tmp = op1->more; tmp != NULL; tmp = tmp->more) {
2582  tmpi = (op1->x-tmp->x+retval->distance_x)*(op1->x-tmp->x+retval->distance_x)+
2583  (op1->y-tmp->y+retval->distance_y)*(op1->y-tmp->y+retval->distance_y);
2584  if (tmpi < best_distance) {
2585  best_distance = tmpi;
2586  best = tmp;
2587  }
2588  }
2589  if (best != op1) {
2590  retval->distance_x += op1->x-best->x;
2591  retval->distance_y += op1->y-best->y;
2592  }
2593  }
2594  retval->part = best;
2595  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2596  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2597  return 1;
2598  }
2599 }
2600 
2626 int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags) {
2627  (void)flags; // unused [avoid compiler warning]
2628  if (!adjacent_map(m, op2->map, &retval->distance_x, &retval->distance_y)) {
2629  /* be conservative and fill in _some_ data */
2630  retval->distance = 100000;
2631  retval->distance_x = 32767;
2632  retval->distance_y = 32767;
2633  retval->direction = 0;
2634  retval->part = NULL;
2635  return 0;
2636  } else {
2637  retval->distance_x += op2->x-x;
2638  retval->distance_y += op2->y-y;
2639 
2640  retval->part = NULL;
2641  retval->distance = isqrt(retval->distance_x*retval->distance_x+retval->distance_y*retval->distance_y);
2642  retval->direction = find_dir_2(-retval->distance_x, -retval->distance_y);
2643  return 1;
2644  }
2645 }
2646 
2665 int on_same_map(const object *op1, const object *op2) {
2666  int dx, dy;
2667 
2668  return adjacent_map(op1->map, op2->map, &dx, &dy);
2669 }
2670 
2688 object *map_find_by_flag(mapstruct *map, int x, int y, int flag) {
2689  object *tmp;
2690 
2691  for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above) {
2692  object *head;
2693 
2694  head = HEAD(tmp);
2695  if (QUERY_FLAG(head, flag))
2696  return head;
2697  }
2698  return NULL;
2699 }
2700 
2706  char base[HUGE_BUF], path[HUGE_BUF];
2707  int count;
2708 
2709  if (map->unique) {
2710  snprintf(path, sizeof(path), "%s/%s/%s", settings.localdir, settings.playerdir, map->path+1);
2711  if (unlink(path) != 0) {
2712  LOG(llevError, "Could not delete %s: %s\n", path, strerror(errno));
2713  }
2714  return;
2715  }
2716 
2717  create_items_path(map->path, base, sizeof(base));
2718 
2719  for (count = 0; count < 10; count++) {
2720  snprintf(path, sizeof(path), "%s.v%02d", base, count);
2721  unlink(path);
2722  }
2723 }
2724 
2730 const char *map_get_path(const object *item) {
2731  if (item->map != NULL) {
2732  if (strlen(item->map->path) > 0) {
2733  return item->map->path;
2734  }
2735 
2736  return item->map->name ? item->map->name : "(empty path and name)";
2737  }
2738 
2739  if (item->env != NULL)
2740  return map_get_path(item->env);
2741 
2742  return "(no map and no env!)";
2743 }
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
S_IWUSR
#define S_IWUSR
Definition: win32.h:47
PLAYER
@ PLAYER
Definition: object.h:110
object_get_owner
object * object_get_owner(object *op)
Definition: object.cpp:804
Settings::mapdir
const char * mapdir
Definition: global.h:251
output_file.h
path.h
FREE_AND_CLEAR_STR_IF
#define FREE_AND_CLEAR_STR_IF(xyz)
Definition: global.h:200
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:534
settings
struct Settings settings
Definition: init.cpp:139
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:571
banquet.l
l
Definition: banquet.py:164
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
SAVE_MODE
#define SAVE_MODE
Definition: config.h:555
MAP_SAVING
#define MAP_SAVING
Definition: map.h:134
obj::face
const Face * face
Definition: object.h:339
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
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.cpp:869
FLAG_OVERLAY_FLOOR
#define FLAG_OVERLAY_FLOOR
Definition: define.h:255
of_close
int of_close(OutputFile *of)
Definition: output_file.cpp:61
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
create_items_path
static void create_items_path(const char *s, char *buf, size_t size)
Definition: map.cpp:167
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:46
of_open
FILE * of_open(OutputFile *of, const char *fname)
Definition: output_file.cpp:30
FLAG_GENERATOR
#define FLAG_GENERATOR
Definition: define.h:248
MAP_RESET_TIMEOUT
#define MAP_RESET_TIMEOUT(m)
Definition: map.h:64
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.cpp:345
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
delete_unique_items
static void delete_unique_items(mapstruct *m)
Definition: map.cpp:1356
ready_map_name
mapstruct * ready_map_name(const char *name, int flags)
Definition: map.cpp:1793
obj::map
struct mapdef * map
Definition: object.h:303
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
S_IROTH
#define S_IROTH
Definition: win32.h:50
load_temporary_map
static int load_temporary_map(mapstruct *m)
Definition: map.cpp:1285
has_been_loaded
mapstruct * has_been_loaded(const char *name)
Definition: map.cpp:78
print_shop_string
static void print_shop_string(mapstruct *m, char *output_string, int size)
Definition: map.cpp:977
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.cpp:2141
MAP_LAYER_FLOOR
#define MAP_LAYER_FLOOR
Definition: map.h:40
Settings::datadir
const char * datadir
Definition: global.h:248
add_face_layer
static void add_face_layer(int low_layer, int high_layer, object *ob, object *layers[], int honor_visibility)
Definition: map.cpp:2072
stringbuffer_new
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.cpp:57
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
SET_MAP_MOVE_ON
#define SET_MAP_MOVE_ON(M, X, Y, C)
Definition: map.h:205
CHECK_INV
@ CHECK_INV
Definition: object.h:172
CALLOC
#define CALLOC(x, y)
Definition: compat.h:31
mapdef::in_memory
uint32_t in_memory
Definition: map.h:338
map_path
void map_path(const char *map, int flags, char *pathname, size_t bufsize)
Definition: map.cpp:1199
map_layer_info
static const Map_Layer_Info map_layer_info[MAP_LAYERS]
Definition: map.cpp:62
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:48
mapdef::tile_map
struct mapdef * tile_map[4]
Definition: map.h:357
msgbuf
static char msgbuf[HUGE_BUF]
Definition: loader.c:2079
typedata::name
const char * name
Definition: define.h:91
clean_object
void clean_object(object *op)
Definition: map.cpp:1621
MAP_PLAYER_UNIQUE
#define MAP_PLAYER_UNIQUE
Definition: map.h:97
PROFILE_BEGIN
#define PROFILE_BEGIN(expr)
Definition: global.h:366
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_map
void dump_map(const mapstruct *m)
Definition: map.cpp:246
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
FLAG_NO_MAGIC
#define FLAG_NO_MAGIC
Definition: define.h:276
blank_face
const Face * blank_face
Definition: image.cpp:36
P_NO_MAGIC
#define P_NO_MAGIC
Definition: map.h:228
TRANSPORT
@ TRANSPORT
Definition: object.h:111
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
LO_NEWFILE
#define LO_NEWFILE
Definition: loader.h:17
FLAG_BLOCKSVIEW
#define FLAG_BLOCKSVIEW
Definition: define.h:269
rv_vector::part
object * part
Definition: map.h:378
npc_dialog.filename
filename
Definition: npc_dialog.py:99
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.cpp:4339
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
free_all_maps
void free_all_maps(void)
Definition: map.cpp:1985
buf
StringBuffer * buf
Definition: readable.cpp:1611
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
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.cpp:53
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:472
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
INS_ABOVE_FLOOR_ONLY
#define INS_ABOVE_FLOOR_ONLY
Definition: object.h:570
rv_vector::distance_y
int distance_y
Definition: map.h:376
map_remove_unique_files
void map_remove_unique_files(const mapstruct *map)
Definition: map.cpp:2705
LO_NOREAD
#define LO_NOREAD
Definition: loader.h:18
typedata
Definition: define.h:89
save_objects
int save_objects(mapstruct *m, FILE *fp, FILE *fp2, int flag)
Definition: map.cpp:725
PROFILE_END
#define PROFILE_END(var, expr)
Definition: global.h:371
m
static event_registration m
Definition: citylife.cpp:425
set_darkness_map
void set_darkness_map(mapstruct *m)
Definition: main.cpp:371
rv_vector::distance_x
int distance_x
Definition: map.h:375
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:131
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.cpp:76
apply_auto_fix
void apply_auto_fix(mapstruct *m)
Definition: main.cpp:258
MAP_LAYER_NO_PICK2
#define MAP_LAYER_NO_PICK2
Definition: map.h:42
MAP_DIFFICULTY
#define MAP_DIFFICULTY(m)
Definition: map.h:65
liv::exp
int64_t exp
Definition: living.h:47
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
item.q
q
Definition: item.py:32
map_size
uint32_t map_size(mapstruct *m)
Definition: map.cpp:825
disinfect.map
map
Definition: disinfect.py:4
P_NEW_MAP
#define P_NEW_MAP
Definition: map.h:251
SAVE_ERROR_CLOSE
#define SAVE_ERROR_CLOSE
Definition: map.h:150
object_value_set_shared
bool object_value_set_shared(const object *op, sstring key)
Definition: object.cpp:4383
of_cancel
void of_cancel(OutputFile *of)
Definition: output_file.cpp:89
get_typedata
const typedata * get_typedata(int itemtype)
Definition: item.cpp:320
P_NO_ERROR
#define P_NO_ERROR
Definition: map.h:241
MSG_TYPE_ATTACK_NOKEY
#define MSG_TYPE_ATTACK_NOKEY
Definition: newclient.h:617
check_inv_recursive
object * check_inv_recursive(object *op, const object *trig)
Definition: button.cpp:782
path_combine_and_normalize
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
Definition: path.cpp:172
load_unique_objects
static void load_unique_objects(mapstruct *m)
Definition: map.cpp:1381
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
first_map
mapstruct * first_map
Definition: init.cpp:107
HEAD
#define HEAD(op)
Definition: object.h:596
clean_tmp_map
void clean_tmp_map(mapstruct *m)
Definition: map.cpp:1976
SAVE_ERROR_RCREATION
#define SAVE_ERROR_RCREATION
Definition: map.h:145
MAP_WHEN_RESET
#define MAP_WHEN_RESET(m)
Definition: map.h:62
change_map_light
int change_map_light(mapstruct *m, int change)
Definition: map.cpp:2017
ext_info_map
void void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
Definition: main.cpp:334
python_init.path
path
Definition: python_init.py:8
mapfile_load_lowlevel
mapstruct * mapfile_load_lowlevel(const char *map, const char *pathname, int flags)
Definition: map.cpp:1209
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.cpp:2320
MAX_DARKNESS
#define MAX_DARKNESS
Definition: define.h:454
MSG_TYPE_ATTACK
#define MSG_TYPE_ATTACK
Definition: newclient.h:409
isqrt
int isqrt(int n)
Definition: utils.cpp:569
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
obj::x
int16_t x
Definition: object.h:333
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
Definition: events.h:51
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:569
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
SET_MAP_FLAGS
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:164
remove_button_link
void remove_button_link(object *op)
Definition: button.cpp:693
MAP_LAYER_LIVING1
#define MAP_LAYER_LIVING1
Definition: map.h:46
MAP_LAYER_FLY1
#define MAP_LAYER_FLY1
Definition: map.h:48
object_free
void object_free(object *ob, int flags)
Definition: object.cpp:1592
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h: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:475
free_map
void free_map(mapstruct *m)
Definition: map.cpp:1684
disinfect.count
int count
Definition: disinfect.py:7
mapdef::spaces
MapSpace * spaces
Definition: map.h:348
level_exp
int64_t level_exp(int level, double expmul)
Definition: living.cpp:1872
free_all_objects
static void free_all_objects(mapstruct *m)
Definition: map.cpp:1637
P_PLAYER
#define P_PLAYER
Definition: map.h:237
sproto.h
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.cpp:2393
MapSpace
Definition: map.h:257
mapdef
Definition: map.h:317
map_find_by_flag
object * map_find_by_flag(mapstruct *map, int x, int y, int flag)
Definition: map.cpp:2688
delete_map
void delete_map(mapstruct *m)
Definition: map.cpp:1730
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:420
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.cpp:488
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:242
SAVE_ERROR_NO_PATH
#define SAVE_ERROR_NO_PATH
Definition: map.h:148
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.cpp:2098
link_multipart_objects
static void link_multipart_objects(mapstruct *m)
Definition: map.cpp:584
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
get_typedata_by_name
const typedata * get_typedata_by_name(const char *name)
Definition: item.cpp:340
fatal
void fatal(enum fatal_error err)
Definition: utils.cpp:580
get_linked_map
mapstruct * get_linked_map(void)
Definition: map.cpp:788
seconds
long seconds(void)
Definition: time.cpp:344
MAP_WIDTH
#define MAP_WIDTH(m)
Definition: map.h:78
create_template_pathname
void create_template_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:144
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:572
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.cpp:222
object_new
object * object_new(void)
Definition: object.cpp:1273
create_overlay_pathname
void create_overlay_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:124
OB_MOVE_BLOCK
#define OB_MOVE_BLOCK(ob1, ob2)
Definition: define.h:423
set_map_reset_time
void set_map_reset_time(mapstruct *map)
Definition: map.cpp:2255
Map_Layer_Info
struct Map_Layer_Info Map_Layer_Info
free_string
void free_string(sstring str)
Definition: shstr.cpp:280
SAVE_MODE_NORMAL
#define SAVE_MODE_NORMAL
Definition: map.h:121
Settings::playerdir
const char * playerdir
Definition: global.h:250
SAVE_ERROR_UCREATION
#define SAVE_ERROR_UCREATION
Definition: map.h:146
StringBuffer
Definition: stringbuffer.cpp:25
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:333
OUT_OF_REAL_MAP
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:218
find_dir_2
int find_dir_2(int x, int y)
Definition: object.cpp:3670
load_and_link_tiled_map
static mapstruct * load_and_link_tiled_map(mapstruct *orig_map, int tile_num)
Definition: map.cpp:2281
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:574
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
decay_objects
void decay_objects(mapstruct *m)
Definition: utils.cpp:175
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
Floor.t
t
Definition: Floor.py:62
Map_Layer_Info
Definition: map.cpp:51
obj::stats
living stats
Definition: object.h:376
load_map_header
static int load_map_header(FILE *fp, mapstruct *m)
Definition: map.cpp:1022
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:193
archt::clone
object clone
Definition: object.h:476
Map_Layer_Info::high_layer
uint8_t high_layer
Definition: map.cpp:52
adjacent_map
static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy)
Definition: map.cpp:2476
Face::visibility
uint8_t visibility
Definition: face.h:16
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.cpp:301
shopitem::name
const char * name
Definition: map.h:298
item
Definition: item.py:1
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:240
create_pathname
char * create_pathname(const char *name, char *buf, size_t size)
Definition: map.cpp:103
give.op
op
Definition: give.py:33
autojail.value
value
Definition: autojail.py:6
MapSpace::flags
uint8_t flags
Definition: map.h:261
rv_vector
Definition: map.h:373
update_buttons
void update_buttons(mapstruct *m)
Definition: button.cpp:227
MAP_SWAPPED
#define MAP_SWAPPED
Definition: map.h:132
objects
object * objects
Definition: object.cpp:294
shopitem::index
int index
Definition: map.h:303
map_get_path
const char * map_get_path(const object *item)
Definition: map.cpp:2730
diamondslots.y
y
Definition: diamondslots.py:16
SET_MAP_MOVE_BLOCK
#define SET_MAP_MOVE_BLOCK(M, X, Y, C)
Definition: map.h:195
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.cpp:2665
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
MAP_HEIGHT
#define MAP_HEIGHT(m)
Definition: map.h:80
save_object_in_sb
void save_object_in_sb(StringBuffer *sb, object *op, const int flag)
Definition: object.cpp:5297
MAP_ENTER_Y
#define MAP_ENTER_Y(m)
Definition: map.h:87
SAVE_ERROR_URENAME
#define SAVE_ERROR_URENAME
Definition: map.h:149
guild_entry.x1
int x1
Definition: guild_entry.py:33
strip_endline
void strip_endline(char *buf)
Definition: utils.cpp:324
obj::more
struct obj * more
Definition: object.h:301
typedata::number
int number
Definition: define.h:90
object_remove_from_active_list
void object_remove_from_active_list(object *op)
Definition: object.cpp:1392
obj::move_type
MoveType move_type
Definition: object.h:432
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:230
S_IRUSR
#define S_IRUSR
Definition: win32.h:56
get_rangevector
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.cpp:2553
create-tower.tile
tile
Definition: create-tower.py:8
update_all_map_los
void update_all_map_los(mapstruct *map)
Definition: los.cpp:508
allocate_map
void allocate_map(mapstruct *m)
Definition: map.cpp:839
castle_read.key
key
Definition: castle_read.py:64
MAP_LAYER_FLY2
#define MAP_LAYER_FLY2
Definition: map.h:49
FMT64U
#define FMT64U
Definition: compat.h:17
SAVE_ERROR_OK
#define SAVE_ERROR_OK
Definition: map.h:144
loader.h
object_fix_multipart
void object_fix_multipart(object *tmp)
Definition: object.cpp:4678
S_IWOTH
#define S_IWOTH
Definition: win32.h:41
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.cpp:308
fix_container_multipart
static void fix_container_multipart(object *container)
Definition: map.cpp:543
MAP_ENTER_X
#define MAP_ENTER_X(m)
Definition: map.h:85
Settings::templatedir
const char * templatedir
Definition: global.h:254
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
EVENT_MAPREADY
#define EVENT_MAPREADY
Definition: events.h:49
MAP_FLUSH
#define MAP_FLUSH
Definition: map.h:96
GET_MAP_FLAGS
#define GET_MAP_FLAGS(M, X, Y)
Definition: map.h:162
DOOR
@ DOOR
Definition: object.h:129
object_sum_weight
signed long object_sum_weight(object *op)
Definition: object.cpp:568
FLAG_UNPAID
#define FLAG_UNPAID
Definition: define.h:236
MAP_LAYER_LIVING2
#define MAP_LAYER_LIVING2
Definition: map.h:47
LL_NORMAL
#define LL_NORMAL
Definition: loader.h:12
OB_TYPE_MOVE_BLOCK
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:432
S_IWGRP
#define S_IWGRP
Definition: win32.h:44
P_NO_CLERIC
#define P_NO_CLERIC
Definition: map.h:239
make_path_to_file
void make_path_to_file(const char *filename)
Definition: porting.cpp:164
save_map
int save_map(mapstruct *m, int flag)
Definition: map.cpp:1428
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.cpp:2626
calculate_difficulty
int calculate_difficulty(mapstruct *m)
Definition: map.cpp:1919
FLAG_IS_LINKED
#define FLAG_IS_LINKED
Definition: define.h:315
SET_MAP_PLAYER
#define SET_MAP_PLAYER(M, X, Y, C)
Definition: map.h:170
blocks_prayer
sstring blocks_prayer
Definition: init.cpp:127
Settings::tmpdir
const char * tmpdir
Definition: global.h:255
mapdef::path
char path[HUGE_BUF]
Definition: map.h:358
MAP_TIMEOUT
#define MAP_TIMEOUT(m)
Definition: map.h:66
mapfile_load
mapstruct * mapfile_load(const char *map, int flags)
Definition: map.cpp:1250
LO_REPEAT
#define LO_REPEAT
Definition: loader.h:15
parse_shop_string
static shopitems * parse_shop_string(const char *input_string, const mapstruct *map)
Definition: map.cpp:891
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
shopitem::strength
int8_t strength
Definition: map.h:301
if
if(!(yy_init))
Definition: loader.c:2626
mapdef::next
struct mapdef * next
Definition: map.h:318
rv_vector::distance
unsigned int distance
Definition: map.h:374
map_layer_name
const char *const map_layer_name[MAP_LAYERS]
Definition: map.cpp:45
MAP_LOADING
#define MAP_LOADING
Definition: map.h:133
load_overlay_map
static int load_overlay_map(const char *filename, mapstruct *m)
Definition: map.cpp:1321
shopitem
Definition: map.h:297
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
check_path
int check_path(const char *name, int prepend_dir)
Definition: map.cpp:202
altar_valkyrie.res
int res
Definition: altar_valkyrie.py:74
S_IRGRP
#define S_IRGRP
Definition: win32.h:53
dump_all_maps
void dump_all_maps(void)
Definition: map.cpp:269
events_execute_global_event
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:27
load_objects
void load_objects(mapstruct *m, FILE *fp, int mapflags)
Definition: map.cpp:612
llevDebug
@ llevDebug
Definition: logger.h:13
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302
P_BLOCKSVIEW
#define P_BLOCKSVIEW
Definition: map.h:227
give.name
name
Definition: give.py:27
LL_MORE
#define LL_MORE
Definition: loader.h:11
Settings::uniquedir
const char * uniquedir
Definition: global.h:253
OutputFile
Definition: output_file.h:41
SET_MAP_MOVE_OFF
#define SET_MAP_MOVE_OFF(M, X, Y, C)
Definition: map.h:210
Settings::localdir
const char * localdir
Definition: global.h:249