ScummVM API documentation
object.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 /*
23  * This code is based on original Hugo Trilogy source code
24  *
25  * Copyright (c) 1989-1995 David P. Gray
26  *
27  */
28 
29 #ifndef HUGO_OBJECT_H
30 #define HUGO_OBJECT_H
31 
32 #include "common/file.h"
33 
34 namespace Hugo {
35 
36 struct Target { // Secondary target for action
37  uint16 _nounIndex; // Secondary object
38  uint16 _verbIndex; // Action on secondary object
39 };
40 
41 struct Uses { // Define uses of certain objects
42  int16 _objId; // Primary object
43  uint16 _dataIndex; // String if no secondary object matches
44  Target *_targets; // List of secondary targets
45 };
46 
48 public:
50  virtual ~ObjectHandler();
51 
52  Overlay _objBound;
53  Overlay _boundary; // Boundary overlay file
54  Overlay _overlay; // First overlay file
55  Overlay _ovlBase; // First overlay base file
56 
57  Object *_objects;
58  uint16 _numObj;
59 
60  byte getBoundaryOverlay(uint16 index) const;
61  byte getObjectBoundary(uint16 index) const;
62  byte getBaseBoundary(uint16 index) const;
63  byte getFirstOverlay(uint16 index) const;
64 
65  int deltaX(const int x1, const int x2, const int vx, int y) const;
66  int deltaY(const int x1, const int x2, const int vy, const int y) const;
67  void boundaryCollision(Object *obj);
68  void clearBoundary(const int x1, const int x2, const int y);
69  void clearScreenBoundary(const int x1, const int x2, const int y);
70  void storeBoundary(const int x1, const int x2, const int y);
71 
72  virtual void homeIn(const int objIndex1, const int objIndex2, const int8 objDx, const int8 objDy) = 0;
73  virtual void moveObjects() = 0;
74  virtual void updateImages() = 0;
75  virtual void swapImages(int objIndex1, int objIndex2) = 0;
76 
77  bool isCarrying(uint16 wordIndex);
78  bool findObjectSpace(Object *obj, int16 *destx, int16 *desty);
79 
80  int calcMaxScore();
81  int16 findObject(uint16 x, uint16 y);
82  void freeObjects();
83  void loadObjectArr(Common::ReadStream &in);
84  void loadObjectUses(Common::ReadStream &in);
85  void loadNumObj(Common::ReadStream &in);
86  void lookObject(Object *obj);
87  void readObjectImages();
88  void readObject(Common::ReadStream &in, Object &curObject);
89  void readUse(Common::ReadStream &in, Uses &curUse);
90  void restoreAllSeq();
91  void restoreObjects(Common::SeekableReadStream *in);
92  void saveObjects(Common::WriteStream *out);
93  void saveSeq(Object *obj);
94  void setCarriedScreen(int screenNum);
95  void showTakeables();
96  void useObject(int16 objId);
97 
98  static int y2comp(const void *a, const void *b);
99 
100  bool isCarried(int objIndex) const;
101  void setCarry(int objIndex, bool val);
102  void setVelocity(int objIndex, int8 vx, int8 vy);
103  void setPath(int objIndex, Path pathType, int16 vxPath, int16 vyPath);
104 
105 protected:
106  HugoEngine *_vm;
107 
108  static const int kEdge = 10; // Closest object can get to edge of screen
109  static const int kEdge2 = kEdge * 2; // Push object further back on edge collision
110  static const int kMaxObjNumb = 128; // Used in Update_images()
111 
112  uint16 _objCount;
113  Uses *_uses;
114  uint16 _usesSize;
115 
116  void restoreSeq(Object *obj);
117 
118  inline bool checkBoundary(int16 x, int16 y);
119  template<typename T>
120  inline int sign(T a) { if ( a < 0) return -1; else return 1; }
121 };
122 
124 public:
126  ~ObjectHandler_v1d() override;
127 
128  void homeIn(const int objIndex1, const int objIndex2, const int8 objDx, const int8 objDy) override;
129  void moveObjects() override;
130  void updateImages() override;
131  void swapImages(int objIndex1, int objIndex2) override;
132 };
133 
135 public:
137  ~ObjectHandler_v2d() override;
138 
139  void moveObjects() override;
140  void updateImages() override;
141 
142  void homeIn(const int objIndex1, const int objIndex2, const int8 objDx, const int8 objDy) override;
143 };
144 
146 public:
148  ~ObjectHandler_v3d() override;
149 
150  void moveObjects() override;
151  void swapImages(int objIndex1, int objIndex2) override;
152 };
153 
155 public:
157  ~ObjectHandler_v1w() override;
158 
159  void moveObjects() override;
160  void updateImages() override;
161  void swapImages(int objIndex1, int objIndex2) override;
162 };
163 
164 } // End of namespace Hugo
165 #endif //HUGO_OBJECT_H
Definition: object.h:145
Definition: console.h:27
Definition: object.h:41
Definition: object.h:47
Definition: stream.h:77
Definition: object.h:123
Definition: stream.h:745
Definition: object.h:36
Definition: object.h:154
Definition: object.h:134
Path
Definition: game.h:75
Definition: default_display_client.h:65
Definition: stream.h:385
Definition: hugo.h:210
Definition: game.h:142