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