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