… | |
… | |
137 | for (x = 0; x < mx; x++) |
137 | for (x = 0; x < mx; x++) |
138 | { |
138 | { |
139 | for (y = 0; y < my; y++) |
139 | for (y = 0; y < my; y++) |
140 | { |
140 | { |
141 | if (x >= ns->mapx || y >= ns->mapy) |
141 | if (x >= ns->mapx || y >= ns->mapy) |
142 | { |
|
|
143 | /* clear cells outside the viewable area */ |
142 | /* clear cells outside the viewable area */ |
144 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
143 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
145 | } |
|
|
146 | else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) |
144 | else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) |
147 | { |
|
|
148 | /* clear newly visible tiles within the viewable area */ |
145 | /* clear newly visible tiles within the viewable area */ |
149 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
146 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
150 | } |
|
|
151 | else |
147 | else |
152 | { |
|
|
153 | memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); |
148 | memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); |
154 | } |
|
|
155 | } |
149 | } |
156 | } |
150 | } |
157 | |
151 | |
158 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
152 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
159 | |
153 | |
… | |
… | |
1460 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1454 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1461 | { |
1455 | { |
1462 | cell->faces[0] = face0; |
1456 | cell->faces[0] = face0; |
1463 | cell->faces[1] = face1; |
1457 | cell->faces[1] = face1; |
1464 | cell->faces[2] = face2; |
1458 | cell->faces[2] = face2; |
1465 | cell->count = count; |
1459 | cell->count = count; |
1466 | cell->stat_hp = 0; |
1460 | cell->stat_hp = 0; |
|
|
1461 | cell->flags = 0; |
1467 | cell->player = 0; |
1462 | cell->player = 0; |
1468 | } |
1463 | } |
1469 | |
1464 | |
1470 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1465 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1471 | #define MAX_LAYERS 3 |
1466 | #define MAX_LAYERS 3 |
1472 | |
1467 | |
… | |
… | |
1868 | strcpy ((char *) sl.buf, "map1 "); |
1863 | strcpy ((char *) sl.buf, "map1 "); |
1869 | else |
1864 | else |
1870 | strcpy ((char *) sl.buf, "map1a "); |
1865 | strcpy ((char *) sl.buf, "map1a "); |
1871 | sl.len = strlen ((char *) sl.buf); |
1866 | sl.len = strlen ((char *) sl.buf); |
1872 | startlen = sl.len; |
1867 | startlen = sl.len; |
|
|
1868 | |
1873 | /*Extendedmapinfo structure initialisation */ |
1869 | /*Extendedmapinfo structure initialisation */ |
1874 | if (socket.ext_mapinfos) |
1870 | if (socket.ext_mapinfos) |
1875 | { |
1871 | { |
1876 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1872 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1877 | strcpy ((char *) esl.buf, "mapextended "); |
1873 | strcpy ((char *) esl.buf, "mapextended "); |
1878 | esl.len = strlen ((char *) esl.buf); |
1874 | esl.len = strlen ((char *) esl.buf); |
1879 | extendedinfos = EMI_NOREDRAW; |
1875 | extendedinfos = EMI_NOREDRAW; |
|
|
1876 | |
1880 | if (socket.EMI_smooth) |
1877 | if (socket.EMI_smooth) |
1881 | extendedinfos |= EMI_SMOOTH; |
1878 | extendedinfos |= EMI_SMOOTH; |
|
|
1879 | |
1882 | ewhatstart = esl.len; |
1880 | ewhatstart = esl.len; |
1883 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1881 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1884 | could need to be taken away */ |
1882 | could need to be taken away */ |
1885 | SockList_AddChar (&esl, extendedinfos); |
1883 | SockList_AddChar (&esl, extendedinfos); |
1886 | eentrysize = getExtendedMapInfoSize (&socket); |
1884 | eentrysize = getExtendedMapInfoSize (&socket); |
… | |
… | |
1892 | /* suppress compiler warnings */ |
1890 | /* suppress compiler warnings */ |
1893 | ewhatstart = 0; |
1891 | ewhatstart = 0; |
1894 | ewhatflag = 0; |
1892 | ewhatflag = 0; |
1895 | estartlen = 0; |
1893 | estartlen = 0; |
1896 | } |
1894 | } |
|
|
1895 | |
1897 | /* Init data to zero */ |
1896 | /* Init data to zero */ |
1898 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1897 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1899 | |
1898 | |
1900 | /* x,y are the real map locations. ax, ay are viewport relative |
1899 | /* x,y are the real map locations. ax, ay are viewport relative |
1901 | * locations. |
1900 | * locations. |
… | |
… | |
1905 | /* We could do this logic as conditionals in the if statement, |
1904 | /* We could do this logic as conditionals in the if statement, |
1906 | * but that started to get a bit messy to look at. |
1905 | * but that started to get a bit messy to look at. |
1907 | */ |
1906 | */ |
1908 | max_x = pl->x + (socket.mapx + 1) / 2; |
1907 | max_x = pl->x + (socket.mapx + 1) / 2; |
1909 | max_y = pl->y + (socket.mapy + 1) / 2; |
1908 | max_y = pl->y + (socket.mapy + 1) / 2; |
|
|
1909 | |
1910 | if (socket.mapmode == Map1aCmd) |
1910 | if (socket.mapmode == Map1aCmd) |
1911 | { |
1911 | { |
1912 | max_x += MAX_HEAD_OFFSET; |
1912 | max_x += MAX_HEAD_OFFSET; |
1913 | max_y += MAX_HEAD_OFFSET; |
1913 | max_y += MAX_HEAD_OFFSET; |
1914 | } |
1914 | } |
… | |
… | |
1947 | * with no faces tells the client to blank out the |
1947 | * with no faces tells the client to blank out the |
1948 | * space. |
1948 | * space. |
1949 | */ |
1949 | */ |
1950 | got_one = 0; |
1950 | got_one = 0; |
1951 | for (i = oldlen + 2; i < sl.len; i++) |
1951 | for (i = oldlen + 2; i < sl.len; i++) |
1952 | { |
|
|
1953 | if (sl.buf[i]) |
1952 | if (sl.buf[i]) |
1954 | got_one = 1; |
1953 | got_one = 1; |
1955 | } |
|
|
1956 | |
1954 | |
1957 | if (got_one && (mask & 0xf)) |
1955 | if (got_one && (mask & 0xf)) |
1958 | { |
|
|
1959 | sl.buf[oldlen + 1] = mask & 0xff; |
1956 | sl.buf[oldlen + 1] = mask & 0xff; |
1960 | } |
|
|
1961 | else |
1957 | else |
1962 | { /*either all faces blank, either no face at all */ |
1958 | { /*either all faces blank, either no face at all */ |
1963 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1959 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1964 | sl.len = oldlen + 2; |
1960 | sl.len = oldlen + 2; |
1965 | else |
1961 | else |
1966 | sl.len = oldlen; |
1962 | sl.len = oldlen; |
1967 | } |
1963 | } |
|
|
1964 | |
1968 | /*What concerns extendinfos, nothing to be done for now |
1965 | /*What concerns extendinfos, nothing to be done for now |
1969 | * (perhaps effects layer later) |
1966 | * (perhaps effects layer later) |
1970 | */ |
1967 | */ |
1971 | continue; /* don't do processing below */ |
1968 | continue; /* don't do processing below */ |
1972 | } |
1969 | } |
1973 | |
1970 | |
1974 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1971 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1975 | |
1972 | |
1976 | d = pl->contr->blocked_los[ax][ay]; |
1973 | d = pl->contr->blocked_los[ax][ay]; |
1977 | |
1974 | |
1978 | /* If the coordinates are not valid, or it is too dark to see, |
1975 | /* If the coordinates are not valid, or it is too dark to see, |
1979 | * we tell the client as such |
1976 | * we tell the client as such |
1980 | */ |
1977 | */ |
1981 | nx = x; |
1978 | nx = x; |
1982 | ny = y; |
1979 | ny = y; |
1983 | m = get_map_from_coord (pl->map, &nx, &ny); |
1980 | m = get_map_from_coord (pl->map, &nx, &ny); |
|
|
1981 | |
1984 | if (!m) |
1982 | if (!m) |
1985 | { |
1983 | { |
1986 | /* space is out of map. Update space and clear values |
1984 | /* space is out of map. Update space and clear values |
1987 | * if this hasn't already been done. If the space is out |
1985 | * if this hasn't already been done. If the space is out |
1988 | * of the map, it shouldn't have a head |
1986 | * of the map, it shouldn't have a head |
… | |
… | |
2002 | */ |
2000 | */ |
2003 | |
2001 | |
2004 | oldlen = sl.len; |
2002 | oldlen = sl.len; |
2005 | |
2003 | |
2006 | SockList_AddShort (&sl, mask); |
2004 | SockList_AddShort (&sl, mask); |
|
|
2005 | |
2007 | if (lastcell.count != -1) |
2006 | if (lastcell.count != -1) |
2008 | need_send = 1; |
2007 | need_send = 1; |
|
|
2008 | |
2009 | count = -1; |
2009 | count = -1; |
2010 | |
2010 | |
2011 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2011 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | { |
2012 | { |
2013 | /* Now check to see if any heads need to be sent */ |
2013 | /* Now check to see if any heads need to be sent */ |
… | |
… | |
2018 | mask |= 0x2; |
2018 | mask |= 0x2; |
2019 | if (check_head (sl, socket, ax, ay, 0)) |
2019 | if (check_head (sl, socket, ax, ay, 0)) |
2020 | mask |= 0x1; |
2020 | mask |= 0x1; |
2021 | |
2021 | |
2022 | lastcell.count = count; |
2022 | lastcell.count = count; |
2023 | |
|
|
2024 | } |
2023 | } |
2025 | else |
2024 | else |
2026 | { |
2025 | { |
2027 | struct MapCell *cell = &lastcell; |
|
|
2028 | |
|
|
2029 | /* properly clear a previously sent big face */ |
2026 | /* properly clear a previously sent big face */ |
2030 | if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) |
2027 | if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0 |
|
|
2028 | || lastcell.stat_hp || lastcell.flags || lastcell.player) |
2031 | need_send = 1; |
2029 | need_send = 1; |
|
|
2030 | |
2032 | map_clearcell (&lastcell, 0, 0, 0, count); |
2031 | map_clearcell (&lastcell, 0, 0, 0, count); |
2033 | } |
2032 | } |
2034 | |
2033 | |
2035 | if ((mask & 0xf) || need_send) |
2034 | if ((mask & 0xf) || need_send) |
2036 | { |
|
|
2037 | sl.buf[oldlen + 1] = mask & 0xff; |
2035 | sl.buf[oldlen + 1] = mask & 0xff; |
2038 | } |
|
|
2039 | else |
2036 | else |
2040 | { |
|
|
2041 | sl.len = oldlen; |
2037 | sl.len = oldlen; |
2042 | } |
|
|
2043 | } |
2038 | } |
2044 | else |
2039 | else |
2045 | { |
2040 | { |
2046 | /* In this block, the space is visible or there are head objects |
2041 | /* In this block, the space is visible or there are head objects |
2047 | * we need to send. |
2042 | * we need to send. |
… | |
… | |
2088 | |
2083 | |
2089 | if (socket.extmap) |
2084 | if (socket.extmap) |
2090 | { |
2085 | { |
2091 | uint8 stat_hp = 0; |
2086 | uint8 stat_hp = 0; |
2092 | uint8 stat_width = 0; |
2087 | uint8 stat_width = 0; |
|
|
2088 | uint8 flags = 0; |
2093 | tag_t player = 0; |
2089 | tag_t player = 0; |
2094 | |
2090 | |
2095 | // send hp information, if applicable |
2091 | // send hp information, if applicable |
2096 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2092 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2097 | { |
2093 | { |
… | |
… | |
2105 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2101 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2106 | stat_width = op->arch->tail_x; |
2102 | stat_width = op->arch->tail_x; |
2107 | } |
2103 | } |
2108 | } |
2104 | } |
2109 | |
2105 | |
|
|
2106 | if (op->msg && op->msg[0] == '@') |
|
|
2107 | flags |= 1; |
|
|
2108 | |
2110 | if (op->type == PLAYER && op != pl) |
2109 | if (op->type == PLAYER && op != pl) |
2111 | player = op->count; |
2110 | player = op->count; |
2112 | } |
2111 | } |
2113 | |
2112 | |
2114 | if (lastcell.stat_hp != stat_hp) |
2113 | if (lastcell.stat_hp != stat_hp) |
… | |
… | |
2139 | last_ext = sl.buf + sl.len; |
2138 | last_ext = sl.buf + sl.len; |
2140 | SockList_AddChar (&sl, 0x47); |
2139 | SockList_AddChar (&sl, 0x47); |
2141 | SockList_AddChar (&sl, 4); |
2140 | SockList_AddChar (&sl, 4); |
2142 | SockList_AddInt (&sl, player); |
2141 | SockList_AddInt (&sl, player); |
2143 | } |
2142 | } |
|
|
2143 | |
|
|
2144 | if (lastcell.flags != flags) |
|
|
2145 | { |
|
|
2146 | lastcell.flags = flags; |
|
|
2147 | |
|
|
2148 | mask |= 0x8; |
|
|
2149 | *last_ext |= 0x80; |
|
|
2150 | last_ext = sl.buf + sl.len; |
|
|
2151 | SockList_AddChar (&sl, 8); |
|
|
2152 | SockList_AddChar (&sl, flags); |
|
|
2153 | } |
2144 | } |
2154 | } |
2145 | |
2155 | |
2146 | /* Floor face */ |
2156 | /* Floor face */ |
2147 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2157 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2148 | mask |= 0x4; |
2158 | mask |= 0x4; |
… | |
… | |
2163 | { |
2173 | { |
2164 | if (lastcell.faces[0] != pl->face->number) |
2174 | if (lastcell.faces[0] != pl->face->number) |
2165 | { |
2175 | { |
2166 | lastcell.faces[0] = pl->face->number; |
2176 | lastcell.faces[0] = pl->face->number; |
2167 | mask |= 0x1; |
2177 | mask |= 0x1; |
|
|
2178 | |
2168 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2179 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2169 | esrv_send_face (&socket, pl->face->number, 0); |
2180 | esrv_send_face (&socket, pl->face->number, 0); |
|
|
2181 | |
2170 | SockList_AddShort (&sl, pl->face->number); |
2182 | SockList_AddShort (&sl, pl->face->number); |
2171 | } |
2183 | } |
2172 | } |
2184 | } |
2173 | /* Top face */ |
|
|
2174 | else |
2185 | else |
2175 | { |
2186 | { |
|
|
2187 | /* Top face */ |
2176 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2188 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2177 | mask |= 0x1; |
2189 | mask |= 0x1; |
|
|
2190 | |
2178 | if (socket.EMI_smooth) |
2191 | if (socket.EMI_smooth) |
2179 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2192 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2180 | { |
|
|
2181 | emask |= 0x1; |
2193 | emask |= 0x1; |
2182 | } |
|
|
2183 | } |
2194 | } |
|
|
2195 | |
2184 | /* Check to see if we are in fact sending anything for this |
2196 | /* Check to see if we are in fact sending anything for this |
2185 | * space by checking the mask. If so, update the mask. |
2197 | * space by checking the mask. If so, update the mask. |
2186 | * if not, reset the len to that from before adding the mask |
2198 | * if not, reset the len to that from before adding the mask |
2187 | * value, so we don't send those bits. |
2199 | * value, so we don't send those bits. |
2188 | */ |
2200 | */ |
2189 | if (mask & 0xf) |
2201 | if (mask & 0xf) |
2190 | { |
|
|
2191 | sl.buf[oldlen + 1] = mask & 0xff; |
2202 | sl.buf[oldlen + 1] = mask & 0xff; |
2192 | } |
|
|
2193 | else |
2203 | else |
2194 | { |
|
|
2195 | sl.len = oldlen; |
2204 | sl.len = oldlen; |
2196 | } |
2205 | |
2197 | if (emask & 0xf) |
2206 | if (emask & 0xf) |
2198 | { |
|
|
2199 | esl.buf[eoldlen + 1] = emask & 0xff; |
2207 | esl.buf[eoldlen + 1] = emask & 0xff; |
2200 | } |
|
|
2201 | else |
2208 | else |
2202 | { |
|
|
2203 | esl.len = eoldlen; |
2209 | esl.len = eoldlen; |
2204 | } |
|
|
2205 | } /* else this is a viewable space */ |
2210 | } /* else this is a viewable space */ |
2206 | } /* for x loop */ |
2211 | } /* for x loop */ |
2207 | } /* for y loop */ |
2212 | } /* for y loop */ |
2208 | |
2213 | |
2209 | /* Verify that we in fact do need to send this */ |
2214 | /* Verify that we in fact do need to send this */ |