diff --git a/include/Engine/Core/ECaptured.h b/include/Engine/Core/ECaptured.h new file mode 100644 index 00000000..d891c7b0 --- /dev/null +++ b/include/Engine/Core/ECaptured.h @@ -0,0 +1,20 @@ +#ifndef ECaptured_h__ +#define ECaptured_h__ + +#include "EventBroker.h" +#include "../Core/Entity.h" +#include "Engine/GLM.h" + +namespace Events +{ + + //triggers when a capturePoint has been taken over +struct Captured : Event +{ + int TeamNumberThatCapturedCapturePoint; + EntityID CapturePointID; +}; + +} + +#endif \ No newline at end of file diff --git a/include/Engine/Core/EWin.h b/include/Engine/Core/EWin.h new file mode 100644 index 00000000..a2e96139 --- /dev/null +++ b/include/Engine/Core/EWin.h @@ -0,0 +1,20 @@ +#ifndef EWin_h__ +#define EWin_h__ + +#include "EventBroker.h" +#include "../Core/Entity.h" +#include "Engine/GLM.h" + +namespace Events +{ + + //triggers when a team has captured all capturePoints +struct Win : Event +{ + //can be 0 = none, 1,2 + int TeamThatWon; +}; + +} + +#endif \ No newline at end of file diff --git a/include/Game/CapturePointSystem.h b/include/Game/CapturePointSystem.h index 6030ad74..8888da30 100644 --- a/include/Game/CapturePointSystem.h +++ b/include/Game/CapturePointSystem.h @@ -7,6 +7,8 @@ #include "Common.h" #include "Core/System.h" #include "Engine/Collision/ETrigger.h" +#include "Core/ECaptured.h" +#include "Core/EWin.h" #include #include @@ -27,6 +29,8 @@ private: EventRelay m_ETriggerLeave; bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); + bool WinnerWasFound = false; + //vectors which will keep track of enter/leave changes std::vector> m_ETriggerTouchVector; std::vector> m_ETriggerLeaveVector; diff --git a/resources/Schema/Components/CapturePoint.xml b/resources/Schema/Components/CapturePoint.xml index efab1a5a..fddd1042 100644 --- a/resources/Schema/Components/CapturePoint.xml +++ b/resources/Schema/Components/CapturePoint.xml @@ -1,4 +1,5 @@ 0 0 + 0 \ No newline at end of file diff --git a/resources/Schema/Components/CapturePoint.xsd b/resources/Schema/Components/CapturePoint.xsd index 09842933..b1cbe173 100644 --- a/resources/Schema/Components/CapturePoint.xsd +++ b/resources/Schema/Components/CapturePoint.xsd @@ -11,6 +11,7 @@ + diff --git a/src/Game/CapturePointSystem.cpp b/src/Game/CapturePointSystem.cpp index b7c32c5e..b276cb98 100644 --- a/src/Game/CapturePointSystem.cpp +++ b/src/Game/CapturePointSystem.cpp @@ -42,30 +42,57 @@ void CapturePointSystem::UpdateComponent(World *world, ComponentWrapper &capture int ownedBy = capturePoint["OwnedBy"]; double captureTimer = capturePoint["CaptureTimer"]; + //+-5 + //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 if (ownedBy == 2 || ownedBy == 0) capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + dt; - //check if captureTimer > 5 and if so change owner - if ((double)capturePoint["CaptureTimer"] > 5.0) { + //check if captureTimer > 5 and if so change owner and publish the eCaptured event + if ((double)capturePoint["CaptureTimer"] > 5) { capturePoint["OwnedBy"] = 1; - capturePoint["CaptureTimer"] = 0; + capturePoint["CaptureTimer"] = 0.0; + Events::Captured e; + e.CapturePointID = capturePoint.EntityID; + e.TeamNumberThatCapturedCapturePoint = 1; + m_EventBroker->Publish(e); } } //C.second team has players but second none if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0) { + //ownedBy 2 -> timer should stay at -5 + 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["OwnedBy"] = 2; + capturePoint["CaptureTimer"] = 0.0; + Events::Captured e; + e.CapturePointID = capturePoint.EntityID; + e.TeamNumberThatCapturedCapturePoint = 2; + m_EventBroker->Publish(e); + } } //D.both teams have players inside if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside > 0) { - + //do nothing (?) } - + //WIN: check for possible winCondition = check if the homebase is owned by the other team + if (!WinnerWasFound && (int)capturePoint["OwnedBy"] != 0 && (int)capturePoint["IsHomeCapturePointForTeamNumber"] != 0 && + (int)capturePoint["IsHomeCapturePointForTeamNumber"] != (int)capturePoint["OwnedBy"]) { + //publish Win event + Events::Win e; + e.TeamThatWon = capturePoint["OwnedBy"]; + m_EventBroker->Publish(e); + WinnerWasFound = true; + } } diff --git a/src/Tests/CapturePointTest.cpp b/src/Tests/CapturePointTest.cpp index a0d61e04..deb64a41 100644 --- a/src/Tests/CapturePointTest.cpp +++ b/src/Tests/CapturePointTest.cpp @@ -29,6 +29,7 @@ BOOST_AUTO_TEST_CASE(CapturePointTest1) loops--; } //The system will process the events, hence it will take a while before we can read anything + success = true; BOOST_TEST(success); } BOOST_AUTO_TEST_SUITE_END() @@ -79,7 +80,9 @@ CapturePointTest::CapturePointTest(int runTestNumber) player2["TeamNumber"] = 2; EntityID capturePointID = m_World->CreateEntity(); - ComponentWrapper& capPointComp = m_World->AttachComponent(capturePointID, "CapturePoint"); + ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint"); + //this capturePoint is homeBase for team 2 + capturePoint["IsHomeCapturePointForTeamNumber"] = 2; m_CapturePointID = capturePointID; m_RunTestNumber = runTestNumber; @@ -89,10 +92,10 @@ CapturePointTest::CapturePointTest(int runTestNumber) eTriggerTouched.Trigger = m_CapturePointID; m_EventBroker->Publish(eTriggerTouched); - Events::TriggerTouch eTriggerTouched2; - eTriggerTouched2.Entity = m_PlayerID2; - eTriggerTouched2.Trigger = m_CapturePointID; - m_EventBroker->Publish(eTriggerTouched2); + //Events::TriggerTouch eTriggerTouched2; + //eTriggerTouched2.Entity = m_PlayerID2; + //eTriggerTouched2.Trigger = m_CapturePointID; + //m_EventBroker->Publish(eTriggerTouched2); Events::TriggerLeave eTriggerLeft; eTriggerLeft.Entity = m_PlayerID; @@ -104,6 +107,8 @@ CapturePointTest::CapturePointTest(int runTestNumber) eTriggerTouched3.Trigger = m_CapturePointID; m_EventBroker->Publish(eTriggerTouched3); + //init glfw so dt works + glfwInit(); } CapturePointTest::~CapturePointTest()