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.327 by root, Fri Apr 16 02:32:25 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 = x * 100 / y; 2233 q = 128 * x / y;
2234 else if (x) 2234 else if (x)
2235 q = -300 * x; 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 { 2240 {
2241 if (q < -242) 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
2242 return 3; 2246 return 3;
2243 if (q < -41) 2247 }
2244 return 2; 2248 else
2245 if (q < 41) 2249 {
2246 return 1; 2250 if (q < -309) return 3;
2247 if (q < 242) 2251 if (q < -52) return 2;
2248 return 8; 2252 if (q < 52) return 1;
2253 if (q < 309) return 8;
2254
2249 return 7; 2255 return 7;
2250 } 2256 }
2251
2252 if (q < -242)
2253 return 7;
2254 if (q < -41)
2255 return 6;
2256 if (q < 41)
2257 return 5;
2258 if (q < 242)
2259 return 4;
2260
2261 return 3;
2262} 2257}
2263 2258
2264/* 2259/*
2265 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2260 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2266 * between two directions (which are expected to be absolute (see absdir()) 2261 * between two directions (which are expected to be absolute (see absdir())
2267 */ 2262 */
2268int 2263int
2269dirdiff (int dir1, int dir2) 2264dirdiff (int dir1, int dir2)
2270{ 2265{
2271 int d;
2272
2273 d = abs (dir1 - dir2); 2266 int d = abs (dir1 - dir2);
2274 if (d > 4)
2275 d = 8 - d;
2276 2267
2277 return d; 2268 return d > 4 ? 8 - d : d;
2278} 2269}
2279 2270
2280/* peterm: 2271/* peterm:
2281 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. 2272 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster.
2282 * Basically, this is a table of directions, and what directions 2273 * Basically, this is a table of directions, and what directions

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines