Skip to content

Commit

Permalink
research tracker update
Browse files Browse the repository at this point in the history
  • Loading branch information
pierow committed Nov 12, 2021
1 parent ea279fb commit 5202080
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 149 deletions.
20 changes: 0 additions & 20 deletions main/source/mod/AvHBaseBuildable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
#include "AvHPlayerUpgrade.h"
#include "../dlls/animation.h"
#include "AvHMovementUtil.h"
#include "AvHNetworkMessages.h"

const int kBaseBuildableSpawnAnimation = 0;
const int kBaseBuildableDeployAnimation = 1;
Expand Down Expand Up @@ -703,25 +702,6 @@ AvHTeamNumber AvHBaseBuildable::GetTeamNumber() const
void AvHBaseBuildable::Killed(entvars_t* pevAttacker, int iGib)
{
bool theInReset = GetGameRules()->GetIsGameInReset();

// Send a Cancel notification so any research can be removed from the research tracker.
if (GetGameRules()->GetGameStarted())
{
FOR_ALL_ENTITIES(kAvHPlayerClassName, AvHPlayer*)
bool theShowNotification = false;

// Show to friendlies...
if (theEntity->pev->team == this->pev->team)
{
theShowNotification = true;
}

if (theShowNotification)
{
NetMsg_PlayHUDNotification(theEntity->pev, 1, MESSAGE_CANCEL, this->pev->origin.x, this->pev->origin.y);
}
END_FOR_ALL_ENTITIES(kAvHPlayerClassName);
}

AvHBaseBuildable::SetHasBeenKilled();
GetGameRules()->RemoveEntityUnderAttack( this->entindex() );
Expand Down
53 changes: 17 additions & 36 deletions main/source/mod/AvHHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,7 @@ void AvHHud::ResetGame(bool inMapChanged)
this->mLastTeamSpectated = TEAM_IND;

this->mStructureNotificationList.clear();
this->mResearchInfoList.clear();

this->mGameTime = -1;
this->mTimeLimit = -1;
Expand Down Expand Up @@ -2961,11 +2962,12 @@ int AvHHud::MsgFunc_ListPS(const char* pszName, int iSize, void* pbuf)
BIND_MESSAGE(PlayHUDNot);
int AvHHud::MsgFunc_PlayHUDNot(const char* pszName, int iSize, void* pbuf)
{
int message_id, sound;
int flags, sound;
float location_x, location_y;
NetMsg_PlayHUDNotification( pbuf, iSize, message_id, sound, location_x, location_y );

if(message_id == 0)
ResearchInfoListType researchInfoBuf;
NetMsg_PlayHUDNotification( pbuf, iSize, flags, sound, location_x, location_y , researchInfoBuf);
// Sound
if(flags == 0)
{
// Hack to avoid adding another network message (at max)
if(!this->GetInTopDownMode())
Expand Down Expand Up @@ -3014,7 +3016,8 @@ int AvHHud::MsgFunc_PlayHUDNot(const char* pszName, int iSize, void* pbuf)

this->PlayHUDSound((AvHHUDSound)sound);
}
else
// Single HUD notification
else if (flags == 1)
{
// Push back icon
HUDNotificationType theNotification;
Expand All @@ -3027,6 +3030,12 @@ int AvHHud::MsgFunc_PlayHUDNot(const char* pszName, int iSize, void* pbuf)
this->mStructureNotificationList.push_back(theNotification);
}
}
// Research info list
else
{
this->mResearchInfoList.clear();
this->mResearchInfoList = researchInfoBuf;
}

return 1;
}
Expand Down Expand Up @@ -5849,41 +5858,13 @@ void AvHHud::UpdateTooltips(float inCurrentTime)

