def generate(self): shops = 0 hotel = 0 taverns = util.roll(1, self.rank, -1) if self.rank >= 3: if util.coinflip(): shops = util.roll(1, self.rank, -2) hotel = util.coinflip() #roll for number of houses. it'lee be 4-8 houses for small village #and 6-12 for town. and much for for large city. but that's it for now house_count = util.roll(self.rank, 3, self.rank) noble_house_count = util.roll(1, self.rank, -3) gl.logger.debug( 'Generating buildings: %d rooms, %d noble, %d tavern, %d shops, %d hotel' % (house_count, noble_house_count, taverns, shops, hotel)) gen = self.create_room_generator(house_count, noble_house_count, taverns, shops, hotel) self.generate_road() for x in (noble_house_count, taverns, shops, hotel): house_count += util.cap_lower(x, 0, 0) gl.logger.debug('Total number of houses: %d' % house_count) if self.room_placer is None: self.generate_rooms_random_place(house_count, gen) else: self.room_placer(self, house_count, gen)
def place_monsters(self): #choose random number of monsters #3d(dlvl) + 3d2 + 7 monsters total - at least 11 monsters on d1 and up-to 40 on d27 num_monsters = util.roll(1, gl.__dlvl__, util.roll(3, 2, 7)) #cap monster generation for now num_monsters = util.cap(num_monsters, 30) for i in range(num_monsters): #choose random spot for this monster x, y = self.find_random_square(self.has_critter_at) #determining critter level. it may vary from XL - 3 to XL + 3. To let is scale better multiply by 100 #cap it to be no lower than 1 crit_hd = util.cap_lower(randrange(gl.__xl__ - 3, gl.__xl__ + 3), 1, 1) self.place_critter(gl.__dlvl__, crit_hd, x, y) #check for OOD monster. let's create OOD 10% of the time for now if libtcod.random_get_int(0, 0, 100) >= 89: crit_level = libtcod.random_get_int(0, gl.__dlvl__ + 2, gl.__dlvl__ + 3) crit_hd = util.cap_lower(randrange(gl.__xl__ - 3, gl.__xl__ + 3), 1, 1) x, y = self.find_random_square(self.has_critter_at) self.place_critter(crit_level, crit_hd, x, y)
def generate_road(self): ms_start = libtcod.sys_elapsed_milli() _h = self.height / 3 road_y = randrange(_h - util.roll(1, 10), _h + util.roll(1, 10)) len_no_break = randrange(self.break_road / 2, self.break_road) old_road_y = road_y delta = 0 if self.rank > self.RANK_CITY: delta = 1 for x in xrange(0, self.width): len_no_break -= 1 if len_no_break <= 0: len_no_break = randrange(self.break_road / 2, self.break_road) y_delta = util.roll(1, 3) #nope, try another turn if y_delta == 1: len_no_break = 1 elif y_delta == 2: old_road_y, road_y = road_y, util.cap_lower( road_y - 1, 0, 0) delta = -1 else: old_road_y, road_y = road_y, util.cap( road_y + 1, self.height) delta = 1 self.roadminy = min(self.roadminy, road_y) self.roadmaxy = max(self.roadmaxy, road_y) if old_road_y != road_y: self._map[old_road_y][x] = self.road() self._map[road_y][x] = self.road() old_road_y = road_y else: self._map[road_y][x] = self.road() if self.rank >= self.RANK_CITY: self._map[road_y + delta][x] = self.road() ms_end = libtcod.sys_elapsed_milli() print 'generated in ' + str(ms_end - ms_start) + ' ms'
def generate(self): shops = 0 hotel = 0 taverns = util.roll(1, self.rank, -1) if self.rank >=3: if util.coinflip(): shops = util.roll(1, self.rank, -2) hotel = util.coinflip() #roll for number of houses. it'lee be 4-8 houses for small village #and 6-12 for town. and much for for large city. but that's it for now house_count = util.roll(self.rank,3, self.rank) noble_house_count = util.roll(1, self.rank, -3) gl.logger.debug('Generating buildings: %d rooms, %d noble, %d tavern, %d shops, %d hotel' % (house_count, noble_house_count, taverns, shops, hotel)) gen = self.create_room_generator(house_count, noble_house_count, taverns, shops, hotel) self.generate_road() for x in (noble_house_count, taverns, shops, hotel): house_count += util.cap_lower(x, 0, 0) gl.logger.debug('Total number of houses: %d' % house_count) if self.room_placer is None: self.generate_rooms_random_place(house_count, gen) else: self.room_placer(self, house_count, gen)
def generate_road(self): ms_start = libtcod.sys_elapsed_milli() _h = self.height / 3 road_y = randrange(_h - util.roll(1, 10), _h + util.roll(1, 10)) len_no_break = randrange(self.break_road / 2, self.break_road) old_road_y = road_y delta = 0 if self.rank > self.RANK_CITY: delta = 1 for x in xrange(0, self.width): len_no_break -= 1 if len_no_break <= 0: len_no_break = randrange(self.break_road / 2, self.break_road) y_delta = util.roll(1, 3) #nope, try another turn if y_delta == 1: len_no_break = 1 elif y_delta == 2: old_road_y, road_y = road_y, util.cap_lower(road_y - 1, 0, 0) delta = -1 else: old_road_y, road_y = road_y, util.cap(road_y + 1, self.height) delta = 1 self.roadminy = min(self.roadminy, road_y) self.roadmaxy = max(self.roadmaxy, road_y) if old_road_y != road_y: self._map[old_road_y][x] = self.road() self._map[road_y][x] = self.road() old_road_y = road_y else: self._map[road_y][x] = self.road() if self.rank >= self.RANK_CITY: self._map[road_y + delta][x] = self.road() ms_end = libtcod.sys_elapsed_milli() print 'generated in ' + str(ms_end - ms_start) + ' ms'
def update_coords(self, playerx, playery): self.x = util.cap_lower(playerx - self.center[0], 0, 0) self.y = util.cap_lower(playery - self.center[1], 0, 0) self.x2 = util.cap(self.x + self.w - 1, self.map.width) self.y2 = util.cap(self.y + self.h - 1, self.map.height) self.playerxy = (playerx, playery)