瀏覽代碼

Get what planet has (and ship), get what planet needs.

bugz 5 年之前
父節點
當前提交
b738ed6f32
共有 1 個文件被更改,包括 105 次插入13 次删除
  1. 105 13
      flexible.py

+ 105 - 13
flexible.py

@@ -1869,8 +1869,6 @@ class ScriptTerror(object):
 
         self.target_sector = None
         
-
-
     def whenDone(self):
         self.defer = defer.Deferred()
         # Call this to chain something after we exit.
@@ -1968,13 +1966,14 @@ class PlanetUpScript(object):
 
     def game_prompt(self, prompt):
         if self.state == 2 and re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
+            self.game.to_player = True
             # For now we output the information, and exit
             # self.queue_game.put("{0}\r\n".format(self.planets))
             self.queue_game.put(pformat(self.planets).replace("\n", self.nl) + self.nl)
 
             if len(self.planets) == 0:
                 # Ok, this is easy.
-                self.queue_game.put(Boxes.alert("You don't have any planets?  You poor dear.", base="red"))
+                self.queue_game.put(Boxes.alert("You don't have any planets?  You poor, poor dear.", base="red"))
                 self.deactivate()
                 return
 
@@ -1990,23 +1989,67 @@ class PlanetUpScript(object):
             if len(obvious) == 1:
                 # There is one.
                 self.planet_number = obvious[0]
-                self.planet_sector = self.planets[self.number]['sector']
-                self.planet_name = self.planets[self.number]['name']
+                self.planet_sector = self.planets[self.planet_number]['sector']
+                self.planet_name = self.planets[self.planet_number]['name']
                 self.state = 4
                 # begin landing procedure ...
                 self.queue_player.put("L")
-            else:
-                # There are either no obvious planets to upgrade, 
-                # or there are multiple planet choices.
+                return
+            
+            # There are either no obvious planets to upgrade, 
+            # or there are multiple planet choices.
+
+            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']))
 
-                self.queue_game.put()
-                pass
+            ask = PlayerInput(self.game)
+            d = ask.prompt("Choose a planet", 3, name="planet", digits=True)
 
-            self.queue_game.put(Boxes.alert("Choices: {0}".format(obvious)))
+            # Display the user's input
+            d.addCallback(self.planet_chosen)
+        elif self.state == 3:
+            if prompt.startswith('Do you want to engage the TransWarp drive? '):
+                self.queue_player.put("N")
+            if prompt.startswith('Engage the Autopilot? (Y/N/Single step/Express) [Y]'):
+                self.queue_player.put("E")
+            elif prompt.startswith('Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ?'):
+                self.queue_player.put("N")
+            elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):             
+                # We're here!
+                self.state = 4
+                self.queue_player.put("L")
+        elif self.state == 4:
+            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.state = 5
+                self.queue_player.put("C")
+        elif self.state == 5:
+            if prompt.startswith('Do you wish to construct one? '):
+                self.queue_game.put(self.nl + "{0}".format(self.need))
+                self.queue_player.put("N")
+                self.deactivate()
 
-            # Wooah Hoss!  What if there's more then one planet in this sector?!
 
+    def planet_chosen(self, choice: str):
+        if choice.strip() == '':
             self.deactivate()
+        else:
+            self.planet_number = int(choice)
+            if self.planet_number in self.planets:
+                # Ok, this'll work
+                self.planet_sector = self.planets[self.planet_number]['sector']
+                self.planet_name = self.planets[self.planet_number]['name']
+                if self.current_sector == self.planet_sector:
+                    self.state = 4
+                    self.queue_player.put("L")
+                else:
+                    self.state = 3
+                    self.queue_player.put("{0}\r".format(self.planet_sector))
+            else:
+                self.deactivate()
 
     def game_line(self, line):
         if self.state == 1:
@@ -2033,13 +2076,62 @@ class PlanetUpScript(object):
                 # [ 10202   #3    Home of Bugz             Class M, Earth Type        No Citadel]
                 # [   ---   (1M)           144   49   26   145    75    12         10          0]
                 details = re.split(r"\s+", line.strip())
+                # OK:  Likely, I'm not going to use these numbers AT ALL.  
                 self.planets[number]['population'] = details[1].replace('(', '').replace(')', '')
                 # Ok, there's going to have to be some sort of modifier (K, M, etc.)
                 # to these numbers.  Beware!
                 self.planets[number]['ore'] = details[5]
                 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]
+            # [Equipment         0        500          0        125        125    100,000]
+            # [Fighters        N/A        N/A          0          0        400  1,000,000]
+            items = ['Fuel Ore', 'Organics', 'Equipment']
+            for i in items:
+                if line.startswith(i):
+                    cargo = line[0].upper()
+                    work = line.replace(',', '')
+                    if i == 'Fuel Ore':
+                        work = work.replace(i, 'Fuel')
+                        self.colonists = 0
+                        self.cargo = {}
+                        self.need = {}
+                        self.ship_cargo = {}
+                    parts = re.split(r'\s+', work)
+                    c = int(parts[1])
+                    planet_has = int(parts[4])
+                    self.colonists += c
+                    self.cargo[cargo] = planet_has
+                    self.ship_carg[cargo] = int(parts[5])
+        elif self.state == 5:
+            # [Planet command (?=help) [D] C]
+            # [Be patient, your Citadel is not yet finished.]
+            if line.startswith('Be patient, your Citadel is not yet finished.'):
+                # Ah HA!
+                self.queue_game.put(self.nl + Boxes.alert("Patience!") + self.nl)
+                self.queue_player.put("Q")  # quit Planet menu.
+                self.deactivate()
+            else:
+                items = ['Colonists', 'Fuel Ore', 'Organics', 'Equipment']                
+                work = line.replace(',', '').replace(' units of', '').strip()
+                #              800,000 Colonists to support the construction,
+                #                   500 units of Fuel Ore,
+                #                    300 units of Organics,
+                #                   600 units of Equipment and     
+                for i in items:
+                    if i in line:
+                        count = int(work.split()[0])
+                        k = i[0].upper()
+                        # keep colonists in same units.
+                        if k == 'C':
+                            count //= 1000
+                        self.need[k] = count
 
     def __del__(self):
         log.debug("PlanetUpScript {0} RIP".format(self))