ScummVM API documentation
motion.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 NGI_MOTION_H
23 #define NGI_MOTION_H
24 
25 #include "ngi/anihandler.h"
26 
27 namespace NGI {
28 
29 class MctlConnectionPoint;
30 class MovGraphLink;
31 class MessageQueue;
32 struct MovArr;
33 struct MovItem;
34 
35 int startWalkTo(int objId, int objKey, int x, int y, int a5);
36 bool doSomeAnimation(int objId, int objKey, int a3);
37 bool doSomeAnimation2(int objId, int objKey);
38 
39 class MotionController : public CObject {
40 public:
41  int _field_4;
42  bool _isEnabled;
43 
44 public:
45  MotionController() : _isEnabled(true), _field_4(0) {}
46  ~MotionController() override {}
47  bool load(MfcArchive &file) override;
48  virtual void methodC() {}
49  virtual void method10() {}
50  virtual void deactivate() { _isEnabled = false; }
51  virtual void activate() { _isEnabled = true; }
52  virtual void attachObject(StaticANIObject *obj) {}
53  virtual int detachObject(StaticANIObject *obj) { return 0; }
54  virtual void detachAllObjects() {}
55  virtual Common::Array<MovItem *> *getPaths(StaticANIObject *ani, int x, int y, int flag1, int *rescount) { return 0; }
56  virtual bool setPosImmediate(StaticANIObject *obj, int x, int y) { return false; }
57  virtual int method30() { return 0; }
58  virtual MessageQueue *startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { return 0; }
59  virtual void setSelFunc(MovArr *(*_callback1)(StaticANIObject *ani, Common::Array<MovItem *> *items, signed int counter)) {}
60  virtual bool resetPosition(StaticANIObject *ani, int flag) { return 0; }
61  virtual int method40() { return 0; }
62  virtual bool canDropInventory(StaticANIObject *ani, int x, int y) { return false; }
63  virtual int method48() { return -1; }
64  virtual MessageQueue *makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { return 0; }
65 
66  void enableLinks(const char *linkName, bool enable);
67  MovGraphLink *getLinkByName(const char *name);
68 };
69 
70 class MovGraphReact : public CObject {
71 public:
72  PointList _points;
73 
74 public:
75  virtual void setCenter(int x1, int y1, int x2, int y2) {}
76  virtual void createRegion() {}
77  virtual bool pointInRegion(int x, int y);
78 };
79 
80 class MctlItem : public CObject {
81 public:
82  Common::ScopedPtr<MotionController> _motionControllerObj;
83  Common::ScopedPtr<MovGraphReact> _movGraphReactObj;
84  Common::Array<MctlConnectionPoint *> _connectionPoints;
85  int _field_20;
86  int _field_24;
87  int _field_28;
88 
89 public:
90  MctlItem() : _field_20(0), _field_24(0), _field_28(0) {}
91  ~MctlItem() override;
92 };
93 
95 public:
98 
99  MctlCompound() { _objtype = kObjTypeMctlCompound; }
100  ~MctlCompound() override;
101 
102  bool load(MfcArchive &file) override;
103 
104  void attachObject(StaticANIObject *obj) override;
105  int detachObject(StaticANIObject *obj) override;
106  void detachAllObjects() override;
107  MessageQueue *startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
108  MessageQueue *makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
109 
110  void initMctlGraph();
111  MctlConnectionPoint *findClosestConnectionPoint(int ox, int oy, int destIndex, int connectionX, int connectionY, int sourceIndex, double *minDistancePtr);
112  void replaceNodeX(int from, int to);
113 
114  uint getMotionControllerCount() { return _motionControllers.size(); }
115  MotionController *getMotionController(int num) { return _motionControllers[num]->_motionControllerObj.get(); }
116 };
117 
119  int varUpGo;
120  int varDownGo;
121  int varUpStop;
122  int varDownStop;
123  int varUpStart;
124  int varDownStart;
125 };
126 
128  int objId;
129  int staticIdsSize;
130  MctlLadderMovementVars *movVars;
131  int *staticIds;
132 };
133 
134 class MctlLadder : public MotionController {
135 public:
136  int _ladderX;
137  int _ladderY;
138  int _ladder_field_14;
139  int _width;
140  int _height;
141  int _ladder_field_20;
142  int _ladder_field_24;
144  AniHandler _aniHandler;
145 
146 public:
147  MctlLadder();
148  ~MctlLadder() override;
149  int collisionDetection(StaticANIObject *man);
150 
151  void attachObject(StaticANIObject *obj) override;
152  int detachObject(StaticANIObject *obj) override { return 1; }
153  void detachAllObjects() override;
154  MessageQueue *startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
155  MessageQueue *makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
156 
157  MessageQueue *controllerWalkTo(StaticANIObject *ani, int off);
158 
159 private:
160  int findObjectPos(StaticANIObject *obj);
161  bool initMovement(StaticANIObject *ani, MctlLadderMovement *movement);
162 };
163 
164 class MovGraphNode : public CObject {
165 public:
166  int _x;
167  int _y;
168  int _z;
169  int16 _field_10;
170  int _field_14;
171 
172 public:
173  MovGraphNode() : _x(0), _y(0), _z(0), _field_10(0), _field_14(0) { _objtype = kObjTypeMovGraphNode; }
174  bool load(MfcArchive &file) override;
175 };
176 
177 class ReactParallel : public MovGraphReact {
178  //CRgn _rgn;
179  int _x1;
180  int _y1;
181  int _x2;
182  int _y2;
183  int _dx;
184  int _dy;
185 
186 public:
187  ReactParallel();
188  bool load(MfcArchive &file) override;
189 
190  void setCenter(int x1, int y1, int x2, int y2) override;
191  void createRegion() override;
192 };
193 
195  Common::Rect _bbox;
196  int _centerX;
197  int _centerY;
198 
199 public:
200  ReactPolygonal();
201 
202  bool load(MfcArchive &file) override;
203 
204  void setCenter(int x1, int y1, int x2, int y2) override;
205  void createRegion() override;
206 
207  Common::Rect getBBox();
208 };
209 
210 class MovGraphLink : public CObject {
211  public:
212  MovGraphNode *_graphSrc;
213  MovGraphNode *_graphDst;
214  DWordArray _dwordArray1;
215  DWordArray _dwordArray2;
216  uint32 _flags;
217  int _field_38;
218  int _field_3C;
219  double _length;
220  double _angle;
221  MovGraphReact *_movGraphReact;
222  Common::String _name;
223 
224  public:
225  MovGraphLink();
226  ~MovGraphLink() override;
227 
228  bool load(MfcArchive &file) override;
229 
230  void recalcLength();
231 };
233 
234 struct MovStep {
235  int sfield_0;
236  MovGraphLink *link;
237 };
238 
239 struct MovArr {
240  Common::Array<MovStep *> _movSteps;
241  int _movStepCount;
242  int _afield_8;
243  MovGraphLink *_link;
244  double _dist;
245  Common::Point _point;
246 };
247 
248 struct MovItem {
249  MovArr *movarr;
250  int _mfield_4;
251  int _mfield_8;
252  int _mfield_C;
253 };
254 
255 struct MovGraphItem {
256  StaticANIObject *ani;
257  int field_4;
258  MovArr movarr;
259  Common::Array<MovItem *> *mi_movitems;
260  int count;
261  int field_30;
262  int field_34;
263  int field_38;
264  int field_3C;
265 
266  MovGraphItem();
267  void free();
268 };
269 
270 class MovGraph : public MotionController {
271 friend class MctlCompound;
272 friend class MctlGraph;
273 friend class MotionController;
274 private:
277  NodeList _nodes;
278  LinkList _links;
279  int _field_44;
281  MovArr *(*_callback1)(StaticANIObject *ani, Common::Array<MovItem *> *items, signed int counter);
282  AniHandler _aniHandler;
283 
284 public:
285  MovGraph();
286  ~MovGraph() override;
287 
288  static int messageHandler(ExCommand *cmd);
289 
290  bool load(MfcArchive &file) override;
291 
292  void attachObject(StaticANIObject *obj) override;
293  int detachObject(StaticANIObject *obj) override;
294  void detachAllObjects() override;
295  Common::Array<MovItem *> *getPaths(StaticANIObject *ani, int x, int y, int flag1, int *rescount) override;
296  bool setPosImmediate(StaticANIObject *obj, int x, int y) override;
297  MessageQueue *startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
298  void setSelFunc(MovArr *(*_callback1)(StaticANIObject *ani, Common::Array<MovItem *> *items, signed int counter)) override;
299  bool resetPosition(StaticANIObject *ani, int flag) override;
300  bool canDropInventory(StaticANIObject *ani, int x, int y) override;
301  MessageQueue *makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
302  virtual MessageQueue *method50(StaticANIObject *ani, MovArr *movarr, int staticsId);
303 
304  double putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMatch);
305  void recalcLinkParams();
306  bool getNearestPoint(int unusedArg, Common::Point *p, MovArr *movarr);
307  MovGraphNode *calcOffset(int ox, int oy);
308  int getObjectIndex(StaticANIObject *ani);
309  Common::Array<MovArr *> *getHitPoints(int x, int y, int *arrSize, int flag1, int flag2);
310  void findAllPaths(MovGraphLink *lnk, MovGraphLink *lnk2, MovGraphLinkList &tempObList1, MovGraphLinkList &tempObList2);
311  Common::Array<MovItem *> *getPaths(MovArr *movarr1, MovArr *movarr2, int *listCount);
312  void genMovItem(MovItem *movitem, MovGraphLink *grlink, MovArr *movarr1, MovArr *movarr2);
313  bool getHitPoint(int idx, int x, int y, MovArr *arr, int a6);
314  MessageQueue *sub1(StaticANIObject *ani, int x, int y, int a5, int x1, int y1, int a8, int a9);
315  MessageQueue *makeWholeQueue(StaticANIObject *ani, MovArr *movarr, int staticsId);
316  void setEnds(MovStep *step1, MovStep *step2);
317 };
318 
319 class Movement;
320 
321 struct MG2I {
322  int _movementId;
323  Movement *_mov;
324  int _mx;
325  int _my;
326 };
327 
328 struct MctlAniSub {
329  int _staticsId2;
330  int _staticsId1;
331  MG2I _walk[3];
332  MG2I _turn[4];
333  MG2I _turnS[4];
334 };
335 
336 struct LinkInfo {
337  MovGraphLink *link;
338  MovGraphNode *node;
339 };
340 
341 struct MctlMQSub {
342  int subIndex;
343  int x;
344  int y;
345  int distance;
346 };
347 
348 struct MctlMQ {
349  int index;
350  Common::Point pt1;
351  Common::Point pt2;
352  int distance1;
353  int distance2;
354  int subIndex;
355  int item1Index;
357  int flags;
358 
359  MctlMQ() { clear(); }
360  void clear();
361 };
362 
363 struct MctlAni { // 744
364  int _objectId;
365  StaticANIObject *_obj;
366  MctlAniSub _subItems[4]; // 184
367 };
368 
369 class MctlGraph : public MovGraph {
370 public:
371  Common::Array<MctlAni> _items2;
372 
373 public:
374  void attachObject(StaticANIObject *obj) override;
375  int detachObject(StaticANIObject *obj) override;
376  void detachAllObjects() override;
377  MessageQueue *startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
378  MessageQueue *makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
379 
380  int getObjIndex(int objectId);
381  int getDirByStatics(int index, int staticsId);
382  int getDirByMovement(int index, int movId);
383  int getDirByPoint(int idx, StaticANIObject *ani);
384 
385  int getDirBySize(MovGraphLink *lnk, int x, int y);
386  int getLinkDir(MovGraphLinkList *linkList, int idx, Common::Rect *a3, Common::Point *a4);
387 
388  bool fillData(StaticANIObject *obj, MctlAni &item);
389  void generateList(MctlMQ &movinfo, MovGraphLinkList *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst);
390  MessageQueue *makeWholeQueue(MctlMQ &mctlMQ);
391 
392  MovGraphNode *getHitNode(int x, int y, int strictMatch);
393  MovGraphLink *getHitLink(int x, int y, int idx, int fuzzyMatch);
394  MovGraphLink *getNearestLink(int x, int y);
395  double iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, MovGraphLinkList *listObj);
396 
397  MessageQueue *makeLineQueue(MctlMQ *movinfo);
398 };
399 
400 class MctlConnectionPoint : public CObject {
401 public:
402  int _connectionX;
403  int _connectionY;
404  int _mctlflags;
405  int _mctlstatic;
406  int16 _mctlmirror;
407  Common::ScopedPtr<MessageQueue> _messageQueueObj;
408  int _motionControllerObj;
409 
411 };
412 
413 } // End of namespace NGI
414 
415 #endif /* NGI_MOTION_H */
Definition: motion.h:328
Definition: motion.h:127
Definition: str.h:59
Definition: utils.h:39
Definition: motion.h:177
Definition: array.h:52
Definition: motion.h:348
Definition: rect.h:144
Definition: motion.h:369
Definition: statics.h:107
Definition: ptr.h:572
Definition: motion.h:80
Definition: motion.h:164
Definition: motion.h:248
Definition: motion.h:118
Definition: messages.h:108
Definition: motion.h:234
Definition: anihandler.h:91
Definition: motion.h:194
Definition: motion.h:321
Definition: rect.h:45
Definition: motion.h:400
Definition: motion.h:39
Definition: motion.h:239
size_type size() const
Definition: array.h:315
Definition: motion.h:94
Definition: statics.h:172
Definition: messages.h:59
Definition: motion.h:134
Definition: motion.h:363
Definition: anihandler.h:25
Common::Array< MctlItem * > _motionControllers
Definition: motion.h:97
Definition: utils.h:189
Definition: motion.h:341
Definition: utils.h:106
Definition: motion.h:255
Definition: motion.h:270
Definition: motion.h:70