]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_fireball.qc
add an additional arg to the W_SetupShot* functions for adjusting the sound channel...
[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_Explode (void)
10 {
11         entity e;
12         float dist;
13         float points;
14         vector dir;
15         float d;
16
17         self.event_damage = SUB_Null;
18         self.takedamage = DAMAGE_NO;
19
20         // 1. dist damage
21         d = (self.owner.health + self.owner.armorvalue);
22         RadiusDamage (self, self.realowner, cvar("g_balance_fireball_primary_damage"), cvar("g_balance_fireball_primary_edgedamage"), cvar("g_balance_fireball_primary_radius"), world, cvar("g_balance_fireball_primary_force"), self.projectiledeathtype, other);
23         if(self.realowner.health + self.realowner.armorvalue >= d)
24         if(!self.cnt)
25         {
26                 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, self.origin, '0 0 0', '0 0 0', '0 0 0', 0, cvar("g_balance_fireball_primary_bfgradius"), 0.2, 0.05, 0.25);
27
28                 // 2. bfg effect
29                 // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
30                 for(e = findradius(self.origin, cvar("g_balance_fireball_primary_bfgradius")); e; e = e.chain)
31                 if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
32                 {
33                         // can we see fireball?
34                         traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
35                         if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway
36                                 continue;
37                         // can we see player who shot fireball?
38                         traceline(e.origin + e.view_ofs, self.realowner.origin + self.realowner.view_ofs, MOVE_NORMAL, e);
39                         if(trace_ent != self.realowner)
40                         if(/* trace_startsolid || */ trace_fraction != 1)
41                                 continue;
42                         dist = vlen(self.origin - e.origin - e.view_ofs);
43                         points = (1 - sqrt(dist / cvar("g_balance_fireball_primary_bfgradius")));
44                         if(points <= 0)
45                                 continue;
46                         dir = normalize(e.origin + e.view_ofs - self.origin);
47
48                         if(accuracy_isgooddamage(self.realowner, e))
49                                 accuracy_add(self.realowner, WEP_FIREBALL, 0, cvar("g_balance_fireball_primary_bfgdamage") * points);
50
51                         Damage(e, self, self.realowner, cvar("g_balance_fireball_primary_bfgdamage") * points, self.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, cvar("g_balance_fireball_primary_bfgforce") * dir);
52                         pointparticles(particleeffectnum("fireball_bfgdamage"), e.origin, -1 * dir, 1);
53                 }
54         }
55
56         remove (self);
57 }
58
59 void W_Fireball_TouchExplode (void)
60 {
61         PROJECTILE_TOUCH;
62         W_Fireball_Explode ();
63 }
64
65 void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage, float burntime)
66 {
67         entity e;
68         float d;
69         vector p;
70
71         if(damage <= 0)
72                 return;
73
74         RandomSelection_Init();
75         for(e = WarpZone_FindRadius(self.origin, dist, TRUE); e; e = e.chain)
76         if(e != self.owner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.owner || IsDifferentTeam(e, self))
77         {
78                 p = e.origin;
79                 p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
80                 p_y += e.mins_y + random() * (e.maxs_y - e.mins_y);
81                 p_z += e.mins_z + random() * (e.maxs_z - e.mins_z);
82                 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
83                 if(d < dist)
84                 {
85                         e.fireball_impactvec = p;
86                         RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
87                 }
88         }
89         if(RandomSelection_chosen_ent)
90         {
91                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
92                 d = damage + (edgedamage - damage) * (d / dist);
93                 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
94                 //trailparticles(self, particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
95                 pointparticles(particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
96         }
97 }
98
99 void W_Fireball_Think()
100 {
101         if(time > self.pushltime)
102         {
103                 self.cnt = 1;
104                 self.projectiledeathtype |= HITTYPE_SPLASH;
105                 W_Fireball_Explode();
106                 return;
107         }
108
109         W_Fireball_LaserPlay(0.1, cvar("g_balance_fireball_primary_laserradius"), cvar("g_balance_fireball_primary_laserdamage"), cvar("g_balance_fireball_primary_laseredgedamage"), cvar("g_balance_fireball_primary_laserburntime"));
110
111         self.nextthink = time + 0.1;
112 }
113
114 void W_Fireball_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
115 {
116         if(self.health <= 0)
117                 return;
118         self.health = self.health - damage;
119         if (self.health <= 0)
120         {
121                 self.cnt = 1;
122                 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
123         }
124 }
125
126 void W_Fireball_Attack1()
127 {
128         local entity proj;
129
130         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", CHAN_WEAPON, cvar("g_balance_fireball_primary_damage") + cvar("g_balance_fireball_primary_bfgdamage"));
131
132         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
133
134         proj = spawn ();
135         proj.classname = "plasma_prim";
136         proj.owner = proj.realowner = self;
137         proj.bot_dodge = TRUE;
138         proj.bot_dodgerating = cvar("g_balance_fireball_primary_damage");
139         proj.pushltime = time + cvar("g_balance_fireball_primary_lifetime");
140         proj.use = W_Fireball_Explode;
141         proj.think = W_Fireball_Think;
142         proj.nextthink = time;
143         proj.health = cvar("g_balance_fireball_primary_health");
144         proj.team = self.team;
145         proj.event_damage = W_Fireball_Damage;
146         proj.takedamage = DAMAGE_YES;
147         proj.damageforcescale = cvar("g_balance_fireball_primary_damageforcescale");
148         PROJECTILE_MAKETRIGGER(proj);
149         proj.projectiledeathtype = WEP_FIREBALL;
150         setorigin(proj, w_shotorg);
151
152         proj.movetype = MOVETYPE_FLY;
153         W_SETUPPROJECTILEVELOCITY(proj, g_balance_fireball_primary);
154         proj.angles = vectoangles(proj.velocity);
155         proj.touch = W_Fireball_TouchExplode;
156         setsize(proj, '-16 -16 -16', '16 16 16');
157         proj.flags = FL_PROJECTILE;
158
159         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
160
161         other = proj; MUTATOR_CALLHOOK(EditProjectile);
162 }
163
164 void W_Fireball_AttackEffect(float i, vector f_diff)
165 {
166         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0, 0);
167         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
168         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
169 }
170
171 void W_Fireball_Attack1_Frame4()
172 {
173         W_Fireball_Attack1();
174         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_primary_animtime"), w_ready);
175 }
176
177 void W_Fireball_Attack1_Frame3()
178 {
179         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
180         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_primary_animtime"), W_Fireball_Attack1_Frame4);
181 }
182
183 void W_Fireball_Attack1_Frame2()
184 {
185         W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
186         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_primary_animtime"), W_Fireball_Attack1_Frame3);
187 }
188
189 void W_Fireball_Attack1_Frame1()
190 {
191         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
192         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_primary_animtime"), W_Fireball_Attack1_Frame2);
193 }
194
195 void W_Fireball_Attack1_Frame0()
196 {
197         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
198                 self.ammo_fuel = self.ammo_fuel - cvar("g_balance_fireball_primary_ammo");
199
200         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
201         sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
202         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_primary_animtime"), W_Fireball_Attack1_Frame1);
203 }
204
205 void W_Firemine_Think()
206 {
207         if(time > self.pushltime)
208         {
209                 remove(self);
210                 return;
211         }
212
213         // make it "hot" once it leaves its owner
214         if(self.owner)
215         {
216                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > cvar("g_balance_fireball_secondary_laserradius"))
217                 {
218                         self.cnt += 1;
219                         if(self.cnt == 3)
220                                 self.owner = world;
221                 }
222                 else
223                         self.cnt = 0;
224         }
225
226         W_Fireball_LaserPlay(0.1, cvar("g_balance_fireball_secondary_laserradius"), cvar("g_balance_fireball_secondary_laserdamage"), cvar("g_balance_fireball_secondary_laseredgedamage"), cvar("g_balance_fireball_secondary_laserburntime"));
227
228         self.nextthink = time + 0.1;
229 }
230
231 void W_Firemine_Touch (void)
232 {
233         PROJECTILE_TOUCH;
234         if (other.takedamage == DAMAGE_AIM)
235         if(Fire_AddDamage(other, self.realowner, cvar("g_balance_fireball_secondary_damage"), cvar("g_balance_fireball_secondary_damagetime"), self.projectiledeathtype | HITTYPE_HEADSHOT) >= 0)
236         {
237                 remove(self);
238                 return;
239         }
240         self.projectiledeathtype |= HITTYPE_BOUNCE;
241 }
242
243 void W_Fireball_Attack2()
244 {
245         local entity proj;
246         vector f_diff;
247         float c;
248
249         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
250                 self.ammo_fuel = self.ammo_fuel - cvar("g_balance_fireball_secondary_ammo");
251
252         c = mod(self.bulletcounter, 4);
253         switch(c)
254         {
255                 case 0:
256                         f_diff = '-1.25 -3.75 0';
257                         break;
258                 case 1:
259                         f_diff = '+1.25 -3.75 0';
260                         break;
261                 case 2:
262                         f_diff = '-1.25 +3.75 0';
263                         break;
264                 case 3:
265                 default:
266                         f_diff = '+1.25 +3.75 0';
267                         break;
268         }
269         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CHAN_WEAPON, cvar("g_balance_fireball_secondary_damage"));
270         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
271         w_shotorg = trace_endpos;
272
273         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
274
275         proj = spawn ();
276         proj.owner = proj.realowner = self;
277         proj.classname = "grenade";
278         proj.bot_dodge = TRUE;
279         proj.bot_dodgerating = cvar("g_balance_fireball_secondary_damage");
280         proj.movetype = MOVETYPE_BOUNCE;
281         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
282         proj.touch = W_Firemine_Touch;
283         PROJECTILE_MAKETRIGGER(proj);
284         setsize(proj, '-4 -4 -4', '4 4 4');
285         setorigin(proj, w_shotorg);
286         proj.think = W_Firemine_Think;
287         proj.nextthink = time;
288         proj.damageforcescale = cvar("g_balance_fireball_secondary_damageforcescale");
289         proj.pushltime = time + cvar("g_balance_fireball_secondary_lifetime");
290         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
291
292         proj.angles = vectoangles(proj.velocity);
293         proj.flags = FL_PROJECTILE;
294
295         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
296
297         other = proj; MUTATOR_CALLHOOK(EditProjectile);
298 }
299
300 void spawnfunc_weapon_fireball (void)
301 {
302         weapon_defaultspawnfunc(WEP_FIREBALL);
303 }
304
305 float w_fireball(float req)
306 {
307         if (req == WR_AIM)
308         {
309                 self.BUTTON_ATCK = FALSE;
310                 self.BUTTON_ATCK2 = FALSE;
311                 if (self.bot_primary_fireballmooth == 0)
312                 {
313                         if(bot_aim(cvar("g_balance_fireball_primary_speed"), 0, cvar("g_balance_fireball_primary_lifetime"), FALSE))
314                         {
315                                 self.BUTTON_ATCK = TRUE;
316                                 if(random() < 0.02) self.bot_primary_fireballmooth = 0;
317                         }
318                 }
319                 else
320                 {
321                         if(bot_aim(cvar("g_balance_fireball_secondary_speed"), cvar("g_balance_fireball_secondary_speed_up"), cvar("g_balance_fireball_secondary_lifetime"), TRUE))
322                         {
323                                 self.BUTTON_ATCK2 = TRUE;
324                                 if(random() < 0.01) self.bot_primary_fireballmooth = 1;
325                         }
326                 }
327         }
328         else if (req == WR_THINK)
329         {
330                 if (self.BUTTON_ATCK)
331                 if (time >= self.fireball_primarytime)
332                 if (weapon_prepareattack(0, cvar("g_balance_fireball_primary_refire")))
333                 {
334                         W_Fireball_Attack1_Frame0();
335                         self.fireball_primarytime = time + cvar("g_balance_fireball_primary_refire2");
336                 }
337                 if (self.BUTTON_ATCK2)
338                 if (weapon_prepareattack(1, cvar("g_balance_fireball_secondary_refire")))
339                 {
340                         W_Fireball_Attack2();
341                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_fireball_secondary_animtime"), w_ready);
342                 }
343         }
344         else if (req == WR_PRECACHE)
345         {
346                 precache_model ("models/weapons/g_fireball.md3");
347                 precache_model ("models/weapons/v_fireball.md3");
348                 precache_model ("models/weapons/h_fireball.iqm");
349                 precache_model ("models/sphere/sphere.md3");
350                 precache_sound ("weapons/fireball_fire.wav");
351                 precache_sound ("weapons/fireball_fire2.wav");
352                 precache_sound ("weapons/fireball_prefire2.wav");
353         }
354         else if (req == WR_SETUP)
355                 weapon_setup(WEP_FIREBALL);
356         else if (req == WR_CHECKAMMO1)
357                 return self.ammo_fuel >= cvar("g_balance_fireball_primary_ammo");
358         else if (req == WR_CHECKAMMO2)
359                 return self.ammo_fuel >= cvar("g_balance_fireball_secondary_ammo");
360         else if (req == WR_RESETPLAYER)
361         {
362                 self.fireball_primarytime = time;
363         }
364         return TRUE;
365 };
366 #endif
367 #ifdef CSQC
368 float w_fireball(float req)
369 {
370         if(req == WR_IMPACTEFFECT)
371         {
372                 vector org2;
373                 if(w_deathtype & HITTYPE_SECONDARY)
374                 {
375                         // firemine goes out silently
376                 }
377                 else
378                 {
379                         org2 = w_org + w_backoff * 16;
380                         pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
381                         if(!w_issilent)
382                                 sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
383                 }
384         }
385         else if(req == WR_PRECACHE)
386         {
387                 precache_sound("weapons/fireball_impact2.wav");
388         }
389         else if (req == WR_SUICIDEMESSAGE)
390         {
391                 if(w_deathtype & HITTYPE_SECONDARY)
392                         w_deathtypestring = "%s forgot about some firemine";
393                 else
394                         w_deathtypestring = "%s should have used a smaller gun";
395         }
396         else if (req == WR_KILLMESSAGE)
397         {
398                 if(w_deathtype & HITTYPE_SECONDARY)
399                 {
400                         if(w_deathtype & HITTYPE_HEADSHOT)
401                                 w_deathtypestring = "%s tried to catch %s's firemine";
402                         else
403                                 w_deathtypestring = "%s fatefully ignored %s's firemine";
404                 }
405                 else
406                 {
407                         if(w_deathtype & HITTYPE_BOUNCE)
408                         {
409                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
410                                         w_deathtypestring = "%s could not hide from %s's fireball";
411                                 else // laser
412                                         w_deathtypestring = "%s saw the pretty lights of %s's fireball";
413                         }
414                         else if(w_deathtype & HITTYPE_SPLASH)
415                                 w_deathtypestring = "%s got too close to %s's fireball";
416                         else
417                                 w_deathtypestring = "%s tasted %s's fireball";
418                 }
419         }
420         return TRUE;
421 }
422 #endif
423 #endif