]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
Electro: remove leftover code from wr_resetplayer that now doesn't work as intended
[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         {
83                 if(e == this.realowner) continue;
84                 if(e.takedamage != DAMAGE_AIM) continue;
85                 if(IS_PLAYER(e) && this.realowner && SAME_TEAM(e, this)) continue;
86
87                 p = e.origin;
88                 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
89                 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
90                 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
91                 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
92                 if(d < dist)
93                 {
94                         e.fireball_impactvec = p;
95                         RandomSelection_AddEnt(e, 1 / (1 + d), !StatusEffects_active(STATUSEFFECT_Burning, e));
96                 }
97         }
98         if(RandomSelection_chosen_ent)
99         {
100                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
101                 d = damage + (edgedamage - damage) * (d / dist);
102                 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
103                 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
104                 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
105         }
106 }
107
108 void W_Fireball_Think(entity this)
109 {
110         if(time > this.pushltime)
111         {
112                 this.cnt = 1;
113                 this.projectiledeathtype |= HITTYPE_SPLASH;
114                 W_Fireball_Explode(this, NULL);
115                 return;
116         }
117
118         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));
119
120         this.nextthink = time + 0.1;
121 }
122
123 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
124 {
125         if(GetResource(this, RES_HEALTH) <= 0)
126                 return;
127
128         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
129                 return; // g_projectiles_damage says to halt
130
131         TakeResource(this, RES_HEALTH, damage);
132         if(GetResource(this, RES_HEALTH) <= 0)
133         {
134                 this.cnt = 1;
135                 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
136         }
137 }
138
139 void W_Fireball_Attack1(entity actor, .entity weaponentity)
140 {
141         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);
142
143         W_MuzzleFlash(WEP_FIREBALL, actor, weaponentity, w_shotorg, w_shotdir);
144
145         entity proj = new(plasma_prim);
146         proj.owner = proj.realowner = actor;
147         proj.bot_dodge = true;
148         proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
149         proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
150         proj.use = W_Fireball_Explode_use;
151         setthink(proj, W_Fireball_Think);
152         proj.nextthink = time;
153         SetResourceExplicit(proj, RES_HEALTH, WEP_CVAR_PRI(fireball, health));
154         proj.team = actor.team;
155         proj.event_damage = W_Fireball_Damage;
156         proj.takedamage = DAMAGE_YES;
157         proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
158         PROJECTILE_MAKETRIGGER(proj);
159         proj.projectiledeathtype = WEP_FIREBALL.m_id;
160         proj.weaponentity_fld = weaponentity;
161         setorigin(proj, w_shotorg);
162
163         set_movetype(proj, MOVETYPE_FLY);
164         W_SetupProjVelocity_PRI(proj, fireball);
165         proj.angles = vectoangles(proj.velocity);
166         settouch(proj, W_Fireball_TouchExplode);
167         setsize(proj, '-16 -16 -16', '16 16 16');
168         proj.flags = FL_PROJECTILE;
169         IL_PUSH(g_projectiles, proj);
170         IL_PUSH(g_bot_dodge, proj);
171         proj.missile_flags = MIF_SPLASH | MIF_PROXY;
172
173         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
174
175         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
176 }
177
178 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
179 {
180         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
181         w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
182         Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
183 }
184
185 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
186 {
187         W_Fireball_Attack1(actor, weaponentity);
188         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
189 }
190
191 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
192 {
193         W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
194         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
195 }
196
197 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
198 {
199         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
200         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
201 }
202
203 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
204 {
205         W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
206         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
207 }
208
209 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
210 {
211         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
212         sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
213         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
214 }
215
216 void W_Fireball_Firemine_Think(entity this)
217 {
218         if(time > this.pushltime)
219         {
220                 delete(this);
221                 return;
222         }
223
224         // make it "hot" once it leaves its owner
225         if(this.owner)
226         {
227                 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
228                 {
229                         this.cnt += 1;
230                         if(this.cnt == 3)
231                                 this.owner = NULL;
232                 }
233                 else
234                         this.cnt = 0;
235         }
236
237         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));
238
239         this.nextthink = time + 0.1;
240 }
241
242 void W_Fireball_Firemine_Touch(entity this, entity toucher)
243 {
244         PROJECTILE_TOUCH(this, toucher);
245         if(toucher.takedamage == DAMAGE_AIM)
246         if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
247         {
248                 delete(this);
249                 return;
250         }
251         this.projectiledeathtype |= HITTYPE_BOUNCE;
252 }
253
254 void W_Fireball_Attack2(entity actor, .entity weaponentity)
255 {
256         entity proj;
257         vector f_diff;
258         float c;
259
260         c = actor.(weaponentity).bulletcounter % 4;
261         switch(c)
262         {
263                 case 0:
264                         f_diff = '-1.25 -3.75 0';
265                         break;
266                 case 1:
267                         f_diff = '+1.25 -3.75 0';
268                         break;
269                 case 2:
270                         f_diff = '-1.25 +3.75 0';
271                         break;
272                 case 3:
273                 default:
274                         f_diff = '+1.25 +3.75 0';
275                         break;
276         }
277         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);
278         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
279         w_shotorg = trace_endpos;
280
281         W_MuzzleFlash(WEP_FIREBALL, actor, weaponentity, w_shotorg, w_shotdir);
282
283         proj = new(grenade);
284         proj.owner = proj.realowner = actor;
285         proj.bot_dodge = true;
286         proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
287         set_movetype(proj, MOVETYPE_BOUNCE);
288         proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
289         settouch(proj, W_Fireball_Firemine_Touch);
290         PROJECTILE_MAKETRIGGER(proj);
291         setsize(proj, '-4 -4 -4', '4 4 4');
292         setorigin(proj, w_shotorg);
293         setthink(proj, W_Fireball_Firemine_Think);
294         proj.nextthink = time;
295         proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
296         proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
297         W_SetupProjVelocity_UP_SEC(proj, fireball);
298
299         proj.angles = vectoangles(proj.velocity);
300         proj.flags = FL_PROJECTILE;
301         IL_PUSH(g_projectiles, proj);
302         IL_PUSH(g_bot_dodge, proj);
303         proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
304
305         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
306
307         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
308 }
309
310 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
311 {
312     PHYS_INPUT_BUTTON_ATCK(actor) = false;
313     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
314     if(actor.bot_primary_fireballmooth == 0)
315     {
316         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
317         {
318             PHYS_INPUT_BUTTON_ATCK(actor) = true;
319             if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
320         }
321     }
322     else
323     {
324         if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
325         {
326             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
327             if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
328         }
329     }
330 }
331 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
332 {
333     if(fire & 1)
334     {
335         if(time >= actor.(weaponentity).fireball_primarytime)
336         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
337         {
338             W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
339             actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
340         }
341     }
342     else if(fire & 2)
343     {
344         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
345         {
346             W_Fireball_Attack2(actor, weaponentity);
347             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
348         }
349     }
350 }
351 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
352 {
353     return true; // infinite ammo
354 }
355 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
356 {
357     return true; // fireball has infinite ammo
358 }
359 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
360 {
361         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
362         {
363                 .entity weaponentity = weaponentities[slot];
364         actor.(weaponentity).fireball_primarytime = time;
365         }
366 }
367 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
368 {
369     if(w_deathtype & HITTYPE_SECONDARY)
370         return WEAPON_FIREBALL_SUICIDE_FIREMINE;
371     else
372         return WEAPON_FIREBALL_SUICIDE_BLAST;
373 }
374 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
375 {
376     if(w_deathtype & HITTYPE_SECONDARY)
377         return WEAPON_FIREBALL_MURDER_FIREMINE;
378     else
379         return WEAPON_FIREBALL_MURDER_BLAST;
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     {
390         // firemine goes out silently
391     }
392     else
393     {
394         org2 = w_org + w_backoff * 16;
395         pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
396         if(!w_issilent)
397             sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom
398     }
399 }
400
401 #endif