Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spiderbot_weapons.qc File Reference
Include dependency graph for spiderbot_weapons.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vector spiberbot_calcartillery (vector org, vector tgt, float ht)
void spiderbot_guide_release (entity this)
void spiderbot_rocket_artillery (entity this)
void spiderbot_rocket_do (entity this)
void spiderbot_rocket_guided (entity this)
void spiderbot_rocket_unguided (entity this)

Variables

float spiberbot_calcartillery_flighttime

Function Documentation

◆ spiberbot_calcartillery()

vector spiberbot_calcartillery ( vector org,
vector tgt,
float ht )

Definition at line 64 of file spiderbot_weapons.qc.

65{
66 float grav, sdist, zdist, vs, vz, jumpheight;
67 vector sdir;
68
70 zdist = tgt_z - org_z;
71 sdist = vlen(tgt - org - zdist * '0 0 1');
72 sdir = normalize(tgt - org - zdist * '0 0 1');
73
74 // how high do we need to go?
75 jumpheight = fabs(ht);
76 if(zdist > 0)
77 jumpheight = jumpheight + zdist;
78
79 // push so high...
80 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
81
82 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
83 if(ht < 0)
84 if(zdist < 0)
85 vz = -vz;
86
87 vector solution;
88 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
89 // ALWAYS solvable because jumpheight >= zdist
90 if(!solution_z)
91 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)
92 if(zdist == 0)
93 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)
94
95 if(zdist < 0)
96 {
97 // down-jump
98 if(ht < 0)
99 {
100 // almost straight line type
101 // jump apex is before the jump
102 // we must take the larger one
104 }
105 else
106 {
107 // regular jump
108 // jump apex is during the jump
109 // we must take the larger one too
111 }
112 }
113 else
114 {
115 // up-jump
116 if(ht < 0)
117 {
118 // almost straight line type
119 // jump apex is after the jump
120 // we must take the smaller one
122 }
123 else
124 {
125 // regular jump
126 // jump apex is during the jump
127 // we must take the larger one
129 }
130 }
132
133 // finally calculate the velocity
134 return sdir * vs + '0 0 1' * vz;
135}
#define autocvar_sv_gravity
Definition stats.qh:421
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition math.qh:304
float vlen(vector v)
float sqrt(float f)
vector normalize(vector v)
float fabs(float f)
vector
Definition self.qh:92
vector org
Definition self.qh:92
float spiberbot_calcartillery_flighttime

References autocvar_sv_gravity, fabs(), normalize(), org, solve_quadratic(), spiberbot_calcartillery_flighttime, sqrt(), vector, and vlen().

Referenced by spiderbot_rocket_do().

◆ spiderbot_guide_release()

void spiderbot_guide_release ( entity this)

Definition at line 47 of file spiderbot_weapons.qc.

48{
49 bool donetrace = false;
50 IL_EACH(g_projectiles, it.realowner == this.owner && getthink(it) == spiderbot_rocket_guided,
51 {
52 if(!donetrace) // something exists, let's trace!
53 {
54 donetrace = true;
56 }
57
58 it.pos1 = trace_endpos;
60 });
61}
entity owner
Definition main.qh:87
vector trace_endpos
#define IL_EACH(this, cond, body)
#define setthink(e, f)
#define getthink(e)
IntrusiveList g_projectiles
Definition common.qh:58
void spiderbot_rocket_guided(entity this)
void spiderbot_rocket_unguided(entity this)
void crosshair_trace(entity pl)
Definition tracing.qc:549

References crosshair_trace(), entity(), g_projectiles, getthink, IL_EACH, owner, setthink, spiderbot_rocket_guided(), spiderbot_rocket_unguided(), and trace_endpos.

Referenced by spiderbot_rocket_do().

◆ spiderbot_rocket_artillery()

void spiderbot_rocket_artillery ( entity this)

Definition at line 5 of file spiderbot_weapons.qc.

6{
7 this.nextthink = time;
9}
float time
float nextthink
void UpdateCSQCProjectile(entity e)

References entity(), nextthink, time, and UpdateCSQCProjectile().

