1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel |
5 | * Copyright (©) 2001,2007 Mark Wedel |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your 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, |
… | |
… | |
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 GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /** |
24 | /** |
25 | * \file |
25 | * \file |
26 | * Client handling. |
26 | * Client handling. |
… | |
… | |
148 | check_map_change (player *pl) |
148 | check_map_change (player *pl) |
149 | { |
149 | { |
150 | client &socket = *pl->ns; |
150 | client &socket = *pl->ns; |
151 | object *ob = pl->observe; |
151 | object *ob = pl->observe; |
152 | |
152 | |
|
|
153 | // first try to aovid a full newmap on tiled map scrolls |
|
|
154 | if (socket.current_map != ob->map) |
|
|
155 | { |
|
|
156 | rv_vector rv; |
|
|
157 | |
|
|
158 | get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); |
|
|
159 | |
|
|
160 | // manhattan distance is very handy here |
|
|
161 | if (rv.distance < 8) // 8 works nicely for speed << 70 and buggy gcfclient |
|
|
162 | { |
|
|
163 | socket.current_map = ob->map; |
|
|
164 | socket.current_x = ob->x; |
|
|
165 | socket.current_y = ob->y; |
|
|
166 | |
|
|
167 | socket_map_scroll (&socket, rv.distance_x, rv.distance_y); |
|
|
168 | socket.floorbox_reset (); |
|
|
169 | } |
|
|
170 | } |
|
|
171 | |
153 | if (socket.current_map != ob->map || socket.force_newmap) |
172 | if (socket.current_map != ob->map || socket.force_newmap) |
154 | { |
173 | { |
155 | clear_map (pl); |
174 | clear_map (pl); |
156 | socket.current_map = ob->map; |
175 | socket.current_map = ob->map; |
157 | |
176 | |
… | |
… | |
263 | { |
282 | { |
264 | char *token = buf; |
283 | char *token = buf; |
265 | buf += strlen (buf) + 9; |
284 | buf += strlen (buf) + 9; |
266 | |
285 | |
267 | // initial map and its origin |
286 | // initial map and its origin |
268 | maptile *map = pl->ob->map; |
287 | maptile *map = pl->observe->map; |
269 | int mapx = pl->ns->mapx / 2 - pl->ob->x; |
288 | int mapx = pl->ns->mapx / 2 - pl->observe->x; |
270 | int mapy = pl->ns->mapy / 2 - pl->ob->y; |
289 | int mapy = pl->ns->mapy / 2 - pl->observe->y; |
271 | int max_distance = 8; // limit maximum path length to something generous |
290 | int max_distance = 8; // limit maximum path length to something generous |
272 | |
291 | |
273 | while (*buf && map && max_distance) |
292 | while (*buf && map && max_distance) |
274 | { |
293 | { |
275 | int dir = *buf++ - '1'; |
294 | int dir = *buf++ - '1'; |
… | |
… | |
686 | * syntax is: move (to) (tag) (nrof) |
705 | * syntax is: move (to) (tag) (nrof) |
687 | */ |
706 | */ |
688 | void |
707 | void |
689 | MoveCmd (char *buf, int len, player *pl) |
708 | MoveCmd (char *buf, int len, player *pl) |
690 | { |
709 | { |
691 | int vals[3], i; |
710 | int to, tag, nrof; |
692 | |
711 | |
693 | /* A little funky here. We only cycle for 2 records, because |
712 | if (3 != sscanf (buf, "%d %d %d", &to, &tag, &nrof)) |
694 | * we obviously are not going to find a space after the third |
|
|
695 | * record. Perhaps we should just replace this with a |
|
|
696 | * sscanf? |
|
|
697 | */ |
|
|
698 | for (i = 0; i < 2; i++) |
|
|
699 | { |
713 | { |
700 | vals[i] = atoi (buf); |
|
|
701 | |
|
|
702 | if (!(buf = strchr (buf, ' '))) |
|
|
703 | { |
|
|
704 | LOG (llevError, "Incomplete move command: %s\n", buf); |
714 | LOG (llevError, "Incomplete move command: %s\n", buf); |
705 | return; |
715 | return; |
706 | } |
|
|
707 | |
|
|
708 | buf++; |
|
|
709 | } |
716 | } |
710 | |
717 | |
711 | vals[2] = atoi (buf); |
718 | esrv_move_object (pl->ob, to, tag, nrof); |
712 | |
|
|
713 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
|
|
714 | esrv_move_object (pl->ob, vals[0], vals[1], vals[2]); |
|
|
715 | } |
719 | } |
716 | |
720 | |
717 | /****************************************************************************** |
721 | /****************************************************************************** |
718 | * |
722 | * |
719 | * Start of commands the server sends to the client. |
723 | * Start of commands the server sends to the client. |
… | |
… | |
886 | |
890 | |
887 | /** |
891 | /** |
888 | * Tells the client that here is a player it should start using. |
892 | * Tells the client that here is a player it should start using. |
889 | */ |
893 | */ |
890 | void |
894 | void |
891 | esrv_new_player (player *pl, uint32 weight) |
895 | esrv_new_player (player *pl) |
892 | { |
896 | { |
|
|
897 | sint32 weight = pl->ob->client_weight (); |
|
|
898 | |
893 | packet sl ("player"); |
899 | packet sl ("player"); |
894 | |
900 | |
895 | sl << uint32 (pl->ob->count) |
901 | sl << uint32 (pl->ob->count) |
896 | << uint32 (weight) |
902 | << uint32 (weight) |
897 | << uint32 (pl->ob->face) |
903 | << uint32 (pl->ob->face) |
… | |
… | |
1031 | |
1037 | |
1032 | /* If player is just joining the game, he isn't here yet, so the map |
1038 | /* If player is just joining the game, he isn't here yet, so the map |
1033 | * can get swapped out. If so, don't try to send them a map. All will |
1039 | * can get swapped out. If so, don't try to send them a map. All will |
1034 | * be OK once they really log in. |
1040 | * be OK once they really log in. |
1035 | */ |
1041 | */ |
1036 | if (!plmap || plmap->in_memory != MAP_IN_MEMORY) |
1042 | if (!plmap || plmap->in_memory != MAP_ACTIVE) |
1037 | return; |
1043 | return; |
1038 | |
1044 | |
1039 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1045 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1040 | int estartlen, eoldlen; |
1046 | int estartlen, eoldlen; |
1041 | uint8 eentrysize; |
1047 | uint8 eentrysize; |
… | |
… | |
1129 | |
1135 | |
1130 | if (!m) |
1136 | if (!m) |
1131 | { |
1137 | { |
1132 | nx = x; ny = y; m = plmap; |
1138 | nx = x; ny = y; m = plmap; |
1133 | |
1139 | |
1134 | if (!xy_normalise (m, nx, ny)) |
1140 | if (xy_normalise (m, nx, ny)) |
|
|
1141 | m->touch (); |
|
|
1142 | else |
1135 | m = 0; |
1143 | m = 0; |
1136 | } |
1144 | } |
1137 | |
1145 | |
1138 | int emask, mask; |
1146 | int emask, mask; |
1139 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1147 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
… | |
… | |
1156 | } |
1164 | } |
1157 | |
1165 | |
1158 | continue; |
1166 | continue; |
1159 | } |
1167 | } |
1160 | |
1168 | |
1161 | m->touch (); |
|
|
1162 | |
|
|
1163 | int d = pl->blocked_los[ax][ay]; |
1169 | int d = pl->blocked_los[ax][ay]; |
1164 | |
1170 | |
1165 | if (d > 3) |
1171 | if (d > 3) |
1166 | { |
1172 | { |
1167 | |
1173 | |
… | |
… | |
1242 | uint8 flags = 0; |
1248 | uint8 flags = 0; |
1243 | tag_t player = 0; |
1249 | tag_t player = 0; |
1244 | |
1250 | |
1245 | // send hp information, if applicable |
1251 | // send hp information, if applicable |
1246 | if (object *op = ms.faces_obj [0]) |
1252 | if (object *op = ms.faces_obj [0]) |
|
|
1253 | if (op->is_head () && !op->invisible) |
1247 | { |
1254 | { |
1248 | if (op->head || op->invisible) |
1255 | if (op->stats.maxhp > op->stats.hp |
1249 | ; // do not show |
1256 | && op->stats.maxhp > 0 |
1250 | else if (op->type == PLAYER |
1257 | && (op->type == PLAYER |
|
|
1258 | || op->type == DOOR // does not work, have maxhp 0 |
1251 | || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) |
1259 | || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR))) |
1252 | { |
|
|
1253 | if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp) |
|
|
1254 | { |
1260 | { |
1255 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1261 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1256 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1262 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1257 | } |
1263 | } |
1258 | } |
|
|
1259 | |
1264 | |
1260 | if (op->msg && op->msg[0] == '@') |
1265 | if (op->msg && op->msg[0] == '@') |
1261 | flags |= 1; |
1266 | flags |= 1; |
1262 | |
1267 | |
1263 | if (op->type == PLAYER && op != ob) |
1268 | if (op->type == PLAYER && op != ob) |
1264 | player = op->count; |
1269 | player = op->count; |
1265 | } |
1270 | } |
1266 | |
1271 | |
1267 | if (lastcell.stat_hp != stat_hp) |
1272 | if (lastcell.stat_hp != stat_hp) |
1268 | { |
1273 | { |
1269 | lastcell.stat_hp = stat_hp; |
1274 | lastcell.stat_hp = stat_hp; |
1270 | |
1275 | |