From e14822e0027ed17bf638cd15dfa3c9221c174913 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 26 Oct 2018 08:41:14 +1000 Subject: [PATCH] Clean up inventory creation code a bit so that it's somewhat spectatable --- qcsrc/common/items/inventory.qh | 19 +++++++++++-------- qcsrc/common/state.qc | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index ba824f40b4..2ec0cdb7b1 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -106,20 +106,23 @@ bool Inventory_Send(Inventory this, Client to, int sf) { TC(Inventory, this); WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY); - entity e = this.owner; - if (IS_SPEC(e)) e = PS(e.enemy); // TODO: how can this *ever* be the case? - TC(Player, e); - Inventory data = e.inventory; - Inventory_Write(data); + TC(PlayerState, this.owner); + Inventory_Write(this); return true; } -void Inventory_new(entity e) +bool Inventory_customize(entity this, entity client) +{ + // sends to spectators too! + return (PS(client) && PS(client).inventory == this); +} + +void Inventory_new(PlayerState this) { Inventory inv = NEW(Inventory), bak = NEW(Inventory); inv.inventory = bak; - inv.drawonlytoclient = IS_CLIENT(e) ? e : e.m_client; - Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send); + setcefc(inv, Inventory_customize); + Net_LinkEntity((inv.owner = this).inventory = inv, false, 0, Inventory_Send); } void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } diff --git a/qcsrc/common/state.qc b/qcsrc/common/state.qc index 2e3a262a59..fc3530744c 100644 --- a/qcsrc/common/state.qc +++ b/qcsrc/common/state.qc @@ -1,6 +1,6 @@ #include "state.qh" -void Inventory_new(entity this); +void Inventory_new(PlayerState this); void Inventory_delete(entity this); void PlayerState_attach(entity this) -- 2.39.2