Merge pull request #1 from jonathangray/initial_port

Initial port of Jedi Outcast back to gcc/unix
This commit is contained in:
Zachary J. Slater 2013-04-23 11:29:25 -07:00
commit bb3b296c0b
1778 changed files with 1174000 additions and 1173371 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,129 +1,129 @@
#include "q_shared.h"
#include <float.h>
angles_t ang_zero( 0.0f, 0.0f, 0.0f );
void toAngles( mat3_t &src, angles_t &dst ) {
double theta;
double cp;
double sp;
sp = src[ 0 ][ 2 ];
// cap off our sin value so that we don't get any NANs
if ( sp > 1.0 ) {
sp = 1.0;
} else if ( sp < -1.0 ) {
sp = -1.0;
}
theta = -asin( sp );
cp = cos( theta );
if ( cp > 8192 * FLT_EPSILON ) {
dst.pitch = theta * 180 / M_PI;
dst.yaw = atan2( src[ 0 ][ 1 ], src[ 0 ][ 0 ] ) * 180 / M_PI;
dst.roll = atan2( src[ 1 ][ 2 ], src[ 2 ][ 2 ] ) * 180 / M_PI;
} else {
dst.pitch = theta * 180 / M_PI;
dst.yaw = -atan2( src[ 1 ][ 0 ], src[ 1 ][ 1 ] ) * 180 / M_PI;
dst.roll = 0;
}
}
void toAngles( quat_t &src, angles_t &dst ) {
mat3_t temp;
toMatrix( src, temp );
toAngles( temp, dst );
}
void toAngles( idVec3_t &src, angles_t &dst ) {
dst.pitch = src[ 0 ];
dst.yaw = src[ 1 ];
dst.roll = src[ 2 ];
}
void angles_t::toVectors( idVec3_t *forward, idVec3_t *right, idVec3_t *up ) {
float angle;
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
angle = yaw * ( M_PI * 2 / 360 );
sy = sin( angle );
cy = cos( angle );
angle = pitch * ( M_PI * 2 / 360 );
sp = sin( angle );
cp = cos( angle );
angle = roll * ( M_PI * 2 / 360 );
sr = sin( angle );
cr = cos( angle );
if ( forward ) {
forward->set( cp * cy, cp * sy, -sp );
}
if ( right ) {
right->set( -sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp );
}
if ( up ) {
up->set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
}
}
idVec3_t angles_t::toForward( void ) {
float angle;
static float sp, sy, cp, cy; // static to help MS compiler fp bugs
angle = yaw * ( M_PI * 2 / 360 );
sy = sin( angle );
cy = cos( angle );
angle = pitch * ( M_PI * 2 / 360 );
sp = sin( angle );
cp = cos( angle );
return idVec3_t( cp * cy, cp * sy, -sp );
}
/*
=================
Normalize360
returns angles normalized to the range [0 <= angle < 360]
=================
*/
angles_t& angles_t::Normalize360( void ) {
pitch = (360.0 / 65536) * ( ( int )( pitch * ( 65536 / 360.0 ) ) & 65535 );
yaw = (360.0 / 65536) * ( ( int )( yaw * ( 65536 / 360.0 ) ) & 65535 );
roll = (360.0 / 65536) * ( ( int )( roll * ( 65536 / 360.0 ) ) & 65535 );
return *this;
}
/*
=================
Normalize180
returns angles normalized to the range [-180 < angle <= 180]
=================
*/
angles_t& angles_t::Normalize180( void ) {
Normalize360();
if ( pitch > 180.0 ) {
pitch -= 360.0;
}
if ( yaw > 180.0 ) {
yaw -= 360.0;
}
if ( roll > 180.0 ) {
roll -= 360.0;
}
return *this;
}
#include "q_shared.h"
#include <float.h>
angles_t ang_zero( 0.0f, 0.0f, 0.0f );
void toAngles( mat3_t &src, angles_t &dst ) {
double theta;
double cp;
double sp;
sp = src[ 0 ][ 2 ];
// cap off our sin value so that we don't get any NANs
if ( sp > 1.0 ) {
sp = 1.0;
} else if ( sp < -1.0 ) {
sp = -1.0;
}
theta = -asin( sp );
cp = cos( theta );
if ( cp > 8192 * FLT_EPSILON ) {
dst.pitch = theta * 180 / M_PI;
dst.yaw = atan2( src[ 0 ][ 1 ], src[ 0 ][ 0 ] ) * 180 / M_PI;
dst.roll = atan2( src[ 1 ][ 2 ], src[ 2 ][ 2 ] ) * 180 / M_PI;
} else {
dst.pitch = theta * 180 / M_PI;
dst.yaw = -atan2( src[ 1 ][ 0 ], src[ 1 ][ 1 ] ) * 180 / M_PI;
dst.roll = 0;
}
}
void toAngles( quat_t &src, angles_t &dst ) {
mat3_t temp;
toMatrix( src, temp );
toAngles( temp, dst );
}
void toAngles( idVec3_t &src, angles_t &dst ) {
dst.pitch = src[ 0 ];
dst.yaw = src[ 1 ];
dst.roll = src[ 2 ];
}
void angles_t::toVectors( idVec3_t *forward, idVec3_t *right, idVec3_t *up ) {
float angle;
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
angle = yaw * ( M_PI * 2 / 360 );
sy = sin( angle );
cy = cos( angle );
angle = pitch * ( M_PI * 2 / 360 );
sp = sin( angle );
cp = cos( angle );
angle = roll * ( M_PI * 2 / 360 );
sr = sin( angle );
cr = cos( angle );
if ( forward ) {
forward->set( cp * cy, cp * sy, -sp );
}
if ( right ) {
right->set( -sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp );
}
if ( up ) {
up->set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
}
}
idVec3_t angles_t::toForward( void ) {
float angle;
static float sp, sy, cp, cy; // static to help MS compiler fp bugs
angle = yaw * ( M_PI * 2 / 360 );
sy = sin( angle );
cy = cos( angle );
angle = pitch * ( M_PI * 2 / 360 );
sp = sin( angle );
cp = cos( angle );
return idVec3_t( cp * cy, cp * sy, -sp );
}
/*
=================
Normalize360
returns angles normalized to the range [0 <= angle < 360]
=================
*/
angles_t& angles_t::Normalize360( void ) {
pitch = (360.0 / 65536) * ( ( int )( pitch * ( 65536 / 360.0 ) ) & 65535 );
yaw = (360.0 / 65536) * ( ( int )( yaw * ( 65536 / 360.0 ) ) & 65535 );
roll = (360.0 / 65536) * ( ( int )( roll * ( 65536 / 360.0 ) ) & 65535 );
return *this;
}
/*
=================
Normalize180
returns angles normalized to the range [-180 < angle <= 180]
=================
*/
angles_t& angles_t::Normalize180( void ) {
Normalize360();
if ( pitch > 180.0 ) {
pitch -= 360.0;
}
if ( yaw > 180.0 ) {
yaw -= 360.0;
}
if ( roll > 180.0 ) {
roll -= 360.0;
}
return *this;
}

View File

@ -1,174 +1,174 @@
#ifndef __MATH_ANGLES_H__
#define __MATH_ANGLES_H__
#include <stdlib.h>
#include <assert.h>
#include "math_vector.h"
class mat3_t;
class quat_t;
class idVec3_t;
typedef idVec3_t &vec3_p;
class angles_t {
public:
float pitch;
float yaw;
float roll;
angles_t();
angles_t( float pitch, float yaw, float roll );
angles_t( const idVec3_t &vec );
friend void toAngles( idVec3_t &src, angles_t &dst );
friend void toAngles( quat_t &src, angles_t &dst );
friend void toAngles( mat3_t &src, angles_t &dst );
operator vec3_p();
float operator[]( int index ) const;
float& operator[]( int index );
void set( float pitch, float yaw, float roll );
void operator=( angles_t const &a );
void operator=( idVec3_t const &a );
friend angles_t operator+( const angles_t &a, const angles_t &b );
angles_t &operator+=( angles_t const &a );
angles_t &operator+=( idVec3_t const &a );
friend angles_t operator-( angles_t &a, angles_t &b );
angles_t &operator-=( angles_t &a );
friend angles_t operator*( const angles_t &a, float b );
friend angles_t operator*( float a, const angles_t &b );
angles_t &operator*=( float a );
friend int operator==( angles_t &a, angles_t &b );
friend int operator!=( angles_t &a, angles_t &b );
void toVectors( idVec3_t *forward, idVec3_t *right = NULL, idVec3_t *up = NULL );
idVec3_t toForward( void );
angles_t &Zero( void );
angles_t &Normalize360( void );
angles_t &Normalize180( void );
};
extern angles_t ang_zero;
inline angles_t::angles_t() {}
inline angles_t::angles_t( float pitch, float yaw, float roll ) {
this->pitch = pitch;
this->yaw = yaw;
this->roll = roll;
}
inline angles_t::angles_t( const idVec3_t &vec ) {
this->pitch = vec.x;
this->yaw = vec.y;
this->roll = vec.z;
}
inline float angles_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 3 ) );
return ( &pitch )[ index ];
}
inline float& angles_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 3 ) );
return ( &pitch )[ index ];
}
inline angles_t::operator vec3_p( void ) {
return *( idVec3_t * )&pitch;
}
inline void angles_t::set( float pitch, float yaw, float roll ) {
this->pitch = pitch;
this->yaw = yaw;
this->roll = roll;
}
inline void angles_t::operator=( angles_t const &a ) {
pitch = a.pitch;
yaw = a.yaw;
roll = a.roll;
}
inline void angles_t::operator=( idVec3_t const &a ) {
pitch = a[ 0 ];
yaw = a[ 1 ];
roll = a[ 2 ];
}
inline angles_t operator+( const angles_t &a, const angles_t &b ) {
return angles_t( a.pitch + b.pitch, a.yaw + b.yaw, a.roll + b.roll );
}
inline angles_t& angles_t::operator+=( angles_t const &a ) {
pitch += a.pitch;
yaw += a.yaw;
roll += a.roll;
return *this;
}
inline angles_t& angles_t::operator+=( idVec3_t const &a ) {
pitch += a.x;
yaw += a.y;
roll += a.z;
return *this;
}
inline angles_t operator-( angles_t &a, angles_t &b ) {
return angles_t( a.pitch - b.pitch, a.yaw - b.yaw, a.roll - b.roll );
}
inline angles_t& angles_t::operator-=( angles_t &a ) {
pitch -= a.pitch;
yaw -= a.yaw;
roll -= a.roll;
return *this;
}
inline angles_t operator*( const angles_t &a, float b ) {
return angles_t( a.pitch * b, a.yaw * b, a.roll * b );
}
inline angles_t operator*( float a, const angles_t &b ) {
return angles_t( a * b.pitch, a * b.yaw, a * b.roll );
}
inline angles_t& angles_t::operator*=( float a ) {
pitch *= a;
yaw *= a;
roll *= a;
return *this;
}
inline int operator==( angles_t &a, angles_t &b ) {
return ( ( a.pitch == b.pitch ) && ( a.yaw == b.yaw ) && ( a.roll == b.roll ) );
}
inline int operator!=( angles_t &a, angles_t &b ) {
return ( ( a.pitch != b.pitch ) || ( a.yaw != b.yaw ) || ( a.roll != b.roll ) );
}
inline angles_t& angles_t::Zero( void ) {
pitch = 0.0f;
yaw = 0.0f;
roll = 0.0f;
return *this;
}
#endif /* !__MATH_ANGLES_H__ */
#ifndef __MATH_ANGLES_H__
#define __MATH_ANGLES_H__
#include <stdlib.h>
#include <assert.h>
#include "math_vector.h"
class mat3_t;
class quat_t;
class idVec3_t;
typedef idVec3_t &vec3_p;
class angles_t {
public:
float pitch;
float yaw;
float roll;
angles_t();
angles_t( float pitch, float yaw, float roll );
angles_t( const idVec3_t &vec );
friend void toAngles( idVec3_t &src, angles_t &dst );
friend void toAngles( quat_t &src, angles_t &dst );
friend void toAngles( mat3_t &src, angles_t &dst );
operator vec3_p();
float operator[]( int index ) const;
float& operator[]( int index );
void set( float pitch, float yaw, float roll );
void operator=( angles_t const &a );
void operator=( idVec3_t const &a );
friend angles_t operator+( const angles_t &a, const angles_t &b );
angles_t &operator+=( angles_t const &a );
angles_t &operator+=( idVec3_t const &a );
friend angles_t operator-( angles_t &a, angles_t &b );
angles_t &operator-=( angles_t &a );
friend angles_t operator*( const angles_t &a, float b );
friend angles_t operator*( float a, const angles_t &b );
angles_t &operator*=( float a );
friend int operator==( angles_t &a, angles_t &b );
friend int operator!=( angles_t &a, angles_t &b );
void toVectors( idVec3_t *forward, idVec3_t *right = NULL, idVec3_t *up = NULL );
idVec3_t toForward( void );
angles_t &Zero( void );
angles_t &Normalize360( void );
angles_t &Normalize180( void );
};
extern angles_t ang_zero;
inline angles_t::angles_t() {}
inline angles_t::angles_t( float pitch, float yaw, float roll ) {
this->pitch = pitch;
this->yaw = yaw;
this->roll = roll;
}
inline angles_t::angles_t( const idVec3_t &vec ) {
this->pitch = vec.x;
this->yaw = vec.y;
this->roll = vec.z;
}
inline float angles_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 3 ) );
return ( &pitch )[ index ];
}
inline float& angles_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 3 ) );
return ( &pitch )[ index ];
}
inline angles_t::operator vec3_p( void ) {
return *( idVec3_t * )&pitch;
}
inline void angles_t::set( float pitch, float yaw, float roll ) {
this->pitch = pitch;
this->yaw = yaw;
this->roll = roll;
}
inline void angles_t::operator=( angles_t const &a ) {
pitch = a.pitch;
yaw = a.yaw;
roll = a.roll;
}
inline void angles_t::operator=( idVec3_t const &a ) {
pitch = a[ 0 ];
yaw = a[ 1 ];
roll = a[ 2 ];
}
inline angles_t operator+( const angles_t &a, const angles_t &b ) {
return angles_t( a.pitch + b.pitch, a.yaw + b.yaw, a.roll + b.roll );
}
inline angles_t& angles_t::operator+=( angles_t const &a ) {
pitch += a.pitch;
yaw += a.yaw;
roll += a.roll;
return *this;
}
inline angles_t& angles_t::operator+=( idVec3_t const &a ) {
pitch += a.x;
yaw += a.y;
roll += a.z;
return *this;
}
inline angles_t operator-( angles_t &a, angles_t &b ) {
return angles_t( a.pitch - b.pitch, a.yaw - b.yaw, a.roll - b.roll );
}
inline angles_t& angles_t::operator-=( angles_t &a ) {
pitch -= a.pitch;
yaw -= a.yaw;
roll -= a.roll;
return *this;
}
inline angles_t operator*( const angles_t &a, float b ) {
return angles_t( a.pitch * b, a.yaw * b, a.roll * b );
}
inline angles_t operator*( float a, const angles_t &b ) {
return angles_t( a * b.pitch, a * b.yaw, a * b.roll );
}
inline angles_t& angles_t::operator*=( float a ) {
pitch *= a;
yaw *= a;
roll *= a;
return *this;
}
inline int operator==( angles_t &a, angles_t &b ) {
return ( ( a.pitch == b.pitch ) && ( a.yaw == b.yaw ) && ( a.roll == b.roll ) );
}
inline int operator!=( angles_t &a, angles_t &b ) {
return ( ( a.pitch != b.pitch ) || ( a.yaw != b.yaw ) || ( a.roll != b.roll ) );
}
inline angles_t& angles_t::Zero( void ) {
pitch = 0.0f;
yaw = 0.0f;
roll = 0.0f;
return *this;
}
#endif /* !__MATH_ANGLES_H__ */

View File

@ -1,113 +1,113 @@
#include "q_shared.h"
mat3_t mat3_default( idVec3_t( 1, 0, 0 ), idVec3_t( 0, 1, 0 ), idVec3_t( 0, 0, 1 ) );
void toMatrix( quat_t const &src, mat3_t &dst ) {
float wx, wy, wz;
float xx, yy, yz;
float xy, xz, zz;
float x2, y2, z2;
x2 = src.x + src.x;
y2 = src.y + src.y;
z2 = src.z + src.z;
xx = src.x * x2;
xy = src.x * y2;
xz = src.x * z2;
yy = src.y * y2;
yz = src.y * z2;
zz = src.z * z2;
wx = src.w * x2;
wy = src.w * y2;
wz = src.w * z2;
dst[ 0 ][ 0 ] = 1.0f - ( yy + zz );
dst[ 0 ][ 1 ] = xy - wz;
dst[ 0 ][ 2 ] = xz + wy;
dst[ 1 ][ 0 ] = xy + wz;
dst[ 1 ][ 1 ] = 1.0f - ( xx + zz );
dst[ 1 ][ 2 ] = yz - wx;
dst[ 2 ][ 0 ] = xz - wy;
dst[ 2 ][ 1 ] = yz + wx;
dst[ 2 ][ 2 ] = 1.0f - ( xx + yy );
}
void toMatrix( angles_t const &src, mat3_t &dst ) {
float angle;
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
angle = src.yaw * ( M_PI * 2.0f / 360.0f );
sy = sin( angle );
cy = cos( angle );
angle = src.pitch * ( M_PI * 2.0f / 360.0f );
sp = sin( angle );
cp = cos( angle );
angle = src.roll * ( M_PI * 2.0f / 360.0f );
sr = sin( angle );
cr = cos( angle );
dst[ 0 ].set( cp * cy, cp * sy, -sp );
dst[ 1 ].set( sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp );
dst[ 2 ].set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
}
void toMatrix( idVec3_t const &src, mat3_t &dst ) {
angles_t sup = src;
toMatrix(sup, dst);
}
void mat3_t::ProjectVector( const idVec3_t &src, idVec3_t &dst ) const {
dst.x = src * mat[ 0 ];
dst.y = src * mat[ 1 ];
dst.z = src * mat[ 2 ];
}
void mat3_t::UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const {
dst = mat[ 0 ] * src.x + mat[ 1 ] * src.y + mat[ 2 ] * src.z;
}
void mat3_t::Transpose( mat3_t &matrix ) {
int i;
int j;
for( i = 0; i < 3; i++ ) {
for( j = 0; j < 3; j++ ) {
matrix[ i ][ j ] = mat[ j ][ i ];
}
}
}
void mat3_t::Transpose( void ) {
float temp;
int i;
int j;
for( i = 0; i < 3; i++ ) {
for( j = i + 1; j < 3; j++ ) {
temp = mat[ i ][ j ];
mat[ i ][ j ] = mat[ j ][ i ];
mat[ j ][ i ] = temp;
}
}
}
mat3_t mat3_t::Inverse( void ) const {
mat3_t inv( *this );
inv.Transpose();
return inv;
}
void mat3_t::Clear( void ) {
mat[0].set( 1, 0, 0 );
mat[1].set( 0, 1, 0 );
mat[2].set( 0, 0, 1 );
}
#include "q_shared.h"
mat3_t mat3_default( idVec3_t( 1, 0, 0 ), idVec3_t( 0, 1, 0 ), idVec3_t( 0, 0, 1 ) );
void toMatrix( quat_t const &src, mat3_t &dst ) {
float wx, wy, wz;
float xx, yy, yz;
float xy, xz, zz;
float x2, y2, z2;
x2 = src.x + src.x;
y2 = src.y + src.y;
z2 = src.z + src.z;
xx = src.x * x2;
xy = src.x * y2;
xz = src.x * z2;
yy = src.y * y2;
yz = src.y * z2;
zz = src.z * z2;
wx = src.w * x2;
wy = src.w * y2;
wz = src.w * z2;
dst[ 0 ][ 0 ] = 1.0f - ( yy + zz );
dst[ 0 ][ 1 ] = xy - wz;
dst[ 0 ][ 2 ] = xz + wy;
dst[ 1 ][ 0 ] = xy + wz;
dst[ 1 ][ 1 ] = 1.0f - ( xx + zz );
dst[ 1 ][ 2 ] = yz - wx;
dst[ 2 ][ 0 ] = xz - wy;
dst[ 2 ][ 1 ] = yz + wx;
dst[ 2 ][ 2 ] = 1.0f - ( xx + yy );
}
void toMatrix( angles_t const &src, mat3_t &dst ) {
float angle;
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
angle = src.yaw * ( M_PI * 2.0f / 360.0f );
sy = sin( angle );
cy = cos( angle );
angle = src.pitch * ( M_PI * 2.0f / 360.0f );
sp = sin( angle );
cp = cos( angle );
angle = src.roll * ( M_PI * 2.0f / 360.0f );
sr = sin( angle );
cr = cos( angle );
dst[ 0 ].set( cp * cy, cp * sy, -sp );
dst[ 1 ].set( sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp );
dst[ 2 ].set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
}
void toMatrix( idVec3_t const &src, mat3_t &dst ) {
angles_t sup = src;
toMatrix(sup, dst);
}
void mat3_t::ProjectVector( const idVec3_t &src, idVec3_t &dst ) const {
dst.x = src * mat[ 0 ];
dst.y = src * mat[ 1 ];
dst.z = src * mat[ 2 ];
}
void mat3_t::UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const {
dst = mat[ 0 ] * src.x + mat[ 1 ] * src.y + mat[ 2 ] * src.z;
}
void mat3_t::Transpose( mat3_t &matrix ) {
int i;
int j;
for( i = 0; i < 3; i++ ) {
for( j = 0; j < 3; j++ ) {
matrix[ i ][ j ] = mat[ j ][ i ];
}
}
}
void mat3_t::Transpose( void ) {
float temp;
int i;
int j;
for( i = 0; i < 3; i++ ) {
for( j = i + 1; j < 3; j++ ) {
temp = mat[ i ][ j ];
mat[ i ][ j ] = mat[ j ][ i ];
mat[ j ][ i ] = temp;
}
}
}
mat3_t mat3_t::Inverse( void ) const {
mat3_t inv( *this );
inv.Transpose();
return inv;
}
void mat3_t::Clear( void ) {
mat[0].set( 1, 0, 0 );
mat[1].set( 0, 1, 0 );
mat[2].set( 0, 0, 1 );
}

View File

