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

Go to the source code of this file.

Functions

 NET_HANDLE (Nade_Orb, bool isNew)
void orb_draw (entity this)
void orb_draw2d (entity this)
bool orb_send (entity this, entity to, int sf)
void orb_setup (entity orb)

Function Documentation

◆ NET_HANDLE()

NET_HANDLE ( Nade_Orb ,
bool isNew )

Definition at line 80 of file net.qc.

81{
82 Net_Accept(Nade_Orb);
83
84 int sf = ReadByte();
85 this.colormod = ReadRegistered(Nades).m_color;
86 setorigin(this, ReadVector());
87 this.ltime = ReadFloat();
88 //this.ltime = time + ReadByte() / 10.0;
90 ? ReadFloat()
91 : (ReadByte() + 1) * 0.125;
93 ? ReadFloat()
94 : (ReadByte() + 1) * 5;
95
96 if (isNew)
97 orb_setup(this);
98 return true;
99}
float lifetime
Definition powerups.qc:23
vector colormod
Definition powerups.qc:21
float radius
Definition impulse.qh:11
const int SF_NADEORB_LIFETIME_FLOAT
Definition net.qh:5
float ltime
Definition net.qh:10
const int SF_NADEORB_RADIUS_FLOAT
Definition net.qh:6
#define ReadFloat()
Definition net.qh:349
#define ReadVector()
Definition net.qh:350
#define ReadRegistered(r)
Definition net.qh:291
int ReadByte()
void orb_setup(entity orb)
Definition net.qc:44

References colormod, lifetime, ltime, orb_setup(), radius, ReadByte(), ReadFloat, ReadRegistered, ReadVector, SF_NADEORB_LIFETIME_FLOAT, and SF_NADEORB_RADIUS_FLOAT.

◆ orb_draw()

void orb_draw ( entity this)

Definition at line 10 of file net.qc.

11{
12 float age = time - (this.ltime - this.lifetime);
13 float dt = time - this.update_time;
14 this.update_time = time;
15
16 if (dt > 0)
17 {
18 this.avelocity *= 24 ** (dt / this.lifetime); // speed up, frametime independent
19 this.angles += dt * this.avelocity;
20 }
21 if (age > 0)
22 {
23 this.scale = this.radius * (age >= this.animstate_endtime
24 ? 1
25 : (this.height * age * (age - this.animstate_endtime * 2))); // increases at decreasing pace up to .radius, as age -> .animstate_endtime
26 this.alpha = sqrt(1 - age / this.lifetime); // slowly fade out
27 }
28}
float animstate_endtime
Definition anim.qh:38
float height
Definition bobbing.qc:3
float alpha
Definition items.qc:13
float update_time
Definition net.qh:11
vector avelocity
float time
ent angles
Definition ent_cs.qc:121
float sqrt(float f)
float scale
Definition projectile.qc:14

References alpha, angles, animstate_endtime, avelocity, entity(), height, lifetime, ltime, radius, scale, sqrt(), time, and update_time.

Referenced by orb_setup().

◆ orb_draw2d()

void orb_draw2d ( entity this)

Definition at line 30 of file net.qc.

31{
32 static float orb_drawtime; // last drawn orb frame, to counter overlapping orbs
33 if (time <= orb_drawtime)
34 return;
35
36 if (boxesoverlap(view_origin - '1 1 1', view_origin + '1 1 1', this.absmin, this.absmax)) // nade orbs actually act as a cube
37 {
38 orb_drawtime = time; // prevent rendering more than one of these per frame!
39 float orb_alpha = this.alpha * 0.6;
41 }
42}
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
vector view_origin
Definition main.qh:109
const float DRAWFLAG_ADDITIVE
vector absmax
vector absmin
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition vector.qh:73
#define vec2(...)
Definition vector.qh:90
float autocvar_hud_colorflash_alpha
Definition view.qh:39

References absmax, absmin, alpha, autocvar_hud_colorflash_alpha, boxesoverlap(), colormod, drawfill, DRAWFLAG_ADDITIVE, entity(), time, vec2, vid_conheight, vid_conwidth, and view_origin.

Referenced by orb_setup().

◆ orb_send()

bool orb_send ( entity this,
entity to,
int sf )

Definition at line 102 of file net.qc.

