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