| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/Inventory.h $ |
| 21 | * $Revision: 46 $ |
| 22 | * $Date: 4/28/99 5:22a $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * Inventory control header |
| 26 | * |
| 27 | * $Log: /DescentIII/main/Inventory.h $ |
| 28 | * |
| 29 | * 46 4/28/99 5:22a Jeff |
| 30 | * added function to get list of inventory items, without having to go |
| 31 | * through inventory one by one |
| 32 | * |
| 33 | * 45 4/20/99 3:06p Jeff |
| 34 | * fixed inventory displaying of non-usable items |
| 35 | * |
| 36 | * 44 4/20/99 1:14p Samir |
| 37 | * added function to determine if inventory item is usable. |
| 38 | * |
| 39 | * 43 4/14/99 3:56a Jeff |
| 40 | * fixed case mismatch in #includes |
| 41 | * |
| 42 | * 42 3/02/99 4:41p Jeff |
| 43 | * Fixed inventory save/load |
| 44 | * |
| 45 | * 41 2/25/99 8:54p Jeff |
| 46 | * Inventory supports level change persistant items. Inventory supports |
| 47 | * time-out objects. Inventory Reset changed (takes a level of reset |
| 48 | * now). Quad lasers stay across level change (single player). Guidebot |
| 49 | * bug fixed (now back in ship on level start). Quads time out when |
| 50 | * spewed. Invulnerability and cloak powerups no longer use game |
| 51 | * event/callbacks, so they can be saved in game saves (moved to |
| 52 | * MakePlayerInvulnerable and MakeObjectInvisible) |
| 53 | * |
| 54 | * 40 2/23/99 7:37p Jeff |
| 55 | * fixed reset so it doesn't remove non-spewable items...made multiplayer |
| 56 | * friendly |
| 57 | * |
| 58 | * 39 2/14/99 4:29a Jeff |
| 59 | * able to set custom descriptions for an item when adding it |
| 60 | * |
| 61 | * 38 2/13/99 12:37a Jeff |
| 62 | * new inventory system. Supports objects that don't die when put in (by |
| 63 | * objhandles). Also changed Inventory::Reset() |
| 64 | * |
| 65 | * 37 2/08/99 5:25p Jeff |
| 66 | * removed all calls to MultiSendRemoveObject, incorportated into |
| 67 | * SetObjectDeadFlag. Fixes sequencing issues in multiplayer |
| 68 | * |
| 69 | * 36 1/18/99 2:46p Matt |
| 70 | * Combined flags & flags2 fields in object struct |
| 71 | * |
| 72 | * 35 1/13/99 2:28a Chris |
| 73 | * Massive AI, OSIRIS update |
| 74 | * |
| 75 | * 34 1/08/99 2:55p Samir |
| 76 | * Ripped out OSIRIS1. |
| 77 | * |
| 78 | * 33 11/11/98 12:05p Jeff |
| 79 | * made inventory.add(object *) a private function...dangerous for |
| 80 | * multiplayer if called |
| 81 | * |
| 82 | * 32 8/19/98 2:17p Jeff |
| 83 | * added a function to get the aux type/id |
| 84 | * |
| 85 | * 31 8/19/98 12:38p Jason |
| 86 | * made countermeasure spewing work correctly |
| 87 | * |
| 88 | * 30 8/13/98 11:56a Jeff |
| 89 | * handle new flags for inventory use |
| 90 | * |
| 91 | * 29 8/10/98 2:20p Jeff |
| 92 | * reset takes a bool now whether to reset everything |
| 93 | * |
| 94 | * 28 7/10/98 7:49p Jeff |
| 95 | * fixed way of getting icon info for countermeasure |
| 96 | * |
| 97 | * 27 7/08/98 6:01p Jeff |
| 98 | * first chance at making multiplayer friendly |
| 99 | * |
| 100 | * 26 7/06/98 7:17p Jeff |
| 101 | * countermeasure support added |
| 102 | * |
| 103 | * 25 7/03/98 3:10p Jeff |
| 104 | * some error handling and added functions to get inventory information |
| 105 | * |
| 106 | * 24 4/24/98 7:09p Jeff |
| 107 | * added a flag for non-useable inventory items |
| 108 | * |
| 109 | * 23 4/23/98 12:02p Jeff |
| 110 | * added a limit to how many items you can put in your inventory |
| 111 | * |
| 112 | * 22 4/19/98 7:32p Jeff |
| 113 | * Moved inventory wrappers to DLLWrappers |
| 114 | * |
| 115 | * 21 4/03/98 11:49a Jeff |
| 116 | * Added another function wrapper, renamed others to fit naming convention |
| 117 | * |
| 118 | * 20 3/31/98 3:55p Jeff |
| 119 | * Added some inventory wrappers |
| 120 | * |
| 121 | * 19 3/26/98 2:58p Jeff |
| 122 | * Added a GetTypeIDCount function |
| 123 | * |
| 124 | * 18 3/23/98 5:36p Jeff |
| 125 | * added a parameter to Add to specify if you want it destroyed when it's |
| 126 | * added |
| 127 | * |
| 128 | * 17 3/20/98 2:44p Jeff |
| 129 | * removed ValidatePos() from ResetPos()....ValidatePos() should be called |
| 130 | * after a ResetPos() if you want to make sure you are on a selectable |
| 131 | * item |
| 132 | * |
| 133 | * 16 2/20/98 5:02p Jeff |
| 134 | * fixed bug so you can switch to a nonselectable item while playing the |
| 135 | * game |
| 136 | * |
| 137 | * 15 2/20/98 4:56p Jeff |
| 138 | * Changed inventory so it now supports non selectable items, plus made |
| 139 | * the list into a circular list |
| 140 | * |
| 141 | * 14 2/15/98 4:49p Jeff |
| 142 | * Added a reset function to clear the inventory |
| 143 | * |
| 144 | * 13 2/11/98 4:54p Jeff |
| 145 | * Moved the inventory into the Player struct |
| 146 | * |
| 147 | * 12 2/09/98 4:58p Jeff |
| 148 | * Connected inventory to hud |
| 149 | * |
| 150 | * 11 2/07/98 6:34p Jeff |
| 151 | * |
| 152 | * 10 2/06/98 2:04p Jeff |
| 153 | * inventory system much more stable now, and works with telcom |
| 154 | * |
| 155 | * 9 2/05/98 7:38p Jeff |
| 156 | * changed inventory system completly...now is classes...works in telcom |
| 157 | * to, added use feature |
| 158 | * |
| 159 | * 8 2/04/98 7:42p Jeff |
| 160 | * began connecting telcom to inventory |
| 161 | * |
| 162 | * 7 2/04/98 12:18p Jeff |
| 163 | * |
| 164 | * 6 2/03/98 6:15p Jeff |
| 165 | * |
| 166 | * 5 1/31/98 8:49p Jeff |
| 167 | * Added a function to count the number of items in the inventory |
| 168 | * |
| 169 | * 4 1/31/98 8:12p Jeff |
| 170 | * Added more inventory functions |
| 171 | * |
| 172 | * 3 1/30/98 7:02p Jeff |
| 173 | * wrote basic internals inven system |
| 174 | * |
| 175 | * 2 1/29/98 3:52p Jeff |
| 176 | * initial creation |
| 177 | * |
| 178 | * $NoKeywords: $ |
| 179 | */ |
| 180 | |
| 181 | #ifndef __INVENTORY_H__ |
| 182 | #define __INVENTORY_H__ |
| 183 | |
| 184 | #include "pstypes.h" |
| 185 | #include "cfile.h" |
| 186 | |
| 187 | struct object; |
| 188 | |
| 189 | #define MAX_UNIQUE_INVEN_ITEMS 10 |
| 190 | |
| 191 | #define INVF_SELECTABLE 0x0003 // old 1 |
| 192 | #define INVF_USEABLE 0x0003 // old 2 |
| 193 | #define INVF_MISSIONITEM 0x0004 // this item lasts across levels |
| 194 | #define INVF_NOREMOVEONUSE 0x0008 |
| 195 | #define INVF_VISWHENUSED 0x0010 |
| 196 | #define INVF_OBJECT 0x0020 // this item isn't a type/id...but an objhandle |
| 197 | #define INVF_NOTSPEWABLE 0x0040 // this object should not spew...stay in inventory after death |
| 198 | #define INVF_TIMEOUTONSPEW 0x0080 // this object/item times out when it's spewed |
| 199 | |
| 200 | // Inventory reset stage settings |
| 201 | #define INVRESET_ALL 0 |
| 202 | #define INVRESET_LEVELCHANGE 1 |
| 203 | #define INVRESET_DEATHSPEW 2 |
| 204 | |
| 205 | struct tInvenList { |
| 206 | bool selectable; |
| 207 | char *hud_name; |
| 208 | int amount; |
| 209 | }; |
| 210 | |
| 211 | struct tInvenInfo { |
| 212 | int count; |
| 213 | char *description; |
| 214 | char *icon_name; |
| 215 | char *name; |
| 216 | int flags; |
| 217 | uint16_t iflags; // Inventory item flags |
| 218 | int type; |
| 219 | int id; |
| 220 | }; |
| 221 | |
| 222 | struct inven_item { |
| 223 | |
| 224 | int type; // what type of object this is... robot, weapon, hostage, powerup, fireball |
| 225 | // if INVF_OBJECT, this is the object handle |
| 226 | int otype; // countermeasure powerup type |
| 227 | int id; // which form of object...which powerup, robot, etc. |
| 228 | // if INVF_OBJECT, this is -1 |
| 229 | int oid; // countermeasure powerup id |
| 230 | int flags; // misc flags |
| 231 | uint16_t pad2; // keep alignment |
| 232 | |
| 233 | int count; // how many of this type/id (not INVF_OBJECT) |
| 234 | |
| 235 | char *description; |
| 236 | char *icon_name; |
| 237 | char *name; |
| 238 | |
| 239 | uint16_t iflags; // Inventory item flags |
| 240 | |
| 241 | inven_item *next, *prev; // pointer to next inventory item |
| 242 | }; |
| 243 | |
| 244 | class Inventory { |
| 245 | public: |
| 246 | Inventory(); |
| 247 | ~Inventory(); |
| 248 | // adds a type/id item to the inventory (returns true on success) |
| 249 | bool Add(int type, int id, object *parent = NULL, int aux_type = -1, int aux_id = -1, int flags = 0, |
| 250 | const char *description = NULL); |
| 251 | // adds an object to the inventory (marked by it's objhandle) |
| 252 | bool AddObject(int object_handle, int flags = 0, const char *description = NULL); |
| 253 | // adds a special cased CounterMeasure into the inventory |
| 254 | bool AddCounterMeasure(int id, int aux_type = -1, int aux_id = -1, int flags = 0, const char *description = NULL); |
| 255 | // removes an item from the inventory (reduces it's count by one...if there is no more, then it goes bye-bye) |
| 256 | bool Remove(int type, int id = -1); |
| 257 | // uses an item in the inventory (also reduces its count by one...if there is no more, then it goes bye-bye) |
| 258 | bool Use(int type, int id, object *parent = NULL); |
| 259 | bool Use(int objhandle, object *parent = NULL); |
| 260 | // returns how many unique type/ids are in the inventory |
| 261 | int Size(void); |
| 262 | // returns true if there is an item in the inventory with the given type/id (or objhandle if id is -1) |
| 263 | bool CheckItem(int type, int id = -1); |
| 264 | // Resets the inventory, cleaning it out |
| 265 | // in_game: set to true if this is being called from during gameplay |
| 266 | // reset_stage: |
| 267 | // INVRESET_ALL: Reset _EVERYTHING_ |
| 268 | // INVRESET_LEVELCHANGE: Remove everything except those that last across levels |
| 269 | // INVRESET_DEATHSPEW: Remove everything except those that do not spew (Default) |
| 270 | void Reset(bool in_game, int reset_stage = INVRESET_DEATHSPEW); |
| 271 | // resets the position pointer in the list to the beginning |
| 272 | void ResetPos(void); |
| 273 | // moves the position pointer to the next inventory item |
| 274 | void NextPos(bool skip = false); |
| 275 | // moves the position pointer to the previous inventory item |
| 276 | void PrevPos(bool skip = false); |
| 277 | // returns the type/id of the item at the current position |
| 278 | // return true if it is a real object |
| 279 | bool GetPosTypeID(int &type, int &id); |
| 280 | // returns the aux type/id of the item |
| 281 | // return true if it is a real object |
| 282 | bool GetAuxPosTypeID(int &type, int &id); |
| 283 | // returns the description of the item at the current position |
| 284 | char *GetPosDescription(void); |
| 285 | // returns the icon name of the item at the current position |
| 286 | char *GetPosIconName(void); |
| 287 | // returns the name of the item at the current position |
| 288 | char *GetPosName(void); |
| 289 | // return information about the current position item |
| 290 | // return true if it is a real object |
| 291 | bool GetPosInfo(uint16_t &iflags, int &flags); |
| 292 | // returns the count of the item at the current position |
| 293 | int GetPosCount(void); |
| 294 | // returns true if the position pointer is at the begining of the inventory list |
| 295 | bool AtBeginning(void); |
| 296 | // returns false if the position pointer is at the end of the inventory list |
| 297 | bool AtEnd(void); |
| 298 | // jump right to an item in the inventory |
| 299 | void GotoPos(int newpos); |
| 300 | void GotoPos(int type, int id); |
| 301 | // uses the currently selected item |
| 302 | bool UsePos(object *parent = NULL); |
| 303 | // returns the 'index' position of the current position |
| 304 | int GetPos(void); |
| 305 | // checks the pos, if its on a nonselectable item it will move to the next selectable (NULL if none) |
| 306 | void ValidatePos(bool forward = true); |
| 307 | // returns whether an item is selectable |
| 308 | bool IsSelectable(void); |
| 309 | bool IsUsable(void); |
| 310 | // returns how many of an type/id is in the inventory |
| 311 | int GetTypeIDCount(int type, int id); |
| 312 | // searches the inventory for the specified type/id, sets the pos to it |
| 313 | bool FindPos(int type, int id = -1); |
| 314 | // saves the inventory to the file (returns number of bytes written) |
| 315 | int SaveInventory(CFILE *file); |
| 316 | // restores the inventory from file (returns number of bytes read) |
| 317 | int ReadInventory(CFILE *file); |
| 318 | // gets a detailed list of information about what is in the inventory |
| 319 | // returns the number of items filled in. |
| 320 | int GetInventoryItemList(tInvenList *list, int max_amount, int *cur_sel); |
| 321 | |
| 322 | private: |
| 323 | // adds an item to the inventory (returns true on success) |
| 324 | bool AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flags, const char *description = NULL); |
| 325 | void RemoveNode(inven_item *node); |
| 326 | // sends a request to the server to use a particular item in the inventory |
| 327 | void SendRequestToServerToUse(int type, int id = -1); |
| 328 | inven_item *FindItem(int type, int id = -1); |
| 329 | inven_item *root; |
| 330 | int count; |
| 331 | inven_item *pos; // used when looking through inventory |
| 332 | }; |
| 333 | |
| 334 | void InventorySwitch(bool forward); |
| 335 | // moves to the next/prev item in the counter measures list (forward==TRUE means forward, forward==FALSE means go |
| 336 | // backwards) |
| 337 | void CounterMeasuresSwitch(bool forward); |
| 338 | // Checks for an object in any of the players inventorys and removes it |
| 339 | void InventoryRemoveObject(int objhandle); |
| 340 | |
| 341 | #endif |