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