--- deliantra/server/socket/request.C 2008/07/13 11:57:25 1.133 +++ deliantra/server/socket/request.C 2008/12/23 06:58:24 1.143 @@ -100,25 +100,21 @@ my = ns->mapy; /* the x and y here are coordinates for the new map, i.e. if we moved - * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, + * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, * if the destination x or y coordinate is outside the viewable * area, we clear the values - otherwise, the old values * are preserved, and the check_head thinks it needs to clear them. */ for (x = 0; x < mx; x++) - { - for (y = 0; y < my; y++) - { - if (x >= ns->mapx || y >= ns->mapy) - /* clear cells outside the viewable area */ - memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); - else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) - /* clear newly visible tiles within the viewable area */ - memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); - else - memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); - } - } + for (y = 0; y < my; y++) + if (x >= ns->mapx || y >= ns->mapy) + /* clear cells outside the viewable area */ + memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); + else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) + /* clear newly visible tiles within the viewable area */ + memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); + else + memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); @@ -835,7 +831,7 @@ AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); for (int s = 0; s < NUM_SKILLS; s++) - if (object *skill = opl->last_skill_ob[s]) + if (object *skill = opl->last_skill_ob [s]) if (skill->stats.exp != ns->last_skill_exp [s]) { ns->last_skill_exp [s] = skill->stats.exp; @@ -914,7 +910,6 @@ pl->ns->last_weight = weight; pl->ns->send_packet (sl); - SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } /****************************************************************************** @@ -1042,16 +1037,14 @@ if (!ob->active) return; - maptile *plmap = ob->map; - /* If player is just joining the game, he isn't here yet, so the map * can get swapped out. If so, don't try to send them a map. All will * be OK once they really log in. */ - if (!plmap || plmap->in_memory != MAP_ACTIVE) + if (!ob->map || ob->map->in_memory != MAP_ACTIVE) return; - int x, y, ax, ay, startlen, max_x, max_y, oldlen; + int startlen, oldlen; int estartlen, eoldlen; uint8 eentrysize; uint16 ewhatstart, ewhatflag; @@ -1061,12 +1054,11 @@ prefetch_surrounding_maps (pl->ob); /* do LOS after calls to update_position */ - if (ob != pl->ob) - clear_los (pl); - else if (pl->do_los) + /* unfortunately, we need to udpate los when observing, currently */ + if (pl->do_los || pl->observe != pl->ob) { - update_los (ob); pl->do_los = 0; + pl->update_los (); } /** @@ -1118,33 +1110,27 @@ estartlen = esl.length (); } - /* x,y are the real map locations. ax, ay are viewport relative - * locations. - */ - ay = 0; - /* We could do this logic as conditionals in the if statement, * but that started to get a bit messy to look at. */ - max_x = ob->x + (socket.mapx + 1) / 2; - max_y = ob->y + (socket.mapy + 1) / 2; + int hx = socket.mapx / 2; + int hy = socket.mapy / 2; - for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++) + for (int dx = -hx; dx <= hx; dx++) { sint16 nx, ny; maptile *m = 0; - ax = 0; - for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++) + for (int dy = -hy; dy <= hy; dy++) { - // check to see if we can simply go one right quickly - ++nx; - if (m && nx >= m->width) + // check to see if we can simply go one down quickly + if (m && ++ny >= m->height) m = 0; + // no, so do it the slow way if (!m) { - nx = x; ny = y; m = plmap; + nx = ob->x + dx; ny = ob->y + dy; m = ob->map; if (xy_normalise (m, nx, ny)) m->touch (); @@ -1152,6 +1138,9 @@ m = 0; } + int ax = dx + hx; + int ay = dy + hy; + int emask, mask; emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; @@ -1162,9 +1151,9 @@ */ if (!m) { - /* space is out of map. Update space and clear values - * if this hasn't already been done. If the space is out - * of the map, it shouldn't have a head + /* space is out of map. Update space and clear values + * if this hasn't already been done. If the space is out + * of the map, it shouldn't have a head. */ if (lastcell.count != -1) { @@ -1175,7 +1164,7 @@ continue; } - int d = pl->blocked_los[ax][ay]; + int d = pl->blocked_los_uc (dx, dy); if (d > 3) { @@ -1264,17 +1253,21 @@ && op->stats.maxhp > 0 && (op->type == PLAYER || op->type == DOOR // does not work, have maxhp 0 - || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR))) + || QUERY_FLAG (op, FLAG_MONSTER) + || QUERY_FLAG (op, FLAG_ALIVE) + || QUERY_FLAG (op, FLAG_GENERATOR))) { stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge } - if (op->msg && op->msg[0] == '@') + if (op->has_dialogue ()) flags |= 1; if (op->type == PLAYER) - player = op->count; + player = op == ob ? pl->ob->count + : op == pl->ob ? ob->count + : op->count; } if (lastcell.stat_hp != stat_hp) @@ -1327,8 +1320,9 @@ if (update_space (sl, socket, ms, lastcell, 1)) mask |= 0x2; - if (ms.player () == ob - && (ob->invisible & (ob->invisible < 50 ? 1 : 7))) + if (ob->invisible + && ob->invisible & (ob->invisible < 50 ? 1 : 7) + && ms.player () == ob) { // force player to be visible to himself if invisible if (lastcell.faces[0] != ob->face) @@ -1434,7 +1428,7 @@ sl << "replyinfo skill_info\n"; for (int i = 1; i < NUM_SKILLS; i++) - sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); + sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); if (sl.length () > MAXSOCKBUF) { @@ -1562,14 +1556,8 @@ /* figure out which skill it uses, if it uses one */ if (spell->skill) - { - for (i = 1; i < NUM_SKILLS; i++) - if (!strcmp (spell->skill, skill_names[i])) - { - skill = i + CS_STAT_SKILLINFO; - break; - } - } + if (object *tmp = pl->find_skill (spell->skill)) + skill = tmp->subtype + CS_STAT_SKILLINFO; // spells better have a face if (!spell->face)