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 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}
26
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}
46
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}
62
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}
136
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}
247
248#endif
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:245
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition player.qh:152
#define autocvar_sv_gravity
Definition stats.qh:421
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
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: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_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:549
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
int max_shot_distance
Definition weapon.qh:203
bool weaponUseForbidden(entity player)
bool weaponLocked(entity player)
float attack_finished_single[MAX_WEAPONSLOTS]