|
|
Format_C Pathfinding [Reupload]
#412819
12/03/12 18:07
12/03/12 18:07
|
Joined: May 2009
Posts: 5,367 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,367
Caucasus
|
As I've seen some of the guys asking for this lately, I've decided to reupload it! I've got C-Script version from the Russian Community, where one of the members, searched and finally found it on his old HDD archive. Then I've converted it into LITE-C myself! I couldn't find an old thread (was too lazy probably), so I've made new one, and I've uploaded both "C-Script" and "Lite-C" version of my WEBSITE (yeah, good old "badcom (dot) at (dot) ua")!! Here are the link: Astar Pathfinding (Lite-C) Astar Pathfinding (C-Script) As all comments were in Russian, I've decided to translate them: MAIN.C
#include <acknex.h>
#include <default.c>
#include "astar.c" // here we have pathfinding functions
#define PRAGMA_PLUGIN "plugin\\format_c.dll";
STRING* level_str = "sample.WMB";
STRING* cbabe_mdl = "cbabe.mdl";
var map1; // the map of obstacles
function main(){
// we create the map of obstacles
create_grid_params(0, 0); // coordinates of the lower left corner of the map (x,y)
map1 = create_grid(15, 12, 64, 64); // we create map 15x12 cells, 64,64 - width, height 1 cell
level_load(level_str);
}
action my_target() // objects which we'll follow
{
while(1){
if (key_cur){ my.x += 20 * time_step; }
if (key_cul){ my.x -= 20 * time_step; }
if (key_cuu){ my.y += 20 * time_step; }
if (key_cud){ my.y -= 20 * time_step; }
wait(1);
}
}
action finder() // object which will find path
{
var temp;
var dots_to_goal = 0; // ammount of cells which we'll need to go throw in order to get to the target cell
my.skill1 = add_path(); // let's create a path and store it in skill1
you = ent_create(cbabe_mdl, my.x, my_target); // object which we'll follow
while(1){
if(key_space){
// if we've pressed space key, then we need to compute path to the target
calc_path_params(my.x, my.y, you.x, you.y); //my.x,my.y - start positions, you.x,you.y - end positions
dots_to_goal = calc_path(map1, my.skill1, 1); //computing the path
//map1-the map of obstacles,skill1-path,1-"allow diagonal movement"
temp = 0;
}
if(temp < dots_to_goal){ // we move throw path till we get to the target
my.x += (path_point_x(my.skill1, temp) - my.x) * time_step;
my.y += (path_point_y(my.skill1, temp) - my.y) * time_step;
if (vec_dist(vector(my.x, my.y, my.z), vector(path_point_x(my.skill1, temp), path_point_y(my.skill1, temp), my.z)) <= 10){
temp += 1;
}
}
wait(1);
}
}
action obstacle()
{
add_cell(map1, my.x, my.y, -333);
}
ASTAR.C
// defines coordinates of the lower left corner of the grid (if we look from the top view)
function create_grid_params(corner_x,corner_y);
// creates a grid, defines ammount of cells horizontally, vertically, width, height of the cell
function create_grid(grid_w,grid_h,cell_w,cell_h);
// deletes the map of obstacles
function map_destroy(map_id);
// deletes all obstacle maps
function map_destroy_all();
// adds rate of the cell in the map of obstacles(-333 - "required cell")
function add_cell(map_id,x,y,price);
// gets the rate of the cell from the obstacles map (for debugging)
function get_cell(map_id,x,y);
// adds path (just a simple massive, where we store coordinates of each node, which leads to the target)
function add_path(); // adds path
function del_path(path_id); // delets path
function path_destroy_all(); // delets all paths
function path_length(path_id); // returns the length of the path (if path was computed)
//defines parameters for pathfinding (start position, end position)
function calc_path_params(start_x,start_y,goal_x,goal_y);
//computes path. map_id,path_id - IDs of the map and path, allowdiag-admission "of walking diagonally"
//returns ammount of nodes (if path was computed) and -1 (if path wasn't computed)
function calc_path(map_id,path_id,allowdiag);
// returns coordinates of each node of the path, if it was computed. point_num - number of node (starting node - 0)
function path_point_x(path_id,point_num);
function path_point_y(path_id,point_num);
// returns number of node in the map of obstacles (for debugging)
// for example, we can check, was node included in the actual path
// if it wasn't we get -1
function point_encode(map_id,x,y);
Sorry for my English guys  If you can't understand anything, just ask me. Edit: I would be really grateful if someone could fix links in the Wiki, cause I've tried to login with my forum nick and password, that didn't work.
|
|
|
Re: Format_C Pathfinding [Reupload]
[Re: sivan]
#412848
12/04/12 07:49
12/04/12 07:49
|
Joined: Mar 2006
Posts: 1,993 Karlsruhe
PadMalcom
Serious User
|
Serious User
Joined: Mar 2006
Posts: 1,993
Karlsruhe
|
Nice thanks  For all those who want to read it in english: http://translate.google.de/translate?hl=en&sl=auto&tl=en&u=http%3A%2F%2Fwww.3dgs.ru%2F
|
|
|
Re: Format_C Pathfinding [Reupload]
[Re: 3run]
#413041
12/06/12 20:24
12/06/12 20:24
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
thanks 3run this is also handy
Compulsive compiler
|
|
|
|