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)
82 if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
85 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
86 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
87 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
88 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
91 e.fireball_impactvec = p;
92 RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
95 if(RandomSelection_chosen_ent)
97 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
98 d = damage + (edgedamage - damage) * (d / dist);
99 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
100 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
101 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
105 void W_Fireball_Think(entity this)
107 if(time > this.pushltime)
110 this.projectiledeathtype |= HITTYPE_SPLASH;
111 W_Fireball_Explode(this, NULL);
115 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));
117 this.nextthink = time + 0.1;
120 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
122 if(GetResource(this, RES_HEALTH) <= 0)
125 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
126 return; // g_projectiles_damage says to halt
128 TakeResource(this, RES_HEALTH, damage);
129 if(GetResource(this, RES_HEALTH) <= 0)
132 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
136 void W_Fireball_Attack1(entity actor, .entity weaponentity)
138 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);
140 W_MuzzleFlash(actor, weaponentity, EFFECT_FIREBALL_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
142 entity proj = new(plasma_prim);
143 proj.owner = proj.realowner = actor;
144 proj.bot_dodge = true;
145 proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
146 proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
147 proj.use = W_Fireball_Explode_use;
148 setthink(proj, W_Fireball_Think);
149 proj.nextthink = time;
150 SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_PRI(fireball, health));
151 proj.team = actor.team;
152 proj.event_damage = W_Fireball_Damage;
153 proj.takedamage = DAMAGE_YES;
154 proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
155 PROJECTILE_MAKETRIGGER(proj);
156 proj.projectiledeathtype = WEP_FIREBALL.m_id;
157 proj.weaponentity_fld = weaponentity;
158 setorigin(proj, w_shotorg);
160 set_movetype(proj, MOVETYPE_FLY);
161 W_SetupProjVelocity_PRI(proj, fireball);
162 proj.angles = vectoangles(proj.velocity);
163 settouch(proj, W_Fireball_TouchExplode);
164 setsize(proj, '-16 -16 -16', '16 16 16');
165 proj.flags = FL_PROJECTILE;
166 IL_PUSH(g_projectiles, proj);
167 IL_PUSH(g_bot_dodge, proj);
168 proj.missile_flags = MIF_SPLASH | MIF_PROXY;
170 CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
172 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
175 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
177 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
178 w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
179 W_MuzzleFlash(actor, weaponentity, EFFECT_FIREBALL_PRE_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
182 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
184 W_Fireball_Attack1(actor, weaponentity);
185 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
188 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
190 W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
191 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
194 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
196 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
197 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
200 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
202 W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
203 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
206 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
208 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
209 sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
210 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
213 void W_Fireball_Firemine_Think(entity this)
215 if(time > this.pushltime)
221 // make it "hot" once it leaves its owner
224 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
234 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));
236 this.nextthink = time + 0.1;
239 void W_Fireball_Firemine_Touch(entity this, entity toucher)
241 PROJECTILE_TOUCH(this, toucher);
242 if(toucher.takedamage == DAMAGE_AIM)
243 if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
248 this.projectiledeathtype |= HITTYPE_BOUNCE;
251 void W_Fireball_Attack2(entity actor, .entity weaponentity)
257 c = actor.(weaponentity).bulletcounter % 4;
261 f_diff = '-1.25 -3.75 0';
264 f_diff = '+1.25 -3.75 0';
267 f_diff = '-1.25 +3.75 0';
271 f_diff = '+1.25 +3.75 0';
274 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);
275 traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
276 w_shotorg = trace_endpos;
278 W_MuzzleFlash(actor, weaponentity, EFFECT_FIREBALL_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir);
281 proj.owner = proj.realowner = actor;
282 proj.bot_dodge = true;
283 proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
284 set_movetype(proj, MOVETYPE_BOUNCE);
285 proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
286 settouch(proj, W_Fireball_Firemine_Touch);
287 PROJECTILE_MAKETRIGGER(proj);
288 setsize(proj, '-4 -4 -4', '4 4 4');
289 setorigin(proj, w_shotorg);
290 setthink(proj, W_Fireball_Firemine_Think);
291 proj.nextthink = time;
292 proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
293 proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
294 W_SetupProjVelocity_UP_SEC(proj, fireball);
296 proj.angles = vectoangles(proj.velocity);
297 proj.flags = FL_PROJECTILE;
298 IL_PUSH(g_projectiles, proj);
299 IL_PUSH(g_bot_dodge, proj);
300 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
302 CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
304 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
307 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
309 PHYS_INPUT_BUTTON_ATCK(actor) = false;
310 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
311 if(actor.bot_primary_fireballmooth == 0)
313 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
315 PHYS_INPUT_BUTTON_ATCK(actor) = true;
316 if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
321 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
323 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
324 if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
328 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
332 if(time >= actor.(weaponentity).fireball_primarytime)
333 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
335 W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
336 actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
341 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
343 W_Fireball_Attack2(actor, weaponentity);
344 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
348 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
350 return true; // infinite ammo
352 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
354 return true; // fireball has infinite ammo
356 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
358 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
360 .entity weaponentity = weaponentities[slot];
361 actor.(weaponentity).fireball_primarytime = time;
364 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
366 if(w_deathtype & HITTYPE_SECONDARY)
367 return WEAPON_FIREBALL_SUICIDE_FIREMINE;
369 return WEAPON_FIREBALL_SUICIDE_BLAST;
371 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
373 if(w_deathtype & HITTYPE_SECONDARY)
374 return WEAPON_FIREBALL_MURDER_FIREMINE;
376 return WEAPON_FIREBALL_MURDER_BLAST;
382 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
385 if(w_deathtype & HITTYPE_SECONDARY)
387 // firemine goes out silently
391 org2 = w_org + w_backoff * 16;
392 pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
394 sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom