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