]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_fireball.qc
Reload if we don't have ammo for a certain attack. Prevents situations in which you...
[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 there's not enough ammo for this attack (but we still have the weapon), reload
256         if(autocvar_g_balance_fireball_reload_ammo && self.clip_load < autocvar_g_balance_fireball_primary_ammo)
257         {
258                 W_Fireball_Reload();
259                 return;
260         }
261
262         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
263         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
264         {
265                 if(autocvar_g_balance_fireball_reload_ammo)
266                 {
267                         self.clip_load -= autocvar_g_balance_fireball_primary_ammo;
268                         self.fireball_load = self.clip_load;
269                 }
270                 else
271                         self.ammo_fuel -= autocvar_g_balance_fireball_primary_ammo;
272         }
273
274         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
275         sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
276         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame1);
277 }
278
279 void W_Firemine_Think()
280 {
281         if(time > self.pushltime)
282         {
283                 remove(self);
284                 return;
285         }
286
287         // make it "hot" once it leaves its owner
288         if(self.owner)
289         {
290                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > autocvar_g_balance_fireball_secondary_laserradius)
291                 {
292                         self.cnt += 1;
293                         if(self.cnt == 3)
294                                 self.owner = world;
295                 }
296                 else
297                         self.cnt = 0;
298         }
299
300         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);
301
302         self.nextthink = time + 0.1;
303 }
304
305 void W_Firemine_Touch (void)
306 {
307         PROJECTILE_TOUCH;
308         if (other.takedamage == DAMAGE_AIM)
309         if(Fire_AddDamage(other, self.realowner, autocvar_g_balance_fireball_secondary_damage, autocvar_g_balance_fireball_secondary_damagetime, self.projectiledeathtype | HITTYPE_HEADSHOT) >= 0)
310         {
311                 remove(self);
312                 return;
313         }
314         self.projectiledeathtype |= HITTYPE_BOUNCE;
315 }
316
317 void W_Fireball_Attack2()
318 {
319         local entity proj;
320         vector f_diff;
321         float c;
322
323         // if there's not enough ammo for this attack (but we still have the weapon), reload
324         if(autocvar_g_balance_fireball_reload_ammo && self.clip_load < autocvar_g_balance_fireball_secondary_ammo)
325         {
326                 W_Fireball_Reload();
327                 return;
328         }
329
330         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
331         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
332         {
333                 if(autocvar_g_balance_fireball_reload_ammo)
334                 {
335                         self.clip_load -= autocvar_g_balance_fireball_secondary_ammo;
336                         self.fireball_load = self.clip_load;
337                 }
338                 else
339                         self.ammo_fuel -= autocvar_g_balance_fireball_secondary_ammo;
340         }
341
342         c = mod(self.bulletcounter, 4);
343         switch(c)
344         {
345                 case 0:
346                         f_diff = '-1.25 -3.75 0';
347                         break;
348                 case 1:
349                         f_diff = '+1.25 -3.75 0';
350                         break;
351                 case 2:
352                         f_diff = '-1.25 +3.75 0';
353                         break;
354                 case 3:
355                 default:
356                         f_diff = '+1.25 +3.75 0';
357                         break;
358         }
359         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CHAN_WEAPON, autocvar_g_balance_fireball_secondary_damage);
360         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
361         w_shotorg = trace_endpos;
362
363         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
364
365         proj = spawn ();
366         proj.owner = proj.realowner = self;
367         proj.classname = "grenade";
368         proj.bot_dodge = TRUE;
369         proj.bot_dodgerating = autocvar_g_balance_fireball_secondary_damage;
370         proj.movetype = MOVETYPE_BOUNCE;
371         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
372         proj.touch = W_Firemine_Touch;
373         PROJECTILE_MAKETRIGGER(proj);
374         setsize(proj, '-4 -4 -4', '4 4 4');
375         setorigin(proj, w_shotorg);
376         proj.think = W_Firemine_Think;
377         proj.nextthink = time;
378         proj.damageforcescale = autocvar_g_balance_fireball_secondary_damageforcescale;
379         proj.pushltime = time + autocvar_g_balance_fireball_secondary_lifetime;
380         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
381
382         proj.angles = vectoangles(proj.velocity);
383         proj.flags = FL_PROJECTILE;
384
385         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
386
387         other = proj; MUTATOR_CALLHOOK(EditProjectile);
388 }
389
390 void spawnfunc_weapon_fireball (void)
391 {
392         weapon_defaultspawnfunc(WEP_FIREBALL);
393 }
394
395 float w_fireball(float req)
396 {
397         if (req == WR_AIM)
398         {
399                 self.BUTTON_ATCK = FALSE;
400                 self.BUTTON_ATCK2 = FALSE;
401                 if (self.bot_primary_fireballmooth == 0)
402                 {
403                         if(bot_aim(autocvar_g_balance_fireball_primary_speed, 0, autocvar_g_balance_fireball_primary_lifetime, FALSE))
404                         {
405                                 self.BUTTON_ATCK = TRUE;
406                                 if(random() < 0.02) self.bot_primary_fireballmooth = 0;
407                         }
408                 }
409                 else
410                 {
411                         if(bot_aim(autocvar_g_balance_fireball_secondary_speed, autocvar_g_balance_fireball_secondary_speed_up, autocvar_g_balance_fireball_secondary_lifetime, TRUE))
412                         {
413                                 self.BUTTON_ATCK2 = TRUE;
414                                 if(random() < 0.01) self.bot_primary_fireballmooth = 1;
415                         }
416                 }
417         }
418         else if (req == WR_THINK)
419         {
420                 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
421                         W_Fireball_Reload();
422                 else if (self.BUTTON_ATCK)
423                 {
424                         if (time >= self.fireball_primarytime)
425                         if (weapon_prepareattack(0, autocvar_g_balance_fireball_primary_refire))
426                         {
427                                 W_Fireball_Attack1_Frame0();
428                                 self.fireball_primarytime = time + autocvar_g_balance_fireball_primary_refire2;
429                         }
430                 }
431                 else if (self.BUTTON_ATCK2)
432                 {
433                         if (weapon_prepareattack(1, autocvar_g_balance_fireball_secondary_refire))
434                         {
435                                 W_Fireball_Attack2();
436                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_fireball_secondary_animtime, w_ready);
437                         }
438                 }
439         if(self.wish_reload)
440         {
441             if(self.switchweapon == self.weapon)
442             {
443                 if(self.weaponentity.state == WS_READY)
444                 {
445                     self.wish_reload = 0;
446                     W_Fireball_Reload();
447                 }
448             }
449         }
450         }
451         else if (req == WR_PRECACHE)
452         {
453                 precache_model ("models/weapons/g_fireball.md3");
454                 precache_model ("models/weapons/v_fireball.md3");
455                 precache_model ("models/weapons/h_fireball.iqm");
456                 precache_model ("models/sphere/sphere.md3");
457                 precache_sound ("weapons/fireball_fire.wav");
458                 precache_sound ("weapons/fireball_fire2.wav");
459                 precache_sound ("weapons/fireball_prefire2.wav");
460         }
461         else if (req == WR_SETUP)
462         {
463                 weapon_setup(WEP_FIREBALL);
464                 W_Fireball_SetAmmoCounter();
465         }
466         else if (req == WR_CHECKAMMO1)
467         {
468                 if(autocvar_g_balance_fireball_reload_ammo)
469                         return self.fireball_load >= autocvar_g_balance_fireball_primary_ammo;
470                 else
471                         return self.ammo_fuel >= autocvar_g_balance_fireball_primary_ammo;
472         }
473         else if (req == WR_CHECKAMMO2)
474         {
475                 if(autocvar_g_balance_fireball_reload_ammo)
476                         return self.fireball_load >= autocvar_g_balance_fireball_secondary_ammo;
477                 else
478                         return self.ammo_fuel >= autocvar_g_balance_fireball_secondary_ammo;
479         }
480         else if (req == WR_RESETPLAYER)
481         {
482                 self.fireball_primarytime = time;
483         }
484         return TRUE;
485 };
486 #endif
487 #ifdef CSQC
488 float w_fireball(float req)
489 {
490         if(req == WR_IMPACTEFFECT)
491         {
492                 vector org2;
493                 if(w_deathtype & HITTYPE_SECONDARY)
494                 {
495                         // firemine goes out silently
496                 }
497                 else
498                 {
499                         org2 = w_org + w_backoff * 16;
500                         pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
501                         if(!w_issilent)
502                                 sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
503                 }
504         }
505         else if(req == WR_PRECACHE)
506         {
507                 precache_sound("weapons/fireball_impact2.wav");
508         }
509         else if (req == WR_SUICIDEMESSAGE)
510         {
511                 if(w_deathtype & HITTYPE_SECONDARY)
512                         w_deathtypestring = "%s forgot about some firemine";
513                 else
514                         w_deathtypestring = "%s should have used a smaller gun";
515         }
516         else if (req == WR_KILLMESSAGE)
517         {
518                 if(w_deathtype & HITTYPE_SECONDARY)
519                 {
520                         if(w_deathtype & HITTYPE_HEADSHOT)
521                                 w_deathtypestring = "%s tried to catch %s's firemine";
522                         else
523                                 w_deathtypestring = "%s fatefully ignored %s's firemine";
524                 }
525                 else
526                 {
527                         if(w_deathtype & HITTYPE_BOUNCE)
528                         {
529                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
530                                         w_deathtypestring = "%s could not hide from %s's fireball";
531                                 else // laser
532                                         w_deathtypestring = "%s saw the pretty lights of %s's fireball";
533                         }
534                         else if(w_deathtype & HITTYPE_SPLASH)
535                                 w_deathtypestring = "%s got too close to %s's fireball";
536                         else
537                                 w_deathtypestring = "%s tasted %s's fireball";
538                 }
539         }
540         else if (req == WR_RELOAD)
541         {
542                 W_Fireball_Reload();
543         }
544         return TRUE;
545 }
546 #endif
547 #endif