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.324 by root, Mon Apr 12 05:22:37 2010 UTC vs.
Revision 1.334 by root, Fri Apr 23 09:22:46 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;
483 483
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
489 LOG (llevDebug, "updating carrying got %ld, expected %ld (%s)\n",
490 (long long)sum, (long long)carrying, debug_desc ());
491
488 carrying = sum; 492 carrying = sum;
489 493
490 if (object *pl = visible_to ()) 494 if (object *pl = visible_to ())
491 if (pl != this) // player is handled lazily 495 if (pl != this) // player is handled lazily
492 esrv_update_item (UPD_WEIGHT, pl, this); 496 esrv_update_item (UPD_WEIGHT, pl, this);
1031} 1035}
1032 1036
1033static struct freed_map : maptile 1037static struct freed_map : maptile
1034{ 1038{
1035 freed_map () 1039 freed_map ()
1040 : maptile (3, 3)
1036 { 1041 {
1037 path = "<freed objects map>"; 1042 path = "<freed objects map>";
1038 name = "/internal/freed_objects_map"; 1043 name = "/internal/freed_objects_map";
1039 width = 3;
1040 height = 3;
1041 no_drop = 1; 1044 no_drop = 1;
1042 no_reset = 1; 1045 no_reset = 1;
1043 1046
1044 alloc ();
1045 in_memory = MAP_ACTIVE; 1047 in_memory = MAP_ACTIVE;
1046 } 1048 }
1047 1049
1048 ~freed_map () 1050 ~freed_map ()
1049 { 1051 {
1570 */ 1572 */
1571 1573
1572 /* 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 */
1573 if (!(flag & INS_NO_WALK_ON) && op->is_head ()) 1575 if (!(flag & INS_NO_WALK_ON) && op->is_head ())
1574 { 1576 {
1575 if (check_move_on (op, originator)) 1577 if (check_move_on (op, originator, flag))
1576 return 0; 1578 return 0;
1577 1579
1578 /* 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
1579 * walk on's. 1581 * walk on's.
1580 */ 1582 */
1581 for (object *tmp = op->more; tmp; tmp = tmp->more) 1583 for (object *tmp = op->more; tmp; tmp = tmp->more)
1582 if (check_move_on (tmp, originator)) 1584 if (check_move_on (tmp, originator, flag))
1583 return 0; 1585 return 0;
1584 } 1586 }
1585 1587
1586 return op; 1588 return op;
1587} 1589}
1813 * 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
1814 * 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
1815 * on top. 1817 * on top.
1816 */ 1818 */
1817int 1819int
1818check_move_on (object *op, object *originator) 1820check_move_on (object *op, object *originator, int flags)
1819{ 1821{
1820 if (op->flag [FLAG_NO_APPLY]) 1822 if (op->flag [FLAG_NO_APPLY])
1821 return 0; 1823 return 0;
1822 1824
1823 object *tmp; 1825 object *tmp;
1882 1884
1883 /* Basically same logic as above, except now for actual apply. */ 1885 /* Basically same logic as above, except now for actual apply. */
1884 if ((!op->move_type && tmp->move_on & MOVE_WALK) || 1886 if ((!op->move_type && tmp->move_on & MOVE_WALK) ||
1885 ((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))
1886 { 1888 {
1889 if (tmp->type == EXIT && (flags & INS_NO_AUTO_EXIT)) //TODO: temporary, fix exits instead
1890 continue;
1891
1887 move_apply (tmp, op, originator); 1892 move_apply (tmp, op, originator);
1888 1893
1889 if (op->destroyed ()) 1894 if (op->destroyed ())
1890 return 1; 1895 return 1;
1891 1896
2216{ 2221{
2217 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);
2218} 2223}
2219 2224
2220/* 2225/*
2221 * 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
2222 * an object which has subtracted the x and y coordinates of another 2227 * for running into direct [dx, dy].
2223 * object, needs to travel toward it. 2228 * (the opposite of crossfire's find_dir_2!)
2224 */ 2229 */
2225int 2230int
2226find_dir_2 (int x, int y) 2231find_dir_2 (int x, int y)
2227{ 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
2228 int q; 2276 int q;
2229 2277
2230 if (y) 2278 if (y)
2231 q = x * 100 / y; 2279 q = 128 * x / y;
2232 else if (x) 2280 else if (x)
2233 q = -300 * x; 2281 q = -512 * x; // to make it > 309
2234 else 2282 else
2235 return 0; 2283 return 0;
2236 2284
2237 if (y > 0) 2285 if (y > 0)
2238 { 2286 {
2239 if (q < -242) 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
2240 return 3; 2292 return 3;
2241 if (q < -41) 2293 }
2242 return 2; 2294 else
2243 if (q < 41) 2295 {
2244 return 1; 2296 if (q < -309) return 3;
2245 if (q < 242) 2297 if (q < -52) return 2;
2246 return 8; 2298 if (q < 52) return 1;
2299 if (q < 309) return 8;
2300
2247 return 7; 2301 return 7;
2248 } 2302 }
2249 2303#endif
2250 if (q < -242)
2251 return 7;
2252 if (q < -41)
2253 return 6;
2254 if (q < 41)
2255 return 5;
2256 if (q < 242)
2257 return 4;
2258
2259 return 3;
2260} 2304}
2261 2305
2262/* 2306/*
2263 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2307 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2264 * between two directions (which are expected to be absolute (see absdir()) 2308 * between two directions (which are expected to be absolute (see absdir())
2265 */ 2309 */
2266int 2310int
2267dirdiff (int dir1, int dir2) 2311dirdiff (int dir1, int dir2)
2268{ 2312{
2269 int d;
2270
2271 d = abs (dir1 - dir2); 2313 int d = abs (dir1 - dir2);
2272 if (d > 4)
2273 d = 8 - d;
2274 2314
2275 return d; 2315 return d > 4 ? 8 - d : d;
2276} 2316}
2277 2317
2278/* peterm: 2318/* peterm:
2279 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. 2319 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster.
2280 * Basically, this is a table of directions, and what directions 2320 * Basically, this is a table of directions, and what directions
2738 } 2778 }
2739 else 2779 else
2740 move_type = mt; 2780 move_type = mt;
2741} 2781}
2742 2782
2783/* object should be a player.
2784 * we return the object the player has marked with the 'mark' command
2785 * below. If no match is found (or object has changed), we return
2786 * NULL. We leave it up to the calling function to print messages if
2787 * nothing is found.
2788 */
2789object *
2790object::mark () const
2791{
2792 if (contr && contr->mark && contr->mark->env == this)
2793 return contr->mark;
2794 else
2795 return 0;
2796}
2797

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines