… | |
… | |
445 | { |
445 | { |
446 | while (op) |
446 | while (op) |
447 | { |
447 | { |
448 | // adjust by actual difference to account for rounding errors |
448 | // adjust by actual difference to account for rounding errors |
449 | // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct |
449 | // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct |
450 | weight = weight_adjust_for (op, op->carrying) |
450 | weight = weight_adjust_for (op, op->carrying + weight) |
451 | - weight_adjust_for (op, op->carrying - weight); |
451 | - weight_adjust_for (op, op->carrying); |
452 | |
452 | |
453 | if (!weight) |
453 | if (!weight) |
454 | return; |
454 | return; |
455 | |
455 | |
456 | op->carrying += weight; |
456 | op->carrying += weight; |
… | |
… | |
484 | sum = weight_adjust_for (this, sum); |
484 | sum = weight_adjust_for (this, sum); |
485 | |
485 | |
486 | if (sum != carrying) |
486 | if (sum != carrying) |
487 | { |
487 | { |
488 | if (carrying != sum)//D |
488 | if (carrying != sum)//D |
489 | LOG (llevDebug, "updating weight got %ld, expected %ld (%s)\n", |
489 | LOG (llevDebug, "updating carrying got %ld, expected %ld (%s)\n", |
490 | (long long)sum, (long long)carrying, debug_desc ()); |
490 | (long long)sum, (long long)carrying, debug_desc ()); |
491 | |
491 | |
492 | carrying = sum; |
492 | carrying = sum; |
493 | |
493 | |
494 | if (object *pl = visible_to ()) |
494 | if (object *pl = visible_to ()) |
… | |
… | |
1572 | */ |
1572 | */ |
1573 | |
1573 | |
1574 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1574 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1575 | if (!(flag & INS_NO_WALK_ON) && op->is_head ()) |
1575 | if (!(flag & INS_NO_WALK_ON) && op->is_head ()) |
1576 | { |
1576 | { |
1577 | if (check_move_on (op, originator)) |
1577 | if (check_move_on (op, originator, flag)) |
1578 | return 0; |
1578 | return 0; |
1579 | |
1579 | |
1580 | /* If we are a multi part object, lets work our way through the check |
1580 | /* If we are a multi part object, let's work our way through the check |
1581 | * walk on's. |
1581 | * walk on's. |
1582 | */ |
1582 | */ |
1583 | for (object *tmp = op->more; tmp; tmp = tmp->more) |
1583 | for (object *tmp = op->more; tmp; tmp = tmp->more) |
1584 | if (check_move_on (tmp, originator)) |
1584 | if (check_move_on (tmp, originator, flag)) |
1585 | return 0; |
1585 | return 0; |
1586 | } |
1586 | } |
1587 | |
1587 | |
1588 | return op; |
1588 | return op; |
1589 | } |
1589 | } |
… | |
… | |
1815 | * MSW 2001-07-08: Check all objects on space, not just those below |
1815 | * MSW 2001-07-08: Check all objects on space, not just those below |
1816 | * object being inserted. insert_ob_in_map may not put new objects |
1816 | * object being inserted. insert_ob_in_map may not put new objects |
1817 | * on top. |
1817 | * on top. |
1818 | */ |
1818 | */ |
1819 | int |
1819 | int |
1820 | check_move_on (object *op, object *originator) |
1820 | check_move_on (object *op, object *originator, int flags) |
1821 | { |
1821 | { |
1822 | if (op->flag [FLAG_NO_APPLY]) |
1822 | if (op->flag [FLAG_NO_APPLY]) |
1823 | return 0; |
1823 | return 0; |
1824 | |
1824 | |
1825 | object *tmp; |
1825 | object *tmp; |
… | |
… | |
1884 | |
1884 | |
1885 | /* Basically same logic as above, except now for actual apply. */ |
1885 | /* Basically same logic as above, except now for actual apply. */ |
1886 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
1886 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
1887 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
1887 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
1888 | { |
1888 | { |
|
|
1889 | if (tmp->type == EXIT && (flags & INS_NO_AUTO_EXIT)) //TODO: temporary, fix exits instead |
|
|
1890 | continue; |
|
|
1891 | |
1889 | move_apply (tmp, op, originator); |
1892 | move_apply (tmp, op, originator); |
1890 | |
1893 | |
1891 | if (op->destroyed ()) |
1894 | if (op->destroyed ()) |
1892 | return 1; |
1895 | return 1; |
1893 | |
1896 | |
… | |
… | |
2218 | { |
2221 | { |
2219 | return (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2222 | return (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2220 | } |
2223 | } |
2221 | |
2224 | |
2222 | /* |
2225 | /* |
2223 | * find_dir_2(delta-x,delta-y) will return a direction in which |
2226 | * find_dir_2(delta-x,delta-y) will return a direction value |
2224 | * an object which has subtracted the x and y coordinates of another |
2227 | * for running into direct [dx, dy]. |
2225 | * object, needs to travel toward it. |
2228 | * (the opposite of crossfire's find_dir_2!) |
2226 | */ |
2229 | */ |
2227 | int |
2230 | int |
2228 | find_dir_2 (int x, int y) |
2231 | find_dir_2 (int x, int y) |
2229 | { |
2232 | { |
|
|
2233 | #if 1 // new algorithm |
|
|
2234 | // this works by putting x, y into 16 sectors, which |
|
|
2235 | // are not equal sized, but are a better approximation |
|
|
2236 | // then the old algorithm, and then using a mapping |
|
|
2237 | // table to map it into a direction value. |
|
|
2238 | // basically, it maps these comparisons to each bit |
|
|
2239 | // bit #3: x < 0 |
|
|
2240 | // bit #2: y < 0 |
|
|
2241 | // bit #1: x > y |
|
|
2242 | // bit #0: x > 2y |
|
|
2243 | |
|
|
2244 | static const uint8 dir[16] = { |
|
|
2245 | 4, 5, 4, 3, |
|
|
2246 | 2, 1, 2, 3, |
|
|
2247 | 6, 5, 6, 7, |
|
|
2248 | 8, 1, 8, 7, |
|
|
2249 | }; |
|
|
2250 | int sector = 0; |
|
|
2251 | |
|
|
2252 | // this is a bit ugly, but more likely to result in branchless code |
|
|
2253 | sector |= x < 0 ? 8 : 0; |
|
|
2254 | x = x < 0 ? -x : x; // abs |
|
|
2255 | |
|
|
2256 | sector |= y < 0 ? 4 : 0; |
|
|
2257 | y = y < 0 ? -y : y; // abs |
|
|
2258 | |
|
|
2259 | if (x > y) |
|
|
2260 | { |
|
|
2261 | sector |= 2; |
|
|
2262 | |
|
|
2263 | if (x > y * 2) |
|
|
2264 | sector |= 1; |
|
|
2265 | } |
|
|
2266 | else |
|
|
2267 | { |
|
|
2268 | if (y > x * 2) |
|
|
2269 | sector |= 1; |
|
|
2270 | else if (!y) |
|
|
2271 | return 0; // x == 0 here |
|
|
2272 | } |
|
|
2273 | |
|
|
2274 | return dir [sector]; |
|
|
2275 | #else // old algorithm |
2230 | int q; |
2276 | int q; |
2231 | |
2277 | |
2232 | if (y) |
2278 | if (y) |
2233 | q = 128 * x / y; |
2279 | q = 128 * x / y; |
2234 | else if (x) |
2280 | else if (x) |
2235 | q = 512 * x; // to make it > 309 |
2281 | q = -512 * x; // to make it > 309 |
2236 | else |
2282 | else |
2237 | return 0; |
2283 | return 0; |
2238 | |
2284 | |
2239 | if (y > 0) |
2285 | if (y > 0) |
|
|
2286 | { |
|
|
2287 | if (q < -309) return 7; |
|
|
2288 | if (q < -52) return 6; |
|
|
2289 | if (q < 52) return 5; |
|
|
2290 | if (q < 309) return 4; |
|
|
2291 | |
|
|
2292 | return 3; |
|
|
2293 | } |
|
|
2294 | else |
2240 | { |
2295 | { |
2241 | if (q < -309) return 3; |
2296 | if (q < -309) return 3; |
2242 | if (q < -52) return 2; |
2297 | if (q < -52) return 2; |
2243 | if (q < 52) return 1; |
2298 | if (q < 52) return 1; |
2244 | if (q < 309) return 8; |
2299 | if (q < 309) return 8; |
2245 | |
2300 | |
2246 | return 7; |
2301 | return 7; |
2247 | } |
2302 | } |
2248 | else |
2303 | #endif |
2249 | { |
|
|
2250 | if (q < -309) return 7; |
|
|
2251 | if (q < -52) return 6; |
|
|
2252 | if (q < 52) return 5; |
|
|
2253 | if (q < 309) return 4; |
|
|
2254 | |
|
|
2255 | return 3; |
|
|
2256 | } |
|
|
2257 | } |
2304 | } |
2258 | |
2305 | |
2259 | /* |
2306 | /* |
2260 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2307 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2261 | * between two directions (which are expected to be absolute (see absdir()) |
2308 | * between two directions (which are expected to be absolute (see absdir()) |