2 REGISTER_WEAPON(FIREBALL, w_fireball, IT_FUEL, 9, WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "fireball", "fireball", _("Fireball"));
5 .float bot_primary_fireballmooth; // whatever a mooth is
6 .vector fireball_impactvec;
7 .float fireball_primarytime;
9 // weapon load persistence, for weapons that support reloading
12 void W_Fireball_SetAmmoCounter()
14 // set clip_load to the weapon we have switched to, if the gun uses reloading
15 if(!autocvar_g_balance_fireball_reload_ammo)
16 self.clip_load = 0; // also keeps crosshair ammo from displaying
19 self.clip_load = self.fireball_load;
20 self.clip_size = autocvar_g_balance_fireball_reload_ammo; // for the crosshair ammo display
24 void W_Fireball_ReloadedAndReady()
28 // now do the ammo transfer
29 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
30 while(self.clip_load < autocvar_g_balance_fireball_reload_ammo && self.ammo_fuel) // make sure we don't add more ammo than we have
35 // fuel can be a non-whole number, which brakes stuff here when between 0 and 1
36 if(self.ammo_fuel < 1)
39 self.fireball_load = self.clip_load;
41 t = ATTACK_FINISHED(self) - autocvar_g_balance_fireball_reload_time - 1;
42 ATTACK_FINISHED(self) = t;
46 void W_Fireball_Reload()
48 // return if reloading is disabled for this weapon
49 if(!autocvar_g_balance_fireball_reload_ammo)
52 if(!W_ReloadCheck(self.ammo_fuel, min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo)))
57 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
59 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_fireball_reload_time + 1;
60 ATTACK_FINISHED(self) = t;
62 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_fireball_reload_time, W_Fireball_ReloadedAndReady);
64 self.old_clip_load = self.clip_load;
68 void W_Fireball_Explode (void)
76 self.event_damage = SUB_Null;
77 self.takedamage = DAMAGE_NO;
80 d = (self.owner.health + self.owner.armorvalue);
81 RadiusDamage (self, self.realowner, autocvar_g_balance_fireball_primary_damage, autocvar_g_balance_fireball_primary_edgedamage, autocvar_g_balance_fireball_primary_radius, world, autocvar_g_balance_fireball_primary_force, self.projectiledeathtype, other);
82 if(self.realowner.health + self.realowner.armorvalue >= d)
85 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, self.origin, '0 0 0', '0 0 0', '0 0 0', 0, autocvar_g_balance_fireball_primary_bfgradius, 0.2, 0.05, 0.25);
88 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
89 for(e = findradius(self.origin, autocvar_g_balance_fireball_primary_bfgradius); e; e = e.chain)
90 if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
92 // can we see fireball?
93 traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
94 if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
96 // can we see player who shot fireball?
97 traceline(e.origin + e.view_ofs, self.realowner.origin + self.realowner.view_ofs, MOVE_NORMAL, e);
98 if(trace_ent != self.realowner)
99 if(/* trace_startsolid || */ trace_fraction != 1)
101 dist = vlen(self.origin - e.origin - e.view_ofs);
102 points = (1 - sqrt(dist / autocvar_g_balance_fireball_primary_bfgradius));
105 dir = normalize(e.origin + e.view_ofs - self.origin);
107 if(accuracy_isgooddamage(self.realowner, e))
108 accuracy_add(self.realowner, WEP_FIREBALL, 0, autocvar_g_balance_fireball_primary_bfgdamage * points);
110 Damage(e, self, self.realowner, autocvar_g_balance_fireball_primary_bfgdamage * points, self.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, autocvar_g_balance_fireball_primary_bfgforce * dir);
111 pointparticles(particleeffectnum("fireball_bfgdamage"), e.origin, -1 * dir, 1);
118 void W_Fireball_TouchExplode (void)
121 W_Fireball_Explode ();
124 void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage, float burntime)
133 RandomSelection_Init();
134 for(e = WarpZone_FindRadius(self.origin, dist, TRUE); e; e = e.chain)
135 if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
138 p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
139 p_y += e.mins_y + random() * (e.maxs_y - e.mins_y);
140 p_z += e.mins_z + random() * (e.maxs_z - e.mins_z);
141 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
144 e.fireball_impactvec = p;
145 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
148 if(RandomSelection_chosen_ent)
150 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
151 d = damage + (edgedamage - damage) * (d / dist);
152 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
153 //trailparticles(self, particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
154 pointparticles(particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
158 void W_Fireball_Think()
160 if(time > self.pushltime)
163 self.projectiledeathtype |= HITTYPE_SPLASH;
164 W_Fireball_Explode();
168 W_Fireball_LaserPlay(0.1, autocvar_g_balance_fireball_primary_laserradius, autocvar_g_balance_fireball_primary_laserdamage, autocvar_g_balance_fireball_primary_laseredgedamage, autocvar_g_balance_fireball_primary_laserburntime);
170 self.nextthink = time + 0.1;
173 void W_Fireball_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
177 self.health = self.health - damage;
178 if (self.health <= 0)
181 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
185 void W_Fireball_Attack1()
189 W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", CHAN_WEAPON, autocvar_g_balance_fireball_primary_damage + autocvar_g_balance_fireball_primary_bfgdamage);
191 pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
194 proj.classname = "plasma_prim";
195 proj.owner = proj.realowner = self;
196 proj.bot_dodge = TRUE;
197 proj.bot_dodgerating = autocvar_g_balance_fireball_primary_damage;
198 proj.pushltime = time + autocvar_g_balance_fireball_primary_lifetime;
199 proj.use = W_Fireball_Explode;
200 proj.think = W_Fireball_Think;
201 proj.nextthink = time;
202 proj.health = autocvar_g_balance_fireball_primary_health;
203 proj.team = self.team;
204 proj.event_damage = W_Fireball_Damage;
205 proj.takedamage = DAMAGE_YES;
206 proj.damageforcescale = autocvar_g_balance_fireball_primary_damageforcescale;
207 PROJECTILE_MAKETRIGGER(proj);
208 proj.projectiledeathtype = WEP_FIREBALL;
209 setorigin(proj, w_shotorg);
211 proj.movetype = MOVETYPE_FLY;
212 W_SETUPPROJECTILEVELOCITY(proj, g_balance_fireball_primary);
213 proj.angles = vectoangles(proj.velocity);
214 proj.touch = W_Fireball_TouchExplode;
215 setsize(proj, '-16 -16 -16', '16 16 16');
216 proj.flags = FL_PROJECTILE;
218 CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
220 other = proj; MUTATOR_CALLHOOK(EditProjectile);
223 void W_Fireball_AttackEffect(float i, vector f_diff)
225 W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0, 0);
226 w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
227 pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
230 void W_Fireball_Attack1_Frame4()
232 W_Fireball_Attack1();
233 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, w_ready);
236 void W_Fireball_Attack1_Frame3()
238 W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
239 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame4);
242 void W_Fireball_Attack1_Frame2()
244 W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
245 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame3);
248 void W_Fireball_Attack1_Frame1()
250 W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
251 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame2);
254 void W_Fireball_Attack1_Frame0()
256 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
257 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
259 if(autocvar_g_balance_fireball_reload_ammo)
261 self.clip_load -= autocvar_g_balance_fireball_primary_ammo;
262 self.fireball_load = self.clip_load;
265 self.ammo_fuel -= autocvar_g_balance_fireball_primary_ammo;
268 W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
269 sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
270 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame1);
273 void W_Firemine_Think()
275 if(time > self.pushltime)
281 // make it "hot" once it leaves its owner
284 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > autocvar_g_balance_fireball_secondary_laserradius)
294 W_Fireball_LaserPlay(0.1, autocvar_g_balance_fireball_secondary_laserradius, autocvar_g_balance_fireball_secondary_laserdamage, autocvar_g_balance_fireball_secondary_laseredgedamage, autocvar_g_balance_fireball_secondary_laserburntime);
296 self.nextthink = time + 0.1;
299 void W_Firemine_Touch (void)
302 if (other.takedamage == DAMAGE_AIM)
303 if(Fire_AddDamage(other, self.realowner, autocvar_g_balance_fireball_secondary_damage, autocvar_g_balance_fireball_secondary_damagetime, self.projectiledeathtype | HITTYPE_HEADSHOT) >= 0)
308 self.projectiledeathtype |= HITTYPE_BOUNCE;
311 void W_Fireball_Attack2()
317 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
318 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
320 if(autocvar_g_balance_fireball_reload_ammo)
322 self.clip_load -= autocvar_g_balance_fireball_secondary_ammo;
323 self.fireball_load = self.clip_load;
326 self.ammo_fuel -= autocvar_g_balance_fireball_secondary_ammo;
329 c = mod(self.bulletcounter, 4);
333 f_diff = '-1.25 -3.75 0';
336 f_diff = '+1.25 -3.75 0';
339 f_diff = '-1.25 +3.75 0';
343 f_diff = '+1.25 +3.75 0';
346 W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CHAN_WEAPON, autocvar_g_balance_fireball_secondary_damage);
347 traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
348 w_shotorg = trace_endpos;
350 pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
353 proj.owner = proj.realowner = self;
354 proj.classname = "grenade";
355 proj.bot_dodge = TRUE;
356 proj.bot_dodgerating = autocvar_g_balance_fireball_secondary_damage;
357 proj.movetype = MOVETYPE_BOUNCE;
358 proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
359 proj.touch = W_Firemine_Touch;
360 PROJECTILE_MAKETRIGGER(proj);
361 setsize(proj, '-4 -4 -4', '4 4 4');
362 setorigin(proj, w_shotorg);
363 proj.think = W_Firemine_Think;
364 proj.nextthink = time;
365 proj.damageforcescale = autocvar_g_balance_fireball_secondary_damageforcescale;
366 proj.pushltime = time + autocvar_g_balance_fireball_secondary_lifetime;
367 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
369 proj.angles = vectoangles(proj.velocity);
370 proj.flags = FL_PROJECTILE;
372 CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
374 other = proj; MUTATOR_CALLHOOK(EditProjectile);
377 void spawnfunc_weapon_fireball (void)
379 weapon_defaultspawnfunc(WEP_FIREBALL);
382 float w_fireball(float req)
387 self.BUTTON_ATCK = FALSE;
388 self.BUTTON_ATCK2 = FALSE;
389 if (self.bot_primary_fireballmooth == 0)
391 if(bot_aim(autocvar_g_balance_fireball_primary_speed, 0, autocvar_g_balance_fireball_primary_lifetime, FALSE))
393 self.BUTTON_ATCK = TRUE;
394 if(random() < 0.02) self.bot_primary_fireballmooth = 0;
399 if(bot_aim(autocvar_g_balance_fireball_secondary_speed, autocvar_g_balance_fireball_secondary_speed_up, autocvar_g_balance_fireball_secondary_lifetime, TRUE))
401 self.BUTTON_ATCK2 = TRUE;
402 if(random() < 0.01) self.bot_primary_fireballmooth = 1;
406 else if (req == WR_THINK)
408 if(autocvar_g_balance_fireball_reload_ammo && self.clip_load < min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo)) // forced reload
410 else if (self.BUTTON_ATCK)
412 if (time >= self.fireball_primarytime)
413 if (weapon_prepareattack(0, autocvar_g_balance_fireball_primary_refire))
415 W_Fireball_Attack1_Frame0();
416 self.fireball_primarytime = time + autocvar_g_balance_fireball_primary_refire2;
419 else if (self.BUTTON_ATCK2)
421 if (weapon_prepareattack(1, autocvar_g_balance_fireball_secondary_refire))
423 W_Fireball_Attack2();
424 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_fireball_secondary_animtime, w_ready);
428 else if (req == WR_PRECACHE)
430 precache_model ("models/weapons/g_fireball.md3");
431 precache_model ("models/weapons/v_fireball.md3");
432 precache_model ("models/weapons/h_fireball.iqm");
433 precache_model ("models/sphere/sphere.md3");
434 precache_sound ("weapons/fireball_fire.wav");
435 precache_sound ("weapons/fireball_fire2.wav");
436 precache_sound ("weapons/fireball_prefire2.wav");
437 precache_sound ("weapons/reload.wav");
439 else if (req == WR_SETUP)
441 weapon_setup(WEP_FIREBALL);
442 W_Fireball_SetAmmoCounter();
444 else if (req == WR_CHECKAMMO1)
446 ammo_amount = self.ammo_fuel >= autocvar_g_balance_fireball_primary_ammo;
447 ammo_amount += self.fireball_load >= autocvar_g_balance_fireball_primary_ammo;
450 else if (req == WR_CHECKAMMO2)
452 ammo_amount = self.ammo_fuel >= autocvar_g_balance_fireball_secondary_ammo;
453 ammo_amount += self.fireball_load >= autocvar_g_balance_fireball_secondary_ammo;
456 else if (req == WR_RESETPLAYER)
458 self.fireball_primarytime = time;
460 // all weapons must be fully loaded when we spawn
461 self.fireball_load = autocvar_g_balance_fireball_reload_ammo;
463 else if (req == WR_RELOAD)
471 float w_fireball(float req)
473 if(req == WR_IMPACTEFFECT)
476 if(w_deathtype & HITTYPE_SECONDARY)
478 // firemine goes out silently
482 org2 = w_org + w_backoff * 16;
483 pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
485 sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
488 else if(req == WR_PRECACHE)
490 precache_sound("weapons/fireball_impact2.wav");
492 else if (req == WR_SUICIDEMESSAGE)
494 if(w_deathtype & HITTYPE_SECONDARY)
495 w_deathtypestring = _("%s forgot about some firemine");
497 w_deathtypestring = _("%s should have used a smaller gun");
499 else if (req == WR_KILLMESSAGE)
501 if(w_deathtype & HITTYPE_SECONDARY)
503 if(w_deathtype & HITTYPE_HEADSHOT)
504 w_deathtypestring = _("%s tried to catch %s's firemine");
506 w_deathtypestring = _("%s fatefully ignored %s's firemine");
510 if(w_deathtype & HITTYPE_BOUNCE)
512 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
513 w_deathtypestring = _("%s could not hide from %s's fireball");
515 w_deathtypestring = _("%s saw the pretty lights of %s's fireball");
517 else if(w_deathtype & HITTYPE_SPLASH)
518 w_deathtypestring = _("%s got too close to %s's fireball");
520 w_deathtypestring = _("%s tasted %s's fireball");