forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
w_lightning.qc
342 lines (292 loc) · 9.56 KB
/
w_lightning.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
/*
===============
LIGHTNING
===============
*/
/*
=================
Chain Lightning
damage repeats outward from the target to more behind them, halving damage each time
search around a little left or right behind the target so the lightning can appear
to arc, so it isn't just a high speed railgun
=================
*/
void(vector start, entity from, float dmg) W_ChainLightning =
{
entity head, targ;
float len, dist, dot, zpc;
vector dir, h_org;
dir = normalize(start - self.origin); // self still attacker (player)
head = findradius(start + dir * 120, 100);
targ = from;
len = A_SHITLOAD;
// find another enemy who hasn't been zapped yet
while (head)
{
if (head != from &&
head.takedamage &&
!(head.customflags & CFL_ZAPPED) &&
(head.movetype >= MOVETYPE_WALK && head.movetype <= MOVETYPE_FLY))
{
h_org = BoundsCenter(head);
traceline2(start, h_org, from, 0);
if (trace_ent == head)
{
// rank by distance
dist = vlen(h_org - start);
// only jump to monsters within a narrow cone, so the player still has to
// reposition smartly to get lightning to link downrange
dot = normalize(h_org - start) * dir;
if (dist <= len)
{
zpc = pointcontents(from.origin);
if ( dot > 0.825 ||
(dist < 72 && dot > 0.725) ||
// extra-wide zappy cone for anyone underwater
(dot > 0.25 && (zpc == CONTENT_WATER || zpc == CONTENT_SLIME) && pointcontents(head.origin) == zpc ) )
{
targ = head;
len = dist;
}
}
}
}
head = head.chain;
}
if (targ != from)
{
LightningBeam(start, targ.origin, from, dmg);
}
}
/*
=================
LightningBeam
=================
*/
void(vector start, vector limit, entity from, float damage) LightningBeam =
{
// from is the originator of the beam - this is the shot monster when chaining
// self always remains the actual attacker
vector left, end;
entity targ;
// fix for wonky 'three beams' bug:
left = normalize(limit - start) * 12;
left = Vector(0 - left_y, left_x, 0);
traceline2(start, limit, from, 0);
end = trace_endpos;
if (trace_ent.takedamage && !(trace_ent.customflags & CFL_ZAPPED))
{
targ = trace_ent;
targ.customflags |= CFL_ZAPPED;
// don't chain from doors, buttons, or special wonky shootable triggers
if ((targ.solid == SOLID_BBOX || targ.solid == SOLID_SLIDEBOX) &&
targ.movetype && targ.movetype != MOVETYPE_PUSH)
{
end = trace_endpos;
if (self.classname == "player")
{
// have the arc pull into the target a little
if (targ.maxs_x <= 32) // not for cthon/etc, he's too big
end = (trace_endpos + targ.origin) * 0.5;
if (targ.classname == "player")
targ.velocity_z = targ.velocity_z + 400;
if (damage > 4)
W_ChainLightning(end, targ, ceil(damage / 3 + 2)); // 30 12 6 4
}
}
// we go through multidamage here because T_Damage clears ZAPPED and we
// need to preserve that flag until we're done so we don't double damage
AddMultiDamage (targ, damage);
// clear and apply multidamage must be called in an enclosing function!
particle (end, '0 0 100', 225, damage*4);
}
// we do the lightning beam after the chain lightning recursion as the stack unwinds,
// so that the closest beam gets sent last. this way, if quake runs out of beams
// in a big LG vs shambler showdown, we're likely to only overwrite the furthest
// and least noticeable beams
if (self.classname == "monster_shambler")
{
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_LIGHTNING1);
}
else
{
sound (targ, CHAN_BODY, "weapons/lhit.wav", 1, ATTN_NORM);
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
}
// quake immediately reuses beams that come from the same entity, so the
// entity the lightning jumped from has to own the next leg of lightning
// or else they auto-overwrite and only the final (nearest) one appears
WriteEntity (MSG_BROADCAST, from);
WriteCoord (MSG_BROADCAST, start_x);
WriteCoord (MSG_BROADCAST, start_y);
WriteCoord (MSG_BROADCAST, start_z);
WriteCoord (MSG_BROADCAST, end_x);
WriteCoord (MSG_BROADCAST, end_y);
WriteCoord (MSG_BROADCAST, end_z);
damage *= 0.3; // tone down the side prongs or the LG is a total scythe vs crowds
traceline2(start + left, end + left, from, 0);
if (trace_ent.takedamage && !(trace_ent.customflags & CFL_ZAPPED)) // don't add damage to any target twice
{
trace_ent.customflags |= CFL_ZAPPED;
particle (trace_endpos, '0 0 100', 225, damage*4);
AddMultiDamage (trace_ent, damage);
}
traceline2(start - left, end - left, from, 0);
if (trace_ent.takedamage && !(trace_ent.customflags & CFL_ZAPPED))
{
trace_ent.customflags |= CFL_ZAPPED;
particle (trace_endpos, '0 0 100', 225, damage*4);
AddMultiDamage (trace_ent, damage);
}
}
/*
float LG_DMG_OUT = 10;
float LG_DMG_IN = 2;
float(entity src, entity att, float dmg) W_ChainLightning =
{
vector org, dir, dst, h_org;
entity head, targ1, targ2;
float dist, dot, len1, len2, dmgback;
vector hit1, hit2;
dmgback = dmg;
src.customflags |= CFL_ZAPPED;
// stop at three iterations (potentially 7 targets). more than that looks bad as quake
// runs out of lightning t_entities at 24 beam segments (32 in fitzquakes)
if (dmg > 32 - LG_DMG_OUT * 2)
{
// look mostly behind the target, so the lightning spreads
// predominantly in the direction the gun is being fired
dir = normalize(src.origin - att.origin);
dir_z = 0;
// zero z after normalizing so if the player is firing down from above, the
// lightning will spread in every direction
org = BoundsCenter(src);
head = findradius(org + dir * 64, 180);
targ1 = targ2 = src;
len1 = len2 = A_SHITLOAD;
// find two enemies who haven't been zapped yet
while (head)
{
if (head != att &&
head.takedamage &&
!(coop && head.classname == att.classname) && // prooobably not fair to unavoidably electrocute your friends
!(head.customflags & CFL_ZAPPED) &&
(head.movetype >= MOVETYPE_WALK && head.movetype <= MOVETYPE_FLY))
{
h_org = BoundsCenter(head);
traceline2(org, h_org, src, 0);
if (trace_ent == head)
{
// rank by distance
dist = vlen(org - h_org);
// bias toward monsters behind and to either side of the target, so lightning
// visibly spreads like the end of raiders of the lost ark
dot = normalize(org - h_org) * dir;
if (dot > 0.7)
dot = 1.4 - dot; // not directly behind if we an help it, can't see it
dist *= dot + 1;
if (dist <= len1)
{
targ2 = targ1;
len2 = len1;
hit2 = hit1;
targ1 = head;
len1 = dist;
hit1 = trace_endpos;
}
else if (dist <= len2)
{
targ2 = head;
len2 = dist;
hit2 = trace_endpos;
}
}
}
head = head.chain;
}
if (targ1 != src) {
dst = BoundsCenter(targ1);
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
WriteEntity (MSG_BROADCAST, targ1);
// shave a little off each end of the beam - it'll still be inside both
// monsters' bounds but it'll save us a t_ent here and there, and reduces
// the likelihood the beam sticks out the far side of the target
dir = normalize(dst - org) * 12;
WriteCoord (MSG_BROADCAST, org_x + dir_x);
WriteCoord (MSG_BROADCAST, org_y + dir_y);
WriteCoord (MSG_BROADCAST, org_z + dir_y);
WriteCoord (MSG_BROADCAST, dst_x - dir_x);
WriteCoord (MSG_BROADCAST, dst_y - dir_y);
WriteCoord (MSG_BROADCAST, dst_z - dir_z);
dmgback = W_ChainLightning(targ1, att, dmg - LG_DMG_OUT);
particle (hit1, '0 0 100', 225, 3 * dmgback);
if (targ2 != src) {
dst = BoundsCenter(targ2);
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
WriteEntity (MSG_BROADCAST, targ2);
dir = normalize(dst - org) * 12;
WriteCoord (MSG_BROADCAST, org_x + dir_x);
WriteCoord (MSG_BROADCAST, org_y + dir_y);
WriteCoord (MSG_BROADCAST, org_z + dir_y);
WriteCoord (MSG_BROADCAST, dst_x - dir_x);
WriteCoord (MSG_BROADCAST, dst_y - dir_y);
WriteCoord (MSG_BROADCAST, dst_z - dir_z);
dmgback = min(dmgback, W_ChainLightning(targ1, att, dmg - LG_DMG_OUT));
particle (hit2, '0 0 100', 225, 3 * dmgback);
}
}
}
T_Damage (src, att, att, dmgback);
return dmgback + LG_DMG_IN;
}
*/
void() W_FireLightning =
{
local vector org;
local float cells;
if (self.ammo_cells < 1)
{
W_SelectBestWeapon();
return;
}
// explode if under water
if (self.waterlevel > 1)
{
cells = self.ammo_cells;
self.ammo_cells = 0;
W_SetCurrentAmmo ();
T_RadiusDamage (self, self, 35*cells, world);
return;
}
if (self.width < time)
{
sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
self.width = time + 0.6;
}
self.punchangle_x = -2;
self.currentammo = self.ammo_cells = self.ammo_cells - 1;
org = self.origin + '0 0 16'+ v_forward * 8;
traceline2(org, org + v_forward * 720, self, TRACE_NOMONSTERS);
ClearMultiDamage();
LightningBeam(org, trace_endpos + v_forward * 8, self, 30);
ApplyMultiDamage();
/* WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_LIGHTNING2); // kabewm
WriteEntity (MSG_BROADCAST, self);
WriteCoord (MSG_BROADCAST, org_x);
WriteCoord (MSG_BROADCAST, org_y);
WriteCoord (MSG_BROADCAST, org_z);
WriteCoord (MSG_BROADCAST, trace_endpos_x);
WriteCoord (MSG_BROADCAST, trace_endpos_y);
WriteCoord (MSG_BROADCAST, trace_endpos_z);
if (trace_ent.takedamage) {
//trace_ent.customflags = trace_ent.customflags | CFL_ZAPPED;
org = trace_endpos;
particle (org, '0 0 100', 225, 3 * W_ChainLightning(trace_ent, self, 32));
}
*/
}