ScummVM API documentation
character.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 MACS2_CHARACTER_H
23#define MACS2_CHARACTER_H
24
25#include "common/array.h"
26#include "common/rect.h"
27#include "macs2/gameobjects.h"
28
29namespace Macs2 {
30
31struct AnimFrame;
32
33class Character {
34private:
35 Common::Point _startPosition;
36
37 uint32 _startTime = 0;
38 uint32 _duration = 0;
39
40 // If this is set, a lerp to a location becomes picking up
41 Macs2::GameObject *_pickedUpObject = nullptr;
42
43 // Handle when the character has moved into a non-walkable area, push them out if
44 // they did and return true, return false otherwise
45 bool handleWalkability(Character *c);
46
47 uint16 lookupWalkability(const Common::Point &p) const;
48 bool shouldStepVerticalMotion() const;
49 bool isAnimationMirrored() const;
50 // Returns false if we are at the end of the path already or the path is not valid
51 bool walkAlongPath();
52 void startLerpTo(const Common::Point &target, uint32 duration, bool ignoreObstacles = false);
53 bool isWalkable(const Common::Point &p) const;
54
55public:
56 Character();
57
58 // Frame counter for pickup animation (runtime+0x215).
59 // Increments each frame while orientation == 0x11.
60 // At _pickupFrameStart: item is transferred to inventory.
61 // At _pickupFrameEnd: animation ends, orientation restored.
62 uint16 _pickupFrameCounter = 0;
63 bool _pickupItemTransferred = false;
64 bool _markedForDeletion = false;
65
66 ObjectOrientation _previousOrientation = OrientationNone;
67
68 // Walk state from walkAlongPath (1008:1b8f) - runtime offsets +0x00..+0x0A, +0x18, +0x33
69 Common::Point _targetPosition; // runtime[+0x00, +0x02]: next waypoint
70 int16 _stepDeltaX = 0; // runtime[+0x04]: abs(endX - startX)
71 int16 _stepDeltaY = 0; // runtime[+0x06]: abs(endY - startY)
72 int16 _stepError = 0; // runtime[+0x18]: Bresenham error accumulator
73 bool _stepDirectionSet = false; // runtime[+0x33]: direction has been calculated
74
76 int16 _currentPathIndex = 0;
77 Common::Point _pathFinalDestination;
78 Common::Array<uint8> _pathfindingOverlay;
79
80 Macs2::GameObject *_gameObject = nullptr;
81 uint16 _motionTargetVerticalOffset = 0;
82 uint16 _motionVerticalOffsetDelta = 0;
83 uint16 _motionDistanceUnits = 0;
84 uint16 _motionProgress = 0;
85 uint16 _motionStartVerticalOffset = 0;
86
87 bool calculatePath(Common::Point target);
88 void setWalkTarget(const Common::Point &target, bool snap);
89 void startPickup(Macs2::GameObject *object);
92
93 const Common::Point &getPosition() const;
94 void setPosition(const Common::Point &newPosition);
95
96 uint16 getVerticalOffset() const;
97 bool hasPendingVerticalMotion() const;
98 bool fillCurrentAnimationFrame(uint16 advanceMode, Macs2::AnimFrame &out) const;
99 Macs2::AnimFrame *getCurrentPortrait(bool onRightSide = false, uint16 frameIndex = 0);
100
101 void update();
102};
103
104void resetCharacterWalkPath(Character *character);
105
106} // namespace Macs2
107
108#endif
Definition: character.h:33
void getPathPolyline(Common::Array< Common::Point > &out) const
Definition: gameobjects.h:107
Definition: rect.h:144
Definition: macs2.h:104