ecc5791ed336f7ecf0929fa233b8f5abec400092
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_hmg.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id      */ HMG,
4 /* function      */ W_HeavyMachineGun,
5 /* ammotype      */ ammo_nails,
6 /* impulse       */ 3,
7 /* flags         */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_SUPERWEAPON,
8 /* rating        */ BOT_PICKUP_RATING_HIGH,
9 /* color     */ '1 1 0',
10 /* modelname */ "ok_hmg",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairuzi 0.6",
13 /* wepimg    */ "weaponhmg",
14 /* refname   */ "hmg",
15 /* wepname   */ _("Heavy Machine Gun")
16 );
17
18 #define HMG_SETTINGS(w_cvar,w_prop) HMG_SETTINGS_LIST(w_cvar, w_prop, HMG, hmg)
19 #define HMG_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, NONE, spread_min) \
21         w_cvar(id, sn, NONE, spread_max) \
22         w_cvar(id, sn, NONE, spread_add) \
23         w_cvar(id, sn, NONE, solidpenetration) \
24         w_cvar(id, sn, NONE, damage) \
25         w_cvar(id, sn, NONE, force) \
26         w_cvar(id, sn, NONE, refire) \
27         w_cvar(id, sn, NONE, ammo) \
28         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
29         w_prop(id, sn, float,  reloading_time, reload_time) \
30         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
31         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
32         w_prop(id, sn, string, weaponreplace, weaponreplace) \
33         w_prop(id, sn, float,  weaponstart, weaponstart) \
34         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
35         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
36
37 #ifdef SVQC
38 HMG_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
39 #endif
40 #else
41 #ifdef SVQC
42
43 void spawnfunc_weapon_hmg() { weapon_defaultspawnfunc(WEP_HMG); }
44
45 void W_HeavyMachineGun_Attack_Auto()
46 {
47         if (!self.BUTTON_ATCK)
48         {
49                 w_ready();
50                 return;
51         }
52
53         if(!WEP_ACTION(self.weapon, WR_CHECKAMMO1))
54         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
55         {
56                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
57                 w_ready();
58                 return;
59         }
60
61         W_DecreaseAmmo(WEP_CVAR(hmg, ammo));
62
63         W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, WEP_CVAR(hmg, damage));
64
65         if(!autocvar_g_norecoil)
66         {
67                 self.punchangle_x = random () - 0.5;
68                 self.punchangle_y = random () - 0.5;
69         }
70
71         float hmg_spread = bound(WEP_CVAR(hmg, spread_min), WEP_CVAR(hmg, spread_min) + (WEP_CVAR(hmg, spread_add) * self.misc_bulletcounter), WEP_CVAR(hmg, spread_max));
72         fireBullet(w_shotorg, w_shotdir, hmg_spread, WEP_CVAR(hmg, solidpenetration), WEP_CVAR(hmg, damage), WEP_CVAR(hmg, force), WEP_HMG, 0);
73
74         self.misc_bulletcounter = self.misc_bulletcounter + 1;
75
76         pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
77
78         W_MachineGun_MuzzleFlash();
79         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
80
81         if (autocvar_g_casings >= 2) // casing code
82                 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);
83
84         ATTACK_FINISHED(self) = time + WEP_CVAR(hmg, refire) * W_WeaponRateFactor();
85         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(hmg, refire), W_HeavyMachineGun_Attack_Auto);
86 }
87
88 float W_HeavyMachineGun(float req)
89 {
90         float ammo_amount;
91         switch(req)
92         {
93                 case WR_AIM:
94                 {
95                         if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
96                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
97                         else
98                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
99                         
100                         return TRUE;
101                 }
102                 case WR_THINK:
103                 {
104                         if(WEP_CVAR(hmg, reload_ammo) && self.clip_load < WEP_CVAR(hmg, ammo)) // forced reload
105                                 WEP_ACTION(self.weapon, WR_RELOAD);
106                         else
107                         {
108                                 if (self.BUTTON_ATCK)
109                                 if (weapon_prepareattack(0, 0))
110                                 {
111                                         self.misc_bulletcounter = 0;
112                                         W_HeavyMachineGun_Attack_Auto();
113                                 }
114                         }
115
116                         return TRUE;
117                 }
118                 case WR_INIT:
119                 {
120                         precache_model ("models/uziflash.md3");
121                         precache_model ("models/weapons/g_ok_hmg.md3");
122                         precache_model ("models/weapons/v_ok_hmg.md3");
123                         precache_model ("models/weapons/h_ok_hmg.iqm");
124                         precache_sound ("weapons/uzi_fire.wav");
125                         HMG_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
126                         return TRUE;
127                 }
128                 case WR_CHECKAMMO1:
129                 {
130                         ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
131
132                         if(autocvar_g_balance_hmg_reload_ammo)
133                                 ammo_amount += self.(weapon_load[WEP_HMG]) >= WEP_CVAR(hmg, ammo);
134
135                         return ammo_amount;
136                 }
137                 case WR_CHECKAMMO2:
138                 {
139                         ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
140
141                         if(autocvar_g_balance_hmg_reload_ammo)
142                                 ammo_amount += self.(weapon_load[WEP_HMG]) >= WEP_CVAR(hmg, ammo);
143
144                         return ammo_amount;
145                 }
146                 case WR_CONFIG:
147                 {
148                         HMG_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
149                         return TRUE;
150                 }
151                 case WR_RELOAD:
152                 {
153                         W_Reload(WEP_CVAR(hmg, ammo), "weapons/reload.wav");
154                         return TRUE;
155                 }
156                 case WR_SUICIDEMESSAGE:
157                 {
158                         return WEAPON_THINKING_WITH_PORTALS;
159                 }
160                 case WR_KILLMESSAGE:
161                 {
162                         if(w_deathtype & HITTYPE_SECONDARY)
163                                 return WEAPON_HMG_MURDER_SNIPE;
164                         else
165                                 return WEAPON_HMG_MURDER_SPRAY;
166                 }
167         }
168         return FALSE;
169 }
170 #endif
171 #ifdef CSQC
172 float W_HeavyMachineGun(float req)
173 {
174         switch(req)
175         {
176                 case WR_IMPACTEFFECT:
177                 {
178                         vector org2;
179                         org2 = w_org + w_backoff * 2;
180                         pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
181                         if(!w_issilent)
182                                 if(w_random < 0.05)
183                                         sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
184                                 else if(w_random < 0.1)
185                                         sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
186                                 else if(w_random < 0.2)
187                                         sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
188
189                         return TRUE;
190                 }
191                 case WR_INIT:
192                 {
193                         precache_sound("weapons/ric1.wav");
194                         precache_sound("weapons/ric2.wav");
195                         precache_sound("weapons/ric3.wav");
196                         return TRUE;
197                 }
198                 case WR_ZOOMRETICLE:
199                 {
200                         // no weapon specific image for this weapon
201                         return FALSE;
202                 }
203         }
204         return FALSE;
205 }
206 #endif
207 #endif