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.328 by root, Sun Apr 18 06:55:34 2010 UTC vs.
Revision 1.329 by root, Sun Apr 18 12:50:07 2010 UTC

2218{ 2218{
2219 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);
2220} 2220}
2221 2221
2222/* 2222/*
2223 * 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
2224 * an object which has subtracted the x and y coordinates of another 2224 * for running into direct [dx, dy].
2225 * object, needs to travel toward it. 2225 * (the opposite of crossfire's find_dir_2!)
2226 */ 2226 */
2227int 2227int
2228find_dir_2 (int x, int y) 2228find_dir_2 (int x, int y)
2229{ 2229{
2230 int q; 2230 int q;
2231 2231
2232 if (y) 2232 if (y)
2233 q = 128 * x / y; 2233 q = 128 * x / y;
2234 else if (x) 2234 else if (x)
2235 q = 512 * x; // to make it > 309 2235 q = -512 * x; // to make it > 309
2236 else 2236 else
2237 return 0; 2237 return 0;
2238 2238
2239 if (y > 0) 2239 if (y > 0)
2240 {
2241 if (q < -309) return 7;
2242 if (q < -52) return 6;
2243 if (q < 52) return 5;
2244 if (q < 309) return 4;
2245
2246 return 3;
2247 }
2248 else
2240 { 2249 {
2241 if (q < -309) return 3; 2250 if (q < -309) return 3;
2242 if (q < -52) return 2; 2251 if (q < -52) return 2;
2243 if (q < 52) return 1; 2252 if (q < 52) return 1;
2244 if (q < 309) return 8; 2253 if (q < 309) return 8;
2245 2254
2246 return 7; 2255 return 7;
2247 }
2248 else
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 } 2256 }
2257} 2257}
2258 2258
2259/* 2259/*
2260 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2260 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines