]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_electro.qc
b8f5b28d1d36121ee77d9ea6f14de07008fe21ae
[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 void spawnfunc_weapon_electro (void)
192 {
193         weapon_defaultspawnfunc(WEP_ELECTRO);
194 }
195
196 void w_electro_checkattack()
197 {
198         if(self.electro_count > 1)
199         if(self.BUTTON_ATCK2)
200         if(weapon_prepareattack(1, -1))
201         {
202                 W_Electro_Attack2();
203                 self.electro_count -= 1;
204                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
205                 return;
206         }
207
208         w_ready();
209 }
210
211 .float bot_secondary_electromooth;
212 float w_electro(float req)
213 {
214         if (req == WR_AIM)
215         {
216                 self.BUTTON_ATCK=FALSE;
217                 self.BUTTON_ATCK2=FALSE;
218                 if(vlen(self.origin-self.enemy.origin) > 1000)
219                         self.bot_secondary_electromooth = 0;
220                 if(self.bot_secondary_electromooth == 0)
221                 {
222                         if(bot_aim(cvar("g_balance_electro_primary_speed"), 0, cvar("g_balance_electro_primary_lifetime"), FALSE))
223                         {
224                                 self.BUTTON_ATCK = TRUE;
225                                 if(random() < 0.01) self.bot_secondary_electromooth = 1;
226                         }
227                 }
228                 else
229                 {
230                         if(bot_aim(cvar("g_balance_electro_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_electro_secondary_lifetime"), TRUE))
231                         {
232                                 self.BUTTON_ATCK2 = TRUE;
233                                 if(random() < 0.03) self.bot_secondary_electromooth = 0;
234                         }
235                 }
236         }
237         else if (req == WR_THINK)
238         {
239                 if (self.BUTTON_ATCK)
240                 if (weapon_prepareattack(0, cvar("g_balance_electro_primary_refire")))
241                 {
242                         W_Electro_Attack();
243                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
244                 }
245                 if (self.BUTTON_ATCK2)
246                 if (time >= self.electro_secondarytime)
247                 if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
248                 {
249                         W_Electro_Attack2();
250                         self.electro_count = cvar("g_balance_electro_secondary_count");
251                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
252                         self.electro_secondarytime = time + cvar("g_balance_electro_secondary_refire2");
253                 }
254         }
255         else if (req == WR_PRECACHE)
256         {
257                 precache_model ("models/weapons/g_electro.md3");
258                 precache_model ("models/weapons/v_electro.md3");
259                 precache_model ("models/weapons/h_electro.dpm");
260                 precache_sound ("weapons/electro_bounce.wav");
261                 precache_sound ("weapons/electro_fire.wav");
262                 precache_sound ("weapons/electro_fire2.wav");
263                 precache_sound ("weapons/electro_impact.wav");
264                 precache_sound ("weapons/electro_impact_combo.wav");
265         }
266         else if (req == WR_SETUP)
267                 weapon_setup(WEP_ELECTRO);
268         else if (req == WR_CHECKAMMO1)
269                 return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
270         else if (req == WR_CHECKAMMO2)
271                 return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
272         else if (req == WR_SUICIDEMESSAGE)
273         {
274                 if(w_deathtype & HITTYPE_SECONDARY)
275                         w_deathtypestring = "could not remember where they put plasma";
276                 else
277                         w_deathtypestring = "played with plasma";
278         }
279         else if (req == WR_KILLMESSAGE)
280         {
281                 if(w_deathtype & HITTYPE_SECONDARY)
282                 {
283                         if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
284                                 w_deathtypestring = "just noticed #'s blue ball";
285                         else // unchecked: BOUNCE
286                                 w_deathtypestring = "got in touch with #'s blue ball";
287                 }
288                 else
289                 {
290                         if(w_deathtype & HITTYPE_BOUNCE) // combo
291                                 w_deathtypestring = "felt the electrifying air of #'s combo";
292                         else if(w_deathtype & HITTYPE_SPLASH)
293                                 w_deathtypestring = "got too close to #'s blue beam";
294                         else
295                                 w_deathtypestring = "was blasted by #'s blue beam";
296                 }
297         }
298         else if (req == WR_RESETPLAYER)
299         {
300                 self.electro_secondarytime = time;
301         }
302         return TRUE;
303 };
304 #endif