diff --git a/include/Game/CapturePointSystem.h b/include/Game/CapturePointSystem.h index 8888da30..f7e600d7 100644 --- a/include/Game/CapturePointSystem.h +++ b/include/Game/CapturePointSystem.h @@ -16,7 +16,7 @@ class CapturePointSystem : public PureSystem { public: - //TODO: on new map, destroy all info in the vectors + //WARNING: on new map, destroy all info in the vectors, as well as reset all variables (just make new?) CapturePointSystem(EventBroker* eventBroker); //updatecomponent @@ -30,6 +30,12 @@ private: bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); bool WinnerWasFound = false; + //need to track these variables for the captureSystem to work as per design! + const int m_NotACapturePoint = 999; + int m_Team1NextPossibleCapturePoint = m_NotACapturePoint; + int m_Team2NextPossibleCapturePoint = m_NotACapturePoint; + int m_Team1HomeCapturePoint = m_NotACapturePoint; + int m_Team2HomeCapturePoint = m_NotACapturePoint; //vectors which will keep track of enter/leave changes std::vector> m_ETriggerTouchVector; diff --git a/resources/Schema/Components/CapturePoint.xml b/resources/Schema/Components/CapturePoint.xml index fddd1042..b2bd53d7 100644 --- a/resources/Schema/Components/CapturePoint.xml +++ b/resources/Schema/Components/CapturePoint.xml @@ -1,4 +1,5 @@ + 0 0 0 0 diff --git a/resources/Schema/Components/CapturePoint.xsd b/resources/Schema/Components/CapturePoint.xsd index b1cbe173..3171cf28 100644 --- a/resources/Schema/Components/CapturePoint.xsd +++ b/resources/Schema/Components/CapturePoint.xsd @@ -12,6 +12,7 @@ + diff --git a/src/Game/CapturePointSystem.cpp b/src/Game/CapturePointSystem.cpp index b276cb98..315e9729 100644 --- a/src/Game/CapturePointSystem.cpp +++ b/src/Game/CapturePointSystem.cpp @@ -10,9 +10,11 @@ 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) { - //NOTE: needs to run each frame, since we're possibly increasing the captureTimer for the capturePoint by dt + //for testing only: + //dt = 20.0; int firstTeamPlayersStandingInside = 0; int secondTeamPlayersStandingInside = 0; @@ -42,40 +44,93 @@ void CapturePointSystem::UpdateComponent(World *world, ComponentWrapper &capture int ownedBy = capturePoint["OwnedBy"]; double captureTimer = capturePoint["CaptureTimer"]; - //+-5 + //check what capturePoint can be taken over next + //TODO: modify this when a point has been taken over + //A. no capturepoint taken yet for at least one of the teams + //A1. 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) { + m_Team1NextPossibleCapturePoint = capturePoint["CapturePointNumber"]; + m_Team1HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team1NextPossibleCapturePoint + } + if (m_Team2NextPossibleCapturePoint == m_NotACapturePoint && (int)capturePoint["IsHomeCapturePointForTeamNumber"] == 2) { + m_Team2NextPossibleCapturePoint = capturePoint["CapturePointNumber"]; + m_Team2HomeCapturePoint = capturePoint["CapturePointNumber"];//needed to calculate next m_Team2NextPossibleCapturePoint + } + //B. at least one capturepoint has been taken over + //do nothing, its being handled inside the next code: + + //TODO: refactor code a bit //A.nobodys standing inside if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) { //do nothing (?) } - //B.first team has players but second none - if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside == 0) { - //ownedBy 1 -> timer should stay at 5 + //B.first team has players but second none, and this capturePoint is the next in line to be able to be captured + if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside == 0 + && m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) { + //ownedBy 1 -> timer should stay at 15 + //increased by numberOfPlayersInside*dt if (ownedBy == 2 || ownedBy == 0) - capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + dt; - //check if captureTimer > 5 and if so change owner and publish the eCaptured event - if ((double)capturePoint["CaptureTimer"] > 5) { + capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + firstTeamPlayersStandingInside*dt; + //check if captureTimer > 15 and if so change owner and publish the eCaptured event + //TODO: graphics 25,50,75% captured events? for graphical issues + if ((double)capturePoint["CaptureTimer"] > 15.0) { + //publish Captured event capturePoint["OwnedBy"] = 1; - capturePoint["CaptureTimer"] = 0.0; Events::Captured e; e.CapturePointID = capturePoint.EntityID; e.TeamNumberThatCapturedCapturePoint = 1; m_EventBroker->Publish(e); + //modify next m_Team1NextPossibleCapturePoint + //example team1:s homepoint is at 0 and team2:s at 7. team 1 capture 3, next will be 4 + //example team1:s homepoint is at 7 and team2:s at 0. team 1 capture 3, next will be 2 + if (m_Team1HomeCapturePoint < m_Team2HomeCapturePoint) { + m_Team1NextPossibleCapturePoint++; + //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) + m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint; + } + else + { + m_Team1NextPossibleCapturePoint--; + //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) + m_Team2NextPossibleCapturePoint = m_Team1NextPossibleCapturePoint; + } } } - //C.second team has players but second none - if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0) { - //ownedBy 2 -> timer should stay at -5 + //C.second team has players but second none, and this capturePoint is the next in line to be able to be captured + if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0 + && m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) { + //ownedBy 2 -> timer should stay at -15 + //decreased by numberOfPlayersInside*dt if (ownedBy == 1 || ownedBy == 0) - capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] - dt; - //check if captureTimer > 5 and if so change owner and publish the eCaptured event - if ((double)capturePoint["CaptureTimer"] < -5.0) { + capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] - secondTeamPlayersStandingInside*dt; + //check if captureTimer < -15 and if so change owner and publish the eCaptured event + //TODO: graphics 25,50,75% captured events? for graphical issues + if ((double)capturePoint["CaptureTimer"] < -15.0) { capturePoint["OwnedBy"] = 2; - capturePoint["CaptureTimer"] = 0.0; Events::Captured e; e.CapturePointID = capturePoint.EntityID; e.TeamNumberThatCapturedCapturePoint = 2; m_EventBroker->Publish(e); + //modify next m_Team2NextPossibleCapturePoint + //example team2:s homepoint is at 0 and team1:s at 7. team 2 capture 3, next will be 4 + //example team2:s homepoint is at 7 and team1:s at 0. team 2 capture 3, next will be 2 + if (m_Team2HomeCapturePoint < m_Team1HomeCapturePoint) + { + 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_Team2NextPossibleCapturePoint > m_Team1NextPossibleCapturePoint) + m_Team1NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint; + } + else + { + 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_Team2NextPossibleCapturePoint < m_Team1NextPossibleCapturePoint) + m_Team1NextPossibleCapturePoint = m_Team2NextPossibleCapturePoint; + } } } diff --git a/src/Tests/CapturePointTest.cpp b/src/Tests/CapturePointTest.cpp index deb64a41..1991acc9 100644 --- a/src/Tests/CapturePointTest.cpp +++ b/src/Tests/CapturePointTest.cpp @@ -83,7 +83,16 @@ CapturePointTest::CapturePointTest(int runTestNumber) ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint"); //this capturePoint is homeBase for team 2 capturePoint["IsHomeCapturePointForTeamNumber"] = 2; + capturePoint["CapturePointNumber"] = 0; m_CapturePointID = capturePointID; + + EntityID capturePointID2 = m_World->CreateEntity(); + ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint"); + //this capturePoint is homeBase for team 1 + capturePoint2["IsHomeCapturePointForTeamNumber"] = 1; + capturePoint2["CapturePointNumber"] = 1; + m_CapturePointID2 = capturePointID2; + m_RunTestNumber = runTestNumber; //add some touch/leave events @@ -104,7 +113,7 @@ CapturePointTest::CapturePointTest(int runTestNumber) Events::TriggerTouch eTriggerTouched3; eTriggerTouched3.Entity = m_PlayerID; - eTriggerTouched3.Trigger = m_CapturePointID; + eTriggerTouched3.Trigger = m_CapturePointID2; m_EventBroker->Publish(eTriggerTouched3); //init glfw so dt works diff --git a/src/Tests/CapturePointTest.h b/src/Tests/CapturePointTest.h index c0244802..1170c613 100644 --- a/src/Tests/CapturePointTest.h +++ b/src/Tests/CapturePointTest.h @@ -34,7 +34,7 @@ private: EventBroker* m_EventBroker; World* m_World; SystemPipeline* m_SystemPipeline; - int m_PlayerID, m_PlayerID2, m_CapturePointID; + int m_PlayerID, m_PlayerID2, m_CapturePointID, m_CapturePointID2; int m_RunTestNumber; };