Skip to content

Commit

Permalink
Z-aware ogres
Browse files Browse the repository at this point in the history
  • Loading branch information
4LT committed Nov 28, 2023
1 parent 387c71f commit 79c431b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 6 deletions.
6 changes: 6 additions & 0 deletions defs.qc
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ float framecount;

float skill;

//
// Conduit globals
//

float gravity;

//================================================

//
Expand Down
55 changes: 55 additions & 0 deletions math.qc
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,58 @@ vector(vector in) normalize_delta_angles = {
out_z = wrap(in_z, MIN_ANG, MAX_ANG);
return out;
};

/*
* Find the sqrt of an integer by leveraging vlen in O(log x) instructions
*/
float(float x) isqrt {
float quot, rem, rt;

quot = floor(x/2);
rem = x - quot * 2;

if (quot > 1) {
rt = isqrt(quot);
return vlen([rt, rt, rem]);
} else {
return vlen([quot, quot, rem]);
}
};

/*
* Approximate the sqrt of a number in O(log x) instructions
*/
float(float x) sqrt {
// boost precision for low values while avoiding saturation on high values
if (x < 256) {
return isqrt(rint(x * 256)) / 16;
} else if (x <= 0xFFFFFF) { // check for EXCEEDINGLY large values
return isqrt(rint(x));
} else {
return isqrt(x);
}
};

/* Find the roots to a quadratic equation
* a - Quadratic coefficient
* b - Linear coefficient
* c - Constant coefficient
*
* Roots are returned as _x and _y of vector, or 1 is returned for _z of vector
*/
vector(float a, float b, float c) quadratic {
float det, det_sqrt;
vector ret_vec;

det = b*b - 4 * a * c;
if (det < 0) {
return [NAN, NAN, 1];
}

ret_vec = '0 0 0';
det_sqrt = sqrt(det);
ret_vec_x = (-b + det_sqrt) / 2 / a;
ret_vec_y = (-b - det_sqrt) / 2 / a;

return ret_vec;
};
58 changes: 52 additions & 6 deletions ogre.qc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ OGRE
==============================================================================
*/

static const float MIN_GRENADE_SLOPE = -0.5;
static const float MAX_GRENADE_SLOPE = 0.85;

$cd /raid/quake/id1/models/ogre_c
$origin 0 0 24
$base base
Expand Down Expand Up @@ -104,12 +107,49 @@ void() OgreGrenadeTouch =
self.avelocity = '0 0 0';
};

static vector(vector start, vector end, float speed) ArcTo = {
float dz, dist, dist_sq, slope, speed_sq, det;
vector vel_0, v_components;

float too_far = FALSE;
float picked_2nd_root = FALSE;
vector disp = end - start;
dz = disp_z;
disp_z = 0;
dist = vlen(disp);
dist_sq = dist * dist;
speed_sq = speed * speed;

// Apply quadratic formula to find slope
det = speed_sq * speed_sq - gravity *
(gravity * dist_sq + 2 * speed_sq * dz);

if (det < 0) {
slope = MAX_GRENADE_SLOPE;
} else {
slope = (speed_sq - sqrt(det)) / gravity / dist;
}

if (slope < MIN_GRENADE_SLOPE) {
slope = MIN_GRENADE_SLOPE;
} else if (slope > MAX_GRENADE_SLOPE) {
slope = MAX_GRENADE_SLOPE;
}

v_components = normalize([1, 0, slope]) * speed;

vel_0 = v_components_x * normalize(disp);
vel_0_z = v_components_z;

return vel_0;
}

/*
================
OgreFireGrenade
================
*/
void(float hopup) OgreFireGrenade =
void(float grenade_speed) OgreFireGrenade =
{
entity missile;

Expand All @@ -126,9 +166,15 @@ void(float hopup) OgreFireGrenade =

makevectors(self.angles);

missile.velocity = normalize(self.enemy.origin - self.origin);
missile.velocity = missile.velocity * 600;
missile.velocity_z = 200 + hopup;
//missile.velocity = normalize(self.enemy.origin - self.origin);
//missile.velocity = missile.velocity * 600;
//missile.velocity_z = 200 + hopup;

missile.velocity = ArcTo(
self.origin,
self.enemy.origin + '0 0 16',
grenade_speed
);

missile.avelocity = '300 300 300';

Expand Down Expand Up @@ -324,7 +370,7 @@ void() ogre_nail3 = [ $shoot2, ogre_nail4 ] { ai_face(); };
//void() ogre_nail4 = [ $shoot3, ogre_nail5 ] { ai_face(); OgreFireGrenade(); };
void() ogre_nail4 = {
self.frame = $shoot3;
ai_face(); OgreFireGrenade(0);
ai_face(); OgreFireGrenade(630);
self.nextthink = time + 0.1;
if (skill > 2) {
self.think = ogre_burst1;
Expand All @@ -338,7 +384,7 @@ void() ogre_nail7 = [ $shoot6, ogre_run1 ] { ai_face(); };

void() ogre_burst1 = [ $shoot2, ogre_burst2 ] { ai_face(); };
void() ogre_burst2 = [ $shoot2, ogre_burst3 ] { ai_face(); };
void() ogre_burst3 = [ $shoot3, ogre_nail5 ] { ai_face(); OgreFireGrenade(40); };
void() ogre_burst3 = [ $shoot3, ogre_nail5 ] { ai_face(); OgreFireGrenade(700); };

void() ogre_pain1 = [ $pain1, ogre_pain2 ] {};
void() ogre_pain2 = [ $pain2, ogre_pain3 ] {};
Expand Down
1 change: 1 addition & 0 deletions world.qc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ void() StartFrame =
{
teamplay = cvar("teamplay");
skill = cvar("skill");
gravity = cvar("sv_gravity");
framecount = framecount + 1;
};

Expand Down

0 comments on commit 79c431b

Please sign in to comment.