@ -1,202 +1,202 @@
#ifndef __MATH_MATRIX_H__
#define __MATH_MATRIX_H__
#include <string.h>
#include "math_vector.h"
#ifndef ID_INLINE
#ifdef _WIN32
#define ID_INLINE __inline
#else
#define ID_INLINE inline
#endif
#endif
class quat_t;
class angles_t;
class mat3_t {
public:
idVec3_t mat[ 3 ];
mat3_t();
mat3_t( float src[ 3 ][ 3 ] );
mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z );
mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz );
friend void toMatrix( quat_t const &src, mat3_t &dst );
friend void toMatrix( angles_t const &src, mat3_t &dst );
friend void toMatrix( idVec3_t const &src, mat3_t &dst );
idVec3_t operator[]( int index ) const;
idVec3_t &operator[]( int index );
idVec3_t operator*( const idVec3_t &vec ) const;
mat3_t operator*( const mat3_t &a ) const;
mat3_t operator*( float a ) const;
mat3_t operator+( mat3_t const &a ) const;
mat3_t operator-( mat3_t const &a ) const;
friend idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat );
friend mat3_t operator*( float a, mat3_t const &b );
mat3_t &operator*=( float a );
mat3_t &operator+=( mat3_t const &a );
mat3_t &operator-=( mat3_t const &a );
void Clear( void );
void ProjectVector( const idVec3_t &src, idVec3_t &dst ) const;
void UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const;
void OrthoNormalize( void );
void Transpose( mat3_t &matrix );
void Transpose( void );
mat3_t Inverse( void ) const;
void Identity( void );
friend void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst );
friend mat3_t SkewSymmetric( idVec3_t const &src );
};
ID_INLINE mat3_t::mat3_t() {
}
ID_INLINE mat3_t::mat3_t( float src[ 3 ][ 3 ] ) {
memcpy( mat, src, sizeof( src ) );
}
ID_INLINE mat3_t::mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z ) {
mat[ 0 ].x = x.x; mat[ 0 ].y = x.y; mat[ 0 ].z = x.z;
mat[ 1 ].x = y.x; mat[ 1 ].y = y.y; mat[ 1 ].z = y.z;
mat[ 2 ].x = z.x; mat[ 2 ].y = z.y; mat[ 2 ].z = z.z;
}
ID_INLINE mat3_t::mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz ) {
mat[ 0 ].x = xx; mat[ 0 ].y = xy; mat[ 0 ].z = xz;
mat[ 1 ].x = yx; mat[ 1 ].y = yy; mat[ 1 ].z = yz;
mat[ 2 ].x = zx; mat[ 2 ].y = zy; mat[ 2 ].z = zz;
}
ID_INLINE idVec3_t mat3_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 3 ) );
return mat[ index ];
}
ID_INLINE idVec3_t& mat3_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 3 ) );
return mat[ index ];
}
ID_INLINE idVec3_t mat3_t::operator*( const idVec3_t &vec ) const {
return idVec3_t(
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
}
ID_INLINE mat3_t mat3_t::operator*( const mat3_t &a ) const {
return mat3_t(
mat[0].x * a[0].x + mat[0].y * a[1].x + mat[0].z * a[2].x,
mat[0].x * a[0].y + mat[0].y * a[1].y + mat[0].z * a[2].y,
mat[0].x * a[0].z + mat[0].y * a[1].z + mat[0].z * a[2].z,
mat[1].x * a[0].x + mat[1].y * a[1].x + mat[1].z * a[2].x,
mat[1].x * a[0].y + mat[1].y * a[1].y + mat[1].z * a[2].y,
mat[1].x * a[0].z + mat[1].y * a[1].z + mat[1].z * a[2].z,
mat[2].x * a[0].x + mat[2].y * a[1].x + mat[2].z * a[2].x,
mat[2].x * a[0].y + mat[2].y * a[1].y + mat[2].z * a[2].y,
mat[2].x * a[0].z + mat[2].y * a[1].z + mat[2].z * a[2].z );
}
ID_INLINE mat3_t mat3_t::operator*( float a ) const {
return mat3_t(
mat[0].x * a, mat[0].y * a, mat[0].z * a,
mat[1].x * a, mat[1].y * a, mat[1].z * a,
mat[2].x * a, mat[2].y * a, mat[2].z * a );
}
ID_INLINE mat3_t mat3_t::operator+( mat3_t const &a ) const {
return mat3_t(
mat[0].x + a[0].x, mat[0].y + a[0].y, mat[0].z + a[0].z,
mat[1].x + a[1].x, mat[1].y + a[1].y, mat[1].z + a[1].z,
mat[2].x + a[2].x, mat[2].y + a[2].y, mat[2].z + a[2].z );
}
ID_INLINE mat3_t mat3_t::operator-( mat3_t const &a ) const {
return mat3_t(
mat[0].x - a[0].x, mat[0].y - a[0].y, mat[0].z - a[0].z,
mat[1].x - a[1].x, mat[1].y - a[1].y, mat[1].z - a[1].z,
mat[2].x - a[2].x, mat[2].y - a[2].y, mat[2].z - a[2].z );
}
ID_INLINE idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat ) {
return idVec3_t(
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
}
ID_INLINE mat3_t operator*( float a, mat3_t const &b ) {
return mat3_t(
b[0].x * a, b[0].y * a, b[0].z * a,
b[1].x * a, b[1].y * a, b[1].z * a,
b[2].x * a, b[2].y * a, b[2].z * a );
}
ID_INLINE mat3_t &mat3_t::operator*=( float a ) {
mat[0].x *= a; mat[0].y *= a; mat[0].z *= a;
mat[1].x *= a; mat[1].y *= a; mat[1].z *= a;
mat[2].x *= a; mat[2].y *= a; mat[2].z *= a;
return *this;
}
ID_INLINE mat3_t &mat3_t::operator+=( mat3_t const &a ) {
mat[0].x += a[0].x; mat[0].y += a[0].y; mat[0].z += a[0].z;
mat[1].x += a[1].x; mat[1].y += a[1].y; mat[1].z += a[1].z;
mat[2].x += a[2].x; mat[2].y += a[2].y; mat[2].z += a[2].z;
return *this;
}
ID_INLINE mat3_t &mat3_t::operator-=( mat3_t const &a ) {
mat[0].x -= a[0].x; mat[0].y -= a[0].y; mat[0].z -= a[0].z;
mat[1].x -= a[1].x; mat[1].y -= a[1].y; mat[1].z -= a[1].z;
mat[2].x -= a[2].x; mat[2].y -= a[2].y; mat[2].z -= a[2].z;
return *this;
}
ID_INLINE void mat3_t::OrthoNormalize( void ) {
mat[ 0 ].Normalize();
mat[ 2 ].Cross( mat[ 0 ], mat[ 1 ] );
mat[ 2 ].Normalize();
mat[ 1 ].Cross( mat[ 2 ], mat[ 0 ] );
mat[ 1 ].Normalize();
}
ID_INLINE void mat3_t::Identity( void ) {
mat[ 0 ].x = 1.f; mat[ 0 ].y = 0.f; mat[ 0 ].z = 0.f;
mat[ 1 ].x = 0.f; mat[ 1 ].y = 1.f; mat[ 1 ].z = 0.f;
mat[ 2 ].x = 0.f; mat[ 2 ].y = 0.f; mat[ 2 ].z = 1.f;
}
ID_INLINE void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst ) {
dst[0].x = inv[0].x * b[0].x + inv[1].x * b[1].x + inv[2].x * b[2].x;
dst[0].y = inv[0].x * b[0].y + inv[1].x * b[1].y + inv[2].x * b[2].y;
dst[0].z = inv[0].x * b[0].z + inv[1].x * b[1].z + inv[2].x * b[2].z;
dst[1].x = inv[0].y * b[0].x + inv[1].y * b[1].x + inv[2].y * b[2].x;
dst[1].y = inv[0].y * b[0].y + inv[1].y * b[1].y + inv[2].y * b[2].y;
dst[1].z = inv[0].y * b[0].z + inv[1].y * b[1].z + inv[2].y * b[2].z;
dst[2].x = inv[0].z * b[0].x + inv[1].z * b[1].x + inv[2].z * b[2].x;
dst[2].y = inv[0].z * b[0].y + inv[1].z * b[1].y + inv[2].z * b[2].y;
dst[2].z = inv[0].z * b[0].z + inv[1].z * b[1].z + inv[2].z * b[2].z;
}
ID_INLINE mat3_t SkewSymmetric( idVec3_t const &src ) {
return mat3_t( 0.0f, -src.z, src.y, src.z, 0.0f, -src.x, -src.y, src.x, 0.0f );
}
extern mat3_t mat3_default;
#endif /* !__MATH_MATRIX_H__ */
#ifndef __MATH_MATRIX_H__
#define __MATH_MATRIX_H__
#include <string.h>
#include "math_vector.h"
#ifndef ID_INLINE
#ifdef _WIN32
#define ID_INLINE __inline
#else
#define ID_INLINE inline
#endif
#endif
class quat_t;
class angles_t;
class mat3_t {
public:
idVec3_t mat[ 3 ];
mat3_t();
mat3_t( float src[ 3 ][ 3 ] );
mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z );
mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz );
friend void toMatrix( quat_t const &src, mat3_t &dst );
friend void toMatrix( angles_t const &src, mat3_t &dst );
friend void toMatrix( idVec3_t const &src, mat3_t &dst );
idVec3_t operator[]( int index ) const;
idVec3_t &operator[]( int index );
idVec3_t operator*( const idVec3_t &vec ) const;
mat3_t operator*( const mat3_t &a ) const;
mat3_t operator*( float a ) const;
mat3_t operator+( mat3_t const &a ) const;
mat3_t operator-( mat3_t const &a ) const;
friend idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat );
friend mat3_t operator*( float a, mat3_t const &b );
mat3_t &operator*=( float a );
mat3_t &operator+=( mat3_t const &a );
mat3_t &operator-=( mat3_t const &a );
void Clear( void );
void ProjectVector( const idVec3_t &src, idVec3_t &dst ) const;
void UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const;
void OrthoNormalize( void );
void Transpose( mat3_t &matrix );
void Transpose( void );
mat3_t Inverse( void ) const;
void Identity( void );
friend void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst );
friend mat3_t SkewSymmetric( idVec3_t const &src );
};
ID_INLINE mat3_t::mat3_t() {
}
ID_INLINE mat3_t::mat3_t( float src[ 3 ][ 3 ] ) {
memcpy( mat, src, sizeof( src ) );
}
ID_INLINE mat3_t::mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z ) {
mat[ 0 ].x = x.x; mat[ 0 ].y = x.y; mat[ 0 ].z = x.z;
mat[ 1 ].x = y.x; mat[ 1 ].y = y.y; mat[ 1 ].z = y.z;
mat[ 2 ].x = z.x; mat[ 2 ].y = z.y; mat[ 2 ].z = z.z;
}
ID_INLINE mat3_t::mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz ) {
mat[ 0 ].x = xx; mat[ 0 ].y = xy; mat[ 0 ].z = xz;
mat[ 1 ].x = yx; mat[ 1 ].y = yy; mat[ 1 ].z = yz;
mat[ 2 ].x = zx; mat[ 2 ].y = zy; mat[ 2 ].z = zz;
}
ID_INLINE idVec3_t mat3_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 3 ) );
return mat[ index ];
}
ID_INLINE idVec3_t& mat3_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 3 ) );
return mat[ index ];
}
ID_INLINE idVec3_t mat3_t::operator*( const idVec3_t &vec ) const {
return idVec3_t(
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
}
ID_INLINE mat3_t mat3_t::operator*( const mat3_t &a ) const {
return mat3_t(
mat[0].x * a[0].x + mat[0].y * a[1].x + mat[0].z * a[2].x,
mat[0].x * a[0].y + mat[0].y * a[1].y + mat[0].z * a[2].y,
mat[0].x * a[0].z + mat[0].y * a[1].z + mat[0].z * a[2].z,
mat[1].x * a[0].x + mat[1].y * a[1].x + mat[1].z * a[2].x,
mat[1].x * a[0].y + mat[1].y * a[1].y + mat[1].z * a[2].y,
mat[1].x * a[0].z + mat[1].y * a[1].z + mat[1].z * a[2].z,
mat[2].x * a[0].x + mat[2].y * a[1].x + mat[2].z * a[2].x,
mat[2].x * a[0].y + mat[2].y * a[1].y + mat[2].z * a[2].y,
mat[2].x * a[0].z + mat[2].y * a[1].z + mat[2].z * a[2].z );
}
ID_INLINE mat3_t mat3_t::operator*( float a ) const {
return mat3_t(
mat[0].x * a, mat[0].y * a, mat[0].z * a,
mat[1].x * a, mat[1].y * a, mat[1].z * a,
mat[2].x * a, mat[2].y * a, mat[2].z * a );
}
ID_INLINE mat3_t mat3_t::operator+( mat3_t const &a ) const {
return mat3_t(
mat[0].x + a[0].x, mat[0].y + a[0].y, mat[0].z + a[0].z,
mat[1].x + a[1].x, mat[1].y + a[1].y, mat[1].z + a[1].z,
mat[2].x + a[2].x, mat[2].y + a[2].y, mat[2].z + a[2].z );
}
ID_INLINE mat3_t mat3_t::operator-( mat3_t const &a ) const {
return mat3_t(
mat[0].x - a[0].x, mat[0].y - a[0].y, mat[0].z - a[0].z,
mat[1].x - a[1].x, mat[1].y - a[1].y, mat[1].z - a[1].z,
mat[2].x - a[2].x, mat[2].y - a[2].y, mat[2].z - a[2].z );
}
ID_INLINE idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat ) {
return idVec3_t(
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
}
ID_INLINE mat3_t operator*( float a, mat3_t const &b ) {
return mat3_t(
b[0].x * a, b[0].y * a, b[0].z * a,
b[1].x * a, b[1].y * a, b[1].z * a,
b[2].x * a, b[2].y * a, b[2].z * a );
}
ID_INLINE mat3_t &mat3_t::operator*=( float a ) {
mat[0].x *= a; mat[0].y *= a; mat[0].z *= a;
mat[1].x *= a; mat[1].y *= a; mat[1].z *= a;
mat[2].x *= a; mat[2].y *= a; mat[2].z *= a;
return *this;
}
ID_INLINE mat3_t &mat3_t::operator+=( mat3_t const &a ) {
mat[0].x += a[0].x; mat[0].y += a[0].y; mat[0].z += a[0].z;
mat[1].x += a[1].x; mat[1].y += a[1].y; mat[1].z += a[1].z;
mat[2].x += a[2].x; mat[2].y += a[2].y; mat[2].z += a[2].z;
return *this;
}
ID_INLINE mat3_t &mat3_t::operator-=( mat3_t const &a ) {
mat[0].x -= a[0].x; mat[0].y -= a[0].y; mat[0].z -= a[0].z;
mat[1].x -= a[1].x; mat[1].y -= a[1].y; mat[1].z -= a[1].z;
mat[2].x -= a[2].x; mat[2].y -= a[2].y; mat[2].z -= a[2].z;
return *this;
}
ID_INLINE void mat3_t::OrthoNormalize( void ) {
mat[ 0 ].Normalize();
mat[ 2 ].Cross( mat[ 0 ], mat[ 1 ] );
mat[ 2 ].Normalize();
mat[ 1 ].Cross( mat[ 2 ], mat[ 0 ] );
mat[ 1 ].Normalize();
}
ID_INLINE void mat3_t::Identity( void ) {
mat[ 0 ].x = 1.f; mat[ 0 ].y = 0.f; mat[ 0 ].z = 0.f;
mat[ 1 ].x = 0.f; mat[ 1 ].y = 1.f; mat[ 1 ].z = 0.f;
mat[ 2 ].x = 0.f; mat[ 2 ].y = 0.f; mat[ 2 ].z = 1.f;
}
ID_INLINE void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst ) {
dst[0].x = inv[0].x * b[0].x + inv[1].x * b[1].x + inv[2].x * b[2].x;
dst[0].y = inv[0].x * b[0].y + inv[1].x * b[1].y + inv[2].x * b[2].y;
dst[0].z = inv[0].x * b[0].z + inv[1].x * b[1].z + inv[2].x * b[2].z;
dst[1].x = inv[0].y * b[0].x + inv[1].y * b[1].x + inv[2].y * b[2].x;
dst[1].y = inv[0].y * b[0].y + inv[1].y * b[1].y + inv[2].y * b[2].y;
dst[1].z = inv[0].y * b[0].z + inv[1].y * b[1].z + inv[2].y * b[2].z;
dst[2].x = inv[0].z * b[0].x + inv[1].z * b[1].x + inv[2].z * b[2].x;
dst[2].y = inv[0].z * b[0].y + inv[1].z * b[1].y + inv[2].z * b[2].y;
dst[2].z = inv[0].z * b[0].z + inv[1].z * b[1].z + inv[2].z * b[2].z;
}
ID_INLINE mat3_t SkewSymmetric( idVec3_t const &src ) {
return mat3_t( 0.0f, -src.z, src.y, src.z, 0.0f, -src.x, -src.y, src.x, 0.0f );
}
extern mat3_t mat3_default;
#endif /* !__MATH_MATRIX_H__ */

View File

@ -1,57 +1,57 @@
#include "math_quaternion.h"
#include "math_matrix.h"
void toQuat( idVec3_t &src, quat_t &dst ) {
dst.x = src.x;
dst.y = src.y;
dst.z = src.z;
dst.w = 0.0f;
}
void toQuat( angles_t &src, quat_t &dst ) {
mat3_t temp;
toMatrix( src, temp );
toQuat( temp, dst );
}
void toQuat( mat3_t &src, quat_t &dst ) {
float trace;
float s;
int i;
int j;
int k;
static int next[ 3 ] = { 1, 2, 0 };
trace = src[ 0 ][ 0 ] + src[ 1 ][ 1 ] + src[ 2 ][ 2 ];
if ( trace > 0.0f ) {
s = ( float )sqrt( trace + 1.0f );
dst.w = s * 0.5f;
s = 0.5f / s;
dst.x = ( src[ 2 ][ 1 ] - src[ 1 ][ 2 ] ) * s;
dst.y = ( src[ 0 ][ 2 ] - src[ 2 ][ 0 ] ) * s;
dst.z = ( src[ 1 ][ 0 ] - src[ 0 ][ 1 ] ) * s;
} else {
i = 0;
if ( src[ 1 ][ 1 ] > src[ 0 ][ 0 ] ) {
i = 1;
}
if ( src[ 2 ][ 2 ] > src[ i ][ i ] ) {
i = 2;
}
j = next[ i ];
k = next[ j ];
s = ( float )sqrt( ( src[ i ][ i ] - ( src[ j ][ j ] + src[ k ][ k ] ) ) + 1.0f );
dst[ i ] = s * 0.5f;
s = 0.5f / s;
dst.w = ( src[ k ][ j ] - src[ j ][ k ] ) * s;
dst[ j ] = ( src[ j ][ i ] + src[ i ][ j ] ) * s;
dst[ k ] = ( src[ k ][ i ] + src[ i ][ k ] ) * s;
}
}
#include "math_quaternion.h"
#include "math_matrix.h"
void toQuat( idVec3_t &src, quat_t &dst ) {
dst.x = src.x;
dst.y = src.y;
dst.z = src.z;
dst.w = 0.0f;
}
void toQuat( angles_t &src, quat_t &dst ) {
mat3_t temp;
toMatrix( src, temp );
toQuat( temp, dst );
}
void toQuat( mat3_t &src, quat_t &dst ) {
float trace;
float s;
int i;
int j;
int k;
static int next[ 3 ] = { 1, 2, 0 };
trace = src[ 0 ][ 0 ] + src[ 1 ][ 1 ] + src[ 2 ][ 2 ];
if ( trace > 0.0f ) {
s = ( float )sqrt( trace + 1.0f );
dst.w = s * 0.5f;
s = 0.5f / s;
dst.x = ( src[ 2 ][ 1 ] - src[ 1 ][ 2 ] ) * s;
dst.y = ( src[ 0 ][ 2 ] - src[ 2 ][ 0 ] ) * s;
dst.z = ( src[ 1 ][ 0 ] - src[ 0 ][ 1 ] ) * s;
} else {
i = 0;
if ( src[ 1 ][ 1 ] > src[ 0 ][ 0 ] ) {
i = 1;
}
if ( src[ 2 ][ 2 ] > src[ i ][ i ] ) {
i = 2;
}
j = next[ i ];
k = next[ j ];
s = ( float )sqrt( ( src[ i ][ i ] - ( src[ j ][ j ] + src[ k ][ k ] ) ) + 1.0f );
dst[ i ] = s * 0.5f;
s = 0.5f / s;
dst.w = ( src[ k ][ j ] - src[ j ][ k ] ) * s;
dst[ j ] = ( src[ j ][ i ] + src[ i ][ j ] ) * s;
dst[ k ] = ( src[ k ][ i ] + src[ i ][ k ] ) * s;
}
}

View File

@ -1,169 +1,169 @@
#ifndef __MATH_QUATERNION_H__
#define __MATH_QUATERNION_H__
#include <assert.h>
#include <math.h>
class idVec3_t;
class angles_t;
class mat3_t;
class quat_t {
public:
float x;
float y;
float z;
float w;
quat_t();
quat_t( float x, float y, float z, float w );
friend void toQuat( idVec3_t &src, quat_t &dst );
friend void toQuat( angles_t &src, quat_t &dst );
friend void toQuat( mat3_t &src, quat_t &dst );
float *vec4( void );
float operator[]( int index ) const;
float &operator[]( int index );
void set( float x, float y, float z, float w );
void operator=( quat_t a );
friend quat_t operator+( quat_t a, quat_t b );
quat_t &operator+=( quat_t a );
friend quat_t operator-( quat_t a, quat_t b );
quat_t &operator-=( quat_t a );
friend quat_t operator*( quat_t a, float b );
friend quat_t operator*( float a, quat_t b );
quat_t &operator*=( float a );
friend int operator==( quat_t a, quat_t b );
friend int operator!=( quat_t a, quat_t b );
float Length( void );
quat_t &Normalize( void );
quat_t operator-();
};
inline quat_t::quat_t() {
}
inline quat_t::quat_t( float x, float y, float z, float w ) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
inline float *quat_t::vec4( void ) {
return &x;
}
inline float quat_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 4 ) );
return ( &x )[ index ];
}
inline float& quat_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 4 ) );
return ( &x )[ index ];
}
inline void quat_t::set( float x, float y, float z, float w ) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
inline void quat_t::operator=( quat_t a ) {
x = a.x;
y = a.y;
z = a.z;
w = a.w;
}
inline quat_t operator+( quat_t a, quat_t b ) {
return quat_t( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
}
inline quat_t& quat_t::operator+=( quat_t a ) {
x += a.x;
y += a.y;
z += a.z;
w += a.w;
return *this;
}
inline quat_t operator-( quat_t a, quat_t b ) {
return quat_t( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
}
inline quat_t& quat_t::operator-=( quat_t a ) {
x -= a.x;
y -= a.y;
z -= a.z;
w -= a.w;
return *this;
}
inline quat_t operator*( quat_t a, float b ) {
return quat_t( a.x * b, a.y * b, a.z * b, a.w * b );
}
inline quat_t operator*( float a, quat_t b ) {
return b * a;
}
inline quat_t& quat_t::operator*=( float a ) {
x *= a;
y *= a;
z *= a;
w *= a;
return *this;
}
inline int operator==( quat_t a, quat_t b ) {
return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) && ( a.w == b.w ) );
}
inline int operator!=( quat_t a, quat_t b ) {
return ( ( a.x != b.x ) || ( a.y != b.y ) || ( a.z != b.z ) && ( a.w != b.w ) );
}
inline float quat_t::Length( void ) {
float length;
length = x * x + y * y + z * z + w * w;
return ( float )sqrt( length );
}
inline quat_t& quat_t::Normalize( void ) {
float length;
float ilength;
length = this->Length();
if ( length ) {
ilength = 1 / length;
x *= ilength;
y *= ilength;
z *= ilength;
w *= ilength;
}
return *this;
}
inline quat_t quat_t::operator-() {
return quat_t( -x, -y, -z, -w );
}
#endif /* !__MATH_QUATERNION_H__ */
#ifndef __MATH_QUATERNION_H__
#define __MATH_QUATERNION_H__
#include <assert.h>
#include <math.h>
class idVec3_t;
class angles_t;
class mat3_t;
class quat_t {
public:
float x;
float y;
float z;
float w;
quat_t();
quat_t( float x, float y, float z, float w );
friend void toQuat( idVec3_t &src, quat_t &dst );
friend void toQuat( angles_t &src, quat_t &dst );
friend void toQuat( mat3_t &src, quat_t &dst );
float *vec4( void );
float operator[]( int index ) const;
float &operator[]( int index );
void set( float x, float y, float z, float w );
void operator=( quat_t a );
friend quat_t operator+( quat_t a, quat_t b );
quat_t &operator+=( quat_t a );
friend quat_t operator-( quat_t a, quat_t b );
quat_t &operator-=( quat_t a );
friend quat_t operator*( quat_t a, float b );
friend quat_t operator*( float a, quat_t b );
quat_t &operator*=( float a );
friend int operator==( quat_t a, quat_t b );
friend int operator!=( quat_t a, quat_t b );
float Length( void );
quat_t &Normalize( void );
quat_t operator-();
};
inline quat_t::quat_t() {
}
inline quat_t::quat_t( float x, float y, float z, float w ) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
inline float *quat_t::vec4( void ) {
return &x;
}
inline float quat_t::operator[]( int index ) const {
assert( ( index >= 0 ) && ( index < 4 ) );
return ( &x )[ index ];
}
inline float& quat_t::operator[]( int index ) {
assert( ( index >= 0 ) && ( index < 4 ) );
return ( &x )[ index ];
}
inline void quat_t::set( float x, float y, float z, float w ) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
inline void quat_t::operator=( quat_t a ) {
x = a.x;
y = a.y;
z = a.z;
w = a.w;
}
inline quat_t operator+( quat_t a, quat_t b ) {
return quat_t( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
}
inline quat_t& quat_t::operator+=( quat_t a ) {
x += a.x;
y += a.y;
z += a.z;
w += a.w;
return *this;
}
inline quat_t operator-( quat_t a, quat_t b ) {
return quat_t( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
}
inline quat_t& quat_t::operator-=( quat_t a ) {
x -= a.x;
y -= a.y;
z -= a.z;
w -= a.w;
return *this;
}
inline quat_t operator*( quat_t a, float b ) {
return quat_t( a.x * b, a.y * b, a.z * b, a.w * b );
}
inline quat_t operator*( float a, quat_t b ) {
return b * a;
}
inline quat_t& quat_t::operator*=( float a ) {
x *= a;
y *= a;
z *= a;
w *= a;
return *this;
}
inline int operator==( quat_t a, quat_t b ) {
return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) && ( a.w == b.w ) );
}
inline int operator!=( quat_t a, quat_t b ) {
return ( ( a.x != b.x ) || ( a.y != b.y ) || ( a.z != b.z ) && ( a.w != b.w ) );
}
inline float quat_t::Length( void ) {
float length;
length = x * x + y * y + z * z + w * w;
return ( float )sqrt( length );
}
inline quat_t& quat_t::Normalize( void ) {
float length;
float ilength;
length = this->Length();
if ( length ) {
ilength = 1 / length;
x *= ilength;
y *= ilength;
z *= ilength;
w *= ilength;
}
return *this;
}
inline quat_t quat_t::operator-() {
return quat_t( -x, -y, -z, -w );
}
#endif /* !__MATH_QUATERNION_H__ */

View File

@ -1,123 +1,123 @@
//#include "../game/q_shared.h"
#include "math_vector.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
#define LERP_DELTA 1e-6
idVec3_t vec_zero( 0.0f, 0.0f, 0.0f );
Bounds boundsZero;
float idVec3_t::toYaw( void ) {
float yaw;
if ( ( y == 0 ) && ( x == 0 ) ) {
yaw = 0;
} else {
yaw = atan2( y, x ) * 180 / M_PI;
if ( yaw < 0 ) {
yaw += 360;
}
}
return yaw;
}
float idVec3_t::toPitch( void ) {
float forward;
float pitch;
if ( ( x == 0 ) && ( y == 0 ) ) {
if ( z > 0 ) {
pitch = 90;
} else {
pitch = 270;
}
} else {
forward = ( float )idSqrt( x * x + y * y );
pitch = atan2( z, forward ) * 180 / M_PI;
if ( pitch < 0 ) {
pitch += 360;
}
}
return pitch;
}
/*
angles_t idVec3_t::toAngles( void ) {
float forward;
float yaw;
float pitch;
if ( ( x == 0 ) && ( y == 0 ) ) {
yaw = 0;
if ( z > 0 ) {
pitch = 90;
} else {
pitch = 270;
}
} else {
yaw = atan2( y, x ) * 180 / M_PI;
if ( yaw < 0 ) {
yaw += 360;
}
forward = ( float )idSqrt( x * x + y * y );
pitch = atan2( z, forward ) * 180 / M_PI;
if ( pitch < 0 ) {
pitch += 360;
}
}
return angles_t( -pitch, yaw, 0 );
}
*/
idVec3_t LerpVector( idVec3_t &w1, idVec3_t &w2, const float t ) {
float omega, cosom, sinom, scale0, scale1;
cosom = w1 * w2;
if ( ( 1.0 - cosom ) > LERP_DELTA ) {
omega = acos( cosom );
sinom = sin( omega );
scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
scale1 = sin( t * omega ) / sinom;
} else {
scale0 = 1.0 - t;
scale1 = t;
}
return ( w1 * scale0 + w2 * scale1 );
}
/*
=============
idVec3_t::string
This is just a convenience function
for printing vectors
=============
*/
char *idVec3_t::string( void ) {
static int index = 0;
static char str[ 8 ][ 36 ];
char *s;
// use an array so that multiple toString's won't collide
s = str[ index ];
index = (index + 1)&7;
sprintf( s, "%.2f %.2f %.2f", x, y, z );
return s;
}
//#include "../game/q_shared.h"
#include "math_vector.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
#define LERP_DELTA 1e-6
idVec3_t vec_zero( 0.0f, 0.0f, 0.0f );
Bounds boundsZero;
float idVec3_t::toYaw( void ) {
float yaw;
if ( ( y == 0 ) && ( x == 0 ) ) {
yaw = 0;
} else {
yaw = atan2( y, x ) * 180 / M_PI;
if ( yaw < 0 ) {
yaw += 360;
}
}
return yaw;
}
float idVec3_t::toPitch( void ) {
float forward;
float pitch;
if ( ( x == 0 ) && ( y == 0 ) ) {
if ( z > 0 ) {
pitch = 90;
} else {
pitch = 270;
}
} else {
forward = ( float )idSqrt( x * x + y * y );
pitch = atan2( z, forward ) * 180 / M_PI;
if ( pitch < 0 ) {
pitch += 360;
}
}
return pitch;
}
/*
angles_t idVec3_t::toAngles( void ) {
float forward;
float yaw;
float pitch;
if ( ( x == 0 ) && ( y == 0 ) ) {
yaw = 0;
if ( z > 0 ) {
pitch = 90;
} else {
pitch = 270;
}
} else {
yaw = atan2( y, x ) * 180 / M_PI;
if ( yaw < 0 ) {
yaw += 360;
}
forward = ( float )idSqrt( x * x + y * y );
pitch = atan2( z, forward ) * 180 / M_PI;
if ( pitch < 0 ) {
pitch += 360;
}
}
return angles_t( -pitch, yaw, 0 );
}
*/
idVec3_t LerpVector( idVec3_t &w1, idVec3_t &w2, const float t ) {
float omega, cosom, sinom, scale0, scale1;
cosom = w1 * w2;
if ( ( 1.0 - cosom ) > LERP_DELTA ) {
omega = acos( cosom );
sinom = sin( omega );
scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
scale1 = sin( t * omega ) / sinom;
} else {
scale0 = 1.0 - t;
scale1 = t;
}
return ( w1 * scale0 + w2 * scale1 );
}
/*
=============
idVec3_t::string
This is just a convenience function
for printing vectors
=============
*/
char *idVec3_t::string( void ) {
static int index = 0;
static char str[ 8 ][ 36 ];
char *s;
// use an array so that multiple toString's won't collide
s = str[ index ];
index = (index + 1)&7;
sprintf( s, "%.2f %.2f %.2f", x, y, z );
return s;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +0,0 @@
SCC = This is a Source Code Control file
[Splines.dsp]
SCC_Aux_Path = "\\ravend\vss_projects\jk2sof2MP"
SCC_Project_Name = "$/General/code/Splines", GAAAAAAA

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,325 +1,325 @@
#ifndef __UTIL_LIST_H__
#define __UTIL_LIST_H__
#include <stdlib.h>
#include <assert.h>
template< class type >
class idList {
private:
int m_num;
int m_size;
int m_granularity;
type *m_list;
public:
idList( int granularity = 16 );
~idList<type>();
void Clear( void );
int Num( void );
void SetNum( int num );
void SetGranularity( int granularity );
void Condense( void );
int Size( void );
void Resize( int size );
type operator[]( int index ) const;
type &operator[]( int index );
int Append( type const & obj );
int AddUnique( type const & obj );
type *Find( type const & obj, int *index = NULL );
bool RemoveIndex( int index );
bool Remove( type const & obj );
typedef int cmp_t(const void *, const void *);
void Sort( cmp_t *compare );
};
/*
================
idList<type>::idList( int )
================
*/
template< class type >
inline idList<type>::idList( int granularity ) {
assert( granularity > 0 );
m_list = NULL;
m_granularity = granularity;
Clear();
}
/*
================
idList<type>::~idList<type>
================
*/
template< class type >
inline idList<type>::~idList() {
Clear();
}
/*
================
idList<type>::Clear
================
*/
template< class type >
inline void idList<type>::Clear( void ) {
if ( m_list ) {
delete[] m_list;
}
m_list = NULL;
m_num = 0;
m_size = 0;
}
/*
================
idList<type>::Num
================
*/
template< class type >
inline int idList<type>::Num( void ) {
return m_num;
}
/*
================
idList<type>::SetNum
================
*/
template< class type >
inline void idList<type>::SetNum( int num ) {
assert( num >= 0 );
if ( num > m_size ) {
// resize it up to the closest level of granularity
Resize( ( ( num + m_granularity - 1 ) / m_granularity ) * m_granularity );
}
m_num = num;
}
/*
================
idList<type>::SetGranularity
================
*/
template< class type >
inline void idList<type>::SetGranularity( int granularity ) {
int newsize;
assert( granularity > 0 );
m_granularity = granularity;
if ( m_list ) {
// resize it to the closest level of granularity
newsize = ( ( m_num + m_granularity - 1 ) / m_granularity ) * m_granularity;
if ( newsize != m_size ) {
Resize( newsize );
}
}
}
/*
================
idList<type>::Condense
Resizes the array to exactly the number of elements it contains
================
*/
template< class type >
inline void idList<type>::Condense( void ) {
if ( m_list ) {
if ( m_num ) {
Resize( m_num );
} else {
Clear();
}
}
}
/*
================
idList<type>::Size
================
*/
template< class type >
inline int idList<type>::Size( void ) {
return m_size;
}
/*
================
idList<type>::Resize
================
*/
template< class type >
inline void idList<type>::Resize( int size ) {
type *temp;
int i;
assert( size > 0 );
if ( size <= 0 ) {
Clear();
return;
}
temp = m_list;
m_size = size;
if ( m_size < m_num ) {
m_num = m_size;
}
m_list = new type[ m_size ];
for( i = 0; i < m_num; i++ ) {
m_list[ i ] = temp[ i ];
}
if ( temp ) {
delete[] temp;
}
}
/*
================
idList<type>::operator[] const
================
*/
template< class type >
inline type idList<type>::operator[]( int index ) const {
assert( index >= 0 );
assert( index < m_num );
return m_list[ index ];
}
/*
================
idList<type>::operator[]
================
*/
template< class type >
inline type &idList<type>::operator[]( int index ) {
assert( index >= 0 );
assert( index < m_num );
return m_list[ index ];
}
/*
================
idList<type>::Append
================
*/
template< class type >
inline int idList<type>::Append( type const & obj ) {
if ( !m_list ) {
Resize( m_granularity );
}
if ( m_num == m_size ) {
Resize( m_size + m_granularity );
}
m_list[ m_num ] = obj;
m_num++;
return m_num - 1;
}
/*
================
idList<type>::AddUnique
================
*/
template< class type >
inline int idList<type>::AddUnique( type const & obj ) {
int index;
if ( !Find( obj, &index ) ) {
index = Append( obj );
}
return index;
}
/*
================
idList<type>::Find
================
*/
template< class type >
inline type *idList<type>::Find( type const & obj, int *index ) {
int i;
for( i = 0; i < m_num; i++ ) {
if ( m_list[ i ] == obj ) {
if ( index ) {
*index = i;
}
return &m_list[ i ];
}
}
return NULL;
}
/*
================
idList<type>::RemoveIndex
================
*/
template< class type >
inline bool idList<type>::RemoveIndex( int index ) {
int i;
if ( !m_list || !m_num ) {
return false;
}
assert( index >= 0 );
assert( index < m_num );
if ( ( index < 0 ) || ( index >= m_num ) ) {
return false;
}
m_num--;
for( i = index; i < m_num; i++ ) {
m_list[ i ] = m_list[ i + 1 ];
}
return true;
}
/*
================
idList<type>::Remove
================
*/
template< class type >
inline bool idList<type>::Remove( type const & obj ) {
int index;
if ( Find( obj, &index ) ) {
return RemoveIndex( index );
}
return false;
}
/*
================
idList<type>::Sort
================
*/
template< class type >
inline void idList<type>::Sort( cmp_t *compare ) {
if ( !m_list ) {
return;
}
qsort( ( void * )m_list, ( size_t )m_num, sizeof( type ), compare );
}
#endif /* !__UTIL_LIST_H__ */
#ifndef __UTIL_LIST_H__
#define __UTIL_LIST_H__
#include <stdlib.h>
#include <assert.h>
template< class type >
class idList {
private:
int m_num;
int m_size;
int m_granularity;
type *m_list;
public:
idList( int granularity = 16 );
~idList<type>();
void Clear( void );
int Num( void );
void SetNum( int num );
void SetGranularity( int granularity );
void Condense( void );
int Size( void );
void Resize( int size );
type operator[]( int index ) const;
type &operator[]( int index );
int Append( type const & obj );
int AddUnique( type const & obj );
type *Find( type const & obj, int *index = NULL );
bool RemoveIndex( int index );
bool Remove( type const & obj );
typedef int cmp_t(const void *, const void *);
void Sort( cmp_t *compare );
};
/*
================
idList<type>::idList( int )
================
*/
template< class type >
inline idList<type>::idList( int granularity ) {
assert( granularity > 0 );
m_list = NULL;
m_granularity = granularity;
Clear();
}
/*
================
idList<type>::~idList<type>
================
*/
template< class type >
inline idList<type>::~idList() {
Clear();
}
/*
================
idList<type>::Clear
================
*/
template< class type >
inline void idList<type>::Clear( void ) {
if ( m_list ) {
delete[] m_list;
}
m_list = NULL;
m_num = 0;
m_size = 0;
}
/*
================
idList<type>::Num
================
*/
template< class type >
inline int idList<type>::Num( void ) {
return m_num;
}
/*
================
idList<type>::SetNum
================
*/
template< class type >
inline void idList<type>::SetNum( int num ) {
assert( num >= 0 );
if ( num > m_size ) {
// resize it up to the closest level of granularity
Resize( ( ( num + m_granularity - 1 ) / m_granularity ) * m_granularity );
}
m_num = num;
}
/*
================
idList<type>::SetGranularity
================
*/
template< class type >
inline void idList<type>::SetGranularity( int granularity ) {
int newsize;
assert( granularity > 0 );
m_granularity = granularity;
if ( m_list ) {
// resize it to the closest level of granularity
newsize = ( ( m_num + m_granularity - 1 ) / m_granularity ) * m_granularity;
if ( newsize != m_size ) {
Resize( newsize );
}
}
}
/*
================
idList<type>::Condense
Resizes the array to exactly the number of elements it contains
================
*/
template< class type >
inline void idList<type>::Condense( void ) {
if ( m_list ) {
if ( m_num ) {
Resize( m_num );
} else {
Clear();
}
}
}
/*
================
idList<type>::Size
================
*/
template< class type >
inline int idList<type>::Size( void ) {
return m_size;
}
/*
================
idList<type>::Resize
================
*/
template< class type >
inline void idList<type>::Resize( int size ) {
type *temp;
int i;
assert( size > 0 );
if ( size <= 0 ) {
Clear();
return;
}
temp = m_list;
m_size = size;
if ( m_size < m_num ) {
m_num = m_size;
}
m_list = new type[ m_size ];
for( i = 0; i < m_num; i++ ) {
m_list[ i ] = temp[ i ];
}
if ( temp ) {
delete[] temp;
}
}
/*
================
idList<type>::operator[] const
================
*/
template< class type >
inline type idList<type>::operator[]( int index ) const {
assert( index >= 0 );
assert( index < m_num );
return m_list[ index ];
}
/*
================
idList<type>::operator[]
================
*/
template< class type >
inline type &idList<type>::operator[]( int index ) {
assert( index >= 0 );
assert( index < m_num );
return m_list[ index ];
}
/*
================
idList<type>::Append
================
*/
template< class type >
inline int idList<type>::Append( type const & obj ) {
if ( !m_list ) {
Resize( m_granularity );
}
if ( m_num == m_size ) {
Resize( m_size + m_granularity );
}
m_list[ m_num ] = obj;
m_num++;
return m_num - 1;
}
/*
================
idList<type>::AddUnique
================
*/
template< class type >
inline int idList<type>::AddUnique( type const & obj ) {
int index;
if ( !Find( obj, &index ) ) {
index = Append( obj );
}
return index;
}
/*
================
idList<type>::Find
================
*/
template< class type >
inline type *idList<type>::Find( type const & obj, int *index ) {
int i;
for( i = 0; i < m_num; i++ ) {
if ( m_list[ i ] == obj ) {
if ( index ) {
*index = i;
}
return &m_list[ i ];
}
}
return NULL;
}
/*
================
idList<type>::RemoveIndex
================
*/
template< class type >
inline bool idList<type>::RemoveIndex( int index ) {
int i;
if ( !m_list || !m_num ) {
return false;
}
assert( index >= 0 );
assert( index < m_num );
if ( ( index < 0 ) || ( index >= m_num ) ) {
return false;
}
m_num--;
for( i = index; i < m_num; i++ ) {
m_list[ i ] = m_list[ i + 1 ];
}
return true;
}
/*
================
idList<type>::Remove
================
*/
template< class type >
inline bool idList<type>::Remove( type const & obj ) {
int index;
if ( Find( obj, &index ) ) {
return RemoveIndex( index );
}
return false;
}
/*
================
idList<type>::Sort
================
*/
template< class type >
inline void idList<type>::Sort( cmp_t *compare ) {
if ( !m_list ) {
return;
}
qsort( ( void * )m_list, ( size_t )m_num, sizeof( type ), compare );
}
#endif /* !__UTIL_LIST_H__ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,246 +1,246 @@
//NOTE: int = default signed
// default long
#define AASID (('S'<<24)+('A'<<16)+('A'<<8)+'E')
#define AASVERSION_OLD 4
#define AASVERSION 5
//presence types
#define PRESENCE_NONE 1
#define PRESENCE_NORMAL 2
#define PRESENCE_CROUCH 4
//travel types
#define MAX_TRAVELTYPES 32
#define TRAVEL_INVALID 1 //temporary not possible
#define TRAVEL_WALK 2 //walking
#define TRAVEL_CROUCH 3 //crouching
#define TRAVEL_BARRIERJUMP 4 //jumping onto a barrier
#define TRAVEL_JUMP 5 //jumping
#define TRAVEL_LADDER 6 //climbing a ladder
#define TRAVEL_WALKOFFLEDGE 7 //walking of a ledge
#define TRAVEL_SWIM 8 //swimming
#define TRAVEL_WATERJUMP 9 //jump out of the water
#define TRAVEL_TELEPORT 10 //teleportation
#define TRAVEL_ELEVATOR 11 //travel by elevator
#define TRAVEL_ROCKETJUMP 12 //rocket jumping required for travel
#define TRAVEL_BFGJUMP 13 //bfg jumping required for travel
#define TRAVEL_GRAPPLEHOOK 14 //grappling hook required for travel
#define TRAVEL_DOUBLEJUMP 15 //double jump
#define TRAVEL_RAMPJUMP 16 //ramp jump
#define TRAVEL_STRAFEJUMP 17 //strafe jump
#define TRAVEL_JUMPPAD 18 //jump pad
#define TRAVEL_FUNCBOB 19 //func bob
//additional travel flags
#define TRAVELTYPE_MASK 0xFFFFFF
#define TRAVELFLAG_NOTTEAM1 (1 << 24)
#define TRAVELFLAG_NOTTEAM2 (2 << 24)
//face flags
#define FACE_SOLID 1 //just solid at the other side
#define FACE_LADDER 2 //ladder
#define FACE_GROUND 4 //standing on ground when in this face
#define FACE_GAP 8 //gap in the ground
#define FACE_LIQUID 16 //face seperating two areas with liquid
#define FACE_LIQUIDSURFACE 32 //face seperating liquid and air
#define FACE_BRIDGE 64 //can walk over this face if bridge is closed
//area contents
#define AREACONTENTS_WATER 1
#define AREACONTENTS_LAVA 2
#define AREACONTENTS_SLIME 4
#define AREACONTENTS_CLUSTERPORTAL 8
#define AREACONTENTS_TELEPORTAL 16
#define AREACONTENTS_ROUTEPORTAL 32
#define AREACONTENTS_TELEPORTER 64
#define AREACONTENTS_JUMPPAD 128
#define AREACONTENTS_DONOTENTER 256
#define AREACONTENTS_VIEWPORTAL 512
#define AREACONTENTS_MOVER 1024
#define AREACONTENTS_NOTTEAM1 2048
#define AREACONTENTS_NOTTEAM2 4096
//number of model of the mover inside this area
#define AREACONTENTS_MODELNUMSHIFT 24
#define AREACONTENTS_MAXMODELNUM 0xFF
#define AREACONTENTS_MODELNUM (AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT)
//area flags
#define AREA_GROUNDED 1 //bot can stand on the ground
#define AREA_LADDER 2 //area contains one or more ladder faces
#define AREA_LIQUID 4 //area contains a liquid
#define AREA_DISABLED 8 //area is disabled for routing when set
#define AREA_BRIDGE 16 //area ontop of a bridge
//aas file header lumps
#define AAS_LUMPS 14
#define AASLUMP_BBOXES 0
#define AASLUMP_VERTEXES 1
#define AASLUMP_PLANES 2
#define AASLUMP_EDGES 3
#define AASLUMP_EDGEINDEX 4
#define AASLUMP_FACES 5
#define AASLUMP_FACEINDEX 6
#define AASLUMP_AREAS 7
#define AASLUMP_AREASETTINGS 8
#define AASLUMP_REACHABILITY 9
#define AASLUMP_NODES 10
#define AASLUMP_PORTALS 11
#define AASLUMP_PORTALINDEX 12
#define AASLUMP_CLUSTERS 13
//========== bounding box =========
//bounding box
typedef struct aas_bbox_s
{
int presencetype;
int flags;
vec3_t mins, maxs;
} aas_bbox_t;
//============ settings ===========
//reachability to another area
typedef struct aas_reachability_s
{
int areanum; //number of the reachable area
int facenum; //number of the face towards the other area
int edgenum; //number of the edge towards the other area
vec3_t start; //start point of inter area movement
vec3_t end; //end point of inter area movement
int traveltype; //type of travel required to get to the area
unsigned short int traveltime;//travel time of the inter area movement
} aas_reachability_t;
//area settings
typedef struct aas_areasettings_s
{
//could also add all kind of statistic fields
int contents; //contents of the area
int areaflags; //several area flags
int presencetype; //how a bot can be present in this area
int cluster; //cluster the area belongs to, if negative it's a portal
int clusterareanum; //number of the area in the cluster
int numreachableareas; //number of reachable areas from this one
int firstreachablearea; //first reachable area in the reachable area index
} aas_areasettings_t;
//cluster portal
typedef struct aas_portal_s
{
int areanum; //area that is the actual portal
int frontcluster; //cluster at front of portal
int backcluster; //cluster at back of portal
int clusterareanum[2]; //number of the area in the front and back cluster
} aas_portal_t;
//cluster portal index
typedef int aas_portalindex_t;
//cluster
typedef struct aas_cluster_s
{
int numareas; //number of areas in the cluster
int numreachabilityareas; //number of areas with reachabilities
int numportals; //number of cluster portals
int firstportal; //first cluster portal in the index
} aas_cluster_t;
//============ 3d definition ============
typedef vec3_t aas_vertex_t;
//just a plane in the third dimension
typedef struct aas_plane_s
{
vec3_t normal; //normal vector of the plane
float dist; //distance of the plane (normal vector * distance = point in plane)
int type;
} aas_plane_t;
//edge
typedef struct aas_edge_s
{
int v[2]; //numbers of the vertexes of this edge
} aas_edge_t;
//edge index, negative if vertexes are reversed
typedef int aas_edgeindex_t;
//a face bounds an area, often it will also seperate two areas
typedef struct aas_face_s
{
int planenum; //number of the plane this face is in
int faceflags; //face flags (no use to create face settings for just this field)
int numedges; //number of edges in the boundary of the face
int firstedge; //first edge in the edge index
int frontarea; //area at the front of this face
int backarea; //area at the back of this face
} aas_face_t;
//face index, stores a negative index if backside of face
typedef int aas_faceindex_t;
//area with a boundary of faces
typedef struct aas_area_s
{
int areanum; //number of this area
//3d definition
int numfaces; //number of faces used for the boundary of the area
int firstface; //first face in the face index used for the boundary of the area
vec3_t mins; //mins of the area
vec3_t maxs; //maxs of the area
vec3_t center; //'center' of the area
} aas_area_t;
//nodes of the bsp tree
typedef struct aas_node_s
{
int planenum;
int children[2]; //child nodes of this node, or areas as leaves when negative
//when a child is zero it's a solid leaf
} aas_node_t;
//=========== aas file ===============
//header lump
typedef struct
{
int fileofs;
int filelen;
} aas_lump_t;
//aas file header
typedef struct aas_header_s
{
int ident;
int version;
int bspchecksum;
//data entries
aas_lump_t lumps[AAS_LUMPS];
} aas_header_t;
//====== additional information ======
/*
- when a node child is a solid leaf the node child number is zero
- two adjacent areas (sharing a plane at opposite sides) share a face
this face is a portal between the areas
- when an area uses a face from the faceindex with a positive index
then the face plane normal points into the area
- the face edges are stored counter clockwise using the edgeindex
- two adjacent convex areas (sharing a face) only share One face
this is a simple result of the areas being convex
- the areas can't have a mixture of ground and gap faces
other mixtures of faces in one area are allowed
- areas with the AREACONTENTS_CLUSTERPORTAL in the settings have
the cluster number set to the negative portal number
- edge zero is a dummy
- face zero is a dummy
- area zero is a dummy
- node zero is a dummy
*/
//NOTE: int = default signed
// default long
#define AASID (('S'<<24)+('A'<<16)+('A'<<8)+'E')
#define AASVERSION_OLD 4
#define AASVERSION 5
//presence types
#define PRESENCE_NONE 1
#define PRESENCE_NORMAL 2
#define PRESENCE_CROUCH 4
//travel types
#define MAX_TRAVELTYPES 32
#define TRAVEL_INVALID 1 //temporary not possible
#define TRAVEL_WALK 2 //walking
#define TRAVEL_CROUCH 3 //crouching
#define TRAVEL_BARRIERJUMP 4 //jumping onto a barrier
#define TRAVEL_JUMP 5 //jumping
#define TRAVEL_LADDER 6 //climbing a ladder
#define TRAVEL_WALKOFFLEDGE 7 //walking of a ledge
#define TRAVEL_SWIM 8 //swimming
#define TRAVEL_WATERJUMP 9 //jump out of the water
#define TRAVEL_TELEPORT 10 //teleportation
#define TRAVEL_ELEVATOR 11 //travel by elevator
#define TRAVEL_ROCKETJUMP 12 //rocket jumping required for travel
#define TRAVEL_BFGJUMP 13 //bfg jumping required for travel
#define TRAVEL_GRAPPLEHOOK 14 //grappling hook required for travel
#define TRAVEL_DOUBLEJUMP 15 //double jump
#define TRAVEL_RAMPJUMP 16 //ramp jump
#define TRAVEL_STRAFEJUMP 17 //strafe jump
#define TRAVEL_JUMPPAD 18 //jump pad
#define TRAVEL_FUNCBOB 19 //func bob
//additional travel flags
#define TRAVELTYPE_MASK 0xFFFFFF
#define TRAVELFLAG_NOTTEAM1 (1 << 24)
#define TRAVELFLAG_NOTTEAM2 (2 << 24)
//face flags
#define FACE_SOLID 1 //just solid at the other side
#define FACE_LADDER 2 //ladder
#define FACE_GROUND 4 //standing on ground when in this face
#define FACE_GAP 8 //gap in the ground
#define FACE_LIQUID 16 //face seperating two areas with liquid
#define FACE_LIQUIDSURFACE 32 //face seperating liquid and air
#define FACE_BRIDGE 64 //can walk over this face if bridge is closed
//area contents
#define AREACONTENTS_WATER 1
#define AREACONTENTS_LAVA 2
#define AREACONTENTS_SLIME 4
#define AREACONTENTS_CLUSTERPORTAL 8
#define AREACONTENTS_TELEPORTAL 16
#define AREACONTENTS_ROUTEPORTAL 32
#define AREACONTENTS_TELEPORTER 64
#define AREACONTENTS_JUMPPAD 128
#define AREACONTENTS_DONOTENTER 256
#define AREACONTENTS_VIEWPORTAL 512
#define AREACONTENTS_MOVER 1024
#define AREACONTENTS_NOTTEAM1 2048
#define AREACONTENTS_NOTTEAM2 4096
//number of model of the mover inside this area
#define AREACONTENTS_MODELNUMSHIFT 24
#define AREACONTENTS_MAXMODELNUM 0xFF
#define AREACONTENTS_MODELNUM (AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT)
//area flags
#define AREA_GROUNDED 1 //bot can stand on the ground
#define AREA_LADDER 2 //area contains one or more ladder faces
#define AREA_LIQUID 4 //area contains a liquid
#define AREA_DISABLED 8 //area is disabled for routing when set
#define AREA_BRIDGE 16 //area ontop of a bridge
//aas file header lumps
#define AAS_LUMPS 14
#define AASLUMP_BBOXES 0
#define AASLUMP_VERTEXES 1
#define AASLUMP_PLANES 2
#define AASLUMP_EDGES 3
#define AASLUMP_EDGEINDEX 4
#define AASLUMP_FACES 5
#define AASLUMP_FACEINDEX 6
#define AASLUMP_AREAS 7
#define AASLUMP_AREASETTINGS 8
#define AASLUMP_REACHABILITY 9
#define AASLUMP_NODES 10
#define AASLUMP_PORTALS 11
#define AASLUMP_PORTALINDEX 12
#define AASLUMP_CLUSTERS 13
//========== bounding box =========
//bounding box
typedef struct aas_bbox_s
{
int presencetype;
int flags;
vec3_t mins, maxs;
} aas_bbox_t;
//============ settings ===========
//reachability to another area
typedef struct aas_reachability_s
{
int areanum; //number of the reachable area
int facenum; //number of the face towards the other area
int edgenum; //number of the edge towards the other area
vec3_t start; //start point of inter area movement
vec3_t end; //end point of inter area movement
int traveltype; //type of travel required to get to the area
unsigned short int traveltime;//travel time of the inter area movement
} aas_reachability_t;
//area settings
typedef struct aas_areasettings_s
{
//could also add all kind of statistic fields
int contents; //contents of the area
int areaflags; //several area flags
int presencetype; //how a bot can be present in this area
int cluster; //cluster the area belongs to, if negative it's a portal
int clusterareanum; //number of the area in the cluster
int numreachableareas; //number of reachable areas from this one
int firstreachablearea; //first reachable area in the reachable area index
} aas_areasettings_t;
//cluster portal
typedef struct aas_portal_s
{
int areanum; //area that is the actual portal
int frontcluster; //cluster at front of portal
int backcluster; //cluster at back of portal
int clusterareanum[2]; //number of the area in the front and back cluster
} aas_portal_t;
//cluster portal index
typedef int aas_portalindex_t;
//cluster
typedef struct aas_cluster_s
{
int numareas; //number of areas in the cluster
int numreachabilityareas; //number of areas with reachabilities
int numportals; //number of cluster portals
int firstportal; //first cluster portal in the index
} aas_cluster_t;
//============ 3d definition ============
typedef vec3_t aas_vertex_t;
//just a plane in the third dimension
typedef struct aas_plane_s
{
vec3_t normal; //normal vector of the plane
float dist; //distance of the plane (normal vector * distance = point in plane)
int type;
} aas_plane_t;
//edge
typedef struct aas_edge_s
{
int v[2]; //numbers of the vertexes of this edge
} aas_edge_t;
//edge index, negative if vertexes are reversed
typedef int aas_edgeindex_t;
//a face bounds an area, often it will also seperate two areas
typedef struct aas_face_s
{
int planenum; //number of the plane this face is in
int faceflags; //face flags (no use to create face settings for just this field)
int numedges; //number of edges in the boundary of the face
int firstedge; //first edge in the edge index
int frontarea; //area at the front of this face
int backarea; //area at the back of this face
} aas_face_t;
//face index, stores a negative index if backside of face
typedef int aas_faceindex_t;
//area with a boundary of faces
typedef struct aas_area_s
{
int areanum; //number of this area
//3d definition
int numfaces; //number of faces used for the boundary of the area
int firstface; //first face in the face index used for the boundary of the area
vec3_t mins; //mins of the area
vec3_t maxs; //maxs of the area
vec3_t center; //'center' of the area
} aas_area_t;
//nodes of the bsp tree
typedef struct aas_node_s
{
int planenum;
int children[2]; //child nodes of this node, or areas as leaves when negative
//when a child is zero it's a solid leaf
} aas_node_t;
//=========== aas file ===============
//header lump
typedef struct
{
int fileofs;
int filelen;
} aas_lump_t;
//aas file header
typedef struct aas_header_s
{
int ident;
int version;
int bspchecksum;
//data entries
aas_lump_t lumps[AAS_LUMPS];
} aas_header_t;
//====== additional information ======
/*
- when a node child is a solid leaf the node child number is zero
- two adjacent areas (sharing a plane at opposite sides) share a face
this face is a portal between the areas
- when an area uses a face from the faceindex with a positive index
then the face plane normal points into the area
- the face edges are stored counter clockwise using the edgeindex
- two adjacent convex areas (sharing a face) only share One face
this is a simple result of the areas being convex
- the areas can't have a mixture of ground and gap faces
other mixtures of faces in one area are allowed
- areas with the AREACONTENTS_CLUSTERPORTAL in the settings have
the cluster number set to the negative portal number
- edge zero is a dummy
- face zero is a dummy
- area zero is a dummy
- node zero is a dummy
*/

View File

@ -1,72 +1,72 @@
/*****************************************************************************
* name: be_aas_bsp.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_bsp.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//loads the given BSP file
int AAS_LoadBSPFile(void);
//dump the loaded BSP data
void AAS_DumpBSPData(void);
//unlink the given entity from the bsp tree leaves
void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves);
//link the given entity to the bsp tree leaves of the given model
bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins,
vec3_t absmaxs,
int entnum,
int modelnum);
//calculates collision with given entity
qboolean AAS_EntityCollision(int entnum,
vec3_t start,
vec3_t boxmins,
vec3_t boxmaxs,
vec3_t end,
int contentmask,
bsp_trace_t *trace);
//for debugging
void AAS_PrintFreeBSPLinks(char *str);
//
#endif //AASINTERN
#define MAX_EPAIRKEY 128
//trace through the world
bsp_trace_t AAS_Trace( vec3_t start,
vec3_t mins,
vec3_t maxs,
vec3_t end,
int passent,
int contentmask);
//returns the contents at the given point
int AAS_PointContents(vec3_t point);
//returns true when p2 is in the PVS of p1
qboolean AAS_inPVS(vec3_t p1, vec3_t p2);
//returns true when p2 is in the PHS of p1
qboolean AAS_inPHS(vec3_t p1, vec3_t p2);
//returns true if the given areas are connected
qboolean AAS_AreasConnected(int area1, int area2);
//creates a list with entities totally or partly within the given box
int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount);
//gets the mins, maxs and origin of a BSP model
void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin);
//handle to the next bsp entity
int AAS_NextBSPEntity(int ent);
//return the value of the BSP epair key
int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size);
//get a vector for the BSP epair key
int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v);
//get a float for the BSP epair key
int AAS_FloatForBSPEpairKey(int ent, char *key, float *value);
//get an integer for the BSP epair key
int AAS_IntForBSPEpairKey(int ent, char *key, int *value);
/*****************************************************************************
* name: be_aas_bsp.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_bsp.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//loads the given BSP file
int AAS_LoadBSPFile(void);
//dump the loaded BSP data
void AAS_DumpBSPData(void);
//unlink the given entity from the bsp tree leaves
void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves);
//link the given entity to the bsp tree leaves of the given model
bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins,
vec3_t absmaxs,
int entnum,
int modelnum);
//calculates collision with given entity
qboolean AAS_EntityCollision(int entnum,
vec3_t start,
vec3_t boxmins,
vec3_t boxmaxs,
vec3_t end,
int contentmask,
bsp_trace_t *trace);
//for debugging
void AAS_PrintFreeBSPLinks(char *str);
//
#endif //AASINTERN
#define MAX_EPAIRKEY 128
//trace through the world
bsp_trace_t AAS_Trace( vec3_t start,
vec3_t mins,
vec3_t maxs,
vec3_t end,
int passent,
int contentmask);
//returns the contents at the given point
int AAS_PointContents(vec3_t point);
//returns true when p2 is in the PVS of p1
qboolean AAS_inPVS(vec3_t p1, vec3_t p2);
//returns true when p2 is in the PHS of p1
qboolean AAS_inPHS(vec3_t p1, vec3_t p2);
//returns true if the given areas are connected
qboolean AAS_AreasConnected(int area1, int area2);
//creates a list with entities totally or partly within the given box
int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount);
//gets the mins, maxs and origin of a BSP model
void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin);
//handle to the next bsp entity
int AAS_NextBSPEntity(int ent);
//return the value of the BSP epair key
int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size);
//get a vector for the BSP epair key
int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v);
//get a float for the BSP epair key
int AAS_FloatForBSPEpairKey(int ent, char *key, float *value);
//get an integer for the BSP epair key
int AAS_IntForBSPEpairKey(int ent, char *key, int *value);

View File

@ -1,470 +1,470 @@
/*****************************************************************************
* name: be_aas_bspq3.c
*
* desc: BSP, Environment Sampling
*
* $Archive: /MissionPack/code/botlib/be_aas_bspq3.c $
* $Author: Ttimo $
* $Revision: 5 $
* $Modtime: 4/22/01 8:52a $
* $Date: 4/22/01 8:52a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_aas_def.h"
extern botlib_import_t botimport;
//#define TRACE_DEBUG
#define ON_EPSILON 0.005
//#define DEG2RAD( a ) (( a * M_PI ) / 180.0F)
#define MAX_BSPENTITIES 2048
typedef struct rgb_s
{
int red;
int green;
int blue;
} rgb_t;
//bsp entity epair
typedef struct bsp_epair_s
{
char *key;
char *value;
struct bsp_epair_s *next;
} bsp_epair_t;
//bsp data entity
typedef struct bsp_entity_s
{
bsp_epair_t *epairs;
} bsp_entity_t;
//id Sofware BSP data
typedef struct bsp_s
{
//true when bsp file is loaded
int loaded;
//entity data
int entdatasize;
char *dentdata;
//bsp entities
int numentities;
bsp_entity_t entities[MAX_BSPENTITIES];
} bsp_t;
//global bsp
bsp_t bspworld;
#ifdef BSP_DEBUG
typedef struct cname_s
{
int value;
char *name;
} cname_t;
cname_t contentnames[] =
{
{CONTENTS_SOLID,"CONTENTS_SOLID"},
{CONTENTS_WINDOW,"CONTENTS_WINDOW"},
{CONTENTS_AUX,"CONTENTS_AUX"},
{CONTENTS_LAVA,"CONTENTS_LAVA"},
{CONTENTS_SLIME,"CONTENTS_SLIME"},
{CONTENTS_WATER,"CONTENTS_WATER"},
{CONTENTS_MIST,"CONTENTS_MIST"},
{LAST_VISIBLE_CONTENTS,"LAST_VISIBLE_CONTENTS"},
{CONTENTS_AREAPORTAL,"CONTENTS_AREAPORTAL"},
{CONTENTS_PLAYERCLIP,"CONTENTS_PLAYERCLIP"},
{CONTENTS_MONSTERCLIP,"CONTENTS_MONSTERCLIP"},
{CONTENTS_CURRENT_0,"CONTENTS_CURRENT_0"},
{CONTENTS_CURRENT_90,"CONTENTS_CURRENT_90"},
{CONTENTS_CURRENT_180,"CONTENTS_CURRENT_180"},
{CONTENTS_CURRENT_270,"CONTENTS_CURRENT_270"},
{CONTENTS_CURRENT_UP,"CONTENTS_CURRENT_UP"},
{CONTENTS_CURRENT_DOWN,"CONTENTS_CURRENT_DOWN"},
{CONTENTS_ORIGIN,"CONTENTS_ORIGIN"},
{CONTENTS_MONSTER,"CONTENTS_MONSTER"},
{CONTENTS_DEADMONSTER,"CONTENTS_DEADMONSTER"},
{CONTENTS_DETAIL,"CONTENTS_DETAIL"},
{CONTENTS_TRANSLUCENT,"CONTENTS_TRANSLUCENT"},
{CONTENTS_LADDER,"CONTENTS_LADDER"},
{0, 0}
};
void PrintContents(int contents)
{
int i;
for (i = 0; contentnames[i].value; i++)
{
if (contents & contentnames[i].value)
{
botimport.Print(PRT_MESSAGE, "%s\n", contentnames[i].name);
} //end if
} //end for
} //end of the function PrintContents
#endif // BSP_DEBUG
//===========================================================================
// traces axial boxes of any size through the world
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
bsp_trace_t AAS_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask)
{
bsp_trace_t bsptrace;
botimport.Trace(&bsptrace, start, mins, maxs, end, passent, contentmask);
return bsptrace;
} //end of the function AAS_Trace
//===========================================================================
// returns the contents at the given point
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_PointContents(vec3_t point)
{
return botimport.PointContents(point);
} //end of the function AAS_PointContents
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_EntityCollision(int entnum,
vec3_t start, vec3_t boxmins, vec3_t boxmaxs, vec3_t end,
int contentmask, bsp_trace_t *trace)
{
bsp_trace_t enttrace;
botimport.EntityTrace(&enttrace, start, boxmins, boxmaxs, end, entnum, contentmask);
if (enttrace.fraction < trace->fraction)
{
Com_Memcpy(trace, &enttrace, sizeof(bsp_trace_t));
return qtrue;
} //end if
return qfalse;
} //end of the function AAS_EntityCollision
//===========================================================================
// returns true if in Potentially Hearable Set
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_inPVS(vec3_t p1, vec3_t p2)
{
return (qboolean)botimport.inPVS(p1, p2);
} //end of the function AAS_InPVS
//===========================================================================
// returns true if in Potentially Visible Set
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_inPHS(vec3_t p1, vec3_t p2)
{
return qtrue;
} //end of the function AAS_inPHS
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin)
{
botimport.BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin);
} //end of the function AAS_BSPModelMinsMaxs
//===========================================================================
// unlinks the entity from all leaves
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves)
{
} //end of the function AAS_UnlinkFromBSPLeaves
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum, int modelnum)
{
return NULL;
} //end of the function AAS_BSPLinkEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount)
{
return 0;
} //end of the function AAS_BoxEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NextBSPEntity(int ent)
{
ent++;
if (ent >= 1 && ent < bspworld.numentities) return ent;
return 0;
} //end of the function AAS_NextBSPEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BSPEntityInRange(int ent)
{
if (ent <= 0 || ent >= bspworld.numentities)
{
botimport.Print(PRT_MESSAGE, "bsp entity out of range\n");
return qfalse;
} //end if
return qtrue;
} //end of the function AAS_BSPEntityInRange
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size)
{
bsp_epair_t *epair;
value[0] = '\0';
if (!AAS_BSPEntityInRange(ent)) return qfalse;
for (epair = bspworld.entities[ent].epairs; epair; epair = epair->next)
{
if (!strcmp(epair->key, key))
{
strncpy(value, epair->value, size-1);
value[size-1] = '\0';
return qtrue;
} //end if
} //end for
return qfalse;
} //end of the function AAS_FindBSPEpair
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v)
{
char buf[MAX_EPAIRKEY];
double v1, v2, v3;
VectorClear(v);
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
//scanf into doubles, then assign, so it is vec_t size independent
v1 = v2 = v3 = 0;
sscanf(buf, "%lf %lf %lf", &v1, &v2, &v3);
v[0] = v1;
v[1] = v2;
v[2] = v3;
return qtrue;
} //end of the function AAS_VectorForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_FloatForBSPEpairKey(int ent, char *key, float *value)
{
char buf[MAX_EPAIRKEY];
*value = 0;
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
*value = atof(buf);
return qtrue;
} //end of the function AAS_FloatForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IntForBSPEpairKey(int ent, char *key, int *value)
{
char buf[MAX_EPAIRKEY];
*value = 0;
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
*value = atoi(buf);
return qtrue;
} //end of the function AAS_IntForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_FreeBSPEntities(void)
{
int i;
bsp_entity_t *ent;
bsp_epair_t *epair, *nextepair;
for (i = 1; i < bspworld.numentities; i++)
{
ent = &bspworld.entities[i];
for (epair = ent->epairs; epair; epair = nextepair)
{
nextepair = epair->next;
//
if (epair->key) FreeMemory(epair->key);
if (epair->value) FreeMemory(epair->value);
FreeMemory(epair);
} //end for
} //end for
bspworld.numentities = 0;
} //end of the function AAS_FreeBSPEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ParseBSPEntities(void)
{
script_t *script;
token_t token;
bsp_entity_t *ent;
bsp_epair_t *epair;
script = LoadScriptMemory(bspworld.dentdata, bspworld.entdatasize, "entdata");
SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES|SCFL_NOSTRINGESCAPECHARS);//SCFL_PRIMITIVE);
bspworld.numentities = 1;
while(PS_ReadToken(script, &token))
{
if (strcmp(token.string, "{"))
{
ScriptError(script, "invalid %s\n", token.string);
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
if (bspworld.numentities >= MAX_BSPENTITIES)
{
botimport.Print(PRT_MESSAGE, "too many entities in BSP file\n");
break;
} //end if
ent = &bspworld.entities[bspworld.numentities];
bspworld.numentities++;
ent->epairs = NULL;
while(PS_ReadToken(script, &token))
{
if (!strcmp(token.string, "}")) break;
epair = (bsp_epair_t *) GetClearedHunkMemory(sizeof(bsp_epair_t));
epair->next = ent->epairs;
ent->epairs = epair;
if (token.type != TT_STRING)
{
ScriptError(script, "invalid %s\n", token.string);
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
StripDoubleQuotes(token.string);
epair->key = (char *) GetHunkMemory(strlen(token.string) + 1);
strcpy(epair->key, token.string);
if (!PS_ExpectTokenType(script, TT_STRING, 0, &token))
{
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
StripDoubleQuotes(token.string);
epair->value = (char *) GetHunkMemory(strlen(token.string) + 1);
strcpy(epair->value, token.string);
} //end while
if (strcmp(token.string, "}"))
{
ScriptError(script, "missing }\n");
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
} //end while
FreeScript(script);
} //end of the function AAS_ParseBSPEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BSPTraceLight(vec3_t start, vec3_t end, vec3_t endpos, int *red, int *green, int *blue)
{
return 0;
} //end of the function AAS_BSPTraceLight
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_DumpBSPData(void)
{
AAS_FreeBSPEntities();
if (bspworld.dentdata) FreeMemory(bspworld.dentdata);
bspworld.dentdata = NULL;
bspworld.entdatasize = 0;
//
bspworld.loaded = qfalse;
Com_Memset( &bspworld, 0, sizeof(bspworld) );
} //end of the function AAS_DumpBSPData
//===========================================================================
// load an bsp file
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadBSPFile(void)
{
AAS_DumpBSPData();
bspworld.entdatasize = strlen(botimport.BSPEntityData()) + 1;
bspworld.dentdata = (char *) GetClearedHunkMemory(bspworld.entdatasize);
Com_Memcpy(bspworld.dentdata, botimport.BSPEntityData(), bspworld.entdatasize);
AAS_ParseBSPEntities();
bspworld.loaded = qtrue;
return BLERR_NOERROR;
} //end of the function AAS_LoadBSPFile
/*****************************************************************************
* name: be_aas_bspq3.c
*
* desc: BSP, Environment Sampling
*
* $Archive: /MissionPack/code/botlib/be_aas_bspq3.c $
* $Author: Ttimo $
* $Revision: 5 $
* $Modtime: 4/22/01 8:52a $
* $Date: 4/22/01 8:52a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_aas_def.h"
extern botlib_import_t botimport;
//#define TRACE_DEBUG
#define ON_EPSILON 0.005
//#define DEG2RAD( a ) (( a * M_PI ) / 180.0F)
#define MAX_BSPENTITIES 2048
typedef struct rgb_s
{
int red;
int green;
int blue;
} rgb_t;
//bsp entity epair
typedef struct bsp_epair_s
{
char *key;
char *value;
struct bsp_epair_s *next;
} bsp_epair_t;
//bsp data entity
typedef struct bsp_entity_s
{
bsp_epair_t *epairs;
} bsp_entity_t;
//id Sofware BSP data
typedef struct bsp_s
{
//true when bsp file is loaded
int loaded;
//entity data
int entdatasize;
char *dentdata;
//bsp entities
int numentities;
bsp_entity_t entities[MAX_BSPENTITIES];
} bsp_t;
//global bsp
bsp_t bspworld;
#ifdef BSP_DEBUG
typedef struct cname_s
{
int value;
char *name;
} cname_t;
cname_t contentnames[] =
{
{CONTENTS_SOLID,"CONTENTS_SOLID"},
{CONTENTS_WINDOW,"CONTENTS_WINDOW"},
{CONTENTS_AUX,"CONTENTS_AUX"},
{CONTENTS_LAVA,"CONTENTS_LAVA"},
{CONTENTS_SLIME,"CONTENTS_SLIME"},
{CONTENTS_WATER,"CONTENTS_WATER"},
{CONTENTS_MIST,"CONTENTS_MIST"},
{LAST_VISIBLE_CONTENTS,"LAST_VISIBLE_CONTENTS"},
{CONTENTS_AREAPORTAL,"CONTENTS_AREAPORTAL"},
{CONTENTS_PLAYERCLIP,"CONTENTS_PLAYERCLIP"},
{CONTENTS_MONSTERCLIP,"CONTENTS_MONSTERCLIP"},
{CONTENTS_CURRENT_0,"CONTENTS_CURRENT_0"},
{CONTENTS_CURRENT_90,"CONTENTS_CURRENT_90"},
{CONTENTS_CURRENT_180,"CONTENTS_CURRENT_180"},
{CONTENTS_CURRENT_270,"CONTENTS_CURRENT_270"},
{CONTENTS_CURRENT_UP,"CONTENTS_CURRENT_UP"},
{CONTENTS_CURRENT_DOWN,"CONTENTS_CURRENT_DOWN"},
{CONTENTS_ORIGIN,"CONTENTS_ORIGIN"},
{CONTENTS_MONSTER,"CONTENTS_MONSTER"},
{CONTENTS_DEADMONSTER,"CONTENTS_DEADMONSTER"},
{CONTENTS_DETAIL,"CONTENTS_DETAIL"},
{CONTENTS_TRANSLUCENT,"CONTENTS_TRANSLUCENT"},
{CONTENTS_LADDER,"CONTENTS_LADDER"},
{0, 0}
};
void PrintContents(int contents)
{
int i;
for (i = 0; contentnames[i].value; i++)
{
if (contents & contentnames[i].value)
{
botimport.Print(PRT_MESSAGE, "%s\n", contentnames[i].name);
} //end if
} //end for
} //end of the function PrintContents
#endif // BSP_DEBUG
//===========================================================================
// traces axial boxes of any size through the world
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
bsp_trace_t AAS_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask)
{
bsp_trace_t bsptrace;
botimport.Trace(&bsptrace, start, mins, maxs, end, passent, contentmask);
return bsptrace;
} //end of the function AAS_Trace
//===========================================================================
// returns the contents at the given point
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_PointContents(vec3_t point)
{
return botimport.PointContents(point);
} //end of the function AAS_PointContents
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_EntityCollision(int entnum,
vec3_t start, vec3_t boxmins, vec3_t boxmaxs, vec3_t end,
int contentmask, bsp_trace_t *trace)
{
bsp_trace_t enttrace;
botimport.EntityTrace(&enttrace, start, boxmins, boxmaxs, end, entnum, contentmask);
if (enttrace.fraction < trace->fraction)
{
Com_Memcpy(trace, &enttrace, sizeof(bsp_trace_t));
return qtrue;
} //end if
return qfalse;
} //end of the function AAS_EntityCollision
//===========================================================================
// returns true if in Potentially Hearable Set
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_inPVS(vec3_t p1, vec3_t p2)
{
return (qboolean)botimport.inPVS(p1, p2);
} //end of the function AAS_InPVS
//===========================================================================
// returns true if in Potentially Visible Set
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
qboolean AAS_inPHS(vec3_t p1, vec3_t p2)
{
return qtrue;
} //end of the function AAS_inPHS
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin)
{
botimport.BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin);
} //end of the function AAS_BSPModelMinsMaxs
//===========================================================================
// unlinks the entity from all leaves
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves)
{
} //end of the function AAS_UnlinkFromBSPLeaves
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum, int modelnum)
{
return NULL;
} //end of the function AAS_BSPLinkEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount)
{
return 0;
} //end of the function AAS_BoxEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NextBSPEntity(int ent)
{
ent++;
if (ent >= 1 && ent < bspworld.numentities) return ent;
return 0;
} //end of the function AAS_NextBSPEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BSPEntityInRange(int ent)
{
if (ent <= 0 || ent >= bspworld.numentities)
{
botimport.Print(PRT_MESSAGE, "bsp entity out of range\n");
return qfalse;
} //end if
return qtrue;
} //end of the function AAS_BSPEntityInRange
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size)
{
bsp_epair_t *epair;
value[0] = '\0';
if (!AAS_BSPEntityInRange(ent)) return qfalse;
for (epair = bspworld.entities[ent].epairs; epair; epair = epair->next)
{
if (!strcmp(epair->key, key))
{
strncpy(value, epair->value, size-1);
value[size-1] = '\0';
return qtrue;
} //end if
} //end for
return qfalse;
} //end of the function AAS_FindBSPEpair
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v)
{
char buf[MAX_EPAIRKEY];
double v1, v2, v3;
VectorClear(v);
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
//scanf into doubles, then assign, so it is vec_t size independent
v1 = v2 = v3 = 0;
sscanf(buf, "%lf %lf %lf", &v1, &v2, &v3);
v[0] = v1;
v[1] = v2;
v[2] = v3;
return qtrue;
} //end of the function AAS_VectorForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_FloatForBSPEpairKey(int ent, char *key, float *value)
{
char buf[MAX_EPAIRKEY];
*value = 0;
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
*value = atof(buf);
return qtrue;
} //end of the function AAS_FloatForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IntForBSPEpairKey(int ent, char *key, int *value)
{
char buf[MAX_EPAIRKEY];
*value = 0;
if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
*value = atoi(buf);
return qtrue;
} //end of the function AAS_IntForBSPEpairKey
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_FreeBSPEntities(void)
{
int i;
bsp_entity_t *ent;
bsp_epair_t *epair, *nextepair;
for (i = 1; i < bspworld.numentities; i++)
{
ent = &bspworld.entities[i];
for (epair = ent->epairs; epair; epair = nextepair)
{
nextepair = epair->next;
//
if (epair->key) FreeMemory(epair->key);
if (epair->value) FreeMemory(epair->value);
FreeMemory(epair);
} //end for
} //end for
bspworld.numentities = 0;
} //end of the function AAS_FreeBSPEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ParseBSPEntities(void)
{
script_t *script;
token_t token;
bsp_entity_t *ent;
bsp_epair_t *epair;
script = LoadScriptMemory(bspworld.dentdata, bspworld.entdatasize, "entdata");
SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES|SCFL_NOSTRINGESCAPECHARS);//SCFL_PRIMITIVE);
bspworld.numentities = 1;
while(PS_ReadToken(script, &token))
{
if (strcmp(token.string, "{"))
{
ScriptError(script, "invalid %s\n", token.string);
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
if (bspworld.numentities >= MAX_BSPENTITIES)
{
botimport.Print(PRT_MESSAGE, "too many entities in BSP file\n");
break;
} //end if
ent = &bspworld.entities[bspworld.numentities];
bspworld.numentities++;
ent->epairs = NULL;
while(PS_ReadToken(script, &token))
{
if (!strcmp(token.string, "}")) break;
epair = (bsp_epair_t *) GetClearedHunkMemory(sizeof(bsp_epair_t));
epair->next = ent->epairs;
ent->epairs = epair;
if (token.type != TT_STRING)
{
ScriptError(script, "invalid %s\n", token.string);
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
StripDoubleQuotes(token.string);
epair->key = (char *) GetHunkMemory(strlen(token.string) + 1);
strcpy(epair->key, token.string);
if (!PS_ExpectTokenType(script, TT_STRING, 0, &token))
{
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
StripDoubleQuotes(token.string);
epair->value = (char *) GetHunkMemory(strlen(token.string) + 1);
strcpy(epair->value, token.string);
} //end while
if (strcmp(token.string, "}"))
{
ScriptError(script, "missing }\n");
AAS_FreeBSPEntities();
FreeScript(script);
return;
} //end if
} //end while
FreeScript(script);
} //end of the function AAS_ParseBSPEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BSPTraceLight(vec3_t start, vec3_t end, vec3_t endpos, int *red, int *green, int *blue)
{
return 0;
} //end of the function AAS_BSPTraceLight
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_DumpBSPData(void)
{
AAS_FreeBSPEntities();
if (bspworld.dentdata) FreeMemory(bspworld.dentdata);
bspworld.dentdata = NULL;
bspworld.entdatasize = 0;
//
bspworld.loaded = qfalse;
Com_Memset( &bspworld, 0, sizeof(bspworld) );
} //end of the function AAS_DumpBSPData
//===========================================================================
// load an bsp file
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadBSPFile(void)
{
AAS_DumpBSPData();
bspworld.entdatasize = strlen(botimport.BSPEntityData()) + 1;
bspworld.dentdata = (char *) GetClearedHunkMemory(bspworld.entdatasize);
Com_Memcpy(bspworld.dentdata, botimport.BSPEntityData(), bspworld.entdatasize);
AAS_ParseBSPEntities();
bspworld.loaded = qtrue;
return BLERR_NOERROR;
} //end of the function AAS_LoadBSPFile

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,21 @@
/*****************************************************************************
* name: be_aas_cluster.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_cluster.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize the AAS clustering
void AAS_InitClustering(void);
//
void AAS_SetViewPortalsAsClusterPortals(void);
#endif //AASINTERN
/*****************************************************************************
* name: be_aas_cluster.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_cluster.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize the AAS clustering
void AAS_InitClustering(void);
//
void AAS_SetViewPortalsAsClusterPortals(void);
#endif //AASINTERN

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +1,45 @@
/*****************************************************************************
* name: be_aas_debug.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_debug.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
//clear the shown debug lines
void AAS_ClearShownDebugLines(void);
//
void AAS_ClearShownPolygons(void);
//show a debug line
void AAS_DebugLine(vec3_t start, vec3_t end, int color);
//show a permenent line
void AAS_PermanentLine(vec3_t start, vec3_t end, int color);
//show a permanent cross
void AAS_DrawPermanentCross(vec3_t origin, float size, int color);
//draw a cross in the plane
void AAS_DrawPlaneCross(vec3_t point, vec3_t normal, float dist, int type, int color);
//show a bounding box
void AAS_ShowBoundingBox(vec3_t origin, vec3_t mins, vec3_t maxs);
//show a face
void AAS_ShowFace(int facenum);
//show an area
void AAS_ShowArea(int areanum, int groundfacesonly);
//
void AAS_ShowAreaPolygons(int areanum, int color, int groundfacesonly);
//draw a cros
void AAS_DrawCross(vec3_t origin, float size, int color);
//print the travel type
void AAS_PrintTravelType(int traveltype);
//draw an arrow
void AAS_DrawArrow(vec3_t start, vec3_t end, int linecolor, int arrowcolor);
//visualize the given reachability
void AAS_ShowReachability(struct aas_reachability_s *reach);
//show the reachable areas from the given area
void AAS_ShowReachableAreas(int areanum);
/*****************************************************************************
* name: be_aas_debug.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_debug.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
//clear the shown debug lines
void AAS_ClearShownDebugLines(void);
//
void AAS_ClearShownPolygons(void);
//show a debug line
void AAS_DebugLine(vec3_t start, vec3_t end, int color);
//show a permenent line
void AAS_PermanentLine(vec3_t start, vec3_t end, int color);
//show a permanent cross
void AAS_DrawPermanentCross(vec3_t origin, float size, int color);
//draw a cross in the plane
void AAS_DrawPlaneCross(vec3_t point, vec3_t normal, float dist, int type, int color);
//show a bounding box
void AAS_ShowBoundingBox(vec3_t origin, vec3_t mins, vec3_t maxs);
//show a face
void AAS_ShowFace(int facenum);
//show an area
void AAS_ShowArea(int areanum, int groundfacesonly);
//
void AAS_ShowAreaPolygons(int areanum, int color, int groundfacesonly);
//draw a cros
void AAS_DrawCross(vec3_t origin, float size, int color);
//print the travel type
void AAS_PrintTravelType(int traveltype);
//draw an arrow
void AAS_DrawArrow(vec3_t start, vec3_t end, int linecolor, int arrowcolor);
//visualize the given reachability
void AAS_ShowReachability(struct aas_reachability_s *reach);
//show the reachable areas from the given area
void AAS_ShowReachableAreas(int areanum);

View File

@ -1,290 +1,290 @@
/*****************************************************************************
* name: be_aas_def.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_def.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
//debugging on
#define AAS_DEBUG
// these are also in q_shared.h - argh (rjr)
#define MAX_CLIENTS 32
#define MAX_MODELS 256 // these are sent over the net as 8 bits
#define MAX_SOUNDS 256 // so they cannot be blindly increased
// these are also in bg_public.h - argh (rjr)
#define CS_SCORES 32
#define CS_MODELS (CS_SCORES+MAX_CLIENTS)
#define CS_SOUNDS (CS_MODELS+MAX_MODELS)
#define DF_AASENTNUMBER(x) (x - aasworld.entities)
#define DF_NUMBERAASENT(x) (&aasworld.entities[x])
#define DF_AASENTCLIENT(x) (x - aasworld.entities - 1)
#define DF_CLIENTAASENT(x) (&aasworld.entities[x + 1])
#ifndef MAX_PATH
#define MAX_PATH MAX_QPATH
#endif
//string index (for model, sound and image index)
typedef struct aas_stringindex_s
{
int numindexes;
char **index;
} aas_stringindex_t;
//structure to link entities to areas and areas to entities
typedef struct aas_link_s
{
int entnum;
int areanum;
struct aas_link_s *next_ent, *prev_ent;
struct aas_link_s *next_area, *prev_area;
} aas_link_t;
//structure to link entities to leaves and leaves to entities
typedef struct bsp_link_s
{
int entnum;
int leafnum;
struct bsp_link_s *next_ent, *prev_ent;
struct bsp_link_s *next_leaf, *prev_leaf;
} bsp_link_t;
typedef struct bsp_entdata_s
{
vec3_t origin;
vec3_t angles;
vec3_t absmins;
vec3_t absmaxs;
int solid;
int modelnum;
} bsp_entdata_t;
//entity
typedef struct aas_entity_s
{
//entity info
aas_entityinfo_t i;
//links into the AAS areas
aas_link_t *areas;
//links into the BSP leaves
bsp_link_t *leaves;
} aas_entity_t;
typedef struct aas_settings_s
{
vec3_t phys_gravitydirection;
float phys_friction;
float phys_stopspeed;
float phys_gravity;
float phys_waterfriction;
float phys_watergravity;
float phys_maxvelocity;
float phys_maxwalkvelocity;
float phys_maxcrouchvelocity;
float phys_maxswimvelocity;
float phys_walkaccelerate;
float phys_airaccelerate;
float phys_swimaccelerate;
float phys_maxstep;
float phys_maxsteepness;
float phys_maxwaterjump;
float phys_maxbarrier;
float phys_jumpvel;
float phys_falldelta5;
float phys_falldelta10;
float rs_waterjump;
float rs_teleport;
float rs_barrierjump;
float rs_startcrouch;
float rs_startgrapple;
float rs_startwalkoffledge;
float rs_startjump;
float rs_rocketjump;
float rs_bfgjump;
float rs_jumppad;
float rs_aircontrolledjumppad;
float rs_funcbob;
float rs_startelevator;
float rs_falldamage5;
float rs_falldamage10;
float rs_maxfallheight;
float rs_maxjumpfallheight;
} aas_settings_t;
#define CACHETYPE_PORTAL 0
#define CACHETYPE_AREA 1
//routing cache
typedef struct aas_routingcache_s
{
byte type; //portal or area cache
float time; //last time accessed or updated
int size; //size of the routing cache
int cluster; //cluster the cache is for
int areanum; //area the cache is created for
vec3_t origin; //origin within the area
float starttraveltime; //travel time to start with
int travelflags; //combinations of the travel flags
struct aas_routingcache_s *prev, *next;
struct aas_routingcache_s *time_prev, *time_next;
unsigned char *reachabilities; //reachabilities used for routing
unsigned short int traveltimes[1]; //travel time for every area (variable sized)
} aas_routingcache_t;
//fields for the routing algorithm
typedef struct aas_routingupdate_s
{
int cluster;
int areanum; //area number of the update
vec3_t start; //start point the area was entered
unsigned short int tmptraveltime; //temporary travel time
unsigned short int *areatraveltimes; //travel times within the area
qboolean inlist; //true if the update is in the list
struct aas_routingupdate_s *next;
struct aas_routingupdate_s *prev;
} aas_routingupdate_t;
//reversed reachability link
typedef struct aas_reversedlink_s
{
int linknum; //the aas_areareachability_t
int areanum; //reachable from this area
struct aas_reversedlink_s *next; //next link
} aas_reversedlink_t;
//reversed area reachability
typedef struct aas_reversedreachability_s
{
int numlinks;
aas_reversedlink_t *first;
} aas_reversedreachability_t;
//areas a reachability goes through
typedef struct aas_reachabilityareas_s
{
int firstarea, numareas;
} aas_reachabilityareas_t;
typedef struct aas_s
{
int loaded; //true when an AAS file is loaded
int initialized; //true when AAS has been initialized
int savefile; //set true when file should be saved
int bspchecksum;
//current time
float time;
int numframes;
//name of the aas file
char filename[MAX_PATH];
char mapname[MAX_PATH];
//bounding boxes
int numbboxes;
aas_bbox_t *bboxes;
//vertexes
int numvertexes;
aas_vertex_t *vertexes;
//planes
int numplanes;
aas_plane_t *planes;
//edges
int numedges;
aas_edge_t *edges;
//edge index
int edgeindexsize;
aas_edgeindex_t *edgeindex;
//faces
int numfaces;
aas_face_t *faces;
//face index
int faceindexsize;
aas_faceindex_t *faceindex;
//convex areas
int numareas;
aas_area_t *areas;
//convex area settings
int numareasettings;
aas_areasettings_t *areasettings;
//reachablity list
int reachabilitysize;
aas_reachability_t *reachability;
//nodes of the bsp tree
int numnodes;
aas_node_t *nodes;
//cluster portals
int numportals;
aas_portal_t *portals;
//cluster portal index
int portalindexsize;
aas_portalindex_t *portalindex;
//clusters
int numclusters;
aas_cluster_t *clusters;
//
int numreachabilityareas;
float reachabilitytime;
//enities linked in the areas
aas_link_t *linkheap; //heap with link structures
int linkheapsize; //size of the link heap
aas_link_t *freelinks; //first free link
aas_link_t **arealinkedentities; //entities linked into areas
//entities
int maxentities;
int maxclients;
aas_entity_t *entities;
//string indexes
char *configstrings[MAX_CONFIGSTRINGS];
int indexessetup;
//index to retrieve travel flag for a travel type
int travelflagfortype[MAX_TRAVELTYPES];
//travel flags for each area based on contents
int *areacontentstravelflags;
//routing update
aas_routingupdate_t *areaupdate;
aas_routingupdate_t *portalupdate;
//number of routing updates during a frame (reset every frame)
int frameroutingupdates;
//reversed reachability links
aas_reversedreachability_t *reversedreachability;
//travel times within the areas
unsigned short ***areatraveltimes;
//array of size numclusters with cluster cache
aas_routingcache_t ***clusterareacache;
aas_routingcache_t **portalcache;
//cache list sorted on time
aas_routingcache_t *oldestcache; // start of cache list sorted on time
aas_routingcache_t *newestcache; // end of cache list sorted on time
//maximum travel time through portal areas
int *portalmaxtraveltimes;
//areas the reachabilities go through
int *reachabilityareaindex;
aas_reachabilityareas_t *reachabilityareas;
} aas_t;
#define AASINTERN
#ifndef BSPCINCLUDE
#include "be_aas_main.h"
#include "be_aas_entity.h"
#include "be_aas_sample.h"
#include "be_aas_cluster.h"
#include "be_aas_reach.h"
#include "be_aas_route.h"
#include "be_aas_routealt.h"
#include "be_aas_debug.h"
#include "be_aas_file.h"
#include "be_aas_optimize.h"
#include "be_aas_bsp.h"
#include "be_aas_move.h"
#endif //BSPCINCLUDE
/*****************************************************************************
* name: be_aas_def.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_def.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
//debugging on
#define AAS_DEBUG
// these are also in q_shared.h - argh (rjr)
#define MAX_CLIENTS 32
#define MAX_MODELS 256 // these are sent over the net as 8 bits
#define MAX_SOUNDS 256 // so they cannot be blindly increased
// these are also in bg_public.h - argh (rjr)
#define CS_SCORES 32
#define CS_MODELS (CS_SCORES+MAX_CLIENTS)
#define CS_SOUNDS (CS_MODELS+MAX_MODELS)
#define DF_AASENTNUMBER(x) (x - aasworld.entities)
#define DF_NUMBERAASENT(x) (&aasworld.entities[x])
#define DF_AASENTCLIENT(x) (x - aasworld.entities - 1)
#define DF_CLIENTAASENT(x) (&aasworld.entities[x + 1])
#ifndef MAX_PATH
#define MAX_PATH MAX_QPATH
#endif
//string index (for model, sound and image index)
typedef struct aas_stringindex_s
{
int numindexes;
char **index;
} aas_stringindex_t;
//structure to link entities to areas and areas to entities
typedef struct aas_link_s
{
int entnum;
int areanum;
struct aas_link_s *next_ent, *prev_ent;
struct aas_link_s *next_area, *prev_area;
} aas_link_t;
//structure to link entities to leaves and leaves to entities
typedef struct bsp_link_s
{
int entnum;
int leafnum;
struct bsp_link_s *next_ent, *prev_ent;
struct bsp_link_s *next_leaf, *prev_leaf;
} bsp_link_t;
typedef struct bsp_entdata_s
{
vec3_t origin;
vec3_t angles;
vec3_t absmins;
vec3_t absmaxs;
int solid;
int modelnum;
} bsp_entdata_t;
//entity
typedef struct aas_entity_s
{
//entity info
aas_entityinfo_t i;
//links into the AAS areas
aas_link_t *areas;
//links into the BSP leaves
bsp_link_t *leaves;
} aas_entity_t;
typedef struct aas_settings_s
{
vec3_t phys_gravitydirection;
float phys_friction;
float phys_stopspeed;
float phys_gravity;
float phys_waterfriction;
float phys_watergravity;
float phys_maxvelocity;
float phys_maxwalkvelocity;
float phys_maxcrouchvelocity;
float phys_maxswimvelocity;
float phys_walkaccelerate;
float phys_airaccelerate;
float phys_swimaccelerate;
float phys_maxstep;
float phys_maxsteepness;
float phys_maxwaterjump;
float phys_maxbarrier;
float phys_jumpvel;
float phys_falldelta5;
float phys_falldelta10;
float rs_waterjump;
float rs_teleport;
float rs_barrierjump;
float rs_startcrouch;
float rs_startgrapple;
float rs_startwalkoffledge;
float rs_startjump;
float rs_rocketjump;
float rs_bfgjump;
float rs_jumppad;
float rs_aircontrolledjumppad;
float rs_funcbob;
float rs_startelevator;
float rs_falldamage5;
float rs_falldamage10;
float rs_maxfallheight;
float rs_maxjumpfallheight;
} aas_settings_t;
#define CACHETYPE_PORTAL 0
#define CACHETYPE_AREA 1
//routing cache
typedef struct aas_routingcache_s
{
byte type; //portal or area cache
float time; //last time accessed or updated
int size; //size of the routing cache
int cluster; //cluster the cache is for
int areanum; //area the cache is created for
vec3_t origin; //origin within the area
float starttraveltime; //travel time to start with
int travelflags; //combinations of the travel flags
struct aas_routingcache_s *prev, *next;
struct aas_routingcache_s *time_prev, *time_next;
unsigned char *reachabilities; //reachabilities used for routing
unsigned short int traveltimes[1]; //travel time for every area (variable sized)
} aas_routingcache_t;
//fields for the routing algorithm
typedef struct aas_routingupdate_s
{
int cluster;
int areanum; //area number of the update
vec3_t start; //start point the area was entered
unsigned short int tmptraveltime; //temporary travel time
unsigned short int *areatraveltimes; //travel times within the area
qboolean inlist; //true if the update is in the list
struct aas_routingupdate_s *next;
struct aas_routingupdate_s *prev;
} aas_routingupdate_t;
//reversed reachability link
typedef struct aas_reversedlink_s
{
int linknum; //the aas_areareachability_t
int areanum; //reachable from this area
struct aas_reversedlink_s *next; //next link
} aas_reversedlink_t;
//reversed area reachability
typedef struct aas_reversedreachability_s
{
int numlinks;
aas_reversedlink_t *first;
} aas_reversedreachability_t;
//areas a reachability goes through
typedef struct aas_reachabilityareas_s
{
int firstarea, numareas;
} aas_reachabilityareas_t;
typedef struct aas_s
{
int loaded; //true when an AAS file is loaded
int initialized; //true when AAS has been initialized
int savefile; //set true when file should be saved
int bspchecksum;
//current time
float time;
int numframes;
//name of the aas file
char filename[MAX_PATH];
char mapname[MAX_PATH];
//bounding boxes
int numbboxes;
aas_bbox_t *bboxes;
//vertexes
int numvertexes;
aas_vertex_t *vertexes;
//planes
int numplanes;
aas_plane_t *planes;
//edges
int numedges;
aas_edge_t *edges;
//edge index
int edgeindexsize;
aas_edgeindex_t *edgeindex;
//faces
int numfaces;
aas_face_t *faces;
//face index
int faceindexsize;
aas_faceindex_t *faceindex;
//convex areas
int numareas;
aas_area_t *areas;
//convex area settings
int numareasettings;
aas_areasettings_t *areasettings;
//reachablity list
int reachabilitysize;
aas_reachability_t *reachability;
//nodes of the bsp tree
int numnodes;
aas_node_t *nodes;
//cluster portals
int numportals;
aas_portal_t *portals;
//cluster portal index
int portalindexsize;
aas_portalindex_t *portalindex;
//clusters
int numclusters;
aas_cluster_t *clusters;
//
int numreachabilityareas;
float reachabilitytime;
//enities linked in the areas
aas_link_t *linkheap; //heap with link structures
int linkheapsize; //size of the link heap
aas_link_t *freelinks; //first free link
aas_link_t **arealinkedentities; //entities linked into areas
//entities
int maxentities;
int maxclients;
aas_entity_t *entities;
//string indexes
char *configstrings[MAX_CONFIGSTRINGS];
int indexessetup;
//index to retrieve travel flag for a travel type
int travelflagfortype[MAX_TRAVELTYPES];
//travel flags for each area based on contents
int *areacontentstravelflags;
//routing update
aas_routingupdate_t *areaupdate;
aas_routingupdate_t *portalupdate;
//number of routing updates during a frame (reset every frame)
int frameroutingupdates;
//reversed reachability links
aas_reversedreachability_t *reversedreachability;
//travel times within the areas
unsigned short ***areatraveltimes;
//array of size numclusters with cluster cache
aas_routingcache_t ***clusterareacache;
aas_routingcache_t **portalcache;
//cache list sorted on time
aas_routingcache_t *oldestcache; // start of cache list sorted on time
aas_routingcache_t *newestcache; // end of cache list sorted on time
//maximum travel time through portal areas
int *portalmaxtraveltimes;
//areas the reachabilities go through
int *reachabilityareaindex;
aas_reachabilityareas_t *reachabilityareas;
} aas_t;
#define AASINTERN
#ifndef BSPCINCLUDE
#include "be_aas_main.h"
#include "be_aas_entity.h"
#include "be_aas_sample.h"
#include "be_aas_cluster.h"
#include "be_aas_reach.h"
#include "be_aas_route.h"
#include "be_aas_routealt.h"
#include "be_aas_debug.h"
#include "be_aas_file.h"
#include "be_aas_optimize.h"
#include "be_aas_bsp.h"
#include "be_aas_move.h"
#endif //BSPCINCLUDE

View File

@ -1,420 +1,420 @@
/*****************************************************************************
* name: be_aas_entity.c
*
* desc: AAS entities
*
* $Archive: /MissionPack/code/botlib/be_aas_entity.c $
* $Author: Zaphod $
* $Revision: 11 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_utils.h"
#include "l_log.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
#define MASK_SOLID CONTENTS_PLAYERCLIP
//FIXME: these might change
enum {
ET_GENERAL,
ET_PLAYER,
ET_ITEM,
ET_MISSILE,
ET_MOVER
};
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_UpdateEntity(int entnum, bot_entitystate_t *state)
{
int relink;
aas_entity_t *ent;
vec3_t absmins, absmaxs;
if (!aasworld.loaded)
{
botimport.Print(PRT_MESSAGE, "AAS_UpdateEntity: not loaded\n");
return BLERR_NOAASFILE;
} //end if
ent = &aasworld.entities[entnum];
if (!state) {
//unlink the entity
AAS_UnlinkFromAreas(ent->areas);
//unlink the entity from the BSP leaves
AAS_UnlinkFromBSPLeaves(ent->leaves);
//
ent->areas = NULL;
//
ent->leaves = NULL;
return BLERR_NOERROR;
}
ent->i.update_time = AAS_Time() - ent->i.ltime;
ent->i.type = state->type;
ent->i.flags = state->flags;
ent->i.ltime = AAS_Time();
VectorCopy(ent->i.origin, ent->i.lastvisorigin);
VectorCopy(state->old_origin, ent->i.old_origin);
ent->i.solid = state->solid;
ent->i.groundent = state->groundent;
ent->i.modelindex = state->modelindex;
ent->i.modelindex2 = state->modelindex2;
ent->i.frame = state->frame;
ent->i.event = state->event;
ent->i.eventParm = state->eventParm;
ent->i.powerups = state->powerups;
ent->i.weapon = state->weapon;
ent->i.legsAnim = state->legsAnim;
ent->i.torsoAnim = state->torsoAnim;
//number of the entity
ent->i.number = entnum;
//updated so set valid flag
ent->i.valid = qtrue;
//link everything the first frame
if (aasworld.numframes == 1) relink = qtrue;
else relink = qfalse;
//
if (ent->i.solid == SOLID_BSP)
{
//if the angles of the model changed
if (!VectorCompare(state->angles, ent->i.angles))
{
VectorCopy(state->angles, ent->i.angles);
relink = qtrue;
} //end if
//get the mins and maxs of the model
//FIXME: rotate mins and maxs
AAS_BSPModelMinsMaxsOrigin(ent->i.modelindex, ent->i.angles, ent->i.mins, ent->i.maxs, NULL);
} //end if
else if (ent->i.solid == SOLID_BBOX)
{
//if the bounding box size changed
if (!VectorCompare(state->mins, ent->i.mins) ||
!VectorCompare(state->maxs, ent->i.maxs))
{
VectorCopy(state->mins, ent->i.mins);
VectorCopy(state->maxs, ent->i.maxs);
relink = qtrue;
} //end if
VectorCopy(state->angles, ent->i.angles);
} //end if
//if the origin changed
if (!VectorCompare(state->origin, ent->i.origin))
{
VectorCopy(state->origin, ent->i.origin);
relink = qtrue;
} //end if
//if the entity should be relinked
if (relink)
{
//don't link the world model
if (entnum != ENTITYNUM_WORLD)
{
//absolute mins and maxs
VectorAdd(ent->i.mins, ent->i.origin, absmins);
VectorAdd(ent->i.maxs, ent->i.origin, absmaxs);
//unlink the entity
AAS_UnlinkFromAreas(ent->areas);
//relink the entity to the AAS areas (use the larges bbox)
ent->areas = AAS_LinkEntityClientBBox(absmins, absmaxs, entnum, PRESENCE_NORMAL);
//unlink the entity from the BSP leaves
AAS_UnlinkFromBSPLeaves(ent->leaves);
//link the entity to the world BSP tree
ent->leaves = AAS_BSPLinkEntity(absmins, absmaxs, entnum, 0);
} //end if
} //end if
return BLERR_NOERROR;
} //end of the function AAS_UpdateEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityInfo(int entnum, aas_entityinfo_t *info)
{
if (!aasworld.initialized)
{
botimport.Print(PRT_FATAL, "AAS_EntityInfo: aasworld not initialized\n");
Com_Memset(info, 0, sizeof(aas_entityinfo_t));
return;
} //end if
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityInfo: entnum %d out of range\n", entnum);
Com_Memset(info, 0, sizeof(aas_entityinfo_t));
return;
} //end if
Com_Memcpy(info, &aasworld.entities[entnum].i, sizeof(aas_entityinfo_t));
} //end of the function AAS_EntityInfo
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityOrigin(int entnum, vec3_t origin)
{
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityOrigin: entnum %d out of range\n", entnum);
VectorClear(origin);
return;
} //end if
VectorCopy(aasworld.entities[entnum].i.origin, origin);
} //end of the function AAS_EntityOrigin
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityModelindex(int entnum)
{
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityModelindex: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.modelindex;
} //end of the function AAS_EntityModelindex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityType(int entnum)
{
if (!aasworld.initialized) return 0;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityType: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.type;
} //end of the AAS_EntityType
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityModelNum(int entnum)
{
if (!aasworld.initialized) return 0;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityModelNum: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.modelindex;
} //end of the function AAS_EntityModelNum
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OriginOfMoverWithModelNum(int modelnum, vec3_t origin)
{
int i;
aas_entity_t *ent;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (ent->i.type == ET_MOVER)
{
if (ent->i.modelindex == modelnum)
{
VectorCopy(ent->i.origin, origin);
return qtrue;
} //end if
} //end if
} //end for
return qfalse;
} //end of the function AAS_OriginOfMoverWithModelNum
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntitySize(int entnum, vec3_t mins, vec3_t maxs)
{
aas_entity_t *ent;
if (!aasworld.initialized) return;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntitySize: entnum %d out of range\n", entnum);
return;
} //end if
ent = &aasworld.entities[entnum];
VectorCopy(ent->i.mins, mins);
VectorCopy(ent->i.maxs, maxs);
} //end of the function AAS_EntitySize
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityBSPData(int entnum, bsp_entdata_t *entdata)
{
aas_entity_t *ent;
ent = &aasworld.entities[entnum];
VectorCopy(ent->i.origin, entdata->origin);
VectorCopy(ent->i.angles, entdata->angles);
VectorAdd(ent->i.origin, ent->i.mins, entdata->absmins);
VectorAdd(ent->i.origin, ent->i.maxs, entdata->absmaxs);
entdata->solid = ent->i.solid;
entdata->modelnum = ent->i.modelindex - 1;
} //end of the function AAS_EntityBSPData
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ResetEntityLinks(void)
{
int i;
for (i = 0; i < aasworld.maxentities; i++)
{
aasworld.entities[i].areas = NULL;
aasworld.entities[i].leaves = NULL;
} //end for
} //end of the function AAS_ResetEntityLinks
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_InvalidateEntities(void)
{
int i;
for (i = 0; i < aasworld.maxentities; i++)
{
aasworld.entities[i].i.valid = qfalse;
aasworld.entities[i].i.number = i;
} //end for
} //end of the function AAS_InvalidateEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UnlinkInvalidEntities(void)
{
int i;
aas_entity_t *ent;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (!ent->i.valid)
{
AAS_UnlinkFromAreas( ent->areas );
ent->areas = NULL;
AAS_UnlinkFromBSPLeaves( ent->leaves );
ent->leaves = NULL;
} //end for
} //end for
} //end of the function AAS_UnlinkInvalidEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NearestEntity(vec3_t origin, int modelindex)
{
int i, bestentnum;
float dist, bestdist;
aas_entity_t *ent;
vec3_t dir;
bestentnum = 0;
bestdist = 99999;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (ent->i.modelindex != modelindex) continue;
VectorSubtract(ent->i.origin, origin, dir);
if (abs(dir[0]) < 40)
{
if (abs(dir[1]) < 40)
{
dist = VectorLength(dir);
if (dist < bestdist)
{
bestdist = dist;
bestentnum = i;
} //end if
} //end if
} //end if
} //end for
return bestentnum;
} //end of the function AAS_NearestEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BestReachableEntityArea(int entnum)
{
aas_entity_t *ent;
ent = &aasworld.entities[entnum];
return AAS_BestReachableLinkArea(ent->areas);
} //end of the function AAS_BestReachableEntityArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NextEntity(int entnum)
{
if (!aasworld.loaded) return 0;
if (entnum < 0) entnum = -1;
while(++entnum < aasworld.maxentities)
{
if (aasworld.entities[entnum].i.valid) return entnum;
} //end while
return 0;
} //end of the function AAS_NextEntity
/*****************************************************************************
* name: be_aas_entity.c
*
* desc: AAS entities
*
* $Archive: /MissionPack/code/botlib/be_aas_entity.c $
* $Author: Zaphod $
* $Revision: 11 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_utils.h"
#include "l_log.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
#define MASK_SOLID CONTENTS_PLAYERCLIP
//FIXME: these might change
enum {
ET_GENERAL,
ET_PLAYER,
ET_ITEM,
ET_MISSILE,
ET_MOVER
};
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_UpdateEntity(int entnum, bot_entitystate_t *state)
{
int relink;
aas_entity_t *ent;
vec3_t absmins, absmaxs;
if (!aasworld.loaded)
{
botimport.Print(PRT_MESSAGE, "AAS_UpdateEntity: not loaded\n");
return BLERR_NOAASFILE;
} //end if
ent = &aasworld.entities[entnum];
if (!state) {
//unlink the entity
AAS_UnlinkFromAreas(ent->areas);
//unlink the entity from the BSP leaves
AAS_UnlinkFromBSPLeaves(ent->leaves);
//
ent->areas = NULL;
//
ent->leaves = NULL;
return BLERR_NOERROR;
}
ent->i.update_time = AAS_Time() - ent->i.ltime;
ent->i.type = state->type;
ent->i.flags = state->flags;
ent->i.ltime = AAS_Time();
VectorCopy(ent->i.origin, ent->i.lastvisorigin);
VectorCopy(state->old_origin, ent->i.old_origin);
ent->i.solid = state->solid;
ent->i.groundent = state->groundent;
ent->i.modelindex = state->modelindex;
ent->i.modelindex2 = state->modelindex2;
ent->i.frame = state->frame;
ent->i.event = state->event;
ent->i.eventParm = state->eventParm;
ent->i.powerups = state->powerups;
ent->i.weapon = state->weapon;
ent->i.legsAnim = state->legsAnim;
ent->i.torsoAnim = state->torsoAnim;
//number of the entity
ent->i.number = entnum;
//updated so set valid flag
ent->i.valid = qtrue;
//link everything the first frame
if (aasworld.numframes == 1) relink = qtrue;
else relink = qfalse;
//
if (ent->i.solid == SOLID_BSP)
{
//if the angles of the model changed
if (!VectorCompare(state->angles, ent->i.angles))
{
VectorCopy(state->angles, ent->i.angles);
relink = qtrue;
} //end if
//get the mins and maxs of the model
//FIXME: rotate mins and maxs
AAS_BSPModelMinsMaxsOrigin(ent->i.modelindex, ent->i.angles, ent->i.mins, ent->i.maxs, NULL);
} //end if
else if (ent->i.solid == SOLID_BBOX)
{
//if the bounding box size changed
if (!VectorCompare(state->mins, ent->i.mins) ||
!VectorCompare(state->maxs, ent->i.maxs))
{
VectorCopy(state->mins, ent->i.mins);
VectorCopy(state->maxs, ent->i.maxs);
relink = qtrue;
} //end if
VectorCopy(state->angles, ent->i.angles);
} //end if
//if the origin changed
if (!VectorCompare(state->origin, ent->i.origin))
{
VectorCopy(state->origin, ent->i.origin);
relink = qtrue;
} //end if
//if the entity should be relinked
if (relink)
{
//don't link the world model
if (entnum != ENTITYNUM_WORLD)
{
//absolute mins and maxs
VectorAdd(ent->i.mins, ent->i.origin, absmins);
VectorAdd(ent->i.maxs, ent->i.origin, absmaxs);
//unlink the entity
AAS_UnlinkFromAreas(ent->areas);
//relink the entity to the AAS areas (use the larges bbox)
ent->areas = AAS_LinkEntityClientBBox(absmins, absmaxs, entnum, PRESENCE_NORMAL);
//unlink the entity from the BSP leaves
AAS_UnlinkFromBSPLeaves(ent->leaves);
//link the entity to the world BSP tree
ent->leaves = AAS_BSPLinkEntity(absmins, absmaxs, entnum, 0);
} //end if
} //end if
return BLERR_NOERROR;
} //end of the function AAS_UpdateEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityInfo(int entnum, aas_entityinfo_t *info)
{
if (!aasworld.initialized)
{
botimport.Print(PRT_FATAL, "AAS_EntityInfo: aasworld not initialized\n");
Com_Memset(info, 0, sizeof(aas_entityinfo_t));
return;
} //end if
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityInfo: entnum %d out of range\n", entnum);
Com_Memset(info, 0, sizeof(aas_entityinfo_t));
return;
} //end if
Com_Memcpy(info, &aasworld.entities[entnum].i, sizeof(aas_entityinfo_t));
} //end of the function AAS_EntityInfo
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityOrigin(int entnum, vec3_t origin)
{
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityOrigin: entnum %d out of range\n", entnum);
VectorClear(origin);
return;
} //end if
VectorCopy(aasworld.entities[entnum].i.origin, origin);
} //end of the function AAS_EntityOrigin
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityModelindex(int entnum)
{
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityModelindex: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.modelindex;
} //end of the function AAS_EntityModelindex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityType(int entnum)
{
if (!aasworld.initialized) return 0;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityType: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.type;
} //end of the AAS_EntityType
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_EntityModelNum(int entnum)
{
if (!aasworld.initialized) return 0;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntityModelNum: entnum %d out of range\n", entnum);
return 0;
} //end if
return aasworld.entities[entnum].i.modelindex;
} //end of the function AAS_EntityModelNum
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OriginOfMoverWithModelNum(int modelnum, vec3_t origin)
{
int i;
aas_entity_t *ent;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (ent->i.type == ET_MOVER)
{
if (ent->i.modelindex == modelnum)
{
VectorCopy(ent->i.origin, origin);
return qtrue;
} //end if
} //end if
} //end for
return qfalse;
} //end of the function AAS_OriginOfMoverWithModelNum
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntitySize(int entnum, vec3_t mins, vec3_t maxs)
{
aas_entity_t *ent;
if (!aasworld.initialized) return;
if (entnum < 0 || entnum >= aasworld.maxentities)
{
botimport.Print(PRT_FATAL, "AAS_EntitySize: entnum %d out of range\n", entnum);
return;
} //end if
ent = &aasworld.entities[entnum];
VectorCopy(ent->i.mins, mins);
VectorCopy(ent->i.maxs, maxs);
} //end of the function AAS_EntitySize
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_EntityBSPData(int entnum, bsp_entdata_t *entdata)
{
aas_entity_t *ent;
ent = &aasworld.entities[entnum];
VectorCopy(ent->i.origin, entdata->origin);
VectorCopy(ent->i.angles, entdata->angles);
VectorAdd(ent->i.origin, ent->i.mins, entdata->absmins);
VectorAdd(ent->i.origin, ent->i.maxs, entdata->absmaxs);
entdata->solid = ent->i.solid;
entdata->modelnum = ent->i.modelindex - 1;
} //end of the function AAS_EntityBSPData
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ResetEntityLinks(void)
{
int i;
for (i = 0; i < aasworld.maxentities; i++)
{
aasworld.entities[i].areas = NULL;
aasworld.entities[i].leaves = NULL;
} //end for
} //end of the function AAS_ResetEntityLinks
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_InvalidateEntities(void)
{
int i;
for (i = 0; i < aasworld.maxentities; i++)
{
aasworld.entities[i].i.valid = qfalse;
aasworld.entities[i].i.number = i;
} //end for
} //end of the function AAS_InvalidateEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UnlinkInvalidEntities(void)
{
int i;
aas_entity_t *ent;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (!ent->i.valid)
{
AAS_UnlinkFromAreas( ent->areas );
ent->areas = NULL;
AAS_UnlinkFromBSPLeaves( ent->leaves );
ent->leaves = NULL;
} //end for
} //end for
} //end of the function AAS_UnlinkInvalidEntities
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NearestEntity(vec3_t origin, int modelindex)
{
int i, bestentnum;
float dist, bestdist;
aas_entity_t *ent;
vec3_t dir;
bestentnum = 0;
bestdist = 99999;
for (i = 0; i < aasworld.maxentities; i++)
{
ent = &aasworld.entities[i];
if (ent->i.modelindex != modelindex) continue;
VectorSubtract(ent->i.origin, origin, dir);
if (abs(dir[0]) < 40)
{
if (abs(dir[1]) < 40)
{
dist = VectorLength(dir);
if (dist < bestdist)
{
bestdist = dist;
bestentnum = i;
} //end if
} //end if
} //end if
} //end for
return bestentnum;
} //end of the function AAS_NearestEntity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_BestReachableEntityArea(int entnum)
{
aas_entity_t *ent;
ent = &aasworld.entities[entnum];
return AAS_BestReachableLinkArea(ent->areas);
} //end of the function AAS_BestReachableEntityArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_NextEntity(int entnum)
{
if (!aasworld.loaded) return 0;
if (entnum < 0) entnum = -1;
while(++entnum < aasworld.maxentities)
{
if (aasworld.entities[entnum].i.valid) return entnum;
} //end while
return 0;
} //end of the function AAS_NextEntity

View File

@ -1,46 +1,46 @@
/*****************************************************************************
* name: be_aas_entity.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_entity.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//invalidates all entity infos
void AAS_InvalidateEntities(void);
//unlink not updated entities
void AAS_UnlinkInvalidEntities(void);
//resets the entity AAS and BSP links (sets areas and leaves pointers to NULL)
void AAS_ResetEntityLinks(void);
//updates an entity
int AAS_UpdateEntity(int ent, bot_entitystate_t *state);
//gives the entity data used for collision detection
void AAS_EntityBSPData(int entnum, bsp_entdata_t *entdata);
#endif //AASINTERN
//returns the size of the entity bounding box in mins and maxs
void AAS_EntitySize(int entnum, vec3_t mins, vec3_t maxs);
//returns the BSP model number of the entity
int AAS_EntityModelNum(int entnum);
//returns the origin of an entity with the given model number
int AAS_OriginOfMoverWithModelNum(int modelnum, vec3_t origin);
//returns the best reachable area the entity is situated in
int AAS_BestReachableEntityArea(int entnum);
//returns the info of the given entity
void AAS_EntityInfo(int entnum, aas_entityinfo_t *info);
//returns the next entity
int AAS_NextEntity(int entnum);
//returns the origin of the entity
void AAS_EntityOrigin(int entnum, vec3_t origin);
//returns the entity type
int AAS_EntityType(int entnum);
//returns the model index of the entity
int AAS_EntityModelindex(int entnum);
/*****************************************************************************
* name: be_aas_entity.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_entity.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//invalidates all entity infos
void AAS_InvalidateEntities(void);
//unlink not updated entities
void AAS_UnlinkInvalidEntities(void);
//resets the entity AAS and BSP links (sets areas and leaves pointers to NULL)
void AAS_ResetEntityLinks(void);
//updates an entity
int AAS_UpdateEntity(int ent, bot_entitystate_t *state);
//gives the entity data used for collision detection
void AAS_EntityBSPData(int entnum, bsp_entdata_t *entdata);
#endif //AASINTERN
//returns the size of the entity bounding box in mins and maxs
void AAS_EntitySize(int entnum, vec3_t mins, vec3_t maxs);
//returns the BSP model number of the entity
int AAS_EntityModelNum(int entnum);
//returns the origin of an entity with the given model number
int AAS_OriginOfMoverWithModelNum(int modelnum, vec3_t origin);
//returns the best reachable area the entity is situated in
int AAS_BestReachableEntityArea(int entnum);
//returns the info of the given entity
void AAS_EntityInfo(int entnum, aas_entityinfo_t *info);
//returns the next entity
int AAS_NextEntity(int entnum);
//returns the origin of the entity
void AAS_EntityOrigin(int entnum, vec3_t origin);
//returns the entity type
int AAS_EntityType(int entnum);
//returns the model index of the entity
int AAS_EntityModelindex(int entnum);

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/*****************************************************************************
* name: be_aas_file.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_file.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//loads the AAS file with the given name
int AAS_LoadAASFile(char *filename);
//writes an AAS file with the given name
qboolean AAS_WriteAASFile(char *filename);
//dumps the loaded AAS data
void AAS_DumpAASData(void);
//print AAS file information
void AAS_FileInfo(void);
#endif //AASINTERN
/*****************************************************************************
* name: be_aas_file.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_file.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//loads the AAS file with the given name
int AAS_LoadAASFile(char *filename);
//writes an AAS file with the given name
qboolean AAS_WriteAASFile(char *filename);
//dumps the loaded AAS data
void AAS_DumpAASData(void);
//print AAS file information
void AAS_FileInfo(void);
#endif //AASINTERN

View File

@ -1,30 +1,30 @@
/*****************************************************************************
* name: be_aas_funcs.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_funcs.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifndef BSPCINCLUDE
#include "be_aas_main.h"
#include "be_aas_entity.h"
#include "be_aas_sample.h"
#include "be_aas_cluster.h"
#include "be_aas_reach.h"
#include "be_aas_route.h"
#include "be_aas_routealt.h"
#include "be_aas_debug.h"
#include "be_aas_file.h"
#include "be_aas_optimize.h"
#include "be_aas_bsp.h"
#include "be_aas_move.h"
#endif //BSPCINCLUDE
/*****************************************************************************
* name: be_aas_funcs.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_funcs.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifndef BSPCINCLUDE
#include "be_aas_main.h"
#include "be_aas_entity.h"
#include "be_aas_sample.h"
#include "be_aas_cluster.h"
#include "be_aas_reach.h"
#include "be_aas_route.h"
#include "be_aas_routealt.h"
#include "be_aas_debug.h"
#include "be_aas_file.h"
#include "be_aas_optimize.h"
#include "be_aas_bsp.h"
#include "be_aas_move.h"
#endif //BSPCINCLUDE

View File

@ -1,412 +1,412 @@
/*****************************************************************************
* name: be_aas_main.c
*
* desc: AAS
*
* $Archive: /MissionPack/code/botlib/be_aas_main.c $
* $Author: Mrelusive $
* $Revision: 8 $
* $Modtime: 11/28/00 7:52a $
* $Date: 11/28/00 7:52a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_libvar.h"
#include "l_utils.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_log.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
aas_t aasworld;
libvar_t *saveroutingcache;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void QDECL AAS_Error(char *fmt, ...)
{
char str[1024];
va_list arglist;
va_start(arglist, fmt);
vsprintf(str, fmt, arglist);
va_end(arglist);
botimport.Print(PRT_FATAL, str);
} //end of the function AAS_Error
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
char *AAS_StringFromIndex(char *indexname, char *stringindex[], int numindexes, int index)
{
if (!aasworld.indexessetup)
{
botimport.Print(PRT_ERROR, "%s: index %d not setup\n", indexname, index);
return "";
} //end if
if (index < 0 || index >= numindexes)
{
botimport.Print(PRT_ERROR, "%s: index %d out of range\n", indexname, index);
return "";
} //end if
if (!stringindex[index])
{
if (index)
{
botimport.Print(PRT_ERROR, "%s: reference to unused index %d\n", indexname, index);
} //end if
return "";
} //end if
return stringindex[index];
} //end of the function AAS_StringFromIndex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IndexFromString(char *indexname, char *stringindex[], int numindexes, char *string)
{
int i;
if (!aasworld.indexessetup)
{
botimport.Print(PRT_ERROR, "%s: index not setup \"%s\"\n", indexname, string);
return 0;
} //end if
for (i = 0; i < numindexes; i++)
{
if (!stringindex[i]) continue;
if (!Q_stricmp(stringindex[i], string)) return i;
} //end for
return 0;
} //end of the function AAS_IndexFromString
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
char *AAS_ModelFromIndex(int index)
{
return AAS_StringFromIndex("ModelFromIndex", &aasworld.configstrings[CS_MODELS], MAX_MODELS, index);
} //end of the function AAS_ModelFromIndex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IndexFromModel(char *modelname)
{
return AAS_IndexFromString("IndexFromModel", &aasworld.configstrings[CS_MODELS], MAX_MODELS, modelname);
} //end of the function AAS_IndexFromModel
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UpdateStringIndexes(int numconfigstrings, char *configstrings[])
{
int i;
//set string pointers and copy the strings
for (i = 0; i < numconfigstrings; i++)
{
if (configstrings[i])
{
//if (aasworld.configstrings[i]) FreeMemory(aasworld.configstrings[i]);
aasworld.configstrings[i] = (char *) GetMemory(strlen(configstrings[i]) + 1);
strcpy(aasworld.configstrings[i], configstrings[i]);
} //end if
} //end for
aasworld.indexessetup = qtrue;
} //end of the function AAS_UpdateStringIndexes
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Loaded(void)
{
return aasworld.loaded;
} //end of the function AAS_Loaded
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Initialized(void)
{
return aasworld.initialized;
} //end of the function AAS_Initialized
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_SetInitialized(void)
{
aasworld.initialized = qtrue;
botimport.Print(PRT_MESSAGE, "AAS initialized.\n");
#ifdef DEBUG
//create all the routing cache
//AAS_CreateAllRoutingCache();
//
//AAS_RoutingInfo();
#endif
} //end of the function AAS_SetInitialized
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ContinueInit(float time)
{
//if no AAS file loaded
if (!aasworld.loaded) return;
//if AAS is already initialized
if (aasworld.initialized) return;
//calculate reachability, if not finished return
if (AAS_ContinueInitReachability(time)) return;
//initialize clustering for the new map
AAS_InitClustering();
//if reachability has been calculated and an AAS file should be written
//or there is a forced data optimization
if (aasworld.savefile || ((int)LibVarGetValue("forcewrite")))
{
//optimize the AAS data
if ((int)LibVarValue("aasoptimize", "0")) AAS_Optimize();
//save the AAS file
if (AAS_WriteAASFile(aasworld.filename))
{
botimport.Print(PRT_MESSAGE, "%s written succesfully\n", aasworld.filename);
} //end if
else
{
botimport.Print(PRT_ERROR, "couldn't write %s\n", aasworld.filename);
} //end else
} //end if
//initialize the routing
AAS_InitRouting();
//at this point AAS is initialized
AAS_SetInitialized();
} //end of the function AAS_ContinueInit
//===========================================================================
// called at the start of every frame
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_StartFrame(float time)
{
aasworld.time = time;
//unlink all entities that were not updated last frame
AAS_UnlinkInvalidEntities();
//invalidate the entities
AAS_InvalidateEntities();
//initialize AAS
AAS_ContinueInit(time);
//
aasworld.frameroutingupdates = 0;
//
if (bot_developer)
{
if (LibVarGetValue("showcacheupdates"))
{
AAS_RoutingInfo();
LibVarSet("showcacheupdates", "0");
} //end if
if (LibVarGetValue("showmemoryusage"))
{
PrintUsedMemorySize();
LibVarSet("showmemoryusage", "0");
} //end if
if (LibVarGetValue("memorydump"))
{
PrintMemoryLabels();
LibVarSet("memorydump", "0");
} //end if
} //end if
//
if (saveroutingcache->value)
{
AAS_WriteRouteCache();
LibVarSet("saveroutingcache", "0");
} //end if
//
aasworld.numframes++;
return BLERR_NOERROR;
} //end of the function AAS_StartFrame
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_Time(void)
{
return aasworld.time;
} //end of the function AAS_Time
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj )
{
vec3_t pVec, vec;
VectorSubtract( point, vStart, pVec );
VectorSubtract( vEnd, vStart, vec );
VectorNormalize( vec );
// project onto the directional vector for this segment
VectorMA( vStart, DotProduct( pVec, vec ), vec, vProj );
} //end of the function AAS_ProjectPointOntoVector
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadFiles(const char *mapname)
{
int errnum;
char aasfile[MAX_PATH];
// char bspfile[MAX_PATH];
strcpy(aasworld.mapname, mapname);
//NOTE: first reset the entity links into the AAS areas and BSP leaves
// the AAS link heap and BSP link heap are reset after respectively the
// AAS file and BSP file are loaded
AAS_ResetEntityLinks();
// load bsp info
AAS_LoadBSPFile();
//load the aas file
Com_sprintf(aasfile, MAX_PATH, "maps/%s.aas", mapname);
errnum = AAS_LoadAASFile(aasfile);
if (errnum != BLERR_NOERROR)
return errnum;
botimport.Print(PRT_MESSAGE, "loaded %s\n", aasfile);
strncpy(aasworld.filename, aasfile, MAX_PATH);
return BLERR_NOERROR;
} //end of the function AAS_LoadFiles
//===========================================================================
// called everytime a map changes
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadMap(const char *mapname)
{
int errnum;
//if no mapname is provided then the string indexes are updated
if (!mapname)
{
return 0;
} //end if
//
aasworld.initialized = qfalse;
//NOTE: free the routing caches before loading a new map because
// to free the caches the old number of areas, number of clusters
// and number of areas in a clusters must be available
AAS_FreeRoutingCaches();
//load the map
errnum = AAS_LoadFiles(mapname);
if (errnum != BLERR_NOERROR)
{
aasworld.loaded = qfalse;
return errnum;
} //end if
//
AAS_InitSettings();
//initialize the AAS link heap for the new map
AAS_InitAASLinkHeap();
//initialize the AAS linked entities for the new map
AAS_InitAASLinkedEntities();
//initialize reachability for the new map
AAS_InitReachability();
//initialize the alternative routing
AAS_InitAlternativeRouting();
//everything went ok
return 0;
} //end of the function AAS_LoadMap
//===========================================================================
// called when the library is first loaded
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Setup(void)
{
aasworld.maxclients = (int) LibVarValue("maxclients", "128");
aasworld.maxentities = (int) LibVarValue("maxentities", "1024");
// as soon as it's set to 1 the routing cache will be saved
saveroutingcache = LibVar("saveroutingcache", "0");
//allocate memory for the entities
if (aasworld.entities) FreeMemory(aasworld.entities);
aasworld.entities = (aas_entity_t *) GetClearedHunkMemory(aasworld.maxentities * sizeof(aas_entity_t));
//invalidate all the entities
AAS_InvalidateEntities();
//force some recalculations
//LibVarSet("forceclustering", "1"); //force clustering calculation
//LibVarSet("forcereachability", "1"); //force reachability calculation
aasworld.numframes = 0;
return BLERR_NOERROR;
} //end of the function AAS_Setup
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_Shutdown(void)
{
AAS_ShutdownAlternativeRouting();
//
AAS_DumpBSPData();
//free routing caches
AAS_FreeRoutingCaches();
//free aas link heap
AAS_FreeAASLinkHeap();
//free aas linked entities
AAS_FreeAASLinkedEntities();
//free the aas data
AAS_DumpAASData();
//free the entities
if (aasworld.entities) FreeMemory(aasworld.entities);
//clear the aasworld structure
Com_Memset(&aasworld, 0, sizeof(aas_t));
//aas has not been initialized
aasworld.initialized = qfalse;
//NOTE: as soon as a new .bsp file is loaded the .bsp file memory is
// freed an reallocated, so there's no need to free that memory here
//print shutdown
botimport.Print(PRT_MESSAGE, "AAS shutdown.\n");
} //end of the function AAS_Shutdown
/*****************************************************************************
* name: be_aas_main.c
*
* desc: AAS
*
* $Archive: /MissionPack/code/botlib/be_aas_main.c $
* $Author: Mrelusive $
* $Revision: 8 $
* $Modtime: 11/28/00 7:52a $
* $Date: 11/28/00 7:52a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_libvar.h"
#include "l_utils.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_log.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
aas_t aasworld;
libvar_t *saveroutingcache;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void QDECL AAS_Error(char *fmt, ...)
{
char str[1024];
va_list arglist;
va_start(arglist, fmt);
vsprintf(str, fmt, arglist);
va_end(arglist);
botimport.Print(PRT_FATAL, str);
} //end of the function AAS_Error
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
char *AAS_StringFromIndex(char *indexname, char *stringindex[], int numindexes, int index)
{
if (!aasworld.indexessetup)
{
botimport.Print(PRT_ERROR, "%s: index %d not setup\n", indexname, index);
return "";
} //end if
if (index < 0 || index >= numindexes)
{
botimport.Print(PRT_ERROR, "%s: index %d out of range\n", indexname, index);
return "";
} //end if
if (!stringindex[index])
{
if (index)
{
botimport.Print(PRT_ERROR, "%s: reference to unused index %d\n", indexname, index);
} //end if
return "";
} //end if
return stringindex[index];
} //end of the function AAS_StringFromIndex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IndexFromString(char *indexname, char *stringindex[], int numindexes, char *string)
{
int i;
if (!aasworld.indexessetup)
{
botimport.Print(PRT_ERROR, "%s: index not setup \"%s\"\n", indexname, string);
return 0;
} //end if
for (i = 0; i < numindexes; i++)
{
if (!stringindex[i]) continue;
if (!Q_stricmp(stringindex[i], string)) return i;
} //end for
return 0;
} //end of the function AAS_IndexFromString
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
char *AAS_ModelFromIndex(int index)
{
return AAS_StringFromIndex("ModelFromIndex", &aasworld.configstrings[CS_MODELS], MAX_MODELS, index);
} //end of the function AAS_ModelFromIndex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_IndexFromModel(char *modelname)
{
return AAS_IndexFromString("IndexFromModel", &aasworld.configstrings[CS_MODELS], MAX_MODELS, modelname);
} //end of the function AAS_IndexFromModel
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_UpdateStringIndexes(int numconfigstrings, char *configstrings[])
{
int i;
//set string pointers and copy the strings
for (i = 0; i < numconfigstrings; i++)
{
if (configstrings[i])
{
//if (aasworld.configstrings[i]) FreeMemory(aasworld.configstrings[i]);
aasworld.configstrings[i] = (char *) GetMemory(strlen(configstrings[i]) + 1);
strcpy(aasworld.configstrings[i], configstrings[i]);
} //end if
} //end for
aasworld.indexessetup = qtrue;
} //end of the function AAS_UpdateStringIndexes
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Loaded(void)
{
return aasworld.loaded;
} //end of the function AAS_Loaded
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Initialized(void)
{
return aasworld.initialized;
} //end of the function AAS_Initialized
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_SetInitialized(void)
{
aasworld.initialized = qtrue;
botimport.Print(PRT_MESSAGE, "AAS initialized.\n");
#ifdef DEBUG
//create all the routing cache
//AAS_CreateAllRoutingCache();
//
//AAS_RoutingInfo();
#endif
} //end of the function AAS_SetInitialized
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ContinueInit(float time)
{
//if no AAS file loaded
if (!aasworld.loaded) return;
//if AAS is already initialized
if (aasworld.initialized) return;
//calculate reachability, if not finished return
if (AAS_ContinueInitReachability(time)) return;
//initialize clustering for the new map
AAS_InitClustering();
//if reachability has been calculated and an AAS file should be written
//or there is a forced data optimization
if (aasworld.savefile || ((int)LibVarGetValue("forcewrite")))
{
//optimize the AAS data
if ((int)LibVarValue("aasoptimize", "0")) AAS_Optimize();
//save the AAS file
if (AAS_WriteAASFile(aasworld.filename))
{
botimport.Print(PRT_MESSAGE, "%s written succesfully\n", aasworld.filename);
} //end if
else
{
botimport.Print(PRT_ERROR, "couldn't write %s\n", aasworld.filename);
} //end else
} //end if
//initialize the routing
AAS_InitRouting();
//at this point AAS is initialized
AAS_SetInitialized();
} //end of the function AAS_ContinueInit
//===========================================================================
// called at the start of every frame
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_StartFrame(float time)
{
aasworld.time = time;
//unlink all entities that were not updated last frame
AAS_UnlinkInvalidEntities();
//invalidate the entities
AAS_InvalidateEntities();
//initialize AAS
AAS_ContinueInit(time);
//
aasworld.frameroutingupdates = 0;
//
if (bot_developer)
{
if (LibVarGetValue("showcacheupdates"))
{
AAS_RoutingInfo();
LibVarSet("showcacheupdates", "0");
} //end if
if (LibVarGetValue("showmemoryusage"))
{
PrintUsedMemorySize();
LibVarSet("showmemoryusage", "0");
} //end if
if (LibVarGetValue("memorydump"))
{
PrintMemoryLabels();
LibVarSet("memorydump", "0");
} //end if
} //end if
//
if (saveroutingcache->value)
{
AAS_WriteRouteCache();
LibVarSet("saveroutingcache", "0");
} //end if
//
aasworld.numframes++;
return BLERR_NOERROR;
} //end of the function AAS_StartFrame
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_Time(void)
{
return aasworld.time;
} //end of the function AAS_Time
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj )
{
vec3_t pVec, vec;
VectorSubtract( point, vStart, pVec );
VectorSubtract( vEnd, vStart, vec );
VectorNormalize( vec );
// project onto the directional vector for this segment
VectorMA( vStart, DotProduct( pVec, vec ), vec, vProj );
} //end of the function AAS_ProjectPointOntoVector
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadFiles(const char *mapname)
{
int errnum;
char aasfile[MAX_PATH];
// char bspfile[MAX_PATH];
strcpy(aasworld.mapname, mapname);
//NOTE: first reset the entity links into the AAS areas and BSP leaves
// the AAS link heap and BSP link heap are reset after respectively the
// AAS file and BSP file are loaded
AAS_ResetEntityLinks();
// load bsp info
AAS_LoadBSPFile();
//load the aas file
Com_sprintf(aasfile, MAX_PATH, "maps/%s.aas", mapname);
errnum = AAS_LoadAASFile(aasfile);
if (errnum != BLERR_NOERROR)
return errnum;
botimport.Print(PRT_MESSAGE, "loaded %s\n", aasfile);
strncpy(aasworld.filename, aasfile, MAX_PATH);
return BLERR_NOERROR;
} //end of the function AAS_LoadFiles
//===========================================================================
// called everytime a map changes
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_LoadMap(const char *mapname)
{
int errnum;
//if no mapname is provided then the string indexes are updated
if (!mapname)
{
return 0;
} //end if
//
aasworld.initialized = qfalse;
//NOTE: free the routing caches before loading a new map because
// to free the caches the old number of areas, number of clusters
// and number of areas in a clusters must be available
AAS_FreeRoutingCaches();
//load the map
errnum = AAS_LoadFiles(mapname);
if (errnum != BLERR_NOERROR)
{
aasworld.loaded = qfalse;
return errnum;
} //end if
//
AAS_InitSettings();
//initialize the AAS link heap for the new map
AAS_InitAASLinkHeap();
//initialize the AAS linked entities for the new map
AAS_InitAASLinkedEntities();
//initialize reachability for the new map
AAS_InitReachability();
//initialize the alternative routing
AAS_InitAlternativeRouting();
//everything went ok
return 0;
} //end of the function AAS_LoadMap
//===========================================================================
// called when the library is first loaded
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Setup(void)
{
aasworld.maxclients = (int) LibVarValue("maxclients", "128");
aasworld.maxentities = (int) LibVarValue("maxentities", "1024");
// as soon as it's set to 1 the routing cache will be saved
saveroutingcache = LibVar("saveroutingcache", "0");
//allocate memory for the entities
if (aasworld.entities) FreeMemory(aasworld.entities);
aasworld.entities = (aas_entity_t *) GetClearedHunkMemory(aasworld.maxentities * sizeof(aas_entity_t));
//invalidate all the entities
AAS_InvalidateEntities();
//force some recalculations
//LibVarSet("forceclustering", "1"); //force clustering calculation
//LibVarSet("forcereachability", "1"); //force reachability calculation
aasworld.numframes = 0;
return BLERR_NOERROR;
} //end of the function AAS_Setup
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_Shutdown(void)
{
AAS_ShutdownAlternativeRouting();
//
AAS_DumpBSPData();
//free routing caches
AAS_FreeRoutingCaches();
//free aas link heap
AAS_FreeAASLinkHeap();
//free aas linked entities
AAS_FreeAASLinkedEntities();
//free the aas data
AAS_DumpAASData();
//free the entities
if (aasworld.entities) FreeMemory(aasworld.entities);
//clear the aasworld structure
Com_Memset(&aasworld, 0, sizeof(aas_t));
//aas has not been initialized
aasworld.initialized = qfalse;
//NOTE: as soon as a new .bsp file is loaded the .bsp file memory is
// freed an reallocated, so there's no need to free that memory here
//print shutdown
botimport.Print(PRT_MESSAGE, "AAS shutdown.\n");
} //end of the function AAS_Shutdown

View File

@ -1,44 +1,44 @@
/*****************************************************************************
* name: be_aas_main.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_main.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
extern aas_t aasworld;
//AAS error message
void QDECL AAS_Error(char *fmt, ...);
//set AAS initialized
void AAS_SetInitialized(void);
//setup AAS with the given number of entities and clients
int AAS_Setup(void);
//shutdown AAS
void AAS_Shutdown(void);
//start a new map
int AAS_LoadMap(const char *mapname);
//start a new time frame
int AAS_StartFrame(float time);
#endif //AASINTERN
//returns true if AAS is initialized
int AAS_Initialized(void);
//returns true if the AAS file is loaded
int AAS_Loaded(void);
//returns the model name from the given index
char *AAS_ModelFromIndex(int index);
//returns the index from the given model name
int AAS_IndexFromModel(char *modelname);
//returns the current time
float AAS_Time(void);
//
void AAS_ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj );
/*****************************************************************************
* name: be_aas_main.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_main.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
extern aas_t aasworld;
//AAS error message
void QDECL AAS_Error(char *fmt, ...);
//set AAS initialized
void AAS_SetInitialized(void);
//setup AAS with the given number of entities and clients
int AAS_Setup(void);
//shutdown AAS
void AAS_Shutdown(void);
//start a new map
int AAS_LoadMap(const char *mapname);
//start a new time frame
int AAS_StartFrame(float time);
#endif //AASINTERN
//returns true if AAS is initialized
int AAS_Initialized(void);
//returns true if the AAS file is loaded
int AAS_Loaded(void);
//returns the model name from the given index
char *AAS_ModelFromIndex(int index);
//returns the index from the given model name
int AAS_IndexFromModel(char *modelname);
//returns the current time
float AAS_Time(void);
//
void AAS_ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj );

File diff suppressed because it is too large Load Diff

View File

@ -1,54 +1,54 @@
/*****************************************************************************
* name: be_aas_move.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_move.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
extern aas_settings_t aassettings;
#endif //AASINTERN
//movement prediction
int AAS_PredictClientMovement(struct aas_clientmove_s *move,
int entnum, vec3_t origin,
int presencetype, int onground,
vec3_t velocity, vec3_t cmdmove,
int cmdframes,
int maxframes, float frametime,
int stopevent, int stopareanum, int visualize);
//predict movement until bounding box is hit
int AAS_ClientMovementHitBBox(struct aas_clientmove_s *move,
int entnum, vec3_t origin,
int presencetype, int onground,
vec3_t velocity, vec3_t cmdmove,
int cmdframes,
int maxframes, float frametime,
vec3_t mins, vec3_t maxs, int visualize);
//returns true if on the ground at the given origin
int AAS_OnGround(vec3_t origin, int presencetype, int passent);
//returns true if swimming at the given origin
int AAS_Swimming(vec3_t origin);
//returns the jump reachability run start point
void AAS_JumpReachRunStart(struct aas_reachability_s *reach, vec3_t runstart);
//returns true if against a ladder at the given origin
int AAS_AgainstLadder(vec3_t origin);
//rocket jump Z velocity when rocket-jumping at origin
float AAS_RocketJumpZVelocity(vec3_t origin);
//bfg jump Z velocity when bfg-jumping at origin
float AAS_BFGJumpZVelocity(vec3_t origin);
//calculates the horizontal velocity needed for a jump and returns true this velocity could be calculated
int AAS_HorizontalVelocityForJump(float zvel, vec3_t start, vec3_t end, float *velocity);
//
void AAS_SetMovedir(vec3_t angles, vec3_t movedir);
//
int AAS_DropToFloor(vec3_t origin, vec3_t mins, vec3_t maxs);
//
void AAS_InitSettings(void);
/*****************************************************************************
* name: be_aas_move.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_move.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
extern aas_settings_t aassettings;
#endif //AASINTERN
//movement prediction
int AAS_PredictClientMovement(struct aas_clientmove_s *move,
int entnum, vec3_t origin,
int presencetype, int onground,
vec3_t velocity, vec3_t cmdmove,
int cmdframes,
int maxframes, float frametime,
int stopevent, int stopareanum, int visualize);
//predict movement until bounding box is hit
int AAS_ClientMovementHitBBox(struct aas_clientmove_s *move,
int entnum, vec3_t origin,
int presencetype, int onground,
vec3_t velocity, vec3_t cmdmove,
int cmdframes,
int maxframes, float frametime,
vec3_t mins, vec3_t maxs, int visualize);
//returns true if on the ground at the given origin
int AAS_OnGround(vec3_t origin, int presencetype, int passent);
//returns true if swimming at the given origin
int AAS_Swimming(vec3_t origin);
//returns the jump reachability run start point
void AAS_JumpReachRunStart(struct aas_reachability_s *reach, vec3_t runstart);
//returns true if against a ladder at the given origin
int AAS_AgainstLadder(vec3_t origin);
//rocket jump Z velocity when rocket-jumping at origin
float AAS_RocketJumpZVelocity(vec3_t origin);
//bfg jump Z velocity when bfg-jumping at origin
float AAS_BFGJumpZVelocity(vec3_t origin);
//calculates the horizontal velocity needed for a jump and returns true this velocity could be calculated
int AAS_HorizontalVelocityForJump(float zvel, vec3_t start, vec3_t end, float *velocity);
//
void AAS_SetMovedir(vec3_t angles, vec3_t movedir);
//
int AAS_DropToFloor(vec3_t origin, vec3_t mins, vec3_t maxs);
//
void AAS_InitSettings(void);

View File

@ -1,295 +1,295 @@
/*****************************************************************************
* name: be_aas_optimize.c
*
* desc: decreases the .aas file size after the reachabilities have
* been calculated, just dumps all the faces, edges and vertexes
*
* $Archive: /MissionPack/code/botlib/be_aas_optimize.c $
* $Author: Zaphod $
* $Revision: 5 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_libvar.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
typedef struct optimized_s
{
//vertexes
int numvertexes;
aas_vertex_t *vertexes;
//edges
int numedges;
aas_edge_t *edges;
//edge index
int edgeindexsize;
aas_edgeindex_t *edgeindex;
//faces
int numfaces;
aas_face_t *faces;
//face index
int faceindexsize;
aas_faceindex_t *faceindex;
//convex areas
int numareas;
aas_area_t *areas;
//
int *vertexoptimizeindex;
int *edgeoptimizeindex;
int *faceoptimizeindex;
} optimized_t;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_KeepEdge(aas_edge_t *edge)
{
return 1;
} //end of the function AAS_KeepFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OptimizeEdge(optimized_t *optimized, int edgenum)
{
int i, optedgenum;
aas_edge_t *edge, *optedge;
edge = &aasworld.edges[abs(edgenum)];
if (!AAS_KeepEdge(edge)) return 0;
optedgenum = optimized->edgeoptimizeindex[abs(edgenum)];
if (optedgenum)
{
//keep the edge reversed sign
if (edgenum > 0) return optedgenum;
else return -optedgenum;
} //end if
optedge = &optimized->edges[optimized->numedges];
for (i = 0; i < 2; i++)
{
if (optimized->vertexoptimizeindex[edge->v[i]])
{
optedge->v[i] = optimized->vertexoptimizeindex[edge->v[i]];
} //end if
else
{
VectorCopy(aasworld.vertexes[edge->v[i]], optimized->vertexes[optimized->numvertexes]);
optedge->v[i] = optimized->numvertexes;
optimized->vertexoptimizeindex[edge->v[i]] = optimized->numvertexes;
optimized->numvertexes++;
} //end else
} //end for
optimized->edgeoptimizeindex[abs(edgenum)] = optimized->numedges;
optedgenum = optimized->numedges;
optimized->numedges++;
//keep the edge reversed sign
if (edgenum > 0) return optedgenum;
else return -optedgenum;
} //end of the function AAS_OptimizeEdge
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_KeepFace(aas_face_t *face)
{
if (!(face->faceflags & FACE_LADDER)) return 0;
else return 1;
} //end of the function AAS_KeepFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OptimizeFace(optimized_t *optimized, int facenum)
{
int i, edgenum, optedgenum, optfacenum;
aas_face_t *face, *optface;
face = &aasworld.faces[abs(facenum)];
if (!AAS_KeepFace(face)) return 0;
optfacenum = optimized->faceoptimizeindex[abs(facenum)];
if (optfacenum)
{
//keep the face side sign
if (facenum > 0) return optfacenum;
else return -optfacenum;
} //end if
optface = &optimized->faces[optimized->numfaces];
Com_Memcpy(optface, face, sizeof(aas_face_t));
optface->numedges = 0;
optface->firstedge = optimized->edgeindexsize;
for (i = 0; i < face->numedges; i++)
{
edgenum = aasworld.edgeindex[face->firstedge + i];
optedgenum = AAS_OptimizeEdge(optimized, edgenum);
if (optedgenum)
{
optimized->edgeindex[optface->firstedge + optface->numedges] = optedgenum;
optface->numedges++;
optimized->edgeindexsize++;
} //end if
} //end for
optimized->faceoptimizeindex[abs(facenum)] = optimized->numfaces;
optfacenum = optimized->numfaces;
optimized->numfaces++;
//keep the face side sign
if (facenum > 0) return optfacenum;
else return -optfacenum;
} //end of the function AAS_OptimizeFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeArea(optimized_t *optimized, int areanum)
{
int i, facenum, optfacenum;
aas_area_t *area, *optarea;
area = &aasworld.areas[areanum];
optarea = &optimized->areas[areanum];
Com_Memcpy(optarea, area, sizeof(aas_area_t));
optarea->numfaces = 0;
optarea->firstface = optimized->faceindexsize;
for (i = 0; i < area->numfaces; i++)
{
facenum = aasworld.faceindex[area->firstface + i];
optfacenum = AAS_OptimizeFace(optimized, facenum);
if (optfacenum)
{
optimized->faceindex[optarea->firstface + optarea->numfaces] = optfacenum;
optarea->numfaces++;
optimized->faceindexsize++;
} //end if
} //end for
} //end of the function AAS_OptimizeArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeAlloc(optimized_t *optimized)
{
optimized->vertexes = (aas_vertex_t *) GetClearedMemory(aasworld.numvertexes * sizeof(aas_vertex_t));
optimized->numvertexes = 0;
optimized->edges = (aas_edge_t *) GetClearedMemory(aasworld.numedges * sizeof(aas_edge_t));
optimized->numedges = 1; //edge zero is a dummy
optimized->edgeindex = (aas_edgeindex_t *) GetClearedMemory(aasworld.edgeindexsize * sizeof(aas_edgeindex_t));
optimized->edgeindexsize = 0;
optimized->faces = (aas_face_t *) GetClearedMemory(aasworld.numfaces * sizeof(aas_face_t));
optimized->numfaces = 1; //face zero is a dummy
optimized->faceindex = (aas_faceindex_t *) GetClearedMemory(aasworld.faceindexsize * sizeof(aas_faceindex_t));
optimized->faceindexsize = 0;
optimized->areas = (aas_area_t *) GetClearedMemory(aasworld.numareas * sizeof(aas_area_t));
optimized->numareas = aasworld.numareas;
//
optimized->vertexoptimizeindex = (int *) GetClearedMemory(aasworld.numvertexes * sizeof(int));
optimized->edgeoptimizeindex = (int *) GetClearedMemory(aasworld.numedges * sizeof(int));
optimized->faceoptimizeindex = (int *) GetClearedMemory(aasworld.numfaces * sizeof(int));
} //end of the function AAS_OptimizeAlloc
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeStore(optimized_t *optimized)
{
//store the optimized vertexes
if (aasworld.vertexes) FreeMemory(aasworld.vertexes);
aasworld.vertexes = optimized->vertexes;
aasworld.numvertexes = optimized->numvertexes;
//store the optimized edges
if (aasworld.edges) FreeMemory(aasworld.edges);
aasworld.edges = optimized->edges;
aasworld.numedges = optimized->numedges;
//store the optimized edge index
if (aasworld.edgeindex) FreeMemory(aasworld.edgeindex);
aasworld.edgeindex = optimized->edgeindex;
aasworld.edgeindexsize = optimized->edgeindexsize;
//store the optimized faces
if (aasworld.faces) FreeMemory(aasworld.faces);
aasworld.faces = optimized->faces;
aasworld.numfaces = optimized->numfaces;
//store the optimized face index
if (aasworld.faceindex) FreeMemory(aasworld.faceindex);
aasworld.faceindex = optimized->faceindex;
aasworld.faceindexsize = optimized->faceindexsize;
//store the optimized areas
if (aasworld.areas) FreeMemory(aasworld.areas);
aasworld.areas = optimized->areas;
aasworld.numareas = optimized->numareas;
//free optimize indexes
FreeMemory(optimized->vertexoptimizeindex);
FreeMemory(optimized->edgeoptimizeindex);
FreeMemory(optimized->faceoptimizeindex);
} //end of the function AAS_OptimizeStore
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_Optimize(void)
{
int i, sign;
optimized_t optimized;
AAS_OptimizeAlloc(&optimized);
for (i = 1; i < aasworld.numareas; i++)
{
AAS_OptimizeArea(&optimized, i);
} //end for
//reset the reachability face pointers
for (i = 0; i < aasworld.reachabilitysize; i++)
{
//NOTE: for TRAVEL_ELEVATOR the facenum is the model number of
// the elevator
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR) continue;
//NOTE: for TRAVEL_JUMPPAD the facenum is the Z velocity and the edgenum is the hor velocity
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_JUMPPAD) continue;
//NOTE: for TRAVEL_FUNCBOB the facenum and edgenum contain other coded information
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_FUNCBOB) continue;
//
sign = aasworld.reachability[i].facenum;
aasworld.reachability[i].facenum = optimized.faceoptimizeindex[abs(aasworld.reachability[i].facenum)];
if (sign < 0) aasworld.reachability[i].facenum = -aasworld.reachability[i].facenum;
sign = aasworld.reachability[i].edgenum;
aasworld.reachability[i].edgenum = optimized.edgeoptimizeindex[abs(aasworld.reachability[i].edgenum)];
if (sign < 0) aasworld.reachability[i].edgenum = -aasworld.reachability[i].edgenum;
} //end for
//store the optimized AAS data into aasworld
AAS_OptimizeStore(&optimized);
//print some nice stuff :)
botimport.Print(PRT_MESSAGE, "AAS data optimized.\n");
} //end of the function AAS_Optimize
/*****************************************************************************
* name: be_aas_optimize.c
*
* desc: decreases the .aas file size after the reachabilities have
* been calculated, just dumps all the faces, edges and vertexes
*
* $Archive: /MissionPack/code/botlib/be_aas_optimize.c $
* $Author: Zaphod $
* $Revision: 5 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_libvar.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
typedef struct optimized_s
{
//vertexes
int numvertexes;
aas_vertex_t *vertexes;
//edges
int numedges;
aas_edge_t *edges;
//edge index
int edgeindexsize;
aas_edgeindex_t *edgeindex;
//faces
int numfaces;
aas_face_t *faces;
//face index
int faceindexsize;
aas_faceindex_t *faceindex;
//convex areas
int numareas;
aas_area_t *areas;
//
int *vertexoptimizeindex;
int *edgeoptimizeindex;
int *faceoptimizeindex;
} optimized_t;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_KeepEdge(aas_edge_t *edge)
{
return 1;
} //end of the function AAS_KeepFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OptimizeEdge(optimized_t *optimized, int edgenum)
{
int i, optedgenum;
aas_edge_t *edge, *optedge;
edge = &aasworld.edges[abs(edgenum)];
if (!AAS_KeepEdge(edge)) return 0;
optedgenum = optimized->edgeoptimizeindex[abs(edgenum)];
if (optedgenum)
{
//keep the edge reversed sign
if (edgenum > 0) return optedgenum;
else return -optedgenum;
} //end if
optedge = &optimized->edges[optimized->numedges];
for (i = 0; i < 2; i++)
{
if (optimized->vertexoptimizeindex[edge->v[i]])
{
optedge->v[i] = optimized->vertexoptimizeindex[edge->v[i]];
} //end if
else
{
VectorCopy(aasworld.vertexes[edge->v[i]], optimized->vertexes[optimized->numvertexes]);
optedge->v[i] = optimized->numvertexes;
optimized->vertexoptimizeindex[edge->v[i]] = optimized->numvertexes;
optimized->numvertexes++;
} //end else
} //end for
optimized->edgeoptimizeindex[abs(edgenum)] = optimized->numedges;
optedgenum = optimized->numedges;
optimized->numedges++;
//keep the edge reversed sign
if (edgenum > 0) return optedgenum;
else return -optedgenum;
} //end of the function AAS_OptimizeEdge
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_KeepFace(aas_face_t *face)
{
if (!(face->faceflags & FACE_LADDER)) return 0;
else return 1;
} //end of the function AAS_KeepFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OptimizeFace(optimized_t *optimized, int facenum)
{
int i, edgenum, optedgenum, optfacenum;
aas_face_t *face, *optface;
face = &aasworld.faces[abs(facenum)];
if (!AAS_KeepFace(face)) return 0;
optfacenum = optimized->faceoptimizeindex[abs(facenum)];
if (optfacenum)
{
//keep the face side sign
if (facenum > 0) return optfacenum;
else return -optfacenum;
} //end if
optface = &optimized->faces[optimized->numfaces];
Com_Memcpy(optface, face, sizeof(aas_face_t));
optface->numedges = 0;
optface->firstedge = optimized->edgeindexsize;
for (i = 0; i < face->numedges; i++)
{
edgenum = aasworld.edgeindex[face->firstedge + i];
optedgenum = AAS_OptimizeEdge(optimized, edgenum);
if (optedgenum)
{
optimized->edgeindex[optface->firstedge + optface->numedges] = optedgenum;
optface->numedges++;
optimized->edgeindexsize++;
} //end if
} //end for
optimized->faceoptimizeindex[abs(facenum)] = optimized->numfaces;
optfacenum = optimized->numfaces;
optimized->numfaces++;
//keep the face side sign
if (facenum > 0) return optfacenum;
else return -optfacenum;
} //end of the function AAS_OptimizeFace
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeArea(optimized_t *optimized, int areanum)
{
int i, facenum, optfacenum;
aas_area_t *area, *optarea;
area = &aasworld.areas[areanum];
optarea = &optimized->areas[areanum];
Com_Memcpy(optarea, area, sizeof(aas_area_t));
optarea->numfaces = 0;
optarea->firstface = optimized->faceindexsize;
for (i = 0; i < area->numfaces; i++)
{
facenum = aasworld.faceindex[area->firstface + i];
optfacenum = AAS_OptimizeFace(optimized, facenum);
if (optfacenum)
{
optimized->faceindex[optarea->firstface + optarea->numfaces] = optfacenum;
optarea->numfaces++;
optimized->faceindexsize++;
} //end if
} //end for
} //end of the function AAS_OptimizeArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeAlloc(optimized_t *optimized)
{
optimized->vertexes = (aas_vertex_t *) GetClearedMemory(aasworld.numvertexes * sizeof(aas_vertex_t));
optimized->numvertexes = 0;
optimized->edges = (aas_edge_t *) GetClearedMemory(aasworld.numedges * sizeof(aas_edge_t));
optimized->numedges = 1; //edge zero is a dummy
optimized->edgeindex = (aas_edgeindex_t *) GetClearedMemory(aasworld.edgeindexsize * sizeof(aas_edgeindex_t));
optimized->edgeindexsize = 0;
optimized->faces = (aas_face_t *) GetClearedMemory(aasworld.numfaces * sizeof(aas_face_t));
optimized->numfaces = 1; //face zero is a dummy
optimized->faceindex = (aas_faceindex_t *) GetClearedMemory(aasworld.faceindexsize * sizeof(aas_faceindex_t));
optimized->faceindexsize = 0;
optimized->areas = (aas_area_t *) GetClearedMemory(aasworld.numareas * sizeof(aas_area_t));
optimized->numareas = aasworld.numareas;
//
optimized->vertexoptimizeindex = (int *) GetClearedMemory(aasworld.numvertexes * sizeof(int));
optimized->edgeoptimizeindex = (int *) GetClearedMemory(aasworld.numedges * sizeof(int));
optimized->faceoptimizeindex = (int *) GetClearedMemory(aasworld.numfaces * sizeof(int));
} //end of the function AAS_OptimizeAlloc
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_OptimizeStore(optimized_t *optimized)
{
//store the optimized vertexes
if (aasworld.vertexes) FreeMemory(aasworld.vertexes);
aasworld.vertexes = optimized->vertexes;
aasworld.numvertexes = optimized->numvertexes;
//store the optimized edges
if (aasworld.edges) FreeMemory(aasworld.edges);
aasworld.edges = optimized->edges;
aasworld.numedges = optimized->numedges;
//store the optimized edge index
if (aasworld.edgeindex) FreeMemory(aasworld.edgeindex);
aasworld.edgeindex = optimized->edgeindex;
aasworld.edgeindexsize = optimized->edgeindexsize;
//store the optimized faces
if (aasworld.faces) FreeMemory(aasworld.faces);
aasworld.faces = optimized->faces;
aasworld.numfaces = optimized->numfaces;
//store the optimized face index
if (aasworld.faceindex) FreeMemory(aasworld.faceindex);
aasworld.faceindex = optimized->faceindex;
aasworld.faceindexsize = optimized->faceindexsize;
//store the optimized areas
if (aasworld.areas) FreeMemory(aasworld.areas);
aasworld.areas = optimized->areas;
aasworld.numareas = optimized->numareas;
//free optimize indexes
FreeMemory(optimized->vertexoptimizeindex);
FreeMemory(optimized->edgeoptimizeindex);
FreeMemory(optimized->faceoptimizeindex);
} //end of the function AAS_OptimizeStore
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_Optimize(void)
{
int i, sign;
optimized_t optimized;
AAS_OptimizeAlloc(&optimized);
for (i = 1; i < aasworld.numareas; i++)
{
AAS_OptimizeArea(&optimized, i);
} //end for
//reset the reachability face pointers
for (i = 0; i < aasworld.reachabilitysize; i++)
{
//NOTE: for TRAVEL_ELEVATOR the facenum is the model number of
// the elevator
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR) continue;
//NOTE: for TRAVEL_JUMPPAD the facenum is the Z velocity and the edgenum is the hor velocity
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_JUMPPAD) continue;
//NOTE: for TRAVEL_FUNCBOB the facenum and edgenum contain other coded information
if ((aasworld.reachability[i].traveltype & TRAVELTYPE_MASK) == TRAVEL_FUNCBOB) continue;
//
sign = aasworld.reachability[i].facenum;
aasworld.reachability[i].facenum = optimized.faceoptimizeindex[abs(aasworld.reachability[i].facenum)];
if (sign < 0) aasworld.reachability[i].facenum = -aasworld.reachability[i].facenum;
sign = aasworld.reachability[i].edgenum;
aasworld.reachability[i].edgenum = optimized.edgeoptimizeindex[abs(aasworld.reachability[i].edgenum)];
if (sign < 0) aasworld.reachability[i].edgenum = -aasworld.reachability[i].edgenum;
} //end for
//store the optimized AAS data into aasworld
AAS_OptimizeStore(&optimized);
//print some nice stuff :)
botimport.Print(PRT_MESSAGE, "AAS data optimized.\n");
} //end of the function AAS_Optimize

View File

@ -1,16 +1,16 @@
/*****************************************************************************
* name: be_aas_optimize.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_optimize.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
void AAS_Optimize(void);
/*****************************************************************************
* name: be_aas_optimize.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_optimize.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
void AAS_Optimize(void);

File diff suppressed because it is too large Load Diff

View File

@ -1,51 +1,51 @@
/*****************************************************************************
* name: be_aas_reach.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_reach.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize calculating the reachabilities
void AAS_InitReachability(void);
//continue calculating the reachabilities
int AAS_ContinueInitReachability(float time);
//
int AAS_BestReachableLinkArea(aas_link_t *areas);
#endif //AASINTERN
//returns true if the are has reachabilities to other areas
int AAS_AreaReachability(int areanum);
//returns the best reachable area and goal origin for a bounding box at the given origin
int AAS_BestReachableArea(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin);
//returns the best jumppad area from which the bbox at origin is reachable
int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs);
//returns the next reachability using the given model
int AAS_NextModelReachability(int num, int modelnum);
//returns the total area of the ground faces of the given area
float AAS_AreaGroundFaceArea(int areanum);
//returns true if the area is crouch only
int AAS_AreaCrouch(int areanum);
//returns true if a player can swim in this area
int AAS_AreaSwim(int areanum);
//returns true if the area is filled with a liquid
int AAS_AreaLiquid(int areanum);
//returns true if the area contains lava
int AAS_AreaLava(int areanum);
//returns true if the area contains slime
int AAS_AreaSlime(int areanum);
//returns true if the area has one or more ground faces
int AAS_AreaGrounded(int areanum);
//returns true if the area has one or more ladder faces
int AAS_AreaLadder(int areanum);
//returns true if the area is a jump pad
int AAS_AreaJumpPad(int areanum);
//returns true if the area is donotenter
int AAS_AreaDoNotEnter(int areanum);
/*****************************************************************************
* name: be_aas_reach.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_reach.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize calculating the reachabilities
void AAS_InitReachability(void);
//continue calculating the reachabilities
int AAS_ContinueInitReachability(float time);
//
int AAS_BestReachableLinkArea(aas_link_t *areas);
#endif //AASINTERN
//returns true if the are has reachabilities to other areas
int AAS_AreaReachability(int areanum);
//returns the best reachable area and goal origin for a bounding box at the given origin
int AAS_BestReachableArea(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin);
//returns the best jumppad area from which the bbox at origin is reachable
int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs);
//returns the next reachability using the given model
int AAS_NextModelReachability(int num, int modelnum);
//returns the total area of the ground faces of the given area
float AAS_AreaGroundFaceArea(int areanum);
//returns true if the area is crouch only
int AAS_AreaCrouch(int areanum);
//returns true if a player can swim in this area
int AAS_AreaSwim(int areanum);
//returns true if the area is filled with a liquid
int AAS_AreaLiquid(int areanum);
//returns true if the area contains lava
int AAS_AreaLava(int areanum);
//returns true if the area contains slime
int AAS_AreaSlime(int areanum);
//returns true if the area has one or more ground faces
int AAS_AreaGrounded(int areanum);
//returns true if the area has one or more ladder faces
int AAS_AreaLadder(int areanum);
//returns true if the area is a jump pad
int AAS_AreaJumpPad(int areanum);
//returns true if the area is donotenter
int AAS_AreaDoNotEnter(int areanum);

File diff suppressed because it is too large Load Diff

View File

@ -1,50 +1,50 @@
/*****************************************************************************
* name: be_aas_route.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_route.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize the AAS routing
void AAS_InitRouting(void);
//free the AAS routing caches
void AAS_FreeRoutingCaches(void);
//returns the travel time from start to end in the given area
unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
//
void AAS_CreateAllRoutingCache(void);
void AAS_WriteRouteCache(void);
//
void AAS_RoutingInfo(void);
#endif //AASINTERN
//returns the travel flag for the given travel type
int AAS_TravelFlagForType(int traveltype);
//return the travel flag(s) for traveling through this area
int AAS_AreaContentsTravelFlags(int areanum);
//returns the index of the next reachability for the given area
int AAS_NextAreaReachability(int areanum, int reachnum);
//returns the reachability with the given index
void AAS_ReachabilityFromNum(int num, struct aas_reachability_s *reach);
//returns a random goal area and goal origin
int AAS_RandomGoalArea(int areanum, int travelflags, int *goalareanum, vec3_t goalorigin);
//enable or disable an area for routing
int AAS_EnableRoutingArea(int areanum, int enable);
//returns the travel time within the given area from start to end
unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
//returns the travel time from the area to the goal area using the given travel flags
int AAS_AreaTravelTimeToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags);
//predict a route up to a stop event
int AAS_PredictRoute(struct aas_predictroute_s *route, int areanum, vec3_t origin,
int goalareanum, int travelflags, int maxareas, int maxtime,
int stopevent, int stopcontents, int stoptfl, int stopareanum);
/*****************************************************************************
* name: be_aas_route.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_route.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
//initialize the AAS routing
void AAS_InitRouting(void);
//free the AAS routing caches
void AAS_FreeRoutingCaches(void);
//returns the travel time from start to end in the given area
unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
//
void AAS_CreateAllRoutingCache(void);
void AAS_WriteRouteCache(void);
//
void AAS_RoutingInfo(void);
#endif //AASINTERN
//returns the travel flag for the given travel type
int AAS_TravelFlagForType(int traveltype);
//return the travel flag(s) for traveling through this area
int AAS_AreaContentsTravelFlags(int areanum);
//returns the index of the next reachability for the given area
int AAS_NextAreaReachability(int areanum, int reachnum);
//returns the reachability with the given index
void AAS_ReachabilityFromNum(int num, struct aas_reachability_s *reach);
//returns a random goal area and goal origin
int AAS_RandomGoalArea(int areanum, int travelflags, int *goalareanum, vec3_t goalorigin);
//enable or disable an area for routing
int AAS_EnableRoutingArea(int areanum, int enable);
//returns the travel time within the given area from start to end
unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
//returns the travel time from the area to the goal area using the given travel flags
int AAS_AreaTravelTimeToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags);
//predict a route up to a stop event
int AAS_PredictRoute(struct aas_predictroute_s *route, int areanum, vec3_t origin,
int goalareanum, int travelflags, int maxareas, int maxtime,
int stopevent, int stopcontents, int stoptfl, int stopareanum);

View File

@ -1,223 +1,223 @@
/*****************************************************************************
* name: be_aas_routealt.c
*
* desc: AAS
*
* $Archive: /MissionPack/code/botlib/be_aas_routealt.c $
* $Author: Zaphod $
* $Revision: 5 $
* $Modtime: 11/22/00 8:47a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_utils.h"
#include "l_memory.h"
#include "l_log.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
#define ENABLE_ALTROUTING
//#define ALTROUTE_DEBUG
typedef struct midrangearea_s
{
int valid;
unsigned short starttime;
unsigned short goaltime;
} midrangearea_t;
midrangearea_t *midrangeareas;
int *clusterareas;
int numclusterareas;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_AltRoutingFloodCluster_r(int areanum)
{
int i, otherareanum;
aas_area_t *area;
aas_face_t *face;
//add the current area to the areas of the current cluster
clusterareas[numclusterareas] = areanum;
numclusterareas++;
//remove the area from the mid range areas
midrangeareas[areanum].valid = qfalse;
//flood to other areas through the faces of this area
area = &aasworld.areas[areanum];
for (i = 0; i < area->numfaces; i++)
{
face = &aasworld.faces[abs(aasworld.faceindex[area->firstface + i])];
//get the area at the other side of the face
if (face->frontarea == areanum) otherareanum = face->backarea;
else otherareanum = face->frontarea;
//if there is an area at the other side of this face
if (!otherareanum) continue;
//if the other area is not a midrange area
if (!midrangeareas[otherareanum].valid) continue;
//
AAS_AltRoutingFloodCluster_r(otherareanum);
} //end for
} //end of the function AAS_AltRoutingFloodCluster_r
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AlternativeRouteGoals(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags,
aas_altroutegoal_t *altroutegoals, int maxaltroutegoals,
int type)
{
#ifndef ENABLE_ALTROUTING
return 0;
#else
int i, j, bestareanum;
int numaltroutegoals, nummidrangeareas;
int starttime, goaltime, goaltraveltime;
float dist, bestdist;
vec3_t mid, dir;
#ifdef ALTROUTE_DEBUG
int startmillisecs;
startmillisecs = Sys_MilliSeconds();
#endif
if (!startareanum || !goalareanum)
return 0;
//travel time towards the goal area
goaltraveltime = AAS_AreaTravelTimeToGoalArea(startareanum, start, goalareanum, travelflags);
//clear the midrange areas
Com_Memset(midrangeareas, 0, aasworld.numareas * sizeof(midrangearea_t));
numaltroutegoals = 0;
//
nummidrangeareas = 0;
//
for (i = 1; i < aasworld.numareas; i++)
{
//
if (!(type & ALTROUTEGOAL_ALL))
{
if (!(type & ALTROUTEGOAL_CLUSTERPORTALS && (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)))
{
if (!(type & ALTROUTEGOAL_VIEWPORTALS && (aasworld.areasettings[i].contents & AREACONTENTS_VIEWPORTAL)))
{
continue;
} //end if
} //end if
} //end if
//if the area has no reachabilities
if (!AAS_AreaReachability(i)) continue;
//tavel time from the area to the start area
starttime = AAS_AreaTravelTimeToGoalArea(startareanum, start, i, travelflags);
if (!starttime) continue;
//if the travel time from the start to the area is greater than the shortest goal travel time
if (starttime > (float) 1.1 * goaltraveltime) continue;
//travel time from the area to the goal area
goaltime = AAS_AreaTravelTimeToGoalArea(i, NULL, goalareanum, travelflags);
if (!goaltime) continue;
//if the travel time from the area to the goal is greater than the shortest goal travel time
if (goaltime > (float) 0.8 * goaltraveltime) continue;
//this is a mid range area
midrangeareas[i].valid = qtrue;
midrangeareas[i].starttime = starttime;
midrangeareas[i].goaltime = goaltime;
Log_Write("%d midrange area %d", nummidrangeareas, i);
nummidrangeareas++;
} //end for
//
for (i = 1; i < aasworld.numareas; i++)
{
if (!midrangeareas[i].valid) continue;
//get the areas in one cluster
numclusterareas = 0;
AAS_AltRoutingFloodCluster_r(i);
//now we've got a cluster with areas through which an alternative route could go
//get the 'center' of the cluster
VectorClear(mid);
for (j = 0; j < numclusterareas; j++)
{
VectorAdd(mid, aasworld.areas[clusterareas[j]].center, mid);
} //end for
VectorScale(mid, 1.0 / numclusterareas, mid);
//get the area closest to the center of the cluster
bestdist = 999999;
bestareanum = 0;
for (j = 0; j < numclusterareas; j++)
{
VectorSubtract(mid, aasworld.areas[clusterareas[j]].center, dir);
dist = VectorLength(dir);
if (dist < bestdist)
{
bestdist = dist;
bestareanum = clusterareas[j];
} //end if
} //end for
//now we've got an area for an alternative route
//FIXME: add alternative goal origin
VectorCopy(aasworld.areas[bestareanum].center, altroutegoals[numaltroutegoals].origin);
altroutegoals[numaltroutegoals].areanum = bestareanum;
altroutegoals[numaltroutegoals].starttraveltime = midrangeareas[bestareanum].starttime;
altroutegoals[numaltroutegoals].goaltraveltime = midrangeareas[bestareanum].goaltime;
altroutegoals[numaltroutegoals].extratraveltime =
(midrangeareas[bestareanum].starttime + midrangeareas[bestareanum].goaltime) -
goaltraveltime;
numaltroutegoals++;
//
#ifdef ALTROUTE_DEBUG
AAS_ShowAreaPolygons(bestareanum, 1, qtrue);
#endif
//don't return more than the maximum alternative route goals
if (numaltroutegoals >= maxaltroutegoals) break;
} //end for
#ifdef ALTROUTE_DEBUG
botimport.Print(PRT_MESSAGE, "alternative route goals in %d msec\n", Sys_MilliSeconds() - startmillisecs);
#endif
return numaltroutegoals;
#endif
} //end of the function AAS_AlternativeRouteGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_InitAlternativeRouting(void)
{
#ifdef ENABLE_ALTROUTING
if (midrangeareas) FreeMemory(midrangeareas);
midrangeareas = (midrangearea_t *) GetMemory(aasworld.numareas * sizeof(midrangearea_t));
if (clusterareas) FreeMemory(clusterareas);
clusterareas = (int *) GetMemory(aasworld.numareas * sizeof(int));
#endif
} //end of the function AAS_InitAlternativeRouting
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShutdownAlternativeRouting(void)
{
#ifdef ENABLE_ALTROUTING
if (midrangeareas) FreeMemory(midrangeareas);
midrangeareas = NULL;
if (clusterareas) FreeMemory(clusterareas);
clusterareas = NULL;
numclusterareas = 0;
#endif
} //end of the function AAS_ShutdownAlternativeRouting
/*****************************************************************************
* name: be_aas_routealt.c
*
* desc: AAS
*
* $Archive: /MissionPack/code/botlib/be_aas_routealt.c $
* $Author: Zaphod $
* $Revision: 5 $
* $Modtime: 11/22/00 8:47a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_utils.h"
#include "l_memory.h"
#include "l_log.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_aas_def.h"
#define ENABLE_ALTROUTING
//#define ALTROUTE_DEBUG
typedef struct midrangearea_s
{
int valid;
unsigned short starttime;
unsigned short goaltime;
} midrangearea_t;
midrangearea_t *midrangeareas;
int *clusterareas;
int numclusterareas;
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_AltRoutingFloodCluster_r(int areanum)
{
int i, otherareanum;
aas_area_t *area;
aas_face_t *face;
//add the current area to the areas of the current cluster
clusterareas[numclusterareas] = areanum;
numclusterareas++;
//remove the area from the mid range areas
midrangeareas[areanum].valid = qfalse;
//flood to other areas through the faces of this area
area = &aasworld.areas[areanum];
for (i = 0; i < area->numfaces; i++)
{
face = &aasworld.faces[abs(aasworld.faceindex[area->firstface + i])];
//get the area at the other side of the face
if (face->frontarea == areanum) otherareanum = face->backarea;
else otherareanum = face->frontarea;
//if there is an area at the other side of this face
if (!otherareanum) continue;
//if the other area is not a midrange area
if (!midrangeareas[otherareanum].valid) continue;
//
AAS_AltRoutingFloodCluster_r(otherareanum);
} //end for
} //end of the function AAS_AltRoutingFloodCluster_r
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AlternativeRouteGoals(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags,
aas_altroutegoal_t *altroutegoals, int maxaltroutegoals,
int type)
{
#ifndef ENABLE_ALTROUTING
return 0;
#else
int i, j, bestareanum;
int numaltroutegoals, nummidrangeareas;
int starttime, goaltime, goaltraveltime;
float dist, bestdist;
vec3_t mid, dir;
#ifdef ALTROUTE_DEBUG
int startmillisecs;
startmillisecs = Sys_MilliSeconds();
#endif
if (!startareanum || !goalareanum)
return 0;
//travel time towards the goal area
goaltraveltime = AAS_AreaTravelTimeToGoalArea(startareanum, start, goalareanum, travelflags);
//clear the midrange areas
Com_Memset(midrangeareas, 0, aasworld.numareas * sizeof(midrangearea_t));
numaltroutegoals = 0;
//
nummidrangeareas = 0;
//
for (i = 1; i < aasworld.numareas; i++)
{
//
if (!(type & ALTROUTEGOAL_ALL))
{
if (!(type & ALTROUTEGOAL_CLUSTERPORTALS && (aasworld.areasettings[i].contents & AREACONTENTS_CLUSTERPORTAL)))
{
if (!(type & ALTROUTEGOAL_VIEWPORTALS && (aasworld.areasettings[i].contents & AREACONTENTS_VIEWPORTAL)))
{
continue;
} //end if
} //end if
} //end if
//if the area has no reachabilities
if (!AAS_AreaReachability(i)) continue;
//tavel time from the area to the start area
starttime = AAS_AreaTravelTimeToGoalArea(startareanum, start, i, travelflags);
if (!starttime) continue;
//if the travel time from the start to the area is greater than the shortest goal travel time
if (starttime > (float) 1.1 * goaltraveltime) continue;
//travel time from the area to the goal area
goaltime = AAS_AreaTravelTimeToGoalArea(i, NULL, goalareanum, travelflags);
if (!goaltime) continue;
//if the travel time from the area to the goal is greater than the shortest goal travel time
if (goaltime > (float) 0.8 * goaltraveltime) continue;
//this is a mid range area
midrangeareas[i].valid = qtrue;
midrangeareas[i].starttime = starttime;
midrangeareas[i].goaltime = goaltime;
Log_Write("%d midrange area %d", nummidrangeareas, i);
nummidrangeareas++;
} //end for
//
for (i = 1; i < aasworld.numareas; i++)
{
if (!midrangeareas[i].valid) continue;
//get the areas in one cluster
numclusterareas = 0;
AAS_AltRoutingFloodCluster_r(i);
//now we've got a cluster with areas through which an alternative route could go
//get the 'center' of the cluster
VectorClear(mid);
for (j = 0; j < numclusterareas; j++)
{
VectorAdd(mid, aasworld.areas[clusterareas[j]].center, mid);
} //end for
VectorScale(mid, 1.0 / numclusterareas, mid);
//get the area closest to the center of the cluster
bestdist = 999999;
bestareanum = 0;
for (j = 0; j < numclusterareas; j++)
{
VectorSubtract(mid, aasworld.areas[clusterareas[j]].center, dir);
dist = VectorLength(dir);
if (dist < bestdist)
{
bestdist = dist;
bestareanum = clusterareas[j];
} //end if
} //end for
//now we've got an area for an alternative route
//FIXME: add alternative goal origin
VectorCopy(aasworld.areas[bestareanum].center, altroutegoals[numaltroutegoals].origin);
altroutegoals[numaltroutegoals].areanum = bestareanum;
altroutegoals[numaltroutegoals].starttraveltime = midrangeareas[bestareanum].starttime;
altroutegoals[numaltroutegoals].goaltraveltime = midrangeareas[bestareanum].goaltime;
altroutegoals[numaltroutegoals].extratraveltime =
(midrangeareas[bestareanum].starttime + midrangeareas[bestareanum].goaltime) -
goaltraveltime;
numaltroutegoals++;
//
#ifdef ALTROUTE_DEBUG
AAS_ShowAreaPolygons(bestareanum, 1, qtrue);
#endif
//don't return more than the maximum alternative route goals
if (numaltroutegoals >= maxaltroutegoals) break;
} //end for
#ifdef ALTROUTE_DEBUG
botimport.Print(PRT_MESSAGE, "alternative route goals in %d msec\n", Sys_MilliSeconds() - startmillisecs);
#endif
return numaltroutegoals;
#endif
} //end of the function AAS_AlternativeRouteGoals
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_InitAlternativeRouting(void)
{
#ifdef ENABLE_ALTROUTING
if (midrangeareas) FreeMemory(midrangeareas);
midrangeareas = (midrangearea_t *) GetMemory(aasworld.numareas * sizeof(midrangearea_t));
if (clusterareas) FreeMemory(clusterareas);
clusterareas = (int *) GetMemory(aasworld.numareas * sizeof(int));
#endif
} //end of the function AAS_InitAlternativeRouting
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShutdownAlternativeRouting(void)
{
#ifdef ENABLE_ALTROUTING
if (midrangeareas) FreeMemory(midrangeareas);
midrangeareas = NULL;
if (clusterareas) FreeMemory(clusterareas);
clusterareas = NULL;
numclusterareas = 0;
#endif
} //end of the function AAS_ShutdownAlternativeRouting

View File

@ -1,23 +1,23 @@
/*****************************************************************************
* name: be_aas_routealt.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_routealt.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
void AAS_InitAlternativeRouting(void);
void AAS_ShutdownAlternativeRouting(void);
#endif //AASINTERN
int AAS_AlternativeRouteGoals(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags,
aas_altroutegoal_t *altroutegoals, int maxaltroutegoals,
int type);
/*****************************************************************************
* name: be_aas_routealt.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_routealt.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
void AAS_InitAlternativeRouting(void);
void AAS_ShutdownAlternativeRouting(void);
#endif //AASINTERN
int AAS_AlternativeRouteGoals(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags,
aas_altroutegoal_t *altroutegoals, int maxaltroutegoals,
int type);

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +1,52 @@
/*****************************************************************************
* name: be_aas_sample.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_sample.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
void AAS_InitAASLinkHeap(void);
void AAS_InitAASLinkedEntities(void);
void AAS_FreeAASLinkHeap(void);
void AAS_FreeAASLinkedEntities(void);
aas_face_t *AAS_AreaGroundFace(int areanum, vec3_t point);
aas_face_t *AAS_TraceEndFace(aas_trace_t *trace);
aas_plane_t *AAS_PlaneFromNum(int planenum);
aas_link_t *AAS_AASLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum);
aas_link_t *AAS_LinkEntityClientBBox(vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype);
qboolean AAS_PointInsideFace(int facenum, vec3_t point, float epsilon);
qboolean AAS_InsideFace(aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon);
void AAS_UnlinkFromAreas(aas_link_t *areas);
#endif //AASINTERN
//returns the mins and maxs of the bounding box for the given presence type
void AAS_PresenceTypeBoundingBox(int presencetype, vec3_t mins, vec3_t maxs);
//returns the cluster the area is in (negative portal number if the area is a portal)
int AAS_AreaCluster(int areanum);
//returns the presence type(s) of the area
int AAS_AreaPresenceType(int areanum);
//returns the presence type(s) at the given point
int AAS_PointPresenceType(vec3_t point);
//returns the result of the trace of a client bbox
aas_trace_t AAS_TraceClientBBox(vec3_t start, vec3_t end, int presencetype, int passent);
//stores the areas the trace went through and returns the number of passed areas
int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas);
//returns the areas the bounding box is in
int AAS_BBoxAreas(vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas);
//return area information
int AAS_AreaInfo( int areanum, aas_areainfo_t *info );
//returns the area the point is in
int AAS_PointAreaNum(vec3_t point);
//
int AAS_PointReachabilityAreaIndex( vec3_t point );
//returns the plane the given face is in
void AAS_FacePlane(int facenum, vec3_t normal, float *dist);
/*****************************************************************************
* name: be_aas_sample.h
*
* desc: AAS
*
* $Archive: /source/code/botlib/be_aas_sample.h $
* $Author: Mrelusive $
* $Revision: 2 $
* $Modtime: 10/05/99 3:32p $
* $Date: 10/05/99 3:42p $
*
*****************************************************************************/
#ifdef AASINTERN
void AAS_InitAASLinkHeap(void);
void AAS_InitAASLinkedEntities(void);
void AAS_FreeAASLinkHeap(void);
void AAS_FreeAASLinkedEntities(void);
aas_face_t *AAS_AreaGroundFace(int areanum, vec3_t point);
aas_face_t *AAS_TraceEndFace(aas_trace_t *trace);
aas_plane_t *AAS_PlaneFromNum(int planenum);
aas_link_t *AAS_AASLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum);
aas_link_t *AAS_LinkEntityClientBBox(vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype);
qboolean AAS_PointInsideFace(int facenum, vec3_t point, float epsilon);
qboolean AAS_InsideFace(aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon);
void AAS_UnlinkFromAreas(aas_link_t *areas);
#endif //AASINTERN
//returns the mins and maxs of the bounding box for the given presence type
void AAS_PresenceTypeBoundingBox(int presencetype, vec3_t mins, vec3_t maxs);
//returns the cluster the area is in (negative portal number if the area is a portal)
int AAS_AreaCluster(int areanum);
//returns the presence type(s) of the area
int AAS_AreaPresenceType(int areanum);
//returns the presence type(s) at the given point
int AAS_PointPresenceType(vec3_t point);
//returns the result of the trace of a client bbox
aas_trace_t AAS_TraceClientBBox(vec3_t start, vec3_t end, int presencetype, int passent);
//stores the areas the trace went through and returns the number of passed areas
int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas);
//returns the areas the bounding box is in
int AAS_BBoxAreas(vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas);
//return area information
int AAS_AreaInfo( int areanum, aas_areainfo_t *info );
//returns the area the point is in
int AAS_PointAreaNum(vec3_t point);
//
int AAS_PointReachabilityAreaIndex( vec3_t point );
//returns the plane the given face is in
void AAS_FacePlane(int facenum, vec3_t normal, float *dist);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,117 +1,117 @@
/*****************************************************************************
* name: be_ai_gen.c
*
* desc: genetic selection
*
* $Archive: /MissionPack/code/botlib/be_ai_gen.c $
* $Author: Zaphod $
* $Revision: 3 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_log.h"
#include "l_utils.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "../game/be_ai_gen.h"
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int GeneticSelection(int numranks, float *rankings)
{
float sum, select;
int i, index;
sum = 0;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
sum += rankings[i];
} //end for
if (sum > 0)
{
//select a bot where the ones with the higest rankings have
//the highest chance of being selected
select = random() * sum;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
sum -= rankings[i];
if (sum <= 0) return i;
} //end for
} //end if
//select a bot randomly
index = random() * numranks;
for (i = 0; i < numranks; i++)
{
if (rankings[index] >= 0) return index;
index = (index + 1) % numranks;
} //end for
return 0;
} //end of the function GeneticSelection
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child)
{
float rankings[256], max;
int i;
if (numranks > 256)
{
botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n");
*parent1 = *parent2 = *child = 0;
return qfalse;
} //end if
for (max = 0, i = 0; i < numranks; i++)
{
if (ranks[i] < 0) continue;
max++;
} //end for
if (max < 3)
{
botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n");
*parent1 = *parent2 = *child = 0;
return qfalse;
} //end if
Com_Memcpy(rankings, ranks, sizeof(float) * numranks);
//select first parent
*parent1 = GeneticSelection(numranks, rankings);
rankings[*parent1] = -1;
//select second parent
*parent2 = GeneticSelection(numranks, rankings);
rankings[*parent2] = -1;
//reverse the rankings
max = 0;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
if (rankings[i] > max) max = rankings[i];
} //end for
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
rankings[i] = max - rankings[i];
} //end for
//select child
*child = GeneticSelection(numranks, rankings);
return qtrue;
} //end of the function GeneticParentsAndChildSelection
/*****************************************************************************
* name: be_ai_gen.c
*
* desc: genetic selection
*
* $Archive: /MissionPack/code/botlib/be_ai_gen.c $
* $Author: Zaphod $
* $Revision: 3 $
* $Modtime: 11/22/00 8:50a $
* $Date: 11/22/00 8:55a $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_log.h"
#include "l_utils.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "../game/be_ai_gen.h"
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int GeneticSelection(int numranks, float *rankings)
{
float sum, select;
int i, index;
sum = 0;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
sum += rankings[i];
} //end for
if (sum > 0)
{
//select a bot where the ones with the higest rankings have
//the highest chance of being selected
select = random() * sum;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
sum -= rankings[i];
if (sum <= 0) return i;
} //end for
} //end if
//select a bot randomly
index = random() * numranks;
for (i = 0; i < numranks; i++)
{
if (rankings[index] >= 0) return index;
index = (index + 1) % numranks;
} //end for
return 0;
} //end of the function GeneticSelection
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child)
{
float rankings[256], max;
int i;
if (numranks > 256)
{
botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n");
*parent1 = *parent2 = *child = 0;
return qfalse;
} //end if
for (max = 0, i = 0; i < numranks; i++)
{
if (ranks[i] < 0) continue;
max++;
} //end for
if (max < 3)
{
botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n");
*parent1 = *parent2 = *child = 0;
return qfalse;
} //end if
Com_Memcpy(rankings, ranks, sizeof(float) * numranks);
//select first parent
*parent1 = GeneticSelection(numranks, rankings);
rankings[*parent1] = -1;
//select second parent
*parent2 = GeneticSelection(numranks, rankings);
rankings[*parent2] = -1;
//reverse the rankings
max = 0;
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
if (rankings[i] > max) max = rankings[i];
} //end for
for (i = 0; i < numranks; i++)
{
if (rankings[i] < 0) continue;
rankings[i] = max - rankings[i];
} //end for
//select child
*child = GeneticSelection(numranks, rankings);
return qtrue;
} //end of the function GeneticParentsAndChildSelection

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More