… | |
… | |
110 | /* We basically go through the stack of objects, and if there is |
110 | /* We basically go through the stack of objects, and if there is |
111 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
111 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
112 | * true. If we get through the entire stack, that must mean |
112 | * true. If we get through the entire stack, that must mean |
113 | * ob is blocking it, so return 0. |
113 | * ob is blocking it, so return 0. |
114 | */ |
114 | */ |
115 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
115 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
116 | { |
116 | { |
117 | if (OB_MOVE_BLOCK (ob, tmp)) |
117 | if (OB_MOVE_BLOCK (ob, tmp)) |
118 | { |
118 | { |
119 | if (INVOKE_OBJECT (BLOCKED_MOVE, tmp, ob)) |
119 | if (INVOKE_OBJECT (BLOCKED_MOVE, tmp, ob)) |
120 | if (RESULT_INT (0)) |
120 | if (RESULT_INT (0)) |
… | |
… | |
144 | return 1; // unconditional block |
144 | return 1; // unconditional block |
145 | |
145 | |
146 | } else { |
146 | } else { |
147 | // space does not block the ob, directly, but |
147 | // space does not block the ob, directly, but |
148 | // anything alive that is not a door still |
148 | // anything alive that is not a door still |
149 | // blocks anything but wizards. |
149 | // blocks anything |
150 | |
150 | |
151 | if (tmp->flag [FLAG_ALIVE] |
151 | if (tmp->flag [FLAG_ALIVE] |
152 | && tmp->head_ () != ob |
|
|
153 | && tmp != ob |
|
|
154 | && tmp->type != DOOR) |
152 | && tmp->type != DOOR |
|
|
153 | && tmp->head_ () != ob) //TODO: maybe move these check up? |
155 | return 1; |
154 | return 1; |
156 | } |
155 | } |
157 | } |
156 | } |
158 | |
157 | |
159 | return 0; |
158 | return 0; |
160 | } |
159 | } |
161 | |
160 | |
162 | /* |
161 | /* |
163 | * Returns qthe blocking object if the given object can't fit in the given |
162 | * Returns the blocking object if the given object can't fit in the given |
164 | * spot. This is meant for multi space objects - for single space objecs, |
163 | * spot. This is meant for multi space objects - for single space objecs, |
165 | * just calling get_map_blocked and checking that against movement type |
164 | * just calling get_map_blocked and checking that against movement type |
166 | * of object. This function goes through all the parts of the multipart |
165 | * of object. This function goes through all the parts of the multipart |
167 | * object and makes sure they can be inserted. |
166 | * object and makes sure they can be inserted. |
168 | * |
167 | * |
… | |
… | |
1430 | get_rangevector (object *op1, object *op2, rv_vector *retval, int flags) |
1429 | get_rangevector (object *op1, object *op2, rv_vector *retval, int flags) |
1431 | { |
1430 | { |
1432 | 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)) |
1433 | { |
1432 | { |
1434 | /* be conservative and fill in _some_ data */ |
1433 | /* be conservative and fill in _some_ data */ |
1435 | retval->distance = 10000; |
1434 | retval->distance = 10000; |
1436 | retval->distance_x = 10000; |
1435 | retval->distance_x = 10000; |
1437 | retval->distance_y = 10000; |
1436 | retval->distance_y = 10000; |
1438 | retval->direction = 0; |
1437 | retval->direction = 0; |
1439 | retval->part = 0; |
1438 | retval->part = 0; |
1440 | } |
1439 | } |
1441 | else |
1440 | else |
1442 | { |
1441 | { |
1443 | retval->distance_x += op2->x - op1->x; |
1442 | retval->distance_x += op2->x - op1->x; |
1444 | retval->distance_y += op2->y - op1->y; |
1443 | retval->distance_y += op2->y - op1->y; |
… | |
… | |
1446 | object *best = op1; |
1445 | object *best = op1; |
1447 | |
1446 | |
1448 | /* If this is multipart, find the closest part now */ |
1447 | /* If this is multipart, find the closest part now */ |
1449 | if (!(flags & 1) && op1->more) |
1448 | if (!(flags & 1) && op1->more) |
1450 | { |
1449 | { |
1451 | 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); |
1452 | |
1451 | |
1453 | /* 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 |
1454 | * distance instead of doing all that work above again |
1453 | * distance instead of doing all that work above again |
1455 | * since the distance fields we set above are positive in the |
1454 | * since the distance fields we set above are positive in the |
1456 | * same axis as is used for multipart objects, the simply arithmetic |
1455 | * same axis as is used for multipart objects, the simply arithmetic |
1457 | * below works. |
1456 | * below works. |
1458 | */ |
1457 | */ |
1459 | for (object *tmp = op1->more; tmp; tmp = tmp->more) |
1458 | for (object *tmp = op1->more; tmp; tmp = tmp->more) |
1460 | { |
1459 | { |
1461 | 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); |
1462 | (op1->y - tmp->y + retval->distance_y) * (op1->y - tmp->y + retval->distance_y); |
1461 | |
1463 | if (tmpi < best_distance) |
1462 | if (tmpi < best_distance) |
1464 | { |
1463 | { |
1465 | best_distance = tmpi; |
1464 | best_distance = tmpi; |
1466 | best = tmp; |
1465 | best = tmp; |
1467 | } |
1466 | } |
1468 | } |
1467 | } |
1469 | |
1468 | |
1470 | if (best != op1) |
1469 | if (best != op1) |
1471 | { |
1470 | { |
1472 | retval->distance_x += op1->x - best->x; |
1471 | retval->distance_x += op1->x - best->x; |
1473 | retval->distance_y += op1->y - best->y; |
1472 | retval->distance_y += op1->y - best->y; |
1474 | } |
1473 | } |
1475 | } |
1474 | } |
1476 | |
1475 | |
1477 | retval->part = best; |
1476 | retval->part = best; |
1478 | 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)); |
1479 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1478 | retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); |
1480 | } |
1479 | } |
1481 | } |
1480 | } |
1482 | |
1481 | |
1483 | /* 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 |
1484 | * the first parameter being an object, it instead is the map |
1483 | * the first parameter being an object, it instead is the map |
… | |
… | |
1494 | 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) |
1495 | { |
1494 | { |
1496 | 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)) |
1497 | { |
1496 | { |
1498 | /* be conservative and fill in _some_ data */ |
1497 | /* be conservative and fill in _some_ data */ |
1499 | retval->distance = 100000; |
1498 | retval->distance = 100000; |
1500 | retval->distance_x = 32767; |
1499 | retval->distance_x = 32767; |
1501 | retval->distance_y = 32767; |
1500 | retval->distance_y = 32767; |
1502 | retval->direction = 0; |
1501 | retval->direction = 0; |
1503 | retval->part = 0; |
1502 | retval->part = 0; |
1504 | } |
1503 | } |
1505 | else |
1504 | else |
1506 | { |
1505 | { |
1507 | retval->distance_x += op2->x - x; |
1506 | retval->distance_x += op2->x - x; |
1508 | retval->distance_y += op2->y - y; |
1507 | retval->distance_y += op2->y - y; |
1509 | |
1508 | |
1510 | retval->part = 0; |
1509 | retval->part = 0; |
1511 | 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)); |
1512 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1511 | retval->direction = find_dir_2 (retval->distance_x, retval->distance_y); |
1513 | } |
1512 | } |
1514 | } |
1513 | } |
1515 | |
1514 | |
1516 | /* 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 |
1517 | * (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 |