Beispiel #1
0
 def findProviders(self, interface, distance):
     """
     Temporary emulation of the old way of doing things so that I can
     surgically replace findProviders.
     """
     return self.idea.obtain(
         Proximity(distance, CanSee(ProviderOf(interface))))
Beispiel #2
0
def _getIt(player, thingName, iface, radius):
    """
    Retrieve game objects answering to the given name which provide the
    given interface and are within the given distance.

    @param player: The L{Thing} from which to search.

    @param radius: How many steps to traverse (note: this is wrong, it
        will become a real distance-y thing with real game-meaning
        someday).
    @type radius: C{float}

    @param iface: The interface which objects within the required range
        must be adaptable to in order to be returned.

    @param thingName: The name of the stuff.
    @type thingName: C{str}

    @return: An iterable of L{iimaginary.IThing} providers which are found.
    """
    providerOf = ProviderOf(iface)
    canSee = CanSee(providerOf, player)
    named = Named(thingName, canSee, player)
    reachable = Reachable(named)
    proximity = Proximity(radius, reachable)
    return list(player.obtainOrReportWhyNot(proximity))
Beispiel #3
0
    def _contentConcepts(self, observer):
        """
        Get concepts for the contents of the thing wrapped by this concept.

        @param observer: The L{objects.Thing} which will observe these
            concepts.

        @return: A L{list} of the contents of C{self.original}, excluding
            C{observer}.
        """
        container = self.original
        seer = CanSee(ProviderOf(iimaginary.IThing))
        for path in self.paths:
            target = path.targetAs(iimaginary.IThing)
            if target is None:
                continue
            if pathIndicatesContainmentIn(path, container):
                if seer.shouldStillKeepGoing(path):
                    if not list(seer.moreObjectionsTo(path, None)):
                        yield target
Beispiel #4
0
    def _contentConcepts(self, observer):
        """
        Get concepts for the contents of the thing wrapped by this concept.

        @param observer: The L{objects.Thing} which will observe these
            concepts.

        @return: A L{list} of the contents of C{self.original}, excluding
            C{observer}.
        """
        container = self.original
        seer = CanSee(ProviderOf(iimaginary.IThing))
        for path in self.paths:
            target = path.targetAs(iimaginary.IThing)
            if target is None:
                continue
            if pathIndicatesContainmentIn(path, container):
                if seer.shouldStillKeepGoing(path):
                    if not list(seer.moreObjectionsTo(path, None)):
                        yield target
Beispiel #5
0
 def resolve_direction(self, player, directionName):
     """
     Identify a direction by having the player search for L{IExit}
     providers that they can see and reach.
     """
     directionName = expandDirection(directionName)
     return player.obtainOrReportWhyNot(
         Proximity(
             3.0,
             Traversability(
                 Named(directionName,
                       CanSee(ProviderOf(iimaginary.IExit)), player))))
Beispiel #6
0
 def setUp(self):
     WonderlandSetupMixin.setUp(self)
     self.observer = object()
     self.retriever = CanSee(
         Named("garden", ProviderOf(INameable), self.alice), self.observer)
Beispiel #7
0
def visualizations(viewingThing, predicate, withinDistance=3.0):
    """
    C{viewingThing} wants to look at something; it might know the name, or
    description, or placement of "something".  For example, if a player types
    C{"look at elephant"}, then "something" would be defined as "anything named
    'elephant'".

    L{visualizations} takes the thing doing the looking and a function to
    determine if a path to a thing-being-looked-at qualifies as, for example, a
    thing that C{viewingThing} might refer to as 'elephant' called
    C{predicate}, which takes a L{Path} whose target is something which may or
    may not be interesting, and returns L{True} if so and L{False} if not.

    L{visualizations} locates all of the options (for example, if there are
    multiple elephants, you might get multiple results) and returns a L{list}
    of L{IConcept} providers, each of which represents the description of one
    thing-that-can-be-looked-at which L{viewingThing} can see.

    @param viewingThing: The observer
    @type viewingThing: L{IThing}

    @param predicate: A callable which takes a L{Path} and returns L{True} if
        the targe tof that L{Path} is relevant as a focus of this
        visualization, L{False} otherwise.
    @type predicate: L{callable} taking L{Path} returning L{bool}

    @param withinDistance: Only search within the distance of this given number
        of meters.
    @type withinDistance: L{float}

    @return: a L{list} of L{IConcept}
    """
    # First, get all the things meeting the predicate's criteria that we can
    # see.
    startPaths = viewingThing.obtainOrReportWhyNot(
        _PathSatisfiesPredicate(
            predicate,
            Proximity(withinDistance,
                      CanSee(ProviderOf(IVisible),
                             viewingThing)
            )
        )
    )

    choices = []

    # Now, for each of those "visual targets", we need to gather a set of
    # related objects which might show up in its description.
    for startPath in startPaths:
        visualTargetIdea = startPath.links[-1].target

        # Now we need to apply lighting to the path, getting the IVisible (or
        # modified IVisible, if it's too dark to see it properly) that we are
        # in fact looking at.
        visible = _lightingApplied(startPath)
        if visible is not None:
            # For each visual target, query outwards from *it*, not the
            # observer, looking for other objects which may be "part" of that
            # visual target - visible along with it.  This is stuff like the
            # contents of a container, the exits from a room, et cetera.  This
            # obtain() begins from the visual target rather than the player,
            # because some of the paths the player wants to see may fold back
            # on themselves.  For example, if a player is seated on a table,
            # and there is a gun next to them on the table and they look at the
            # room, they should still be able to see the gun as part of the
            # room, despite the fact that the path goes player -> chair -> room
            # -> chair -> gun.  The chair -> room -> chair path would be
            # disallowed by the cycle-detection in obtain().
            #
            # Use of a distance predicate here is a temporary solution.  It is
            # necessary to avoid collecting all the objects in the entire
            # simulation graph but it doesn't necessarily set the bounds of
            # this obtain call correctly.  How much stuff around the target is
            # worth returning here?  How much is relevant to the thing you're
            # looking at?  Mere proximity doesn't really answer that question.
            # At some point, we should figure out what rules we want to use to
            # define "related to" for the purposes of the vision system and
            # replace this Proximity with them somehow.
            subPaths = visualTargetIdea.obtain(
                _PathSatisfiesPredicate(
                    lambda p: True,
                    Proximity(withinDistance, ProviderOf(IVisible))
                )
            )

            # However, since visual obstructions which may obscure or transform
            # the appearance of the objects related to the object being
            # observed begin from the viewer, and *not* from the object being
            # observed, we must re-introduce the viewer.
            paths = [
                Path(links=startPath.links + subPath.links)
                for subPath in subPaths

                # Hide the viewer from themselves - random objects that you
                # look at shouldn't function as mirrors.
                if not subPath.targetAs(IThing) is viewingThing
            ]
            paths.sort(key=lambda x: len(x.links))
            paths = list(path for path in paths if _isIlluminated(path))
            choices.append(visible.visualizeWithContents(paths))
    return choices