UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
inventory.h
Go to the documentation of this file.
1 
5 /*
6 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 Original file from Quake 2 v3.21: quake2-2.31/game/g_utils.c
9 Copyright (C) 1997-2001 Id Software, Inc.
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 See the GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26 */
27 
28 #pragma once
29 
30 #include "q_shared.h"
31 
32 typedef struct inventoryImport_s {
33  void (*Free) (void* data);
34 
36 
37  void* (*Alloc) (size_t size);
39 
41 {
42  const inventoryImport_t* import;
43  Item* _invList; /* @todo figure out WTF this is good for (Duke, 11.3.2013) */
45  const csi_t* csi;
46  const char* invName;
47 
48 public:
50 
51  void initInventory (const char* name, const csi_t* csi, const inventoryImport_t* import);
52  bool removeFromInventory (Inventory* const inv, const invDef_t* container, Item* fItem) __attribute__((warn_unused_result));
53  Item* addToInventory (Inventory* const inv, const Item* const item, const invDef_t* container, int x, int y,
54  int amount) __attribute__((warn_unused_result));
55 
56  inventory_action_t moveInInventory (Inventory* const inv, const invDef_t* from, Item* item, const invDef_t* to,
57  int tx, int ty, int* TU, Item** icp);
58 
59  bool tryAddToInventory (Inventory* const inv, const Item* const item, const invDef_t* container);
60  void destroyInventory (Inventory* const inv);
61  void destroyInventoryInterface(void);
62  void emptyContainer (Inventory* const inv, const containerIndex_t container);
63 
64  void EquipActor (character_t* const chr, const equipDef_t* ed, const objDef_t* weapon, int maxWeight);
65 
66  void EquipActorNormal (character_t* const chr, const equipDef_t* ed, int maxWeight);
67 
68  void EquipActorMelee (Inventory* const inv, const teamDef_t* td);
69 
70  void EquipActorRobot (Inventory* const inv, const objDef_t* weapon);
71 
72  int GetUsedSlots ();
73 
74 protected:
75  inline void* alloc (size_t size)
76  {
77  return import->Alloc(size);
78  }
79 
80  inline void free (void* data)
81  {
82  import->Free(data);
83  }
84  void removeInvList (Item* invList);
85  Item* addInvList (Inventory* const inv, const invDef_t* container);
86  float GetInventoryState (const Inventory* inventory, int& slowestFd);
87  int PackAmmoAndWeapon (character_t* const chr, const objDef_t* weapon, int missedPrimary, const equipDef_t* ed, int maxWeight);
88 };
inventory_action_t
Possible inventory actions for moving items between containers.
Definition: inv_shared.h:65
bool tryAddToInventory(Inventory *const inv, const Item *const item, const invDef_t *container)
Tries to add an item to a container (in the inventory inv).
Definition: inventory.cpp:470
void destroyInventory(Inventory *const inv)
Destroys inventory.
Definition: inventory.cpp:521
int PackAmmoAndWeapon(character_t *const chr, const objDef_t *weapon, int missedPrimary, const equipDef_t *ed, int maxWeight)
Pack a weapon, possibly with some ammo.
Definition: inventory.cpp:566
Common header file.
void * alloc(size_t size)
Definition: inventory.h:75
inventory_action_t moveInInventory(Inventory *const inv, const invDef_t *from, Item *item, const invDef_t *to, int tx, int ty, int *TU, Item **icp)
Conditions for moving items between containers.
Definition: inventory.cpp:239
const csi_t * csi
Definition: inventory.h:45
void(* FreeAll)(void)
Definition: inventory.h:35
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
#define __attribute__(x)
Definition: cxx.h:37
const char * invName
Definition: inventory.h:46
item instance data, with linked list capability
Definition: inv_shared.h:402
inventory definition with all its containers
Definition: inv_shared.h:525
struct inventoryImport_s inventoryImport_t
GLsizei size
Definition: r_gl.h:152
void EquipActor(character_t *const chr, const equipDef_t *ed, const objDef_t *weapon, int maxWeight)
Definition: inventory.cpp:947
The csi structure is the client-server-information structure which contains all the static data neede...
Definition: q_shared.h:515
void initInventory(const char *name, const csi_t *csi, const inventoryImport_t *import)
Initializes the inventory definition by linking the ->next pointers properly.
Definition: inventory.cpp:986
void EquipActorNormal(character_t *const chr, const equipDef_t *ed, int maxWeight)
Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from ...
Definition: inventory.cpp:741
Item * addInvList(Inventory *const inv, const invDef_t *container)
Definition: inventory.cpp:57
void(* Free)(void *data)
Definition: inventory.h:33
void EquipActorRobot(Inventory *const inv, const objDef_t *weapon)
Equip robot actor with default weapon. (defined in ugv_t->weapon)
Definition: inventory.cpp:705
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
int32_t containerIndex_t
Definition: inv_shared.h:46
Item * addToInventory(Inventory *const inv, const Item *const item, const invDef_t *container, int x, int y, int amount) __attribute__((warn_unused_result))
Add an item to a specified container in a given inventory.
Definition: inventory.cpp:91
void EquipActorMelee(Inventory *const inv, const teamDef_t *td)
Equip melee actor with item defined per teamDefs.
Definition: inventory.cpp:682
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
void free(void *data)
Definition: inventory.h:80
inventory definition for our menus
Definition: inv_shared.h:371
float GetInventoryState(const Inventory *inventory, int &slowestFd)
Get the state of the given inventory: the items weight and the min TU needed to make full use of all ...
Definition: inventory.cpp:540
GLsizei const GLvoid * data
Definition: r_gl.h:152
void emptyContainer(Inventory *const inv, const containerIndex_t container)
Clears the linked list of a container - removes all items from this container.
Definition: inventory.cpp:501
void destroyInventoryInterface(void)
Definition: inventory.cpp:999
bool removeFromInventory(Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
Definition: inventory.cpp:152
void removeInvList(Item *invList)
Definition: inventory.cpp:32
int GetUsedSlots()
Calculate the number of used inventory slots.
Definition: inventory.cpp:966
Describes a character with all its attributes.
Definition: chr_shared.h:369