I try to add a algorithm into the routing process for avoiding the "danger area".
If I have know what is the "danger area" (the coordinate with a radius), how do I to eliminate these area from the routing process ?
I have traced some program...
src/Task/Route.pm
src/Utils/PathFinding.pm
src/auto/XSTools/PathFinding/algorithm.cpp
Am I right ?
Then, I have two questions:
1. How to pass the parameters (the coordinate with a radius) from Perl to C++ ?
(I guess, from Route::getRoute to PathFinding...)
2. Where do I add the codes to to eliminate the "danger area" from the routing process ?
(I guess, some where in src/auto/XSTools/PathFinding/algorithm.cpp)
Could give me some help !?
Route away from the "danger area" !!
Moderator: Moderators
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: Route away from the "danger area" !!
Maybe distance map can be changed for this. It's used for avoiding walls currently.
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: Route away from the "danger area" !!
Do you mean to change the .dist file in Fields folder ?
But the "danger area" what I said is dynamics !
Actually, I want to mark the position(coordinate) where the Boss Monster appears,
and to set the (x - r, y - r) to (x + r, y + r) to be the "danger area".
Then, eliminating this "danger area" in routing process.
Changing the "danger area" when next meeting the Boss Monster !
But the "danger area" what I said is dynamics !
Actually, I want to mark the position(coordinate) where the Boss Monster appears,
and to set the (x - r, y - r) to (x + r, y + r) to be the "danger area".
Then, eliminating this "danger area" in routing process.
Changing the "danger area" when next meeting the Boss Monster !
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: Route away from the "danger area" !!
Another Question:
The CalcPath_pathStep function in src/auto/XSTools/PathFinding/algorithm.cpp, is it only calculating the path steps in the same field ?
The CalcPath_pathStep function in src/auto/XSTools/PathFinding/algorithm.cpp, is it only calculating the path steps in the same field ?
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: Route away from the "danger area" !!
For basic setup, you can change $field->{dstMap}.
You can do this by changing loading/generation functions in Field module, then use something like
to refresh already loaded $field when your data changes, and you'll need to somehow tell existing routing tasks to refresh or clear AI.
However, this way is not very flexible afaik (many things you may want to change are still inside cpp functions) and the whole "temporarily avoid parts of maps in all possible routing" idea has many potential problems which would arise if implemented poorly.
If you just want to avoid danger while you're randomwalking on the map as usual, maybe it's easier to tweak random walking? Like, check whether any of route points are close to danger areas when a new route is generated. If so, generate another route immediately.
You can do this by changing loading/generation functions in Field module, then use something like
Code: Select all
$field->loadByName($args{field}->name, 1);
However, this way is not very flexible afaik (many things you may want to change are still inside cpp functions) and the whole "temporarily avoid parts of maps in all possible routing" idea has many potential problems which would arise if implemented poorly.
If you just want to avoid danger while you're randomwalking on the map as usual, maybe it's easier to tweak random walking? Like, check whether any of route points are close to danger areas when a new route is generated. If so, generate another route immediately.
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: Route away from the "danger area" !!
Thank you very much !
Actually, I have completed this job !!
I descript simply as following:
1. I pass a coordnate and a radus (danger area) parametr into $class->_reset(..)
from reset of src/Utils/PathFinding.pm.
Such as:
The $dgrx and $dgry are the coordnate and the $dgrr is the radus.
2. In src/auto/XSTools/PathFinding, get the coordnate and the radus with PathFinding__reset(...) of PathFinding.xs.
Then new a pos *dgrpos and unsigned short dgrr, and pass them into CalcPath_init (...)
Such as:
3. In src/auto/XSTools/PathFinding, get the pos and the radus with CalcPath_init (...) of algorithm.cpp
Such as:
And now, the pos * dgrpos unsigned short dgrrds is the danger area !!
4. In src/auto/XSTools/PathFinding/algorithm.cpp, convert the pos and the radus into a rectangle area.
Such as:
5. In src/auto/XSTools/PathFinding/algorithm.cpp, add a new function, IsSafe().
Such as:
6. In src/auto/XSTools/PathFinding/algorithm.cpp, add a condition into the judgement statement.
Such as:
I am testing this now.
I think I will not commit these codes !
Actually, I have completed this job !!
I descript simply as following:
1. I pass a coordnate and a radus (danger area) parametr into $class->_reset(..)
from reset of src/Utils/PathFinding.pm.
Such as:
Code: Select all
return $class->_reset($args{distance_map}, $args{weights}, $args{width}, $args{height},
$args{start}{x}, $args{start}{y},
$args{dest}{x}, $args{dest}{y},
$args{timeout}, $dgrx, $dgry, $dgrr);
2. In src/auto/XSTools/PathFinding, get the coordnate and the radus with PathFinding__reset(...) of PathFinding.xs.
Then new a pos *dgrpos and unsigned short dgrr, and pass them into CalcPath_init (...)
Such as:
Code: Select all
PathFinding__reset(session, map, weights, width, height, startx, starty, destx, desty, time_max, dgrx, dgry, dgrr)
.....
CalcPath_init (session, real_map, real_weights, width, height, start, dest, time_max, dgrpos, dgrr);
Such as:
Code: Select all
CalcPath_init (CalcPath_session *session, const char* map, const unsigned char* weight,
unsigned long width, unsigned long height,
pos * start, pos * dest, unsigned long time_max, pos * dgrpos, unsigned short dgrrds)
4. In src/auto/XSTools/PathFinding/algorithm.cpp, convert the pos and the radus into a rectangle area.
Such as:
Code: Select all
unsigned short dgrL = (dgrpos->x > dgrrds) ? dgrpos->x - dgrrds : 0 ;
unsigned short dgrR = dgrpos->x + dgrrds;
unsigned short dgrT = dgrpos->y + dgrrds;
unsigned short dgrB = (dgrpos->y > dgrrds) ? dgrpos->y - dgrrds : 0;
Such as:
Code: Select all
static inline char
IsSafe(pos *p, unsigned short l, unsigned short r, unsigned short t, unsigned short b) {
if (p->x >= l && p->x <= r && p->y >= b && p->y <= t) {
return 0;
} else {
return 1;
}
}
Such as:
Code: Select all
if (IsSafe(&mappos, dgrL, dgrR, dgrT, dgrB) != 0
&& CalcPath_getMap(map, width, height, &mappos) != 0
.....
I think I will not commit these codes !
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: Route away from the "danger area" !!
After some testing...
It seems to works well !
When I set some one coordinate with a radius...
It could route away from this "danger area" !!
It seems to works well !
When I set some one coordinate with a radius...
It could route away from this "danger area" !!