ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.329 by root, Sun Apr 18 12:50:07 2010 UTC vs.
Revision 1.336 by root, Wed Apr 28 11:19:09 2010 UTC

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 */
1819int 1819int
1820check_move_on (object *op, object *originator) 1820check_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 ((flags & INS_NO_AUTO_EXIT)
1890 && (tmp->type == EXIT || tmp->type == TELEPORTER
1891 || tmp->type == HOLE || tmp->type == TRAPDOOR)) //TODO: temporary, fix exits instead
1892 continue;
1893
1889 move_apply (tmp, op, originator); 1894 move_apply (tmp, op, originator);
1890 1895
1891 if (op->destroyed ()) 1896 if (op->destroyed ())
1892 return 1; 1897 return 1;
1893 1898
2225 * (the opposite of crossfire's find_dir_2!) 2230 * (the opposite of crossfire's find_dir_2!)
2226 */ 2231 */
2227int 2232int
2228find_dir_2 (int x, int y) 2233find_dir_2 (int x, int y)
2229{ 2234{
2235#if 1 // new algorithm
2236 // this works by putting x, y into 16 sectors, which
2237 // are not equal sized, but are a better approximation
2238 // then the old algorithm, and then using a mapping
2239 // table to map it into a direction value.
2240 // basically, it maps these comparisons to each bit
2241 // bit #3: x < 0
2242 // bit #2: y < 0
2243 // bit #1: x > y
2244 // bit #0: x > 2y
2245
2246 static const uint8 dir[16] = {
2247 4, 5, 4, 3,
2248 2, 1, 2, 3,
2249 6, 5, 6, 7,
2250 8, 1, 8, 7,
2251 };
2252 int sector = 0;
2253
2254 // this is a bit ugly, but more likely to result in branchless code
2255 sector |= x < 0 ? 8 : 0;
2256 x = x < 0 ? -x : x; // abs
2257
2258 sector |= y < 0 ? 4 : 0;
2259 y = y < 0 ? -y : y; // abs
2260
2261 if (x > y)
2262 {
2263 sector |= 2;
2264
2265 if (x > y * 2)
2266 sector |= 1;
2267 }
2268 else
2269 {
2270 if (y > x * 2)
2271 sector |= 1;
2272 else if (!y)
2273 return 0; // x == 0 here
2274 }
2275
2276 return dir [sector];
2277#else // old algorithm
2230 int q; 2278 int q;
2231 2279
2232 if (y) 2280 if (y)
2233 q = 128 * x / y; 2281 q = 128 * x / y;
2234 else if (x) 2282 else if (x)
2252 if (q < 52) return 1; 2300 if (q < 52) return 1;
2253 if (q < 309) return 8; 2301 if (q < 309) return 8;
2254 2302
2255 return 7; 2303 return 7;
2256 } 2304 }
2305#endif
2257} 2306}
2258 2307
2259/* 2308/*
2260 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2309 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2261 * between two directions (which are expected to be absolute (see absdir()) 2310 * between two directions (which are expected to be absolute (see absdir())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines