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,2011 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 | |
… | |
… | |
158 | client &socket = *pl->ns; |
158 | client &socket = *pl->ns; |
159 | object *ob = pl->viewpoint; |
159 | object *ob = pl->viewpoint; |
160 | |
160 | |
161 | if (socket.mapinfocmd) |
161 | if (socket.mapinfocmd) |
162 | { |
162 | { |
163 | if (ob->map && ob->map->path[0]) |
163 | if (ob->map && ob->map->path) |
164 | { |
164 | { |
165 | int flags = 0; |
165 | int flags = 0; |
166 | |
166 | |
|
|
167 | // due to historical glitches, the bit ordering and map index ordering differs |
167 | if (ob->map->tile_path[0]) flags |= 0x01; |
168 | if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01; |
168 | if (ob->map->tile_path[1]) flags |= 0x02; |
169 | if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02; |
169 | if (ob->map->tile_path[2]) flags |= 0x04; |
170 | if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04; |
170 | if (ob->map->tile_path[3]) flags |= 0x08; |
171 | if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08; |
171 | // these two are debatable |
172 | // these two are debatable |
172 | if (ob->map->tile_path[4]) flags |= 0x10; |
173 | if (ob->map->tile_path [TILE_UP ]) flags |= 0x10; |
173 | if (ob->map->tile_path[5]) flags |= 0x20; |
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 | } |
… | |
… | |
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 | |
|
|
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 | |
349 | // maybe we should only allow the four flat directions |
353 | // maybe we should only allow the four flat directions |
350 | if (dir >= 0 && dir < array_length (map->tile_path)) |
354 | if (IN_RANGE_EXC (dir, 0, array_length (dirmap))) |
351 | { |
355 | { |
|
|
356 | dir = dirmap [dir]; |
|
|
357 | |
352 | if (!map->tile_path [dir]) |
358 | if (!map->tile_path [dir]) |
353 | map = 0; |
359 | map = 0; |
354 | else if (map->tile_available (dir, false)) |
360 | else if (map->tile_available (dir, false)) |
355 | { |
361 | { |
356 | maptile *neigh = map->tile_map [dir]; |
362 | maptile *neigh = map->tile_map [dir]; |
… | |
… | |
379 | send_packet_printf ("mapinfo %s nomap", token); |
385 | send_packet_printf ("mapinfo %s nomap", token); |
380 | else |
386 | else |
381 | { |
387 | { |
382 | int flags = 0; |
388 | int flags = 0; |
383 | |
389 | |
|
|
390 | // due to historical glitches, the bit ordering and map index ordering differs |
384 | if (map->tile_path[0]) flags |= 0x01; |
391 | if (map->tile_path [TILE_NORTH]) flags |= 0x01; |
385 | if (map->tile_path[1]) flags |= 0x02; |
392 | if (map->tile_path [TILE_EAST ]) flags |= 0x02; |
386 | if (map->tile_path[2]) flags |= 0x04; |
393 | if (map->tile_path [TILE_SOUTH]) flags |= 0x04; |
387 | if (map->tile_path[3]) flags |= 0x08; |
394 | if (map->tile_path [TILE_WEST ]) flags |= 0x08; |
388 | // these two are debatable |
395 | // these two are debatable |
389 | if (map->tile_path[4]) flags |= 0x10; |
396 | if (map->tile_path [TILE_UP ]) flags |= 0x10; |
390 | if (map->tile_path[5]) flags |= 0x20; |
397 | if (map->tile_path [TILE_DOWN ]) flags |= 0x20; |
391 | |
398 | |
392 | 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); |
393 | } |
400 | } |
394 | |
401 | |
395 | return 1; |
402 | return 1; |
… | |
… | |
879 | } |
886 | } |
880 | |
887 | |
881 | /* Nothing changed */ |
888 | /* Nothing changed */ |
882 | return 0; |
889 | return 0; |
883 | } |
890 | } |
884 | |
|
|
885 | //-GPL |
|
|
886 | |
|
|
887 | // prefetch some flat area around the player |
|
|
888 | static void |
|
|
889 | prefetch_surrounding_area (object *op, maptile *map, int range) |
|
|
890 | { |
|
|
891 | for (maprect *rect = map->split_to_tiles (mapwalk_buf, |
|
|
892 | op->x - range , op->y - range , |
|
|
893 | op->x + range + 1, op->y + range + 1); |
|
|
894 | rect->m; |
|
|
895 | ++rect) |
|
|
896 | { |
|
|
897 | rect->m->touch (); |
|
|
898 | rect->m->activate (); |
|
|
899 | } |
|
|
900 | } |
|
|
901 | |
|
|
902 | // prefetch a generous area around the player, also up and down |
|
|
903 | void |
|
|
904 | object::prefetch_surrounding_maps () |
|
|
905 | { |
|
|
906 | prefetch_surrounding_area (this, map, 40); |
|
|
907 | |
|
|
908 | if (maptile *m = map->tile_available (TILE_DOWN)) |
|
|
909 | prefetch_surrounding_area (this, m, 20); |
|
|
910 | |
|
|
911 | if (maptile *m = map->tile_available (TILE_UP)) |
|
|
912 | prefetch_surrounding_area (this, m, 20); |
|
|
913 | } |
|
|
914 | |
|
|
915 | //+GPL |
|
|
916 | |
891 | |
917 | /** |
892 | /** |
918 | * Draws client map. |
893 | * Draws client map. |
919 | */ |
894 | */ |
920 | void |
895 | void |
… | |
… | |
1260 | |
1235 | |
1261 | /* 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. */ |
1262 | static void |
1237 | static void |
1263 | append_spell (player *pl, packet &sl, object *spell) |
1238 | append_spell (player *pl, packet &sl, object *spell) |
1264 | { |
1239 | { |
1265 | int i, skill = 0; |
1240 | int skill = 0; |
1266 | |
1241 | |
1267 | if (!(spell->name)) |
1242 | if (!(spell->name)) |
1268 | { |
1243 | { |
1269 | 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); |
1270 | return; |
1245 | return; |