5 /* ammotype */ ammo_cells,
7 /* flags */ WEP_FLAG_NORMAL,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
10 /* modelname */ "hlac",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhlac 0.7",
13 /* wepimg */ "weaponhlac",
15 /* wepname */ _("Arc")
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_maxangle) \
32 w_cvar(id, sn, NONE, beam_nonplayerdamage) \
33 w_cvar(id, sn, NONE, beam_range) \
34 w_cvar(id, sn, NONE, beam_refire) \
35 w_cvar(id, sn, NONE, beam_returnspeed) \
36 w_cvar(id, sn, NONE, beam_tightness) \
37 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
38 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
39 w_prop(id, sn, string, weaponreplace, weaponreplace) \
40 w_prop(id, sn, float, weaponstart, weaponstart) \
41 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
42 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
45 vector arc_shotorigin[4];
54 #define ARC_BT_BURST_MISS 10
55 #define ARC_BT_BURST_WALL 11
56 #define ARC_BT_BURST_HEAL 12
57 #define ARC_BT_BURST_HIT 13
58 #define ARC_BT_BURSTMASK 10
61 #define ARC_MAX_SEGMENTS 20
62 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
64 .entity arc_beam; // used for beam
65 .float BUTTON_ATCK_prev; // for better animation control
66 .float lg_fire_prev; // for better animation control
67 .float beam_initialized;
71 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
73 float W_Arc_Beam_Send(entity to, float sf)
75 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
77 // Truncate information when this beam is displayed to the owner client
78 // - The owner client has no use for beam start position or directions,
79 // it always figures this information out for itself with csqc code.
80 // - Spectating the owner also truncates this information.
81 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
93 WriteByte(MSG_ENTITY, sf);
95 if(sf & 1) // settings information
97 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
98 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
99 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
100 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
102 WriteByte(MSG_ENTITY, drawlocal);
104 if(sf & 2) // starting location
106 WriteCoord(MSG_ENTITY, self.beam_start_x);
107 WriteCoord(MSG_ENTITY, self.beam_start_y);
108 WriteCoord(MSG_ENTITY, self.beam_start_z);
110 if(sf & 4) // want/aim direction
112 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
113 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
114 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
116 if(sf & 8) // beam direction
118 WriteCoord(MSG_ENTITY, self.beam_dir_x);
119 WriteCoord(MSG_ENTITY, self.beam_dir_y);
120 WriteCoord(MSG_ENTITY, self.beam_dir_z);
122 if(sf & 16) // beam type
124 WriteByte(MSG_ENTITY, self.beam_type);
130 void W_Arc_Beam_Think(void)
133 if(self != self.owner.arc_beam)
138 if((self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
140 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
145 if(self.owner.BUTTON_ATCK2)
147 burst = ARC_BT_BURSTMASK;
150 // decrease ammo // todo: support burst ammo
151 float dt = frametime;
152 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
154 if(WEP_CVAR(arc, beam_ammo))
156 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR(arc, beam_ammo));
157 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR(arc, beam_ammo) * frametime);
161 makevectors(self.owner.v_angle);
163 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR(arc, beam_damage) * dt, WEP_CVAR(arc, beam_range));
165 // network information: shot origin and want/aim direction
166 if(self.beam_start != w_shotorg)
169 self.beam_start = w_shotorg;
171 if(self.beam_wantdir != w_shotdir)
174 self.beam_wantdir = w_shotdir;
177 if(!self.beam_initialized)
180 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
181 self.lg_ents[i] = spawn();
184 self.beam_dir = w_shotdir;
185 self.beam_initialized = TRUE;
189 if(self.beam_dir != w_shotdir)
191 float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG);
193 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
195 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
196 anglelimit = min(WEP_CVAR(arc, beam_maxangle) / angle, 1);
200 // the radius is not too far yet, no worries :D
204 // calculate how much we're going to move the end of the beam to the want position
205 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR(arc, beam_returnspeed) * dt)), 1);
206 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
208 // todo: figure out a way so that blendfactor becomes 0 at some point,
209 // currently self.beam_dir and w_shotdir never really become equal as there is no rounding/snapping point
210 // printf("blendfactor = %f\n", blendfactor);
212 // network information: beam direction
215 // calculate how many segments are needed
216 float max_allowed_segments;
218 if(WEP_CVAR(arc, beam_distancepersegment))
219 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
221 max_allowed_segments = ARC_MAX_SEGMENTS;
223 if(WEP_CVAR(arc, beam_degreespersegment))
225 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
227 else { segments = 1; }
234 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
236 float new_beam_type = 0;
237 vector last_origin = w_shotorg;
238 for(i = 1; i <= segments; ++i)
240 // WEAPONTODO (server and client):
241 // Segment blend and distance should probably really be calculated in a better way,
242 // however I am not sure how to do it properly. There are a few things I have tried,
243 // but most of them do not work properly due to my lack of understanding regarding
244 // the mathematics behind them.
246 // Ideally, we should calculate the positions along a perfect curve
247 // between wantdir and self.beam_dir with an option for depth of arc
249 // Another issue is that (on the client code) we must separate the
250 // curve into multiple rendered curves when handling warpzones.
252 // I can handle this by detecting it for each segment, however that
253 // is a fairly inefficient method in comparison to having a curved line
254 // drawing function similar to Draw_CylindricLine that accepts
255 // top and bottom origins as input, this way there would be no
256 // overlapping edges when connecting the curved pieces.
258 // WEAPONTODO (client):
259 // In order to do nice fading and pointing on the starting segment, we must always
260 // have that drawn as a separate triangle... However, that is difficult to do when
261 // keeping in mind the above problems and also optimizing the amount of segments
262 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
264 // calculate this on every segment to ensure that we always reach the full length of the attack
265 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
266 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
268 vector new_dir = normalize( (w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
269 vector new_origin = last_origin + (new_dir * segmentdist);
271 WarpZone_traceline_antilag(
277 ANTILAG_LATENCY(self.owner)
280 float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
281 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
283 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
284 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
286 float falloff = ExponentialFalloff(
287 WEP_CVAR(arc, beam_falloff_mindist),
288 WEP_CVAR(arc, beam_falloff_maxdist),
289 WEP_CVAR(arc, beam_falloff_halflifedist),
290 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
293 if(is_player && SAME_TEAM(self.owner, trace_ent))
295 // hit a team mate heal them now
296 new_beam_type = ARC_BT_HEAL;
302 rootdamage = WEP_CVAR(arc, beam_damage);
304 rootdamage = WEP_CVAR(arc, beam_nonplayerdamage);
306 if(accuracy_isgooddamage(self.owner, trace_ent))
312 rootdamage * dt * falloff
320 rootdamage * dt * falloff,
323 WEP_CVAR(arc, beam_force) * new_dir * dt * falloff
326 new_beam_type = ARC_BT_HIT;
330 else if(trace_fraction != 1)
332 // we collided with geometry
333 new_beam_type = ARC_BT_WALL;
338 last_origin = new_origin;
342 // if we're bursting, use burst visual effects
343 new_beam_type += burst;
345 // network information: beam type
346 if(new_beam_type != self.beam_type)
348 self.SendFlags |= 16;
349 self.beam_type = new_beam_type;
352 self.owner.lg_fire_prev = time;
353 self.nextthink = time;
356 // Attack functions =========================
357 void W_Arc_Beam(void)
359 print("W_Arc_Beam();\n");
360 // only play fire sound if 1 sec has passed since player let go the fire button
361 if(time - self.lg_fire_prev > 1)
362 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
364 entity beam, oldself;
366 self.arc_beam = beam = spawn();
367 beam.classname = "W_Arc_Beam";
368 beam.solid = SOLID_NOT;
369 beam.think = W_Arc_Beam_Think;
371 beam.movetype = MOVETYPE_NONE;
372 beam.shot_spread = 1;
373 beam.bot_dodge = TRUE;
374 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
375 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
383 float W_Arc(float req)
389 if(WEP_CVAR(arc, beam_botaimspeed))
390 self.BUTTON_ATCK = bot_aim(WEP_CVAR(arc, beam_botaimspeed), 0, WEP_CVAR(arc, beam_botaimlifetime), FALSE);
392 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
399 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
400 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
401 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
403 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
405 if(weapon_prepareattack(0, 0))
407 if((!self.arc_beam) || wasfreed(self.arc_beam))
410 if(!self.BUTTON_ATCK_prev)
412 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
413 self.BUTTON_ATCK_prev = 1;
419 if(self.BUTTON_ATCK_prev != 0)
421 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
422 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
424 self.BUTTON_ATCK_prev = 0;
427 //if(self.BUTTON_ATCK2)
428 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
431 // self.arc_count = autocvar_g_balance_arc_secondary_count;
432 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
433 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
440 precache_model("models/weapons/g_arc.md3");
441 precache_model("models/weapons/v_arc.md3");
442 precache_model("models/weapons/h_arc.iqm");
443 //precache_sound("weapons/arc_bounce.wav");
444 precache_sound("weapons/arc_fire.wav");
445 precache_sound("weapons/arc_fire2.wav");
446 precache_sound("weapons/arc_impact.wav");
447 //precache_sound("weapons/arc_impact_combo.wav");
448 //precache_sound("weapons/W_Arc_Beam_fire.wav");
453 return !WEP_CVAR(arc, beam_ammo) || (self.WEP_AMMO(ARC) > 0);
457 //return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
462 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
467 if(w_deathtype & HITTYPE_SECONDARY)
469 return WEAPON_ELECTRO_MURDER_ORBS;
473 if(w_deathtype & HITTYPE_BOUNCE)
474 return WEAPON_ELECTRO_MURDER_COMBO;
476 return WEAPON_ELECTRO_MURDER_BOLT;
481 //self.arc_secondarytime = time;
490 WEP_ACTION(WEP_ARC, WR_INIT);
491 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
492 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
493 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
494 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
495 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
499 float W_Arc(float req)
503 case WR_IMPACTEFFECT:
506 org2 = w_org + w_backoff * 6;
508 if(w_deathtype & HITTYPE_SECONDARY)
510 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
512 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
516 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
518 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
525 precache_sound("weapons/arc_impact.wav");
526 precache_sound("weapons/arc_impact_combo.wav");
531 // no weapon specific image for this weapon