ScummVM API documentation
core.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 TSAGE_CORE_H
23 #define TSAGE_CORE_H
24 
25 #include "common/scummsys.h"
26 #include "common/endian.h"
27 #include "common/error.h"
28 #include "common/list.h"
29 #include "common/rect.h"
30 #include "graphics/surface.h"
31 #include "tsage/events.h"
32 #include "tsage/graphics.h"
33 #include "tsage/resources.h"
34 #include "tsage/saveload.h"
35 
36 namespace TsAGE {
37 
38 #define MAX_FLAGS 256
39 
40 class EventHandler;
41 class SceneObject;
42 class SceneObjectList;
43 class ObjectMover;
44 class Action;
45 class Serializer;
46 
47 class InvObject : public SavedObject {
48 public:
49  int _sceneNumber;
50  int _displayResNum;
51  int _rlbNum;
52  int _cursorNum;
53  Rect _bounds;
54  CursorType _cursorId;
55  Common::String _description;
56  int _iconResNum;
57 
58  int _visage;
59  int _strip;
60  int _frame;
61 public:
62  InvObject(int sceneNumber, int rlbNum, int cursorNum, CursorType cursorId, const Common::String description);
63  InvObject(int visage, int strip, int frame);
64  InvObject(int visage, int strip);
65 
66  bool inInventory() const;
67  void setCursor();
68 
69  Common::String getClassName() override { return "InvObject"; }
70  void synchronize(Serializer &s) override {
71  s.syncAsUint16LE(_sceneNumber);
72  }
73 };
74 
75 class InvObjectList : public SavedObject {
76 public:
78  InvObject *_selectedItem;
79 
80  InvObjectList();
81  int indexOf(InvObject *obj) const;
82  InvObject *getItem(int objectNum);
83  int getObjectScene(int objectNum);
84 
85  Common::String getClassName() override { return "InvObjectList"; }
86  void synchronize(Serializer &s) override;
87 };
88 
89 /*--------------------------------------------------------------------------*/
90 
94 class RefCounter : public Serialisable {
95 private:
96  int _ctr;
97 public:
98  RefCounter() { clear(); }
99  ~RefCounter() override {}
100 
101  RefCounter(int v) { _ctr = v; }
102 
103  void clear() { _ctr = 0; }
104  void setCtr(int v) { _ctr = v; }
105  int decCtr() {
106  if (_ctr > 0) --_ctr;
107  return _ctr;
108  }
109  int incCtr() { return ++_ctr; }
110  int getCtr() const { return _ctr; }
111 
112  void synchronize(Serializer &s) override { s.syncAsSint16LE(_ctr); }
113 };
114 
115 class EventHandler : public SavedObject {
116 public:
117  Action *_action;
118 
119  EventHandler() : SavedObject() { _action = NULL; }
120  ~EventHandler() override { destroy(); }
121 
122  void synchronize(Serializer &s) override { SYNC_POINTER(_action); }
123  Common::String getClassName() override { return "EventHandler"; }
124  virtual void postInit(SceneObjectList *OwnerList = NULL) {}
125  virtual void remove() {}
126  virtual void signal() {}
127  virtual void process(Event &event) {}
128  virtual void dispatch();
129  virtual void setAction(Action *action) { setAction(action, NULL); }
130  virtual void setAction(Action *action, EventHandler *endHandler, ...);
131  virtual void destroy() {}
132 };
133 
134 class Action : public EventHandler {
135 public:
136  EventHandler *_owner;
137  int _actionIndex;
138  int _delayFrames;
139  uint32 _startFrame;
140  bool _attached;
141  EventHandler *_endHandler;
142 
143  Action();
144 
145  void synchronize(Serializer &s) override;
146  Common::String getClassName() override { return "Action"; }
147  void remove() override;
148  void process(Event &event) override;
149  void dispatch() override;
150  virtual void attached(EventHandler *newOwner, EventHandler *endHandler, va_list va);
151 
152  void attach(EventHandler *newOwner, EventHandler *endHandler, ...) {
153  va_list va;
154  va_start(va, endHandler);
155  attached(newOwner, endHandler, va);
156  va_end(va);
157  }
158  int getActionIndex() const { return _actionIndex; }
159  void setActionIndex(int index) { _actionIndex = index; }
160  void setDelay(int numFrames);
161 };
162 
163 class ActionExt : public Action {
164 public:
165  int _state;
166 };
167 
168 #define ADD_PLAYER_MOVER(X, Y) { Common::Point pt(X, Y); PlayerMover *mover = new PlayerMover(); \
169  g_globals->_player.addMover(mover, &pt, this); }
170 #define ADD_PLAYER_MOVER_NULL(OBJ, X, Y) { Common::Point pt(X, Y); PlayerMover *mover = new PlayerMover(); \
171  OBJ.addMover(mover, &pt, NULL); }
172 #define ADD_PLAYER_MOVER_THIS(OBJ, X, Y) { Common::Point pt(X, Y); PlayerMover *mover = new PlayerMover(); \
173  OBJ.addMover(mover, &pt, this); }
174 
175 #define ADD_MOVER(OBJ, X, Y) { Common::Point pt(X, Y); NpcMover *mover = new NpcMover(); \
176  OBJ.addMover(mover, &pt, this); }
177 #define ADD_MOVER_NULL(OBJ, X, Y) { Common::Point pt(X, Y); NpcMover *mover = new NpcMover(); \
178  OBJ.addMover(mover, &pt, NULL); }
179 
180 class ObjectMover : public EventHandler {
181 public:
182  Common::Point _destPosition;
183  Common::Point _moveDelta;
184  Common::Point _moveSign;
185  int _minorDiff;
186  int _majorDiff;
187  int _changeCtr;
188  Action *_action;
189  SceneObject *_sceneObject;
190 public:
191  ObjectMover() { _action = NULL; _sceneObject = NULL; _minorDiff = 0; _majorDiff = 0; _changeCtr = 0;}
192  ~ObjectMover() override;
193 
194  void synchronize(Serializer &s) override;
195  Common::String getClassName() override { return "ObjectMover"; }
196  void remove() override;
197  void dispatch() override;
198  virtual void startMove(SceneObject *sceneObj, va_list va) {}
199  virtual void setup(const Common::Point &destPos);
200  virtual bool dontMove() const;
201  virtual void endMove();
202 };
203 
204 class ObjectMover2 : public ObjectMover {
205 public:
206  SceneObject *_destObject;
207  int _minArea;
208  int _maxArea;
209 public:
210  ObjectMover2();
211  ~ObjectMover2() override {}
212 
213  void synchronize(Serializer &s) override;
214  Common::String getClassName() override { return "ObjectMover2"; }
215  void dispatch() override;
216  void startMove(SceneObject *sceneObj, va_list va) override;
217  void endMove() override;
218 };
219 
220 class ObjectMover3 : public ObjectMover2 {
221 public:
222  Common::String getClassName() override { return "ObjectMover3"; }
223  void dispatch() override;
224  void startMove(SceneObject *sceneObj, va_list va) override;
225  void endMove() override;
226 };
227 
228 class NpcMover : public ObjectMover {
229 public:
230  Common::String getClassName() override { return "NpcMover"; }
231  void startMove(SceneObject *sceneObj, va_list va) override;
232 };
233 
234 #define MAX_ROUTE_SIZE 20
235 #define ROUTE_END_VAL -20000
236 
237 class RouteEnds {
238 public:
239  Common::Point moveSrc;
240  Common::Point moveDest;
241 };
242 
243 class PlayerMover : public NpcMover {
244 protected:
245  void setDest(const Common::Point &destPos);
246  void pathfind(Common::Point *routeList, Common::Point srcPos, Common::Point destPos, RouteEnds routeEnds);
247  int regionIndexOf(const Common::Point &pt);
248  int regionIndexOf(int xp, int yp) { return regionIndexOf(Common::Point(xp, yp)); }
249  int findClosestRegion(Common::Point &pt, const Common::List<int> &indexList);
250  int checkMover(Common::Point &srcPos, const Common::Point &destPos);
251  void doStepsOfNpcMovement(const Common::Point &pt1, const Common::Point &pt2, int numSteps, Common::Point &ptOut);
252  int calculateRestOfRoute(int *routeList, int srcRegion, int destRegion, bool &foundRoute);
253 
254  static Common::Point *findLinePoint(RouteEnds *routeEnds, Common::Point *objPos, int length, Common::Point *outPos);
255  static int findDistance(const Common::Point &pt1, const Common::Point &pt2);
256  static bool sub_F8E5_calculatePoint(const Common::Point &pt1, const Common::Point &pt2, const Common::Point &pt3,
257  const Common::Point &pt4, Common::Point *ptOut = NULL);
258 public:
259  Common::Point _finalDest;
260  Common::Point _routeList[MAX_ROUTE_SIZE];
261  int _routeIndex;
262 
263  void synchronize(Serializer &s) override;
264  Common::String getClassName() override { return "PlayerMover"; }
265  void startMove(SceneObject *sceneObj, va_list va) override;
266  void endMove() override;
267 };
268 
269 class PlayerMover2 : public PlayerMover {
270 public:
271  SceneObject *_destObject;
272  int _maxArea;
273  int _minArea;
274  PlayerMover2() : PlayerMover() { _destObject = NULL; _minArea = _maxArea = 0;}
275 
276  void synchronize(Serializer &s) override;
277  Common::String getClassName() override { return "PlayerMover2"; }
278  void dispatch() override;
279  void startMove(SceneObject *sceneObj, va_list va) override;
280  void endMove() override;
281 };
282 
283 /*--------------------------------------------------------------------------*/
284 
285 class ScenePalette;
286 
287 class PaletteModifier : public SavedObject {
288 public:
289  ScenePalette *_scenePalette;
290  Action *_action;
291 public:
292  PaletteModifier();
293 
294  void synchronize(Serializer &s) override {
295  SYNC_POINTER(_scenePalette);
296  SYNC_POINTER(_action);
297  }
298  virtual void signal() = 0;
299  virtual void remove() = 0;
300 };
301 
303 public:
304  byte _palette[256 * 3];
305  int _step;
306  int _percent;
307 
309 
310  virtual void setPalette(ScenePalette *palette, int step);
311  Common::String getClassName() override { return "PaletteModifierCached"; }
312  void synchronize(Serializer &s) override;
313 };
314 
316 public:
317  int _delayCtr;
318  uint32 _frameNumber;
319  int _currIndex;
320  int _start;
321  int _end;
322  int _rotationMode;
323  int _duration;
324  int _idxChange;
325  int _countdown;
326 public:
327  PaletteRotation();
328 
329  Common::String getClassName() override { return "PaletteRotation"; }
330  void synchronize(Serializer &s) override;
331  void signal() override;
332  void remove() override;
333 
334  void setStep(int step) { _step = step; }
335  void set(ScenePalette *palette, int start, int end, int rotationMode, int duration, Action *action);
336  bool decDuration();
337  void setDelay(int amount);
338 };
339 
341 public:
342  byte _palette[256 * 3];
343 public:
344  Common::String getClassName() override { return "PaletteFader"; }
345  void synchronize(Serializer &s) override;
346  void signal() override;
347  void remove() override;
348  void setPalette(ScenePalette *palette, int step) override;
349 };
350 
351 /*--------------------------------------------------------------------------*/
352 
353 enum FadeMode {FADEMODE_NONE = 0, FADEMODE_GRADUAL = 1, FADEMODE_IMMEDIATE = 2};
354 
355 class ScenePalette : public SavedObject {
356 public:
357  byte _palette[256 * 3];
358  GfxColors _colors;
360 
361  uint8 _redColor;
362  uint8 _greenColor;
363  uint8 _blueColor;
364  uint8 _aquaColor;
365  uint8 _purpleColor;
366  uint8 _limeColor;
367 public:
368  ScenePalette();
369  ScenePalette(int paletteNum);
370  ~ScenePalette() override;
371 
372  bool loadPalette(int paletteNum);
373  void loadPalette(const byte *pSrc, int start, int count);
374  void replace(const ScenePalette *src) { loadPalette(src->_palette, 0, 256); }
375  void refresh();
376  void setPalette(int index, int count);
377  void getEntry(int index, uint *r, uint *g, uint *b);
378  void setEntry(int index, uint r, uint g, uint b);
379  uint8 indexOf(uint r, uint g, uint b, int threshold = 0xffff, int start = 0, int count = 256);
380  void getPalette(int start = 0, int count = 256);
381  void signalListeners();
382  void clearListeners();
383  void fade(const byte *adjustData, bool fullAdjust, int percent);
384  PaletteRotation *addRotation(int start, int end, int rotationMode, int duration = 0, Action *action = NULL);
385  PaletteFader *addFader(const byte *arrBufferRGB, int palSize, int step, Action *action);
386 
387  static void changeBackground(const Rect &bounds, FadeMode fadeMode);
388 
389  void synchronize(Serializer &s) override;
390  Common::String getClassName() override { return "ScenePalette"; }
391 };
392 
393 // DisplayParamType constant set. This must not be an enum
394 const int SET_WIDTH = 0;
395 const int SET_X = 1;
396 const int SET_Y = 2;
397 const int SET_FONT = 3;
398 const int SET_BG_COLOR = 4;
399 const int SET_FG_COLOR = 5;
400 const int SET_KEEP_ONSCREEN = 6;
401 const int SET_EXT_BGCOLOR = 7;
402 const int SET_EXT_FGCOLOR = 8;
403 const int SET_POS_MODE = 9;
404 const int SET_TEXT_MODE = 10;
405 const int LIST_END = -999;
406 
407 class SceneItem : public EventHandler {
408 public:
409  Rect _bounds;
410  Common::String _msg;
411  Common::Point _position;
412  int _yDiff;
413  int _sceneRegionId;
414 public:
415  SceneItem() : EventHandler() { _msg = "Feature"; _action = NULL; _sceneRegionId = 0; _yDiff = 0;}
416 
417  void synchronize(Serializer &s) override;
418  Common::String getClassName() override { return "SceneItem"; }
419  void remove() override;
420  void destroy() override {}
421  virtual bool startAction(CursorType action, Event &event);
422  virtual void doAction(int action);
423 
424  bool contains(const Common::Point &pt);
425  void setBounds(const Rect &newBounds) { _bounds = newBounds; }
426  void setBounds(const int ys, const int xe, const int ye, const int xs) { _bounds = Rect(MIN(xs, xe), MIN(ys, ye), MAX(xs, xe), MAX(ys, ye)); }
427  static void display(int resNum, int lineNum, ...);
428  static void display2(int resNum, int lineNum);
429  static void display(const Common::String &msg);
430 };
431 
432 class SceneItemExt : public SceneItem {
433 public:
434  int _state;
435 
436  Common::String getClassName() override { return "SceneItemExt"; }
437  void synchronize(Serializer &s) override {
438  SceneItem::synchronize(s);
439  s.syncAsSint16LE(_state);
440  }
441 };
442 
443 class SceneHotspot : public SceneItem {
444 public:
445  int _resNum, _lookLineNum, _useLineNum, _talkLineNum;
446 public:
447  SceneHotspot();
448  void synchronize(Serializer &s) override;
449  bool startAction(CursorType action, Event &event) override;
450  Common::String getClassName() override { return "SceneHotspot"; }
451  void doAction(int action) override;
452 
453  void setDetails(int ys, int xs, int ye, int xe, const int resnum, const int lookLineNum, const int useLineNum);
454  void setDetails(const Rect &bounds, int resNum, int lookLineNum, int talkLineNum, int useLineNum, int mode, SceneItem *item);
455  void setDetails(int sceneRegionId, int resNum, int lookLineNum, int talkLineNum, int useLineNum, int mode = 0);
456  void setDetails(int resNum, int lookLineNum, int talkLineNum, int useLineNum, int mode, SceneItem *item);
457  void setDetails(int resNum, int lookLineNum, int talkLineNum, int useLineNum);
458 };
459 
460 enum AnimateMode {ANIM_MODE_NONE = 0, ANIM_MODE_1 = 1, ANIM_MODE_2 = 2, ANIM_MODE_3 = 3,
461  ANIM_MODE_4 = 4, ANIM_MODE_5 = 5, ANIM_MODE_6 = 6, ANIM_MODE_7 = 7, ANIM_MODE_8 = 8,
462  // Introduced in Blue Force
463  ANIM_MODE_9 = 9
464 };
465 
466 // Actor effect enumeration used in Return to Ringworld 2
467 enum Effect { EFFECT_NONE = 0, EFFECT_SHADED = 1, EFFECT_SMOKE = 3,
468  EFFECT_SHADOW_MAP = 5, EFFECT_SHADED2 = 6 };
469 
470 class SceneObject;
471 
472 class Visage {
473 private:
474  byte *_data;
475 
476  void flipHorizontal(GfxSurface &s);
477  void flipVertical(GfxSurface &s);
478 public:
479  int _resNum;
480  int _rlbNum;
481  bool _flipHoriz;
482  bool _flipVert;
483 public:
484  Visage();
485  Visage(const Visage &v);
486  ~Visage();
487 
488  void setVisage(int resNum, int rlbNum = 9999);
489  GfxSurface getFrame(int frameNum);
490  int getFrameCount() const;
491  Visage &operator=(const Visage &gfxSurface);
492 };
493 
495 private:
496  Visage _visageImages;
497 public:
498  SceneObject *_sceneObject;
499 public:
500  SceneObjectWrapper() { _sceneObject = NULL; }
501  ~SceneObjectWrapper() override {}
502 
503  void setSceneObject(SceneObject *so);
504  void check();
505 
506  void synchronize(Serializer &s) override;
507  Common::String getClassName() override { return "SceneObjectWrapper"; }
508  void remove() override;
509  void dispatch() override;
510 };
511 
512 enum ObjectFlags {OBJFLAG_FIXED_PRIORITY = 1, OBJFLAG_NO_UPDATES = 2, OBJFLAG_ZOOMED = 4,
513  OBJFLAG_SUPPRESS_DISPATCH = 8, OBJFLAG_HIDE = 0x100, OBJFLAG_HIDING = 0x200, OBJFLAG_REMOVE = 0x400,
514  OBJFLAG_CLONED = 0x800, OBJFLAG_CHECK_REGION = 0x1000, OBJFLAG_PANE_0 = 0x4000, OBJFLAG_PANE_1 = 0x8000,
515  OBJFLAG_PANES = OBJFLAG_PANE_0 | OBJFLAG_PANE_1,
516  OBJFLAG_FLIP_CENTROID_X = 0x10000, OBJFLAG_FLIP_CENTROID_Y = 0x20000
517 };
518 
519 class SceneObject : public SceneHotspot {
520 private:
521  Visage _visageImages;
522 
523  int getNewFrame();
524  void animEnded();
525 public:
526  int changeFrame();
527  uint32 _updateStartFrame;
528  uint32 _walkStartFrame;
529  Common::Point _oldPosition;
530  int _percent;
531  int _priority;
532  int _angle;
533  uint32 _flags;
534  int _xs, _xe;
535  Rect _paneRects[2];
536  int _visage;
537  SceneObjectWrapper *_objectWrapper;
538  int _strip;
539  AnimateMode _animateMode;
540  int _frame;
541  int _endFrame;
542  int _loopCount;
543  int _frameChange;
544  int _numFrames;
545  int _regionIndex;
546  EventHandler *_mover;
547  Common::Point _moveDiff;
548  int _moveRate;
549  Common::Point _actorDestPos;
550  Action *_endAction;
551  uint32 _regionBitList;
552 
553  // Ringworld 2 specific fields
554  byte *_shadowMap;
555  int _shade, _oldShade;
556  int _effect;
557  SceneObject *_linkedActor;
558 public:
559  SceneObject();
560  SceneObject(const SceneObject &so);
561  ~SceneObject() override;
562 
563  SceneObject& operator=(const SceneObject &so);
564 
565  void setPosition(const Common::Point &p, int yDiff = 0);
566  void setStrip(int frameNum);
567  void setStrip2(int frameNum);
568  void setZoom(int percent);
569  void updateZoom();
570  void changeZoom(int percent);
571  void setFrame(int frameNum);
572  void setFrame2(int frameNum);
573  void setPriority(int priority);
574  void fixPriority(int priority);
575  void setVisage(int visage);
576  void setObjectWrapper(SceneObjectWrapper *objWrapper);
577  void addMover(ObjectMover *mover, ...);
578  void getHorizBounds();
579  int getRegionIndex();
580  int checkRegion(const Common::Point &pt);
581  void animate(int animMode, ...);
582  void checkAngle(const SceneObject *obj);
583  void checkAngle(const Common::Point &pt);
584  void hide();
585  void show();
586  int getSpliceArea(const SceneObject *obj);
587  int getFrameCount();
588  bool isNoMover() const { return !_mover || (_regionIndex > 0); }
589 
590  void synchronize(Serializer &s) override;
591  Common::String getClassName() override { return "SceneObject"; }
592  void postInit(SceneObjectList *OwnerList = NULL) override;
593  void remove() override;
594  void process(Event &event) override { event.handled = true; }
595  void dispatch() override;
596  virtual void calcAngle(const Common::Point &pt);
597  virtual void removeObject();
598  virtual GfxSurface getFrame();
599  virtual void reposition();
600  virtual void draw();
601  virtual void proc19() {}
602  virtual void updateScreen();
603  // New methods introduced by Blue Force
604  virtual void updateAngle(const Common::Point &pt);
605  virtual void changeAngle(int angle);
606  // New methods introduced by Ringworld 2
607  virtual void copy(SceneObject *src);
608  virtual SceneObject *clone() const;
609 
610  void setup(int visage, int stripFrameNum, int frameNum, int posX, int posY, int priority);
611  void setup(int visage, int stripFrameNum, int frameNum);
612 };
613 
615 public:
616  Common::String getClassName() override { return "BackgroundSceneObject"; }
617  void postInit(SceneObjectList *OwnerList = NULL) override;
618  void draw() override;
619  SceneObject *clone() const override;
620 
621  void setup2(int visage, int stripFrameNum, int frameNum, int posX, int posY, int priority, int effect);
622  static void copySceneToBackground();
623 };
624 
625 class SceneText : public SceneObject {
626 public:
627  int _fontNumber;
628  int _width;
629  TextAlign _textMode;
630  int _color1;
631  int _color2;
632  int _color3;
633  GfxSurface _textSurface;
634 public:
635  SceneText();
636  ~SceneText() override;
637 
638  void setup(const Common::String &msg);
639 
640  void synchronize(Serializer &s) override;
641  Common::String getClassName() override { return "SceneText"; }
642  GfxSurface getFrame() override { return _textSurface; }
643  void updateScreen() override;
644 };
645 
646 #define MAX_CHARACTERS 4
647 enum R2RCharacter { R2_NONE = 0, R2_QUINN = 1, R2_SEEKER = 2, R2_MIRANDA = 3 };
648 
649 class Player : public SceneObject {
650 public:
651  bool _canWalk;
652  bool _uiEnabled;
653  bool _enabled;
654 
655  // Return to Ringworld specific fields
656  R2RCharacter _characterIndex;
657  int _characterScene[MAX_CHARACTERS];
658  int _oldCharacterScene[MAX_CHARACTERS];
659  Common::Point _characterPos[MAX_CHARACTERS];
660  int _characterStrip[MAX_CHARACTERS];
661  int _characterFrame[MAX_CHARACTERS];
662 public:
663  Player();
664 
665  Common::String getClassName() override { return "Player"; }
666  void synchronize(Serializer &s) override;
667  void postInit(SceneObjectList *OwnerList = NULL) override;
668  void process(Event &event) override;
669 
670  void disableControl();
671  void enableControl();
672  void disableControl(CursorType cursorId, CursorType objectId = CURSOR_NONE);
673  void enableControl(CursorType cursorId, CursorType objectId = CURSOR_NONE);
674 };
675 
676 /*--------------------------------------------------------------------------*/
677 
679 public:
681 
682  void load(int size, const byte *srcP) {
683  for (int i = 0; i < size; ++i, srcP += 4)
684  items.push_back(LineSlice(READ_LE_UINT16(srcP), READ_LE_UINT16(srcP + 2)));
685  }
686  void load2(int size, ...) {
687  va_list va;
688  va_start(va, size);
689 
690  while (size-- > 0) {
691  int xs = va_arg(va, int);
692  int xe = va_arg(va, int);
693  items.push_back(LineSlice(xs, xe));
694  }
695  va_end(va);
696  }
697 
698  void add(LineSlice &slice) { items.push_back(slice); }
699  void add(int xs, int xe) { items.push_back(LineSlice(xs, xe)); }
700  static LineSliceSet mergeSlices(const LineSliceSet &set1, LineSliceSet &set2);
701 };
702 
703 class Region {
704 public:
705  int _regionSize;
706  int _regionId;
707  Rect _bounds;
709 public:
710  Region() { _regionSize = 0; _regionId = 0; }
711  Region(int resNum, int rlbNum, ResourceType ctlType = RES_CONTROL);
712  Region(int regionId, const byte *regionData);
713 
714  void load(const byte *regionData);
715  bool contains(const Common::Point &pt);
716  bool empty() const;
717  void clear();
718  void setRect(const Rect &r);
719  void setRect(int xs, int ys, int xe, int ye);
720  const LineSliceSet &getLineSlices(int yp);
721  LineSliceSet sectPoints(int yp, const LineSliceSet &sliceSet);
722  void draw();
723  void uniteLine(int yp, LineSliceSet &sliceSet);
724  void uniteRect(const Rect &rect);
725 
726  static LineSliceSet mergeSlices(const LineSliceSet &set1, const LineSliceSet &set2);
727 };
728 
729 class SceneRegions : public Common::List<Region> {
730 public:
731  void load(int sceneNum);
732 
733  int indexOf(const Common::Point &pt);
734 };
735 
736 class SceneObjectList : public SavedObject {
737 private:
738  void checkIntersection(Common::Array<SceneObject *> &ObjList, uint ObjIndex, int PaneNum);
739 
741  bool _listAltered;
742 public:
743  SceneObjectList() { _listAltered = false; }
744  void sortList(Common::Array<SceneObject *> &ObjList);
745 
746  Common::String getClassName() override { return "SceneObjectList"; }
747  void synchronize(Serializer &s) override;
748 
749  void draw();
750  void activate();
751  static void deactivate();
752 
753  typedef void (*EventHandlerFn)(EventHandler *fn);
754  void recurse(EventHandlerFn Fn) {
755  // Loop through each object
756  _listAltered = false;
757  for (SynchronizedList<SceneObject *>::iterator i = _objList.begin(); i != _objList.end() && !_listAltered; ) {
758  SceneObject *o = *i;
759  ++i;
760  Fn(o);
761  }
762  }
763  SynchronizedList<SceneObject *>::iterator begin() { return _objList.begin(); }
764  SynchronizedList<SceneObject *>::iterator end() { return _objList.end(); }
765  int size() const { return _objList.size(); }
766  bool contains(SceneObject *sceneObj) { return TsAGE::contains(_objList, sceneObj); }
767  void push_back(SceneObject *sceneObj) { _objList.push_back(sceneObj); }
768  void push_front(SceneObject *sceneObj) { _objList.push_front(sceneObj); }
769  void remove(SceneObject *sceneObj) {
770  _objList.remove(sceneObj);
771  _listAltered = true;
772  }
773  void clear() { _objList.clear(); }
774 };
775 
776 class ScenePriorities : public Common::List<Region> {
777 public:
778  int _resNum;
779  Region _defaultPriorityRegion;
780 public:
781  void load(int resNum);
782 
783  Region *find(int priority);
784 };
785 
786 /*--------------------------------------------------------------------------*/
787 
788 class SceneItemList : public SynchronizedList<SceneItem *> {
789 public:
790  void addItems(SceneItem *first, ...);
791 };
792 
793 /*--------------------------------------------------------------------------*/
794 
796 public:
797  int _yp;
798  int _xp;
799  int _xDiff;
800  int _yDiff;
801  int _xDirection;
802  int _halfDiff;
803  int _yDiff2;
804 
805  void process();
806 };
807 
808 #define PROCESS_LIST_SIZE 100
809 
810 class WalkRegion : public Region {
811 private:
812  static RegionSupportRec _processList[PROCESS_LIST_SIZE];
813  void loadProcessList(byte *dataP, int dataSize, int &dataIndex, int &regionHeight);
814  int process1(int idx, byte *dataP, int dataSize);
815  void process2(int dataIndex, int x1, int y1, int x2, int y2);
816  void process3(int yp, int dataCount, int &idx1, int &idx2);
817  void process4(int yp, int idx1, int idx2, int &count);
818  void process5(int idx1, int idx2);
819  void loadRecords(int yp, int size, int processIndex);
820  void process6(RegionSupportRec &rec);
821 public:
822  Common::Point _pt;
823  int _idxListIndex;
824  int _idxList2Index;
825 public:
826  void loadRegion(byte *dataP, int size);
827 };
828 
829 class WRField18 {
830 public:
831  Common::Point _pt1, _pt2;
832  int _v;
833 public:
834  void load(byte *data);
835 };
836 
837 class WalkRegions {
838 private:
839  void loadOriginal();
840  void loadRevised();
841 public:
842  int _resNum;
843  RouteEnds _routeEnds;
844  Common::Array<WalkRegion> _regionList;
845  Common::Array<WRField18> _field18;
846  Common::Array<int> _idxList;
847  Common::Array<int> _idxList2;
848  Common::List<int> _disabledRegions;
849 public:
850  WalkRegions() { _resNum = -1; }
851  virtual ~WalkRegions() {}
852  virtual void synchronize(Serializer &s);
853 
854  void clear();
855  void load(int sceneNum);
856  int indexOf(const Common::Point &pt, const Common::List<int> *indexList = NULL);
857  WalkRegion &operator[](int idx) {
858  assert((idx >= 1) && (idx <= (int)_regionList.size()));
859  return _regionList[idx - 1];
860  }
861  void disableRegion(int regionId);
862  void enableRegion(int regionId);
863 };
864 
865 /*--------------------------------------------------------------------------*/
866 
867 class FloatSet {
868 public:
869  double _float1, _float2, _float3, _float4;
870 
871  FloatSet() { _float1 = _float2 = _float3 = _float4 = 0; }
872  void add(double v1, double v2, double v3);
873  void proc1(double v);
874  double sqrt(FloatSet &floatSet);
875 };
876 
877 /*--------------------------------------------------------------------------*/
878 
879 class GameHandler : public EventHandler {
880 public:
881  RefCounter _lockCtr;
882  RefCounter _waitCtr;
883  int _nextWaitCtr;
884 public:
885  GameHandler();
886  ~GameHandler() override;
887  void execute();
888 
889  void synchronize(Serializer &s) override;
890  Common::String getClassName() override { return "GameHandler"; }
891  void postInit(SceneObjectList *OwnerList = NULL) override {}
892  void dispatch() override {}
893 };
894 
895 class SceneHandler : public GameHandler {
896 public:
897  int _saveGameSlot;
898  int _loadGameSlot;
899  int _delayTicks;
900  Common::String _saveName;
901  uint32 _prevFrameNumber;
902 protected:
903  virtual void playerAction(Event &event) {}
904  virtual void processEnd(Event &event) {}
905  virtual void postLoad(int priorSceneBeforeLoad, int currentSceneBeforeLoad) {}
906 public:
907  SceneHandler();
908  void registerHandler();
909  uint32 getFrameDifference();
910 
911  Common::String getClassName() override { return "SceneHandler"; }
912  void postInit(SceneObjectList *OwnerList = NULL) override;
913  void process(Event &event) override;
914  void dispatch() override;
915 
916  static void dispatchObject(EventHandler *obj);
917  static void saveListener(Serializer &ser);
918 };
919 
920 } // End of namespace TsAGE
921 
922 #endif
Definition: core.h:228
Definition: core.h:75
Definition: core.h:443
Definition: graphics.h:57
Definition: str.h:59
Definition: saveload.h:98
Definition: saveload.h:84
Definition: core.h:703
Definition: core.h:678
Definition: core.h:115
Definition: core.h:432
Definition: core.h:736
Definition: core.h:269
Definition: array.h:52
Definition: core.h:355
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: core.h:134
size_type size() const
Definition: list.h:198
Definition: core.h:407
void push_front(const T &element)
Definition: list.h:135
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
Definition: core.h:795
Definition: core.h:220
Definition: core.h:180
void replace(It begin, It end, const Dat &original, const Dat &replaced)
Definition: algorithm.h:448
void push_back(const T &element)
Definition: array.h:180
Definition: core.h:776
iterator end()
Definition: list.h:240
Definition: core.h:472
Definition: core.h:879
iterator begin()
Definition: list.h:227
Definition: graphics.h:79
Definition: core.h:614
Definition: core.h:47
Definition: core.h:867
Definition: core.h:94
Definition: core.h:243
Definition: rect.h:45
Definition: events.h:47
Definition: saveload.h:115
Definition: blueforce_dialogs.h:30
void clear()
Definition: list.h:206
size_type size() const
Definition: array.h:315
Definition: core.h:302
void remove(const T &val)
Definition: list.h:125
Definition: saveload.h:63
Definition: core.h:829
Definition: core.h:895
Definition: core.h:729
Definition: core.h:163
T MIN(T a, T b)
Definition: util.h:59
Definition: core.h:287
Definition: graphics.h:65
Definition: core.h:519
Definition: list_intern.h:51
T MAX(T a, T b)
Definition: util.h:62
Definition: core.h:788
Definition: graphics.h:40
Definition: core.h:315
void push_back(const T &element)
Definition: list.h:140
Definition: core.h:625
Definition: core.h:649
Definition: core.h:494
Definition: core.h:237
Definition: core.h:837
Definition: core.h:340
Definition: core.h:204
Definition: core.h:810