From e471c960142a9032abd1bade68a7cb4cc668cd0f Mon Sep 17 00:00:00 2001 From: ZOD Date: Sat, 28 Nov 2015 11:32:40 -0500 Subject: [PATCH] Teams implementation Add team functionality to shapebase objects --- Engine/source/T3D/fps/guiShapeNameHud.cpp | 101 +++++++++++++++++++-- Engine/source/T3D/shapeBase.cpp | 42 +++++++++ Engine/source/T3D/shapeBase.h | 14 ++- Engine/source/T3D/turret/aiTurretShape.cpp | 16 ++++ 4 files changed, 163 insertions(+), 10 deletions(-) diff --git a/Engine/source/T3D/fps/guiShapeNameHud.cpp b/Engine/source/T3D/fps/guiShapeNameHud.cpp index 25a0ad7e0..2db8eafc7 100644 --- a/Engine/source/T3D/fps/guiShapeNameHud.cpp +++ b/Engine/source/T3D/fps/guiShapeNameHud.cpp @@ -30,7 +30,7 @@ #include "T3D/shapeBase.h" #include "gfx/gfxDrawUtil.h" #include "console/engineAPI.h" - +#include "T3D/missionMarker.h" //> ZOD: Team coloring //---------------------------------------------------------------------------- /// Displays name & damage above shape objects. @@ -52,7 +52,10 @@ class GuiShapeNameHud : public GuiControl { ColorF mTextColor; ColorF mLabelFillColor; ColorF mLabelFrameColor; - + // ZOD: Team coloring + ColorF mEnemyTextColor; + ColorF mNeutralTextColor; + //> ZOD: End addition F32 mVerticalOffset; F32 mDistanceFade; bool mShowFrame; @@ -63,7 +66,10 @@ class GuiShapeNameHud : public GuiControl { Point2I mLabelPadding; 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: GuiShapeNameHud(); @@ -120,6 +126,10 @@ GuiShapeNameHud::GuiShapeNameHud() mLabelFillColor.set( 0.25f, 0.25f, 0.25f, 0.25f ); mLabelFrameColor.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; mShowLabelFrame = mShowLabelFill = false; mVerticalOffset = 0.5f; @@ -135,6 +145,10 @@ void GuiShapeNameHud::initPersistFields() 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( "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"); addGroup("Misc"); @@ -174,7 +188,10 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) // Must have a connection and control object GameConnection* conn = GameConnection::getConnectionToServer(); if (!conn) return; - GameBase * control = dynamic_cast(conn->getControlObject()); +//> ZOD: Team coloring + //GameBase * control = dynamic_cast(conn->getControlObject()); + ShapeBase * control = dynamic_cast(conn->getControlObject()); +//< ZOD: End edit if (!control) return; // Get control camera info @@ -199,6 +216,12 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) static U32 losMask = TerrainObjectType | ShapeBaseObjectType | StaticObjectType; 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, // so we can find all the shape base objects by iterating through // our current connection. @@ -207,6 +230,9 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) if ( shape ) { 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 // 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: 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 - 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 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 if (mShowFrame) GFX->getDrawUtil()->drawRect(updateRect, mFrameColor); @@ -291,7 +380,7 @@ void GuiShapeNameHud::onRender( Point2I, const RectI &updateRect) /// specified y position.) /// @param name String name to display. /// @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 height = mProfile->mFont->getHeight() + mLabelPadding.y * 2; diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index 55b258a72..0f45cd876 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -907,6 +907,7 @@ ShapeBase::ShapeBase() damageDir( 0.0f, 0.0f, 1.0f ), mCloaked( false ), mCloakLevel( 0.0f ), + mTeamId( 0 ), //> ZOD: Add team Id mFadeOut( true ), mFading( false ), mFadeVal( 1.0f ), @@ -2969,6 +2970,12 @@ U32 ShapeBase::packUpdate(NetConnection *con, U32 mask, BitStream *stream) ThreadMask | ImageMask | CloakMask | SkinMask))) return retMask; +//> ZOD: Add team Id + if(stream->writeFlag(mask & TeamMask)) { + stream->write(mTeamId); + } +//< ZOD: End addition + if (stream->writeFlag(mask & DamageMask)) { stream->writeFloat(mClampF(mDamage / mDataBlock->maxDamage, 0.f, 1.f), DamageLevelBits); stream->writeInt(mDamageState,NumDamageStateBits); @@ -3076,6 +3083,12 @@ void ShapeBase::unpackUpdate(NetConnection *con, BitStream *stream) if(!stream->readFlag()) return; +//> ZOD: Add team Id + if(stream->readFlag()) { + stream->read(&mTeamId); + } +//< ZOD: End addition + if (stream->readFlag()) { mDamage = mClampF(stream->readFloat(DamageLevelBits) * mDataBlock->maxDamage, 0.f, mDataBlock->maxDamage); 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 ),, "@brief Add or remove this object from the scene.\n\n" diff --git a/Engine/source/T3D/shapeBase.h b/Engine/source/T3D/shapeBase.h index fcada642b..c1a4d9b0d 100644 --- a/Engine/source/T3D/shapeBase.h +++ b/Engine/source/T3D/shapeBase.h @@ -876,7 +876,7 @@ protected: F32 mEnergy; ///< Current enery level. F32 mRechargeRate; ///< Energy recharge rate (in units/tick). - + S32 mTeamId; ///< ZOD: Team identification for shape name F32 mMass; ///< Mass. F32 mOneOverMass; ///< Inverse of mass. /// @note This is used to optimize certain physics calculations. @@ -1139,8 +1139,11 @@ public: DamageMask = Parent::NextFreeMask << 1, NoWarpMask = Parent::NextFreeMask << 2, CloakMask = Parent::NextFreeMask << 3, - SkinMask = Parent::NextFreeMask << 4, - MeshHiddenMask = Parent::NextFreeMask << 5, + //SkinMask = Parent::NextFreeMask << 4, + 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 ThreadMaskN = SoundMaskN << MaxSoundThreads, ///< Extends + MaxScriptThreads bits ImageMaskN = ThreadMaskN << MaxScriptThreads, ///< Extends + MaxMountedImage bits @@ -1170,7 +1173,10 @@ public: void onSceneRemove(); static void consoleInit(); 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 diff --git a/Engine/source/T3D/turret/aiTurretShape.cpp b/Engine/source/T3D/turret/aiTurretShape.cpp index 5d895c8ab..688cf8fb6 100644 --- a/Engine/source/T3D/turret/aiTurretShape.cpp +++ b/Engine/source/T3D/turret/aiTurretShape.cpp @@ -380,6 +380,12 @@ static void _scanCallback( SceneObject* object, void* data ) ShapeBase* shape = dynamic_cast(object); 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(); // Put target position into the scan node's space @@ -1352,3 +1358,13 @@ DefineEngineMethod( AITurretShape, recenterTurret, void, ( ),, { 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