path: New DIR_BACK()
Actually pathfind.c's rev_dir() turned into a macro, to make it available elsewhere. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
21b8add73e
commit
296f3272e2
2 changed files with 7 additions and 11 deletions
|
@ -27,7 +27,7 @@
|
||||||
* path.h: Definitions for directions, paths, etc.
|
* path.h: Definitions for directions, paths, etc.
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2005-2011
|
* Markus Armbruster, 2005-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PATH_H
|
#ifndef PATH_H
|
||||||
|
@ -49,6 +49,8 @@
|
||||||
#define DIR_FIRST 1
|
#define DIR_FIRST 1
|
||||||
#define DIR_LAST 6
|
#define DIR_LAST 6
|
||||||
|
|
||||||
|
#define DIR_BACK(dir) ((dir) >= DIR_FIRST + 3 ? (dir) - 3 : (dir) + 3)
|
||||||
|
|
||||||
#define MOB_MOVE 0
|
#define MOB_MOVE 0
|
||||||
#define MOB_MARCH 1
|
#define MOB_MARCH 1
|
||||||
#define MOB_RAIL 2
|
#define MOB_RAIL 2
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* pathfind.c: Find cheapest paths
|
* pathfind.c: Find cheapest paths
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2011
|
* Markus Armbruster, 2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -325,13 +325,6 @@ y_in_dir(coord y, int dir)
|
||||||
return yy;
|
return yy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
rev_dir(int dir)
|
|
||||||
{
|
|
||||||
assert(DIR_FIRST <= dir && dir <= DIR_LAST);
|
|
||||||
return dir >= DIR_FIRST + 3 ? dir - 3 : dir + 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the current source and cost function.
|
* Set the current source and cost function.
|
||||||
* SX,SY is the source.
|
* SX,SY is the source.
|
||||||
|
@ -456,8 +449,9 @@ path_find_route(char *buf, size_t bufsz,
|
||||||
i = bufsz;
|
i = bufsz;
|
||||||
buf[--i] = dirch[d];
|
buf[--i] = dirch[d];
|
||||||
len++;
|
len++;
|
||||||
x = x_in_dir(x, rev_dir(d));
|
assert(DIR_FIRST <= d && d <= DIR_LAST);
|
||||||
y = y_in_dir(y, rev_dir(d));
|
x = x_in_dir(x, DIR_BACK(d));
|
||||||
|
y = y_in_dir(y, DIR_BACK(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(x == sx && y == sy);
|
assert(x == sx && y == sy);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue