chiark / gitweb /
show last vessel if we aren't on a vessel
[ypp-sc-tools.db-test.git] / yoweb-scrape
index b12b5032fcb9eb7c09cfdfa867dbd34f57eb8e65..ed9533ef51c513b4628673712880bc9a0b0b1e3c 100755 (executable)
@@ -438,6 +438,7 @@ class ChatLogTracker:
                self._progress = [0, os.fstat(self._f.fileno()).st_size]
                self._disembark_myself()
                self._need_redisplay = False
+               self._lastvessel = None
 
        def _disembark_myself(self):
                self._v = None
@@ -620,7 +621,7 @@ class ChatLogTracker:
                        pn = self._myself.name
                        vn = m.group(1)
                        v = self._vessel_lookup(vn, timestamp, dm, create=True)
-                       self._vessel = vn
+                       self._lastvessel = self._vessel = vn
                        self._v = v
                        ob_x(pn, 'we boarded')
                        self.expire_garbage(timestamp)
@@ -807,14 +808,22 @@ class ChatLogTracker:
        def myname(self):
                # returns our pirate name
                return self._myself.name
-       def vessel(self):
-               # returns the vessel we're aboard or None
+       def vesselname(self):
+               # returns the vessel name we're aboard or None
                return self._vessel
-       def aboard(self):
-               # returns a list of PirateAboard sorted by name
-               if self._v is None: return []
-               return [ self._v[pn]
-                        for pn in sorted(self._v.keys())
+       def lastvesselname(self):
+               # returns the last vessel name we were aboard or None
+               return self._lastvessel
+       def aboard(self, vesselname=True):
+               # returns a list of PirateAboard the vessel
+               #  sorted by pirate name
+               #  you can pass this None and you'll get []
+               #  or True for the current vessel (which is the default)
+               if vesselname is True: v = self._v
+               else: v = self._vl.get(vesselname.title())
+               if v is None: return []
+               return [ v[pn]
+                        for pn in sorted(v.keys())
                         if not pn.startswith('#') ]
 
 #---------- implementations of actual operation modes ----------
@@ -980,9 +989,18 @@ def do_ship_aid(args, bu):
 
                s = "%s" % track.myname()
 
-               vn = track.vessel()
-               if vn is None: s += " not on a vessel"
-               else: s += " on board the %s" % vn
+               vn = track.vesselname()
+               if vn is not None:
+                       s += " on board the %s" % vn
+
+               if vn is None:
+                       vn = track.lastvesselname()
+                       if vn is not None:
+                               s += " ashore from the %s" % vn
+
+               if vn is None:
+                       s += " not on a vessel"
+
                s += " at %s\n" % time.strftime("%Y-%m-%d %H:%M:%S")
 
                tbl = StandingsTable()