NS/main/source/mod/AvHAIHelper.cpp

643 lines
20 KiB
C++
Raw Normal View History

Bot integration for v3.3b8 (#156) * Initial bot commit * Added server commands and cvars for adding AI players to the game. * Added auto modes for automating the adding and removal of bots * Bots connect to the server and join teams correctly * Added round restart and new map detection for AI system Push before new project added for detour * Initial bot integration * Integrated all basic bot code for navigation and task performing * Added support for multi_managers to better understand how buttons and triggers affect doors * Improved bot understanding of door triggers and weldables * Reworked nav profiles Nav profiles for bots are now dynamically updated to take into account changing capabilities, such as picking up a welder * Improved bot door usage * Added weldable obstacles back into navigation Bots now understand how to get around weldable barriers * Replaced fixed arrays with vectors * Resource node and hive lists are now vectors. * Further improved bot weld behaviour * Added dynamic reachability calculations When barriers and doors are open/closed, new reachability calculations are done for structures and items so bots understand when items/structures become reachable or unreachable as the match progresses. * Added team-based reachability calculations Reachabilities for structures and items are now based on the team, so bots understand when they can't reach a structure from their spawn point. * Implemented long-range off-mesh connections and dynamic off-mesh connections * Implemented fully dynamic off-mesh connections Phase gates now use connections rather than custom path finding. Much more performant. * Replaced arrays with vectors for simpler code * Started Bot Swimming * Bots understand trigger_changetarget Bots can now navigate doors operated with a trigger_changetarget so they understand the sequence in which triggers must be activated to make it work * Push before trying to fix long-range connections * Implement new off-mesh connection system * Redid population of door triggers * Fixed trigger types and links to doors * Added lift and moving platform support * Lift improvements * Bots avoid getting crushed under a lift when summoning it * Bots are better at judging which stop a platform needs to be at * Tweak lift and welder usage * Fixed bug with multiple off-mesh connections close together * Finish lift movement * Fixed dodgy path finding * Improved skulk ladder usage and lerk lift usage * Fix crash with path finding * Re-implement commander AI * Commander improvements * Improve commander sieging * Commander scanning tweak * Reimplemented regular marine AI * Start reimplementing alien AI * Implement gorge building behaviours * Start alien tactical decisioning * Continuing alien building and other non-combat logic * More alien role work * Adjusted base node definitions * Iterate Capper Logic * Alien assault AI * Alien Combat * Fix grenade throwing, better combat * Marine combat AI improvements * Commander improvements * Commander + nav improvements * Drop mines * Improved bot stuck detection * Commander supply improvements * Bot fill timing config * Added nsbots.cfg to configure internal bots * Changed bot config file to "nsbots.cfg" * Bug fixing with navigation * Fix skulk movement on ladders * Improved commander placement and tactical refresh * Fixed bug with ladder climbing * Doors block off-mesh connections * Finished doors blocking connections * Marine and alien tactical bug fixes * Add commander beacon back in * Start combat mode stuff * First pass at combat mode * Bots attack turrets * Fix ladder and wall climbing * Commander chat request * Improved skulk ladders * Added nav meshes for new bot code * Added bot configuration to listen server menu * Added bot config file * Added default bot config to listenserver.cfg * Added default bot settings to server.cfg * Include VS filter for bot files * Crash fixes * Bot improvements * Bot stability and mine placement improvements * Fixed crash on new map start with bots * Reverted Svencoop fix * Fixed crash, added more cvars * Performance improvement * Commander building improvements * Stop bot spasming when waiting to take command * Fixed doors not blocking connections * Added bot disabled guard to round start * Commander improvements, movement improvements * Tweaked level load sequence * Performance improvements * Bot load spread * Fixed commander update * Refactor bot frame handling * Bug fixes + Pierow's dynamic load spread * Minor bug fixes * Fix door detection, prep for test * Fixed commander siege spam * linux compile test * fix hardcoded inlcudes * O1 compile flag for detour - fix linux server crash * Revert detour compile flags to original for windows * linux build update * remove x64 build configs * update bot nav meshes and configs * fix bot physics at high server fps, update navmeshes. from @RGreenlees --------- Co-authored-by: RGreenlees <RGreenlees@users.noreply.github.com> Co-authored-by: RichardGreenlees <richard.greenlees@forecast.global>
2024-03-21 18:17:18 +00:00
#include "AvHAIHelper.h"
#include "AvHAIMath.h"
#include "AvHAIPlayerUtil.h"
#include "AvHAITactical.h"
#include "AvHAINavigation.h"
#include "AvHGamerules.h"
#include <unordered_map>
int m_spriteTexture;
std::unordered_map<const char*, std::string> LocalizedLocationsMap;
bool UTIL_CommanderTrace(const edict_t* pEdict, const Vector& start, const Vector& end)
{
TraceResult hit;
edict_t* IgnoreEdict = (!FNullEnt(pEdict)) ? pEdict->v.pContainingEntity : NULL;
UTIL_TraceLine(start, end, ignore_monsters, ignore_glass, IgnoreEdict, &hit);
return (hit.flFraction >= 1.0f);
}
bool UTIL_QuickTrace(const edict_t* pEdict, const Vector& start, const Vector& end, bool bAllowStartSolid)
{
TraceResult hit;
edict_t* IgnoreEdict = (!FNullEnt(pEdict)) ? pEdict->v.pContainingEntity : NULL;
UTIL_TraceLine(start, end, ignore_monsters, ignore_glass, IgnoreEdict, &hit);
return (hit.flFraction >= 1.0f && !hit.fAllSolid && (bAllowStartSolid || !hit.fStartSolid));
}
bool UTIL_QuickHullTrace(const edict_t* pEdict, const Vector& start, const Vector& end, bool bAllowStartSolid)
{
int hullNum = (!FNullEnt(pEdict)) ? GetPlayerHullIndex(pEdict) : point_hull;
edict_t* IgnoreEdict = (!FNullEnt(pEdict)) ? pEdict->v.pContainingEntity : NULL;
TraceResult hit;
UTIL_TraceHull(start, end, ignore_monsters, hullNum, IgnoreEdict, &hit);
return (hit.flFraction >= 1.0f && !hit.fAllSolid && (bAllowStartSolid || !hit.fStartSolid));
}
bool UTIL_QuickHullTrace(const edict_t* pEdict, const Vector& start, const Vector& end, int hullNum, bool bAllowStartSolid)
{
TraceResult hit;
edict_t* IgnoreEdict = (!FNullEnt(pEdict)) ? pEdict->v.pContainingEntity : NULL;
UTIL_TraceHull(start, end, ignore_monsters, hullNum, IgnoreEdict, &hit);
return (hit.flFraction >= 1.0f && !hit.fAllSolid && (bAllowStartSolid || !hit.fStartSolid));
}
edict_t* UTIL_TraceEntity(const edict_t* pEdict, const Vector& start, const Vector& end)
{
TraceResult hit;
edict_t* IgnoreEdict = (!FNullEnt(pEdict)) ? pEdict->v.pContainingEntity : NULL;
UTIL_TraceLine(start, end, dont_ignore_monsters, dont_ignore_glass, IgnoreEdict, &hit);
return hit.pHit;
}
Vector UTIL_GetTraceHitLocation(const Vector Start, const Vector End)
{
TraceResult hit;
UTIL_TraceHull(Start, End, ignore_monsters, point_hull, NULL, &hit);
if (hit.flFraction < 1.0f && !hit.fAllSolid)
{
return hit.vecEndPos;
}
return Start;
}
Vector UTIL_GetHullTraceHitLocation(const Vector Start, const Vector End, int HullNum)
{
TraceResult hit;
UTIL_TraceHull(Start, End, ignore_monsters, HullNum, NULL, &hit);
if (hit.flFraction < 1.0f && !hit.fAllSolid)
{
return hit.vecEndPos;
}
return Start;
}
Vector UTIL_GetGroundLocation(const Vector CheckLocation)
{
if (vIsZero(CheckLocation)) { return g_vecZero; }
TraceResult hit;
UTIL_TraceHull(CheckLocation, (CheckLocation - Vector(0.0f, 0.0f, 1000.0f)), ignore_monsters, head_hull, nullptr, &hit);
if (hit.flFraction < 1.0f)
{
return hit.vecEndPos;
}
return CheckLocation;
}
Vector UTIL_GetEntityGroundLocation(const edict_t* pEntity)
{
if (FNullEnt(pEntity)) { return g_vecZero; }
bool bIsPlayer = IsEdictPlayer(pEntity);
if (bIsPlayer)
{
if (IsPlayerOnLadder(pEntity))
{
return UTIL_GetFloorUnderEntity(pEntity);
}
if (pEntity->v.flags & FL_ONGROUND)
{
if (FNullEnt(pEntity->v.groundentity))
{
return GetPlayerBottomOfCollisionHull(pEntity);
}
if (!IsEdictPlayer(pEntity->v.groundentity) && GetDeployableObjectTypeFromEdict(pEntity->v.groundentity) == STRUCTURE_NONE)
{
return GetPlayerBottomOfCollisionHull(pEntity);
}
}
return UTIL_GetFloorUnderEntity(pEntity);
}
if (GetDeployableObjectTypeFromEdict(pEntity) == STRUCTURE_ALIEN_HIVE)
{
return UTIL_GetFloorUnderEntity(pEntity);
const AvHAIHiveDefinition* Hive = AITAC_GetHiveFromEdict(pEntity);
if (Hive)
{
return Hive->FloorLocation;
}
else
{
return UTIL_GetFloorUnderEntity(pEntity);
}
}
Vector Centre = UTIL_GetCentreOfEntity(pEntity);
Centre.z = pEntity->v.absmin.z + 1.0f;
return Centre;
}
Vector UTIL_GetCentreOfEntity(const edict_t* Entity)
{
if (!Entity) { return g_vecZero; }
return (Entity->v.absmin + (Entity->v.size * 0.5f));
}
Vector UTIL_GetFloorUnderEntity(const edict_t* Edict)
{
if (FNullEnt(Edict)) { return g_vecZero; }
TraceResult hit;
Vector EntityCentre = UTIL_GetCentreOfEntity(Edict) + Vector(0.0f, 0.0f, 1.0f);
Vector TraceEnd = (EntityCentre - Vector(0.0f, 0.0f, 1000.0f));
UTIL_TraceHull(EntityCentre, TraceEnd, ignore_monsters, head_hull, Edict->v.pContainingEntity, &hit);
if (hit.flFraction < 1.0f)
{
return (hit.vecEndPos + Vector(0.0f, 0.0f, 1.0f));
}
return Edict->v.origin;
}
Vector UTIL_GetClosestPointOnEntityToLocation(const Vector Location, const edict_t* Entity)
{
return Vector(clampf(Location.x, Entity->v.absmin.x, Entity->v.absmax.x), clampf(Location.y, Entity->v.absmin.y, Entity->v.absmax.y), clampf(Location.z, Entity->v.absmin.z, Entity->v.absmax.z));
}
Vector UTIL_GetClosestPointOnEntityToLocation(const Vector Location, const edict_t* Entity, const Vector EntityLocation)
{
Vector MinVec = EntityLocation - (Entity->v.size * 0.5f);
Vector MaxVec = EntityLocation + (Entity->v.size * 0.5f);
return Vector(clampf(Location.x, MinVec.x, MaxVec.x), clampf(Location.y, MinVec.y, MaxVec.y), clampf(Location.z, MinVec.z, MaxVec.z));
}
AvHAIDeployableStructureType IUSER3ToStructureType(const int inIUSER3)
{
if (inIUSER3 == AVH_USER3_COMMANDER_STATION) { return STRUCTURE_MARINE_COMMCHAIR; }
if (inIUSER3 == AVH_USER3_RESTOWER) { return STRUCTURE_MARINE_RESTOWER; }
if (inIUSER3 == AVH_USER3_INFANTRYPORTAL) { return STRUCTURE_MARINE_INFANTRYPORTAL; }
if (inIUSER3 == AVH_USER3_ARMORY) { return STRUCTURE_MARINE_ARMOURY; }
if (inIUSER3 == AVH_USER3_ADVANCED_ARMORY) { return STRUCTURE_MARINE_ADVARMOURY; }
if (inIUSER3 == AVH_USER3_TURRET_FACTORY) { return STRUCTURE_MARINE_TURRETFACTORY; }
if (inIUSER3 == AVH_USER3_ADVANCED_TURRET_FACTORY) { return STRUCTURE_MARINE_ADVTURRETFACTORY; }
if (inIUSER3 == AVH_USER3_TURRET) { return STRUCTURE_MARINE_TURRET; }
if (inIUSER3 == AVH_USER3_SIEGETURRET) { return STRUCTURE_MARINE_SIEGETURRET; }
if (inIUSER3 == AVH_USER3_ARMSLAB) { return STRUCTURE_MARINE_ARMSLAB; }
if (inIUSER3 == AVH_USER3_PROTOTYPE_LAB) { return STRUCTURE_MARINE_PROTOTYPELAB; }
if (inIUSER3 == AVH_USER3_OBSERVATORY) { return STRUCTURE_MARINE_OBSERVATORY; }
if (inIUSER3 == AVH_USER3_PHASEGATE) { return STRUCTURE_MARINE_PHASEGATE; }
if (inIUSER3 == AVH_USER3_MINE) { return STRUCTURE_MARINE_DEPLOYEDMINE; }
if (inIUSER3 == AVH_USER3_HIVE) { return STRUCTURE_ALIEN_HIVE; }
if (inIUSER3 == AVH_USER3_ALIENRESTOWER) { return STRUCTURE_ALIEN_RESTOWER; }
if (inIUSER3 == AVH_USER3_DEFENSE_CHAMBER) { return STRUCTURE_ALIEN_DEFENCECHAMBER; }
if (inIUSER3 == AVH_USER3_SENSORY_CHAMBER) { return STRUCTURE_ALIEN_SENSORYCHAMBER; }
if (inIUSER3 == AVH_USER3_MOVEMENT_CHAMBER) { return STRUCTURE_ALIEN_MOVEMENTCHAMBER; }
if (inIUSER3 == AVH_USER3_OFFENSE_CHAMBER) { return STRUCTURE_ALIEN_OFFENCECHAMBER; }
return STRUCTURE_NONE;
}
AvHAIDeployableStructureType GetDeployableObjectTypeFromEdict(const edict_t* StructureEdict)
{
if (FNullEnt(StructureEdict)) { return STRUCTURE_NONE; }
return IUSER3ToStructureType(StructureEdict->v.iuser3);
}
bool IsEdictStructure(const edict_t* edict)
{
return (GetDeployableObjectTypeFromEdict(edict) != STRUCTURE_NONE);
}
bool IsEdictHive(const edict_t* edict)
{
if (FNullEnt(edict)) { return false; }
return (edict->v.iuser3 == AVH_USER3_HIVE);
}
bool IsDamagingStructure(const edict_t* StructureEdict)
{
return IsDamagingStructure(GetStructureTypeFromEdict(StructureEdict));
}
bool IsDamagingStructure(AvHAIDeployableStructureType StructureType)
{
switch (StructureType)
{
case STRUCTURE_ALIEN_OFFENCECHAMBER:
case STRUCTURE_MARINE_TURRET:
return true;
default:
return false;
}
return false;
}
AvHAIDeployableStructureType GetStructureTypeFromEdict(const edict_t* StructureEdict)
{
if (FNullEnt(StructureEdict)) { return STRUCTURE_NONE; }
return IUSER3ToStructureType(StructureEdict->v.iuser3);
}
bool GetNearestMapLocationAtPoint(vec3_t SearchLocation, string& outLocation)
{
bool theSuccess = false;
const AvHBaseInfoLocationListType& inLocations = GetGameRules()->GetInfoLocations();
bool bFoundNearest = false;
float MinDist = 0.0f;
// Look at our current position, and see if we lie within of the map locations
for (AvHBaseInfoLocationListType::const_iterator theIter = inLocations.begin(); theIter != inLocations.end(); theIter++)
{
if (theIter->GetIsPointInRegion(SearchLocation))
{
outLocation = theIter->GetLocationName();
return true;
}
float NearestX = clampf(SearchLocation.x, theIter->GetMinExtent().x, theIter->GetMaxExtent().x);
float NearestY = clampf(SearchLocation.y, theIter->GetMinExtent().y, theIter->GetMaxExtent().y);
float ThisDist = vDist2DSq(SearchLocation, Vector(NearestX, NearestY, 0.0f));
if (!bFoundNearest || ThisDist < MinDist)
{
outLocation = theIter->GetLocationName();
bFoundNearest = true;
theSuccess = true;
MinDist = ThisDist;
}
}
return theSuccess;
}
void AIDEBUG_DrawBotPath(AvHAIPlayer* pBot, float DrawTime)
{
AIDEBUG_DrawPath(pBot->BotNavInfo.CurrentPath, DrawTime);
}
void AIDEBUG_DrawPath(vector<bot_path_node>& path, float DrawTime)
{
if (path.size() == 0) { return; }
for (auto it = path.begin(); it != path.end(); it++)
{
Vector FromLoc = it->FromLocation;
Vector ToLoc = it->Location;
switch (it->flag)
{
case SAMPLE_POLYFLAGS_WELD:
case SAMPLE_POLYFLAGS_DOOR:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 255, 0, 0);
break;
case SAMPLE_POLYFLAGS_JUMP:
case SAMPLE_POLYFLAGS_DUCKJUMP:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 255, 255, 0);
break;
case SAMPLE_POLYFLAGS_LADDER:
case SAMPLE_POLYFLAGS_LIFT:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 0, 0, 255);
break;
case SAMPLE_POLYFLAGS_WALLCLIMB:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 0, 128, 0);
break;
case SAMPLE_POLYFLAGS_BLOCKED:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 128, 128, 128);
break;
case SAMPLE_POLYFLAGS_TEAM1PHASEGATE:
case SAMPLE_POLYFLAGS_TEAM2PHASEGATE:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime, 255, 128, 128);
break;
default:
UTIL_DrawLine(INDEXENT(1), FromLoc, ToLoc, DrawTime);
break;
}
}
}
void UTIL_DrawLine(edict_t* pEntity, Vector start, Vector end)
{
if (FNullEnt(pEntity) || pEntity->free) { return; }
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_BEAMPOINTS);
WRITE_COORD(start.x);
WRITE_COORD(start.y);
WRITE_COORD(start.z);
WRITE_COORD(end.x);
WRITE_COORD(end.y);
WRITE_COORD(end.z);
WRITE_SHORT(m_spriteTexture);
WRITE_BYTE(1); // framestart
WRITE_BYTE(10); // framerate
WRITE_BYTE(1); // life in 0.1's
WRITE_BYTE(5); // width
WRITE_BYTE(0); // noise
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(250); // brightness
WRITE_BYTE(5); // speed
MESSAGE_END();
}
void UTIL_DrawLine(edict_t* pEntity, Vector start, Vector end, float drawTimeSeconds)
{
if (FNullEnt(pEntity) || pEntity->free) { return; }
int timeTenthSeconds = (int)floorf(drawTimeSeconds * 10.0f);
timeTenthSeconds = fmaxf(timeTenthSeconds, 1);
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_BEAMPOINTS);
WRITE_COORD(start.x);
WRITE_COORD(start.y);
WRITE_COORD(start.z);
WRITE_COORD(end.x);
WRITE_COORD(end.y);
WRITE_COORD(end.z);
WRITE_SHORT(m_spriteTexture);
WRITE_BYTE(1); // framestart
WRITE_BYTE(10); // framerate
WRITE_BYTE(timeTenthSeconds); // life in 0.1's
WRITE_BYTE(5); // width
WRITE_BYTE(0); // noise
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(255); // r, g, b
WRITE_BYTE(250); // brightness
WRITE_BYTE(5); // speed
MESSAGE_END();
}
void UTIL_DrawLine(edict_t* pEntity, Vector start, Vector end, float drawTimeSeconds, int r, int g, int b)
{
if (FNullEnt(pEntity) || pEntity->free) { return; }
int timeTenthSeconds = (int)floorf(drawTimeSeconds * 10.0f);
timeTenthSeconds = fmaxf(timeTenthSeconds, 1);
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_BEAMPOINTS);
WRITE_COORD(start.x);
WRITE_COORD(start.y);
WRITE_COORD(start.z);
WRITE_COORD(end.x);
WRITE_COORD(end.y);
WRITE_COORD(end.z);
WRITE_SHORT(m_spriteTexture);
WRITE_BYTE(1); // framestart
WRITE_BYTE(10); // framerate
WRITE_BYTE(timeTenthSeconds); // life in 0.1's
WRITE_BYTE(5); // width
WRITE_BYTE(0); // noise
WRITE_BYTE(r); // r, g, b
WRITE_BYTE(g); // r, g, b
WRITE_BYTE(b); // r, g, b
WRITE_BYTE(250); // brightness
WRITE_BYTE(5); // speed
MESSAGE_END();
}
void UTIL_DrawLine(edict_t* pEntity, Vector start, Vector end, int r, int g, int b)
{
if (FNullEnt(pEntity) || pEntity->free) { return; }
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_BEAMPOINTS);
WRITE_COORD(start.x);
WRITE_COORD(start.y);
WRITE_COORD(start.z);
WRITE_COORD(end.x);
WRITE_COORD(end.y);
WRITE_COORD(end.z);
WRITE_SHORT(m_spriteTexture);
WRITE_BYTE(1); // framestart
WRITE_BYTE(10); // framerate
WRITE_BYTE(1); // life in 0.1's
WRITE_BYTE(5); // width
WRITE_BYTE(0); // noise
WRITE_BYTE(r); // r, g, b
WRITE_BYTE(g); // r, g, b
WRITE_BYTE(b); // r, g, b
WRITE_BYTE(250); // brightness
WRITE_BYTE(5); // speed
MESSAGE_END();
}
void UTIL_DrawBox(edict_t* pEntity, Vector bMin, Vector bMax, float drawTimeSeconds)
{
Vector LowerBottomLeftCorner = bMin;
Vector LowerTopLeftCorner = Vector(bMin.x, bMax.y, bMin.z);
Vector LowerTopRightCorner = Vector(bMax.x, bMax.y, bMin.z);
Vector LowerBottomRightCorner = Vector(bMax.x, bMin.y, bMin.z);
Vector UpperBottomLeftCorner = Vector(bMin.x, bMin.y, bMax.z);
Vector UpperTopLeftCorner = Vector(bMin.x, bMax.y, bMax.z);
Vector UpperTopRightCorner = Vector(bMax.x, bMax.y, bMax.z);
Vector UpperBottomRightCorner = Vector(bMax.x, bMin.y, bMax.z);
UTIL_DrawLine(pEntity, LowerTopLeftCorner, LowerTopRightCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerTopRightCorner, LowerBottomRightCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerBottomRightCorner, LowerBottomLeftCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, UpperBottomLeftCorner, UpperTopLeftCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, UpperTopLeftCorner, UpperTopRightCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, UpperTopRightCorner, UpperBottomRightCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, UpperBottomRightCorner, UpperBottomLeftCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerBottomLeftCorner, UpperBottomLeftCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerTopLeftCorner, UpperTopLeftCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerTopRightCorner, UpperTopRightCorner, drawTimeSeconds, 255, 255, 255);
UTIL_DrawLine(pEntity, LowerBottomRightCorner, UpperBottomRightCorner, drawTimeSeconds, 255, 255, 255);
}
void UTIL_DrawBox(edict_t* pEntity, Vector bMin, Vector bMax, float drawTimeSeconds, int r, int g, int b)
{
Vector LowerBottomLeftCorner = bMin;
Vector LowerTopLeftCorner = Vector(bMin.x, bMax.y, bMin.z);
Vector LowerTopRightCorner = Vector(bMax.x, bMax.y, bMin.z);
Vector LowerBottomRightCorner = Vector(bMax.x, bMin.y, bMin.z);
Vector UpperBottomLeftCorner = Vector(bMin.x, bMin.y, bMax.z);
Vector UpperTopLeftCorner = Vector(bMin.x, bMax.y, bMax.z);
Vector UpperTopRightCorner = Vector(bMax.x, bMax.y, bMax.z);
Vector UpperBottomRightCorner = Vector(bMax.x, bMin.y, bMax.z);
UTIL_DrawLine(pEntity, LowerTopLeftCorner, LowerTopRightCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerTopRightCorner, LowerBottomRightCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerBottomRightCorner, LowerBottomLeftCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, UpperBottomLeftCorner, UpperTopLeftCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, UpperTopLeftCorner, UpperTopRightCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, UpperTopRightCorner, UpperBottomRightCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, UpperBottomRightCorner, UpperBottomLeftCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerBottomLeftCorner, UpperBottomLeftCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerTopLeftCorner, UpperTopLeftCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerTopRightCorner, UpperTopRightCorner, drawTimeSeconds, r, g, b);
UTIL_DrawLine(pEntity, LowerBottomRightCorner, UpperBottomRightCorner, drawTimeSeconds, r, g, b);
}
void UTIL_DrawHUDText(edict_t* pEntity, char channel, float x, float y, unsigned char r, unsigned char g, unsigned char b, const char* string)
{
// higher level wrapper for hudtextparms TE_TEXTMESSAGEs. This function is meant to be called
// every frame, since the duration of the display is roughly worth the duration of a video
// frame. The X and Y coordinates are unary fractions which are bound to this rule:
// 0: top of the screen (Y) or left of the screen (X), left aligned text
// 1: bottom of the screen (Y) or right of the screen (X), right aligned text
// -1(only one negative value possible): center of the screen (X and Y), centered text
// Any value ranging from 0 to 1 will represent a valid position on the screen.
//static short duration;
if (FNullEnt(pEntity)) { return; }
//duration = (int)GAME_GetServerMSecVal() * 256 / 750; // compute text message duration
//if (duration < 5)
// duration = 5;
MESSAGE_BEGIN(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, pEntity);
WRITE_BYTE(TE_TEXTMESSAGE);
WRITE_BYTE(channel); // channel
WRITE_SHORT((int)(x * 8192.0f)); // x coordinates * 8192
WRITE_SHORT((int)(y * 8192.0f)); // y coordinates * 8192
WRITE_BYTE(0); // effect (fade in/out)
WRITE_BYTE(r); // initial RED
WRITE_BYTE(g); // initial GREEN
WRITE_BYTE(b); // initial BLUE
WRITE_BYTE(1); // initial ALPHA
WRITE_BYTE(r); // effect RED
WRITE_BYTE(g); // effect GREEN
WRITE_BYTE(b); // effect BLUE
WRITE_BYTE(1); // effect ALPHA
WRITE_SHORT(0); // fade-in time in seconds * 256
WRITE_SHORT(0); // fade-out time in seconds * 256
WRITE_SHORT(5); // hold time in seconds * 256
WRITE_STRING(string);//string); // send the string
MESSAGE_END(); // end
return;
}
void UTIL_ClearLocalizations()
{
LocalizedLocationsMap.clear();
}
void UTIL_LocalizeText(const char* InputText, string& OutputText)
{
// Don't localize empty strings
if (!strcmp(InputText, ""))
{
OutputText = "";
}
char theInputString[1024];
sprintf(theInputString, "%s", InputText);
std::unordered_map<const char*, std::string>::const_iterator FoundLocalization = LocalizedLocationsMap.find(theInputString);
if (FoundLocalization != LocalizedLocationsMap.end())
{
OutputText = FoundLocalization->second;
return;
}
char filename[256];
std::string localizedString(theInputString);
string titlesPath = string(getModDirectory()) + "/titles.txt";
strcpy(filename, titlesPath.c_str());
std::ifstream cFile(filename);
if (cFile.is_open())
{
std::string line;
while (getline(cFile, line))
{
line.erase(std::remove_if(line.begin(), line.end(), ::isspace),
line.end());
if (line[0] == '/' || line.empty())
continue;
if (line.compare(theInputString) == 0)
{
getline(cFile, line);
getline(cFile, localizedString);
break;
}
}
}
char theOutputString[1024];
sprintf(theOutputString, "%s", localizedString.c_str());
string Delimiter = "Hive -";
auto delimiterPos = localizedString.find(Delimiter);
if (delimiterPos == std::string::npos)
{
Delimiter = "Hive Location -";
delimiterPos = localizedString.find(Delimiter);
}
if (delimiterPos == std::string::npos)
{
Delimiter = "Hive Location -";
delimiterPos = localizedString.find("Hive Location -");
}
if (delimiterPos != std::string::npos)
{
auto AreaName = localizedString.substr(delimiterPos + Delimiter.length());
AreaName.erase(0, AreaName.find_first_not_of(" \r\n\t\v\f"));
sprintf(theOutputString, "%s", AreaName.c_str());
}
OutputText = theOutputString;
LocalizedLocationsMap[InputText] = OutputText;
}