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