Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
spiderbot_weapons.qc
Go to the documentation of this file.
2
3#ifdef SVQC
4
10
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}
24
42
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}
58
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}
127
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}
238
239#endif // SVQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
float wait
Definition items.qc:17
entity owner
Definition main.qh:87
#define IS_DEAD(s)
Definition player.qh:244
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition player.qh:154
vector velocity
float time
vector trace_endpos
float nextthink
float MOVE_WORLDONLY
vector v_forward
vector origin
#define use
void UpdateCSQCProjectile(entity e)
#define gettagindex
#define IL_EACH(this, cond, body)
#define STAT(...)
Definition stats.qh:82
ERASEABLE vector solve_quadratic(float a, float b, float c)
ax^2 + bx + c = 0
Definition math.qh:304
float random(void)
float vlen(vector v)
float sqrt(float f)
vector randomvec(void)
vector normalize(vector v)
float fabs(float f)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
#define PHYS_GRAVITY(s)
Definition movetypes.qh:53
const int MOVETYPE_TOSS
Definition movetypes.qh:135
#define NULL
Definition post.qh:14
#define gettaginfo
Definition post.qh:32
const int PROJECTILE_SPIDERROCKET
#define setthink(e, f)
#define getthink(e)
vector
Definition self.qh:92
vector org
Definition self.qh:92
IntrusiveList g_projectiles
Definition common.qh:58
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_rocket_artillery(entity this)
float spiberbot_calcartillery_flighttime
void spiderbot_rocket_guided(entity this)
void spiderbot_rocket_unguided(entity this)
void spiderbot_rocket_do(entity this)
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_turnrate
float autocvar_g_vehicle_spiderbot_rocket_force
float autocvar_g_vehicle_spiderbot_rocket_noise
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
vector pos1
Definition subs.qh:50
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
entity realowner
void crosshair_trace(entity pl)
Definition tracing.qc:542
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
int max_shot_distance
Definition weapon.qh:245
bool weaponUseForbidden(entity player)
bool weaponLocked(entity player)
float attack_finished_single[MAX_WEAPONSLOTS]