ScummVM API documentation
patrol.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  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_PATROL_H
27 #define SAGA2_PATROL_H
28 
29 namespace Saga2 {
30 
31 struct TilePoint;
32 class PatrolRouteList;
33 extern PatrolRouteList **patrolRouteList; // Global patrol route array
34 
35 /* ===================================================================== *
36  PatrolRoute class
37  * ===================================================================== */
38 
39 // This class represents an individual patrol route. A patrol route
40 // consists of an integer representing the number of way points in the
41 // patrol route followed by a variable number of TilePoints representing
42 // the coordinates of the patrol routes.
43 
44 class PatrolRoute {
45  int16 _wayPoints; // The number of way points in this patrol route
46  TilePoint **_route;
47 
48 public:
50  ~PatrolRoute();
51 
52  // Return the number of way points
53  int16 vertices() const {
54  return _wayPoints;
55  }
56 
57  // Returns a const reference to a specified way point
58  const TilePoint &operator[](int16 index) const;
59 };
60 
61 /* ===================================================================== *
62  PatrolRouteList class
63  * ===================================================================== */
64 
65 // This class represent a variable sized list of patrol routes. The list
66 // consists of a pointer to the actual patrol route data followed by a
67 // pointer to a dynamically allocated array of 32-bit integers representing
68 // the offset, in bytes, of each corresponding patrol route from the
69 // beginning of the patrol route data.
70 
72  friend void initPatrolRoutes();
73  friend void cleanupPatrolRoutes();
74 
75  int16 _numRoutes;
76  PatrolRoute **_routes;
77 
78 public:
80  ~PatrolRouteList();
81 
82  // Returns the number of patrol routes in the list
83  int16 routes() {
84  return _numRoutes;
85  }
86 
87  // Returns a reference to the specified patrol route
88  PatrolRoute &getRoute(int16 index) {
89  return *_routes[index];
90  }
91 };
92 
93 /* ===================================================================== *
94  PatrolRouteIterator class
95  * ===================================================================== */
96 
97 // This class represents a view of a patrol route by introducing the notion
98 // of iteration to the patrol routes. In other words, it provides a
99 // method of moving from one way point in a patrol route to the next.
100 
101 enum PatrolRouteIteratorFlags {
102 
103  // These flags define the type of iterator, and are only initialized
104  // when the iterator is constructed.
105  kPatrolRouteReverse = (1 << 0), // Iterate in reverse
106  kPatrolRouteAlternate = (1 << 1), // Iterate back and forth
107  kPatrolRouteRepeat = (1 << 2), // Iterate repeatedly
108  kPatrolRouteRandom = (1 << 3), // Iterate randomly
109 
110  // These flags define the current state of the iterator.
111  kPatrolRouteInAlternate = (1 << 4) // Iterator is currently going in
112  // the alternate direction
113 };
114 
116  int16 _routeNo; // Index of the patrol route
117  int16 _vertexNo; // Current waypoint index
118  byte _mapNum; // Map in which this route exists
119  byte _flags; // various flags
120 
121 public:
122  PatrolRouteIterator() { _routeNo = _vertexNo = 0; _mapNum = _flags = 0;}
123  PatrolRouteIterator(uint8 map, int16 rte, uint8 type);
124  PatrolRouteIterator(uint8 map, int16 rte, uint8 type, int16 startingPoint);
125 
126  void read(Common::InSaveFile *in);
127  void write(Common::MemoryWriteStreamDynamic *out) const;
128 
129 private:
130  void increment(); // Increment waypoint index
131  void decrement(); // Decrement waypoint index
132  void altIncrement(); // Increment in alternate direction
133  void altDecrement(); // Decrement in alternate direction
134 
135 public:
136  // Determine if the iterator will repeat infinitely
137  bool isRepeating() const {
138  return _flags & (kPatrolRouteRepeat | kPatrolRouteRandom);
139  }
140 
141  // Return the current way point number
142  int16 wayPointNum() const {
143  return _vertexNo;
144  }
145 
146  // Return the coordinates of the current waypoint
147  const TilePoint operator*() const;
148 
149  // Iterate
150  const PatrolRouteIterator &operator++();
151 
152  // Determine if this iterator is equivalent to the specified iterator
153  bool operator==(const PatrolRouteIterator &iter) const {
154  return _routeNo == iter._routeNo && _vertexNo == iter._vertexNo
155  && _mapNum == iter._mapNum && _flags == iter._flags;
156  }
157 };
158 
159 /* ===================================================================== *
160  PatrolRoute list management function prototypes
161  * ===================================================================== */
162 
163 // Load the patrol routes from the resource file
164 void initPatrolRoutes();
165 
166 // Cleanup the patrol routes
167 void cleanupPatrolRoutes();
168 
169 } // end of namespace Saga2
170 
171 #endif
Definition: actor.h:32
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: stream.h:745
Definition: patrol.h:115
Definition: patrol.h:44
Definition: patrol.h:71