]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_fireball.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_fireball.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(FIREBALL, w_fireball, IT_FUEL, 9, WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "fireball", "fireball", _("Fireball"));
3 #else
4 #ifdef SVQC
5 .float bot_primary_fireballmooth; // whatever a mooth is
6 .vector fireball_impactvec;
7 .float fireball_primarytime;
8
9 .float fireball_load;
10
11 void W_Fireball_SetAmmoCounter()
12 {
13         // set clip_load to the weapon we have switched to, if the gun uses reloading
14         if(!autocvar_g_balance_fireball_reload_ammo)
15                 self.clip_load = 0; // also keeps crosshair ammo from displaying
16         else
17         {
18                 self.clip_load = self.fireball_load;
19                 self.clip_size = autocvar_g_balance_fireball_reload_ammo; // for the crosshair ammo display
20         }
21 }
22
23 void W_Fireball_ReloadedAndReady()
24 {
25         float t;
26
27         // now do the ammo transfer
28         self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
29         while(self.clip_load < autocvar_g_balance_fireball_reload_ammo && self.ammo_fuel) // make sure we don't add more ammo than we have
30         {
31                 self.clip_load += 1;
32                 self.ammo_fuel -= 1;
33
34                 // fuel can be a non-whole number, which brakes stuff here when between 0 and 1
35                 if(self.ammo_fuel < 1)
36                         self.ammo_fuel = 0;
37         }
38         self.fireball_load = self.clip_load;
39
40         t = ATTACK_FINISHED(self) - autocvar_g_balance_fireball_reload_time - 1;
41         ATTACK_FINISHED(self) = t;
42         w_ready();
43 }
44
45 void W_Fireball_Reload()
46 {
47         // return if reloading is disabled for this weapon
48         if(!autocvar_g_balance_fireball_reload_ammo)
49                 return;
50
51         if(!W_ReloadCheck(self.ammo_fuel, min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo)))
52                 return;
53
54         float t;
55
56         sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
57
58         t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_fireball_reload_time + 1;
59         ATTACK_FINISHED(self) = t;
60
61         weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_fireball_reload_time, W_Fireball_ReloadedAndReady);
62
63         self.old_clip_load = self.clip_load;
64         self.clip_load = -1;
65 }
66
67 void W_Fireball_Explode (void)
68 {
69         entity e;
70         float dist;
71         float points;
72         vector dir;
73         float d;
74
75         self.event_damage = SUB_Null;
76         self.takedamage = DAMAGE_NO;
77
78         // 1. dist damage
79         d = (self.owner.health + self.owner.armorvalue);
80         RadiusDamage (self, self.realowner, autocvar_g_balance_fireball_primary_damage, autocvar_g_balance_fireball_primary_edgedamage, autocvar_g_balance_fireball_primary_radius, world, autocvar_g_balance_fireball_primary_force, self.projectiledeathtype, other);
81         if(self.realowner.health + self.realowner.armorvalue >= d)
82         if(!self.cnt)
83         {
84                 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, self.origin, '0 0 0', '0 0 0', '0 0 0', 0, autocvar_g_balance_fireball_primary_bfgradius, 0.2, 0.05, 0.25);
85
86                 // 2. bfg effect
87                 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
88                 for(e = findradius(self.origin, autocvar_g_balance_fireball_primary_bfgradius); e; e = e.chain)
89                 if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
90                 {
91                         // can we see fireball?
92                         traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
93                         if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
94                                 continue;
95                         // can we see player who shot fireball?
96                         traceline(e.origin + e.view_ofs, self.realowner.origin + self.realowner.view_ofs, MOVE_NORMAL, e);
97                         if(trace_ent != self.realowner)
98                         if(/* trace_startsolid || */ trace_fraction != 1)
99                                 continue;
100                         dist = vlen(self.origin - e.origin - e.view_ofs);
101                         points = (1 - sqrt(dist / autocvar_g_balance_fireball_primary_bfgradius));
102                         if(points <= 0)
103                                 continue;
104                         dir = normalize(e.origin + e.view_ofs - self.origin);
105
106                         if(accuracy_isgooddamage(self.realowner, e))
107                                 accuracy_add(self.realowner, WEP_FIREBALL, 0, autocvar_g_balance_fireball_primary_bfgdamage * points);
108
109                         Damage(e, self, self.realowner, autocvar_g_balance_fireball_primary_bfgdamage * points, self.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, autocvar_g_balance_fireball_primary_bfgforce * dir);
110                         pointparticles(particleeffectnum("fireball_bfgdamage"), e.origin, -1 * dir, 1);
111                 }
112         }
113
114         remove (self);
115 }
116
117 void W_Fireball_TouchExplode (void)
118 {
119         PROJECTILE_TOUCH;
120         W_Fireball_Explode ();
121 }
122
123 void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage, float burntime)
124 {
125         entity e;
126         float d;
127         vector p;
128
129         if(damage <= 0)
130                 return;
131
132         RandomSelection_Init();
133         for(e = WarpZone_FindRadius(self.origin, dist, TRUE); e; e = e.chain)
134         if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
135         {
136                 p = e.origin;
137                 p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
138                 p_y += e.mins_y + random() * (e.maxs_y - e.mins_y);
139                 p_z += e.mins_z + random() * (e.maxs_z - e.mins_z);
140                 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
141                 if(d < dist)
142                 {
143                         e.fireball_impactvec = p;
144                         RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
145                 }
146         }
147         if(RandomSelection_chosen_ent)
148         {
149                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
150                 d = damage + (edgedamage - damage) * (d / dist);
151                 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
152                 //trailparticles(self, particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
153                 pointparticles(particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
154         }
155 }
156
157 void W_Fireball_Think()
158 {
159         if(time > self.pushltime)
160         {
161                 self.cnt = 1;
162                 self.projectiledeathtype |= HITTYPE_SPLASH;
163                 W_Fireball_Explode();
164                 return;
165         }
166
167         W_Fireball_LaserPlay(0.1, autocvar_g_balance_fireball_primary_laserradius, autocvar_g_balance_fireball_primary_laserdamage, autocvar_g_balance_fireball_primary_laseredgedamage, autocvar_g_balance_fireball_primary_laserburntime);
168
169         self.nextthink = time + 0.1;
170 }
171
172 void W_Fireball_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
173 {
174         if(self.health <= 0)
175                 return;
176         self.health = self.health - damage;
177         if (self.health <= 0)
178         {
179                 self.cnt = 1;
180                 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
181         }
182 }
183
184 void W_Fireball_Attack1()
185 {
186         local entity proj;
187
188         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", CHAN_WEAPON, autocvar_g_balance_fireball_primary_damage + autocvar_g_balance_fireball_primary_bfgdamage);
189
190         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
191
192         proj = spawn ();
193         proj.classname = "plasma_prim";
194         proj.owner = proj.realowner = self;
195         proj.bot_dodge = TRUE;
196         proj.bot_dodgerating = autocvar_g_balance_fireball_primary_damage;
197         proj.pushltime = time + autocvar_g_balance_fireball_primary_lifetime;
198         proj.use = W_Fireball_Explode;
199         proj.think = W_Fireball_Think;
200         proj.nextthink = time;
201         proj.health = autocvar_g_balance_fireball_primary_health;
202         proj.team = self.team;
203         proj.event_damage = W_Fireball_Damage;
204         proj.takedamage = DAMAGE_YES;
205         proj.damageforcescale = autocvar_g_balance_fireball_primary_damageforcescale;
206         PROJECTILE_MAKETRIGGER(proj);
207         proj.projectiledeathtype = WEP_FIREBALL;
208         setorigin(proj, w_shotorg);
209
210         proj.movetype = MOVETYPE_FLY;
211         W_SETUPPROJECTILEVELOCITY(proj, g_balance_fireball_primary);
212         proj.angles = vectoangles(proj.velocity);
213         proj.touch = W_Fireball_TouchExplode;
214         setsize(proj, '-16 -16 -16', '16 16 16');
215         proj.flags = FL_PROJECTILE;
216
217         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
218
219         other = proj; MUTATOR_CALLHOOK(EditProjectile);
220 }
221
222 void W_Fireball_AttackEffect(float i, vector f_diff)
223 {
224         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0, 0);
225         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
226         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
227 }
228
229 void W_Fireball_Attack1_Frame4()
230 {
231         W_Fireball_Attack1();
232         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, w_ready);
233 }
234
235 void W_Fireball_Attack1_Frame3()
236 {
237         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
238         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame4);
239 }
240
241 void W_Fireball_Attack1_Frame2()
242 {
243         W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
244         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame3);
245 }
246
247 void W_Fireball_Attack1_Frame1()
248 {
249         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
250         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame2);
251 }
252
253 void W_Fireball_Attack1_Frame0()
254 {
255         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
256         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
257         {
258                 if(autocvar_g_balance_fireball_reload_ammo)
259                 {
260                         self.clip_load -= autocvar_g_balance_fireball_primary_ammo;
261                         self.fireball_load = self.clip_load;
262                 }
263                 else
264                         self.ammo_fuel -= autocvar_g_balance_fireball_primary_ammo;
265         }
266
267         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
268         sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
269         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame1);
270 }
271
272 void W_Firemine_Think()
273 {
274         if(time > self.pushltime)
275         {
276                 remove(self);
277                 return;
278         }
279
280         // make it "hot" once it leaves its owner
281         if(self.owner)
282         {
283                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > autocvar_g_balance_fireball_secondary_laserradius)
284                 {
285                         self.cnt += 1;
286                         if(self.cnt == 3)
287                                 self.owner = world;
288                 }
289                 else
290                         self.cnt = 0;
291         }
292
293         W_Fireball_LaserPlay(0.1, autocvar_g_balance_fireball_secondary_laserradius, autocvar_g_balance_fireball_secondary_laserdamage, autocvar_g_balance_fireball_secondary_laseredgedamage, autocvar_g_balance_fireball_secondary_laserburntime);
294
295         self.nextthink = time + 0.1;
296 }
297
298 void W_Firemine_Touch (void)
299 {
300         PROJECTILE_TOUCH;
301         if (other.takedamage == DAMAGE_AIM)
302         if(Fire_AddDamage(other, self.realowner, autocvar_g_balance_fireball_secondary_damage, autocvar_g_balance_fireball_secondary_damagetime, self.projectiledeathtype | HITTYPE_HEADSHOT) >= 0)
303         {
304                 remove(self);
305                 return;
306         }
307         self.projectiledeathtype |= HITTYPE_BOUNCE;
308 }
309
310 void W_Fireball_Attack2()
311 {
312         local entity proj;
313         vector f_diff;
314         float c;
315
316         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
317         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
318         {
319                 if(autocvar_g_balance_fireball_reload_ammo)
320                 {
321                         self.clip_load -= autocvar_g_balance_fireball_secondary_ammo;
322                         self.fireball_load = self.clip_load;
323                 }
324                 else
325                         self.ammo_fuel -= autocvar_g_balance_fireball_secondary_ammo;
326         }
327
328         c = mod(self.bulletcounter, 4);
329         switch(c)
330         {
331                 case 0:
332                         f_diff = '-1.25 -3.75 0';
333                         break;
334                 case 1:
335                         f_diff = '+1.25 -3.75 0';
336                         break;
337                 case 2:
338                         f_diff = '-1.25 +3.75 0';
339                         break;
340                 case 3:
341                 default:
342                         f_diff = '+1.25 +3.75 0';
343                         break;
344         }
345         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CHAN_WEAPON, autocvar_g_balance_fireball_secondary_damage);
346         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
347         w_shotorg = trace_endpos;
348
349         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
350
351         proj = spawn ();
352         proj.owner = proj.realowner = self;
353         proj.classname = "grenade";
354         proj.bot_dodge = TRUE;
355         proj.bot_dodgerating = autocvar_g_balance_fireball_secondary_damage;
356         proj.movetype = MOVETYPE_BOUNCE;
357         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
358         proj.touch = W_Firemine_Touch;
359         PROJECTILE_MAKETRIGGER(proj);
360         setsize(proj, '-4 -4 -4', '4 4 4');
361         setorigin(proj, w_shotorg);
362         proj.think = W_Firemine_Think;
363         proj.nextthink = time;
364         proj.damageforcescale = autocvar_g_balance_fireball_secondary_damageforcescale;
365         proj.pushltime = time + autocvar_g_balance_fireball_secondary_lifetime;
366         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
367
368         proj.angles = vectoangles(proj.velocity);
369         proj.flags = FL_PROJECTILE;
370
371         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
372
373         other = proj; MUTATOR_CALLHOOK(EditProjectile);
374 }
375
376 void spawnfunc_weapon_fireball (void)
377 {
378         weapon_defaultspawnfunc(WEP_FIREBALL);
379 }
380
381 float w_fireball(float req)
382 {
383         if (req == WR_AIM)
384         {
385                 self.BUTTON_ATCK = FALSE;
386                 self.BUTTON_ATCK2 = FALSE;
387                 if (self.bot_primary_fireballmooth == 0)
388                 {
389                         if(bot_aim(autocvar_g_balance_fireball_primary_speed, 0, autocvar_g_balance_fireball_primary_lifetime, FALSE))
390                         {
391                                 self.BUTTON_ATCK = TRUE;
392                                 if(random() < 0.02) self.bot_primary_fireballmooth = 0;
393                         }
394                 }
395                 else
396                 {
397                         if(bot_aim(autocvar_g_balance_fireball_secondary_speed, autocvar_g_balance_fireball_secondary_speed_up, autocvar_g_balance_fireball_secondary_lifetime, TRUE))
398                         {
399                                 self.BUTTON_ATCK2 = TRUE;
400                                 if(random() < 0.01) self.bot_primary_fireballmooth = 1;
401                         }
402                 }
403         }
404         else if (req == WR_THINK)
405         {
406                 if(autocvar_g_balance_fireball_reload_ammo && self.clip_load < min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo)) // forced reload
407                         W_Fireball_Reload();
408                 else if (self.BUTTON_ATCK)
409                 {
410                         if (time >= self.fireball_primarytime)
411                         if (weapon_prepareattack(0, autocvar_g_balance_fireball_primary_refire))
412                         {
413                                 W_Fireball_Attack1_Frame0();
414                                 self.fireball_primarytime = time + autocvar_g_balance_fireball_primary_refire2;
415                         }
416                 }
417                 else if (self.BUTTON_ATCK2)
418                 {
419                         if (weapon_prepareattack(1, autocvar_g_balance_fireball_secondary_refire))
420                         {
421                                 W_Fireball_Attack2();
422                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_fireball_secondary_animtime, w_ready);
423                         }
424                 }
425         if(self.wish_reload)
426         {
427             if(self.switchweapon == self.weapon)
428             {
429                 if(self.weaponentity.state == WS_READY)
430                 {
431                     self.wish_reload = 0;
432                     W_Fireball_Reload();
433                 }
434             }
435         }
436         }
437         else if (req == WR_PRECACHE)
438         {
439                 precache_model ("models/weapons/g_fireball.md3");
440                 precache_model ("models/weapons/v_fireball.md3");
441                 precache_model ("models/weapons/h_fireball.iqm");
442                 precache_model ("models/sphere/sphere.md3");
443                 precache_sound ("weapons/fireball_fire.wav");
444                 precache_sound ("weapons/fireball_fire2.wav");
445                 precache_sound ("weapons/fireball_prefire2.wav");
446         }
447         else if (req == WR_SETUP)
448         {
449                 weapon_setup(WEP_FIREBALL);
450                 W_Fireball_SetAmmoCounter();
451         }
452         else if (req == WR_CHECKAMMO1)
453         {
454                 if(autocvar_g_balance_fireball_reload_ammo)
455                         return self.fireball_load >= autocvar_g_balance_fireball_primary_ammo;
456                 else
457                         return self.ammo_fuel >= autocvar_g_balance_fireball_primary_ammo;
458         }
459         else if (req == WR_CHECKAMMO2)
460         {
461                 if(autocvar_g_balance_fireball_reload_ammo)
462                         return self.fireball_load >= autocvar_g_balance_fireball_secondary_ammo;
463                 else
464                         return self.ammo_fuel >= autocvar_g_balance_fireball_secondary_ammo;
465         }
466         else if (req == WR_RESETPLAYER)
467         {
468                 self.fireball_primarytime = time;
469         }
470         return TRUE;
471 };
472 #endif
473 #ifdef CSQC
474 float w_fireball(float req)
475 {
476         if(req == WR_IMPACTEFFECT)
477         {
478                 vector org2;
479                 if(w_deathtype & HITTYPE_SECONDARY)
480                 {
481                         // firemine goes out silently
482                 }
483                 else
484                 {
485                         org2 = w_org + w_backoff * 16;
486                         pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
487                         if(!w_issilent)
488                                 sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
489                 }
490         }
491         else if(req == WR_PRECACHE)
492         {
493                 precache_sound("weapons/fireball_impact2.wav");
494         }
495         else if (req == WR_SUICIDEMESSAGE)
496         {
497                 if(w_deathtype & HITTYPE_SECONDARY)
498                         w_deathtypestring = "%s forgot about some firemine";
499                 else
500                         w_deathtypestring = "%s should have used a smaller gun";
501         }
502         else if (req == WR_KILLMESSAGE)
503         {
504                 if(w_deathtype & HITTYPE_SECONDARY)
505                 {
506                         if(w_deathtype & HITTYPE_HEADSHOT)
507                                 w_deathtypestring = "%s tried to catch %s's firemine";
508                         else
509                                 w_deathtypestring = "%s fatefully ignored %s's firemine";
510                 }
511                 else
512                 {
513                         if(w_deathtype & HITTYPE_BOUNCE)
514                         {
515                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
516                                         w_deathtypestring = "%s could not hide from %s's fireball";
517                                 else // laser
518                                         w_deathtypestring = "%s saw the pretty lights of %s's fireball";
519                         }
520                         else if(w_deathtype & HITTYPE_SPLASH)
521                                 w_deathtypestring = "%s got too close to %s's fireball";
522                         else
523                                 w_deathtypestring = "%s tasted %s's fireball";
524                 }
525         }
526         else if (req == WR_RELOAD)
527         {
528                 W_Fireball_Reload();
529         }
530         return TRUE;
531 }
532 #endif
533 #endif