void AvHHud::UpdateStructureNotification(float inCurrentTime)
{
const int kMaxIcons = 5;
Vector cancelLocation;
const int kMaxIcons = 4;
const float kTimeToDisplayIcon = 6.0f;
AvHTeamNumber theCurrentTeam = this->GetHUDTeam();

// Reset on a team change
if (this->mLastTeamNumber != theCurrentTeam)
this->mStructureNotificationList.clear();

for(StructureHUDNotificationListType::iterator theIter = this->mStructureNotificationList.begin(); theIter != this->mStructureNotificationList.end(); /* no inc */)
{
int theCost;
bool theResearchable;
float theBuildOrResearchTime;
AvHMessageID theTech = theIter->mStructureID;
this->mTechNodes.GetResearchInfo(theTech, theResearchable, theCost, theBuildOrResearchTime);
bool isResearch = AvHSHUGetIsResearchTech(theTech);
float timeToDisplayIcon = 6.0f;

if (isResearch)
{
theIter->mResearchTimer = max(0, theBuildOrResearchTime - (inCurrentTime - theIter->mTime));
timeToDisplayIcon = theBuildOrResearchTime;
}
else
{
theIter->mResearchTimer = 0;
}

if (theTech == MESSAGE_CANCEL)
{
cancelLocation = theIter->mLocation;
this->mStructureNotificationList.erase(theIter);
theIter = this->mStructureNotificationList.begin();
}
else if ((inCurrentTime > (theIter->mTime + timeToDisplayIcon)) || (!(theIter->mResearchTimer > 0) && this->mStructureNotificationList.size() > kMaxIcons ) || (theIter->mLocation == cancelLocation))
if ((inCurrentTime > (theIter->mTime + kTimeToDisplayIcon)) || (this->mStructureNotificationList.size() > kMaxIcons))
{
theIter = this->mStructureNotificationList.erase(theIter);
}
Expand Down
3 changes: 2 additions & 1 deletion main/source/mod/AvHHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,14 +844,15 @@ class AvHHud : public UIHud
{
AvHMessageID mStructureID;
float mTime;
float mResearchTimer;
int mPlayerIndex;
Vector mLocation;
} HUDNotificationType;

typedef vector< HUDNotificationType > StructureHUDNotificationListType;
StructureHUDNotificationListType mStructureNotificationList;

ResearchInfoListType mResearchInfoList;

int mCrosshairShowCount;
AVHHSPRITE mCrosshairSprite;
wrect_t mCrosshairRect;
Expand Down
95 changes: 58 additions & 37 deletions main/source/mod/AvHHudRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,64 +1474,69 @@ void AvHHud::DrawHUDStructureNotification()
float theCurrentX = kHUDStructureNotificationStartX;
float theCurrentY = kHUDStructureNotificationStartY;

//bool inTopDown = GetInTopDownMode();
AvHTeamNumber theCurrentTeam = this->GetHUDTeam();
bool isMarine = GetIsMarine();
float kSmallScaleFactor;
//Don't make building icons smaller if alien.
(theCurrentTeam == TEAM_TWO) ? kSmallScaleFactor = 1.0f : kSmallScaleFactor = 0.75f;
(isMarine) ? kSmallScaleFactor = 0.75f : kSmallScaleFactor = 1.0f;
const float kIconWidthSmall = kHUDStructureNotificationIconWidth * kSmallScaleFactor;
const float kIconHeightSmall = kHUDStructureNotificationIconHeight * kSmallScaleFactor;

if (isMarine)
{
for (ResearchInfoListType::iterator theIter = this->mResearchInfoList.begin(); theIter != this->mResearchInfoList.end(); theIter++)
{
// Draw icon
AvHMessageID theIconTech = theIter->mResearch;
int theFrame = 0;
int theStartX = (theCurrentX + kHUDStructureNotificationIconWidth + kHUDStructureNotificationIconHorizontalSpacing)*ScreenWidth();

string theResearchTimerText;
ActionButton::GetLabelForMessage(theIconTech, theResearchTimerText);

int timeLeft = theIter->mTimeResearchDone - this->mTimeOfCurrentUpdate;
int theMinutesLeft = timeLeft / 60;
int theSecondsLeft = timeLeft % 60;

if (theMinutesLeft)
theResearchTimerText += " - " + MakeStringFromInt(theMinutesLeft) + "m " + MakeStringFromInt(theSecondsLeft) + "s";
else
theResearchTimerText += " - " + MakeStringFromInt(theSecondsLeft) + "s";

int theR, theG, theB;
this->GetPrimaryHudColor(theR, theG, theB, true, false);
char theCharBuffer[512];
sprintf(theCharBuffer, "%s", theResearchTimerText.c_str());

float theCurrentTextY = theCurrentY + (kHUDStructureNotificationIconHeight * kTextHeightCenteringFactor);

this->DrawTechTreeSprite(theIconTech, theCurrentX*ScreenWidth(), theCurrentY*ScreenHeight(), kHUDStructureNotificationIconWidth*ScreenWidth(), kHUDStructureNotificationIconHeight*ScreenHeight(), theFrame);
this->DrawHudString(theStartX, theCurrentTextY*ScreenHeight(), ScreenWidth(), theCharBuffer, theR, theG, theB);

theCurrentY += (kHUDStructureNotificationIconHeight + kHUDStructureNotificationIconVerticalSpacing);
}
}

for(StructureHUDNotificationListType::iterator theIter = this->mStructureNotificationList.begin(); theIter != this->mStructureNotificationList.end(); theIter++)
{
// Draw icon
AvHMessageID theIconTech = theIter->mStructureID;
int theFrame = 0;

string theLocationName = this->GetNameOfLocation(theIter->mLocation);
int theStartX = (theCurrentX + kHUDStructureNotificationIconWidth + kHUDStructureNotificationIconHorizontalSpacing)*ScreenWidth();
bool isResearch = AvHSHUGetIsResearchTech(theIconTech);

//Don't draw cancel notifications. Still getting sent them in UpdateStructureNotification so they can be read to remove research.
if (theIconTech != MESSAGE_CANCEL)
if (!isResearch)
{
if (isResearch)
this->DrawTechTreeSprite(theIconTech, theCurrentX*ScreenWidth(), theCurrentY*ScreenHeight(), kIconWidthSmall*ScreenWidth(), kIconHeightSmall*ScreenHeight(), theFrame);
if (theLocationName != "")
{
string theResearchTimerText;
ActionButton::GetLabelForMessage(theIter->mStructureID, theResearchTimerText);

int timeLeft = theIter->mResearchTimer;
int theMinutesLeft = timeLeft / 60;
int theSecondsLeft = timeLeft % 60;

if (theMinutesLeft)
theResearchTimerText += " - " + MakeStringFromInt(theMinutesLeft) + "m " + MakeStringFromInt(theSecondsLeft) + "s";
else
theResearchTimerText += " - " + MakeStringFromInt(theSecondsLeft) + "s";

int theR, theG, theB;
this->GetPrimaryHudColor(theR, theG, theB, true, false);
char theCharBuffer[512];
sprintf(theCharBuffer, "%s", theResearchTimerText.c_str());

float theCurrentTextY = theCurrentY + (kHUDStructureNotificationIconHeight * kTextHeightCenteringFactor);

this->DrawTechTreeSprite(theIconTech, theCurrentX*ScreenWidth(), theCurrentY*ScreenHeight(), kHUDStructureNotificationIconWidth*ScreenWidth(), kHUDStructureNotificationIconHeight*ScreenHeight(), theFrame);
this->DrawHudString(theStartX, theCurrentTextY*ScreenHeight(), ScreenWidth(), theCharBuffer, theR, theG, theB);
}
else
{
this->DrawTechTreeSprite(theIconTech, theCurrentX*ScreenWidth(), theCurrentY*ScreenHeight(), kIconWidthSmall*ScreenWidth(), kIconHeightSmall*ScreenHeight(), theFrame);

int theStartXsmall = theStartX * kSmallScaleFactor;
float theCurrentTextY = theCurrentY + (kIconHeightSmall * kTextHeightCenteringFactor);

if (theLocationName != "")
this->DrawTranslatedString(theStartXsmall, theCurrentTextY*ScreenHeight(), theLocationName.c_str(), false, true);
this->DrawTranslatedString(theStartXsmall, theCurrentTextY*ScreenHeight(), theLocationName.c_str(), false, true);
}

// Increment coords
theCurrentY += (kHUDStructureNotificationIconHeight + kHUDStructureNotificationIconVerticalSpacing);
theCurrentY += (kIconHeightSmall + kHUDStructureNotificationIconVerticalSpacing);
}
}

Expand Down Expand Up @@ -4229,6 +4234,22 @@ void AvHHud::RenderAlienUI()
{
theR = theG = theB = 100;
}
// If building, draw time until completion.
else if (theIter->mStatus > 0 && theIter->mStatus < 6)
{
const int totalBuildTime = BALANCE_VAR(kHiveBuildTime);
if (theIter->mBuildTime > 0 && theIter->mBuildTime < totalBuildTime)
{
int timeLeft = theIter->mBuildTime;
int theMinutesLeft = timeLeft / 60;
int theSecondsLeft = timeLeft % 60;

if (theMinutesLeft)
theTranslatedLocationName = MakeStringFromInt(theMinutesLeft) + "m " + MakeStringFromInt(theSecondsLeft) + "s - " + theTranslatedLocationName;
else
theTranslatedLocationName = MakeStringFromInt(theSecondsLeft) + "s - " + theTranslatedLocationName;
}
}

this->DrawHudStringReverse(mViewport[0] + mViewport[2] - 5, theScreenPosY, ScreenWidth(), (char*)theTranslatedLocationName.c_str(), theR, theG, theB);
}
Expand Down
65 changes: 58 additions & 7 deletions main/source/mod/AvHNetworkMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void Net_InitializeMessages(void)
g_msgFog = REG_USER_MSG( "Fog", -1 );
g_msgGameStatus = REG_USER_MSG( "GameStatus", -1 );
g_msgListPS = REG_USER_MSG( "ListPS", -1 );
g_msgPlayHUDNotification = REG_USER_MSG( "PlayHUDNot", 6 );
g_msgPlayHUDNotification = REG_USER_MSG( "PlayHUDNot", -1 );
g_msgHUDSetUpgrades = REG_USER_MSG( "SetUpgrades", 1);
g_msgProgressBar = REG_USER_MSG( "Progress", -1 );
g_msgServerVar = REG_USER_MSG( "ServerVar", -1 );
Expand Down Expand Up @@ -969,6 +969,7 @@ enum AlienInfo_ChangeFlags
if( changes & HEALTH_CHANGED )
{
hives[counter].mHealthPercentage = READ_BYTE();
hives[counter].mBuildTime = READ_BYTE();
}
}
}
Expand Down Expand Up @@ -1019,8 +1020,9 @@ enum AlienInfo_ChangeFlags
client_hives[index].mUnderAttack != current->mUnderAttack || client_hives[index].mTechnology != current->mTechnology )
{ change_flags |= STATUS_CHANGED; }

