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
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
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)
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 if square_distance(self.character.location, self.target().location) > self.target( ).location.bbox.square_bounding_radius(): return self.next_tick(1) target_location = Location(self.target().location.parent, self.target().location.position) target_location.velocity = Vector3D(0, -0.5, 0) target_entity_moving = Entity(self.target().id, location=target_location) target_location = Location( self.target().location.parent, Point3D(self.target().location.position.x, self.target().location.position.y - 0.1, self.target().location.position.z)) target_location.velocity = Vector3D(0, 0, 0) target_entity = Entity(self.target().id, location=target_location) 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) move = Operation("move", target_entity_moving, to=self.target()) res.append(move) res.append(self.next_tick(1)) return res
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))
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.pos) target_location.velocity = Vector3D(0, -0.5, 0) new_loc = self.character.location.pos 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.pos.x, self.target().location.pos.y + diff, self.target().location.pos.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
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))
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))
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))
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))
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
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
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
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
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))
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))
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
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))
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))
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
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))
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))
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
def event(self, me, original_op, op): direction = me.steering.direction_to(me.map.get(op.from_).location) destination = Location() destination.velocity = -direction.unit_vector() return Operation("move", Entity(me.entity.id, location=destination))
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