def test_hide_actors(self): import direction from sites import Cave import wide from schedule import Schedule world = wide.Overworld(sched=Schedule(), name="world") cave = Cave.at_point(world, coordinates=(15, 15), direction=direction.random(), landmark_name="cave") assert (world.schedule.current_time == 0) p = Kobold() cave.add_population(p) world.schedule.run_game(3000) assert (world.schedule.current_time == 0) cave.update_region() world.schedule.run_game(3000) assert (world.schedule.current_time == 3000) p.hide_actors() world.schedule.run_game(3000) assert (world.schedule.current_time == 3000) cave.update_region() world.schedule.run_game(3000) assert (world.schedule.current_time == 6000) p.hide_actors() cave.update_region() world.schedule.run_game(3000) assert (world.schedule.current_time == 9000)
def update(self): if functions.distance_between(self.rect,data.player.rect)> self.SENSES: if self.timetochangedirection <= 0: self.direction = direction.random() self.timeleft -= 1 else: self.move(direction.to_vector(ai.pathfinding(self.rect, data.player.rect),self.SPEED))
def __init__(self, start, end, direct="random"): self.start = start self.end = end locations = (start, end) if direct == "random": direct = direction.random() directions = (direct.opposite, direct) name_pair = [Name("door to") + place.name for place in (end, start)] super().__init__(locations=locations, directions=directions, name_pair=name_pair)
def take_turn(self): for agent in self.enemy_priority: new_priority = int(self.enemy_priority[agent] * 0.9**(self.update_period / day)) if self.destroyed: return if random() < 1 / 200: self.tomb_count += 1 tomb_name = namemaker.make_name() agent_print( f"{self.name} built a tomb named {tomb_name.get_text()}") sites.Tomb.at_point( self.location, direction.random(), self.location.random_in_circle(self.coordinates, 5), landmark_name=tomb_name + "tomb", ) if random() < 1 / 1000: self.unrest += 20 agent_print(f"{self.name} suffered a plague") roll = random() if roll < 1 / 10: # print_(f"{self.name} had a good harvest") if self.unrest > 10: self.unrest -= 10 else: self.unrest = 0 elif roll > 9 / 10: self.unrest += 3 # print_(f"{self.name} had a bad harvest") if random() < (self.unrest / 100)**2: group = BanditGroup( name=namemaker.make_name() + "gang", target=self, location=self.location, coordinates=self.location.random_in_circle( self.coordinates, 5), ) agent_print( f"{self.name} spawned {group.name} at unrest {self.unrest:.2f}" ) if self.unrest > 60 + random() * 40: agent_print( f"{self.name} crumbled to ruin amid starvation and rioting.") self.destroyed = True return
def update(self): if functions.distance_between(self.rect,config.player.rect)> self.SENSES: if self.timetochangedirection <= 0: self.direction = direction.random() self.timeleft -= 1 else: #ai.pathfind(self.rect, player.rect) #not implemented yet vector = [random.randint(0,self.SPEED*2)-self.SPEED, random.randint(0,self.SPEED*2)-self.SPEED] self.move(vector)
def update(self): if functions.distance_between(self.rect, data.player.rect) > self.SENSES: if self.timetochangedirection <= 0: self.direction = direction.random() self.timeleft -= 1 else: self.move( direction.to_vector( ai.pathfinding(self.rect, data.player.rect), self.SPEED))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ai = WaitingAI(self) self.site = sites.TownSite.at_point( location=self.location, direction=direction.random(), coordinates=self.coordinates, landmark_name=self.name_object + "village", agent=self, ) # # Removing the hardcoded towns for now # self.site.add_morph(sites.TownBuildingMorph(building.WeaponShop)) # self.site.add_morph(sites.TownBuildingMorph(building.Inn)) self.traits.add(trait.town()) self.enemy_priority: Dict[WorldAgent, int] = {} self.last_attacks = {}
def pathfinding(origin, destination): return direction.random()