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