mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-17 11:00:38 +02:00
Added bot code.
This commit is contained in:
+6
-150
@@ -30,6 +30,10 @@ If you have questions concerning this license or the applicable additional terms
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../Game_local.h"
|
||||
#include "AASCallback_AvoidLocation.h"
|
||||
#include "AASCallback_FindAreaOutOfRange.h"
|
||||
#include "AASCallback_FindAttackPosition.h"
|
||||
#include "AASCallback_FindCoverArea.h"
|
||||
|
||||
static const char* moveCommandString[NUM_MOVE_COMMANDS] = {
|
||||
"MOVE_NONE",
|
||||
@@ -128,154 +132,6 @@ void idMoveState::Restore(idRestoreGame* savefile) {
|
||||
savefile->ReadInt(anim);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindCover::idAASFindCover
|
||||
============
|
||||
*/
|
||||
idAASFindCover::idAASFindCover(const idVec3& hideFromPos) {
|
||||
int numPVSAreas;
|
||||
idBounds bounds(hideFromPos - idVec3(16, 16, 0), hideFromPos + idVec3(16, 16, 64));
|
||||
|
||||
// setup PVS
|
||||
numPVSAreas = gameLocal.pvs.GetPVSAreas(bounds, PVSAreas, idEntity::MAX_PVS_AREAS);
|
||||
hidePVS = gameLocal.pvs.SetupCurrentPVS(PVSAreas, numPVSAreas);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindCover::~idAASFindCover
|
||||
============
|
||||
*/
|
||||
idAASFindCover::~idAASFindCover() {
|
||||
gameLocal.pvs.FreeCurrentPVS(hidePVS);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindCover::TestArea
|
||||
============
|
||||
*/
|
||||
bool idAASFindCover::TestArea(const idAAS* aas, int areaNum) {
|
||||
idVec3 areaCenter;
|
||||
int numPVSAreas;
|
||||
int PVSAreas[idEntity::MAX_PVS_AREAS];
|
||||
|
||||
areaCenter = aas->AreaCenter(areaNum);
|
||||
areaCenter[2] += 1.0f;
|
||||
|
||||
numPVSAreas = gameLocal.pvs.GetPVSAreas(idBounds(areaCenter).Expand(16.0f), PVSAreas, idEntity::MAX_PVS_AREAS);
|
||||
if (!gameLocal.pvs.InCurrentPVS(hidePVS, PVSAreas, numPVSAreas)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindAreaOutOfRange::idAASFindAreaOutOfRange
|
||||
============
|
||||
*/
|
||||
idAASFindAreaOutOfRange::idAASFindAreaOutOfRange(const idVec3& targetPos, float maxDist) {
|
||||
this->targetPos = targetPos;
|
||||
this->maxDistSqr = maxDist * maxDist;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindAreaOutOfRange::TestArea
|
||||
============
|
||||
*/
|
||||
bool idAASFindAreaOutOfRange::TestArea(const idAAS* aas, int areaNum) {
|
||||
const idVec3& areaCenter = aas->AreaCenter(areaNum);
|
||||
trace_t trace;
|
||||
float dist;
|
||||
|
||||
dist = (targetPos.ToVec2() - areaCenter.ToVec2()).LengthSqr();
|
||||
|
||||
if ((maxDistSqr > 0.0f) && (dist < maxDistSqr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gameLocal.clip.TracePoint(trace, targetPos, areaCenter + idVec3(0.0f, 0.0f, 1.0f), MASK_OPAQUE, NULL);
|
||||
if (trace.fraction < 1.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindAttackPosition::idAASFindAttackPosition
|
||||
============
|
||||
*/
|
||||
idAASFindAttackPosition::idAASFindAttackPosition(const idAI* self, const idMat3& gravityAxis, idEntity* target, const idVec3& targetPos, const idVec3& fireOffset) {
|
||||
int numPVSAreas;
|
||||
|
||||
this->target = target;
|
||||
this->targetPos = targetPos;
|
||||
this->fireOffset = fireOffset;
|
||||
this->self = self;
|
||||
this->gravityAxis = gravityAxis;
|
||||
|
||||
excludeBounds = idBounds(idVec3(-64.0, -64.0f, -8.0f), idVec3(64.0, 64.0f, 64.0f));
|
||||
excludeBounds.TranslateSelf(self->GetPhysics()->GetOrigin());
|
||||
|
||||
// setup PVS
|
||||
idBounds bounds(targetPos - idVec3(16, 16, 0), targetPos + idVec3(16, 16, 64));
|
||||
numPVSAreas = gameLocal.pvs.GetPVSAreas(bounds, PVSAreas, idEntity::MAX_PVS_AREAS);
|
||||
targetPVS = gameLocal.pvs.SetupCurrentPVS(PVSAreas, numPVSAreas);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindAttackPosition::~idAASFindAttackPosition
|
||||
============
|
||||
*/
|
||||
idAASFindAttackPosition::~idAASFindAttackPosition() {
|
||||
gameLocal.pvs.FreeCurrentPVS(targetPVS);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
idAASFindAttackPosition::TestArea
|
||||
============
|
||||
*/
|
||||
bool idAASFindAttackPosition::TestArea(const idAAS* aas, int areaNum) {
|
||||
idVec3 dir;
|
||||
idVec3 local_dir;
|
||||
idVec3 fromPos;
|
||||
idMat3 axis;
|
||||
idVec3 areaCenter;
|
||||
int numPVSAreas;
|
||||
int PVSAreas[idEntity::MAX_PVS_AREAS];
|
||||
|
||||
areaCenter = aas->AreaCenter(areaNum);
|
||||
areaCenter[2] += 1.0f;
|
||||
|
||||
if (excludeBounds.ContainsPoint(areaCenter)) {
|
||||
// too close to where we already are
|
||||
return false;
|
||||
}
|
||||
|
||||
numPVSAreas = gameLocal.pvs.GetPVSAreas(idBounds(areaCenter).Expand(16.0f), PVSAreas, idEntity::MAX_PVS_AREAS);
|
||||
if (!gameLocal.pvs.InCurrentPVS(targetPVS, PVSAreas, numPVSAreas)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// calculate the world transform of the launch position
|
||||
dir = targetPos - areaCenter;
|
||||
gravityAxis.ProjectVector(dir, local_dir);
|
||||
local_dir.z = 0.0f;
|
||||
local_dir.ToVec2().Normalize();
|
||||
axis = local_dir.ToMat3();
|
||||
fromPos = areaCenter + fireOffset * axis;
|
||||
|
||||
return self->GetAimDir(fromPos, target, self, dir);
|
||||
}
|
||||
|
||||
/*
|
||||
=====================
|
||||
idAI::idAI
|
||||
@@ -1839,7 +1695,7 @@ bool idAI::MoveOutOfRange(idEntity* ent, float range) {
|
||||
pos = ent->GetPhysics()->GetOrigin();
|
||||
}
|
||||
|
||||
idAASFindAreaOutOfRange findGoal(pos, range);
|
||||
idAASCallback_FindAreaOutOfRange findGoal(pos, range);
|
||||
if (!aas->FindNearestGoal(goal, areaNum, org, pos, travelFlags, &obstacle, 1, findGoal)) {
|
||||
StopMove(MOVE_STATUS_DEST_UNREACHABLE);
|
||||
AI_DEST_UNREACHABLE = true;
|
||||
@@ -1990,7 +1846,7 @@ bool idAI::MoveToCover(idEntity* entity, const idVec3& hideFromPos) {
|
||||
// consider the entity the monster tries to hide from as an obstacle
|
||||
obstacle.absBounds = entity->GetPhysics()->GetAbsBounds();
|
||||
|
||||
idAASFindCover findCover(hideFromPos);
|
||||
idAASCallback_FindCoverArea findCover(hideFromPos);
|
||||
if (!aas->FindNearestGoal(hideGoal, areaNum, org, hideFromPos, travelFlags, &obstacle, 1, findCover)) {
|
||||
StopMove(MOVE_STATUS_DEST_UNREACHABLE);
|
||||
AI_DEST_UNREACHABLE = true;
|
||||
|
||||
Reference in New Issue
Block a user