Skip to content

Commit

Permalink
09.1.5添加版本
Browse files Browse the repository at this point in the history
  • Loading branch information
johnalan committed Jan 4, 2010
0 parents commit d225fc8
Show file tree
Hide file tree
Showing 1,762 changed files with 526,661 additions and 0 deletions.
542 changes: 542 additions & 0 deletions T3D/aiClient.cpp

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions T3D/aiClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------------
// Torque 3D
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#ifndef _AICLIENT_H_
#define _AICLIENT_H_

#ifndef _AICONNECTION_H_
#include "T3D/aiConnection.h"
#endif
#ifndef _TVECTOR_H_
#include "core/util/tVector.h"
#endif

class ShapeBase;
class Player;

class AIClient : public AIConnection {

typedef AIConnection Parent;

private:
enum {
FireTrigger = 0,
JumpTrigger = 2,
JetTrigger = 3,
GrenadeTrigger = 4,
MineTrigger = 5
};

F32 mMoveSpeed;
S32 mMoveMode;
F32 mMoveTolerance; // How close to the destination before we stop

bool mTriggers[MaxTriggerKeys];

Player *mPlayer;

Point3F mMoveDestination;
Point3F mLocation;
Point3F mLastLocation; // For stuck check

bool mAimToDestination;
Point3F mAimLocation;
bool mTargetInLOS;

SimObjectPtr<ShapeBase> mTargetObject;

// Utility Methods
void throwCallback( const char *name );
public:

DECLARE_CONOBJECT( AIClient );

enum {
ModeStop = 0,
ModeMove,
ModeStuck,
ModeCount // This is in there as a max index value
};

AIClient();
~AIClient();

U32 getMoveList( Move **movePtr,U32 *numMoves );

// ---Targeting and aiming sets/gets
void setTargetObject( ShapeBase *targetObject );
S32 getTargetObject() const;

// ---Movement sets/gets
void setMoveSpeed( const F32 speed );
F32 getMoveSpeed() const { return mMoveSpeed; }

void setMoveMode( S32 mode );
S32 getMoveMode() const { return mMoveMode; }

void setMoveTolerance( const F32 tolerance );
F32 getMoveTolerance() const { return mMoveTolerance; }

void setMoveDestination( const Point3F &location );
Point3F getMoveDestination() const { return mMoveDestination; }

Point3F getLocation() const { return mLocation; }

// ---Facing(Aiming) sets/gets
void setAimLocation( const Point3F &location );
Point3F getAimLocation() const { return mAimLocation; }
void clearAim();

// ---Other
void missionCycleCleanup();
void onAdd( const char *nameSpace );
};

#endif
193 changes: 193 additions & 0 deletions T3D/aiConnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
//-----------------------------------------------------------------------------
// Torque 3D
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#include "T3D/aiConnection.h"

IMPLEMENT_CONOBJECT( AIConnection );


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

AIConnection::AIConnection() {
mAIControlled = true;
mMove = NullMove;
}


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

void AIConnection::clearMoves( U32 )
{
// Clear the pending move list. This connection generates moves
// on the fly, so there are never any pending moves.
}

void AIConnection::setMove(Move* m)
{
mMove = *m;
}

const Move& AIConnection::getMove()
{
return mMove;
}

/// Retrive the pending moves
/**
* The GameConnection base class queues moves for delivery to the
* controll object. This function is normally used to retrieve the
* queued moves recieved from the client. The AI connection does not
* have a connected client and simply generates moves on-the-fly
* base on it's current state.
*/
U32 AIConnection::getMoveList( Move **lngMove, U32 *numMoves )
{
*numMoves = 1;
*lngMove = &mMove;
return *numMoves;
}


//-----------------------------------------------------------------------------
// Console functions & methods
//-----------------------------------------------------------------------------

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

static inline F32 moveClamp(F32 v)
{
// Support function to convert/clamp the input into a move rotation
// which only allows 0 -> M_2PI.
F32 a = mClampF(v, -M_2PI_F, M_2PI_F);
return (a < 0) ? a + M_2PI_F : a;
}


