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