… | |
… | |
77 | /* Make sure the coordinates are valid - they should be, as caller should |
77 | /* Make sure the coordinates are valid - they should be, as caller should |
78 | * have already checked this. |
78 | * have already checked this. |
79 | */ |
79 | */ |
80 | if (OUT_OF_REAL_MAP (m, sx, sy)) |
80 | if (OUT_OF_REAL_MAP (m, sx, sy)) |
81 | { |
81 | { |
82 | LOG (llevError, "blocked_link: Passed map, x, y coordinates outside of map\n"); |
82 | LOG (llevError | logBacktrace, "blocked_link: Passed map, x, y coordinates outside of map\n"); |
83 | return 1; |
83 | return 1; |
84 | } |
84 | } |
85 | |
85 | |
86 | mapspace &ms = m->at (sx, sy); |
86 | mapspace &ms = m->at (sx, sy); |
87 | |
87 | |
… | |
… | |
90 | |
90 | |
91 | /* If space is currently not blocked by anything, no need to |
91 | /* If space is currently not blocked by anything, no need to |
92 | * go further. Not true for players - all sorts of special |
92 | * go further. Not true for players - all sorts of special |
93 | * things we need to do for players. |
93 | * things we need to do for players. |
94 | */ |
94 | */ |
95 | if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) |
95 | if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && blocked == 0) |
96 | return 0; |
96 | return 0; |
97 | |
97 | |
98 | /* if there isn't anything alive on this space, and this space isn't |
98 | /* if there isn't anything alive on this space, and this space isn't |
99 | * otherwise blocked, we can return now. Only if there is a living |
99 | * otherwise blocked, we can return now. Only if there is a living |
100 | * creature do we need to investigate if it is part of this creature |
100 | * creature do we need to investigate if it is part of this creature |
… | |
… | |
1429 | get_rangevector (object *op1, object *op2, rv_vector *retval, int flags) |
1429 | get_rangevector (object *op1, object *op2, rv_vector *retval, int flags) |
1430 | { |
1430 | { |
1431 | if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y)) |
1431 | if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y)) |
1432 | { |
1432 | { |
1433 | /* be conservative and fill in _some_ data */ |
1433 | /* be conservative and fill in _some_ data */ |
1434 | retval->distance = 10000; |
1434 | retval->distance = 10000; |
1435 | retval->distance_x = 10000; |
1435 | retval->distance_x = 10000; |
1436 | retval->distance_y = 10000; |
1436 | retval->distance_y = 10000; |
1437 | retval->direction = 0; |
1437 | retval->direction = 0; |
1438 | retval->part = 0; |
1438 | retval->part = 0; |
1439 | } |
1439 | } |
1440 | else |
1440 | else |
1441 | { |
1441 | { |
1442 | retval->distance_x += op2->x - op1->x; |
1442 | retval->distance_x += op2->x - op1->x; |
1443 | retval->distance_y += op2->y - op1->y; |
1443 | retval->distance_y += op2->y - op1->y; |
… | |
… | |
1445 | object *best = op1; |
1445 | object *best = op1; |
1446 | |
1446 | |
1447 | /* If this is multipart, find the closest part now */ |
1447 | /* If this is multipart, find the closest part now */ |
1448 | if (!(flags & 1) && op1->more) |
1448 | if (!(flags & 1) && op1->more) |
1449 | { |
1449 | { |
1450 | int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi; |
1450 | int best_distance = idistance (retval->distance_x, retval->distance_y); |
1451 | |
1451 | |
1452 | /* we just take the offset of the piece to head to figure |
1452 | /* we just take the offset of the piece to head to figure |
1453 | * distance instead of doing all that work above again |
1453 | * distance instead of doing all that work above again |
1454 | * since the distance fields we set above are positive in the |
1454 | * since the distance fields we set above are positive in the |
1455 | * same axis as is used for multipart objects, the simply arithmetic |
1455 | * same axis as is used for multipart objects, the simply arithmetic |
1456 | * below works. |
1456 | * below works. |
1457 | */ |
1457 | */ |
1458 | for (object *tmp = op1->more; tmp; tmp = tmp->more) |
1458 | for (object *tmp = op1->more; tmp; tmp = tmp->more) |
1459 | { |
1459 | { |
1460 | tmpi = (op1->x - tmp->x + retval->distance_x) * (op1->x - tmp->x + retval->distance_x) + |
1460 | int tmpi = idistance (op1->x - tmp->x + retval->distance_x, op1->y - tmp->y + retval->distance_y); |
1461 | (op1->y - tmp->y + retval->distance_y) * (op1->y - tmp->y + retval->distance_y); |
1461 | |
1462 | if (tmpi < best_distance) |
1462 | if (tmpi < best_distance) |
1463 | { |
1463 | { |
1464 | best_distance = tmpi; |
1464 | best_distance = tmpi; |
1465 | best = tmp; |
1465 | best = tmp; |
1466 | } |
1466 | } |
1467 | } |
1467 | } |
1468 | |
1468 | |
1469 | if (best != op1) |
1469 | if (best != op1) |
1470 | { |
1470 | { |
1471 | retval->distance_x += op1->x - best->x; |
1471 | retval->distance_x += op1->x - best->x; |
1472 | retval->distance_y += op1->y - best->y; |
1472 | retval->distance_y += op1->y - best->y; |
1473 | } |
1473 | } |
1474 | } |
1474 | } |
1475 | |
1475 | |
1476 | retval->part = best; |
1476 | retval->part = best; |
1477 | retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); |
1477 | retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); |
1478 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1478 | retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); |
1479 | } |
1479 | } |
1480 | } |
1480 | } |
1481 | |
1481 | |
1482 | /* this is basically the same as get_rangevector above, but instead of |
1482 | /* this is basically the same as get_rangevector above, but instead of |
1483 | * the first parameter being an object, it instead is the map |
1483 | * the first parameter being an object, it instead is the map |
… | |
… | |
1493 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags) |
1493 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector *retval, int flags) |
1494 | { |
1494 | { |
1495 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
1495 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
1496 | { |
1496 | { |
1497 | /* be conservative and fill in _some_ data */ |
1497 | /* be conservative and fill in _some_ data */ |
1498 | retval->distance = 100000; |
1498 | retval->distance = 100000; |
1499 | retval->distance_x = 32767; |
1499 | retval->distance_x = 32767; |
1500 | retval->distance_y = 32767; |
1500 | retval->distance_y = 32767; |
1501 | retval->direction = 0; |
1501 | retval->direction = 0; |
1502 | retval->part = 0; |
1502 | retval->part = 0; |
1503 | } |
1503 | } |
1504 | else |
1504 | else |
1505 | { |
1505 | { |
1506 | retval->distance_x += op2->x - x; |
1506 | retval->distance_x += op2->x - x; |
1507 | retval->distance_y += op2->y - y; |
1507 | retval->distance_y += op2->y - y; |
1508 | |
1508 | |
1509 | retval->part = 0; |
1509 | retval->part = 0; |
1510 | retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); |
1510 | retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); |
1511 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1511 | retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); |
1512 | } |
1512 | } |
1513 | } |
1513 | } |
1514 | |
1514 | |
1515 | /* Returns true of op1 and op2 are effectively on the same map |
1515 | /* Returns true of op1 and op2 are effectively on the same map |
1516 | * (as related to map tiling). Note that this looks for a path from |
1516 | * (as related to map tiling). Note that this looks for a path from |