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