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