Skip to content

Commit fcd7564

Browse files
committed
Sub-Space Navigation. Hazzard / Docking checking to follow. \o/
1 parent c54e1e9 commit fcd7564

10 files changed

+70
-15
lines changed

Calculators.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,40 @@ def distance(x1, y1, x2, y2):
1313
y = y2 - y1
1414
return sqrt(x * x + y * y)
1515

16+
@staticmethod
17+
def sublight_navigation(game):
18+
dest_sys = game.read_xypos()
19+
if not dest_sys:
20+
game.display("Invalid course.")
21+
game.display()
22+
return
23+
24+
game.display()
25+
game.display("Sub-light engines engaged.")
26+
game.display()
27+
game.game_map.go_to(dest_sys)
28+
29+
game.time_remaining -= 1
30+
game.star_date += 1
31+
32+
game.enterprise.short_range_scan(game)
33+
34+
if game.enterprise.docked:
35+
game.display("Lowering shields as part of docking sequence...")
36+
game.display("Enterprise successfully docked with starbase.")
37+
game.display()
38+
else:
39+
if game.game_map.klingons > 0:
40+
ShipKlingon.attack_if_you_can(game)
41+
game.display()
42+
elif not game.enterprise.repair(game):
43+
game.enterprise.damage(game, -1)
1644

1745
@staticmethod
18-
def navigation(game):
46+
def warp_navigation(game):
1947
if game.enterprise.navigation_damage > 0:
2048
max_warp_factor = 0.2 + random.randint(0, 8) / 10.0
21-
game.display("Warp engines damaged. Maximum warp factor: {0}".format(max_warp_factor))
49+
game.display(f"Warp engines damaged. Maximum warp factor: {max_warp_factor}")
2250
game.display()
2351

2452
dest_sys = game.read_sector()
@@ -53,7 +81,7 @@ def navigation(game):
5381
game.display()
5482
else:
5583
if game.game_map.klingons > 0:
56-
ShipKlingon.attack(game)
84+
ShipKlingon.attack_if_you_can(game)
5785
game.display()
5886
elif not game.enterprise.repair(game):
5987
game.enterprise.damage(game, -1)

Console.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def read_nav(self, prompt= "Helm: sector 1-64, a-h, 1-8?"):
4343
text = input(prompt + ': ')
4444
return Destination.parse_sector(text)
4545

46+
def read_xypos(self, prompt= "Helm: a-h, 1-8?"):
47+
text = input(prompt + ': ')
48+
return Destination.parse_xypos(text)
49+
4650

4751
if __name__ == '__main__':
4852
con = Con()

Controls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def phasers(game):
7575
game.game_map.remove_items(destroyed_ships)
7676
if game.game_map.klingons > 0:
7777
game.display()
78-
ShipKlingon.attack(game)
78+
ShipKlingon.attack_if_you_can(game)
7979
game.display()
8080

8181

@@ -165,7 +165,7 @@ def torpedos(game):
165165
game.display("Torpedo missed.")
166166
if len(game.game_map.get_area_klingons()) > 0:
167167
game.display()
168-
ShipKlingon.attack(game)
168+
ShipKlingon.attack_if_you_can(game)
169169
game.display()
170170

171171

MapGame.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def place(self, takers):
5555
takers[which] -= taken
5656
return tuple(takers)
5757

58-
def enterprise_in(self, glyph, dest=None):
58+
def enterprise_in(self, dest=None):
5959
''' Place the ENTERPRISE at the destination, else a
6060
random one. Return the x, y location - else False '''
6161
area = self.area()
@@ -209,10 +209,14 @@ def random_jump(self):
209209
def go_to(self, dest):
210210
if self.last_nav:
211211
self.enterprise_out()
212-
assert(isinstance(self.sector, int))
213-
self.sector = dest.sector
214-
self.xpos = dest.xpos
215-
self.ypos = dest.ypos
212+
if dest.sector > 0:
213+
self.sector = dest.sector
214+
if dest.xpos != -1:
215+
self.xpos = dest.xpos
216+
self.ypos = dest.ypos
217+
dest.sector = self.sector
218+
dest.xpos = self.xpos
219+
dest.ypos = self.ypos
216220
self.enterprise_in(dest)
217221
self.last_nav = dest
218222

MapSparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def place_glyph(self, glyph, dest=None):
131131
self.plot_glyph(xpos, ypos, glyph)
132132
return xpos, ypos
133133
else:
134-
self.plot_glyph(xpos, ypos, glyph)
134+
self.plot_glyph(dest.xpos, dest.ypos, glyph)
135135
return dest.xpos, dest.ypos
136136

137137
@staticmethod

Points.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
class Destination():
44
''' Zero based, Map navigation '''
55
def __init__(self, sector=-1, xpos=-1, ypos=-1, warp=0):
6+
if sector > 64: sector = 64 # zOuter Limits =)
7+
if xpos > 7: xpos = 7
8+
if ypos > 7: ypos = 7
9+
if xpos < 0: xpos = 0
10+
if ypos < 0: ypos = 0
11+
if warp > 10: warp = 10
12+
if warp < 0: warp = 0
613
self.warp = warp
714
self.sector = sector
815
self.xpos = xpos

Quadrant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def display_area(game, quad):
5454
sb += col
5555
sb += info[row]
5656
sb += f" -=--=--=--=--=--=--=--=- Docked: {game.enterprise.docked}\n"
57+
sb += " a b c d e f g h \n"
5758
print(sb, end='')
5859

5960
if quad.klingons > 0:

ShipKlingon.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def from_map(self, xpos, ypos):
1818
self.shield_level = 300 + random.randint(0, 199)
1919

2020
@staticmethod
21-
def attack(game):
21+
def attack_if_you_can(game):
22+
'''
23+
IF you ever find yourself in the AREA, then have at USS?
24+
'''
2225
if game.is_testing:
2326
return False
2427
from Calculators import Calc

StarTrek2020.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def run(self):
3232
aliens = random.randrange(12, 16)
3333
starbases = random.randrange(6, 8)
3434
game.game_map.randomize(starbases, stars, aliens)
35+
dest = Destination(64, 5, 5)
36+
game.game_map.go_to(dest)
37+
game.game_map.get_area(64).name = 'Outer Limits'
3538
self.print_mission()
3639

3740
self.show_strings(TrekStrings.HELM_CMDS)
@@ -47,8 +50,12 @@ def run(self):
4750
def command_prompt(self):
4851
command = self.read("Enter command: ").strip().lower()
4952
self.display()
50-
if command == "nav":
51-
Calc.navigation(game)
53+
if command == "nav": # force of habbit?
54+
Calc.warp_navigation(game)
55+
if command == "wsn":
56+
Calc.warp_navigation(game)
57+
if command == "ssn":
58+
Calc.sublight_navigation(game)
5259
elif command == "srs":
5360
game.enterprise.short_range_scan(game)
5461
elif command == "lrs":

TrekStrings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@
9898

9999
HELM_CMDS = [
100100
"--- Commands -----------------",
101-
"nav = Navigation",
101+
"wsn = Warp Speed Navigator",
102+
"ssn = Sublight Speed Navigator",
102103
"srs = Short Range Scan",
103104
"lrs = Long Range Scan",
104105
"pha = Phaser Control",

0 commit comments

Comments
 (0)