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) { 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)
112 float i, burst = TRUE;
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 // network information: shot origin and want/aim direction
162 if(self.beam_start != w_shotorg)
165 self.beam_start = w_shotorg;
167 if(self.beam_wantdir != w_shotdir)
170 self.beam_wantdir = w_shotdir;
173 if(!self.beam_initialized)
176 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
177 self.lg_ents[i] = spawn();
180 self.beam_dir = w_shotdir;
181 self.beam_initialized = TRUE;
185 if(self.beam_dir != w_shotdir)
187 float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG);
189 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
191 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
192 anglelimit = min(WEP_CVAR(arc, beam_maxangle) / angle, 1);
196 // the radius is not too far yet, no worries :D
200 // calculate how much we're going to move the end of the beam to the want position
201 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR(arc, beam_returnspeed) * dt)), 1);
202 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
204 // todo: figure out a way so that blendfactor becomes 0 at some point,
205 // currently self.beam_dir and w_shotdir never really become equal as there is no rounding/snapping point
206 // printf("blendfactor = %f\n", blendfactor);
208 // network information: beam direction
211 // calculate how many segments are needed
212 float max_allowed_segments;
214 if(WEP_CVAR(arc, beam_distancepersegment))
215 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
217 max_allowed_segments = ARC_MAX_SEGMENTS;
219 if(WEP_CVAR(arc, beam_degreespersegment))
221 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
223 else { segments = 1; }
230 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
233 //printf("segment count: %d\n", segments);
234 //string segmentinfo = "";
240 float new_beam_type = 0;
241 vector last_origin = w_shotorg;
242 for(i = 1; i <= segments; ++i)
244 // calculate this on every segment to ensure that we always reach the full length of the attack
245 float segmentblend = (i/segments);
246 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
248 vector new_dir = normalize( (w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
249 vector new_origin = last_origin + (new_dir * segmentdist);
251 WarpZone_traceline_antilag(
257 ANTILAG_LATENCY(self.owner)
261 //APPEND_TO_STRING(segmentinfo, "^4, ", sprintf("^3org%s-dis'%f'", vtos(new_origin), segmentdist));
264 float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
265 if(trace_ent && (trace_ent.takedamage == DAMAGE_AIM) && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
267 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
268 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
271 totaldist += segmentdist * trace_fraction;
275 float falloff = ExponentialFalloff(
276 WEP_CVAR(arc, beam_falloff_mindist),
277 WEP_CVAR(arc, beam_falloff_maxdist),
278 WEP_CVAR(arc, beam_falloff_halflifedist),
279 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
282 if(is_player && SAME_TEAM(self.owner, trace_ent))
284 // hit a team mate heal them now
286 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
287 te_customflash(hitorigin, 80, 5, '0 1 0');
290 "W_Arc_Beam_Think(): HIT TEAM MATE: "
291 "Hitorg: %s, Segments: %d, Distance: %f\n",
298 new_beam_type = ARC_BT_HEAL;
304 rootdamage = WEP_CVAR(arc, beam_damage);
306 rootdamage = WEP_CVAR(arc, beam_nonplayerdamage);
308 if(accuracy_isgooddamage(self.owner, trace_ent))
314 rootdamage * dt * falloff
322 rootdamage * dt * falloff,
325 WEP_CVAR(arc, beam_force) * new_dir * dt * falloff
329 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
330 te_customflash(hitorigin, 80, 5, '1 0 0');
333 "W_Arc_Beam_Think(): HIT ENTITY: "
334 "Hitorg: %s, Segments: %d, Distance: %f\n",
341 new_beam_type = ARC_BT_HIT;
345 else if(trace_fraction != 1)
347 // we collided with geometry
349 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
350 te_customflash(trace_endpos, 50, 2, '0 0 1');
352 totaldist += segmentdist * trace_fraction;
354 "W_Arc_Beam_Think(): HIT WALL: "
355 "Hitorg: %s, Segments: %d, Distance: %f\n",
362 new_beam_type = ARC_BT_WALL;
369 totaldist += segmentdist;
371 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
373 last_origin = new_origin;
382 "W_Arc_Beam_Think(): MISS: "
383 "Shotorg: %s, Endpos: %s, Segments: %d: %s\n",
390 te_customflash(trace_endpos, 50, 2, '1 1 0');
394 // if we're bursting, use burst visual effects
395 new_beam_type += burst;
397 // network information: beam type
398 if(new_beam_type != self.beam_type)
401 self.beam_type = new_beam_type;
404 self.owner.lg_fire_prev = time;
405 self.nextthink = time;
408 // Attack functions =========================
409 void W_Arc_Beam(void)
411 print("W_Arc_Beam();\n");
412 // only play fire sound if 1 sec has passed since player let go the fire button
413 if(time - self.lg_fire_prev > 1)
414 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
416 entity beam, oldself;
418 self.arc_beam = beam = spawn();
419 beam.classname = "W_Arc_Beam";
420 beam.solid = SOLID_NOT;
421 beam.think = W_Arc_Beam_Think;
423 beam.movetype = MOVETYPE_NONE;
424 beam.shot_spread = 1;
425 beam.bot_dodge = TRUE;
426 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
427 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
435 float W_Arc(float req)
441 if(WEP_CVAR(arc, beam_botaimspeed))
442 self.BUTTON_ATCK = bot_aim(WEP_CVAR(arc, beam_botaimspeed), 0, WEP_CVAR(arc, beam_botaimlifetime), FALSE);
444 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
451 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
452 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
453 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
455 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
457 if(weapon_prepareattack(0, 0))
459 if((!self.arc_beam) || wasfreed(self.arc_beam))
462 if(!self.BUTTON_ATCK_prev)
464 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
465 self.BUTTON_ATCK_prev = 1;
471 if(self.BUTTON_ATCK_prev != 0)
473 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
474 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
476 self.BUTTON_ATCK_prev = 0;
479 //if(self.BUTTON_ATCK2)
480 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
483 // self.arc_count = autocvar_g_balance_arc_secondary_count;
484 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
485 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
492 precache_model("models/weapons/g_arc.md3");
493 precache_model("models/weapons/v_arc.md3");
494 precache_model("models/weapons/h_arc.iqm");
495 //precache_sound("weapons/arc_bounce.wav");
496 precache_sound("weapons/arc_fire.wav");
497 precache_sound("weapons/arc_fire2.wav");
498 precache_sound("weapons/arc_impact.wav");
499 //precache_sound("weapons/arc_impact_combo.wav");
500 //precache_sound("weapons/W_Arc_Beam_fire.wav");
505 return !WEP_CVAR(arc, beam_ammo) || (self.WEP_AMMO(ARC) > 0);
509 //return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
514 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
519 if(w_deathtype & HITTYPE_SECONDARY)
521 return WEAPON_ELECTRO_MURDER_ORBS;
525 if(w_deathtype & HITTYPE_BOUNCE)
526 return WEAPON_ELECTRO_MURDER_COMBO;
528 return WEAPON_ELECTRO_MURDER_BOLT;
533 //self.arc_secondarytime = time;
542 WEP_ACTION(WEP_ARC, WR_INIT);
543 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
544 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
545 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
546 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
547 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
551 float W_Arc(float req)
555 case WR_IMPACTEFFECT:
558 org2 = w_org + w_backoff * 6;
560 if(w_deathtype & HITTYPE_SECONDARY)
562 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
564 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
568 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
570 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
577 precache_sound("weapons/arc_impact.wav");
578 precache_sound("weapons/arc_impact_combo.wav");
583 // no weapon specific image for this weapon