ScummVM API documentation
assign.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_ASSIGN_H
27 #define SAGA2_ASSIGN_H
28 
29 #include "saga2/target.h"
30 
31 namespace Saga2 {
32 
33 class Actor;
34 class Task;
35 class TaskStack;
36 
37 // Constants representing the non-virtual ActorAssignment classes
38 enum AssignmentTypes {
39  kPatrolRouteAssignment,
40  kHuntToBeNearLocationAssignment,
41  kHuntToBeNearActorAssignment,
42  kHuntToKillAssignment,
43  kTetheredWanderAssignment,
44  kAttendAssignment
45 };
46 
47 /* ===================================================================== *
48  ActorAssignment class
49  * ===================================================================== */
50 
52 
53  enum {
54  kAFHasAssignment = (1 << 3)
55  };
56 
57  uint16 _startFrame, // Time in day when this was constructed
58  _endFrame; // End time of the assignment
59 
60  Actor *_actor;
61 
62 public:
63  // Constructor
64  ActorAssignment(Actor *a, uint16 until);
65 
67 
68  // Destructor
69  virtual ~ActorAssignment();
70 
71  // Return the number of bytes need to archive the data in this
72  // assignment
73  virtual int32 archiveSize() const;
74 
75  virtual void write(Common::MemoryWriteStreamDynamic *out) const;
76 
77  // Construct a TaskStack for this assignment
78  TaskStack *createTask();
79 
80  // This function is called to notify the assignment of the
81  // completion of a task which the assignment had created.
82  virtual void handleTaskCompletion(TaskResult result);
83 
84  // Determine if assignment's time limit is up
85  virtual bool isValid();
86 
87  // Return a pointer to the actor to which this assignment belongs
88  Actor *getActor() const;
89 
90  // Return an integer representing the class of this assignment
91  virtual int16 type() const = 0;
92 
93 protected:
94  void startTask();
95 
96  // Determine if this assignment needs to create a task at this time
97  virtual bool taskNeeded();
98 
99  // Create a Task for this assignment
100  virtual Task *getTask(TaskStack *ts) = 0;
101 };
102 
103 /* ===================================================================== *
104  PatrolRouteAssignment class
105  * ===================================================================== */
106 
108  int16 _routeNo, // Patrol route number
109  _startingWayPoint, // Way point at which to start (-1 = default)
110  _endingWayPoint; // Way point at which to end (-1 = default)
111  uint8 _routeFlags, // Flags indicating how patrol route should
112  // be followed
113  _flags; // Flags representing the state of this
114  // assignment
115 
116  enum {
117  kRouteCompleted = (1 << 0)
118  };
119 
120 public:
121  // Constructor -- initial object construction
123  Actor *a,
124  uint16 until,
125  int16 rteNo,
126  uint8 patrolFlags,
127  int16 start = -1,
128  int16 end = -1);
129 
131 
132  // Return the number of bytes need to archive the data in this
133  // assignment
134  int32 archiveSize() const;
135 
136  void write(Common::MemoryWriteStreamDynamic *out) const;
137 
138  // Return an integer representing the type of this assignment
139  int16 type() const;
140 
141  // This function is called to notify the assignment of the
142  // completion of a task which the assignment had created.
143  void handleTaskCompletion(TaskResult result);
144 
145  // Determine if assignment is still valid
146  bool isValid();
147 
148 protected:
149  // Determine if this assignment needs to create a task at this time
150  bool taskNeeded();
151 
152  // Construct a Task for this assignment
153  Task *getTask(TaskStack *ts);
154 };
155 
156 /* ===================================================================== *
157  HuntToBeNearLocationAssignment class
158  * ===================================================================== */
159 
161  TargetPlaceHolder _targetMem;
162  uint16 _range;
163 
164  // An initialization function which provides a common ground for
165  // the initial constructors.
166  void initialize(const Target &targ, uint16 r);
167 
168 public:
169  // Constructors -- initial assignment construction
170 
171  // Construct with no time limit and a specific TilePoint
172  HuntToBeNearLocationAssignment(Actor *a, const TilePoint &tp, uint16 r);
173 
174  // Construct with time limit and a specific TilePoint
176  Actor *a,
177  uint16 until,
178  const TilePoint &tp,
179  uint16 r) :
180  ActorAssignment(a, until) {
181  initialize(LocationTarget(tp), r);
182  }
183 
184  // Construct with no time limit and an abstract target
185  HuntToBeNearLocationAssignment(Actor *a, const Target &targ, uint16 r);
186 
187  // Construct with time limit and an abstract target
189  Actor *a,
190  uint16 until,
191  const Target &targ,
192  uint16 r) :
193  ActorAssignment(a, until) {
194  initialize(targ, r);
195  }
196 
197 
199 
200  // Return the number of bytes need to archive the data in this
201  // assignment
202  int32 archiveSize() const;
203 
204  void write(Common::MemoryWriteStreamDynamic *out) const;
205 
206  int16 type() const;
207 
208 protected:
209  bool taskNeeded();
210 
211  Task *getTask(TaskStack *ts);
212 
213  const Target *getTarget() const {
214  return (const Target *)_targetMem;
215  }
216 };
217 
218 /* ===================================================================== *
219  HuntToBeNearActorAssignment class
220  * ===================================================================== */
221 
223  TargetPlaceHolder _targetMem;
224  uint16 _range;
225  uint8 _flags;
226 
227  enum {
228  kTrack = (1 << 0) // This hunt is a track.
229  };
230 
231  // An initialization function which provides a common ground for
232  // the initial constructors.
233  void initialize(
234  const ActorTarget &at,
235  uint16 r,
236  bool trackFlag);
237 
238 public:
239  // Constructors -- initial assignment construction
240 
241  // Construct with no time limit and specific actor
243  Actor *a,
244  uint16 r,
245  bool trackFlag = false);
246 
247  // Construct with time limit and specific actor
249  Actor *ac,
250  uint16 until,
251  Actor *a,
252  uint16 r,
253  bool trackFlag = false) :
254  ActorAssignment(ac, until) {
255  assert(isActor(a) && a != getActor());
256  initialize(SpecificActorTarget(a), r, trackFlag);
257  }
258 
259  // Construct with no time limit and abstract actor target
261  Actor *a,
262  const ActorTarget &at,
263  uint16 r,
264  bool trackFlag = false);
265 
266  // Construct with time limit and abstract actor target
268  Actor *a,
269  uint16 until,
270  const ActorTarget &at,
271  uint16 r,
272  bool trackFlag = false) :
273  ActorAssignment(a, until) {
274  initialize(at, r, trackFlag);
275  }
276 
278 
279  // Return the number of bytes need to archive the data in this
280  // assignment
281  int32 archiveSize() const;
282 
283  void write(Common::MemoryWriteStreamDynamic *out) const;
284 
285  int16 type() const;
286 
287 protected:
288  bool taskNeeded();
289 
290  Task *getTask(TaskStack *ts);
291 
292  const ActorTarget *getTarget() const {
293  return (const ActorTarget *)_targetMem;
294  }
295 };
296 
297 /* ===================================================================== *
298  HuntToKillAssignment class
299  * ===================================================================== */
300 
302  TargetPlaceHolder _targetMem;
303  uint8 _flags;
304 
305  enum {
306  kTrack = (1 << 0), // This hunt is a track.
307  kSpecificActor = (1 << 1) // The actor target is a specific actor
308  };
309 
310  // An initialization function which provides a common ground for
311  // the initial constructors.
312  void initialize(
313  const ActorTarget &at,
314  bool trackFlag,
315  bool specificActorFlag);
316 
317 public:
318  // Constructors -- initial assignment construction
319 
320  // Construct with no time limit and specific actor
321  HuntToKillAssignment(Actor *a, bool trackFlag = false);
322 
323  // Construct with time limit and specific actor
325  Actor *ac,
326  uint16 until,
327  Actor *a,
328  bool trackFlag = false) :
329  ActorAssignment(ac, until) {
330  assert(isActor(a) && a != getActor());
331  initialize(SpecificActorTarget(a), trackFlag, true);
332  }
333 
334  // Construct with no time limit and abstract actor target
336  Actor *a,
337  const ActorTarget &at,
338  bool trackFlag = false);
339 
340  // Construct with time limit and abstract actor target
342  Actor *a,
343  uint16 until,
344  const ActorTarget &at,
345  bool trackFlag = false) :
346  ActorAssignment(a, until) {
347  initialize(at, trackFlag, false);
348  }
349 
350  // Return the number of bytes need to archive the data in this
351  // assignment
352  int32 archiveSize() const;
353 
354  void write(Common::MemoryWriteStreamDynamic *out) const;
355 
356  // Determine if assignment's time limit is up or if the actor is
357  // already dead
358  bool isValid();
359 
360  int16 type() const;
361 
362 protected:
363  bool taskNeeded();
364 
365  Task *getTask(TaskStack *ts);
366 
367  const ActorTarget *getTarget() const {
368  return (const ActorTarget *)_targetMem;
369  }
370 };
371 
372 /* ===================================================================== *
373  TetheredAssignment class
374  * ===================================================================== */
375 
377 protected:
378  // Tether region
379  int16 _minU, // Minimum U coordinate in tether
380  _minV, // Minimum V coordinate in tether
381  _maxU, // Maximum U coordinate in tether
382  _maxV; // Maximum V coordinate in tether
383 
384 public:
385  // Constructor -- initial assignment construction
386  TetheredAssignment(Actor *a, uint16 until, const TileRegion &reg) :
387  ActorAssignment(a, until),
388  _minU(reg.min.u),
389  _minV(reg.min.v),
390  _maxU(reg.max.u),
391  _maxV(reg.max.v) {
392  }
393 
395 
396  // Return the number of bytes need to archive the data in this
397  // assignment
398  int32 archiveSize() const;
399 
400  void write(Common::MemoryWriteStreamDynamic *out) const;
401 };
402 
403 /* ===================================================================== *
404  TetheredWanderAssignment class
405  * ===================================================================== */
406 
408 public:
409  // Constructor -- initial assignment construction
410  TetheredWanderAssignment(Actor *a, uint16 until, const TileRegion &reg);
411 
413 
414  // Return an integer representing the type of this assignment
415  int16 type() const;
416 
417 protected:
418  // Construct a Task for this assignment
419  Task *getTask(TaskStack *ts);
420 };
421 
422 /* ===================================================================== *
423  AttendAssignment class
424  * ===================================================================== */
425 
427  GameObject *_obj; // Object to which to attend
428 
429 public:
430  // Constructor -- initial assignment construction
431  AttendAssignment(Actor *a, uint16 until, GameObject *o);
432 
434 
435  // Return the number of bytes need to archive the data in this
436  // assignment
437  int32 archiveSize() const;
438 
439  void write(Common::MemoryWriteStreamDynamic *out) const;
440 
441  // Return an integer representing the type of this assignment
442  int16 type() const;
443 
444 protected:
445  // Construct a Task for this assignment
446  Task *getTask(TaskStack *ts);
447 };
448 
449 /* ===================================================================== *
450  Prototypes
451  * ===================================================================== */
452 
453 // Return the number of bytes necessary to archive this actor's
454 // assignment in an archive buffer
455 int32 assignmentArchiveSize(Actor *a);
456 
457 void writeAssignment(Actor *a, Common::MemoryWriteStreamDynamic *out);
458 void readAssignment(Actor *a, Common::InSaveFile *in);
459 
460 }
461 
462 #endif
Definition: assign.h:426
Definition: task.h:122
Definition: target.h:135
Definition: actor.h:32
Definition: target.h:549
Definition: assign.h:107
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: stream.h:745
Definition: actor.h:589
Definition: tcoords.h:222
Definition: assign.h:407
Definition: assign.h:301
Definition: target.h:183
Definition: assign.h:222
Definition: objects.h:118
Definition: target.h:530
Definition: task.h:1563
Definition: assign.h:376
Definition: assign.h:51