]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
3f9cd4c4e18f6d731d2d7db54764b983ceb8ec0e
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / fireball.qc
1 #include "fireball.qh"
2
3 #ifdef SVQC
4 spawnfunc(weapon_fireball) { weapon_defaultspawnfunc(this, WEP_FIREBALL); }
5
6 void W_Fireball_Explode(entity this, entity directhitentity)
7 {
8         entity e;
9         float dist;
10         float points;
11         vector dir;
12         float d;
13
14         this.event_damage = func_null;
15         this.takedamage = DAMAGE_NO;
16
17         // 1. dist damage
18         d = (this.realowner.health + this.realowner.armorvalue);
19         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);
20         if(this.realowner.health + this.realowner.armorvalue >= d)
21         if(!this.cnt)
22         {
23                 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);
24
25                 // 2. bfg effect
26                 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
27                 for(e = findradius(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain)
28                 if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
29                 {
30                         // can we see fireball?
31                         traceline(e.origin + e.view_ofs, this.origin, MOVE_NORMAL, e);
32                         if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
33                                 continue;
34                         // can we see player who shot fireball?
35                         traceline(e.origin + e.view_ofs, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e);
36                         if(trace_ent != this.realowner)
37                         if(/* trace_startsolid || */ trace_fraction != 1)
38                                 continue;
39                         dist = vlen(this.origin - e.origin - e.view_ofs);
40                         points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
41                         if(points <= 0)
42                                 continue;
43                         dir = normalize(e.origin + e.view_ofs - this.origin);
44
45                         if(accuracy_isgooddamage(this.realowner, e))
46                                 accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
47
48                         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);
49                         Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1);
50                 }
51         }
52
53         delete(this);
54 }
55
56 void W_Fireball_Explode_think(entity this)
57 {
58         W_Fireball_Explode(this, NULL);
59 }
60
61 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
62 {
63         W_Fireball_Explode(this, trigger);
64 }
65
66 void W_Fireball_TouchExplode(entity this, entity toucher)
67 {
68         PROJECTILE_TOUCH(this, toucher);
69         W_Fireball_Explode(this, toucher);
70 }
71
72 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
73 {
74         entity e;
75         float d;
76         vector p;
77
78         if(damage <= 0)
79                 return;
80
81         RandomSelection_Init();
82         for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
83         if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
84         {
85                 p = e.origin;
86                 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
87                 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
88                 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
89                 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
90                 if(d < dist)
91                 {
92                         e.fireball_impactvec = p;
93                         RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
94                 }
95         }
96         if(RandomSelection_chosen_ent)
97         {
98                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
99                 d = damage + (edgedamage - damage) * (d / dist);
100                 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
101                 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
102                 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
103         }
104 }
105
106 void W_Fireball_Think(entity this)
107 {
108         if(time > this.pushltime)
109         {
110                 this.cnt = 1;
111                 this.projectiledeathtype |= HITTYPE_SPLASH;
112                 W_Fireball_Explode(this, NULL);
113                 return;
114         }
115
116         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
118         this.nextthink = time + 0.1;
119 }
120
121 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
122 {
123         if(this.health <= 0)
124                 return;
125
126         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
127                 return; // g_projectiles_damage says to halt
128
129         this.health = this.health - damage;
130         if(this.health <= 0)
131         {
132                 this.cnt = 1;
133                 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
134         }
135 }
136
137 void W_Fireball_Attack1(entity actor, .entity weaponentity)
138 {
139         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));
140
141         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
142
143         entity proj = new(plasma_prim);
144         proj.owner = proj.realowner = actor;
145         proj.bot_dodge = true;
146         proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
147         proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
148         proj.use = W_Fireball_Explode_use;
149         setthink(proj, W_Fireball_Think);
150         proj.nextthink = time;
151         proj.health = WEP_CVAR_PRI(fireball, health);
152         proj.team = actor.team;
153         proj.event_damage = W_Fireball_Damage;
154         proj.takedamage = DAMAGE_YES;
155         proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
156         PROJECTILE_MAKETRIGGER(proj);
157         proj.projectiledeathtype = WEP_FIREBALL.m_id;
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);
178         w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
179         Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
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));
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         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
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