+
+def capture():
+ game.ididit = False # Nothing if we fail
+ game.optime = 0.0
+
+ # Make sure there is room in the brig
+ if game.brigfree == 0:
+ prout(_("Security reports the brig is already full."))
+ return
+
+ if damaged(DRADIO):
+ prout(_("Uhura- \"We have no subspace radio communication, sir.\""))
+ return
+
+ if damaged(DTRANSP):
+ prout(_("Scotty- \"Transporter damaged, sir.\""))
+ return
+
+ # find out if there are any at all
+ if game.klhere < 1:
+ prout(_("Uhura- \"Getting no response, sir.\""))
+ return
+
+ # if there is more than one Klingon, find out which one
+ # Cruddy, just takes one at random. Should ask the captain.
+ # Nah, just select the weakest one since it is most likely to
+ # surrender (Tom Almy mod)
+ klingons = [e for e in game.enemies if e.type == 'K']
+ weakest = sorted(klingons, key=lambda e: e.power)[0]
+ game.optime = 0.05 # This action will take some time
+ game.ididit = True # So any others can strike back
+
+ # check out that Klingon
+ # The algorithm isn't that great and could use some more
+ # intelligent design
+ # x = 300 + 25*skill;
+ x = game.energy / (weakest.power * len(klingons))
+ #prout(_("Stats: energy = %s, kpower = %s, klingons = %s")
+ # % (game.energy, weakest.power, len(klingons)))
+ x *= 2.5 # would originally have been equivalent of 1.4,
+ # but we want command to work more often, more humanely
+ #prout(_("Prob = %.4f" % x))
+ # x = 100; // For testing, of course!
+ if x < rnd.real(100):
+ # guess what, he surrendered!!!
+ prout(_("Klingon captain at %s surrenders.") % weakest.location)
+ i = rnd.real(200)
+ if i > 0:
+ prout(_("%d Klingons commit suicide rather than be taken captive.") % (200 - i))
+ if i > game.brigfree:
+ prout(_("%d Klingons die because there is no room for them in the brig.") % (i-game.brigfree))
+ i = game.brigfree
+ game.brigfree -= i
+ prout(_("%d captives taken") % i)
+ deadkl(weakest.location, weakest.type, game.sector)
+ if game.unwon()<=0:
+ finish(FWON)
+ return
+
+ # big surprise, he refuses to surrender
+ prout(_("Fat chance, captain!"))
+
+# Code from events.c begins here.