Changed CapturePointSystem in light of new enums in the components and a teamcomponent. Half the tests are currently working

This commit is contained in:
verysecrethero
2016-01-19 15:31:15 +01:00
parent 4c1a49a8a4
commit f197993beb
17 changed files with 190 additions and 189 deletions
-1
View File
@@ -27,7 +27,6 @@ set(SOURCE_FILES
"Game.cpp"
${SOURCE_FILES_Systems}
${SOURCE_FILES_Events}
"CapturePointSystem.cpp"
)
set(LIBRARIES
+1 -1
View File
@@ -8,7 +8,7 @@
#include "Systems/SpawnerSystem.h"
#include "Systems/PlayerSpawnSystem.h"
#include "Core/EntityFileWriter.h"
#include "Game/CapturePointSystem.h"
#include "Game/Systems/CapturePointSystem.h"
Game::Game(int argc, char* argv[])
{
@@ -1,8 +1,9 @@
#include "CapturePointSystem.h"
#include "Systems/CapturePointSystem.h"
#include <algorithm>
CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
: PureSystem(eventBroker, "CapturePoint")
: System(eventBroker),
PureSystem("CapturePoint")
{
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
@@ -11,10 +12,21 @@ CapturePointSystem::CapturePointSystem(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(World* world, ComponentWrapper& capturePoint, double dt)
void CapturePointSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
{
bool hasTeamComponent = world->HasComponent(capturePoint.EntityID, "Team");
if (!hasTeamComponent) {
world->AttachComponent(capturePoint.EntityID, "Team");
ComponentWrapper& teamComponent = world->GetComponent(capturePoint.EntityID, "Team");
teamComponent["Team"] = 0;
}
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 spectatorTeam = (int)teamComponent["Team"].Enum("Spectator");
//check how many players are standing inside and are healthy
for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--)
@@ -36,28 +48,30 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
continue;
}
}
//check team - 0 = no team
int teamNumber = world->GetComponent(playerID, "Player")["TeamNumber"];
if (teamNumber == 1) {
//check team - spectatorNumber = "no team"
int teamNumber = world->GetComponent(playerID, "Player")["Team"];
if (teamNumber == redTeam) {
firstTeamPlayersStandingInside++;
}
else if (teamNumber == 2) {
} else if (teamNumber == blueTeam) {
secondTeamPlayersStandingInside++;
}
continue;
}
}
int ownedBy = capturePoint["OwnedBy"];
int ownedBy = teamComponent["Team"];
//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)capturePoint["IsHomeCapturePointForTeamNumber"] == 1) {
if (m_Team1NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == redTeam) {
m_Team1NextPossibleCapturePoint = capturePoint["CapturePointNumber"];
m_Team1HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team1NextPossibleCapturePoint
}
else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)capturePoint["IsHomeCapturePointForTeamNumber"] == 2) {
} else if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)teamComponent["Team"] == blueTeam) {
m_Team2NextPossibleCapturePoint = capturePoint["CapturePointNumber"];
m_Team2HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team2NextPossibleCapturePoint
}
@@ -72,34 +86,31 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
&& m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
{
timerDeltaChange = firstTeamPlayersStandingInside*dt;
currentTeam = 1;
}
else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0
currentTeam = blueTeam;
} else if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0
&& m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"])
{
timerDeltaChange = -secondTeamPlayersStandingInside*dt;
currentTeam = 2;
currentTeam = redTeam;
}
//A.nobodys standing inside
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) {
//A.nobodys standing inside
//do nothing (?)
}
//B. at most one of the teams have players inside (this means datavariable currentTeam is not 0)
else if (currentTeam != 0) {
} else if (currentTeam == blueTeam || currentTeam == redTeam) {
//B. at most one of the teams have players inside (this means datavariable currentTeam is not 0)
//if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly
if (ownedBy != currentTeam) {
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 ((ownedBy == currentTeam && currentTeam == 1 && (double)capturePoint["CaptureTimer"] < 0.0) ||
(ownedBy == currentTeam && currentTeam == 2 && (double)capturePoint["CaptureTimer"] > 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;
}
//check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event
if (abs((double)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver)) {
capturePoint["OwnedBy"] = currentTeam;
teamComponent["Team"] = currentTeam;
capturePoint["CaptureTimer"] = 0.0;
//publish Captured event
Events::Captured e;
@@ -112,10 +123,9 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
bool team1HasTheZeroCapturePoint = m_Team1HomeCapturePoint < m_Team2HomeCapturePoint;
if (team1HasTheZeroCapturePoint) {
if (currentTeam == 1) {
if (currentTeam == redTeam) {
m_Team1NextPossibleCapturePoint++;
}
else {
} else {
m_Team2NextPossibleCapturePoint--;
}
//adjust flag for other team if their previous point has just been taken
@@ -126,12 +136,10 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
if (m_Team1NextPossibleCapturePoint == m_Team2NextPossibleCapturePoint + 2) {
m_Team1NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint - 1;
}
}
else {
if (currentTeam == 1) {
} else {
if (currentTeam == redTeam) {
m_Team1NextPossibleCapturePoint--;
}
else {
} else {
m_Team2NextPossibleCapturePoint++;
}
//adjust flag for other team if their previous point has just been taken
@@ -144,19 +152,27 @@ void CapturePointSystem::UpdateComponent(World* world, ComponentWrapper& capture
}
}
}
}
//C.both teams have players inside
else if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) {
} 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
if (!m_WinnerWasFound && (int)capturePoint["OwnedBy"] != 0 && (int)capturePoint["IsHomeCapturePointForTeamNumber"] != 0 &&
(int)capturePoint["IsHomeCapturePointForTeamNumber"] != (int)capturePoint["OwnedBy"]) {
bool checkForWinner = false;
if ((int)capturePoint["CapturePointNumber"] == m_Team1HomeCapturePoint && (int)teamComponent["Team"] != redTeam)
{
checkForWinner = true;
}
if ((int)capturePoint["CapturePointNumber"] == m_Team2HomeCapturePoint && (int)teamComponent["Team"] != blueTeam)
{
checkForWinner = true;
}
if (checkForWinner && !m_WinnerWasFound)
{
//publish Win event
Events::Win e;
e.TeamThatWon = capturePoint["OwnedBy"];
e.TeamThatWon = teamComponent["Team"];
m_EventBroker->Publish(e);
m_WinnerWasFound = true;
}
+1 -1
View File
@@ -27,7 +27,7 @@ void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, Componen
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
//check if health is <= 0
if ((double)component["Health"] <= 0.0f) {
health["Health"] = 0.0;
component["Health"] = 0.0;
//publish death event
Events::PlayerDeath e;
e.PlayerID = player.EntityID;