… | |
… | |
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). |
… | |
… | |
1039 | { |
1035 | { |
1040 | object *ob = pl->observe; |
1036 | object *ob = pl->observe; |
1041 | if (!ob->active) |
1037 | if (!ob->active) |
1042 | return; |
1038 | return; |
1043 | |
1039 | |
1044 | maptile *plmap = ob->map; |
|
|
1045 | |
|
|
1046 | /* 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 |
1047 | * 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 |
1048 | * be OK once they really log in. |
1042 | * be OK once they really log in. |
1049 | */ |
1043 | */ |
1050 | if (!plmap || plmap->in_memory != MAP_ACTIVE) |
1044 | if (!ob->map || ob->map->in_memory != MAP_ACTIVE) |
1051 | return; |
1045 | return; |
1052 | |
1046 | |
1053 | int x, y, ax, ay, startlen, max_x, max_y, oldlen; |
1047 | int startlen, oldlen; |
1054 | int estartlen, eoldlen; |
1048 | int estartlen, eoldlen; |
1055 | uint8 eentrysize; |
1049 | uint8 eentrysize; |
1056 | uint16 ewhatstart, ewhatflag; |
1050 | uint16 ewhatstart, ewhatflag; |
1057 | uint8 extendedinfos; |
1051 | uint8 extendedinfos; |
1058 | |
1052 | |
1059 | check_map_change (pl); |
1053 | check_map_change (pl); |
1060 | prefetch_surrounding_maps (pl->ob); |
1054 | prefetch_surrounding_maps (pl->ob); |
1061 | |
1055 | |
1062 | /* do LOS after calls to update_position */ |
1056 | /* do LOS after calls to update_position */ |
1063 | if (ob != pl->ob) |
1057 | /* unfortunately, we need to udpate los when observing, currently */ |
1064 | clear_los (pl); |
1058 | if (pl->do_los || pl->observe != pl->ob) |
1065 | else if (pl->do_los) |
|
|
1066 | { |
1059 | { |
1067 | update_los (ob); |
|
|
1068 | pl->do_los = 0; |
1060 | pl->do_los = 0; |
|
|
1061 | pl->update_los (); |
1069 | } |
1062 | } |
1070 | |
1063 | |
1071 | /** |
1064 | /** |
1072 | * 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 |
1073 | * 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 |
… | |
… | |
1115 | << uint8 (eentrysize); |
1108 | << uint8 (eentrysize); |
1116 | |
1109 | |
1117 | estartlen = esl.length (); |
1110 | estartlen = esl.length (); |
1118 | } |
1111 | } |
1119 | |
1112 | |
1120 | /* x,y are the real map locations. ax, ay are viewport relative |
|
|
1121 | * locations. |
|
|
1122 | */ |
|
|
1123 | ay = 0; |
|
|
1124 | |
|
|
1125 | /* We could do this logic as conditionals in the if statement, |
1113 | /* We could do this logic as conditionals in the if statement, |
1126 | * but that started to get a bit messy to look at. |
1114 | * but that started to get a bit messy to look at. |
1127 | */ |
1115 | */ |
1128 | max_x = ob->x + (socket.mapx + 1) / 2; |
1116 | int hx = socket.mapx / 2; |
1129 | max_y = ob->y + (socket.mapy + 1) / 2; |
1117 | int hy = socket.mapy / 2; |
1130 | |
1118 | |
1131 | for (y = ob->y - socket.mapy / 2; y < max_y; y++, ay++) |
1119 | for (int dx = -hx; dx <= hx; dx++) |
1132 | { |
1120 | { |
1133 | sint16 nx, ny; |
1121 | sint16 nx, ny; |
1134 | maptile *m = 0; |
1122 | maptile *m = 0; |
1135 | |
1123 | |
1136 | ax = 0; |
1124 | for (int dy = -hy; dy <= hy; dy++) |
1137 | for (x = ob->x - socket.mapx / 2; x < max_x; x++, ax++) |
|
|
1138 | { |
1125 | { |
1139 | // check to see if we can simply go one right quickly |
1126 | // check to see if we can simply go one down quickly |
1140 | ++nx; |
|
|
1141 | if (m && nx >= m->width) |
1127 | if (m && ++ny >= m->height) |
1142 | m = 0; |
1128 | m = 0; |
1143 | |
1129 | |
|
|
1130 | // no, so do it the slow way |
1144 | if (!m) |
1131 | if (!m) |
1145 | { |
1132 | { |
1146 | nx = x; ny = y; m = plmap; |
1133 | nx = ob->x + dx; ny = ob->y + dy; m = ob->map; |
1147 | |
1134 | |
1148 | if (xy_normalise (m, nx, ny)) |
1135 | if (xy_normalise (m, nx, ny)) |
1149 | m->touch (); |
1136 | m->touch (); |
1150 | else |
1137 | else |
1151 | m = 0; |
1138 | m = 0; |
1152 | } |
1139 | } |
1153 | |
1140 | |
|
|
1141 | int ax = dx + hx; |
|
|
1142 | int ay = dy + hy; |
|
|
1143 | |
1154 | int emask, mask; |
1144 | int emask, mask; |
1155 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1145 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1156 | |
1146 | |
1157 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1147 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1158 | |
1148 | |
1159 | /* 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, |
1160 | * we tell the client as such |
1150 | * we tell the client as such |
1161 | */ |
1151 | */ |
1162 | if (!m) |
1152 | if (!m) |
1163 | { |
1153 | { |
1164 | /* space is out of map. Update space and clear values |
1154 | /* space is out of map. Update space and clear values |
1165 | * 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 |
1166 | * of the map, it shouldn't have a head |
1156 | * of the map, it shouldn't have a head. |
1167 | */ |
1157 | */ |
1168 | if (lastcell.count != -1) |
1158 | if (lastcell.count != -1) |
1169 | { |
1159 | { |
1170 | sl << uint16 (mask); |
1160 | sl << uint16 (mask); |
1171 | map_clearcell (&lastcell, -1); |
1161 | map_clearcell (&lastcell, -1); |
1172 | } |
1162 | } |
1173 | |
1163 | |
1174 | continue; |
1164 | continue; |
1175 | } |
1165 | } |
1176 | |
1166 | |
1177 | int d = pl->blocked_los[ax][ay]; |
1167 | int d = pl->blocked_los_uc (dx, dy); |
1178 | |
1168 | |
1179 | if (d > 3) |
1169 | if (d > 3) |
1180 | { |
1170 | { |
1181 | int need_send = 0, count; |
1171 | int need_send = 0, count; |
1182 | |
1172 | |
… | |
… | |
1328 | |
1318 | |
1329 | /* Middle face */ |
1319 | /* Middle face */ |
1330 | if (update_space (sl, socket, ms, lastcell, 1)) |
1320 | if (update_space (sl, socket, ms, lastcell, 1)) |
1331 | mask |= 0x2; |
1321 | mask |= 0x2; |
1332 | |
1322 | |
|
|
1323 | if (ob->invisible |
|
|
1324 | && ob->invisible & (ob->invisible < 50 ? 1 : 7) |
1333 | if (ms.player () == ob |
1325 | && ms.player () == ob) |
1334 | && (ob->invisible & (ob->invisible < 50 ? 1 : 7))) |
|
|
1335 | { |
1326 | { |
1336 | // force player to be visible to himself if invisible |
1327 | // force player to be visible to himself if invisible |
1337 | if (lastcell.faces[0] != ob->face) |
1328 | if (lastcell.faces[0] != ob->face) |
1338 | { |
1329 | { |
1339 | lastcell.faces[0] = ob->face; |
1330 | lastcell.faces[0] = ob->face; |