Xonotic
sv_weapon.qc
Go to the documentation of this file.
1 #include "sv_weapon.qh"
2 
3 void W_Nexball_Attack(Weapon thiswep, entity actor, .entity weaponentity, float t);
4 void W_Nexball_Attack2(Weapon thiswep, entity actor, .entity weaponentity);
5 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity);
6 
7 METHOD(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))
13  {
14  if(actor.ballcarried && !STAT(NB_METERSTART, actor))
15  STAT(NB_METERSTART, actor) = time;
16  else
17  weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
18  }
19  else
20  {
21  W_Nexball_Attack(thiswep, actor, weaponentity, -1);
22  weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
23  }
24  if(fire & 2)
25  if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
26  {
27  W_Nexball_Attack2(thiswep, actor, weaponentity);
28  weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
29  }
30 
31  if(!(fire & 1) && STAT(NB_METERSTART, actor) && actor.ballcarried)
32  {
33  W_Nexball_Attack(thiswep, actor, weaponentity, time - STAT(NB_METERSTART, actor));
34  // DropBall or stealing will set metertime back to 0
35  weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
36  }
37 }
38 
39 METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor, .entity weaponentity))
40 {
41  TC(BallStealer, this);
42  //weapon_setup(WEP_PORTO.m_id);
43 }
44 
45 METHOD(BallStealer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
46 {
47  TC(BallStealer, thiswep);
48 }
49 
50 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor, .entity weaponentity))
51 {
52  TC(BallStealer, this);
53  return true;
54 }
55 
56 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor, .entity weaponentity))
57 {
58  TC(BallStealer, this);
59  return true;
60 }
61 
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 }
76 
77 void W_Nexball_Touch(entity this, entity toucher)
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 }
107 
108 void W_Nexball_Attack(Weapon thiswep, entity actor, .entity weaponentity, float t)
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 }
143 
144 void W_Nexball_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
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
float g_nexball_meter_period
Definition: sv_nexball.qh:54
float teamkill_complain
Definition: damage.qh:57
void W_Nexball_Think(entity this)
Definition: sv_weapon.qc:62
entity() spawn
const vector BALL_MAXS
Definition: sv_nexball.qh:26
ClientState CS(Client this)
Definition: state.qh:47
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
bool autocvar_g_nexball_basketball_meter
Definition: sv_nexball.qc:20
void W_Nexball_Touch(entity this, entity toucher)
Definition: sv_weapon.qc:77
float autocvar_g_nexball_basketball_meter_maxpower
Definition: sv_nexball.qc:21
float autocvar_g_nexball_tackling
Definition: sv_nexball.qc:38
vector w_shotdir
Definition: tracing.qh:19
void GiveBall(entity plyr, entity ball)
Definition: sv_nexball.qc:141
float autocvar_g_balance_nexball_secondary_animtime
Definition: sv_nexball.qc:44
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
float autocvar_g_nexball_basketball_meter_minpower
Definition: sv_nexball.qc:22
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
const int EF_BRIGHTFIELD
#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
IntrusiveList g_bot_dodge
Definition: api.qh:150
#define PROJECTILE_TOUCH(e, t)
Definition: common.qh:27
float autocvar_g_nexball_safepass_turnrate
Definition: sv_nexball.qc:34
void W_Nexball_Attack(Weapon thiswep, entity actor,.entity weaponentity, float t)
Definition: sv_weapon.qc:108
float autocvar_g_balance_nexball_primary_refire
Definition: sv_nexball.qc:42
entity enemy
Definition: sv_ctf.qh:143
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
float autocvar_g_balance_nexball_primary_speed
Definition: sv_nexball.qc:43
const int CH_WEAPON_A
Definition: sound.qh:7
float autocvar_g_balance_nexball_secondary_lifetime
Definition: sv_nexball.qc:46
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
const int CH_TRIGGER
Definition: sound.qh:12
#define NULL
Definition: post.qh:17
const float VOL_BASE
Definition: sound.qh:36
#define TC(T, sym)
Definition: _all.inc:82
#define SAME_TEAM(a, b)
Definition: teams.qh:239
const int HITTYPE_SECONDARY
Definition: all.qh:25
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition: tracing.qh:33
#define IS_DEAD(s)
Definition: utils.qh:26
const float ATTEN_NORM
Definition: sound.qh:30
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
IntrusiveList g_projectiles
Definition: common.qh:46
float autocvar_g_balance_nexball_secondary_refire
Definition: sv_nexball.qc:47
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
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
setorigin(ent, v)
void LogNB(string mode, entity actor)
Definition: sv_nexball.qc:77
#define setthink(e, f)
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
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103
void W_Nexball_Attack2(Weapon thiswep, entity actor,.entity weaponentity)
Definition: sv_weapon.qc:144
float autocvar_g_balance_nexball_primary_animtime
Definition: sv_nexball.qc:41
float autocvar_g_nexball_basketball_teamsteal
Definition: sv_nexball.qh:44
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
#define IS_PLAYER(v)
Definition: utils.qh:9
float EF_LOWPRECISION