]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_rifle.qc
Add multiplier for compat
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_rifle.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ RIFLE,
4 /* function */ W_Rifle,
5 /* ammotype */ ammo_nails,
6 /* impulse  */ 7,
7 /* flags    */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* color        */ '0.5 1 0',
10 /* model    */ "campingrifle",
11 /* crosshair */ "gfx/crosshairrifle 0.5",
12 /* netname  */ "rifle",
13 /* fullname */ _("Rifle")
14 );
15
16 #define RIFLE_SETTINGS(w_cvar,w_prop) RIFLE_SETTINGS_LIST(w_cvar, w_prop, RIFLE, rifle)
17 #define RIFLE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
18         w_cvar(id, sn, BOTH, ammo) \
19         w_cvar(id, sn, BOTH, animtime) \
20         w_cvar(id, sn, BOTH, bullethail) \
21         w_cvar(id, sn, BOTH, burstcost) \
22         w_cvar(id, sn, BOTH, damage) \
23         w_cvar(id, sn, BOTH, force) \
24         w_cvar(id, sn, BOTH, refire) \
25         w_cvar(id, sn, BOTH, shots) \
26         w_cvar(id, sn, BOTH, solidpenetration) \
27         w_cvar(id, sn, BOTH, spread) \
28         w_cvar(id, sn, BOTH, tracer) \
29         w_cvar(id, sn, NONE, bursttime) \
30         w_cvar(id, sn, NONE, secondary) \
31         w_cvar(id, sn, SEC,  reload) \
32         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
33         w_prop(id, sn, float,  reloading_time, reload_time) \
34         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
35         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
36         w_prop(id, sn, string, weaponreplace, weaponreplace) \
37         w_prop(id, sn, float,  weaponstart, weaponstart) \
38         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
39
40 #ifdef SVQC
41 RIFLE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
42 .float rifle_accumulator;
43 #endif
44 #else
45 #ifdef SVQC
46 void spawnfunc_weapon_rifle (void) { weapon_defaultspawnfunc(WEP_RIFLE); }
47 void spawnfunc_weapon_campingrifle (void) { spawnfunc_weapon_rifle(); }
48 void spawnfunc_weapon_sniperrifle (void) { spawnfunc_weapon_rifle(); }
49
50 void W_Rifle_FireBullet(float pSpread, float pDamage, float pForce, float pSolidPenetration, float pAmmo, float deathtype, float pTracer, float pShots, string pSound)
51 {
52         float i;
53
54         W_DecreaseAmmo(pAmmo);
55
56         W_SetupShot (self, TRUE, 2, pSound, CH_WEAPON_A, pDamage * pShots);
57
58         pointparticles(particleeffectnum("rifle_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
59
60         if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
61         {
62                 w_shotdir = v_forward;
63                 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
64         }
65
66         for(i = 0; i < pShots; ++i)
67                 fireBullet(w_shotorg, w_shotdir, pSpread, pSolidPenetration, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE));
68
69         if (autocvar_g_casings >= 2)
70                 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
71 }
72
73 void W_Rifle_Attack()
74 {
75         W_Rifle_FireBullet(WEP_CVAR_PRI(rifle, spread), WEP_CVAR_PRI(rifle, damage), WEP_CVAR_PRI(rifle, force), WEP_CVAR_PRI(rifle, solidpenetration), WEP_CVAR_PRI(rifle, ammo), WEP_RIFLE, WEP_CVAR_PRI(rifle, tracer), WEP_CVAR_PRI(rifle, shots), "weapons/campingrifle_fire.wav");
76 }
77
78 void W_Rifle_Attack2()
79 {
80         W_Rifle_FireBullet(WEP_CVAR_SEC(rifle, spread), WEP_CVAR_SEC(rifle, damage), WEP_CVAR_SEC(rifle, force), WEP_CVAR_SEC(rifle, solidpenetration), WEP_CVAR_SEC(rifle, ammo), WEP_RIFLE | HITTYPE_SECONDARY, WEP_CVAR_SEC(rifle, tracer), WEP_CVAR_SEC(rifle, shots), "weapons/campingrifle_fire2.wav");
81 }
82
83 .void(void) rifle_bullethail_attackfunc;
84 .float rifle_bullethail_frame;
85 .float rifle_bullethail_animtime;
86 .float rifle_bullethail_refire;
87 void W_Rifle_BulletHail_Continue()
88 {
89         float r, sw, af;
90
91         sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
92         af = ATTACK_FINISHED(self);
93         self.switchweapon = self.weapon;
94         ATTACK_FINISHED(self) = time;
95         print(ftos(self.WEP_AMMO(RIFLE)), "\n");
96         r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
97         if(self.switchweapon == self.weapon)
98                 self.switchweapon = sw;
99         if(r)
100         {
101                 self.rifle_bullethail_attackfunc();
102                 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
103                 print("thinkf set\n");
104         }
105         else
106         {
107                 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
108                 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
109         }
110 }
111
112 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
113 {
114         // if we get here, we have at least one bullet to fire
115         AttackFunc();
116         if(mode)
117         {
118                 // continue hail
119                 self.rifle_bullethail_attackfunc = AttackFunc;
120                 self.rifle_bullethail_frame = fr;
121                 self.rifle_bullethail_animtime = animtime;
122                 self.rifle_bullethail_refire = refire;
123                 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
124         }
125         else
126         {
127                 // just one shot
128                 weapon_thinkf(fr, animtime, w_ready);
129         }
130 }
131
132 .float bot_secondary_riflemooth;
133 float W_Rifle(float req)
134 {
135         float ammo_amount;
136         
137         switch(req)
138         {
139                 case WR_AIM:
140                 {
141                         self.BUTTON_ATCK=FALSE;
142                         self.BUTTON_ATCK2=FALSE;
143                         if(vlen(self.origin-self.enemy.origin) > 1000)
144                                 self.bot_secondary_riflemooth = 0;
145                         if(self.bot_secondary_riflemooth == 0)
146                         {
147                                 if(bot_aim(1000000, 0, 0.001, FALSE))
148                                 {
149                                         self.BUTTON_ATCK = TRUE;
150                                         if(random() < 0.01) self.bot_secondary_riflemooth = 1;
151                                 }
152                         }
153                         else
154                         {
155                                 if(bot_aim(1000000, 0, 0.001, FALSE))
156                                 {
157                                         self.BUTTON_ATCK2 = TRUE;
158                                         if(random() < 0.03) self.bot_secondary_riflemooth = 0;
159                                 }
160                         }
161                         
162                         return TRUE;
163                 }
164                 case WR_THINK:
165                 {
166                         if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) // forced reload
167                                 WEP_ACTION(self.weapon, WR_RELOAD);
168                         else
169                         {
170                                 self.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), self.rifle_accumulator, time);
171                                 if (self.BUTTON_ATCK)
172                                 if (weapon_prepareattack_check(0, WEP_CVAR_PRI(rifle, refire)))
173                                 if (time >= self.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
174                                 {
175                                         weapon_prepareattack_do(0, WEP_CVAR_PRI(rifle, refire));
176                                         W_Rifle_BulletHail(WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
177                                         self.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
178                                 }
179                                 if (self.BUTTON_ATCK2)
180                                 {
181                                         if (WEP_CVAR(rifle, secondary))
182                                         {
183                                                 if(WEP_CVAR_SEC(rifle, reload))
184                                                         WEP_ACTION(self.weapon, WR_RELOAD);
185                                                 else
186                                                 {
187                                                         if (weapon_prepareattack_check(1, WEP_CVAR_SEC(rifle, refire)))
188                                                         if (time >= self.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
189                                                         {
190                                                                 weapon_prepareattack_do(1, WEP_CVAR_SEC(rifle, refire));
191                                                                 W_Rifle_BulletHail(WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
192                                                                 self.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
193                                                         }
194                                                 }
195                                         }
196                                 }
197                         }
198                         
199                         return TRUE;
200                 }
201                 case WR_INIT:
202                 {
203                         precache_model ("models/weapons/g_campingrifle.md3");
204                         precache_model ("models/weapons/v_campingrifle.md3");
205                         precache_model ("models/weapons/h_campingrifle.iqm");
206                         precache_sound ("weapons/campingrifle_fire.wav");
207                         precache_sound ("weapons/campingrifle_fire2.wav");
208                         RIFLE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
209                         return TRUE;
210                 }
211                 case WR_CHECKAMMO1:
212                 {
213                         ammo_amount = self.WEP_AMMO(RIFLE) >= WEP_CVAR_PRI(rifle, ammo);
214                         ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_PRI(rifle, ammo);
215                         return ammo_amount;
216                 }
217                 case WR_CHECKAMMO2:
218                 {
219                         ammo_amount = self.WEP_AMMO(RIFLE) >= WEP_CVAR_SEC(rifle, ammo);
220                         ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_SEC(rifle, ammo);
221                         return ammo_amount;
222                 }
223                 case WR_CONFIG:
224                 {
225                         RIFLE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
226                         return TRUE;
227                 }
228                 case WR_RESETPLAYER:
229                 {
230                         self.rifle_accumulator = time - WEP_CVAR(rifle, bursttime);
231                         return TRUE;
232                 }
233                 case WR_RELOAD:
234                 {
235                         W_Reload(min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo)), "weapons/reload.wav");
236                         return TRUE;
237                 }
238                 case WR_SUICIDEMESSAGE:
239                 {
240                         return WEAPON_THINKING_WITH_PORTALS;
241                 }
242                 case WR_KILLMESSAGE:
243                 {
244                         if(w_deathtype & HITTYPE_SECONDARY)
245                         {
246                                 if(w_deathtype & HITTYPE_BOUNCE)
247                                         return WEAPON_RIFLE_MURDER_HAIL_PIERCING;
248                                 else
249                                         return WEAPON_RIFLE_MURDER_HAIL;
250                         }
251                         else
252                         {
253                                 if(w_deathtype & HITTYPE_BOUNCE)
254                                         return WEAPON_RIFLE_MURDER_PIERCING;
255                                 else
256                                         return WEAPON_RIFLE_MURDER;
257                         }
258                 }
259         }
260         return TRUE;
261 }
262 #endif
263 #ifdef CSQC
264 float W_Rifle(float req)
265 {
266         switch(req)
267         {
268                 case WR_IMPACTEFFECT:
269                 {
270                         vector org2;
271                         org2 = w_org + w_backoff * 2;
272                         pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
273                         if(!w_issilent)
274                         {
275                                 if(w_random < 0.2)
276                                         sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
277                                 else if(w_random < 0.4)
278                                         sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
279                                 else if(w_random < 0.5)
280                                         sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
281                         }
282                         
283                         return TRUE;
284                 }
285                 case WR_INIT:
286                 {
287                         precache_sound("weapons/ric1.wav");
288                         precache_sound("weapons/ric2.wav");
289                         precache_sound("weapons/ric3.wav");
290                         if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
291                         {
292                                 precache_pic("gfx/reticle_nex");
293                         }
294                         return TRUE;
295                 }
296                 case WR_ZOOMRETICLE:
297                 {
298                         if(button_zoom || zoomscript_caught)
299                         {
300                                 reticle_image = "gfx/reticle_nex";
301                                 return TRUE;
302                         }
303                         else
304                         {
305                                 // no weapon specific image for this weapon
306                                 return FALSE;
307                         }
308                 }
309         }
310
311         return TRUE;
312 }
313 #endif
314 #endif