]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
5049f885bd9637721bfd50e5087ad2b17fbe793f
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / fireball.qc
1 #include "fireball.qh"
2
3 #ifdef SVQC
4 spawnfunc(weapon_fireball)
5 {
6         weapon_defaultspawnfunc(this, WEP_FIREBALL);
7 }
8
9 void W_Fireball_Explode(entity this, entity directhitentity)
10 {
11         entity e;
12         float dist;
13         float points;
14         vector dir;
15         float d;
16
17         this.event_damage = func_null;
18         this.takedamage = DAMAGE_NO;
19
20         // 1. dist damage
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) {
24                 if (!this.cnt) {
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);
26
27                         // 2. bfg effect
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
36                                                                 continue;
37                                                         }
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) {
42                                                                         continue;
43                                                                 }
44                                                         }
45                                                         dist = vlen(this.origin - e.origin - e.view_ofs);
46                                                         points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
47                                                         if (points <= 0) {
48                                                                 continue;
49                                                         }
50                                                         dir = normalize(e.origin + e.view_ofs - this.origin);
51
52                                                         if (accuracy_isgooddamage(this.realowner, e)) {
53                                                                 accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
54                                                         }
55
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);
58                                                 }
59                                         }
60                                 }
61                         }
62                 }
63         }
64
65         delete(this);
66 }
67
68 void W_Fireball_Explode_think(entity this)
69 {
70         W_Fireball_Explode(this, NULL);
71 }
72
73 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
74 {
75         W_Fireball_Explode(this, trigger);
76 }
77
78 void W_Fireball_TouchExplode(entity this, entity toucher)
79 {
80         PROJECTILE_TOUCH(this, toucher);
81         W_Fireball_Explode(this, toucher);
82 }
83
84 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
85 {
86         entity e;
87         float d;
88         vector p;
89
90         if (damage <= 0) {
91                 return;
92         }
93
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)) {
99                                         p = e.origin;
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);
104                                         if (d < dist) {
105                                                 e.fireball_impactvec = p;
106                                                 RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e));
107                                         }
108                                 }
109                         }
110                 }
111         }
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);
118         }
119 }
120
121 void W_Fireball_Think(entity this)
122 {
123         if (time > this.pushltime) {
124                 this.cnt = 1;
125                 this.projectiledeathtype |= HITTYPE_SPLASH;
126                 W_Fireball_Explode(this, NULL);
127                 return;
128         }
129
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));
131
132         this.nextthink = time + 0.1;
133 }
134
135 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
136 {
137         if (this.health <= 0) {
138                 return;
139         }
140
141         if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) { // no exceptions
142                 return; // g_projectiles_damage says to halt
143         }
144         this.health = this.health - damage;
145         if (this.health <= 0) {
146                 this.cnt = 1;
147                 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
148         }
149 }
150
151 void W_Fireball_Attack1(entity actor, .entity weaponentity)
152 {
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));
154
155         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
156
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);
173
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;
183
184         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
185
186         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
187 }
188
189 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
190 {
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);
194 }
195
196 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
197 {
198         W_Fireball_Attack1(actor, weaponentity);
199         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
200 }
201
202 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
203 {
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);
206 }
207
208 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
209 {
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);
212 }
213
214 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
215 {
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);
218 }
219
220 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
221 {
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);
225 }
226
227 void W_Fireball_Firemine_Think(entity this)
228 {
229         if (time > this.pushltime) {
230                 delete(this);
231                 return;
232         }
233
234         // make it "hot" once it leaves its owner
235         if (this.owner) {
236                 if (vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius))) {
237                         this.cnt += 1;
238                         if (this.cnt == 3) {
239                                 this.owner = NULL;
240                         }
241                 } else {
242                         this.cnt = 0;
243                 }
244         }
245
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));
247
248         this.nextthink = time + 0.1;
249 }
250
251 void W_Fireball_Firemine_Touch(entity this, entity toucher)
252 {
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) {
256                         delete(this);
257                         return;
258                 }
259         }
260         this.projectiledeathtype |= HITTYPE_BOUNCE;
261 }
262
263 void W_Fireball_Attack2(entity actor, .entity weaponentity)
264 {
265         entity proj;
266         vector f_diff;
267         float c;
268
269         c = actor.(weaponentity).bulletcounter % 4;
270         switch (c) {
271                 case 0:
272                         f_diff = '-1.25 -3.75 0';
273                         break;
274                 case 1:
275                         f_diff = '+1.25 -3.75 0';
276                         break;
277                 case 2:
278                         f_diff = '-1.25 +3.75 0';
279                         break;
280                 case 3:
281                 default:
282                         f_diff = '+1.25 +3.75 0';
283                         break;
284         }
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;
288
289         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
290
291         proj = new(grenade);
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);
306
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;
312
313         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
314
315         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
316 }
317
318 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
319 {
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; }
326                 }
327         } else {
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; }
331                 }
332         }
333 }
334 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
335 {
336         if (fire & 1) {
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);
341                         }
342                 }
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);
347                 }
348         }
349 }
350 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
351 {
352         return true; // infinite ammo
353 }
354 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
355 {
356         return true; // fireball has infinite ammo
357 }
358 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
359 {
360         for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) {
361                 .entity weaponentity = weaponentities[slot];
362                 actor.(weaponentity).fireball_primarytime = time;
363         }
364 }
365 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
366 {
367         if (w_deathtype & HITTYPE_SECONDARY) {
368                 return WEAPON_FIREBALL_SUICIDE_FIREMINE;
369         } else {
370                 return WEAPON_FIREBALL_SUICIDE_BLAST;
371         }
372 }
373 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
374 {
375         if (w_deathtype & HITTYPE_SECONDARY) {
376                 return WEAPON_FIREBALL_MURDER_FIREMINE;
377         } else {
378                 return WEAPON_FIREBALL_MURDER_BLAST;
379         }
380 }
381
382 #endif
383 #ifdef CSQC
384
385 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
386 {
387         vector org2;
388         if (w_deathtype & HITTYPE_SECONDARY) {
389                 // firemine goes out silently
390         } else {
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
399 #endif