Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
inventory.qh File Reference
#include "all.qh"
#include <client/hud/panel/pickup.qh>
Include dependency graph for inventory.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Inventory

Macros

#define G_MAJOR(id)
#define G_MINOR(id)

Functions

void Inventory_clear (entity store)
bool Inventory_customize (entity this, entity client)
void Inventory_delete (entity e)
void Inventory_new (PlayerState this)
void Inventory_pickupitem (Pickup this, entity player)
void Inventory_remove (entity this)
bool Inventory_Send (Inventory this, Client to, int sf)
void Inventory_update (entity e)
void Inventory_Write (Inventory data, Inventory store)
void InventoryStorage_attach (entity e)
void InventoryStorage_delete (entity e)
 NET_HANDLE (ENT_CLIENT_INVENTORY, bool isnew)
 NET_HANDLE (TE_CSQC_WEAPONPICKUP, bool isnew)
 STATIC_INIT (Inventory)

Variables

Inventory g_inventory
Inventory inventory
 Player inventory.
const int Inventory_groups_major = 4
const int Inventory_groups_minor = 8
Inventory inventory_store
 Player inventory storage (holds previous state)
int minorBitsArr [Inventory_groups_major]

Macro Definition Documentation

◆ G_MAJOR

#define G_MAJOR ( id)
Value:
const int Inventory_groups_minor
Definition inventory.qh:18
float floor(float f)

Definition at line 35 of file inventory.qh.

Referenced by Inventory_Write().

◆ G_MINOR

#define G_MINOR ( id)
Value:

Definition at line 36 of file inventory.qh.

Referenced by Inventory_Write().

Function Documentation

◆ Inventory_clear()

void Inventory_clear ( entity store)

Definition at line 169 of file inventory.qh.

170{
171 // NOTE: you will need to perform Inventory_update after this to update the storage entity
172 // (unless store is the storage entity)
173 FOREACH(Items, true, {
174 .int fld = inv_items[it.m_id];
175 store.(fld) = 0;
176 });
177}
#define FOREACH(list, cond, body)
Definition iter.qh:19

References entity(), and FOREACH.

Referenced by reset_map().

◆ Inventory_customize()

bool Inventory_customize ( entity this,
entity client )

Definition at line 143 of file inventory.qh.

144{
145 // sends to spectators too!
146 return (PS(client) && PS(client).inventory == this);
147}
Inventory inventory
Player inventory.
Definition inventory.qh:12
#define PS(this)
Definition state.qh:18

References entity(), inventory, and PS.

Referenced by Inventory_new().

◆ Inventory_delete()

void Inventory_delete ( entity e)

Definition at line 158 of file inventory.qh.

158{ delete(e.inventory); }

References entity().

Referenced by PlayerState_detach().

◆ Inventory_new()

void Inventory_new ( PlayerState this)

Definition at line 149 of file inventory.qh.

150{
151 Inventory inv = NEW(Inventory);
153 this.inventory = inv;
154 inv.owner = this;
155 Net_LinkEntity(inv, false, 0, Inventory_Send);
156}
bool Inventory_Send(Inventory this, Client to, int sf)
Definition inventory.qh:134
bool Inventory_customize(entity this, entity client)
Definition inventory.qh:143
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:123
#define NEW(cname,...)
Definition oo.qh:117
#define setcefc(e, f)

References Inventory_customize(), Inventory_Send(), Net_LinkEntity(), NEW, and setcefc.

Referenced by PlayerState_attach().

◆ Inventory_pickupitem()

void Inventory_pickupitem ( Pickup this,
entity player )

Definition at line 161 of file inventory.qh.

162{
163 //LOG_DEBUGF("entity %i picked up %s", player, this.m_name);
164 entity store = IS_PLAYER(player) ? PS(player) : player;
165 ++store.inventory.inv_items[this.m_id];
166 Inventory_update(store);
167}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:243
int m_id
Definition effect.qh:19
void Inventory_update(entity e)
Definition inventory.qh:159

References entity(), Inventory_update(), IS_PLAYER, m_id, and PS.