if( client_hives.size() <= index || client_hives[index].mHealthPercentage != current->mHealthPercentage )
if( client_hives.size() <= index || client_hives[index].mHealthPercentage != current->mHealthPercentage || client_hives[index].mBuildTime != current->mBuildTime )
{ change_flags |= HEALTH_CHANGED; }

WRITE_BYTE(change_flags);

//send change data
Expand Down Expand Up @@ -1048,6 +1050,7 @@ enum AlienInfo_ChangeFlags
if( change_flags & HEALTH_CHANGED )
{
WRITE_BYTE(current->mHealthPercentage);
WRITE_BYTE(current->mBuildTime);
}
}
MESSAGE_END();
Expand Down Expand Up @@ -1494,17 +1497,43 @@ union float_converter
#endif

#ifndef AVH_SERVER
void NetMsg_PlayHUDNotification( void* const buffer, const int size, int& flags, int& sound, float& location_x, float& location_y )
void NetMsg_PlayHUDNotification( void* const buffer, const int size, int& flags, int& sound, float& location_x, float& location_y, ResearchInfoListType& researching)
{
BEGIN_READ( buffer, size );
flags = READ_BYTE();
sound = READ_BYTE();
location_x = READ_COORD();
location_y = READ_COORD();
// If sound or one time build notification
if (flags == 0 || flags == 1)
{
sound = READ_BYTE();
location_x = READ_COORD();
location_y = READ_COORD();
}
else
{
// Research tracker info
if (flags == 2)
{
int num_research = READ_BYTE();
researching.clear();
for (int counter = 0; counter < num_research; counter++)
{
AvHResearchInfo theResearchInfoEntry;
theResearchInfoEntry.mResearch = (AvHMessageID)READ_BYTE();

float_converter c;
c.l = READ_LONG();
theResearchInfoEntry.mTimeResearchDone = c.f;

//theResearchInfoEntry.mEntityIndex = READ_LONG();

researching.push_back(theResearchInfoEntry);
}
}
}
END_READ();
}
#else
void NetMsg_PlayHUDNotification( entvars_t* const pev, const int flags, const int sound, const float location_x, const float location_y )
void NetMsg_PlayHUDNotification_Single(entvars_t* const pev, const int flags, const int sound, const float location_x, const float location_y)
{
MESSAGE_BEGIN( MSG_ONE, g_msgPlayHUDNotification, NULL, pev );
WRITE_BYTE( flags );
Expand All @@ -1513,6 +1542,28 @@ union float_converter
WRITE_COORD( location_y );
MESSAGE_END();
}
void NetMsg_PlayHUDNotification_Research(entvars_t* const pev, const int flags, const ResearchInfoListType& researching)
{
MESSAGE_BEGIN(MSG_ONE, g_msgPlayHUDNotification, NULL, pev);
WRITE_BYTE(flags);
if (flags == 2)
{
// Research tracker info
WRITE_BYTE(researching.size());
ResearchInfoListType::const_iterator current, end = researching.end();
for (current = researching.begin(); current != end; ++current)
{
WRITE_BYTE(current->mResearch);

float_converter c;
c.f = current->mTimeResearchDone;
WRITE_LONG(c.l);

//WRITE_LONG(current->mEntityIndex);
}
}
MESSAGE_END();
}
#endif

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit 5202080

Please sign in to comment.