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