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