Fixed logic for CapturePointSystem

This commit is contained in:
verysecrethero
2016-01-15 11:04:00 +01:00
parent 5e9a3774ab
commit 76a8b43ca3
2 changed files with 42 additions and 23 deletions
+41 -23
View File
@@ -24,18 +24,22 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
//some player has touched this - lets figure out: what team, health //some player has touched this - lets figure out: what team, health
EntityID playerID = std::get<0>(triggerTouched); EntityID playerID = std::get<0>(triggerTouched);
bool hasHealthComponent = world->HasComponent(playerID, "Health"); bool hasHealthComponent = world->HasComponent(playerID, "Health");
if (!hasHealthComponent) if (!hasHealthComponent) {
continue; continue;
}
double currentHealth = world->GetComponent(playerID, "Health")["Health"]; double currentHealth = world->GetComponent(playerID, "Health")["Health"];
//check if player is dead //check if player is dead
if ((int)currentHealth == 0) if ((int)currentHealth == 0) {
continue; continue;
}
//check team - 0 = no team //check team - 0 = no team
int teamNumber = world->GetComponent(playerID, "Player")["TeamNumber"]; int teamNumber = world->GetComponent(playerID, "Player")["TeamNumber"];
if (teamNumber == 1) if (teamNumber == 1) {
firstTeamPlayersStandingInside++; firstTeamPlayersStandingInside++;
else if (teamNumber == 2) }
else if (teamNumber == 2) {
secondTeamPlayersStandingInside++; secondTeamPlayersStandingInside++;
}
continue; continue;
} }
} }
@@ -81,13 +85,14 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
//B. at most one of the teams have players inside (this means datavariable currentTeam is not 0) //B. at most one of the teams have players inside (this means datavariable currentTeam is not 0)
else if (currentTeam != 0) { else if (currentTeam != 0) {
//if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly
if (ownedBy != currentTeam) if (ownedBy != currentTeam) {
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; capturePoint["CaptureTimer"] = (double)capturePoint["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 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 == 1 && (double)capturePoint["CaptureTimer"] < 0.0) if ((ownedBy == currentTeam && currentTeam == 1 && (double)capturePoint["CaptureTimer"] < 0.0) ||
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; (ownedBy == currentTeam && currentTeam == 2 && (double)capturePoint["CaptureTimer"] > 0.0)) {
if (ownedBy == currentTeam && currentTeam == 2 && (double)capturePoint["CaptureTimer"] > 0.0)
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange;
}
//check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event
if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver)) { if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver)) {
capturePoint["OwnedBy"] = currentTeam; capturePoint["OwnedBy"] = currentTeam;
@@ -98,24 +103,38 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
e.TeamNumberThatCapturedCapturePoint = currentTeam; e.TeamNumberThatCapturedCapturePoint = currentTeam;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
//modify nextPossibleCapturePoint, depending on, example: if team 1 has "0" as homebase or team 1 has "7" as homebase //modify nextPossibleCapturePoint, depending on, example: if team 1 has "0" as homebase or team 1 has "7" as homebase
if (m_Team1HomeCapturePoint < m_Team2HomeCapturePoint) {
if (currentTeam == 1) //0 = false 1 = true
bool team1HasTheZeroCapturePoint = m_Team1HomeCapturePoint < m_Team2HomeCapturePoint;
if (team1HasTheZeroCapturePoint) {
if (currentTeam == 1) {
m_Team1NextPossibleCapturePoint++; m_Team1NextPossibleCapturePoint++;
if (currentTeam == 2) }
else {
m_Team2NextPossibleCapturePoint--; m_Team2NextPossibleCapturePoint--;
//if this was a contested capturePoint (i.e. both teams try to take point 3), then modify other teams next point as well }
if (m_Team1NextPossibleCapturePoint > m_Team2NextPossibleCapturePoint) //adjust flag for other team if their previous point has just been taken
m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint; if (m_Team2NextPossibleCapturePoint == m_Team1NextPossibleCapturePoint - 2) {
m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint + 1;
}
if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint + 2) {
m_Team1NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint - 1;
}
} }
else else {
{ if (currentTeam == 1) {
if (currentTeam == 1)
m_Team1NextPossibleCapturePoint--; m_Team1NextPossibleCapturePoint--;
if (currentTeam == 2) }
else {
m_Team2NextPossibleCapturePoint++; m_Team2NextPossibleCapturePoint++;
//if this was a contested capturePoint (i.e. both teams try to take point 3), then modify other teams next point as well }
if (m_Team1NextPossibleCapturePoint < m_Team2NextPossibleCapturePoint) if (m_Team2NextPossibleCapturePoint == m_Team1NextPossibleCapturePoint + 2) {
m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint; m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint - 1;
}
if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint - 2) {
m_Team1NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint + 1;
}
} }
} }
} }
@@ -139,8 +158,7 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
{ {
//auto personEntered = e.Entity; //personEntered = e.Entity, thingEntered = e.Trigger
//auto 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;
} }
+1
View File
@@ -27,6 +27,7 @@ void HealthSystem::UpdateComponent(World *world, ComponentWrapper &health, doubl
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1); m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
//check if health is <= 0 //check if health is <= 0
if ((double)health["Health"] <= 0.0f) { if ((double)health["Health"] <= 0.0f) {
health["Health"] = 0.0;
//publish death event //publish death event
Events::PlayerDeath e; Events::PlayerDeath e;
e.PlayerID = player.EntityID; e.PlayerID = player.EntityID;