Prechádzať zdrojové kódy

Fixed off by one using index_cargo. Commented out some debug.

Still to do:  Move the debug into the log files, so I know
where to look when things go wrong.
bugz 5 rokov pred
rodič
commit
5d16967be3
1 zmenil súbory, kde vykonal 35 pridanie a 23 odobranie
  1. 35 23
      flexible.py

+ 35 - 23
flexible.py

@@ -1954,6 +1954,8 @@ class PlanetUpScript(object):
         self.prompt = game.buffer
         self.save = self.observer.save()
         self.nl = "\n\r"
+        self.cargo_index = { 'F': 0, 'O': 1, 'E': 2}
+        self.index_cargo = ('F', 'O', 'E')
 
         # I actually don't want the player input, but I'll grab it anyway.
         self.observer.connect("player", self.player)
@@ -2010,6 +2012,7 @@ class PlanetUpScript(object):
             # There are either no obvious planets to upgrade, 
             # or there are multiple planet choices.
 
+            # TODO:  A nice box with our planet choices inside.
             self.queue_game.put("Choose:" + self.nl)
             for s in self.planets.keys():
                 self.queue_game.put("{0} [{1}] {2}\r\n".format( s, self.planets[s]['sector'], self.planets[s]['name']))
@@ -2033,7 +2036,7 @@ class PlanetUpScript(object):
             if prompt.startswith('Land on which planet <Q to abort> ?'):
                 self.queue_player.put("{0}\r".format(self.planet_number))
             if prompt.startswith('Planet command (?=help) [D] '):
-                self.queue_game.put(self.nl + "{0} : {1}".format( self.colonists, self.cargo) + self.nl)
+                # self.queue_game.put(self.nl + "{0} : {1}".format( self.colonists, self.cargo) + self.nl)
                 self.state = 5
                 self.queue_player.put("C")
         elif self.state == 5:
@@ -2041,17 +2044,17 @@ class PlanetUpScript(object):
                 # Have we met all the needs?  If so, do it.  ;)
                 # If not, xfer the cargo on the ship to the planet and get moving!
                 ready = True
-                for i in ['F', 'O', 'E']:
+                for i in self.index_cargo: # ['F', 'O', 'E']:
                     if self.need[i] > self.cargo[i]:
                         ready = False
-                        self.queue_game.put( "Need: {0}".format(i) + self.nl)
+                        log.info("Need: {0}".format(i))
                         # break
                 if self.need['C'] > self.colonists:
-                    self.queue_game.put("Need: people" + self.nl)
+                    log.info("Need: people")
                     ready = False
-                self.queue_game.put(self.nl + "{0}".format(self.need))
+                # self.queue_game.put(self.nl + "{0}".format(self.need))
                 if ready:
-                    self.queue_game(self.nl + Boxes.alert("Party Planet Pants On!"))
+                    self.queue_game.put(self.nl + Boxes.alert("Party Planet Pants On!"))
                     self.queue_player.put('YQ')
                     self.deactivate()
                     return
@@ -2059,9 +2062,9 @@ class PlanetUpScript(object):
                 # Xfer cargo, and get ready to travel...
 
             if prompt.startswith('Planet command (?=help) [D] '):
-                self.queue_game.put(pformat(self.ship_cargo).replace("\n", self.nl) + self.nl)
-                self.queue_game.put(pformat(self.cargo).replace("\n", self.nl) + self.nl)                
-                for idx, c in enumerate(('F', 'O', 'E')):
+                # self.queue_game.put(pformat(self.ship_cargo).replace("\n", self.nl) + self.nl)
+                # self.queue_game.put(pformat(self.cargo).replace("\n", self.nl) + self.nl)                
+                for idx, c in enumerate(self.index_cargo): # ('F', 'O', 'E')):
                     if self.ship_cargo[c] > 0:
                         # Transfer Cargo, (No display), Leave [1,2, or 3], \r = All of it.
                         self.queue_player.put("TNL{0}\r".format(idx + 1))
@@ -2112,13 +2115,14 @@ class PlanetUpScript(object):
                     # Colonist
                     # [How many groups of Colonists do you want to take ([125] empty holds) ? ]
                     self.queue_player.put("L")   # "LT\r")