Referenced by Pickup::giveTo(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ Inventory_remove()

void Inventory_remove ( entity this)

Definition at line 44 of file inventory.qh.

45{
46 if(g_inventory == this)
48}
Inventory g_inventory
Definition inventory.qh:42
#define NULL
Definition post.qh:14

References entity(), g_inventory, and NULL.

Referenced by NET_HANDLE().

◆ Inventory_Send()

bool Inventory_Send ( Inventory this,
Client to,
int sf )

Definition at line 134 of file inventory.qh.

135{
136 TC(Inventory, this);
137 WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
138 TC(PlayerState, this.owner);
139 Inventory_Write(this, to.inventory_store);
140 return true;
141}
Purpose: common player state, usable on client and server Client: singleton representing the viewed p...
Definition state.qh:8
entity owner
Definition main.qh:87
void Inventory_Write(Inventory data, Inventory store)
Definition inventory.qh:87
#define TC(T, sym)
Definition _all.inc:82
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221

References Inventory_Write(), MSG_ENTITY, owner, TC, and WriteHeader.

Referenced by Inventory_new().

◆ Inventory_update()

void Inventory_update ( entity e)

Definition at line 159 of file inventory.qh.

159{ e.inventory.SendFlags = 0xFFFFFF; }

References entity().

Referenced by Inventory_pickupitem(), and reset_map().

◆ Inventory_Write()

void Inventory_Write ( Inventory data,
Inventory store )

Definition at line 87 of file inventory.qh.

88{
89 if (!data) {
91 return;
92 }
93 TC(Inventory, data);
94
95 for (int i = 0; i < Inventory_groups_major; ++i)
96 minorBitsArr[i] = 0;
97
98 int majorBits = 0;
99 FOREACH(Items, true, {
100 .int fld = inv_items[it.m_id];
101 const bool changed = store.(fld) != data.(fld);
102 store.(fld) = data.(fld);
103 if (changed) {
104 int maj = G_MAJOR(it.m_id);
105 majorBits = BITSET(majorBits, BIT(maj), true);
106 minorBitsArr[maj] = BITSET(minorBitsArr[maj], BIT(G_MINOR(it.m_id)), true);
107 }
108 });
109
110 Writebits(MSG_ENTITY, majorBits, Inventory_groups_major);
111 for (int i = 0; i < Inventory_groups_major; ++i)
112 {
113 if (!(majorBits & BIT(i)))
114 continue;
115
116 const int minorBits = minorBitsArr[i];
117 Writebits(MSG_ENTITY, minorBits, Inventory_groups_minor);
118 for (int j = 0; j < Inventory_groups_minor; ++j)
119 {
120 if (!(minorBits & BIT(j)))
121 continue;
122
123 const entity it = REGISTRY_GET(Items, Inventory_groups_minor * i + j);
124 WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
125 }
126 }
127}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define BITSET(var, mask, flag)
Definition bits.qh:11
int inv_items[REGISTRY_MAX(Items)]
Stores counts of items, the id being the index.
Definition inventory.qh:8
int minorBitsArr[Inventory_groups_major]
Definition inventory.qh:86
#define G_MAJOR(id)
Definition inventory.qh:35
const int Inventory_groups_major
Definition inventory.qh:19
#define G_MINOR(id)
Definition inventory.qh:36
void WriteShort(float data, float dest, float desto)
void WriteByte(float data, float dest, float desto)
#define REGISTRY_GET(id, i)
Definition registry.qh:43

References BIT, BITSET, entity(), FOREACH, G_MAJOR, G_MINOR, Inventory::inv_items, Inventory_groups_major, Inventory_groups_minor, minorBitsArr, MSG_ENTITY, REGISTRY_GET, TC, WriteByte(), and WriteShort().

Referenced by Inventory_Send().

◆ InventoryStorage_attach()

void InventoryStorage_attach ( entity e)

Definition at line 179 of file inventory.qh.

179{ e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; }

References entity(), and NEW.

◆ InventoryStorage_delete()

void InventoryStorage_delete ( entity e)

Definition at line 180 of file inventory.qh.

180{ delete(e.inventory_store); }

References entity().

◆ NET_HANDLE() [1/2]

NET_HANDLE ( ENT_CLIENT_INVENTORY ,
bool isnew )

Definition at line 50 of file inventory.qh.

51{
52 make_pure(this);
53 g_inventory = this;
54 this.entremove = Inventory_remove;
55 const int majorBits = Readbits(Inventory_groups_major);
56 for (int i = 0; i < Inventory_groups_major; ++i) {
57 if (!(majorBits & BIT(i))) {
58 continue;
59 }
60 const int minorBits = Readbits(Inventory_groups_minor);
61 for (int j = 0; j < Inventory_groups_minor; ++j) {
62 if (!(minorBits & BIT(j))) {
63 continue;
64 }
65 const GameItem it = REGISTRY_GET(Items, Inventory_groups_minor * i + j);
66 .int fld = inv_items[it.m_id];
67 int prev = this.(fld);
68 int next = this.(fld) = ReadByte();
69
70 Pickup_Update(it, next - prev);
71 LOG_DEBUGF("%s: %.0f -> %.0f", it.m_name, prev, next);
72 }
73 }
74 return true;
75}
int m_id
Definition item.qh:127
void Pickup_Update(entity item, int count)
Definition pickup.qc:15
prev
Definition all.qh:71
next
Definition all.qh:93
void Inventory_remove(entity this)
Definition inventory.qh:44
int ReadByte()
int Readbits(int num)
Definition net.qh:372
#define LOG_DEBUGF(...)
Definition log.qh:81
#define make_pure(e)
direct use is
Definition oo.qh:13

References BIT, g_inventory, Inventory_groups_major, Inventory_groups_minor, Inventory_remove(), LOG_DEBUGF, GameItem::m_id, make_pure, next, Pickup_Update(), prev, Readbits(), ReadByte(), and REGISTRY_GET.

◆ NET_HANDLE() [2/2]

NET_HANDLE ( TE_CSQC_WEAPONPICKUP ,
bool isnew )

Definition at line 77 of file inventory.qh.

78{
79 const Weapon it = REGISTRY_GET(Weapons, ReadByte());
80 Pickup_Update(it, 1);
81 return true;
82}
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:44
Weapons
Definition guide.qh:113

References Pickup_Update(), ReadByte(), REGISTRY_GET, and Weapons.

◆ STATIC_INIT()

STATIC_INIT ( Inventory )

Definition at line 24 of file inventory.qh.

25{
27 error("Inventory_groups_minor is not a multiple of 8.");
28 int min_major_value = ceil(REGISTRY_COUNT(Items) / Inventory_groups_minor);
29 if (Inventory_groups_major < min_major_value)
30 error(sprintf("Inventory_groups_major can not be < %d.", min_major_value));
31}
float ceil(float f)
#define error
Definition pre.qh:6
#define REGISTRY_COUNT(id)
Definition registry.qh:18

References ceil(), error, floor(), Inventory_groups_major, Inventory_groups_minor, and REGISTRY_COUNT.

Variable Documentation

◆ g_inventory

◆ inventory

Inventory inventory

Player inventory.

Definition at line 12 of file inventory.qh.

Referenced by Inventory_customize().

◆ Inventory_groups_major

const int Inventory_groups_major = 4

Definition at line 19 of file inventory.qh.

Referenced by Inventory_Write(), NET_HANDLE(), and STATIC_INIT().

◆ Inventory_groups_minor

const int Inventory_groups_minor = 8

Definition at line 18 of file inventory.qh.

Referenced by Inventory_Write(), NET_HANDLE(), and STATIC_INIT().

◆ inventory_store

Inventory inventory_store

Player inventory storage (holds previous state)

Definition at line 14 of file inventory.qh.

Referenced by PlayerState_detach().

◆ minorBitsArr

int minorBitsArr[Inventory_groups_major]

Definition at line 86 of file inventory.qh.

Referenced by Inventory_Write().