stock A_star_pathfinder(ent, Float:ent_origin[3], Float:End_Origin[3], Float:End_Way[][3])
{
static i, checked = 0, Float:extra = 0.1, cost[8], diff[8], bool:finished = false, best_diff = 669999,
best_way = 0, Float:Created_Way[max_way_points][3], Float:Explore_Origin[8][3],
Float:Got_Origin[8][3], Float:Start_Search_From_Here[3]
Start_Search_From_Here = ent_origin
if(vector_distance(ent_origin, End_Origin) <= 150.0)
{
g_way_counter[ent] = 1
End_Way[0] = End_Origin
return
}
static bool:Broken_Point[8]
while(!finished || checked >= (max_way_points - 1))
{
best_diff = 669999
Explore_Origin[0][0] = 300.0 * extra
Explore_Origin[0][1] = 0.0
Explore_Origin[0][2] = 0.0
Explore_Origin[1][0] = 150.0 * extra
Explore_Origin[1][1] = 150.0 * extra
Explore_Origin[1][2] = 0.0
Explore_Origin[2][0] = 0.0
Explore_Origin[2][1] = 300.0 * extra
Explore_Origin[2][2] = 0.0
Explore_Origin[3][0] = -150.0 * extra
Explore_Origin[3][1] = -300.0 * extra
Explore_Origin[3][2] = 0.0
Explore_Origin[4][0] = -300.0 * extra
Explore_Origin[4][1] = 0.0
Explore_Origin[4][2] = 0.0
Explore_Origin[5][0] = -150.0 * extra
Explore_Origin[5][1] = -150.0 * extra
Explore_Origin[5][2] = 0.0
Explore_Origin[6][0] = 0.0
Explore_Origin[6][1] = -150.0 * extra
Explore_Origin[6][2] = 0.0
Explore_Origin[7][0] = 150.0 * extra
Explore_Origin[7][1] = -150.0 * extra
Explore_Origin[7][2] = 0.0
for(i = 0; i < sizeof(Explore_Origin); i++)
{
checked++
Got_Origin[i] = Start_Search_From_Here
Got_Origin[i][0] += Explore_Origin[i][0]
Got_Origin[i][1] += Explore_Origin[i][1]
Got_Origin[i][2] += Explore_Origin[i][2]
Broken_Point[i] = false
if (is_outside_map(Got_Origin[i]))
{
cost[i] = 10500;
Broken_Point[i] = true
}
if (i == 0 || i == 2 || i == 4 || i == 6)
{
cost[i] += 10
} else {
cost[i] += 14
}
diff[i] = floatround(vector_distance(Got_Origin[i], End_Origin)) + (cost[i] + i)
if(vector_distance(Got_Origin[i], End_Origin) <= 150.0 * extra)
{
finished = true
}
}
for(i = 0; i < sizeof(Explore_Origin); i++)
{
if ( best_diff >= diff[i] )
{
if ( !Broken_Point[i] )
{
best_diff = diff[i]
best_way = i;
}
}
}
Start_Search_From_Here = Got_Origin[best_way]
new Float:got_dist = vector_distance(Start_Search_From_Here, End_Origin)
if ( g_way_counter[ent] >= (max_way_points - 1) || got_dist <= 150.0 * extra)
{
for(i = 0; i < g_way_counter[ent]; i++)
{
End_Way[i] = Created_Way[g_way_counter[ent] - i]
bomb_led(End_Way[i])
}
finished = true
return;
}
else
{
g_way_counter[ent] += 1
Created_Way[g_way_counter[ent]] = Got_Origin[best_way]
}
}
for(i = 0; i < g_way_counter[ent]; i++)
{
End_Way[i] = Created_Way[g_way_counter[ent]-i]
bomb_led(End_Way[i])
}
}
stock bomb_led(const Float:point[3])
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_GLOWSPRITE)
engfunc(EngFunc_WriteCoord, point[0])
engfunc(EngFunc_WriteCoord, point[1])
engfunc(EngFunc_WriteCoord, point[2])
write_short(spr_bomb)
write_byte(10)
write_byte(3)
write_byte(255)
message_end()
}
stock Search_Way(ent, Float:target[3])
{
static Float:npc_origin[3]
g_way_counter[ent] = 0
pev(ent, pev_origin, npc_origin)
A_star_pathfinder(ent, npc_origin, target, point)
if ( g_way_counter[ent] < 1 )
return
g_way_point[ent] = point[0]
g_way_point_index[ent] = 1
}
stock is_outside_map(Float:Origin[3]) return (engfunc(EngFunc_PointContents, Origin) == CONTENTS_SOLID)