UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
grid.h
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 1997-2001 Id Software, Inc.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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 
35 typedef struct forbiddenList_s {
36 private:
39 public:
40 
42  reset();
43  }
44  inline void add(pos3_t pos, byte* entSize) {
45  fbList[fbListLength++] = pos;
46  fbList[fbListLength++] = entSize;
47 
48  if (fbListLength > MAX_FORBIDDENLIST)
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 
83 typedef 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 /*==========================================================
96 GRID ORIENTED MOVEMENT AND SCANNING
97 ==========================================================*/
98 
99 void Grid_RecalcRouting(mapTiles_t* mapTiles, Routing& routing, const char* name, const GridBox& box, const char** list);
100 void Grid_RecalcBoxRouting(mapTiles_t* mapTiles, Routing& routing, const GridBox& box, const char** list);
101 void Grid_CalcPathing(const Routing& routing, const actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, int distance, forbiddenList_t* forbiddenList);
102 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);
103 void Grid_MoveStore(pathing_t* path);
104 pos_t Grid_MoveLength(const pathing_t* path, const pos3_t to, byte crouchingState, bool stored);
105 int Grid_MoveNext(const pathing_t* path, const pos3_t toPos, byte crouchingState);
106 unsigned int Grid_Ceiling(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
107 int Grid_Floor(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
108 int Grid_GetTUsForDirection(const int dir, bool crouched);
109 pos_t Grid_Fall(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos);
110 bool Grid_ShouldUseAutostand (const pathing_t* path, const pos3_t toPos);
111 void Grid_PosToVec(const Routing& routing, const actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec);
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
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
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
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
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_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
int32_t actorSizeEnum_t
Definition: ufotypes.h:77
dvec_t areaFrom[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition: grid.h:89
#define MAX_FORBIDDENLIST
Definition: grid.h:28
pos_t ** getNext(pos_t **prev)
Definition: grid.h:54
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
#define PATHFINDING_WIDTH
absolute max
Definition: defines.h:292
byte area[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition: grid.h:85
void reset()
Definition: grid.h:51
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
forbiddenList_s()
Definition: grid.h:41
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
int fbListLength
Definition: grid.h:38
static forbiddenList_t forbiddenList
A list of locations that cannot be moved to.
Definition: cl_actor.cpp:602
Definition: grid.h:83
pos_t pos3_t[3]
Definition: ufotypes.h:58
struct forbiddenList_s forbiddenList_t
A list of locations that cannot be moved to.
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
pos_t * fbList[MAX_FORBIDDENLIST]
Definition: grid.h:37
byte areaStored[ACTOR_MAX_STATES][PATHFINDING_HEIGHT][PATHFINDING_WIDTH][PATHFINDING_WIDTH]
Definition: grid.h:86
#define VectorCompare(a, b)
Definition: vector.h:63
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
Definition: defines.h:294
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
void Grid_MoveStore(pathing_t *path)
Caches the calculated move.
Definition: grid.cpp:683
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
forbiddenList_t * fbList
Definition: grid.h:92
vec_t vec3_t[3]
Definition: ufotypes.h:39
void add(pos3_t pos, byte *entSize)
Definition: grid.h:44
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
struct pathing_s pathing_t
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
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
A list of locations that cannot be moved to.
Definition: grid.h:35
#define ACTOR_MAX_STATES
Definition: defines.h:338
uint8_t byte
Definition: ufotypes.h:34
actorSizeEnum_t getEntSize(pos_t **current)
Definition: grid.h:64
byte pos_t
Definition: ufotypes.h:57
static mapTiles_t mapTiles