-                elif self.fetch in ('F', 'O', 'E'):
+                elif self.fetch in self.index_cargo: # ('F', 'O', 'E'):
                     # Port, Trade
                     self.queue_player.put("pt")
             elif re.match(r"How many holds of .+ do you want to sell", prompt):
                 # This shouldn't occur...
                 self.queue_game.put("OH NOSE!" + self.nl)
                 self.deactivate()
+                return
             elif prompt.startswith('Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ?'):
                 self.queue_game.put("N")
             elif re.match(r"How many holds of .+ do you want to buy \[\d+\]\? ", prompt):
@@ -2126,6 +2130,7 @@ class PlanetUpScript(object):
                     _, _, holds = prompt.partition('[')
                     holds, _, _ = holds.partition(']')
                     self.fetch_amount = int(holds)
+                    log.info("Buying {0} of {1}".format(holds, self.fetch))
                     self.queue_player.put("\r\r")
                     self.state = 8
                 else:
@@ -2153,24 +2158,32 @@ class PlanetUpScript(object):
                 if self.fetch == 'C':
                     # Colonist / No display Planet / Leave
                     self.queue_player.put("SNL")
-                elif self.fetch in ('F', 'O', 'E'):
+                elif self.fetch in self.index_cargo: # ('F', 'O', 'E'):
                     # Cargo, No display / Leave
                     self.queue_player.put("TNL")
-            elif prompt.startswith('(1)Ore, (2)Org or (3)Equipment ?'):
-                if self.fetch == 'F':
-                    idx = 1
-                elif self.fetch == 'O':
-                    idx = 2
-                elif self.fetch == 'E':
-                    idx = 3
-                self.queue_player.put("{0}\r\rQ".format(idx))
+            elif prompt.startswith('(1)Ore, (2)Org or (3)Equipment ?'):                
+                self.queue_player.put("{0}\r\rQ".format(self.cargo_index[self.fetch] + 1))
                 self.cargo[self.fetch] += self.fetch_amount
                 self.state = 6
 
             elif prompt.startswith('(1)Ore, (2)Org or (3)Equipment Production?'):
+                log.info("place_people: {0}".format(self.place_people))
+                safe_places = [ k for k in self.place_people.keys() if self.place_people[k] ]
+                if len(safe_places) == 0:
+                    # Ok, (GREAT)  Class "U" Vaporous/Gaseus  >:(
+                    safe_places = ['F', 'O', 'E']
+
                 # TO FIX:  Use self.place_people to decide.
                 # Ok, I'd choose, but for right now.
-                self.queue_player.put("1\r\rQ")
+                log.info("Safe {0} index {1}".format(safe_places, self.place_start))                
+                put_people = safe_places[self.place_start]
+                log.info("Use: {0}".format(put_people))
+
+                self.place_start += 1
+                if self.place_start >= len(safe_places):
+                    self.place_start = 0
+
+                self.queue_player.put("{0}\r\rQ".format(self.cargo_index[put_people] + 1))
                 self.colonists += self.fetch_amount
                 self.state = 6
 
@@ -2228,9 +2241,6 @@ class PlanetUpScript(object):
                 self.planets[number]['org'] = details[6]
                 self.planets[number]['equ'] = details[7]
         elif self.state == 4:
-            # TODO:
-            # I need the ship amounts -- so I can xfer to planet...
-
             # [  Item    Colonists  Colonists    Daily     Planet      Ship      Planet  ]
             # [Fuel Ore          0          1          0          0          0  1,000,000]
             # [Organics          0        N/A          0          0          0     10,000]
@@ -2249,6 +2259,7 @@ class PlanetUpScript(object):
                         self.ship_cargo = {}
                         self.place_people = {}
                     parts = re.split(r'\s+', work)
+                    log.info("parts: {0}".format(parts))
                     c = int(parts[1])
                     planet_has = int(parts[4])
                     self.colonists += c
@@ -2256,6 +2267,7 @@ class PlanetUpScript(object):
                     self.ship_cargo[cargo] = int(parts[5])
                     # Boolean, can we place people here?  If N/A, then don't!
                     self.place_people[cargo] = parts[2] != 'N/A'
+                    self.place_start = 0
 
         elif self.state == 5:
             # [Planet command (?=help) [D] C]