--- deliantra/server/socket/request.C 2006/08/17 20:23:32 1.2 +++ deliantra/server/socket/request.C 2006/08/18 02:06:58 1.3 @@ -1,6 +1,6 @@ /* * static char *rcsid_init_c = - * "$Id: request.C,v 1.2 2006/08/17 20:23:32 root Exp $"; + * "$Id: request.C,v 1.3 2006/08/18 02:06:58 root Exp $"; */ /* @@ -370,6 +370,9 @@ } else if (!strcmp(cmd,"extcmd")) { ns->extcmd = atoi(param); safe_strcat(cmdback, "1", &slen, HUGE_BUF); + } else if (!strcmp(cmd,"extmap")) { + ns->extmap = atoi(param); + safe_strcat(cmdback, "1", &slen, HUGE_BUF); } else if (!strcmp(cmd,"facecache")) { ns->facecache = atoi(param); safe_strcat(cmdback, param, &slen, HUGE_BUF); @@ -1267,10 +1270,11 @@ /** Clears a map cell */ static void map_clearcell(struct MapCell *cell, int face0, int face1, int face2, int count) { - cell->count=count; cell->faces[0] = face0; cell->faces[1] = face1; cell->faces[2] = face2; + cell->count = count; + cell->stat_hp = 255; } #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) @@ -1305,7 +1309,7 @@ * if needed, and returning 1. If this no data needs to get * sent, it returns zero. */ -static inline int check_head(SockList *sl, NewSocket *ns, int ax, int ay, int layer) +static int check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) { short face_num; @@ -1314,12 +1318,12 @@ else face_num = 0; - if (face_num != ns->lastmap.cells[ax][ay].faces[layer]) { - SockList_AddShort(sl, face_num); - if (face_num && !(ns->faces_sent[face_num] & NS_FACESENT_FACE)) - esrv_send_face(ns, face_num, 0); + if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { + SockList_AddShort (&sl, face_num); + if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) + esrv_send_face (&ns, face_num, 0); heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; - ns->lastmap.cells[ax][ay].faces[layer] = face_num; + ns.lastmap.cells[ax][ay].faces[layer] = face_num; return 1; } @@ -1346,7 +1350,7 @@ * actually match. */ -static inline int update_space(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) +static int update_space(SockList *sl, NewSocket *ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) { object *ob, *head; uint16 face_num; @@ -1625,29 +1629,30 @@ uint16 ewhatstart,ewhatflag; uint8 extendedinfos; mapstruct *m; + NewSocket &socket = pl->contr->socket; check_map_change (pl->contr); sl.buf=(unsigned char*)malloc(MAXSOCKBUF); - if (pl->contr->socket.mapmode == Map1Cmd) + if (socket.mapmode == Map1Cmd) strcpy((char*)sl.buf,"map1 "); else strcpy((char*)sl.buf,"map1a "); sl.len=strlen((char*)sl.buf); startlen = sl.len; /*Extendedmapinfo structure initialisation*/ - if (pl->contr->socket.ext_mapinfos){ + if (socket.ext_mapinfos){ esl.buf=(unsigned char*)malloc(MAXSOCKBUF); strcpy((char*)esl.buf,"mapextended "); esl.len=strlen((char*)esl.buf); extendedinfos=EMI_NOREDRAW; - if (pl->contr->socket.EMI_smooth) + if (socket.EMI_smooth) extendedinfos|=EMI_SMOOTH; ewhatstart=esl.len; ewhatflag=extendedinfos; /*The EMI_NOREDRAW bit could need to be taken away*/ SockList_AddChar(&esl, extendedinfos); - eentrysize=getExtendedMapInfoSize(&(pl->contr->socket)); + eentrysize=getExtendedMapInfoSize(&socket); SockList_AddChar(&esl, eentrysize); estartlen = esl.len; } else { @@ -1667,16 +1672,16 @@ /* We could do this logic as conditionals in the if statement, * but that started to get a bit messy to look at. */ - max_x = pl->x+(pl->contr->socket.mapx+1)/2; - max_y = pl->y+(pl->contr->socket.mapy+1)/2; - if (pl->contr->socket.mapmode == Map1aCmd) { + max_x = pl->x+(socket.mapx+1)/2; + max_y = pl->y+(socket.mapy+1)/2; + if (socket.mapmode == Map1aCmd) { max_x += MAX_HEAD_OFFSET; max_y += MAX_HEAD_OFFSET; } - for(y=pl->y-pl->contr->socket.mapy/2; yy-socket.mapy/2; yx-pl->contr->socket.mapx/2;xx-socket.mapx/2;x= pl->contr->socket.mapx || ay >= pl->contr->socket.mapy) { + if (ax >= socket.mapx || ay >= socket.mapy) { int i, got_one; oldlen = sl.len; - SockList_AddShort(&sl, mask); - if (check_head(&sl, &pl->contr->socket, ax, ay, 2)) + if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; - if (check_head(&sl, &pl->contr->socket, ax, ay, 1)) + if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; - if (check_head(&sl, &pl->contr->socket, ax, ay, 0)) + if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; /* If all we are doing is sending 0 (blank) faces, we don't @@ -1714,10 +1718,10 @@ if (got_one && (mask & 0xf)) { sl.buf[oldlen+1] = mask & 0xff; } else { /*either all faces blank, either no face at all*/ - if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ - sl.len = oldlen + 2; - else - sl.len = oldlen; + if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ + sl.len = oldlen + 2; + else + sl.len = oldlen; } /*What concerns extendinfos, nothing to be done for now * (perhaps effects layer later) @@ -1725,6 +1729,8 @@ continue; /* don't do processing below */ } + MapCell &lastcell = socket.lastmap.cells[ax][ay]; + d = pl->contr->blocked_los[ax][ay]; /* If the coordinates are not valid, or it is too dark to see, @@ -1738,9 +1744,9 @@ * if this hasn't already been done. If the space is out * of the map, it shouldn't have a head */ - if (pl->contr->socket.lastmap.cells[ax][ay].count != -1) { + if (lastcell.count != -1) { SockList_AddShort(&sl, mask); - map_clearcell(&pl->contr->socket.lastmap.cells[ax][ay],0,0,0,-1); + map_clearcell(&lastcell,0,0,0,-1); } } else if (d>3) { int need_send=0, count; @@ -1749,45 +1755,31 @@ */ oldlen = sl.len; -#if 0 - /* First thing we do is blank out this space (clear it) - * if not already done. If the client is using darkness, and - * this space is at the edge, we also include the darkness. - */ - if (d==4) { - if (pl->contr->socket.darkness && pl->contr->socket.lastmap.cells[ax][ay].count != d) { - mask |= 8; - SockList_AddShort(&sl, mask); - SockList_AddChar(&sl, 0); - } - count = d; - } else -#endif - { - SockList_AddShort(&sl, mask); - if (pl->contr->socket.lastmap.cells[ax][ay].count != -1) need_send=1; - count = -1; - } - if (pl->contr->socket.mapmode == Map1aCmd && have_head(ax, ay)) { + SockList_AddShort(&sl, mask); + if (lastcell.count != -1) need_send=1; + count = -1; + + if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { /* Now check to see if any heads need to be sent */ - if (check_head(&sl, &pl->contr->socket, ax, ay, 2)) + if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; - if (check_head(&sl, &pl->contr->socket, ax, ay, 1)) + if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; - if (check_head(&sl, &pl->contr->socket, ax, ay, 0)) + if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; - pl->contr->socket.lastmap.cells[ax][ay].count = count; + + lastcell.count = count; } else { - struct MapCell *cell = &pl->contr->socket.lastmap.cells[ax][ay]; + struct MapCell *cell = &lastcell; /* properly clear a previously sent big face */ if(cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) need_send = 1; - map_clearcell(&pl->contr->socket.lastmap.cells[ax][ay], 0, 0, 0, count); + map_clearcell(&lastcell, 0, 0, 0, count); } if ((mask & 0xf) || need_send) { @@ -1816,65 +1808,78 @@ emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; SockList_AddShort(&sl, mask); - if (pl->contr->socket.ext_mapinfos) + if (socket.ext_mapinfos) SockList_AddShort(&esl, emask); + unsigned char dummy; + unsigned char *last_ext = &dummy; + /* Darkness changed */ - if (pl->contr->socket.lastmap.cells[ax][ay].count != d && pl->contr->socket.darkness) { - pl->contr->socket.lastmap.cells[ax][ay].count = d; - mask |= 0x8; /* darkness bit */ - - /* Protocol defines 255 full bright, 0 full dark. - * We currently don't have that many darkness ranges, - * so we current what limited values we do have. - */ - if (d==0) SockList_AddChar(&sl, 255); - else if (d==1) SockList_AddChar(&sl, 191); - else if (d==2) SockList_AddChar(&sl, 127); - else if (d==3) SockList_AddChar(&sl, 63); - } - else { - /* need to reset from -1 so that if it does become blocked again, - * the code that deals with that can detect that it needs to tell - * the client that this space is now blocked. - */ - pl->contr->socket.lastmap.cells[ax][ay].count = d; + if (lastcell.count != d && socket.darkness) { + mask |= 0x8; + + if (socket.extmap) + { + *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); + } + else + SockList_AddChar (&sl, 255 - 64 * d); } + lastcell.count = d; + + if (socket.extmap) + { + uint8 stat_hp = 0; + + // send hp information, if applicable + if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) + if (op->stats.maxhp > 0 + && (unsigned)op->stats.maxhp + 1 > (unsigned)op->stats.hp + && IS_LIVE (op)) + stat_hp = 255 - op->stats.hp * 255 / op->stats.maxhp; + + if (lastcell.stat_hp != stat_hp) + { + lastcell.stat_hp = stat_hp; + + mask |= 0x8; + *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 5); + SockList_AddChar (&sl, stat_hp); + } + } + /* Floor face */ - if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 2)) + if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) mask |= 0x4; - if (pl->contr->socket.EMI_smooth) - if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 2)){ + if (socket.EMI_smooth) + if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) emask |= 0x4; - } /* Middle face */ - if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 1)) + if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) mask |= 0x2; - if (pl->contr->socket.EMI_smooth) - if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 1)){ + if (socket.EMI_smooth) + if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) emask |= 0x2; - } - if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { - if (pl->contr->socket.lastmap.cells[ax][ay].faces[0] != pl->face->number) { - pl->contr->socket.lastmap.cells[ax][ay].faces[0] = pl->face->number; + if (lastcell.faces[0] != pl->face->number) { + lastcell.faces[0] = pl->face->number; mask |= 0x1; - if (!(pl->contr->socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) - esrv_send_face(&pl->contr->socket, pl->face->number, 0); + if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) + esrv_send_face(&socket, pl->face->number, 0); SockList_AddShort(&sl, pl->face->number); } } /* Top face */ else { - if (update_space(&sl, &pl->contr->socket, m, nx, ny, ax, ay, 0)) + if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) mask |= 0x1; - if (pl->contr->socket.EMI_smooth) - if (update_smooth(&esl, &pl->contr->socket, m, nx, ny, ax, ay, 0)){ + if (socket.EMI_smooth) + if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ emask |= 0x1; } } @@ -1898,8 +1903,8 @@ } /* for y loop */ /* Verify that we in fact do need to send this */ - if (pl->contr->socket.ext_mapinfos){ - if (!(sl.len>startlen || pl->contr->socket.sent_scroll)){ + if (socket.ext_mapinfos){ + if (!(sl.len>startlen || socket.sent_scroll)){ /* No map data will follow, so don't say the client * it doesn't need draw! */ @@ -1907,13 +1912,13 @@ esl.buf[ewhatstart+1] = ewhatflag & 0xff; } if (esl.len>estartlen) { - Send_With_Handling(&pl->contr->socket, &esl); + Send_With_Handling(&socket, &esl); } free(esl.buf); } - if (sl.len>startlen || pl->contr->socket.sent_scroll) { - Send_With_Handling(&pl->contr->socket, &sl); - pl->contr->socket.sent_scroll = 0; + if (sl.len>startlen || socket.sent_scroll) { + Send_With_Handling(&socket, &sl); + socket.sent_scroll = 0; } free(sl.buf); }