]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_uzi.qc
tweaked bot weapon choosing
[divverent/nexuiz.git] / data / qcsrc / server / w_uzi.qc
1 // leilei's fancy muzzleflash stuff
2 void() W_Uzi_Flash_Go;
3 void() W_Uzi_Flash_Go {
4         if (self.frame > 10){
5                 SUB_Remove();
6                 return;
7         }
8         self.frame = self.frame + 2;
9         self.alpha = self.alpha - 0.2;
10         self.think = W_Uzi_Flash_Go;
11         self.nextthink = time + 0.02;
12 };
13
14 .float uzi_bulletcounter;
15 void W_Uzi_Attack (void)
16 {
17         local entity flash, flash2;
18
19         if (cvar("g_use_ammunition"))
20         {
21                 if (self.uzi_bulletcounter == 1)
22                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_first_ammo");
23                 else
24                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_sustained_ammo");
25         }
26         W_SetupShot (self, '25 5.5 -8', TRUE, 0, "weapons/uzi_fire.wav");
27         //W_SetupShot (self, '25 8 -8', TRUE, 0, "weapons/uzi_fire.wav"); // TODO: move model to the right a little
28         if (!g_norecoil)
29         {
30                 self.punchangle_x = random () - 0.5;
31                 self.punchangle_y = random () - 0.5;
32         }
33
34         // this attack_finished just enforces a cooldown at the end of a burst
35         ATTACK_FINISHED(self) = time + cvar("g_balance_uzi_first_refire");
36
37         if (self.uzi_bulletcounter == 1)
38                 fireBullet (w_shotorg, w_shotdir, cvar("g_balance_uzi_first_spread"), cvar("g_balance_uzi_first_damage"), cvar("g_balance_uzi_first_force"), IT_UZI, TRUE);
39         else
40                 fireBullet (w_shotorg, w_shotdir, cvar("g_balance_uzi_sustained_spread"), cvar("g_balance_uzi_sustained_damage"), cvar("g_balance_uzi_sustained_force"), IT_UZI, (self.uzi_bulletcounter & 3) == 0);
41
42         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
43
44         // muzzle flash for 1st person view
45         flash = spawn();
46         setorigin(flash, '53 5 0');
47         setmodel(flash, "models/uziflash.md3"); // precision set below
48         setattachment(flash, self.weaponentity, "bone01");
49         flash.owner = self;
50         flash.viewmodelforclient = self;
51         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
52         flash.scale = 1.2;
53         //SUB_SetFade(flash, time + 0.06, 0);
54         flash.think = W_Uzi_Flash_Go;
55         flash.nextthink = time + 0.02;
56         flash.frame = 2;
57
58         // muzzle flash for 3rd person view
59         flash2 = spawn();
60         setorigin(flash2, '43 1 8');
61         setmodel(flash2, "models/uziflash.md3"); // precision set below
62         setattachment(flash2, self.exteriorweaponentity, "");
63         //SUB_SetFade(flash2, time + 0.06, 0);
64         flash2.think = W_Uzi_Flash_Go;
65         flash2.nextthink = time + 0.02;
66         flash2.frame = 2;
67         // common properties
68         flash.angles_z = flash2.angles_z = flash.v_angle_z + random() * 180;
69         flash.alpha = flash2.alpha = 1;
70         flash.effects = flash2.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
71
72         // casing code
73         if (cvar("g_casings") >= 2)
74                 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);
75 }
76
77 // weapon frames
78 void()  uzi_fire1_02 =
79 {
80         if(self.weapon != self.switchweapon) // abort immediately if switching
81         {
82                 w_ready();
83                 return;
84         }
85         if (self.button0)
86         {
87                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
88                 {
89                         self.switchweapon = w_getbestweapon(self);
90                         if (self.switchweapon != self.weapon)
91                                 self.cnt = self.weapon;
92                         w_ready();
93                         return;
94                 }
95                 ATTACK_FINISHED(self) = time + cvar("g_balance_uzi_refire");
96                 self.uzi_bulletcounter = self.uzi_bulletcounter + 1;
97                 W_Uzi_Attack();
98                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
99         }
100         else
101                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), w_ready);
102 };
103
104 float(float req) w_uzi =
105 {
106         if (req == WR_AIM)
107                 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
108                         self.button0 = bot_aim(1000000, 0, 0.001, FALSE);
109                 else
110                 {
111                         self.button3 = bot_aim(1000000, 0, 0.001, FALSE);
112                 }
113         else if (req == WR_THINK)
114         {
115                 if (self.button0)
116                 if (weapon_prepareattack(0, cvar("g_balance_uzi_refire")))
117                 {
118                         self.uzi_bulletcounter = 1;
119                         W_Uzi_Attack();
120                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
121                 }
122                 if (self.button3)
123                 if (weapon_prepareattack(1, cvar("g_balance_uzi_refire")))
124                 {
125                         self.uzi_bulletcounter = 1;
126                         W_Uzi_Attack();
127                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), w_ready);
128                 }
129         }
130         else if (req == WR_PRECACHE)
131         {
132                 precache_model ("models/tracer.mdl");
133                 precache_model ("models/uziflash.md3");
134                 precache_model ("models/weapons/g_uzi.md3");
135                 precache_model ("models/weapons/v_uzi.md3");
136                 precache_model ("models/weapons/w_uzi.zym");
137                 precache_sound ("weapons/ric1.wav");
138                 precache_sound ("weapons/ric2.wav");
139                 precache_sound ("weapons/ric3.wav");
140                 precache_sound ("weapons/tink1.wav");
141                 precache_sound ("weapons/uzi_fire.wav");
142                 if (cvar("g_casings") >= 2)
143                         precache_model ("models/casing_bronze.mdl");
144         }
145         else if (req == WR_SETUP)
146                 weapon_setup(WEP_UZI, "uzi", IT_NAILS);
147         else if (req == WR_CHECKAMMO1)
148                 return self.ammo_nails >= cvar("g_balance_uzi_first_ammo");
149         else if (req == WR_CHECKAMMO2)
150                 return self.ammo_nails >= cvar("g_balance_uzi_first_ammo");
151         else if (req == WR_REGISTER)
152                 weapon_register(WEP_UZI, cvar("g_balance_uzi_first_ammo"));
153         return TRUE;
154 };