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