ScummVM API documentation
PathfindingGraphNode.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_PATHFINDINGGRAPHNODE_H
32 #define CRAB_PATHFINDINGGRAPHNODE_H
33 
34 #include "crab/Rectangle.h"
35 #include "crab/vectors.h"
36 
37 namespace Crab {
38 
39 // This is the basic pathfinding node that will construct the pathfinding graph. (SZ)
40 // Although Unrest is using a square grid based pathfinding map, this is made to be a general use pathfinding node.
42  friend class PathfindingGrid;
43 
44  int _id; // Each ID will be assigned when the pathfinding graph is generated and will identify each node.
45 
46  float _movementCost; // 1 is open terrain, >1 is impeding terrain, <0 is completely obstructed
47 
48  Vector2f _position; // Position of the node
49 
50  Rect _collisionRect; // Represents spaced covered by the node.
51 
52 public:
54  Common::Array<float> _neighborCosts; // The movement cost for the neighbor nodes (distance to the node X the nodes movement cost)
55  // This is stored to prevent having to recalculate each frame.
56 
58  PathfindingGraphNode(Vector2f pos, int i);
59 
61 
62  float getMovementCost() {
63  return _movementCost;
64  }
65 
66  Vector2f getPosition() const {
67  return _position;
68  }
69 
70  // Adds node to neighbor vector and cost to neighbor costs
71  void addNeighbor(PathfindingGraphNode *node);
72 
73  // Same as above, but does not calculate distance. Used when all nodes
74  // are equidistant
75  void addNeighbor(PathfindingGraphNode *node, bool ignoreDistance);
76 
77  // const Common::Array< PathfindingGraphNode*>& GetNeighbors() const;
78 
79  Rect getRect() const {
80  return _collisionRect;
81  }
82 
83  // Return true if the node is adjacent to a blocked node
84  bool adjacentToObstacle() const;
85 
86  // Return true if the node is adjacent to the otherNode
87  bool adjacentToNode(PathfindingGraphNode *otherNode);
88 };
89 
90 } // End of namespace Crab
91 
92 #endif // CRAB_PATHFINDINGGRAPHNODE_H
Definition: Rectangle.h:42
Definition: array.h:52
Definition: PathfindingGrid.h:43
Definition: moveeffect.h:37
Definition: PathfindingGraphNode.h:41