]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_fireball.qc
[NOT FOR 2.5.2] fireball now uses less alpha on shockwave
[divverent/nexuiz.git] / data / qcsrc / server / w_fireball.qc
1 .float bot_secondary_fireballmooth; // whatever a mooth is
2 .vector fireball_impactvec;
3
4 void W_Fireball_Explode (void)
5 {
6         entity e;
7         float dist;
8         float points;
9         vector dir;
10         float d;
11
12         self.event_damage = SUB_Null;
13
14         // 1. dist damage
15         d = (self.owner.health + self.owner.armorvalue);
16         RadiusDamage (self, self.realowner, cvar("g_balance_fireball_secondary_damage"), cvar("g_balance_fireball_secondary_edgedamage"), cvar("g_balance_fireball_secondary_radius"), world, cvar("g_balance_fireball_secondary_force"), self.projectiledeathtype, other);
17         if(self.realowner.health + self.realowner.armorvalue >= d)
18         if(!self.cnt)
19         {
20                 modeleffect_spawn("models/sphere/sphere.md3", 0, 0, self.origin, '0 0 0', '0 0 0', '0 0 0', 0, cvar("g_balance_fireball_secondary_bfgradius"), 0.2, 0.05, 0.25);
21
22                 // 2. bfg effect
23                 FOR_EACH_PLAYER(e) if(e != self.owner) if(e.takedamage) if(!self.owner || IsDifferentTeam(e, self))
24                 {
25                         // can we see fireball?
26                         traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
27                         if(trace_startsolid || trace_fraction != 1)
28                                 continue;
29                         // can we see player who shot fireball?
30                         traceline(e.origin + e.view_ofs, self.realowner.origin + self.realowner.view_ofs, MOVE_NORMAL, e);
31                         if(trace_ent != self.realowner)
32                         if(trace_startsolid || trace_fraction != 1)
33                                 continue;
34                         dist = vlen(self.origin - e.origin - e.view_ofs);
35                         points = (1 - sqrt(dist / cvar("g_balance_fireball_secondary_bfgradius")));
36                         if(points <= 0)
37                                 continue;
38                         dir = normalize(e.origin + e.view_ofs - self.origin);
39                         Damage(e, self, self.realowner, cvar("g_balance_fireball_secondary_bfgdamage") * points, self.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, cvar("g_balance_fireball_secondary_bfgforce") * dir);
40                         pointparticles(particleeffectnum("fireball_bfgdamage"), e.origin, -1 * dir, 1);
41                 }
42         }
43
44         remove (self);
45 }
46
47 void W_Fireball_TouchExplode (void)
48 {
49         PROJECTILE_TOUCH;
50         W_Fireball_Explode ();
51 }
52
53 void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage, float burntime)
54 {
55         entity e;
56         float d;
57         vector p;
58
59         RandomSelection_Init();
60         FOR_EACH_PLAYER(e) if(e != self.owner) if(e.takedamage) if(!self.owner || IsDifferentTeam(e, self))
61         {
62                 p = e.origin;
63                 p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
64                 p_y += e.mins_y + random() * (e.maxs_y - e.mins_y);
65                 p_z += e.mins_z + random() * (e.maxs_z - e.mins_z);
66                 d = vlen(self.origin - p);
67                 if(d < dist)
68                 {
69                         traceline(p, self.origin, MOVE_NORMAL, e);
70                         if(trace_startsolid || trace_fraction != 1)
71                                 continue;
72                         e.fireball_impactvec = p;
73                         RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
74                 }
75         }
76         if(RandomSelection_chosen_ent)
77         {
78                 d = vlen(self.origin - RandomSelection_chosen_ent.fireball_impactvec);
79                 d = damage + (edgedamage - damage) * (d / dist);
80                 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
81                 //trailparticles(self, particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
82                 pointparticles(particleeffectnum("fireball_laser"), self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
83         }
84 }
85
86 void W_Fireball_Think()
87 {
88         if(time > self.pushltime)
89         {
90                 self.cnt = 1;
91                 W_Fireball_Explode();
92                 return;
93         }
94
95         W_Fireball_LaserPlay(0.1, cvar("g_balance_fireball_secondary_laserradius"), cvar("g_balance_fireball_secondary_laserdamage"), cvar("g_balance_fireball_secondary_laseredgedamage"), cvar("g_balance_fireball_secondary_laserburntime"));
96
97         self.nextthink = time + 0.1;
98 }
99
100 void W_Fireball_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
101 {
102         if(self.health <= 0)
103                 return;
104         self.health = self.health - damage;
105         if (self.health <= 0)
106         {
107                 self.cnt = 1;
108                 W_PrepareExplosionByDamage(attacker, W_Fireball_Explode);
109         }
110 }
111
112 void W_Fireball_Attack2()
113 {
114         local entity proj;
115
116         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 2, "weapons/fireball_fire2.wav", cvar("g_balance_fireball_secondary_damage"));
117
118         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
119
120         proj = spawn ();
121         proj.classname = "plasma_prim";
122         proj.owner = proj.realowner = self;
123         proj.bot_dodge = TRUE;
124         proj.bot_dodgerating = cvar("g_balance_fireball_secondary_damage");
125         proj.pushltime = time + cvar("g_balance_fireball_secondary_lifetime");
126         proj.use = W_Fireball_Explode;
127         proj.think = W_Fireball_Think;
128         proj.nextthink = time;
129         proj.health = cvar("g_balance_fireball_secondary_health");
130         proj.team = self.team;
131         proj.event_damage = W_Fireball_Damage;
132         proj.damageforcescale = cvar("g_balance_fireball_secondary_damageforcescale");
133         PROJECTILE_MAKETRIGGER(proj);
134         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
135         setorigin(proj, w_shotorg);
136
137         proj.movetype = MOVETYPE_FLY;
138         proj.velocity = w_shotdir * cvar("g_balance_fireball_secondary_speed");
139         W_SetupProjectileVelocity(proj);
140         proj.angles = vectoangles(proj.velocity);
141         proj.touch = W_Fireball_TouchExplode;
142         setsize(proj, '-16 -16 -16', '16 16 16');
143         proj.flags = FL_PROJECTILE;
144
145         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
146 }
147
148 void W_Fireball_AttackEffect(float i, vector f_diff)
149 {
150         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0);
151         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
152         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
153 }
154
155 void W_Fireball_Attack2_Frame4()
156 {
157         W_Fireball_Attack2();
158         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), w_ready);
159 }
160
161 void W_Fireball_Attack2_Frame3()
162 {
163         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
164         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame4);
165 }
166
167 void W_Fireball_Attack2_Frame2()
168 {
169         W_Fireball_AttackEffect(0, '-1.25 +3.75 0');
170         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame3);
171 }
172
173 void W_Fireball_Attack2_Frame1()
174 {
175         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
176         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame2);
177 }
178
179 void W_Fireball_Attack2_Frame0()
180 {
181         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
182                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_fireball_secondary_ammo");
183
184         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
185         sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
186         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame1);
187 }
188
189 void W_Firemine_Think()
190 {
191         if(time > self.pushltime)
192         {
193                 remove(self);
194                 return;
195         }
196
197         // make it "hot" once it leaves its owner
198         if(self.owner)
199                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > cvar("g_balance_fireball_primary_laserradius"))
200                         self.owner = world;
201
202         W_Fireball_LaserPlay(0.1, cvar("g_balance_fireball_primary_laserradius"), cvar("g_balance_fireball_primary_laserdamage"), cvar("g_balance_fireball_primary_laseredgedamage"), cvar("g_balance_fireball_primary_laserburntime"));
203
204         self.nextthink = time + 0.1;
205 }
206
207 void W_Firemine_Touch (void)
208 {
209         PROJECTILE_TOUCH;
210         if (other.takedamage == DAMAGE_AIM)
211         {
212                 Fire_AddDamage(other, self.realowner, cvar("g_balance_fireball_primary_damage"), cvar("g_balance_fireball_primary_damagetime"), self.projectiledeathtype | HITTYPE_HEADSHOT);
213                 remove(self);
214         }
215         else
216         {
217                 self.projectiledeathtype |= HITTYPE_BOUNCE;
218         }
219 }
220
221 void W_Fireball_Attack1()
222 {
223         local entity proj;
224         vector f_diff;
225         float c;
226
227         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
228                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_fireball_primary_ammo");
229
230         c = mod(self.bulletcounter, 4);
231         switch(c)
232         {
233                 case 0:
234                         f_diff = '-1.25 -3.75 0';
235                         break;
236                 case 1:
237                         f_diff = '+1.25 -3.75 0';
238                         break;
239                 case 2:
240                         f_diff = '-1.25 +3.75 0';
241                         break;
242                 case 3:
243                 default:
244                         f_diff = '+1.25 +3.75 0';
245                         break;
246         }
247         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", cvar("g_balance_fireball_primary_damage"));
248         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
249         w_shotorg = trace_endpos;
250
251         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
252
253         proj = spawn ();
254         proj.owner = proj.realowner = self;
255         proj.classname = "grenade";
256         proj.bot_dodge = TRUE;
257         proj.bot_dodgerating = cvar("g_balance_fireball_primary_damage");
258         proj.movetype = MOVETYPE_BOUNCE;
259         proj.projectiledeathtype = WEP_FIREBALL;
260         proj.touch = W_Firemine_Touch;
261         PROJECTILE_MAKETRIGGER(proj);
262         setsize(proj, '-4 -4 -4', '4 4 4');
263         setorigin(proj, w_shotorg);
264         proj.think = W_Firemine_Think;
265         proj.nextthink = time;
266         proj.damageforcescale = cvar("g_balance_fireball_primary_damageforcescale");
267         proj.velocity = w_shotdir * cvar("g_balance_fireball_primary_speed") + v_up * cvar("g_balance_fireball_primary_speed_up");
268         proj.pushltime = time + cvar("g_balance_fireball_primary_lifetime");
269         W_SetupProjectileVelocity(proj);
270
271         proj.angles = vectoangles(proj.velocity);
272         proj.flags = FL_PROJECTILE;
273
274         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
275 }
276
277 void spawnfunc_weapon_fireball (void)
278 {
279         weapon_defaultspawnfunc(WEP_FIREBALL);
280 }
281
282 float w_fireball(float req)
283 {
284         if (req == WR_AIM)
285         {
286                 self.BUTTON_ATCK = FALSE;
287                 self.BUTTON_ATCK2 = FALSE;
288                 if (self.bot_secondary_fireballmooth == 0)
289                 {
290                         if(bot_aim(cvar("g_balance_fireball_primary_speed"), cvar("g_balance_fireball_primary_speed_up"), cvar("g_balance_fireball_primary_lifetime"), TRUE))
291                         {
292                                 self.BUTTON_ATCK = TRUE;
293                                 if(random() < 0.01) self.bot_secondary_fireballmooth = 1;
294                         }
295                 }
296                 else
297                 {
298                         if(bot_aim(cvar("g_balance_fireball_secondary_speed"), 0, cvar("g_balance_fireball_secondary_lifetime"), FALSE))
299                         {
300                                 self.BUTTON_ATCK2 = TRUE;
301                                 if(random() < 0.02) self.bot_secondary_fireballmooth = 0;
302                         }
303                 }
304         }
305         else if (req == WR_THINK)
306         {
307                 if (self.BUTTON_ATCK)
308                 if (weapon_prepareattack(0, cvar("g_balance_fireball_primary_refire")))
309                 {
310                         W_Fireball_Attack1();
311                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_fireball_primary_animtime"), w_ready);
312                 }
313                 if (self.BUTTON_ATCK2)
314                 if (weapon_prepareattack(1, cvar("g_balance_fireball_secondary_refire")))
315                 {
316                         W_Fireball_Attack2_Frame0();
317                 }
318         }
319         else if (req == WR_PRECACHE)
320         {
321                 precache_model ("models/weapons/g_fireball.md3");
322                 precache_model ("models/weapons/v_fireball.md3");
323                 precache_model ("models/weapons/h_fireball.dpm");
324                 precache_model ("models/sphere/sphere.md3");
325                 precache_sound ("weapons/fireball_fire.wav");
326                 precache_sound ("weapons/fireball_fire2.wav");
327                 precache_sound ("weapons/fireball_prefire2.wav");
328         }
329         else if (req == WR_SETUP)
330                 weapon_setup(WEP_FIREBALL);
331         else if (req == WR_CHECKAMMO1)
332                 return self.ammo_rockets >= cvar("g_balance_fireball_primary_ammo");
333         else if (req == WR_CHECKAMMO2)
334                 return self.ammo_rockets >= cvar("g_balance_fireball_secondary_ammo");
335         else if (req == WR_SUICIDEMESSAGE)
336         {
337                 if(w_deathtype & HITTYPE_SECONDARY)
338                         w_deathtypestring = "should have used a smaller gun";
339                 else
340                         w_deathtypestring = "forgot about some firemine";
341         }
342         else if (req == WR_KILLMESSAGE)
343         {
344                 if(w_deathtype & HITTYPE_SECONDARY)
345                 {
346                         if(w_deathtype & HITTYPE_BOUNCE)
347                         {
348                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
349                                 {
350                                         w_deathtypestring = "could not hide from #'s fireball";
351                                 }
352                                 else // laser
353                                 {
354                                         w_deathtypestring = "saw the pretty lights of #'s fireball";
355                                 }
356                         }
357                         else if(w_deathtype & HITTYPE_SPLASH)
358                                 w_deathtypestring = "got too close to #'s fireball";
359                         else
360                                 w_deathtypestring = "tasted #'s fireball";
361                 }
362                 else
363                 {
364                         if(w_deathtype & HITTYPE_HEADSHOT)
365                                 w_deathtypestring = "tried to catch #'s firemine";
366                         else
367                                 w_deathtypestring = "fatefully ignored #'s firemine";
368                 }
369         }
370         return TRUE;
371 };