UFO: Alien Invasion
Loading...
Searching...
No Matches
grid.h
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#pragma once
27
28#define MAX_FORBIDDENLIST (MAX_EDICTS * 4)
29
35typedef struct forbiddenList_s {
36private:
39public:
40
42 reset();
43 }
44 inline void add(pos3_t pos, byte* entSize) {
45 fbList[fbListLength++] = pos;
46 fbList[fbListLength++] = entSize;
47
49 Sys_Error("ForbiddenList.add: list too long\n");
50 }
51 inline void reset() {
52 fbListLength = 0;
53 }
54 inline pos_t** getNext(pos_t** prev) {
55 if (!fbListLength)
56 return nullptr;
57 if (!prev)
58 return fbList;
59 prev += 2;
60 if (prev >= fbList + fbListLength)
61 return nullptr;
62 return prev;
63 }
64 inline actorSizeEnum_t getEntSize(pos_t** current) {
65 actorSizeEnum_t entSize;
66 byte* forbiddenSize = *(current + 1);
67 memcpy(&entSize, forbiddenSize, sizeof(entSize));
68 return entSize;
69 }
70#ifdef DEBUG
71 /* this is NOT equivalent to Grid_CheckForbidden() !! Just for debugging purposes */
72 inline bool contains(const pos3_t pos) {
73 pos_t** p = nullptr;
74 while ((p = getNext(p))) {
75 if (VectorCompare((*p), pos))
76 return true;
77 }
78 return false;
79 }
80#endif
82
83typedef struct pathing_s {
84 /* TUs needed to move to this cell for the current actor */
87
88 /* Indicates where the actor would have moved from to get to the cell */
90
91 /* forbidden list */
93} pathing_t;
94
95/*==========================================================
96GRID ORIENTED MOVEMENT AND SCANNING
97==========================================================*/
98
99void Grid_RecalcRouting(mapTiles_t* mapTiles, Routing& routing, const char* name, const GridBox& box, const char** list);
100void Grid_RecalcBoxRouting(mapTiles_t* mapTiles, Routing& routing, const GridBox& box, const char** list);
101void Grid_CalcPathing(const Routing& routing, const actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, int distance, forbiddenList_t* forbiddenList);
102bool 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);
103void Grid_MoveStore(pathing_t* path);
104pos_t Grid_MoveLength(const pathing_t* path, const pos3_t to, byte crouchingState, bool stored);
105int Grid_MoveNext(const pathing_t* path, const pos3_t toPos, byte crouchingState);
106unsigned int Grid_Ceiling(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
107int Grid_Floor(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
108int Grid_GetTUsForDirection(const int dir, bool crouched);
109pos_t Grid_Fall(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
110bool Grid_ShouldUseAutostand (const pathing_t* path, const pos3_t toPos);
111void Grid_PosToVec(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec);
static forbiddenList_t forbiddenList
A list of locations that cannot be moved to.
Definition cl_actor.cpp:602
#define PATHFINDING_WIDTH
absolute max
Definition defines.h:292
#define ACTOR_MAX_STATES
Definition defines.h:338
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
Definition defines.h:294
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
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.
Definition grid.cpp:698
void Grid_CalcPathing(const Routing &routing, const actorSizeEnum_t actorSize, pathing_t *path, const pos3_t from, int distance, forbiddenList_t *forbiddenList)
Recalculate the pathing table for the given actor(-position).
Definition grid.cpp:497
int Grid_GetTUsForDirection(const int dir, bool crouched)
Returns the amounts of TUs that are needed to perform one step into the given direction.
Definition grid.cpp:766
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.
Definition grid.cpp:783
void Grid_PosToVec(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec)
Converts a grid position to world coordinates.
Definition grid.cpp:832
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.
Definition grid.cpp:818
void Grid_MoveStore(pathing_t *path)
Caches the calculated move.
Definition grid.cpp:683
#define MAX_FORBIDDENLIST
Definition grid.h:28
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).
Definition grid.cpp:719
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.
Definition grid.cpp:590
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.
Definition grid.cpp:854
unsigned int Grid_Ceiling(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Returns the height of the floor in a cell.
Definition grid.cpp:741
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.
Definition grid.cpp:922
int Grid_Floor(const Routing &routing, const actorSizeEnum_t actorSize, const pos3_t pos)
Returns the height of the floor in a cell.
Definition grid.cpp:754
short dvec_t
The direction vector tells us where the actor came from (in his previous step). The pathing table hol...
Definition mathlib.h:236
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
A list of locations that cannot be moved to.
Definition grid.h:35
pos_t * fbList[MAX_FORBIDDENLIST]
Definition grid.h:37
void add(pos3_t pos, byte *entSize)
Definition grid.h:44
int fbListLength
Definition grid.h:38
actorSizeEnum_t getEntSize(pos_t **current)
Definition grid.h:64
void reset()
Definition grid.h:51
pos_t ** getNext(pos_t **prev)
Definition grid.h:54
forbiddenList_s()
Definition grid.h:41
byte areaStored[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition grid.h:86
forbiddenList_t * fbList
Definition grid.h:92
dvec_t areaFrom[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition grid.h:89
byte area[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition grid.h:85
static mapTiles_t mapTiles
pos_t pos3_t[3]
Definition ufotypes.h:58
byte pos_t
Definition ufotypes.h:57
vec_t vec3_t[3]
Definition ufotypes.h:39
int32_t actorSizeEnum_t
Definition ufotypes.h:77
#define VectorCompare(a, b)
Definition vector.h:63