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, damage) \
23 w_cvar(id, sn, PRI, degreespersegment) \
24 w_cvar(id, sn, PRI, distancepersegment) \
25 w_cvar(id, sn, PRI, falloff_halflifedist) \
26 w_cvar(id, sn, PRI, falloff_maxdist) \
27 w_cvar(id, sn, PRI, falloff_mindist) \
28 w_cvar(id, sn, PRI, force) \
29 w_cvar(id, sn, PRI, maxangle) \
30 w_cvar(id, sn, PRI, range) \
31 w_cvar(id, sn, PRI, refire) \
32 w_cvar(id, sn, PRI, returnspeed) \
33 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
34 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
35 w_prop(id, sn, string, weaponreplace, weaponreplace) \
36 w_prop(id, sn, float, weaponstart, weaponstart) \
37 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
38 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
41 vector arc_shotorigin[4];
44 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
46 .vector hook_start, hook_end; // used for beam
47 .entity arc_beam; // used for beam
48 .float BUTTON_ATCK_prev; // for better animation control
49 .float lg_fire_prev; // for better animation control
53 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
55 float W_Arc_Beam_Send(entity to, float sf)
57 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
59 if(sound_allowed(MSG_BROADCAST, self.owner))
61 WriteByte(MSG_ENTITY, sf);
64 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
65 WriteCoord(MSG_ENTITY, WEP_CVAR_PRI(arc, range));
69 WriteCoord(MSG_ENTITY, self.hook_start_x);
70 WriteCoord(MSG_ENTITY, self.hook_start_y);
71 WriteCoord(MSG_ENTITY, self.hook_start_z);
75 WriteCoord(MSG_ENTITY, self.hook_end_x);
76 WriteCoord(MSG_ENTITY, self.hook_end_y);
77 WriteCoord(MSG_ENTITY, self.hook_end_z);
83 #define ARC_MAX_SEGMENTS 20
84 .entity lg_ents[ARC_MAX_SEGMENTS]; // debug
87 .float beam_initialized;
88 void W_Arc_Beam_Think(void)
91 //print("W_Arc_Beam_Think();\n");
92 if(self != self.owner.arc_beam)
95 print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n");
100 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)
102 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
106 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
107 remove(self.lg_ents[i]);
109 print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n");
116 float dt = frametime;
117 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
119 if(WEP_CVAR_PRI(arc, ammo))
121 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR_PRI(arc, ammo));
122 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR_PRI(arc, ammo) * frametime);
126 makevectors(self.owner.v_angle);
128 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range));
129 //WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
131 vector want_dir = w_shotdir;
132 //vector want_pos = w_shotend;
134 if(!self.beam_initialized)
137 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
138 self.lg_ents[i] = spawn();
141 self.beam_dir = want_dir;
142 self.beam_initialized = TRUE;
146 //vector direction_to_want_pos = normalize(want_pos - w_shotorg);
147 //float distance_to_want_pos = vlen(want_pos - w_shotorg);
148 //printf("distance_to_want_pos: %f\n", distance_to_want_pos);
150 if(self.beam_dir != want_dir)
152 //vector direction_to_beam_pos = normalize(self.beam_endpos - w_shotorg);
154 float angle = ceil(vlen(want_dir - self.beam_dir) * RAD2DEG);
156 if(angle && (angle > WEP_CVAR_PRI(arc, maxangle)))
158 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
160 printf("Correcting max angle: %f %f\n", angle, WEP_CVAR_PRI(arc, distancepersegment));
162 anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1);
166 // the radius is not too far yet, no worries :D
170 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1);
172 self.beam_dir = normalize((want_dir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
173 //self.beam_endpos = w_shotorg + (newdir * distance_to_want_pos);
175 float max_allowed_segments = ARC_MAX_SEGMENTS;
177 //if(WEP_CVAR_PRI(arc, distancepersegment))
178 // max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (distance_to_want_pos / WEP_CVAR_PRI(arc, distancepersegment)));
180 // max_allowed_segments = ARC_MAX_SEGMENTS;
182 // this is where we calculate how many segments are needed
183 if(WEP_CVAR_PRI(arc, degreespersegment))
185 segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments );
186 //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments );
188 else { segments = 1; }
195 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR_PRI(arc, range)));
196 //te_customflash(beam_endpos_estimate, 40, 2, '1 1 1');
199 printf("segment count: %d\n", segments);
200 float hit_something = FALSE;
202 float segmentdist; // = WEP_CVAR_PRI(arc, range) / segments; // = vlen(self.beam_endpos - last_origin) * (1/segments);
203 float segmentblend;// = (1/segments);
204 vector last_origin = w_shotorg;
205 for(i = 1; i <= segments; ++i)
207 segmentblend = (i/segments);
208 segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
209 //direction_to_want_pos = normalize(self.beam_endpos - last_origin);
210 vector blended = normalize((want_dir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend));
211 vector new_origin = last_origin + (blended * segmentdist);
213 WarpZone_traceline_antilag(self.owner, last_origin, new_origin, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
217 //vector attackend = (last_origin * (1 - trace_fraction) + new_origin * trace_fraction); // trace_endpos jumps weirdly with playermodels...
218 float falloff = ExponentialFalloff(
219 WEP_CVAR_PRI(arc, falloff_mindist),
220 WEP_CVAR_PRI(arc, falloff_maxdist),
221 WEP_CVAR_PRI(arc, falloff_halflifedist),
222 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg)
225 if(accuracy_isgooddamage(self.owner, trace_ent))
226 accuracy_add(self.owner, WEP_ARC, 0, WEP_CVAR_PRI(arc, damage) * dt * falloff);
232 WEP_CVAR_PRI(arc, damage) * dt * falloff,
235 (blended * WEP_CVAR_PRI(arc, force)) * dt * falloff
239 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
240 te_customflash(trace_endpos, 80, 5, '1 0 0');
241 hit_something = TRUE;
245 else if(trace_fraction != 1)
247 // we collided with geometry
249 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
250 te_customflash(trace_endpos, 50, 2, '0 0 1');
251 hit_something = TRUE;
258 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
260 last_origin = new_origin;
267 te_customflash(trace_endpos, 50, 2, '0 1 0');
272 /*if(w_shotorg != self.hook_start)
275 self.hook_start = w_shotorg;
277 if(w_shotend != self.hook_end)
280 self.hook_end = w_shotend;
283 self.owner.lg_fire_prev = time;
284 self.nextthink = time;
287 // Attack functions =========================
288 void W_Arc_Beam(void)
290 print("W_Arc_Beam();\n");
291 // only play fire sound if 0.5 sec has passed since player let go the fire button
292 if(time - self.lg_fire_prev > 0.5)
293 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
295 entity beam, oldself;
297 self.arc_beam = beam = spawn();
298 beam.classname = "W_Arc_Beam";
299 beam.solid = SOLID_NOT;
300 beam.think = W_Arc_Beam_Think;
302 beam.movetype = MOVETYPE_NONE;
303 beam.shot_spread = 1;
304 beam.bot_dodge = TRUE;
305 beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
306 //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
314 float W_Arc(float req)
320 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
322 self.BUTTON_ATCK=FALSE;
323 self.BUTTON_ATCK2=FALSE;
324 if(vlen(self.origin-self.enemy.origin) > 1000)
325 self.bot_aim_whichfiretype = 0;
326 if(self.bot_aim_whichfiretype == 0)
330 if(autocvar_g_balance_arc_primary_speed)
331 shoot = bot_aim(autocvar_g_balance_arc_primary_speed, 0, autocvar_g_balance_arc_primary_lifetime, FALSE);
333 shoot = bot_aim(1000000, 0, 0.001, FALSE);
337 self.BUTTON_ATCK = TRUE;
338 if(random() < 0.01) self.bot_aim_whichfiretype = 1;
343 //if(bot_aim(autocvar_g_balance_arc_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_arc_secondary_lifetime, TRUE))
345 // self.BUTTON_ATCK2 = TRUE;
346 // if(random() < 0.03) self.bot_aim_whichfiretype = 0;
357 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
358 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
359 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
361 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
363 if(weapon_prepareattack(0, 0))
365 if((!self.arc_beam) || wasfreed(self.arc_beam))
368 if(!self.BUTTON_ATCK_prev)
370 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
371 self.BUTTON_ATCK_prev = 1;
377 if(self.BUTTON_ATCK_prev != 0)
379 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
380 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
382 self.BUTTON_ATCK_prev = 0;
385 //if(self.BUTTON_ATCK2)
386 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
389 // self.arc_count = autocvar_g_balance_arc_secondary_count;
390 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
391 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
398 precache_model("models/weapons/g_arc.md3");
399 precache_model("models/weapons/v_arc.md3");
400 precache_model("models/weapons/h_arc.iqm");
401 //precache_sound("weapons/arc_bounce.wav");
402 precache_sound("weapons/arc_fire.wav");
403 precache_sound("weapons/arc_fire2.wav");
404 precache_sound("weapons/arc_impact.wav");
405 //precache_sound("weapons/arc_impact_combo.wav");
406 //precache_sound("weapons/W_Arc_Beam_fire.wav");
411 return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0);
415 return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
419 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
424 if(w_deathtype & HITTYPE_SECONDARY)
426 return WEAPON_ELECTRO_MURDER_ORBS;
430 if(w_deathtype & HITTYPE_BOUNCE)
431 return WEAPON_ELECTRO_MURDER_COMBO;
433 return WEAPON_ELECTRO_MURDER_BOLT;
438 //self.arc_secondarytime = time;
447 WEP_ACTION(WEP_ARC, WR_INIT);
448 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
449 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
450 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
451 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
452 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
456 float W_Arc(float req)
460 case WR_IMPACTEFFECT:
463 org2 = w_org + w_backoff * 6;
465 if(w_deathtype & HITTYPE_SECONDARY)
467 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
469 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
473 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
475 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
482 precache_sound("weapons/arc_impact.wav");
483 precache_sound("weapons/arc_impact_combo.wav");
488 // no weapon specific image for this weapon