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