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