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 void W_Arc_Beam_Think(void)
90 //print("W_Arc_Beam_Think();\n");
91 if(self != self.owner.arc_beam)
94 print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n");
99 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)
101 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
105 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
106 remove(self.lg_ents[i]);
108 print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n");
115 float dt = frametime;
116 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
118 if(WEP_CVAR_PRI(arc, ammo))
120 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR_PRI(arc, ammo));
121 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR_PRI(arc, ammo) * frametime);
125 makevectors(self.owner.v_angle);
127 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range));
128 //WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
130 vector want_pos = w_shotend;
132 // TODO: remove this, we should REALLY set it from the attack function
133 if(self.beam_endpos == '0 0 0')
136 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
137 self.lg_ents[i] = spawn();
140 self.beam_endpos = want_pos;
144 vector direction_to_want_pos = normalize(want_pos - w_shotorg);
145 float distance_to_want_pos = vlen(want_pos - w_shotorg);
146 printf("distance_to_want_pos: %f\n", distance_to_want_pos);
148 if(self.beam_endpos != want_pos)
150 vector direction_to_beam_pos = normalize(self.beam_endpos - w_shotorg);
152 float angle = ceil(vlen(direction_to_want_pos - direction_to_beam_pos) * RAD2DEG);
154 if(angle && (angle > WEP_CVAR_PRI(arc, maxangle)))
156 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
158 printf("Correcting max angle: %f\n", angle);
160 anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1);
164 // the radius is not too far yet, no worries :D
168 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1);
170 newdir = normalize((direction_to_want_pos * (1 - blendfactor)) + (direction_to_beam_pos * blendfactor));
171 self.beam_endpos = w_shotorg + (newdir * distance_to_want_pos);
173 float max_allowed_segments;
175 if(WEP_CVAR_PRI(arc, distancepersegment))
176 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (distance_to_want_pos / WEP_CVAR_PRI(arc, distancepersegment)));
178 max_allowed_segments = ARC_MAX_SEGMENTS;
179 // this is where we calculate how many segments are needed
180 if(WEP_CVAR_PRI(arc, degreespersegment))
182 segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments );
183 //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments );
185 else { segments = 1; }
189 newdir = direction_to_want_pos;
193 te_customflash(self.beam_endpos, 40, 2, '1 1 1');
196 printf("segment count: %d\n", segments);
198 float segmentdist = distance_to_want_pos * (1/segments);
199 float segmentblend;// = (1/segments);
200 vector last_origin = w_shotorg;
201 for(i = 1; i <= segments; ++i)
203 segmentblend = (i/segments);
204 vector blended = normalize((direction_to_want_pos * (1 - segmentblend)) + (newdir * segmentblend));
205 vector new_origin = last_origin + (blended * segmentdist);
207 WarpZone_traceline_antilag(self.owner, last_origin, new_origin, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
211 float falloff = ExponentialFalloff(
212 WEP_CVAR_PRI(arc, falloff_mindist),
213 WEP_CVAR_PRI(arc, falloff_maxdist),
214 WEP_CVAR_PRI(arc, falloff_halflifedist),
215 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg)
218 if(accuracy_isgooddamage(self.owner, trace_ent))
219 accuracy_add(self.owner, WEP_ARC, 0, WEP_CVAR_PRI(arc, damage) * dt * falloff);
225 WEP_CVAR_PRI(arc, damage) * dt * falloff,
228 (blended * WEP_CVAR_PRI(arc, force)) * dt * falloff
232 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
233 te_customflash(trace_endpos, 80, 5, '1 0 0');
241 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
243 last_origin = new_origin;
248 /*if(w_shotorg != self.hook_start)
251 self.hook_start = w_shotorg;
253 if(w_shotend != self.hook_end)
256 self.hook_end = w_shotend;
259 self.owner.lg_fire_prev = time;
260 self.nextthink = time;
263 // Attack functions =========================
264 void W_Arc_Beam(void)
266 print("W_Arc_Beam();\n");
267 // only play fire sound if 0.5 sec has passed since player let go the fire button
268 if(time - self.lg_fire_prev > 0.5)
269 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
271 entity beam, oldself;
273 self.arc_beam = beam = spawn();
274 beam.classname = "W_Arc_Beam";
275 beam.solid = SOLID_NOT;
276 beam.think = W_Arc_Beam_Think;
278 beam.movetype = MOVETYPE_NONE;
279 beam.shot_spread = 1;
280 beam.bot_dodge = TRUE;
281 beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
282 //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
290 float W_Arc(float req)
296 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
298 self.BUTTON_ATCK=FALSE;
299 self.BUTTON_ATCK2=FALSE;
300 if(vlen(self.origin-self.enemy.origin) > 1000)
301 self.bot_aim_whichfiretype = 0;
302 if(self.bot_aim_whichfiretype == 0)
306 if(autocvar_g_balance_arc_primary_speed)
307 shoot = bot_aim(autocvar_g_balance_arc_primary_speed, 0, autocvar_g_balance_arc_primary_lifetime, FALSE);
309 shoot = bot_aim(1000000, 0, 0.001, FALSE);
313 self.BUTTON_ATCK = TRUE;
314 if(random() < 0.01) self.bot_aim_whichfiretype = 1;
319 //if(bot_aim(autocvar_g_balance_arc_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_arc_secondary_lifetime, TRUE))
321 // self.BUTTON_ATCK2 = TRUE;
322 // if(random() < 0.03) self.bot_aim_whichfiretype = 0;
333 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
334 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
335 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
337 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
339 if(weapon_prepareattack(0, 0))
341 if((!self.arc_beam) || wasfreed(self.arc_beam))
344 if(!self.BUTTON_ATCK_prev)
346 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
347 self.BUTTON_ATCK_prev = 1;
353 if(self.BUTTON_ATCK_prev != 0)
355 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
356 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
358 self.BUTTON_ATCK_prev = 0;
361 //if(self.BUTTON_ATCK2)
362 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
365 // self.arc_count = autocvar_g_balance_arc_secondary_count;
366 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
367 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
374 precache_model("models/weapons/g_arc.md3");
375 precache_model("models/weapons/v_arc.md3");
376 precache_model("models/weapons/h_arc.iqm");
377 //precache_sound("weapons/arc_bounce.wav");
378 precache_sound("weapons/arc_fire.wav");
379 precache_sound("weapons/arc_fire2.wav");
380 precache_sound("weapons/arc_impact.wav");
381 //precache_sound("weapons/arc_impact_combo.wav");
382 //precache_sound("weapons/W_Arc_Beam_fire.wav");
387 return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0);
391 return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
395 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
400 if(w_deathtype & HITTYPE_SECONDARY)
402 return WEAPON_ELECTRO_MURDER_ORBS;
406 if(w_deathtype & HITTYPE_BOUNCE)
407 return WEAPON_ELECTRO_MURDER_COMBO;
409 return WEAPON_ELECTRO_MURDER_BOLT;
414 //self.arc_secondarytime = time;
423 WEP_ACTION(WEP_ARC, WR_INIT);
424 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
425 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
426 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
427 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
428 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
432 float W_Arc(float req)
436 case WR_IMPACTEFFECT:
439 org2 = w_org + w_backoff * 6;
441 if(w_deathtype & HITTYPE_SECONDARY)
443 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
445 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
449 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
451 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
458 precache_sound("weapons/arc_impact.wav");
459 precache_sound("weapons/arc_impact_combo.wav");
464 // no weapon specific image for this weapon