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

Go to the source code of this file.

Macros

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

Functions

 NET_HANDLE (ENT_CLIENT_STATUSEFFECTS, bool isnew)
void ONREMOVE (entity this)
 REGISTER_MUTATOR (status_effects, true)
 STATIC_INIT (StatusEffects)
bool StatusEffects_active (StatusEffect this, entity actor)
void StatusEffects_apply (StatusEffect this, entity actor, float eff_time, int eff_flags)
void StatusEffects_clearall (entity store)
void StatusEffects_copy (StatusEffect this, entity store, float time_offset)
bool StatusEffects_customize (entity this, entity client)
void StatusEffects_delete (entity e)
void StatusEffects_entremove (entity this)
float StatusEffects_gettime (StatusEffect this, entity actor)
void StatusEffects_new (entity this)
void StatusEffects_remove (StatusEffect this, entity actor, int removal_type)
void StatusEffects_removeall (entity actor, int removal_type)
bool StatusEffects_Send (StatusEffect this, entity to, int sf)
void StatusEffects_tick (entity actor)
void StatusEffects_update (entity e)
void StatusEffects_Write (StatusEffect data, StatusEffect store)
void StatusEffectsStorage_attach (entity e)
void StatusEffectsStorage_delete (entity e)

Variables

StatusEffect g_statuseffects
int SEFminorBitsArr [StatusEffects_groups_major]
StatusEffect statuseffects
 Entity statuseffects.
const int StatusEffects_groups_major = 4
const int StatusEffects_groups_minor = 8
StatusEffect statuseffects_store
 Player statuseffects storage (holds previous state)

Macro Definition Documentation

◆ G_MAJOR

#define G_MAJOR ( id)
Value:
float floor(float f)
const int StatusEffects_groups_minor

Definition at line 36 of file status_effects.qh.

Referenced by StatusEffects_Write().

◆ G_MINOR

#define G_MINOR ( id)
Value:

Definition at line 37 of file status_effects.qh.

Referenced by StatusEffects_Write().

Function Documentation

◆ NET_HANDLE()

NET_HANDLE ( ENT_CLIENT_STATUSEFFECTS ,
bool isnew )

Definition at line 48 of file status_effects.qh.

49{
50 make_pure(this);
51 g_statuseffects = this;
52 this.entremove = StatusEffects_entremove;
53 const int majorBits = Readbits(StatusEffects_groups_major);
54 for (int i = 0; i < StatusEffects_groups_major; ++i) {
55 if (!(majorBits & BIT(i))) {
56 continue;
57 }
58 const int minorBits = Readbits(StatusEffects_groups_minor);
59 for (int j = 0; j < StatusEffects_groups_minor; ++j) {
60 if (!(minorBits & BIT(j))) {
61 continue;
62 }
63 const StatusEffect it = REGISTRY_GET(StatusEffects, StatusEffects_groups_minor * i + j);
64 this.statuseffect_time[it.m_id] = ReadFloat();
65 this.statuseffect_flags[it.m_id] = ReadByte();
66 }
67 }
68 return true;
69}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
int m_id
Definition all.qh:34
#define ReadFloat()
Definition net.qh:366
int ReadByte()
int Readbits(int num)
Definition net.qh:372
#define make_pure(e)
direct use is
Definition oo.qh:13
#define REGISTRY_GET(id, i)
Definition registry.qh:43
StatusEffect g_statuseffects
void StatusEffects_entremove(entity this)
const int StatusEffects_groups_major

References BIT, g_statuseffects, StatusEffect::m_id, make_pure, Readbits(), ReadByte(), ReadFloat, REGISTRY_GET, StatusEffects_entremove(), StatusEffects_groups_major, and StatusEffects_groups_minor.

◆ ONREMOVE()

void ONREMOVE ( entity this)

Definition at line 173 of file status_effects.qh.

