]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_fireball.qc
fireball: also hurt turrets
[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.damageforcescale = cvar("g_balance_fireball_secondary_damageforcescale");
137         PROJECTILE_MAKETRIGGER(proj);
138         proj.projectiledeathtype = WEP_FIREBALL | HITTYPE_SECONDARY;
139         setorigin(proj, w_shotorg);
140
141         proj.movetype = MOVETYPE_FLY;
142         proj.velocity = w_shotdir * cvar("g_balance_fireball_secondary_speed");
143         W_SetupProjectileVelocity(proj);
144         proj.angles = vectoangles(proj.velocity);
145         proj.touch = W_Fireball_TouchExplode;
146         setsize(proj, '-16 -16 -16', '16 16 16');
147         proj.flags = FL_PROJECTILE;
148
149         CSQCProjectile(proj, TRUE, PROJECTILE_FIREBALL, TRUE);
150 }
151
152 void W_Fireball_AttackEffect(float i, vector f_diff)
153 {
154         W_SetupShot_ProjectileSize (self, '-16 -16 -16', '16 16 16', FALSE, 0, "", 0);
155         w_shotorg += f_diff_x * v_up + f_diff_y * v_right;
156         pointparticles(particleeffectnum("fireball_preattack_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
157 }
158
159 void W_Fireball_Attack2_Frame4()
160 {
161         W_Fireball_Attack2();
162         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), w_ready);
163 }
164
165 void W_Fireball_Attack2_Frame3()
166 {
167         W_Fireball_AttackEffect(0, '+1.25 +3.75 0');
168         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame4);
169 }
170
171 void W_Fireball_Attack2_Frame2()
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_Frame3);
175 }
176
177 void W_Fireball_Attack2_Frame1()
178 {
179         W_Fireball_AttackEffect(1, '+1.25 -3.75 0');
180         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame2);
181 }
182
183 void W_Fireball_Attack2_Frame0()
184 {
185         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
186                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_fireball_secondary_ammo");
187
188         W_Fireball_AttackEffect(0, '-1.25 -3.75 0');
189         sound (self, CHAN_WEAPON, "weapons/fireball_prefire2.wav", VOL_BASE, ATTN_NORM);
190         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_fireball_secondary_animtime"), W_Fireball_Attack2_Frame1);
191 }
192
193 void W_Firemine_Think()
194 {
195         if(time > self.pushltime)
196         {
197                 remove(self);
198                 return;
199         }
200
201         // make it "hot" once it leaves its owner
202         if(self.owner)
203                 if(vlen(self.origin - self.owner.origin - self.owner.view_ofs) > cvar("g_balance_fireball_primary_laserradius"))
204                         self.owner = world;
205
206         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"));
207
208         self.nextthink = time + 0.1;
209 }
210
211 void W_Firemine_Touch (void)
212 {
213         PROJECTILE_TOUCH;
214         if (other.takedamage == DAMAGE_AIM)
215         {
216                 Fire_AddDamage(other, self.realowner, cvar("g_balance_fireball_primary_damage"), cvar("g_balance_fireball_primary_damagetime"), self.projectiledeathtype | HITTYPE_HEADSHOT);
217                 remove(self);
218         }
219         else
220         {
221                 self.projectiledeathtype |= HITTYPE_BOUNCE;
222         }
223 }
224
225 void W_Fireball_Attack1()
226 {
227         local entity proj;
228         vector f_diff;
229         float c;
230
231         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
232                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_fireball_primary_ammo");
233
234         c = mod(self.bulletcounter, 4);
235         switch(c)
236         {
237                 case 0:
238                         f_diff = '-1.25 -3.75 0';
239                         break;
240                 case 1:
241                         f_diff = '+1.25 -3.75 0';
242                         break;
243                 case 2:
244                         f_diff = '-1.25 +3.75 0';
245                         break;
246                 case 3:
247                 default:
248                         f_diff = '+1.25 +3.75 0';
249                         break;
250         }
251         W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', FALSE, 2, "weapons/fireball_fire.wav", cvar("g_balance_fireball_primary_damage"));
252         traceline(w_shotorg, w_shotorg + f_diff_x * v_up + f_diff_y * v_right, MOVE_NORMAL, self);
253         w_shotorg = trace_endpos;
254
255         pointparticles(particleeffectnum("fireball_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
256
257         proj = spawn ();
258         proj.owner = proj.realowner = self;
259         proj.classname = "grenade";
260         proj.bot_dodge = TRUE;
261         proj.bot_dodgerating = cvar("g_balance_fireball_primary_damage");
262         proj.movetype = MOVETYPE_BOUNCE;
263         proj.projectiledeathtype = WEP_FIREBALL;
264         proj.touch = W_Firemine_Touch;
265         PROJECTILE_MAKETRIGGER(proj);
266         setsize(proj, '-4 -4 -4', '4 4 4');
267         setorigin(proj, w_shotorg);
268         proj.think = W_Firemine_Think;
269         proj.nextthink = time;
270         proj.damageforcescale = cvar("g_balance_fireball_primary_damageforcescale");
271         proj.velocity = w_shotdir * cvar("g_balance_fireball_primary_speed") + v_up * cvar("g_balance_fireball_primary_speed_up");
272         proj.pushltime = time + cvar("g_balance_fireball_primary_lifetime");
273         W_SetupProjectileVelocity(proj);
274
275         proj.angles = vectoangles(proj.velocity);
276         proj.flags = FL_PROJECTILE;
277
278         CSQCProjectile(proj, TRUE, PROJECTILE_FIREMINE, TRUE);
279 }
280
281 void spawnfunc_weapon_fireball (void)
282 {
283         weapon_defaultspawnfunc(WEP_FIREBALL);
284 }
285
286 float w_fireball(float req)
287 {
288         if (req == WR_AIM)
289         {
290                 self.BUTTON_ATCK = FALSE;
291                 self.BUTTON_ATCK2 = FALSE;
292                 if (self.bot_secondary_fireballmooth == 0)
293                 {
294                         if(bot_aim(cvar("g_balance_fireball_primary_speed"), cvar("g_balance_fireball_primary_speed_up"), cvar("g_balance_fireball_primary_lifetime"), TRUE))
295                         {
296                                 self.BUTTON_ATCK = TRUE;
297                                 if(random() < 0.01) self.bot_secondary_fireballmooth = 1;
298                         }
299                 }
300                 else
301                 {
302                         if(bot_aim(cvar("g_balance_fireball_secondary_speed"), 0, cvar("g_balance_fireball_secondary_lifetime"), FALSE))
303                         {
304                                 self.BUTTON_ATCK2 = TRUE;
305                                 if(random() < 0.02) self.bot_secondary_fireballmooth = 0;
306                         }
307                 }
308         }
309         else if (req == WR_THINK)
310         {
311                 if (self.BUTTON_ATCK)
312                 if (weapon_prepareattack(0, cvar("g_balance_fireball_primary_refire")))
313                 {
314                         W_Fireball_Attack1();
315                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_fireball_primary_animtime"), w_ready);
316                 }
317                 if (self.BUTTON_ATCK2)
318                 if (weapon_prepareattack(1, cvar("g_balance_fireball_secondary_refire")))
319                 {
320                         W_Fireball_Attack2_Frame0();
321                 }
322         }
323         else if (req == WR_PRECACHE)
324         {
325                 precache_model ("models/weapons/g_fireball.md3");
326                 precache_model ("models/weapons/v_fireball.md3");
327                 precache_model ("models/weapons/h_fireball.dpm");
328                 precache_model ("models/sphere/sphere.md3");
329                 precache_sound ("weapons/fireball_fire.wav");
330                 precache_sound ("weapons/fireball_fire2.wav");
331                 precache_sound ("weapons/fireball_prefire2.wav");
332         }
333         else if (req == WR_SETUP)
334                 weapon_setup(WEP_FIREBALL);
335         else if (req == WR_CHECKAMMO1)
336                 return self.ammo_rockets >= cvar("g_balance_fireball_primary_ammo");
337         else if (req == WR_CHECKAMMO2)
338                 return self.ammo_rockets >= cvar("g_balance_fireball_secondary_ammo");
339         else if (req == WR_SUICIDEMESSAGE)
340         {
341                 if(w_deathtype & HITTYPE_SECONDARY)
342                         w_deathtypestring = "should have used a smaller gun";
343                 else
344                         w_deathtypestring = "forgot about some firemine";
345         }
346         else if (req == WR_KILLMESSAGE)
347         {
348                 if(w_deathtype & HITTYPE_SECONDARY)
349                 {
350                         if(w_deathtype & HITTYPE_BOUNCE)
351                         {
352                                 if(w_deathtype & HITTYPE_SPLASH) // BFG effect
353                                 {
354                                         w_deathtypestring = "could not hide from #'s fireball";
355                                 }
356                                 else // laser
357                                 {
358                                         w_deathtypestring = "saw the pretty lights of #'s fireball";
359                                 }
360                         }
361                         else if(w_deathtype & HITTYPE_SPLASH)
362                                 w_deathtypestring = "got too close to #'s fireball";
363                         else
364                                 w_deathtypestring = "tasted #'s fireball";
365                 }
366                 else
367                 {
368                         if(w_deathtype & HITTYPE_HEADSHOT)
369                                 w_deathtypestring = "tried to catch #'s firemine";
370                         else
371                                 w_deathtypestring = "fatefully ignored #'s firemine";
372                 }
373         }
374         return TRUE;
375 };