예제 #1
0
    def move_dijkstra(self, target):
        self.path = libtcod.dijkstra_new(Fov.get_fov_map(), 1.41)

        libtcod.dijkstra_compute(self.path, self.x, self.y)
        libtcod.dijkstra_path_set(self.path, target.x, target.y)

        self.walk_path()
예제 #2
0
파일: effects.py 프로젝트: pom2ter/immortal
def fireball(x, y, radius):
	path = util.set_full_explore_map(game.current_map)
	libtcod.dijkstra_compute(path, x, y)
	for step in range(0, radius + 1):
		player_fov = False
		for i in range(-radius, radius + 1):
			for j in range(-radius, radius + 1):
				if libtcod.map_is_in_fov(game.fov_map, x + i, y + j) and libtcod.dijkstra_get_distance(path, x + i, y + j) <= step and libtcod.dijkstra_get_distance(path, x + i, y + j) >= 0:
					(front, back, lerp) = util.render_tiles_animations(x + i, y + j, libtcod.Color(160, 0, 0), libtcod.Color(64, 0, 0), libtcod.Color(0, 0, 0), round(libtcod.random_get_float(game.rnd, 0, 1), 1))
					libtcod.console_put_char_ex(0, game.MAP_X + x - game.curx + i, game.MAP_Y + y - game.cury + j, '*', front, back)
					player_fov = True
		if player_fov:
			libtcod.console_flush()
			time.sleep(0.05)
			player_fov = False

	for obj in game.current_map.objects:
		damage = util.roll_dice(1, 10)
		if obj.name == 'player':
			if libtcod.dijkstra_get_distance(path, game.char.x, game.char.y) <= radius:
				game.message.new('You are hit by a fireball for ' + str(damage) + ' pts of damage!', game.turns, libtcod.Color(160, 0, 0))
				game.player.take_damage(damage, 'a fireball')
		elif obj.entity:
			if libtcod.dijkstra_get_distance(path, obj.x, obj.y) <= radius:
				obj.entity.take_damage(obj.x, obj.y, damage, 'a fireball', True)
예제 #3
0
파일: effects.py 프로젝트: pom2ter/immortal
def sleeping_gas(x, y, radius, duration):
	path = util.set_full_explore_map(game.current_map)
	libtcod.dijkstra_compute(path, x, y)
	for i in range(-radius, radius + 1):
		for j in range(-radius, radius + 1):
			if libtcod.dijkstra_get_distance(path, x + i, y + j) <= radius and libtcod.dijkstra_get_distance(path, x + i, y + j) >= 0:
				game.current_map.tile[x + i][y + j].update({'icon': game.current_map.tile[x + i][y + j]['icon'], 'back_light_color': libtcod.Color(115, 220, 225), 'back_dark_color': libtcod.Color(0, 143, 189), 'lerp': round(libtcod.random_get_float(game.rnd, 0, 1), 1), 'duration': game.turns + duration, 'type': 'sleep_gas'})
				for obj in game.current_map.objects:
					if obj.item is None:
						if obj.x == x + i and obj.y == y + j:
							if obj.name == 'player':
								game.message.new('You are caught in a sleeping cloud!', game.turns)
								if 'sleep' not in game.player.flags:
									dice = util.roll_dice(1, 50)
									if dice > game.player.wisdom + (game.player.karma / 2):
										game.message.new('You fall asleep!', game.turns, libtcod.Color(0, 143, 189))
										game.player.flags.append('sleep')
							else:
								if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y):
									game.message.new(obj.entity.article.capitalize() + obj.entity.get_name() + ' is caught in a sleeping cloud!', game.turns)
								if 'sleep' not in obj.entity.flags:
									dice = util.roll_dice(1, 3)
									if dice == 3:
										if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y):
											game.message.new(obj.entity.article.capitalize() + obj.entity.get_name() + ' falls asleep!', game.turns)
										obj.entity.flags.append('sleep')
예제 #4
0
	def get_djikstra(self, x,y):
		if (x,y) not in self.djikstra_cache:
			print 'new (%s, %s)' % (x,y)
			dj = libtcod.dijkstra_new(self.fov_map)
			libtcod.dijkstra_compute(dj, x, y)
			self.dijkstra_cache[x,y] = dj
		return dj
예제 #5
0
	def set_dijkstra_map(self):
		fov_map = libtcod.map_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		for y in range(game.WORLDMAP_HEIGHT):
			for x in range(game.WORLDMAP_WIDTH):
				libtcod.map_set_properties(fov_map, x, y, True, True)
		path = libtcod.dijkstra_new(fov_map)
		libtcod.dijkstra_compute(path, self.originx, self.originy)
		return path
예제 #6
0
def test_dijkstra_callback(map_, path_callback):
    path = libtcodpy.dijkstra_new_using_function(
        libtcodpy.map_get_width(map_),
        libtcodpy.map_get_height(map_),
        path_callback,
    )
    libtcodpy.dijkstra_compute(path, *POINT_A)
    libtcodpy.dijkstra_delete(path)
