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