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