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