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 // WEAPONTODO (server and client):
209 // blendfactor never actually becomes 0 in this situation, which is a problem
210 // regarding precision... this means that self.beam_dir and w_shotdir approach
211 // eachother, however they never actually become the same value with this method.
213 // Perhaps we should do some form of rounding/snapping?
215 // printf("blendfactor = %f\n", blendfactor);
217 // network information: beam direction
220 // calculate how many segments are needed
221 float max_allowed_segments;
223 if(WEP_CVAR(arc, beam_distancepersegment))
224 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
226 max_allowed_segments = ARC_MAX_SEGMENTS;
228 if(WEP_CVAR(arc, beam_degreespersegment))
230 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
242 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
244 float new_beam_type = 0;
245 vector last_origin = w_shotorg;
246 for(i = 1; i <= segments; ++i)
248 // WEAPONTODO (server and client):
249 // Segment blend and distance should probably really be calculated in a better way,
250 // however I am not sure how to do it properly. There are a few things I have tried,
251 // but most of them do not work properly due to my lack of understanding regarding
252 // the mathematics behind them.
254 // Ideally, we should calculate the positions along a perfect curve
255 // between wantdir and self.beam_dir with an option for depth of arc
257 // Another issue is that (on the client code) we must separate the
258 // curve into multiple rendered curves when handling warpzones.
260 // I can handle this by detecting it for each segment, however that
261 // is a fairly inefficient method in comparison to having a curved line
262 // drawing function similar to Draw_CylindricLine that accepts
263 // top and bottom origins as input, this way there would be no
264 // overlapping edges when connecting the curved pieces.
266 // WEAPONTODO (client):
267 // In order to do nice fading and pointing on the starting segment, we must always
268 // have that drawn as a separate triangle... However, that is difficult to do when
269 // keeping in mind the above problems and also optimizing the amount of segments
270 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
272 // calculate this on every segment to ensure that we always reach the full length of the attack
273 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
274 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
276 vector new_dir = normalize( (w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
277 vector new_origin = last_origin + (new_dir * segmentdist);
279 WarpZone_traceline_antilag(
285 ANTILAG_LATENCY(self.owner)
288 float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
289 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
291 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
292 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
294 float falloff = ExponentialFalloff(
295 WEP_CVAR(arc, beam_falloff_mindist),
296 WEP_CVAR(arc, beam_falloff_maxdist),
297 WEP_CVAR(arc, beam_falloff_halflifedist),
298 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
301 if(is_player && SAME_TEAM(self.owner, trace_ent))
303 // hit a team mate heal them now
304 new_beam_type = ARC_BT_HEAL;
310 rootdamage = WEP_CVAR(arc, beam_damage);
312 rootdamage = WEP_CVAR(arc, beam_nonplayerdamage);
314 if(accuracy_isgooddamage(self.owner, trace_ent))
320 rootdamage * dt * falloff
328 rootdamage * dt * falloff,
331 WEP_CVAR(arc, beam_force) * new_dir * dt * falloff
334 new_beam_type = ARC_BT_HIT;
338 else if(trace_fraction != 1)
340 // we collided with geometry
341 new_beam_type = ARC_BT_WALL;
346 last_origin = new_origin;
350 // if we're bursting, use burst visual effects
351 new_beam_type += burst;
353 // network information: beam type
354 if(new_beam_type != self.beam_type)
356 self.SendFlags |= 16;
357 self.beam_type = new_beam_type;
360 self.owner.lg_fire_prev = time;
361 self.nextthink = time;
364 // Attack functions =========================
365 void W_Arc_Beam(void)
367 print("W_Arc_Beam();\n");
368 // only play fire sound if 1 sec has passed since player let go the fire button
369 if(time - self.lg_fire_prev > 1)
370 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
372 entity beam, oldself;
374 self.arc_beam = beam = spawn();
375 beam.classname = "W_Arc_Beam";
376 beam.solid = SOLID_NOT;
377 beam.think = W_Arc_Beam_Think;
379 beam.movetype = MOVETYPE_NONE;
380 beam.shot_spread = 1;
381 beam.bot_dodge = TRUE;
382 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
383 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
391 float W_Arc(float req)
397 if(WEP_CVAR(arc, beam_botaimspeed))
398 self.BUTTON_ATCK = bot_aim(WEP_CVAR(arc, beam_botaimspeed), 0, WEP_CVAR(arc, beam_botaimlifetime), FALSE);
400 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
407 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
408 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
409 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
411 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
413 if(weapon_prepareattack(0, 0))
415 if((!self.arc_beam) || wasfreed(self.arc_beam))
418 if(!self.BUTTON_ATCK_prev)
420 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
421 self.BUTTON_ATCK_prev = 1;
427 if(self.BUTTON_ATCK_prev != 0)
429 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
430 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
432 self.BUTTON_ATCK_prev = 0;
435 //if(self.BUTTON_ATCK2)
436 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
439 // self.arc_count = autocvar_g_balance_arc_secondary_count;
440 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
441 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
448 precache_model("models/weapons/g_arc.md3");
449 precache_model("models/weapons/v_arc.md3");
450 precache_model("models/weapons/h_arc.iqm");
451 //precache_sound("weapons/arc_bounce.wav");
452 precache_sound("weapons/arc_fire.wav");
453 precache_sound("weapons/arc_fire2.wav");
454 precache_sound("weapons/arc_impact.wav");
455 //precache_sound("weapons/arc_impact_combo.wav");
456 //precache_sound("weapons/W_Arc_Beam_fire.wav");
461 return !WEP_CVAR(arc, beam_ammo) || (self.WEP_AMMO(ARC) > 0);
465 //return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
470 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
475 if(w_deathtype & HITTYPE_SECONDARY)
477 return WEAPON_ELECTRO_MURDER_ORBS;
481 if(w_deathtype & HITTYPE_BOUNCE)
482 return WEAPON_ELECTRO_MURDER_COMBO;
484 return WEAPON_ELECTRO_MURDER_BOLT;
489 //self.arc_secondarytime = time;
498 WEP_ACTION(WEP_ARC, WR_INIT);
499 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
500 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
501 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
502 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
503 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
507 float W_Arc(float req)
511 case WR_IMPACTEFFECT:
514 org2 = w_org + w_backoff * 6;
516 if(w_deathtype & HITTYPE_SECONDARY)
518 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
520 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
524 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
526 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
533 precache_sound("weapons/arc_impact.wav");
534 precache_sound("weapons/arc_impact_combo.wav");
539 // no weapon specific image for this weapon