]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/hmg.qc
Merge branch 'terencehill/quickmenu_file_example' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / 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, m_name, 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 REGISTER_MUTATOR(hmg_nadesupport, true);
47 MUTATOR_HOOKFUNCTION(hmg_nadesupport, Nade_Damage)
48 {
49         if (MUTATOR_ARGV(0, entity) != WEP_HMG) return;
50         return = true;
51         MUTATOR_ARGV(0, float) /* damage */ = self.max_health * 0.1;
52 }
53
54 spawnfunc(weapon_hmg) { weapon_defaultspawnfunc(this, WEP_HMG); }
55
56 void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
57 {
58         if (!actor.BUTTON_ATCK)
59         {
60                 w_ready(thiswep, actor, weaponentity, fire);
61                 return;
62         }
63
64         Weapon w = get_weaponinfo(actor.weapon);
65         if(!w.wr_checkammo1(w))
66         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
67         {
68                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
69                 w_ready(thiswep, actor, weaponentity, fire);
70                 return;
71         }
72
73         W_DecreaseAmmo(WEP_HMG, self, WEP_CVAR(hmg, ammo));
74
75         W_SetupShot (actor, true, 0, SND(UZI_FIRE), CH_WEAPON_A, WEP_CVAR(hmg, damage));
76
77         if(!autocvar_g_norecoil)
78         {
79                 actor.punchangle_x = random () - 0.5;
80                 actor.punchangle_y = random () - 0.5;
81         }
82
83         float hmg_spread = bound(WEP_CVAR(hmg, spread_min), WEP_CVAR(hmg, spread_min) + (WEP_CVAR(hmg, spread_add) * actor.misc_bulletcounter), WEP_CVAR(hmg, spread_max));
84         fireBullet(w_shotorg, w_shotdir, hmg_spread, WEP_CVAR(hmg, solidpenetration), WEP_CVAR(hmg, damage), WEP_CVAR(hmg, force), WEP_HMG.m_id, 0);
85
86         actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
87
88         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
89
90         W_MachineGun_MuzzleFlash();
91         W_AttachToShotorg(actor, actor.muzzle_flash, '5 0 0');
92
93         if (autocvar_g_casings >= 2) // casing code
94                 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, actor);
95
96         int slot = weaponslot(weaponentity);
97         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(hmg, refire) * W_WeaponRateFactor();
98         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(hmg, refire), W_HeavyMachineGun_Attack_Auto);
99 }
100
101                 METHOD(HeavyMachineGun, wr_aim, void(entity thiswep))
102                 {
103                         if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
104                                 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false);
105                         else
106                                 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false);
107                 }
108                 METHOD(HeavyMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
109                 {
110                         if(WEP_CVAR(hmg, reload_ammo) && actor.clip_load < WEP_CVAR(hmg, ammo)) { // forced reload
111                                 Weapon w = get_weaponinfo(actor.weapon);
112                                 w.wr_reload(w);
113                         } else
114                         {
115                                 if (fire & 1)
116                                 if (weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
117                                 {
118                                         actor.misc_bulletcounter = 0;
119                                         W_HeavyMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
120                                 }
121                         }
122                 }
123                 METHOD(HeavyMachineGun, wr_init, void(entity thiswep))
124                 {
125                         HMG_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
126                 }
127                 METHOD(HeavyMachineGun, wr_checkammo1, bool(entity thiswep))
128                 {
129                         float ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
130
131                         if(autocvar_g_balance_hmg_reload_ammo)
132                                 ammo_amount += self.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
133
134                         return ammo_amount;
135                 }
136                 METHOD(HeavyMachineGun, wr_checkammo2, bool(entity thiswep))
137                 {
138                         float ammo_amount = self.ammo_nails >= WEP_CVAR(hmg, ammo);
139
140                         if(autocvar_g_balance_hmg_reload_ammo)
141                                 ammo_amount += self.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
142
143                         return ammo_amount;
144                 }
145                 METHOD(HeavyMachineGun, wr_config, void(entity thiswep))
146                 {
147                         HMG_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
148                 }
149                 METHOD(HeavyMachineGun, wr_reload, void(entity thiswep))
150                 {
151                         W_Reload(self, WEP_CVAR(hmg, ammo), SND(RELOAD));
152                 }
153                 METHOD(HeavyMachineGun, wr_suicidemessage, int(entity thiswep))
154                 {
155                         return WEAPON_THINKING_WITH_PORTALS;
156                 }
157                 METHOD(HeavyMachineGun, wr_killmessage, int(entity thiswep))
158                 {
159                         if(w_deathtype & HITTYPE_SECONDARY)
160                                 return WEAPON_HMG_MURDER_SNIPE;
161                         else
162                                 return WEAPON_HMG_MURDER_SPRAY;
163                 }
164
165 #endif
166 #ifdef CSQC
167
168                 METHOD(HeavyMachineGun, wr_impacteffect, void(entity thiswep))
169                 {
170                         vector org2;
171                         org2 = w_org + w_backoff * 2;
172                         pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
173                         if(!w_issilent)
174                                 sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
175                 }
176
177 #endif
178 #endif