… | |
… | |
31 | #endif /* win32 */ |
31 | #endif /* win32 */ |
32 | |
32 | |
33 | #include "path.h" |
33 | #include "path.h" |
34 | |
34 | |
35 | |
35 | |
36 | extern 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 | |
43 | mapstruct * |
41 | maptile * |
44 | has_been_loaded (const char *name) |
42 | has_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 | |
208 | void |
206 | void |
209 | dump_map (const mapstruct *m) |
207 | dump_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 | |
233 | void |
231 | void |
234 | dump_all_maps (void) |
232 | dump_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 | */ |
254 | int |
252 | int |
255 | get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
253 | get_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 | |
|
|
294 | int |
290 | int |
295 | blocked_link (object *ob, mapstruct *m, int sx, int sy) |
291 | blocked_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 | |
416 | int |
412 | int |
417 | ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) |
413 | ob_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 | |
495 | static void |
491 | static void |
496 | link_multipart_objects (mapstruct *m) |
492 | link_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 | */ |
542 | void |
538 | void |
543 | load_objects (mapstruct *m, object_thawer & fp, int mapflags) |
539 | load_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 | */ |
618 | void |
614 | void |
619 | save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) |
615 | save_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 */ |
… | |
… | |
648 | } /* for this space */ |
644 | } /* for this space */ |
649 | } /* for this j */ |
645 | } /* for this j */ |
650 | } |
646 | } |
651 | |
647 | |
652 | /* |
648 | /* |
653 | * Allocates, initialises, and returns a pointer to a mapstruct. |
649 | * Allocates, initialises, and returns a pointer to a maptile. |
654 | * Modified to no longer take a path option which was not being |
650 | * Modified to no longer take a path option which was not being |
655 | * used anyways. MSW 2001-07-01 |
651 | * used anyways. MSW 2001-07-01 |
656 | */ |
652 | */ |
657 | |
653 | |
658 | mapstruct * |
654 | maptile * |
659 | get_linked_map (void) |
655 | get_linked_map (void) |
660 | { |
656 | { |
661 | mapstruct *map = new mapstruct; |
657 | maptile *map = new maptile; |
662 | mapstruct *mp; |
658 | maptile *mp; |
663 | |
659 | |
664 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
660 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
665 | if (mp == NULL) |
661 | if (mp == NULL) |
666 | first_map = map; |
662 | first_map = map; |
667 | else |
663 | else |
… | |
… | |
682 | MAP_WORLDPARTY (map) = -1; |
678 | MAP_WORLDPARTY (map) = -1; |
683 | return map; |
679 | return map; |
684 | } |
680 | } |
685 | |
681 | |
686 | /* |
682 | /* |
687 | * Allocates the arrays contained in a mapstruct. |
683 | * Allocates the arrays contained in a maptile. |
688 | * This basically allocates the dynamic array of spaces for the |
684 | * This basically allocates the dynamic array of spaces for the |
689 | * map. |
685 | * map. |
690 | */ |
686 | */ |
691 | |
687 | |
692 | void |
688 | void |
693 | allocate_map (mapstruct *m) |
689 | allocate_map (maptile *m) |
694 | { |
690 | { |
695 | m->in_memory = MAP_IN_MEMORY; |
691 | m->in_memory = MAP_IN_MEMORY; |
696 | /* Log this condition and free the storage. We could I suppose |
692 | /* Log this condition and free the storage. We could I suppose |
697 | * realloc, but if the caller is presuming the data will be intact, |
693 | * realloc, but if the caller is presuming the data will be intact, |
698 | * that is their poor assumption. |
694 | * that is their poor assumption. |
… | |
… | |
710 | } |
706 | } |
711 | |
707 | |
712 | /* Create and returns a map of the specific size. Used |
708 | /* Create and returns a map of the specific size. Used |
713 | * in random map code and the editor. |
709 | * in random map code and the editor. |
714 | */ |
710 | */ |
715 | mapstruct * |
711 | maptile * |
716 | get_empty_map (int sizex, int sizey) |
712 | get_empty_map (int sizex, int sizey) |
717 | { |
713 | { |
718 | mapstruct *m = get_linked_map (); |
714 | maptile *m = get_linked_map (); |
719 | |
715 | |
720 | m->width = sizex; |
716 | m->width = sizex; |
721 | m->height = sizey; |
717 | m->height = sizey; |
722 | m->in_memory = MAP_SWAPPED; |
718 | m->in_memory = MAP_SWAPPED; |
723 | allocate_map (m); |
719 | allocate_map (m); |
… | |
… | |
805 | } |
801 | } |
806 | |
802 | |
807 | /* opposite of parse string, this puts the string that was originally fed in to |
803 | /* opposite of parse string, this puts the string that was originally fed in to |
808 | * the map (or something equivilent) into output_string. */ |
804 | * the map (or something equivilent) into output_string. */ |
809 | static void |
805 | static void |
810 | print_shop_string (mapstruct *m, char *output_string) |
806 | print_shop_string (maptile *m, char *output_string) |
811 | { |
807 | { |
812 | int i; |
808 | int i; |
813 | char tmp[MAX_BUF]; |
809 | char tmp[MAX_BUF]; |
814 | |
810 | |
815 | strcpy (output_string, ""); |
811 | strcpy (output_string, ""); |
… | |
… | |
849 | * MSW 2001-07-01 |
845 | * MSW 2001-07-01 |
850 | * return 0 on success, 1 on failure. |
846 | * return 0 on success, 1 on failure. |
851 | */ |
847 | */ |
852 | |
848 | |
853 | static int |
849 | static int |
854 | load_map_header (object_thawer & fp, mapstruct *m) |
850 | load_map_header (object_thawer & fp, maptile *m) |
855 | { |
851 | { |
856 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
852 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
857 | int msgpos = 0; |
853 | int msgpos = 0; |
858 | int maplorepos = 0; |
854 | int maplorepos = 0; |
859 | |
855 | |
… | |
… | |
1147 | } |
1143 | } |
1148 | |
1144 | |
1149 | /* |
1145 | /* |
1150 | * Opens the file "filename" and reads information about the map |
1146 | * Opens the file "filename" and reads information about the map |
1151 | * from the given file, and stores it in a newly allocated |
1147 | * from the given file, and stores it in a newly allocated |
1152 | * mapstruct. A pointer to this structure is returned, or NULL on failure. |
1148 | * maptile. A pointer to this structure is returned, or NULL on failure. |
1153 | * flags correspond to those in map.h. Main ones used are |
1149 | * 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 |
1150 | * 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 |
1151 | * 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. |
1152 | * 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 |
1153 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1158 | * managed map list. |
1154 | * managed map list. |
1159 | */ |
1155 | */ |
1160 | |
1156 | |
1161 | mapstruct * |
1157 | maptile * |
1162 | load_original_map (const char *filename, int flags) |
1158 | load_original_map (const char *filename, int flags) |
1163 | { |
1159 | { |
1164 | mapstruct *m; |
1160 | maptile *m; |
1165 | char pathname[MAX_BUF]; |
1161 | char pathname[MAX_BUF]; |
1166 | |
1162 | |
1167 | if (flags & MAP_PLAYER_UNIQUE) |
1163 | if (flags & MAP_PLAYER_UNIQUE) |
1168 | strcpy (pathname, filename); |
1164 | strcpy (pathname, filename); |
1169 | else if (flags & MAP_OVERLAY) |
1165 | else if (flags & MAP_OVERLAY) |
… | |
… | |
1205 | * Loads a map, which has been loaded earlier, from file. |
1201 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Return the map object we load into (this can change from the passed |
1202 | * Return the map object we load into (this can change from the passed |
1207 | * option if we can't find the original map) |
1203 | * option if we can't find the original map) |
1208 | */ |
1204 | */ |
1209 | |
1205 | |
1210 | static mapstruct * |
1206 | static maptile * |
1211 | load_temporary_map (mapstruct *m) |
1207 | load_temporary_map (maptile *m) |
1212 | { |
1208 | { |
1213 | char buf[MAX_BUF]; |
1209 | char buf[MAX_BUF]; |
1214 | |
1210 | |
1215 | if (!m->tmpname) |
1211 | if (!m->tmpname) |
1216 | { |
1212 | { |
… | |
… | |
1258 | * Loads a map, which has been loaded earlier, from file. |
1254 | * Loads a map, which has been loaded earlier, from file. |
1259 | * Return the map object we load into (this can change from the passed |
1255 | * Return the map object we load into (this can change from the passed |
1260 | * option if we can't find the original map) |
1256 | * option if we can't find the original map) |
1261 | */ |
1257 | */ |
1262 | |
1258 | |
1263 | mapstruct * |
1259 | maptile * |
1264 | load_overlay_map (const char *filename, mapstruct *m) |
1260 | load_overlay_map (const char *filename, maptile *m) |
1265 | { |
1261 | { |
1266 | char pathname[MAX_BUF]; |
1262 | char pathname[MAX_BUF]; |
1267 | |
1263 | |
1268 | strcpy (pathname, create_overlay_pathname (filename)); |
1264 | strcpy (pathname, create_overlay_pathname (filename)); |
1269 | |
1265 | |
… | |
… | |
1292 | * This is the start of unique map handling code |
1288 | * This is the start of unique map handling code |
1293 | *****************************************************************************/ |
1289 | *****************************************************************************/ |
1294 | |
1290 | |
1295 | /* This goes through map 'm' and removed any unique items on the map. */ |
1291 | /* This goes through map 'm' and removed any unique items on the map. */ |
1296 | static void |
1292 | static void |
1297 | delete_unique_items (mapstruct *m) |
1293 | delete_unique_items (maptile *m) |
1298 | { |
1294 | { |
1299 | int i, j, unique; |
1295 | int i, j, unique; |
1300 | object *op, *next; |
1296 | object *op, *next; |
1301 | |
1297 | |
1302 | for (i = 0; i < MAP_WIDTH (m); i++) |
1298 | for (i = 0; i < MAP_WIDTH (m); i++) |
… | |
… | |
1324 | /* |
1320 | /* |
1325 | * Loads unique objects from file(s) into the map which is in memory |
1321 | * Loads unique objects from file(s) into the map which is in memory |
1326 | * m is the map to load unique items into. |
1322 | * m is the map to load unique items into. |
1327 | */ |
1323 | */ |
1328 | static void |
1324 | static void |
1329 | load_unique_objects (mapstruct *m) |
1325 | load_unique_objects (maptile *m) |
1330 | { |
1326 | { |
1331 | int count; |
1327 | int count; |
1332 | char firstname[MAX_BUF]; |
1328 | char firstname[MAX_BUF]; |
1333 | |
1329 | |
1334 | for (count = 0; count < 10; count++) |
1330 | for (count = 0; count < 10; count++) |
… | |
… | |
1357 | |
1353 | |
1358 | /* |
1354 | /* |
1359 | * Saves a map to file. If flag is set, it is saved into the same |
1355 | * 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 |
1356 | * file it was (originally) loaded from. Otherwise a temporary |
1361 | * filename will be genarated, and the file will be stored there. |
1357 | * filename will be genarated, and the file will be stored there. |
1362 | * The temporary filename will be stored in the mapstructure. |
1358 | * The temporary filename will be stored in the maptileure. |
1363 | * If the map is unique, we also save to the filename in the map |
1359 | * If the map is unique, we also save to the filename in the map |
1364 | * (this should have been updated when first loaded) |
1360 | * (this should have been updated when first loaded) |
1365 | */ |
1361 | */ |
1366 | |
1362 | |
1367 | int |
1363 | int |
1368 | new_save_map (mapstruct *m, int flag) |
1364 | new_save_map (maptile *m, int flag) |
1369 | { |
1365 | { |
1370 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1366 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1371 | int i; |
1367 | int i; |
1372 | |
1368 | |
1373 | if (flag && !*m->path) |
1369 | if (flag && !*m->path) |
… | |
… | |
1537 | /* |
1533 | /* |
1538 | * Remove and free all objects in the given map. |
1534 | * Remove and free all objects in the given map. |
1539 | */ |
1535 | */ |
1540 | |
1536 | |
1541 | void |
1537 | void |
1542 | free_all_objects (mapstruct *m) |
1538 | free_all_objects (maptile *m) |
1543 | { |
1539 | { |
1544 | int i, j; |
1540 | int i, j; |
1545 | object *op; |
1541 | object *op; |
1546 | |
1542 | |
1547 | for (i = 0; i < MAP_WIDTH (m); i++) |
1543 | for (i = 0; i < MAP_WIDTH (m); i++) |
… | |
… | |
1570 | } |
1566 | } |
1571 | } |
1567 | } |
1572 | } |
1568 | } |
1573 | |
1569 | |
1574 | /* |
1570 | /* |
1575 | * Frees everything allocated by the given mapstructure. |
1571 | * Frees everything allocated by the given maptileure. |
1576 | * don't free tmpname - our caller is left to do that |
1572 | * don't free tmpname - our caller is left to do that |
1577 | */ |
1573 | */ |
1578 | |
1574 | |
1579 | void |
1575 | void |
1580 | free_map (mapstruct *m, int flag) |
1576 | free_map (maptile *m, int flag) |
1581 | { |
1577 | { |
1582 | int i; |
1578 | int i; |
1583 | |
1579 | |
1584 | if (!m->in_memory) |
1580 | if (!m->in_memory) |
1585 | { |
1581 | { |
… | |
… | |
1612 | } |
1608 | } |
1613 | m->in_memory = MAP_SWAPPED; |
1609 | m->in_memory = MAP_SWAPPED; |
1614 | } |
1610 | } |
1615 | |
1611 | |
1616 | /* |
1612 | /* |
1617 | * function: vanish mapstruct |
1613 | * function: vanish maptile |
1618 | * m : pointer to mapstruct, if NULL no action |
1614 | * m : pointer to maptile, if NULL no action |
1619 | * this deletes all the data on the map (freeing pointers) |
1615 | * this deletes all the data on the map (freeing pointers) |
1620 | * and then removes this map from the global linked list of maps. |
1616 | * and then removes this map from the global linked list of maps. |
1621 | */ |
1617 | */ |
1622 | |
1618 | |
1623 | void |
1619 | void |
1624 | delete_map (mapstruct *m) |
1620 | delete_map (maptile *m) |
1625 | { |
1621 | { |
1626 | mapstruct *tmp, *last; |
1622 | maptile *tmp, *last; |
1627 | int i; |
1623 | int i; |
1628 | |
1624 | |
1629 | if (!m) |
1625 | if (!m) |
1630 | return; |
1626 | return; |
1631 | |
1627 | |
… | |
… | |
1693 | * dont do any more name translation on it. |
1689 | * dont do any more name translation on it. |
1694 | * |
1690 | * |
1695 | * Returns a pointer to the given map. |
1691 | * Returns a pointer to the given map. |
1696 | */ |
1692 | */ |
1697 | |
1693 | |
1698 | mapstruct * |
1694 | maptile * |
1699 | ready_map_name (const char *name, int flags) |
1695 | ready_map_name (const char *name, int flags) |
1700 | { |
1696 | { |
1701 | mapstruct *m; |
1697 | maptile *m; |
1702 | |
1698 | |
1703 | if (!name) |
1699 | if (!name) |
1704 | return (NULL); |
1700 | return (NULL); |
1705 | |
1701 | |
1706 | /* Have we been at this level before? */ |
1702 | /* Have we been at this level before? */ |
… | |
… | |
1808 | * have a difficulty set than using this function - human calculation |
1804 | * have a difficulty set than using this function - human calculation |
1809 | * is much better than this functions guesswork. |
1805 | * is much better than this functions guesswork. |
1810 | */ |
1806 | */ |
1811 | |
1807 | |
1812 | int |
1808 | int |
1813 | calculate_difficulty (mapstruct *m) |
1809 | calculate_difficulty (maptile *m) |
1814 | { |
1810 | { |
1815 | object *op; |
1811 | object *op; |
1816 | archetype *at; |
1812 | archetype *at; |
1817 | int x, y, i; |
1813 | int x, y, i; |
1818 | long monster_cnt = 0; |
1814 | long monster_cnt = 0; |
… | |
… | |
1860 | |
1856 | |
1861 | return 1; |
1857 | return 1; |
1862 | } |
1858 | } |
1863 | |
1859 | |
1864 | void |
1860 | void |
1865 | clean_tmp_map (mapstruct *m) |
1861 | clean_tmp_map (maptile *m) |
1866 | { |
1862 | { |
1867 | if (m->tmpname == NULL) |
1863 | if (m->tmpname == NULL) |
1868 | return; |
1864 | return; |
1869 | INVOKE_MAP (CLEAN, m); |
1865 | INVOKE_MAP (CLEAN, m); |
1870 | (void) unlink (m->tmpname); |
1866 | (void) unlink (m->tmpname); |
… | |
… | |
1895 | * to maps than los. |
1891 | * to maps than los. |
1896 | * postive values make it darker, negative make it brighter |
1892 | * postive values make it darker, negative make it brighter |
1897 | */ |
1893 | */ |
1898 | |
1894 | |
1899 | int |
1895 | int |
1900 | change_map_light (mapstruct *m, int change) |
1896 | change_map_light (maptile *m, int change) |
1901 | { |
1897 | { |
1902 | int new_level = m->darkness + change; |
1898 | int new_level = m->darkness + change; |
1903 | |
1899 | |
1904 | /* Nothing to do */ |
1900 | /* Nothing to do */ |
1905 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
1901 | 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, |
1932 | * on the map (what it looks like, whether it blocks magic, |
1937 | * has a living creatures, prevents people from passing |
1933 | * has a living creatures, prevents people from passing |
1938 | * through, etc) |
1934 | * through, etc) |
1939 | */ |
1935 | */ |
1940 | void |
1936 | void |
1941 | update_position (mapstruct *m, int x, int y) |
1937 | update_position (maptile *m, int x, int y) |
1942 | { |
1938 | { |
1943 | object *tmp, *last = NULL; |
1939 | object *tmp, *last = NULL; |
1944 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1940 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1945 | New_Face *top, *floor, *middle; |
1941 | New_Face *top, *floor, *middle; |
1946 | object *top_obj, *floor_obj, *middle_obj; |
1942 | object *top_obj, *floor_obj, *middle_obj; |
… | |
… | |
2139 | SET_MAP_LIGHT (m, x, y, light); |
2135 | SET_MAP_LIGHT (m, x, y, light); |
2140 | } |
2136 | } |
2141 | |
2137 | |
2142 | |
2138 | |
2143 | void |
2139 | void |
2144 | set_map_reset_time (mapstruct *map) |
2140 | set_map_reset_time (maptile *map) |
2145 | { |
2141 | { |
2146 | int timeout; |
2142 | int timeout; |
2147 | |
2143 | |
2148 | timeout = MAP_RESET_TIMEOUT (map); |
2144 | timeout = MAP_RESET_TIMEOUT (map); |
2149 | if (timeout <= 0) |
2145 | if (timeout <= 0) |
… | |
… | |
2158 | * maps tile_map values if it tiles back to this one. It returns |
2154 | * 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 |
2155 | * 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. |
2156 | * so that it is easier for calling functions to verify success. |
2161 | */ |
2157 | */ |
2162 | |
2158 | |
2163 | static mapstruct * |
2159 | static maptile * |
2164 | load_and_link_tiled_map (mapstruct *orig_map, int tile_num) |
2160 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
2165 | { |
2161 | { |
2166 | int dest_tile = (tile_num + 2) % 4; |
2162 | int dest_tile = (tile_num + 2) % 4; |
2167 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2163 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2168 | |
2164 | |
2169 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
2165 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
… | |
… | |
2184 | * tiled maps. |
2180 | * tiled maps. |
2185 | * |
2181 | * |
2186 | * |
2182 | * |
2187 | */ |
2183 | */ |
2188 | int |
2184 | int |
2189 | out_of_map (mapstruct *m, int x, int y) |
2185 | out_of_map (maptile *m, int x, int y) |
2190 | { |
2186 | { |
2191 | |
2187 | |
2192 | /* If we get passed a null map, this is obviously the |
2188 | /* If we get passed a null map, this is obviously the |
2193 | * case. This generally shouldn't happen, but if the |
2189 | * case. This generally shouldn't happen, but if the |
2194 | * map loads fail below, it could happen. |
2190 | * map loads fail below, it could happen. |
… | |
… | |
2249 | * the map as that the coordinates are really on, and |
2245 | * the map as that the coordinates are really on, and |
2250 | * updates x and y to be the localized coordinates. |
2246 | * updates x and y to be the localized coordinates. |
2251 | * Using this is more efficient of calling out_of_map |
2247 | * Using this is more efficient of calling out_of_map |
2252 | * and then figuring out what the real map is |
2248 | * and then figuring out what the real map is |
2253 | */ |
2249 | */ |
2254 | mapstruct * |
2250 | maptile * |
2255 | get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) |
2251 | get_map_from_coord (maptile *m, sint16 * x, sint16 * y) |
2256 | { |
2252 | { |
2257 | |
2253 | |
2258 | if (*x < 0) |
2254 | if (*x < 0) |
2259 | { |
2255 | { |
2260 | if (!m->tile_path[3]) |
2256 | if (!m->tile_path[3]) |
… | |
… | |
2306 | /** |
2302 | /** |
2307 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2303 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2308 | * map1 to map2 in dx/dy. |
2304 | * map1 to map2 in dx/dy. |
2309 | */ |
2305 | */ |
2310 | static int |
2306 | static int |
2311 | adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) |
2307 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
2312 | { |
2308 | { |
2313 | if (!map1 || !map2) |
2309 | if (!map1 || !map2) |
2314 | return 0; |
2310 | return 0; |
2315 | |
2311 | |
2316 | if (map1 == map2) |
2312 | if (map1 == map2) |
… | |
… | |
2474 | * for something in the future. Also, since no object is pasted, the best |
2470 | * for something in the future. Also, since no object is pasted, the best |
2475 | * field of the rv_vector is set to NULL. |
2471 | * field of the rv_vector is set to NULL. |
2476 | */ |
2472 | */ |
2477 | |
2473 | |
2478 | void |
2474 | void |
2479 | get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2475 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2480 | { |
2476 | { |
2481 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2477 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2482 | { |
2478 | { |
2483 | /* be conservative and fill in _some_ data */ |
2479 | /* be conservative and fill in _some_ data */ |
2484 | retval->distance = 100000; |
2480 | retval->distance = 100000; |