Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_weapon.qc
Go to the documentation of this file.
1#include "sv_weapon.qh"
2
3void W_Nexball_Attack(Weapon thiswep, entity actor, .entity weaponentity, float t);
4void W_Nexball_Attack2(Weapon thiswep, entity actor, .entity weaponentity);
5vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity);
6
7METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
8{
9 TC(BallStealer, thiswep);
10 if (fire & 1)
11 if (weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
12 {
14 {
15 if (actor.ballcarried && !STAT(NB_METERSTART, actor))
16 STAT(NB_METERSTART, actor) = time;
17 else
18 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
19 }
20 else
21 {
22 W_Nexball_Attack(thiswep, actor, weaponentity, -1);
23 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
24 }
25 }
26 if (fire & 2)
27 if (weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
28 {
29 W_Nexball_Attack2(thiswep, actor, weaponentity);
30 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
31 }
32
33 if (!(fire & 1) && STAT(NB_METERSTART, actor) && actor.ballcarried)
34 {
35 W_Nexball_Attack(thiswep, actor, weaponentity, time - STAT(NB_METERSTART, actor));
36 // DropBall or stealing will set metertime back to 0
37 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
38 }
39}
40
41METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor, .entity weaponentity))
42{
43 TC(BallStealer, this);
44 //weapon_setup(WEP_PORTO.m_id);
45}
46
47METHOD(BallStealer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
48{
49 TC(BallStealer, thiswep);
50}
51
52METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor, .entity weaponentity))
53{
54 TC(BallStealer, this);
55 return true;
56}
57
58METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor, .entity weaponentity))
59{
60 TC(BallStealer, this);
61 return true;
62}
63
65{
66 //dprint("W_Nexball_Think\n");
67 //vector new_dir = steerlib_arrive(WarpZone_RefSys_TransformOrigin(this.enemy, this, this.enemy.origin), 2500);
68 float _speed = vlen(this.velocity);
69 vector old_dir = this.velocity * (1 / _speed);
70 vector new_dir = normalize(WarpZone_RefSys_TransformOrigin(this.enemy, this, this.enemy.origin + '0 0 50') - this.origin);
71
72 this.velocity = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
73 //this.velocity = new_dir * autocvar_g_nexball_safepass_turnrate;
74
75 this.nextthink = time;
76}
77
79{
80 //this.think = func_null;
81 //this.enemy = NULL;
82
84 entity ball = toucher;
85 entity attacker = this.owner;
86 // TODO: mutator hook to prevent picking up objectives
87 if ((attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal)
88 && (ball = toucher.ballcarried) && !IS_DEAD(toucher) && (IS_PLAYER(attacker)))
89 {
92 if (!attacker.ballcarried && !IS_DEAD(attacker))
93 {
94 LogNB("stole", attacker);
96
97 if (SAME_TEAM(attacker, toucher) && time > CS(attacker).teamkill_complain)
98 {
99 CS(attacker).teamkill_complain = time + 5;
100 CS(attacker).teamkill_soundtime = time + 0.4;
101 CS(attacker).teamkill_soundsource = toucher;
102 }
103
104 GiveBall(attacker, toucher.ballcarried);
105 }
106 }
107
108 delete(this);
109}
110
111void W_Nexball_Attack(Weapon thiswep, entity actor, .entity weaponentity, float t)
112{
113 entity ball = actor.ballcarried;
114 if (!ball)
115 return;
116
117 W_SetupShot_ProjectileSize(actor, weaponentity, BALL_MINS, BALL_MAXS, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0, WEP_PORTO.m_id); // TODO: use ballstealer weapon here? we don't want duplicates in the scoreboard
118
119 // Calculate multiplier
120 float mul;
121 if (t < 0)
122 mul = 1;
123 else
124 {
126 float ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
127 //One triangle wave period with 1 as max
129 if (mul > 1)
130 mul = 2 - mul;
131 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
132 }
133
135
136 // TODO: use the speed_up cvar too ??
137}
138
139void W_Nexball_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
140{
141 if (actor.ballcarried.enemy)
142 {
143 entity _ball = actor.ballcarried;
144 W_SetupShot_ProjectileSize(actor, weaponentity, BALL_MINS, BALL_MAXS, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0, WEP_PORTO.m_id | HITTYPE_SECONDARY); // TODO: use the ball stealer weapon here? probably don't want duplicates
145 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32, _ball));
147 _ball.nextthink = time;
148 return;
149 }
150
152 return;
153
154 W_SetupShot(actor, weaponentity, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0, WEP_PORTO.m_id);
155 entity missile = new(ballstealer);
156
157 missile.owner = actor;
158
159 set_movetype(missile, MOVETYPE_FLY);
160 PROJECTILE_MAKETRIGGER(missile);
161
162 //setmodel(missile, "models/elaser.mdl"); // precision set below
163 setsize(missile, '0 0 0', '0 0 0');
164 setorigin(missile, w_shotorg);
165
167 missile.angles = vectoangles(missile.velocity);
168 settouch(missile, W_Nexball_Touch);
169 setthink(missile, SUB_Remove);
170 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; // FIXME: use a distance instead?
171
172 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
173 missile.flags = FL_PROJECTILE;
174 IL_PUSH(g_projectiles, missile);
175 IL_PUSH(g_bot_dodge, missile);
176
177 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
178}
IntrusiveList g_bot_dodge
Definition api.qh:150
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
entity owner
Definition main.qh:87
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
const int FL_PROJECTILE
Definition constants.qh:77
vector velocity
float time
float nextthink
const int EF_BRIGHTFIELD
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
float teamkill_complain
Definition damage.qh:54
const int HITTYPE_SECONDARY
Definition all.qh:31
void SUB_Remove(entity this)
Remove entity.
Definition defer.qh:12
float EF_LOWPRECISION
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define TC(T, sym)
Definition _all.inc:82
#define STAT(...)
Definition stats.qh:94
vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
Transform origin org in from's reference into to's reference.
Definition common.qc:787
float vlen(vector v)
vector vectoangles(vector v)
vector normalize(vector v)
float max(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
#define UNSET_ONGROUND(s)
Definition movetypes.qh:18
const int MOVETYPE_FLY
Definition movetypes.qh:138
#define METHOD(cname, name, prototype)
Definition oo.qh:274
const int PROJECTILE_ELECTRO
Definition projectiles.qh:3
#define setthink(e, f)
vector
Definition self.qh:96
vector org
Definition self.qh:96
entity entity toucher
Definition self.qh:76
#define settouch(e, f)
Definition self.qh:77
#define PROJECTILE_TOUCH(e, t)
Definition common.qh:40
IntrusiveList g_projectiles
Definition common.qh:70
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:46
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
const int CH_WEAPON_A
Definition sound.qh:7
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
ClientState CS(Client this)
Definition state.qh:47
entity enemy
Definition sv_ctf.qh:152
float autocvar_g_nexball_basketball_meter_minpower
Definition sv_nexball.qc:22
float autocvar_g_balance_nexball_primary_refire
Definition sv_nexball.qc:42
bool autocvar_g_nexball_basketball_meter
Definition sv_nexball.qc:20
float autocvar_g_balance_nexball_secondary_refire
Definition sv_nexball.qc:47
float autocvar_g_nexball_basketball_meter_maxpower
Definition sv_nexball.qc:21
void LogNB(string mode, entity actor)
Definition sv_nexball.qc:76
float autocvar_g_balance_nexball_primary_animtime
Definition sv_nexball.qc:41
float autocvar_g_balance_nexball_secondary_lifetime
Definition sv_nexball.qc:46
float autocvar_g_balance_nexball_secondary_speed
Definition sv_nexball.qc:48
void GiveBall(entity plyr, entity ball)
float autocvar_g_balance_nexball_primary_speed
Definition sv_nexball.qc:43
float autocvar_g_nexball_safepass_turnrate
Definition sv_nexball.qc:34
float autocvar_g_balance_nexball_secondary_force
Definition sv_nexball.qc:45
float autocvar_g_nexball_tackling
Definition sv_nexball.qc:38
void DropBall(entity ball, vector org, vector vel)
float autocvar_g_balance_nexball_secondary_animtime
Definition sv_nexball.qc:44
float autocvar_g_nexball_basketball_teamsteal
Definition sv_nexball.qh:44
const vector BALL_MAXS
Definition sv_nexball.qh:26
float g_nexball_meter_period
Definition sv_nexball.qh:53
const vector BALL_MINS
Definition sv_nexball.qh:25
void W_Nexball_Think(entity this)
Definition sv_weapon.qc:64
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition jumppads.qc:32
void W_Nexball_Attack2(Weapon thiswep, entity actor,.entity weaponentity)
Definition sv_weapon.qc:139
void W_Nexball_Attack(Weapon thiswep, entity actor,.entity weaponentity, float t)
Definition sv_weapon.qc:111
void W_Nexball_Touch(entity this, entity toucher)
Definition sv_weapon.qc:78
#define SAME_TEAM(a, b)
Definition teams.qh:241
vector W_CalculateProjectileVelocity(entity actor, vector pvelocity, vector mvelocity, float forceAbsolute)
Definition tracing.qc:177
vector w_shotdir
Definition tracing.qh:20
#define W_SetupShot_ProjectileSize(ent, wepent, mi, ma, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:30
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:51
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)