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