Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
hlac.qc
Go to the documentation of this file.
1#include "hlac.qh"
2
3#ifdef SVQC
4
6{
7 float isprimary;
8
10
11 this.event_damage = func_null;
12
13 isprimary = !(this.projectiledeathtype & HITTYPE_SECONDARY);
14
15 RadiusDamage(this, this.realowner,
16 WEP_CVAR_BOTH(WEP_HLAC, isprimary, damage),
17 WEP_CVAR_BOTH(WEP_HLAC, isprimary, edgedamage),
18 WEP_CVAR_BOTH(WEP_HLAC, isprimary, radius),
19 NULL, NULL,
20 WEP_CVAR_BOTH(WEP_HLAC, isprimary, force),
22
23 delete(this);
24}
25
26void W_HLAC_Attack(Weapon thiswep, entity actor, .entity weaponentity)
27{
28 entity missile;
29
30 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(WEP_HLAC, ammo), weaponentity);
31
32 float spread = WEP_CVAR_PRI(WEP_HLAC, spread_min) + (WEP_CVAR_PRI(WEP_HLAC, spread_add) * actor.(weaponentity).misc_bulletcounter);
33 spread = min(spread,WEP_CVAR_PRI(WEP_HLAC, spread_max));
34 if(IS_DUCKED(actor) && IS_ONGROUND(actor))
35 spread *= WEP_CVAR_PRI(WEP_HLAC, spread_crouchmod);
36
37 W_SetupShot(actor, weaponentity, false, 3, SND_HLAC_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(WEP_HLAC, damage), thiswep.m_id);
38 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
40 {
41 actor.punchangle_x = random() - 0.5;
42 actor.punchangle_y = random() - 0.5;
43 }
44
45 missile = new(hlacbolt);
46 missile.owner = missile.realowner = actor;
47 missile.bot_dodge = true;
48
49 missile.bot_dodgerating = WEP_CVAR_PRI(WEP_HLAC, damage);
50
51 set_movetype(missile, MOVETYPE_FLY);
53
54 setorigin(missile, w_shotorg);
55 setsize(missile, '0 0 0', '0 0 0');
56
57 W_SetupProjVelocity_Basic(missile, WEP_CVAR_PRI(WEP_HLAC, speed), spread);
58 //missile.angles = vectoangles(missile.velocity); // csqc
59
60 settouch(missile, W_HLAC_Touch);
61 setthink(missile, SUB_Remove);
62
63 missile.nextthink = time + WEP_CVAR_PRI(WEP_HLAC, lifetime);
64
65 missile.flags = FL_PROJECTILE;
66 IL_PUSH(g_projectiles, missile);
67 IL_PUSH(g_bot_dodge, missile);
68 missile.projectiledeathtype = thiswep.m_id;
69 missile.weaponentity_fld = weaponentity;
70
71 CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
72
73 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
74}
75
76void W_HLAC_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
77{
78 entity missile;
79 float spread = WEP_CVAR_SEC(WEP_HLAC, spread);
80
81 if(IS_DUCKED(actor) && IS_ONGROUND(actor))
82 spread *= WEP_CVAR_SEC(WEP_HLAC, spread_crouchmod);
83
84 W_SetupShot(actor, weaponentity, false, 3, SND_HLAC_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(WEP_HLAC, damage) * WEP_CVAR_SEC(WEP_HLAC, shots), thiswep.m_id | HITTYPE_SECONDARY);
85 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
86 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(WEP_HLAC, ammo), weaponentity);
87
88 for(int j = WEP_CVAR_SEC(WEP_HLAC, shots); j > 0; --j)
89 {
90 missile = new(hlacbolt);
91 missile.owner = missile.realowner = actor;
92 missile.bot_dodge = true;
93
94 missile.bot_dodgerating = WEP_CVAR_SEC(WEP_HLAC, damage);
95
96 set_movetype(missile, MOVETYPE_FLY);
98
99 setorigin(missile, w_shotorg);
100 setsize(missile, '0 0 0', '0 0 0');
101
102 W_SetupProjVelocity_Basic(missile, WEP_CVAR_SEC(WEP_HLAC, speed), spread);
103 //missile.angles = vectoangles(missile.velocity); // csqc
104
105 settouch(missile, W_HLAC_Touch);
106 setthink(missile, SUB_Remove);
107
108 missile.nextthink = time + WEP_CVAR_SEC(WEP_HLAC, lifetime);
109
110 missile.flags = FL_PROJECTILE;
111 IL_PUSH(g_projectiles, missile);
112 IL_PUSH(g_bot_dodge, missile);
113 missile.missile_flags = MIF_SPLASH;
114 missile.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
115 missile.weaponentity_fld = weaponentity;
116
117 CSQCProjectile(missile, true, PROJECTILE_HLAC, true);
118
119 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
120 }
121
123 {
124 actor.punchangle_x = random() - 0.5;
125 actor.punchangle_y = random() - 0.5;
126 }
127}
128
129// weapon frames
130void W_HLAC_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
131{
132 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
133 {
134 w_ready(thiswep, actor, weaponentity, fire);
135 return;
136 }
137
138 if(PHYS_INPUT_BUTTON_ATCK(actor))
139 {
140 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
141 if(!(actor.items & IT_UNLIMITED_AMMO))
142 {
143 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
144 w_ready(thiswep, actor, weaponentity, fire);
145 return;
146 }
147
148 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(WEP_HLAC, refire) * W_WeaponRateFactor(actor);
149 W_HLAC_Attack(thiswep, actor, weaponentity);
150 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
151 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_HLAC, refire), W_HLAC_Attack_Frame);
152 }
153 else
154 {
155 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_HLAC, animtime), w_ready);
156 }
157}
158
159METHOD(HLAC, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
160{
161 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(WEP_HLAC, speed), 0, WEP_CVAR_PRI(WEP_HLAC, lifetime), false, true);
162}
163
164METHOD(HLAC, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
165{
166 if(autocvar_g_balance_hlac_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(WEP_HLAC, ammo), WEP_CVAR_SEC(WEP_HLAC, ammo))) { // forced reload
167 thiswep.wr_reload(thiswep, actor, weaponentity);
168 } else if(fire & 1)
169 {
170 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(WEP_HLAC, refire)))
171 {
172 actor.(weaponentity).misc_bulletcounter = 0;
173 W_HLAC_Attack(thiswep, actor, weaponentity);
174 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_HLAC, refire), W_HLAC_Attack_Frame);
175 }
176 }
177
178 else if((fire & 2) && WEP_CVAR(WEP_HLAC, secondary))
179 {
180 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(WEP_HLAC, refire)))
181 {
182 W_HLAC_Attack2(thiswep, actor, weaponentity);
183 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(WEP_HLAC, animtime), w_ready);
184 }
185 }
186}
187
188METHOD(HLAC, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
189{
190 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_HLAC, ammo);
191 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(WEP_HLAC, ammo);
192 return ammo_amount;
193}
194
195METHOD(HLAC, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
196{
197 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(WEP_HLAC, ammo);
198 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(WEP_HLAC, ammo);
199 return ammo_amount;
200}
201
202METHOD(HLAC, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
203{
204 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(WEP_HLAC, ammo), WEP_CVAR_SEC(WEP_HLAC, ammo)), SND_RELOAD);
205}
206
207METHOD(HLAC, wr_suicidemessage, Notification(entity thiswep))
208{
209 return WEAPON_HLAC_SUICIDE;
210}
211
212METHOD(HLAC, wr_killmessage, Notification(entity thiswep))
213{
214 return WEAPON_HLAC_MURDER;
215}
216
217#endif
218#ifdef CSQC
219
220METHOD(HLAC, wr_impacteffect, void(entity thiswep, entity actor))
221{
222 // TODO: remove this caching & fallback after next release (xonotic-v0.9.0)
223 // do the same for the muzzleflash effect in hlac.qh. see also common/effects/all.inc
224 entity eff = EFFECT_GREEN_HLAC_IMPACT;
225 if (!thiswep.cnt) // cache effect num here
226 thiswep.cnt = particleeffectnum(eff); // can't return 0
227 if (thiswep.cnt < 0)
228 eff = EFFECT_BLASTER_IMPACT; // compatible with Xonotic v0.8.6 or lower
229
230 vector org2 = w_org + w_backoff * 2;
231 pointparticles(eff, org2, w_backoff * 1000, 1);
232 if(!w_issilent)
233 sound(actor, CH_SHOTS, SND_LASERIMPACT, VOL_BASE, ATTN_NORM);
234}
235
236#endif
237#ifdef MENUQC
239#include "blaster.qh"
240
241METHOD(HLAC, describe, string(HLAC this))
242{
243 TC(HLAC, this);
245 PAR(_("The %s (or HLAC for short) fires lasers in quick succession. "
246 "The projectiles it fires are similar to those of the %s."), COLORED_NAME(this), COLORED_NAME(WEP_BLASTER));
247 PAR(_("The secondary fire shoots a burst of multiple randomly-scattered lasers at once."));
248 PAR(_("Unlike the %s, it consumes %s ammo for each laser shot, meaning that it cannot be used infinitely."), COLORED_NAME(WEP_BLASTER), COLORED_NAME(ITEM_Cells));
249 PAR(_("The %s works best in close ranges, but the primary fire is also useful in medium ranges."), COLORED_NAME(this));
250 PAR(_("A unique aspect of the %s is that the longer the primary fire is held, the more that the lasers will start to spread out. "
251 "This means releasing primary fire every now and then is important to restore accuracy. "
252 "Also, the %s has less spread when used while crouching."), COLORED_NAME(this), COLORED_NAME(this));
253 PAR(W_Guide_Keybinds(this));
254 PAR(W_Guide_DPS_secondaryMultishot(this.netname, "primary", "secondary", "secondary_shots", "", false));
255 return PAGE_TEXT;
256}
257
258#endif
bool bot_aim(entity this,.entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, float applygravity, bool shot_accurate)
IntrusiveList g_bot_dodge
Definition api.qh:150
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition hlac.qh:11
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:44
int m_id
Definition weapon.qh:45
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:92
string netname
Definition powerups.qc:20
float lifetime
Definition powerups.qc:23
#define COLORED_NAME(this)
Definition color.qh:195
const int IT_UNLIMITED_AMMO
Definition item.qh:23
float radius
Definition impulse.qh:11
#define IS_DUCKED(s)
Definition player.qh:210
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition player.qh:150
float W_WeaponRateFactor(entity this)
const int FL_PROJECTILE
Definition constants.qh:85
float time
const float ATTN_NORM
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype,.entity weaponentity, entity directhitentity)
Definition damage.qc:981
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:246
vector w_org
vector w_backoff
float w_issilent
const int HITTYPE_SECONDARY
Definition all.qh:29
void SUB_Remove(entity this)
Remove entity.
Definition defer.qh:13
float speed
Definition dynlight.qc:9
#define pointparticles(effect, org, vel, howmany)
Definition effect.qh:7
#define particleeffectnum(e)
Definition effect.qh:3
void W_HLAC_Attack(Weapon thiswep, entity actor,.entity weaponentity)
Definition hlac.qc:26
void W_HLAC_Attack_Frame(Weapon thiswep, entity actor,.entity weaponentity, int fire)
Definition hlac.qc:130
void W_HLAC_Attack2(Weapon thiswep, entity actor,.entity weaponentity)
Definition hlac.qc:76
void W_HLAC_Touch(entity this, entity toucher)
Definition hlac.qc:5
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define TC(T, sym)
Definition _all.inc:82
float random(void)
float min(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_FLY
Definition movetypes.qh:134
#define IS_ONGROUND(s)
Definition movetypes.qh:16
var void func_null()
entity Notification
always last
Definition all.qh:81
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
const int PROJECTILE_HLAC
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
#define setthink(e, f)
vector
Definition self.qh:92
entity entity toucher
Definition self.qh:72
#define settouch(e, f)
Definition self.qh:73
const int MIF_SPLASH
Definition common.qh:46
int projectiledeathtype
Definition common.qh:21
#define PROJECTILE_TOUCH(e, t)
Definition common.qh:28
IntrusiveList g_projectiles
Definition common.qh:58
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:34
float misc_bulletcounter
Definition common.qh:19
const float VOL_BASE
Definition sound.qh:36
const int CH_SHOTS
Definition sound.qh:14
const int CH_WEAPON_A
Definition sound.qh:7
#define sound(e, c, s, v, a)
Definition sound.qh:52
#define PAGE_TEXT
Definition string.qh:643
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:649
#define PAGE_TEXT_INIT()
Definition string.qh:642
float ammo
Definition sv_turrets.qh:43
entity realowner
bool autocvar_g_norecoil
Definition tracing.qh:16
vector w_shotdir
Definition tracing.qh:20
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:34
#define W_SetupProjVelocity_Basic(ent, pspeed, pspread)
Definition tracing.qh:49
string W_Guide_Keybinds(Weapon wep)
Definition all.qc:836
string W_Guide_DPS_secondaryMultishot(string name, string pri, string sec, string shots, string refire2, bool sec_variable)
Definition all.qc:967
void W_MuzzleFlash(Weapon thiswep, entity actor,.entity weaponentity, vector shotorg, vector shotdir)
Definition all.qc:728
#define WEP_CVAR_PRI(wep, name)
Definition all.qh:322
#define WEP_CVAR_BOTH(wep, isprimary, name)
Definition all.qh:324
#define WEP_CVAR(wep, name)
Definition all.qh:321
#define WEP_CVAR_SEC(wep, name)
Definition all.qh:323
void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use,.entity weaponentity)
void W_Reload(entity actor,.entity weaponentity, float sent_ammo_min, Sound sent_sound)
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
#define ATTACK_FINISHED(ent, w)
entity weaponentity_fld
float weapon_load[REGISTRY_MAX(Weapons)]