- for enemy in game.enemies:
- enemy.kavgd = enemy.kdist
- newcnd()
- drawmaps(0)
- setwnd(message_window)
- w.i = w.j = 0
- if game.inorbit:
- prout(_("Helmsman Sulu- \"Leaving standard orbit.\""))
- game.inorbit = False
- angle = ((15.0 - course.bearing) * 0.5235988)
- deltax = -math.sin(angle)
- deltay = math.cos(angle)
- if math.fabs(deltax) > math.fabs(deltay):
- bigger = math.fabs(deltax)
- else:
- bigger = math.fabs(deltay)
- deltay /= bigger
- deltax /= bigger
- # If tractor beam is to occur, don't move full distance
- if game.state.date+game.optime >= scheduled(FTBEAM):
- trbeam = True
- game.condition = "red"
- course.distance = course.distance*(scheduled(FTBEAM)-game.state.date)/game.optime + 0.1
- game.optime = scheduled(FTBEAM) - game.state.date + 1e-5
- # Move within the quadrant
- game.quad[game.sector.i][game.sector.j] = IHDOT
- x = game.sector.i
- y = game.sector.j
- for m in range(course.moves):
- x += deltax
- y += deltay
- w.i = int(round(x))
- w.j = int(round(y))
- if not w.valid_sector():
- # Leaving quadrant -- allow final enemy attack
- # Don't do it if being pushed by Nova
- if len(game.enemies) != 0 and not novapush:
- newcnd()
- for enemy in game.enemies:
- finald = (w - enemy.kloc).distance()
- enemy.kavgd = 0.5 * (finald + enemy.kdist)
- #
- # Stas Sergeev added the condition
- # that attacks only happen if Klingons
- # are present and your skill is good.
- #
- if game.skill > SKILL_GOOD and game.klhere > 0 and not game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
- attack(torps_ok=False)
- if game.alldone:
- return
- # check for edge of galaxy
- w = course.final
- kinks = 0
- while True:
- kink = False
- if w.i < 0:
- w.i = -w.i
- kink = True
- if w.j < 0:
- w.j = -w.j
- kink = True
- if w.i >= GALSIZE*QUADSIZE:
- w.i = (GALSIZE*QUADSIZE*2) - w.i
- kink = True
- if w.j >= GALSIZE*QUADSIZE:
- w.j = (GALSIZE*QUADSIZE*2) - w.j
- kink = True
- if kink:
- kinks += 1
- else:
- break
- if kinks:
- game.nkinks += 1
- if game.nkinks == 3:
- # Three strikes -- you're out!
- finish(FNEG3)
- return
- skip(1)
- prout(_("YOU HAVE ATTEMPTED TO CROSS THE NEGATIVE ENERGY BARRIER"))
- prout(_("AT THE EDGE OF THE GALAXY. THE THIRD TIME YOU TRY THIS,"))
- prout(_("YOU WILL BE DESTROYED."))
- # Compute final position in new quadrant
- if trbeam: # Don't bother if we are to be beamed
+ if game.alldone:
+ return
+ # check for edge of galaxy
+ kinks = 0
+ while True:
+ kink = False
+ if course.final.i < 0:
+ course.final.i = -course.final.i
+ kink = True
+ if course.final.j < 0:
+ course.final.j = -course.final.j
+ kink = True
+ if course.final.i >= GALSIZE*QUADSIZE:
+ course.final.i = (GALSIZE*QUADSIZE*2) - course.final.i
+ kink = True
+ if course.final.j >= GALSIZE*QUADSIZE:
+ course.final.j = (GALSIZE*QUADSIZE*2) - course.final.j
+ kink = True
+ if kink:
+ kinks += 1
+ else:
+ break
+ if kinks:
+ game.nkinks += 1
+ if game.nkinks == 3:
+ # Three strikes -- you're out!
+ finish(FNEG3)