32 #define RT_AREA_POS(path, p, state) ((path)->area[(state)][(p)[2]][(p)[1]][(p)[0]]) 33 #define RT_AREA_FROM_POS(path, p, state) ((path)->areaFrom[(state)][(p)[2]][(p)[1]][(p)[0]]) 34 #define RT_SAREA(path, x, y, z, state) ((path)->areaStored[(state)][(z)][(y)][(x)]) 35 #define RT_AREA_TEST_POS(path, p, state) assert((p)[2] < PATHFINDING_HEIGHT);\ 36 assert((state) == 0 || (state) == 1); 110 const int fx = (*p)[0];
111 const int fy = (*p)[1];
112 const int fz = (*p)[2];
114 if (fx + entSize <= chkPos[0] || chkPos[0] + actorSize <= fx)
116 if (fy + entSize <= chkPos[1] || chkPos[1] + actorSize <= fy)
178 flier(false), hasLadderToClimb(false), hasLadderSupport(false), actorHeight(0), actorCrouchedHeight(0), routing(
179 r), dir(_dir), actorSize(_actorSize), crouchingState(_crouchingState), TUsAfter(0)
312 if (actorStepupHeight < stepupHeight) {
316 const int nx =
toPos[0];
317 const int ny =
toPos[1];
318 const int nz =
toPos[2];
398 if (passageHeight < neededHeight) {
510 pos3_t excludeFromForbiddenList;
523 Vector4Set(epos, from[0], from[1], from[2], amst);
533 if (usedTUs >= maxTUs)
538 if (dir == 12 || dir == 14 || dir == 15)
544 Step step(routing, pos, actorSize, amst, dir);
594 assert(crouchingState == 0 || crouchingState == 1);
604 pos3_t excludeFromForbiddenList;
616 Vector4Set(epos, from[0], from[1], from[2], crouchingState);
626 if (usedTUs >= maxTUs)
631 if (dir == 12 || dir == 14 || dir == 15)
637 Step step(routing, pos, actorSize, crouchingState, dir);
702 assert(crouchingState == 0 || crouchingState == 1);
707 return RT_SAREA(path, to[0], to[1], to[2], crouchingState);
801 const int base = routing.
getFloor(actorSize, pos[0], pos[1], z);
820 const int tusCrouched =
RT_AREA_POS(path, toPos, 1);
821 const int tusUpright =
RT_AREA_POS(path, toPos, 0);
822 return tusUpright + 2 *
TU_CROUCH < tusCrouched;
837 Com_Printf(
"Grid_PosToVec: Warning - z level bigger than 7 (%i - source: %.02f)\n", pos[2], vec[2]);
840 const int gridFloor =
Grid_Floor(routing, actorSize, pos);
841 vec[2] += std::max(0, std::min(
UNIT_HEIGHT, gridFloor));
857 for (
int actorSize = 1; actorSize <=
ACTOR_MAX_SIZE; ++actorSize) {
866 for (
int z = rBox.
getMaxZ(); z >= 0; --z) {
876 for (
int actorSize = 1; actorSize <=
ACTOR_MAX_SIZE; actorSize++) {
884 if (x > box.
getMaxX() && dir != 1 && dir != 5 && dir != 6)
886 if (y > box.
getMaxY() && dir != 3 && dir != 5 && dir != 7)
889 if (x < box.
getMinX() && dir != 0 && dir != 4 && dir != 7)
891 if (y < box.
getMinY() && dir != 2 && dir != 4 && dir != 6)
895 if (x < box.
getMinX() - 1 && dir != 0 && dir != 4 && dir != 7)
897 if (y < box.
getMinY() - 1 && dir != 2 && dir != 4 && dir != 6)
927 Com_Printf(
"Called Grid_RecalcRouting with no inline model\n");
932 Com_Printf(
"Called Grid_RecalcRouting with invalid inline model name '%s'\n",
name);
946 vec3_t centerVec, halfVec, newCenterVec;
961 VectorAdd(newCenterVec, halfVec, maxVec);
964 absbox.
set(minVec, maxVec);
973 rerouteBox.
set(absbox);
bool init()
Initialize the other Step data.
void CalculateMinsMaxs(const vec3_t angles, const AABB &relBox, const vec3_t origin, AABB &absBox)
Calculates the bounding box in absolute coordinates, also for rotating objects. WARNING: do not use t...
bool Grid_ShouldUseAutostand(const pathing_t *path, const pos3_t toPos)
Checks if a crouched actor could save TUs by standing up, walking and crouching again.
CASSERT(lengthof(TUsUsed)==PATHFINDING_DIRECTIONS)
#define SizedPosToVec(p, actorSize, v)
SizedPosToVect locates the center of an actor based on size and position.
#define VectorCopy(src, dest)
int Grid_GetTUsForDirection(const int dir, bool crouched)
Returns the amounts of TUs that are needed to perform one step into the given direction.
byte isStepDownLevel(const actorSizeEnum_t actorSize, const pos3_t pos, const int dir) const
#define TU_FLYING_MOVING_FACTOR
#define ModelCeilingToQuant(x)
int Grid_MoveNext(const pathing_t *path, const pos3_t toPos, byte crouchingState)
Get the direction to use to move to a position (used to reconstruct the path)
#define DIRECTION_CLIMB_UP
void PQueuePush(priorityQueue_t *pq, const pos4_t item, priorityQueueRating_t r)
pos_t Grid_Fall(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Calculated the new height level when something falls down from a certain position.
#define DIRECTION_STAND_UP
bool checkWalkingDirections(const pathing_t *path)
Checks if we can walk in the given direction First test for opening height availability. Then test for stepup compatibility. Last test for fall.
#define DV_FLAG_AUTOCROUCHED
void Grid_CalcPathing(const Routing &routing, const actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, int maxTUs, forbiddenList_t *fb_list)
Recalculate the pathing table for the given actor(-position)
#define DIRECTION_CLIMB_DOWN
void calcNewTUs(const pathing_t *path)
Calculate the TUs after we in the given dir.
const vec4_t dvecs[PATHFINDING_DIRECTIONS]
byte isStepUpLevel(const actorSizeEnum_t actorSize, const pos3_t pos, const int dir) const
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
void PQueueFree(priorityQueue_t *pq)
free up memory for pqueue
void VectorCreateRotationMatrix(const vec3_t angles, vec3_t matrix[3])
void Grid_RecalcRouting(mapTiles_t *mapTiles, Routing &routing, const char *name, const GridBox &box, const char **list)
This function recalculates the routing surrounding the entity name.
static void Grid_SetMoveData(pathing_t *path, const pos3_t toPos, const int crouch, const byte length, const int dir, const int oldZ)
const byte crouchingState
unsigned int Grid_Ceiling(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Returns the height of the floor in a cell.
dvec_t areaFrom[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
void Grid_RecalcBoxRouting(mapTiles_t *mapTiles, Routing &routing, const GridBox &box, const char **list)
This function recalculates the routing in and around the box bounded by min and max.
#define CELL_HEIGHT
A cell's height in QUANT sized units.
#define PATHFINDING_MAX_FALL
Step(const Routing &r, const pos3_t fromPos, const actorSizeEnum_t actorSize, const byte crouchingState, const int dir)
Constructor.
pos_t Grid_MoveLength(const pathing_t *path, const pos3_t to, byte crouchingState, bool stored)
Return the needed TUs to walk to a given position.
#define PQueueIsEmpty(pq)
#define RT_AREA_TEST_POS(path, p, state)
#define FLYING_DIRECTIONS
bool checkFlyingDirections() const
Checks if we can move in the given flying direction.
#define PATHFINDING_DIRECTIONS
#define RT_AREA_FROM_POS(path, p, state)
#define Vector4Set(v, r, g, b, a)
#define PATHFINDING_MAX_STEPUP
QGL_EXTERN GLuint GLsizei GLsizei * length
void set(const AABB &other)
Copies the values from the given aabb.
the priority queue struct the actual data is stored in priorityQueueElement_t
byte getCeiling(const int actorSize, const pos3_t pos) const
Header file for the priority queue implementation.
actorSizeEnum_t getEntSize(pos_t **current)
static forbiddenList_t forbiddenList
A list of locations that cannot be moved to.
pos_t ** getNext(pos_t **prev)
#define VectorNotEmpty(a)
#define RT_SAREA(path, x, y, z, state)
bool Grid_FindPath(const Routing &routing, const actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t *forbiddenList)
Tries to find a path from the given actor(-position) to a given target position.
void shift(const vec3_t shiftVec)
shove the whole box by the given vector
grid pathfinding and routing
void getCenter(vec3_t center) const
Calculates the center of the bounding box.
bool checkVerticalDirections() const
Checks if we can move in the given vertical direction.
static const int TUsUsed[]
#define RT_AREA_POS(path, p, state)
cBspModel_t * CM_InlineModel(const mapTiles_t *mapTiles, const char *name)
Searches all inline models and return the cBspModel_t pointer for the given modelnumber or -name...
#define TU_CROUCH_MOVING_FACTOR
#define VectorCompare(a, b)
void RT_UpdateConnectionColumn(mapTiles_t *mapTiles, Routing &routing, const int actorSize, const int x, const int y, const int dir, const char **list, const int minZ, const int maxZ)
Routing Function to update the connection between two fields.
void Grid_MoveStore(pathing_t *path)
Caches the calculated move.
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
#define VectorAdd(a, b, dest)
actorSizeEnum_t actorSize
Battlescape grid functions.
void set(const pos3_t mini, const pos3_t maxi)
#define PLAYER_CROUCHING_HEIGHT
int Grid_Floor(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Returns the height of the floor in a cell.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
A list of locations that cannot be moved to.
#define DV_FLAG_AUTOCROUCH
bool isPossible(const pathing_t *path)
bool calcNewPos()
Calculate the cell the we end up in if moving in the give dir.
byte area[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
int RT_CheckCell(mapTiles_t *mapTiles, Routing &routing, const int actorSize, const int x, const int y, const int z, const char **list)
This function looks to see if an actor of a given size can occupy a cell(s) and if so identifies the ...
void PQueuePop(priorityQueue_t *pq, pos4_t item)
remove the first node from the pqueue and provide a pointer to it
definitions common between client and server, but not game lib
static bool Grid_CheckForbidden(const pos3_t exclude, const actorSizeEnum_t actorSize, pathing_t *path, pos3_t chkPos)
Checks one cell on the grid against the 'forbiddenList' (i.e. cells blocked by other entities)...
void VectorRotate(vec3_t m[3], const vec3_t va, vec3_t vb)
Rotate a vector with a rotation matrix.
#define ROUTING_UNREACHABLE
#define ACTOR_SIZE_NORMAL
void clipToMaxBoundaries()
void Grid_PosToVec(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec)
Converts a grid position to world coordinates.
#define ROUTING_NOT_REACHABLE
signed char getFloor(const actorSizeEnum_t actorSize, const pos3_t pos) const
#define VectorEqual(a, b)
#define PLAYER_STANDING_HEIGHT
a struct holding the relevant data to check if we can move between two adjacent cells ...
byte getStepupHeight(const int actorSize, const int x, const int y, const int z, const int dir) const
return the value without the flags for z-level change
#define VectorSubtract(a, b, dest)
void PQueueInitialise(priorityQueue_t *pq, uint32_t maxElements)
initialise the priority queue with a maximum size of maxelements.
byte getConn(const int actorSize, const int x, const int y, const int z, const int dir) const
static mapTiles_t mapTiles
byte areaStored[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
void expandXY(const int byVal)
expand the box in four directions, but clip them to the maximum boundaries