//-----------------------------------------------------------------------------
/// Construct and connect an AI connection object
ConsoleFunction(aiConnect, S32 , 2, 20, "(...)"
"Make a new AIConnection, and pass arguments to the onConnect script callback.")
{
// Create the connection
AIConnection *aiConnection = new AIConnection();
aiConnection->registerObject();

// Add the connection to the client group
SimGroup *g = Sim::getClientGroup();
g->addObject( aiConnection );

// Prep the arguments for the console exec...
// Make sure and leav args[1] empty.
const char* args[21];
args[0] = "onConnect";
for (S32 i = 1; i < argc; i++)
args[i + 1] = argv[i];

// Execute the connect console function, this is the same
// onConnect function invoked for normal client connections
Con::execute(aiConnection, argc + 1, args);
return aiConnection->getId();
}


//-----------------------------------------------------------------------------
ConsoleMethod(AIConnection,setMove,void,4, 4,"(string field, float value)"
"Set a field on the current move.\n\n"
"@param field One of {'x','y','z','yaw','pitch','roll'}\n"
"@param value Value to set field to.")
{
Move move = object->getMove();

// Ok, a little slow for now, but this is just an example..
if (!dStricmp(argv[2],"x"))
move.x = mClampF(dAtof(argv[3]),-1,1);
else
if (!dStricmp(argv[2],"y"))
move.y = mClampF(dAtof(argv[3]),-1,1);
else
if (!dStricmp(argv[2],"z"))
move.z = mClampF(dAtof(argv[3]),-1,1);
else
if (!dStricmp(argv[2],"yaw"))
move.yaw = moveClamp(dAtof(argv[3]));
else
if (!dStricmp(argv[2],"pitch"))
move.pitch = moveClamp(dAtof(argv[3]));
else
if (!dStricmp(argv[2],"roll"))
move.roll = moveClamp(dAtof(argv[3]));

//
object->setMove(&move);
}

ConsoleMethod(AIConnection,getMove,F32,3, 3,"(string field)"
"Get the given field of a move.\n\n"
"@param field One of {'x','y','z','yaw','pitch','roll'}\n"
"@returns The requested field on the current move.")
{
const Move& move = object->getMove();
if (!dStricmp(argv[2],"x"))
return move.x;
if (!dStricmp(argv[2],"y"))
return move.y;
if (!dStricmp(argv[2],"z"))
return move.z;
if (!dStricmp(argv[2],"yaw"))
return move.yaw;
if (!dStricmp(argv[2],"pitch"))
return move.pitch;
if (!dStricmp(argv[2],"roll"))
return move.roll;
return 0;
}


ConsoleMethod(AIConnection,setFreeLook,void,3, 3,"(bool isFreeLook)"
"Enable/disable freelook on the current move.")
{
Move move = object->getMove();
move.freeLook = dAtob(argv[2]);
object->setMove(&move);
}

ConsoleMethod(AIConnection,getFreeLook,bool,2, 2,"getFreeLook()"
"Is freelook on for the current move?")
{
return object->getMove().freeLook;
}


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

ConsoleMethod(AIConnection,setTrigger,void,4, 4,"(int trigger, bool set)"
"Set a trigger.")
{
S32 idx = dAtoi(argv[2]);
if (idx >= 0 && idx < MaxTriggerKeys) {
Move move = object->getMove();
move.trigger[idx] = dAtob(argv[3]);
object->setMove(&move);
}
}

ConsoleMethod(AIConnection,getTrigger,bool,4, 4,"(int trigger)"
"Is the given trigger set?")
{
S32 idx = dAtoi(argv[2]);
if (idx >= 0 && idx < MaxTriggerKeys)
return object->getMove().trigger[idx];
return false;
}


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

ConsoleMethod(AIConnection,getAddress,const char*,2, 2,"")
{
// Override the netConnection method to return to indicate
// this is an ai connection.
return "ai:local";
}
39 changes: 39 additions & 0 deletions T3D/aiConnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// Torque 3D
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

#ifndef _AICONNECTION_H_
#define _AICONNECTION_H_

#ifndef _GAMECONNECTION_H_
#include "T3D/gameConnection.h"
#endif
#ifndef _MOVEMANAGER_H_
#include "T3D/moveManager.h"
#endif

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

class AIConnection : public GameConnection
{
typedef GameConnection Parent;

protected:
Move mMove;

public:
AIConnection();
DECLARE_CONOBJECT( AIConnection );

// Interface
const Move& getMove();
void setMove(Move *m);

// GameConnection overrides
void clearMoves(U32 n);
virtual U32 getMoveList(Move **,U32 *numMoves);
};


#endif
Loading

0 comments on commit d225fc8

Please sign in to comment.