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