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