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