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 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 |
… | |
… | |
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 | |
158 | static void |
155 | static void |
159 | send_map_info (player *pl) |
156 | send_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 | } |
… | |
… | |
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 (dir >= 0 && dir < 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; |
… | |
… | |
878 | return 0; |
889 | return 0; |
879 | } |
890 | } |
880 | |
891 | |
881 | //-GPL |
892 | //-GPL |
882 | |
893 | |
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 |
894 | // prefetch some flat area around the player |
887 | static void |
895 | static void |
888 | prefetch_surrounding_maps (object *op) |
896 | prefetch_surrounding_area (object *op, maptile *map, int range) |
889 | { |
897 | { |
890 | for (maprect *rect = op->map->split_to_tiles (mapwalk_buf, |
898 | for (maprect *rect = map->split_to_tiles (mapwalk_buf, |
891 | op->x - PREFETCH , op->y - PREFETCH , |
899 | op->x - range , op->y - range , |
892 | op->x + PREFETCH + 1, op->y + PREFETCH + 1); |
900 | op->x + range + 1, op->y + range + 1); |
893 | rect->m; |
901 | rect->m; |
894 | ++rect) |
902 | ++rect) |
|
|
903 | { |
895 | rect->m->touch (); |
904 | rect->m->touch (); |
|
|
905 | rect->m->activate (); |
|
|
906 | } |
|
|
907 | } |
|
|
908 | |
|
|
909 | // prefetch a generous area around the player, also up and down |
|
|
910 | void |
|
|
911 | object::prefetch_surrounding_maps () |
|
|
912 | { |
|
|
913 | prefetch_surrounding_area (this, map, 40); |
|
|
914 | |
|
|
915 | if (maptile *m = map->tile_available (TILE_DOWN)) |
|
|
916 | prefetch_surrounding_area (this, m, 20); |
|
|
917 | |
|
|
918 | if (maptile *m = map->tile_available (TILE_UP)) |
|
|
919 | prefetch_surrounding_area (this, m, 20); |
896 | } |
920 | } |
897 | |
921 | |
898 | //+GPL |
922 | //+GPL |
899 | |
923 | |
900 | /** |
924 | /** |
… | |
… | |
909 | |
933 | |
910 | /* If player is just joining the game, he isn't here yet, so the map |
934 | /* 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 |
935 | * can get swapped out. If so, don't try to send them a map. All will |
912 | * be OK once they really log in. |
936 | * be OK once they really log in. |
913 | */ |
937 | */ |
914 | if (!ob->map || ob->map->in_memory != MAP_ACTIVE) |
938 | if (!ob->map || ob->map->state != MAP_ACTIVE) |
915 | return; |
939 | return; |
916 | |
940 | |
917 | int startlen, oldlen; |
941 | int startlen, oldlen; |
918 | |
942 | |
919 | check_map_change (pl); |
943 | check_map_change (pl); |
920 | prefetch_surrounding_maps (pl->ob); |
944 | pl->ob->prefetch_surrounding_maps (); |
921 | |
945 | |
922 | /* do LOS after calls to update_position */ |
946 | /* do LOS after calls to update_position */ |
923 | /* unfortunately, we need to udpate los when observing, currently */ |
947 | /* unfortunately, we need to udpate los when observing, currently */ |
924 | if (pl->do_los || pl->viewpoint != pl->ob) |
948 | if (pl->do_los || pl->viewpoint != pl->ob) |
925 | { |
949 | { |
… | |
… | |
950 | * look like. |
974 | * look like. |
951 | */ |
975 | */ |
952 | |
976 | |
953 | client &socket = *pl->ns; |
977 | client &socket = *pl->ns; |
954 | |
978 | |
955 | packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); |
979 | packet sl ("map1a"); |
956 | |
980 | |
957 | startlen = sl.length (); |
981 | startlen = sl.length (); |
958 | |
982 | |
959 | int hx = socket.mapx / 2; |
983 | int hx = socket.mapx / 2; |
960 | int hy = socket.mapy / 2; |
984 | int hy = socket.mapy / 2; |