mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Merge pull request #3 from ZOD2015/ueberengine-dev
Teams implementation
This commit is contained in:
commit
b8d462e22e
4 changed files with 163 additions and 10 deletions
|
|
@ -30,7 +30,7 @@
|
||||||
#include "T3D/shapeBase.h"
|
#include "T3D/shapeBase.h"
|
||||||
#include "gfx/gfxDrawUtil.h"
|
#include "gfx/gfxDrawUtil.h"
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
|
#include "T3D/missionMarker.h" //> ZOD: Team coloring
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/// Displays name & damage above shape objects.
|
/// Displays name & damage above shape objects.
|
||||||
|
|
@ -52,7 +52,10 @@ class GuiShapeNameHud : public GuiControl {
|
||||||
ColorF mTextColor;
|
ColorF mTextColor;
|
||||||
ColorF mLabelFillColor;
|
ColorF mLabelFillColor;
|
||||||
ColorF mLabelFrameColor;
|
ColorF mLabelFrameColor;
|
||||||
|
// ZOD: Team coloring
|
||||||
|
ColorF mEnemyTextColor;
|
||||||
|
ColorF mNeutralTextColor;
|
||||||
|
//> ZOD: End addition
|
||||||
F32 mVerticalOffset;
|
F32 mVerticalOffset;
|
||||||
F32 mDistanceFade;
|
F32 mDistanceFade;
|
||||||
bool mShowFrame;
|
bool mShowFrame;
|
||||||
|
|
@ -63,7 +66,10 @@ class GuiShapeNameHud : public GuiControl {
|
||||||
Point2I mLabelPadding;
|
Point2I mLabelPadding;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawName( Point2I offset, const char *buf, F32 opacity);
|
// ZOD: Team coloring
|
||||||
|
//void drawName( Point2I offset, const char *buf, F32 opacity);
|
||||||
|
void drawName( Point2I offset, const char *buf, F32 opacity, ColorF color);
|
||||||
|
//> ZOD: End edit
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuiShapeNameHud();
|
GuiShapeNameHud();
|
||||||
|
|
@ -120,6 +126,10 @@ GuiShapeNameHud::GuiShapeNameHud()
|
||||||
mLabelFillColor.set( 0.25f, 0.25f, 0.25f, 0.25f );
|
mLabelFillColor.set( 0.25f, 0.25f, 0.25f, 0.25f );
|
||||||
mLabelFrameColor.set( 0, 1, 0, 1 );
|
mLabelFrameColor.set( 0, 1, 0, 1 );
|
||||||
mTextColor.set( 0, 1, 0, 1 );
|
mTextColor.set( 0, 1, 0, 1 );
|
||||||
|
//> ZOD: Team coloring
|
||||||
|
mEnemyTextColor.set( 1, 0, 0, 1 );
|
||||||
|
mNeutralTextColor.set( 1, 1, 1, 1 );
|
||||||
|
//> ZOD: End addition
|
||||||
mShowFrame = mShowFill = true;
|
mShowFrame = mShowFill = true;
|
||||||
mShowLabelFrame = mShowLabelFill = false;
|
mShowLabelFrame = mShowLabelFill = false;
|
||||||
mVerticalOffset = 0.5f;
|
mVerticalOffset = 0.5f;
|
||||||
|
|
@ -135,6 +145,10 @@ void GuiShapeNameHud::initPersistFields()
|
||||||
addField( "textColor", TypeColorF, Offset( mTextColor, GuiShapeNameHud ), "Color for the text on this control." );
|
addField( "textColor", TypeColorF, Offset( mTextColor, GuiShapeNameHud ), "Color for the text on this control." );
|
||||||
addField( "labelFillColor", TypeColorF, Offset( mLabelFillColor, GuiShapeNameHud ), "Color for the background of each shape name label." );
|
addField( "labelFillColor", TypeColorF, Offset( mLabelFillColor, GuiShapeNameHud ), "Color for the background of each shape name label." );
|
||||||
addField( "labelFrameColor", TypeColorF, Offset( mLabelFrameColor, GuiShapeNameHud ), "Color for the frames around each shape name label." );
|
addField( "labelFrameColor", TypeColorF, Offset( mLabelFrameColor, GuiShapeNameHud ), "Color for the frames around each shape name label." );
|
||||||
|
// ZOD: Team coloring
|
||||||
|
addField( "enemyTextColor", TypeColorF, Offset( mEnemyTextColor, GuiShapeNameHud ), "Color for enemy shapes." );
|
||||||
|
//> ZOD: End addition
|
||||||
|
addField( "neutralTextColor", TypeColorF, Offset( mNeutralTextColor, GuiShapeNameHud ), "Color for neutral shapes." );
|
||||||
endGroup("Colors");
|
endGroup("Colors");
|
||||||
|
|
||||||
addGroup("Misc");
|
addGroup("Misc");
|
||||||
|
|
@ -174,7 +188,10 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
// Must have a connection and control object
|
// Must have a connection and control object
|
||||||
GameConnection* conn = GameConnection::getConnectionToServer();
|
GameConnection* conn = GameConnection::getConnectionToServer();
|
||||||
if (!conn) return;
|
if (!conn) return;
|
||||||
GameBase * control = dynamic_cast<GameBase*>(conn->getControlObject());
|
//> ZOD: Team coloring
|
||||||
|
//GameBase * control = dynamic_cast<GameBase*>(conn->getControlObject());
|
||||||
|
ShapeBase * control = dynamic_cast<ShapeBase*>(conn->getControlObject());
|
||||||
|
//< ZOD: End edit
|
||||||
if (!control) return;
|
if (!control) return;
|
||||||
|
|
||||||
// Get control camera info
|
// Get control camera info
|
||||||
|
|
@ -199,6 +216,12 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
static U32 losMask = TerrainObjectType | ShapeBaseObjectType | StaticObjectType;
|
static U32 losMask = TerrainObjectType | ShapeBaseObjectType | StaticObjectType;
|
||||||
control->disableCollision();
|
control->disableCollision();
|
||||||
|
|
||||||
|
//> ZOD: Team coloring
|
||||||
|
ColorF renderColor;
|
||||||
|
const char *fof = NULL;
|
||||||
|
char buf[64];
|
||||||
|
//< ZOD: End addition
|
||||||
|
|
||||||
// All ghosted objects are added to the server connection group,
|
// All ghosted objects are added to the server connection group,
|
||||||
// so we can find all the shape base objects by iterating through
|
// so we can find all the shape base objects by iterating through
|
||||||
// our current connection.
|
// our current connection.
|
||||||
|
|
@ -207,6 +230,9 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
if ( shape ) {
|
if ( shape ) {
|
||||||
if (shape != control && shape->getShapeName())
|
if (shape != control && shape->getShapeName())
|
||||||
{
|
{
|
||||||
|
//> ZOD: If cloaked, early out
|
||||||
|
if ( shape->getCloakedState() )
|
||||||
|
continue;
|
||||||
|
|
||||||
// Target pos to test, if it's a player run the LOS to his eye
|
// Target pos to test, if it's a player run the LOS to his eye
|
||||||
// point, otherwise we'll grab the generic box center.
|
// point, otherwise we'll grab the generic box center.
|
||||||
|
|
@ -266,8 +292,32 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
F32 opacity = (shapeDist < fadeDistance)? 1.0:
|
F32 opacity = (shapeDist < fadeDistance)? 1.0:
|
||||||
1.0 - (shapeDist - fadeDistance) / (visDistance - fadeDistance);
|
1.0 - (shapeDist - fadeDistance) / (visDistance - fadeDistance);
|
||||||
|
|
||||||
|
//> ZOD: Team coloring
|
||||||
|
|
||||||
|
S32 myId = control->getTeamId();
|
||||||
|
S32 targetId = shape->getTeamId();
|
||||||
|
if(targetId == 0)
|
||||||
|
{
|
||||||
|
fof = "N";
|
||||||
|
renderColor = mNeutralTextColor;
|
||||||
|
}
|
||||||
|
else if(myId != targetId)
|
||||||
|
{
|
||||||
|
fof = "E";
|
||||||
|
renderColor = mEnemyTextColor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fof = "F";
|
||||||
|
renderColor = mTextColor;
|
||||||
|
}
|
||||||
|
// Append the distance from the shape to the name
|
||||||
|
dSprintf(buf,sizeof(buf), "%s : %gm", shape->getShapeName(), mFloor(shapeDist));
|
||||||
|
drawName(Point2I((S32)projPnt.x, (S32)projPnt.y), buf, opacity, renderColor);
|
||||||
|
|
||||||
|
//< ZOD: End addition
|
||||||
// Render the shape's name
|
// Render the shape's name
|
||||||
drawName(Point2I((S32)projPnt.x, (S32)projPnt.y),shape->getShapeName(),opacity);
|
//drawName(Point2I((S32)projPnt.x, (S32)projPnt.y),shape->getShapeName(),opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -275,6 +325,45 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
// Restore control object collision
|
// Restore control object collision
|
||||||
control->enableCollision();
|
control->enableCollision();
|
||||||
|
|
||||||
|
// ZOD: Waypoints
|
||||||
|
|
||||||
|
SimSet *WayPointSet = Sim::getWayPointSet();
|
||||||
|
SimSet::iterator i;
|
||||||
|
for(i = WayPointSet->begin(); i != WayPointSet->end(); i++)
|
||||||
|
{
|
||||||
|
WayPoint *way = (WayPoint *) (*i);
|
||||||
|
S32 myId = control->getTeamId();
|
||||||
|
S32 wayId = way->getTeamId();
|
||||||
|
|
||||||
|
Point3F wayPos;
|
||||||
|
MatrixF srtMat = way->getTransform();
|
||||||
|
srtMat.getColumn(3, &wayPos);
|
||||||
|
|
||||||
|
VectorF wayDir = wayPos - control->getPosition();//camPos;
|
||||||
|
F32 wayDist = wayDir.lenSquared();
|
||||||
|
if (wayDist == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
wayDist = mSqrt(wayDist);
|
||||||
|
|
||||||
|
Point3F projPnt;
|
||||||
|
wayPos.z += mVerticalOffset;
|
||||||
|
if (!parent->project(wayPos, &projPnt))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fof = way->mName;
|
||||||
|
if(wayId == 0)
|
||||||
|
renderColor = mNeutralTextColor;
|
||||||
|
else if(myId != wayId)
|
||||||
|
renderColor = mEnemyTextColor;
|
||||||
|
else
|
||||||
|
renderColor = mTextColor;
|
||||||
|
|
||||||
|
dSprintf(buf,sizeof(buf), "%s : %gm", fof, mFloor(wayDist));
|
||||||
|
drawName(Point2I((S32)projPnt.x, (S32)projPnt.y), buf, renderColor.alpha, renderColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZOD: End addition
|
||||||
// Border last
|
// Border last
|
||||||
if (mShowFrame)
|
if (mShowFrame)
|
||||||
GFX->getDrawUtil()->drawRect(updateRect, mFrameColor);
|
GFX->getDrawUtil()->drawRect(updateRect, mFrameColor);
|
||||||
|
|
@ -291,7 +380,7 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect)
|
||||||
/// specified y position.)
|
/// specified y position.)
|
||||||
/// @param name String name to display.
|
/// @param name String name to display.
|
||||||
/// @param opacity Opacity of name (a fraction).
|
/// @param opacity Opacity of name (a fraction).
|
||||||
void GuiShapeNameHud::drawName(Point2I offset, const char *name, F32 opacity)
|
void GuiShapeNameHud::drawName(Point2I offset, const char *name, F32 opacity, ColorF mTextColor)
|
||||||
{
|
{
|
||||||
F32 width = mProfile->mFont->getStrWidth((const UTF8 *)name) + mLabelPadding.x * 2;
|
F32 width = mProfile->mFont->getStrWidth((const UTF8 *)name) + mLabelPadding.x * 2;
|
||||||
F32 height = mProfile->mFont->getHeight() + mLabelPadding.y * 2;
|
F32 height = mProfile->mFont->getHeight() + mLabelPadding.y * 2;
|
||||||
|
|
|
||||||
|
|
@ -907,6 +907,7 @@ ShapeBase::ShapeBase()
|
||||||
damageDir( 0.0f, 0.0f, 1.0f ),
|
damageDir( 0.0f, 0.0f, 1.0f ),
|
||||||
mCloaked( false ),
|
mCloaked( false ),
|
||||||
mCloakLevel( 0.0f ),
|
mCloakLevel( 0.0f ),
|
||||||
|
mTeamId( 0 ), //> ZOD: Add team Id
|
||||||
mFadeOut( true ),
|
mFadeOut( true ),
|
||||||
mFading( false ),
|
mFading( false ),
|
||||||
mFadeVal( 1.0f ),
|
mFadeVal( 1.0f ),
|
||||||
|
|
@ -2969,6 +2970,12 @@ U32 ShapeBase::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
||||||
ThreadMask | ImageMask | CloakMask | SkinMask)))
|
ThreadMask | ImageMask | CloakMask | SkinMask)))
|
||||||
return retMask;
|
return retMask;
|
||||||
|
|
||||||
|
//> ZOD: Add team Id
|
||||||
|
if(stream->writeFlag(mask & TeamMask)) {
|
||||||
|
stream->write(mTeamId);
|
||||||
|
}
|
||||||
|
//< ZOD: End addition
|
||||||
|
|
||||||
if (stream->writeFlag(mask & DamageMask)) {
|
if (stream->writeFlag(mask & DamageMask)) {
|
||||||
stream->writeFloat(mClampF(mDamage / mDataBlock->maxDamage, 0.f, 1.f), DamageLevelBits);
|
stream->writeFloat(mClampF(mDamage / mDataBlock->maxDamage, 0.f, 1.f), DamageLevelBits);
|
||||||
stream->writeInt(mDamageState,NumDamageStateBits);
|
stream->writeInt(mDamageState,NumDamageStateBits);
|
||||||
|
|
@ -3076,6 +3083,12 @@ void ShapeBase::unpackUpdate(NetConnection *con, BitStream *stream)
|
||||||
if(!stream->readFlag())
|
if(!stream->readFlag())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//> ZOD: Add team Id
|
||||||
|
if(stream->readFlag()) {
|
||||||
|
stream->read(&mTeamId);
|
||||||
|
}
|
||||||
|
//< ZOD: End addition
|
||||||
|
|
||||||
if (stream->readFlag()) {
|
if (stream->readFlag()) {
|
||||||
mDamage = mClampF(stream->readFloat(DamageLevelBits) * mDataBlock->maxDamage, 0.f, mDataBlock->maxDamage);
|
mDamage = mClampF(stream->readFloat(DamageLevelBits) * mDataBlock->maxDamage, 0.f, mDataBlock->maxDamage);
|
||||||
DamageState prevState = mDamageState;
|
DamageState prevState = mDamageState;
|
||||||
|
|
@ -3579,6 +3592,35 @@ void ShapeBase::setCurrentWaterObject( WaterObject *obj )
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
//> ZOD: Add team Id
|
||||||
|
void ShapeBase::setTeamId(S32 teamId)
|
||||||
|
{
|
||||||
|
if(teamId < 0)
|
||||||
|
teamId = 0;
|
||||||
|
|
||||||
|
mTeamId = teamId;
|
||||||
|
setMaskBits(TeamMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod( ShapeBase, setTeamId, void, ( S32 teamId ),,
|
||||||
|
"@brief Set this object's current team.\n\n"
|
||||||
|
|
||||||
|
"@param teamId new team\n"
|
||||||
|
|
||||||
|
"@see getTeamId()\n")
|
||||||
|
{
|
||||||
|
object->setTeamId( teamId );
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod( ShapeBase, getTeamId, S32, (),,
|
||||||
|
"@brief Get the object's current team.\n\n"
|
||||||
|
|
||||||
|
"@return team\n"
|
||||||
|
|
||||||
|
"@see setTeamId()\n")
|
||||||
|
{
|
||||||
|
return object->getTeamId();
|
||||||
|
}
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
DefineEngineMethod( ShapeBase, setHidden, void, ( bool show ),,
|
DefineEngineMethod( ShapeBase, setHidden, void, ( bool show ),,
|
||||||
"@brief Add or remove this object from the scene.\n\n"
|
"@brief Add or remove this object from the scene.\n\n"
|
||||||
|
|
|
||||||
|
|
@ -876,7 +876,7 @@ protected:
|
||||||
|
|
||||||
F32 mEnergy; ///< Current enery level.
|
F32 mEnergy; ///< Current enery level.
|
||||||
F32 mRechargeRate; ///< Energy recharge rate (in units/tick).
|
F32 mRechargeRate; ///< Energy recharge rate (in units/tick).
|
||||||
|
S32 mTeamId; ///< ZOD: Team identification for shape name
|
||||||
F32 mMass; ///< Mass.
|
F32 mMass; ///< Mass.
|
||||||
F32 mOneOverMass; ///< Inverse of mass.
|
F32 mOneOverMass; ///< Inverse of mass.
|
||||||
/// @note This is used to optimize certain physics calculations.
|
/// @note This is used to optimize certain physics calculations.
|
||||||
|
|
@ -1139,8 +1139,11 @@ public:
|
||||||
DamageMask = Parent::NextFreeMask << 1,
|
DamageMask = Parent::NextFreeMask << 1,
|
||||||
NoWarpMask = Parent::NextFreeMask << 2,
|
NoWarpMask = Parent::NextFreeMask << 2,
|
||||||
CloakMask = Parent::NextFreeMask << 3,
|
CloakMask = Parent::NextFreeMask << 3,
|
||||||
SkinMask = Parent::NextFreeMask << 4,
|
//SkinMask = Parent::NextFreeMask << 4,
|
||||||
MeshHiddenMask = Parent::NextFreeMask << 5,
|
SkinMask = CloakMask,
|
||||||
|
//MeshHiddenMask = Parent::NextFreeMask << 5,
|
||||||
|
MeshHiddenMask = Parent::NextFreeMask << 4,
|
||||||
|
TeamMask = Parent::NextFreeMask << 5, //> ZOD: Add team Id
|
||||||
SoundMaskN = Parent::NextFreeMask << 6, ///< Extends + MaxSoundThreads bits
|
SoundMaskN = Parent::NextFreeMask << 6, ///< Extends + MaxSoundThreads bits
|
||||||
ThreadMaskN = SoundMaskN << MaxSoundThreads, ///< Extends + MaxScriptThreads bits
|
ThreadMaskN = SoundMaskN << MaxSoundThreads, ///< Extends + MaxScriptThreads bits
|
||||||
ImageMaskN = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits
|
ImageMaskN = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits
|
||||||
|
|
@ -1170,7 +1173,10 @@ public:
|
||||||
void onSceneRemove();
|
void onSceneRemove();
|
||||||
static void consoleInit();
|
static void consoleInit();
|
||||||
bool onNewDataBlock( GameBaseData *dptr, bool reload );
|
bool onNewDataBlock( GameBaseData *dptr, bool reload );
|
||||||
|
//> ZOD: Add team Id
|
||||||
|
S32 getTeamId() { return mTeamId; }
|
||||||
|
void setTeamId(S32 team);
|
||||||
|
//< ZOD: End addition
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// @name Name & Skin tags
|
/// @name Name & Skin tags
|
||||||
|
|
|
||||||
|
|
@ -380,6 +380,12 @@ static void _scanCallback( SceneObject* object, void* data )
|
||||||
ShapeBase* shape = dynamic_cast<ShapeBase*>(object);
|
ShapeBase* shape = dynamic_cast<ShapeBase*>(object);
|
||||||
if (shape && shape->getDamageState() == ShapeBase::Enabled)
|
if (shape && shape->getDamageState() == ShapeBase::Enabled)
|
||||||
{
|
{
|
||||||
|
//> ZOD: Filter out these immediately
|
||||||
|
S32 myId = turret->getTeamId();
|
||||||
|
S32 targetId = shape->getTeamId();
|
||||||
|
if (myId == targetId || shape->getCloakedState())
|
||||||
|
return;
|
||||||
|
//< ZOD: End addition
|
||||||
Point3F targetPos = shape->getBoxCenter();
|
Point3F targetPos = shape->getBoxCenter();
|
||||||
|
|
||||||
// Put target position into the scan node's space
|
// Put target position into the scan node's space
|
||||||
|
|
@ -1352,3 +1358,13 @@ DefineEngineMethod( AITurretShape, recenterTurret, void, ( ),,
|
||||||
{
|
{
|
||||||
object->recenterTurret();
|
object->recenterTurret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//< ZOD: You will shoot who I say to shoot!
|
||||||
|
DefineEngineMethod( AITurretShape, addToTargetList, void, (ShapeBase* obj),,
|
||||||
|
"@brief Adds object to the turret's target list.\n\n"
|
||||||
|
"All objects in this list will be targeted by the turret.\n"
|
||||||
|
"@param obj The ShapeBase object to target.\n")
|
||||||
|
{
|
||||||
|
object->addPotentialTarget(obj);
|
||||||
|
}
|
||||||
|
//< ZOD: End addition
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue