예제 #1
0
    def _create_initial_mod(self):
        y = self.character.location.position.y + 1.0
        mod_path = Line([[self.pos.x, self.pos.z]])
        modmap = {
            'height': y,
            'shape': {
                'points': [[-1.0, -1.0], [-1.0, 1.0], [1.0, 1.0], [1.0, -1.0]],
                'type': 'polygon'
            },
            'type': 'levelmod'
        }
        area_map = {'shape': modmap['shape'], 'layer': 7}
        line_map = mod_path.as_data()

        mod_loc = Location(self.character.location.parent)
        mod_loc.velocity = Vector3D()
        mod_loc.position = self.pos

        mod_create = Operation("create",
                               Entity(name="wall",
                                      type="path",
                                      line=line_map,
                                      location=mod_loc,
                                      terrainmod=modmap,
                                      area=area_map),
                               to=self.target())
        res = Oplist()
        res.append(mod_create)
        res.append(self.next_tick(0.75))
        return res
예제 #2
0
    def _create_initial_mod(self):
        print("no existing mod")
        y = self.character.location.position.y + 1.0
        modmap = {'height': y,
                  'shape': Polygon([[-0.7, -0.7],
                                    [-1.0, 0.0],
                                    [-0.7, 0.7],
                                    [0.0, 1.0],
                                    [0.7, 0.7],
                                    [1.0, 0.0],
                                    [0.7, -0.7],
                                    [0.0, -1.0]]).as_data(),
                  'type': 'levelmod'}
        area_map = {'shape': modmap['shape'],
                    'layer': 7}

        mod_loc = Location(self.character.location.parent)
        mod_loc.velocity = Vector3D()
        mod_loc.position = self.pos

        mod_create = Operation("create",
                               Entity(name="motte",
                                      type="path",
                                      location=mod_loc,
                                      terrainmod=modmap,
                                      area=area_map),
                               to=self.target())
        res = Oplist()
        res.append(mod_create)
        res.append(self.next_tick(0.75))
        return res
예제 #3
0
    def knowledge_updated(self, entity):
        if entity.has_prop_map('_knowledge'):
            knowledge = entity.get_prop_map('_knowledge')

            for key, knowledge_element in knowledge.items():
                (predicate, subject) = key.split(':')
                object_word = knowledge_element

                if predicate == 'location':
                    # If it's just a string it's a reference to an entity id (with zero position).
                    if isinstance(object_word, str):
                        entity_id_string = object_word
                        # A prefix of "$eid:" denotes an entity id; it should be stripped first.
                        if entity_id_string.startswith("$eid:"):
                            entity_id_string = entity_id_string[5:]
                        where = self.map.get_add(entity_id_string)
                        object_word = Location(where)
                    else:
                        if len(object_word) == 3:
                            loc = self.entity.location.copy()
                            loc.pos = Vector3D(object_word)
                            object_word = loc
                        elif len(object_word) == 4:
                            entity_id_string = object_word[0]
                            # A prefix of "$eid:" denotes an entity id; it should be stripped first.
                            if entity_id_string.startswith("$eid:"):
                                entity_id_string = entity_id_string[5:]
                            where = self.map.get_add(entity_id_string)
                            object_word = Location(where,
                                                   Vector3D(object_word[:3]))

                self.add_knowledge(predicate, subject, object_word)
예제 #4
0
    def delete_operation(self, op):
        res = Oplist()

        # Restore status if it's zero.
        if self.has_prop_float("status"):
            res += Operation("set", Entity(self.id, status=1.0), to=self.id)

        # Respawn in a spawn area
        respawn_alias = self.get_prop_string("_respawning")
        if respawn_alias:
            respawn_entity = server.get_alias_entity(respawn_alias)
            if respawn_entity:
                pos = Spawner.get_spawn_pos(respawn_entity)
                if pos:
                    location = Location()
                    location.pos = pos
                    # Randomize orientation
                    rotation = random.random() * math.pi * 2
                    location.orientation = physics.Quaternion(physics.Vector3D(0, 1, 0), rotation)
                    location.parent = respawn_entity.location.parent
                    # Emit a sight of this entity being defeated
                    res += Operation("sight", Operation("defeated", Entity(self.id)))
                    res += Operation("move", Entity(self.id, location=location), to=self.id)
                    res += Operation("imaginary", Entity(description="You were killed and will be respawned."), to=self.id, from_=self.id)
                    return server.OPERATION_BLOCKED, res
예제 #5
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        self.rate = 0.5 / 0.75
        self.progress += 1

        if not target:
            print("Target is no more")
            self.irrelevant()
            return

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(1.75)

        self.progress = 0

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.position = self.pos
        lumberh = 0  # lumberheight
        lumberl = 0  # lumberlength
        res = Oplist()
        lcount = 0
        # makes sure we have 3 lumber to construct A frame
        for item in self.character.contains:
            if item.type[0] == str(self.materials):
                lcount = lcount + 1
                lumberl = item.location.bbox.high_corner[2] - \
                          item.location.bbox.low_corner[2]
                lumberh = item.location.bbox.high_corner[1] - \
                          item.location.bbox.low_corner[1]

            if lcount == 3:
                break
        else:
            print("No materials in inventory for A frame")
            self.irrelevant()
            return

        bbox1 = [
            -lumberl / 2, -lumberl / 2, -lumberh / 2, lumberl / 2, lumberl / 2,
            lumberh / 2
        ]
        # bbox of a frame
        create = Operation("create",
                           Entity(name="A_Frame",
                                  type="construction",
                                  bbox=bbox1,
                                  location=chunk_loc),
                           to=target)
        create.set_serialno(0)
        res.append(create)
        res.append(self.next_tick(1.75))
        return res
예제 #6
0
    def sow_operation(self, op):
        """ Op handler for sow op which activates this task """

        if len(op) < 1:
            sys.stderr.write("Fish task has no target in sow op")

        # FIXME Use weak references, once we have them
        self.target = server.world.get_object(op[0].id)
        self.tool = op.to

        self.pos = Point3D(op[0].pos)

        # self.character.contains is a list of entities inside the player's inventory

        bait = 0

        for item in self.character.contains:
            if item.type[0] in self.baitlist:
                bait = item
                # self.character.contains.remove(item)
                break
        else:
            print("No bait in inventory")
            self.irrelevant()
            return

        if "ocean" not in self.target().type:
            print("Can fish only in the ocean")
            self.irrelevant()
            return

        self.bait = weakref.ref(bait)
        self.progress = 0.5

        res = Oplist()

        float_loc = Location(self.character.location.parent)
        # This is <server.Entity object at 0xb161b90>

        float_loc.position = self.pos

        bait_vector = Vector3D(0, -0.5, -0)
        bait_loc = float_loc.copy()
        bait_loc.position = bait_loc.position + bait_vector

        res = Operation("create",
                        Entity(name="bobber",
                               parent="bobber",
                               location=float_loc),
                        to=self.target())
        res = res + Operation(
            "move", Entity(bait.id, location=bait_loc), to=bait)
        res = res + Operation("create",
                              Entity(parent="fishing_hook",
                                     location=Location(bait, Point3D(0, 0,
                                                                     0))),
                              to=bait)
        return res
예제 #7
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        self.rate = 0.5 / 0.75
        self.progress += 1

        if not target:
            print("Target is no more")
            self.irrelevant()
            return

        lcount = 0  # Lumber count
        acount = 0  # A frame count
        self.gname = ""  # Gate name
        # makes sure we have 3 lumber to construct A frame
        for item in self.character.contains:
            if item.type[0] == "lumber":
                lcount = lcount + 1
            if item.type[0] == "construction":
                acount = acount + 1
            if lcount == 3:
                self.gname = "House_Gate"
                break
            if acount == 2 and lcount == 1:
                self.gname = "Basic_Gate"
                break
        else:
            print("No materials in inventory for a Gate")
            self.irrelevant()

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.pos = self.pos
        chunk_loc.orientation = self.character.location.orientation
        res = Oplist()
        bbox1 = [-4, -4, -.01, 4, 4,
                 .01]  # Needed so it can be viewed from afar
        create = Operation("create",
                           Entity(name=self.gname,
                                  type="construction",
                                  bbox=bbox1,
                                  location=chunk_loc),
                           to=target)
        create.set_serialno(0)
        res.append(create)
        res.append(self.next_tick(1.75))
        return res
예제 #8
0
 def do_peck(self, me):
     # world =
     # ground = world.id
     # op = Operation("eat", ground)
     target = Location(me.entity.location.parent, me.entity.location.pos)
     target.pos = Vector3D(target.pos.x + uniform(-1.5, 1.5), target.pos.y, target.pos.z + uniform(-1.5, 1.5))
     target.velocity = Vector3D(1, 0, 0)
     # op += Operation("move",  Entity(me.entity.id, location=target))
     return Operation("move", Entity(me.entity.id, location=target))
예제 #9
0
 def face(self, other):
     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))
예제 #10
0
파일: move.py 프로젝트: worldforge/cyphesis
 def run(self, me):
     lst_of_what = me.mem.recall_place(me.entity.location, self.range, self.filter)
     if not lst_of_what or len(lst_of_what) == 0: return
     dist_vect = distance_to(me.entity.location, lst_of_what[0].location).unit_vector()
     multiply = 1.0 * self.direction * const.basic_tick
     loc = Location(me.entity.location.parent)
     loc.pos = me.entity.location.pos + (dist_vect * multiply)
     ent = Entity(me.entity.id, location=loc)
     return Operation("move", ent)
예제 #11
0
 def event(self, me, original_op, op):
     ent = op[0]
     # This goal currently causes mayhem. Effectively disable it.
     if 1:
         return
     if ent.id == me.entity.id:
         return
     ent = me.map.get(ent.id)
     if ent == None:
         print("not convering on Nothing")
         return
     if ent.type[0] != me.entity.type[0]:
         print("not convering on something not me")
         return
     if type(ent.location.parent) == type(None):
         print("flock.event, ent.location.parent is None")
         return
     if type(me.entity.location.parent) == type(None):
         print("flock.event, me.entity.location.parent is None")
         return
     if me.entity.location.parent.id != ent.location.parent.id:
         print("not convering on something elsewhere")
         return
     if type(ent.location.pos) != Point3D:
         print("position not an Point", type(ent.location.pos))
         return
     edist = (ent.location.pos - me.entity.location.pos)
     if edist.sqr_mag() < 50:
         print("not convering on close enough")
         return
     evel = ent.location.velocity
     if evel and evel.sqr_mag() > 0.1:
         myvel = me.entity.location.velocity
         edir = edist.unit_vector()
         if myvel and myvel.sqr_mag() > 0.1:
             myvel = myvel.unit_vector()
             # If I move in the same direction, then do nothing
             if evel.dot(myvel) > 0.5:
                 print("not convering on moving with")
                 return
             # If I am moving towards them, then do nothing
             if edir.dot(myvel) > 0.5:
                 print("not convering on moving towards them")
                 return
         # If they are coming towards me, then do nothing
         if edir.dot(evel) < - 0.5:
             print("not convering on moving towards me")
             return
         new_loc = Location(me.entity.location.parent)
         new_loc.velocity = ent.location.velocity
     else:
         new_loc = ent.location.copy()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         new_loc.pos = new_loc.pos - edir
     print("converging")
     return Operation("move", Entity(me.entity.id, location=new_loc))
예제 #12
0
    def tick_operation(self, op):

        """ Op handler for regular tick op """
        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        self.rate = 0.5 / 0.75
        self.progress += 1

        if not target:
            print("Target is no more")
            self.irrelevant()
            return

        lcount = 0  # Lumber count
        acount = 0  # A frame count
        self.gname = ""  # Gate name
        # makes sure we have 3 lumber to construct A frame
        for item in self.character.contains:
            if item.type[0] == "lumber":
                lcount = lcount + 1
            if item.type[0] == "construction":
                acount = acount + 1
            if lcount == 3:
                self.gname = "House_Gate"
                break
            if acount == 2 and lcount == 1:
                self.gname = "Basic_Gate"
                break
        else:
            print("No materials in inventory for a Gate")
            self.irrelevant()

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.position = self.pos
        chunk_loc.orientation = self.character.location.orientation
        res = Oplist()
        bbox1 = [-4, -4, -.01, 4, 4, .01]  # Needed so it can be viewed from afar
        create = Operation("create", Entity(name=self.gname,
                                            type="construction",
                                            bbox=bbox1,
                                            location=chunk_loc),
                           to=target)
        create.set_serialno(0)
        res.append(create)
        res.append(self.next_tick(1.75))
        return res
예제 #13
0
 def burn_operation(self, op):
     fire_status = op[0].status
     to_ = op[0].id
     ret = Oplist()
     if fire_status < 0.5:
         ret = ret + Operation("nourish", Entity(op[0].id, mass=(0.5 - fire_status)), to=to_)
     fire_loc = Location(self, Point3D(0, 0, 0.75))
     fire_loc.bbox = BBox(0.05, 0.05, 0.5)
     ret = ret + Operation("move", Entity(to_, location=fire_loc, mode='planted'), to=to_)
     return ret
예제 #14
0
 def face(self, other):
     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))
예제 #15
0
 def event(self, me, original_op, op):
     # FIXME Trigger this on interlinguish instead
     # FIXME Use the verb rather than the hardcoded RE
     talk_entity = op[0]
     if hasattr(talk_entity, "say"):
         say = talk_entity.say
         if sowee_pattern.match(say):
             destination = Location()
             destination.velocity = Vector3D(0, 0, 0)
             return Operation("move", Entity(me.entity.id, location=destination))
예제 #16
0
    def tick_operation(self, op):

        """ Op handler for regular tick op """
        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        self.rate = 0.5 / 0.75
        self.progress += 1

        if not target:
            print("Target is no more")
            self.irrelevant()
            return

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(1.75)

        self.progress = 0

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.position = self.pos
        lumberh = 0  # lumberheight
        lumberl = 0  # lumberlength
        res = Oplist()
        lcount = 0
        # makes sure we have 3 lumber to construct A frame
        for item in self.character.contains:
            if item.type[0] == str(self.materials):
                lcount = lcount + 1
                lumberl = item.location.bbox.high_corner[2] - \
                          item.location.bbox.low_corner[2]
                lumberh = item.location.bbox.high_corner[1] - \
                          item.location.bbox.low_corner[1]

            if lcount == 3:
                break
        else:
            print("No materials in inventory for A frame")
            self.irrelevant()
            return

        bbox1 = [-lumberl / 2, -lumberl / 2, -lumberh / 2, lumberl / 2, lumberl / 2, lumberh / 2]
        # bbox of a frame
        create = Operation("create", Entity(name="A_Frame",
                                            type="construction",
                                            bbox=bbox1, location=chunk_loc),
                           to=target)
        create.set_serialno(0)
        res.append(create)
        res.append(self.next_tick(1.75))
        return res
예제 #17
0
 def face(self, other):
     """ Turn to face that another character, ensuring that
         we are facing the character we are hitting """
     vector = distance_to(self.character.location, other.location)
     vector.y = 0
     if vector.sqr_mag() < 0.1:
         return
     vector = vector.unit_vector()
     newloc = Location(self.character.location.parent)
     newloc.orientation = Quaternion(Vector3D(1, 0, 0), vector)
     return Operation("move", Entity(self.character.id, location=newloc))
예제 #18
0
 def face(self, other):
     """ Turn to face that another character, ensuring that
         we are facing the character we are hitting """
     vector = distance_to(self.character.location, other.location)
     vector.y = 0
     if vector.sqr_mag() < 0.1:
         return
     vector = vector.unit_vector()
     newloc = Location(self.character.location.parent)
     newloc.orientation = Quaternion(Vector3D(1, 0, 0), vector)
     return Operation("move", Entity(self.character.id, location=newloc))
예제 #19
0
파일: move.py 프로젝트: MasterMann/cyphesis
 def run(self, me):
     lst_of_what = me.mem.recall_place(me.entity.location, self.range,
                                       self.filter)
     if not lst_of_what or len(lst_of_what) == 0: return
     dist_vect = distance_to(me.entity.location,
                             lst_of_what[0].location).unit_vector()
     multiply = 1.0 * self.direction * const.basic_tick
     loc = Location(me.entity.location.parent)
     loc.pos = me.entity.location.pos + (dist_vect * multiply)
     ent = Entity(me.entity.id, location=loc)
     return Operation("move", ent)
예제 #20
0
파일: Reap.py 프로젝트: digimax20/cyphesis
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Reap.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        if self.count == 0:
            self.count = int(self.target().props.mass)
            # print "setting target mass to ", self.count

        if not self.character.location.velocity.is_valid() or \
            self.character.location.velocity.sqr_mag() < 1 or \
            self.character.location.velocity.sqr_mag() > 10:
            self.rate = 0
            self.progress = 0
            # print "Not moving the right speed"
            return self.next_tick(1.75)

        old_rate = self.rate

        self.rate = 1.0 / 1.75
        self.progress = 0.01

        if old_rate < 0.1:
            # print "Wasn't moving right speed"
            return self.next_tick(1.75)

        surface = self.target().props.terrain.get_surface(
            self.character.location.pos)
        if surface is not 2:
            # print "Not grass"
            return self.next_tick(1.75)

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.pos = self.character.location.pos

        create = Operation("create",
                           Entity(name="grass",
                                  type="grass",
                                  location=chunk_loc),
                           to=self.target())
        res.append(create)

        res.append(self.next_tick(1.75))

        return res
예제 #21
0
파일: Sift.py 프로젝트: worldforge/cyphesis
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Dig.tick"
        if self.target() is None:
            print("Target is no more")
            self.irrelevant()
            return

        world = self.target().location.parent

        material = self.target().props.name
        # print material

        if material not in Sift.materials:
            print("Not right material for earthworms")
            self.irrelevant()
            return

        old_rate = self.rate

        self.rate = 0.1 / 1.75
        self.progress += 0.1

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(1.75)

        self.progress = 0

        res = Oplist()

        self_loc = Location(self.character)
        self_loc.velocity = Vector3D()
        if hasattr(world, 'moisture'):
            moisture = 10 * world.moisture
        else:
            moisture = 1
        self_loc.position = self.pos

        quality = int(self.get_quality(self_loc.position, self.target(), moisture))
        print(quality)
        for i in range(int(quality / 2), quality):
            res = res + Operation("create", Entity(name="scrawny earthworm", parent="annelid", location=self_loc), to=self.character)
        for i in range(int((10 - quality) / 2), quality):
            res = res + Operation("create", Entity(name="juicy earthworm", parent="annelid", location=self_loc), to=self.character)

        self.irrelevant()
        return res
예제 #22
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Dig.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        old_rate = self.rate

        self.rate = 0.1 / 1.75
        self.progress += 0.1

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(1.75)

        self.progress = 0

        surface = self.target().props.terrain.get_surface(self.pos)
        # print "SURFACE %d at %s" % (surface, self.pos)
        if surface not in Dig.materials:
            print("Not right")
            self.irrelevant()
            return

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.position = self.pos

        create = Operation("create",
                           Entity(name=Dig.materials[surface],
                                  type="pile",
                                  material=Dig.materials[surface],
                                  location=chunk_loc),
                           to=self.target())
        create.set_serialno(0)
        res.append(create)

        res.append(self.next_tick(1.75))

        return res
예제 #23
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Raise.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return
        if not self.target().location.parent:
            # Not withstanding famous quotes to the contrary, in these
            # system we can not move the world no matter how large a lever
            # or firm a place to stand we have.
            self.irrelevant()
            return

        distance = distance_to(self.character.location, self.target().location)
        # Check we are not too far away from the object to interact with it
        # This calculation is imprecise as it sums the square radii, but
        # its usually close enough.
        d = distance.sqr_mag()
        r = self.character.location.bbox.square_bounding_radius() + \
            self.target().location.bbox.square_bounding_radius()
        if d > r:
            return self.next_tick(1)
        if d < const.epsilon:
            # print "Going nowhere"
            return self.next_tick(1)
        # print "DISTANCE ", distance, distance.is_valid()
        axis = distance.cross(Vector3D(0, 1, 0))
        # If distance is zero, axis becomes zero
        # print "DISTANCE ", distance, distance.is_valid(), axis, axis.is_valid()
        # If axis is zero, the quaternion contains NaNs.
        rotation = Quaternion(axis, -0.05)
        # print "ROT ", rotation, rotation.is_valid()
        if self.target().location.orientation.is_valid():
            # print "VALID"
            rotation = self.target().location.orientation * rotation

        # print "NEW_ROT", rotation, rotation.is_valid()
        target_location = Location(self.target().location.parent,
                                   self.target().location.position)
        target_location.orientation = rotation
        move = Operation("move",
                         Entity(self.target().id, location=target_location),
                         to=self.target())
        res = Oplist()
        res.append(move)

        res.append(self.next_tick(0.5))

        return res
예제 #24
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Raise.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return
        if not self.target().location.parent:
            # Not withstanding famous quotes to the contrary, in these
            # system we can not move the world no matter how large a lever
            # or firm a place to stand we have.
            self.irrelevant()
            return

        distance = distance_to(self.character.location, self.target().location)
        # Check we are not too far away from the object to interact with it
        # This calculation is imprecise as it sums the square radii, but
        # its usually close enough.
        d = distance.sqr_mag()
        r = self.character.location.bbox.square_bounding_radius() + \
            self.target().location.bbox.square_bounding_radius()
        if d > r:
            return self.next_tick(1);
        if d < const.epsilon:
            # print "Going nowhere"
            return self.next_tick(1);
        # print "DISTANCE ", distance, distance.is_valid()
        axis = distance.cross(Vector3D(0, 1, 0))
        # If distance is zero, axis becomes zero
        # print "DISTANCE ", distance, distance.is_valid(), axis, axis.is_valid()
        # If axis is zero, the quaternion contains NaNs.
        rotation = Quaternion(axis, -0.05)
        # print "ROT ", rotation, rotation.is_valid()
        if self.target().location.orientation.is_valid():
            # print "VALID"
            rotation = self.target().location.orientation * rotation

        # print "NEW_ROT", rotation, rotation.is_valid()
        target_location = Location(self.target().location.parent,
                                   self.target().location.position)
        target_location.orientation = rotation
        move = Operation("move", Entity(self.target().id,
                                        location=target_location), to=self.target())
        res = Oplist()
        res.append(move)

        res.append(self.next_tick(0.5))

        return res
예제 #25
0
파일: Dig.py 프로젝트: worldforge/cyphesis
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Dig.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        old_rate = self.rate

        self.rate = 0.1 / 1.75
        self.progress += 0.1

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(1.75)

        self.progress = 0

        surface = self.target().props.terrain.get_surface(self.pos)
        # print "SURFACE %d at %s" % (surface, self.pos)
        if surface not in Dig.materials:
            print("Not right")
            self.irrelevant()
            return

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.position = self.pos

        create = Operation("create",
                           Entity(name=Dig.materials[surface],
                                  type="pile",
                                  material=Dig.materials[surface],
                                  location=chunk_loc), to=self.target())
        create.set_serialno(0)
        res.append(create)

        res.append(self.next_tick(1.75))

        return res
예제 #26
0
    def info_operation(self, op):
        print("Aframe info")
        aframe = server.world.get_object(op[0].id)
        self.lcount = 0

        raw_materials = []
        for item in self.character.contains:
            if item.type[0] == str(self.materials):
                raw_materials.append(item)
                self.lcount = self.lcount + 1
            if self.lcount == 3:
                break
        else:
            print("No materials in inventory for A frame")
            self.irrelevant()
            return

        chunk_loc = Location(aframe())
        chunk_loc.position = Point3D([0, 0, 0])

        count = self.lcount
        res = Oplist()
        # loops through raw_materials and places 3 lumber
        # in inventory infront of user
        offset = Vector3D(0, 0, 0)
        while (count > 0):
            tar = raw_materials.pop()
            # length of the lumber obtained
            lumberlength = tar.location.bbox.high_corner[2] - \
                           tar.location.bbox.low_corner[2]
            lumberheight = tar.location.bbox.high_corner[1] - \
                           tar.location.bbox.low_corner[1]
            # rough length to position lumber
            lumber_length = lumberlength / 4

            if count == 3:
                # left component
                chunk_loc.orientation = Quaternion([.653, 0.27, .27, .653])
            if count == 2:
                # right component
                chunk_loc.orientation = Quaternion([.653, -0.27, -.27, .653])
                offset = Vector3D(lumber_length, 0, 0)
                chunk_loc.position = chunk_loc.position + offset
            if count == 1:
                # bottom component
                chunk_loc.position = Point3D([0, 0, 0])  # self.pos
                # .707 is sin(.5) which is needed for a 90 degree rotation
                chunk_loc.orientation = Quaternion([.707, 0, .707, 0])
                offset = Vector3D(-(1.5 * lumber_length), 0, (2.5 * lumber_length))
                chunk_loc.position = chunk_loc.position + offset

            move = Operation("move", Entity(tar.id, location=chunk_loc,
                                            mode="fixed"), to=tar)
            res.append(move)
            count = count - 1

        self.progress = 1
        self.irrelevant()
        return res
예제 #27
0
 def origin_updated(self, entity):
     origin = entity.get_prop_map("_origin")
     if origin:
         self.add_knowledge(
             "location", "origin",
             Location(self.map.get_add(origin["$eid"]),
                      Point3D(origin["pos"])))
예제 #28
0
    def dig_operation(self, op):

        arg = op[0]
        if not arg:
            return server.OPERATION_IGNORED

        if not arg.pos:
            print('No pos supplied')
            return server.OPERATION_IGNORED

        terrain_prop = self.props.terrain
        if not terrain_prop:
            print('No terrain prop on diggable terrain entity')
            return server.OPERATION_IGNORED

        surface = self.props.terrain.get_surface_name(arg.pos[0], arg.pos[2])
        if surface not in DiggableTerrain.materials:
            print("The surface couldn't be digged here. Material {}.".format(
                surface))
            return server.OPERATION_IGNORED

        material = DiggableTerrain.materials[surface]

        chunk_loc = Location(self, arg.pos)

        print("Creating pile of {} at {}".format(material, chunk_loc))
        new_entity = Entity(name="Pile of {}".format(material),
                            parent="pile",
                            material=material,
                            location=chunk_loc)
        if material == 'earth':
            new_entity._worms = random.randint(0, 3)
        create_op = Operation("create", new_entity, to=self.id)

        return server.OPERATION_BLOCKED, create_op
예제 #29
0
 def keep_it(self, me):
     result = Oplist()
     if (self.where in me.things) == 0: return
     if (self.what in me.things) == 0: return
     thing_all = me.find_thing(self.what)
     where = me.find_thing(self.where)[0]
     to_location = Location(where, Point3D(0, 0, 0))
     minx = where.location.bbox.low_corner.x
     minz = where.location.bbox.low_corner.z
     maxx = where.location.bbox.high_corner.x
     maxz = where.location.bbox.high_corner.z
     for thing in thing_all:
         if thing.location.parent.id != where.id and thing.location.parent.id != me.entity.id:
             thingloc = Location(where, Point3D(uniform(minx, maxx), 0, uniform(minz, maxz)))
             result.append(Operation("move", Entity(thing.id, location=thingloc)))
     return result
예제 #30
0
 def move_it_to_loc(self, me):
     if self.wait > 0:
         self.wait = self.wait - 1
         return
     if type(self.location) == str:
         self.location = me.get_knowledge("location", self.location)
     elif not isLocation(self.location):
         self.location = Location(self.location, Point3D(0.0, 0.0, 0.0))
     if type(self.what) == str:
         if (self.what in me.things) == 0:
             return
         what = me.things[self.what][0]
         if self.speed == 0 or what.location.parent.id != self.location.parent.id:
             return Operation("move", Entity(what.id,
                                             location=self.location))
         iloc = what.location.copy()
         vel = what.location.pos.unit_vector_to(self.location.pos)
         iloc.velocity = vel * self.speed
         self.location.velocity = Vector3D(0.0, 0.0, 0.0)
         m_op1 = Operation("move", Entity(what.id, location=iloc))
         m_op2 = Operation("move", Entity(what.id, location=self.location))
         time = ((self.location.pos - what.location.pos).mag() / self.speed)
         self.wait = (time / const.basic_tick) + 1
         m_op2.set_future_seconds(time)
         return Oplist(m_op1, m_op2)
예제 #31
0
 def event(self, me, op, say):
     object = say[1].word
     thing = me.map.get(object)
     who = me.map.get(op.to)
     if thing is None:
         if object != self.what:
             return Operation("talk",
                              Entity(say=who.name + ", I am not interested in buying your " + str(object) + "."))
         me.goals.insert(0, BuyFrom(self.what, self.cost, op.to))
         return Operation("talk", Entity(say=who.name + " which " + object + " would you like to sell?"))
     if self.what not in thing.type:
         return
     if thing in me.find_thing(self.what):
         return
     # price=me.get_knowledge("price", thing.type[0])
     price = self.cost * int(thing.mass)
     res = Oplist()
     coins = me.find_thing("coin")
     if len(coins) < int(price):
         print("Coins: " + str(len(coins)) + " Cost: " + str(self.cost))
         return Operation("talk", Entity(say="I can't afford any " + self.what + "s at the moment."))
     for i in range(0, int(price)):
         coin = coins[0]
         me.remove_thing(coin)
         res.append(Operation("move", Entity(coin.id, location=Location(who, Point3D(0, 0, 0)))))
     res.append(Operation("talk", Entity(say="Thankyou " + who.name + ", come again.")))
     me.add_thing(thing)
     return res
예제 #32
0
파일: move.py 프로젝트: MasterMann/cyphesis
 def pick_it_up(self, me):
     what = self.what
     if type(what) == str:
         if (self.what in me.things) == 0: return 0
         what = me.things[self.what][0]
     return Operation("move",
                      Entity(id, location=Location(me, Point3D(0, 0, 0))))
예제 #33
0
def potion_handler(instance):
    """
     Create a poisoning instance
    :param instance:
    :return:
    """
    new_entity = Entity(parent="poisoning", location=Location(instance.actor))
    return Operation("create", new_entity, to=instance.tool.id)
예제 #34
0
파일: Bow.py 프로젝트: worldforge/cyphesis
 def shoot_operation(self, op):
     ammo = op[0].id
     to_ = op[1].id
     target = server.world.get_object(to_)
     vel = target.location.position - self.location.parent.location.position
     time = vel.mag() / 5
     vel = vel.unit_vector() * 5
     loc1 = Location(self.location.parent.location.parent, self.location.parent.location.position)
     loc1.velocity = vel
     loc2 = Location(target.location.parent, Point3D(0, 0, 0))
     loc2.velocity = Vector3D(0, 0, 0)
     m1 = Operation("move", Entity(ammo, location=loc1), to=ammo)
     m2 = Operation("move", Entity(ammo, location=loc2), to=ammo)
     m2.set_future_seconds(time)
     t = Operation("set", Entity(to_, status=-1), to=to_)
     t.set_future_seconds(time)
     return Oplist(m1, m2, t)
예제 #35
0
 def keep_it(self, me):
     result = Oplist()
     if (self.what in me.things) == 0: return
     thing_all = me.find_thing(self.what)
     to_loc = Location(me, Point3D(0, 0, 0))
     for thing in thing_all:
         if thing.location.parent.id != me.entity.id:
             result.append(Operation("move", Entity(thing.id, location=to_loc)))
     return result
예제 #36
0
 def event(self, me, original_op, op):
     # FIXME Now that this code is trigger goal, has this update been done?
     other = me.map.update(op[0], op.get_seconds())
     if other.id == me.entity.id: return
     # target=op[0].location.copy()
     if other.location.parent.id != me.entity.location.parent.id: return
     if hasattr(other, "type") and other.type[0] not in self.kinds: return
     destination = other.location.pos
     distance = destination.distance(me.entity.location.pos)
     if distance < 1: return
     # CHeat, random chance that it ignores movement
     if uniform(0, 30 / distance) < 1: return
     target = Location(me.entity.location.parent)
     velocity = destination - me.entity.location.pos
     if velocity.mag() == 0: return
     target.velocity = velocity.unit_vector()
     target.pos = destination
     return Operation("move", Entity(me.entity.id, location=target))
예제 #37
0
 def event(self, me, original_op, op):
     # FIXME Now that this code is trigger goal, has this update been done?
     other = me.map.update(op[0], op.get_seconds())
     if other.id == me.entity.id: return
     # target=op[0].location.copy()
     if other.location.parent.id != me.entity.location.parent.id: return
     if hasattr(other, "type") and other.type[0] not in self.kinds: return
     destination = other.location.pos
     distance = destination.distance(me.entity.location.pos)
     if distance < 1: return
     # CHeat, random chance that it ignores movement
     if uniform(0, 30 / distance) < 1: return
     target = Location(me.entity.location.parent)
     velocity = destination - me.entity.location.pos
     if velocity.mag() == 0: return
     target.velocity = velocity.unit_vector()
     target.pos = destination
     return Operation("move", Entity(me.entity.id, location=target))
예제 #38
0
    def check(self, me):
        seller = me.map.get(self.who)
        if not seller:
            return
        for transfer in me.transfers:
            if transfer[0] != self.who:
                continue
            item = me.map.get(transfer[1])
            if not item:
                continue
            if item.type[0] != self.what:
                continue
            # FIXME Removing messes up the for loop
            me.transfers.remove(transfer)
            if item.mass:
                price = int(item.mass * self.cost)
                coins = me.find_thing("coin")
                if len(coins) < price:
                    me.remove_thing(item)
                    return Operation("talk", Entity(
                        say="I can't afford to buy that " + self.what + " at the moment.")) + Operation("move",
                                                                                                        Entity(item.id,
                                                                                                               location=Location(
                                                                                                                   seller.id,
                                                                                                                   Point3D(
                                                                                                                       0,
                                                                                                                       0,
                                                                                                                       0))))
                res = Oplist()
                for i in range(0, price):
                    coin = coins[0]
                    me.remove_thing(coin)
                    res.append(Operation("move", Entity(coin.id, location=Location(seller, Point3D(0, 0, 0)))))
                res.append(Operation("talk", Entity(
                    say="Thankyou " + seller.name + ", here are " + str(price) + " coins for the pig.")))
                self.irrelevant = 1
                return res

        if not hasattr(seller, "right_hand_wield") or not seller.right_hand_wield:
            return
        if self.last_valued and seller.right_hand_wield == self.last_valued:
            return
        wield = me.map.get(seller.right_hand_wield)
        if not wield:
            return
        if self.what != wield.type[0]:
            return
        if not wield.mass:
            return
        price = int(wield.mass * self.cost)
        coins = me.find_thing("coin")
        self.last_valued = wield.id
        if len(coins) < price:
            return Operation("talk", Entity(say="I can't afford to buy that " + self.what + " at the moment."))
        else:
            return Operation("talk",
                             Entity(say=seller.name + " that " + self.what + " is worth " + str(price) + " coins."))
예제 #39
0
파일: herd.py 프로젝트: worldforge/cyphesis
 def event(self, me, original_op, op):
     ent = op[0]
     if ent.id == me.entity.id:
         return
     ent = me.map.get(ent.id)
     if ent is None:
         return
     if ent.type[0] != me.entity.type[0]:
         return
     if me.entity.parent.id != ent.parent.id:
         return
     try:
         val = self.herd_members[ent.id]
     except KeyError:
         val = 0
     if type(ent.location.pos) != Point3D:
         return
     if me.entity.location.pos.distance(ent.location.pos) < 6:
         val = val + 1
         self.herd_members[ent.id] = val
         return
     # If we have not seen this one before 50 times, then it is not yet
     # really a member of the herd
     if not val > 50:
         return
     val = val + 1
     self.herd_members[ent.id] = val
     if ent.location.velocity:
         myvel = me.entity.location.velocity.unit_vector()
         evel = ent.location.velocity.unit_vector()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         # If I am moving towards them, or in the same direction, then do nothing
         if myvel and (evel.dot(myvel) > 0.5 or edir.dot(myvel) > 0.5):
             return
         # If they are coming towards me, then do nothing
         if edir.dot(evel) < -0.5:
             return
         new_loc = Location(me.entity.parent)
         new_loc.velocity = ent.location.velocity
     else:
         new_loc = ent.location.copy()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         new_loc.pos = new_loc.pos - edir
     return Operation("move", Entity(me.entity.id, location=new_loc))
예제 #40
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))
예제 #41
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Dragging.tick"
        self.pos = self.character.location.pos
        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        if not self.target().location.parent:
            # Make sure the user dosen't use dragging on the world entity..
            self.irrelevant()
            return

        old_rate = self.rate

        self.rate = 0.5 / 0.75
        self.progress += 0.5

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.pos = self.pos
        # Move the entity to user's position.
        res = res + Operation("move",
                              Entity(self.target().id, location=chunk_loc),
                              to=self.target())
        res.append(self.next_tick(0.75))

        return res
예제 #42
0
파일: move.py 프로젝트: worldforge/cyphesis
 def follow(self, me):
     id = me.get_knowledge('focus', self.who)
     who = me.map.get(str(id))
     if who == 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))
예제 #43
0
 def pick_it_up(self, me):
     for what in self.what:
         thing = get_focused_thing(me, what)
         if thing is None:
             continue
         if thing.location.parent.id != me.entity.id:
             print("Trying to pick up {}".format(str(thing)))
             return Operation(
                 "move",
                 Entity(thing.id,
                        location=Location(me.entity, Point3D(0, 0, 0))))
예제 #44
0
 def do_amble(self, me):
     id = me.get_knowledge('focus', 'hook')
     if id != None:
         thing = me.map.get(id)
         if thing == None:
             me.remove_knowledge('focus', what)
         else:
             if thing.location.parent.id != me.entity.location.parent.id:
                 me.remove_knowledge('focus', what)
             else:
                 if thing.location.parent.id == me.entity.id:
                     return
     # world =
     # ground = world.id
     # op = Operation("eat", ground)
     # print "Fish ambling"
     target = Location(me.entity.location.parent, me.entity.location.pos)
     target.pos = Vector3D(target.pos.x + uniform(-1.5, 1.5), target.pos.y, target.pos.z + uniform(-1.5, 1.5))
     target.velocity = Vector3D(1, 0, 0)
     return Operation("move", Entity(me.entity.id, location=target))
예제 #45
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        res = Oplist()

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        if not self.target().location.parent:
            self.irrelevant()
            return

        target_location = Location(self.target().location.parent,
                                   self.target().location.position)
        target_location.velocity = Vector3D(0, -0.5, 0)
        new_loc = self.character.location.position
        origin = self.points[0]
        # Get the diffrence in the location of user at current time to the time when he started the task
        diff = origin.x - new_loc.x
        target_entity_moving = Entity(self.target().id, location=target_location)

        # Replicate the diffrence in position to the corresponding change in height.
        target_location = Location(self.target().location.parent,
                                   Point3D(self.target().location.position.x,
                                           self.target().location.position.y + diff,
                                           self.target().location.position.z))
        target_location.velocity = Vector3D(0, 0, 0)
        target_entity = Entity(self.target().id, location=target_location)

        # Make the mode fixed to remove the height constraint on entity. 
        if not hasattr(self.target(), 'mode') or self.target().props.mode != 'fixed':
            target_entity.mode = 'fixed'

        move = Operation("move", target_entity, to=self.target())
        move.set_future_seconds(0.2)
        res.append(move)

        res.append(self.next_tick(1.5))

        return res
예제 #46
0
파일: herd.py 프로젝트: worldforge/cyphesis
 def event(self, me, original_op, op):
     ent = op[0]
     if ent.id == me.entity.id: return
     ent = me.map.get(ent.id)
     if ent == None: return
     if ent.type[0] != me.entity.type[0]: return
     if me.entity.location.parent.id != ent.location.parent.id: return
     try:
         val = self.herd_members[ent.id]
     except KeyError:
         val = 0
     if type(ent.location.pos) != Point3D:
         return
     if me.entity.location.pos.distance(ent.location.pos) < 6:
         val = val + 1
         self.herd_members[ent.id] = val
         return
     # If we have not seen this one before 50 times, then it is not yet
     # really a member of the herd
     if not val > 50: return
     val = val + 1
     self.herd_members[ent.id] = val
     if ent.location.velocity:
         myvel = me.entity.location.velocity.unit_vector()
         evel = ent.location.velocity.unit_vector()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         # If I am moving towards them, or in the same direction, then do nothing
         if myvel and (evel.dot(myvel) > 0.5 or edir.dot(myvel) > 0.5):
             return
         # If they are coming towards me, then do nothing
         if edir.dot(evel) < - 0.5:
             return
         new_loc = Location(me.entity.location.parent)
         new_loc.velocity = ent.location.velocity
     else:
         new_loc = ent.location.copy()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         new_loc.pos = new_loc.pos - edir
     return Operation("move", Entity(me.entity.id, location=new_loc))
예제 #47
0
    def tick_operation(self, op):

        """ Op handler for regular tick op """
        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        self.rate = 0.5 / 0.75
        self.progress += 1

        if not target:
            print("Target is no more")
            self.irrelevant()
            return

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.position = self.pos

        chunk_loc.orientation = self.character.location.orientation
        res = Oplist()
        acount = 0  # A frame count
        lcount = 0  # lumber count
        wcount = 0  # wood count
        ccount = 0  # campfire count
        bcount = 0  # boulder count
        self.fname = ""  # furnishing name
        lumberwidth = 0
        # makes sure we have the right amount of material
        for item in self.character.contains:
            if item.type[0] == "lumber":
                lcount = lcount + 1
                lumberwidth = item.location.bbox.high_corner[2] - item.location.bbox.low_corner[2]
            if item.type[0] == "wood":
                wcount = wcount + 1
            if item.type[0] == "campfire":
                ccount = ccount + 1
            if item.type[0] == "boulder":
                bcount = bcount + 1
            if item.type[0] == "construction":
                acount = acount + 1

        print(str(lcount))
        print(str(wcount))
        if lcount == 1 and wcount == 3:
            self.fname = "Table"
        elif lcount == 4 and wcount == 2:
            self.fname = "Chair"
        elif lcount == 0 and wcount == 5:
            self.fname = "Floor"
        elif lcount == 0 and wcount == 4:
            self.fname = "Siding"
        elif ccount == 1 and bcount == 4:
            self.fname = "Fireplace"
        elif lcount == 3 and wcount == 5:
            self.fname = "Roof"
        elif wcount == 0 and lcount == 5:
            self.fname = "Wallframe"
        else:
            print("No materials in inventory for Furnishings 1")
            self.irrelevant()
            return

        bbox1 = [-1, -1, -1, 1, 1, 1]  # cube bbox so the ojects can be viewed from afar.  Relatively close fit
        if (self.fname == "Floor"):  # If floor make different bbox which is thing so it can be walked over
            bbox1 = [-2, -2, -.01, 2, 2, .01]
        if (self.fname == "Wallframe"):  # If wall frame make bbox based upon the 2 aframes used
            bbox1 = [-lumberwidth, -.5, -lumberwidth, 0, .5, lumberwidth]
        if (self.fname == "Siding"):
            bbox1 = [-3, -.1, -3, 3, .1, 3]
        create = Operation("create", Entity(name=self.fname, type="construction", bbox=bbox1, location=chunk_loc), to=target)
        create.set_serialno(0)
        res.append(create)
        res.append(self.next_tick(1.75))
        return res
예제 #48
0
파일: herd.py 프로젝트: worldforge/cyphesis
 def event(self, me, original_op, op):
     # print "school called"
     ent = op[0]
     if ent.id == me.entity.id:
         # print "detecting myself"
         return
     ent = me.map.get(ent.id)
     if ent == None:
         # print "type is none"
         return
     if ent.name != me.name:
         # print "ent.type!=me.entity.type"
         return
     if type(ent.location.parent) == type(None):
         # print "school.event, ent.location.parent is None"
         return
     if type(me.entity.location.parent) == type(None):
         # print "school.event, me.entity.location.parent is None"
         return
     if me.entity.location.parent.id != ent.location.parent.id:
         # print "me.entity.location.parent.id!=ent.location.parent.id"
         return
     if type(ent.location.pos) != object:
         # print ent.location.pos
         # print type(ent.location.pos)
         # print "type(ent.location.pos)!=object"
         return
     distance = (ent.location.pos - me.entity.location.pos).mag()
     id = me.get_knowledge('focus', 'hook')
     if id != None:
         thing = me.map.get(id)
         if thing == None:
             me.remove_knowledge('focus', what)
         else:
             if thing.location.parent.id != me.entity.location.parent.id:
                 me.remove_knowledge('focus', what)
             else:
                 if thing.location.parent.id == me.entity.id:
                     return
     # ensures that the entity will check only other entities really close to it,
     # thereby reducing the possibility of infinite loops
     if distance < 0.4 and ent.location.velocity:
         print("changing only velocity")
         new_loc = Location(me.entity.location.parent)
         new_loc.velocity = ent.location.velocity
     if distance > 0.4 and ent.location.velocity:
         print("changing both location and velocity")
         myvel = me.entity.location.velocity.unit_vector()
         evel = ent.location.velocity.unit_vector()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         if myvel and (evel.dot(myvel) > 0.9 or edir.dot(myvel) > 0.9):
             return
         if edir.dot(evel) < 0:
             new_loc = Location(me.entity.location.parent)
             # replace by rotatez?
             new_loc.velocity = -ent.location.velocity
         else:
             new_loc = Location(me.entity.location.parent)
             new_loc.velocity = ent.location.velocity
     else:
         print("everything perfect, not doing anything")
         new_loc = ent.location.copy()
         edir = (ent.location.pos - me.entity.location.pos).unit_vector()
         new_loc.pos = new_loc.pos - edir
     return Operation("move", Entity(me.entity.id, location=new_loc))
예제 #49
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Trenching.tick"

        target = self.target()
        if not target:
            # print "Target is no more"
            self.irrelevant()
            return

        # FIXME We are overriding the position specified above?
        self.pos = self.character.location.position

        old_rate = self.rate
        self.rate = 0.5 / 0.75
        self.progress += 0.5

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.position = self.pos

        if not hasattr(self, 'terrain_mod'):
            mods = target.terrain.find_mods(self.pos)
            if len(mods) == 0:
                # There is no terrain mod where we are digging,
                # so we check if it is in the materials , and if so create
                # a trench
                surface = target.terrain.get_surface(self.pos)
                # print "SURFACE %d at %s" % (surface, self.pos)
                if surface not in Trenching.materials:
                    # print "Not in material"
                    self.irrelevant()
                    return
                self.surface = surface

                y = self.character.location.position.y - 1.0
                modmap = {
                    'height': y,
                    'shape': {
                        'points': [[-1.0, -1.0],
                                   [-1.0, 1.0],
                                   [1.0, 1.0],
                                   [1.0, -1.0]],
                        'type': 'polygon'
                    },
                    'type': 'levelmod'
                }
                trenches_create = Operation("create",
                                            Entity(name="trenches",
                                                   type="path",
                                                   location=chunk_loc,
                                                   terrainmod=modmap),
                                            to=target)
                res.append(trenches_create)
            else:
                for mod in mods:
                    if not hasattr(mod, 'name') or mod.name != 'trenches':
                        # print "%s is no good" % mod.id
                        continue
                    # print "%s looks good" % mod.id
                    mod.terrainmod.height -= 1.0
                    # We have modified the attribute in place, so must send an update op to propagate
                    res.append(Operation("update", to=mod.id))
                    break
            # self.terrain_mod = "moddy_mod_mod"

        create = Operation("create",
                           Entity(name=Trenching.materials[self.surface],
                                  type="pile",
                                  material=Trenching.materials[self.surface],
                                  location=chunk_loc), to=target)
        res.append(create)

        res.append(self.next_tick(0.75))

        return res
예제 #50
0
    def tick_operation(self, op):
        """ Op handler for regular tick op """
        # print "Delve.tick"

        if self.target() is None:
            # print "Target is no more"
            self.irrelevant()
            return

        old_rate = self.rate

        self.rate = 0.5 / 0.75
        self.progress += 0.5

        if old_rate < 0.01:
            self.progress = 0

        # print "%s" % self.pos

        if self.progress < 1:
            # print "Not done yet"
            return self.next_tick(0.75)

        self.progress = 0

        res = Oplist()

        chunk_loc = Location(self.character.location.parent)
        chunk_loc.velocity = Vector3D()

        chunk_loc.position = self.pos

        if not hasattr(self, 'terrain_mod'):
            mods = self.target().props.terrain.find_mods(self.pos)
            if len(mods) == 0:
                # There is no terrain mod where we are digging,
                # so we check if it is rock, and if so create
                # a quarry
                surface = self.target().props.terrain.get_surface(self.pos)
                # print "SURFACE %d at %s" % (surface, self.pos)
                if surface not in Delve.materials:
                    print("Not rock")
                    self.irrelevant()
                    return
                self.surface = surface

                y = self.character.location.position.y + 1.0
                modmap = {
                    'height': y,
                    'shape': {
                        'points': [[-1.0, -1.0],
                                   [-1.0, 1.0],
                                   [1.0, 1.0],
                                   [1.0, -1.0]],
                        'type': 'polygon'
                    },
                    'type': 'levelmod'
                }
                quarry_create = Operation("create",
                                          Entity(name="quarry",
                                                 type="path",
                                                 location=chunk_loc,
                                                 terrainmod=modmap),
                                          to=self.target())
                res.append(quarry_create)
            else:
                print(mods)
                for mod in mods:
                    if not hasattr(mod, 'name') or mod.name != 'quarry':
                        print("%s is no good" % mod.id)
                        continue
                    print("%s looks good" % mod.id)
                    print(mod.terrainmod)
                    mod.terrainmod.height -= 2.0
                    # We have modified the attribute in place, so must send an update op to propagate
                    res.append(Operation("update", to=mod.id))
                    break
            # self.terrain_mod = "moddy_mod_mod"

        create = Operation("create",
                           Entity(name=Delve.materials[self.surface],
                                  type=Delve.materials[self.surface],
                                  location=chunk_loc), to=self.target())
        res.append(create)

        res.append(self.next_tick(0.75))

        return res
예제 #51
0
    def info_operation(self, op):
        print("Gate info")
        gate = server.world.get_object(op[0].id)
        self.lcount = 0  # needs 1 lumber for basic gate
        self.acount = 0  # needs 2 a frames for basic gate
        raw_materials = []  # Holds construction
        raw_materials1 = []  # Holds lumber
        for item in self.character.contains:
            if item.type[0] == str("construction"):
                raw_materials.append(item)
                self.acount = self.acount + 1
            if item.type[0] == str("lumber"):
                raw_materials1.append(item)
                self.lcount = self.lcount + 1
            if self.acount == 2 and self.lcount == 1:
                break
            if self.lcount == 3:
                break
        else:
            print("No materials in inventory for Gate")
            self.irrelevant()
            return

        chunk_loc = Location(gate())
        chunk_loc.position = Point3D([0, 0, 0])
        res = Oplist()

        if self.gname == "Basic_Gate":
            count1 = self.lcount
            while (count1 > 0):
                tar = raw_materials1.pop()
                self.lumber_length = tar.location.bbox.high_corner[2] - \
                                     tar.location.bbox.low_corner[2]
                offset = Vector3D(self.lumber_length / 7, self.lumber_length * .63, -
                self.lumber_length / 3.5)
                chunk_loc.orientation = Quaternion([.707, 0, 0, .707])
                # Same as an Euler of (0,90 Degrees,0)
                chunk_loc.position = chunk_loc.position + offset
                move1 = Operation("move", Entity(tar.id, location=chunk_loc,
                                                 mode="fixed"), to=tar)
                res.append(move1)
                count1 = count1 - 1

            count = self.acount
            chunk_loc = Location(gate())
            chunk_loc.position = Point3D([0, 0, 0])
            # Resets
            # loops through raw_materials and places 3 lumber
            # in inventory infront of user
            offset = Vector3D(0, 0, 0)
            while (count > 0):
                tar = raw_materials.pop()

                if count == 2:
                    # left component of gate
                    chunk_loc.position = Point3D([0, 0, 0])
                    offset = Vector3D(0, self.lumber_length * .7, 0)
                    chunk_loc.orientation = Quaternion([.707, 0, 0, .707])
                    chunk_loc.position = chunk_loc.position + offset

                if count == 1:
                    # right component of gate
                    chunk_loc.position = Point3D([0, 0, 0])
                    offset = Vector3D(0,
                                      self.lumber_length * .7, (self.lumber_length / 2))
                    chunk_loc.orientation = Quaternion([.707, 0, 0, .707])
                    chunk_loc.position = chunk_loc.position + offset

                move = Operation("move", Entity(tar.id, location=chunk_loc,
                                                mode="fixed"), to=tar)
                res.append(move)
                count = count - 1

        if self.gname == "House_Gate":
            # Left leg of the house frame
            tar = raw_materials1.pop()
            chunk_loc.position = Point3D([0, 0, 0])
            self.lumber_length = tar.location.bbox.high_corner[2] - \
                                 tar.location.bbox.low_corner[2]
            offset = Vector3D(0, self.lumber_length * .8, -self.lumber_length / 4)
            chunk_loc.orientation = Quaternion([.707, .707, 0, 0])
            chunk_loc.position = chunk_loc.position + offset
            move1 = Operation("move", Entity(tar.id, location=chunk_loc,
                                             mode="fixed"), to=tar)
            res.append(move1)
            # Right Leg of the house frame
            tar = raw_materials1.pop()
            chunk_loc.position = Point3D([0, 0, 0])
            self.lumber_length = tar.location.bbox.high_corner[2] - \
                                 tar.location.bbox.low_corner[2]
            offset = Vector3D(0,
                              self.lumber_length * .8, -self.lumber_length * (3.0 / 4.0))
            chunk_loc.orientation = Quaternion([.707, .707, 0, 0])
            chunk_loc.position = chunk_loc.position + offset
            move1 = Operation("move", Entity(tar.id, location=chunk_loc,
                                             mode="fixed"), to=tar)
            res.append(move1)
            # Top of the house frame
            tar = raw_materials1.pop()
            chunk_loc.position = Point3D([0, 0, 0])
            self.lumber_length = tar.location.bbox.high_corner[2] - \
                                 tar.location.bbox.low_corner[2]
            offset = Vector3D(0, self.lumber_length * (.7, -self.lumber_length))
            chunk_loc.orientation = Quaternion([.5, .5, -.5, .5])
            # Same as (90 Degrees, 0, 90 Degrees)
            chunk_loc.position = chunk_loc.position + offset
            move1 = Operation("move", Entity(tar.id, location=chunk_loc,
                                             mode="fixed"), to=tar)
            res.append(move1)

        self.progress = 1
        self.irrelevant()
        return res
예제 #52
0
 def event(self, me, original_op, op):
     distance = distance_to(me.map.get(op.from_).location, me.entity.location)
     destination = Location()
     destination.velocity = distance.unit_vector()
     return Operation("move", Entity(me.entity.id, location=destination))
예제 #53
0
    def info_operation(self, op):
        print("Furnishings info")
        item = server.world.get_object(op[0].id)
        chunk_loc = Location(item())
        chunk_loc.position = Point3D([0, 0, 0])
        res = Oplist()
        target = self.target()
        raw_materials = []
        raw_materials1 = []  # holders campfire
        raw_materials2 = []  # temp holder for aframes to be moved
        acount = 0  # A frame count
        lcount = 0  # Lumber count
        wcount = 0  # Wood count
        bcount = 0  # Boulder count
        ccount = 0  # Campfire count
        for item in self.character.contains:
            if item.type[0] == "lumber":
                raw_materials.append(item)
                lcount = lcount + 1
            if item.type[0] == "wood":
                raw_materials.append(item)
                wcount = wcount + 1
            if item.type[0] == "campfire":
                raw_materials1.append(item)
                ccount = ccount + 1
            if item.type[0] == "boulder":
                raw_materials.append(item)
                bcount = bcount + 1
            if item.type[0] == "construction":
                raw_materials2.append(item)
                acount = acount + 1

        count = lcount + wcount + bcount
        if self.fname == "Table":
            # Making table
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # create the table
            # Table base
            lbbox = [-.2, -.2, -.5, .2, .2, .5]  # local bbox
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # create the table top
            offset = Vector3D(0, 1, 0)
            chunk_loc.position = chunk_loc.position + offset
            lbbox = [-.7, -.7, -.1, .7, .7, .1]
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
        if self.fname == "Chair":
            # Making chair
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # create the legs
            # leg 1
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(.2, 0, -.2)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target)
            res.append(create)

            # leg 2
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(-.2, 0, -.2)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target)
            res.append(create)

            # leg 3
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(-.2, 0, .2)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target)
            res.append(create)

            # leg 4
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(.2, 0, .2)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target)
            res.append(create)

            # create the seat
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(0, .5, 0)
            lbbox = [-.3, -.3, -.1, .3, .3, .1]  # Local bbox
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)

            # create the back of the seat
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(-.3, .75, 0)
            lbbox = [-.1, -.3, -.4, .1, .3, .4]  # local bbox
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)

        if self.fname == "Floor":
            # Making Floor
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # create the Floor, it is one large wood
            lbbox = [-2, -2, -.1, 2, 2, .1]  # local bbox
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
        if self.fname == "Siding":
            # Making wooden siding with window
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # Siding is made of 4 components so it looks like we have a window
            # Bottom part
            lbbox = [-3, -.1, -1, 3, .1, 2]
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # Top part
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(0, 4, 0)
            chunk_loc.position = chunk_loc.position + offset
            lbbox = [-3, -.1, -1, 3, .1, 2]
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # left part
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(-2, 2, 0)
            chunk_loc.position = chunk_loc.position + offset
            lbbox = [-1, -.1, -.5, 1, .1, .5]
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # Right part
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(2, 2, 0)
            chunk_loc.position = chunk_loc.position + offset
            lbbox = [-1, -.1, -.5, 1, .1, .5]
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
        if self.fname == "Fireplace":
            # Making Fireplace
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # Move campfire
            tar = raw_materials1.pop()
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
            # make floor of fireplace
            lbbox = [-2, -1, -.1, 2, 1, .1]  # local bbox
            create = Operation("create", Entity(name="boulder", type="boulder", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # make wall 1 of fireplace
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(-1.6, 0, 0)
            lbbox = [-.1, -1, -.1, .1, 1, 1.5]
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="boulder", type="boulder", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # make wall 2 of fireplace
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(1.6, 0, 0)
            lbbox = [-.1, -1, -.1, .1, 1, 1.5]
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="boulder", type="boulder", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # make back of fireplace
            chunk_loc.position = Point3D([0, 0, 0])
            offset = Vector3D(0, 0, .6)
            lbbox = [-2, -.1, -.1, 2, .1, 1.5]
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="boulder", type="boulder", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
        if self.fname == "Wallframe":
            # Bottom part of wall frame
            chunk_loc.position = Point3D([0, 0, 0])
            tar = raw_materials.pop()
            lumberlength = tar.location.bbox.high_corner[2] - tar.location.bbox.low_corner[2]
            chunk_loc.orientation = Quaternion([.5, .5, .5, .5])
            offset = Vector3D(-lumberlength / 2, 0, 0)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
            # Top part of wall frame
            chunk_loc.position = Point3D([0, 0, 0])
            tar = raw_materials.pop()
            offset = Vector3D(-lumberlength / 2, 0, lumberlength * .8)
            chunk_loc.position = chunk_loc.position + offset
            chunk_loc.orientation = Quaternion([.5, .5, .5, .5])
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
            # Left part of wall frame
            chunk_loc.position = Point3D([0, 0, 0])
            tar = raw_materials.pop()
            offset = Vector3D((lumberlength / 2.0) * -.8, lumberlength * .8, 0)
            chunk_loc.position = chunk_loc.position + offset
            chunk_loc.orientation = Quaternion([.707, .707, 0, 0])
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
            # Right part of wall frame
            chunk_loc.position = Point3D([0, 0, 0])
            tar = raw_materials.pop()
            offset = Vector3D((lumberlength / 2.0) * .8, lumberlength * .8, 0)
            chunk_loc.position = chunk_loc.position + offset
            chunk_loc.orientation = Quaternion([.707, .707, 0, 0])
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
            # Center part of wall frame
            chunk_loc.position = Point3D([0, 0, 0])
            tar = raw_materials.pop()
            offset = Vector3D((lumberlength / 2.0) * -.8, lumberlength * .1, 0)
            chunk_loc.position = chunk_loc.position + offset
            chunk_loc.orientation = Quaternion([.27, .27, .65, .65])
            create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar)
            res.append(create)
        if self.fname == "Roof":
            # Making the roof, roof is 1 lumber and a large wooden covering
            while (count > 0):
                tar = raw_materials.pop()
                set = Operation("set", Entity(tar.id, status=-1), to=tar)
                res.append(set)
                count = count - 1
            # create the top, it is one large wood
            lbbox = [-4, -4, -.1, 4, 4, .3]  # local bbox
            offset = Vector3D(0, 5, 0)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="wood", type="wood", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)
            # create column
            chunk_loc.position = Point3D([0, 0, 0])
            lbbox = [-.5, -.5, -.1, .5, .5, 6]  # local bbox
            offset = Vector3D(0, 0, 0)
            chunk_loc.position = chunk_loc.position + offset
            create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, bbox=lbbox, mode="fixed"), to=target)
            res.append(create)

        self.progress = 1
        self.irrelevant()
        return res