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