ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.176 by root, Thu Apr 29 15:59:10 2010 UTC vs.
Revision 1.189 by root, Wed Oct 31 09:17:14 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel 5 * Copyright (©) 2001 Mark Wedel
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25//+GPL 25//+GPL
26 26
146 pl->ns->mapinfo_queue_clear (); 146 pl->ns->mapinfo_queue_clear ();
147 147
148 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); 148 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap));
149 149
150 pl->ns->force_newmap = false; 150 pl->ns->force_newmap = false;
151
152 if (pl->ns->newmapcmd == 1)
153 pl->ns->send_packet ("newmap"); 151 pl->ns->send_packet ("newmap");
154
155 pl->ns->floorbox_reset (); 152 pl->ns->floorbox_reset ();
156} 153}
157 154
158static void 155static void
159send_map_info (player *pl) 156send_map_info (player *pl)
161 client &socket = *pl->ns; 158 client &socket = *pl->ns;
162 object *ob = pl->viewpoint; 159 object *ob = pl->viewpoint;
163 160
164 if (socket.mapinfocmd) 161 if (socket.mapinfocmd)
165 { 162 {
166 if (ob->map && ob->map->path[0]) 163 if (ob->map && ob->map->path)
167 { 164 {
168 int flags = 0; 165 int flags = 0;
169 166
167 // due to historical glitches, the bit ordering and map index ordering differs
170 if (ob->map->tile_path[0]) flags |= 1; 168 if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01;
171 if (ob->map->tile_path[1]) flags |= 2; 169 if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02;
172 if (ob->map->tile_path[2]) flags |= 4; 170 if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04;
173 if (ob->map->tile_path[3]) flags |= 8; 171 if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08;
172 // these two are debatable
173 if (ob->map->tile_path [TILE_UP ]) flags |= 0x10;
174 if (ob->map->tile_path [TILE_DOWN ]) flags |= 0x20;
174 175
175 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", 176 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
176 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, 177 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
177 ob->map->width, ob->map->height, &ob->map->path); 178 ob->map->width, ob->map->height, &ob->map->path);
178 } 179 }
193 { 194 {
194 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); 195 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
195 socket.current_region = reg; 196 socket.current_region = reg;
196 } 197 }
197 198
198 // first try to aovid a full newmap on tiled map scrolls 199 // first try to avoid a full newmap on tiled map scrolls
199 if (socket.current_map != ob->map && !socket.force_newmap) 200 if (socket.current_map != ob->map && !socket.force_newmap)
200 { 201 {
201 rv_vector rv; 202 rv_vector rv;
202 203
203 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); 204 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0);
344 345
345 while (*buf && map && max_distance) 346 while (*buf && map && max_distance)
346 { 347 {
347 int dir = *buf++ - '1'; 348 int dir = *buf++ - '1';
348 349
349 if (dir >= 0 && dir <= 3) 350 // due to historical glitches, the mapinfo index and tile index differs
351 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN };
352
353 // maybe we should only allow the four flat directions
354 if (IN_RANGE_EXC (dir, 0, array_length (dirmap)))
350 { 355 {
356 dir = dirmap [dir];
357
351 if (!map->tile_path [dir]) 358 if (!map->tile_path [dir])
352 map = 0; 359 map = 0;
353 else if (map->tile_available (dir, false)) 360 else if (map->tile_available (dir, false))
354 { 361 {
355 maptile *neigh = map->tile_map [dir]; 362 maptile *neigh = map->tile_map [dir];
378 send_packet_printf ("mapinfo %s nomap", token); 385 send_packet_printf ("mapinfo %s nomap", token);
379 else 386 else
380 { 387 {
381 int flags = 0; 388 int flags = 0;
382 389
390 // due to historical glitches, the bit ordering and map index ordering differs
383 if (map->tile_path[0]) flags |= 1; 391 if (map->tile_path [TILE_NORTH]) flags |= 0x01;
384 if (map->tile_path[1]) flags |= 2; 392 if (map->tile_path [TILE_EAST ]) flags |= 0x02;
385 if (map->tile_path[2]) flags |= 4; 393 if (map->tile_path [TILE_SOUTH]) flags |= 0x04;
386 if (map->tile_path[3]) flags |= 8; 394 if (map->tile_path [TILE_WEST ]) flags |= 0x08;
395 // these two are debatable
396 if (map->tile_path [TILE_UP ]) flags |= 0x10;
397 if (map->tile_path [TILE_DOWN ]) flags |= 0x20;
387 398
388 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); 399 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path);
389 } 400 }
390 401
391 return 1; 402 return 1;
876 887
877 /* Nothing changed */ 888 /* Nothing changed */
878 return 0; 889 return 0;
879} 890}
880 891
881//-GPL
882
883// prefetch maps in an area of PREFETCH x PREFETCH around the player
884#define PREFETCH 40
885
886// prefetch a generous area around the player
887static void
888prefetch_surrounding_maps (object *op)
889{
890 for (maprect *rect = op->map->split_to_tiles (mapwalk_buf,
891 op->x - PREFETCH , op->y - PREFETCH ,
892 op->x + PREFETCH + 1, op->y + PREFETCH + 1);
893 rect->m;
894 ++rect)
895 rect->m->touch ();
896}
897
898//+GPL
899
900/** 892/**
901 * Draws client map. 893 * Draws client map.
902 */ 894 */
903void 895void
904draw_client_map (player *pl) 896draw_client_map (player *pl)
909 901
910 /* If player is just joining the game, he isn't here yet, so the map 902 /* If player is just joining the game, he isn't here yet, so the map
911 * can get swapped out. If so, don't try to send them a map. All will 903 * can get swapped out. If so, don't try to send them a map. All will
912 * be OK once they really log in. 904 * be OK once they really log in.
913 */ 905 */
914 if (!ob->map || ob->map->in_memory != MAP_ACTIVE) 906 if (!ob->map || ob->map->state != MAP_ACTIVE)
915 return; 907 return;
916 908
917 int startlen, oldlen; 909 int startlen, oldlen;
918 910
919 check_map_change (pl); 911 check_map_change (pl);
920 prefetch_surrounding_maps (pl->ob); 912 pl->ob->prefetch_surrounding_maps ();
921 913
922 /* do LOS after calls to update_position */ 914 /* do LOS after calls to update_position */
923 /* unfortunately, we need to udpate los when observing, currently */ 915 /* unfortunately, we need to udpate los when observing, currently */
924 if (pl->do_los || pl->viewpoint != pl->ob) 916 if (pl->do_los || pl->viewpoint != pl->ob)
925 { 917 {
950 * look like. 942 * look like.
951 */ 943 */
952 944
953 client &socket = *pl->ns; 945 client &socket = *pl->ns;
954 946
955 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 947 packet sl ("map1a");
956 948
957 startlen = sl.length (); 949 startlen = sl.length ();
958 950
959 int hx = socket.mapx / 2; 951 int hx = socket.mapx / 2;
960 int hy = socket.mapy / 2; 952 int hy = socket.mapy / 2;
1243 1235
1244/* appends the spell *spell to the Socklist we will send the data to. */ 1236/* appends the spell *spell to the Socklist we will send the data to. */
1245static void 1237static void
1246append_spell (player *pl, packet &sl, object *spell) 1238append_spell (player *pl, packet &sl, object *spell)
1247{ 1239{
1248 int i, skill = 0; 1240 int skill = 0;
1249 1241
1250 if (!(spell->name)) 1242 if (!(spell->name))
1251 { 1243 {
1252 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1244 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1253 return; 1245 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines