]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_shotgun.qc
very major cleanup of precache code, this patch reduced memory usage
[divverent/nexuiz.git] / data / qcsrc / server / w_shotgun.qc
1
2 void W_Shotgun_Attack (void)
3 {
4         float   sc;
5         float   bullets;
6         float   d;
7         float   f;
8         float   spread;
9
10         bullets = cvar("g_balance_shotgun_primary_bullets");
11         d = cvar("g_balance_shotgun_primary_damage");
12         f = cvar("g_balance_shotgun_primary_force");
13         spread = cvar("g_balance_shotgun_primary_spread");
14
15         W_SetupShot (self, '15 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
16         for (sc = 0;sc < bullets;sc = sc + 1)
17                 fireBullet (w_shotorg, w_shotdir, spread, d, f, IT_SHOTGUN, sc < 3);
18         if (cvar("g_use_ammunition"))
19                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_primary_ammo");
20
21         W_Smoke(w_shotorg, v_forward, 12);
22         //te_smallflash(w_shotorg);
23
24         // casing code
25         if (cvar("g_casings") >= 1)
26                 SpawnCasing (w_shotorg, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
27 }
28
29 void W_Shotgun_Attack2 (void)
30 {
31         float   sc;
32         float   bullets;
33         float   d;
34         float   f;
35         float   spread;
36
37         bullets = cvar("g_balance_shotgun_secondary_bullets");
38         d = cvar("g_balance_shotgun_secondary_damage");
39         f = cvar("g_balance_shotgun_secondary_force");
40         spread = cvar("g_balance_shotgun_secondary_spread");
41
42         W_SetupShot (self, '15 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
43         for (sc = 0;sc < bullets;sc = sc + 1)
44                 fireBullet (w_shotorg, w_shotdir, spread, d, f, IT_SHOTGUN, sc < 3);
45         if (cvar("g_use_ammunition"))
46                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_secondary_ammo");
47
48         W_Smoke(w_shotorg + v_forward * 8, v_forward, 12);
49         //te_smallflash(w_shotorg);
50
51         // casing code
52         if (cvar("g_casings") >= 1)
53                 SpawnCasing (w_shotorg, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
54 }
55
56 // weapon frames
57 void()  shotgun_fire2_03 =
58 {
59         W_Shotgun_Attack2();
60         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), w_ready);
61 }
62 void()  shotgun_fire2_02 =
63 {
64         W_Shotgun_Attack2();
65         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_03);
66 }
67
68 float(float req) w_shotgun =
69 {
70         if (req == WR_AIM)
71                 if(vlen(self.origin-self.enemy.origin)>200)
72                         self.button0 = bot_aim(1000000, 0, 0.001, FALSE);
73                 else
74                         self.button3 = bot_aim(1000000, 0, 0.001, FALSE);
75         else if (req == WR_THINK)
76         {
77                 if (self.button0)
78                 if (weapon_prepareattack(0, cvar("g_balance_shotgun_primary_refire")))
79                 {
80                         W_Shotgun_Attack();
81                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_primary_animtime"), w_ready);
82                 }
83                 if (self.button3)
84                 if (weapon_prepareattack(1, cvar("g_balance_shotgun_secondary_refire")))
85                 {
86                         W_Shotgun_Attack2();
87                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_02);
88                 }
89         }
90         else if (req == WR_PRECACHE)
91         {
92                 precache_model ("models/tracer.mdl");
93                 precache_model ("models/weapons/g_shotgun.md3");
94                 precache_model ("models/weapons/v_shotgun.md3");
95                 precache_model ("models/weapons/w_shotgun.zym");
96                 precache_sound ("misc/itempickup.wav");
97                 precache_sound ("weapons/ric1.wav");
98                 precache_sound ("weapons/ric2.wav");
99                 precache_sound ("weapons/ric3.wav");
100                 precache_sound ("weapons/shotgun_fire.wav");
101                 precache_sound ("weapons/tink1.wav");
102                 if (cvar("g_casings") >= 1)
103                         precache_model ("models/casing_shell.mdl");
104         }
105         else if (req == WR_SETUP)
106                 weapon_setup(WEP_SHOTGUN, "shotgun", IT_SHELLS);
107         else if (req == WR_CHECKAMMO1)
108                 return self.ammo_shells >= cvar("g_balance_shotgun_primary_ammo");
109         else if (req == WR_CHECKAMMO2)
110                 return self.ammo_shells >= cvar("g_balance_shotgun_secondary_ammo") * 3;
111         return TRUE;
112 };