Ticket #710: circledetection.patch
File circledetection.patch, 8.8 KB (added by rhinocesaurus, 12 years ago) 


src/spells2.c
890 890 891 891 /* 892 892 * Useful constants for the area around the player to detect. 893 * This is instead of using circular detection spells.894 893 */ 895 #define DETECT_DIST_X 40 /* Detect 42 grids to the left & right */ 896 #define DETECT_DIST_Y 22 /* Detect 22 grids to the top & bottom */ 894 #define DETECT_DIST 32 /* Detect 32 grids in all directions */ 897 895 898 896 899 897 … … 907 905 { 908 906 int i, x, y; 909 907 int x1, x2, y1, y2; 908 int py, px, dy, dx; 909 int d; 910 910 911 /* Extract player location */ 912 py = p_ptr>py; 913 px = p_ptr>px; 914 911 915 /* Pick an area to map */ 912 y1 = p _ptr>py  DETECT_DIST_Y;913 y2 = p _ptr>py + DETECT_DIST_Y;914 x1 = p _ptr>px  DETECT_DIST_X;915 x2 = p _ptr>px + DETECT_DIST_X;916 y1 = py  DETECT_DIST; 917 y2 = py + DETECT_DIST; 918 x1 = px  DETECT_DIST; 919 x2 = px + DETECT_DIST; 916 920 917 921 if (y1 < 0) y1 = 0; 918 922 if (x1 < 0) x1 = 0; … … 926 930 if (cave_feat[y][x] < FEAT_SECRET) 927 931 { 928 932 if (!in_bounds_fully(y, x)) continue; 933 934 /* Distance components */ 935 dy = (py > y) ? (py  y) : (y  py); 936 dx = (px > x) ? (px  x) : (x  px); 929 937 938 /* Distance squared */ 939 d = dy*dy + dx*dx; 940 941 /* Don't detect outside the radius */ 942 if (d > DETECT_DIST * DETECT_DIST) continue; 943 944 930 945 /* Memorize normal features */ 931 946 if (cave_feat[y][x] > FEAT_INVIS) 932 947 { … … 963 978 { 964 979 int y, x; 965 980 int x1, x2, y1, y2; 981 int py, px, dy, dx; 982 int d; 966 983 967 984 bool detect = FALSE; 968 985 969 986 (void)aware; 970 987 988 /* Extract player location */ 989 py = p_ptr>py; 990 px = p_ptr>px; 991 971 992 /* Pick an area to map */ 972 y1 = p _ptr>py  DETECT_DIST_Y;973 y2 = p _ptr>py + DETECT_DIST_Y;974 x1 = p _ptr>px  DETECT_DIST_X;975 x2 = p _ptr>px + DETECT_DIST_X;993 y1 = py  DETECT_DIST; 994 y2 = py + DETECT_DIST; 995 x1 = px  DETECT_DIST; 996 x2 = px + DETECT_DIST; 976 997 977 998 if (y1 < 0) y1 = 0; 978 999 if (x1 < 0) x1 = 0; … … 984 1005 for (x = x1; x < x2; x++) 985 1006 { 986 1007 if (!in_bounds_fully(y, x)) continue; 1008 1009 /* Distance components */ 1010 dy = (py > y) ? (py  y) : (y  py); 1011 dx = (px > x) ? (px  x) : (x  px); 987 1012 1013 /* Distance squared */ 1014 d = dy*dy + dx*dx; 1015 1016 /* Don't detect outside the radius */ 1017 if (d > DETECT_DIST * DETECT_DIST) continue; 1018 988 1019 /* Detect invisible traps */ 989 1020 if (cave_feat[y][x] == FEAT_INVIS) 990 1021 { … … 1045 1076 { 1046 1077 int y, x; 1047 1078 int x1, x2, y1, y2; 1079 int py, px, dy, dx; 1080 int d; 1048 1081 1049 1082 bool doors = FALSE, stairs = FALSE; 1050 1083 1084 /* Extract player location */ 1085 py = p_ptr>py; 1086 px = p_ptr>px; 1051 1087 1052 1088 /* Pick an area to map */ 1053 y1 = p _ptr>py  DETECT_DIST_Y;1054 y2 = p _ptr>py + DETECT_DIST_Y;1055 x1 = p _ptr>px  DETECT_DIST_X;1056 x2 = p _ptr>px + DETECT_DIST_X;1089 y1 = py  DETECT_DIST; 1090 y2 = py + DETECT_DIST; 1091 x1 = px  DETECT_DIST; 1092 x2 = px + DETECT_DIST; 1057 1093 1058 1094 if (y1 < 0) y1 = 0; 1059 1095 if (x1 < 0) x1 = 0; … … 1066 1102 { 1067 1103 if (!in_bounds_fully(y, x)) continue; 1068 1104 1105 /* Distance components */ 1106 dy = (py > y) ? (py  y) : (y  py); 1107 dx = (px > x) ? (px  x) : (x  px); 1108 1109 /* Distance squared */ 1110 d = dy*dy + dx*dx; 1111 1112 /* Don't detect outside the radius */ 1113 if (d > DETECT_DIST * DETECT_DIST) continue; 1114 1069 1115 /* Detect secret doors */ 1070 1116 if (cave_feat[y][x] == FEAT_SECRET) 1071 1117 place_closed_door(y, x); … … 1122 1168 int i; 1123 1169 int y, x; 1124 1170 int x1, x2, y1, y2; 1171 int py, px, dy, dx; 1172 int d; 1125 1173 1126 1174 bool gold_buried = FALSE; 1127 1175 bool objects = FALSE; 1128 1176 1177 /* Extract player location */ 1178 py = p_ptr>py; 1179 px = p_ptr>px; 1129 1180 1130 1181 /* Pick an area to map */ 1131 y1 = p _ptr>py  DETECT_DIST_Y;1132 y2 = p _ptr>py + DETECT_DIST_Y;1133 x1 = p _ptr>px  DETECT_DIST_X;1134 x2 = p _ptr>px + DETECT_DIST_X;1182 y1 = py  DETECT_DIST; 1183 y2 = py + DETECT_DIST; 1184 x1 = px  DETECT_DIST; 1185 x2 = px + DETECT_DIST; 1135 1186 1136 1187 if (y1 < 0) y1 = 0; 1137 1188 if (x1 < 0) x1 = 0; … … 1144 1195 { 1145 1196 if (!in_bounds_fully(y, x)) continue; 1146 1197 1198 /* Distance components */ 1199 dy = (py > y) ? (py  y) : (y  py); 1200 dx = (px > x) ? (px  x) : (x  px); 1201 1202 /* Distance squared */ 1203 d = dy*dy + dx*dx; 1204 1205 /* Don't detect outside the radius */ 1206 if (d > DETECT_DIST * DETECT_DIST) continue; 1207 1147 1208 /* Notice embedded gold */ 1148 1209 if ((cave_feat[y][x] == FEAT_MAGMA_H)  1149 1210 (cave_feat[y][x] == FEAT_QUARTZ_H)) … … 1183 1244 y = o_ptr>iy; 1184 1245 x = o_ptr>ix; 1185 1246 1186 /* Only detectnearby objects */1247 /* Only try nearby objects */ 1187 1248 if (x < x1  y < y1  x > x2  y > y2) continue; 1188 1249 1250 /* Distance components */ 1251 dy = (py > y) ? (py  y) : (y  py); 1252 dx = (px > x) ? (px  x) : (x  px); 1253 1254 /* Distance squared */ 1255 d = dy*dy + dx*dx; 1256 1257 /* Don't detect outside the radius */ 1258 if (d > DETECT_DIST * DETECT_DIST) continue; 1259 1189 1260 /* Hack  memorize it */ 1190 1261 o_ptr>marked = TRUE; 1191 1262 … … 1223 1294 { 1224 1295 int i, y, x, tv; 1225 1296 int x1, x2, y1, y2; 1297 int py, px, dy, dx; 1298 int d; 1226 1299 1227 1300 bool detect = FALSE; 1228 1301 1302 /* Extract player location */ 1303 py = p_ptr>py; 1304 px = p_ptr>px; 1229 1305 1230 1306 /* Pick an area to map */ 1231 y1 = p _ptr>py  DETECT_DIST_Y;1232 y2 = p _ptr>py + DETECT_DIST_Y;1233 x1 = p _ptr>px  DETECT_DIST_X;1234 x2 = p _ptr>px + DETECT_DIST_X;1307 y1 = py  DETECT_DIST; 1308 y2 = py + DETECT_DIST; 1309 x1 = px  DETECT_DIST; 1310 x2 = px + DETECT_DIST; 1235 1311 1236 1312 if (y1 < 0) y1 = 0; 1237 1313 if (x1 < 0) x1 = 0; … … 1251 1327 /* Location */ 1252 1328 y = o_ptr>iy; 1253 1329 x = o_ptr>ix; 1330 1331 /* Only try nearby objects */ 1332 if (x < x1  y < y1  x > x2  y > y2) continue; 1333 1334 /* Distance components */ 1335 dy = (py > y) ? (py  y) : (y  py); 1336 dx = (px > x) ? (px  x) : (x  px); 1254 1337 1338 /* Distance squared */ 1339 d = dy*dy + dx*dx; 1340 1341 /* Don't detect outside the radius */ 1342 if (d > DETECT_DIST * DETECT_DIST) continue; 1255 1343 1256 /* Only detect nearby objects */1257 if (x < x1  y < y1  x > x2  y > y2) continue;1258 1259 1344 /* Examine the tval */ 1260 1345 tv = o_ptr>tval; 1261 1346 … … 1295 1380 { 1296 1381 int i, y, x; 1297 1382 int x1, x2, y1, y2; 1383 int py, px, dy, dx; 1384 int d; 1298 1385 1299 1386 bool flag = FALSE; 1300 1387 1301 1388 1389 /* Extract player location */ 1390 py = p_ptr>py; 1391 px = p_ptr>px; 1392 1302 1393 /* Pick an area to map */ 1303 y1 = p _ptr>py  DETECT_DIST_Y;1304 y2 = p _ptr>py + DETECT_DIST_Y;1305 x1 = p _ptr>px  DETECT_DIST_X;1306 x2 = p _ptr>px + DETECT_DIST_X;1394 y1 = py  DETECT_DIST; 1395 y2 = py + DETECT_DIST; 1396 x1 = px  DETECT_DIST; 1397 x2 = px + DETECT_DIST; 1307 1398 1308 1399 if (y1 < 0) y1 = 0; 1309 1400 if (x1 < 0) x1 = 0; … … 1323 1414 y = m_ptr>fy; 1324 1415 x = m_ptr>fx; 1325 1416 1326 /* Only detectnearby monsters */1417 /* Only try nearby monsters */ 1327 1418 if (x < x1  y < y1  x > x2  y > y2) continue; 1328 1419 1420 /* Distance components */ 1421 dy = (py > y) ? (py  y) : (y  py); 1422 dx = (px > x) ? (px  x) : (x  px); 1423 1424 /* Distance squared */ 1425 d = dy*dy + dx*dx; 1426 1427 /* Don't detect outside the radius */ 1428 if (d > DETECT_DIST * DETECT_DIST) continue; 1429 1329 1430 /* Detect all noninvisible monsters */ 1330 1431 if (!(r_ptr>flags[1] & (RF1_INVISIBLE))) 1331 1432 { … … 1360 1461 { 1361 1462 int i, y, x; 1362 1463 int x1, x2, y1, y2; 1464 int py, px, dy, dx; 1465 int d; 1363 1466 1364 1467 bool flag = FALSE; 1365 1468 1469 /* Extract player location */ 1470 py = p_ptr>py; 1471 px = p_ptr>px; 1472 1366 1473 /* Pick an area to map */ 1367 y1 = p _ptr>py  DETECT_DIST_Y;1368 y2 = p _ptr>py + DETECT_DIST_Y;1369 x1 = p _ptr>px  DETECT_DIST_X;1370 x2 = p _ptr>px + DETECT_DIST_X;1474 y1 = py  DETECT_DIST; 1475 y2 = py + DETECT_DIST; 1476 x1 = px  DETECT_DIST; 1477 x2 = px + DETECT_DIST; 1371 1478 1372 1479 if (y1 < 0) y1 = 0; 1373 1480 if (x1 < 0) x1 = 0; … … 1387 1494 y = m_ptr>fy; 1388 1495 x = m_ptr>fx; 1389 1496 1390 /* Only detect nearby objects */1497 /* Only try nearby monsters */ 1391 1498 if (x < x1  y < y1  x > x2  y > y2) continue; 1392 1499 1500 /* Distance components */ 1501 dy = (py > y) ? (py  y) : (y  py); 1502 dx = (px > x) ? (px  x) : (x  px); 1503 1504 /* Distance squared */ 1505 d = dy*dy + dx*dx; 1506 1507 /* Don't detect outside the radius */ 1508 if (d > DETECT_DIST * DETECT_DIST) continue; 1509 1393 1510 /* Detect invisible monsters */ 1394 1511 if (r_ptr>flags[1] & (RF1_INVISIBLE)) 1395 1512 { … … 1434 1551 { 1435 1552 int i, y, x; 1436 1553 int x1, x2, y1, y2; 1554 int py, px, dy, dx; 1555 int d; 1437 1556 1438 1557 bool flag = FALSE; 1439 1558 1559 /* Extract player location */ 1560 py = p_ptr>py; 1561 px = p_ptr>px; 1562 1440 1563 /* Pick an area to map */ 1441 y1 = p _ptr>py  DETECT_DIST_Y;1442 y2 = p _ptr>py + DETECT_DIST_Y;1443 x1 = p _ptr>px  DETECT_DIST_X;1444 x2 = p _ptr>px + DETECT_DIST_X;1564 y1 = py  DETECT_DIST; 1565 y2 = py + DETECT_DIST; 1566 x1 = px  DETECT_DIST; 1567 x2 = px + DETECT_DIST; 1445 1568 1446 1569 if (y1 < 0) y1 = 0; 1447 1570 if (x1 < 0) x1 = 0; … … 1461 1584 y = m_ptr>fy; 1462 1585 x = m_ptr>fx; 1463 1586 1464 /* Only detect nearby objects */1587 /* Only try nearby monsters */ 1465 1588 if (x < x1  y < y1  x > x2  y > y2) continue; 1466 1589 1590 /* Distance components */ 1591 dy = (py > y) ? (py  y) : (y  py); 1592 dx = (px > x) ? (px  x) : (x  px); 1593 1594 /* Distance squared */ 1595 d = dy*dy + dx*dx; 1596 1597 /* Don't detect outside the radius */ 1598 if (d > DETECT_DIST * DETECT_DIST) continue; 1599 1467 1600 /* Detect evil monsters */ 1468 1601 if (r_ptr>flags[2] & (RF2_EVIL)) 1469 1602 {