]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_campingrifle.qc
rifle: invert the meaning of the bulletcounter field
[divverent/nexuiz.git] / data / qcsrc / server / w_campingrifle.qc
1 //Camping rifle Primary mode: manually operated bolt*, Secondary: full automatic**
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_ReloadedAndReady()
8 {
9         float t;
10         self.campingrifle_bulletcounter = cvar("g_balance_campingrifle_magazinecapacity");
11         t = ATTACK_FINISHED(self) - cvar("g_balance_campingrifle_reloadtime") - 1;
12         ATTACK_FINISHED(self) = t;
13         w_ready();
14 }
15
16 void W_Campingrifle_Reload()
17 {
18         float t;
19
20         if (self.campingrifle_bulletcounter >= cvar("g_balance_campingrifle_magazinecapacity"))
21                 return;
22         
23         if (self.weaponentity)
24         {
25                 if (self.weaponentity.wframe == WFRAME_RELOAD)
26                         return;
27
28                 // allow to switch away while reloading, but this will cause a new reload!
29                 self.weaponentity.state = WS_READY;
30         }
31
32         sound (self, CHAN_WEAPON2, "weapons/campingrifle_reload.wav", VOL_BASE, ATTN_NORM);
33
34         t = max(time, ATTACK_FINISHED(self)) + cvar("g_balance_campingrifle_reloadtime") + 1;
35         ATTACK_FINISHED(self) = t;
36
37         weapon_thinkf(WFRAME_RELOAD, cvar("g_balance_campingrifle_reloadtime"), W_Campingrifle_ReloadedAndReady);
38
39         self.campingrifle_bulletcounter = -1;
40 }
41
42 void W_Campingrifle_CheckReloadAndReady()
43 {
44         w_ready();
45         if (self.campingrifle_bulletcounter <= 0)
46                 W_Campingrifle_Reload();
47         else
48                 w_ready();
49 }
50
51 void W_CampingRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
52 {
53         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
54                 self.ammo_nails -= pAmmo;
55
56         if(deathtype & HITTYPE_SECONDARY)
57                 W_SetupShot (self, cvar("g_antilag_bullets") && pSpeed >= cvar("g_antilag_bullets"), 2, "weapons/campingrifle_fire2.wav", cvar("g_balance_campingrifle_secondary_damage"));
58         else
59                 W_SetupShot (self, cvar("g_antilag_bullets") && pSpeed >= cvar("g_antilag_bullets"), 2, "weapons/campingrifle_fire.wav", cvar("g_balance_campingrifle_primary_damage"));
60
61         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
62
63         if(self.BUTTON_ZOOM) // if zoomed, shoot from the eye
64         {
65                 w_shotdir = v_forward;
66                 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
67         }
68
69         fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pHeadshotAddedDamage / pDamage, pForce, deathtype, EF_RED, 1, pBulletConstant);
70
71         if (cvar("g_casings") >= 2)
72                 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);
73         
74         self.campingrifle_bulletcounter = self.campingrifle_bulletcounter - 1;
75 }
76
77 void W_Campingrifle_Attack()
78 {
79         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"));
80 }
81
82 void W_Campingrifle_Attack2()
83 {
84         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"));
85 }
86
87 void spawnfunc_weapon_campingrifle (void)
88 {
89         weapon_defaultspawnfunc(WEP_CAMPINGRIFLE);
90 }
91
92 .float bot_secondary_campingriflemooth;
93 float w_campingrifle(float req)
94 {
95         if (req == WR_AIM)
96         {
97                 self.BUTTON_ATCK=FALSE;
98                 self.BUTTON_ATCK2=FALSE;
99                 if(vlen(self.origin-self.enemy.origin) > 1000)
100                         self.bot_secondary_campingriflemooth = 0;
101                 if(self.bot_secondary_campingriflemooth == 0)
102                 {
103                         if(bot_aim(cvar("g_balance_campingrifle_primary_speed"), 0, cvar("g_balance_campingrifle_primary_lifetime"), TRUE))
104                         {
105                                 self.BUTTON_ATCK = TRUE;
106                                 if(random() < 0.01) self.bot_secondary_campingriflemooth = 1;
107                         }
108                 }
109                 else
110                 {
111                         if(bot_aim(cvar("g_balance_campingrifle_secondary_speed"), 0, cvar("g_balance_campingrifle_secondary_lifetime"), TRUE))
112                         {
113                                 self.BUTTON_ATCK2 = TRUE;
114                                 if(random() < 0.03) self.bot_secondary_campingriflemooth = 0;
115                         }
116                 }
117         }
118         else if (req == WR_THINK)
119         {
120                 if(self.campingrifle_bulletcounter < 0) // forced reload (e.g. because interrupted)
121                 {
122                         if(self.switchweapon == self.weapon)
123                         if(self.weaponentity.state == WS_READY)
124                                 W_Campingrifle_Reload();
125                 }
126                 else
127                 {
128                         if (self.BUTTON_ATCK)
129                         if (weapon_prepareattack(0, cvar("g_balance_campingrifle_primary_refire")))
130                         {
131                                 W_Campingrifle_Attack();
132                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_campingrifle_primary_animtime"), W_Campingrifle_CheckReloadAndReady);
133                         }
134                         if (self.BUTTON_ATCK2)
135                         if (weapon_prepareattack(1, cvar("g_balance_campingrifle_secondary_refire")))
136                         {
137                                 W_Campingrifle_Attack2();
138                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_campingrifle_secondary_animtime"), W_Campingrifle_CheckReloadAndReady);
139                         }
140                 }
141         }
142         else if (req == WR_PRECACHE)
143         {               
144                 precache_model ("models/weapons/g_campingrifle.md3");
145                 precache_model ("models/weapons/v_campingrifle.md3");
146                 precache_model ("models/weapons/h_campingrifle.dpm");
147                 precache_sound ("weapons/campingrifle_reload.wav");
148                 precache_sound ("weapons/campingrifle_fire.wav");
149                 precache_sound ("weapons/campingrifle_fire2.wav");
150         }
151         else if (req == WR_SETUP)
152         {
153                 weapon_setup(WEP_CAMPINGRIFLE);
154
155                 if(cvar("g_balance_campingrifle_auto_reload_after_changing_weapons"))
156                 {
157                         if(self.campingrifle_bulletcounter < cvar("g_balance_campingrifle_magazinecapacity"))
158                                 self.campingrifle_bulletcounter = -1;
159                 }
160         }
161         else if (req == WR_CHECKAMMO1)
162                 return self.ammo_nails >= cvar("g_balance_campingrifle_primary_ammo");
163         else if (req == WR_CHECKAMMO2)
164                 return self.ammo_nails >= cvar("g_balance_campingrifle_secondary_ammo");
165         else if (req == WR_SUICIDEMESSAGE)
166         {
167                 if(w_deathtype & HITTYPE_SECONDARY)
168                         w_deathtypestring = "shot himself automatically";
169                 else
170                         w_deathtypestring = "sniped himself somehow";
171         }
172         else if (req == WR_KILLMESSAGE)
173         {
174                 if(w_deathtype & HITTYPE_SECONDARY)
175                 {
176                         if(w_deathtype & HITTYPE_BOUNCE)
177                                 w_deathtypestring = "failed to hide from #'s bullet hail";
178                         else
179                                 w_deathtypestring = "died in #'s bullet hail";
180                 }
181                 else
182                 {
183                         if(w_deathtype & HITTYPE_BOUNCE)
184                         {
185                                 // TODO special headshot message here too?
186                                 w_deathtypestring = "failed to hide from #'s rifle";
187                         }
188                         else
189                         {
190                                 if(w_deathtype & HITTYPE_HEADSHOT)
191                                         w_deathtypestring = "got hit in the head by #";
192                                 else
193                                         w_deathtypestring = "was sniped by #";
194                         }
195                 }
196         }
197         else if (req == WR_RELOAD)
198         {
199                 W_Campingrifle_Reload();
200         }
201         return TRUE;
202 };