]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/hmg.qc
Merge branch 'Mario/teams_bitflag' 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
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, ammo, float, NONE) \
21                 P(class, prefix, damage, float, NONE) \
22                 P(class, prefix, force, float, NONE) \
23                 P(class, prefix, refire, float, NONE) \
24                 P(class, prefix, reload_ammo, float, NONE) \
25                 P(class, prefix, reload_time, float, NONE) \
26                 P(class, prefix, solidpenetration, float, NONE) \
27                 P(class, prefix, spread_add, float, NONE) \
28                 P(class, prefix, spread_max, float, NONE) \
29                 P(class, prefix, spread_min, float, NONE) \
30                 P(class, prefix, switchdelay_drop, float, NONE) \
31                 P(class, prefix, switchdelay_raise, float, NONE) \
32                 P(class, prefix, weaponreplace, string, NONE) \
33                 P(class, prefix, weaponstartoverride, float, NONE) \
34                 P(class, prefix, weaponstart, float, NONE) \
35                 P(class, prefix, weaponthrowable, float, NONE) \
36     END()
37     W_PROPS(X, HeavyMachineGun, hmg)
38 #undef X
39
40 ENDCLASS(HeavyMachineGun)
41 REGISTER_WEAPON(HMG, hmg, NEW(HeavyMachineGun));
42
43 #endif
44 #ifdef IMPLEMENTATION
45 #ifdef SVQC
46
47 REGISTER_MUTATOR(hmg_nadesupport, true);
48 MUTATOR_HOOKFUNCTION(hmg_nadesupport, Nade_Damage)
49 {
50         if (M_ARGV(1, entity) != WEP_HMG) return;
51         return = true;
52         M_ARGV(3, float) /* damage */ = (M_ARGV(0, entity)).max_health * 0.1;
53 }
54
55 spawnfunc(weapon_hmg) { weapon_defaultspawnfunc(this, WEP_HMG); }
56
57 void W_HeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
58 {
59         if (!PHYS_INPUT_BUTTON_ATCK(actor))
60         {
61                 w_ready(thiswep, actor, weaponentity, fire);
62                 return;
63         }
64
65         if((!thiswep.wr_checkammo1(thiswep, actor) && !(actor.items & IT_UNLIMITED_WEAPON_AMMO)) || (!(actor.items & IT_SUPERWEAPON) && !(actor.items & IT_UNLIMITED_SUPERWEAPONS)))
66         {
67                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
68                 w_ready(thiswep, actor, weaponentity, fire);
69                 return;
70         }
71
72         W_DecreaseAmmo(WEP_HMG, actor, WEP_CVAR(hmg, ammo));
73
74         W_SetupShot (actor, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(hmg, damage));
75
76         if(!autocvar_g_norecoil)
77         {
78                 actor.punchangle_x = random () - 0.5;
79                 actor.punchangle_y = random () - 0.5;
80         }
81
82         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));
83         fireBullet(actor, w_shotorg, w_shotdir, hmg_spread, WEP_CVAR(hmg, solidpenetration), WEP_CVAR(hmg, damage), WEP_CVAR(hmg, force), WEP_HMG.m_id, 0);
84
85         actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
86
87         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
88
89         W_MachineGun_MuzzleFlash(actor);
90         W_AttachToShotorg(actor, actor.muzzle_flash, '5 0 0');
91
92         if (autocvar_g_casings >= 2) // casing code
93         {
94                 makevectors(actor.v_angle); // for some reason, this is lost
95                 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);
96         }
97
98         int slot = weaponslot(weaponentity);
99         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(hmg, refire) * W_WeaponRateFactor(actor);
100         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(hmg, refire), W_HeavyMachineGun_Attack_Auto);
101 }
102
103 METHOD(HeavyMachineGun, wr_aim, void(entity thiswep, entity actor))
104 {
105     if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
106         PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, 1000000, 0, 0.001, false);
107     else
108         PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, 1000000, 0, 0.001, false);
109 }
110
111 METHOD(HeavyMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
112 {
113     if(WEP_CVAR(hmg, reload_ammo) && actor.clip_load < WEP_CVAR(hmg, ammo)) { // forced reload
114         thiswep.wr_reload(thiswep, actor, weaponentity);
115     } else
116     {
117         if (fire & 1)
118         if (weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
119         {
120             actor.misc_bulletcounter = 0;
121             W_HeavyMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
122         }
123     }
124 }
125
126 METHOD(HeavyMachineGun, wr_checkammo1, bool(entity thiswep, entity actor))
127 {
128     float ammo_amount = actor.ammo_nails >= WEP_CVAR(hmg, ammo);
129
130     if(autocvar_g_balance_hmg_reload_ammo)
131         ammo_amount += actor.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
132
133     return ammo_amount;
134 }
135
136 METHOD(HeavyMachineGun, wr_checkammo2, bool(entity thiswep, entity actor))
137 {
138     float ammo_amount = actor.ammo_nails >= WEP_CVAR(hmg, ammo);
139
140     if(autocvar_g_balance_hmg_reload_ammo)
141         ammo_amount += actor.(weapon_load[WEP_HMG.m_id]) >= WEP_CVAR(hmg, ammo);
142
143     return ammo_amount;
144 }
145
146 METHOD(HeavyMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
147 {
148     W_Reload(actor, WEP_CVAR(hmg, ammo), SND_RELOAD);
149 }
150
151 METHOD(HeavyMachineGun, wr_suicidemessage, Notification(entity thiswep))
152 {
153     return WEAPON_THINKING_WITH_PORTALS;
154 }
155
156 METHOD(HeavyMachineGun, wr_killmessage, Notification(entity thiswep))
157 {
158     if(w_deathtype & HITTYPE_SECONDARY)
159         return WEAPON_HMG_MURDER_SNIPE;
160     else
161         return WEAPON_HMG_MURDER_SPRAY;
162 }
163
164 #endif
165 #ifdef CSQC
166
167 METHOD(HeavyMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
168 {
169     vector org2;
170     org2 = w_org + w_backoff * 2;
171     pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
172     if(!w_issilent)
173         sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
174 }
175
176 #endif
177 #endif