forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfog.qc
375 lines (323 loc) · 10.5 KB
/
fog.qc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
====================
FOG
adapted from similar things czg did in honey_fog.qc god bless him
====================
*/
float FOG_INTERVAL = 0.05; //1/20;
/*FGD
@baseclass = Fog [
fog_density(string) : "Fog Density"
fog_color(string) : "Fog Color"
]
@baseclass = FogShift [
fog_density(string) : "Start Fog Density"
fog_color(string) : "Start Fog Color"
fog_density2(string) : "End Fog Density"
fog_color2(string) : "End Fog Color"
]
*/
float(entity e, float dens, vector col) fog_sigdif =
{
float sig;
if ((e.fog_density + dens) * 0.5 < 0.1) sig = 0.0025;
else sig = 0.005;
if (fabs(e.fog_density - dens) > sig) return TRUE;
if ((e.fog_color_x + col_x) * 0.5 < 0.1) sig = 0.005;
else sig = 0.01;
if (fabs(e.fog_color_x - col_x) > sig) return TRUE;
if ((e.fog_color_y + col_y) * 0.5 < 0.1) sig = 0.005;
else sig = 0.01;
if (fabs(e.fog_color_y - col_y) > sig) return TRUE;
if ((e.fog_color_z + col_z) * 0.5 < 0.1) sig = 0.005;
else sig = 0.01;
if (fabs(e.fog_color_z - col_z) > sig) return TRUE;
return FALSE;
}
/*
================
fog_save
================
*/
void( entity client, float density, vector color ) fog_save =
{
if (client.classname != "player") return;
// save whatever we set the client's fog to in case of saves/loads
client.fog_density = density;
client.fog_color = color;
}
/*
================
fog_setFromEnt
================
*/
void( entity client, entity fogger ) fog_setFromEnt =
{
dprint("setting fog values\n");
// don't set the fog if the entity has no values, because it might be a custom map with
// _fog on the worldspawn instead
// to actually get an entity to clear the fog, set a color but leave density at 0
if (!fogger.fog_color)
if (!fogger.fog_density)
return;
fog_set(client, fogger.fog_density, fogger.fog_color);
}
/*
================
fog_set
================
*/
void( entity client, float density, vector color ) fog_set =
{
if (client.classname != "player") return;
if (!cleanUpClientShit)
{
if (client.fog_density == density && client.fog_color == color)
return FALSE;
}
//stuffcmd(client, "r_showtris 0\n"); return;
//dprint3("setting fog at ", ftos(time*1000), "\n");
stuffcmd(client, "\nfog ");
stuffcmd_float(client, density);
stuffcmd(client, " ");
stuffcmd_float(client, color_x * (icantsee + 1));
stuffcmd(client, " ");
stuffcmd_float(client, color_y * (icantsee + 1));
stuffcmd(client, " ");
stuffcmd_float(client, color_z * (icantsee + 1));
stuffcmd(client, "\n");
fog_save(client, density, color);
}
/*
================
fog_blendTouch
================
*/
void() fog_blendTouch =
{
if (!CheckValidTouch()) return;
// fix for only first client getting a fog change when multiple coop clients are touching this at once
if (time != self.rad_time) // because fog is rad
if (time < self.attack_finished)
return;
float f, ldensity, leaving, force;
vector dorg, mid, ovel;
vector lcolor;
force = (time - self.invisible_time >= FOG_INTERVAL * 10);
// if you run/fall through a fogblend fast enough you can come out the other side
// partially blended, so check if player will exit the trigger bounds before the
// next touch (same class of bug as leaping through lasers in Q2)
ovel = (other.groundentity.velocity + other.velocity) * FOG_INTERVAL;
leaving = ( (other.absmax_x + ovel_x < self.absmin_x) ||
(other.absmax_y + ovel_y < self.absmin_y) ||
(other.absmax_z + ovel_z < self.absmin_z) ||
(other.absmin_x + ovel_x > self.absmax_x) ||
(other.absmin_y + ovel_y > self.absmax_y) ||
(other.absmin_z + ovel_z > self.absmax_z) );
if (leaving)
{
// last chance to set fog correctly, so snap it to the final values
leaving = ovel * self.movedir;
if (leaving > 0)
{
ldensity = self.fog_density2;
lcolor = self.fog_color2;
}
else
{
ldensity = self.fog_density;
lcolor = self.fog_color;
}
force = TRUE;
}
else
{
// in transition, blend proportionally between the two fogs
mid = (self.mins + self.maxs) * 0.5;
dorg = other.origin + other.view_ofs - mid;
f = dorg * self.movedir;
f = (f / self.distance) + 0.5;
ldensity = lerp(self.fog_density, self.fog_density2, f);
lcolor = lerpVector(self.fog_color, self.fog_color2, f);
}
if (force || fog_sigdif(other,ldensity,lcolor))
{
self.invisible_time = time;
fog_set(other, ldensity, lcolor);
}
//fog_save(other, ldensity, lcolor);
self.rad_time = time;
self.attack_finished = time + FOG_INTERVAL / 2;
// bprint(ftos(f*1000));
// bprint("\n");
}
/*QUAKED trigger_fogblend (.5 .5 .2) ?
Acts as a smoothly blending portal between two zones of different fog. Sets the fog for any client passing through it, blending their global fog settings between "fog_color"/"fog_density" and "fog_color2"/"fog_density2" proportional to their position within the trigger.
The axis of motion on which the blend happens is defined by "angle", pointing to whatever zone has color2 and density2. Trigger therefore has two 'sides' - the side that "angle" points to, and the opposite side.
"distance" - override the length of the blend period in world units - defaults to bounds size
on 'angle' otherwise. this is only useful for diagonal triggers.
CAVEATS:
- will 'stuffcmd' 2 dozen times per frame so try not to make these huge
- a bug in most quake engine ports will reset the eye position smoothing that happens when climbing stairs or riding a plat on every frame that a 'stuffcmd' is sent, so fog transitions during upwards motion will cause noticeable stuttering.
*/
/*FGD
@SolidClass base(Appearflags, Targetname, Target, FogShift) = trigger_fogblend :
"Trigger: Fog Blend
Acts as a smoothly blending portal between two zones of different fog. Sets the fog for any client passing through it, blending their global fog settings between start and end values proportional to their position within the trigger.
- will 'stuffcmd' 2 dozen times per frame so try not to make these huge
- a bug in most quake engine ports will reset the eye position smoothing that happens when climbing stairs or riding a plat on every frame that a 'stuffcmd' is sent, so fog transitions during upwards motion will cause noticeable stuttering."
[
distance(integer) : "Length of blend distance (defaults to size of trigger)"
angle(integer) : "Axis of motion of blend (points toward end values)"
]
*/
void() trigger_fogblend =
{
if (!SUB_ShouldSpawn()) return;
if (self.angles == '0 0 0') // InitTrigger assumes angle 0 means no angle
self.angles = '0 360 0';
InitTrigger ();
self.touch = fog_blendTouch;
self.distance = zeroconvertdefault(self.distance, BoundsAngleSize(self.movedir, self.size));
}
// ================================
void(float density, vector color) target_fogblend_save =
{
if (self.spawnflags & 4)
{
entity pl;
pl = nextent(world);
while (pl.flags & FL_CLIENT)
{
fog_save(pl, density, color);
pl = nextent(pl);
}
}
else
fog_save(self.enemy, density, color);
}
void(float density, vector color) target_fogblend_set =
{
if (self.spawnflags & 4)
{
entity pl;
pl = nextent(world);
while (pl.flags & FL_CLIENT)
{
fog_set(pl, density, color);
pl = nextent(pl);
}
}
else
fog_set(self.enemy, density, color);
}
/*
================
target_fogblend_use
================
*/
void() target_fogblend_use =
{
float d;
vector c;
self.enemy = activator;
if (self.enemy.classname != "player") return;
if (!(self.spawnflags & 1))
self.state = 1 - self.state;
self.nextthink = time + self.delay;
if (self.state)
{
self.pain_finished = time + self.delay + self.speed;
d = self.fog_density2;
c = self.fog_color2;
}
else
{
self.pain_finished = time + self.delay + self.speed2;
d = self.fog_density;
c = self.fog_color;
}
target_fogblend_save(d, c);
self.use = SUB_Null; // don't allow retriggering before the blend is done or it looks super duper wacky
}
/*
================
fog_blendTimeThink
================
*/
void() fog_blendTimeThink =
{
float f, d;
vector c;
if (time >= self.pain_finished)
{
f = 1;
self.use = target_fogblend_use;
}
else
{
self.nextthink = time + FOG_INTERVAL;
if (self.state && self.speed)
f = 1 - (self.pain_finished - time) / self.speed;
else if (self.speed2)
f = 1 - (self.pain_finished - time) / self.speed2;
else
f = 1;
}
if (self.state)
{
d = lerpHermite(self.fog_density, self.fog_density2, f);
c = lerpVectorHermite(self.fog_color, self.fog_color2, f);
}
else
{
d = lerpHermite(self.fog_density2, self.fog_density, f);
c = lerpVectorHermite(self.fog_color2, self.fog_color, f);
}
target_fogblend_set(d, c);
}
/*QUAKED target_fogblend (.5 .5 .2) (-8 -8 -8) (8 8 8) ONE_WAY REVERSE GLOBAL
Blends the fog for a client. activator's fog will be blended from "fog_color" and "fog_density"
to "fog_color2" and "fog_density2". Triggering again will blend it back, unless ONE_WAY is set.
Set REVERSE if you're tired of swapping the values by hand.
Set GLOBAL to affect all clients in multiplayer, not just the activator.
"delay" - pause before beginning to blend
"speed" - time to spend blending, -1 for an instant change to fog2.
"speed2" - time to spend blending back, if different than "speed". -1 for instant.
CAVEATS:
- will 'stuffcmd' 2 dozen times per frame so try not to make this take too long
- a bug in most quake engine ports will reset the eye position smoothing that happens when climbing stairs or riding a plat on every frame that a 'stuffcmd' is sent, so fog transitions during upwards motion will cause noticeable stuttering.
*/
/*FGD
@PointClass base(Appearflags, Targetname, FogShift) color(128 128 50) = target_fogblend :
"Target: Fog Blend
Activator's fog will be blended over time from start to end values.
- will 'stuffcmd' 2 dozen times per frame so try not to make this take too long
- a bug in most quake engine ports will reset the eye position smoothing that happens when climbing stairs or riding a plat on every frame that a 'stuffcmd' is sent, so fog transitions during upwards motion will cause noticeable stuttering."
[
spawnflags(flags) = [
1 : "One-Way Only" : 0
2 : "Reverse Start/End" : 0
4 : "All clients" : 0
]
delay(string) : "Pause before starting blend"
speed(string) : "Time to blend (-1 for instant)"
speed2(string) : "Time to blend back, if different (-1 for instant)"
]
*/
void() target_fogblend =
{
if (!SUB_ShouldSpawn()) return;
self.use = target_fogblend_use;
self.think = fog_blendTimeThink;
if (self.spawnflags & 2)
self.state = 1;
else
self.state = 0;
if (self.spawnflags & 1)
self.state = 1 - self.state;
if (!self.speed) self.speed = 1;
if (!self.speed2) self.speed2 = self.speed;
if (self.speed == -1) self.speed = 0;
if (self.speed2 == -1) self.speed2 = 0;
}