Пример #1
0
 def face(self, other):
     """turn to face other entity"""
     vector = distance_to(self.entity.location, other.location)
     vector.y = 0
     if vector.sqr_mag() < 0.1:
         return
     vector = vector.unit_vector()
     newloc = Location(self.entity.location.parent)
     newloc.orientation = Quaternion(Vector3D(0, 0, 1), vector, Vector3D(0, 1, 0))
     return Operation("move", Entity(self.entity.id, location=newloc))
Пример #2
0
 def follow(self, me):
     focus_id = me.get_knowledge('focus', self.who)
     who = me.map.get(str(focus_id))
     if who is None:
         self.irrelevant = 1
         return
     dist = distance_to(me.entity.location, who.location)
     target = Location(me.entity.location.parent)
     square_dist = dist.sqr_mag()
     if square_dist > 64:
         # print "We must be far far away - run"
         target.velocity = dist.unit_vector() * 3
     elif square_dist > 25:
         # print "We must be far away - walk"
         target.velocity = dist.unit_vector()
     else:
         # print "We must be close - stop"
         target.velocity = Vector3D(0, 0, 0)
     return Operation("move", Entity(me.entity.id, location=target))
Пример #3
0
    def interlinguish_tell_verb1_operation(self, op, say):
        """Handle a sentence of the form 'Tell (me) ....'

        Accept queries about what we know. Mostly this is for debugging
        and for the time being it is useful to answer these queries no matter
        who asks."""

        # Ignore messages addressed to others
        if not self.is_talk_op_addressed_to_me_or_none(op):
            return None

        # Currently no checking for trus here.
        # We are being liberal with interpretation of "subject" and "object"
        word_subject = say[1].word
        word_predicate = say[2].word
        word_object = say[3].word
        k = self.get_knowledge(word_predicate, word_object)
        if k is None:
            pass
        # return Operation('talk',Entity(say="I know nothing about the "+predicate+" of "+object))
        else:
            k_type = type(k)
            if isinstance(k_type, Location):
                dist = distance_to(self.entity.location, k)
                dist.y = 0
                distmag = dist.mag()
                if distmag < 8:
                    k = 'right here'
                else:
                    # Currently this assumes dist is relative to TLVE
                    k = '%f metres %s' % (distmag, vector_to_compass(dist))
            elif k_type != str:
                k = 'difficult to explain'
            elif word_predicate == 'about':
                return self.face_and_address(op.to, k)
            return self.face_and_address(
                op.to,
                "The " + word_predicate + " of " + word_object + " is " + k)