d6ea5c35b6ae3d14e1feaf7c0a5bde05a16c0173
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_uzi.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", "Machine Gun");
3 #else
4 #ifdef SVQC
5 // leilei's fancy muzzleflash stuff
6 void W_Uzi_Flash_Go() {
7         if (self.frame > 10){
8                 SUB_Remove();
9                 return;
10         }
11         self.frame = self.frame + 2;
12         self.alpha = self.alpha - 0.2;
13         self.think = W_Uzi_Flash_Go;
14         self.nextthink = time + 0.02;
15 };
16
17 .float uzi_bulletcounter;
18 void W_Uzi_Attack (float deathtype)
19 {
20         local entity flash;
21
22         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
23         {
24                 if (self.uzi_bulletcounter == 1)
25                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_first_ammo");
26                 else
27                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_sustained_ammo");
28         }
29         W_SetupShot (self, cvar("g_antilag_bullets") && cvar("g_balance_uzi_speed") >= cvar("g_antilag_bullets"), 0, "weapons/uzi_fire.wav", cvar("g_balance_uzi_first_damage"));
30         if (!g_norecoil)
31         {
32                 self.punchangle_x = random () - 0.5;
33                 self.punchangle_y = random () - 0.5;
34         }
35
36         // this attack_finished just enforces a cooldown at the end of a burst
37         ATTACK_FINISHED(self) = time + cvar("g_balance_uzi_first_refire") * W_WeaponRateFactor();
38
39         if (self.uzi_bulletcounter == 1)
40                 fireBallisticBullet(w_shotorg, w_shotdir, cvar("g_balance_uzi_first_spread"), cvar("g_balance_uzi_speed"), 5, cvar("g_balance_uzi_first_damage"), 0, cvar("g_balance_uzi_first_force"), deathtype, 0, 1, cvar("g_balance_uzi_bulletconstant"));
41         else
42                 fireBallisticBullet(w_shotorg, w_shotdir, cvar("g_balance_uzi_sustained_spread"), cvar("g_balance_uzi_speed"), 5, cvar("g_balance_uzi_sustained_damage"), 0, cvar("g_balance_uzi_sustained_force"), deathtype, 0, 1, cvar("g_balance_uzi_bulletconstant"));
43         endFireBallisticBullet();
44
45         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
46
47         // muzzle flash for 1st person view
48         flash = spawn();
49         setmodel(flash, "models/uziflash.md3"); // precision set below
50         //SUB_SetFade(flash, time + 0.06, 0);
51         flash.think = W_Uzi_Flash_Go;
52         flash.nextthink = time + 0.02;
53         flash.frame = 2;
54         flash.alpha = 1;
55         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
56         W_AttachToShotorg(flash, '5 0 0');
57
58         // casing code
59         if (cvar("g_casings") >= 2)
60                 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
61 }
62
63 // weapon frames
64 void uzi_fire1_02()
65 {
66         if(self.weapon != self.switchweapon) // abort immediately if switching
67         {
68                 w_ready();
69                 return;
70         }
71         if (self.BUTTON_ATCK)
72         {
73                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
74                 {
75                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
76                         w_ready();
77                         return;
78                 }
79                 self.uzi_bulletcounter = self.uzi_bulletcounter + 1;
80                 W_Uzi_Attack(WEP_UZI);
81                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
82         }
83         else
84                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), w_ready);
85 };
86
87 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
88
89 float w_uzi(float req)
90 {
91         if (req == WR_AIM)
92                 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
93                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
94                 else
95                 {
96                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
97                 }
98         else if (req == WR_THINK)
99         {
100                 if (self.BUTTON_ATCK)
101                 if (weapon_prepareattack(0, 0))
102                 {
103                         self.uzi_bulletcounter = 1;
104                         W_Uzi_Attack(WEP_UZI); // sets attack_finished
105                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
106                 }
107                 if (self.BUTTON_ATCK2 && cvar("g_balance_uzi_first"))
108                 if (weapon_prepareattack(1, 0))
109                 {
110                         self.uzi_bulletcounter = 1;
111                         W_Uzi_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
112                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_uzi_first_refire"), w_ready);
113                 }
114         }
115         else if (req == WR_PRECACHE)
116         {
117                 precache_model ("models/uziflash.md3");
118                 precache_model ("models/weapons/g_uzi.md3");
119                 precache_model ("models/weapons/v_uzi.md3");
120                 precache_model ("models/weapons/h_uzi.iqm");
121                 precache_sound ("weapons/uzi_fire.wav");
122         }
123         else if (req == WR_SETUP)
124                 weapon_setup(WEP_UZI);
125         else if (req == WR_CHECKAMMO1)
126                 return self.ammo_nails >= cvar("g_balance_uzi_first_ammo");
127         else if (req == WR_CHECKAMMO2)
128                 return self.ammo_nails >= cvar("g_balance_uzi_first_ammo");
129         else if (req == WR_SUICIDEMESSAGE)
130                 w_deathtypestring = "did the impossible";
131         else if (req == WR_KILLMESSAGE)
132         {
133                 if(w_deathtype & HITTYPE_SECONDARY)
134                         w_deathtypestring = "was sniped by";
135                 else
136                         w_deathtypestring = "was riddled full of holes by";
137         }
138         return TRUE;
139 };
140 #endif
141 #ifdef CSQC
142 float w_uzi(float req)
143 {
144         return TRUE;
145 }
146 #endif
147 #endif