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