Xonotic
sv_weapon.qc File Reference
#include "sv_weapon.qh"
+ Include dependency graph for sv_weapon.qc:

Go to the source code of this file.

Functions

vector trigger_push_calculatevelocity (vector org, entity tgt, float ht, entity pushed_entity)
 
void W_Nexball_Attack (Weapon thiswep, entity actor,.entity weaponentity, float t)
 
void W_Nexball_Attack2 (Weapon thiswep, entity actor,.entity weaponentity)
 
void W_Nexball_Think (entity this)
 
void W_Nexball_Touch (entity this, entity toucher)
 

Function Documentation

◆ trigger_push_calculatevelocity()

vector trigger_push_calculatevelocity ( vector  org,
entity  tgt,
float  ht,
entity  pushed_entity 
)

Definition at line 31 of file jumppads.qc.

Referenced by W_Nexball_Attack2().

32 {
33  float grav, sdist, zdist, vs, vz, jumpheight;
34  vector sdir, torg;
35 
36  torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
37 
38  grav = PHYS_GRAVITY(NULL);
39  if(pushed_entity && pushed_entity.gravity)
40  grav *= pushed_entity.gravity;
41 
42  zdist = torg.z - org.z;
43  sdist = vlen(torg - org - zdist * '0 0 1');
44  sdir = normalize(torg - org - zdist * '0 0 1');
45 
46  // how high do we need to push the player?
47  jumpheight = fabs(ht);
48  if(zdist > 0)
49  jumpheight = jumpheight + zdist;
50 
51  /*
52  STOP.
53 
54  You will not understand the following equations anyway...
55  But here is what I did to get them.
56 
57  I used the functions
58 
59  s(t) = t * vs
60  z(t) = t * vz - 1/2 grav t^2
61 
62  and solved for:
63 
64  s(ti) = sdist
65  z(ti) = zdist
66  max(z, ti) = jumpheight
67 
68  From these three equations, you will find the three parameters vs, vz
69  and ti.
70  */
71 
72  // push him so high...
73  vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
74 
75  // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
76  if(ht < 0)
77  if(zdist < 0)
78  vz = -vz;
79 
80  vector solution;
81  solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
82  // ALWAYS solvable because jumpheight >= zdist
83  if(!solution.z)
84  solution_y = solution.x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0)
85  if(zdist == 0)
86  solution_x = solution.y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
87 
88  float flighttime;
89  if(zdist < 0)
90  {
91  // down-jump
92  if(ht < 0)
93  {
94  // almost straight line type
95  // jump apex is before the jump
96  // we must take the larger one
97  flighttime = solution.y;
98  }
99  else
100  {
101  // regular jump
102  // jump apex is during the jump
103  // we must take the larger one too
104  flighttime = solution.y;
105  }
106  }
107  else
108  {
109  // up-jump
110  if(ht < 0)
111  {
112  // almost straight line type
113  // jump apex is after the jump
114  // we must take the smaller one
115  flighttime = solution.x;
116  }
117  else
118  {
119  // regular jump
120  // jump apex is during the jump
121  // we must take the larger one
122  flighttime = solution.y;
123  }
124  }
125  vs = sdist / flighttime;
126 
127  // finally calculate the velocity
128  return sdir * vs + '0 0 1' * vz;
129 }
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition: math.qh:307
#define NULL
Definition: post.qh:17
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the caller graph for this function:

◆ W_Nexball_Attack()

void W_Nexball_Attack ( Weapon  thiswep,
entity  actor,
.entity  weaponentity,
float  t 
)

Definition at line 108 of file sv_weapon.qc.

References autocvar_g_balance_nexball_primary_speed, autocvar_g_nexball_basketball_meter_maxpower, autocvar_g_nexball_basketball_meter_minpower, BALL_MAXS, BALL_MINS, CH_WEAPON_A, DropBall(), entity(), g_nexball_meter_period, max(), MOVE_WORLDONLY, NULL, trace_startsolid, W_CalculateProjectileVelocity(), W_SetupShot, w_shotdir, and w_shotorg.

