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