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.326 by root, Thu Apr 15 00:56:40 2010 UTC vs.
Revision 1.330 by root, Sun Apr 18 14:01:33 2010 UTC

1035} 1035}
1036 1036
1037static struct freed_map : maptile 1037static struct freed_map : maptile
1038{ 1038{
1039 freed_map () 1039 freed_map ()
1040 : maptile (3, 3)
1040 { 1041 {
1041 path = "<freed objects map>"; 1042 path = "<freed objects map>";
1042 name = "/internal/freed_objects_map"; 1043 name = "/internal/freed_objects_map";
1043 width = 3;
1044 height = 3;
1045 no_drop = 1; 1044 no_drop = 1;
1046 no_reset = 1; 1045 no_reset = 1;
1047 1046
1048 alloc ();
1049 in_memory = MAP_ACTIVE; 1047 in_memory = MAP_ACTIVE;
1050 } 1048 }
1051 1049
1052 ~freed_map () 1050 ~freed_map ()
1053 { 1051 {
2220{ 2218{
2221 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);
2222} 2220}
2223 2221
2224/* 2222/*
2225 * 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
2226 * an object which has subtracted the x and y coordinates of another 2224 * for running into direct [dx, dy].
2227 * object, needs to travel toward it. 2225 * (the opposite of crossfire's find_dir_2!)
2228 */ 2226 */
2229int 2227int
2230find_dir_2 (int x, int y) 2228find_dir_2 (int x, int y)
2231{ 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
2236 static const uint8 dir[16] = {
2237 4, 5, 4, 3,
2238 2, 1, 2, 3,
2239 6, 5, 6, 7,
2240 8, 1, 8, 7,
2241 };
2242 int sector = 0;
2243
2244 // this is a bit ugly, but more likely to result in branchless code
2245 sector |= x < 0 ? 8 : 0;
2246 x = x < 0 ? -x : x; // abs
2247
2248 sector |= y < 0 ? 4 : 0;
2249 y = y < 0 ? -y : y; // abs
2250
2251 if (x > y)
2252 {
2253 sector |= 2;
2254
2255 if (x > y * 2)
2256 sector |= 1;
2257 }
2258 else
2259 {
2260 if (y > x * 2)
2261 sector |= 1;
2262 else if (!y)
2263 return 0; // x == 0 here
2264 }
2265
2266 return dir [sector];
2267#else // old algorithm
2232 int q; 2268 int q;
2233 2269
2234 if (y) 2270 if (y)
2235 q = x * 100 / y; 2271 q = 128 * x / y;
2236 else if (x) 2272 else if (x)
2237 q = -300 * x; 2273 q = -512 * x; // to make it > 309
2238 else 2274 else
2239 return 0; 2275 return 0;
2240 2276
2241 if (y > 0) 2277 if (y > 0)
2242 { 2278 {
2243 if (q < -242) 2279 if (q < -309) return 7;
2280 if (q < -52) return 6;
2281 if (q < 52) return 5;
2282 if (q < 309) return 4;
2283
2244 return 3; 2284 return 3;
2245 if (q < -41) 2285 }
2246 return 2; 2286 else
2247 if (q < 41) 2287 {
2248 return 1; 2288 if (q < -309) return 3;
2249 if (q < 242) 2289 if (q < -52) return 2;
2250 return 8; 2290 if (q < 52) return 1;
2291 if (q < 309) return 8;
2292
2251 return 7; 2293 return 7;
2252 } 2294 }
2253 2295#endif
2254 if (q < -242)
2255 return 7;
2256 if (q < -41)
2257 return 6;
2258 if (q < 41)
2259 return 5;
2260 if (q < 242)
2261 return 4;
2262
2263 return 3;
2264} 2296}
2265 2297
2266/* 2298/*
2267 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2299 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2268 * between two directions (which are expected to be absolute (see absdir()) 2300 * between two directions (which are expected to be absolute (see absdir())
2269 */ 2301 */
2270int 2302int
2271dirdiff (int dir1, int dir2) 2303dirdiff (int dir1, int dir2)
2272{ 2304{
2273 int d;
2274
2275 d = abs (dir1 - dir2); 2305 int d = abs (dir1 - dir2);
2276 if (d > 4)
2277 d = 8 - d;
2278 2306
2279 return d; 2307 return d > 4 ? 8 - d : d;
2280} 2308}
2281 2309
2282/* peterm: 2310/* peterm:
2283 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. 2311 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster.
2284 * Basically, this is a table of directions, and what directions 2312 * Basically, this is a table of directions, and what directions

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines