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