109 {
110  entity ball;
111  float mul, mi, ma;
112  if(!(ball = actor.ballcarried))
113  return;
114 
115  W_SetupShot(actor, weaponentity, 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
117  if(trace_startsolid)
118  {
119  if(STAT(NB_METERSTART, actor))
120  STAT(NB_METERSTART, actor) = 0; // Shot failed, hide the power meter
121  return;
122  }
123 
124  //Calculate multiplier
125  if(t < 0)
126  mul = 1;
127  else
128  {
130  ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
131  //One triangle wave period with 1 as max
133  if(mul > 1)
134  mul = 2 - mul;
135  mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
136  }
137 
139 
140 
141  //TODO: use the speed_up cvar too ??
142 }
void DropBall(entity ball, vector org, vector vel)
Definition: sv_nexball.qc:202
vector w_shotorg
Definition: tracing.qh:18
float g_nexball_meter_period
Definition: sv_nexball.qh:54
entity() spawn
const vector BALL_MAXS
Definition: sv_nexball.qh:26
float autocvar_g_nexball_basketball_meter_maxpower
Definition: sv_nexball.qc:21
vector w_shotdir
Definition: tracing.qh:19
float autocvar_g_nexball_basketball_meter_minpower
Definition: sv_nexball.qc:22
float autocvar_g_balance_nexball_primary_speed
Definition: sv_nexball.qc:43
const int CH_WEAPON_A
Definition: sound.qh:7
#define NULL
Definition: post.qh:17
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:33
const vector BALL_MINS
Definition: sv_nexball.qh:25
float trace_startsolid
Definition: csprogsdefs.qc:35
vector W_CalculateProjectileVelocity(entity actor, vector pvelocity, vector mvelocity, float forceAbsolute)
Definition: tracing.qc:169
float MOVE_WORLDONLY
+ Here is the call graph for this function:

◆ W_Nexball_Attack2()

void W_Nexball_Attack2 ( Weapon  thiswep,
entity  actor,
.entity  weaponentity 
)

Definition at line 144 of file sv_weapon.qc.

References autocvar_g_balance_nexball_secondary_lifetime, autocvar_g_balance_nexball_secondary_speed, autocvar_g_nexball_tackling, CH_WEAPON_A, CSQCProjectile(), DropBall(), EF_BRIGHTFIELD, EF_LOWPRECISION, entity(), g_bot_dodge, g_projectiles, HITTYPE_SECONDARY, IL_PUSH(), MOVETYPE_FLY, PROJECTILE_ELECTRO, PROJECTILE_MAKETRIGGER, set_movetype(), setorigin(), setthink, time, trigger_push_calculatevelocity(), vectoangles(), W_Nexball_Think(), W_Nexball_Touch(), W_SetupProjVelocity_Basic, W_SetupShot, and w_shotorg.

145 {
146  if(actor.ballcarried.enemy)
147  {
148  entity _ball = actor.ballcarried;
149  W_SetupShot(actor, weaponentity, 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
150  DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32, _ball));
151  setthink(_ball, W_Nexball_Think);
152  _ball.nextthink = time;
153  return;
154  }
155 
157  return;
158 
159  W_SetupShot(actor, weaponentity, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0, WEP_PORTO.m_id);
160  entity missile = new(ballstealer);
161 
162  missile.owner = actor;
163 
164  set_movetype(missile, MOVETYPE_FLY);
165  PROJECTILE_MAKETRIGGER(missile);
166 
167  //setmodel(missile, "models/elaser.mdl"); // precision set below
168  setsize(missile, '0 0 0', '0 0 0');
169  setorigin(missile, w_shotorg);
170 
172  missile.angles = vectoangles(missile.velocity);
173  settouch(missile, W_Nexball_Touch);
174  setthink(missile, SUB_Remove);
175  missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
176 
177  missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
178  missile.flags = FL_PROJECTILE;
179  IL_PUSH(g_projectiles, missile);
180  IL_PUSH(g_bot_dodge, missile);
181 
182  CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
183 }
#define W_SetupProjVelocity_Basic(ent, pspeed, pspread)
Definition: tracing.qh:48
float autocvar_g_balance_nexball_secondary_speed
Definition: sv_nexball.qc:48
void DropBall(entity ball, vector org, vector vel)
Definition: sv_nexball.qc:202
vector w_shotorg
Definition: tracing.qh:18
#define PROJECTILE_MAKETRIGGER(e)
Definition: common.qh:29
void W_Nexball_Think(entity this)
Definition: sv_weapon.qc:62
entity() spawn
void W_Nexball_Touch(entity this, entity toucher)
Definition: sv_weapon.qc:77
float autocvar_g_nexball_tackling
Definition: sv_nexball.qc:38
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
const int EF_BRIGHTFIELD
IntrusiveList g_bot_dodge
Definition: api.qh:150
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
const int CH_WEAPON_A
Definition: sound.qh:7
float autocvar_g_balance_nexball_secondary_lifetime
Definition: sv_nexball.qc:46
const int HITTYPE_SECONDARY
Definition: all.qh:25
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:33
IntrusiveList g_projectiles
Definition: common.qh:46
const int PROJECTILE_ELECTRO
Definition: projectiles.qh:3
vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
Definition: jumppads.qc:31
setorigin(ent, v)
#define setthink(e, f)
float time
Definition: csprogsdefs.qc:16
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
float EF_LOWPRECISION
+ Here is the call graph for this function:

