Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
rainsnow.qc
Go to the documentation of this file.
1#include "rainsnow.qh"
2REGISTER_NET_LINKED(ENT_CLIENT_RAINSNOW)
3
4#ifdef SVQC
5bool rainsnow_SendEntity(entity this, entity to, float sf)
6{
7 vector myorg = this.origin + this.mins;
8 vector mysize = this.maxs - this.mins;
9 WriteHeader(MSG_ENTITY, ENT_CLIENT_RAINSNOW);
11 WriteVector(MSG_ENTITY, myorg);
12 WriteVector(MSG_ENTITY, mysize);
16 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
17 return true;
18}
19
20/*QUAKED spawnfunc_func_rain (0 .5 .8) ?
21This is an invisible area like a trigger, which rain falls inside of.
22
23Keys:
24"velocity"
25 falling direction (should be something like '0 0 -700', use the X and Y velocity for wind)
26"cnt"
27 sets color of rain (default 12 - white)
28"count"
29 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
30*/
31spawnfunc(func_rain)
32{
33 this.dest = this.velocity;
34 this.velocity = '0 0 0';
35 if (!this.dest)
36 this.dest = '0 0 -700';
37 this.angles = '0 0 0';
39 this.solid = SOLID_NOT;
40 SetBrushEntityModel(this, true);
41 if (!this.cnt)
42 this.cnt = 12;
43 if (!this.count)
44 this.count = 2000;
45 // relative to absolute particle count
46 //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
47 this.count = bound(1, this.count, 65535);
48
49 this.state = RAINSNOW_RAIN;
50
51 Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
52}
53
54
55/*QUAKED spawnfunc_func_snow (0 .5 .8) ?
56This is an invisible area like a trigger, which snow falls inside of.
57
58Keys:
59"velocity"
60 falling direction (should be something like '0 0 -300', use the X and Y velocity for wind)
61"cnt"
62 sets color of rain (default 12 - white)
63"count"
64 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
65*/
66spawnfunc(func_snow)
67{
68 this.dest = this.velocity;
69 this.velocity = '0 0 0';
70 if (!this.dest)
71 this.dest = '0 0 -300';
72 this.angles = '0 0 0';
74 this.solid = SOLID_NOT;
75 SetBrushEntityModel(this, true);
76 if (!this.cnt)
77 this.cnt = 12;
78 if (!this.count)
79 this.count = 2000;
80 // relative to absolute particle count
81 //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
82 this.count = bound(1, this.count, 65535);
83
84 this.state = RAINSNOW_SNOW;
85
86 Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
87}
88#elif defined(CSQC)
89float autocvar_cl_rainsnow_maxdrawdist = 1000;
90
91void Draw_RainSnow(entity this)
92{
93 float drawdist = ((this.fade_end) ? this.fade_end : autocvar_cl_rainsnow_maxdrawdist);
94 vector maxdist = '1 1 1' * drawdist;
95
96 if (boxesoverlap(view_origin - maxdist, view_origin + maxdist, this.absmin, this.absmax)) // optimisation: don't render any rain if the player is outside the view distance
97 {
98 vector effbox_min = vec_to_max(view_origin - maxdist, this.origin + this.mins);
99 vector effbox_max = vec_to_min(view_origin + maxdist, this.origin + this.maxs);
100 vector mysize = effbox_max - effbox_min;
101 float mycount = bound(1, 0.1 * this.count * (mysize.x / 1024) * (mysize.y / 1024), 65535);
102 if (this.state == RAINSNOW_RAIN)
103 te_particlerain(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
104 else
105 te_particlesnow(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
106 }
107}
108
109NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
110{
111 this.state = ReadByte(); // Rain, Snow, or Whatever
112 this.origin = ReadVector();
113 this.maxs = ReadVector();
114 this.velocity = decompressShortVector(ReadShort());
115 this.count = ReadShort();
116 this.glow_color = ReadByte(); // color
117 this.fade_end = ReadShort();
118
119 return = true;
120
121 this.mins = -0.5 * this.maxs;
122 this.maxs = 0.5 * this.maxs;
123 this.origin -= this.mins;
124
125 this.solid = SOLID_NOT; // before setorigin/setsize to prevent area grid linking
126 setorigin(this, this.origin);
127 setsize(this, this.mins, this.maxs);
128 if (isnew)
129 IL_PUSH(g_drawables, this);
130 this.draw = Draw_RainSnow;
131}
132#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
float count
Definition powerups.qc:22
IntrusiveList g_drawables
Definition main.qh:91
vector view_origin
Definition main.qh:109
float drawframetime
Definition main.qh:108
float fade_end
Definition item.qh:87
float compressShortVector(vector vec)
Definition util.qc:531
vector decompressShortVector(int data)
Definition util.qc:496
vector mins
vector velocity
const float SOLID_NOT
vector maxs
vector absmax
vector origin
float solid
vector absmin
int state
float glow_color
ent angles
Definition ent_cs.qc:146
WriteByte(chan, ent.angles.y/DEC_FACTOR)
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
vector dest
Definition jumppads.qh:54
#define NET_HANDLE(id, param)
Definition net.qh:15
const int MSG_ENTITY
Definition net.qh:156
#define ReadVector()
Definition net.qh:349
#define WriteHeader(to, id)
Definition net.qh:265
#define REGISTER_NET_LINKED(id)
Definition net.qh:91
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
int ReadByte()
float bound(float min, float value, float max)
float random(void)
void WriteShort(float data, float dest, float desto)
float floor(float f)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:133
ERASEABLE vector vec_to_min(vector a, vector b)
Definition p2mathlib.qc:30
ERASEABLE vector vec_to_max(vector a, vector b)
Definition p2mathlib.qc:40
bool rainsnow_SendEntity(entity this, entity to, float sf)
Definition rainsnow.qc:5
const int RAINSNOW_SNOW
Definition rainsnow.qh:4
const int RAINSNOW_RAIN
Definition rainsnow.qh:5
vector
Definition self.qh:96
#define spawnfunc(id)
Definition spawnfunc.qh:107
void SetBrushEntityModel(entity this, bool with_lod)
Definition subs.qc:419
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:72