📄 be_aas_move.c
字号:
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
/*****************************************************************************
* name: be_aas_move.c
*
* desc: AAS
*
* $Archive: /MissionPack/code/botlib/be_aas_move.c $
*
*****************************************************************************/
#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_libvar.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;
aas_settings_t aassettings;
//#define AAS_MOVE_DEBUG
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_DropToFloor(vec3_t origin, vec3_t mins, vec3_t maxs)
{
vec3_t end;
bsp_trace_t trace;
VectorCopy(origin, end);
end[2] -= 100;
trace = AAS_Trace(origin, mins, maxs, end, 0, CONTENTS_SOLID);
if (trace.startsolid) return qfalse;
VectorCopy(trace.endpos, origin);
return qtrue;
} //end of the function AAS_DropToFloor
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_InitSettings(void)
{
aassettings.phys_gravitydirection[0] = 0;
aassettings.phys_gravitydirection[1] = 0;
aassettings.phys_gravitydirection[2] = -1;
aassettings.phys_friction = LibVarValue("phys_friction", "6");
aassettings.phys_stopspeed = LibVarValue("phys_stopspeed", "100");
aassettings.phys_gravity = LibVarValue("phys_gravity", "800");
aassettings.phys_waterfriction = LibVarValue("phys_waterfriction", "1");
aassettings.phys_watergravity = LibVarValue("phys_watergravity", "400");
aassettings.phys_maxvelocity = LibVarValue("phys_maxvelocity", "320");
aassettings.phys_maxwalkvelocity = LibVarValue("phys_maxwalkvelocity", "320");
aassettings.phys_maxcrouchvelocity = LibVarValue("phys_maxcrouchvelocity", "100");
aassettings.phys_maxswimvelocity = LibVarValue("phys_maxswimvelocity", "150");
aassettings.phys_walkaccelerate = LibVarValue("phys_walkaccelerate", "10");
aassettings.phys_airaccelerate = LibVarValue("phys_airaccelerate", "1");
aassettings.phys_swimaccelerate = LibVarValue("phys_swimaccelerate", "4");
aassettings.phys_maxstep = LibVarValue("phys_maxstep", "19");
aassettings.phys_maxsteepness = LibVarValue("phys_maxsteepness", "0.7");
aassettings.phys_maxwaterjump = LibVarValue("phys_maxwaterjump", "18");
aassettings.phys_maxbarrier = LibVarValue("phys_maxbarrier", "33");
aassettings.phys_jumpvel = LibVarValue("phys_jumpvel", "270");
aassettings.phys_falldelta5 = LibVarValue("phys_falldelta5", "40");
aassettings.phys_falldelta10 = LibVarValue("phys_falldelta10", "60");
aassettings.rs_waterjump = LibVarValue("rs_waterjump", "400");
aassettings.rs_teleport = LibVarValue("rs_teleport", "50");
aassettings.rs_barrierjump = LibVarValue("rs_barrierjump", "100");
aassettings.rs_startcrouch = LibVarValue("rs_startcrouch", "300");
aassettings.rs_startgrapple = LibVarValue("rs_startgrapple", "500");
aassettings.rs_startwalkoffledge = LibVarValue("rs_startwalkoffledge", "70");
aassettings.rs_startjump = LibVarValue("rs_startjump", "300");
aassettings.rs_rocketjump = LibVarValue("rs_rocketjump", "500");
aassettings.rs_bfgjump = LibVarValue("rs_bfgjump", "500");
aassettings.rs_jumppad = LibVarValue("rs_jumppad", "250");
aassettings.rs_aircontrolledjumppad = LibVarValue("rs_aircontrolledjumppad", "300");
aassettings.rs_funcbob = LibVarValue("rs_funcbob", "300");
aassettings.rs_startelevator = LibVarValue("rs_startelevator", "50");
aassettings.rs_falldamage5 = LibVarValue("rs_falldamage5", "300");
aassettings.rs_falldamage10 = LibVarValue("rs_falldamage10", "500");
aassettings.rs_maxfallheight = LibVarValue("rs_maxfallheight", "0");
aassettings.rs_maxjumpfallheight = LibVarValue("rs_maxjumpfallheight", "450");
} //end of the function AAS_InitSettings
//===========================================================================
// returns qtrue if the bot is against a ladder
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AgainstLadder(vec3_t origin)
{
int areanum, i, facenum, side;
vec3_t org;
aas_plane_t *plane;
aas_face_t *face;
aas_area_t *area;
VectorCopy(origin, org);
areanum = AAS_PointAreaNum(org);
if (!areanum)
{
org[0] += 1;
areanum = AAS_PointAreaNum(org);
if (!areanum)
{
org[1] += 1;
areanum = AAS_PointAreaNum(org);
if (!areanum)
{
org[0] -= 2;
areanum = AAS_PointAreaNum(org);
if (!areanum)
{
org[1] -= 2;
areanum = AAS_PointAreaNum(org);
} //end if
} //end if
} //end if
} //end if
//if in solid... wrrr shouldn't happen
if (!areanum) return qfalse;
//if not in a ladder area
if (!(aasworld.areasettings[areanum].areaflags & AREA_LADDER)) return qfalse;
//if a crouch only area
if (!(aasworld.areasettings[areanum].presencetype & PRESENCE_NORMAL)) return qfalse;
//
area = &aasworld.areas[areanum];
for (i = 0; i < area->numfaces; i++)
{
facenum = aasworld.faceindex[area->firstface + i];
side = facenum < 0;
face = &aasworld.faces[abs(facenum)];
//if the face isn't a ladder face
if (!(face->faceflags & FACE_LADDER)) continue;
//get the plane the face is in
plane = &aasworld.planes[face->planenum ^ side];
//if the origin is pretty close to the plane
if (abs(DotProduct(plane->normal, origin) - plane->dist) < 3)
{
if (AAS_PointInsideFace(abs(facenum), origin, 0.1f)) return qtrue;
} //end if
} //end for
return qfalse;
} //end of the function AAS_AgainstLadder
//===========================================================================
// returns qtrue if the bot is on the ground
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_OnGround(vec3_t origin, int presencetype, int passent)
{
aas_trace_t trace;
vec3_t end, up = {0, 0, 1};
aas_plane_t *plane;
VectorCopy(origin, end);
end[2] -= 10;
trace = AAS_TraceClientBBox(origin, end, presencetype, passent);
//if in solid
if (trace.startsolid) return qfalse;
//if nothing hit at all
if (trace.fraction >= 1.0) return qfalse;
//if too far from the hit plane
if (origin[2] - trace.endpos[2] > 10) return qfalse;
//check if the plane isn't too steep
plane = AAS_PlaneFromNum(trace.planenum);
if (DotProduct(plane->normal, up) < aassettings.phys_maxsteepness) return qfalse;
//the bot is on the ground
return qtrue;
} //end of the function AAS_OnGround
//===========================================================================
// returns qtrue if a bot at the given position is swimming
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_Swimming(vec3_t origin)
{
vec3_t testorg;
VectorCopy(origin, testorg);
testorg[2] -= 2;
if (AAS_PointContents(testorg) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) return qtrue;
return qfalse;
} //end of the function AAS_Swimming
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
static vec3_t VEC_UP = {0, -1, 0};
static vec3_t MOVEDIR_UP = {0, 0, 1};
static vec3_t VEC_DOWN = {0, -2, 0};
static vec3_t MOVEDIR_DOWN = {0, 0, -1};
void AAS_SetMovedir(vec3_t angles, vec3_t movedir)
{
if (VectorCompare(angles, VEC_UP))
{
VectorCopy(MOVEDIR_UP, movedir);
} //end if
else if (VectorCompare(angles, VEC_DOWN))
{
VectorCopy(MOVEDIR_DOWN, movedir);
} //end else if
else
{
AngleVectors(angles, movedir, NULL, NULL);
} //end else
} //end of the function AAS_SetMovedir
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_JumpReachRunStart(aas_reachability_t *reach, vec3_t runstart)
{
vec3_t hordir, start, cmdmove;
aas_clientmove_t move;
//
hordir[0] = reach->start[0] - reach->end[0];
hordir[1] = reach->start[1] - reach->end[1];
hordir[2] = 0;
VectorNormalize(hordir);
//start point
VectorCopy(reach->start, start);
start[2] += 1;
//get command movement
VectorScale(hordir, 400, cmdmove);
//
AAS_PredictClientMovement(&move, -1, start, PRESENCE_NORMAL, qtrue,
vec3_origin, cmdmove, 1, 2, 0.1f,
SE_ENTERWATER|SE_ENTERSLIME|SE_ENTERLAVA|
SE_HITGROUNDDAMAGE|SE_GAP, 0, qfalse);
VectorCopy(move.endpos, runstart);
//don't enter slime or lava and don't fall from too high
if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE))
{
VectorCopy(start, runstart);
} //end if
} //end of the function AAS_JumpReachRunStart
//===========================================================================
// returns the Z velocity when rocket jumping at the origin
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_WeaponJumpZVelocity(vec3_t origin, float radiusdamage)
{
vec3_t kvel, v, start, end, forward, right, viewangles, dir;
float mass, knockback, points;
vec3_t rocketoffset = {8, 8, -8};
vec3_t botmins = {-16, -16, -24};
vec3_t botmaxs = {16, 16, 32};
bsp_trace_t bsptrace;
//look down (90 degrees)
viewangles[PITCH] = 90;
viewangles[YAW] = 0;
viewangles[ROLL] = 0;
//get the start point shooting from
VectorCopy(origin, start);
start[2] += 8; //view offset Z
AngleVectors(viewangles, forward, right, NULL);
start[0] += forward[0] * rocketoffset[0] + right[0] * rocketoffset[1];
start[1] += forward[1] * rocketoffset[0] + right[1] * rocketoffset[1];
start[2] += forward[2] * rocketoffset[0] + right[2] * rocketoffset[1] + rocketoffset[2];
//end point of the trace
VectorMA(start, 500, forward, end);
//trace a line to get the impact point
bsptrace = AAS_Trace(start, NULL, NULL, end, 1, CONTENTS_SOLID);
//calculate the damage the bot will get from the rocket impact
VectorAdd(botmins, botmaxs, v);
VectorMA(origin, 0.5, v, v);
VectorSubtract(bsptrace.endpos, v, v);
//
points = radiusdamage - 0.5 * VectorLength(v);
if (points < 0) points = 0;
//the owner of the rocket gets half the damage
points *= 0.5;
//mass of the bot (p_client.c: PutClientInServer)
mass = 200;
//knockback is the same as the damage points
knockback = points;
//direction of the damage (from trace.endpos to bot origin)
VectorSubtract(origin, bsptrace.endpos, dir);
VectorNormalize(dir);
//damage velocity
VectorScale(dir, 1600.0 * (float)knockback / mass, kvel); //the rocket jump hack...
//rocket impact velocity + jump velocity
return kvel[2] + aassettings.phys_jumpvel;
} //end of the function AAS_WeaponJumpZVelocity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_RocketJumpZVelocity(vec3_t origin)
{
//rocket radius damage is 120 (p_weapon.c: Weapon_RocketLauncher_Fire)
return AAS_WeaponJumpZVelocity(origin, 120);
} //end of the function AAS_RocketJumpZVelocity
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_BFGJumpZVelocity(vec3_t origin)
{
//bfg radius damage is 1000 (p_weapon.c: weapon_bfg_fire)
return AAS_WeaponJumpZVelocity(origin, 120);
} //end of the function AAS_BFGJumpZVelocity
//===========================================================================
// applies ground friction to the given velocity
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_Accelerate(vec3_t velocity, float frametime, vec3_t wishdir, float wishspeed, float accel)
{
// q2 style
int i;
float addspeed, accelspeed, currentspeed;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -