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