]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_electro.qc
refire2 for electro and fireball;
[divverent/nexuiz.git] / data / qcsrc / server / w_electro.qc
1 .float electro_count;
2 .float electro_secondarytime;
3
4 void W_Plasma_Explode_Combo (void);
5
6 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
7 {
8         local entity e;
9         e = findradius(org, rad);
10         while (e)
11         {
12                 if (e.classname == "plasma")
13                 {
14                         // see if there is line of sight to the combo ball
15                         traceline(org, e.origin, MOVE_NOMONSTERS, e);
16                         if (trace_fraction == 1 || trace_ent == e)
17                         {
18                                 // change owner to whoever caused the combo explosion
19                                 e.owner = own;
20                                 e.takedamage = DAMAGE_NO;
21                                 e.classname = "plasma_chain";
22                                 e.think = W_Plasma_Explode_Combo;
23                                 e.nextthink = time + vlen(e.origin - org) / cvar("g_balance_electro_combo_speed"); // delay combo chains, looks cooler
24                         }
25                 }
26                 e = e.chain;
27         }
28 }
29
30 void W_Plasma_Explode (void)
31 {
32         if(other.takedamage == DAMAGE_AIM)
33                 if(other.classname == "player")
34                         if(IsDifferentTeam(self.owner, other))
35                                 if(other.deadflag == DEAD_NO)
36                                         if(IsFlying(other))
37                                                 announce(self.owner, "announcer/male/electrobitch.wav");
38
39         self.event_damage = SUB_Null;
40         self.takedamage = DAMAGE_NO;
41         if (self.movetype == MOVETYPE_BOUNCE)
42         {
43                 RadiusDamage (self, self.owner, cvar("g_balance_electro_secondary_damage"), cvar("g_balance_electro_secondary_edgedamage"), cvar("g_balance_electro_secondary_radius"), world, cvar("g_balance_electro_secondary_force"), self.projectiledeathtype, other);
44         }
45         else
46         {
47                 W_Plasma_TriggerCombo(self.origin, cvar("g_balance_electro_primary_comboradius"), self.owner);
48                 RadiusDamage (self, self.owner, cvar("g_balance_electro_primary_damage"), cvar("g_balance_electro_primary_edgedamage"), cvar("g_balance_electro_primary_radius"), world, cvar("g_balance_electro_primary_force"), self.projectiledeathtype, other);
49         }
50
51         remove (self);
52 }
53
54 void W_Plasma_Explode_Combo (void)
55 {
56
57         W_Plasma_TriggerCombo(self.origin, cvar("g_balance_electro_combo_comboradius"), self.owner);
58
59         self.event_damage = SUB_Null;
60         RadiusDamage (self, self.owner, cvar("g_balance_electro_combo_damage"), cvar("g_balance_electro_combo_edgedamage"), cvar("g_balance_electro_combo_radius"), world, cvar("g_balance_electro_combo_force"), WEP_ELECTRO | HITTYPE_BOUNCE, world); // use THIS type for a combo because primary can't bounce
61         remove (self);
62 }
63
64 void W_Plasma_Touch (void)
65 {
66         PROJECTILE_TOUCH;
67         if (other.takedamage == DAMAGE_AIM) {
68                 W_Plasma_Explode ();
69         } else {
70                 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
71                 self.projectiledeathtype |= HITTYPE_BOUNCE;
72         }
73 }
74
75 void W_Plasma_TouchExplode (void)
76 {
77         PROJECTILE_TOUCH;
78         W_Plasma_Explode ();
79 }
80
81 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
82 {
83         if(self.health <= 0)
84                 return;
85         // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
86         self.health = self.health - damage;
87         if (self.health <= 0)
88         {
89                 self.takedamage = DAMAGE_NO;
90                 self.nextthink = time;
91                 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
92                 {
93                         // change owner to whoever caused the combo explosion
94                         self.owner = inflictor.owner;
95                         self.classname = "plasma_chain";
96                         self.think = W_Plasma_Explode_Combo;
97                         self.nextthink = time + vlen(self.origin - inflictor.origin) / cvar("g_balance_electro_combo_speed"); // delay combo chains, looks cooler
98                 }
99                 else
100                 {
101                         self.use = W_Plasma_Explode;
102                         self.think = adaptor_think2use;
103                 }
104         }
105 }
106
107 void W_Electro_Attack()
108 {
109         local entity proj;
110
111         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", cvar("g_balance_electro_primary_damage"));
112
113         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
114
115         proj = spawn ();
116         proj.classname = "plasma_prim";
117         proj.owner = self;
118         proj.bot_dodge = TRUE;
119         proj.bot_dodgerating = cvar("g_balance_electro_primary_damage");
120         proj.use = W_Plasma_Explode;
121         proj.think = adaptor_think2use;
122         proj.nextthink = time + cvar("g_balance_electro_primary_lifetime");
123         PROJECTILE_MAKETRIGGER(proj);
124         proj.projectiledeathtype = WEP_ELECTRO;
125         setorigin(proj, w_shotorg);
126
127         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
128                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
129         proj.movetype = MOVETYPE_FLY;
130         proj.velocity = w_shotdir * cvar("g_balance_electro_primary_speed");
131         W_SetupProjectileVelocity(proj);
132         proj.angles = vectoangles(proj.velocity);
133         proj.touch = W_Plasma_TouchExplode;
134         setsize(proj, '0 0 -3', '0 0 -3');
135         proj.flags = FL_PROJECTILE;
136
137         //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
138         //sounds bad
139
140         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
141 }
142
143 void W_Electro_Attack2()
144 {
145         local entity proj;
146
147         W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire2.wav", cvar("g_balance_electro_secondary_damage"));
148         w_shotdir = v_forward; // no TrueAim for grenades please
149
150         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
151
152         proj = spawn ();
153         proj.classname = "plasma";
154         proj.owner = self;
155         proj.use = W_Plasma_Explode;
156         proj.think = adaptor_think2use;
157         proj.bot_dodge = TRUE;
158         proj.bot_dodgerating = cvar("g_balance_electro_secondary_damage");
159         proj.nextthink = time + cvar("g_balance_electro_secondary_lifetime");
160         PROJECTILE_MAKETRIGGER(proj);
161         proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
162         setorigin(proj, w_shotorg);
163
164         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
165                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_secondary_ammo");
166         //proj.glow_size = 50;
167         //proj.glow_color = 45;
168         proj.movetype = MOVETYPE_BOUNCE;
169         proj.velocity = (w_shotdir + randomvec() * cvar("g_balance_electro_secondary_spread")) * cvar("g_balance_electro_secondary_speed") + v_up * cvar("g_balance_electro_secondary_speed_up");
170         W_SetupProjectileVelocity(proj);
171         proj.touch = W_Plasma_Touch;
172         setsize(proj, '0 0 -3', '0 0 -3');
173         proj.takedamage = DAMAGE_YES;
174         proj.damageforcescale = cvar("g_balance_electro_secondary_damageforcescale");
175         proj.health = cvar("g_balance_electro_secondary_health");
176         proj.event_damage = W_Plasma_Damage;
177         proj.flags = FL_PROJECTILE;
178
179 #if 0
180         entity p2;
181         p2 = spawn();
182         copyentity(proj, p2);
183         setmodel(p2, "models/ebomb.mdl");
184         setsize(p2, proj.mins, proj.maxs);
185 #endif
186
187         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
188 }
189
190 void spawnfunc_weapon_electro (void)
191 {
192         weapon_defaultspawnfunc(WEP_ELECTRO);
193 }
194
195 void w_electro_checkattack()
196 {
197         if(self.electro_count > 1)
198         if(self.BUTTON_ATCK2)
199         if(weapon_prepareattack(1, -1))
200         {
201                 W_Electro_Attack2();
202                 self.electro_count -= 1;
203                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
204                 return;
205         }
206
207         w_ready();
208 }
209
210 .float bot_secondary_electromooth;
211 float w_electro(float req)
212 {
213         if (req == WR_AIM)
214         {
215                 self.BUTTON_ATCK=FALSE;
216                 self.BUTTON_ATCK2=FALSE;
217                 if(vlen(self.origin-self.enemy.origin) > 1000)
218                         self.bot_secondary_electromooth = 0;
219                 if(self.bot_secondary_electromooth == 0)
220                 {
221                         if(bot_aim(cvar("g_balance_electro_primary_speed"), 0, cvar("g_balance_electro_primary_lifetime"), FALSE))
222                         {
223                                 self.BUTTON_ATCK = TRUE;
224                                 if(random() < 0.01) self.bot_secondary_electromooth = 1;
225                         }
226                 }
227                 else
228                 {
229                         if(bot_aim(cvar("g_balance_electro_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_electro_secondary_lifetime"), TRUE))
230                         {
231                                 self.BUTTON_ATCK2 = TRUE;
232                                 if(random() < 0.03) self.bot_secondary_electromooth = 0;
233                         }
234                 }
235         }
236         else if (req == WR_THINK)
237         {
238                 if (self.BUTTON_ATCK)
239                 if (weapon_prepareattack(0, cvar("g_balance_electro_primary_refire")))
240                 {
241                         W_Electro_Attack();
242                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
243                 }
244                 if (self.BUTTON_ATCK2)
245                 if (time >= self.electro_secondarytime)
246                 if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
247                 {
248                         W_Electro_Attack2();
249                         self.electro_count = cvar("g_balance_electro_secondary_count");
250                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
251                         self.electro_secondarytime = time + cvar("g_balance_electro_secondary_refire2");
252                 }
253         }
254         else if (req == WR_PRECACHE)
255         {
256                 precache_model ("models/weapons/g_electro.md3");
257                 precache_model ("models/weapons/v_electro.md3");
258                 precache_model ("models/weapons/h_electro.dpm");
259                 precache_sound ("weapons/electro_bounce.wav");
260                 precache_sound ("weapons/electro_fire.wav");
261                 precache_sound ("weapons/electro_fire2.wav");
262                 precache_sound ("weapons/electro_impact.wav");
263                 precache_sound ("weapons/electro_impact_combo.wav");
264         }
265         else if (req == WR_SETUP)
266                 weapon_setup(WEP_ELECTRO);
267         else if (req == WR_CHECKAMMO1)
268                 return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
269         else if (req == WR_CHECKAMMO2)
270                 return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
271         else if (req == WR_SUICIDEMESSAGE)
272         {
273                 if(w_deathtype & HITTYPE_SECONDARY)
274                         w_deathtypestring = "could not remember where he put plasma";
275                 else
276                         w_deathtypestring = "played with plasma";
277         }
278         else if (req == WR_KILLMESSAGE)
279         {
280                 if(w_deathtype & HITTYPE_SECONDARY)
281                 {
282                         if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
283                                 w_deathtypestring = "just noticed #'s blue ball";
284                         else // unchecked: BOUNCE
285                                 w_deathtypestring = "got in touch with #'s blue ball";
286                 }
287                 else
288                 {
289                         if(w_deathtype & HITTYPE_BOUNCE) // combo
290                                 w_deathtypestring = "felt the electrifying air of #'s combo";
291                         else if(w_deathtype & HITTYPE_SPLASH)
292                                 w_deathtypestring = "got too close to #'s blue beam";
293                         else
294                                 w_deathtypestring = "was blasted by #'s blue beam";
295                 }
296         }
297         return TRUE;
298 };