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 
23 #ifndef BLADERUNNER_ACTOR_H
24 #define BLADERUNNER_ACTOR_H
25 
26 #include "bladerunner/boundingbox.h"
27 #include "bladerunner/vector.h"
28 
29 #include "common/array.h"
30 #include "common/rect.h"
31 
32 namespace BladeRunner {
33 
34 class ActorClues;
35 class ActorCombat;
36 class ActorWalk;
37 class BladeRunnerEngine;
38 class BoundingBox;
39 class MovementTrack;
40 class SaveFileReadStream;
41 class SaveFileWriteStream;
42 class View;
43 
44 class Actor {
45 	BladeRunnerEngine *_vm;
46 
47 	static const int kActorTimers = 7;
48 
49 public:
50 	BoundingBox    _bbox;
51 	Common::Rect   _screenRectangle;
52 	MovementTrack *_movementTrack;
53 	ActorWalk     *_walkInfo;
54 	ActorCombat   *_combatInfo;
55 	ActorClues    *_clues;
56 
57 private:
58 	int                _honesty;
59 	int                _intelligence;
60 	int                _stability;
61 	int                _combatAggressiveness;
62 	int                _goalNumber;
63 	Common::Array<int> _friendlinessToOther;
64 
65 	int _currentHP;
66 	int _maxHP;
67 
68 	int     _id;
69 	int     _setId;
70 	Vector3 _position;
71 	int     _facing; // [0, 1024)
72 	int     _targetFacing;
73 	int     _walkboxId;
74 
75 	int     _cluesLimit;
76 	uint32  _timer4RemainDefault;
77 
78 	// Flags
79 	bool _isTarget;
80 	bool _isInvisible;
81 	bool _isImmuneToObstacles;
82 	bool _mustReachWalkDestination;
83 	bool _isRetired;
84 	bool _inCombat;
85 	bool _isMoving;
86 	bool _damageAnimIfMoving;
87 
88 	// Movement
89 	bool   _movementTrackPaused;
90 	int    _movementTrackNextWaypointId;
91 	int32  _movementTrackNextDelay;  // probably not used
92 	int    _movementTrackNextAngle;  // fixed: used for AI_Movement_Track_Append_With_Facing - original: probably not used
93 	bool   _movementTrackNextRunning;
94 
95 	int    _movementTrackWalkingToWaypointId;
96 	int32  _movementTrackDelayOnNextWaypoint;
97 
98 	// Animation
99 	int _width;
100 	int _height;
101 	int _animationMode;
102 	int _animationModeCombatIdle;
103 	int _animationModeCombatWalk;
104 	int _animationModeCombatRun;
105 	int _fps;
106 	int _frameMs;
107 	int _animationId;
108 	int _animationFrame;
109 
110 	int _retiredWidth;
111 	int _retiredHeight;
112 
113 	int32 _timersLeft[kActorTimers];  // this keeps time difference, and it is stored during save() (saveInt actually saves a uint32)
114 	uint32 _timersLast[kActorTimers]; // this keeps actual time, and is not stored during save(), so it can be a uint32
115 
116 	float _scale;
117 
118 	Vector3 _actorSpeed;
119 
120 	int _sitcomRatio;
121 
122 public:
123 	Actor(BladeRunnerEngine *_vm, int actorId);
124 	~Actor();
125 
126 	void setup(int actorId);
127 
128 	void setAtXYZ(const Vector3 &pos, int facing, bool setFacing = true, bool moving = false, bool retired = false);
129 	void setAtWaypoint(int waypointId, int angle, bool moving, bool retired);
130 
getId()131 	int  getId() const { return _id; };
132 	float getX() const;
133 	float getY() const;
134 	float getZ() const;
135 	Vector3 getXYZ() const;
136 	int getFacing() const;
137 	int getAnimationMode() const;
138 	int getAnimationId() const;
139 
getPosition()140 	Vector3 getPosition() const { return _position; }
141 
142 	void changeAnimationMode(int animationMode, bool force = false);
143 	int  getFPS() const;
144 	void setFPS(int fps);
145 	void increaseFPS();
146 
147 	void   timerStart(int timerId, int32 intervalMillis);
148 	void   timerReset(int timerId);
149 	int32 timerLeft(int timerId);
150 	void   timersUpdate();
151 	void   timerUpdate(int timerId);
152 
153 	void movementTrackNext(bool omitAiScript);
154 	void movementTrackPause();
155 	void movementTrackUnpause();
156 	void movementTrackWaypointReached();
157 
158 	bool loopWalk(const Vector3 &destination, int proximity, bool interruptible, bool runFlag, const Vector3 &start, float targetWidth, float targetSize, bool mustReach, bool *isRunningFlag, bool async);
159 	bool walkTo(bool runFlag, const Vector3 &destination, bool mustReach);
160 	bool loopWalkToActor(int otherActorId, int proximity, int interruptible, bool runFlag, bool mustReach, bool *isRunningFlag);
161 	bool loopWalkToItem(int itemId, int proximity, int interruptible, bool runFlag, bool mustReach, bool *isRunningFlag);
162 	bool loopWalkToSceneObject(const Common::String &objectName, int proximity, bool interruptible, bool runFlag, bool mustReach, bool *isRunningFlag);
163 	bool loopWalkToWaypoint(int waypointId, int proximity, int interruptible, bool runFlag, bool mustReach, bool *isRunningFlag);
164 	bool loopWalkToXYZ(const Vector3 &destination, int proximity, bool interruptible, bool runFlag, bool mustReach, bool *isRunningFlag);
165 	bool asyncWalkToWaypoint(int waypointId, int proximity, bool runFlag, bool mustReach);
166 	void asyncWalkToXYZ(const Vector3 &destination, int proximity, bool runFlag, bool mustReach);
167 	void run();
168 
169 	bool tick(bool forceUpdate, Common::Rect *screenRect);
170 	void tickCombat();
171 	bool draw(Common::Rect *screenRect);
172 
173 	void resetScreenRectangleAndBbox();
174 
175 	int getSetId()  const;
176 	void setSetId(int setId);
getBoundingBox()177 	const BoundingBox &getBoundingBox() const { return _bbox; }
getScreenRectangle()178 	const Common::Rect &getScreenRectangle() { return _screenRectangle; }
getWalkbox()179 	int getWalkbox() const { return _walkboxId; }
180 
isRetired()181 	bool isRetired() const { return _isRetired; }
isTarget()182 	bool isTarget() const { return _isTarget; }
183 	void setTarget(bool targetable);
isImmuneToObstacles()184 	bool isImmuneToObstacles() const { return _isImmuneToObstacles; }
inCombat()185 	bool inCombat() const { return _inCombat; }
186 
isMoving()187 	bool isMoving() const { return _isMoving; }
setMoving(bool value)188 	void setMoving(bool value) { _isMoving = value; }
189 
mustReachWalkDestination()190 	bool mustReachWalkDestination() const { return _mustReachWalkDestination; }
191 	bool isWalking() const;
192 	bool isRunning() const;
193 	void stopWalking(bool value);
194 
195 	void faceActor(int otherActorId, bool animate);
196 	void faceObject(const Common::String &objectName, bool animate);
197 	void faceItem(int itemId, bool animate);
198 	void faceWaypoint(int waypointId, bool animate);
199 	void faceXYZ(float x, float y, float z, bool animate);
200 	void faceXYZ(const Vector3 &pos, bool animate);
201 	void faceCurrentCamera(bool animate);
202 	void faceHeading(int heading, bool animate);
203 	void setFacing(int facing, bool halfOrSet = true);
204 
getCurrentHP()205 	int getCurrentHP() const { return _currentHP; }
getMaxHP()206 	int getMaxHP() const { return _maxHP; }
207 	void setCurrentHP(int hp);
208 	void setHealth(int hp, int maxHp);
209 	void modifyCurrentHP(signed int change);
210 	void modifyMaxHP(signed int change);
211 
getFriendlinessToOther(int otherActorId)212 	int getFriendlinessToOther(int otherActorId) const { return _friendlinessToOther[otherActorId]; }
213 	void setFriendlinessToOther(int otherActorId, int friendliness);
214 	void modifyFriendlinessToOther(int otherActorId, signed int change);
215 	bool checkFriendlinessAndHonesty(int otherActorId);
216 
getHonesty()217 	int getHonesty() const { return _honesty; }
218 	void setHonesty(int honesty);
219 	void modifyHonesty(signed int change);
220 
getIntelligence()221 	int getIntelligence() const { return _intelligence; }
222 	void setIntelligence(int intelligence);
223 	void modifyIntelligence(signed int change);
224 
getStability()225 	int getStability() const { return _stability; }
226 	void setStability(int stability);
227 	void modifyStability(signed int change);
228 
getCombatAggressiveness()229 	int getCombatAggressiveness() const { return _combatAggressiveness; }
230 	void setCombatAggressiveness(int combatAggressiveness);
231 	void modifyCombatAggressiveness(signed int change);
232 
233 	void setInvisible(bool isInvisible);
234 	void setImmunityToObstacles(bool isImmune);
235 
236 	void setFlagDamageAnimIfMoving(bool value);
237 	bool getFlagDamageAnimIfMoving() const;
238 
239 	int getSitcomRatio() const;
240 
241 	void retire(bool isRetired, int width, int height, int retiredByActorId);
242 
243 	void combatModeOn(int initialState, bool rangedAttack, int enemyId, int waypointType, int animationModeCombatIdle, int animationModeCombatWalk, int animationModeCombatRun, int fleeRatio, int coverRatio, int attackRatio, int damage, int range, bool unstoppable);
244 	void combatModeOff();
245 
246 	void setGoal(int goalNumber);
247 	int getGoal() const;
248 
249 	float distanceFromActor(int otherActorId);
250 	int angleTo(const Vector3 &target) const;
251 
252 	void speechPlay(int sentenceId, bool voiceOver);
253 	void speechStop();
254 	bool isSpeeching();
255 
256 	void addClueToDatabase(int clueId, int unknown, bool clueAcquired, bool unknownFlag, int fromActorId);
257 	bool canAcquireClue(int clueId) const;
258 	void acquireClue(int clueId, bool unknownFlag, int fromActorId);
259 	void loseClue(int clueId);
260 	bool hasClue(int clueId) const;
261 	bool copyClues(int actorId);
262 	void acquireCluesByRelations();
263 
264 	int soundVolume() const;
265 	int soundPan(uint8 overrideRange = 35) const;
266 
267 	bool isObstacleBetween(const Vector3 &target);
268 
269 	void save(SaveFileWriteStream &f);
270 	void load(SaveFileReadStream &f);
271 
272 	static int findTargetUnderMouse(BladeRunnerEngine *vm, int mouseX, int mouseY);
273 
274 private:
275 	void setBoundingBox(const Vector3 &position, bool retired);
276 	float distanceFromView(View *view) const;
277 
278 	bool findEmptyPositionAround(const Vector3 &startPosition, const Vector3 &targetPosition, float size, Vector3 *emptyPosition);
279 	bool findNearestPosition(Vector3 *nearestPosition, float targetWidth, int proximity, float targetSize, const Vector3 &startPosition, const Vector3 &targetPosition);
280 	bool stepAway(const Vector3 &destination, float distance);
281 	//bool walkFindU3(int actorId, Vector3 from, int distance, Vector3 *out);
282 };
283 
284 } // End of namespace BladeRunner
285 
286 #endif
287