]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/rainsnow.qc
Merge branch 'master' into TimePath/scrollpanel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / rainsnow.qc
1 #include "rainsnow.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_RAINSNOW)
3
4 #ifdef SVQC
5 bool 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);
10         WriteByte(MSG_ENTITY, this.state);
11         WriteVector(MSG_ENTITY, myorg);
12         WriteVector(MSG_ENTITY, mysize);
13         WriteShort(MSG_ENTITY, compressShortVector(this.dest));
14         WriteShort(MSG_ENTITY, this.count);
15         WriteByte(MSG_ENTITY, this.cnt);
16         return true;
17 }
18
19 /*QUAKED spawnfunc_func_rain (0 .5 .8) ?
20 This is an invisible area like a trigger, which rain falls inside of.
21
22 Keys:
23 "velocity"
24  falling direction (should be something like '0 0 -700', use the X and Y velocity for wind)
25 "cnt"
26  sets color of rain (default 12 - white)
27 "count"
28  adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
29 */
30 spawnfunc(func_rain)
31 {
32         this.dest = this.velocity;
33         this.velocity = '0 0 0';
34         if (!this.dest)
35                 this.dest = '0 0 -700';
36         this.angles = '0 0 0';
37         set_movetype(this, MOVETYPE_NONE);
38         this.solid = SOLID_NOT;
39         SetBrushEntityModel(this);
40         if (!this.cnt)
41                 this.cnt = 12;
42         if (!this.count)
43                 this.count = 2000;
44         this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
45         if (this.count < 1)
46                 this.count = 1;
47         if(this.count > 65535)
48                 this.count = 65535;
49
50         this.state = 1; // 1 is rain, 0 is snow
51         this.Version = 1;
52
53         Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
54 }
55
56
57 /*QUAKED spawnfunc_func_snow (0 .5 .8) ?
58 This is an invisible area like a trigger, which snow falls inside of.
59
60 Keys:
61 "velocity"
62  falling direction (should be something like '0 0 -300', use the X and Y velocity for wind)
63 "cnt"
64  sets color of rain (default 12 - white)
65 "count"
66  adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
67 */
68 spawnfunc(func_snow)
69 {
70         this.dest = this.velocity;
71         this.velocity = '0 0 0';
72         if (!this.dest)
73                 this.dest = '0 0 -300';
74         this.angles = '0 0 0';
75         set_movetype(this, MOVETYPE_NONE);
76         this.solid = SOLID_NOT;
77         SetBrushEntityModel(this);
78         if (!this.cnt)
79                 this.cnt = 12;
80         if (!this.count)
81                 this.count = 2000;
82         this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
83         if (this.count < 1)
84                 this.count = 1;
85         if(this.count > 65535)
86                 this.count = 65535;
87
88         this.state = 0; // 1 is rain, 0 is snow
89         this.Version = 1;
90
91         Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
92 }
93 #elif defined(CSQC)
94 float autocvar_cl_rainsnow_maxdrawdist = 2048;
95
96 void Draw_Rain(entity this)
97 {
98         vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist;
99         maxdist.z = 5;
100         if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5'))
101         //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist))
102         te_particlerain(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
103 }
104
105 void Draw_Snow(entity this)
106 {
107         vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist;
108         maxdist.z = 5;
109         if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5'))
110         //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist))
111         te_particlesnow(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
112 }
113
114 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
115 {
116         this.impulse = ReadByte(); // Rain, Snow, or Whatever
117         this.origin = ReadVector();
118         this.maxs = ReadVector();
119         this.velocity = decompressShortVector(ReadShort());
120         this.count = ReadShort() * 10;
121         this.glow_color = ReadByte(); // color
122
123         return = true;
124
125         this.mins    = -0.5 * this.maxs;
126         this.maxs    =  0.5 * this.maxs;
127         this.origin  = this.origin - this.mins;
128
129         setorigin(this, this.origin);
130         setsize(this, this.mins, this.maxs);
131         this.solid = SOLID_NOT;
132         if (isnew) IL_PUSH(g_drawables, this);
133         if(this.impulse)
134                 this.draw = Draw_Rain;
135         else
136                 this.draw = Draw_Snow;
137 }
138 #endif