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