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_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
37 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
38 w_prop(id, sn, string, weaponreplace, weaponreplace) \
39 w_prop(id, sn, float, weaponstart, weaponstart) \
40 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
41 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
44 vector arc_shotorigin[4];
53 #define ARC_BT_BURST_MISS 10
54 #define ARC_BT_BURST_WALL 11
55 #define ARC_BT_BURST_HEAL 12
56 #define ARC_BT_BURST_HIT 13
57 #define ARC_BT_BURSTMASK 10
60 #define ARC_MAX_SEGMENTS 20
61 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
63 .entity arc_beam; // used for beam
64 .float BUTTON_ATCK_prev; // for better animation control
65 .float lg_fire_prev; // for better animation control
67 .entity lg_ents[ARC_MAX_SEGMENTS]; // debug
69 .float beam_initialized;
73 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
75 float W_Arc_Beam_Send(entity to, float sf)
77 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
79 // don't send group 1, 2, or 3 if this beam is for the local player
80 if((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to))) { sf &= ~7; }
81 WriteByte(MSG_ENTITY, sf);
83 if(sf & 1) // starting location // not sent if beam is for owner
85 //WriteByte(MSG_ENTITY, num_for_edict(self.owner));
86 WriteCoord(MSG_ENTITY, self.beam_start_x);
87 WriteCoord(MSG_ENTITY, self.beam_start_y);
88 WriteCoord(MSG_ENTITY, self.beam_start_z);
89 //WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
91 if(sf & 2) // want/aim direction
93 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
94 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
95 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
97 if(sf & 4) // beam direction
99 WriteCoord(MSG_ENTITY, self.beam_dir_x);
100 WriteCoord(MSG_ENTITY, self.beam_dir_y);
101 WriteCoord(MSG_ENTITY, self.beam_dir_z);
103 if(sf & 8) // beam type
105 WriteByte(MSG_ENTITY, self.beam_type);
110 void W_Arc_Beam_Think(void)
113 if(self != self.owner.arc_beam)
118 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
119 remove(self.lg_ents[i]);
121 print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n");
126 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)
128 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
132 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
133 remove(self.lg_ents[i]);
135 print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n");
141 if(self.owner.BUTTON_ATCK2)
143 burst = ARC_BT_BURSTMASK;
146 // decrease ammo // todo: support burst ammo
147 float dt = frametime;
148 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
150 if(WEP_CVAR(arc, beam_ammo))
152 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR(arc, beam_ammo));
153 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR(arc, beam_ammo) * frametime);
157 makevectors(self.owner.v_angle);
159 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR(arc, beam_damage) * dt, WEP_CVAR(arc, beam_range));
161 //printf("SERVER direction: %s\n", vtos(w_shotdir));
163 // network information: shot origin and want/aim direction
164 if(self.beam_start != w_shotorg)
167 self.beam_start = w_shotorg;
169 if(self.beam_wantdir != w_shotdir)
172 self.beam_wantdir = w_shotdir;
175 if(!self.beam_initialized)
178 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
179 self.lg_ents[i] = spawn();
182 self.beam_dir = w_shotdir;
183 self.beam_initialized = TRUE;
187 if(self.beam_dir != w_shotdir)
189 float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG);
191 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
193 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
194 anglelimit = min(WEP_CVAR(arc, beam_maxangle) / angle, 1);
198 // the radius is not too far yet, no worries :D
202 // calculate how much we're going to move the end of the beam to the want position
203 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR(arc, beam_returnspeed) * dt)), 1);
204 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
206 // todo: figure out a way so that blendfactor becomes 0 at some point,
207 // currently self.beam_dir and w_shotdir never really become equal as there is no rounding/snapping point
208 // printf("blendfactor = %f\n", blendfactor);
210 // network information: beam direction
213 // calculate how many segments are needed
214 float max_allowed_segments;
216 if(WEP_CVAR(arc, beam_distancepersegment))
217 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
219 max_allowed_segments = ARC_MAX_SEGMENTS;
221 if(WEP_CVAR(arc, beam_degreespersegment))
223 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
225 else { segments = 1; }
232 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
235 //printf("segment count: %d\n", segments);
236 //string segmentinfo = "";
242 float new_beam_type = 0;
243 vector last_origin = w_shotorg;
244 for(i = 1; i <= segments; ++i)
246 // calculate this on every segment to ensure that we always reach the full length of the attack
247 float segmentblend = (i/segments);
248 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
250 vector new_dir = normalize( (w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
251 vector new_origin = last_origin + (new_dir * segmentdist);
253 WarpZone_traceline_antilag(
259 ANTILAG_LATENCY(self.owner)
263 //APPEND_TO_STRING(segmentinfo, "^4, ", sprintf("^3org%s-dis'%f'", vtos(new_origin), segmentdist));
266 float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
267 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
269 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
270 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
273 totaldist += segmentdist * trace_fraction;
277 float falloff = ExponentialFalloff(
278 WEP_CVAR(arc, beam_falloff_mindist),
279 WEP_CVAR(arc, beam_falloff_maxdist),
280 WEP_CVAR(arc, beam_falloff_halflifedist),
281 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
284 if(is_player && SAME_TEAM(self.owner, trace_ent))
286 // hit a team mate heal them now
288 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
289 te_customflash(hitorigin, 80, 5, '0 1 0');
292 "W_Arc_Beam_Think(): HIT TEAM MATE: "
293 "Hitorg: %s, Segments: %d, Distance: %f\n",
300 new_beam_type = ARC_BT_HEAL;
306 rootdamage = WEP_CVAR(arc, beam_damage);
308 rootdamage = WEP_CVAR(arc, beam_nonplayerdamage);
310 if(accuracy_isgooddamage(self.owner, trace_ent))
316 rootdamage * dt * falloff
324 rootdamage * dt * falloff,
327 WEP_CVAR(arc, beam_force) * new_dir * dt * falloff
331 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
332 te_customflash(hitorigin, 80, 5, '1 0 0');
335 "W_Arc_Beam_Think(): HIT ENTITY: "
336 "Hitorg: %s, Segments: %d, Distance: %f\n",
343 new_beam_type = ARC_BT_HIT;
347 else if(trace_fraction != 1)
349 // we collided with geometry
351 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
352 te_customflash(trace_endpos, 50, 2, '0 0 1');
354 totaldist += segmentdist * trace_fraction;
356 "W_Arc_Beam_Think(): HIT WALL: "
357 "Hitorg: %s, Segments: %d, Distance: %f\n",
364 new_beam_type = ARC_BT_WALL;
371 totaldist += segmentdist;
373 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
375 last_origin = new_origin;
384 "W_Arc_Beam_Think(): MISS: "
385 "Shotorg: %s, Endpos: %s, Segments: %d: %s\n",
392 te_customflash(trace_endpos, 50, 2, '1 1 0');
396 // if we're bursting, use burst visual effects
397 new_beam_type += burst;
399 // network information: beam type
400 if(new_beam_type != self.beam_type)
403 self.beam_type = new_beam_type;
406 self.owner.lg_fire_prev = time;
407 self.nextthink = time;
410 // Attack functions =========================
411 void W_Arc_Beam(void)
413 print("W_Arc_Beam();\n");
414 // only play fire sound if 1 sec has passed since player let go the fire button
415 if(time - self.lg_fire_prev > 1)
416 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
418 entity beam, oldself;
420 self.arc_beam = beam = spawn();
421 beam.classname = "W_Arc_Beam";
422 beam.solid = SOLID_NOT;
423 beam.think = W_Arc_Beam_Think;
425 beam.movetype = MOVETYPE_NONE;
426 beam.shot_spread = 1;
427 beam.bot_dodge = TRUE;
428 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
429 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
437 float W_Arc(float req)
443 if(WEP_CVAR(arc, beam_botaimspeed))
444 self.BUTTON_ATCK = bot_aim(WEP_CVAR(arc, beam_botaimspeed), 0, WEP_CVAR(arc, beam_botaimlifetime), FALSE);
446 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
453 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
454 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
455 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
457 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
459 if(weapon_prepareattack(0, 0))
461 if((!self.arc_beam) || wasfreed(self.arc_beam))
464 if(!self.BUTTON_ATCK_prev)
466 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
467 self.BUTTON_ATCK_prev = 1;
473 if(self.BUTTON_ATCK_prev != 0)
475 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
476 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
478 self.BUTTON_ATCK_prev = 0;
481 //if(self.BUTTON_ATCK2)
482 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
485 // self.arc_count = autocvar_g_balance_arc_secondary_count;
486 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
487 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
494 precache_model("models/weapons/g_arc.md3");
495 precache_model("models/weapons/v_arc.md3");
496 precache_model("models/weapons/h_arc.iqm");
497 //precache_sound("weapons/arc_bounce.wav");
498 precache_sound("weapons/arc_fire.wav");
499 precache_sound("weapons/arc_fire2.wav");
500 precache_sound("weapons/arc_impact.wav");
501 //precache_sound("weapons/arc_impact_combo.wav");
502 //precache_sound("weapons/W_Arc_Beam_fire.wav");
507 return !WEP_CVAR(arc, beam_ammo) || (self.WEP_AMMO(ARC) > 0);
511 //return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
516 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
521 if(w_deathtype & HITTYPE_SECONDARY)
523 return WEAPON_ELECTRO_MURDER_ORBS;
527 if(w_deathtype & HITTYPE_BOUNCE)
528 return WEAPON_ELECTRO_MURDER_COMBO;
530 return WEAPON_ELECTRO_MURDER_BOLT;
535 //self.arc_secondarytime = time;
544 WEP_ACTION(WEP_ARC, WR_INIT);
545 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
546 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
547 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
548 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
549 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
553 float W_Arc(float req)
557 case WR_IMPACTEFFECT:
560 org2 = w_org + w_backoff * 6;
562 if(w_deathtype & HITTYPE_SECONDARY)
564 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
566 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
570 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
572 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
579 precache_sound("weapons/arc_impact.wav");
580 precache_sound("weapons/arc_impact_combo.wav");
585 // no weapon specific image for this weapon