… | |
… | |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #include <unistd.h> |
29 | #include <unistd.h> |
30 | |
30 | |
31 | #include "path.h" |
31 | #include "path.h" |
32 | |
|
|
33 | |
32 | |
34 | /* |
33 | /* |
35 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
36 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
37 | */ |
36 | */ |
… | |
… | |
324 | /* We basically go through the stack of objects, and if there is |
323 | /* We basically go through the stack of objects, and if there is |
325 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
324 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
326 | * true. If we get through the entire stack, that must mean |
325 | * true. If we get through the entire stack, that must mean |
327 | * ob is blocking it, so return 0. |
326 | * ob is blocking it, so return 0. |
328 | */ |
327 | */ |
329 | for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) |
328 | for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) |
330 | { |
329 | { |
331 | |
330 | |
332 | /* This must be before the checks below. Code for inventory checkers. */ |
331 | /* This must be before the checks below. Code for inventory checkers. */ |
333 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
332 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
334 | { |
333 | { |
… | |
… | |
398 | * |
397 | * |
399 | * Note this used to be arch_blocked, but with new movement |
398 | * Note this used to be arch_blocked, but with new movement |
400 | * code, we need to have actual object to check its move_type |
399 | * code, we need to have actual object to check its move_type |
401 | * against the move_block values. |
400 | * against the move_block values. |
402 | */ |
401 | */ |
403 | |
|
|
404 | int |
402 | int |
405 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
403 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
406 | { |
404 | { |
407 | archetype *tmp; |
405 | archetype *tmp; |
408 | int flag; |
406 | int flag; |
… | |
… | |
438 | |
436 | |
439 | /* Note it is intentional that we check ob - the movement type of the |
437 | /* Note it is intentional that we check ob - the movement type of the |
440 | * head of the object should correspond for the entire object. |
438 | * head of the object should correspond for the entire object. |
441 | */ |
439 | */ |
442 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
440 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
443 | return AB_NO_PASS; |
441 | return P_NO_PASS; |
444 | |
|
|
445 | } |
442 | } |
|
|
443 | |
446 | return 0; |
444 | return 0; |
447 | } |
445 | } |
448 | |
446 | |
449 | /* When the map is loaded, load_object does not actually insert objects |
447 | /* When the map is loaded, load_object does not actually insert objects |
450 | * into inventory, but just links them. What this does is go through |
448 | * into inventory, but just links them. What this does is go through |
… | |
… | |
487 | object *tmp, *op, *last, *above; |
485 | object *tmp, *op, *last, *above; |
488 | archetype *at; |
486 | archetype *at; |
489 | |
487 | |
490 | for (x = 0; x < MAP_WIDTH (m); x++) |
488 | for (x = 0; x < MAP_WIDTH (m); x++) |
491 | for (y = 0; y < MAP_HEIGHT (m); y++) |
489 | for (y = 0; y < MAP_HEIGHT (m); y++) |
492 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) |
490 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
493 | { |
491 | { |
494 | above = tmp->above; |
492 | above = tmp->above; |
495 | |
493 | |
496 | /* already multipart - don't do anything more */ |
494 | /* already multipart - don't do anything more */ |
497 | if (tmp->head || tmp->more) |
495 | if (tmp->head || tmp->more) |
… | |
… | |
582 | { |
580 | { |
583 | for (j = 0; j < m->height; j++) |
581 | for (j = 0; j < m->height; j++) |
584 | { |
582 | { |
585 | unique = 0; |
583 | unique = 0; |
586 | /* check for unique items, or unique squares */ |
584 | /* check for unique items, or unique squares */ |
587 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
585 | for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above) |
588 | { |
586 | { |
589 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
587 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
590 | unique = 1; |
588 | unique = 1; |
591 | |
589 | |
592 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
590 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
… | |
… | |
613 | /* first pass - save one-part objects */ |
611 | /* first pass - save one-part objects */ |
614 | for (i = 0; i < MAP_WIDTH (m); i++) |
612 | for (i = 0; i < MAP_WIDTH (m); i++) |
615 | for (j = 0; j < MAP_HEIGHT (m); j++) |
613 | for (j = 0; j < MAP_HEIGHT (m); j++) |
616 | { |
614 | { |
617 | unique = 0; |
615 | unique = 0; |
618 | for (op = get_map_ob (m, i, j); op; op = op->above) |
616 | for (op = GET_MAP_OB (m, i, j); op; op = op->above) |
619 | { |
617 | { |
620 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
618 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
621 | unique = 1; |
619 | unique = 1; |
622 | |
620 | |
623 | if (op->type == PLAYER) |
621 | if (op->type == PLAYER) |
624 | { |
|
|
625 | LOG (llevDebug, "Player on map that is being saved\n"); |
|
|
626 | continue; |
622 | continue; |
627 | } |
|
|
628 | |
623 | |
629 | if (op->head || op->owner) |
624 | if (op->head || op->owner) |
630 | continue; |
625 | continue; |
631 | |
626 | |
632 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
627 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
633 | save_object (fp2, op, 3); |
628 | save_object (fp2, op, 3); |
634 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
629 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
635 | save_object (fp, op, 3); |
630 | save_object (fp, op, 3); |
636 | |
631 | } |
637 | } /* for this space */ |
632 | } |
638 | } /* for this j */ |
|
|
639 | } |
633 | } |
640 | |
634 | |
641 | maptile::maptile () |
635 | maptile::maptile () |
642 | { |
636 | { |
643 | in_memory = MAP_SWAPPED; |
637 | in_memory = MAP_SWAPPED; |
… | |
… | |
693 | { |
687 | { |
694 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
688 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
695 | free (spaces); |
689 | free (spaces); |
696 | } |
690 | } |
697 | |
691 | |
698 | spaces = (MapSpace *) |
692 | spaces = (mapspace *) |
699 | calloc (1, width * height * sizeof (MapSpace)); |
693 | calloc (1, width * height * sizeof (mapspace)); |
700 | |
694 | |
701 | if (!spaces) |
695 | if (!spaces) |
702 | fatal (OUT_OF_MEMORY); |
696 | fatal (OUT_OF_MEMORY); |
703 | } |
697 | } |
704 | |
698 | |
… | |
… | |
1250 | for (i = 0; i < MAP_WIDTH (m); i++) |
1244 | for (i = 0; i < MAP_WIDTH (m); i++) |
1251 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1245 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1252 | { |
1246 | { |
1253 | unique = 0; |
1247 | unique = 0; |
1254 | |
1248 | |
1255 | for (op = get_map_ob (m, i, j); op; op = next) |
1249 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1256 | { |
1250 | { |
1257 | next = op->above; |
1251 | next = op->above; |
1258 | |
1252 | |
1259 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1253 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1260 | unique = 1; |
1254 | unique = 1; |
… | |
… | |
1639 | last->next = m->next; |
1633 | last->next = m->next; |
1640 | |
1634 | |
1641 | delete m; |
1635 | delete m; |
1642 | } |
1636 | } |
1643 | |
1637 | |
1644 | |
|
|
1645 | |
|
|
1646 | /* |
1638 | /* |
1647 | * Makes sure the given map is loaded and swapped in. |
1639 | * Makes sure the given map is loaded and swapped in. |
1648 | * name is path name of the map. |
1640 | * name is path name of the map. |
1649 | * flags meaning: |
1641 | * flags meaning: |
1650 | * 0x1 (MAP_FLUSH): flush the map - always load from the map directory, |
1642 | * 0x1 (MAP_FLUSH): flush the map - always load from the map directory, |
… | |
… | |
1652 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1644 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1653 | * dont do any more name translation on it. |
1645 | * dont do any more name translation on it. |
1654 | * |
1646 | * |
1655 | * Returns a pointer to the given map. |
1647 | * Returns a pointer to the given map. |
1656 | */ |
1648 | */ |
1657 | |
|
|
1658 | maptile * |
1649 | maptile * |
1659 | ready_map_name (const char *name, int flags) |
1650 | ready_map_name (const char *name, int flags) |
1660 | { |
1651 | { |
1661 | maptile *m; |
1652 | maptile *m; |
1662 | |
1653 | |
… | |
… | |
1785 | return MAP_DIFFICULTY (m); |
1776 | return MAP_DIFFICULTY (m); |
1786 | } |
1777 | } |
1787 | |
1778 | |
1788 | for (x = 0; x < MAP_WIDTH (m); x++) |
1779 | for (x = 0; x < MAP_WIDTH (m); x++) |
1789 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1780 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1790 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
1781 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1791 | { |
1782 | { |
1792 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1783 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1793 | { |
1784 | { |
1794 | total_exp += op->stats.exp; |
1785 | total_exp += op->stats.exp; |
1795 | monster_cnt++; |
1786 | monster_cnt++; |
… | |
… | |
1888 | /* All clients need to get re-updated for the change */ |
1879 | /* All clients need to get re-updated for the change */ |
1889 | update_all_map_los (m); |
1880 | update_all_map_los (m); |
1890 | return 1; |
1881 | return 1; |
1891 | } |
1882 | } |
1892 | |
1883 | |
1893 | |
|
|
1894 | /* |
1884 | /* |
1895 | * This function updates various attributes about a specific space |
1885 | * This function updates various attributes about a specific space |
1896 | * on the map (what it looks like, whether it blocks magic, |
1886 | * on the map (what it looks like, whether it blocks magic, |
1897 | * has a living creatures, prevents people from passing |
1887 | * has a living creatures, prevents people from passing |
1898 | * through, etc) |
1888 | * through, etc) |
1899 | */ |
1889 | */ |
1900 | void |
1890 | void |
1901 | update_position (maptile *m, int x, int y) |
1891 | update_position (maptile *m, int x, int y) |
1902 | { |
1892 | { |
1903 | object *tmp, *last = NULL; |
1893 | object *tmp, *last = 0; |
1904 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1894 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1905 | New_Face *top, *floor, *middle; |
1895 | New_Face *top, *floor, *middle; |
1906 | object *top_obj, *floor_obj, *middle_obj; |
1896 | object *top_obj, *floor_obj, *middle_obj; |
1907 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1897 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1908 | |
1898 | |
… | |
… | |
1912 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
1902 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
1913 | return; |
1903 | return; |
1914 | } |
1904 | } |
1915 | |
1905 | |
1916 | middle = blank_face; |
1906 | middle = blank_face; |
1917 | top = blank_face; |
1907 | top = blank_face; |
1918 | floor = blank_face; |
1908 | floor = blank_face; |
1919 | |
1909 | |
1920 | middle_obj = NULL; |
1910 | middle_obj = 0; |
1921 | top_obj = NULL; |
1911 | top_obj = 0; |
1922 | floor_obj = NULL; |
1912 | floor_obj = 0; |
1923 | |
1913 | |
1924 | for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1914 | for (tmp = GET_MAP_OB (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1925 | { |
1915 | { |
1926 | |
|
|
1927 | /* This could be made additive I guess (two lights better than |
1916 | /* This could be made additive I guess (two lights better than |
1928 | * one). But if so, it shouldn't be a simple additive - 2 |
1917 | * one). But if so, it shouldn't be a simple additive - 2 |
1929 | * light bulbs do not illuminate twice as far as once since |
1918 | * light bulbs do not illuminate twice as far as once since |
1930 | * it is a disapation factor that is squared (or is it cubed?) |
1919 | * it is a dissapation factor that is cubed. |
1931 | */ |
1920 | */ |
1932 | if (tmp->glow_radius > light) |
1921 | if (tmp->glow_radius > light) |
1933 | light = tmp->glow_radius; |
1922 | light = tmp->glow_radius; |
1934 | |
1923 | |
1935 | /* This call is needed in order to update objects the player |
1924 | /* This call is needed in order to update objects the player |
… | |
… | |
1973 | { |
1962 | { |
1974 | middle = tmp->face; |
1963 | middle = tmp->face; |
1975 | middle_obj = tmp; |
1964 | middle_obj = tmp; |
1976 | } |
1965 | } |
1977 | } |
1966 | } |
|
|
1967 | |
1978 | if (tmp == tmp->above) |
1968 | if (tmp == tmp->above) |
1979 | { |
1969 | { |
1980 | LOG (llevError, "Error in structure of map\n"); |
1970 | LOG (llevError, "Error in structure of map\n"); |
1981 | exit (-1); |
1971 | exit (-1); |
1982 | } |
1972 | } |
1983 | |
1973 | |
1984 | move_slow |= tmp->move_slow; |
1974 | move_slow |= tmp->move_slow; |
1985 | move_block |= tmp->move_block; |
1975 | move_block |= tmp->move_block; |
1986 | move_on |= tmp->move_on; |
1976 | move_on |= tmp->move_on; |
1987 | move_off |= tmp->move_off; |
1977 | move_off |= tmp->move_off; |
1988 | move_allow |= tmp->move_allow; |
1978 | move_allow |= tmp->move_allow; |
1989 | |
1979 | |
1990 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
1991 | flags |= P_IS_ALIVE; |
|
|
1992 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) |
|
|
1993 | flags |= P_NO_MAGIC; |
|
|
1994 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) |
|
|
1995 | flags |= P_NO_CLERIC; |
|
|
1996 | if (tmp->type == SAFE_GROUND) |
|
|
1997 | flags |= P_SAFE; |
|
|
1998 | |
|
|
1999 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) |
1980 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
2000 | flags |= P_BLOCKSVIEW; |
1981 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
2001 | } /* for stack of objects */ |
1982 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
|
|
1983 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
|
|
1984 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
|
|
1985 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
|
|
1986 | } |
2002 | |
1987 | |
2003 | /* we don't want to rely on this function to have accurate flags, but |
1988 | /* we don't want to rely on this function to have accurate flags, but |
2004 | * since we're already doing the work, we calculate them here. |
1989 | * since we're already doing the work, we calculate them here. |
2005 | * if they don't match, logic is broken someplace. |
1990 | * if they don't match, logic is broken someplace. |
2006 | */ |
1991 | */ |
2007 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
1992 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
2008 | { |
|
|
2009 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
1993 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
2010 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
1994 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
2011 | } |
1995 | |
2012 | SET_MAP_FLAGS (m, x, y, flags); |
1996 | mapspace &s = m->at (x, y); |
2013 | SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); |
1997 | |
2014 | SET_MAP_MOVE_ON (m, x, y, move_on); |
1998 | s.flags = flags; |
2015 | SET_MAP_MOVE_OFF (m, x, y, move_off); |
1999 | s.move_block = move_block & ~move_allow; |
2016 | SET_MAP_MOVE_SLOW (m, x, y, move_slow); |
2000 | s.move_on = move_on; |
|
|
2001 | s.move_off = move_off; |
|
|
2002 | s.move_slow = move_slow; |
2017 | |
2003 | |
2018 | /* At this point, we have a floor face (if there is a floor), |
2004 | /* At this point, we have a floor face (if there is a floor), |
2019 | * and the floor is set - we are not going to touch it at |
2005 | * and the floor is set - we are not going to touch it at |
2020 | * this point. |
2006 | * this point. |
2021 | * middle contains the highest visibility face. |
2007 | * middle contains the highest visibility face. |
… | |
… | |
2075 | break; |
2061 | break; |
2076 | } |
2062 | } |
2077 | } |
2063 | } |
2078 | } |
2064 | } |
2079 | } |
2065 | } |
|
|
2066 | |
2080 | if (middle == floor) |
2067 | if (middle == floor) |
2081 | middle = blank_face; |
2068 | middle = blank_face; |
|
|
2069 | |
2082 | if (top == middle) |
2070 | if (top == middle) |
2083 | middle = blank_face; |
2071 | middle = blank_face; |
|
|
2072 | |
2084 | SET_MAP_FACE (m, x, y, top, 0); |
2073 | SET_MAP_FACE (m, x, y, top, 0); |
2085 | if (top != blank_face) |
2074 | if (top != blank_face) |
2086 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
2075 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
2087 | else |
2076 | else |
2088 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
2077 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
|
|
2078 | |
2089 | SET_MAP_FACE (m, x, y, middle, 1); |
2079 | SET_MAP_FACE (m, x, y, middle, 1); |
2090 | if (middle != blank_face) |
2080 | if (middle != blank_face) |
2091 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
2081 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
2092 | else |
2082 | else |
2093 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
2083 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
|
|
2084 | |
2094 | SET_MAP_FACE (m, x, y, floor, 2); |
2085 | SET_MAP_FACE (m, x, y, floor, 2); |
2095 | if (floor != blank_face) |
2086 | if (floor != blank_face) |
2096 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
2087 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
2097 | else |
2088 | else |
2098 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
2089 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
|
|
2090 | |
2099 | SET_MAP_LIGHT (m, x, y, light); |
2091 | SET_MAP_LIGHT (m, x, y, light); |
2100 | } |
2092 | } |
2101 | |
2093 | |
2102 | |
2094 | |
2103 | void |
2095 | void |