3 /* WEP_##id */ LIGHTNING,
4 /* function */ w_lightning,
5 /* ammotype */ IT_CELLS,
7 /* flags */ WEP_FLAG_NORMAL | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
9 /* model */ "lightning",
10 /* shortname */ "lightning",
11 /* fullname */ _("Lightning")
16 vector lightning_shotorigin[4];
21 // Declarations =========================
22 .vector hook_start, hook_end; // used for beam
23 .entity lightning_beam; // used for beam
24 .float BUTTON_ATCK_prev; // for better animation control
25 .float lg_fire_prev; // for better animation control
27 // Lightning functions =========================
28 float W_Lightning_Beam_Send(entity to, float sf)
30 WriteByte(MSG_ENTITY, ENT_CLIENT_LIGHTNING_BEAM);
32 if(sound_allowed(MSG_BROADCAST, self.owner))
34 WriteByte(MSG_ENTITY, sf);
37 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
38 WriteCoord(MSG_ENTITY, autocvar_g_balance_lightning_primary_range);
42 WriteCoord(MSG_ENTITY, self.hook_start_x);
43 WriteCoord(MSG_ENTITY, self.hook_start_y);
44 WriteCoord(MSG_ENTITY, self.hook_start_z);
48 WriteCoord(MSG_ENTITY, self.hook_end_x);
49 WriteCoord(MSG_ENTITY, self.hook_end_y);
50 WriteCoord(MSG_ENTITY, self.hook_end_z);
55 void W_Lightning_Beam_Think()
57 self.owner.lg_fire_prev = time;
58 if (self != self.owner.lightning_beam)
63 if (self.owner.weaponentity.state != WS_INUSE || (self.owner.ammo_cells <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
65 if(self == self.owner.lightning_beam)
66 self.owner.lightning_beam = world;
71 self.nextthink = time;
73 makevectors(self.owner.v_angle);
77 if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
79 if(autocvar_g_balance_lightning_primary_ammo)
81 dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_lightning_primary_ammo);
82 self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_lightning_primary_ammo * frametime);
86 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_lightning_primary_damage * dt, autocvar_g_balance_lightning_primary_range);
87 WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
93 force = w_shotdir * autocvar_g_balance_lightning_primary_force;
95 f = ExponentialFalloff(autocvar_g_balance_lightning_primary_falloff_mindist, autocvar_g_balance_lightning_primary_falloff_maxdist, autocvar_g_balance_lightning_primary_falloff_halflifedist, vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
97 if(accuracy_isgooddamage(self.owner, trace_ent))
98 accuracy_add(self.owner, WEP_LIGHTNING, 0, autocvar_g_balance_lightning_primary_damage * dt * f);
99 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_lightning_primary_damage * dt * f, WEP_LIGHTNING, trace_endpos, force * dt);
103 if(w_shotorg != self.hook_start)
106 self.hook_start = w_shotorg;
108 if(w_shotend != self.hook_end)
111 self.hook_end = w_shotend;
115 // Attack functions =========================
116 void W_Lightning_Attack1 (void)
118 // only play fire sound if 0.5 sec has passed since player let go the fire button
119 if(time - self.lg_fire_prev > 0.5)
120 sound (self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
122 entity beam, oldself;
124 self.lightning_beam = beam = spawn();
125 beam.classname = "W_Lightning_Beam";
126 beam.solid = SOLID_NOT;
127 beam.think = W_Lightning_Beam_Think;
129 beam.movetype = MOVETYPE_NONE;
130 beam.shot_spread = 1;
131 beam.bot_dodge = TRUE;
132 beam.bot_dodgerating = autocvar_g_balance_lightning_primary_damage;
133 Net_LinkEntity(beam, FALSE, 0, W_Lightning_Beam_Send);
141 float w_lightning(float req)
145 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
147 self.BUTTON_ATCK=FALSE;
148 self.BUTTON_ATCK2=FALSE;
149 if(vlen(self.origin-self.enemy.origin) > 1000)
150 self.bot_aim_whichfiretype = 0;
151 if(self.bot_aim_whichfiretype == 0)
155 if(autocvar_g_balance_lightning_primary_speed)
156 shoot = bot_aim(autocvar_g_balance_lightning_primary_speed, 0, autocvar_g_balance_lightning_primary_lifetime, FALSE);
158 shoot = bot_aim(1000000, 0, 0.001, FALSE);
162 self.BUTTON_ATCK = TRUE;
163 if(random() < 0.01) self.bot_aim_whichfiretype = 1;
168 //if(bot_aim(autocvar_g_balance_lightning_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_lightning_secondary_lifetime, TRUE))
170 // self.BUTTON_ATCK2 = TRUE;
171 // if(random() < 0.03) self.bot_aim_whichfiretype = 0;
176 else if (req == WR_THINK)
178 if (self.BUTTON_ATCK)
180 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
181 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
182 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_lightning_primary_animtime, w_ready);
184 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
186 if (weapon_prepareattack(0, 0))
188 if ((!self.lightning_beam) || wasfreed(self.lightning_beam))
189 W_Lightning_Attack1();
191 if(!self.BUTTON_ATCK_prev)
193 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
194 self.BUTTON_ATCK_prev = 1;
200 if (self.BUTTON_ATCK_prev != 0)
202 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_lightning_primary_animtime, w_ready);
203 ATTACK_FINISHED(self) = time + autocvar_g_balance_lightning_primary_refire * W_WeaponRateFactor();
205 self.BUTTON_ATCK_prev = 0;
208 //if (self.BUTTON_ATCK2)
209 //if (weapon_prepareattack(1, autocvar_g_balance_lightning_secondary_refire))
211 // W_Lightning_Attack2();
212 // self.lightning_count = autocvar_g_balance_lightning_secondary_count;
213 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_lightning_secondary_animtime, w_lightning_checkattack);
214 // self.lightning_secondarytime = time + autocvar_g_balance_lightning_secondary_refire2 * W_WeaponRateFactor();
217 else if (req == WR_PRECACHE)
219 precache_model ("models/weapons/g_lightning.md3");
220 precache_model ("models/weapons/v_lightning.md3");
221 precache_model ("models/weapons/h_lightning.iqm");
222 //precache_sound ("weapons/lightning_bounce.wav");
223 precache_sound ("weapons/lightning_fire.wav");
224 precache_sound ("weapons/lightning_fire2.wav");
225 precache_sound ("weapons/lightning_impact.wav");
226 //precache_sound ("weapons/lightning_impact_combo.wav");
227 //precache_sound ("weapons/W_Lightning_Beam_fire.wav");
229 else if (req == WR_SETUP)
230 weapon_setup(WEP_LIGHTNING);
231 else if (req == WR_CHECKAMMO1)
233 return !autocvar_g_balance_lightning_primary_ammo || (self.ammo_cells > 0);
235 else if (req == WR_CHECKAMMO2)
236 return self.ammo_cells >= autocvar_g_balance_lightning_secondary_ammo;
237 else if (req == WR_KILLMESSAGE)
239 if(w_deathtype & HITTYPE_SECONDARY)
241 return WEAPON_ELECTRO_MURDER_ORBS;
245 if(w_deathtype & HITTYPE_BOUNCE)
246 return WEAPON_ELECTRO_MURDER_COMBO;
248 return WEAPON_ELECTRO_MURDER_BOLT;
251 else if (req == WR_RESETPLAYER)
253 //self.lightning_secondarytime = time;
260 weapon_action(WEP_LIGHTNING, WR_PRECACHE);
261 lightning_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 1);
262 lightning_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 2);
263 lightning_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 3);
264 lightning_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_LIGHTNING), FALSE, FALSE, 4);
267 void spawnfunc_weapon_lightning (void) // should this really be here?
269 weapon_defaultspawnfunc(WEP_LIGHTNING);
273 float w_lightning(float req)
275 if(req == WR_IMPACTEFFECT)
278 org2 = w_org + w_backoff * 6;
280 if(w_deathtype & HITTYPE_SECONDARY)
282 pointparticles(particleeffectnum("lightning_ballexplode"), org2, '0 0 0', 1);
284 sound(self, CH_SHOTS, "weapons/lightning_impact.wav", VOL_BASE, ATTN_NORM);
288 pointparticles(particleeffectnum("lightning_impact"), org2, '0 0 0', 1);
290 sound(self, CH_SHOTS, "weapons/lightning_impact.wav", VOL_BASE, ATTN_NORM);
293 else if(req == WR_PRECACHE)
295 precache_sound("weapons/lightning_impact.wav");
296 precache_sound("weapons/lightning_impact_combo.wav");