def _setup_camp(m): cfire=m.make('campfire',pos=(100,-50,settlement_height)) m.make('fire',pos=(0,0,0),parent=cfire.id) cfire=m.make('campfire',pos=(90,-50,settlement_height)) m.make('fire',pos=(0,0,0),parent=cfire.id) for i in range(10, 350, 5): direction=Vector3D(sin(radians(i)) * uniform(0,2), cos(radians(i)) * uniform(0,2), 10).unit_vector() orient=Quaternion(Vector3D(0,0,1), direction) m.make('stake', pos=(100 + 14 * sin(radians(i)), -50 + 16 * cos(radians(i)), -1), bbox=[-0.5,-0.5,0,0.5,0.5,5 + uniform(0,2)], orientation=orient.as_list()) camp_area_points=[] for i in range(10, 350, 17): camp_area_points.append([14 * sin(radians(i)), 16 * cos(radians(i))]) camp_area={'shape': {'points': camp_area_points, 'type': 'polygon'}, 'layer': 7 } m.make('path', name='camp_area', pos=camp_pos, area=camp_area, bbox=[-14, -16, 0, 14, 16, 1], spawn={'name': 'goblin village', 'character_types': ['goblin'], 'contains': ['shirt', 'trousers', 'cloak', 'boots', 'hat']})
def _setup_camp(m): cfire=m.make('campfire',pos=(100,-50,settlement_height)) m.make('fire',pos=(0,0,0),parent=cfire.id) cfire=m.make('campfire',pos=(90,-50,settlement_height)) m.make('fire',pos=(0,0,0),parent=cfire.id) for i in range(10, 350, 5): direction=Vector3D(sin(radians(i)) * uniform(0,2), cos(radians(i)) * uniform(0,2), 10).unit_vector() orient=Quaternion(Vector3D(0, 1, 0), direction) m.make('stake', pos=(100 + 14 * sin(radians(i)), -50 + 16 * cos(radians(i)), -1), bbox=[-0.5,-0.5,0,0.5,0.5,5 + uniform(0,2)], orientation=orient.as_list()) camp_area_points=[] for i in range(10, 350, 17): camp_area_points.append([14 * sin(radians(i)), 16 * cos(radians(i))]) camp_area={'shape': {'points': camp_area_points, 'type': 'polygon'}, 'layer': 7 } m.make('path', name='camp_area', pos=camp_pos, area=camp_area, bbox=[-14, -16, 0, 14, 16, 1], spawn={'name': 'goblin village', 'character_types': ['goblin'], 'contains': ['shirt', 'pants', 'cloak', 'boots', 'hat']})
def _setup_camp(m): cfire = m.make("campfire", pos=(100, -50, settlement_height)) m.make("fire", pos=(0, 0, 0), parent=cfire.id) cfire = m.make("campfire", pos=(90, -50, settlement_height)) m.make("fire", pos=(0, 0, 0), parent=cfire.id) for i in range(10, 350, 5): direction = Vector3D(sin(radians(i)) * uniform(0, 2), cos(radians(i)) * uniform(0, 2), 10).unit_vector() orient = Quaternion(Vector3D(0, 0, 1), direction) m.make( "stake", pos=(100 + 14 * sin(radians(i)), -50 + 16 * cos(radians(i)), -1), bbox=[-0.5, -0.5, 0, 0.5, 0.5, 5 + uniform(0, 2)], orientation=orient.as_list(), ) camp_area_points = [] for i in range(10, 350, 17): camp_area_points.append([14 * sin(radians(i)), 16 * cos(radians(i))]) camp_area = {"shape": {"points": camp_area_points, "type": "polygon"}, "layer": 7} m.make( "path", name="camp_area", pos=camp_pos, area=camp_area, bbox=[-14, -16, 0, 14, 16, 1], spawn={ "name": "goblin village", "character_types": ["goblin"], "contains": ["shirt", "trousers", "cloak", "boots", "hat"], }, )
def info_operation(self,op): print("Aframe info") aframe = server.world.get_object_ref(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.coordinates =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.far_point[2]- \ tar.location.bbox.near_point[2] lumberheight=tar.location.bbox.far_point[1]- \ tar.location.bbox.near_point[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.coordinates=chunk_loc.coordinates+offset if count == 1 : #bottom component chunk_loc.coordinates = 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),-(2.5*lumber_length),0) chunk_loc.coordinates=chunk_loc.coordinates+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
def _add_obstacles(m): for i in range(0, num_obstacles): xpos = uniform(xmin, xmax) ypos = uniform(ymin, ymax) orient = Quaternion(Vector3D(0, 1, 0), uniform(0, pi * 2.0)) m.make('stone_palisade', pos=(xpos, ypos, defaultZ), orientation=orient.as_list())
def _add_agents(m): for i in range(0, num_humans): xpos = uniform(xmin, xmax) ypos = uniform(ymin, ymax) orient = Quaternion(Vector3D(0, 0, 1), uniform(0, pi * 2.0)) h = m.make('human', pos=(xpos, ypos, defaultZ), orientation=orient.as_list()) m.know(h, [('w1', 'location', (uniform(xmin, xmax), uniform(ymin, ymax), defaultZ)) , ('w2', 'location', (uniform(xmin, xmax), uniform(ymin, ymax), defaultZ)) , ('w3', 'location', (uniform(xmin, xmax), uniform(ymin, ymax), defaultZ)) , ('w4', 'location', (uniform(xmin, xmax), uniform(ymin, ymax), defaultZ))]) m.learn(h, [(il.patrol, "patrol(['w1', 'w2', 'w3', 'w4'])")])
def shoot_in_direction(direction, instance, res): Usage.set_cooldown_on_attached(instance.tool, instance.actor) arrows = instance.actor.find_in_contains(arrow_filter) if len(arrows): direction.normalize() # Adjust the start position of the arrow, so it's outside of the actor, at mid height start_adjust = Vector3D(direction) start_adjust.y = 0 start_adjust.normalize() start_adjust.y = instance.actor.location.bbox.high_corner.y * 0.8 new_loc = instance.actor.location.copy() new_loc.pos += start_adjust new_loc.orientation = Quaternion(Vector3D(0, 0, 1), direction, Vector3D(1, 0, 0)) mode_data = {"mode": "projectile", "$eid": instance.actor.id, "extra": {"damage": 20}} # TODO: match with animation in client res.append(instance.actor.start_action("bow/releasing", 1)) res.append(Operation("move", Entity(arrows[0].id, location=new_loc, velocity=direction * 60, mode="projectile", mode_data=mode_data), to=arrows[0].id))
def shoot_poison_in_direction(direction, instance, res): Usage.set_cooldown_on_attached(instance.tool, instance.actor) direction.normalize() # Adjust the start position of the projectile, so it's outside of the actor, at mid height start_adjust = Vector3D(direction) start_adjust.y = 0 start_adjust.normalize() start_adjust.y = instance.actor.location.bbox.high_corner.y * 0.8 new_loc = instance.actor.location.copy() new_loc.pos += start_adjust new_loc.orientation = Quaternion(Vector3D(0, 0, 1), direction, Vector3D(1, 0, 0)) mode_data = {"mode": "projectile", "$eid": instance.actor.id} res.append( Operation("create", Entity(parent="poisonball", location=new_loc, velocity=direction * 60, mode="projectile", mode_data=mode_data, damage_poison=instance.tool.props.damage), to=instance.tool.id))
def face(self, other): vector = distance_to(self.location, other.location) vector.z = 0 if vector.square_mag() < 0.1: return vector = vector.unit_vector() newloc = Location(self.location.parent) newloc.orientation = Quaternion(Vector3D(1, 0, 0), vector) return Operation("move", Entity(self.id, location=newloc))
def face(self, other): """turn to face other entity""" vector = distance_to(self.entity.location, other.location) vector.y = 0 if vector.sqr_mag() < 0.1: return vector = vector.unit_vector() newloc = Location(self.entity.location.parent) newloc.orientation = Quaternion(Vector3D(0, 0, 1), vector, Vector3D(0, 1, 0)) return Operation("move", Entity(self.entity.id, location=newloc))
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.z = 0 if vector.square_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))
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.square_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, 0, 1)) # 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.coordinates) 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
def face(self, other): """turn to face other entity""" vector = self.steering.direction_to(other) if vector is None: return vector.y = 0 if vector.sqr_mag() < 0.1: return vector = vector.unit_vector() return Operation( "set", Entity(self.entity.id, _direction=Quaternion(Vector3D(0, 0, 1), vector, Vector3D(0, 1, 0)).as_list()))
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 tick_operation(self, op): """ Op handler for regular tick op """ # print "Logging.tick" if self.target() is None: # print "Target is no more" self.irrelevant() return current_status = self.target().status #Measure the distance between the entity horizontal edges. Else we won't be able to reach if either entity is too thick. distance_between_entity_edges_squared = square_horizontal_edge_distance(self.character.location, self.target().location) #Assume that a standard human can reach 1.5 meters, and use this to determine if we're close enough to be able to perform the logging standard_human_reach_squared=1.5*1.5 if distance_between_entity_edges_squared > standard_human_reach_squared: self.progress = 1 - current_status self.rate = 0 return self.next_tick(1.75) res=Oplist() if current_status > 0.11: set=Operation("set", Entity(self.target().id, status=current_status-0.1), to=self.target()) res.append(set) # print "CHOP",current_status normal=Vector3D(0,0,1) # print "LOC.ori ", self.target().location.orientation # calculate how tilted the tree is already if self.target().location.orientation.is_valid(): normal.rotate(self.target().location.orientation) # print "Normal ", normal, normal.dot(Vector3D(0,0,1)) # if the tree is standing, and it's already half cut down, rotate # it to be horizontal, away from the character if normal.dot(Vector3D(0,0,1)) > 0.8 and current_status < 0.5: # print "Fall down" # determine the axis of rotation by cross product of the vector # from character to tree, and vertically upward vector axis = distance_to(self.character.location, self.target().location).cross(Vector3D(0,0,1)) # the axis must be a unit vector try: axis = axis.unit_vector() except ZeroDivisionError: axis = Vector3D(1,0,0) # print "axis ", axis # create a rotation of 90 degrees around this axis orient = Quaternion(axis, math.pi / -2.0) # if the tree is rotated, apply this too if self.target().location.orientation.is_valid(): orient = self.target().location.orientation * orient move_location = self.target().location.copy() move_location.orientation = orient move = Operation("move", Entity(self.target().id, mode='felled', location=move_location), to = self.target()) res.append(move) else: # print "become log" set = Operation("set", Entity(self.target().id, status = -1), to = self.target()) res.append(set) create_loc = self.target().location.copy() create_loc.orientation = self.target().location.orientation create = Operation("create", Entity(parents = ["lumber"], mass = self.target().mass, location = create_loc, bbox = self.target().bbox), to = self.target()) res.append(create) self.progress = 1 - current_status self.rate = 0.1 / 1.75 res.append(self.next_tick(1.75)) return res
def default(host='', account='', password='', **args): # general things m=create_editor(host, account, password) world=m.look() if not hasattr(world, 'name'): _setup_landscape(m, world) _setup_outpost(m) _setup_settlement(m) _setup_camp(m) _add_resources(m) _add_animals(m) # Example of Mercator forest. # m.make('forest', name='sherwood',pos=(-50, 10,settlement_height), # bbox=[40,40,40]) # the lych, who makes bones into skeletons if m.look_for(type='lych') is None: lych=m.make('lych', pos=(-21, -89, settlement_height)) m.learn(lych,lych_goals) m.know(lych,lych_knowledge) m.tell_importance(lych,il.assemble,'>',il.patrol) # animals if m.look_for(type='pig') is None: piglet = m.make('pig', pos=(-3,-1,settlement_height)) m.learn(piglet,pig_goals) if m.look_for(type='wolf') is None: wolf = m.make('wolf', pos=(90,-90,settlement_height)) m.learn(wolf,wolf_goals) m.know(wolf,wolf_knowledge) m.tell_importance(wolf,il.forage,'>',il.hunt) m.tell_importance(wolf,il.forage,'>',il.patrol) m.tell_importance(wolf,il.hunt,'>',il.patrol) if m.look_for(type='crab') is None: crab = m.make('crab', pos=(-90,90,settlement_height)) m.learn(crab,crab_goals) if m.look_for(type='skeleton') is None: skeleton = m.make('skeleton', pos=(-38,-25,settlement_height)) m.learn(skeleton,skeleton_goals) if m.look_for(type='squirrel') is None: squirrel = m.make('squirrel', pos=(-32,-15,settlement_height)) m.know(squirrel,sknowledge) m.learn(squirrel,squirrel_goals) # villagers # An NPC settler if m.look_for(name='Ranum Umado') is None: settler=m.make('settler', name='Ranum Umado', pos=(0,40,0)) axe=m.make('axe',pos=(0,0,0),parent=settler.id) m.own(settler,axe) m.know(settler,[('forest','location',(130,40,0))]) m.learn(settler,(il.trade,"harvest_resource('lumber','oak','forest','axe', range=60)")) m.learn(settler,(il.roam,"roam(60, ['forest'])")) # An NPC forester if m.look_for(name='Ineos Adsam') is None: settler=m.make('settler', name='Ineos Adsam',pos=(0, 30, 0)) trowel=m.make('trowel',pos=(0,0,0),parent=settler.id) m.own(settler, trowel) m.know(settler,[('forest','location',(130,40,0))]) m.learn(settler,(il.trade,"plant_seeds('acorn','oak','forest','trowel', range=60)")) m.learn(settler,(il.roam,"roam(60, ['forest'])")) stall = m.look_for(name='Butcher Stall') if stall is None: stall=m.make('stall', name='Butcher Stall', pos=butcher_stall_pos, orientation=directions[5]) m.make('wall', parent=stall.id, pos=(0 ,0 ,0), bbox=(-0.5, -1.5, 0, 0.5, 1.5, 0.8)) m.make('wall', parent=stall.id, pos=(2, 0, 0), bbox=(0, -1.5, 0, 0.5, 1.5, 2)) # An NPC Butcher if m.look_for(name='Ulad Bargan') is None: butcher=m.make('settler', name='Ulad Bargan',desc='the butcher', pos=butcher_pos,age=probability.fertility_age) m.learn(butcher,(il.trade,"trade('pig', 'cleaver', 'ham', 'market')")) m.learn(butcher,(il.buy_livestock,"buy_livestock('pig', 1)")) m.learn(butcher,(il.market,"run_shop('mstall_freshmeat_1_se'," "'open','dawn')")) m.learn(butcher,(il.market,"run_shop('mstall_freshmeat_1_se'," "'closed','evening')")) m.learn(butcher,(il.help,"add_help(['" "I need live pigs to restock my butcher stall.'," "'Do you have any pigs for sale?'," "'I prefer pigs that have grown to more than 20kg.']," "['I would like to sell a pig'])")) m.know(butcher,bknowledge) m.know(butcher,bprices) cleaver=m.make('cleaver', place='market', pos=(0, 0, 0), parent=butcher.id) m.own(butcher,cleaver) m.own(butcher, stall) m.learn(butcher,(il.sell,"sell_trade('ham', 'market')")) coins=[] for i in range(0, 60): coins.append(m.make('coin',pos=(0,0,0),parent=butcher.id)) m.own(butcher,coins) # clothing-merchant stall = m.look_for(name='Tailor Stall') if stall is None: stall = m.make('stall', name='Tailor Stall', pos=tailor_stall_pos, orientation=directions[7]) m.make('wall', parent=stall.id, pos=(0, 0, 0), bbox=(-0.5,-1.5,0,0.5,1.5,0.8)) m.make('wall', parent=stall.id, pos=(2, 0, 0), bbox=(0,-1.5,0,0.5,1.5,2)) if m.look_for(name='Bok Forgo') is None: tailor=m.make('merchant', name='Bok Forgo',desc='the tailor', pos=tailor_pos,age=probability.fertility_age) m.learn(tailor,(il.help,"add_help(['Get your clothes here.','Everything to keep you looking your best is here.'])")) m.know(tailor, tailor_knowledge) m.know(tailor, tailor_prices) m.own(tailor, stall) clothes=[] garment_types=['shirt', 'pants', 'cloak'] garment_styles=['ragged', 'burlap', 'sun', 'fine'] for i in range(0, 15): gty = garment_types[randint(0, len(garment_types)-1)] gsty = garment_styles[randint(0, len(garment_styles)-1)] gname = '%s %s' % (gsty, gty) clothes.append(m.make(gty,name=gname,pos=(0, uniform(-0.7, 0.7), 0), parent=stall.id)) m.own(tailor, clothes) # tool-merchant stall = m.look_for(name='Tool Stall') if stall is None: stall = m.make('stall', name='Tool Stall', pos=tool_stall_pos, orientation=directions[2]) m.make('wall', parent=stall.id, pos=(0, 0, 0), bbox=(-0.5,-1.5,0,0.5,1.5,0.8)) m.make('wall',parent=stall.id, pos=(2, 0, 0), bbox=(0,-1.5,0,0.5,1.5,2)) if m.look_for(name='Blackun Decker') is None: tmerchant=m.make('merchant', name='Blackun Decker', desc='the tool merchant', pos=tool_merchant_pos,age=probability.fertility_age) m.learn(tmerchant,(il.help,"add_help(['Get all your tools here.'," "'Everything a settler needs is available at " "great prices.'])")) m.know(tmerchant, toolmerc_knowledge) m.know(tmerchant, toolprices) m.own(tmerchant, stall) tools=[] # the different tools must be stated here \|/ tooltypes=['shovel', 'axe', 'tinderbox', 'bowl', 'pole', 'bottle', 'cleaver', 'pickaxe', 'scythe', 'bucksaw', 'trowel', 'hammer', 'fishingrod', 'sieve', ] for i in range(0, 20): tty = tooltypes[randint(0,len(tooltypes)-1)] tools.append(m.make(tty, pos=(uniform(-0.7, 0.7), uniform(-0.5,0.5),0.6), parent=stall.id, orientation=directions[randint(0,7)])) m.own(tmerchant,tools) sty = m.look_for(type='sty') if sty is None: sty=m.make('sty',pos=pig_sty_pos) merchant = m.look_for(name='Dyfed Searae') if merchant is None: merchant=m.make('merchant', name='Dyfed Searae',desc='the pig merchant', pos=pig_sty_pos,age=probability.fertility_age, orientation=Quaternion(Vector3D([1,0,0]), Vector3D([0,-1,0])).as_list()) m.know(merchant,mknowledge) m.know(merchant,area) m.know(merchant,mprices) m.learn(merchant,(il.keep,"keep_livestock('pig', 'sty', 'sowee')")) m.learn(merchant,(il.sell,"sell_trade('pig', 'market', 'morning')")) m.learn(merchant,(il.sell,"sell_trade('pig', 'market', 'afternoon')")) m.learn(merchant,(il.lunch,"meal('ham','midday', 'inn')")) m.learn(merchant,(il.sup,"meal('beer', 'evening', 'inn')")) m.learn(merchant,(il.welcome,"welcome('Welcome to this our settlement'," "'settler')")) m.learn(merchant,(il.help,"add_help([" "'Thankyou for joining our remote settlement.'," "'Our first task is to build some shelter, but while we are " "doing that we still need food.'," "'You can help us out by raising pigs for slaughter.'," "'If you want to buy a piglet to raise, let me know by saying " "you would like to buy one.'," "'Pigs love to eat acorns from under the oak trees that are " "abundant in this area.']," "['I would like to buy a pig', 'Pehaps I will buy one later'])")) m.own(merchant,sty) piglets=[] for i in range(0, 6): piglets.append(m.make('pig',pos=(uniform(0,4),uniform(0,4),settlement_height),parent=sty.id,orientation=directions[randint(0,7)])) m.learn(piglets,pig_goals) m.own(merchant,piglets) if m.look_for(name='Gorun Iksa') is None: marshall=m.make('marshall', name='Gorun Iksa', desc='the duke\'s marshall', pos=(14,12,settlement_height)) m.know(marshall, [('deed','price','50')]) m.know(marshall, area) m.know(marshall, about) m.learn(marshall,(il.help,"add_help([" "'On behalf of the Duke I would like to welcome you to moraf.'," "'If you are new here I suggest talking to the pig seller.'," "'He will tell you what you can do to help out.'," "'If you have decide you would like to settle here I can " "assign you some land'," "'but you will need to show that you are a useful citizen.'," "'If you can raise 50 coins herding pigs, then a plot of land is " "yours.']," "['I would like to buy a deed'," "'I will come back when I have raised some pigs'])")) plots=[] for i in range(20, 200, 20): for j in range(-100, 100, 20): plots.append(m.make('deed', pos=(0,0,0), parent=marshall.id, plot=(i,j))) m.own(marshall, plots) # Warriors - the more adventurous types warriors=[] warrior = m.look_for(name='Vonaa Barile') if warrior is None: warrior=m.make('mercenary', name='Vonaa Barile', pos=(uniform(-2,2),uniform(-2,2),settlement_height), orientation=directions[randint(0,7)]) bow=m.make('bow',pos=(0,0,0), parent=warrior.id) m.own(warrior,bow) for i in range(0, 6): arrow=m.make('arrow',pos=(0,0,0), parent=warrior.id) m.own(warrior,arrow) warriors.append(warrior) warrior = m.look_for(name='Lile Birloc') if warrior is None: warrior=m.make('mercenary', name='Lile Birloc', pos=(uniform(-2,2), uniform(-2,2), settlement_height), orientation=directions[randint(0,7)]) bow=m.make('bow',pos=(0,0,0), parent=warrior.id) m.own(warrior,bow) for i in range(0, 6): arrow=m.make('arrow',pos=(0,0,0), parent=warrior.id) m.own(warrior,arrow) warriors.append(warrior) # Warriors all know where stuff is in the village m.know(warriors,area) # Warriors enjoy their food and drink m.know(warriors, [('services','price','5')]) m.learn(warriors,(il.help,"add_help([" "'The forest is a dangerous place.'," "'If you need some help protecting your pigs,'," "'I can help you out for a day or so.'," "'I will need some gold for food and equipment.'," "'For 5 coins I can work for you until sundown.'," "'After sundown you should make sure your pigs are safe,'," "'and get indoors yourself.'," "'If you want to hire my services,'," "'let me know by saying you would like to hire me.']," "['I would like to hire your services'," "'I can take care of my pigs alone'])")) m.learn(warriors,(il.hire,"hire_trade()")) m.learn(warriors,(il.forage,"gather(['boots', 'cloak', 'shirt'," "'pants', 'hat', 'skull', 'coin'])")) m.learn(warriors,(il.lunch,"meal('ham','midday', 'inn')")) m.learn(warriors,(il.sup,"meal('beer', 'evening', 'inn')")) # Goblins if m.look_for(type='goblin') is None: goblin_guards=[] goblin=m.make('goblin', pos=(102, -33, settlement_height)) goblin_guards.append(goblin) goblin=m.make('goblin', pos=(98, -33, settlement_height)) goblin_guards.append(goblin) m.learn(goblin_guards,(il.defend,"defend('settler', 10)"))
def tick_operation(self, op): """ Op handler for regular tick op """ # print "Logging.tick" if self.target() is None: # print "Target is no more" self.irrelevant() return current_status = self.target().props.status # Measure the distance between the entity horizontal edges. Else we won't be able to reach if either entity is too thick. distance_between_entity_edges_squared = square_horizontal_edge_distance( self.character.location, self.target().location) # Assume that a standard human can reach 1.5 meters, and use this to determine if we're close enough to be able to perform the logging standard_human_reach_squared = 1.5 * 1.5 # TODO: replace this with asking the domain about the entities' reach if distance_between_entity_edges_squared > standard_human_reach_squared: self.progress = 1 - current_status self.rate = 0 return self.next_tick(1.75) res = Oplist() if current_status > 0.11: set = Operation("set", Entity(self.target().id, status=current_status - 0.1), to=self.target()) res.append(set) if current_status <= 0.5 and self.target().props.mode != 'free': print("Timber!") # Make it fall initially 15 degrees away from the logger entity. axis = distance_to(self.character.location, self.target().location).cross( Vector3D(0, 1, 0)) # the axis must be a unit vector try: axis = axis.unit_vector() except ZeroDivisionError: axis = Vector3D(1, 0, 0) # print "axis ", axis # create a rotation of 15 degrees around this axis orient = Quaternion(axis, math.pi / -12.0) # if the tree is rotated, apply this too if self.target().location.orientation.is_valid(): orient = self.target().location.orientation * orient move_location = self.target().location.copy() move_location.orientation = orient move = Operation("move", Entity(self.target().id, mode='free', location=move_location), to=self.target()) res.append(move) else: # print "become log" set = Operation("set", Entity(self.target().id, status=-1), to=self.target()) res.append(set) create_loc = self.target().location.copy() create_loc.orientation = self.target().location.orientation create = Operation( "create", Entity( parent="lumber", mass=self.target().props.mass, location=create_loc, # bbox = self.target().bbox, mode="free"), to=self.target()) res.append(create) self.progress = 1 - current_status self.rate = 0.1 / 1.75 res.append(self.next_tick(1.75)) return res