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
34namespace Asylum {
35
36class AsylumEngine;
37class GraphicResource;
38class Screen;
39
40struct ActionArea;
41struct 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
87public:
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
154
156 // Visibility
158
164 bool isVisible() { return flags & kActorFlagVisible; }
165
172
176 void show() { setVisible(true); }
177
181 void hide() { setVisible(false); }
182
184 // Drawing & update
186
190 void draw();
191
196
200 void update();
201
205 void enable() { changeStatus(kActorStatusEnabled); }
206
212 void changeStatus(ActorStatus status);
213
215 // Direction & position
217
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
263
265 // Misc
267
271 void stopSound();
272
280 Common::String toString(bool shortString = true);
281
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
340private:
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 _walkingSounds[4];
371 uint32 _field_64C;
372 uint32 _field_650;
373 ResourceId _graphicResourceIds[55];
374 char _name[256];
375 int32 _distancesEO[20];
376 int32 _distancesNS[20];
377 int32 _distancesNSEO[20];
378 int32 _actionIdx2;
379 int32 _field_924;
380 uint32 _lastScreenUpdate;
381 int32 _scriptIndex;
382 //actionType
383 int32 _field_934;
384 int32 _field_938;
385 ResourceId _soundResourceId; // field_93C
386 int32 _numberValue01;
387 int32 _field_944; // has collision ?!
388 int32 _field_948;
389 int32 _field_94C;
390 int32 _numberFlag01;
391 int16 _numberStringWidth;
392 Common::Point _numberPoint;
393 char _numberString01[8];
394 int32 _field_968;
395 int32 _transparency;
396 bool _processNewDirection;
397 bool _invertPriority;
398 ActorDirection _nextDirection;
399 int32 _nextActionIndex;
400 ActorIndex _nextActorIndex;
401 Common::Point _nextPositionOffset;
402 Common::Point _nextPosition;
403 int32 _field_994;
404 int32 _field_998;
405 int32 _field_99C;
406 int32 _field_9A0;
407
409 // Actor data
411 ActorData _data;
412
413 int32 _tickCount;
414
415 uint32 _updateCounter;
416
418 // Update methods
420 void updateStatusInteracting();
421 void checkPumpkinDeath();
422 void updatePumpkin(GameFlag flagToCheck, GameFlag flagToSet, ObjectId objectToUpdate, ObjectId objectToDisable);
423
424 void updateStatusEnabled();
425 void updateStatusEnabledProcessStatus(int16 testX, int16 testY, uint32 counter, int16 setX, int16 setY);
426
427 void updateStatusBored();
428
429 void CrowClosesIn();
430 void ScareCrowClosesIn();
431 void TentacleRises();
432
433 void updateStatusEnabled2();
434 void CrowHoveringBeforeKill();
435 void CrowStatusQuo();
436 void TentacleWigglesForSarah();
437
438 void CrowDives();
439 void MaxGetsHit();
440 void MaxAttacks();
441 void checkScareCrowDeath();
442 bool checkCrowDeath();
443 void ScareCrowAttacks();
444 bool actorsIntersect(ActorIndex actorIndex1, ActorIndex actorIndex2);
445 void TentacleWhips();
446 void SarahAttacks();
447
448 void MaxGetsSome();
449 void SarahGetsSome();
450
451 void TentacleDies();
452
453 void CrowSwoops();
454 void ScareCrowRetreats();
455
456 void updateStatusMorphing();
457
458 void actionAreaCheck();
459
461 // Path finding functions
463 uint32 _frameNumber;
464 bool findLeftPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
465 bool findRightPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
466 bool findUpPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
467 bool findDownPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
468 bool tryDirection(const Common::Point &source, Common::Array<int> *actions, Common::Point *point, ActorDirection direction, const Common::Point &destination, bool *flag);
469 bool canGetToDest(Common::Array<int> *actions, const Common::Point &point, ActorDirection direction, int16 loopcount);
470 bool testPolyInLink(const Common::Point &pt, Common::Array<int> *actions);
471
473 // Misc
475
481 void setVisible(bool value);
482
486 void setVolume();
487
488 void TentacleBlocksSarah(const Common::Point &vec1, Common::Point vec2);
489 void SarahDies();
490
497 void updateNumbers(uint item, const Common::Point &point);
498
507 bool isInActionArea(const Common::Point &pt, ActionArea *area);
508
510 // Helper methods
512
518 void updateGraphicData(uint32 offset);
519
525 DrawFlags getGraphicsFlags();
526
535 int32 getStride(ActorDirection direction, uint32 frameIndex) const;
536
545 int32 getWalkIncrement(ActorDirection direction, uint32 frameIndex) const;
546
554 static void incPosition(ActorDirection direction, int16 delta, Common::Point *point);
555
564 static int32 getAngleOfVector(const Common::Point &vec1, const Common::Point &vec2);
565
573 static void getCrowStrikeZone(Common::Rect *rect, ActorDirection direction, const Common::Point &point);
574
583 static bool determineLeftOrRight(const Common::Point &vec1, const Common::Point &vec2);
584
593 static int16 pointInRectXAdjust(const Common::Rect &rect, const Common::Point &point);
594
603 static int16 pointInRectYAdjust(const Common::Rect &rect, const Common::Point &point);
604
605}; // end of class MainActor
606
607} // end of namespace Asylum
608
609#endif // ASYLUM_RESOURCES_ACTOR_H
Definition: actor.h:86
bool canChangeStatus(int index) const
bool isVisible()
Definition: actor.h:164
void drawNumber()
static void morphInto(AsylumEngine *engine, int nextPlayer)
void updateReflectionData()
void adjustCoordinates(Common::Point *point)
void clearReflectionData()
bool isOnScreen()
bool checkBoredStatus() const
void show()
Definition: actor.h:176
void load(Common::SeekableReadStream *stream)
static ActorDirection getAngle(const Common::Point &vec1, const Common::Point &vec2)
void enable()
Definition: actor.h:205
void faceTarget(uint32 target, DirectionFrom from)
void hide()
Definition: actor.h:181
void changeDirection(ActorDirection direction)
static uint32 euclidianDistance(const Common::Point &point1, const Common::Point &point2)
void changeStatus(ActorStatus status)
void setPosition(int16 newX, int16 newY, ActorDirection newDirection, uint32 frame)
Common::String toString(bool shortString=true)
void stopSound()
Definition: asylum.h:73
Definition: inventory.h:32
uint32 readUint32LE()
Definition: stream.h:473
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
Definition: stream.h:745
Definition: serializer.h:352
Definition: serializer.h:80
Definition: str.h:59
#define ARRAYSIZE(x)
Definition: util.h:114
Definition: script.h:58
Definition: actor.h:43
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: rect.h:536
Definition: atari-screen.h:58