… | |
… | |
222 | void |
222 | void |
223 | dump_all_maps (void) |
223 | dump_all_maps (void) |
224 | { |
224 | { |
225 | maptile *m; |
225 | maptile *m; |
226 | |
226 | |
227 | for (m = first_map; m != NULL; m = m->next) |
227 | for (m = first_map; m; m = m->next) |
228 | { |
|
|
229 | dump_map (m); |
228 | dump_map (m); |
230 | } |
|
|
231 | } |
229 | } |
232 | |
230 | |
233 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
231 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
234 | * one function that just returns a P_.. value (see map.h) |
232 | * one function that just returns a P_.. value (see map.h) |
235 | * it will also do map translation for tiled maps, returning |
233 | * it will also do map translation for tiled maps, returning |
… | |
… | |
239 | * is needed. The case of not passing values is if we're just |
237 | * is needed. The case of not passing values is if we're just |
240 | * checking for the existence of something on those spaces, but |
238 | * checking for the existence of something on those spaces, but |
241 | * don't expect to insert/remove anything from those spaces. |
239 | * don't expect to insert/remove anything from those spaces. |
242 | */ |
240 | */ |
243 | int |
241 | int |
244 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
242 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny) |
245 | { |
243 | { |
246 | sint16 newx, newy; |
244 | sint16 newx, newy; |
247 | int retval = 0; |
245 | int retval = 0; |
248 | maptile *mp; |
246 | maptile *mp; |
249 | |
247 | |
250 | if (out_of_map (oldmap, x, y)) |
|
|
251 | return P_OUT_OF_MAP; |
|
|
252 | newx = x; |
248 | newx = x; |
253 | newy = y; |
249 | newy = y; |
|
|
250 | |
254 | mp = get_map_from_coord (oldmap, &newx, &newy); |
251 | mp = get_map_from_coord (oldmap, &newx, &newy); |
|
|
252 | |
|
|
253 | if (!mp) |
|
|
254 | return P_OUT_OF_MAP; |
|
|
255 | |
255 | if (mp != oldmap) |
256 | if (mp != oldmap) |
256 | retval |= P_NEW_MAP; |
257 | retval |= P_NEW_MAP; |
257 | if (newmap) |
|
|
258 | *newmap = mp; |
|
|
259 | if (nx) |
|
|
260 | *nx = newx; |
|
|
261 | if (ny) |
|
|
262 | *ny = newy; |
|
|
263 | |
258 | |
264 | retval |= mp->spaces[newx + mp->width * newy].flags; |
259 | if (newmap) *newmap = mp; |
|
|
260 | if (nx) *nx = newx; |
|
|
261 | if (ny) *ny = newy; |
265 | |
262 | |
266 | return retval; |
263 | return retval | mp->at (newx, newy).flags (); |
267 | } |
264 | } |
268 | |
265 | |
269 | /* |
266 | /* |
270 | * Returns true if the given coordinate is blocked except by the |
267 | * Returns true if the given coordinate is blocked except by the |
271 | * object passed is not blocking. This is used with |
268 | * object passed is not blocking. This is used with |
… | |
… | |
294 | } |
291 | } |
295 | |
292 | |
296 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
293 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
297 | * directly. |
294 | * directly. |
298 | */ |
295 | */ |
299 | mflags = m->spaces[sx + m->width * sy].flags; |
296 | mflags = m->at (sx, sy).flags (); |
300 | |
297 | |
301 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
298 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
302 | |
299 | |
303 | /* If space is currently not blocked by anything, no need to |
300 | /* If space is currently not blocked by anything, no need to |
304 | * go further. Not true for players - all sorts of special |
301 | * go further. Not true for players - all sorts of special |
… | |
… | |
1886 | * on the map (what it looks like, whether it blocks magic, |
1883 | * on the map (what it looks like, whether it blocks magic, |
1887 | * has a living creatures, prevents people from passing |
1884 | * has a living creatures, prevents people from passing |
1888 | * through, etc) |
1885 | * through, etc) |
1889 | */ |
1886 | */ |
1890 | void |
1887 | void |
1891 | update_position (maptile *m, int x, int y) |
1888 | mapspace::update_ () |
1892 | { |
1889 | { |
1893 | object *tmp, *last = 0; |
1890 | object *tmp, *last = 0; |
1894 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1891 | uint8 flags = 0, light = 0, anywhere = 0; |
1895 | New_Face *top, *floor, *middle; |
1892 | New_Face *top, *floor, *middle; |
1896 | object *top_obj, *floor_obj, *middle_obj; |
1893 | object *top_obj, *floor_obj, *middle_obj; |
1897 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1894 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1898 | |
1895 | |
1899 | oldflags = GET_MAP_FLAGS (m, x, y); |
|
|
1900 | if (!(oldflags & P_NEED_UPDATE)) |
|
|
1901 | { |
|
|
1902 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
|
|
1903 | return; |
|
|
1904 | } |
|
|
1905 | |
|
|
1906 | middle = blank_face; |
1896 | middle = blank_face; |
1907 | top = blank_face; |
1897 | top = blank_face; |
1908 | floor = blank_face; |
1898 | floor = blank_face; |
1909 | |
1899 | |
1910 | middle_obj = 0; |
1900 | middle_obj = 0; |
1911 | top_obj = 0; |
1901 | top_obj = 0; |
1912 | floor_obj = 0; |
1902 | floor_obj = 0; |
1913 | |
1903 | |
1914 | for (tmp = GET_MAP_OB (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1904 | for (tmp = bottom; tmp; last = tmp, tmp = tmp->above) |
1915 | { |
1905 | { |
1916 | /* This could be made additive I guess (two lights better than |
1906 | /* This could be made additive I guess (two lights better than |
1917 | * one). But if so, it shouldn't be a simple additive - 2 |
1907 | * one). But if so, it shouldn't be a simple additive - 2 |
1918 | * light bulbs do not illuminate twice as far as once since |
1908 | * light bulbs do not illuminate twice as far as once since |
1919 | * it is a dissapation factor that is cubed. |
1909 | * it is a dissapation factor that is cubed. |
… | |
… | |
1983 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1973 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1984 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1974 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1985 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1975 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1986 | } |
1976 | } |
1987 | |
1977 | |
1988 | /* we don't want to rely on this function to have accurate flags, but |
1978 | this->light = light; |
1989 | * since we're already doing the work, we calculate them here. |
|
|
1990 | * if they don't match, logic is broken someplace. |
|
|
1991 | */ |
|
|
1992 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
|
|
1993 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
|
|
1994 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
|
|
1995 | |
|
|
1996 | mapspace &s = m->at (x, y); |
|
|
1997 | |
|
|
1998 | s.flags = flags; |
1979 | this->flags_ = flags; |
1999 | s.move_block = move_block & ~move_allow; |
1980 | this->move_block = move_block & ~move_allow; |
2000 | s.move_on = move_on; |
1981 | this->move_on = move_on; |
2001 | s.move_off = move_off; |
1982 | this->move_off = move_off; |
2002 | s.move_slow = move_slow; |
1983 | this->move_slow = move_slow; |
2003 | |
1984 | |
2004 | /* At this point, we have a floor face (if there is a floor), |
1985 | /* At this point, we have a floor face (if there is a floor), |
2005 | * and the floor is set - we are not going to touch it at |
1986 | * and the floor is set - we are not going to touch it at |
2006 | * this point. |
1987 | * this point. |
2007 | * middle contains the highest visibility face. |
1988 | * middle contains the highest visibility face. |
… | |
… | |
2068 | middle = blank_face; |
2049 | middle = blank_face; |
2069 | |
2050 | |
2070 | if (top == middle) |
2051 | if (top == middle) |
2071 | middle = blank_face; |
2052 | middle = blank_face; |
2072 | |
2053 | |
2073 | SET_MAP_FACE (m, x, y, top, 0); |
2054 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
2074 | if (top != blank_face) |
2055 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
2075 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
2056 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
2076 | else |
|
|
2077 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
|
|
2078 | |
|
|
2079 | SET_MAP_FACE (m, x, y, middle, 1); |
|
|
2080 | if (middle != blank_face) |
|
|
2081 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
|
|
2082 | else |
|
|
2083 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
|
|
2084 | |
|
|
2085 | SET_MAP_FACE (m, x, y, floor, 2); |
|
|
2086 | if (floor != blank_face) |
|
|
2087 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
|
|
2088 | else |
|
|
2089 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
|
|
2090 | |
|
|
2091 | SET_MAP_LIGHT (m, x, y, light); |
|
|
2092 | } |
2057 | } |
2093 | |
|
|
2094 | |
2058 | |
2095 | void |
2059 | void |
2096 | set_map_reset_time (maptile *map) |
2060 | set_map_reset_time (maptile *map) |
2097 | { |
2061 | { |
2098 | int timeout; |
2062 | int timeout; |
… | |
… | |
2138 | * |
2102 | * |
2139 | */ |
2103 | */ |
2140 | int |
2104 | int |
2141 | out_of_map (maptile *m, int x, int y) |
2105 | out_of_map (maptile *m, int x, int y) |
2142 | { |
2106 | { |
2143 | |
|
|
2144 | /* If we get passed a null map, this is obviously the |
2107 | /* If we get passed a null map, this is obviously the |
2145 | * case. This generally shouldn't happen, but if the |
2108 | * case. This generally shouldn't happen, but if the |
2146 | * map loads fail below, it could happen. |
2109 | * map loads fail below, it could happen. |
2147 | */ |
2110 | */ |
2148 | if (!m) |
2111 | if (!m) |
… | |
… | |
2150 | |
2113 | |
2151 | if (x < 0) |
2114 | if (x < 0) |
2152 | { |
2115 | { |
2153 | if (!m->tile_path[3]) |
2116 | if (!m->tile_path[3]) |
2154 | return 1; |
2117 | return 1; |
|
|
2118 | |
2155 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2119 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2156 | { |
|
|
2157 | load_and_link_tiled_map (m, 3); |
2120 | load_and_link_tiled_map (m, 3); |
2158 | } |
2121 | |
2159 | return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); |
2122 | return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); |
2160 | } |
2123 | } |
|
|
2124 | |
2161 | if (x >= MAP_WIDTH (m)) |
2125 | if (x >= MAP_WIDTH (m)) |
2162 | { |
2126 | { |
2163 | if (!m->tile_path[1]) |
2127 | if (!m->tile_path[1]) |
2164 | return 1; |
2128 | return 1; |
|
|
2129 | |
2165 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2130 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2166 | { |
|
|
2167 | load_and_link_tiled_map (m, 1); |
2131 | load_and_link_tiled_map (m, 1); |
2168 | } |
2132 | |
2169 | return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); |
2133 | return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); |
2170 | } |
2134 | } |
|
|
2135 | |
2171 | if (y < 0) |
2136 | if (y < 0) |
2172 | { |
2137 | { |
2173 | if (!m->tile_path[0]) |
2138 | if (!m->tile_path[0]) |
2174 | return 1; |
2139 | return 1; |
|
|
2140 | |
2175 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2141 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2176 | { |
|
|
2177 | load_and_link_tiled_map (m, 0); |
2142 | load_and_link_tiled_map (m, 0); |
2178 | } |
2143 | |
2179 | return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); |
2144 | return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); |
2180 | } |
2145 | } |
|
|
2146 | |
2181 | if (y >= MAP_HEIGHT (m)) |
2147 | if (y >= MAP_HEIGHT (m)) |
2182 | { |
2148 | { |
2183 | if (!m->tile_path[2]) |
2149 | if (!m->tile_path[2]) |
2184 | return 1; |
2150 | return 1; |
|
|
2151 | |
2185 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2152 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2186 | { |
|
|
2187 | load_and_link_tiled_map (m, 2); |
2153 | load_and_link_tiled_map (m, 2); |
2188 | } |
2154 | |
2189 | return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); |
2155 | return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); |
2190 | } |
2156 | } |
2191 | |
2157 | |
2192 | /* Simple case - coordinates are within this local |
2158 | /* Simple case - coordinates are within this local |
2193 | * map. |
2159 | * map. |
… | |
… | |
2208 | { |
2174 | { |
2209 | |
2175 | |
2210 | if (*x < 0) |
2176 | if (*x < 0) |
2211 | { |
2177 | { |
2212 | if (!m->tile_path[3]) |
2178 | if (!m->tile_path[3]) |
2213 | return NULL; |
2179 | return 0; |
2214 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2180 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2215 | load_and_link_tiled_map (m, 3); |
2181 | load_and_link_tiled_map (m, 3); |
2216 | |
2182 | |
2217 | *x += MAP_WIDTH (m->tile_map[3]); |
2183 | *x += MAP_WIDTH (m->tile_map[3]); |
2218 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2184 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2219 | } |
2185 | } |
|
|
2186 | |
2220 | if (*x >= MAP_WIDTH (m)) |
2187 | if (*x >= MAP_WIDTH (m)) |
2221 | { |
2188 | { |
2222 | if (!m->tile_path[1]) |
2189 | if (!m->tile_path[1]) |
2223 | return NULL; |
2190 | return 0; |
|
|
2191 | |
2224 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2192 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2225 | load_and_link_tiled_map (m, 1); |
2193 | load_and_link_tiled_map (m, 1); |
2226 | |
2194 | |
2227 | *x -= MAP_WIDTH (m); |
2195 | *x -= MAP_WIDTH (m); |
2228 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2196 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2229 | } |
2197 | } |
|
|
2198 | |
2230 | if (*y < 0) |
2199 | if (*y < 0) |
2231 | { |
2200 | { |
2232 | if (!m->tile_path[0]) |
2201 | if (!m->tile_path[0]) |
2233 | return NULL; |
2202 | return 0; |
|
|
2203 | |
2234 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2204 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2235 | load_and_link_tiled_map (m, 0); |
2205 | load_and_link_tiled_map (m, 0); |
2236 | |
2206 | |
2237 | *y += MAP_HEIGHT (m->tile_map[0]); |
2207 | *y += MAP_HEIGHT (m->tile_map[0]); |
2238 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2208 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2239 | } |
2209 | } |
|
|
2210 | |
2240 | if (*y >= MAP_HEIGHT (m)) |
2211 | if (*y >= MAP_HEIGHT (m)) |
2241 | { |
2212 | { |
2242 | if (!m->tile_path[2]) |
2213 | if (!m->tile_path[2]) |
2243 | return NULL; |
2214 | return 0; |
|
|
2215 | |
2244 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2216 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2245 | load_and_link_tiled_map (m, 2); |
2217 | load_and_link_tiled_map (m, 2); |
2246 | |
2218 | |
2247 | *y -= MAP_HEIGHT (m); |
2219 | *y -= MAP_HEIGHT (m); |
2248 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2220 | return (get_map_from_coord (m->tile_map[2], x, y)); |