5 void W_Fireball_Explode(entity this, entity directhitentity)
13 this.event_damage = func_null;
14 this.takedamage = DAMAGE_NO;
17 d = (GetResource(this.realowner, RES_HEALTH) + GetResource(this.realowner, RES_ARMOR));
18 RadiusDamage(this, this.realowner, WEP_CVAR_PRI(fireball, damage), WEP_CVAR_PRI(fireball, edgedamage), WEP_CVAR_PRI(fireball, radius), NULL, NULL, WEP_CVAR_PRI(fireball, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
19 if(GetResource(this.realowner, RES_HEALTH) + GetResource(this.realowner, RES_ARMOR) >= d)
22 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, this.origin, '0 0 0', '0 0 0', '0 0 0', 0, WEP_CVAR_PRI(fireball, bfgradius), 0.2, 0.05, 0.25);
25 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
26 for(e = findradius(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain)
27 if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
29 // can we see fireball?
30 traceline(e.origin + e.view_ofs, this.origin, MOVE_NORMAL, e);
31 if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
33 // can we see player who shot fireball?
34 traceline(e.origin + e.view_ofs, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e);
35 if(trace_ent != this.realowner)
36 if(/* trace_startsolid || */ trace_fraction != 1)
38 dist = vlen(this.origin - e.origin - e.view_ofs);
39 points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
42 dir = normalize(e.origin + e.view_ofs - this.origin);
44 if(accuracy_isgooddamage(this.realowner, e))
45 accuracy_add(this.realowner, WEP_FIREBALL, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
47 Damage(e, this, this.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, this.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, this.weaponentity_fld, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir);
48 Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1);
55 void W_Fireball_Explode_think(entity this)
57 W_Fireball_Explode(this, NULL);
60 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
62 W_Fireball_Explode(this, trigger);
65 void W_Fireball_TouchExplode(entity this, entity toucher)
67 PROJECTILE_TOUCH(this, toucher);
68 W_Fireball_Explode(this, toucher);
71 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
80 RandomSelection_Init();
81 for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
83 if(e == this.realowner) continue;
84 if(e.takedamage != DAMAGE_AIM) continue;
85 if(IS_PLAYER(e) && this.realowner && SAME_TEAM(e, this)) continue;
88 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
89 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
90 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
91 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
94 e.fireball_impactvec = p;
95 RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
98 if(RandomSelection_chosen_ent)
100 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
101 d = damage + (edgedamage - damage) * (d / dist);
102 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
103 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
104 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
108 void W_Fireball_Think(entity this)
110 if(time > this.pushltime)
113 this.projectiledeathtype |= HITTYPE_SPLASH;
114 W_Fireball_Explode(this, NULL);
118 W_Fireball_LaserPlay(this, 0.1, WEP_CVAR_PRI(fireball, laserradius), WEP_CVAR_PRI(fireball, laserdamage), WEP_CVAR_PRI(fireball, laseredgedamage), WEP_CVAR_PRI(fireball, laserburntime));
120 this.nextthink = time + 0.1;
123 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
125 if(GetResource(this, RES_HEALTH) <= 0)
128 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
129 return; // g_projectiles_damage says to halt
131 TakeResource(this, RES_HEALTH, damage);
132 if(GetResource(this, RES_HEALTH) <= 0)
135 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
139 void W_Fireball_Attack1(entity actor, .entity weaponentity)
141 W_SetupShot_ProjectileSize(actor, weaponentity, '-16 -16 -16', '16 16 16', false, 2, SND_FIREBALL_FIRE2, CH_WEAPON_A, WEP_CVAR_PRI(fireball, damage) + WEP_CVAR_PRI(fireball, bfgdamage), WEP_FIREBALL.m_id);
143 W_MuzzleFlash(WEP_FIREBALL, actor, weaponentity, w_shotorg, w_shotdir);
145 entity proj = new(plasma_prim);
146 proj.owner = proj.realowner = actor;
147 proj.bot_dodge = true;
148 proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
149 proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
150 proj.use = W_Fireball_Explode_use;
151 setthink(proj, W_Fireball_Think);
152 proj.nextthink = time;
153 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_PRI(fireball, health));
154 proj.team = actor.team;
155 proj.event_damage = W_Fireball_Damage;
156 proj.takedamage = DAMAGE_YES;
157 proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
158 PROJECTILE_MAKETRIGGER(proj);
159 proj.projectiledeathtype = WEP_FIREBALL.m_id;
160 proj.weaponentity_fld = weaponentity;
161 setorigin(proj, w_shotorg);
163 set_movetype(proj, MOVETYPE_FLY);
164 W_SetupProjVelocity_PRI(proj, fireball);
165 proj.angles = vectoangles(proj.velocity);
166 settouch(proj, W_Fireball_TouchExplode);
167 setsize(proj, '-16 -16 -16', '16 16 16');
168 proj.flags = FL_PROJECTILE;
169 IL_PUSH(g_projectiles, proj);
170 IL_PUSH(g_bot_dodge, proj);
171 proj.missile_flags = MIF_SPLASH | MIF_PROXY;
173 CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
175 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
178 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
180 W_SetupShot_ProjectileSize(actor, weaponentity, '-16 -16 -16', '16 16 16', false, 0, SND_Null, 0, 0, WEP_FIREBALL.m_id); // TODO: probably doesn't need deathtype, just a prefire effect
181 w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
182 Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
185 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
187 W_Fireball_Attack1(actor, weaponentity);
188 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
191 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
193 W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
194 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
197 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
199 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
200 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
203 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
205 W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
206 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
209 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
211 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
212 sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
213 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
216 void W_Fireball_Firemine_Think(entity this)
218 if(time > this.pushltime)
224 // make it "hot" once it leaves its owner
227 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
237 W_Fireball_LaserPlay(this, 0.1, WEP_CVAR_SEC(fireball, laserradius), WEP_CVAR_SEC(fireball, laserdamage), WEP_CVAR_SEC(fireball, laseredgedamage), WEP_CVAR_SEC(fireball, laserburntime));
239 this.nextthink = time + 0.1;
242 void W_Fireball_Firemine_Touch(entity this, entity toucher)
244 PROJECTILE_TOUCH(this, toucher);
245 if(toucher.takedamage == DAMAGE_AIM)
246 if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
251 this.projectiledeathtype |= HITTYPE_BOUNCE;
254 void W_Fireball_Attack2(entity actor, .entity weaponentity)
260 c = actor.(weaponentity).bulletcounter % 4;
264 f_diff = '-1.25 -3.75 0';
267 f_diff = '+1.25 -3.75 0';
270 f_diff = '-1.25 +3.75 0';
274 f_diff = '+1.25 +3.75 0';
277 W_SetupShot_ProjectileSize(actor, weaponentity, '-4 -4 -4', '4 4 4', false, 2, SND_FIREBALL_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(fireball, damage), WEP_FIREBALL.m_id | HITTYPE_SECONDARY);
278 traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
279 w_shotorg = trace_endpos;
281 W_MuzzleFlash(WEP_FIREBALL, actor, weaponentity, w_shotorg, w_shotdir);
284 proj.owner = proj.realowner = actor;
285 proj.bot_dodge = true;
286 proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
287 set_movetype(proj, MOVETYPE_BOUNCE);
288 proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
289 settouch(proj, W_Fireball_Firemine_Touch);
290 PROJECTILE_MAKETRIGGER(proj);
291 setsize(proj, '-4 -4 -4', '4 4 4');
292 setorigin(proj, w_shotorg);
293 setthink(proj, W_Fireball_Firemine_Think);
294 proj.nextthink = time;
295 proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
296 proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
297 W_SetupProjVelocity_UP_SEC(proj, fireball);
299 proj.angles = vectoangles(proj.velocity);
300 proj.flags = FL_PROJECTILE;
301 IL_PUSH(g_projectiles, proj);
302 IL_PUSH(g_bot_dodge, proj);
303 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
305 CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
307 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
310 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
312 PHYS_INPUT_BUTTON_ATCK(actor) = false;
313 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
314 if(actor.bot_primary_fireballmooth == 0)
316 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
318 PHYS_INPUT_BUTTON_ATCK(actor) = true;
319 if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
324 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
326 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
327 if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
331 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
335 if(time >= actor.(weaponentity).fireball_primarytime)
336 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
338 W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
339 actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
344 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
346 W_Fireball_Attack2(actor, weaponentity);
347 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
351 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
353 return true; // infinite ammo
355 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
357 return true; // fireball has infinite ammo
359 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
361 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
363 .entity weaponentity = weaponentities[slot];
364 actor.(weaponentity).fireball_primarytime = time;
367 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
369 if(w_deathtype & HITTYPE_SECONDARY)
370 return WEAPON_FIREBALL_SUICIDE_FIREMINE;
372 return WEAPON_FIREBALL_SUICIDE_BLAST;
374 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
376 if(w_deathtype & HITTYPE_SECONDARY)
377 return WEAPON_FIREBALL_MURDER_FIREMINE;
379 return WEAPON_FIREBALL_MURDER_BLAST;
385 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
388 if(w_deathtype & HITTYPE_SECONDARY)
390 // firemine goes out silently
394 org2 = w_org + w_backoff * 16;
395 pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
397 sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom