]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_fireball.qc
try to work around dead bodies
[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                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > cvar("g_balance_fireball_primary_laserradius"))
205                         self.owner = world;
206
207         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"));
208
209         self.nextthink = time + 0.1;
210 }
211
212 void W_Firemine_Touch (void)
213 {
214         PROJECTILE_TOUCH;
215         if (other.takedamage == DAMAGE_AIM)
216         if(Fire_AddDamage(other, self.realowner, cvar("g_balance_fireball_primary_damage"), cvar("g_balance_fireball_primary_damagetime"), self.projectiledeathtype | HITTYPE_HEADSHOT) >= 0)
217         {
218                 remove(self);
219                 return;
220         }
221         self.projectiledeathtype |= HITTYPE_BOUNCE;
222 }
223
224 void W_Fireball_Attack1()
225 {
226         local entity proj;
227         vector f_diff;
228         float c;
229
230         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
231                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_fireball_primary_ammo");
232
233         c = mod(self.bulletcounter, 4);
234         switch(c)
235         {
236                 case 0:
237                         f_diff = '-1.25 -3.75 0';
238                         break;
239                 case 1:
240                         f_diff = '+1.25 -3.75 0';
241                         break;
242                 case 2:
243                         f_diff = '-1.25 +3.75 0';
244                         break;
245                 case 3:
246                 default:
247                         f_diff = '+1.25 +3.75 0';
248                         break;
249         }
250         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", cvar("g_balance_fireball_primary_damage"));
251         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
252         w_shotorg = trace_endpos;
253
254         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
255
256         proj = spawn ();
257         proj.owner = proj.realowner = self;
258         proj.classname = "grenade";
259         proj.bot_dodge = TRUE;
260         proj.bot_dodgerating = cvar("g_balance_fireball_primary_damage");
261         proj.movetype = MOVETYPE_BOUNCE;
262         proj.projectiledeathtype = WEP_FIREBALL;
263         proj.touch = W_Firemine_Touch;
264         PROJECTILE_MAKETRIGGER(proj);
265         setsize(proj, '-4 -4 -4', '4 4 4');
266         setorigin(proj, w_shotorg);
267         proj.think = W_Firemine_Think;
268         proj.nextthink = time;
269         proj.damageforcescale = cvar("g_balance_fireball_primary_damageforcescale");
270         proj.velocity = w_shotdir * cvar("g_balance_fireball_primary_speed") + v_up * cvar("g_balance_fireball_primary_speed_up");
271         proj.pushltime = time + cvar("g_balance_fireball_primary_lifetime");
272         W_SetupProjectileVelocity(proj);
273
274         proj.angles = vectoangles(proj.velocity);
275         proj.flags = FL_PROJECTILE;
276
277         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
278 }
279
280 void spawnfunc_weapon_fireball (void)
281 {
282         weapon_defaultspawnfunc(WEP_FIREBALL);
283 }
284
285 float w_fireball(float req)
286 {
287         if (req == WR_AIM)
288         {
289                 self.BUTTON_ATCK = FALSE;
290                 self.BUTTON_ATCK2 = FALSE;
291                 if (self.bot_secondary_fireballmooth == 0)
292                 {
293                         if(bot_aim(cvar("g_balance_fireball_primary_speed"), cvar("g_balance_fireball_primary_speed_up"), cvar("g_balance_fireball_primary_lifetime"), TRUE))
294                         {
295                                 self.BUTTON_ATCK = TRUE;
296                                 if(random() < 0.01) self.bot_secondary_fireballmooth = 1;
297                         }
298                 }
299                 else
300                 {
301                         if(bot_aim(cvar("g_balance_fireball_secondary_speed"), 0, cvar("g_balance_fireball_secondary_lifetime"), FALSE))
302                         {
303                                 self.BUTTON_ATCK2 = TRUE;
304                                 if(random() < 0.02) self.bot_secondary_fireballmooth = 0;
305                         }
306                 }
307         }
308         else if (req == WR_THINK)
309         {
310                 if (self.BUTTON_ATCK)
311                 if (weapon_prepareattack(0, cvar("g_balance_fireball_primary_refire")))
312                 {
313                         W_Fireball_Attack1();
314                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_fireball_primary_animtime"), w_ready);
315                 }
316                 if (self.BUTTON_ATCK2)
317                 if (weapon_prepareattack(1, cvar("g_balance_fireball_secondary_refire")))
318                 {
319                         W_Fireball_Attack2_Frame0();
320                 }
321         }
322         else if (req == WR_PRECACHE)
323         {
324                 precache_model ("models/weapons/g_fireball.md3");
325                 precache_model ("models/weapons/v_fireball.md3");
326                 precache_model ("models/weapons/h_fireball.dpm");
327                 precache_model ("models/sphere/sphere.md3");
328                 precache_sound ("weapons/fireball_fire.wav");
329                 precache_sound ("weapons/fireball_fire2.wav");
330                 precache_sound ("weapons/fireball_prefire2.wav");
331         }
332         else if (req == WR_SETUP)
333                 weapon_setup(WEP_FIREBALL);
334         else if (req == WR_CHECKAMMO1)
335                 return self.ammo_rockets >= cvar("g_balance_fireball_primary_ammo");
336         else if (req == WR_CHECKAMMO2)
337                 return self.ammo_rockets >= cvar("g_balance_fireball_secondary_ammo");
338         else if (req == WR_SUICIDEMESSAGE)
339         {
340                 if(w_deathtype & HITTYPE_SECONDARY)
341                         w_deathtypestring = "should have used a smaller gun";
342                 else
343                         w_deathtypestring = "forgot about some firemine";
344         }
345         else if (req == WR_KILLMESSAGE)
346         {
347                 if(w_deathtype & HITTYPE_SECONDARY)
348                 {
349                         if(w_deathtype & HITTYPE_BOUNCE)
350                         {
351                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
352                                 {
353                                         w_deathtypestring = "could not hide from #'s fireball";
354                                 }
355                                 else // laser
356                                 {
357                                         w_deathtypestring = "saw the pretty lights of #'s fireball";
358                                 }
359                         }
360                         else if(w_deathtype & HITTYPE_SPLASH)
361                                 w_deathtypestring = "got too close to #'s fireball";
362                         else
363                                 w_deathtypestring = "tasted #'s fireball";
364                 }
365                 else
366                 {
367                         if(w_deathtype & HITTYPE_HEADSHOT)
368                                 w_deathtypestring = "tried to catch #'s firemine";
369                         else
370                                 w_deathtypestring = "fatefully ignored #'s firemine";
371                 }
372         }
373         return TRUE;
374 };