HUD for capture points now update with Capture point data.

This commit is contained in:
Tleety
2016-02-10 23:59:13 +01:00
parent 64a2354b24
commit 447f41dbff
4 changed files with 287 additions and 254 deletions
+23 -29
View File
@@ -1,55 +1,49 @@
#ifndef CapturePointSystem_h__ #ifndef CapturePointHUDSystem_h__
#define CapturePointSystem_h__ #define CapturePointHUDSystem_h__
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glm/common.hpp> #include <glm/common.hpp>
#include <glm/gtc/quaternion.hpp>
#include "Common.h" #include "Common.h"
#include "Core/System.h" #include "Core/System.h"
#include "Engine/Collision/ETrigger.h" #include "Engine/Collision/ETrigger.h"
#include "Core/ECaptured.h"
#include "Core/EWin.h"
#include <tuple> class CapturePointHUDSystem : public ImpureSystem
#include <vector>
class CapturePointSystem : public PureSystem
{ {
public: public:
//WARNING: on new map, destroy all info in the vectors, as well as reset all variables (just make new?) CapturePointHUDSystem(World* world, EventBroker* eventBroker);
CapturePointSystem(World* world, EventBroker* eventBroker);
//updatecomponent virtual void Update(double dt) override;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override;
private: private:
//methods which will take care of specific events //methods which will take care of specific events
EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch; /* EventRelay<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch;
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e);
EventRelay<CapturePointSystem, Events::TriggerLeave> m_ETriggerLeave; EventRelay<CapturePointSystem, Events::TriggerLeave> m_ETriggerLeave;
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured; EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e); bool CapturePointSystem::OnCaptured(const Events::Captured& e);*/
bool m_WinnerWasFound = false; //bool m_WinnerWasFound = false;
//need to track these variables for the captureSystem to work as per design! ////need to track these variables for the captureSystem to work as per design!
const int m_NotACapturePoint = 999; //const int m_NotACapturePoint = 999;
int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; //int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint;
int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; //int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint;
int m_RedTeamHomeCapturePoint = m_NotACapturePoint; //int m_RedTeamHomeCapturePoint = m_NotACapturePoint;
int m_BlueTeamHomeCapturePoint = m_NotACapturePoint; //int m_BlueTeamHomeCapturePoint = m_NotACapturePoint;
int m_NumberOfCapturePoints = 0; //int m_NumberOfCapturePoints = 0;
std::map<int, EntityWrapper> m_CapturePointNumberToEntityMap; //std::map<int, EntityWrapper> m_CapturePointNumberToEntityMap;
//std::vector<ComponentWrapper> ////std::vector<ComponentWrapper>
const double m_CaptureTimeToTakeOver = 15.0; //const double m_CaptureTimeToTakeOver = 15.0;
bool m_ResetTimers = false; //bool m_ResetTimers = false;
//vectors which will keep track of enter/leave changes ////vectors which will keep track of enter/leave changes
std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerTouchVector; //std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerTouchVector;
std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerLeaveVector; //std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerLeaveVector;
}; };
#endif #endif
+2 -3
View File
@@ -30,12 +30,11 @@ void main()
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
if(pos <= FillPercentage) { if(pos <= FillPercentage) {
color_result += FillColor; color_result = FillColor*diffuseTexel.a;
} }
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
color_result += glowTexel*3;
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0);
} }
+2
View File
@@ -12,6 +12,7 @@
#include "Systems/PlayerDeathSystem.h" #include "Systems/PlayerDeathSystem.h"
#include "Core/EntityFileWriter.h" #include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/CapturePointHUDSystem.h"
#include "Game/Systems/PickupSpawnSystem.h" #include "Game/Systems/PickupSpawnSystem.h"
#include "Game/Systems/WeaponSystem.h" #include "Game/Systems/WeaponSystem.h"
#include "Rendering/AnimationSystem.h" #include "Rendering/AnimationSystem.h"
@@ -103,6 +104,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
+258 -220
View File
@@ -1,243 +1,281 @@
#include "Systems/CapturePointSystem.h" #include "Systems/CapturePointHUDSystem.h"
#include <algorithm>
CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) CapturePointHUDSystem::CapturePointHUDSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker) : System(world, eventBroker)
, PureSystem("CapturePoint") , ImpureSystem()
{ {
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); //EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); //EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); //EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
} }
//here all capturepoints will update their component
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt void CapturePointHUDSystem::Update(double dt)
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
{ {
if (m_WinnerWasFound) { bool LoadCheck = false;
return; int redTeam;
} int blueTeam;
const int capturePointNumber = cCapturePoint["CapturePointNumber"]; int spectatorTeam;
const bool hasTeamComponent = capturePointEntity.HasComponent("Team");
//if point doesnt have a teamComponent yet, add one. since: auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD");
//what if capture point has no team -> we cant get/use the team enum from it... auto CapturePoints = m_World->GetComponents("CapturePoint");
if (!hasTeamComponent) {
m_World->AttachComponent(cCapturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = capturePointEntity["Team"];
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
}
ComponentWrapper& teamComponent = capturePointEntity["Team"];
const int redTeam = (int)teamComponent["Team"].Enum("Red");
const int blueTeam = (int)teamComponent["Team"].Enum("Blue");
const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
int homePointForTeam = (int)cCapturePoint["HomePointForTeam"]; for(auto& cCapturePointHUD : *CapturePointHUDElements) {
if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) { int HUD_ID = cCapturePointHUD["CapturePointNumber"];
m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3 EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID);
if (homePointForTeam == redTeam) { EntityWrapper entityHUDparent = entityHUD.Parent();
m_RedTeamHomeCapturePoint = capturePointNumber;
m_BlueTeamHomeCapturePoint = 0; for(auto& cCapturePoint : *CapturePoints) {
} else { EntityWrapper entityCP = EntityWrapper(m_World, cCapturePoint.EntityID);
m_BlueTeamHomeCapturePoint = capturePointNumber;
m_RedTeamHomeCapturePoint = 0; //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");
}
//Color hud with team color
auto capturePointTeam = (int)teamComponent["Team"];
entityHUDparent["Sprite"]["Color"] = capturePointTeam == blueTeam ? glm::vec4(0, 0.2f, 1, 0.7) : capturePointTeam == redTeam ? glm::vec4(1, 0.2f, 0, 0.7) : glm::vec4(1, 1, 1, 0.3);
//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.2f, 0, 0.7) : glm::vec4(0, 0.2f, 1, 0.7);
entityHUD["Fill"]["Color"] = fillColor;
entityHUD["Fill"]["Percentage"] = progress;
}
} }
} }
//if we havent received all capturepoints yet, just return //if (m_WinnerWasFound) {
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { // return;
m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); //}
return; //const int capturePointNumber = cCapturePoint["CapturePointNumber"];
} //const bool hasTeamComponent = capturePointEntity.HasComponent("Team");
//we have all capturepoints now - process stuff ////if point doesnt have a teamComponent yet, add one. since:
int ownedBy = teamComponent["Team"]; ////what if capture point has no team -> we cant get/use the team enum from it...
int redTeamPlayersStandingInside = 0; //if (!hasTeamComponent) {
int blueTeamPlayersStandingInside = 0; // m_World->AttachComponent(cCapturePoint.EntityID, "Team");
if (capturePointEntity.HasComponent("Model")) { // ComponentWrapper& teamComponent = capturePointEntity["Team"];
//Now sets team color to the capturepoint, or white if it is uncaptured. // teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); //}
} //ComponentWrapper& teamComponent = capturePointEntity["Team"];
//const int redTeam = (int)teamComponent["Team"].Enum("Red");
//const int blueTeam = (int)teamComponent["Team"].Enum("Blue");
//const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
//calculate next possible capturePoint for both teams //int homePointForTeam = (int)cCapturePoint["HomePointForTeam"];
std::map<std::string, int> nextPossibleCapturePoint; //if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) {
nextPossibleCapturePoint["Red"] = -1; // m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3
nextPossibleCapturePoint["Blue"] = -1; // if (homePointForTeam == redTeam) {
for (int i = 0; i < m_NumberOfCapturePoints; i++) // m_RedTeamHomeCapturePoint = capturePointNumber;
{ // m_BlueTeamHomeCapturePoint = 0;
if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { // } else {
continue; // m_BlueTeamHomeCapturePoint = capturePointNumber;
} // m_RedTeamHomeCapturePoint = 0;
ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; // }
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) { //}
nextPossibleCapturePoint["Red"] = i + 1;
}
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) {
nextPossibleCapturePoint["Blue"] = i + 1;
}
}
for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
{
if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
continue;
}
ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
nextPossibleCapturePoint["Red"] = i - 1;
}
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) {
nextPossibleCapturePoint["Blue"] = i - 1;
}
}
//reset timers and reset the bool that triggers this ////if we havent received all capturepoints yet, just return
if (m_ResetTimers) { //if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) {
for (int i = 0; i < m_NumberOfCapturePoints; i++) // m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity));
{ // return;
ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; //}
if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
(int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) {
capturePoint["CaptureTimer"] = 0.0;
}
}
m_ResetTimers = false;
}
//colorize next possible capturepoint ////we have all capturepoints now - process stuff
if (nextPossibleCapturePoint["Red"] == capturePointNumber) { //int ownedBy = teamComponent["Team"];
capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3); //int redTeamPlayersStandingInside = 0;
} //int blueTeamPlayersStandingInside = 0;
if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { //if (capturePointEntity.HasComponent("Model")) {
capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3); // //Now sets team color to the capturepoint, or white if it is uncaptured.
} // capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3);
//}
//check how many players are standing inside and are healthy ////calculate next possible capturePoint for both teams
for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) //std::map<std::string, int> nextPossibleCapturePoint;
{ //nextPossibleCapturePoint["Red"] = -1;
auto triggerTouched = m_ETriggerTouchVector[i - 1]; //nextPossibleCapturePoint["Blue"] = -1;
if (std::get<1>(triggerTouched) == capturePointEntity) { //for (int i = 0; i < m_NumberOfCapturePoints; i++)
//some player has touched this - lets figure out: what team, health //{
EntityWrapper player = std::get<0>(triggerTouched); // if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
//check if its really a player that has triggered the touch // continue;
if (!player.HasComponent("Player")) { // }
//if a non-player has entered the capturePoint, just erase that event and continue // ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1); // if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) {
continue; // nextPossibleCapturePoint["Red"] = i + 1;
} // }
bool hasHealthComponent = player.HasComponent("Health"); // if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) {
if (hasHealthComponent) { // nextPossibleCapturePoint["Blue"] = i + 1;
double currentHealth = player["Health"]["Health"]; // }
//check if player is dead //}
if ((int)currentHealth == 0) { //for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
continue; //{
} // if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
} // continue;
//check team - spectatorNumber = "no team" // }
int teamNumber = player["Team"]["Team"]; // ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
if (teamNumber == redTeam) { // if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
redTeamPlayersStandingInside++; // nextPossibleCapturePoint["Red"] = i - 1;
} else if (teamNumber == blueTeam) { // }
blueTeamPlayersStandingInside++; // if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) {
} // nextPossibleCapturePoint["Blue"] = i - 1;
continue; // }
} //}
}
//create data to be used in option B ////reset timers and reset the bool that triggers this
//check so this is the next possible capture point for the take-over team and see if only one team is standing inside it //if (m_ResetTimers) {
double timerDeltaChange = 0.0; // for (int i = 0; i < m_NumberOfCapturePoints; i++)
int currentTeam = 0; // {
bool canCapture = false; // ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"];
if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) { // if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
timerDeltaChange = redTeamPlayersStandingInside*dt; // (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) {
currentTeam = redTeam; // capturePoint["CaptureTimer"] = 0.0;
canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber; // }
} // }
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) { // m_ResetTimers = false;
timerDeltaChange = -blueTeamPlayersStandingInside*dt; //}
currentTeam = blueTeam;
canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber;
}
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) { ////colorize next possible capturepoint
//A.nobodys standing inside //if (nextPossibleCapturePoint["Red"] == capturePointNumber) {
//do nothing (?) // capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3);
} else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) { //}
//C.both teams have players inside //if (nextPossibleCapturePoint["Blue"] == capturePointNumber) {
//do nothing (?) // capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3);
} else { //}
//B. at most one of the teams have players inside
//if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly
if (ownedBy != currentTeam && canCapture) {
if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) {
LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently.
}
cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange;
}
//if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0
if ((ownedBy == currentTeam && currentTeam == redTeam && (double)cCapturePoint["CaptureTimer"] < 0.0) ||
(ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) {
cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange;
}
//check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event
if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
teamComponent["Team"] = currentTeam;
cCapturePoint["CaptureTimer"] = 0.0;
//publish Captured event
LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently.
Events::Captured e;
e.CapturePointID = cCapturePoint.EntityID;
e.TeamNumberThatCapturedCapturePoint = currentTeam;
m_EventBroker->Publish(e);
//NextPossibleCapturePoint will be calculated in the next update...
}
}
//check for possible winCondition = check if the homebase is owned by the other team ////check how many players are standing inside and are healthy
bool checkForWinner = false; //for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--)
if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam) //{
{ // auto triggerTouched = m_ETriggerTouchVector[i - 1];
checkForWinner = true; // if (std::get<1>(triggerTouched) == capturePointEntity) {
} // //some player has touched this - lets figure out: what team, health
if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam) // EntityWrapper player = std::get<0>(triggerTouched);
{ // //check if its really a player that has triggered the touch
checkForWinner = true; // if (!player.HasComponent("Player")) {
} // //if a non-player has entered the capturePoint, just erase that event and continue
// m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1);
// continue;
// }
// bool hasHealthComponent = player.HasComponent("Health");
// if (hasHealthComponent) {
// double currentHealth = player["Health"]["Health"];
// //check if player is dead
// if ((int)currentHealth == 0) {
// continue;
// }
// }
// //check team - spectatorNumber = "no team"
// int teamNumber = player["Team"]["Team"];
// if (teamNumber == redTeam) {
// redTeamPlayersStandingInside++;
// } else if (teamNumber == blueTeam) {
// blueTeamPlayersStandingInside++;
// }
// continue;
// }
//}
if (checkForWinner && !m_WinnerWasFound) ////create data to be used in option B
{ ////check so this is the next possible capture point for the take-over team and see if only one team is standing inside it
//publish Win event //double timerDeltaChange = 0.0;
Events::Win e; //int currentTeam = 0;
e.TeamThatWon = ownedBy; //bool canCapture = false;
m_EventBroker->Publish(e); //if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) {
m_WinnerWasFound = true; // timerDeltaChange = redTeamPlayersStandingInside*dt;
} // currentTeam = redTeam;
// canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber;
//}
//if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) {
// timerDeltaChange = -blueTeamPlayersStandingInside*dt;
// currentTeam = blueTeam;
// canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber;
//}
//if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) {
// //A.nobodys standing inside
// //do nothing (?)
//} else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) {
// //C.both teams have players inside
// //do nothing (?)
//} else {
// //B. at most one of the teams have players inside
// //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly
// if (ownedBy != currentTeam && canCapture) {
// if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) {
// LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently.
// }
// cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange;
// }
// //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0
// if ((ownedBy == currentTeam && currentTeam == redTeam && (double)cCapturePoint["CaptureTimer"] < 0.0) ||
// (ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) {
// cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange;
// }
// //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event
// if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
// teamComponent["Team"] = currentTeam;
// cCapturePoint["CaptureTimer"] = 0.0;
// //publish Captured event
// LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently.
// Events::Captured e;
// e.CapturePointID = cCapturePoint.EntityID;
// e.TeamNumberThatCapturedCapturePoint = currentTeam;
// m_EventBroker->Publish(e);
// //NextPossibleCapturePoint will be calculated in the next update...
// }
//}
////check for possible winCondition = check if the homebase is owned by the other team
//bool checkForWinner = false;
//if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam)
//{
// checkForWinner = true;
//}
//if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam)
//{
// checkForWinner = true;
//}
//if (checkForWinner && !m_WinnerWasFound)
//{
// //publish Win event
// Events::Win e;
// e.TeamThatWon = ownedBy;
// m_EventBroker->Publish(e);
// m_WinnerWasFound = true;
//}
} }
//
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) //bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
{ //{
//personEntered = e.Entity, thingEntered = e.Trigger // //personEntered = e.Entity, thingEntered = e.Trigger
m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger)); // m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger));
return true; // return true;
} //}
//
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e) //bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e)
{ //{
for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++) // for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++)
{ // {
auto triggerTouched = m_ETriggerTouchVector[i]; // auto triggerTouched = m_ETriggerTouchVector[i];
if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) { // if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) {
m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i); // m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i);
break; // break;
} // }
} // }
return true; // return true;
} //}
bool CapturePointSystem::OnCaptured(const Events::Captured& e) //bool CapturePointSystem::OnCaptured(const Events::Captured& e)
{ //{
//reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams // //reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams
m_ResetTimers = true; // m_ResetTimers = true;
return true; // return true;
} //}