]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
5e869228c99cd28fbef18a7d275ca3000ca09264
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hlac.qc
1 #include "hlac.qh"
2
3 #ifdef SVQC
4
5 METHOD(HLAC, m_spawnfunc_hookreplace, Weapon(HLAC this, entity e))
6 {
7     if (autocvar_g_weapon_noncore_allow && !Item_IsLoot(e) && (this.spawnflags & WEP_FLAG_MUTATORBLOCKED))
8     {
9         return WEP_CRYLINK;
10     }
11     return this;
12 }
13
14 void W_HLAC_Touch(entity this, entity toucher)
15 {
16         float isprimary;
17
18         PROJECTILE_TOUCH(this, toucher);
19
20         this.event_damage = func_null;
21
22         isprimary = !(this.projectiledeathtype & HITTYPE_SECONDARY);
23
24         RadiusDamage(this, this.realowner, WEP_CVAR_BOTH(hlac, isprimary, damage), WEP_CVAR_BOTH(hlac, isprimary, edgedamage), WEP_CVAR_BOTH(hlac, isprimary, radius),
25                                                 NULL, NULL, WEP_CVAR_BOTH(hlac, isprimary, force), this.projectiledeathtype, this.weaponentity_fld, toucher);
26
27         delete(this);
28 }
29
30 void W_HLAC_Attack(Weapon thiswep, entity actor, .entity weaponentity)
31 {
32         entity missile;
33     float spread;
34
35         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hlac, ammo), weaponentity);
36
37     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * actor.(weaponentity).misc_bulletcounter);
38     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
39     if(actor.crouch)
40         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
41
42         W_SetupShot(actor, weaponentity, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage), thiswep.m_id);
43         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
44         if(!autocvar_g_norecoil)
45         {
46                 actor.punchangle_x = random() - 0.5;
47                 actor.punchangle_y = random() - 0.5;
48         }
49
50         missile = new(hlacbolt);
51         missile.owner = missile.realowner = actor;
52         missile.bot_dodge = true;
53
54     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
55
56         set_movetype(missile, MOVETYPE_FLY);
57         PROJECTILE_MAKETRIGGER(missile);
58
59         setorigin(missile, w_shotorg);
60         setsize(missile, '0 0 0', '0 0 0');
61
62         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
63         //missile.angles = vectoangles(missile.velocity); // csqc
64
65         settouch(missile, W_HLAC_Touch);
66         setthink(missile, SUB_Remove);
67
68     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
69
70         missile.flags = FL_PROJECTILE;
71         IL_PUSH(g_projectiles, missile);
72         IL_PUSH(g_bot_dodge, missile);
73         missile.projectiledeathtype = thiswep.m_id;
74         missile.weaponentity_fld = weaponentity;
75
76         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
77
78         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
79 }
80
81 void W_HLAC_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
82 {
83         entity missile;
84     float spread;
85
86     spread = WEP_CVAR_SEC(hlac, spread);
87
88
89     if(actor.crouch)
90         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
91
92         W_SetupShot(actor, weaponentity, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage), thiswep.m_id | HITTYPE_SECONDARY);
93         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
94
95         missile = new(hlacbolt);
96         missile.owner = missile.realowner = actor;
97         missile.bot_dodge = true;
98
99     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
100
101         set_movetype(missile, MOVETYPE_FLY);
102         PROJECTILE_MAKETRIGGER(missile);
103
104         setorigin(missile, w_shotorg);
105         setsize(missile, '0 0 0', '0 0 0');
106
107         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
108         //missile.angles = vectoangles(missile.velocity); // csqc
109
110         settouch(missile, W_HLAC_Touch);
111         setthink(missile, SUB_Remove);
112
113     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
114
115         missile.flags = FL_PROJECTILE;
116         IL_PUSH(g_projectiles, missile);
117         IL_PUSH(g_bot_dodge, missile);
118         missile.missile_flags = MIF_SPLASH;
119         missile.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
120         missile.weaponentity_fld = weaponentity;
121
122         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
123
124         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
125 }
126
127 // weapon frames
128 void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
129 {
130         if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
131         {
132                 w_ready(thiswep, actor, weaponentity, fire);
133                 return;
134         }
135
136         if(PHYS_INPUT_BUTTON_ATCK(actor))
137         {
138                 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
139                 if(!(actor.items & IT_UNLIMITED_AMMO))
140                 {
141                         W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
142                         w_ready(thiswep, actor, weaponentity, fire);
143                         return;
144                 }
145
146                 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor(actor);
147                 W_HLAC_Attack(thiswep, actor, weaponentity);
148                 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
149         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
150         }
151         else
152         {
153                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
154         }
155 }
156
157 void W_HLAC_Attack2_Frame(Weapon thiswep, entity actor, .entity weaponentity)
158 {
159     float i;
160
161         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hlac, ammo), weaponentity);
162
163     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
164         W_HLAC_Attack2(thiswep, actor, weaponentity);
165
166         if(!autocvar_g_norecoil)
167         {
168                 actor.punchangle_x = random() - 0.5;
169                 actor.punchangle_y = random() - 0.5;
170         }
171 }
172
173 METHOD(HLAC, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
174 {
175     PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
176 }
177 METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
178 {
179     if(autocvar_g_balance_hlac_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) { // forced reload
180         thiswep.wr_reload(thiswep, actor, weaponentity);
181     } else if(fire & 1)
182     {
183         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hlac, refire)))
184         {
185             actor.(weaponentity).misc_bulletcounter = 0;
186             W_HLAC_Attack(thiswep, actor, weaponentity);
187             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
188         }
189     }
190
191     else if((fire & 2) && WEP_CVAR(hlac, secondary))
192     {
193         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hlac, refire)))
194         {
195             W_HLAC_Attack2_Frame(thiswep, actor, weaponentity);
196             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
197         }
198     }
199 }
200 METHOD(HLAC, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
201 {
202     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(hlac, ammo);
203     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
204     return ammo_amount;
205 }
206 METHOD(HLAC, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
207 {
208     float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(hlac, ammo);
209     ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
210     return ammo_amount;
211 }
212 METHOD(HLAC, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
213 {
214     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), SND_RELOAD);
215 }
216 METHOD(HLAC, wr_suicidemessage, Notification(entity thiswep))
217 {
218     return WEAPON_HLAC_SUICIDE;
219 }
220 METHOD(HLAC, wr_killmessage, Notification(entity thiswep))
221 {
222     return WEAPON_HLAC_MURDER;
223 }
224
225 #endif
226 #ifdef CSQC
227
228 METHOD(HLAC, wr_impacteffect, void(entity thiswep, entity actor))
229 {
230     vector org2;
231     org2 = w_org + w_backoff * 6;
232     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
233     if(!w_issilent)
234         sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
235 }
236
237 #endif