]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_campingrifle.qc
slightly updated crifle
[divverent/nexuiz.git] / data / qcsrc / server / w_campingrifle.qc
1 //Camping rifle Primary mode: manually operated bolt*, Secondary: full automatic** --MikeeUSA--
2 //* Manually operating the bolt means that all the power of the gas is used to propell the bullet. In this mode the bolt is prevented from moving backwards in response to the firing of the bullet.
3 //** In fully automatic mode some of the gas is used to extract and reload the next cartrige, thus there is less power and range.
4
5 .float campingrifle_bulletcounter;
6
7 void W_Campingrifle_Reload()
8 {
9         if (self.campingrifle_bulletcounter <= 0)
10                 return;
11         
12         sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
13         ATTACK_FINISHED(self) = time + cvar("g_balance_campingrifle_reloadtime");
14         self.campingrifle_bulletcounter = 0;
15 }
16
17 void W_Campingrifle_CheckReload()
18 {
19         if (self.campingrifle_bulletcounter >= cvar("g_balance_campingrifle_magazinecapacity"))
20                 W_Campingrifle_Reload();
21 }
22
23 void W_CampingRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
24 {
25         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
26                 self.ammo_nails -= pAmmo;
27
28         W_SetupShot (self, '32 8 -8', FALSE, 2, "weapons/campingrifle_fire.wav");
29         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
30
31         if(self.BUTTON_ZOOM) // if zoomed, shoot from the eye
32         {
33                 w_shotdir = v_forward;
34                 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
35         }
36
37         fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pHeadshotAddedDamage / pDamage, pForce, deathtype, EF_RED, 1, pBulletConstant);
38
39         if (cvar("g_casings") >= 2)
40                 SpawnCasing (w_shotorg + v_forward * 10, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3);
41         
42         self.campingrifle_bulletcounter = self.campingrifle_bulletcounter + 1;
43         W_Campingrifle_CheckReload();
44 }
45
46 void W_Campingrifle_Attack()
47 {
48         W_CampingRifle_FireBullet(cvar("g_balance_campingrifle_primary_spread"), cvar("g_balance_campingrifle_primary_damage"), cvar("g_balance_campingrifle_primary_headshotaddeddamage"), cvar("g_balance_campingrifle_primary_force"), cvar("g_balance_campingrifle_primary_speed"), cvar("g_balance_campingrifle_primary_lifetime"), cvar("g_balance_campingrifle_primary_ammo"), WEP_CAMPINGRIFLE, cvar("g_balance_campingrifle_primary_bulletconstant"));
49 }
50
51 void W_Campingrifle_Attack2()
52 {
53         W_CampingRifle_FireBullet(cvar("g_balance_campingrifle_secondary_spread"), cvar("g_balance_campingrifle_secondary_damage"), cvar("g_balance_campingrifle_secondary_headshotaddeddamage"), cvar("g_balance_campingrifle_secondary_force"), cvar("g_balance_campingrifle_secondary_speed"), cvar("g_balance_campingrifle_secondary_lifetime"), cvar("g_balance_campingrifle_secondary_ammo"), WEP_CAMPINGRIFLE | HITTYPE_SECONDARY, cvar("g_balance_campingrifle_secondary_bulletconstant"));
54 }
55
56 void spawnfunc_weapon_campingrifle (void)
57 {
58         weapon_defaultspawnfunc(WEP_CAMPINGRIFLE);
59 }
60
61 .float bot_secondary_campingriflemooth;
62 float w_campingrifle(float req)
63 {
64         if (req == WR_AIM)
65         {
66                 self.BUTTON_ATCK=FALSE;
67                 self.BUTTON_ATCK2=FALSE;
68                 if(vlen(self.origin-self.enemy.origin) > 1000)
69                         self.bot_secondary_campingriflemooth = 0;
70                 if(self.bot_secondary_campingriflemooth == 0)
71                 {
72                         if(bot_aim(cvar("g_balance_campingrifle_primary_speed"), 0, cvar("g_balance_campingrifle_primary_lifetime"), TRUE))
73                         {
74                                 self.BUTTON_ATCK = TRUE;
75                                 if(random() < 0.01) self.bot_secondary_campingriflemooth = 1;
76                         }
77                 }
78                 else
79                 {
80                         if(bot_aim(cvar("g_balance_campingrifle_secondary_speed"), 0, cvar("g_balance_campingrifle_secondary_lifetime"), TRUE))
81                         {
82                                 self.BUTTON_ATCK2 = TRUE;
83                                 if(random() < 0.03) self.bot_secondary_campingriflemooth = 0;
84                         }
85                 }
86         }
87         else if (req == WR_THINK)
88         {
89                 if (self.BUTTON_ATCK)
90                 if (weapon_prepareattack(0, cvar("g_balance_campingrifle_primary_refire")))
91                 {
92                         W_Campingrifle_Attack();
93                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_campingrifle_primary_animtime"), w_ready);
94                 }
95                 if (self.BUTTON_ATCK2)
96                 if (weapon_prepareattack(1, cvar("g_balance_campingrifle_secondary_refire")))
97                 {
98                         W_Campingrifle_Attack2();
99                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_campingrifle_secondary_animtime"), w_ready);
100                 }
101         }
102         else if (req == WR_PRECACHE)
103         {               
104                 precache_model ("models/tracer.mdl");
105                 precache_model ("models/weapons/g_campingrifle.md3");
106                 precache_model ("models/weapons/v_campingrifle.md3");
107                 precache_model ("models/weapons/w_campingrifle.zym");
108                 precache_sound ("weapons/campingrifle_reload.wav");
109                 precache_sound ("weapons/ric1.wav");
110                 precache_sound ("weapons/ric2.wav");
111                 precache_sound ("weapons/ric3.wav");
112                 precache_sound ("weapons/campingrifle_fire.wav");
113                 if (cvar("g_casings") >= 2)
114                 {
115                         precache_sound ("weapons/brass1.wav");
116                         precache_sound ("weapons/brass2.wav");
117                         precache_sound ("weapons/brass3.wav");
118                         precache_model ("models/casing_bronze.mdl");
119                 }
120         }
121         else if (req == WR_SETUP)
122         {
123                 weapon_setup(WEP_CAMPINGRIFLE);
124                 W_Campingrifle_Reload();
125         }
126         else if (req == WR_CHECKAMMO1)
127                 return self.ammo_nails >= cvar("g_balance_campingrifle_primary_ammo");
128         else if (req == WR_CHECKAMMO2)
129                 return self.ammo_nails >= cvar("g_balance_campingrifle_secondary_ammo");
130         else if (req == WR_SUICIDEMESSAGE)
131         {
132                 if(w_deathtype & HITTYPE_SECONDARY)
133                         w_deathtypestring = "shot himself automatically";
134                 else
135                         w_deathtypestring = "sniped himself somehow";
136         }
137         else if (req == WR_KILLMESSAGE)
138         {
139                 if(w_deathtype & HITTYPE_SECONDARY)
140                 {
141                         if(w_deathtype & HITTYPE_BOUNCE)
142                                 w_deathtypestring = "failed to hide from #'s bullet hail";
143                         else
144                                 w_deathtypestring = "died in #'s bullet hail";
145                 }
146                 else
147                 {
148                         if(w_deathtype & HITTYPE_BOUNCE)
149                         {
150                                 // TODO special headshot message here too?
151                                 w_deathtypestring = "failed to hide from #'s rifle";
152                         }
153                         else
154                         {
155                                 if(w_deathtype & HITTYPE_HEADSHOT)
156                                         w_deathtypestring = "got hit in the head by #";
157                                 else
158                                         w_deathtypestring = "was sniped by #";
159                         }
160                 }
161         }
162         return TRUE;
163 };