4 spawnfunc(weapon_fireball)
6 weapon_defaultspawnfunc(this, WEP_FIREBALL);
9 void W_Fireball_Explode(entity this, entity directhitentity)
17 this.event_damage = func_null;
18 this.takedamage = DAMAGE_NO;
21 d = (this.realowner.health + this.realowner.armorvalue);
22 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, directhitentity);
23 if (this.realowner.health + this.realowner.armorvalue >= d) {
25 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);
28 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
29 for (e = findradius(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain) {
30 if (e != this.realowner) {
31 if (e.takedamage == DAMAGE_AIM) {
32 if (!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) {
33 // can we see fireball?
34 traceline(e.origin + e.view_ofs, this.origin, MOVE_NORMAL, e);
35 if ( /* trace_startsolid || */ trace_fraction != 1) { // startsolid should be never happening anyway
38 // can we see player who shot fireball?
39 traceline(e.origin + e.view_ofs, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e);
40 if (trace_ent != this.realowner) {
41 if ( /* trace_startsolid || */ trace_fraction != 1) {
45 dist = vlen(this.origin - e.origin - e.view_ofs);
46 points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
50 dir = normalize(e.origin + e.view_ofs - this.origin);
52 if (accuracy_isgooddamage(this.realowner, e)) {
53 accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
56 Damage(e, this, this.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, this.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir);
57 Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1);
68 void W_Fireball_Explode_think(entity this)
70 W_Fireball_Explode(this, NULL);
73 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
75 W_Fireball_Explode(this, trigger);
78 void W_Fireball_TouchExplode(entity this, entity toucher)
80 PROJECTILE_TOUCH(this, toucher);
81 W_Fireball_Explode(this, toucher);
84 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
94 RandomSelection_Init();
95 for (e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain) {
96 if (e != this.realowner) {
97 if (e.takedamage == DAMAGE_AIM) {
98 if (!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) {
100 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
101 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
102 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
103 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
105 e.fireball_impactvec = p;
106 RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
112 if (RandomSelection_chosen_ent) {
113 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
114 d = damage + (edgedamage - damage) * (d / dist);
115 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
116 // trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
117 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
121 void W_Fireball_Think(entity this)
123 if (time > this.pushltime) {
125 this.projectiledeathtype |= HITTYPE_SPLASH;
126 W_Fireball_Explode(this, NULL);
130 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));
132 this.nextthink = time + 0.1;
135 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
137 if (this.health <= 0) {
141 if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) { // no exceptions
142 return; // g_projectiles_damage says to halt
144 this.health = this.health - damage;
145 if (this.health <= 0) {
147 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
151 void W_Fireball_Attack1(entity actor, .entity weaponentity)
153 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));
155 Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
157 entity proj = new(plasma_prim);
158 proj.owner = proj.realowner = actor;
159 proj.bot_dodge = true;
160 proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
161 proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
162 proj.use = W_Fireball_Explode_use;
163 setthink(proj, W_Fireball_Think);
164 proj.nextthink = time;
165 proj.health = WEP_CVAR_PRI(fireball, health);
166 proj.team = actor.team;
167 proj.event_damage = W_Fireball_Damage;
168 proj.takedamage = DAMAGE_YES;
169 proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
170 PROJECTILE_MAKETRIGGER(proj);
171 proj.projectiledeathtype = WEP_FIREBALL.m_id;
172 setorigin(proj, w_shotorg);
174 set_movetype(proj, MOVETYPE_FLY);
175 W_SetupProjVelocity_PRI(proj, fireball);
176 proj.angles = vectoangles(proj.velocity);
177 settouch(proj, W_Fireball_TouchExplode);
178 setsize(proj, '-16 -16 -16', '16 16 16');
179 proj.flags = FL_PROJECTILE;
180 IL_PUSH(g_projectiles, proj);
181 IL_PUSH(g_bot_dodge, proj);
182 proj.missile_flags = MIF_SPLASH | MIF_PROXY;
184 CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
186 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
189 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
191 W_SetupShot_ProjectileSize(actor, weaponentity, '-16 -16 -16', '16 16 16', false, 0, SND_Null, 0, 0);
192 w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
193 Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
196 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
198 W_Fireball_Attack1(actor, weaponentity);
199 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
202 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
204 W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
205 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
208 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
210 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
211 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
214 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
216 W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
217 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
220 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
222 W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
223 sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
224 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
227 void W_Fireball_Firemine_Think(entity this)
229 if (time > this.pushltime) {
234 // make it "hot" once it leaves its owner
236 if (vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius))) {
246 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));
248 this.nextthink = time + 0.1;
251 void W_Fireball_Firemine_Touch(entity this, entity toucher)
253 PROJECTILE_TOUCH(this, toucher);
254 if (toucher.takedamage == DAMAGE_AIM) {
255 if (Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0) {
260 this.projectiledeathtype |= HITTYPE_BOUNCE;
263 void W_Fireball_Attack2(entity actor, .entity weaponentity)
269 c = actor.(weaponentity).bulletcounter % 4;
272 f_diff = '-1.25 -3.75 0';
275 f_diff = '+1.25 -3.75 0';
278 f_diff = '-1.25 +3.75 0';
282 f_diff = '+1.25 +3.75 0';
285 W_SetupShot_ProjectileSize(actor, weaponentity, '-4 -4 -4', '4 4 4', false, 2, SND_FIREBALL_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(fireball, damage));
286 traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
287 w_shotorg = trace_endpos;
289 Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
292 proj.owner = proj.realowner = actor;
293 proj.bot_dodge = true;
294 proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
295 set_movetype(proj, MOVETYPE_BOUNCE);
296 proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
297 settouch(proj, W_Fireball_Firemine_Touch);
298 PROJECTILE_MAKETRIGGER(proj);
299 setsize(proj, '-4 -4 -4', '4 4 4');
300 setorigin(proj, w_shotorg);
301 setthink(proj, W_Fireball_Firemine_Think);
302 proj.nextthink = time;
303 proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
304 proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
305 W_SetupProjVelocity_UP_SEC(proj, fireball);
307 proj.angles = vectoangles(proj.velocity);
308 proj.flags = FL_PROJECTILE;
309 IL_PUSH(g_projectiles, proj);
310 IL_PUSH(g_bot_dodge, proj);
311 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
313 CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
315 MUTATOR_CALLHOOK(EditProjectile, actor, proj);
318 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
320 PHYS_INPUT_BUTTON_ATCK(actor) = false;
321 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
322 if (actor.bot_primary_fireballmooth == 0) {
323 if (bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false)) {
324 PHYS_INPUT_BUTTON_ATCK(actor) = true;
325 if (random() < 0.02) { actor.bot_primary_fireballmooth = 0; }
328 if (bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true)) {
329 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
330 if (random() < 0.01) { actor.bot_primary_fireballmooth = 1; }
334 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
337 if (time >= actor.(weaponentity).fireball_primarytime) {
338 if (weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire))) {
339 W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
340 actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
343 } else if (fire & 2) {
344 if (weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire))) {
345 W_Fireball_Attack2(actor, weaponentity);
346 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
350 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
352 return true; // infinite ammo
354 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
356 return true; // fireball has infinite ammo
358 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
360 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) {
361 .entity weaponentity = weaponentities[slot];
362 actor.(weaponentity).fireball_primarytime = time;
365 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
367 if (w_deathtype & HITTYPE_SECONDARY) {
368 return WEAPON_FIREBALL_SUICIDE_FIREMINE;
370 return WEAPON_FIREBALL_SUICIDE_BLAST;
373 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
375 if (w_deathtype & HITTYPE_SECONDARY) {
376 return WEAPON_FIREBALL_MURDER_FIREMINE;
378 return WEAPON_FIREBALL_MURDER_BLAST;
385 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
388 if (w_deathtype & HITTYPE_SECONDARY) {
389 // 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