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 TWINE_SCENE_ACTOR_H
23 #define TWINE_SCENE_ACTOR_H
24 
25 #include "common/scummsys.h"
26 #include "twine/parser/anim.h"
27 #include "twine/parser/body.h"
28 #include "twine/parser/entity.h"
29 #include "twine/shared.h"
30 
31 namespace TwinE {
32 
34 #define NUM_SPRITES 425 // 200 for lba1
35 
37 #define NUM_BODIES 469 // 131 for lba1
38 
41  int16 startValue = 0;
42  int16 endValue = 0;
43  int16 timeValue = 0;
44  int32 memoTicks = 0;
45 
50  int16 getRealValueFromTime(int32 time);
51  int16 getRealAngle(int32 time);
52 };
53 
56  const KeyFrame *ptr = nullptr;
57  int32 time = 0;
58 };
59 
62  uint32 bComputeCollisionWithObj : 1; // 0x000001 CHECK_OBJ_COL
63  uint32 bComputeCollisionWithBricks : 1; // 0x000002 CHECK_BRICK_COL
64  uint32 bIsZonable : 1; // 0x000004 CHECK_ZONE - testing of scenaric areas
65  uint32 bUsesClipping : 1; // 0x000008 SPRITE_CLIP - (doors) fixed clip area
66  uint32 bCanBePushed : 1; // 0x000010 PUSHABLE
67  uint32 bComputeLowCollision : 1; // 0x000020 COL_BASSE
68  uint32 bCanDrown : 1; // 0x000040 CHECK_CODE_JEU
69  uint32 bComputeCollisionWithFloor : 1; // 0x000080 CHECK_WATER_COL
70  uint32 bUnk0100 : 1; // 0x000100
71  uint32 bIsHidden : 1; // 0x000200 INVISIBLE - not drawn but all computed
72  uint32 bIsSpriteActor : 1; // 0x000400 SPRITE_3D - a sprite not a 3D object
73  uint32 bCanFall : 1; // 0x000800 OBJ_FALLABLE
74  uint32 bDoesntCastShadow : 1; // 0x001000 NO_SHADOW - no auto shadow
75  uint32 bIsBackgrounded : 1; // 0x002000 OBJ_BACKGROUND - is embedded in the decor the 1st time
76  uint32 bIsCarrierActor : 1; // 0x004000 OBJ_CARRIER - can carry and move an obj
77  // take smaller value for bound, or if not set take average for bound
78  uint32 bUseMiniZv : 1; // 0x008000 MINI_ZV - square on smaller dimension (if 3D object)
79  uint32 bHasInvalidPosition : 1; // 0x010000
80  uint32 bNoElectricShock : 1; // 0x020000
81  uint32 bHasSpriteAnim3D : 1; // 0x040000
82  uint32 bNoPreClipping : 1; // 0x080000
83  uint32 bHasZBuffer : 1; // 0x100000
84  uint32 bHasZBufferInWater : 1; // 0x200000
85 };
86 
89  uint32 bWaitHitFrame : 1; // 0x0001 WAIT_HIT_FRAME - wait for hit frame
90  uint32 bIsHitting : 1; // 0x0002 OK_HIT - hit frame anim
91  uint32 bAnimEnded : 1; // 0x0004 ANIM_END - anim ended in the current loop (will be looped in the next engine loop)
92  uint32 bAnimNewFrame : 1; // 0x0008 NEW_FRAME - new frame anim reached
93  uint32 bIsDrawn : 1; // 0x0010 WAS_DRAWN - actor has been drawn in this loop
94  uint32 bIsDead : 1; // 0x0020 OBJ_DEAD - is dead
95  uint32 bIsSpriteMoving : 1; // 0x0040 AUTO_STOP_DOOR - door is opening or closing (wait to reach the destination position)
96  uint32 bIsRotationByAnim : 1; // 0x0080 ANIM_MASTER_ROT - actor rotation is managed by its animation not by the engine
97  uint32 bIsFalling : 1; // 0x0100 FALLING - is falling on scene
98  uint32 bIsTargetable : 1; // 0x0200 OK_SUPER_HIT (lba2)
99  uint32 bIsBlinking : 1; // 0x0400 FRAME_SHIELD (lba2)
100  uint32 bWasWalkingBeforeFalling : 1; // 0x0800 DRAW_SHADOW (lba2) - bWasWalkingBeforeFalling in lba1
101  uint32 bUnk1000 : 1; // 0x1000 ANIM_MASTER_GRAVITY (lba2)
102  uint32 bUnk2000 : 1; // 0x2000 SKATING (lba2) Ouch! I slip in a forbidden collision
103  uint32 bUnk4000 : 1; // 0x4000 OK_RENVOIE (lba2) ready to send back a projectile
104  uint32 bUnk8000 : 1; // 0x8000 LEFT_JUMP (lba2) ready to jump from the left foot
105  uint32 bRIGHT_JUMP : 1; // RIGHT_JUMP (1<<16) // (lba2) ready to jump from the right foot
106  uint32 bWAIT_SUPER_HIT : 1; // WAIT_SUPER_HIT (1<<17) // (lba2) waiting for the end of the animation before giving another super hit
107  uint32 bTRACK_MASTER_ROT : 1; // TRACK_MASTER_ROT (1<<18) // (lba2) it's the track that manages the direction
108  uint32 bFLY_JETPACK : 1; // FLY_JETPACK (1<<19) // (lba2) flying with the Jetpack
109  uint32 bDONT_PICK_CODE_JEU : 1; // DONT_PICK_CODE_JEU (1<<20) // (lba2) Cheat - Conveyor Belt Zones
110  uint32 bMANUAL_INTER_FRAME : 1; // MANUAL_INTER_FRAME (1<<21) // (lba2) Manually performs the ObjectSetInterFrame()
111  uint32 bWAIT_COORD : 1; // WAIT_COORD (1<<22) // (lba2) waiting to have been displayed to pass the coordinates from one point to an extra
112  uint32 bCHECK_FALLING : 1; // CHECK_FALLING (1<<23) // (lba2) forces object to test FALLING during a frame
113 };
114 
126  uint16 givenNothing : 1;
127  uint16 unk2 : 1; // unused in lba1
128  uint16 unk3 : 1; // unused in lba1
129  uint16 unk4 : 1; // unused in lba1
130  uint16 kashes : 1;
131  uint16 lifepoints : 1;
132  uint16 magicpoints : 1;
133  uint16 key : 1;
134  uint16 cloverleaf : 1;
135  uint16 unused : 7;
136 };
137 
138 #define kActorMaxLife 50
139 
145 class ActorStruct {
146 private:
147  ShapeType _col = ShapeType::kNone; // collision
148  bool _brickCausesDamage = false;
149 
150  EntityData _entityData;
151 
152 public:
153  StaticFlagsStruct _staticFlags;
154  DynamicFlagsStruct _workFlags;
155 
156  inline ShapeType brickShape() const { return _col; }
157  inline void setCollision(ShapeType shapeType) {
158  _col = shapeType;
159  _brickCausesDamage = false;
160  }
161  inline void setBrickCausesDamage() { _brickCausesDamage = true; }
162  inline bool brickCausesDamage() { return _brickCausesDamage; }
163  void loadModel(int32 modelIndex, bool lba1);
164 
165  void addLife(int32 val);
166 
167  void setLife(int32 val);
168 
169  bool isAttackWeaponAnimationActive() const;
170  bool isAttackAnimationActive() const;
171  bool isJumpAnimationActive() const;
172 
173  const IVec3 &posObj() const;
174 
175  int32 _body = -1; // costumeIndex - index into bodyTable
176  BodyType _genBody = BodyType::btNormal;
177  BodyType _saveGenBody = BodyType::btNormal; // lba2
178  AnimationTypes _genAnim = AnimationTypes::kAnimNone;
179  AnimationTypes _nextGenAnim = AnimationTypes::kStanding;
180  AnimationTypes _ptrAnimAction = AnimationTypes::kAnimNone;
181  int32 _sprite = 0;
182  EntityData *_entityDataPtr = nullptr;
183 
184  int16 _actorIdx = 0; // own actor index
185  IVec3 _pos; // PosObjX, PosObjY, PosObjZ
186  int32 _strengthOfHit = 0;
187  int32 _hitBy = -1;
188  BonusParameter _bonusParameter;
189  int32 _beta = 0; // facing angle of actor. Minumum is 0 (SW). Going counter clock wise (BETA in original sources)
190  int32 _speed = 40; // SRot - speed of movement
191  ControlMode _controlMode = ControlMode::kNoMove;
192  int32 _delayInMillis = 0;
193  int32 _cropLeft = 0; // Info
194  int32 _cropTop = 0; // Info1
195  int32 _cropRight = 0; // Info2
196  int32 _cropBottom = 0; // Info3
197  int32 _followedActor = 0; // same as info3
198  int32 _bonusAmount = 0;
199  int32 _talkColor = COLOR_BLACK;
200  int32 _armor = 1;
201  int32 _lifePoint = kActorMaxLife;
202 
205  IVec3 _oldPos; // OldPosX, OldPosY, OldPosZ
206 
207  int32 _offsetTrack = -1;
208  uint8 *_ptrTrack = nullptr;
209  int32 _moveScriptSize = 0;
210 
211  int32 _offsetLife = 0;
212  int32 _saveOffsetLife = 0; // lba2
213  uint8 *_lifeScript = nullptr;
214  int32 _lifeScriptSize = 0;
215 
216  int32 _labelTrack = 0; // script label index
217  int32 _offsetLabelTrack = 0; // pointer to LABEL offset
218  int32 _memoLabelTrack = 0;
219 
223  int32 _objCol = -1; // ObjCol
227  int32 _carryBy = -1;
228  int32 _zoneSce = -1;
229 
230  int32 _animStepBeta = 0;
231  IVec3 _animStep;
232  int32 _anim = -1;
233  int32 _doorWidth = 0;
234  int32 _frame = 0;
235  AnimType _flagAnim = AnimType::kAnimationTypeRepeat;
236  int32 _spriteActorRotation = 0;
237  uint8 _brickSound = 0U; // CodeJeu
238 
239  BoundingBox _boundingBox; // Xmin, YMin, Zmin, Xmax, Ymax, Zmax
240  ActorMoveStruct realAngle;
241  AnimTimerDataStruct _animTimerData;
242 };
243 
244 inline const IVec3 &ActorStruct::posObj() const {
245  return _pos;
246 }
247 
248 inline void ActorStruct::addLife(int32 val) {
249  setLife(_lifePoint + val);
250 }
251 
252 inline void ActorStruct::setLife(int32 val) {
253  _lifePoint = val;
254  if (_lifePoint > kActorMaxLife) {
255  _lifePoint = kActorMaxLife;
256  }
257 }
258 
259 class TwinEEngine;
260 
261 class Actor {
262 private:
263  TwinEEngine *_engine;
264 
266  EntityData _heroEntityNORMAL;
268  EntityData _heroEntityATHLETIC;
270  EntityData _heroEntityAGGRESSIVE;
272  EntityData _heroEntityDISCRETE;
274  EntityData _heroEntityPROTOPACK;
275 
281  int32 searchBody(BodyType bodyIdx, int32 actorIdx, ActorBoundingBox &actorBoundingBox);
282 
283  void loadBehaviourEntity(ActorStruct *actor, EntityData &entityData, int16 &bodyAnimIndex, int32 index);
284 
285  void copyInterAnim(const BodyData &src, BodyData &dest);
286 
287 public:
288  Actor(TwinEEngine *engine);
289 
290  HeroBehaviourType _heroBehaviour = HeroBehaviourType::kNormal; // Comportement
291  HeroBehaviourType _saveHeroBehaviour = HeroBehaviourType::kNormal; // SaveComportementHero (lba2)
293  bool _combatAuto = true;
295  HeroBehaviourType _previousHeroBehaviour = HeroBehaviourType::kNormal;
297  int16 _previousHeroAngle = 0;
298 
299  int16 _cropBottomScreen = 0; // TODO: usage differ in original sources
300 
302  int16 _heroAnimIdxNORMAL = 0;
304  int16 _heroAnimIdxATHLETIC = 0;
306  int16 _heroAnimIdxAGGRESSIVE = 0;
308  int16 _heroAnimIdxDISCRETE = 0;
310  int16 _heroAnimIdxPROTOPACK = 0;
311 
313  int16 _heroAnimIdx[4];
314 
315  void initSpriteActor(int32 actorIdx);
316 
318  void restartHeroScene();
319 
321  void loadHeroEntities();
322 
323  TextId getTextIdForBehaviour() const;
324 
329  void setBehaviour(HeroBehaviourType behaviour);
330 
336  void initBody(BodyType bodyIdx, int16 actorIdx);
337 
342  void startInitObj(int16 actorIdx);
343 
348  void initObject(int16 actorIdx);
349 
357  void hitObj(int32 actorIdx, int32 actorIdxAttacked, int32 strengthOfHit, int32 angle);
358 
360  void processActorCarrier(int32 actorIdx);
361 
363  void giveExtraBonus(int32 actorIdx);
364 };
365 
366 } // namespace TwinE
367 
368 #endif
int16 getRealValueFromTime(int32 time)
Definition: actor.h:145
Definition: actor.h:261
Definition: shared.h:113
Definition: actor.h:55
Definition: actor.h:125
Definition: actor.h:61
Associate 3d models from body hqr with animations from anim.hqr for the game characters.
Definition: entity.h:69
Definition: twine.h:200
Definition: achievements_tables.h:27
Definition: actor.h:40
Axis aligned bounding box.
Definition: shared.h:179
Definition: anim.h:45
Definition: actor.h:88
IVec3 _processActor
Definition: actor.h:204
Definition: shared.h:184
Definition: body.h:35