]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/hlac.qc
Merge branch 'master' into terencehill/hud_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / hlac.qc
1 #include "hlac.qh"
2 #ifndef IMPLEMENTATION
3 CLASS(HLAC, Weapon)
4 /* ammotype  */ ATTRIB(HLAC, ammo_field, .int, ammo_cells);
5 /* impulse   */ ATTRIB(HLAC, impulse, int, 6);
6 /* flags     */ ATTRIB(HLAC, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
7 /* rating    */ ATTRIB(HLAC, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
8 /* color     */ ATTRIB(HLAC, wpcolor, vector, '0 1 0');
9 /* modelname */ ATTRIB(HLAC, mdl, string, "hlac");
10 #ifdef GAMEQC
11 /* model     */ ATTRIB(HLAC, m_model, Model, MDL_HLAC_ITEM);
12 #endif
13 /* crosshair */ ATTRIB(HLAC, w_crosshair, string, "gfx/crosshairhlac");
14 /* crosshair */ ATTRIB(HLAC, w_crosshair_size, float, 0.6);
15 /* wepimg    */ ATTRIB(HLAC, model2, string, "weaponhlac");
16 /* refname   */ ATTRIB(HLAC, netname, string, "hlac");
17 /* wepname   */ ATTRIB(HLAC, m_name, string, _("Heavy Laser Assault Cannon"));
18
19 #define X(BEGIN, P, END, class, prefix) \
20         BEGIN(class) \
21                 P(class, prefix, ammo, float, BOTH) \
22                 P(class, prefix, animtime, float, BOTH) \
23                 P(class, prefix, damage, float, BOTH) \
24                 P(class, prefix, edgedamage, float, BOTH) \
25                 P(class, prefix, force, float, BOTH) \
26                 P(class, prefix, lifetime, float, BOTH) \
27                 P(class, prefix, radius, float, BOTH) \
28                 P(class, prefix, refire, float, BOTH) \
29                 P(class, prefix, reload_ammo, float, NONE) \
30                 P(class, prefix, reload_time, float, NONE) \
31                 P(class, prefix, secondary, float, NONE) \
32                 P(class, prefix, shots, float, SEC) \
33                 P(class, prefix, speed, float, BOTH) \
34                 P(class, prefix, spread, float, SEC) \
35                 P(class, prefix, spread_add, float, PRI) \
36                 P(class, prefix, spread_crouchmod, float, BOTH) \
37                 P(class, prefix, spread_max, float, PRI) \
38                 P(class, prefix, spread_min, float, PRI) \
39                 P(class, prefix, switchdelay_drop, float, NONE) \
40                 P(class, prefix, switchdelay_raise, float, NONE) \
41                 P(class, prefix, weaponreplace, string,NONE) \
42                 P(class, prefix, weaponstartoverride, float, NONE) \
43                 P(class, prefix, weaponstart, float, NONE) \
44                 P(class, prefix, weaponthrowable, float, NONE) \
45         END()
46     W_PROPS(X, HLAC, hlac)
47 #undef X
48
49 ENDCLASS(HLAC)
50 REGISTER_WEAPON(HLAC, hlac, NEW(HLAC));
51
52
53 #endif
54 #ifdef IMPLEMENTATION
55 #ifdef SVQC
56 spawnfunc(weapon_hlac) { weapon_defaultspawnfunc(this, WEP_HLAC); }
57
58 void W_HLAC_Touch(entity this, entity toucher)
59 {
60         float isprimary;
61
62         PROJECTILE_TOUCH(this, toucher);
63
64         this.event_damage = func_null;
65
66         isprimary = !(this.projectiledeathtype & HITTYPE_SECONDARY);
67
68         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);
69
70         delete(this);
71 }
72
73 void W_HLAC_Attack(Weapon thiswep, entity actor, .entity weaponentity)
74 {
75         entity missile;
76     float spread;
77
78         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hlac, ammo));
79
80     spread = WEP_CVAR_PRI(hlac, spread_min) + (WEP_CVAR_PRI(hlac, spread_add) * actor.misc_bulletcounter);
81     spread = min(spread,WEP_CVAR_PRI(hlac, spread_max));
82     if(actor.crouch)
83         spread = spread * WEP_CVAR_PRI(hlac, spread_crouchmod);
84
85         W_SetupShot(actor, weaponentity, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(hlac, damage));
86         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
87         if(!autocvar_g_norecoil)
88         {
89                 actor.punchangle_x = random() - 0.5;
90                 actor.punchangle_y = random() - 0.5;
91         }
92
93         missile = new(hlacbolt);
94         missile.owner = missile.realowner = actor;
95         missile.bot_dodge = true;
96
97     missile.bot_dodgerating = WEP_CVAR_PRI(hlac, damage);
98
99         set_movetype(missile, MOVETYPE_FLY);
100         PROJECTILE_MAKETRIGGER(missile);
101
102         setorigin(missile, w_shotorg);
103         setsize(missile, '0 0 0', '0 0 0');
104
105         W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(hlac, speed), spread);
106         //missile.angles = vectoangles(missile.velocity); // csqc
107
108         settouch(missile, W_HLAC_Touch);
109         setthink(missile, SUB_Remove);
110
111     missile.nextthink = time + WEP_CVAR_PRI(hlac, lifetime);
112
113         missile.flags = FL_PROJECTILE;
114         IL_PUSH(g_projectiles, missile);
115         missile.projectiledeathtype = WEP_HLAC.m_id;
116
117         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
118
119         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
120 }
121
122 void W_HLAC_Attack2(entity actor, .entity weaponentity)
123 {
124         entity missile;
125     float spread;
126
127     spread = WEP_CVAR_SEC(hlac, spread);
128
129
130     if(actor.crouch)
131         spread = spread * WEP_CVAR_SEC(hlac, spread_crouchmod);
132
133         W_SetupShot(actor, weaponentity, false, 3, SND_LASERGUN_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hlac, damage));
134         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
135
136         missile = new(hlacbolt);
137         missile.owner = missile.realowner = actor;
138         missile.bot_dodge = true;
139
140     missile.bot_dodgerating = WEP_CVAR_SEC(hlac, damage);
141
142         set_movetype(missile, MOVETYPE_FLY);
143         PROJECTILE_MAKETRIGGER(missile);
144
145         setorigin(missile, w_shotorg);
146         setsize(missile, '0 0 0', '0 0 0');
147
148         W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(hlac, speed), spread);
149         //missile.angles = vectoangles(missile.velocity); // csqc
150
151         settouch(missile, W_HLAC_Touch);
152         setthink(missile, SUB_Remove);
153
154     missile.nextthink = time + WEP_CVAR_SEC(hlac, lifetime);
155
156         missile.flags = FL_PROJECTILE;
157         IL_PUSH(g_projectiles, missile);
158         missile.missile_flags = MIF_SPLASH;
159         missile.projectiledeathtype = WEP_HLAC.m_id | HITTYPE_SECONDARY;
160
161         CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
162
163         MUTATOR_CALLHOOK(EditProjectile, actor, missile);
164 }
165
166 // weapon frames
167 void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
168 {
169         if(PS(actor).m_weapon != PS(actor).m_switchweapon) // abort immediately if switching
170         {
171                 w_ready(thiswep, actor, weaponentity, fire);
172                 return;
173         }
174
175         if(PHYS_INPUT_BUTTON_ATCK(actor))
176         {
177                 if(!thiswep.wr_checkammo1(thiswep, actor))
178                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
179                 {
180                         W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
181                         w_ready(thiswep, actor, weaponentity, fire);
182                         return;
183                 }
184
185                 int slot = weaponslot(weaponentity);
186                 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hlac, refire) * W_WeaponRateFactor(actor);
187                 W_HLAC_Attack(WEP_HLAC, actor, weaponentity);
188                 actor.misc_bulletcounter = actor.misc_bulletcounter + 1;
189         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
190         }
191         else
192         {
193                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, animtime), w_ready);
194         }
195 }
196
197 void W_HLAC_Attack2_Frame(Weapon thiswep, entity actor, .entity weaponentity)
198 {
199     float i;
200
201         W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hlac, ammo));
202
203     for(i=WEP_CVAR_SEC(hlac, shots);i>0;--i)
204         W_HLAC_Attack2(actor, weaponentity);
205
206         if(!autocvar_g_norecoil)
207         {
208                 actor.punchangle_x = random() - 0.5;
209                 actor.punchangle_y = random() - 0.5;
210         }
211 }
212
213 METHOD(HLAC, wr_aim, void(entity thiswep, entity actor))
214 {
215     PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR_PRI(hlac, speed), 0, WEP_CVAR_PRI(hlac, lifetime), false);
216 }
217 METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
218 {
219     if(autocvar_g_balance_hlac_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo))) { // forced reload
220         thiswep.wr_reload(thiswep, actor, weaponentity);
221     } else if(fire & 1)
222     {
223         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hlac, refire)))
224         {
225             actor.misc_bulletcounter = 0;
226             W_HLAC_Attack(thiswep, actor, weaponentity);
227             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hlac, refire), W_HLAC_Attack_Frame);
228         }
229     }
230
231     else if((fire & 2) && WEP_CVAR(hlac, secondary))
232     {
233         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hlac, refire)))
234         {
235             W_HLAC_Attack2_Frame(thiswep, actor, weaponentity);
236             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hlac, animtime), w_ready);
237         }
238     }
239 }
240 METHOD(HLAC, wr_checkammo1, bool(entity thiswep, entity actor))
241 {
242     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(hlac, ammo);
243     ammo_amount += actor.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_PRI(hlac, ammo);
244     return ammo_amount;
245 }
246 METHOD(HLAC, wr_checkammo2, bool(entity thiswep, entity actor))
247 {
248     float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(hlac, ammo);
249     ammo_amount += actor.(weapon_load[WEP_HLAC.m_id]) >= WEP_CVAR_SEC(hlac, ammo);
250     return ammo_amount;
251 }
252 METHOD(HLAC, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
253 {
254     W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(hlac, ammo), WEP_CVAR_SEC(hlac, ammo)), SND_RELOAD);
255 }
256 METHOD(HLAC, wr_suicidemessage, Notification(entity thiswep))
257 {
258     return WEAPON_HLAC_SUICIDE;
259 }
260 METHOD(HLAC, wr_killmessage, Notification(entity thiswep))
261 {
262     return WEAPON_HLAC_MURDER;
263 }
264
265 #endif
266 #ifdef CSQC
267
268 METHOD(HLAC, wr_impacteffect, void(entity thiswep, entity actor))
269 {
270     vector org2;
271     org2 = w_org + w_backoff * 6;
272     pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
273     if(!w_issilent)
274         sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
275 }
276
277 #endif
278 #endif