]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
d658c8b8049efecc6f756594f4ab13f946e76742
[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 = (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)
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, 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, 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);
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, .entity weaponentity, vector hitloc, vector force)
121 {
122         if(GetResource(this, RES_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         TakeResource(this, RES_HEALTH, damage);
129         if(GetResource(this, RES_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), WEP_FIREBALL.m_id);
139
140         W_MuzzleFlash(actor, weaponentity, EFFECT_FIREBALL_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir * 1000);
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         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);
159
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;
169
170         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
171
172         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
173 }
174
175 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
176 {
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 * 1000);
180 }
181
182 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
183 {
184         W_Fireball_Attack1(actor, weaponentity);
185         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
186 }
187
188 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
189 {
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);
192 }
193
194 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
195 {
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);
198 }
199
200 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
201 {
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);
204 }
205
206 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
207 {
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);
211 }
212
213 void W_Fireball_Firemine_Think(entity this)
214 {
215         if(time > this.pushltime)
216         {
217                 delete(this);
218                 return;
219         }
220
221         // make it "hot" once it leaves its owner
222         if(this.owner)
223         {
224                 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
225                 {
226                         this.cnt += 1;
227                         if(this.cnt == 3)
228                                 this.owner = NULL;
229                 }
230                 else
231                         this.cnt = 0;
232         }
233
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));
235
236         this.nextthink = time + 0.1;
237 }
238
239 void W_Fireball_Firemine_Touch(entity this, entity toucher)
240 {
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)
244         {
245                 delete(this);
246                 return;
247         }
248         this.projectiledeathtype |= HITTYPE_BOUNCE;
249 }
250
251 void W_Fireball_Attack2(entity actor, .entity weaponentity)
252 {
253         entity proj;
254         vector f_diff;
255         float c;
256
257         c = actor.(weaponentity).bulletcounter % 4;
258         switch(c)
259         {
260                 case 0:
261                         f_diff = '-1.25 -3.75 0';
262                         break;
263                 case 1:
264                         f_diff = '+1.25 -3.75 0';
265                         break;
266                 case 2:
267                         f_diff = '-1.25 +3.75 0';
268                         break;
269                 case 3:
270                 default:
271                         f_diff = '+1.25 +3.75 0';
272                         break;
273         }
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;
277
278         W_MuzzleFlash(actor, weaponentity, EFFECT_FIREBALL_MUZZLEFLASH, MDL_Null, w_shotorg, w_shotdir * 1000);
279
280         proj = new(grenade);
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);
295
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;
301
302         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
303
304         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
305 }
306
307 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
308 {
309     PHYS_INPUT_BUTTON_ATCK(actor) = false;
310     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
311     if(actor.bot_primary_fireballmooth == 0)
312     {
313         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
314         {
315             PHYS_INPUT_BUTTON_ATCK(actor) = true;
316             if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
317         }
318     }
319     else
320     {
321         if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
322         {
323             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
324             if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
325         }
326     }
327 }
328 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
329 {
330     if(fire & 1)
331     {
332         if(time >= actor.(weaponentity).fireball_primarytime)
333         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
334         {
335             W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
336             actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
337         }
338     }
339     else if(fire & 2)
340     {
341         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
342         {
343             W_Fireball_Attack2(actor, weaponentity);
344             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
345         }
346     }
347 }
348 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
349 {
350     return true; // infinite ammo
351 }
352 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
353 {
354     return true; // fireball has infinite ammo
355 }
356 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
357 {
358         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
359         {
360                 .entity weaponentity = weaponentities[slot];
361         actor.(weaponentity).fireball_primarytime = time;
362         }
363 }
364 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
365 {
366     if(w_deathtype & HITTYPE_SECONDARY)
367         return WEAPON_FIREBALL_SUICIDE_FIREMINE;
368     else
369         return WEAPON_FIREBALL_SUICIDE_BLAST;
370 }
371 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
372 {
373     if(w_deathtype & HITTYPE_SECONDARY)
374         return WEAPON_FIREBALL_MURDER_FIREMINE;
375     else
376         return WEAPON_FIREBALL_MURDER_BLAST;
377 }
378
379 #endif
380 #ifdef CSQC
381
382 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
383 {
384     vector org2;
385     if(w_deathtype & HITTYPE_SECONDARY)
386     {
387         // firemine goes out silently
388     }
389     else
390     {
391         org2 = w_org + w_backoff * 16;
392         pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
393         if(!w_issilent)
394             sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom
395     }
396 }
397
398 #endif