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