Game Development Community

Problem with my bots

by Christian Weber · in Technical Issues · 09/04/2002 (11:46 am) · 4 replies

When I use the command "AIPlayer::handleWaypointsAndChase(%this)" Im getting a error msg that the command "getLocation" couldn't be find in the "AiPlayer.cs" file. Here is my file:

Quote:
//-----------------------------------------------------------------------------
// Torque Game Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------

//
// This is the default AIPlayer class file, when the aiAddPlayer function
// is executed, if an initalization function is provided it will
//

//-----------------------------------------------------------------------------
// Callback Handlers
//-----------------------------------------------------------------------------
function AIPlayer::onStuck() {
echo( "Ich haenge fest" );
}

function AIPlayer::onUnStuck() {
echo( "onUnStuck" );
}

function AIPlayer::onStop() {
echo( "Stoppe" );
}

function AIPlayer::onMove() {
echo( "Unterwegs" );
}

function AIPlayer::onReachDestination() {
echo( "onReachDestination" );
}

function AIPlayer::onTargetEnterLOS() {
echo( "onTargetEnterLOS" );
}

function AIPlayer::onTargetExitLOS() {
echo( "onTargetExitLOS" );
}

function AIPlayer::onAdd() {
echo( "Bot erstellt." );
}

//
// Test Fxn
//
function AITest::onAdd() {
echo( "Multi-namespace worked!" );
}

function AIPlayer::handleWaypointsAndChase(%this)
{
// look for next "available" human player... :-)
%nextClient = ClientGroup.getObject(AIPlayer::getClosestHuman(%this));
$daPlaya = %nextClient.player;
if(!isObject($daPlaya) || !isObject(%this))
{
return;
}
// get his position:
%playPos = $daPlaya.getPosition();
// but first look for some waypoints...
// if there are some waypoints to follow
if(isObject(BotMarkers))
{
%num = getNumberBotMarkers();
// %this.countMyMoves tracks the number of waypoints already passed by this AI
if(%this.countMyMoves $= "")
{
//echo number of waypoint once
echo(%num @ " BotMarkers gefunden!");
}
// output player posititon
error("Player Position: " @ %playPos);
// as long as this bot hasn't completed the waypoint path:
if(%this.countMyMoves < BotMarkers.getCount())
{
%dest = BotMarkers.getObject(%this.countMyMoves).position;
echo("Naechster Punkt: " @ %dest);
echo("Die Entfernung ist: " @ getMarkerDistance(%this.countMyMoves, %this));
echo("myMoves along the waypoint path:" SPC %this.countMyMoves);
%this.setMoveDestination(%dest);
%this.move();
%this.countMyMoves++;
}
// okay, finished path, time for hunting the player...
else
{
AIPlayer::shootHimIfYouSeeHim(%this, %playPos);
}
}
// else: No waypoints, so chase the player!
else
{
AIPlayer::shootHimIfYouSeeHim(%this, %playPos);
}
}

function AIPlayer::shootHimIfYouSeeHim(%this, %playPos)
{
%this.setTargetObject($daPlaya);
%iSeeHim = aiPlayer::isObjectInView(%this, $daPlaya);
error(%this.player SPC "isObjectInView:" SPC %iSeeHim);
if(%iSeeHim)
{
error(%this.player @ ": I see him!!!");
%this.setAimLocation($daPlaya.getWorldBoxCenter());
// do we have a weapon?
error(%this.player SPC "has Weapon:" SPC %this.player.hasInventory("Crossbow"));
error(%this.player SPC "has Ammo:" SPC %this.player.hasInventory("CrossbowAmmo"));
if ( (%this.player.hasInventory("Crossbow") && %this.player.hasInventory("CrossbowAmmo"))
|| (%this.player.hasInventory("Rifle") && %this.player.hasInventory("RifleAmmo")) )
{
// shoooooot
%this.setTrigger(0,true);
}
else
{
error(%this.player SPC "has no weapon/ammo!");
}
%this.setMoveDestination(%playPos);
%this.move();
}
// no player in sight?
else
{
// clear aim
%this.clearAim();
// check for next nearest player
%nextClient = ClientGroup.getObject(AIPlayer::getClosestHuman(%this));
$daPlaya = %nextClient.player;
if(!isObject($daPlaya))
{
return;
}
%playPos = $daPlaya.getPosition();
%this.setMoveDestination(%playPos);
%this.setAimLocation($daPlaya.getWorldBoxCenter());
%this.move();
}
}

// this one's provided by Ryan Mette
function aiPlayer::isObjectInView(%this, %object)
{
%player = %this.player;
// default sight range of AI:
%this.sightRange = 70.0;
if (!(isObject(%player) && isObject(%object))) return;

%objPos = %object.getWorldBoxCenter();
%eyePoint = %player.getWorldBoxCenter();
%distance = VectorDist(%objPos, %eyePoint);

error("DISTANCE:" SPC %distance);

if (%distance <= %this.sightRange)
{
// if the object is within 1.5 meters sometimes it can
// fall out of the field of view due to the eye height
if (%distance > 2)
{
%eyeTransform = %player.getEyeTransform();
%eyePoint = firstWord(%eyeTransform)
SPC getWord(%eyeTransform, 1)
SPC getWord(%eyeTransform, 2);
}
%eyeVector = VectorNormalize(%player.getEyeVector());

//make sure we're not looking through walls...
%mask = $TypeMasks::TerrainObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::StaticShapeObjectType;
%losResult = containerRayCast(%objPos, %eyePoint, %mask);
%losObject = GetWord(%losResult, 0);
if (!isObject(%losObject))
{
//create the vector from this client to the client
%objVector = VectorNormalize(VectorSub(%objPos, %eyePoint));

// dot product to determine field of view
%dot = VectorDot(%objVector, %eyeVector);

// within field of view
return (%dot > 0.6);
}
}
return false;
}

// provided by Jared Hoberock
// I changed it to use ClientGroup instead of its own array like Jared did...
function AIPlayer::getClosestHuman(%this) {
%botPos = %this.getLocation();
%count = ClientGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%client = ClientGroup.getObject(%i);
%playPos = %client.player.getPosition();
%tempDist = VectorDist(%playPos, %botPos);
if(%i == 0) {
%dist = %tempDist;
%index = %i;
}
else {
if(%dist > %tempDist) {
%dist = %tempDist;
%index = %i;
}
}
}
return %index;
}

function getNumberBotMarkers()
{
%count = BotMarkers.getCount();
return %count;
}
function getMarkerDistance(%markernumber, %bot)
{
%botPosition = %bot.getLocation();
%markerObject = BotMarkers.getObject(%markernumber);
%dist = vectorDist( %botPosition, %markerObject.position );
return %dist;
}

//-----------------------------------------------------------------------------
//

Any help would be nice and sorry for my bad spelling and grammar.

thx,
Chris

#1
09/04/2002 (11:56 am)
Try getPosition instead of getLocation.
#2
09/04/2002 (1:14 pm)
he doesnt find getPosition, too.
#3
09/04/2002 (1:20 pm)
Why don't you dump the contents of the object and see what is available. For example you could do:

Quote:%this.dump();

Then open your console using the tilde key and check the output.
#4
01/18/2004 (2:17 pm)
Does the AI work with the new version of RealmWars?