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