◆ spiderbot_rocket_do()

void spiderbot_rocket_do ( entity this)

Definition at line 137 of file spiderbot_weapons.qc.

138{
139 vector v;
140 entity rocket = NULL;
141
142 if (this.wait != -10)
143 {
144 if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && STAT(VEHICLESTAT_W2MODE, this) == SBRM_GUIDE)
145 {
146 if (this.wait == 1)
147 if (this.tur_head.frame == 9 || this.tur_head.frame == 1)
148 {
149 if(this.gun2.cnt < time && this.tur_head.frame == 9)
150 this.tur_head.frame = 1;
151
152 return;
153 }
154 this.wait = 1;
155 }
156 else
157 {
158 if(this.wait)
160
161 this.wait = 0;
162 }
163 }
164
165 if(this.gun2.cnt > time)
166 return;
167
168 if (this.tur_head.frame >= 9)
169 {
170 this.tur_head.frame = 1;
171 this.wait = 0;
172 }
173
174 if(this.wait != -10)
176 return;
177
178 if(weaponLocked(this.owner) || weaponUseForbidden(this.owner))
179 return;
180
181 v = gettaginfo(this.tur_head,gettagindex(this.tur_head,"tag_fire"));
182
183 switch(STAT(VEHICLESTAT_W2MODE, this))
184 {
185 case SBRM_VOLLY:
186 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
189 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
193 rocket.nextthink = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed);
195
196 if(PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.tur_head.frame == 1)
197 this.wait = -10;
198 break;
199 case SBRM_GUIDE:
200 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
203 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, this.owner);
205 rocket.pos1 = trace_endpos;
206 rocket.nextthink = time;
208
209
210 break;
211 case SBRM_ARTILLERY:
212 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
215 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
216
218
220 rocket.pos1_z = trace_endpos_z;
221
222 traceline(v, v + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this);
223 float h1 = 0.75 * vlen(v - trace_endpos);
224
225 //v = trace_endpos;
226 traceline(v , rocket.pos1 + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this);
227 float h2 = 0.75 * vlen(rocket.pos1 - v);
228
229 rocket.velocity = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2));
231 rocket.gravity = 1;
232 //setthink(rocket, spiderbot_rocket_artillery);
233 break;
234 }
235 rocket.classname = "spiderbot_rocket";
236
238
239 this.tur_head.frame += 1;
240 if (this.tur_head.frame == 9)
242 else
244
245 this.gun2.cnt = time + this.attack_finished_single[0];
246}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float wait
Definition items.qc:17
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition player.qh:152
float MOVE_WORLDONLY
vector v_forward
#define gettagindex
#define STAT(...)
Definition stats.qh:82
float random(void)
vector randomvec(void)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_TOSS
Definition movetypes.qh:135
#define NULL
Definition post.qh:14
#define gettaginfo
Definition post.qh:32
const int PROJECTILE_SPIDERROCKET
const int SBRM_VOLLY
Definition spiderbot.qc:12
const int SBRM_GUIDE
Definition spiderbot.qc:13
const int SBRM_ARTILLERY
Definition spiderbot.qc:14
vector spiberbot_calcartillery(vector org, vector tgt, float ht)
void spiderbot_guide_release(entity this)
float autocvar_g_vehicle_spiderbot_rocket_speed
float autocvar_g_vehicle_spiderbot_rocket_lifetime
float autocvar_g_vehicle_spiderbot_rocket_force
float autocvar_g_vehicle_spiderbot_rocket_damage
float autocvar_g_vehicle_spiderbot_rocket_radius
float autocvar_g_vehicle_spiderbot_rocket_health
float autocvar_g_vehicle_spiderbot_rocket_spread
float autocvar_g_vehicle_spiderbot_rocket_refire2
float autocvar_g_vehicle_spiderbot_rocket_reload
float autocvar_g_vehicle_spiderbot_rocket_refire
entity tur_head
Definition sv_turrets.qh:28
entity vehicles_projectile(entity this, entity _mzlfx, Sound _mzlsound, vector _org, vector _vel, float _dmg, float _radi, float _force, float _size, int _deahtype, float _projtype, float _health, bool _cull, bool _clianim, entity _owner)
void vehicles_projectile_explode_think(entity this)
entity gun2
int max_shot_distance
Definition weapon.qh:203
bool weaponUseForbidden(entity player)
bool weaponLocked(entity player)
float attack_finished_single[MAX_WEAPONSLOTS]

