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