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