示例#1
0
    def receive(self):
        args = self.commandMatch.group('args')
        if not args:
            coords = ()
        else:
            try:
                coords = map(empParse.str2Coords, string.split(args))
            except ValueError:
                viewer.Error("Bad coords.")
            pos = []
            start = coords[0]
            pos.append(coords[0])
            for i in range(1, len(coords)):
                path = empPath.best_path(coords[i - 1], coords[i])
                if path is None:
                    viewer.Error("Path could not be completed.")
                    return
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    pos.append(start)
            coords = pos

        apply(viewer.map.drawPath, tuple(coords))
示例#2
0
    def receive(self):
        args = self.commandMatch.group('args')
        if not args:
            coords = ()
        else:
            try:
                coords = map(empParse.str2Coords, string.split(args))
            except ValueError:
                viewer.Error("Bad coords.")
            pos = []
            start = coords[0]
            pos.append(coords[0])
            for i in range(1, len(coords)):
                path = empPath.best_path(coords[i-1], coords[i])
                if path is None:
                    viewer.Error("Path could not be completed.")
                    return
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    pos.append(start)
            coords = pos

        apply(viewer.map.drawPath, tuple(coords))
示例#3
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity, first[0], first[1], sDB[first].get(
                    self.commodity, "??"), last[0], last[1], sDB[last].get(
                        self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i - 1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(
                    math.floor((db.get('mob', 0) -
                                empSector.move_weight(db, self.commodity) *
                                path.cost * quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill": color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
        ##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)
示例#4
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity,
                first[0], first[1], sDB[first].get(self.commodity, "??"),
                last[0], last[1], sDB[last].get(self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i-1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(math.floor(
                    (db.get('mob', 0)
                     - empSector.move_weight(db, self.commodity)
                     * path.cost*quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill":color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)