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