Logic in CapturePointSystem is working again. Need to update all Tests!
This commit is contained in:
@@ -14,20 +14,80 @@ CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
|
||||
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
|
||||
void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
|
||||
{
|
||||
bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "Team");
|
||||
const int capturePointNumber = capturePoint["CapturePointNumber"];
|
||||
const bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "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) {
|
||||
world->AttachComponent(capturePoint.EntityID, "Team");
|
||||
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
|
||||
teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator");
|
||||
}
|
||||
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
|
||||
int firstTeamPlayersStandingInside = 0;
|
||||
int secondTeamPlayersStandingInside = 0;
|
||||
//what if capture point has no TEAM? -> NO ENUM.
|
||||
const int redTeam = (int)teamComponent["Team"].Enum("Red");//"team 1"
|
||||
const int blueTeam = (int)teamComponent["Team"].Enum("Blue");//"team 2"
|
||||
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"];
|
||||
if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) {
|
||||
m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3
|
||||
if (homePointForTeam == redTeam) {
|
||||
m_RedTeamHomeCapturePoint = capturePointNumber;
|
||||
m_BlueTeamHomeCapturePoint = 0;
|
||||
} else {
|
||||
m_BlueTeamHomeCapturePoint = capturePointNumber;
|
||||
m_RedTeamHomeCapturePoint = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//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));
|
||||
return;
|
||||
}
|
||||
|
||||
//we have all capturepoints now - process stuff
|
||||
int ownedBy = teamComponent["Team"];
|
||||
int redTeamPlayersStandingInside = 0;
|
||||
int blueTeamPlayersStandingInside = 0;
|
||||
if (entity.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);
|
||||
}
|
||||
|
||||
//calculate next possible capturePoint for both teams
|
||||
m_NextPossibleCapturePoint["Red"] = -1;
|
||||
m_NextPossibleCapturePoint["Blue"] = -1;
|
||||
for (size_t i = 0; i < m_NumberOfCapturePoints; i++)
|
||||
{
|
||||
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
|
||||
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) {
|
||||
m_NextPossibleCapturePoint["Red"] = i + 1;
|
||||
}
|
||||
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) {
|
||||
m_NextPossibleCapturePoint["Blue"] = i + 1;
|
||||
}
|
||||
}
|
||||
for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--)
|
||||
{
|
||||
ComponentWrapper& capturePointOwnedBy = world->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team");
|
||||
if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) {
|
||||
m_NextPossibleCapturePoint["Red"] = i - 1;
|
||||
}
|
||||
if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) {
|
||||
m_NextPossibleCapturePoint["Blue"] = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
//colorize next possible capturepoint
|
||||
if (m_NextPossibleCapturePoint["Red"] == capturePointNumber) {
|
||||
entity["Model"]["Color"] = glm::vec4(1, 1, 0, 1);
|
||||
}
|
||||
if (m_NextPossibleCapturePoint["Blue"] == capturePointNumber) {
|
||||
entity["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--)
|
||||
{
|
||||
@@ -51,70 +111,40 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
|
||||
//check team - spectatorNumber = "no team"
|
||||
int teamNumber = world->GetComponent(playerID, "Team")["Team"];
|
||||
if (teamNumber == redTeam) {
|
||||
firstTeamPlayersStandingInside++;
|
||||
redTeamPlayersStandingInside++;
|
||||
} else if (teamNumber == blueTeam) {
|
||||
secondTeamPlayersStandingInside++;
|
||||
blueTeamPlayersStandingInside++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int ownedBy = teamComponent["Team"];
|
||||
//Probably want to distinguish the capturepoint depending on team affiliation.
|
||||
if (entity.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);
|
||||
}
|
||||
//om ej next satt, förvänta sig att en capturepoint med en viss team färg kommer in...
|
||||
//sätt isåfall next och kör på..
|
||||
//gör inget tills man fått den infon
|
||||
|
||||
/*check what capturePoint can be taken over next:
|
||||
no capturepoint taken yet for at least one of the teams <->
|
||||
at the start of the match the system is unaware of what capturePoint is the first one for each team*/
|
||||
if (m_Team1NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == redTeam) {
|
||||
m_Team1HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team1NextPossibleCapturePoint
|
||||
if (m_Team1HomeCapturePoint == 0) {
|
||||
m_Team1NextPossibleCapturePoint = 1;
|
||||
} else {
|
||||
m_Team1NextPossibleCapturePoint = (int)capturePoint["CapturePointNumber"] - 1;
|
||||
}
|
||||
} else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == blueTeam) {
|
||||
m_Team2HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team2NextPossibleCapturePoint
|
||||
if (m_Team2HomeCapturePoint == 0) {
|
||||
m_Team2NextPossibleCapturePoint = 1;
|
||||
} else {
|
||||
m_Team2NextPossibleCapturePoint = (int)capturePoint["CapturePointNumber"] - 1;
|
||||
}
|
||||
}
|
||||
//at least one capturepoint has been taken over
|
||||
//do nothing, its being handled inside the next code:
|
||||
|
||||
//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
|
||||
double timerDeltaChange = 0.0;
|
||||
int currentTeam = 0;
|
||||
if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside == 0
|
||||
&& m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
|
||||
{
|
||||
timerDeltaChange = firstTeamPlayersStandingInside*dt;
|
||||
bool canCapture = false;
|
||||
if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) {
|
||||
timerDeltaChange = redTeamPlayersStandingInside*dt;
|
||||
currentTeam = redTeam;
|
||||
} else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0
|
||||
&& m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
|
||||
{
|
||||
timerDeltaChange = -secondTeamPlayersStandingInside*dt;
|
||||
canCapture = m_NextPossibleCapturePoint["Red"] == capturePointNumber;
|
||||
}
|
||||
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) {
|
||||
timerDeltaChange = -blueTeamPlayersStandingInside*dt;
|
||||
currentTeam = blueTeam;
|
||||
canCapture = m_NextPossibleCapturePoint["Blue"] == capturePointNumber;
|
||||
}
|
||||
|
||||
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) {
|
||||
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) {
|
||||
//A.nobodys standing inside
|
||||
//do nothing (?)
|
||||
} else if (currentTeam == blueTeam || currentTeam == redTeam) {
|
||||
//B. at most one of the teams have players inside (this means datavariable currentTeam is not 0)
|
||||
} 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) {
|
||||
if (ownedBy != currentTeam && canCapture) {
|
||||
if (abs((double)capturePoint["CaptureTimer"]) < 0.001f) {
|
||||
LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently.
|
||||
}
|
||||
@@ -126,7 +156,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
|
||||
capturePoint["CaptureTimer"] = (double)capturePoint["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)) {
|
||||
if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) {
|
||||
teamComponent["Team"] = currentTeam;
|
||||
capturePoint["CaptureTimer"] = 0.0;
|
||||
//publish Captured event
|
||||
@@ -135,53 +165,17 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
|
||||
e.CapturePointID = capturePoint.EntityID;
|
||||
e.TeamNumberThatCapturedCapturePoint = currentTeam;
|
||||
m_EventBroker->Publish(e);
|
||||
//modify nextPossibleCapturePoint, depending on, example: if team 1 has "0" as homebase or team 1 has "7" as homebase
|
||||
|
||||
//0 = false 1 = true
|
||||
bool team1HasTheZeroCapturePoint = m_Team1HomeCapturePoint < m_Team2HomeCapturePoint;
|
||||
|
||||
if (team1HasTheZeroCapturePoint) {
|
||||
if (currentTeam == redTeam) {
|
||||
m_Team1NextPossibleCapturePoint++;
|
||||
} else {
|
||||
m_Team2NextPossibleCapturePoint--;
|
||||
}
|
||||
//adjust flag for other team if their previous point has just been taken
|
||||
//this depends on what team has what homepoint ("side")
|
||||
if (m_Team2NextPossibleCapturePoint == m_Team1NextPossibleCapturePoint - 2) {
|
||||
m_Team2NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint + 1;
|
||||
}
|
||||
if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint + 2) {
|
||||
m_Team1NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint - 1;
|
||||
}
|
||||
} else {
|
||||
if (currentTeam == redTeam) {
|
||||
m_Team1NextPossibleCapturePoint--;
|
||||
} else {
|
||||
m_Team2NextPossibleCapturePoint++;
|
||||
}
|
||||
//adjust flag for other team if their previous point has just been taken
|
||||
//this depends on what team has what homepoint ("side")
|
||||
if (m_Team2NextPossibleCapturePoint == m_Team1NextPossibleCapturePoint + 2) {
|
||||
m_Team2NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint - 1;
|
||||
}
|
||||
if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint - 2) {
|
||||
m_Team1NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint + 1;
|
||||
}
|
||||
}
|
||||
//NextPossibleCapturePoint will be calculated in the next update...
|
||||
}
|
||||
} else if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) {
|
||||
//C.both teams have players inside
|
||||
//do nothing (?)
|
||||
}
|
||||
|
||||
//check for possible winCondition = check if the homebase is owned by the other team
|
||||
bool checkForWinner = false;
|
||||
if ((int)capturePoint["CapturePointNumber"] == m_Team1HomeCapturePoint && (int)teamComponent["Team"] != redTeam)
|
||||
if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam)
|
||||
{
|
||||
checkForWinner = true;
|
||||
}
|
||||
if ((int)capturePoint["CapturePointNumber"] == m_Team2HomeCapturePoint && (int)teamComponent["Team"] != blueTeam)
|
||||
if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam)
|
||||
{
|
||||
checkForWinner = true;
|
||||
}
|
||||
@@ -190,7 +184,7 @@ void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, Co
|
||||
{
|
||||
//publish Win event
|
||||
Events::Win e;
|
||||
e.TeamThatWon = teamComponent["Team"];
|
||||
e.TeamThatWon = ownedBy;
|
||||
m_EventBroker->Publish(e);
|
||||
m_WinnerWasFound = true;
|
||||
}
|
||||
@@ -216,3 +210,7 @@ bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CapturePointSystem::OnCaptured(const Events::Captured& e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user