References attack_finished_single, autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_force, autocvar_g_vehicle_spiderbot_rocket_health, autocvar_g_vehicle_spiderbot_rocket_lifetime, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_refire, autocvar_g_vehicle_spiderbot_rocket_refire2, autocvar_g_vehicle_spiderbot_rocket_reload, autocvar_g_vehicle_spiderbot_rocket_speed, autocvar_g_vehicle_spiderbot_rocket_spread, crosshair_trace(), entity(), gettagindex, gettaginfo, gun2, max_shot_distance, MOVE_WORLDONLY, MOVETYPE_TOSS, normalize(), NULL, owner, PHYS_INPUT_BUTTON_ATCK2, PROJECTILE_SPIDERROCKET, random(), randomvec(), SBRM_ARTILLERY, SBRM_GUIDE, SBRM_VOLLY, set_movetype(), setthink, spiberbot_calcartillery(), spiderbot_guide_release(), spiderbot_rocket_guided(), STAT, time, trace_endpos, tur_head, v_forward, vector, vehicles_projectile(), vehicles_projectile_explode_think(), vlen(), wait, weaponLocked(), and weaponUseForbidden().

Referenced by spiderbot_frame().

◆ spiderbot_rocket_guided()

void spiderbot_rocket_guided ( entity this)

Definition at line 27 of file spiderbot_weapons.qc.

28{
29 vector newdir, olddir;
30
31 this.nextthink = time;
32
33 if(!this.realowner.vehicle)
35
37 olddir = normalize(this.velocity);
40
42
43 if (IS_DEAD(this.owner) || this.cnt < time)
44 this.use(this, NULL, NULL);
45}
float cnt
Definition powerups.qc:24
#define IS_DEAD(s)
Definition player.qh:245
vector velocity
vector origin
#define use
float autocvar_g_vehicle_spiderbot_rocket_turnrate
float autocvar_g_vehicle_spiderbot_rocket_noise
entity realowner

References autocvar_g_vehicle_spiderbot_rocket_noise, autocvar_g_vehicle_spiderbot_rocket_speed, autocvar_g_vehicle_spiderbot_rocket_turnrate, cnt, crosshair_trace(), entity(), IS_DEAD, nextthink, normalize(), NULL, origin, owner, randomvec(), realowner, setthink, spiderbot_rocket_unguided(), time, trace_endpos, UpdateCSQCProjectile(), use, vector, and velocity.

Referenced by spiderbot_guide_release(), and spiderbot_rocket_do().

◆ spiderbot_rocket_unguided()

void spiderbot_rocket_unguided ( entity this)

Definition at line 11 of file spiderbot_weapons.qc.

12{
13 vector newdir, olddir;
14
15 this.nextthink = time;
16
17 olddir = normalize(this.velocity);
20
22
23 if (IS_DEAD(this.owner) || this.cnt < time || vdist(this.pos1 - this.origin, <, 16))
24 this.use(this, NULL, NULL);
25}
vector pos1
Definition subs.qh:50
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8

References autocvar_g_vehicle_spiderbot_rocket_noise, autocvar_g_vehicle_spiderbot_rocket_speed, autocvar_g_vehicle_spiderbot_rocket_turnrate, cnt, entity(), IS_DEAD, nextthink, normalize(), NULL, origin, owner, pos1, randomvec(), time, UpdateCSQCProjectile(), use, vdist, vector, and velocity.

Referenced by spiderbot_guide_release(), and spiderbot_rocket_guided().

Variable Documentation

◆ spiberbot_calcartillery_flighttime

float spiberbot_calcartillery_flighttime

Definition at line 63 of file spiderbot_weapons.qc.

Referenced by spiberbot_calcartillery().