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