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