1 #include "spiderbot_weapons.qh"
7 void spiderbot_rocket_artillery(entity this)
10 UpdateCSQCProjectile(this);
13 void spiderbot_rocket_unguided(entity this)
15 vector newdir, olddir;
17 this.nextthink = time;
19 olddir = normalize(this.velocity);
20 newdir = normalize(this.pos1 - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
21 this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
23 UpdateCSQCProjectile(this);
25 if (IS_DEAD(this.owner) || this.cnt < time || vdist(this.pos1 - this.origin, <, 16))
26 this.use(this, NULL, NULL);
29 void spiderbot_rocket_guided(entity this)
31 vector newdir, olddir;
33 this.nextthink = time;
35 if(!this.realowner.vehicle)
36 setthink(this, spiderbot_rocket_unguided);
38 crosshair_trace(this.realowner);
39 olddir = normalize(this.velocity);
40 newdir = normalize(trace_endpos - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise;
41 this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed;
43 UpdateCSQCProjectile(this);
45 if (IS_DEAD(this.owner) || this.cnt < time)
46 this.use(this, NULL, NULL);
49 void spiderbot_guide_release(entity this)
51 FOREACH_ENTITY_ENT(realowner, this.owner,
53 if(i == 0) // something exists, let's trace!
54 crosshair_trace(this.owner);
56 if(getthink(it) == spiderbot_rocket_guided)
58 it.pos1 = trace_endpos;
59 setthink(it, spiderbot_rocket_unguided);
64 float spiberbot_calcartillery_flighttime;
65 vector spiberbot_calcartillery(vector org, vector tgt, float ht)
67 float grav, sdist, zdist, vs, vz, jumpheight;
70 grav = autocvar_sv_gravity;
71 zdist = tgt_z - org_z;
72 sdist = vlen(tgt - org - zdist * '0 0 1');
73 sdir = normalize(tgt - org - zdist * '0 0 1');
75 // how high do we need to go?
76 jumpheight = fabs(ht);
78 jumpheight = jumpheight + zdist;
81 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
83 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
89 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
90 // ALWAYS solvable because jumpheight >= zdist
92 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)
94 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)
101 // almost straight line type
102 // jump apex is before the jump
103 // we must take the larger one
104 spiberbot_calcartillery_flighttime = solution_y;
109 // jump apex is during the jump
110 // we must take the larger one too
111 spiberbot_calcartillery_flighttime = solution_y;
119 // almost straight line type
120 // jump apex is after the jump
121 // we must take the smaller one
122 spiberbot_calcartillery_flighttime = solution_x;
127 // jump apex is during the jump
128 // we must take the larger one
129 spiberbot_calcartillery_flighttime = solution_y;
132 vs = sdist / spiberbot_calcartillery_flighttime;
134 // finally calculate the velocity
135 return sdir * vs + '0 0 1' * vz;
138 void spiderbot_rocket_do(entity this)
141 entity rocket = NULL;
143 if (this.wait != -10)
145 if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.vehicle_weapon2mode == SBRM_GUIDE)
148 if (this.tur_head.frame == 9 || this.tur_head.frame == 1)
150 if(this.gun2.cnt < time && this.tur_head.frame == 9)
151 this.tur_head.frame = 1;
160 spiderbot_guide_release(this);
166 if(this.gun2.cnt > time)
169 if (this.tur_head.frame >= 9)
171 this.tur_head.frame = 1;
176 if(!PHYS_INPUT_BUTTON_ATCK2(this.owner))
179 if(forbidWeaponUse(this.owner))
182 v = gettaginfo(this.tur_head,gettagindex(this.tur_head,"tag_fire"));
184 switch(this.vehicle_weapon2mode)
187 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE,
188 v, normalize(randomvec() * autocvar_g_vehicle_spiderbot_rocket_spread + v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
189 autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
190 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
191 crosshair_trace(this.owner);
192 float _dist = (random() * autocvar_g_vehicle_spiderbot_rocket_radius) + vlen(v - trace_endpos);
193 _dist -= (random() * autocvar_g_vehicle_spiderbot_rocket_radius) ;
194 rocket.nextthink = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed);
195 setthink(rocket, vehicles_projectile_explode_think);
197 if(PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.tur_head.frame == 1)
201 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE,
202 v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
203 autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
204 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, this.owner);
205 crosshair_trace(this.owner);
206 rocket.pos1 = trace_endpos;
207 rocket.nextthink = time;
208 setthink(rocket, spiderbot_rocket_guided);
213 rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE,
214 v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed,
215 autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1,
216 DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner);
218 crosshair_trace(this.owner);
220 rocket.pos1 = trace_endpos + randomvec() * (0.75 * autocvar_g_vehicle_spiderbot_rocket_radius);
221 rocket.pos1_z = trace_endpos_z;
223 traceline(v, v + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, this);
224 float h1 = 0.75 * vlen(v - trace_endpos);
227 traceline(v , rocket.pos1 + '0 0 1' * MAX_SHOT_DISTANCE, MOVE_WORLDONLY, this);
228 float h2 = 0.75 * vlen(rocket.pos1 - v);
230 rocket.velocity = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2));
231 set_movetype(rocket, MOVETYPE_TOSS);
233 //setthink(rocket, spiderbot_rocket_artillery);
236 rocket.classname = "spiderbot_rocket";
238 rocket.cnt = time + autocvar_g_vehicle_spiderbot_rocket_lifetime;
240 this.tur_head.frame += 1;
241 if (this.tur_head.frame == 9)
242 this.attack_finished_single[0] = autocvar_g_vehicle_spiderbot_rocket_reload;
244 this.attack_finished_single[0] = ((this.vehicle_weapon2mode == SBRM_VOLLY) ? autocvar_g_vehicle_spiderbot_rocket_refire2 : autocvar_g_vehicle_spiderbot_rocket_refire);
246 this.gun2.cnt = time + this.attack_finished_single[0];