summaryrefslogtreecommitdiff
path: root/src/map/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/path.c')
-rw-r--r--src/map/path.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/map/path.c b/src/map/path.c
index 543497c33..f271e8219 100644
--- a/src/map/path.c
+++ b/src/map/path.c
@@ -2,8 +2,8 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
+ * Copyright (C) 2012-2020 Hercules Dev Team
+ * Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
#define DIR_SOUTH 4
#define DIR_EAST 8
-struct path_interface path_s;
+static struct path_interface path_s;
struct path_interface *path;
/// @name Structures and defines for A* pathfinding
@@ -85,10 +85,11 @@ static const unsigned char walk_choices [3][3] =
* Find the closest reachable cell, 'count' cells away from (x0,y0) in direction (dx,dy).
* Income after the coordinates of the blow
*------------------------------------------*/
-int path_blownpos(struct block_list *bl, int16 m,int16 x0,int16 y0,int16 dx,int16 dy,int count)
+static int path_blownpos(struct block_list *bl, int16 m, int16 x0, int16 y0, int16 dx, int16 dy, int count)
{
struct map_data *md;
+ Assert_retr(-1, m >= 0 && m < map->count);
if( !map->list[m].cell )
return -1;
md = &map->list[m];
@@ -118,7 +119,7 @@ int path_blownpos(struct block_list *bl, int16 m,int16 x0,int16 y0,int16 dx,int1
/*==========================================
* is ranged attack from (x0,y0) to (x1,y1) possible?
*------------------------------------------*/
-bool path_search_long(struct shootpath_data *spd,struct block_list *bl,int16 m,int16 x0,int16 y0,int16 x1,int16 y1,cell_chk cell)
+static bool path_search_long(struct shootpath_data *spd, struct block_list *bl, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, cell_chk cell)
{
int dx, dy;
int wx = 0, wy = 0;
@@ -126,6 +127,8 @@ bool path_search_long(struct shootpath_data *spd,struct block_list *bl,int16 m,i
struct map_data *md;
struct shootpath_data s_spd;
+ Assert_retr(false, m >= 0 && m < map->count);
+
if( spd == NULL )
spd = &s_spd; // use dummy output variable
@@ -189,10 +192,8 @@ bool path_search_long(struct shootpath_data *spd,struct block_list *bl,int16 m,i
/// Ensures there is enough space in array to store new element.
static void heap_push_node(struct node_heap *heap, struct path_node *node)
{
-#ifndef __clang_analyzer__ // TODO: Figure out why clang's static analyzer doesn't like this
BHEAP_ENSURE(*heap, 1, 256);
BHEAP_PUSH2(*heap, node, NODE_MINTOPCMP, swap_ptr);
-#endif // __clang_analyzer__
}
/// Updates path_node in the binary node_heap.
@@ -252,12 +253,14 @@ static int add_path(struct node_heap *heap, struct path_node *tp, int16 x, int16
* flag: &1 = easy path search only
* cell: type of obstruction to check for
*------------------------------------------*/
-bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell)
+static bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell)
{
- register int i, j, x, y, dx, dy;
+ register int i, x, y, dx, dy;
struct map_data *md;
struct walkpath_data s_wpd;
+ Assert_retr(false, m >= 0 && m < map->count);
+
if (wpd == NULL)
wpd = &s_wpd; // use dummy output variable
@@ -315,8 +318,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
}
return false; // easy path unsuccessful
- }
- else { // !(flag&1)
+ } else { // !(flag&1)
// A* (A-star) pathfinding
// We always use A* for finding walkpaths because it is what game client uses.
// Easy pathfinding cuts corners of non-walkable cells, but client always walks around it.
@@ -331,6 +333,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
int xs = md->xs - 1;
int ys = md->ys - 1;
int len = 0;
+ int j;
memset(tp, 0, sizeof(tp));
// Start node
@@ -407,7 +410,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
}
for (it = current; it->parent != NULL; it = it->parent, len++);
- if (len > sizeof(wpd->path)) {
+ if (len > (int)sizeof(wpd->path)) {
return false;
}
@@ -426,7 +429,7 @@ bool path_search(struct walkpath_data *wpd, struct block_list *bl, int16 m, int1
}
//Distance functions, taken from http://www.flipcode.com/articles/article_fastdistance.shtml
-bool check_distance(int dx, int dy, int distance)
+static bool check_distance(int dx, int dy, int distance)
{
#ifdef CIRCULAR_AREA
//In this case, we just do a square comparison. Add 1 tile grace for diagonal range checks.
@@ -438,7 +441,7 @@ bool check_distance(int dx, int dy, int distance)
#endif
}
-unsigned int distance(int dx, int dy)
+static unsigned int distance(int dx, int dy)
{
#ifdef CIRCULAR_AREA
unsigned int min, max;
@@ -475,7 +478,7 @@ unsigned int distance(int dx, int dy)
* @param distance: Distance to check against
* @return Within distance(1); Not within distance(0);
*/
-bool check_distance_client(int dx, int dy, int distance)
+static bool check_distance_client(int dx, int dy, int distance)
{
if(distance < 0) distance = 0;
@@ -489,7 +492,7 @@ bool check_distance_client(int dx, int dy, int distance)
* @param dy: Vertical distance
* @return Circular distance
*/
-int distance_client(int dx, int dy)
+static int distance_client(int dx, int dy)
{
double temp_dist = sqrt((double)(dx*dx + dy*dy));
@@ -502,7 +505,8 @@ int distance_client(int dx, int dy)
return ((int)temp_dist);
}
-void path_defaults(void) {
+void path_defaults(void)
+{
path = &path_s;
path->blownpos = path_blownpos;