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