]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_fireball.qc
Move tuba, seeker, rifle, port, nex, hook, hlac, hagar, fireball, devastator & crylin...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_fireball.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ FIREBALL,
4 /* function */ w_fireball,
5 /* ammotype */ 0,
6 /* impulse  */ 9,
7 /* flags    */ WEP_FLAG_SUPERWEAPON | WEP_TYPE_SPLASH,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* model    */ "fireball",
10 /* netname  */ "fireball",
11 /* fullname */ _("Fireball")
12 );
13
14 #define FIREBALL_SETTINGS(w_cvar,w_prop) \
15         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, animtime) \
16         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, refire) \
17         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, damage) \
18         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, damageforcescale) \
19         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, speed) \
20         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, lifetime) \
21         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, laserburntime) \
22         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, laserdamage) \
23         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, laseredgedamage) \
24         w_cvar(WEP_FIREBALL, fireball, MO_BOTH, laserradius) \
25         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  edgedamage) \
26         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  force) \
27         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  radius) \
28         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  health) \
29         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  refire2) \
30         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  bfgdamage) \
31         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  bfgforce) \
32         w_cvar(WEP_FIREBALL, fireball, MO_PRI,  bfgradius) \
33         w_cvar(WEP_FIREBALL, fireball, MO_SEC,  damagetime) \
34         w_cvar(WEP_FIREBALL, fireball, MO_SEC,  speed_up) \
35         w_prop(WEP_FIREBALL, fireball, reloading_ammo, reload_ammo) \
36         w_prop(WEP_FIREBALL, fireball, reloading_time, reload_time) \
37         w_prop(WEP_FIREBALL, fireball, switchdelay_raise, switchdelay_raise) \
38         w_prop(WEP_FIREBALL, fireball, switchdelay_drop, switchdelay_drop)
39
40 #ifdef SVQC
41 FIREBALL_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
42 .float bot_primary_fireballmooth; // whatever a mooth is
43 .vector fireball_impactvec;
44 .float fireball_primarytime;
45 #endif
46 #else
47 #ifdef SVQC
48 void spawnfunc_weapon_fireball() { weapon_defaultspawnfunc(WEP_FIREBALL); }
49
50 void W_Fireball_Explode (void)
51 {
52         entity e;
53         float dist;
54         float points;
55         vector dir;
56         float d;
57
58         self.event_damage = func_null;
59         self.takedamage = DAMAGE_NO;
60
61         // 1. dist damage
62         d = (self.realowner.health + self.realowner.armorvalue);
63         RadiusDamage (self, self.realowner, WEP_CVAR_PRI(fireball, damage), WEP_CVAR_PRI(fireball, edgedamage), WEP_CVAR_PRI(fireball, radius), world, world, WEP_CVAR_PRI(fireball, force), self.projectiledeathtype, other);
64         if(self.realowner.health + self.realowner.armorvalue >= d)
65         if(!self.cnt)
66         {
67                 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, self.origin, '0 0 0', '0 0 0', '0 0 0', 0, WEP_CVAR_PRI(fireball, bfgradius), 0.2, 0.05, 0.25);
68
69                 // 2. bfg effect
70                 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
71                 for(e = findradius(self.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain)
72                 if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
73                 {
74                         // can we see fireball?
75                         traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
76                         if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
77                                 continue;
78                         // can we see player who shot fireball?
79                         traceline(e.origin + e.view_ofs, self.realowner.origin + self.realowner.view_ofs, MOVE_NORMAL, e);
80                         if(trace_ent != self.realowner)
81                         if(/* trace_startsolid || */ trace_fraction != 1)
82                                 continue;
83                         dist = vlen(self.origin - e.origin - e.view_ofs);
84                         points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius)));
85                         if(points <= 0)
86                                 continue;
87                         dir = normalize(e.origin + e.view_ofs - self.origin);
88
89                         if(accuracy_isgooddamage(self.realowner, e))
90                                 accuracy_add(self.realowner, WEP_FIREBALL, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
91
92                         Damage(e, self, self.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, self.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir);
93                         pointparticles(particleeffectnum("fireball_bfgdamage"), e.origin, -1 * dir, 1);
94                 }
95         }
96
97         remove (self);
98 }
99
100 void W_Fireball_TouchExplode (void)
101 {
102         PROJECTILE_TOUCH;
103         W_Fireball_Explode ();
104 }
105
106 void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage, float burntime)
107 {
108         entity e;
109         float d;
110         vector p;
111
112         if(damage <= 0)
113                 return;
114
115         RandomSelection_Init();
116         for(e = WarpZone_FindRadius(self.origin, dist, TRUE); e; e = e.chain)
117         if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
118         {
119                 p = e.origin;
120                 p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
121                 p_y += e.mins_y + random() * (e.maxs_y - e.mins_y);
122                 p_z += e.mins_z + random() * (e.maxs_z - e.mins_z);
123                 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
124                 if(d < dist)
125                 {
126                         e.fireball_impactvec = p;
127                         RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
128                 }
129         }
130         if(RandomSelection_chosen_ent)
131         {
132                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
133                 d = damage + (edgedamage - damage) * (d / dist);
134                 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
135                 //trailparticles(self, particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
136                 pointparticles(particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
137         }
138 }
139
140 void W_Fireball_Think()
141 {
142         if(time > self.pushltime)
143         {
144                 self.cnt = 1;
145                 self.projectiledeathtype |= HITTYPE_SPLASH;
146                 W_Fireball_Explode();
147                 return;
148         }
149
150         W_Fireball_LaserPlay(0.1, WEP_CVAR_PRI(fireball, laserradius), WEP_CVAR_PRI(fireball, laserdamage), WEP_CVAR_PRI(fireball, laseredgedamage), WEP_CVAR_PRI(fireball, laserburntime));
151
152         self.nextthink = time + 0.1;
153 }
154
155 void W_Fireball_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
156 {
157         if(self.health <= 0)
158                 return;
159
160         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
161                 return; // g_projectiles_damage says to halt
162
163         self.health = self.health - damage;
164         if (self.health <= 0)
165         {
166                 self.cnt = 1;
167                 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
168         }
169 }
170
171 void W_Fireball_Attack1()
172 {
173         entity proj;
174
175         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", CH_WEAPON_A, WEP_CVAR_PRI(fireball, damage) + WEP_CVAR_PRI(fireball, bfgdamage));
176
177         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
178
179         proj = spawn ();
180         proj.classname = "plasma_prim";
181         proj.owner = proj.realowner = self;
182         proj.bot_dodge = TRUE;
183         proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
184         proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
185         proj.use = W_Fireball_Explode;
186         proj.think = W_Fireball_Think;
187         proj.nextthink = time;
188         proj.health = WEP_CVAR_PRI(fireball, health);
189         proj.team = self.team;
190         proj.event_damage = W_Fireball_Damage;
191         proj.takedamage = DAMAGE_YES;
192         proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
193         PROJECTILE_MAKETRIGGER(proj);
194         proj.projectiledeathtype = WEP_FIREBALL;
195         setorigin(proj, w_shotorg);
196
197         proj.movetype = MOVETYPE_FLY;
198         W_SETUPPROJECTILEVELOCITY(proj, g_balance_fireball_primary);
199         proj.angles = vectoangles(proj.velocity);
200         proj.touch = W_Fireball_TouchExplode;
201         setsize(proj, '-16 -16 -16', '16 16 16');
202         proj.flags = FL_PROJECTILE;
203     proj.missile_flags = MIF_SPLASH | MIF_PROXY;
204
205         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
206
207         other = proj; MUTATOR_CALLHOOK(EditProjectile);
208 }
209
210 void W_Fireball_AttackEffect(float i, vector f_diff)
211 {
212         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0, 0);
213         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
214         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
215 }
216
217 void W_Fireball_Attack1_Frame4()
218 {
219         W_Fireball_Attack1();
220         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
221 }
222
223 void W_Fireball_Attack1_Frame3()
224 {
225         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
226         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
227 }
228
229 void W_Fireball_Attack1_Frame2()
230 {
231         W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
232         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
233 }
234
235 void W_Fireball_Attack1_Frame1()
236 {
237         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
238         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
239 }
240
241 void W_Fireball_Attack1_Frame0()
242 {
243         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
244         sound (self, CH_WEAPON_SINGLE, "weapons/fireball_prefire2.wav", VOL_BASE, ATTEN_NORM);
245         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
246 }
247
248 void W_Firemine_Think()
249 {
250         if(time > self.pushltime)
251         {
252                 remove(self);
253                 return;
254         }
255
256         // make it "hot" once it leaves its owner
257         if(self.owner)
258         {
259                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > WEP_CVAR_SEC(fireball, laserradius))
260                 {
261                         self.cnt += 1;
262                         if(self.cnt == 3)
263                                 self.owner = world;
264                 }
265                 else
266                         self.cnt = 0;
267         }
268
269         W_Fireball_LaserPlay(0.1, WEP_CVAR_SEC(fireball, laserradius), WEP_CVAR_SEC(fireball, laserdamage), WEP_CVAR_SEC(fireball, laseredgedamage), WEP_CVAR_SEC(fireball, laserburntime));
270
271         self.nextthink = time + 0.1;
272 }
273
274 void W_Firemine_Touch (void)
275 {
276         PROJECTILE_TOUCH;
277         if (other.takedamage == DAMAGE_AIM)
278         if(Fire_AddDamage(other, self.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), self.projectiledeathtype) >= 0)
279         {
280                 remove(self);
281                 return;
282         }
283         self.projectiledeathtype |= HITTYPE_BOUNCE;
284 }
285
286 void W_Fireball_Attack2()
287 {
288         entity proj;
289         vector f_diff;
290         float c;
291
292         c = mod(self.bulletcounter, 4);
293         switch(c)
294         {
295                 case 0:
296                         f_diff = '-1.25 -3.75 0';
297                         break;
298                 case 1:
299                         f_diff = '+1.25 -3.75 0';
300                         break;
301                 case 2:
302                         f_diff = '-1.25 +3.75 0';
303                         break;
304                 case 3:
305                 default:
306                         f_diff = '+1.25 +3.75 0';
307                         break;
308         }
309         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(fireball, damage));
310         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
311         w_shotorg = trace_endpos;
312
313         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
314
315         proj = spawn ();
316         proj.owner = proj.realowner = self;
317         proj.classname = "grenade";
318         proj.bot_dodge = TRUE;
319         proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
320         proj.movetype = MOVETYPE_BOUNCE;
321         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
322         proj.touch = W_Firemine_Touch;
323         PROJECTILE_MAKETRIGGER(proj);
324         setsize(proj, '-4 -4 -4', '4 4 4');
325         setorigin(proj, w_shotorg);
326         proj.think = W_Firemine_Think;
327         proj.nextthink = time;
328         proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
329         proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
330         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
331
332         proj.angles = vectoangles(proj.velocity);
333         proj.flags = FL_PROJECTILE;
334     proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
335
336         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
337
338         other = proj; MUTATOR_CALLHOOK(EditProjectile);
339 }
340
341 float w_fireball(float req)
342 {
343         switch(req)
344         {
345                 case WR_AIM:
346                 {
347                         self.BUTTON_ATCK = FALSE;
348                         self.BUTTON_ATCK2 = FALSE;
349                         if (self.bot_primary_fireballmooth == 0)
350                         {
351                                 if(bot_aim(WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), FALSE))
352                                 {
353                                         self.BUTTON_ATCK = TRUE;
354                                         if(random() < 0.02) self.bot_primary_fireballmooth = 0;
355                                 }
356                         }
357                         else
358                         {
359                                 if(bot_aim(WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), TRUE))
360                                 {
361                                         self.BUTTON_ATCK2 = TRUE;
362                                         if(random() < 0.01) self.bot_primary_fireballmooth = 1;
363                                 }
364                         }
365                         
366                         return TRUE;
367                 }
368                 case WR_THINK:
369                 {
370                         if (self.BUTTON_ATCK)
371                         {
372                                 if (time >= self.fireball_primarytime)
373                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(fireball, refire)))
374                                 {
375                                         W_Fireball_Attack1_Frame0();
376                                         self.fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor();
377                                 }
378                         }
379                         else if (self.BUTTON_ATCK2)
380                         {
381                                 if (weapon_prepareattack(1, WEP_CVAR_SEC(fireball, refire)))
382                                 {
383                                         W_Fireball_Attack2();
384                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
385                                 }
386                         }
387                         
388                         return TRUE;
389                 }
390                 case WR_INIT:
391                 {
392                         precache_model ("models/weapons/g_fireball.md3");
393                         precache_model ("models/weapons/v_fireball.md3");
394                         precache_model ("models/weapons/h_fireball.iqm");
395                         precache_model ("models/sphere/sphere.md3");
396                         precache_sound ("weapons/fireball_fire.wav");
397                         precache_sound ("weapons/fireball_fire2.wav");
398                         precache_sound ("weapons/fireball_prefire2.wav");
399                         FIREBALL_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
400                         return TRUE;
401                 }
402                 case WR_SETUP:
403                 {
404                         self.current_ammo = ammo_none;
405                         return TRUE;
406                 }
407                 case WR_CHECKAMMO1:
408                 case WR_CHECKAMMO2:
409                 {
410                         return TRUE; // fireball has infinite ammo
411                 }
412                 case WR_CONFIG:
413                 {
414                         FIREBALL_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
415                         return TRUE;
416                 }
417                 case WR_RESETPLAYER:
418                 {
419                         self.fireball_primarytime = time;
420                         return TRUE;
421                 }
422                 case WR_SUICIDEMESSAGE:
423                 {
424                         if(w_deathtype & HITTYPE_SECONDARY)
425                                 return WEAPON_FIREBALL_SUICIDE_FIREMINE;
426                         else
427                                 return WEAPON_FIREBALL_SUICIDE_BLAST;
428                 }
429                 case WR_KILLMESSAGE:
430                 {
431                         if(w_deathtype & HITTYPE_SECONDARY)
432                                 return WEAPON_FIREBALL_MURDER_FIREMINE;
433                         else
434                                 return WEAPON_FIREBALL_MURDER_BLAST;
435                 }
436         }
437         return TRUE;
438 }
439 #endif
440 #ifdef CSQC
441 float w_fireball(float req)
442 {
443         switch(req)
444         {
445                 case WR_IMPACTEFFECT:
446                 {
447                         vector org2;
448                         if(w_deathtype & HITTYPE_SECONDARY)
449                         {
450                                 // firemine goes out silently
451                         }
452                         else
453                         {
454                                 org2 = w_org + w_backoff * 16;
455                                 pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
456                                 if(!w_issilent)
457                                         sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTEN_NORM * 0.25); // long range boom
458                         }
459                         
460                         return TRUE;
461                 }
462                 case WR_INIT:
463                 {
464                         precache_sound("weapons/fireball_impact2.wav");
465                         return TRUE;
466                 }
467         }
468
469         return TRUE;
470 }
471 #endif
472 #endif