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