◆ W_Nexball_Think()

void W_Nexball_Think ( entity  this)

Definition at line 62 of file sv_weapon.qc.

References autocvar_g_nexball_safepass_turnrate, enemy, nextthink, normalize(), time, vector(), velocity, and vlen().

Referenced by W_Nexball_Attack2().

63 {
64  //dprint("W_Nexball_Think\n");
65  //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
66  vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
67  vector old_dir = normalize(this.velocity);
68  float _speed = vlen(this.velocity);
69  vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
70  //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
71 
72  this.velocity = new_vel;
73 
74  this.nextthink = time;
75 }
float autocvar_g_nexball_safepass_turnrate
Definition: sv_nexball.qc:34
entity enemy
Definition: sv_ctf.qh:143
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ W_Nexball_Touch()

void W_Nexball_Touch ( entity  this,
entity  toucher 
)

Definition at line 77 of file sv_weapon.qc.

References _sound, ATTEN_NORM, autocvar_g_balance_nexball_secondary_force, autocvar_g_nexball_basketball_teamsteal, CH_TRIGGER, CS(), entity(), GiveBall(), IS_DEAD, IS_PLAYER, LogNB(), normalize(), owner, PROJECTILE_TOUCH, SAME_TEAM, teamkill_complain, time, UNSET_ONGROUND, velocity, and VOL_BASE.

Referenced by W_Nexball_Attack2().

78 {
79  entity ball, attacker;
80  attacker = this.owner;
81  //this.think = func_null;
82  //this.enemy = NULL;
83 
84  PROJECTILE_TOUCH(this, toucher);
85  if(attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal)
86  if((ball = toucher.ballcarried) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (IS_PLAYER(attacker)))
87  {
88  toucher.velocity = toucher.velocity + normalize(this.velocity) * toucher.damageforcescale * autocvar_g_balance_nexball_secondary_force;
89  UNSET_ONGROUND(toucher);
90  if(!attacker.ballcarried)
91  {
92  LogNB("stole", attacker);
93  _sound(toucher, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
94 
95  if(SAME_TEAM(attacker, toucher) && time > CS(attacker).teamkill_complain)
96  {
97  CS(attacker).teamkill_complain = time + 5;
98  CS(attacker).teamkill_soundtime = time + 0.4;
99  CS(attacker).teamkill_soundsource = toucher;
100  }
101 
102  GiveBall(attacker, toucher.ballcarried);
103  }
104  }
105  delete(this);
106 }
float teamkill_complain
Definition: damage.qh:57
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
void GiveBall(entity plyr, entity ball)
Definition: sv_nexball.qc:141
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
entity owner
Definition: main.qh:73
float autocvar_g_balance_nexball_secondary_force
Definition: sv_nexball.qc:45
#define PROJECTILE_TOUCH(e, t)
Definition: common.qh:27
const int CH_TRIGGER
Definition: sound.qh:12
const float VOL_BASE
Definition: sound.qh:36
#define SAME_TEAM(a, b)
Definition: teams.qh:239
#define IS_DEAD(s)
Definition: utils.qh:26
const float ATTEN_NORM
Definition: sound.qh:30
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
void LogNB(string mode, entity actor)
Definition: sv_nexball.qc:77
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
float autocvar_g_nexball_basketball_teamsteal
Definition: sv_nexball.qh:44
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function: