]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_campingrifle.qc
fix bugs with camping rifle introduced by my anim changes
[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_ReloadedAndReady()
8 {
9         float t;
10         self.campingrifle_bulletcounter = 0;
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 == 0)
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
40 void W_Campingrifle_CheckReloadAndReady()
41 {
42         w_ready();
43         if (self.campingrifle_bulletcounter >= cvar("g_balance_campingrifle_magazinecapacity"))
44                 W_Campingrifle_Reload();
45         else
46                 w_ready();
47 }
48
49 void W_CampingRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant)
50 {
51         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
52                 self.ammo_nails -= pAmmo;
53
54         W_SetupShot (self, '41 7 -10.5', FALSE, 2, "weapons/campingrifle_fire.wav");
55         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
56
57         if(self.BUTTON_ZOOM) // if zoomed, shoot from the eye
58         {
59                 w_shotdir = v_forward;
60                 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
61         }
62
63         fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pHeadshotAddedDamage / pDamage, pForce, deathtype, EF_RED, 1, pBulletConstant);
64
65         if (cvar("g_casings") >= 2)
66                 SpawnCasing (w_shotorg - v_forward * 15, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3);
67         
68         self.campingrifle_bulletcounter = self.campingrifle_bulletcounter + 1;
69 }
70
71 void W_Campingrifle_Attack()
72 {
73         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"));
74 }
75
76 void W_Campingrifle_Attack2()
77 {
78         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"));
79 }
80
81 void spawnfunc_weapon_campingrifle (void)
82 {
83         weapon_defaultspawnfunc(WEP_CAMPINGRIFLE);
84 }
85
86 .float bot_secondary_campingriflemooth;
87 float w_campingrifle(float req)
88 {
89         if (req == WR_AIM)
90         {
91                 self.BUTTON_ATCK=FALSE;
92                 self.BUTTON_ATCK2=FALSE;
93                 if(vlen(self.origin-self.enemy.origin) > 1000)
94                         self.bot_secondary_campingriflemooth = 0;
95                 if(self.bot_secondary_campingriflemooth == 0)
96                 {
97                         if(bot_aim(cvar("g_balance_campingrifle_primary_speed"), 0, cvar("g_balance_campingrifle_primary_lifetime"), TRUE))
98                         {
99                                 self.BUTTON_ATCK = TRUE;
100                                 if(random() < 0.01) self.bot_secondary_campingriflemooth = 1;
101                         }
102                 }
103                 else
104                 {
105                         if(bot_aim(cvar("g_balance_campingrifle_secondary_speed"), 0, cvar("g_balance_campingrifle_secondary_lifetime"), TRUE))
106                         {
107                                 self.BUTTON_ATCK2 = TRUE;
108                                 if(random() < 0.03) self.bot_secondary_campingriflemooth = 0;
109                         }
110                 }
111         }
112         else if (req == WR_THINK)
113         {
114                 if(self.campingrifle_bulletcounter < 0)
115                 {
116                         if(self.switchweapon == self.weapon)
117                         if(self.weaponentity.state == WS_READY)
118                                 W_Campingrifle_Reload();
119                 }
120                 else
121                 {
122                         if (self.BUTTON_ATCK)
123                         if (weapon_prepareattack(0, cvar("g_balance_campingrifle_primary_refire")))
124                         {
125                                 W_Campingrifle_Attack();
126                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_campingrifle_primary_animtime"), W_Campingrifle_CheckReloadAndReady);
127                         }
128                         if (self.BUTTON_ATCK2)
129                         if (weapon_prepareattack(1, cvar("g_balance_campingrifle_secondary_refire")))
130                         {
131                                 W_Campingrifle_Attack2();
132                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_campingrifle_secondary_animtime"), W_Campingrifle_CheckReloadAndReady);
133                         }
134                 }
135         }
136         else if (req == WR_PRECACHE)
137         {               
138                 precache_model ("models/weapons/g_campingrifle.md3");
139                 precache_model ("models/weapons/v_campingrifle.md3");
140                 precache_model ("models/weapons/w_campingrifle.zym");
141                 precache_sound ("weapons/campingrifle_reload.wav");
142                 precache_sound ("weapons/campingrifle_fire.wav");
143         }
144         else if (req == WR_SETUP)
145         {
146                 weapon_setup(WEP_CAMPINGRIFLE);
147                 if(self.campingrifle_bulletcounter != 0)
148                         self.campingrifle_bulletcounter = -1;
149         }
150         else if (req == WR_CHECKAMMO1)
151                 return self.ammo_nails >= cvar("g_balance_campingrifle_primary_ammo");
152         else if (req == WR_CHECKAMMO2)
153                 return self.ammo_nails >= cvar("g_balance_campingrifle_secondary_ammo");
154         else if (req == WR_SUICIDEMESSAGE)
155         {
156                 if(w_deathtype & HITTYPE_SECONDARY)
157                         w_deathtypestring = "shot himself automatically";
158                 else
159                         w_deathtypestring = "sniped himself somehow";
160         }
161         else if (req == WR_KILLMESSAGE)
162         {
163                 if(w_deathtype & HITTYPE_SECONDARY)
164                 {
165                         if(w_deathtype & HITTYPE_BOUNCE)
166                                 w_deathtypestring = "failed to hide from #'s bullet hail";
167                         else
168                                 w_deathtypestring = "died in #'s bullet hail";
169                 }
170                 else
171                 {
172                         if(w_deathtype & HITTYPE_BOUNCE)
173                         {
174                                 // TODO special headshot message here too?
175                                 w_deathtypestring = "failed to hide from #'s rifle";
176                         }
177                         else
178                         {
179                                 if(w_deathtype & HITTYPE_HEADSHOT)
180                                         w_deathtypestring = "got hit in the head by #";
181                                 else
182                                         w_deathtypestring = "was sniped by #";
183                         }
184                 }
185         }
186         else if (req == WR_RELOAD)
187         {
188                 W_Campingrifle_Reload();
189         }
190         return TRUE;
191 };