]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hmg.qc
Monsters: make mage more player friendly
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hmg.qc
1 #ifndef IMPLEMENTATION
2 CLASS(HeavyMachineGun, Weapon)
3 /* ammotype  */ ATTRIB(HeavyMachineGun, ammo_field, .int, ammo_nails)
4 /* impulse   */ ATTRIB(HeavyMachineGun, impulse, int, 3)
5 /* flags     */ ATTRIB(HeavyMachineGun, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_SUPERWEAPON);
6 /* rating    */ ATTRIB(HeavyMachineGun, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color     */ ATTRIB(HeavyMachineGun, wpcolor, vector, '0.5 0.5 0');
8 /* modelname */ ATTRIB(HeavyMachineGun, mdl, string, "ok_hmg");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(HeavyMachineGun, m_model, Model, MDL_HMG_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(HeavyMachineGun, w_crosshair, string, "gfx/crosshairuzi");
13 /* crosshair */ ATTRIB(HeavyMachineGun, w_crosshair_size, float, 0.6);
14 /* wepimg    */ ATTRIB(HeavyMachineGun, model2, string, "weaponhmg");
15 /* refname   */ ATTRIB(HeavyMachineGun, netname, string, "hmg");
16 /* wepname   */ ATTRIB(HeavyMachineGun, message, string, _("Heavy Machine Gun"));
17 ENDCLASS(HeavyMachineGun)
18 REGISTER_WEAPON(HMG, NEW(HeavyMachineGun));
19
20 #define HMG_SETTINGS(w_cvar,w_prop) HMG_SETTINGS_LIST(w_cvar, w_prop, HMG, hmg)
21 #define HMG_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, NONE, spread_min) \
23         w_cvar(id, sn, NONE, spread_max) \
24         w_cvar(id, sn, NONE, spread_add) \
25         w_cvar(id, sn, NONE, solidpenetration) \
26         w_cvar(id, sn, NONE, damage) \
27         w_cvar(id, sn, NONE, force) \
28         w_cvar(id, sn, NONE, refire) \
29         w_cvar(id, sn, NONE, ammo) \
30         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
31         w_prop(id, sn, float,  reloading_time, reload_time) \
32         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
33         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
34         w_prop(id, sn, string, weaponreplace, weaponreplace) \
35         w_prop(id, sn, float,  weaponstart, weaponstart) \
36         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
37         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
38
39 #ifdef SVQC
40 HMG_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
41 #endif
42 #endif
43 #ifdef IMPLEMENTATION
44 #ifdef SVQC
45
46 void spawnfunc_weapon_hmg() { weapon_defaultspawnfunc(WEP_HMG.m_id); }
47
48 void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, bool fire1, bool fire2)
49 {SELFPARAM();
50         if (!self.BUTTON_ATCK)
51         {
52                 w_ready(thiswep, fire1, fire2);
53                 return;
54         }
55
56         if(!_WEP_ACTION(self.weapon, WR_CHECKAMMO1))
57         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
58         {
59                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
60                 w_ready(thiswep, fire1, fire2);
61                 return;
62         }
63
64         W_DecreaseAmmo(WEP_HMG, WEP_CVAR(hmg, ammo));
65
66         W_SetupShot (self, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(hmg, damage));
67
68         if(!autocvar_g_norecoil)
69         {
70                 self.punchangle_x = random () - 0.5;
71                 self.punchangle_y = random () - 0.5;
72         }
73
74         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));
75         fireBullet(w_shotorg, w_shotdir, hmg_spread, WEP_CVAR(hmg, solidpenetration), WEP_CVAR(hmg, damage), WEP_CVAR(hmg, force), WEP_HMG.m_id, 0);
76
77         self.misc_bulletcounter = self.misc_bulletcounter + 1;
78
79         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
80
81         W_MachineGun_MuzzleFlash();
82         W_AttachToShotorg(self.muzzle_flash, '5 0 0');
83
84         if (autocvar_g_casings >= 2) // casing code
85                 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);
86
87         ATTACK_FINISHED(self) = time + WEP_CVAR(hmg, refire) * W_WeaponRateFactor();
88         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(hmg, refire), W_HeavyMachineGun_Attack_Auto);
89 }
90
91                 METHOD(HeavyMachineGun, wr_aim, bool(entity thiswep))
92                 {
93                         if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
94                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false);
95                         else
96                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
97
98                         return true;
99                 }
100                 METHOD(HeavyMachineGun, wr_think, bool(entity thiswep, bool fire1, bool fire2))
101                 {
102                         if(WEP_CVAR(hmg, reload_ammo) && self.clip_load < WEP_CVAR(hmg, ammo)) // forced reload
103                                 _WEP_ACTION(self.weapon, WR_RELOAD);
104                         else
105                         {
106                                 if (fire1)
107                                 if (weapon_prepareattack(false, 0))
108                                 {
109                                         self.misc_bulletcounter = 0;
110                                         W_HeavyMachineGun_Attack_Auto(thiswep, fire1, fire2);
111                                 }
112                         }
113
114                         return true;
115                 }
116                 METHOD(HeavyMachineGun, wr_init, bool(entity thiswep))
117                 {
118                         HMG_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
119                         return true;
120                 }
121                 METHOD(HeavyMachineGun, wr_checkammo1, bool(entity thiswep))
122                 {
123                         float ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
124
125                         if(autocvar_g_balance_hmg_reload_ammo)
126                                 ammo_amount += self.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
127
128                         return ammo_amount;
129                 }
130                 METHOD(HeavyMachineGun, wr_checkammo2, bool(entity thiswep))
131                 {
132                         float ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
133
134                         if(autocvar_g_balance_hmg_reload_ammo)
135                                 ammo_amount += self.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
136
137                         return ammo_amount;
138                 }
139                 METHOD(HeavyMachineGun, wr_config, bool(entity thiswep))
140                 {
141                         HMG_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
142                         return true;
143                 }
144                 METHOD(HeavyMachineGun, wr_reload, bool(entity thiswep))
145                 {
146                         W_Reload(WEP_CVAR(hmg, ammo), SND(RELOAD));
147                         return true;
148                 }
149                 METHOD(HeavyMachineGun, wr_suicidemessage, bool(entity thiswep))
150                 {
151                         return WEAPON_THINKING_WITH_PORTALS;
152                 }
153                 METHOD(HeavyMachineGun, wr_killmessage, bool(entity thiswep))
154                 {
155                         if(w_deathtype & HITTYPE_SECONDARY)
156                                 return WEAPON_HMG_MURDER_SNIPE;
157                         else
158                                 return WEAPON_HMG_MURDER_SPRAY;
159                 }
160
161 #endif
162 #ifdef CSQC
163
164                 METHOD(HeavyMachineGun, wr_impacteffect, bool(entity thiswep))
165                 {
166                         vector org2;
167                         org2 = w_org + w_backoff * 2;
168                         pointparticles(particleeffectnum(EFFECT_MACHINEGUN_IMPACT), org2, w_backoff * 1000, 1);
169                         if(!w_issilent)
170                                 if(w_random < 0.05)
171                                         sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTEN_NORM);
172                                 else if(w_random < 0.1)
173                                         sound(self, CH_SHOTS, SND_RIC2, VOL_BASE, ATTEN_NORM);
174                                 else if(w_random < 0.2)
175                                         sound(self, CH_SHOTS, SND_RIC3, VOL_BASE, ATTEN_NORM);
176
177                         return true;
178                 }
179                 METHOD(HeavyMachineGun, wr_init, bool(entity thiswep))
180                 {
181                         return true;
182                 }
183                 METHOD(HeavyMachineGun, wr_zoomreticle, bool(entity thiswep))
184                 {
185                         // no weapon specific image for this weapon
186                         return false;
187                 }
188
189 #endif
190 #endif