libtcod
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_PATH_H_
36#define TCOD_PATH_H_
37
38#include "fov_types.h"
39#include "list.h"
40#include "portability.h"
43#ifdef __cplusplus
44extern "C" {
45#endif
46typedef float (*TCOD_path_func_t)(int xFrom, int yFrom, int xTo, int yTo, void* user_data);
47struct TCOD_Path;
48typedef struct TCOD_Path* TCOD_path_t;
49
50TCODLIB_API TCOD_path_t TCOD_path_new_using_map(TCOD_Map* map, float diagonalCost);
51TCODLIB_API TCOD_path_t
52TCOD_path_new_using_function(int map_width, int map_height, TCOD_path_func_t func, void* user_data, float diagonalCost);
53
54TCODLIB_API bool TCOD_path_compute(TCOD_path_t path, int ox, int oy, int dx, int dy);
55TCODLIB_API bool TCOD_path_walk(TCOD_path_t path, int* x, int* y, bool recalculate_when_needed);
56TCODLIB_API bool TCOD_path_is_empty(TCOD_path_t path);
57TCODLIB_API int TCOD_path_size(TCOD_path_t path);
58TCODLIB_API void TCOD_path_reverse(TCOD_path_t path);
59TCODLIB_API void TCOD_path_get(TCOD_path_t path, int index, int* x, int* y);
60TCODLIB_API void TCOD_path_get_origin(TCOD_path_t path, int* x, int* y);
61TCODLIB_API void TCOD_path_get_destination(TCOD_path_t path, int* x, int* y);
62TCODLIB_API void TCOD_path_delete(TCOD_path_t path);
63
64/* Dijkstra stuff - by Mingos*/
70typedef struct TCOD_Dijkstra {
71 int diagonal_cost;
72 int width, height, nodes_max;
73 TCOD_Map* map; /* a TCODMap with walkability data */
74 TCOD_path_func_t func;
75 void* user_data;
76 unsigned int* distances; /* distances grid */
77 unsigned int* nodes; /* the processed nodes */
78 TCOD_list_t path;
80typedef struct TCOD_Dijkstra* TCOD_dijkstra_t;
81
82TCODLIB_API TCOD_Dijkstra* TCOD_dijkstra_new(TCOD_Map* map, float diagonalCost);
83TCODLIB_API TCOD_Dijkstra* TCOD_dijkstra_new_using_function(
84 int map_width, int map_height, TCOD_path_func_t func, void* user_data, float diagonalCost);
85TCODLIB_API void TCOD_dijkstra_compute(TCOD_Dijkstra* dijkstra, int root_x, int root_y);
86TCODLIB_API float TCOD_dijkstra_get_distance(TCOD_Dijkstra* dijkstra, int x, int y);
87TCODLIB_API bool TCOD_dijkstra_path_set(TCOD_Dijkstra* dijkstra, int x, int y);
88TCODLIB_API bool TCOD_dijkstra_is_empty(TCOD_Dijkstra* path);
89TCODLIB_API int TCOD_dijkstra_size(TCOD_Dijkstra* path);
90TCODLIB_API void TCOD_dijkstra_reverse(TCOD_Dijkstra* path);
91TCODLIB_API void TCOD_dijkstra_get(TCOD_Dijkstra* path, int index, int* x, int* y);
92TCODLIB_API bool TCOD_dijkstra_path_walk(TCOD_Dijkstra* dijkstra, int* x, int* y);
93TCODLIB_API void TCOD_dijkstra_delete(TCOD_Dijkstra* dijkstra);
94#ifdef __cplusplus
95}
96#endif
98#endif // TCOD_PATH_H_
Field-of-view types.
Deprecated libtcod list module.
Miscellaneous tools needed across platforms.
Dijkstra data structure.
Definition path.h:70
Private map struct.
Definition fov_types.h:51