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.128 by root, Tue May 6 16:55:26 2008 UTC vs.
Revision 1.146 by root, Sat Dec 27 01:25:00 2008 UTC

98 */ 98 */
99 mx = ns->mapx; 99 mx = ns->mapx;
100 my = ns->mapy; 100 my = ns->mapy;
101 101
102 /* the x and y here are coordinates for the new map, i.e. if we moved 102 /* the x and y here are coordinates for the new map, i.e. if we moved
103 * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, 103 * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason,
104 * if the destination x or y coordinate is outside the viewable 104 * if the destination x or y coordinate is outside the viewable
105 * area, we clear the values - otherwise, the old values 105 * area, we clear the values - otherwise, the old values
106 * are preserved, and the check_head thinks it needs to clear them. 106 * are preserved, and the check_head thinks it needs to clear them.
107 */ 107 */
108 for (x = 0; x < mx; x++) 108 for (x = 0; x < mx; x++)
109 {
110 for (y = 0; y < my; y++) 109 for (y = 0; y < my; y++)
111 {
112 if (x >= ns->mapx || y >= ns->mapy) 110 if (x >= ns->mapx || y >= ns->mapy)
113 /* clear cells outside the viewable area */ 111 /* clear cells outside the viewable area */
114 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); 112 memset (&newmap.cells[x][y], 0, sizeof (struct MapCell));
115 else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) 113 else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy)
116 /* clear newly visible tiles within the viewable area */ 114 /* clear newly visible tiles within the viewable area */
117 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); 115 memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell));
118 else 116 else
119 memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); 117 memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell));
120 }
121 }
122 118
123 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); 119 memcpy (&(ns->lastmap), &newmap, sizeof (struct Map));
124 120
125 /* Make sure that the next "map1" command will be sent (even if it is 121 /* Make sure that the next "map1" command will be sent (even if it is
126 * empty). 122 * empty).
141 pl->ns->send_packet ("newmap"); 137 pl->ns->send_packet ("newmap");
142 138
143 pl->ns->floorbox_reset (); 139 pl->ns->floorbox_reset ();
144} 140}
145 141
142static void
143send_map_info (player *pl)
144{
145 client &socket = *pl->ns;
146 object *ob = pl->observe;
147
148 if (socket.mapinfocmd)
149 {
150 if (ob->map && ob->map->path[0])
151 {
152 int flags = 0;
153
154 if (ob->map->tile_path[0]) flags |= 1;
155 if (ob->map->tile_path[1]) flags |= 2;
156 if (ob->map->tile_path[2]) flags |= 4;
157 if (ob->map->tile_path[3]) flags |= 8;
158
159 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
160 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
161 ob->map->width, ob->map->height, &ob->map->path);
162 }
163 else
164 socket.send_packet ("mapinfo current");
165 }
166}
167
146/** check for map/region change and send new map data */ 168/** check for map/region change and send new map data */
147static void 169static void
148check_map_change (player *pl) 170check_map_change (player *pl)
149{ 171{
150 client &socket = *pl->ns; 172 client &socket = *pl->ns;
151 object *ob = pl->observe; 173 object *ob = pl->observe;
152 174
175 region *reg = ob->region ();
176 if (socket.current_region != reg)
177 {
178 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
179 socket.current_region = reg;
180 }
181
182 // first try to aovid a full newmap on tiled map scrolls
183 if (socket.current_map != ob->map && !socket.force_newmap)
184 {
185 rv_vector rv;
186
187 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0);
188
189 // manhattan distance is very handy here
190 if (rv.distance < 8) // 8 works nicely for speed << 70 and buggy gcfclient
191 {
192 socket.current_map = ob->map;
193 socket.current_x = ob->x;
194 socket.current_y = ob->y;
195
196 socket_map_scroll (&socket, rv.distance_x, rv.distance_y);
197 socket.floorbox_reset ();
198 send_map_info (pl);
199 }
200 }
201
153 if (socket.current_map != ob->map || socket.force_newmap) 202 if (socket.current_map != ob->map || socket.force_newmap)
154 { 203 {
155 clear_map (pl); 204 clear_map (pl);
156 socket.current_map = ob->map; 205 socket.current_map = ob->map;
157 206 send_map_info (pl);
158 if (socket.mapinfocmd)
159 {
160 if (ob->map && ob->map->path[0])
161 {
162 int flags = 0;
163
164 if (ob->map->tile_path[0]) flags |= 1;
165 if (ob->map->tile_path[1]) flags |= 2;
166 if (ob->map->tile_path[2]) flags |= 4;
167 if (ob->map->tile_path[3]) flags |= 8;
168
169 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
170 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
171 ob->map->width, ob->map->height, &ob->map->path);
172 }
173 else
174 socket.send_packet ("mapinfo current");
175 }
176 } 207 }
177 else if (socket.current_x != ob->x || socket.current_y != ob->y) 208 else if (socket.current_x != ob->x || socket.current_y != ob->y)
178 { 209 {
179 int dx = ob->x - socket.current_x; 210 int dx = ob->x - socket.current_x;
180 int dy = ob->y - socket.current_y; 211 int dy = ob->y - socket.current_y;
181 212
182 if (socket.buggy_mapscroll && (abs (dx) > 8 || abs (dy) > 8))
183 clear_map (pl); // current (<= 1.9.1) clients have unchecked buffer overflows
184 else
185 {
186 socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); 213 socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y);
187 socket.floorbox_reset (); 214 socket.floorbox_reset ();
188 }
189 } 215 }
190 216
191 socket.current_x = ob->x; 217 socket.current_x = ob->x;
192 socket.current_y = ob->y; 218 socket.current_y = ob->y;
193
194 region *reg = ob->region ();
195 if (socket.current_region != reg)
196 {
197 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
198 socket.current_region = reg;
199 }
200} 219}
201 220
202/** 221/**
203 * RequestInfo is sort of a meta command. There is some specific 222 * RequestInfo is sort of a meta command. There is some specific
204 * request of information, but we call other functions to provide 223 * request of information, but we call other functions to provide
380AddMeCmd (char *buf, int len, client *ns) 399AddMeCmd (char *buf, int len, client *ns)
381{ 400{
382 INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); 401 INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len));
383} 402}
384 403
385/** Reply to ExtendedInfos command */
386void
387ToggleExtendedInfos (char *buf, int len, client * ns)
388{
389 char cmdback[MAX_BUF];
390 char command[50];
391 int info, nextinfo;
392
393 cmdback[0] = '\0';
394 nextinfo = 0;
395
396 while (1)
397 {
398 /* 1. Extract an info */
399 info = nextinfo;
400
401 while ((info < len) && (buf[info] == ' '))
402 info++;
403
404 if (info >= len)
405 break;
406
407 nextinfo = info + 1;
408
409 while ((nextinfo < len) && (buf[nextinfo] != ' '))
410 nextinfo++;
411
412 if (nextinfo - info >= 49) /*Erroneous info asked */
413 continue;
414
415 strncpy (command, &(buf[info]), nextinfo - info);
416
417 /* 2. Interpret info */
418 if (!strcmp ("smooth", command))
419 /* Toggle smoothing */
420 ns->EMI_smooth = !ns->EMI_smooth;
421 else
422 /*bad value */;
423
424 /*3. Next info */
425 }
426
427 strcpy (cmdback, "ExtendedInfoSet");
428
429 if (ns->EMI_smooth)
430 {
431 strcat (cmdback, " ");
432 strcat (cmdback, "smoothing");
433 }
434
435 ns->send_packet (cmdback);
436}
437
438/* 404/*
439#define MSG_TYPE_BOOK 1 405#define MSG_TYPE_BOOK 1
440#define MSG_TYPE_CARD 2 406#define MSG_TYPE_CARD 2
441#define MSG_TYPE_PAPER 3 407#define MSG_TYPE_PAPER 3
442#define MSG_TYPE_SIGN 4 408#define MSG_TYPE_SIGN 4
686 * syntax is: move (to) (tag) (nrof) 652 * syntax is: move (to) (tag) (nrof)
687 */ 653 */
688void 654void
689MoveCmd (char *buf, int len, player *pl) 655MoveCmd (char *buf, int len, player *pl)
690{ 656{
691 int vals[3], i; 657 int to, tag, nrof;
692 658
693 /* A little funky here. We only cycle for 2 records, because 659 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 { 660 {
700 vals[i] = atoi (buf);
701
702 if (!(buf = strchr (buf, ' ')))
703 {
704 LOG (llevError, "Incomplete move command: %s\n", buf); 661 LOG (llevError, "Incomplete move command: %s\n", buf);
705 return; 662 return;
706 }
707
708 buf++;
709 } 663 }
710 664
711 vals[2] = atoi (buf); 665 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} 666}
716 667
717/****************************************************************************** 668/******************************************************************************
718 * 669 *
719 * Start of commands the server sends to the client. 670 * Start of commands the server sends to the client.
820 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 771 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
821 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 772 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
822 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 773 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
823 774
824 for (int s = 0; s < NUM_SKILLS; s++) 775 for (int s = 0; s < NUM_SKILLS; s++)
825 if (object *skill = opl->last_skill_ob[s]) 776 if (object *skill = opl->last_skill_ob [s])
826 if (skill->stats.exp != ns->last_skill_exp [s]) 777 if (skill->stats.exp != ns->last_skill_exp [s])
827 { 778 {
828 ns->last_skill_exp [s] = skill->stats.exp; 779 ns->last_skill_exp [s] = skill->stats.exp;
829 780
830 /* Always send along the level if exp changes. This is only 781 /* Always send along the level if exp changes. This is only
899 << uint32 (pl->ob->face) 850 << uint32 (pl->ob->face)
900 << data8 (pl->ob->name); 851 << data8 (pl->ob->name);
901 852
902 pl->ns->last_weight = weight; 853 pl->ns->last_weight = weight;
903 pl->ns->send_packet (sl); 854 pl->ns->send_packet (sl);
904 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
905} 855}
906 856
907/****************************************************************************** 857/******************************************************************************
908 * 858 *
909 * Start of map related commands. 859 * Start of map related commands.
976 926
977 /* Nothing changed */ 927 /* Nothing changed */
978 return 0; 928 return 0;
979} 929}
980 930
981/**
982 * Returns the size of a data for a map square as returned by
983 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
984 * available.
985 */
986int
987getExtendedMapInfoSize (client * ns)
988{
989 int result = 0;
990
991 if (ns->ext_mapinfos)
992 {
993 if (ns->EMI_smooth)
994 result += 1; /*One byte for smoothlevel */
995 }
996
997 return result;
998}
999
1000// prefetch (and touch) all maps within a specific distancd 931// prefetch (and touch) all maps within a specific distancd
1001static void 932static void
1002prefetch_surrounding_maps (maptile *map, int distance) 933prefetch_surrounding_maps (maptile *map, int distance)
1003{ 934{
1004 map->last_access = runtime; 935 map->last_access = runtime;
1027{ 958{
1028 object *ob = pl->observe; 959 object *ob = pl->observe;
1029 if (!ob->active) 960 if (!ob->active)
1030 return; 961 return;
1031 962
1032 maptile *plmap = ob->map;
1033
1034 /* If player is just joining the game, he isn't here yet, so the map 963 /* If player is just joining the game, he isn't here yet, so the map
1035 * can get swapped out. If so, don't try to send them a map. All will 964 * can get swapped out. If so, don't try to send them a map. All will
1036 * be OK once they really log in. 965 * be OK once they really log in.
1037 */ 966 */
1038 if (!plmap || plmap->in_memory != MAP_ACTIVE) 967 if (!ob->map || ob->map->in_memory != MAP_ACTIVE)
1039 return; 968 return;
1040 969
1041 int x, y, ax, ay, startlen, max_x, max_y, oldlen;
1042 int estartlen, eoldlen; 970 int startlen, oldlen;
1043 uint8 eentrysize;
1044 uint16 ewhatstart, ewhatflag;
1045 uint8 extendedinfos;
1046 971
1047 check_map_change (pl); 972 check_map_change (pl);
1048 prefetch_surrounding_maps (pl->ob); 973 prefetch_surrounding_maps (pl->ob);
1049 974
1050 /* do LOS after calls to update_position */ 975 /* do LOS after calls to update_position */
1051 if (ob != pl->ob) 976 /* unfortunately, we need to udpate los when observing, currently */
1052 clear_los (pl); 977 if (pl->do_los || pl->observe != pl->ob)
1053 else if (pl->do_los)
1054 { 978 {
1055 update_los (ob);
1056 pl->do_los = 0; 979 pl->do_los = 0;
980 pl->update_los ();
1057 } 981 }
1058 982
1059 /** 983 /**
1060 * This function uses the new map1 protocol command to send the map 984 * This function uses the new map1 protocol command to send the map
1061 * to the client. It is necessary because the old map command supports 985 * to the client. It is necessary because the old map command supports
1080 */ 1004 */
1081 1005
1082 client &socket = *pl->ns; 1006 client &socket = *pl->ns;
1083 1007
1084 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 1008 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a");
1085 packet esl;
1086 1009
1087 startlen = sl.length (); 1010 startlen = sl.length ();
1088 1011
1089 /*Extendedmapinfo structure initialisation */ 1012 int hx = socket.mapx / 2;
1090 if (socket.ext_mapinfos) 1013 int hy = socket.mapy / 2;
1091 {
1092 extendedinfos = EMI_NOREDRAW;
1093 1014
1094 if (socket.EMI_smooth) 1015 ordered_mapwalk_begin (ob, -hx, -hy, hx, hy)
1095 extendedinfos |= EMI_SMOOTH; 1016 int ax = dx + hx;
1017 int ay = dy + hy;
1096 1018
1097 ewhatstart = esl.length (); 1019 int mask = (ax << 10) | (ay << 4);
1098 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1099 could need to be taken away */
1100 eentrysize = getExtendedMapInfoSize (&socket);
1101 esl << "mapextended "
1102 << uint8 (extendedinfos)
1103 << uint8 (eentrysize);
1104
1105 estartlen = esl.length ();
1106 }
1107
1108 /* x,y are the real map locations. ax, ay are viewport relative
1109 * locations.
1110 */
1111 ay = 0;
1112
1113 /* We could do this logic as conditionals in the if statement,
1114 * but that started to get a bit messy to look at.
1115 */
1116 max_x = ob->x + (socket.mapx + 1) / 2;
1117 max_y = ob->y + (socket.mapy + 1) / 2;
1118
1119 for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++)
1120 {
1121 sint16 nx, ny;
1122 maptile *m = 0;
1123
1124 ax = 0;
1125 for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++)
1126 {
1127 // check to see if we can simply go one right quickly
1128 ++nx;
1129 if (m && nx >= m->width)
1130 m = 0;
1131
1132 if (!m)
1133 {
1134 nx = x; ny = y; m = plmap;
1135
1136 if (xy_normalise (m, nx, ny))
1137 m->touch ();
1138 else
1139 m = 0;
1140 }
1141
1142 int emask, mask;
1143 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1144
1145 MapCell &lastcell = socket.lastmap.cells[ax][ay]; 1020 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1146 1021
1147 /* If the coordinates are not valid, or it is too dark to see, 1022 /* If the coordinates are not valid, or it is too dark to see,
1148 * we tell the client as such 1023 * we tell the client as such
1149 */ 1024 */
1150 if (!m) 1025 if (!m)
1151 { 1026 {
1152 /* space is out of map. Update space and clear values 1027 /* space is out of map. Update space and clear values
1153 * if this hasn't already been done. If the space is out 1028 * if this hasn't already been done. If the space is out
1154 * of the map, it shouldn't have a head 1029 * of the map, it shouldn't have a head.
1155 */ 1030 */
1156 if (lastcell.count != -1) 1031 if (lastcell.count != -1)
1032 {
1033 sl << uint16 (mask);
1034 map_clearcell (&lastcell, -1);
1035 }
1036
1037 continue;
1038 }
1039
1040 int d = pl->blocked_los_uc (dx, dy);
1041
1042 if (d > 3)
1043 {
1044 /* This block deals with spaces that are not visible for whatever
1045 * reason. Still may need to send the head for this space.
1046 */
1047 if (lastcell.count != -1
1048 || lastcell.faces[0]
1049 || lastcell.faces[1]
1050 || lastcell.faces[2]
1051 || lastcell.stat_hp
1052 || lastcell.flags
1053 || lastcell.player)
1054 sl << uint16 (mask);
1055
1056 /* properly clear a previously sent big face */
1057 map_clearcell (&lastcell, -1);
1058 }
1059 else
1060 {
1061 /* In this block, the space is visible.
1062 */
1063
1064 /* Rather than try to figure out what everything that we might
1065 * need to send is, then form the packet after that,
1066 * we presume that we will in fact form a packet, and update
1067 * the bits by what we do actually send. If we send nothing,
1068 * we just back out sl.length () to the old value, and no harm
1069 * is done.
1070 * I think this is simpler than doing a bunch of checks to see
1071 * what if anything we need to send, setting the bits, then
1072 * doing those checks again to add the real data.
1073 */
1074 oldlen = sl.length ();
1075
1076 sl << uint16 (mask);
1077
1078 unsigned char dummy;
1079 unsigned char *last_ext = &dummy;
1080
1081 /* Darkness changed */
1082 if (lastcell.count != d)
1083 {
1084 mask |= 0x8;
1085
1086 if (socket.extmap)
1087 {
1088 *last_ext |= 0x80;
1089 last_ext = &sl[sl.length ()];
1090 sl << uint8 (d);
1091 }
1092 else
1093 sl << uint8 (255 - 64 * d);
1094 }
1095
1096 lastcell.count = d;
1097
1098 mapspace &ms = m->at (nx, ny);
1099 ms.update ();
1100
1101 if (expect_true (socket.extmap))
1102 {
1103 uint8 stat_hp = 0;
1104 uint8 stat_width = 0;
1105 uint8 flags = 0;
1106 tag_t player = 0;
1107
1108 // send hp information, if applicable
1109 if (object *op = ms.faces_obj [0])
1110 if (op->is_head () && !op->invisible)
1157 { 1111 {
1158 sl << uint16 (mask); 1112 if (op->stats.maxhp > op->stats.hp
1159 map_clearcell (&lastcell, -1); 1113 && op->stats.maxhp > 0
1114 && (op->type == PLAYER
1115 || op->type == DOOR // does not work, have maxhp 0
1116 || QUERY_FLAG (op, FLAG_MONSTER)
1117 || QUERY_FLAG (op, FLAG_ALIVE)
1118 || QUERY_FLAG (op, FLAG_GENERATOR)))
1119 {
1120 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1121 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1122 }
1123
1124 if (expect_false (op->has_dialogue ()))
1125 flags |= 1;
1126
1127 if (expect_false (op->type == PLAYER))
1128 player = op == ob ? pl->ob->count
1129 : op == pl->ob ? ob->count
1130 : op->count;
1160 } 1131 }
1161 1132
1162 continue; 1133 if (expect_false (lastcell.stat_hp != stat_hp))
1163 }
1164
1165 int d = pl->blocked_los[ax][ay];
1166
1167 if (d > 3)
1168 {
1169
1170 int need_send = 0, count;
1171
1172 /* This block deals with spaces that are not visible for whatever
1173 * reason. Still may need to send the head for this space.
1174 */
1175
1176 oldlen = sl.length ();
1177
1178 sl << uint16 (mask);
1179
1180 if (lastcell.count != -1)
1181 need_send = 1;
1182
1183 count = -1;
1184
1185 /* properly clear a previously sent big face */
1186 if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2]
1187 || lastcell.stat_hp || lastcell.flags || lastcell.player)
1188 need_send = 1;
1189
1190 map_clearcell (&lastcell, count);
1191
1192 if ((mask & 0xf) || need_send)
1193 sl[oldlen + 1] = mask & 0xff;
1194 else
1195 sl.reset (oldlen);
1196 }
1197 else
1198 {
1199 /* In this block, the space is visible.
1200 */
1201
1202 /* Rather than try to figure out what everything that we might
1203 * need to send is, then form the packet after that,
1204 * we presume that we will in fact form a packet, and update
1205 * the bits by what we do actually send. If we send nothing,
1206 * we just back out sl.length () to the old value, and no harm
1207 * is done.
1208 * I think this is simpler than doing a bunch of checks to see
1209 * what if anything we need to send, setting the bits, then
1210 * doing those checks again to add the real data.
1211 */
1212 oldlen = sl.length ();
1213 eoldlen = esl.length ();
1214
1215 sl << uint16 (mask);
1216
1217 unsigned char dummy;
1218 unsigned char *last_ext = &dummy;
1219
1220 /* Darkness changed */
1221 if (lastcell.count != d && socket.darkness)
1222 { 1134 {
1135 lastcell.stat_hp = stat_hp;
1136
1223 mask |= 0x8; 1137 mask |= 0x8;
1138 *last_ext |= 0x80;
1139 last_ext = &sl[sl.length ()];
1224 1140
1225 if (socket.extmap) 1141 sl << uint8 (5) << uint8 (stat_hp);
1142
1143 if (stat_width > 1)
1226 { 1144 {
1227 *last_ext |= 0x80; 1145 *last_ext |= 0x80;
1228 last_ext = &sl[sl.length ()]; 1146 last_ext = &sl[sl.length ()];
1229 sl << uint8 (d);
1230 }
1231 else
1232 sl << uint8 (255 - 64 * d);
1233 }
1234 1147
1235 lastcell.count = d;
1236
1237 mapspace &ms = m->at (nx, ny);
1238 ms.update ();
1239
1240 if (socket.extmap)
1241 {
1242 uint8 stat_hp = 0;
1243 uint8 stat_width = 0;
1244 uint8 flags = 0;
1245 tag_t player = 0;
1246
1247 // send hp information, if applicable
1248 if (object *op = ms.faces_obj [0])
1249 if (op->is_head () && !op->invisible)
1250 {
1251 if (op->stats.maxhp > op->stats.hp
1252 && op->stats.maxhp > 0
1253 && (op->type == PLAYER
1254 || op->type == DOOR // does not work, have maxhp 0
1255 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)))
1256 {
1257 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1258 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1259 }
1260
1261 if (op->msg && op->msg[0] == '@')
1262 flags |= 1;
1263
1264 if (op->type == PLAYER && op != ob)
1265 player = op->count;
1266 }
1267
1268 if (lastcell.stat_hp != stat_hp)
1269 {
1270 lastcell.stat_hp = stat_hp;
1271
1272 mask |= 0x8;
1273 *last_ext |= 0x80;
1274 last_ext = &sl[sl.length ()];
1275
1276 sl << uint8 (5) << uint8 (stat_hp);
1277
1278 if (stat_width > 1)
1279 {
1280 *last_ext |= 0x80;
1281 last_ext = &sl[sl.length ()];
1282
1283 sl << uint8 (6) << uint8 (stat_width); 1148 sl << uint8 (6) << uint8 (stat_width);
1284 }
1285 } 1149 }
1286
1287 if (lastcell.player != player)
1288 {
1289 lastcell.player = player;
1290
1291 mask |= 0x8;
1292 *last_ext |= 0x80;
1293 last_ext = &sl[sl.length ()];
1294
1295 sl << uint8 (0x47) << uint8 (4) << (uint32)player;
1296 }
1297
1298 if (lastcell.flags != flags)
1299 {
1300 lastcell.flags = flags;
1301
1302 mask |= 0x8;
1303 *last_ext |= 0x80;
1304 last_ext = &sl[sl.length ()];
1305
1306 sl << uint8 (8) << uint8 (flags);
1307 }
1308 } 1150 }
1309 1151
1310 /* Floor face */ 1152 if (expect_false (lastcell.player != player))
1311 if (update_space (sl, socket, ms, lastcell, 2)) 1153 {
1154 lastcell.player = player;
1155
1312 mask |= 0x4; 1156 mask |= 0x8;
1157 *last_ext |= 0x80;
1158 last_ext = &sl[sl.length ()];
1313 1159
1314 /* Middle face */ 1160 sl << uint8 (0x47) << uint8 (4) << (uint32)player;
1315 if (update_space (sl, socket, ms, lastcell, 1)) 1161 }
1162
1163 if (expect_false (lastcell.flags != flags))
1164 {
1165 lastcell.flags = flags;
1166
1316 mask |= 0x2; 1167 mask |= 0x8;
1168 *last_ext |= 0x80;
1169 last_ext = &sl[sl.length ()];
1317 1170
1318 if (ms.player () == ob 1171 sl << uint8 (8) << uint8 (flags);
1319 && (ob->invisible & (ob->invisible < 50 ? 1 : 7)))
1320 { 1172 }
1173 }
1174
1175 /* Floor face */
1176 if (update_space (sl, socket, ms, lastcell, 2))
1177 mask |= 0x4;
1178
1179 /* Middle face */
1180 if (update_space (sl, socket, ms, lastcell, 1))
1181 mask |= 0x2;
1182
1183 if (expect_false (ob->invisible)
1184 && ob->invisible & (ob->invisible < 50 ? 1 : 7)
1185 && ms.player () == ob)
1186 {
1321 // force player to be visible to himself if invisible 1187 // force player to be visible to himself if invisible
1322 if (lastcell.faces[0] != ob->face) 1188 if (lastcell.faces[0] != ob->face)
1323 { 1189 {
1324 lastcell.faces[0] = ob->face; 1190 lastcell.faces[0] = ob->face;
1325 1191
1326 mask |= 0x1;
1327 sl << uint16 (ob->face);
1328
1329 socket.send_faces (ob);
1330 }
1331 }
1332 /* Top face */
1333 else if (update_space (sl, socket, ms, lastcell, 0))
1334 mask |= 0x1; 1192 mask |= 0x1;
1193 sl << uint16 (ob->face);
1335 1194
1195 socket.send_faces (ob);
1196 }
1197 }
1198 /* Top face */
1199 else if (update_space (sl, socket, ms, lastcell, 0))
1200 mask |= 0x1;
1201
1336 /* Check to see if we are in fact sending anything for this 1202 /* Check to see if we are in fact sending anything for this
1337 * space by checking the mask. If so, update the mask. 1203 * space by checking the mask. If so, update the mask.
1338 * if not, reset the len to that from before adding the mask 1204 * if not, reset the len to that from before adding the mask
1339 * value, so we don't send those bits. 1205 * value, so we don't send those bits.
1340 */ 1206 */
1341 if (mask & 0xf) 1207 if (mask & 0xf)
1342 sl[oldlen + 1] = mask & 0xff; 1208 sl[oldlen + 1] = mask & 0xff;
1343 else 1209 else
1344 sl.reset (oldlen); 1210 sl.reset (oldlen);
1345
1346 if (socket.ext_mapinfos)
1347 esl << uint16 (emask);
1348
1349 if (socket.EMI_smooth)
1350 {
1351 for (int layer = 2+1; layer--; )
1352 {
1353 object *ob = ms.faces_obj [layer];
1354
1355 // If there is no object for this space, or if the face for the object
1356 // is the blank face, set the smoothlevel to zero.
1357 int smoothlevel = ob && ob->face != blank_face ? ob->smoothlevel : 0;
1358
1359 // We've gotten what face we want to use for the object. Now see if
1360 // if it has changed since we last sent it to the client.
1361 if (lastcell.smooth[layer] != smoothlevel)
1362 {
1363 lastcell.smooth[layer] = smoothlevel;
1364 esl << uint8 (smoothlevel);
1365 emask |= 1 << layer;
1366 }
1367 }
1368
1369 if (emask & 0xf)
1370 esl[eoldlen + 1] = emask & 0xff;
1371 else
1372 esl.reset (eoldlen);
1373 }
1374 } /* else this is a viewable space */ 1211 } /* else this is a viewable space */
1375 } /* for x loop */ 1212 ordered_mapwalk_end
1376 } /* for y loop */
1377 1213
1378 socket.flush_fx (); 1214 socket.flush_fx ();
1379
1380 /* Verify that we in fact do need to send this */
1381 if (socket.ext_mapinfos)
1382 {
1383 if (!(sl.length () > startlen || socket.sent_scroll))
1384 {
1385 /* No map data will follow, so don't say the client
1386 * it doesn't need draw!
1387 */
1388 ewhatflag &= ~EMI_NOREDRAW;
1389 esl[ewhatstart + 1] = ewhatflag & 0xff;
1390 }
1391
1392 if (esl.length () > estartlen)
1393 socket.send_packet (esl);
1394 }
1395 1215
1396 if (sl.length () > startlen || socket.sent_scroll) 1216 if (sl.length () > startlen || socket.sent_scroll)
1397 { 1217 {
1398 socket.send_packet (sl); 1218 socket.send_packet (sl);
1399 socket.sent_scroll = 0; 1219 socket.sent_scroll = 0;
1420{ 1240{
1421 packet sl; 1241 packet sl;
1422 sl << "replyinfo skill_info\n"; 1242 sl << "replyinfo skill_info\n";
1423 1243
1424 for (int i = 1; i < NUM_SKILLS; i++) 1244 for (int i = 1; i < NUM_SKILLS; i++)
1425 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 1245 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]);
1426 1246
1427 if (sl.length () > MAXSOCKBUF) 1247 if (sl.length () > MAXSOCKBUF)
1428 { 1248 {
1429 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 1249 LOG (llevError, "Buffer overflow in send_skill_info!\n");
1430 fatal (0); 1250 fatal (0);
1474 if (spell->type == SPELL) 1294 if (spell->type == SPELL)
1475 { 1295 {
1476 int flags = 0; 1296 int flags = 0;
1477 1297
1478 /* check if we need to update it */ 1298 /* check if we need to update it */
1479 if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) 1299 if (spell->cached_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA))
1480 { 1300 {
1481 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1301 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1482 flags |= UPD_SP_MANA; 1302 flags |= UPD_SP_MANA;
1483 } 1303 }
1484 1304
1485 if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) 1305 if (spell->cached_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE))
1486 { 1306 {
1487 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1307 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1488 flags |= UPD_SP_GRACE; 1308 flags |= UPD_SP_GRACE;
1489 } 1309 }
1490 1310
1491 if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) 1311 if (spell->cached_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell))
1492 { 1312 {
1493 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1313 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1494 flags |= UPD_SP_DAMAGE; 1314 flags |= UPD_SP_DAMAGE;
1495 } 1315 }
1496 1316
1497 if (flags) 1317 if (flags)
1498 { 1318 {
1500 1320
1501 sl << "updspell " 1321 sl << "updspell "
1502 << uint8 (flags) 1322 << uint8 (flags)
1503 << uint32 (spell->count); 1323 << uint32 (spell->count);
1504 1324
1505 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 1325 if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp);
1506 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 1326 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->cached_grace);
1507 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 1327 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->cached_eat);
1508 1328
1509 pl->ns->send_packet (sl); 1329 pl->ns->send_packet (sl);
1510 } 1330 }
1511 } 1331 }
1512 } 1332 }
1542 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1362 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1543 return; 1363 return;
1544 } 1364 }
1545 1365
1546 /* store costs and damage in the object struct, to compare to later */ 1366 /* store costs and damage in the object struct, to compare to later */
1547 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1367 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1548 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1368 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1549 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1369 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1550 1370
1551 /* figure out which skill it uses, if it uses one */ 1371 /* figure out which skill it uses, if it uses one */
1552 if (spell->skill) 1372 if (spell->skill)
1553 { 1373 if (object *tmp = pl->find_skill (spell->skill))
1554 for (i = 1; i < NUM_SKILLS; i++)
1555 if (!strcmp (spell->skill, skill_names[i]))
1556 {
1557 skill = i + CS_STAT_SKILLINFO; 1374 skill = tmp->subtype + CS_STAT_SKILLINFO;
1558 break;
1559 }
1560 }
1561 1375
1562 // spells better have a face 1376 // spells better have a face
1563 if (!spell->face) 1377 if (!spell->face)
1564 { 1378 {
1565 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); 1379 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name);
1570 1384
1571 /* send the current values */ 1385 /* send the current values */
1572 sl << uint32 (spell->count) 1386 sl << uint32 (spell->count)
1573 << uint16 (spell->level) 1387 << uint16 (spell->level)
1574 << uint16 (spell->casting_time) 1388 << uint16 (spell->casting_time)
1575 << uint16 (spell->last_sp) 1389 << uint16 (spell->cached_sp)
1576 << uint16 (spell->last_grace) 1390 << uint16 (spell->cached_grace)
1577 << uint16 (spell->last_eat) 1391 << uint16 (spell->cached_eat)
1578 << uint8 (skill) 1392 << uint8 (skill)
1579 << uint32 (spell->path_attuned) 1393 << uint32 (spell->path_attuned)
1580 << uint32 (spell->face) 1394 << uint32 (spell->face)
1581 << data8 (spell->name) 1395 << data8 (spell->name)
1582 << data16 (spell->msg); 1396 << data16 (spell->msg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines