… | |
… | |
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 weight 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 | |
1033 | static struct freed_map : maptile |
1037 | static 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 | { |
… | |
… | |
2216 | { |
2218 | { |
2217 | return (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2219 | return (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); |
2218 | } |
2220 | } |
2219 | |
2221 | |
2220 | /* |
2222 | /* |
2221 | * find_dir_2(delta-x,delta-y) will return a direction in which |
2223 | * 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 |
2224 | * for running into direct [dx, dy]. |
2223 | * object, needs to travel toward it. |
2225 | * (the opposite of crossfire's find_dir_2!) |
2224 | */ |
2226 | */ |
2225 | int |
2227 | int |
2226 | find_dir_2 (int x, int y) |
2228 | find_dir_2 (int x, int y) |
2227 | { |
2229 | { |
|
|
2230 | #if 1 // new algorithm |
|
|
2231 | // this works by putting x, y into 16 sectors, which |
|
|
2232 | // are not equal sized, but are a better approximation |
|
|
2233 | // then the old algorithm, and then using a mapping |
|
|
2234 | // table to map it into a direction value. |
|
|
2235 | // basically, it maps these comparisons to each bit |
|
|
2236 | // bit #3: x < 0 |
|
|
2237 | // bit #2: y < 0 |
|
|
2238 | // bit #1: x > y |
|
|
2239 | // bit #0: x > 2y |
|
|
2240 | |
|
|
2241 | static const uint8 dir[16] = { |
|
|
2242 | 4, 5, 4, 3, |
|
|
2243 | 2, 1, 2, 3, |
|
|
2244 | 6, 5, 6, 7, |
|
|
2245 | 8, 1, 8, 7, |
|
|
2246 | }; |
|
|
2247 | int sector = 0; |
|
|
2248 | |
|
|
2249 | // this is a bit ugly, but more likely to result in branchless code |
|
|
2250 | sector |= x < 0 ? 8 : 0; |
|
|
2251 | x = x < 0 ? -x : x; // abs |
|
|
2252 | |
|
|
2253 | sector |= y < 0 ? 4 : 0; |
|
|
2254 | y = y < 0 ? -y : y; // abs |
|
|
2255 | |
|
|
2256 | if (x > y) |
|
|
2257 | { |
|
|
2258 | sector |= 2; |
|
|
2259 | |
|
|
2260 | if (x > y * 2) |
|
|
2261 | sector |= 1; |
|
|
2262 | } |
|
|
2263 | else |
|
|
2264 | { |
|
|
2265 | if (y > x * 2) |
|
|
2266 | sector |= 1; |
|
|
2267 | else if (!y) |
|
|
2268 | return 0; // x == 0 here |
|
|
2269 | } |
|
|
2270 | |
|
|
2271 | return dir [sector]; |
|
|
2272 | #else // old algorithm |
2228 | int q; |
2273 | int q; |
2229 | |
2274 | |
2230 | if (y) |
2275 | if (y) |
2231 | q = x * 100 / y; |
2276 | q = 128 * x / y; |
2232 | else if (x) |
2277 | else if (x) |
2233 | q = -300 * x; |
2278 | q = -512 * x; // to make it > 309 |
2234 | else |
2279 | else |
2235 | return 0; |
2280 | return 0; |
2236 | |
2281 | |
2237 | if (y > 0) |
2282 | if (y > 0) |
2238 | { |
2283 | { |
2239 | if (q < -242) |
2284 | if (q < -309) return 7; |
|
|
2285 | if (q < -52) return 6; |
|
|
2286 | if (q < 52) return 5; |
|
|
2287 | if (q < 309) return 4; |
|
|
2288 | |
2240 | return 3; |
2289 | return 3; |
2241 | if (q < -41) |
2290 | } |
2242 | return 2; |
2291 | else |
2243 | if (q < 41) |
2292 | { |
2244 | return 1; |
2293 | if (q < -309) return 3; |
2245 | if (q < 242) |
2294 | if (q < -52) return 2; |
2246 | return 8; |
2295 | if (q < 52) return 1; |
|
|
2296 | if (q < 309) return 8; |
|
|
2297 | |
2247 | return 7; |
2298 | return 7; |
2248 | } |
2299 | } |
2249 | |
2300 | #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 | } |
2301 | } |
2261 | |
2302 | |
2262 | /* |
2303 | /* |
2263 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2304 | * dirdiff(dir1, dir2) returns how many 45-degrees differences there is |
2264 | * between two directions (which are expected to be absolute (see absdir()) |
2305 | * between two directions (which are expected to be absolute (see absdir()) |
2265 | */ |
2306 | */ |
2266 | int |
2307 | int |
2267 | dirdiff (int dir1, int dir2) |
2308 | dirdiff (int dir1, int dir2) |
2268 | { |
2309 | { |
2269 | int d; |
|
|
2270 | |
|
|
2271 | d = abs (dir1 - dir2); |
2310 | int d = abs (dir1 - dir2); |
2272 | if (d > 4) |
|
|
2273 | d = 8 - d; |
|
|
2274 | |
2311 | |
2275 | return d; |
2312 | return d > 4 ? 8 - d : d; |
2276 | } |
2313 | } |
2277 | |
2314 | |
2278 | /* peterm: |
2315 | /* peterm: |
2279 | * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. |
2316 | * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. |
2280 | * Basically, this is a table of directions, and what directions |
2317 | * Basically, this is a table of directions, and what directions |
… | |
… | |
2738 | } |
2775 | } |
2739 | else |
2776 | else |
2740 | move_type = mt; |
2777 | move_type = mt; |
2741 | } |
2778 | } |
2742 | |
2779 | |
|
|
2780 | /* object should be a player. |
|
|
2781 | * we return the object the player has marked with the 'mark' command |
|
|
2782 | * below. If no match is found (or object has changed), we return |
|
|
2783 | * NULL. We leave it up to the calling function to print messages if |
|
|
2784 | * nothing is found. |
|
|
2785 | */ |
|
|
2786 | object * |
|
|
2787 | object::mark () const |
|
|
2788 | { |
|
|
2789 | if (contr && contr->mark && contr->mark->env == this) |
|
|
2790 | return contr->mark; |
|
|
2791 | else |
|
|
2792 | return 0; |
|
|
2793 | } |
|
|
2794 | |