]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/fireball.qc
8d17a247d4c36c8408473c8c7b595e96c168ca7b
[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[MAX_WEAPONSLOTS];
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(entity this, entity directhitentity)
66 {
67         entity e;
68         float dist;
69         float points;
70         vector dir;
71         float d;
72
73         this.event_damage = func_null;
74         this.takedamage = DAMAGE_NO;
75
76         // 1. dist damage
77         d = (this.realowner.health + this.realowner.armorvalue);
78         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);
79         if(this.realowner.health + this.realowner.armorvalue >= d)
80         if(!this.cnt)
81         {
82                 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);
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(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain)
87                 if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
88                 {
89                         // can we see fireball?
90                         traceline(e.origin + e.view_ofs, this.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, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e);
95                         if(trace_ent != this.realowner)
96                         if(/* trace_startsolid || */ trace_fraction != 1)
97                                 continue;
98                         dist = vlen(this.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 - this.origin);
103
104                         if(accuracy_isgooddamage(this.realowner, e))
105                                 accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points);
106
107                         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);
108                         Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1);
109                 }
110         }
111
112         delete(this);
113 }
114
115 void W_Fireball_Explode_think(entity this)
116 {
117         W_Fireball_Explode(this, NULL);
118 }
119
120 void W_Fireball_Explode_use(entity this, entity actor, entity trigger)
121 {
122         W_Fireball_Explode(this, trigger);
123 }
124
125 void W_Fireball_TouchExplode(entity this, entity toucher)
126 {
127         PROJECTILE_TOUCH(this, toucher);
128         W_Fireball_Explode(this, toucher);
129 }
130
131 void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float edgedamage, float burntime)
132 {
133         entity e;
134         float d;
135         vector p;
136
137         if(damage <= 0)
138                 return;
139
140         RandomSelection_Init();
141         for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain)
142         if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this))
143         {
144                 p = e.origin;
145                 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
146                 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
147                 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
148                 d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p);
149                 if(d < dist)
150                 {
151                         e.fireball_impactvec = p;
152                         RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
153                 }
154         }
155         if(RandomSelection_chosen_ent)
156         {
157                 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec);
158                 d = damage + (edgedamage - damage) * (d / dist);
159                 Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE);
160                 //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec);
161                 Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1);
162         }
163 }
164
165 void W_Fireball_Think(entity this)
166 {
167         if(time > this.pushltime)
168         {
169                 this.cnt = 1;
170                 this.projectiledeathtype |= HITTYPE_SPLASH;
171                 W_Fireball_Explode(this, NULL);
172                 return;
173         }
174
175         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));
176
177         this.nextthink = time + 0.1;
178 }
179
180 void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
181 {
182         if(this.health <= 0)
183                 return;
184
185         if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
186                 return; // g_projectiles_damage says to halt
187
188         this.health = this.health - damage;
189         if(this.health <= 0)
190         {
191                 this.cnt = 1;
192                 W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think);
193         }
194 }
195
196 void W_Fireball_Attack1(entity actor, .entity weaponentity)
197 {
198         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));
199
200         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
201
202         entity proj = new(plasma_prim);
203         proj.owner = proj.realowner = actor;
204         proj.bot_dodge = true;
205         proj.bot_dodgerating = WEP_CVAR_PRI(fireball, damage);
206         proj.pushltime = time + WEP_CVAR_PRI(fireball, lifetime);
207         proj.use = W_Fireball_Explode_use;
208         setthink(proj, W_Fireball_Think);
209         proj.nextthink = time;
210         proj.health = WEP_CVAR_PRI(fireball, health);
211         proj.team = actor.team;
212         proj.event_damage = W_Fireball_Damage;
213         proj.takedamage = DAMAGE_YES;
214         proj.damageforcescale = WEP_CVAR_PRI(fireball, damageforcescale);
215         PROJECTILE_MAKETRIGGER(proj);
216         proj.projectiledeathtype = WEP_FIREBALL.m_id;
217         setorigin(proj, w_shotorg);
218
219         set_movetype(proj, MOVETYPE_FLY);
220         W_SetupProjVelocity_PRI(proj, fireball);
221         proj.angles = vectoangles(proj.velocity);
222         settouch(proj, W_Fireball_TouchExplode);
223         setsize(proj, '-16 -16 -16', '16 16 16');
224         proj.flags = FL_PROJECTILE;
225         IL_PUSH(g_projectiles, proj);
226     proj.missile_flags = MIF_SPLASH | MIF_PROXY;
227
228         CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true);
229
230         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
231 }
232
233 void W_Fireball_AttackEffect(entity actor, .entity weaponentity, float i, vector f_diff)
234 {
235         W_SetupShot_ProjectileSize(actor, weaponentity, '-16 -16 -16', '16 16 16', false, 0, SND_Null, 0, 0);
236         w_shotorg += f_diff.x * v_up + f_diff.y * v_right;
237         Send_Effect(EFFECT_FIREBALL_PRE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
238 }
239
240 void W_Fireball_Attack1_Frame4(Weapon thiswep, entity actor, .entity weaponentity, int fire)
241 {
242         W_Fireball_Attack1(actor, weaponentity);
243         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), w_ready);
244 }
245
246 void W_Fireball_Attack1_Frame3(Weapon thiswep, entity actor, .entity weaponentity, int fire)
247 {
248         W_Fireball_AttackEffect(actor, weaponentity, 0, '+1.25 +3.75 0');
249         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame4);
250 }
251
252 void W_Fireball_Attack1_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
253 {
254         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 +3.75 0');
255         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame3);
256 }
257
258 void W_Fireball_Attack1_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
259 {
260         W_Fireball_AttackEffect(actor, weaponentity, 1, '+1.25 -3.75 0');
261         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame2);
262 }
263
264 void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentity, int fire)
265 {
266         W_Fireball_AttackEffect(actor, weaponentity, 0, '-1.25 -3.75 0');
267         sound(actor, CH_WEAPON_SINGLE, SND_FIREBALL_PREFIRE2, VOL_BASE, ATTEN_NORM);
268         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(fireball, animtime), W_Fireball_Attack1_Frame1);
269 }
270
271 void W_Fireball_Firemine_Think(entity this)
272 {
273         if(time > this.pushltime)
274         {
275                 delete(this);
276                 return;
277         }
278
279         // make it "hot" once it leaves its owner
280         if(this.owner)
281         {
282                 if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius)))
283                 {
284                         this.cnt += 1;
285                         if(this.cnt == 3)
286                                 this.owner = NULL;
287                 }
288                 else
289                         this.cnt = 0;
290         }
291
292         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));
293
294         this.nextthink = time + 0.1;
295 }
296
297 void W_Fireball_Firemine_Touch(entity this, entity toucher)
298 {
299         PROJECTILE_TOUCH(this, toucher);
300         if(toucher.takedamage == DAMAGE_AIM)
301         if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0)
302         {
303                 delete(this);
304                 return;
305         }
306         this.projectiledeathtype |= HITTYPE_BOUNCE;
307 }
308
309 void W_Fireball_Attack2(entity actor, .entity weaponentity)
310 {
311         entity proj;
312         vector f_diff;
313         float c;
314
315         c = actor.bulletcounter % 4;
316         switch(c)
317         {
318                 case 0:
319                         f_diff = '-1.25 -3.75 0';
320                         break;
321                 case 1:
322                         f_diff = '+1.25 -3.75 0';
323                         break;
324                 case 2:
325                         f_diff = '-1.25 +3.75 0';
326                         break;
327                 case 3:
328                 default:
329                         f_diff = '+1.25 +3.75 0';
330                         break;
331         }
332         W_SetupShot_ProjectileSize(actor, weaponentity, '-4 -4 -4', '4 4 4', false, 2, SND_FIREBALL_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(fireball, damage));
333         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, actor);
334         w_shotorg = trace_endpos;
335
336         Send_Effect(EFFECT_FIREBALL_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
337
338         proj = new(grenade);
339         proj.owner = proj.realowner = actor;
340         proj.bot_dodge = true;
341         proj.bot_dodgerating = WEP_CVAR_SEC(fireball, damage);
342         set_movetype(proj, MOVETYPE_BOUNCE);
343         proj.projectiledeathtype = WEP_FIREBALL.m_id | HITTYPE_SECONDARY;
344         settouch(proj, W_Fireball_Firemine_Touch);
345         PROJECTILE_MAKETRIGGER(proj);
346         setsize(proj, '-4 -4 -4', '4 4 4');
347         setorigin(proj, w_shotorg);
348         setthink(proj, W_Fireball_Firemine_Think);
349         proj.nextthink = time;
350         proj.damageforcescale = WEP_CVAR_SEC(fireball, damageforcescale);
351         proj.pushltime = time + WEP_CVAR_SEC(fireball, lifetime);
352         W_SetupProjVelocity_UP_SEC(proj, fireball);
353
354         proj.angles = vectoangles(proj.velocity);
355         proj.flags = FL_PROJECTILE;
356         IL_PUSH(g_projectiles, proj);
357     proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
358
359         CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true);
360
361         MUTATOR_CALLHOOK(EditProjectile, actor, proj);
362 }
363
364 METHOD(Fireball, wr_aim, void(entity thiswep, entity actor))
365 {
366     PHYS_INPUT_BUTTON_ATCK(actor) = false;
367     PHYS_INPUT_BUTTON_ATCK2(actor) = false;
368     if(actor.bot_primary_fireballmooth == 0)
369     {
370         if(bot_aim(actor, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false))
371         {
372             PHYS_INPUT_BUTTON_ATCK(actor) = true;
373             if(random() < 0.02) actor.bot_primary_fireballmooth = 0;
374         }
375     }
376     else
377     {
378         if(bot_aim(actor, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true))
379         {
380             PHYS_INPUT_BUTTON_ATCK2(actor) = true;
381             if(random() < 0.01) actor.bot_primary_fireballmooth = 1;
382         }
383     }
384 }
385 METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
386 {
387     if(fire & 1)
388     {
389         int slot = weaponslot(weaponentity);
390         if(time >= actor.fireball_primarytime[slot])
391         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire)))
392         {
393             W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire);
394             actor.fireball_primarytime[slot] = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor);
395         }
396     }
397     else if(fire & 2)
398     {
399         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire)))
400         {
401             W_Fireball_Attack2(actor, weaponentity);
402             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready);
403         }
404     }
405 }
406 METHOD(Fireball, wr_setup, void(entity thiswep, entity actor))
407 {
408     actor.ammo_field = ammo_none;
409 }
410 METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor))
411 {
412     return true; // infinite ammo
413 }
414 METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor))
415 {
416     return true; // fireball has infinite ammo
417 }
418 METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor))
419 {
420         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
421         actor.fireball_primarytime[slot] = time;
422 }
423 METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep))
424 {
425     if(w_deathtype & HITTYPE_SECONDARY)
426         return WEAPON_FIREBALL_SUICIDE_FIREMINE;
427     else
428         return WEAPON_FIREBALL_SUICIDE_BLAST;
429 }
430 METHOD(Fireball, wr_killmessage, Notification(entity thiswep))
431 {
432     if(w_deathtype & HITTYPE_SECONDARY)
433         return WEAPON_FIREBALL_MURDER_FIREMINE;
434     else
435         return WEAPON_FIREBALL_MURDER_BLAST;
436 }
437
438 #endif
439 #ifdef CSQC
440
441 METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor))
442 {
443     vector org2;
444     if(w_deathtype & HITTYPE_SECONDARY)
445     {
446         // firemine goes out silently
447     }
448     else
449     {
450         org2 = w_org + w_backoff * 16;
451         pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1);
452         if(!w_issilent)
453             sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom
454     }
455 }
456
457 #endif
458 #endif