def add_splatter(self, x, y, material, amount, spread = 1): valid_tiles = [] for points in self.iter_floodfill(x, y, spread): weight = 1./len(points) valid_tiles.extend( (point, weight) for point in points ) while valid_tiles: i, j = weighted_choice(valid_tiles) if self.feature_at(i, j).splatters[material] < 1: amount = self.splat(i, j, material, amount) if amount <= 0: return else: for n, ((i2, j2), weight) in enumerate(valid_tiles): if (i2, j2) == (i, j): del valid_tiles[n] break
def init(self): self.name = 'Test Map' self.width = 80 self.height = 40 seed = [(x, y) for (x, y), value in mg.roomer(80, 40, 40).iteritems() if value == mg.EMPTY] map = mg.delve_connected(self.width, self.height, 2, 4, 0.1, False, True, limit_draw = False, draw_once = True, fraction_cleared = 0.7, seed = seed) for (x, y), value in map.iteritems(): self.place_feature(x, y, {mg.FILLED:features.StoneWall, mg.EMPTY:features.StoneFloor}[value]() ) for (x, y) in mg.get_door_locations(map): if random.random() > 0.5: self.place_feature(x, y, features.WoodenDoor()) actor_spots = self.get_free_spots_actor() item_spots = self.get_free_spots_item() for x, y in random.sample(actor_spots, 20): self.place_actor( x, y, actors.Executioner() ) map_items = [ #(items.PotionEnergy, 10), #(items.PotionHealing, 10), #(items.ScrollScrying, 5), #(items.WeaponBattleAxe, 1), #(items.WeaponLongsword, 2), #(items.WeaponSpear, 2), (items.WeaponKnife, 5), #(items.WeaponKnuckles, 2), #(items.ArmorHeavyChain, 2), (items.Shield, 5) ] for x, y in random.sample(item_spots, 100): self.place_item( x, y, weighted_choice(map_items)() )