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