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