fixing bugs, adding comments, structures and functions for the map vote system
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@14122 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
0ce03186ee
commit
c9cb74a9e5
29
data/gui/karts_online.stkgui
Normal file
29
data/gui/karts_online.stkgui
Normal file
@ -0,0 +1,29 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="1%" y="1%" width="98%" height="99%" layout="vertical-row" >
|
||||
|
||||
<header width="80%"
|
||||
I18N="In the kart selection (player setup) screen"
|
||||
text="Choose a Kart"
|
||||
align="center" text_align="center" />
|
||||
|
||||
<placeholder id="playerskarts" width="100%" align="center" proportion="4">
|
||||
<!-- Contents is added programatically -->
|
||||
</placeholder>
|
||||
|
||||
<spacer height="15" width="25"/>
|
||||
|
||||
<box proportion="2" width="100%" layout="vertical-row" padding="2">
|
||||
<ribbon_grid id="karts" proportion="1" square_items="true" width="100%" align="center"
|
||||
child_width="90" child_height="90" max_rows="3"/>
|
||||
</box>
|
||||
|
||||
<!-- Groups will be added dynamically at runtime -->
|
||||
<tabs width="98%" x="1%" height="25" id="kartgroups">
|
||||
</tabs>
|
||||
<spacer width="100%" height="2%"/>
|
||||
</div>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
|
||||
|
||||
</stkgui>
|
@ -170,6 +170,7 @@ src/network/protocols/start_game_protocol.cpp
|
||||
src/network/protocols/start_server.cpp
|
||||
src/network/protocols/stop_server.cpp
|
||||
src/network/protocols/synchronization_protocol.cpp
|
||||
src/network/race_config.cpp
|
||||
src/network/server_network_manager.cpp
|
||||
src/network/stk_host.cpp
|
||||
src/network/stk_peer.cpp
|
||||
@ -475,6 +476,7 @@ src/network/protocols/start_game_protocol.hpp
|
||||
src/network/protocols/start_server.hpp
|
||||
src/network/protocols/stop_server.hpp
|
||||
src/network/protocols/synchronization_protocol.hpp
|
||||
src/network/race_config.hpp
|
||||
src/network/remote_kart_info.hpp
|
||||
src/network/server_network_manager.hpp
|
||||
src/network/singleton.hpp
|
||||
|
@ -20,13 +20,14 @@
|
||||
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GameSetup::GameSetup()
|
||||
{
|
||||
m_race_config = new RaceConfig();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -23,6 +23,7 @@
|
||||
#define GAME_SETUP_HPP
|
||||
|
||||
#include "online/profile.hpp"
|
||||
#include "network/race_config.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -89,9 +90,12 @@ class GameSetup
|
||||
*/
|
||||
bool isKartAllowed(std::string kart_name) {return true; }
|
||||
|
||||
RaceConfig* getRaceConfig() { return m_race_config; }
|
||||
|
||||
protected:
|
||||
std::vector<NetworkPlayerProfile*> m_players; //!< Information about players
|
||||
NetworkPlayerProfile m_self_profile; //!< Information about self (client only)
|
||||
RaceConfig* m_race_config;
|
||||
};
|
||||
|
||||
#endif // GAME_SETUP_HPP
|
||||
|
@ -24,12 +24,6 @@
|
||||
#include "network/game_setup.hpp"
|
||||
#include "network/network_string.hpp"
|
||||
|
||||
|
||||
class RaceConfig
|
||||
{
|
||||
int m_world_type;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \class LobbyRoomProtocol
|
||||
* \brief Class used while the game is being prepared.
|
||||
|
169
src/network/race_config.cpp
Normal file
169
src/network/race_config.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
#include "network/race_config.hpp"
|
||||
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
template<typename S>
|
||||
S getHighestInHistogram(std::map<S,int>* histogram)
|
||||
{
|
||||
S best_item;
|
||||
int highest_count;
|
||||
for (typename std::map<S, int>::iterator it = histogram->begin();
|
||||
it != histogram->end(); it++)
|
||||
{
|
||||
if (it->second > highest_count)
|
||||
{
|
||||
highest_count = it->second;
|
||||
best_item = it->first;
|
||||
}
|
||||
}
|
||||
return best_item;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
TrackVote::TrackVote()
|
||||
{
|
||||
has_voted_laps = false;
|
||||
has_voted_track = false;
|
||||
has_voted_reversed = false;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void TrackVote::voteTrack(std::string track)
|
||||
{
|
||||
track_info.track = track;
|
||||
has_voted_track = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void TrackVote::voteReversed(bool reversed)
|
||||
{
|
||||
track_info.reversed = reversed;
|
||||
has_voted_reversed = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void TrackVote::voteLaps(int laps)
|
||||
{
|
||||
track_info.laps = laps;
|
||||
has_voted_laps = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int GPRaceInfo::getMajorMode()
|
||||
{
|
||||
return RaceManager::MAJOR_MODE_GRAND_PRIX;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int SingleRaceInfo::getMajorMode()
|
||||
{
|
||||
return RaceManager::MAJOR_MODE_SINGLE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
RaceConfig::RaceConfig()
|
||||
{
|
||||
m_max_players = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RaceConfig::setPlayerCount(int count)
|
||||
{
|
||||
m_max_players = count;
|
||||
m_votes.resize(m_max_players);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RaceConfig::setPlayerTrackVote(int player_id, std::string track_name)
|
||||
{
|
||||
m_votes[player_id].voteTrack(track_name);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RaceConfig::setPlayerReverseVote(int player_id, bool reversed)
|
||||
{
|
||||
m_votes[player_id].voteReversed(reversed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RaceConfig::setPlayerLapVote(int player_id, int lap_count)
|
||||
{
|
||||
m_votes[player_id].voteLaps(lap_count);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RaceConfig::computeNextTrack()
|
||||
{
|
||||
// first create histograms of the votes
|
||||
std::map<std::string,int> tracks_histogram;
|
||||
std::map<bool,int> reversed_histogram;
|
||||
std::map<int,int> laps_histogram;
|
||||
for (unsigned int i = 0; i < m_max_players; i++)
|
||||
{
|
||||
// increase the count of votes
|
||||
if (m_votes[i].has_voted_track)
|
||||
{
|
||||
try // maps
|
||||
{
|
||||
tracks_histogram.at(m_votes[i].track_info.track) ++;
|
||||
}
|
||||
catch (const std::out_of_range& oor) // doesn't exist in the map : add it
|
||||
{
|
||||
tracks_histogram[m_votes[i].track_info.track] = 1;
|
||||
}
|
||||
}
|
||||
else if (m_votes[i].has_voted_reversed)
|
||||
{
|
||||
try // reversed
|
||||
{
|
||||
reversed_histogram.at(m_votes[i].track_info.reversed) ++;
|
||||
}
|
||||
catch (const std::out_of_range& oor) // doesn't exist in the map : add it
|
||||
{
|
||||
reversed_histogram[m_votes[i].track_info.reversed] = 1;
|
||||
}
|
||||
}
|
||||
else if (m_votes[i].has_voted_laps)
|
||||
{
|
||||
try // laps
|
||||
{
|
||||
laps_histogram.at(m_votes[i].track_info.laps) ++;
|
||||
}
|
||||
catch (const std::out_of_range& oor) // doesn't exist in the map : add it
|
||||
{
|
||||
laps_histogram[m_votes[i].track_info.laps] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// now find the highest votes
|
||||
m_track.track = getHighestInHistogram<std::string>(&tracks_histogram);
|
||||
m_track.reversed = getHighestInHistogram<bool>(&reversed_histogram);
|
||||
m_track.laps = getHighestInHistogram<int>(&laps_histogram);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const TrackInfo* RaceConfig::getNextTrack() const
|
||||
{
|
||||
return m_track.track;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool RaceConfig::getReverse() const
|
||||
{
|
||||
return m_track.track;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool RaceConfig::getLapCount() const
|
||||
{
|
||||
return m_track.track;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
58
src/network/race_config.hpp
Normal file
58
src/network/race_config.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef RACE_CONFIG_HPP
|
||||
#define RACE_CONFIG_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TrackInfo
|
||||
{
|
||||
public:
|
||||
std::string track;
|
||||
bool reversed;
|
||||
int laps;
|
||||
};
|
||||
class TrackVote
|
||||
{
|
||||
public:
|
||||
TrackVote();
|
||||
|
||||
void voteTrack(std::string track);
|
||||
void voteReversed(bool reversed);
|
||||
void voteLaps(int laps);
|
||||
|
||||
TrackInfo track_info;
|
||||
|
||||
bool has_voted_track;
|
||||
bool has_voted_reversed;
|
||||
bool has_voted_laps;
|
||||
|
||||
int minor_race_type; // corresponds to the enum in race_manager.hpp
|
||||
};
|
||||
|
||||
class RaceConfig
|
||||
{
|
||||
public:
|
||||
RaceConfig();
|
||||
|
||||
void setPlayerCount(int count);
|
||||
void setPlayerTrackVote(int player_id, std::string track_name);
|
||||
void setPlayerReverseVote(int player_id, bool reversed);
|
||||
void setPlayerLapVote(int player_id, int lap_count);
|
||||
|
||||
void computeNextTrack();
|
||||
|
||||
const TrackInfo* getNextTrack() const;
|
||||
bool getReverse() const;
|
||||
bool getLapCount() const;
|
||||
|
||||
protected:
|
||||
TrackInfo m_track;
|
||||
bool m_reverse;
|
||||
int m_laps;
|
||||
|
||||
std::vector<TrackVote> m_votes;
|
||||
int m_max_players;
|
||||
};
|
||||
|
||||
|
||||
#endif // RACE_CONFIG_HPP
|
Loading…
Reference in New Issue
Block a user