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, BOTH, ammo) \
21 w_cvar(id, sn, PRI, animtime) \
22 w_cvar(id, sn, PRI, botaimspeed) \
23 w_cvar(id, sn, PRI, botaimlifetime) \
24 w_cvar(id, sn, PRI, damage) \
25 w_cvar(id, sn, PRI, degreespersegment) \
26 w_cvar(id, sn, PRI, distancepersegment) \
27 w_cvar(id, sn, PRI, falloff_halflifedist) \
28 w_cvar(id, sn, PRI, falloff_maxdist) \
29 w_cvar(id, sn, PRI, falloff_mindist) \
30 w_cvar(id, sn, PRI, force) \
31 w_cvar(id, sn, PRI, maxangle) \
32 w_cvar(id, sn, PRI, range) \
33 w_cvar(id, sn, PRI, refire) \
34 w_cvar(id, sn, PRI, returnspeed) \
35 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
36 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
37 w_prop(id, sn, string, weaponreplace, weaponreplace) \
38 w_prop(id, sn, float, weaponstart, weaponstart) \
39 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
40 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
43 vector arc_shotorigin[4];
46 #define ARC_BT_ENEMY 3
49 #define ARC_MAX_SEGMENTS 20
50 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
52 .entity arc_beam; // used for beam
53 .float BUTTON_ATCK_prev; // for better animation control
54 .float lg_fire_prev; // for better animation control
57 .entity lg_ents[ARC_MAX_SEGMENTS]; // debug
61 .float beam_initialized;
66 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
68 float W_Arc_Beam_Send(entity to, float sf)
70 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
72 if(sound_allowed(MSG_BROADCAST, self.owner))
74 WriteByte(MSG_ENTITY, sf);
75 if(sf & 1) // main information
77 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
78 WriteCoord(MSG_ENTITY, WEP_CVAR_PRI(arc, range));
80 if(sf & 2) // want/aim direction
82 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
83 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
84 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
86 if(sf & 4) // beam direction
88 WriteCoord(MSG_ENTITY, self.beam_dir_x);
89 WriteCoord(MSG_ENTITY, self.beam_dir_y);
90 WriteCoord(MSG_ENTITY, self.beam_dir_z);
92 if(sf & 8) // beam type
94 WriteByte(MSG_ENTITY, self.beam_type);
98 void W_Arc_Beam_Think(void)
101 if(self != self.owner.arc_beam)
104 print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n");
109 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)
111 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
115 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
116 remove(self.lg_ents[i]);
118 print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n");
125 float dt = frametime;
126 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
128 if(WEP_CVAR_PRI(arc, ammo))
130 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR_PRI(arc, ammo));
131 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR_PRI(arc, ammo) * frametime);
135 makevectors(self.owner.v_angle);
137 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range));
139 // network information: want/aim direction
140 if(self.beam_wantdir != w_shotdir)
143 self.beam_wantdir = w_shotdir;
146 if(!self.beam_initialized)
149 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
150 self.lg_ents[i] = spawn();
153 self.beam_dir = w_shotdir;
154 self.beam_initialized = TRUE;
158 if(self.beam_dir != w_shotdir)
160 float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG);
162 if(angle && (angle > WEP_CVAR_PRI(arc, maxangle)))
164 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
166 printf("Correcting max angle: %f %f\n", angle, WEP_CVAR_PRI(arc, distancepersegment));
168 anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1);
172 // the radius is not too far yet, no worries :D
176 // calculate how much we're going to move the end of the beam to the want position
177 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1);
178 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
180 // network information: beam direction
183 // this is where we calculate how many segments are needed
184 float max_allowed_segments = ARC_MAX_SEGMENTS;
187 if(WEP_CVAR_PRI(arc, distancepersegment))
188 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (distance_to_want_pos / WEP_CVAR_PRI(arc, distancepersegment)));
190 max_allowed_segments = ARC_MAX_SEGMENTS;
193 if(WEP_CVAR_PRI(arc, degreespersegment))
195 segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments );
196 //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments );
198 else { segments = 1; }
205 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR_PRI(arc, range)));
208 printf("segment count: %d\n", segments);
209 //string segmentinfo = "";
212 float new_beam_type = 0;
213 vector last_origin = w_shotorg;
214 for(i = 1; i <= segments; ++i)
216 // this could probably be calculated in a better way
217 float segmentblend = (i/segments);
218 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
220 vector new_dir = normalize((w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend));
221 vector new_origin = last_origin + (new_dir * segmentdist);
223 WarpZone_traceline_antilag(
229 ANTILAG_LATENCY(self.owner)
232 if(trace_ent) // and check if this ent takes damage
234 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
235 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
237 if(SAME_TEAM(self.owner, trace_ent))
239 // hit a team mate heal them now
241 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
242 te_customflash(hitorigin, 80, 5, '1 0 0');
244 new_beam_type = ARC_BT_HEAL;
248 // hit an enemy/other damageable object
249 float falloff = ExponentialFalloff(
250 WEP_CVAR_PRI(arc, falloff_mindist),
251 WEP_CVAR_PRI(arc, falloff_maxdist),
252 WEP_CVAR_PRI(arc, falloff_halflifedist),
253 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
256 if(accuracy_isgooddamage(self.owner, trace_ent))
262 WEP_CVAR_PRI(arc, damage) * dt * falloff
270 WEP_CVAR_PRI(arc, damage) * dt * falloff,
273 WEP_CVAR_PRI(arc, force) * new_dir * dt * falloff
277 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
278 te_customflash(hitorigin, 80, 5, '1 0 0');
280 new_beam_type = ARC_BT_ENEMY;
284 else if(trace_fraction != 1)
286 // we collided with geometry
288 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
289 te_customflash(trace_endpos, 50, 2, '0 0 1');
291 new_beam_type = ARC_BT_WALL;
297 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
299 last_origin = new_origin;
306 te_customflash(trace_endpos, 50, 2, '0 1 0');
310 // network information: beam type
311 if(new_beam_type != self.beam_type)
314 self.beam_type = new_beam_type;
317 self.owner.lg_fire_prev = time;
318 self.nextthink = time;
321 // Attack functions =========================
322 void W_Arc_Beam(void)
324 print("W_Arc_Beam();\n");
325 // only play fire sound if 0.5 sec has passed since player let go the fire button
326 if(time - self.lg_fire_prev > 0.5)
327 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
329 entity beam, oldself;
331 self.arc_beam = beam = spawn();
332 beam.classname = "W_Arc_Beam";
333 beam.solid = SOLID_NOT;
334 beam.think = W_Arc_Beam_Think;
336 beam.movetype = MOVETYPE_NONE;
337 beam.shot_spread = 1;
338 beam.bot_dodge = TRUE;
339 beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
340 //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
348 float W_Arc(float req)
354 if(WEP_CVAR_PRI(arc, botaimspeed))
355 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(arc, botaimspeed), 0, WEP_CVAR_PRI(arc, botaimlifetime), FALSE);
357 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
364 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
365 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
366 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
368 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
370 if(weapon_prepareattack(0, 0))
372 if((!self.arc_beam) || wasfreed(self.arc_beam))
375 if(!self.BUTTON_ATCK_prev)
377 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
378 self.BUTTON_ATCK_prev = 1;
384 if(self.BUTTON_ATCK_prev != 0)
386 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
387 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
389 self.BUTTON_ATCK_prev = 0;
392 //if(self.BUTTON_ATCK2)
393 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
396 // self.arc_count = autocvar_g_balance_arc_secondary_count;
397 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
398 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
405 precache_model("models/weapons/g_arc.md3");
406 precache_model("models/weapons/v_arc.md3");
407 precache_model("models/weapons/h_arc.iqm");
408 //precache_sound("weapons/arc_bounce.wav");
409 precache_sound("weapons/arc_fire.wav");
410 precache_sound("weapons/arc_fire2.wav");
411 precache_sound("weapons/arc_impact.wav");
412 //precache_sound("weapons/arc_impact_combo.wav");
413 //precache_sound("weapons/W_Arc_Beam_fire.wav");
418 return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0);
422 return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
426 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
431 if(w_deathtype & HITTYPE_SECONDARY)
433 return WEAPON_ELECTRO_MURDER_ORBS;
437 if(w_deathtype & HITTYPE_BOUNCE)
438 return WEAPON_ELECTRO_MURDER_COMBO;
440 return WEAPON_ELECTRO_MURDER_BOLT;
445 //self.arc_secondarytime = time;
454 WEP_ACTION(WEP_ARC, WR_INIT);
455 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
456 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
457 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
458 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
459 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
463 float W_Arc(float req)
467 case WR_IMPACTEFFECT:
470 org2 = w_org + w_backoff * 6;
472 if(w_deathtype & HITTYPE_SECONDARY)
474 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
476 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
480 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
482 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
489 precache_sound("weapons/arc_impact.wav");
490 precache_sound("weapons/arc_impact_combo.wav");
495 // no weapon specific image for this weapon