]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/arc.qc
Add a new attack mode to Arc (disabled by default)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / arc.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Arc, Weapon)
3 /* ammotype  */ ATTRIB(Arc, ammo_field, .int, ammo_cells)
4 /* impulse   */ ATTRIB(Arc, impulse, int, 3)
5 /* flags     */ ATTRIB(Arc, spawnflags, int, WEP_FLAG_NORMAL);
6 /* rating    */ ATTRIB(Arc, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color     */ ATTRIB(Arc, wpcolor, vector, '1 1 1');
8 /* modelname */ ATTRIB(Arc, mdl, string, "arc");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(Arc, m_model, Model, MDL_ARC_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(Arc, w_crosshair, string, "gfx/crosshairhlac");
13 /* crosshair */ ATTRIB(Arc, w_crosshair_size, float, 0.7);
14 /* wepimg    */ ATTRIB(Arc, model2, string, "weaponarc");
15 /* refname   */ ATTRIB(Arc, netname, string, "arc");
16 /* wepname   */ ATTRIB(Arc, m_name, string, _("Arc"));
17
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, bolt, float, NONE) \
21                 P(class, prefix, bolt_ammo, float, NONE) \
22         P(class, prefix, bolt_damageforcescale, float, NONE) \
23         P(class, prefix, bolt_damage, float, NONE) \
24         P(class, prefix, bolt_edgedamage, float, NONE) \
25         P(class, prefix, bolt_force, float, NONE) \
26         P(class, prefix, bolt_health, float, NONE) \
27         P(class, prefix, bolt_lifetime, float, NONE) \
28         P(class, prefix, bolt_radius, float, NONE) \
29         P(class, prefix, bolt_refire, float, NONE) \
30         P(class, prefix, bolt_speed, float, NONE) \
31         P(class, prefix, bolt_spread, float, NONE) \
32                 P(class, prefix, beam_ammo, float, NONE) \
33         P(class, prefix, beam_animtime, float, NONE) \
34         P(class, prefix, beam_botaimlifetime, float, NONE) \
35         P(class, prefix, beam_botaimspeed, float, NONE) \
36         P(class, prefix, beam_damage, float, NONE) \
37         P(class, prefix, beam_degreespersegment, float, NONE) \
38         P(class, prefix, beam_distancepersegment, float, NONE) \
39         P(class, prefix, beam_falloff_halflifedist, float, NONE) \
40         P(class, prefix, beam_falloff_maxdist, float, NONE) \
41         P(class, prefix, beam_falloff_mindist, float, NONE) \
42         P(class, prefix, beam_force, float, NONE) \
43         P(class, prefix, beam_healing_amax, float, NONE) \
44         P(class, prefix, beam_healing_aps, float, NONE) \
45         P(class, prefix, beam_healing_hmax, float, NONE) \
46         P(class, prefix, beam_healing_hps, float, NONE) \
47         P(class, prefix, beam_heat, float, NONE) /* heat increase per second (primary) */ \
48         P(class, prefix, beam_maxangle, float, NONE) \
49         P(class, prefix, beam_nonplayerdamage, float, NONE) \
50         P(class, prefix, beam_range, float, NONE) \
51         P(class, prefix, beam_refire, float, NONE) \
52         P(class, prefix, beam_returnspeed, float, NONE) \
53         P(class, prefix, beam_tightness, float, NONE) \
54         P(class, prefix, burst_ammo, float, NONE) \
55         P(class, prefix, burst_damage, float, NONE) \
56         P(class, prefix, burst_healing_aps, float, NONE) \
57         P(class, prefix, burst_healing_hps, float, NONE) \
58         P(class, prefix, burst_heat, float, NONE) /* heat increase per second (secondary) */ \
59         P(class, prefix, cooldown, float, NONE) /* heat decrease per second when resting */ \
60         P(class, prefix, overheat_max, float, NONE) /* maximum heat before jamming */ \
61         P(class, prefix, overheat_min, float, NONE) /* minimum heat to wait for cooldown */ \
62         P(class, prefix, switchdelay_drop, float, NONE) \
63         P(class, prefix, switchdelay_raise, float, NONE) \
64         P(class, prefix, weaponreplace, string, NONE) \
65         P(class, prefix, weaponstartoverride, float, NONE) \
66         P(class, prefix, weaponstart, float, NONE) \
67         P(class, prefix, weaponthrowable, float, NONE) \
68     END()
69     W_PROPS(X, Arc, arc)
70 #undef X
71
72 ENDCLASS(Arc)
73 REGISTER_WEAPON(ARC, arc, NEW(Arc));
74
75
76 #ifndef MENUQC
77 const float ARC_MAX_SEGMENTS = 20;
78 vector arc_shotorigin[4];
79 .vector beam_start;
80 .vector beam_dir;
81 .vector beam_wantdir;
82 .int beam_type;
83
84 const int ARC_BT_MISS =        0x00;
85 const int ARC_BT_WALL =        0x01;
86 const int ARC_BT_HEAL =        0x02;
87 const int ARC_BT_HIT =         0x03;
88 const int ARC_BT_BURST_MISS =  0x10;
89 const int ARC_BT_BURST_WALL =  0x11;
90 const int ARC_BT_BURST_HEAL =  0x12;
91 const int ARC_BT_BURST_HIT =   0x13;
92 const int ARC_BT_BURSTMASK =   0x10;
93
94 const int ARC_SF_SETTINGS =    BIT(0);
95 const int ARC_SF_START =       BIT(1);
96 const int ARC_SF_WANTDIR =     BIT(2);
97 const int ARC_SF_BEAMDIR =     BIT(3);
98 const int ARC_SF_BEAMTYPE =    BIT(4);
99 const int ARC_SF_LOCALMASK =   ARC_SF_START | ARC_SF_WANTDIR | ARC_SF_BEAMDIR;
100 #endif
101 #ifdef SVQC
102 .entity arc_beam;
103 .bool arc_BUTTON_ATCK_prev; // for better animation control
104 .float beam_prev;
105 .float beam_initialized;
106 .float beam_bursting;
107 .float beam_teleporttime;
108 .float beam_heat; // (beam) amount of heat produced
109 .float arc_overheat; // (dropped arc/player) time during which it's too hot
110 .float arc_cooldown; // (dropped arc/player) cooling speed
111 .float arc_heat_percent = _STAT(ARC_HEAT);
112 .float arc_smoke_sound;
113 #endif
114 #ifdef CSQC
115
116 .vector beam_color;
117 .float beam_alpha;
118 .float beam_thickness;
119 .entity beam_traileffect;
120 .entity beam_hiteffect;
121 .float beam_hitlight[4]; // 0: radius, 123: rgb
122 .entity beam_muzzleeffect;
123 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
124 .string beam_image;
125
126 .entity beam_muzzleentity;
127
128 .float beam_degreespersegment;
129 .float beam_distancepersegment;
130 .float beam_usevieworigin;
131 .float beam_initialized;
132 .float beam_maxangle;
133 .float beam_range;
134 .float beam_returnspeed;
135 .float beam_tightness;
136 .vector beam_shotorigin;
137
138 entity Draw_ArcBeam_callback_entity;
139 float Draw_ArcBeam_callback_last_thickness;
140 vector Draw_ArcBeam_callback_last_top; // NOTE: in same coordinate system as player.
141 vector Draw_ArcBeam_callback_last_bottom; // NOTE: in same coordinate system as player.
142 #endif
143 #endif
144 #ifdef IMPLEMENTATION
145 #ifdef SVQC
146 spawnfunc(weapon_arc) { weapon_defaultspawnfunc(this, WEP_ARC); }
147
148 bool W_Arc_Beam_Send(entity this, entity to, int sf)
149 {
150         WriteHeader(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
151
152         // Truncate information when this beam is displayed to the owner client
153         // - The owner client has no use for beam start position or directions,
154         //    it always figures this information out for itself with csqc code.
155         // - Spectating the owner also truncates this information.
156         float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
157         if(drawlocal) { sf &= ~ARC_SF_LOCALMASK; }
158
159         WriteByte(MSG_ENTITY, sf);
160
161         if(sf & ARC_SF_SETTINGS) // settings information
162         {
163                 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
164                 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
165                 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
166                 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
167                 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
168                 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
169
170                 WriteByte(MSG_ENTITY, drawlocal);
171         }
172         if(sf & ARC_SF_START) // starting location
173         {
174                 WriteCoord(MSG_ENTITY, self.beam_start.x);
175                 WriteCoord(MSG_ENTITY, self.beam_start.y);
176                 WriteCoord(MSG_ENTITY, self.beam_start.z);
177         }
178         if(sf & ARC_SF_WANTDIR) // want/aim direction
179         {
180                 WriteCoord(MSG_ENTITY, self.beam_wantdir.x);
181                 WriteCoord(MSG_ENTITY, self.beam_wantdir.y);
182                 WriteCoord(MSG_ENTITY, self.beam_wantdir.z);
183         }
184         if(sf & ARC_SF_BEAMDIR) // beam direction
185         {
186                 WriteCoord(MSG_ENTITY, self.beam_dir.x);
187                 WriteCoord(MSG_ENTITY, self.beam_dir.y);
188                 WriteCoord(MSG_ENTITY, self.beam_dir.z);
189         }
190         if(sf & ARC_SF_BEAMTYPE) // beam type
191         {
192                 WriteByte(MSG_ENTITY, self.beam_type);
193         }
194
195         return true;
196 }
197
198 void Reset_ArcBeam(entity player, vector forward)
199 {
200         if (!player.arc_beam) {
201                 return;
202         }
203         player.arc_beam.beam_dir = forward;
204         player.arc_beam.beam_teleporttime = time;
205 }
206
207 float Arc_GetHeat_Percent(entity player)
208 {
209         if ( WEP_CVAR(arc, overheat_max) <= 0 ||  WEP_CVAR(arc, overheat_max) <= 0 )
210         {
211                 player.arc_overheat = 0;
212                 return 0;
213         }
214
215         if ( player.arc_beam )
216                 return player.arc_beam.beam_heat/WEP_CVAR(arc, overheat_max);
217
218         if ( player.arc_overheat > time )
219         {
220                 return (player.arc_overheat-time) / WEP_CVAR(arc, overheat_max)
221                         * player.arc_cooldown;
222         }
223
224         return 0;
225 }
226 void Arc_Player_SetHeat(entity player)
227 {
228         player.arc_heat_percent = Arc_GetHeat_Percent(player);
229         //dprint("Heat: ",ftos(player.arc_heat_percent*100),"%\n");
230 }
231
232 void W_Arc_Bolt_Explode()
233 {SELFPARAM();
234         self.event_damage = func_null;
235         RadiusDamage(self, self.realowner, WEP_CVAR(arc, bolt_damage), WEP_CVAR(arc, bolt_edgedamage), WEP_CVAR(arc, bolt_radius), world, world, WEP_CVAR(arc, bolt_force), self.projectiledeathtype, other);
236
237         remove(self);
238 }
239
240 void W_Arc_Bolt_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
241 {
242         if(this.health <= 0)
243                 return;
244
245         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1))
246                 return; // g_projectiles_damage says to halt
247
248         this.health = this.health - damage;
249         this.angles = vectoangles(this.velocity);
250
251         if(this.health <= 0)
252                 WITH(entity, self, this, W_PrepareExplosionByDamage(attacker, this.think));
253 }
254
255 void W_Arc_Bolt_Touch()
256 {SELFPARAM();
257         PROJECTILE_TOUCH;
258         self.use();
259 }
260
261 void W_Arc_Attack_Bolt(Weapon thiswep)
262 {SELFPARAM();
263         entity missile;
264
265         W_DecreaseAmmo(thiswep, self, WEP_CVAR(arc, bolt_ammo));
266
267         W_SetupShot(self, false, 2, SND(LASERGUN_FIRE), CH_WEAPON_A, WEP_CVAR(arc, bolt_damage));
268
269         Send_Effect(EFFECT_ARC_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
270
271         missile = new(missile);
272         missile.owner = missile.realowner = self;
273         missile.bot_dodge = true;
274         missile.bot_dodgerating = WEP_CVAR(arc, bolt_damage);
275
276         missile.takedamage = DAMAGE_YES;
277         missile.health = WEP_CVAR(arc, bolt_health);
278         missile.damageforcescale = WEP_CVAR(arc, bolt_damageforcescale);
279         missile.event_damage = W_Arc_Bolt_Damage;
280         missile.damagedbycontents = true;
281
282         missile.touch = W_Arc_Bolt_Touch;
283         missile.use = W_Arc_Bolt_Explode;
284         missile.think = adaptor_think2use_hittype_splash;
285         missile.nextthink = time + WEP_CVAR(arc, bolt_lifetime);
286         PROJECTILE_MAKETRIGGER(missile);
287         missile.projectiledeathtype = WEP_ARC.m_id | HITTYPE_SECONDARY;
288         setorigin(missile, w_shotorg);
289         setsize(missile, '0 0 0', '0 0 0');
290
291         missile.movetype = MOVETYPE_FLY;
292         W_SetupProjVelocity_PRE(missile, arc, bolt_);
293
294         missile.angles = vectoangles(missile.velocity);
295         missile.flags = FL_PROJECTILE;
296         missile.missile_flags = MIF_SPLASH;
297
298         CSQCProjectile(missile, true, PROJECTILE_ARC_BOLT, true);
299
300         MUTATOR_CALLHOOK(EditProjectile, self, missile);
301 }
302
303 void W_Arc_Beam_Think()
304 {SELFPARAM();
305         if(self != self.owner.arc_beam)
306         {
307                 remove(self);
308                 return;
309         }
310
311
312         float burst = 0;
313         if( (self.owner.BUTTON_ATCK2 && !WEP_CVAR(arc, bolt)) || self.beam_bursting)
314         {
315                 if(!self.beam_bursting)
316                         self.beam_bursting = true;
317                 burst = ARC_BT_BURSTMASK;
318         }
319
320         Weapon thiswep = WEP_ARC;
321
322         if(
323                 !IS_PLAYER(self.owner)
324                 ||
325                 (self.owner.(thiswep.ammo_field) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
326                 ||
327                 IS_DEAD(self.owner)
328                 ||
329                 (!self.owner.BUTTON_ATCK && !burst )
330                 ||
331                 STAT(FROZEN, self.owner)
332                 ||
333                 self.owner.vehicle
334                 ||
335                 (WEP_CVAR(arc, overheat_max) > 0 && self.beam_heat >= WEP_CVAR(arc, overheat_max))
336         )
337         {
338                 if ( WEP_CVAR(arc, cooldown) > 0 )
339                 {
340                         float cooldown_speed = 0;
341                         if ( self.beam_heat > WEP_CVAR(arc, overheat_min) && WEP_CVAR(arc, cooldown) > 0 )
342                         {
343                                 cooldown_speed = WEP_CVAR(arc, cooldown);
344                         }
345                         else if ( !burst )
346                         {
347                                 cooldown_speed = self.beam_heat / WEP_CVAR(arc, beam_refire);
348                         }
349
350                         if ( cooldown_speed )
351                         {
352                                 self.owner.arc_overheat = time + self.beam_heat / cooldown_speed;
353                                 self.owner.arc_cooldown = cooldown_speed;
354                         }
355
356                         if ( WEP_CVAR(arc, overheat_max) > 0 && self.beam_heat >= WEP_CVAR(arc, overheat_max) )
357                         {
358                                 Send_Effect(EFFECT_ARC_OVERHEAT,
359                                         self.beam_start, self.beam_wantdir, 1 );
360                                 sound(self, CH_WEAPON_A, SND_ARC_STOP, VOL_BASE, ATTN_NORM);
361                         }
362                 }
363
364                 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
365                 setself(self.owner);
366                 Weapon w = WEP_ARC;
367                 if(!w.wr_checkammo1(w) && !w.wr_checkammo2(w))
368                 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
369                 {
370                         // note: this doesn't force the switch
371                         W_SwitchToOtherWeapon(self);
372                 }
373                 setself(this);
374                 remove(self);
375                 return;
376         }
377
378         // decrease ammo
379         float coefficient = frametime;
380         if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
381         {
382                 float rootammo;
383                 if(burst)
384                         { rootammo = WEP_CVAR(arc, burst_ammo); }
385                 else
386                         { rootammo = WEP_CVAR(arc, beam_ammo); }
387
388                 if(rootammo)
389                 {
390                         coefficient = min(coefficient, self.owner.(thiswep.ammo_field) / rootammo);
391                         self.owner.(thiswep.ammo_field) = max(0, self.owner.(thiswep.ammo_field) - (rootammo * frametime));
392                 }
393         }
394         float heat_speed = burst ? WEP_CVAR(arc, burst_heat) : WEP_CVAR(arc, beam_heat);
395         self.beam_heat = min( WEP_CVAR(arc, overheat_max), self.beam_heat + heat_speed*frametime );
396
397         makevectors(self.owner.v_angle);
398
399         W_SetupShot_Range(
400                 self.owner,
401                 true,
402                 0,
403                 "",
404                 0,
405                 WEP_CVAR(arc, beam_damage) * coefficient,
406                 WEP_CVAR(arc, beam_range)
407         );
408
409         // After teleport, "lock" the beam until the teleport is confirmed.
410         if (time < self.beam_teleporttime + ANTILAG_LATENCY(self.owner)) {
411                 w_shotdir = self.beam_dir;
412         }
413
414         // network information: shot origin and want/aim direction
415         if(self.beam_start != w_shotorg)
416         {
417                 self.SendFlags |= ARC_SF_START;
418                 self.beam_start = w_shotorg;
419         }
420         if(self.beam_wantdir != w_shotdir)
421         {
422                 self.SendFlags |= ARC_SF_WANTDIR;
423                 self.beam_wantdir = w_shotdir;
424         }
425
426         if(!self.beam_initialized)
427         {
428                 self.beam_dir = w_shotdir;
429                 self.beam_initialized = true;
430         }
431
432         // WEAPONTODO: Detect player velocity so that the beam curves when moving too
433         // idea: blend together self.beam_dir with the inverted direction the player is moving in
434         // might have to make some special accomodation so that it only uses view_right and view_up
435
436         // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
437
438         float segments;
439         if(self.beam_dir != w_shotdir)
440         {
441                 // calculate how much we're going to move the end of the beam to the want position
442                 // WEAPONTODO (server and client):
443                 // blendfactor never actually becomes 0 in this situation, which is a problem
444                 // regarding precision... this means that self.beam_dir and w_shotdir approach
445                 // eachother, however they never actually become the same value with this method.
446                 // Perhaps we should do some form of rounding/snapping?
447                 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
448                 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
449                 {
450                         // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
451                         float blendfactor = bound(
452                                 0,
453                                 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
454                                 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
455                         );
456                         self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
457                 }
458                 else
459                 {
460                         // the radius is not too far yet, no worries :D
461                         float blendfactor = bound(
462                                 0,
463                                 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
464                                 1
465                         );
466                         self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
467                 }
468
469                 // network information: beam direction
470                 self.SendFlags |= ARC_SF_BEAMDIR;
471
472                 // calculate how many segments are needed
473                 float max_allowed_segments;
474
475                 if(WEP_CVAR(arc, beam_distancepersegment))
476                 {
477                         max_allowed_segments = min(
478                                 ARC_MAX_SEGMENTS,
479                                 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
480                         );
481                 }
482                 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
483
484                 if(WEP_CVAR(arc, beam_degreespersegment))
485                 {
486                         segments = bound(
487                                 1,
488                                 (
489                                         min(
490                                                 angle,
491                                                 WEP_CVAR(arc, beam_maxangle)
492                                         )
493                                         /
494                                         WEP_CVAR(arc, beam_degreespersegment)
495                                 ),
496                                 max_allowed_segments
497                         );
498                 }
499                 else { segments = 1; }
500         }
501         else { segments = 1; }
502
503         vector beam_endpos = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
504         vector beam_controlpoint = w_shotorg + w_shotdir * (WEP_CVAR(arc, beam_range) * (1 - WEP_CVAR(arc, beam_tightness)));
505
506         float i;
507         float new_beam_type = 0;
508         vector last_origin = w_shotorg;
509         for(i = 1; i <= segments; ++i)
510         {
511                 // WEAPONTODO (client):
512                 // In order to do nice fading and pointing on the starting segment, we must always
513                 // have that drawn as a separate triangle... However, that is difficult to do when
514                 // keeping in mind the above problems and also optimizing the amount of segments
515                 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
516
517                 vector new_origin = bezier_quadratic_getpoint(
518                         w_shotorg,
519                         beam_controlpoint,
520                         beam_endpos,
521                         i / segments);
522                 vector new_dir = normalize(new_origin - last_origin);
523
524                 WarpZone_traceline_antilag(
525                         self.owner,
526                         last_origin,
527                         new_origin,
528                         MOVE_NORMAL,
529                         self.owner,
530                         ANTILAG_LATENCY(self.owner)
531                 );
532
533                 // Do all the transforms for warpzones right now, as we already
534                 // "are" in the post-trace system (if we hit a player, that's
535                 // always BEHIND the last passed wz).
536                 last_origin = trace_endpos;
537                 w_shotorg = WarpZone_TransformOrigin(WarpZone_trace_transform, w_shotorg);
538                 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
539                 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
540                 new_dir = WarpZone_TransformVelocity(WarpZone_trace_transform, new_dir);
541
542                 float is_player = (
543                         IS_PLAYER(trace_ent)
544                         ||
545                         trace_ent.classname == "body"
546                         ||
547                         IS_MONSTER(trace_ent)
548                 );
549
550                 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
551                 {
552                         // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
553                         // NO. trace_endpos should be just fine. If not,
554                         // that's an engine bug that needs proper debugging.
555                         vector hitorigin = trace_endpos;
556
557                         float falloff = ExponentialFalloff(
558                                 WEP_CVAR(arc, beam_falloff_mindist),
559                                 WEP_CVAR(arc, beam_falloff_maxdist),
560                                 WEP_CVAR(arc, beam_falloff_halflifedist),
561                                 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
562                         );
563
564                         if(is_player && SAME_TEAM(self.owner, trace_ent))
565                         {
566                                 float roothealth, rootarmor;
567                                 if(burst)
568                                 {
569                                         roothealth = WEP_CVAR(arc, burst_healing_hps);
570                                         rootarmor = WEP_CVAR(arc, burst_healing_aps);
571                                 }
572                                 else
573                                 {
574                                         roothealth = WEP_CVAR(arc, beam_healing_hps);
575                                         rootarmor = WEP_CVAR(arc, beam_healing_aps);
576                                 }
577
578                                 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
579                                 {
580                                         trace_ent.health = min(
581                                                 trace_ent.health + (roothealth * coefficient),
582                                                 WEP_CVAR(arc, beam_healing_hmax)
583                                         );
584                                 }
585                                 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
586                                 {
587                                         trace_ent.armorvalue = min(
588                                                 trace_ent.armorvalue + (rootarmor * coefficient),
589                                                 WEP_CVAR(arc, beam_healing_amax)
590                                         );
591                                 }
592
593                                 // stop rot, set visual effect
594                                 if(roothealth || rootarmor)
595                                 {
596                                         trace_ent.pauserothealth_finished = max(
597                                                 trace_ent.pauserothealth_finished,
598                                                 time + autocvar_g_balance_pause_health_rot
599                                         );
600                                         trace_ent.pauserotarmor_finished = max(
601                                                 trace_ent.pauserotarmor_finished,
602                                                 time + autocvar_g_balance_pause_armor_rot
603                                         );
604                                         new_beam_type = ARC_BT_HEAL;
605                                 }
606                         }
607                         else
608                         {
609                                 float rootdamage;
610                                 if(is_player)
611                                 {
612                                         if(burst)
613                                                 { rootdamage = WEP_CVAR(arc, burst_damage); }
614                                         else
615                                                 { rootdamage = WEP_CVAR(arc, beam_damage); }
616                                 }
617                                 else
618                                         { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
619
620                                 if(accuracy_isgooddamage(self.owner, trace_ent))
621                                 {
622                                         accuracy_add(
623                                                 self.owner,
624                                                 WEP_ARC.m_id,
625                                                 0,
626                                                 rootdamage * coefficient * falloff
627                                         );
628                                 }
629
630                                 Damage(
631                                         trace_ent,
632                                         self.owner,
633                                         self.owner,
634                                         rootdamage * coefficient * falloff,
635                                         WEP_ARC.m_id,
636                                         hitorigin,
637                                         WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
638                                 );
639
640                                 new_beam_type = ARC_BT_HIT;
641                         }
642                         break;
643                 }
644                 else if(trace_fraction != 1)
645                 {
646                         // we collided with geometry
647                         new_beam_type = ARC_BT_WALL;
648                         break;
649                 }
650         }
651
652         // te_explosion(trace_endpos);
653
654         // if we're bursting, use burst visual effects
655         new_beam_type |= burst;
656
657         // network information: beam type
658         if(new_beam_type != self.beam_type)
659         {
660                 self.SendFlags |= ARC_SF_BEAMTYPE;
661                 self.beam_type = new_beam_type;
662         }
663
664         self.owner.beam_prev = time;
665         self.nextthink = time;
666 }
667
668 void W_Arc_Beam(float burst)
669 {SELFPARAM();
670
671         // only play fire sound if 1 sec has passed since player let go the fire button
672         if(time - self.beam_prev > 1)
673                 sound(self, CH_WEAPON_A, SND_ARC_FIRE, VOL_BASE, ATTN_NORM);
674
675         entity beam = self.arc_beam = new(W_Arc_Beam);
676         beam.solid = SOLID_NOT;
677         beam.think = W_Arc_Beam_Think;
678         beam.owner = self;
679         beam.movetype = MOVETYPE_NONE;
680         beam.bot_dodge = true;
681         beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
682         beam.beam_bursting = burst;
683         Net_LinkEntity(beam, false, 0, W_Arc_Beam_Send);
684
685         WITH(entity, self, beam, beam.think());
686 }
687
688 void Arc_Smoke()
689 {SELFPARAM();
690         makevectors(self.v_angle);
691         W_SetupShot_Range(self,true,0,"",0,0,0);
692
693         vector smoke_origin = w_shotorg + self.velocity*frametime;
694         if ( self.arc_overheat > time )
695         {
696                 if ( random() < self.arc_heat_percent )
697                         Send_Effect(EFFECT_ARC_SMOKE, smoke_origin, '0 0 0', 1 );
698                 if ( self.BUTTON_ATCK || self.BUTTON_ATCK2 )
699                 {
700                         Send_Effect(EFFECT_ARC_OVERHEAT_FIRE, smoke_origin, w_shotdir, 1 );
701                         if ( !self.arc_smoke_sound )
702                         {
703                                 self.arc_smoke_sound = 1;
704                                 sound(self, CH_SHOTS_SINGLE, SND_ARC_LOOP_OVERHEAT, VOL_BASE, ATTN_NORM);
705                         }
706                 }
707         }
708         else if ( self.arc_beam && WEP_CVAR(arc, overheat_max) > 0 &&
709                         self.arc_beam.beam_heat > WEP_CVAR(arc, overheat_min) )
710         {
711                 if ( random() < (self.arc_beam.beam_heat-WEP_CVAR(arc, overheat_min)) /
712                                 ( WEP_CVAR(arc, overheat_max)-WEP_CVAR(arc, overheat_min) ) )
713                         Send_Effect(EFFECT_ARC_SMOKE, smoke_origin, '0 0 0', 1 );
714         }
715
716         if (  self.arc_smoke_sound && ( self.arc_overheat <= time ||
717                 !( self.BUTTON_ATCK || self.BUTTON_ATCK2 ) ) || PS(self).m_switchweapon != WEP_ARC )
718         {
719                 self.arc_smoke_sound = 0;
720                 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
721         }
722 }
723
724                 METHOD(Arc, wr_aim, void(entity thiswep))
725                 {
726                         SELFPARAM();
727                         if(WEP_CVAR(arc, beam_botaimspeed))
728                         {
729                                 self.BUTTON_ATCK = bot_aim(
730                                         WEP_CVAR(arc, beam_botaimspeed),
731                                         0,
732                                         WEP_CVAR(arc, beam_botaimlifetime),
733                                         false
734                                 );
735                         }
736                         else
737                         {
738                                 self.BUTTON_ATCK = bot_aim(
739                                         1000000,
740                                         0,
741                                         0.001,
742                                         false
743                                 );
744                         }
745                 }
746                 METHOD(Arc, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
747                 {
748                         Arc_Player_SetHeat(actor);
749                         Arc_Smoke();
750
751                         bool beam_fire2 = ((fire & 2) && !WEP_CVAR(arc, bolt));
752
753                         if (time >= actor.arc_overheat)
754                         if ((fire & 1) || beam_fire2 || actor.arc_beam.beam_bursting)
755                         {
756
757                                 if(actor.arc_BUTTON_ATCK_prev)
758                                 {
759                                         #if 0
760                                         if(actor.animstate_startframe == actor.anim_shoot.x && actor.animstate_numframes == actor.anim_shoot.y)
761                                                 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
762                                         else
763                                         #endif
764                                                 weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, WEP_CVAR(arc, beam_animtime), w_ready);
765                                 }
766
767                                 if((!actor.arc_beam) || wasfreed(actor.arc_beam))
768                                 {
769                                         if(weapon_prepareattack(thiswep, actor, weaponentity, boolean(beam_fire2), 0))
770                                         {
771                                                 W_Arc_Beam(boolean(beam_fire2));
772
773                                                 if(!actor.arc_BUTTON_ATCK_prev)
774                                                 {
775                                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
776                                                         actor.arc_BUTTON_ATCK_prev = true;
777                                                 }
778                                         }
779                                 }
780
781                                 return;
782                         }
783                         else if(fire & 2)
784                         {
785                                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(arc, bolt_refire)))
786                                 {
787                                         W_Arc_Attack_Bolt(thiswep);
788                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(arc, bolt_refire), w_ready);
789                                 }
790                         }
791
792                         if(actor.arc_BUTTON_ATCK_prev)
793                         {
794                                 sound(actor, CH_WEAPON_A, SND_ARC_STOP, VOL_BASE, ATTN_NORM);
795                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
796                                 int slot = weaponslot(weaponentity);
797                                 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
798                         }
799                         actor.arc_BUTTON_ATCK_prev = false;
800
801                         #if 0
802                         if(fire & 2)
803                         if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_arc_secondary_refire))
804                         {
805                                 W_Arc_Attack2();
806                                 actor.arc_count = autocvar_g_balance_arc_secondary_count;
807                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
808                                 actor.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
809                         }
810                         #endif
811                 }
812                 METHOD(Arc, wr_init, void(entity thiswep))
813                 {
814                         if(!arc_shotorigin[0])
815                         {
816                                 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC.m_id), false, false, 1);
817                                 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC.m_id), false, false, 2);
818                                 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC.m_id), false, false, 3);
819                                 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC.m_id), false, false, 4);
820                         }
821                 }
822                 METHOD(Arc, wr_checkammo1, bool(entity thiswep))
823                 {
824                         SELFPARAM();
825                         return ((!WEP_CVAR(arc, beam_ammo)) || (self.(thiswep.ammo_field) > 0));
826                 }
827                 METHOD(Arc, wr_checkammo2, bool(entity thiswep))
828                 {
829                         SELFPARAM();
830                         if(WEP_CVAR(arc, bolt))
831                         {
832                                 float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR(arc, bolt_ammo);
833                                 ammo_amount += self.(weapon_load[WEP_ARC.m_id]) >= WEP_CVAR(arc, bolt_ammo);
834                                 return ammo_amount;
835                         }
836                         else
837                                 return WEP_CVAR(arc, overheat_max) > 0 &&
838                                         ((!WEP_CVAR(arc, burst_ammo)) || (self.(thiswep.ammo_field) > 0));
839                 }
840                 METHOD(Arc, wr_killmessage, int(entity thiswep))
841                 {
842                         if(w_deathtype & HITTYPE_SECONDARY)
843                                 return WEAPON_ARC_MURDER_SPRAY;
844                         else
845                                 return WEAPON_ARC_MURDER;
846                 }
847                 METHOD(Arc, wr_drop, void(entity thiswep))
848                 {
849                         weapon_dropevent_item.arc_overheat = self.arc_overheat;
850                         weapon_dropevent_item.arc_cooldown = self.arc_cooldown;
851                         self.arc_overheat = 0;
852                         self.arc_cooldown = 0;
853                 }
854                 METHOD(Arc, wr_pickup, void(entity thiswep))
855                 {
856                         if ( !client_hasweapon(self, thiswep, false, false) &&
857                                 weapon_dropevent_item.arc_overheat > time )
858                         {
859                                 self.arc_overheat = weapon_dropevent_item.arc_overheat;
860                                 self.arc_cooldown = weapon_dropevent_item.arc_cooldown;
861                         }
862                 }
863 #endif
864 #ifdef CSQC
865                 METHOD(Arc, wr_impacteffect, void(entity thiswep))
866                 {
867                         if(w_deathtype & HITTYPE_SECONDARY)
868                         {
869                                 vector org2;
870                                 org2 = w_org + w_backoff * 6;
871                                 pointparticles(EFFECT_ARC_BOLT_EXPLODE, org2, w_backoff * 1000, 1);
872                                 if(!w_issilent) { sound(self, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM); }
873                         }
874                 }
875
876 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
877 {
878         entity beam = Draw_ArcBeam_callback_entity;
879         vector transformed_view_org;
880         transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
881
882         // Thickdir shall be perpendicular to the beam and to the view-to-beam direction (WEAPONTODO: WHY)
883         // WEAPONTODO: Wouldn't it be better to be perpendicular to the beam and to the view FORWARD direction?
884         vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
885
886         vector hitorigin;
887
888         // draw segment
889         #if 0
890         if(trace_fraction != 1)
891         {
892                 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
893                 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
894                 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
895         }
896         else
897         {
898                 hitorigin = hit;
899         }
900         #else
901         hitorigin = hit;
902         #endif
903
904         // decide upon thickness
905         float thickness = beam.beam_thickness;
906
907         // draw primary beam render
908         vector top    = hitorigin + (thickdir * thickness);
909         vector bottom = hitorigin - (thickdir * thickness);
910
911         vector last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
912         vector last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
913
914         R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
915         R_PolygonVertex(
916                 top,
917                 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
918                 beam.beam_color,
919                 beam.beam_alpha
920         );
921         R_PolygonVertex(
922                 last_top,
923                 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
924                 beam.beam_color,
925                 beam.beam_alpha
926         );
927         R_PolygonVertex(
928                 last_bottom,
929                 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
930                 beam.beam_color,
931                 beam.beam_alpha
932         );
933         R_PolygonVertex(
934                 bottom,
935                 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
936                 beam.beam_color,
937                 beam.beam_alpha
938         );
939         R_EndPolygon();
940
941         // draw trailing particles
942         // NOTES:
943         //  - Don't use spammy particle counts here, use a FEW small particles around the beam
944         //  - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
945         if(beam.beam_traileffect)
946         {
947                 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
948         }
949
950         // set up for the next
951         Draw_ArcBeam_callback_last_thickness = thickness;
952         Draw_ArcBeam_callback_last_top = WarpZone_UnTransformOrigin(WarpZone_trace_transform, top);
953         Draw_ArcBeam_callback_last_bottom = WarpZone_UnTransformOrigin(WarpZone_trace_transform, bottom);
954 }
955
956 void Reset_ArcBeam()
957 {
958         entity e;
959         for (e = world; (e = findfloat(e, beam_usevieworigin, 1)); ) {
960                 e.beam_initialized = false;
961         }
962         for (e = world; (e = findfloat(e, beam_usevieworigin, 2)); ) {
963                 e.beam_initialized = false;
964         }
965 }
966
967 void Draw_ArcBeam(entity this)
968 {
969         float dt = time - this.move_time;
970         this.move_time = time;
971         if(dt <= 0) { return; }
972
973         if(!this.beam_usevieworigin)
974         {
975                 InterpolateOrigin_Do(this);
976         }
977
978         // origin = beam starting origin
979         // v_angle = wanted/aim direction
980         // angles = current direction of beam
981
982         vector start_pos;
983         vector wantdir; //= view_forward;
984         vector beamdir; //= this.beam_dir;
985
986         float segments;
987         if(this.beam_usevieworigin)
988         {
989                 // WEAPONTODO:
990                 // Currently we have to replicate nearly the same method of figuring
991                 // out the shotdir that the server does... Ideally in the future we
992                 // should be able to acquire this from a generalized function built
993                 // into a weapon system for client code.
994
995                 // find where we are aiming
996                 makevectors(warpzone_save_view_angles);
997                 vector forward = v_forward;
998                 vector right = v_right;
999                 vector up = v_up;
1000
1001                 // decide upon start position
1002                 if(this.beam_usevieworigin == 2)
1003                         { start_pos = warpzone_save_view_origin; }
1004                 else
1005                         { start_pos = this.origin; }
1006
1007                 // trace forward with an estimation
1008                 WarpZone_TraceLine(
1009                         start_pos,
1010                         start_pos + forward * this.beam_range,
1011                         MOVE_NOMONSTERS,
1012                         this
1013                 );
1014
1015                 // untransform in case our trace went through a warpzone
1016                 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
1017
1018                 // un-adjust trueaim if shotend is too close
1019                 if(vdist(end_pos - start_pos, <, g_trueaim_minrange))
1020                         end_pos = start_pos + (forward * g_trueaim_minrange);
1021
1022                 // move shot origin to the actual gun muzzle origin
1023                 vector origin_offset =
1024                           right * -this.beam_shotorigin.y
1025                         + up * this.beam_shotorigin.z;
1026
1027                 start_pos = start_pos + origin_offset;
1028
1029                 // Move it also forward, but only as far as possible without hitting anything. Don't poke into walls!
1030                 traceline(start_pos, start_pos + forward * this.beam_shotorigin.x, MOVE_NORMAL, this);
1031                 start_pos = trace_endpos;
1032
1033                 // calculate the aim direction now
1034                 wantdir = normalize(end_pos - start_pos);
1035
1036                 if(!this.beam_initialized)
1037                 {
1038                         this.beam_dir = wantdir;
1039                         this.beam_initialized = true;
1040                 }
1041
1042                 if(this.beam_dir != wantdir)
1043                 {
1044                         // calculate how much we're going to move the end of the beam to the want position
1045                         // WEAPONTODO (server and client):
1046                         // blendfactor never actually becomes 0 in this situation, which is a problem
1047                         // regarding precision... this means that this.beam_dir and w_shotdir approach
1048                         // eachother, however they never actually become the same value with this method.
1049                         // Perhaps we should do some form of rounding/snapping?
1050                         float angle = vlen(wantdir - this.beam_dir) * RAD2DEG;
1051                         if(angle && (angle > this.beam_maxangle))
1052                         {
1053                                 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
1054                                 float blendfactor = bound(
1055                                         0,
1056                                         (1 - (this.beam_returnspeed * frametime)),
1057                                         min(this.beam_maxangle / angle, 1)
1058                                 );
1059                                 this.beam_dir = normalize((wantdir * (1 - blendfactor)) + (this.beam_dir * blendfactor));
1060                         }
1061                         else
1062                         {
1063                                 // the radius is not too far yet, no worries :D
1064                                 float blendfactor = bound(
1065                                         0,
1066                                         (1 - (this.beam_returnspeed * frametime)),
1067                                         1
1068                                 );
1069                                 this.beam_dir = normalize((wantdir * (1 - blendfactor)) + (this.beam_dir * blendfactor));
1070                         }
1071
1072                         // calculate how many segments are needed
1073                         float max_allowed_segments;
1074
1075                         if(this.beam_distancepersegment)
1076                         {
1077                                 max_allowed_segments = min(
1078                                         ARC_MAX_SEGMENTS,
1079                                         1 + (vlen(wantdir / this.beam_distancepersegment))
1080                                 );
1081                         }
1082                         else { max_allowed_segments = ARC_MAX_SEGMENTS; }
1083
1084                         if(this.beam_degreespersegment)
1085                         {
1086                                 segments = bound(
1087                                         1,
1088                                         (
1089                                                 min(
1090                                                         angle,
1091                                                         this.beam_maxangle
1092                                                 )
1093                                                 /
1094                                                 this.beam_degreespersegment
1095                                         ),
1096                                         max_allowed_segments
1097                                 );
1098                         }
1099                         else { segments = 1; }
1100                 }
1101                 else { segments = 1; }
1102
1103                 // set the beam direction which the rest of the code will refer to
1104                 beamdir = this.beam_dir;
1105
1106                 // finally, set this.angles to the proper direction so that muzzle attachment points in proper direction
1107                 this.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
1108         }
1109         else
1110         {
1111                 // set the values from the provided info from the networked entity
1112                 start_pos = this.origin;
1113                 wantdir = this.v_angle;
1114                 beamdir = this.angles;
1115
1116                 if(beamdir != wantdir)
1117                 {
1118                         float angle = vlen(wantdir - beamdir) * RAD2DEG;
1119
1120                         // calculate how many segments are needed
1121                         float max_allowed_segments;
1122
1123                         if(this.beam_distancepersegment)
1124                         {
1125                                 max_allowed_segments = min(
1126                                         ARC_MAX_SEGMENTS,
1127                                         1 + (vlen(wantdir / this.beam_distancepersegment))
1128                                 );
1129                         }
1130                         else { max_allowed_segments = ARC_MAX_SEGMENTS; }
1131
1132                         if(this.beam_degreespersegment)
1133                         {
1134                                 segments = bound(
1135                                         1,
1136                                         (
1137                                                 min(
1138                                                         angle,
1139                                                         this.beam_maxangle
1140                                                 )
1141                                                 /
1142                                                 this.beam_degreespersegment
1143                                         ),
1144                                         max_allowed_segments
1145                                 );
1146                         }
1147                         else { segments = 1; }
1148                 }
1149                 else { segments = 1; }
1150         }
1151
1152         setorigin(this, start_pos);
1153         this.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
1154
1155         vector beam_endpos = (start_pos + (beamdir * this.beam_range));
1156         vector beam_controlpoint = start_pos + wantdir * (this.beam_range * (1 - this.beam_tightness));
1157
1158         Draw_ArcBeam_callback_entity = this;
1159         Draw_ArcBeam_callback_last_thickness = 0;
1160         Draw_ArcBeam_callback_last_top = start_pos;
1161         Draw_ArcBeam_callback_last_bottom = start_pos;
1162
1163         vector last_origin = start_pos;
1164         vector original_start_pos = start_pos;
1165
1166         float i;
1167         for(i = 1; i <= segments; ++i)
1168         {
1169                 // WEAPONTODO (client):
1170                 // In order to do nice fading and pointing on the starting segment, we must always
1171                 // have that drawn as a separate triangle... However, that is difficult to do when
1172                 // keeping in mind the above problems and also optimizing the amount of segments
1173                 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
1174
1175                 vector new_origin = bezier_quadratic_getpoint(
1176                         start_pos,
1177                         beam_controlpoint,
1178                         beam_endpos,
1179                         i / segments);
1180
1181                 WarpZone_TraceBox_ThroughZone(
1182                         last_origin,
1183                         '0 0 0',
1184                         '0 0 0',
1185                         new_origin,
1186                         MOVE_NORMAL,
1187                         world,
1188                         world,
1189                         Draw_ArcBeam_callback
1190                 );
1191
1192                 // Do all the transforms for warpzones right now, as we already "are" in the post-trace
1193                 // system (if we hit a player, that's always BEHIND the last passed wz).
1194                 last_origin = trace_endpos;
1195                 start_pos = WarpZone_TransformOrigin(WarpZone_trace_transform, start_pos);
1196                 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
1197                 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
1198                 beamdir = WarpZone_TransformVelocity(WarpZone_trace_transform, beamdir);
1199                 Draw_ArcBeam_callback_last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
1200                 Draw_ArcBeam_callback_last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
1201
1202                 if(trace_fraction < 1) { break; }
1203         }
1204
1205         // visual effects for startpoint and endpoint
1206         if(this.beam_hiteffect)
1207         {
1208                 // FIXME we really should do this on the server so it actually
1209                 // matches gameplay. What this client side stuff is doing is no
1210                 // more than guesswork.
1211                 if((trace_ent || trace_fraction < 1) && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
1212                 pointparticles(
1213                         this.beam_hiteffect,
1214                         last_origin,
1215                         beamdir * -1,
1216                         frametime * 2
1217                 );
1218         }
1219         if(this.beam_hitlight[0])
1220         {
1221                 adddynamiclight(
1222                         last_origin,
1223                         this.beam_hitlight[0],
1224                         vec3(
1225                                 this.beam_hitlight[1],
1226                                 this.beam_hitlight[2],
1227                                 this.beam_hitlight[3]
1228                         )
1229                 );
1230         }
1231         if(this.beam_muzzleeffect)
1232         {
1233                 pointparticles(
1234                         this.beam_muzzleeffect,
1235                         original_start_pos + wantdir * 20,
1236                         wantdir * 1000,
1237                         frametime * 0.1
1238                 );
1239         }
1240         if(this.beam_muzzlelight[0])
1241         {
1242                 adddynamiclight(
1243                         original_start_pos + wantdir * 20,
1244                         this.beam_muzzlelight[0],
1245                         vec3(
1246                                 this.beam_muzzlelight[1],
1247                                 this.beam_muzzlelight[2],
1248                                 this.beam_muzzlelight[3]
1249                         )
1250                 );
1251         }
1252
1253         // cleanup
1254         Draw_ArcBeam_callback_entity = world;
1255         Draw_ArcBeam_callback_last_thickness = 0;
1256         Draw_ArcBeam_callback_last_top = '0 0 0';
1257         Draw_ArcBeam_callback_last_bottom = '0 0 0';
1258 }
1259
1260 void Remove_ArcBeam(entity this)
1261 {
1262         remove(this.beam_muzzleentity);
1263         sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
1264 }
1265
1266 NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew)
1267 {
1268         int sf = ReadByte();
1269         entity flash;
1270
1271         if(isnew)
1272         {
1273                 int gunalign = W_GetGunAlignment(world);
1274
1275                 self.beam_shotorigin = arc_shotorigin[gunalign];
1276
1277                 // set other main attributes of the beam
1278                 self.draw = Draw_ArcBeam;
1279                 self.entremove = Remove_ArcBeam;
1280                 self.move_time = time;
1281                 loopsound(self, CH_SHOTS_SINGLE, SND(ARC_LOOP), VOL_BASE, ATTEN_NORM);
1282
1283                 flash = spawn();
1284                 flash.owner = self;
1285                 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1286                 flash.drawmask = MASK_NORMAL;
1287                 flash.solid = SOLID_NOT;
1288                 flash.avelocity_z = 5000;
1289                 setattachment(flash, self, "");
1290                 setorigin(flash, '0 0 0');
1291
1292                 self.beam_muzzleentity = flash;
1293         }
1294         else
1295         {
1296                 flash = self.beam_muzzleentity;
1297         }
1298
1299         if(sf & ARC_SF_SETTINGS) // settings information
1300         {
1301                 self.beam_degreespersegment = ReadShort();
1302                 self.beam_distancepersegment = ReadShort();
1303                 self.beam_maxangle = ReadShort();
1304                 self.beam_range = ReadCoord();
1305                 self.beam_returnspeed = ReadShort();
1306                 self.beam_tightness = (ReadByte() / 10);
1307
1308                 if(ReadByte())
1309                 {
1310                         if(autocvar_chase_active)
1311                                 { self.beam_usevieworigin = 1; }
1312                         else // use view origin
1313                                 { self.beam_usevieworigin = 2; }
1314                 }
1315                 else
1316                 {
1317                         self.beam_usevieworigin = 0;
1318                 }
1319         }
1320
1321         if(!self.beam_usevieworigin)
1322         {
1323                 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1324                 self.iflags = IFLAG_ORIGIN;
1325
1326                 InterpolateOrigin_Undo(self);
1327         }
1328
1329         if(sf & ARC_SF_START) // starting location
1330         {
1331                 self.origin_x = ReadCoord();
1332                 self.origin_y = ReadCoord();
1333                 self.origin_z = ReadCoord();
1334         }
1335         else if(self.beam_usevieworigin) // infer the location from player location
1336         {
1337                 if(self.beam_usevieworigin == 2)
1338                 {
1339                         // use view origin
1340                         self.origin = view_origin;
1341                 }
1342                 else
1343                 {
1344                         // use player origin so that third person display still works
1345                         self.origin = entcs_receiver(player_localnum).origin + ('0 0 1' * STAT(VIEWHEIGHT));
1346                 }
1347         }
1348
1349         setorigin(self, self.origin);
1350
1351         if(sf & ARC_SF_WANTDIR) // want/aim direction
1352         {
1353                 self.v_angle_x = ReadCoord();
1354                 self.v_angle_y = ReadCoord();
1355                 self.v_angle_z = ReadCoord();
1356         }
1357
1358         if(sf & ARC_SF_BEAMDIR) // beam direction
1359         {
1360                 self.angles_x = ReadCoord();
1361                 self.angles_y = ReadCoord();
1362                 self.angles_z = ReadCoord();
1363         }
1364
1365         if(sf & ARC_SF_BEAMTYPE) // beam type
1366         {
1367                 self.beam_type = ReadByte();
1368                 switch(self.beam_type)
1369                 {
1370                         case ARC_BT_MISS:
1371                         {
1372                                 self.beam_color = '1 1 1';
1373                                 self.beam_alpha = 0.5;
1374                                 self.beam_thickness = 8;
1375                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1376                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1377                                 self.beam_hitlight[0] = 0;
1378                                 self.beam_hitlight[1] = 1;
1379                                 self.beam_hitlight[2] = 1;
1380                                 self.beam_hitlight[3] = 1;
1381                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1382                                 self.beam_muzzlelight[0] = 0;
1383                                 self.beam_muzzlelight[1] = 1;
1384                                 self.beam_muzzlelight[2] = 1;
1385                                 self.beam_muzzlelight[3] = 1;
1386                                 if(self.beam_muzzleeffect)
1387                                 {
1388                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1389                                         flash.alpha = self.beam_alpha;
1390                                         flash.colormod = self.beam_color;
1391                                         flash.scale = 0.5;
1392                                 }
1393                                 break;
1394                         }
1395                         case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1396                         {
1397                                 self.beam_color = '1 1 1';
1398                                 self.beam_alpha = 0.5;
1399                                 self.beam_thickness = 8;
1400                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1401                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1402                                 self.beam_hitlight[0] = 0;
1403                                 self.beam_hitlight[1] = 1;
1404                                 self.beam_hitlight[2] = 1;
1405                                 self.beam_hitlight[3] = 1;
1406                                 self.beam_muzzleeffect = NULL; // (EFFECT_GRENADE_MUZZLEFLASH);
1407                                 self.beam_muzzlelight[0] = 0;
1408                                 self.beam_muzzlelight[1] = 1;
1409                                 self.beam_muzzlelight[2] = 1;
1410                                 self.beam_muzzlelight[3] = 1;
1411                                 self.beam_image = "particles/lgbeam";
1412                                 if(self.beam_muzzleeffect)
1413                                 {
1414                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1415                                         flash.alpha = self.beam_alpha;
1416                                         flash.colormod = self.beam_color;
1417                                         flash.scale = 0.5;
1418                                 }
1419                                 break;
1420                         }
1421                         case ARC_BT_HEAL:
1422                         {
1423                                 self.beam_color = '1 1 1';
1424                                 self.beam_alpha = 0.5;
1425                                 self.beam_thickness = 8;
1426                                 self.beam_traileffect = (EFFECT_ARC_BEAM_HEAL);
1427                                 self.beam_hiteffect = (EFFECT_ARC_BEAM_HEAL_IMPACT);
1428                                 self.beam_hitlight[0] = 0;
1429                                 self.beam_hitlight[1] = 1;
1430                                 self.beam_hitlight[2] = 1;
1431                                 self.beam_hitlight[3] = 1;
1432                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1433                                 self.beam_muzzlelight[0] = 0;
1434                                 self.beam_muzzlelight[1] = 1;
1435                                 self.beam_muzzlelight[2] = 1;
1436                                 self.beam_muzzlelight[3] = 1;
1437                                 self.beam_image = "particles/lgbeam";
1438                                 if(self.beam_muzzleeffect)
1439                                 {
1440                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1441                                         flash.alpha = self.beam_alpha;
1442                                         flash.colormod = self.beam_color;
1443                                         flash.scale = 0.5;
1444                                 }
1445                                 break;
1446                         }
1447                         case ARC_BT_HIT:
1448                         {
1449                                 self.beam_color = '1 1 1';
1450                                 self.beam_alpha = 0.5;
1451                                 self.beam_thickness = 8;
1452                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1453                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1454                                 self.beam_hitlight[0] = 20;
1455                                 self.beam_hitlight[1] = 1;
1456                                 self.beam_hitlight[2] = 0;
1457                                 self.beam_hitlight[3] = 0;
1458                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1459                                 self.beam_muzzlelight[0] = 50;
1460                                 self.beam_muzzlelight[1] = 1;
1461                                 self.beam_muzzlelight[2] = 0;
1462                                 self.beam_muzzlelight[3] = 0;
1463                                 self.beam_image = "particles/lgbeam";
1464                                 if(self.beam_muzzleeffect)
1465                                 {
1466                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1467                                         flash.alpha = self.beam_alpha;
1468                                         flash.colormod = self.beam_color;
1469                                         flash.scale = 0.5;
1470                                 }
1471                                 break;
1472                         }
1473                         case ARC_BT_BURST_MISS:
1474                         {
1475                                 self.beam_color = '1 1 1';
1476                                 self.beam_alpha = 0.5;
1477                                 self.beam_thickness = 14;
1478                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1479                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1480                                 self.beam_hitlight[0] = 0;
1481                                 self.beam_hitlight[1] = 1;
1482                                 self.beam_hitlight[2] = 1;
1483                                 self.beam_hitlight[3] = 1;
1484                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1485                                 self.beam_muzzlelight[0] = 0;
1486                                 self.beam_muzzlelight[1] = 1;
1487                                 self.beam_muzzlelight[2] = 1;
1488                                 self.beam_muzzlelight[3] = 1;
1489                                 self.beam_image = "particles/lgbeam";
1490                                 if(self.beam_muzzleeffect)
1491                                 {
1492                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1493                                         flash.alpha = self.beam_alpha;
1494                                         flash.colormod = self.beam_color;
1495                                         flash.scale = 0.5;
1496                                 }
1497                                 break;
1498                         }
1499                         case ARC_BT_BURST_WALL:
1500                         {
1501                                 self.beam_color = '1 1 1';
1502                                 self.beam_alpha = 0.5;
1503                                 self.beam_thickness = 14;
1504                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1505                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1506                                 self.beam_hitlight[0] = 0;
1507                                 self.beam_hitlight[1] = 1;
1508                                 self.beam_hitlight[2] = 1;
1509                                 self.beam_hitlight[3] = 1;
1510                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1511                                 self.beam_muzzlelight[0] = 0;
1512                                 self.beam_muzzlelight[1] = 1;
1513                                 self.beam_muzzlelight[2] = 1;
1514                                 self.beam_muzzlelight[3] = 1;
1515                                 self.beam_image = "particles/lgbeam";
1516                                 if(self.beam_muzzleeffect)
1517                                 {
1518                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1519                                         flash.alpha = self.beam_alpha;
1520                                         flash.colormod = self.beam_color;
1521                                         flash.scale = 0.5;
1522                                 }
1523                                 break;
1524                         }
1525                         case ARC_BT_BURST_HEAL:
1526                         {
1527                                 self.beam_color = '1 1 1';
1528                                 self.beam_alpha = 0.5;
1529                                 self.beam_thickness = 14;
1530                                 self.beam_traileffect = (EFFECT_ARC_BEAM_HEAL);
1531                                 self.beam_hiteffect = (EFFECT_ARC_BEAM_HEAL_IMPACT2);
1532                                 self.beam_hitlight[0] = 0;
1533                                 self.beam_hitlight[1] = 1;
1534                                 self.beam_hitlight[2] = 1;
1535                                 self.beam_hitlight[3] = 1;
1536                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1537                                 self.beam_muzzlelight[0] = 0;
1538                                 self.beam_muzzlelight[1] = 1;
1539                                 self.beam_muzzlelight[2] = 1;
1540                                 self.beam_muzzlelight[3] = 1;
1541                                 self.beam_image = "particles/lgbeam";
1542                                 if(self.beam_muzzleeffect)
1543                                 {
1544                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1545                                         flash.alpha = self.beam_alpha;
1546                                         flash.colormod = self.beam_color;
1547                                         flash.scale = 0.5;
1548                                 }
1549                                 break;
1550                         }
1551                         case ARC_BT_BURST_HIT:
1552                         {
1553                                 self.beam_color = '1 1 1';
1554                                 self.beam_alpha = 0.5;
1555                                 self.beam_thickness = 14;
1556                                 self.beam_traileffect = (EFFECT_ARC_BEAM);
1557                                 self.beam_hiteffect = (EFFECT_ARC_LIGHTNING);
1558                                 self.beam_hitlight[0] = 0;
1559                                 self.beam_hitlight[1] = 1;
1560                                 self.beam_hitlight[2] = 1;
1561                                 self.beam_hitlight[3] = 1;
1562                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1563                                 self.beam_muzzlelight[0] = 0;
1564                                 self.beam_muzzlelight[1] = 1;
1565                                 self.beam_muzzlelight[2] = 1;
1566                                 self.beam_muzzlelight[3] = 1;
1567                                 self.beam_image = "particles/lgbeam";
1568                                 if(self.beam_muzzleeffect)
1569                                 {
1570                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1571                                         flash.alpha = self.beam_alpha;
1572                                         flash.colormod = self.beam_color;
1573                                         flash.scale = 0.5;
1574                                 }
1575                                 break;
1576                         }
1577
1578                         // shouldn't be possible, but lets make it colorful if it does :D
1579                         default:
1580                         {
1581                                 self.beam_color = randomvec();
1582                                 self.beam_alpha = 1;
1583                                 self.beam_thickness = 8;
1584                                 self.beam_traileffect = NULL;
1585                                 self.beam_hiteffect = NULL;
1586                                 self.beam_hitlight[0] = 0;
1587                                 self.beam_hitlight[1] = 1;
1588                                 self.beam_hitlight[2] = 1;
1589                                 self.beam_hitlight[3] = 1;
1590                                 self.beam_muzzleeffect = NULL; //(EFFECT_VORTEX_MUZZLEFLASH);
1591                                 self.beam_muzzlelight[0] = 0;
1592                                 self.beam_muzzlelight[1] = 1;
1593                                 self.beam_muzzlelight[2] = 1;
1594                                 self.beam_muzzlelight[3] = 1;
1595                                 self.beam_image = "particles/lgbeam";
1596                                 if(self.beam_muzzleeffect)
1597                                 {
1598                                         setmodel(flash, MDL_ARC_MUZZLEFLASH);
1599                                         flash.alpha = self.beam_alpha;
1600                                         flash.colormod = self.beam_color;
1601                                         flash.scale = 0.5;
1602                                 }
1603                                 break;
1604                         }
1605                 }
1606         }
1607
1608         if(!self.beam_usevieworigin)
1609         {
1610                 InterpolateOrigin_Note(this);
1611         }
1612         return true;
1613 }
1614
1615 #endif
1616 #endif