Fixed walk_choices's type (#3353)
Fixes #3310 Replaced some still hardcoded values with their define constants. Added a function to check if a walk will be diagonal and fixed invalid calculation for it. Thanks to @DavidPS92
This commit is contained in:
parent
4f97c749c4
commit
a05ed6e814
@ -1644,7 +1644,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
|
||||
}
|
||||
speed=status_get_speed(&md->bl);
|
||||
for(i=c=0;i<md->ud.walkpath.path_len;i++){ // The next walk start time is calculated.
|
||||
if(md->ud.walkpath.path[i]&1)
|
||||
if( direction_diagonal( md->ud.walkpath.path[i] ) )
|
||||
c+=speed*MOVE_DIAGONAL_COST/MOVE_COST;
|
||||
else
|
||||
c+=speed;
|
||||
|
@ -56,7 +56,7 @@ static BHEAP_STRUCT_VAR(node_heap, g_open_set); // use static heap for all path
|
||||
/// @}
|
||||
|
||||
// Translates dx,dy into walking direction
|
||||
static const char walk_choices [3][3] =
|
||||
static enum directions walk_choices [3][3] =
|
||||
{
|
||||
{DIR_NORTHWEST,DIR_NORTH,DIR_NORTHEAST},
|
||||
{DIR_WEST,DIR_CENTER,DIR_EAST},
|
||||
@ -510,3 +510,7 @@ int distance_client(int dx, int dy)
|
||||
|
||||
return ((int)temp_dist);
|
||||
}
|
||||
|
||||
bool direction_diagonal( enum directions direction ){
|
||||
return direction == DIR_NORTHWEST || direction == DIR_SOUTHWEST || direction == DIR_SOUTHEAST || direction == DIR_NORTHEAST;
|
||||
}
|
||||
|
@ -13,17 +13,6 @@ enum cell_chk : uint8;
|
||||
|
||||
#define MAX_WALKPATH 32
|
||||
|
||||
struct walkpath_data {
|
||||
unsigned char path_len,path_pos;
|
||||
unsigned char path[MAX_WALKPATH];
|
||||
};
|
||||
|
||||
struct shootpath_data {
|
||||
int rx,ry,len;
|
||||
int x[MAX_WALKPATH];
|
||||
int y[MAX_WALKPATH];
|
||||
};
|
||||
|
||||
enum directions : int8 {
|
||||
DIR_CENTER = -1,
|
||||
DIR_NORTH = 0,
|
||||
@ -37,6 +26,17 @@ enum directions : int8 {
|
||||
DIR_MAX
|
||||
};
|
||||
|
||||
struct walkpath_data {
|
||||
unsigned char path_len,path_pos;
|
||||
enum directions path[MAX_WALKPATH];
|
||||
};
|
||||
|
||||
struct shootpath_data {
|
||||
int rx,ry,len;
|
||||
int x[MAX_WALKPATH];
|
||||
int y[MAX_WALKPATH];
|
||||
};
|
||||
|
||||
#define check_distance_bl(bl1, bl2, distance) check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
|
||||
#define check_distance_blxy(bl, x1, y1, distance) check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
|
||||
#define check_distance_xy(x0, y0, x1, y1, distance) check_distance((x0)-(x1), (y0)-(y1), distance)
|
||||
@ -68,6 +68,8 @@ unsigned int distance(int dx, int dy);
|
||||
bool check_distance_client(int dx, int dy, int distance);
|
||||
int distance_client(int dx, int dy);
|
||||
|
||||
bool direction_diagonal( enum directions direction );
|
||||
|
||||
//
|
||||
void do_init_path();
|
||||
void do_final_path();
|
||||
|
@ -1076,7 +1076,7 @@ static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
|
||||
}
|
||||
|
||||
for(i = c = 0; i < pd->ud.walkpath.path_len; i++) {
|
||||
if(pd->ud.walkpath.path[i]&1)
|
||||
if( direction_diagonal( pd->ud.walkpath.path[i] ) )
|
||||
c += pd->status.speed*MOVE_DIAGONAL_COST/MOVE_COST;
|
||||
else
|
||||
c += pd->status.speed;
|
||||
|
@ -101,13 +101,12 @@ int unit_walktoxy_sub(struct block_list *bl)
|
||||
if (ud->target_to && ud->chaserange>1) {
|
||||
// Generally speaking, the walk path is already to an adjacent tile
|
||||
// so we only need to shorten the path if the range is greater than 1.
|
||||
uint8 dir;
|
||||
// Trim the last part of the path to account for range,
|
||||
// but always move at least one cell when requested to move.
|
||||
for (i = (ud->chaserange*10)-10; i > 0 && ud->walkpath.path_len>1;) {
|
||||
ud->walkpath.path_len--;
|
||||
dir = ud->walkpath.path[ud->walkpath.path_len];
|
||||
if(dir&1)
|
||||
enum directions dir = ud->walkpath.path[ud->walkpath.path_len];
|
||||
if( direction_diagonal( dir ) )
|
||||
i -= MOVE_COST*20; //When chasing, units will target a diamond-shaped area in range [Playtester]
|
||||
else
|
||||
i -= MOVE_COST;
|
||||
@ -126,7 +125,7 @@ int unit_walktoxy_sub(struct block_list *bl)
|
||||
|
||||
if(ud->walkpath.path_pos>=ud->walkpath.path_len)
|
||||
i = -1;
|
||||
else if(ud->walkpath.path[ud->walkpath.path_pos]&1)
|
||||
else if( direction_diagonal( ud->walkpath.path[ud->walkpath.path_pos] ) )
|
||||
i = status_get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST;
|
||||
else
|
||||
i = status_get_speed(bl);
|
||||
@ -322,7 +321,6 @@ static TIMER_FUNC(unit_walktoxy_timer){
|
||||
int i;
|
||||
int x,y,dx,dy;
|
||||
unsigned char icewall_walk_block;
|
||||
uint8 dir;
|
||||
struct block_list *bl;
|
||||
struct unit_data *ud;
|
||||
TBL_PC *sd=NULL;
|
||||
@ -356,17 +354,17 @@ static TIMER_FUNC(unit_walktoxy_timer){
|
||||
if(ud->walkpath.path_pos>=ud->walkpath.path_len)
|
||||
return 0;
|
||||
|
||||
if(ud->walkpath.path[ud->walkpath.path_pos]>=8)
|
||||
if(ud->walkpath.path[ud->walkpath.path_pos]>=DIR_MAX)
|
||||
return 1;
|
||||
|
||||
x = bl->x;
|
||||
y = bl->y;
|
||||
|
||||
dir = ud->walkpath.path[ud->walkpath.path_pos];
|
||||
enum directions dir = ud->walkpath.path[ud->walkpath.path_pos];
|
||||
ud->dir = dir;
|
||||
|
||||
dx = dirx[(int)dir];
|
||||
dy = diry[(int)dir];
|
||||
dx = dirx[dir];
|
||||
dy = diry[dir];
|
||||
|
||||
// Get icewall walk block depending on Status Immune mode (players can't be trapped)
|
||||
if(md && status_has_mode(&md->status,MD_STATUS_IMMUNE))
|
||||
@ -495,8 +493,8 @@ static TIMER_FUNC(unit_walktoxy_timer){
|
||||
ud->steptimer = INVALID_TIMER;
|
||||
}
|
||||
//Delay stepactions by half a step (so they are executed at full step)
|
||||
if(ud->walkpath.path[ud->walkpath.path_pos]&1)
|
||||
i = status_get_speed(bl)*14/20;
|
||||
if( direction_diagonal( ud->walkpath.path[ud->walkpath.path_pos] ) )
|
||||
i = status_get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST/2;
|
||||
else
|
||||
i = status_get_speed(bl)/2;
|
||||
ud->steptimer = add_timer(tick+i, unit_step_timer, bl->id, 0);
|
||||
@ -515,8 +513,8 @@ static TIMER_FUNC(unit_walktoxy_timer){
|
||||
|
||||
if(ud->walkpath.path_pos >= ud->walkpath.path_len)
|
||||
i = -1;
|
||||
else if(ud->walkpath.path[ud->walkpath.path_pos]&1)
|
||||
i = status_get_speed(bl)*14/10;
|
||||
else if( direction_diagonal( ud->walkpath.path[ud->walkpath.path_pos] ) )
|
||||
i = status_get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST;
|
||||
else
|
||||
i = status_get_speed(bl);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user