174{
175 // remove statuseffects object attached to 'this'
176 if(this.statuseffects && this.statuseffects.owner == this)
178}
StatusEffect statuseffects
Entity statuseffects.
void StatusEffects_delete(entity e)

References entity(), statuseffects, and StatusEffects_delete().

Referenced by ClientDisconnect(), and CSQC_Ent_Update().

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( status_effects ,
true  )

◆ STATIC_INIT()

STATIC_INIT ( StatusEffects )

Definition at line 25 of file status_effects.qh.

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

References ceil(), error, floor(), REGISTRY_COUNT, StatusEffects_groups_major, and StatusEffects_groups_minor.

◆ StatusEffects_active()

◆ StatusEffects_apply()

void StatusEffects_apply ( StatusEffect this,
entity actor,
float eff_time,
int eff_flags )

Definition at line 31 of file status_effects.qc.

32{
33 if (!actor || eff_time <= time)
34 return;
35
36 this.m_apply(this, actor, eff_time, eff_flags);
37}
float time

References entity(), and time.

Referenced by buff_Disability_ApplyStunned(), buff_Touch(), Fire_AddDamage(), GiveBuff(), GiveItems(), GiveStatusEffect(), Item_GiveTo(), M_Mage_Defend_Shield(), Monster_Spawn(), nade_ice_freeze(), and PutPlayerInServer().

◆ StatusEffects_clearall()

void StatusEffects_clearall ( entity store)

Definition at line 156 of file status_effects.qh.

157{
158 if(!store)
159 return; // safety net
160 // NOTE: you will need to perform StatusEffects_update after this to update the storage entity
161 // (unless store is the storage entity)
162 FOREACH(StatusEffects, true, {
163 store.statuseffect_time[it.m_id] = 0;
164 store.statuseffect_flags[it.m_id] = 0;
165 });
166}
#define FOREACH(list, cond, body)
Definition iter.qh:19

References entity(), and FOREACH.

Referenced by Monster_Spawn(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ StatusEffects_copy()

void StatusEffects_copy ( StatusEffect this,
entity store,
float time_offset )

Definition at line 39 of file status_effects.qc.

40{
41 if(!this || !store)
42 return;
43 FOREACH(StatusEffects, true,
44 {
45 if(time_offset)
46 store.statuseffect_time[it.m_id] = time + this.statuseffect_time[it.m_id] - time_offset;
47 else
48 store.statuseffect_time[it.m_id] = this.statuseffect_time[it.m_id];
49 store.statuseffect_flags[it.m_id] = this.statuseffect_flags[it.m_id];
50 });
51}

References entity(), FOREACH, and time.

Referenced by CheatImpulse().

◆ StatusEffects_customize()

bool StatusEffects_customize ( entity this,
entity client )

Definition at line 132 of file status_effects.qh.

133{
134 // sends to spectators too!
135 return (client.statuseffects == this);
136}

References entity().

Referenced by StatusEffects_new().

◆ StatusEffects_delete()

void StatusEffects_delete ( entity e)

Definition at line 150 of file status_effects.qh.

150{ delete(e.statuseffects); e.statuseffects = NULL; }
#define NULL
Definition post.qh:14

References entity(), and NULL.

Referenced by MUTATOR_HOOKFUNCTION(), and ONREMOVE().

◆ StatusEffects_entremove()

void StatusEffects_entremove ( entity this)

Definition at line 42 of file status_effects.qh.

43{
44 if(g_statuseffects == this)
46}

References entity(), g_statuseffects, and NULL.

Referenced by NET_HANDLE().

◆ StatusEffects_gettime()

float StatusEffects_gettime ( StatusEffect this,
entity actor )

Definition at line 17 of file status_effects.qc.

18{
19 entity store = actor;
20#ifdef SVQC
21 store = actor.statuseffects;
22#endif
23 if(!store) return 0;
24 float eff_time = store.statuseffect_time[this.m_id];
25 // if effect end time has passed and m_tick hasn't removed the effect yet
26 // return current time since the effect is actually still active in this frame
27 return (eff_time < time ? time : eff_time);
28}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
int m_id
Definition effect.qh:19

References entity(), m_id, and time.

Referenced by Fire_AddDamage(), Fire_ApplyDamage(), GiveBuff(), GiveStatusEffect(), havocbot_goalrating_enemyplayers(), Item_GiveTo(), MUTATOR_HOOKFUNCTION(), player_powerups(), powerups_DropItem(), and W_ThrowNewWeapon().

◆ StatusEffects_new()

void StatusEffects_new ( entity this)

Definition at line 138 of file status_effects.qh.

139{
141 this.statuseffects = eff;
142 eff.owner = this;
143 if(this.statuseffects_store)
144 {
146 Net_LinkEntity(eff, false, 0, StatusEffects_Send);
147 }
148}
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)
bool StatusEffects_Send(StatusEffect this, entity to, int sf)
bool StatusEffects_customize(entity this, entity client)
StatusEffect statuseffects_store
Player statuseffects storage (holds previous state)

