completed list of roughly ported over scripthooks.

todo: need to figure out why followobject is only hitting the first path node. likely  amixup with goal handling
This commit is contained in:
AzaezelX 2025-04-17 01:27:08 -05:00
parent e37ae27bc0
commit 4fb92f02a3
16 changed files with 386 additions and 40 deletions

View file

@ -19,3 +19,90 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "AICover.h"
#include "AIController.h"
struct CoverSearch
{
Point3F loc;
Point3F from;
F32 dist;
F32 best;
CoverPoint* point;
CoverSearch() : loc(0, 0, 0), from(0, 0, 0)
{
best = -FLT_MAX;
point = NULL;
dist = FLT_MAX;
}
};
static void findCoverCallback(SceneObject* obj, void* key)
{
CoverPoint* p = dynamic_cast<CoverPoint*>(obj);
if (!p || p->isOccupied())
return;
CoverSearch* s = static_cast<CoverSearch*>(key);
Point3F dir = s->from - p->getPosition();
dir.normalizeSafe();
// Score first based on angle of cover point to enemy.
F32 score = mDot(p->getNormal(), dir);
// Score also based on distance from seeker.
score -= (p->getPosition() - s->loc).len() / s->dist;
// Finally, consider cover size.
score += (p->getSize() + 1) / CoverPoint::NumSizes;
score *= p->getQuality();
if (score > s->best)
{
s->best = score;
s->point = p;
}
}
bool AIController::findCover(const Point3F& from, F32 radius)
{
if (radius <= 0)
return false;
// Create a search state.
CoverSearch s;
s.loc = getAIInfo()->getPosition();
s.dist = radius;
// Direction we seek cover FROM.
s.from = from;
// Find cover points.
Box3F box(radius * 2.0f);
box.setCenter(getAIInfo()->getPosition());
getAIInfo()->mObj->getContainer()->findObjects(box, MarkerObjectType, findCoverCallback, &s);
// Go to cover!
if (s.point)
{
// Calling setPathDestination clears cover...
bool foundPath = getNav()->setPathDestination(s.point->getPosition());
setCover(s.point);
s.point->setOccupied(true);
return foundPath;
}
return false;
}
DefineEngineMethod(AIController, findCover, S32, (Point3F from, F32 radius), ,
"@brief Tells the AI to find cover nearby.\n\n"
"@param from Location to find cover from (i.e., enemy position).\n"
"@param radius Distance to search for cover.\n"
"@return Cover point ID if cover was found, -1 otherwise.\n\n")
{
if (object->findCover(from, radius))
{
CoverPoint* cover = object->getCover()->mCoverPoint.getObject();
return cover ? cover->getId() : -1;
}
else
{
return -1;
}
}