- # Move within the quadrant
- game.quad[game.sector.x][game.sector.y] = IHDOT
- x = game.sector.x
- y = game.sector.y
- n = 10.0*game.dist*bigger+0.5
-
- if n > 0:
- for m in range(1, n+1):
- x += deltax
- y += deltay
- w.x = x + 0.5
- w.y = y + 0.5
- if not VALID_SECTOR(w.x, w.y):
- # Leaving quadrant -- allow final enemy attack
- # Don't do it if being pushed by Nova
- if game.nenhere != 0 and not novapush:
- newcnd()
- for m in range(game.nenhere):
- finald = distance(w, game.ks[m])
- game.kavgd[m] = 0.5 * (finald + game.kdist[m])
- #
- # 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.x][game.quadrant.y].supernova:
- attack(False)
- if game.alldone:
- return
- # compute final position -- new quadrant and sector
- x = QUADSIZE*(game.quadrant.x-1)+game.sector.x
- y = QUADSIZE*(game.quadrant.y-1)+game.sector.y
- w.x = x+10.0*game.dist*bigger*deltax+0.5
- w.y = y+10.0*game.dist*bigger*deltay+0.5
- # check for edge of galaxy
- kinks = 0
- while True:
- kink = 0
- if w.x <= 0:
- w.x = -w.x + 1
- kink = 1
- if w.y <= 0:
- w.y = -w.y + 1
- kink = 1
- if w.x > GALSIZE*QUADSIZE:
- w.x = (GALSIZE*QUADSIZE*2)+1 - w.x
- kink = 1
- if w.y > GALSIZE*QUADSIZE:
- w.y = (GALSIZE*QUADSIZE*2)+1 - w.y
- kink = 1
- if kink:
- kinks = 1
- if not kink:
- 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
- return
- game.quadrant.x = (w.x+(QUADSIZE-1))/QUADSIZE
- game.quadrant.y = (w.y+(QUADSIZE-1))/QUADSIZE
- game.sector.x = w.x - QUADSIZE*(game.quadrant.x-1)
- game.sector.y = w.y - QUADSIZE*(game.quadrant.y-1)
- skip(1)
- prout(_("Entering Quadrant %s.") % game.quadrant)
- game.quad[game.sector.x][game.sector.y] = game.ship
- newqad(False)
- if game.skill>SKILL_NOVICE:
- attack(False)
- return
- iquad = game.quad[w.x][w.y]
- if iquad != IHDOT:
- # object encountered in flight path
- stopegy = 50.0*game.dist/game.optime
- game.dist = distance(game.sector, w) / (QUADSIZE * 1.0)
- if iquad in (IHT. IHK, OHC, IHS, IHR, IHQUEST):
- game.sector = w
- ram(False, iquad, game.sector)
- final = game.sector
- elif iquad == IHBLANK:
- skip(1)
- prouts(_("***RED ALERT! RED ALERT!"))
- skip(1)
- proutn("***")
- crmshp()
- proutn(_(" pulled into black hole at Sector %s") % w)
- #
- # Getting pulled into a black hole was certain
- # death in Almy's original. Stas Sergeev added a
- # possibility that you'll get timewarped instead.
- #
- n=0
- for m in range(NDEVICES):
- if game.damage[m]>0:
- n += 1
- probf=math.pow(1.4,(game.energy+game.shield)/5000.0-1.0)*math.pow(1.3,1.0/(n+1)-1.0)
- if (game.options & OPTION_BLKHOLE) and random.random()>probf:
- timwrp()
- else:
- finish(FHOLE)
- return
- else:
- # something else
- skip(1)
- crmshp()
- if iquad == IHWEB:
- proutn(_(" encounters Tholian web at %s;") % w)
- else:
- proutn(_(" blocked by object at %s;") % w)
- proutn(_("Emergency stop required "))
- prout(_("%2d units of energy.") % int(stopegy))
- game.energy -= stopegy
- final.x = x-deltax+0.5
- final.y = y-deltay+0.5
- game.sector = final
- if game.energy <= 0:
- finish(FNRG)
- return
- # We're here!
- no_quad_change()
- return
- game.dist = distance(game.sector, w) / (QUADSIZE * 1.0)
- game.sector = w
- final = game.sector
- no_quad_change()
+ # Move out
+ game.quad[game.sector.i][game.sector.j] = IHDOT
+ for m in range(course.moves):
+ course.next()
+ w = course.sector()
+ if course.origin.quadrant() != course.location.quadrant():
+ newquadrant(noattack)
+ break
+ elif check_collision(w):
+ print "Collision detected"
+ break
+ else:
+ game.sector = w
+ # We're in destination quadrant -- compute new average enemy distances
+ game.quad[game.sector.i][game.sector.j] = game.ship
+ if game.enemies:
+ for enemy in game.enemies:
+ finald = (w-enemy.kloc).distance()
+ enemy.kavgd = 0.5 * (finald + enemy.kdist)
+ enemy.kdist = finald
+ game.enemies.sort(lambda x, y: cmp(x.kdist, y.kdist))
+ if not game.state.galaxy[game.quadrant.i][game.quadrant.j].supernova:
+ attack(torps_ok=False)
+ for enemy in game.enemies:
+ enemy.kavgd = enemy.kdist
+ newcnd()
+ drawmaps(0)
+ setwnd(message_window)