예제 #7
0
    def __join_rooms(self):

        all_caves = self.__determine_areas()

        # Build a tunneling map for pathing - use the permanent state check to determine passability.
        tunnelingmap = libtcod.map_new(self.__width, self.__height)
        for x in range(1, self.__width - 1):
            for y in range(1, self.__height - 1):
                perm_wall = (self.__map[x][y].permanent
                             and self.__map[x][y].blocked)
                libtcod.map_set_properties(tunnelingmap, x, y, True,
                                           not perm_wall)

        # The tunneling path will let us move from the origin to the center.
        tunnelingpath = libtcod.dijkstra_new(tunnelingmap, 0.0)

        # The center needs to be non-permanent, otherwise we can't path to it.
        center_x, center_y = self.__find_good_center(self.center_pt)

        for cave in all_caves.keys():
            # This comment used to run the joining.  The function is still usable!
            #self.__join_points(all_caves[cave][0])
            origin_x = all_caves[cave][0][0]
            origin_y = all_caves[cave][0][1]

            libtcod.dijkstra_compute(tunnelingpath, origin_x, origin_y)
            if not libtcod.dijkstra_path_set(tunnelingpath, center_x,
                                             center_y):
                print "Could not path! Center point permanent:", self.__map[
                    center_x][center_y].permanent
            prev_pt = (origin_x, origin_y)
            while not libtcod.dijkstra_is_empty(tunnelingpath):
                x, y = libtcod.dijkstra_path_walk(tunnelingpath)
                next_pt = (x, y)
                if x is not None:

                    root1 = self.__ds.find(next_pt)
                    root2 = self.__ds.find(prev_pt)

                    if root1 != root2:
                        self.__ds.union(root1, root2)

                    self.__map[next_pt[0]][next_pt[1]].blocked = False
                    self.__map[next_pt[0]][next_pt[1]].block_sight = False
                    self.__map[next_pt[0]][next_pt[1]].debug = True  # DEBUG

                    if self.__stop_drawing(prev_pt, next_pt, self.center_pt):
                        print "Done cave", cave
                        break

                    prev_pt = next_pt

        all_caves = self.__determine_areas()
        if len(all_caves.keys()) > 1:
            self.__join_rooms()
예제 #8
0
    def __join_rooms(self):

        all_caves = self.__determine_areas()


        # Build a tunneling map for pathing - use the permanent state check to determine passability.
        tunnelingmap = libtcod.map_new(self.__width, self.__height)
        for x in range(1, self.__width-1):
            for y in range(1, self.__height-1):
                perm_wall = (self.__map[x][y].permanent and self.__map[x][y].blocked)
                libtcod.map_set_properties(tunnelingmap, x, y, True, not perm_wall)

        # The tunneling path will let us move from the origin to the center.
        tunnelingpath = libtcod.dijkstra_new(tunnelingmap, 0.0)

        # The center needs to be non-permanent, otherwise we can't path to it.
        center_x, center_y = self.__find_good_center(self.center_pt)

        for cave in all_caves.keys():
            # This comment used to run the joining.  The function is still usable!
            #self.__join_points(all_caves[cave][0])
            origin_x = all_caves[cave][0][0]
            origin_y = all_caves[cave][0][1]

            libtcod.dijkstra_compute(tunnelingpath, origin_x, origin_y)
            if not libtcod.dijkstra_path_set(tunnelingpath, center_x, center_y):
                print "Could not path! Center point permanent:", self.__map[center_x][center_y].permanent
            prev_pt = (origin_x, origin_y)
            while not libtcod.dijkstra_is_empty(tunnelingpath):
                x, y = libtcod.dijkstra_path_walk(tunnelingpath)
                next_pt = (x, y)
                if x is not None:

                    root1 = self.__ds.find(next_pt)
                    root2 = self.__ds.find(prev_pt)

                    if root1 != root2:
                        self.__ds.union(root1, root2)

                    self.__map[next_pt[0]][next_pt[1]].blocked = False
                    self.__map[next_pt[0]][next_pt[1]].block_sight = False
                    self.__map[next_pt[0]][next_pt[1]].debug = True          # DEBUG

                    if self.__stop_drawing(prev_pt, next_pt, self.center_pt):
                        print "Done cave", cave
                        break

                    prev_pt = next_pt

        all_caves = self.__determine_areas()
        if len(all_caves.keys())>1:
            self.__join_rooms()
예제 #9
0
def test_dijkstra(map_):
    path = libtcodpy.dijkstra_new(map_)

    libtcodpy.dijkstra_compute(path, *POINT_A)

    assert not libtcodpy.dijkstra_path_set(path, *POINT_C)
    assert libtcodpy.dijkstra_get_distance(path, *POINT_C) == -1

    assert libtcodpy.dijkstra_path_set(path, *POINT_B)
    assert libtcodpy.dijkstra_size(path)
    assert not libtcodpy.dijkstra_is_empty(path)

    libtcodpy.dijkstra_reverse(path)

    for i in range(libtcodpy.dijkstra_size(path)):
        x, y = libtcodpy.dijkstra_get(path, i)

    while (x, y) != (None, None):
        x, y = libtcodpy.dijkstra_path_walk(path)

    libtcodpy.dijkstra_delete(path)
예제 #10
0
    def findPath( self, start, end ):
        def point( p ):
            return ( int( math.floor( p.x ) ), int( math.floor( p.y ) ) )

        start = point( start )
        end = point( end )

        if self.pathEnd != end:
            self.pathEnd = end

            self.dijkstra = tcod.dijkstra_new( self.tcodmap, 1.41421356237 )
            tcod.dijkstra_compute( self.dijkstra, end[0], end[1] )

        if not tcod.dijkstra_path_set( self.dijkstra, start[0], start[1] ):
            return None

        ret = []
        while not tcod.dijkstra_is_empty( self.dijkstra ):
            x, y = tcod.dijkstra_path_walk( self.dijkstra )
            ret.append( ( x, y ) )

        return ret
예제 #11
0
	def UpdateNavMapLocation(self):
		libtcod.dijkstra_compute(self.currentpath, self.owner.x, self.owner.y)