centerprints now are managed independently per line
[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         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
7         WriteByte (MSG_BROADCAST, 79);
8         WriteCoord (MSG_BROADCAST, org2_x);
9         WriteCoord (MSG_BROADCAST, org2_y);
10         WriteCoord (MSG_BROADCAST, org2_z);
11         WriteCoord (MSG_BROADCAST, 0);          // SeienAbunae: groan... Useless clutter
12         WriteCoord (MSG_BROADCAST, 0);
13         WriteCoord (MSG_BROADCAST, 0);
14         WriteByte (MSG_BROADCAST, 155);
15
16         self.event_damage = SUB_Null;
17         if (self.movetype == MOVETYPE_BOUNCE)
18                 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"), IT_ELECTRO);
19         else
20                 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"), IT_ELECTRO);
21         sound (self, CHAN_BODY, "weapons/electro_impact.ogg", 1, ATTN_NORM);
22
23         remove (self);
24 }
25
26 void W_Plasma_Explode_Combo (void) {
27         vector org2;
28
29         org2 = findbetterlocation (self.origin, 8);
30         te_spikequad(self.origin);
31
32         sound (self, CHAN_BODY, "weapons/electro_impact_combo.ogg", 1, ATTN_NORM);
33
34         self.event_damage = SUB_Null;
35         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"), IT_ELECTRO);
36         te_explosionrgb(org2, '0.5 0.5 1');
37         remove (self);
38 }
39
40 void W_Plasma_Touch (void)
41 {
42         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
43         {
44                 sound (self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
45                 remove(self);
46                 return;
47         }
48         if (other.takedamage == DAMAGE_AIM) {
49                 W_Plasma_Explode ();
50         } else {
51                 sound (self, CHAN_IMPACT, "weapons/electro_bounce.ogg", 1, ATTN_NORM);
52         }
53 }
54
55 void W_Plasma_TouchExplode (void)
56 {
57         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
58         {
59                 sound (self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
60                 remove(self);
61                 return;
62         }
63         W_Plasma_Explode ();
64 }
65
66 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
67 {
68         self.health = self.health - damage;
69         if (self.health <= 0)
70         {
71                 self.takedamage = DAMAGE_NO;
72                 self.nextthink = time;
73                 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
74                 {
75                         // change owner to whoever caused the combo explosion
76                         self.owner = inflictor.owner;
77                         self.classname = "plasma_chain";
78                         self.think = W_Plasma_Explode_Combo;
79                 }
80                 else
81                         self.think = W_Plasma_Explode;
82         }
83 }
84
85 void() W_Electro_Attack
86 {
87         local entity proj;
88
89         W_SetupShot (self, '15 8 -8', FALSE, 2, "weapons/electro_fire.ogg");
90
91         proj = spawn ();
92         proj.classname = "plasma_prim";
93         proj.owner = self;
94         proj.bot_dodge = TRUE;
95         proj.bot_dodgerating = cvar("g_balance_electro_primary_damage");
96         proj.think = W_Plasma_Explode;
97         proj.nextthink = time + cvar("g_balance_electro_primary_lifetime");
98         proj.solid = SOLID_BBOX;
99         setorigin(proj, w_shotorg);
100
101         if (cvar("g_use_ammunition"))
102                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
103         proj.effects = EF_BRIGHTFIELD | EF_FULLBRIGHT | EF_NOSHADOW | EF_LOWPRECISION;
104         proj.movetype = MOVETYPE_FLY;
105         proj.velocity = w_shotdir * cvar("g_balance_electro_primary_speed");
106         proj.angles = vectoangles(proj.velocity);
107         proj.touch = W_Plasma_TouchExplode;
108         proj.flags = FL_PROJECTILE;
109         setmodel(proj, "models/elaser.mdl");
110         setsize(proj, '0 0 0', '0 0 0');
111
112         // LordHavoc: disabled because no one likes this sound and it sometimes never stops due to packet loss
113         //sound (proj, CHAN_BODY, "weapons/electro_fly.wav", 1, ATTN_NORM);
114 }
115
116 void() W_Electro_Attack2
117 {
118         local entity proj;
119
120         W_SetupShot (self, '15 8 -8', FALSE, 2, "weapons/electro_fire2.ogg");
121
122         proj = spawn ();
123         proj.classname = "plasma";
124         proj.owner = self;
125         proj.think = W_Plasma_Explode;
126         proj.bot_dodge = TRUE;
127         proj.bot_dodgerating = cvar("g_balance_electro_secondary_damage");
128         proj.nextthink = time + cvar("g_balance_electro_secondary_lifetime");
129         proj.solid = SOLID_BBOX;
130         setorigin(proj, w_shotorg);
131
132         if (cvar("g_use_ammunition"))
133                 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_secondary_ammo");
134         proj.effects = EF_FULLBRIGHT | EF_NOSHADOW | EF_LOWPRECISION;
135         //proj.glow_size = 50;
136         //proj.glow_color = 45;
137         proj.movetype = MOVETYPE_BOUNCE;
138         proj.velocity = v_forward * cvar("g_balance_electro_secondary_speed") + v_up * cvar("g_balance_electro_secondary_speed_up");
139         proj.touch = W_Plasma_Touch;
140         setmodel(proj, "models/ebomb.mdl");
141         setsize(proj, '0 0 -3', '0 0 -3');
142         proj.takedamage = DAMAGE_YES;
143         proj.damageforcescale = 4;
144         proj.health = 5;
145         proj.event_damage = W_Plasma_Damage;
146         proj.flags = FL_PROJECTILE;
147
148         // LordHavoc: disabled because no one likes this sound and it sometimes never stops due to packet loss
149         //sound (proj, CHAN_BODY, "weapons/electro_fly.wav", 1, ATTN_NORM);
150 }
151
152 float(float req) w_electro =
153 {
154         if (req == WR_AIM)
155                 self.button0 = bot_aim(cvar("g_balance_electro_primary_speed"), 0, cvar("g_balance_electro_primary_lifetime"), FALSE);
156         else if (req == WR_THINK)
157         {
158                 if (self.button0)
159                 if (weapon_prepareattack(0, cvar("g_balance_electro_primary_refire")))
160                 {
161                         W_Electro_Attack();
162                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
163                 }
164                 if (self.button3)
165                 if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
166                 {
167                         W_Electro_Attack2();
168                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_secondary_animtime"), w_ready);
169                 }
170         }
171         else if (req == WR_SETUP)
172                 weapon_setup(WEP_ELECTRO, "electro", IT_CELLS);
173         else if (req == WR_CHECKAMMO1)
174                 return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
175         else if (req == WR_CHECKAMMO2)
176                 return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
177         return TRUE;
178 };