]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_fireball.qc
Merge remote-tracking branch 'origin/terencehill/misc_hud_fixes'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_fireball.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(FIREBALL, w_fireball, 0, 9, WEP_FLAG_SUPERWEAPON | 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 = func_null;
18         self.takedamage = DAMAGE_NO;
19
20         // 1. dist damage
21         d = (self.realowner.health + self.realowner.armorvalue);
22         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);
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, autocvar_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, autocvar_g_balance_fireball_primary_bfgradius); e; e = e.chain)
31                 if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.realowner || 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 / autocvar_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, autocvar_g_balance_fireball_primary_bfgdamage * points);
50
51                         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);
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.realowner) if(e.takedamage == DAMAGE_AIM) if(e.classname != "player" || !self.realowner || 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, autocvar_g_balance_fireball_primary_laserradius, autocvar_g_balance_fireball_primary_laserdamage, autocvar_g_balance_fireball_primary_laseredgedamage, autocvar_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                 
119         if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
120                 return; // g_projectiles_damage says to halt
121                 
122         self.health = self.health - damage;
123         if (self.health <= 0)
124         {
125                 self.cnt = 1;
126                 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
127         }
128 }
129
130 void W_Fireball_Attack1()
131 {
132         entity proj;
133
134         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", CH_WEAPON_A, autocvar_g_balance_fireball_primary_damage + autocvar_g_balance_fireball_primary_bfgdamage);
135
136         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
137
138         proj = spawn ();
139         proj.classname = "plasma_prim";
140         proj.owner = proj.realowner = self;
141         proj.bot_dodge = TRUE;
142         proj.bot_dodgerating = autocvar_g_balance_fireball_primary_damage;
143         proj.pushltime = time + autocvar_g_balance_fireball_primary_lifetime;
144         proj.use = W_Fireball_Explode;
145         proj.think = W_Fireball_Think;
146         proj.nextthink = time;
147         proj.health = autocvar_g_balance_fireball_primary_health;
148         proj.team = self.team;
149         proj.event_damage = W_Fireball_Damage;
150         proj.takedamage = DAMAGE_YES;
151         proj.damageforcescale = autocvar_g_balance_fireball_primary_damageforcescale;
152         PROJECTILE_MAKETRIGGER(proj);
153         proj.projectiledeathtype = WEP_FIREBALL;
154         setorigin(proj, w_shotorg);
155
156         proj.movetype = MOVETYPE_FLY;
157         W_SETUPPROJECTILEVELOCITY(proj, g_balance_fireball_primary);
158         proj.angles = vectoangles(proj.velocity);
159         proj.touch = W_Fireball_TouchExplode;
160         setsize(proj, '-16 -16 -16', '16 16 16');
161         proj.flags = FL_PROJECTILE;
162     proj.missile_flags = MIF_SPLASH | MIF_PROXY;
163     
164         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
165
166         other = proj; MUTATOR_CALLHOOK(EditProjectile);
167 }
168
169 void W_Fireball_AttackEffect(float i, vector f_diff)
170 {
171         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0, 0);
172         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
173         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
174 }
175
176 void W_Fireball_Attack1_Frame4()
177 {
178         W_Fireball_Attack1();
179         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, w_ready);
180 }
181
182 void W_Fireball_Attack1_Frame3()
183 {
184         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
185         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame4);
186 }
187
188 void W_Fireball_Attack1_Frame2()
189 {
190         W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
191         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame3);
192 }
193
194 void W_Fireball_Attack1_Frame1()
195 {
196         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
197         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame2);
198 }
199
200 void W_Fireball_Attack1_Frame0()
201 {
202         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
203         sound (self, CH_WEAPON_SINGLE, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
204         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_fireball_primary_animtime, W_Fireball_Attack1_Frame1);
205 }
206
207 void W_Firemine_Think()
208 {
209         if(time > self.pushltime)
210         {
211                 remove(self);
212                 return;
213         }
214
215         // make it "hot" once it leaves its owner
216         if(self.owner)
217         {
218                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > autocvar_g_balance_fireball_secondary_laserradius)
219                 {
220                         self.cnt += 1;
221                         if(self.cnt == 3)
222                                 self.owner = world;
223                 }
224                 else
225                         self.cnt = 0;
226         }
227
228         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);
229
230         self.nextthink = time + 0.1;
231 }
232
233 void W_Firemine_Touch (void)
234 {
235         PROJECTILE_TOUCH;
236         if (other.takedamage == DAMAGE_AIM)
237         if(Fire_AddDamage(other, self.realowner, autocvar_g_balance_fireball_secondary_damage, autocvar_g_balance_fireball_secondary_damagetime, self.projectiledeathtype) >= 0)
238         {
239                 remove(self);
240                 return;
241         }
242         self.projectiledeathtype |= HITTYPE_BOUNCE;
243 }
244
245 void W_Fireball_Attack2()
246 {
247         entity proj;
248         vector f_diff;
249         float c;
250
251         c = mod(self.bulletcounter, 4);
252         switch(c)
253         {
254                 case 0:
255                         f_diff = '-1.25 -3.75 0';
256                         break;
257                 case 1:
258                         f_diff = '+1.25 -3.75 0';
259                         break;
260                 case 2:
261                         f_diff = '-1.25 +3.75 0';
262                         break;
263                 case 3:
264                 default:
265                         f_diff = '+1.25 +3.75 0';
266                         break;
267         }
268         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", CH_WEAPON_A, autocvar_g_balance_fireball_secondary_damage);
269         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
270         w_shotorg = trace_endpos;
271
272         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
273
274         proj = spawn ();
275         proj.owner = proj.realowner = self;
276         proj.classname = "grenade";
277         proj.bot_dodge = TRUE;
278         proj.bot_dodgerating = autocvar_g_balance_fireball_secondary_damage;
279         proj.movetype = MOVETYPE_BOUNCE;
280         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
281         proj.touch = W_Firemine_Touch;
282         PROJECTILE_MAKETRIGGER(proj);
283         setsize(proj, '-4 -4 -4', '4 4 4');
284         setorigin(proj, w_shotorg);
285         proj.think = W_Firemine_Think;
286         proj.nextthink = time;
287         proj.damageforcescale = autocvar_g_balance_fireball_secondary_damageforcescale;
288         proj.pushltime = time + autocvar_g_balance_fireball_secondary_lifetime;
289         W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_fireball_secondary);
290
291         proj.angles = vectoangles(proj.velocity);
292         proj.flags = FL_PROJECTILE;
293     proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
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         //float ammo_amount;
308         if (req == WR_AIM)
309         {
310                 self.BUTTON_ATCK = FALSE;
311                 self.BUTTON_ATCK2 = FALSE;
312                 if (self.bot_primary_fireballmooth == 0)
313                 {
314                         if(bot_aim(autocvar_g_balance_fireball_primary_speed, 0, autocvar_g_balance_fireball_primary_lifetime, FALSE))
315                         {
316                                 self.BUTTON_ATCK = TRUE;
317                                 if(random() < 0.02) self.bot_primary_fireballmooth = 0;
318                         }
319                 }
320                 else
321                 {
322                         if(bot_aim(autocvar_g_balance_fireball_secondary_speed, autocvar_g_balance_fireball_secondary_speed_up, autocvar_g_balance_fireball_secondary_lifetime, TRUE))
323                         {
324                                 self.BUTTON_ATCK2 = TRUE;
325                                 if(random() < 0.01) self.bot_primary_fireballmooth = 1;
326                         }
327                 }
328         }
329         else if (req == WR_THINK)
330         {
331                 if (self.BUTTON_ATCK)
332                 {
333                         if (time >= self.fireball_primarytime)
334                         if (weapon_prepareattack(0, autocvar_g_balance_fireball_primary_refire))
335                         {
336                                 W_Fireball_Attack1_Frame0();
337                                 self.fireball_primarytime = time + autocvar_g_balance_fireball_primary_refire2 * W_WeaponRateFactor();
338                         }
339                 }
340                 else if (self.BUTTON_ATCK2)
341                 {
342                         if (weapon_prepareattack(1, autocvar_g_balance_fireball_secondary_refire))
343                         {
344                                 W_Fireball_Attack2();
345                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_fireball_secondary_animtime, w_ready);
346                         }
347                 }
348         }
349         else if (req == WR_PRECACHE)
350         {
351                 precache_model ("models/weapons/g_fireball.md3");
352                 precache_model ("models/weapons/v_fireball.md3");
353                 precache_model ("models/weapons/h_fireball.iqm");
354                 precache_model ("models/sphere/sphere.md3");
355                 precache_sound ("weapons/fireball_fire.wav");
356                 precache_sound ("weapons/fireball_fire2.wav");
357                 precache_sound ("weapons/fireball_prefire2.wav");
358                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
359         }
360         else if (req == WR_SETUP)
361         {
362                 weapon_setup(WEP_FIREBALL);
363                 self.current_ammo = ammo_none;
364         }
365         else if (req == WR_CHECKAMMO1)
366         {
367                 return 1;
368         }
369         else if (req == WR_CHECKAMMO2)
370         {
371                 return 1;
372         }
373         else if (req == WR_RESETPLAYER)
374         {
375                 self.fireball_primarytime = time;
376         }
377         else if (req == WR_SUICIDEMESSAGE)
378         {
379                 if(w_deathtype & HITTYPE_SECONDARY)
380                         return WEAPON_FIREBALL_SUICIDE_FIREMINE;
381                 else
382                         return WEAPON_FIREBALL_SUICIDE_BLAST;
383         }
384         else if (req == WR_KILLMESSAGE)
385         {
386                 if(w_deathtype & HITTYPE_SECONDARY)
387                 {
388                         return WEAPON_FIREBALL_MURDER_FIREMINE;
389                 }
390                 else
391                 {
392                         return WEAPON_FIREBALL_MURDER_BLAST;
393                 }
394         }
395         return TRUE;
396 }
397 #endif
398 #ifdef CSQC
399 float w_fireball(float req)
400 {
401         if(req == WR_IMPACTEFFECT)
402         {
403                 vector org2;
404                 if(w_deathtype & HITTYPE_SECONDARY)
405                 {
406                         // firemine goes out silently
407                 }
408                 else
409                 {
410                         org2 = w_org + w_backoff * 16;
411                         pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
412                         if(!w_issilent)
413                                 sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
414                 }
415         }
416         else if(req == WR_PRECACHE)
417         {
418                 precache_sound("weapons/fireball_impact2.wav");
419         }
420
421         return TRUE;
422 }
423 #endif
424 #endif