]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_shotgun.qc
now with REAL linear falloff (old formula was wrong)
[divverent/nexuiz.git] / data / qcsrc / server / w_shotgun.qc
1
2 void W_Shotgun_Attack (void)
3 {
4         float   sc;
5         float   ammoamount;
6         float   bullets;
7         float   d;
8         float   f;
9         float   spread;
10         float   bulletspeed;
11         float   bulletconstant;
12         local entity flash;
13
14         ammoamount = cvar("g_balance_shotgun_primary_ammo");
15         bullets = cvar("g_balance_shotgun_primary_bullets");
16         d = cvar("g_balance_shotgun_primary_damage");
17         f = cvar("g_balance_shotgun_primary_force");
18         spread = cvar("g_balance_shotgun_primary_spread");
19         bulletspeed = cvar("g_balance_shotgun_primary_speed");
20         bulletconstant = cvar("g_balance_shotgun_primary_bulletconstant");
21
22         W_SetupShot (self, cvar("g_antilag_bullets") && bulletspeed >= cvar("g_antilag_bullets"), 5, "weapons/shotgun_fire.wav", cvar("g_balance_shotgun_primary_damage"));
23         for (sc = 0;sc < bullets;sc = sc + 1)
24                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant);
25         endFireBallisticBullet();
26         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
27                 self.ammo_shells = self.ammo_shells - ammoamount;
28
29         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_primary_ammo"));
30
31         // casing code
32         if (cvar("g_casings") >= 1)
33                 for (sc = 0;sc < ammoamount;sc = sc + 1)
34                         SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
35
36         // muzzle flash for 1st person view
37         flash = spawn();
38         setmodel(flash, "models/uziflash.md3"); // precision set below
39         flash.think = SUB_Remove;
40         flash.nextthink = time + 0.06;
41         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
42         W_AttachToShotorg(flash, '5 0 0');
43
44 }
45
46 void W_Shotgun_Attack2 (void)
47 {
48         float   sc;
49         float   ammoamount;
50         float   bullets;
51         float   d;
52         float   f;
53         float   spread;
54         float   bulletspeed;
55         float   bulletconstant;
56         local entity flash;
57
58         ammoamount = cvar("g_balance_shotgun_secondary_ammo");
59         bullets = cvar("g_balance_shotgun_secondary_bullets");
60         d = cvar("g_balance_shotgun_secondary_damage");
61         f = cvar("g_balance_shotgun_secondary_force");
62         spread = cvar("g_balance_shotgun_secondary_spread");
63         bulletspeed = cvar("g_balance_shotgun_secondary_speed");
64         bulletconstant = cvar("g_balance_shotgun_secondary_bulletconstant");
65
66         W_SetupShot (self, cvar("g_antilag_bullets") && bulletspeed >= cvar("g_antilag_bullets"), 5, "weapons/shotgun_fire.wav", cvar("g_balance_shotgun_secondary_damage"));
67         for (sc = 0;sc < bullets;sc = sc + 1)
68                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN | HITTYPE_SECONDARY, 0, 1, bulletconstant);
69         endFireBallisticBullet();
70         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
71                 self.ammo_shells = self.ammo_shells - ammoamount;
72
73         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_secondary_ammo"));
74
75         // casing code
76         if (cvar("g_casings") >= 1)
77                 for (sc = 0;sc < ammoamount;sc = sc + 1)
78                         SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
79
80         flash = spawn();
81         setmodel(flash, "models/uziflash.md3"); // precision set below
82         flash.scale = 1.2;
83         flash.think = SUB_Remove;
84         flash.nextthink = time + 0.06;
85         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
86         W_AttachToShotorg(flash, '5 0 0');
87 }
88
89 // weapon frames
90 void shotgun_fire2_03()
91 {
92         W_Shotgun_Attack2();
93         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), w_ready);
94 }
95 void shotgun_fire2_02()
96 {
97         W_Shotgun_Attack2();
98         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_03);
99 }
100
101 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
102
103 float w_shotgun(float req)
104 {
105         if (req == WR_AIM)
106                 if(vlen(self.origin-self.enemy.origin)>200)
107                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
108                 else
109                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
110         else if (req == WR_THINK)
111         {
112                 if (self.BUTTON_ATCK)
113                 if (weapon_prepareattack(0, cvar("g_balance_shotgun_primary_refire")))
114                 {
115                         W_Shotgun_Attack();
116                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_primary_animtime"), w_ready);
117                 }
118                 if (self.BUTTON_ATCK2)
119                 if (weapon_prepareattack(1, cvar("g_balance_shotgun_secondary_refire")))
120                 {
121                         W_Shotgun_Attack2();
122                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_02);
123                 }
124         }
125         else if (req == WR_PRECACHE)
126         {
127                 precache_model ("models/uziflash.md3");
128                 precache_model ("models/weapons/g_shotgun.md3");
129                 precache_model ("models/weapons/v_shotgun.md3");
130                 precache_model ("models/weapons/h_shotgun.dpm");
131                 precache_sound ("misc/itempickup.wav");
132                 precache_sound ("weapons/shotgun_fire.wav");
133         }
134         else if (req == WR_SETUP)
135                 weapon_setup(WEP_SHOTGUN);
136         else if (req == WR_CHECKAMMO1)
137                 return self.ammo_shells >= cvar("g_balance_shotgun_primary_ammo");
138         else if (req == WR_CHECKAMMO2)
139                 return self.ammo_shells >= cvar("g_balance_shotgun_secondary_ammo") * 3;
140         else if (req == WR_SUICIDEMESSAGE)
141                 w_deathtypestring = "did the impossible";
142         else if (req == WR_KILLMESSAGE)
143         {
144                 w_deathtypestring = "was gunned by"; // unchecked: SECONDARY
145         }
146         return TRUE;
147 };