]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
Merge branch 'master' into terencehill/min_spec_time
[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, this.weaponentity_fld, 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, 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(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), WEP_FIREBALL.m_id);
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         proj.weaponentity_fld = weaponentity;
158         proj.weaponentity_fld = weaponentity;
159         setorigin(proj, w_shotorg);
160
161         set_movetype(proj, MOVETYPE_FLY);
162         W_SetupProjVelocity_PRI(proj, fireball);
163         proj.angles = vectoangles(proj.velocity);
164         settouch(proj, W_Fireball_TouchExplode);
165         setsize(proj, '-16 -16 -16', '16 16 16');
166         proj.flags = FL_PROJECTILE;
167         IL_PUSH(g_projectiles, proj);
168         IL_PUSH(g_bot_dodge, proj);
169     proj.missile_flags = MIF_SPLASH | MIF_PROXY;
170
171         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
172
173         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
174 }
175
176 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
177 {
178         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
179         w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
180         Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
181 }
182
183 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
184 {
185         W_Fireball_Attack1(actor, weaponentity);
186         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
187 }
188
189 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
190 {
191         W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
192         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
193 }
194
195 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
196 {
197         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
198         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
199 }
200
201 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
202 {
203         W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
204         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
205 }
206
207 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
208 {
209         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
210         sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
211         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
212 }
213
214 void W_Fireball_Firemine_Think(entity this)
215 {
216         if(time > this.pushltime)
217         {
218                 delete(this);
219                 return;
220         }
221
222         // make it "hot" once it leaves its owner
223         if(this.owner)
224         {
225                 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
226                 {
227                         this.cnt += 1;
228                         if(this.cnt == 3)
229                                 this.owner = NULL;
230                 }
231                 else
232                         this.cnt = 0;
233         }
234
235         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));
236
237         this.nextthink = time + 0.1;
238 }
239
240 void W_Fireball_Firemine_Touch(entity this, entity toucher)
241 {
242         PROJECTILE_TOUCH(this, toucher);
243         if(toucher.takedamage == DAMAGE_AIM)
244         if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
245         {
246                 delete(this);
247                 return;
248         }
249         this.projectiledeathtype |= HITTYPE_BOUNCE;
250 }
251
252 void W_Fireball_Attack2(entity actor, .entity weaponentity)
253 {
254         entity proj;
255         vector f_diff;
256         float c;
257
258         c = actor.(weaponentity).bulletcounter % 4;
259         switch(c)
260         {
261                 case 0:
262                         f_diff = '-1.25 -3.75 0';
263                         break;
264                 case 1:
265                         f_diff = '+1.25 -3.75 0';
266                         break;
267                 case 2:
268                         f_diff = '-1.25 +3.75 0';
269                         break;
270                 case 3:
271                 default:
272                         f_diff = '+1.25 +3.75 0';
273                         break;
274         }
275         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);
276         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
277         w_shotorg = trace_endpos;
278
279         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
280
281         proj = new(grenade);
282         proj.owner = proj.realowner = actor;
283         proj.bot_dodge = true;
284         proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
285         set_movetype(proj, MOVETYPE_BOUNCE);
286         proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
287         settouch(proj, W_Fireball_Firemine_Touch);
288         PROJECTILE_MAKETRIGGER(proj);
289         setsize(proj, '-4 -4 -4', '4 4 4');
290         setorigin(proj, w_shotorg);
291         setthink(proj, W_Fireball_Firemine_Think);
292         proj.nextthink = time;
293         proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
294         proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
295         W_SetupProjVelocity_UP_SEC(proj, fireball);
296
297         proj.angles = vectoangles(proj.velocity);
298         proj.flags = FL_PROJECTILE;
299         IL_PUSH(g_projectiles, proj);
300         IL_PUSH(g_bot_dodge, proj);
301     proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
302
303         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
304
305         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
306 }
307
308 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
309 {
310     PHYS_INPUT_BUTTON_ATCK(actor) = false;
311     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
312     if(actor.bot_primary_fireballmooth == 0)
313     {
314         if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
315         {
316             PHYS_INPUT_BUTTON_ATCK(actor) = true;
317             if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
318         }
319     }
320     else
321     {
322         if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
323         {
324             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
325             if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
326         }
327     }
328 }
329 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
330 {
331     if(fire & 1)
332     {
333         if(time >= actor.(weaponentity).fireball_primarytime)
334         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
335         {
336             W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
337             actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
338         }
339     }
340     else if(fire & 2)
341     {
342         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
343         {
344             W_Fireball_Attack2(actor, weaponentity);
345             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
346         }
347     }
348 }
349 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
350 {
351     return true; // infinite ammo
352 }
353 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
354 {
355     return true; // fireball has infinite ammo
356 }
357 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
358 {
359         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
360         {
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 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
373 {
374     if(w_deathtype & HITTYPE_SECONDARY)
375         return WEAPON_FIREBALL_MURDER_FIREMINE;
376     else
377         return WEAPON_FIREBALL_MURDER_BLAST;
378 }
379
380 #endif
381 #ifdef CSQC
382
383 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
384 {
385     vector org2;
386     if(w_deathtype & HITTYPE_SECONDARY)
387     {
388         // firemine goes out silently
389     }
390     else
391     {
392         org2 = w_org + w_backoff * 16;
393         pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
394         if(!w_issilent)
395             sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom
396     }
397 }
398
399 #endif