Commit b18219f7 by Thomas Brandého

Taunt clear other actions

parent 866c144b
......@@ -96,10 +96,14 @@ void Client::handlePackets()
break;
}
case MAP_INIT:
{
int turn;
packet >> turn;
packet >> m_map;
m_graphics->initCrates(m_map.getCrates());
m_graphics->setTurn(m_map.getTurn());
m_graphics->setTurn(turn);
break;
}
case MAP_DIFF:
{
MapDiff msg;
......
......@@ -13,7 +13,7 @@ MapKoban::MapKoban():
MapKoban::MapKoban(int w, int h):
m_width(w),
m_height(h),
m_turn_id(0),
//m_turn_id(0),
m_tiles(std::vector<int>(m_width*m_height, FLOOR))
{
}
......
......@@ -11,7 +11,7 @@ class MapKoban
{
int m_width;
int m_height;
unsigned int m_turn_id;
// unsigned int m_turn_id;
std::vector<int> m_tiles;
std::vector<Crate> m_crates;
......@@ -22,8 +22,8 @@ public:
int getWidth() { return m_width; }
int getHeight() { return m_height; }
void newTurn(){m_turn_id++;}
unsigned int getTurn(){return m_turn_id;}
// void newTurn(){m_turn_id++;}
// unsigned int getTurn(){return m_turn_id;}
TileType getTile(sf::Vector2i v);
......
......@@ -84,7 +84,7 @@ bool MapInstance::teleportPlayer(const sf::String &id, sf::Vector2i pos)
player_add.id = id;
player_add.color = player->color;
player_add.pos = pos;
player_add.turn_id = m_map.getTurn();
player_add.turn_id = getCurrentTurn();
sf::Packet packet;
packet << PLAYER_REMOVE;
packet << player_remove;
......@@ -117,6 +117,22 @@ void MapInstance::pushPlayerAction(PlayerDiff p_diff)
diff->players.push_back(p_diff);
}
void MapInstance::clearAllPlayerAction(std::string id){
int start = getCurrentTurn();
int end = m_characters[id]->action_turn;
if(start > end)
return;
else
{
for(int i = start; i <= end; i++)
{
MapDiff* md = m_mapdiffs[i];
md->players.erase(std::remove_if(md->players.begin(),md->players.end(),[id](PlayerDiff d){return d.id == id;}),md->players.end());
}
m_characters[id]->action_turn=start;
}
}
void MapInstance::filterMapDiff()
{
MapDiff* raw_diff = m_mapdiffs[m_current_turn_id];
......
......@@ -57,6 +57,7 @@ public:
sf::Packet& packCharacterData(sf::Packet &packet);
void pushPlayerAction(PlayerDiff p_diff);
void clearAllPlayerAction(std::string id);
unsigned int getCurrentTurn(){return m_current_turn_id;}
......
......@@ -112,7 +112,7 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
auth_answer.isOk = false;
packet_out << AUTH_ANSWER << auth_answer;
if(auth_answer.isOk){
packet_out << MAP_INIT << map->getMapData();
packet_out << MAP_INIT << m_server->getMap()->getCurrentTurn() << map->getMapData();
packet_out = map->packCharacterData(packet_out);
}
safeSend(socket,packet_out);
......@@ -149,6 +149,7 @@ void SocketHandler::handleSocketMessage(sf::TcpSocket& socket)
p_diff.id = client.id;
p_diff.dir = (Direction)t.type;
p_diff.action = IDLE;
m_server->getMap()->clearAllPlayerAction(client.id);
m_server->getMap()->pushPlayerAction(p_diff);
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment