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
def _create_initial_mod(self): y = self.character.location.pos.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.pos = 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.pos.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.pos = 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 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.pos = self.pos bait_vector = Vector3D(0, -0.5, -0) bait_loc = float_loc.copy() bait_loc.pos = bait_loc.pos + 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
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 """ 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
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)
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 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)
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 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): # 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 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.pos = 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.pos = chunk_loc.pos + 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.pos = 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.pos = Point3D([0, 0, 0]) offset = Vector3D(0, self.lumber_length * .7, 0) chunk_loc.orientation = Quaternion([.707, 0, 0, .707]) chunk_loc.pos = chunk_loc.pos + offset if count == 1: # right component of gate chunk_loc.pos = 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.pos = chunk_loc.pos + 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.pos = 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.pos = chunk_loc.pos + 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.pos = 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.pos = chunk_loc.pos + 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.pos = 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.pos = chunk_loc.pos + offset move1 = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar) res.append(move1) self.progress = 1 self.irrelevant() return res
def info_operation(self, op): print("Furnishings info") item = server.world.get_object(op[0].id) chunk_loc = Location(item()) chunk_loc.pos = 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.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(.2, 0, -.2) chunk_loc.pos = chunk_loc.pos + offset create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target) res.append(create) # leg 2 chunk_loc.pos = Point3D([0, 0, 0]) offset = Vector3D(-.2, 0, -.2) chunk_loc.pos = chunk_loc.pos + offset create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target) res.append(create) # leg 3 chunk_loc.pos = Point3D([0, 0, 0]) offset = Vector3D(-.2, 0, .2) chunk_loc.pos = chunk_loc.pos + offset create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target) res.append(create) # leg 4 chunk_loc.pos = Point3D([0, 0, 0]) offset = Vector3D(.2, 0, .2) chunk_loc.pos = chunk_loc.pos + offset create = Operation("create", Entity(name="lumber", type="lumber", location=chunk_loc, mode="fixed"), to=target) res.append(create) # create the seat chunk_loc.pos = Point3D([0, 0, 0]) offset = Vector3D(0, .5, 0) lbbox = [-.3, -.3, -.1, .3, .3, .1] # Local bbox chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(-.3, .75, 0) lbbox = [-.1, -.3, -.4, .1, .3, .4] # local bbox chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(0, 4, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(-2, 2, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(2, 2, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(-1.6, 0, 0) lbbox = [-.1, -1, -.1, .1, 1, 1.5] chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(1.6, 0, 0) lbbox = [-.1, -1, -.1, .1, 1, 1.5] chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) offset = Vector3D(0, 0, .6) lbbox = [-2, -.1, -.1, 2, .1, 1.5] chunk_loc.pos = chunk_loc.pos + 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.pos = 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.pos = chunk_loc.pos + offset create = Operation("move", Entity(tar.id, location=chunk_loc, mode="fixed"), to=tar) res.append(create) # Top part of wall frame chunk_loc.pos = Point3D([0, 0, 0]) tar = raw_materials.pop() offset = Vector3D(-lumberlength / 2, 0, lumberlength * .8) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) tar = raw_materials.pop() offset = Vector3D((lumberlength / 2.0) * -.8, lumberlength * .8, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) tar = raw_materials.pop() offset = Vector3D((lumberlength / 2.0) * .8, lumberlength * .8, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) tar = raw_materials.pop() offset = Vector3D((lumberlength / 2.0) * -.8, lumberlength * .1, 0) chunk_loc.pos = chunk_loc.pos + 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.pos = chunk_loc.pos + 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.pos = Point3D([0, 0, 0]) lbbox = [-.5, -.5, -.1, .5, .5, 6] # local bbox offset = Vector3D(0, 0, 0) chunk_loc.pos = chunk_loc.pos + 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
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 """ 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.pos = 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