103{
104 sf = 0;
105 float byte_lifetime = this.lifetime * 8 - 1; // range: 0.125..32 in increments of 0.125
106 if (byte_lifetime < 0 || byte_lifetime >= BIT(8) || byte_lifetime != floor(byte_lifetime))
108 float byte_radius = this.radius * 0.2 - 1; // range: 5..1280 in increments of 5
109 if (byte_radius < 0 || byte_radius >= BIT(8) || byte_radius != floor(byte_radius))
111
112 WriteHeader(MSG_ENTITY, Nade_Orb);
114 WriteRegistered(Nades, MSG_ENTITY, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)));
115 WriteVector(MSG_ENTITY, this.origin);
116 WriteFloat(MSG_ENTITY, this.ltime);
117 //WriteByte(MSG_ENTITY, (this.ltime - time) * 10.0 + 0.5); // round time delta to a 1/10th of a second
119 WriteFloat(MSG_ENTITY, this.lifetime);
120 else
121 WriteByte(MSG_ENTITY, rint(byte_lifetime));
123 WriteFloat(MSG_ENTITY, this.radius);
124 else
125 WriteByte(MSG_ENTITY, rint(byte_radius));
126
127 return true;
128}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
vector origin
const int MSG_ENTITY
Definition net.qh:156
#define WriteHeader(to, id)
Definition net.qh:265
#define WriteRegistered(r, to, it)
Definition net.qh:293
#define STAT(...)
Definition stats.qh:82
float rint(float f)
void WriteByte(float data, float dest, float desto)
float floor(float f)
#define REGISTRY_GET(id, i)
Definition registry.qh:43

References BIT, entity(), floor(), lifetime, ltime, MSG_ENTITY, origin, radius, REGISTRY_GET, rint(), SF_NADEORB_LIFETIME_FLOAT, SF_NADEORB_RADIUS_FLOAT, STAT, WriteByte(), WriteHeader, and WriteRegistered.

Referenced by nades_spawn_orb().

◆ orb_setup()

void orb_setup ( entity orb)

Definition at line 44 of file net.qc.

45{
46 orb.update_time = time; // used to calculate dt
47 orb.animstate_endtime = 0.25 * min(orb.lifetime, 1); // when the orb will stop expanding
48 orb.height = -4 * (2 * orb.animstate_endtime) ** -2; // amplitude used in scaling calculation
49
50 setmodel(orb, MDL_NADE_ORB);
51 orb.skin = 1;
52
53 float model_radius = orb.maxs.x;
54 vector size = '0.5 0.5 0.5' * orb.radius;
55 setsize(orb, -size, size);
56 orb.radius *= 0.6 / model_radius;
57
58 orb.draw = orb_draw;
59 orb.draw2d = orb_draw2d;
60 IL_PUSH(g_drawables, orb);
62 SetResourceExplicit(orb, RES_HEALTH, 255);
64 orb.solid = SOLID_NOT;
65 orb.drawmask = MASK_NORMAL;
66 orb.renderflags |= RF_ADDITIVE;
67 orb.scale = 0.01;
68 float spin_dir = 2*M_PI * random();
69 orb.avelocity = '6 0 0' * sin(spin_dir) + '0 0 6' * cos(spin_dir);
70
71 float age = time - (orb.ltime - orb.lifetime);
72 if (age > 0)
73 orb.avelocity *= 24 ** (age / orb.lifetime);
74}
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
IntrusiveList g_drawables
Definition main.qh:91
IntrusiveList g_drawables_2d
Definition main.qh:92
#define setmodel(this, m)
Definition model.qh:26
const float RF_ADDITIVE
const float MASK_NORMAL
const float SOLID_NOT
vector size
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define M_PI
Definition mathlib.qh:108
float cos(float f)
float random(void)
float sin(float f)
float min(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
void orb_draw(entity this)
Definition net.qc:10
void orb_draw2d(entity this)
Definition net.qc:30
vector
Definition self.qh:92

References cos(), entity(), g_drawables, g_drawables_2d, IL_PUSH(), M_PI, MASK_NORMAL, min(), MOVETYPE_NONE, orb_draw(), orb_draw2d(), random(), RF_ADDITIVE, set_movetype(), setmodel, SetResourceExplicit(), sin(), size, SOLID_NOT, time, and vector.

Referenced by NET_HANDLE().