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