The arrow should now track CapturePoints correctly at start and when they are captured.

This commit is contained in:
Tleety
2016-03-01 21:57:30 +01:00
parent a38c18fd3a
commit ab40fa715b
2 changed files with 82 additions and 56 deletions
@@ -8,6 +8,7 @@
#include "Common.h"
#include "Core/System.h"
#include "Core/Transform.h"
#include "Core/ECaptured.h"
class CapturePointArrowHUDSystem : public ImpureSystem
@@ -18,6 +19,12 @@ public:
virtual void Update(double dt) override;
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
+75 -56
View File
@@ -4,12 +4,12 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params)
: System(params)
, ImpureSystem()
{
EVENT_SUBSCRIBE_MEMBER(m_ECapturedEvent, &CapturePointArrowHUDSystem::OnCapturePointCaptured);
}
void CapturePointArrowHUDSystem::Update(double dt)
{
bool LoadCheck = true;
int redTeam;
int blueTeam;
@@ -25,11 +25,13 @@ void CapturePointArrowHUDSystem::Update(double dt)
for(auto& cArrowHUD : *ArrowHUDs) {
//Get what team the current arrow corresponds to
EntityWrapper ArrowEntity = EntityWrapper(m_World, cArrowHUD.EntityID);
EntityWrapper teamEntity = ArrowEntity.FirstParentWithComponent("Team");
if (!teamEntity.Valid()) {
if (!ArrowEntity.Valid()) {
continue;
}
auto cTeam = teamEntity["Team"];
if(!ArrowEntity.HasComponent("Team")) {
continue;
}
auto cTeam = ArrowEntity["Team"];
int currentTeam = (int)cTeam["Team"];
if (LoadCheck) {
@@ -37,20 +39,60 @@ void CapturePointArrowHUDSystem::Update(double dt)
blueTeam = (int)cTeam["Team"].Enum("Blue");
spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
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.
//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.
glm::vec3 pos;
int target = cArrowHUD["CurrentTarget"];
for(auto& cCP : *CapturePoints) {
if((int)cCP["CapturePointNumber"] == target) {
EntityWrapper CPEntity = EntityWrapper(m_World, cCP.EntityID);
pos = Transform::AbsolutePosition(CPEntity);
break;
}
if(currentTeam == redTeam) {
pos = m_RedTeamCurrentTarget;
} else if (currentTeam == blueTeam) {
pos = m_BlueTeamCurrentTarget;
}
pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f);
glm::vec3& arrowOri = ArrowEntity["Transform"]["Orientation"];
glm::vec3 lookVector = glm::normalize(Transform::AbsolutePosition(ArrowEntity) - pos); //Maybe should be player instead
float pitch = std::asin(-lookVector.y);
@@ -63,54 +105,31 @@ void CapturePointArrowHUDSystem::Update(double dt)
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
}
}
}
/*
bool LoadCheck = true;
int redTeam;
int blueTeam;
int spectatorTeam;
auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD");
auto CapturePoints = m_World->GetComponents("CapturePoint");
if (CapturePointHUDElements == nullptr) {
return;
bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
{
if (!e.NextCapturePoint.HasComponent("Team"))
{
return 0;
}
if (!CapturePointHUDElements) {
return;
auto cTeam = e.NextCapturePoint["Team"];
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) {
int HUD_ID = cCapturePointHUD["CapturePointNumber"];
EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID);
EntityWrapper entityHUDparent = entityHUD.Parent();
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;
}
}
if(e.TeamNumberThatCapturedCapturePoint == redTeam) {
m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);
} else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) {
m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);;
}
*/
}
}