+ return course(delta.distance(), delta.bearing(), isprobe=isprobe)
+
+class course:
+ # Eventually, we want to consolidate all course compuation here,
+ # including for torpedos and the Enterprise.
+ def __init__(self, distance, bearing, warp=None, isprobe=False):
+ # Course actually laid in -- thisis straight from the old getcd().
+ self.distance = distance
+ self.bearing = bearing
+ self.warp = warp or game.warpfac
+ self.isprobe = isprobe
+ # This odd relic suggests that the bearing() code we inherited from
+ # FORTRAN is actually computing clockface directions.
+ if self.bearing < 0.0:
+ self.bearing += 12.0
+ # This code was moved from the probe() routine
+ if isprobe:
+ angle = ((15.0 - self.bearing) * 0.5235988)
+ self.increment = coord(-math.sin(angle), math.cos(angle))
+ bigger = max(abs(self.increment.i), abs(self.increment.j))
+ self.increment /= bigger
+ self.location = coord(game.quadrant.i*QUADSIZE + game.sector.i,
+ game.quadrant.j*QUADSIZE + game.sector.j)
+ self.loc = copy.copy(game.quadrant)
+ self.moves = 10.0*self.distance*bigger +0.5
+ def power(self):
+ return self.distance*(self.warp**3)*(game.shldup+1)
+ def time(self):
+ return 10.0*self.distance/self.warp**2
+ def next(self):
+ "Next location on course, currently only at quadrant granularity."
+ self.location += self.increment
+ newloc = (self.location / float(QUADSIZE)).snaptogrid()
+ if not newloc == self.loc:
+ self.loc = newloc
+ return True
+ else:
+ return False