ScummVM API documentation
world.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  * Based on
24  * WebVenture (c) 2010, Sean Kasun
25  * https://github.com/mrkite/webventure, http://seancode.com/webventure/
26  *
27  * Used with explicit permission from the author
28  */
29 
30 #ifndef MACVENTURE_WORLD_H
31 #define MACVENTURE_WORLD_H
32 
33 #include "macventure/container.h"
34 #include "macventure/text.h"
35 
36 namespace MacVenture {
37 
38 typedef uint32 ObjID;
39 typedef uint16 Attribute;
40 typedef Common::Array<Attribute> AttributeGroup;
41 class TextAsset;
42 
43 enum ObjectAttributeID {
44  kAttrParentObject = 0,
45  kAttrPosX = 1,
46  kAttrPosY = 2,
47  kAttrInvisible = 3,
48  kAttrUnclickable = 4,
49  kAttrUndraggable = 5,
50  kAttrContainerOpen = 6,
51  kAttrPrefixes = 7,
52  kAttrIsExit = 8,
53  kAttrExitX = 9,
54  kAttrExitY = 10,
55  kAttrHiddenExit = 11,
56  kAttrOtherDoor = 12,
57  kAttrIsOpen = 13,
58  kAttrIsLocked = 14,
59  kAttrWeight = 16,
60  kAttrSize = 17,
61  kAttrHasDescription = 19,
62  kAttrIsDoor = 20,
63  kAttrIsContainer = 22,
64  kAttrIsOperable = 23,
65  kAttrIsEnterable = 24,
66  kAttrIsEdible = 25
67 };
68 
69 class SaveGame {
70 public:
72  ~SaveGame();
73 
74  Attribute getAttr(ObjID objID, uint32 attrID);
75  void setAttr(uint32 attrID, ObjID objID, Attribute value);
76 
77  void setGlobal(uint32 attrID, Attribute value);
78  const Common::Array<uint16> &getGlobals();
79 
80  const Common::Array<AttributeGroup> &getGroups();
81  const AttributeGroup *getGroup(uint32 groupID);
82  const Common::String &getText();
83 
84  void saveInto(Common::OutSaveFile *file);
85 
86 private:
87  void loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *res);
88  void loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream *res);
89  void loadText(MacVentureEngine *engine, Common::SeekableReadStream *res);
90 
91 private:
93  Common::Array<uint16> _globals;
94  Common::String _text;
95 };
96 
97 class World {
98 public:
100  ~World();
101 
102  void startNewGame();
103 
104  void setObjAttr(ObjID objID, uint32 attrID, Attribute value);
105  void setGlobal(uint32 attrID, Attribute value);
106  void updateObj(ObjID objID);
107  void captureChildren(ObjID objID);
108  void releaseChildren(ObjID objID);
109 
110  uint32 getObjAttr(ObjID objID, uint32 attrID);
111  Attribute getGlobal(uint32 attrID);
112  Common::String getText(ObjID objID, ObjID source, ObjID target);
113 
114  bool isObjActive(ObjID objID);
115 
116  ObjID getAncestor(ObjID objID);
117  Common::Array<ObjID> getFamily(ObjID objID, bool recursive);
118  Common::Array<ObjID> getChildren(ObjID objID, bool recursive);
119 
120  void loadGameFrom(Common::InSaveFile *file);
121  void saveGameInto(Common::OutSaveFile *file);
122 
123 private:
124  bool isObjDraggable(ObjID objID);
125  bool intersects(ObjID objID, Common::Rect rect);
126 
127  void calculateObjectRelations();
128  void setParent(ObjID child, ObjID newParent);
129 
130 private:
131  MacVentureEngine *_engine;
132  Common::MacResManager *_resourceManager;
133 
134  Common::Path _startGameFileName;
135 
136  SaveGame *_saveGame;
137 
138  Container *_objectConstants;
139  Container *_gameText;
140 
141  Common::Array<ObjID> _relations; // Parent-child relations, stored in Williams Heap format
142 };
143 
144 } // End of namespace MacVenture
145 
146 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: savefile.h:54
Definition: array.h:52
Definition: rect.h:144
Definition: path.h:52
Definition: stream.h:745
Definition: world.h:97
Definition: container.h:48
Definition: macventure.h:185
Definition: world.h:69
Definition: container.h:38