References entity(), Net_LinkEntity(), NEW, setcefc, statuseffects, StatusEffects_customize(), StatusEffects_Send(), and statuseffects_store.

Referenced by StatusEffect::m_apply().

◆ StatusEffects_remove()

void StatusEffects_remove ( StatusEffect this,
entity actor,
int removal_type )

Definition at line 53 of file status_effects.qc.

54{
55 this.m_remove(this, actor, removal_type);
56}

References entity().

Referenced by Damage(), GiveBuff(), GiveStatusEffect(), invasion_SpawnChosenMonster(), player_powerups(), W_ThrowNewWeapon(), and weapon_prepareattack_do().

◆ StatusEffects_removeall()

void StatusEffects_removeall ( entity actor,
int removal_type )

Definition at line 58 of file status_effects.qc.

59{
60 if(!actor.statuseffects)
61 return;
62 FOREACH(StatusEffects, true,
63 {
64 it.m_remove(it, actor, removal_type);
65 });
66}

References entity(), and FOREACH.

Referenced by ctf_Handle_Pickup(), ctf_RespawnFlag(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ StatusEffects_Send()

bool StatusEffects_Send ( StatusEffect this,
entity to,
int sf )

Definition at line 124 of file status_effects.qh.

125{
126 TC(StatusEffect, this);
127 WriteHeader(MSG_ENTITY, ENT_CLIENT_STATUSEFFECTS);
128 StatusEffects_Write(this, to.statuseffects_store);
129 return true;
130}
#define TC(T, sym)
Definition _all.inc:82
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221
void StatusEffects_Write(StatusEffect data, StatusEffect store)

References entity(), MSG_ENTITY, StatusEffects_Write(), TC, and WriteHeader.

Referenced by StatusEffects_new().

◆ StatusEffects_tick()

void StatusEffects_tick ( entity actor)

Definition at line 9 of file status_effects.qc.

10{
11 FOREACH(StatusEffects, it.m_active(it, actor),
12 {
13 it.m_tick(it, actor);
14 });
15}

References entity(), and FOREACH.

Referenced by MUTATOR_HOOKFUNCTION().

◆ StatusEffects_update()

void StatusEffects_update ( entity e)

Definition at line 153 of file status_effects.qh.

153{ e.statuseffects.SendFlags = 0xFFFFFF; }

References entity().

Referenced by CheatImpulse(), GiveItems(), StatusEffect::m_apply(), StatusEffect::m_remove(), Monster_Spawn(), MUTATOR_HOOKFUNCTION(), and W_ThrowNewWeapon().

◆ StatusEffects_Write()

void StatusEffects_Write ( StatusEffect data,
StatusEffect store )

Definition at line 74 of file status_effects.qh.

75{
76 if (!data) {
78 return;
79 }
80 TC(StatusEffect, data);
81
82 for (int i = 0; i < StatusEffects_groups_major; ++i)
83 SEFminorBitsArr[i] = 0;
84
85 int majorBits = 0;
86 FOREACH(StatusEffects, true, {
87 .float fld = statuseffect_time[it.m_id];
88 .int flg = statuseffect_flags[it.m_id];
89 const bool changed = (store.(fld) != data.(fld) || store.(flg) != data.(flg));
90 store.(fld) = data.(fld);
91 store.(flg) = data.(flg);
92 if (changed) {
93 int maj = G_MAJOR(it.m_id);
94 majorBits = BITSET(majorBits, BIT(maj), true);
95 SEFminorBitsArr[maj] = BITSET(SEFminorBitsArr[maj], BIT(G_MINOR(it.m_id)), true);
96 }
97 });
98
99 Writebits(MSG_ENTITY, majorBits, StatusEffects_groups_major);
100 for (int i = 0; i < StatusEffects_groups_major; ++i)
101 {
102 if (!(majorBits & BIT(i)))
103 continue;
104
105 const int minorBits = SEFminorBitsArr[i];
106 Writebits(MSG_ENTITY, minorBits, StatusEffects_groups_minor);
107 for (int j = 0; j < StatusEffects_groups_minor; ++j)
108 {
109 if (!(minorBits & BIT(j)))
110 continue;
111
112 const entity it = REGISTRY_GET(StatusEffects, StatusEffects_groups_minor * i + j);
113 WriteFloat(MSG_ENTITY, data.statuseffect_time[it.m_id]);
115 }
116 }
117}
#define BITSET(var, mask, flag)
Definition bits.qh:11
int statuseffect_flags[REGISTRY_MAX(StatusEffects)]
Definition all.qh:49
float statuseffect_time[REGISTRY_MAX(StatusEffects)]
Stores times of status effects, the id being the index.
Definition all.qh:48
void WriteShort(float data, float dest, float desto)
void WriteByte(float data, float dest, float desto)
int SEFminorBitsArr[StatusEffects_groups_major]
#define G_MAJOR(id)
#define G_MINOR(id)

References BIT, BITSET, entity(), FOREACH, G_MAJOR, G_MINOR, MSG_ENTITY, REGISTRY_GET, SEFminorBitsArr, StatusEffect::statuseffect_flags, StatusEffect::statuseffect_time, StatusEffects_groups_major, StatusEffects_groups_minor, TC, WriteByte(), and WriteShort().

Referenced by StatusEffects_Send().

◆ StatusEffectsStorage_attach()

void StatusEffectsStorage_attach ( entity e)

Definition at line 168 of file status_effects.qh.

168{ e.statuseffects_store = NEW(StatusEffect); e.statuseffects_store.drawonlytoclient = e; }

References entity(), and NEW.

Referenced by ClientState_attach().

◆ StatusEffectsStorage_delete()

void StatusEffectsStorage_delete ( entity e)

Definition at line 169 of file status_effects.qh.

169{ delete(e.statuseffects_store); e.statuseffects_store = NULL; }

References entity(), and NULL.

Referenced by ClientState_detach().

Variable Documentation

◆ g_statuseffects

◆ SEFminorBitsArr

int SEFminorBitsArr[StatusEffects_groups_major]

Definition at line 73 of file status_effects.qh.

Referenced by StatusEffects_Write().

◆ statuseffects

StatusEffect statuseffects

Entity statuseffects.

Definition at line 13 of file status_effects.qh.

Referenced by CheatImpulse(), Monster_Spawn(), ONREMOVE(), and StatusEffects_new().

◆ StatusEffects_groups_major

const int StatusEffects_groups_major = 4

Definition at line 20 of file status_effects.qh.

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

◆ StatusEffects_groups_minor

const int StatusEffects_groups_minor = 8

Definition at line 19 of file status_effects.qh.

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

◆ statuseffects_store

StatusEffect statuseffects_store

Player statuseffects storage (holds previous state)

Definition at line 15 of file status_effects.qh.

Referenced by StatusEffects_new().