]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
Push down spawning logic from spawnfuncs to dedicated spawning functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / fireball.qc
1 #include "fireball.qh"
2
3 #ifdef SVQC
4
5 void W_Fireball_Explode(entity this, entity directhitentity)
6 {
7         entity e;
8         float dist;
9         float points;
10         vector dir;
11         float d;
12
13         this.event_damage = func_null;
14         this.takedamage = DAMAGE_NO;
15
16         // 1. dist damage
17         d = (this.realowner.health + this.realowner.armorvalue);
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, directhitentity);
19         if(this.realowner.health + this.realowner.armorvalue >= d)
20         if(!this.cnt)
21         {
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);
23
24                 // 2. bfg effect
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))
28                 {
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
32                                 continue;
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)
37                                 continue;
38                         dist = vlen(this.origin - e.origin - e.view_ofs);
39                         points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
40                         if(points <= 0)
41                                 continue;
42                         dir = normalize(e.origin + e.view_ofs - this.origin);
43
44                         if(accuracy_isgooddamage(this.realowner, e))
45                                 accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
46
47                         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);
48                         Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1);
49                 }
50         }
51
52         delete(this);
53 }
54
55 void W_Fireball_Explode_think(entity this)
56 {
57         W_Fireball_Explode(this, NULL);
58 }
59
60 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
61 {
62         W_Fireball_Explode(this, trigger);
63 }
64
65 void W_Fireball_TouchExplode(entity this, entity toucher)
66 {
67         PROJECTILE_TOUCH(this, toucher);
68         W_Fireball_Explode(this, toucher);
69 }
70
71 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
72 {
73         entity e;
74         float d;
75         vector p;
76
77         if(damage <= 0)
78                 return;
79
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))
83         {
84                 p = e.origin;
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);
89                 if(d < dist)
90                 {
91                         e.fireball_impactvec = p;
92                         RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
93                 }
94         }
95         if(RandomSelection_chosen_ent)
96         {
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);
102         }
103 }
104
105 void W_Fireball_Think(entity this)
106 {
107         if(time > this.pushltime)
108         {
109                 this.cnt = 1;
110                 this.projectiledeathtype |= HITTYPE_SPLASH;
111                 W_Fireball_Explode(this, NULL);
112                 return;
113         }
114
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));
116
117         this.nextthink = time + 0.1;
118 }
119
120 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
121 {
122         if(this.health <= 0)
123                 return;
124
125         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
126                 return; // g_projectiles_damage says to halt
127
128         this.health = this.health - damage;
129         if(this.health <= 0)
130         {
131                 this.cnt = 1;
132                 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
133         }
134 }
135
136 void W_Fireball_Attack1(entity actor, .entity weaponentity)
137 {
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));
139
140         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
141
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         proj.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         setorigin(proj, w_shotorg);
158
159         set_movetype(proj, MOVETYPE_FLY);
160         W_SetupProjVelocity_PRI(proj, fireball);
161         proj.angles = vectoangles(proj.velocity);
162         settouch(proj, W_Fireball_TouchExplode);
163         setsize(proj, '-16 -16 -16', '16 16 16');
164         proj.flags = FL_PROJECTILE;
165         IL_PUSH(g_projectiles, proj);
166         IL_PUSH(g_bot_dodge, proj);
167     proj.missile_flags = MIF_SPLASH | MIF_PROXY;
168
169         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
170
171         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
172 }
173
174 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
175 {
176         W_SetupShot_ProjectileSize(actor, weaponentity, '-16 -16 -16', '16 16 16', false, 0, SND_Null, 0, 0);
177         w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
178         Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
179 }
180
181 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
182 {
183         W_Fireball_Attack1(actor, weaponentity);
184         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
185 }
186
187 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
188 {
189         W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
190         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
191 }
192
193 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
194 {
195         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
196         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
197 }
198
199 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
200 {
201         W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
202         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
203 }
204
205 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
206 {
207         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
208         sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
209         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
210 }
211
212 void W_Fireball_Firemine_Think(entity this)
213 {
214         if(time > this.pushltime)
215         {
216                 delete(this);
217                 return;
218         }
219
220         // make it "hot" once it leaves its owner
221         if(this.owner)
222         {
223                 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
224                 {
225                         this.cnt += 1;
226                         if(this.cnt == 3)
227                                 this.owner = NULL;
228                 }
229                 else
230                         this.cnt = 0;
231         }
232
233         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));
234
235         this.nextthink = time + 0.1;
236 }
237
238 void W_Fireball_Firemine_Touch(entity this, entity toucher)
239 {
240         PROJECTILE_TOUCH(this, toucher);
241         if(toucher.takedamage == DAMAGE_AIM)
242         if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
243         {
244                 delete(this);
245                 return;
246         }
247         this.projectiledeathtype |= HITTYPE_BOUNCE;
248 }
249
250 void W_Fireball_Attack2(entity actor, .entity weaponentity)
251 {
252         entity proj;
253         vector f_diff;
254         float c;
255
256         c = actor.(weaponentity).bulletcounter % 4;
257         switch(c)
258         {
259                 case 0:
260                         f_diff = '-1.25 -3.75 0';
261                         break;
262                 case 1:
263                         f_diff = '+1.25 -3.75 0';
264                         break;
265                 case 2:
266                         f_diff = '-1.25 +3.75 0';
267                         break;
268                 case 3:
269                 default:
270                         f_diff = '+1.25 +3.75 0';
271                         break;
272         }
273         W_SetupShot_ProjectileSize(actor, weaponentity, '-4 -4 -4', '4 4 4', false, 2, SND_FIREBALL_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(fireball, damage));
274         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
275         w_shotorg = trace_endpos;
276
277         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
278
279         proj = new(grenade);
280         proj.owner = proj.realowner = actor;
281         proj.bot_dodge = true;
282         proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
283         set_movetype(proj, MOVETYPE_BOUNCE);
284         proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
285         settouch(proj, W_Fireball_Firemine_Touch);
286         PROJECTILE_MAKETRIGGER(proj);
287         setsize(proj, '-4 -4 -4', '4 4 4');
288         setorigin(proj, w_shotorg);
289         setthink(proj, W_Fireball_Firemine_Think);
290         proj.nextthink = time;
291         proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
292         proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
293         W_SetupProjVelocity_UP_SEC(proj, fireball);
294
295         proj.angles = vectoangles(proj.velocity);
296         proj.flags = FL_PROJECTILE;
297         IL_PUSH(g_projectiles, proj);
298         IL_PUSH(g_bot_dodge, proj);
299     proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
300
301         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
302
303         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
304 }
305
306 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
307 {
308     PHYS_INPUT_BUTTON_ATCK(actor) = false;
309     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
310     if(actor.bot_primary_fireballmooth == 0)
311     {
312         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
313         {
314             PHYS_INPUT_BUTTON_ATCK(actor) = true;
315             if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
316         }
317     }
318     else
319     {
320         if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
321         {
322             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
323             if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
324         }
325     }
326 }
327 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
328 {
329     if(fire & 1)
330     {
331         if(time >= actor.(weaponentity).fireball_primarytime)
332         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
333         {
334             W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
335             actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
336         }
337     }
338     else if(fire & 2)
339     {
340         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
341         {
342             W_Fireball_Attack2(actor, weaponentity);
343             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
344         }
345     }
346 }
347 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
348 {
349     return true; // infinite ammo
350 }
351 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
352 {
353     return true; // fireball has infinite ammo
354 }
355 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
356 {
357         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
358         {
359                 .entity weaponentity = weaponentities[slot];
360         actor.(weaponentity).fireball_primarytime = time;
361         }
362 }
363 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
364 {
365     if(w_deathtype & HITTYPE_SECONDARY)
366         return WEAPON_FIREBALL_SUICIDE_FIREMINE;
367     else
368         return WEAPON_FIREBALL_SUICIDE_BLAST;
369 }
370 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
371 {
372     if(w_deathtype & HITTYPE_SECONDARY)
373         return WEAPON_FIREBALL_MURDER_FIREMINE;
374     else
375         return WEAPON_FIREBALL_MURDER_BLAST;
376 }
377
378 #endif
379 #ifdef CSQC
380
381 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
382 {
383     vector org2;
384     if(w_deathtype & HITTYPE_SECONDARY)
385     {
386         // firemine goes out silently
387     }
388     else
389     {
390         org2 = w_org + w_backoff * 16;
391         pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
392         if(!w_issilent)
393             sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom
394     }
395 }
396
397 #endif