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 = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
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);
147 if(self.beam_endpos != want_pos)
149 vector direction_to_beam_pos = normalize(self.beam_endpos - w_shotorg);
150 float angle = (vlen(direction_to_want_pos - direction_to_beam_pos) * RAD2DEG);
152 if(angle && (angle > WEP_CVAR_PRI(arc, maxangle)))
154 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
156 printf("Correcting max angle: %f\n", angle);
158 anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1);
162 // the radius is not too far yet, no worries :D
166 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1);
168 newdir = normalize((direction_to_want_pos * (1 - blendfactor)) + (direction_to_beam_pos * blendfactor));
169 self.beam_endpos = w_shotorg + (newdir * distance_to_want_pos);
171 float max_allowed_segments;
173 if(WEP_CVAR_PRI(arc, distancepersegment))
174 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (distance_to_want_pos / WEP_CVAR_PRI(arc, distancepersegment)));
176 max_allowed_segments = ARC_MAX_SEGMENTS;
177 // this is where we calculate how many segments are needed
178 if(WEP_CVAR_PRI(arc, degreespersegment))
180 segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments );
181 //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments );
183 else { segments = 1; }
187 newdir = direction_to_want_pos;
192 printf("segment count: %d\n", segments);
194 float segmentdist = distance_to_want_pos * (1/segments);
195 float segmentblend;// = (1/segments);
196 vector last_origin = w_shotorg;
197 for(i = 1; i <= segments; ++i)
199 segmentblend = (i/segments);
200 vector blended = normalize((direction_to_want_pos * (1 - segmentblend)) + (newdir * segmentblend));
201 vector new_origin = last_origin + (blended * segmentdist);
204 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
207 last_origin = new_origin;
215 force = w_shotdir * WEP_CVAR_PRI(arc, force);
217 float f = ExponentialFalloff(
218 WEP_CVAR_PRI(arc, falloff_mindist),
219 WEP_CVAR_PRI(arc, falloff_maxdist),
220 WEP_CVAR_PRI(arc, falloff_halflifedist),
221 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg)
224 if(accuracy_isgooddamage(self.owner, trace_ent))
225 accuracy_add(self.owner, WEP_ARC, 0, WEP_CVAR_PRI(arc, damage) * dt * f);
231 WEP_CVAR_PRI(arc, damage) * dt * f,
240 /*if(w_shotorg != self.hook_start)
243 self.hook_start = w_shotorg;
245 if(w_shotend != self.hook_end)
248 self.hook_end = w_shotend;
251 self.owner.lg_fire_prev = time;
252 self.nextthink = time;
255 // Attack functions =========================
256 void W_Arc_Beam(void)
258 print("W_Arc_Beam();\n");
259 // only play fire sound if 0.5 sec has passed since player let go the fire button
260 if(time - self.lg_fire_prev > 0.5)
261 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
263 entity beam, oldself;
265 self.arc_beam = beam = spawn();
266 beam.classname = "W_Arc_Beam";
267 beam.solid = SOLID_NOT;
268 beam.think = W_Arc_Beam_Think;
270 beam.movetype = MOVETYPE_NONE;
271 beam.shot_spread = 1;
272 beam.bot_dodge = TRUE;
273 beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
274 //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
282 float W_Arc(float req)
288 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
290 self.BUTTON_ATCK=FALSE;
291 self.BUTTON_ATCK2=FALSE;
292 if(vlen(self.origin-self.enemy.origin) > 1000)
293 self.bot_aim_whichfiretype = 0;
294 if(self.bot_aim_whichfiretype == 0)
298 if(autocvar_g_balance_arc_primary_speed)
299 shoot = bot_aim(autocvar_g_balance_arc_primary_speed, 0, autocvar_g_balance_arc_primary_lifetime, FALSE);
301 shoot = bot_aim(1000000, 0, 0.001, FALSE);
305 self.BUTTON_ATCK = TRUE;
306 if(random() < 0.01) self.bot_aim_whichfiretype = 1;
311 //if(bot_aim(autocvar_g_balance_arc_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_arc_secondary_lifetime, TRUE))
313 // self.BUTTON_ATCK2 = TRUE;
314 // if(random() < 0.03) self.bot_aim_whichfiretype = 0;
325 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
326 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
327 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
329 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
331 if(weapon_prepareattack(0, 0))
333 if((!self.arc_beam) || wasfreed(self.arc_beam))
336 if(!self.BUTTON_ATCK_prev)
338 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
339 self.BUTTON_ATCK_prev = 1;
345 if(self.BUTTON_ATCK_prev != 0)
347 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
348 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
350 self.BUTTON_ATCK_prev = 0;
353 //if(self.BUTTON_ATCK2)
354 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
357 // self.arc_count = autocvar_g_balance_arc_secondary_count;
358 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
359 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
366 precache_model("models/weapons/g_arc.md3");
367 precache_model("models/weapons/v_arc.md3");
368 precache_model("models/weapons/h_arc.iqm");
369 //precache_sound("weapons/arc_bounce.wav");
370 precache_sound("weapons/arc_fire.wav");
371 precache_sound("weapons/arc_fire2.wav");
372 precache_sound("weapons/arc_impact.wav");
373 //precache_sound("weapons/arc_impact_combo.wav");
374 //precache_sound("weapons/W_Arc_Beam_fire.wav");
379 return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0);
383 return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
387 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
392 if(w_deathtype & HITTYPE_SECONDARY)
394 return WEAPON_ELECTRO_MURDER_ORBS;
398 if(w_deathtype & HITTYPE_BOUNCE)
399 return WEAPON_ELECTRO_MURDER_COMBO;
401 return WEAPON_ELECTRO_MURDER_BOLT;
406 //self.arc_secondarytime = time;
415 WEP_ACTION(WEP_ARC, WR_INIT);
416 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
417 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
418 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
419 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
420 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
424 float W_Arc(float req)
428 case WR_IMPACTEFFECT:
431 org2 = w_org + w_backoff * 6;
433 if(w_deathtype & HITTYPE_SECONDARY)
435 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
437 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
441 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
443 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
450 precache_sound("weapons/arc_impact.wav");
451 precache_sound("weapons/arc_impact_combo.wav");
456 // no weapon specific image for this weapon