UFO: Alien Invasion
Loading...
Searching...
No Matches
inventory.h
Go to the documentation of this file.
1
4
5/*
6All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8Original file from Quake 2 v3.21: quake2-2.31/game/g_utils.c
9Copyright (C) 1997-2001 Id Software, Inc.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26*/
27
28#pragma once
29
30#include "q_shared.h"
31
32typedef 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
48public:
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);
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
74protected:
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 definition with all its containers
Definition inv_shared.h:525
void destroyInventory(Inventory *const inv)
Destroys inventory.
void removeInvList(Item *invList)
Definition inventory.cpp:32
void free(void *data)
Definition inventory.h:80
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).
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.
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.
int GetUsedSlots()
Calculate the number of used inventory slots.
void EquipActorMelee(Inventory *const inv, const teamDef_t *td)
Equip melee actor with item defined per teamDefs.
const char * invName
Definition inventory.h:46
void initInventory(const char *name, const csi_t *csi, const inventoryImport_t *import)
Initializes the inventory definition by linking the ->next pointers properly.
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 ...
bool removeFromInventory(Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
void EquipActor(character_t *const chr, const equipDef_t *ed, const objDef_t *weapon, int maxWeight)
void emptyContainer(Inventory *const inv, const containerIndex_t container)
Clears the linked list of a container - removes all items from this container.
void EquipActorRobot(Inventory *const inv, const objDef_t *weapon)
Equip robot actor with default weapon. (defined in ugv_t->weapon).
void destroyInventoryInterface(void)
void * alloc(size_t size)
Definition inventory.h:75
const csi_t * csi
Definition inventory.h:45
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
Item * addInvList(Inventory *const inv, const invDef_t *container)
Definition inventory.cpp:57
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 ...
item instance data, with linked list capability
Definition inv_shared.h:402
#define __attribute__(x)
Definition cxx.h:37
int32_t containerIndex_t
Definition inv_shared.h:46
inventory_action_t
Possible inventory actions for moving items between containers.
Definition inv_shared.h:65
voidpf void uLong size
Definition ioapi.h:42
Common header file.
QGL_EXTERN void(APIENTRY *qglActiveTexture)(GLenum texture)
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
Describes a character with all its attributes.
Definition chr_shared.h:388
The csi structure is the client-server-information structure which contains all the static data neede...
Definition q_shared.h:515
inventory definition for our menus
Definition inv_shared.h:371
void(* FreeAll)(void)
Definition inventory.h:35
void(* Free)(void *data)
Definition inventory.h:33
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264