]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/rainsnow.qc
4e8df8c75723cc0cc07f325313d7ef1ff1b77a7a
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / 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, true);
40         if (!this.cnt)
41         {
42                 this.cnt = 12;
43         }
44         if (!this.count)
45                 this.count = 2000;
46         // relative to absolute particle count
47         //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
48         if (this.count < 1)
49                 this.count = 1;
50         if(this.count > 65535)
51                 this.count = 65535;
52
53         this.state = RAINSNOW_RAIN;
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, true);
80         if (!this.cnt)
81         {
82                 this.cnt = 12;
83         }
84         if (!this.count)
85                 this.count = 2000;
86         // relative to absolute particle count
87         //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
88         if (this.count < 1)
89                 this.count = 1;
90         if(this.count > 65535)
91                 this.count = 65535;
92
93         this.state = RAINSNOW_SNOW;
94
95         Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
96 }
97 #elif defined(CSQC)
98 float autocvar_cl_rainsnow_maxdrawdist = 500;
99
100 void Draw_RainSnow(entity this)
101 {
102         vector maxdist = '1 1 1' * autocvar_cl_rainsnow_maxdrawdist;
103
104         vector effbox_min = vec_to_max(view_origin - maxdist, this.origin + this.mins);
105         vector effbox_max = vec_to_min(view_origin + maxdist, this.origin + this.maxs);
106
107         vector mysize = effbox_max - effbox_min;
108         float mycount = bound(1, 0.1 * this.count * (mysize.x / 1024) * (mysize.y / 1024), 65535);
109
110         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
111         {
112                 if(this.state == RAINSNOW_RAIN)
113                 te_particlerain(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
114         else
115                 te_particlesnow(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
116         }
117 }
118
119 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
120 {
121         this.state = ReadByte(); // Rain, Snow, or Whatever
122         this.origin = ReadVector();
123         this.maxs = ReadVector();
124         this.velocity = decompressShortVector(ReadShort());
125         this.count = ReadShort();
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         this.draw = Draw_RainSnow;
139 }
140 #endif