--- deliantra/server/socket/request.C 2007/08/24 00:26:10 1.119 +++ deliantra/server/socket/request.C 2008/09/25 04:09:57 1.138 @@ -1,11 +1,11 @@ /* - * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001,2007 Mark Wedel * Copyright (©) 1992,2007 Frank Tore Johansen * - * Crossfire TRT is free software: you can redistribute it and/or modify + * Deliantra is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * The authors can be reached via e-mail to + * The authors can be reached via e-mail to */ /** @@ -143,6 +143,32 @@ pl->ns->floorbox_reset (); } +static void +send_map_info (player *pl) +{ + client &socket = *pl->ns; + object *ob = pl->observe; + + if (socket.mapinfocmd) + { + if (ob->map && ob->map->path[0]) + { + int flags = 0; + + if (ob->map->tile_path[0]) flags |= 1; + if (ob->map->tile_path[1]) flags |= 2; + if (ob->map->tile_path[2]) flags |= 4; + if (ob->map->tile_path[3]) flags |= 8; + + socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", + flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, + ob->map->width, ob->map->height, &ob->map->path); + } + else + socket.send_packet ("mapinfo current"); + } +} + /** check for map/region change and send new map data */ static void check_map_change (player *pl) @@ -150,30 +176,39 @@ client &socket = *pl->ns; object *ob = pl->observe; - if (socket.current_map != ob->map || socket.force_newmap) + region *reg = ob->region (); + if (socket.current_region != reg) { - clear_map (pl); - socket.current_map = ob->map; + INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); + socket.current_region = reg; + } + + // first try to aovid a full newmap on tiled map scrolls + if (socket.current_map != ob->map && !socket.force_newmap) + { + rv_vector rv; - if (socket.mapinfocmd) + get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); + + // manhattan distance is very handy here + if (rv.distance < 8) // 8 works nicely for speed << 70 and buggy gcfclient { - if (ob->map && ob->map->path[0]) - { - int flags = 0; + socket.current_map = ob->map; + socket.current_x = ob->x; + socket.current_y = ob->y; - if (ob->map->tile_path[0]) flags |= 1; - if (ob->map->tile_path[1]) flags |= 2; - if (ob->map->tile_path[2]) flags |= 4; - if (ob->map->tile_path[3]) flags |= 8; - - socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", - flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, - ob->map->width, ob->map->height, &ob->map->path); - } - else - socket.send_packet ("mapinfo current"); + socket_map_scroll (&socket, rv.distance_x, rv.distance_y); + socket.floorbox_reset (); + send_map_info (pl); } } + + if (socket.current_map != ob->map || socket.force_newmap) + { + clear_map (pl); + socket.current_map = ob->map; + send_map_info (pl); + } else if (socket.current_x != ob->x || socket.current_y != ob->y) { int dx = ob->x - socket.current_x; @@ -190,13 +225,6 @@ socket.current_x = ob->x; socket.current_y = ob->y; - - region *reg = ob->region (); - if (socket.current_region != reg) - { - INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); - socket.current_region = reg; - } } /** @@ -265,9 +293,9 @@ buf += strlen (buf) + 9; // initial map and its origin - maptile *map = pl->ob->map; - int mapx = pl->ns->mapx / 2 - pl->ob->x; - int mapy = pl->ns->mapy / 2 - pl->ob->y; + maptile *map = pl->observe->map; + int mapx = pl->ns->mapx / 2 - pl->observe->x; + int mapy = pl->ns->mapy / 2 - pl->observe->y; int max_distance = 8; // limit maximum path length to something generous while (*buf && map && max_distance) @@ -278,7 +306,7 @@ { if (!map->tile_path [dir]) map = 0; - else if (map->tile_available (dir)) + else if (map->tile_available (dir, false)) { maptile *neigh = map->tile_map [dir]; @@ -302,7 +330,7 @@ if (!max_distance) send_packet_printf ("mapinfo %s error", token); - else if (!map || !map->path[0]) + else if (!map || !map->path) send_packet_printf ("mapinfo %s nomap", token); else { @@ -688,30 +716,15 @@ void MoveCmd (char *buf, int len, player *pl) { - int vals[3], i; + int to, tag, nrof; - /* A little funky here. We only cycle for 2 records, because - * we obviously are not going to find a space after the third - * record. Perhaps we should just replace this with a - * sscanf? - */ - for (i = 0; i < 2; i++) + if (3 != sscanf (buf, "%d %d %d", &to, &tag, &nrof)) { - vals[i] = atoi (buf); - - if (!(buf = strchr (buf, ' '))) - { - LOG (llevError, "Incomplete move command: %s\n", buf); - return; - } - - buf++; + LOG (llevError, "Incomplete move command: %s\n", buf); + return; } - vals[2] = atoi (buf); - -/* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ - esrv_move_object (pl->ob, vals[0], vals[1], vals[2]); + esrv_move_object (pl->ob, to, tag, nrof); } /****************************************************************************** @@ -822,7 +835,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; @@ -888,8 +901,10 @@ * Tells the client that here is a player it should start using. */ void -esrv_new_player (player *pl, uint32 weight) +esrv_new_player (player *pl) { + sint32 weight = pl->ob->client_weight (); + packet sl ("player"); sl << uint32 (pl->ob->count) @@ -899,7 +914,6 @@ pl->ns->last_weight = weight; pl->ns->send_packet (sl); - SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } /****************************************************************************** @@ -1033,7 +1047,7 @@ * 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_IN_MEMORY) + if (!plmap || plmap->in_memory != MAP_ACTIVE) return; int x, y, ax, ay, startlen, max_x, max_y, oldlen; @@ -1131,7 +1145,9 @@ { nx = x; ny = y; m = plmap; - if (!xy_normalise (m, nx, ny)) + if (xy_normalise (m, nx, ny)) + m->touch (); + else m = 0; } @@ -1158,13 +1174,10 @@ continue; } - m->touch (); - int d = pl->blocked_los[ax][ay]; if (d > 3) { - int need_send = 0, count; /* This block deals with spaces that are not visible for whatever @@ -1180,11 +1193,11 @@ count = -1; - /* properly clear a previously sent big face */ if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2] || lastcell.stat_hp || lastcell.flags || lastcell.player) need_send = 1; + /* properly clear a previously sent big face */ map_clearcell (&lastcell, count); if ((mask & 0xf) || need_send) @@ -1244,25 +1257,28 @@ // send hp information, if applicable if (object *op = ms.faces_obj [0]) - { - if (op->head || op->invisible) - ; // do not show - else if (op->type == PLAYER - || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) - { - if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) - { - 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] == '@') - flags |= 1; - - if (op->type == PLAYER && op != ob) - player = op->count; - } + if (op->is_head () && !op->invisible) + { + if (op->stats.maxhp > op->stats.hp + && 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))) + { + 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->has_dialogue ()) + flags |= 1; + + if (op->type == PLAYER) + player = op == ob ? pl->ob->count + : op == pl->ob ? ob->count + : op->count; + } if (lastcell.stat_hp != stat_hp) { @@ -1475,21 +1491,21 @@ int flags = 0; /* check if we need to update it */ - if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) + if (spell->cached_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) { - spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); + spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); flags |= UPD_SP_MANA; } - if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) + if (spell->cached_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) { - spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); + spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); flags |= UPD_SP_GRACE; } - if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) + if (spell->cached_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) { - spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); + spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); flags |= UPD_SP_DAMAGE; } @@ -1501,9 +1517,9 @@ << uint8 (flags) << uint32 (spell->count); - if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); - if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); - if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); + if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp); + if (flags & UPD_SP_GRACE ) sl << uint16 (spell->cached_grace); + if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->cached_eat); pl->ns->send_packet (sl); } @@ -1543,9 +1559,9 @@ } /* store costs and damage in the object struct, to compare to later */ - spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); - spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); - spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); + spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); + spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); + spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); /* figure out which skill it uses, if it uses one */ if (spell->skill) @@ -1571,9 +1587,9 @@ sl << uint32 (spell->count) << uint16 (spell->level) << uint16 (spell->casting_time) - << uint16 (spell->last_sp) - << uint16 (spell->last_grace) - << uint16 (spell->last_eat) + << uint16 (spell->cached_sp) + << uint16 (spell->cached_grace) + << uint16 (spell->cached_eat) << uint8 (skill) << uint32 (spell->path_attuned) << uint32 (spell->face)