Made TriggerSystem make use of Octree
This commit is contained in:
@@ -13,27 +13,27 @@ CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker)
|
||||
|
||||
//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 CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
|
||||
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
|
||||
{
|
||||
if (m_WinnerWasFound) {
|
||||
return;
|
||||
}
|
||||
const int capturePointNumber = capturePoint["CapturePointNumber"];
|
||||
const bool hasTeamComponent = m_World->HasComponent(capturePoint.EntityID, "Team");
|
||||
const int capturePointNumber = cCapturePoint["CapturePointNumber"];
|
||||
const bool hasTeamComponent = capturePointEntity.HasComponent("Team");
|
||||
|
||||
//if point doesnt have a teamComponent yet, add one. since:
|
||||
//what if capture point has no team -> we cant get/use the team enum from it...
|
||||
if (!hasTeamComponent) {
|
||||
m_World->AttachComponent(capturePoint.EntityID, "Team");
|
||||
ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team");
|
||||
m_World->AttachComponent(cCapturePoint.EntityID, "Team");
|
||||
ComponentWrapper& teamComponent = capturePointEntity["Team"];
|
||||
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
|
||||
}
|
||||
ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team");
|
||||
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)capturePoint["HomePointForTeam"];
|
||||
int homePointForTeam = (int)cCapturePoint["HomePointForTeam"];
|
||||
if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) {
|
||||
m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3
|
||||
if (homePointForTeam == redTeam) {
|
||||
@@ -46,8 +46,8 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
}
|
||||
|
||||
//if we havent received all capturepoints yet, just return
|
||||
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityIDMap.size()) {
|
||||
m_CapturePointNumberToEntityIDMap.insert(std::make_pair(capturePointNumber, capturePoint.EntityID));
|
||||
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) {
|
||||
m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
int ownedBy = teamComponent["Team"];
|
||||
int redTeamPlayersStandingInside = 0;
|
||||
int blueTeamPlayersStandingInside = 0;
|
||||
if (entity.HasComponent("Model")) {
|
||||
if (capturePointEntity.HasComponent("Model")) {
|
||||
//Now sets team color to the capturepoint, or white if it is uncaptured.
|
||||
entity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 1) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 1) : glm::vec4(1, 1, 1, 1);
|
||||
capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 1) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 1) : glm::vec4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
//calculate next possible capturePoint for both teams
|
||||
@@ -66,10 +66,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
nextPossibleCapturePoint["Blue"] = -1;
|
||||
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
|
||||
{
|
||||
if (!m_World->HasComponent(m_CapturePointNumberToEntityIDMap[i], "Team")) {
|
||||
if (m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
|
||||
continue;
|
||||
}
|
||||
ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
|
||||
ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
|
||||
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) {
|
||||
nextPossibleCapturePoint["Red"] = i + 1;
|
||||
}
|
||||
@@ -79,10 +79,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
}
|
||||
for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
|
||||
{
|
||||
if (!m_World->HasComponent(m_CapturePointNumberToEntityIDMap[i], "Team")) {
|
||||
if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) {
|
||||
continue;
|
||||
}
|
||||
ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
|
||||
ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"];
|
||||
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
|
||||
nextPossibleCapturePoint["Red"] = i - 1;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
if (m_ResetTimers) {
|
||||
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
|
||||
{
|
||||
ComponentWrapper& capturePoint = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "CapturePoint");
|
||||
ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"];
|
||||
if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] &&
|
||||
(int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) {
|
||||
capturePoint["CaptureTimer"] = 0.0;
|
||||
@@ -106,34 +106,34 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
|
||||
//colorize next possible capturepoint
|
||||
if (nextPossibleCapturePoint["Red"] == capturePointNumber) {
|
||||
entity["Model"]["Color"] = glm::vec4(1, 1, 0, 1);
|
||||
capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 1);
|
||||
}
|
||||
if (nextPossibleCapturePoint["Blue"] == capturePointNumber) {
|
||||
entity["Model"]["Color"] = glm::vec4(0, 1, 1, 1);
|
||||
capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 1);
|
||||
}
|
||||
|
||||
//check how many players are standing inside and are healthy
|
||||
for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--)
|
||||
{
|
||||
auto triggerTouched = m_ETriggerTouchVector[i - 1];
|
||||
if (std::get<1>(triggerTouched) == capturePoint.EntityID) {
|
||||
if (std::get<1>(triggerTouched) == capturePointEntity) {
|
||||
//some player has touched this - lets figure out: what team, health
|
||||
EntityID playerID = std::get<0>(triggerTouched);
|
||||
if (!m_World->HasComponent(playerID, "Player")) {
|
||||
EntityWrapper player = std::get<0>(triggerTouched);
|
||||
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 = m_World->HasComponent(playerID, "Health");
|
||||
bool hasHealthComponent = player.HasComponent("Health");
|
||||
if (hasHealthComponent) {
|
||||
double currentHealth = m_World->GetComponent(playerID, "Health")["Health"];
|
||||
double currentHealth = player["Health"]["Health"];
|
||||
//check if player is dead
|
||||
if ((int)currentHealth == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//check team - spectatorNumber = "no team"
|
||||
int teamNumber = m_World->GetComponent(playerID, "Team")["Team"];
|
||||
int teamNumber = player["Team"]["Team"];
|
||||
if (teamNumber == redTeam) {
|
||||
redTeamPlayersStandingInside++;
|
||||
} else if (teamNumber == blueTeam) {
|
||||
@@ -169,24 +169,24 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper
|
||||
//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)capturePoint["CaptureTimer"]) < 0.001f) {
|
||||
if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) {
|
||||
LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently.
|
||||
}
|
||||
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange;
|
||||
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)capturePoint["CaptureTimer"] < 0.0) ||
|
||||
(ownedBy == currentTeam && currentTeam == blueTeam && (double)capturePoint["CaptureTimer"] > 0.0)) {
|
||||
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange;
|
||||
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)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
|
||||
if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
|
||||
teamComponent["Team"] = currentTeam;
|
||||
capturePoint["CaptureTimer"] = 0.0;
|
||||
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 = capturePoint.EntityID;
|
||||
e.CapturePointID = cCapturePoint.EntityID;
|
||||
e.TeamNumberThatCapturedCapturePoint = currentTeam;
|
||||
m_EventBroker->Publish(e);
|
||||
//NextPossibleCapturePoint will be calculated in the next update...
|
||||
|
||||
Reference in New Issue
Block a user