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 60 of file spiderbot_weapons.qc.

61{
62 float grav = PHYS_GRAVITY(NULL);
63 float zdist = tgt.z - org.z;
64 float sdist = vlen(tgt - org - zdist * '0 0 1');
65 vector sdir = normalize(tgt - org - zdist * '0 0 1');
66
67 // how high do we need to go?
68 float jumpheight = fabs(ht);
69 if (zdist > 0)
70 jumpheight += zdist;
71
72 // push so high...
73 float vz = sqrt(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 && zdist < 0)
77 vz = -vz;
78
79 vector solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
80 // ALWAYS solvable because jumpheight >= zdist
81 if (!solution.z)
82 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)
83 if (zdist == 0)
84 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)
85
86 if (zdist < 0)
87 {
88 // down-jump
89 if (ht < 0)
90 {
91 // almost straight line type
92 // jump apex is before the jump
93 // we must take the larger one
95 }
96 else
97 {
98 // regular jump
99 // jump apex is during the jump
100 // we must take the larger one too
102 }
103 }
104 else
105 {
106 // up-jump
107 if (ht < 0)
108 {
109 // almost straight line type
110 // jump apex is after the jump
111 // we must take the smaller one
113 }
114 else
115 {
116 // regular jump
117 // jump apex is during the jump
118 // we must take the larger one
120 }
121 }
122 float vs = sdist / spiberbot_calcartillery_flighttime;
123
124 // finally calculate the velocity
125 return sdir * vs + '0 0 1' * vz;
126}
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)
#define PHYS_GRAVITY(s)
Definition movetypes.qh:53
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
vector org
Definition self.qh:92
float spiberbot_calcartillery_flighttime

References fabs(), normalize(), NULL, org, PHYS_GRAVITY, 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 43 of file spiderbot_weapons.qc.

44{
45 bool done_trace = false;
46 IL_EACH(g_projectiles, it.realowner == this.owner && getthink(it) == spiderbot_rocket_guided,
47 {
48 if (!done_trace) // something exists, let's trace!
49 {
50 done_trace = true;
52 }
53
54 it.pos1 = trace_endpos;
56 });
57}
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:542

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 128 of file spiderbot_weapons.qc.

129{
130 if (this.wait != -10)
131 {
132 if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && STAT(VEHICLESTAT_W2MODE, this) == SBRM_GUIDE)
133 {
134 if (this.wait == 1
135 && (this.tur_head.frame == 9 || this.tur_head.frame == 1))
136 {
137 if (this.gun2.cnt < time && this.tur_head.frame == 9)
138 this.tur_head.frame = 1;
139
140 return;
141 }
142 this.wait = 1;
143 }
144 else
145 {
146 if (this.wait)
148
149 this.wait = 0;
150 }
151 }
152
153 if (this.gun2.cnt > time)
154 return;
155
156 if (this.tur_head.frame >= 9)
157 {
158 this.tur_head.frame = 1;
159 this.wait = 0;
160 }
161
162 if (this.wait != -10
164 return;
165
166 if (weaponLocked(this.owner) || weaponUseForbidden(this.owner))
167 return;
168
169 entity rocket = NULL;
170 vector v = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_fire"));
171
172 switch (STAT(VEHICLESTAT_W2MODE, this))
173 {
174 case SBRM_VOLLY:
175 {
176 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
179 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
183 rocket.nextthink = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed);
185
186 if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.tur_head.frame == 1)
187 this.wait = -10;
188 break;
189 }
190 case SBRM_GUIDE:
191 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
194 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, this.owner);
196 rocket.pos1 = trace_endpos;
197 rocket.nextthink = time;
199 break;
200 case SBRM_ARTILLERY:
201 {
202 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH, SND_VEH_SPIDERBOT_ROCKET_FIRE,
205 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
206
208
210 rocket.pos1.z = trace_endpos.z;
211
212 traceline(v, v + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this);
213 float h1 = 0.75 * vlen(v - trace_endpos);
214
215 //v = trace_endpos;
216 traceline(v, rocket.pos1 + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this);
217 float h2 = 0.75 * vlen(rocket.pos1 - v);
218
219 rocket.velocity = spiberbot_calcartillery(v, rocket.pos1, (h1 < h2 ? h1 : h2));
221 rocket.gravity = 1;
222 //setthink(rocket, spiderbot_rocket_artillery);
223 break;
224 }
225 }
226 rocket.classname = "spiderbot_rocket";
227
229
230 ++this.tur_head.frame;
231 if (this.tur_head.frame == 9)
233 else
235
236 this.gun2.cnt = time + this.attack_finished_single[0];
237}
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:154
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 gettaginfo
Definition post.qh:32
const int PROJECTILE_SPIDERROCKET
const int SBRM_VOLLY
Definition spiderbot.qc:10
const int SBRM_GUIDE
Definition spiderbot.qc:11
const int SBRM_ARTILLERY
Definition spiderbot.qc:12
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:245
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 25 of file spiderbot_weapons.qc.

26{
27 this.nextthink = time;
28
29 if (!this.realowner.vehicle)
31
33 vector olddir = normalize(this.velocity);
36
38
39 if (IS_DEAD(this.owner) || this.cnt < time)
40 this.use(this, NULL, NULL);
41}
float cnt
Definition powerups.qc:24
#define IS_DEAD(s)
Definition player.qh:244
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 this.nextthink = time;
14
15 vector olddir = normalize(this.velocity);
18
20
21 if (IS_DEAD(this.owner) || this.cnt < time || vdist(this.pos1 - this.origin, <, 16))
22 this.use(this, NULL, NULL);
23}
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 59 of file spiderbot_weapons.qc.

Referenced by spiberbot_calcartillery().