ScummVM API documentation
actor.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 #ifndef ASYLUM_RESOURCES_ACTOR_H
23 #define ASYLUM_RESOURCES_ACTOR_H
24 
25 #include "common/array.h"
26 #include "common/rect.h"
27 #include "common/serializer.h"
28 #include "common/stream.h"
29 
30 #include "asylum/shared.h"
31 
32 #include "asylum/resources/inventory.h"
33 
34 namespace Asylum {
35 
36 class AsylumEngine;
37 class GraphicResource;
38 class Screen;
39 
40 struct ActionArea;
41 struct GraphicFrame;
42 
44  uint32 count;
45  int32 current;
46  Common::Point points[120];
47  ActorDirection directions[120];
48 
49  ActorData() {
50  count = 0;
51  current = 0;
52  memset(&directions, 0, sizeof(directions));
53  }
54 
55  virtual ~ActorData() {}
56 
57  void load(Common::SeekableReadStream *stream) {
58  count = stream->readUint32LE();
59 
60  current = stream->readUint32LE();
61 
62  for (int32 i = 0; i < 120; i++) {
63  points[i].x = stream->readSint32LE();
64  points[i].y = stream->readSint32LE();
65  }
66 
67  for (int32 i = 0; i < 120; i++)
68  directions[i] = (ActorDirection)stream->readSint32LE();
69  }
70 
71  // Serializable
72  void saveLoadWithSerializer(Common::Serializer &s) {
73  s.syncAsUint32LE(count);
74  s.syncAsSint32LE(current);
75 
76  for (int32 i = 0; i < ARRAYSIZE(points); i++) {
77  s.syncAsSint32LE(points[i].x);
78  s.syncAsSint32LE(points[i].y);
79  }
80 
81  for (int32 i = 0; i < ARRAYSIZE(directions); i++)
82  s.syncAsSint32LE(directions[i]);
83  }
84 };
85 
86 class Actor : public Common::Serializable {
87 public:
88  Actor(AsylumEngine *engine, ActorIndex index);
89  virtual ~Actor() {};
90 
92  // Public variables & accessors
94  int32 flags;
95  int32 actionType; // ActionType enum value
96  Inventory inventory;
97 
98  void setActionIndex2(int32 index) { _actionIdx2 = index; }
99  void setObjectIndex(int32 index) { _objectIndex = index; }
100  void setDirection(ActorDirection dir) { _direction = dir; }
101  void setFrameCount(int32 count) { _frameCount = count; }
102  void setFrameIndex(int32 number) { _frameIndex = number; }
103  void setLastScreenUpdate(int32 tick) { _lastScreenUpdate = tick; }
104  void setNumberFlag01(int32 number) { _numberFlag01 = number; }
105  void setPriority(int32 priority) { _priority = priority; }
106  void setResourceId(ResourceId id) { _resourceId = id; }
107  void setSoundResourceId(ResourceId id) { _soundResourceId = id; }
108  void setStatus(ActorStatus status) { _status = status; }
109  void setTransparency(int32 val) { _transparency = val; }
110  void setTickCount(int32 tickCount) { _tickCount = tickCount; }
111 
112  void setField934(int32 val) { _field_934 = val; }
113  void setField938(int32 val) { _field_938 = val; }
114  void setField944(int32 val) { _field_944 = val; }
115 
116  int32 getActionIndex3() { return _actionIdx3; }
117  Common::Rect *getBoundingRect() { return &_boundingRect; }
118  ActorDirection getDirection() { return _direction; }
119  uint32 getFrameCount() { return _frameCount; }
120  uint32 getFrameIndex() { return _frameIndex; }
121  char *getName() { return (char *)&_name; }
122  ActorIndex getNextActorIndex() { return _nextActorIndex; }
123  int32 getNumberValue01() { return _numberValue01; }
124  Common::Point *getPoint() { return &_point; }
125  Common::Point *getPoint1() { return &_point1; }
126  Common::Point *getPoint2() { return &_point2; }
127  int32 getPriority() { return _priority; }
128  ResourceId getResourceId() { return _resourceId; }
129  ResourceId getResourcesId(uint32 index) { return _graphicResourceIds[index]; }
130  int32 getScriptIndex() { return _scriptIndex; }
131  bool shouldInvertPriority() { return _invertPriority; }
132  ResourceId getSoundResourceId() { return _soundResourceId; }
133  ActorStatus getStatus() { return _status; }
134  int32 getTickCount() { return _tickCount; }
135 
136  int32 getField934() { return _field_934; }
137  int32 getField944() { return _field_944; }
138  int32 getField948() { return _field_948; }
139  int32 getField94C() { return _field_94C; }
140 
141  // For saving
142  ActorData *getData() { return &_data; }
143 
145  // Data
147 
153  void load(Common::SeekableReadStream *stream);
154 
156  // Visibility
158 
164  bool isVisible() { return flags & kActorFlagVisible; }
165 
171  bool isOnScreen();
172 
176  void show() { setVisible(true); }
177 
181  void hide() { setVisible(false); }
182 
184  // Drawing & update
186 
190  void draw();
191 
195  void drawNumber();
196 
200  void update();
201 
205  void enable() { changeStatus(kActorStatusEnabled); }
206 
212  void changeStatus(ActorStatus status);
213 
215  // Direction & position
217 
221  void updateReflectionData();
222 
228  void changeDirection(ActorDirection direction);
229 
236  void faceTarget(uint32 target, DirectionFrom from);
237 
246  void setPosition(int16 newX, int16 newY, ActorDirection newDirection, uint32 frame);
247 
255  bool canChangeStatus(int index) const;
256 
262  void adjustCoordinates(Common::Point *point);
263 
265  // Misc
267 
271  void stopSound();
272 
280  Common::String toString(bool shortString = true);
281 
285  void clearReflectionData();
286 
287  bool canReach(const Common::Point &point);
288  void forceTo(int16 actorX, int16 actorY, bool doSpeech);
289  void setupReflectionData(ActorIndex nextActor, int32 actionAreaId, ActorDirection nextDirection, const Common::Point &nextPosition, bool invertPriority, const Common::Point &nextPositionOffset);
290  bool aNicePlaceToTalk(Common::Point *point, int32 *param);
291  bool canMove(Common::Point *point, ActorDirection direction, uint32 count, bool hasDelta);
292  void move(ActorDirection dir, uint32 distance);
293  bool testActorCollision(Common::Point *point, ActorDirection direction);
294  void drawInventory();
295  void stopWalking();
296 
302  bool checkBoredStatus() const;
303 
305  // Static update methods
307  static void crowsReturn(AsylumEngine *engine);
308 
315  static void morphInto(AsylumEngine *engine, int nextPlayer);
316 
325  static ActorDirection getAngle(const Common::Point &vec1, const Common::Point &vec2);
326 
335  static uint32 euclidianDistance(const Common::Point &point1, const Common::Point &point2);
336 
337  // Serializable
338  void saveLoadWithSerializer(Common::Serializer &s);
339 
340 private:
341  AsylumEngine *_vm;
342 
343  // Our current index
344  ActorIndex _index;
345 
347  // Data
349  Common::Point _point;
350  ResourceId _resourceId;
351  int32 _objectIndex;
352  uint32 _frameIndex;
353  uint32 _frameCount;
354  Common::Point _point1;
355  Common::Point _point2;
356  Common::Rect _boundingRect;
357  ActorDirection _direction;
358  int32 _field_3C;
359  ActorStatus _status;
360  int32 _field_44;
361  int32 _priority;
362  //flags
363  int32 _field_50;
364  int32 _field_54;
365  int32 _field_58;
366  int32 _field_5C;
367  int32 _field_60;
368  int32 _actionIdx3;
369  // TODO field_68 till field_617
370  ResourceId _walkingSound1;
371  ResourceId _walkingSound2;
372  ResourceId _walkingSound3;
373  ResourceId _walkingSound4;
374  uint32 _field_64C;
375  uint32 _field_650;
376  ResourceId _graphicResourceIds[55];
377  char _name[256];
378  int32 _distancesEO[20];
379  int32 _distancesNS[20];
380  int32 _distancesNSEO[20];
381  int32 _actionIdx2;
382  int32 _field_924;
383  uint32 _lastScreenUpdate;
384  int32 _scriptIndex;
385  //actionType
386  int32 _field_934;
387  int32 _field_938;
388  ResourceId _soundResourceId; // field_93C
389  int32 _numberValue01;
390  int32 _field_944; // has collision ?!
391  int32 _field_948;
392  int32 _field_94C;
393  int32 _numberFlag01;
394  int16 _numberStringWidth;
395  Common::Point _numberPoint;
396  char _numberString01[8];
397  int32 _field_968;
398  int32 _transparency;
399  bool _processNewDirection;
400  bool _invertPriority;
401  ActorDirection _nextDirection;
402  int32 _nextActionIndex;
403  ActorIndex _nextActorIndex;
404  Common::Point _nextPositionOffset;
405  Common::Point _nextPosition;
406  int32 _field_994;
407  int32 _field_998;
408  int32 _field_99C;
409  int32 _field_9A0;
410 
412  // Actor data
414  ActorData _data;
415 
416  int32 _tickCount;
417 
418  uint32 _updateCounter;
419 
421  // Update methods
423  void updateStatusInteracting();
424  void checkPumpkinDeath();
425  void updatePumpkin(GameFlag flagToCheck, GameFlag flagToSet, ObjectId objectToUpdate, ObjectId objectToDisable);
426 
427  void updateStatusEnabled();
428  void updateStatusEnabledProcessStatus(int16 testX, int16 testY, uint32 counter, int16 setX, int16 setY);
429 
430  void updateStatusBored();
431 
432  void CrowClosesIn();
433  void ScareCrowClosesIn();
434  void TentacleRises();
435 
436  void updateStatusEnabled2();
437  void CrowHoveringBeforeKill();
438  void CrowStatusQuo();
439  void TentacleWigglesForSarah();
440 
441  void CrowDives();
442  void MaxGetsHit();
443  void MaxAttacks();
444  void checkScareCrowDeath();
445  bool checkCrowDeath();
446  void ScareCrowAttacks();
447  bool actorsIntersect(ActorIndex actorIndex1, ActorIndex actorIndex2);
448  void TentacleWhips();
449  void SarahAttacks();
450 
451  void MaxGetsSome();
452  void SarahGetsSome();
453 
454  void TentacleDies();
455 
456  void CrowSwoops();
457  void ScareCrowRetreats();
458 
459  void updateStatusMorphing();
460 
461  void actionAreaCheck();
462 
464  // Path finding functions
466  uint32 _frameNumber;
467  bool findLeftPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
468  bool findRightPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
469  bool findUpPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
470  bool findDownPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
471  bool tryDirection(const Common::Point &source, Common::Array<int> *actions, Common::Point *point, ActorDirection direction, const Common::Point &destination, bool *flag);
472  bool canGetToDest(Common::Array<int> *actions, const Common::Point &point, ActorDirection direction, int16 loopcount);
473  bool testPolyInLink(const Common::Point &pt, Common::Array<int> *actions);
474 
476  // Misc
478 
484  void setVisible(bool value);
485 
489  void setVolume();
490 
491  void TentacleBlocksSarah(const Common::Point &vec1, Common::Point vec2);
492  void SarahDies();
493 
500  void updateNumbers(uint item, const Common::Point &point);
501 
510  bool isInActionArea(const Common::Point &pt, ActionArea *area);
511 
513  // Helper methods
515 
521  void updateGraphicData(uint32 offset);
522 
528  DrawFlags getGraphicsFlags();
529 
538  int32 getStride(ActorDirection direction, uint32 frameIndex) const;
539 
548  int32 getWalkIncrement(ActorDirection direction, uint32 frameIndex) const;
549 
557  static void incPosition(ActorDirection direction, int16 delta, Common::Point *point);
558 
567  static int32 getAngleOfVector(const Common::Point &vec1, const Common::Point &vec2);
568 
576  static void getCrowStrikeZone(Common::Rect *rect, ActorDirection direction, const Common::Point &point);
577 
586  static bool determineLeftOrRight(const Common::Point &vec1, const Common::Point &vec2);
587 
596  static int16 pointInRectXAdjust(const Common::Rect &rect, const Common::Point &point);
597 
606  static int16 pointInRectYAdjust(const Common::Rect &rect, const Common::Point &point);
607 
608 }; // end of class MainActor
609 
610 } // end of namespace Asylum
611 
612 #endif // ASYLUM_RESOURCES_ACTOR_H
#define ARRAYSIZE(x)
Definition: util.h:91
Definition: inventory.h:32
Definition: str.h:59
void enable()
Definition: actor.h:205
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: actor.h:86
uint32 readUint32LE()
Definition: stream.h:473
Definition: asylum.h:53
Definition: rect.h:144
Definition: atari-screen.h:60
Definition: stream.h:745
Definition: serializer.h:79
Definition: actor.h:43
Definition: script.h:58
void show()
Definition: actor.h:176
Definition: rect.h:45
Definition: asylum.h:73
Definition: serializer.h:308
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
int16 x
Definition: rect.h:46
bool isVisible()
Definition: actor.h:164
void hide()
Definition: actor.h:181
int16 y
Definition: rect.h:47