WIP
This commit is contained in:
@@ -10,74 +10,134 @@ CapturePointArrowHUDSystem::CapturePointArrowHUDSystem(SystemParams params)
|
|||||||
|
|
||||||
void CapturePointArrowHUDSystem::Update(double dt)
|
void CapturePointArrowHUDSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
bool LoadCheck = true;
|
bool loadCheck = true;
|
||||||
int redTeam;
|
int redTeam;
|
||||||
int blueTeam;
|
int blueTeam;
|
||||||
int spectatorTeam;
|
int spectatorTeam;
|
||||||
|
|
||||||
//Get list for all CapturePointArrowHUDComponents
|
//Get list for all CapturePointArrowHUDComponents
|
||||||
auto ArrowHUDs = m_World->GetComponents("CapturePointArrowHUD");
|
auto arrowHUDs = m_World->GetComponents("CapturePointArrowHUD");
|
||||||
auto CapturePoints = m_World->GetComponents("CapturePoint");
|
auto capturePoints = m_World->GetComponents("CapturePoint");
|
||||||
if(ArrowHUDs == nullptr) {
|
if(arrowHUDs == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
if (!ArrowEntity.Valid()) {
|
if (!arrowEntity.Valid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!ArrowEntity.HasComponent("Team")) {
|
if(!arrowEntity.HasComponent("Team")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto cTeam = ArrowEntity["Team"];
|
auto cTeam = arrowEntity["Team"];
|
||||||
int currentTeam = (int)cTeam["Team"];
|
int currentTeam = (int)cTeam["Team"];
|
||||||
|
|
||||||
if (LoadCheck) {
|
if (loadCheck) {
|
||||||
redTeam = (int)cTeam["Team"].Enum("Red");
|
redTeam = (int)cTeam["Team"].Enum("Red");
|
||||||
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) {
|
if (!m_InitialtargetsSet) {
|
||||||
glm::vec3 target1, target2;
|
std::unordered_map<int, glm::vec3> blueTargets, redTargets;
|
||||||
EntityWrapper home1, home2;
|
EntityWrapper homeBlue, homeRed;
|
||||||
|
int lastCP = -INFINITY;
|
||||||
|
int firstCP = INFINITY;
|
||||||
|
|
||||||
for (auto& cCP : *CapturePoints) {
|
for (auto& cCP : *capturePoints) {
|
||||||
auto homePointTeam = (int)cCP["HomePointForTeam"];
|
auto homePointTeam = (int)cCP["HomePointForTeam"];
|
||||||
auto CPID = (int)cCP["CapturePointNumber"];
|
EntityWrapper capturePointEntity = EntityWrapper(m_World, cCP.EntityID);
|
||||||
|
int capturePointID = (int)capturePointEntity["CapturePoint"]["CapturePointNumber"];
|
||||||
|
|
||||||
if(CPID == 0) {
|
if(capturePointID < firstCP) {
|
||||||
//Home point for one team
|
firstCP = capturePointID;
|
||||||
home1 = EntityWrapper(m_World, cCP.EntityID);
|
}
|
||||||
} else if (CPID == 1) {
|
|
||||||
//First target for one team, so save it for later use.
|
if(capturePointID > lastCP) {
|
||||||
target1 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID));
|
lastCP = capturePointID;
|
||||||
} else if (CPID == 3) {
|
}
|
||||||
//First target for one team, so save it for later use.
|
|
||||||
target2 = Transform::AbsolutePosition(EntityWrapper(m_World, cCP.EntityID));
|
if (!capturePointEntity.HasComponent("Team")) {
|
||||||
} else if (CPID == 4) {
|
continue;
|
||||||
//Home point for one team
|
}
|
||||||
home2 = EntityWrapper(m_World, cCP.EntityID);
|
|
||||||
|
int currentOwner = (int)capturePointEntity["Team"]["Team"];
|
||||||
|
|
||||||
|
if(currentOwner != redTeam) {
|
||||||
|
//This capturePoint is not owned by the red team and is therefor an eligible target for red team
|
||||||
|
glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity);
|
||||||
|
redTargets.insert(std::pair<int, glm::vec3>(capturePointID, targetPos));
|
||||||
|
}
|
||||||
|
if(currentOwner != blueTeam) {
|
||||||
|
//This capturePoint is not owned by the blue team and is therefor an eligible target for blue team
|
||||||
|
glm::vec3 targetPos = Transform::AbsolutePosition(capturePointEntity);
|
||||||
|
blueTargets.insert(std::pair<int, glm::vec3>(capturePointID, targetPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(homePointTeam == blueTeam) {
|
||||||
|
//CP is the home point for blue team.
|
||||||
|
homeBlue = capturePointEntity;
|
||||||
|
} else if (homePointTeam == redTeam) {
|
||||||
|
//CP is the home point for red team.
|
||||||
|
homeRed = capturePointEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check what team is the owner of Home1 and set their target to the next capturepoint
|
|
||||||
if(!home1.Valid() || !home2.Valid()) {
|
if(!homeRed.Valid() || !homeBlue.Valid()) {
|
||||||
|
//One or both teams have no home point, cant continue
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((int)home1["CapturePoint"]["HomePointForTeam"] == redTeam) {
|
|
||||||
m_RedTeamCurrentTarget = target1;
|
std::unordered_map<int, glm::vec3>::const_iterator got;
|
||||||
} else if ((int)home1["CapturePoint"]["HomePointForTeam"] == blueTeam) {
|
//Find next target for red team.
|
||||||
m_BlueTeamCurrentTarget = target1;
|
if((int)homeRed["CapturePoint"]["CapturePointNumber"] == lastCP) {
|
||||||
|
//Red home base is the last capture point, count back from lastCP and find next target
|
||||||
|
for (int i = lastCP; i >= firstCP; i--) {
|
||||||
|
got = redTargets.find(i);
|
||||||
|
if(got == redTargets.end()) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
m_RedTeamCurrentTarget = got->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((int)homeRed["CapturePoint"]["CapturePointNumber"] == firstCP) {
|
||||||
|
//Red home is the first capture point, count forward from firstCP and find next target.
|
||||||
|
for (int i = firstCP; i <= lastCP; i++) {
|
||||||
|
got = redTargets.find(i);
|
||||||
|
if(got == redTargets.end()) {
|
||||||
|
//Target was not found, try the next one after that.
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
m_RedTeamCurrentTarget = got->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check what team is the owner of Home2 and set their target to the next capturepoint
|
//Find next target for blue team
|
||||||
if ((int)home2["CapturePoint"]["HomePointForTeam"] == redTeam) {
|
if ((int)homeBlue["CapturePoint"]["CapturePointNumber"] == lastCP) {
|
||||||
m_RedTeamCurrentTarget = target2;
|
//Red home base is the last capture point, count back from lastCP and find next target
|
||||||
} else if ((int)home2["CapturePoint"]["HomePointForTeam"] == blueTeam) {
|
for (int i = lastCP; i >= firstCP; i--) {
|
||||||
m_BlueTeamCurrentTarget = target2;
|
got = blueTargets.find(i);
|
||||||
|
if (got == blueTargets.end()) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
m_BlueTeamCurrentTarget = got->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((int)homeBlue["CapturePoint"]["CapturePointNumber"] == firstCP) {
|
||||||
|
//Red home is the first capture point, count forward from firstCP and find next target.
|
||||||
|
for (int i = firstCP; i <= lastCP; i++) {
|
||||||
|
got = blueTargets.find(i);
|
||||||
|
if (got == blueTargets.end()) {
|
||||||
|
//Target was not found, try the next one after that.
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
m_BlueTeamCurrentTarget = got->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,14 +153,14 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
|||||||
|
|
||||||
pos = currentTeam == redTeam ? m_RedTeamCurrentTarget : currentTeam == blueTeam ? m_BlueTeamCurrentTarget : glm::vec3(0.f);
|
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);
|
||||||
float yaw = std::atan2(lookVector.x, lookVector.z);
|
float yaw = std::atan2(lookVector.x, lookVector.z);
|
||||||
arrowOri.x = pitch;
|
arrowOri.x = pitch;
|
||||||
arrowOri.y = yaw;
|
arrowOri.y = yaw;
|
||||||
arrowOri.z = 0.f;
|
arrowOri.z = 0.f;
|
||||||
EntityWrapper parent = ArrowEntity.Parent();
|
EntityWrapper parent = arrowEntity.Parent();
|
||||||
if (parent.Valid()) {
|
if (parent.Valid()) {
|
||||||
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
|
arrowOri -= Transform::AbsoluteOrientationEuler(parent);
|
||||||
}
|
}
|
||||||
@@ -109,8 +169,7 @@ void CapturePointArrowHUDSystem::Update(double dt)
|
|||||||
|
|
||||||
bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
|
bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
|
||||||
{
|
{
|
||||||
if (!e.NextCapturePoint.HasComponent("Team"))
|
if (!e.NextCapturePoint.HasComponent("Team")) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,18 +178,11 @@ bool CapturePointArrowHUDSystem::OnCapturePointCaptured(Events::Captured& e)
|
|||||||
int redTeam = (int)cTeam["Team"].Enum("Red");
|
int redTeam = (int)cTeam["Team"].Enum("Red");
|
||||||
int blueTeam = (int)cTeam["Team"].Enum("Blue");
|
int blueTeam = (int)cTeam["Team"].Enum("Blue");
|
||||||
int spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
|
int spectatorTeam = (int)cTeam["Team"].Enum("Spectator");
|
||||||
int target = -1;
|
|
||||||
|
|
||||||
if (e.NextCapturePoint.HasComponent("CapturePoint")) {
|
|
||||||
target = (int)e.NextCapturePoint["CapturePoint"]["CapturePointNumber"];
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(e.TeamNumberThatCapturedCapturePoint == redTeam) {
|
if(e.TeamNumberThatCapturedCapturePoint == redTeam) {
|
||||||
m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);
|
m_RedTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);
|
||||||
} else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) {
|
} else if (e.TeamNumberThatCapturedCapturePoint == blueTeam) {
|
||||||
m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);;
|
m_BlueTeamCurrentTarget = Transform::AbsolutePosition(e.NextCapturePoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_InitialtargetsSet = true;
|
m_InitialtargetsSet = true;
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_RecentlyCapturedNeedNextCapturePointNow) {
|
if (m_RecentlyCapturedNeedNextCapturePointNow) {
|
||||||
|
//TODO: Next capture point for both teams
|
||||||
m_CapturedEvent.NextCapturePoint = m_CapturedEvent.TeamNumberThatCapturedCapturePoint == blueTeam ?
|
m_CapturedEvent.NextCapturePoint = m_CapturedEvent.TeamNumberThatCapturedCapturePoint == blueTeam ?
|
||||||
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]] :
|
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]] :
|
||||||
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
|
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
|
||||||
|
|||||||
Reference in New Issue
Block a user