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