55from ShipKlingon import ShipKlingon
66from Points import Destination
77from Quadrant import Quadrant
8+ from ErrorCollision import ErrorEnterpriseCollision
89
910import MapSparse
1011
@@ -57,19 +58,30 @@ def place(self, takers):
5758
5859 def enterprise_in (self , dest = None ):
5960 ''' Place the ENTERPRISE at the destination, else a
60- random one. Return the x, y location - else False '''
61- area = self .area ()
61+ random one.
62+
63+ Will raise an ErrorEnterpriseCollision, upon same.
64+
65+ Returns the final x, y location upon success '''
66+ area = self .pw_area ()
67+ berror = False
6268 if area :
69+ for p in area ._pieces :
70+ if p .xpos == dest .xpos and p .ypos == dest .ypos :
71+ pos = area .place_glyph (Glyphs .ENTERPRISE )
72+ berror = p .glyph
6373 pos = area .place_glyph (Glyphs .ENTERPRISE , dest )
74+ if berror :
75+ raise ErrorEnterpriseCollision (berror )
6476 if pos :
6577 return pos
6678 return False
6779
6880 def enterprise_location (self ):
6981 ''' Get Enterprise location. False if not found. '''
70- area = self .area ()
82+ area = self .pw_area ()
7183 if area :
72- for obj in area .objs :
84+ for obj in area ._pieces :
7385 if obj .glyph == Glyphs .ENTERPRISE :
7486 return obj .xpos , obj .ypos
7587 return False
@@ -82,7 +94,7 @@ def enterprise_out(self):
8294
8395 def place_glyph (self , glyph , dest = None ):
8496 ''' Place the glyph as the destination, else a random one '''
85- area = self .area ()
97+ area = self .pw_area ()
8698 if area :
8799 pos = area .place_glyph (self , glyph , dest )
88100 if pos :
@@ -91,11 +103,11 @@ def place_glyph(self, glyph, dest=None):
91103
92104 def remove (self , xpos , ypos ):
93105 ''' Remove ANYTHING from the present AREA '''
94- area = self .area ()
106+ area = self .pw_area ()
95107 if area :
96108 area .remove (xpos , ypos )
97109
98- def area (self ):
110+ def pw_area (self ):
99111 '''
100112 Return the internal / sparsely populated AREA object.
101113 Return an empty / default AREA upon coordinate error.
@@ -119,9 +131,9 @@ def scan_quad(self, sector):
119131 def _count_area (self , glyph ):
120132 ''' Tally the number of glyphs in the AREA '''
121133 count = 0
122- area = self .area ()
134+ area = self .pw_area ()
123135 if area :
124- for obj in area .objs :
136+ for obj in area ._pieces :
125137 if obj .glyph == glyph :
126138 count += 1
127139 return count
@@ -134,7 +146,7 @@ def update_counts(self):
134146 self .stars += area .count_glyphs (Glyphs .STAR )
135147
136148 def remove_items (self , removed ):
137- area = self .area ()
149+ area = self .pw_area ()
138150 for obj in removed :
139151 area .remove (obj .xpos , obj .ypos )
140152 self .update_counts ()
@@ -144,7 +156,7 @@ def get_area_klingons(self):
144156 Return this Area's data for Kingons, in an array.
145157 '''
146158 results = []
147- area = self .area ()
159+ area = self .pw_area ()
148160 for data in area .get_data (Glyphs .KLINGON ):
149161 ship = ShipKlingon ()
150162 ship .from_map (data .xpos , data .ypos )
@@ -166,14 +178,14 @@ def get_area_objects(self):
166178 NOTE: Changes to this collection will update Area
167179 content.
168180 '''
169- area = self .area ()
170- return area .objs
181+ area = self .pw_area ()
182+ return area ._pieces
171183
172184 def game_id (self , piece ):
173185 '''
174186 Uniquely identify a game piece / object.
175187 '''
176- area = self .area ()
188+ area = self .pw_area ()
177189 num = (area .number * 100 ) + (piece .ypos * 8 ) + piece .xpos
178190 return f"{ piece .glyph [1 ]} x{ num } "
179191
@@ -188,25 +200,29 @@ def get_all(self, glyph):
188200 return results
189201
190202 def quad (self ):
191- area = self .area ()
203+ area = self .pw_area ()
192204 return Quadrant .from_area (area )
193205
194206 def get_map (self ):
195207 '''
196208 Generate AREA map of the present sector.
197209 '''
198- area = self .area ()
210+ area = self .pw_area ()
199211 return area .get_map ()
200212
201213 def random_jump (self ):
202214 dest = Destination (
203- random .randint (1 , 65 ),
215+ random .randint (1 , 64 ),
204216 random .randint (0 , 7 ),
205217 random .randint (0 , 7 )
206218 )
207- self .go_to (dest )
219+ self ._go_to (dest )
208220
209- def go_to (self , dest ):
221+ def _go_to (self , dest ):
222+ '''
223+ Place the main player (Enterprise, for now) into the Area.
224+ Returns the final, effective, player location.
225+ '''
210226 if self .last_nav :
211227 self .enterprise_out ()
212228 if dest .sector > 0 :
@@ -217,8 +233,11 @@ def go_to(self, dest):
217233 dest .sector = self .sector
218234 dest .xpos = self .xpos
219235 dest .ypos = self .ypos
220- self .enterprise_in (dest )
236+ pos = self .enterprise_in (dest )
237+ dest .xpos = pos [0 ]
238+ dest .ypos = pos [1 ]
221239 self .last_nav = dest
240+ return dest
222241
223242 def randomize (self , bases = None , stars = None , aliens = None ):
224243 if not aliens :
0 commit comments