The arrow should now track CapturePoints correctly at start and when they are captured.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/Transform.h"
|
#include "Core/Transform.h"
|
||||||
|
#include "Core/ECaptured.h"
|
||||||
|
|
||||||
|
|
||||||
class CapturePointArrowHUDSystem : public ImpureSystem
|
class CapturePointArrowHUDSystem : public ImpureSystem
|
||||||
@@ -18,6 +19,12 @@ public:
|
|||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EventRelay<CapturePointArrowHUDSystem, Events::Captured> m_ECapturedEvent;
|
||||||
|
bool OnCapturePointCaptured(Events::Captured& e);
|
||||||
|
|
||||||
|
bool m_InitialtargetsSet = false;
|
||||||
|
glm::vec3 m_RedTeamCurrentTarget;
|
||||||
|
glm::vec3 m_BlueTeamCurrentTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,12 +4,12 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params)
|
|||||||
: System(params)
|
: System(params)
|
||||||
, ImpureSystem()
|
, ImpureSystem()
|
||||||
{
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ECapturedEvent, &CapturePointArrowHUDSystem::OnCapturePointCaptured);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CapturePointArrowHUDSystem::Update(double dt)
|
void CapturePointArrowHUDSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool LoadCheck = true;
|
bool LoadCheck = true;
|
||||||
int redTeam;
|
int redTeam;
|
||||||
int blueTeam;
|
int blueTeam;
|
||||||
@@ -25,11 +25,13 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
|||||||
for(auto& cArrowHUD : *ArrowHUDs) {
|
for(auto& cArrowHUD : *ArrowHUDs) {
|
||||||
//Get what team the current arrow corresponds to
|
//Get what team the current arrow corresponds to
|
||||||
EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID);
|
EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID);
|
||||||
EntityWrapper teamEntity = ArrowEntity.FirstParentWithComponent("Team");
|
if (!ArrowEntity.Valid()) {
|
||||||
if (!teamEntity.Valid()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto cTeam = teamEntity["Team"];
|
if(!ArrowEntity.HasComponent("Team")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto cTeam = ArrowEntity["Team"];
|
||||||
int currentTeam = (int)cTeam["Team"];
|
int currentTeam = (int)cTeam["Team"];
|
||||||
|
|
||||||
if (LoadCheck) {
|
if (LoadCheck) {
|
||||||
@@ -37,20 +39,60 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
|||||||
blueTeam = (int)cTeam["Team"].Enum("Blue");
|
blueTeam = (int)cTeam["Team"].Enum("Blue");
|
||||||
spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
|
spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
|
||||||
LoadCheck = false;
|
LoadCheck = false;
|
||||||
|
|
||||||
|
|
||||||
|
if (!m_InitialtargetsSet) {
|
||||||
|
glm::vec3 target1, target2;
|
||||||
|
EntityWrapper home1, home2;
|
||||||
|
|
||||||
|
for (auto& cCP : *CapturePoints) {
|
||||||
|
auto homePointTeam = (int)cCP["HomePointForTeam"];
|
||||||
|
auto CPID = (int)cCP["CapturePointNumber"];
|
||||||
|
|
||||||
|
if(CPID == 0) {
|
||||||
|
//Home point for one team
|
||||||
|
home1 = EntityWrapper(m_World, cCP.EntityID);
|
||||||
|
} else if (CPID == 1) {
|
||||||
|
//First target for one team, so save it for later use.
|
||||||
|
target1 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID));
|
||||||
|
} else if (CPID == 3) {
|
||||||
|
//First target for one team, so save it for later use.
|
||||||
|
target2 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID));
|
||||||
|
} else if (CPID == 4) {
|
||||||
|
//Home point for one team
|
||||||
|
home2 = EntityWrapper(m_World, cCP.EntityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Check what team is the owner of Home1 and set their target to the next capturepoint
|
||||||
|
if((int)home1["CapturePoint"]["HomePointForTeam"] == redTeam) {
|
||||||
|
m_RedTeamCurrentTarget = target1;
|
||||||
|
} else if ((int)home1["CapturePoint"]["HomePointForTeam"] == blueTeam) {
|
||||||
|
m_BlueTeamCurrentTarget = target1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check what team is the owner of Home2 and set their target to the next capturepoint
|
||||||
|
if ((int)home2["CapturePoint"]["HomePointForTeam"] == redTeam) {
|
||||||
|
m_RedTeamCurrentTarget = target2;
|
||||||
|
} else if ((int)home2["CapturePoint"]["HomePointForTeam"] == blueTeam) {
|
||||||
|
m_BlueTeamCurrentTarget = target2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if red team, get red team next point, otherwise blue team next point.
|
//if red team, get red team next point, otherwise blue team next point.
|
||||||
//Untill this is awailable we will just use the hardcoded value in the component.
|
//Untill this is awailable we will just use the hardcoded value in the component.
|
||||||
//This will also give us a position, so we wont need to loop through all capturePoints.
|
//This will also give us a position, so we wont need to loop through all capturePoints.
|
||||||
glm::vec3 pos;
|
glm::vec3 pos;
|
||||||
int target = cArrowHUD["CurrentTarget"];
|
if(currentTeam == redTeam) {
|
||||||
for(auto& cCP : *CapturePoints) {
|
pos = m_RedTeamCurrentTarget;
|
||||||
if((int)cCP["CapturePointNumber"] == target) {
|
} else if (currentTeam == blueTeam) {
|
||||||
EntityWrapper CPEntity = EntityWrapper(m_World, cCP.EntityID);
|
pos = m_BlueTeamCurrentTarget;
|
||||||
pos = Transform::AbsolutePosition(CPEntity);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f);
|
||||||
|
|
||||||
glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"];
|
glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"];
|
||||||
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead
|
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead
|
||||||
float pitch = std::asin(-lookVector.y);
|
float pitch = std::asin(-lookVector.y);
|
||||||
@@ -63,54 +105,31 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
|||||||
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
|
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
|
||||||
bool LoadCheck = true;
|
{
|
||||||
int redTeam;
|
if (!e.NextCapturePoint.HasComponent("Team"))
|
||||||
int blueTeam;
|
{
|
||||||
int spectatorTeam;
|
return 0;
|
||||||
|
|
||||||
auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD");
|
|
||||||
auto CapturePoints = m_World->GetComponents("CapturePoint");
|
|
||||||
if (CapturePointHUDElements == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CapturePointHUDElements) {
|
auto cTeam = e.NextCapturePoint["Team"];
|
||||||
return;
|
|
||||||
|
int redTeam = (int)cTeam["Team"].Enum("Red");
|
||||||
|
int blueTeam = (int)cTeam["Team"].Enum("Blue");
|
||||||
|
int spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
|
||||||
|
int target = -1;
|
||||||
|
|
||||||
|
if (e.NextCapturePoint.HasComponent("CapturePoint")) {
|
||||||
|
target = (int)e.NextCapturePoint["CapturePoint"]["CapturePointNumber"];
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& cCapturePointHUD : *CapturePointHUDElements) {
|
if(e.TeamNumberThatCapturedCapturePoint == redTeam) {
|
||||||
int HUD_ID = cCapturePointHUD["CapturePointNumber"];
|
m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);
|
||||||
EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID);
|
} else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) {
|
||||||
EntityWrapper entityHUDparent = entityHUD.Parent();
|
m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);;
|
||||||
|
|
||||||
for (auto& cCapturePoint : *CapturePoints) {
|
|
||||||
EntityWrapper entityCP = EntityWrapper(m_World, cCapturePoint.EntityID);
|
|
||||||
|
|
||||||
//Check if the HUD corresponds to the Capture Point Number
|
|
||||||
if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) {
|
|
||||||
ComponentWrapper& teamComponent = entityCP["Team"];
|
|
||||||
if (LoadCheck) {
|
|
||||||
redTeam = (int)teamComponent["Team"].Enum("Red");
|
|
||||||
blueTeam = (int)teamComponent["Team"].Enum("Blue");
|
|
||||||
spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
|
|
||||||
LoadCheck = false;
|
|
||||||
}
|
|
||||||
//Color hud with team color
|
|
||||||
auto capturePointTeam = (int)teamComponent["Team"];
|
|
||||||
entityHUDparent["Sprite"]["Color"] = capturePointTeam == blueTeam ? glm::vec4(0, 0.2f, 1, 0.7f) : capturePointTeam == redTeam ? glm::vec4(1, 0.0f, 0, 0.7f) : glm::vec4(1, 1, 1, 0.3f);
|
|
||||||
|
|
||||||
//Progress is scaled with time
|
|
||||||
double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"];
|
|
||||||
double progress = glm::abs(currentCaptureTime)/15.0;
|
|
||||||
int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam;
|
|
||||||
((glm::vec3&)entityHUD["Transform"]["Orientation"]).z = currentCapturingTeam == redTeam ? glm::half_pi<float>()+glm::pi<float>() : glm::half_pi<float>();
|
|
||||||
glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.f, 0, 0.7f) : glm::vec4(0, 0.2f, 1, 0.7f);
|
|
||||||
entityHUD["Fill"]["Color"] = fillColor;
|
|
||||||
entityHUD["Fill"]["Percentage"] = progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user