do bouncing client side (sound is still server side)
[divverent/nexuiz.git] / data / qcsrc / server / w_electro.qc
1
2 void W_Plasma_Explode (void)
3 {
4         vector org2;
5         org2 = findbetterlocation (self.origin, 8);
6
7         if(other.takedamage == DAMAGE_AIM)
8                 if(other.classname == "player")
9                         if(IsDifferentTeam(self.owner, other))
10                                 if(IsFlying(other))
11                                         announce(self.owner, "announcer/male/electrobitch.wav");
12
13         self.event_damage = SUB_Null;
14         if (self.movetype == MOVETYPE_BOUNCE)
15         {
16                 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
17                 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);
18         }
19         else
20         {
21                 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
22                 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);
23         }
24
25         sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
26
27         remove (self);
28 }
29
30 void W_Plasma_Explode_Combo (void) {
31         vector org2;
32
33         org2 = findbetterlocation (self.origin, 8);
34         pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
35
36         sound (self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
37
38         self.event_damage = SUB_Null;
39         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, other); // use THIS type for a combo because primary can't bounce
40         remove (self);
41 }
42
43 void W_Plasma_Touch (void)
44 {
45         //UpdateCSQCProjectile(self);
46
47         PROJECTILE_TOUCH;
48         if (other.takedamage == DAMAGE_AIM) {
49                 W_Plasma_Explode ();
50         } else {
51                 sound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
52                 self.projectiledeathtype |= HITTYPE_BOUNCE;
53         }
54 }
55
56 void W_Plasma_TouchExplode (void)
57 {
58         PROJECTILE_TOUCH;
59         W_Plasma_Explode ();
60 }
61
62 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
63 {
64         if(self.health <= 0)
65                 return;
66         self.health = self.health - damage;
67         if (self.health <= 0)
68         {
69                 self.takedamage = DAMAGE_NO;
70                 self.nextthink = time;
71                 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
72                 {
73                         // change owner to whoever caused the combo explosion
74                         self.owner = inflictor.owner;
75                         self.classname = "plasma_chain";
76                         self.think = W_Plasma_Explode_Combo;
77                         self.nextthink = time + vlen(self.origin - inflictor.origin) / cvar("g_balance_electro_combo_speed"); // delay combo chains, looks cooler
78                 }
79                 else
80                         self.think = W_Plasma_Explode;
81         }
82 }
83
84 void W_Electro_Attack()
85 {
86         local entity proj;
87
88         W_SetupShot (self, '25 8 -8', FALSE, 2, "weapons/electro_fire.wav");
89
90         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
91
92         proj = spawn ();
93         proj.classname = "plasma_prim";
94         proj.owner = self;
95         proj.bot_dodge = TRUE;
96         proj.bot_dodgerating = cvar("g_balance_electro_primary_damage");
97         proj.use = W_Plasma_Explode;
98         proj.think = adaptor_think2use;
99         proj.nextthink = time + cvar("g_balance_electro_primary_lifetime");
100         proj.solid = SOLID_BBOX;
101         proj.projectiledeathtype = WEP_ELECTRO;
102         setorigin(proj, w_shotorg);
103
104         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
105                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
106         proj.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
107         proj.movetype = MOVETYPE_FLY;
108         proj.velocity = w_shotdir * cvar("g_balance_electro_primary_speed");
109         W_SetupProjectileVelocity(proj);
110         proj.angles = vectoangles(proj.velocity);
111         proj.touch = W_Plasma_TouchExplode;
112         proj.flags = FL_PROJECTILE;
113         setmodel(proj, "models/elaser.mdl"); // precision set above
114         setsize(proj, '0 0 0', '0 0 0');
115
116         //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
117         //sounds bad
118 }
119
120 void W_Electro_Attack2()
121 {
122         local entity proj;
123
124         W_SetupShot (self, '25 8 -8', FALSE, 2, "weapons/electro_fire2.wav");
125
126         pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
127
128         proj = spawn ();
129         proj.classname = "plasma";
130         proj.owner = self;
131         proj.use = W_Plasma_Explode;
132         proj.think = adaptor_think2use;
133         proj.bot_dodge = TRUE;
134         proj.bot_dodgerating = cvar("g_balance_electro_secondary_damage");
135         proj.nextthink = time + cvar("g_balance_electro_secondary_lifetime");
136         proj.solid = SOLID_BBOX;
137         proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
138         setorigin(proj, w_shotorg);
139
140         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
141                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_secondary_ammo");
142         proj.effects = EF_LOWPRECISION;
143         //proj.glow_size = 50;
144         //proj.glow_color = 45;
145         proj.movetype = MOVETYPE_BOUNCE;
146         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");
147         W_SetupProjectileVelocity(proj);
148         proj.touch = W_Plasma_Touch;
149         setmodel(proj, "models/ebomb.mdl"); // precision set above
150         setsize(proj, '0 0 -3', '0 0 -3');
151         proj.takedamage = DAMAGE_YES;
152         proj.damageforcescale = 4;
153         proj.health = cvar("g_balance_electro_secondary_health");
154         proj.event_damage = W_Plasma_Damage;
155         proj.flags = FL_PROJECTILE;
156
157         CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO);
158 }
159
160 void spawnfunc_weapon_electro (void)
161 {
162         weapon_defaultspawnfunc(WEP_ELECTRO);
163 }
164
165 .float bot_secondary_electromooth;
166 float w_electro(float req)
167 {
168         if (req == WR_AIM)
169         {
170                 self.BUTTON_ATCK=FALSE;
171                 self.BUTTON_ATCK2=FALSE;
172                 if(vlen(self.origin-self.enemy.origin) > 1000)
173                         self.bot_secondary_electromooth = 0;
174                 if(self.bot_secondary_electromooth == 0)
175                 {
176                         if(bot_aim(cvar("g_balance_electro_primary_speed"), 0, cvar("g_balance_electro_primary_lifetime"), FALSE))
177                         {
178                                 self.BUTTON_ATCK = TRUE;
179                                 if(random() < 0.01) self.bot_secondary_electromooth = 1;
180                         }
181                 }
182                 else
183                 {
184                         if(bot_aim(cvar("g_balance_electro_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_electro_secondary_lifetime"), TRUE))
185                         {
186                                 self.BUTTON_ATCK2 = TRUE;
187                                 if(random() < 0.03) self.bot_secondary_electromooth = 0;
188                         }
189                 }
190         }
191         else if (req == WR_THINK)
192         {
193                 if (self.BUTTON_ATCK)
194                 if (weapon_prepareattack(0, cvar("g_balance_electro_primary_refire")))
195                 {
196                         W_Electro_Attack();
197                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
198                 }
199                 if (self.BUTTON_ATCK2)
200                 if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
201                 {
202                         W_Electro_Attack2();
203                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_secondary_animtime"), w_ready);
204                 }
205         }
206         else if (req == WR_PRECACHE)
207         {
208                 precache_model ("models/ebomb.mdl");
209                 precache_model ("models/elaser.mdl");
210                 precache_model ("models/weapons/g_electro.md3");
211                 precache_model ("models/weapons/v_electro.md3");
212                 precache_model ("models/weapons/w_electro.zym");
213                 precache_sound ("weapons/electro_bounce.wav");
214                 precache_sound ("weapons/electro_fire.wav");
215                 precache_sound ("weapons/electro_fire2.wav");
216                 precache_sound ("weapons/electro_fly.wav");
217                 precache_sound ("weapons/electro_impact.wav");
218                 precache_sound ("weapons/electro_impact_combo.wav");
219         }
220         else if (req == WR_SETUP)
221                 weapon_setup(WEP_ELECTRO);
222         else if (req == WR_CHECKAMMO1)
223                 return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
224         else if (req == WR_CHECKAMMO2)
225                 return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
226         else if (req == WR_SUICIDEMESSAGE)
227         {
228                 if(w_deathtype & HITTYPE_SECONDARY)
229                         w_deathtypestring = "could not remember where he put plasma";
230                 else
231                         w_deathtypestring = "played with plasma";
232         }
233         else if (req == WR_KILLMESSAGE)
234         {
235                 if(w_deathtype & HITTYPE_SECONDARY)
236                 {
237                         if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
238                                 w_deathtypestring = "just noticed #'s blue ball";
239                         else // unchecked: BOUNCE
240                                 w_deathtypestring = "got in touch with #'s blue ball";
241                 }
242                 else
243                 {
244                         if(w_deathtype & HITTYPE_BOUNCE) // combo
245                                 w_deathtypestring = "felt the electrifying air of #'s combo";
246                         else if(w_deathtype & HITTYPE_SPLASH)
247                                 w_deathtypestring = "got too close to #'s blue beam";
248                         else
249                                 w_deathtypestring = "was blasted by #'s blue beam";
250                 }
251         }
252         return TRUE;
253 };