+ return course(bearing=delta.bearing(), distance=delta.distance())
+
+class course:
+ def __init__(self, bearing, distance, origin=None):
+ self.distance = distance
+ self.bearing = bearing
+ # The bearing() code we inherited from FORTRAN is actually computing
+ # clockface directions!
+ if self.bearing < 0.0:
+ self.bearing += 12.0
+ self.angle = ((15.0 - self.bearing) * 0.5235988)
+ if origin is None:
+ self.location = cartesian(game.quadrant, game.sector)
+ self.increment = coord(-math.sin(self.angle), math.cos(self.angle))
+ bigger = max(abs(self.increment.i), abs(self.increment.j))
+ self.increment /= bigger
+ self.moves = 10*self.distance*bigger +0.5
+ def next(self, grain=1):
+ "Next step on course."
+ self.moves -=1
+ self.nextlocation = self.location + self.increment
+ oldloc = (self.location/grain).roundtogrid()
+ newloc = (self.nextlocation/grain).roundtogrid()
+ self.location = self.nextlocation
+ if newloc != oldloc:
+ return True
+ else:
+ return False
+ def quadrant(self):
+ return (self.location / QUADSIZE).roundtogrid()
+ def sector(self):
+ return coord(self.location.i % QUADSIZE, self.location.j % QUADSIZE)
+ def power(self, warp):
+ return self.distance*(warp**3)*(game.shldup+1)
+ def time(self, warp):
+ return 10.0*self.distance/warp**2