properly transmit whether crylink projectiles are bouncing or not
[divverent/nexuiz.git] / data / qcsrc / server / w_crylink.qc
1 .float gravity;
2
3 .entity realowner;
4
5 void W_Crylink_Touch (void)
6 {
7         float finalhit;
8         float f;
9         PROJECTILE_TOUCH;
10         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
11         if(finalhit)
12                 f = 1;
13         else
14                 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
15         if(self.alpha)
16                 f *= self.alpha;
17         RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, self.projectiledeathtype, other);
18         if (finalhit)
19         {
20                 remove (self);
21                 return;
22         }
23         self.cnt = self.cnt - 1;
24         self.angles = vectoangles(self.velocity);
25         self.owner = world;
26         self.projectiledeathtype |= HITTYPE_BOUNCE;
27         // commented out as it causes a little hitch...
28         //if(proj.cnt == 0)
29         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
30 }
31
32 void W_Crylink_Touch2 (void)
33 {
34         float finalhit;
35         float f;
36         PROJECTILE_TOUCH;
37         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
38         if(finalhit)
39                 f = 1;
40         else
41                 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
42         if(self.alpha)
43                 f *= self.alpha;
44         RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, self.projectiledeathtype, other);
45         if (finalhit)
46         {
47                 remove (self);
48                 return;
49         }
50         self.cnt = self.cnt - 1;
51         self.angles = vectoangles(self.velocity);
52         self.owner = world;
53         self.projectiledeathtype |= HITTYPE_BOUNCE;
54         // commented out as it causes a little hitch...
55         //if(proj.cnt == 0)
56         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
57 }
58
59 void W_Crylink_Attack (void)
60 {
61         local float counter, shots;
62         local entity proj;
63         local vector s;
64         vector forward, right, up;
65
66         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
67                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
68
69         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav");
70         forward = v_forward;
71         right = v_right;
72         up = v_up;
73
74         shots = cvar("g_balance_crylink_primary_shots");
75         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
76         while (counter < shots)
77         {
78                 proj = spawn ();
79                 proj.realowner = proj.owner = self;
80                 proj.classname = "spike";
81                 proj.bot_dodge = TRUE;
82                 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
83
84                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
85                 proj.solid = SOLID_BBOX;
86                 proj.projectiledeathtype = WEP_CRYLINK;
87                 //proj.gravity = 0.001;
88
89                 setorigin (proj, w_shotorg);
90
91
92                 s = '0 0 0';
93                 if (counter == 0)
94                         s = '0 0 0';
95                 else
96                 {
97                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
98                         s_y = v_forward_x;
99                         s_z = v_forward_y;
100                 }
101                 s = s * cvar("g_balance_crylink_primary_spread");
102                 proj.velocity = (w_shotdir + right * s_y + up * s_z) * cvar("g_balance_crylink_primary_speed");
103 //              proj.velocity = (w_shotdir + randomvec() * cvar("g_balance_crylink_primary_spread")) * cvar("g_balance_crylink_primary_speed");
104                 W_SetupProjectileVelocity(proj);
105                 proj.touch = W_Crylink_Touch;
106                 if(counter == 0)
107                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_middle_lifetime"), cvar("g_balance_crylink_primary_middle_fadetime"));
108                 else if(counter <= 3)
109                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_star_lifetime"), cvar("g_balance_crylink_primary_star_fadetime"));
110                 else
111                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_other_lifetime"), cvar("g_balance_crylink_primary_other_fadetime"));
112                 proj.cnt = cvar("g_balance_crylink_primary_bounces");
113                 //proj.scale = 1 + 1 * proj.cnt;
114
115                 proj.angles = vectoangles (proj.velocity);
116
117                 //proj.glow_size = 20;
118
119                 proj.flags = FL_PROJECTILE;
120
121                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
122
123                 counter = counter + 1;
124         }
125 }
126
127 void W_Crylink_Attack2 (void)
128 {
129         local float counter, shots;
130         local entity proj;
131
132         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
133                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
134
135         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav");
136
137         shots = cvar("g_balance_crylink_secondary_shots");
138         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
139         while (counter < shots)
140         {
141                 proj = spawn ();
142                 proj.realowner = proj.owner = self;
143                 proj.classname = "spike";
144                 proj.bot_dodge = TRUE;
145                 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
146
147                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
148                 proj.solid = SOLID_BBOX;
149                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
150                 //proj.gravity = 0.001;
151
152                 setorigin (proj, w_shotorg);
153
154                 proj.velocity = (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread")) * cvar("g_balance_crylink_secondary_speed");
155                 W_SetupProjectileVelocity(proj);
156                 proj.touch = W_Crylink_Touch2;
157                 if(counter == (shots - 1) / 2)
158                         SUB_SetFade(proj, time + cvar("g_balance_crylink_secondary_middle_lifetime"), cvar("g_balance_crylink_secondary_middle_fadetime"));
159                 else
160                         SUB_SetFade(proj, time + cvar("g_balance_crylink_secondary_line_lifetime"), cvar("g_balance_crylink_secondary_line_fadetime"));
161                 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
162                 //proj.scale = 1 + 1 * proj.cnt;
163
164                 proj.angles = vectoangles (proj.velocity);
165
166                 //proj.glow_size = 20;
167
168                 proj.flags = FL_PROJECTILE;
169
170                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
171
172                 counter = counter + 1;
173         }
174 }
175
176
177 /*
178 // experimental lightning gun
179 void W_Crylink_Attack3 (void)
180 {
181         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
182                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
183         W_SetupShot (self, TRUE, 0, "weapons/crylink_fire.wav");
184
185         traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * 1000, FALSE, self, self.ping * 0.001);
186
187         pointparticles(particleeffectnum("lightning_muzzleflash", w_shotorg, w_shotdir * 1000, 1);
188         pointparticles(particleeffectnum("lightning_impact", trace_endpos, trace_plane_normal * 1000, 1);
189         trailparticles(world, particleeffectnum("lightning_beam", w_shotorg, trace_endpos);
190
191         if (trace_fraction < 1)
192                 Damage(trace_ent, self, self, cvar("g_balance_crylink_primary_damage"), WEP_CRYLINK | HITTYPE_SECONDARY, trace_endpos, '0 0 0');
193 }
194 */
195
196 void spawnfunc_weapon_crylink (void)
197 {
198         weapon_defaultspawnfunc(WEP_CRYLINK);
199 }
200
201 float w_crylink(float req)
202 {
203         if (req == WR_AIM)
204         {
205                 if (random() > 0.15)
206                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
207                 else
208                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
209         }
210         else if (req == WR_THINK)
211         {
212                 if (self.BUTTON_ATCK)
213                 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
214                 {
215                         W_Crylink_Attack();
216                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
217                 }
218                 if (self.BUTTON_ATCK2)
219                 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
220                 {
221                         W_Crylink_Attack2();
222                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
223                 }
224         }
225         else if (req == WR_PRECACHE)
226         {
227                 precache_model ("models/weapons/g_crylink.md3");
228                 precache_model ("models/weapons/v_crylink.md3");
229                 precache_model ("models/weapons/h_crylink.dpm");
230                 precache_sound ("weapons/crylink_fire.wav");
231                 precache_sound ("weapons/crylink_fire2.wav");
232         }
233         else if (req == WR_SETUP)
234                 weapon_setup(WEP_CRYLINK);
235         else if (req == WR_CHECKAMMO1)
236                 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
237         else if (req == WR_CHECKAMMO2)
238                 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
239         else if (req == WR_SUICIDEMESSAGE)
240         {
241                 w_deathtypestring = "succeeded at self-destructing himself with the Crylink";
242         }
243         else if (req == WR_KILLMESSAGE)
244         {
245                 if(w_deathtype & HITTYPE_BOUNCE)
246                         w_deathtypestring = "could not hide from #'s Crylink"; // unchecked: SPLASH (SECONDARY can't be)
247                 else if(w_deathtype & HITTYPE_SPLASH)
248                         w_deathtypestring = "was too close to #'s Crylink"; // unchecked: SECONDARY
249                 else
250                         w_deathtypestring = "took a close look at #'s Crylink"; // unchecked: SECONDARY
251         }
252         return TRUE;
253 };