ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.30 by root, Thu Sep 14 22:33:59 2006 UTC vs.
Revision 1.34 by root, Sun Dec 3 02:04:57 2006 UTC

31#endif /* win32 */ 31#endif /* win32 */
32 32
33#include "path.h" 33#include "path.h"
34 34
35 35
36extern int nrofallocobjects, nroffreeobjects;
37
38/* 36/*
39 * Returns the mapstruct which has a name matching the given argument. 37 * Returns the maptile which has a name matching the given argument.
40 * return NULL if no match is found. 38 * return NULL if no match is found.
41 */ 39 */
42 40
43mapstruct * 41maptile *
44has_been_loaded (const char *name) 42has_been_loaded (const char *name)
45{ 43{
46 mapstruct *map; 44 maptile *map;
47 45
48 if (!name || !*name) 46 if (!name || !*name)
49 return 0; 47 return 0;
50 for (map = first_map; map; map = map->next) 48 for (map = first_map; map; map = map->next)
51 if (!strcmp (name, map->path)) 49 if (!strcmp (name, map->path))
204 * Dumping these at llevError doesn't seem right, but is 202 * Dumping these at llevError doesn't seem right, but is
205 * necessary to make sure the information is in fact logged. 203 * necessary to make sure the information is in fact logged.
206 */ 204 */
207 205
208void 206void
209dump_map (const mapstruct *m) 207dump_map (const maptile *m)
210{ 208{
211 LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); 209 LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory);
212 LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); 210 LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m));
213 211
214 if (m->msg != NULL) 212 if (m->msg != NULL)
231 */ 229 */
232 230
233void 231void
234dump_all_maps (void) 232dump_all_maps (void)
235{ 233{
236 mapstruct *m; 234 maptile *m;
237 235
238 for (m = first_map; m != NULL; m = m->next) 236 for (m = first_map; m != NULL; m = m->next)
239 { 237 {
240 dump_map (m); 238 dump_map (m);
241 } 239 }
250 * is needed. The case of not passing values is if we're just 248 * is needed. The case of not passing values is if we're just
251 * checking for the existence of something on those spaces, but 249 * checking for the existence of something on those spaces, but
252 * don't expect to insert/remove anything from those spaces. 250 * don't expect to insert/remove anything from those spaces.
253 */ 251 */
254int 252int
255get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) 253get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny)
256{ 254{
257 sint16 newx, newy; 255 sint16 newx, newy;
258 int retval = 0; 256 int retval = 0;
259 mapstruct *mp; 257 maptile *mp;
260 258
261 if (out_of_map (oldmap, x, y)) 259 if (out_of_map (oldmap, x, y))
262 return P_OUT_OF_MAP; 260 return P_OUT_OF_MAP;
263 newx = x; 261 newx = x;
264 newy = y; 262 newy = y;
275 retval |= mp->spaces[newx + mp->width * newy].flags; 273 retval |= mp->spaces[newx + mp->width * newy].flags;
276 274
277 return retval; 275 return retval;
278} 276}
279 277
280
281/* 278/*
282 * Returns true if the given coordinate is blocked except by the 279 * Returns true if the given coordinate is blocked except by the
283 * object passed is not blocking. This is used with 280 * object passed is not blocking. This is used with
284 * multipart monsters - if we want to see if a 2x2 monster 281 * multipart monsters - if we want to see if a 2x2 monster
285 * can move 1 space to the left, we don't want its own area 282 * can move 1 space to the left, we don't want its own area
288 * monster. 285 * monster.
289 * m, x, y are the target map/coordinates - needed for map tiling. 286 * m, x, y are the target map/coordinates - needed for map tiling.
290 * the coordinates & map passed in should have been updated for tiling 287 * the coordinates & map passed in should have been updated for tiling
291 * by the caller. 288 * by the caller.
292 */ 289 */
293
294int 290int
295blocked_link (object *ob, mapstruct *m, int sx, int sy) 291blocked_link (object *ob, maptile *m, int sx, int sy)
296{ 292{
297 object *tmp; 293 object *tmp;
298 int mflags, blocked; 294 int mflags, blocked;
299 295
300 /* Make sure the coordinates are valid - they should be, as caller should 296 /* Make sure the coordinates are valid - they should be, as caller should
412 * code, we need to have actual object to check its move_type 408 * code, we need to have actual object to check its move_type
413 * against the move_block values. 409 * against the move_block values.
414 */ 410 */
415 411
416int 412int
417ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) 413ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
418{ 414{
419 archetype *tmp; 415 archetype *tmp;
420 int flag; 416 int flag;
421 mapstruct *m1; 417 maptile *m1;
422 sint16 sx, sy; 418 sint16 sx, sy;
423 419
424 if (ob == NULL) 420 if (ob == NULL)
425 { 421 {
426 flag = get_map_flags (m, &m1, x, y, &sx, &sy); 422 flag = get_map_flags (m, &m1, x, y, &sx, &sy);
491 * they are saved). We do have to look for the old maps that did save 487 * they are saved). We do have to look for the old maps that did save
492 * the more sections and not re-add sections for them. 488 * the more sections and not re-add sections for them.
493 */ 489 */
494 490
495static void 491static void
496link_multipart_objects (mapstruct *m) 492link_multipart_objects (maptile *m)
497{ 493{
498 int x, y; 494 int x, y;
499 object *tmp, *op, *last, *above; 495 object *tmp, *op, *last, *above;
500 archetype *at; 496 archetype *at;
501 497
538 * Loads (ands parses) the objects into a given map from the specified 534 * Loads (ands parses) the objects into a given map from the specified
539 * file pointer. 535 * file pointer.
540 * mapflags is the same as we get with load_original_map 536 * mapflags is the same as we get with load_original_map
541 */ 537 */
542void 538void
543load_objects (mapstruct *m, object_thawer & fp, int mapflags) 539load_objects (maptile *m, object_thawer & fp, int mapflags)
544{ 540{
545 int i, j; 541 int i, j;
546 int unique; 542 int unique;
547 object *op, *prev = NULL, *last_more = NULL, *otmp; 543 object *op, *prev = NULL, *last_more = NULL, *otmp;
548 544
614 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 610 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
615 * and we only save the head of multi part objects - this is needed 611 * and we only save the head of multi part objects - this is needed
616 * in order to do map tiling properly. 612 * in order to do map tiling properly.
617 */ 613 */
618void 614void
619save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) 615save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag)
620{ 616{
621 int i, j = 0, unique = 0; 617 int i, j = 0, unique = 0;
622 object *op; 618 object *op;
623 619
624 /* first pass - save one-part objects */ 620 /* first pass - save one-part objects */
647 643
648 } /* for this space */ 644 } /* for this space */
649 } /* for this j */ 645 } /* for this j */
650} 646}
651 647
648maptile::maptile ()
649{
650 in_memory = MAP_SWAPPED;
651 /* The maps used to pick up default x and y values from the
652 * map archetype. Mimic that behaviour.
653 */
654 MAP_WIDTH (this) = 16;
655 MAP_HEIGHT (this) = 16;
656 MAP_RESET_TIMEOUT (this) = 0;
657 MAP_TIMEOUT (this) = 300;
658 MAP_ENTER_X (this) = 0;
659 MAP_ENTER_Y (this) = 0;
660 /*set part to -1 indicating conversion to weather map not yet done */
661 MAP_WORLDPARTX (this) = -1;
662 MAP_WORLDPARTY (this) = -1;
663}
664
652/* 665/*
653 * Allocates, initialises, and returns a pointer to a mapstruct. 666 * Allocates, initialises, and returns a pointer to a maptile.
654 * Modified to no longer take a path option which was not being 667 * Modified to no longer take a path option which was not being
655 * used anyways. MSW 2001-07-01 668 * used anyways. MSW 2001-07-01
656 */ 669 */
657 670maptile *
658mapstruct *
659get_linked_map (void) 671get_linked_map (void)
660{ 672{
661 mapstruct *map = new mapstruct; 673 maptile *mp, *map = new maptile;
662 mapstruct *mp;
663 674
664 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 675 for (mp = first_map; mp && mp->next; mp = mp->next);
676
665 if (mp == NULL) 677 if (mp == NULL)
666 first_map = map; 678 first_map = map;
667 else 679 else
668 mp->next = map; 680 mp->next = map;
669 681
670 map->in_memory = MAP_SWAPPED;
671 /* The maps used to pick up default x and y values from the
672 * map archetype. Mimic that behaviour.
673 */
674 MAP_WIDTH (map) = 16;
675 MAP_HEIGHT (map) = 16;
676 MAP_RESET_TIMEOUT (map) = 0;
677 MAP_TIMEOUT (map) = 300;
678 MAP_ENTER_X (map) = 0;
679 MAP_ENTER_Y (map) = 0;
680 /*set part to -1 indicating conversion to weather map not yet done */
681 MAP_WORLDPARTX (map) = -1;
682 MAP_WORLDPARTY (map) = -1;
683 return map; 682 return map;
684} 683}
685 684
686/* 685/*
687 * Allocates the arrays contained in a mapstruct. 686 * Allocates the arrays contained in a maptile.
688 * This basically allocates the dynamic array of spaces for the 687 * This basically allocates the dynamic array of spaces for the
689 * map. 688 * map.
690 */ 689 */
691
692void 690void
693allocate_map (mapstruct *m) 691maptile::allocate ()
694{ 692{
695 m->in_memory = MAP_IN_MEMORY; 693 in_memory = MAP_IN_MEMORY;
694
696 /* Log this condition and free the storage. We could I suppose 695 /* Log this condition and free the storage. We could I suppose
697 * realloc, but if the caller is presuming the data will be intact, 696 * realloc, but if the caller is presuming the data will be intact,
698 * that is their poor assumption. 697 * that is their poor assumption.
699 */ 698 */
700 if (m->spaces) 699 if (spaces)
701 { 700 {
702 LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); 701 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
703 free (m->spaces); 702 free (spaces);
704 } 703 }
705 704
706 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 705 spaces = (MapSpace *)
706 calloc (1, width * height * sizeof (MapSpace));
707 707
708 if (m->spaces == NULL) 708 if (!spaces)
709 fatal (OUT_OF_MEMORY); 709 fatal (OUT_OF_MEMORY);
710} 710}
711 711
712/* Create and returns a map of the specific size. Used 712/* Create and returns a map of the specific size. Used
713 * in random map code and the editor. 713 * in random map code and the editor.
714 */ 714 */
715mapstruct * 715maptile *
716get_empty_map (int sizex, int sizey) 716get_empty_map (int sizex, int sizey)
717{ 717{
718 mapstruct *m = get_linked_map (); 718 maptile *m = get_linked_map ();
719 719
720 m->width = sizex; 720 m->width = sizex;
721 m->height = sizey; 721 m->height = sizey;
722 m->in_memory = MAP_SWAPPED; 722 m->in_memory = MAP_SWAPPED;
723 allocate_map (m); 723 m->allocate ();
724
724 return m; 725 return m;
725} 726}
726 727
727/* Takes a string from a map definition and outputs a pointer to the array of shopitems 728/* Takes a string from a map definition and outputs a pointer to the array of shopitems
728 * corresponding to that string. Memory is allocated for this, it must be freed 729 * corresponding to that string. Memory is allocated for this, it must be freed
805} 806}
806 807
807/* opposite of parse string, this puts the string that was originally fed in to 808/* opposite of parse string, this puts the string that was originally fed in to
808 * the map (or something equivilent) into output_string. */ 809 * the map (or something equivilent) into output_string. */
809static void 810static void
810print_shop_string (mapstruct *m, char *output_string) 811print_shop_string (maptile *m, char *output_string)
811{ 812{
812 int i; 813 int i;
813 char tmp[MAX_BUF]; 814 char tmp[MAX_BUF];
814 815
815 strcpy (output_string, ""); 816 strcpy (output_string, "");
849 * MSW 2001-07-01 850 * MSW 2001-07-01
850 * return 0 on success, 1 on failure. 851 * return 0 on success, 1 on failure.
851 */ 852 */
852 853
853static int 854static int
854load_map_header (object_thawer & fp, mapstruct *m) 855load_map_header (object_thawer & fp, maptile *m)
855{ 856{
856 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 857 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
857 int msgpos = 0; 858 int msgpos = 0;
858 int maplorepos = 0; 859 int maplorepos = 0;
859 860
1147} 1148}
1148 1149
1149/* 1150/*
1150 * Opens the file "filename" and reads information about the map 1151 * Opens the file "filename" and reads information about the map
1151 * from the given file, and stores it in a newly allocated 1152 * from the given file, and stores it in a newly allocated
1152 * mapstruct. A pointer to this structure is returned, or NULL on failure. 1153 * maptile. A pointer to this structure is returned, or NULL on failure.
1153 * flags correspond to those in map.h. Main ones used are 1154 * flags correspond to those in map.h. Main ones used are
1154 * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and 1155 * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and
1155 * MAP_BLOCK, in which case we block on this load. This happens in all 1156 * MAP_BLOCK, in which case we block on this load. This happens in all
1156 * cases, no matter if this flag is set or not. 1157 * cases, no matter if this flag is set or not.
1157 * MAP_STYLE: style map - don't add active objects, don't add to server 1158 * MAP_STYLE: style map - don't add active objects, don't add to server
1158 * managed map list. 1159 * managed map list.
1159 */ 1160 */
1160 1161
1161mapstruct * 1162maptile *
1162load_original_map (const char *filename, int flags) 1163load_original_map (const char *filename, int flags)
1163{ 1164{
1164 mapstruct *m; 1165 maptile *m;
1165 char pathname[MAX_BUF]; 1166 char pathname[MAX_BUF];
1166 1167
1167 if (flags & MAP_PLAYER_UNIQUE) 1168 if (flags & MAP_PLAYER_UNIQUE)
1168 strcpy (pathname, filename); 1169 strcpy (pathname, filename);
1169 else if (flags & MAP_OVERLAY) 1170 else if (flags & MAP_OVERLAY)
1186 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1187 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1187 delete_map (m); 1188 delete_map (m);
1188 return NULL; 1189 return NULL;
1189 } 1190 }
1190 1191
1191 allocate_map (m); 1192 m->allocate ();
1192 1193
1193 m->in_memory = MAP_LOADING; 1194 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1195 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1196
1196 m->in_memory = MAP_IN_MEMORY; 1197 m->in_memory = MAP_IN_MEMORY;
1205 * Loads a map, which has been loaded earlier, from file. 1206 * Loads a map, which has been loaded earlier, from file.
1206 * Return the map object we load into (this can change from the passed 1207 * Return the map object we load into (this can change from the passed
1207 * option if we can't find the original map) 1208 * option if we can't find the original map)
1208 */ 1209 */
1209 1210
1210static mapstruct * 1211static maptile *
1211load_temporary_map (mapstruct *m) 1212load_temporary_map (maptile *m)
1212{ 1213{
1213 char buf[MAX_BUF]; 1214 char buf[MAX_BUF];
1214 1215
1215 if (!m->tmpname) 1216 if (!m->tmpname)
1216 { 1217 {
1242 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1243 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1243 delete_map (m); 1244 delete_map (m);
1244 m = load_original_map (m->path, 0); 1245 m = load_original_map (m->path, 0);
1245 return NULL; 1246 return NULL;
1246 } 1247 }
1248
1247 allocate_map (m); 1249 m->allocate ();
1248 1250
1249 m->in_memory = MAP_LOADING; 1251 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1252 load_objects (m, thawer, 0);
1251 1253
1252 m->in_memory = MAP_IN_MEMORY; 1254 m->in_memory = MAP_IN_MEMORY;
1258 * Loads a map, which has been loaded earlier, from file. 1260 * Loads a map, which has been loaded earlier, from file.
1259 * Return the map object we load into (this can change from the passed 1261 * Return the map object we load into (this can change from the passed
1260 * option if we can't find the original map) 1262 * option if we can't find the original map)
1261 */ 1263 */
1262 1264
1263mapstruct * 1265maptile *
1264load_overlay_map (const char *filename, mapstruct *m) 1266load_overlay_map (const char *filename, maptile *m)
1265{ 1267{
1266 char pathname[MAX_BUF]; 1268 char pathname[MAX_BUF];
1267 1269
1268 strcpy (pathname, create_overlay_pathname (filename)); 1270 strcpy (pathname, create_overlay_pathname (filename));
1269 1271
1277 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1279 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1278 delete_map (m); 1280 delete_map (m);
1279 m = load_original_map (m->path, 0); 1281 m = load_original_map (m->path, 0);
1280 return NULL; 1282 return NULL;
1281 } 1283 }
1282 /*allocate_map(m); */ 1284 /*m->allocate ();*/
1283 1285
1284 m->in_memory = MAP_LOADING; 1286 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1287 load_objects (m, thawer, MAP_OVERLAY);
1286 1288
1287 m->in_memory = MAP_IN_MEMORY; 1289 m->in_memory = MAP_IN_MEMORY;
1292 * This is the start of unique map handling code 1294 * This is the start of unique map handling code
1293 *****************************************************************************/ 1295 *****************************************************************************/
1294 1296
1295/* This goes through map 'm' and removed any unique items on the map. */ 1297/* This goes through map 'm' and removed any unique items on the map. */
1296static void 1298static void
1297delete_unique_items (mapstruct *m) 1299delete_unique_items (maptile *m)
1298{ 1300{
1299 int i, j, unique; 1301 int i, j, unique;
1300 object *op, *next; 1302 object *op, *next;
1301 1303
1302 for (i = 0; i < MAP_WIDTH (m); i++) 1304 for (i = 0; i < MAP_WIDTH (m); i++)
1324/* 1326/*
1325 * Loads unique objects from file(s) into the map which is in memory 1327 * Loads unique objects from file(s) into the map which is in memory
1326 * m is the map to load unique items into. 1328 * m is the map to load unique items into.
1327 */ 1329 */
1328static void 1330static void
1329load_unique_objects (mapstruct *m) 1331load_unique_objects (maptile *m)
1330{ 1332{
1331 int count; 1333 int count;
1332 char firstname[MAX_BUF]; 1334 char firstname[MAX_BUF];
1333 1335
1334 for (count = 0; count < 10; count++) 1336 for (count = 0; count < 10; count++)
1357 1359
1358/* 1360/*
1359 * Saves a map to file. If flag is set, it is saved into the same 1361 * Saves a map to file. If flag is set, it is saved into the same
1360 * file it was (originally) loaded from. Otherwise a temporary 1362 * file it was (originally) loaded from. Otherwise a temporary
1361 * filename will be genarated, and the file will be stored there. 1363 * filename will be genarated, and the file will be stored there.
1362 * The temporary filename will be stored in the mapstructure. 1364 * The temporary filename will be stored in the maptileure.
1363 * If the map is unique, we also save to the filename in the map 1365 * If the map is unique, we also save to the filename in the map
1364 * (this should have been updated when first loaded) 1366 * (this should have been updated when first loaded)
1365 */ 1367 */
1366 1368
1367int 1369int
1368new_save_map (mapstruct *m, int flag) 1370new_save_map (maptile *m, int flag)
1369{ 1371{
1370 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1372 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1371 int i; 1373 int i;
1372 1374
1373 if (flag && !*m->path) 1375 if (flag && !*m->path)
1537/* 1539/*
1538 * Remove and free all objects in the given map. 1540 * Remove and free all objects in the given map.
1539 */ 1541 */
1540 1542
1541void 1543void
1542free_all_objects (mapstruct *m) 1544free_all_objects (maptile *m)
1543{ 1545{
1544 int i, j; 1546 int i, j;
1545 object *op; 1547 object *op;
1546 1548
1547 for (i = 0; i < MAP_WIDTH (m); i++) 1549 for (i = 0; i < MAP_WIDTH (m); i++)
1570 } 1572 }
1571 } 1573 }
1572} 1574}
1573 1575
1574/* 1576/*
1575 * Frees everything allocated by the given mapstructure. 1577 * Frees everything allocated by the given maptileure.
1576 * don't free tmpname - our caller is left to do that 1578 * don't free tmpname - our caller is left to do that
1577 */ 1579 */
1578 1580
1579void 1581void
1580free_map (mapstruct *m, int flag) 1582free_map (maptile *m, int flag)
1581{ 1583{
1582 int i; 1584 int i;
1583 1585
1584 if (!m->in_memory) 1586 if (!m->in_memory)
1585 { 1587 {
1612 } 1614 }
1613 m->in_memory = MAP_SWAPPED; 1615 m->in_memory = MAP_SWAPPED;
1614} 1616}
1615 1617
1616/* 1618/*
1617 * function: vanish mapstruct 1619 * function: vanish maptile
1618 * m : pointer to mapstruct, if NULL no action 1620 * m : pointer to maptile, if NULL no action
1619 * this deletes all the data on the map (freeing pointers) 1621 * this deletes all the data on the map (freeing pointers)
1620 * and then removes this map from the global linked list of maps. 1622 * and then removes this map from the global linked list of maps.
1621 */ 1623 */
1622 1624
1623void 1625void
1624delete_map (mapstruct *m) 1626delete_map (maptile *m)
1625{ 1627{
1626 mapstruct *tmp, *last; 1628 maptile *tmp, *last;
1627 int i; 1629 int i;
1628 1630
1629 if (!m) 1631 if (!m)
1630 return; 1632 return;
1631 1633
1693 * dont do any more name translation on it. 1695 * dont do any more name translation on it.
1694 * 1696 *
1695 * Returns a pointer to the given map. 1697 * Returns a pointer to the given map.
1696 */ 1698 */
1697 1699
1698mapstruct * 1700maptile *
1699ready_map_name (const char *name, int flags) 1701ready_map_name (const char *name, int flags)
1700{ 1702{
1701 mapstruct *m; 1703 maptile *m;
1702 1704
1703 if (!name) 1705 if (!name)
1704 return (NULL); 1706 return (NULL);
1705 1707
1706 /* Have we been at this level before? */ 1708 /* Have we been at this level before? */
1808 * have a difficulty set than using this function - human calculation 1810 * have a difficulty set than using this function - human calculation
1809 * is much better than this functions guesswork. 1811 * is much better than this functions guesswork.
1810 */ 1812 */
1811 1813
1812int 1814int
1813calculate_difficulty (mapstruct *m) 1815calculate_difficulty (maptile *m)
1814{ 1816{
1815 object *op; 1817 object *op;
1816 archetype *at; 1818 archetype *at;
1817 int x, y, i; 1819 int x, y, i;
1818 long monster_cnt = 0; 1820 long monster_cnt = 0;
1860 1862
1861 return 1; 1863 return 1;
1862} 1864}
1863 1865
1864void 1866void
1865clean_tmp_map (mapstruct *m) 1867clean_tmp_map (maptile *m)
1866{ 1868{
1867 if (m->tmpname == NULL) 1869 if (m->tmpname == NULL)
1868 return; 1870 return;
1869 INVOKE_MAP (CLEAN, m); 1871 INVOKE_MAP (CLEAN, m);
1870 (void) unlink (m->tmpname); 1872 (void) unlink (m->tmpname);
1895 * to maps than los. 1897 * to maps than los.
1896 * postive values make it darker, negative make it brighter 1898 * postive values make it darker, negative make it brighter
1897 */ 1899 */
1898 1900
1899int 1901int
1900change_map_light (mapstruct *m, int change) 1902change_map_light (maptile *m, int change)
1901{ 1903{
1902 int new_level = m->darkness + change; 1904 int new_level = m->darkness + change;
1903 1905
1904 /* Nothing to do */ 1906 /* Nothing to do */
1905 if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) 1907 if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS))
1936 * on the map (what it looks like, whether it blocks magic, 1938 * on the map (what it looks like, whether it blocks magic,
1937 * has a living creatures, prevents people from passing 1939 * has a living creatures, prevents people from passing
1938 * through, etc) 1940 * through, etc)
1939 */ 1941 */
1940void 1942void
1941update_position (mapstruct *m, int x, int y) 1943update_position (maptile *m, int x, int y)
1942{ 1944{
1943 object *tmp, *last = NULL; 1945 object *tmp, *last = NULL;
1944 uint8 flags = 0, oldflags, light = 0, anywhere = 0; 1946 uint8 flags = 0, oldflags, light = 0, anywhere = 0;
1945 New_Face *top, *floor, *middle; 1947 New_Face *top, *floor, *middle;
1946 object *top_obj, *floor_obj, *middle_obj; 1948 object *top_obj, *floor_obj, *middle_obj;
2139 SET_MAP_LIGHT (m, x, y, light); 2141 SET_MAP_LIGHT (m, x, y, light);
2140} 2142}
2141 2143
2142 2144
2143void 2145void
2144set_map_reset_time (mapstruct *map) 2146set_map_reset_time (maptile *map)
2145{ 2147{
2146 int timeout; 2148 int timeout;
2147 2149
2148 timeout = MAP_RESET_TIMEOUT (map); 2150 timeout = MAP_RESET_TIMEOUT (map);
2149 if (timeout <= 0) 2151 if (timeout <= 0)
2158 * maps tile_map values if it tiles back to this one. It returns 2160 * maps tile_map values if it tiles back to this one. It returns
2159 * the value of orig_map->tile_map[tile_num]. It really only does this 2161 * the value of orig_map->tile_map[tile_num]. It really only does this
2160 * so that it is easier for calling functions to verify success. 2162 * so that it is easier for calling functions to verify success.
2161 */ 2163 */
2162 2164
2163static mapstruct * 2165static maptile *
2164load_and_link_tiled_map (mapstruct *orig_map, int tile_num) 2166load_and_link_tiled_map (maptile *orig_map, int tile_num)
2165{ 2167{
2166 int dest_tile = (tile_num + 2) % 4; 2168 int dest_tile = (tile_num + 2) % 4;
2167 char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); 2169 char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]);
2168 2170
2169 orig_map->tile_map[tile_num] = ready_map_name (path, 0); 2171 orig_map->tile_map[tile_num] = ready_map_name (path, 0);
2184 * tiled maps. 2186 * tiled maps.
2185 * 2187 *
2186 * 2188 *
2187 */ 2189 */
2188int 2190int
2189out_of_map (mapstruct *m, int x, int y) 2191out_of_map (maptile *m, int x, int y)
2190{ 2192{
2191 2193
2192 /* If we get passed a null map, this is obviously the 2194 /* If we get passed a null map, this is obviously the
2193 * case. This generally shouldn't happen, but if the 2195 * case. This generally shouldn't happen, but if the
2194 * map loads fail below, it could happen. 2196 * map loads fail below, it could happen.
2249 * the map as that the coordinates are really on, and 2251 * the map as that the coordinates are really on, and
2250 * updates x and y to be the localized coordinates. 2252 * updates x and y to be the localized coordinates.
2251 * Using this is more efficient of calling out_of_map 2253 * Using this is more efficient of calling out_of_map
2252 * and then figuring out what the real map is 2254 * and then figuring out what the real map is
2253 */ 2255 */
2254mapstruct * 2256maptile *
2255get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) 2257get_map_from_coord (maptile *m, sint16 * x, sint16 * y)
2256{ 2258{
2257 2259
2258 if (*x < 0) 2260 if (*x < 0)
2259 { 2261 {
2260 if (!m->tile_path[3]) 2262 if (!m->tile_path[3])
2306/** 2308/**
2307 * Return whether map2 is adjacent to map1. If so, store the distance from 2309 * Return whether map2 is adjacent to map1. If so, store the distance from
2308 * map1 to map2 in dx/dy. 2310 * map1 to map2 in dx/dy.
2309 */ 2311 */
2310static int 2312static int
2311adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) 2313adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy)
2312{ 2314{
2313 if (!map1 || !map2) 2315 if (!map1 || !map2)
2314 return 0; 2316 return 0;
2315 2317
2316 if (map1 == map2) 2318 if (map1 == map2)
2474 * for something in the future. Also, since no object is pasted, the best 2476 * for something in the future. Also, since no object is pasted, the best
2475 * field of the rv_vector is set to NULL. 2477 * field of the rv_vector is set to NULL.
2476 */ 2478 */
2477 2479
2478void 2480void
2479get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) 2481get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags)
2480{ 2482{
2481 if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) 2483 if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y))
2482 { 2484 {
2483 /* be conservative and fill in _some_ data */ 2485 /* be conservative and fill in _some_ data */
2484 retval->distance = 100000; 2486 retval->distance = 100000;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines