📄 be_aas_reach.c
字号:
VectorCopy(origin, start);
start[0] += (float) j * 4 * k;
start[1] += (float) j * 4 * l;
start[2] += (float) i * 4;
areanum = AAS_PointAreaNum(start);
} //end for
} //end for
} //end for
} //end for
//if an area was found
if (areanum)
{
//drop client bbox down and try again
VectorCopy(start, end);
start[2] += 0.25;
end[2] -= 50;
trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1);
if (!trace.startsolid)
{
areanum = AAS_PointAreaNum(trace.endpos);
VectorCopy(trace.endpos, goalorigin);
//FIXME: cannot enable next line right now because the reachability
// does not have to be calculated when the level items are loaded
//if the origin is in an area with reachability
//if (AAS_AreaReachability(areanum)) return areanum;
if (areanum) return areanum;
} //end if
else
{
//it can very well happen that the AAS_PointAreaNum function tells that
//a point is in an area and that starting a AAS_TraceClientBBox from that
//point will return trace.startsolid qtrue
#if 0
if (AAS_PointAreaNum(start))
{
Log_Write("point %f %f %f in area %d but trace startsolid", start[0], start[1], start[2], areanum);
AAS_DrawPermanentCross(start, 4, LINECOLOR_RED);
} //end if
botimport.Print(PRT_MESSAGE, "AAS_BestReachableArea: start solid\n");
#endif
VectorCopy(start, goalorigin);
return areanum;
} //end else
} //end if
//
//AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs);
//NOTE: the goal origin does not have to be in the goal area
// because the bot will have to move towards the item origin anyway
VectorCopy(origin, goalorigin);
//
VectorAdd(origin, mins, absmins);
VectorAdd(origin, maxs, absmaxs);
//add bounding box size
//VectorSubtract(absmins, bbmaxs, absmins);
//VectorSubtract(absmaxs, bbmins, absmaxs);
//link an invalid (-1) entity
areas = AAS_LinkEntityClientBBox(absmins, absmaxs, -1, PRESENCE_CROUCH);
//get the reachable link arae
areanum = AAS_BestReachableLinkArea(areas);
//unlink the invalid entity
AAS_UnlinkFromAreas(areas);
//
return areanum;
} //end of the function AAS_BestReachableArea
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_SetupReachabilityHeap(void)
{
int i;
reachabilityheap = (aas_lreachability_t *) GetClearedMemory(
AAS_MAX_REACHABILITYSIZE * sizeof(aas_lreachability_t));
for (i = 0; i < AAS_MAX_REACHABILITYSIZE-1; i++)
{
reachabilityheap[i].next = &reachabilityheap[i+1];
} //end for
reachabilityheap[AAS_MAX_REACHABILITYSIZE-1].next = NULL;
nextreachability = reachabilityheap;
numlreachabilities = 0;
} //end of the function AAS_InitReachabilityHeap
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_ShutDownReachabilityHeap(void)
{
FreeMemory(reachabilityheap);
numlreachabilities = 0;
} //end of the function AAS_ShutDownReachabilityHeap
//===========================================================================
// returns a reachability link
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
aas_lreachability_t *AAS_AllocReachability(void)
{
aas_lreachability_t *r;
if (!nextreachability) return NULL;
//make sure the error message only shows up once
if (!nextreachability->next) AAS_Error("AAS_MAX_REACHABILITYSIZE");
//
r = nextreachability;
nextreachability = nextreachability->next;
numlreachabilities++;
return r;
} //end of the function AAS_AllocReachability
//===========================================================================
// frees a reachability link
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_FreeReachability(aas_lreachability_t *lreach)
{
Com_Memset(lreach, 0, sizeof(aas_lreachability_t));
lreach->next = nextreachability;
nextreachability = lreach;
numlreachabilities--;
} //end of the function AAS_FreeReachability
//===========================================================================
// returns qtrue if the area has reachability links
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaReachability(int areanum)
{
if (areanum < 0 || areanum >= aasworld.numareas)
{
AAS_Error("AAS_AreaReachability: areanum %d out of range", areanum);
return 0;
} //end if
return aasworld.areasettings[areanum].numreachableareas;
} //end of the function AAS_AreaReachability
//===========================================================================
// returns the surface area of all ground faces together of the area
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_AreaGroundFaceArea(int areanum)
{
int i;
float total;
aas_area_t *area;
aas_face_t *face;
total = 0;
area = &aasworld.areas[areanum];
for (i = 0; i < area->numfaces; i++)
{
face = &aasworld.faces[abs(aasworld.faceindex[area->firstface + i])];
if (!(face->faceflags & FACE_GROUND)) continue;
//
total += AAS_FaceArea(face);
} //end for
return total;
} //end of the function AAS_AreaGroundFaceArea
//===========================================================================
// returns the center of a face
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void AAS_FaceCenter(int facenum, vec3_t center)
{
int i;
float scale;
aas_face_t *face;
aas_edge_t *edge;
face = &aasworld.faces[facenum];
VectorClear(center);
for (i = 0; i < face->numedges; i++)
{
edge = &aasworld.edges[abs(aasworld.edgeindex[face->firstedge + i])];
VectorAdd(center, aasworld.vertexes[edge->v[0]], center);
VectorAdd(center, aasworld.vertexes[edge->v[1]], center);
} //end for
scale = 0.5 / face->numedges;
VectorScale(center, scale, center);
} //end of the function AAS_FaceCenter
//===========================================================================
// returns the maximum distance a player can fall before being damaged
// damage = deltavelocity*deltavelocity * 0.0001
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_FallDamageDistance(void)
{
float maxzvelocity, gravity, t;
maxzvelocity = sqrt(30 * 10000);
gravity = aassettings.phys_gravity;
t = maxzvelocity / gravity;
return 0.5 * gravity * t * t;
} //end of the function AAS_FallDamageDistance
//===========================================================================
// distance = 0.5 * gravity * t * t
// vel = t * gravity
// damage = vel * vel * 0.0001
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_FallDelta(float distance)
{
float t, delta, gravity;
gravity = aassettings.phys_gravity;
t = sqrt(fabs(distance) * 2 / gravity);
delta = t * gravity;
return delta * delta * 0.0001;
} //end of the function AAS_FallDelta
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_MaxJumpHeight(float phys_jumpvel)
{
float phys_gravity;
phys_gravity = aassettings.phys_gravity;
//maximum height a player can jump with the given initial z velocity
return 0.5 * phys_gravity * (phys_jumpvel / phys_gravity) * (phys_jumpvel / phys_gravity);
} //end of the function MaxJumpHeight
//===========================================================================
// returns true if a player can only crouch in the area
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float AAS_MaxJumpDistance(float phys_jumpvel)
{
float phys_gravity, phys_maxvelocity, t;
phys_gravity = aassettings.phys_gravity;
phys_maxvelocity = aassettings.phys_maxvelocity;
//time a player takes to fall the height
t = sqrt(aassettings.rs_maxjumpfallheight / (0.5 * phys_gravity));
//maximum distance
return phys_maxvelocity * (t + phys_jumpvel / phys_gravity);
} //end of the function AAS_MaxJumpDistance
//===========================================================================
// returns true if a player can only crouch in the area
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaCrouch(int areanum)
{
if (!(aasworld.areasettings[areanum].presencetype & PRESENCE_NORMAL)) return qtrue;
else return qfalse;
} //end of the function AAS_AreaCrouch
//===========================================================================
// returns qtrue if it is possible to swim in the area
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaSwim(int areanum)
{
if (aasworld.areasettings[areanum].areaflags & AREA_LIQUID) return qtrue;
else return qfalse;
} //end of the function AAS_AreaSwim
//===========================================================================
// returns qtrue if the area contains a liquid
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaLiquid(int areanum)
{
if (aasworld.areasettings[areanum].areaflags & AREA_LIQUID) return qtrue;
else return qfalse;
} //end of the function AAS_AreaLiquid
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaLava(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_LAVA);
} //end of the function AAS_AreaLava
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaSlime(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_SLIME);
} //end of the function AAS_AreaSlime
//===========================================================================
// returns qtrue if the area contains ground faces
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaGrounded(int areanum)
{
return (aasworld.areasettings[areanum].areaflags & AREA_GROUNDED);
} //end of the function AAS_AreaGround
//===========================================================================
// returns true if the area contains ladder faces
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaLadder(int areanum)
{
return (aasworld.areasettings[areanum].areaflags & AREA_LADDER);
} //end of the function AAS_AreaLadder
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaJumpPad(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_JUMPPAD);
} //end of the function AAS_AreaJumpPad
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaTeleporter(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_TELEPORTER);
} //end of the function AAS_AreaTeleporter
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaClusterPortal(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL);
} //end of the function AAS_AreaClusterPortal
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_AreaDoNotEnter(int areanum)
{
return (aasworld.areasettings[areanum].contents & AREACONTENTS_DONOTENTER);
} //end of the function AAS_AreaDoNotEnter
//===========================================================================
// returns the time it takes perform a barrier jump
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -