Skip to content

Commit

Permalink
skins mode now repeats the final hole in the event of a tie
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Aug 21, 2023
1 parent 273ecab commit 0248ec9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 1297
#define BUILDNUMBER_STR "1297"
#define BUILDNUMBER 1305
#define BUILDNUMBER_STR "1305"

#endif /* BUILD_NUMBER_H_ */
29 changes: 27 additions & 2 deletions samples/golf/src/golf/server/ServerGolfRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,38 @@ bool GolfState::summariseDefaultRules()
std::uint16_t data = (player->client << 8) | player->player;
m_sharedData.host.broadcastPacket(PacketID::HoleWon, data, net::NetFlag::Reliable, ConstVal::NetChannelReliable);
}
else
else //increase the skins pot, but only if not repeating the final hole else we'll be here forever...
{
m_skinsPot++;

std::uint16_t data = 0xff00 | m_skinsPot;
m_sharedData.host.broadcastPacket(PacketID::HoleWon, data, net::NetFlag::Reliable, ConstVal::NetChannelReliable);
}


//check if we tied the last hole
if (m_sharedData.scoreType == ScoreType::Skins
&& ((m_currentHole + 1) == m_holeData.size()))
{
if (sortData[0].holeScore[m_currentHole] == sortData[1].holeScore[m_currentHole])
{
gameFinished = false;
//this is used to make sure we send the correct score update to the client when this function returns
//TODO we can also use this to cap the skins pot if necessary
m_skinsFinals = true;

for (auto& p : m_playerInfo)
{
p.holeScore[m_currentHole] = 0;
}

if (m_currentHole)
{
//we might be on a custom course with one
//hole in which case don't negate.
m_currentHole--;
}
}
}
}

return gameFinished;
Expand Down
10 changes: 7 additions & 3 deletions samples/golf/src/golf/server/ServerGolfState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ GolfState::GolfState(SharedData& sd)
m_scoreboardReadyFlags (0),
m_gameStarted (false),
m_allMapsLoaded (false),
m_skinsFinals (false),
m_currentHole (0),
m_skinsPot (1),
m_currentBest (MaxStrokes),
Expand Down Expand Up @@ -795,19 +796,22 @@ void GolfState::setNextHole()


//broadcast all scores to make sure everyone is up to date
//note that in skins games the above summary may have reduced
//the current hole index if the hole needs repeating
auto scoreHole = m_skinsFinals ? std::min(m_currentHole + 1, std::uint8_t(m_holeData.size()) - 1) : m_currentHole;
for (auto& player : m_playerInfo)
{
player.totalScore += player.holeScore[m_currentHole];
player.totalScore += player.holeScore[scoreHole];
player.targetHit = false;

ScoreUpdate su;
su.client = player.client;
su.player = player.player;
su.hole = m_currentHole;
su.hole = scoreHole;
su.score = player.totalScore;
su.matchScore = player.matchWins;
su.skinsScore = player.skins;
su.stroke = player.holeScore[m_currentHole];
su.stroke = player.holeScore[scoreHole];

m_sharedData.host.broadcastPacket(PacketID::ScoreUpdate, su, net::NetFlag::Reliable, ConstVal::NetChannelReliable);
}
Expand Down
1 change: 1 addition & 0 deletions samples/golf/src/golf/server/ServerGolfState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace sv
//game rule stuff. TODO encapsulate somewhere
bool m_gameStarted;
bool m_allMapsLoaded;
bool m_skinsFinals;
std::uint8_t m_currentHole;
std::vector<PlayerStatus> m_playerInfo; //active players. Sorted by distance so the front position is active player
std::uint8_t m_skinsPot;
Expand Down

0 comments on commit 0248ec9

Please sign in to comment.