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