ScummVM API documentation
item.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  * Additional copyright for this file:
8  * Copyright (C) 1995-1997 Presto Studios, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef PEGASUS_ITEMS_ITEM_H
26 #define PEGASUS_ITEMS_ITEM_H
27 
28 #include "common/endian.h"
29 
30 #include "pegasus/types.h"
31 #include "pegasus/util.h"
32 
33 namespace Common {
34  class Error;
35  class ReadStream;
36  class WriteStream;
37  class SeekableReadStream;
38 }
39 
40 namespace Pegasus {
41 
42 // JMPItemInfo contains resource data used by all Items.
43 
44 struct JMPItemInfo {
45  TimeValue infoLeftTime;
46  TimeValue infoRightStart;
47  TimeValue infoRightStop;
48  uint32 dragSpriteNormalID;
49  uint32 dragSpriteUsedID;
50 };
51 
52 // ItemStateEntry contains a single state/TimeValue pair. The TimeValue is
53 // the time value to set the shared area movie that corresponds with the given
54 // state of an inventory item.
55 
57  ItemState itemState;
58  TimeValue itemTime;
59 };
60 
61 struct ItemStateInfo {
62  uint16 numEntries; // For easy ResEdit access
63  ItemStateEntry *entries;
64 };
65 
66 // ItemExtraEntry
67 
68 static const short kLeftAreaExtra = 0;
69 static const short kMiddleAreaExtra = 1;
70 static const short kRightAreaExtra = 2;
71 
73  uint32 extraID;
74  uint16 extraArea;
75  TimeValue extraStart;
76  TimeValue extraStop;
77 };
78 
79 struct ItemExtraInfo {
80  uint16 numEntries; // For easy ResEdit access
81  ItemExtraEntry *entries;
82 };
83 
84 // Inventory info resource type and ID:
85 // Individual inventory items are stored in these resource types.
86 // Resource ID is item ID + kItemBaseResID.
87 
88 static const uint32 kItemInfoResType = MKTAG('I', 't', 'e', 'm'); // JMPItemInfoHandle
89 static const uint32 kLeftAreaInfoResType = MKTAG('L', 'e', 'f', 't'); // ItemStateInfoHandle
90 static const uint32 kMiddleAreaInfoResType = MKTAG('M', 'i', 'd', 'l'); // ItemStateInfoHandle
91 static const uint32 kRightAreaInfoResType = MKTAG('R', 'g', 'h', 't'); // ItemStateInfoHandle
92 static const uint32 kItemExtraInfoResType = MKTAG('I', 'X', 't', 'r'); // ItemExtraInfoHandle
93 
94 static const uint16 kItemBaseResID = 128;
95 
96 // Item IDs.
97 
98 static const ItemID kAirMask = 7;
99 static const ItemID kAntidote = 8;
100 static const ItemID kArgonCanister = 9;
101 static const ItemID kCardBomb = 10;
102 static const ItemID kCrowbar = 11;
103 static const ItemID kGasCanister = 12;
104 static const ItemID kHistoricalLog = 13;
105 static const ItemID kJourneymanKey = 14;
106 static const ItemID kKeyCard = 15;
107 static const ItemID kMachineGun = 16;
108 static const ItemID kMarsCard = 17;
109 static const ItemID kNitrogenCanister = 18;
110 static const ItemID kOrangeJuiceGlassFull = 19;
111 static const ItemID kOrangeJuiceGlassEmpty = 20;
112 static const ItemID kPoisonDart = 21;
113 static const ItemID kSinclairKey = 22;
114 static const ItemID kStunGun = 23;
115 static const ItemID kArgonPickup = 24;
116 
117 // Biochips.
118 
119 static const ItemID kAIBiochip = 0;
120 static const ItemID kArthurBiochip = 1;
121 static const ItemID kInterfaceBiochip = 1;
122 static const ItemID kMapBiochip = 2;
123 static const ItemID kOpticalBiochip = 3;
124 static const ItemID kPegasusBiochip = 4;
125 static const ItemID kRetinalScanBiochip = 5;
126 static const ItemID kShieldBiochip = 6;
127 
128 static const ItemID kNumItems = 25;
129 
130 // Item States.
131 
132 static const ItemState kAI000 = 0;
133 static const ItemState kAI005 = 1;
134 static const ItemState kAI006 = 2;
135 static const ItemState kAI010 = 3;
136 static const ItemState kAI015 = 4;
137 static const ItemState kAI016 = 5;
138 static const ItemState kAI020 = 6;
139 static const ItemState kAI024 = 7;
140 static const ItemState kAI100 = 8;
141 static const ItemState kAI101 = 9;
142 static const ItemState kAI105 = 10;
143 static const ItemState kAI106 = 11;
144 static const ItemState kAI110 = 12;
145 static const ItemState kAI111 = 13;
146 static const ItemState kAI115 = 14;
147 static const ItemState kAI116 = 15;
148 static const ItemState kAI120 = 16;
149 static const ItemState kAI121 = 17;
150 static const ItemState kAI124 = 18;
151 static const ItemState kAI125 = 19;
152 static const ItemState kAI126 = 20;
153 static const ItemState kAI200 = 21;
154 static const ItemState kAI201 = 22;
155 static const ItemState kAI202 = 23;
156 static const ItemState kAI205 = 24;
157 static const ItemState kAI206 = 25;
158 static const ItemState kAI210 = 26;
159 static const ItemState kAI211 = 27;
160 static const ItemState kAI212 = 28;
161 static const ItemState kAI215 = 29;
162 static const ItemState kAI216 = 30;
163 static const ItemState kAI220 = 31;
164 static const ItemState kAI221 = 32;
165 static const ItemState kAI222 = 33;
166 static const ItemState kAI224 = 34;
167 static const ItemState kAI225 = 35;
168 static const ItemState kAI226 = 36;
169 static const ItemState kAI300 = 37;
170 static const ItemState kAI301 = 38;
171 static const ItemState kAI302 = 39;
172 static const ItemState kAI303 = 40;
173 static const ItemState kAI305 = 41;
174 static const ItemState kAI306 = 42;
175 static const ItemState kAI310 = 43;
176 static const ItemState kAI311 = 44;
177 static const ItemState kAI312 = 45;
178 static const ItemState kAI313 = 46;
179 static const ItemState kAI315 = 47;
180 static const ItemState kAI316 = 48;
181 static const ItemState kAI320 = 49;
182 static const ItemState kAI321 = 50;
183 static const ItemState kAI322 = 51;
184 static const ItemState kAI323 = 52;
185 static const ItemState kAI324 = 53;
186 static const ItemState kAI325 = 54;
187 static const ItemState kAI326 = 55;
188 static const ItemState kNormalItem = 56;
189 static const ItemState kMapUnavailable = 57;
190 static const ItemState kMapEngaged = 58;
191 static const ItemState kOptical000 = 59;
192 static const ItemState kOptical001 = 60;
193 static const ItemState kOptical002 = 61;
194 static const ItemState kOptical010 = 62;
195 static const ItemState kOptical011 = 63;
196 static const ItemState kOptical012 = 64;
197 static const ItemState kOptical020 = 65;
198 static const ItemState kOptical021 = 66;
199 static const ItemState kOptical100 = 67;
200 static const ItemState kOptical101 = 68;
201 static const ItemState kOptical102 = 69;
202 static const ItemState kOptical110 = 70;
203 static const ItemState kOptical111 = 71;
204 static const ItemState kOptical112 = 72;
205 static const ItemState kOptical120 = 73;
206 static const ItemState kOptical121 = 74;
207 static const ItemState kOptical200 = 75;
208 static const ItemState kOptical201 = 76;
209 static const ItemState kOptical210 = 77;
210 static const ItemState kOptical211 = 78;
211 static const ItemState kPegasusTSA00 = 79;
212 static const ItemState kPegasusTSA10 = 80;
213 static const ItemState kPegasusPrehistoric00 = 81;
214 static const ItemState kPegasusPrehistoric01 = 82;
215 static const ItemState kPegasusPrehistoric10 = 83;
216 static const ItemState kPegasusPrehistoric11 = 84;
217 static const ItemState kPegasusMars00 = 85;
218 static const ItemState kPegasusMars01 = 86;
219 static const ItemState kPegasusMars10 = 87;
220 static const ItemState kPegasusMars11 = 88;
221 static const ItemState kPegasusNorad00 = 89;
222 static const ItemState kPegasusNorad01 = 90;
223 static const ItemState kPegasusNorad10 = 91;
224 static const ItemState kPegasusNorad11 = 92;
225 static const ItemState kPegasusWSC00 = 93;
226 static const ItemState kPegasusWSC01 = 94;
227 static const ItemState kPegasusWSC10 = 95;
228 static const ItemState kPegasusWSC11 = 96;
229 static const ItemState kPegasusCaldoria = 97;
230 static const ItemState kRetinalSimulating = 98;
231 static const ItemState kShieldNormal = 99;
232 static const ItemState kShieldRadiation = 100;
233 static const ItemState kShieldPlasma = 101;
234 static const ItemState kShieldCardBomb = 102;
235 static const ItemState kShieldDraining = 103;
236 static const ItemState kAirMaskEmptyOff = 104;
237 static const ItemState kAirMaskEmptyFilter = 105;
238 static const ItemState kAirMaskLowOff = 106;
239 static const ItemState kAirMaskLowFilter = 107;
240 static const ItemState kAirMaskLowOn = 108;
241 static const ItemState kAirMaskFullOff = 109;
242 static const ItemState kAirMaskFullFilter = 110;
243 static const ItemState kAirMaskFullOn = 111;
244 static const ItemState kArgonEmpty = 112;
245 static const ItemState kArgonFull = 113;
246 static const ItemState kFlashlightOff = 114;
247 static const ItemState kFlashlightOn = 115;
248 static const ItemState kNitrogenEmpty = 116;
249 static const ItemState kNitrogenFull = 117;
250 static const ItemState kFullGlass = 118;
251 static const ItemState kArthur000 = 119;
252 static const ItemState kArthur002 = 120;
253 static const ItemState kArthur010 = 121;
254 static const ItemState kArthur012 = 122;
255 static const ItemState kArthur100 = 123;
256 static const ItemState kArthur102 = 124;
257 static const ItemState kArthur110 = 125;
258 static const ItemState kArthur112 = 126;
259 
260 // Extra IDs.
261 
262 static const uint32 kRetinalScanSearching = 0;
263 static const uint32 kRetinalScanActivated = 1;
264 static const uint32 kShieldIntro = 2;
265 static const uint32 kRemoveAirMask = 3;
266 static const uint32 kRemoveArgon = 4;
267 static const uint32 kRemoveCrowbar = 5;
268 static const uint32 kGasCanLoop = 6;
269 static const uint32 kRemoveJourneymanKey = 7;
270 static const uint32 kRemoveMarsCard = 8;
271 static const uint32 kRemoveNitrogen = 9;
272 static const uint32 kRemoveGlass = 10;
273 static const uint32 kRemoveDart = 11;
274 static const uint32 kRemoveSinclairKey = 12;
275 
276 enum ItemType {
277  kInventoryItemType,
278  kBiochipItemType
279 };
280 
281 class Sprite;
282 
283 /*
284 
285  Item is an object which can be picked up and carried around.
286  Items have
287  a location
288  an ID.
289  weight
290  an owner (kNoActorID if no one is carrying the Item)
291 
292 */
293 
294 class Item : public IDObject {
295 public:
296  Item(const ItemID id, const NeighborhoodID neighborhood, const RoomID room, const DirectionConstant direction);
297  virtual ~Item();
298 
299  // WriteToStream writes everything EXCEPT the item's ID.
300  // It is assumed that the calling function will write and read the ID.
301  virtual void writeToStream(Common::WriteStream *stream);
302  virtual void readFromStream(Common::ReadStream *stream);
303 
304  virtual ActorID getItemOwner() const;
305  virtual void setItemOwner(const ActorID owner);
306 
307  void getItemRoom(NeighborhoodID &neighborhood, RoomID &room, DirectionConstant &direction) const;
308  void setItemRoom(const NeighborhoodID neighborhood, const RoomID room, const DirectionConstant direction);
309  NeighborhoodID getItemNeighborhood() const;
310 
311  virtual WeightType getItemWeight();
312 
313  virtual void setItemState(const ItemState state);
314  virtual ItemState getItemState() const;
315 
316  virtual ItemType getItemType() = 0;
317 
318  TimeValue getInfoLeftTime() const;
319  void getInfoRightTimes(TimeValue &, TimeValue &) const;
320  TimeValue getSharedAreaTime() const;
321 
322  Sprite *getDragSprite(const DisplayElementID) const;
323 
324  /*
325  select -- called when this item becomes current. Also called when the inventory
326  panel holding this item is raised and this is the current item.
327  deselect -- called when this item is no longer current.
328  activate -- called on the current item when the panel is closed.
329  */
330  // In an override of these three member functions, you must call the inherited
331  // member functions.
332  virtual void select();
333  virtual void deselect();
334  virtual bool isSelected() { return _isSelected; }
335 
336  virtual void activate() { _isActive = true; }
337  virtual bool isActive() { return _isActive; }
338  virtual void pickedUp() {}
339  virtual void addedToInventory() {}
340  virtual void removedFromInventory() {}
341  virtual void dropped() {}
342 
343  // Called when the shared area is taken by another item, but this item is still
344  // selected.
345  virtual void giveUpSharedArea() {}
346  virtual void takeSharedArea() {}
347 
348  void findItemExtra(const uint32 extraID, ItemExtraEntry &entry);
349 
350  // Reset to its original state at the beginning of the game
351  void reset();
352 
353 protected:
354  NeighborhoodID _itemNeighborhood;
355  RoomID _itemRoom;
356  DirectionConstant _itemDirection;
357  ActorID _itemOwnerID;
358  WeightType _itemWeight;
359  ItemState _itemState;
360 
361  NeighborhoodID _originalNeighborhood;
362  RoomID _originalRoom;
363  DirectionConstant _originalDirection;
364 
365  JMPItemInfo _itemInfo;
366  ItemStateInfo _sharedAreaInfo;
367  ItemExtraInfo _itemExtras;
368  bool _isActive;
369  bool _isSelected;
370 
371  static void getItemStateEntry(ItemStateInfo, uint32, ItemState &, TimeValue &);
372  static void findItemStateEntryByState(ItemStateInfo, ItemState, TimeValue &);
373  static ItemStateInfo readItemState(Common::SeekableReadStream *stream);
374 };
375 
376 } // End of namespace Pegasus
377 
378 #endif
Definition: stream.h:77
Definition: elements.h:168
Definition: stream.h:745
Definition: item.h:56
Definition: item.h:79
Definition: item.h:294
Definition: item.h:44
Definition: util.h:38
Definition: algorithm.h:29
Definition: item.h:72
#define MKTAG(a0, a1, a2, a3)
Definition: endian.h:188
Definition: stream.h:385
Definition: item.h:61
Definition: ai_action.h:33