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.133 by root, Sun Jul 13 11:57:25 2008 UTC vs.
Revision 1.143 by root, Tue Dec 23 06:58:24 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).
833 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 829 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
834 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 830 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
835 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 831 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
836 832
837 for (int s = 0; s < NUM_SKILLS; s++) 833 for (int s = 0; s < NUM_SKILLS; s++)
838 if (object *skill = opl->last_skill_ob[s]) 834 if (object *skill = opl->last_skill_ob [s])
839 if (skill->stats.exp != ns->last_skill_exp [s]) 835 if (skill->stats.exp != ns->last_skill_exp [s])
840 { 836 {
841 ns->last_skill_exp [s] = skill->stats.exp; 837 ns->last_skill_exp [s] = skill->stats.exp;
842 838
843 /* Always send along the level if exp changes. This is only 839 /* Always send along the level if exp changes. This is only
912 << uint32 (pl->ob->face) 908 << uint32 (pl->ob->face)
913 << data8 (pl->ob->name); 909 << data8 (pl->ob->name);
914 910
915 pl->ns->last_weight = weight; 911 pl->ns->last_weight = weight;
916 pl->ns->send_packet (sl); 912 pl->ns->send_packet (sl);
917 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
918} 913}
919 914
920/****************************************************************************** 915/******************************************************************************
921 * 916 *
922 * Start of map related commands. 917 * Start of map related commands.
1040{ 1035{
1041 object *ob = pl->observe; 1036 object *ob = pl->observe;
1042 if (!ob->active) 1037 if (!ob->active)
1043 return; 1038 return;
1044 1039
1045 maptile *plmap = ob->map;
1046
1047 /* If player is just joining the game, he isn't here yet, so the map 1040 /* If player is just joining the game, he isn't here yet, so the map
1048 * can get swapped out. If so, don't try to send them a map. All will 1041 * can get swapped out. If so, don't try to send them a map. All will
1049 * be OK once they really log in. 1042 * be OK once they really log in.
1050 */ 1043 */
1051 if (!plmap || plmap->in_memory != MAP_ACTIVE) 1044 if (!ob->map || ob->map->in_memory != MAP_ACTIVE)
1052 return; 1045 return;
1053 1046
1054 int x, y, ax, ay, startlen, max_x, max_y, oldlen; 1047 int startlen, oldlen;
1055 int estartlen, eoldlen; 1048 int estartlen, eoldlen;
1056 uint8 eentrysize; 1049 uint8 eentrysize;
1057 uint16 ewhatstart, ewhatflag; 1050 uint16 ewhatstart, ewhatflag;
1058 uint8 extendedinfos; 1051 uint8 extendedinfos;
1059 1052
1060 check_map_change (pl); 1053 check_map_change (pl);
1061 prefetch_surrounding_maps (pl->ob); 1054 prefetch_surrounding_maps (pl->ob);
1062 1055
1063 /* do LOS after calls to update_position */ 1056 /* do LOS after calls to update_position */
1064 if (ob != pl->ob) 1057 /* unfortunately, we need to udpate los when observing, currently */
1065 clear_los (pl); 1058 if (pl->do_los || pl->observe != pl->ob)
1066 else if (pl->do_los)
1067 { 1059 {
1068 update_los (ob);
1069 pl->do_los = 0; 1060 pl->do_los = 0;
1061 pl->update_los ();
1070 } 1062 }
1071 1063
1072 /** 1064 /**
1073 * This function uses the new map1 protocol command to send the map 1065 * This function uses the new map1 protocol command to send the map
1074 * to the client. It is necessary because the old map command supports 1066 * to the client. It is necessary because the old map command supports
1116 << uint8 (eentrysize); 1108 << uint8 (eentrysize);
1117 1109
1118 estartlen = esl.length (); 1110 estartlen = esl.length ();
1119 } 1111 }
1120 1112
1121 /* x,y are the real map locations. ax, ay are viewport relative
1122 * locations.
1123 */
1124 ay = 0;
1125
1126 /* We could do this logic as conditionals in the if statement, 1113 /* We could do this logic as conditionals in the if statement,
1127 * but that started to get a bit messy to look at. 1114 * but that started to get a bit messy to look at.
1128 */ 1115 */
1129 max_x = ob->x + (socket.mapx + 1) / 2; 1116 int hx = socket.mapx / 2;
1130 max_y = ob->y + (socket.mapy + 1) / 2; 1117 int hy = socket.mapy / 2;
1131 1118
1132 for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++) 1119 for (int dx = -hx; dx <= hx; dx++)
1133 { 1120 {
1134 sint16 nx, ny; 1121 sint16 nx, ny;
1135 maptile *m = 0; 1122 maptile *m = 0;
1136 1123
1137 ax = 0; 1124 for (int dy = -hy; dy <= hy; dy++)
1138 for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++)
1139 { 1125 {
1140 // check to see if we can simply go one right quickly 1126 // check to see if we can simply go one down quickly
1141 ++nx;
1142 if (m && nx >= m->width) 1127 if (m && ++ny >= m->height)
1143 m = 0; 1128 m = 0;
1144 1129
1130 // no, so do it the slow way
1145 if (!m) 1131 if (!m)
1146 { 1132 {
1147 nx = x; ny = y; m = plmap; 1133 nx = ob->x + dx; ny = ob->y + dy; m = ob->map;
1148 1134
1149 if (xy_normalise (m, nx, ny)) 1135 if (xy_normalise (m, nx, ny))
1150 m->touch (); 1136 m->touch ();
1151 else 1137 else
1152 m = 0; 1138 m = 0;
1153 } 1139 }
1154 1140
1141 int ax = dx + hx;
1142 int ay = dy + hy;
1143
1155 int emask, mask; 1144 int emask, mask;
1156 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1145 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1157 1146
1158 MapCell &lastcell = socket.lastmap.cells[ax][ay]; 1147 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1159 1148
1160 /* If the coordinates are not valid, or it is too dark to see, 1149 /* If the coordinates are not valid, or it is too dark to see,
1161 * we tell the client as such 1150 * we tell the client as such
1162 */ 1151 */
1163 if (!m) 1152 if (!m)
1164 { 1153 {
1165 /* space is out of map. Update space and clear values 1154 /* space is out of map. Update space and clear values
1166 * if this hasn't already been done. If the space is out 1155 * if this hasn't already been done. If the space is out
1167 * of the map, it shouldn't have a head 1156 * of the map, it shouldn't have a head.
1168 */ 1157 */
1169 if (lastcell.count != -1) 1158 if (lastcell.count != -1)
1170 { 1159 {
1171 sl << uint16 (mask); 1160 sl << uint16 (mask);
1172 map_clearcell (&lastcell, -1); 1161 map_clearcell (&lastcell, -1);
1173 } 1162 }
1174 1163
1175 continue; 1164 continue;
1176 } 1165 }
1177 1166
1178 int d = pl->blocked_los[ax][ay]; 1167 int d = pl->blocked_los_uc (dx, dy);
1179 1168
1180 if (d > 3) 1169 if (d > 3)
1181 { 1170 {
1182 int need_send = 0, count; 1171 int need_send = 0, count;
1183 1172
1262 { 1251 {
1263 if (op->stats.maxhp > op->stats.hp 1252 if (op->stats.maxhp > op->stats.hp
1264 && op->stats.maxhp > 0 1253 && op->stats.maxhp > 0
1265 && (op->type == PLAYER 1254 && (op->type == PLAYER
1266 || op->type == DOOR // does not work, have maxhp 0 1255 || op->type == DOOR // does not work, have maxhp 0
1267 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR))) 1256 || QUERY_FLAG (op, FLAG_MONSTER)
1257 || QUERY_FLAG (op, FLAG_ALIVE)
1258 || QUERY_FLAG (op, FLAG_GENERATOR)))
1268 { 1259 {
1269 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1260 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1270 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge 1261 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1271 } 1262 }
1272 1263
1273 if (op->msg && op->msg[0] == '@') 1264 if (op->has_dialogue ())
1274 flags |= 1; 1265 flags |= 1;
1275 1266
1276 if (op->type == PLAYER) 1267 if (op->type == PLAYER)
1277 player = op->count; 1268 player = op == ob ? pl->ob->count
1269 : op == pl->ob ? ob->count
1270 : op->count;
1278 } 1271 }
1279 1272
1280 if (lastcell.stat_hp != stat_hp) 1273 if (lastcell.stat_hp != stat_hp)
1281 { 1274 {
1282 lastcell.stat_hp = stat_hp; 1275 lastcell.stat_hp = stat_hp;
1325 1318
1326 /* Middle face */ 1319 /* Middle face */
1327 if (update_space (sl, socket, ms, lastcell, 1)) 1320 if (update_space (sl, socket, ms, lastcell, 1))
1328 mask |= 0x2; 1321 mask |= 0x2;
1329 1322
1323 if (ob->invisible
1324 && ob->invisible & (ob->invisible < 50 ? 1 : 7)
1330 if (ms.player () == ob 1325 && ms.player () == ob)
1331 && (ob->invisible & (ob->invisible < 50 ? 1 : 7)))
1332 { 1326 {
1333 // force player to be visible to himself if invisible 1327 // force player to be visible to himself if invisible
1334 if (lastcell.faces[0] != ob->face) 1328 if (lastcell.faces[0] != ob->face)
1335 { 1329 {
1336 lastcell.faces[0] = ob->face; 1330 lastcell.faces[0] = ob->face;
1432{ 1426{
1433 packet sl; 1427 packet sl;
1434 sl << "replyinfo skill_info\n"; 1428 sl << "replyinfo skill_info\n";
1435 1429
1436 for (int i = 1; i < NUM_SKILLS; i++) 1430 for (int i = 1; i < NUM_SKILLS; i++)
1437 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 1431 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]);
1438 1432
1439 if (sl.length () > MAXSOCKBUF) 1433 if (sl.length () > MAXSOCKBUF)
1440 { 1434 {
1441 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 1435 LOG (llevError, "Buffer overflow in send_skill_info!\n");
1442 fatal (0); 1436 fatal (0);
1560 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1554 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1561 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1555 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1562 1556
1563 /* figure out which skill it uses, if it uses one */ 1557 /* figure out which skill it uses, if it uses one */
1564 if (spell->skill) 1558 if (spell->skill)
1565 { 1559 if (object *tmp = pl->find_skill (spell->skill))
1566 for (i = 1; i < NUM_SKILLS; i++)
1567 if (!strcmp (spell->skill, skill_names[i]))
1568 {
1569 skill = i + CS_STAT_SKILLINFO; 1560 skill = tmp->subtype + CS_STAT_SKILLINFO;
1570 break;
1571 }
1572 }
1573 1561
1574 // spells better have a face 1562 // spells better have a face
1575 if (!spell->face) 1563 if (!spell->face)
1576 { 1564 {
1577 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); 1565 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines