CapturePointSystem now tracks and verifies if a capturePoint can be taken over. Also the time is changed faster the more players stand on the capturepoint (number*dt). Also took care of the problem when both teams have the same contested capturepoint.

Added variable in the CapturePoint component:  CapturePointNumber. This is needed since we cant know what capturepoint is next to be taken over otherwise.
Updated the CapturePointTest according to current CapturePointSystem
TODO: try to refactor code in CapturePointSystem
This commit is contained in:
verysecrethero
2016-01-13 11:41:01 +01:00
parent 3a1056a2c3
commit 7a8604bf2b
6 changed files with 91 additions and 19 deletions
+7 -1
View File
@@ -16,7 +16,7 @@
class CapturePointSystem : public PureSystem class CapturePointSystem : public PureSystem
{ {
public: 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); CapturePointSystem(EventBroker* eventBroker);
//updatecomponent //updatecomponent
@@ -30,6 +30,12 @@ private:
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
bool WinnerWasFound = false; 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 //vectors which will keep track of enter/leave changes
std::vector<std::tuple<EntityID, EntityID>> m_ETriggerTouchVector; std::vector<std::tuple<EntityID, EntityID>> m_ETriggerTouchVector;
@@ -1,4 +1,5 @@
<c:CapturePoint> <c:CapturePoint>
<CapturePointNumber>0</CapturePointNumber>
<CaptureTimer>0</CaptureTimer> <CaptureTimer>0</CaptureTimer>
<OwnedBy>0</OwnedBy> <OwnedBy>0</OwnedBy>
<IsHomeCapturePointForTeamNumber>0</IsHomeCapturePointForTeamNumber> <IsHomeCapturePointForTeamNumber>0</IsHomeCapturePointForTeamNumber>
@@ -12,6 +12,7 @@
<xs:element name="CaptureTimer" type="t:double" minOccurs="0"/> <xs:element name="CaptureTimer" type="t:double" minOccurs="0"/>
<xs:element name="OwnedBy" type="t:int" minOccurs="0"/> <xs:element name="OwnedBy" type="t:int" minOccurs="0"/>
<xs:element name="IsHomeCapturePointForTeamNumber" type="t:int" minOccurs="0"/> <xs:element name="IsHomeCapturePointForTeamNumber" type="t:int" minOccurs="0"/>
<xs:element name="CapturePointNumber" type="t:int" minOccurs="0"/>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
+71 -16
View File
@@ -10,9 +10,11 @@ CapturePointSystem::CapturePointSystem(EventBroker* eventBroker)
} }
//here all capturepoints will update their component //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, 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 firstTeamPlayersStandingInside = 0;
int secondTeamPlayersStandingInside = 0; int secondTeamPlayersStandingInside = 0;
@@ -42,40 +44,93 @@ void CapturePointSystem::UpdateComponent(World *world, ComponentWrapper &capture
int ownedBy = capturePoint["OwnedBy"]; int ownedBy = capturePoint["OwnedBy"];
double captureTimer = capturePoint["CaptureTimer"]; 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 //A.nobodys standing inside
if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) { if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside == 0) {
//do nothing (?) //do nothing (?)
} }
//B.first team has players but second none //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) { if (firstTeamPlayersStandingInside > 0 && secondTeamPlayersStandingInside == 0
//ownedBy 1 -> timer should stay at 5 && m_Team1NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) {
//ownedBy 1 -> timer should stay at 15
//increased by numberOfPlayersInside*dt
if (ownedBy == 2 || ownedBy == 0) if (ownedBy == 2 || ownedBy == 0)
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + dt; capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + firstTeamPlayersStandingInside*dt;
//check if captureTimer > 5 and if so change owner and publish the eCaptured event //check if captureTimer > 15 and if so change owner and publish the eCaptured event
if ((double)capturePoint["CaptureTimer"] > 5) { //TODO: graphics 25,50,75% captured events? for graphical issues
if ((double)capturePoint["CaptureTimer"] > 15.0) {
//publish Captured event
capturePoint["OwnedBy"] = 1; capturePoint["OwnedBy"] = 1;
capturePoint["CaptureTimer"] = 0.0;
Events::Captured e; Events::Captured e;
e.CapturePointID = capturePoint.EntityID; e.CapturePointID = capturePoint.EntityID;
e.TeamNumberThatCapturedCapturePoint = 1; e.TeamNumberThatCapturedCapturePoint = 1;
m_EventBroker->Publish(e); 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 //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) { if (firstTeamPlayersStandingInside == 0 && secondTeamPlayersStandingInside > 0
//ownedBy 2 -> timer should stay at -5 && m_Team2NextPossibleCapturePoint == (int)capturePoint["CapturePointNumber"]) {
//ownedBy 2 -> timer should stay at -15
//decreased by numberOfPlayersInside*dt
if (ownedBy == 1 || ownedBy == 0) if (ownedBy == 1 || ownedBy == 0)
capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] - dt; capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] - secondTeamPlayersStandingInside*dt;
//check if captureTimer > 5 and if so change owner and publish the eCaptured event //check if captureTimer < -15 and if so change owner and publish the eCaptured event
if ((double)capturePoint["CaptureTimer"] < -5.0) { //TODO: graphics 25,50,75% captured events? for graphical issues
if ((double)capturePoint["CaptureTimer"] < -15.0) {
capturePoint["OwnedBy"] = 2; capturePoint["OwnedBy"] = 2;
capturePoint["CaptureTimer"] = 0.0;
Events::Captured e; Events::Captured e;
e.CapturePointID = capturePoint.EntityID; e.CapturePointID = capturePoint.EntityID;
e.TeamNumberThatCapturedCapturePoint = 2; e.TeamNumberThatCapturedCapturePoint = 2;
m_EventBroker->Publish(e); 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;
}
} }
} }
+10 -1
View File
@@ -83,7 +83,16 @@ CapturePointTest::CapturePointTest(int runTestNumber)
ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint"); ComponentWrapper& capturePoint = m_World->AttachComponent(capturePointID, "CapturePoint");
//this capturePoint is homeBase for team 2 //this capturePoint is homeBase for team 2
capturePoint["IsHomeCapturePointForTeamNumber"] = 2; capturePoint["IsHomeCapturePointForTeamNumber"] = 2;
capturePoint["CapturePointNumber"] = 0;
m_CapturePointID = capturePointID; 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; m_RunTestNumber = runTestNumber;
//add some touch/leave events //add some touch/leave events
@@ -104,7 +113,7 @@ CapturePointTest::CapturePointTest(int runTestNumber)
Events::TriggerTouch eTriggerTouched3; Events::TriggerTouch eTriggerTouched3;
eTriggerTouched3.Entity = m_PlayerID; eTriggerTouched3.Entity = m_PlayerID;
eTriggerTouched3.Trigger = m_CapturePointID; eTriggerTouched3.Trigger = m_CapturePointID2;
m_EventBroker->Publish(eTriggerTouched3); m_EventBroker->Publish(eTriggerTouched3);
//init glfw so dt works //init glfw so dt works
+1 -1
View File
@@ -34,7 +34,7 @@ private:
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
World* m_World; World* m_World;
SystemPipeline* m_SystemPipeline; SystemPipeline* m_SystemPipeline;
int m_PlayerID, m_PlayerID2, m_CapturePointID; int m_PlayerID, m_PlayerID2, m_CapturePointID, m_CapturePointID2;
int m_RunTestNumber; int m_RunTestNumber;
}; };