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